]> git.0d.be Git - empathy.git/commitdiff
Rethink a bit the logic for an incoming transfer.
authorCosimo Cecchi <cosimo.cecchi@collabora.co.uk>
Wed, 18 Feb 2009 15:41:12 +0000 (16:41 +0100)
committerCosimo Cecchi <cosimoc@gnome.org>
Mon, 1 Jun 2009 15:47:34 +0000 (17:47 +0200)
Now, a client should have to do the following, in order to receive a file transfer:
- let the EmpathyFTFactory claim the EmpathyDispatchOperation
- the factory will emit "new-incoming-transfer" when the handler is filled with
  the relevant properties
- now you can choose a destination file, and then you should call _set_destination
  on EmpathyFTFactory passing the handler.
- the factory will emit "new-ft-handler" as you're now ready to start the actual
  transfer.

libempathy-gtk/empathy-ui-utils.c
libempathy-gtk/empathy-ui-utils.h
libempathy/empathy-ft-factory.c
libempathy/empathy-ft-factory.h
libempathy/empathy-ft-handler.c
libempathy/empathy-ft-handler.h
src/empathy.c

index c61ad0dac93c0b4b2ded39fc8faa96d2de963f15..c33abb63d2ec4187203ca22ea3852ad0d7708c07 100644 (file)
@@ -1418,13 +1418,14 @@ file_manager_send_file_response_cb (GtkDialog      *widget,
 
                factory = empathy_ft_factory_dup_singleton ();
 
-               empathy_ft_factory_new_transfer (factory, contact, file);
+               empathy_ft_factory_new_transfer_outgoing (factory, contact, file);
 
                manager = gtk_recent_manager_get_default ();
                gtk_recent_manager_add_item (manager, uri);
 
                g_free (uri);
                g_object_unref (factory);
+               g_object_unref (file);
        }
 
        gtk_widget_destroy (GTK_WIDGET (widget));
@@ -1466,6 +1467,49 @@ empathy_send_file_with_file_chooser (EmpathyContact *contact)
        gtk_widget_show (widget);
 }
 
+static void
+file_manager_receive_file_response_cb (GtkDialog *dialog,
+                                      GtkResponseType response,
+                                      EmpathyFTHandler *handler)
+{
+       EmpathyFTFactory *factory;
+       GFile *file;
+
+       if (response == GTK_RESPONSE_OK) {
+               factory = empathy_ft_factory_dup_singleton ();
+               file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (dialog));
+
+               empathy_ft_factory_set_destination_for_incoming_handler
+                       (factory, handler, file);
+
+               g_object_unref (factory);
+               g_object_unref (file);
+       }
+
+       gtk_widget_destroy (GTK_WIDGET (dialog));
+}
+
+void
+empathy_receive_file_with_file_chooser (EmpathyFTHandler *handler)
+{
+       GtkWidget *widget;
+
+       widget = gtk_file_chooser_dialog_new (_("Select a destination"),
+                                             NULL,
+                                             GTK_FILE_CHOOSER_ACTION_SAVE,
+                                             GTK_STOCK_CANCEL,
+                                             GTK_RESPONSE_CANCEL,
+                                             GTK_STOCK_SAVE,
+                                             GTK_RESPONSE_OK,
+                                             NULL);
+       gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (widget),
+               empathy_ft_handler_get_filename (handler));
+       g_signal_connect (widget, "response",
+               G_CALLBACK (file_manager_receive_file_response_cb), handler);
+
+       gtk_widget_show (widget);
+}
+
 typedef struct {
        EmpathySound sound_id;
        const char * event_ca_id;
index 0b5b17f28273897b2db3de09ac992d9d26df236a..4d58fedcf7d3f52ba7bafbf2b716d1b87a264b49 100644 (file)
@@ -39,8 +39,8 @@
 #include <libmissioncontrol/mc-account.h>
 #include <libmissioncontrol/mc-profile.h>
 
-
 #include <libempathy/empathy-contact.h>
+#include <libempathy/empathy-ft-handler.h>
 
 #include "empathy-chat-view.h"
 
@@ -124,6 +124,7 @@ GtkWidget * empathy_link_button_new                     (const gchar      *url,
                                                         const gchar      *title);
 
 void        empathy_send_file_with_file_chooser         (EmpathyContact   *contact);
+void        empathy_receive_file_with_file_chooser      (EmpathyFTHandler *handler);
 
 /* Sounds */
 void        empathy_sound_play                          (GtkWidget        *widget,
index 8aad81a5a78ad5ee4873aadb729ee7ecbf78a64e..d180fa1edbbee8305da6f788760544fc88076bfb 100644 (file)
@@ -34,6 +34,7 @@ G_DEFINE_TYPE (EmpathyFTFactory, empathy_ft_factory, G_TYPE_OBJECT);
 
 enum {
   NEW_FT_HANDLER,
+  NEW_INCOMING_TRANSFER,
   LAST_SIGNAL
 };
 
@@ -75,6 +76,14 @@ empathy_ft_factory_class_init (EmpathyFTFactoryClass *klass)
       _empathy_marshal_VOID__OBJECT_BOOLEAN,
       G_TYPE_NONE,
       2, EMPATHY_TYPE_FT_HANDLER, G_TYPE_BOOLEAN);
+
+  signals[NEW_INCOMING_TRANSFER] =
+    g_signal_new ("new-incoming-transfer",
+      G_TYPE_FROM_CLASS (klass),
+      G_SIGNAL_RUN_LAST, 0,
+      NULL, NULL,
+      g_cclosure_marshal_VOID__OBJECT,
+      G_TYPE_NONE, 1, EMPATHY_TYPE_FT_HANDLER);
 }
 
 static void
