1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * Copyright (C) 2002-2007 Imendio AB
4 * Copyright (C) 2007-2010 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
21 * Authors: Xavier Claessens <xclaesse@gmail.com>
22 * Danielle Madeley <danielle.madeley@collabora.co.uk>
29 #include <gdk/gdkkeysyms.h>
30 #include <glib/gi18n.h>
32 #include <telepathy-glib/account-manager.h>
33 #include <telepathy-glib/util.h>
34 #include <folks/folks.h>
36 #include <libempathy/empathy-contact.h>
37 #include <libempathy/empathy-utils.h>
38 #include <libempathy/empathy-request-util.h>
39 #include <libempathy/empathy-chatroom-manager.h>
40 #include <libempathy/empathy-chatroom.h>
41 #include <libempathy/empathy-contact-list.h>
42 #include <libempathy/empathy-contact-manager.h>
43 #include <libempathy/empathy-gsettings.h>
44 #include <libempathy/empathy-individual-manager.h>
45 #include <libempathy/empathy-gsettings.h>
46 #include <libempathy/empathy-status-presets.h>
47 #include <libempathy/empathy-tp-contact-factory.h>
49 #include <libempathy-gtk/empathy-contact-dialogs.h>
50 #include <libempathy-gtk/empathy-contact-list-store.h>
51 #include <libempathy-gtk/empathy-contact-list-view.h>
52 #include <libempathy-gtk/empathy-live-search.h>
53 #include <libempathy-gtk/empathy-contact-blocking-dialog.h>
54 #include <libempathy-gtk/empathy-contact-search-dialog.h>
55 #include <libempathy-gtk/empathy-geometry.h>
56 #include <libempathy-gtk/empathy-gtk-enum-types.h>
57 #include <libempathy-gtk/empathy-individual-dialogs.h>
58 #include <libempathy-gtk/empathy-individual-store.h>
59 #include <libempathy-gtk/empathy-individual-view.h>
60 #include <libempathy-gtk/empathy-new-message-dialog.h>
61 #include <libempathy-gtk/empathy-new-call-dialog.h>
62 #include <libempathy-gtk/empathy-log-window.h>
63 #include <libempathy-gtk/empathy-presence-chooser.h>
64 #include <libempathy-gtk/empathy-sound-manager.h>
65 #include <libempathy-gtk/empathy-ui-utils.h>
67 #include "empathy-accounts-dialog.h"
68 #include "empathy-call-observer.h"
69 #include "empathy-chat-manager.h"
70 #include "empathy-main-window.h"
71 #include "empathy-preferences.h"
72 #include "empathy-about-dialog.h"
73 #include "empathy-debug-window.h"
74 #include "empathy-new-chatroom-dialog.h"
75 #include "empathy-map-view.h"
76 #include "empathy-chatrooms-window.h"
77 #include "empathy-event-manager.h"
78 #include "empathy-ft-manager.h"
80 #define DEBUG_FLAG EMPATHY_DEBUG_OTHER
81 #include <libempathy/empathy-debug.h>
83 /* Flashing delay for icons (milliseconds). */
84 #define FLASH_TIMEOUT 500
86 /* Minimum width of roster window if something goes wrong. */
89 /* Accels (menu shortcuts) can be configured and saved */
90 #define ACCELS_FILENAME "accels.txt"
92 /* Name in the geometry file */
93 #define GEOMETRY_NAME "main-window"
96 PAGE_CONTACT_LIST = 0,
105 G_DEFINE_TYPE (EmpathyMainWindow, empathy_main_window, GTK_TYPE_WINDOW);
107 #define GET_PRIV(self) ((EmpathyMainWindowPriv *)((EmpathyMainWindow *) self)->priv)
109 struct _EmpathyMainWindowPriv {
110 EmpathyContactList *contact_manager;
111 EmpathyIndividualStore *individual_store;
112 EmpathyIndividualView *individual_view;
113 TpAccountManager *account_manager;
114 EmpathyChatroomManager *chatroom_manager;
115 EmpathyEventManager *event_manager;
116 EmpathySoundManager *sound_mgr;
117 EmpathyCallObserver *call_observer;
118 guint flash_timeout_id;
122 GSettings *gsettings_ui;
123 GSettings *gsettings_contacts;
125 GtkWidget *preferences;
126 GtkWidget *main_vbox;
128 GtkWidget *throbber_tool_item;
129 GtkWidget *presence_toolbar;
130 GtkWidget *presence_chooser;
131 GtkWidget *errors_vbox;
132 GtkWidget *auth_vbox;
133 GtkWidget *search_bar;
135 GtkWidget *no_entry_label;
137 GtkToggleAction *show_protocols;
138 GtkRadioAction *sort_by_name;
139 GtkRadioAction *sort_by_status;
140 GtkRadioAction *normal_with_avatars;
141 GtkRadioAction *normal_size;
142 GtkRadioAction *compact_size;
144 GtkUIManager *ui_manager;
145 GtkAction *view_history;
146 GtkAction *room_join_favorites;
147 GtkWidget *room_menu;
148 GtkWidget *room_separator;
149 GtkWidget *edit_context;
150 GtkWidget *edit_context_separator;
152 GtkActionGroup *balance_action_group;
153 GtkAction *view_balance_show_in_roster;
154 GtkWidget *balance_vbox;
156 guint size_timeout_id;
158 /* reffed TpAccount* => visible GtkInfoBar* */
161 /* EmpathyEvent* => visible GtkInfoBar* */
164 /* stores a mapping from TpAccount to Handler ID to prevent
165 * to listen more than once to the status-changed signal */
166 GHashTable *status_changed_handlers;
168 /* Actions that are enabled when there are connected accounts */
169 GList *actions_connected;
171 gboolean shell_running;
175 main_window_flash_stop (EmpathyMainWindow *window)
177 EmpathyMainWindowPriv *priv = GET_PRIV (window);
179 if (priv->flash_timeout_id == 0) {
183 DEBUG ("Stop flashing");
184 g_source_remove (priv->flash_timeout_id);
185 priv->flash_timeout_id = 0;
186 priv->flash_on = FALSE;
192 EmpathyMainWindow *window;
196 main_window_flash_foreach (GtkTreeModel *model,
201 FlashForeachData *data = (FlashForeachData *) user_data;
202 FolksIndividual *individual;
203 EmpathyContact *contact;
204 const gchar *icon_name;
205 GtkTreePath *parent_path = NULL;
206 GtkTreeIter parent_iter;
207 GdkPixbuf *pixbuf = NULL;
209 gtk_tree_model_get (model, iter,
210 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual,
213 if (individual == NULL)
216 contact = empathy_contact_dup_from_folks_individual (individual);
217 if (contact != data->event->contact)
221 icon_name = data->event->icon_name;
222 pixbuf = empathy_pixbuf_from_icon_name (icon_name, GTK_ICON_SIZE_MENU);
224 pixbuf = empathy_individual_store_get_individual_status_icon (
225 GET_PRIV (data->window)->individual_store,
228 g_object_ref (pixbuf);
231 gtk_tree_store_set (GTK_TREE_STORE (model), iter,
232 EMPATHY_INDIVIDUAL_STORE_COL_ICON_STATUS, pixbuf,
235 /* To make sure the parent is shown correctly, we emit
236 * the row-changed signal on the parent so it prompts
237 * it to be refreshed by the filter func.
239 if (gtk_tree_model_iter_parent (model, &parent_iter, iter)) {
240 parent_path = gtk_tree_model_get_path (model, &parent_iter);
243 gtk_tree_model_row_changed (model, parent_path, &parent_iter);
244 gtk_tree_path_free (parent_path);
248 g_object_unref (individual);
249 tp_clear_object (&contact);
250 tp_clear_object (&pixbuf);
256 main_window_flash_cb (EmpathyMainWindow *window)
258 EmpathyMainWindowPriv *priv = GET_PRIV (window);
261 gboolean found_event = FALSE;
262 FlashForeachData data;
264 priv->flash_on = !priv->flash_on;
265 data.on = priv->flash_on;
266 model = GTK_TREE_MODEL (priv->individual_store);
268 events = empathy_event_manager_get_events (priv->event_manager);
269 for (l = events; l; l = l->next) {
270 data.event = l->data;
271 data.window = window;
272 if (!data.event->contact || !data.event->must_ack) {
277 gtk_tree_model_foreach (model,
278 main_window_flash_foreach,
283 main_window_flash_stop (window);
290 main_window_flash_start (EmpathyMainWindow *window)
292 EmpathyMainWindowPriv *priv = GET_PRIV (window);
294 if (priv->flash_timeout_id != 0) {
298 DEBUG ("Start flashing");
299 priv->flash_timeout_id = g_timeout_add (FLASH_TIMEOUT,
300 (GSourceFunc) main_window_flash_cb,
302 main_window_flash_cb (window);
306 main_window_remove_auth (EmpathyMainWindow *window,
309 EmpathyMainWindowPriv *priv = GET_PRIV (window);
310 GtkWidget *error_widget;
312 error_widget = g_hash_table_lookup (priv->auths, event);
313 if (error_widget != NULL) {
314 gtk_widget_destroy (error_widget);
315 g_hash_table_remove (priv->auths, event);
320 main_window_auth_add_clicked_cb (GtkButton *button,
321 EmpathyMainWindow *window)
325 event = g_object_get_data (G_OBJECT (button), "event");
327 empathy_event_approve (event);
329 main_window_remove_auth (window, event);
333 main_window_auth_close_clicked_cb (GtkButton *button,
334 EmpathyMainWindow *window)
338 event = g_object_get_data (G_OBJECT (button), "event");
340 empathy_event_decline (event);
341 main_window_remove_auth (window, event);
345 main_window_auth_display (EmpathyMainWindow *window,
348 EmpathyMainWindowPriv *priv = GET_PRIV (window);
349 TpAccount *account = event->account;
351 GtkWidget *content_area;
354 GtkWidget *add_button;
355 GtkWidget *close_button;
356 GtkWidget *action_area;
357 GtkWidget *action_table;
358 const gchar *icon_name;
361 if (g_hash_table_lookup (priv->auths, event) != NULL) {
365 info_bar = gtk_info_bar_new ();
366 gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_QUESTION);
368 gtk_widget_set_no_show_all (info_bar, TRUE);
369 gtk_box_pack_start (GTK_BOX (priv->auth_vbox), info_bar, FALSE, TRUE, 0);
370 gtk_widget_show (info_bar);
372 icon_name = tp_account_get_icon_name (account);
373 image = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_SMALL_TOOLBAR);
374 gtk_widget_show (image);
376 str = g_markup_printf_escaped ("<b>%s</b>\n%s",
377 tp_account_get_display_name (account),
378 _("Password required"));
380 label = gtk_label_new (str);
381 gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
382 gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_END);
383 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
384 gtk_widget_show (label);
388 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
389 gtk_box_pack_start (GTK_BOX (content_area), image, FALSE, FALSE, 0);
390 gtk_box_pack_start (GTK_BOX (content_area), label, TRUE, TRUE, 0);
392 image = gtk_image_new_from_stock (GTK_STOCK_ADD, GTK_ICON_SIZE_BUTTON);
393 add_button = gtk_button_new ();
394 gtk_button_set_image (GTK_BUTTON (add_button), image);
395 gtk_widget_set_tooltip_text (add_button, _("Provide Password"));
396 gtk_widget_show (add_button);
398 image = gtk_image_new_from_stock (GTK_STOCK_CLOSE, GTK_ICON_SIZE_BUTTON);
399 close_button = gtk_button_new ();
400 gtk_button_set_image (GTK_BUTTON (close_button), image);
401 gtk_widget_set_tooltip_text (close_button, _("Disconnect"));
402 gtk_widget_show (close_button);
404 action_table = gtk_table_new (1, 2, FALSE);
405 gtk_table_set_col_spacings (GTK_TABLE (action_table), 6);
406 gtk_widget_show (action_table);
408 action_area = gtk_info_bar_get_action_area (GTK_INFO_BAR (info_bar));
409 gtk_box_pack_start (GTK_BOX (action_area), action_table, FALSE, FALSE, 0);
411 gtk_table_attach (GTK_TABLE (action_table), add_button, 0, 1, 0, 1,
412 (GtkAttachOptions) (GTK_SHRINK),
413 (GtkAttachOptions) (GTK_SHRINK), 0, 0);
414 gtk_table_attach (GTK_TABLE (action_table), close_button, 1, 2, 0, 1,
415 (GtkAttachOptions) (GTK_SHRINK),
416 (GtkAttachOptions) (GTK_SHRINK), 0, 0);
418 g_object_set_data_full (G_OBJECT (info_bar),
419 "event", event, NULL);
420 g_object_set_data_full (G_OBJECT (add_button),
421 "event", event, NULL);
422 g_object_set_data_full (G_OBJECT (close_button),
423 "event", event, NULL);
425 g_signal_connect (add_button, "clicked",
426 G_CALLBACK (main_window_auth_add_clicked_cb),
428 g_signal_connect (close_button, "clicked",
429 G_CALLBACK (main_window_auth_close_clicked_cb),
432 gtk_widget_show (priv->auth_vbox);
434 g_hash_table_insert (priv->auths, event, info_bar);
438 modify_event_count (GtkTreeModel *model,
443 FolksIndividual *individual;
444 EmpathyContact *contact;
447 gtk_tree_model_get (model, iter,
448 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual,
449 EMPATHY_INDIVIDUAL_STORE_COL_EVENT_COUNT, &count,
452 if (individual == NULL)
455 increase ? count++ : count--;
457 contact = empathy_contact_dup_from_folks_individual (individual);
458 if (contact == event->contact) {
459 gtk_tree_store_set (GTK_TREE_STORE (model), iter,
460 EMPATHY_INDIVIDUAL_STORE_COL_EVENT_COUNT, count, -1);
463 tp_clear_object (&contact);
464 g_object_unref (individual);
468 increase_event_count_foreach (GtkTreeModel *model,
473 EmpathyEvent *event = user_data;
475 modify_event_count (model, iter, event, TRUE);
481 increase_event_count (EmpathyMainWindow *self,
484 EmpathyMainWindowPriv *priv = GET_PRIV (self);
487 model = GTK_TREE_MODEL (priv->individual_store);
489 gtk_tree_model_foreach (model, increase_event_count_foreach, event);
493 decrease_event_count_foreach (GtkTreeModel *model,
498 EmpathyEvent *event = user_data;
500 modify_event_count (model, iter, event, FALSE);
506 decrease_event_count (EmpathyMainWindow *self,
509 EmpathyMainWindowPriv *priv = GET_PRIV (self);
512 model = GTK_TREE_MODEL (priv->individual_store);
514 gtk_tree_model_foreach (model, decrease_event_count_foreach, event);
518 main_window_event_added_cb (EmpathyEventManager *manager,
520 EmpathyMainWindow *window)
522 if (event->contact) {
523 increase_event_count (window, event);
525 main_window_flash_start (window);
526 } else if (event->type == EMPATHY_EVENT_TYPE_AUTH) {
527 main_window_auth_display (window, event);
532 main_window_event_removed_cb (EmpathyEventManager *manager,
534 EmpathyMainWindow *window)
536 EmpathyMainWindowPriv *priv = GET_PRIV (window);
537 FlashForeachData data;
539 if (event->type == EMPATHY_EVENT_TYPE_AUTH) {
540 main_window_remove_auth (window, event);
544 if (!event->contact) {
548 decrease_event_count (window, event);
552 data.window = window;
553 gtk_tree_model_foreach (GTK_TREE_MODEL (priv->individual_store),
554 main_window_flash_foreach,
559 main_window_load_events_idle_cb (gpointer user_data)
561 EmpathyMainWindow *window = user_data;
562 EmpathyMainWindowPriv *priv = GET_PRIV (window);
565 l = empathy_event_manager_get_events (priv->event_manager);
567 main_window_event_added_cb (priv->event_manager, l->data,
576 main_window_row_activated_cb (EmpathyContactListView *view,
578 GtkTreeViewColumn *col,
579 EmpathyMainWindow *window)
581 EmpathyMainWindowPriv *priv = GET_PRIV (window);
582 EmpathyContact *contact = NULL;
583 FolksIndividual *individual;
588 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->individual_view));
589 gtk_tree_model_get_iter (model, &iter, path);
591 gtk_tree_model_get (model, &iter,
592 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL,
596 if (individual != NULL) {
597 contact = empathy_contact_dup_from_folks_individual (individual);
604 /* If the contact has an event activate it, otherwise the
605 * default handler of row-activated will be called. */
606 events = empathy_event_manager_get_events (priv->event_manager);
607 for (l = events; l; l = l->next) {
608 EmpathyEvent *event = l->data;
610 if (event->contact == contact) {
611 DEBUG ("Activate event");
612 empathy_event_activate (event);
614 /* We don't want the default handler of this signal
615 * (e.g. open a chat) */
616 g_signal_stop_emission_by_name (view, "row-activated");
621 g_object_unref (contact);
623 tp_clear_object (&individual);
627 main_window_row_deleted_cb (GtkTreeModel *model,
629 EmpathyMainWindow *window)
631 EmpathyMainWindowPriv *priv = GET_PRIV (window);
632 GtkTreeIter help_iter;
634 if (!gtk_tree_model_get_iter_first (model, &help_iter)) {
637 if (empathy_individual_view_is_searching (
638 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 (
651 GTK_NOTEBOOK (priv->notebook), PAGE_NO_MATCH);
657 main_window_row_inserted_cb (GtkTreeModel *model,
660 EmpathyMainWindow *window)
662 EmpathyMainWindowPriv *priv = GET_PRIV (window);
666 gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook),
668 gtk_widget_grab_focus (GTK_WIDGET (priv->individual_view));
670 /* The store is being filled, it will be done after an idle cb.
671 * So we can then get events. If we do that too soon, event's
672 * contact is not yet in the store and it won't get marked as
674 g_idle_add (main_window_load_events_idle_cb, window);
679 main_window_remove_error (EmpathyMainWindow *window,
682 EmpathyMainWindowPriv *priv = GET_PRIV (window);
683 GtkWidget *error_widget;
685 error_widget = g_hash_table_lookup (priv->errors, account);
686 if (error_widget != NULL) {
687 gtk_widget_destroy (error_widget);
688 g_hash_table_remove (priv->errors, account);
693 main_window_account_disabled_cb (TpAccountManager *manager,
695 EmpathyMainWindow *window)
697 main_window_remove_error (window, account);
701 main_window_error_retry_clicked_cb (GtkButton *button,
702 EmpathyMainWindow *window)
706 account = g_object_get_data (G_OBJECT (button), "account");
707 tp_account_reconnect_async (account, NULL, NULL);
709 main_window_remove_error (window, account);
713 main_window_error_edit_clicked_cb (GtkButton *button,
714 EmpathyMainWindow *window)
718 account = g_object_get_data (G_OBJECT (button), "account");
720 empathy_accounts_dialog_show_application (
721 gtk_widget_get_screen (GTK_WIDGET (button)),
722 account, FALSE, FALSE);
724 main_window_remove_error (window, account);
728 main_window_error_close_clicked_cb (GtkButton *button,
729 EmpathyMainWindow *window)
733 account = g_object_get_data (G_OBJECT (button), "account");
734 main_window_remove_error (window, account);
738 main_window_error_display (EmpathyMainWindow *window,
741 EmpathyMainWindowPriv *priv = GET_PRIV (window);
743 GtkWidget *content_area;
746 GtkWidget *retry_button;
747 GtkWidget *edit_button;
748 GtkWidget *close_button;
749 GtkWidget *action_area;
750 GtkWidget *action_table;
752 const gchar *icon_name;
753 const gchar *error_message;
754 gboolean user_requested;
757 empathy_account_get_error_message (account, &user_requested);
759 if (user_requested) {
763 str = g_markup_printf_escaped ("<b>%s</b>\n%s",
764 tp_account_get_display_name (account),
767 info_bar = g_hash_table_lookup (priv->errors, account);
769 label = g_object_get_data (G_OBJECT (info_bar), "label");
771 /* Just set the latest error and return */
772 gtk_label_set_markup (GTK_LABEL (label), str);
778 info_bar = gtk_info_bar_new ();
779 gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_ERROR);
781 gtk_widget_set_no_show_all (info_bar, TRUE);
782 gtk_box_pack_start (GTK_BOX (priv->errors_vbox), info_bar, FALSE, TRUE, 0);
783 gtk_widget_show (info_bar);
785 icon_name = tp_account_get_icon_name (account);
786 image = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_SMALL_TOOLBAR);
787 gtk_widget_show (image);
789 label = gtk_label_new (str);
790 gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
791 gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_END);
792 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
793 gtk_widget_show (label);
796 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
797 gtk_box_pack_start (GTK_BOX (content_area), image, FALSE, FALSE, 0);
798 gtk_box_pack_start (GTK_BOX (content_area), label, TRUE, TRUE, 0);
800 image = gtk_image_new_from_stock (GTK_STOCK_REFRESH, GTK_ICON_SIZE_BUTTON);
801 retry_button = gtk_button_new ();
802 gtk_button_set_image (GTK_BUTTON (retry_button), image);
803 gtk_widget_set_tooltip_text (retry_button, _("Reconnect"));
804 gtk_widget_show (retry_button);
806 image = gtk_image_new_from_stock (GTK_STOCK_EDIT, GTK_ICON_SIZE_BUTTON);
807 edit_button = gtk_button_new ();
808 gtk_button_set_image (GTK_BUTTON (edit_button), image);
809 gtk_widget_set_tooltip_text (edit_button, _("Edit Account"));
810 gtk_widget_show (edit_button);
812 image = gtk_image_new_from_stock (GTK_STOCK_CLOSE, GTK_ICON_SIZE_BUTTON);
813 close_button = gtk_button_new ();
814 gtk_button_set_image (GTK_BUTTON (close_button), image);
815 gtk_widget_set_tooltip_text (close_button, _("Close"));
816 gtk_widget_show (close_button);
818 action_table = gtk_table_new (1, 3, FALSE);
819 gtk_table_set_col_spacings (GTK_TABLE (action_table), 2);
820 gtk_widget_show (action_table);
822 action_area = gtk_info_bar_get_action_area (GTK_INFO_BAR (info_bar));
823 gtk_box_pack_start (GTK_BOX (action_area), action_table, FALSE, FALSE, 0);
825 gtk_table_attach (GTK_TABLE (action_table), retry_button, 0, 1, 0, 1,
826 (GtkAttachOptions) (GTK_SHRINK),
827 (GtkAttachOptions) (GTK_SHRINK), 0, 0);
828 gtk_table_attach (GTK_TABLE (action_table), edit_button, 1, 2, 0, 1,
829 (GtkAttachOptions) (GTK_SHRINK),
830 (GtkAttachOptions) (GTK_SHRINK), 0, 0);
831 gtk_table_attach (GTK_TABLE (action_table), close_button, 2, 3, 0, 1,
832 (GtkAttachOptions) (GTK_SHRINK),
833 (GtkAttachOptions) (GTK_SHRINK), 0, 0);
835 g_object_set_data (G_OBJECT (info_bar), "label", label);
836 g_object_set_data_full (G_OBJECT (info_bar),
837 "account", g_object_ref (account),
839 g_object_set_data_full (G_OBJECT (edit_button),
840 "account", g_object_ref (account),
842 g_object_set_data_full (G_OBJECT (close_button),
843 "account", g_object_ref (account),
845 g_object_set_data_full (G_OBJECT (retry_button),
846 "account", g_object_ref (account),
849 g_signal_connect (edit_button, "clicked",
850 G_CALLBACK (main_window_error_edit_clicked_cb),
852 g_signal_connect (close_button, "clicked",
853 G_CALLBACK (main_window_error_close_clicked_cb),
855 g_signal_connect (retry_button, "clicked",
856 G_CALLBACK (main_window_error_retry_clicked_cb),
859 gtk_widget_set_tooltip_text (priv->errors_vbox, error_message);
860 gtk_widget_show (priv->errors_vbox);
862 g_hash_table_insert (priv->errors, g_object_ref (account), info_bar);
866 main_window_update_status (EmpathyMainWindow *window)
868 EmpathyMainWindowPriv *priv = GET_PRIV (window);
869 gboolean connected, connecting;
872 connected = empathy_account_manager_get_accounts_connected (&connecting);
874 /* Update the spinner state */
876 gtk_spinner_start (GTK_SPINNER (priv->throbber));
877 gtk_widget_show (priv->throbber_tool_item);
879 gtk_spinner_stop (GTK_SPINNER (priv->throbber));
880 gtk_widget_hide (priv->throbber_tool_item);
883 /* Update widgets sensibility */
884 for (l = priv->actions_connected; l; l = l->next) {
885 gtk_action_set_sensitive (l->data, connected);
888 /* Update favourite rooms sensitivity */
889 children = gtk_container_get_children (GTK_CONTAINER (priv->room_menu));
890 for (l = children; l != NULL; l = l->next) {
891 if (g_object_get_data (G_OBJECT (l->data), "is_favorite") != NULL) {
892 gtk_widget_set_sensitive (GTK_WIDGET (l->data), connected);
895 g_list_free (children);
899 main_window_account_to_action_name (TpAccount *account)
903 /* action names can't have '/' in them, replace it with '.' */
904 r = g_strdup (tp_account_get_path_suffix (account));
905 r = g_strdelimit (r, "/", '.');
911 main_window_balance_activate_cb (GtkAction *action,
912 EmpathyMainWindow *window)
916 uri = g_object_get_data (G_OBJECT (action), "manage-credit-uri");
918 if (!tp_str_empty (uri)) {
919 DEBUG ("Top-up credit URI: %s", uri);
920 empathy_url_show (GTK_WIDGET (window), uri);
922 DEBUG ("unknown protocol for top-up");
927 main_window_balance_update_balance (GtkAction *action,
930 TpAccount *account = tp_connection_get_account (conn);
933 guint scale = G_MAXINT32;
934 const gchar *currency = "";
937 if (!tp_connection_get_balance (conn, &amount, &scale, ¤cy))
941 scale == G_MAXINT32 &&
942 tp_str_empty (currency)) {
943 /* unknown balance */
944 money = g_strdup ("--");
946 char *tmp = empathy_format_currency (amount, scale, currency);
948 money = g_strdup_printf ("%s %s", currency, tmp);
952 /* Translators: this string will be something like:
953 * Top up My Account ($1.23)..." */
954 str = g_strdup_printf (_("Top up %s (%s)..."),
955 tp_account_get_display_name (account),
958 gtk_action_set_label (action, str);
961 /* update the money label in the roster */
962 label = g_object_get_data (G_OBJECT (action), "money-label");
964 gtk_label_set_text (GTK_LABEL (label), money);
969 main_window_balance_changed_cb (TpConnection *conn,
972 const gchar *currency,
975 main_window_balance_update_balance (action, conn);
979 main_window_setup_balance_create_action (EmpathyMainWindow *window,
982 EmpathyMainWindowPriv *priv = GET_PRIV (window);
986 GError *error = NULL;
988 /* create the action group if required */
989 if (priv->balance_action_group == NULL) {
990 priv->balance_action_group =
991 gtk_action_group_new ("balance-action-group");
993 gtk_ui_manager_insert_action_group (priv->ui_manager,
994 priv->balance_action_group, -1);
997 /* create the action */
998 name = main_window_account_to_action_name (account);
999 action = gtk_action_new (name,
1000 tp_account_get_display_name (account),
1001 _("Top up account credit"),
1003 g_object_bind_property (account, "icon-name", action, "icon-name",
1004 G_BINDING_SYNC_CREATE);
1006 g_signal_connect (action, "activate",
1007 G_CALLBACK (main_window_balance_activate_cb), window);
1009 gtk_action_group_add_action (priv->balance_action_group, action);
1010 g_object_unref (action);
1012 ui = g_strdup_printf (
1014 " <menubar name='menubar'>"
1015 " <menu action='view'>"
1016 " <placeholder name='view_balance_placeholder'>"
1017 " <menuitem action='%s'/>"
1024 merge_id = gtk_ui_manager_add_ui_from_string (priv->ui_manager,
1026 if (error != NULL) {
1027 DEBUG ("Failed to add balance UI for %s: %s",
1028 tp_account_get_display_name (account),
1030 g_error_free (error);
1033 g_object_set_data (G_OBJECT (action),
1034 "merge-id", GUINT_TO_POINTER (merge_id));
1043 main_window_setup_balance_create_widget (EmpathyMainWindow *window,
1047 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1048 GtkWidget *hbox, *image, *label, *button;
1050 hbox = gtk_hbox_new (FALSE, 6);
1053 image = gtk_image_new ();
1054 gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, TRUE, 0);
1055 g_object_bind_property (action, "icon-name", image, "icon-name",
1056 G_BINDING_SYNC_CREATE);
1058 /* account name label */
1059 label = gtk_label_new ("");
1060 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
1061 gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 0);
1062 g_object_bind_property (account, "display-name", label, "label",
1063 G_BINDING_SYNC_CREATE);
1066 label = gtk_label_new ("");
1067 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
1068 gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, TRUE, 0);
1069 g_object_set_data (G_OBJECT (action), "money-label", label);
1072 button = gtk_button_new_with_label (_("Top Up..."));
1073 gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, TRUE, 0);
1074 g_signal_connect_swapped (button, "clicked",
1075 G_CALLBACK (gtk_action_activate), action);
1077 gtk_box_pack_start (GTK_BOX (priv->balance_vbox), hbox, FALSE, TRUE, 0);
1078 gtk_widget_show_all (hbox);
1080 /* tie the lifetime of the widget to the lifetime of the action */
1081 g_object_weak_ref (G_OBJECT (action),
1082 (GWeakNotify) gtk_widget_destroy, hbox);
1088 main_window_setup_balance (EmpathyMainWindow *window,
1091 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1092 TpConnection *conn = tp_account_get_connection (account);
1099 if (!tp_proxy_is_prepared (conn, TP_CONNECTION_FEATURE_BALANCE))
1102 DEBUG ("Setting up balance for acct: %s",
1103 tp_account_get_display_name (account));
1105 /* create the action */
1106 action = main_window_setup_balance_create_action (window, account);
1111 gtk_action_set_visible (priv->view_balance_show_in_roster, TRUE);
1113 /* create the display widget */
1114 main_window_setup_balance_create_widget (window, action, account);
1116 /* check the current balance and monitor for any changes */
1117 uri = tp_connection_get_balance_uri (conn);
1119 g_object_set_data_full (G_OBJECT (action), "manage-credit-uri",
1120 g_strdup (uri), g_free);
1121 gtk_action_set_sensitive (GTK_ACTION (action), !tp_str_empty (uri));
1123 main_window_balance_update_balance (GTK_ACTION (action), conn);
1125 g_signal_connect (conn, "balance-changed",
1126 G_CALLBACK (main_window_balance_changed_cb), action);
1131 main_window_remove_balance_action (EmpathyMainWindow *window,
1134 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1139 if (priv->balance_action_group == NULL)
1142 name = main_window_account_to_action_name (account);
1144 action = gtk_action_group_get_action (
1145 priv->balance_action_group, name);
1147 if (action != NULL) {
1150 DEBUG ("Removing action");
1152 merge_id = GPOINTER_TO_UINT (g_object_get_data (
1156 gtk_ui_manager_remove_ui (priv->ui_manager,
1158 gtk_action_group_remove_action (
1159 priv->balance_action_group, action);
1164 a = gtk_action_group_list_actions (
1165 priv->balance_action_group);
1167 gtk_action_set_visible (
1168 priv->view_balance_show_in_roster,
1169 g_list_length (a) > 0);
1175 main_window_connection_changed_cb (TpAccount *account,
1179 gchar *dbus_error_name,
1180 GHashTable *details,
1181 EmpathyMainWindow *window)
1183 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1185 main_window_update_status (window);
1187 if (current == TP_CONNECTION_STATUS_DISCONNECTED &&
1188 reason != TP_CONNECTION_STATUS_REASON_REQUESTED) {
1189 main_window_error_display (window, account);
1192 if (current == TP_CONNECTION_STATUS_DISCONNECTED) {
1193 empathy_sound_manager_play (priv->sound_mgr, GTK_WIDGET (window),
1194 EMPATHY_SOUND_ACCOUNT_DISCONNECTED);
1196 /* remove balance action if required */
1197 main_window_remove_balance_action (window, account);
1200 if (current == TP_CONNECTION_STATUS_CONNECTED) {
1201 empathy_sound_manager_play (priv->sound_mgr, GTK_WIDGET (window),
1202 EMPATHY_SOUND_ACCOUNT_CONNECTED);
1204 /* Account connected without error, remove error message if any */
1205 main_window_remove_error (window, account);
1206 main_window_setup_balance (window, account);
1211 main_window_accels_load (void)
1215 filename = g_build_filename (g_get_user_config_dir (), PACKAGE_NAME, ACCELS_FILENAME, NULL);
1216 if (g_file_test (filename, G_FILE_TEST_EXISTS)) {
1217 DEBUG ("Loading from:'%s'", filename);
1218 gtk_accel_map_load (filename);
1225 main_window_accels_save (void)
1228 gchar *file_with_path;
1230 dir = g_build_filename (g_get_user_config_dir (), PACKAGE_NAME, NULL);
1231 g_mkdir_with_parents (dir, S_IRUSR | S_IWUSR | S_IXUSR);
1232 file_with_path = g_build_filename (dir, ACCELS_FILENAME, NULL);
1235 DEBUG ("Saving to:'%s'", file_with_path);
1236 gtk_accel_map_save (file_with_path);
1238 g_free (file_with_path);
1242 empathy_main_window_finalize (GObject *window)
1244 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1245 GHashTableIter iter;
1246 gpointer key, value;
1248 /* Save user-defined accelerators. */
1249 main_window_accels_save ();
1251 g_list_free (priv->actions_connected);
1253 g_object_unref (priv->account_manager);
1254 g_object_unref (priv->individual_store);
1255 g_object_unref (priv->contact_manager);
1256 g_object_unref (priv->sound_mgr);
1257 g_hash_table_destroy (priv->errors);
1258 g_hash_table_destroy (priv->auths);
1260 /* disconnect all handlers of status-changed signal */
1261 g_hash_table_iter_init (&iter, priv->status_changed_handlers);
1262 while (g_hash_table_iter_next (&iter, &key, &value))
1263 g_signal_handler_disconnect (TP_ACCOUNT (key),
1264 GPOINTER_TO_UINT (value));
1266 g_hash_table_destroy (priv->status_changed_handlers);
1268 g_signal_handlers_disconnect_by_func (priv->event_manager,
1269 main_window_event_added_cb,
1271 g_signal_handlers_disconnect_by_func (priv->event_manager,
1272 main_window_event_removed_cb,
1274 g_object_unref (priv->call_observer);
1275 g_object_unref (priv->event_manager);
1276 g_object_unref (priv->ui_manager);
1277 g_object_unref (priv->chatroom_manager);
1279 g_object_unref (priv->gsettings_ui);
1280 g_object_unref (priv->gsettings_contacts);
1282 G_OBJECT_CLASS (empathy_main_window_parent_class)->finalize (window);
1286 main_window_key_press_event_cb (GtkWidget *window,
1290 if (event->keyval == GDK_KEY_T
1291 && event->state & GDK_SHIFT_MASK
1292 && event->state & GDK_CONTROL_MASK) {
1293 empathy_chat_manager_call_undo_closed_chat ();
1299 main_window_chat_quit_cb (GtkAction *action,
1300 EmpathyMainWindow *window)
1306 main_window_view_history_cb (GtkAction *action,
1307 EmpathyMainWindow *window)
1309 empathy_log_window_show (NULL, NULL, FALSE, GTK_WINDOW (window));
1313 main_window_chat_new_message_cb (GtkAction *action,
1314 EmpathyMainWindow *window)
1316 empathy_new_message_dialog_show (GTK_WINDOW (window));
1320 main_window_chat_new_call_cb (GtkAction *action,
1321 EmpathyMainWindow *window)
1323 empathy_new_call_dialog_show (GTK_WINDOW (window));
1327 main_window_chat_add_contact_cb (GtkAction *action,
1328 EmpathyMainWindow *window)
1330 empathy_new_individual_dialog_show (GTK_WINDOW (window));
1334 main_window_chat_search_contacts_cb (GtkAction *action,
1335 EmpathyMainWindow *window)
1337 GtkWidget *dialog = empathy_contact_search_dialog_new (
1338 GTK_WINDOW (window));
1339 gtk_widget_show (dialog);
1343 main_window_view_show_ft_manager (GtkAction *action,
1344 EmpathyMainWindow *window)
1346 empathy_ft_manager_show ();
1350 main_window_view_show_offline_cb (GtkToggleAction *action,
1351 EmpathyMainWindow *window)
1353 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1356 current = gtk_toggle_action_get_active (action);
1357 g_settings_set_boolean (priv->gsettings_ui,
1358 EMPATHY_PREFS_UI_SHOW_OFFLINE,
1361 empathy_individual_view_set_show_offline (priv->individual_view,
1366 main_window_notify_sort_contact_cb (GSettings *gsettings,
1368 EmpathyMainWindow *window)
1370 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1373 str = g_settings_get_string (gsettings, key);
1377 GEnumClass *enum_class;
1378 GEnumValue *enum_value;
1380 type = empathy_individual_store_sort_get_type ();
1381 enum_class = G_ENUM_CLASS (g_type_class_peek (type));
1382 enum_value = g_enum_get_value_by_nick (enum_class, str);
1384 /* By changing the value of the GtkRadioAction,
1385 it emits a signal that calls main_window_view_sort_contacts_cb
1386 which updates the contacts list */
1387 gtk_radio_action_set_current_value (priv->sort_by_name,
1390 g_warning ("Wrong value for sort_criterium configuration : %s", str);
1397 main_window_view_sort_contacts_cb (GtkRadioAction *action,
1398 GtkRadioAction *current,
1399 EmpathyMainWindow *window)
1401 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1402 EmpathyContactListStoreSort value;
1405 GEnumClass *enum_class;
1406 GEnumValue *enum_value;
1408 value = gtk_radio_action_get_current_value (action);
1409 group = gtk_radio_action_get_group (action);
1411 /* Get string from index */
1412 type = empathy_individual_store_sort_get_type ();
1413 enum_class = G_ENUM_CLASS (g_type_class_peek (type));
1414 enum_value = g_enum_get_value (enum_class, g_slist_index (group, current));
1417 g_warning ("No GEnumValue for EmpathyContactListSort with GtkRadioAction index:%d",
1418 g_slist_index (group, action));
1420 g_settings_set_string (priv->gsettings_contacts,
1421 EMPATHY_PREFS_CONTACTS_SORT_CRITERIUM,
1422 enum_value->value_nick);
1424 empathy_individual_store_set_sort_criterium (priv->individual_store,
1429 main_window_view_show_protocols_cb (GtkToggleAction *action,
1430 EmpathyMainWindow *window)
1432 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1435 value = gtk_toggle_action_get_active (action);
1437 g_settings_set_boolean (priv->gsettings_ui,
1438 EMPATHY_PREFS_UI_SHOW_PROTOCOLS,
1440 empathy_individual_store_set_show_protocols (priv->individual_store,
1444 /* Matches GtkRadioAction values set in empathy-main-window.ui */
1445 #define CONTACT_LIST_NORMAL_SIZE_WITH_AVATARS 0
1446 #define CONTACT_LIST_NORMAL_SIZE 1
1447 #define CONTACT_LIST_COMPACT_SIZE 2
1450 main_window_view_contacts_list_size_cb (GtkRadioAction *action,
1451 GtkRadioAction *current,
1452 EmpathyMainWindow *window)
1454 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1455 GSettings *gsettings_ui;
1458 value = gtk_radio_action_get_current_value (action);
1459 /* create a new GSettings, so we can delay the setting until both
1461 gsettings_ui = g_settings_new (EMPATHY_PREFS_UI_SCHEMA);
1463 DEBUG ("radio button toggled, value = %i", value);
1465 g_settings_delay (gsettings_ui);
1466 g_settings_set_boolean (gsettings_ui,
1467 EMPATHY_PREFS_UI_SHOW_AVATARS,
1468 value == CONTACT_LIST_NORMAL_SIZE_WITH_AVATARS);
1470 g_settings_set_boolean (gsettings_ui,
1471 EMPATHY_PREFS_UI_COMPACT_CONTACT_LIST,
1472 value == CONTACT_LIST_COMPACT_SIZE);
1473 g_settings_apply (gsettings_ui);
1475 /* FIXME: these enums probably have the wrong namespace */
1476 empathy_individual_store_set_show_avatars (priv->individual_store,
1477 value == CONTACT_LIST_NORMAL_SIZE_WITH_AVATARS);
1478 empathy_individual_store_set_is_compact (priv->individual_store,
1479 value == CONTACT_LIST_COMPACT_SIZE);
1481 g_object_unref (gsettings_ui);
1484 static void main_window_notify_show_protocols_cb (GSettings *gsettings,
1486 EmpathyMainWindow *window)
1488 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1490 gtk_toggle_action_set_active (priv->show_protocols,
1491 g_settings_get_boolean (gsettings,
1492 EMPATHY_PREFS_UI_SHOW_PROTOCOLS));
1497 main_window_notify_contact_list_size_cb (GSettings *gsettings,
1499 EmpathyMainWindow *window)
1501 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1504 if (g_settings_get_boolean (gsettings,
1505 EMPATHY_PREFS_UI_COMPACT_CONTACT_LIST)) {
1506 value = CONTACT_LIST_COMPACT_SIZE;
1507 } else if (g_settings_get_boolean (gsettings,
1508 EMPATHY_PREFS_UI_SHOW_AVATARS)) {
1509 value = CONTACT_LIST_NORMAL_SIZE_WITH_AVATARS;
1511 value = CONTACT_LIST_NORMAL_SIZE;
1514 DEBUG ("setting changed, value = %i", value);
1516 /* By changing the value of the GtkRadioAction,
1517 it emits a signal that calls main_window_view_contacts_list_size_cb
1518 which updates the contacts list */
1519 gtk_radio_action_set_current_value (priv->normal_with_avatars, value);
1523 main_window_edit_search_contacts_cb (GtkCheckMenuItem *item,
1524 EmpathyMainWindow *window)
1526 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1528 empathy_individual_view_start_search (priv->individual_view);
1532 main_window_view_show_map_cb (GtkCheckMenuItem *item,
1533 EmpathyMainWindow *window)
1535 #ifdef HAVE_LIBCHAMPLAIN
1536 empathy_map_view_show ();
1541 join_chatroom (EmpathyChatroom *chatroom,
1547 account = empathy_chatroom_get_account (chatroom);
1548 room = empathy_chatroom_get_room (chatroom);
1550 DEBUG ("Requesting channel for '%s'", room);
1551 empathy_join_muc (account, room, timestamp);
1557 EmpathyChatroom *chatroom;
1561 } join_fav_account_sig_ctx;
1563 static join_fav_account_sig_ctx *
1564 join_fav_account_sig_ctx_new (TpAccount *account,
1565 EmpathyChatroom *chatroom,
1568 join_fav_account_sig_ctx *ctx = g_slice_new0 (
1569 join_fav_account_sig_ctx);
1571 ctx->account = g_object_ref (account);
1572 ctx->chatroom = g_object_ref (chatroom);
1573 ctx->timestamp = timestamp;
1578 join_fav_account_sig_ctx_free (join_fav_account_sig_ctx *ctx)
1580 g_object_unref (ctx->account);
1581 g_object_unref (ctx->chatroom);
1582 g_slice_free (join_fav_account_sig_ctx, ctx);
1586 account_status_changed_cb (TpAccount *account,
1587 TpConnectionStatus old_status,
1588 TpConnectionStatus new_status,
1590 gchar *dbus_error_name,
1591 GHashTable *details,
1594 join_fav_account_sig_ctx *ctx = user_data;
1596 switch (new_status) {
1597 case TP_CONNECTION_STATUS_DISCONNECTED:
1598 /* Don't wait any longer */
1602 case TP_CONNECTION_STATUS_CONNECTING:
1606 case TP_CONNECTION_STATUS_CONNECTED:
1607 /* We can join the room */
1611 g_assert_not_reached ();
1614 join_chatroom (ctx->chatroom, ctx->timestamp);
1617 g_source_remove (ctx->timeout);
1618 g_signal_handler_disconnect (account, ctx->sig_id);
1621 #define JOIN_FAVORITE_TIMEOUT 5
1624 join_favorite_timeout_cb (gpointer data)
1626 join_fav_account_sig_ctx *ctx = data;
1628 /* stop waiting for joining the favorite room */
1629 g_signal_handler_disconnect (ctx->account, ctx->sig_id);
1634 main_window_favorite_chatroom_join (EmpathyChatroom *chatroom)
1638 account = empathy_chatroom_get_account (chatroom);
1639 if (tp_account_get_connection_status (account, NULL) !=
1640 TP_CONNECTION_STATUS_CONNECTED) {
1641 join_fav_account_sig_ctx *ctx;
1643 ctx = join_fav_account_sig_ctx_new (account, chatroom,
1644 empathy_get_current_action_time ());
1646 ctx->sig_id = g_signal_connect_data (account, "status-changed",
1647 G_CALLBACK (account_status_changed_cb), ctx,
1648 (GClosureNotify) join_fav_account_sig_ctx_free, 0);
1650 ctx->timeout = g_timeout_add_seconds (JOIN_FAVORITE_TIMEOUT,
1651 join_favorite_timeout_cb, ctx);
1655 join_chatroom (chatroom, empathy_get_current_action_time ());
1659 main_window_favorite_chatroom_menu_activate_cb (GtkMenuItem *menu_item,
1660 EmpathyChatroom *chatroom)
1662 main_window_favorite_chatroom_join (chatroom);
1666 main_window_favorite_chatroom_menu_add (EmpathyMainWindow *window,
1667 EmpathyChatroom *chatroom)
1669 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1670 GtkWidget *menu_item;
1671 const gchar *name, *account_name;
1675 if (g_object_get_data (G_OBJECT (chatroom), "menu_item")) {
1679 name = empathy_chatroom_get_name (chatroom);
1680 account_name = tp_account_get_display_name (
1681 empathy_chatroom_get_account (chatroom));
1682 label = g_strdup_printf ("%s (%s)", name, account_name);
1683 menu_item = gtk_menu_item_new_with_label (label);
1685 g_object_set_data (G_OBJECT (menu_item), "is_favorite",
1686 GUINT_TO_POINTER (TRUE));
1688 g_object_set_data (G_OBJECT (chatroom), "menu_item", menu_item);
1689 g_signal_connect (menu_item, "activate",
1690 G_CALLBACK (main_window_favorite_chatroom_menu_activate_cb),
1693 gtk_menu_shell_insert (GTK_MENU_SHELL (priv->room_menu),
1696 gtk_widget_show (menu_item);
1700 main_window_favorite_chatroom_menu_added_cb (EmpathyChatroomManager *manager,
1701 EmpathyChatroom *chatroom,
1702 EmpathyMainWindow *window)
1704 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1706 main_window_favorite_chatroom_menu_add (window, chatroom);
1707 gtk_widget_show (priv->room_separator);
1708 gtk_action_set_sensitive (priv->room_join_favorites, TRUE);
1712 main_window_favorite_chatroom_menu_removed_cb (EmpathyChatroomManager *manager,
1713 EmpathyChatroom *chatroom,
1714 EmpathyMainWindow *window)
1716 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1717 GtkWidget *menu_item;
1720 menu_item = g_object_get_data (G_OBJECT (chatroom), "menu_item");
1721 g_object_set_data (G_OBJECT (chatroom), "menu_item", NULL);
1722 gtk_widget_destroy (menu_item);
1724 chatrooms = empathy_chatroom_manager_get_chatrooms (priv->chatroom_manager, NULL);
1726 gtk_widget_show (priv->room_separator);
1728 gtk_widget_hide (priv->room_separator);
1731 gtk_action_set_sensitive (priv->room_join_favorites, chatrooms != NULL);
1732 g_list_free (chatrooms);
1736 main_window_favorite_chatroom_menu_setup (EmpathyMainWindow *window)
1738 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1739 GList *chatrooms, *l;
1742 priv->chatroom_manager = empathy_chatroom_manager_dup_singleton (NULL);
1743 chatrooms = empathy_chatroom_manager_get_chatrooms (
1744 priv->chatroom_manager, NULL);
1745 room = gtk_ui_manager_get_widget (priv->ui_manager,
1747 priv->room_menu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (room));
1748 priv->room_separator = gtk_ui_manager_get_widget (priv->ui_manager,
1749 "/menubar/room/room_separator");
1751 for (l = chatrooms; l; l = l->next) {
1752 main_window_favorite_chatroom_menu_add (window, l->data);
1756 gtk_widget_hide (priv->room_separator);
1759 gtk_action_set_sensitive (priv->room_join_favorites, chatrooms != NULL);
1761 g_signal_connect (priv->chatroom_manager, "chatroom-added",
1762 G_CALLBACK (main_window_favorite_chatroom_menu_added_cb),
1764 g_signal_connect (priv->chatroom_manager, "chatroom-removed",
1765 G_CALLBACK (main_window_favorite_chatroom_menu_removed_cb),
1768 g_list_free (chatrooms);
1772 main_window_room_join_new_cb (GtkAction *action,
1773 EmpathyMainWindow *window)
1775 empathy_new_chatroom_dialog_show (GTK_WINDOW (window));
1779 main_window_room_join_favorites_cb (GtkAction *action,
1780 EmpathyMainWindow *window)
1782 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1783 GList *chatrooms, *l;
1785 chatrooms = empathy_chatroom_manager_get_chatrooms (priv->chatroom_manager, NULL);
1786 for (l = chatrooms; l; l = l->next) {
1787 main_window_favorite_chatroom_join (l->data);
1789 g_list_free (chatrooms);
1793 main_window_room_manage_favorites_cb (GtkAction *action,
1794 EmpathyMainWindow *window)
1796 empathy_chatrooms_window_show (GTK_WINDOW (window));
1800 main_window_edit_cb (GtkAction *action,
1801 EmpathyMainWindow *window)
1803 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1806 /* FIXME: It should use the UIManager to merge the contact/group submenu */
1807 submenu = empathy_individual_view_get_individual_menu (
1808 priv->individual_view);
1813 item = GTK_MENU_ITEM (priv->edit_context);
1814 label = gtk_bin_get_child (GTK_BIN (item));
1815 gtk_label_set_text (GTK_LABEL (label), _("Contact"));
1817 gtk_widget_show (priv->edit_context);
1818 gtk_widget_show (priv->edit_context_separator);
1820 gtk_menu_item_set_submenu (item, submenu);
1825 submenu = empathy_individual_view_get_group_menu (
1826 priv->individual_view);
1831 item = GTK_MENU_ITEM (priv->edit_context);
1832 label = gtk_bin_get_child (GTK_BIN (item));
1833 gtk_label_set_text (GTK_LABEL (label), _("Group"));
1835 gtk_widget_show (priv->edit_context);
1836 gtk_widget_show (priv->edit_context_separator);
1838 gtk_menu_item_set_submenu (item, submenu);
1843 gtk_widget_hide (priv->edit_context);
1844 gtk_widget_hide (priv->edit_context_separator);
1850 main_window_edit_accounts_cb (GtkAction *action,
1851 EmpathyMainWindow *window)
1853 empathy_accounts_dialog_show_application (gdk_screen_get_default (),
1854 NULL, FALSE, FALSE);
1858 main_window_edit_personal_information_cb (GtkAction *action,
1859 EmpathyMainWindow *window)
1861 empathy_contact_personal_dialog_show (GTK_WINDOW (window));
1865 main_window_edit_blocked_contacts_cb (GtkAction *action,
1866 EmpathyMainWindow *window)
1870 dialog = empathy_contact_blocking_dialog_new (GTK_WINDOW (window));
1871 gtk_widget_show (dialog);
1872 g_signal_connect (dialog, "response",
1873 G_CALLBACK (gtk_widget_destroy), NULL);
1877 empathy_main_window_show_preferences (EmpathyMainWindow *window,
1880 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1882 if (priv->preferences == NULL) {
1883 priv->preferences = empathy_preferences_new (GTK_WINDOW (window),
1884 priv->shell_running);
1885 g_object_add_weak_pointer (G_OBJECT (priv->preferences),
1886 (gpointer) &priv->preferences);
1888 gtk_widget_show (priv->preferences);
1890 gtk_window_present (GTK_WINDOW (priv->preferences));
1894 empathy_preferences_show_tab (
1895 EMPATHY_PREFERENCES (priv->preferences), tab);
1899 main_window_edit_preferences_cb (GtkAction *action,
1900 EmpathyMainWindow *window)
1902 empathy_main_window_show_preferences (window, NULL);
1906 main_window_help_about_cb (GtkAction *action,
1907 EmpathyMainWindow *window)
1909 empathy_about_dialog_new (GTK_WINDOW (window));
1913 main_window_help_debug_cb (GtkAction *action,
1914 EmpathyMainWindow *window)
1916 empathy_launch_program (BIN_DIR, "empathy-debugger", NULL);
1920 main_window_help_contents_cb (GtkAction *action,
1921 EmpathyMainWindow *window)
1923 empathy_url_show (GTK_WIDGET (window), "ghelp:empathy");
1927 main_window_throbber_button_press_event_cb (GtkWidget *throbber,
1928 GdkEventButton *event,
1929 EmpathyMainWindow *window)
1931 if (event->type != GDK_BUTTON_PRESS ||
1932 event->button != 1) {
1936 empathy_accounts_dialog_show_application (
1937 gtk_widget_get_screen (GTK_WIDGET (throbber)),
1938 NULL, FALSE, FALSE);
1944 main_window_account_removed_cb (TpAccountManager *manager,
1946 EmpathyMainWindow *window)
1948 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1951 a = tp_account_manager_get_valid_accounts (manager);
1953 gtk_action_set_sensitive (priv->view_history,
1954 g_list_length (a) > 0);
1958 /* remove errors if any */
1959 main_window_remove_error (window, account);
1961 /* remove the balance action if required */
1962 main_window_remove_balance_action (window, account);
1966 main_window_account_validity_changed_cb (TpAccountManager *manager,
1969 EmpathyMainWindow *window)
1971 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1975 handler_id = GPOINTER_TO_UINT (g_hash_table_lookup (
1976 priv->status_changed_handlers, account));
1978 /* connect signal only if it was not connected yet */
1979 if (handler_id == 0) {
1980 handler_id = g_signal_connect (account,
1982 G_CALLBACK (main_window_connection_changed_cb),
1984 g_hash_table_insert (priv->status_changed_handlers,
1985 account, GUINT_TO_POINTER (handler_id));
1989 main_window_account_removed_cb (manager, account, window);
1993 main_window_notify_show_offline_cb (GSettings *gsettings,
1995 gpointer toggle_action)
1997 gtk_toggle_action_set_active (toggle_action,
1998 g_settings_get_boolean (gsettings, key));
2002 main_window_connection_items_setup (EmpathyMainWindow *window,
2005 EmpathyMainWindowPriv *priv = GET_PRIV (window);
2009 const gchar *actions_connected[] = {
2011 "room_join_favorites",
2014 "chat_search_contacts",
2016 "edit_personal_information",
2017 "edit_blocked_contacts",
2018 "edit_search_contacts"
2021 for (i = 0, list = NULL; i < G_N_ELEMENTS (actions_connected); i++) {
2022 action = gtk_builder_get_object (gui, actions_connected[i]);
2023 list = g_list_prepend (list, action);
2026 priv->actions_connected = list;
2030 account_manager_prepared_cb (GObject *source_object,
2031 GAsyncResult *result,
2034 GList *accounts, *j;
2035 TpAccountManager *manager = TP_ACCOUNT_MANAGER (source_object);
2036 EmpathyMainWindow *window = user_data;
2037 EmpathyMainWindowPriv *priv = GET_PRIV (window);
2038 GError *error = NULL;
2040 if (!tp_proxy_prepare_finish (manager, result, &error)) {
2041 DEBUG ("Failed to prepare account manager: %s", error->message);
2042 g_error_free (error);
2046 accounts = tp_account_manager_get_valid_accounts (priv->account_manager);
2047 for (j = accounts; j != NULL; j = j->next) {
2048 TpAccount *account = TP_ACCOUNT (j->data);
2051 handler_id = g_signal_connect (account, "status-changed",
2052 G_CALLBACK (main_window_connection_changed_cb),
2054 g_hash_table_insert (priv->status_changed_handlers,
2055 account, GUINT_TO_POINTER (handler_id));
2057 main_window_setup_balance (window, account);
2060 g_signal_connect (manager, "account-validity-changed",
2061 G_CALLBACK (main_window_account_validity_changed_cb),
2064 main_window_update_status (window);
2066 /* Disable the "Previous Conversations" menu entry if there is no account */
2067 gtk_action_set_sensitive (priv->view_history,
2068 g_list_length (accounts) > 0);
2070 g_list_free (accounts);
2074 empathy_main_window_set_shell_running (EmpathyMainWindow *window,
2075 gboolean shell_running)
2077 EmpathyMainWindowPriv *priv = GET_PRIV (window);
2079 if (priv->shell_running == shell_running)
2082 priv->shell_running = shell_running;
2083 g_object_notify (G_OBJECT (window), "shell-running");
2087 empathy_main_window_constructor (GType type,
2088 guint n_construct_params,
2089 GObjectConstructParam *construct_params)
2091 static GObject *window = NULL;
2094 return g_object_ref (window);
2096 window = G_OBJECT_CLASS (empathy_main_window_parent_class)->constructor (
2097 type, n_construct_params, construct_params);
2099 g_object_add_weak_pointer (window, (gpointer) &window);
2105 empathy_main_window_set_property (GObject *object,
2107 const GValue *value,
2110 EmpathyMainWindow *self = EMPATHY_MAIN_WINDOW (object);
2111 EmpathyMainWindowPriv *priv = GET_PRIV (self);
2113 switch (property_id)
2115 case PROP_SHELL_RUNNING:
2116 priv->shell_running = g_value_get_boolean (value);
2119 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2125 empathy_main_window_get_property (GObject *object,
2130 EmpathyMainWindow *self = EMPATHY_MAIN_WINDOW (object);
2131 EmpathyMainWindowPriv *priv = GET_PRIV (self);
2133 switch (property_id)
2135 case PROP_SHELL_RUNNING:
2136 g_value_set_boolean (value, priv->shell_running);
2139 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2145 empathy_main_window_class_init (EmpathyMainWindowClass *klass)
2147 GObjectClass *object_class = G_OBJECT_CLASS (klass);
2150 object_class->finalize = empathy_main_window_finalize;
2151 object_class->constructor = empathy_main_window_constructor;
2153 object_class->set_property = empathy_main_window_set_property;
2154 object_class->get_property = empathy_main_window_get_property;
2156 pspec = g_param_spec_boolean ("shell-running",
2158 "Whether the Shell is running or not",
2160 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
2161 g_object_class_install_property (object_class, PROP_SHELL_RUNNING, pspec);
2163 g_type_class_add_private (object_class, sizeof (EmpathyMainWindowPriv));
2167 empathy_main_window_init (EmpathyMainWindow *window)
2169 EmpathyMainWindowPriv *priv;
2170 EmpathyIndividualManager *individual_manager;
2171 GtkBuilder *gui, *gui_mgr;
2173 GtkToggleAction *show_offline_widget;
2174 GtkAction *show_map_widget;
2176 gboolean show_offline;
2178 GtkTreeModel *model;
2179 GtkWidget *search_vbox;
2182 priv = window->priv = G_TYPE_INSTANCE_GET_PRIVATE (window,
2183 EMPATHY_TYPE_MAIN_WINDOW, EmpathyMainWindowPriv);
2185 priv->gsettings_ui = g_settings_new (EMPATHY_PREFS_UI_SCHEMA);
2186 priv->gsettings_contacts = g_settings_new (EMPATHY_PREFS_CONTACTS_SCHEMA);
2188 priv->sound_mgr = empathy_sound_manager_dup_singleton ();
2190 gtk_window_set_title (GTK_WINDOW (window), _("Contact List"));
2191 gtk_window_set_role (GTK_WINDOW (window), "contact_list");
2192 gtk_window_set_default_size (GTK_WINDOW (window), 225, 325);
2194 /* don't finalize the widget on delete-event, just hide it */
2195 g_signal_connect (window, "delete-event",
2196 G_CALLBACK (gtk_widget_hide_on_delete), NULL);
2198 /* Set up interface */
2199 filename = empathy_file_lookup ("empathy-main-window.ui", "src");
2200 gui = empathy_builder_get_file (filename,
2201 "main_vbox", &priv->main_vbox,
2202 "balance_vbox", &priv->balance_vbox,
2203 "errors_vbox", &priv->errors_vbox,
2204 "auth_vbox", &priv->auth_vbox,
2205 "search_vbox", &search_vbox,
2206 "presence_toolbar", &priv->presence_toolbar,
2207 "notebook", &priv->notebook,
2208 "no_entry_label", &priv->no_entry_label,
2209 "roster_scrolledwindow", &sw,
2213 /* Set UI manager */
2214 filename = empathy_file_lookup ("empathy-main-window-menubar.ui", "src");
2215 gui_mgr = empathy_builder_get_file (filename,
2216 "ui_manager", &priv->ui_manager,
2217 "view_show_offline", &show_offline_widget,
2218 "view_show_protocols", &priv->show_protocols,
2219 "view_sort_by_name", &priv->sort_by_name,
2220 "view_sort_by_status", &priv->sort_by_status,
2221 "view_normal_size_with_avatars", &priv->normal_with_avatars,
2222 "view_normal_size", &priv->normal_size,
2223 "view_compact_size", &priv->compact_size,
2224 "view_history", &priv->view_history,
2225 "view_show_map", &show_map_widget,
2226 "room_join_favorites", &priv->room_join_favorites,
2227 "view_balance_show_in_roster", &priv->view_balance_show_in_roster,
2228 "menubar", &menubar,
2232 /* The UI manager is living in its own .ui file as Glade doesn't support
2233 * those. The GtkMenubar has to be in this file as well to we manually add
2234 * it to the first position of the vbox. */
2235 gtk_box_pack_start (GTK_BOX (priv->main_vbox), menubar, FALSE, FALSE, 0);
2236 gtk_box_reorder_child (GTK_BOX (priv->main_vbox), menubar, 0);
2238 gtk_container_add (GTK_CONTAINER (window), priv->main_vbox);
2239 gtk_widget_show (priv->main_vbox);
2241 g_signal_connect (window, "key-press-event",
2242 G_CALLBACK (main_window_key_press_event_cb), NULL);
2244 empathy_builder_connect (gui_mgr, window,
2245 "chat_quit", "activate", main_window_chat_quit_cb,
2246 "chat_new_message", "activate", main_window_chat_new_message_cb,
2247 "chat_new_call", "activate", main_window_chat_new_call_cb,
2248 "view_history", "activate", main_window_view_history_cb,
2249 "room_join_new", "activate", main_window_room_join_new_cb,
2250 "room_join_favorites", "activate", main_window_room_join_favorites_cb,
2251 "room_manage_favorites", "activate", main_window_room_manage_favorites_cb,
2252 "chat_add_contact", "activate", main_window_chat_add_contact_cb,
2253 "chat_search_contacts", "activate", main_window_chat_search_contacts_cb,
2254 "view_show_ft_manager", "activate", main_window_view_show_ft_manager,
2255 "view_show_offline", "toggled", main_window_view_show_offline_cb,
2256 "view_show_protocols", "toggled", main_window_view_show_protocols_cb,
2257 "view_sort_by_name", "changed", main_window_view_sort_contacts_cb,
2258 "view_normal_size_with_avatars", "changed", main_window_view_contacts_list_size_cb,
2259 "view_show_map", "activate", main_window_view_show_map_cb,
2260 "edit", "activate", main_window_edit_cb,
2261 "edit_accounts", "activate", main_window_edit_accounts_cb,
2262 "edit_personal_information", "activate", main_window_edit_personal_information_cb,
2263 "edit_blocked_contacts", "activate", main_window_edit_blocked_contacts_cb,
2264 "edit_preferences", "activate", main_window_edit_preferences_cb,
2265 "edit_search_contacts", "activate", main_window_edit_search_contacts_cb,
2266 "help_about", "activate", main_window_help_about_cb,
2267 "help_debug", "activate", main_window_help_debug_cb,
2268 "help_contents", "activate", main_window_help_contents_cb,
2271 /* Set up connection related widgets. */
2272 main_window_connection_items_setup (window, gui_mgr);
2274 g_object_ref (priv->ui_manager);
2275 g_object_unref (gui);
2276 g_object_unref (gui_mgr);
2278 #ifndef HAVE_LIBCHAMPLAIN
2279 gtk_action_set_visible (show_map_widget, FALSE);
2282 priv->account_manager = tp_account_manager_dup ();
2284 tp_proxy_prepare_async (priv->account_manager, NULL,
2285 account_manager_prepared_cb, window);
2287 priv->errors = g_hash_table_new_full (g_direct_hash,
2292 priv->auths = g_hash_table_new (NULL, NULL);
2294 priv->status_changed_handlers = g_hash_table_new_full (g_direct_hash,
2300 main_window_favorite_chatroom_menu_setup (window);
2302 priv->edit_context = gtk_ui_manager_get_widget (priv->ui_manager,
2303 "/menubar/edit/edit_context");
2304 priv->edit_context_separator = gtk_ui_manager_get_widget (
2306 "/menubar/edit/edit_context_separator");
2307 gtk_widget_hide (priv->edit_context);
2308 gtk_widget_hide (priv->edit_context_separator);
2310 /* Set up contact list. */
2311 empathy_status_presets_get_all ();
2313 /* Set up presence chooser */
2314 priv->presence_chooser = empathy_presence_chooser_new ();
2315 gtk_widget_show (priv->presence_chooser);
2316 item = gtk_tool_item_new ();
2317 gtk_widget_show (GTK_WIDGET (item));
2318 gtk_widget_set_size_request (priv->presence_chooser, 10, -1);
2319 gtk_container_add (GTK_CONTAINER (item), priv->presence_chooser);
2320 gtk_tool_item_set_is_important (item, TRUE);
2321 gtk_tool_item_set_expand (item, TRUE);
2322 gtk_toolbar_insert (GTK_TOOLBAR (priv->presence_toolbar), item, -1);
2324 /* Set up the throbber */
2325 priv->throbber = gtk_spinner_new ();
2326 gtk_widget_set_size_request (priv->throbber, 16, -1);
2327 gtk_widget_set_events (priv->throbber, GDK_BUTTON_PRESS_MASK);
2328 g_signal_connect (priv->throbber, "button-press-event",
2329 G_CALLBACK (main_window_throbber_button_press_event_cb),
2331 gtk_widget_show (priv->throbber);
2333 item = gtk_tool_item_new ();
2334 gtk_container_set_border_width (GTK_CONTAINER (item), 6);
2335 gtk_toolbar_insert (GTK_TOOLBAR (priv->presence_toolbar), item, -1);
2336 gtk_container_add (GTK_CONTAINER (item), priv->throbber);
2337 priv->throbber_tool_item = GTK_WIDGET (item);
2339 /* XXX: this class is designed to live for the duration of the program,
2340 * so it's got a race condition between its signal handlers and its
2341 * finalization. The class is planned to be removed, so we won't fix
2342 * this before then. */
2343 priv->contact_manager = EMPATHY_CONTACT_LIST (
2344 empathy_contact_manager_dup_singleton ());
2345 individual_manager = empathy_individual_manager_dup_singleton ();
2346 priv->individual_store = empathy_individual_store_new (
2347 individual_manager);
2348 g_object_unref (individual_manager);
2350 /* For the moment, we disallow Persona drops onto the main contact list (e.g. from things such as
2351 * the EmpathyPersonaView in the linking dialogue). No code is hooked up to do anything on a Persona
2352 * drop, so allowing them would achieve nothing except confusion. */
2353 priv->individual_view = empathy_individual_view_new (
2354 priv->individual_store,
2355 EMPATHY_INDIVIDUAL_VIEW_FEATURE_ALL ^ EMPATHY_INDIVIDUAL_VIEW_FEATURE_PERSONA_DROP,
2356 EMPATHY_INDIVIDUAL_FEATURE_ALL);
2358 gtk_widget_show (GTK_WIDGET (priv->individual_view));
2359 gtk_container_add (GTK_CONTAINER (sw),
2360 GTK_WIDGET (priv->individual_view));
2361 g_signal_connect (priv->individual_view, "row-activated",
2362 G_CALLBACK (main_window_row_activated_cb),
2365 /* Set up search bar */
2366 priv->search_bar = empathy_live_search_new (
2367 GTK_WIDGET (priv->individual_view));
2368 empathy_individual_view_set_live_search (priv->individual_view,
2369 EMPATHY_LIVE_SEARCH (priv->search_bar));
2370 gtk_box_pack_start (GTK_BOX (search_vbox), priv->search_bar,
2373 g_signal_connect_swapped (window, "map",
2374 G_CALLBACK (gtk_widget_grab_focus), priv->individual_view);
2376 /* Connect to proper signals to check if contact list is empty or not */
2377 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->individual_view));
2379 g_signal_connect (model, "row-inserted",
2380 G_CALLBACK (main_window_row_inserted_cb),
2382 g_signal_connect (model, "row-deleted",
2383 G_CALLBACK (main_window_row_deleted_cb),
2386 /* Load user-defined accelerators. */
2387 main_window_accels_load ();
2389 /* Set window size. */
2390 empathy_geometry_bind (GTK_WINDOW (window), GEOMETRY_NAME);
2392 /* bind view_balance_show_in_roster */
2393 g_settings_bind (priv->gsettings_ui, "show-balance-in-roster",
2394 priv->view_balance_show_in_roster, "active",
2395 G_SETTINGS_BIND_DEFAULT);
2396 g_object_bind_property (priv->view_balance_show_in_roster, "active",
2397 priv->balance_vbox, "visible",
2398 G_BINDING_SYNC_CREATE);
2400 /* Enable event handling */
2401 priv->call_observer = empathy_call_observer_dup_singleton ();
2402 priv->event_manager = empathy_event_manager_dup_singleton ();
2404 g_signal_connect (priv->event_manager, "event-added",
2405 G_CALLBACK (main_window_event_added_cb), window);
2406 g_signal_connect (priv->event_manager, "event-removed",
2407 G_CALLBACK (main_window_event_removed_cb), window);
2408 g_signal_connect (priv->account_manager, "account-validity-changed",
2409 G_CALLBACK (main_window_account_validity_changed_cb),
2411 g_signal_connect (priv->account_manager, "account-removed",
2412 G_CALLBACK (main_window_account_removed_cb),
2414 g_signal_connect (priv->account_manager, "account-disabled",
2415 G_CALLBACK (main_window_account_disabled_cb),
2418 /* Show offline ? */
2419 show_offline = g_settings_get_boolean (priv->gsettings_ui,
2420 EMPATHY_PREFS_UI_SHOW_OFFLINE);
2421 g_signal_connect (priv->gsettings_ui,
2422 "changed::" EMPATHY_PREFS_UI_SHOW_OFFLINE,
2423 G_CALLBACK (main_window_notify_show_offline_cb),
2424 show_offline_widget);
2426 gtk_toggle_action_set_active (show_offline_widget, show_offline);
2428 /* Show protocol ? */
2429 g_signal_connect (priv->gsettings_ui,
2430 "changed::" EMPATHY_PREFS_UI_SHOW_PROTOCOLS,
2431 G_CALLBACK (main_window_notify_show_protocols_cb),
2434 main_window_notify_show_protocols_cb (priv->gsettings_ui,
2435 EMPATHY_PREFS_UI_SHOW_PROTOCOLS,
2438 /* Sort by name / by status ? */
2439 g_signal_connect (priv->gsettings_contacts,
2440 "changed::" EMPATHY_PREFS_CONTACTS_SORT_CRITERIUM,
2441 G_CALLBACK (main_window_notify_sort_contact_cb),
2444 main_window_notify_sort_contact_cb (priv->gsettings_contacts,
2445 EMPATHY_PREFS_CONTACTS_SORT_CRITERIUM,
2448 /* Contacts list size */
2449 g_signal_connect (priv->gsettings_ui,
2450 "changed::" EMPATHY_PREFS_UI_COMPACT_CONTACT_LIST,
2451 G_CALLBACK (main_window_notify_contact_list_size_cb),
2453 g_signal_connect (priv->gsettings_ui,
2454 "changed::" EMPATHY_PREFS_UI_SHOW_AVATARS,
2455 G_CALLBACK (main_window_notify_contact_list_size_cb),
2458 main_window_notify_contact_list_size_cb (priv->gsettings_ui,
2459 EMPATHY_PREFS_UI_SHOW_AVATARS,
2464 empathy_main_window_dup (void)
2466 return g_object_new (EMPATHY_TYPE_MAIN_WINDOW, NULL);