diff options
author | Guillaume Desmottes <guillaume.desmottes@collabora.co.uk> | 2011-09-21 21:53:44 +0800 |
---|---|---|
committer | Guillaume Desmottes <guillaume.desmottes@collabora.co.uk> | 2011-09-27 21:11:27 +0800 |
commit | a3d1d0df9e007c2d59c03ecaecf19321f60151c1 (patch) | |
tree | 4167edd85317bb58972433617ad1a10d499247c6 | |
parent | 88fc949d3521c77a8ab9e86f8366f670b940bafb (diff) | |
download | gsoc2013-empathy-a3d1d0df9e007c2d59c03ecaecf19321f60151c1.tar gsoc2013-empathy-a3d1d0df9e007c2d59c03ecaecf19321f60151c1.tar.gz gsoc2013-empathy-a3d1d0df9e007c2d59c03ecaecf19321f60151c1.tar.bz2 gsoc2013-empathy-a3d1d0df9e007c2d59c03ecaecf19321f60151c1.tar.lz gsoc2013-empathy-a3d1d0df9e007c2d59c03ecaecf19321f60151c1.tar.xz gsoc2013-empathy-a3d1d0df9e007c2d59c03ecaecf19321f60151c1.tar.zst gsoc2013-empathy-a3d1d0df9e007c2d59c03ecaecf19321f60151c1.zip |
EmpathyTpFile: inherit from TpFileTransferChannel
https://bugzilla.gnome.org/show_bug.cgi?id=658245
-rw-r--r-- | libempathy/empathy-client-factory.c | 6 | ||||
-rw-r--r-- | libempathy/empathy-ft-factory.c | 12 | ||||
-rw-r--r-- | libempathy/empathy-ft-handler.c | 15 | ||||
-rw-r--r-- | libempathy/empathy-tp-file.c | 150 | ||||
-rw-r--r-- | libempathy/empathy-tp-file.h | 12 | ||||
-rw-r--r-- | src/empathy-event-manager.c | 5 |
6 files changed, 54 insertions, 146 deletions
diff --git a/libempathy/empathy-client-factory.c b/libempathy/empathy-client-factory.c index 3794ef60d..f7529bf2e 100644 --- a/libempathy/empathy-client-factory.c +++ b/libempathy/empathy-client-factory.c @@ -24,6 +24,7 @@ #include "empathy-client-factory.h" #include "empathy-tp-chat.h" +#include "empathy-tp-file.h" #include "empathy-utils.h" #include <telepathy-yell/telepathy-yell.h> @@ -88,6 +89,11 @@ empathy_client_factory_create_channel (TpSimpleClientFactory *factory, return TP_CHANNEL (call_channel_new_with_factory ( TP_SIMPLE_CLIENT_FACTORY (factory), conn, path, properties, error)); } + else if (!tp_strdiff (chan_type, TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER)) + { + return TP_CHANNEL (empathy_tp_file_new ( + TP_SIMPLE_CLIENT_FACTORY (factory), conn, path, properties, error)); + } return chainup->create_channel (factory, conn, path, properties, error); } diff --git a/libempathy/empathy-ft-factory.c b/libempathy/empathy-ft-factory.c index 472451fa0..5097f9b1e 100644 --- a/libempathy/empathy-ft-factory.c +++ b/libempathy/empathy-ft-factory.c @@ -179,22 +179,16 @@ handle_channels_cb (TpSimpleHandler *handler, 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) + if (!EMPATHY_IS_TP_FILE (channel)) 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); + empathy_ft_handler_new_incoming ((EmpathyTpFile *) channel, + ft_handler_incoming_ready_cb, self); } diff --git a/libempathy/empathy-ft-handler.c b/libempathy/empathy-ft-handler.c index 8654bdd20..83557d480 100644 --- a/libempathy/empathy-ft-handler.c +++ b/libempathy/empathy-ft-handler.c @@ -725,7 +725,7 @@ ft_handler_create_channel_cb (GObject *source, EmpathyFTHandler *handler = user_data; EmpathyFTHandlerPriv *priv = GET_PRIV (handler); GError *error = NULL; - TpChannel *channel = NULL; + TpChannel *channel; DEBUG ("Dispatcher create channel CB"); @@ -741,18 +741,16 @@ ft_handler_create_channel_cb (GObject *source, { emit_error_signal (handler, error); + g_clear_object (&channel); g_error_free (error); - goto out; + return; } - priv->tpfile = empathy_tp_file_new (channel); + priv->tpfile = EMPATHY_TP_FILE (channel); empathy_tp_file_offer (priv->tpfile, priv->gfile, priv->cancellable, ft_transfer_progress_callback, handler, ft_transfer_operation_callback, handler); - -out: - tp_clear_object (&channel); } static void @@ -1365,7 +1363,6 @@ empathy_ft_handler_new_incoming (EmpathyTpFile *tp_file, gpointer user_data) { EmpathyFTHandler *handler; - TpChannel *channel; CallbacksData *data; g_return_if_fail (EMPATHY_IS_TP_FILE (tp_file)); @@ -1373,14 +1370,12 @@ empathy_ft_handler_new_incoming (EmpathyTpFile *tp_file, handler = g_object_new (EMPATHY_TYPE_FT_HANDLER, "tp-file", tp_file, NULL); - g_object_get (tp_file, "channel", &channel, NULL); - data = g_slice_new0 (CallbacksData); data->callback = callback; data->user_data = user_data; data->handler = g_object_ref (handler); - tp_cli_dbus_properties_call_get_all (channel, + tp_cli_dbus_properties_call_get_all (tp_file, -1, TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER, channel_get_all_properties_cb, data, NULL, G_OBJECT (handler)); } diff --git a/libempathy/empathy-tp-file.c b/libempathy/empathy-tp-file.c index 09e14ceb6..d6d565654 100644 --- a/libempathy/empathy-tp-file.c +++ b/libempathy/empathy-tp-file.c @@ -66,8 +66,6 @@ /* EmpathyTpFile object */ struct _EmpathyTpFilePrivate { - TpChannel *channel; - GInputStream *in_stream; GOutputStream *out_stream; @@ -97,13 +95,7 @@ struct _EmpathyTpFilePrivate { gboolean is_closed; }; -enum { - PROP_0, - PROP_CHANNEL, - PROP_INCOMING -}; - -G_DEFINE_TYPE (EmpathyTpFile, empathy_tp_file, G_TYPE_OBJECT); +G_DEFINE_TYPE (EmpathyTpFile, empathy_tp_file, TP_TYPE_FILE_TRANSFER_CHANNEL); /* private functions */ @@ -589,8 +581,7 @@ file_read_async_cb (GObject *source, */ initialize_empty_ac_variant (self->priv->socket_access_control, ¬hing); - tp_cli_channel_type_file_transfer_call_provide_file ( - self->priv->channel, -1, + tp_cli_channel_type_file_transfer_call_provide_file ((TpChannel *) self, -1, self->priv->socket_address_type, self->priv->socket_access_control, ¬hing, ft_operation_provide_or_accept_file_cb, NULL, NULL, G_OBJECT (self)); @@ -616,7 +607,7 @@ file_transfer_set_uri_cb (TpProxy *proxy, */ initialize_empty_ac_variant (self->priv->socket_access_control, ¬hing); - tp_cli_channel_type_file_transfer_call_accept_file (self->priv->channel, + tp_cli_channel_type_file_transfer_call_accept_file ((TpChannel *) self, -1, self->priv->socket_address_type, self->priv->socket_access_control, ¬hing, self->priv->offset, ft_operation_provide_or_accept_file_cb, NULL, NULL, weak_object); @@ -650,7 +641,7 @@ file_replace_async_cb (GObject *source, uri = g_file_get_uri (file); value = tp_g_value_slice_new_take_string (uri); - tp_cli_dbus_properties_call_set (self->priv->channel, -1, + tp_cli_dbus_properties_call_set ((TpChannel *) self, -1, TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER, "URI", value, file_transfer_set_uri_cb, NULL, NULL, G_OBJECT (self)); @@ -682,7 +673,7 @@ close_channel_internal (EmpathyTpFile *self, self->priv->is_closing = TRUE; - tp_cli_channel_call_close (self->priv->channel, -1, + tp_cli_channel_call_close ((TpChannel *) self, -1, channel_closed_cb, GINT_TO_POINTER (cancel), NULL, G_OBJECT (self)); } @@ -700,13 +691,6 @@ do_dispose (GObject *object) { EmpathyTpFile *self = (EmpathyTpFile *) object; - if (self->priv->channel != NULL) - { - g_signal_handlers_disconnect_by_func (self->priv->channel, - tp_file_invalidated_cb, object); - tp_clear_object (&self->priv->channel); - } - tp_clear_object (&self->priv->in_stream); tp_clear_object (&self->priv->out_stream); tp_clear_object (&self->priv->cancellable); @@ -731,68 +715,28 @@ do_finalize (GObject *object) } static void -do_get_property (GObject *object, - guint param_id, - GValue *value, - GParamSpec *pspec) -{ - EmpathyTpFile *self = (EmpathyTpFile *) object; - - switch (param_id) - { - case PROP_CHANNEL: - g_value_set_object (value, self->priv->channel); - break; - case PROP_INCOMING: - g_value_set_boolean (value, self->priv->incoming); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); - break; - }; -} - -static void -do_set_property (GObject *object, - guint param_id, - const GValue *value, - GParamSpec *pspec) -{ - EmpathyTpFile *self = (EmpathyTpFile *) object; - - switch (param_id) - { - case PROP_CHANNEL: - self->priv->channel = g_object_ref (g_value_get_object (value)); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); - break; - }; -} - -static void do_constructed (GObject *object) { EmpathyTpFile *self = (EmpathyTpFile *) object; + TpChannel *channel = (TpChannel *) self; - g_signal_connect (self->priv->channel, "invalidated", + g_signal_connect (self, "invalidated", G_CALLBACK (tp_file_invalidated_cb), self); - self->priv->incoming = !tp_channel_get_requested (self->priv->channel); + self->priv->incoming = !tp_channel_get_requested (channel); tp_cli_channel_type_file_transfer_connect_to_file_transfer_state_changed ( - self->priv->channel, tp_file_state_changed_cb, NULL, NULL, object, NULL); + channel, tp_file_state_changed_cb, NULL, NULL, object, NULL); tp_cli_channel_type_file_transfer_connect_to_transferred_bytes_changed ( - self->priv->channel, tp_file_transferred_bytes_changed_cb, + channel, tp_file_transferred_bytes_changed_cb, NULL, NULL, object, NULL); - tp_cli_dbus_properties_call_get (self->priv->channel, + tp_cli_dbus_properties_call_get (channel, -1, TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER, "State", tp_file_get_state_cb, NULL, NULL, object); - tp_cli_dbus_properties_call_get (self->priv->channel, + tp_cli_dbus_properties_call_get (channel, -1, TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER, "AvailableSocketTypes", tp_file_get_available_socket_types_cb, NULL, NULL, object); @@ -810,66 +754,32 @@ empathy_tp_file_class_init (EmpathyTpFileClass *klass) object_class->finalize = do_finalize; object_class->dispose = do_dispose; object_class->constructed = do_constructed; - object_class->get_property = do_get_property; - object_class->set_property = do_set_property; - - /* Construct-only properties */ - - /** - * EmpathyTpFile:channel: - * - * The #TpChannel requested for the file transfer. - */ - g_object_class_install_property (object_class, - PROP_CHANNEL, - g_param_spec_object ("channel", - "telepathy channel", - "The file transfer channel", - TP_TYPE_CHANNEL, - G_PARAM_READWRITE | - G_PARAM_CONSTRUCT_ONLY)); - - /** - * EmpathyTpFile:incoming: - * - * %TRUE if the transfer is incoming, %FALSE if it's outgoing. - */ - g_object_class_install_property (object_class, - PROP_INCOMING, - g_param_spec_boolean ("incoming", - "direction of transfer", - "The direction of the file being transferred", - FALSE, - G_PARAM_READABLE)); g_type_class_add_private (object_class, sizeof (EmpathyTpFilePrivate)); } /* public methods */ -/** - * empathy_tp_file_new: - * @channel: a #TpChannel - * @incoming: whether the file transfer is incoming or not - * - * Creates a new #EmpathyTpFile wrapping @channel. - * The returned #EmpathyTpFile should be unrefed - * with g_object_unref() when finished with. - * - * Return value: a new #EmpathyTpFile - */ EmpathyTpFile * -empathy_tp_file_new (TpChannel *channel) +empathy_tp_file_new (TpSimpleClientFactory *factory, + TpConnection *conn, + const gchar *object_path, + const GHashTable *immutable_properties, + GError **error) { - EmpathyTpFile *self; - - g_return_val_if_fail (TP_IS_CHANNEL (channel), NULL); - - self = g_object_new (EMPATHY_TYPE_TP_FILE, - "channel", channel, - NULL); - - return self; + TpProxy *conn_proxy = (TpProxy *) conn; + + g_return_val_if_fail (TP_IS_CONNECTION (conn), NULL); + g_return_val_if_fail (immutable_properties != NULL, NULL); + + return g_object_new (EMPATHY_TYPE_TP_FILE, + "factory", factory, + "connection", conn, + "dbus-daemon", conn_proxy->dbus_daemon, + "bus-name", conn_proxy->bus_name, + "object-path", object_path, + "channel-properties", immutable_properties, + NULL); } /** diff --git a/libempathy/empathy-tp-file.h b/libempathy/empathy-tp-file.h index aca8a0f89..7d8520426 100644 --- a/libempathy/empathy-tp-file.h +++ b/libempathy/empathy-tp-file.h @@ -27,7 +27,7 @@ #include <gio/gio.h> #include <glib.h> -#include <telepathy-glib/channel.h> +#include <telepathy-glib/file-transfer-channel.h> G_BEGIN_DECLS @@ -60,12 +60,12 @@ typedef struct _EmpathyTpFilePrivate EmpathyTpFilePrivate; typedef struct _EmpathyTpFileClass EmpathyTpFileClass; struct _EmpathyTpFile { - GObject parent; + TpFileTransferChannel parent; EmpathyTpFilePrivate *priv; }; struct _EmpathyTpFileClass { - GObjectClass parent_class; + TpFileTransferChannelClass parent_class; }; /* prototypes for operation callbacks */ @@ -96,7 +96,11 @@ GType empathy_tp_file_get_type (void) G_GNUC_CONST; /* public methods */ -EmpathyTpFile * empathy_tp_file_new (TpChannel *channel); +EmpathyTpFile * empathy_tp_file_new (TpSimpleClientFactory *factory, + TpConnection *conn, + const gchar *object_path, + const GHashTable *immutable_properties, + GError **error); void empathy_tp_file_accept (EmpathyTpFile *tp_file, guint64 offset, diff --git a/src/empathy-event-manager.c b/src/empathy-event-manager.c index a6ce22b18..1e22aa053 100644 --- a/src/empathy-event-manager.c +++ b/src/empathy-event-manager.c @@ -1115,12 +1115,11 @@ approve_channels (TpSimpleApprover *approver, event_manager_call_channel_got_contact_cb, approval, NULL, G_OBJECT (self)); } - else if (channel_type == TP_IFACE_QUARK_CHANNEL_TYPE_FILE_TRANSFER) + else if (EMPATHY_IS_TP_FILE (channel)) { TpHandle handle; - EmpathyTpFile *tp_file = empathy_tp_file_new (channel); - approval->handler_instance = G_OBJECT (tp_file); + approval->handler_instance = g_object_ref (channel); handle = tp_channel_get_handle (channel, NULL); |