2 * Copyright (C) 2002-2007 Imendio AB
3 * Copyright (C) 2007-2010 Collabora Ltd.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of the
8 * License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public
16 * License along with this program; if not, write to the
17 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18 * Boston, MA 02110-1301 USA
20 * Authors: Xavier Claessens <xclaesse@gmail.com>
21 * Danielle Madeley <danielle.madeley@collabora.co.uk>
28 #include <gdk/gdkkeysyms.h>
29 #include <glib/gi18n.h>
31 #include <telepathy-glib/account-manager.h>
32 #include <telepathy-glib/util.h>
33 #include <folks/folks.h>
35 #include <libempathy/empathy-contact.h>
36 #include <libempathy/empathy-utils.h>
37 #include <libempathy/empathy-request-util.h>
38 #include <libempathy/empathy-chatroom-manager.h>
39 #include <libempathy/empathy-chatroom.h>
40 #include <libempathy/empathy-contact-list.h>
41 #include <libempathy/empathy-gsettings.h>
42 #include <libempathy/empathy-individual-manager.h>
43 #include <libempathy/empathy-gsettings.h>
44 #include <libempathy/empathy-status-presets.h>
45 #include <libempathy/empathy-tp-contact-factory.h>
47 #include <libempathy-gtk/empathy-contact-dialogs.h>
48 #include <libempathy-gtk/empathy-live-search.h>
49 #include <libempathy-gtk/empathy-contact-blocking-dialog.h>
50 #include <libempathy-gtk/empathy-contact-search-dialog.h>
51 #include <libempathy-gtk/empathy-geometry.h>
52 #include <libempathy-gtk/empathy-gtk-enum-types.h>
53 #include <libempathy-gtk/empathy-individual-dialogs.h>
54 #include <libempathy-gtk/empathy-individual-store.h>
55 #include <libempathy-gtk/empathy-individual-store-manager.h>
56 #include <libempathy-gtk/empathy-individual-view.h>
57 #include <libempathy-gtk/empathy-new-message-dialog.h>
58 #include <libempathy-gtk/empathy-new-call-dialog.h>
59 #include <libempathy-gtk/empathy-log-window.h>
60 #include <libempathy-gtk/empathy-presence-chooser.h>
61 #include <libempathy-gtk/empathy-sound-manager.h>
62 #include <libempathy-gtk/empathy-ui-utils.h>
64 #include "empathy-accounts-dialog.h"
65 #include "empathy-call-observer.h"
66 #include "empathy-chat-manager.h"
67 #include "empathy-roster-window.h"
68 #include "empathy-preferences.h"
69 #include "empathy-about-dialog.h"
70 #include "empathy-debug-window.h"
71 #include "empathy-new-chatroom-dialog.h"
72 #include "empathy-map-view.h"
73 #include "empathy-chatrooms-window.h"
74 #include "empathy-event-manager.h"
75 #include "empathy-ft-manager.h"
77 #define DEBUG_FLAG EMPATHY_DEBUG_OTHER
78 #include <libempathy/empathy-debug.h>
80 /* Flashing delay for icons (milliseconds). */
81 #define FLASH_TIMEOUT 500
83 /* Minimum width of roster window if something goes wrong. */
86 /* Accels (menu shortcuts) can be configured and saved */
87 #define ACCELS_FILENAME "accels.txt"
89 /* Name in the geometry file */
90 #define GEOMETRY_NAME "roster-window"
94 PAGE_CONTACT_LIST = 0,
104 G_DEFINE_TYPE (EmpathyRosterWindow, empathy_roster_window, GTK_TYPE_WINDOW);
106 #define GET_PRIV(self) ((EmpathyRosterWindowPriv *)((EmpathyRosterWindow *) self)->priv)
108 struct _EmpathyRosterWindowPriv {
109 EmpathyIndividualStore *individual_store;
110 EmpathyIndividualView *individual_view;
111 TpAccountManager *account_manager;
112 EmpathyChatroomManager *chatroom_manager;
113 EmpathyEventManager *event_manager;
114 EmpathySoundManager *sound_mgr;
115 EmpathyCallObserver *call_observer;
116 guint flash_timeout_id;
120 GSettings *gsettings_ui;
121 GSettings *gsettings_contacts;
123 GtkWidget *preferences;
124 GtkWidget *main_vbox;
126 GtkWidget *throbber_tool_item;
127 GtkWidget *presence_toolbar;
128 GtkWidget *presence_chooser;
129 GtkWidget *errors_vbox;
130 GtkWidget *auth_vbox;
131 GtkWidget *search_bar;
133 GtkWidget *no_entry_label;
135 GtkToggleAction *show_protocols;
136 GtkRadioAction *sort_by_name;
137 GtkRadioAction *sort_by_status;
138 GtkRadioAction *normal_with_avatars;
139 GtkRadioAction *normal_size;
140 GtkRadioAction *compact_size;
142 GtkUIManager *ui_manager;
143 GtkAction *view_history;
144 GtkAction *room_join_favorites;
145 GtkWidget *room_menu;
146 GtkWidget *room_separator;
147 GtkWidget *edit_context;
148 GtkWidget *edit_context_separator;
150 GtkActionGroup *balance_action_group;
151 GtkAction *view_balance_show_in_roster;
152 GtkWidget *balance_vbox;
154 guint size_timeout_id;
156 /* reffed TpAccount* => visible GtkInfoBar* */
159 /* EmpathyEvent* => visible GtkInfoBar* */
162 /* stores a mapping from TpAccount to Handler ID to prevent
163 * to listen more than once to the status-changed signal */
164 GHashTable *status_changed_handlers;
166 /* Actions that are enabled when there are connected accounts */
167 GList *actions_connected;
169 gboolean shell_running;
173 roster_window_flash_stop (EmpathyRosterWindow *window)
175 EmpathyRosterWindowPriv *priv = GET_PRIV (window);
177 if (priv->flash_timeout_id == 0)
180 DEBUG ("Stop flashing");
181 g_source_remove (priv->flash_timeout_id);
182 priv->flash_timeout_id = 0;
183 priv->flash_on = FALSE;
190 EmpathyRosterWindow *window;
194 roster_window_flash_foreach (GtkTreeModel *model,
199 FlashForeachData *data = (FlashForeachData *) user_data;
200 FolksIndividual *individual;
201 EmpathyContact *contact;
202 const gchar *icon_name;
203 GtkTreePath *parent_path = NULL;
204 GtkTreeIter parent_iter;
205 GdkPixbuf *pixbuf = NULL;
207 gtk_tree_model_get (model, iter,
208 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual,
211 if (individual == NULL)
214 contact = empathy_contact_dup_from_folks_individual (individual);
215 if (contact != data->event->contact)
220 icon_name = data->event->icon_name;
221 pixbuf = empathy_pixbuf_from_icon_name (icon_name, GTK_ICON_SIZE_MENU);
225 pixbuf = empathy_individual_store_get_individual_status_icon (
226 GET_PRIV (data->window)->individual_store,
229 g_object_ref (pixbuf);
232 gtk_tree_store_set (GTK_TREE_STORE (model), iter,
233 EMPATHY_INDIVIDUAL_STORE_COL_ICON_STATUS, pixbuf,
236 /* To make sure the parent is shown correctly, we emit
237 * the row-changed signal on the parent so it prompts
238 * it to be refreshed by the filter func.
240 if (gtk_tree_model_iter_parent (model, &parent_iter, iter))
242 parent_path = gtk_tree_model_get_path (model, &parent_iter);
245 if (parent_path != NULL)
247 gtk_tree_model_row_changed (model, parent_path, &parent_iter);
248 gtk_tree_path_free (parent_path);
252 g_object_unref (individual);
253 tp_clear_object (&contact);
254 tp_clear_object (&pixbuf);
260 roster_window_flash_cb (EmpathyRosterWindow *window)
262 EmpathyRosterWindowPriv *priv = GET_PRIV (window);
265 gboolean found_event = FALSE;
266 FlashForeachData data;
268 priv->flash_on = !priv->flash_on;
269 data.on = priv->flash_on;
270 model = GTK_TREE_MODEL (priv->individual_store);
272 events = empathy_event_manager_get_events (priv->event_manager);
273 for (l = events; l; l = l->next)
275 data.event = l->data;
276 data.window = window;
277 if (!data.event->contact || !data.event->must_ack)
281 gtk_tree_model_foreach (model,
282 roster_window_flash_foreach,
287 roster_window_flash_stop (window);
293 roster_window_flash_start (EmpathyRosterWindow *window)
295 EmpathyRosterWindowPriv *priv = GET_PRIV (window);
297 if (priv->flash_timeout_id != 0)
300 DEBUG ("Start flashing");
301 priv->flash_timeout_id = g_timeout_add (FLASH_TIMEOUT,
302 (GSourceFunc) roster_window_flash_cb,
305 roster_window_flash_cb (window);
309 roster_window_remove_auth (EmpathyRosterWindow *window,
312 EmpathyRosterWindowPriv *priv = GET_PRIV (window);
313 GtkWidget *error_widget;
315 error_widget = g_hash_table_lookup (priv->auths, event);
316 if (error_widget != NULL)
318 gtk_widget_destroy (error_widget);
319 g_hash_table_remove (priv->auths, event);
324 roster_window_auth_add_clicked_cb (GtkButton *button,
325 EmpathyRosterWindow *window)
329 event = g_object_get_data (G_OBJECT (button), "event");
331 empathy_event_approve (event);
333 roster_window_remove_auth (window, event);
337 roster_window_auth_close_clicked_cb (GtkButton *button,
338 EmpathyRosterWindow *window)
342 event = g_object_get_data (G_OBJECT (button), "event");
344 empathy_event_decline (event);
345 roster_window_remove_auth (window, event);
349 roster_window_auth_display (EmpathyRosterWindow *window,
352 EmpathyRosterWindowPriv *priv = GET_PRIV (window);
353 TpAccount *account = event->account;
355 GtkWidget *content_area;
358 GtkWidget *add_button;
359 GtkWidget *close_button;
360 GtkWidget *action_area;
361 GtkWidget *action_grid;
362 const gchar *icon_name;
365 if (g_hash_table_lookup (priv->auths, event) != NULL)
368 info_bar = gtk_info_bar_new ();
369 gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_QUESTION);
371 gtk_widget_set_no_show_all (info_bar, TRUE);
372 gtk_box_pack_start (GTK_BOX (priv->auth_vbox), info_bar, FALSE, TRUE, 0);
373 gtk_widget_show (info_bar);
375 icon_name = tp_account_get_icon_name (account);
376 image = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_SMALL_TOOLBAR);
377 gtk_widget_show (image);
379 str = g_markup_printf_escaped ("<b>%s</b>\n%s",
380 tp_account_get_display_name (account),
381 _("Password required"));
383 label = gtk_label_new (str);
384 gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
385 gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_END);
386 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
387 gtk_widget_show (label);
391 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
392 gtk_box_pack_start (GTK_BOX (content_area), image, FALSE, FALSE, 0);
393 gtk_box_pack_start (GTK_BOX (content_area), label, TRUE, TRUE, 0);
395 image = gtk_image_new_from_stock (GTK_STOCK_ADD, GTK_ICON_SIZE_BUTTON);
396 add_button = gtk_button_new ();
397 gtk_button_set_image (GTK_BUTTON (add_button), image);
398 gtk_widget_set_tooltip_text (add_button, _("Provide Password"));
399 gtk_widget_show (add_button);
401 image = gtk_image_new_from_stock (GTK_STOCK_CLOSE, GTK_ICON_SIZE_BUTTON);
402 close_button = gtk_button_new ();
403 gtk_button_set_image (GTK_BUTTON (close_button), image);
404 gtk_widget_set_tooltip_text (close_button, _("Disconnect"));
405 gtk_widget_show (close_button);
407 action_grid = gtk_grid_new ();
408 gtk_grid_set_column_spacing (GTK_GRID (action_grid), 6);
409 gtk_widget_show (action_grid);
411 action_area = gtk_info_bar_get_action_area (GTK_INFO_BAR (info_bar));
412 gtk_box_pack_start (GTK_BOX (action_area), action_grid, FALSE, FALSE, 0);
414 gtk_grid_attach (GTK_GRID (action_grid), add_button, 0, 0, 1, 1);
415 gtk_grid_attach (GTK_GRID (action_grid), close_button, 1, 0, 1, 1);
417 g_object_set_data_full (G_OBJECT (info_bar),
418 "event", event, NULL);
419 g_object_set_data_full (G_OBJECT (add_button),
420 "event", event, NULL);
421 g_object_set_data_full (G_OBJECT (close_button),
422 "event", event, NULL);
424 g_signal_connect (add_button, "clicked",
425 G_CALLBACK (roster_window_auth_add_clicked_cb), window);
426 g_signal_connect (close_button, "clicked",
427 G_CALLBACK (roster_window_auth_close_clicked_cb), window);
429 gtk_widget_show (priv->auth_vbox);
431 g_hash_table_insert (priv->auths, event, info_bar);
435 modify_event_count (GtkTreeModel *model,
440 FolksIndividual *individual;
441 EmpathyContact *contact;
444 gtk_tree_model_get (model, iter,
445 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual,
446 EMPATHY_INDIVIDUAL_STORE_COL_EVENT_COUNT, &count,
449 if (individual == NULL)
452 increase ? count++ : count--;
454 contact = empathy_contact_dup_from_folks_individual (individual);
455 if (contact == event->contact)
456 gtk_tree_store_set (GTK_TREE_STORE (model), iter,
457 EMPATHY_INDIVIDUAL_STORE_COL_EVENT_COUNT, count, -1);
459 tp_clear_object (&contact);
460 g_object_unref (individual);
464 increase_event_count_foreach (GtkTreeModel *model,
469 EmpathyEvent *event = user_data;
471 modify_event_count (model, iter, event, TRUE);
477 increase_event_count (EmpathyRosterWindow *self,
480 EmpathyRosterWindowPriv *priv = GET_PRIV (self);
483 model = GTK_TREE_MODEL (priv->individual_store);
485 gtk_tree_model_foreach (model, increase_event_count_foreach, event);
489 decrease_event_count_foreach (GtkTreeModel *model,
494 EmpathyEvent *event = user_data;
496 modify_event_count (model, iter, event, FALSE);
502 decrease_event_count (EmpathyRosterWindow *self,
505 EmpathyRosterWindowPriv *priv = GET_PRIV (self);
508 model = GTK_TREE_MODEL (priv->individual_store);
510 gtk_tree_model_foreach (model, decrease_event_count_foreach, event);
514 roster_window_event_added_cb (EmpathyEventManager *manager,
516 EmpathyRosterWindow *window)
520 increase_event_count (window, event);
522 roster_window_flash_start (window);
524 else if (event->type == EMPATHY_EVENT_TYPE_AUTH)
526 roster_window_auth_display (window, event);
531 roster_window_event_removed_cb (EmpathyEventManager *manager,
533 EmpathyRosterWindow *window)
535 EmpathyRosterWindowPriv *priv = GET_PRIV (window);
536 FlashForeachData data;
538 if (event->type == EMPATHY_EVENT_TYPE_AUTH)
540 roster_window_remove_auth (window, event);
547 decrease_event_count (window, event);
551 data.window = window;
553 gtk_tree_model_foreach (GTK_TREE_MODEL (priv->individual_store),
554 roster_window_flash_foreach,
559 roster_window_load_events_idle_cb (gpointer user_data)
561 EmpathyRosterWindow *window = user_data;
562 EmpathyRosterWindowPriv *priv = GET_PRIV (window);
565 l = empathy_event_manager_get_events (priv->event_manager);
568 roster_window_event_added_cb (priv->event_manager, l->data,
577 roster_window_row_activated_cb (EmpathyIndividualView *view,
579 GtkTreeViewColumn *col,
580 EmpathyRosterWindow *window)
582 EmpathyRosterWindowPriv *priv = GET_PRIV (window);
583 EmpathyContact *contact = NULL;
584 FolksIndividual *individual;
589 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->individual_view));
590 gtk_tree_model_get_iter (model, &iter, path);
592 gtk_tree_model_get (model, &iter, EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL,
595 if (individual != NULL)
596 contact = empathy_contact_dup_from_folks_individual (individual);
601 /* If the contact has an event activate it, otherwise the
602 * default handler of row-activated will be called. */
603 events = empathy_event_manager_get_events (priv->event_manager);
604 for (l = events; l; l = l->next)
606 EmpathyEvent *event = l->data;
608 if (event->contact == contact)
610 DEBUG ("Activate event");
611 empathy_event_activate (event);
613 /* We don't want the default handler of this signal
614 * (e.g. open a chat) */
615 g_signal_stop_emission_by_name (view, "row-activated");
620 g_object_unref (contact);
622 tp_clear_object (&individual);
626 roster_window_row_deleted_cb (GtkTreeModel *model,
628 EmpathyRosterWindow *window)
630 EmpathyRosterWindowPriv *priv = GET_PRIV (window);
631 GtkTreeIter help_iter;
633 if (!gtk_tree_model_get_iter_first (model, &help_iter))
637 if (empathy_individual_view_is_searching (priv->individual_view))
641 tmp = g_strdup_printf ("<b><span size='xx-large'>%s</span></b>",
642 _("No match found"));
644 gtk_label_set_markup (GTK_LABEL (priv->no_entry_label), tmp);
647 gtk_label_set_line_wrap (GTK_LABEL (priv->no_entry_label),
650 gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook),
657 roster_window_row_inserted_cb (GtkTreeModel *model,
660 EmpathyRosterWindow *window)
662 EmpathyRosterWindowPriv *priv = GET_PRIV (window);
667 gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook),
669 gtk_widget_grab_focus (GTK_WIDGET (priv->individual_view));
671 /* The store is being filled, it will be done after an idle cb.
672 * So we can then get events. If we do that too soon, event's
673 * contact is not yet in the store and it won't get marked as
675 g_idle_add (roster_window_load_events_idle_cb, window);
680 roster_window_remove_error (EmpathyRosterWindow *window,
683 EmpathyRosterWindowPriv *priv = GET_PRIV (window);
684 GtkWidget *error_widget;
686 error_widget = g_hash_table_lookup (priv->errors, account);
687 if (error_widget != NULL)
689 gtk_widget_destroy (error_widget);
690 g_hash_table_remove (priv->errors, account);
695 roster_window_account_disabled_cb (TpAccountManager *manager,
697 EmpathyRosterWindow *window)
699 roster_window_remove_error (window, account);
703 roster_window_error_retry_clicked_cb (GtkButton *button,
704 EmpathyRosterWindow *window)
708 account = g_object_get_data (G_OBJECT (button), "account");
709 tp_account_reconnect_async (account, NULL, NULL);
711 roster_window_remove_error (window, account);
715 roster_window_error_edit_clicked_cb (GtkButton *button,
716 EmpathyRosterWindow *window)
720 account = g_object_get_data (G_OBJECT (button), "account");
722 empathy_accounts_dialog_show_application (
723 gtk_widget_get_screen (GTK_WIDGET (button)),
724 account, FALSE, FALSE);
726 roster_window_remove_error (window, account);
730 roster_window_error_close_clicked_cb (GtkButton *button,
731 EmpathyRosterWindow *window)
735 account = g_object_get_data (G_OBJECT (button), "account");
736 roster_window_remove_error (window, account);
740 roster_window_error_upgrade_sw_clicked_cb (GtkButton *button,
741 EmpathyRosterWindow *window)
746 account = g_object_get_data (G_OBJECT (button), "account");
747 roster_window_remove_error (window, account);
749 dialog = gtk_message_dialog_new (GTK_WINDOW (window),
750 GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR,
752 _("Sorry, %s accounts can’t be used until your %s software is updated."),
753 tp_account_get_protocol (account),
754 tp_account_get_protocol (account));
756 g_signal_connect_swapped (dialog, "response",
757 G_CALLBACK (gtk_widget_destroy),
760 gtk_widget_show (dialog);
764 roster_window_upgrade_software_error (EmpathyRosterWindow *window,
767 EmpathyRosterWindowPriv *priv = GET_PRIV (window);
769 GtkWidget *content_area;
772 GtkWidget *upgrade_button;
773 GtkWidget *close_button;
774 GtkWidget *action_area;
775 GtkWidget *action_grid;
777 const gchar *icon_name;
778 const gchar *error_message;
779 gboolean user_requested;
782 empathy_account_get_error_message (account, &user_requested);
787 str = g_markup_printf_escaped ("<b>%s</b>\n%s",
788 tp_account_get_display_name (account),
791 /* If there are other errors, remove them */
792 roster_window_remove_error (window, account);
794 info_bar = gtk_info_bar_new ();
795 gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_ERROR);
797 gtk_widget_set_no_show_all (info_bar, TRUE);
798 gtk_box_pack_start (GTK_BOX (priv->errors_vbox), info_bar, FALSE, TRUE, 0);
799 gtk_widget_show (info_bar);
801 icon_name = tp_account_get_icon_name (account);
802 image = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_SMALL_TOOLBAR);
803 gtk_widget_show (image);
805 label = gtk_label_new (str);
806 gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
807 gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_END);
808 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
809 gtk_widget_show (label);
812 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
813 gtk_box_pack_start (GTK_BOX (content_area), image, FALSE, FALSE, 0);
814 gtk_box_pack_start (GTK_BOX (content_area), label, TRUE, TRUE, 0);
816 image = gtk_image_new_from_stock (GTK_STOCK_REFRESH, GTK_ICON_SIZE_BUTTON);
817 upgrade_button = gtk_button_new ();
818 gtk_button_set_image (GTK_BUTTON (upgrade_button), image);
819 gtk_widget_set_tooltip_text (upgrade_button, _("Update software..."));
820 gtk_widget_show (upgrade_button);
822 image = gtk_image_new_from_stock (GTK_STOCK_CLOSE, GTK_ICON_SIZE_BUTTON);
823 close_button = gtk_button_new ();
824 gtk_button_set_image (GTK_BUTTON (close_button), image);
825 gtk_widget_set_tooltip_text (close_button, _("Close"));
826 gtk_widget_show (close_button);
828 action_grid = gtk_grid_new ();
829 gtk_grid_set_column_spacing (GTK_GRID (action_grid), 2);
830 gtk_widget_show (action_grid);
832 action_area = gtk_info_bar_get_action_area (GTK_INFO_BAR (info_bar));
833 gtk_box_pack_start (GTK_BOX (action_area), action_grid, FALSE, FALSE, 0);
835 gtk_grid_attach (GTK_GRID (action_grid), upgrade_button, 0, 0, 1, 1);
836 gtk_grid_attach (GTK_GRID (action_grid), close_button, 1, 0, 1, 1);
838 g_object_set_data (G_OBJECT (info_bar), "label", label);
839 g_object_set_data_full (G_OBJECT (info_bar),
840 "account", g_object_ref (account),
842 g_object_set_data_full (G_OBJECT (upgrade_button),
843 "account", g_object_ref (account),
845 g_object_set_data_full (G_OBJECT (close_button),
846 "account", g_object_ref (account),
849 g_signal_connect (upgrade_button, "clicked",
850 G_CALLBACK (roster_window_error_upgrade_sw_clicked_cb), window);
851 g_signal_connect (close_button, "clicked",
852 G_CALLBACK (roster_window_error_close_clicked_cb), window);
854 gtk_widget_set_tooltip_text (priv->errors_vbox, error_message);
855 gtk_widget_show (priv->errors_vbox);
857 g_hash_table_insert (priv->errors, g_object_ref (account), info_bar);
861 roster_window_error_display (EmpathyRosterWindow *window,
864 EmpathyRosterWindowPriv *priv = GET_PRIV (window);
866 GtkWidget *content_area;
869 GtkWidget *retry_button;
870 GtkWidget *edit_button;
871 GtkWidget *close_button;
872 GtkWidget *action_area;
873 GtkWidget *action_grid;
875 const gchar *icon_name;
876 const gchar *error_message;
877 gboolean user_requested;
879 if (!tp_strdiff (TP_ERROR_STR_SOFTWARE_UPGRADE_REQUIRED,
880 tp_account_get_detailed_error (account, NULL)))
882 roster_window_upgrade_software_error (window, account);
886 error_message = empathy_account_get_error_message (account, &user_requested);
891 str = g_markup_printf_escaped ("<b>%s</b>\n%s",
892 tp_account_get_display_name (account), error_message);
894 info_bar = g_hash_table_lookup (priv->errors, account);
897 label = g_object_get_data (G_OBJECT (info_bar), "label");
899 /* Just set the latest error and return */
900 gtk_label_set_markup (GTK_LABEL (label), str);
906 info_bar = gtk_info_bar_new ();
907 gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_ERROR);
909 gtk_widget_set_no_show_all (info_bar, TRUE);
910 gtk_box_pack_start (GTK_BOX (priv->errors_vbox), info_bar, FALSE, TRUE, 0);
911 gtk_widget_show (info_bar);
913 icon_name = tp_account_get_icon_name (account);
914 image = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_SMALL_TOOLBAR);
915 gtk_widget_show (image);
917 label = gtk_label_new (str);
918 gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
919 gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_END);
920 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
921 gtk_widget_show (label);
924 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
925 gtk_box_pack_start (GTK_BOX (content_area), image, FALSE, FALSE, 0);
926 gtk_box_pack_start (GTK_BOX (content_area), label, TRUE, TRUE, 0);
928 image = gtk_image_new_from_stock (GTK_STOCK_REFRESH, GTK_ICON_SIZE_BUTTON);
929 retry_button = gtk_button_new ();
930 gtk_button_set_image (GTK_BUTTON (retry_button), image);
931 gtk_widget_set_tooltip_text (retry_button, _("Reconnect"));
932 gtk_widget_show (retry_button);
934 image = gtk_image_new_from_stock (GTK_STOCK_EDIT, GTK_ICON_SIZE_BUTTON);
935 edit_button = gtk_button_new ();
936 gtk_button_set_image (GTK_BUTTON (edit_button), image);
937 gtk_widget_set_tooltip_text (edit_button, _("Edit Account"));
938 gtk_widget_show (edit_button);
940 image = gtk_image_new_from_stock (GTK_STOCK_CLOSE, GTK_ICON_SIZE_BUTTON);
941 close_button = gtk_button_new ();
942 gtk_button_set_image (GTK_BUTTON (close_button), image);
943 gtk_widget_set_tooltip_text (close_button, _("Close"));
944 gtk_widget_show (close_button);
946 action_grid = gtk_grid_new ();
947 gtk_grid_set_column_spacing (GTK_GRID (action_grid), 2);
948 gtk_widget_show (action_grid);
950 action_area = gtk_info_bar_get_action_area (GTK_INFO_BAR (info_bar));
951 gtk_box_pack_start (GTK_BOX (action_area), action_grid, FALSE, FALSE, 0);
953 gtk_grid_attach (GTK_GRID (action_grid), retry_button, 0, 0, 1, 1);
954 gtk_grid_attach (GTK_GRID (action_grid), edit_button, 1, 0, 1, 1);
955 gtk_grid_attach (GTK_GRID (action_grid), close_button, 2, 0, 1, 1);
957 g_object_set_data (G_OBJECT (info_bar), "label", label);
958 g_object_set_data_full (G_OBJECT (info_bar),
959 "account", g_object_ref (account),
961 g_object_set_data_full (G_OBJECT (edit_button),
962 "account", g_object_ref (account),
964 g_object_set_data_full (G_OBJECT (close_button),
965 "account", g_object_ref (account),
967 g_object_set_data_full (G_OBJECT (retry_button),
968 "account", g_object_ref (account),
971 g_signal_connect (edit_button, "clicked",
972 G_CALLBACK (roster_window_error_edit_clicked_cb), window);
973 g_signal_connect (close_button, "clicked",
974 G_CALLBACK (roster_window_error_close_clicked_cb), window);
975 g_signal_connect (retry_button, "clicked",
976 G_CALLBACK (roster_window_error_retry_clicked_cb), window);
978 gtk_widget_set_tooltip_text (priv->errors_vbox, error_message);
979 gtk_widget_show (priv->errors_vbox);
981 g_hash_table_insert (priv->errors, g_object_ref (account), info_bar);
985 roster_window_update_status (EmpathyRosterWindow *window)
987 EmpathyRosterWindowPriv *priv = GET_PRIV (window);
988 gboolean connected, connecting;
991 connected = empathy_account_manager_get_accounts_connected (&connecting);
993 /* Update the spinner state */
996 gtk_spinner_start (GTK_SPINNER (priv->throbber));
997 gtk_widget_show (priv->throbber_tool_item);
1001 gtk_spinner_stop (GTK_SPINNER (priv->throbber));
1002 gtk_widget_hide (priv->throbber_tool_item);
1005 /* Update widgets sensibility */
1006 for (l = priv->actions_connected; l; l = l->next)
1007 gtk_action_set_sensitive (l->data, connected);
1009 /* Update favourite rooms sensitivity */
1010 children = gtk_container_get_children (GTK_CONTAINER (priv->room_menu));
1011 for (l = children; l != NULL; l = l->next)
1013 if (g_object_get_data (G_OBJECT (l->data), "is_favorite") != NULL)
1014 gtk_widget_set_sensitive (GTK_WIDGET (l->data), connected);
1017 g_list_free (children);
1021 roster_window_account_to_action_name (TpAccount *account)
1025 /* action names can't have '/' in them, replace it with '.' */
1026 r = g_strdup (tp_account_get_path_suffix (account));
1027 r = g_strdelimit (r, "/", '.');
1033 roster_window_balance_activate_cb (GtkAction *action,
1034 EmpathyRosterWindow *window)
1038 uri = g_object_get_data (G_OBJECT (action), "manage-credit-uri");
1040 if (!tp_str_empty (uri))
1042 DEBUG ("Top-up credit URI: %s", uri);
1043 empathy_url_show (GTK_WIDGET (window), uri);
1047 DEBUG ("unknown protocol for top-up");
1052 roster_window_balance_update_balance (GtkAction *action,
1055 TpAccount *account = tp_connection_get_account (conn);
1058 guint scale = G_MAXINT32;
1059 const gchar *currency = "";
1062 if (!tp_connection_get_balance (conn, &amount, &scale, ¤cy))
1066 scale == G_MAXINT32 &&
1067 tp_str_empty (currency))
1069 /* unknown balance */
1070 money = g_strdup ("--");
1074 char *tmp = empathy_format_currency (amount, scale, currency);
1076 money = g_strdup_printf ("%s %s", currency, tmp);
1080 /* Translators: this string will be something like:
1081 * Top up My Account ($1.23)..." */
1082 str = g_strdup_printf (_("Top up %s (%s)..."),
1083 tp_account_get_display_name (account), money);
1085 gtk_action_set_label (action, str);
1088 /* update the money label in the roster */
1089 label = g_object_get_data (G_OBJECT (action), "money-label");
1091 gtk_label_set_text (GTK_LABEL (label), money);
1096 roster_window_balance_changed_cb (TpConnection *conn,
1099 const gchar *currency,
1102 roster_window_balance_update_balance (action, conn);
1106 roster_window_setup_balance_create_action (EmpathyRosterWindow *window,
1109 EmpathyRosterWindowPriv *priv = GET_PRIV (window);
1113 GError *error = NULL;
1115 /* create the action group if required */
1116 if (priv->balance_action_group == NULL)
1118 priv->balance_action_group =
1119 gtk_action_group_new ("balance-action-group");
1121 gtk_ui_manager_insert_action_group (priv->ui_manager,
1122 priv->balance_action_group, -1);
1125 /* create the action */
1126 name = roster_window_account_to_action_name (account);
1127 action = gtk_action_new (name,
1128 tp_account_get_display_name (account),
1129 _("Top up account credit"), NULL);
1131 g_object_bind_property (account, "icon-name", action, "icon-name",
1132 G_BINDING_SYNC_CREATE);
1134 g_signal_connect (action, "activate",
1135 G_CALLBACK (roster_window_balance_activate_cb), window);
1137 gtk_action_group_add_action (priv->balance_action_group, action);
1138 g_object_unref (action);
1140 ui = g_strdup_printf (
1142 " <menubar name='menubar'>"
1143 " <menu action='view'>"
1144 " <placeholder name='view_balance_placeholder'>"
1145 " <menuitem action='%s'/>"
1152 merge_id = gtk_ui_manager_add_ui_from_string (priv->ui_manager,
1157 DEBUG ("Failed to add balance UI for %s: %s",
1158 tp_account_get_display_name (account),
1160 g_error_free (error);
1163 g_object_set_data (G_OBJECT (action),
1164 "merge-id", GUINT_TO_POINTER (merge_id));
1173 roster_window_setup_balance_create_widget (EmpathyRosterWindow *window,
1177 EmpathyRosterWindowPriv *priv = GET_PRIV (window);
1178 GtkWidget *hbox, *image, *label, *button;
1180 hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
1183 image = gtk_image_new ();
1184 gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, TRUE, 0);
1185 g_object_bind_property (action, "icon-name", image, "icon-name",
1186 G_BINDING_SYNC_CREATE);
1188 /* account name label */
1189 label = gtk_label_new ("");
1190 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
1191 gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 0);
1192 g_object_bind_property (account, "display-name", label, "label",
1193 G_BINDING_SYNC_CREATE);
1196 label = gtk_label_new ("");
1197 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
1198 gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, TRUE, 0);
1199 g_object_set_data (G_OBJECT (action), "money-label", label);
1202 button = gtk_button_new_with_label (_("Top Up..."));
1203 gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, TRUE, 0);
1204 g_signal_connect_swapped (button, "clicked",
1205 G_CALLBACK (gtk_action_activate), action);
1207 gtk_box_pack_start (GTK_BOX (priv->balance_vbox), hbox, FALSE, TRUE, 0);
1208 gtk_widget_show_all (hbox);
1210 /* tie the lifetime of the widget to the lifetime of the action */
1211 g_object_weak_ref (G_OBJECT (action),
1212 (GWeakNotify) gtk_widget_destroy, hbox);
1218 roster_window_setup_balance (EmpathyRosterWindow *window,
1221 EmpathyRosterWindowPriv *priv = GET_PRIV (window);
1222 TpConnection *conn = tp_account_get_connection (account);
1229 if (!tp_proxy_is_prepared (conn, TP_CONNECTION_FEATURE_BALANCE))
1232 DEBUG ("Setting up balance for acct: %s",
1233 tp_account_get_display_name (account));
1235 /* create the action */
1236 action = roster_window_setup_balance_create_action (window, account);
1241 gtk_action_set_visible (priv->view_balance_show_in_roster, TRUE);
1243 /* create the display widget */
1244 roster_window_setup_balance_create_widget (window, action, account);
1246 /* check the current balance and monitor for any changes */
1247 uri = tp_connection_get_balance_uri (conn);
1249 g_object_set_data_full (G_OBJECT (action), "manage-credit-uri",
1250 g_strdup (uri), g_free);
1251 gtk_action_set_sensitive (GTK_ACTION (action), !tp_str_empty (uri));
1253 roster_window_balance_update_balance (GTK_ACTION (action), conn);
1255 g_signal_connect (conn, "balance-changed",
1256 G_CALLBACK (roster_window_balance_changed_cb), action);
1260 roster_window_remove_balance_action (EmpathyRosterWindow *window,
1263 EmpathyRosterWindowPriv *priv = GET_PRIV (window);
1268 if (priv->balance_action_group == NULL)
1271 name = roster_window_account_to_action_name (account);
1273 action = gtk_action_group_get_action (
1274 priv->balance_action_group, name);
1280 DEBUG ("Removing action");
1282 merge_id = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (action),
1285 gtk_ui_manager_remove_ui (priv->ui_manager,
1287 gtk_action_group_remove_action (
1288 priv->balance_action_group, action);
1293 a = gtk_action_group_list_actions (
1294 priv->balance_action_group);
1296 gtk_action_set_visible (priv->view_balance_show_in_roster,
1297 g_list_length (a) > 0);
1303 roster_window_connection_changed_cb (TpAccount *account,
1307 gchar *dbus_error_name,
1308 GHashTable *details,
1309 EmpathyRosterWindow *window)
1311 EmpathyRosterWindowPriv *priv = GET_PRIV (window);
1313 roster_window_update_status (window);
1315 if (current == TP_CONNECTION_STATUS_DISCONNECTED &&
1316 reason != TP_CONNECTION_STATUS_REASON_REQUESTED)
1318 roster_window_error_display (window, account);
1321 if (current == TP_CONNECTION_STATUS_DISCONNECTED)
1323 empathy_sound_manager_play (priv->sound_mgr, GTK_WIDGET (window),
1324 EMPATHY_SOUND_ACCOUNT_DISCONNECTED);
1326 /* remove balance action if required */
1327 roster_window_remove_balance_action (window, account);
1330 if (current == TP_CONNECTION_STATUS_CONNECTED)
1332 empathy_sound_manager_play (priv->sound_mgr, GTK_WIDGET (window),
1333 EMPATHY_SOUND_ACCOUNT_CONNECTED);
1335 /* Account connected without error, remove error message if any */
1336 roster_window_remove_error (window, account);
1337 roster_window_setup_balance (window, account);
1342 roster_window_accels_load (void)
1346 filename = g_build_filename (g_get_user_config_dir (),
1347 PACKAGE_NAME, ACCELS_FILENAME, NULL);
1348 if (g_file_test (filename, G_FILE_TEST_EXISTS))
1350 DEBUG ("Loading from:'%s'", filename);
1351 gtk_accel_map_load (filename);
1358 roster_window_accels_save (void)
1361 gchar *file_with_path;
1363 dir = g_build_filename (g_get_user_config_dir (), PACKAGE_NAME, NULL);
1364 g_mkdir_with_parents (dir, S_IRUSR | S_IWUSR | S_IXUSR);
1365 file_with_path = g_build_filename (dir, ACCELS_FILENAME, NULL);
1368 DEBUG ("Saving to:'%s'", file_with_path);
1369 gtk_accel_map_save (file_with_path);
1371 g_free (file_with_path);
1375 empathy_roster_window_finalize (GObject *window)
1377 EmpathyRosterWindowPriv *priv = GET_PRIV (window);
1378 GHashTableIter iter;
1379 gpointer key, value;
1381 /* Save user-defined accelerators. */
1382 roster_window_accels_save ();
1384 g_list_free (priv->actions_connected);
1386 g_object_unref (priv->account_manager);
1387 g_object_unref (priv->individual_store);
1388 g_object_unref (priv->sound_mgr);
1389 g_hash_table_unref (priv->errors);
1390 g_hash_table_unref (priv->auths);
1392 /* disconnect all handlers of status-changed signal */
1393 g_hash_table_iter_init (&iter, priv->status_changed_handlers);
1394 while (g_hash_table_iter_next (&iter, &key, &value))
1395 g_signal_handler_disconnect (TP_ACCOUNT (key), GPOINTER_TO_UINT (value));
1397 g_hash_table_unref (priv->status_changed_handlers);
1399 g_signal_handlers_disconnect_by_func (priv->event_manager,
1400 roster_window_event_added_cb, window);
1401 g_signal_handlers_disconnect_by_func (priv->event_manager,
1402 roster_window_event_removed_cb, window);
1404 g_object_unref (priv->call_observer);
1405 g_object_unref (priv->event_manager);
1406 g_object_unref (priv->ui_manager);
1407 g_object_unref (priv->chatroom_manager);
1409 g_object_unref (priv->gsettings_ui);
1410 g_object_unref (priv->gsettings_contacts);
1412 G_OBJECT_CLASS (empathy_roster_window_parent_class)->finalize (window);
1416 roster_window_key_press_event_cb (GtkWidget *window,
1420 if (event->keyval == GDK_KEY_T
1421 && event->state & GDK_SHIFT_MASK
1422 && event->state & GDK_CONTROL_MASK)
1423 empathy_chat_manager_call_undo_closed_chat ();
1429 roster_window_chat_quit_cb (GtkAction *action,
1430 EmpathyRosterWindow *window)
1432 gtk_widget_destroy (GTK_WIDGET (window));
1436 roster_window_view_history_cb (GtkAction *action,
1437 EmpathyRosterWindow *window)
1439 empathy_log_window_show (NULL, NULL, FALSE, GTK_WINDOW (window));
1443 roster_window_chat_new_message_cb (GtkAction *action,
1444 EmpathyRosterWindow *window)
1446 empathy_new_message_dialog_show (GTK_WINDOW (window));
1450 roster_window_chat_new_call_cb (GtkAction *action,
1451 EmpathyRosterWindow *window)
1453 empathy_new_call_dialog_show (GTK_WINDOW (window));
1457 roster_window_chat_add_contact_cb (GtkAction *action,
1458 EmpathyRosterWindow *window)
1460 empathy_new_individual_dialog_show (GTK_WINDOW (window));
1464 roster_window_chat_search_contacts_cb (GtkAction *action,
1465 EmpathyRosterWindow *window)
1467 GtkWidget *dialog = empathy_contact_search_dialog_new (
1468 GTK_WINDOW (window));
1470 gtk_widget_show (dialog);
1474 roster_window_view_show_ft_manager (GtkAction *action,
1475 EmpathyRosterWindow *window)
1477 empathy_ft_manager_show ();
1481 roster_window_view_show_offline_cb (GtkToggleAction *action,
1482 EmpathyRosterWindow *window)
1484 EmpathyRosterWindowPriv *priv = GET_PRIV (window);
1487 current = gtk_toggle_action_get_active (action);
1488 g_settings_set_boolean (priv->gsettings_ui,
1489 EMPATHY_PREFS_UI_SHOW_OFFLINE,
1492 empathy_individual_view_set_show_offline (priv->individual_view,
1497 roster_window_notify_sort_contact_cb (GSettings *gsettings,
1499 EmpathyRosterWindow *window)
1501 EmpathyRosterWindowPriv *priv = GET_PRIV (window);
1504 str = g_settings_get_string (gsettings, key);
1509 GEnumClass *enum_class;
1510 GEnumValue *enum_value;
1512 type = empathy_individual_store_sort_get_type ();
1513 enum_class = G_ENUM_CLASS (g_type_class_peek (type));
1514 enum_value = g_enum_get_value_by_nick (enum_class, str);
1517 /* By changing the value of the GtkRadioAction,
1518 it emits a signal that calls roster_window_view_sort_contacts_cb
1519 which updates the contacts list */
1520 gtk_radio_action_set_current_value (priv->sort_by_name,
1525 g_warning ("Wrong value for sort_criterium configuration : %s", str);
1532 roster_window_view_sort_contacts_cb (GtkRadioAction *action,
1533 GtkRadioAction *current,
1534 EmpathyRosterWindow *window)
1536 EmpathyRosterWindowPriv *priv = GET_PRIV (window);
1537 EmpathyIndividualStoreSort value;
1540 GEnumClass *enum_class;
1541 GEnumValue *enum_value;
1543 value = gtk_radio_action_get_current_value (action);
1544 group = gtk_radio_action_get_group (action);
1546 /* Get string from index */
1547 type = empathy_individual_store_sort_get_type ();
1548 enum_class = G_ENUM_CLASS (g_type_class_peek (type));
1549 enum_value = g_enum_get_value (enum_class, g_slist_index (group, current));
1552 g_warning ("No GEnumValue for EmpathyContactListSort with GtkRadioAction index:%d",
1553 g_slist_index (group, action));
1555 g_settings_set_string (priv->gsettings_contacts,
1556 EMPATHY_PREFS_CONTACTS_SORT_CRITERIUM,
1557 enum_value->value_nick);
1559 empathy_individual_store_set_sort_criterium (priv->individual_store,
1564 roster_window_view_show_protocols_cb (GtkToggleAction *action,
1565 EmpathyRosterWindow *window)
1567 EmpathyRosterWindowPriv *priv = GET_PRIV (window);
1570 value = gtk_toggle_action_get_active (action);
1572 g_settings_set_boolean (priv->gsettings_ui,
1573 EMPATHY_PREFS_UI_SHOW_PROTOCOLS,
1576 empathy_individual_store_set_show_protocols (priv->individual_store,
1580 /* Matches GtkRadioAction values set in empathy-roster-window.ui */
1581 #define CONTACT_LIST_NORMAL_SIZE_WITH_AVATARS 0
1582 #define CONTACT_LIST_NORMAL_SIZE 1
1583 #define CONTACT_LIST_COMPACT_SIZE 2
1586 roster_window_view_contacts_list_size_cb (GtkRadioAction *action,
1587 GtkRadioAction *current,
1588 EmpathyRosterWindow *window)
1590 EmpathyRosterWindowPriv *priv = GET_PRIV (window);
1591 GSettings *gsettings_ui;
1594 value = gtk_radio_action_get_current_value (action);
1595 /* create a new GSettings, so we can delay the setting until both
1597 gsettings_ui = g_settings_new (EMPATHY_PREFS_UI_SCHEMA);
1599 DEBUG ("radio button toggled, value = %i", value);
1601 g_settings_delay (gsettings_ui);
1602 g_settings_set_boolean (gsettings_ui, EMPATHY_PREFS_UI_SHOW_AVATARS,
1603 value == CONTACT_LIST_NORMAL_SIZE_WITH_AVATARS);
1605 g_settings_set_boolean (gsettings_ui, EMPATHY_PREFS_UI_COMPACT_CONTACT_LIST,
1606 value == CONTACT_LIST_COMPACT_SIZE);
1607 g_settings_apply (gsettings_ui);
1609 /* FIXME: these enums probably have the wrong namespace */
1610 empathy_individual_store_set_show_avatars (priv->individual_store,
1611 value == CONTACT_LIST_NORMAL_SIZE_WITH_AVATARS);
1612 empathy_individual_store_set_is_compact (priv->individual_store,
1613 value == CONTACT_LIST_COMPACT_SIZE);
1615 g_object_unref (gsettings_ui);
1618 static void roster_window_notify_show_protocols_cb (GSettings *gsettings,
1620 EmpathyRosterWindow *window)
1622 EmpathyRosterWindowPriv *priv = GET_PRIV (window);
1624 gtk_toggle_action_set_active (priv->show_protocols,
1625 g_settings_get_boolean (gsettings, EMPATHY_PREFS_UI_SHOW_PROTOCOLS));
1630 roster_window_notify_contact_list_size_cb (GSettings *gsettings,
1632 EmpathyRosterWindow *window)
1634 EmpathyRosterWindowPriv *priv = GET_PRIV (window);
1637 if (g_settings_get_boolean (gsettings,
1638 EMPATHY_PREFS_UI_COMPACT_CONTACT_LIST))
1639 value = CONTACT_LIST_COMPACT_SIZE;
1640 else if (g_settings_get_boolean (gsettings,
1641 EMPATHY_PREFS_UI_SHOW_AVATARS))
1642 value = CONTACT_LIST_NORMAL_SIZE_WITH_AVATARS;
1644 value = CONTACT_LIST_NORMAL_SIZE;
1646 DEBUG ("setting changed, value = %i", value);
1648 /* By changing the value of the GtkRadioAction,
1649 it emits a signal that calls roster_window_view_contacts_list_size_cb
1650 which updates the contacts list */
1651 gtk_radio_action_set_current_value (priv->normal_with_avatars, value);
1655 roster_window_edit_search_contacts_cb (GtkCheckMenuItem *item,
1656 EmpathyRosterWindow *window)
1658 EmpathyRosterWindowPriv *priv = GET_PRIV (window);
1660 empathy_individual_view_start_search (priv->individual_view);
1664 roster_window_view_show_map_cb (GtkCheckMenuItem *item,
1665 EmpathyRosterWindow *window)
1667 #ifdef HAVE_LIBCHAMPLAIN
1668 empathy_map_view_show ();
1673 join_chatroom (EmpathyChatroom *chatroom,
1679 account = empathy_chatroom_get_account (chatroom);
1680 room = empathy_chatroom_get_room (chatroom);
1682 DEBUG ("Requesting channel for '%s'", room);
1683 empathy_join_muc (account, room, timestamp);
1689 EmpathyChatroom *chatroom;
1693 } join_fav_account_sig_ctx;
1695 static join_fav_account_sig_ctx *
1696 join_fav_account_sig_ctx_new (TpAccount *account,
1697 EmpathyChatroom *chatroom,
1700 join_fav_account_sig_ctx *ctx = g_slice_new0 (
1701 join_fav_account_sig_ctx);
1703 ctx->account = g_object_ref (account);
1704 ctx->chatroom = g_object_ref (chatroom);
1705 ctx->timestamp = timestamp;
1710 join_fav_account_sig_ctx_free (join_fav_account_sig_ctx *ctx)
1712 g_object_unref (ctx->account);
1713 g_object_unref (ctx->chatroom);
1714 g_slice_free (join_fav_account_sig_ctx, ctx);
1718 account_status_changed_cb (TpAccount *account,
1719 TpConnectionStatus old_status,
1720 TpConnectionStatus new_status,
1722 gchar *dbus_error_name,
1723 GHashTable *details,
1726 join_fav_account_sig_ctx *ctx = user_data;
1730 case TP_CONNECTION_STATUS_DISCONNECTED:
1731 /* Don't wait any longer */
1735 case TP_CONNECTION_STATUS_CONNECTING:
1739 case TP_CONNECTION_STATUS_CONNECTED:
1740 /* We can join the room */
1744 g_assert_not_reached ();
1747 join_chatroom (ctx->chatroom, ctx->timestamp);
1750 g_source_remove (ctx->timeout);
1751 g_signal_handler_disconnect (account, ctx->sig_id);
1754 #define JOIN_FAVORITE_TIMEOUT 5
1757 join_favorite_timeout_cb (gpointer data)
1759 join_fav_account_sig_ctx *ctx = data;
1761 /* stop waiting for joining the favorite room */
1762 g_signal_handler_disconnect (ctx->account, ctx->sig_id);
1767 roster_window_favorite_chatroom_join (EmpathyChatroom *chatroom)
1771 account = empathy_chatroom_get_account (chatroom);
1772 if (tp_account_get_connection_status (account, NULL) !=
1773 TP_CONNECTION_STATUS_CONNECTED)
1775 join_fav_account_sig_ctx *ctx;
1777 ctx = join_fav_account_sig_ctx_new (account, chatroom,
1778 empathy_get_current_action_time ());
1780 ctx->sig_id = g_signal_connect_data (account, "status-changed",
1781 G_CALLBACK (account_status_changed_cb), ctx,
1782 (GClosureNotify) join_fav_account_sig_ctx_free, 0);
1784 ctx->timeout = g_timeout_add_seconds (JOIN_FAVORITE_TIMEOUT,
1785 join_favorite_timeout_cb, ctx);
1789 join_chatroom (chatroom, empathy_get_current_action_time ());
1793 roster_window_favorite_chatroom_menu_activate_cb (GtkMenuItem *menu_item,
1794 EmpathyChatroom *chatroom)
1796 roster_window_favorite_chatroom_join (chatroom);
1800 roster_window_favorite_chatroom_menu_add (EmpathyRosterWindow *window,
1801 EmpathyChatroom *chatroom)
1803 EmpathyRosterWindowPriv *priv = GET_PRIV (window);
1804 GtkWidget *menu_item;
1805 const gchar *name, *account_name;
1808 if (g_object_get_data (G_OBJECT (chatroom), "menu_item"))
1811 name = empathy_chatroom_get_name (chatroom);
1812 account_name = tp_account_get_display_name (
1813 empathy_chatroom_get_account (chatroom));
1814 label = g_strdup_printf ("%s (%s)", name, account_name);
1815 menu_item = gtk_menu_item_new_with_label (label);
1817 g_object_set_data (G_OBJECT (menu_item), "is_favorite",
1818 GUINT_TO_POINTER (TRUE));
1820 g_object_set_data (G_OBJECT (chatroom), "menu_item", menu_item);
1821 g_signal_connect (menu_item, "activate",
1822 G_CALLBACK (roster_window_favorite_chatroom_menu_activate_cb),
1825 gtk_menu_shell_insert (GTK_MENU_SHELL (priv->room_menu),
1828 gtk_widget_show (menu_item);
1832 roster_window_favorite_chatroom_menu_added_cb (EmpathyChatroomManager *manager,
1833 EmpathyChatroom *chatroom,
1834 EmpathyRosterWindow *window)
1836 EmpathyRosterWindowPriv *priv = GET_PRIV (window);
1838 roster_window_favorite_chatroom_menu_add (window, chatroom);
1839 gtk_widget_show (priv->room_separator);
1840 gtk_action_set_sensitive (priv->room_join_favorites, TRUE);
1844 roster_window_favorite_chatroom_menu_removed_cb (
1845 EmpathyChatroomManager *manager,
1846 EmpathyChatroom *chatroom,
1847 EmpathyRosterWindow *window)
1849 EmpathyRosterWindowPriv *priv = GET_PRIV (window);
1850 GtkWidget *menu_item;
1853 menu_item = g_object_get_data (G_OBJECT (chatroom), "menu_item");
1854 g_object_set_data (G_OBJECT (chatroom), "menu_item", NULL);
1855 gtk_widget_destroy (menu_item);
1857 chatrooms = empathy_chatroom_manager_get_chatrooms (priv->chatroom_manager,
1860 gtk_widget_show (priv->room_separator);
1862 gtk_widget_hide (priv->room_separator);
1864 gtk_action_set_sensitive (priv->room_join_favorites, chatrooms != NULL);
1865 g_list_free (chatrooms);
1869 roster_window_favorite_chatroom_menu_setup (EmpathyRosterWindow *window)
1871 EmpathyRosterWindowPriv *priv = GET_PRIV (window);
1872 GList *chatrooms, *l;
1875 priv->chatroom_manager = empathy_chatroom_manager_dup_singleton (NULL);
1876 chatrooms = empathy_chatroom_manager_get_chatrooms (
1877 priv->chatroom_manager, NULL);
1878 room = gtk_ui_manager_get_widget (priv->ui_manager,
1880 priv->room_menu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (room));
1881 priv->room_separator = gtk_ui_manager_get_widget (priv->ui_manager,
1882 "/menubar/room/room_separator");
1884 for (l = chatrooms; l; l = l->next)
1885 roster_window_favorite_chatroom_menu_add (window, l->data);
1888 gtk_widget_hide (priv->room_separator);
1890 gtk_action_set_sensitive (priv->room_join_favorites, chatrooms != NULL);
1892 g_signal_connect (priv->chatroom_manager, "chatroom-added",
1893 G_CALLBACK (roster_window_favorite_chatroom_menu_added_cb),
1896 g_signal_connect (priv->chatroom_manager, "chatroom-removed",
1897 G_CALLBACK (roster_window_favorite_chatroom_menu_removed_cb),
1900 g_list_free (chatrooms);
1904 roster_window_room_join_new_cb (GtkAction *action,
1905 EmpathyRosterWindow *window)
1907 empathy_new_chatroom_dialog_show (GTK_WINDOW (window));
1911 roster_window_room_join_favorites_cb (GtkAction *action,
1912 EmpathyRosterWindow *window)
1914 EmpathyRosterWindowPriv *priv = GET_PRIV (window);
1915 GList *chatrooms, *l;
1917 chatrooms = empathy_chatroom_manager_get_chatrooms (priv->chatroom_manager,
1920 for (l = chatrooms; l; l = l->next)
1921 roster_window_favorite_chatroom_join (l->data);
1923 g_list_free (chatrooms);
1927 roster_window_room_manage_favorites_cb (GtkAction *action,
1928 EmpathyRosterWindow *window)
1930 empathy_chatrooms_window_show (GTK_WINDOW (window));
1934 roster_window_edit_cb (GtkAction *action,
1935 EmpathyRosterWindow *window)
1937 EmpathyRosterWindowPriv *priv = GET_PRIV (window);
1940 /* FIXME: It should use the UIManager to merge the contact/group submenu */
1941 submenu = empathy_individual_view_get_individual_menu (
1942 priv->individual_view);
1948 item = GTK_MENU_ITEM (priv->edit_context);
1949 label = gtk_bin_get_child (GTK_BIN (item));
1950 gtk_label_set_text (GTK_LABEL (label), _("Contact"));
1952 gtk_widget_show (priv->edit_context);
1953 gtk_widget_show (priv->edit_context_separator);
1955 gtk_menu_item_set_submenu (item, submenu);
1960 submenu = empathy_individual_view_get_group_menu (priv->individual_view);
1966 item = GTK_MENU_ITEM (priv->edit_context);
1967 label = gtk_bin_get_child (GTK_BIN (item));
1968 gtk_label_set_text (GTK_LABEL (label), _("Group"));
1970 gtk_widget_show (priv->edit_context);
1971 gtk_widget_show (priv->edit_context_separator);
1973 gtk_menu_item_set_submenu (item, submenu);
1978 gtk_widget_hide (priv->edit_context);
1979 gtk_widget_hide (priv->edit_context_separator);
1985 roster_window_edit_accounts_cb (GtkAction *action,
1986 EmpathyRosterWindow *window)
1988 empathy_accounts_dialog_show_application (gdk_screen_get_default (),
1989 NULL, FALSE, FALSE);
1993 roster_window_edit_personal_information_cb (GtkAction *action,
1994 EmpathyRosterWindow *window)
1996 empathy_contact_personal_dialog_show (GTK_WINDOW (window));
2000 roster_window_edit_blocked_contacts_cb (GtkAction *action,
2001 EmpathyRosterWindow *window)
2005 dialog = empathy_contact_blocking_dialog_new (GTK_WINDOW (window));
2006 gtk_widget_show (dialog);
2008 g_signal_connect (dialog, "response",
2009 G_CALLBACK (gtk_widget_destroy), NULL);
2013 empathy_roster_window_show_preferences (EmpathyRosterWindow *window,
2016 EmpathyRosterWindowPriv *priv = GET_PRIV (window);
2018 if (priv->preferences == NULL)
2020 priv->preferences = empathy_preferences_new (GTK_WINDOW (window),
2021 priv->shell_running);
2022 g_object_add_weak_pointer (G_OBJECT (priv->preferences),
2023 (gpointer) &priv->preferences);
2025 gtk_widget_show (priv->preferences);
2029 gtk_window_present (GTK_WINDOW (priv->preferences));
2033 empathy_preferences_show_tab (
2034 EMPATHY_PREFERENCES (priv->preferences), tab);
2038 roster_window_edit_preferences_cb (GtkAction *action,
2039 EmpathyRosterWindow *window)
2041 empathy_roster_window_show_preferences (window, NULL);
2045 roster_window_help_about_cb (GtkAction *action,
2046 EmpathyRosterWindow *window)
2048 empathy_about_dialog_new (GTK_WINDOW (window));
2052 roster_window_help_debug_cb (GtkAction *action,
2053 EmpathyRosterWindow *window)
2055 empathy_launch_program (BIN_DIR, "empathy-debugger", NULL);
2059 roster_window_help_contents_cb (GtkAction *action,
2060 EmpathyRosterWindow *window)
2062 empathy_url_show (GTK_WIDGET (window), "ghelp:empathy");
2066 roster_window_throbber_button_press_event_cb (GtkWidget *throbber,
2067 GdkEventButton *event,
2068 EmpathyRosterWindow *window)
2070 if (event->type != GDK_BUTTON_PRESS ||
2074 empathy_accounts_dialog_show_application (
2075 gtk_widget_get_screen (GTK_WIDGET (throbber)),
2076 NULL, FALSE, FALSE);
2082 roster_window_account_removed_cb (TpAccountManager *manager,
2084 EmpathyRosterWindow *window)
2086 EmpathyRosterWindowPriv *priv = GET_PRIV (window);
2089 a = tp_account_manager_get_valid_accounts (manager);
2091 gtk_action_set_sensitive (priv->view_history,
2092 g_list_length (a) > 0);
2096 /* remove errors if any */
2097 roster_window_remove_error (window, account);
2099 /* remove the balance action if required */
2100 roster_window_remove_balance_action (window, account);
2104 roster_window_account_validity_changed_cb (TpAccountManager *manager,
2107 EmpathyRosterWindow *window)
2109 EmpathyRosterWindowPriv *priv = GET_PRIV (window);
2114 handler_id = GPOINTER_TO_UINT (g_hash_table_lookup (
2115 priv->status_changed_handlers, account));
2117 /* connect signal only if it was not connected yet */
2118 if (handler_id == 0)
2120 handler_id = g_signal_connect (account,
2122 G_CALLBACK (roster_window_connection_changed_cb),
2124 g_hash_table_insert (priv->status_changed_handlers,
2125 account, GUINT_TO_POINTER (handler_id));
2129 roster_window_account_removed_cb (manager, account, window);
2133 roster_window_notify_show_offline_cb (GSettings *gsettings,
2135 gpointer toggle_action)
2137 gtk_toggle_action_set_active (toggle_action,
2138 g_settings_get_boolean (gsettings, key));
2142 roster_window_connection_items_setup (EmpathyRosterWindow *window,
2145 EmpathyRosterWindowPriv *priv = GET_PRIV (window);
2149 const gchar *actions_connected[] = {
2151 "room_join_favorites",
2154 "chat_search_contacts",
2156 "edit_personal_information",
2157 "edit_blocked_contacts",
2158 "edit_search_contacts"
2161 for (i = 0, list = NULL; i < G_N_ELEMENTS (actions_connected); i++)
2163 action = gtk_builder_get_object (gui, actions_connected[i]);
2164 list = g_list_prepend (list, action);
2167 priv->actions_connected = list;
2171 account_manager_prepared_cb (GObject *source_object,
2172 GAsyncResult *result,
2175 GList *accounts, *j;
2176 TpAccountManager *manager = TP_ACCOUNT_MANAGER (source_object);
2177 EmpathyRosterWindow *window = user_data;
2178 EmpathyRosterWindowPriv *priv = GET_PRIV (window);
2179 GError *error = NULL;
2181 if (!tp_proxy_prepare_finish (manager, result, &error))
2183 DEBUG ("Failed to prepare account manager: %s", error->message);
2184 g_error_free (error);
2188 accounts = tp_account_manager_get_valid_accounts (priv->account_manager);
2189 for (j = accounts; j != NULL; j = j->next)
2191 TpAccount *account = TP_ACCOUNT (j->data);
2194 handler_id = g_signal_connect (account, "status-changed",
2195 G_CALLBACK (roster_window_connection_changed_cb),
2197 g_hash_table_insert (priv->status_changed_handlers,
2198 account, GUINT_TO_POINTER (handler_id));
2200 roster_window_setup_balance (window, account);
2203 g_signal_connect (manager, "account-validity-changed",
2204 G_CALLBACK (roster_window_account_validity_changed_cb), window);
2206 roster_window_update_status (window);
2208 /* Disable the "Previous Conversations" menu entry if there is no account */
2209 gtk_action_set_sensitive (priv->view_history,
2210 g_list_length (accounts) > 0);
2212 g_list_free (accounts);
2216 empathy_roster_window_set_shell_running (EmpathyRosterWindow *window,
2217 gboolean shell_running)
2219 EmpathyRosterWindowPriv *priv = GET_PRIV (window);
2221 if (priv->shell_running == shell_running)
2224 priv->shell_running = shell_running;
2225 g_object_notify (G_OBJECT (window), "shell-running");
2229 empathy_roster_window_constructor (GType type,
2230 guint n_construct_params,
2231 GObjectConstructParam *construct_params)
2233 static GObject *window = NULL;
2236 return g_object_ref (window);
2238 window = G_OBJECT_CLASS (empathy_roster_window_parent_class)->constructor (
2239 type, n_construct_params, construct_params);
2241 g_object_add_weak_pointer (window, (gpointer) &window);
2247 empathy_roster_window_set_property (GObject *object,
2249 const GValue *value,
2252 EmpathyRosterWindow *self = EMPATHY_ROSTER_WINDOW (object);
2253 EmpathyRosterWindowPriv *priv = GET_PRIV (self);
2255 switch (property_id)
2257 case PROP_SHELL_RUNNING:
2258 priv->shell_running = g_value_get_boolean (value);
2261 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2267 empathy_roster_window_get_property (GObject *object,
2272 EmpathyRosterWindow *self = EMPATHY_ROSTER_WINDOW (object);
2273 EmpathyRosterWindowPriv *priv = GET_PRIV (self);
2275 switch (property_id)
2277 case PROP_SHELL_RUNNING:
2278 g_value_set_boolean (value, priv->shell_running);
2281 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2287 empathy_roster_window_class_init (EmpathyRosterWindowClass *klass)
2289 GObjectClass *object_class = G_OBJECT_CLASS (klass);
2292 object_class->finalize = empathy_roster_window_finalize;
2293 object_class->constructor = empathy_roster_window_constructor;
2295 object_class->set_property = empathy_roster_window_set_property;
2296 object_class->get_property = empathy_roster_window_get_property;
2298 pspec = g_param_spec_boolean ("shell-running",
2300 "Whether the Shell is running or not",
2302 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
2303 g_object_class_install_property (object_class, PROP_SHELL_RUNNING, pspec);
2305 g_type_class_add_private (object_class, sizeof (EmpathyRosterWindowPriv));
2309 empathy_roster_window_init (EmpathyRosterWindow *window)
2311 EmpathyRosterWindowPriv *priv;
2312 EmpathyIndividualManager *individual_manager;
2313 GtkBuilder *gui, *gui_mgr;
2315 GtkToggleAction *show_offline_widget;
2316 GtkAction *show_map_widget;
2318 gboolean show_offline;
2320 GtkTreeModel *model;
2321 GtkWidget *search_vbox;
2324 priv = window->priv = G_TYPE_INSTANCE_GET_PRIVATE (window,
2325 EMPATHY_TYPE_ROSTER_WINDOW, EmpathyRosterWindowPriv);
2327 priv->gsettings_ui = g_settings_new (EMPATHY_PREFS_UI_SCHEMA);
2328 priv->gsettings_contacts = g_settings_new (EMPATHY_PREFS_CONTACTS_SCHEMA);
2330 priv->sound_mgr = empathy_sound_manager_dup_singleton ();
2332 gtk_window_set_title (GTK_WINDOW (window), _("Contact List"));
2333 gtk_window_set_role (GTK_WINDOW (window), "contact_list");
2334 gtk_window_set_default_size (GTK_WINDOW (window), 225, 325);
2336 /* don't finalize the widget on delete-event, just hide it */
2337 g_signal_connect (window, "delete-event",
2338 G_CALLBACK (gtk_widget_hide_on_delete), NULL);
2340 /* Set up interface */
2341 filename = empathy_file_lookup ("empathy-roster-window.ui", "src");
2342 gui = empathy_builder_get_file (filename,
2343 "main_vbox", &priv->main_vbox,
2344 "balance_vbox", &priv->balance_vbox,
2345 "errors_vbox", &priv->errors_vbox,
2346 "auth_vbox", &priv->auth_vbox,
2347 "search_vbox", &search_vbox,
2348 "presence_toolbar", &priv->presence_toolbar,
2349 "notebook", &priv->notebook,
2350 "no_entry_label", &priv->no_entry_label,
2351 "roster_scrolledwindow", &sw,
2355 /* Set UI manager */
2356 filename = empathy_file_lookup ("empathy-roster-window-menubar.ui", "src");
2357 gui_mgr = empathy_builder_get_file (filename,
2358 "ui_manager", &priv->ui_manager,
2359 "view_show_offline", &show_offline_widget,
2360 "view_show_protocols", &priv->show_protocols,
2361 "view_sort_by_name", &priv->sort_by_name,
2362 "view_sort_by_status", &priv->sort_by_status,
2363 "view_normal_size_with_avatars", &priv->normal_with_avatars,
2364 "view_normal_size", &priv->normal_size,
2365 "view_compact_size", &priv->compact_size,
2366 "view_history", &priv->view_history,
2367 "view_show_map", &show_map_widget,
2368 "room_join_favorites", &priv->room_join_favorites,
2369 "view_balance_show_in_roster", &priv->view_balance_show_in_roster,
2370 "menubar", &menubar,
2374 /* The UI manager is living in its own .ui file as Glade doesn't support
2375 * those. The GtkMenubar has to be in this file as well to we manually add
2376 * it to the first position of the vbox. */
2377 gtk_box_pack_start (GTK_BOX (priv->main_vbox), menubar, FALSE, FALSE, 0);
2378 gtk_box_reorder_child (GTK_BOX (priv->main_vbox), menubar, 0);
2380 gtk_container_add (GTK_CONTAINER (window), priv->main_vbox);
2381 gtk_widget_show (priv->main_vbox);
2383 g_signal_connect (window, "key-press-event",
2384 G_CALLBACK (roster_window_key_press_event_cb), NULL);
2386 empathy_builder_connect (gui_mgr, window,
2387 "chat_quit", "activate", roster_window_chat_quit_cb,
2388 "chat_new_message", "activate", roster_window_chat_new_message_cb,
2389 "chat_new_call", "activate", roster_window_chat_new_call_cb,
2390 "view_history", "activate", roster_window_view_history_cb,
2391 "room_join_new", "activate", roster_window_room_join_new_cb,
2392 "room_join_favorites", "activate", roster_window_room_join_favorites_cb,
2393 "room_manage_favorites", "activate", roster_window_room_manage_favorites_cb,
2394 "chat_add_contact", "activate", roster_window_chat_add_contact_cb,
2395 "chat_search_contacts", "activate", roster_window_chat_search_contacts_cb,
2396 "view_show_ft_manager", "activate", roster_window_view_show_ft_manager,
2397 "view_show_offline", "toggled", roster_window_view_show_offline_cb,
2398 "view_show_protocols", "toggled", roster_window_view_show_protocols_cb,
2399 "view_sort_by_name", "changed", roster_window_view_sort_contacts_cb,
2400 "view_normal_size_with_avatars", "changed", roster_window_view_contacts_list_size_cb,
2401 "view_show_map", "activate", roster_window_view_show_map_cb,
2402 "edit", "activate", roster_window_edit_cb,
2403 "edit_accounts", "activate", roster_window_edit_accounts_cb,
2404 "edit_personal_information", "activate", roster_window_edit_personal_information_cb,
2405 "edit_blocked_contacts", "activate", roster_window_edit_blocked_contacts_cb,
2406 "edit_preferences", "activate", roster_window_edit_preferences_cb,
2407 "edit_search_contacts", "activate", roster_window_edit_search_contacts_cb,
2408 "help_about", "activate", roster_window_help_about_cb,
2409 "help_debug", "activate", roster_window_help_debug_cb,
2410 "help_contents", "activate", roster_window_help_contents_cb,
2413 /* Set up connection related widgets. */
2414 roster_window_connection_items_setup (window, gui_mgr);
2416 g_object_ref (priv->ui_manager);
2417 g_object_unref (gui);
2418 g_object_unref (gui_mgr);
2420 #ifndef HAVE_LIBCHAMPLAIN
2421 gtk_action_set_visible (show_map_widget, FALSE);
2424 priv->account_manager = tp_account_manager_dup ();
2426 tp_proxy_prepare_async (priv->account_manager, NULL,
2427 account_manager_prepared_cb, window);
2429 priv->errors = g_hash_table_new_full (g_direct_hash, g_direct_equal,
2430 g_object_unref, NULL);
2432 priv->auths = g_hash_table_new (NULL, NULL);
2434 priv->status_changed_handlers = g_hash_table_new_full (g_direct_hash,
2435 g_direct_equal, NULL, NULL);
2438 roster_window_favorite_chatroom_menu_setup (window);
2440 priv->edit_context = gtk_ui_manager_get_widget (priv->ui_manager,
2441 "/menubar/edit/edit_context");
2442 priv->edit_context_separator = gtk_ui_manager_get_widget (
2444 "/menubar/edit/edit_context_separator");
2445 gtk_widget_hide (priv->edit_context);
2446 gtk_widget_hide (priv->edit_context_separator);
2448 /* Set up contact list. */
2449 empathy_status_presets_get_all ();
2451 /* Set up presence chooser */
2452 priv->presence_chooser = empathy_presence_chooser_new ();
2453 gtk_widget_show (priv->presence_chooser);
2454 item = gtk_tool_item_new ();
2455 gtk_widget_show (GTK_WIDGET (item));
2456 gtk_widget_set_size_request (priv->presence_chooser, 10, -1);
2457 gtk_container_add (GTK_CONTAINER (item), priv->presence_chooser);
2458 gtk_tool_item_set_is_important (item, TRUE);
2459 gtk_tool_item_set_expand (item, TRUE);
2460 gtk_toolbar_insert (GTK_TOOLBAR (priv->presence_toolbar), item, -1);
2462 /* Set up the throbber */
2463 priv->throbber = gtk_spinner_new ();
2464 gtk_widget_set_size_request (priv->throbber, 16, -1);
2465 gtk_widget_set_events (priv->throbber, GDK_BUTTON_PRESS_MASK);
2466 g_signal_connect (priv->throbber, "button-press-event",
2467 G_CALLBACK (roster_window_throbber_button_press_event_cb),
2469 gtk_widget_show (priv->throbber);
2471 item = gtk_tool_item_new ();
2472 gtk_container_set_border_width (GTK_CONTAINER (item), 6);
2473 gtk_toolbar_insert (GTK_TOOLBAR (priv->presence_toolbar), item, -1);
2474 gtk_container_add (GTK_CONTAINER (item), priv->throbber);
2475 priv->throbber_tool_item = GTK_WIDGET (item);
2477 /* XXX: this class is designed to live for the duration of the program,
2478 * so it's got a race condition between its signal handlers and its
2479 * finalization. The class is planned to be removed, so we won't fix
2480 * this before then. */
2481 individual_manager = empathy_individual_manager_dup_singleton ();
2482 priv->individual_store = EMPATHY_INDIVIDUAL_STORE (
2483 empathy_individual_store_manager_new (individual_manager));
2484 g_object_unref (individual_manager);
2486 /* For the moment, we disallow Persona drops onto the roster contact list
2487 * (e.g. from things such as the EmpathyPersonaView in the linking dialogue).
2488 * No code is hooked up to do anything on a Persona drop, so allowing them
2489 * would achieve nothing except confusion. */
2490 priv->individual_view = empathy_individual_view_new (
2491 priv->individual_store,
2492 /* EmpathyIndividualViewFeatureFlags */
2493 EMPATHY_INDIVIDUAL_VIEW_FEATURE_GROUPS_SAVE |
2494 EMPATHY_INDIVIDUAL_VIEW_FEATURE_GROUPS_RENAME |
2495 EMPATHY_INDIVIDUAL_VIEW_FEATURE_GROUPS_REMOVE |
2496 EMPATHY_INDIVIDUAL_VIEW_FEATURE_GROUPS_CHANGE |
2497 EMPATHY_INDIVIDUAL_VIEW_FEATURE_INDIVIDUAL_REMOVE |
2498 EMPATHY_INDIVIDUAL_VIEW_FEATURE_INDIVIDUAL_DROP |
2499 EMPATHY_INDIVIDUAL_VIEW_FEATURE_INDIVIDUAL_DRAG |
2500 EMPATHY_INDIVIDUAL_VIEW_FEATURE_INDIVIDUAL_TOOLTIP |
2501 EMPATHY_INDIVIDUAL_VIEW_FEATURE_INDIVIDUAL_CALL |
2502 EMPATHY_INDIVIDUAL_VIEW_FEATURE_FILE_DROP,
2503 /* EmpathyIndividualFeatureFlags */
2504 EMPATHY_INDIVIDUAL_FEATURE_CHAT |
2505 EMPATHY_INDIVIDUAL_FEATURE_CALL |
2506 EMPATHY_INDIVIDUAL_FEATURE_EDIT |
2507 EMPATHY_INDIVIDUAL_FEATURE_INFO |
2508 EMPATHY_INDIVIDUAL_FEATURE_LINK |
2509 EMPATHY_INDIVIDUAL_FEATURE_SMS |
2510 EMPATHY_INDIVIDUAL_FEATURE_CALL_PHONE);
2512 gtk_widget_show (GTK_WIDGET (priv->individual_view));
2513 gtk_container_add (GTK_CONTAINER (sw),
2514 GTK_WIDGET (priv->individual_view));
2515 g_signal_connect (priv->individual_view, "row-activated",
2516 G_CALLBACK (roster_window_row_activated_cb), window);
2518 /* Set up search bar */
2519 priv->search_bar = empathy_live_search_new (
2520 GTK_WIDGET (priv->individual_view));
2521 empathy_individual_view_set_live_search (priv->individual_view,
2522 EMPATHY_LIVE_SEARCH (priv->search_bar));
2523 gtk_box_pack_start (GTK_BOX (search_vbox), priv->search_bar,
2526 g_signal_connect_swapped (window, "map",
2527 G_CALLBACK (gtk_widget_grab_focus), priv->individual_view);
2529 /* Connect to proper signals to check if contact list is empty or not */
2530 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->individual_view));
2532 g_signal_connect (model, "row-inserted",
2533 G_CALLBACK (roster_window_row_inserted_cb), window);
2534 g_signal_connect (model, "row-deleted",
2535 G_CALLBACK (roster_window_row_deleted_cb), window);
2537 /* Load user-defined accelerators. */
2538 roster_window_accels_load ();
2540 /* Set window size. */
2541 empathy_geometry_bind (GTK_WINDOW (window), GEOMETRY_NAME);
2543 /* bind view_balance_show_in_roster */
2544 g_settings_bind (priv->gsettings_ui, "show-balance-in-roster",
2545 priv->view_balance_show_in_roster, "active",
2546 G_SETTINGS_BIND_DEFAULT);
2547 g_object_bind_property (priv->view_balance_show_in_roster, "active",
2548 priv->balance_vbox, "visible",
2549 G_BINDING_SYNC_CREATE);
2551 /* Enable event handling */
2552 priv->call_observer = empathy_call_observer_dup_singleton ();
2553 priv->event_manager = empathy_event_manager_dup_singleton ();
2555 g_signal_connect (priv->event_manager, "event-added",
2556 G_CALLBACK (roster_window_event_added_cb), window);
2557 g_signal_connect (priv->event_manager, "event-removed",
2558 G_CALLBACK (roster_window_event_removed_cb), window);
2559 g_signal_connect (priv->account_manager, "account-validity-changed",
2560 G_CALLBACK (roster_window_account_validity_changed_cb), window);
2561 g_signal_connect (priv->account_manager, "account-removed",
2562 G_CALLBACK (roster_window_account_removed_cb), window);
2563 g_signal_connect (priv->account_manager, "account-disabled",
2564 G_CALLBACK (roster_window_account_disabled_cb), window);
2566 /* Show offline ? */
2567 show_offline = g_settings_get_boolean (priv->gsettings_ui,
2568 EMPATHY_PREFS_UI_SHOW_OFFLINE);
2570 g_signal_connect (priv->gsettings_ui,
2571 "changed::" EMPATHY_PREFS_UI_SHOW_OFFLINE,
2572 G_CALLBACK (roster_window_notify_show_offline_cb), show_offline_widget);
2574 gtk_toggle_action_set_active (show_offline_widget, show_offline);
2576 /* Show protocol ? */
2577 g_signal_connect (priv->gsettings_ui,
2578 "changed::" EMPATHY_PREFS_UI_SHOW_PROTOCOLS,
2579 G_CALLBACK (roster_window_notify_show_protocols_cb), window);
2581 roster_window_notify_show_protocols_cb (priv->gsettings_ui,
2582 EMPATHY_PREFS_UI_SHOW_PROTOCOLS, window);
2584 /* Sort by name / by status ? */
2585 g_signal_connect (priv->gsettings_contacts,
2586 "changed::" EMPATHY_PREFS_CONTACTS_SORT_CRITERIUM,
2587 G_CALLBACK (roster_window_notify_sort_contact_cb), window);
2589 roster_window_notify_sort_contact_cb (priv->gsettings_contacts,
2590 EMPATHY_PREFS_CONTACTS_SORT_CRITERIUM, window);
2592 /* Contacts list size */
2593 g_signal_connect (priv->gsettings_ui,
2594 "changed::" EMPATHY_PREFS_UI_COMPACT_CONTACT_LIST,
2595 G_CALLBACK (roster_window_notify_contact_list_size_cb), window);
2597 g_signal_connect (priv->gsettings_ui,
2598 "changed::" EMPATHY_PREFS_UI_SHOW_AVATARS,
2599 G_CALLBACK (roster_window_notify_contact_list_size_cb),
2602 roster_window_notify_contact_list_size_cb (priv->gsettings_ui,
2603 EMPATHY_PREFS_UI_SHOW_AVATARS, window);
2607 empathy_roster_window_dup (void)
2609 return g_object_new (EMPATHY_TYPE_ROSTER_WINDOW, NULL);