empathy r1770 - in trunk: libempathy libempathy-gtk



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

Log:
Converted sources to Collabora coding style. (Jonny Lamb)

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

Modified:
   trunk/libempathy-gtk/empathy-ft-manager.c
   trunk/libempathy-gtk/empathy-ft-manager.h
   trunk/libempathy/empathy-file.c
   trunk/libempathy/empathy-file.h
   trunk/libempathy/empathy-utils.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:15:54 2008
@@ -57,18 +57,18 @@
 
 enum
 {
-	COL_PERCENT,
-	COL_IMAGE,
-	COL_MESSAGE,
-	COL_REMAINING,
-	COL_FT_OBJECT
+  COL_PERCENT,
+  COL_IMAGE,
+  COL_MESSAGE,
+  COL_REMAINING,
+  COL_FT_OBJECT
 };
 
 enum
 {
-	PROGRESS_COL_POS,
-	FILE_COL_POS,
-	REMAINING_COL_POS
+  PROGRESS_COL_POS,
+  FILE_COL_POS,
+  REMAINING_COL_POS
 };
 
 #define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), EMPATHY_TYPE_FT_MANAGER, EmpathyFTManagerPriv))
@@ -80,39 +80,38 @@
  */
 struct _EmpathyFTManagerPriv
 {
-	GtkTreeModel *model;
-	GHashTable *file_to_row_ref;
+  GtkTreeModel *model;
+  GHashTable *file_to_row_ref;
 
-	/* Widgets */
-	GtkWidget *window;
-	GtkWidget *treeview;
-	GtkWidget *open_button;
-	GtkWidget *abort_button;
+  /* Widgets */
+  GtkWidget *window;
+  GtkWidget *treeview;
+  GtkWidget *open_button;
+  GtkWidget *abort_button;
 
-	guint save_geometry_id;
+  guint save_geometry_id;
 };
 
 enum
 {
-	RESPONSE_OPEN  = 1,
-	RESPONSE_STOP  = 2,
-	RESPONSE_CLEAR = 3
+  RESPONSE_OPEN  = 1,
+  RESPONSE_STOP  = 2,
+  RESPONSE_CLEAR = 3
 };
 
-static void empathy_ft_manager_class_init    (EmpathyFTManagerClass *klass);
-static void empathy_ft_manager_init          (EmpathyFTManager      *ft_manager);
-static void empathy_ft_manager_finalize      (GObject               *object);
-
-static void ft_manager_build_ui              (EmpathyFTManager      *ft_manager);
-static void ft_manager_response_cb           (GtkWidget             *dialog,
-					      gint                   response,
-					      EmpathyFTManager      *ft_manager);
-static void ft_manager_add_file_to_list      (EmpathyFTManager      *ft_manager,
-					      EmpathyFile           *file);
-static void ft_manager_remove_file_from_list (EmpathyFTManager      *ft_manager,
-					      EmpathyFile           *file);
-static void ft_manager_display_accept_dialog (EmpathyFTManager      *ft_manager,
-					      EmpathyFile           *file);
+static void empathy_ft_manager_class_init (EmpathyFTManagerClass *klass);
+static void empathy_ft_manager_init (EmpathyFTManager *ft_manager);
+static void empathy_ft_manager_finalize (GObject *object);
+
+static void ft_manager_build_ui (EmpathyFTManager *ft_manager);
+static void ft_manager_response_cb (GtkWidget *dialog, gint response,
+    EmpathyFTManager *ft_manager);
+static void ft_manager_add_file_to_list (EmpathyFTManager *ft_manager,
+    EmpathyFile *file);
+static void ft_manager_remove_file_from_list (EmpathyFTManager *ft_manager,
+    EmpathyFile *file);
+static void ft_manager_display_accept_dialog (EmpathyFTManager *ft_manager,
+    EmpathyFile *file);
 
 G_DEFINE_TYPE (EmpathyFTManager, empathy_ft_manager, G_TYPE_OBJECT);
 
@@ -121,44 +120,43 @@
 static void
 empathy_ft_manager_class_init (EmpathyFTManagerClass *klass)
 {
-	GObjectClass *object_class = G_OBJECT_CLASS (klass);
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
-	object_class->finalize = empathy_ft_manager_finalize;
+  object_class->finalize = empathy_ft_manager_finalize;
 
-	g_type_class_add_private (object_class, sizeof (EmpathyFTManagerPriv));
+  g_type_class_add_private (object_class, sizeof (EmpathyFTManagerPriv));
 }
 
 static void
 empathy_ft_manager_init (EmpathyFTManager *ft_manager)
 {
-	EmpathyFTManagerPriv *priv;
+  EmpathyFTManagerPriv *priv;
 
-	priv = GET_PRIV (ft_manager);
+  priv = GET_PRIV (ft_manager);
 
-	priv->file_to_row_ref = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL,
-						     (GDestroyNotify) gtk_tree_row_reference_free);
+  priv->file_to_row_ref = g_hash_table_new_full (g_direct_hash,
+      g_direct_equal, NULL, (GDestroyNotify) gtk_tree_row_reference_free);
 
-	ft_manager_build_ui (ft_manager);
+  ft_manager_build_ui (ft_manager);
 }
 
 static void
 empathy_ft_manager_finalize (GObject *object)
 {
-	EmpathyFTManagerPriv *priv;
+  EmpathyFTManagerPriv *priv;
 
-	DEBUG ("Finalizing: %p", object);
+  DEBUG ("Finalizing: %p", object);
 
-	priv = GET_PRIV (object);
+  priv = GET_PRIV (object);
 
-	g_hash_table_destroy (priv->file_to_row_ref);
+  g_hash_table_destroy (priv->file_to_row_ref);
 
-	if (priv->save_geometry_id != 0) {
-		g_source_remove (priv->save_geometry_id);
-	}
+  if (priv->save_geometry_id != 0)
+    g_source_remove (priv->save_geometry_id);
 
-	manager_p = NULL;
+  manager_p = NULL;
 
-	G_OBJECT_CLASS (empathy_ft_manager_parent_class)->finalize (object);
+  G_OBJECT_CLASS (empathy_ft_manager_parent_class)->finalize (object);
 }
 
 /**
@@ -172,10 +170,10 @@
 EmpathyFTManager *
 empathy_ft_manager_get_default (void)
 {
-	if (!manager_p)
-		manager_p = g_object_new (EMPATHY_TYPE_FT_MANAGER, NULL);
+  if (!manager_p)
+    manager_p = g_object_new (EMPATHY_TYPE_FT_MANAGER, NULL);
 
-	return manager_p;
+  return manager_p;
 }
 
 /**
@@ -188,23 +186,23 @@
  * @ft.
  */
 void
