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-store-manager.h>
58 #include <libempathy-gtk/empathy-individual-view.h>
59 #include <libempathy-gtk/empathy-new-message-dialog.h>
60 #include <libempathy-gtk/empathy-new-call-dialog.h>
61 #include <libempathy-gtk/empathy-log-window.h>
62 #include <libempathy-gtk/empathy-presence-chooser.h>
63 #include <libempathy-gtk/empathy-sound-manager.h>
64 #include <libempathy-gtk/empathy-ui-utils.h>
66 #include "empathy-accounts-dialog.h"
67 #include "empathy-call-observer.h"
68 #include "empathy-chat-manager.h"
69 #include "empathy-main-window.h"
70 #include "empathy-preferences.h"
71 #include "empathy-about-dialog.h"
72 #include "empathy-debug-window.h"
73 #include "empathy-new-chatroom-dialog.h"
74 #include "empathy-map-view.h"
75 #include "empathy-chatrooms-window.h"
76 #include "empathy-event-manager.h"
77 #include "empathy-ft-manager.h"
79 #define DEBUG_FLAG EMPATHY_DEBUG_OTHER
80 #include <libempathy/empathy-debug.h>
82 /* Flashing delay for icons (milliseconds). */
83 #define FLASH_TIMEOUT 500
85 /* Minimum width of roster window if something goes wrong. */
88 /* Accels (menu shortcuts) can be configured and saved */
89 #define ACCELS_FILENAME "accels.txt"
91 /* Name in the geometry file */
92 #define GEOMETRY_NAME "main-window"
95 PAGE_CONTACT_LIST = 0,
104 G_DEFINE_TYPE (EmpathyMainWindow, empathy_main_window, GTK_TYPE_WINDOW);
106 #define GET_PRIV(self) ((EmpathyMainWindowPriv *)((EmpathyMainWindow *) self)->priv)
108 struct _EmpathyMainWindowPriv {
109 EmpathyContactList *contact_manager;
110 EmpathyIndividualStore *individual_store;
111 EmpathyIndividualView *individual_view;
112 TpAccountManager *account_manager;
113 EmpathyChatroomManager *chatroom_manager;
114 EmpathyEventManager *event_manager;
115 EmpathySoundManager *sound_mgr;
116 EmpathyCallObserver *call_observer;
117 guint flash_timeout_id;
121 GSettings *gsettings_ui;
122 GSettings *gsettings_contacts;
124 GtkWidget *preferences;
125 GtkWidget *main_vbox;
127 GtkWidget *throbber_tool_item;
128 GtkWidget *presence_toolbar;
129 GtkWidget *presence_chooser;
130 GtkWidget *errors_vbox;
131 GtkWidget *auth_vbox;
132 GtkWidget *search_bar;
134 GtkWidget *no_entry_label;
136 GtkToggleAction *show_protocols;
137 GtkRadioAction *sort_by_name;
138 GtkRadioAction *sort_by_status;
139 GtkRadioAction *normal_with_avatars;
140 GtkRadioAction *normal_size;
141 GtkRadioAction *compact_size;
143 GtkUIManager *ui_manager;
144 GtkAction *view_history;
145 GtkAction *room_join_favorites;
146 GtkWidget *room_menu;
147 GtkWidget *room_separator;
148 GtkWidget *edit_context;
149 GtkWidget *edit_context_separator;
151 GtkActionGroup *balance_action_group;
152 GtkAction *view_balance_show_in_roster;
153 GtkWidget *balance_vbox;
155 guint size_timeout_id;
157 /* reffed TpAccount* => visible GtkInfoBar* */
160 /* EmpathyEvent* => visible GtkInfoBar* */
163 /* stores a mapping from TpAccount to Handler ID to prevent
164 * to listen more than once to the status-changed signal */
165 GHashTable *status_changed_handlers;
167 /* Actions that are enabled when there are connected accounts */
168 GList *actions_connected;
170 gboolean shell_running;
174 main_window_flash_stop (EmpathyMainWindow *window)
176 EmpathyMainWindowPriv *priv = GET_PRIV (window);
178 if (priv->flash_timeout_id == 0) {
182 DEBUG ("Stop flashing");
183 g_source_remove (priv->flash_timeout_id);
184 priv->flash_timeout_id = 0;
185 priv->flash_on = FALSE;
191 EmpathyMainWindow *window;
195 main_window_flash_foreach (GtkTreeModel *model,
200 FlashForeachData *data = (FlashForeachData *) user_data;
201 FolksIndividual *individual;
202 EmpathyContact *contact;
203 const gchar *icon_name;
204 GtkTreePath *parent_path = NULL;
205 GtkTreeIter parent_iter;
206 GdkPixbuf *pixbuf = NULL;
208 gtk_tree_model_get (model, iter,
209 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual,
212 if (individual == NULL)
215 contact = empathy_contact_dup_from_folks_individual (individual);
216 if (contact != data->event->contact)
220 icon_name = data->event->icon_name;
221 pixbuf = empathy_pixbuf_from_icon_name (icon_name, GTK_ICON_SIZE_MENU);
223 pixbuf = empathy_individual_store_get_individual_status_icon (
224 GET_PRIV (data->window)->individual_store,
227 g_object_ref (pixbuf);
230 gtk_tree_store_set (GTK_TREE_STORE (model), iter,
231 EMPATHY_INDIVIDUAL_STORE_COL_ICON_STATUS, pixbuf,
234 /* To make sure the parent is shown correctly, we emit
235 * the row-changed signal on the parent so it prompts
236 * it to be refreshed by the filter func.
238 if (gtk_tree_model_iter_parent (model, &parent_iter, iter)) {
239 parent_path = gtk_tree_model_get_path (model, &parent_iter);
242 gtk_tree_model_row_changed (model, parent_path, &parent_iter);
243 gtk_tree_path_free (parent_path);
247 g_object_unref (individual);
248 tp_clear_object (&contact);
249 tp_clear_object (&pixbuf);
255 main_window_flash_cb (EmpathyMainWindow *window)
257 EmpathyMainWindowPriv *priv = GET_PRIV (window);
260 gboolean found_event = FALSE;
261 FlashForeachData data;
263 priv->flash_on = !priv->flash_on;
264 data.on = priv->flash_on;
265 model = GTK_TREE_MODEL (priv->individual_store);
267 events = empathy_event_manager_get_events (priv->event_manager);
268 for (l = events; l; l = l->next) {
269 data.event = l->data;
270 data.window = window;
271 if (!data.event->contact || !data.event->must_ack) {
276 gtk_tree_model_foreach (model,
277 main_window_flash_foreach,
282 main_window_flash_stop (window);
289 main_window_flash_start (EmpathyMainWindow *window)
291 EmpathyMainWindowPriv *priv = GET_PRIV (window);
293 if (priv->flash_timeout_id != 0) {
297 DEBUG ("Start flashing");
298 priv->flash_timeout_id = g_timeout_add (FLASH_TIMEOUT,
299 (GSourceFunc) main_window_flash_cb,
301 main_window_flash_cb (window);
305 main_window_remove_auth (EmpathyMainWindow *window,
308 EmpathyMainWindowPriv *priv = GET_PRIV (window);
309 GtkWidget *error_widget;
311 error_widget = g_hash_table_lookup (priv->auths, event);
312 if (error_widget != NULL) {
313 gtk_widget_destroy (error_widget);
314 g_hash_table_remove (priv->auths, event);
319 main_window_auth_add_clicked_cb (GtkButton *button,
320 EmpathyMainWindow *window)
324 event = g_object_get_data (G_OBJECT (button), "event");
326 empathy_event_approve (event);
328 main_window_remove_auth (window, event);
332 main_window_auth_close_clicked_cb (GtkButton *button,
333 EmpathyMainWindow *window)
337 event = g_object_get_data (G_OBJECT (button), "event");
339 empathy_event_decline (event);
340 main_window_remove_auth (window, event);
344 main_window_auth_display (EmpathyMainWindow *window,
347 EmpathyMainWindowPriv *priv = GET_PRIV (window);
348 TpAccount *account = event->account;
350 GtkWidget *content_area;
353 GtkWidget *add_button;
354 GtkWidget *close_button;
355 GtkWidget *action_area;
356 GtkWidget *action_grid;
357 const gchar *icon_name;
360 if (g_hash_table_lookup (priv->auths, event) != NULL) {
364 info_bar = gtk_info_bar_new ();
365 gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_QUESTION);
367 gtk_widget_set_no_show_all (info_bar, TRUE);
368 gtk_box_pack_start (GTK_BOX (priv->auth_vbox), info_bar, FALSE, TRUE, 0);
369 gtk_widget_show (info_bar);
371 icon_name = tp_account_get_icon_name (account);
372 image = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_SMALL_TOOLBAR);
373 gtk_widget_show (image);
375 str = g_markup_printf_escaped ("<b>%s</b>\n%s",
376 tp_account_get_display_name (account),
377 _("Password required"));
379 label = gtk_label_new (str);
380 gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
381 gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_END);
382 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
383 gtk_widget_show (label);
387 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
388 gtk_box_pack_start (GTK_BOX (content_area), image, FALSE, FALSE, 0);
389 gtk_box_pack_start (GTK_BOX (content_area), label, TRUE, TRUE, 0);
391 image = gtk_image_new_from_stock (GTK_STOCK_ADD, GTK_ICON_SIZE_BUTTON);
392 add_button = gtk_button_new ();
393 gtk_button_set_image (GTK_BUTTON (add_button), image);
394 gtk_widget_set_tooltip_text (add_button, _("Provide Password"));
395 gtk_widget_show (add_button);
397 image = gtk_image_new_from_stock (GTK_STOCK_CLOSE, GTK_ICON_SIZE_BUTTON);
398 close_button = gtk_button_new ();
399 gtk_button_set_image (GTK_BUTTON (close_button), image);
400 gtk_widget_set_tooltip_text (close_button, _("Disconnect"));
401 gtk_widget_show (close_button);
403 action_grid = gtk_grid_new ();
404 gtk_grid_set_column_spacing (GTK_GRID (action_grid), 6);
405 gtk_widget_show (action_grid);
407 action_area = gtk_info_bar_get_action_area (GTK_INFO_BAR (info_bar));
408 gtk_box_pack_start (GTK_BOX (action_area), action_grid, FALSE, FALSE, 0);
410 gtk_grid_attach (GTK_GRID (action_grid), add_button, 0, 0, 1, 1);
411 gtk_grid_attach (GTK_GRID (action_grid), close_button, 1, 0, 1, 1);
413 g_object_set_data_full (G_OBJECT (info_bar),
414 "event", event, NULL);
415 g_object_set_data_full (G_OBJECT (add_button),
416 "event", event, NULL);
417 g_object_set_data_full (G_OBJECT (close_button),
418 "event", event, NULL);
420 g_signal_connect (add_button, "clicked",
421 G_CALLBACK (main_window_auth_add_clicked_cb),
423 g_signal_connect (close_button, "clicked",
424 G_CALLBACK (main_window_auth_close_clicked_cb),
427 gtk_widget_show (priv->auth_vbox);
429 g_hash_table_insert (priv->auths, event, info_bar);
433 modify_event_count (GtkTreeModel *model,
438 FolksIndividual *individual;
439 EmpathyContact *contact;
442 gtk_tree_model_get (model, iter,
443 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual,
444 EMPATHY_INDIVIDUAL_STORE_COL_EVENT_COUNT, &count,
447 if (individual == NULL)
450 increase ? count++ : count--;
452 contact = empathy_contact_dup_from_folks_individual (individual);
453 if (contact == event->contact) {
454 gtk_tree_store_set (GTK_TREE_STORE (model), iter,
455 EMPATHY_INDIVIDUAL_STORE_COL_EVENT_COUNT, count, -1);
458 tp_clear_object (&contact);
459 g_object_unref (individual);
463 increase_event_count_foreach (GtkTreeModel *model,
468 EmpathyEvent *event = user_data;
470 modify_event_count (model, iter, event, TRUE);
476 increase_event_count (EmpathyMainWindow *self,
479 EmpathyMainWindowPriv *priv = GET_PRIV (self);
482 model = GTK_TREE_MODEL (priv->individual_store);
484 gtk_tree_model_foreach (model, increase_event_count_foreach, event);
488 decrease_event_count_foreach (GtkTreeModel *model,
493 EmpathyEvent *event = user_data;
495 modify_event_count (model, iter, event, FALSE);
501 decrease_event_count (EmpathyMainWindow *self,
504 EmpathyMainWindowPriv *priv = GET_PRIV (self);
507 model = GTK_TREE_MODEL (priv->individual_store);
509 gtk_tree_model_foreach (model, decrease_event_count_foreach, event);
513 main_window_event_added_cb (EmpathyEventManager *manager,
515 EmpathyMainWindow *window)
517 if (event->contact) {
518 increase_event_count (window, event);
520 main_window_flash_start (window);
521 } else if (event->type == EMPATHY_EVENT_TYPE_AUTH) {
522 main_window_auth_display (window, event);
527 main_window_event_removed_cb (EmpathyEventManager *manager,
529 EmpathyMainWindow *window)
531 EmpathyMainWindowPriv *priv = GET_PRIV (window);
532 FlashForeachData data;
534 if (event->type == EMPATHY_EVENT_TYPE_AUTH) {
535 main_window_remove_auth (window, event);
539 if (!event->contact) {
543 decrease_event_count (window, event);
547 data.window = window;
548 gtk_tree_model_foreach (GTK_TREE_MODEL (priv->individual_store),
549 main_window_flash_foreach,
554 main_window_load_events_idle_cb (gpointer user_data)
556 EmpathyMainWindow *window = user_data;
557 EmpathyMainWindowPriv *priv = GET_PRIV (window);
560 l = empathy_event_manager_get_events (priv->event_manager);
562 main_window_event_added_cb (priv->event_manager, l->data,
571 main_window_row_activated_cb (EmpathyIndividualView *view,
573 GtkTreeViewColumn *col,
574 EmpathyMainWindow *window)
576 EmpathyMainWindowPriv *priv = GET_PRIV (window);
577 EmpathyContact *contact = NULL;
578 FolksIndividual *individual;
583 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->individual_view));
584 gtk_tree_model_get_iter (model, &iter, path);
586 gtk_tree_model_get (model, &iter,
587 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL,
591 if (individual != NULL) {
592 contact = empathy_contact_dup_from_folks_individual (individual);
599 /* If the contact has an event activate it, otherwise the
600 * default handler of row-activated will be called. */
601 events = empathy_event_manager_get_events (priv->event_manager);
602 for (l = events; l; l = l->next) {
603 EmpathyEvent *event = l->data;
605 if (event->contact == contact) {
606 DEBUG ("Activate event");
607 empathy_event_activate (event);
609 /* We don't want the default handler of this signal
610 * (e.g. open a chat) */
611 g_signal_stop_emission_by_name (view, "row-activated");
616 g_object_unref (contact);
618 tp_clear_object (&individual);
622 main_window_row_deleted_cb (GtkTreeModel *model,
624 EmpathyMainWindow *window)
626 EmpathyMainWindowPriv *priv = GET_PRIV (window);
627 GtkTreeIter help_iter;
629 if (!gtk_tree_model_get_iter_first (model, &help_iter)) {
632 if (empathy_individual_view_is_searching (
633 priv->individual_view)) {
636 tmp = g_strdup_printf ("<b><span size='xx-large'>%s</span></b>",
637 _("No match found"));
639 gtk_label_set_markup (GTK_LABEL (priv->no_entry_label), tmp);
642 gtk_label_set_line_wrap (GTK_LABEL (priv->no_entry_label),
645 gtk_notebook_set_current_page (
646 GTK_NOTEBOOK (priv->notebook), PAGE_NO_MATCH);
652 main_window_row_inserted_cb (GtkTreeModel *model,
655 EmpathyMainWindow *window)
657 EmpathyMainWindowPriv *priv = GET_PRIV (window);
661 gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook),
663 gtk_widget_grab_focus (GTK_WIDGET (priv->individual_view));
665 /* The store is being filled, it will be done after an idle cb.
666 * So we can then get events. If we do that too soon, event's
667 * contact is not yet in the store and it won't get marked as
669 g_idle_add (main_window_load_events_idle_cb, window);
674 main_window_remove_error (EmpathyMainWindow *window,
677 EmpathyMainWindowPriv *priv = GET_PRIV (window);
678 GtkWidget *error_widget;
680 error_widget = g_hash_table_lookup (priv->errors, account);
681 if (error_widget != NULL) {
682 gtk_widget_destroy (error_widget);
683 g_hash_table_remove (priv->errors, account);
688 main_window_account_disabled_cb (TpAccountManager *manager,
690 EmpathyMainWindow *window)
692 main_window_remove_error (window, account);
696 main_window_error_retry_clicked_cb (GtkButton *button,
697 EmpathyMainWindow *window)
701 account = g_object_get_data (G_OBJECT (button), "account");
702 tp_account_reconnect_async (account, NULL, NULL);
704 main_window_remove_error (window, account);
708 main_window_error_edit_clicked_cb (GtkButton *button,
709 EmpathyMainWindow *window)
713 account = g_object_get_data (G_OBJECT (button), "account");
715 empathy_accounts_dialog_show_application (
716 gtk_widget_get_screen (GTK_WIDGET (button)),
717 account, FALSE, FALSE);
719 main_window_remove_error (window, account);
723 main_window_error_close_clicked_cb (GtkButton *button,
724 EmpathyMainWindow *window)
728 account = g_object_get_data (G_OBJECT (button), "account");
729 main_window_remove_error (window, account);
733 main_window_error_upgrade_sw_clicked_cb (GtkButton *button,
734 EmpathyMainWindow *window)
739 account = g_object_get_data (G_OBJECT (button), "account");
740 main_window_remove_error (window, account);
742 dialog = gtk_message_dialog_new (GTK_WINDOW (window),
743 GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR,
745 _("Sorry, %s accounts can’t be used until your %s software is updated."),
746 tp_account_get_protocol (account),
747 tp_account_get_protocol (account));
749 g_signal_connect_swapped (dialog, "response",
750 G_CALLBACK (gtk_widget_destroy),
753 gtk_widget_show (dialog);
757 main_window_upgrade_software_error (EmpathyMainWindow *window,
760 EmpathyMainWindowPriv *priv = GET_PRIV (window);
762 GtkWidget *content_area;
765 GtkWidget *upgrade_button;
766 GtkWidget *close_button;
767 GtkWidget *action_area;
768 GtkWidget *action_grid;
770 const gchar *icon_name;
771 const gchar *error_message;
772 gboolean user_requested;
775 empathy_account_get_error_message (account, &user_requested);
777 if (user_requested) {
781 str = g_markup_printf_escaped ("<b>%s</b>\n%s",
782 tp_account_get_display_name (account),
785 /* If there are other errors, remove them */
786 main_window_remove_error (window, account);
788 info_bar = gtk_info_bar_new ();
789 gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_ERROR);
791 gtk_widget_set_no_show_all (info_bar, TRUE);
792 gtk_box_pack_start (GTK_BOX (priv->errors_vbox), info_bar, FALSE, TRUE, 0);
793 gtk_widget_show (info_bar);
795 icon_name = tp_account_get_icon_name (account);
796 image = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_SMALL_TOOLBAR);
797 gtk_widget_show (image);
799 label = gtk_label_new (str);
800 gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
801 gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_END);
802 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
803 gtk_widget_show (label);
806 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
807 gtk_box_pack_start (GTK_BOX (content_area), image, FALSE, FALSE, 0);
808 gtk_box_pack_start (GTK_BOX (content_area), label, TRUE, TRUE, 0);
810 image = gtk_image_new_from_stock (GTK_STOCK_REFRESH, GTK_ICON_SIZE_BUTTON);
811 upgrade_button = gtk_button_new ();
812 gtk_button_set_image (GTK_BUTTON (upgrade_button), image);
813 gtk_widget_set_tooltip_text (upgrade_button, _("Update software..."));
814 gtk_widget_show (upgrade_button);
816 image = gtk_image_new_from_stock (GTK_STOCK_CLOSE, GTK_ICON_SIZE_BUTTON);
817 close_button = gtk_button_new ();
818 gtk_button_set_image (GTK_BUTTON (close_button), image);
819 gtk_widget_set_tooltip_text (close_button, _("Close"));
820 gtk_widget_show (close_button);
822 action_grid = gtk_grid_new ();
823 gtk_grid_set_column_spacing (GTK_GRID (action_grid), 2);
824 gtk_widget_show (action_grid);
826 action_area = gtk_info_bar_get_action_area (GTK_INFO_BAR (info_bar));
827 gtk_box_pack_start (GTK_BOX (action_area), action_grid, FALSE, FALSE, 0);
829 gtk_grid_attach (GTK_GRID (action_grid), upgrade_button, 0, 0, 1, 1);
830 gtk_grid_attach (GTK_GRID (action_grid), close_button, 1, 0, 1, 1);
832 g_object_set_data (G_OBJECT (info_bar), "label", label);
833 g_object_set_data_full (G_OBJECT (info_bar),
834 "account", g_object_ref (account),
836 g_object_set_data_full (G_OBJECT (upgrade_button),
837 "account", g_object_ref (account),
839 g_object_set_data_full (G_OBJECT (close_button),
840 "account", g_object_ref (account),
843 g_signal_connect (upgrade_button, "clicked",
844 G_CALLBACK (main_window_error_upgrade_sw_clicked_cb),
846 g_signal_connect (close_button, "clicked",
847 G_CALLBACK (main_window_error_close_clicked_cb),
850 gtk_widget_set_tooltip_text (priv->errors_vbox, error_message);
851 gtk_widget_show (priv->errors_vbox);
853 g_hash_table_insert (priv->errors, g_object_ref (account), info_bar);
857 main_window_error_display (EmpathyMainWindow *window,
860 EmpathyMainWindowPriv *priv = GET_PRIV (window);
862 GtkWidget *content_area;
865 GtkWidget *retry_button;
866 GtkWidget *edit_button;
867 GtkWidget *close_button;
868 GtkWidget *action_area;
869 GtkWidget *action_grid;
871 const gchar *icon_name;
872 const gchar *error_message;
873 gboolean user_requested;
875 if (!tp_strdiff (TP_ERROR_STR_SOFTWARE_UPGRADE_REQUIRED,
876 tp_account_get_detailed_error (account, NULL))) {
877 main_window_upgrade_software_error (window, account);
882 empathy_account_get_error_message (account, &user_requested);
884 if (user_requested) {
888 str = g_markup_printf_escaped ("<b>%s</b>\n%s",
889 tp_account_get_display_name (account),
892 info_bar = g_hash_table_lookup (priv->errors, account);
894 label = g_object_get_data (G_OBJECT (info_bar), "label");
896 /* Just set the latest error and return */
897 gtk_label_set_markup (GTK_LABEL (label), str);
903 info_bar = gtk_info_bar_new ();
904 gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_ERROR);
906 gtk_widget_set_no_show_all (info_bar, TRUE);
907 gtk_box_pack_start (GTK_BOX (priv->errors_vbox), info_bar, FALSE, TRUE, 0);
908 gtk_widget_show (info_bar);
910 icon_name = tp_account_get_icon_name (account);
911 image = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_SMALL_TOOLBAR);
912 gtk_widget_show (image);
914 label = gtk_label_new (str);
915 gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
916 gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_END);
917 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
918 gtk_widget_show (label);
921 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
922 gtk_box_pack_start (GTK_BOX (content_area), image, FALSE, FALSE, 0);
923 gtk_box_pack_start (GTK_BOX (content_area), label, TRUE, TRUE, 0);
925 image = gtk_image_new_from_stock (GTK_STOCK_REFRESH, GTK_ICON_SIZE_BUTTON);
926 retry_button = gtk_button_new ();
927 gtk_button_set_image (GTK_BUTTON (retry_button), image);
928 gtk_widget_set_tooltip_text (retry_button, _("Reconnect"));
929 gtk_widget_show (retry_button);
931 image = gtk_image_new_from_stock (GTK_STOCK_EDIT, GTK_ICON_SIZE_BUTTON);
932 edit_button = gtk_button_new ();
933 gtk_button_set_image (GTK_BUTTON (edit_button), image);
934 gtk_widget_set_tooltip_text (edit_button, _("Edit Account"));
935 gtk_widget_show (edit_button);
937 image = gtk_image_new_from_stock (GTK_STOCK_CLOSE, GTK_ICON_SIZE_BUTTON);
938 close_button = gtk_button_new ();
939 gtk_button_set_image (GTK_BUTTON (close_button), image);
940 gtk_widget_set_tooltip_text (close_button, _("Close"));
941 gtk_widget_show (close_button);
943 action_grid = gtk_grid_new ();
944 gtk_grid_set_column_spacing (GTK_GRID (action_grid), 2);
945 gtk_widget_show (action_grid);
947 action_area = gtk_info_bar_get_action_area (GTK_INFO_BAR (info_bar));
948 gtk_box_pack_start (GTK_BOX (action_area), action_grid, FALSE, FALSE, 0);
950 gtk_grid_attach (GTK_GRID (action_grid), retry_button, 0, 0, 1, 1);
951 gtk_grid_attach (GTK_GRID (action_grid), edit_button, 1, 0, 1, 1);
952 gtk_grid_attach (GTK_GRID (action_grid), close_button, 2, 0, 1, 1);
954 g_object_set_data (G_OBJECT (info_bar), "label", label);
955 g_object_set_data_full (G_OBJECT (info_bar),
956 "account", g_object_ref (account),
958 g_object_set_data_full (G_OBJECT (edit_button),
959 "account", g_object_ref (account),
961 g_object_set_data_full (G_OBJECT (close_button),
962 "account", g_object_ref (account),
964 g_object_set_data_full (G_OBJECT (retry_button),
965 "account", g_object_ref (account),
968 g_signal_connect (edit_button, "clicked",
969 G_CALLBACK (main_window_error_edit_clicked_cb),
971 g_signal_connect (close_button, "clicked",
972 G_CALLBACK (main_window_error_close_clicked_cb),
974 g_signal_connect (retry_button, "clicked",
975 G_CALLBACK (main_window_error_retry_clicked_cb),
978 gtk_widget_set_tooltip_text (priv->errors_vbox, error_message);
979 gtk_widget_show (priv->errors_vbox);
981 g_hash_table_insert (priv->errors, g_object_ref (account), info_bar);
985 main_window_update_status (EmpathyMainWindow *window)
987 EmpathyMainWindowPriv *priv = GET_PRIV (window);
988 gboolean connected, connecting;
991 connected = empathy_account_manager_get_accounts_connected (&connecting);
993 /* Update the spinner state */
995 gtk_spinner_start (GTK_SPINNER (priv->throbber));
996 gtk_widget_show (priv->throbber_tool_item);
998 gtk_spinner_stop (GTK_SPINNER (priv->throbber));
999 gtk_widget_hide (priv->throbber_tool_item);
1002 /* Update widgets sensibility */
1003 for (l = priv->actions_connected; l; l = l->next) {
1004 gtk_action_set_sensitive (l->data, connected);
1007 /* Update favourite rooms sensitivity */
1008 children = gtk_container_get_children (GTK_CONTAINER (priv->room_menu));
1009 for (l = children; l != NULL; l = l->next) {
1010 if (g_object_get_data (G_OBJECT (l->data), "is_favorite") != NULL) {
1011 gtk_widget_set_sensitive (GTK_WIDGET (l->data), connected);
1014 g_list_free (children);
1018 main_window_account_to_action_name (TpAccount *account)
1022 /* action names can't have '/' in them, replace it with '.' */
1023 r = g_strdup (tp_account_get_path_suffix (account));
1024 r = g_strdelimit (r, "/", '.');
1030 main_window_balance_activate_cb (GtkAction *action,
1031 EmpathyMainWindow *window)
1035 uri = g_object_get_data (G_OBJECT (action), "manage-credit-uri");
1037 if (!tp_str_empty (uri)) {
1038 DEBUG ("Top-up credit URI: %s", uri);
1039 empathy_url_show (GTK_WIDGET (window), uri);
1041 DEBUG ("unknown protocol for top-up");
1046 main_window_balance_update_balance (GtkAction *action,
1049 TpAccount *account = tp_connection_get_account (conn);
1052 guint scale = G_MAXINT32;
1053 const gchar *currency = "";
1056 if (!tp_connection_get_balance (conn, &amount, &scale, ¤cy))
1060 scale == G_MAXINT32 &&
1061 tp_str_empty (currency)) {
1062 /* unknown balance */
1063 money = g_strdup ("--");
1065 char *tmp = empathy_format_currency (amount, scale, currency);
1067 money = g_strdup_printf ("%s %s", currency, tmp);
1071 /* Translators: this string will be something like:
1072 * Top up My Account ($1.23)..." */
1073 str = g_strdup_printf (_("Top up %s (%s)..."),
1074 tp_account_get_display_name (account),
1077 gtk_action_set_label (action, str);
1080 /* update the money label in the roster */
1081 label = g_object_get_data (G_OBJECT (action), "money-label");
1083 gtk_label_set_text (GTK_LABEL (label), money);
1088 main_window_balance_changed_cb (TpConnection *conn,
1091 const gchar *currency,
1094 main_window_balance_update_balance (action, conn);
1098 main_window_setup_balance_create_action (EmpathyMainWindow *window,
1101 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1105 GError *error = NULL;
1107 /* create the action group if required */
1108 if (priv->balance_action_group == NULL) {
1109 priv->balance_action_group =
1110 gtk_action_group_new ("balance-action-group");
1112 gtk_ui_manager_insert_action_group (priv->ui_manager,
1113 priv->balance_action_group, -1);
1116 /* create the action */
1117 name = main_window_account_to_action_name (account);
1118 action = gtk_action_new (name,
1119 tp_account_get_display_name (account),
1120 _("Top up account credit"),
1122 g_object_bind_property (account, "icon-name", action, "icon-name",
1123 G_BINDING_SYNC_CREATE);
1125 g_signal_connect (action, "activate",
1126 G_CALLBACK (main_window_balance_activate_cb), window);
1128 gtk_action_group_add_action (priv->balance_action_group, action);
1129 g_object_unref (action);
1131 ui = g_strdup_printf (
1133 " <menubar name='menubar'>"
1134 " <menu action='view'>"
1135 " <placeholder name='view_balance_placeholder'>"
1136 " <menuitem action='%s'/>"
1143 merge_id = gtk_ui_manager_add_ui_from_string (priv->ui_manager,
1145 if (error != NULL) {
1146 DEBUG ("Failed to add balance UI for %s: %s",
1147 tp_account_get_display_name (account),
1149 g_error_free (error);
1152 g_object_set_data (G_OBJECT (action),
1153 "merge-id", GUINT_TO_POINTER (merge_id));
1162 main_window_setup_balance_create_widget (EmpathyMainWindow *window,
1166 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1167 GtkWidget *hbox, *image, *label, *button;
1169 hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
1172 image = gtk_image_new ();
1173 gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, TRUE, 0);
1174 g_object_bind_property (action, "icon-name", image, "icon-name",
1175 G_BINDING_SYNC_CREATE);
1177 /* account name label */
1178 label = gtk_label_new ("");
1179 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
1180 gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 0);
1181 g_object_bind_property (account, "display-name", label, "label",
1182 G_BINDING_SYNC_CREATE);
1185 label = gtk_label_new ("");
1186 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
1187 gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, TRUE, 0);
1188 g_object_set_data (G_OBJECT (action), "money-label", label);
1191 button = gtk_button_new_with_label (_("Top Up..."));
1192 gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, TRUE, 0);
1193 g_signal_connect_swapped (button, "clicked",
1194 G_CALLBACK (gtk_action_activate), action);
1196 gtk_box_pack_start (GTK_BOX (priv->balance_vbox), hbox, FALSE, TRUE, 0);
1197 gtk_widget_show_all (hbox);
1199 /* tie the lifetime of the widget to the lifetime of the action */
1200 g_object_weak_ref (G_OBJECT (action),
1201 (GWeakNotify) gtk_widget_destroy, hbox);
1207 main_window_setup_balance (EmpathyMainWindow *window,
1210 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1211 TpConnection *conn = tp_account_get_connection (account);
1218 if (!tp_proxy_is_prepared (conn, TP_CONNECTION_FEATURE_BALANCE))
1221 DEBUG ("Setting up balance for acct: %s",
1222 tp_account_get_display_name (account));
1224 /* create the action */
1225 action = main_window_setup_balance_create_action (window, account);
1230 gtk_action_set_visible (priv->view_balance_show_in_roster, TRUE);
1232 /* create the display widget */
1233 main_window_setup_balance_create_widget (window, action, account);
1235 /* check the current balance and monitor for any changes */
1236 uri = tp_connection_get_balance_uri (conn);
1238 g_object_set_data_full (G_OBJECT (action), "manage-credit-uri",
1239 g_strdup (uri), g_free);
1240 gtk_action_set_sensitive (GTK_ACTION (action), !tp_str_empty (uri));
1242 main_window_balance_update_balance (GTK_ACTION (action), conn);
1244 g_signal_connect (conn, "balance-changed",
1245 G_CALLBACK (main_window_balance_changed_cb), action);
1250 main_window_remove_balance_action (EmpathyMainWindow *window,
1253 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1258 if (priv->balance_action_group == NULL)
1261 name = main_window_account_to_action_name (account);
1263 action = gtk_action_group_get_action (
1264 priv->balance_action_group, name);
1266 if (action != NULL) {
1269 DEBUG ("Removing action");
1271 merge_id = GPOINTER_TO_UINT (g_object_get_data (
1275 gtk_ui_manager_remove_ui (priv->ui_manager,
1277 gtk_action_group_remove_action (
1278 priv->balance_action_group, action);
1283 a = gtk_action_group_list_actions (
1284 priv->balance_action_group);
1286 gtk_action_set_visible (
1287 priv->view_balance_show_in_roster,
1288 g_list_length (a) > 0);
1294 main_window_connection_changed_cb (TpAccount *account,
1298 gchar *dbus_error_name,
1299 GHashTable *details,
1300 EmpathyMainWindow *window)
1302 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1304 main_window_update_status (window);
1306 if (current == TP_CONNECTION_STATUS_DISCONNECTED &&
1307 reason != TP_CONNECTION_STATUS_REASON_REQUESTED) {
1308 main_window_error_display (window, account);
1311 if (current == TP_CONNECTION_STATUS_DISCONNECTED) {
1312 empathy_sound_manager_play (priv->sound_mgr, GTK_WIDGET (window),
1313 EMPATHY_SOUND_ACCOUNT_DISCONNECTED);
1315 /* remove balance action if required */
1316 main_window_remove_balance_action (window, account);
1319 if (current == TP_CONNECTION_STATUS_CONNECTED) {
1320 empathy_sound_manager_play (priv->sound_mgr, GTK_WIDGET (window),
1321 EMPATHY_SOUND_ACCOUNT_CONNECTED);
1323 /* Account connected without error, remove error message if any */
1324 main_window_remove_error (window, account);
1325 main_window_setup_balance (window, account);
1330 main_window_accels_load (void)
1334 filename = g_build_filename (g_get_user_config_dir (), PACKAGE_NAME, ACCELS_FILENAME, NULL);
1335 if (g_file_test (filename, G_FILE_TEST_EXISTS)) {
1336 DEBUG ("Loading from:'%s'", filename);
1337 gtk_accel_map_load (filename);
1344 main_window_accels_save (void)
1347 gchar *file_with_path;
1349 dir = g_build_filename (g_get_user_config_dir (), PACKAGE_NAME, NULL);
1350 g_mkdir_with_parents (dir, S_IRUSR | S_IWUSR | S_IXUSR);
1351 file_with_path = g_build_filename (dir, ACCELS_FILENAME, NULL);
1354 DEBUG ("Saving to:'%s'", file_with_path);
1355 gtk_accel_map_save (file_with_path);
1357 g_free (file_with_path);
1361 empathy_main_window_finalize (GObject *window)
1363 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1364 GHashTableIter iter;
1365 gpointer key, value;
1367 /* Save user-defined accelerators. */
1368 main_window_accels_save ();
1370 g_list_free (priv->actions_connected);
1372 g_object_unref (priv->account_manager);
1373 g_object_unref (priv->individual_store);
1374 g_object_unref (priv->contact_manager);
1375 g_object_unref (priv->sound_mgr);
1376 g_hash_table_unref (priv->errors);
1377 g_hash_table_unref (priv->auths);
1379 /* disconnect all handlers of status-changed signal */
1380 g_hash_table_iter_init (&iter, priv->status_changed_handlers);
1381 while (g_hash_table_iter_next (&iter, &key, &value))
1382 g_signal_handler_disconnect (TP_ACCOUNT (key),
1383 GPOINTER_TO_UINT (value));
1385 g_hash_table_unref (priv->status_changed_handlers);
1387 g_signal_handlers_disconnect_by_func (priv->event_manager,
1388 main_window_event_added_cb,
1390 g_signal_handlers_disconnect_by_func (priv->event_manager,
1391 main_window_event_removed_cb,
1393 g_object_unref (priv->call_observer);
1394 g_object_unref (priv->event_manager);
1395 g_object_unref (priv->ui_manager);
1396 g_object_unref (priv->chatroom_manager);
1398 g_object_unref (priv->gsettings_ui);
1399 g_object_unref (priv->gsettings_contacts);
1401 G_OBJECT_CLASS (empathy_main_window_parent_class)->finalize (window);
1405 main_window_key_press_event_cb (GtkWidget *window,
1409 if (event->keyval == GDK_KEY_T
1410 && event->state & GDK_SHIFT_MASK
1411 && event->state & GDK_CONTROL_MASK) {
1412 empathy_chat_manager_call_undo_closed_chat ();
1418 main_window_chat_quit_cb (GtkAction *action,
1419 EmpathyMainWindow *window)
1421 gtk_widget_destroy (GTK_WIDGET (window));
1425 main_window_view_history_cb (GtkAction *action,
1426 EmpathyMainWindow *window)
1428 empathy_log_window_show (NULL, NULL, FALSE, GTK_WINDOW (window));
1432 main_window_chat_new_message_cb (GtkAction *action,
1433 EmpathyMainWindow *window)
1435 empathy_new_message_dialog_show (GTK_WINDOW (window));
1439 main_window_chat_new_call_cb (GtkAction *action,
1440 EmpathyMainWindow *window)
1442 empathy_new_call_dialog_show (GTK_WINDOW (window));
1446 main_window_chat_add_contact_cb (GtkAction *action,
1447 EmpathyMainWindow *window)
1449 empathy_new_individual_dialog_show (GTK_WINDOW (window));
1453 main_window_chat_search_contacts_cb (GtkAction *action,
1454 EmpathyMainWindow *window)
1456 GtkWidget *dialog = empathy_contact_search_dialog_new (
1457 GTK_WINDOW (window));
1458 gtk_widget_show (dialog);
1462 main_window_view_show_ft_manager (GtkAction *action,
1463 EmpathyMainWindow *window)
1465 empathy_ft_manager_show ();
1469 main_window_view_show_offline_cb (GtkToggleAction *action,
1470 EmpathyMainWindow *window)
1472 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1475 current = gtk_toggle_action_get_active (action);
1476 g_settings_set_boolean (priv->gsettings_ui,
1477 EMPATHY_PREFS_UI_SHOW_OFFLINE,
1480 empathy_individual_view_set_show_offline (priv->individual_view,
1485 main_window_notify_sort_contact_cb (GSettings *gsettings,
1487 EmpathyMainWindow *window)
1489 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1492 str = g_settings_get_string (gsettings, key);
1496 GEnumClass *enum_class;
1497 GEnumValue *enum_value;
1499 type = empathy_individual_store_sort_get_type ();
1500 enum_class = G_ENUM_CLASS (g_type_class_peek (type));
1501 enum_value = g_enum_get_value_by_nick (enum_class, str);
1503 /* By changing the value of the GtkRadioAction,
1504 it emits a signal that calls main_window_view_sort_contacts_cb
1505 which updates the contacts list */
1506 gtk_radio_action_set_current_value (priv->sort_by_name,
1509 g_warning ("Wrong value for sort_criterium configuration : %s", str);
1516 main_window_view_sort_contacts_cb (GtkRadioAction *action,
1517 GtkRadioAction *current,
1518 EmpathyMainWindow *window)
1520 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1521 EmpathyIndividualStoreSort value;
1524 GEnumClass *enum_class;
1525 GEnumValue *enum_value;
1527 value = gtk_radio_action_get_current_value (action);
1528 group = gtk_radio_action_get_group (action);
1530 /* Get string from index */
1531 type = empathy_individual_store_sort_get_type ();
1532 enum_class = G_ENUM_CLASS (g_type_class_peek (type));
1533 enum_value = g_enum_get_value (enum_class, g_slist_index (group, current));
1536 g_warning ("No GEnumValue for EmpathyContactListSort with GtkRadioAction index:%d",
1537 g_slist_index (group, action));
1539 g_settings_set_string (priv->gsettings_contacts,
1540 EMPATHY_PREFS_CONTACTS_SORT_CRITERIUM,
1541 enum_value->value_nick);
1543 empathy_individual_store_set_sort_criterium (priv->individual_store,
1548 main_window_view_show_protocols_cb (GtkToggleAction *action,
1549 EmpathyMainWindow *window)
1551 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1554 value = gtk_toggle_action_get_active (action);
1556 g_settings_set_boolean (priv->gsettings_ui,
1557 EMPATHY_PREFS_UI_SHOW_PROTOCOLS,
1559 empathy_individual_store_set_show_protocols (priv->individual_store,
1563 /* Matches GtkRadioAction values set in empathy-main-window.ui */
1564 #define CONTACT_LIST_NORMAL_SIZE_WITH_AVATARS 0
1565 #define CONTACT_LIST_NORMAL_SIZE 1
1566 #define CONTACT_LIST_COMPACT_SIZE 2
1569 main_window_view_contacts_list_size_cb (GtkRadioAction *action,
1570 GtkRadioAction *current,
1571 EmpathyMainWindow *window)
1573 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1574 GSettings *gsettings_ui;
1577 value = gtk_radio_action_get_current_value (action);
1578 /* create a new GSettings, so we can delay the setting until both
1580 gsettings_ui = g_settings_new (EMPATHY_PREFS_UI_SCHEMA);
1582 DEBUG ("radio button toggled, value = %i", value);
1584 g_settings_delay (gsettings_ui);
1585 g_settings_set_boolean (gsettings_ui,
1586 EMPATHY_PREFS_UI_SHOW_AVATARS,
1587 value == CONTACT_LIST_NORMAL_SIZE_WITH_AVATARS);
1589 g_settings_set_boolean (gsettings_ui,
1590 EMPATHY_PREFS_UI_COMPACT_CONTACT_LIST,
1591 value == CONTACT_LIST_COMPACT_SIZE);
1592 g_settings_apply (gsettings_ui);
1594 /* FIXME: these enums probably have the wrong namespace */
1595 empathy_individual_store_set_show_avatars (priv->individual_store,
1596 value == CONTACT_LIST_NORMAL_SIZE_WITH_AVATARS);
1597 empathy_individual_store_set_is_compact (priv->individual_store,
1598 value == CONTACT_LIST_COMPACT_SIZE);
1600 g_object_unref (gsettings_ui);
1603 static void main_window_notify_show_protocols_cb (GSettings *gsettings,
1605 EmpathyMainWindow *window)
1607 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1609 gtk_toggle_action_set_active (priv->show_protocols,
1610 g_settings_get_boolean (gsettings,
1611 EMPATHY_PREFS_UI_SHOW_PROTOCOLS));
1616 main_window_notify_contact_list_size_cb (GSettings *gsettings,
1618 EmpathyMainWindow *window)
1620 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1623 if (g_settings_get_boolean (gsettings,
1624 EMPATHY_PREFS_UI_COMPACT_CONTACT_LIST)) {
1625 value = CONTACT_LIST_COMPACT_SIZE;
1626 } else if (g_settings_get_boolean (gsettings,
1627 EMPATHY_PREFS_UI_SHOW_AVATARS)) {
1628 value = CONTACT_LIST_NORMAL_SIZE_WITH_AVATARS;
1630 value = CONTACT_LIST_NORMAL_SIZE;
1633 DEBUG ("setting changed, value = %i", value);
1635 /* By changing the value of the GtkRadioAction,
1636 it emits a signal that calls main_window_view_contacts_list_size_cb
1637 which updates the contacts list */
1638 gtk_radio_action_set_current_value (priv->normal_with_avatars, value);
1642 main_window_edit_search_contacts_cb (GtkCheckMenuItem *item,
1643 EmpathyMainWindow *window)
1645 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1647 empathy_individual_view_start_search (priv->individual_view);
1651 main_window_view_show_map_cb (GtkCheckMenuItem *item,
1652 EmpathyMainWindow *window)
1654 #ifdef HAVE_LIBCHAMPLAIN
1655 empathy_map_view_show ();
1660 join_chatroom (EmpathyChatroom *chatroom,
1666 account = empathy_chatroom_get_account (chatroom);
1667 room = empathy_chatroom_get_room (chatroom);
1669 DEBUG ("Requesting channel for '%s'", room);
1670 empathy_join_muc (account, room, timestamp);
1676 EmpathyChatroom *chatroom;
1680 } join_fav_account_sig_ctx;
1682 static join_fav_account_sig_ctx *
1683 join_fav_account_sig_ctx_new (TpAccount *account,
1684 EmpathyChatroom *chatroom,
1687 join_fav_account_sig_ctx *ctx = g_slice_new0 (
1688 join_fav_account_sig_ctx);
1690 ctx->account = g_object_ref (account);
1691 ctx->chatroom = g_object_ref (chatroom);
1692 ctx->timestamp = timestamp;
1697 join_fav_account_sig_ctx_free (join_fav_account_sig_ctx *ctx)
1699 g_object_unref (ctx->account);
1700 g_object_unref (ctx->chatroom);
1701 g_slice_free (join_fav_account_sig_ctx, ctx);
1705 account_status_changed_cb (TpAccount *account,
1706 TpConnectionStatus old_status,
1707 TpConnectionStatus new_status,
1709 gchar *dbus_error_name,
1710 GHashTable *details,
1713 join_fav_account_sig_ctx *ctx = user_data;
1715 switch (new_status) {
1716 case TP_CONNECTION_STATUS_DISCONNECTED:
1717 /* Don't wait any longer */
1721 case TP_CONNECTION_STATUS_CONNECTING:
1725 case TP_CONNECTION_STATUS_CONNECTED:
1726 /* We can join the room */
1730 g_assert_not_reached ();
1733 join_chatroom (ctx->chatroom, ctx->timestamp);
1736 g_source_remove (ctx->timeout);
1737 g_signal_handler_disconnect (account, ctx->sig_id);
1740 #define JOIN_FAVORITE_TIMEOUT 5
1743 join_favorite_timeout_cb (gpointer data)
1745 join_fav_account_sig_ctx *ctx = data;
1747 /* stop waiting for joining the favorite room */
1748 g_signal_handler_disconnect (ctx->account, ctx->sig_id);
1753 main_window_favorite_chatroom_join (EmpathyChatroom *chatroom)
1757 account = empathy_chatroom_get_account (chatroom);
1758 if (tp_account_get_connection_status (account, NULL) !=
1759 TP_CONNECTION_STATUS_CONNECTED) {
1760 join_fav_account_sig_ctx *ctx;
1762 ctx = join_fav_account_sig_ctx_new (account, chatroom,
1763 empathy_get_current_action_time ());
1765 ctx->sig_id = g_signal_connect_data (account, "status-changed",
1766 G_CALLBACK (account_status_changed_cb), ctx,
1767 (GClosureNotify) join_fav_account_sig_ctx_free, 0);
1769 ctx->timeout = g_timeout_add_seconds (JOIN_FAVORITE_TIMEOUT,
1770 join_favorite_timeout_cb, ctx);
1774 join_chatroom (chatroom, empathy_get_current_action_time ());
1778 main_window_favorite_chatroom_menu_activate_cb (GtkMenuItem *menu_item,
1779 EmpathyChatroom *chatroom)
1781 main_window_favorite_chatroom_join (chatroom);
1785 main_window_favorite_chatroom_menu_add (EmpathyMainWindow *window,
1786 EmpathyChatroom *chatroom)
1788 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1789 GtkWidget *menu_item;
1790 const gchar *name, *account_name;
1794 if (g_object_get_data (G_OBJECT (chatroom), "menu_item")) {
1798 name = empathy_chatroom_get_name (chatroom);
1799 account_name = tp_account_get_display_name (
1800 empathy_chatroom_get_account (chatroom));
1801 label = g_strdup_printf ("%s (%s)", name, account_name);
1802 menu_item = gtk_menu_item_new_with_label (label);
1804 g_object_set_data (G_OBJECT (menu_item), "is_favorite",
1805 GUINT_TO_POINTER (TRUE));
1807 g_object_set_data (G_OBJECT (chatroom), "menu_item", menu_item);
1808 g_signal_connect (menu_item, "activate",
1809 G_CALLBACK (main_window_favorite_chatroom_menu_activate_cb),
1812 gtk_menu_shell_insert (GTK_MENU_SHELL (priv->room_menu),
1815 gtk_widget_show (menu_item);
1819 main_window_favorite_chatroom_menu_added_cb (EmpathyChatroomManager *manager,
1820 EmpathyChatroom *chatroom,
1821 EmpathyMainWindow *window)
1823 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1825 main_window_favorite_chatroom_menu_add (window, chatroom);
1826 gtk_widget_show (priv->room_separator);
1827 gtk_action_set_sensitive (priv->room_join_favorites, TRUE);
1831 main_window_favorite_chatroom_menu_removed_cb (EmpathyChatroomManager *manager,
1832 EmpathyChatroom *chatroom,
1833 EmpathyMainWindow *window)
1835 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1836 GtkWidget *menu_item;
1839 menu_item = g_object_get_data (G_OBJECT (chatroom), "menu_item");
1840 g_object_set_data (G_OBJECT (chatroom), "menu_item", NULL);
1841 gtk_widget_destroy (menu_item);
1843 chatrooms = empathy_chatroom_manager_get_chatrooms (priv->chatroom_manager, NULL);
1845 gtk_widget_show (priv->room_separator);
1847 gtk_widget_hide (priv->room_separator);
1850 gtk_action_set_sensitive (priv->room_join_favorites, chatrooms != NULL);
1851 g_list_free (chatrooms);
1855 main_window_favorite_chatroom_menu_setup (EmpathyMainWindow *window)
1857 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1858 GList *chatrooms, *l;
1861 priv->chatroom_manager = empathy_chatroom_manager_dup_singleton (NULL);
1862 chatrooms = empathy_chatroom_manager_get_chatrooms (
1863 priv->chatroom_manager, NULL);
1864 room = gtk_ui_manager_get_widget (priv->ui_manager,
1866 priv->room_menu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (room));
1867 priv->room_separator = gtk_ui_manager_get_widget (priv->ui_manager,
1868 "/menubar/room/room_separator");
1870 for (l = chatrooms; l; l = l->next) {
1871 main_window_favorite_chatroom_menu_add (window, l->data);
1875 gtk_widget_hide (priv->room_separator);
1878 gtk_action_set_sensitive (priv->room_join_favorites, chatrooms != NULL);
1880 g_signal_connect (priv->chatroom_manager, "chatroom-added",
1881 G_CALLBACK (main_window_favorite_chatroom_menu_added_cb),
1883 g_signal_connect (priv->chatroom_manager, "chatroom-removed",
1884 G_CALLBACK (main_window_favorite_chatroom_menu_removed_cb),
1887 g_list_free (chatrooms);
1891 main_window_room_join_new_cb (GtkAction *action,
1892 EmpathyMainWindow *window)
1894 empathy_new_chatroom_dialog_show (GTK_WINDOW (window));
1898 main_window_room_join_favorites_cb (GtkAction *action,
1899 EmpathyMainWindow *window)
1901 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1902 GList *chatrooms, *l;
1904 chatrooms = empathy_chatroom_manager_get_chatrooms (priv->chatroom_manager, NULL);
1905 for (l = chatrooms; l; l = l->next) {
1906 main_window_favorite_chatroom_join (l->data);
1908 g_list_free (chatrooms);
1912 main_window_room_manage_favorites_cb (GtkAction *action,
1913 EmpathyMainWindow *window)
1915 empathy_chatrooms_window_show (GTK_WINDOW (window));
1919 main_window_edit_cb (GtkAction *action,
1920 EmpathyMainWindow *window)
1922 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1925 /* FIXME: It should use the UIManager to merge the contact/group submenu */
1926 submenu = empathy_individual_view_get_individual_menu (
1927 priv->individual_view);
1932 item = GTK_MENU_ITEM (priv->edit_context);
1933 label = gtk_bin_get_child (GTK_BIN (item));
1934 gtk_label_set_text (GTK_LABEL (label), _("Contact"));
1936 gtk_widget_show (priv->edit_context);
1937 gtk_widget_show (priv->edit_context_separator);
1939 gtk_menu_item_set_submenu (item, submenu);
1944 submenu = empathy_individual_view_get_group_menu (
1945 priv->individual_view);
1950 item = GTK_MENU_ITEM (priv->edit_context);
1951 label = gtk_bin_get_child (GTK_BIN (item));
1952 gtk_label_set_text (GTK_LABEL (label), _("Group"));
1954 gtk_widget_show (priv->edit_context);
1955 gtk_widget_show (priv->edit_context_separator);
1957 gtk_menu_item_set_submenu (item, submenu);
1962 gtk_widget_hide (priv->edit_context);
1963 gtk_widget_hide (priv->edit_context_separator);
1969 main_window_edit_accounts_cb (GtkAction *action,
1970 EmpathyMainWindow *window)
1972 empathy_accounts_dialog_show_application (gdk_screen_get_default (),
1973 NULL, FALSE, FALSE);
1977 main_window_edit_personal_information_cb (GtkAction *action,
1978 EmpathyMainWindow *window)
1980 empathy_contact_personal_dialog_show (GTK_WINDOW (window));
1984 main_window_edit_blocked_contacts_cb (GtkAction *action,
1985 EmpathyMainWindow *window)
1989 dialog = empathy_contact_blocking_dialog_new (GTK_WINDOW (window));
1990 gtk_widget_show (dialog);
1991 g_signal_connect (dialog, "response",
1992 G_CALLBACK (gtk_widget_destroy), NULL);
1996 empathy_main_window_show_preferences (EmpathyMainWindow *window,
1999 EmpathyMainWindowPriv *priv = GET_PRIV (window);
2001 if (priv->preferences == NULL) {
2002 priv->preferences = empathy_preferences_new (GTK_WINDOW (window),
2003 priv->shell_running);
2004 g_object_add_weak_pointer (G_OBJECT (priv->preferences),
2005 (gpointer) &priv->preferences);
2007 gtk_widget_show (priv->preferences);
2009 gtk_window_present (GTK_WINDOW (priv->preferences));
2013 empathy_preferences_show_tab (
2014 EMPATHY_PREFERENCES (priv->preferences), tab);
2018 main_window_edit_preferences_cb (GtkAction *action,
2019 EmpathyMainWindow *window)
2021 empathy_main_window_show_preferences (window, NULL);
2025 main_window_help_about_cb (GtkAction *action,
2026 EmpathyMainWindow *window)
2028 empathy_about_dialog_new (GTK_WINDOW (window));
2032 main_window_help_debug_cb (GtkAction *action,
2033 EmpathyMainWindow *window)
2035 empathy_launch_program (BIN_DIR, "empathy-debugger", NULL);
2039 main_window_help_contents_cb (GtkAction *action,
2040 EmpathyMainWindow *window)
2042 empathy_url_show (GTK_WIDGET (window), "ghelp:empathy");
2046 main_window_throbber_button_press_event_cb (GtkWidget *throbber,
2047 GdkEventButton *event,
2048 EmpathyMainWindow *window)
2050 if (event->type != GDK_BUTTON_PRESS ||
2051 event->button != 1) {
2055 empathy_accounts_dialog_show_application (
2056 gtk_widget_get_screen (GTK_WIDGET (throbber)),
2057 NULL, FALSE, FALSE);
2063 main_window_account_removed_cb (TpAccountManager *manager,
2065 EmpathyMainWindow *window)
2067 EmpathyMainWindowPriv *priv = GET_PRIV (window);
2070 a = tp_account_manager_get_valid_accounts (manager);
2072 gtk_action_set_sensitive (priv->view_history,
2073 g_list_length (a) > 0);
2077 /* remove errors if any */
2078 main_window_remove_error (window, account);
2080 /* remove the balance action if required */
2081 main_window_remove_balance_action (window, account);
2085 main_window_account_validity_changed_cb (TpAccountManager *manager,
2088 EmpathyMainWindow *window)
2090 EmpathyMainWindowPriv *priv = GET_PRIV (window);
2094 handler_id = GPOINTER_TO_UINT (g_hash_table_lookup (
2095 priv->status_changed_handlers, account));
2097 /* connect signal only if it was not connected yet */
2098 if (handler_id == 0) {
2099 handler_id = g_signal_connect (account,
2101 G_CALLBACK (main_window_connection_changed_cb),
2103 g_hash_table_insert (priv->status_changed_handlers,
2104 account, GUINT_TO_POINTER (handler_id));
2108 main_window_account_removed_cb (manager, account, window);
2112 main_window_notify_show_offline_cb (GSettings *gsettings,
2114 gpointer toggle_action)
2116 gtk_toggle_action_set_active (toggle_action,
2117 g_settings_get_boolean (gsettings, key));
2121 main_window_connection_items_setup (EmpathyMainWindow *window,
2124 EmpathyMainWindowPriv *priv = GET_PRIV (window);
2128 const gchar *actions_connected[] = {
2130 "room_join_favorites",
2133 "chat_search_contacts",
2135 "edit_personal_information",
2136 "edit_blocked_contacts",
2137 "edit_search_contacts"
2140 for (i = 0, list = NULL; i < G_N_ELEMENTS (actions_connected); i++) {
2141 action = gtk_builder_get_object (gui, actions_connected[i]);
2142 list = g_list_prepend (list, action);
2145 priv->actions_connected = list;
2149 account_manager_prepared_cb (GObject *source_object,
2150 GAsyncResult *result,
2153 GList *accounts, *j;
2154 TpAccountManager *manager = TP_ACCOUNT_MANAGER (source_object);
2155 EmpathyMainWindow *window = user_data;
2156 EmpathyMainWindowPriv *priv = GET_PRIV (window);
2157 GError *error = NULL;
2159 if (!tp_proxy_prepare_finish (manager, result, &error)) {
2160 DEBUG ("Failed to prepare account manager: %s", error->message);
2161 g_error_free (error);
2165 accounts = tp_account_manager_get_valid_accounts (priv->account_manager);
2166 for (j = accounts; j != NULL; j = j->next) {
2167 TpAccount *account = TP_ACCOUNT (j->data);
2170 handler_id = g_signal_connect (account, "status-changed",
2171 G_CALLBACK (main_window_connection_changed_cb),
2173 g_hash_table_insert (priv->status_changed_handlers,
2174 account, GUINT_TO_POINTER (handler_id));
2176 main_window_setup_balance (window, account);
2179 g_signal_connect (manager, "account-validity-changed",
2180 G_CALLBACK (main_window_account_validity_changed_cb),
2183 main_window_update_status (window);
2185 /* Disable the "Previous Conversations" menu entry if there is no account */
2186 gtk_action_set_sensitive (priv->view_history,
2187 g_list_length (accounts) > 0);
2189 g_list_free (accounts);
2193 empathy_main_window_set_shell_running (EmpathyMainWindow *window,
2194 gboolean shell_running)
2196 EmpathyMainWindowPriv *priv = GET_PRIV (window);
2198 if (priv->shell_running == shell_running)
2201 priv->shell_running = shell_running;
2202 g_object_notify (G_OBJECT (window), "shell-running");
2206 empathy_main_window_constructor (GType type,
2207 guint n_construct_params,
2208 GObjectConstructParam *construct_params)
2210 static GObject *window = NULL;
2213 return g_object_ref (window);
2215 window = G_OBJECT_CLASS (empathy_main_window_parent_class)->constructor (
2216 type, n_construct_params, construct_params);
2218 g_object_add_weak_pointer (window, (gpointer) &window);
2224 empathy_main_window_set_property (GObject *object,
2226 const GValue *value,
2229 EmpathyMainWindow *self = EMPATHY_MAIN_WINDOW (object);
2230 EmpathyMainWindowPriv *priv = GET_PRIV (self);
2232 switch (property_id)
2234 case PROP_SHELL_RUNNING:
2235 priv->shell_running = g_value_get_boolean (value);
2238 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2244 empathy_main_window_get_property (GObject *object,
2249 EmpathyMainWindow *self = EMPATHY_MAIN_WINDOW (object);
2250 EmpathyMainWindowPriv *priv = GET_PRIV (self);
2252 switch (property_id)
2254 case PROP_SHELL_RUNNING:
2255 g_value_set_boolean (value, priv->shell_running);
2258 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2264 empathy_main_window_class_init (EmpathyMainWindowClass *klass)
2266 GObjectClass *object_class = G_OBJECT_CLASS (klass);
2269 object_class->finalize = empathy_main_window_finalize;
2270 object_class->constructor = empathy_main_window_constructor;
2272 object_class->set_property = empathy_main_window_set_property;
2273 object_class->get_property = empathy_main_window_get_property;
2275 pspec = g_param_spec_boolean ("shell-running",
2277 "Whether the Shell is running or not",
2279 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
2280 g_object_class_install_property (object_class, PROP_SHELL_RUNNING, pspec);
2282 g_type_class_add_private (object_class, sizeof (EmpathyMainWindowPriv));
2286 empathy_main_window_init (EmpathyMainWindow *window)
2288 EmpathyMainWindowPriv *priv;
2289 EmpathyIndividualManager *individual_manager;
2290 GtkBuilder *gui, *gui_mgr;
2292 GtkToggleAction *show_offline_widget;
2293 GtkAction *show_map_widget;
2295 gboolean show_offline;
2297 GtkTreeModel *model;
2298 GtkWidget *search_vbox;
2301 priv = window->priv = G_TYPE_INSTANCE_GET_PRIVATE (window,
2302 EMPATHY_TYPE_MAIN_WINDOW, EmpathyMainWindowPriv);
2304 priv->gsettings_ui = g_settings_new (EMPATHY_PREFS_UI_SCHEMA);
2305 priv->gsettings_contacts = g_settings_new (EMPATHY_PREFS_CONTACTS_SCHEMA);
2307 priv->sound_mgr = empathy_sound_manager_dup_singleton ();
2309 gtk_window_set_title (GTK_WINDOW (window), _("Contact List"));
2310 gtk_window_set_role (GTK_WINDOW (window), "contact_list");
2311 gtk_window_set_default_size (GTK_WINDOW (window), 225, 325);
2313 /* don't finalize the widget on delete-event, just hide it */
2314 g_signal_connect (window, "delete-event",
2315 G_CALLBACK (gtk_widget_hide_on_delete), NULL);
2317 /* Set up interface */
2318 filename = empathy_file_lookup ("empathy-main-window.ui", "src");
2319 gui = empathy_builder_get_file (filename,
2320 "main_vbox", &priv->main_vbox,
2321 "balance_vbox", &priv->balance_vbox,
2322 "errors_vbox", &priv->errors_vbox,
2323 "auth_vbox", &priv->auth_vbox,
2324 "search_vbox", &search_vbox,
2325 "presence_toolbar", &priv->presence_toolbar,
2326 "notebook", &priv->notebook,
2327 "no_entry_label", &priv->no_entry_label,
2328 "roster_scrolledwindow", &sw,
2332 /* Set UI manager */
2333 filename = empathy_file_lookup ("empathy-main-window-menubar.ui", "src");
2334 gui_mgr = empathy_builder_get_file (filename,
2335 "ui_manager", &priv->ui_manager,
2336 "view_show_offline", &show_offline_widget,
2337 "view_show_protocols", &priv->show_protocols,
2338 "view_sort_by_name", &priv->sort_by_name,
2339 "view_sort_by_status", &priv->sort_by_status,
2340 "view_normal_size_with_avatars", &priv->normal_with_avatars,
2341 "view_normal_size", &priv->normal_size,
2342 "view_compact_size", &priv->compact_size,
2343 "view_history", &priv->view_history,
2344 "view_show_map", &show_map_widget,
2345 "room_join_favorites", &priv->room_join_favorites,
2346 "view_balance_show_in_roster", &priv->view_balance_show_in_roster,
2347 "menubar", &menubar,
2351 /* The UI manager is living in its own .ui file as Glade doesn't support
2352 * those. The GtkMenubar has to be in this file as well to we manually add
2353 * it to the first position of the vbox. */
2354 gtk_box_pack_start (GTK_BOX (priv->main_vbox), menubar, FALSE, FALSE, 0);
2355 gtk_box_reorder_child (GTK_BOX (priv->main_vbox), menubar, 0);
2357 gtk_container_add (GTK_CONTAINER (window), priv->main_vbox);
2358 gtk_widget_show (priv->main_vbox);
2360 g_signal_connect (window, "key-press-event",
2361 G_CALLBACK (main_window_key_press_event_cb), NULL);
2363 empathy_builder_connect (gui_mgr, window,
2364 "chat_quit", "activate", main_window_chat_quit_cb,
2365 "chat_new_message", "activate", main_window_chat_new_message_cb,
2366 "chat_new_call", "activate", main_window_chat_new_call_cb,
2367 "view_history", "activate", main_window_view_history_cb,
2368 "room_join_new", "activate", main_window_room_join_new_cb,
2369 "room_join_favorites", "activate", main_window_room_join_favorites_cb,
2370 "room_manage_favorites", "activate", main_window_room_manage_favorites_cb,
2371 "chat_add_contact", "activate", main_window_chat_add_contact_cb,
2372 "chat_search_contacts", "activate", main_window_chat_search_contacts_cb,
2373 "view_show_ft_manager", "activate", main_window_view_show_ft_manager,
2374 "view_show_offline", "toggled", main_window_view_show_offline_cb,
2375 "view_show_protocols", "toggled", main_window_view_show_protocols_cb,
2376 "view_sort_by_name", "changed", main_window_view_sort_contacts_cb,
2377 "view_normal_size_with_avatars", "changed", main_window_view_contacts_list_size_cb,
2378 "view_show_map", "activate", main_window_view_show_map_cb,
2379 "edit", "activate", main_window_edit_cb,
2380 "edit_accounts", "activate", main_window_edit_accounts_cb,
2381 "edit_personal_information", "activate", main_window_edit_personal_information_cb,
2382 "edit_blocked_contacts", "activate", main_window_edit_blocked_contacts_cb,
2383 "edit_preferences", "activate", main_window_edit_preferences_cb,
2384 "edit_search_contacts", "activate", main_window_edit_search_contacts_cb,
2385 "help_about", "activate", main_window_help_about_cb,
2386 "help_debug", "activate", main_window_help_debug_cb,
2387 "help_contents", "activate", main_window_help_contents_cb,
2390 /* Set up connection related widgets. */
2391 main_window_connection_items_setup (window, gui_mgr);
2393 g_object_ref (priv->ui_manager);
2394 g_object_unref (gui);
2395 g_object_unref (gui_mgr);
2397 #ifndef HAVE_LIBCHAMPLAIN
2398 gtk_action_set_visible (show_map_widget, FALSE);
2401 priv->account_manager = tp_account_manager_dup ();
2403 tp_proxy_prepare_async (priv->account_manager, NULL,
2404 account_manager_prepared_cb, window);
2406 priv->errors = g_hash_table_new_full (g_direct_hash,
2411 priv->auths = g_hash_table_new (NULL, NULL);
2413 priv->status_changed_handlers = g_hash_table_new_full (g_direct_hash,
2419 main_window_favorite_chatroom_menu_setup (window);
2421 priv->edit_context = gtk_ui_manager_get_widget (priv->ui_manager,
2422 "/menubar/edit/edit_context");
2423 priv->edit_context_separator = gtk_ui_manager_get_widget (
2425 "/menubar/edit/edit_context_separator");
2426 gtk_widget_hide (priv->edit_context);
2427 gtk_widget_hide (priv->edit_context_separator);
2429 /* Set up contact list. */
2430 empathy_status_presets_get_all ();
2432 /* Set up presence chooser */
2433 priv->presence_chooser = empathy_presence_chooser_new ();
2434 gtk_widget_show (priv->presence_chooser);
2435 item = gtk_tool_item_new ();
2436 gtk_widget_show (GTK_WIDGET (item));
2437 gtk_widget_set_size_request (priv->presence_chooser, 10, -1);
2438 gtk_container_add (GTK_CONTAINER (item), priv->presence_chooser);
2439 gtk_tool_item_set_is_important (item, TRUE);
2440 gtk_tool_item_set_expand (item, TRUE);
2441 gtk_toolbar_insert (GTK_TOOLBAR (priv->presence_toolbar), item, -1);
2443 /* Set up the throbber */
2444 priv->throbber = gtk_spinner_new ();
2445 gtk_widget_set_size_request (priv->throbber, 16, -1);
2446 gtk_widget_set_events (priv->throbber, GDK_BUTTON_PRESS_MASK);
2447 g_signal_connect (priv->throbber, "button-press-event",
2448 G_CALLBACK (main_window_throbber_button_press_event_cb),
2450 gtk_widget_show (priv->throbber);
2452 item = gtk_tool_item_new ();
2453 gtk_container_set_border_width (GTK_CONTAINER (item), 6);
2454 gtk_toolbar_insert (GTK_TOOLBAR (priv->presence_toolbar), item, -1);
2455 gtk_container_add (GTK_CONTAINER (item), priv->throbber);
2456 priv->throbber_tool_item = GTK_WIDGET (item);
2458 /* XXX: this class is designed to live for the duration of the program,
2459 * so it's got a race condition between its signal handlers and its
2460 * finalization. The class is planned to be removed, so we won't fix
2461 * this before then. */
2462 priv->contact_manager = EMPATHY_CONTACT_LIST (
2463 empathy_contact_manager_dup_singleton ());
2464 individual_manager = empathy_individual_manager_dup_singleton ();
2465 priv->individual_store = EMPATHY_INDIVIDUAL_STORE (
2466 empathy_individual_store_manager_new (individual_manager));
2467 g_object_unref (individual_manager);
2469 /* For the moment, we disallow Persona drops onto the main contact list (e.g. from things such as
2470 * the EmpathyPersonaView in the linking dialogue). No code is hooked up to do anything on a Persona
2471 * drop, so allowing them would achieve nothing except confusion. */
2472 priv->individual_view = empathy_individual_view_new (
2473 priv->individual_store,
2474 EMPATHY_INDIVIDUAL_VIEW_FEATURE_ALL ^ EMPATHY_INDIVIDUAL_VIEW_FEATURE_PERSONA_DROP,
2475 EMPATHY_INDIVIDUAL_FEATURE_ALL ^ EMPATHY_INDIVIDUAL_FEATURE_ADD_CONTACT);
2477 gtk_widget_show (GTK_WIDGET (priv->individual_view));
2478 gtk_container_add (GTK_CONTAINER (sw),
2479 GTK_WIDGET (priv->individual_view));
2480 g_signal_connect (priv->individual_view, "row-activated",
2481 G_CALLBACK (main_window_row_activated_cb),
2484 /* Set up search bar */
2485 priv->search_bar = empathy_live_search_new (
2486 GTK_WIDGET (priv->individual_view));
2487 empathy_individual_view_set_live_search (priv->individual_view,
2488 EMPATHY_LIVE_SEARCH (priv->search_bar));
2489 gtk_box_pack_start (GTK_BOX (search_vbox), priv->search_bar,
2492 g_signal_connect_swapped (window, "map",
2493 G_CALLBACK (gtk_widget_grab_focus), priv->individual_view);
2495 /* Connect to proper signals to check if contact list is empty or not */
2496 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->individual_view));
2498 g_signal_connect (model, "row-inserted",
2499 G_CALLBACK (main_window_row_inserted_cb),
2501 g_signal_connect (model, "row-deleted",
2502 G_CALLBACK (main_window_row_deleted_cb),
2505 /* Load user-defined accelerators. */
2506 main_window_accels_load ();
2508 /* Set window size. */
2509 empathy_geometry_bind (GTK_WINDOW (window), GEOMETRY_NAME);
2511 /* bind view_balance_show_in_roster */
2512 g_settings_bind (priv->gsettings_ui, "show-balance-in-roster",
2513 priv->view_balance_show_in_roster, "active",
2514 G_SETTINGS_BIND_DEFAULT);
2515 g_object_bind_property (priv->view_balance_show_in_roster, "active",
2516 priv->balance_vbox, "visible",
2517 G_BINDING_SYNC_CREATE);
2519 /* Enable event handling */
2520 priv->call_observer = empathy_call_observer_dup_singleton ();
2521 priv->event_manager = empathy_event_manager_dup_singleton ();
2523 g_signal_connect (priv->event_manager, "event-added",
2524 G_CALLBACK (main_window_event_added_cb), window);
2525 g_signal_connect (priv->event_manager, "event-removed",
2526 G_CALLBACK (main_window_event_removed_cb), window);
2527 g_signal_connect (priv->account_manager, "account-validity-changed",
2528 G_CALLBACK (main_window_account_validity_changed_cb),
2530 g_signal_connect (priv->account_manager, "account-removed",
2531 G_CALLBACK (main_window_account_removed_cb),
2533 g_signal_connect (priv->account_manager, "account-disabled",
2534 G_CALLBACK (main_window_account_disabled_cb),
2537 /* Show offline ? */
2538 show_offline = g_settings_get_boolean (priv->gsettings_ui,
2539 EMPATHY_PREFS_UI_SHOW_OFFLINE);
2540 g_signal_connect (priv->gsettings_ui,
2541 "changed::" EMPATHY_PREFS_UI_SHOW_OFFLINE,
2542 G_CALLBACK (main_window_notify_show_offline_cb),
2543 show_offline_widget);
2545 gtk_toggle_action_set_active (show_offline_widget, show_offline);
2547 /* Show protocol ? */
2548 g_signal_connect (priv->gsettings_ui,
2549 "changed::" EMPATHY_PREFS_UI_SHOW_PROTOCOLS,
2550 G_CALLBACK (main_window_notify_show_protocols_cb),
2553 main_window_notify_show_protocols_cb (priv->gsettings_ui,
2554 EMPATHY_PREFS_UI_SHOW_PROTOCOLS,
2557 /* Sort by name / by status ? */
2558 g_signal_connect (priv->gsettings_contacts,
2559 "changed::" EMPATHY_PREFS_CONTACTS_SORT_CRITERIUM,
2560 G_CALLBACK (main_window_notify_sort_contact_cb),
2563 main_window_notify_sort_contact_cb (priv->gsettings_contacts,
2564 EMPATHY_PREFS_CONTACTS_SORT_CRITERIUM,
2567 /* Contacts list size */
2568 g_signal_connect (priv->gsettings_ui,
2569 "changed::" EMPATHY_PREFS_UI_COMPACT_CONTACT_LIST,
2570 G_CALLBACK (main_window_notify_contact_list_size_cb),
2572 g_signal_connect (priv->gsettings_ui,
2573 "changed::" EMPATHY_PREFS_UI_SHOW_AVATARS,
2574 G_CALLBACK (main_window_notify_contact_list_size_cb),
2577 main_window_notify_contact_list_size_cb (priv->gsettings_ui,
2578 EMPATHY_PREFS_UI_SHOW_AVATARS,
2583 empathy_main_window_dup (void)
2585 return g_object_new (EMPATHY_TYPE_MAIN_WINDOW, NULL);