diff options
author | Guillaume Desmottes <guillaume.desmottes@collabora.co.uk> | 2010-06-29 23:14:25 +0800 |
---|---|---|
committer | Guillaume Desmottes <guillaume.desmottes@collabora.co.uk> | 2010-08-11 15:43:56 +0800 |
commit | 247b08745627b9189ef93c50a346f2a7b7c52e1c (patch) | |
tree | 2d00e3ad603ba5c66b6353cac18269c0a5369486 | |
parent | a3392a992e98b330d9a604a7b539dbed60e6f375 (diff) | |
download | gsoc2013-empathy-247b08745627b9189ef93c50a346f2a7b7c52e1c.tar gsoc2013-empathy-247b08745627b9189ef93c50a346f2a7b7c52e1c.tar.gz gsoc2013-empathy-247b08745627b9189ef93c50a346f2a7b7c52e1c.tar.bz2 gsoc2013-empathy-247b08745627b9189ef93c50a346f2a7b7c52e1c.tar.lz gsoc2013-empathy-247b08745627b9189ef93c50a346f2a7b7c52e1c.tar.xz gsoc2013-empathy-247b08745627b9189ef93c50a346f2a7b7c52e1c.tar.zst gsoc2013-empathy-247b08745627b9189ef93c50a346f2a7b7c52e1c.zip |
Use TpSimpleHandler to handle incoming file transfer (#623139)
-rw-r--r-- | libempathy/empathy-ft-factory.c | 128 | ||||
-rw-r--r-- | libempathy/empathy-ft-factory.h | 5 | ||||
-rw-r--r-- | src/empathy.c | 6 |
3 files changed, 102 insertions, 37 deletions
diff --git a/libempathy/empathy-ft-factory.c b/libempathy/empathy-ft-factory.c index 5d54203fc..7ae9ad100 100644 --- a/libempathy/empathy-ft-factory.c +++ b/libempathy/empathy-ft-factory.c @@ -23,6 +23,8 @@ #include <glib.h> +#include <telepathy-glib/telepathy-glib.h> + #include "empathy-ft-factory.h" #include "empathy-ft-handler.h" #include "empathy-marshal.h" @@ -56,6 +58,13 @@ enum { static EmpathyFTFactory *factory_singleton = NULL; static guint signals[LAST_SIGNAL] = { 0 }; +/* private structure */ +typedef struct { + TpBaseClient *handler; +} EmpathyFTFactoryPriv; + +#define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyFTFactory) + static GObject * do_constructor (GType type, guint n_props, @@ -81,6 +90,8 @@ empathy_ft_factory_class_init (EmpathyFTFactoryClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); + g_type_class_add_private (klass, sizeof (EmpathyFTFactoryPriv)); + object_class->constructor = do_constructor; /** @@ -127,29 +138,94 @@ empathy_ft_factory_class_init (EmpathyFTFactoryClass *klass) } static void -empathy_ft_factory_init (EmpathyFTFactory *self) +ft_handler_incoming_ready_cb (EmpathyFTHandler *handler, + GError *error, + gpointer user_data) { - /* do nothing */ + EmpathyFTFactory *factory = user_data; + + g_signal_emit (factory, signals[NEW_INCOMING_TRANSFER], 0, handler, error); } static void -ft_handler_outgoing_ready_cb (EmpathyFTHandler *handler, - GError *error, +handle_channels_cb (TpSimpleHandler *handler, + TpAccount *account, + TpConnection *connection, + GList *channels, + GList *requests_satisfied, + gint64 user_action_time, + TpHandleChannelsContext *context, gpointer user_data) { - EmpathyFTFactory *factory = user_data; + EmpathyFTFactory *self = user_data; + GList *l; - g_signal_emit (factory, signals[NEW_FT_HANDLER], 0, handler, error); + for (l = channels; l != NULL; l = g_list_next (l)) + { + TpChannel *channel = l->data; + EmpathyTpFile *tp_file; + + if (tp_proxy_get_invalidated (channel) != NULL) + continue; + + if (tp_channel_get_channel_type_id (channel) != + TP_IFACE_QUARK_CHANNEL_TYPE_FILE_TRANSFER) + continue; + + tp_file = empathy_tp_file_new (channel); + + /* We handle only incoming FT */ + empathy_ft_handler_new_incoming (tp_file, ft_handler_incoming_ready_cb, + self); + + g_object_unref (tp_file); + } + + + tp_handle_channels_context_accept (context); } static void -ft_handler_incoming_ready_cb (EmpathyFTHandler *handler, +empathy_ft_factory_init (EmpathyFTFactory *self) +{ + EmpathyFTFactoryPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (self, + EMPATHY_TYPE_FT_FACTORY, EmpathyFTFactoryPriv); + TpDBusDaemon *dbus; + GError *error = NULL; + + self->priv = priv; + + dbus = tp_dbus_daemon_dup (&error); + if (dbus == NULL) + { + g_warning ("Failed to get TpDBusDaemon: %s", error->message); + g_error_free (error); + return; + } + + priv->handler = tp_simple_handler_new (dbus, FALSE, FALSE, + "Empathy.FileTransfer", FALSE, handle_channels_cb, self, NULL); + + tp_base_client_take_handler_filter (priv->handler, tp_asv_new ( + TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING, + TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER, + TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, G_TYPE_UINT, TP_HANDLE_TYPE_CONTACT, + /* Only handle *incoming* channels as outgoing FT channels has to be + * handled by the requester. */ + TP_PROP_CHANNEL_REQUESTED, G_TYPE_BOOLEAN, FALSE, + NULL)); + + g_object_unref (dbus); +} + +static void +ft_handler_outgoing_ready_cb (EmpathyFTHandler *handler, GError *error, gpointer user_data) { EmpathyFTFactory *factory = user_data; - g_signal_emit (factory, signals[NEW_INCOMING_TRANSFER], 0, handler, error); + g_signal_emit (factory, signals[NEW_FT_HANDLER], 0, handler, error); } /* public methods */ @@ -191,33 +267,6 @@ empathy_ft_factory_new_transfer_outgoing (EmpathyFTFactory *factory, } /** - * empathy_ft_factory_claim_channel: - * @factory: an #EmpathyFTFactory - * @operation: the #EmpathyDispatchOperation wrapping the channel - * - * Let the @factory claim the channel, starting the creation of a new - * incoming #EmpathyFTHandler. - */ -void -empathy_ft_factory_claim_channel (EmpathyFTFactory *factory, - EmpathyDispatchOperation *operation) -{ - EmpathyTpFile *tp_file; - - g_return_if_fail (EMPATHY_IS_FT_FACTORY (factory)); - g_return_if_fail (EMPATHY_IS_DISPATCH_OPERATION (operation)); - - /* 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, ft_handler_incoming_ready_cb, - factory); - - empathy_dispatch_operation_claim (operation); -} - -/** * empathy_ft_factory_set_destination_for_incoming_handler: * @factory: an #EmpathyFTFactory * @handler: the #EmpathyFTHandler to set the destination of @@ -240,3 +289,12 @@ empathy_ft_factory_set_destination_for_incoming_handler ( g_signal_emit (factory, signals[NEW_FT_HANDLER], 0, handler, NULL); } + +gboolean +empathy_ft_factory_register (EmpathyFTFactory *self, + GError **error) +{ + EmpathyFTFactoryPriv *priv = GET_PRIV (self); + + return tp_base_client_register (priv->handler, error); +} diff --git a/libempathy/empathy-ft-factory.h b/libempathy/empathy-ft-factory.h index cffb73301..00b2af5a9 100644 --- a/libempathy/empathy-ft-factory.h +++ b/libempathy/empathy-ft-factory.h @@ -64,13 +64,14 @@ EmpathyFTFactory* empathy_ft_factory_dup_singleton (void); void empathy_ft_factory_new_transfer_outgoing (EmpathyFTFactory *factory, EmpathyContact *contact, GFile *source); -void empathy_ft_factory_claim_channel (EmpathyFTFactory *factory, - EmpathyDispatchOperation *operation); void empathy_ft_factory_set_destination_for_incoming_handler ( EmpathyFTFactory *factory, EmpathyFTHandler *handler, GFile *destination); +gboolean empathy_ft_factory_register (EmpathyFTFactory *self, + GError **error); + G_END_DECLS #endif /* __EMPATHY_FT_FACTORY_H__ */ diff --git a/src/empathy.c b/src/empathy.c index bb39263bc..aefb934eb 100644 --- a/src/empathy.c +++ b/src/empathy.c @@ -538,6 +538,12 @@ main (int argc, char *argv[]) g_signal_connect (ft_factory, "new-incoming-transfer", G_CALLBACK (new_incoming_transfer_cb), NULL); + if (!empathy_ft_factory_register (ft_factory, &error)) + { + g_warning ("Failed to register FileTransfer handler: %s", error->message); + g_error_free (error); + } + /* Location mananger */ #ifdef HAVE_GEOCLUE location_manager = empathy_location_manager_dup_singleton (); |