-empathy_ft_manager_add_file (EmpathyFTManager *ft_manager,
-			     EmpathyFile      *file)
+empathy_ft_manager_add_file (EmpathyFTManager *ft_manager, EmpathyFile *file)
 {
-	EmpFileTransferState state;
+  EmpFileTransferState state;
 
-	g_return_if_fail (EMPATHY_IS_FT_MANAGER (ft_manager));
-	g_return_if_fail (EMPATHY_IS_FILE (file));
+  g_return_if_fail (EMPATHY_IS_FT_MANAGER (ft_manager));
+  g_return_if_fail (EMPATHY_IS_FILE (file));
 
-	DEBUG ("Adding a file transfer: contact=%s, filename=%s",
-	       empathy_contact_get_name (empathy_file_get_contact (file)),
-	       empathy_file_get_filename (file));
-
-	state = empathy_file_get_state (file);
-	if (state == EMP_FILE_TRANSFER_STATE_LOCAL_PENDING)
-		ft_manager_display_accept_dialog (ft_manager, file);
-	else
-		ft_manager_add_file_to_list (ft_manager, file);
+  DEBUG ("Adding a file transfer: contact=%s, filename=%s",
+      empathy_contact_get_name (empathy_file_get_contact (file)),
+      empathy_file_get_filename (file));
+
+  state = empathy_file_get_state (file);
+
+  if (state == EMP_FILE_TRANSFER_STATE_LOCAL_PENDING)
+    ft_manager_display_accept_dialog (ft_manager, file);
+  else
+    ft_manager_add_file_to_list (ft_manager, file);
 }
 
 /**
@@ -218,1002 +216,1005 @@
 GtkWidget *
 empathy_ft_manager_get_dialog (EmpathyFTManager *ft_manager)
 {
-	EmpathyFTManagerPriv *priv;
+  EmpathyFTManagerPriv *priv;
 
-	g_return_val_if_fail (EMPATHY_IS_FT_MANAGER (ft_manager), NULL);
+  g_return_val_if_fail (EMPATHY_IS_FT_MANAGER (ft_manager), NULL);
 
-	priv = GET_PRIV (ft_manager);
+  priv = GET_PRIV (ft_manager);
 
-	return priv->window;
+  return priv->window;
 }
 
 static gchar *
 format_interval (gint interval)
 {
-	gint hours, mins, secs;
+  gint hours, mins, secs;
 
-	hours = interval / 3600;
-	interval -= hours * 3600;
-	mins = interval / 60;
-	interval -= mins * 60;
-	secs = interval;
-
-	if (hours > 0)
-		return g_strdup_printf (_("%u:%02u.%02u"), hours, mins, secs);
-	else
-		return g_strdup_printf (_("%02u.%02u"), mins, secs);
+  hours = interval / 3600;
+  interval -= hours * 3600;
+  mins = interval / 60;
+  interval -= mins * 60;
+  secs = interval;
+
+  if (hours > 0)
+    return g_strdup_printf (_("%u:%02u.%02u"), hours, mins, secs);
+  else
+    return g_strdup_printf (_("%02u.%02u"), mins, secs);
 }
 
 static GtkTreeRowReference *
 get_row_from_file (EmpathyFTManager *ft_manager, EmpathyFile *file)
 {
-	EmpathyFTManagerPriv *priv;
+  EmpathyFTManagerPriv *priv;
 
-	priv = GET_PRIV (ft_manager);
+  priv = GET_PRIV (ft_manager);
 
-	return g_hash_table_lookup (priv->file_to_row_ref, file);
+  return g_hash_table_lookup (priv->file_to_row_ref, file);
 }
 
 static void
 update_buttons (EmpathyFTManager *ft_manager)
 {
-	EmpathyFTManagerPriv *priv;
-	GtkTreeSelection     *selection;
-	GtkTreeModel         *model;
-	GtkTreeIter           iter;
-	GValue                val = {0, };
-	EmpathyFile          *file;
-	gboolean              open_enabled = FALSE;
-	gboolean              abort_enabled = FALSE;
-
-	priv = GET_PRIV (ft_manager);
-
-	selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
-	if (gtk_tree_selection_get_selected (selection, &model, &iter)) {
-		gtk_tree_model_get_value (model, &iter, COL_FT_OBJECT, &val);
-		file = g_value_get_object (&val);
-		g_value_unset (&val);
-
-		if (empathy_file_get_state (file) == EMP_FILE_TRANSFER_STATE_COMPLETED) {
-			if (empathy_file_get_direction (file) ==
-			    EMP_FILE_TRANSFER_DIRECTION_INCOMING)
-				open_enabled = TRUE;
-			else
-				open_enabled = FALSE;
-			abort_enabled = FALSE;
-		} else if (empathy_file_get_state (file) ==
-			   EMP_FILE_TRANSFER_STATE_CANCELED) {
-			open_enabled = FALSE;
-			abort_enabled = FALSE;
-		} else {
-			open_enabled = FALSE;
-			abort_enabled = TRUE;
-		}
-	}
+  EmpathyFTManagerPriv *priv;
+  GtkTreeSelection *selection;
+  GtkTreeModel *model;
+  GtkTreeIter iter;
+  GValue val = {0, };
+  EmpathyFile *file;
+  gboolean open_enabled = FALSE;
+  gboolean abort_enabled = FALSE;
+
+  priv = GET_PRIV (ft_manager);
+
+  selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
+  if (gtk_tree_selection_get_selected (selection, &model, &iter))
+    {
+      gtk_tree_model_get_value (model, &iter, COL_FT_OBJECT, &val);
+      file = g_value_get_object (&val);
+      g_value_unset (&val);
+
+      if (empathy_file_get_state (file) == EMP_FILE_TRANSFER_STATE_COMPLETED)
+        {
+          if (empathy_file_get_direction (file) ==
+              EMP_FILE_TRANSFER_DIRECTION_INCOMING)
+            open_enabled = TRUE;
+          else
+            open_enabled = FALSE;
+
+          abort_enabled = FALSE;
+
+        }
+      else if (empathy_file_get_state (file) ==
+        EMP_FILE_TRANSFER_STATE_CANCELED)
+        {
+          open_enabled = FALSE;
+          abort_enabled = FALSE;
+        }
+      else
+        {
+          open_enabled = FALSE;
+          abort_enabled = TRUE;
+        }
+    }
 
-	gtk_widget_set_sensitive (priv->open_button, open_enabled);
-	gtk_widget_set_sensitive (priv->abort_button, abort_enabled);
+  gtk_widget_set_sensitive (priv->open_button, open_enabled);
+  gtk_widget_set_sensitive (priv->abort_button, abort_enabled);
 }
 
 static const gchar *
 get_state_change_reason_description (EmpFileTransferStateChangeReason reason)
 {
-	switch (reason) {
-	case EMP_FILE_TRANSFER_STATE_CHANGE_REASON_NONE:
-		return _("File transfer not completed");
-	case EMP_FILE_TRANSFER_STATE_CHANGE_REASON_LOCAL_STOPPED:
-		return _("You canceled the file transfer");
-	case EMP_FILE_TRANSFER_STATE_CHANGE_REASON_REMOTE_STOPPED:
-		return _("The other participant canceled the file transfer");
-	case EMP_FILE_TRANSFER_STATE_CHANGE_REASON_LOCAL_ERROR:
-		return _("Error while trying to transfer the file");
-	case EMP_FILE_TRANSFER_STATE_CHANGE_REASON_REMOTE_ERROR:
-		return _("The other participant is unable to transfer the file");
-	default:
-		g_return_val_if_reached ("");
-	}
-}
-
-static void
-update_ft_row (EmpathyFTManager *ft_manager,
-	       EmpathyFile      *file)
-{
-	EmpathyFTManagerPriv *priv;
-	GtkTreeRowReference  *row_ref;
-	GtkTreePath          *path;
-	GtkTreeIter           iter;
-	const gchar          *filename;
-	const gchar          *contact_name;
-	gchar                *msg;
-	gchar                *remaining_str;
-	gchar                *first_line_format;
-	gchar                *first_line;
-	gchar                *second_line;
-	guint64               transferred_bytes;
-	guint64               total_size;
-	gint                  remaining = -1;
-	gint                  percent;
-	EmpFileTransferState  state;
-	EmpFileTransferStateChangeReason reason;
-
-	priv = GET_PRIV (ft_manager);
-
-	row_ref = get_row_from_file (ft_manager, file);
-	g_return_if_fail (row_ref != NULL);
-
-	filename = empathy_file_get_filename (file);
-	contact_name = empathy_contact_get_name (empathy_file_get_contact (file));
-	transferred_bytes = empathy_file_get_transferred_bytes (file);
-	total_size = empathy_file_get_size (file);
-	state = empathy_file_get_state (file);
-	reason = empathy_file_get_state_change_reason (file);
-
-	/* The state is changed asynchronously, so we can get local pending
-	 * transfers just before their state is changed to open.
-	 * Just treat them as open file transfers. */
-	if (state == EMP_FILE_TRANSFER_STATE_LOCAL_PENDING)
-		state = EMP_FILE_TRANSFER_STATE_OPEN;
-
-	switch (state)
-	{
-	case EMP_FILE_TRANSFER_STATE_REMOTE_PENDING:
-	case EMP_FILE_TRANSFER_STATE_OPEN:
-		if (empathy_file_get_direction (file) ==
-		    EMP_FILE_TRANSFER_DIRECTION_INCOMING)
-			/* translators: first %s is filename, second %s is the contact name */
-			first_line_format = _("Receiving \"%s\" from %s");
-		else
-			/* translators: first %s is filename, second %s is the contact name */
-			first_line_format = _("Sending \"%s\" to %s");
-		first_line = g_strdup_printf (first_line_format, filename, contact_name);
-
-		if (state == EMP_FILE_TRANSFER_STATE_OPEN) {
-			gchar *total_size_str;
-			gchar *transferred_bytes_str;
-
-			if (total_size == EMPATHY_FILE_UNKNOWN_SIZE)
-				/* translators: the text before the "|" is context to
-				 * help you decide on the correct translation. You MUST
-				 * OMIT it in the translated string. */
-				total_size_str = g_strdup (Q_("file size|Unknown"));
-			else
-				total_size_str = g_format_size_for_display (total_size);
-
-			transferred_bytes_str = g_format_size_for_display (transferred_bytes);
-
-			/* translators: first %s is the transferred size, second %s is
-			 * the total file size */
-			second_line = g_strdup_printf (_("%s of %s"), transferred_bytes_str,
-						       total_size_str);
-			g_free (transferred_bytes_str);
-			g_free (total_size_str);
-		} else {
-			second_line = g_strdup (_("Wating the other participant's response"));
-		}
-
-		remaining = empathy_file_get_remaining_time (file);
-		break;
-
-	case EMP_FILE_TRANSFER_STATE_COMPLETED:
-		if (empathy_file_get_direction (file) ==
-		    EMP_FILE_TRANSFER_DIRECTION_INCOMING)
-			/* translators: first %s is filename, second %s
-			 * is the contact name */
-			first_line = g_strdup_printf (
-				_("\"%s\" received from %s"), filename,
-				contact_name);
-		else
-			/* translators: first %s is filename, second %s
-			 * is the contact name */
-			first_line = g_strdup_printf (
-					_("\"%s\" sent to %s"), filename,
-					contact_name);
-		second_line = g_strdup ("File transfer completed");
-		break;
-
-	case EMP_FILE_TRANSFER_STATE_CANCELED:
-		if (empathy_file_get_direction (file) ==
-		    EMP_FILE_TRANSFER_DIRECTION_INCOMING)
-			/* translators: first %s is filename, second %s
-			 * is the contact name */
-			first_line = g_strdup_printf (
-				_("\"%s\" receiving from %s"), filename,
-				contact_name);
-		else
-			/* translators: first %s is filename, second %s
-			 * is the contact name */
-			first_line = g_strdup_printf (
-					_("\"%s\" sending to %s"), filename,
-					contact_name);
-		second_line = g_strdup_printf (_("File transfer canceled: %s"),
-		    get_state_change_reason_description (reason));
-		break;
-
-	default:
-		g_return_if_reached ();
-	}
-
-	if (total_size != EMPATHY_FILE_UNKNOWN_SIZE)
-		percent = transferred_bytes * 100 / total_size;
-	else
-		percent = -1;
-
-	if (remaining < 0) {
-		if (state == EMP_FILE_TRANSFER_STATE_COMPLETED ||
-		    state == EMP_FILE_TRANSFER_STATE_CANCELED)
-			remaining_str = g_strdup ("");
-		else
-			/* translators: the text before the "|" is context to
-			 * help you decide on the correct translation. You
-			 * MUST OMIT it in the translated string. */
-			remaining_str = g_strdup (Q_("remaining time|Unknown"));
-	} else {
-		remaining_str = format_interval (remaining);
-	}
-
-	msg = g_strdup_printf ("%s\n%s", first_line, second_line);
-
-	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_PERCENT, percent,
-			    COL_MESSAGE, msg,
-			    COL_REMAINING, remaining_str,
-			    -1);
-	gtk_tree_path_free (path);
-
-	g_free (msg);
-	g_free (first_line);
-	g_free (second_line);
-	g_free (remaining_str);
-
-	update_buttons (ft_manager);
-}
-
-static void
-transferred_bytes_changed_cb (EmpathyFile      *file,
-			      GParamSpec       *pspec,
-			      EmpathyFTManager *ft_manager)
-{
-	update_ft_row (ft_manager, file);
-}
-
-static void
-state_changed_cb (EmpathyFile      *file,
-		  GParamSpec       *pspec,
-		  EmpathyFTManager *ft_manager)
-{
-	EmpathyFTManagerPriv *priv;
-	gboolean              remove;
-
-	priv = GET_PRIV (ft_manager);
-
-	switch (empathy_file_get_state (file)) {
-		case EMP_FILE_TRANSFER_STATE_COMPLETED:
-			if (empathy_file_get_direction (file) ==
-			    EMP_FILE_TRANSFER_DIRECTION_INCOMING) {
-				GtkRecentManager *manager;
-				const gchar      *uri;
-
-				manager = gtk_recent_manager_get_default ();
-				uri = g_object_get_data (G_OBJECT (file), "uri");
-				gtk_recent_manager_add_item (manager, uri);
-			}
-
-		case EMP_FILE_TRANSFER_STATE_CANCELED:
-			/* Automatically remove file transfers if the
-			 * window if not visible. */
-			/* FIXME how do the user know if the file transfer
-			 * failed? */
-			remove = !GTK_WIDGET_VISIBLE (priv->window);
-			break;
-
-		default:
-			remove = FALSE;
-			break;
-	}
-
-	if (remove)
-		ft_manager_remove_file_from_list (ft_manager, file);
-	else
-		update_ft_row (ft_manager, file);
-}
-
-static void
-ft_manager_add_file_to_list (EmpathyFTManager *ft_manager,
-			     EmpathyFile      *file)
-{
-	EmpathyFTManagerPriv *priv;
-	GtkTreeRowReference  *row_ref;
-	GtkTreeIter           iter;
-	GtkTreeSelection     *selection;
-	GtkTreePath          *path;
-	GtkIconTheme         *theme;
-	GtkIconInfo          *icon_info;
-	GdkPixbuf            *pixbuf;
-	const gchar          *mime;
-	gchar                *icon_name;
-	gint                  width = 16;
-	gint                  height = 16;
-
-	priv = GET_PRIV (ft_manager);
-
-	gtk_list_store_append (GTK_LIST_STORE (priv->model),
-			       &iter);
-	gtk_list_store_set (GTK_LIST_STORE (priv->model),
-			    &iter, COL_FT_OBJECT, file, -1);
-
-	path =  gtk_tree_model_get_path (GTK_TREE_MODEL (priv->model), &iter);
-	row_ref = gtk_tree_row_reference_new (GTK_TREE_MODEL (priv->model), path);
-	gtk_tree_path_free (path);
-
-	g_object_ref (file);
-	g_hash_table_insert (priv->file_to_row_ref, file, row_ref);
-
-	update_ft_row (ft_manager, file);
-
-	selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
-	gtk_tree_selection_unselect_all (selection);
-	gtk_tree_selection_select_iter (selection, &iter);
-
-	g_signal_connect (file, "notify::state",
-			  G_CALLBACK (state_changed_cb), ft_manager);
-	g_signal_connect (file, "notify::transferred-bytes",
-			  G_CALLBACK (transferred_bytes_changed_cb), ft_manager);
-
-	mime = gnome_vfs_get_mime_type_for_name (empathy_file_get_filename (file));
-	theme = gtk_icon_theme_get_default ();
-	/* FIXME remove the dependency on libgnomeui replacing this function
-	 * with gio/gvfs or copying the code from gtk-recent */
-	icon_name = gnome_icon_lookup (theme, NULL, NULL, NULL, NULL,
-				       mime, GNOME_ICON_LOOKUP_FLAGS_NONE, NULL);
-
-	gtk_icon_size_lookup_for_settings (gtk_widget_get_settings (priv->window),
-					   GTK_ICON_SIZE_MENU, &width, &height);
-	width *= 2;
-
-	icon_info = gtk_icon_theme_lookup_icon (theme, icon_name, width, 0);
-	g_free (icon_name);
-	if (icon_info != NULL) {
-		pixbuf = gdk_pixbuf_new_from_file_at_size
-			(gtk_icon_info_get_filename (icon_info), width, width, NULL);
-		gtk_icon_info_free (icon_info);
-
-		gtk_list_store_set (GTK_LIST_STORE (priv->model),
-				    &iter, COL_IMAGE, pixbuf, -1);
-		if (pixbuf != NULL)
-		{
-			g_object_unref (pixbuf);
-		}
-	}
-
-	gtk_window_present (GTK_WINDOW (priv->window));
-}
-
-static void
-selection_changed (GtkTreeSelection *selection,
-		   EmpathyFTManager *ft_manager)
-{
-	update_buttons (ft_manager);
-}
-
-static void
-progress_cell_data_func (GtkTreeViewColumn *col,
-			 GtkCellRenderer   *renderer,
-			 GtkTreeModel      *model,
-			 GtkTreeIter       *iter,
-			 gpointer           user_data)
-{
-	const gchar *text = NULL;
-	gint         percent;
-
-	gtk_tree_model_get (model, iter,
-			    COL_PERCENT, &percent,
-			    -1);
-
-	if (percent < 0) {
-		percent = 0;
-		/* Translators: The text before the "|" is context to help you
-		 * decide on the correct translation. You MUST OMIT it in the
-		 * translated string. */
-		text = Q_("file transfer percent|Unknown");
-	}
-
-	g_object_set (renderer, "text", text, "value", percent, NULL);
-}
-
-static void
-ft_manager_clear_foreach_cb (gpointer key,
-			     gpointer value,
-			     gpointer user_data)
-{
-	GSList     **list = user_data;
-	EmpathyFile *file = key;
-
-	switch (empathy_file_get_state (file)) {
-		case EMP_FILE_TRANSFER_STATE_COMPLETED:
-		case EMP_FILE_TRANSFER_STATE_CANCELED:
-			*list = g_slist_append (*list, file);
-			break;
-		default:
-			break;
-	}
+  switch (reason)
+    {
+      case EMP_FILE_TRANSFER_STATE_CHANGE_REASON_NONE:
+        return _("File transfer not completed");
+      case EMP_FILE_TRANSFER_STATE_CHANGE_REASON_LOCAL_STOPPED:
+        return _("You canceled the file transfer");
+      case EMP_FILE_TRANSFER_STATE_CHANGE_REASON_REMOTE_STOPPED:
+        return _("The other participant canceled the file transfer");
+      case EMP_FILE_TRANSFER_STATE_CHANGE_REASON_LOCAL_ERROR:
+        return _("Error while trying to transfer the file");
+      case EMP_FILE_TRANSFER_STATE_CHANGE_REASON_REMOTE_ERROR:
+        return _("The other participant is unable to transfer the file");
+      default:
+        g_return_val_if_reached ("");
+    }
+}
+
+static void
+update_ft_row (EmpathyFTManager *ft_manager, EmpathyFile *file)
+{
+  EmpathyFTManagerPriv *priv;
+  GtkTreeRowReference  *row_ref;
+  GtkTreePath *path;
+  GtkTreeIter iter;
+  const gchar *filename;
+  const gchar *contact_name;
+  gchar *msg;
+  gchar *remaining_str;
+  gchar *first_line_format;
+  gchar *first_line;
+  gchar *second_line;
+  guint64 transferred_bytes;
+  guint64 total_size;
+  gint remaining = -1;
+  gint percent;
+  EmpFileTransferState state;
+  EmpFileTransferStateChangeReason reason;
+
+  priv = GET_PRIV (ft_manager);
+
+  row_ref = get_row_from_file (ft_manager, file);
+  g_return_if_fail (row_ref != NULL);
+
+  filename = empathy_file_get_filename (file);
+  contact_name = empathy_contact_get_name (empathy_file_get_contact (file));
+  transferred_bytes = empathy_file_get_transferred_bytes (file);
+  total_size = empathy_file_get_size (file);
+  state = empathy_file_get_state (file);
+  reason = empathy_file_get_state_change_reason (file);
+
+  /* The state is changed asynchronously, so we can get local pending
+   * transfers just before their state is changed to open.
+   * Just treat them as open file transfers. */
+  if (state == EMP_FILE_TRANSFER_STATE_LOCAL_PENDING)
+    state = EMP_FILE_TRANSFER_STATE_OPEN;
+
+  switch (state)
+    {
+      case EMP_FILE_TRANSFER_STATE_REMOTE_PENDING:
+      case EMP_FILE_TRANSFER_STATE_OPEN:
+        if (empathy_file_get_direction (file) ==
+            EMP_FILE_TRANSFER_DIRECTION_INCOMING)
+          /* translators: first %s is filename, second %s is the contact name */
+          first_line_format = _("Receiving \"%s\" from %s");
+        else
+          /* translators: first %s is filename, second %s is the contact name */
+          first_line_format = _("Sending \"%s\" to %s");
+
+        first_line = g_strdup_printf (first_line_format, filename, contact_name);
+
+        if (state == EMP_FILE_TRANSFER_STATE_OPEN)
+          {
+            gchar *total_size_str;
+            gchar *transferred_bytes_str;
+
+            if (total_size == EMPATHY_FILE_UNKNOWN_SIZE)
+              /* translators: the text before the "|" is context to
+               * help you decide on the correct translation. You MUST
+               * OMIT it in the translated string. */
+              total_size_str = g_strdup (Q_("file size|Unknown"));
+            else
+              total_size_str = g_format_size_for_display (total_size);
+
+            transferred_bytes_str = g_format_size_for_display (transferred_bytes);
+
+            /* translators: first %s is the transferred size, second %s is
+             * the total file size */
+            second_line = g_strdup_printf (_("%s of %s"), transferred_bytes_str,
+                total_size_str);
+            g_free (transferred_bytes_str);
+            g_free (total_size_str);
+
+          }
+        else
+          second_line = g_strdup (_("Wating the other participant's response"));
+
+      remaining = empathy_file_get_remaining_time (file);
+      break;
+
+    case EMP_FILE_TRANSFER_STATE_COMPLETED:
+      if (empathy_file_get_direction (file) ==
+          EMP_FILE_TRANSFER_DIRECTION_INCOMING)
+        /* translators: first %s is filename, second %s
+         * is the contact name */
+        first_line = g_strdup_printf (
+            _("\"%s\" received from %s"), filename,
+            contact_name);
+      else
+        /* translators: first %s is filename, second %s
+         * is the contact name */
+        first_line = g_strdup_printf (
+            _("\"%s\" sent to %s"), filename,
+            contact_name);
+
+      second_line = g_strdup ("File transfer completed");
+
+      break;
+
+    case EMP_FILE_TRANSFER_STATE_CANCELED:
+      if (empathy_file_get_direction (file) ==
+          EMP_FILE_TRANSFER_DIRECTION_INCOMING)
+        /* translators: first %s is filename, second %s
+         * is the contact name */
+        first_line = g_strdup_printf (
+            _("\"%s\" receiving from %s"), filename,
+            contact_name);
+      else
+        /* translators: first %s is filename, second %s
+         * is the contact name */
+        first_line = g_strdup_printf (
+            _("\"%s\" sending to %s"), filename,
+            contact_name);
+
+      second_line = g_strdup_printf (_("File transfer canceled: %s"),
+          get_state_change_reason_description (reason));
+
+      break;
+
+    default:
+      g_return_if_reached ();
+
+    }
+
+  if (total_size != EMPATHY_FILE_UNKNOWN_SIZE)
+    percent = transferred_bytes * 100 / total_size;
+  else
+    percent = -1;
+
+  if (remaining < 0)
+    {
+      if (state == EMP_FILE_TRANSFER_STATE_COMPLETED ||
+          state == EMP_FILE_TRANSFER_STATE_CANCELED)
+        remaining_str = g_strdup ("");
+      else
+        /* translators: the text before the "|" is context to
+         * help you decide on the correct translation. You
+         * MUST OMIT it in the translated string. */
+        remaining_str = g_strdup (Q_("remaining time|Unknown"));
+    }
+  else
+    remaining_str = format_interval (remaining);
+
+  msg = g_strdup_printf ("%s\n%s", first_line, second_line);
+
+  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_PERCENT, percent,
+      COL_MESSAGE, msg,
+      COL_REMAINING, remaining_str,
+      -1);
+
+  gtk_tree_path_free (path);
+
+  g_free (msg);
+  g_free (first_line);
+  g_free (second_line);
+  g_free (remaining_str);
+
+  update_buttons (ft_manager);
+}
+
+static void
+transferred_bytes_changed_cb (EmpathyFile *file, GParamSpec *pspec,
+    EmpathyFTManager *ft_manager)
+{
+  update_ft_row (ft_manager, file);
+}
+
+static void
+state_changed_cb (EmpathyFile *file, GParamSpec *pspec,
+    EmpathyFTManager *ft_manager)
+{
+  EmpathyFTManagerPriv *priv;
+  gboolean remove;
+
+  priv = GET_PRIV (ft_manager);
+
+  switch (empathy_file_get_state (file))
+    {
+      case EMP_FILE_TRANSFER_STATE_COMPLETED:
+        if (empathy_file_get_direction (file) ==
+            EMP_FILE_TRANSFER_DIRECTION_INCOMING)
+          {
+            GtkRecentManager *manager;
+            const gchar *uri;
+
+            manager = gtk_recent_manager_get_default ();
+            uri = g_object_get_data (G_OBJECT (file), "uri");
+            gtk_recent_manager_add_item (manager, uri);
+         }
+
+      case EMP_FILE_TRANSFER_STATE_CANCELED:
+        /* Automatically remove file transfers if the
+         * window if not visible. */
+        /* FIXME how do the user know if the file transfer
+         * failed? */
+        remove = !GTK_WIDGET_VISIBLE (priv->window);
+        break;
+
+      default:
+        remove = FALSE;
+        break;
+    }
+
+  if (remove)
+    ft_manager_remove_file_from_list (ft_manager, file);
+  else
+    update_ft_row (ft_manager, file);
+}
+
+static void
+ft_manager_add_file_to_list (EmpathyFTManager *ft_manager, EmpathyFile *file)
+{
+  EmpathyFTManagerPriv *priv;
+  GtkTreeRowReference  *row_ref;
+  GtkTreeIter iter;
+  GtkTreeSelection *selection;
+  GtkTreePath *path;
+  GtkIconTheme *theme;
+  GtkIconInfo *icon_info;
+  GdkPixbuf *pixbuf;
+  const gchar *mime;
+  gchar *icon_name;
+  gint width = 16;
+  gint height = 16;
+
+  priv = GET_PRIV (ft_manager);
+
+  gtk_list_store_append (GTK_LIST_STORE (priv->model), &iter);
+  gtk_list_store_set (GTK_LIST_STORE (priv->model), &iter, COL_FT_OBJECT,
+      file, -1);
+
+  path =  gtk_tree_model_get_path (GTK_TREE_MODEL (priv->model), &iter);
+  row_ref = gtk_tree_row_reference_new (GTK_TREE_MODEL (priv->model), path);
+  gtk_tree_path_free (path);
+
+  g_object_ref (file);
+  g_hash_table_insert (priv->file_to_row_ref, file, row_ref);
+
+  update_ft_row (ft_manager, file);
+
+  selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
+  gtk_tree_selection_unselect_all (selection);
+  gtk_tree_selection_select_iter (selection, &iter);
+
+  g_signal_connect (file, "notify::state",
+      G_CALLBACK (state_changed_cb), ft_manager);
+  g_signal_connect (file, "notify::transferred-bytes",
+      G_CALLBACK (transferred_bytes_changed_cb), ft_manager);
+
+  mime = gnome_vfs_get_mime_type_for_name (empathy_file_get_filename (file));
+  theme = gtk_icon_theme_get_default ();
+  /* FIXME remove the dependency on libgnomeui replacing this function
+   * with gio/gvfs or copying the code from gtk-recent */
+  icon_name = gnome_icon_lookup (theme, NULL, NULL, NULL, NULL,
+      mime, GNOME_ICON_LOOKUP_FLAGS_NONE, NULL);
+
+  gtk_icon_size_lookup_for_settings (gtk_widget_get_settings (priv->window),
+      GTK_ICON_SIZE_MENU, &width, &height);
+  width *= 2;
+
+  icon_info = gtk_icon_theme_lookup_icon (theme, icon_name, width, 0);
+  g_free (icon_name);
+  if (icon_info != NULL)
+    {
+      pixbuf = gdk_pixbuf_new_from_file_at_size
+          (gtk_icon_info_get_filename (icon_info), width, width, NULL);
+      gtk_icon_info_free (icon_info);
+
+      gtk_list_store_set (GTK_LIST_STORE (priv->model),
+          &iter, COL_IMAGE, pixbuf, -1);
+      if (pixbuf != NULL)
+        {
+          g_object_unref (pixbuf);
+        }
+    }
+
+  gtk_window_present (GTK_WINDOW (priv->window));
+}
+
+static void
+selection_changed (GtkTreeSelection *selection, EmpathyFTManager *ft_manager)
+{
+  update_buttons (ft_manager);
+}
+
+static void
+progress_cell_data_func (GtkTreeViewColumn *col, GtkCellRenderer *renderer,
+    GtkTreeModel *model, GtkTreeIter *iter, gpointer user_data)
+{
+  const gchar *text = NULL;
+  gint percent;
+
+  gtk_tree_model_get (model, iter, COL_PERCENT, &percent, -1);
+
+  if (percent < 0)
+    {
+      percent = 0;
+      /* Translators: The text before the "|" is context to help you
+       * decide on the correct translation. You MUST OMIT it in the
+       * translated string. */
+      text = Q_("file transfer percent|Unknown");
+    }
+
+  g_object_set (renderer, "text", text, "value", percent, NULL);
+}
+
+static void
+ft_manager_clear_foreach_cb (gpointer key, gpointer value, gpointer user_data)
+{
+  GSList **list = user_data;
+  EmpathyFile *file = key;
+
+  switch (empathy_file_get_state (file))
+    {
+      case EMP_FILE_TRANSFER_STATE_COMPLETED:
+      case EMP_FILE_TRANSFER_STATE_CANCELED:
+        *list = g_slist_append (*list, file);
+        break;
+      default:
+        break;
+    }
 }
 
 static void
 ft_manager_clear (EmpathyFTManager *ft_manager)
 {
-	EmpathyFTManagerPriv *priv;
-	GSList               *closed_files = NULL;
-	GSList               *l;
+  EmpathyFTManagerPriv *priv;
+  GSList *closed_files = NULL;
+  GSList *l;
 
-	priv = GET_PRIV (ft_manager);
+  priv = GET_PRIV (ft_manager);
 
-	DEBUG ("Clearing file transfer list");
+  DEBUG ("Clearing file transfer list");
 
-	g_hash_table_foreach (priv->file_to_row_ref, ft_manager_clear_foreach_cb,
-			      &closed_files);
+  g_hash_table_foreach (priv->file_to_row_ref, ft_manager_clear_foreach_cb,
+      &closed_files);
 
-	for (l = closed_files; l; l = l->next) {
-		ft_manager_remove_file_from_list (ft_manager, l->data);
-	}
+  for (l = closed_files; l; l = l->next)
+    {
+      ft_manager_remove_file_from_list (ft_manager, l->data);
+    }
 
-	g_slist_free (closed_files);
+  g_slist_free (closed_files);
 }
 
 static gboolean
