empathy r1837 - in trunk: libempathy libempathy-gtk



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

Log:
Don't expose streams in EmpathyTpFile, but use the GFile. (Jonny Lamb)

Signed-off-by: Jonny Lamb <jonny lamb collabora co uk>

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:20:08 2008
@@ -764,13 +764,10 @@
       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 @@
               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));

Modified: trunk/libempathy/empathy-dispatcher.c
==============================================================================
--- trunk/libempathy/empathy-dispatcher.c	(original)
+++ trunk/libempathy/empathy-dispatcher.c	Fri Nov 21 16:20:08 2008
@@ -933,7 +933,6 @@
 {
 	GFileInfo      *info;
 	guint64         size;
-	GInputStream   *in_stream = NULL;
 	MissionControl *mc;
 	McAccount      *account;
 	TpConnection   *connection;
@@ -954,7 +953,6 @@
 				  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 @@
 	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);

Modified: trunk/libempathy/empathy-tp-file.c
==============================================================================
--- trunk/libempathy/empathy-tp-file.c	(original)
+++ trunk/libempathy/empathy-tp-file.c	Fri Nov 21 16:20:08 2008
@@ -275,6 +275,7 @@
   TpChannel *channel;
 
   EmpathyContact *contact;
+  GFile *gfile;
   GInputStream *in_stream;
   GOutputStream *out_stream;
   gboolean incoming;
@@ -303,7 +304,6 @@
   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 @@
   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 @@
         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 @@
   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 @@
 }
 
 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 @@
           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));
 }

Modified: trunk/libempathy/empathy-tp-file.h
==============================================================================
--- trunk/libempathy/empathy-tp-file.h	(original)
+++ trunk/libempathy/empathy-tp-file.h	Fri Nov 21 16:20:08 2008
@@ -76,8 +76,6 @@
 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 @@
 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



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