@@ -112,7 +121,7 @@ ft_handler_incoming_ready_cb (EmpathyFTHandler *handler,
       return;
     }
 
-  g_signal_emit (factory, signals[NEW_FT_HANDLER], 0, handler, FALSE);
+  g_signal_emit (factory, signals[NEW_INCOMING_TRANSFER], 0, handler);
 }
 
 /* public methods */
@@ -124,9 +133,9 @@ empathy_ft_factory_dup_singleton (void)
 }
 
 void
-empathy_ft_factory_new_transfer (EmpathyFTFactory *factory,
-                                 EmpathyContact *contact,
-                                 GFile *source)
+empathy_ft_factory_new_transfer_outgoing (EmpathyFTFactory *factory,
+                                          EmpathyContact *contact,
+                                          GFile *source)
 {
   g_return_if_fail (EMPATHY_IS_FT_FACTORY (factory));
   g_return_if_fail (EMPATHY_IS_CONTACT (contact));
@@ -138,20 +147,34 @@ empathy_ft_factory_new_transfer (EmpathyFTFactory *factory,
 
 void
 empathy_ft_factory_claim_channel (EmpathyFTFactory *factory,
-                                  EmpathyDispatchOperation *operation,
-                                  GFile *destination)
+                                  EmpathyDispatchOperation *operation)
 {
   EmpathyTpFile *tp_file;
 
   g_return_if_fail (EMPATHY_IS_FT_FACTORY (factory));
   g_return_if_fail (EMPATHY_IS_DISPATCH_OPERATION (operation));
-  g_return_if_fail (G_IS_FILE (destination));
 
+  /* own a reference to the EmpathyTpFile */
   tp_file = EMPATHY_TP_FILE
-      (empathy_dispatch_operation_get_channel_wrapper (operation));
-  empathy_ft_handler_new_incoming (tp_file, destination,
-      ft_handler_incoming_ready_cb, factory);
+      ((empathy_dispatch_operation_get_channel_wrapper (operation)));
+
+  empathy_ft_handler_new_incoming (tp_file, ft_handler_incoming_ready_cb,
+      factory);
 
   empathy_dispatch_operation_claim (operation);
 }
 
+void
+empathy_ft_factory_set_destination_for_incoming_handler
+                                                 (EmpathyFTFactory *factory,
+                                                  EmpathyFTHandler *handler,
+                                                  GFile *destination)
+{
+  g_return_if_fail (EMPATHY_IS_FT_FACTORY (factory));
+  g_return_if_fail (EMPATHY_IS_FT_HANDLER (handler));
+  g_return_if_fail (G_IS_FILE (destination));
+
+  empathy_ft_handler_incoming_set_destination (handler, destination);
+
+  g_signal_emit (factory, signals[NEW_FT_HANDLER], 0, handler, FALSE);
+}
index 221ea9ca8c0a9eea8458aa75e3b9573610764048..f482855a31ae975f840509c87fe86c2f938d55f5 100644 (file)
@@ -28,6 +28,7 @@
 #include <gio/gio.h>
 
 #include "empathy-contact.h"
+#include "empathy-ft-handler.h"
 #include "empathy-dispatch-operation.h"
 
 G_BEGIN_DECLS
@@ -57,10 +58,14 @@ GType empathy_ft_factory_get_type (void);
 
 /* public methods */
 EmpathyFTFactory* empathy_ft_factory_dup_singleton (void);
-void empathy_ft_factory_new_transfer (EmpathyFTFactory *factory,
+void empathy_ft_factory_new_transfer_outgoing (EmpathyFTFactory *factory,
   EmpathyContact *contact, GFile *source);
 void empathy_ft_factory_claim_channel (EmpathyFTFactory *factory,
-  EmpathyDispatchOperation *operation, GFile *destination);
+  EmpathyDispatchOperation *operation);
+void empathy_ft_factory_set_destination_for_incoming_handler
+                                                 (EmpathyFTFactory *factory,
+                                                  EmpathyFTHandler *handler,
+                                                  GFile *destination);
 
 G_END_DECLS
 
index d1909c15ccba66d2394e1b21d5315569e218ec8b..0d061b59c8e386ce000f819ea90a1478e4a3c882 100644 (file)
@@ -855,7 +855,6 @@ empathy_ft_handler_new_outgoing (EmpathyContact *contact,
 
 void
 empathy_ft_handler_new_incoming (EmpathyTpFile *tp_file,
-                                 GFile *destination,
                                  EmpathyFTHandlerReadyCallback callback,
                                  gpointer user_data)
 {
@@ -864,10 +863,9 @@ empathy_ft_handler_new_incoming (EmpathyTpFile *tp_file,
   CallbacksData *data;
 
   g_return_if_fail (EMPATHY_IS_TP_FILE (tp_file));
-  g_return_if_fail (G_IS_FILE (destination));
 
   handler = g_object_new (EMPATHY_TYPE_FT_HANDLER,
-      "tp-file", tp_file, "gfile", destination, NULL);
+      "tp-file", tp_file, NULL);
 
   g_object_get (tp_file, "channel", &channel, NULL);
 
@@ -909,3 +907,25 @@ empathy_ft_handler_start_transfer (EmpathyFTHandler *handler,
           ft_transfer_operation_callback, handler);
     }
 }
+
+void
+empathy_ft_handler_incoming_set_destination (EmpathyFTHandler *handler,
+                                             GFile *destination)
+{
+  g_return_if_fail (EMPATHY_IS_FT_HANDLER (handler));
+  g_return_if_fail (G_IS_FILE (destination));
+
+  g_object_set (handler, "gfile", destination, NULL);
+}
+
+const char *
+empathy_ft_handler_get_filename (EmpathyFTHandler *handler)
+{
+  EmpathyFTHandlerPriv *priv;
+
+  g_return_val_if_fail (EMPATHY_IS_FT_HANDLER (handler), NULL);
+
+  priv = GET_PRIV (handler);
+
+  return priv->filename;
+}
index ee32ffd31e1ee78c5d02e6e8bc15a2e03cb7d1b4..695d9c22d8cac53712ceebbf1f4a788ff8755f05 100644 (file)
@@ -63,12 +63,17 @@ GType empathy_ft_handler_get_type (void);
 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);