-ft_manager_delete_event_cb (GtkWidget        *widget,
-			    GdkEvent         *event,
-			    EmpathyFTManager *ft_manager)
-{
-	EmpathyFTManagerPriv *priv;
-
-	priv = GET_PRIV (ft_manager);
-
-	ft_manager_clear (ft_manager);
-	if (g_hash_table_size (priv->file_to_row_ref) == 0) {
-		DEBUG ("Destroying window");
-		empathy_ft_manager_finalize (G_OBJECT (ft_manager));
-		manager_p = NULL;
-		return FALSE;
-	} else {
-		DEBUG ("Hiding window");
-		gtk_widget_hide (widget);
-		return TRUE;
-	}
+ft_manager_delete_event_cb (GtkWidget *widget, GdkEvent *event,
+    EmpathyFTManager *ft_manager)
+{
+  EmpathyFTManagerPriv *priv;
 
+  priv = GET_PRIV (ft_manager);
+
+  ft_manager_clear (ft_manager);
+  if (g_hash_table_size (priv->file_to_row_ref) == 0)
+    {
+      DEBUG ("Destroying window");
+      empathy_ft_manager_finalize (G_OBJECT (ft_manager));
+      manager_p = NULL;
+      return FALSE;
+    }
+  else
+    {
+      DEBUG ("Hiding window");
+      gtk_widget_hide (widget);
+      return TRUE;
+    }
 }
 
 static gboolean
 ft_manager_save_geometry_timeout_cb (EmpathyFTManager *ft_manager)
 {
-	EmpathyFTManagerPriv *priv;
-	gint                  x, y, w, h;
+  EmpathyFTManagerPriv *priv;
+  gint x, y, w, h;
 
-	priv = GET_PRIV (ft_manager);
+  priv = GET_PRIV (ft_manager);
 
-	gtk_window_get_size (GTK_WINDOW (priv->window), &w, &h);
-	gtk_window_get_position (GTK_WINDOW (priv->window), &x, &y);
+  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);
+  empathy_geometry_save ("ft-manager", x, y, w, h);
 
-	priv->save_geometry_id = 0;
+  priv->save_geometry_id = 0;
 
-	return FALSE;
+  return FALSE;
 }
 
 static gboolean
