[empathy: 15/148] Modify EmpathyFTHandler to adapt to the changes in EmpathyTpFile API.



commit a5440333ee18a3174acc2437e2ba1e30365b1bca
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Tue Feb 17 19:48:01 2009 +0100

    Modify EmpathyFTHandler to adapt to the changes in EmpathyTpFile API.
---
 libempathy/empathy-ft-handler.c |   47 +++++++++++++++++++++++++++++++++-----
 libempathy/empathy-ft-handler.h |    5 ++-
 libempathy/empathy-tp-file.c    |    6 +---
 3 files changed, 45 insertions(+), 13 deletions(-)

diff --git a/libempathy/empathy-ft-handler.c b/libempathy/empathy-ft-handler.c
index 00bcf30..85d70db 100644
--- a/libempathy/empathy-ft-handler.c
+++ b/libempathy/empathy-ft-handler.c
@@ -248,9 +248,9 @@ empathy_ft_handler_class_init (EmpathyFTHandlerClass *klass)
   signals[TRANSFER_PROGRESS] =
     g_signal_new ("transfer-progress", G_TYPE_FROM_CLASS (klass),
         G_SIGNAL_RUN_LAST, 0, NULL, NULL,
-        _empathy_marshal_VOID__OBJECT_UINT64_UINT64,
+        _empathy_marshal_VOID__UINT64_UINT64,
         G_TYPE_NONE,
-        2, EMPATHY_TYPE_TP_FILE, G_TYPE_UINT64, G_TYPE_UINT64);
+        2, G_TYPE_UINT64, G_TYPE_UINT64);
 
   signals[HASHING_STARTED] =
     g_signal_new ("hashing-started", G_TYPE_FROM_CLASS (klass),
@@ -319,12 +319,41 @@ hash_data_free (HashingData *data)
 }
 
 static void
+ft_transfer_operation_callback (EmpathyTpFile *tp_file,
+                                const GError *error,
+                                gpointer user_data)
+{
+  EmpathyFTHandler *handler = user_data;
+
+  if (error != NULL)
+    g_signal_emit (handler, signals[TRANSFER_ERROR], 0, error);
+  else
+    g_signal_emit (handler, signals[TRANSFER_DONE], 0);
+}
+
+static void
+ft_transfer_progress_callback (EmpathyTpFile *tp_file,
+                               guint64 transferred_bytes,
+                               guint64 total_bytes,
+                               gpointer user_data)
+{
+  EmpathyFTHandler *handler = user_data;
+  EmpathyFTHandlerPriv *priv = GET_PRIV (handler);
+
+  if (priv->transferred_bytes != transferred_bytes)
+    {
+      priv->transferred_bytes = transferred_bytes;
+      g_signal_emit (handler, signals[TRANSFER_PROGRESS], 0,
+          transferred_bytes, total_bytes);
+    }
+}
+
+static void
 ft_handler_create_channel_cb (EmpathyDispatchOperation *operation,
                               const GError *error,
                               gpointer user_data)
 {
   EmpathyFTHandler *handler = user_data;
-  GError *myerr = NULL;
   EmpathyFTHandlerPriv *priv = GET_PRIV (handler);
 
   DEBUG ("FT: dispatcher create channel CB");
@@ -337,7 +366,10 @@ ft_handler_create_channel_cb (EmpathyDispatchOperation *operation,
 
   priv->tpfile = g_object_ref
       (empathy_dispatch_operation_get_channel_wrapper (operation));
-  empathy_tp_file_offer (priv->tpfile, priv->gfile, &myerr);
+  empathy_tp_file_offer (priv->tpfile, priv->gfile, priv->cancellable,
+      ft_transfer_progress_callback, handler,
+      ft_transfer_operation_callback, handler);
+
   empathy_dispatch_operation_claim (operation);
 }
 
@@ -732,7 +764,7 @@ channel_get_all_properties_cb (TpProxy *proxy,
 
   if (error != NULL)
     {
-      cb_data->callback (NULL, error, cb_data->user_data);
+      cb_data->callback (NULL, (GError *) error, cb_data->user_data);
       g_object_unref (handler);
       return;
     }
@@ -835,7 +867,6 @@ empathy_ft_handler_start_transfer (EmpathyFTHandler *handler,
                                    GCancellable *cancellable)
 {
   EmpathyFTHandlerPriv *priv;
-  GError *error = NULL;
 
   g_return_if_fail (EMPATHY_IS_FT_HANDLER (handler));
 
@@ -849,6 +880,8 @@ empathy_ft_handler_start_transfer (EmpathyFTHandler *handler,
   else
     {
       /* TODO: add support for resume. */
-      empathy_tp_file_accept (priv->tpfile, 0, priv->gfile, &error);
+      empathy_tp_file_accept (priv->tpfile, 0, priv->gfile, priv->cancellable,
+          ft_transfer_progress_callback, handler,
+          ft_transfer_operation_callback, handler);
     }
 }
diff --git a/libempathy/empathy-ft-handler.h b/libempathy/empathy-ft-handler.h
index 41e33d7..ee32ffd 100644
--- a/libempathy/empathy-ft-handler.h
+++ b/libempathy/empathy-ft-handler.h
@@ -60,8 +60,9 @@ typedef void (* EmpathyFTHandlerReadyCallback) (EmpathyFTHandler *handler,
 GType empathy_ft_handler_get_type (void);
 
 /* public methods */
-EmpathyFTHandler * empathy_ft_handler_new_outgoing (EmpathyContact *contact,
-    GFile *source);
+void empathy_ft_handler_new_outgoing (EmpathyContact *contact,
+    GFile *source, EmpathyFTHandlerReadyCallback callback,
+    gpointer user_data);
 void empathy_ft_handler_new_incoming (EmpathyTpFile *tp_file,
     GFile *destination, EmpathyFTHandlerReadyCallback callback,
     gpointer user_data);
diff --git a/libempathy/empathy-tp-file.c b/libempathy/empathy-tp-file.c
index 8370743..6f794b2 100644
--- a/libempathy/empathy-tp-file.c
+++ b/libempathy/empathy-tp-file.c
@@ -409,10 +409,8 @@ tp_file_transferred_bytes_changed_cb (TpProxy *proxy,
 
   /* notify clients */
   if (priv->progress_callback)
-    {
-      priv->progress_callback (EMPATHY_TP_FILE (weak_object),
-          priv->transferred_bytes, priv->size, priv->progress_user_data);
-    }
+    priv->progress_callback (EMPATHY_TP_FILE (weak_object),
+        priv->transferred_bytes, priv->size, priv->progress_user_data);
 }
 
 static void



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]