]> git.0d.be Git - empathy.git/blobdiff - libempathy/empathy-dispatch-operation.c
Merge branch 'ft_rework'
[empathy.git] / libempathy / empathy-dispatch-operation.c
index def9e43e18ccfd4f9f3d00c0e49a4b3dfff0b9f8..7a116f870689ff3d7845d7366d3f3c8c6f0e1a14 100644 (file)
 
 #include "empathy-dispatch-operation.h"
 #include <libempathy/empathy-enum-types.h>
+#include <libempathy/empathy-tp-contact-factory.h>
 #include <libempathy/empathy-tp-chat.h>
 #include <libempathy/empathy-tp-call.h>
 #include <libempathy/empathy-tp-file.h>
 
 #include "empathy-marshal.h"
 
+#include "extensions/extensions.h"
+
 #define DEBUG_FLAG EMPATHY_DEBUG_DISPATCHER
 #include <libempathy/empathy-debug.h>
 
@@ -170,11 +173,38 @@ empathy_dispatch_operation_invalidated (TpProxy *proxy, guint domain,
   g_signal_emit (self, signals[INVALIDATED], 0, domain, code, message);
 }
 
+static void
+dispatcher_operation_got_contact_cb (EmpathyTpContactFactory *factory,
+                                     EmpathyContact *contact,
+                                     const GError *error,
+                                     gpointer user_data,
+                                     GObject *self)
+{
+  EmpathyDispatchOperationPriv *priv = GET_PRIV (self);
+
+  if (error)
+    {
+      /* FIXME: We should cancel the operation */
+      DEBUG ("Error: %s", error->message);
+      return;
+    }
+
+  if (priv->contact != NULL)
+    g_object_unref (priv->contact);
+  priv->contact = g_object_ref (contact);
+  g_object_notify (G_OBJECT (self), "contact");
+
+  tp_channel_call_when_ready (priv->channel,
+    empathy_dispatch_operation_channel_ready_cb, self);
+}
+
 static void
 empathy_dispatch_operation_constructed (GObject *object)
 {
   EmpathyDispatchOperation *self = EMPATHY_DISPATCH_OPERATION (object);
   EmpathyDispatchOperationPriv *priv = GET_PRIV (self);
+  TpHandle handle;
+  TpHandleType handle_type;
 
   empathy_dispatch_operation_set_status (self,
     EMPATHY_DISPATCHER_OPERATION_STATE_PREPARING);
@@ -183,6 +213,19 @@ empathy_dispatch_operation_constructed (GObject *object)
     g_signal_connect (priv->channel, "invalidated",
       G_CALLBACK (empathy_dispatch_operation_invalidated), self);
 
+  handle = tp_channel_get_handle (priv->channel, &handle_type);
+
+  if (handle_type == TP_CONN_HANDLE_TYPE_CONTACT && priv->contact == NULL)
+    {
+      EmpathyTpContactFactory *factory;
+
+      factory = empathy_tp_contact_factory_dup_singleton (priv->connection);
+      empathy_tp_contact_factory_get_from_handle (factory, handle,
+       dispatcher_operation_got_contact_cb, NULL, NULL, object);
+      g_object_unref (factory);
+      return;
+    }
+
   tp_channel_call_when_ready (priv->channel,
     empathy_dispatch_operation_channel_ready_cb, self);
 }
@@ -235,7 +278,7 @@ empathy_dispatch_operation_class_init (
       0,
       NULL, NULL,
       _empathy_marshal_VOID__UINT_INT_STRING,
-      G_TYPE_NONE, 0);
+      G_TYPE_NONE, 3, G_TYPE_UINT, G_TYPE_INT, G_TYPE_STRING);
 
   param_spec = g_param_spec_object ("connection",
     "connection", "The telepathy connection",
@@ -370,6 +413,10 @@ empathy_dispatch_operation_channel_ready_cb (TpChannel *channel,
   EmpathyDispatchOperationPriv *priv = GET_PRIV (self);
   GQuark channel_type;
 
+  /* The error will be handled in empathy_dispatch_operation_invalidated */
+  if (error != NULL)
+    return;
+
   g_assert (channel == priv->channel);
 
   /* If the channel wrapper is defined, we assume it's ready */
@@ -387,27 +434,23 @@ empathy_dispatch_operation_channel_ready_cb (TpChannel *channel,
         {
           priv->ready_handler = g_signal_connect (chat, "notify::ready",
             G_CALLBACK (empathy_dispatcher_operation_tp_chat_ready_cb), self);
-          goto readying;
+          return;
         }
-
     }
   else if (channel_type == TP_IFACE_QUARK_CHANNEL_TYPE_STREAMED_MEDIA)
     {
-       EmpathyTpCall *call = empathy_tp_call_new (channel);
-       priv->channel_wrapper = G_OBJECT (call);
-
+      EmpathyTpCall *call = empathy_tp_call_new (channel);
+      priv->channel_wrapper = G_OBJECT (call);
     }
-  else if (channel_type == EMP_IFACE_QUARK_CHANNEL_TYPE_FILE_TRANSFER)
+  else if (channel_type == TP_IFACE_QUARK_CHANNEL_TYPE_FILE_TRANSFER)
     {
-       EmpathyTpFile *file = empathy_tp_file_new (channel);
+       EmpathyTpFile *file = empathy_tp_file_new (channel, priv->incoming);
        priv->channel_wrapper = G_OBJECT (file);
     }
 
 ready:
   empathy_dispatch_operation_set_status (self,
     EMPATHY_DISPATCHER_OPERATION_STATE_PENDING);
-readying:
-  return;
 }
 
 EmpathyDispatchOperation *
@@ -475,12 +518,18 @@ empathy_dispatch_operation_approve (EmpathyDispatchOperation *operation)
 
       g_signal_emit (operation, signals[APPROVED], 0);
     }
-  else
+  else if (priv->status < EMPATHY_DISPATCHER_OPERATION_STATE_APPROVING)
     {
       DEBUG ("Pre-approving operation %s",
         empathy_dispatch_operation_get_object_path (operation));
       priv->approved = TRUE;
     }
+  else
+    {
+      DEBUG (
+        "Ignoring approval for %s as it's already past the approval stage",
+        empathy_dispatch_operation_get_object_path (operation));
+    }
 }
 
 /* Returns whether or not the operation was successfully claimed */
@@ -514,7 +563,7 @@ empathy_dispatch_operation_get_tp_connection (
 
   priv = GET_PRIV (operation);
 
-  return g_object_ref (priv->connection);
+  return priv->connection;
 }
 
 TpChannel *