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 create_media_channel_cb (GObject
*source
,
68 if (!tp_account_channel_request_create_channel_finish (
69 TP_ACCOUNT_CHANNEL_REQUEST (source
), result
, &error
))
71 DEBUG ("Failed to create media channel: %s", error
->message
);
77 * SECTION:empathy-new-call-dialog
78 * @title: EmpathyNewCallDialog
79 * @short_description: A dialog to show a new call
80 * @include: libempathy-gtk/empathy-new-call-dialog.h
82 * #EmpathyNewCallDialog is a dialog which allows a call
83 * to be started with any contact on any enabled account.
87 call_contact (TpAccount
*account
,
88 const gchar
*contact_id
,
93 TpAccountChannelRequest
*req
;
95 request
= tp_asv_new (
96 TP_PROP_CHANNEL_CHANNEL_TYPE
, G_TYPE_STRING
,
97 TP_IFACE_CHANNEL_TYPE_STREAMED_MEDIA
,
98 TP_PROP_CHANNEL_TARGET_HANDLE_TYPE
, G_TYPE_UINT
, TP_HANDLE_TYPE_CONTACT
,
99 TP_PROP_CHANNEL_TARGET_ID
, G_TYPE_STRING
, contact_id
,
100 TP_PROP_CHANNEL_TYPE_STREAMED_MEDIA_INITIAL_AUDIO
, G_TYPE_BOOLEAN
,
102 TP_PROP_CHANNEL_TYPE_STREAMED_MEDIA_INITIAL_VIDEO
, G_TYPE_BOOLEAN
,
106 req
= tp_account_channel_request_new (account
, request
, timestamp
);
108 tp_account_channel_request_create_channel_async (req
, NULL
, NULL
,
109 create_media_channel_cb
, NULL
);
111 g_object_unref (req
);
115 empathy_new_call_dialog_response (GtkDialog
*dialog
, int response_id
)
117 EmpathyNewCallDialogPriv
*priv
= GET_PRIV (dialog
);
120 const gchar
*contact_id
;
122 if (response_id
!= GTK_RESPONSE_ACCEPT
) goto out
;
124 contact_id
= empathy_contact_selector_dialog_get_selected (
125 EMPATHY_CONTACT_SELECTOR_DIALOG (dialog
), NULL
, &account
);
127 if (EMP_STR_EMPTY (contact_id
) || account
== NULL
) goto out
;
129 /* check if video is enabled now because the dialog will be destroyed once
130 * we return from this function. */
131 video
= gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv
->check_video
));
133 call_contact (account
, contact_id
, video
, gtk_get_current_event_time ());
136 gtk_widget_destroy (GTK_WIDGET (dialog
));
140 empathy_new_call_dialog_account_filter (EmpathyContactSelectorDialog
*dialog
,
143 TpConnection
*connection
;
144 EmpathyDispatcher
*dispatcher
;
147 if (tp_account_get_connection_status (account
, NULL
) !=
148 TP_CONNECTION_STATUS_CONNECTED
)
151 /* check if CM supports calls */
152 connection
= tp_account_get_connection (account
);
153 if (connection
== NULL
)
156 dispatcher
= empathy_dispatcher_dup_singleton ();
158 classes
= empathy_dispatcher_find_requestable_channel_classes
159 (dispatcher
, connection
, TP_IFACE_CHANNEL_TYPE_STREAMED_MEDIA
,
160 TP_HANDLE_TYPE_CONTACT
, NULL
);
162 g_object_unref (dispatcher
);
167 g_list_free (classes
);
172 empathy_new_call_dialog_constructor (GType type
,
174 GObjectConstructParam
*props
)
178 if (dialog_singleton
)
180 retval
= G_OBJECT (dialog_singleton
);
181 g_object_ref (retval
);
185 retval
= G_OBJECT_CLASS (
186 empathy_new_call_dialog_parent_class
)->constructor (type
,
189 dialog_singleton
= EMPATHY_NEW_CALL_DIALOG (retval
);
190 g_object_add_weak_pointer (retval
, (gpointer
) &dialog_singleton
);
197 empathy_new_call_dialog_init (EmpathyNewCallDialog
*dialog
)
199 EmpathyContactSelectorDialog
*parent
= EMPATHY_CONTACT_SELECTOR_DIALOG (
201 EmpathyNewCallDialogPriv
*priv
= GET_PRIV (dialog
);
204 /* add video toggle */
205 priv
->check_video
= gtk_check_button_new_with_mnemonic (_("Send _Video"));
207 gtk_box_pack_end (GTK_BOX (parent
->vbox
), priv
->check_video
,
210 gtk_widget_show (priv
->check_video
);
212 /* add chat button */
213 parent
->button_action
= gtk_button_new_with_mnemonic (_("C_all"));
214 image
= gtk_image_new_from_icon_name (EMPATHY_IMAGE_VOIP
,
215 GTK_ICON_SIZE_BUTTON
);
216 gtk_button_set_image (GTK_BUTTON (parent
->button_action
), image
);
218 gtk_dialog_add_action_widget (GTK_DIALOG (dialog
), parent
->button_action
,
219 GTK_RESPONSE_ACCEPT
);
220 gtk_widget_show (parent
->button_action
);
222 /* Tweak the dialog */
223 gtk_window_set_title (GTK_WINDOW (dialog
), _("New Call"));
224 gtk_window_set_role (GTK_WINDOW (dialog
), "new_call");
226 gtk_widget_set_sensitive (parent
->button_action
, FALSE
);
230 empathy_new_call_dialog_class_init (
231 EmpathyNewCallDialogClass
*class)
233 GObjectClass
*object_class
= G_OBJECT_CLASS (class);
234 GtkDialogClass
*dialog_class
= GTK_DIALOG_CLASS (class);
235 EmpathyContactSelectorDialogClass
*selector_dialog_class
= \
236 EMPATHY_CONTACT_SELECTOR_DIALOG_CLASS (class);
238 g_type_class_add_private (class, sizeof (EmpathyNewCallDialogPriv
));
240 object_class
->constructor
= empathy_new_call_dialog_constructor
;
242 dialog_class
->response
= empathy_new_call_dialog_response
;
244 selector_dialog_class
->account_filter
= empathy_new_call_dialog_account_filter
;
248 * empathy_new_call_dialog_new:
249 * @parent: parent #GtkWindow of the dialog
251 * Create a new #EmpathyNewCallDialog it.
253 * Return value: the new #EmpathyNewCallDialog
256 empathy_new_call_dialog_show (GtkWindow
*parent
)
260 dialog
= g_object_new (EMPATHY_TYPE_NEW_CALL_DIALOG
, NULL
);
264 gtk_window_set_transient_for (GTK_WINDOW (dialog
),
265 GTK_WINDOW (parent
));
268 gtk_widget_show (dialog
);