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 <libempathy/empathy-tp-contact-factory.h>
32 #include <libempathy/empathy-contact-manager.h>
33 #include <libempathy/empathy-call-factory.h>
34 #include <libempathy/empathy-dispatcher.h>
35 #include <libempathy/empathy-utils.h>
37 #define DEBUG_FLAG EMPATHY_DEBUG_CONTACT
38 #include <libempathy/empathy-debug.h>
40 #include <libempathy-gtk/empathy-ui-utils.h>
41 #include <libempathy-gtk/empathy-images.h>
43 #include "empathy-new-call-dialog.h"
44 #include "empathy-account-chooser.h"
46 static EmpathyNewCallDialog *dialog_singleton = NULL;
48 G_DEFINE_TYPE(EmpathyNewCallDialog, empathy_new_call_dialog,
49 EMPATHY_TYPE_CONTACT_SELECTOR_DIALOG)
51 typedef struct _EmpathyNewCallDialogPriv EmpathyNewCallDialogPriv;
53 struct _EmpathyNewCallDialogPriv {
54 GtkWidget *check_video;
58 (G_TYPE_INSTANCE_GET_PRIVATE ((o), EMPATHY_TYPE_NEW_CALL_DIALOG, \
59 EmpathyNewCallDialogPriv))
62 * SECTION:empathy-new-call-dialog
63 * @title: EmpathyNewCallDialog
64 * @short_description: A dialog to show a new call
65 * @include: libempathy-gtk/empathy-new-call-dialog.h
67 * #EmpathyNewCallDialog is a dialog which allows a call
68 * to be started with any contact on any enabled account.
72 got_contact_cb (EmpathyTpContactFactory *factory,
73 EmpathyContact *contact,
78 EmpathyCallFactory *call_factory;
79 gboolean video = GPOINTER_TO_UINT (user_data);
83 DEBUG ("Failed: %s", error->message);
87 call_factory = empathy_call_factory_get ();
88 empathy_call_factory_new_call_with_streams (call_factory, contact, TRUE,
93 empathy_new_call_dialog_got_response (EmpathyContactSelectorDialog *dialog,
94 TpConnection *connection,
95 const gchar *contact_id)
97 EmpathyNewCallDialogPriv *priv = GET_PRIV (dialog);
98 EmpathyTpContactFactory *factory;
101 /* check if video is enabled now because the dialog will be destroyed once
102 * we return from this function. */
103 video = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->check_video));
105 factory = empathy_tp_contact_factory_dup_singleton (connection);
106 empathy_tp_contact_factory_get_from_id (factory, contact_id,
107 got_contact_cb, GUINT_TO_POINTER (video), NULL, NULL);
109 g_object_unref (factory);
113 empathy_new_call_dialog_account_filter (EmpathyContactSelectorDialog *dialog,
116 TpConnection *connection;
117 EmpathyDispatcher *dispatcher;
120 if (tp_account_get_connection_status (account, NULL) !=
121 TP_CONNECTION_STATUS_CONNECTED)
124 /* check if CM supports calls */
125 connection = tp_account_get_connection (account);
126 if (connection == NULL)
129 dispatcher = empathy_dispatcher_dup_singleton ();
131 classes = empathy_dispatcher_find_requestable_channel_classes
132 (dispatcher, connection, TP_IFACE_CHANNEL_TYPE_STREAMED_MEDIA,
133 TP_HANDLE_TYPE_CONTACT, NULL);
135 g_object_unref (dispatcher);
140 g_list_free (classes);
145 empathy_new_call_dialog_constructor (GType type,
147 GObjectConstructParam *props)
151 if (dialog_singleton)
153 retval = G_OBJECT (dialog_singleton);
154 g_object_ref (retval);
158 retval = G_OBJECT_CLASS (
159 empathy_new_call_dialog_parent_class)->constructor (type,
162 dialog_singleton = EMPATHY_NEW_CALL_DIALOG (retval);
163 g_object_add_weak_pointer (retval, (gpointer) &dialog_singleton);
170 empathy_new_call_dialog_init (EmpathyNewCallDialog *dialog)
172 EmpathyContactSelectorDialog *parent = EMPATHY_CONTACT_SELECTOR_DIALOG (
174 EmpathyNewCallDialogPriv *priv = GET_PRIV (dialog);
177 /* add video toggle */
178 priv->check_video = gtk_check_button_new_with_mnemonic (_("Send _Video"));
180 gtk_box_pack_end (GTK_BOX (parent->vbox), priv->check_video,
183 gtk_widget_show (priv->check_video);
185 /* add chat button */
186 parent->button_action = gtk_button_new_with_mnemonic (_("_Call"));
187 image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_VOIP,
188 GTK_ICON_SIZE_BUTTON);
189 gtk_button_set_image (GTK_BUTTON (parent->button_action), image);
191 gtk_dialog_add_action_widget (GTK_DIALOG (dialog), parent->button_action,
192 GTK_RESPONSE_ACCEPT);
193 gtk_widget_show (parent->button_action);
195 /* Tweak the dialog */
196 gtk_window_set_title (GTK_WINDOW (dialog), _("New Call"));
197 gtk_window_set_role (GTK_WINDOW (dialog), "new_call");
199 gtk_widget_set_sensitive (parent->button_action, FALSE);
203 empathy_new_call_dialog_class_init (
204 EmpathyNewCallDialogClass *class)
206 GObjectClass *object_class = G_OBJECT_CLASS (class);
207 EmpathyContactSelectorDialogClass *dialog_class = \
208 EMPATHY_CONTACT_SELECTOR_DIALOG_CLASS (class);
210 g_type_class_add_private (class, sizeof (EmpathyNewCallDialogPriv));
212 object_class->constructor = empathy_new_call_dialog_constructor;
214 dialog_class->got_response = empathy_new_call_dialog_got_response;
215 dialog_class->account_filter = empathy_new_call_dialog_account_filter;
219 * empathy_new_call_dialog_new:
220 * @parent: parent #GtkWindow of the dialog
222 * Create a new #EmpathyNewCallDialog it.
224 * Return value: the new #EmpathyNewCallDialog
227 empathy_new_call_dialog_show (GtkWindow *parent)
231 dialog = g_object_new (EMPATHY_TYPE_NEW_CALL_DIALOG, NULL);
235 gtk_window_set_transient_for (GTK_WINDOW (dialog),
236 GTK_WINDOW (parent));
239 gtk_widget_show (dialog);