aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libempathy-gtk/empathy-ft-manager.c13
-rw-r--r--libempathy/empathy-dispatcher.c4
-rw-r--r--libempathy/empathy-tp-file.c93
-rw-r--r--libempathy/empathy-tp-file.h6
4 files changed, 43 insertions, 73 deletions
diff --git a/libempathy-gtk/empathy-ft-manager.c b/libempathy-gtk/empathy-ft-manager.c
index 5814d14fe..53b69fb48 100644
--- a/libempathy-gtk/empathy-ft-manager.c
+++ b/libempathy-gtk/empathy-ft-manager.c
@@ -764,13 +764,10 @@ ft_manager_save_dialog_response_cb (GtkDialog *widget,
if (uri)
{
GFile *file;
- GOutputStream *out_stream;
- gchar *filename;
GError *error = NULL;
file = g_file_new_for_uri (uri);
- out_stream = G_OUTPUT_STREAM (g_file_replace (file, NULL,
- FALSE, 0, NULL, &error));
+ empathy_tp_file_set_gfile (response_data->tp_file, file, &error);
if (error)
{
@@ -780,23 +777,15 @@ ft_manager_save_dialog_response_cb (GtkDialog *widget,
return;
}
- empathy_tp_file_set_output_stream (response_data->tp_file, out_stream);
-
g_object_set_data_full (G_OBJECT (response_data->tp_file),
"uri", uri, g_free);
- filename = g_file_get_basename (file);
- empathy_tp_file_set_filename (response_data->tp_file, filename);
-
empathy_tp_file_accept (response_data->tp_file, 0);
ft_manager_add_tp_file_to_list (response_data->ft_manager,
response_data->tp_file);
- g_free (filename);
g_object_unref (file);
- if (out_stream)
- g_object_unref (out_stream);
}
folder = gtk_file_chooser_get_current_folder (GTK_FILE_CHOOSER (widget));
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