-ft_manager_configure_event_cb (GtkWidget         *widget,
-			       GdkEventConfigure *event,
-			       EmpathyFTManager  *ft_manager)
+ft_manager_configure_event_cb (GtkWidget *widget, GdkEventConfigure *event,
+    EmpathyFTManager *ft_manager)
 {
-	EmpathyFTManagerPriv *priv;
+  EmpathyFTManagerPriv *priv;
 
-	priv = GET_PRIV (ft_manager);
+  priv = GET_PRIV (ft_manager);
 
-	if (priv->save_geometry_id != 0) {
-		g_source_remove (priv->save_geometry_id);
-	}
+  if (priv->save_geometry_id != 0)
+    g_source_remove (priv->save_geometry_id);
 
-	priv->save_geometry_id =
-		g_timeout_add (500,
-			       (GSourceFunc) ft_manager_save_geometry_timeout_cb,
-			       ft_manager);
+  priv->save_geometry_id = g_timeout_add (500,
+      (GSourceFunc) ft_manager_save_geometry_timeout_cb, ft_manager);
 
-	return FALSE;
+  return FALSE;
 }
 
 static void
 ft_manager_build_ui (EmpathyFTManager *ft_manager)
 {
-	EmpathyFTManagerPriv *priv;
-	gint                  x, y, w, h;
-	GtkListStore         *liststore;
-	GtkTreeViewColumn    *column;
-	GtkCellRenderer      *renderer;
-	GtkTreeSelection     *selection;
-	gchar                *filename;
-
-	priv = GET_PRIV (ft_manager);
-
-	/* Keep this object alive until we have the dialog window */
-	g_object_ref (ft_manager);
-
-	filename = empathy_file_lookup ("empathy-ft-manager.glade",
-					"libempathy-gtk");
-	empathy_glade_get_file (filename,
-			        "ft_manager_dialog",
-			        NULL,
-			        "ft_manager_dialog", &priv->window,
-			        "ft_list", &priv->treeview,
-			        "open_button", &priv->open_button,
-			        "abort_button", &priv->abort_button,
-			        NULL);
-	g_free (filename);
-
-	g_signal_connect (priv->window, "response",
-			  G_CALLBACK (ft_manager_response_cb), ft_manager);
-	g_signal_connect (priv->window, "delete-event",
-			  G_CALLBACK (ft_manager_delete_event_cb), ft_manager);
-	g_signal_connect (priv->window, "configure-event",
-			  G_CALLBACK (ft_manager_configure_event_cb), ft_manager);
-
-	gtk_window_set_icon_name (GTK_WINDOW (priv->window), EMPATHY_IMAGE_DOCUMENT_SEND);
-
-	/* 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 glade file if we don't have
-		 * good w, h geometry. */
-		gtk_window_resize (GTK_WINDOW (priv->window), w, h);
-	}
-
-	gtk_tree_selection_set_mode (gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview)),
-				     GTK_SELECTION_BROWSE);
-
-	liststore = gtk_list_store_new (5,
-					G_TYPE_INT,
-					GDK_TYPE_PIXBUF,
-					G_TYPE_STRING,
-					G_TYPE_STRING,
-					G_TYPE_OBJECT);
-
-	gtk_tree_view_set_model (GTK_TREE_VIEW(priv->treeview),
-				 GTK_TREE_MODEL (liststore));
-	g_object_unref (liststore);
-	gtk_tree_view_set_headers_visible (GTK_TREE_VIEW(priv->treeview),
-					   TRUE);
-
-	/* Icon and filename column*/
-	column = gtk_tree_view_column_new ();
-	gtk_tree_view_column_set_title (column, _("File"));
-	renderer = gtk_cell_renderer_pixbuf_new ();
-	g_object_set (renderer, "xpad", 3, NULL);
-	gtk_tree_view_column_pack_start (column, renderer, FALSE);
-	gtk_tree_view_column_set_attributes (column, renderer,
-					    "pixbuf", COL_IMAGE,
-					    NULL);
-	renderer = gtk_cell_renderer_text_new ();
-	g_object_set (renderer, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
-	gtk_tree_view_column_pack_start (column, renderer, TRUE);
-	gtk_tree_view_column_set_attributes (column, renderer,
-					     "text", COL_MESSAGE,
-					     NULL);
-	gtk_tree_view_insert_column (GTK_TREE_VIEW (priv->treeview), column,
-				     FILE_COL_POS);
-	gtk_tree_view_column_set_expand (column, TRUE);
-	gtk_tree_view_column_set_resizable (column, TRUE);
-	gtk_tree_view_column_set_sort_column_id (column, COL_MESSAGE);
-	gtk_tree_view_column_set_spacing (column, 3);
-
-	/* Progress column */
-	renderer = gtk_cell_renderer_progress_new ();
-	g_object_set (renderer, "xalign", 0.5, NULL);
-	gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW(priv->treeview),
-						     PROGRESS_COL_POS, _("%"),
-						     renderer,
-						     NULL);
-	column = gtk_tree_view_get_column (GTK_TREE_VIEW(priv->treeview),
-					   PROGRESS_COL_POS);
-	gtk_tree_view_column_set_cell_data_func(column, renderer,
-						progress_cell_data_func,
-						NULL, NULL);
-	gtk_tree_view_column_set_sort_column_id (column, COL_PERCENT);
-
-	/* Remaining time column */
-	renderer = gtk_cell_renderer_text_new ();
-	g_object_set (renderer, "xalign", 0.5, NULL);
-	gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW(priv->treeview),
-						     REMAINING_COL_POS, _("Remaining"),
-						     renderer,
-						     "text", COL_REMAINING,
-						     NULL);
-
-	column = gtk_tree_view_get_column (GTK_TREE_VIEW(priv->treeview),
-					   REMAINING_COL_POS);
-	gtk_tree_view_column_set_sort_column_id (column, COL_REMAINING);
+  EmpathyFTManagerPriv *priv;
+  gint x, y, w, h;
+  GtkListStore *liststore;
+  GtkTreeViewColumn *column;
+  GtkCellRenderer *renderer;
+  GtkTreeSelection *selection;
+  gchar *filename;
+
+  priv = GET_PRIV (ft_manager);
+
+  /* Keep this object alive until we have the dialog window */
+  g_object_ref (ft_manager);
+
+  filename = empathy_file_lookup ("empathy-ft-manager.glade",
+      "libempathy-gtk");
+  empathy_glade_get_file (filename,
+      "ft_manager_dialog", NULL,
+      "ft_manager_dialog", &priv->window,
+      "ft_list", &priv->treeview,
+      "open_button", &priv->open_button,
+      "abort_button", &priv->abort_button,
+      NULL);
+  g_free (filename);
+
+  g_signal_connect (priv->window, "response",
+      G_CALLBACK (ft_manager_response_cb), ft_manager);
+  g_signal_connect (priv->window, "delete-event",
+      G_CALLBACK (ft_manager_delete_event_cb), ft_manager);
+  g_signal_connect (priv->window, "configure-event",
+      G_CALLBACK (ft_manager_configure_event_cb), ft_manager);
+
+  gtk_window_set_icon_name (GTK_WINDOW (priv->window), EMPATHY_IMAGE_DOCUMENT_SEND);
+
+  /* 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 glade file if we don't have
+       * good w, h geometry. */
+      gtk_window_resize (GTK_WINDOW (priv->window), w, h);
+    }
+
+  gtk_tree_selection_set_mode (gtk_tree_view_get_selection (GTK_TREE_VIEW (
+      priv->treeview)), GTK_SELECTION_BROWSE);
+
+  liststore = gtk_list_store_new (5, G_TYPE_INT, GDK_TYPE_PIXBUF,
+      G_TYPE_STRING, G_TYPE_STRING, G_TYPE_OBJECT);
+
+  gtk_tree_view_set_model (GTK_TREE_VIEW(priv->treeview),
+      GTK_TREE_MODEL (liststore));
+  g_object_unref (liststore);
+  gtk_tree_view_set_headers_visible (GTK_TREE_VIEW(priv->treeview), TRUE);
+
+  /* Icon and filename column*/
+  column = gtk_tree_view_column_new ();
+  gtk_tree_view_column_set_title (column, _("File"));
+  renderer = gtk_cell_renderer_pixbuf_new ();
+  g_object_set (renderer, "xpad", 3, NULL);
+  gtk_tree_view_column_pack_start (column, renderer, FALSE);
+  gtk_tree_view_column_set_attributes (column, renderer,
+      "pixbuf", COL_IMAGE,
+      NULL);
+  renderer = gtk_cell_renderer_text_new ();
+  g_object_set (renderer, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
+  gtk_tree_view_column_pack_start (column, renderer, TRUE);
+  gtk_tree_view_column_set_attributes (column, renderer,
+      "text", COL_MESSAGE,
+      NULL);
+  gtk_tree_view_insert_column (GTK_TREE_VIEW (priv->treeview), column,
+      FILE_COL_POS);
+  gtk_tree_view_column_set_expand (column, TRUE);
+  gtk_tree_view_column_set_resizable (column, TRUE);
+  gtk_tree_view_column_set_sort_column_id (column, COL_MESSAGE);
+  gtk_tree_view_column_set_spacing (column, 3);
+
+  /* Progress column */
+  renderer = gtk_cell_renderer_progress_new ();
+  g_object_set (renderer, "xalign", 0.5, NULL);
+  gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW(priv->treeview),
+      PROGRESS_COL_POS, _("%"),
+      renderer,
+      NULL);
+  column = gtk_tree_view_get_column (GTK_TREE_VIEW(priv->treeview),
+      PROGRESS_COL_POS);
+  gtk_tree_view_column_set_cell_data_func(column, renderer,
+      progress_cell_data_func,
+      NULL, NULL);
+  gtk_tree_view_column_set_sort_column_id (column, COL_PERCENT);
+
+  /* Remaining time column */
+  renderer = gtk_cell_renderer_text_new ();
+  g_object_set (renderer, "xalign", 0.5, NULL);
+  gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW(priv->treeview),
+      REMAINING_COL_POS, _("Remaining"),
+      renderer,
+      "text", COL_REMAINING,
+      NULL);
+
+  column = gtk_tree_view_get_column (GTK_TREE_VIEW(priv->treeview),
+      REMAINING_COL_POS);
+  gtk_tree_view_column_set_sort_column_id (column, COL_REMAINING);
 
-	gtk_tree_view_set_enable_search (GTK_TREE_VIEW (priv->treeview), FALSE);
+  gtk_tree_view_set_enable_search (GTK_TREE_VIEW (priv->treeview), FALSE);
 
