]> git.0d.be Git - empathy.git/blobdiff - src/empathy-tube-dispatch.c
Merge branch 'irc-dialog-579800'
[empathy.git] / src / empathy-tube-dispatch.c
index 31775a6d330514a22ce10f5f922417073a11e9aa..63b31b2b6f1e190b624ea963cbe443d190d5d59b 100644 (file)
@@ -37,6 +37,8 @@
 #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)
 
@@ -93,12 +95,14 @@ empathy_tube_dispatch_list_activatable_names_cb (TpDBusDaemon *proxy,
     {
       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);
 }
@@ -113,6 +117,7 @@ empathy_tube_dispatch_name_has_owner_cb (TpDBusDaemon *proxy,
 
   if (error != NULL)
     {
+      DEBUG ("NameHasOwner failed. Can't dispatch tube");
       empathy_tube_dispatch_set_ability (self,
         EMPATHY_TUBE_DISPATCHABILITY_IMPOSSIBLE);
       return;
@@ -120,11 +125,13 @@ empathy_tube_dispatch_name_has_owner_cb (TpDBusDaemon *proxy,
 
   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));
@@ -139,30 +146,60 @@ empathy_tube_dispatch_constructed (GObject *object)
   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);
 
-  service = tp_asv_get_string (properties,
-    EMP_IFACE_CHANNEL_TYPE_STREAM_TUBE  ".Service");
+  channel_type = tp_asv_get_string (properties,
+    TP_IFACE_CHANNEL ".ChannelType");
+  if (channel_type == NULL)
+    goto failed;
+
+  if (!tp_strdiff (channel_type, EMP_IFACE_CHANNEL_TYPE_STREAM_TUBE))
+    {
+      type = TP_TUBE_TYPE_STREAM;
+      service = tp_asv_get_string (properties,
+        EMP_IFACE_CHANNEL_TYPE_STREAM_TUBE  ".Service");
+    }
+  else if (!tp_strdiff (channel_type, EMP_IFACE_CHANNEL_TYPE_DBUS_TUBE))
+    {
+      GError *error = NULL;
+
+      type = TP_TUBE_TYPE_DBUS;
+      service = tp_asv_get_string (properties,
+        EMP_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 (
-    TP_TUBE_TYPE_STREAM, service);
-  priv->object_path =
-    empathy_tube_handler_build_object_path (TP_TUBE_TYPE_STREAM, service);
+  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));
 
-
-  g_object_unref (channel);
   return;
 
 failed:
@@ -318,7 +355,7 @@ 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, message);
+      GTK_MESSAGE_WARNING, GTK_BUTTONS_CLOSE, "%s", message);
 
   gtk_dialog_run (GTK_DIALOG (dialog));
 
@@ -359,7 +396,6 @@ empathy_tube_do_dispatch (EmpathyTubeDispatch *self)
 
   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 (),
@@ -382,7 +418,6 @@ empathy_tube_do_dispatch (EmpathyTubeDispatch *self)
     object_path, handle_type, handle,
     empathy_tube_dispatch_handle_tube_cb, NULL, NULL, G_OBJECT (self));
 
-  g_object_unref (channel);
   g_object_unref (thandler);
   g_object_unref (connection);
   g_free (object_path);
@@ -408,15 +443,14 @@ empathy_tube_dispatch_handle (EmpathyTubeDispatch *tube_dispatch)
       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"
-          " needed application to handle it "), priv->service);
+        _("An invitation was offered for service %s, but you don't have the "
+          "needed application 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);
-      g_object_unref (channel);
 
       goto done;
     }