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-request-util.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-blocking-dialog.h>
54 #include <libempathy-gtk/empathy-contact-search-dialog.h>
55 #include <libempathy-gtk/empathy-geometry.h>
56 #include <libempathy-gtk/empathy-gtk-enum-types.h>
57 #include <libempathy-gtk/empathy-individual-dialogs.h>
58 #include <libempathy-gtk/empathy-individual-store.h>
59 #include <libempathy-gtk/empathy-individual-view.h>
60 #include <libempathy-gtk/empathy-new-message-dialog.h>
61 #include <libempathy-gtk/empathy-new-call-dialog.h>
62 #include <libempathy-gtk/empathy-log-window.h>
63 #include <libempathy-gtk/empathy-presence-chooser.h>
64 #include <libempathy-gtk/empathy-sound-manager.h>
65 #include <libempathy-gtk/empathy-ui-utils.h>
67 #include "empathy-accounts-dialog.h"
68 #include "empathy-call-observer.h"
69 #include "empathy-chat-manager.h"
70 #include "empathy-main-window.h"
71 #include "empathy-preferences.h"
72 #include "empathy-about-dialog.h"
73 #include "empathy-debug-window.h"
74 #include "empathy-new-chatroom-dialog.h"
75 #include "empathy-map-view.h"
76 #include "empathy-chatrooms-window.h"
77 #include "empathy-event-manager.h"
78 #include "empathy-ft-manager.h"
79 #include "empathy-migrate-butterfly-logs.h"
81 #define DEBUG_FLAG EMPATHY_DEBUG_OTHER
82 #include <libempathy/empathy-debug.h>
84 /* Flashing delay for icons (milliseconds). */
85 #define FLASH_TIMEOUT 500
87 /* Minimum width of roster window if something goes wrong. */
90 /* Accels (menu shortcuts) can be configured and saved */
91 #define ACCELS_FILENAME "accels.txt"
93 /* Name in the geometry file */
94 #define GEOMETRY_NAME "main-window"
97 PAGE_CONTACT_LIST = 0,
101 G_DEFINE_TYPE (EmpathyMainWindow, empathy_main_window, GTK_TYPE_WINDOW);
103 #define GET_PRIV(self) ((EmpathyMainWindowPriv *)((EmpathyMainWindow *) self)->priv)
105 struct _EmpathyMainWindowPriv {
106 EmpathyContactList *contact_manager;
107 EmpathyIndividualStore *individual_store;
108 EmpathyIndividualView *individual_view;
109 TpAccountManager *account_manager;
110 EmpathyChatroomManager *chatroom_manager;
111 EmpathyEventManager *event_manager;
112 EmpathySoundManager *sound_mgr;
113 EmpathyCallObserver *call_observer;
114 guint flash_timeout_id;
118 GSettings *gsettings_ui;
119 GSettings *gsettings_contacts;
121 GtkWidget *preferences;
122 GtkWidget *main_vbox;
124 GtkWidget *throbber_tool_item;
125 GtkWidget *presence_toolbar;
126 GtkWidget *presence_chooser;
127 GtkWidget *errors_vbox;
128 GtkWidget *auth_vbox;
129 GtkWidget *search_bar;
131 GtkWidget *no_entry_label;
133 GtkToggleAction *show_protocols;
134 GtkRadioAction *sort_by_name;
135 GtkRadioAction *sort_by_status;
136 GtkRadioAction *normal_with_avatars;
137 GtkRadioAction *normal_size;
138 GtkRadioAction *compact_size;
140 GtkUIManager *ui_manager;
141 GtkAction *view_history;
142 GtkAction *room_join_favorites;
143 GtkWidget *room_menu;
144 GtkWidget *room_separator;
145 GtkWidget *edit_context;
146 GtkWidget *edit_context_separator;
148 guint size_timeout_id;
150 /* reffed TpAccount* => visible GtkInfoBar* */
153 /* EmpathyEvent* => visible GtkInfoBar* */
156 /* stores a mapping from TpAccount to Handler ID to prevent
157 * to listen more than once to the status-changed signal */
158 GHashTable *status_changed_handlers;
160 /* Actions that are enabled when there are connected accounts */
161 GList *actions_connected;
163 /* The idle event source to migrate butterfly's logs */
164 guint butterfly_log_migration_members_changed_id;
168 main_window_flash_stop (EmpathyMainWindow *window)
170 EmpathyMainWindowPriv *priv = GET_PRIV (window);
172 if (priv->flash_timeout_id == 0) {
176 DEBUG ("Stop flashing");
177 g_source_remove (priv->flash_timeout_id);
178 priv->flash_timeout_id = 0;
179 priv->flash_on = FALSE;
185 EmpathyMainWindow *window;
189 main_window_flash_foreach (GtkTreeModel *model,
194 FlashForeachData *data = (FlashForeachData *) user_data;
195 FolksIndividual *individual;
196 EmpathyContact *contact;
197 const gchar *icon_name;
198 GtkTreePath *parent_path = NULL;
199 GtkTreeIter parent_iter;
200 GdkPixbuf *pixbuf = NULL;
202 gtk_tree_model_get (model, iter,
203 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL,
207 if (individual == NULL)
210 contact = empathy_contact_dup_from_folks_individual (individual);
211 if (contact != data->event->contact) {
212 tp_clear_object (&contact);
217 icon_name = data->event->icon_name;
218 pixbuf = empathy_pixbuf_from_icon_name (icon_name, GTK_ICON_SIZE_MENU);
220 pixbuf = empathy_individual_store_get_individual_status_icon (
221 GET_PRIV (data->window)->individual_store,
224 g_object_ref (pixbuf);
227 gtk_tree_store_set (GTK_TREE_STORE (model), iter,
228 EMPATHY_INDIVIDUAL_STORE_COL_ICON_STATUS, pixbuf,
231 /* To make sure the parent is shown correctly, we emit
232 * the row-changed signal on the parent so it prompts
233 * it to be refreshed by the filter func.
235 if (gtk_tree_model_iter_parent (model, &parent_iter, iter)) {
236 parent_path = gtk_tree_model_get_path (model, &parent_iter);
239 gtk_tree_model_row_changed (model, parent_path, &parent_iter);
240 gtk_tree_path_free (parent_path);
243 g_object_unref (individual);
244 tp_clear_object (&contact);
245 tp_clear_object (&pixbuf);
251 main_window_flash_cb (EmpathyMainWindow *window)
253 EmpathyMainWindowPriv *priv = GET_PRIV (window);
256 gboolean found_event = FALSE;
257 FlashForeachData data;
259 priv->flash_on = !priv->flash_on;
260 data.on = priv->flash_on;
261 model = GTK_TREE_MODEL (priv->individual_store);
263 events = empathy_event_manager_get_events (priv->event_manager);
264 for (l = events; l; l = l->next) {
265 data.event = l->data;
266 data.window = window;
267 if (!data.event->contact || !data.event->must_ack) {
272 gtk_tree_model_foreach (model,
273 main_window_flash_foreach,
278 main_window_flash_stop (window);
285 main_window_flash_start (EmpathyMainWindow *window)
287 EmpathyMainWindowPriv *priv = GET_PRIV (window);
289 if (priv->flash_timeout_id != 0) {
293 DEBUG ("Start flashing");
294 priv->flash_timeout_id = g_timeout_add (FLASH_TIMEOUT,
295 (GSourceFunc) main_window_flash_cb,
297 main_window_flash_cb (window);
301 main_window_remove_auth (EmpathyMainWindow *window,
304 EmpathyMainWindowPriv *priv = GET_PRIV (window);
305 GtkWidget *error_widget;
307 error_widget = g_hash_table_lookup (priv->auths, event);
308 if (error_widget != NULL) {
309 gtk_widget_destroy (error_widget);
310 g_hash_table_remove (priv->auths, event);
315 main_window_auth_add_clicked_cb (GtkButton *button,
316 EmpathyMainWindow *window)
320 event = g_object_get_data (G_OBJECT (button), "event");
322 empathy_event_approve (event);
324 main_window_remove_auth (window, event);
328 main_window_auth_close_clicked_cb (GtkButton *button,
329 EmpathyMainWindow *window)
333 event = g_object_get_data (G_OBJECT (button), "event");
335 empathy_event_decline (event);
336 main_window_remove_auth (window, event);
340 main_window_auth_display (EmpathyMainWindow *window,
343 EmpathyMainWindowPriv *priv = GET_PRIV (window);
344 TpAccount *account = event->account;
346 GtkWidget *content_area;
349 GtkWidget *add_button;
350 GtkWidget *close_button;
351 GtkWidget *action_area;
352 GtkWidget *action_table;
353 const gchar *icon_name;
356 if (g_hash_table_lookup (priv->auths, event) != NULL) {
360 info_bar = gtk_info_bar_new ();
361 gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_QUESTION);
363 gtk_widget_set_no_show_all (info_bar, TRUE);
364 gtk_box_pack_start (GTK_BOX (priv->auth_vbox), info_bar, FALSE, TRUE, 0);
365 gtk_widget_show (info_bar);
367 icon_name = tp_account_get_icon_name (account);
368 image = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_SMALL_TOOLBAR);
369 gtk_widget_show (image);
371 str = g_markup_printf_escaped ("<b>%s</b>\n%s",
372 tp_account_get_display_name (account),
373 _("Password required"));
375 label = gtk_label_new (str);
376 gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
377 gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_END);
378 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
379 gtk_widget_show (label);
383 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
384 gtk_box_pack_start (GTK_BOX (content_area), image, FALSE, FALSE, 0);
385 gtk_box_pack_start (GTK_BOX (content_area), label, TRUE, TRUE, 0);
387 image = gtk_image_new_from_stock (GTK_STOCK_ADD, GTK_ICON_SIZE_BUTTON);
388 add_button = gtk_button_new ();
389 gtk_button_set_image (GTK_BUTTON (add_button), image);
390 gtk_widget_set_tooltip_text (add_button, _("Provide Password"));
391 gtk_widget_show (add_button);
393 image = gtk_image_new_from_stock (GTK_STOCK_CLOSE, GTK_ICON_SIZE_BUTTON);
394 close_button = gtk_button_new ();
395 gtk_button_set_image (GTK_BUTTON (close_button), image);
396 gtk_widget_set_tooltip_text (close_button, _("Disconnect"));
397 gtk_widget_show (close_button);
399 action_table = gtk_table_new (1, 2, FALSE);
400 gtk_table_set_col_spacings (GTK_TABLE (action_table), 6);
401 gtk_widget_show (action_table);
403 action_area = gtk_info_bar_get_action_area (GTK_INFO_BAR (info_bar));
404 gtk_box_pack_start (GTK_BOX (action_area), action_table, FALSE, FALSE, 0);
406 gtk_table_attach (GTK_TABLE (action_table), add_button, 0, 1, 0, 1,
407 (GtkAttachOptions) (GTK_SHRINK),
408 (GtkAttachOptions) (GTK_SHRINK), 0, 0);
409 gtk_table_attach (GTK_TABLE (action_table), close_button, 1, 2, 0, 1,
410 (GtkAttachOptions) (GTK_SHRINK),
411 (GtkAttachOptions) (GTK_SHRINK), 0, 0);
413 g_object_set_data_full (G_OBJECT (info_bar),
414 "event", event, NULL);
415 g_object_set_data_full (G_OBJECT (add_button),
416 "event", event, NULL);
417 g_object_set_data_full (G_OBJECT (close_button),
418 "event", event, NULL);
420 g_signal_connect (add_button, "clicked",
421 G_CALLBACK (main_window_auth_add_clicked_cb),
423 g_signal_connect (close_button, "clicked",
424 G_CALLBACK (main_window_auth_close_clicked_cb),
427 gtk_widget_show (priv->auth_vbox);
429 g_hash_table_insert (priv->auths, event, info_bar);
433 main_window_event_added_cb (EmpathyEventManager *manager,
435 EmpathyMainWindow *window)
437 if (event->contact) {
438 main_window_flash_start (window);
439 } else if (event->type == EMPATHY_EVENT_TYPE_AUTH) {
440 main_window_auth_display (window, event);
445 main_window_event_removed_cb (EmpathyEventManager *manager,
447 EmpathyMainWindow *window)
449 EmpathyMainWindowPriv *priv = GET_PRIV (window);
450 FlashForeachData data;
452 if (event->type == EMPATHY_EVENT_TYPE_AUTH) {
453 main_window_remove_auth (window, event);
457 if (!event->contact) {
463 data.window = window;
464 gtk_tree_model_foreach (GTK_TREE_MODEL (priv->individual_store),
465 main_window_flash_foreach,
470 main_window_row_activated_cb (EmpathyContactListView *view,
472 GtkTreeViewColumn *col,
473 EmpathyMainWindow *window)
475 EmpathyMainWindowPriv *priv = GET_PRIV (window);
476 EmpathyContact *contact = NULL;
477 FolksIndividual *individual;
482 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->individual_view));
483 gtk_tree_model_get_iter (model, &iter, path);
485 gtk_tree_model_get (model, &iter,
486 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL,
490 if (individual != NULL) {
491 contact = empathy_contact_dup_from_folks_individual (individual);
498 /* If the contact has an event activate it, otherwise the
499 * default handler of row-activated will be called. */
500 events = empathy_event_manager_get_events (priv->event_manager);
501 for (l = events; l; l = l->next) {
502 EmpathyEvent *event = l->data;
504 if (event->contact == contact) {
505 DEBUG ("Activate event");
506 empathy_event_activate (event);
508 /* We don't want the default handler of this signal
509 * (e.g. open a chat) */
510 g_signal_stop_emission_by_name (view, "row-activated");
515 g_object_unref (contact);
517 tp_clear_object (&individual);
521 main_window_row_deleted_cb (GtkTreeModel *model,
523 EmpathyMainWindow *window)
525 EmpathyMainWindowPriv *priv = GET_PRIV (window);
526 GtkTreeIter help_iter;
528 if (!gtk_tree_model_get_iter_first (model, &help_iter)) {
531 if (empathy_individual_view_is_searching (
532 priv->individual_view)) {
535 tmp = g_strdup_printf ("<b><span size='xx-large'>%s</span></b>",
536 _("No match found"));
538 gtk_label_set_markup (GTK_LABEL (priv->no_entry_label), tmp);
541 gtk_label_set_line_wrap (GTK_LABEL (priv->no_entry_label),
544 gtk_notebook_set_current_page (
545 GTK_NOTEBOOK (priv->notebook), PAGE_NO_MATCH);
551 main_window_row_inserted_cb (GtkTreeModel *model,
554 EmpathyMainWindow *window)
556 EmpathyMainWindowPriv *priv = GET_PRIV (window);
560 gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook),
562 gtk_widget_grab_focus (GTK_WIDGET (priv->individual_view));
567 main_window_remove_error (EmpathyMainWindow *window,
570 EmpathyMainWindowPriv *priv = GET_PRIV (window);
571 GtkWidget *error_widget;
573 error_widget = g_hash_table_lookup (priv->errors, account);
574 if (error_widget != NULL) {
575 gtk_widget_destroy (error_widget);
576 g_hash_table_remove (priv->errors, account);
581 main_window_account_disabled_cb (TpAccountManager *manager,
583 EmpathyMainWindow *window)
585 main_window_remove_error (window, account);
589 main_window_error_retry_clicked_cb (GtkButton *button,
590 EmpathyMainWindow *window)
594 account = g_object_get_data (G_OBJECT (button), "account");
595 tp_account_reconnect_async (account, NULL, NULL);
597 main_window_remove_error (window, account);
601 main_window_error_edit_clicked_cb (GtkButton *button,
602 EmpathyMainWindow *window)
606 account = g_object_get_data (G_OBJECT (button), "account");
608 empathy_accounts_dialog_show_application (
609 gtk_widget_get_screen (GTK_WIDGET (button)),
610 account, FALSE, FALSE);
612 main_window_remove_error (window, account);
616 main_window_error_close_clicked_cb (GtkButton *button,
617 EmpathyMainWindow *window)
621 account = g_object_get_data (G_OBJECT (button), "account");
622 main_window_remove_error (window, account);
626 main_window_error_display (EmpathyMainWindow *window,
629 EmpathyMainWindowPriv *priv = GET_PRIV (window);
631 GtkWidget *content_area;
634 GtkWidget *retry_button;
635 GtkWidget *edit_button;
636 GtkWidget *close_button;
637 GtkWidget *action_area;
638 GtkWidget *action_table;
640 const gchar *icon_name;
641 const gchar *error_message;
642 gboolean user_requested;
645 empathy_account_get_error_message (account, &user_requested);
647 if (user_requested) {
651 str = g_markup_printf_escaped ("<b>%s</b>\n%s",
652 tp_account_get_display_name (account),
655 info_bar = g_hash_table_lookup (priv->errors, account);
657 label = g_object_get_data (G_OBJECT (info_bar), "label");
659 /* Just set the latest error and return */
660 gtk_label_set_markup (GTK_LABEL (label), str);
666 info_bar = gtk_info_bar_new ();
667 gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_ERROR);
669 gtk_widget_set_no_show_all (info_bar, TRUE);
670 gtk_box_pack_start (GTK_BOX (priv->errors_vbox), info_bar, FALSE, TRUE, 0);
671 gtk_widget_show (info_bar);
673 icon_name = tp_account_get_icon_name (account);
674 image = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_SMALL_TOOLBAR);
675 gtk_widget_show (image);
677 label = gtk_label_new (str);
678 gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
679 gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_END);
680 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
681 gtk_widget_show (label);
684 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
685 gtk_box_pack_start (GTK_BOX (content_area), image, FALSE, FALSE, 0);
686 gtk_box_pack_start (GTK_BOX (content_area), label, TRUE, TRUE, 0);
688 image = gtk_image_new_from_stock (GTK_STOCK_REFRESH, GTK_ICON_SIZE_BUTTON);
689 retry_button = gtk_button_new ();
690 gtk_button_set_image (GTK_BUTTON (retry_button), image);
691 gtk_widget_set_tooltip_text (retry_button, _("Reconnect"));
692 gtk_widget_show (retry_button);
694 image = gtk_image_new_from_stock (GTK_STOCK_EDIT, GTK_ICON_SIZE_BUTTON);
695 edit_button = gtk_button_new ();
696 gtk_button_set_image (GTK_BUTTON (edit_button), image);
697 gtk_widget_set_tooltip_text (edit_button, _("Edit Account"));
698 gtk_widget_show (edit_button);
700 image = gtk_image_new_from_stock (GTK_STOCK_CLOSE, GTK_ICON_SIZE_BUTTON);
701 close_button = gtk_button_new ();
702 gtk_button_set_image (GTK_BUTTON (close_button), image);
703 gtk_widget_set_tooltip_text (close_button, _("Close"));
704 gtk_widget_show (close_button);
706 action_table = gtk_table_new (1, 3, FALSE);
707 gtk_table_set_col_spacings (GTK_TABLE (action_table), 2);
708 gtk_widget_show (action_table);
710 action_area = gtk_info_bar_get_action_area (GTK_INFO_BAR (info_bar));
711 gtk_box_pack_start (GTK_BOX (action_area), action_table, FALSE, FALSE, 0);
713 gtk_table_attach (GTK_TABLE (action_table), retry_button, 0, 1, 0, 1,
714 (GtkAttachOptions) (GTK_SHRINK),
715 (GtkAttachOptions) (GTK_SHRINK), 0, 0);
716 gtk_table_attach (GTK_TABLE (action_table), edit_button, 1, 2, 0, 1,
717 (GtkAttachOptions) (GTK_SHRINK),
718 (GtkAttachOptions) (GTK_SHRINK), 0, 0);
719 gtk_table_attach (GTK_TABLE (action_table), close_button, 2, 3, 0, 1,
720 (GtkAttachOptions) (GTK_SHRINK),
721 (GtkAttachOptions) (GTK_SHRINK), 0, 0);
723 g_object_set_data (G_OBJECT (info_bar), "label", label);
724 g_object_set_data_full (G_OBJECT (info_bar),
725 "account", g_object_ref (account),
727 g_object_set_data_full (G_OBJECT (edit_button),
728 "account", g_object_ref (account),
730 g_object_set_data_full (G_OBJECT (close_button),
731 "account", g_object_ref (account),
733 g_object_set_data_full (G_OBJECT (retry_button),
734 "account", g_object_ref (account),
737 g_signal_connect (edit_button, "clicked",
738 G_CALLBACK (main_window_error_edit_clicked_cb),
740 g_signal_connect (close_button, "clicked",
741 G_CALLBACK (main_window_error_close_clicked_cb),
743 g_signal_connect (retry_button, "clicked",
744 G_CALLBACK (main_window_error_retry_clicked_cb),
747 gtk_widget_set_tooltip_text (priv->errors_vbox, error_message);
748 gtk_widget_show (priv->errors_vbox);
750 g_hash_table_insert (priv->errors, g_object_ref (account), info_bar);
754 main_window_update_status (EmpathyMainWindow *window)
756 EmpathyMainWindowPriv *priv = GET_PRIV (window);
757 gboolean connected, connecting;
760 connected = empathy_account_manager_get_accounts_connected (&connecting);
762 /* Update the spinner state */
764 gtk_spinner_start (GTK_SPINNER (priv->throbber));
765 gtk_widget_show (priv->throbber_tool_item);
767 gtk_spinner_stop (GTK_SPINNER (priv->throbber));
768 gtk_widget_hide (priv->throbber_tool_item);
771 /* Update widgets sensibility */
772 for (l = priv->actions_connected; l; l = l->next) {
773 gtk_action_set_sensitive (l->data, connected);
776 /* Update favourite rooms sensitivity */
777 children = gtk_container_get_children (GTK_CONTAINER (priv->room_menu));
778 for (l = children; l != NULL; l = l->next) {
779 if (g_object_get_data (G_OBJECT (l->data), "is_favorite") != NULL) {
780 gtk_widget_set_sensitive (GTK_WIDGET (l->data), connected);
783 g_list_free (children);
787 main_window_connection_changed_cb (TpAccount *account,
791 gchar *dbus_error_name,
793 EmpathyMainWindow *window)
795 EmpathyMainWindowPriv *priv = GET_PRIV (window);
797 main_window_update_status (window);
799 if (current == TP_CONNECTION_STATUS_DISCONNECTED &&
800 reason != TP_CONNECTION_STATUS_REASON_REQUESTED) {
801 main_window_error_display (window, account);
804 if (current == TP_CONNECTION_STATUS_DISCONNECTED) {
805 empathy_sound_manager_play (priv->sound_mgr, GTK_WIDGET (window),
806 EMPATHY_SOUND_ACCOUNT_DISCONNECTED);
809 if (current == TP_CONNECTION_STATUS_CONNECTED) {
810 empathy_sound_manager_play (priv->sound_mgr, GTK_WIDGET (window),
811 EMPATHY_SOUND_ACCOUNT_CONNECTED);
813 /* Account connected without error, remove error message if any */
814 main_window_remove_error (window, account);
819 main_window_accels_load (void)
823 filename = g_build_filename (g_get_user_config_dir (), PACKAGE_NAME, ACCELS_FILENAME, NULL);
824 if (g_file_test (filename, G_FILE_TEST_EXISTS)) {
825 DEBUG ("Loading from:'%s'", filename);
826 gtk_accel_map_load (filename);
833 main_window_accels_save (void)
836 gchar *file_with_path;
838 dir = g_build_filename (g_get_user_config_dir (), PACKAGE_NAME, NULL);
839 g_mkdir_with_parents (dir, S_IRUSR | S_IWUSR | S_IXUSR);
840 file_with_path = g_build_filename (dir, ACCELS_FILENAME, NULL);
843 DEBUG ("Saving to:'%s'", file_with_path);
844 gtk_accel_map_save (file_with_path);
846 g_free (file_with_path);
850 empathy_main_window_finalize (GObject *window)
852 EmpathyMainWindowPriv *priv = GET_PRIV (window);
856 /* Save user-defined accelerators. */
857 main_window_accels_save ();
859 g_list_free (priv->actions_connected);
861 g_object_unref (priv->account_manager);
862 g_object_unref (priv->individual_store);
863 g_object_unref (priv->contact_manager);
864 g_object_unref (priv->sound_mgr);
865 g_hash_table_destroy (priv->errors);
866 g_hash_table_destroy (priv->auths);
868 /* disconnect all handlers of status-changed signal */
869 g_hash_table_iter_init (&iter, priv->status_changed_handlers);
870 while (g_hash_table_iter_next (&iter, &key, &value))
871 g_signal_handler_disconnect (TP_ACCOUNT (key),
872 GPOINTER_TO_UINT (value));
874 g_hash_table_destroy (priv->status_changed_handlers);
876 g_signal_handlers_disconnect_by_func (priv->event_manager,
877 main_window_event_added_cb,
879 g_signal_handlers_disconnect_by_func (priv->event_manager,
880 main_window_event_removed_cb,
882 g_object_unref (priv->call_observer);
883 g_object_unref (priv->event_manager);
884 g_object_unref (priv->ui_manager);
885 g_object_unref (priv->chatroom_manager);
887 g_object_unref (priv->gsettings_ui);
888 g_object_unref (priv->gsettings_contacts);
890 G_OBJECT_CLASS (empathy_main_window_parent_class)->finalize (window);
894 main_window_key_press_event_cb (GtkWidget *window,
898 EmpathyChatManager *chat_manager;
900 if (event->keyval == GDK_KEY_T
901 && event->state & GDK_SHIFT_MASK
902 && event->state & GDK_CONTROL_MASK) {
903 chat_manager = empathy_chat_manager_dup_singleton ();
904 empathy_chat_manager_undo_closed_chat (chat_manager);
905 g_object_unref (chat_manager);
911 main_window_chat_quit_cb (GtkAction *action,
912 EmpathyMainWindow *window)
918 main_window_view_history_cb (GtkAction *action,
919 EmpathyMainWindow *window)
921 empathy_log_window_show (NULL, NULL, FALSE, GTK_WINDOW (window));
925 main_window_chat_new_message_cb (GtkAction *action,
926 EmpathyMainWindow *window)
928 empathy_new_message_dialog_show (GTK_WINDOW (window));
932 main_window_chat_new_call_cb (GtkAction *action,
933 EmpathyMainWindow *window)
935 empathy_new_call_dialog_show (GTK_WINDOW (window));
939 main_window_chat_add_contact_cb (GtkAction *action,
940 EmpathyMainWindow *window)
942 empathy_new_individual_dialog_show (GTK_WINDOW (window));
946 main_window_chat_search_contacts_cb (GtkAction *action,
947 EmpathyMainWindow *window)
949 GtkWidget *dialog = empathy_contact_search_dialog_new (
950 GTK_WINDOW (window));
951 gtk_widget_show (dialog);
955 main_window_view_show_ft_manager (GtkAction *action,
956 EmpathyMainWindow *window)
958 empathy_ft_manager_show ();
962 main_window_view_show_offline_cb (GtkToggleAction *action,
963 EmpathyMainWindow *window)
965 EmpathyMainWindowPriv *priv = GET_PRIV (window);
968 current = gtk_toggle_action_get_active (action);
969 g_settings_set_boolean (priv->gsettings_ui,
970 EMPATHY_PREFS_UI_SHOW_OFFLINE,
973 empathy_individual_view_set_show_offline (priv->individual_view,
978 main_window_notify_sort_contact_cb (GSettings *gsettings,
980 EmpathyMainWindow *window)
982 EmpathyMainWindowPriv *priv = GET_PRIV (window);
985 str = g_settings_get_string (gsettings, key);
989 GEnumClass *enum_class;
990 GEnumValue *enum_value;
992 type = empathy_individual_store_sort_get_type ();
993 enum_class = G_ENUM_CLASS (g_type_class_peek (type));
994 enum_value = g_enum_get_value_by_nick (enum_class, str);
996 /* By changing the value of the GtkRadioAction,
997 it emits a signal that calls main_window_view_sort_contacts_cb
998 which updates the contacts list */
999 gtk_radio_action_set_current_value (priv->sort_by_name,
1002 g_warning ("Wrong value for sort_criterium configuration : %s", str);
1009 main_window_view_sort_contacts_cb (GtkRadioAction *action,
1010 GtkRadioAction *current,
1011 EmpathyMainWindow *window)
1013 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1014 EmpathyContactListStoreSort value;
1017 GEnumClass *enum_class;
1018 GEnumValue *enum_value;
1020 value = gtk_radio_action_get_current_value (action);
1021 group = gtk_radio_action_get_group (action);
1023 /* Get string from index */
1024 type = empathy_individual_store_sort_get_type ();
1025 enum_class = G_ENUM_CLASS (g_type_class_peek (type));
1026 enum_value = g_enum_get_value (enum_class, g_slist_index (group, current));
1029 g_warning ("No GEnumValue for EmpathyContactListSort with GtkRadioAction index:%d",
1030 g_slist_index (group, action));
1032 g_settings_set_string (priv->gsettings_contacts,
1033 EMPATHY_PREFS_CONTACTS_SORT_CRITERIUM,
1034 enum_value->value_nick);
1036 empathy_individual_store_set_sort_criterium (priv->individual_store,
1041 main_window_view_show_protocols_cb (GtkToggleAction *action,
1042 EmpathyMainWindow *window)
1044 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1047 value = gtk_toggle_action_get_active (action);
1049 g_settings_set_boolean (priv->gsettings_ui,
1050 EMPATHY_PREFS_UI_SHOW_PROTOCOLS,
1052 empathy_individual_store_set_show_protocols (priv->individual_store,
1056 /* Matches GtkRadioAction values set in empathy-main-window.ui */
1057 #define CONTACT_LIST_NORMAL_SIZE_WITH_AVATARS 0
1058 #define CONTACT_LIST_NORMAL_SIZE 1
1059 #define CONTACT_LIST_COMPACT_SIZE 2
1062 main_window_view_contacts_list_size_cb (GtkRadioAction *action,
1063 GtkRadioAction *current,
1064 EmpathyMainWindow *window)
1066 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1067 GSettings *gsettings_ui;
1070 value = gtk_radio_action_get_current_value (action);
1071 /* create a new GSettings, so we can delay the setting until both
1073 gsettings_ui = g_settings_new (EMPATHY_PREFS_UI_SCHEMA);
1075 DEBUG ("radio button toggled, value = %i", value);
1077 g_settings_delay (gsettings_ui);
1078 g_settings_set_boolean (gsettings_ui,
1079 EMPATHY_PREFS_UI_SHOW_AVATARS,
1080 value == CONTACT_LIST_NORMAL_SIZE_WITH_AVATARS);
1082 g_settings_set_boolean (gsettings_ui,
1083 EMPATHY_PREFS_UI_COMPACT_CONTACT_LIST,
1084 value == CONTACT_LIST_COMPACT_SIZE);
1085 g_settings_apply (gsettings_ui);
1087 /* FIXME: these enums probably have the wrong namespace */
1088 empathy_individual_store_set_show_avatars (priv->individual_store,
1089 value == CONTACT_LIST_NORMAL_SIZE_WITH_AVATARS);
1090 empathy_individual_store_set_is_compact (priv->individual_store,
1091 value == CONTACT_LIST_COMPACT_SIZE);
1093 g_object_unref (gsettings_ui);
1096 static void main_window_notify_show_protocols_cb (GSettings *gsettings,
1098 EmpathyMainWindow *window)
1100 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1102 gtk_toggle_action_set_active (priv->show_protocols,
1103 g_settings_get_boolean (gsettings,
1104 EMPATHY_PREFS_UI_SHOW_PROTOCOLS));
1109 main_window_notify_contact_list_size_cb (GSettings *gsettings,
1111 EmpathyMainWindow *window)
1113 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1116 if (g_settings_get_boolean (gsettings,
1117 EMPATHY_PREFS_UI_COMPACT_CONTACT_LIST)) {
1118 value = CONTACT_LIST_COMPACT_SIZE;
1119 } else if (g_settings_get_boolean (gsettings,
1120 EMPATHY_PREFS_UI_SHOW_AVATARS)) {
1121 value = CONTACT_LIST_NORMAL_SIZE_WITH_AVATARS;
1123 value = CONTACT_LIST_NORMAL_SIZE;
1126 DEBUG ("setting changed, value = %i", value);
1128 /* By changing the value of the GtkRadioAction,
1129 it emits a signal that calls main_window_view_contacts_list_size_cb
1130 which updates the contacts list */
1131 gtk_radio_action_set_current_value (priv->normal_with_avatars, value);
1135 main_window_edit_search_contacts_cb (GtkCheckMenuItem *item,
1136 EmpathyMainWindow *window)
1138 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1140 empathy_individual_view_start_search (priv->individual_view);
1144 main_window_view_show_map_cb (GtkCheckMenuItem *item,
1145 EmpathyMainWindow *window)
1147 #ifdef HAVE_LIBCHAMPLAIN
1148 empathy_map_view_show ();
1153 join_chatroom (EmpathyChatroom *chatroom,
1159 account = empathy_chatroom_get_account (chatroom);
1160 room = empathy_chatroom_get_room (chatroom);
1162 DEBUG ("Requesting channel for '%s'", room);
1163 empathy_join_muc (account, room, timestamp);
1169 EmpathyChatroom *chatroom;
1173 } join_fav_account_sig_ctx;
1175 static join_fav_account_sig_ctx *
1176 join_fav_account_sig_ctx_new (TpAccount *account,
1177 EmpathyChatroom *chatroom,
1180 join_fav_account_sig_ctx *ctx = g_slice_new0 (
1181 join_fav_account_sig_ctx);
1183 ctx->account = g_object_ref (account);
1184 ctx->chatroom = g_object_ref (chatroom);
1185 ctx->timestamp = timestamp;
1190 join_fav_account_sig_ctx_free (join_fav_account_sig_ctx *ctx)
1192 g_object_unref (ctx->account);
1193 g_object_unref (ctx->chatroom);
1194 g_slice_free (join_fav_account_sig_ctx, ctx);
1198 account_status_changed_cb (TpAccount *account,
1199 TpConnectionStatus old_status,
1200 TpConnectionStatus new_status,
1202 gchar *dbus_error_name,
1203 GHashTable *details,
1206 join_fav_account_sig_ctx *ctx = user_data;
1208 switch (new_status) {
1209 case TP_CONNECTION_STATUS_DISCONNECTED:
1210 /* Don't wait any longer */
1214 case TP_CONNECTION_STATUS_CONNECTING:
1218 case TP_CONNECTION_STATUS_CONNECTED:
1219 /* We can join the room */
1223 g_assert_not_reached ();
1226 join_chatroom (ctx->chatroom, ctx->timestamp);
1229 g_source_remove (ctx->timeout);
1230 g_signal_handler_disconnect (account, ctx->sig_id);
1233 #define JOIN_FAVORITE_TIMEOUT 5
1236 join_favorite_timeout_cb (gpointer data)
1238 join_fav_account_sig_ctx *ctx = data;
1240 /* stop waiting for joining the favorite room */
1241 g_signal_handler_disconnect (ctx->account, ctx->sig_id);
1246 main_window_favorite_chatroom_join (EmpathyChatroom *chatroom)
1250 account = empathy_chatroom_get_account (chatroom);
1251 if (tp_account_get_connection_status (account, NULL) !=
1252 TP_CONNECTION_STATUS_CONNECTED) {
1253 join_fav_account_sig_ctx *ctx;
1255 ctx = join_fav_account_sig_ctx_new (account, chatroom,
1256 gtk_get_current_event_time ());
1258 ctx->sig_id = g_signal_connect_data (account, "status-changed",
1259 G_CALLBACK (account_status_changed_cb), ctx,
1260 (GClosureNotify) join_fav_account_sig_ctx_free, 0);
1262 ctx->timeout = g_timeout_add_seconds (JOIN_FAVORITE_TIMEOUT,
1263 join_favorite_timeout_cb, ctx);
1267 join_chatroom (chatroom, gtk_get_current_event_time ());
1271 main_window_favorite_chatroom_menu_activate_cb (GtkMenuItem *menu_item,
1272 EmpathyChatroom *chatroom)
1274 main_window_favorite_chatroom_join (chatroom);
1278 main_window_favorite_chatroom_menu_add (EmpathyMainWindow *window,
1279 EmpathyChatroom *chatroom)
1281 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1282 GtkWidget *menu_item;
1285 if (g_object_get_data (G_OBJECT (chatroom), "menu_item")) {
1289 name = empathy_chatroom_get_name (chatroom);
1290 menu_item = gtk_menu_item_new_with_label (name);
1291 g_object_set_data (G_OBJECT (menu_item), "is_favorite",
1292 GUINT_TO_POINTER (TRUE));
1294 g_object_set_data (G_OBJECT (chatroom), "menu_item", menu_item);
1295 g_signal_connect (menu_item, "activate",
1296 G_CALLBACK (main_window_favorite_chatroom_menu_activate_cb),
1299 gtk_menu_shell_insert (GTK_MENU_SHELL (priv->room_menu),
1302 gtk_widget_show (menu_item);
1306 main_window_favorite_chatroom_menu_added_cb (EmpathyChatroomManager *manager,
1307 EmpathyChatroom *chatroom,
1308 EmpathyMainWindow *window)
1310 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1312 main_window_favorite_chatroom_menu_add (window, chatroom);
1313 gtk_widget_show (priv->room_separator);
1314 gtk_action_set_sensitive (priv->room_join_favorites, TRUE);
1318 main_window_favorite_chatroom_menu_removed_cb (EmpathyChatroomManager *manager,
1319 EmpathyChatroom *chatroom,
1320 EmpathyMainWindow *window)
1322 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1323 GtkWidget *menu_item;
1326 menu_item = g_object_get_data (G_OBJECT (chatroom), "menu_item");
1327 g_object_set_data (G_OBJECT (chatroom), "menu_item", NULL);
1328 gtk_widget_destroy (menu_item);
1330 chatrooms = empathy_chatroom_manager_get_chatrooms (priv->chatroom_manager, NULL);
1332 gtk_widget_show (priv->room_separator);
1334 gtk_widget_hide (priv->room_separator);
1337 gtk_action_set_sensitive (priv->room_join_favorites, chatrooms != NULL);
1338 g_list_free (chatrooms);
1342 main_window_favorite_chatroom_menu_setup (EmpathyMainWindow *window)
1344 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1345 GList *chatrooms, *l;
1348 priv->chatroom_manager = empathy_chatroom_manager_dup_singleton (NULL);
1349 chatrooms = empathy_chatroom_manager_get_chatrooms (
1350 priv->chatroom_manager, NULL);
1351 room = gtk_ui_manager_get_widget (priv->ui_manager,
1353 priv->room_menu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (room));
1354 priv->room_separator = gtk_ui_manager_get_widget (priv->ui_manager,
1355 "/menubar/room/room_separator");
1357 for (l = chatrooms; l; l = l->next) {
1358 main_window_favorite_chatroom_menu_add (window, l->data);
1362 gtk_widget_hide (priv->room_separator);
1365 gtk_action_set_sensitive (priv->room_join_favorites, chatrooms != NULL);
1367 g_signal_connect (priv->chatroom_manager, "chatroom-added",
1368 G_CALLBACK (main_window_favorite_chatroom_menu_added_cb),
1370 g_signal_connect (priv->chatroom_manager, "chatroom-removed",
1371 G_CALLBACK (main_window_favorite_chatroom_menu_removed_cb),
1374 g_list_free (chatrooms);
1378 main_window_room_join_new_cb (GtkAction *action,
1379 EmpathyMainWindow *window)
1381 empathy_new_chatroom_dialog_show (GTK_WINDOW (window));
1385 main_window_room_join_favorites_cb (GtkAction *action,
1386 EmpathyMainWindow *window)
1388 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1389 GList *chatrooms, *l;
1391 chatrooms = empathy_chatroom_manager_get_chatrooms (priv->chatroom_manager, NULL);
1392 for (l = chatrooms; l; l = l->next) {
1393 main_window_favorite_chatroom_join (l->data);
1395 g_list_free (chatrooms);
1399 main_window_room_manage_favorites_cb (GtkAction *action,
1400 EmpathyMainWindow *window)
1402 empathy_chatrooms_window_show (GTK_WINDOW (window));
1406 main_window_edit_cb (GtkAction *action,
1407 EmpathyMainWindow *window)
1409 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1412 /* FIXME: It should use the UIManager to merge the contact/group submenu */
1413 submenu = empathy_individual_view_get_individual_menu (
1414 priv->individual_view);
1419 item = GTK_MENU_ITEM (priv->edit_context);
1420 label = gtk_bin_get_child (GTK_BIN (item));
1421 gtk_label_set_text (GTK_LABEL (label), _("Contact"));
1423 gtk_widget_show (priv->edit_context);
1424 gtk_widget_show (priv->edit_context_separator);
1426 gtk_menu_item_set_submenu (item, submenu);
1431 submenu = empathy_individual_view_get_group_menu (
1432 priv->individual_view);
1437 item = GTK_MENU_ITEM (priv->edit_context);
1438 label = gtk_bin_get_child (GTK_BIN (item));
1439 gtk_label_set_text (GTK_LABEL (label), _("Group"));
1441 gtk_widget_show (priv->edit_context);
1442 gtk_widget_show (priv->edit_context_separator);
1444 gtk_menu_item_set_submenu (item, submenu);
1449 gtk_widget_hide (priv->edit_context);
1450 gtk_widget_hide (priv->edit_context_separator);
1456 main_window_edit_accounts_cb (GtkAction *action,
1457 EmpathyMainWindow *window)
1459 empathy_accounts_dialog_show_application (gdk_screen_get_default (),
1460 NULL, FALSE, FALSE);
1464 main_window_edit_personal_information_cb (GtkAction *action,
1465 EmpathyMainWindow *window)
1467 empathy_contact_personal_dialog_show (GTK_WINDOW (window));
1471 main_window_edit_blocked_contacts_cb (GtkAction *action,
1472 EmpathyMainWindow *window)
1476 dialog = empathy_contact_blocking_dialog_new (GTK_WINDOW (window));
1477 gtk_widget_show (dialog);
1478 g_signal_connect (dialog, "response",
1479 G_CALLBACK (gtk_widget_destroy), NULL);
1483 main_window_edit_preferences_cb (GtkAction *action,
1484 EmpathyMainWindow *window)
1486 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1488 if (priv->preferences == NULL) {
1489 priv->preferences = empathy_preferences_new (GTK_WINDOW (window));
1490 g_object_add_weak_pointer (G_OBJECT (priv->preferences),
1491 (gpointer) &priv->preferences);
1493 gtk_widget_show (priv->preferences);
1495 gtk_window_present (GTK_WINDOW (priv->preferences));
1500 main_window_help_about_cb (GtkAction *action,
1501 EmpathyMainWindow *window)
1503 empathy_about_dialog_new (GTK_WINDOW (window));
1507 main_window_help_debug_cb (GtkAction *action,
1508 EmpathyMainWindow *window)
1510 GdkDisplay *display;
1511 GError *error = NULL;
1514 GdkAppLaunchContext *context = NULL;
1516 /* Try to run from source directory if possible */
1517 path = g_build_filename (g_getenv ("EMPATHY_SRCDIR"), "src",
1518 "empathy-debugger", NULL);
1520 if (!g_file_test (path, G_FILE_TEST_EXISTS)) {
1522 path = g_build_filename (BIN_DIR, "empathy-debugger", NULL);
1525 app_info = g_app_info_create_from_commandline (path, NULL, 0, &error);
1526 if (app_info == NULL) {
1527 DEBUG ("Failed to create app info: %s", error->message);
1528 g_error_free (error);
1532 display = gdk_display_get_default ();
1533 context = gdk_display_get_app_launch_context (display);
1535 if (!g_app_info_launch (app_info, NULL, (GAppLaunchContext *) context,
1537 g_warning ("Failed to open debug window: %s", error->message);
1538 g_error_free (error);
1543 tp_clear_object (&app_info);
1544 tp_clear_object (&context);
1549 main_window_help_contents_cb (GtkAction *action,
1550 EmpathyMainWindow *window)
1552 empathy_url_show (GTK_WIDGET (window), "ghelp:empathy");
1556 main_window_throbber_button_press_event_cb (GtkWidget *throbber,
1557 GdkEventButton *event,
1558 EmpathyMainWindow *window)
1560 if (event->type != GDK_BUTTON_PRESS ||
1561 event->button != 1) {
1565 empathy_accounts_dialog_show_application (
1566 gtk_widget_get_screen (GTK_WIDGET (throbber)),
1567 NULL, FALSE, FALSE);
1573 main_window_account_removed_cb (TpAccountManager *manager,
1575 EmpathyMainWindow *window)
1577 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1580 a = tp_account_manager_get_valid_accounts (manager);
1582 gtk_action_set_sensitive (priv->view_history,
1583 g_list_length (a) > 0);
1587 /* remove errors if any */
1588 main_window_remove_error (window, account);
1592 main_window_account_validity_changed_cb (TpAccountManager *manager,
1595 EmpathyMainWindow *window)
1597 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1601 handler_id = GPOINTER_TO_UINT (g_hash_table_lookup (
1602 priv->status_changed_handlers, account));
1604 /* connect signal only if it was not connected yet */
1605 if (handler_id == 0) {
1606 handler_id = g_signal_connect (account,
1608 G_CALLBACK (main_window_connection_changed_cb),
1610 g_hash_table_insert (priv->status_changed_handlers,
1611 account, GUINT_TO_POINTER (handler_id));
1615 main_window_account_removed_cb (manager, account, window);
1619 main_window_notify_show_offline_cb (GSettings *gsettings,
1621 gpointer toggle_action)
1623 gtk_toggle_action_set_active (toggle_action,
1624 g_settings_get_boolean (gsettings, key));
1628 main_window_connection_items_setup (EmpathyMainWindow *window,
1631 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1635 const gchar *actions_connected[] = {
1637 "room_join_favorites",
1641 "edit_personal_information",
1642 "edit_blocked_contacts"
1645 for (i = 0, list = NULL; i < G_N_ELEMENTS (actions_connected); i++) {
1646 action = gtk_builder_get_object (gui, actions_connected[i]);
1647 list = g_list_prepend (list, action);
1650 priv->actions_connected = list;
1654 account_manager_prepared_cb (GObject *source_object,
1655 GAsyncResult *result,
1658 GList *accounts, *j;
1659 TpAccountManager *manager = TP_ACCOUNT_MANAGER (source_object);
1660 EmpathyMainWindow *window = user_data;
1661 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1662 GError *error = NULL;
1664 if (!tp_account_manager_prepare_finish (manager, result, &error)) {
1665 DEBUG ("Failed to prepare account manager: %s", error->message);
1666 g_error_free (error);
1670 accounts = tp_account_manager_get_valid_accounts (priv->account_manager);
1671 for (j = accounts; j != NULL; j = j->next) {
1672 TpAccount *account = TP_ACCOUNT (j->data);
1675 handler_id = g_signal_connect (account, "status-changed",
1676 G_CALLBACK (main_window_connection_changed_cb),
1678 g_hash_table_insert (priv->status_changed_handlers,
1679 account, GUINT_TO_POINTER (handler_id));
1682 g_signal_connect (manager, "account-validity-changed",
1683 G_CALLBACK (main_window_account_validity_changed_cb),
1686 main_window_update_status (window);
1688 /* Disable the "Previous Conversations" menu entry if there is no account */
1689 gtk_action_set_sensitive (priv->view_history,
1690 g_list_length (accounts) > 0);
1692 g_list_free (accounts);
1696 main_window_members_changed_cb (EmpathyContactList *list,
1697 EmpathyContact *contact,
1698 EmpathyContact *actor,
1702 EmpathyMainWindow *window)
1704 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1709 if (!empathy_migrate_butterfly_logs (contact)) {
1710 g_signal_handler_disconnect (list,
1711 priv->butterfly_log_migration_members_changed_id);
1712 priv->butterfly_log_migration_members_changed_id = 0;
1717 empathy_main_window_constructor (GType type,
1718 guint n_construct_params,
1719 GObjectConstructParam *construct_params)
1721 static GObject *window = NULL;
1724 return g_object_ref (window);
1726 window = G_OBJECT_CLASS (empathy_main_window_parent_class)->constructor (
1727 type, n_construct_params, construct_params);
1729 g_object_add_weak_pointer (window, (gpointer) &window);
1735 empathy_main_window_class_init (EmpathyMainWindowClass *klass)
1737 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1739 object_class->finalize = empathy_main_window_finalize;
1740 object_class->constructor = empathy_main_window_constructor;
1742 g_type_class_add_private (object_class, sizeof (EmpathyMainWindowPriv));
1746 empathy_main_window_init (EmpathyMainWindow *window)
1748 EmpathyMainWindowPriv *priv;
1749 EmpathyIndividualManager *individual_manager;
1752 GtkToggleAction *show_offline_widget;
1753 GtkAction *show_map_widget;
1755 gboolean show_offline;
1758 GtkTreeModel *model;
1760 priv = window->priv = G_TYPE_INSTANCE_GET_PRIVATE (window,
1761 EMPATHY_TYPE_MAIN_WINDOW, EmpathyMainWindowPriv);
1763 priv->gsettings_ui = g_settings_new (EMPATHY_PREFS_UI_SCHEMA);
1764 priv->gsettings_contacts = g_settings_new (EMPATHY_PREFS_CONTACTS_SCHEMA);
1766 priv->sound_mgr = empathy_sound_manager_dup_singleton ();
1768 gtk_window_set_title (GTK_WINDOW (window), _("Contact List"));
1769 gtk_window_set_role (GTK_WINDOW (window), "contact_list");
1770 gtk_window_set_default_size (GTK_WINDOW (window), 225, 325);
1772 /* Set up interface */
1773 filename = empathy_file_lookup ("empathy-main-window.ui", "src");
1774 gui = empathy_builder_get_file (filename,
1775 "main_vbox", &priv->main_vbox,
1776 "errors_vbox", &priv->errors_vbox,
1777 "auth_vbox", &priv->auth_vbox,
1778 "ui_manager", &priv->ui_manager,
1779 "view_show_offline", &show_offline_widget,
1780 "view_show_protocols", &priv->show_protocols,
1781 "view_sort_by_name", &priv->sort_by_name,
1782 "view_sort_by_status", &priv->sort_by_status,
1783 "view_normal_size_with_avatars", &priv->normal_with_avatars,
1784 "view_normal_size", &priv->normal_size,
1785 "view_compact_size", &priv->compact_size,
1786 "view_history", &priv->view_history,
1787 "view_show_map", &show_map_widget,
1788 "room_join_favorites", &priv->room_join_favorites,
1789 "presence_toolbar", &priv->presence_toolbar,
1790 "notebook", &priv->notebook,
1791 "no_entry_label", &priv->no_entry_label,
1792 "roster_scrolledwindow", &sw,
1796 gtk_container_add (GTK_CONTAINER (window), priv->main_vbox);
1797 gtk_widget_show (priv->main_vbox);
1799 g_signal_connect (window, "key-press-event",
1800 G_CALLBACK (main_window_key_press_event_cb), NULL);
1802 empathy_builder_connect (gui, window,
1803 "chat_quit", "activate", main_window_chat_quit_cb,
1804 "chat_new_message", "activate", main_window_chat_new_message_cb,
1805 "chat_new_call", "activate", main_window_chat_new_call_cb,
1806 "view_history", "activate", main_window_view_history_cb,
1807 "room_join_new", "activate", main_window_room_join_new_cb,
1808 "room_join_favorites", "activate", main_window_room_join_favorites_cb,
1809 "room_manage_favorites", "activate", main_window_room_manage_favorites_cb,
1810 "chat_add_contact", "activate", main_window_chat_add_contact_cb,
1811 "chat_search_contacts", "activate", main_window_chat_search_contacts_cb,
1812 "view_show_ft_manager", "activate", main_window_view_show_ft_manager,
1813 "view_show_offline", "toggled", main_window_view_show_offline_cb,
1814 "view_show_protocols", "toggled", main_window_view_show_protocols_cb,
1815 "view_sort_by_name", "changed", main_window_view_sort_contacts_cb,
1816 "view_normal_size_with_avatars", "changed", main_window_view_contacts_list_size_cb,
1817 "view_show_map", "activate", main_window_view_show_map_cb,
1818 "edit", "activate", main_window_edit_cb,
1819 "edit_accounts", "activate", main_window_edit_accounts_cb,
1820 "edit_personal_information", "activate", main_window_edit_personal_information_cb,
1821 "edit_blocked_contacts", "activate", main_window_edit_blocked_contacts_cb,
1822 "edit_preferences", "activate", main_window_edit_preferences_cb,
1823 "edit_search_contacts", "activate", main_window_edit_search_contacts_cb,
1824 "help_about", "activate", main_window_help_about_cb,
1825 "help_debug", "activate", main_window_help_debug_cb,
1826 "help_contents", "activate", main_window_help_contents_cb,
1829 /* Set up connection related widgets. */
1830 main_window_connection_items_setup (window, gui);
1832 g_object_ref (priv->ui_manager);
1833 g_object_unref (gui);
1835 #ifndef HAVE_LIBCHAMPLAIN
1836 gtk_action_set_visible (show_map_widget, FALSE);
1839 priv->account_manager = tp_account_manager_dup ();
1841 tp_account_manager_prepare_async (priv->account_manager, NULL,
1842 account_manager_prepared_cb, window);
1844 priv->errors = g_hash_table_new_full (g_direct_hash,
1849 priv->auths = g_hash_table_new (NULL, NULL);
1851 priv->status_changed_handlers = g_hash_table_new_full (g_direct_hash,
1857 main_window_favorite_chatroom_menu_setup (window);
1859 priv->edit_context = gtk_ui_manager_get_widget (priv->ui_manager,
1860 "/menubar/edit/edit_context");
1861 priv->edit_context_separator = gtk_ui_manager_get_widget (
1863 "/menubar/edit/edit_context_separator");
1864 gtk_widget_hide (priv->edit_context);
1865 gtk_widget_hide (priv->edit_context_separator);
1867 /* Set up contact list. */
1868 empathy_status_presets_get_all ();
1870 /* Set up presence chooser */
1871 priv->presence_chooser = empathy_presence_chooser_new ();
1872 gtk_widget_show (priv->presence_chooser);
1873 item = gtk_tool_item_new ();
1874 gtk_widget_show (GTK_WIDGET (item));
1875 gtk_widget_set_size_request (priv->presence_chooser, 10, -1);
1876 gtk_container_add (GTK_CONTAINER (item), priv->presence_chooser);
1877 gtk_tool_item_set_is_important (item, TRUE);
1878 gtk_tool_item_set_expand (item, TRUE);
1879 gtk_toolbar_insert (GTK_TOOLBAR (priv->presence_toolbar), item, -1);
1881 /* Set up the throbber */
1882 priv->throbber = gtk_spinner_new ();
1883 gtk_widget_set_size_request (priv->throbber, 16, -1);
1884 gtk_widget_set_tooltip_text (priv->throbber, _("Show and edit accounts"));
1885 gtk_widget_set_events (priv->throbber, GDK_BUTTON_PRESS_MASK);
1886 g_signal_connect (priv->throbber, "button-press-event",
1887 G_CALLBACK (main_window_throbber_button_press_event_cb),
1889 gtk_widget_show (priv->throbber);
1891 item = gtk_tool_item_new ();
1892 gtk_container_set_border_width (GTK_CONTAINER (item), 6);
1893 gtk_toolbar_insert (GTK_TOOLBAR (priv->presence_toolbar), item, -1);
1894 gtk_container_add (GTK_CONTAINER (item), priv->throbber);
1895 priv->throbber_tool_item = GTK_WIDGET (item);
1897 /* XXX: this class is designed to live for the duration of the program,
1898 * so it's got a race condition between its signal handlers and its
1899 * finalization. The class is planned to be removed, so we won't fix
1900 * this before then. */
1901 priv->contact_manager = EMPATHY_CONTACT_LIST (
1902 empathy_contact_manager_dup_singleton ());
1903 individual_manager = empathy_individual_manager_dup_singleton ();
1904 priv->individual_store = empathy_individual_store_new (
1905 individual_manager);
1906 g_object_unref (individual_manager);
1908 /* For the moment, we disallow Persona drops onto the main contact list (e.g. from things such as
1909 * the EmpathyPersonaView in the linking dialogue). No code is hooked up to do anything on a Persona
1910 * drop, so allowing them would achieve nothing except confusion. */
1911 priv->individual_view = empathy_individual_view_new (
1912 priv->individual_store,
1913 EMPATHY_INDIVIDUAL_VIEW_FEATURE_ALL ^ EMPATHY_INDIVIDUAL_VIEW_FEATURE_PERSONA_DROP,
1914 EMPATHY_INDIVIDUAL_FEATURE_ALL);
1916 priv->butterfly_log_migration_members_changed_id = g_signal_connect (
1917 priv->contact_manager, "members-changed",
1918 G_CALLBACK (main_window_members_changed_cb), window);
1920 gtk_widget_show (GTK_WIDGET (priv->individual_view));
1921 gtk_container_add (GTK_CONTAINER (sw),
1922 GTK_WIDGET (priv->individual_view));
1923 g_signal_connect (priv->individual_view, "row-activated",
1924 G_CALLBACK (main_window_row_activated_cb),
1927 /* Set up search bar */
1928 priv->search_bar = empathy_live_search_new (
1929 GTK_WIDGET (priv->individual_view));
1930 empathy_individual_view_set_live_search (priv->individual_view,
1931 EMPATHY_LIVE_SEARCH (priv->search_bar));
1932 gtk_box_pack_start (GTK_BOX (priv->main_vbox), priv->search_bar,
1934 g_signal_connect_swapped (window, "map",
1935 G_CALLBACK (gtk_widget_grab_focus), priv->individual_view);
1937 /* Connect to proper signals to check if contact list is empty or not */
1938 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->individual_view));
1940 g_signal_connect (model, "row-inserted",
1941 G_CALLBACK (main_window_row_inserted_cb),
1943 g_signal_connect (model, "row-deleted",
1944 G_CALLBACK (main_window_row_deleted_cb),
1947 /* Load user-defined accelerators. */
1948 main_window_accels_load ();
1950 /* Set window size. */
1951 empathy_geometry_bind (GTK_WINDOW (window), GEOMETRY_NAME);
1953 /* Enable event handling */
1954 priv->call_observer = empathy_call_observer_dup_singleton ();
1955 priv->event_manager = empathy_event_manager_dup_singleton ();
1957 g_signal_connect (priv->event_manager, "event-added",
1958 G_CALLBACK (main_window_event_added_cb), window);
1959 g_signal_connect (priv->event_manager, "event-removed",
1960 G_CALLBACK (main_window_event_removed_cb), window);
1961 g_signal_connect (priv->account_manager, "account-validity-changed",
1962 G_CALLBACK (main_window_account_validity_changed_cb),
1964 g_signal_connect (priv->account_manager, "account-removed",
1965 G_CALLBACK (main_window_account_removed_cb),
1967 g_signal_connect (priv->account_manager, "account-disabled",
1968 G_CALLBACK (main_window_account_disabled_cb),
1971 l = empathy_event_manager_get_events (priv->event_manager);
1973 main_window_event_added_cb (priv->event_manager, l->data,
1978 /* Show offline ? */
1979 show_offline = g_settings_get_boolean (priv->gsettings_ui,
1980 EMPATHY_PREFS_UI_SHOW_OFFLINE);
1981 g_signal_connect (priv->gsettings_ui,
1982 "changed::" EMPATHY_PREFS_UI_SHOW_OFFLINE,
1983 G_CALLBACK (main_window_notify_show_offline_cb),
1984 show_offline_widget);
1986 gtk_toggle_action_set_active (show_offline_widget, show_offline);
1988 /* Show protocol ? */
1989 g_signal_connect (priv->gsettings_ui,
1990 "changed::" EMPATHY_PREFS_UI_SHOW_PROTOCOLS,
1991 G_CALLBACK (main_window_notify_show_protocols_cb),
1994 main_window_notify_show_protocols_cb (priv->gsettings_ui,
1995 EMPATHY_PREFS_UI_SHOW_PROTOCOLS,
1998 /* Sort by name / by status ? */
1999 g_signal_connect (priv->gsettings_contacts,
2000 "changed::" EMPATHY_PREFS_CONTACTS_SORT_CRITERIUM,
2001 G_CALLBACK (main_window_notify_sort_contact_cb),
2004 main_window_notify_sort_contact_cb (priv->gsettings_contacts,
2005 EMPATHY_PREFS_CONTACTS_SORT_CRITERIUM,
2008 /* Contacts list size */
2009 g_signal_connect (priv->gsettings_ui,
2010 "changed::" EMPATHY_PREFS_UI_COMPACT_CONTACT_LIST,
2011 G_CALLBACK (main_window_notify_contact_list_size_cb),
2013 g_signal_connect (priv->gsettings_ui,
2014 "changed::" EMPATHY_PREFS_UI_SHOW_AVATARS,
2015 G_CALLBACK (main_window_notify_contact_list_size_cb),
2018 main_window_notify_contact_list_size_cb (priv->gsettings_ui,
2019 EMPATHY_PREFS_UI_SHOW_AVATARS,
2024 empathy_main_window_dup (void)
2026 return g_object_new (EMPATHY_TYPE_MAIN_WINDOW, NULL);