+    EmpathyFTHandlerReadyCallback callback, gpointer user_data);
+void empathy_ft_handler_incoming_set_destination (EmpathyFTHandler *handler,
+    GFile *destination);
+
 void empathy_ft_handler_start_transfer (EmpathyFTHandler *handler,
     GCancellable *cancellable);
 
+const char * empathy_ft_handler_get_filename (EmpathyFTHandler *handler);
+
 G_END_DECLS
 
 #endif /* __EMPATHY_FT_HANDLER_H__ */
index c588fd9e70477bad10581990dcfd22f54a627087..705e6f0e543f31eee1266e3389f5b9cdb1ce443e 100644 (file)
@@ -133,7 +133,7 @@ dispatch_cb (EmpathyDispatcher *dispatcher,
                EmpathyFTFactory *factory;
 
                factory = empathy_ft_factory_dup_singleton ();
-               empathy_ft_factory_claim_channel (factory, operation, NULL);
+               empathy_ft_factory_claim_channel (factory, operation);
        }
 }
 
@@ -404,6 +404,22 @@ show_version_cb (const char *option_name,
        return FALSE;
 }
 
+static void
+new_incoming_transfer_cb (EmpathyFTFactory *factory,
+                         EmpathyFTHandler *handler,
+                         gpointer user_data)
+{
+       empathy_receive_file_with_file_chooser (handler);
+}
+
+static void
+new_ft_handler_cb (EmpathyFTFactory *factory,
+                  EmpathyFTHandler *handler,
+                  gpointer user_data)
+{
+       /* TODO: add to FT window */
+}
+
 static void
 new_call_handler_cb (EmpathyCallFactory *factory, EmpathyCallHandler *handler,
        gboolean outgoing, gpointer user_data)
@@ -427,6 +443,7 @@ main (int argc, char *argv[])
        EmpathyChatroomManager *chatroom_manager;
        EmpathyFTManager  *ft_manager;
        EmpathyCallFactory *call_factory;
+       EmpathyFTFactory  *ft_factory;
        GtkWidget         *window;
        MissionControl    *mc;
        EmpathyIdle       *idle;
@@ -581,6 +598,12 @@ main (int argc, char *argv[])
        call_factory = empathy_call_factory_initialise ();
        g_signal_connect (G_OBJECT (call_factory), "new-call-handler",
                G_CALLBACK (new_call_handler_cb), NULL);
+       /* Create the FT factory */
+       ft_factory = empathy_ft_factory_dup_singleton ();
+       g_signal_connect (ft_factory, "new-ft-handler",
+               G_CALLBACK (new_ft_handler_cb), NULL);
+       g_signal_connect (ft_factory, "new-incoming-transfer",
+               G_CALLBACK (new_incoming_transfer_cb), NULL);
 
        /* Location mananger */
 #if HAVE_GEOCLUE
@@ -601,6 +624,7 @@ main (int argc, char *argv[])
 #if HAVE_GEOCLUE
        g_object_unref (location_manager);
 #endif
+       g_object_unref (ft_factory);
 
        notify_uninit ();