]> git.0d.be Git - empathy.git/commitdiff
empathy_tp_file_accept/offer takes the GFile in param and return a GError if the...
authorXavier Claessens <xclaesse@src.gnome.org>
Fri, 21 Nov 2008 16:23:02 +0000 (16:23 +0000)
committerXavier Claessens <xclaesse@src.gnome.org>
Fri, 21 Nov 2008 16:23:02 +0000 (16:23 +0000)
svn path=/trunk/; revision=1881

libempathy-gtk/empathy-ft-manager.c
libempathy/empathy-dispatcher.c
libempathy/empathy-tp-file.c
libempathy/empathy-tp-file.h

index 624680d93e2b26c7b29ae3545b99252a2d670257..df4b61d4975838530c2c0765c7685a87a790fe5e 100644 (file)
@@ -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);
 
index 1d7578d2c686b63eb03a780620e741b00b3a9685..1ba3adf3cc1f1830046b2ff04598ec841c8b5b2c 100644 (file)
@@ -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);
index e0516c32b511c2859b1f634f470e05198702d810..c26f939f69eb1557172aa9ea1b6a58dd54b2db87 100644 (file)
@@ -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 (&nothing, G_TYPE_STRING);
-  g_value_set_string (&nothing, "");
+  g_value_set_static_string (&nothing, "");
 
   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,
-      &nothing, offset, tp_file_method_cb, tp_file, NULL, NULL);
+      &nothing, 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 (&nothing, G_TYPE_STRING);
-  g_value_set_string (&nothing, "");
+  g_value_set_static_string (&nothing, "");
 
   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,
-      &nothing, tp_file_method_cb, tp_file, NULL, NULL);
+      &nothing, 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)
 {
index 04bd8fa58ff3537231411413150a93493d67b73c..408b67cb0b936bf119980febfe3073421955cc6a 100644 (file)
@@ -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