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-live-search.h>
51 #include <libempathy-gtk/empathy-contact-blocking-dialog.h>
52 #include <libempathy-gtk/empathy-contact-search-dialog.h>
53 #include <libempathy-gtk/empathy-geometry.h>
54 #include <libempathy-gtk/empathy-gtk-enum-types.h>
55 #include <libempathy-gtk/empathy-individual-dialogs.h>
56 #include <libempathy-gtk/empathy-individual-store.h>
57 #include <libempathy-gtk/empathy-individual-view.h>
58 #include <libempathy-gtk/empathy-new-message-dialog.h>
59 #include <libempathy-gtk/empathy-new-call-dialog.h>
60 #include <libempathy-gtk/empathy-log-window.h>
61 #include <libempathy-gtk/empathy-presence-chooser.h>
62 #include <libempathy-gtk/empathy-sound-manager.h>
63 #include <libempathy-gtk/empathy-ui-utils.h>
65 #include "empathy-accounts-dialog.h"
66 #include "empathy-call-observer.h"
67 #include "empathy-chat-manager.h"
68 #include "empathy-main-window.h"
69 #include "empathy-preferences.h"
70 #include "empathy-about-dialog.h"
71 #include "empathy-debug-window.h"
72 #include "empathy-new-chatroom-dialog.h"
73 #include "empathy-map-view.h"
74 #include "empathy-chatrooms-window.h"
75 #include "empathy-event-manager.h"
76 #include "empathy-ft-manager.h"
78 #define DEBUG_FLAG EMPATHY_DEBUG_OTHER
79 #include <libempathy/empathy-debug.h>
81 /* Flashing delay for icons (milliseconds). */
82 #define FLASH_TIMEOUT 500
84 /* Minimum width of roster window if something goes wrong. */
87 /* Accels (menu shortcuts) can be configured and saved */
88 #define ACCELS_FILENAME "accels.txt"
90 /* Name in the geometry file */
91 #define GEOMETRY_NAME "main-window"
94 PAGE_CONTACT_LIST = 0,
103 G_DEFINE_TYPE (EmpathyMainWindow, empathy_main_window, GTK_TYPE_WINDOW);
105 #define GET_PRIV(self) ((EmpathyMainWindowPriv *)((EmpathyMainWindow *) self)->priv)
107 struct _EmpathyMainWindowPriv {
108 EmpathyContactList *contact_manager;
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 main_window_flash_stop (EmpathyMainWindow *window)
175 EmpathyMainWindowPriv *priv = GET_PRIV (window);
177 if (priv->flash_timeout_id == 0) {
181 DEBUG ("Stop flashing");
182 g_source_remove (priv->flash_timeout_id);
183 priv->flash_timeout_id = 0;
184 priv->flash_on = FALSE;
190 EmpathyMainWindow *window;
194 main_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)
219 icon_name = data->event->icon_name;
220 pixbuf = empathy_pixbuf_from_icon_name (icon_name, GTK_ICON_SIZE_MENU);
222 pixbuf = empathy_individual_store_get_individual_status_icon (
223 GET_PRIV (data->window)->individual_store,
226 g_object_ref (pixbuf);
229 gtk_tree_store_set (GTK_TREE_STORE (model), iter,
230 EMPATHY_INDIVIDUAL_STORE_COL_ICON_STATUS, pixbuf,
233 /* To make sure the parent is shown correctly, we emit
234 * the row-changed signal on the parent so it prompts
235 * it to be refreshed by the filter func.
237 if (gtk_tree_model_iter_parent (model, &parent_iter, iter)) {
238 parent_path = gtk_tree_model_get_path (model, &parent_iter);
241 gtk_tree_model_row_changed (model, parent_path, &parent_iter);
242 gtk_tree_path_free (parent_path);
246 g_object_unref (individual);
247 tp_clear_object (&contact);
248 tp_clear_object (&pixbuf);
254 main_window_flash_cb (EmpathyMainWindow *window)
256 EmpathyMainWindowPriv *priv = GET_PRIV (window);
259 gboolean found_event = FALSE;
260 FlashForeachData data;
262 priv->flash_on = !priv->flash_on;
263 data.on = priv->flash_on;
264 model = GTK_TREE_MODEL (priv->individual_store);
266 events = empathy_event_manager_get_events (priv->event_manager);
267 for (l = events; l; l = l->next) {
268 data.event = l->data;
269 data.window = window;
270 if (!data.event->contact || !data.event->must_ack) {
275 gtk_tree_model_foreach (model,
276 main_window_flash_foreach,
281 main_window_flash_stop (window);
288 main_window_flash_start (EmpathyMainWindow *window)
290 EmpathyMainWindowPriv *priv = GET_PRIV (window);
292 if (priv->flash_timeout_id != 0) {
296 DEBUG ("Start flashing");
297 priv->flash_timeout_id = g_timeout_add (FLASH_TIMEOUT,
298 (GSourceFunc) main_window_flash_cb,
300 main_window_flash_cb (window);
304 main_window_remove_auth (EmpathyMainWindow *window,
307 EmpathyMainWindowPriv *priv = GET_PRIV (window);
308 GtkWidget *error_widget;
310 error_widget = g_hash_table_lookup (priv->auths, event);
311 if (error_widget != NULL) {
312 gtk_widget_destroy (error_widget);
313 g_hash_table_remove (priv->auths, event);
318 main_window_auth_add_clicked_cb (GtkButton *button,
319 EmpathyMainWindow *window)
323 event = g_object_get_data (G_OBJECT (button), "event");
325 empathy_event_approve (event);
327 main_window_remove_auth (window, event);
331 main_window_auth_close_clicked_cb (GtkButton *button,
332 EmpathyMainWindow *window)
336 event = g_object_get_data (G_OBJECT (button), "event");
338 empathy_event_decline (event);
339 main_window_remove_auth (window, event);
343 main_window_auth_display (EmpathyMainWindow *window,
346 EmpathyMainWindowPriv *priv = GET_PRIV (window);
347 TpAccount *account = event->account;
349 GtkWidget *content_area;
352 GtkWidget *add_button;
353 GtkWidget *close_button;
354 GtkWidget *action_area;
355 GtkWidget *action_grid;
356 const gchar *icon_name;
359 if (g_hash_table_lookup (priv->auths, event) != NULL) {
363 info_bar = gtk_info_bar_new ();
364 gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_QUESTION);
366 gtk_widget_set_no_show_all (info_bar, TRUE);
367 gtk_box_pack_start (GTK_BOX (priv->auth_vbox), info_bar, FALSE, TRUE, 0);
368 gtk_widget_show (info_bar);
370 icon_name = tp_account_get_icon_name (account);
371 image = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_SMALL_TOOLBAR);
372 gtk_widget_show (image);
374 str = g_markup_printf_escaped ("<b>%s</b>\n%s",
375 tp_account_get_display_name (account),
376 _("Password required"));
378 label = gtk_label_new (str);
379 gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
380 gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_END);
381 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
382 gtk_widget_show (label);
386 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
387 gtk_box_pack_start (GTK_BOX (content_area), image, FALSE, FALSE, 0);
388 gtk_box_pack_start (GTK_BOX (content_area), label, TRUE, TRUE, 0);
390 image = gtk_image_new_from_stock (GTK_STOCK_ADD, GTK_ICON_SIZE_BUTTON);
391 add_button = gtk_button_new ();
392 gtk_button_set_image (GTK_BUTTON (add_button), image);
393 gtk_widget_set_tooltip_text (add_button, _("Provide Password"));
394 gtk_widget_show (add_button);
396 image = gtk_image_new_from_stock (GTK_STOCK_CLOSE, GTK_ICON_SIZE_BUTTON);
397 close_button = gtk_button_new ();
398 gtk_button_set_image (GTK_BUTTON (close_button), image);
399 gtk_widget_set_tooltip_text (close_button, _("Disconnect"));
400 gtk_widget_show (close_button);
402 action_grid = gtk_grid_new ();
403 gtk_grid_set_column_spacing (GTK_GRID (action_grid), 6);
404 gtk_widget_show (action_grid);
406 action_area = gtk_info_bar_get_action_area (GTK_INFO_BAR (info_bar));
407 gtk_box_pack_start (GTK_BOX (action_area), action_grid, FALSE, FALSE, 0);
409 gtk_grid_attach (GTK_GRID (action_grid), add_button, 0, 0, 1, 1);
410 gtk_grid_attach (GTK_GRID (action_grid), close_button, 1, 0, 1, 1);
412 g_object_set_data_full (G_OBJECT (info_bar),
413 "event", event, NULL);
414 g_object_set_data_full (G_OBJECT (add_button),
415 "event", event, NULL);
416 g_object_set_data_full (G_OBJECT (close_button),
417 "event", event, NULL);
419 g_signal_connect (add_button, "clicked",
420 G_CALLBACK (main_window_auth_add_clicked_cb),
422 g_signal_connect (close_button, "clicked",
423 G_CALLBACK (main_window_auth_close_clicked_cb),
426 gtk_widget_show (priv->auth_vbox);
428 g_hash_table_insert (priv->auths, event, info_bar);
432 modify_event_count (GtkTreeModel *model,
437 FolksIndividual *individual;
438 EmpathyContact *contact;
441 gtk_tree_model_get (model, iter,
442 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual,
443 EMPATHY_INDIVIDUAL_STORE_COL_EVENT_COUNT, &count,
446 if (individual == NULL)
449 increase ? count++ : count--;
451 contact = empathy_contact_dup_from_folks_individual (individual);
452 if (contact == event->contact) {
453 gtk_tree_store_set (GTK_TREE_STORE (model), iter,
454 EMPATHY_INDIVIDUAL_STORE_COL_EVENT_COUNT, count, -1);
457 tp_clear_object (&contact);
458 g_object_unref (individual);
462 increase_event_count_foreach (GtkTreeModel *model,
467 EmpathyEvent *event = user_data;
469 modify_event_count (model, iter, event, TRUE);
475 increase_event_count (EmpathyMainWindow *self,
478 EmpathyMainWindowPriv *priv = GET_PRIV (self);
481 model = GTK_TREE_MODEL (priv->individual_store);
483 gtk_tree_model_foreach (model, increase_event_count_foreach, event);
487 decrease_event_count_foreach (GtkTreeModel *model,
492 EmpathyEvent *event = user_data;
494 modify_event_count (model, iter, event, FALSE);
500 decrease_event_count (EmpathyMainWindow *self,
503 EmpathyMainWindowPriv *priv = GET_PRIV (self);
506 model = GTK_TREE_MODEL (priv->individual_store);
508 gtk_tree_model_foreach (model, decrease_event_count_foreach, event);
512 main_window_event_added_cb (EmpathyEventManager *manager,
514 EmpathyMainWindow *window)
516 if (event->contact) {
517 increase_event_count (window, event);
519 main_window_flash_start (window);
520 } else if (event->type == EMPATHY_EVENT_TYPE_AUTH) {
521 main_window_auth_display (window, event);
526 main_window_event_removed_cb (EmpathyEventManager *manager,
528 EmpathyMainWindow *window)
530 EmpathyMainWindowPriv *priv = GET_PRIV (window);
531 FlashForeachData data;
533 if (event->type == EMPATHY_EVENT_TYPE_AUTH) {
534 main_window_remove_auth (window, event);
538 if (!event->contact) {
542 decrease_event_count (window, event);
546 data.window = window;
547 gtk_tree_model_foreach (GTK_TREE_MODEL (priv->individual_store),
548 main_window_flash_foreach,
553 main_window_load_events_idle_cb (gpointer user_data)
555 EmpathyMainWindow *window = user_data;
556 EmpathyMainWindowPriv *priv = GET_PRIV (window);
559 l = empathy_event_manager_get_events (priv->event_manager);
561 main_window_event_added_cb (priv->event_manager, l->data,
570 main_window_row_activated_cb (EmpathyIndividualView *view,
572 GtkTreeViewColumn *col,
573 EmpathyMainWindow *window)
575 EmpathyMainWindowPriv *priv = GET_PRIV (window);
576 EmpathyContact *contact = NULL;
577 FolksIndividual *individual;
582 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->individual_view));
583 gtk_tree_model_get_iter (model, &iter, path);
585 gtk_tree_model_get (model, &iter,
586 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL,
590 if (individual != NULL) {
591 contact = empathy_contact_dup_from_folks_individual (individual);
598 /* If the contact has an event activate it, otherwise the
599 * default handler of row-activated will be called. */
600 events = empathy_event_manager_get_events (priv->event_manager);
601 for (l = events; l; l = l->next) {
602 EmpathyEvent *event = l->data;
604 if (event->contact == contact) {
605 DEBUG ("Activate event");
606 empathy_event_activate (event);
608 /* We don't want the default handler of this signal
609 * (e.g. open a chat) */
610 g_signal_stop_emission_by_name (view, "row-activated");
615 g_object_unref (contact);
617 tp_clear_object (&individual);
621 main_window_row_deleted_cb (GtkTreeModel *model,
623 EmpathyMainWindow *window)
625 EmpathyMainWindowPriv *priv = GET_PRIV (window);
626 GtkTreeIter help_iter;
628 if (!gtk_tree_model_get_iter_first (model, &help_iter)) {
631 if (empathy_individual_view_is_searching (
632 priv->individual_view)) {
635 tmp = g_strdup_printf ("<b><span size='xx-large'>%s</span></b>",
636 _("No match found"));
638 gtk_label_set_markup (GTK_LABEL (priv->no_entry_label), tmp);
641 gtk_label_set_line_wrap (GTK_LABEL (priv->no_entry_label),
644 gtk_notebook_set_current_page (
645 GTK_NOTEBOOK (priv->notebook), PAGE_NO_MATCH);
651 main_window_row_inserted_cb (GtkTreeModel *model,
654 EmpathyMainWindow *window)
656 EmpathyMainWindowPriv *priv = GET_PRIV (window);
660 gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook),
662 gtk_widget_grab_focus (GTK_WIDGET (priv->individual_view));
664 /* The store is being filled, it will be done after an idle cb.
665 * So we can then get events. If we do that too soon, event's
666 * contact is not yet in the store and it won't get marked as
668 g_idle_add (main_window_load_events_idle_cb, window);
673 main_window_remove_error (EmpathyMainWindow *window,
676 EmpathyMainWindowPriv *priv = GET_PRIV (window);
677 GtkWidget *error_widget;
679 error_widget = g_hash_table_lookup (priv->errors, account);
680 if (error_widget != NULL) {
681 gtk_widget_destroy (error_widget);
682 g_hash_table_remove (priv->errors, account);
687 main_window_account_disabled_cb (TpAccountManager *manager,
689 EmpathyMainWindow *window)
691 main_window_remove_error (window, account);
695 main_window_error_retry_clicked_cb (GtkButton *button,
696 EmpathyMainWindow *window)
700 account = g_object_get_data (G_OBJECT (button), "account");
701 tp_account_reconnect_async (account, NULL, NULL);
703 main_window_remove_error (window, account);
707 main_window_error_edit_clicked_cb (GtkButton *button,
708 EmpathyMainWindow *window)
712 account = g_object_get_data (G_OBJECT (button), "account");
714 empathy_accounts_dialog_show_application (
715 gtk_widget_get_screen (GTK_WIDGET (button)),
716 account, FALSE, FALSE);
718 main_window_remove_error (window, account);
722 main_window_error_close_clicked_cb (GtkButton *button,
723 EmpathyMainWindow *window)
727 account = g_object_get_data (G_OBJECT (button), "account");
728 main_window_remove_error (window, account);
732 main_window_error_upgrade_sw_clicked_cb (GtkButton *button,
733 EmpathyMainWindow *window)
738 account = g_object_get_data (G_OBJECT (button), "account");
739 main_window_remove_error (window, account);
741 dialog = gtk_message_dialog_new (GTK_WINDOW (window),
742 GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR,
744 _("Sorry, %s accounts can’t be used until your %s software is updated."),
745 tp_account_get_protocol (account),
746 tp_account_get_protocol (account));
748 g_signal_connect_swapped (dialog, "response",
749 G_CALLBACK (gtk_widget_destroy),
752 gtk_widget_show (dialog);
756 main_window_upgrade_software_error (EmpathyMainWindow *window,
759 EmpathyMainWindowPriv *priv = GET_PRIV (window);
761 GtkWidget *content_area;
764 GtkWidget *upgrade_button;
765 GtkWidget *close_button;
766 GtkWidget *action_area;
767 GtkWidget *action_grid;
769 const gchar *icon_name;
770 const gchar *error_message;
771 gboolean user_requested;
774 empathy_account_get_error_message (account, &user_requested);
776 if (user_requested) {
780 str = g_markup_printf_escaped ("<b>%s</b>\n%s",
781 tp_account_get_display_name (account),
784 /* If there are other errors, remove them */
785 main_window_remove_error (window, account);
787 info_bar = gtk_info_bar_new ();
788 gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_ERROR);
790 gtk_widget_set_no_show_all (info_bar, TRUE);
791 gtk_box_pack_start (GTK_BOX (priv->errors_vbox), info_bar, FALSE, TRUE, 0);
792 gtk_widget_show (info_bar);
794 icon_name = tp_account_get_icon_name (account);
795 image = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_SMALL_TOOLBAR);
796 gtk_widget_show (image);
798 label = gtk_label_new (str);
799 gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
800 gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_END);
801 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
802 gtk_widget_show (label);
805 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
806 gtk_box_pack_start (GTK_BOX (content_area), image, FALSE, FALSE, 0);
807 gtk_box_pack_start (GTK_BOX (content_area), label, TRUE, TRUE, 0);
809 image = gtk_image_new_from_stock (GTK_STOCK_REFRESH, GTK_ICON_SIZE_BUTTON);
810 upgrade_button = gtk_button_new ();
811 gtk_button_set_image (GTK_BUTTON (upgrade_button), image);
812 gtk_widget_set_tooltip_text (upgrade_button, _("Update software..."));
813 gtk_widget_show (upgrade_button);
815 image = gtk_image_new_from_stock (GTK_STOCK_CLOSE, GTK_ICON_SIZE_BUTTON);
816 close_button = gtk_button_new ();
817 gtk_button_set_image (GTK_BUTTON (close_button), image);
818 gtk_widget_set_tooltip_text (close_button, _("Close"));
819 gtk_widget_show (close_button);
821 action_grid = gtk_grid_new ();
822 gtk_grid_set_column_spacing (GTK_GRID (action_grid), 2);
823 gtk_widget_show (action_grid);
825 action_area = gtk_info_bar_get_action_area (GTK_INFO_BAR (info_bar));
826 gtk_box_pack_start (GTK_BOX (action_area), action_grid, FALSE, FALSE, 0);
828 gtk_grid_attach (GTK_GRID (action_grid), upgrade_button, 0, 0, 1, 1);
829 gtk_grid_attach (GTK_GRID (action_grid), close_button, 1, 0, 1, 1);
831 g_object_set_data (G_OBJECT (info_bar), "label", label);
832 g_object_set_data_full (G_OBJECT (info_bar),
833 "account", g_object_ref (account),
835 g_object_set_data_full (G_OBJECT (upgrade_button),
836 "account", g_object_ref (account),
838 g_object_set_data_full (G_OBJECT (close_button),
839 "account", g_object_ref (account),
842 g_signal_connect (upgrade_button, "clicked",
843 G_CALLBACK (main_window_error_upgrade_sw_clicked_cb),
845 g_signal_connect (close_button, "clicked",
846 G_CALLBACK (main_window_error_close_clicked_cb),
849 gtk_widget_set_tooltip_text (priv->errors_vbox, error_message);
850 gtk_widget_show (priv->errors_vbox);
852 g_hash_table_insert (priv->errors, g_object_ref (account), info_bar);
856 main_window_error_display (EmpathyMainWindow *window,
859 EmpathyMainWindowPriv *priv = GET_PRIV (window);
861 GtkWidget *content_area;
864 GtkWidget *retry_button;
865 GtkWidget *edit_button;
866 GtkWidget *close_button;
867 GtkWidget *action_area;
868 GtkWidget *action_grid;
870 const gchar *icon_name;
871 const gchar *error_message;
872 gboolean user_requested;
874 if (!tp_strdiff (TP_ERROR_STR_SOFTWARE_UPGRADE_REQUIRED,
875 tp_account_get_detailed_error (account, NULL))) {
876 main_window_upgrade_software_error (window, account);
881 empathy_account_get_error_message (account, &user_requested);
883 if (user_requested) {
887 str = g_markup_printf_escaped ("<b>%s</b>\n%s",
888 tp_account_get_display_name (account),
891 info_bar = g_hash_table_lookup (priv->errors, account);
893 label = g_object_get_data (G_OBJECT (info_bar), "label");
895 /* Just set the latest error and return */
896 gtk_label_set_markup (GTK_LABEL (label), str);
902 info_bar = gtk_info_bar_new ();
903 gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_ERROR);
905 gtk_widget_set_no_show_all (info_bar, TRUE);
906 gtk_box_pack_start (GTK_BOX (priv->errors_vbox), info_bar, FALSE, TRUE, 0);
907 gtk_widget_show (info_bar);
909 icon_name = tp_account_get_icon_name (account);
910 image = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_SMALL_TOOLBAR);
911 gtk_widget_show (image);
913 label = gtk_label_new (str);
914 gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
915 gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_END);
916 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
917 gtk_widget_show (label);
920 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
921 gtk_box_pack_start (GTK_BOX (content_area), image, FALSE, FALSE, 0);
922 gtk_box_pack_start (GTK_BOX (content_area), label, TRUE, TRUE, 0);
924 image = gtk_image_new_from_stock (GTK_STOCK_REFRESH, GTK_ICON_SIZE_BUTTON);
925 retry_button = gtk_button_new ();
926 gtk_button_set_image (GTK_BUTTON (retry_button), image);
927 gtk_widget_set_tooltip_text (retry_button, _("Reconnect"));
928 gtk_widget_show (retry_button);
930 image = gtk_image_new_from_stock (GTK_STOCK_EDIT, GTK_ICON_SIZE_BUTTON);
931 edit_button = gtk_button_new ();
932 gtk_button_set_image (GTK_BUTTON (edit_button), image);
933 gtk_widget_set_tooltip_text (edit_button, _("Edit Account"));
934 gtk_widget_show (edit_button);
936 image = gtk_image_new_from_stock (GTK_STOCK_CLOSE, GTK_ICON_SIZE_BUTTON);
937 close_button = gtk_button_new ();
938 gtk_button_set_image (GTK_BUTTON (close_button), image);
939 gtk_widget_set_tooltip_text (close_button, _("Close"));
940 gtk_widget_show (close_button);
942 action_grid = gtk_grid_new ();
943 gtk_grid_set_column_spacing (GTK_GRID (action_grid), 2);
944 gtk_widget_show (action_grid);
946 action_area = gtk_info_bar_get_action_area (GTK_INFO_BAR (info_bar));
947 gtk_box_pack_start (GTK_BOX (action_area), action_grid, FALSE, FALSE, 0);
949 gtk_grid_attach (GTK_GRID (action_grid), retry_button, 0, 0, 1, 1);
950 gtk_grid_attach (GTK_GRID (action_grid), edit_button, 1, 0, 1, 1);
951 gtk_grid_attach (GTK_GRID (action_grid), close_button, 2, 0, 1, 1);
953 g_object_set_data (G_OBJECT (info_bar), "label", label);
954 g_object_set_data_full (G_OBJECT (info_bar),
955 "account", g_object_ref (account),
957 g_object_set_data_full (G_OBJECT (edit_button),
958 "account", g_object_ref (account),
960 g_object_set_data_full (G_OBJECT (close_button),
961 "account", g_object_ref (account),
963 g_object_set_data_full (G_OBJECT (retry_button),
964 "account", g_object_ref (account),
967 g_signal_connect (edit_button, "clicked",
968 G_CALLBACK (main_window_error_edit_clicked_cb),
970 g_signal_connect (close_button, "clicked",
971 G_CALLBACK (main_window_error_close_clicked_cb),
973 g_signal_connect (retry_button, "clicked",
974 G_CALLBACK (main_window_error_retry_clicked_cb),
977 gtk_widget_set_tooltip_text (priv->errors_vbox, error_message);
978 gtk_widget_show (priv->errors_vbox);
980 g_hash_table_insert (priv->errors, g_object_ref (account), info_bar);
984 main_window_update_status (EmpathyMainWindow *window)
986 EmpathyMainWindowPriv *priv = GET_PRIV (window);
987 gboolean connected, connecting;
990 connected = empathy_account_manager_get_accounts_connected (&connecting);
992 /* Update the spinner state */
994 gtk_spinner_start (GTK_SPINNER (priv->throbber));
995 gtk_widget_show (priv->throbber_tool_item);
997 gtk_spinner_stop (GTK_SPINNER (priv->throbber));
998 gtk_widget_hide (priv->throbber_tool_item);
1001 /* Update widgets sensibility */
1002 for (l = priv->actions_connected; l; l = l->next) {
1003 gtk_action_set_sensitive (l->data, connected);
1006 /* Update favourite rooms sensitivity */
1007 children = gtk_container_get_children (GTK_CONTAINER (priv->room_menu));
1008 for (l = children; l != NULL; l = l->next) {
1009 if (g_object_get_data (G_OBJECT (l->data), "is_favorite") != NULL) {
1010 gtk_widget_set_sensitive (GTK_WIDGET (l->data), connected);
1013 g_list_free (children);
1017 main_window_account_to_action_name (TpAccount *account)
1021 /* action names can't have '/' in them, replace it with '.' */
1022 r = g_strdup (tp_account_get_path_suffix (account));
1023 r = g_strdelimit (r, "/", '.');
1029 main_window_balance_activate_cb (GtkAction *action,
1030 EmpathyMainWindow *window)
1034 uri = g_object_get_data (G_OBJECT (action), "manage-credit-uri");
1036 if (!tp_str_empty (uri)) {
1037 DEBUG ("Top-up credit URI: %s", uri);
1038 empathy_url_show (GTK_WIDGET (window), uri);
1040 DEBUG ("unknown protocol for top-up");
1045 main_window_balance_update_balance (GtkAction *action,
1048 TpAccount *account = tp_connection_get_account (conn);
1051 guint scale = G_MAXINT32;
1052 const gchar *currency = "";
1055 if (!tp_connection_get_balance (conn, &amount, &scale, ¤cy))
1059 scale == G_MAXINT32 &&
1060 tp_str_empty (currency)) {
1061 /* unknown balance */
1062 money = g_strdup ("--");
1064 char *tmp = empathy_format_currency (amount, scale, currency);
1066 money = g_strdup_printf ("%s %s", currency, tmp);
1070 /* Translators: this string will be something like:
1071 * Top up My Account ($1.23)..." */
1072 str = g_strdup_printf (_("Top up %s (%s)..."),
1073 tp_account_get_display_name (account),
1076 gtk_action_set_label (action, str);
1079 /* update the money label in the roster */
1080 label = g_object_get_data (G_OBJECT (action), "money-label");
1082 gtk_label_set_text (GTK_LABEL (label), money);
1087 main_window_balance_changed_cb (TpConnection *conn,
1090 const gchar *currency,
1093 main_window_balance_update_balance (action, conn);
1097 main_window_setup_balance_create_action (EmpathyMainWindow *window,
1100 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1104 GError *error = NULL;
1106 /* create the action group if required */
1107 if (priv->balance_action_group == NULL) {
1108 priv->balance_action_group =
1109 gtk_action_group_new ("balance-action-group");
1111 gtk_ui_manager_insert_action_group (priv->ui_manager,
1112 priv->balance_action_group, -1);
1115 /* create the action */
1116 name = main_window_account_to_action_name (account);
1117 action = gtk_action_new (name,
1118 tp_account_get_display_name (account),
1119 _("Top up account credit"),
1121 g_object_bind_property (account, "icon-name", action, "icon-name",
1122 G_BINDING_SYNC_CREATE);
1124 g_signal_connect (action, "activate",
1125 G_CALLBACK (main_window_balance_activate_cb), window);
1127 gtk_action_group_add_action (priv->balance_action_group, action);
1128 g_object_unref (action);
1130 ui = g_strdup_printf (
1132 " <menubar name='menubar'>"
1133 " <menu action='view'>"
1134 " <placeholder name='view_balance_placeholder'>"
1135 " <menuitem action='%s'/>"
1142 merge_id = gtk_ui_manager_add_ui_from_string (priv->ui_manager,
1144 if (error != NULL) {
1145 DEBUG ("Failed to add balance UI for %s: %s",
1146 tp_account_get_display_name (account),
1148 g_error_free (error);
1151 g_object_set_data (G_OBJECT (action),
1152 "merge-id", GUINT_TO_POINTER (merge_id));
1161 main_window_setup_balance_create_widget (EmpathyMainWindow *window,
1165 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1166 GtkWidget *hbox, *image, *label, *button;
1168 hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
1171 image = gtk_image_new ();
1172 gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, TRUE, 0);
1173 g_object_bind_property (action, "icon-name", image, "icon-name",
1174 G_BINDING_SYNC_CREATE);
1176 /* account name label */
1177 label = gtk_label_new ("");
1178 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
1179 gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 0);
1180 g_object_bind_property (account, "display-name", label, "label",
1181 G_BINDING_SYNC_CREATE);
1184 label = gtk_label_new ("");
1185 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
1186 gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, TRUE, 0);
1187 g_object_set_data (G_OBJECT (action), "money-label", label);
1190 button = gtk_button_new_with_label (_("Top Up..."));
1191 gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, TRUE, 0);
1192 g_signal_connect_swapped (button, "clicked",
1193 G_CALLBACK (gtk_action_activate), action);
1195 gtk_box_pack_start (GTK_BOX (priv->balance_vbox), hbox, FALSE, TRUE, 0);
1196 gtk_widget_show_all (hbox);
1198 /* tie the lifetime of the widget to the lifetime of the action */
1199 g_object_weak_ref (G_OBJECT (action),
1200 (GWeakNotify) gtk_widget_destroy, hbox);
1206 main_window_setup_balance (EmpathyMainWindow *window,
1209 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1210 TpConnection *conn = tp_account_get_connection (account);
1217 if (!tp_proxy_is_prepared (conn, TP_CONNECTION_FEATURE_BALANCE))
1220 DEBUG ("Setting up balance for acct: %s",
1221 tp_account_get_display_name (account));
1223 /* create the action */
1224 action = main_window_setup_balance_create_action (window, account);
1229 gtk_action_set_visible (priv->view_balance_show_in_roster, TRUE);
1231 /* create the display widget */
1232 main_window_setup_balance_create_widget (window, action, account);
1234 /* check the current balance and monitor for any changes */
1235 uri = tp_connection_get_balance_uri (conn);
1237 g_object_set_data_full (G_OBJECT (action), "manage-credit-uri",
1238 g_strdup (uri), g_free);
1239 gtk_action_set_sensitive (GTK_ACTION (action), !tp_str_empty (uri));
1241 main_window_balance_update_balance (GTK_ACTION (action), conn);
1243 g_signal_connect (conn, "balance-changed",
1244 G_CALLBACK (main_window_balance_changed_cb), action);
1249 main_window_remove_balance_action (EmpathyMainWindow *window,
1252 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1257 if (priv->balance_action_group == NULL)
1260 name = main_window_account_to_action_name (account);
1262 action = gtk_action_group_get_action (
1263 priv->balance_action_group, name);
1265 if (action != NULL) {
1268 DEBUG ("Removing action");
1270 merge_id = GPOINTER_TO_UINT (g_object_get_data (
1274 gtk_ui_manager_remove_ui (priv->ui_manager,
1276 gtk_action_group_remove_action (
1277 priv->balance_action_group, action);
1282 a = gtk_action_group_list_actions (
1283 priv->balance_action_group);
1285 gtk_action_set_visible (
1286 priv->view_balance_show_in_roster,
1287 g_list_length (a) > 0);
1293 main_window_connection_changed_cb (TpAccount *account,
1297 gchar *dbus_error_name,
1298 GHashTable *details,
1299 EmpathyMainWindow *window)
1301 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1303 main_window_update_status (window);
1305 if (current == TP_CONNECTION_STATUS_DISCONNECTED &&
1306 reason != TP_CONNECTION_STATUS_REASON_REQUESTED) {
1307 main_window_error_display (window, account);
1310 if (current == TP_CONNECTION_STATUS_DISCONNECTED) {
1311 empathy_sound_manager_play (priv->sound_mgr, GTK_WIDGET (window),
1312 EMPATHY_SOUND_ACCOUNT_DISCONNECTED);
1314 /* remove balance action if required */
1315 main_window_remove_balance_action (window, account);
1318 if (current == TP_CONNECTION_STATUS_CONNECTED) {
1319 empathy_sound_manager_play (priv->sound_mgr, GTK_WIDGET (window),
1320 EMPATHY_SOUND_ACCOUNT_CONNECTED);
1322 /* Account connected without error, remove error message if any */
1323 main_window_remove_error (window, account);
1324 main_window_setup_balance (window, account);
1329 main_window_accels_load (void)
1333 filename = g_build_filename (g_get_user_config_dir (), PACKAGE_NAME, ACCELS_FILENAME, NULL);
1334 if (g_file_test (filename, G_FILE_TEST_EXISTS)) {
1335 DEBUG ("Loading from:'%s'", filename);
1336 gtk_accel_map_load (filename);
1343 main_window_accels_save (void)
1346 gchar *file_with_path;
1348 dir = g_build_filename (g_get_user_config_dir (), PACKAGE_NAME, NULL);
1349 g_mkdir_with_parents (dir, S_IRUSR | S_IWUSR | S_IXUSR);
1350 file_with_path = g_build_filename (dir, ACCELS_FILENAME, NULL);
1353 DEBUG ("Saving to:'%s'", file_with_path);
1354 gtk_accel_map_save (file_with_path);
1356 g_free (file_with_path);
1360 empathy_main_window_finalize (GObject *window)
1362 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1363 GHashTableIter iter;
1364 gpointer key, value;
1366 /* Save user-defined accelerators. */
1367 main_window_accels_save ();
1369 g_list_free (priv->actions_connected);
1371 g_object_unref (priv->account_manager);
1372 g_object_unref (priv->individual_store);
1373 g_object_unref (priv->contact_manager);
1374 g_object_unref (priv->sound_mgr);
1375 g_hash_table_unref (priv->errors);
1376 g_hash_table_unref (priv->auths);
1378 /* disconnect all handlers of status-changed signal */
1379 g_hash_table_iter_init (&iter, priv->status_changed_handlers);
1380 while (g_hash_table_iter_next (&iter, &key, &value))
1381 g_signal_handler_disconnect (TP_ACCOUNT (key),
1382 GPOINTER_TO_UINT (value));
1384 g_hash_table_unref (priv->status_changed_handlers);
1386 g_signal_handlers_disconnect_by_func (priv->event_manager,
1387 main_window_event_added_cb,
1389 g_signal_handlers_disconnect_by_func (priv->event_manager,
1390 main_window_event_removed_cb,
1392 g_object_unref (priv->call_observer);
1393 g_object_unref (priv->event_manager);
1394 g_object_unref (priv->ui_manager);
1395 g_object_unref (priv->chatroom_manager);
1397 g_object_unref (priv->gsettings_ui);
1398 g_object_unref (priv->gsettings_contacts);
1400 G_OBJECT_CLASS (empathy_main_window_parent_class)->finalize (window);
1404 main_window_key_press_event_cb (GtkWidget *window,
1408 if (event->keyval == GDK_KEY_T
1409 && event->state & GDK_SHIFT_MASK
1410 && event->state & GDK_CONTROL_MASK) {
1411 empathy_chat_manager_call_undo_closed_chat ();
1417 main_window_chat_quit_cb (GtkAction *action,
1418 EmpathyMainWindow *window)
1420 gtk_widget_destroy (GTK_WIDGET (window));
1424 main_window_view_history_cb (GtkAction *action,
1425 EmpathyMainWindow *window)
1427 empathy_log_window_show (NULL, NULL, FALSE, GTK_WINDOW (window));
1431 main_window_chat_new_message_cb (GtkAction *action,
1432 EmpathyMainWindow *window)
1434 empathy_new_message_dialog_show (GTK_WINDOW (window));
1438 main_window_chat_new_call_cb (GtkAction *action,
1439 EmpathyMainWindow *window)
1441 empathy_new_call_dialog_show (GTK_WINDOW (window));
1445 main_window_chat_add_contact_cb (GtkAction *action,
1446 EmpathyMainWindow *window)
1448 empathy_new_individual_dialog_show (GTK_WINDOW (window));
1452 main_window_chat_search_contacts_cb (GtkAction *action,
1453 EmpathyMainWindow *window)
1455 GtkWidget *dialog = empathy_contact_search_dialog_new (
1456 GTK_WINDOW (window));
1457 gtk_widget_show (dialog);
1461 main_window_view_show_ft_manager (GtkAction *action,
1462 EmpathyMainWindow *window)
1464 empathy_ft_manager_show ();
1468 main_window_view_show_offline_cb (GtkToggleAction *action,
1469 EmpathyMainWindow *window)
1471 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1474 current = gtk_toggle_action_get_active (action);
1475 g_settings_set_boolean (priv->gsettings_ui,
1476 EMPATHY_PREFS_UI_SHOW_OFFLINE,
1479 empathy_individual_view_set_show_offline (priv->individual_view,
1484 main_window_notify_sort_contact_cb (GSettings *gsettings,
1486 EmpathyMainWindow *window)
1488 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1491 str = g_settings_get_string (gsettings, key);
1495 GEnumClass *enum_class;
1496 GEnumValue *enum_value;
1498 type = empathy_individual_store_sort_get_type ();
1499 enum_class = G_ENUM_CLASS (g_type_class_peek (type));
1500 enum_value = g_enum_get_value_by_nick (enum_class, str);
1502 /* By changing the value of the GtkRadioAction,
1503 it emits a signal that calls main_window_view_sort_contacts_cb
1504 which updates the contacts list */
1505 gtk_radio_action_set_current_value (priv->sort_by_name,
1508 g_warning ("Wrong value for sort_criterium configuration : %s", str);
1515 main_window_view_sort_contacts_cb (GtkRadioAction *action,
1516 GtkRadioAction *current,
1517 EmpathyMainWindow *window)
1519 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1520 EmpathyIndividualStoreSort value;
1523 GEnumClass *enum_class;
1524 GEnumValue *enum_value;
1526 value = gtk_radio_action_get_current_value (action);
1527 group = gtk_radio_action_get_group (action);
1529 /* Get string from index */
1530 type = empathy_individual_store_sort_get_type ();
1531 enum_class = G_ENUM_CLASS (g_type_class_peek (type));
1532 enum_value = g_enum_get_value (enum_class, g_slist_index (group, current));
1535 g_warning ("No GEnumValue for EmpathyContactListSort with GtkRadioAction index:%d",
1536 g_slist_index (group, action));
1538 g_settings_set_string (priv->gsettings_contacts,
1539 EMPATHY_PREFS_CONTACTS_SORT_CRITERIUM,
1540 enum_value->value_nick);
1542 empathy_individual_store_set_sort_criterium (priv->individual_store,
1547 main_window_view_show_protocols_cb (GtkToggleAction *action,
1548 EmpathyMainWindow *window)
1550 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1553 value = gtk_toggle_action_get_active (action);
1555 g_settings_set_boolean (priv->gsettings_ui,
1556 EMPATHY_PREFS_UI_SHOW_PROTOCOLS,
1558 empathy_individual_store_set_show_protocols (priv->individual_store,
1562 /* Matches GtkRadioAction values set in empathy-main-window.ui */
1563 #define CONTACT_LIST_NORMAL_SIZE_WITH_AVATARS 0
1564 #define CONTACT_LIST_NORMAL_SIZE 1
1565 #define CONTACT_LIST_COMPACT_SIZE 2
1568 main_window_view_contacts_list_size_cb (GtkRadioAction *action,
1569 GtkRadioAction *current,
1570 EmpathyMainWindow *window)
1572 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1573 GSettings *gsettings_ui;
1576 value = gtk_radio_action_get_current_value (action);
1577 /* create a new GSettings, so we can delay the setting until both
1579 gsettings_ui = g_settings_new (EMPATHY_PREFS_UI_SCHEMA);
1581 DEBUG ("radio button toggled, value = %i", value);
1583 g_settings_delay (gsettings_ui);
1584 g_settings_set_boolean (gsettings_ui,
1585 EMPATHY_PREFS_UI_SHOW_AVATARS,
1586 value == CONTACT_LIST_NORMAL_SIZE_WITH_AVATARS);
1588 g_settings_set_boolean (gsettings_ui,
1589 EMPATHY_PREFS_UI_COMPACT_CONTACT_LIST,
1590 value == CONTACT_LIST_COMPACT_SIZE);
1591 g_settings_apply (gsettings_ui);
1593 /* FIXME: these enums probably have the wrong namespace */
1594 empathy_individual_store_set_show_avatars (priv->individual_store,
1595 value == CONTACT_LIST_NORMAL_SIZE_WITH_AVATARS);
1596 empathy_individual_store_set_is_compact (priv->individual_store,
1597 value == CONTACT_LIST_COMPACT_SIZE);
1599 g_object_unref (gsettings_ui);
1602 static void main_window_notify_show_protocols_cb (GSettings *gsettings,
1604 EmpathyMainWindow *window)
1606 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1608 gtk_toggle_action_set_active (priv->show_protocols,
1609 g_settings_get_boolean (gsettings,
1610 EMPATHY_PREFS_UI_SHOW_PROTOCOLS));
1615 main_window_notify_contact_list_size_cb (GSettings *gsettings,
1617 EmpathyMainWindow *window)
1619 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1622 if (g_settings_get_boolean (gsettings,
1623 EMPATHY_PREFS_UI_COMPACT_CONTACT_LIST)) {
1624 value = CONTACT_LIST_COMPACT_SIZE;
1625 } else if (g_settings_get_boolean (gsettings,
1626 EMPATHY_PREFS_UI_SHOW_AVATARS)) {
1627 value = CONTACT_LIST_NORMAL_SIZE_WITH_AVATARS;
1629 value = CONTACT_LIST_NORMAL_SIZE;
1632 DEBUG ("setting changed, value = %i", value);
1634 /* By changing the value of the GtkRadioAction,
1635 it emits a signal that calls main_window_view_contacts_list_size_cb
1636 which updates the contacts list */
1637 gtk_radio_action_set_current_value (priv->normal_with_avatars, value);
1641 main_window_edit_search_contacts_cb (GtkCheckMenuItem *item,
1642 EmpathyMainWindow *window)
1644 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1646 empathy_individual_view_start_search (priv->individual_view);
1650 main_window_view_show_map_cb (GtkCheckMenuItem *item,
1651 EmpathyMainWindow *window)
1653 #ifdef HAVE_LIBCHAMPLAIN
1654 empathy_map_view_show ();
1659 join_chatroom (EmpathyChatroom *chatroom,
1665 account = empathy_chatroom_get_account (chatroom);
1666 room = empathy_chatroom_get_room (chatroom);
1668 DEBUG ("Requesting channel for '%s'", room);
1669 empathy_join_muc (account, room, timestamp);
1675 EmpathyChatroom *chatroom;
1679 } join_fav_account_sig_ctx;
1681 static join_fav_account_sig_ctx *
1682 join_fav_account_sig_ctx_new (TpAccount *account,
1683 EmpathyChatroom *chatroom,
1686 join_fav_account_sig_ctx *ctx = g_slice_new0 (
1687 join_fav_account_sig_ctx);
1689 ctx->account = g_object_ref (account);
1690 ctx->chatroom = g_object_ref (chatroom);
1691 ctx->timestamp = timestamp;
1696 join_fav_account_sig_ctx_free (join_fav_account_sig_ctx *ctx)
1698 g_object_unref (ctx->account);
1699 g_object_unref (ctx->chatroom);
1700 g_slice_free (join_fav_account_sig_ctx, ctx);
1704 account_status_changed_cb (TpAccount *account,
1705 TpConnectionStatus old_status,
1706 TpConnectionStatus new_status,
1708 gchar *dbus_error_name,
1709 GHashTable *details,
1712 join_fav_account_sig_ctx *ctx = user_data;
1714 switch (new_status) {
1715 case TP_CONNECTION_STATUS_DISCONNECTED:
1716 /* Don't wait any longer */
1720 case TP_CONNECTION_STATUS_CONNECTING:
1724 case TP_CONNECTION_STATUS_CONNECTED:
1725 /* We can join the room */
1729 g_assert_not_reached ();
1732 join_chatroom (ctx->chatroom, ctx->timestamp);
1735 g_source_remove (ctx->timeout);
1736 g_signal_handler_disconnect (account, ctx->sig_id);
1739 #define JOIN_FAVORITE_TIMEOUT 5
1742 join_favorite_timeout_cb (gpointer data)
1744 join_fav_account_sig_ctx *ctx = data;
1746 /* stop waiting for joining the favorite room */
1747 g_signal_handler_disconnect (ctx->account, ctx->sig_id);
1752 main_window_favorite_chatroom_join (EmpathyChatroom *chatroom)
1756 account = empathy_chatroom_get_account (chatroom);
1757 if (tp_account_get_connection_status (account, NULL) !=
1758 TP_CONNECTION_STATUS_CONNECTED) {
1759 join_fav_account_sig_ctx *ctx;
1761 ctx = join_fav_account_sig_ctx_new (account, chatroom,
1762 empathy_get_current_action_time ());
1764 ctx->sig_id = g_signal_connect_data (account, "status-changed",
1765 G_CALLBACK (account_status_changed_cb), ctx,
1766 (GClosureNotify) join_fav_account_sig_ctx_free, 0);
1768 ctx->timeout = g_timeout_add_seconds (JOIN_FAVORITE_TIMEOUT,
1769 join_favorite_timeout_cb, ctx);
1773 join_chatroom (chatroom, empathy_get_current_action_time ());
1777 main_window_favorite_chatroom_menu_activate_cb (GtkMenuItem *menu_item,
1778 EmpathyChatroom *chatroom)
1780 main_window_favorite_chatroom_join (chatroom);
1784 main_window_favorite_chatroom_menu_add (EmpathyMainWindow *window,
1785 EmpathyChatroom *chatroom)
1787 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1788 GtkWidget *menu_item;
1789 const gchar *name, *account_name;
1793 if (g_object_get_data (G_OBJECT (chatroom), "menu_item")) {
1797 name = empathy_chatroom_get_name (chatroom);
1798 account_name = tp_account_get_display_name (
1799 empathy_chatroom_get_account (chatroom));
1800 label = g_strdup_printf ("%s (%s)", name, account_name);
1801 menu_item = gtk_menu_item_new_with_label (label);
1803 g_object_set_data (G_OBJECT (menu_item), "is_favorite",
1804 GUINT_TO_POINTER (TRUE));
1806 g_object_set_data (G_OBJECT (chatroom), "menu_item", menu_item);
1807 g_signal_connect (menu_item, "activate",
1808 G_CALLBACK (main_window_favorite_chatroom_menu_activate_cb),
1811 gtk_menu_shell_insert (GTK_MENU_SHELL (priv->room_menu),
1814 gtk_widget_show (menu_item);
1818 main_window_favorite_chatroom_menu_added_cb (EmpathyChatroomManager *manager,
1819 EmpathyChatroom *chatroom,
1820 EmpathyMainWindow *window)
1822 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1824 main_window_favorite_chatroom_menu_add (window, chatroom);
1825 gtk_widget_show (priv->room_separator);
1826 gtk_action_set_sensitive (priv->room_join_favorites, TRUE);
1830 main_window_favorite_chatroom_menu_removed_cb (EmpathyChatroomManager *manager,
1831 EmpathyChatroom *chatroom,
1832 EmpathyMainWindow *window)
1834 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1835 GtkWidget *menu_item;
1838 menu_item = g_object_get_data (G_OBJECT (chatroom), "menu_item");
1839 g_object_set_data (G_OBJECT (chatroom), "menu_item", NULL);
1840 gtk_widget_destroy (menu_item);
1842 chatrooms = empathy_chatroom_manager_get_chatrooms (priv->chatroom_manager, NULL);
1844 gtk_widget_show (priv->room_separator);
1846 gtk_widget_hide (priv->room_separator);
1849 gtk_action_set_sensitive (priv->room_join_favorites, chatrooms != NULL);
1850 g_list_free (chatrooms);
1854 main_window_favorite_chatroom_menu_setup (EmpathyMainWindow *window)
1856 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1857 GList *chatrooms, *l;
1860 priv->chatroom_manager = empathy_chatroom_manager_dup_singleton (NULL);
1861 chatrooms = empathy_chatroom_manager_get_chatrooms (
1862 priv->chatroom_manager, NULL);
1863 room = gtk_ui_manager_get_widget (priv->ui_manager,
1865 priv->room_menu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (room));
1866 priv->room_separator = gtk_ui_manager_get_widget (priv->ui_manager,
1867 "/menubar/room/room_separator");
1869 for (l = chatrooms; l; l = l->next) {
1870 main_window_favorite_chatroom_menu_add (window, l->data);
1874 gtk_widget_hide (priv->room_separator);
1877 gtk_action_set_sensitive (priv->room_join_favorites, chatrooms != NULL);
1879 g_signal_connect (priv->chatroom_manager, "chatroom-added",
1880 G_CALLBACK (main_window_favorite_chatroom_menu_added_cb),
1882 g_signal_connect (priv->chatroom_manager, "chatroom-removed",
1883 G_CALLBACK (main_window_favorite_chatroom_menu_removed_cb),
1886 g_list_free (chatrooms);
1890 main_window_room_join_new_cb (GtkAction *action,
1891 EmpathyMainWindow *window)
1893 empathy_new_chatroom_dialog_show (GTK_WINDOW (window));
1897 main_window_room_join_favorites_cb (GtkAction *action,
1898 EmpathyMainWindow *window)
1900 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1901 GList *chatrooms, *l;
1903 chatrooms = empathy_chatroom_manager_get_chatrooms (priv->chatroom_manager, NULL);
1904 for (l = chatrooms; l; l = l->next) {
1905 main_window_favorite_chatroom_join (l->data);
1907 g_list_free (chatrooms);
1911 main_window_room_manage_favorites_cb (GtkAction *action,
1912 EmpathyMainWindow *window)
1914 empathy_chatrooms_window_show (GTK_WINDOW (window));
1918 main_window_edit_cb (GtkAction *action,
1919 EmpathyMainWindow *window)
1921 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1924 /* FIXME: It should use the UIManager to merge the contact/group submenu */
1925 submenu = empathy_individual_view_get_individual_menu (
1926 priv->individual_view);
1931 item = GTK_MENU_ITEM (priv->edit_context);
1932 label = gtk_bin_get_child (GTK_BIN (item));
1933 gtk_label_set_text (GTK_LABEL (label), _("Contact"));
1935 gtk_widget_show (priv->edit_context);
1936 gtk_widget_show (priv->edit_context_separator);
1938 gtk_menu_item_set_submenu (item, submenu);
1943 submenu = empathy_individual_view_get_group_menu (
1944 priv->individual_view);
1949 item = GTK_MENU_ITEM (priv->edit_context);
1950 label = gtk_bin_get_child (GTK_BIN (item));
1951 gtk_label_set_text (GTK_LABEL (label), _("Group"));
1953 gtk_widget_show (priv->edit_context);
1954 gtk_widget_show (priv->edit_context_separator);
1956 gtk_menu_item_set_submenu (item, submenu);
1961 gtk_widget_hide (priv->edit_context);
1962 gtk_widget_hide (priv->edit_context_separator);
1968 main_window_edit_accounts_cb (GtkAction *action,
1969 EmpathyMainWindow *window)
1971 empathy_accounts_dialog_show_application (gdk_screen_get_default (),
1972 NULL, FALSE, FALSE);
1976 main_window_edit_personal_information_cb (GtkAction *action,
1977 EmpathyMainWindow *window)
1979 empathy_contact_personal_dialog_show (GTK_WINDOW (window));
1983 main_window_edit_blocked_contacts_cb (GtkAction *action,
1984 EmpathyMainWindow *window)
1988 dialog = empathy_contact_blocking_dialog_new (GTK_WINDOW (window));
1989 gtk_widget_show (dialog);
1990 g_signal_connect (dialog, "response",
1991 G_CALLBACK (gtk_widget_destroy), NULL);
1995 empathy_main_window_show_preferences (EmpathyMainWindow *window,
1998 EmpathyMainWindowPriv *priv = GET_PRIV (window);
2000 if (priv->preferences == NULL) {
2001 priv->preferences = empathy_preferences_new (GTK_WINDOW (window),
2002 priv->shell_running);
2003 g_object_add_weak_pointer (G_OBJECT (priv->preferences),
2004 (gpointer) &priv->preferences);
2006 gtk_widget_show (priv->preferences);
2008 gtk_window_present (GTK_WINDOW (priv->preferences));
2012 empathy_preferences_show_tab (
2013 EMPATHY_PREFERENCES (priv->preferences), tab);
2017 main_window_edit_preferences_cb (GtkAction *action,
2018 EmpathyMainWindow *window)
2020 empathy_main_window_show_preferences (window, NULL);
2024 main_window_help_about_cb (GtkAction *action,
2025 EmpathyMainWindow *window)
2027 empathy_about_dialog_new (GTK_WINDOW (window));
2031 main_window_help_debug_cb (GtkAction *action,
2032 EmpathyMainWindow *window)
2034 empathy_launch_program (BIN_DIR, "empathy-debugger", NULL);
2038 main_window_help_contents_cb (GtkAction *action,
2039 EmpathyMainWindow *window)
2041 empathy_url_show (GTK_WIDGET (window), "ghelp:empathy");
2045 main_window_throbber_button_press_event_cb (GtkWidget *throbber,
2046 GdkEventButton *event,
2047 EmpathyMainWindow *window)
2049 if (event->type != GDK_BUTTON_PRESS ||
2050 event->button != 1) {
2054 empathy_accounts_dialog_show_application (
2055 gtk_widget_get_screen (GTK_WIDGET (throbber)),
2056 NULL, FALSE, FALSE);
2062 main_window_account_removed_cb (TpAccountManager *manager,
2064 EmpathyMainWindow *window)
2066 EmpathyMainWindowPriv *priv = GET_PRIV (window);
2069 a = tp_account_manager_get_valid_accounts (manager);
2071 gtk_action_set_sensitive (priv->view_history,
2072 g_list_length (a) > 0);
2076 /* remove errors if any */
2077 main_window_remove_error (window, account);
2079 /* remove the balance action if required */
2080 main_window_remove_balance_action (window, account);
2084 main_window_account_validity_changed_cb (TpAccountManager *manager,
2087 EmpathyMainWindow *window)
2089 EmpathyMainWindowPriv *priv = GET_PRIV (window);
2093 handler_id = GPOINTER_TO_UINT (g_hash_table_lookup (
2094 priv->status_changed_handlers, account));
2096 /* connect signal only if it was not connected yet */
2097 if (handler_id == 0) {
2098 handler_id = g_signal_connect (account,
2100 G_CALLBACK (main_window_connection_changed_cb),
2102 g_hash_table_insert (priv->status_changed_handlers,
2103 account, GUINT_TO_POINTER (handler_id));
2107 main_window_account_removed_cb (manager, account, window);
2111 main_window_notify_show_offline_cb (GSettings *gsettings,
2113 gpointer toggle_action)
2115 gtk_toggle_action_set_active (toggle_action,
2116 g_settings_get_boolean (gsettings, key));
2120 main_window_connection_items_setup (EmpathyMainWindow *window,
2123 EmpathyMainWindowPriv *priv = GET_PRIV (window);
2127 const gchar *actions_connected[] = {
2129 "room_join_favorites",
2132 "chat_search_contacts",
2134 "edit_personal_information",
2135 "edit_blocked_contacts",
2136 "edit_search_contacts"
2139 for (i = 0, list = NULL; i < G_N_ELEMENTS (actions_connected); i++) {
2140 action = gtk_builder_get_object (gui, actions_connected[i]);
2141 list = g_list_prepend (list, action);
2144 priv->actions_connected = list;
2148 account_manager_prepared_cb (GObject *source_object,
2149 GAsyncResult *result,
2152 GList *accounts, *j;
2153 TpAccountManager *manager = TP_ACCOUNT_MANAGER (source_object);
2154 EmpathyMainWindow *window = user_data;
2155 EmpathyMainWindowPriv *priv = GET_PRIV (window);
2156 GError *error = NULL;
2158 if (!tp_proxy_prepare_finish (manager, result, &error)) {
2159 DEBUG ("Failed to prepare account manager: %s", error->message);
2160 g_error_free (error);
2164 accounts = tp_account_manager_get_valid_accounts (priv->account_manager);
2165 for (j = accounts; j != NULL; j = j->next) {
2166 TpAccount *account = TP_ACCOUNT (j->data);
2169 handler_id = g_signal_connect (account, "status-changed",
2170 G_CALLBACK (main_window_connection_changed_cb),
2172 g_hash_table_insert (priv->status_changed_handlers,
2173 account, GUINT_TO_POINTER (handler_id));
2175 main_window_setup_balance (window, account);
2178 g_signal_connect (manager, "account-validity-changed",
2179 G_CALLBACK (main_window_account_validity_changed_cb),
2182 main_window_update_status (window);
2184 /* Disable the "Previous Conversations" menu entry if there is no account */
2185 gtk_action_set_sensitive (priv->view_history,
2186 g_list_length (accounts) > 0);
2188 g_list_free (accounts);
2192 empathy_main_window_set_shell_running (EmpathyMainWindow *window,
2193 gboolean shell_running)
2195 EmpathyMainWindowPriv *priv = GET_PRIV (window);
2197 if (priv->shell_running == shell_running)
2200 priv->shell_running = shell_running;
2201 g_object_notify (G_OBJECT (window), "shell-running");
2205 empathy_main_window_constructor (GType type,
2206 guint n_construct_params,
2207 GObjectConstructParam *construct_params)
2209 static GObject *window = NULL;
2212 return g_object_ref (window);
2214 window = G_OBJECT_CLASS (empathy_main_window_parent_class)->constructor (
2215 type, n_construct_params, construct_params);
2217 g_object_add_weak_pointer (window, (gpointer) &window);
2223 empathy_main_window_set_property (GObject *object,
2225 const GValue *value,
2228 EmpathyMainWindow *self = EMPATHY_MAIN_WINDOW (object);
2229 EmpathyMainWindowPriv *priv = GET_PRIV (self);
2231 switch (property_id)
2233 case PROP_SHELL_RUNNING:
2234 priv->shell_running = g_value_get_boolean (value);
2237 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2243 empathy_main_window_get_property (GObject *object,
2248 EmpathyMainWindow *self = EMPATHY_MAIN_WINDOW (object);
2249 EmpathyMainWindowPriv *priv = GET_PRIV (self);
2251 switch (property_id)
2253 case PROP_SHELL_RUNNING:
2254 g_value_set_boolean (value, priv->shell_running);
2257 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2263 empathy_main_window_class_init (EmpathyMainWindowClass *klass)
2265 GObjectClass *object_class = G_OBJECT_CLASS (klass);
2268 object_class->finalize = empathy_main_window_finalize;
2269 object_class->constructor = empathy_main_window_constructor;
2271 object_class->set_property = empathy_main_window_set_property;
2272 object_class->get_property = empathy_main_window_get_property;
2274 pspec = g_param_spec_boolean ("shell-running",
2276 "Whether the Shell is running or not",
2278 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
2279 g_object_class_install_property (object_class, PROP_SHELL_RUNNING, pspec);
2281 g_type_class_add_private (object_class, sizeof (EmpathyMainWindowPriv));
2285 empathy_main_window_init (EmpathyMainWindow *window)
2287 EmpathyMainWindowPriv *priv;
2288 EmpathyIndividualManager *individual_manager;
2289 GtkBuilder *gui, *gui_mgr;
2291 GtkToggleAction *show_offline_widget;
2292 GtkAction *show_map_widget;
2294 gboolean show_offline;
2296 GtkTreeModel *model;
2297 GtkWidget *search_vbox;
2300 priv = window->priv = G_TYPE_INSTANCE_GET_PRIVATE (window,
2301 EMPATHY_TYPE_MAIN_WINDOW, EmpathyMainWindowPriv);
2303 priv->gsettings_ui = g_settings_new (EMPATHY_PREFS_UI_SCHEMA);
2304 priv->gsettings_contacts = g_settings_new (EMPATHY_PREFS_CONTACTS_SCHEMA);
2306 priv->sound_mgr = empathy_sound_manager_dup_singleton ();
2308 gtk_window_set_title (GTK_WINDOW (window), _("Contact List"));
2309 gtk_window_set_role (GTK_WINDOW (window), "contact_list");
2310 gtk_window_set_default_size (GTK_WINDOW (window), 225, 325);
2312 /* don't finalize the widget on delete-event, just hide it */
2313 g_signal_connect (window, "delete-event",
2314 G_CALLBACK (gtk_widget_hide_on_delete), NULL);
2316 /* Set up interface */
2317 filename = empathy_file_lookup ("empathy-main-window.ui", "src");
2318 gui = empathy_builder_get_file (filename,
2319 "main_vbox", &priv->main_vbox,
2320 "balance_vbox", &priv->balance_vbox,
2321 "errors_vbox", &priv->errors_vbox,
2322 "auth_vbox", &priv->auth_vbox,
2323 "search_vbox", &search_vbox,
2324 "presence_toolbar", &priv->presence_toolbar,
2325 "notebook", &priv->notebook,
2326 "no_entry_label", &priv->no_entry_label,
2327 "roster_scrolledwindow", &sw,
2331 /* Set UI manager */
2332 filename = empathy_file_lookup ("empathy-main-window-menubar.ui", "src");
2333 gui_mgr = empathy_builder_get_file (filename,
2334 "ui_manager", &priv->ui_manager,
2335 "view_show_offline", &show_offline_widget,
2336 "view_show_protocols", &priv->show_protocols,
2337 "view_sort_by_name", &priv->sort_by_name,
2338 "view_sort_by_status", &priv->sort_by_status,
2339 "view_normal_size_with_avatars", &priv->normal_with_avatars,
2340 "view_normal_size", &priv->normal_size,
2341 "view_compact_size", &priv->compact_size,
2342 "view_history", &priv->view_history,
2343 "view_show_map", &show_map_widget,
2344 "room_join_favorites", &priv->room_join_favorites,
2345 "view_balance_show_in_roster", &priv->view_balance_show_in_roster,
2346 "menubar", &menubar,
2350 /* The UI manager is living in its own .ui file as Glade doesn't support
2351 * those. The GtkMenubar has to be in this file as well to we manually add
2352 * it to the first position of the vbox. */
2353 gtk_box_pack_start (GTK_BOX (priv->main_vbox), menubar, FALSE, FALSE, 0);
2354 gtk_box_reorder_child (GTK_BOX (priv->main_vbox), menubar, 0);
2356 gtk_container_add (GTK_CONTAINER (window), priv->main_vbox);
2357 gtk_widget_show (priv->main_vbox);
2359 g_signal_connect (window, "key-press-event",
2360 G_CALLBACK (main_window_key_press_event_cb), NULL);
2362 empathy_builder_connect (gui_mgr, window,
2363 "chat_quit", "activate", main_window_chat_quit_cb,
2364 "chat_new_message", "activate", main_window_chat_new_message_cb,
2365 "chat_new_call", "activate", main_window_chat_new_call_cb,
2366 "view_history", "activate", main_window_view_history_cb,
2367 "room_join_new", "activate", main_window_room_join_new_cb,
2368 "room_join_favorites", "activate", main_window_room_join_favorites_cb,
2369 "room_manage_favorites", "activate", main_window_room_manage_favorites_cb,
2370 "chat_add_contact", "activate", main_window_chat_add_contact_cb,
2371 "chat_search_contacts", "activate", main_window_chat_search_contacts_cb,
2372 "view_show_ft_manager", "activate", main_window_view_show_ft_manager,
2373 "view_show_offline", "toggled", main_window_view_show_offline_cb,
2374 "view_show_protocols", "toggled", main_window_view_show_protocols_cb,
2375 "view_sort_by_name", "changed", main_window_view_sort_contacts_cb,
2376 "view_normal_size_with_avatars", "changed", main_window_view_contacts_list_size_cb,
2377 "view_show_map", "activate", main_window_view_show_map_cb,
2378 "edit", "activate", main_window_edit_cb,
2379 "edit_accounts", "activate", main_window_edit_accounts_cb,
2380 "edit_personal_information", "activate", main_window_edit_personal_information_cb,
2381 "edit_blocked_contacts", "activate", main_window_edit_blocked_contacts_cb,
2382 "edit_preferences", "activate", main_window_edit_preferences_cb,
2383 "edit_search_contacts", "activate", main_window_edit_search_contacts_cb,
2384 "help_about", "activate", main_window_help_about_cb,
2385 "help_debug", "activate", main_window_help_debug_cb,
2386 "help_contents", "activate", main_window_help_contents_cb,
2389 /* Set up connection related widgets. */
2390 main_window_connection_items_setup (window, gui_mgr);
2392 g_object_ref (priv->ui_manager);
2393 g_object_unref (gui);
2394 g_object_unref (gui_mgr);
2396 #ifndef HAVE_LIBCHAMPLAIN
2397 gtk_action_set_visible (show_map_widget, FALSE);
2400 priv->account_manager = tp_account_manager_dup ();
2402 tp_proxy_prepare_async (priv->account_manager, NULL,
2403 account_manager_prepared_cb, window);
2405 priv->errors = g_hash_table_new_full (g_direct_hash,
2410 priv->auths = g_hash_table_new (NULL, NULL);
2412 priv->status_changed_handlers = g_hash_table_new_full (g_direct_hash,
2418 main_window_favorite_chatroom_menu_setup (window);
2420 priv->edit_context = gtk_ui_manager_get_widget (priv->ui_manager,
2421 "/menubar/edit/edit_context");
2422 priv->edit_context_separator = gtk_ui_manager_get_widget (
2424 "/menubar/edit/edit_context_separator");
2425 gtk_widget_hide (priv->edit_context);
2426 gtk_widget_hide (priv->edit_context_separator);
2428 /* Set up contact list. */
2429 empathy_status_presets_get_all ();
2431 /* Set up presence chooser */
2432 priv->presence_chooser = empathy_presence_chooser_new ();
2433 gtk_widget_show (priv->presence_chooser);
2434 item = gtk_tool_item_new ();
2435 gtk_widget_show (GTK_WIDGET (item));
2436 gtk_widget_set_size_request (priv->presence_chooser, 10, -1);
2437 gtk_container_add (GTK_CONTAINER (item), priv->presence_chooser);
2438 gtk_tool_item_set_is_important (item, TRUE);
2439 gtk_tool_item_set_expand (item, TRUE);
2440 gtk_toolbar_insert (GTK_TOOLBAR (priv->presence_toolbar), item, -1);
2442 /* Set up the throbber */
2443 priv->throbber = gtk_spinner_new ();
2444 gtk_widget_set_size_request (priv->throbber, 16, -1);
2445 gtk_widget_set_events (priv->throbber, GDK_BUTTON_PRESS_MASK);
2446 g_signal_connect (priv->throbber, "button-press-event",
2447 G_CALLBACK (main_window_throbber_button_press_event_cb),
2449 gtk_widget_show (priv->throbber);
2451 item = gtk_tool_item_new ();
2452 gtk_container_set_border_width (GTK_CONTAINER (item), 6);
2453 gtk_toolbar_insert (GTK_TOOLBAR (priv->presence_toolbar), item, -1);
2454 gtk_container_add (GTK_CONTAINER (item), priv->throbber);
2455 priv->throbber_tool_item = GTK_WIDGET (item);
2457 /* XXX: this class is designed to live for the duration of the program,
2458 * so it's got a race condition between its signal handlers and its
2459 * finalization. The class is planned to be removed, so we won't fix
2460 * this before then. */
2461 priv->contact_manager = EMPATHY_CONTACT_LIST (
2462 empathy_contact_manager_dup_singleton ());
2463 individual_manager = empathy_individual_manager_dup_singleton ();
2464 priv->individual_store = empathy_individual_store_new (
2465 individual_manager);
2466 g_object_unref (individual_manager);
2468 /* For the moment, we disallow Persona drops onto the main contact list (e.g. from things such as
2469 * the EmpathyPersonaView in the linking dialogue). No code is hooked up to do anything on a Persona
2470 * drop, so allowing them would achieve nothing except confusion. */
2471 priv->individual_view = empathy_individual_view_new (
2472 priv->individual_store,
2473 EMPATHY_INDIVIDUAL_VIEW_FEATURE_ALL ^ EMPATHY_INDIVIDUAL_VIEW_FEATURE_PERSONA_DROP,
2474 EMPATHY_INDIVIDUAL_FEATURE_ALL);
2476 gtk_widget_show (GTK_WIDGET (priv->individual_view));
2477 gtk_container_add (GTK_CONTAINER (sw),
2478 GTK_WIDGET (priv->individual_view));
2479 g_signal_connect (priv->individual_view, "row-activated",
2480 G_CALLBACK (main_window_row_activated_cb),
2483 /* Set up search bar */
2484 priv->search_bar = empathy_live_search_new (
2485 GTK_WIDGET (priv->individual_view));
2486 empathy_individual_view_set_live_search (priv->individual_view,
2487 EMPATHY_LIVE_SEARCH (priv->search_bar));
2488 gtk_box_pack_start (GTK_BOX (search_vbox), priv->search_bar,
2491 g_signal_connect_swapped (window, "map",
2492 G_CALLBACK (gtk_widget_grab_focus), priv->individual_view);
2494 /* Connect to proper signals to check if contact list is empty or not */
2495 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->individual_view));
2497 g_signal_connect (model, "row-inserted",
2498 G_CALLBACK (main_window_row_inserted_cb),
2500 g_signal_connect (model, "row-deleted",
2501 G_CALLBACK (main_window_row_deleted_cb),
2504 /* Load user-defined accelerators. */
2505 main_window_accels_load ();
2507 /* Set window size. */
2508 empathy_geometry_bind (GTK_WINDOW (window), GEOMETRY_NAME);
2510 /* bind view_balance_show_in_roster */
2511 g_settings_bind (priv->gsettings_ui, "show-balance-in-roster",
2512 priv->view_balance_show_in_roster, "active",
2513 G_SETTINGS_BIND_DEFAULT);
2514 g_object_bind_property (priv->view_balance_show_in_roster, "active",
2515 priv->balance_vbox, "visible",
2516 G_BINDING_SYNC_CREATE);
2518 /* Enable event handling */
2519 priv->call_observer = empathy_call_observer_dup_singleton ();
2520 priv->event_manager = empathy_event_manager_dup_singleton ();
2522 g_signal_connect (priv->event_manager, "event-added",
2523 G_CALLBACK (main_window_event_added_cb), window);
2524 g_signal_connect (priv->event_manager, "event-removed",
2525 G_CALLBACK (main_window_event_removed_cb), window);
2526 g_signal_connect (priv->account_manager, "account-validity-changed",
2527 G_CALLBACK (main_window_account_validity_changed_cb),
2529 g_signal_connect (priv->account_manager, "account-removed",
2530 G_CALLBACK (main_window_account_removed_cb),
2532 g_signal_connect (priv->account_manager, "account-disabled",
2533 G_CALLBACK (main_window_account_disabled_cb),
2536 /* Show offline ? */
2537 show_offline = g_settings_get_boolean (priv->gsettings_ui,
2538 EMPATHY_PREFS_UI_SHOW_OFFLINE);
2539 g_signal_connect (priv->gsettings_ui,
2540 "changed::" EMPATHY_PREFS_UI_SHOW_OFFLINE,
2541 G_CALLBACK (main_window_notify_show_offline_cb),
2542 show_offline_widget);
2544 gtk_toggle_action_set_active (show_offline_widget, show_offline);
2546 /* Show protocol ? */
2547 g_signal_connect (priv->gsettings_ui,
2548 "changed::" EMPATHY_PREFS_UI_SHOW_PROTOCOLS,
2549 G_CALLBACK (main_window_notify_show_protocols_cb),
2552 main_window_notify_show_protocols_cb (priv->gsettings_ui,
2553 EMPATHY_PREFS_UI_SHOW_PROTOCOLS,
2556 /* Sort by name / by status ? */
2557 g_signal_connect (priv->gsettings_contacts,
2558 "changed::" EMPATHY_PREFS_CONTACTS_SORT_CRITERIUM,
2559 G_CALLBACK (main_window_notify_sort_contact_cb),
2562 main_window_notify_sort_contact_cb (priv->gsettings_contacts,
2563 EMPATHY_PREFS_CONTACTS_SORT_CRITERIUM,
2566 /* Contacts list size */
2567 g_signal_connect (priv->gsettings_ui,
2568 "changed::" EMPATHY_PREFS_UI_COMPACT_CONTACT_LIST,
2569 G_CALLBACK (main_window_notify_contact_list_size_cb),
2571 g_signal_connect (priv->gsettings_ui,
2572 "changed::" EMPATHY_PREFS_UI_SHOW_AVATARS,
2573 G_CALLBACK (main_window_notify_contact_list_size_cb),
2576 main_window_notify_contact_list_size_cb (priv->gsettings_ui,
2577 EMPATHY_PREFS_UI_SHOW_AVATARS,
2582 empathy_main_window_dup (void)
2584 return g_object_new (EMPATHY_TYPE_MAIN_WINDOW, NULL);