-	priv->model = GTK_TREE_MODEL (liststore);
+  priv->model = GTK_TREE_MODEL (liststore);
 
-	selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
-	g_signal_connect (selection, "changed", G_CALLBACK (selection_changed), ft_manager);
+  selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
+  g_signal_connect (selection, "changed", G_CALLBACK (selection_changed), ft_manager);
 }
 
 static void
 ft_manager_remove_file_from_list (EmpathyFTManager *ft_manager,
-				  EmpathyFile      *file)
+    EmpathyFile *file)
 {
-	EmpathyFTManagerPriv *priv;
-	GtkTreeRowReference  *row_ref;
-	GtkTreePath          *path = NULL;
-	GtkTreeIter           iter, iter2;
-
-	priv = GET_PRIV (ft_manager);
-
-	row_ref = get_row_from_file (ft_manager, file);
-	g_return_if_fail (row_ref);
-
-	DEBUG ("Removing file transfer from window: contact=%s, filename=%s",
-	       empathy_contact_get_name (empathy_file_get_contact (file)),
-	       empathy_file_get_filename (file));
-
-	/* Get the row we'll select after removal ("smart" selection) */
-
-	path = gtk_tree_row_reference_get_path (row_ref);
-	gtk_tree_model_get_iter (GTK_TREE_MODEL (priv->model),
-				 &iter, path);
-	gtk_tree_path_free (path);
-
-	row_ref = NULL;
-	iter2 = iter;
-	if (gtk_tree_model_iter_next (GTK_TREE_MODEL (priv->model), &iter))
-	{
-		path = gtk_tree_model_get_path  (GTK_TREE_MODEL (priv->model), &iter);
-		row_ref = gtk_tree_row_reference_new (GTK_TREE_MODEL (priv->model), path);
-	}
-	else
-	{
-		path = gtk_tree_model_get_path (GTK_TREE_MODEL (priv->model), &iter2);
-		if (gtk_tree_path_prev (path))
-		{
-			row_ref = gtk_tree_row_reference_new (GTK_TREE_MODEL (priv->model),
-							      path);
-		}
-	}
-	gtk_tree_path_free (path);
-
-	/* Removal */
-
-	gtk_list_store_remove (GTK_LIST_STORE (priv->model), &iter2);
-	g_hash_table_remove (priv->file_to_row_ref,
-			     file);
-	g_object_unref (file);
-
-	/* Actual selection */
-
-	if (row_ref != NULL)
-	{
-		path = gtk_tree_row_reference_get_path (row_ref);
-		if (path != NULL)
-		{
-			gtk_tree_view_set_cursor (GTK_TREE_VIEW (priv->treeview),
-						  path, NULL, FALSE);
-			gtk_tree_path_free (path);
-		}
-		gtk_tree_row_reference_free (row_ref);
-	}
+  EmpathyFTManagerPriv *priv;
+  GtkTreeRowReference *row_ref;
+  GtkTreePath *path = NULL;
+  GtkTreeIter iter, iter2;
+
+  priv = GET_PRIV (ft_manager);
+
+  row_ref = get_row_from_file (ft_manager, file);
+  g_return_if_fail (row_ref);
+
+  DEBUG ("Removing file transfer from window: contact=%s, filename=%s",
+      empathy_contact_get_name (empathy_file_get_contact (file)),
+      empathy_file_get_filename (file));
+
+  /* Get the row we'll select after removal ("smart" selection) */
+
+  path = gtk_tree_row_reference_get_path (row_ref);
+  gtk_tree_model_get_iter (GTK_TREE_MODEL (priv->model),
+      &iter, path);
+  gtk_tree_path_free (path);
+
+  row_ref = NULL;
+  iter2 = iter;
+  if (gtk_tree_model_iter_next (GTK_TREE_MODEL (priv->model), &iter))
+    {
+      path = gtk_tree_model_get_path  (GTK_TREE_MODEL (priv->model), &iter);
+      row_ref = gtk_tree_row_reference_new (GTK_TREE_MODEL (priv->model), path);
+    }
+  else
+    {
+      path = gtk_tree_model_get_path (GTK_TREE_MODEL (priv->model), &iter2);
+      if (gtk_tree_path_prev (path))
+        {
+          row_ref = gtk_tree_row_reference_new (GTK_TREE_MODEL (priv->model),
+              path);
+        }
+    }
+  gtk_tree_path_free (path);
+
+  /* Removal */
+
+  gtk_list_store_remove (GTK_LIST_STORE (priv->model), &iter2);
+  g_hash_table_remove (priv->file_to_row_ref, file);
+  g_object_unref (file);
+
+  /* Actual selection */
+
+  if (row_ref != NULL)
+    {
+      path = gtk_tree_row_reference_get_path (row_ref);
+      if (path != NULL)
+        {
+          gtk_tree_view_set_cursor (GTK_TREE_VIEW (priv->treeview),
+              path, NULL, FALSE);
+          gtk_tree_path_free (path);
+        }
+      gtk_tree_row_reference_free (row_ref);
+    }
+
 }
 
 static void
 ft_manager_open (EmpathyFTManager *ft_manager)
 {
-	EmpathyFTManagerPriv *priv;
-	GValue                val = {0, };
-	GtkTreeSelection     *selection;
-	GtkTreeIter           iter;
-	GtkTreeModel         *model;
-	EmpathyFile          *file;
-	const gchar          *uri;
-
-	priv = GET_PRIV (ft_manager);
-
-	selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
-	
-	if (!gtk_tree_selection_get_selected (selection, &model, &iter))
-		return;
-
-	gtk_tree_model_get_value (model, &iter, COL_FT_OBJECT, &val);
-
-	file = g_value_get_object (&val);
-	g_return_if_fail (file != NULL);
-
-	uri = g_object_get_data (G_OBJECT (file), "uri");
-	DEBUG ("Opening URI: %s", uri);
-	empathy_url_show (uri);
-}
+  EmpathyFTManagerPriv *priv;
+  GValue val = {0, };
+  GtkTreeSelection *selection;
+  GtkTreeIter iter;
+  GtkTreeModel *model;
+  EmpathyFile *file;
+  const gchar *uri;
 
-static void
-ft_manager_stop (EmpathyFTManager *ft_manager)
-{
-	EmpathyFTManagerPriv *priv;
-	GValue                val = {0, };
-	GtkTreeSelection     *selection;
-	GtkTreeIter           iter;
-	GtkTreeModel         *model;
-	EmpathyFile          *file;
-
-	priv = GET_PRIV (ft_manager);
-
-	selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
-	
-	if (!gtk_tree_selection_get_selected (selection, &model, &iter))
-		return;
-
-	gtk_tree_model_get_value (model, &iter, COL_FT_OBJECT, &val);
-
-	file = g_value_get_object (&val);
-	g_return_if_fail (file != NULL);
-
-	DEBUG ("Stopping file transfer: contact=%s, filename=%s",
-	       empathy_contact_get_name (empathy_file_get_contact (file)),
-	       empathy_file_get_filename (file));
-
-	empathy_file_cancel (file);
-
-	g_value_unset (&val);
-}
+  priv = GET_PRIV (ft_manager);
 
-static void
-ft_manager_response_cb (GtkWidget        *dialog,
-			gint              response,
-			EmpathyFTManager *ft_manager)
-{
-	switch (response)
-	{
-	case RESPONSE_CLEAR:
-		ft_manager_clear (ft_manager);
-		break;
-	case RESPONSE_OPEN:
-		ft_manager_open (ft_manager);
-		break;
-	case RESPONSE_STOP:
-		ft_manager_stop (ft_manager);
-		break;
-	}
-}
+  selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
 
-/*
- * Receiving files
- */
+  if (!gtk_tree_selection_get_selected (selection, &model, &iter))
+    return;
 
-typedef struct {
-	EmpathyFTManager *ft_manager;
-	EmpathyFile      *file;
-} ReceiveResponseData;
+  gtk_tree_model_get_value (model, &iter, COL_FT_OBJECT, &val);
 
-static void
-free_receive_response_data (ReceiveResponseData *response_data)
-{
-	if (!response_data)
-		return;
+  file = g_value_get_object (&val);
+  g_return_if_fail (file != NULL);
 
-	g_object_unref (response_data->file);
-	g_object_unref (response_data->ft_manager);
-	g_free (response_data);
+  uri = g_object_get_data (G_OBJECT (file), "uri");
+  DEBUG ("Opening URI: %s", uri);
+  empathy_url_show (uri);
 }
 
 static void
-ft_manager_save_dialog_response_cb (GtkDialog           *widget,
-				    gint                 response_id,
-				    ReceiveResponseData *response_data)
+ft_manager_stop (EmpathyFTManager *ft_manager)
 {
-	if (response_id == GTK_RESPONSE_OK) {
-		gchar *uri;
-		gchar *folder;
+  EmpathyFTManagerPriv *priv;
+  GValue                val = {0, };
+  GtkTreeSelection     *selection;
+  GtkTreeIter           iter;
+  GtkTreeModel         *model;
+  EmpathyFile          *file;
 
-		uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (widget));
+  priv = GET_PRIV (ft_manager);
 
-		if (uri) {
-			GFile         *file;
-			GOutputStream *out_stream;
-			gchar         *filename;
-			GError        *error = NULL;
+  selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
 
-			file = g_file_new_for_uri (uri);
-			out_stream = G_OUTPUT_STREAM (g_file_replace (file, NULL,
-								      FALSE, 0,
-								      NULL, &error));
+  if (!gtk_tree_selection_get_selected (selection, &model, &iter))
+    return;
 
-			if (error) {
-				g_warning ("Error with opening file to write to: %s",
-					error->message ? error->message : "no error");
-				g_error_free (error);
-				return;
-			}
+  gtk_tree_model_get_value (model, &iter, COL_FT_OBJECT, &val);
 
-			empathy_file_set_output_stream (response_data->file, out_stream);
+  file = g_value_get_object (&val);
+  g_return_if_fail (file != NULL);
 
-			g_object_set_data_full (G_OBJECT (response_data->file),
-						"uri", uri, g_free);
+  DEBUG ("Stopping file transfer: contact=%s, filename=%s",
+      empathy_contact_get_name (empathy_file_get_contact (file)),
+      empathy_file_get_filename (file));
 
-			filename = g_file_get_basename (file);
-			empathy_file_set_filename (response_data->file, filename);
+  empathy_file_cancel (file);
+
+  g_value_unset (&val);
+}
+
+static void
+ft_manager_response_cb (GtkWidget *dialog, gint response,
+    EmpathyFTManager *ft_manager)
+{
+  switch (response)
+    {
+      case RESPONSE_CLEAR:
+        ft_manager_clear (ft_manager);
+        break;
+      case RESPONSE_OPEN:
+        ft_manager_open (ft_manager);
+        break;
+      case RESPONSE_STOP:
+        ft_manager_stop (ft_manager);
+        break;
+    }
+}
 
-			empathy_file_accept (response_data->file);
+/*
+ * Receiving files
+ */
 
-			ft_manager_add_file_to_list (response_data->ft_manager,
-						     response_data->file);
+typedef struct {
+  EmpathyFTManager *ft_manager;
+  EmpathyFile      *file;
+} ReceiveResponseData;
 
-			g_free (filename);
-			g_object_unref (file);
-			if (out_stream)
-				g_object_unref (out_stream);
-		}
+static void
+free_receive_response_data (ReceiveResponseData *response_data)
+{
+  if (!response_data)
+    return;
 
-		folder = gtk_file_chooser_get_current_folder (GTK_FILE_CHOOSER (widget));
-		if (folder) {
-			empathy_conf_set_string (empathy_conf_get (),
-						 EMPATHY_PREFS_FILE_TRANSFER_DEFAULT_FOLDER,
-						 folder);
-			g_free (folder);
-		}
-	}
+  g_object_unref (response_data->file);
+  g_object_unref (response_data->ft_manager);
+  g_free (response_data);
+}
+
+static void
+ft_manager_save_dialog_response_cb (GtkDialog *widget, gint response_id,
+    ReceiveResponseData *response_data)
+{
+  if (response_id == GTK_RESPONSE_OK)
+    {
+      gchar *uri;
+      gchar *folder;
+
+      uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (widget));
+
+      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));
+
+          if (error)
+            {
+              g_warning ("Error with opening file to write to: %s",
+                  error->message ? error->message : "no error");
+              g_error_free (error);
+              return;
+            }
+
+          empathy_file_set_output_stream (response_data->file, out_stream);
+
+          g_object_set_data_full (G_OBJECT (response_data->file),
+              "uri", uri, g_free);
+
+          filename = g_file_get_basename (file);
+          empathy_file_set_filename (response_data->file, filename);
+
+          empathy_file_accept (response_data->file);
+
+          ft_manager_add_file_to_list (response_data->ft_manager,
+              response_data->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));
+      if (folder)
+        {
+          empathy_conf_set_string (empathy_conf_get (),
+              EMPATHY_PREFS_FILE_TRANSFER_DEFAULT_FOLDER,
+              folder);
+          g_free (folder);
+        }
+    }
 
