]> git.0d.be Git - empathy.git/blobdiff - src/empathy-ft-manager.c
Updated Swedish translation
[empathy.git] / src / empathy-ft-manager.c
index 5424e057b379c7c39a502322aa56592fc29f6de9..4321969d661b011115a01c45b5a69d0b5e0d858c 100644 (file)
 /* The original file transfer manager code was copied from Epiphany */
 
 #include "config.h"
-
-#include <string.h>
+#include "empathy-ft-manager.h"
 
 #include <glib/gi18n.h>
-#include <gtk/gtk.h>
+#include <tp-account-widgets/tpaw-builder.h>
 
-#define DEBUG_FLAG EMPATHY_DEBUG_FT
-#include <libempathy/empathy-debug.h>
-#include <libempathy/empathy-tp-file.h>
-#include <libempathy/empathy-utils.h>
+#include "empathy-geometry.h"
+#include "empathy-ui-utils.h"
+#include "empathy-utils.h"
 
-#include <libempathy-gtk/empathy-conf.h>
-#include <libempathy-gtk/empathy-ui-utils.h>
-#include <libempathy-gtk/empathy-geometry.h>
-#include <libempathy-gtk/empathy-images.h>
-
-#include "empathy-ft-manager.h"
-
-
-/**
- * SECTION:empathy-ft-manager
- * @short_description: File transfer dialog
- * @see_also: #EmpathyTpFile, empathy_dispatcher_send_file()
- * @include: libempthy-gtk/empathy-ft-manager.h
- *
- * The #EmpathyFTManager object represents the file transfer dialog,
- * it can show multiple file transfers at the same time (added
- * with empathy_ft_manager_add_tp_file()).
- */
+#define DEBUG_FLAG EMPATHY_DEBUG_FT
+#include "empathy-debug.h"
 
 enum
 {
@@ -67,11 +49,6 @@ enum
   COL_FT_OBJECT
 };
 
-/**
- * EmpathyFTManagerPriv:
- *
- * Private fields of the #EmpathyFTManager class.
- */
 typedef struct {
   GtkTreeModel *model;
   GHashTable *ft_handler_to_row_ref;
@@ -81,15 +58,15 @@ typedef struct {
   GtkWidget *treeview;
   GtkWidget *open_button;
   GtkWidget *abort_button;
-
-  guint save_geometry_id;
+  GtkWidget *clear_button;
 } EmpathyFTManagerPriv;
 
 enum
 {
   RESPONSE_OPEN  = 1,
   RESPONSE_STOP  = 2,
-  RESPONSE_CLEAR = 3
+  RESPONSE_CLEAR = 3,
+  RESPONSE_CLOSE = 4
 };
 
 G_DEFINE_TYPE (EmpathyFTManager, empathy_ft_manager, G_TYPE_OBJECT);
@@ -98,9 +75,11 @@ G_DEFINE_TYPE (EmpathyFTManager, empathy_ft_manager, G_TYPE_OBJECT);
 
 static EmpathyFTManager *manager_singleton = NULL;
 
-#if 0
+static void ft_handler_hashing_started_cb (EmpathyFTHandler *handler,
+    EmpathyFTManager *manager);
+
 static gchar *
-ft_manager_format_interval (gint interval)
+ft_manager_format_interval (guint interval)
 {
   gint hours, mins, secs;
 
@@ -117,7 +96,6 @@ ft_manager_format_interval (gint interval)
     /* Translators: time left, when is is less than one hour */
     return g_strdup_printf (_("%02u.%02u"), mins, secs);
 }
-#endif
 
 static void
 ft_manager_update_buttons (EmpathyFTManager *manager)
@@ -125,15 +103,12 @@ ft_manager_update_buttons (EmpathyFTManager *manager)
   GtkTreeSelection *selection;
   GtkTreeModel *model;
   GtkTreeIter iter;
-<<<<<<< HEAD:src/empathy-ft-manager.c
-  EmpathyTpFile *tp_file;
-  TpFileTransferState state;
-=======
   EmpathyFTHandler *handler;
->>>>>>> Use the proper TP interface instead of emp_cli:src/empathy-ft-manager.c
   gboolean open_enabled = FALSE;
   gboolean abort_enabled = FALSE;
+  gboolean clear_enabled = FALSE;
   gboolean is_completed, is_cancelled;
+  GHashTableIter hash_iter;
   EmpathyFTManagerPriv *priv = GET_PRIV (manager);
 
   selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
@@ -146,49 +121,32 @@ ft_manager_update_buttons (EmpathyFTManager *manager)
       is_cancelled = empathy_ft_handler_is_cancelled (handler);
 
       /* I can open the file if the transfer is completed and was incoming */
-<<<<<<< HEAD:src/empathy-ft-manager.c
-      open_enabled = (state == TP_FILE_TRANSFER_STATE_COMPLETED &&
-        empathy_tp_file_is_incoming (tp_file));
-
-      /* I can abort if the transfer is not already finished */
-      abort_enabled = (state != TP_FILE_TRANSFER_STATE_CANCELLED &&
-        state != TP_FILE_TRANSFER_STATE_COMPLETED);
-=======
       open_enabled = (is_completed && empathy_ft_handler_is_incoming (handler));
 
       /* I can abort if the transfer is not already finished */
       abort_enabled = (is_cancelled == FALSE && is_completed == FALSE);
->>>>>>> Use the proper TP interface instead of emp_cli:src/empathy-ft-manager.c
 
       g_object_unref (handler);
     }
 
