diff options
author | Emilio Pozuelo Monfort <emilio.pozuelo@collabora.co.uk> | 2011-06-09 17:28:44 +0800 |
---|---|---|
committer | Emilio Pozuelo Monfort <emilio.pozuelo@collabora.co.uk> | 2011-06-09 17:28:44 +0800 |
commit | 8944f13286ba5293781f2d57980da284cb2aa29d (patch) | |
tree | 91aa682420a072399f03ac7fb456f62c13064add /libempathy-gtk | |
parent | 981a1377f660a9d1e3660dc66613b993b78486fc (diff) | |
parent | 3f52e59aa058c16a9ba115398681a16b1e289cd1 (diff) | |
download | gsoc2013-empathy-8944f13286ba5293781f2d57980da284cb2aa29d.tar gsoc2013-empathy-8944f13286ba5293781f2d57980da284cb2aa29d.tar.gz gsoc2013-empathy-8944f13286ba5293781f2d57980da284cb2aa29d.tar.bz2 gsoc2013-empathy-8944f13286ba5293781f2d57980da284cb2aa29d.tar.lz gsoc2013-empathy-8944f13286ba5293781f2d57980da284cb2aa29d.tar.xz gsoc2013-empathy-8944f13286ba5293781f2d57980da284cb2aa29d.tar.zst gsoc2013-empathy-8944f13286ba5293781f2d57980da284cb2aa29d.zip |
Merge branch 'call'
Diffstat (limited to 'libempathy-gtk')
-rw-r--r-- | libempathy-gtk/Makefile.am | 4 | ||||
-rw-r--r-- | libempathy-gtk/empathy-call-utils.c | 194 | ||||
-rw-r--r-- | libempathy-gtk/empathy-call-utils.h | 43 | ||||
-rw-r--r-- | libempathy-gtk/empathy-contact-menu.c | 9 | ||||
-rw-r--r-- | libempathy-gtk/empathy-individual-menu.c | 9 | ||||
-rw-r--r-- | libempathy-gtk/empathy-new-call-dialog.c | 52 |
6 files changed, 262 insertions, 49 deletions
diff --git a/libempathy-gtk/Makefile.am b/libempathy-gtk/Makefile.am index bb2565885..7023ecfe5 100644 --- a/libempathy-gtk/Makefile.am +++ b/libempathy-gtk/Makefile.am @@ -8,6 +8,7 @@ AM_CPPFLAGS = \ -DPKGDATADIR=\""$(pkgdatadir)"\" \ -DGCR_API_SUBJECT_TO_CHANGE \ $(EMPATHY_CFLAGS) \ + $(YELL_CFLAGS) \ $(ENCHANT_CFLAGS) \ $(LIBCHAMPLAIN_CFLAGS) \ $(GEOCLUE_CFLAGS) \ @@ -35,6 +36,7 @@ libempathy_gtk_handwritten_source = \ empathy-account-widget.c \ empathy-avatar-chooser.c \ empathy-avatar-image.c \ + empathy-call-utils.c \ empathy-cell-renderer-activatable.c \ empathy-cell-renderer-expander.c \ empathy-cell-renderer-text.c \ @@ -95,6 +97,7 @@ libempathy_gtk_headers = \ empathy-account-widget.h \ empathy-avatar-chooser.h \ empathy-avatar-image.h \ + empathy-call-utils.h \ empathy-cell-renderer-activatable.h \ empathy-cell-renderer-expander.h \ empathy-cell-renderer-text.h \ @@ -160,6 +163,7 @@ nodist_libempathy_gtk_la_SOURCES =\ libempathy_gtk_la_LIBADD = \ $(EMPATHY_LIBS) \ + $(EMPATHY_LIBS) \ $(GTK_LIBS) \ $(LIBNOTIFY_LIBS) \ $(CANBERRA_LIBS) \ diff --git a/libempathy-gtk/empathy-call-utils.c b/libempathy-gtk/empathy-call-utils.c new file mode 100644 index 000000000..4e8f6d2cd --- /dev/null +++ b/libempathy-gtk/empathy-call-utils.c @@ -0,0 +1,194 @@ +/* + * Copyright (C) 2011 Collabora Ltd. + * + * The code contained in this file is free software; you can redistribute + * it and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either version + * 2.1 of the License, or (at your option) any later version. + * + * This file is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this code; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Authors: Emilio Pozuelo Monfort <emilio.pozuelo@collabora.co.uk> + */ + +#include "config.h" + +#include <glib/gi18n.h> + +#include <gtk/gtk.h> + +#include <telepathy-glib/telepathy-glib.h> + +#include <telepathy-yell/telepathy-yell.h> + +#include "empathy-call-utils.h" + +#include <libempathy/empathy-request-util.h> + +#define DEBUG_FLAG EMPATHY_DEBUG_OTHER +#include <libempathy/empathy-debug.h> + +static const gchar * +get_error_display_message (GError *error) +{ + if (error->domain != TP_ERROR) + return _("There was an error starting the call"); + + switch (error->code) + { + case TP_ERROR_NETWORK_ERROR: + return _("Network error"); + case TP_ERROR_NOT_CAPABLE: + return _("The specified contact doesn't support calls"); + case TP_ERROR_OFFLINE: + return _("The specified contact is offline"); + case TP_ERROR_INVALID_HANDLE: + return _("The specified contact is not valid"); + case TP_ERROR_EMERGENCY_CALLS_NOT_SUPPORTED: + return _("Emergency calls are not supported on this protocol"); + } + + return _("There was an error starting the call"); +} + +static void +show_call_error (GError *error) +{ + GtkWidget *dialog; + + dialog = gtk_message_dialog_new (NULL, 0, + GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, + "%s", get_error_display_message (error)); + + g_signal_connect_swapped (dialog, "response", + G_CALLBACK (gtk_widget_destroy), + dialog); + + gtk_widget_show (dialog); +} + +GHashTable * +empathy_call_create_call_request (const gchar *contact, + gboolean initial_audio, + gboolean initial_video) +{ + return tp_asv_new ( + TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING, + TPY_IFACE_CHANNEL_TYPE_CALL, + TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, G_TYPE_UINT, + TP_HANDLE_TYPE_CONTACT, + TP_PROP_CHANNEL_TARGET_ID, G_TYPE_STRING, + contact, + TPY_PROP_CHANNEL_TYPE_CALL_INITIAL_AUDIO, G_TYPE_BOOLEAN, + initial_audio, + TPY_PROP_CHANNEL_TYPE_CALL_INITIAL_VIDEO, G_TYPE_BOOLEAN, + initial_video, + NULL); +} + +GHashTable * +empathy_call_create_streamed_media_request (const gchar *contact, + gboolean initial_audio, + gboolean initial_video) +{ + return tp_asv_new ( + TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING, + TP_IFACE_CHANNEL_TYPE_STREAMED_MEDIA, + TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, G_TYPE_UINT, + TP_HANDLE_TYPE_CONTACT, + TP_PROP_CHANNEL_TARGET_ID, G_TYPE_STRING, + contact, + TP_PROP_CHANNEL_TYPE_STREAMED_MEDIA_INITIAL_AUDIO, G_TYPE_BOOLEAN, + initial_audio, + TP_PROP_CHANNEL_TYPE_STREAMED_MEDIA_INITIAL_VIDEO, G_TYPE_BOOLEAN, + initial_video, + NULL); +} + +static void +create_call_channel_cb (GObject *source, + GAsyncResult *result, + gpointer user_data) +{ + GError *error = NULL; + + if (!tp_account_channel_request_create_channel_finish ( + TP_ACCOUNT_CHANNEL_REQUEST (source), + result, + &error)) + { + DEBUG ("Failed to create Call channel: %s", error->message); + show_call_error (error); + g_error_free (error); + } +} + +static void +create_streamed_media_channel_cb (GObject *source, + GAsyncResult *result, + gpointer user_data) +{ + TpAccountChannelRequest *call_req = user_data; + GError *error = NULL; + + if (tp_account_channel_request_create_channel_finish ( + TP_ACCOUNT_CHANNEL_REQUEST (source), result, &error)) + { + g_object_unref (call_req); + return; + } + + DEBUG ("Failed to create StreamedMedia channel: %s", error->message); + + if (error->code != TP_ERROR_NOT_IMPLEMENTED) + { + show_call_error (error); + return; + } + + DEBUG ("Let's try with a Call channel"); + g_error_free (error); + tp_account_channel_request_create_channel_async (call_req, + EMPATHY_CALL_BUS_NAME, NULL, + create_call_channel_cb, + NULL); +} + +void +empathy_call_new_with_streams (const gchar *contact, + TpAccount *account, + gboolean initial_audio, + gboolean initial_video, + gint64 timestamp) +{ + GHashTable *call_request, *streamed_media_request; + TpAccountChannelRequest *call_req, *streamed_media_req; + + call_request = empathy_call_create_call_request (contact, + initial_audio, + initial_video); + + streamed_media_request = empathy_call_create_streamed_media_request ( + contact, initial_audio, initial_video); + + call_req = tp_account_channel_request_new (account, call_request, timestamp); + streamed_media_req = tp_account_channel_request_new (account, + streamed_media_request, + timestamp); + + tp_account_channel_request_create_channel_async (streamed_media_req, + EMPATHY_AV_BUS_NAME, NULL, + create_streamed_media_channel_cb, + call_req); + + g_hash_table_unref (call_request); + g_hash_table_unref (streamed_media_request); + g_object_unref (streamed_media_req); +} diff --git a/libempathy-gtk/empathy-call-utils.h b/libempathy-gtk/empathy-call-utils.h new file mode 100644 index 000000000..99a97f202 --- /dev/null +++ b/libempathy-gtk/empathy-call-utils.h @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2011 Collabora Ltd. + * + * The code contained in this file is free software; you can redistribute + * it and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either version + * 2.1 of the License, or (at your option) any later version. + * + * This file is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this code; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Authors: Emilio Pozuelo Monfort <emilio.pozuelo@collabora.co.uk> + */ + +#ifndef __EMPATHY_CALL_UTILS_H__ +#define __EMPATHY_CALL_UTILS_H__ + +G_BEGIN_DECLS + +/* Calls */ +void empathy_call_new_with_streams (const gchar *contact, + TpAccount *account, + gboolean initial_audio, + gboolean initial_video, + gint64 timestamp); + +GHashTable * empathy_call_create_call_request (const gchar *contact, + gboolean initial_audio, + gboolean initial_video); + +GHashTable * empathy_call_create_streamed_media_request (const gchar *contact, + gboolean initial_audio, + gboolean initial_video); + +G_END_DECLS + +#endif /* __EMPATHY_CALL_UTILS_H__ */ diff --git a/libempathy-gtk/empathy-contact-menu.c b/libempathy-gtk/empathy-contact-menu.c index ecdbee1ba..60e7052ea 100644 --- a/libempathy-gtk/empathy-contact-menu.c +++ b/libempathy-gtk/empathy-contact-menu.c @@ -39,6 +39,7 @@ #include "empathy-contact-dialogs.h" #include "empathy-ui-utils.h" #include "empathy-share-my-desktop.h" +#include "empathy-call-utils.h" static GtkWidget *empathy_contact_block_menu_item_new (EmpathyContact *); @@ -343,7 +344,9 @@ static void empathy_contact_audio_call_menu_item_activated (GtkMenuItem *item, EmpathyContact *contact) { - empathy_call_new_with_streams (contact, TRUE, FALSE, + empathy_call_new_with_streams (empathy_contact_get_id (contact), + empathy_contact_get_account (contact), + TRUE, FALSE, empathy_get_current_action_time ()); } @@ -374,7 +377,9 @@ static void empathy_contact_video_call_menu_item_activated (GtkMenuItem *item, EmpathyContact *contact) { - empathy_call_new_with_streams (contact, TRUE, TRUE, + empathy_call_new_with_streams (empathy_contact_get_id (contact), + empathy_contact_get_account (contact), + TRUE, TRUE, empathy_get_current_action_time ()); } diff --git a/libempathy-gtk/empathy-individual-menu.c b/libempathy-gtk/empathy-individual-menu.c index 8a2654b8f..a92e5bcd9 100644 --- a/libempathy-gtk/empathy-individual-menu.c +++ b/libempathy-gtk/empathy-individual-menu.c @@ -46,6 +46,7 @@ #include "empathy-ui-utils.h" #include "empathy-share-my-desktop.h" #include "empathy-linking-dialog.h" +#include "empathy-call-utils.h" #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyIndividualMenu) @@ -617,7 +618,9 @@ empathy_individual_audio_call_menu_item_activated (GtkMenuItem *item, { g_return_if_fail (EMPATHY_IS_CONTACT (contact)); - empathy_call_new_with_streams (contact, TRUE, FALSE, + empathy_call_new_with_streams (empathy_contact_get_id (contact), + empathy_contact_get_account (contact), + TRUE, FALSE, empathy_get_current_action_time ()); } @@ -659,7 +662,9 @@ empathy_individual_video_call_menu_item_activated (GtkMenuItem *item, { g_return_if_fail (EMPATHY_IS_CONTACT (contact)); - empathy_call_new_with_streams (contact, TRUE, TRUE, + empathy_call_new_with_streams (empathy_contact_get_id (contact), + empathy_contact_get_account (contact), + TRUE, TRUE, empathy_get_current_action_time ()); } diff --git a/libempathy-gtk/empathy-new-call-dialog.c b/libempathy-gtk/empathy-new-call-dialog.c index 86430cd24..139eb1de5 100644 --- a/libempathy-gtk/empathy-new-call-dialog.c +++ b/libempathy-gtk/empathy-new-call-dialog.c @@ -28,6 +28,8 @@ #include <telepathy-glib/interfaces.h> +#include <telepathy-yell/telepathy-yell.h> + #include <libempathy/empathy-tp-contact-factory.h> #include <libempathy/empathy-contact-manager.h> #include <libempathy/empathy-utils.h> @@ -41,6 +43,7 @@ #include "empathy-new-call-dialog.h" #include "empathy-account-chooser.h" +#include "empathy-call-utils.h" static EmpathyNewCallDialog *dialog_singleton = NULL; @@ -62,21 +65,6 @@ struct _EmpathyNewCallDialogPriv { (G_TYPE_INSTANCE_GET_PRIVATE ((o), EMPATHY_TYPE_NEW_CALL_DIALOG, \ EmpathyNewCallDialogPriv)) -static void -create_media_channel_cb (GObject *source, - GAsyncResult *result, - gpointer user_data) -{ - GError *error = NULL; - - if (!tp_account_channel_request_create_channel_finish ( - TP_ACCOUNT_CHANNEL_REQUEST (source), result, &error)) - { - DEBUG ("Failed to create media channel: %s", error->message); - g_error_free (error); - } -} - /** * SECTION:empathy-new-call-dialog * @title: EmpathyNewCallDialog @@ -88,34 +76,6 @@ create_media_channel_cb (GObject *source, */ static void -call_contact (TpAccount *account, - const gchar *contact_id, - gboolean video, - gint64 timestamp) -{ - GHashTable *request; - TpAccountChannelRequest *req; - - request = tp_asv_new ( - TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING, - TP_IFACE_CHANNEL_TYPE_STREAMED_MEDIA, - TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, G_TYPE_UINT, TP_HANDLE_TYPE_CONTACT, - TP_PROP_CHANNEL_TARGET_ID, G_TYPE_STRING, contact_id, - TP_PROP_CHANNEL_TYPE_STREAMED_MEDIA_INITIAL_AUDIO, G_TYPE_BOOLEAN, - TRUE, - TP_PROP_CHANNEL_TYPE_STREAMED_MEDIA_INITIAL_VIDEO, G_TYPE_BOOLEAN, - video, - NULL); - - req = tp_account_channel_request_new (account, request, timestamp); - - tp_account_channel_request_create_channel_async (req, EMPATHY_AV_BUS_NAME, - NULL, create_media_channel_cb, NULL); - - g_object_unref (req); -} - -static void empathy_new_call_dialog_response (GtkDialog *dialog, int response_id) { EmpathyNewCallDialogPriv *priv = GET_PRIV (dialog); @@ -134,7 +94,8 @@ empathy_new_call_dialog_response (GtkDialog *dialog, int response_id) * we return from this function. */ video = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->check_video)); - call_contact (account, contact_id, video, + empathy_call_new_with_streams (contact_id, + account, TRUE, video, empathy_get_current_action_time ()); out: @@ -169,7 +130,8 @@ conn_prepared_cb (GObject *conn, chan_type = tp_asv_get_string (fixed, TP_PROP_CHANNEL_CHANNEL_TYPE); - if (tp_strdiff (chan_type, TP_IFACE_CHANNEL_TYPE_STREAMED_MEDIA)) + if (tp_strdiff (chan_type, TP_IFACE_CHANNEL_TYPE_STREAMED_MEDIA) + && tp_strdiff (chan_type, TPY_IFACE_CHANNEL_TYPE_CALL)) continue; if (tp_asv_get_uint32 (fixed, TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, NULL) != |