From e5ac1f797a0e2f24f9a2412abf833dcdddf6998d Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Tue, 17 Feb 2009 20:07:06 +0100 Subject: [PATCH] Make libempathy compile with the new changes. --- libempathy/empathy-ft-factory.c | 24 +++-- libempathy/empathy-ft-handler.c | 3 +- libempathy/empathy-tp-file.c | 169 +++++++++++++++----------------- libempathy/empathy-tp-file.h | 3 +- 4 files changed, 100 insertions(+), 99 deletions(-) diff --git a/libempathy/empathy-ft-factory.c b/libempathy/empathy-ft-factory.c index 5f62f99e..407434d6 100644 --- a/libempathy/empathy-ft-factory.c +++ b/libempathy/empathy-ft-factory.c @@ -113,6 +113,22 @@ empathy_ft_factory_init (EmpathyFTFactory *self) self->priv = priv; } +static void +ft_handler_outgoing_ready_cb (EmpathyFTHandler *handler, + GError *error, + gpointer user_data) +{ + EmpathyFTFactory *factory = user_data; + + if (error != NULL) + { + /* TODO: error handling */ + return; + } + + g_signal_emit (factory, signals[NEW_FT_HANDLER], 0, handler, TRUE); +} + static void ft_handler_incoming_ready_cb (EmpathyFTHandler *handler, GError *error, @@ -142,16 +158,12 @@ empathy_ft_factory_new_transfer (EmpathyFTFactory *factory, EmpathyContact *contact, GFile *source) { - EmpathyFTHandler *handler; - g_return_if_fail (EMPATHY_IS_FT_FACTORY (factory)); g_return_if_fail (EMPATHY_IS_CONTACT (contact)); g_return_if_fail (G_IS_FILE (source)); - handler = empathy_ft_handler_new_outgoing (contact, source); - g_signal_emit (factory, signals[NEW_FT_HANDLER], 0, handler, TRUE); - - g_object_unref (handler); + empathy_ft_handler_new_outgoing (contact, source, + ft_handler_outgoing_ready_cb, factory); } void diff --git a/libempathy/empathy-ft-handler.c b/libempathy/empathy-ft-handler.c index 85d70dbd..ca054aa3 100644 --- a/libempathy/empathy-ft-handler.c +++ b/libempathy/empathy-ft-handler.c @@ -334,7 +334,6 @@ ft_transfer_operation_callback (EmpathyTpFile *tp_file, static void ft_transfer_progress_callback (EmpathyTpFile *tp_file, guint64 transferred_bytes, - guint64 total_bytes, gpointer user_data) { EmpathyFTHandler *handler = user_data; @@ -344,7 +343,7 @@ ft_transfer_progress_callback (EmpathyTpFile *tp_file, { priv->transferred_bytes = transferred_bytes; g_signal_emit (handler, signals[TRANSFER_PROGRESS], 0, - transferred_bytes, total_bytes); + transferred_bytes, priv->total_bytes); } } diff --git a/libempathy/empathy-tp-file.c b/libempathy/empathy-tp-file.c index 6f794b28..cbaff763 100644 --- a/libempathy/empathy-tp-file.c +++ b/libempathy/empathy-tp-file.c @@ -25,6 +25,7 @@ #include #include +#include #include #include #include @@ -90,6 +91,7 @@ struct _EmpathyTpFilePriv { gboolean incoming; time_t start_time; gchar *unix_socket_path; + guint64 offset; /* GCancellable we're passed when offering/accepting the transfer */ GCancellable *cancellable; @@ -97,7 +99,7 @@ struct _EmpathyTpFilePriv { /* callbacks for the operation */ EmpathyTpFileProgressCallback progress_callback; gpointer progress_user_data; - EmpathyTpFileOperationCallback op_callback, + EmpathyTpFileOperationCallback op_callback; gpointer op_user_data; }; @@ -107,6 +109,11 @@ enum { PROP_STATE }; +static void tp_file_state_changed_cb (TpProxy *proxy, guint state, + guint reason, gpointer user_data, GObject *weak_object); +static void tp_file_transferred_bytes_changed_cb (TpProxy *proxy, guint64 count, + gpointer user_data, GObject *weak_object); + #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyTpFile) G_DEFINE_TYPE (EmpathyTpFile, empathy_tp_file, G_TYPE_OBJECT); @@ -162,11 +169,7 @@ tp_file_finalize (GObject *object) g_object_unref (priv->factory); } - g_free (priv->filename); g_free (priv->unix_socket_path); - g_free (priv->description); - g_free (priv->content_hash); - g_free (priv->content_type); if (priv->in_stream) g_object_unref (priv->in_stream); @@ -202,7 +205,7 @@ tp_file_get_property (GObject *object, GValue *value, GParamSpec *pspec) { - EmpathyTpFilePriv = GET_PRIV (object); + EmpathyTpFilePriv *priv = GET_PRIV (object); switch (param_id) { @@ -266,9 +269,6 @@ tp_file_constructor (GType type, GObject *file_obj; EmpathyTpFile *tp_file; EmpathyTpFilePriv *priv; - TpHandle handle; - GHashTable *properties; - McAccount *account; file_obj = G_OBJECT_CLASS (empathy_tp_file_parent_class)->constructor (type, n_props, props); @@ -276,8 +276,6 @@ tp_file_constructor (GType type, tp_file = EMPATHY_TP_FILE (file_obj); priv = GET_PRIV (tp_file); - priv->factory = empathy_contact_factory_dup_singleton (); - g_signal_connect (priv->channel, "invalidated", G_CALLBACK (tp_file_invalidated_cb), tp_file); @@ -289,12 +287,6 @@ tp_file_constructor (GType type, TP_PROXY (priv->channel), tp_file_transferred_bytes_changed_cb, NULL, NULL, G_OBJECT (tp_file), NULL); - account = empathy_channel_get_account (priv->channel); - - handle = tp_channel_get_handle (priv->channel, NULL); - priv->contact = empathy_contact_factory_get_from_handle ( - priv->factory, account, (guint) handle); - tp_cli_dbus_properties_call_get (priv->channel, -1, EMP_IFACE_CHANNEL_TYPE_FILE_TRANSFER, "State", tp_file_get_state_cb, NULL, NULL, file_obj); @@ -302,8 +294,6 @@ tp_file_constructor (GType type, priv->state_change_reason = EMP_FILE_TRANSFER_STATE_CHANGE_REASON_NONE; - g_object_unref (account); - return file_obj; } @@ -360,59 +350,6 @@ ft_operation_close_with_error (EmpathyTpFile *tp_file, priv->op_callback (tp_file, error, priv->op_user_data); } -static void -tp_file_state_changed_cb (TpProxy *proxy, - guint state, - guint reason, - gpointer user_data, - GObject *weak_object) -{ - EmpathyTpFilePriv *priv = GET_PRIV (weak_object); - - if (state == priv->state) - return; - - DEBUG ("File transfer state changed:\n" - "\tfilename = %s, old state = %u, state = %u, reason = %u\n" - "\tincoming = %s, in_stream = %s, out_stream = %s", - priv->filename, priv->state, state, reason, - priv->incoming ? "yes" : "no", - priv->in_stream ? "present" : "not present", - priv->out_stream ? "present" : "not present"); - - /* If the channel is open AND we have the socket path, we can start the - * transfer. The socket path could be NULL if we are not doing the actual - * data transfer but are just an observer for the channel. - */ - if (state == EMP_FILE_TRANSFER_STATE_OPEN && - priv->unix_socket_path != NULL) - tp_file_start_transfer (tp_file); - - priv->state = state; - priv->state_change_reason = reason; - - g_object_notify (G_OBJECT (tp_file), "state"); -} - -static void -tp_file_transferred_bytes_changed_cb (TpProxy *proxy, - guint64 count, - gpointer user_data, - GObject *weak_object) -{ - EmpathyTpFilePriv *priv = GET_PRIV (weak_object); - - if (priv->transferred_bytes == count) - return; - - priv->transferred_bytes = count; - - /* notify clients */ - if (priv->progress_callback) - priv->progress_callback (EMPATHY_TP_FILE (weak_object), - priv->transferred_bytes, priv->size, priv->progress_user_data); -} - static void splice_stream_ready_cb (GObject *source, GAsyncResult *res, @@ -487,8 +424,7 @@ tp_file_start_transfer (EmpathyTpFile *tp_file) /* notify we're starting a transfer */ if (priv->progress_callback) - priv->progress_callback (tp_file, 0, priv->size, - priv->progress_callback_user_data); + priv->progress_callback (tp_file, 0, priv->progress_user_data); if (priv->incoming) { @@ -520,6 +456,54 @@ tp_file_start_transfer (EmpathyTpFile *tp_file) } } +static void +tp_file_state_changed_cb (TpProxy *proxy, + guint state, + guint reason, + gpointer user_data, + GObject *weak_object) +{ + EmpathyTpFilePriv *priv = GET_PRIV (weak_object); + + if (state == priv->state) + return; + + DEBUG ("File transfer state changed:\n" + "old state = %u, state = %u, reason = %u\n" + "\tincoming = %s, in_stream = %s, out_stream = %s", + priv->state, state, reason, + priv->incoming ? "yes" : "no", + priv->in_stream ? "present" : "not present", + priv->out_stream ? "present" : "not present"); + + /* If the channel is open AND we have the socket path, we can start the + * transfer. The socket path could be NULL if we are not doing the actual + * data transfer but are just an observer for the channel. + */ + if (state == EMP_FILE_TRANSFER_STATE_OPEN && + priv->unix_socket_path != NULL) + tp_file_start_transfer (EMPATHY_TP_FILE (weak_object)); + + priv->state = state; + priv->state_change_reason = reason; + + g_object_notify (weak_object, "state"); +} + +static void +tp_file_transferred_bytes_changed_cb (TpProxy *proxy, + guint64 count, + gpointer user_data, + GObject *weak_object) +{ + EmpathyTpFilePriv *priv = GET_PRIV (weak_object); + + /* notify clients */ + if (priv->progress_callback) + priv->progress_callback (EMPATHY_TP_FILE (weak_object), + count, priv->progress_user_data); +} + static void ft_operation_provide_or_accept_file_cb (TpProxy *proxy, const GValue *address, @@ -589,7 +573,7 @@ file_read_async_cb (GObject *source, g_value_set_static_string (¬hing, ""); emp_cli_channel_type_file_transfer_call_provide_file ( - TP_PROXY (tp_file->priv->channel), -1, + TP_PROXY (priv->channel), -1, TP_SOCKET_ADDRESS_TYPE_UNIX, TP_SOCKET_ACCESS_CONTROL_LOCALHOST, ¬hing, ft_operation_provide_or_accept_file_cb, NULL, NULL, G_OBJECT (tp_file)); } @@ -617,20 +601,15 @@ file_replace_async_cb (GObject *source, return; } - priv->out_stream = out_stream; - - priv->filename = g_file_get_basename (gfile); - g_object_notify (G_OBJECT (tp_file), "filename"); - - DEBUG ("Accepting file: filename=%s", tp_file->priv->filename); + priv->out_stream = G_OUTPUT_STREAM (out_stream); g_value_init (¬hing, G_TYPE_STRING); g_value_set_static_string (¬hing, ""); emp_cli_channel_type_file_transfer_call_accept_file (TP_PROXY (priv->channel), -1, TP_SOCKET_ADDRESS_TYPE_UNIX, TP_SOCKET_ACCESS_CONTROL_LOCALHOST, - ¬hing, offset, ft_operation_provide_or_accept_file_cb, NULL, NULL, - G_OBJECT (tp_file)); + ¬hing, priv->offset, + ft_operation_provide_or_accept_file_cb, NULL, NULL, G_OBJECT (tp_file)); } @@ -682,9 +661,10 @@ empathy_tp_file_accept (EmpathyTpFile *tp_file, priv->op_callback = op_callback; priv->op_user_data = op_user_data; priv->incoming = TRUE; + priv->offset = offset; - g_file_replace_async (file, G_PRIORITY_DEFAULT, cancellable, - file_replace_async_cb, tp_file); + g_file_replace_async (gfile, NULL, FALSE, G_FILE_CREATE_NONE, + G_PRIORITY_DEFAULT, cancellable, file_replace_async_cb, tp_file); } void @@ -709,7 +689,7 @@ empathy_tp_file_offer (EmpathyTpFile *tp_file, priv->op_user_data = op_user_data; priv->incoming = FALSE; - g_file_read_async (file, G_PRIORITY_DEFAULT, cancellable, + g_file_read_async (gfile, G_PRIORITY_DEFAULT, cancellable, file_read_async_cb, tp_file); } @@ -724,8 +704,13 @@ empathy_tp_file_offer (EmpathyTpFile *tp_file, gboolean empathy_tp_file_is_incoming (EmpathyTpFile *tp_file) { + EmpathyTpFilePriv *priv; + g_return_val_if_fail (EMPATHY_IS_TP_FILE (tp_file), FALSE); - return tp_file->priv->incoming; + + priv = GET_PRIV (tp_file); + + return priv->incoming; } /** @@ -762,14 +747,18 @@ empathy_tp_file_get_state (EmpathyTpFile *tp_file, void empathy_tp_file_cancel (EmpathyTpFile *tp_file) { + EmpathyTpFilePriv *priv; + g_return_if_fail (EMPATHY_IS_TP_FILE (tp_file)); + + priv = GET_PRIV (tp_file); DEBUG ("Closing channel.."); - tp_cli_channel_call_close (tp_file->priv->channel, -1, + tp_cli_channel_call_close (priv->channel, -1, NULL, NULL, NULL, NULL); - if (tp_file->priv->cancellable != NULL) - g_cancellable_cancel (tp_file->priv->cancellable); + if (priv->cancellable != NULL) + g_cancellable_cancel (priv->cancellable); } /** diff --git a/libempathy/empathy-tp-file.h b/libempathy/empathy-tp-file.h index a1447f38..b6fb7ff3 100644 --- a/libempathy/empathy-tp-file.h +++ b/libempathy/empathy-tp-file.h @@ -62,7 +62,6 @@ struct _EmpathyTpFileClass typedef void (* EmpathyTpFileProgressCallback) (EmpathyTpFile *tp_file, guint64 current_bytes, - guint64 total_bytes, gpointer user_data); typedef void (* EmpathyTpFileOperationCallback) @@ -96,6 +95,8 @@ void empathy_tp_file_offer (EmpathyTpFile *tp_file, void empathy_tp_file_cancel (EmpathyTpFile *tp_file); void empathy_tp_file_close (EmpathyTpFile *tp_file); +gboolean empathy_tp_file_is_incoming (EmpathyTpFile *tp_file); + guint empathy_tp_file_get_state (EmpathyTpFile *tp_file, guint *reason); G_END_DECLS -- 2.39.2