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 EmpathyContactList *contact_manager;
105 EmpathyIndividualStore *individual_store;
106 EmpathyIndividualView *individual_view;
107 TpAccountManager *account_manager;
108 EmpathyChatroomManager *chatroom_manager;
109 EmpathyEventManager *event_manager;
110 guint flash_timeout_id;
114 GSettings *gsettings_ui;
115 GSettings *gsettings_contacts;
117 GtkWidget *preferences;
118 GtkWidget *main_vbox;
120 GtkWidget *throbber_tool_item;
121 GtkWidget *presence_toolbar;
122 GtkWidget *presence_chooser;
123 GtkWidget *errors_vbox;
124 GtkWidget *search_bar;
126 GtkWidget *no_entry_label;
128 GtkToggleAction *show_protocols;
129 GtkRadioAction *sort_by_name;
130 GtkRadioAction *sort_by_status;
131 GtkRadioAction *normal_with_avatars;
132 GtkRadioAction *normal_size;
133 GtkRadioAction *compact_size;
135 GtkUIManager *ui_manager;
136 GtkAction *view_history;
137 GtkAction *room_join_favorites;
138 GtkWidget *room_menu;
139 GtkWidget *room_separator;
140 GtkWidget *edit_context;
141 GtkWidget *edit_context_separator;
143 guint size_timeout_id;
146 /* stores a mapping from TpAccount to Handler ID to prevent
147 * to listen more than once to the status-changed signal */
148 GHashTable *status_changed_handlers;
150 /* Actions that are enabled when there are connected accounts */
151 GList *actions_connected;
153 /* The idle event source to migrate butterfly's logs */
154 guint butterfly_log_migration_members_changed_id;
158 main_window_flash_stop (EmpathyMainWindow *window)
160 EmpathyMainWindowPriv *priv = GET_PRIV (window);
162 if (priv->flash_timeout_id == 0) {
166 DEBUG ("Stop flashing");
167 g_source_remove (priv->flash_timeout_id);
168 priv->flash_timeout_id = 0;
169 priv->flash_on = FALSE;
175 EmpathyMainWindow *window;
179 main_window_flash_foreach (GtkTreeModel *model,
184 FlashForeachData *data = (FlashForeachData *) user_data;
185 FolksIndividual *individual;
186 EmpathyContact *contact;
187 const gchar *icon_name;
188 GtkTreePath *parent_path = NULL;
189 GtkTreeIter parent_iter;
190 GdkPixbuf *pixbuf = NULL;
192 gtk_tree_model_get (model, iter,
193 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL,
197 if (individual == NULL)
200 contact = empathy_contact_dup_from_folks_individual (individual);
201 if (contact != data->event->contact) {
202 tp_clear_object (&contact);
207 icon_name = data->event->icon_name;
208 pixbuf = empathy_pixbuf_from_icon_name (icon_name, GTK_ICON_SIZE_MENU);
210 pixbuf = empathy_individual_store_get_individual_status_icon (
211 GET_PRIV (data->window)->individual_store,
215 gtk_tree_store_set (GTK_TREE_STORE (model), iter,
216 EMPATHY_INDIVIDUAL_STORE_COL_ICON_STATUS, pixbuf,
219 /* To make sure the parent is shown correctly, we emit
220 * the row-changed signal on the parent so it prompts
221 * it to be refreshed by the filter func.
223 if (gtk_tree_model_iter_parent (model, &parent_iter, iter)) {
224 parent_path = gtk_tree_model_get_path (model, &parent_iter);
227 gtk_tree_model_row_changed (model, parent_path, &parent_iter);
228 gtk_tree_path_free (parent_path);
231 g_object_unref (individual);
232 tp_clear_object (&contact);
238 main_window_flash_cb (EmpathyMainWindow *window)
240 EmpathyMainWindowPriv *priv = GET_PRIV (window);
243 gboolean found_event = FALSE;
244 FlashForeachData data;
246 priv->flash_on = !priv->flash_on;
247 data.on = priv->flash_on;
248 model = GTK_TREE_MODEL (priv->individual_store);
250 events = empathy_event_manager_get_events (priv->event_manager);
251 for (l = events; l; l = l->next) {
252 data.event = l->data;
253 data.window = window;
254 if (!data.event->contact || !data.event->must_ack) {
259 gtk_tree_model_foreach (model,
260 main_window_flash_foreach,
265 main_window_flash_stop (window);
272 main_window_flash_start (EmpathyMainWindow *window)
274 EmpathyMainWindowPriv *priv = GET_PRIV (window);
276 if (priv->flash_timeout_id != 0) {
280 DEBUG ("Start flashing");
281 priv->flash_timeout_id = g_timeout_add (FLASH_TIMEOUT,
282 (GSourceFunc) main_window_flash_cb,
284 main_window_flash_cb (window);
288 main_window_event_added_cb (EmpathyEventManager *manager,
290 EmpathyMainWindow *window)
292 if (event->contact) {
293 main_window_flash_start (window);
298 main_window_event_removed_cb (EmpathyEventManager *manager,
300 EmpathyMainWindow *window)
302 EmpathyMainWindowPriv *priv = GET_PRIV (window);
303 FlashForeachData data;
305 if (!event->contact) {
311 data.window = window;
312 gtk_tree_model_foreach (GTK_TREE_MODEL (priv->individual_store),
313 main_window_flash_foreach,
318 main_window_row_activated_cb (EmpathyContactListView *view,
320 GtkTreeViewColumn *col,
321 EmpathyMainWindow *window)
323 EmpathyMainWindowPriv *priv = GET_PRIV (window);
324 EmpathyContact *contact = NULL;
325 FolksIndividual *individual;
330 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->individual_view));
331 gtk_tree_model_get_iter (model, &iter, path);
333 gtk_tree_model_get (model, &iter,
334 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL,
338 if (individual != NULL) {
339 contact = empathy_contact_dup_from_folks_individual (individual);
346 /* If the contact has an event activate it, otherwise the
347 * default handler of row-activated will be called. */
348 events = empathy_event_manager_get_events (priv->event_manager);
349 for (l = events; l; l = l->next) {
350 EmpathyEvent *event = l->data;
352 if (event->contact == contact) {
353 DEBUG ("Activate event");
354 empathy_event_activate (event);
356 /* We don't want the default handler of this signal
357 * (e.g. open a chat) */
358 g_signal_stop_emission_by_name (view, "row-activated");
363 g_object_unref (contact);
365 tp_clear_object (&individual);
369 main_window_row_deleted_cb (GtkTreeModel *model,
371 EmpathyMainWindow *window)
373 EmpathyMainWindowPriv *priv = GET_PRIV (window);
374 GtkTreeIter help_iter;
376 if (!gtk_tree_model_get_iter_first (model, &help_iter)) {
379 if (empathy_individual_view_is_searching (
380 priv->individual_view)) {
383 tmp = g_strdup_printf ("<b><span size='xx-large'>%s</span></b>",
384 _("No match found"));
386 gtk_label_set_markup (GTK_LABEL (priv->no_entry_label), tmp);
389 gtk_label_set_ellipsize (GTK_LABEL (priv->no_entry_label),
390 PANGO_ELLIPSIZE_END);
392 gtk_notebook_set_current_page (
393 GTK_NOTEBOOK (priv->notebook), PAGE_NO_MATCH);
399 main_window_row_inserted_cb (GtkTreeModel *model,
402 EmpathyMainWindow *window)
404 EmpathyMainWindowPriv *priv = GET_PRIV (window);
408 gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook),
410 gtk_widget_grab_focus (GTK_WIDGET (priv->individual_view));
415 main_window_remove_error (EmpathyMainWindow *window,
418 EmpathyMainWindowPriv *priv = GET_PRIV (window);
419 GtkWidget *error_widget;
421 error_widget = g_hash_table_lookup (priv->errors, account);
422 if (error_widget != NULL) {
423 gtk_widget_destroy (error_widget);
424 g_hash_table_remove (priv->errors, account);
429 main_window_account_disabled_cb (TpAccountManager *manager,
431 EmpathyMainWindow *window)
433 main_window_remove_error (window, account);
437 main_window_error_retry_clicked_cb (GtkButton *button,
438 EmpathyMainWindow *window)
442 account = g_object_get_data (G_OBJECT (button), "account");
443 tp_account_reconnect_async (account, NULL, NULL);
445 main_window_remove_error (window, account);
449 main_window_error_edit_clicked_cb (GtkButton *button,
450 EmpathyMainWindow *window)
454 account = g_object_get_data (G_OBJECT (button), "account");
456 empathy_accounts_dialog_show_application (
457 gtk_widget_get_screen (GTK_WIDGET (button)),
458 account, FALSE, FALSE);
460 main_window_remove_error (window, account);
464 main_window_error_close_clicked_cb (GtkButton *button,
465 EmpathyMainWindow *window)
469 account = g_object_get_data (G_OBJECT (button), "account");
470 main_window_remove_error (window, account);
474 main_window_error_display (EmpathyMainWindow *window,
477 EmpathyMainWindowPriv *priv = GET_PRIV (window);
479 GtkWidget *content_area;
482 GtkWidget *retry_button;
483 GtkWidget *edit_button;
484 GtkWidget *close_button;
485 GtkWidget *action_area;
486 GtkWidget *action_table;
488 const gchar *icon_name;
489 const gchar *error_message;
490 gboolean user_requested;
493 empathy_account_get_error_message (account, &user_requested);
495 if (user_requested) {
499 str = g_markup_printf_escaped ("<b>%s</b>\n%s",
500 tp_account_get_display_name (account),
503 info_bar = g_hash_table_lookup (priv->errors, account);
505 label = g_object_get_data (G_OBJECT (info_bar), "label");
507 /* Just set the latest error and return */
508 gtk_label_set_markup (GTK_LABEL (label), str);
514 info_bar = gtk_info_bar_new ();
515 gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_ERROR);
517 gtk_widget_set_no_show_all (info_bar, TRUE);
518 gtk_box_pack_start (GTK_BOX (priv->errors_vbox), info_bar, FALSE, TRUE, 0);
519 gtk_widget_show (info_bar);
521 icon_name = tp_account_get_icon_name (account);
522 image = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_SMALL_TOOLBAR);
523 gtk_widget_show (image);
525 label = gtk_label_new (str);
526 gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
527 gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_END);
528 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
529 gtk_widget_show (label);
532 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
533 gtk_box_pack_start (GTK_BOX (content_area), image, FALSE, FALSE, 0);
534 gtk_box_pack_start (GTK_BOX (content_area), label, TRUE, TRUE, 0);
536 image = gtk_image_new_from_stock (GTK_STOCK_REFRESH, GTK_ICON_SIZE_BUTTON);
537 retry_button = gtk_button_new ();
538 gtk_button_set_image (GTK_BUTTON (retry_button), image);
539 gtk_widget_set_tooltip_text (retry_button, _("Reconnect"));
540 gtk_widget_show (retry_button);
542 image = gtk_image_new_from_stock (GTK_STOCK_EDIT, GTK_ICON_SIZE_BUTTON);
543 edit_button = gtk_button_new ();
544 gtk_button_set_image (GTK_BUTTON (edit_button), image);
545 gtk_widget_set_tooltip_text (edit_button, _("Edit Account"));
546 gtk_widget_show (edit_button);
548 image = gtk_image_new_from_stock (GTK_STOCK_CLOSE, GTK_ICON_SIZE_BUTTON);
549 close_button = gtk_button_new ();
550 gtk_button_set_image (GTK_BUTTON (close_button), image);
551 gtk_widget_set_tooltip_text (close_button, _("Close"));
552 gtk_widget_show (close_button);
554 action_table = gtk_table_new (1, 3, FALSE);
555 gtk_table_set_col_spacings (GTK_TABLE (action_table), 2);
556 gtk_widget_show (action_table);
558 action_area = gtk_info_bar_get_action_area (GTK_INFO_BAR (info_bar));
559 gtk_box_pack_start (GTK_BOX (action_area), action_table, FALSE, FALSE, 0);
561 gtk_table_attach (GTK_TABLE (action_table), retry_button, 0, 1, 0, 1,
562 (GtkAttachOptions) (GTK_SHRINK),
563 (GtkAttachOptions) (GTK_SHRINK), 0, 0);
564 gtk_table_attach (GTK_TABLE (action_table), edit_button, 1, 2, 0, 1,
565 (GtkAttachOptions) (GTK_SHRINK),
566 (GtkAttachOptions) (GTK_SHRINK), 0, 0);
567 gtk_table_attach (GTK_TABLE (action_table), close_button, 2, 3, 0, 1,
568 (GtkAttachOptions) (GTK_SHRINK),
569 (GtkAttachOptions) (GTK_SHRINK), 0, 0);
571 g_object_set_data (G_OBJECT (info_bar), "label", label);
572 g_object_set_data_full (G_OBJECT (info_bar),
573 "account", g_object_ref (account),
575 g_object_set_data_full (G_OBJECT (edit_button),
576 "account", g_object_ref (account),
578 g_object_set_data_full (G_OBJECT (close_button),
579 "account", g_object_ref (account),
581 g_object_set_data_full (G_OBJECT (retry_button),
582 "account", g_object_ref (account),
585 g_signal_connect (edit_button, "clicked",
586 G_CALLBACK (main_window_error_edit_clicked_cb),
588 g_signal_connect (close_button, "clicked",
589 G_CALLBACK (main_window_error_close_clicked_cb),
591 g_signal_connect (retry_button, "clicked",
592 G_CALLBACK (main_window_error_retry_clicked_cb),
595 gtk_widget_show (priv->errors_vbox);
597 g_hash_table_insert (priv->errors, g_object_ref (account), info_bar);
601 main_window_update_status (EmpathyMainWindow *window)
603 EmpathyMainWindowPriv *priv = GET_PRIV (window);
604 gboolean connected, connecting;
607 connected = empathy_account_manager_get_accounts_connected (&connecting);
609 /* Update the spinner state */
611 gtk_spinner_start (GTK_SPINNER (priv->throbber));
612 gtk_widget_show (priv->throbber_tool_item);
614 gtk_spinner_stop (GTK_SPINNER (priv->throbber));
615 gtk_widget_hide (priv->throbber_tool_item);
618 /* Update widgets sensibility */
619 for (l = priv->actions_connected; l; l = l->next) {
620 gtk_action_set_sensitive (l->data, connected);
625 main_window_connection_changed_cb (TpAccount *account,
629 gchar *dbus_error_name,
631 EmpathyMainWindow *window)
633 main_window_update_status (window);
635 if (current == TP_CONNECTION_STATUS_DISCONNECTED &&
636 reason != TP_CONNECTION_STATUS_REASON_REQUESTED) {
637 main_window_error_display (window, account);
640 if (current == TP_CONNECTION_STATUS_DISCONNECTED) {
641 empathy_sound_play (GTK_WIDGET (window),
642 EMPATHY_SOUND_ACCOUNT_DISCONNECTED);
645 if (current == TP_CONNECTION_STATUS_CONNECTED) {
646 empathy_sound_play (GTK_WIDGET (window),
647 EMPATHY_SOUND_ACCOUNT_CONNECTED);
649 /* Account connected without error, remove error message if any */
650 main_window_remove_error (window, account);
655 main_window_accels_load (void)
659 filename = g_build_filename (g_get_user_config_dir (), PACKAGE_NAME, ACCELS_FILENAME, NULL);
660 if (g_file_test (filename, G_FILE_TEST_EXISTS)) {
661 DEBUG ("Loading from:'%s'", filename);
662 gtk_accel_map_load (filename);
669 main_window_accels_save (void)
672 gchar *file_with_path;
674 dir = g_build_filename (g_get_user_config_dir (), PACKAGE_NAME, NULL);
675 g_mkdir_with_parents (dir, S_IRUSR | S_IWUSR | S_IXUSR);
676 file_with_path = g_build_filename (dir, ACCELS_FILENAME, NULL);
679 DEBUG ("Saving to:'%s'", file_with_path);
680 gtk_accel_map_save (file_with_path);
682 g_free (file_with_path);
686 empathy_main_window_finalize (GObject *window)
688 EmpathyMainWindowPriv *priv = GET_PRIV (window);
692 /* Save user-defined accelerators. */
693 main_window_accels_save ();
695 g_list_free (priv->actions_connected);
697 g_object_unref (priv->account_manager);
698 g_object_unref (priv->individual_store);
699 g_object_unref (priv->contact_manager);
700 g_hash_table_destroy (priv->errors);
702 /* disconnect all handlers of status-changed signal */
703 g_hash_table_iter_init (&iter, priv->status_changed_handlers);
704 while (g_hash_table_iter_next (&iter, &key, &value))
705 g_signal_handler_disconnect (TP_ACCOUNT (key),
706 GPOINTER_TO_UINT (value));
708 g_hash_table_destroy (priv->status_changed_handlers);
710 g_signal_handlers_disconnect_by_func (priv->event_manager,
711 main_window_event_added_cb,
713 g_signal_handlers_disconnect_by_func (priv->event_manager,
714 main_window_event_removed_cb,
716 g_object_unref (priv->event_manager);
717 g_object_unref (priv->ui_manager);
718 g_object_unref (priv->chatroom_manager);
720 g_object_unref (priv->gsettings_ui);
721 g_object_unref (priv->gsettings_contacts);
723 G_OBJECT_CLASS (empathy_main_window_parent_class)->finalize (window);
727 main_window_key_press_event_cb (GtkWidget *window,
731 EmpathyChatManager *chat_manager;
733 if (event->keyval == GDK_KEY_T
734 && event->state & GDK_SHIFT_MASK
735 && event->state & GDK_CONTROL_MASK) {
736 chat_manager = empathy_chat_manager_dup_singleton ();
737 empathy_chat_manager_undo_closed_chat (chat_manager);
738 g_object_unref (chat_manager);
744 main_window_chat_quit_cb (GtkAction *action,
745 EmpathyMainWindow *window)
751 main_window_view_history_cb (GtkAction *action,
752 EmpathyMainWindow *window)
754 empathy_log_window_show (NULL, NULL, FALSE, GTK_WINDOW (window));
758 main_window_chat_new_message_cb (GtkAction *action,
759 EmpathyMainWindow *window)
761 empathy_new_message_dialog_show (GTK_WINDOW (window));
765 main_window_chat_new_call_cb (GtkAction *action,
766 EmpathyMainWindow *window)
768 empathy_new_call_dialog_show (GTK_WINDOW (window));
772 main_window_chat_add_contact_cb (GtkAction *action,
773 EmpathyMainWindow *window)
775 empathy_new_individual_dialog_show (GTK_WINDOW (window));
779 main_window_view_show_ft_manager (GtkAction *action,
780 EmpathyMainWindow *window)
782 empathy_ft_manager_show ();
786 main_window_view_show_offline_cb (GtkToggleAction *action,
787 EmpathyMainWindow *window)
789 EmpathyMainWindowPriv *priv = GET_PRIV (window);
792 current = gtk_toggle_action_get_active (action);
793 g_settings_set_boolean (priv->gsettings_ui,
794 EMPATHY_PREFS_UI_SHOW_OFFLINE,
797 empathy_individual_view_set_show_offline (priv->individual_view,
802 main_window_notify_sort_contact_cb (GSettings *gsettings,
804 EmpathyMainWindow *window)
806 EmpathyMainWindowPriv *priv = GET_PRIV (window);
809 str = g_settings_get_string (gsettings, key);
813 GEnumClass *enum_class;
814 GEnumValue *enum_value;
816 type = empathy_individual_store_sort_get_type ();
817 enum_class = G_ENUM_CLASS (g_type_class_peek (type));
818 enum_value = g_enum_get_value_by_nick (enum_class, str);
820 /* By changing the value of the GtkRadioAction,
821 it emits a signal that calls main_window_view_sort_contacts_cb
822 which updates the contacts list */
823 gtk_radio_action_set_current_value (priv->sort_by_name,
826 g_warning ("Wrong value for sort_criterium configuration : %s", str);
833 main_window_view_sort_contacts_cb (GtkRadioAction *action,
834 GtkRadioAction *current,
835 EmpathyMainWindow *window)
837 EmpathyMainWindowPriv *priv = GET_PRIV (window);
838 EmpathyContactListStoreSort value;
841 GEnumClass *enum_class;
842 GEnumValue *enum_value;
844 value = gtk_radio_action_get_current_value (action);
845 group = gtk_radio_action_get_group (action);
847 /* Get string from index */
848 type = empathy_individual_store_sort_get_type ();
849 enum_class = G_ENUM_CLASS (g_type_class_peek (type));
850 enum_value = g_enum_get_value (enum_class, g_slist_index (group, current));
853 g_warning ("No GEnumValue for EmpathyContactListSort with GtkRadioAction index:%d",
854 g_slist_index (group, action));
856 g_settings_set_string (priv->gsettings_contacts,
857 EMPATHY_PREFS_CONTACTS_SORT_CRITERIUM,
858 enum_value->value_nick);
860 empathy_individual_store_set_sort_criterium (priv->individual_store,
865 main_window_view_show_protocols_cb (GtkToggleAction *action,
866 EmpathyMainWindow *window)
868 EmpathyMainWindowPriv *priv = GET_PRIV (window);
871 value = gtk_toggle_action_get_active (action);
873 g_settings_set_boolean (priv->gsettings_ui,
874 EMPATHY_PREFS_UI_SHOW_PROTOCOLS,
876 empathy_individual_store_set_show_protocols (priv->individual_store,
880 /* Matches GtkRadioAction values set in empathy-main-window.ui */
881 #define CONTACT_LIST_NORMAL_SIZE_WITH_AVATARS 0
882 #define CONTACT_LIST_NORMAL_SIZE 1
883 #define CONTACT_LIST_COMPACT_SIZE 2
886 main_window_view_contacts_list_size_cb (GtkRadioAction *action,
887 GtkRadioAction *current,
888 EmpathyMainWindow *window)
890 EmpathyMainWindowPriv *priv = GET_PRIV (window);
891 GSettings *gsettings_ui;
894 value = gtk_radio_action_get_current_value (action);
895 /* create a new GSettings, so we can delay the setting until both
897 gsettings_ui = g_settings_new (EMPATHY_PREFS_UI_SCHEMA);
899 DEBUG ("radio button toggled, value = %i", value);
901 g_settings_delay (gsettings_ui);
902 g_settings_set_boolean (gsettings_ui,
903 EMPATHY_PREFS_UI_SHOW_AVATARS,
904 value == CONTACT_LIST_NORMAL_SIZE_WITH_AVATARS);
906 g_settings_set_boolean (gsettings_ui,
907 EMPATHY_PREFS_UI_COMPACT_CONTACT_LIST,
908 value == CONTACT_LIST_COMPACT_SIZE);
909 g_settings_apply (gsettings_ui);
911 /* FIXME: these enums probably have the wrong namespace */
912 empathy_individual_store_set_show_avatars (priv->individual_store,
913 value == CONTACT_LIST_NORMAL_SIZE_WITH_AVATARS);
914 empathy_individual_store_set_is_compact (priv->individual_store,
915 value == CONTACT_LIST_COMPACT_SIZE);
917 g_object_unref (gsettings_ui);
920 static void main_window_notify_show_protocols_cb (GSettings *gsettings,
922 EmpathyMainWindow *window)
924 EmpathyMainWindowPriv *priv = GET_PRIV (window);
926 gtk_toggle_action_set_active (priv->show_protocols,
927 g_settings_get_boolean (gsettings,
928 EMPATHY_PREFS_UI_SHOW_PROTOCOLS));
933 main_window_notify_contact_list_size_cb (GSettings *gsettings,
935 EmpathyMainWindow *window)
937 EmpathyMainWindowPriv *priv = GET_PRIV (window);
940 if (g_settings_get_boolean (gsettings,
941 EMPATHY_PREFS_UI_COMPACT_CONTACT_LIST)) {
942 value = CONTACT_LIST_COMPACT_SIZE;
943 } else if (g_settings_get_boolean (gsettings,
944 EMPATHY_PREFS_UI_SHOW_AVATARS)) {
945 value = CONTACT_LIST_NORMAL_SIZE_WITH_AVATARS;
947 value = CONTACT_LIST_NORMAL_SIZE;
950 DEBUG ("setting changed, value = %i", value);
952 /* By changing the value of the GtkRadioAction,
953 it emits a signal that calls main_window_view_contacts_list_size_cb
954 which updates the contacts list */
955 gtk_radio_action_set_current_value (priv->normal_with_avatars, value);
959 main_window_edit_search_contacts_cb (GtkCheckMenuItem *item,
960 EmpathyMainWindow *window)
962 EmpathyMainWindowPriv *priv = GET_PRIV (window);
964 empathy_individual_view_start_search (priv->individual_view);
968 main_window_view_show_map_cb (GtkCheckMenuItem *item,
969 EmpathyMainWindow *window)
971 #ifdef HAVE_LIBCHAMPLAIN
972 empathy_map_view_show ();
977 join_chatroom (EmpathyChatroom *chatroom,
983 account = empathy_chatroom_get_account (chatroom);
984 room = empathy_chatroom_get_room (chatroom);
986 DEBUG ("Requesting channel for '%s'", room);
987 empathy_dispatcher_join_muc (account, room, timestamp);
993 EmpathyChatroom *chatroom;
997 } join_fav_account_sig_ctx;
999 static join_fav_account_sig_ctx *
1000 join_fav_account_sig_ctx_new (TpAccount *account,
1001 EmpathyChatroom *chatroom,
1004 join_fav_account_sig_ctx *ctx = g_slice_new0 (
1005 join_fav_account_sig_ctx);
1007 ctx->account = g_object_ref (account);
1008 ctx->chatroom = g_object_ref (chatroom);
1009 ctx->timestamp = timestamp;
1014 join_fav_account_sig_ctx_free (join_fav_account_sig_ctx *ctx)
1016 g_object_unref (ctx->account);
1017 g_object_unref (ctx->chatroom);
1018 g_slice_free (join_fav_account_sig_ctx, ctx);
1022 account_status_changed_cb (TpAccount *account,
1023 TpConnectionStatus old_status,
1024 TpConnectionStatus new_status,
1026 gchar *dbus_error_name,
1027 GHashTable *details,
1030 join_fav_account_sig_ctx *ctx = user_data;
1032 switch (new_status) {
1033 case TP_CONNECTION_STATUS_DISCONNECTED:
1034 /* Don't wait any longer */
1038 case TP_CONNECTION_STATUS_CONNECTING:
1042 case TP_CONNECTION_STATUS_CONNECTED:
1043 /* We can join the room */
1047 g_assert_not_reached ();
1050 join_chatroom (ctx->chatroom, ctx->timestamp);
1053 g_source_remove (ctx->timeout);
1054 g_signal_handler_disconnect (account, ctx->sig_id);
1057 #define JOIN_FAVORITE_TIMEOUT 5
1060 join_favorite_timeout_cb (gpointer data)
1062 join_fav_account_sig_ctx *ctx = data;
1064 /* stop waiting for joining the favorite room */
1065 g_signal_handler_disconnect (ctx->account, ctx->sig_id);
1070 main_window_favorite_chatroom_join (EmpathyChatroom *chatroom)
1074 account = empathy_chatroom_get_account (chatroom);
1075 if (tp_account_get_connection_status (account, NULL) !=
1076 TP_CONNECTION_STATUS_CONNECTED) {
1077 join_fav_account_sig_ctx *ctx;
1079 ctx = join_fav_account_sig_ctx_new (account, chatroom,
1080 gtk_get_current_event_time ());
1082 ctx->sig_id = g_signal_connect_data (account, "status-changed",
1083 G_CALLBACK (account_status_changed_cb), ctx,
1084 (GClosureNotify) join_fav_account_sig_ctx_free, 0);
1086 ctx->timeout = g_timeout_add_seconds (JOIN_FAVORITE_TIMEOUT,
1087 join_favorite_timeout_cb, ctx);
1091 join_chatroom (chatroom, gtk_get_current_event_time ());
1095 main_window_favorite_chatroom_menu_activate_cb (GtkMenuItem *menu_item,
1096 EmpathyChatroom *chatroom)
1098 main_window_favorite_chatroom_join (chatroom);
1102 main_window_favorite_chatroom_menu_add (EmpathyMainWindow *window,
1103 EmpathyChatroom *chatroom)
1105 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1106 GtkWidget *menu_item;
1109 if (g_object_get_data (G_OBJECT (chatroom), "menu_item")) {
1113 name = empathy_chatroom_get_name (chatroom);
1114 menu_item = gtk_menu_item_new_with_label (name);
1116 g_object_set_data (G_OBJECT (chatroom), "menu_item", menu_item);
1117 g_signal_connect (menu_item, "activate",
1118 G_CALLBACK (main_window_favorite_chatroom_menu_activate_cb),
1121 gtk_menu_shell_insert (GTK_MENU_SHELL (priv->room_menu),
1124 gtk_widget_show (menu_item);
1128 main_window_favorite_chatroom_menu_added_cb (EmpathyChatroomManager *manager,
1129 EmpathyChatroom *chatroom,
1130 EmpathyMainWindow *window)
1132 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1134 main_window_favorite_chatroom_menu_add (window, chatroom);
1135 gtk_widget_show (priv->room_separator);
1136 gtk_action_set_sensitive (priv->room_join_favorites, TRUE);
1140 main_window_favorite_chatroom_menu_removed_cb (EmpathyChatroomManager *manager,
1141 EmpathyChatroom *chatroom,
1142 EmpathyMainWindow *window)
1144 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1145 GtkWidget *menu_item;
1148 menu_item = g_object_get_data (G_OBJECT (chatroom), "menu_item");
1149 g_object_set_data (G_OBJECT (chatroom), "menu_item", NULL);
1150 gtk_widget_destroy (menu_item);
1152 chatrooms = empathy_chatroom_manager_get_chatrooms (priv->chatroom_manager, NULL);
1154 gtk_widget_show (priv->room_separator);
1156 gtk_widget_hide (priv->room_separator);
1159 gtk_action_set_sensitive (priv->room_join_favorites, chatrooms != NULL);
1160 g_list_free (chatrooms);
1164 main_window_favorite_chatroom_menu_setup (EmpathyMainWindow *window)
1166 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1167 GList *chatrooms, *l;
1170 priv->chatroom_manager = empathy_chatroom_manager_dup_singleton (NULL);
1171 chatrooms = empathy_chatroom_manager_get_chatrooms (
1172 priv->chatroom_manager, NULL);
1173 room = gtk_ui_manager_get_widget (priv->ui_manager,
1175 priv->room_menu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (room));
1176 priv->room_separator = gtk_ui_manager_get_widget (priv->ui_manager,
1177 "/menubar/room/room_separator");
1179 for (l = chatrooms; l; l = l->next) {
1180 main_window_favorite_chatroom_menu_add (window, l->data);
1184 gtk_widget_hide (priv->room_separator);
1187 gtk_action_set_sensitive (priv->room_join_favorites, chatrooms != NULL);
1189 g_signal_connect (priv->chatroom_manager, "chatroom-added",
1190 G_CALLBACK (main_window_favorite_chatroom_menu_added_cb),
1192 g_signal_connect (priv->chatroom_manager, "chatroom-removed",
1193 G_CALLBACK (main_window_favorite_chatroom_menu_removed_cb),
1196 g_list_free (chatrooms);
1200 main_window_room_join_new_cb (GtkAction *action,
1201 EmpathyMainWindow *window)
1203 empathy_new_chatroom_dialog_show (GTK_WINDOW (window));
1207 main_window_room_join_favorites_cb (GtkAction *action,
1208 EmpathyMainWindow *window)
1210 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1211 GList *chatrooms, *l;
1213 chatrooms = empathy_chatroom_manager_get_chatrooms (priv->chatroom_manager, NULL);
1214 for (l = chatrooms; l; l = l->next) {
1215 main_window_favorite_chatroom_join (l->data);
1217 g_list_free (chatrooms);
1221 main_window_room_manage_favorites_cb (GtkAction *action,
1222 EmpathyMainWindow *window)
1224 empathy_chatrooms_window_show (GTK_WINDOW (window));
1228 main_window_edit_cb (GtkAction *action,
1229 EmpathyMainWindow *window)
1231 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1234 /* FIXME: It should use the UIManager to merge the contact/group submenu */
1235 submenu = empathy_individual_view_get_individual_menu (
1236 priv->individual_view);
1241 item = GTK_MENU_ITEM (priv->edit_context);
1242 label = gtk_bin_get_child (GTK_BIN (item));
1243 gtk_label_set_text (GTK_LABEL (label), _("Contact"));
1245 gtk_widget_show (priv->edit_context);
1246 gtk_widget_show (priv->edit_context_separator);
1248 gtk_menu_item_set_submenu (item, submenu);
1253 submenu = empathy_individual_view_get_group_menu (
1254 priv->individual_view);
1259 item = GTK_MENU_ITEM (priv->edit_context);
1260 label = gtk_bin_get_child (GTK_BIN (item));
1261 gtk_label_set_text (GTK_LABEL (label), _("Group"));
1263 gtk_widget_show (priv->edit_context);
1264 gtk_widget_show (priv->edit_context_separator);
1266 gtk_menu_item_set_submenu (item, submenu);
1271 gtk_widget_hide (priv->edit_context);
1272 gtk_widget_hide (priv->edit_context_separator);
1278 main_window_edit_accounts_cb (GtkAction *action,
1279 EmpathyMainWindow *window)
1281 empathy_accounts_dialog_show_application (gdk_screen_get_default (),
1282 NULL, FALSE, FALSE);
1286 main_window_edit_personal_information_cb (GtkAction *action,
1287 EmpathyMainWindow *window)
1289 empathy_contact_personal_dialog_show (GTK_WINDOW (window));
1293 main_window_edit_preferences_cb (GtkAction *action,
1294 EmpathyMainWindow *window)
1296 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1298 if (priv->preferences == NULL) {
1299 priv->preferences = empathy_preferences_new (GTK_WINDOW (window));
1300 g_object_add_weak_pointer (G_OBJECT (priv->preferences),
1301 (gpointer) &priv->preferences);
1303 gtk_widget_show (priv->preferences);
1305 gtk_window_present (GTK_WINDOW (priv->preferences));
1310 main_window_help_about_cb (GtkAction *action,
1311 EmpathyMainWindow *window)
1313 empathy_about_dialog_new (GTK_WINDOW (window));
1317 main_window_help_debug_cb (GtkAction *action,
1318 EmpathyMainWindow *window)
1320 GdkScreen *screen = gdk_screen_get_default ();
1321 GError *error = NULL;
1322 gchar *argv[2] = { NULL, };
1326 g_return_if_fail (GDK_IS_SCREEN (screen));
1328 /* Try to run from source directory if possible */
1329 path = g_build_filename (g_getenv ("EMPATHY_SRCDIR"), "src",
1330 "empathy-debugger", NULL);
1332 if (!g_file_test (path, G_FILE_TEST_EXISTS)) {
1334 path = g_build_filename (BIN_DIR, "empathy-debugger", NULL);
1339 gdk_spawn_on_screen (screen, NULL, argv, NULL,
1340 G_SPAWN_SEARCH_PATH,
1341 NULL, NULL, NULL, &error);
1344 g_warning ("Failed to open debug window: %s", error->message);
1345 g_error_free (error);
1352 main_window_help_contents_cb (GtkAction *action,
1353 EmpathyMainWindow *window)
1355 empathy_url_show (GTK_WIDGET (window), "ghelp:empathy");
1359 main_window_throbber_button_press_event_cb (GtkWidget *throbber,
1360 GdkEventButton *event,
1361 EmpathyMainWindow *window)
1363 if (event->type != GDK_BUTTON_PRESS ||
1364 event->button != 1) {
1368 empathy_accounts_dialog_show_application (
1369 gtk_widget_get_screen (GTK_WIDGET (throbber)),
1370 NULL, FALSE, FALSE);
1376 main_window_account_removed_cb (TpAccountManager *manager,
1378 EmpathyMainWindow *window)
1380 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1383 a = tp_account_manager_get_valid_accounts (manager);
1385 gtk_action_set_sensitive (priv->view_history,
1386 g_list_length (a) > 0);
1390 /* remove errors if any */
1391 main_window_remove_error (window, account);
1395 main_window_account_validity_changed_cb (TpAccountManager *manager,
1398 EmpathyMainWindow *window)
1400 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1404 handler_id = GPOINTER_TO_UINT (g_hash_table_lookup (
1405 priv->status_changed_handlers, account));
1407 /* connect signal only if it was not connected yet */
1408 if (handler_id == 0) {
1409 handler_id = g_signal_connect (account,
1411 G_CALLBACK (main_window_connection_changed_cb),
1413 g_hash_table_insert (priv->status_changed_handlers,
1414 account, GUINT_TO_POINTER (handler_id));
1418 main_window_account_removed_cb (manager, account, window);
1422 main_window_notify_show_offline_cb (GSettings *gsettings,
1424 gpointer toggle_action)
1426 gtk_toggle_action_set_active (toggle_action,
1427 g_settings_get_boolean (gsettings, key));
1431 main_window_connection_items_setup (EmpathyMainWindow *window,
1434 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1438 const gchar *actions_connected[] = {
1443 "edit_personal_information"
1446 for (i = 0, list = NULL; i < G_N_ELEMENTS (actions_connected); i++) {
1447 action = gtk_builder_get_object (gui, actions_connected[i]);
1448 list = g_list_prepend (list, action);
1451 priv->actions_connected = list;
1455 account_manager_prepared_cb (GObject *source_object,
1456 GAsyncResult *result,
1459 GList *accounts, *j;
1460 TpAccountManager *manager = TP_ACCOUNT_MANAGER (source_object);
1461 EmpathyMainWindow *window = user_data;
1462 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1463 GError *error = NULL;
1465 if (!tp_account_manager_prepare_finish (manager, result, &error)) {
1466 DEBUG ("Failed to prepare account manager: %s", error->message);
1467 g_error_free (error);
1471 accounts = tp_account_manager_get_valid_accounts (priv->account_manager);
1472 for (j = accounts; j != NULL; j = j->next) {
1473 TpAccount *account = TP_ACCOUNT (j->data);
1476 handler_id = g_signal_connect (account, "status-changed",
1477 G_CALLBACK (main_window_connection_changed_cb),
1479 g_hash_table_insert (priv->status_changed_handlers,
1480 account, GUINT_TO_POINTER (handler_id));
1483 g_signal_connect (manager, "account-validity-changed",
1484 G_CALLBACK (main_window_account_validity_changed_cb),
1487 main_window_update_status (window);
1489 /* Disable the "Previous Conversations" menu entry if there is no account */
1490 gtk_action_set_sensitive (priv->view_history,
1491 g_list_length (accounts) > 0);
1493 g_list_free (accounts);
1497 main_window_members_changed_cb (EmpathyContactList *list,
1498 EmpathyContact *contact,
1499 EmpathyContact *actor,
1503 EmpathyMainWindow *window)
1505 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1510 if (!empathy_migrate_butterfly_logs (contact)) {
1511 g_signal_handler_disconnect (list,
1512 priv->butterfly_log_migration_members_changed_id);
1513 priv->butterfly_log_migration_members_changed_id = 0;
1518 empathy_main_window_constructor (GType type,
1519 guint n_construct_params,
1520 GObjectConstructParam *construct_params)
1522 static GObject *window = NULL;
1525 return g_object_ref (window);
1527 window = G_OBJECT_CLASS (empathy_main_window_parent_class)->constructor (
1528 type, n_construct_params, construct_params);
1530 g_object_add_weak_pointer (window, (gpointer) &window);
1536 empathy_main_window_class_init (EmpathyMainWindowClass *klass)
1538 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1540 object_class->finalize = empathy_main_window_finalize;
1541 object_class->constructor = empathy_main_window_constructor;
1543 g_type_class_add_private (object_class, sizeof (EmpathyMainWindowPriv));
1547 empathy_main_window_init (EmpathyMainWindow *window)
1549 EmpathyMainWindowPriv *priv;
1550 EmpathyIndividualManager *individual_manager;
1553 GtkToggleAction *show_offline_widget;
1554 GtkAction *show_map_widget;
1556 gboolean show_offline;
1559 GtkTreeModel *model;
1561 priv = window->priv = G_TYPE_INSTANCE_GET_PRIVATE (window,
1562 EMPATHY_TYPE_MAIN_WINDOW, EmpathyMainWindowPriv);
1564 priv->gsettings_ui = g_settings_new (EMPATHY_PREFS_UI_SCHEMA);
1565 priv->gsettings_contacts = g_settings_new (EMPATHY_PREFS_CONTACTS_SCHEMA);
1567 gtk_window_set_title (GTK_WINDOW (window), _("Contact List"));
1568 gtk_window_set_role (GTK_WINDOW (window), "contact_list");
1569 gtk_window_set_default_size (GTK_WINDOW (window), 225, 325);
1571 /* Set up interface */
1572 filename = empathy_file_lookup ("empathy-main-window.ui", "src");
1573 gui = empathy_builder_get_file (filename,
1574 "main_vbox", &priv->main_vbox,
1575 "errors_vbox", &priv->errors_vbox,
1576 "ui_manager", &priv->ui_manager,
1577 "view_show_offline", &show_offline_widget,
1578 "view_show_protocols", &priv->show_protocols,
1579 "view_sort_by_name", &priv->sort_by_name,
1580 "view_sort_by_status", &priv->sort_by_status,
1581 "view_normal_size_with_avatars", &priv->normal_with_avatars,
1582 "view_normal_size", &priv->normal_size,
1583 "view_compact_size", &priv->compact_size,
1584 "view_history", &priv->view_history,
1585 "view_show_map", &show_map_widget,
1586 "room_join_favorites", &priv->room_join_favorites,
1587 "presence_toolbar", &priv->presence_toolbar,
1588 "notebook", &priv->notebook,
1589 "no_entry_label", &priv->no_entry_label,
1590 "roster_scrolledwindow", &sw,
1594 gtk_container_add (GTK_CONTAINER (window), priv->main_vbox);
1595 gtk_widget_show (priv->main_vbox);
1597 g_signal_connect (window, "key-press-event",
1598 G_CALLBACK (main_window_key_press_event_cb), NULL);
1600 empathy_builder_connect (gui, window,
1601 "chat_quit", "activate", main_window_chat_quit_cb,
1602 "chat_new_message", "activate", main_window_chat_new_message_cb,
1603 "chat_new_call", "activate", main_window_chat_new_call_cb,
1604 "view_history", "activate", main_window_view_history_cb,
1605 "room_join_new", "activate", main_window_room_join_new_cb,
1606 "room_join_favorites", "activate", main_window_room_join_favorites_cb,
1607 "room_manage_favorites", "activate", main_window_room_manage_favorites_cb,
1608 "chat_add_contact", "activate", main_window_chat_add_contact_cb,
1609 "view_show_ft_manager", "activate", main_window_view_show_ft_manager,
1610 "view_show_offline", "toggled", main_window_view_show_offline_cb,
1611 "view_show_protocols", "toggled", main_window_view_show_protocols_cb,
1612 "view_sort_by_name", "changed", main_window_view_sort_contacts_cb,
1613 "view_normal_size_with_avatars", "changed", main_window_view_contacts_list_size_cb,
1614 "view_show_map", "activate", main_window_view_show_map_cb,
1615 "edit", "activate", main_window_edit_cb,
1616 "edit_accounts", "activate", main_window_edit_accounts_cb,
1617 "edit_personal_information", "activate", main_window_edit_personal_information_cb,
1618 "edit_preferences", "activate", main_window_edit_preferences_cb,
1619 "edit_search_contacts", "activate", main_window_edit_search_contacts_cb,
1620 "help_about", "activate", main_window_help_about_cb,
1621 "help_debug", "activate", main_window_help_debug_cb,
1622 "help_contents", "activate", main_window_help_contents_cb,
1625 /* Set up connection related widgets. */
1626 main_window_connection_items_setup (window, gui);
1628 g_object_ref (priv->ui_manager);
1629 g_object_unref (gui);
1631 #ifndef HAVE_LIBCHAMPLAIN
1632 gtk_action_set_visible (show_map_widget, FALSE);
1635 priv->account_manager = tp_account_manager_dup ();
1637 tp_account_manager_prepare_async (priv->account_manager, NULL,
1638 account_manager_prepared_cb, window);
1640 priv->errors = g_hash_table_new_full (g_direct_hash,
1645 priv->status_changed_handlers = g_hash_table_new_full (g_direct_hash,
1651 main_window_favorite_chatroom_menu_setup (window);
1653 priv->edit_context = gtk_ui_manager_get_widget (priv->ui_manager,
1654 "/menubar/edit/edit_context");
1655 priv->edit_context_separator = gtk_ui_manager_get_widget (
1657 "/menubar/edit/edit_context_separator");
1658 gtk_widget_hide (priv->edit_context);
1659 gtk_widget_hide (priv->edit_context_separator);
1661 /* Set up contact list. */
1662 empathy_status_presets_get_all ();
1664 /* Set up presence chooser */
1665 priv->presence_chooser = empathy_presence_chooser_new ();
1666 gtk_widget_show (priv->presence_chooser);
1667 item = gtk_tool_item_new ();
1668 gtk_widget_show (GTK_WIDGET (item));
1669 gtk_container_add (GTK_CONTAINER (item), priv->presence_chooser);
1670 gtk_tool_item_set_is_important (item, TRUE);
1671 gtk_tool_item_set_expand (item, TRUE);
1672 gtk_toolbar_insert (GTK_TOOLBAR (priv->presence_toolbar), item, -1);
1674 /* Set up the throbber */
1675 priv->throbber = gtk_spinner_new ();
1676 gtk_widget_set_size_request (priv->throbber, 16, -1);
1677 gtk_widget_set_tooltip_text (priv->throbber, _("Show and edit accounts"));
1678 gtk_widget_set_events (priv->throbber, GDK_BUTTON_PRESS_MASK);
1679 g_signal_connect (priv->throbber, "button-press-event",
1680 G_CALLBACK (main_window_throbber_button_press_event_cb),
1682 gtk_widget_show (priv->throbber);
1684 item = gtk_tool_item_new ();
1685 gtk_container_set_border_width (GTK_CONTAINER (item), 6);
1686 gtk_toolbar_insert (GTK_TOOLBAR (priv->presence_toolbar), item, -1);
1687 gtk_container_add (GTK_CONTAINER (item), priv->throbber);
1688 priv->throbber_tool_item = GTK_WIDGET (item);
1690 /* XXX: this class is designed to live for the duration of the program,
1691 * so it's got a race condition between its signal handlers and its
1692 * finalization. The class is planned to be removed, so we won't fix
1693 * this before then. */
1694 priv->contact_manager = EMPATHY_CONTACT_LIST (
1695 empathy_contact_manager_dup_singleton ());
1696 individual_manager = empathy_individual_manager_dup_singleton ();
1697 priv->individual_store = empathy_individual_store_new (
1698 individual_manager);
1699 g_object_unref (individual_manager);
1701 /* For the moment, we disallow Persona drops onto the main contact list (e.g. from things such as
1702 * the EmpathyPersonaView in the linking dialogue). No code is hooked up to do anything on a Persona
1703 * drop, so allowing them would achieve nothing except confusion. */
1704 priv->individual_view = empathy_individual_view_new (
1705 priv->individual_store,
1706 EMPATHY_INDIVIDUAL_VIEW_FEATURE_ALL ^ EMPATHY_INDIVIDUAL_VIEW_FEATURE_PERSONA_DROP,
1707 EMPATHY_INDIVIDUAL_FEATURE_ALL);
1709 priv->butterfly_log_migration_members_changed_id = g_signal_connect (
1710 priv->contact_manager, "members-changed",
1711 G_CALLBACK (main_window_members_changed_cb), window);
1713 gtk_widget_show (GTK_WIDGET (priv->individual_view));
1714 gtk_container_add (GTK_CONTAINER (sw),
1715 GTK_WIDGET (priv->individual_view));
1716 g_signal_connect (priv->individual_view, "row-activated",
1717 G_CALLBACK (main_window_row_activated_cb),
1720 /* Set up search bar */
1721 priv->search_bar = empathy_live_search_new (
1722 GTK_WIDGET (priv->individual_view));
1723 empathy_individual_view_set_live_search (priv->individual_view,
1724 EMPATHY_LIVE_SEARCH (priv->search_bar));
1725 gtk_box_pack_start (GTK_BOX (priv->main_vbox), priv->search_bar,
1727 g_signal_connect_swapped (window, "map",
1728 G_CALLBACK (gtk_widget_grab_focus), priv->individual_view);
1730 /* Connect to proper signals to check if contact list is empty or not */
1731 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->individual_view));
1733 g_signal_connect (model, "row-inserted",
1734 G_CALLBACK (main_window_row_inserted_cb),
1736 g_signal_connect (model, "row-deleted",
1737 G_CALLBACK (main_window_row_deleted_cb),
1740 /* Load user-defined accelerators. */
1741 main_window_accels_load ();
1743 /* Set window size. */
1744 empathy_geometry_bind (GTK_WINDOW (window), GEOMETRY_NAME);
1746 /* Enable event handling */
1747 priv->event_manager = empathy_event_manager_dup_singleton ();
1749 g_signal_connect (priv->event_manager, "event-added",
1750 G_CALLBACK (main_window_event_added_cb), window);
1751 g_signal_connect (priv->event_manager, "event-removed",
1752 G_CALLBACK (main_window_event_removed_cb), window);
1753 g_signal_connect (priv->account_manager, "account-validity-changed",
1754 G_CALLBACK (main_window_account_validity_changed_cb),
1756 g_signal_connect (priv->account_manager, "account-removed",
1757 G_CALLBACK (main_window_account_removed_cb),
1759 g_signal_connect (priv->account_manager, "account-disabled",
1760 G_CALLBACK (main_window_account_disabled_cb),
1763 l = empathy_event_manager_get_events (priv->event_manager);
1765 main_window_event_added_cb (priv->event_manager, l->data,
1770 /* Show offline ? */
1771 show_offline = g_settings_get_boolean (priv->gsettings_ui,
1772 EMPATHY_PREFS_UI_SHOW_OFFLINE);
1773 g_signal_connect (priv->gsettings_ui,
1774 "changed::" EMPATHY_PREFS_UI_SHOW_OFFLINE,
1775 G_CALLBACK (main_window_notify_show_offline_cb),
1776 show_offline_widget);
1778 gtk_toggle_action_set_active (show_offline_widget, show_offline);
1780 /* Show protocol ? */
1781 g_signal_connect (priv->gsettings_ui,
1782 "changed::" EMPATHY_PREFS_UI_SHOW_PROTOCOLS,
1783 G_CALLBACK (main_window_notify_show_protocols_cb),
1786 main_window_notify_show_protocols_cb (priv->gsettings_ui,
1787 EMPATHY_PREFS_UI_SHOW_PROTOCOLS,
1790 /* Sort by name / by status ? */
1791 g_signal_connect (priv->gsettings_contacts,
1792 "changed::" EMPATHY_PREFS_CONTACTS_SORT_CRITERIUM,
1793 G_CALLBACK (main_window_notify_sort_contact_cb),
1796 main_window_notify_sort_contact_cb (priv->gsettings_contacts,
1797 EMPATHY_PREFS_CONTACTS_SORT_CRITERIUM,
1800 /* Contacts list size */
1801 g_signal_connect (priv->gsettings_ui,
1802 "changed::" EMPATHY_PREFS_UI_COMPACT_CONTACT_LIST,
1803 G_CALLBACK (main_window_notify_contact_list_size_cb),
1805 g_signal_connect (priv->gsettings_ui,
1806 "changed::" EMPATHY_PREFS_UI_SHOW_AVATARS,
1807 G_CALLBACK (main_window_notify_contact_list_size_cb),
1810 main_window_notify_contact_list_size_cb (priv->gsettings_ui,
1811 EMPATHY_PREFS_UI_SHOW_AVATARS,
1816 empathy_main_window_dup (void)
1818 return g_object_new (EMPATHY_TYPE_MAIN_WINDOW, NULL);