diff options
author | Jonny Lamb <jonny.lamb@collabora.co.uk> | 2008-11-22 00:20:08 +0800 |
---|---|---|
committer | Xavier Claessens <xclaesse@src.gnome.org> | 2008-11-22 00:20:08 +0800 |
commit | 1bfcaed673317c3ea7e34903ad224e28a7a6a5ed (patch) | |
tree | 9e08776c82fc51232768e8c136cf20688e2b3c26 /libempathy/empathy-tp-file.c | |
parent | f16740fbe979cf1c99c327befc01e97db54ae26e (diff) | |
download | gsoc2013-empathy-1bfcaed673317c3ea7e34903ad224e28a7a6a5ed.tar gsoc2013-empathy-1bfcaed673317c3ea7e34903ad224e28a7a6a5ed.tar.gz gsoc2013-empathy-1bfcaed673317c3ea7e34903ad224e28a7a6a5ed.tar.bz2 gsoc2013-empathy-1bfcaed673317c3ea7e34903ad224e28a7a6a5ed.tar.lz gsoc2013-empathy-1bfcaed673317c3ea7e34903ad224e28a7a6a5ed.tar.xz gsoc2013-empathy-1bfcaed673317c3ea7e34903ad224e28a7a6a5ed.tar.zst gsoc2013-empathy-1bfcaed673317c3ea7e34903ad224e28a7a6a5ed.zip |
Don't expose streams in EmpathyTpFile, but use the GFile. (Jonny Lamb)
Signed-off-by: Jonny Lamb <jonny.lamb@collabora.co.uk>
svn path=/trunk/; revision=1837
Diffstat (limited to 'libempathy/empathy-tp-file.c')
-rw-r--r-- | libempathy/empathy-tp-file.c | 93 |
1 files changed, 39 insertions, 54 deletions
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)); } |