diff options
author | Xavier Claessens <xclaesse@src.gnome.org> | 2008-11-22 00:23:02 +0800 |
---|---|---|
committer | Xavier Claessens <xclaesse@src.gnome.org> | 2008-11-22 00:23:02 +0800 |
commit | 2f6a0562f6b163cbbd8df706ade46802ab02c1d5 (patch) | |
tree | c7876efe1be33e0db7a7dbf841187ea87247a6c3 | |
parent | 0ec0fd88d836a9c72df629d410ed7eeb5a60d540 (diff) | |
download | gsoc2013-empathy-2f6a0562f6b163cbbd8df706ade46802ab02c1d5.tar gsoc2013-empathy-2f6a0562f6b163cbbd8df706ade46802ab02c1d5.tar.gz gsoc2013-empathy-2f6a0562f6b163cbbd8df706ade46802ab02c1d5.tar.bz2 gsoc2013-empathy-2f6a0562f6b163cbbd8df706ade46802ab02c1d5.tar.lz gsoc2013-empathy-2f6a0562f6b163cbbd8df706ade46802ab02c1d5.tar.xz gsoc2013-empathy-2f6a0562f6b163cbbd8df706ade46802ab02c1d5.tar.zst gsoc2013-empathy-2f6a0562f6b163cbbd8df706ade46802ab02c1d5.zip |
empathy_tp_file_accept/offer takes the GFile in param and return a GError if the file can't be opened.
svn path=/trunk/; revision=1881
-rw-r--r-- | libempathy-gtk/empathy-ft-manager.c | 4 | ||||
-rw-r--r-- | libempathy/empathy-dispatcher.c | 3 | ||||
-rw-r--r-- | libempathy/empathy-tp-file.c | 112 | ||||
-rw-r--r-- | libempathy/empathy-tp-file.h | 10 |
4 files changed, 32 insertions, 97 deletions
diff --git a/libempathy-gtk/empathy-ft-manager.c b/libempathy-gtk/empathy-ft-manager.c index 624680d93..df4b61d49 100644 --- a/libempathy-gtk/empathy-ft-manager.c +++ b/libempathy-gtk/empathy-ft-manager.c @@ -744,7 +744,7 @@ ft_manager_save_dialog_response_cb (GtkDialog *widget, GError *error = NULL; file = g_file_new_for_uri (uri); - empathy_tp_file_set_gfile (response_data->tp_file, file, &error); + empathy_tp_file_accept (response_data->tp_file, 0, file, &error); if (error) { @@ -773,8 +773,6 @@ ft_manager_save_dialog_response_cb (GtkDialog *widget, g_object_set_data_full (G_OBJECT (response_data->tp_file), "uri", uri, g_free); - empathy_tp_file_accept (response_data->tp_file, 0); - ft_manager_add_tp_file_to_list (response_data->ft_manager, response_data->tp_file); diff --git a/libempathy/empathy-dispatcher.c b/libempathy/empathy-dispatcher.c index 1d7578d2c..1ba3adf3c 100644 --- a/libempathy/empathy-dispatcher.c +++ b/libempathy/empathy-dispatcher.c @@ -958,8 +958,7 @@ file_channel_create_cb (TpConnection *connection, NULL); tp_file = empathy_tp_file_new (channel); - empathy_tp_file_set_gfile (tp_file, request->gfile, NULL); - empathy_tp_file_offer (tp_file); + empathy_tp_file_offer (tp_file, request->gfile, NULL); g_object_unref (request->gfile); g_slice_free (FileChannelRequest, request); diff --git a/libempathy/empathy-tp-file.c b/libempathy/empathy-tp-file.c index e0516c32b..c26f939f6 100644 --- a/libempathy/empathy-tp-file.c +++ b/libempathy/empathy-tp-file.c @@ -280,7 +280,6 @@ struct _EmpathyTpFilePriv { TpChannel *channel; EmpathyContact *contact; - GFile *gfile; GInputStream *in_stream; GOutputStream *out_stream; @@ -370,9 +369,6 @@ tp_file_finalize (GObject *object) g_free (tp_file->priv->content_hash); g_free (tp_file->priv->content_type); - if (tp_file->priv->gfile) - g_object_unref (tp_file->priv->gfile); - if (tp_file->priv->in_stream) g_object_unref (tp_file->priv->in_stream); @@ -771,7 +767,7 @@ tp_file_method_cb (TpProxy *proxy, gpointer user_data, GObject *weak_object) { - EmpathyTpFile *tp_file = (EmpathyTpFile *) user_data; + EmpathyTpFile *tp_file = (EmpathyTpFile *) weak_object; if (error) { @@ -791,52 +787,70 @@ tp_file_method_cb (TpProxy *proxy, /** * empathy_tp_file_accept: * @tp_file: an #EmpathyTpFile + * @offset: position where to start the transfer + * @gfile: a #GFile where to write transfered data + * @error: a #GError set if there is an error when opening @gfile * * Accepts a file transfer that's in the "local pending" state (i.e. * EMP_FILE_TRANSFER_STATE_LOCAL_PENDING). */ void empathy_tp_file_accept (EmpathyTpFile *tp_file, - guint64 offset) + guint64 offset, + GFile *gfile, + GError **error) { GValue nothing = { 0 }; g_return_if_fail (EMPATHY_IS_TP_FILE (tp_file)); + g_return_if_fail (G_IS_FILE (gfile)); + + tp_file->priv->out_stream = G_OUTPUT_STREAM (g_file_replace (gfile, NULL, + FALSE, 0, NULL, error)); + if (error && *error) + return; - g_return_if_fail (tp_file->priv->out_stream != NULL); + tp_file->priv->filename = g_file_get_basename (gfile); + g_object_notify (G_OBJECT (tp_file), "filename"); DEBUG ("Accepting file: filename=%s", tp_file->priv->filename); g_value_init (¬hing, G_TYPE_STRING); - g_value_set_string (¬hing, ""); + g_value_set_static_string (¬hing, ""); emp_cli_channel_type_file_transfer_call_accept_file (TP_PROXY ( tp_file->priv->channel), -1, TP_SOCKET_ADDRESS_TYPE_UNIX, TP_SOCKET_ACCESS_CONTROL_LOCALHOST, - ¬hing, offset, tp_file_method_cb, tp_file, NULL, NULL); + ¬hing, offset, tp_file_method_cb, NULL, NULL, G_OBJECT (tp_file)); } /** * empathy_tp_file_offer: * @tp_file: an #EmpathyTpFile + * @gfile: a #GFile where to read the data to transfer + * @error: a #GError set if there is an error when opening @gfile * * Offers a file transfer that's in the "not offered" state (i.e. * EMP_FILE_TRANSFER_STATE_NOT_OFFERED). */ void -empathy_tp_file_offer (EmpathyTpFile *tp_file) +empathy_tp_file_offer (EmpathyTpFile *tp_file, GFile *gfile, GError **error) { GValue nothing = { 0 }; g_return_if_fail (EMPATHY_IS_TP_FILE (tp_file)); + tp_file->priv->in_stream = G_INPUT_STREAM (g_file_read (gfile, NULL, error)); + if (error && *error) + return; + g_value_init (¬hing, G_TYPE_STRING); - g_value_set_string (¬hing, ""); + g_value_set_static_string (¬hing, ""); emp_cli_channel_type_file_transfer_call_provide_file ( TP_PROXY (tp_file->priv->channel), -1, TP_SOCKET_ADDRESS_TYPE_UNIX, TP_SOCKET_ACCESS_CONTROL_LOCALHOST, - ¬hing, tp_file_method_cb, tp_file, NULL, NULL); + ¬hing, tp_file_method_cb, NULL, NULL, G_OBJECT (tp_file)); } EmpathyContact * @@ -846,13 +860,6 @@ empathy_tp_file_get_contact (EmpathyTpFile *tp_file) return tp_file->priv->contact; } -GFile * -empathy_tp_file_get_gfile (EmpathyTpFile *tp_file) -{ - g_return_val_if_fail (EMPATHY_IS_TP_FILE (tp_file), NULL); - return g_object_ref (tp_file->priv->gfile); -} - const gchar * empathy_tp_file_get_filename (EmpathyTpFile *tp_file) { @@ -934,73 +941,6 @@ empathy_tp_file_cancel (EmpathyTpFile *tp_file) g_cancellable_cancel (tp_file->priv->cancellable); } -void -empathy_tp_file_set_gfile (EmpathyTpFile *tp_file, - GFile *gfile, - GError **error) -{ - g_return_if_fail (EMPATHY_IS_TP_FILE (tp_file)); - g_return_if_fail (gfile); - - if (tp_file->priv->gfile == gfile) - return; - - tp_file->priv->gfile = g_object_ref (gfile); - - if (!tp_file->priv->incoming) - { - GInputStream *in_stream; - - in_stream = G_INPUT_STREAM (g_file_read (gfile, NULL, NULL)); - - if (tp_file->priv->in_stream) - g_object_unref (tp_file->priv->in_stream); - - tp_file->priv->in_stream = g_object_ref (in_stream); - } - else - { - GOutputStream *out_stream; - gchar *filename; - - out_stream = G_OUTPUT_STREAM (g_file_replace (gfile, NULL, FALSE, - 0, NULL, error)); - - if (*error) - return; - - if (tp_file->priv->out_stream == out_stream) - return; - - if (tp_file->priv->out_stream) - g_object_unref (tp_file->priv->out_stream); - - tp_file->priv->out_stream = g_object_ref (out_stream); - - filename = g_file_get_basename (gfile); - empathy_tp_file_set_filename (tp_file, filename); - - g_free (filename); - } -} - -void -empathy_tp_file_set_filename (EmpathyTpFile *tp_file, - const gchar *filename) -{ - g_return_if_fail (EMPATHY_IS_TP_FILE (tp_file)); - g_return_if_fail (filename != NULL); - - if (tp_file->priv->filename && strcmp (filename, - tp_file->priv->filename) == 0) - return; - - g_free (tp_file->priv->filename); - tp_file->priv->filename = g_strdup (filename); - - g_object_notify (G_OBJECT (tp_file), "filename"); -} - static void empathy_tp_file_class_init (EmpathyTpFileClass *klass) { diff --git a/libempathy/empathy-tp-file.h b/libempathy/empathy-tp-file.h index 04bd8fa58..408b67cb0 100644 --- a/libempathy/empathy-tp-file.h +++ b/libempathy/empathy-tp-file.h @@ -67,9 +67,11 @@ GType empathy_tp_file_get_type (void) G_GNUC_CONST; EmpathyTpFile *empathy_tp_file_new (TpChannel *channel); TpChannel *empathy_tp_file_get_channel (EmpathyTpFile *tp_file); -void empathy_tp_file_accept (EmpathyTpFile *tp_file, guint64 offset); +void empathy_tp_file_accept (EmpathyTpFile *tp_file, guint64 offset, + GFile *gfile, GError **error); void empathy_tp_file_cancel (EmpathyTpFile *tp_file); -void empathy_tp_file_offer (EmpathyTpFile *tp_file); +void empathy_tp_file_offer (EmpathyTpFile *tp_file, GFile *gfile, + GError **error); const gchar *empathy_tp_file_get_id (EmpathyTpFile *tp_file); guint64 empathy_tp_file_get_transferred_bytes (EmpathyTpFile *tp_file); @@ -81,10 +83,6 @@ EmpFileTransferStateChangeReason empathy_tp_file_get_state_change_reason (Empath guint64 empathy_tp_file_get_size (EmpathyTpFile *tp_file); guint64 empathy_tp_file_get_transferred_bytes (EmpathyTpFile *tp_file); gint empathy_tp_file_get_remaining_time (EmpathyTpFile *tp_file); -GFile *empathy_tp_file_get_gfile (EmpathyTpFile *tp_file); - -void empathy_tp_file_set_gfile (EmpathyTpFile *tp_file, GFile *gfile, GError **error); -void empathy_tp_file_set_filename (EmpathyTpFile *tp_file, const gchar *filename); G_END_DECLS |