2 * Copyright (C) 2009 Collabora Ltd.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library 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 library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 * Authors: Guillaume Desmottes <guillaume.desmottes@collabora.co.uk>
27 #include <glib/gi18n-lib.h>
29 #include <telepathy-glib/interfaces.h>
31 #include <telepathy-yell/telepathy-yell.h>
33 #include <libempathy/empathy-tp-contact-factory.h>
34 #include <libempathy/empathy-contact-manager.h>
35 #include <libempathy/empathy-utils.h>
36 #include <libempathy/empathy-request-util.h>
38 #define DEBUG_FLAG EMPATHY_DEBUG_CONTACT
39 #include <libempathy/empathy-debug.h>
41 #include <libempathy-gtk/empathy-ui-utils.h>
42 #include <libempathy-gtk/empathy-images.h>
44 #include "empathy-new-call-dialog.h"
45 #include "empathy-account-chooser.h"
46 #include "empathy-call-utils.h"
48 static EmpathyNewCallDialog *dialog_singleton = NULL;
50 G_DEFINE_TYPE(EmpathyNewCallDialog, empathy_new_call_dialog,
51 EMPATHY_TYPE_CONTACT_SELECTOR_DIALOG)
53 typedef struct _EmpathyNewCallDialogPriv EmpathyNewCallDialogPriv;
56 EmpathyAccountChooserFilterResultCallback callback;
60 struct _EmpathyNewCallDialogPriv {
61 GtkWidget *check_video;
65 (G_TYPE_INSTANCE_GET_PRIVATE ((o), EMPATHY_TYPE_NEW_CALL_DIALOG, \
66 EmpathyNewCallDialogPriv))
69 * SECTION:empathy-new-call-dialog
70 * @title: EmpathyNewCallDialog
71 * @short_description: A dialog to show a new call
72 * @include: libempathy-gtk/empathy-new-call-dialog.h
74 * #EmpathyNewCallDialog is a dialog which allows a call
75 * to be started with any contact on any enabled account.
79 empathy_new_call_dialog_response (GtkDialog *dialog, int response_id)
81 EmpathyNewCallDialogPriv *priv = GET_PRIV (dialog);
84 const gchar *contact_id;
86 if (response_id != GTK_RESPONSE_ACCEPT) goto out;
88 contact_id = empathy_contact_selector_dialog_get_selected (
89 EMPATHY_CONTACT_SELECTOR_DIALOG (dialog), NULL, &account);
91 if (EMP_STR_EMPTY (contact_id) || account == NULL) goto out;
93 /* check if video is enabled now because the dialog will be destroyed once
94 * we return from this function. */
95 video = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->check_video));
97 empathy_call_new_with_streams (contact_id,
99 empathy_get_current_action_time ());
102 gtk_widget_destroy (GTK_WIDGET (dialog));
106 conn_prepared_cb (GObject *conn,
107 GAsyncResult *result,
110 FilterCallbackData *data = user_data;
111 GError *myerr = NULL;
112 TpCapabilities *caps;
116 if (!tp_proxy_prepare_finish (conn, result, &myerr))
119 caps = tp_connection_get_capabilities (TP_CONNECTION (conn));
120 classes = tp_capabilities_get_channel_classes (caps);
122 for (i = 0; i < classes->len; i++)
126 const gchar *chan_type;
128 tp_value_array_unpack (g_ptr_array_index (classes, i), 2,
131 chan_type = tp_asv_get_string (fixed, TP_PROP_CHANNEL_CHANNEL_TYPE);
133 if (tp_strdiff (chan_type, TP_IFACE_CHANNEL_TYPE_STREAMED_MEDIA)
134 && tp_strdiff (chan_type, TPY_IFACE_CHANNEL_TYPE_CALL))
137 if (tp_asv_get_uint32 (fixed, TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, NULL) !=
138 TP_HANDLE_TYPE_CONTACT)
141 data->callback (TRUE, data->user_data);
142 g_slice_free (FilterCallbackData, data);
147 data->callback (FALSE, data->user_data);
148 g_slice_free (FilterCallbackData, data);
152 empathy_new_call_dialog_account_filter (EmpathyContactSelectorDialog *dialog,
153 EmpathyAccountChooserFilterResultCallback callback,
154 gpointer callback_data,
157 TpConnection *connection;
158 FilterCallbackData *cb_data;
159 GQuark features[] = { TP_CONNECTION_FEATURE_CAPABILITIES, 0 };
161 if (tp_account_get_connection_status (account, NULL) !=
162 TP_CONNECTION_STATUS_CONNECTED)
164 callback (FALSE, callback_data);
168 /* check if CM supports calls */
169 connection = tp_account_get_connection (account);
170 if (connection == NULL)
172 callback (FALSE, callback_data);
176 cb_data = g_slice_new0 (FilterCallbackData);
177 cb_data->callback = callback;
178 cb_data->user_data = callback_data;
179 tp_proxy_prepare_async (connection, features, conn_prepared_cb, cb_data);
183 empathy_new_call_dialog_constructor (GType type,
185 GObjectConstructParam *props)
189 if (dialog_singleton)
191 retval = G_OBJECT (dialog_singleton);
192 g_object_ref (retval);
196 retval = G_OBJECT_CLASS (
197 empathy_new_call_dialog_parent_class)->constructor (type,
200 dialog_singleton = EMPATHY_NEW_CALL_DIALOG (retval);
201 g_object_add_weak_pointer (retval, (gpointer) &dialog_singleton);
208 empathy_new_call_dialog_init (EmpathyNewCallDialog *dialog)
210 EmpathyContactSelectorDialog *parent = EMPATHY_CONTACT_SELECTOR_DIALOG (
212 EmpathyNewCallDialogPriv *priv = GET_PRIV (dialog);
215 /* add video toggle */
216 priv->check_video = gtk_check_button_new_with_mnemonic (_("Send _Video"));
218 gtk_box_pack_end (GTK_BOX (parent->vbox), priv->check_video,
221 gtk_widget_show (priv->check_video);
223 /* add chat button */
224 parent->button_action = gtk_button_new_with_mnemonic (_("C_all"));
225 image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_VOIP,
226 GTK_ICON_SIZE_BUTTON);
227 gtk_button_set_image (GTK_BUTTON (parent->button_action), image);
229 gtk_dialog_add_action_widget (GTK_DIALOG (dialog), parent->button_action,
230 GTK_RESPONSE_ACCEPT);
231 gtk_widget_show (parent->button_action);
233 /* Tweak the dialog */
234 gtk_window_set_title (GTK_WINDOW (dialog), _("New Call"));
235 gtk_window_set_role (GTK_WINDOW (dialog), "new_call");
237 gtk_widget_set_sensitive (parent->button_action, FALSE);
241 empathy_new_call_dialog_class_init (
242 EmpathyNewCallDialogClass *class)
244 GObjectClass *object_class = G_OBJECT_CLASS (class);
245 GtkDialogClass *dialog_class = GTK_DIALOG_CLASS (class);
246 EmpathyContactSelectorDialogClass *selector_dialog_class = \
247 EMPATHY_CONTACT_SELECTOR_DIALOG_CLASS (class);
249 g_type_class_add_private (class, sizeof (EmpathyNewCallDialogPriv));
251 object_class->constructor = empathy_new_call_dialog_constructor;
253 dialog_class->response = empathy_new_call_dialog_response;
255 selector_dialog_class->account_filter = empathy_new_call_dialog_account_filter;
259 * empathy_new_call_dialog_new:
260 * @parent: parent #GtkWindow of the dialog
262 * Create a new #EmpathyNewCallDialog it.
264 * Return value: the new #EmpathyNewCallDialog
267 empathy_new_call_dialog_show (GtkWindow *parent)
271 dialog = g_object_new (EMPATHY_TYPE_NEW_CALL_DIALOG, NULL);
275 gtk_window_set_transient_for (GTK_WINDOW (dialog),
276 GTK_WINDOW (parent));
279 gtk_widget_show (dialog);