empathy r1881 - in trunk: libempathy libempathy-gtk



Author: xclaesse
Date: Fri Nov 21 16:23:02 2008
New Revision: 1881
URL: http://svn.gnome.org/viewvc/empathy?rev=1881&view=rev

Log:
empathy_tp_file_accept/offer takes the GFile in param and return a GError if the file can't be opened.

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

Modified: trunk/libempathy-gtk/empathy-ft-manager.c
==============================================================================
--- trunk/libempathy-gtk/empathy-ft-manager.c	(original)
+++ trunk/libempathy-gtk/empathy-ft-manager.c	Fri Nov 21 16:23:02 2008
@@ -744,7 +744,7 @@
           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 @@
           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);
 

Modified: trunk/libempathy/empathy-dispatcher.c
==============================================================================
--- trunk/libempathy/empathy-dispatcher.c	(original)
+++ trunk/libempathy/empathy-dispatcher.c	Fri Nov 21 16:23:02 2008
@@ -958,8 +958,7 @@
 				 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);

Modified: trunk/libempathy/empathy-tp-file.c
==============================================================================
--- trunk/libempathy/empathy-tp-file.c	(original)
+++ trunk/libempathy/empathy-tp-file.c	Fri Nov 21 16:23:02 2008
@@ -280,7 +280,6 @@
   TpChannel *channel;
 
   EmpathyContact *contact;
-  GFile *gfile;
   GInputStream *in_stream;
   GOutputStream *out_stream;
 
@@ -370,9 +369,6 @@
   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 @@
                    gpointer user_data,
                    GObject *weak_object)
 {
-  EmpathyTpFile *tp_file = (EmpathyTpFile *) user_data;
+  EmpathyTpFile *tp_file = (EmpathyTpFile *) weak_object;
 
   if (error)
     {
@@ -791,52 +787,70 @@
 /**
  * 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 @@
   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 @@
   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)
 {

Modified: trunk/libempathy/empathy-tp-file.h
==============================================================================
--- trunk/libempathy/empathy-tp-file.h	(original)
+++ trunk/libempathy/empathy-tp-file.h	Fri Nov 21 16:23:02 2008
@@ -67,9 +67,11 @@
 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 @@
 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
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]