Don't try to access empathy_adium_info_* stuff when webkit support is disabled
[empathy-mirror.git] / libempathy-gtk / empathy-call-utils.c
blob4e8f6d2cd5d64acadd72114eebe82ca582df5066
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"
23 #include <glib/gi18n.h>
25 #include <gtk/gtk.h>
27 #include <telepathy-glib/telepathy-glib.h>
29 #include <telepathy-yell/telepathy-yell.h>
31 #include "empathy-call-utils.h"
33 #include <libempathy/empathy-request-util.h>
35 #define DEBUG_FLAG EMPATHY_DEBUG_OTHER
36 #include <libempathy/empathy-debug.h>
38 static const gchar *
39 get_error_display_message (GError *error)
41 if (error->domain != TP_ERROR)
42 return _("There was an error starting the call");
44 switch (error->code)
46 case TP_ERROR_NETWORK_ERROR:
47 return _("Network error");
48 case TP_ERROR_NOT_CAPABLE:
49 return _("The specified contact doesn't support calls");
50 case TP_ERROR_OFFLINE:
51 return _("The specified contact is offline");
52 case TP_ERROR_INVALID_HANDLE:
53 return _("The specified contact is not valid");
54 case TP_ERROR_EMERGENCY_CALLS_NOT_SUPPORTED:
55 return _("Emergency calls are not supported on this protocol");
58 return _("There was an error starting the call");
61 static void
62 show_call_error (GError *error)
64 GtkWidget *dialog;
66 dialog = gtk_message_dialog_new (NULL, 0,
67 GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
68 "%s", get_error_display_message (error));
70 g_signal_connect_swapped (dialog, "response",
71 G_CALLBACK (gtk_widget_destroy),
72 dialog);
74 gtk_widget_show (dialog);
77 GHashTable *
78 empathy_call_create_call_request (const gchar *contact,
79 gboolean initial_audio,
80 gboolean initial_video)
82 return tp_asv_new (
83 TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING,
84 TPY_IFACE_CHANNEL_TYPE_CALL,
85 TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, G_TYPE_UINT,
86 TP_HANDLE_TYPE_CONTACT,
87 TP_PROP_CHANNEL_TARGET_ID, G_TYPE_STRING,
88 contact,
89 TPY_PROP_CHANNEL_TYPE_CALL_INITIAL_AUDIO, G_TYPE_BOOLEAN,
90 initial_audio,
91 TPY_PROP_CHANNEL_TYPE_CALL_INITIAL_VIDEO, G_TYPE_BOOLEAN,
92 initial_video,
93 NULL);
96 GHashTable *
97 empathy_call_create_streamed_media_request (const gchar *contact,
98 gboolean initial_audio,
99 gboolean initial_video)
101 return tp_asv_new (
102 TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING,
103 TP_IFACE_CHANNEL_TYPE_STREAMED_MEDIA,
104 TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, G_TYPE_UINT,
105 TP_HANDLE_TYPE_CONTACT,
106 TP_PROP_CHANNEL_TARGET_ID, G_TYPE_STRING,
107 contact,
108 TP_PROP_CHANNEL_TYPE_STREAMED_MEDIA_INITIAL_AUDIO, G_TYPE_BOOLEAN,
109 initial_audio,
110 TP_PROP_CHANNEL_TYPE_STREAMED_MEDIA_INITIAL_VIDEO, G_TYPE_BOOLEAN,
111 initial_video,
112 NULL);
115 static void
116 create_call_channel_cb (GObject *source,
117 GAsyncResult *result,
118 gpointer user_data)
120 GError *error = NULL;
122 if (!tp_account_channel_request_create_channel_finish (
123 TP_ACCOUNT_CHANNEL_REQUEST (source),
124 result,
125 &error))
127 DEBUG ("Failed to create Call channel: %s", error->message);
128 show_call_error (error);
129 g_error_free (error);
133 static void
134 create_streamed_media_channel_cb (GObject *source,
135 GAsyncResult *result,
136 gpointer user_data)
138 TpAccountChannelRequest *call_req = user_data;
139 GError *error = NULL;
141 if (tp_account_channel_request_create_channel_finish (
142 TP_ACCOUNT_CHANNEL_REQUEST (source), result, &error))
144 g_object_unref (call_req);
145 return;
148 DEBUG ("Failed to create StreamedMedia channel: %s", error->message);
150 if (error->code != TP_ERROR_NOT_IMPLEMENTED)
152 show_call_error (error);
153 return;
156 DEBUG ("Let's try with a Call channel");
157 g_error_free (error);
158 tp_account_channel_request_create_channel_async (call_req,
159 EMPATHY_CALL_BUS_NAME, NULL,
160 create_call_channel_cb,
161 NULL);
164 void
165 empathy_call_new_with_streams (const gchar *contact,
166 TpAccount *account,
167 gboolean initial_audio,
168 gboolean initial_video,
169 gint64 timestamp)
171 GHashTable *call_request, *streamed_media_request;
172 TpAccountChannelRequest *call_req, *streamed_media_req;
174 call_request = empathy_call_create_call_request (contact,
175 initial_audio,
176 initial_video);
178 streamed_media_request = empathy_call_create_streamed_media_request (
179 contact, initial_audio, initial_video);
181 call_req = tp_account_channel_request_new (account, call_request, timestamp);
182 streamed_media_req = tp_account_channel_request_new (account,
183 streamed_media_request,
184 timestamp);
186 tp_account_channel_request_create_channel_async (streamed_media_req,
187 EMPATHY_AV_BUS_NAME, NULL,
188 create_streamed_media_channel_cb,
189 call_req);
191 g_hash_table_unref (call_request);
192 g_hash_table_unref (streamed_media_request);
193 g_object_unref (streamed_media_req);