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-camera-monitor.h>
35 #include <libempathy/empathy-contact-manager.h>
36 #include <libempathy/empathy-utils.h>
37 #include <libempathy/empathy-request-util.h>
39 #define DEBUG_FLAG EMPATHY_DEBUG_CONTACT
40 #include <libempathy/empathy-debug.h>
42 #include <libempathy-gtk/empathy-ui-utils.h>
43 #include <libempathy-gtk/empathy-images.h>
45 #include "empathy-new-call-dialog.h"
46 #include "empathy-account-chooser.h"
47 #include "empathy-call-utils.h"
49 static EmpathyNewCallDialog *dialog_singleton = NULL;
51 G_DEFINE_TYPE(EmpathyNewCallDialog, empathy_new_call_dialog,
52 EMPATHY_TYPE_CONTACT_SELECTOR_DIALOG)
54 typedef struct _EmpathyNewCallDialogPriv EmpathyNewCallDialogPriv;
57 EmpathyAccountChooserFilterResultCallback callback;
61 struct _EmpathyNewCallDialogPriv {
62 GtkWidget *check_video;
64 EmpathyCameraMonitor *monitor;
68 (G_TYPE_INSTANCE_GET_PRIVATE ((o), EMPATHY_TYPE_NEW_CALL_DIALOG, \
69 EmpathyNewCallDialogPriv))
72 * SECTION:empathy-new-call-dialog
73 * @title: EmpathyNewCallDialog
74 * @short_description: A dialog to show a new call
75 * @include: libempathy-gtk/empathy-new-call-dialog.h
77 * #EmpathyNewCallDialog is a dialog which allows a call
78 * to be started with any contact on any enabled account.
82 empathy_new_call_dialog_response (GtkDialog *dialog, int response_id)
84 EmpathyNewCallDialogPriv *priv = GET_PRIV (dialog);
87 const gchar *contact_id;
89 if (response_id != GTK_RESPONSE_ACCEPT) goto out;
91 contact_id = empathy_contact_selector_dialog_get_selected (
92 EMPATHY_CONTACT_SELECTOR_DIALOG (dialog), NULL, &account);
94 if (EMP_STR_EMPTY (contact_id) || account == NULL) goto out;
96 /* check if video is enabled now because the dialog will be destroyed once
97 * we return from this function. */
98 video = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->check_video));
100 empathy_call_new_with_streams (contact_id,
101 account, TRUE, video,
102 empathy_get_current_action_time ());
105 gtk_widget_destroy (GTK_WIDGET (dialog));
109 empathy_new_call_dialog_account_filter (EmpathyContactSelectorDialog *dialog,
110 EmpathyAccountChooserFilterResultCallback callback,
111 gpointer callback_data,
114 TpConnection *connection;
115 gboolean supported = FALSE;
117 TpCapabilities *caps;
120 /* check if CM supports calls */
121 connection = tp_account_get_connection (account);
122 if (connection == NULL)
125 caps = tp_connection_get_capabilities (connection);
129 classes = tp_capabilities_get_channel_classes (caps);
131 for (i = 0; i < classes->len; i++)
135 const gchar *chan_type;
137 tp_value_array_unpack (g_ptr_array_index (classes, i), 2,
140 chan_type = tp_asv_get_string (fixed, TP_PROP_CHANNEL_CHANNEL_TYPE);
142 if (tp_strdiff (chan_type, TP_IFACE_CHANNEL_TYPE_STREAMED_MEDIA)
143 && tp_strdiff (chan_type, TPY_IFACE_CHANNEL_TYPE_CALL))
146 if (tp_asv_get_uint32 (fixed, TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, NULL) !=
147 TP_HANDLE_TYPE_CONTACT)
155 callback (supported, callback_data);
159 empathy_new_call_dialog_dispose (GObject *object)
161 EmpathyNewCallDialogPriv *priv = GET_PRIV (object);
163 tp_clear_object (&priv->monitor);
165 G_OBJECT_CLASS (empathy_new_call_dialog_parent_class)->dispose (object);
169 empathy_new_call_dialog_constructor (GType type,
171 GObjectConstructParam *props)
175 if (dialog_singleton)
177 retval = G_OBJECT (dialog_singleton);
178 g_object_ref (retval);
182 retval = G_OBJECT_CLASS (
183 empathy_new_call_dialog_parent_class)->constructor (type,
186 dialog_singleton = EMPATHY_NEW_CALL_DIALOG (retval);
187 g_object_add_weak_pointer (retval, (gpointer) &dialog_singleton);
194 empathy_new_call_dialog_init (EmpathyNewCallDialog *dialog)
196 EmpathyContactSelectorDialog *parent = EMPATHY_CONTACT_SELECTOR_DIALOG (
198 EmpathyNewCallDialogPriv *priv = GET_PRIV (dialog);
201 priv->monitor = empathy_camera_monitor_dup_singleton ();
203 /* add video toggle */
204 priv->check_video = gtk_check_button_new_with_mnemonic (_("Send _Video"));
205 g_object_bind_property (priv->monitor, "available",
206 priv->check_video, "sensitive",
207 G_BINDING_SYNC_CREATE);
209 gtk_box_pack_end (GTK_BOX (parent->vbox), priv->check_video,
212 gtk_widget_show (priv->check_video);
214 /* add chat button */
215 parent->button_action = gtk_button_new_with_mnemonic (_("C_all"));
216 image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_VOIP,
217 GTK_ICON_SIZE_BUTTON);
218 gtk_button_set_image (GTK_BUTTON (parent->button_action), image);
220 gtk_dialog_add_action_widget (GTK_DIALOG (dialog), parent->button_action,
221 GTK_RESPONSE_ACCEPT);
222 gtk_widget_show (parent->button_action);
224 /* Tweak the dialog */
225 gtk_window_set_title (GTK_WINDOW (dialog), _("New Call"));
226 gtk_window_set_role (GTK_WINDOW (dialog), "new_call");
228 gtk_widget_set_sensitive (parent->button_action, FALSE);
232 empathy_new_call_dialog_class_init (
233 EmpathyNewCallDialogClass *class)
235 GObjectClass *object_class = G_OBJECT_CLASS (class);
236 GtkDialogClass *dialog_class = GTK_DIALOG_CLASS (class);
237 EmpathyContactSelectorDialogClass *selector_dialog_class = \
238 EMPATHY_CONTACT_SELECTOR_DIALOG_CLASS (class);
240 g_type_class_add_private (class, sizeof (EmpathyNewCallDialogPriv));
242 object_class->constructor = empathy_new_call_dialog_constructor;
243 object_class->dispose = empathy_new_call_dialog_dispose;
245 dialog_class->response = empathy_new_call_dialog_response;
247 selector_dialog_class->account_filter = empathy_new_call_dialog_account_filter;
251 * empathy_new_call_dialog_new:
252 * @parent: parent #GtkWindow of the dialog
254 * Create a new #EmpathyNewCallDialog it.
256 * Return value: the new #EmpathyNewCallDialog
259 empathy_new_call_dialog_show (GtkWindow *parent)
263 dialog = g_object_new (EMPATHY_TYPE_NEW_CALL_DIALOG, NULL);
267 gtk_window_set_transient_for (GTK_WINDOW (dialog),
268 GTK_WINDOW (parent));
271 gtk_widget_show (dialog);