1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * Copyright (C) 2002-2007 Imendio AB
4 * Copyright (C) 2007-2010 Collabora Ltd.
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public
17 * License along with this program; if not, write to the
18 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 * Boston, MA 02110-1301 USA
21 * Authors: Xavier Claessens <xclaesse@gmail.com>
22 * Danielle Madeley <danielle.madeley@collabora.co.uk>
29 #include <gdk/gdkkeysyms.h>
30 #include <glib/gi18n.h>
32 #include <telepathy-glib/account-manager.h>
33 #include <telepathy-glib/util.h>
34 #include <folks/folks.h>
36 #include <libempathy/empathy-contact.h>
37 #include <libempathy/empathy-utils.h>
38 #include <libempathy/empathy-dispatcher.h>
39 #include <libempathy/empathy-chatroom-manager.h>
40 #include <libempathy/empathy-chatroom.h>
41 #include <libempathy/empathy-contact-list.h>
42 #include <libempathy/empathy-contact-manager.h>
43 #include <libempathy/empathy-gsettings.h>
44 #include <libempathy/empathy-individual-manager.h>
45 #include <libempathy/empathy-gsettings.h>
46 #include <libempathy/empathy-status-presets.h>
47 #include <libempathy/empathy-tp-contact-factory.h>
49 #include <libempathy-gtk/empathy-contact-dialogs.h>
50 #include <libempathy-gtk/empathy-contact-list-store.h>
51 #include <libempathy-gtk/empathy-contact-list-view.h>
52 #include <libempathy-gtk/empathy-live-search.h>
53 #include <libempathy-gtk/empathy-contact-search-dialog.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-call-observer.h"
68 #include "empathy-chat-manager.h"
69 #include "empathy-main-window.h"
70 #include "empathy-preferences.h"
71 #include "empathy-about-dialog.h"
72 #include "empathy-debug-window.h"
73 #include "empathy-new-chatroom-dialog.h"
74 #include "empathy-map-view.h"
75 #include "empathy-chatrooms-window.h"
76 #include "empathy-event-manager.h"
77 #include "empathy-ft-manager.h"
78 #include "empathy-migrate-butterfly-logs.h"
80 #define DEBUG_FLAG EMPATHY_DEBUG_OTHER
81 #include <libempathy/empathy-debug.h>
83 /* Flashing delay for icons (milliseconds). */
84 #define FLASH_TIMEOUT 500
86 /* Minimum width of roster window if something goes wrong. */
89 /* Accels (menu shortcuts) can be configured and saved */
90 #define ACCELS_FILENAME "accels.txt"
92 /* Name in the geometry file */
93 #define GEOMETRY_NAME "main-window"
96 PAGE_CONTACT_LIST = 0,
100 G_DEFINE_TYPE (EmpathyMainWindow, empathy_main_window, GTK_TYPE_WINDOW);
102 #define GET_PRIV(self) ((EmpathyMainWindowPriv *)((EmpathyMainWindow *) self)->priv)
104 struct _EmpathyMainWindowPriv {
105 EmpathyContactList *contact_manager;
106 EmpathyIndividualStore *individual_store;
107 EmpathyIndividualView *individual_view;
108 TpAccountManager *account_manager;
109 EmpathyChatroomManager *chatroom_manager;
110 EmpathyEventManager *event_manager;
111 EmpathySoundManager *sound_mgr;
112 EmpathyCallObserver *call_observer;
113 guint flash_timeout_id;
117 GSettings *gsettings_ui;
118 GSettings *gsettings_contacts;
120 GtkWidget *preferences;
121 GtkWidget *main_vbox;
123 GtkWidget *throbber_tool_item;
124 GtkWidget *presence_toolbar;
125 GtkWidget *presence_chooser;
126 GtkWidget *errors_vbox;
127 GtkWidget *auth_vbox;
128 GtkWidget *search_bar;
130 GtkWidget *no_entry_label;
132 GtkToggleAction *show_protocols;
133 GtkRadioAction *sort_by_name;
134 GtkRadioAction *sort_by_status;
135 GtkRadioAction *normal_with_avatars;
136 GtkRadioAction *normal_size;
137 GtkRadioAction *compact_size;
139 GtkUIManager *ui_manager;
140 GtkAction *view_history;
141 GtkAction *room_join_favorites;
142 GtkWidget *room_menu;
143 GtkWidget *room_separator;
144 GtkWidget *edit_context;
145 GtkWidget *edit_context_separator;
147 guint size_timeout_id;
149 /* reffed TpAccount* => visible GtkInfoBar* */
152 /* EmpathyEvent* => visible GtkInfoBar* */
155 /* stores a mapping from TpAccount to Handler ID to prevent
156 * to listen more than once to the status-changed signal */
157 GHashTable *status_changed_handlers;
159 /* Actions that are enabled when there are connected accounts */
160 GList *actions_connected;
162 /* The idle event source to migrate butterfly's logs */
163 guint butterfly_log_migration_members_changed_id;
167 main_window_flash_stop (EmpathyMainWindow *window)
169 EmpathyMainWindowPriv *priv = GET_PRIV (window);
171 if (priv->flash_timeout_id == 0) {
175 DEBUG ("Stop flashing");
176 g_source_remove (priv->flash_timeout_id);
177 priv->flash_timeout_id = 0;
178 priv->flash_on = FALSE;
184 EmpathyMainWindow *window;
188 main_window_flash_foreach (GtkTreeModel *model,
193 FlashForeachData *data = (FlashForeachData *) user_data;
194 FolksIndividual *individual;
195 EmpathyContact *contact;
196 const gchar *icon_name;
197 GtkTreePath *parent_path = NULL;
198 GtkTreeIter parent_iter;
199 GdkPixbuf *pixbuf = NULL;
201 gtk_tree_model_get (model, iter,
202 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL,
206 if (individual == NULL)
209 contact = empathy_contact_dup_from_folks_individual (individual);
210 if (contact != data->event->contact) {
211 tp_clear_object (&contact);
216 icon_name = data->event->icon_name;
217 pixbuf = empathy_pixbuf_from_icon_name (icon_name, GTK_ICON_SIZE_MENU);
219 pixbuf = empathy_individual_store_get_individual_status_icon (
220 GET_PRIV (data->window)->individual_store,
224 gtk_tree_store_set (GTK_TREE_STORE (model), iter,
225 EMPATHY_INDIVIDUAL_STORE_COL_ICON_STATUS, pixbuf,
228 /* To make sure the parent is shown correctly, we emit
229 * the row-changed signal on the parent so it prompts
230 * it to be refreshed by the filter func.
232 if (gtk_tree_model_iter_parent (model, &parent_iter, iter)) {
233 parent_path = gtk_tree_model_get_path (model, &parent_iter);
236 gtk_tree_model_row_changed (model, parent_path, &parent_iter);
237 gtk_tree_path_free (parent_path);
240 g_object_unref (individual);
241 tp_clear_object (&contact);
247 main_window_flash_cb (EmpathyMainWindow *window)
249 EmpathyMainWindowPriv *priv = GET_PRIV (window);
252 gboolean found_event = FALSE;
253 FlashForeachData data;
255 priv->flash_on = !priv->flash_on;
256 data.on = priv->flash_on;
257 model = GTK_TREE_MODEL (priv->individual_store);
259 events = empathy_event_manager_get_events (priv->event_manager);
260 for (l = events; l; l = l->next) {
261 data.event = l->data;
262 data.window = window;
263 if (!data.event->contact || !data.event->must_ack) {
268 gtk_tree_model_foreach (model,
269 main_window_flash_foreach,
274 main_window_flash_stop (window);
281 main_window_flash_start (EmpathyMainWindow *window)
283 EmpathyMainWindowPriv *priv = GET_PRIV (window);
285 if (priv->flash_timeout_id != 0) {
289 DEBUG ("Start flashing");
290 priv->flash_timeout_id = g_timeout_add (FLASH_TIMEOUT,
291 (GSourceFunc) main_window_flash_cb,
293 main_window_flash_cb (window);
297 main_window_remove_auth (EmpathyMainWindow *window,
300 EmpathyMainWindowPriv *priv = GET_PRIV (window);
301 GtkWidget *error_widget;
303 error_widget = g_hash_table_lookup (priv->auths, event);
304 if (error_widget != NULL) {
305 gtk_widget_destroy (error_widget);
306 g_hash_table_remove (priv->auths, event);
311 main_window_auth_add_clicked_cb (GtkButton *button,
312 EmpathyMainWindow *window)
316 event = g_object_get_data (G_OBJECT (button), "event");
318 empathy_event_approve (event);
320 main_window_remove_auth (window, event);
324 main_window_auth_close_clicked_cb (GtkButton *button,
325 EmpathyMainWindow *window)
329 event = g_object_get_data (G_OBJECT (button), "event");
331 empathy_event_decline (event);
332 main_window_remove_auth (window, event);
336 main_window_auth_display (EmpathyMainWindow *window,
339 EmpathyMainWindowPriv *priv = GET_PRIV (window);
340 TpAccount *account = event->account;
342 GtkWidget *content_area;
345 GtkWidget *add_button;
346 GtkWidget *close_button;
347 GtkWidget *action_area;
348 GtkWidget *action_table;
349 const gchar *icon_name;
352 if (g_hash_table_lookup (priv->auths, event) != NULL) {
356 info_bar = gtk_info_bar_new ();
357 gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_QUESTION);
359 gtk_widget_set_no_show_all (info_bar, TRUE);
360 gtk_box_pack_start (GTK_BOX (priv->auth_vbox), info_bar, FALSE, TRUE, 0);
361 gtk_widget_show (info_bar);
363 icon_name = tp_account_get_icon_name (account);
364 image = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_SMALL_TOOLBAR);
365 gtk_widget_show (image);
367 str = g_markup_printf_escaped ("<b>%s</b>\n%s",
368 tp_account_get_display_name (account),
369 _("Password required"));
371 label = gtk_label_new (str);
372 gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
373 gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_END);
374 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
375 gtk_widget_show (label);
379 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
380 gtk_box_pack_start (GTK_BOX (content_area), image, FALSE, FALSE, 0);
381 gtk_box_pack_start (GTK_BOX (content_area), label, TRUE, TRUE, 0);
383 image = gtk_image_new_from_stock (GTK_STOCK_ADD, GTK_ICON_SIZE_BUTTON);
384 add_button = gtk_button_new ();
385 gtk_button_set_image (GTK_BUTTON (add_button), image);
386 gtk_widget_set_tooltip_text (add_button, _("Provide Password"));
387 gtk_widget_show (add_button);
389 image = gtk_image_new_from_stock (GTK_STOCK_CLOSE, GTK_ICON_SIZE_BUTTON);
390 close_button = gtk_button_new ();
391 gtk_button_set_image (GTK_BUTTON (close_button), image);
392 gtk_widget_set_tooltip_text (close_button, _("Disconnect"));
393 gtk_widget_show (close_button);
395 action_table = gtk_table_new (1, 2, FALSE);
396 gtk_table_set_col_spacings (GTK_TABLE (action_table), 6);
397 gtk_widget_show (action_table);
399 action_area = gtk_info_bar_get_action_area (GTK_INFO_BAR (info_bar));
400 gtk_box_pack_start (GTK_BOX (action_area), action_table, FALSE, FALSE, 0);
402 gtk_table_attach (GTK_TABLE (action_table), add_button, 0, 1, 0, 1,
403 (GtkAttachOptions) (GTK_SHRINK),
404 (GtkAttachOptions) (GTK_SHRINK), 0, 0);
405 gtk_table_attach (GTK_TABLE (action_table), close_button, 1, 2, 0, 1,
406 (GtkAttachOptions) (GTK_SHRINK),
407 (GtkAttachOptions) (GTK_SHRINK), 0, 0);
409 g_object_set_data_full (G_OBJECT (info_bar),
410 "event", event, NULL);
411 g_object_set_data_full (G_OBJECT (add_button),
412 "event", event, NULL);
413 g_object_set_data_full (G_OBJECT (close_button),
414 "event", event, NULL);
416 g_signal_connect (add_button, "clicked",
417 G_CALLBACK (main_window_auth_add_clicked_cb),
419 g_signal_connect (close_button, "clicked",
420 G_CALLBACK (main_window_auth_close_clicked_cb),
423 gtk_widget_show (priv->auth_vbox);
425 g_hash_table_insert (priv->auths, event, info_bar);
429 main_window_event_added_cb (EmpathyEventManager *manager,
431 EmpathyMainWindow *window)
433 if (event->contact) {
434 main_window_flash_start (window);
435 } else if (event->type == EMPATHY_EVENT_TYPE_AUTH) {
436 main_window_auth_display (window, event);
441 main_window_event_removed_cb (EmpathyEventManager *manager,
443 EmpathyMainWindow *window)
445 EmpathyMainWindowPriv *priv = GET_PRIV (window);
446 FlashForeachData data;
448 if (event->type == EMPATHY_EVENT_TYPE_AUTH) {
449 main_window_remove_auth (window, event);
453 if (!event->contact) {
459 data.window = window;
460 gtk_tree_model_foreach (GTK_TREE_MODEL (priv->individual_store),
461 main_window_flash_foreach,
466 main_window_row_activated_cb (EmpathyContactListView *view,
468 GtkTreeViewColumn *col,
469 EmpathyMainWindow *window)
471 EmpathyMainWindowPriv *priv = GET_PRIV (window);
472 EmpathyContact *contact = NULL;
473 FolksIndividual *individual;
478 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->individual_view));
479 gtk_tree_model_get_iter (model, &iter, path);
481 gtk_tree_model_get (model, &iter,
482 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL,
486 if (individual != NULL) {
487 contact = empathy_contact_dup_from_folks_individual (individual);
494 /* If the contact has an event activate it, otherwise the
495 * default handler of row-activated will be called. */
496 events = empathy_event_manager_get_events (priv->event_manager);
497 for (l = events; l; l = l->next) {
498 EmpathyEvent *event = l->data;
500 if (event->contact == contact) {
501 DEBUG ("Activate event");
502 empathy_event_activate (event);
504 /* We don't want the default handler of this signal
505 * (e.g. open a chat) */
506 g_signal_stop_emission_by_name (view, "row-activated");
511 g_object_unref (contact);
513 tp_clear_object (&individual);
517 main_window_row_deleted_cb (GtkTreeModel *model,
519 EmpathyMainWindow *window)
521 EmpathyMainWindowPriv *priv = GET_PRIV (window);
522 GtkTreeIter help_iter;
524 if (!gtk_tree_model_get_iter_first (model, &help_iter)) {
527 if (empathy_individual_view_is_searching (
528 priv->individual_view)) {
531 tmp = g_strdup_printf ("<b><span size='xx-large'>%s</span></b>",
532 _("No match found"));
534 gtk_label_set_markup (GTK_LABEL (priv->no_entry_label), tmp);
537 gtk_label_set_line_wrap (GTK_LABEL (priv->no_entry_label),
540 gtk_notebook_set_current_page (
541 GTK_NOTEBOOK (priv->notebook), PAGE_NO_MATCH);
547 main_window_row_inserted_cb (GtkTreeModel *model,
550 EmpathyMainWindow *window)
552 EmpathyMainWindowPriv *priv = GET_PRIV (window);
556 gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook),
558 gtk_widget_grab_focus (GTK_WIDGET (priv->individual_view));
563 main_window_remove_error (EmpathyMainWindow *window,
566 EmpathyMainWindowPriv *priv = GET_PRIV (window);
567 GtkWidget *error_widget;
569 error_widget = g_hash_table_lookup (priv->errors, account);
570 if (error_widget != NULL) {
571 gtk_widget_destroy (error_widget);
572 g_hash_table_remove (priv->errors, account);
577 main_window_account_disabled_cb (TpAccountManager *manager,
579 EmpathyMainWindow *window)
581 main_window_remove_error (window, account);
585 main_window_error_retry_clicked_cb (GtkButton *button,
586 EmpathyMainWindow *window)
590 account = g_object_get_data (G_OBJECT (button), "account");
591 tp_account_reconnect_async (account, NULL, NULL);
593 main_window_remove_error (window, account);
597 main_window_error_edit_clicked_cb (GtkButton *button,
598 EmpathyMainWindow *window)
602 account = g_object_get_data (G_OBJECT (button), "account");
604 empathy_accounts_dialog_show_application (
605 gtk_widget_get_screen (GTK_WIDGET (button)),
606 account, FALSE, FALSE);
608 main_window_remove_error (window, account);
612 main_window_error_close_clicked_cb (GtkButton *button,
613 EmpathyMainWindow *window)
617 account = g_object_get_data (G_OBJECT (button), "account");
618 main_window_remove_error (window, account);
622 main_window_error_display (EmpathyMainWindow *window,
625 EmpathyMainWindowPriv *priv = GET_PRIV (window);
627 GtkWidget *content_area;
630 GtkWidget *retry_button;
631 GtkWidget *edit_button;
632 GtkWidget *close_button;
633 GtkWidget *action_area;
634 GtkWidget *action_table;
636 const gchar *icon_name;
637 const gchar *error_message;
638 gboolean user_requested;
641 empathy_account_get_error_message (account, &user_requested);
643 if (user_requested) {
647 str = g_markup_printf_escaped ("<b>%s</b>\n%s",
648 tp_account_get_display_name (account),
651 info_bar = g_hash_table_lookup (priv->errors, account);
653 label = g_object_get_data (G_OBJECT (info_bar), "label");
655 /* Just set the latest error and return */
656 gtk_label_set_markup (GTK_LABEL (label), str);
662 info_bar = gtk_info_bar_new ();
663 gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_ERROR);
665 gtk_widget_set_no_show_all (info_bar, TRUE);
666 gtk_box_pack_start (GTK_BOX (priv->errors_vbox), info_bar, FALSE, TRUE, 0);
667 gtk_widget_show (info_bar);
669 icon_name = tp_account_get_icon_name (account);
670 image = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_SMALL_TOOLBAR);
671 gtk_widget_show (image);
673 label = gtk_label_new (str);
674 gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
675 gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_END);
676 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
677 gtk_widget_show (label);
680 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
681 gtk_box_pack_start (GTK_BOX (content_area), image, FALSE, FALSE, 0);
682 gtk_box_pack_start (GTK_BOX (content_area), label, TRUE, TRUE, 0);
684 image = gtk_image_new_from_stock (GTK_STOCK_REFRESH, GTK_ICON_SIZE_BUTTON);
685 retry_button = gtk_button_new ();
686 gtk_button_set_image (GTK_BUTTON (retry_button), image);
687 gtk_widget_set_tooltip_text (retry_button, _("Reconnect"));
688 gtk_widget_show (retry_button);
690 image = gtk_image_new_from_stock (GTK_STOCK_EDIT, GTK_ICON_SIZE_BUTTON);
691 edit_button = gtk_button_new ();
692 gtk_button_set_image (GTK_BUTTON (edit_button), image);
693 gtk_widget_set_tooltip_text (edit_button, _("Edit Account"));
694 gtk_widget_show (edit_button);
696 image = gtk_image_new_from_stock (GTK_STOCK_CLOSE, GTK_ICON_SIZE_BUTTON);
697 close_button = gtk_button_new ();
698 gtk_button_set_image (GTK_BUTTON (close_button), image);
699 gtk_widget_set_tooltip_text (close_button, _("Close"));
700 gtk_widget_show (close_button);
702 action_table = gtk_table_new (1, 3, FALSE);
703 gtk_table_set_col_spacings (GTK_TABLE (action_table), 2);
704 gtk_widget_show (action_table);
706 action_area = gtk_info_bar_get_action_area (GTK_INFO_BAR (info_bar));
707 gtk_box_pack_start (GTK_BOX (action_area), action_table, FALSE, FALSE, 0);
709 gtk_table_attach (GTK_TABLE (action_table), retry_button, 0, 1, 0, 1,
710 (GtkAttachOptions) (GTK_SHRINK),
711 (GtkAttachOptions) (GTK_SHRINK), 0, 0);
712 gtk_table_attach (GTK_TABLE (action_table), edit_button, 1, 2, 0, 1,
713 (GtkAttachOptions) (GTK_SHRINK),
714 (GtkAttachOptions) (GTK_SHRINK), 0, 0);
715 gtk_table_attach (GTK_TABLE (action_table), close_button, 2, 3, 0, 1,
716 (GtkAttachOptions) (GTK_SHRINK),
717 (GtkAttachOptions) (GTK_SHRINK), 0, 0);
719 g_object_set_data (G_OBJECT (info_bar), "label", label);
720 g_object_set_data_full (G_OBJECT (info_bar),
721 "account", g_object_ref (account),
723 g_object_set_data_full (G_OBJECT (edit_button),
724 "account", g_object_ref (account),
726 g_object_set_data_full (G_OBJECT (close_button),
727 "account", g_object_ref (account),
729 g_object_set_data_full (G_OBJECT (retry_button),
730 "account", g_object_ref (account),
733 g_signal_connect (edit_button, "clicked",
734 G_CALLBACK (main_window_error_edit_clicked_cb),
736 g_signal_connect (close_button, "clicked",
737 G_CALLBACK (main_window_error_close_clicked_cb),
739 g_signal_connect (retry_button, "clicked",
740 G_CALLBACK (main_window_error_retry_clicked_cb),
743 gtk_widget_set_tooltip_text (priv->errors_vbox, error_message);
744 gtk_widget_show (priv->errors_vbox);
746 g_hash_table_insert (priv->errors, g_object_ref (account), info_bar);
750 main_window_update_status (EmpathyMainWindow *window)
752 EmpathyMainWindowPriv *priv = GET_PRIV (window);
753 gboolean connected, connecting;
756 connected = empathy_account_manager_get_accounts_connected (&connecting);
758 /* Update the spinner state */
760 gtk_spinner_start (GTK_SPINNER (priv->throbber));
761 gtk_widget_show (priv->throbber_tool_item);
763 gtk_spinner_stop (GTK_SPINNER (priv->throbber));
764 gtk_widget_hide (priv->throbber_tool_item);
767 /* Update widgets sensibility */
768 for (l = priv->actions_connected; l; l = l->next) {
769 gtk_action_set_sensitive (l->data, connected);
772 /* Update favourite rooms sensitivity */
773 children = gtk_container_get_children (GTK_CONTAINER (priv->room_menu));
774 for (l = children; l != NULL; l = l->next) {
775 if (g_object_get_data (G_OBJECT (l->data), "is_favorite") != NULL) {
776 gtk_widget_set_sensitive (GTK_WIDGET (l->data), connected);
779 g_list_free (children);
783 main_window_connection_changed_cb (TpAccount *account,
787 gchar *dbus_error_name,
789 EmpathyMainWindow *window)
791 EmpathyMainWindowPriv *priv = GET_PRIV (window);
793 main_window_update_status (window);
795 if (current == TP_CONNECTION_STATUS_DISCONNECTED &&
796 reason != TP_CONNECTION_STATUS_REASON_REQUESTED) {
797 main_window_error_display (window, account);
800 if (current == TP_CONNECTION_STATUS_DISCONNECTED) {
801 empathy_sound_manager_play (priv->sound_mgr, GTK_WIDGET (window),
802 EMPATHY_SOUND_ACCOUNT_DISCONNECTED);
805 if (current == TP_CONNECTION_STATUS_CONNECTED) {
806 empathy_sound_manager_play (priv->sound_mgr, GTK_WIDGET (window),
807 EMPATHY_SOUND_ACCOUNT_CONNECTED);
809 /* Account connected without error, remove error message if any */
810 main_window_remove_error (window, account);
815 main_window_accels_load (void)
819 filename = g_build_filename (g_get_user_config_dir (), PACKAGE_NAME, ACCELS_FILENAME, NULL);
820 if (g_file_test (filename, G_FILE_TEST_EXISTS)) {
821 DEBUG ("Loading from:'%s'", filename);
822 gtk_accel_map_load (filename);
829 main_window_accels_save (void)
832 gchar *file_with_path;
834 dir = g_build_filename (g_get_user_config_dir (), PACKAGE_NAME, NULL);
835 g_mkdir_with_parents (dir, S_IRUSR | S_IWUSR | S_IXUSR);
836 file_with_path = g_build_filename (dir, ACCELS_FILENAME, NULL);
839 DEBUG ("Saving to:'%s'", file_with_path);
840 gtk_accel_map_save (file_with_path);
842 g_free (file_with_path);
846 empathy_main_window_finalize (GObject *window)
848 EmpathyMainWindowPriv *priv = GET_PRIV (window);
852 /* Save user-defined accelerators. */
853 main_window_accels_save ();
855 g_list_free (priv->actions_connected);
857 g_object_unref (priv->account_manager);
858 g_object_unref (priv->individual_store);
859 g_object_unref (priv->contact_manager);
860 g_object_unref (priv->sound_mgr);
861 g_hash_table_destroy (priv->errors);
862 g_hash_table_destroy (priv->auths);
864 /* disconnect all handlers of status-changed signal */
865 g_hash_table_iter_init (&iter, priv->status_changed_handlers);
866 while (g_hash_table_iter_next (&iter, &key, &value))
867 g_signal_handler_disconnect (TP_ACCOUNT (key),
868 GPOINTER_TO_UINT (value));
870 g_hash_table_destroy (priv->status_changed_handlers);
872 g_signal_handlers_disconnect_by_func (priv->event_manager,
873 main_window_event_added_cb,
875 g_signal_handlers_disconnect_by_func (priv->event_manager,
876 main_window_event_removed_cb,
879 g_object_unref (priv->call_observer);
881 g_object_unref (priv->event_manager);
882 g_object_unref (priv->ui_manager);
883 g_object_unref (priv->chatroom_manager);
885 g_object_unref (priv->gsettings_ui);
886 g_object_unref (priv->gsettings_contacts);
888 G_OBJECT_CLASS (empathy_main_window_parent_class)->finalize (window);
892 main_window_key_press_event_cb (GtkWidget *window,
896 EmpathyChatManager *chat_manager;
898 if (event->keyval == GDK_KEY_T
899 && event->state & GDK_SHIFT_MASK
900 && event->state & GDK_CONTROL_MASK) {
901 chat_manager = empathy_chat_manager_dup_singleton ();
902 empathy_chat_manager_undo_closed_chat (chat_manager);
903 g_object_unref (chat_manager);
909 main_window_chat_quit_cb (GtkAction *action,
910 EmpathyMainWindow *window)
916 main_window_view_history_cb (GtkAction *action,
917 EmpathyMainWindow *window)
919 empathy_log_window_show (NULL, NULL, FALSE, GTK_WINDOW (window));
923 main_window_chat_new_message_cb (GtkAction *action,
924 EmpathyMainWindow *window)
926 empathy_new_message_dialog_show (GTK_WINDOW (window));
930 main_window_chat_new_call_cb (GtkAction *action,
931 EmpathyMainWindow *window)
933 empathy_new_call_dialog_show (GTK_WINDOW (window));
937 main_window_chat_add_contact_cb (GtkAction *action,
938 EmpathyMainWindow *window)
940 empathy_new_individual_dialog_show (GTK_WINDOW (window));
944 main_window_chat_search_contacts_cb (GtkAction *action,
945 EmpathyMainWindow *window)
947 GtkWidget *dialog = empathy_contact_search_dialog_new (
948 GTK_WINDOW (window));
949 gtk_widget_show (dialog);
953 main_window_view_show_ft_manager (GtkAction *action,
954 EmpathyMainWindow *window)
956 empathy_ft_manager_show ();
960 main_window_view_show_offline_cb (GtkToggleAction *action,
961 EmpathyMainWindow *window)
963 EmpathyMainWindowPriv *priv = GET_PRIV (window);
966 current = gtk_toggle_action_get_active (action);
967 g_settings_set_boolean (priv->gsettings_ui,
968 EMPATHY_PREFS_UI_SHOW_OFFLINE,
971 empathy_individual_view_set_show_offline (priv->individual_view,
976 main_window_notify_sort_contact_cb (GSettings *gsettings,
978 EmpathyMainWindow *window)
980 EmpathyMainWindowPriv *priv = GET_PRIV (window);
983 str = g_settings_get_string (gsettings, key);
987 GEnumClass *enum_class;
988 GEnumValue *enum_value;
990 type = empathy_individual_store_sort_get_type ();
991 enum_class = G_ENUM_CLASS (g_type_class_peek (type));
992 enum_value = g_enum_get_value_by_nick (enum_class, str);
994 /* By changing the value of the GtkRadioAction,
995 it emits a signal that calls main_window_view_sort_contacts_cb
996 which updates the contacts list */
997 gtk_radio_action_set_current_value (priv->sort_by_name,
1000 g_warning ("Wrong value for sort_criterium configuration : %s", str);
1007 main_window_view_sort_contacts_cb (GtkRadioAction *action,
1008 GtkRadioAction *current,
1009 EmpathyMainWindow *window)
1011 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1012 EmpathyContactListStoreSort value;
1015 GEnumClass *enum_class;
1016 GEnumValue *enum_value;
1018 value = gtk_radio_action_get_current_value (action);
1019 group = gtk_radio_action_get_group (action);
1021 /* Get string from index */
1022 type = empathy_individual_store_sort_get_type ();
1023 enum_class = G_ENUM_CLASS (g_type_class_peek (type));
1024 enum_value = g_enum_get_value (enum_class, g_slist_index (group, current));
1027 g_warning ("No GEnumValue for EmpathyContactListSort with GtkRadioAction index:%d",
1028 g_slist_index (group, action));
1030 g_settings_set_string (priv->gsettings_contacts,
1031 EMPATHY_PREFS_CONTACTS_SORT_CRITERIUM,
1032 enum_value->value_nick);
1034 empathy_individual_store_set_sort_criterium (priv->individual_store,
1039 main_window_view_show_protocols_cb (GtkToggleAction *action,
1040 EmpathyMainWindow *window)
1042 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1045 value = gtk_toggle_action_get_active (action);
1047 g_settings_set_boolean (priv->gsettings_ui,
1048 EMPATHY_PREFS_UI_SHOW_PROTOCOLS,
1050 empathy_individual_store_set_show_protocols (priv->individual_store,
1054 /* Matches GtkRadioAction values set in empathy-main-window.ui */
1055 #define CONTACT_LIST_NORMAL_SIZE_WITH_AVATARS 0
1056 #define CONTACT_LIST_NORMAL_SIZE 1
1057 #define CONTACT_LIST_COMPACT_SIZE 2
1060 main_window_view_contacts_list_size_cb (GtkRadioAction *action,
1061 GtkRadioAction *current,
1062 EmpathyMainWindow *window)
1064 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1065 GSettings *gsettings_ui;
1068 value = gtk_radio_action_get_current_value (action);
1069 /* create a new GSettings, so we can delay the setting until both
1071 gsettings_ui = g_settings_new (EMPATHY_PREFS_UI_SCHEMA);
1073 DEBUG ("radio button toggled, value = %i", value);
1075 g_settings_delay (gsettings_ui);
1076 g_settings_set_boolean (gsettings_ui,
1077 EMPATHY_PREFS_UI_SHOW_AVATARS,
1078 value == CONTACT_LIST_NORMAL_SIZE_WITH_AVATARS);
1080 g_settings_set_boolean (gsettings_ui,
1081 EMPATHY_PREFS_UI_COMPACT_CONTACT_LIST,
1082 value == CONTACT_LIST_COMPACT_SIZE);
1083 g_settings_apply (gsettings_ui);
1085 /* FIXME: these enums probably have the wrong namespace */
1086 empathy_individual_store_set_show_avatars (priv->individual_store,
1087 value == CONTACT_LIST_NORMAL_SIZE_WITH_AVATARS);
1088 empathy_individual_store_set_is_compact (priv->individual_store,
1089 value == CONTACT_LIST_COMPACT_SIZE);
1091 g_object_unref (gsettings_ui);
1094 static void main_window_notify_show_protocols_cb (GSettings *gsettings,
1096 EmpathyMainWindow *window)
1098 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1100 gtk_toggle_action_set_active (priv->show_protocols,
1101 g_settings_get_boolean (gsettings,
1102 EMPATHY_PREFS_UI_SHOW_PROTOCOLS));
1107 main_window_notify_contact_list_size_cb (GSettings *gsettings,
1109 EmpathyMainWindow *window)
1111 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1114 if (g_settings_get_boolean (gsettings,
1115 EMPATHY_PREFS_UI_COMPACT_CONTACT_LIST)) {
1116 value = CONTACT_LIST_COMPACT_SIZE;
1117 } else if (g_settings_get_boolean (gsettings,
1118 EMPATHY_PREFS_UI_SHOW_AVATARS)) {
1119 value = CONTACT_LIST_NORMAL_SIZE_WITH_AVATARS;
1121 value = CONTACT_LIST_NORMAL_SIZE;
1124 DEBUG ("setting changed, value = %i", value);
1126 /* By changing the value of the GtkRadioAction,
1127 it emits a signal that calls main_window_view_contacts_list_size_cb
1128 which updates the contacts list */
1129 gtk_radio_action_set_current_value (priv->normal_with_avatars, value);
1133 main_window_edit_search_contacts_cb (GtkCheckMenuItem *item,
1134 EmpathyMainWindow *window)
1136 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1138 empathy_individual_view_start_search (priv->individual_view);
1142 main_window_view_show_map_cb (GtkCheckMenuItem *item,
1143 EmpathyMainWindow *window)
1145 #ifdef HAVE_LIBCHAMPLAIN
1146 empathy_map_view_show ();
1151 join_chatroom (EmpathyChatroom *chatroom,
1157 account = empathy_chatroom_get_account (chatroom);
1158 room = empathy_chatroom_get_room (chatroom);
1160 DEBUG ("Requesting channel for '%s'", room);
1161 empathy_dispatcher_join_muc (account, room, timestamp);
1167 EmpathyChatroom *chatroom;
1171 } join_fav_account_sig_ctx;
1173 static join_fav_account_sig_ctx *
1174 join_fav_account_sig_ctx_new (TpAccount *account,
1175 EmpathyChatroom *chatroom,
1178 join_fav_account_sig_ctx *ctx = g_slice_new0 (
1179 join_fav_account_sig_ctx);
1181 ctx->account = g_object_ref (account);
1182 ctx->chatroom = g_object_ref (chatroom);
1183 ctx->timestamp = timestamp;
1188 join_fav_account_sig_ctx_free (join_fav_account_sig_ctx *ctx)
1190 g_object_unref (ctx->account);
1191 g_object_unref (ctx->chatroom);
1192 g_slice_free (join_fav_account_sig_ctx, ctx);
1196 account_status_changed_cb (TpAccount *account,
1197 TpConnectionStatus old_status,
1198 TpConnectionStatus new_status,
1200 gchar *dbus_error_name,
1201 GHashTable *details,
1204 join_fav_account_sig_ctx *ctx = user_data;
1206 switch (new_status) {
1207 case TP_CONNECTION_STATUS_DISCONNECTED:
1208 /* Don't wait any longer */
1212 case TP_CONNECTION_STATUS_CONNECTING:
1216 case TP_CONNECTION_STATUS_CONNECTED:
1217 /* We can join the room */
1221 g_assert_not_reached ();
1224 join_chatroom (ctx->chatroom, ctx->timestamp);
1227 g_source_remove (ctx->timeout);
1228 g_signal_handler_disconnect (account, ctx->sig_id);
1231 #define JOIN_FAVORITE_TIMEOUT 5
1234 join_favorite_timeout_cb (gpointer data)
1236 join_fav_account_sig_ctx *ctx = data;
1238 /* stop waiting for joining the favorite room */
1239 g_signal_handler_disconnect (ctx->account, ctx->sig_id);
1244 main_window_favorite_chatroom_join (EmpathyChatroom *chatroom)
1248 account = empathy_chatroom_get_account (chatroom);
1249 if (tp_account_get_connection_status (account, NULL) !=
1250 TP_CONNECTION_STATUS_CONNECTED) {
1251 join_fav_account_sig_ctx *ctx;
1253 ctx = join_fav_account_sig_ctx_new (account, chatroom,
1254 gtk_get_current_event_time ());
1256 ctx->sig_id = g_signal_connect_data (account, "status-changed",
1257 G_CALLBACK (account_status_changed_cb), ctx,
1258 (GClosureNotify) join_fav_account_sig_ctx_free, 0);
1260 ctx->timeout = g_timeout_add_seconds (JOIN_FAVORITE_TIMEOUT,
1261 join_favorite_timeout_cb, ctx);
1265 join_chatroom (chatroom, gtk_get_current_event_time ());
1269 main_window_favorite_chatroom_menu_activate_cb (GtkMenuItem *menu_item,
1270 EmpathyChatroom *chatroom)
1272 main_window_favorite_chatroom_join (chatroom);
1276 main_window_favorite_chatroom_menu_add (EmpathyMainWindow *window,
1277 EmpathyChatroom *chatroom)
1279 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1280 GtkWidget *menu_item;
1283 if (g_object_get_data (G_OBJECT (chatroom), "menu_item")) {
1287 name = empathy_chatroom_get_name (chatroom);
1288 menu_item = gtk_menu_item_new_with_label (name);
1289 g_object_set_data (G_OBJECT (menu_item), "is_favorite",
1290 GUINT_TO_POINTER (TRUE));
1292 g_object_set_data (G_OBJECT (chatroom), "menu_item", menu_item);
1293 g_signal_connect (menu_item, "activate",
1294 G_CALLBACK (main_window_favorite_chatroom_menu_activate_cb),
1297 gtk_menu_shell_insert (GTK_MENU_SHELL (priv->room_menu),
1300 gtk_widget_show (menu_item);
1304 main_window_favorite_chatroom_menu_added_cb (EmpathyChatroomManager *manager,
1305 EmpathyChatroom *chatroom,
1306 EmpathyMainWindow *window)
1308 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1310 main_window_favorite_chatroom_menu_add (window, chatroom);
1311 gtk_widget_show (priv->room_separator);
1312 gtk_action_set_sensitive (priv->room_join_favorites, TRUE);
1316 main_window_favorite_chatroom_menu_removed_cb (EmpathyChatroomManager *manager,
1317 EmpathyChatroom *chatroom,
1318 EmpathyMainWindow *window)
1320 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1321 GtkWidget *menu_item;
1324 menu_item = g_object_get_data (G_OBJECT (chatroom), "menu_item");
1325 g_object_set_data (G_OBJECT (chatroom), "menu_item", NULL);
1326 gtk_widget_destroy (menu_item);
1328 chatrooms = empathy_chatroom_manager_get_chatrooms (priv->chatroom_manager, NULL);
1330 gtk_widget_show (priv->room_separator);
1332 gtk_widget_hide (priv->room_separator);
1335 gtk_action_set_sensitive (priv->room_join_favorites, chatrooms != NULL);
1336 g_list_free (chatrooms);
1340 main_window_favorite_chatroom_menu_setup (EmpathyMainWindow *window)
1342 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1343 GList *chatrooms, *l;
1346 priv->chatroom_manager = empathy_chatroom_manager_dup_singleton (NULL);
1347 chatrooms = empathy_chatroom_manager_get_chatrooms (
1348 priv->chatroom_manager, NULL);
1349 room = gtk_ui_manager_get_widget (priv->ui_manager,
1351 priv->room_menu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (room));
1352 priv->room_separator = gtk_ui_manager_get_widget (priv->ui_manager,
1353 "/menubar/room/room_separator");
1355 for (l = chatrooms; l; l = l->next) {
1356 main_window_favorite_chatroom_menu_add (window, l->data);
1360 gtk_widget_hide (priv->room_separator);
1363 gtk_action_set_sensitive (priv->room_join_favorites, chatrooms != NULL);
1365 g_signal_connect (priv->chatroom_manager, "chatroom-added",
1366 G_CALLBACK (main_window_favorite_chatroom_menu_added_cb),
1368 g_signal_connect (priv->chatroom_manager, "chatroom-removed",
1369 G_CALLBACK (main_window_favorite_chatroom_menu_removed_cb),
1372 g_list_free (chatrooms);
1376 main_window_room_join_new_cb (GtkAction *action,
1377 EmpathyMainWindow *window)
1379 empathy_new_chatroom_dialog_show (GTK_WINDOW (window));
1383 main_window_room_join_favorites_cb (GtkAction *action,
1384 EmpathyMainWindow *window)
1386 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1387 GList *chatrooms, *l;
1389 chatrooms = empathy_chatroom_manager_get_chatrooms (priv->chatroom_manager, NULL);
1390 for (l = chatrooms; l; l = l->next) {
1391 main_window_favorite_chatroom_join (l->data);
1393 g_list_free (chatrooms);
1397 main_window_room_manage_favorites_cb (GtkAction *action,
1398 EmpathyMainWindow *window)
1400 empathy_chatrooms_window_show (GTK_WINDOW (window));
1404 main_window_edit_cb (GtkAction *action,
1405 EmpathyMainWindow *window)
1407 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1410 /* FIXME: It should use the UIManager to merge the contact/group submenu */
1411 submenu = empathy_individual_view_get_individual_menu (
1412 priv->individual_view);
1417 item = GTK_MENU_ITEM (priv->edit_context);
1418 label = gtk_bin_get_child (GTK_BIN (item));
1419 gtk_label_set_text (GTK_LABEL (label), _("Contact"));
1421 gtk_widget_show (priv->edit_context);
1422 gtk_widget_show (priv->edit_context_separator);
1424 gtk_menu_item_set_submenu (item, submenu);
1429 submenu = empathy_individual_view_get_group_menu (
1430 priv->individual_view);
1435 item = GTK_MENU_ITEM (priv->edit_context);
1436 label = gtk_bin_get_child (GTK_BIN (item));
1437 gtk_label_set_text (GTK_LABEL (label), _("Group"));
1439 gtk_widget_show (priv->edit_context);
1440 gtk_widget_show (priv->edit_context_separator);
1442 gtk_menu_item_set_submenu (item, submenu);
1447 gtk_widget_hide (priv->edit_context);
1448 gtk_widget_hide (priv->edit_context_separator);
1454 main_window_edit_accounts_cb (GtkAction *action,
1455 EmpathyMainWindow *window)
1457 empathy_accounts_dialog_show_application (gdk_screen_get_default (),
1458 NULL, FALSE, FALSE);
1462 main_window_edit_personal_information_cb (GtkAction *action,
1463 EmpathyMainWindow *window)
1465 empathy_contact_personal_dialog_show (GTK_WINDOW (window));
1469 main_window_edit_preferences_cb (GtkAction *action,
1470 EmpathyMainWindow *window)
1472 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1474 if (priv->preferences == NULL) {
1475 priv->preferences = empathy_preferences_new (GTK_WINDOW (window));
1476 g_object_add_weak_pointer (G_OBJECT (priv->preferences),
1477 (gpointer) &priv->preferences);
1479 gtk_widget_show (priv->preferences);
1481 gtk_window_present (GTK_WINDOW (priv->preferences));
1486 main_window_help_about_cb (GtkAction *action,
1487 EmpathyMainWindow *window)
1489 empathy_about_dialog_new (GTK_WINDOW (window));
1493 main_window_help_debug_cb (GtkAction *action,
1494 EmpathyMainWindow *window)
1496 GdkDisplay *display;
1497 GError *error = NULL;
1500 GdkAppLaunchContext *context = NULL;
1502 /* Try to run from source directory if possible */
1503 path = g_build_filename (g_getenv ("EMPATHY_SRCDIR"), "src",
1504 "empathy-debugger", NULL);
1506 if (!g_file_test (path, G_FILE_TEST_EXISTS)) {
1508 path = g_build_filename (BIN_DIR, "empathy-debugger", NULL);
1511 app_info = g_app_info_create_from_commandline (path, NULL, 0, &error);
1512 if (app_info == NULL) {
1513 DEBUG ("Failed to create app info: %s", error->message);
1514 g_error_free (error);
1518 display = gdk_display_get_default ();
1519 context = gdk_display_get_app_launch_context (display);
1521 if (!g_app_info_launch (app_info, NULL, (GAppLaunchContext *) context,
1523 g_warning ("Failed to open debug window: %s", error->message);
1524 g_error_free (error);
1529 tp_clear_object (&app_info);
1530 tp_clear_object (&context);
1535 main_window_help_contents_cb (GtkAction *action,
1536 EmpathyMainWindow *window)
1538 empathy_url_show (GTK_WIDGET (window), "ghelp:empathy");
1542 main_window_throbber_button_press_event_cb (GtkWidget *throbber,
1543 GdkEventButton *event,
1544 EmpathyMainWindow *window)
1546 if (event->type != GDK_BUTTON_PRESS ||
1547 event->button != 1) {
1551 empathy_accounts_dialog_show_application (
1552 gtk_widget_get_screen (GTK_WIDGET (throbber)),
1553 NULL, FALSE, FALSE);
1559 main_window_account_removed_cb (TpAccountManager *manager,
1561 EmpathyMainWindow *window)
1563 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1566 a = tp_account_manager_get_valid_accounts (manager);
1568 gtk_action_set_sensitive (priv->view_history,
1569 g_list_length (a) > 0);
1573 /* remove errors if any */
1574 main_window_remove_error (window, account);
1578 main_window_account_validity_changed_cb (TpAccountManager *manager,
1581 EmpathyMainWindow *window)
1583 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1587 handler_id = GPOINTER_TO_UINT (g_hash_table_lookup (
1588 priv->status_changed_handlers, account));
1590 /* connect signal only if it was not connected yet */
1591 if (handler_id == 0) {
1592 handler_id = g_signal_connect (account,
1594 G_CALLBACK (main_window_connection_changed_cb),
1596 g_hash_table_insert (priv->status_changed_handlers,
1597 account, GUINT_TO_POINTER (handler_id));
1601 main_window_account_removed_cb (manager, account, window);
1605 main_window_notify_show_offline_cb (GSettings *gsettings,
1607 gpointer toggle_action)
1609 gtk_toggle_action_set_active (toggle_action,
1610 g_settings_get_boolean (gsettings, key));
1614 main_window_connection_items_setup (EmpathyMainWindow *window,
1617 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1621 const gchar *actions_connected[] = {
1623 "room_join_favorites",
1627 "edit_personal_information"
1630 for (i = 0, list = NULL; i < G_N_ELEMENTS (actions_connected); i++) {
1631 action = gtk_builder_get_object (gui, actions_connected[i]);
1632 list = g_list_prepend (list, action);
1635 priv->actions_connected = list;
1639 account_manager_prepared_cb (GObject *source_object,
1640 GAsyncResult *result,
1643 GList *accounts, *j;
1644 TpAccountManager *manager = TP_ACCOUNT_MANAGER (source_object);
1645 EmpathyMainWindow *window = user_data;
1646 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1647 GError *error = NULL;
1649 if (!tp_account_manager_prepare_finish (manager, result, &error)) {
1650 DEBUG ("Failed to prepare account manager: %s", error->message);
1651 g_error_free (error);
1655 accounts = tp_account_manager_get_valid_accounts (priv->account_manager);
1656 for (j = accounts; j != NULL; j = j->next) {
1657 TpAccount *account = TP_ACCOUNT (j->data);
1660 handler_id = g_signal_connect (account, "status-changed",
1661 G_CALLBACK (main_window_connection_changed_cb),
1663 g_hash_table_insert (priv->status_changed_handlers,
1664 account, GUINT_TO_POINTER (handler_id));
1667 g_signal_connect (manager, "account-validity-changed",
1668 G_CALLBACK (main_window_account_validity_changed_cb),
1671 main_window_update_status (window);
1673 /* Disable the "Previous Conversations" menu entry if there is no account */
1674 gtk_action_set_sensitive (priv->view_history,
1675 g_list_length (accounts) > 0);
1677 g_list_free (accounts);
1681 main_window_members_changed_cb (EmpathyContactList *list,
1682 EmpathyContact *contact,
1683 EmpathyContact *actor,
1687 EmpathyMainWindow *window)
1689 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1694 if (!empathy_migrate_butterfly_logs (contact)) {
1695 g_signal_handler_disconnect (list,
1696 priv->butterfly_log_migration_members_changed_id);
1697 priv->butterfly_log_migration_members_changed_id = 0;
1702 empathy_main_window_constructor (GType type,
1703 guint n_construct_params,
1704 GObjectConstructParam *construct_params)
1706 static GObject *window = NULL;
1709 return g_object_ref (window);
1711 window = G_OBJECT_CLASS (empathy_main_window_parent_class)->constructor (
1712 type, n_construct_params, construct_params);
1714 g_object_add_weak_pointer (window, (gpointer) &window);
1720 empathy_main_window_class_init (EmpathyMainWindowClass *klass)
1722 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1724 object_class->finalize = empathy_main_window_finalize;
1725 object_class->constructor = empathy_main_window_constructor;
1727 g_type_class_add_private (object_class, sizeof (EmpathyMainWindowPriv));
1731 empathy_main_window_init (EmpathyMainWindow *window)
1733 EmpathyMainWindowPriv *priv;
1734 EmpathyIndividualManager *individual_manager;
1737 GtkToggleAction *show_offline_widget;
1738 GtkAction *show_map_widget;
1740 gboolean show_offline;
1743 GtkTreeModel *model;
1745 priv = window->priv = G_TYPE_INSTANCE_GET_PRIVATE (window,
1746 EMPATHY_TYPE_MAIN_WINDOW, EmpathyMainWindowPriv);
1748 priv->gsettings_ui = g_settings_new (EMPATHY_PREFS_UI_SCHEMA);
1749 priv->gsettings_contacts = g_settings_new (EMPATHY_PREFS_CONTACTS_SCHEMA);
1751 priv->sound_mgr = empathy_sound_manager_dup_singleton ();
1753 gtk_window_set_title (GTK_WINDOW (window), _("Contact List"));
1754 gtk_window_set_role (GTK_WINDOW (window), "contact_list");
1755 gtk_window_set_default_size (GTK_WINDOW (window), 225, 325);
1757 /* Set up interface */
1758 filename = empathy_file_lookup ("empathy-main-window.ui", "src");
1759 gui = empathy_builder_get_file (filename,
1760 "main_vbox", &priv->main_vbox,
1761 "errors_vbox", &priv->errors_vbox,
1762 "auth_vbox", &priv->auth_vbox,
1763 "ui_manager", &priv->ui_manager,
1764 "view_show_offline", &show_offline_widget,
1765 "view_show_protocols", &priv->show_protocols,
1766 "view_sort_by_name", &priv->sort_by_name,
1767 "view_sort_by_status", &priv->sort_by_status,
1768 "view_normal_size_with_avatars", &priv->normal_with_avatars,
1769 "view_normal_size", &priv->normal_size,
1770 "view_compact_size", &priv->compact_size,
1771 "view_history", &priv->view_history,
1772 "view_show_map", &show_map_widget,
1773 "room_join_favorites", &priv->room_join_favorites,
1774 "presence_toolbar", &priv->presence_toolbar,
1775 "notebook", &priv->notebook,
1776 "no_entry_label", &priv->no_entry_label,
1777 "roster_scrolledwindow", &sw,
1781 gtk_container_add (GTK_CONTAINER (window), priv->main_vbox);
1782 gtk_widget_show (priv->main_vbox);
1784 g_signal_connect (window, "key-press-event",
1785 G_CALLBACK (main_window_key_press_event_cb), NULL);
1787 empathy_builder_connect (gui, window,
1788 "chat_quit", "activate", main_window_chat_quit_cb,
1789 "chat_new_message", "activate", main_window_chat_new_message_cb,
1790 "chat_new_call", "activate", main_window_chat_new_call_cb,
1791 "view_history", "activate", main_window_view_history_cb,
1792 "room_join_new", "activate", main_window_room_join_new_cb,
1793 "room_join_favorites", "activate", main_window_room_join_favorites_cb,
1794 "room_manage_favorites", "activate", main_window_room_manage_favorites_cb,
1795 "chat_add_contact", "activate", main_window_chat_add_contact_cb,
1796 "chat_search_contacts", "activate", main_window_chat_search_contacts_cb,
1797 "view_show_ft_manager", "activate", main_window_view_show_ft_manager,
1798 "view_show_offline", "toggled", main_window_view_show_offline_cb,
1799 "view_show_protocols", "toggled", main_window_view_show_protocols_cb,
1800 "view_sort_by_name", "changed", main_window_view_sort_contacts_cb,
1801 "view_normal_size_with_avatars", "changed", main_window_view_contacts_list_size_cb,
1802 "view_show_map", "activate", main_window_view_show_map_cb,
1803 "edit", "activate", main_window_edit_cb,
1804 "edit_accounts", "activate", main_window_edit_accounts_cb,
1805 "edit_personal_information", "activate", main_window_edit_personal_information_cb,
1806 "edit_preferences", "activate", main_window_edit_preferences_cb,
1807 "edit_search_contacts", "activate", main_window_edit_search_contacts_cb,
1808 "help_about", "activate", main_window_help_about_cb,
1809 "help_debug", "activate", main_window_help_debug_cb,
1810 "help_contents", "activate", main_window_help_contents_cb,
1813 /* Set up connection related widgets. */
1814 main_window_connection_items_setup (window, gui);
1816 g_object_ref (priv->ui_manager);
1817 g_object_unref (gui);
1819 #ifndef HAVE_LIBCHAMPLAIN
1820 gtk_action_set_visible (show_map_widget, FALSE);
1823 priv->account_manager = tp_account_manager_dup ();
1825 tp_account_manager_prepare_async (priv->account_manager, NULL,
1826 account_manager_prepared_cb, window);
1828 priv->errors = g_hash_table_new_full (g_direct_hash,
1833 priv->auths = g_hash_table_new (NULL, NULL);
1835 priv->status_changed_handlers = g_hash_table_new_full (g_direct_hash,
1841 main_window_favorite_chatroom_menu_setup (window);
1843 priv->edit_context = gtk_ui_manager_get_widget (priv->ui_manager,
1844 "/menubar/edit/edit_context");
1845 priv->edit_context_separator = gtk_ui_manager_get_widget (
1847 "/menubar/edit/edit_context_separator");
1848 gtk_widget_hide (priv->edit_context);
1849 gtk_widget_hide (priv->edit_context_separator);
1851 /* Set up contact list. */
1852 empathy_status_presets_get_all ();
1854 /* Set up presence chooser */
1855 priv->presence_chooser = empathy_presence_chooser_new ();
1856 gtk_widget_show (priv->presence_chooser);
1857 item = gtk_tool_item_new ();
1858 gtk_widget_show (GTK_WIDGET (item));
1859 gtk_widget_set_size_request (priv->presence_chooser, 10, -1);
1860 gtk_container_add (GTK_CONTAINER (item), priv->presence_chooser);
1861 gtk_tool_item_set_is_important (item, TRUE);
1862 gtk_tool_item_set_expand (item, TRUE);
1863 gtk_toolbar_insert (GTK_TOOLBAR (priv->presence_toolbar), item, -1);
1865 /* Set up the throbber */
1866 priv->throbber = gtk_spinner_new ();
1867 gtk_widget_set_size_request (priv->throbber, 16, -1);
1868 gtk_widget_set_tooltip_text (priv->throbber, _("Show and edit accounts"));
1869 gtk_widget_set_events (priv->throbber, GDK_BUTTON_PRESS_MASK);
1870 g_signal_connect (priv->throbber, "button-press-event",
1871 G_CALLBACK (main_window_throbber_button_press_event_cb),
1873 gtk_widget_show (priv->throbber);
1875 item = gtk_tool_item_new ();
1876 gtk_container_set_border_width (GTK_CONTAINER (item), 6);
1877 gtk_toolbar_insert (GTK_TOOLBAR (priv->presence_toolbar), item, -1);
1878 gtk_container_add (GTK_CONTAINER (item), priv->throbber);
1879 priv->throbber_tool_item = GTK_WIDGET (item);
1881 /* XXX: this class is designed to live for the duration of the program,
1882 * so it's got a race condition between its signal handlers and its
1883 * finalization. The class is planned to be removed, so we won't fix
1884 * this before then. */
1885 priv->contact_manager = EMPATHY_CONTACT_LIST (
1886 empathy_contact_manager_dup_singleton ());
1887 individual_manager = empathy_individual_manager_dup_singleton ();
1888 priv->individual_store = empathy_individual_store_new (
1889 individual_manager);
1890 g_object_unref (individual_manager);
1892 /* For the moment, we disallow Persona drops onto the main contact list (e.g. from things such as
1893 * the EmpathyPersonaView in the linking dialogue). No code is hooked up to do anything on a Persona
1894 * drop, so allowing them would achieve nothing except confusion. */
1895 priv->individual_view = empathy_individual_view_new (
1896 priv->individual_store,
1897 EMPATHY_INDIVIDUAL_VIEW_FEATURE_ALL ^ EMPATHY_INDIVIDUAL_VIEW_FEATURE_PERSONA_DROP,
1898 EMPATHY_INDIVIDUAL_FEATURE_ALL);
1900 priv->butterfly_log_migration_members_changed_id = g_signal_connect (
1901 priv->contact_manager, "members-changed",
1902 G_CALLBACK (main_window_members_changed_cb), window);
1904 gtk_widget_show (GTK_WIDGET (priv->individual_view));
1905 gtk_container_add (GTK_CONTAINER (sw),
1906 GTK_WIDGET (priv->individual_view));
1907 g_signal_connect (priv->individual_view, "row-activated",
1908 G_CALLBACK (main_window_row_activated_cb),
1911 /* Set up search bar */
1912 priv->search_bar = empathy_live_search_new (
1913 GTK_WIDGET (priv->individual_view));
1914 empathy_individual_view_set_live_search (priv->individual_view,
1915 EMPATHY_LIVE_SEARCH (priv->search_bar));
1916 gtk_box_pack_start (GTK_BOX (priv->main_vbox), priv->search_bar,
1918 g_signal_connect_swapped (window, "map",
1919 G_CALLBACK (gtk_widget_grab_focus), priv->individual_view);
1921 /* Connect to proper signals to check if contact list is empty or not */
1922 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->individual_view));
1924 g_signal_connect (model, "row-inserted",
1925 G_CALLBACK (main_window_row_inserted_cb),
1927 g_signal_connect (model, "row-deleted",
1928 G_CALLBACK (main_window_row_deleted_cb),
1931 /* Load user-defined accelerators. */
1932 main_window_accels_load ();
1934 /* Set window size. */
1935 empathy_geometry_bind (GTK_WINDOW (window), GEOMETRY_NAME);
1937 /* Enable event handling */
1939 * FIXME: https://bugzilla.gnome.org/show_bug.cgi?id=644127
1940 priv->call_observer = empathy_call_observer_dup_singleton ();
1942 priv->event_manager = empathy_event_manager_dup_singleton ();
1944 g_signal_connect (priv->event_manager, "event-added",
1945 G_CALLBACK (main_window_event_added_cb), window);
1946 g_signal_connect (priv->event_manager, "event-removed",
1947 G_CALLBACK (main_window_event_removed_cb), window);
1948 g_signal_connect (priv->account_manager, "account-validity-changed",
1949 G_CALLBACK (main_window_account_validity_changed_cb),
1951 g_signal_connect (priv->account_manager, "account-removed",
1952 G_CALLBACK (main_window_account_removed_cb),
1954 g_signal_connect (priv->account_manager, "account-disabled",
1955 G_CALLBACK (main_window_account_disabled_cb),
1958 l = empathy_event_manager_get_events (priv->event_manager);
1960 main_window_event_added_cb (priv->event_manager, l->data,
1965 /* Show offline ? */
1966 show_offline = g_settings_get_boolean (priv->gsettings_ui,
1967 EMPATHY_PREFS_UI_SHOW_OFFLINE);
1968 g_signal_connect (priv->gsettings_ui,
1969 "changed::" EMPATHY_PREFS_UI_SHOW_OFFLINE,
1970 G_CALLBACK (main_window_notify_show_offline_cb),
1971 show_offline_widget);
1973 gtk_toggle_action_set_active (show_offline_widget, show_offline);
1975 /* Show protocol ? */
1976 g_signal_connect (priv->gsettings_ui,
1977 "changed::" EMPATHY_PREFS_UI_SHOW_PROTOCOLS,
1978 G_CALLBACK (main_window_notify_show_protocols_cb),
1981 main_window_notify_show_protocols_cb (priv->gsettings_ui,
1982 EMPATHY_PREFS_UI_SHOW_PROTOCOLS,
1985 /* Sort by name / by status ? */
1986 g_signal_connect (priv->gsettings_contacts,
1987 "changed::" EMPATHY_PREFS_CONTACTS_SORT_CRITERIUM,
1988 G_CALLBACK (main_window_notify_sort_contact_cb),
1991 main_window_notify_sort_contact_cb (priv->gsettings_contacts,
1992 EMPATHY_PREFS_CONTACTS_SORT_CRITERIUM,
1995 /* Contacts list size */
1996 g_signal_connect (priv->gsettings_ui,
1997 "changed::" EMPATHY_PREFS_UI_COMPACT_CONTACT_LIST,
1998 G_CALLBACK (main_window_notify_contact_list_size_cb),
2000 g_signal_connect (priv->gsettings_ui,
2001 "changed::" EMPATHY_PREFS_UI_SHOW_AVATARS,
2002 G_CALLBACK (main_window_notify_contact_list_size_cb),
2005 main_window_notify_contact_list_size_cb (priv->gsettings_ui,
2006 EMPATHY_PREFS_UI_SHOW_AVATARS,
2011 empathy_main_window_dup (void)
2013 return g_object_new (EMPATHY_TYPE_MAIN_WINDOW, NULL);