aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonny Lamb <jonny.lamb@collabora.co.uk>2008-11-22 00:17:23 +0800
committerXavier Claessens <xclaesse@src.gnome.org>2008-11-22 00:17:23 +0800
commit0035f651e71678b14368bbc74cd718c974ad5b09 (patch)
tree35762cad05c1c613da102a683e868e18a5a3d110
parent8694a647857514b394f5474b2665d2a1c4bc3979 (diff)
downloadgsoc2013-empathy-0035f651e71678b14368bbc74cd718c974ad5b09.tar
gsoc2013-empathy-0035f651e71678b14368bbc74cd718c974ad5b09.tar.gz
gsoc2013-empathy-0035f651e71678b14368bbc74cd718c974ad5b09.tar.bz2
gsoc2013-empathy-0035f651e71678b14368bbc74cd718c974ad5b09.tar.lz
gsoc2013-empathy-0035f651e71678b14368bbc74cd718c974ad5b09.tar.xz
gsoc2013-empathy-0035f651e71678b14368bbc74cd718c974ad5b09.tar.zst
gsoc2013-empathy-0035f651e71678b14368bbc74cd718c974ad5b09.zip
Re-ordered EmpathyFTManager so functions need no declaration at the top of the file. (Jonny Lamb)
Signed-off-by: Jonny Lamb <jonny.lamb@collabora.co.uk> svn path=/trunk/; revision=1793
-rw-r--r--libempathy-gtk/empathy-ft-manager.c761
1 files changed, 374 insertions, 387 deletions
diff --git a/libempathy-gtk/empathy-ft-manager.c b/libempathy-gtk/empathy-ft-manager.c
index 536e2e7f4..93b352054 100644
--- a/libempathy-gtk/empathy-ft-manager.c
+++ b/libempathy-gtk/empathy-ft-manager.c
@@ -103,66 +103,10 @@ enum
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_tp_file_to_list (EmpathyFTManager *ft_manager,
- EmpathyTpFile *tp_file);
-static void ft_manager_remove_file_from_list (EmpathyFTManager *ft_manager,
- EmpathyTpFile *tp_file);
-static void ft_manager_display_accept_dialog (EmpathyFTManager *ft_manager,
- EmpathyTpFile *tp_file);
-
G_DEFINE_TYPE (EmpathyFTManager, empathy_ft_manager, G_TYPE_OBJECT);
static EmpathyFTManager *manager_p = NULL;
-static void
-empathy_ft_manager_class_init (EmpathyFTManagerClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->finalize = empathy_ft_manager_finalize;
-
- g_type_class_add_private (object_class, sizeof (EmpathyFTManagerPriv));
-}
-
-static void
-empathy_ft_manager_init (EmpathyFTManager *ft_manager)
-{
- EmpathyFTManagerPriv *priv;
-
- priv = GET_PRIV (ft_manager);
-
- priv->tp_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);
-}
-
-static void
-empathy_ft_manager_finalize (GObject *object)
-{
- EmpathyFTManagerPriv *priv;
-
- DEBUG ("Finalizing: %p", object);
-
- priv = GET_PRIV (object);
-
- g_hash_table_destroy (priv->tp_file_to_row_ref);
-
- if (priv->save_geometry_id != 0)
- g_source_remove (priv->save_geometry_id);
-
- manager_p = NULL;
-
- G_OBJECT_CLASS (empathy_ft_manager_parent_class)->finalize (object);
-}
-
/**
* empathy_ft_manager_get_default:
*
@@ -181,36 +125,6 @@ empathy_ft_manager_get_default (void)
}
/**
- * empathy_ft_manager_add_tp_file:
- * @ft_manager: an #EmpathyFTManager
- * @ft: an #EmpathyFT
- *
- * Adds a file transfer to the file transfer manager dialog @ft_manager.
- * The manager dialog then shows the progress and other information about
- * @ft.
- */
-void
-empathy_ft_manager_add_tp_file (EmpathyFTManager *ft_manager,
- EmpathyTpFile *tp_file)
-{
- EmpFileTransferState state;
-
- g_return_if_fail (EMPATHY_IS_FT_MANAGER (ft_manager));
- g_return_if_fail (EMPATHY_IS_TP_FILE (tp_file));
-
- DEBUG ("Adding a file transfer: contact=%s, filename=%s",
- empathy_contact_get_name (empathy_tp_file_get_contact (tp_file)),
- empathy_tp_file_get_filename (tp_file));
-
- state = empathy_tp_file_get_state (tp_file);
-
- if (state == EMP_FILE_TRANSFER_STATE_LOCAL_PENDING)
- ft_manager_display_accept_dialog (ft_manager, tp_file);
- else
- ft_manager_add_tp_file_to_list (ft_manager, tp_file);
-}
-
-/**
* empathy_ft_manager_get_dialog:
* @ft_manager: an #EmpathyFTManager
*
@@ -504,119 +418,6 @@ transferred_bytes_changed_cb (EmpathyTpFile *tp_file,
}
static void
-state_changed_cb (EmpathyTpFile *tp_file,
- GParamSpec *pspec,
- EmpathyFTManager *ft_manager)
-{
- EmpathyFTManagerPriv *priv;
- gboolean remove;
-
- priv = GET_PRIV (ft_manager);
-
- switch (empathy_tp_file_get_state (tp_file))
- {
- case EMP_FILE_TRANSFER_STATE_COMPLETED:
- if (empathy_tp_file_get_incoming (tp_file))
- {
- GtkRecentManager *manager;
- const gchar *uri;
-
- manager = gtk_recent_manager_get_default ();
- uri = g_object_get_data (G_OBJECT (tp_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, tp_file);
- else
- update_ft_row (ft_manager, tp_file);
-}
-
-static void
-ft_manager_add_tp_file_to_list (EmpathyFTManager *ft_manager,
- EmpathyTpFile *tp_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,
- tp_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 (tp_file);
- g_hash_table_insert (priv->tp_file_to_row_ref, tp_file, row_ref);
-
- update_ft_row (ft_manager, tp_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 (tp_file, "notify::state",
- G_CALLBACK (state_changed_cb), ft_manager);
- g_signal_connect (tp_file, "notify::transferred-bytes",
- G_CALLBACK (transferred_bytes_changed_cb), ft_manager);
-
- mime = gnome_vfs_get_mime_type_for_name (empathy_tp_file_get_filename (tp_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)
{
@@ -647,72 +448,6 @@ progress_cell_data_func (GtkTreeViewColumn *col,
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;
- EmpathyTpFile *tp_file = key;
-
- switch (empathy_tp_file_get_state (tp_file))
- {
- case EMP_FILE_TRANSFER_STATE_COMPLETED:
- case EMP_FILE_TRANSFER_STATE_CANCELED:
- *list = g_slist_append (*list, tp_file);
- break;
- default:
- break;
- }
-}
-
-static void
-ft_manager_clear (EmpathyFTManager *ft_manager)
-{
- EmpathyFTManagerPriv *priv;
- GSList *closed_files = NULL;
- GSList *l;
-
- priv = GET_PRIV (ft_manager);
-
- DEBUG ("Clearing file transfer list");
-
- g_hash_table_foreach (priv->tp_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);
- }
-
- 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->tp_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)
{
@@ -750,127 +485,6 @@ ft_manager_configure_event_cb (GtkWidget *widget,
}
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);
-
- gtk_tree_view_set_enable_search (GTK_TREE_VIEW (priv->treeview), FALSE);
-
- 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);
-}
-
-static void
ft_manager_remove_file_from_list (EmpathyFTManager *ft_manager,
EmpathyTpFile *tp_file)
{
@@ -936,6 +550,160 @@ ft_manager_remove_file_from_list (EmpathyFTManager *ft_manager,
}
static void
+ft_manager_clear_foreach_cb (gpointer key,
+ gpointer value,
+ gpointer user_data)
+{
+ GSList **list = user_data;
+ EmpathyTpFile *tp_file = key;
+
+ switch (empathy_tp_file_get_state (tp_file))
+ {
+ case EMP_FILE_TRANSFER_STATE_COMPLETED:
+ case EMP_FILE_TRANSFER_STATE_CANCELED:
+ *list = g_slist_append (*list, tp_file);
+ break;
+ default:
+ break;
+ }
+}
+
+static void
+ft_manager_clear (EmpathyFTManager *ft_manager)
+{
+ EmpathyFTManagerPriv *priv;
+ GSList *closed_files = NULL;
+ GSList *l;
+
+ priv = GET_PRIV (ft_manager);
+
+ DEBUG ("Clearing file transfer list");
+
+ g_hash_table_foreach (priv->tp_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);
+ }
+
+ g_slist_free (closed_files);
+}
+
+static void
+state_changed_cb (EmpathyTpFile *tp_file,
+ GParamSpec *pspec,
+ EmpathyFTManager *ft_manager)
+{
+ EmpathyFTManagerPriv *priv;
+ gboolean remove;
+
+ priv = GET_PRIV (ft_manager);
+
+ switch (empathy_tp_file_get_state (tp_file))
+ {
+ case EMP_FILE_TRANSFER_STATE_COMPLETED:
+ if (empathy_tp_file_get_incoming (tp_file))
+ {
+ GtkRecentManager *manager;
+ const gchar *uri;
+
+ manager = gtk_recent_manager_get_default ();
+ uri = g_object_get_data (G_OBJECT (tp_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, tp_file);
+ else
+ update_ft_row (ft_manager, tp_file);
+}
+
+static void
+ft_manager_add_tp_file_to_list (EmpathyFTManager *ft_manager,
+ EmpathyTpFile *tp_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,
+ tp_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 (tp_file);
+ g_hash_table_insert (priv->tp_file_to_row_ref, tp_file, row_ref);
+
+ update_ft_row (ft_manager, tp_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 (tp_file, "notify::state",
+ G_CALLBACK (state_changed_cb), ft_manager);
+ g_signal_connect (tp_file, "notify::transferred-bytes",
+ G_CALLBACK (transferred_bytes_changed_cb), ft_manager);
+
+ mime = gnome_vfs_get_mime_type_for_name (empathy_tp_file_get_filename (tp_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
ft_manager_open (EmpathyFTManager *ft_manager)
{
EmpathyFTManagerPriv *priv;
@@ -1165,7 +933,7 @@ ft_manager_receive_file_response_cb (GtkWidget *dialog,
gtk_widget_destroy (dialog);
}
-void
+static void
ft_manager_display_accept_dialog (EmpathyFTManager *ft_manager,
EmpathyTpFile *tp_file)
{
@@ -1239,3 +1007,222 @@ ft_manager_display_accept_dialog (EmpathyFTManager *ft_manager,
g_free (size_str);
}
+/**
+ * empathy_ft_manager_add_tp_file:
+ * @ft_manager: an #EmpathyFTManager
+ * @ft: an #EmpathyFT
+ *
+ * Adds a file transfer to the file transfer manager dialog @ft_manager.
+ * The manager dialog then shows the progress and other information about
+ * @ft.
+ */
+void
+empathy_ft_manager_add_tp_file (EmpathyFTManager *ft_manager,
+ EmpathyTpFile *tp_file)
+{
+ EmpFileTransferState state;
+
+ g_return_if_fail (EMPATHY_IS_FT_MANAGER (ft_manager));
+ g_return_if_fail (EMPATHY_IS_TP_FILE (tp_file));
+
+ DEBUG ("Adding a file transfer: contact=%s, filename=%s",
+ empathy_contact_get_name (empathy_tp_file_get_contact (tp_file)),
+ empathy_tp_file_get_filename (tp_file));
+
+ state = empathy_tp_file_get_state (tp_file);
+
+ if (state == EMP_FILE_TRANSFER_STATE_LOCAL_PENDING)
+ ft_manager_display_accept_dialog (ft_manager, tp_file);
+ else
+ ft_manager_add_tp_file_to_list (ft_manager, tp_file);
+}
+
+static void
+empathy_ft_manager_finalize (GObject *object)
+{
+ EmpathyFTManagerPriv *priv;
+
+ DEBUG ("Finalizing: %p", object);
+
+ priv = GET_PRIV (object);
+
+ g_hash_table_destroy (priv->tp_file_to_row_ref);
+
+ if (priv->save_geometry_id != 0)
+ g_source_remove (priv->save_geometry_id);
+
+ manager_p = NULL;
+
+ G_OBJECT_CLASS (empathy_ft_manager_parent_class)->finalize (object);
+}
+
+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->tp_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 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);
+
+ gtk_tree_view_set_enable_search (GTK_TREE_VIEW (priv->treeview), FALSE);
+
+ 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);
+}
+
+static void
+empathy_ft_manager_init (EmpathyFTManager *ft_manager)
+{
+ EmpathyFTManagerPriv *priv;
+
+ priv = GET_PRIV (ft_manager);
+
+ priv->tp_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);
+}
+
+static void
+empathy_ft_manager_class_init (EmpathyFTManagerClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->finalize = empathy_ft_manager_finalize;
+
+ g_type_class_add_private (object_class, sizeof (EmpathyFTManagerPriv));
+}
+
+