]> git.0d.be Git - empathy.git/blobdiff - libempathy/empathy-dispatch-operation.c
add myself to AUTHORS
[empathy.git] / libempathy / empathy-dispatch-operation.c
index 2a98b912a04c4717670a102ff12408d82f39921e..20ebadb83c611c81f5a6a9d83ea25afb91b92c4a 100644 (file)
@@ -22,6 +22,8 @@
 #include <stdio.h>
 #include <stdlib.h>
 
+#include <telepathy-glib/interfaces.h>
+
 #include "empathy-dispatch-operation.h"
 #include <libempathy/empathy-enum-types.h>
 #include <libempathy/empathy-tp-contact-factory.h>
@@ -194,10 +196,42 @@ dispatcher_operation_got_contact_cb (EmpathyTpContactFactory *factory,
   priv->contact = g_object_ref (contact);
   g_object_notify (G_OBJECT (self), "contact");
 
+  /* Ensure to keep the self object alive while the call_when_ready is
+   * running */
+  g_object_ref (self);
   tp_channel_call_when_ready (priv->channel,
     empathy_dispatch_operation_channel_ready_cb, self);
 }
 
+static void
+dispatch_operation_connection_ready (TpConnection *connection,
+    const GError *error,
+    gpointer user_data)
+{
+  EmpathyDispatchOperation *self = EMPATHY_DISPATCH_OPERATION (user_data);
+  EmpathyDispatchOperationPriv *priv = GET_PRIV (self);
+  EmpathyTpContactFactory *factory;
+  TpHandle handle;
+
+  if (error != NULL)
+    goto out;
+
+  if (priv->status >= EMPATHY_DISPATCHER_OPERATION_STATE_CLAIMED)
+    /* no point to get more information */
+    goto out;
+
+  handle = tp_channel_get_handle (priv->channel, NULL);
+
+  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, G_OBJECT (self));
+
+  g_object_unref (factory);
+out:
+  g_object_unref (self);
+}
+
 static void
 empathy_dispatch_operation_constructed (GObject *object)
 {
@@ -215,17 +249,17 @@ empathy_dispatch_operation_constructed (GObject *object)
 
   handle = tp_channel_get_handle (priv->channel, &handle_type);
 
-  if (handle_type == TP_CONN_HANDLE_TYPE_CONTACT && priv->contact == NULL)
+  if (handle_type == TP_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);
+      /* Ensure to keep the self object alive while the call_when_ready is
+       * running */
+      g_object_ref (self);
+      tp_connection_call_when_ready (priv->connection,
+          dispatch_operation_connection_ready, object);
       return;
     }
 
+  g_object_ref (self);
   tp_channel_call_when_ready (priv->channel,
     empathy_dispatch_operation_channel_ready_cb, self);
 }
@@ -339,18 +373,16 @@ empathy_dispatch_operation_dispose (GObject *object)
 
   g_object_unref (priv->connection);
 
-  if (priv->channel_wrapper != NULL)
-    g_object_unref (priv->channel_wrapper);
-
   if (priv->ready_handler != 0)
     g_signal_handler_disconnect (priv->channel_wrapper,
-      priv->invalidated_handler);
+      priv->ready_handler);
 
+  if (priv->channel_wrapper != NULL)
+    g_object_unref (priv->channel_wrapper);
 
   g_signal_handler_disconnect (priv->channel, priv->invalidated_handler);
   g_object_unref (priv->channel);
 
-
   if (priv->contact != NULL)
     g_object_unref (priv->contact);
 
@@ -405,23 +437,6 @@ empathy_dispatcher_operation_tp_chat_ready_cb (GObject *object,
     EMPATHY_DISPATCHER_OPERATION_STATE_PENDING);
 }
 
-static void
-empathy_dispatcher_operation_tp_file_ready_cb (GObject *object,
-  GParamSpec *spec, gpointer user_data)
-{
-  EmpathyDispatchOperation *self = EMPATHY_DISPATCH_OPERATION (user_data);
-  EmpathyDispatchOperationPriv *priv = GET_PRIV (self);
-
-  if (!empathy_tp_file_is_ready (EMPATHY_TP_FILE (priv->channel_wrapper)))
-    return;
-
-  g_signal_handler_disconnect (priv->channel_wrapper, priv->ready_handler);
-  priv->ready_handler = 0;
-
-  empathy_dispatch_operation_set_status (self,
-    EMPATHY_DISPATCHER_OPERATION_STATE_PENDING);
-}
-
 static void
 empathy_dispatch_operation_channel_ready_cb (TpChannel *channel,
   const GError *error, gpointer user_data)
@@ -432,10 +447,14 @@ empathy_dispatch_operation_channel_ready_cb (TpChannel *channel,
 
   /* The error will be handled in empathy_dispatch_operation_invalidated */
   if (error != NULL)
-    return;
+    goto out;
 
   g_assert (channel == priv->channel);
 
+  if (priv->status >= EMPATHY_DISPATCHER_OPERATION_STATE_CLAIMED)
+    /* no point to get more information */
+    goto out;
+
   /* If the channel wrapper is defined, we assume it's ready */
   if (priv->channel_wrapper != NULL)
     goto ready;
@@ -451,7 +470,7 @@ 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);
-          return;
+          goto out;
         }
     }
   else if (channel_type == TP_IFACE_QUARK_CHANNEL_TYPE_STREAMED_MEDIA)
@@ -468,6 +487,8 @@ empathy_dispatch_operation_channel_ready_cb (TpChannel *channel,
 ready:
   empathy_dispatch_operation_set_status (self,
     EMPATHY_DISPATCHER_OPERATION_STATE_PENDING);
+out:
+  g_object_unref (self);
 }
 
 EmpathyDispatchOperation *