-  gtk_widget_set_sensitive (priv->open_button, open_enabled);
-  gtk_widget_set_sensitive (priv->abort_button, abort_enabled);
-}
+  g_hash_table_iter_init (&hash_iter, priv->ft_handler_to_row_ref);
 
-#if 0
-static const gchar *
-ft_manager_state_change_reason_to_string (TpFileTransferStateChangeReason reason)
-{
-  switch (reason)
+  while (g_hash_table_iter_next (&hash_iter, (gpointer *) &handler, NULL))
     {
-      case TP_FILE_TRANSFER_STATE_CHANGE_REASON_NONE:
-        return _("No reason was specified");
-      case TP_FILE_TRANSFER_STATE_CHANGE_REASON_REQUESTED:
-        return _("The change in state was requested");
-      case TP_FILE_TRANSFER_STATE_CHANGE_REASON_LOCAL_STOPPED:
-        return _("You canceled the file transfer");
-      case TP_FILE_TRANSFER_STATE_CHANGE_REASON_REMOTE_STOPPED:
-        return _("The other participant canceled the file transfer");
-      case TP_FILE_TRANSFER_STATE_CHANGE_REASON_LOCAL_ERROR:
-        return _("Error while trying to transfer the file");
-      case TP_FILE_TRANSFER_STATE_CHANGE_REASON_REMOTE_ERROR:
-        return _("The other participant is unable to transfer the file");
+      if (empathy_ft_handler_is_completed (handler) ||
+          empathy_ft_handler_is_cancelled (handler))
+          clear_enabled = TRUE;
+
+      if (clear_enabled)
+        break;
     }
-  return _("Unknown reason");
+
+  gtk_widget_set_sensitive (priv->open_button, open_enabled);
+  gtk_widget_set_sensitive (priv->abort_button, abort_enabled);
+
+  if (clear_enabled)
+    gtk_widget_set_sensitive (priv->clear_button, TRUE);
 }
