]> git.0d.be Git - empathy.git/commitdiff
Rework the logic of cancelling transfers
authorCosimo Cecchi <cosimo.cecchi@collabora.co.uk>
Sun, 3 May 2009 23:44:24 +0000 (01:44 +0200)
committerCosimo Cecchi <cosimoc@gnome.org>
Mon, 1 Jun 2009 15:47:37 +0000 (17:47 +0200)
Rework the logic of cancelling transfers so that the GCancellable object
is not used from an UI frontend, as that would require to duplicate
storage for each EmpathyFTHandler in the manager.

libempathy/empathy-ft-handler.c
libempathy/empathy-ft-handler.h
src/empathy-ft-manager.c

index 89fc13399bed947af8d455c5834650c7694a52fe..93232b18709823bde4d46f594a7f1106a87f1d2e 100644 (file)
@@ -912,15 +912,14 @@ empathy_ft_handler_new_incoming (EmpathyTpFile *tp_file,
 }
 
 void
-empathy_ft_handler_start_transfer (EmpathyFTHandler *handler,
-                                   GCancellable *cancellable)
+empathy_ft_handler_start_transfer (EmpathyFTHandler *handler)
 {
   EmpathyFTHandlerPriv *priv;
 
   g_return_if_fail (EMPATHY_IS_FT_HANDLER (handler));
 
   priv = GET_PRIV (handler);
-  priv->cancellable = g_object_ref (cancellable);
+  priv->cancellable = g_cancellable_new ();
 
   if (priv->tpfile == NULL)
     {
@@ -940,6 +939,20 @@ empathy_ft_handler_start_transfer (EmpathyFTHandler *handler,
     }
 }
 
+void
+empathy_ft_handler_cancel_transfer (EmpathyFTHandler *handler)
+{
+  EmpathyFTHandlerPriv *priv;
+
+  g_return_if_fail (EMPATHY_IS_FT_HANDLER (handler));
+
+  priv = GET_PRIV (handler);
+
+  g_return_if_fail (priv->tpfile != NULL);
+
+  empathy_tp_file_cancel (priv->tpfile);
+}
+
 void
 empathy_ft_handler_incoming_set_destination (EmpathyFTHandler *handler,
                                              GFile *destination)
index 221f4e5b5255a5934e449f9b4ec950b810b26986..085abab52cbbecaca6e36c07aef71725dd4e1bca 100644 (file)
@@ -69,8 +69,8 @@ void empathy_ft_handler_new_incoming (EmpathyTpFile *tp_file,
 void empathy_ft_handler_incoming_set_destination (EmpathyFTHandler *handler,
     GFile *destination);
 
-void empathy_ft_handler_start_transfer (EmpathyFTHandler *handler,
-    GCancellable *cancellable);
+void empathy_ft_handler_start_transfer (EmpathyFTHandler *handler);
+void empathy_ft_handler_cancel_transfer (EmpathyFTHandler *handler);
 
 /* properties of the transfer */
 const char * empathy_ft_handler_get_filename (EmpathyFTHandler *handler);
index 671a3a4a2eb24beef8145759de88ed5d5ea14471..6048cac70bd8760b813de2f40a2a2c95d9c569b0 100644 (file)
@@ -76,7 +76,6 @@ enum
 typedef struct {
   GtkTreeModel *model;
   GHashTable *ft_handler_to_row_ref;
-  GHashTable *cancellable_refs;
 
   /* Widgets */
   GtkWidget *window;
@@ -238,7 +237,6 @@ ft_manager_remove_file_from_model (EmpathyFTManager *manager,
   GtkTreePath *path = NULL;
   GtkTreeIter iter;
   gboolean update_selection;
-  GCancellable *cancellable;
   EmpathyFTManagerPriv *priv = GET_PRIV (manager);
 
   row_ref = ft_manager_get_row_from_handler (manager, handler);
@@ -272,12 +270,6 @@ ft_manager_remove_file_from_model (EmpathyFTManager *manager,
 
   if (update_selection)
     gtk_tree_selection_select_iter (selection, &iter);
-
-  cancellable = g_hash_table_lookup (priv->cancellable_refs, handler);
-
-  if (cancellable != NULL) {
-    g_cancellable_cancel (cancellable);
-  }
 }
 
 static gboolean
@@ -409,7 +401,6 @@ ft_handler_transfer_done_cb (EmpathyFTHandler *handler,
   char *first_line, *second_line, *message;
   gboolean incoming;
   GtkTreeRowReference *row_ref;
-  EmpathyFTManagerPriv *priv = GET_PRIV (manager);
 
   DEBUG ("Transfer done");
 
@@ -437,9 +428,6 @@ ft_handler_transfer_done_cb (EmpathyFTHandler *handler,
   message = g_strdup_printf ("%s\n%s", first_line, second_line);
   ft_manager_update_handler_message (manager, row_ref, message);
 
-  /* remove the cancellable object */
-  g_hash_table_remove (priv->cancellable_refs, handler);
-
   /* update buttons */
   ft_manager_update_buttons (manager);
 
@@ -578,16 +566,11 @@ static void
 ft_manager_start_transfer (EmpathyFTManager *manager,
                            EmpathyFTHandler *handler)
 {
-  GCancellable *cancellable;
   EmpathyFTManagerPriv *priv;
   gboolean is_incoming;
 
   priv = GET_PRIV (manager);
 
-  cancellable = g_cancellable_new ();
-  g_hash_table_insert (priv->cancellable_refs, g_object_ref (handler),
-      cancellable);
-
   is_incoming = empathy_ft_handler_is_incoming (handler);
 
   DEBUG ("Start transfer, is incoming %d", is_incoming);
@@ -604,7 +587,7 @@ ft_manager_start_transfer (EmpathyFTManager *manager,
         G_CALLBACK (ft_handler_hashing_started_cb), manager);
   }
 
-  empathy_ft_handler_start_transfer (handler, cancellable);
+  empathy_ft_handler_start_transfer (handler);
 }
 
 static void
@@ -706,7 +689,6 @@ ft_manager_stop (EmpathyFTManager *manager)
   GtkTreeIter iter;
   GtkTreeModel *model;
   EmpathyFTHandler *handler;
-  GCancellable *cancellable;
   EmpathyFTManagerPriv *priv;
 
   priv = GET_PRIV (manager);
@@ -723,10 +705,9 @@ ft_manager_stop (EmpathyFTManager *manager)
       empathy_contact_get_name (empathy_ft_handler_get_contact (handler)),
       empathy_ft_handler_get_filename (handler));
 
-  cancellable = g_hash_table_lookup (priv->cancellable_refs, handler);
-  g_assert (cancellable != NULL);
+  empathy_ft_handler_cancel_transfer (handler);
 
-  g_cancellable_cancel (cancellable);
+  g_object_unref (handler);
 }
 
 static gboolean
@@ -953,8 +934,6 @@ empathy_ft_manager_init (EmpathyFTManager *manager)
   priv->ft_handler_to_row_ref = g_hash_table_new_full (g_direct_hash,
       g_direct_equal, (GDestroyNotify) g_object_unref,
       (GDestroyNotify) gtk_tree_row_reference_free);
-  priv->cancellable_refs = g_hash_table_new_full (g_direct_hash, g_direct_equal,
-      (GDestroyNotify) g_object_unref, (GDestroyNotify) g_object_unref);
 
   ft_manager_build_ui (manager);
 }