diff options
Diffstat (limited to 'libempathy')
-rw-r--r-- | libempathy/empathy-dispatcher.c | 4 | ||||
-rw-r--r-- | libempathy/empathy-tp-file.c | 93 | ||||
-rw-r--r-- | libempathy/empathy-tp-file.h | 6 |
3 files changed, 42 insertions, 61 deletions
diff --git a/libempathy/empathy-dispatcher.c b/libempathy/empathy-dispatcher.c index a110a2f94..69a8e80cc 100644 --- a/libempathy/empathy-dispatcher.c +++ b/libempathy/empathy-dispatcher.c @@ -933,7 +933,6 @@ empathy_dispatcher_send_file (EmpathyContact *contact, { GFileInfo *info; guint64 size; - GInputStream *in_stream = NULL; MissionControl *mc; McAccount *account; TpConnection *connection; @@ -954,7 +953,6 @@ empathy_dispatcher_send_file (EmpathyContact *contact, 0, NULL, NULL); size = info ? g_file_info_get_size (info) : EMPATHY_TP_FILE_UNKNOWN_SIZE; filename = g_file_get_basename (gfile); - in_stream = G_INPUT_STREAM (g_file_read (gfile, NULL, NULL)); mc = empathy_mission_control_new (); account = empathy_contact_get_account (contact); connection = mission_control_get_tpconnection (mc, account, NULL); @@ -1014,7 +1012,7 @@ empathy_dispatcher_send_file (EmpathyContact *contact, tp_file = empathy_tp_file_new (channel); if (tp_file) { - empathy_tp_file_set_input_stream (tp_file, in_stream); + empathy_tp_file_set_gfile (tp_file, gfile, NULL); } empathy_tp_file_offer (tp_file); diff --git a/libempathy/empathy-tp-file.c b/libempathy/empathy-tp-file.c index bfc5e71a6..3a2083b3b 100644 --- a/libempathy/empathy-tp-file.c +++ b/libempathy/empathy-tp-file.c @@ -275,6 +275,7 @@ struct _EmpathyTpFilePriv { TpChannel *channel; EmpathyContact *contact; + GFile *gfile; GInputStream *in_stream; GOutputStream *out_stream; gboolean incoming; @@ -303,7 +304,6 @@ enum { PROP_TRANSFERRED_BYTES, PROP_CONTENT_HASH_TYPE, PROP_CONTENT_HASH, - PROP_IN_STREAM, }; G_DEFINE_TYPE (EmpathyTpFile, empathy_tp_file, G_TYPE_OBJECT); @@ -362,6 +362,9 @@ 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); @@ -663,11 +666,6 @@ tp_file_set_property (GObject *object, g_free (tp_file->priv->content_hash); tp_file->priv->content_hash = g_value_dup_string (value); break; - case PROP_IN_STREAM: - if (tp_file->priv->in_stream) - g_object_unref (tp_file->priv->in_stream); - tp_file->priv->in_stream = g_object_ref (g_value_get_object (value)); - break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); break; @@ -805,18 +803,11 @@ empathy_tp_file_get_contact (EmpathyTpFile *tp_file) return tp_file->priv->contact; } -GInputStream * -empathy_tp_file_get_input_stream (EmpathyTpFile *tp_file) +GFile * +empathy_tp_file_get_gfile (EmpathyTpFile *tp_file) { g_return_val_if_fail (EMPATHY_IS_TP_FILE (tp_file), NULL); - return tp_file->priv->in_stream; -} - -GOutputStream * -empathy_tp_file_get_output_stream (EmpathyTpFile *tp_file) -{ - g_return_val_if_fail (EMPATHY_IS_TP_FILE (tp_file), NULL); - return tp_file->priv->out_stream; + return g_object_ref (tp_file->priv->gfile); } const gchar * @@ -901,51 +892,53 @@ empathy_tp_file_cancel (EmpathyTpFile *tp_file) } void -empathy_tp_file_set_input_stream (EmpathyTpFile *tp_file, - GInputStream *in_stream) +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 (G_IS_INPUT_STREAM (in_stream)); + g_return_if_fail (gfile); - if (tp_file->priv->in_stream == in_stream) + if (tp_file->priv->gfile == gfile) return; - if (tp_file->priv->incoming) - g_warning ("Setting an input stream for incoming file " - "transfers is useless"); + tp_file->priv->gfile = g_object_ref (gfile); - if (tp_file->priv->in_stream) - g_object_unref (tp_file->priv->in_stream); + if (!tp_file->priv->incoming) + { + GInputStream *in_stream; - if (in_stream) - g_object_ref (in_stream); + in_stream = G_INPUT_STREAM (g_file_read (gfile, NULL, NULL)); - tp_file->priv->in_stream = in_stream; + if (tp_file->priv->in_stream) + g_object_unref (tp_file->priv->in_stream); - g_object_notify (G_OBJECT (tp_file), "in-stream"); -} + tp_file->priv->in_stream = g_object_ref (in_stream); + } + else + { + GOutputStream *out_stream; + gchar *filename; -void -empathy_tp_file_set_output_stream (EmpathyTpFile *tp_file, - GOutputStream *out_stream) -{ - g_return_if_fail (EMPATHY_IS_TP_FILE (tp_file)); - g_return_if_fail (G_IS_OUTPUT_STREAM (out_stream)); + out_stream = G_OUTPUT_STREAM (g_file_replace (gfile, NULL, FALSE, + 0, NULL, error)); - if (tp_file->priv->out_stream == out_stream) - return; + if (*error) + return; - if (!tp_file->priv->incoming) - g_warning ("Setting an output stream for outgoing file " - "transfers is useless"); + if (tp_file->priv->out_stream == out_stream) + return; - if (tp_file->priv->out_stream) - g_object_unref (tp_file->priv->out_stream); + if (tp_file->priv->out_stream) + g_object_unref (tp_file->priv->out_stream); + + tp_file->priv->out_stream = g_object_ref (out_stream); - if (out_stream) - g_object_ref (out_stream); + filename = g_file_get_basename (gfile); + empathy_tp_file_set_filename (tp_file, filename); - tp_file->priv->out_stream = out_stream; + g_free (filename); + } } void @@ -1059,13 +1052,5 @@ empathy_tp_file_class_init (EmpathyTpFileClass *klass) 0, G_PARAM_READWRITE)); - g_object_class_install_property (object_class, - PROP_IN_STREAM, - g_param_spec_object ("in-stream", - "transfer input stream", - "The input stream for file transfer", - G_TYPE_INPUT_STREAM, - G_PARAM_READWRITE)); - g_type_class_add_private (object_class, sizeof (EmpathyTpFilePriv)); } diff --git a/libempathy/empathy-tp-file.h b/libempathy/empathy-tp-file.h index f412f847b..fe85296b8 100644 --- a/libempathy/empathy-tp-file.h +++ b/libempathy/empathy-tp-file.h @@ -76,8 +76,6 @@ void empathy_tp_file_offer (EmpathyTpFile *tp_file); const gchar *empathy_tp_file_get_id (EmpathyTpFile *tp_file); guint64 empathy_tp_file_get_transferred_bytes (EmpathyTpFile *tp_file); EmpathyContact *empathy_tp_file_get_contact (EmpathyTpFile *tp_file); -GInputStream *empathy_tp_file_get_input_stream (EmpathyTpFile *tp_file); -GOutputStream *empathy_tp_file_get_output_stream (EmpathyTpFile *tp_file); const gchar *empathy_tp_file_get_filename (EmpathyTpFile *tp_file); gboolean empathy_tp_file_get_incoming (EmpathyTpFile *tp_file); EmpFileTransferState empathy_tp_file_get_state (EmpathyTpFile *tp_file); @@ -85,9 +83,9 @@ 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_input_stream (EmpathyTpFile *tp_file, GInputStream *uri); -void empathy_tp_file_set_output_stream (EmpathyTpFile *tp_file, GOutputStream *uri); +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 |