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"
94 G_DEFINE_TYPE (EmpathyMainWindow, empathy_main_window, GTK_TYPE_WINDOW);
96 #define GET_PRIV(self) ((EmpathyMainWindowPriv *)((EmpathyMainWindow *) self)->priv)
98 struct _EmpathyMainWindowPriv {
99 EmpathyIndividualStore *individual_store;
100 EmpathyIndividualView *individual_view;
101 TpAccountManager *account_manager;
102 EmpathyChatroomManager *chatroom_manager;
103 EmpathyEventManager *event_manager;
104 guint flash_timeout_id;
108 GSettings *gsettings_ui;
109 GSettings *gsettings_contacts;
111 GtkWidget *preferences;
112 GtkWidget *main_vbox;
114 GtkWidget *throbber_tool_item;
115 GtkWidget *presence_toolbar;
116 GtkWidget *presence_chooser;
117 GtkWidget *errors_vbox;
118 GtkWidget *search_bar;
120 GtkWidget *no_entry_label;
122 GtkToggleAction *show_protocols;
123 GtkRadioAction *sort_by_name;
124 GtkRadioAction *sort_by_status;
125 GtkRadioAction *normal_with_avatars;
126 GtkRadioAction *normal_size;
127 GtkRadioAction *compact_size;
129 GtkUIManager *ui_manager;
130 GtkAction *view_history;
131 GtkAction *room_join_favorites;
132 GtkWidget *room_menu;
133 GtkWidget *room_separator;
134 GtkWidget *edit_context;
135 GtkWidget *edit_context_separator;
137 guint size_timeout_id;
140 /* stores a mapping from TpAccount to Handler ID to prevent
141 * to listen more than once to the status-changed signal */
142 GHashTable *status_changed_handlers;
144 /* Actions that are enabled when there are connected accounts */
145 GList *actions_connected;
147 /* The idle event source to migrate butterfly's logs */
148 guint butterfly_log_migration_members_changed_id;
152 main_window_flash_stop (EmpathyMainWindow *window)
154 EmpathyMainWindowPriv *priv = GET_PRIV (window);
156 if (priv->flash_timeout_id == 0) {
160 DEBUG ("Stop flashing");
161 g_source_remove (priv->flash_timeout_id);
162 priv->flash_timeout_id = 0;
163 priv->flash_on = FALSE;
169 EmpathyMainWindow *window;
173 main_window_flash_foreach (GtkTreeModel *model,
178 FlashForeachData *data = (FlashForeachData *) user_data;
179 FolksIndividual *individual;
180 EmpathyContact *contact;
181 const gchar *icon_name;
182 GtkTreePath *parent_path = NULL;
183 GtkTreeIter parent_iter;
184 GdkPixbuf *pixbuf = NULL;
186 gtk_tree_model_get (model, iter,
187 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL,
191 if (individual == NULL)
194 contact = empathy_contact_dup_from_folks_individual (individual);
195 if (contact != data->event->contact) {
196 tp_clear_object (&contact);
201 icon_name = data->event->icon_name;
202 pixbuf = empathy_pixbuf_from_icon_name (icon_name, GTK_ICON_SIZE_MENU);
204 pixbuf = empathy_individual_store_get_individual_status_icon (
205 GET_PRIV (data->window)->individual_store,
209 gtk_tree_store_set (GTK_TREE_STORE (model), iter,
210 EMPATHY_INDIVIDUAL_STORE_COL_ICON_STATUS, pixbuf,
213 /* To make sure the parent is shown correctly, we emit
214 * the row-changed signal on the parent so it prompts
215 * it to be refreshed by the filter func.
217 if (gtk_tree_model_iter_parent (model, &parent_iter, iter)) {
218 parent_path = gtk_tree_model_get_path (model, &parent_iter);
221 gtk_tree_model_row_changed (model, parent_path, &parent_iter);
222 gtk_tree_path_free (parent_path);
225 g_object_unref (individual);
226 tp_clear_object (&contact);
232 main_window_flash_cb (EmpathyMainWindow *window)
234 EmpathyMainWindowPriv *priv = GET_PRIV (window);
237 gboolean found_event = FALSE;
238 FlashForeachData data;
240 priv->flash_on = !priv->flash_on;
241 data.on = priv->flash_on;
242 model = GTK_TREE_MODEL (priv->individual_store);
244 events = empathy_event_manager_get_events (priv->event_manager);
245 for (l = events; l; l = l->next) {
246 data.event = l->data;
247 data.window = window;
248 if (!data.event->contact || !data.event->must_ack) {
253 gtk_tree_model_foreach (model,
254 main_window_flash_foreach,
259 main_window_flash_stop (window);
266 main_window_flash_start (EmpathyMainWindow *window)
268 EmpathyMainWindowPriv *priv = GET_PRIV (window);
270 if (priv->flash_timeout_id != 0) {
274 DEBUG ("Start flashing");
275 priv->flash_timeout_id = g_timeout_add (FLASH_TIMEOUT,
276 (GSourceFunc) main_window_flash_cb,
278 main_window_flash_cb (window);
282 main_window_event_added_cb (EmpathyEventManager *manager,
284 EmpathyMainWindow *window)
286 if (event->contact) {
287 main_window_flash_start (window);
292 main_window_event_removed_cb (EmpathyEventManager *manager,
294 EmpathyMainWindow *window)
296 EmpathyMainWindowPriv *priv = GET_PRIV (window);
297 FlashForeachData data;
299 if (!event->contact) {
305 data.window = window;
306 gtk_tree_model_foreach (GTK_TREE_MODEL (priv->individual_store),
307 main_window_flash_foreach,
312 main_window_row_activated_cb (EmpathyContactListView *view,
314 GtkTreeViewColumn *col,
315 EmpathyMainWindow *window)
317 EmpathyMainWindowPriv *priv = GET_PRIV (window);
318 EmpathyContact *contact = NULL;
319 FolksIndividual *individual;
324 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->individual_view));
325 gtk_tree_model_get_iter (model, &iter, path);
327 gtk_tree_model_get (model, &iter,
328 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL,
332 if (individual != NULL) {
333 contact = empathy_contact_dup_from_folks_individual (individual);
340 /* If the contact has an event activate it, otherwise the
341 * default handler of row-activated will be called. */
342 events = empathy_event_manager_get_events (priv->event_manager);
343 for (l = events; l; l = l->next) {
344 EmpathyEvent *event = l->data;
346 if (event->contact == contact) {
347 DEBUG ("Activate event");
348 empathy_event_activate (event);
350 /* We don't want the default handler of this signal
351 * (e.g. open a chat) */
352 g_signal_stop_emission_by_name (view, "row-activated");
357 g_object_unref (contact);
359 tp_clear_object (&individual);
363 main_window_row_deleted_cb (GtkTreeModel *model,
365 EmpathyMainWindow *window)
367 EmpathyMainWindowPriv *priv = GET_PRIV (window);
368 GtkTreeIter help_iter;
370 if (!gtk_tree_model_get_iter_first (model, &help_iter)) {
373 /* TODO: check if we are searching or not */
374 gtk_label_set_text (GTK_LABEL (priv->no_entry_label),
375 _("Your contact list is empty"));
376 gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook),
378 g_debug ("contact list empty");
383 main_window_row_inserted_cb (GtkTreeModel *model,
386 EmpathyMainWindow *window)
388 EmpathyMainWindowPriv *priv = GET_PRIV (window);
392 gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook),
394 g_debug ("contact list is not empty any more");
399 main_window_remove_error (EmpathyMainWindow *window,
402 EmpathyMainWindowPriv *priv = GET_PRIV (window);
403 GtkWidget *error_widget;
405 error_widget = g_hash_table_lookup (priv->errors, account);
406 if (error_widget != NULL) {
407 gtk_widget_destroy (error_widget);
408 g_hash_table_remove (priv->errors, account);
413 main_window_account_disabled_cb (TpAccountManager *manager,
415 EmpathyMainWindow *window)
417 main_window_remove_error (window, account);
421 main_window_error_retry_clicked_cb (GtkButton *button,
422 EmpathyMainWindow *window)
426 account = g_object_get_data (G_OBJECT (button), "account");
427 tp_account_reconnect_async (account, NULL, NULL);
429 main_window_remove_error (window, account);
433 main_window_error_edit_clicked_cb (GtkButton *button,
434 EmpathyMainWindow *window)
438 account = g_object_get_data (G_OBJECT (button), "account");
440 empathy_accounts_dialog_show_application (
441 gtk_widget_get_screen (GTK_WIDGET (button)),
442 account, FALSE, FALSE);
444 main_window_remove_error (window, account);
448 main_window_error_close_clicked_cb (GtkButton *button,
449 EmpathyMainWindow *window)
453 account = g_object_get_data (G_OBJECT (button), "account");
454 main_window_remove_error (window, account);
458 main_window_error_display (EmpathyMainWindow *window,
461 EmpathyMainWindowPriv *priv = GET_PRIV (window);
463 GtkWidget *content_area;
466 GtkWidget *retry_button;
467 GtkWidget *edit_button;
468 GtkWidget *close_button;
469 GtkWidget *action_area;
470 GtkWidget *action_table;
472 const gchar *icon_name;
474 str = g_markup_printf_escaped ("<b>%s</b>\n%s",
475 tp_account_get_display_name (account),
476 empathy_account_get_error_message (account));
478 info_bar = g_hash_table_lookup (priv->errors, account);
480 label = g_object_get_data (G_OBJECT (info_bar), "label");
482 /* Just set the latest error and return */
483 gtk_label_set_markup (GTK_LABEL (label), str);
489 info_bar = gtk_info_bar_new ();
490 gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_ERROR);
492 gtk_widget_set_no_show_all (info_bar, TRUE);
493 gtk_box_pack_start (GTK_BOX (priv->errors_vbox), info_bar, FALSE, TRUE, 0);
494 gtk_widget_show (info_bar);
496 icon_name = tp_account_get_icon_name (account);
497 image = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_SMALL_TOOLBAR);
498 gtk_widget_show (image);
500 label = gtk_label_new (str);
501 gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
502 gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_END);
503 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
504 gtk_widget_show (label);
507 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
508 gtk_box_pack_start (GTK_BOX (content_area), image, FALSE, FALSE, 0);
509 gtk_box_pack_start (GTK_BOX (content_area), label, TRUE, TRUE, 0);
511 image = gtk_image_new_from_stock (GTK_STOCK_REFRESH, GTK_ICON_SIZE_BUTTON);
512 retry_button = gtk_button_new ();
513 gtk_button_set_image (GTK_BUTTON (retry_button), image);
514 gtk_widget_set_tooltip_text (retry_button, _("Reconnect"));
515 gtk_widget_show (retry_button);
517 image = gtk_image_new_from_stock (GTK_STOCK_EDIT, GTK_ICON_SIZE_BUTTON);
518 edit_button = gtk_button_new ();
519 gtk_button_set_image (GTK_BUTTON (edit_button), image);
520 gtk_widget_set_tooltip_text (edit_button, _("Edit Account"));
521 gtk_widget_show (edit_button);
523 image = gtk_image_new_from_stock (GTK_STOCK_CLOSE, GTK_ICON_SIZE_BUTTON);
524 close_button = gtk_button_new ();
525 gtk_button_set_image (GTK_BUTTON (close_button), image);
526 gtk_widget_set_tooltip_text (close_button, _("Close"));
527 gtk_widget_show (close_button);
529 action_table = gtk_table_new (1, 3, FALSE);
530 gtk_table_set_col_spacings (GTK_TABLE (action_table), 2);
531 gtk_widget_show (action_table);
533 action_area = gtk_info_bar_get_action_area (GTK_INFO_BAR (info_bar));
534 gtk_box_pack_start (GTK_BOX (action_area), action_table, FALSE, FALSE, 0);
536 gtk_table_attach (GTK_TABLE (action_table), retry_button, 0, 1, 0, 1,
537 (GtkAttachOptions) (GTK_SHRINK),
538 (GtkAttachOptions) (GTK_SHRINK), 0, 0);
539 gtk_table_attach (GTK_TABLE (action_table), edit_button, 1, 2, 0, 1,
540 (GtkAttachOptions) (GTK_SHRINK),
541 (GtkAttachOptions) (GTK_SHRINK), 0, 0);
542 gtk_table_attach (GTK_TABLE (action_table), close_button, 2, 3, 0, 1,
543 (GtkAttachOptions) (GTK_SHRINK),
544 (GtkAttachOptions) (GTK_SHRINK), 0, 0);
546 g_object_set_data (G_OBJECT (info_bar), "label", label);
547 g_object_set_data_full (G_OBJECT (info_bar),
548 "account", g_object_ref (account),
550 g_object_set_data_full (G_OBJECT (edit_button),
551 "account", g_object_ref (account),
553 g_object_set_data_full (G_OBJECT (close_button),
554 "account", g_object_ref (account),
556 g_object_set_data_full (G_OBJECT (retry_button),
557 "account", g_object_ref (account),
560 g_signal_connect (edit_button, "clicked",
561 G_CALLBACK (main_window_error_edit_clicked_cb),
563 g_signal_connect (close_button, "clicked",
564 G_CALLBACK (main_window_error_close_clicked_cb),
566 g_signal_connect (retry_button, "clicked",
567 G_CALLBACK (main_window_error_retry_clicked_cb),
570 gtk_widget_show (priv->errors_vbox);
572 g_hash_table_insert (priv->errors, g_object_ref (account), info_bar);
576 main_window_update_status (EmpathyMainWindow *window)
578 EmpathyMainWindowPriv *priv = GET_PRIV (window);
579 gboolean connected, connecting;
582 connected = empathy_account_manager_get_accounts_connected (&connecting);
584 /* Update the spinner state */
586 gtk_spinner_start (GTK_SPINNER (priv->throbber));
587 gtk_widget_show (priv->throbber_tool_item);
589 gtk_spinner_stop (GTK_SPINNER (priv->throbber));
590 gtk_widget_hide (priv->throbber_tool_item);
593 /* Update widgets sensibility */
594 for (l = priv->actions_connected; l; l = l->next) {
595 gtk_action_set_sensitive (l->data, connected);
600 main_window_connection_changed_cb (TpAccount *account,
604 gchar *dbus_error_name,
606 EmpathyMainWindow *window)
608 main_window_update_status (window);
610 if (current == TP_CONNECTION_STATUS_DISCONNECTED &&
611 reason != TP_CONNECTION_STATUS_REASON_REQUESTED) {
612 main_window_error_display (window, account);
615 if (current == TP_CONNECTION_STATUS_DISCONNECTED) {
616 empathy_sound_play (GTK_WIDGET (window),
617 EMPATHY_SOUND_ACCOUNT_DISCONNECTED);
620 if (current == TP_CONNECTION_STATUS_CONNECTED) {
621 empathy_sound_play (GTK_WIDGET (window),
622 EMPATHY_SOUND_ACCOUNT_CONNECTED);
624 /* Account connected without error, remove error message if any */
625 main_window_remove_error (window, account);
630 main_window_accels_load (void)
634 filename = g_build_filename (g_get_user_config_dir (), PACKAGE_NAME, ACCELS_FILENAME, NULL);
635 if (g_file_test (filename, G_FILE_TEST_EXISTS)) {
636 DEBUG ("Loading from:'%s'", filename);
637 gtk_accel_map_load (filename);
644 main_window_accels_save (void)
647 gchar *file_with_path;
649 dir = g_build_filename (g_get_user_config_dir (), PACKAGE_NAME, NULL);
650 g_mkdir_with_parents (dir, S_IRUSR | S_IWUSR | S_IXUSR);
651 file_with_path = g_build_filename (dir, ACCELS_FILENAME, NULL);
654 DEBUG ("Saving to:'%s'", file_with_path);
655 gtk_accel_map_save (file_with_path);
657 g_free (file_with_path);
661 empathy_main_window_finalize (GObject *window)
663 EmpathyMainWindowPriv *priv = GET_PRIV (window);
667 /* Save user-defined accelerators. */
668 main_window_accels_save ();
670 g_list_free (priv->actions_connected);
672 g_object_unref (priv->account_manager);
673 g_object_unref (priv->individual_store);
674 g_hash_table_destroy (priv->errors);
676 /* disconnect all handlers of status-changed signal */
677 g_hash_table_iter_init (&iter, priv->status_changed_handlers);
678 while (g_hash_table_iter_next (&iter, &key, &value))
679 g_signal_handler_disconnect (TP_ACCOUNT (key),
680 GPOINTER_TO_UINT (value));
682 g_hash_table_destroy (priv->status_changed_handlers);
684 g_signal_handlers_disconnect_by_func (priv->event_manager,
685 main_window_event_added_cb,
687 g_signal_handlers_disconnect_by_func (priv->event_manager,
688 main_window_event_removed_cb,
690 g_object_unref (priv->event_manager);
691 g_object_unref (priv->ui_manager);
692 g_object_unref (priv->chatroom_manager);
694 g_object_unref (priv->gsettings_ui);
695 g_object_unref (priv->gsettings_contacts);
697 G_OBJECT_CLASS (empathy_main_window_parent_class)->finalize (window);
701 main_window_key_press_event_cb (GtkWidget *window,
705 EmpathyChatManager *chat_manager;
707 if (event->keyval == GDK_T
708 && event->state & GDK_SHIFT_MASK
709 && event->state & GDK_CONTROL_MASK) {
710 chat_manager = empathy_chat_manager_dup_singleton ();
711 empathy_chat_manager_undo_closed_chat (chat_manager);
712 g_object_unref (chat_manager);
718 main_window_chat_quit_cb (GtkAction *action,
719 EmpathyMainWindow *window)
725 main_window_view_history_cb (GtkAction *action,
726 EmpathyMainWindow *window)
728 empathy_log_window_show (NULL, NULL, FALSE, GTK_WINDOW (window));
732 main_window_chat_new_message_cb (GtkAction *action,
733 EmpathyMainWindow *window)
735 empathy_new_message_dialog_show (GTK_WINDOW (window));
739 main_window_chat_new_call_cb (GtkAction *action,
740 EmpathyMainWindow *window)
742 empathy_new_call_dialog_show (GTK_WINDOW (window));
746 main_window_chat_add_contact_cb (GtkAction *action,
747 EmpathyMainWindow *window)
749 empathy_new_individual_dialog_show (GTK_WINDOW (window));
753 main_window_view_show_ft_manager (GtkAction *action,
754 EmpathyMainWindow *window)
756 empathy_ft_manager_show ();
760 main_window_view_show_offline_cb (GtkToggleAction *action,
761 EmpathyMainWindow *window)
763 EmpathyMainWindowPriv *priv = GET_PRIV (window);
766 current = gtk_toggle_action_get_active (action);
767 g_settings_set_boolean (priv->gsettings_ui,
768 EMPATHY_PREFS_UI_SHOW_OFFLINE,
771 empathy_individual_view_set_show_offline (priv->individual_view,
776 main_window_notify_sort_contact_cb (GSettings *gsettings,
778 EmpathyMainWindow *window)
780 EmpathyMainWindowPriv *priv = GET_PRIV (window);
783 str = g_settings_get_string (gsettings, key);
787 GEnumClass *enum_class;
788 GEnumValue *enum_value;
790 type = empathy_individual_store_sort_get_type ();
791 enum_class = G_ENUM_CLASS (g_type_class_peek (type));
792 enum_value = g_enum_get_value_by_nick (enum_class, str);
794 /* By changing the value of the GtkRadioAction,
795 it emits a signal that calls main_window_view_sort_contacts_cb
796 which updates the contacts list */
797 gtk_radio_action_set_current_value (priv->sort_by_name,
800 g_warning ("Wrong value for sort_criterium configuration : %s", str);
807 main_window_view_sort_contacts_cb (GtkRadioAction *action,
808 GtkRadioAction *current,
809 EmpathyMainWindow *window)
811 EmpathyMainWindowPriv *priv = GET_PRIV (window);
812 EmpathyContactListStoreSort value;
815 GEnumClass *enum_class;
816 GEnumValue *enum_value;
818 value = gtk_radio_action_get_current_value (action);
819 group = gtk_radio_action_get_group (action);
821 /* Get string from index */
822 type = empathy_individual_store_sort_get_type ();
823 enum_class = G_ENUM_CLASS (g_type_class_peek (type));
824 enum_value = g_enum_get_value (enum_class, g_slist_index (group, current));
827 g_warning ("No GEnumValue for EmpathyContactListSort with GtkRadioAction index:%d",
828 g_slist_index (group, action));
830 g_settings_set_string (priv->gsettings_contacts,
831 EMPATHY_PREFS_CONTACTS_SORT_CRITERIUM,
832 enum_value->value_nick);
834 empathy_individual_store_set_sort_criterium (priv->individual_store,
839 main_window_view_show_protocols_cb (GtkToggleAction *action,
840 EmpathyMainWindow *window)
842 EmpathyMainWindowPriv *priv = GET_PRIV (window);
845 value = gtk_toggle_action_get_active (action);
847 g_settings_set_boolean (priv->gsettings_ui,
848 EMPATHY_PREFS_UI_SHOW_PROTOCOLS,
850 empathy_individual_store_set_show_protocols (priv->individual_store,
854 /* Matches GtkRadioAction values set in empathy-main-window.ui */
855 #define CONTACT_LIST_NORMAL_SIZE_WITH_AVATARS 0
856 #define CONTACT_LIST_NORMAL_SIZE 1
857 #define CONTACT_LIST_COMPACT_SIZE 2
860 main_window_view_contacts_list_size_cb (GtkRadioAction *action,
861 GtkRadioAction *current,
862 EmpathyMainWindow *window)
864 EmpathyMainWindowPriv *priv = GET_PRIV (window);
865 GSettings *gsettings_ui;
868 value = gtk_radio_action_get_current_value (action);
869 /* create a new GSettings, so we can delay the setting until both
871 gsettings_ui = g_settings_new (EMPATHY_PREFS_UI_SCHEMA);
873 DEBUG ("radio button toggled, value = %i", value);
875 g_settings_delay (gsettings_ui);
876 g_settings_set_boolean (gsettings_ui,
877 EMPATHY_PREFS_UI_SHOW_AVATARS,
878 value == CONTACT_LIST_NORMAL_SIZE_WITH_AVATARS);
880 g_settings_set_boolean (gsettings_ui,
881 EMPATHY_PREFS_UI_COMPACT_CONTACT_LIST,
882 value == CONTACT_LIST_COMPACT_SIZE);
883 g_settings_apply (gsettings_ui);
885 /* FIXME: these enums probably have the wrong namespace */
886 empathy_individual_store_set_show_avatars (priv->individual_store,
887 value == CONTACT_LIST_NORMAL_SIZE_WITH_AVATARS);
888 empathy_individual_store_set_is_compact (priv->individual_store,
889 value == CONTACT_LIST_COMPACT_SIZE);
891 g_object_unref (gsettings_ui);
894 static void main_window_notify_show_protocols_cb (GSettings *gsettings,
896 EmpathyMainWindow *window)
898 EmpathyMainWindowPriv *priv = GET_PRIV (window);
900 gtk_toggle_action_set_active (priv->show_protocols,
901 g_settings_get_boolean (gsettings,
902 EMPATHY_PREFS_UI_SHOW_PROTOCOLS));
907 main_window_notify_contact_list_size_cb (GSettings *gsettings,
909 EmpathyMainWindow *window)
911 EmpathyMainWindowPriv *priv = GET_PRIV (window);
914 if (g_settings_get_boolean (gsettings,
915 EMPATHY_PREFS_UI_COMPACT_CONTACT_LIST)) {
916 value = CONTACT_LIST_COMPACT_SIZE;
917 } else if (g_settings_get_boolean (gsettings,
918 EMPATHY_PREFS_UI_SHOW_AVATARS)) {
919 value = CONTACT_LIST_NORMAL_SIZE_WITH_AVATARS;
921 value = CONTACT_LIST_NORMAL_SIZE;
924 DEBUG ("setting changed, value = %i", value);
926 /* By changing the value of the GtkRadioAction,
927 it emits a signal that calls main_window_view_contacts_list_size_cb
928 which updates the contacts list */
929 gtk_radio_action_set_current_value (priv->normal_with_avatars, value);
933 main_window_view_show_map_cb (GtkCheckMenuItem *item,
934 EmpathyMainWindow *window)
936 #if HAVE_LIBCHAMPLAIN
937 empathy_map_view_show ();
942 join_chatroom (EmpathyChatroom *chatroom,
946 TpConnection *connection;
949 account = empathy_chatroom_get_account (chatroom);
950 connection = tp_account_get_connection (account);
951 g_assert (connection != NULL);
952 room = empathy_chatroom_get_room (chatroom);
954 DEBUG ("Requesting channel for '%s'", room);
955 empathy_dispatcher_join_muc (connection, room, timestamp);
961 EmpathyChatroom *chatroom;
965 } join_fav_account_sig_ctx;
967 static join_fav_account_sig_ctx *
968 join_fav_account_sig_ctx_new (TpAccount *account,
969 EmpathyChatroom *chatroom,
972 join_fav_account_sig_ctx *ctx = g_slice_new0 (
973 join_fav_account_sig_ctx);
975 ctx->account = g_object_ref (account);
976 ctx->chatroom = g_object_ref (chatroom);
977 ctx->timestamp = timestamp;
982 join_fav_account_sig_ctx_free (join_fav_account_sig_ctx *ctx)
984 g_object_unref (ctx->account);
985 g_object_unref (ctx->chatroom);
986 g_slice_free (join_fav_account_sig_ctx, ctx);
990 account_status_changed_cb (TpAccount *account,
991 TpConnectionStatus old_status,
992 TpConnectionStatus new_status,
994 gchar *dbus_error_name,
998 join_fav_account_sig_ctx *ctx = user_data;
1000 switch (new_status) {
1001 case TP_CONNECTION_STATUS_DISCONNECTED:
1002 /* Don't wait any longer */
1006 case TP_CONNECTION_STATUS_CONNECTING:
1010 case TP_CONNECTION_STATUS_CONNECTED:
1011 /* We can join the room */
1015 join_chatroom (ctx->chatroom, ctx->timestamp);
1018 g_source_remove (ctx->timeout);
1019 g_signal_handler_disconnect (account, ctx->sig_id);
1022 #define JOIN_FAVORITE_TIMEOUT 5
1025 join_favorite_timeout_cb (gpointer data)
1027 join_fav_account_sig_ctx *ctx = data;
1029 /* stop waiting for joining the favorite room */
1030 g_signal_handler_disconnect (ctx->account, ctx->sig_id);
1035 main_window_favorite_chatroom_join (EmpathyChatroom *chatroom)
1039 account = empathy_chatroom_get_account (chatroom);
1040 if (tp_account_get_connection_status (account, NULL) !=
1041 TP_CONNECTION_STATUS_CONNECTED) {
1042 join_fav_account_sig_ctx *ctx;
1044 ctx = join_fav_account_sig_ctx_new (account, chatroom,
1045 gtk_get_current_event_time ());
1047 ctx->sig_id = g_signal_connect_data (account, "status-changed",
1048 G_CALLBACK (account_status_changed_cb), ctx,
1049 (GClosureNotify) join_fav_account_sig_ctx_free, 0);
1051 ctx->timeout = g_timeout_add_seconds (JOIN_FAVORITE_TIMEOUT,
1052 join_favorite_timeout_cb, ctx);
1056 join_chatroom (chatroom, gtk_get_current_event_time ());
1060 main_window_favorite_chatroom_menu_activate_cb (GtkMenuItem *menu_item,
1061 EmpathyChatroom *chatroom)
1063 main_window_favorite_chatroom_join (chatroom);
1067 main_window_favorite_chatroom_menu_add (EmpathyMainWindow *window,
1068 EmpathyChatroom *chatroom)
1070 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1071 GtkWidget *menu_item;
1074 if (g_object_get_data (G_OBJECT (chatroom), "menu_item")) {
1078 name = empathy_chatroom_get_name (chatroom);
1079 menu_item = gtk_menu_item_new_with_label (name);
1081 g_object_set_data (G_OBJECT (chatroom), "menu_item", menu_item);
1082 g_signal_connect (menu_item, "activate",
1083 G_CALLBACK (main_window_favorite_chatroom_menu_activate_cb),
1086 gtk_menu_shell_insert (GTK_MENU_SHELL (priv->room_menu),
1089 gtk_widget_show (menu_item);
1093 main_window_favorite_chatroom_menu_added_cb (EmpathyChatroomManager *manager,
1094 EmpathyChatroom *chatroom,
1095 EmpathyMainWindow *window)
1097 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1099 main_window_favorite_chatroom_menu_add (window, chatroom);
1100 gtk_widget_show (priv->room_separator);
1101 gtk_action_set_sensitive (priv->room_join_favorites, TRUE);
1105 main_window_favorite_chatroom_menu_removed_cb (EmpathyChatroomManager *manager,
1106 EmpathyChatroom *chatroom,
1107 EmpathyMainWindow *window)
1109 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1110 GtkWidget *menu_item;
1113 menu_item = g_object_get_data (G_OBJECT (chatroom), "menu_item");
1114 g_object_set_data (G_OBJECT (chatroom), "menu_item", NULL);
1115 gtk_widget_destroy (menu_item);
1117 chatrooms = empathy_chatroom_manager_get_chatrooms (priv->chatroom_manager, NULL);
1119 gtk_widget_show (priv->room_separator);
1121 gtk_widget_hide (priv->room_separator);
1124 gtk_action_set_sensitive (priv->room_join_favorites, chatrooms != NULL);
1125 g_list_free (chatrooms);
1129 main_window_favorite_chatroom_menu_setup (EmpathyMainWindow *window)
1131 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1132 GList *chatrooms, *l;
1135 priv->chatroom_manager = empathy_chatroom_manager_dup_singleton (NULL);
1136 chatrooms = empathy_chatroom_manager_get_chatrooms (
1137 priv->chatroom_manager, NULL);
1138 room = gtk_ui_manager_get_widget (priv->ui_manager,
1140 priv->room_menu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (room));
1141 priv->room_separator = gtk_ui_manager_get_widget (priv->ui_manager,
1142 "/menubar/room/room_separator");
1144 for (l = chatrooms; l; l = l->next) {
1145 main_window_favorite_chatroom_menu_add (window, l->data);
1149 gtk_widget_hide (priv->room_separator);
1152 gtk_action_set_sensitive (priv->room_join_favorites, chatrooms != NULL);
1154 g_signal_connect (priv->chatroom_manager, "chatroom-added",
1155 G_CALLBACK (main_window_favorite_chatroom_menu_added_cb),
1157 g_signal_connect (priv->chatroom_manager, "chatroom-removed",
1158 G_CALLBACK (main_window_favorite_chatroom_menu_removed_cb),
1161 g_list_free (chatrooms);
1165 main_window_room_join_new_cb (GtkAction *action,
1166 EmpathyMainWindow *window)
1168 empathy_new_chatroom_dialog_show (GTK_WINDOW (window));
1172 main_window_room_join_favorites_cb (GtkAction *action,
1173 EmpathyMainWindow *window)
1175 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1176 GList *chatrooms, *l;
1178 chatrooms = empathy_chatroom_manager_get_chatrooms (priv->chatroom_manager, NULL);
1179 for (l = chatrooms; l; l = l->next) {
1180 main_window_favorite_chatroom_join (l->data);
1182 g_list_free (chatrooms);
1186 main_window_room_manage_favorites_cb (GtkAction *action,
1187 EmpathyMainWindow *window)
1189 empathy_chatrooms_window_show (GTK_WINDOW (window));
1193 main_window_edit_cb (GtkAction *action,
1194 EmpathyMainWindow *window)
1196 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1199 /* FIXME: It should use the UIManager to merge the contact/group submenu */
1200 submenu = empathy_individual_view_get_individual_menu (
1201 priv->individual_view);
1206 item = GTK_MENU_ITEM (priv->edit_context);
1207 label = gtk_bin_get_child (GTK_BIN (item));
1208 gtk_label_set_text (GTK_LABEL (label), _("Contact"));
1210 gtk_widget_show (priv->edit_context);
1211 gtk_widget_show (priv->edit_context_separator);
1213 gtk_menu_item_set_submenu (item, submenu);
1218 submenu = empathy_individual_view_get_group_menu (
1219 priv->individual_view);
1224 item = GTK_MENU_ITEM (priv->edit_context);
1225 label = gtk_bin_get_child (GTK_BIN (item));
1226 gtk_label_set_text (GTK_LABEL (label), _("Group"));
1228 gtk_widget_show (priv->edit_context);
1229 gtk_widget_show (priv->edit_context_separator);
1231 gtk_menu_item_set_submenu (item, submenu);
1236 gtk_widget_hide (priv->edit_context);
1237 gtk_widget_hide (priv->edit_context_separator);
1243 main_window_edit_accounts_cb (GtkAction *action,
1244 EmpathyMainWindow *window)
1246 empathy_accounts_dialog_show_application (gdk_screen_get_default (),
1247 NULL, FALSE, FALSE);
1251 main_window_edit_personal_information_cb (GtkAction *action,
1252 EmpathyMainWindow *window)
1254 empathy_contact_personal_dialog_show (GTK_WINDOW (window));
1258 main_window_edit_preferences_cb (GtkAction *action,
1259 EmpathyMainWindow *window)
1261 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1263 if (priv->preferences == NULL) {
1264 priv->preferences = empathy_preferences_new (GTK_WINDOW (window));
1265 g_object_add_weak_pointer (G_OBJECT (priv->preferences),
1266 (gpointer) &priv->preferences);
1268 gtk_widget_show (priv->preferences);
1270 gtk_window_present (GTK_WINDOW (priv->preferences));
1275 main_window_help_about_cb (GtkAction *action,
1276 EmpathyMainWindow *window)
1278 empathy_about_dialog_new (GTK_WINDOW (window));
1282 main_window_help_debug_cb (GtkAction *action,
1283 EmpathyMainWindow *window)
1285 GdkScreen *screen = gdk_screen_get_default ();
1286 GError *error = NULL;
1287 gchar *argv[2] = { NULL, };
1291 g_return_if_fail (GDK_IS_SCREEN (screen));
1293 /* Try to run from source directory if possible */
1294 path = g_build_filename (g_getenv ("EMPATHY_SRCDIR"), "src",
1295 "empathy-debugger", NULL);
1297 if (!g_file_test (path, G_FILE_TEST_EXISTS)) {
1299 path = g_build_filename (BIN_DIR, "empathy-debugger", NULL);
1304 gdk_spawn_on_screen (screen, NULL, argv, NULL,
1305 G_SPAWN_SEARCH_PATH,
1306 NULL, NULL, NULL, &error);
1309 g_warning ("Failed to open debug window: %s", error->message);
1310 g_error_free (error);
1317 main_window_help_contents_cb (GtkAction *action,
1318 EmpathyMainWindow *window)
1320 empathy_url_show (GTK_WIDGET (window), "ghelp:empathy");
1324 main_window_throbber_button_press_event_cb (GtkWidget *throbber,
1325 GdkEventButton *event,
1326 EmpathyMainWindow *window)
1328 if (event->type != GDK_BUTTON_PRESS ||
1329 event->button != 1) {
1333 empathy_accounts_dialog_show_application (
1334 gtk_widget_get_screen (GTK_WIDGET (throbber)),
1335 NULL, FALSE, FALSE);
1341 main_window_account_removed_cb (TpAccountManager *manager,
1343 EmpathyMainWindow *window)
1345 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1348 a = tp_account_manager_get_valid_accounts (manager);
1350 gtk_action_set_sensitive (priv->view_history,
1351 g_list_length (a) > 0);
1355 /* remove errors if any */
1356 main_window_remove_error (window, account);
1360 main_window_account_validity_changed_cb (TpAccountManager *manager,
1363 EmpathyMainWindow *window)
1365 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1369 handler_id = GPOINTER_TO_UINT (g_hash_table_lookup (
1370 priv->status_changed_handlers, account));
1372 /* connect signal only if it was not connected yet */
1373 if (handler_id == 0) {
1374 handler_id = g_signal_connect (account,
1376 G_CALLBACK (main_window_connection_changed_cb),
1378 g_hash_table_insert (priv->status_changed_handlers,
1379 account, GUINT_TO_POINTER (handler_id));
1383 main_window_account_removed_cb (manager, account, window);
1387 main_window_notify_show_offline_cb (GSettings *gsettings,
1389 gpointer toggle_action)
1391 gtk_toggle_action_set_active (toggle_action,
1392 g_settings_get_boolean (gsettings, key));
1396 main_window_connection_items_setup (EmpathyMainWindow *window,
1399 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1403 const gchar *actions_connected[] = {
1408 "edit_personal_information"
1411 for (i = 0, list = NULL; i < G_N_ELEMENTS (actions_connected); i++) {
1412 action = gtk_builder_get_object (gui, actions_connected[i]);
1413 list = g_list_prepend (list, action);
1416 priv->actions_connected = list;
1420 account_manager_prepared_cb (GObject *source_object,
1421 GAsyncResult *result,
1424 GList *accounts, *j;
1425 TpAccountManager *manager = TP_ACCOUNT_MANAGER (source_object);
1426 EmpathyMainWindow *window = user_data;
1427 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1428 GError *error = NULL;
1430 if (!tp_account_manager_prepare_finish (manager, result, &error)) {
1431 DEBUG ("Failed to prepare account manager: %s", error->message);
1432 g_error_free (error);
1436 accounts = tp_account_manager_get_valid_accounts (priv->account_manager);
1437 for (j = accounts; j != NULL; j = j->next) {
1438 TpAccount *account = TP_ACCOUNT (j->data);
1441 handler_id = g_signal_connect (account, "status-changed",
1442 G_CALLBACK (main_window_connection_changed_cb),
1444 g_hash_table_insert (priv->status_changed_handlers,
1445 account, GUINT_TO_POINTER (handler_id));
1448 g_signal_connect (manager, "account-validity-changed",
1449 G_CALLBACK (main_window_account_validity_changed_cb),
1452 main_window_update_status (window);
1454 /* Disable the "Previous Conversations" menu entry if there is no account */
1455 gtk_action_set_sensitive (priv->view_history,
1456 g_list_length (accounts) > 0);
1458 g_list_free (accounts);
1462 main_window_members_changed_cb (EmpathyContactList *list,
1463 EmpathyContact *contact,
1464 EmpathyContact *actor,
1468 EmpathyMainWindow *window)
1470 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1475 if (!empathy_migrate_butterfly_logs (contact)) {
1476 g_signal_handler_disconnect (list,
1477 priv->butterfly_log_migration_members_changed_id);
1478 priv->butterfly_log_migration_members_changed_id = 0;
1483 empathy_main_window_constructor (GType type,
1484 guint n_construct_params,
1485 GObjectConstructParam *construct_params)
1487 static GObject *window = NULL;
1490 return g_object_ref (window);
1492 window = G_OBJECT_CLASS (empathy_main_window_parent_class)->constructor (
1493 type, n_construct_params, construct_params);
1495 g_object_add_weak_pointer (window, (gpointer) &window);
1501 empathy_main_window_class_init (EmpathyMainWindowClass *klass)
1503 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1505 object_class->finalize = empathy_main_window_finalize;
1506 object_class->constructor = empathy_main_window_constructor;
1508 g_type_class_add_private (object_class, sizeof (EmpathyMainWindowPriv));
1512 empathy_main_window_init (EmpathyMainWindow *window)
1514 EmpathyMainWindowPriv *priv;
1515 EmpathyContactList *list_iface;
1516 EmpathyIndividualManager *individual_manager;
1519 GtkToggleAction *show_offline_widget;
1520 GtkAction *show_map_widget;
1522 gboolean show_offline;
1525 GtkTreeModel *model;
1527 priv = window->priv = G_TYPE_INSTANCE_GET_PRIVATE (window,
1528 EMPATHY_TYPE_MAIN_WINDOW, EmpathyMainWindowPriv);
1530 priv->gsettings_ui = g_settings_new (EMPATHY_PREFS_UI_SCHEMA);
1531 priv->gsettings_contacts = g_settings_new (EMPATHY_PREFS_CONTACTS_SCHEMA);
1535 gtk_window_set_title (GTK_WINDOW (window), _("Contact List"));
1536 gtk_window_set_role (GTK_WINDOW (window), "contact_list");
1537 gtk_window_set_default_size (GTK_WINDOW (window), 225, 325);
1539 /* Set up interface */
1540 filename = empathy_file_lookup ("empathy-main-window.ui", "src");
1541 gui = empathy_builder_get_file (filename,
1542 "main_vbox", &priv->main_vbox,
1543 "errors_vbox", &priv->errors_vbox,
1544 "ui_manager", &priv->ui_manager,
1545 "view_show_offline", &show_offline_widget,
1546 "view_show_protocols", &priv->show_protocols,
1547 "view_sort_by_name", &priv->sort_by_name,
1548 "view_sort_by_status", &priv->sort_by_status,
1549 "view_normal_size_with_avatars", &priv->normal_with_avatars,
1550 "view_normal_size", &priv->normal_size,
1551 "view_compact_size", &priv->compact_size,
1552 "view_history", &priv->view_history,
1553 "view_show_map", &show_map_widget,
1554 "room_join_favorites", &priv->room_join_favorites,
1555 "presence_toolbar", &priv->presence_toolbar,
1556 "notebook", &priv->notebook,
1557 "no_entry_label", &priv->no_entry_label,
1558 "roster_scrolledwindow", &sw,
1562 gtk_container_add (GTK_CONTAINER (window), priv->main_vbox);
1563 gtk_widget_show (priv->main_vbox);
1565 g_signal_connect (window, "key-press-event",
1566 G_CALLBACK (main_window_key_press_event_cb), NULL);
1568 empathy_builder_connect (gui, window,
1569 "chat_quit", "activate", main_window_chat_quit_cb,
1570 "chat_new_message", "activate", main_window_chat_new_message_cb,
1571 "chat_new_call", "activate", main_window_chat_new_call_cb,
1572 "view_history", "activate", main_window_view_history_cb,
1573 "room_join_new", "activate", main_window_room_join_new_cb,
1574 "room_join_favorites", "activate", main_window_room_join_favorites_cb,
1575 "room_manage_favorites", "activate", main_window_room_manage_favorites_cb,
1576 "chat_add_contact", "activate", main_window_chat_add_contact_cb,
1577 "view_show_ft_manager", "activate", main_window_view_show_ft_manager,
1578 "view_show_offline", "toggled", main_window_view_show_offline_cb,
1579 "view_show_protocols", "toggled", main_window_view_show_protocols_cb,
1580 "view_sort_by_name", "changed", main_window_view_sort_contacts_cb,
1581 "view_normal_size_with_avatars", "changed", main_window_view_contacts_list_size_cb,
1582 "view_show_map", "activate", main_window_view_show_map_cb,
1583 "edit", "activate", main_window_edit_cb,
1584 "edit_accounts", "activate", main_window_edit_accounts_cb,
1585 "edit_personal_information", "activate", main_window_edit_personal_information_cb,
1586 "edit_preferences", "activate", main_window_edit_preferences_cb,
1587 "help_about", "activate", main_window_help_about_cb,
1588 "help_debug", "activate", main_window_help_debug_cb,
1589 "help_contents", "activate", main_window_help_contents_cb,
1592 /* Set up connection related widgets. */
1593 main_window_connection_items_setup (window, gui);
1595 g_object_ref (priv->ui_manager);
1596 g_object_unref (gui);
1598 #if !HAVE_LIBCHAMPLAIN
1599 gtk_action_set_visible (show_map_widget, FALSE);
1602 priv->account_manager = tp_account_manager_dup ();
1604 tp_account_manager_prepare_async (priv->account_manager, NULL,
1605 account_manager_prepared_cb, window);
1607 priv->errors = g_hash_table_new_full (g_direct_hash,
1612 priv->status_changed_handlers = g_hash_table_new_full (g_direct_hash,
1618 main_window_favorite_chatroom_menu_setup (window);
1620 priv->edit_context = gtk_ui_manager_get_widget (priv->ui_manager,
1621 "/menubar/edit/edit_context");
1622 priv->edit_context_separator = gtk_ui_manager_get_widget (
1624 "/menubar/edit/edit_context_separator");
1625 gtk_widget_hide (priv->edit_context);
1626 gtk_widget_hide (priv->edit_context_separator);
1628 /* Set up contact list. */
1629 empathy_status_presets_get_all ();
1631 /* Set up presence chooser */
1632 priv->presence_chooser = empathy_presence_chooser_new ();
1633 gtk_widget_show (priv->presence_chooser);
1634 item = gtk_tool_item_new ();
1635 gtk_widget_show (GTK_WIDGET (item));
1636 gtk_container_add (GTK_CONTAINER (item), priv->presence_chooser);
1637 gtk_tool_item_set_is_important (item, TRUE);
1638 gtk_tool_item_set_expand (item, TRUE);
1639 gtk_toolbar_insert (GTK_TOOLBAR (priv->presence_toolbar), item, -1);
1641 /* Set up the throbber */
1642 priv->throbber = gtk_spinner_new ();
1643 gtk_widget_set_size_request (priv->throbber, 16, -1);
1644 gtk_widget_set_tooltip_text (priv->throbber, _("Show and edit accounts"));
1645 gtk_widget_set_has_window (GTK_WIDGET (priv->throbber), TRUE);
1646 gtk_widget_set_events (priv->throbber, GDK_BUTTON_PRESS_MASK);
1647 g_signal_connect (priv->throbber, "button-press-event",
1648 G_CALLBACK (main_window_throbber_button_press_event_cb),
1650 gtk_widget_show (priv->throbber);
1652 item = gtk_tool_item_new ();
1653 gtk_container_set_border_width (GTK_CONTAINER (item), 6);
1654 gtk_toolbar_insert (GTK_TOOLBAR (priv->presence_toolbar), item, -1);
1655 gtk_container_add (GTK_CONTAINER (item), priv->throbber);
1656 priv->throbber_tool_item = GTK_WIDGET (item);
1658 list_iface = EMPATHY_CONTACT_LIST (empathy_contact_manager_dup_singleton ());
1659 individual_manager = empathy_individual_manager_dup_singleton ();
1660 priv->individual_store = empathy_individual_store_new (
1661 individual_manager);
1662 g_object_unref (individual_manager);
1664 priv->individual_view = empathy_individual_view_new (
1665 priv->individual_store,
1666 EMPATHY_INDIVIDUAL_VIEW_FEATURE_ALL,
1667 EMPATHY_INDIVIDUAL_FEATURE_ALL);
1669 priv->butterfly_log_migration_members_changed_id = g_signal_connect (
1670 list_iface, "members-changed",
1671 G_CALLBACK (main_window_members_changed_cb), window);
1673 g_object_unref (list_iface);
1675 gtk_widget_show (GTK_WIDGET (priv->individual_view));
1676 gtk_container_add (GTK_CONTAINER (sw),
1677 GTK_WIDGET (priv->individual_view));
1678 g_signal_connect (priv->individual_view, "row-activated",
1679 G_CALLBACK (main_window_row_activated_cb),
1682 /* Set up search bar */
1683 priv->search_bar = empathy_live_search_new (
1684 GTK_WIDGET (priv->individual_view));
1685 empathy_individual_view_set_live_search (priv->individual_view,
1686 EMPATHY_LIVE_SEARCH (priv->search_bar));
1687 gtk_box_pack_start (GTK_BOX (priv->main_vbox), priv->search_bar,
1689 g_signal_connect_swapped (window, "map",
1690 G_CALLBACK (gtk_widget_grab_focus), priv->individual_view);
1692 /* Connect to proper signals to check if contact list is empty or not */
1693 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->individual_view));
1694 g_signal_connect (model, "row-inserted",
1695 G_CALLBACK (main_window_row_inserted_cb),
1697 g_signal_connect (model, "row-deleted",
1698 G_CALLBACK (main_window_row_deleted_cb),
1701 /* Load user-defined accelerators. */
1702 main_window_accels_load ();
1704 /* Set window size. */
1705 empathy_geometry_bind (GTK_WINDOW (window), GEOMETRY_NAME);
1707 /* Enable event handling */
1708 priv->event_manager = empathy_event_manager_dup_singleton ();
1710 g_signal_connect (priv->event_manager, "event-added",
1711 G_CALLBACK (main_window_event_added_cb), window);
1712 g_signal_connect (priv->event_manager, "event-removed",
1713 G_CALLBACK (main_window_event_removed_cb), window);
1714 g_signal_connect (priv->account_manager, "account-validity-changed",
1715 G_CALLBACK (main_window_account_validity_changed_cb),
1717 g_signal_connect (priv->account_manager, "account-removed",
1718 G_CALLBACK (main_window_account_removed_cb),
1720 g_signal_connect (priv->account_manager, "account-disabled",
1721 G_CALLBACK (main_window_account_disabled_cb),
1724 l = empathy_event_manager_get_events (priv->event_manager);
1726 main_window_event_added_cb (priv->event_manager, l->data,
1731 /* Show offline ? */
1732 show_offline = g_settings_get_boolean (priv->gsettings_ui,
1733 EMPATHY_PREFS_UI_SHOW_OFFLINE);
1734 g_signal_connect (priv->gsettings_ui,
1735 "changed::" EMPATHY_PREFS_UI_SHOW_OFFLINE,
1736 G_CALLBACK (main_window_notify_show_offline_cb),
1737 show_offline_widget);
1739 gtk_toggle_action_set_active (show_offline_widget, show_offline);
1741 /* Show protocol ? */
1742 g_signal_connect (priv->gsettings_ui,
1743 "changed::" EMPATHY_PREFS_UI_SHOW_PROTOCOLS,
1744 G_CALLBACK (main_window_notify_show_protocols_cb),
1747 main_window_notify_show_protocols_cb (priv->gsettings_ui,
1748 EMPATHY_PREFS_UI_SHOW_PROTOCOLS,
1751 /* Sort by name / by status ? */
1752 g_signal_connect (priv->gsettings_contacts,
1753 "changed::" EMPATHY_PREFS_CONTACTS_SORT_CRITERIUM,
1754 G_CALLBACK (main_window_notify_sort_contact_cb),
1757 main_window_notify_sort_contact_cb (priv->gsettings_contacts,
1758 EMPATHY_PREFS_CONTACTS_SORT_CRITERIUM,
1761 /* Contacts list size */
1762 g_signal_connect (priv->gsettings_ui,
1763 "changed::" EMPATHY_PREFS_UI_COMPACT_CONTACT_LIST,
1764 G_CALLBACK (main_window_notify_contact_list_size_cb),
1766 g_signal_connect (priv->gsettings_ui,
1767 "changed::" EMPATHY_PREFS_UI_SHOW_AVATARS,
1768 G_CALLBACK (main_window_notify_contact_list_size_cb),
1771 main_window_notify_contact_list_size_cb (priv->gsettings_ui,
1772 EMPATHY_PREFS_UI_SHOW_AVATARS,
1777 empathy_main_window_dup (void)
1779 return g_object_new (EMPATHY_TYPE_MAIN_WINDOW, NULL);