diff options
-rw-r--r-- | libempathy/Makefile.am | 2 | ||||
-rw-r--r-- | libempathy/empathy-dispatcher.c | 1 | ||||
-rw-r--r-- | libempathy/empathy-tube-handler.c | 288 | ||||
-rw-r--r-- | libempathy/empathy-tube-handler.h | 64 | ||||
-rw-r--r-- | po/POTFILES.in | 1 | ||||
-rw-r--r-- | src/.gitignore | 3 | ||||
-rw-r--r-- | src/Makefile.am | 5 | ||||
-rw-r--r-- | src/empathy-tube-dispatch.c | 467 | ||||
-rw-r--r-- | src/empathy-tube-dispatch.h | 75 |
9 files changed, 1 insertions, 905 deletions
diff --git a/libempathy/Makefile.am b/libempathy/Makefile.am index 4d5acc63a..fa62d0cd7 100644 --- a/libempathy/Makefile.am +++ b/libempathy/Makefile.am @@ -61,7 +61,6 @@ libempathy_headers = \ empathy-tp-contact-list.h \ empathy-tp-file.h \ empathy-tp-roomlist.h \ - empathy-tube-handler.h \ empathy-types.h \ empathy-utils.h @@ -102,7 +101,6 @@ libempathy_la_SOURCES = \ empathy-tp-contact-list.c \ empathy-tp-file.c \ empathy-tp-roomlist.c \ - empathy-tube-handler.c \ empathy-utils.c # do not distribute generated files diff --git a/libempathy/empathy-dispatcher.c b/libempathy/empathy-dispatcher.c index c096bd231..201e48409 100644 --- a/libempathy/empathy-dispatcher.c +++ b/libempathy/empathy-dispatcher.c @@ -45,7 +45,6 @@ #include "empathy-dispatcher.h" #include "empathy-handler.h" #include "empathy-utils.h" -#include "empathy-tube-handler.h" #include "empathy-tp-contact-factory.h" #include "empathy-chatroom-manager.h" #include "empathy-utils.h" diff --git a/libempathy/empathy-tube-handler.c b/libempathy/empathy-tube-handler.c deleted file mode 100644 index 2b50ec852..000000000 --- a/libempathy/empathy-tube-handler.c +++ /dev/null @@ -1,288 +0,0 @@ -/* - * Copyright (C) 2008 Collabora Ltd. - * - * This library 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 library 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 library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - * Authors: Xavier Claessens <xclaesse@gmail.com> - * Elliot Fairweather <elliot.fairweather@collabora.co.uk> - */ - -#include <config.h> - -#include <dbus/dbus-glib.h> - -#include <telepathy-glib/dbus.h> -#include <telepathy-glib/connection.h> -#include <telepathy-glib/channel.h> -#include <telepathy-glib/interfaces.h> -#include <telepathy-glib/util.h> - -#include <extensions/extensions.h> - -#include "empathy-tube-handler.h" - -#define DEBUG_FLAG EMPATHY_DEBUG_OTHER -#include "empathy-debug.h" - -static void empathy_tube_handler_iface_init (EmpSvcTubeHandlerClass *klass); - -enum -{ - NEW_TUBE, - LAST_SIGNAL -}; - -static guint signals[LAST_SIGNAL]; - -G_DEFINE_TYPE_WITH_CODE (EmpathyTubeHandler, empathy_tube_handler, - G_TYPE_OBJECT, G_IMPLEMENT_INTERFACE (EMP_TYPE_SVC_TUBE_HANDLER, - empathy_tube_handler_iface_init)) - -typedef struct -{ - EmpathyTubeHandler *thandler; - gchar *bus_name; - gchar *connection; - gchar *channel; - guint handle_type; - guint handle; - TpChannel *tube; -} IdleData; - -static void -tube_ready_destroy_notify (gpointer data) -{ - IdleData *idle_data = data; - - g_object_unref (idle_data->tube); - g_free (idle_data->bus_name); - g_free (idle_data->connection); - g_free (idle_data->channel); - g_slice_free (IdleData, idle_data); -} - -static void -channel_ready_cb (TpChannel *channel, - const GError *error, - gpointer data) -{ - IdleData *idle_data = data; - - if (error != NULL) - { - DEBUG ("channel has been invalidated: %s", error->message); - tube_ready_destroy_notify (data); - g_object_unref (channel); - return; - } - - g_signal_emit (idle_data->thandler, signals[NEW_TUBE], 0, idle_data->tube); - - g_object_unref (channel); -} - -static void -connection_ready_cb (TpConnection *connection, - const GError *error, - gpointer data) -{ - TpChannel *channel; - IdleData *idle_data = data; - - if (error != NULL) - { - DEBUG ("connection has been invalidated: %s", error->message); - tube_ready_destroy_notify (data); - g_object_unref (connection); - return; - } - - channel = tp_channel_new (connection, idle_data->channel, - TP_IFACE_CHANNEL_TYPE_TUBES, idle_data->handle_type, - idle_data->handle, NULL); - tp_channel_call_when_ready (channel, channel_ready_cb, idle_data); - - g_object_unref (connection); -} - -static gboolean -tube_handler_handle_tube_idle_cb (gpointer data) -{ - IdleData *idle_data = data; - TpConnection *connection; - static TpDBusDaemon *daemon = NULL; - - DEBUG ("New tube to be handled"); - - if (!daemon) - daemon = tp_dbus_daemon_new (tp_get_bus ()); - - connection = tp_connection_new (daemon, idle_data->bus_name, - idle_data->connection, NULL); - tp_connection_call_when_ready (connection, - connection_ready_cb, idle_data); - - return FALSE; -} - -static void -tube_handler_handle_tube (EmpSvcTubeHandler *self, - const gchar *bus_name, - const gchar *connection, - const gchar *channel, - guint handle_type, - guint handle, - DBusGMethodInvocation *context) -{ - EmpathyTubeHandler *thandler = EMPATHY_TUBE_HANDLER (self); - IdleData *data; - - data = g_slice_new (IdleData); - data->thandler = thandler; - data->bus_name = g_strdup (bus_name); - data->connection = g_strdup (connection); - data->channel = g_strdup (channel); - data->handle_type = handle_type; - data->handle = handle; - - g_idle_add_full (G_PRIORITY_HIGH, tube_handler_handle_tube_idle_cb, - data, NULL); - - emp_svc_tube_handler_return_from_handle_tube (context); -} - -static void -empathy_tube_handler_class_init (EmpathyTubeHandlerClass *klass) -{ - signals[NEW_TUBE] = - g_signal_new ("new-tube", G_OBJECT_CLASS_TYPE (klass), - G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__OBJECT, - G_TYPE_NONE, 1, TP_TYPE_CHANNEL); -} - -static void -empathy_tube_handler_iface_init (EmpSvcTubeHandlerClass *klass) -{ - emp_svc_tube_handler_implement_handle_tube (klass, - tube_handler_handle_tube); -} - -static void -empathy_tube_handler_init (EmpathyTubeHandler *thandler) -{ -} - -EmpathyTubeHandler * -empathy_tube_handler_new (TpTubeType type, - const gchar *service) -{ - EmpathyTubeHandler *thandler = NULL; - DBusGProxy *proxy; - guint result; - gchar *bus_name; - gchar *object_path; - GError *error = NULL; - - g_return_val_if_fail (type < NUM_TP_TUBE_TYPES, NULL); - g_return_val_if_fail (service != NULL, NULL); - - bus_name = empathy_tube_handler_build_bus_name (type, service); - object_path = empathy_tube_handler_build_object_path (type, service); - - proxy = dbus_g_proxy_new_for_name (tp_get_bus (), DBUS_SERVICE_DBUS, - DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS); - - if (!dbus_g_proxy_call (proxy, "RequestName", &error, - G_TYPE_STRING, bus_name, G_TYPE_UINT, DBUS_NAME_FLAG_DO_NOT_QUEUE, - G_TYPE_INVALID, G_TYPE_UINT, &result, G_TYPE_INVALID)) - { - DEBUG ("Failed to request name: %s", - error ? error->message : "No error given"); - g_clear_error (&error); - goto OUT; - } - - DEBUG ("Creating tube handler %s", bus_name); - thandler = g_object_new (EMPATHY_TYPE_TUBE_HANDLER, NULL); - dbus_g_connection_register_g_object (tp_get_bus (), object_path, - G_OBJECT (thandler)); - -OUT: - g_object_unref (proxy); - g_free (bus_name); - g_free (object_path); - - return thandler; -} - -static gchar * -sanitize_service_name (const gchar *str) -{ - guint i; - gchar *result; - - g_assert (str != NULL); - result = g_strdup (str); - - for (i = 0; result[i] != '\0'; i++) - { - if (!g_ascii_isalnum (result[i])) - result[i] = '_'; - } - - return result; -} - -gchar * -empathy_tube_handler_build_bus_name (TpTubeType type, - const gchar *service) -{ - gchar *str = NULL; - const gchar *prefix = NULL; - gchar *service_escaped; - - g_return_val_if_fail (type < NUM_TP_TUBE_TYPES, NULL); - g_return_val_if_fail (service != NULL, NULL); - - if (type == TP_TUBE_TYPE_DBUS) - prefix = "org.gnome.Empathy.DTubeHandler."; - else if (type == TP_TUBE_TYPE_STREAM) - prefix = "org.gnome.Empathy.StreamTubeHandler."; - else - g_return_val_if_reached (NULL); - - service_escaped = sanitize_service_name (service); - str = g_strconcat (prefix, service_escaped, NULL); - g_free (service_escaped); - - return str; -} - -gchar * -empathy_tube_handler_build_object_path (TpTubeType type, - const gchar *service) -{ - gchar *bus_name; - gchar *str; - - g_return_val_if_fail (type < NUM_TP_TUBE_TYPES, NULL); - g_return_val_if_fail (service != NULL, NULL); - - bus_name = empathy_tube_handler_build_bus_name (type, service); - str = g_strdelimit (g_strdup_printf ("/%s", bus_name), ".", '/'); - g_free (bus_name); - - return str; -} diff --git a/libempathy/empathy-tube-handler.h b/libempathy/empathy-tube-handler.h deleted file mode 100644 index f20527a68..000000000 --- a/libempathy/empathy-tube-handler.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (C) 2008 Collabora Ltd. - * - * This library 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 library 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 library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - * Authors: Xavier Claessens <xclaesse@gmail.com> - * Elliot Fairweather <elliot.fairweather@collabora.co.uk> - */ - -#ifndef __EMPATHY_TUBE_HANDLER_H__ -#define __EMPATHY_TUBE_HANDLER_H__ - -#include <glib.h> - -#include <telepathy-glib/enums.h> - -G_BEGIN_DECLS - -#define EMPATHY_TYPE_TUBE_HANDLER (empathy_tube_handler_get_type ()) -#define EMPATHY_TUBE_HANDLER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), \ - EMPATHY_TYPE_TUBE_HANDLER, EmpathyTubeHandler)) -#define EMPATHY_TUBE_HANDLER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), \ - EMPATHY_TYPE_TUBE_HANDLER, EmpathyTubeHandlerClass)) -#define EMPATHY_IS_TUBE_HANDLER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), \ - EMPATHY_TYPE_TUBE_HANDLER)) -#define EMPATHY_IS_TUBE_HANDLER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), \ - EMPATHY_TYPE_TUBE_HANDLER)) -#define EMPATHY_TUBE_HANDLER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), \ - EMPATHY_TYPE_TUBE_HANDLER, EmpathyTubeHandlerClass)) - -typedef struct _EmpathyTubeHandler EmpathyTubeHandler; -typedef struct _EmpathyTubeHandlerClass EmpathyTubeHandlerClass; - -struct _EmpathyTubeHandler { - GObject parent; -}; - -struct _EmpathyTubeHandlerClass { - GObjectClass parent_class; -}; - -GType empathy_tube_handler_get_type (void) G_GNUC_CONST; -EmpathyTubeHandler *empathy_tube_handler_new (TpTubeType type, - const gchar *service); -gchar *empathy_tube_handler_build_bus_name (TpTubeType type, - const gchar *service); -gchar *empathy_tube_handler_build_object_path (TpTubeType type, - const gchar *service); - -G_END_DECLS - -#endif /* __EMPATHY_TUBE_HANDLER_H__ */ diff --git a/po/POTFILES.in b/po/POTFILES.in index 7075d27ae..573a45c36 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -83,7 +83,6 @@ src/empathy-preferences.c [type: gettext/glade]src/empathy-preferences.ui src/empathy-status-icon.c [type: gettext/glade]src/empathy-status-icon.ui -src/empathy-tube-dispatch.c [type: gettext/glade]src/empathy-call-window-fullscreen.ui src/empathy-map-view.c [type: gettext/glade]src/empathy-map-view.ui diff --git a/src/.gitignore b/src/.gitignore index 17f66a507..6e1baa592 100644 --- a/src/.gitignore +++ b/src/.gitignore @@ -2,9 +2,6 @@ empathy empathy-accounts empathy-chat-chandler empathy-call-chandler -empathy-tubes-chandler -empathy-tube-dispatch-enumtypes.c -empathy-tube-dispatch-enumtypes.h org.gnome.Empathy.Chat.service org.gnome.Empathy.Call.service org.gnome.Empathy.Tubes.service diff --git a/src/Makefile.am b/src/Makefile.am index c3f6582e7..6360dee09 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -23,9 +23,7 @@ LDADD = \ bin_PROGRAMS = \ empathy -BUILT_SOURCES= \ - empathy-tube-dispatch-enumtypes.h \ - empathy-tube-dispatch-enumtypes.c +BUILT_SOURCES= empathy_handwritten_source = \ empathy-about-dialog.c empathy-about-dialog.h \ @@ -49,7 +47,6 @@ empathy_handwritten_source = \ empathy-preferences.c empathy-preferences.h \ empathy-sidebar.c empathy-sidebar.h \ empathy-status-icon.c empathy-status-icon.h \ - empathy-tube-dispatch.c empathy-tube-dispatch.h \ empathy.c empathy_SOURCES = \ diff --git a/src/empathy-tube-dispatch.c b/src/empathy-tube-dispatch.c deleted file mode 100644 index 60f7f4b72..000000000 --- a/src/empathy-tube-dispatch.c +++ /dev/null @@ -1,467 +0,0 @@ -/* - * empathy-tube-dispatch.c - Source for EmpathyTubeDispatch - * Copyright (C) 2008 Collabora Ltd. - * @author Sjoerd Simons <sjoerd.simons@collabora.co.uk> - * - * This library 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 library 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 library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - - -#include <stdio.h> -#include <stdlib.h> - -#include <telepathy-glib/dbus.h> -#include <telepathy-glib/util.h> -#include <telepathy-glib/proxy-subclass.h> -#include <telepathy-glib/interfaces.h> - -#include <gtk/gtk.h> -#include <glib/gi18n.h> - - -#include <libempathy/empathy-tube-handler.h> -#include <extensions/extensions.h> - - -#include "empathy-tube-dispatch.h" -#include "empathy-tube-dispatch-enumtypes.h" - -#define DEBUG_FLAG EMPATHY_DEBUG_DISPATCHER -#include <libempathy/empathy-debug.h> - -G_DEFINE_TYPE(EmpathyTubeDispatch, empathy_tube_dispatch, G_TYPE_OBJECT) - -static void empathy_tube_dispatch_set_ability ( - EmpathyTubeDispatch *tube_dispatch, - EmpathyTubeDispatchAbility dispatchability); - -/* private structure */ -typedef struct _EmpathyTubeDispatchPriv EmpathyTubeDispatchPriv; - -/* properties */ -enum { - PROP_OPERATION = 1, - PROP_DISPATCHABILITY -}; - - -struct _EmpathyTubeDispatchPriv -{ - gboolean dispose_has_run; - EmpathyDispatchOperation *operation; - EmpathyTubeDispatchAbility dispatchability; - gchar *service; - gchar *bus_name; - gchar *object_path; - TpDBusDaemon *dbus; -}; - -#define GET_PRIV(o) \ - (G_TYPE_INSTANCE_GET_PRIVATE ((o), \ - EMPATHY_TYPE_TUBE_DISPATCH, EmpathyTubeDispatchPriv)) - -static void -empathy_tube_dispatch_init (EmpathyTubeDispatch *obj) -{ - EmpathyTubeDispatchPriv *priv = GET_PRIV (obj); - - priv->dispatchability = EMPATHY_TUBE_DISPATCHABILITY_UNKNOWN; -} - -static void empathy_tube_dispatch_dispose (GObject *object); -static void empathy_tube_dispatch_finalize (GObject *object); - -static void -empathy_tube_dispatch_list_activatable_names_cb (TpDBusDaemon *proxy, - const gchar **names, const GError *error, gpointer user_data, - GObject *object) -{ - EmpathyTubeDispatch *self = EMPATHY_TUBE_DISPATCH (object); - EmpathyTubeDispatchPriv *priv = GET_PRIV (self); - gchar **name; - - for (name = (gchar **) names; *name != NULL; name++) - { - if (!tp_strdiff (*name, priv->bus_name)) - { - DEBUG ("Found tube handler. Can dispatch it"); - empathy_tube_dispatch_set_ability (self, - EMPATHY_TUBE_DISPATCHABILITY_POSSIBLE); - return; - } - } - - DEBUG ("Didn't find tube handler. Can't dispatch it"); - empathy_tube_dispatch_set_ability (self, - EMPATHY_TUBE_DISPATCHABILITY_IMPOSSIBLE); -} - -static void -empathy_tube_dispatch_name_has_owner_cb (TpDBusDaemon *proxy, - gboolean has_owner, const GError *error, gpointer user_data, - GObject *object) -{ - EmpathyTubeDispatch *self = EMPATHY_TUBE_DISPATCH (object); - EmpathyTubeDispatchPriv *priv = GET_PRIV (self); - - if (error != NULL) - { - DEBUG ("NameHasOwner failed. Can't dispatch tube"); - empathy_tube_dispatch_set_ability (self, - EMPATHY_TUBE_DISPATCHABILITY_IMPOSSIBLE); - return; - } - - if (has_owner) - { - DEBUG ("Tube handler is running. Can dispatch it"); - empathy_tube_dispatch_set_ability (self, - EMPATHY_TUBE_DISPATCHABILITY_POSSIBLE); - } - else - { - DEBUG ("Tube handler is not running. Calling ListActivatableNames"); - tp_cli_dbus_daemon_call_list_activatable_names (priv->dbus, -1, - empathy_tube_dispatch_list_activatable_names_cb, NULL, NULL, - G_OBJECT (self)); - } -} - -static void -empathy_tube_dispatch_constructed (GObject *object) -{ - EmpathyTubeDispatch *self = EMPATHY_TUBE_DISPATCH (object); - EmpathyTubeDispatchPriv *priv = GET_PRIV (self); - TpChannel *channel; - GHashTable *properties; - const gchar *service; - const gchar *channel_type; - TpTubeType type; - - priv->dbus = tp_dbus_daemon_new (tp_get_bus ()); - - channel = empathy_dispatch_operation_get_channel (priv->operation); - properties = tp_channel_borrow_immutable_properties (channel); - - channel_type = tp_asv_get_string (properties, - TP_IFACE_CHANNEL ".ChannelType"); - if (channel_type == NULL) - goto failed; - - if (!tp_strdiff (channel_type, TP_IFACE_CHANNEL_TYPE_STREAM_TUBE)) - { - type = TP_TUBE_TYPE_STREAM; - service = tp_asv_get_string (properties, - TP_IFACE_CHANNEL_TYPE_STREAM_TUBE ".Service"); - } - else if (!tp_strdiff (channel_type, TP_IFACE_CHANNEL_TYPE_DBUS_TUBE)) - { - GError *error = NULL; - - type = TP_TUBE_TYPE_DBUS; - service = tp_asv_get_string (properties, - TP_IFACE_CHANNEL_TYPE_DBUS_TUBE ".ServiceName"); - - if (!tp_dbus_check_valid_bus_name (service, TP_DBUS_NAME_TYPE_WELL_KNOWN, - &error)) - { - DEBUG ("Can't dispatch tube; invalid ServiceName %s: %s", service, - error->message); - g_error_free (error); - goto failed; - } - } - else - { - goto failed; - } - - - if (service == NULL) - goto failed; - - priv->bus_name = empathy_tube_handler_build_bus_name (type, service); - priv->object_path = empathy_tube_handler_build_object_path (type, service); - - priv->service = g_strdup (service); - - DEBUG ("Look for tube handler %s\n", priv->bus_name); - tp_cli_dbus_daemon_call_name_has_owner (priv->dbus, -1, priv->bus_name, - empathy_tube_dispatch_name_has_owner_cb, NULL, NULL, G_OBJECT (self)); - - return; - -failed: - empathy_tube_dispatch_set_ability (self, - EMPATHY_TUBE_DISPATCHABILITY_IMPOSSIBLE); -} - -static void -empathy_tube_dispatch_set_property (GObject *object, - guint property_id, const GValue *value, GParamSpec *pspec) -{ - EmpathyTubeDispatch *tube_dispatch = EMPATHY_TUBE_DISPATCH (object); - EmpathyTubeDispatchPriv *priv = GET_PRIV (tube_dispatch); - - switch (property_id) - { - case PROP_OPERATION: - priv->operation = g_value_dup_object (value); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -static void -empathy_tube_dispatch_get_property (GObject *object, - guint property_id, GValue *value, GParamSpec *pspec) -{ - EmpathyTubeDispatch *tube_dispatch = EMPATHY_TUBE_DISPATCH (object); - EmpathyTubeDispatchPriv *priv = GET_PRIV (tube_dispatch); - - switch (property_id) - { - case PROP_OPERATION: - g_value_set_object (value, priv->operation); - break; - case PROP_DISPATCHABILITY: - g_value_set_enum (value, priv->dispatchability); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -static void -empathy_tube_dispatch_class_init ( - EmpathyTubeDispatchClass *empathy_tube_dispatch_class) -{ - GObjectClass *object_class = G_OBJECT_CLASS (empathy_tube_dispatch_class); - GParamSpec *param_spec; - - g_type_class_add_private (empathy_tube_dispatch_class, - sizeof (EmpathyTubeDispatchPriv)); - - object_class->set_property = empathy_tube_dispatch_set_property; - object_class->get_property = empathy_tube_dispatch_get_property; - - object_class->constructed = empathy_tube_dispatch_constructed; - object_class->dispose = empathy_tube_dispatch_dispose; - object_class->finalize = empathy_tube_dispatch_finalize; - - param_spec = g_param_spec_object ("operation", - "operation", "The telepathy connection", - EMPATHY_TYPE_DISPATCH_OPERATION, - G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_OPERATION, param_spec); - - param_spec = g_param_spec_enum ("dispatchability", - "dispatchability", - "Whether or not there is a handler to dispatch the operation to", - EMPATHY_TYPE_TUBE_DISPATCH_ABILITY, EMPATHY_TUBE_DISPATCHABILITY_UNKNOWN, - G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_DISPATCHABILITY, - param_spec); - -} - -void -empathy_tube_dispatch_dispose (GObject *object) -{ - EmpathyTubeDispatch *self = EMPATHY_TUBE_DISPATCH (object); - EmpathyTubeDispatchPriv *priv = GET_PRIV (self); - - if (priv->dispose_has_run) - return; - - priv->dispose_has_run = TRUE; - - /* release any references held by the object here */ - if (priv->operation != NULL) - g_object_unref (priv->operation); - - priv->operation = NULL; - - if (priv->dbus != NULL) - g_object_unref (priv->dbus); - - priv->dbus = NULL; - - - if (G_OBJECT_CLASS (empathy_tube_dispatch_parent_class)->dispose) - G_OBJECT_CLASS (empathy_tube_dispatch_parent_class)->dispose (object); -} - -void -empathy_tube_dispatch_finalize (GObject *object) -{ - EmpathyTubeDispatch *self = EMPATHY_TUBE_DISPATCH (object); - EmpathyTubeDispatchPriv *priv = GET_PRIV (self); - - g_free (priv->bus_name); - g_free (priv->object_path); - g_free (priv->service); - - /* free any data held directly by the object here */ - - G_OBJECT_CLASS (empathy_tube_dispatch_parent_class)->finalize (object); -} - -EmpathyTubeDispatch * -empathy_tube_dispatch_new (EmpathyDispatchOperation *operation) -{ - return EMPATHY_TUBE_DISPATCH (g_object_new (EMPATHY_TYPE_TUBE_DISPATCH, - "operation", operation, NULL)); -} - -EmpathyTubeDispatchAbility -empathy_tube_dispatch_is_dispatchable (EmpathyTubeDispatch *tube_dispatch) -{ - EmpathyTubeDispatchPriv *priv = GET_PRIV (tube_dispatch); - - return priv->dispatchability; -} - -static void -empathy_tube_dispatch_set_ability (EmpathyTubeDispatch *tube_dispatch, - EmpathyTubeDispatchAbility dispatchability) -{ - EmpathyTubeDispatchPriv *priv = GET_PRIV (tube_dispatch); - - if (priv->dispatchability == dispatchability) - return; - - priv->dispatchability = dispatchability; - g_object_notify (G_OBJECT (tube_dispatch), "dispatchability"); -} - -static void -empathy_tube_dispatch_show_error (EmpathyTubeDispatch *self, gchar *message) -{ - GtkWidget *dialog; - - dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, - GTK_MESSAGE_WARNING, GTK_BUTTONS_CLOSE, "%s", message); - - gtk_dialog_run (GTK_DIALOG (dialog)); - - gtk_widget_destroy (dialog); -} - -static void -empathy_tube_dispatch_handle_tube_cb (TpProxy *proxy, const GError *error, - gpointer user_data, GObject *object) -{ - EmpathyTubeDispatch *self = EMPATHY_TUBE_DISPATCH (object); - EmpathyTubeDispatchPriv *priv = GET_PRIV (self); - - if (error != NULL) - { - gchar *msg = g_strdup_printf ( - _("Unable to start application for service %s: %s"), - priv->service, error->message); - - empathy_tube_dispatch_show_error (self, msg); - g_free (msg); - } - - /* Remove the ref we were holding because of the dispatching */ - g_object_unref (object); -} - -static void -empathy_tube_do_dispatch (EmpathyTubeDispatch *self) -{ - EmpathyTubeDispatchPriv *priv = GET_PRIV (self); - TpChannel *channel; - TpProxy *connection; - TpProxy *thandler; - gchar *object_path; - guint handle_type; - guint handle; - - channel = empathy_dispatch_operation_get_channel (priv->operation); - - /* Create the proxy for the tube handler */ - thandler = g_object_new (TP_TYPE_PROXY, - "dbus-connection", tp_get_bus (), - "bus-name", priv->bus_name, - "object-path", priv->object_path, - NULL); - - tp_proxy_add_interface_by_id (thandler, EMP_IFACE_QUARK_TUBE_HANDLER); - - /* Give the tube to the handler */ - g_object_get (channel, - "connection", &connection, - "object-path", &object_path, - "handle_type", &handle_type, - "handle", &handle, - NULL); - - emp_cli_tube_handler_call_handle_tube (thandler, -1, - connection->bus_name, connection->object_path, - object_path, handle_type, handle, - empathy_tube_dispatch_handle_tube_cb, NULL, NULL, G_OBJECT (self)); - - g_object_unref (thandler); - g_object_unref (connection); - g_free (object_path); -} - -void -empathy_tube_dispatch_handle (EmpathyTubeDispatch *tube_dispatch) -{ - EmpathyTubeDispatchPriv *priv = GET_PRIV (tube_dispatch); - - /* Keep ourselves alive untill the dispatching is finished */ - g_object_ref (tube_dispatch); - - /* If we can't claim it, don't do anything */ - if (!empathy_dispatch_operation_claim (priv->operation)) - goto done; - - if (priv->dispatchability != EMPATHY_TUBE_DISPATCHABILITY_POSSIBLE) - { - gchar *msg; - TpChannel *channel; - - channel = empathy_dispatch_operation_get_channel (priv->operation); - - msg = g_strdup_printf ( - _("An invitation was offered for service %s, but you don't have the " - "application necessary to handle it"), priv->service); - - empathy_tube_dispatch_show_error (tube_dispatch, msg); - - g_free (msg); - - tp_cli_channel_call_close (channel, -1, NULL, NULL, NULL, NULL); - - goto done; - } - else - { - empathy_tube_do_dispatch (tube_dispatch); - } - - return; -done: - g_object_unref (tube_dispatch); -} - diff --git a/src/empathy-tube-dispatch.h b/src/empathy-tube-dispatch.h deleted file mode 100644 index 844c88145..000000000 --- a/src/empathy-tube-dispatch.h +++ /dev/null @@ -1,75 +0,0 @@ -/* - * empathy-tube-dispatch.h - Header for EmpathyTubeDispatch - * Copyright (C) 2008 Collabora Ltd. - * @author Sjoerd Simons <sjoerd.simons@collabora.co.uk> - * - * This library 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 library 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 library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#ifndef __EMPATHY_TUBE_DISPATCH_H__ -#define __EMPATHY_TUBE_DISPATCH_H__ - -#include <glib-object.h> - -#include <libempathy/empathy-dispatch-operation.h> - -G_BEGIN_DECLS - -typedef enum { - EMPATHY_TUBE_DISPATCHABILITY_UNKNOWN, - EMPATHY_TUBE_DISPATCHABILITY_POSSIBLE, - EMPATHY_TUBE_DISPATCHABILITY_IMPOSSIBLE, -} EmpathyTubeDispatchAbility; - -typedef struct _EmpathyTubeDispatch EmpathyTubeDispatch; -typedef struct _EmpathyTubeDispatchClass EmpathyTubeDispatchClass; - -struct _EmpathyTubeDispatchClass { - GObjectClass parent_class; -}; - -struct _EmpathyTubeDispatch { - GObject parent; -}; - -GType empathy_tube_dispatch_get_type (void); - -/* TYPE MACROS */ -#define EMPATHY_TYPE_TUBE_DISPATCH \ - (empathy_tube_dispatch_get_type ()) -#define EMPATHY_TUBE_DISPATCH(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST((obj), EMPATHY_TYPE_TUBE_DISPATCH, \ - EmpathyTubeDispatch)) -#define EMPATHY_TUBE_DISPATCH_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST((klass), EMPATHY_TYPE_TUBE_DISPATCH, \ - EmpathyTubeDispatchClass)) -#define EMPATHY_IS_TUBE_DISPATCH(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE((obj), EMPATHY_TYPE_TUBE_DISPATCH)) -#define EMPATHY_IS_TUBE_DISPATCH_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE((klass), EMPATHY_TYPE_TUBE_DISPATCH)) -#define EMPATHY_TUBE_DISPATCH_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS ((obj), EMPATHY_TYPE_TUBE_DISPATCH, \ - EmpathyTubeDispatchClass)) - -EmpathyTubeDispatch * empathy_tube_dispatch_new ( - EmpathyDispatchOperation *operation); - -EmpathyTubeDispatchAbility empathy_tube_dispatch_is_dispatchable ( - EmpathyTubeDispatch *tube_dispatch); -void empathy_tube_dispatch_handle (EmpathyTubeDispatch *tube_dispatch); - -G_END_DECLS - -#endif /* #ifndef __EMPATHY_TUBE_DISPATCH_H__*/ |