-	gtk_widget_destroy (GTK_WIDGET (widget));
-	free_receive_response_data (response_data);
+  gtk_widget_destroy (GTK_WIDGET (widget));
+  free_receive_response_data (response_data);
 }
 
 static void
 ft_manager_create_save_dialog (ReceiveResponseData *response_data)
 {
-	GtkWidget     *widget;
-	gchar         *folder;
-	GtkFileFilter *filter;
+  GtkWidget *widget;
+  gchar *folder;
+  GtkFileFilter *filter;
 
-	DEBUG ("Creating save file chooser");
+  DEBUG ("Creating save file chooser");
 
-	widget = g_object_new (GTK_TYPE_FILE_CHOOSER_DIALOG,
-			       "action", GTK_FILE_CHOOSER_ACTION_SAVE,
-			       "select-multiple", FALSE,
-			       "do-overwrite-confirmation", TRUE,
-			       NULL);
+  widget = g_object_new (GTK_TYPE_FILE_CHOOSER_DIALOG,
+      "action", GTK_FILE_CHOOSER_ACTION_SAVE,
+      "select-multiple", FALSE,
+      "do-overwrite-confirmation", TRUE,
+      NULL);
 
-	gtk_window_set_title (GTK_WINDOW (widget), _("Save file"));
+  gtk_window_set_title (GTK_WINDOW (widget), _("Save file"));
 
-	if (!empathy_conf_get_string (empathy_conf_get (),
-				      EMPATHY_PREFS_FILE_TRANSFER_DEFAULT_FOLDER,
-				      &folder) || !folder) {
-		folder = g_strdup (g_get_user_special_dir (G_USER_DIRECTORY_DOWNLOAD));
-	}
+  if (!empathy_conf_get_string (empathy_conf_get (),
+      EMPATHY_PREFS_FILE_TRANSFER_DEFAULT_FOLDER,
+      &folder) || !folder)
+    folder = g_strdup (g_get_user_special_dir (G_USER_DIRECTORY_DOWNLOAD));
 
-	if (folder)
-		gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (widget), folder);
+  if (folder)
+    gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (widget), folder);
 
-	gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (widget),
-					   empathy_file_get_filename (response_data->file));
+  gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (widget),
+      empathy_file_get_filename (response_data->file));
 
-	gtk_dialog_add_buttons (GTK_DIALOG (widget),
-				GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
-				GTK_STOCK_SAVE, GTK_RESPONSE_OK,
-				NULL);
+  gtk_dialog_add_buttons (GTK_DIALOG (widget),
+      GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+      GTK_STOCK_SAVE, GTK_RESPONSE_OK,
+      NULL);
 
-	gtk_dialog_set_default_response (GTK_DIALOG (widget),
-					 GTK_RESPONSE_OK);
+  gtk_dialog_set_default_response (GTK_DIALOG (widget),
+      GTK_RESPONSE_OK);
 
-	g_signal_connect (widget, "response",
-			  G_CALLBACK (ft_manager_save_dialog_response_cb),
-			  response_data);
+  g_signal_connect (widget, "response",
+      G_CALLBACK (ft_manager_save_dialog_response_cb), response_data);
 
-	filter = gtk_file_filter_new ();
-	gtk_file_filter_set_name (filter, "All Files");
-	gtk_file_filter_add_pattern (filter, "*");
-	gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (widget), filter);
+  filter = gtk_file_filter_new ();
+  gtk_file_filter_set_name (filter, "All Files");
+  gtk_file_filter_add_pattern (filter, "*");
+  gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (widget), filter);
 
-	gtk_widget_show (widget);
+  gtk_widget_show (widget);
 
-	g_free (folder);
+  g_free (folder);
 }
 
 static void
-ft_manager_receive_file_response_cb (GtkWidget           *dialog,
-				     gint                 response,
-				     ReceiveResponseData *response_data)
+ft_manager_receive_file_response_cb (GtkWidget *dialog, gint response,
+    ReceiveResponseData *response_data)
 {
-	TpChannel *channel;
+  TpChannel *channel;
 
-	if (response == GTK_RESPONSE_ACCEPT) {
-		ft_manager_create_save_dialog (response_data);
-	} else {
-		channel = empathy_file_get_channel (response_data->file);
-		tp_cli_channel_run_close (channel, -1, NULL, NULL);
-		free_receive_response_data (response_data);
-	}
+  if (response == GTK_RESPONSE_ACCEPT)
+    ft_manager_create_save_dialog (response_data);
+  else
+    {
+      channel = empathy_file_get_channel (response_data->file);
+      tp_cli_channel_run_close (channel, -1, NULL, NULL);
+      free_receive_response_data (response_data);
+    }
 
-	gtk_widget_destroy (dialog);
+  gtk_widget_destroy (dialog);
 }
 
 void
 ft_manager_display_accept_dialog (EmpathyFTManager *ft_manager,
-				  EmpathyFile      *file)
+    EmpathyFile *file)
 {
-	GtkWidget           *dialog;
-	GtkWidget           *image;
-	GtkWidget           *button;
-	const gchar         *contact_name;
-	const gchar         *filename;
-	guint64              size;
-	gchar               *size_str;
-	ReceiveResponseData *response_data;
-
-	g_return_if_fail (EMPATHY_IS_FT_MANAGER (ft_manager));
-	g_return_if_fail (EMPATHY_IS_FILE (file));
-
-	DEBUG ("Creating accept dialog");
-
-	contact_name = empathy_contact_get_name (empathy_file_get_contact (file));
-	filename = empathy_file_get_filename (file);
-
-	size = empathy_file_get_size (file);
-	if (size == EMPATHY_FILE_UNKNOWN_SIZE)
-		size_str = g_strdup (_("unknown size"));
-	else
-		size_str = g_format_size_for_display (size);
-
-	dialog = gtk_message_dialog_new (NULL, 0, GTK_MESSAGE_INFO,
-					 GTK_BUTTONS_NONE,
-					 _("%s would like to send you a file"),
-					 contact_name);
-
-	gtk_message_dialog_format_secondary_text
-		(GTK_MESSAGE_DIALOG (dialog),
-		 _("Do you want to accept the file \"%s\" (%s)?"),
-		 filename, size_str);
-
-	/* Icon */
-	image = gtk_image_new_from_stock (GTK_STOCK_SAVE, GTK_ICON_SIZE_DIALOG);
-	gtk_widget_show (image);
-	gtk_message_dialog_set_image (GTK_MESSAGE_DIALOG (dialog), image);
-
-	/* Decline button */
-	button = gtk_button_new_with_mnemonic (_("_Decline"));
-	gtk_button_set_image (GTK_BUTTON (button),
-			      gtk_image_new_from_stock (GTK_STOCK_CANCEL,
-							GTK_ICON_SIZE_BUTTON));
-	gtk_widget_show (button);
-	gtk_dialog_add_action_widget (GTK_DIALOG (dialog), button,
-				      GTK_RESPONSE_REJECT);
-
-	/* Accept button */
-	button = gtk_button_new_with_mnemonic (_("_Accept"));
-	gtk_button_set_image (GTK_BUTTON (button),
-			      gtk_image_new_from_stock (GTK_STOCK_SAVE,
-							GTK_ICON_SIZE_BUTTON));
-	gtk_widget_show (button);
-	gtk_dialog_add_action_widget (GTK_DIALOG (dialog), button,
-				      GTK_RESPONSE_ACCEPT);
-	GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
-	gtk_widget_grab_default (button);
-
-	response_data = g_new0 (ReceiveResponseData, 1);
-	response_data->ft_manager = g_object_ref (ft_manager);
-	response_data->file = g_object_ref (file);
-
-	g_signal_connect (dialog, "response",
-			  G_CALLBACK (ft_manager_receive_file_response_cb),
-			  response_data);
+  GtkWidget *dialog;
+  GtkWidget *image;
+  GtkWidget *button;
+  const gchar *contact_name;
+  const gchar *filename;
+  guint64 size;
+  gchar *size_str;
+  ReceiveResponseData *response_data;
+
+  g_return_if_fail (EMPATHY_IS_FT_MANAGER (ft_manager));
+  g_return_if_fail (EMPATHY_IS_FILE (file));
+
+  DEBUG ("Creating accept dialog");
+
+  contact_name = empathy_contact_get_name (empathy_file_get_contact (file));
+  filename = empathy_file_get_filename (file);
+
+  size = empathy_file_get_size (file);
+  if (size == EMPATHY_FILE_UNKNOWN_SIZE)
+    size_str = g_strdup (_("unknown size"));
+  else
+    size_str = g_format_size_for_display (size);
+
+  dialog = gtk_message_dialog_new (NULL, 0, GTK_MESSAGE_INFO,
+      GTK_BUTTONS_NONE,
+      _("%s would like to send you a file"),
+      contact_name);
+
+  gtk_message_dialog_format_secondary_text
+      (GTK_MESSAGE_DIALOG (dialog),
+       _("Do you want to accept the file \"%s\" (%s)?"),
+       filename, size_str);
+
+  /* Icon */
+  image = gtk_image_new_from_stock (GTK_STOCK_SAVE, GTK_ICON_SIZE_DIALOG);
+  gtk_widget_show (image);
+  gtk_message_dialog_set_image (GTK_MESSAGE_DIALOG (dialog), image);
+
+  /* Decline button */
+  button = gtk_button_new_with_mnemonic (_("_Decline"));
+  gtk_button_set_image (GTK_BUTTON (button),
+      gtk_image_new_from_stock (GTK_STOCK_CANCEL,
+          GTK_ICON_SIZE_BUTTON));
+  gtk_widget_show (button);
+  gtk_dialog_add_action_widget (GTK_DIALOG (dialog), button,
+      GTK_RESPONSE_REJECT);
+
+  /* Accept button */
+  button = gtk_button_new_with_mnemonic (_("_Accept"));
+  gtk_button_set_image (GTK_BUTTON (button),
+      gtk_image_new_from_stock (GTK_STOCK_SAVE,
+          GTK_ICON_SIZE_BUTTON));
+  gtk_widget_show (button);
+  gtk_dialog_add_action_widget (GTK_DIALOG (dialog), button,
+      GTK_RESPONSE_ACCEPT);
+  GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
+  gtk_widget_grab_default (button);
+
+  response_data = g_new0 (ReceiveResponseData, 1);
+  response_data->ft_manager = g_object_ref (ft_manager);
+  response_data->file = g_object_ref (file);
+
+  g_signal_connect (dialog, "response",
+      G_CALLBACK (ft_manager_receive_file_response_cb), response_data);
 
-	gtk_widget_show (dialog);
+  gtk_widget_show (dialog);
 
-	g_free (size_str);
+  g_free (size_str);
 }
 

Modified: trunk/libempathy-gtk/empathy-ft-manager.h
==============================================================================
--- trunk/libempathy-gtk/empathy-ft-manager.h	(original)
+++ trunk/libempathy-gtk/empathy-ft-manager.h	Fri Nov 21 16:15:54 2008
@@ -30,33 +30,32 @@
 
 G_BEGIN_DECLS
 
-#define EMPATHY_TYPE_FT_MANAGER         (empathy_ft_manager_get_type ())
-#define EMPATHY_FT_MANAGER(o)           (G_TYPE_CHECK_INSTANCE_CAST ((o), EMPATHY_TYPE_FT_MANAGER, EmpathyFTManager))
-#define EMPATHY_FT_MANAGER_CLASS(k)     (G_TYPE_CHECK_CLASS_CAST((k), EMPATHY_TYPE_FT_MANAGER, EmpathyFTManagerClass))
-#define EMPATHY_IS_FT_MANAGER(o)        (G_TYPE_CHECK_INSTANCE_TYPE ((o), EMPATHY_TYPE_FT_MANAGER))
-#define EMPATHY_IS_FT_MANAGER_CLASS(k)  (G_TYPE_CHECK_CLASS_TYPE ((k), EMPATHY_TYPE_FT_MANAGER))
+#define EMPATHY_TYPE_FT_MANAGER (empathy_ft_manager_get_type ())
+#define EMPATHY_FT_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), EMPATHY_TYPE_FT_MANAGER, EmpathyFTManager))
+#define EMPATHY_FT_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), EMPATHY_TYPE_FT_MANAGER, EmpathyFTManagerClass))
+#define EMPATHY_IS_FT_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), EMPATHY_TYPE_FT_MANAGER))
+#define EMPATHY_IS_FT_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), EMPATHY_TYPE_FT_MANAGER))
 #define EMPATHY_FT_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), EMPATHY_TYPE_FT_MANAGER, EmpathyFTManagerClass))
 
-typedef struct _EmpathyFTManager      EmpathyFTManager;
-typedef struct _EmpathyFTManagerPriv  EmpathyFTManagerPriv;
+typedef struct _EmpathyFTManager EmpathyFTManager;
+typedef struct _EmpathyFTManagerPriv EmpathyFTManagerPriv;
 typedef struct _EmpathyFTManagerClass EmpathyFTManagerClass;
 
 struct _EmpathyFTManager
 {
-	GObject parent;
+  GObject parent;
 };
 
 struct _EmpathyFTManagerClass
 {
-	GObjectClass parent_class;
+  GObjectClass parent_class;
 };
 
