]> git.0d.be Git - empathy.git/blobdiff - libempathy/empathy-tp-file.c
Merge branch 'sasl'
[empathy.git] / libempathy / empathy-tp-file.c
index e60b2999d045b8752d3ef12e1cd60e9d3aace5e1..25a8c40bc095c254bca7f8c2d4d03fec35399768 100644 (file)
@@ -30,6 +30,7 @@
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <sys/un.h>
+#include <netinet/in.h>
 
 #include <glib/gi18n-lib.h>
 
@@ -40,6 +41,7 @@
 #include <telepathy-glib/gtypes.h>
 #include <telepathy-glib/proxy-subclass.h>
 #include <telepathy-glib/util.h>
+#include <telepathy-glib/interfaces.h>
 
 #include "empathy-tp-file.h"
 #include "empathy-marshal.h"
@@ -65,7 +67,6 @@
 
 typedef struct {
   TpChannel *channel;
-  gboolean ready;
 
   GInputStream *in_stream;
   GOutputStream *out_stream;
@@ -92,6 +93,7 @@ typedef struct {
   EmpathyTpFileOperationCallback op_callback;
   gpointer op_user_data;
 
+  gboolean is_closing;
   gboolean is_closed;
 
   gboolean dispose_run;
@@ -240,15 +242,17 @@ splice_stream_ready_cb (GObject *source,
     gpointer user_data)
 {
   EmpathyTpFile *tp_file;
+  EmpathyTpFilePriv *priv;
   GError *error = NULL;
 
   tp_file = user_data;
+  priv = GET_PRIV (tp_file);
 
   g_output_stream_splice_finish (G_OUTPUT_STREAM (source), res, &error);
 
   DEBUG ("Splice stream ready cb, error %p", error);
 
-  if (error != NULL)
+  if (error != NULL && !priv->is_closing)
     {
       ft_operation_close_with_error (tp_file, error);
       g_clear_error (&error);
@@ -590,7 +594,7 @@ file_read_async_cb (GObject *source,
 
   in_stream = g_file_read_finish (G_FILE (source), res, &error);
 
-  if (error != NULL)
+  if (error != NULL && !priv->is_closing)
     {
       ft_operation_close_with_error (tp_file, error);
       g_clear_error (&error);
@@ -673,6 +677,8 @@ close_channel_internal (EmpathyTpFile *tp_file,
   DEBUG ("Closing channel, should cancel %s", cancel ?
          "True" : "False");
 
+  priv->is_closing = TRUE;
+
   tp_cli_channel_call_close (priv->channel, -1,
     channel_closed_cb, GINT_TO_POINTER (cancel), NULL, G_OBJECT (tp_file));
 }
@@ -770,9 +776,6 @@ do_set_property (GObject *object,
       case PROP_CHANNEL:
         priv->channel = g_object_ref (g_value_get_object (value));
         break;
-      case PROP_INCOMING:
-        priv->incoming = g_value_get_boolean (value);
-        break;
       default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
         break;
@@ -791,6 +794,8 @@ do_constructed (GObject *object)
   g_signal_connect (priv->channel, "invalidated",
     G_CALLBACK (tp_file_invalidated_cb), tp_file);
 
+  priv->incoming = !tp_channel_get_requested (priv->channel);
+
   tp_cli_channel_type_file_transfer_connect_to_file_transfer_state_changed (
       priv->channel, tp_file_state_changed_cb, NULL, NULL, object, NULL);
 
@@ -848,8 +853,7 @@ empathy_tp_file_class_init (EmpathyTpFileClass *klass)
           "direction of transfer",
           "The direction of the file being transferred",
           FALSE,
-          G_PARAM_READWRITE |
-          G_PARAM_CONSTRUCT_ONLY));
+          G_PARAM_READABLE));
 
   g_type_class_add_private (object_class, sizeof (EmpathyTpFilePriv));
 }
@@ -861,22 +865,21 @@ empathy_tp_file_class_init (EmpathyTpFileClass *klass)
  * @channel: a #TpChannel
  * @incoming: whether the file transfer is incoming or not
  *
- * Creates a new #EmpathyTpFile wrapping @channel, with the direction
- * specified by @incoming. The returned #EmpathyTpFile should be unrefed
+ * Creates a new #EmpathyTpFile wrapping @channel.
+ * The returned #EmpathyTpFile should be unrefed
  * with g_object_unref() when finished with.
  *
  * Return value: a new #EmpathyTpFile
  */
 EmpathyTpFile *
-empathy_tp_file_new (TpChannel *channel,
-    gboolean incoming)
+empathy_tp_file_new (TpChannel *channel)
 {
   EmpathyTpFile *tp_file;
 
   g_return_val_if_fail (TP_IS_CHANNEL (channel), NULL);
 
   tp_file = g_object_new (EMPATHY_TYPE_TP_FILE,
-      "channel", channel, "incoming", incoming,
+      "channel", channel,
       NULL);
 
   return tp_file;