Update Greek translation
[empathy-mirror.git] / libempathy-gtk / empathy-call-utils.c
blobaa4c3b0ef4b37053b50747f1a9e43a4884b73483
1 /*
2 * Copyright (C) 2011 Collabora Ltd.
4 * The code contained in this file is free software; you can redistribute
5 * it and/or modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either version
7 * 2.1 of the License, or (at your option) any later version.
9 * This file is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this code; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 * Authors: Emilio Pozuelo Monfort <emilio.pozuelo@collabora.co.uk>
21 #include "config.h"
22 #include "empathy-call-utils.h"
24 #include <glib/gi18n-lib.h>
25 #include <gtk/gtk.h>
26 #include <telepathy-glib/telepathy-glib-dbus.h>
28 #include "empathy-request-util.h"
30 #define DEBUG_FLAG EMPATHY_DEBUG_OTHER
31 #include "empathy-debug.h"
33 static const gchar *
34 get_error_display_message (GError *error)
36 if (error->domain != TP_ERROR)
37 return _("There was an error starting the call");
39 switch (error->code)
41 case TP_ERROR_NETWORK_ERROR:
42 return _("Network error");
43 case TP_ERROR_NOT_CAPABLE:
44 return _("The specified contact doesn’t support calls");
45 case TP_ERROR_OFFLINE:
46 return _("The specified contact is offline");
47 case TP_ERROR_INVALID_HANDLE:
48 return _("The specified contact is not valid");
49 case TP_ERROR_EMERGENCY_CALLS_NOT_SUPPORTED:
50 return _("Emergency calls are not supported on this protocol");
51 case TP_ERROR_INSUFFICIENT_BALANCE:
52 return _("You don’t have enough credit in order to place this call");
55 return _("There was an error starting the call");
58 static void
59 show_call_error (GError *error)
61 GtkWidget *dialog;
63 dialog = gtk_message_dialog_new (NULL, 0,
64 GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
65 "%s", get_error_display_message (error));
67 g_signal_connect_swapped (dialog, "response",
68 G_CALLBACK (gtk_widget_destroy),
69 dialog);
71 gtk_widget_show (dialog);
74 static void
75 create_call_channel_cb (GObject *source,
76 GAsyncResult *result,
77 gpointer user_data)
79 GError *error = NULL;
81 if (tp_account_channel_request_create_channel_finish (
82 TP_ACCOUNT_CHANNEL_REQUEST (source), result, &error))
83 return;
85 DEBUG ("Failed to create Call channel: %s", error->message);
87 show_call_error (error);
90 TpAccountChannelRequest *
91 empathy_call_create_call_request (TpAccount *account,
92 const gchar *contact,
93 gboolean initial_video,
94 gint64 timestamp)
96 TpAccountChannelRequest *call_req;
98 if (initial_video)
99 call_req = tp_account_channel_request_new_audio_video_call (account,
100 timestamp);
101 else
102 call_req = tp_account_channel_request_new_audio_call (account, timestamp);
104 tp_account_channel_request_set_target_id (call_req, TP_HANDLE_TYPE_CONTACT,
105 contact);
107 return call_req;
110 void
111 empathy_call_new_with_streams (const gchar *contact,
112 TpAccount *account,
113 gboolean initial_video,
114 gint64 timestamp)
116 TpAccountChannelRequest *call_req;
118 call_req = empathy_call_create_call_request (account, contact, initial_video,
119 timestamp);
121 tp_account_channel_request_create_channel_async (call_req,
122 EMPATHY_CALL_TP_BUS_NAME, NULL, create_call_channel_cb, NULL);
124 g_object_unref (call_req);
127 /* Copied from telepathy-yell call-channel.c */
128 void
129 empathy_call_channel_send_video (TpCallChannel *self,
130 gboolean send)
132 GPtrArray *contents;
133 gboolean found = FALSE;
134 guint i;
136 g_return_if_fail (TP_IS_CALL_CHANNEL (self));
138 /* Loop over all the contents, if some of them a video set all their
139 * streams to sending, otherwise request a video channel in case we want to
140 * sent */
141 contents = tp_call_channel_get_contents (self);
142 for (i = 0 ; i < contents->len ; i++)
144 TpCallContent *content = g_ptr_array_index (contents, i);
146 if (tp_call_content_get_media_type (content) ==
147 TP_MEDIA_STREAM_TYPE_VIDEO)
149 GPtrArray *streams;
150 guint j;
152 found = TRUE;
153 streams = tp_call_content_get_streams (content);
154 for (j = 0; j < streams->len; j++)
156 TpCallStream *stream = g_ptr_array_index (streams, j);
158 tp_call_stream_set_sending_async (stream, send, NULL, NULL);
163 if (send && !found)
165 tp_call_channel_add_content_async (self, "video",
166 TP_MEDIA_STREAM_TYPE_VIDEO, TP_MEDIA_STREAM_DIRECTION_BIDIRECTIONAL,
167 NULL, NULL);
171 /* Copied from telepathy-yell call-channel.c */
172 TpSendingState
173 empathy_call_channel_get_video_state (TpCallChannel *self)
175 TpSendingState result = TP_SENDING_STATE_NONE;
176 GPtrArray *contents;
177 guint i;
179 g_return_val_if_fail (TP_IS_CALL_CHANNEL (self), TP_SENDING_STATE_NONE);
181 contents = tp_call_channel_get_contents (self);
182 for (i = 0 ; i < contents->len ; i++)
184 TpCallContent *content = g_ptr_array_index (contents, i);
186 if (tp_call_content_get_media_type (content) ==
187 TP_MEDIA_STREAM_TYPE_VIDEO)
189 GPtrArray *streams;
190 guint j;
192 streams = tp_call_content_get_streams (content);
193 for (j = 0; j < streams->len; j++)
195 TpCallStream *stream = g_ptr_array_index (streams, j);
196 TpSendingState state;
198 state = tp_call_stream_get_local_sending_state (stream);
199 if (state != TP_SENDING_STATE_PENDING_STOP_SENDING &&
200 state > result)
201 result = state;
206 return result;