-GType             empathy_ft_manager_get_type  (void);
+GType empathy_ft_manager_get_type (void);
 
-EmpathyFTManager *empathy_ft_manager_get_default          (void);
-void              empathy_ft_manager_add_file             (EmpathyFTManager *ft_manager,
-							   EmpathyFile      *file);
-GtkWidget        *empathy_ft_manager_get_dialog           (EmpathyFTManager *ft_manager);
+EmpathyFTManager *empathy_ft_manager_get_default (void);
+void empathy_ft_manager_add_file (EmpathyFTManager *ft_manager, EmpathyFile *file);
+GtkWidget *empathy_ft_manager_get_dialog (EmpathyFTManager *ft_manager);
 
 G_END_DECLS
 

Modified: trunk/libempathy/empathy-file.c
==============================================================================
--- trunk/libempathy/empathy-file.c	(original)
+++ trunk/libempathy/empathy-file.c	Fri Nov 21 16:15:54 2008
@@ -64,34 +64,24 @@
  * the transferred file is unknown.
  */
 
-static void      empathy_file_class_init           (EmpathyFileClass      *klass);
-static void      empathy_file_init                 (EmpathyFile           *file);
-static void      file_finalize                     (GObject               *object);
-static GObject * file_constructor                  (GType                  type,
-                 guint                  n_props,
-                 GObjectConstructParam *props);
-static void      file_get_property                 (GObject               *object,
-                 guint                  param_id,
-                 GValue                *value,
-                 GParamSpec            *pspec);
-static void      file_set_property                 (GObject               *object,
-                 guint                  param_id,
-                 const GValue          *value,
-                 GParamSpec            *pspec);
-static void      file_destroy_cb                   (TpChannel             *file_chan,
-                 EmpathyFile           *file);
-static void      file_closed_cb                    (TpChannel             *file_chan,
-                 EmpathyFile           *file,
-                 GObject                 *weak_object);
-static void      file_state_changed_cb             (DBusGProxy            *file_iface,
-                 guint                  state,
-                 guint                  reason,
-                 EmpathyFile           *file);
-static void      file_transferred_bytes_changed_cb (TpProxy *proxy, guint64 count,
+static void empathy_file_class_init (EmpathyFileClass *klass);
+static void empathy_file_init (EmpathyFile *file);
+static void file_finalize (GObject *object);
+static GObject *file_constructor (GType type, guint n_props,
+    GObjectConstructParam *props);
+static void file_get_property (GObject *object, guint param_id, GValue *value,
+    GParamSpec *pspec);
+static void file_set_property (GObject *object, guint param_id, const GValue *value,
+    GParamSpec *pspec);
+static void file_destroy_cb (TpChannel *file_chan, EmpathyFile *file);
+static void file_closed_cb (TpChannel *file_chan, EmpathyFile *file,
+    GObject *weak_object);
+static void file_state_changed_cb (DBusGProxy *file_iface, guint state,
+    guint reason, EmpathyFile *file);
+static void file_transferred_bytes_changed_cb (TpProxy *proxy, guint64 count,
     EmpathyFile *file, GObject *weak_object);
-static void      copy_stream                        (GInputStream          *in,
-                 GOutputStream         *out,
-                 GCancellable          *cancellable);
+static void copy_stream (GInputStream *in, GOutputStream *out,
+    GCancellable *cancellable);
 
 /* EmpathyFile object */
 
@@ -102,29 +92,27 @@
 
 struct _EmpathyFilePriv {
   EmpathyContactFactory *factory;
-  McAccount             *account;
-  gchar                 *id;
-  MissionControl        *mc;
-
-  TpChannel             *channel;
-
-  /* Previously in File/FT struct */
-  EmpathyFile                            *cached_empathy_file;
-  EmpathyContact                         *contact;
-  GInputStream                           *in_stream;
-  GOutputStream                          *out_stream;
-  gchar                                  *filename;
-  EmpFileTransferDirection                direction;
-  EmpFileTransferState                    state;
-  EmpFileTransferStateChangeReason        state_change_reason;
-  guint64                                 size;
-  guint64                                 transferred_bytes;
-  gint64                                  start_time;
-  gchar                                  *unix_socket_path;
-  gchar                                  *content_md5;
-  gchar                                  *content_type;
-  gchar                                  *description;
-  GCancellable                           *cancellable;
+  McAccount *account;
+  gchar *id;
+  MissionControl *mc;
+  TpChannel *channel;
+
+  EmpathyFile *cached_empathy_file;
+  EmpathyContact *contact;
+  GInputStream *in_stream;
+  GOutputStream *out_stream;
+  gchar *filename;
+  EmpFileTransferDirection direction;
+  EmpFileTransferState state;
+  EmpFileTransferStateChangeReason state_change_reason;
+  guint64 size;
+  guint64 transferred_bytes;
+  gint64 start_time;
+  gchar *unix_socket_path;
+  gchar *content_md5;
+  gchar *content_type;
+  gchar *description;
+  GCancellable *cancellable;
 };
 
 enum {
@@ -258,7 +246,7 @@
 file_finalize (GObject *object)
 {
   EmpathyFilePriv *priv;
-  EmpathyFile     *file;
+  EmpathyFile *file;
 
   file = EMPATHY_FILE (object);
   priv = GET_PRIV (file);
@@ -309,17 +297,16 @@
 }
 
 static GObject *
-file_constructor (GType                  type,
-       guint                  n_props,
-       GObjectConstructParam *props)
+file_constructor (GType type, guint n_props, GObjectConstructParam *props)
 {
-  GObject         *file;
+  GObject *file;
   EmpathyFilePriv *priv;
-  GError            *error = NULL;
-  GHashTable        *properties;
-  TpHandle           handle;
+  GError *error = NULL;
+  GHashTable *properties;
+  TpHandle handle;
 
-  file = G_OBJECT_CLASS (empathy_file_parent_class)->constructor (type, n_props, props);
+  file = G_OBJECT_CLASS (empathy_file_parent_class)->constructor (type, n_props,
+      props);
 
   priv = GET_PRIV (file);
 
@@ -327,25 +314,29 @@
   priv->mc = empathy_mission_control_new ();
 
   tp_cli_channel_connect_to_closed (priv->channel,
-                                    (tp_cli_channel_signal_callback_closed) file_closed_cb,
-                                    file,
-                                    NULL, NULL, NULL);
-
-  emp_cli_channel_type_file_connect_to_file_transfer_state_changed (TP_PROXY (priv->channel),
-                                                                    (emp_cli_channel_type_file_signal_callback_file_transfer_state_changed) file_state_changed_cb,
-                                                                    file,
-                                                                    NULL, NULL, NULL);
-
-  emp_cli_channel_type_file_connect_to_transferred_bytes_changed (TP_PROXY (priv->channel),
-                                                                  (emp_cli_channel_type_file_signal_callback_transferred_bytes_changed) file_transferred_bytes_changed_cb,
-                                                                  file,
-                                                                  NULL, NULL, NULL);
+      (tp_cli_channel_signal_callback_closed) file_closed_cb,
+      file,
+      NULL, NULL, NULL);
+
+  emp_cli_channel_type_file_connect_to_file_transfer_state_changed (
+      TP_PROXY (priv->channel),
+      (emp_cli_channel_type_file_signal_callback_file_transfer_state_changed)
+          file_state_changed_cb,
+      file,
+      NULL, NULL, NULL);
+
+  emp_cli_channel_type_file_connect_to_transferred_bytes_changed (
+      TP_PROXY (priv->channel),
+      (emp_cli_channel_type_file_signal_callback_transferred_bytes_changed)
+          file_transferred_bytes_changed_cb,
+      file,
+      NULL, NULL, NULL);
 
 
   handle = tp_channel_get_handle (priv->channel, NULL);
   priv->contact = empathy_contact_factory_get_from_handle (priv->factory,
-                                                           priv->account,
-                                                           (guint) handle);
+      priv->account,
+      (guint) handle);
 
   if (!tp_cli_dbus_properties_run_get_all (priv->channel,
       -1, EMP_IFACE_CHANNEL_TYPE_FILE, &properties, &error, NULL))
@@ -364,17 +355,23 @@
    * a warning if called for a not closed file transfer. */
   priv->state_change_reason = -1;
 
-  priv->transferred_bytes = g_value_get_uint64 (g_hash_table_lookup (properties, "TransferredBytes"));
+  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->filename = g_value_dup_string (g_hash_table_lookup (properties,
+      "Filename"));
 
-  priv->content_md5 = g_value_dup_string (g_hash_table_lookup (properties, "ContentMD5"));
+  priv->content_md5 = g_value_dup_string (g_hash_table_lookup (properties,
+      "ContentMD5"));
 
-  priv->description = g_value_dup_string (g_hash_table_lookup (properties, "Description"));
+  priv->description = g_value_dup_string (g_hash_table_lookup (properties,
+      "Description"));
 
-  priv->unix_socket_path = g_value_dup_string (g_hash_table_lookup (properties, "SocketPath"));
+  priv->unix_socket_path = g_value_dup_string (g_hash_table_lookup (properties,
+      "SocketPath"));
 
-  priv->direction = g_value_get_uint (g_hash_table_lookup (properties, "Direction"));
+  priv->direction = g_value_get_uint (g_hash_table_lookup (properties,
+      "Direction"));
 
   g_hash_table_destroy (properties);
 
@@ -382,13 +379,11 @@
 }
 
 static void
-file_get_property (GObject    *object,
-        guint       param_id,
-        GValue     *value,
-        GParamSpec *pspec)
+file_get_property (GObject *object, guint param_id, GValue *value,
+    GParamSpec *pspec)
 {
   EmpathyFilePriv *priv;
-  EmpathyFile     *file;
+  EmpathyFile *file;
 
   priv = GET_PRIV (object);
   file = EMPATHY_FILE (object);
@@ -408,27 +403,23 @@
 }
 
 static void
-file_channel_set_dbus_property (gpointer proxy,
-                                   const gchar *property,
-                                   const GValue *value)
+file_channel_set_dbus_property (gpointer proxy, const gchar *property,
+    const GValue *value)
 {
         DEBUG ("Setting %s property", property);
         tp_cli_dbus_properties_run_set (TP_PROXY (proxy),
-                                        -1,
-                                        EMP_IFACE_CHANNEL_TYPE_FILE,
-                                        property,
-                                        value,
-                                        NULL,
-                                        NULL);
+            -1,
+            EMP_IFACE_CHANNEL_TYPE_FILE,
+            property,
+            value,
+            NULL, NULL);
         DEBUG ("done");
 }
 
 
 static void
-file_set_property (GObject      *object,
-        guint         param_id,
-        const GValue *value,
-        GParamSpec   *pspec)
+file_set_property (GObject *object, guint param_id, const GValue *value,
+    GParamSpec *pspec)
 {
   EmpathyFilePriv *priv;
 
@@ -488,13 +479,12 @@
  * Returns: a new #EmpathyFile
  */
 EmpathyFile *
-empathy_file_new (McAccount *account,
-       TpChannel *channel)
+empathy_file_new (McAccount *account, TpChannel *channel)
 {
   return g_object_new (EMPATHY_TYPE_FILE,
-           "account", account,
-           "channel", channel,
-           NULL);
+      "account", account,
+      "channel", channel,
+      NULL);
 }
 
 /**
@@ -546,7 +536,7 @@
 
   DEBUG ("Channel Closed or CM crashed");
 
-  g_object_unref  (priv->channel);
+  g_object_unref (priv->channel);
   priv->channel = NULL;
 }
 
@@ -559,8 +549,8 @@
 
   /* The channel is closed, do just like if the proxy was destroyed */
   g_signal_handlers_disconnect_by_func (priv->channel,
-                file_destroy_cb,
-                file);
+      file_destroy_cb,
+      file);
   file_destroy_cb (file_channel, file);
 }
 
@@ -586,12 +576,12 @@
 
   /* TODO: This could probably be a little nicer. */
   tp_cli_dbus_properties_run_get (priv->channel,
-                                  -1,
-                                  EMP_IFACE_CHANNEL_TYPE_FILE,
-                                  "SocketPath",
-                                  &socket_path,
-                                  NULL,
-                                  NULL);
+      -1,
+      EMP_IFACE_CHANNEL_TYPE_FILE,
+      "SocketPath",
+      &socket_path,
+      NULL,
+      NULL);
 
   if (priv->unix_socket_path)
     g_free (priv->unix_socket_path);
@@ -602,8 +592,6 @@
   if (G_STR_EMPTY (priv->unix_socket_path))
     return -1;
 
-  DEBUG ("socket path is %s", priv->unix_socket_path);
-
   fd = socket (PF_UNIX, SOCK_STREAM, 0);
   if (fd < 0)
     return -1;
@@ -694,7 +682,7 @@
 static void
 send_file (EmpathyFile *file)
 {
-  gint           socket_fd;
+  gint socket_fd;
   GOutputStream *socket_stream;
   EmpathyFilePriv *priv;
 
@@ -722,26 +710,24 @@
 }
 
 static void
