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,
878 g_object_unref (priv->call_observer);
879 g_object_unref (priv->event_manager);
880 g_object_unref (priv->ui_manager);
881 g_object_unref (priv->chatroom_manager);
883 g_object_unref (priv->gsettings_ui);
884 g_object_unref (priv->gsettings_contacts);
886 G_OBJECT_CLASS (empathy_main_window_parent_class)->finalize (window);
890 main_window_key_press_event_cb (GtkWidget *window,
894 EmpathyChatManager *chat_manager;
896 if (event->keyval == GDK_KEY_T
897 && event->state & GDK_SHIFT_MASK
898 && event->state & GDK_CONTROL_MASK) {
899 chat_manager = empathy_chat_manager_dup_singleton ();
900 empathy_chat_manager_undo_closed_chat (chat_manager);
901 g_object_unref (chat_manager);
907 main_window_chat_quit_cb (GtkAction *action,
908 EmpathyMainWindow *window)
914 main_window_view_history_cb (GtkAction *action,
915 EmpathyMainWindow *window)
917 empathy_log_window_show (NULL, NULL, FALSE, GTK_WINDOW (window));
921 main_window_chat_new_message_cb (GtkAction *action,
922 EmpathyMainWindow *window)
924 empathy_new_message_dialog_show (GTK_WINDOW (window));
928 main_window_chat_new_call_cb (GtkAction *action,
929 EmpathyMainWindow *window)
931 empathy_new_call_dialog_show (GTK_WINDOW (window));
935 main_window_chat_add_contact_cb (GtkAction *action,
936 EmpathyMainWindow *window)
938 empathy_new_individual_dialog_show (GTK_WINDOW (window));
942 main_window_chat_search_contacts_cb (GtkAction *action,
943 EmpathyMainWindow *window)
945 GtkWidget *dialog = empathy_contact_search_dialog_new (
946 GTK_WINDOW (window));
947 gtk_widget_show (dialog);
951 main_window_view_show_ft_manager (GtkAction *action,
952 EmpathyMainWindow *window)
954 empathy_ft_manager_show ();
958 main_window_view_show_offline_cb (GtkToggleAction *action,
959 EmpathyMainWindow *window)
961 EmpathyMainWindowPriv *priv = GET_PRIV (window);
964 current = gtk_toggle_action_get_active (action);
965 g_settings_set_boolean (priv->gsettings_ui,
966 EMPATHY_PREFS_UI_SHOW_OFFLINE,
969 empathy_individual_view_set_show_offline (priv->individual_view,
974 main_window_notify_sort_contact_cb (GSettings *gsettings,
976 EmpathyMainWindow *window)
978 EmpathyMainWindowPriv *priv = GET_PRIV (window);
981 str = g_settings_get_string (gsettings, key);
985 GEnumClass *enum_class;
986 GEnumValue *enum_value;
988 type = empathy_individual_store_sort_get_type ();
989 enum_class = G_ENUM_CLASS (g_type_class_peek (type));
990 enum_value = g_enum_get_value_by_nick (enum_class, str);
992 /* By changing the value of the GtkRadioAction,
993 it emits a signal that calls main_window_view_sort_contacts_cb
994 which updates the contacts list */
995 gtk_radio_action_set_current_value (priv->sort_by_name,
998 g_warning ("Wrong value for sort_criterium configuration : %s", str);
1005 main_window_view_sort_contacts_cb (GtkRadioAction *action,
1006 GtkRadioAction *current,
1007 EmpathyMainWindow *window)
1009 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1010 EmpathyContactListStoreSort value;
1013 GEnumClass *enum_class;
1014 GEnumValue *enum_value;
1016 value = gtk_radio_action_get_current_value (action);
1017 group = gtk_radio_action_get_group (action);
1019 /* Get string from index */
1020 type = empathy_individual_store_sort_get_type ();
1021 enum_class = G_ENUM_CLASS (g_type_class_peek (type));
1022 enum_value = g_enum_get_value (enum_class, g_slist_index (group, current));
1025 g_warning ("No GEnumValue for EmpathyContactListSort with GtkRadioAction index:%d",
1026 g_slist_index (group, action));
1028 g_settings_set_string (priv->gsettings_contacts,
1029 EMPATHY_PREFS_CONTACTS_SORT_CRITERIUM,
1030 enum_value->value_nick);
1032 empathy_individual_store_set_sort_criterium (priv->individual_store,
1037 main_window_view_show_protocols_cb (GtkToggleAction *action,
1038 EmpathyMainWindow *window)
1040 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1043 value = gtk_toggle_action_get_active (action);
1045 g_settings_set_boolean (priv->gsettings_ui,
1046 EMPATHY_PREFS_UI_SHOW_PROTOCOLS,
1048 empathy_individual_store_set_show_protocols (priv->individual_store,
1052 /* Matches GtkRadioAction values set in empathy-main-window.ui */
1053 #define CONTACT_LIST_NORMAL_SIZE_WITH_AVATARS 0
1054 #define CONTACT_LIST_NORMAL_SIZE 1
1055 #define CONTACT_LIST_COMPACT_SIZE 2
1058 main_window_view_contacts_list_size_cb (GtkRadioAction *action,
1059 GtkRadioAction *current,
1060 EmpathyMainWindow *window)
1062 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1063 GSettings *gsettings_ui;
1066 value = gtk_radio_action_get_current_value (action);
1067 /* create a new GSettings, so we can delay the setting until both
1069 gsettings_ui = g_settings_new (EMPATHY_PREFS_UI_SCHEMA);
1071 DEBUG ("radio button toggled, value = %i", value);
1073 g_settings_delay (gsettings_ui);
1074 g_settings_set_boolean (gsettings_ui,
1075 EMPATHY_PREFS_UI_SHOW_AVATARS,
1076 value == CONTACT_LIST_NORMAL_SIZE_WITH_AVATARS);
1078 g_settings_set_boolean (gsettings_ui,
1079 EMPATHY_PREFS_UI_COMPACT_CONTACT_LIST,
1080 value == CONTACT_LIST_COMPACT_SIZE);
1081 g_settings_apply (gsettings_ui);
1083 /* FIXME: these enums probably have the wrong namespace */
1084 empathy_individual_store_set_show_avatars (priv->individual_store,
1085 value == CONTACT_LIST_NORMAL_SIZE_WITH_AVATARS);
1086 empathy_individual_store_set_is_compact (priv->individual_store,
1087 value == CONTACT_LIST_COMPACT_SIZE);
1089 g_object_unref (gsettings_ui);
1092 static void main_window_notify_show_protocols_cb (GSettings *gsettings,
1094 EmpathyMainWindow *window)
1096 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1098 gtk_toggle_action_set_active (priv->show_protocols,
1099 g_settings_get_boolean (gsettings,
1100 EMPATHY_PREFS_UI_SHOW_PROTOCOLS));
1105 main_window_notify_contact_list_size_cb (GSettings *gsettings,
1107 EmpathyMainWindow *window)
1109 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1112 if (g_settings_get_boolean (gsettings,
1113 EMPATHY_PREFS_UI_COMPACT_CONTACT_LIST)) {
1114 value = CONTACT_LIST_COMPACT_SIZE;
1115 } else if (g_settings_get_boolean (gsettings,
1116 EMPATHY_PREFS_UI_SHOW_AVATARS)) {
1117 value = CONTACT_LIST_NORMAL_SIZE_WITH_AVATARS;
1119 value = CONTACT_LIST_NORMAL_SIZE;
1122 DEBUG ("setting changed, value = %i", value);
1124 /* By changing the value of the GtkRadioAction,
1125 it emits a signal that calls main_window_view_contacts_list_size_cb
1126 which updates the contacts list */
1127 gtk_radio_action_set_current_value (priv->normal_with_avatars, value);
1131 main_window_edit_search_contacts_cb (GtkCheckMenuItem *item,
1132 EmpathyMainWindow *window)
1134 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1136 empathy_individual_view_start_search (priv->individual_view);
1140 main_window_view_show_map_cb (GtkCheckMenuItem *item,
1141 EmpathyMainWindow *window)
1143 #ifdef HAVE_LIBCHAMPLAIN
1144 empathy_map_view_show ();
1149 join_chatroom (EmpathyChatroom *chatroom,
1155 account = empathy_chatroom_get_account (chatroom);
1156 room = empathy_chatroom_get_room (chatroom);
1158 DEBUG ("Requesting channel for '%s'", room);
1159 empathy_dispatcher_join_muc (account, room, timestamp);
1165 EmpathyChatroom *chatroom;
1169 } join_fav_account_sig_ctx;
1171 static join_fav_account_sig_ctx *
1172 join_fav_account_sig_ctx_new (TpAccount *account,
1173 EmpathyChatroom *chatroom,
1176 join_fav_account_sig_ctx *ctx = g_slice_new0 (
1177 join_fav_account_sig_ctx);
1179 ctx->account = g_object_ref (account);
1180 ctx->chatroom = g_object_ref (chatroom);
1181 ctx->timestamp = timestamp;
1186 join_fav_account_sig_ctx_free (join_fav_account_sig_ctx *ctx)
1188 g_object_unref (ctx->account);
1189 g_object_unref (ctx->chatroom);
1190 g_slice_free (join_fav_account_sig_ctx, ctx);
1194 account_status_changed_cb (TpAccount *account,
1195 TpConnectionStatus old_status,
1196 TpConnectionStatus new_status,
1198 gchar *dbus_error_name,
1199 GHashTable *details,
1202 join_fav_account_sig_ctx *ctx = user_data;
1204 switch (new_status) {
1205 case TP_CONNECTION_STATUS_DISCONNECTED:
1206 /* Don't wait any longer */
1210 case TP_CONNECTION_STATUS_CONNECTING:
1214 case TP_CONNECTION_STATUS_CONNECTED:
1215 /* We can join the room */
1219 g_assert_not_reached ();
1222 join_chatroom (ctx->chatroom, ctx->timestamp);
1225 g_source_remove (ctx->timeout);
1226 g_signal_handler_disconnect (account, ctx->sig_id);
1229 #define JOIN_FAVORITE_TIMEOUT 5
1232 join_favorite_timeout_cb (gpointer data)
1234 join_fav_account_sig_ctx *ctx = data;
1236 /* stop waiting for joining the favorite room */
1237 g_signal_handler_disconnect (ctx->account, ctx->sig_id);
1242 main_window_favorite_chatroom_join (EmpathyChatroom *chatroom)
1246 account = empathy_chatroom_get_account (chatroom);
1247 if (tp_account_get_connection_status (account, NULL) !=
1248 TP_CONNECTION_STATUS_CONNECTED) {
1249 join_fav_account_sig_ctx *ctx;
1251 ctx = join_fav_account_sig_ctx_new (account, chatroom,
1252 gtk_get_current_event_time ());
1254 ctx->sig_id = g_signal_connect_data (account, "status-changed",
1255 G_CALLBACK (account_status_changed_cb), ctx,
1256 (GClosureNotify) join_fav_account_sig_ctx_free, 0);
1258 ctx->timeout = g_timeout_add_seconds (JOIN_FAVORITE_TIMEOUT,
1259 join_favorite_timeout_cb, ctx);
1263 join_chatroom (chatroom, gtk_get_current_event_time ());
1267 main_window_favorite_chatroom_menu_activate_cb (GtkMenuItem *menu_item,
1268 EmpathyChatroom *chatroom)
1270 main_window_favorite_chatroom_join (chatroom);
1274 main_window_favorite_chatroom_menu_add (EmpathyMainWindow *window,
1275 EmpathyChatroom *chatroom)
1277 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1278 GtkWidget *menu_item;
1281 if (g_object_get_data (G_OBJECT (chatroom), "menu_item")) {
1285 name = empathy_chatroom_get_name (chatroom);
1286 menu_item = gtk_menu_item_new_with_label (name);
1287 g_object_set_data (G_OBJECT (menu_item), "is_favorite",
1288 GUINT_TO_POINTER (TRUE));
1290 g_object_set_data (G_OBJECT (chatroom), "menu_item", menu_item);
1291 g_signal_connect (menu_item, "activate",
1292 G_CALLBACK (main_window_favorite_chatroom_menu_activate_cb),
1295 gtk_menu_shell_insert (GTK_MENU_SHELL (priv->room_menu),
1298 gtk_widget_show (menu_item);
1302 main_window_favorite_chatroom_menu_added_cb (EmpathyChatroomManager *manager,
1303 EmpathyChatroom *chatroom,
1304 EmpathyMainWindow *window)
1306 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1308 main_window_favorite_chatroom_menu_add (window, chatroom);
1309 gtk_widget_show (priv->room_separator);
1310 gtk_action_set_sensitive (priv->room_join_favorites, TRUE);
1314 main_window_favorite_chatroom_menu_removed_cb (EmpathyChatroomManager *manager,
1315 EmpathyChatroom *chatroom,
1316 EmpathyMainWindow *window)
1318 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1319 GtkWidget *menu_item;
1322 menu_item = g_object_get_data (G_OBJECT (chatroom), "menu_item");
1323 g_object_set_data (G_OBJECT (chatroom), "menu_item", NULL);
1324 gtk_widget_destroy (menu_item);
1326 chatrooms = empathy_chatroom_manager_get_chatrooms (priv->chatroom_manager, NULL);
1328 gtk_widget_show (priv->room_separator);
1330 gtk_widget_hide (priv->room_separator);
1333 gtk_action_set_sensitive (priv->room_join_favorites, chatrooms != NULL);
1334 g_list_free (chatrooms);
1338 main_window_favorite_chatroom_menu_setup (EmpathyMainWindow *window)
1340 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1341 GList *chatrooms, *l;
1344 priv->chatroom_manager = empathy_chatroom_manager_dup_singleton (NULL);
1345 chatrooms = empathy_chatroom_manager_get_chatrooms (
1346 priv->chatroom_manager, NULL);
1347 room = gtk_ui_manager_get_widget (priv->ui_manager,
1349 priv->room_menu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (room));
1350 priv->room_separator = gtk_ui_manager_get_widget (priv->ui_manager,
1351 "/menubar/room/room_separator");
1353 for (l = chatrooms; l; l = l->next) {
1354 main_window_favorite_chatroom_menu_add (window, l->data);
1358 gtk_widget_hide (priv->room_separator);
1361 gtk_action_set_sensitive (priv->room_join_favorites, chatrooms != NULL);
1363 g_signal_connect (priv->chatroom_manager, "chatroom-added",
1364 G_CALLBACK (main_window_favorite_chatroom_menu_added_cb),
1366 g_signal_connect (priv->chatroom_manager, "chatroom-removed",
1367 G_CALLBACK (main_window_favorite_chatroom_menu_removed_cb),
1370 g_list_free (chatrooms);
1374 main_window_room_join_new_cb (GtkAction *action,
1375 EmpathyMainWindow *window)
1377 empathy_new_chatroom_dialog_show (GTK_WINDOW (window));
1381 main_window_room_join_favorites_cb (GtkAction *action,
1382 EmpathyMainWindow *window)
1384 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1385 GList *chatrooms, *l;
1387 chatrooms = empathy_chatroom_manager_get_chatrooms (priv->chatroom_manager, NULL);
1388 for (l = chatrooms; l; l = l->next) {
1389 main_window_favorite_chatroom_join (l->data);
1391 g_list_free (chatrooms);
1395 main_window_room_manage_favorites_cb (GtkAction *action,
1396 EmpathyMainWindow *window)
1398 empathy_chatrooms_window_show (GTK_WINDOW (window));
1402 main_window_edit_cb (GtkAction *action,
1403 EmpathyMainWindow *window)
1405 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1408 /* FIXME: It should use the UIManager to merge the contact/group submenu */
1409 submenu = empathy_individual_view_get_individual_menu (
1410 priv->individual_view);
1415 item = GTK_MENU_ITEM (priv->edit_context);
1416 label = gtk_bin_get_child (GTK_BIN (item));
1417 gtk_label_set_text (GTK_LABEL (label), _("Contact"));
1419 gtk_widget_show (priv->edit_context);
1420 gtk_widget_show (priv->edit_context_separator);
1422 gtk_menu_item_set_submenu (item, submenu);
1427 submenu = empathy_individual_view_get_group_menu (
1428 priv->individual_view);
1433 item = GTK_MENU_ITEM (priv->edit_context);
1434 label = gtk_bin_get_child (GTK_BIN (item));
1435 gtk_label_set_text (GTK_LABEL (label), _("Group"));
1437 gtk_widget_show (priv->edit_context);
1438 gtk_widget_show (priv->edit_context_separator);
1440 gtk_menu_item_set_submenu (item, submenu);
1445 gtk_widget_hide (priv->edit_context);
1446 gtk_widget_hide (priv->edit_context_separator);
1452 main_window_edit_accounts_cb (GtkAction *action,
1453 EmpathyMainWindow *window)
1455 empathy_accounts_dialog_show_application (gdk_screen_get_default (),
1456 NULL, FALSE, FALSE);
1460 main_window_edit_personal_information_cb (GtkAction *action,
1461 EmpathyMainWindow *window)
1463 empathy_contact_personal_dialog_show (GTK_WINDOW (window));
1467 main_window_edit_preferences_cb (GtkAction *action,
1468 EmpathyMainWindow *window)
1470 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1472 if (priv->preferences == NULL) {
1473 priv->preferences = empathy_preferences_new (GTK_WINDOW (window));
1474 g_object_add_weak_pointer (G_OBJECT (priv->preferences),
1475 (gpointer) &priv->preferences);
1477 gtk_widget_show (priv->preferences);
1479 gtk_window_present (GTK_WINDOW (priv->preferences));
1484 main_window_help_about_cb (GtkAction *action,
1485 EmpathyMainWindow *window)
1487 empathy_about_dialog_new (GTK_WINDOW (window));
1491 main_window_help_debug_cb (GtkAction *action,
1492 EmpathyMainWindow *window)
1494 GdkDisplay *display;
1495 GError *error = NULL;
1498 GdkAppLaunchContext *context = NULL;
1500 /* Try to run from source directory if possible */
1501 path = g_build_filename (g_getenv ("EMPATHY_SRCDIR"), "src",
1502 "empathy-debugger", NULL);
1504 if (!g_file_test (path, G_FILE_TEST_EXISTS)) {
1506 path = g_build_filename (BIN_DIR, "empathy-debugger", NULL);
1509 app_info = g_app_info_create_from_commandline (path, NULL, 0, &error);
1510 if (app_info == NULL) {
1511 DEBUG ("Failed to create app info: %s", error->message);
1512 g_error_free (error);
1516 display = gdk_display_get_default ();
1517 context = gdk_display_get_app_launch_context (display);
1519 if (!g_app_info_launch (app_info, NULL, (GAppLaunchContext *) context,
1521 g_warning ("Failed to open debug window: %s", error->message);
1522 g_error_free (error);
1527 tp_clear_object (&app_info);
1528 tp_clear_object (&context);
1533 main_window_help_contents_cb (GtkAction *action,
1534 EmpathyMainWindow *window)
1536 empathy_url_show (GTK_WIDGET (window), "ghelp:empathy");
1540 main_window_throbber_button_press_event_cb (GtkWidget *throbber,
1541 GdkEventButton *event,
1542 EmpathyMainWindow *window)
1544 if (event->type != GDK_BUTTON_PRESS ||
1545 event->button != 1) {
1549 empathy_accounts_dialog_show_application (
1550 gtk_widget_get_screen (GTK_WIDGET (throbber)),
1551 NULL, FALSE, FALSE);
1557 main_window_account_removed_cb (TpAccountManager *manager,
1559 EmpathyMainWindow *window)
1561 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1564 a = tp_account_manager_get_valid_accounts (manager);
1566 gtk_action_set_sensitive (priv->view_history,
1567 g_list_length (a) > 0);
1571 /* remove errors if any */
1572 main_window_remove_error (window, account);
1576 main_window_account_validity_changed_cb (TpAccountManager *manager,
1579 EmpathyMainWindow *window)
1581 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1585 handler_id = GPOINTER_TO_UINT (g_hash_table_lookup (
1586 priv->status_changed_handlers, account));
1588 /* connect signal only if it was not connected yet */
1589 if (handler_id == 0) {
1590 handler_id = g_signal_connect (account,
1592 G_CALLBACK (main_window_connection_changed_cb),
1594 g_hash_table_insert (priv->status_changed_handlers,
1595 account, GUINT_TO_POINTER (handler_id));
1599 main_window_account_removed_cb (manager, account, window);
1603 main_window_notify_show_offline_cb (GSettings *gsettings,
1605 gpointer toggle_action)
1607 gtk_toggle_action_set_active (toggle_action,
1608 g_settings_get_boolean (gsettings, key));
1612 main_window_connection_items_setup (EmpathyMainWindow *window,
1615 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1619 const gchar *actions_connected[] = {
1621 "room_join_favorites",
1625 "edit_personal_information"
1628 for (i = 0, list = NULL; i < G_N_ELEMENTS (actions_connected); i++) {
1629 action = gtk_builder_get_object (gui, actions_connected[i]);
1630 list = g_list_prepend (list, action);
1633 priv->actions_connected = list;
1637 account_manager_prepared_cb (GObject *source_object,
1638 GAsyncResult *result,
1641 GList *accounts, *j;
1642 TpAccountManager *manager = TP_ACCOUNT_MANAGER (source_object);
1643 EmpathyMainWindow *window = user_data;
1644 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1645 GError *error = NULL;
1647 if (!tp_account_manager_prepare_finish (manager, result, &error)) {
1648 DEBUG ("Failed to prepare account manager: %s", error->message);
1649 g_error_free (error);
1653 accounts = tp_account_manager_get_valid_accounts (priv->account_manager);
1654 for (j = accounts; j != NULL; j = j->next) {
1655 TpAccount *account = TP_ACCOUNT (j->data);
1658 handler_id = g_signal_connect (account, "status-changed",
1659 G_CALLBACK (main_window_connection_changed_cb),
1661 g_hash_table_insert (priv->status_changed_handlers,
1662 account, GUINT_TO_POINTER (handler_id));
1665 g_signal_connect (manager, "account-validity-changed",
1666 G_CALLBACK (main_window_account_validity_changed_cb),
1669 main_window_update_status (window);
1671 /* Disable the "Previous Conversations" menu entry if there is no account */
1672 gtk_action_set_sensitive (priv->view_history,
1673 g_list_length (accounts) > 0);
1675 g_list_free (accounts);
1679 main_window_members_changed_cb (EmpathyContactList *list,
1680 EmpathyContact *contact,
1681 EmpathyContact *actor,
1685 EmpathyMainWindow *window)
1687 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1692 if (!empathy_migrate_butterfly_logs (contact)) {
1693 g_signal_handler_disconnect (list,
1694 priv->butterfly_log_migration_members_changed_id);
1695 priv->butterfly_log_migration_members_changed_id = 0;
1700 empathy_main_window_constructor (GType type,
1701 guint n_construct_params,
1702 GObjectConstructParam *construct_params)
1704 static GObject *window = NULL;
1707 return g_object_ref (window);
1709 window = G_OBJECT_CLASS (empathy_main_window_parent_class)->constructor (
1710 type, n_construct_params, construct_params);
1712 g_object_add_weak_pointer (window, (gpointer) &window);
1718 empathy_main_window_class_init (EmpathyMainWindowClass *klass)
1720 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1722 object_class->finalize = empathy_main_window_finalize;
1723 object_class->constructor = empathy_main_window_constructor;
1725 g_type_class_add_private (object_class, sizeof (EmpathyMainWindowPriv));
1729 empathy_main_window_init (EmpathyMainWindow *window)
1731 EmpathyMainWindowPriv *priv;
1732 EmpathyIndividualManager *individual_manager;
1735 GtkToggleAction *show_offline_widget;
1736 GtkAction *show_map_widget;
1738 gboolean show_offline;
1741 GtkTreeModel *model;
1743 priv = window->priv = G_TYPE_INSTANCE_GET_PRIVATE (window,
1744 EMPATHY_TYPE_MAIN_WINDOW, EmpathyMainWindowPriv);
1746 priv->gsettings_ui = g_settings_new (EMPATHY_PREFS_UI_SCHEMA);
1747 priv->gsettings_contacts = g_settings_new (EMPATHY_PREFS_CONTACTS_SCHEMA);
1749 priv->sound_mgr = empathy_sound_manager_dup_singleton ();
1751 gtk_window_set_title (GTK_WINDOW (window), _("Contact List"));
1752 gtk_window_set_role (GTK_WINDOW (window), "contact_list");
1753 gtk_window_set_default_size (GTK_WINDOW (window), 225, 325);
1755 /* Set up interface */
1756 filename = empathy_file_lookup ("empathy-main-window.ui", "src");
1757 gui = empathy_builder_get_file (filename,
1758 "main_vbox", &priv->main_vbox,
1759 "errors_vbox", &priv->errors_vbox,
1760 "auth_vbox", &priv->auth_vbox,
1761 "ui_manager", &priv->ui_manager,
1762 "view_show_offline", &show_offline_widget,
1763 "view_show_protocols", &priv->show_protocols,
1764 "view_sort_by_name", &priv->sort_by_name,
1765 "view_sort_by_status", &priv->sort_by_status,
1766 "view_normal_size_with_avatars", &priv->normal_with_avatars,
1767 "view_normal_size", &priv->normal_size,
1768 "view_compact_size", &priv->compact_size,
1769 "view_history", &priv->view_history,
1770 "view_show_map", &show_map_widget,
1771 "room_join_favorites", &priv->room_join_favorites,
1772 "presence_toolbar", &priv->presence_toolbar,
1773 "notebook", &priv->notebook,
1774 "no_entry_label", &priv->no_entry_label,
1775 "roster_scrolledwindow", &sw,
1779 gtk_container_add (GTK_CONTAINER (window), priv->main_vbox);
1780 gtk_widget_show (priv->main_vbox);
1782 g_signal_connect (window, "key-press-event",
1783 G_CALLBACK (main_window_key_press_event_cb), NULL);
1785 empathy_builder_connect (gui, window,
1786 "chat_quit", "activate", main_window_chat_quit_cb,
1787 "chat_new_message", "activate", main_window_chat_new_message_cb,
1788 "chat_new_call", "activate", main_window_chat_new_call_cb,
1789 "view_history", "activate", main_window_view_history_cb,
1790 "room_join_new", "activate", main_window_room_join_new_cb,
1791 "room_join_favorites", "activate", main_window_room_join_favorites_cb,
1792 "room_manage_favorites", "activate", main_window_room_manage_favorites_cb,
1793 "chat_add_contact", "activate", main_window_chat_add_contact_cb,
1794 "chat_search_contacts", "activate", main_window_chat_search_contacts_cb,
1795 "view_show_ft_manager", "activate", main_window_view_show_ft_manager,
1796 "view_show_offline", "toggled", main_window_view_show_offline_cb,
1797 "view_show_protocols", "toggled", main_window_view_show_protocols_cb,
1798 "view_sort_by_name", "changed", main_window_view_sort_contacts_cb,
1799 "view_normal_size_with_avatars", "changed", main_window_view_contacts_list_size_cb,
1800 "view_show_map", "activate", main_window_view_show_map_cb,
1801 "edit", "activate", main_window_edit_cb,
1802 "edit_accounts", "activate", main_window_edit_accounts_cb,
1803 "edit_personal_information", "activate", main_window_edit_personal_information_cb,
1804 "edit_preferences", "activate", main_window_edit_preferences_cb,
1805 "edit_search_contacts", "activate", main_window_edit_search_contacts_cb,
1806 "help_about", "activate", main_window_help_about_cb,
1807 "help_debug", "activate", main_window_help_debug_cb,
1808 "help_contents", "activate", main_window_help_contents_cb,
1811 /* Set up connection related widgets. */
1812 main_window_connection_items_setup (window, gui);
1814 g_object_ref (priv->ui_manager);
1815 g_object_unref (gui);
1817 #ifndef HAVE_LIBCHAMPLAIN
1818 gtk_action_set_visible (show_map_widget, FALSE);
1821 priv->account_manager = tp_account_manager_dup ();
1823 tp_account_manager_prepare_async (priv->account_manager, NULL,
1824 account_manager_prepared_cb, window);
1826 priv->errors = g_hash_table_new_full (g_direct_hash,
1831 priv->auths = g_hash_table_new (NULL, NULL);
1833 priv->status_changed_handlers = g_hash_table_new_full (g_direct_hash,
1839 main_window_favorite_chatroom_menu_setup (window);
1841 priv->edit_context = gtk_ui_manager_get_widget (priv->ui_manager,
1842 "/menubar/edit/edit_context");
1843 priv->edit_context_separator = gtk_ui_manager_get_widget (
1845 "/menubar/edit/edit_context_separator");
1846 gtk_widget_hide (priv->edit_context);
1847 gtk_widget_hide (priv->edit_context_separator);
1849 /* Set up contact list. */
1850 empathy_status_presets_get_all ();
1852 /* Set up presence chooser */
1853 priv->presence_chooser = empathy_presence_chooser_new ();
1854 gtk_widget_show (priv->presence_chooser);
1855 item = gtk_tool_item_new ();
1856 gtk_widget_show (GTK_WIDGET (item));
1857 gtk_widget_set_size_request (priv->presence_chooser, 10, -1);
1858 gtk_container_add (GTK_CONTAINER (item), priv->presence_chooser);
1859 gtk_tool_item_set_is_important (item, TRUE);
1860 gtk_tool_item_set_expand (item, TRUE);
1861 gtk_toolbar_insert (GTK_TOOLBAR (priv->presence_toolbar), item, -1);
1863 /* Set up the throbber */
1864 priv->throbber = gtk_spinner_new ();
1865 gtk_widget_set_size_request (priv->throbber, 16, -1);
1866 gtk_widget_set_tooltip_text (priv->throbber, _("Show and edit accounts"));
1867 gtk_widget_set_events (priv->throbber, GDK_BUTTON_PRESS_MASK);
1868 g_signal_connect (priv->throbber, "button-press-event",
1869 G_CALLBACK (main_window_throbber_button_press_event_cb),
1871 gtk_widget_show (priv->throbber);
1873 item = gtk_tool_item_new ();
1874 gtk_container_set_border_width (GTK_CONTAINER (item), 6);
1875 gtk_toolbar_insert (GTK_TOOLBAR (priv->presence_toolbar), item, -1);
1876 gtk_container_add (GTK_CONTAINER (item), priv->throbber);
1877 priv->throbber_tool_item = GTK_WIDGET (item);
1879 /* XXX: this class is designed to live for the duration of the program,
1880 * so it's got a race condition between its signal handlers and its
1881 * finalization. The class is planned to be removed, so we won't fix
1882 * this before then. */
1883 priv->contact_manager = EMPATHY_CONTACT_LIST (
1884 empathy_contact_manager_dup_singleton ());
1885 individual_manager = empathy_individual_manager_dup_singleton ();
1886 priv->individual_store = empathy_individual_store_new (
1887 individual_manager);
1888 g_object_unref (individual_manager);
1890 /* For the moment, we disallow Persona drops onto the main contact list (e.g. from things such as
1891 * the EmpathyPersonaView in the linking dialogue). No code is hooked up to do anything on a Persona
1892 * drop, so allowing them would achieve nothing except confusion. */
1893 priv->individual_view = empathy_individual_view_new (
1894 priv->individual_store,
1895 EMPATHY_INDIVIDUAL_VIEW_FEATURE_ALL ^ EMPATHY_INDIVIDUAL_VIEW_FEATURE_PERSONA_DROP,
1896 EMPATHY_INDIVIDUAL_FEATURE_ALL);
1898 priv->butterfly_log_migration_members_changed_id = g_signal_connect (
1899 priv->contact_manager, "members-changed",
1900 G_CALLBACK (main_window_members_changed_cb), window);
1902 gtk_widget_show (GTK_WIDGET (priv->individual_view));
1903 gtk_container_add (GTK_CONTAINER (sw),
1904 GTK_WIDGET (priv->individual_view));
1905 g_signal_connect (priv->individual_view, "row-activated",
1906 G_CALLBACK (main_window_row_activated_cb),
1909 /* Set up search bar */
1910 priv->search_bar = empathy_live_search_new (
1911 GTK_WIDGET (priv->individual_view));
1912 empathy_individual_view_set_live_search (priv->individual_view,
1913 EMPATHY_LIVE_SEARCH (priv->search_bar));
1914 gtk_box_pack_start (GTK_BOX (priv->main_vbox), priv->search_bar,
1916 g_signal_connect_swapped (window, "map",
1917 G_CALLBACK (gtk_widget_grab_focus), priv->individual_view);
1919 /* Connect to proper signals to check if contact list is empty or not */
1920 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->individual_view));
1922 g_signal_connect (model, "row-inserted",
1923 G_CALLBACK (main_window_row_inserted_cb),
1925 g_signal_connect (model, "row-deleted",
1926 G_CALLBACK (main_window_row_deleted_cb),
1929 /* Load user-defined accelerators. */
1930 main_window_accels_load ();
1932 /* Set window size. */
1933 empathy_geometry_bind (GTK_WINDOW (window), GEOMETRY_NAME);
1935 /* Enable event handling */
1936 priv->call_observer = empathy_call_observer_dup_singleton ();
1937 priv->event_manager = empathy_event_manager_dup_singleton ();
1939 g_signal_connect (priv->event_manager, "event-added",
1940 G_CALLBACK (main_window_event_added_cb), window);
1941 g_signal_connect (priv->event_manager, "event-removed",
1942 G_CALLBACK (main_window_event_removed_cb), window);
1943 g_signal_connect (priv->account_manager, "account-validity-changed",
1944 G_CALLBACK (main_window_account_validity_changed_cb),
1946 g_signal_connect (priv->account_manager, "account-removed",
1947 G_CALLBACK (main_window_account_removed_cb),
1949 g_signal_connect (priv->account_manager, "account-disabled",
1950 G_CALLBACK (main_window_account_disabled_cb),
1953 l = empathy_event_manager_get_events (priv->event_manager);
1955 main_window_event_added_cb (priv->event_manager, l->data,
1960 /* Show offline ? */
1961 show_offline = g_settings_get_boolean (priv->gsettings_ui,
1962 EMPATHY_PREFS_UI_SHOW_OFFLINE);
1963 g_signal_connect (priv->gsettings_ui,
1964 "changed::" EMPATHY_PREFS_UI_SHOW_OFFLINE,
1965 G_CALLBACK (main_window_notify_show_offline_cb),
1966 show_offline_widget);
1968 gtk_toggle_action_set_active (show_offline_widget, show_offline);
1970 /* Show protocol ? */
1971 g_signal_connect (priv->gsettings_ui,
1972 "changed::" EMPATHY_PREFS_UI_SHOW_PROTOCOLS,
1973 G_CALLBACK (main_window_notify_show_protocols_cb),
1976 main_window_notify_show_protocols_cb (priv->gsettings_ui,
1977 EMPATHY_PREFS_UI_SHOW_PROTOCOLS,
1980 /* Sort by name / by status ? */
1981 g_signal_connect (priv->gsettings_contacts,
1982 "changed::" EMPATHY_PREFS_CONTACTS_SORT_CRITERIUM,
1983 G_CALLBACK (main_window_notify_sort_contact_cb),
1986 main_window_notify_sort_contact_cb (priv->gsettings_contacts,
1987 EMPATHY_PREFS_CONTACTS_SORT_CRITERIUM,
1990 /* Contacts list size */
1991 g_signal_connect (priv->gsettings_ui,
1992 "changed::" EMPATHY_PREFS_UI_COMPACT_CONTACT_LIST,
1993 G_CALLBACK (main_window_notify_contact_list_size_cb),
1995 g_signal_connect (priv->gsettings_ui,
1996 "changed::" EMPATHY_PREFS_UI_SHOW_AVATARS,
1997 G_CALLBACK (main_window_notify_contact_list_size_cb),
2000 main_window_notify_contact_list_size_cb (priv->gsettings_ui,
2001 EMPATHY_PREFS_UI_SHOW_AVATARS,
2006 empathy_main_window_dup (void)
2008 return g_object_new (EMPATHY_TYPE_MAIN_WINDOW, NULL);