2 * Copyright (C) 2003, 2004 Xan Lopez
3 * Copyright (C) 2007 Marco Barisione <marco@barisione.org>
4 * Copyright (C) 2008-2009 Collabora Ltd.
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public
17 * License along with this program; if not, write to the
18 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 * Boston, MA 02110-1301 USA
22 * Marco Barisione <marco@barisione.org>
23 * Jonny Lamb <jonny.lamb@collabora.co.uk>
24 * Xavier Claessens <xclaesse@gmail.com>
25 * Cosimo Cecchi <cosimo.cecchi@collabora.co.uk>
28 /* The original file transfer manager code was copied from Epiphany */
34 #include <glib/gi18n.h>
37 #define DEBUG_FLAG EMPATHY_DEBUG_FT
38 #include <libempathy/empathy-debug.h>
39 #include <libempathy/empathy-tp-file.h>
40 #include <libempathy/empathy-utils.h>
42 #include <libempathy-gtk/empathy-conf.h>
43 #include <libempathy-gtk/empathy-ui-utils.h>
44 #include <libempathy-gtk/empathy-geometry.h>
45 #include <libempathy-gtk/empathy-images.h>
47 #include "empathy-ft-manager.h"
49 #include "extensions/extensions.h"
52 * SECTION:empathy-ft-manager
53 * @short_description: File transfer dialog
54 * @see_also: #EmpathyTpFile, empathy_dispatcher_send_file()
55 * @include: libempthy-gtk/empathy-ft-manager.h
57 * The #EmpathyFTManager object represents the file transfer dialog,
58 * it can show multiple file transfers at the same time (added
59 * with empathy_ft_manager_add_tp_file()).
72 * EmpathyFTManagerPriv:
74 * Private fields of the #EmpathyFTManager class.
78 GHashTable *ft_handler_to_row_ref;
79 GHashTable *cancellable_refs;
84 GtkWidget *open_button;
85 GtkWidget *abort_button;
87 guint save_geometry_id;
88 } EmpathyFTManagerPriv;
97 G_DEFINE_TYPE (EmpathyFTManager, empathy_ft_manager, G_TYPE_OBJECT);
99 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyFTManager)
101 static EmpathyFTManager *manager_singleton = NULL;
105 ft_manager_format_interval (gint interval)
107 gint hours, mins, secs;
109 hours = interval / 3600;
110 interval -= hours * 3600;
111 mins = interval / 60;
112 interval -= mins * 60;
116 /* Translators: time left, when it is more than one hour */
117 return g_strdup_printf (_("%u:%02u.%02u"), hours, mins, secs);
119 /* Translators: time left, when is is less than one hour */
120 return g_strdup_printf (_("%02u.%02u"), mins, secs);
125 ft_manager_update_buttons (EmpathyFTManager *manager)
127 GtkTreeSelection *selection;
130 <<<<<<< HEAD:src/empathy-ft-manager.c
131 EmpathyTpFile *tp_file;
132 TpFileTransferState state;
134 EmpathyFTHandler *handler;
135 >>>>>>> Use the proper TP interface instead of emp_cli:src/empathy-ft-manager.c
136 gboolean open_enabled = FALSE;
137 gboolean abort_enabled = FALSE;
138 gboolean is_completed, is_cancelled;
139 EmpathyFTManagerPriv *priv = GET_PRIV (manager);
141 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
143 if (gtk_tree_selection_get_selected (selection, &model, &iter))
145 gtk_tree_model_get (model, &iter, COL_FT_OBJECT, &handler, -1);
147 is_completed = empathy_ft_handler_is_completed (handler);
148 is_cancelled = empathy_ft_handler_is_cancelled (handler);
150 /* I can open the file if the transfer is completed and was incoming */
151 <<<<<<< HEAD:src/empathy-ft-manager.c
152 open_enabled = (state == TP_FILE_TRANSFER_STATE_COMPLETED &&
153 empathy_tp_file_is_incoming (tp_file));
155 /* I can abort if the transfer is not already finished */
156 abort_enabled = (state != TP_FILE_TRANSFER_STATE_CANCELLED &&
157 state != TP_FILE_TRANSFER_STATE_COMPLETED);
159 open_enabled = (is_completed && empathy_ft_handler_is_incoming (handler));
161 /* I can abort if the transfer is not already finished */
162 abort_enabled = (is_cancelled == FALSE && is_completed == FALSE);
163 >>>>>>> Use the proper TP interface instead of emp_cli:src/empathy-ft-manager.c
165 g_object_unref (handler);
168 gtk_widget_set_sensitive (priv->open_button, open_enabled);
169 gtk_widget_set_sensitive (priv->abort_button, abort_enabled);
174 ft_manager_state_change_reason_to_string (TpFileTransferStateChangeReason reason)
178 case TP_FILE_TRANSFER_STATE_CHANGE_REASON_NONE:
179 return _("No reason was specified");
180 case TP_FILE_TRANSFER_STATE_CHANGE_REASON_REQUESTED:
181 return _("The change in state was requested");
182 case TP_FILE_TRANSFER_STATE_CHANGE_REASON_LOCAL_STOPPED:
183 return _("You canceled the file transfer");
184 case TP_FILE_TRANSFER_STATE_CHANGE_REASON_REMOTE_STOPPED:
185 return _("The other participant canceled the file transfer");
186 case TP_FILE_TRANSFER_STATE_CHANGE_REASON_LOCAL_ERROR:
187 return _("Error while trying to transfer the file");
188 case TP_FILE_TRANSFER_STATE_CHANGE_REASON_REMOTE_ERROR:
189 return _("The other participant is unable to transfer the file");
191 return _("Unknown reason");
196 ft_manager_selection_changed (GtkTreeSelection *selection,
197 EmpathyFTManager *manager)
199 ft_manager_update_buttons (manager);
203 ft_manager_progress_cell_data_func (GtkTreeViewColumn *col,
204 GtkCellRenderer *renderer,
209 const gchar *text = NULL;
212 gtk_tree_model_get (model, iter, COL_PERCENT, &percent, -1);
217 text = C_("file transfer percent", "Unknown");
220 g_object_set (renderer, "text", text, "value", percent, NULL);
223 static GtkTreeRowReference *
224 ft_manager_get_row_from_handler (EmpathyFTManager *manager,
225 EmpathyFTHandler *handler)
227 EmpathyFTManagerPriv *priv = GET_PRIV (manager);
229 return g_hash_table_lookup (priv->ft_handler_to_row_ref, handler);
233 ft_manager_remove_file_from_model (EmpathyFTManager *manager,
234 EmpathyFTHandler *handler)
236 GtkTreeRowReference *row_ref;
237 GtkTreeSelection *selection;
238 GtkTreePath *path = NULL;
240 gboolean update_selection;
241 GCancellable *cancellable;
242 EmpathyFTManagerPriv *priv = GET_PRIV (manager);
244 row_ref = ft_manager_get_row_from_handler (manager, handler);
245 g_return_if_fail (row_ref);
247 DEBUG ("Removing file transfer from window: contact=%s, filename=%s",
248 empathy_contact_get_name (empathy_ft_handler_get_contact (handler)),
249 empathy_ft_handler_get_filename (handler));
251 /* Get the iter from the row_ref */
252 path = gtk_tree_row_reference_get_path (row_ref);
253 gtk_tree_model_get_iter (priv->model, &iter, path);
254 gtk_tree_path_free (path);
256 /* We have to update the selection only if we are removing the selected row */
257 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
258 update_selection = gtk_tree_selection_iter_is_selected (selection, &iter);
260 /* Remove tp_file's row. After that iter points to the next row */
261 if (!gtk_list_store_remove (GTK_LIST_STORE (priv->model), &iter))
265 /* There is no next row, set iter to the last row */
266 n_row = gtk_tree_model_iter_n_children (priv->model, NULL);
268 gtk_tree_model_iter_nth_child (priv->model, &iter, NULL, n_row - 1);
270 update_selection = FALSE;
273 if (update_selection)
274 gtk_tree_selection_select_iter (selection, &iter);
276 cancellable = g_hash_table_lookup (priv->cancellable_refs, handler);
278 if (cancellable != NULL) {
279 g_cancellable_cancel (cancellable);
284 remove_finished_transfer_foreach (gpointer key,
288 EmpathyFTHandler *handler = key;
289 EmpathyFTManager *manager = user_data;
291 if (empathy_ft_handler_is_completed (handler) ||
292 empathy_ft_handler_is_cancelled (handler))
294 ft_manager_remove_file_from_model (manager, handler);
302 ft_manager_format_progress_bytes_and_percentage (guint64 current,
306 char *total_str, *current_str, *retval;
308 total_str = g_format_size_for_display (total);
309 current_str = g_format_size_for_display (current);
311 /* translators: first %s is the currently processed size, second %s is
312 * the total file size */
313 retval = g_strdup_printf (_("%s of %s"), current_str, total_str);
316 g_free (current_str);
318 if (percentage != NULL)
321 *percentage = current * 100 / total;
330 ft_manager_format_contact_info (EmpathyFTHandler *handler)
333 const char *filename, *contact_name, *first_line_format;
336 incoming = empathy_ft_handler_is_incoming (handler);
337 contact_name = empathy_contact_get_name
338 (empathy_ft_handler_get_contact (handler));
339 filename = empathy_ft_handler_get_filename (handler);
342 /* translators: first %s is filename, second %s is the contact name */
343 first_line_format = _("Receiving \"%s\" from %s");
345 /* translators: first %s is filename, second %s is the contact name */
346 first_line_format = _("Sending \"%s\" to %s");
348 retval = g_strdup_printf (first_line_format, filename, contact_name);
354 ft_manager_update_handler_message (EmpathyFTManager *manager,
355 GtkTreeRowReference *row_ref,
360 EmpathyFTManagerPriv *priv = GET_PRIV (manager);
362 /* Set new value in the store */
363 path = gtk_tree_row_reference_get_path (row_ref);
364 gtk_tree_model_get_iter (priv->model, &iter, path);
365 gtk_list_store_set (GTK_LIST_STORE (priv->model),
367 COL_MESSAGE, message ? message : "",
370 gtk_tree_path_free (path);
374 ft_manager_update_handler_progress (EmpathyFTManager *manager,
375 GtkTreeRowReference *row_ref,
380 EmpathyFTManagerPriv *priv = GET_PRIV (manager);
382 /* Set new value in the store */
383 path = gtk_tree_row_reference_get_path (row_ref);
384 gtk_tree_model_get_iter (priv->model, &iter, path);
385 gtk_list_store_set (GTK_LIST_STORE (priv->model),
387 COL_PERCENT, percentage,
390 gtk_tree_path_free (path);
395 ft_handler_transfer_error_cb (EmpathyFTHandler *handler,
397 EmpathyFTManager *manager)
399 /* TODO: implement */
403 ft_handler_transfer_done_cb (EmpathyFTHandler *handler,
404 EmpathyTpFile *tp_file,
405 EmpathyFTManager *manager)
407 const char *contact_name;
408 const char *filename;
409 char *first_line, *second_line, *message;
411 GtkTreeRowReference *row_ref;
412 EmpathyFTManagerPriv *priv = GET_PRIV (manager);
414 row_ref = ft_manager_get_row_from_handler (manager, handler);
415 g_return_if_fail (row_ref != NULL);
417 incoming = empathy_ft_handler_is_incoming (handler);
418 contact_name = empathy_contact_get_name
419 (empathy_ft_handler_get_contact (handler));
420 filename = empathy_ft_handler_get_filename (handler);
423 /* translators: first %s is filename, second %s
424 * is the contact name */
425 first_line = g_strdup_printf (_("\"%s\" received from %s"), filename,
428 /* translators: first %s is filename, second %s
429 * is the contact name */
430 first_line = g_strdup_printf (_("\"%s\" sent to %s"), filename,
433 second_line = g_strdup (_("File transfer completed"));
435 message = g_strdup_printf ("%s\n%s", first_line, second_line);
436 ft_manager_update_handler_message (manager, row_ref, message);
438 /* remove the cancellable object */
439 g_hash_table_remove (priv->cancellable_refs, handler);
442 ft_manager_update_buttons (manager);
446 g_free (second_line);
450 ft_handler_transfer_progress_cb (EmpathyFTHandler *handler,
451 guint64 current_bytes,
453 EmpathyFTManager *manager)
455 char *first_line, *second_line, *message;
457 GtkTreeRowReference *row_ref;
459 row_ref = ft_manager_get_row_from_handler (manager, handler);
460 g_return_if_fail (row_ref != NULL);
462 first_line = ft_manager_format_contact_info (handler);
463 second_line = ft_manager_format_progress_bytes_and_percentage
464 (current_bytes, total_bytes, &percentage);
466 message = g_strdup_printf ("%s\n%s", first_line, second_line);
468 ft_manager_update_handler_message (manager, row_ref, message);
469 ft_manager_update_handler_progress (manager, row_ref, percentage);
475 ft_handler_transfer_started_cb (EmpathyFTHandler *handler,
476 EmpathyTpFile *tp_file,
477 EmpathyFTManager *manager)
479 guint64 transferred_bytes, total_bytes;
481 g_signal_connect (handler, "transfer-progress",
482 G_CALLBACK (ft_handler_transfer_progress_cb), manager);
483 g_signal_connect (handler, "transfer-done",
484 G_CALLBACK (ft_handler_transfer_done_cb), manager);
486 transferred_bytes = empathy_ft_handler_get_transferred_bytes (handler);
487 total_bytes = empathy_ft_handler_get_total_bytes (handler);
489 ft_handler_transfer_progress_cb (handler, transferred_bytes, total_bytes,
494 ft_handler_hashing_done_cb (EmpathyFTHandler *handler,
495 EmpathyFTManager *manager)
497 g_signal_connect (handler, "transfer-started",
498 G_CALLBACK (ft_handler_transfer_started_cb), manager);
502 ft_handler_hashing_progress_cb (EmpathyFTHandler *handler,
503 guint64 current_bytes,
505 EmpathyFTManager *manager)
507 char *first_line, *second_line, *message;
508 GtkTreeRowReference *row_ref;
510 row_ref = ft_manager_get_row_from_handler (manager, handler);
511 g_return_if_fail (row_ref != NULL);
513 first_line = g_strdup_printf (_("Hashing \"%s\""),
514 empathy_ft_handler_get_filename (handler));
515 second_line = ft_manager_format_progress_bytes_and_percentage
516 (current_bytes, total_bytes, NULL);
518 message = g_strdup_printf ("%s\n%s", first_line, second_line);
520 ft_manager_update_handler_message (manager, row_ref, message);
526 ft_handler_hashing_started_cb (EmpathyFTHandler *handler,
527 EmpathyFTManager *manager)
530 GtkTreeRowReference *row_ref;
532 g_signal_connect (handler, "hashing-progress",
533 G_CALLBACK (ft_handler_hashing_progress_cb), manager);
534 g_signal_connect (handler, "hashing-done",
535 G_CALLBACK (ft_handler_hashing_done_cb), manager);
537 row_ref = ft_manager_get_row_from_handler (manager, handler);
538 g_return_if_fail (row_ref != NULL);
540 message = g_strdup_printf (_("Hashing \"%s\""),
541 empathy_ft_handler_get_filename (handler));
543 ft_manager_update_handler_message (manager, row_ref, message);
549 ft_manager_start_transfer (EmpathyFTManager *manager,
550 EmpathyFTHandler *handler)
552 GCancellable *cancellable;
553 EmpathyFTManagerPriv *priv;
555 priv = GET_PRIV (manager);
557 cancellable = g_cancellable_new ();
558 g_hash_table_insert (priv->cancellable_refs, g_object_ref (handler),
561 /* now connect the signals */
562 g_signal_connect (handler, "transfer-error",
563 G_CALLBACK (ft_handler_transfer_error_cb), manager);
565 if (empathy_ft_handler_is_incoming (handler)) {
566 g_signal_connect (handler, "hashing-started",
567 G_CALLBACK (ft_handler_hashing_started_cb), manager);
569 g_signal_connect (handler, "transfer-started",
570 G_CALLBACK (ft_handler_transfer_started_cb), manager);
573 empathy_ft_handler_start_transfer (handler, cancellable);
577 ft_manager_add_handler_to_list (EmpathyFTManager *manager,
578 EmpathyFTHandler *handler)
580 GtkTreeRowReference *row_ref;
582 GtkTreeSelection *selection;
585 const char *content_type;
586 char *first_line, *second_line, *message;
587 EmpathyFTManagerPriv *priv = GET_PRIV (manager);
589 /* get the icon name from the mime-type of the file. */
590 content_type = empathy_ft_handler_get_content_type (handler);
591 icon = g_content_type_get_icon (content_type);
593 /* append the handler in the store */
594 gtk_list_store_insert_with_values (GTK_LIST_STORE (priv->model),
595 &iter, G_MAXINT, COL_FT_OBJECT, handler, COL_ICON, icon, -1);
596 g_object_unref (icon);
598 /* insert the new row_ref in the hash table */
599 path = gtk_tree_model_get_path (GTK_TREE_MODEL (priv->model), &iter);
600 row_ref = gtk_tree_row_reference_new (GTK_TREE_MODEL (priv->model), path);
601 gtk_tree_path_free (path);
602 g_hash_table_insert (priv->ft_handler_to_row_ref, g_object_ref (handler),
605 /* select the new row */
606 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
607 gtk_tree_selection_select_iter (selection, &iter);
609 /* hook up the signals and start the transfer */
610 ft_manager_start_transfer (manager, handler);
612 /* update the row with the initial values */
613 first_line = ft_manager_format_contact_info (handler);
614 second_line = g_strdup (_("Waiting for the other participant's response"));
615 message = g_strdup_printf ("%s\n%s", first_line, second_line);
617 ft_manager_update_handler_message (manager, row_ref, message);
620 g_free (second_line);
625 ft_manager_clear (EmpathyFTManager *manager)
627 EmpathyFTManagerPriv *priv;
629 DEBUG ("Clearing file transfer list");
631 priv = GET_PRIV (manager);
633 /* Remove completed and cancelled transfers */
634 g_hash_table_foreach_remove (priv->ft_handler_to_row_ref,
635 remove_finished_transfer_foreach, manager);
639 ft_manager_open (EmpathyFTManager *manager)
641 GtkTreeSelection *selection;
644 EmpathyFTHandler *handler;
647 EmpathyFTManagerPriv *priv = GET_PRIV (manager);
649 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
651 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
654 gtk_tree_model_get (model, &iter, COL_FT_OBJECT, &handler, -1);
656 file = empathy_ft_handler_get_gfile (handler);
657 uri = g_file_get_uri (file);
659 DEBUG ("Opening URI: %s", uri);
660 empathy_url_show (GTK_WIDGET (priv->window), uri);
662 g_object_unref (handler);
667 ft_manager_stop (EmpathyFTManager *manager)
669 GtkTreeSelection *selection;
672 EmpathyFTHandler *handler;
673 GCancellable *cancellable;
674 EmpathyFTManagerPriv *priv;
676 priv = GET_PRIV (manager);
678 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
680 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
683 gtk_tree_model_get (model, &iter, COL_FT_OBJECT, &handler, -1);
684 g_return_if_fail (handler != NULL);
686 DEBUG ("Stopping file transfer: contact=%s, filename=%s",
687 empathy_contact_get_name (empathy_ft_handler_get_contact (handler)),
688 empathy_ft_handler_get_filename (handler));
690 cancellable = g_hash_table_lookup (priv->cancellable_refs, handler);
691 g_assert (cancellable != NULL);
693 g_cancellable_cancel (cancellable);
697 ft_manager_save_geometry_timeout_cb (EmpathyFTManager *manager)
699 EmpathyFTManagerPriv *priv = GET_PRIV (manager);
702 gtk_window_get_size (GTK_WINDOW (priv->window), &w, &h);
703 gtk_window_get_position (GTK_WINDOW (priv->window), &x, &y);
705 empathy_geometry_save ("ft-manager", x, y, w, h);
707 priv->save_geometry_id = 0;
713 ft_manager_configure_event_cb (GtkWidget *widget,
714 GdkEventConfigure *event,
715 EmpathyFTManager *manager)
717 EmpathyFTManagerPriv *priv = GET_PRIV (manager);
719 if (priv->save_geometry_id != 0)
720 g_source_remove (priv->save_geometry_id);
722 priv->save_geometry_id = g_timeout_add (500,
723 (GSourceFunc) ft_manager_save_geometry_timeout_cb, manager);
729 ft_manager_response_cb (GtkWidget *widget,
731 EmpathyFTManager *manager)
736 ft_manager_clear (manager);
739 ft_manager_open (manager);
742 ft_manager_stop (manager);
748 ft_manager_delete_event_cb (GtkWidget *widget,
750 EmpathyFTManager *manager)
752 EmpathyFTManagerPriv *priv = GET_PRIV (manager);
754 /* remove all the completed/cancelled/errored transfers */
755 ft_manager_clear (manager);
757 if (g_hash_table_size (priv->ft_handler_to_row_ref) > 0)
759 /* There is still FTs on flight, just hide the window */
760 DEBUG ("Hiding window");
761 gtk_widget_hide (widget);
769 ft_manager_destroy_cb (GtkWidget *widget,
770 EmpathyFTManager *manager)
772 g_object_unref (manager);
776 ft_manager_build_ui (EmpathyFTManager *manager)
781 GtkListStore *liststore;
782 GtkTreeViewColumn *column;
783 GtkCellRenderer *renderer;
784 GtkTreeSelection *selection;
786 EmpathyFTManagerPriv *priv = GET_PRIV (manager);
788 filename = empathy_file_lookup ("empathy-ft-manager.ui", "src");
789 gui = empathy_builder_get_file (filename,
790 "ft_manager_dialog", &priv->window,
791 "ft_list", &priv->treeview,
792 "open_button", &priv->open_button,
793 "abort_button", &priv->abort_button,
797 empathy_builder_connect (gui, manager,
798 "ft_manager_dialog", "destroy", ft_manager_destroy_cb,
799 "ft_manager_dialog", "response", ft_manager_response_cb,
800 "ft_manager_dialog", "delete-event", ft_manager_delete_event_cb,
801 "ft_manager_dialog", "configure-event", ft_manager_configure_event_cb,
804 g_object_unref (gui);
806 /* Window geometry. */
807 empathy_geometry_load ("ft-manager", &x, &y, &w, &h);
809 if (x >= 0 && y >= 0)
811 /* Let the window manager position it if we don't have
812 * good x, y coordinates. */
813 gtk_window_move (GTK_WINDOW (priv->window), x, y);
818 /* Use the defaults from the ui file if we don't have
819 * good w, h geometry. */
820 gtk_window_resize (GTK_WINDOW (priv->window), w, h);
823 /* Setup the tree view */
824 view = GTK_TREE_VIEW (priv->treeview);
825 selection = gtk_tree_view_get_selection (view);
826 gtk_tree_selection_set_mode (selection, GTK_SELECTION_BROWSE);
827 g_signal_connect (selection, "changed",
828 G_CALLBACK (ft_manager_selection_changed), manager);
829 gtk_tree_view_set_headers_visible (view, TRUE);
830 gtk_tree_view_set_enable_search (view, FALSE);
832 /* Setup the model */
833 liststore = gtk_list_store_new (5,
834 G_TYPE_INT, /* percent */
835 G_TYPE_ICON, /* icon */
836 G_TYPE_STRING, /* message */
837 G_TYPE_STRING, /* remaining */
838 G_TYPE_OBJECT); /* ft_handler */
839 gtk_tree_view_set_model (view, GTK_TREE_MODEL (liststore));
840 priv->model = GTK_TREE_MODEL (liststore);
841 g_object_unref (liststore);
843 /* Progress column */
844 column = gtk_tree_view_column_new ();
845 gtk_tree_view_column_set_title (column, _("%"));
846 gtk_tree_view_column_set_sort_column_id (column, COL_PERCENT);
847 gtk_tree_view_insert_column (view, column, -1);
849 renderer = gtk_cell_renderer_progress_new ();
850 g_object_set (renderer, "xalign", 0.5, NULL);
851 gtk_tree_view_column_pack_start (column, renderer, FALSE);
852 gtk_tree_view_column_set_cell_data_func (column, renderer,
853 ft_manager_progress_cell_data_func, NULL, NULL);
855 /* Icon and filename column*/
856 column = gtk_tree_view_column_new ();
857 gtk_tree_view_column_set_title (column, _("File"));
858 gtk_tree_view_column_set_expand (column, TRUE);
859 gtk_tree_view_column_set_resizable (column, TRUE);
860 gtk_tree_view_column_set_sort_column_id (column, COL_MESSAGE);
861 gtk_tree_view_column_set_spacing (column, 3);
862 gtk_tree_view_insert_column (view, column, -1);
864 renderer = gtk_cell_renderer_pixbuf_new ();
865 g_object_set (renderer, "xpad", 3,
866 "stock-size", GTK_ICON_SIZE_DND, NULL);
867 gtk_tree_view_column_pack_start (column, renderer, FALSE);
868 gtk_tree_view_column_set_attributes (column, renderer,
869 "gicon", COL_ICON, NULL);
871 renderer = gtk_cell_renderer_text_new ();
872 g_object_set (renderer, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
873 gtk_tree_view_column_pack_start (column, renderer, TRUE);
874 gtk_tree_view_column_set_attributes (column, renderer,
875 "text", COL_MESSAGE, NULL);
877 /* Remaining time column */
878 column = gtk_tree_view_column_new ();
879 gtk_tree_view_column_set_title (column, _("Remaining"));
880 gtk_tree_view_column_set_sort_column_id (column, COL_REMAINING);
881 gtk_tree_view_insert_column (view, column, -1);
883 renderer = gtk_cell_renderer_text_new ();
884 g_object_set (renderer, "xalign", 0.5, NULL);
885 gtk_tree_view_column_pack_start (column, renderer, FALSE);
886 gtk_tree_view_column_set_attributes (column, renderer,
887 "text", COL_REMAINING, NULL);
890 /* GObject method overrides */
893 empathy_ft_manager_finalize (GObject *object)
895 EmpathyFTManagerPriv *priv = GET_PRIV (object);
897 DEBUG ("%p", object);
899 g_hash_table_destroy (priv->ft_handler_to_row_ref);
901 if (priv->save_geometry_id != 0)
902 g_source_remove (priv->save_geometry_id);
904 G_OBJECT_CLASS (empathy_ft_manager_parent_class)->finalize (object);
908 empathy_ft_manager_init (EmpathyFTManager *manager)
910 EmpathyFTManagerPriv *priv;
912 priv = G_TYPE_INSTANCE_GET_PRIVATE ((manager), EMPATHY_TYPE_FT_MANAGER,
913 EmpathyFTManagerPriv);
915 manager->priv = priv;
917 priv->ft_handler_to_row_ref = g_hash_table_new_full (g_direct_hash,
918 g_direct_equal, (GDestroyNotify) g_object_unref,
919 (GDestroyNotify) gtk_tree_row_reference_free);
920 priv->cancellable_refs = g_hash_table_new_full (g_direct_hash, g_direct_equal,
921 (GDestroyNotify) g_object_unref, (GDestroyNotify) g_object_unref);
923 ft_manager_build_ui (manager);
927 empathy_ft_manager_constructor (GType type,
929 GObjectConstructParam *props)
933 if (manager_singleton)
935 retval = g_object_ref (manager_singleton);
939 retval = G_OBJECT_CLASS (empathy_ft_manager_parent_class)->constructor
940 (type, n_props, props);
942 manager_singleton = EMPATHY_FT_MANAGER (retval);
943 g_object_add_weak_pointer (retval, (gpointer) &manager_singleton);
950 empathy_ft_manager_class_init (EmpathyFTManagerClass *klass)
952 GObjectClass *object_class = G_OBJECT_CLASS (klass);
954 object_class->finalize = empathy_ft_manager_finalize;
955 object_class->constructor = empathy_ft_manager_constructor;
957 g_type_class_add_private (object_class, sizeof (EmpathyFTManagerPriv));
963 * empathy_ft_manager_dup_singleton:
965 * Returns a reference to the #EmpathyFTManager singleton object.
967 * Returns: a #EmpathyFTManager
970 empathy_ft_manager_dup_singleton (void)
972 return g_object_new (EMPATHY_TYPE_FT_MANAGER, NULL);
976 empathy_ft_manager_add_handler (EmpathyFTManager *manager,
977 EmpathyFTHandler *handler)
979 EmpathyFTManagerPriv *priv = GET_PRIV (manager);
981 g_return_if_fail (EMPATHY_IS_FT_MANAGER (manager));
982 g_return_if_fail (EMPATHY_IS_FT_HANDLER (handler));
984 ft_manager_add_handler_to_list (manager, handler);
985 gtk_window_present (GTK_WINDOW (priv->window));