-file_state_changed_cb (DBusGProxy *file_iface,
-    EmpFileTransferState state,
-    EmpFileTransferStateChangeReason reason,
-    EmpathyFile *file)
+file_state_changed_cb (DBusGProxy *file_iface, EmpFileTransferState state,
+    EmpFileTransferStateChangeReason reason, EmpathyFile *file)
 {
   EmpathyFilePriv *priv;
 
   priv = GET_PRIV (file);
 
   DEBUG ("File transfer state changed: filename=%s, "
-           "old state=%u, state=%u, reason=%u",
-           priv->filename, priv->state, state, reason);
+      "old state=%u, state=%u, reason=%u",
+      priv->filename, priv->state, state, reason);
 
   if (state == EMP_FILE_TRANSFER_STATE_OPEN)
     priv->start_time = get_time_msec ();
 
   DEBUG ("state = %u, direction = %u, in_stream = %s, out_stream = %s",
-         state, priv->direction,
-         priv->in_stream ? "present" : "not present",
-         priv->out_stream ? "present" : "not present");
+      state, priv->direction,
+      priv->in_stream ? "present" : "not present",
+      priv->out_stream ? "present" : "not present");
 
   if (state == EMP_FILE_TRANSFER_STATE_OPEN &&
       priv->direction == EMP_FILE_TRANSFER_DIRECTION_OUTGOING &&
@@ -842,7 +828,7 @@
   priv = GET_PRIV (file);
 
   g_return_val_if_fail (priv->state_change_reason >= 0,
-            EMP_FILE_TRANSFER_STATE_CHANGE_REASON_NONE);
+      EMP_FILE_TRANSFER_STATE_CHANGE_REASON_NONE);
 
   return priv->state_change_reason;
 }
@@ -871,9 +857,9 @@
 empathy_file_get_remaining_time (EmpathyFile *file)
 {
   EmpathyFilePriv *priv;
-  gint64   curr_time, elapsed_time;
-  gdouble  time_per_byte;
-  gdouble  remaining_time;
+  gint64 curr_time, elapsed_time;
+  gdouble time_per_byte;
+  gdouble remaining_time;
 
   priv = GET_PRIV (file);
 
@@ -920,16 +906,17 @@
 
   if (priv->in_stream)
     g_object_unref (priv->in_stream);
+
   if (in_stream)
     g_object_ref (in_stream);
+
   priv->in_stream = in_stream;
 
   g_object_notify (G_OBJECT (file), "in-stream");
 }
 
 void
-empathy_file_set_output_stream (EmpathyFile *file,
-    GOutputStream *out_stream)
+empathy_file_set_output_stream (EmpathyFile *file, GOutputStream *out_stream)
 {
   EmpathyFilePriv *priv;
 
@@ -944,8 +931,10 @@
 
   if (priv->out_stream)
     g_object_unref (priv->out_stream);
+
   if (out_stream)
     g_object_ref (out_stream);
+
   priv->out_stream = out_stream;
 }
 
@@ -959,9 +948,8 @@
 
   g_return_if_fail (filename != NULL);
 
-  if (priv->filename && strcmp (filename, priv->filename) == 0) {
+  if (priv->filename && strcmp (filename, priv->filename) == 0)
     return;
-  }
 
   g_free (priv->filename);
   priv->filename = g_strdup (filename);
@@ -975,17 +963,17 @@
 #define BUFFER_SIZE 4096
 
 typedef struct {
-  GInputStream  *in;
+  GInputStream *in;
   GOutputStream *out;
   GCancellable  *cancellable;
-  char          *buff[N_BUFFERS]; /* the temporary buffers */
-  gsize          count[N_BUFFERS]; /* how many bytes are used in the buffers */
-  gboolean       is_full[N_BUFFERS]; /* whether the buffers contain data */
-  gint           curr_read; /* index of the buffer used for reading */
-  gint           curr_write; /* index of the buffer used for writing */
-  gboolean       is_reading; /* we are reading */
-  gboolean       is_writing; /* we are writing */
-  guint          n_closed; /* number of streams that have been closed */
+  char *buff[N_BUFFERS]; /* the temporary buffers */
+  gsize count[N_BUFFERS]; /* how many bytes are used in the buffers */
+  gboolean is_full[N_BUFFERS]; /* whether the buffers contain data */
+  gint curr_read; /* index of the buffer used for reading */
+  gint curr_write; /* index of the buffer used for writing */
+  gboolean is_reading; /* we are reading */
+  gboolean is_writing; /* we are writing */
+  guint n_closed; /* number of streams that have been closed */
 } CopyData;
 
 static void schedule_next (CopyData *copy);
@@ -1048,16 +1036,17 @@
 write_done_cb (GObject *source_object, GAsyncResult *res, gpointer user_data)
 {
   CopyData *copy = user_data;
-  gssize    count_write;
-  GError   *error = NULL;
+  gssize count_write;
+  GError *error = NULL;
 
   count_write = g_output_stream_write_finish (copy->out, res, &error);
 
-  if (count_write <= 0) {
-    io_error (copy, error);
-    g_error_free (error);
-    return;
-  }
+  if (count_write <= 0)
+    {
+      io_error (copy, error);
+      g_error_free (error);
+      return;
+    }
 
   copy->is_full[copy->curr_write] = FALSE;
   copy->curr_write = (copy->curr_write + 1) % N_BUFFERS;
@@ -1070,21 +1059,23 @@
 read_done_cb (GObject *source_object, GAsyncResult *res, gpointer user_data)
 {
   CopyData *copy = user_data;
-  gssize    count_read;
-  GError   *error = NULL;
+  gssize count_read;
+  GError *error = NULL;
 
   count_read = g_input_stream_read_finish (copy->in, res, &error);
 
-  if (count_read == 0) {
-    g_input_stream_close_async (copy->in, 0, copy->cancellable,
-              close_done, copy);
-    copy->in = NULL;
-  }
-  else if (count_read < 0) {
-    io_error (copy, error);
-    g_error_free (error);
-    return;
-  }
+  if (count_read == 0)
+    {
+      g_input_stream_close_async (copy->in, 0, copy->cancellable,
+          close_done, copy);
+      copy->in = NULL;
+    }
+  else if (count_read < 0)
+    {
+      io_error (copy, error);
+      g_error_free (error);
+      return;
+    }
 
   copy->count[copy->curr_read] = count_read;
   copy->is_full[copy->curr_read] = TRUE;
@@ -1099,44 +1090,49 @@
 {
   if (copy->in != NULL &&
       !copy->is_reading &&
-      !copy->is_full[copy->curr_read]) {
-    /* We are not reading and the current buffer is empty, so
-     * start an async read. */
-    copy->is_reading = TRUE;
-    g_input_stream_read_async (copy->in,
-             copy->buff[copy->curr_read],
-             BUFFER_SIZE, 0, copy->cancellable,
-             read_done_cb, copy);
-  }
+      !copy->is_full[copy->curr_read])
+    {
+      /* We are not reading and the current buffer is empty, so
+       * start an async read. */
+      copy->is_reading = TRUE;
+      g_input_stream_read_async (copy->in,
+          copy->buff[copy->curr_read],
+          BUFFER_SIZE, 0, copy->cancellable,
+          read_done_cb, copy);
+    }
 
   if (!copy->is_writing &&
-      copy->is_full[copy->curr_write]) {
-    if (copy->count[copy->curr_write] == 0) {
-      /* The last read on the buffer read 0 bytes, this
-       * means that we got an EOF, so we can close
-       * the output channel. */
-      g_output_stream_close_async (copy->out, 0,
-                 copy->cancellable,
-                 close_done, copy);
+      copy->is_full[copy->curr_write])
+    {
+      if (copy->count[copy->curr_write] == 0)
+        {
+          /* The last read on the buffer read 0 bytes, this
+           * means that we got an EOF, so we can close
+           * the output channel. */
+          g_output_stream_close_async (copy->out, 0,
+              copy->cancellable,
+              close_done, copy);
       copy->out = NULL;
-    } else {
-      /* We are not writing and the current buffer contains
-       * data, so start an async write. */
-      copy->is_writing = TRUE;
-      g_output_stream_write_async (copy->out,
-                 copy->buff[copy->curr_write],
-                 copy->count[copy->curr_write],
-                 0, copy->cancellable,
-                 write_done_cb, copy);
+        }
+      else
+        {
+          /* We are not writing and the current buffer contains
+           * data, so start an async write. */
+          copy->is_writing = TRUE;
+          g_output_stream_write_async (copy->out,
+              copy->buff[copy->curr_write],
+              copy->count[copy->curr_write],
+              0, copy->cancellable,
+              write_done_cb, copy);
+        }
     }
-  }
 }
 
 static void
 copy_stream (GInputStream *in, GOutputStream *out, GCancellable *cancellable)
 {
   CopyData *copy;
-  gint      i;
+  gint i;
 
   g_return_if_fail (in != NULL);
   g_return_if_fail (out != NULL);

Modified: trunk/libempathy/empathy-file.h
==============================================================================
--- trunk/libempathy/empathy-file.h	(original)
+++ trunk/libempathy/empathy-file.h	Fri Nov 21 16:15:54 2008
@@ -61,30 +61,29 @@
 };
 
 GType empathy_file_get_type (void) G_GNUC_CONST;
-EmpathyFile *empathy_file_new (McAccount       *account, TpChannel *channel);
-const gchar *empathy_file_get_id (EmpathyFile *file);
-TpChannel *empathy_file_get_channel (EmpathyFile *file);
 
+EmpathyFile *empathy_file_new (McAccount *account, TpChannel *channel);
+
+TpChannel *empathy_file_get_channel (EmpathyFile *file);
 void empathy_file_accept (EmpathyFile *file);
-guint64                                 empathy_file_get_transferred_bytes   (EmpathyFile   *file);
-EmpathyContact *                        empathy_file_get_contact             (EmpathyFile   *file);
-GInputStream *                          empathy_file_get_input_stream        (EmpathyFile   *file);
-GOutputStream *                         empathy_file_get_output_stream       (EmpathyFile   *file);
-const gchar *                           empathy_file_get_filename            (EmpathyFile   *file);
-EmpFileTransferDirection          empathy_file_get_direction           (EmpathyFile   *file);
-EmpFileTransferState              empathy_file_get_state               (EmpathyFile   *file);
-EmpFileTransferStateChangeReason  empathy_file_get_state_change_reason (EmpathyFile   *file);
-guint64                                 empathy_file_get_size                (EmpathyFile   *file);
-guint64                                 empathy_file_get_transferred_bytes   (EmpathyFile   *file);
-gint                                    empathy_file_get_remaining_time      (EmpathyFile   *file);
-
-void                                    empathy_file_set_input_stream        (EmpathyFile   *file,
-										GInputStream  *uri);
-void                                    empathy_file_set_output_stream       (EmpathyFile   *file,
-										GOutputStream *uri);
-void                                    empathy_file_set_filename            (EmpathyFile   *file,
-										const gchar   *filename);
-void                                    empathy_file_cancel                  (EmpathyFile   *file);
+void empathy_file_cancel (EmpathyFile *file);
+
+const gchar *empathy_file_get_id (EmpathyFile *file);
+guint64 empathy_file_get_transferred_bytes (EmpathyFile *file);
+EmpathyContact *empathy_file_get_contact (EmpathyFile *file);
+GInputStream *empathy_file_get_input_stream (EmpathyFile *file);
+GOutputStream *empathy_file_get_output_stream (EmpathyFile *file);
+const gchar *empathy_file_get_filename (EmpathyFile *file);
+EmpFileTransferDirection empathy_file_get_direction (EmpathyFile *file);
+EmpFileTransferState empathy_file_get_state (EmpathyFile *file);
+EmpFileTransferStateChangeReason empathy_file_get_state_change_reason (EmpathyFile *file);
+guint64 empathy_file_get_size (EmpathyFile *file);
+guint64 empathy_file_get_transferred_bytes (EmpathyFile *file);
+gint empathy_file_get_remaining_time (EmpathyFile *file);
+
+void empathy_file_set_input_stream (EmpathyFile *file, GInputStream *uri);
+void empathy_file_set_output_stream (EmpathyFile *file, GOutputStream *uri);
+void empathy_file_set_filename (EmpathyFile *file, const gchar *filename);
 
 G_END_DECLS
 

Modified: trunk/libempathy/empathy-utils.h
==============================================================================
--- trunk/libempathy/empathy-utils.h	(original)
+++ trunk/libempathy/empathy-utils.h	Fri Nov 21 16:15:54 2008
@@ -129,6 +129,11 @@
                                                      guint64          size);
 EmpathyFile *  empathy_send_file                    (EmpathyContact  *contact,
                                                      GFile           *file);
+/* File transfer */
+EmpathyFile *empathy_send_file                      (EmpathyContact  *contact,
+						     GFile           *file);
+
+/* General */
 void         empathy_init                           (void);
 
 G_END_DECLS



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