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-manager.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 EmpathySoundManager *sound_mgr;;
111 guint flash_timeout_id;
115 GSettings *gsettings_ui;
116 GSettings *gsettings_contacts;
118 GtkWidget *preferences;
119 GtkWidget *main_vbox;
121 GtkWidget *throbber_tool_item;
122 GtkWidget *presence_toolbar;
123 GtkWidget *presence_chooser;
124 GtkWidget *errors_vbox;
125 GtkWidget *auth_vbox;
126 GtkWidget *search_bar;
128 GtkWidget *no_entry_label;
130 GtkToggleAction *show_protocols;
131 GtkRadioAction *sort_by_name;
132 GtkRadioAction *sort_by_status;
133 GtkRadioAction *normal_with_avatars;
134 GtkRadioAction *normal_size;
135 GtkRadioAction *compact_size;
137 GtkUIManager *ui_manager;
138 GtkAction *view_history;
139 GtkAction *room_join_favorites;
140 GtkWidget *room_menu;
141 GtkWidget *room_separator;
142 GtkWidget *edit_context;
143 GtkWidget *edit_context_separator;
145 guint size_timeout_id;
149 /* stores a mapping from TpAccount to Handler ID to prevent
150 * to listen more than once to the status-changed signal */
151 GHashTable *status_changed_handlers;
153 /* Actions that are enabled when there are connected accounts */
154 GList *actions_connected;
156 /* The idle event source to migrate butterfly's logs */
157 guint butterfly_log_migration_members_changed_id;
161 main_window_flash_stop (EmpathyMainWindow *window)
163 EmpathyMainWindowPriv *priv = GET_PRIV (window);
165 if (priv->flash_timeout_id == 0) {
169 DEBUG ("Stop flashing");
170 g_source_remove (priv->flash_timeout_id);
171 priv->flash_timeout_id = 0;
172 priv->flash_on = FALSE;
178 EmpathyMainWindow *window;
182 main_window_flash_foreach (GtkTreeModel *model,
187 FlashForeachData *data = (FlashForeachData *) user_data;
188 FolksIndividual *individual;
189 EmpathyContact *contact;
190 const gchar *icon_name;
191 GtkTreePath *parent_path = NULL;
192 GtkTreeIter parent_iter;
193 GdkPixbuf *pixbuf = NULL;
195 gtk_tree_model_get (model, iter,
196 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL,
200 if (individual == NULL)
203 contact = empathy_contact_dup_from_folks_individual (individual);
204 if (contact != data->event->contact) {
205 tp_clear_object (&contact);
210 icon_name = data->event->icon_name;
211 pixbuf = empathy_pixbuf_from_icon_name (icon_name, GTK_ICON_SIZE_MENU);
213 pixbuf = empathy_individual_store_get_individual_status_icon (
214 GET_PRIV (data->window)->individual_store,
218 gtk_tree_store_set (GTK_TREE_STORE (model), iter,
219 EMPATHY_INDIVIDUAL_STORE_COL_ICON_STATUS, pixbuf,
222 /* To make sure the parent is shown correctly, we emit
223 * the row-changed signal on the parent so it prompts
224 * it to be refreshed by the filter func.
226 if (gtk_tree_model_iter_parent (model, &parent_iter, iter)) {
227 parent_path = gtk_tree_model_get_path (model, &parent_iter);
230 gtk_tree_model_row_changed (model, parent_path, &parent_iter);
231 gtk_tree_path_free (parent_path);
234 g_object_unref (individual);
235 tp_clear_object (&contact);
241 main_window_flash_cb (EmpathyMainWindow *window)
243 EmpathyMainWindowPriv *priv = GET_PRIV (window);
246 gboolean found_event = FALSE;
247 FlashForeachData data;
249 priv->flash_on = !priv->flash_on;
250 data.on = priv->flash_on;
251 model = GTK_TREE_MODEL (priv->individual_store);
253 events = empathy_event_manager_get_events (priv->event_manager);
254 for (l = events; l; l = l->next) {
255 data.event = l->data;
256 data.window = window;
257 if (!data.event->contact || !data.event->must_ack) {
262 gtk_tree_model_foreach (model,
263 main_window_flash_foreach,
268 main_window_flash_stop (window);
275 main_window_flash_start (EmpathyMainWindow *window)
277 EmpathyMainWindowPriv *priv = GET_PRIV (window);
279 if (priv->flash_timeout_id != 0) {
283 DEBUG ("Start flashing");
284 priv->flash_timeout_id = g_timeout_add (FLASH_TIMEOUT,
285 (GSourceFunc) main_window_flash_cb,
287 main_window_flash_cb (window);
291 main_window_remove_auth (EmpathyMainWindow *window,
294 EmpathyMainWindowPriv *priv = GET_PRIV (window);
295 GtkWidget *error_widget;
297 error_widget = g_hash_table_lookup (priv->auths, event);
298 if (error_widget != NULL) {
299 gtk_widget_destroy (error_widget);
300 g_hash_table_remove (priv->auths, event);
305 main_window_auth_add_clicked_cb (GtkButton *button,
306 EmpathyMainWindow *window)
310 event = g_object_get_data (G_OBJECT (button), "event");
312 empathy_event_approve (event);
314 main_window_remove_auth (window, event);
318 main_window_auth_close_clicked_cb (GtkButton *button,
319 EmpathyMainWindow *window)
323 event = g_object_get_data (G_OBJECT (button), "event");
325 empathy_event_decline (event);
326 main_window_remove_auth (window, event);
330 main_window_auth_display (EmpathyMainWindow *window,
333 EmpathyMainWindowPriv *priv = GET_PRIV (window);
334 TpAccount *account = event->account;
336 GtkWidget *content_area;
339 GtkWidget *add_button;
340 GtkWidget *close_button;
341 GtkWidget *action_area;
342 GtkWidget *action_table;
343 const gchar *icon_name;
346 if (g_hash_table_lookup (priv->auths, event) != NULL) {
350 info_bar = gtk_info_bar_new ();
351 gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_QUESTION);
353 gtk_widget_set_no_show_all (info_bar, TRUE);
354 gtk_box_pack_start (GTK_BOX (priv->auth_vbox), info_bar, FALSE, TRUE, 0);
355 gtk_widget_show (info_bar);
357 icon_name = tp_account_get_icon_name (account);
358 image = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_SMALL_TOOLBAR);
359 gtk_widget_show (image);
361 str = g_markup_printf_escaped ("<b>%s</b>\n%s",
362 tp_account_get_display_name (account),
363 _("Password required"));
365 label = gtk_label_new (str);
366 gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
367 gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_END);
368 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
369 gtk_widget_show (label);
373 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
374 gtk_box_pack_start (GTK_BOX (content_area), image, FALSE, FALSE, 0);
375 gtk_box_pack_start (GTK_BOX (content_area), label, TRUE, TRUE, 0);
377 image = gtk_image_new_from_stock (GTK_STOCK_ADD, GTK_ICON_SIZE_BUTTON);
378 add_button = gtk_button_new ();
379 gtk_button_set_image (GTK_BUTTON (add_button), image);
380 gtk_widget_set_tooltip_text (add_button, _("Provide Password"));
381 gtk_widget_show (add_button);
383 image = gtk_image_new_from_stock (GTK_STOCK_CLOSE, GTK_ICON_SIZE_BUTTON);
384 close_button = gtk_button_new ();
385 gtk_button_set_image (GTK_BUTTON (close_button), image);
386 gtk_widget_set_tooltip_text (close_button, _("Cancel"));
387 gtk_widget_show (close_button);
389 action_table = gtk_table_new (1, 2, FALSE);
390 gtk_table_set_col_spacings (GTK_TABLE (action_table), 6);
391 gtk_widget_show (action_table);
393 action_area = gtk_info_bar_get_action_area (GTK_INFO_BAR (info_bar));
394 gtk_box_pack_start (GTK_BOX (action_area), action_table, FALSE, FALSE, 0);
396 gtk_table_attach (GTK_TABLE (action_table), add_button, 0, 1, 0, 1,
397 (GtkAttachOptions) (GTK_SHRINK),
398 (GtkAttachOptions) (GTK_SHRINK), 0, 0);
399 gtk_table_attach (GTK_TABLE (action_table), close_button, 1, 2, 0, 1,
400 (GtkAttachOptions) (GTK_SHRINK),
401 (GtkAttachOptions) (GTK_SHRINK), 0, 0);
403 g_object_set_data_full (G_OBJECT (info_bar),
404 "event", event, NULL);
405 g_object_set_data_full (G_OBJECT (add_button),
406 "event", event, NULL);
407 g_object_set_data_full (G_OBJECT (close_button),
408 "event", event, NULL);
410 g_signal_connect (add_button, "clicked",
411 G_CALLBACK (main_window_auth_add_clicked_cb),
413 g_signal_connect (close_button, "clicked",
414 G_CALLBACK (main_window_auth_close_clicked_cb),
417 gtk_widget_show (priv->auth_vbox);
419 g_hash_table_insert (priv->auths, event, info_bar);
423 main_window_event_added_cb (EmpathyEventManager *manager,
425 EmpathyMainWindow *window)
427 if (event->contact) {
428 main_window_flash_start (window);
429 } else if (event->type == EMPATHY_EVENT_TYPE_AUTH) {
430 main_window_auth_display (window, event);
435 main_window_event_removed_cb (EmpathyEventManager *manager,
437 EmpathyMainWindow *window)
439 EmpathyMainWindowPriv *priv = GET_PRIV (window);
440 FlashForeachData data;
442 if (event->type == EMPATHY_EVENT_TYPE_AUTH) {
443 main_window_remove_auth (window, event);
447 if (!event->contact) {
453 data.window = window;
454 gtk_tree_model_foreach (GTK_TREE_MODEL (priv->individual_store),
455 main_window_flash_foreach,
460 main_window_row_activated_cb (EmpathyContactListView *view,
462 GtkTreeViewColumn *col,
463 EmpathyMainWindow *window)
465 EmpathyMainWindowPriv *priv = GET_PRIV (window);
466 EmpathyContact *contact = NULL;
467 FolksIndividual *individual;
472 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->individual_view));
473 gtk_tree_model_get_iter (model, &iter, path);
475 gtk_tree_model_get (model, &iter,
476 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL,
480 if (individual != NULL) {
481 contact = empathy_contact_dup_from_folks_individual (individual);
488 /* If the contact has an event activate it, otherwise the
489 * default handler of row-activated will be called. */
490 events = empathy_event_manager_get_events (priv->event_manager);
491 for (l = events; l; l = l->next) {
492 EmpathyEvent *event = l->data;
494 if (event->contact == contact) {
495 DEBUG ("Activate event");
496 empathy_event_activate (event);
498 /* We don't want the default handler of this signal
499 * (e.g. open a chat) */
500 g_signal_stop_emission_by_name (view, "row-activated");
505 g_object_unref (contact);
507 tp_clear_object (&individual);
511 main_window_row_deleted_cb (GtkTreeModel *model,
513 EmpathyMainWindow *window)
515 EmpathyMainWindowPriv *priv = GET_PRIV (window);
516 GtkTreeIter help_iter;
518 if (!gtk_tree_model_get_iter_first (model, &help_iter)) {
521 if (empathy_individual_view_is_searching (
522 priv->individual_view)) {
525 tmp = g_strdup_printf ("<b><span size='xx-large'>%s</span></b>",
526 _("No match found"));
528 gtk_label_set_markup (GTK_LABEL (priv->no_entry_label), tmp);
531 gtk_label_set_ellipsize (GTK_LABEL (priv->no_entry_label),
532 PANGO_ELLIPSIZE_END);
534 gtk_notebook_set_current_page (
535 GTK_NOTEBOOK (priv->notebook), PAGE_NO_MATCH);
541 main_window_row_inserted_cb (GtkTreeModel *model,
544 EmpathyMainWindow *window)
546 EmpathyMainWindowPriv *priv = GET_PRIV (window);
550 gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook),
552 gtk_widget_grab_focus (GTK_WIDGET (priv->individual_view));
557 main_window_remove_error (EmpathyMainWindow *window,
560 EmpathyMainWindowPriv *priv = GET_PRIV (window);
561 GtkWidget *error_widget;
563 error_widget = g_hash_table_lookup (priv->errors, account);
564 if (error_widget != NULL) {
565 gtk_widget_destroy (error_widget);
566 g_hash_table_remove (priv->errors, account);
571 main_window_account_disabled_cb (TpAccountManager *manager,
573 EmpathyMainWindow *window)
575 main_window_remove_error (window, account);
579 main_window_error_retry_clicked_cb (GtkButton *button,
580 EmpathyMainWindow *window)
584 account = g_object_get_data (G_OBJECT (button), "account");
585 tp_account_reconnect_async (account, NULL, NULL);
587 main_window_remove_error (window, account);
591 main_window_error_edit_clicked_cb (GtkButton *button,
592 EmpathyMainWindow *window)
596 account = g_object_get_data (G_OBJECT (button), "account");
598 empathy_accounts_dialog_show_application (
599 gtk_widget_get_screen (GTK_WIDGET (button)),
600 account, FALSE, FALSE);
602 main_window_remove_error (window, account);
606 main_window_error_close_clicked_cb (GtkButton *button,
607 EmpathyMainWindow *window)
611 account = g_object_get_data (G_OBJECT (button), "account");
612 main_window_remove_error (window, account);
616 main_window_error_display (EmpathyMainWindow *window,
619 EmpathyMainWindowPriv *priv = GET_PRIV (window);
621 GtkWidget *content_area;
624 GtkWidget *retry_button;
625 GtkWidget *edit_button;
626 GtkWidget *close_button;
627 GtkWidget *action_area;
628 GtkWidget *action_table;
630 const gchar *icon_name;
631 const gchar *error_message;
632 gboolean user_requested;
635 empathy_account_get_error_message (account, &user_requested);
637 if (user_requested) {
641 str = g_markup_printf_escaped ("<b>%s</b>\n%s",
642 tp_account_get_display_name (account),
645 info_bar = g_hash_table_lookup (priv->errors, account);
647 label = g_object_get_data (G_OBJECT (info_bar), "label");
649 /* Just set the latest error and return */
650 gtk_label_set_markup (GTK_LABEL (label), str);
656 info_bar = gtk_info_bar_new ();
657 gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_ERROR);
659 gtk_widget_set_no_show_all (info_bar, TRUE);
660 gtk_box_pack_start (GTK_BOX (priv->errors_vbox), info_bar, FALSE, TRUE, 0);
661 gtk_widget_show (info_bar);
663 icon_name = tp_account_get_icon_name (account);
664 image = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_SMALL_TOOLBAR);
665 gtk_widget_show (image);
667 label = gtk_label_new (str);
668 gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
669 gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_END);
670 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
671 gtk_widget_show (label);
674 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
675 gtk_box_pack_start (GTK_BOX (content_area), image, FALSE, FALSE, 0);
676 gtk_box_pack_start (GTK_BOX (content_area), label, TRUE, TRUE, 0);
678 image = gtk_image_new_from_stock (GTK_STOCK_REFRESH, GTK_ICON_SIZE_BUTTON);
679 retry_button = gtk_button_new ();
680 gtk_button_set_image (GTK_BUTTON (retry_button), image);
681 gtk_widget_set_tooltip_text (retry_button, _("Reconnect"));
682 gtk_widget_show (retry_button);
684 image = gtk_image_new_from_stock (GTK_STOCK_EDIT, GTK_ICON_SIZE_BUTTON);
685 edit_button = gtk_button_new ();
686 gtk_button_set_image (GTK_BUTTON (edit_button), image);
687 gtk_widget_set_tooltip_text (edit_button, _("Edit Account"));
688 gtk_widget_show (edit_button);
690 image = gtk_image_new_from_stock (GTK_STOCK_CLOSE, GTK_ICON_SIZE_BUTTON);
691 close_button = gtk_button_new ();
692 gtk_button_set_image (GTK_BUTTON (close_button), image);
693 gtk_widget_set_tooltip_text (close_button, _("Close"));
694 gtk_widget_show (close_button);
696 action_table = gtk_table_new (1, 3, FALSE);
697 gtk_table_set_col_spacings (GTK_TABLE (action_table), 2);
698 gtk_widget_show (action_table);
700 action_area = gtk_info_bar_get_action_area (GTK_INFO_BAR (info_bar));
701 gtk_box_pack_start (GTK_BOX (action_area), action_table, FALSE, FALSE, 0);
703 gtk_table_attach (GTK_TABLE (action_table), retry_button, 0, 1, 0, 1,
704 (GtkAttachOptions) (GTK_SHRINK),
705 (GtkAttachOptions) (GTK_SHRINK), 0, 0);
706 gtk_table_attach (GTK_TABLE (action_table), edit_button, 1, 2, 0, 1,
707 (GtkAttachOptions) (GTK_SHRINK),
708 (GtkAttachOptions) (GTK_SHRINK), 0, 0);
709 gtk_table_attach (GTK_TABLE (action_table), close_button, 2, 3, 0, 1,
710 (GtkAttachOptions) (GTK_SHRINK),
711 (GtkAttachOptions) (GTK_SHRINK), 0, 0);
713 g_object_set_data (G_OBJECT (info_bar), "label", label);
714 g_object_set_data_full (G_OBJECT (info_bar),
715 "account", g_object_ref (account),
717 g_object_set_data_full (G_OBJECT (edit_button),
718 "account", g_object_ref (account),
720 g_object_set_data_full (G_OBJECT (close_button),
721 "account", g_object_ref (account),
723 g_object_set_data_full (G_OBJECT (retry_button),
724 "account", g_object_ref (account),
727 g_signal_connect (edit_button, "clicked",
728 G_CALLBACK (main_window_error_edit_clicked_cb),
730 g_signal_connect (close_button, "clicked",
731 G_CALLBACK (main_window_error_close_clicked_cb),
733 g_signal_connect (retry_button, "clicked",
734 G_CALLBACK (main_window_error_retry_clicked_cb),
737 gtk_widget_show (priv->errors_vbox);
739 g_hash_table_insert (priv->errors, g_object_ref (account), info_bar);
743 main_window_update_status (EmpathyMainWindow *window)
745 EmpathyMainWindowPriv *priv = GET_PRIV (window);
746 gboolean connected, connecting;
749 connected = empathy_account_manager_get_accounts_connected (&connecting);
751 /* Update the spinner state */
753 gtk_spinner_start (GTK_SPINNER (priv->throbber));
754 gtk_widget_show (priv->throbber_tool_item);
756 gtk_spinner_stop (GTK_SPINNER (priv->throbber));
757 gtk_widget_hide (priv->throbber_tool_item);
760 /* Update widgets sensibility */
761 for (l = priv->actions_connected; l; l = l->next) {
762 gtk_action_set_sensitive (l->data, connected);
765 /* Update favourite rooms sensitivity */
766 children = gtk_container_get_children (GTK_CONTAINER (priv->room_menu));
767 for (l = children; l != NULL; l = l->next) {
768 if (g_object_get_data (G_OBJECT (l->data), "is_favorite") != NULL) {
769 gtk_widget_set_sensitive (GTK_WIDGET (l->data), connected);
772 g_list_free (children);
776 main_window_connection_changed_cb (TpAccount *account,
780 gchar *dbus_error_name,
782 EmpathyMainWindow *window)
784 EmpathyMainWindowPriv *priv = GET_PRIV (window);
786 main_window_update_status (window);
788 if (current == TP_CONNECTION_STATUS_DISCONNECTED &&
789 reason != TP_CONNECTION_STATUS_REASON_REQUESTED) {
790 main_window_error_display (window, account);
793 if (current == TP_CONNECTION_STATUS_DISCONNECTED) {
794 empathy_sound_manager_play (priv->sound_mgr, GTK_WIDGET (window),
795 EMPATHY_SOUND_ACCOUNT_DISCONNECTED);
798 if (current == TP_CONNECTION_STATUS_CONNECTED) {
799 empathy_sound_manager_play (priv->sound_mgr, GTK_WIDGET (window),
800 EMPATHY_SOUND_ACCOUNT_CONNECTED);
802 /* Account connected without error, remove error message if any */
803 main_window_remove_error (window, account);
808 main_window_accels_load (void)
812 filename = g_build_filename (g_get_user_config_dir (), PACKAGE_NAME, ACCELS_FILENAME, NULL);
813 if (g_file_test (filename, G_FILE_TEST_EXISTS)) {
814 DEBUG ("Loading from:'%s'", filename);
815 gtk_accel_map_load (filename);
822 main_window_accels_save (void)
825 gchar *file_with_path;
827 dir = g_build_filename (g_get_user_config_dir (), PACKAGE_NAME, NULL);
828 g_mkdir_with_parents (dir, S_IRUSR | S_IWUSR | S_IXUSR);
829 file_with_path = g_build_filename (dir, ACCELS_FILENAME, NULL);
832 DEBUG ("Saving to:'%s'", file_with_path);
833 gtk_accel_map_save (file_with_path);
835 g_free (file_with_path);
839 empathy_main_window_finalize (GObject *window)
841 EmpathyMainWindowPriv *priv = GET_PRIV (window);
845 /* Save user-defined accelerators. */
846 main_window_accels_save ();
848 g_list_free (priv->actions_connected);
850 g_object_unref (priv->account_manager);
851 g_object_unref (priv->individual_store);
852 g_object_unref (priv->contact_manager);
853 g_object_unref (priv->sound_mgr);
854 g_hash_table_destroy (priv->errors);
855 g_hash_table_destroy (priv->auths);
857 /* disconnect all handlers of status-changed signal */
858 g_hash_table_iter_init (&iter, priv->status_changed_handlers);
859 while (g_hash_table_iter_next (&iter, &key, &value))
860 g_signal_handler_disconnect (TP_ACCOUNT (key),
861 GPOINTER_TO_UINT (value));
863 g_hash_table_destroy (priv->status_changed_handlers);
865 g_signal_handlers_disconnect_by_func (priv->event_manager,
866 main_window_event_added_cb,
868 g_signal_handlers_disconnect_by_func (priv->event_manager,
869 main_window_event_removed_cb,
871 g_object_unref (priv->event_manager);
872 g_object_unref (priv->ui_manager);
873 g_object_unref (priv->chatroom_manager);
875 g_object_unref (priv->gsettings_ui);
876 g_object_unref (priv->gsettings_contacts);
878 G_OBJECT_CLASS (empathy_main_window_parent_class)->finalize (window);
882 main_window_key_press_event_cb (GtkWidget *window,
886 EmpathyChatManager *chat_manager;
888 if (event->keyval == GDK_KEY_T
889 && event->state & GDK_SHIFT_MASK
890 && event->state & GDK_CONTROL_MASK) {
891 chat_manager = empathy_chat_manager_dup_singleton ();
892 empathy_chat_manager_undo_closed_chat (chat_manager);
893 g_object_unref (chat_manager);
899 main_window_chat_quit_cb (GtkAction *action,
900 EmpathyMainWindow *window)
906 main_window_view_history_cb (GtkAction *action,
907 EmpathyMainWindow *window)
909 empathy_log_window_show (NULL, NULL, FALSE, GTK_WINDOW (window));
913 main_window_chat_new_message_cb (GtkAction *action,
914 EmpathyMainWindow *window)
916 empathy_new_message_dialog_show (GTK_WINDOW (window));
920 main_window_chat_new_call_cb (GtkAction *action,
921 EmpathyMainWindow *window)
923 empathy_new_call_dialog_show (GTK_WINDOW (window));
927 main_window_chat_add_contact_cb (GtkAction *action,
928 EmpathyMainWindow *window)
930 empathy_new_individual_dialog_show (GTK_WINDOW (window));
934 main_window_view_show_ft_manager (GtkAction *action,
935 EmpathyMainWindow *window)
937 empathy_ft_manager_show ();
941 main_window_view_show_offline_cb (GtkToggleAction *action,
942 EmpathyMainWindow *window)
944 EmpathyMainWindowPriv *priv = GET_PRIV (window);
947 current = gtk_toggle_action_get_active (action);
948 g_settings_set_boolean (priv->gsettings_ui,
949 EMPATHY_PREFS_UI_SHOW_OFFLINE,
952 empathy_individual_view_set_show_offline (priv->individual_view,
957 main_window_notify_sort_contact_cb (GSettings *gsettings,
959 EmpathyMainWindow *window)
961 EmpathyMainWindowPriv *priv = GET_PRIV (window);
964 str = g_settings_get_string (gsettings, key);
968 GEnumClass *enum_class;
969 GEnumValue *enum_value;
971 type = empathy_individual_store_sort_get_type ();
972 enum_class = G_ENUM_CLASS (g_type_class_peek (type));
973 enum_value = g_enum_get_value_by_nick (enum_class, str);
975 /* By changing the value of the GtkRadioAction,
976 it emits a signal that calls main_window_view_sort_contacts_cb
977 which updates the contacts list */
978 gtk_radio_action_set_current_value (priv->sort_by_name,
981 g_warning ("Wrong value for sort_criterium configuration : %s", str);
988 main_window_view_sort_contacts_cb (GtkRadioAction *action,
989 GtkRadioAction *current,
990 EmpathyMainWindow *window)
992 EmpathyMainWindowPriv *priv = GET_PRIV (window);
993 EmpathyContactListStoreSort value;
996 GEnumClass *enum_class;
997 GEnumValue *enum_value;
999 value = gtk_radio_action_get_current_value (action);
1000 group = gtk_radio_action_get_group (action);
1002 /* Get string from index */
1003 type = empathy_individual_store_sort_get_type ();
1004 enum_class = G_ENUM_CLASS (g_type_class_peek (type));
1005 enum_value = g_enum_get_value (enum_class, g_slist_index (group, current));
1008 g_warning ("No GEnumValue for EmpathyContactListSort with GtkRadioAction index:%d",
1009 g_slist_index (group, action));
1011 g_settings_set_string (priv->gsettings_contacts,
1012 EMPATHY_PREFS_CONTACTS_SORT_CRITERIUM,
1013 enum_value->value_nick);
1015 empathy_individual_store_set_sort_criterium (priv->individual_store,
1020 main_window_view_show_protocols_cb (GtkToggleAction *action,
1021 EmpathyMainWindow *window)
1023 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1026 value = gtk_toggle_action_get_active (action);
1028 g_settings_set_boolean (priv->gsettings_ui,
1029 EMPATHY_PREFS_UI_SHOW_PROTOCOLS,
1031 empathy_individual_store_set_show_protocols (priv->individual_store,
1035 /* Matches GtkRadioAction values set in empathy-main-window.ui */
1036 #define CONTACT_LIST_NORMAL_SIZE_WITH_AVATARS 0
1037 #define CONTACT_LIST_NORMAL_SIZE 1
1038 #define CONTACT_LIST_COMPACT_SIZE 2
1041 main_window_view_contacts_list_size_cb (GtkRadioAction *action,
1042 GtkRadioAction *current,
1043 EmpathyMainWindow *window)
1045 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1046 GSettings *gsettings_ui;
1049 value = gtk_radio_action_get_current_value (action);
1050 /* create a new GSettings, so we can delay the setting until both
1052 gsettings_ui = g_settings_new (EMPATHY_PREFS_UI_SCHEMA);
1054 DEBUG ("radio button toggled, value = %i", value);
1056 g_settings_delay (gsettings_ui);
1057 g_settings_set_boolean (gsettings_ui,
1058 EMPATHY_PREFS_UI_SHOW_AVATARS,
1059 value == CONTACT_LIST_NORMAL_SIZE_WITH_AVATARS);
1061 g_settings_set_boolean (gsettings_ui,
1062 EMPATHY_PREFS_UI_COMPACT_CONTACT_LIST,
1063 value == CONTACT_LIST_COMPACT_SIZE);
1064 g_settings_apply (gsettings_ui);
1066 /* FIXME: these enums probably have the wrong namespace */
1067 empathy_individual_store_set_show_avatars (priv->individual_store,
1068 value == CONTACT_LIST_NORMAL_SIZE_WITH_AVATARS);
1069 empathy_individual_store_set_is_compact (priv->individual_store,
1070 value == CONTACT_LIST_COMPACT_SIZE);
1072 g_object_unref (gsettings_ui);
1075 static void main_window_notify_show_protocols_cb (GSettings *gsettings,
1077 EmpathyMainWindow *window)
1079 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1081 gtk_toggle_action_set_active (priv->show_protocols,
1082 g_settings_get_boolean (gsettings,
1083 EMPATHY_PREFS_UI_SHOW_PROTOCOLS));
1088 main_window_notify_contact_list_size_cb (GSettings *gsettings,
1090 EmpathyMainWindow *window)
1092 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1095 if (g_settings_get_boolean (gsettings,
1096 EMPATHY_PREFS_UI_COMPACT_CONTACT_LIST)) {
1097 value = CONTACT_LIST_COMPACT_SIZE;
1098 } else if (g_settings_get_boolean (gsettings,
1099 EMPATHY_PREFS_UI_SHOW_AVATARS)) {
1100 value = CONTACT_LIST_NORMAL_SIZE_WITH_AVATARS;
1102 value = CONTACT_LIST_NORMAL_SIZE;
1105 DEBUG ("setting changed, value = %i", value);
1107 /* By changing the value of the GtkRadioAction,
1108 it emits a signal that calls main_window_view_contacts_list_size_cb
1109 which updates the contacts list */
1110 gtk_radio_action_set_current_value (priv->normal_with_avatars, value);
1114 main_window_edit_search_contacts_cb (GtkCheckMenuItem *item,
1115 EmpathyMainWindow *window)
1117 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1119 empathy_individual_view_start_search (priv->individual_view);
1123 main_window_view_show_map_cb (GtkCheckMenuItem *item,
1124 EmpathyMainWindow *window)
1126 #ifdef HAVE_LIBCHAMPLAIN
1127 empathy_map_view_show ();
1132 join_chatroom (EmpathyChatroom *chatroom,
1138 account = empathy_chatroom_get_account (chatroom);
1139 room = empathy_chatroom_get_room (chatroom);
1141 DEBUG ("Requesting channel for '%s'", room);
1142 empathy_dispatcher_join_muc (account, room, timestamp);
1148 EmpathyChatroom *chatroom;
1152 } join_fav_account_sig_ctx;
1154 static join_fav_account_sig_ctx *
1155 join_fav_account_sig_ctx_new (TpAccount *account,
1156 EmpathyChatroom *chatroom,
1159 join_fav_account_sig_ctx *ctx = g_slice_new0 (
1160 join_fav_account_sig_ctx);
1162 ctx->account = g_object_ref (account);
1163 ctx->chatroom = g_object_ref (chatroom);
1164 ctx->timestamp = timestamp;
1169 join_fav_account_sig_ctx_free (join_fav_account_sig_ctx *ctx)
1171 g_object_unref (ctx->account);
1172 g_object_unref (ctx->chatroom);
1173 g_slice_free (join_fav_account_sig_ctx, ctx);
1177 account_status_changed_cb (TpAccount *account,
1178 TpConnectionStatus old_status,
1179 TpConnectionStatus new_status,
1181 gchar *dbus_error_name,
1182 GHashTable *details,
1185 join_fav_account_sig_ctx *ctx = user_data;
1187 switch (new_status) {
1188 case TP_CONNECTION_STATUS_DISCONNECTED:
1189 /* Don't wait any longer */
1193 case TP_CONNECTION_STATUS_CONNECTING:
1197 case TP_CONNECTION_STATUS_CONNECTED:
1198 /* We can join the room */
1202 g_assert_not_reached ();
1205 join_chatroom (ctx->chatroom, ctx->timestamp);
1208 g_source_remove (ctx->timeout);
1209 g_signal_handler_disconnect (account, ctx->sig_id);
1212 #define JOIN_FAVORITE_TIMEOUT 5
1215 join_favorite_timeout_cb (gpointer data)
1217 join_fav_account_sig_ctx *ctx = data;
1219 /* stop waiting for joining the favorite room */
1220 g_signal_handler_disconnect (ctx->account, ctx->sig_id);
1225 main_window_favorite_chatroom_join (EmpathyChatroom *chatroom)
1229 account = empathy_chatroom_get_account (chatroom);
1230 if (tp_account_get_connection_status (account, NULL) !=
1231 TP_CONNECTION_STATUS_CONNECTED) {
1232 join_fav_account_sig_ctx *ctx;
1234 ctx = join_fav_account_sig_ctx_new (account, chatroom,
1235 gtk_get_current_event_time ());
1237 ctx->sig_id = g_signal_connect_data (account, "status-changed",
1238 G_CALLBACK (account_status_changed_cb), ctx,
1239 (GClosureNotify) join_fav_account_sig_ctx_free, 0);
1241 ctx->timeout = g_timeout_add_seconds (JOIN_FAVORITE_TIMEOUT,
1242 join_favorite_timeout_cb, ctx);
1246 join_chatroom (chatroom, gtk_get_current_event_time ());
1250 main_window_favorite_chatroom_menu_activate_cb (GtkMenuItem *menu_item,
1251 EmpathyChatroom *chatroom)
1253 main_window_favorite_chatroom_join (chatroom);
1257 main_window_favorite_chatroom_menu_add (EmpathyMainWindow *window,
1258 EmpathyChatroom *chatroom)
1260 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1261 GtkWidget *menu_item;
1264 if (g_object_get_data (G_OBJECT (chatroom), "menu_item")) {
1268 name = empathy_chatroom_get_name (chatroom);
1269 menu_item = gtk_menu_item_new_with_label (name);
1270 g_object_set_data (G_OBJECT (menu_item), "is_favorite",
1271 GUINT_TO_POINTER (TRUE));
1273 g_object_set_data (G_OBJECT (chatroom), "menu_item", menu_item);
1274 g_signal_connect (menu_item, "activate",
1275 G_CALLBACK (main_window_favorite_chatroom_menu_activate_cb),
1278 gtk_menu_shell_insert (GTK_MENU_SHELL (priv->room_menu),
1281 gtk_widget_show (menu_item);
1285 main_window_favorite_chatroom_menu_added_cb (EmpathyChatroomManager *manager,
1286 EmpathyChatroom *chatroom,
1287 EmpathyMainWindow *window)
1289 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1291 main_window_favorite_chatroom_menu_add (window, chatroom);
1292 gtk_widget_show (priv->room_separator);
1293 gtk_action_set_sensitive (priv->room_join_favorites, TRUE);
1297 main_window_favorite_chatroom_menu_removed_cb (EmpathyChatroomManager *manager,
1298 EmpathyChatroom *chatroom,
1299 EmpathyMainWindow *window)
1301 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1302 GtkWidget *menu_item;
1305 menu_item = g_object_get_data (G_OBJECT (chatroom), "menu_item");
1306 g_object_set_data (G_OBJECT (chatroom), "menu_item", NULL);
1307 gtk_widget_destroy (menu_item);
1309 chatrooms = empathy_chatroom_manager_get_chatrooms (priv->chatroom_manager, NULL);
1311 gtk_widget_show (priv->room_separator);
1313 gtk_widget_hide (priv->room_separator);
1316 gtk_action_set_sensitive (priv->room_join_favorites, chatrooms != NULL);
1317 g_list_free (chatrooms);
1321 main_window_favorite_chatroom_menu_setup (EmpathyMainWindow *window)
1323 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1324 GList *chatrooms, *l;
1327 priv->chatroom_manager = empathy_chatroom_manager_dup_singleton (NULL);
1328 chatrooms = empathy_chatroom_manager_get_chatrooms (
1329 priv->chatroom_manager, NULL);
1330 room = gtk_ui_manager_get_widget (priv->ui_manager,
1332 priv->room_menu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (room));
1333 priv->room_separator = gtk_ui_manager_get_widget (priv->ui_manager,
1334 "/menubar/room/room_separator");
1336 for (l = chatrooms; l; l = l->next) {
1337 main_window_favorite_chatroom_menu_add (window, l->data);
1341 gtk_widget_hide (priv->room_separator);
1344 gtk_action_set_sensitive (priv->room_join_favorites, chatrooms != NULL);
1346 g_signal_connect (priv->chatroom_manager, "chatroom-added",
1347 G_CALLBACK (main_window_favorite_chatroom_menu_added_cb),
1349 g_signal_connect (priv->chatroom_manager, "chatroom-removed",
1350 G_CALLBACK (main_window_favorite_chatroom_menu_removed_cb),
1353 g_list_free (chatrooms);
1357 main_window_room_join_new_cb (GtkAction *action,
1358 EmpathyMainWindow *window)
1360 empathy_new_chatroom_dialog_show (GTK_WINDOW (window));
1364 main_window_room_join_favorites_cb (GtkAction *action,
1365 EmpathyMainWindow *window)
1367 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1368 GList *chatrooms, *l;
1370 chatrooms = empathy_chatroom_manager_get_chatrooms (priv->chatroom_manager, NULL);
1371 for (l = chatrooms; l; l = l->next) {
1372 main_window_favorite_chatroom_join (l->data);
1374 g_list_free (chatrooms);
1378 main_window_room_manage_favorites_cb (GtkAction *action,
1379 EmpathyMainWindow *window)
1381 empathy_chatrooms_window_show (GTK_WINDOW (window));
1385 main_window_edit_cb (GtkAction *action,
1386 EmpathyMainWindow *window)
1388 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1391 /* FIXME: It should use the UIManager to merge the contact/group submenu */
1392 submenu = empathy_individual_view_get_individual_menu (
1393 priv->individual_view);
1398 item = GTK_MENU_ITEM (priv->edit_context);
1399 label = gtk_bin_get_child (GTK_BIN (item));
1400 gtk_label_set_text (GTK_LABEL (label), _("Contact"));
1402 gtk_widget_show (priv->edit_context);
1403 gtk_widget_show (priv->edit_context_separator);
1405 gtk_menu_item_set_submenu (item, submenu);
1410 submenu = empathy_individual_view_get_group_menu (
1411 priv->individual_view);
1416 item = GTK_MENU_ITEM (priv->edit_context);
1417 label = gtk_bin_get_child (GTK_BIN (item));
1418 gtk_label_set_text (GTK_LABEL (label), _("Group"));
1420 gtk_widget_show (priv->edit_context);
1421 gtk_widget_show (priv->edit_context_separator);
1423 gtk_menu_item_set_submenu (item, submenu);
1428 gtk_widget_hide (priv->edit_context);
1429 gtk_widget_hide (priv->edit_context_separator);
1435 main_window_edit_accounts_cb (GtkAction *action,
1436 EmpathyMainWindow *window)
1438 empathy_accounts_dialog_show_application (gdk_screen_get_default (),
1439 NULL, FALSE, FALSE);
1443 main_window_edit_personal_information_cb (GtkAction *action,
1444 EmpathyMainWindow *window)
1446 empathy_contact_personal_dialog_show (GTK_WINDOW (window));
1450 main_window_edit_preferences_cb (GtkAction *action,
1451 EmpathyMainWindow *window)
1453 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1455 if (priv->preferences == NULL) {
1456 priv->preferences = empathy_preferences_new (GTK_WINDOW (window));
1457 g_object_add_weak_pointer (G_OBJECT (priv->preferences),
1458 (gpointer) &priv->preferences);
1460 gtk_widget_show (priv->preferences);
1462 gtk_window_present (GTK_WINDOW (priv->preferences));
1467 main_window_help_about_cb (GtkAction *action,
1468 EmpathyMainWindow *window)
1470 empathy_about_dialog_new (GTK_WINDOW (window));
1474 main_window_help_debug_cb (GtkAction *action,
1475 EmpathyMainWindow *window)
1477 GdkScreen *screen = gdk_screen_get_default ();
1478 GError *error = NULL;
1479 gchar *argv[2] = { NULL, };
1483 g_return_if_fail (GDK_IS_SCREEN (screen));
1485 /* Try to run from source directory if possible */
1486 path = g_build_filename (g_getenv ("EMPATHY_SRCDIR"), "src",
1487 "empathy-debugger", NULL);
1489 if (!g_file_test (path, G_FILE_TEST_EXISTS)) {
1491 path = g_build_filename (BIN_DIR, "empathy-debugger", NULL);
1496 gdk_spawn_on_screen (screen, NULL, argv, NULL,
1497 G_SPAWN_SEARCH_PATH,
1498 NULL, NULL, NULL, &error);
1501 g_warning ("Failed to open debug window: %s", error->message);
1502 g_error_free (error);
1509 main_window_help_contents_cb (GtkAction *action,
1510 EmpathyMainWindow *window)
1512 empathy_url_show (GTK_WIDGET (window), "ghelp:empathy");
1516 main_window_throbber_button_press_event_cb (GtkWidget *throbber,
1517 GdkEventButton *event,
1518 EmpathyMainWindow *window)
1520 if (event->type != GDK_BUTTON_PRESS ||
1521 event->button != 1) {
1525 empathy_accounts_dialog_show_application (
1526 gtk_widget_get_screen (GTK_WIDGET (throbber)),
1527 NULL, FALSE, FALSE);
1533 main_window_account_removed_cb (TpAccountManager *manager,
1535 EmpathyMainWindow *window)
1537 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1540 a = tp_account_manager_get_valid_accounts (manager);
1542 gtk_action_set_sensitive (priv->view_history,
1543 g_list_length (a) > 0);
1547 /* remove errors if any */
1548 main_window_remove_error (window, account);
1552 main_window_account_validity_changed_cb (TpAccountManager *manager,
1555 EmpathyMainWindow *window)
1557 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1561 handler_id = GPOINTER_TO_UINT (g_hash_table_lookup (
1562 priv->status_changed_handlers, account));
1564 /* connect signal only if it was not connected yet */
1565 if (handler_id == 0) {
1566 handler_id = g_signal_connect (account,
1568 G_CALLBACK (main_window_connection_changed_cb),
1570 g_hash_table_insert (priv->status_changed_handlers,
1571 account, GUINT_TO_POINTER (handler_id));
1575 main_window_account_removed_cb (manager, account, window);
1579 main_window_notify_show_offline_cb (GSettings *gsettings,
1581 gpointer toggle_action)
1583 gtk_toggle_action_set_active (toggle_action,
1584 g_settings_get_boolean (gsettings, key));
1588 main_window_connection_items_setup (EmpathyMainWindow *window,
1591 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1595 const gchar *actions_connected[] = {
1597 "room_join_favorites",
1601 "edit_personal_information"
1604 for (i = 0, list = NULL; i < G_N_ELEMENTS (actions_connected); i++) {
1605 action = gtk_builder_get_object (gui, actions_connected[i]);
1606 list = g_list_prepend (list, action);
1609 priv->actions_connected = list;
1613 account_manager_prepared_cb (GObject *source_object,
1614 GAsyncResult *result,
1617 GList *accounts, *j;
1618 TpAccountManager *manager = TP_ACCOUNT_MANAGER (source_object);
1619 EmpathyMainWindow *window = user_data;
1620 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1621 GError *error = NULL;
1623 if (!tp_account_manager_prepare_finish (manager, result, &error)) {
1624 DEBUG ("Failed to prepare account manager: %s", error->message);
1625 g_error_free (error);
1629 accounts = tp_account_manager_get_valid_accounts (priv->account_manager);
1630 for (j = accounts; j != NULL; j = j->next) {
1631 TpAccount *account = TP_ACCOUNT (j->data);
1634 handler_id = g_signal_connect (account, "status-changed",
1635 G_CALLBACK (main_window_connection_changed_cb),
1637 g_hash_table_insert (priv->status_changed_handlers,
1638 account, GUINT_TO_POINTER (handler_id));
1641 g_signal_connect (manager, "account-validity-changed",
1642 G_CALLBACK (main_window_account_validity_changed_cb),
1645 main_window_update_status (window);
1647 /* Disable the "Previous Conversations" menu entry if there is no account */
1648 gtk_action_set_sensitive (priv->view_history,
1649 g_list_length (accounts) > 0);
1651 g_list_free (accounts);
1655 main_window_members_changed_cb (EmpathyContactList *list,
1656 EmpathyContact *contact,
1657 EmpathyContact *actor,
1661 EmpathyMainWindow *window)
1663 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1668 if (!empathy_migrate_butterfly_logs (contact)) {
1669 g_signal_handler_disconnect (list,
1670 priv->butterfly_log_migration_members_changed_id);
1671 priv->butterfly_log_migration_members_changed_id = 0;
1676 empathy_main_window_constructor (GType type,
1677 guint n_construct_params,
1678 GObjectConstructParam *construct_params)
1680 static GObject *window = NULL;
1683 return g_object_ref (window);
1685 window = G_OBJECT_CLASS (empathy_main_window_parent_class)->constructor (
1686 type, n_construct_params, construct_params);
1688 g_object_add_weak_pointer (window, (gpointer) &window);
1694 empathy_main_window_class_init (EmpathyMainWindowClass *klass)
1696 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1698 object_class->finalize = empathy_main_window_finalize;
1699 object_class->constructor = empathy_main_window_constructor;
1701 g_type_class_add_private (object_class, sizeof (EmpathyMainWindowPriv));
1705 empathy_main_window_init (EmpathyMainWindow *window)
1707 EmpathyMainWindowPriv *priv;
1708 EmpathyIndividualManager *individual_manager;
1711 GtkToggleAction *show_offline_widget;
1712 GtkAction *show_map_widget;
1714 gboolean show_offline;
1717 GtkTreeModel *model;
1719 priv = window->priv = G_TYPE_INSTANCE_GET_PRIVATE (window,
1720 EMPATHY_TYPE_MAIN_WINDOW, EmpathyMainWindowPriv);
1722 priv->gsettings_ui = g_settings_new (EMPATHY_PREFS_UI_SCHEMA);
1723 priv->gsettings_contacts = g_settings_new (EMPATHY_PREFS_CONTACTS_SCHEMA);
1725 priv->sound_mgr = empathy_sound_manager_dup_singleton ();
1727 gtk_window_set_title (GTK_WINDOW (window), _("Contact List"));
1728 gtk_window_set_role (GTK_WINDOW (window), "contact_list");
1729 gtk_window_set_default_size (GTK_WINDOW (window), 225, 325);
1731 /* Set up interface */
1732 filename = empathy_file_lookup ("empathy-main-window.ui", "src");
1733 gui = empathy_builder_get_file (filename,
1734 "main_vbox", &priv->main_vbox,
1735 "errors_vbox", &priv->errors_vbox,
1736 "auth_vbox", &priv->auth_vbox,
1737 "ui_manager", &priv->ui_manager,
1738 "view_show_offline", &show_offline_widget,
1739 "view_show_protocols", &priv->show_protocols,
1740 "view_sort_by_name", &priv->sort_by_name,
1741 "view_sort_by_status", &priv->sort_by_status,
1742 "view_normal_size_with_avatars", &priv->normal_with_avatars,
1743 "view_normal_size", &priv->normal_size,
1744 "view_compact_size", &priv->compact_size,
1745 "view_history", &priv->view_history,
1746 "view_show_map", &show_map_widget,
1747 "room_join_favorites", &priv->room_join_favorites,
1748 "presence_toolbar", &priv->presence_toolbar,
1749 "notebook", &priv->notebook,
1750 "no_entry_label", &priv->no_entry_label,
1751 "roster_scrolledwindow", &sw,
1755 gtk_container_add (GTK_CONTAINER (window), priv->main_vbox);
1756 gtk_widget_show (priv->main_vbox);
1758 g_signal_connect (window, "key-press-event",
1759 G_CALLBACK (main_window_key_press_event_cb), NULL);
1761 empathy_builder_connect (gui, window,
1762 "chat_quit", "activate", main_window_chat_quit_cb,
1763 "chat_new_message", "activate", main_window_chat_new_message_cb,
1764 "chat_new_call", "activate", main_window_chat_new_call_cb,
1765 "view_history", "activate", main_window_view_history_cb,
1766 "room_join_new", "activate", main_window_room_join_new_cb,
1767 "room_join_favorites", "activate", main_window_room_join_favorites_cb,
1768 "room_manage_favorites", "activate", main_window_room_manage_favorites_cb,
1769 "chat_add_contact", "activate", main_window_chat_add_contact_cb,
1770 "view_show_ft_manager", "activate", main_window_view_show_ft_manager,
1771 "view_show_offline", "toggled", main_window_view_show_offline_cb,
1772 "view_show_protocols", "toggled", main_window_view_show_protocols_cb,
1773 "view_sort_by_name", "changed", main_window_view_sort_contacts_cb,
1774 "view_normal_size_with_avatars", "changed", main_window_view_contacts_list_size_cb,
1775 "view_show_map", "activate", main_window_view_show_map_cb,
1776 "edit", "activate", main_window_edit_cb,
1777 "edit_accounts", "activate", main_window_edit_accounts_cb,
1778 "edit_personal_information", "activate", main_window_edit_personal_information_cb,
1779 "edit_preferences", "activate", main_window_edit_preferences_cb,
1780 "edit_search_contacts", "activate", main_window_edit_search_contacts_cb,
1781 "help_about", "activate", main_window_help_about_cb,
1782 "help_debug", "activate", main_window_help_debug_cb,
1783 "help_contents", "activate", main_window_help_contents_cb,
1786 /* Set up connection related widgets. */
1787 main_window_connection_items_setup (window, gui);
1789 g_object_ref (priv->ui_manager);
1790 g_object_unref (gui);
1792 #ifndef HAVE_LIBCHAMPLAIN
1793 gtk_action_set_visible (show_map_widget, FALSE);
1796 priv->account_manager = tp_account_manager_dup ();
1798 tp_account_manager_prepare_async (priv->account_manager, NULL,
1799 account_manager_prepared_cb, window);
1801 priv->errors = g_hash_table_new_full (g_direct_hash,
1806 priv->auths = g_hash_table_new_full (g_direct_hash,
1811 priv->status_changed_handlers = g_hash_table_new_full (g_direct_hash,
1817 main_window_favorite_chatroom_menu_setup (window);
1819 priv->edit_context = gtk_ui_manager_get_widget (priv->ui_manager,
1820 "/menubar/edit/edit_context");
1821 priv->edit_context_separator = gtk_ui_manager_get_widget (
1823 "/menubar/edit/edit_context_separator");
1824 gtk_widget_hide (priv->edit_context);
1825 gtk_widget_hide (priv->edit_context_separator);
1827 /* Set up contact list. */
1828 empathy_status_presets_get_all ();
1830 /* Set up presence chooser */
1831 priv->presence_chooser = empathy_presence_chooser_new ();
1832 gtk_widget_show (priv->presence_chooser);
1833 item = gtk_tool_item_new ();
1834 gtk_widget_show (GTK_WIDGET (item));
1835 gtk_container_add (GTK_CONTAINER (item), priv->presence_chooser);
1836 gtk_tool_item_set_is_important (item, TRUE);
1837 gtk_tool_item_set_expand (item, TRUE);
1838 gtk_toolbar_insert (GTK_TOOLBAR (priv->presence_toolbar), item, -1);
1840 /* Set up the throbber */
1841 priv->throbber = gtk_spinner_new ();
1842 gtk_widget_set_size_request (priv->throbber, 16, -1);
1843 gtk_widget_set_tooltip_text (priv->throbber, _("Show and edit accounts"));
1844 gtk_widget_set_events (priv->throbber, GDK_BUTTON_PRESS_MASK);
1845 g_signal_connect (priv->throbber, "button-press-event",
1846 G_CALLBACK (main_window_throbber_button_press_event_cb),
1848 gtk_widget_show (priv->throbber);
1850 item = gtk_tool_item_new ();
1851 gtk_container_set_border_width (GTK_CONTAINER (item), 6);
1852 gtk_toolbar_insert (GTK_TOOLBAR (priv->presence_toolbar), item, -1);
1853 gtk_container_add (GTK_CONTAINER (item), priv->throbber);
1854 priv->throbber_tool_item = GTK_WIDGET (item);
1856 /* XXX: this class is designed to live for the duration of the program,
1857 * so it's got a race condition between its signal handlers and its
1858 * finalization. The class is planned to be removed, so we won't fix
1859 * this before then. */
1860 priv->contact_manager = EMPATHY_CONTACT_LIST (
1861 empathy_contact_manager_dup_singleton ());
1862 individual_manager = empathy_individual_manager_dup_singleton ();
1863 priv->individual_store = empathy_individual_store_new (
1864 individual_manager);
1865 g_object_unref (individual_manager);
1867 /* For the moment, we disallow Persona drops onto the main contact list (e.g. from things such as
1868 * the EmpathyPersonaView in the linking dialogue). No code is hooked up to do anything on a Persona
1869 * drop, so allowing them would achieve nothing except confusion. */
1870 priv->individual_view = empathy_individual_view_new (
1871 priv->individual_store,
1872 EMPATHY_INDIVIDUAL_VIEW_FEATURE_ALL ^ EMPATHY_INDIVIDUAL_VIEW_FEATURE_PERSONA_DROP,
1873 EMPATHY_INDIVIDUAL_FEATURE_ALL);
1875 priv->butterfly_log_migration_members_changed_id = g_signal_connect (
1876 priv->contact_manager, "members-changed",
1877 G_CALLBACK (main_window_members_changed_cb), window);
1879 gtk_widget_show (GTK_WIDGET (priv->individual_view));
1880 gtk_container_add (GTK_CONTAINER (sw),
1881 GTK_WIDGET (priv->individual_view));
1882 g_signal_connect (priv->individual_view, "row-activated",
1883 G_CALLBACK (main_window_row_activated_cb),
1886 /* Set up search bar */
1887 priv->search_bar = empathy_live_search_new (
1888 GTK_WIDGET (priv->individual_view));
1889 empathy_individual_view_set_live_search (priv->individual_view,
1890 EMPATHY_LIVE_SEARCH (priv->search_bar));
1891 gtk_box_pack_start (GTK_BOX (priv->main_vbox), priv->search_bar,
1893 g_signal_connect_swapped (window, "map",
1894 G_CALLBACK (gtk_widget_grab_focus), priv->individual_view);
1896 /* Connect to proper signals to check if contact list is empty or not */
1897 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->individual_view));
1899 g_signal_connect (model, "row-inserted",
1900 G_CALLBACK (main_window_row_inserted_cb),
1902 g_signal_connect (model, "row-deleted",
1903 G_CALLBACK (main_window_row_deleted_cb),
1906 /* Load user-defined accelerators. */
1907 main_window_accels_load ();
1909 /* Set window size. */
1910 empathy_geometry_bind (GTK_WINDOW (window), GEOMETRY_NAME);
1912 /* Enable event handling */
1913 priv->event_manager = empathy_event_manager_dup_singleton ();
1915 g_signal_connect (priv->event_manager, "event-added",
1916 G_CALLBACK (main_window_event_added_cb), window);
1917 g_signal_connect (priv->event_manager, "event-removed",
1918 G_CALLBACK (main_window_event_removed_cb), window);
1919 g_signal_connect (priv->account_manager, "account-validity-changed",
1920 G_CALLBACK (main_window_account_validity_changed_cb),
1922 g_signal_connect (priv->account_manager, "account-removed",
1923 G_CALLBACK (main_window_account_removed_cb),
1925 g_signal_connect (priv->account_manager, "account-disabled",
1926 G_CALLBACK (main_window_account_disabled_cb),
1929 l = empathy_event_manager_get_events (priv->event_manager);
1931 main_window_event_added_cb (priv->event_manager, l->data,
1936 /* Show offline ? */
1937 show_offline = g_settings_get_boolean (priv->gsettings_ui,
1938 EMPATHY_PREFS_UI_SHOW_OFFLINE);
1939 g_signal_connect (priv->gsettings_ui,
1940 "changed::" EMPATHY_PREFS_UI_SHOW_OFFLINE,
1941 G_CALLBACK (main_window_notify_show_offline_cb),
1942 show_offline_widget);
1944 gtk_toggle_action_set_active (show_offline_widget, show_offline);
1946 /* Show protocol ? */
1947 g_signal_connect (priv->gsettings_ui,
1948 "changed::" EMPATHY_PREFS_UI_SHOW_PROTOCOLS,
1949 G_CALLBACK (main_window_notify_show_protocols_cb),
1952 main_window_notify_show_protocols_cb (priv->gsettings_ui,
1953 EMPATHY_PREFS_UI_SHOW_PROTOCOLS,
1956 /* Sort by name / by status ? */
1957 g_signal_connect (priv->gsettings_contacts,
1958 "changed::" EMPATHY_PREFS_CONTACTS_SORT_CRITERIUM,
1959 G_CALLBACK (main_window_notify_sort_contact_cb),
1962 main_window_notify_sort_contact_cb (priv->gsettings_contacts,
1963 EMPATHY_PREFS_CONTACTS_SORT_CRITERIUM,
1966 /* Contacts list size */
1967 g_signal_connect (priv->gsettings_ui,
1968 "changed::" EMPATHY_PREFS_UI_COMPACT_CONTACT_LIST,
1969 G_CALLBACK (main_window_notify_contact_list_size_cb),
1971 g_signal_connect (priv->gsettings_ui,
1972 "changed::" EMPATHY_PREFS_UI_SHOW_AVATARS,
1973 G_CALLBACK (main_window_notify_contact_list_size_cb),
1976 main_window_notify_contact_list_size_cb (priv->gsettings_ui,
1977 EMPATHY_PREFS_UI_SHOW_AVATARS,
1982 empathy_main_window_dup (void)
1984 return g_object_new (EMPATHY_TYPE_MAIN_WINDOW, NULL);