]> git.0d.be Git - empathy.git/commitdiff
Remove empathy_tp_file_keep_alive hack and connect to "notify::state" in file_channel...
authorXavier Claessens <xclaesse@src.gnome.org>
Fri, 21 Nov 2008 16:25:11 +0000 (16:25 +0000)
committerXavier Claessens <xclaesse@src.gnome.org>
Fri, 21 Nov 2008 16:25:11 +0000 (16:25 +0000)
svn path=/trunk/; revision=1913

libempathy/empathy-dispatcher.c
libempathy/empathy-tp-file.c
libempathy/empathy-tp-file.h
src/empathy.c

index 21b6bcccbe250fbf0dfcec180967d70a8713ed46..7f2d873e70ee6a4c7340901e88512e585c92c05a 100644 (file)
@@ -933,6 +933,19 @@ typedef struct {
        TpHandle handle;
 } FileChannelRequest;
 
+static void
+tp_file_state_notify_cb (EmpathyTpFile *tp_file)
+{
+       EmpFileTransferState state;
+
+       state = empathy_tp_file_get_state (tp_file, NULL);
+       if (state == EMP_FILE_TRANSFER_STATE_COMPLETED ||
+           state == EMP_FILE_TRANSFER_STATE_CANCELLED) {
+               DEBUG ("Transfer is done, unref the object");
+               g_object_unref (tp_file);
+       }
+}
+
 static void
 file_channel_create_cb (TpConnection *connection,
                        const gchar  *object_path,
@@ -957,10 +970,13 @@ file_channel_create_cb (TpConnection *connection,
                                 request->handle,
                                 NULL);
 
+       /* We give the ref to the callback, it is responsible to unref the
+        * object once the transfer is done. */
        tp_file = empathy_tp_file_new (channel);
        empathy_tp_file_offer (tp_file, request->gfile, NULL);
-       empathy_tp_file_keep_alive (tp_file);
-       g_object_unref (tp_file);
+       g_signal_connect (tp_file, "notify::state",
+                         G_CALLBACK (tp_file_state_notify_cb),
+                         NULL);
 
        g_object_unref (request->gfile);
        g_slice_free (FileChannelRequest, request);
index 9a6602ecce3622582f98e14244ff83e856aac2b2..940db073a3c4d39261c03b78bb22e397ec485e8b 100644 (file)
@@ -297,7 +297,6 @@ struct _EmpathyTpFilePriv {
   time_t start_time;
   gchar *unix_socket_path;
   GCancellable *cancellable;
-  gboolean keep_alive;
 };
 
 enum {
@@ -326,18 +325,6 @@ empathy_tp_file_init (EmpathyTpFile *tp_file)
   tp_file->priv = priv;
 }
 
-static void
-tp_file_check_keep_alive (EmpathyTpFile *tp_file)
-{
-  if (tp_file->priv->keep_alive &&
-      (tp_file->priv->state == EMP_FILE_TRANSFER_STATE_COMPLETED ||
-       tp_file->priv->state == EMP_FILE_TRANSFER_STATE_CANCELLED))
-    {
-      tp_file->priv->keep_alive = FALSE;
-      g_object_unref (tp_file);
-    }
-}
-
 static void
 tp_file_invalidated_cb (TpProxy       *proxy,
                        guint          domain,
@@ -356,8 +343,6 @@ tp_file_invalidated_cb (TpProxy       *proxy,
           EMP_FILE_TRANSFER_STATE_CHANGE_REASON_LOCAL_ERROR;
       g_object_notify (G_OBJECT (tp_file), "state");
     }
-
-  tp_file_check_keep_alive (tp_file);
 }
 
 static void
@@ -488,7 +473,6 @@ tp_file_state_changed_cb (TpProxy *proxy,
   tp_file->priv->state_change_reason = reason;
 
   g_object_notify (G_OBJECT (tp_file), "state");
-  tp_file_check_keep_alive (tp_file);
 }
 
 static void
@@ -840,27 +824,6 @@ empathy_tp_file_offer (EmpathyTpFile *tp_file, GFile *gfile, GError **error)
       &nothing, tp_file_method_cb, NULL, NULL, G_OBJECT (tp_file));
 }
 
-/**
- * empathy_tp_file_keep_alive:
- * @tp_file: an #EmpathyTpFile
- *
- * Keep @tp_file alive until the file transfer is COMPLETED or CANCELLED, by
- * adding a temporary reference.
- */
-void
-empathy_tp_file_keep_alive (EmpathyTpFile *tp_file)
-{
-  g_return_if_fail (EMPATHY_IS_TP_FILE (tp_file));
-
-  if (tp_file->priv->keep_alive)
-    return;
-
-  tp_file->priv->keep_alive = TRUE;
-  if (tp_file->priv->state != EMP_FILE_TRANSFER_STATE_COMPLETED &&
-      tp_file->priv->state != EMP_FILE_TRANSFER_STATE_CANCELLED)
-    g_object_ref (tp_file);
-}
-
 EmpathyContact *
 empathy_tp_file_get_contact (EmpathyTpFile *tp_file)
 {
index 4ea6650f8f94d7d44d011c96682ad04c39fc466d..3eb55a935e8fd04d080cd8c7ed174f03641e356e 100644 (file)
@@ -72,7 +72,6 @@ void empathy_tp_file_accept (EmpathyTpFile *tp_file, guint64 offset,
 void empathy_tp_file_cancel (EmpathyTpFile *tp_file);
 void empathy_tp_file_offer (EmpathyTpFile *tp_file, GFile *gfile,
   GError **error);
-void empathy_tp_file_keep_alive (EmpathyTpFile *tp_file);
 
 guint64 empathy_tp_file_get_transferred_bytes (EmpathyTpFile *tp_file);
 EmpathyContact *empathy_tp_file_get_contact (EmpathyTpFile *tp_file);
index b1ea60018c02dbfdeae099710cb597b0a997e484..dc295be6de9af6236373076495a0795c8abee1a8 100644 (file)
@@ -112,7 +112,6 @@ dispatch_channel_cb (EmpathyDispatcher *dispatcher,
                ft_manager = empathy_ft_manager_get_default ();
                tp_file = empathy_tp_file_new (channel);
                empathy_ft_manager_add_tp_file (ft_manager, tp_file);
-               empathy_tp_file_keep_alive (tp_file);
                g_object_unref (tp_file);
        }
 }