]> git.0d.be Git - empathy.git/blobdiff - libempathy/empathy-ft-handler.c
individual-menu: remove link-contacts-activated signal
[empathy.git] / libempathy / empathy-ft-handler.c
index be40d5e01c76a38dfaa7aa5dab2cb89b5852042c..c701b193d9e5c6ef491d1296e69e6e5cc7a4cd4a 100644 (file)
 
 #include <glib.h>
 #include <glib/gi18n.h>
+#include <telepathy-glib/account-channel-request.h>
 #include <telepathy-glib/util.h>
+#include <telepathy-glib/dbus.h>
+#include <telepathy-glib/interfaces.h>
 
 #include "empathy-ft-handler.h"
 #include "empathy-tp-contact-factory.h"
-#include "empathy-dispatcher.h"
-#include "empathy-marshal.h"
 #include "empathy-time.h"
 #include "empathy-utils.h"
 
@@ -75,7 +76,7 @@ G_DEFINE_TYPE (EmpathyFTHandler, empathy_ft_handler, G_TYPE_OBJECT)
 #define BUFFER_SIZE 4096
 
 enum {
-  PROP_TP_FILE = 1,
+  PROP_CHANNEL = 1,
   PROP_G_FILE,
   PROP_CONTACT,
   PROP_CONTENT_TYPE,
@@ -84,7 +85,7 @@ enum {
   PROP_MODIFICATION_TIME,
   PROP_TOTAL_BYTES,
   PROP_TRANSFERRED_BYTES,
-  PROP_USE_HASH
+  PROP_USER_ACTION_TIME
 };
 
 enum {
@@ -119,12 +120,10 @@ typedef struct {
   gboolean dispose_run;
 
   GFile *gfile;
-  EmpathyTpFile *tpfile;
+  TpFileTransferChannel *channel;
   GCancellable *cancellable;
   gboolean use_hash;
 
-  EmpathyDispatcher *dispatcher;
-
   /* request for the new transfer */
   GHashTable *request;
 
@@ -139,10 +138,12 @@ typedef struct {
   gchar *content_hash;
   TpFileHashType content_hash_type;
 
+  gint64 user_action_time;
+
   /* time and speed */
   gdouble speed;
   guint remaining_time;
-  time_t last_update_time;
+  gint64 last_update_time;
 
   gboolean is_completed;
 } EmpathyFTHandlerPriv;
@@ -160,7 +161,7 @@ do_get_property (GObject *object,
     GParamSpec *pspec)
 {
   EmpathyFTHandlerPriv *priv = GET_PRIV (object);
-  
+
   switch (property_id)
     {
       case PROP_CONTACT:
@@ -187,11 +188,11 @@ do_get_property (GObject *object,
       case PROP_G_FILE:
         g_value_set_object (value, priv->gfile);
         break;
-      case PROP_TP_FILE:
-        g_value_set_object (value, priv->tpfile);
+      case PROP_CHANNEL:
+        g_value_set_object (value, priv->channel);
         break;
-      case PROP_USE_HASH:
-        g_value_set_boolean (value, priv->use_hash);
+      case PROP_USER_ACTION_TIME:
+        g_value_set_int64 (value, priv->user_action_time);
         break;
       default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -232,11 +233,11 @@ do_set_property (GObject *object,
       case PROP_G_FILE:
         priv->gfile = g_value_dup_object (value);
         break;
-      case PROP_TP_FILE:
-        priv->tpfile = g_value_dup_object (value);
+      case PROP_CHANNEL:
+        priv->channel = g_value_dup_object (value);
         break;
-      case PROP_USE_HASH:
-        priv->use_hash = g_value_get_boolean (value);
+      case PROP_USER_ACTION_TIME:
+        priv->user_action_time = g_value_get_int64 (value);
         break;
       default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -263,10 +264,10 @@ do_dispose (GObject *object)
     priv->gfile = NULL;
   }
 
-  if (priv->tpfile != NULL) {
-    empathy_tp_file_close (priv->tpfile);
-    g_object_unref (priv->tpfile);
-    priv->tpfile = NULL;
+  if (priv->channel != NULL) {
+    tp_channel_close_async (TP_CHANNEL (priv->channel), NULL, NULL);
+    g_object_unref (priv->channel);
+    priv->channel = NULL;
   }
 
   if (priv->cancellable != NULL) {
@@ -280,12 +281,6 @@ do_dispose (GObject *object)
       priv->request = NULL;
     }
 
-  if (priv->dispatcher != NULL)
-    {
-      g_object_unref (priv->dispatcher);
-      priv->dispatcher = NULL;
-    }
-
   G_OBJECT_CLASS (empathy_ft_handler_parent_class)->dispose (object);
 }
 
@@ -415,46 +410,43 @@ empathy_ft_handler_class_init (EmpathyFTHandlerClass *klass)
   g_object_class_install_property (object_class, PROP_G_FILE, param_spec);
 
   /**
-   * EmpathyFTHandler:tp-file:
+   * EmpathyFTHandler:channel:
    *
-   * The underlying #EmpathyTpFile managing the transfer
+   * The underlying #TpFileTransferChannel managing the transfer
    */
-  param_spec = g_param_spec_object ("tp-file",
-    "tp-file", "The file's channel wrapper",
-    EMPATHY_TYPE_TP_FILE,
+  param_spec = g_param_spec_object ("channel",
+    "channel", "The file transfer channel",
+    TP_TYPE_FILE_TRANSFER_CHANNEL,
     G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
-  g_object_class_install_property (object_class, PROP_TP_FILE, param_spec);
+  g_object_class_install_property (object_class, PROP_CHANNEL, param_spec);
 
-  /**
-   * EmpathyFTHandler:use-hash:
-   *
-   * %TRUE if checksumming is enabled for the handler, %FALSE otherwise
-   */
-  param_spec = g_param_spec_boolean ("use-hash",
-    "use-hash", "Whether we should use checksum when sending or receiving",
-    FALSE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
-  g_object_class_install_property (object_class, PROP_USE_HASH, param_spec);
+  param_spec = g_param_spec_int64 ("user-action-time", "user action time",
+    "User action time",
+    0, G_MAXINT64, 0,
+    G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
+  g_object_class_install_property (object_class, PROP_USER_ACTION_TIME,
+      param_spec);
 
   /* signals */
 
   /**
    * EmpathyFTHandler::transfer-started
    * @handler: the object which has received the signal
-   * @tp_file: the #EmpathyTpFile for which the transfer has started
+   * @channel: the #TpFileTransferChannel for which the transfer has started
    *
    * This signal is emitted when the actual transfer starts.
    */
   signals[TRANSFER_STARTED] =
     g_signal_new ("transfer-started", G_TYPE_FROM_CLASS (klass),
         G_SIGNAL_RUN_LAST, 0, NULL, NULL,
-        g_cclosure_marshal_VOID__OBJECT,
+        g_cclosure_marshal_generic,
         G_TYPE_NONE,
-        1, EMPATHY_TYPE_TP_FILE);
+        1, TP_TYPE_FILE_TRANSFER_CHANNEL);
 
   /**
    * EmpathyFTHandler::transfer-done
    * @handler: the object which has received the signal
-   * @tp_file: the #EmpathyTpFile for which the transfer has started
+   * @channel: the #TpFileTransferChannel for which the transfer has started
    *
    * This signal will be emitted when the actual transfer is completed
    * successfully.
@@ -462,9 +454,9 @@ empathy_ft_handler_class_init (EmpathyFTHandlerClass *klass)
   signals[TRANSFER_DONE] =
     g_signal_new ("transfer-done", G_TYPE_FROM_CLASS (klass),
         G_SIGNAL_RUN_LAST, 0, NULL, NULL,
-        g_cclosure_marshal_VOID__OBJECT,
+        g_cclosure_marshal_generic,
         G_TYPE_NONE,
-        1, EMPATHY_TYPE_TP_FILE);
+        1, TP_TYPE_FILE_TRANSFER_CHANNEL);
 
   /**
    * EmpathyFTHandler::transfer-error
@@ -480,7 +472,7 @@ empathy_ft_handler_class_init (EmpathyFTHandlerClass *klass)
   signals[TRANSFER_ERROR] =
     g_signal_new ("transfer-error", G_TYPE_FROM_CLASS (klass),
         G_SIGNAL_RUN_LAST, 0, NULL, NULL,
-        g_cclosure_marshal_VOID__POINTER,
+        g_cclosure_marshal_generic,
         G_TYPE_NONE,
         1, G_TYPE_POINTER);
 
@@ -499,7 +491,7 @@ empathy_ft_handler_class_init (EmpathyFTHandlerClass *klass)
   signals[TRANSFER_PROGRESS] =
     g_signal_new ("transfer-progress", G_TYPE_FROM_CLASS (klass),
         G_SIGNAL_RUN_LAST, 0, NULL, NULL,
-        _empathy_marshal_VOID__UINT64_UINT64_UINT_DOUBLE,
+        g_cclosure_marshal_generic,
         G_TYPE_NONE,
         4, G_TYPE_UINT64, G_TYPE_UINT64, G_TYPE_UINT, G_TYPE_DOUBLE);
 
@@ -508,17 +500,16 @@ empathy_ft_handler_class_init (EmpathyFTHandlerClass *klass)
    * @handler: the object which has received the signal
    *
    * This signal is emitted when the hashing operation of the handler
-   * is started. Note that this only happens if the handler is created
-   * with checksum enabled and, even if the option is set, is not
-   * guaranteed to happen for incoming handlers, as the CM might not
-   * support sending/receiving the file hash. You can use
-   * empathy_ft_handler_get_use_hash() to find out whether the handler really
-   * supports checksum.
+   * is started. Note that this might happen or not, depending on the CM
+   * and remote contact capabilities. Clients shoud use
+   * empathy_ft_handler_get_use_hash() before calling
+   * empathy_ft_handler_start_transfer() to know whether they should connect
+   * to this signal.
    */
   signals[HASHING_STARTED] =
     g_signal_new ("hashing-started", G_TYPE_FROM_CLASS (klass),
         G_SIGNAL_RUN_LAST, 0, NULL, NULL,
-        g_cclosure_marshal_VOID__VOID,
+        g_cclosure_marshal_generic,
         G_TYPE_NONE, 0);
 
   /**
@@ -533,7 +524,7 @@ empathy_ft_handler_class_init (EmpathyFTHandlerClass *klass)
   signals[HASHING_PROGRESS] =
     g_signal_new ("hashing-progress", G_TYPE_FROM_CLASS (klass),
         G_SIGNAL_RUN_LAST, 0, NULL, NULL,
-        _empathy_marshal_VOID__UINT64_UINT64,
+        g_cclosure_marshal_generic,
         G_TYPE_NONE,
         2, G_TYPE_UINT64, G_TYPE_UINT64);
 
@@ -547,7 +538,7 @@ empathy_ft_handler_class_init (EmpathyFTHandlerClass *klass)
   signals[HASHING_DONE] =
     g_signal_new ("hashing-done", G_TYPE_FROM_CLASS (klass),
         G_SIGNAL_RUN_LAST, 0, NULL, NULL,
-        g_cclosure_marshal_VOID__VOID,
+        g_cclosure_marshal_generic,
         G_TYPE_NONE, 0);
 }
 
@@ -559,7 +550,6 @@ empathy_ft_handler_init (EmpathyFTHandler *self)
 
   self->priv = priv;
   priv->cancellable = g_cancellable_new ();
-  priv->dispatcher = empathy_dispatcher_dup_singleton ();
 }
 
 /* private functions */
@@ -600,6 +590,7 @@ tp_file_hash_to_g_checksum (TpFileHashType type)
       case TP_FILE_HASH_TYPE_SHA256:
         retval = G_CHECKSUM_SHA256;
         break;
+      case TP_FILE_HASH_TYPE_NONE:
       default:
         g_assert_not_reached ();
         break;
@@ -635,46 +626,20 @@ emit_error_signal (EmpathyFTHandler *handler,
 {
   EmpathyFTHandlerPriv *priv = GET_PRIV (handler);
 
+  DEBUG ("Error in transfer: %s\n", error->message);
+
   if (!g_cancellable_is_cancelled (priv->cancellable))
     g_cancellable_cancel (priv->cancellable);
 
   g_signal_emit (handler, signals[TRANSFER_ERROR], 0, error);
 }
 
-static void
-ft_transfer_operation_callback (EmpathyTpFile *tp_file,
-    const GError *error,
-    gpointer user_data)
-{
-  EmpathyFTHandler *handler = user_data;
-  EmpathyFTHandlerPriv *priv = GET_PRIV (handler);
-
-  DEBUG ("Transfer operation callback, error %p", error);
-
-  if (error != NULL)
-    {
-      emit_error_signal (handler, error);
-    }
-  else
-    {
-      priv->is_completed = TRUE;
-      g_signal_emit (handler, signals[TRANSFER_DONE], 0, tp_file);
-
-      empathy_tp_file_close (tp_file);
-
-      if (empathy_ft_handler_is_incoming (handler) && priv->use_hash)
-        {
-          check_hash_incoming (handler);
-        }
-    }
-}
-
 static void
 update_remaining_time_and_speed (EmpathyFTHandler *handler,
     guint64 transferred_bytes)
 {
   EmpathyFTHandlerPriv *priv = GET_PRIV (handler);
-  time_t elapsed_time, current_time;
+  gint64 elapsed_time, current_time;
   guint64 transferred, last_transferred_bytes;
   gdouble speed;
   gint remaining_time;
@@ -697,127 +662,224 @@ update_remaining_time_and_speed (EmpathyFTHandler *handler,
 }
 
 static void
-ft_transfer_progress_callback (EmpathyTpFile *tp_file,
-    guint64 transferred_bytes,
-    gpointer user_data)
+ft_transfer_transferred_bytes_cb (TpFileTransferChannel *channel,
+    GParamSpec *pspec,
+    EmpathyFTHandler *handler)
 {
-  EmpathyFTHandler *handler = user_data;
   EmpathyFTHandlerPriv *priv = GET_PRIV (handler);
+  guint64 bytes;
 
   if (empathy_ft_handler_is_cancelled (handler))
     return;
 
-  if (transferred_bytes == 0)
+  bytes = tp_file_transfer_channel_get_transferred_bytes (channel);
+
+  if (priv->transferred_bytes == 0)
     {
       priv->last_update_time = empathy_time_get_current ();
-      g_signal_emit (handler, signals[TRANSFER_STARTED], 0, tp_file);
+      g_signal_emit (handler, signals[TRANSFER_STARTED], 0, channel);
     }
 
-  if (priv->transferred_bytes != transferred_bytes)
+  if (priv->transferred_bytes != bytes)
     {
-      update_remaining_time_and_speed (handler, transferred_bytes);
+      update_remaining_time_and_speed (handler, bytes);
 
       g_signal_emit (handler, signals[TRANSFER_PROGRESS], 0,
-          transferred_bytes, priv->total_bytes, priv->remaining_time,
+          bytes, priv->total_bytes, priv->remaining_time,
           priv->speed);
     }
 }
 
 static void
-ft_handler_create_channel_cb (EmpathyDispatchOperation *operation,
-    const GError *error,
+ft_transfer_provide_cb (GObject *source,
+    GAsyncResult *result,
     gpointer user_data)
 {
+  TpFileTransferChannel *channel = TP_FILE_TRANSFER_CHANNEL (source);
   EmpathyFTHandler *handler = user_data;
-  EmpathyFTHandlerPriv *priv = GET_PRIV (handler);
-  GError *my_error = (GError *) error;
+  GError *error = NULL;
 
-  DEBUG ("Dispatcher create channel CB");
+  if (!tp_file_transfer_channel_provide_file_finish (channel, result, &error))
+    {
+      emit_error_signal (handler, error);
+      g_clear_error (&error);
+    }
+}
 
-  if (my_error == NULL)
+static void
+ft_transfer_accept_cb (GObject *source,
+    GAsyncResult *result,
+    gpointer user_data)
+{
+  TpFileTransferChannel *channel = TP_FILE_TRANSFER_CHANNEL (source);
+  EmpathyFTHandler *handler = user_data;
+  GError *error = NULL;
+
+  if (!tp_file_transfer_channel_accept_file_finish (channel, result, &error))
     {
-      g_cancellable_set_error_if_cancelled (priv->cancellable, &my_error);
+      emit_error_signal (handler, error);
+      g_clear_error (&error);
     }
+}
 
-  if (my_error != NULL)
+static GError *
+error_from_state_change_reason (TpFileTransferStateChangeReason reason)
+{
+  const char *string;
+  GError *retval = NULL;
+
+  string = NULL;
+
+  switch (reason)
     {
-      emit_error_signal (handler, my_error);
+      case TP_FILE_TRANSFER_STATE_CHANGE_REASON_NONE:
+        string = _("No reason was specified");
+        break;
+      case TP_FILE_TRANSFER_STATE_CHANGE_REASON_REQUESTED:
+        string = _("The change in state was requested");
+        break;
+      case TP_FILE_TRANSFER_STATE_CHANGE_REASON_LOCAL_STOPPED:
+        string = _("You canceled the file transfer");
+        break;
+      case TP_FILE_TRANSFER_STATE_CHANGE_REASON_REMOTE_STOPPED:
+        string = _("The other participant canceled the file transfer");
+        break;
+      case TP_FILE_TRANSFER_STATE_CHANGE_REASON_LOCAL_ERROR:
+        string = _("Error while trying to transfer the file");
+        break;
+      case TP_FILE_TRANSFER_STATE_CHANGE_REASON_REMOTE_ERROR:
+        string = _("The other participant is unable to transfer the file");
+        break;
+      default:
+        string = _("Unknown reason");
+        break;
+    }
+
+  retval = g_error_new_literal (EMPATHY_FT_ERROR_QUARK,
+      EMPATHY_FT_ERROR_TP_ERROR, string);
+
+  return retval;
+}
+
+static void
+ft_transfer_state_cb (TpFileTransferChannel *channel,
+    GParamSpec *pspec,
+    EmpathyFTHandler *handler)
+{
+  EmpathyFTHandlerPriv *priv = GET_PRIV (handler);
+  TpFileTransferStateChangeReason reason;
+  TpFileTransferState state = tp_file_transfer_channel_get_state (
+      channel, &reason);
+
+  if (state == TP_FILE_TRANSFER_STATE_COMPLETED)
+    {
+      priv->is_completed = TRUE;
+      g_signal_emit (handler, signals[TRANSFER_DONE], 0, channel);
+
+      tp_channel_close_async (TP_CHANNEL (channel), NULL, NULL);
+
+      if (empathy_ft_handler_is_incoming (handler) && priv->use_hash)
+        {
+          check_hash_incoming (handler);
+        }
+    }
+  else if (state == TP_FILE_TRANSFER_STATE_CANCELLED)
+    {
+      GError *error = error_from_state_change_reason (reason);
+      emit_error_signal (handler, error);
+      g_clear_error (&error);
+    }
+}
+
+static void
+ft_handler_create_channel_cb (GObject *source,
+    GAsyncResult *result,
+    gpointer user_data)
+{
+  EmpathyFTHandler *handler = user_data;
+  EmpathyFTHandlerPriv *priv = GET_PRIV (handler);
+  GError *error = NULL;
+  TpChannel *channel;
 
-      if (my_error != error)
-        g_clear_error (&my_error);
+  DEBUG ("Dispatcher create channel CB");
+
+  channel = tp_account_channel_request_create_and_handle_channel_finish (
+        TP_ACCOUNT_CHANNEL_REQUEST (source), result, NULL, &error);
+
+  if (channel == NULL)
+    DEBUG ("Failed to request FT channel: %s", error->message);
+  else
+    g_cancellable_set_error_if_cancelled (priv->cancellable, &error);
 
+  if (error != NULL)
+    {
+      emit_error_signal (handler, error);
+
+      g_clear_object (&channel);
+      g_error_free (error);
       return;
     }
 
-  priv->tpfile = g_object_ref
-      (empathy_dispatch_operation_get_channel_wrapper (operation));
+  priv->channel = TP_FILE_TRANSFER_CHANNEL (channel);
 
-  empathy_tp_file_offer (priv->tpfile, priv->gfile, priv->cancellable,
-      ft_transfer_progress_callback, handler,
-      ft_transfer_operation_callback, handler);
+  tp_g_signal_connect_object (priv->channel, "notify::state",
+      G_CALLBACK (ft_transfer_state_cb), handler, 0);
+  tp_g_signal_connect_object (priv->channel, "notify::transferred-bytes",
+      G_CALLBACK (ft_transfer_transferred_bytes_cb), handler, 0);
 
-  empathy_dispatch_operation_claim (operation);
+  tp_file_transfer_channel_provide_file_async (priv->channel, priv->gfile,
+      ft_transfer_provide_cb, handler);
 }
 
 static void
 ft_handler_push_to_dispatcher (EmpathyFTHandler *handler)
 {
-  TpConnection *connection;
+  TpAccount *account;
   EmpathyFTHandlerPriv *priv = GET_PRIV (handler);
+  TpAccountChannelRequest *req;
 
   DEBUG ("Pushing request to the dispatcher");
 
-  connection = empathy_contact_get_connection (priv->contact);
+  account = empathy_contact_get_account (priv->contact);
+
+  req = tp_account_channel_request_new (account, priv->request,
+      priv->user_action_time);
 
-  /* I want to own a reference to the request, and destroy it later */
-  empathy_dispatcher_create_channel (priv->dispatcher, connection,
-      g_hash_table_ref (priv->request), ft_handler_create_channel_cb, handler);
+  tp_account_channel_request_create_and_handle_channel_async (req, NULL,
+      ft_handler_create_channel_cb, handler);
+
+  g_object_unref (req);
 }
 
 static void
 ft_handler_populate_outgoing_request (EmpathyFTHandler *handler)
 {
   guint contact_handle;
-  GHashTable *request;
-  GValue *value;
   EmpathyFTHandlerPriv *priv = GET_PRIV (handler);
-
-  request = priv->request = g_hash_table_new_full (g_str_hash, g_str_equal,
-           NULL, (GDestroyNotify) tp_g_value_slice_free);
+  gchar *uri;
 
   contact_handle = empathy_contact_get_handle (priv->contact);
-
-  /* org.freedesktop.Telepathy.Channel.ChannelType */
-  value = tp_g_value_slice_new_string (TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER);
-  g_hash_table_insert (request, TP_IFACE_CHANNEL ".ChannelType", value);
-
-  /* org.freedesktop.Telepathy.Channel.TargetHandleType */
-  value = tp_g_value_slice_new_uint (TP_HANDLE_TYPE_CONTACT);
-  g_hash_table_insert (request, TP_IFACE_CHANNEL ".TargetHandleType", value);
-
-  /* org.freedesktop.Telepathy.Channel.TargetHandle */
-  value = tp_g_value_slice_new_uint (contact_handle);
-  g_hash_table_insert (request, TP_IFACE_CHANNEL ".TargetHandle", value);
-
-  /* org.freedesktop.Telepathy.Channel.Type.FileTransfer.ContentType */
-  value = tp_g_value_slice_new_string (priv->content_type);
-  g_hash_table_insert (request,
-      TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER ".ContentType", value);
-
-  /* org.freedesktop.Telepathy.Channel.Type.FileTransfer.Filename */
-  value = tp_g_value_slice_new_string (priv->filename);
-  g_hash_table_insert (request,
-      TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER ".Filename", value);
-
-  /* org.freedesktop.Telepathy.Channel.Type.FileTransfer.Size */
-  value = tp_g_value_slice_new_uint64 (priv->total_bytes);
-  g_hash_table_insert (request,
-      TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER ".Size", value);
-
-  /* org.freedesktop.Telepathy.Channel.Type.FileTransfer.Date */
-  value = tp_g_value_slice_new_uint64 ((guint64) priv->mtime);
-  g_hash_table_insert (request,
-      TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER ".Date", value);
+  uri = g_file_get_uri (priv->gfile);
+
+  priv->request = tp_asv_new (
+      TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING,
+        TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER,
+      TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, G_TYPE_UINT,
+        TP_HANDLE_TYPE_CONTACT,
+      TP_PROP_CHANNEL_TARGET_HANDLE, G_TYPE_UINT,
+        contact_handle,
+      TP_PROP_CHANNEL_TYPE_FILE_TRANSFER_CONTENT_TYPE, G_TYPE_STRING,
+        priv->content_type,
+      TP_PROP_CHANNEL_TYPE_FILE_TRANSFER_FILENAME, G_TYPE_STRING,
+        priv->filename,
+      TP_PROP_CHANNEL_TYPE_FILE_TRANSFER_SIZE, G_TYPE_UINT64,
+        priv->total_bytes,
+      TP_PROP_CHANNEL_TYPE_FILE_TRANSFER_DATE, G_TYPE_UINT64,
+        priv->mtime,
+      TP_PROP_CHANNEL_TYPE_FILE_TRANSFER_URI, G_TYPE_STRING, uri,
+      NULL);
+
+  g_free (uri);
 }
 
 static gboolean
@@ -827,7 +889,6 @@ hash_job_done (gpointer user_data)
   EmpathyFTHandler *handler = hash_data->handler;
   EmpathyFTHandlerPriv *priv;
   GError *error = NULL;
-  GValue *value;
 
   DEBUG ("Closing stream after hashing.");
 
@@ -836,6 +897,7 @@ hash_job_done (gpointer user_data)
   if (hash_data->error != NULL)
     {
       error = hash_data->error;
+      hash_data->error = NULL;
       goto cleanup;
     }
 
@@ -852,8 +914,7 @@ hash_job_done (gpointer user_data)
 
           error = g_error_new_literal (EMPATHY_FT_ERROR_QUARK,
               EMPATHY_FT_ERROR_HASH_MISMATCH,
-              _("The hash of the received file and the "
-                "sent one do not match"));
+              _("File transfer completed, but the file was corrupted"));
           goto cleanup;
         }
       else
@@ -868,10 +929,9 @@ hash_job_done (gpointer user_data)
       /* set the checksum in the request...
        * org.freedesktop.Telepathy.Channel.Type.FileTransfer.ContentHash
        */
-      value = tp_g_value_slice_new_string
-          (g_checksum_get_string (hash_data->checksum));
-      g_hash_table_insert (priv->request,
-          TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER ".ContentHash", value);
+      tp_asv_set_string (priv->request,
+          TP_PROP_CHANNEL_TYPE_FILE_TRANSFER_CONTENT_HASH,
+          g_checksum_get_string (hash_data->checksum));
     }
 
 cleanup:
@@ -913,11 +973,8 @@ do_hash_job (GIOSchedulerJob *job,
 {
   HashingData *hash_data = user_data;
   gssize bytes_read;
-  EmpathyFTHandlerPriv *priv;
   GError *error = NULL;
 
-  priv = GET_PRIV (hash_data->handler);
-
 again:
   if (hash_data->buffer == NULL)
     hash_data->buffer = g_malloc0 (BUFFER_SIZE);
@@ -991,7 +1048,6 @@ ft_handler_read_async_cb (GObject *source,
   GFileInputStream *stream;
   GError *error = NULL;
   HashingData *hash_data;
-  GValue *value;
   EmpathyFTHandler *handler = user_data;
   EmpathyFTHandlerPriv *priv = GET_PRIV (handler);
 
@@ -1013,10 +1069,9 @@ ft_handler_read_async_cb (GObject *source,
   /* FIXME: MD5 is the only ContentHashType supported right now */
   hash_data->checksum = g_checksum_new (G_CHECKSUM_MD5);
 
-  /* org.freedesktop.Telepathy.Channel.Type.FileTransfer.ContentHashType */
-  value = tp_g_value_slice_new_uint (TP_FILE_HASH_TYPE_MD5);
-  g_hash_table_insert (priv->request,
-      TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER ".ContentHashType", value);
+  tp_asv_set_uint32 (priv->request,
+      TP_PROP_CHANNEL_TYPE_FILE_TRANSFER_CONTENT_HASH_TYPE,
+      TP_FILE_HASH_TYPE_MD5);
 
   g_signal_emit (handler, signals[HASHING_STARTED], 0);
 
@@ -1035,72 +1090,132 @@ callbacks_data_free (gpointer user_data)
   g_slice_free (CallbacksData, data);
 }
 
-static void
-find_ft_channel_class_cb (GStrv channel_class,
-    gpointer user_data)
+static gboolean
+set_content_hash_type_from_classes (EmpathyFTHandler *handler,
+    GPtrArray *classes)
 {
-  CallbacksData *data = user_data;
-  EmpathyFTHandler *handler = data->handler;  
-  gboolean allowed = TRUE;
-  GError *myerr = NULL;
+  GArray *possible_values;
+  guint value;
+  gboolean valid;
+  EmpathyFTHandlerPriv *priv = GET_PRIV (handler);
+  gboolean support_ft = FALSE;
+  guint i;
+
+  possible_values = g_array_new (TRUE, TRUE, sizeof (guint));
+
+  for (i = 0; i < classes->len; i++)
+    {
+      GHashTable *fixed;
+      GStrv allowed;
+      const gchar *chan_type;
 
-  /* this takes care of channel_class == NULL as well */
-  if (!tp_strv_contains ((const gchar * const *) channel_class,
-      TP_IFACE_CHANNEL ".TargetHandle"))
-    allowed = FALSE;
+      tp_value_array_unpack (g_ptr_array_index (classes, i), 2,
+          &fixed, &allowed);
 
-  DEBUG ("check if FT is allowed: %s", allowed ? "True" : "False");
+      chan_type = tp_asv_get_string (fixed, TP_PROP_CHANNEL_CHANNEL_TYPE);
 
-  if (!allowed)
+      if (tp_strdiff (chan_type, TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER))
+        continue;
+
+      if (tp_asv_get_uint32 (fixed, TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, NULL) !=
+          TP_HANDLE_TYPE_CONTACT)
+        continue;
+
+      support_ft = TRUE;
+
+      value = tp_asv_get_uint32
+        (fixed, TP_PROP_CHANNEL_TYPE_FILE_TRANSFER_CONTENT_HASH_TYPE,
+         &valid);
+
+      if (valid)
+        g_array_append_val (possible_values, value);
+    }
+
+  if (!support_ft)
     {
-      g_set_error_literal (&myerr, EMPATHY_FT_ERROR_QUARK,
-          EMPATHY_FT_ERROR_NOT_SUPPORTED,
-          _("File transfer not supported by remote contact"));
+      g_array_unref (possible_values);
+      return FALSE;
+    }
 
-      data->callback (NULL, myerr, data->user_data);
-      g_clear_error (&myerr);
+  if (possible_values->len == 0)
+    {
+      /* there are no channel classes with hash support, disable it. */
+      priv->use_hash = FALSE;
+      priv->content_hash_type = TP_FILE_HASH_TYPE_NONE;
+
+      goto out;
+    }
+
+  priv->use_hash = TRUE;
+
+  if (possible_values->len == 1)
+    {
+      priv->content_hash_type = g_array_index (possible_values, guint, 0);
     }
   else
     {
-      data->callback (handler, NULL, data->user_data);
+      /* order the array and pick the first non zero, so that MD5
+       * is the preferred value.
+       */
+      g_array_sort (possible_values, empathy_uint_compare);
+
+      if (g_array_index (possible_values, guint, 0) == 0)
+        priv->content_hash_type = g_array_index (possible_values, guint, 1);
+      else
+        priv->content_hash_type = g_array_index (possible_values, guint, 0);
     }
 
-  callbacks_data_free (data);
+out:
+  g_array_unref (possible_values);
+
+  DEBUG ("Hash enabled %s; setting content hash type as %u",
+         priv->use_hash ? "True" : "False", priv->content_hash_type);
+
+  return TRUE;
 }
 
 static void
-find_hash_channel_class_cb (GStrv channel_class,
-    gpointer user_data)
+check_hashing (CallbacksData *data)
 {
-  CallbacksData *data = user_data;
   EmpathyFTHandler *handler = data->handler;
-  EmpathyFTHandlerPriv *priv = GET_PRIV (handler);  
-  gboolean allowed = TRUE;
+  EmpathyFTHandlerPriv *priv = GET_PRIV (handler);
+  GError *myerr = NULL;
+  TpCapabilities *caps;
+  GPtrArray *classes;
+  TpConnection *conn;
 
-  /* this takes care of channel_class == NULL as well */
-  if (!tp_strv_contains ((const gchar * const *) channel_class,
-      TP_IFACE_CHANNEL ".TargetHandle"))
-    allowed = FALSE;
+  conn = empathy_contact_get_connection (priv->contact);
 
-  DEBUG ("check if FT+hash is allowed: %s", allowed ? "True" : "False");
+  caps = tp_connection_get_capabilities (conn);
+  if (caps == NULL)
+    {
+      data->callback (handler, NULL, data->user_data);
+      goto out;
+    }
+
+  classes = tp_capabilities_get_channel_classes (caps);
 
-  if (!allowed)
+  /* set whether we support hash and the type of it */
+  if (!set_content_hash_type_from_classes (handler, classes))
     {
-      priv->use_hash = FALSE;
+      g_set_error_literal (&myerr, EMPATHY_FT_ERROR_QUARK,
+          EMPATHY_FT_ERROR_NOT_SUPPORTED,
+          _("File transfer not supported by remote contact"));
 
-      /* see if we support FT without hash instead */
-      empathy_dispatcher_find_requestable_channel_classes_async
-          (priv->dispatcher, empathy_contact_get_connection (priv->contact),
-           TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER, TP_HANDLE_TYPE_CONTACT,
-           find_ft_channel_class_cb, data, NULL);
+      if (!g_cancellable_is_cancelled (priv->cancellable))
+        g_cancellable_cancel (priv->cancellable);
 
-      return;
+      data->callback (handler, myerr, data->user_data);
+      g_clear_error (&myerr);
     }
   else
     {
+      /* get back to the caller now */
       data->callback (handler, NULL, data->user_data);
-      callbacks_data_free (data);
     }
+
+out:
+  callbacks_data_free (data);
 }
 
 static void
@@ -1137,9 +1252,25 @@ ft_handler_gfile_ready_cb (GObject *source,
   if (error != NULL)
     goto out;
 
+  if (g_file_info_get_file_type (info) != G_FILE_TYPE_REGULAR)
+    {
+      error = g_error_new_literal (EMPATHY_FT_ERROR_QUARK,
+          EMPATHY_FT_ERROR_INVALID_SOURCE_FILE,
+          _("The selected file is not a regular file"));
+      goto out;
+    }
+
+  priv->total_bytes = g_file_info_get_size (info);
+  if (priv->total_bytes == 0)
+    {
+      error = g_error_new_literal (EMPATHY_FT_ERROR_QUARK,
+          EMPATHY_FT_ERROR_EMPTY_SOURCE_FILE,
+          _("The selected file is empty"));
+      goto out;
+    }
+
   priv->content_type = g_strdup (g_file_info_get_content_type (info));
   priv->filename = g_strdup (g_file_info_get_display_name (info));
-  priv->total_bytes = g_file_info_get_size (info);
   g_file_info_get_modification_time (info, &mtime);
   priv->mtime = mtime.tv_sec;
   priv->transferred_bytes = 0;
@@ -1153,24 +1284,20 @@ out:
       if (!g_cancellable_is_cancelled (priv->cancellable))
         g_cancellable_cancel (priv->cancellable);
 
-      cb_data->callback (NULL, error, cb_data->user_data);
+      cb_data->callback (cb_data->handler, error, cb_data->user_data);
       g_error_free (error);
-      g_object_unref (cb_data->handler);
 
       callbacks_data_free (cb_data);
     }
   else
     {
       /* see if FT/hashing are allowed */
-      empathy_dispatcher_find_requestable_channel_classes_async
-          (priv->dispatcher, empathy_contact_get_connection (priv->contact),
-           TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER, TP_HANDLE_TYPE_CONTACT,
-           find_hash_channel_class_cb, cb_data, "ContentHashType", NULL);
+      check_hashing (cb_data);
     }
 }
 
 static void
-contact_factory_contact_cb (EmpathyTpContactFactory *factory,
+contact_factory_contact_cb (TpConnection *connection,
     EmpathyContact *contact,
     const GError *error,
     gpointer user_data,
@@ -1185,12 +1312,12 @@ contact_factory_contact_cb (EmpathyTpContactFactory *factory,
       if (!g_cancellable_is_cancelled (priv->cancellable))
         g_cancellable_cancel (priv->cancellable);
 
-      cb_data->callback (NULL, (GError *) error, cb_data->user_data);
-      g_object_unref (handler);
+      cb_data->callback (handler, (GError *) error, cb_data->user_data);
+      callbacks_data_free (cb_data);
       return;
     }
 
-  priv->contact = contact;
+  priv->contact = g_object_ref (contact);
 
   cb_data->callback (handler, NULL, cb_data->user_data);
 }
@@ -1205,7 +1332,6 @@ channel_get_all_properties_cb (TpProxy *proxy,
   CallbacksData *cb_data = user_data;
   EmpathyFTHandler *handler = EMPATHY_FT_HANDLER (weak_object);
   EmpathyFTHandlerPriv *priv = GET_PRIV (handler);
-  EmpathyTpContactFactory *c_factory;
   TpHandle c_handle;
 
   if (error != NULL)
@@ -1213,40 +1339,23 @@ channel_get_all_properties_cb (TpProxy *proxy,
       if (!g_cancellable_is_cancelled (priv->cancellable))
         g_cancellable_cancel (priv->cancellable);
 
-      cb_data->callback (NULL, (GError *) error, cb_data->user_data);
-      g_object_unref (handler);
+      cb_data->callback (handler, (GError *) error, cb_data->user_data);
+
+      callbacks_data_free (cb_data);
       return;
     }
 
-  priv->total_bytes = g_value_get_uint64 (
-      g_hash_table_lookup (properties, "Size"));
-
-  priv->transferred_bytes = g_value_get_uint64 (
-      g_hash_table_lookup (properties, "TransferredBytes"));
-
-  priv->filename = g_value_dup_string (
-      g_hash_table_lookup (properties, "Filename"));
-
   priv->content_hash = g_value_dup_string (
       g_hash_table_lookup (properties, "ContentHash"));
 
   priv->content_hash_type = g_value_get_uint (
       g_hash_table_lookup (properties, "ContentHashType"));
 
-  priv->content_type = g_value_dup_string (
-      g_hash_table_lookup (properties, "ContentType"));
-
-  priv->description = g_value_dup_string (
-      g_hash_table_lookup (properties, "Description"));
-
-  c_factory = empathy_tp_contact_factory_dup_singleton
-      (tp_channel_borrow_connection (TP_CHANNEL (proxy)));
   c_handle = tp_channel_get_handle (TP_CHANNEL (proxy), NULL);
-  empathy_tp_contact_factory_get_from_handle (c_factory, c_handle,
+  empathy_tp_contact_factory_get_from_handle (
+      tp_channel_borrow_connection (TP_CHANNEL (proxy)), c_handle,
       contact_factory_contact_cb, cb_data, callbacks_data_free,
       G_OBJECT (handler));
-
-  g_object_unref (c_factory);
 }
 
 /* public methods */
@@ -1255,7 +1364,6 @@ channel_get_all_properties_cb (TpProxy *proxy,
  * empathy_ft_handler_new_outgoing:
  * @contact: the #EmpathyContact to send @source to
  * @source: the #GFile to send
- * @use_hash: whether the handler should send a checksum of the file
  * @callback: callback to be called when the handler has been created
  * @user_data: user data to be passed to @callback
  *
@@ -1264,7 +1372,7 @@ channel_get_all_properties_cb (TpProxy *proxy,
 void
 empathy_ft_handler_new_outgoing (EmpathyContact *contact,
     GFile *source,
-    gboolean use_hash,
+    gint64 action_time,
     EmpathyFTHandlerReadyCallback callback,
     gpointer user_data)
 {
@@ -1272,14 +1380,16 @@ empathy_ft_handler_new_outgoing (EmpathyContact *contact,
   CallbacksData *data;
   EmpathyFTHandlerPriv *priv;
 
-  DEBUG ("New handler outgoing, use hash %s",
-         use_hash ? "True" : "False");
+  DEBUG ("New handler outgoing");
 
   g_return_if_fail (EMPATHY_IS_CONTACT (contact));
   g_return_if_fail (G_IS_FILE (source));
 
   handler = g_object_new (EMPATHY_TYPE_FT_HANDLER,
-      "contact", contact, "gfile", source, "use-hash", use_hash, NULL);
+      "contact", contact,
+      "gfile", source,
+      "user-action-time", action_time,
+      NULL);
 
   priv = GET_PRIV (handler);
 
@@ -1293,6 +1403,7 @@ empathy_ft_handler_new_outgoing (EmpathyContact *contact,
       G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME ","
       G_FILE_ATTRIBUTE_STANDARD_SIZE ","
       G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE ","
+      G_FILE_ATTRIBUTE_STANDARD_TYPE ","
       G_FILE_ATTRIBUTE_TIME_MODIFIED,
       G_FILE_QUERY_INFO_NONE, G_PRIORITY_DEFAULT,
       NULL, (GAsyncReadyCallback) ft_handler_gfile_ready_cb, data);
@@ -1300,7 +1411,7 @@ empathy_ft_handler_new_outgoing (EmpathyContact *contact,
 
 /**
  * empathy_ft_handler_new_incoming:
- * @tp_file: the #EmpathyTpFile wrapping the incoming channel
+ * @channel: the #TpFileTransferChannel proxy to the incoming channel
  * @callback: callback to be called when the handler has been created
  * @user_data: user data to be passed to @callback
  *
@@ -1310,26 +1421,39 @@ empathy_ft_handler_new_outgoing (EmpathyContact *contact,
  * is ready.
  */
 void
-empathy_ft_handler_new_incoming (EmpathyTpFile *tp_file,
+empathy_ft_handler_new_incoming (TpFileTransferChannel *channel,
     EmpathyFTHandlerReadyCallback callback,
     gpointer user_data)
 {
   EmpathyFTHandler *handler;
-  TpChannel *channel;
   CallbacksData *data;
+  EmpathyFTHandlerPriv *priv;
 
-  g_return_if_fail (EMPATHY_IS_TP_FILE (tp_file));
+  g_return_if_fail (TP_IS_FILE_TRANSFER_CHANNEL (channel));
 
   handler = g_object_new (EMPATHY_TYPE_FT_HANDLER,
-      "tp-file", tp_file, NULL);
+      "channel", channel, NULL);
 
-  g_object_get (tp_file, "channel", &channel, NULL);
+  priv = GET_PRIV (handler);
 
   data = g_slice_new0 (CallbacksData);
   data->callback = callback;
   data->user_data = user_data;
   data->handler = g_object_ref (handler);
 
+  priv->total_bytes = tp_file_transfer_channel_get_size (channel);
+
+  priv->transferred_bytes = tp_file_transfer_channel_get_transferred_bytes (
+      channel);
+
+  priv->filename = g_strdup (tp_file_transfer_channel_get_filename (channel));
+
+  priv->content_type = g_strdup (tp_file_transfer_channel_get_mime_type (
+      channel));
+
+  priv->description = g_strdup (tp_file_transfer_channel_get_description (
+      channel));
+
   tp_cli_dbus_properties_call_get_all (channel,
       -1, TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER,
       channel_get_all_properties_cb, data, NULL, G_OBJECT (handler));
@@ -1351,16 +1475,20 @@ empathy_ft_handler_start_transfer (EmpathyFTHandler *handler)
 
   priv = GET_PRIV (handler);
 
-  if (priv->tpfile == NULL)
+  if (priv->channel == NULL)
     {
       ft_handler_complete_request (handler);
     }
   else
     {
       /* TODO: add support for resume. */
-      empathy_tp_file_accept (priv->tpfile, 0, priv->gfile, priv->cancellable,
-          ft_transfer_progress_callback, handler,
-          ft_transfer_operation_callback, handler);
+      tp_file_transfer_channel_accept_file_async (priv->channel,
+          priv->gfile, 0, ft_transfer_accept_cb, handler);
+
+      tp_g_signal_connect_object (priv->channel, "notify::state",
+          G_CALLBACK (ft_transfer_state_cb), handler, 0);
+      tp_g_signal_connect_object (priv->channel, "notify::transferred-bytes",
+          G_CALLBACK (ft_transfer_transferred_bytes_cb), handler, 0);
     }
 }
 
@@ -1381,21 +1509,19 @@ empathy_ft_handler_cancel_transfer (EmpathyFTHandler *handler)
 
   priv = GET_PRIV (handler);
 
-  /* if we don't have an EmpathyTpFile, we are hashing, so
+  /* if we don't have a channel, we are hashing, so
    * we can just cancel the GCancellable to stop it.
    */
-  if (priv->tpfile == NULL)
+  if (priv->channel == NULL)
     g_cancellable_cancel (priv->cancellable);
   else
-    empathy_tp_file_cancel (priv->tpfile);
+    tp_channel_close_async (TP_CHANNEL (priv->channel), NULL, NULL);
 }
 
 /**
  * empathy_ft_handler_incoming_set_destination:
  * @handler: an #EmpathyFTHandler
  * @destination: the #GFile where the transfer should be saved
- * @use_hash: whether the handler should, after the transfer, try to
- * validate it with checksum.
  *
  * Sets the destination of the incoming handler to be @destination.
  * Note that calling this method is mandatory before starting the transfer
@@ -1403,28 +1529,25 @@ empathy_ft_handler_cancel_transfer (EmpathyFTHandler *handler)
  */
 void
 empathy_ft_handler_incoming_set_destination (EmpathyFTHandler *handler,
-    GFile *destination,
-    gboolean use_hash)
+    GFile *destination)
 {
   EmpathyFTHandlerPriv *priv;
 
-  DEBUG ("Set incoming destination, use hash %s",
-         use_hash ? "True" : "False");
-
   g_return_if_fail (EMPATHY_IS_FT_HANDLER (handler));
   g_return_if_fail (G_IS_FILE (destination));
 
   priv = GET_PRIV (handler);
 
-  g_object_set (handler, "gfile", destination,
-      "use-hash", use_hash, NULL);
+  g_object_set (handler, "gfile", destination, NULL);
 
-  /* check if hash is really supported. if it isn't, set use_hash to FALSE
+  /* check if hash is supported. if it isn't, set use_hash to FALSE
    * anyway, so that clients won't be expecting us to checksum.
    */
   if (EMP_STR_EMPTY (priv->content_hash) ||
       priv->content_hash_type == TP_FILE_HASH_TYPE_NONE)
     priv->use_hash = FALSE;
+  else
+    priv->use_hash = TRUE;
 }
 
 /**
@@ -1511,9 +1634,8 @@ empathy_ft_handler_get_gfile (EmpathyFTHandler *handler)
  * empathy_ft_handler_get_use_hash:
  * @handler: an #EmpathyFTHandler
  *
- * Returns whether @handler has checksumming enabled. Note that if the CM
- * doesn't support sending/receiving the checksum, this can return %FALSE even
- * if the handler was created with the use_hash parameter set to %TRUE.
+ * Returns whether @handler has checksumming enabled. This can depend on
+ * the CM and the remote contact capabilities.
  *
  * Return value: %TRUE if the handler has checksumming enabled,
  * %FALSE otherwise.
@@ -1547,10 +1669,10 @@ empathy_ft_handler_is_incoming (EmpathyFTHandler *handler)
 
   priv = GET_PRIV (handler);
 
-  if (priv->tpfile == NULL)
+  if (priv->channel == NULL)
     return FALSE;
 
-  return empathy_tp_file_is_incoming (priv->tpfile);
+  return !tp_channel_get_requested ((TpChannel *) priv->channel);
 }
 
 /**