aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCosimo Cecchi <cosimo.cecchi@collabora.co.uk>2009-02-18 23:41:12 +0800
committerCosimo Cecchi <cosimoc@gnome.org>2009-06-01 23:47:34 +0800
commit58d08cef143811d990218551a922451609978610 (patch)
treed90811a64a6135a048d3c90aee13654019089b5b
parent1e69ae50fa2a35ac4e54283d40e9d96777ff6e61 (diff)
downloadgsoc2013-empathy-58d08cef143811d990218551a922451609978610.tar
gsoc2013-empathy-58d08cef143811d990218551a922451609978610.tar.gz
gsoc2013-empathy-58d08cef143811d990218551a922451609978610.tar.bz2
gsoc2013-empathy-58d08cef143811d990218551a922451609978610.tar.lz
gsoc2013-empathy-58d08cef143811d990218551a922451609978610.tar.xz
gsoc2013-empathy-58d08cef143811d990218551a922451609978610.tar.zst
gsoc2013-empathy-58d08cef143811d990218551a922451609978610.zip
Rethink a bit the logic for an incoming transfer.
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.
-rw-r--r--libempathy-gtk/empathy-ui-utils.c46
-rw-r--r--libempathy-gtk/empathy-ui-utils.h3
-rw-r--r--libempathy/empathy-ft-factory.c43
-rw-r--r--libempathy/empathy-ft-factory.h9
-rw-r--r--libempathy/empathy-ft-handler.c26
-rw-r--r--libempathy/empathy-ft-handler.h9
-rw-r--r--src/empathy.c26
7 files changed, 142 insertions, 20 deletions
diff --git a/libempathy-gtk/empathy-ui-utils.c b/libempathy-gtk/empathy-ui-utils.c
index c61ad0dac..c33abb63d 100644
--- a/libempathy-gtk/empathy-ui-utils.c
+++ b/libempathy-gtk/empathy-ui-utils.c
@@ -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;
diff --git a/libempathy-gtk/empathy-ui-utils.h b/libempathy-gtk/empathy-ui-utils.h
index 0b5b17f28..4d58fedcf 100644
--- a/libempathy-gtk/empathy-ui-utils.h
+++ b/libempathy-gtk/empathy-ui-utils.h
@@ -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,
diff --git a/libempathy/empathy-ft-factory.c b/libempathy/empathy-ft-factory.c
index 8aad81a5a..d180fa1ed 100644
--- a/libempathy/empathy-ft-factory.c
+++ b/libempathy/empathy-ft-factory.c
@@ -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);
+}
diff --git a/libempathy/empathy-ft-factory.h b/libempathy/empathy-ft-factory.h
index 221ea9ca8..f482855a3 100644
--- a/libempathy/empathy-ft-factory.h
+++ b/libempathy/empathy-ft-factory.h
@@ -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
diff --git a/libempathy/empathy-ft-handler.c b/libempathy/empathy-ft-handler.c
index d1909c15c..0d061b59c 100644
--- a/libempathy/empathy-ft-handler.c
+++ b/libempathy/empathy-ft-handler.c
@@ -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;
+}
diff --git a/libempathy/empathy-ft-handler.h b/libempathy/empathy-ft-handler.h
index ee32ffd31..695d9c22d 100644
--- a/libempathy/empathy-ft-handler.h
+++ b/libempathy/empathy-ft-handler.h
@@ -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__ */
diff --git a/src/empathy.c b/src/empathy.c
index c588fd9e7..705e6f0e5 100644
--- a/src/empathy.c
+++ b/src/empathy.c
@@ -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);
}
}
@@ -405,6 +405,22 @@ show_version_cb (const char *option_name,
}
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 ();