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-idle.h>
38 #include <libempathy/empathy-utils.h>
39 #include <libempathy/empathy-dispatcher.h>
40 #include <libempathy/empathy-chatroom-manager.h>
41 #include <libempathy/empathy-chatroom.h>
42 #include <libempathy/empathy-contact-list.h>
43 #include <libempathy/empathy-contact-manager.h>
44 #include <libempathy/empathy-gsettings.h>
45 #include <libempathy/empathy-individual-manager.h>
46 #include <libempathy/empathy-gsettings.h>
47 #include <libempathy/empathy-status-presets.h>
48 #include <libempathy/empathy-tp-contact-factory.h>
50 #include <libempathy-gtk/empathy-contact-dialogs.h>
51 #include <libempathy-gtk/empathy-contact-list-store.h>
52 #include <libempathy-gtk/empathy-contact-list-view.h>
53 #include <libempathy-gtk/empathy-live-search.h>
54 #include <libempathy-gtk/empathy-geometry.h>
55 #include <libempathy-gtk/empathy-gtk-enum-types.h>
56 #include <libempathy-gtk/empathy-individual-dialogs.h>
57 #include <libempathy-gtk/empathy-individual-store.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.h>
64 #include <libempathy-gtk/empathy-ui-utils.h>
66 #include "empathy-accounts-dialog.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"
77 #include "empathy-migrate-butterfly-logs.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,
99 G_DEFINE_TYPE (EmpathyMainWindow, empathy_main_window, GTK_TYPE_WINDOW);
101 #define GET_PRIV(self) ((EmpathyMainWindowPriv *)((EmpathyMainWindow *) self)->priv)
103 struct _EmpathyMainWindowPriv {
104 EmpathyIndividualStore *individual_store;
105 EmpathyIndividualView *individual_view;
106 TpAccountManager *account_manager;
107 EmpathyChatroomManager *chatroom_manager;
108 EmpathyEventManager *event_manager;
109 guint flash_timeout_id;
113 GSettings *gsettings_ui;
114 GSettings *gsettings_contacts;
116 GtkWidget *preferences;
117 GtkWidget *main_vbox;
119 GtkWidget *throbber_tool_item;
120 GtkWidget *presence_toolbar;
121 GtkWidget *presence_chooser;
122 GtkWidget *errors_vbox;
123 GtkWidget *search_bar;
125 GtkWidget *no_entry_label;
127 GtkToggleAction *show_protocols;
128 GtkRadioAction *sort_by_name;
129 GtkRadioAction *sort_by_status;
130 GtkRadioAction *normal_with_avatars;
131 GtkRadioAction *normal_size;
132 GtkRadioAction *compact_size;
134 GtkUIManager *ui_manager;
135 GtkAction *view_history;
136 GtkAction *room_join_favorites;
137 GtkWidget *room_menu;
138 GtkWidget *room_separator;
139 GtkWidget *edit_context;
140 GtkWidget *edit_context_separator;
142 guint size_timeout_id;
145 /* stores a mapping from TpAccount to Handler ID to prevent
146 * to listen more than once to the status-changed signal */
147 GHashTable *status_changed_handlers;
149 /* Actions that are enabled when there are connected accounts */
150 GList *actions_connected;
152 /* The idle event source to migrate butterfly's logs */
153 guint butterfly_log_migration_members_changed_id;
157 main_window_flash_stop (EmpathyMainWindow *window)
159 EmpathyMainWindowPriv *priv = GET_PRIV (window);
161 if (priv->flash_timeout_id == 0) {
165 DEBUG ("Stop flashing");
166 g_source_remove (priv->flash_timeout_id);
167 priv->flash_timeout_id = 0;
168 priv->flash_on = FALSE;
174 EmpathyMainWindow *window;
178 main_window_flash_foreach (GtkTreeModel *model,
183 FlashForeachData *data = (FlashForeachData *) user_data;
184 FolksIndividual *individual;
185 EmpathyContact *contact;
186 const gchar *icon_name;
187 GtkTreePath *parent_path = NULL;
188 GtkTreeIter parent_iter;
189 GdkPixbuf *pixbuf = NULL;
191 gtk_tree_model_get (model, iter,
192 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL,
196 if (individual == NULL)
199 contact = empathy_contact_dup_from_folks_individual (individual);
200 if (contact != data->event->contact) {
201 tp_clear_object (&contact);
206 icon_name = data->event->icon_name;
207 pixbuf = empathy_pixbuf_from_icon_name (icon_name, GTK_ICON_SIZE_MENU);
209 pixbuf = empathy_individual_store_get_individual_status_icon (
210 GET_PRIV (data->window)->individual_store,
214 gtk_tree_store_set (GTK_TREE_STORE (model), iter,
215 EMPATHY_INDIVIDUAL_STORE_COL_ICON_STATUS, pixbuf,
218 /* To make sure the parent is shown correctly, we emit
219 * the row-changed signal on the parent so it prompts
220 * it to be refreshed by the filter func.
222 if (gtk_tree_model_iter_parent (model, &parent_iter, iter)) {
223 parent_path = gtk_tree_model_get_path (model, &parent_iter);
226 gtk_tree_model_row_changed (model, parent_path, &parent_iter);
227 gtk_tree_path_free (parent_path);
230 g_object_unref (individual);
231 tp_clear_object (&contact);
237 main_window_flash_cb (EmpathyMainWindow *window)
239 EmpathyMainWindowPriv *priv = GET_PRIV (window);
242 gboolean found_event = FALSE;
243 FlashForeachData data;
245 priv->flash_on = !priv->flash_on;
246 data.on = priv->flash_on;
247 model = GTK_TREE_MODEL (priv->individual_store);
249 events = empathy_event_manager_get_events (priv->event_manager);
250 for (l = events; l; l = l->next) {
251 data.event = l->data;
252 data.window = window;
253 if (!data.event->contact || !data.event->must_ack) {
258 gtk_tree_model_foreach (model,
259 main_window_flash_foreach,
264 main_window_flash_stop (window);
271 main_window_flash_start (EmpathyMainWindow *window)
273 EmpathyMainWindowPriv *priv = GET_PRIV (window);
275 if (priv->flash_timeout_id != 0) {
279 DEBUG ("Start flashing");
280 priv->flash_timeout_id = g_timeout_add (FLASH_TIMEOUT,
281 (GSourceFunc) main_window_flash_cb,
283 main_window_flash_cb (window);
287 main_window_event_added_cb (EmpathyEventManager *manager,
289 EmpathyMainWindow *window)
291 if (event->contact) {
292 main_window_flash_start (window);
297 main_window_event_removed_cb (EmpathyEventManager *manager,
299 EmpathyMainWindow *window)
301 EmpathyMainWindowPriv *priv = GET_PRIV (window);
302 FlashForeachData data;
304 if (!event->contact) {
310 data.window = window;
311 gtk_tree_model_foreach (GTK_TREE_MODEL (priv->individual_store),
312 main_window_flash_foreach,
317 main_window_row_activated_cb (EmpathyContactListView *view,
319 GtkTreeViewColumn *col,
320 EmpathyMainWindow *window)
322 EmpathyMainWindowPriv *priv = GET_PRIV (window);
323 EmpathyContact *contact = NULL;
324 FolksIndividual *individual;
329 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->individual_view));
330 gtk_tree_model_get_iter (model, &iter, path);
332 gtk_tree_model_get (model, &iter,
333 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL,
337 if (individual != NULL) {
338 contact = empathy_contact_dup_from_folks_individual (individual);
345 /* If the contact has an event activate it, otherwise the
346 * default handler of row-activated will be called. */
347 events = empathy_event_manager_get_events (priv->event_manager);
348 for (l = events; l; l = l->next) {
349 EmpathyEvent *event = l->data;
351 if (event->contact == contact) {
352 DEBUG ("Activate event");
353 empathy_event_activate (event);
355 /* We don't want the default handler of this signal
356 * (e.g. open a chat) */
357 g_signal_stop_emission_by_name (view, "row-activated");
362 g_object_unref (contact);
364 tp_clear_object (&individual);
368 main_window_row_deleted_cb (GtkTreeModel *model,
370 EmpathyMainWindow *window)
372 EmpathyMainWindowPriv *priv = GET_PRIV (window);
373 GtkTreeIter help_iter;
375 if (!gtk_tree_model_get_iter_first (model, &help_iter)) {
378 if (empathy_individual_view_is_searching (
379 priv->individual_view)) {
382 tmp = g_strdup_printf ("<b><span size='xx-large'>%s</span></b>",
383 _("No match found"));
385 gtk_label_set_markup (GTK_LABEL (priv->no_entry_label), tmp);
388 gtk_label_set_ellipsize (GTK_LABEL (priv->no_entry_label),
389 PANGO_ELLIPSIZE_END);
391 gtk_notebook_set_current_page (
392 GTK_NOTEBOOK (priv->notebook), PAGE_NO_MATCH);
398 main_window_row_inserted_cb (GtkTreeModel *model,
401 EmpathyMainWindow *window)
403 EmpathyMainWindowPriv *priv = GET_PRIV (window);
407 gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook),
409 gtk_widget_grab_focus (GTK_WIDGET (priv->individual_view));
414 main_window_remove_error (EmpathyMainWindow *window,
417 EmpathyMainWindowPriv *priv = GET_PRIV (window);
418 GtkWidget *error_widget;
420 error_widget = g_hash_table_lookup (priv->errors, account);
421 if (error_widget != NULL) {
422 gtk_widget_destroy (error_widget);
423 g_hash_table_remove (priv->errors, account);
428 main_window_account_disabled_cb (TpAccountManager *manager,
430 EmpathyMainWindow *window)
432 main_window_remove_error (window, account);
436 main_window_error_retry_clicked_cb (GtkButton *button,
437 EmpathyMainWindow *window)
441 account = g_object_get_data (G_OBJECT (button), "account");
442 tp_account_reconnect_async (account, NULL, NULL);
444 main_window_remove_error (window, account);
448 main_window_error_edit_clicked_cb (GtkButton *button,
449 EmpathyMainWindow *window)
453 account = g_object_get_data (G_OBJECT (button), "account");
455 empathy_accounts_dialog_show_application (
456 gtk_widget_get_screen (GTK_WIDGET (button)),
457 account, FALSE, FALSE);
459 main_window_remove_error (window, account);
463 main_window_error_close_clicked_cb (GtkButton *button,
464 EmpathyMainWindow *window)
468 account = g_object_get_data (G_OBJECT (button), "account");
469 main_window_remove_error (window, account);
473 main_window_error_display (EmpathyMainWindow *window,
476 EmpathyMainWindowPriv *priv = GET_PRIV (window);
478 GtkWidget *content_area;
481 GtkWidget *retry_button;
482 GtkWidget *edit_button;
483 GtkWidget *close_button;
484 GtkWidget *action_area;
485 GtkWidget *action_table;
487 const gchar *icon_name;
488 const gchar *error_message;
489 gboolean user_requested;
492 empathy_account_get_error_message (account, &user_requested);
494 if (user_requested) {
498 str = g_markup_printf_escaped ("<b>%s</b>\n%s",
499 tp_account_get_display_name (account),
502 info_bar = g_hash_table_lookup (priv->errors, account);
504 label = g_object_get_data (G_OBJECT (info_bar), "label");
506 /* Just set the latest error and return */
507 gtk_label_set_markup (GTK_LABEL (label), str);
513 info_bar = gtk_info_bar_new ();
514 gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_ERROR);
516 gtk_widget_set_no_show_all (info_bar, TRUE);
517 gtk_box_pack_start (GTK_BOX (priv->errors_vbox), info_bar, FALSE, TRUE, 0);
518 gtk_widget_show (info_bar);
520 icon_name = tp_account_get_icon_name (account);
521 image = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_SMALL_TOOLBAR);
522 gtk_widget_show (image);
524 label = gtk_label_new (str);
525 gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
526 gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_END);
527 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
528 gtk_widget_show (label);
531 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
532 gtk_box_pack_start (GTK_BOX (content_area), image, FALSE, FALSE, 0);
533 gtk_box_pack_start (GTK_BOX (content_area), label, TRUE, TRUE, 0);
535 image = gtk_image_new_from_stock (GTK_STOCK_REFRESH, GTK_ICON_SIZE_BUTTON);
536 retry_button = gtk_button_new ();
537 gtk_button_set_image (GTK_BUTTON (retry_button), image);
538 gtk_widget_set_tooltip_text (retry_button, _("Reconnect"));
539 gtk_widget_show (retry_button);
541 image = gtk_image_new_from_stock (GTK_STOCK_EDIT, GTK_ICON_SIZE_BUTTON);
542 edit_button = gtk_button_new ();
543 gtk_button_set_image (GTK_BUTTON (edit_button), image);
544 gtk_widget_set_tooltip_text (edit_button, _("Edit Account"));
545 gtk_widget_show (edit_button);
547 image = gtk_image_new_from_stock (GTK_STOCK_CLOSE, GTK_ICON_SIZE_BUTTON);
548 close_button = gtk_button_new ();
549 gtk_button_set_image (GTK_BUTTON (close_button), image);
550 gtk_widget_set_tooltip_text (close_button, _("Close"));
551 gtk_widget_show (close_button);
553 action_table = gtk_table_new (1, 3, FALSE);
554 gtk_table_set_col_spacings (GTK_TABLE (action_table), 2);
555 gtk_widget_show (action_table);
557 action_area = gtk_info_bar_get_action_area (GTK_INFO_BAR (info_bar));
558 gtk_box_pack_start (GTK_BOX (action_area), action_table, FALSE, FALSE, 0);
560 gtk_table_attach (GTK_TABLE (action_table), retry_button, 0, 1, 0, 1,
561 (GtkAttachOptions) (GTK_SHRINK),
562 (GtkAttachOptions) (GTK_SHRINK), 0, 0);
563 gtk_table_attach (GTK_TABLE (action_table), edit_button, 1, 2, 0, 1,
564 (GtkAttachOptions) (GTK_SHRINK),
565 (GtkAttachOptions) (GTK_SHRINK), 0, 0);
566 gtk_table_attach (GTK_TABLE (action_table), close_button, 2, 3, 0, 1,
567 (GtkAttachOptions) (GTK_SHRINK),
568 (GtkAttachOptions) (GTK_SHRINK), 0, 0);
570 g_object_set_data (G_OBJECT (info_bar), "label", label);
571 g_object_set_data_full (G_OBJECT (info_bar),
572 "account", g_object_ref (account),
574 g_object_set_data_full (G_OBJECT (edit_button),
575 "account", g_object_ref (account),
577 g_object_set_data_full (G_OBJECT (close_button),
578 "account", g_object_ref (account),
580 g_object_set_data_full (G_OBJECT (retry_button),
581 "account", g_object_ref (account),
584 g_signal_connect (edit_button, "clicked",
585 G_CALLBACK (main_window_error_edit_clicked_cb),
587 g_signal_connect (close_button, "clicked",
588 G_CALLBACK (main_window_error_close_clicked_cb),
590 g_signal_connect (retry_button, "clicked",
591 G_CALLBACK (main_window_error_retry_clicked_cb),
594 gtk_widget_show (priv->errors_vbox);
596 g_hash_table_insert (priv->errors, g_object_ref (account), info_bar);
600 main_window_update_status (EmpathyMainWindow *window)
602 EmpathyMainWindowPriv *priv = GET_PRIV (window);
603 gboolean connected, connecting;
606 connected = empathy_account_manager_get_accounts_connected (&connecting);
608 /* Update the spinner state */
610 gtk_spinner_start (GTK_SPINNER (priv->throbber));
611 gtk_widget_show (priv->throbber_tool_item);
613 gtk_spinner_stop (GTK_SPINNER (priv->throbber));
614 gtk_widget_hide (priv->throbber_tool_item);
617 /* Update widgets sensibility */
618 for (l = priv->actions_connected; l; l = l->next) {
619 gtk_action_set_sensitive (l->data, connected);
624 main_window_connection_changed_cb (TpAccount *account,
628 gchar *dbus_error_name,
630 EmpathyMainWindow *window)
632 main_window_update_status (window);
634 if (current == TP_CONNECTION_STATUS_DISCONNECTED &&
635 reason != TP_CONNECTION_STATUS_REASON_REQUESTED) {
636 main_window_error_display (window, account);
639 if (current == TP_CONNECTION_STATUS_DISCONNECTED) {
640 empathy_sound_play (GTK_WIDGET (window),
641 EMPATHY_SOUND_ACCOUNT_DISCONNECTED);
644 if (current == TP_CONNECTION_STATUS_CONNECTED) {
645 empathy_sound_play (GTK_WIDGET (window),
646 EMPATHY_SOUND_ACCOUNT_CONNECTED);
648 /* Account connected without error, remove error message if any */
649 main_window_remove_error (window, account);
654 main_window_accels_load (void)
658 filename = g_build_filename (g_get_user_config_dir (), PACKAGE_NAME, ACCELS_FILENAME, NULL);
659 if (g_file_test (filename, G_FILE_TEST_EXISTS)) {
660 DEBUG ("Loading from:'%s'", filename);
661 gtk_accel_map_load (filename);
668 main_window_accels_save (void)
671 gchar *file_with_path;
673 dir = g_build_filename (g_get_user_config_dir (), PACKAGE_NAME, NULL);
674 g_mkdir_with_parents (dir, S_IRUSR | S_IWUSR | S_IXUSR);
675 file_with_path = g_build_filename (dir, ACCELS_FILENAME, NULL);
678 DEBUG ("Saving to:'%s'", file_with_path);
679 gtk_accel_map_save (file_with_path);
681 g_free (file_with_path);
685 empathy_main_window_finalize (GObject *window)
687 EmpathyMainWindowPriv *priv = GET_PRIV (window);
691 /* Save user-defined accelerators. */
692 main_window_accels_save ();
694 g_list_free (priv->actions_connected);
696 g_object_unref (priv->account_manager);
697 g_object_unref (priv->individual_store);
698 g_hash_table_destroy (priv->errors);
700 /* disconnect all handlers of status-changed signal */
701 g_hash_table_iter_init (&iter, priv->status_changed_handlers);
702 while (g_hash_table_iter_next (&iter, &key, &value))
703 g_signal_handler_disconnect (TP_ACCOUNT (key),
704 GPOINTER_TO_UINT (value));
706 g_hash_table_destroy (priv->status_changed_handlers);
708 g_signal_handlers_disconnect_by_func (priv->event_manager,
709 main_window_event_added_cb,
711 g_signal_handlers_disconnect_by_func (priv->event_manager,
712 main_window_event_removed_cb,
714 g_object_unref (priv->event_manager);
715 g_object_unref (priv->ui_manager);
716 g_object_unref (priv->chatroom_manager);
718 g_object_unref (priv->gsettings_ui);
719 g_object_unref (priv->gsettings_contacts);
721 G_OBJECT_CLASS (empathy_main_window_parent_class)->finalize (window);
725 main_window_key_press_event_cb (GtkWidget *window,
729 EmpathyChatManager *chat_manager;
731 if (event->keyval == GDK_KEY_T
732 && event->state & GDK_SHIFT_MASK
733 && event->state & GDK_CONTROL_MASK) {
734 chat_manager = empathy_chat_manager_dup_singleton ();
735 empathy_chat_manager_undo_closed_chat (chat_manager);
736 g_object_unref (chat_manager);
742 main_window_chat_quit_cb (GtkAction *action,
743 EmpathyMainWindow *window)
749 main_window_view_history_cb (GtkAction *action,
750 EmpathyMainWindow *window)
752 empathy_log_window_show (NULL, NULL, FALSE, GTK_WINDOW (window));
756 main_window_chat_new_message_cb (GtkAction *action,
757 EmpathyMainWindow *window)
759 empathy_new_message_dialog_show (GTK_WINDOW (window));
763 main_window_chat_new_call_cb (GtkAction *action,
764 EmpathyMainWindow *window)
766 empathy_new_call_dialog_show (GTK_WINDOW (window));
770 main_window_chat_add_contact_cb (GtkAction *action,
771 EmpathyMainWindow *window)
773 empathy_new_individual_dialog_show (GTK_WINDOW (window));
777 main_window_view_show_ft_manager (GtkAction *action,
778 EmpathyMainWindow *window)
780 empathy_ft_manager_show ();
784 main_window_view_show_offline_cb (GtkToggleAction *action,
785 EmpathyMainWindow *window)
787 EmpathyMainWindowPriv *priv = GET_PRIV (window);
790 current = gtk_toggle_action_get_active (action);
791 g_settings_set_boolean (priv->gsettings_ui,
792 EMPATHY_PREFS_UI_SHOW_OFFLINE,
795 empathy_individual_view_set_show_offline (priv->individual_view,
800 main_window_notify_sort_contact_cb (GSettings *gsettings,
802 EmpathyMainWindow *window)
804 EmpathyMainWindowPriv *priv = GET_PRIV (window);
807 str = g_settings_get_string (gsettings, key);
811 GEnumClass *enum_class;
812 GEnumValue *enum_value;
814 type = empathy_individual_store_sort_get_type ();
815 enum_class = G_ENUM_CLASS (g_type_class_peek (type));
816 enum_value = g_enum_get_value_by_nick (enum_class, str);
818 /* By changing the value of the GtkRadioAction,
819 it emits a signal that calls main_window_view_sort_contacts_cb
820 which updates the contacts list */
821 gtk_radio_action_set_current_value (priv->sort_by_name,
824 g_warning ("Wrong value for sort_criterium configuration : %s", str);
831 main_window_view_sort_contacts_cb (GtkRadioAction *action,
832 GtkRadioAction *current,
833 EmpathyMainWindow *window)
835 EmpathyMainWindowPriv *priv = GET_PRIV (window);
836 EmpathyContactListStoreSort value;
839 GEnumClass *enum_class;
840 GEnumValue *enum_value;
842 value = gtk_radio_action_get_current_value (action);
843 group = gtk_radio_action_get_group (action);
845 /* Get string from index */
846 type = empathy_individual_store_sort_get_type ();
847 enum_class = G_ENUM_CLASS (g_type_class_peek (type));
848 enum_value = g_enum_get_value (enum_class, g_slist_index (group, current));
851 g_warning ("No GEnumValue for EmpathyContactListSort with GtkRadioAction index:%d",
852 g_slist_index (group, action));
854 g_settings_set_string (priv->gsettings_contacts,
855 EMPATHY_PREFS_CONTACTS_SORT_CRITERIUM,
856 enum_value->value_nick);
858 empathy_individual_store_set_sort_criterium (priv->individual_store,
863 main_window_view_show_protocols_cb (GtkToggleAction *action,
864 EmpathyMainWindow *window)
866 EmpathyMainWindowPriv *priv = GET_PRIV (window);
869 value = gtk_toggle_action_get_active (action);
871 g_settings_set_boolean (priv->gsettings_ui,
872 EMPATHY_PREFS_UI_SHOW_PROTOCOLS,
874 empathy_individual_store_set_show_protocols (priv->individual_store,
878 /* Matches GtkRadioAction values set in empathy-main-window.ui */
879 #define CONTACT_LIST_NORMAL_SIZE_WITH_AVATARS 0
880 #define CONTACT_LIST_NORMAL_SIZE 1
881 #define CONTACT_LIST_COMPACT_SIZE 2
884 main_window_view_contacts_list_size_cb (GtkRadioAction *action,
885 GtkRadioAction *current,
886 EmpathyMainWindow *window)
888 EmpathyMainWindowPriv *priv = GET_PRIV (window);
889 GSettings *gsettings_ui;
892 value = gtk_radio_action_get_current_value (action);
893 /* create a new GSettings, so we can delay the setting until both
895 gsettings_ui = g_settings_new (EMPATHY_PREFS_UI_SCHEMA);
897 DEBUG ("radio button toggled, value = %i", value);
899 g_settings_delay (gsettings_ui);
900 g_settings_set_boolean (gsettings_ui,
901 EMPATHY_PREFS_UI_SHOW_AVATARS,
902 value == CONTACT_LIST_NORMAL_SIZE_WITH_AVATARS);
904 g_settings_set_boolean (gsettings_ui,
905 EMPATHY_PREFS_UI_COMPACT_CONTACT_LIST,
906 value == CONTACT_LIST_COMPACT_SIZE);
907 g_settings_apply (gsettings_ui);
909 /* FIXME: these enums probably have the wrong namespace */
910 empathy_individual_store_set_show_avatars (priv->individual_store,
911 value == CONTACT_LIST_NORMAL_SIZE_WITH_AVATARS);
912 empathy_individual_store_set_is_compact (priv->individual_store,
913 value == CONTACT_LIST_COMPACT_SIZE);
915 g_object_unref (gsettings_ui);
918 static void main_window_notify_show_protocols_cb (GSettings *gsettings,
920 EmpathyMainWindow *window)
922 EmpathyMainWindowPriv *priv = GET_PRIV (window);
924 gtk_toggle_action_set_active (priv->show_protocols,
925 g_settings_get_boolean (gsettings,
926 EMPATHY_PREFS_UI_SHOW_PROTOCOLS));
931 main_window_notify_contact_list_size_cb (GSettings *gsettings,
933 EmpathyMainWindow *window)
935 EmpathyMainWindowPriv *priv = GET_PRIV (window);
938 if (g_settings_get_boolean (gsettings,
939 EMPATHY_PREFS_UI_COMPACT_CONTACT_LIST)) {
940 value = CONTACT_LIST_COMPACT_SIZE;
941 } else if (g_settings_get_boolean (gsettings,
942 EMPATHY_PREFS_UI_SHOW_AVATARS)) {
943 value = CONTACT_LIST_NORMAL_SIZE_WITH_AVATARS;
945 value = CONTACT_LIST_NORMAL_SIZE;
948 DEBUG ("setting changed, value = %i", value);
950 /* By changing the value of the GtkRadioAction,
951 it emits a signal that calls main_window_view_contacts_list_size_cb
952 which updates the contacts list */
953 gtk_radio_action_set_current_value (priv->normal_with_avatars, value);
957 main_window_view_show_map_cb (GtkCheckMenuItem *item,
958 EmpathyMainWindow *window)
960 #ifdef HAVE_LIBCHAMPLAIN
961 empathy_map_view_show ();
966 join_chatroom (EmpathyChatroom *chatroom,
972 account = empathy_chatroom_get_account (chatroom);
973 room = empathy_chatroom_get_room (chatroom);
975 DEBUG ("Requesting channel for '%s'", room);
976 empathy_dispatcher_join_muc (account, room, timestamp);
982 EmpathyChatroom *chatroom;
986 } join_fav_account_sig_ctx;
988 static join_fav_account_sig_ctx *
989 join_fav_account_sig_ctx_new (TpAccount *account,
990 EmpathyChatroom *chatroom,
993 join_fav_account_sig_ctx *ctx = g_slice_new0 (
994 join_fav_account_sig_ctx);
996 ctx->account = g_object_ref (account);
997 ctx->chatroom = g_object_ref (chatroom);
998 ctx->timestamp = timestamp;
1003 join_fav_account_sig_ctx_free (join_fav_account_sig_ctx *ctx)
1005 g_object_unref (ctx->account);
1006 g_object_unref (ctx->chatroom);
1007 g_slice_free (join_fav_account_sig_ctx, ctx);
1011 account_status_changed_cb (TpAccount *account,
1012 TpConnectionStatus old_status,
1013 TpConnectionStatus new_status,
1015 gchar *dbus_error_name,
1016 GHashTable *details,
1019 join_fav_account_sig_ctx *ctx = user_data;
1021 switch (new_status) {
1022 case TP_CONNECTION_STATUS_DISCONNECTED:
1023 /* Don't wait any longer */
1027 case TP_CONNECTION_STATUS_CONNECTING:
1031 case TP_CONNECTION_STATUS_CONNECTED:
1032 /* We can join the room */
1036 g_assert_not_reached ();
1039 join_chatroom (ctx->chatroom, ctx->timestamp);
1042 g_source_remove (ctx->timeout);
1043 g_signal_handler_disconnect (account, ctx->sig_id);
1046 #define JOIN_FAVORITE_TIMEOUT 5
1049 join_favorite_timeout_cb (gpointer data)
1051 join_fav_account_sig_ctx *ctx = data;
1053 /* stop waiting for joining the favorite room */
1054 g_signal_handler_disconnect (ctx->account, ctx->sig_id);
1059 main_window_favorite_chatroom_join (EmpathyChatroom *chatroom)
1063 account = empathy_chatroom_get_account (chatroom);
1064 if (tp_account_get_connection_status (account, NULL) !=
1065 TP_CONNECTION_STATUS_CONNECTED) {
1066 join_fav_account_sig_ctx *ctx;
1068 ctx = join_fav_account_sig_ctx_new (account, chatroom,
1069 gtk_get_current_event_time ());
1071 ctx->sig_id = g_signal_connect_data (account, "status-changed",
1072 G_CALLBACK (account_status_changed_cb), ctx,
1073 (GClosureNotify) join_fav_account_sig_ctx_free, 0);
1075 ctx->timeout = g_timeout_add_seconds (JOIN_FAVORITE_TIMEOUT,
1076 join_favorite_timeout_cb, ctx);
1080 join_chatroom (chatroom, gtk_get_current_event_time ());
1084 main_window_favorite_chatroom_menu_activate_cb (GtkMenuItem *menu_item,
1085 EmpathyChatroom *chatroom)
1087 main_window_favorite_chatroom_join (chatroom);
1091 main_window_favorite_chatroom_menu_add (EmpathyMainWindow *window,
1092 EmpathyChatroom *chatroom)
1094 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1095 GtkWidget *menu_item;
1098 if (g_object_get_data (G_OBJECT (chatroom), "menu_item")) {
1102 name = empathy_chatroom_get_name (chatroom);
1103 menu_item = gtk_menu_item_new_with_label (name);
1105 g_object_set_data (G_OBJECT (chatroom), "menu_item", menu_item);
1106 g_signal_connect (menu_item, "activate",
1107 G_CALLBACK (main_window_favorite_chatroom_menu_activate_cb),
1110 gtk_menu_shell_insert (GTK_MENU_SHELL (priv->room_menu),
1113 gtk_widget_show (menu_item);
1117 main_window_favorite_chatroom_menu_added_cb (EmpathyChatroomManager *manager,
1118 EmpathyChatroom *chatroom,
1119 EmpathyMainWindow *window)
1121 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1123 main_window_favorite_chatroom_menu_add (window, chatroom);
1124 gtk_widget_show (priv->room_separator);
1125 gtk_action_set_sensitive (priv->room_join_favorites, TRUE);
1129 main_window_favorite_chatroom_menu_removed_cb (EmpathyChatroomManager *manager,
1130 EmpathyChatroom *chatroom,
1131 EmpathyMainWindow *window)
1133 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1134 GtkWidget *menu_item;
1137 menu_item = g_object_get_data (G_OBJECT (chatroom), "menu_item");
1138 g_object_set_data (G_OBJECT (chatroom), "menu_item", NULL);
1139 gtk_widget_destroy (menu_item);
1141 chatrooms = empathy_chatroom_manager_get_chatrooms (priv->chatroom_manager, NULL);
1143 gtk_widget_show (priv->room_separator);
1145 gtk_widget_hide (priv->room_separator);
1148 gtk_action_set_sensitive (priv->room_join_favorites, chatrooms != NULL);
1149 g_list_free (chatrooms);
1153 main_window_favorite_chatroom_menu_setup (EmpathyMainWindow *window)
1155 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1156 GList *chatrooms, *l;
1159 priv->chatroom_manager = empathy_chatroom_manager_dup_singleton (NULL);
1160 chatrooms = empathy_chatroom_manager_get_chatrooms (
1161 priv->chatroom_manager, NULL);
1162 room = gtk_ui_manager_get_widget (priv->ui_manager,
1164 priv->room_menu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (room));
1165 priv->room_separator = gtk_ui_manager_get_widget (priv->ui_manager,
1166 "/menubar/room/room_separator");
1168 for (l = chatrooms; l; l = l->next) {
1169 main_window_favorite_chatroom_menu_add (window, l->data);
1173 gtk_widget_hide (priv->room_separator);
1176 gtk_action_set_sensitive (priv->room_join_favorites, chatrooms != NULL);
1178 g_signal_connect (priv->chatroom_manager, "chatroom-added",
1179 G_CALLBACK (main_window_favorite_chatroom_menu_added_cb),
1181 g_signal_connect (priv->chatroom_manager, "chatroom-removed",
1182 G_CALLBACK (main_window_favorite_chatroom_menu_removed_cb),
1185 g_list_free (chatrooms);
1189 main_window_room_join_new_cb (GtkAction *action,
1190 EmpathyMainWindow *window)
1192 empathy_new_chatroom_dialog_show (GTK_WINDOW (window));
1196 main_window_room_join_favorites_cb (GtkAction *action,
1197 EmpathyMainWindow *window)
1199 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1200 GList *chatrooms, *l;
1202 chatrooms = empathy_chatroom_manager_get_chatrooms (priv->chatroom_manager, NULL);
1203 for (l = chatrooms; l; l = l->next) {
1204 main_window_favorite_chatroom_join (l->data);
1206 g_list_free (chatrooms);
1210 main_window_room_manage_favorites_cb (GtkAction *action,
1211 EmpathyMainWindow *window)
1213 empathy_chatrooms_window_show (GTK_WINDOW (window));
1217 main_window_edit_cb (GtkAction *action,
1218 EmpathyMainWindow *window)
1220 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1223 /* FIXME: It should use the UIManager to merge the contact/group submenu */
1224 submenu = empathy_individual_view_get_individual_menu (
1225 priv->individual_view);
1230 item = GTK_MENU_ITEM (priv->edit_context);
1231 label = gtk_bin_get_child (GTK_BIN (item));
1232 gtk_label_set_text (GTK_LABEL (label), _("Contact"));
1234 gtk_widget_show (priv->edit_context);
1235 gtk_widget_show (priv->edit_context_separator);
1237 gtk_menu_item_set_submenu (item, submenu);
1242 submenu = empathy_individual_view_get_group_menu (
1243 priv->individual_view);
1248 item = GTK_MENU_ITEM (priv->edit_context);
1249 label = gtk_bin_get_child (GTK_BIN (item));
1250 gtk_label_set_text (GTK_LABEL (label), _("Group"));
1252 gtk_widget_show (priv->edit_context);
1253 gtk_widget_show (priv->edit_context_separator);
1255 gtk_menu_item_set_submenu (item, submenu);
1260 gtk_widget_hide (priv->edit_context);
1261 gtk_widget_hide (priv->edit_context_separator);
1267 main_window_edit_accounts_cb (GtkAction *action,
1268 EmpathyMainWindow *window)
1270 empathy_accounts_dialog_show_application (gdk_screen_get_default (),
1271 NULL, FALSE, FALSE);
1275 main_window_edit_personal_information_cb (GtkAction *action,
1276 EmpathyMainWindow *window)
1278 empathy_contact_personal_dialog_show (GTK_WINDOW (window));
1282 main_window_edit_preferences_cb (GtkAction *action,
1283 EmpathyMainWindow *window)
1285 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1287 if (priv->preferences == NULL) {
1288 priv->preferences = empathy_preferences_new (GTK_WINDOW (window));
1289 g_object_add_weak_pointer (G_OBJECT (priv->preferences),
1290 (gpointer) &priv->preferences);
1292 gtk_widget_show (priv->preferences);
1294 gtk_window_present (GTK_WINDOW (priv->preferences));
1299 main_window_help_about_cb (GtkAction *action,
1300 EmpathyMainWindow *window)
1302 empathy_about_dialog_new (GTK_WINDOW (window));
1306 main_window_help_debug_cb (GtkAction *action,
1307 EmpathyMainWindow *window)
1309 GdkScreen *screen = gdk_screen_get_default ();
1310 GError *error = NULL;
1311 gchar *argv[2] = { NULL, };
1315 g_return_if_fail (GDK_IS_SCREEN (screen));
1317 /* Try to run from source directory if possible */
1318 path = g_build_filename (g_getenv ("EMPATHY_SRCDIR"), "src",
1319 "empathy-debugger", NULL);
1321 if (!g_file_test (path, G_FILE_TEST_EXISTS)) {
1323 path = g_build_filename (BIN_DIR, "empathy-debugger", NULL);
1328 gdk_spawn_on_screen (screen, NULL, argv, NULL,
1329 G_SPAWN_SEARCH_PATH,
1330 NULL, NULL, NULL, &error);
1333 g_warning ("Failed to open debug window: %s", error->message);
1334 g_error_free (error);
1341 main_window_help_contents_cb (GtkAction *action,
1342 EmpathyMainWindow *window)
1344 empathy_url_show (GTK_WIDGET (window), "ghelp:empathy");
1348 main_window_throbber_button_press_event_cb (GtkWidget *throbber,
1349 GdkEventButton *event,
1350 EmpathyMainWindow *window)
1352 if (event->type != GDK_BUTTON_PRESS ||
1353 event->button != 1) {
1357 empathy_accounts_dialog_show_application (
1358 gtk_widget_get_screen (GTK_WIDGET (throbber)),
1359 NULL, FALSE, FALSE);
1365 main_window_account_removed_cb (TpAccountManager *manager,
1367 EmpathyMainWindow *window)
1369 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1372 a = tp_account_manager_get_valid_accounts (manager);
1374 gtk_action_set_sensitive (priv->view_history,
1375 g_list_length (a) > 0);
1379 /* remove errors if any */
1380 main_window_remove_error (window, account);
1384 main_window_account_validity_changed_cb (TpAccountManager *manager,
1387 EmpathyMainWindow *window)
1389 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1393 handler_id = GPOINTER_TO_UINT (g_hash_table_lookup (
1394 priv->status_changed_handlers, account));
1396 /* connect signal only if it was not connected yet */
1397 if (handler_id == 0) {
1398 handler_id = g_signal_connect (account,
1400 G_CALLBACK (main_window_connection_changed_cb),
1402 g_hash_table_insert (priv->status_changed_handlers,
1403 account, GUINT_TO_POINTER (handler_id));
1407 main_window_account_removed_cb (manager, account, window);
1411 main_window_notify_show_offline_cb (GSettings *gsettings,
1413 gpointer toggle_action)
1415 gtk_toggle_action_set_active (toggle_action,
1416 g_settings_get_boolean (gsettings, key));
1420 main_window_connection_items_setup (EmpathyMainWindow *window,
1423 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1427 const gchar *actions_connected[] = {
1432 "edit_personal_information"
1435 for (i = 0, list = NULL; i < G_N_ELEMENTS (actions_connected); i++) {
1436 action = gtk_builder_get_object (gui, actions_connected[i]);
1437 list = g_list_prepend (list, action);
1440 priv->actions_connected = list;
1444 account_manager_prepared_cb (GObject *source_object,
1445 GAsyncResult *result,
1448 GList *accounts, *j;
1449 TpAccountManager *manager = TP_ACCOUNT_MANAGER (source_object);
1450 EmpathyMainWindow *window = user_data;
1451 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1452 GError *error = NULL;
1454 if (!tp_account_manager_prepare_finish (manager, result, &error)) {
1455 DEBUG ("Failed to prepare account manager: %s", error->message);
1456 g_error_free (error);
1460 accounts = tp_account_manager_get_valid_accounts (priv->account_manager);
1461 for (j = accounts; j != NULL; j = j->next) {
1462 TpAccount *account = TP_ACCOUNT (j->data);
1465 handler_id = g_signal_connect (account, "status-changed",
1466 G_CALLBACK (main_window_connection_changed_cb),
1468 g_hash_table_insert (priv->status_changed_handlers,
1469 account, GUINT_TO_POINTER (handler_id));
1472 g_signal_connect (manager, "account-validity-changed",
1473 G_CALLBACK (main_window_account_validity_changed_cb),
1476 main_window_update_status (window);
1478 /* Disable the "Previous Conversations" menu entry if there is no account */
1479 gtk_action_set_sensitive (priv->view_history,
1480 g_list_length (accounts) > 0);
1482 g_list_free (accounts);
1486 main_window_members_changed_cb (EmpathyContactList *list,
1487 EmpathyContact *contact,
1488 EmpathyContact *actor,
1492 EmpathyMainWindow *window)
1494 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1499 if (!empathy_migrate_butterfly_logs (contact)) {
1500 g_signal_handler_disconnect (list,
1501 priv->butterfly_log_migration_members_changed_id);
1502 priv->butterfly_log_migration_members_changed_id = 0;
1507 empathy_main_window_constructor (GType type,
1508 guint n_construct_params,
1509 GObjectConstructParam *construct_params)
1511 static GObject *window = NULL;
1514 return g_object_ref (window);
1516 window = G_OBJECT_CLASS (empathy_main_window_parent_class)->constructor (
1517 type, n_construct_params, construct_params);
1519 g_object_add_weak_pointer (window, (gpointer) &window);
1525 empathy_main_window_class_init (EmpathyMainWindowClass *klass)
1527 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1529 object_class->finalize = empathy_main_window_finalize;
1530 object_class->constructor = empathy_main_window_constructor;
1532 g_type_class_add_private (object_class, sizeof (EmpathyMainWindowPriv));
1536 empathy_main_window_init (EmpathyMainWindow *window)
1538 EmpathyMainWindowPriv *priv;
1539 EmpathyContactList *list_iface;
1540 EmpathyIndividualManager *individual_manager;
1543 GtkToggleAction *show_offline_widget;
1544 GtkAction *show_map_widget;
1546 gboolean show_offline;
1549 GtkTreeModel *model;
1551 priv = window->priv = G_TYPE_INSTANCE_GET_PRIVATE (window,
1552 EMPATHY_TYPE_MAIN_WINDOW, EmpathyMainWindowPriv);
1554 priv->gsettings_ui = g_settings_new (EMPATHY_PREFS_UI_SCHEMA);
1555 priv->gsettings_contacts = g_settings_new (EMPATHY_PREFS_CONTACTS_SCHEMA);
1557 gtk_window_set_title (GTK_WINDOW (window), _("Contact List"));
1558 gtk_window_set_role (GTK_WINDOW (window), "contact_list");
1559 gtk_window_set_default_size (GTK_WINDOW (window), 225, 325);
1561 /* Set up interface */
1562 filename = empathy_file_lookup ("empathy-main-window.ui", "src");
1563 gui = empathy_builder_get_file (filename,
1564 "main_vbox", &priv->main_vbox,
1565 "errors_vbox", &priv->errors_vbox,
1566 "ui_manager", &priv->ui_manager,
1567 "view_show_offline", &show_offline_widget,
1568 "view_show_protocols", &priv->show_protocols,
1569 "view_sort_by_name", &priv->sort_by_name,
1570 "view_sort_by_status", &priv->sort_by_status,
1571 "view_normal_size_with_avatars", &priv->normal_with_avatars,
1572 "view_normal_size", &priv->normal_size,
1573 "view_compact_size", &priv->compact_size,
1574 "view_history", &priv->view_history,
1575 "view_show_map", &show_map_widget,
1576 "room_join_favorites", &priv->room_join_favorites,
1577 "presence_toolbar", &priv->presence_toolbar,
1578 "notebook", &priv->notebook,
1579 "no_entry_label", &priv->no_entry_label,
1580 "roster_scrolledwindow", &sw,
1584 gtk_container_add (GTK_CONTAINER (window), priv->main_vbox);
1585 gtk_widget_show (priv->main_vbox);
1587 g_signal_connect (window, "key-press-event",
1588 G_CALLBACK (main_window_key_press_event_cb), NULL);
1590 empathy_builder_connect (gui, window,
1591 "chat_quit", "activate", main_window_chat_quit_cb,
1592 "chat_new_message", "activate", main_window_chat_new_message_cb,
1593 "chat_new_call", "activate", main_window_chat_new_call_cb,
1594 "view_history", "activate", main_window_view_history_cb,
1595 "room_join_new", "activate", main_window_room_join_new_cb,
1596 "room_join_favorites", "activate", main_window_room_join_favorites_cb,
1597 "room_manage_favorites", "activate", main_window_room_manage_favorites_cb,
1598 "chat_add_contact", "activate", main_window_chat_add_contact_cb,
1599 "view_show_ft_manager", "activate", main_window_view_show_ft_manager,
1600 "view_show_offline", "toggled", main_window_view_show_offline_cb,
1601 "view_show_protocols", "toggled", main_window_view_show_protocols_cb,
1602 "view_sort_by_name", "changed", main_window_view_sort_contacts_cb,
1603 "view_normal_size_with_avatars", "changed", main_window_view_contacts_list_size_cb,
1604 "view_show_map", "activate", main_window_view_show_map_cb,
1605 "edit", "activate", main_window_edit_cb,
1606 "edit_accounts", "activate", main_window_edit_accounts_cb,
1607 "edit_personal_information", "activate", main_window_edit_personal_information_cb,
1608 "edit_preferences", "activate", main_window_edit_preferences_cb,
1609 "help_about", "activate", main_window_help_about_cb,
1610 "help_debug", "activate", main_window_help_debug_cb,
1611 "help_contents", "activate", main_window_help_contents_cb,
1614 /* Set up connection related widgets. */
1615 main_window_connection_items_setup (window, gui);
1617 g_object_ref (priv->ui_manager);
1618 g_object_unref (gui);
1620 #ifndef HAVE_LIBCHAMPLAIN
1621 gtk_action_set_visible (show_map_widget, FALSE);
1624 priv->account_manager = tp_account_manager_dup ();
1626 tp_account_manager_prepare_async (priv->account_manager, NULL,
1627 account_manager_prepared_cb, window);
1629 priv->errors = g_hash_table_new_full (g_direct_hash,
1634 priv->status_changed_handlers = g_hash_table_new_full (g_direct_hash,
1640 main_window_favorite_chatroom_menu_setup (window);
1642 priv->edit_context = gtk_ui_manager_get_widget (priv->ui_manager,
1643 "/menubar/edit/edit_context");
1644 priv->edit_context_separator = gtk_ui_manager_get_widget (
1646 "/menubar/edit/edit_context_separator");
1647 gtk_widget_hide (priv->edit_context);
1648 gtk_widget_hide (priv->edit_context_separator);
1650 /* Set up contact list. */
1651 empathy_status_presets_get_all ();
1653 /* Set up presence chooser */
1654 priv->presence_chooser = empathy_presence_chooser_new ();
1655 gtk_widget_show (priv->presence_chooser);
1656 item = gtk_tool_item_new ();
1657 gtk_widget_show (GTK_WIDGET (item));
1658 gtk_container_add (GTK_CONTAINER (item), priv->presence_chooser);
1659 gtk_tool_item_set_is_important (item, TRUE);
1660 gtk_tool_item_set_expand (item, TRUE);
1661 gtk_toolbar_insert (GTK_TOOLBAR (priv->presence_toolbar), item, -1);
1663 /* Set up the throbber */
1664 priv->throbber = gtk_spinner_new ();
1665 gtk_widget_set_size_request (priv->throbber, 16, -1);
1666 gtk_widget_set_tooltip_text (priv->throbber, _("Show and edit accounts"));
1667 gtk_widget_set_events (priv->throbber, GDK_BUTTON_PRESS_MASK);
1668 g_signal_connect (priv->throbber, "button-press-event",
1669 G_CALLBACK (main_window_throbber_button_press_event_cb),
1671 gtk_widget_show (priv->throbber);
1673 item = gtk_tool_item_new ();
1674 gtk_container_set_border_width (GTK_CONTAINER (item), 6);
1675 gtk_toolbar_insert (GTK_TOOLBAR (priv->presence_toolbar), item, -1);
1676 gtk_container_add (GTK_CONTAINER (item), priv->throbber);
1677 priv->throbber_tool_item = GTK_WIDGET (item);
1679 list_iface = EMPATHY_CONTACT_LIST (empathy_contact_manager_dup_singleton ());
1680 individual_manager = empathy_individual_manager_dup_singleton ();
1681 priv->individual_store = empathy_individual_store_new (
1682 individual_manager);
1683 g_object_unref (individual_manager);
1685 /* For the moment, we disallow Persona drops onto the main contact list (e.g. from things such as
1686 * the EmpathyPersonaView in the linking dialogue). No code is hooked up to do anything on a Persona
1687 * drop, so allowing them would achieve nothing except confusion. */
1688 priv->individual_view = empathy_individual_view_new (
1689 priv->individual_store,
1690 EMPATHY_INDIVIDUAL_VIEW_FEATURE_ALL ^ EMPATHY_INDIVIDUAL_VIEW_FEATURE_PERSONA_DROP,
1691 EMPATHY_INDIVIDUAL_FEATURE_ALL);
1693 priv->butterfly_log_migration_members_changed_id = g_signal_connect (
1694 list_iface, "members-changed",
1695 G_CALLBACK (main_window_members_changed_cb), window);
1697 g_object_unref (list_iface);
1699 gtk_widget_show (GTK_WIDGET (priv->individual_view));
1700 gtk_container_add (GTK_CONTAINER (sw),
1701 GTK_WIDGET (priv->individual_view));
1702 g_signal_connect (priv->individual_view, "row-activated",
1703 G_CALLBACK (main_window_row_activated_cb),
1706 /* Set up search bar */
1707 priv->search_bar = empathy_live_search_new (
1708 GTK_WIDGET (priv->individual_view));
1709 empathy_individual_view_set_live_search (priv->individual_view,
1710 EMPATHY_LIVE_SEARCH (priv->search_bar));
1711 gtk_box_pack_start (GTK_BOX (priv->main_vbox), priv->search_bar,
1713 g_signal_connect_swapped (window, "map",
1714 G_CALLBACK (gtk_widget_grab_focus), priv->individual_view);
1716 /* Connect to proper signals to check if contact list is empty or not */
1717 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->individual_view));
1719 g_signal_connect (model, "row-inserted",
1720 G_CALLBACK (main_window_row_inserted_cb),
1722 g_signal_connect (model, "row-deleted",
1723 G_CALLBACK (main_window_row_deleted_cb),
1726 /* Load user-defined accelerators. */
1727 main_window_accels_load ();
1729 /* Set window size. */
1730 empathy_geometry_bind (GTK_WINDOW (window), GEOMETRY_NAME);
1732 /* Enable event handling */
1733 priv->event_manager = empathy_event_manager_dup_singleton ();
1735 g_signal_connect (priv->event_manager, "event-added",
1736 G_CALLBACK (main_window_event_added_cb), window);
1737 g_signal_connect (priv->event_manager, "event-removed",
1738 G_CALLBACK (main_window_event_removed_cb), window);
1739 g_signal_connect (priv->account_manager, "account-validity-changed",
1740 G_CALLBACK (main_window_account_validity_changed_cb),
1742 g_signal_connect (priv->account_manager, "account-removed",
1743 G_CALLBACK (main_window_account_removed_cb),
1745 g_signal_connect (priv->account_manager, "account-disabled",
1746 G_CALLBACK (main_window_account_disabled_cb),
1749 l = empathy_event_manager_get_events (priv->event_manager);
1751 main_window_event_added_cb (priv->event_manager, l->data,
1756 /* Show offline ? */
1757 show_offline = g_settings_get_boolean (priv->gsettings_ui,
1758 EMPATHY_PREFS_UI_SHOW_OFFLINE);
1759 g_signal_connect (priv->gsettings_ui,
1760 "changed::" EMPATHY_PREFS_UI_SHOW_OFFLINE,
1761 G_CALLBACK (main_window_notify_show_offline_cb),
1762 show_offline_widget);
1764 gtk_toggle_action_set_active (show_offline_widget, show_offline);
1766 /* Show protocol ? */
1767 g_signal_connect (priv->gsettings_ui,
1768 "changed::" EMPATHY_PREFS_UI_SHOW_PROTOCOLS,
1769 G_CALLBACK (main_window_notify_show_protocols_cb),
1772 main_window_notify_show_protocols_cb (priv->gsettings_ui,
1773 EMPATHY_PREFS_UI_SHOW_PROTOCOLS,
1776 /* Sort by name / by status ? */
1777 g_signal_connect (priv->gsettings_contacts,
1778 "changed::" EMPATHY_PREFS_CONTACTS_SORT_CRITERIUM,
1779 G_CALLBACK (main_window_notify_sort_contact_cb),
1782 main_window_notify_sort_contact_cb (priv->gsettings_contacts,
1783 EMPATHY_PREFS_CONTACTS_SORT_CRITERIUM,
1786 /* Contacts list size */
1787 g_signal_connect (priv->gsettings_ui,
1788 "changed::" EMPATHY_PREFS_UI_COMPACT_CONTACT_LIST,
1789 G_CALLBACK (main_window_notify_contact_list_size_cb),
1791 g_signal_connect (priv->gsettings_ui,
1792 "changed::" EMPATHY_PREFS_UI_SHOW_AVATARS,
1793 G_CALLBACK (main_window_notify_contact_list_size_cb),
1796 main_window_notify_contact_list_size_cb (priv->gsettings_ui,
1797 EMPATHY_PREFS_UI_SHOW_AVATARS,
1802 empathy_main_window_dup (void)
1804 return g_object_new (EMPATHY_TYPE_MAIN_WINDOW, NULL);