-#endif
 
 static void
 ft_manager_selection_changed (GtkTreeSelection *selection,
@@ -242,7 +200,7 @@ ft_manager_remove_file_from_model (EmpathyFTManager *manager,
   g_return_if_fail (row_ref);
 
   DEBUG ("Removing file transfer from window: contact=%s, filename=%s",
-      empathy_contact_get_name (empathy_ft_handler_get_contact (handler)),
+      empathy_contact_get_alias (empathy_ft_handler_get_contact (handler)),
       empathy_ft_handler_get_filename (handler));
 
   /* Get the iter from the row_ref */
@@ -289,26 +247,34 @@ remove_finished_transfer_foreach (gpointer key,
   return FALSE;
 }
 
-static char *
+static gchar *
 ft_manager_format_progress_bytes_and_percentage (guint64 current,
                                                  guint64 total,
+                                                 gdouble speed,
                                                  int *percentage)
 {
   char *total_str, *current_str, *retval;
+  char *speed_str = NULL;
 
-  total_str = g_format_size_for_display (total);
-  current_str = g_format_size_for_display (current);
+  total_str = g_format_size (total);
+  current_str = g_format_size (current);
+
+  if (speed > 0)
+    speed_str = g_format_size ((goffset) speed);
 
   /* translators: first %s is the currently processed size, second %s is
    * the total file size */
-  retval = g_strdup_printf (_("%s of %s"), current_str, total_str);
+  retval = speed_str ?
+    g_strdup_printf (_("%s of %s at %s/s"), current_str, total_str, speed_str) :
+    g_strdup_printf (_("%s of %s"), current_str, total_str);
 
   g_free (total_str);
   g_free (current_str);
+  g_free (speed_str);
 
   if (percentage != NULL)
     {
-      if (total != 0) 
+      if (total != 0)
         *percentage = current * 100 / total;
       else
         *percentage = -1;
@@ -317,7 +283,7 @@ ft_manager_format_progress_bytes_and_percentage (guint64 current,
   return retval;
 }
 
-static char *
+static gchar *
 ft_manager_format_contact_info (EmpathyFTHandler *handler)
 {
   gboolean incoming;
@@ -325,7 +291,7 @@ ft_manager_format_contact_info (EmpathyFTHandler *handler)
   char *retval;
 
   incoming = empathy_ft_handler_is_incoming (handler);
-  contact_name = empathy_contact_get_name
+  contact_name = empathy_contact_get_alias
     (empathy_ft_handler_get_contact (handler));
   filename = empathy_ft_handler_get_filename (handler);
 
@@ -341,6 +307,49 @@ ft_manager_format_contact_info (EmpathyFTHandler *handler)
   return retval;
 }
 
+static gchar *
+ft_manager_format_error_message (EmpathyFTHandler *handler,
+                                 const GError *error)
+{
+  const char *contact_name, *filename;
+  EmpathyContact *contact;
+  char *first_line, *message;
+  gboolean incoming;
+
+  contact_name = NULL;
+  incoming = empathy_ft_handler_is_incoming (handler);
+
+  contact = empathy_ft_handler_get_contact (handler);
+  if (contact)
+    contact_name = empathy_contact_get_alias (contact);
+
+  filename = empathy_ft_handler_get_filename (handler);
+
+  if (incoming)
+    /* filename/contact_name here are either both NULL or both valid */
+    if (filename && contact_name)
+      /* translators: first %s is filename, second %s
+       * is the contact name */
+      first_line = g_strdup_printf (_("Error receiving \"%s\" from %s"), filename,
+          contact_name);
+    else
+      first_line = g_strdup (_("Error receiving a file"));
+  else
+    /* translators: first %s is filename, second %s
+     * is the contact name */
+    if (filename && contact_name)
+      first_line = g_strdup_printf (_("Error sending \"%s\" to %s"), filename,
+          contact_name);
+    else
+      first_line = g_strdup (_("Error sending a file"));
+
+  message = g_strdup_printf ("%s\n%s", first_line, error->message);
+
+  g_free (first_line);
+
+  return message;
+}
+
 static void
 ft_manager_update_handler_message (EmpathyFTManager *manager,
                                    GtkTreeRowReference *row_ref,
@@ -382,32 +391,89 @@ ft_manager_update_handler_progress (EmpathyFTManager *manager,
 
 }
 
+static void
+ft_manager_update_handler_time (EmpathyFTManager *manager,
+                                GtkTreeRowReference *row_ref,
+                                guint remaining_time)
+{
+  GtkTreePath *path;
+  GtkTreeIter iter;
+  EmpathyFTManagerPriv *priv = GET_PRIV (manager);
+  char *remaining_str;
+
+  remaining_str = ft_manager_format_interval (remaining_time);
+
+  /* Set new value in the store */
+  path = gtk_tree_row_reference_get_path (row_ref);
+  gtk_tree_model_get_iter (priv->model, &iter, path);
+  gtk_list_store_set (GTK_LIST_STORE (priv->model),
+      &iter,
+      COL_REMAINING, remaining_str,
+      -1);
+
+  gtk_tree_path_free (path);
+  g_free (remaining_str);
+}
+
+static void
+ft_manager_clear_handler_time (EmpathyFTManager *manager,
+                               GtkTreeRowReference *row_ref)
+{
+  GtkTreePath *path;
+  GtkTreeIter iter;
+  EmpathyFTManagerPriv *priv = GET_PRIV (manager);
+
+  /* Set new value in the store */
+  path = gtk_tree_row_reference_get_path (row_ref);
+  gtk_tree_model_get_iter (priv->model, &iter, path);
+  gtk_list_store_set (GTK_LIST_STORE (priv->model),
+      &iter,
+      COL_REMAINING, NULL,
+      -1);
+
+  gtk_tree_path_free (path);
+}
+
 static void
 ft_handler_transfer_error_cb (EmpathyFTHandler *handler,
                               GError *error,
                               EmpathyFTManager *manager)
 {
-  /* TODO: implement */
+  char *message;
+  GtkTreeRowReference *row_ref;
+
+  DEBUG ("Transfer error %s", error->message);
+
+  row_ref = ft_manager_get_row_from_handler (manager, handler);
+  g_return_if_fail (row_ref != NULL);
+
+  message = ft_manager_format_error_message (handler, error);
+
+  ft_manager_update_handler_message (manager, row_ref, message);
+  ft_manager_clear_handler_time (manager, row_ref);
+  ft_manager_update_buttons (manager);
+
+  g_free (message);
 }
 
 static void
-ft_handler_transfer_done_cb (EmpathyFTHandler *handler,
-                             EmpathyTpFile *tp_file,
-                             EmpathyFTManager *manager)
+do_real_transfer_done (EmpathyFTManager *manager,
+                       EmpathyFTHandler *handler)
 {
   const char *contact_name;
   const char *filename;
   char *first_line, *second_line, *message;
+  char *uri;
   gboolean incoming;
   GtkTreeRowReference *row_ref;
-
-  DEBUG ("Transfer done");
+  GtkRecentManager *recent_manager;
+  GFile *file;
 
   row_ref = ft_manager_get_row_from_handler (manager, handler);
   g_return_if_fail (row_ref != NULL);
 
   incoming = empathy_ft_handler_is_incoming (handler);
-  contact_name = empathy_contact_get_name
+  contact_name = empathy_contact_get_alias
     (empathy_ft_handler_get_contact (handler));
   filename = empathy_ft_handler_get_filename (handler);
 
@@ -426,6 +492,7 @@ ft_handler_transfer_done_cb (EmpathyFTHandler *handler,
 
   message = g_strdup_printf ("%s\n%s", first_line, second_line);
   ft_manager_update_handler_message (manager, row_ref, message);
+  ft_manager_clear_handler_time (manager, row_ref);
 
   /* update buttons */
   ft_manager_update_buttons (manager);
@@ -433,12 +500,44 @@ ft_handler_transfer_done_cb (EmpathyFTHandler *handler,
   g_free (message);
   g_free (first_line);
   g_free (second_line);
+
+  recent_manager = gtk_recent_manager_get_default ();
+  file = empathy_ft_handler_get_gfile (handler);
+  uri = g_file_get_uri (file);
+
+  gtk_recent_manager_add_item (recent_manager, uri);
+
+  g_free (uri);
+}
+
+static void
+ft_handler_transfer_done_cb (EmpathyFTHandler *handler,
+                             TpFileTransferChannel *channel,
+                             EmpathyFTManager *manager)
+{
+  if (empathy_ft_handler_is_incoming (handler) &&
+      empathy_ft_handler_get_use_hash (handler))
+    {
+      DEBUG ("Transfer done, waiting for hashing-started");
+
+      /* connect to the signal and return early */
+      g_signal_connect (handler, "hashing-started",
+          G_CALLBACK (ft_handler_hashing_started_cb), manager);
+
+      return;
+    }
+
+  DEBUG ("Transfer done, no hashing");
+
+  do_real_transfer_done (manager, handler);
 }
 
 static void
 ft_handler_transfer_progress_cb (EmpathyFTHandler *handler,
                                  guint64 current_bytes,
                                  guint64 total_bytes,
+                                 guint remaining_time,
+                                 gdouble speed,
                                  EmpathyFTManager *manager)
 {
   char *first_line, *second_line, *message;
@@ -452,19 +551,24 @@ ft_handler_transfer_progress_cb (EmpathyFTHandler *handler,
 
   first_line = ft_manager_format_contact_info (handler);
   second_line = ft_manager_format_progress_bytes_and_percentage
-    (current_bytes, total_bytes, &percentage);
+    (current_bytes, total_bytes, speed, &percentage);
 
   message = g_strdup_printf ("%s\n%s", first_line, second_line);
 
   ft_manager_update_handler_message (manager, row_ref, message);
   ft_manager_update_handler_progress (manager, row_ref, percentage);
 
+  if (remaining_time > 0)
+    ft_manager_update_handler_time (manager, row_ref, remaining_time);
+
   g_free (message);
+  g_free (first_line);
+  g_free (second_line);
 }
 
 static void
 ft_handler_transfer_started_cb (EmpathyFTHandler *handler,
-                                EmpathyTpFile *tp_file,
+                                TpFileTransferChannel *channel,
                                 EmpathyFTManager *manager)
 {
   guint64 transferred_bytes, total_bytes;
@@ -480,7 +584,7 @@ ft_handler_transfer_started_cb (EmpathyFTHandler *handler,
   total_bytes = empathy_ft_handler_get_total_bytes (handler);
 
   ft_handler_transfer_progress_cb (handler, transferred_bytes, total_bytes,
-      manager);
+      0, -1, manager);
 }
 
 static void
@@ -492,10 +596,16 @@ ft_handler_hashing_done_cb (EmpathyFTHandler *handler,
 
   DEBUG ("Hashing done");
 
+  /* update the message */
+  if (empathy_ft_handler_is_incoming (handler))
+    {
+      do_real_transfer_done (manager, handler);
+      return;
+    }
+
   row_ref = ft_manager_get_row_from_handler (manager, handler);
   g_return_if_fail (row_ref != NULL);
 
-  /* update the message */
   first_line = ft_manager_format_contact_info (handler);
   second_line = g_strdup (_("Waiting for the other participant's response"));
   message = g_strdup_printf ("%s\n%s", first_line, second_line);
@@ -519,28 +629,33 @@ ft_handler_hashing_progress_cb (EmpathyFTHandler *handler,
   char *first_line, *second_line, *message;
   GtkTreeRowReference *row_ref;
 
-  DEBUG ("Hashing progress");
-
   row_ref = ft_manager_get_row_from_handler (manager, handler);
   g_return_if_fail (row_ref != NULL);
 
-  first_line =  g_strdup_printf (_("Hashing \"%s\""),
-      empathy_ft_handler_get_filename (handler));
+  if (empathy_ft_handler_is_incoming (handler))
+      first_line = g_strdup_printf (_("Checking integrity of \"%s\""),
+          empathy_ft_handler_get_filename (handler));
+  else
+      first_line =  g_strdup_printf (_("Hashing \"%s\""),
+          empathy_ft_handler_get_filename (handler));
+
   second_line = ft_manager_format_progress_bytes_and_percentage
-    (current_bytes, total_bytes, NULL);
+    (current_bytes, total_bytes, -1, NULL);
 
   message = g_strdup_printf ("%s\n%s", first_line, second_line);
 
   ft_manager_update_handler_message (manager, row_ref, message);
 
   g_free (message);
+  g_free (first_line);
+  g_free (second_line);
 }
 
 static void
 ft_handler_hashing_started_cb (EmpathyFTHandler *handler,
                                EmpathyFTManager *manager)
 {
-  char *message;
+  char *message, *first_line, *second_line;
   GtkTreeRowReference *row_ref;
 
   DEBUG ("Hashing started");
@@ -553,11 +668,21 @@ ft_handler_hashing_started_cb (EmpathyFTHandler *handler,
   row_ref = ft_manager_get_row_from_handler (manager, handler);
   g_return_if_fail (row_ref != NULL);
 
-  message =  g_strdup_printf (_("Hashing \"%s\""),
-      empathy_ft_handler_get_filename (handler));
+  first_line = ft_manager_format_contact_info (handler);
+
+  if (empathy_ft_handler_is_incoming (handler))
+      second_line = g_strdup_printf (_("Checking integrity of \"%s\""),
+          empathy_ft_handler_get_filename (handler));
+  else
+      second_line = g_strdup_printf (_("Hashing \"%s\""),
+          empathy_ft_handler_get_filename (handler));
+
+  message = g_strdup_printf ("%s\n%s", first_line, second_line);
 
   ft_manager_update_handler_message (manager, row_ref, message);
 
+  g_free (first_line);
+  g_free (second_line);
   g_free (message);
 }
 
@@ -565,25 +690,24 @@ static void
 ft_manager_start_transfer (EmpathyFTManager *manager,
                            EmpathyFTHandler *handler)
 {
-  EmpathyFTManagerPriv *priv;
-  gboolean is_incoming;
-
-  priv = GET_PRIV (manager);
+  gboolean is_outgoing;
 
-  is_incoming = empathy_ft_handler_is_incoming (handler);
+  is_outgoing = !empathy_ft_handler_is_incoming (handler);
 
-  DEBUG ("Start transfer, is incoming %d", is_incoming);
+  DEBUG ("Start transfer, is outgoing %s",
+      is_outgoing ? "True" : "False");
 
   /* now connect the signals */
   g_signal_connect (handler, "transfer-error",
       G_CALLBACK (ft_handler_transfer_error_cb), manager);
 
-  if (is_incoming) {
-    g_signal_connect (handler, "transfer-started",
-        G_CALLBACK (ft_handler_transfer_started_cb), manager);
-  } else {
+  if (is_outgoing && empathy_ft_handler_get_use_hash (handler)) {
     g_signal_connect (handler, "hashing-started",
         G_CALLBACK (ft_handler_hashing_started_cb), manager);
+  } else {
+    /* either incoming or outgoing without hash */
+    g_signal_connect (handler, "transfer-started",
+        G_CALLBACK (ft_handler_transfer_started_cb), manager);
   }
 
   empathy_ft_handler_start_transfer (handler);
@@ -591,25 +715,33 @@ ft_manager_start_transfer (EmpathyFTManager *manager,
 
 static void
 ft_manager_add_handler_to_list (EmpathyFTManager *manager,
-                                EmpathyFTHandler *handler)
+                                EmpathyFTHandler *handler,
+                                const GError *error)
 {
   GtkTreeRowReference *row_ref;
   GtkTreeIter iter;
   GtkTreeSelection *selection;
   GtkTreePath *path;
   GIcon *icon;
-  const char *content_type;
-  char *first_line, *second_line, *message;
+  const char *content_type, *second_line;
+  char *first_line, *message;
   EmpathyFTManagerPriv *priv = GET_PRIV (manager);
 
+  icon = NULL;
+
   /* get the icon name from the mime-type of the file. */
   content_type = empathy_ft_handler_get_content_type (handler);
-  icon = g_content_type_get_icon (content_type);
+
+  if (content_type != NULL)
+    icon = g_content_type_get_icon (content_type);
 
   /* append the handler in the store */
   gtk_list_store_insert_with_values (GTK_LIST_STORE (priv->model),
-      &iter, G_MAXINT, COL_FT_OBJECT, handler, COL_ICON, icon, -1);
-  g_object_unref (icon);
+      &iter, G_MAXINT, COL_FT_OBJECT, handler,
+      COL_ICON, icon, -1);
+
+  if (icon != NULL)
+    g_object_unref (icon);
 
   /* insert the new row_ref in the hash table  */
   path = gtk_tree_model_get_path (GTK_TREE_MODEL (priv->model), &iter);
@@ -622,21 +754,34 @@ ft_manager_add_handler_to_list (EmpathyFTManager *manager,
   selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
   gtk_tree_selection_select_iter (selection, &iter);
 
-  /* update the row with the initial values */
-  if (empathy_ft_handler_is_incoming (handler)) {
+  if (error != NULL)
+    {
+      message = ft_manager_format_error_message (handler, error);
+      ft_manager_update_handler_message (manager, row_ref, message);
+
+      g_free (message);
+      return;
+    }
+
+  /* update the row with the initial values.
+   * the only case where we postpone this is in case we're managing
+   * an outgoing+hashing transfer, as the hashing started signal will
+   * take care of updating the information.
+   */
+  if (empathy_ft_handler_is_incoming (handler) ||
+      !empathy_ft_handler_get_use_hash (handler)) {
     first_line = ft_manager_format_contact_info (handler);
-    second_line = g_strdup (_("Waiting for the other participant's response"));
+    second_line = _("Waiting for the other participant's response");
     message = g_strdup_printf ("%s\n%s", first_line, second_line);
 
     ft_manager_update_handler_message (manager, row_ref, message);
+
+    g_free (first_line);
+    g_free (message);
   }
 
   /* hook up the signals and start the transfer */
   ft_manager_start_transfer (manager, handler);
-
-  g_free (first_line);
-  g_free (second_line);
-  g_free (message);
 }
 
 static void
@@ -651,6 +796,9 @@ ft_manager_clear (EmpathyFTManager *manager)
   /* Remove completed and cancelled transfers */
   g_hash_table_foreach_remove (priv->ft_handler_to_row_ref,
       remove_finished_transfer_foreach, manager);
+
+  /* set the clear button back to insensitive */
+  gtk_widget_set_sensitive (priv->clear_button, FALSE);
 }
 
 static void
@@ -660,8 +808,6 @@ ft_manager_open (EmpathyFTManager *manager)
   GtkTreeIter iter;
   GtkTreeModel *model;
   EmpathyFTHandler *handler;
-  char *uri;
-  GFile *file;
   EmpathyFTManagerPriv *priv = GET_PRIV (manager);
 
   selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
@@ -671,14 +817,19 @@ ft_manager_open (EmpathyFTManager *manager)
 
   gtk_tree_model_get (model, &iter, COL_FT_OBJECT, &handler, -1);
 
-  file = empathy_ft_handler_get_gfile (handler);
-  uri = g_file_get_uri (file);
+  if (empathy_ft_handler_is_completed (handler)){
+    char *uri;
+    GFile *file;
 
-  DEBUG ("Opening URI: %s", uri);
-  empathy_url_show (GTK_WIDGET (priv->window), uri);
+    file = empathy_ft_handler_get_gfile (handler);
+    uri = g_file_get_uri (file);
+
+    DEBUG ("Opening URI: %s", uri);
+    empathy_url_show (GTK_WIDGET (priv->window), uri);
+    g_free (uri);
+  }
 
   g_object_unref (handler);
-  g_free (uri);
 }
 
 static void
@@ -701,7 +852,7 @@ ft_manager_stop (EmpathyFTManager *manager)
   g_return_if_fail (handler != NULL);
 
   DEBUG ("Stopping file transfer: contact=%s, filename=%s",
-      empathy_contact_get_name (empathy_ft_handler_get_contact (handler)),
+      empathy_contact_get_alias (empathy_ft_handler_get_contact (handler)),
       empathy_ft_handler_get_filename (handler));
 
   empathy_ft_handler_cancel_transfer (handler);
@@ -710,33 +861,22 @@ ft_manager_stop (EmpathyFTManager *manager)
 }
 
 static gboolean
-ft_manager_save_geometry_timeout_cb (EmpathyFTManager *manager)
+close_window (EmpathyFTManager *manager)
 {
   EmpathyFTManagerPriv *priv = GET_PRIV (manager);
-  gint x, y, w, h;
-
-  gtk_window_get_size (GTK_WINDOW (priv->window), &w, &h);
-  gtk_window_get_position (GTK_WINDOW (priv->window), &x, &y);
 
-  empathy_geometry_save ("ft-manager", x, y, w, h);
-
-  priv->save_geometry_id = 0;
-
-  return FALSE;
-}
-
-static gboolean
-ft_manager_configure_event_cb (GtkWidget *widget,
-                               GdkEventConfigure *event,
-                               EmpathyFTManager *manager)
-{
-  EmpathyFTManagerPriv *priv = GET_PRIV (manager);
+  DEBUG ("%p", manager);
 
-  if (priv->save_geometry_id != 0)
-    g_source_remove (priv->save_geometry_id);
+  /* remove all the completed/cancelled/errored transfers */
+  ft_manager_clear (manager);
 
-  priv->save_geometry_id = g_timeout_add (500,
-      (GSourceFunc) ft_manager_save_geometry_timeout_cb, manager);
+  if (g_hash_table_size (priv->ft_handler_to_row_ref) > 0)
+    {
+      /* There is still FTs on flight, just hide the window */
+      DEBUG ("Hiding window");
+      gtk_widget_hide (priv->window);
+      return TRUE;
+    }
 
   return FALSE;
 }
@@ -746,6 +886,8 @@ ft_manager_response_cb (GtkWidget *widget,
                         gint response,
                         EmpathyFTManager *manager)
 {
+  EmpathyFTManagerPriv *priv = GET_PRIV (manager);
+
   switch (response)
     {
       case RESPONSE_CLEAR:
@@ -757,6 +899,16 @@ ft_manager_response_cb (GtkWidget *widget,
       case RESPONSE_STOP:
         ft_manager_stop (manager);
         break;
+      case RESPONSE_CLOSE:
+        if (!close_window (manager))
+          gtk_widget_destroy (priv->window);
+        break;
+      case GTK_RESPONSE_NONE:
+      case GTK_RESPONSE_DELETE_EVENT:
+        /* Do nothing */
+        break;
+      default:
+        g_assert_not_reached ();
     }
 }
 
@@ -765,34 +917,51 @@ ft_manager_delete_event_cb (GtkWidget *widget,
                             GdkEvent *event,
                             EmpathyFTManager *manager)
 {
-  EmpathyFTManagerPriv *priv = GET_PRIV (manager);
-
-  /* remove all the completed/cancelled/errored transfers */
-  ft_manager_clear (manager);
-
-  if (g_hash_table_size (priv->ft_handler_to_row_ref) > 0)
-    {
-      /* There is still FTs on flight, just hide the window */
-      DEBUG ("Hiding window");
-      gtk_widget_hide (widget);
-      return TRUE;
-    }
-
-  return FALSE;
+  return close_window (manager);
 }
 
 static void
 ft_manager_destroy_cb (GtkWidget *widget,
                        EmpathyFTManager *manager)
 {
+  DEBUG ("%p", manager);
+
   g_object_unref (manager);
 }
 
+static gboolean
+ft_view_button_press_event_cb (GtkWidget *widget,
+                               GdkEventKey *event,
+                               EmpathyFTManager *manager)
+{
+
+  if (event->type != GDK_2BUTTON_PRESS)
+      return FALSE;
+
+  ft_manager_open (manager);
+
+  return FALSE;
+}
+
+static gboolean
+ft_manager_key_press_event_cb (GtkWidget *widget,
+                               GdkEventKey *event,
+                               gpointer user_data)
+{
+  if ((event->state & GDK_CONTROL_MASK && event->keyval == GDK_KEY_w)
+      || event->keyval == GDK_KEY_Escape)
+    {
+      gtk_widget_destroy (widget);
+      return TRUE;
+    }
+
+  return FALSE;
+}
+
 static void
 ft_manager_build_ui (EmpathyFTManager *manager)
 {
   GtkBuilder *gui;
-  gint x, y, w, h;
   GtkTreeView *view;
   GtkListStore *liststore;
   GtkTreeViewColumn *column;
@@ -802,39 +971,26 @@ ft_manager_build_ui (EmpathyFTManager *manager)
   EmpathyFTManagerPriv *priv = GET_PRIV (manager);
 
   filename = empathy_file_lookup ("empathy-ft-manager.ui", "src");
-  gui = empathy_builder_get_file (filename,
+  gui = tpaw_builder_get_file (filename,
       "ft_manager_dialog", &priv->window,
       "ft_list", &priv->treeview,
+      "clear_button", &priv->clear_button,
       "open_button", &priv->open_button,
       "abort_button", &priv->abort_button,
       NULL);
   g_free (filename);
 
-  empathy_builder_connect (gui, manager,
+  tpaw_builder_connect (gui, manager,
       "ft_manager_dialog", "destroy", ft_manager_destroy_cb,
       "ft_manager_dialog", "response", ft_manager_response_cb,
       "ft_manager_dialog", "delete-event", ft_manager_delete_event_cb,
-      "ft_manager_dialog", "configure-event", ft_manager_configure_event_cb,
+      "ft_manager_dialog", "key-press-event", ft_manager_key_press_event_cb,
       NULL);
 
-  g_object_unref (gui);
+  tpaw_builder_unref_and_keep_widget (gui, priv->window);
 
   /* Window geometry. */
-  empathy_geometry_load ("ft-manager", &x, &y, &w, &h);
-
-  if (x >= 0 && y >= 0)
-    {
-      /* Let the window manager position it if we don't have
-       * good x, y coordinates. */
-      gtk_window_move (GTK_WINDOW (priv->window), x, y);
-    }
-
-  if (w > 0 && h > 0)
-    {
-      /* Use the defaults from the ui file if we don't have
-       * good w, h geometry. */
-      gtk_window_resize (GTK_WINDOW (priv->window), w, h);
-    }
+  empathy_geometry_bind (GTK_WINDOW (priv->window), "ft-manager");
 
   /* Setup the tree view */
   view = GTK_TREE_VIEW (priv->treeview);
@@ -842,6 +998,9 @@ ft_manager_build_ui (EmpathyFTManager *manager)
   gtk_tree_selection_set_mode (selection, GTK_SELECTION_BROWSE);
   g_signal_connect (selection, "changed",
       G_CALLBACK (ft_manager_selection_changed), manager);
+  g_signal_connect (view, "button-press-event",
+                    G_CALLBACK (ft_view_button_press_event_cb),
+                    manager);
   gtk_tree_view_set_headers_visible (view, TRUE);
   gtk_tree_view_set_enable_search (view, FALSE);
 
@@ -901,6 +1060,11 @@ ft_manager_build_ui (EmpathyFTManager *manager)
   gtk_tree_view_column_pack_start (column, renderer, FALSE);
   gtk_tree_view_column_set_attributes (column, renderer,
       "text", COL_REMAINING, NULL);
+
+  /* clear button should be sensitive only if there are completed/cancelled
+   * handlers in the store.
+   */
+  gtk_widget_set_sensitive (priv->clear_button, FALSE);
 }
 
 /* GObject method overrides */
@@ -910,12 +1074,9 @@ empathy_ft_manager_finalize (GObject *object)
 {
   EmpathyFTManagerPriv *priv = GET_PRIV (object);
 
-  DEBUG ("%p", object);
+  DEBUG ("FT Manager %p", object);
 
-  g_hash_table_destroy (priv->ft_handler_to_row_ref);
-
-  if (priv->save_geometry_id != 0)
-    g_source_remove (priv->save_geometry_id);
+  g_hash_table_unref (priv->ft_handler_to_row_ref);
 
   G_OBJECT_CLASS (empathy_ft_manager_parent_class)->finalize (object);
 }
@@ -946,7 +1107,7 @@ empathy_ft_manager_constructor (GType type,
 
   if (manager_singleton)
     {
-      retval = g_object_ref (manager_singleton);
+      retval = G_OBJECT (manager_singleton);
     }
   else
     {
@@ -973,31 +1134,48 @@ empathy_ft_manager_class_init (EmpathyFTManagerClass *klass)
 
 /* public methods */
 
-/**
- * empathy_ft_manager_dup_singleton:
- *
- * Returns a reference to the #EmpathyFTManager singleton object.
- *
- * Returns: a #EmpathyFTManager
- */
-EmpathyFTManager *
-empathy_ft_manager_dup_singleton (void)
+void
+empathy_ft_manager_add_handler (EmpathyFTHandler *handler)
 {
-  return g_object_new (EMPATHY_TYPE_FT_MANAGER, NULL);
+  EmpathyFTManager *manager;
+  EmpathyFTManagerPriv *priv;
+
+  DEBUG ("Adding handler");
+
+  g_return_if_fail (EMPATHY_IS_FT_HANDLER (handler));
+
+  manager = g_object_new (EMPATHY_TYPE_FT_MANAGER, NULL);
+  priv = GET_PRIV (manager);
+
+  ft_manager_add_handler_to_list (manager, handler, NULL);
+  gtk_window_present (GTK_WINDOW (priv->window));
 }
 
 void
-empathy_ft_manager_add_handler (EmpathyFTManager *manager,
-                                EmpathyFTHandler *handler)
+empathy_ft_manager_display_error (EmpathyFTHandler *handler,
+                                  const GError *error)
 {
-  EmpathyFTManagerPriv *priv = GET_PRIV (manager);
-
-  DEBUG ("Adding handler");
+  EmpathyFTManager *manager;
+  EmpathyFTManagerPriv *priv;
 
-  g_return_if_fail (EMPATHY_IS_FT_MANAGER (manager));
   g_return_if_fail (EMPATHY_IS_FT_HANDLER (handler));
+  g_return_if_fail (error != NULL);
+
+  manager = g_object_new (EMPATHY_TYPE_FT_MANAGER, NULL);
+  priv = GET_PRIV (manager);
 
-  ft_manager_add_handler_to_list (manager, handler);
+  ft_manager_add_handler_to_list (manager, handler, error);
   gtk_window_present (GTK_WINDOW (priv->window));
 }
 
+void
+empathy_ft_manager_show (void)
+{
+  EmpathyFTManager *manager;
+  EmpathyFTManagerPriv *priv;
+
+  manager = g_object_new (EMPATHY_TYPE_FT_MANAGER, NULL);
+  priv = GET_PRIV (manager);
+
+  gtk_window_present (GTK_WINDOW (priv->window));
+}