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,
225 gtk_tree_store_set (GTK_TREE_STORE (model), iter,
226 EMPATHY_INDIVIDUAL_STORE_COL_ICON_STATUS, pixbuf,
229 /* To make sure the parent is shown correctly, we emit
230 * the row-changed signal on the parent so it prompts
231 * it to be refreshed by the filter func.
233 if (gtk_tree_model_iter_parent (model, &parent_iter, iter)) {
234 parent_path = gtk_tree_model_get_path (model, &parent_iter);
237 gtk_tree_model_row_changed (model, parent_path, &parent_iter);
238 gtk_tree_path_free (parent_path);
241 g_object_unref (individual);
242 tp_clear_object (&contact);
248 main_window_flash_cb (EmpathyMainWindow *window)
250 EmpathyMainWindowPriv *priv = GET_PRIV (window);
253 gboolean found_event = FALSE;
254 FlashForeachData data;
256 priv->flash_on = !priv->flash_on;
257 data.on = priv->flash_on;
258 model = GTK_TREE_MODEL (priv->individual_store);
260 events = empathy_event_manager_get_events (priv->event_manager);
261 for (l = events; l; l = l->next) {
262 data.event = l->data;
263 data.window = window;
264 if (!data.event->contact || !data.event->must_ack) {
269 gtk_tree_model_foreach (model,
270 main_window_flash_foreach,
275 main_window_flash_stop (window);
282 main_window_flash_start (EmpathyMainWindow *window)
284 EmpathyMainWindowPriv *priv = GET_PRIV (window);
286 if (priv->flash_timeout_id != 0) {
290 DEBUG ("Start flashing");
291 priv->flash_timeout_id = g_timeout_add (FLASH_TIMEOUT,
292 (GSourceFunc) main_window_flash_cb,
294 main_window_flash_cb (window);
298 main_window_remove_auth (EmpathyMainWindow *window,
301 EmpathyMainWindowPriv *priv = GET_PRIV (window);
302 GtkWidget *error_widget;
304 error_widget = g_hash_table_lookup (priv->auths, event);
305 if (error_widget != NULL) {
306 gtk_widget_destroy (error_widget);
307 g_hash_table_remove (priv->auths, event);
312 main_window_auth_add_clicked_cb (GtkButton *button,
313 EmpathyMainWindow *window)
317 event = g_object_get_data (G_OBJECT (button), "event");
319 empathy_event_approve (event);
321 main_window_remove_auth (window, event);
325 main_window_auth_close_clicked_cb (GtkButton *button,
326 EmpathyMainWindow *window)
330 event = g_object_get_data (G_OBJECT (button), "event");
332 empathy_event_decline (event);
333 main_window_remove_auth (window, event);
337 main_window_auth_display (EmpathyMainWindow *window,
340 EmpathyMainWindowPriv *priv = GET_PRIV (window);
341 TpAccount *account = event->account;
343 GtkWidget *content_area;
346 GtkWidget *add_button;
347 GtkWidget *close_button;
348 GtkWidget *action_area;
349 GtkWidget *action_table;
350 const gchar *icon_name;
353 if (g_hash_table_lookup (priv->auths, event) != NULL) {
357 info_bar = gtk_info_bar_new ();
358 gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_QUESTION);
360 gtk_widget_set_no_show_all (info_bar, TRUE);
361 gtk_box_pack_start (GTK_BOX (priv->auth_vbox), info_bar, FALSE, TRUE, 0);
362 gtk_widget_show (info_bar);
364 icon_name = tp_account_get_icon_name (account);
365 image = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_SMALL_TOOLBAR);
366 gtk_widget_show (image);
368 str = g_markup_printf_escaped ("<b>%s</b>\n%s",
369 tp_account_get_display_name (account),
370 _("Password required"));
372 label = gtk_label_new (str);
373 gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
374 gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_END);
375 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
376 gtk_widget_show (label);
380 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
381 gtk_box_pack_start (GTK_BOX (content_area), image, FALSE, FALSE, 0);
382 gtk_box_pack_start (GTK_BOX (content_area), label, TRUE, TRUE, 0);
384 image = gtk_image_new_from_stock (GTK_STOCK_ADD, GTK_ICON_SIZE_BUTTON);
385 add_button = gtk_button_new ();
386 gtk_button_set_image (GTK_BUTTON (add_button), image);
387 gtk_widget_set_tooltip_text (add_button, _("Provide Password"));
388 gtk_widget_show (add_button);
390 image = gtk_image_new_from_stock (GTK_STOCK_CLOSE, GTK_ICON_SIZE_BUTTON);
391 close_button = gtk_button_new ();
392 gtk_button_set_image (GTK_BUTTON (close_button), image);
393 gtk_widget_set_tooltip_text (close_button, _("Disconnect"));
394 gtk_widget_show (close_button);
396 action_table = gtk_table_new (1, 2, FALSE);
397 gtk_table_set_col_spacings (GTK_TABLE (action_table), 6);
398 gtk_widget_show (action_table);
400 action_area = gtk_info_bar_get_action_area (GTK_INFO_BAR (info_bar));
401 gtk_box_pack_start (GTK_BOX (action_area), action_table, FALSE, FALSE, 0);
403 gtk_table_attach (GTK_TABLE (action_table), add_button, 0, 1, 0, 1,
404 (GtkAttachOptions) (GTK_SHRINK),
405 (GtkAttachOptions) (GTK_SHRINK), 0, 0);
406 gtk_table_attach (GTK_TABLE (action_table), close_button, 1, 2, 0, 1,
407 (GtkAttachOptions) (GTK_SHRINK),
408 (GtkAttachOptions) (GTK_SHRINK), 0, 0);
410 g_object_set_data_full (G_OBJECT (info_bar),
411 "event", event, NULL);
412 g_object_set_data_full (G_OBJECT (add_button),
413 "event", event, NULL);
414 g_object_set_data_full (G_OBJECT (close_button),
415 "event", event, NULL);
417 g_signal_connect (add_button, "clicked",
418 G_CALLBACK (main_window_auth_add_clicked_cb),
420 g_signal_connect (close_button, "clicked",
421 G_CALLBACK (main_window_auth_close_clicked_cb),
424 gtk_widget_show (priv->auth_vbox);
426 g_hash_table_insert (priv->auths, event, info_bar);
430 main_window_event_added_cb (EmpathyEventManager *manager,
432 EmpathyMainWindow *window)
434 if (event->contact) {
435 main_window_flash_start (window);
436 } else if (event->type == EMPATHY_EVENT_TYPE_AUTH) {
437 main_window_auth_display (window, event);
442 main_window_event_removed_cb (EmpathyEventManager *manager,
444 EmpathyMainWindow *window)
446 EmpathyMainWindowPriv *priv = GET_PRIV (window);
447 FlashForeachData data;
449 if (event->type == EMPATHY_EVENT_TYPE_AUTH) {
450 main_window_remove_auth (window, event);
454 if (!event->contact) {
460 data.window = window;
461 gtk_tree_model_foreach (GTK_TREE_MODEL (priv->individual_store),
462 main_window_flash_foreach,
467 main_window_row_activated_cb (EmpathyContactListView *view,
469 GtkTreeViewColumn *col,
470 EmpathyMainWindow *window)
472 EmpathyMainWindowPriv *priv = GET_PRIV (window);
473 EmpathyContact *contact = NULL;
474 FolksIndividual *individual;
479 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->individual_view));
480 gtk_tree_model_get_iter (model, &iter, path);
482 gtk_tree_model_get (model, &iter,
483 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL,
487 if (individual != NULL) {
488 contact = empathy_contact_dup_from_folks_individual (individual);
495 /* If the contact has an event activate it, otherwise the
496 * default handler of row-activated will be called. */
497 events = empathy_event_manager_get_events (priv->event_manager);
498 for (l = events; l; l = l->next) {
499 EmpathyEvent *event = l->data;
501 if (event->contact == contact) {
502 DEBUG ("Activate event");
503 empathy_event_activate (event);
505 /* We don't want the default handler of this signal
506 * (e.g. open a chat) */
507 g_signal_stop_emission_by_name (view, "row-activated");
512 g_object_unref (contact);
514 tp_clear_object (&individual);
518 main_window_row_deleted_cb (GtkTreeModel *model,
520 EmpathyMainWindow *window)
522 EmpathyMainWindowPriv *priv = GET_PRIV (window);
523 GtkTreeIter help_iter;
525 if (!gtk_tree_model_get_iter_first (model, &help_iter)) {
528 if (empathy_individual_view_is_searching (
529 priv->individual_view)) {
532 tmp = g_strdup_printf ("<b><span size='xx-large'>%s</span></b>",
533 _("No match found"));
535 gtk_label_set_markup (GTK_LABEL (priv->no_entry_label), tmp);
538 gtk_label_set_line_wrap (GTK_LABEL (priv->no_entry_label),
541 gtk_notebook_set_current_page (
542 GTK_NOTEBOOK (priv->notebook), PAGE_NO_MATCH);
548 main_window_row_inserted_cb (GtkTreeModel *model,
551 EmpathyMainWindow *window)
553 EmpathyMainWindowPriv *priv = GET_PRIV (window);
557 gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook),
559 gtk_widget_grab_focus (GTK_WIDGET (priv->individual_view));
564 main_window_remove_error (EmpathyMainWindow *window,
567 EmpathyMainWindowPriv *priv = GET_PRIV (window);
568 GtkWidget *error_widget;
570 error_widget = g_hash_table_lookup (priv->errors, account);
571 if (error_widget != NULL) {
572 gtk_widget_destroy (error_widget);
573 g_hash_table_remove (priv->errors, account);
578 main_window_account_disabled_cb (TpAccountManager *manager,
580 EmpathyMainWindow *window)
582 main_window_remove_error (window, account);
586 main_window_error_retry_clicked_cb (GtkButton *button,
587 EmpathyMainWindow *window)
591 account = g_object_get_data (G_OBJECT (button), "account");
592 tp_account_reconnect_async (account, NULL, NULL);
594 main_window_remove_error (window, account);
598 main_window_error_edit_clicked_cb (GtkButton *button,
599 EmpathyMainWindow *window)
603 account = g_object_get_data (G_OBJECT (button), "account");
605 empathy_accounts_dialog_show_application (
606 gtk_widget_get_screen (GTK_WIDGET (button)),
607 account, FALSE, FALSE);
609 main_window_remove_error (window, account);
613 main_window_error_close_clicked_cb (GtkButton *button,
614 EmpathyMainWindow *window)
618 account = g_object_get_data (G_OBJECT (button), "account");
619 main_window_remove_error (window, account);
623 main_window_error_display (EmpathyMainWindow *window,
626 EmpathyMainWindowPriv *priv = GET_PRIV (window);
628 GtkWidget *content_area;
631 GtkWidget *retry_button;
632 GtkWidget *edit_button;
633 GtkWidget *close_button;
634 GtkWidget *action_area;
635 GtkWidget *action_table;
637 const gchar *icon_name;
638 const gchar *error_message;
639 gboolean user_requested;
642 empathy_account_get_error_message (account, &user_requested);
644 if (user_requested) {
648 str = g_markup_printf_escaped ("<b>%s</b>\n%s",
649 tp_account_get_display_name (account),
652 info_bar = g_hash_table_lookup (priv->errors, account);
654 label = g_object_get_data (G_OBJECT (info_bar), "label");
656 /* Just set the latest error and return */
657 gtk_label_set_markup (GTK_LABEL (label), str);
663 info_bar = gtk_info_bar_new ();
664 gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_ERROR);
666 gtk_widget_set_no_show_all (info_bar, TRUE);
667 gtk_box_pack_start (GTK_BOX (priv->errors_vbox), info_bar, FALSE, TRUE, 0);
668 gtk_widget_show (info_bar);
670 icon_name = tp_account_get_icon_name (account);
671 image = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_SMALL_TOOLBAR);
672 gtk_widget_show (image);
674 label = gtk_label_new (str);
675 gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
676 gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_END);
677 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
678 gtk_widget_show (label);
681 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
682 gtk_box_pack_start (GTK_BOX (content_area), image, FALSE, FALSE, 0);
683 gtk_box_pack_start (GTK_BOX (content_area), label, TRUE, TRUE, 0);
685 image = gtk_image_new_from_stock (GTK_STOCK_REFRESH, GTK_ICON_SIZE_BUTTON);
686 retry_button = gtk_button_new ();
687 gtk_button_set_image (GTK_BUTTON (retry_button), image);
688 gtk_widget_set_tooltip_text (retry_button, _("Reconnect"));
689 gtk_widget_show (retry_button);
691 image = gtk_image_new_from_stock (GTK_STOCK_EDIT, GTK_ICON_SIZE_BUTTON);
692 edit_button = gtk_button_new ();
693 gtk_button_set_image (GTK_BUTTON (edit_button), image);
694 gtk_widget_set_tooltip_text (edit_button, _("Edit Account"));
695 gtk_widget_show (edit_button);
697 image = gtk_image_new_from_stock (GTK_STOCK_CLOSE, GTK_ICON_SIZE_BUTTON);
698 close_button = gtk_button_new ();
699 gtk_button_set_image (GTK_BUTTON (close_button), image);
700 gtk_widget_set_tooltip_text (close_button, _("Close"));
701 gtk_widget_show (close_button);
703 action_table = gtk_table_new (1, 3, FALSE);
704 gtk_table_set_col_spacings (GTK_TABLE (action_table), 2);
705 gtk_widget_show (action_table);
707 action_area = gtk_info_bar_get_action_area (GTK_INFO_BAR (info_bar));
708 gtk_box_pack_start (GTK_BOX (action_area), action_table, FALSE, FALSE, 0);
710 gtk_table_attach (GTK_TABLE (action_table), retry_button, 0, 1, 0, 1,
711 (GtkAttachOptions) (GTK_SHRINK),
712 (GtkAttachOptions) (GTK_SHRINK), 0, 0);
713 gtk_table_attach (GTK_TABLE (action_table), edit_button, 1, 2, 0, 1,
714 (GtkAttachOptions) (GTK_SHRINK),
715 (GtkAttachOptions) (GTK_SHRINK), 0, 0);
716 gtk_table_attach (GTK_TABLE (action_table), close_button, 2, 3, 0, 1,
717 (GtkAttachOptions) (GTK_SHRINK),
718 (GtkAttachOptions) (GTK_SHRINK), 0, 0);
720 g_object_set_data (G_OBJECT (info_bar), "label", label);
721 g_object_set_data_full (G_OBJECT (info_bar),
722 "account", g_object_ref (account),
724 g_object_set_data_full (G_OBJECT (edit_button),
725 "account", g_object_ref (account),
727 g_object_set_data_full (G_OBJECT (close_button),
728 "account", g_object_ref (account),
730 g_object_set_data_full (G_OBJECT (retry_button),
731 "account", g_object_ref (account),
734 g_signal_connect (edit_button, "clicked",
735 G_CALLBACK (main_window_error_edit_clicked_cb),
737 g_signal_connect (close_button, "clicked",
738 G_CALLBACK (main_window_error_close_clicked_cb),
740 g_signal_connect (retry_button, "clicked",
741 G_CALLBACK (main_window_error_retry_clicked_cb),
744 gtk_widget_set_tooltip_text (priv->errors_vbox, error_message);
745 gtk_widget_show (priv->errors_vbox);
747 g_hash_table_insert (priv->errors, g_object_ref (account), info_bar);
751 main_window_update_status (EmpathyMainWindow *window)
753 EmpathyMainWindowPriv *priv = GET_PRIV (window);
754 gboolean connected, connecting;
757 connected = empathy_account_manager_get_accounts_connected (&connecting);
759 /* Update the spinner state */
761 gtk_spinner_start (GTK_SPINNER (priv->throbber));
762 gtk_widget_show (priv->throbber_tool_item);
764 gtk_spinner_stop (GTK_SPINNER (priv->throbber));
765 gtk_widget_hide (priv->throbber_tool_item);
768 /* Update widgets sensibility */
769 for (l = priv->actions_connected; l; l = l->next) {
770 gtk_action_set_sensitive (l->data, connected);
773 /* Update favourite rooms sensitivity */
774 children = gtk_container_get_children (GTK_CONTAINER (priv->room_menu));
775 for (l = children; l != NULL; l = l->next) {
776 if (g_object_get_data (G_OBJECT (l->data), "is_favorite") != NULL) {
777 gtk_widget_set_sensitive (GTK_WIDGET (l->data), connected);
780 g_list_free (children);
784 main_window_connection_changed_cb (TpAccount *account,
788 gchar *dbus_error_name,
790 EmpathyMainWindow *window)
792 EmpathyMainWindowPriv *priv = GET_PRIV (window);
794 main_window_update_status (window);
796 if (current == TP_CONNECTION_STATUS_DISCONNECTED &&
797 reason != TP_CONNECTION_STATUS_REASON_REQUESTED) {
798 main_window_error_display (window, account);
801 if (current == TP_CONNECTION_STATUS_DISCONNECTED) {
802 empathy_sound_manager_play (priv->sound_mgr, GTK_WIDGET (window),
803 EMPATHY_SOUND_ACCOUNT_DISCONNECTED);
806 if (current == TP_CONNECTION_STATUS_CONNECTED) {
807 empathy_sound_manager_play (priv->sound_mgr, GTK_WIDGET (window),
808 EMPATHY_SOUND_ACCOUNT_CONNECTED);
810 /* Account connected without error, remove error message if any */
811 main_window_remove_error (window, account);
816 main_window_accels_load (void)
820 filename = g_build_filename (g_get_user_config_dir (), PACKAGE_NAME, ACCELS_FILENAME, NULL);
821 if (g_file_test (filename, G_FILE_TEST_EXISTS)) {
822 DEBUG ("Loading from:'%s'", filename);
823 gtk_accel_map_load (filename);
830 main_window_accels_save (void)
833 gchar *file_with_path;
835 dir = g_build_filename (g_get_user_config_dir (), PACKAGE_NAME, NULL);
836 g_mkdir_with_parents (dir, S_IRUSR | S_IWUSR | S_IXUSR);
837 file_with_path = g_build_filename (dir, ACCELS_FILENAME, NULL);
840 DEBUG ("Saving to:'%s'", file_with_path);
841 gtk_accel_map_save (file_with_path);
843 g_free (file_with_path);
847 empathy_main_window_finalize (GObject *window)
849 EmpathyMainWindowPriv *priv = GET_PRIV (window);
853 /* Save user-defined accelerators. */
854 main_window_accels_save ();
856 g_list_free (priv->actions_connected);
858 g_object_unref (priv->account_manager);
859 g_object_unref (priv->individual_store);
860 g_object_unref (priv->contact_manager);
861 g_object_unref (priv->sound_mgr);
862 g_hash_table_destroy (priv->errors);
863 g_hash_table_destroy (priv->auths);
865 /* disconnect all handlers of status-changed signal */
866 g_hash_table_iter_init (&iter, priv->status_changed_handlers);
867 while (g_hash_table_iter_next (&iter, &key, &value))
868 g_signal_handler_disconnect (TP_ACCOUNT (key),
869 GPOINTER_TO_UINT (value));
871 g_hash_table_destroy (priv->status_changed_handlers);
873 g_signal_handlers_disconnect_by_func (priv->event_manager,
874 main_window_event_added_cb,
876 g_signal_handlers_disconnect_by_func (priv->event_manager,
877 main_window_event_removed_cb,
879 g_object_unref (priv->call_observer);
880 g_object_unref (priv->event_manager);
881 g_object_unref (priv->ui_manager);
882 g_object_unref (priv->chatroom_manager);
884 g_object_unref (priv->gsettings_ui);
885 g_object_unref (priv->gsettings_contacts);
887 G_OBJECT_CLASS (empathy_main_window_parent_class)->finalize (window);
891 main_window_key_press_event_cb (GtkWidget *window,
895 EmpathyChatManager *chat_manager;
897 if (event->keyval == GDK_KEY_T
898 && event->state & GDK_SHIFT_MASK
899 && event->state & GDK_CONTROL_MASK) {
900 chat_manager = empathy_chat_manager_dup_singleton ();
901 empathy_chat_manager_undo_closed_chat (chat_manager);
902 g_object_unref (chat_manager);
908 main_window_chat_quit_cb (GtkAction *action,
909 EmpathyMainWindow *window)
915 main_window_view_history_cb (GtkAction *action,
916 EmpathyMainWindow *window)
918 empathy_log_window_show (NULL, NULL, FALSE, GTK_WINDOW (window));
922 main_window_chat_new_message_cb (GtkAction *action,
923 EmpathyMainWindow *window)
925 empathy_new_message_dialog_show (GTK_WINDOW (window));
929 main_window_chat_new_call_cb (GtkAction *action,
930 EmpathyMainWindow *window)
932 empathy_new_call_dialog_show (GTK_WINDOW (window));
936 main_window_chat_add_contact_cb (GtkAction *action,
937 EmpathyMainWindow *window)
939 empathy_new_individual_dialog_show (GTK_WINDOW (window));
943 main_window_chat_search_contacts_cb (GtkAction *action,
944 EmpathyMainWindow *window)
946 GtkWidget *dialog = empathy_contact_search_dialog_new (
947 GTK_WINDOW (window));
948 gtk_widget_show (dialog);
952 main_window_view_show_ft_manager (GtkAction *action,
953 EmpathyMainWindow *window)
955 empathy_ft_manager_show ();
959 main_window_view_show_offline_cb (GtkToggleAction *action,
960 EmpathyMainWindow *window)
962 EmpathyMainWindowPriv *priv = GET_PRIV (window);
965 current = gtk_toggle_action_get_active (action);
966 g_settings_set_boolean (priv->gsettings_ui,
967 EMPATHY_PREFS_UI_SHOW_OFFLINE,
970 empathy_individual_view_set_show_offline (priv->individual_view,
975 main_window_notify_sort_contact_cb (GSettings *gsettings,
977 EmpathyMainWindow *window)
979 EmpathyMainWindowPriv *priv = GET_PRIV (window);
982 str = g_settings_get_string (gsettings, key);
986 GEnumClass *enum_class;
987 GEnumValue *enum_value;
989 type = empathy_individual_store_sort_get_type ();
990 enum_class = G_ENUM_CLASS (g_type_class_peek (type));
991 enum_value = g_enum_get_value_by_nick (enum_class, str);
993 /* By changing the value of the GtkRadioAction,
994 it emits a signal that calls main_window_view_sort_contacts_cb
995 which updates the contacts list */
996 gtk_radio_action_set_current_value (priv->sort_by_name,
999 g_warning ("Wrong value for sort_criterium configuration : %s", str);
1006 main_window_view_sort_contacts_cb (GtkRadioAction *action,
1007 GtkRadioAction *current,
1008 EmpathyMainWindow *window)
1010 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1011 EmpathyContactListStoreSort value;
1014 GEnumClass *enum_class;
1015 GEnumValue *enum_value;
1017 value = gtk_radio_action_get_current_value (action);
1018 group = gtk_radio_action_get_group (action);
1020 /* Get string from index */
1021 type = empathy_individual_store_sort_get_type ();
1022 enum_class = G_ENUM_CLASS (g_type_class_peek (type));
1023 enum_value = g_enum_get_value (enum_class, g_slist_index (group, current));
1026 g_warning ("No GEnumValue for EmpathyContactListSort with GtkRadioAction index:%d",
1027 g_slist_index (group, action));
1029 g_settings_set_string (priv->gsettings_contacts,
1030 EMPATHY_PREFS_CONTACTS_SORT_CRITERIUM,
1031 enum_value->value_nick);
1033 empathy_individual_store_set_sort_criterium (priv->individual_store,
1038 main_window_view_show_protocols_cb (GtkToggleAction *action,
1039 EmpathyMainWindow *window)
1041 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1044 value = gtk_toggle_action_get_active (action);
1046 g_settings_set_boolean (priv->gsettings_ui,
1047 EMPATHY_PREFS_UI_SHOW_PROTOCOLS,
1049 empathy_individual_store_set_show_protocols (priv->individual_store,
1053 /* Matches GtkRadioAction values set in empathy-main-window.ui */
1054 #define CONTACT_LIST_NORMAL_SIZE_WITH_AVATARS 0
1055 #define CONTACT_LIST_NORMAL_SIZE 1
1056 #define CONTACT_LIST_COMPACT_SIZE 2
1059 main_window_view_contacts_list_size_cb (GtkRadioAction *action,
1060 GtkRadioAction *current,
1061 EmpathyMainWindow *window)
1063 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1064 GSettings *gsettings_ui;
1067 value = gtk_radio_action_get_current_value (action);
1068 /* create a new GSettings, so we can delay the setting until both
1070 gsettings_ui = g_settings_new (EMPATHY_PREFS_UI_SCHEMA);
1072 DEBUG ("radio button toggled, value = %i", value);
1074 g_settings_delay (gsettings_ui);
1075 g_settings_set_boolean (gsettings_ui,
1076 EMPATHY_PREFS_UI_SHOW_AVATARS,
1077 value == CONTACT_LIST_NORMAL_SIZE_WITH_AVATARS);
1079 g_settings_set_boolean (gsettings_ui,
1080 EMPATHY_PREFS_UI_COMPACT_CONTACT_LIST,
1081 value == CONTACT_LIST_COMPACT_SIZE);
1082 g_settings_apply (gsettings_ui);
1084 /* FIXME: these enums probably have the wrong namespace */
1085 empathy_individual_store_set_show_avatars (priv->individual_store,
1086 value == CONTACT_LIST_NORMAL_SIZE_WITH_AVATARS);
1087 empathy_individual_store_set_is_compact (priv->individual_store,
1088 value == CONTACT_LIST_COMPACT_SIZE);
1090 g_object_unref (gsettings_ui);
1093 static void main_window_notify_show_protocols_cb (GSettings *gsettings,
1095 EmpathyMainWindow *window)
1097 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1099 gtk_toggle_action_set_active (priv->show_protocols,
1100 g_settings_get_boolean (gsettings,
1101 EMPATHY_PREFS_UI_SHOW_PROTOCOLS));
1106 main_window_notify_contact_list_size_cb (GSettings *gsettings,
1108 EmpathyMainWindow *window)
1110 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1113 if (g_settings_get_boolean (gsettings,
1114 EMPATHY_PREFS_UI_COMPACT_CONTACT_LIST)) {
1115 value = CONTACT_LIST_COMPACT_SIZE;
1116 } else if (g_settings_get_boolean (gsettings,
1117 EMPATHY_PREFS_UI_SHOW_AVATARS)) {
1118 value = CONTACT_LIST_NORMAL_SIZE_WITH_AVATARS;
1120 value = CONTACT_LIST_NORMAL_SIZE;
1123 DEBUG ("setting changed, value = %i", value);
1125 /* By changing the value of the GtkRadioAction,
1126 it emits a signal that calls main_window_view_contacts_list_size_cb
1127 which updates the contacts list */
1128 gtk_radio_action_set_current_value (priv->normal_with_avatars, value);
1132 main_window_edit_search_contacts_cb (GtkCheckMenuItem *item,
1133 EmpathyMainWindow *window)
1135 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1137 empathy_individual_view_start_search (priv->individual_view);
1141 main_window_view_show_map_cb (GtkCheckMenuItem *item,
1142 EmpathyMainWindow *window)
1144 #ifdef HAVE_LIBCHAMPLAIN
1145 empathy_map_view_show ();
1150 join_chatroom (EmpathyChatroom *chatroom,
1156 account = empathy_chatroom_get_account (chatroom);
1157 room = empathy_chatroom_get_room (chatroom);
1159 DEBUG ("Requesting channel for '%s'", room);
1160 empathy_join_muc (account, room, timestamp);
1166 EmpathyChatroom *chatroom;
1170 } join_fav_account_sig_ctx;
1172 static join_fav_account_sig_ctx *
1173 join_fav_account_sig_ctx_new (TpAccount *account,
1174 EmpathyChatroom *chatroom,
1177 join_fav_account_sig_ctx *ctx = g_slice_new0 (
1178 join_fav_account_sig_ctx);
1180 ctx->account = g_object_ref (account);
1181 ctx->chatroom = g_object_ref (chatroom);
1182 ctx->timestamp = timestamp;
1187 join_fav_account_sig_ctx_free (join_fav_account_sig_ctx *ctx)
1189 g_object_unref (ctx->account);
1190 g_object_unref (ctx->chatroom);
1191 g_slice_free (join_fav_account_sig_ctx, ctx);
1195 account_status_changed_cb (TpAccount *account,
1196 TpConnectionStatus old_status,
1197 TpConnectionStatus new_status,
1199 gchar *dbus_error_name,
1200 GHashTable *details,
1203 join_fav_account_sig_ctx *ctx = user_data;
1205 switch (new_status) {
1206 case TP_CONNECTION_STATUS_DISCONNECTED:
1207 /* Don't wait any longer */
1211 case TP_CONNECTION_STATUS_CONNECTING:
1215 case TP_CONNECTION_STATUS_CONNECTED:
1216 /* We can join the room */
1220 g_assert_not_reached ();
1223 join_chatroom (ctx->chatroom, ctx->timestamp);
1226 g_source_remove (ctx->timeout);
1227 g_signal_handler_disconnect (account, ctx->sig_id);
1230 #define JOIN_FAVORITE_TIMEOUT 5
1233 join_favorite_timeout_cb (gpointer data)
1235 join_fav_account_sig_ctx *ctx = data;
1237 /* stop waiting for joining the favorite room */
1238 g_signal_handler_disconnect (ctx->account, ctx->sig_id);
1243 main_window_favorite_chatroom_join (EmpathyChatroom *chatroom)
1247 account = empathy_chatroom_get_account (chatroom);
1248 if (tp_account_get_connection_status (account, NULL) !=
1249 TP_CONNECTION_STATUS_CONNECTED) {
1250 join_fav_account_sig_ctx *ctx;
1252 ctx = join_fav_account_sig_ctx_new (account, chatroom,
1253 gtk_get_current_event_time ());
1255 ctx->sig_id = g_signal_connect_data (account, "status-changed",
1256 G_CALLBACK (account_status_changed_cb), ctx,
1257 (GClosureNotify) join_fav_account_sig_ctx_free, 0);
1259 ctx->timeout = g_timeout_add_seconds (JOIN_FAVORITE_TIMEOUT,
1260 join_favorite_timeout_cb, ctx);
1264 join_chatroom (chatroom, gtk_get_current_event_time ());
1268 main_window_favorite_chatroom_menu_activate_cb (GtkMenuItem *menu_item,
1269 EmpathyChatroom *chatroom)
1271 main_window_favorite_chatroom_join (chatroom);
1275 main_window_favorite_chatroom_menu_add (EmpathyMainWindow *window,
1276 EmpathyChatroom *chatroom)
1278 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1279 GtkWidget *menu_item;
1280 const gchar *name, *account_name;
1284 if (g_object_get_data (G_OBJECT (chatroom), "menu_item")) {
1288 name = empathy_chatroom_get_name (chatroom);
1289 account_name = tp_account_get_display_name (
1290 empathy_chatroom_get_account (chatroom));
1291 label = g_strdup_printf ("%s (%s)", name, account_name);
1292 menu_item = gtk_menu_item_new_with_label (label);
1294 g_object_set_data (G_OBJECT (menu_item), "is_favorite",
1295 GUINT_TO_POINTER (TRUE));
1297 g_object_set_data (G_OBJECT (chatroom), "menu_item", menu_item);
1298 g_signal_connect (menu_item, "activate",
1299 G_CALLBACK (main_window_favorite_chatroom_menu_activate_cb),
1302 gtk_menu_shell_insert (GTK_MENU_SHELL (priv->room_menu),
1305 gtk_widget_show (menu_item);
1309 main_window_favorite_chatroom_menu_added_cb (EmpathyChatroomManager *manager,
1310 EmpathyChatroom *chatroom,
1311 EmpathyMainWindow *window)
1313 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1315 main_window_favorite_chatroom_menu_add (window, chatroom);
1316 gtk_widget_show (priv->room_separator);
1317 gtk_action_set_sensitive (priv->room_join_favorites, TRUE);
1321 main_window_favorite_chatroom_menu_removed_cb (EmpathyChatroomManager *manager,
1322 EmpathyChatroom *chatroom,
1323 EmpathyMainWindow *window)
1325 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1326 GtkWidget *menu_item;
1329 menu_item = g_object_get_data (G_OBJECT (chatroom), "menu_item");
1330 g_object_set_data (G_OBJECT (chatroom), "menu_item", NULL);
1331 gtk_widget_destroy (menu_item);
1333 chatrooms = empathy_chatroom_manager_get_chatrooms (priv->chatroom_manager, NULL);
1335 gtk_widget_show (priv->room_separator);
1337 gtk_widget_hide (priv->room_separator);
1340 gtk_action_set_sensitive (priv->room_join_favorites, chatrooms != NULL);
1341 g_list_free (chatrooms);
1345 main_window_favorite_chatroom_menu_setup (EmpathyMainWindow *window)
1347 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1348 GList *chatrooms, *l;
1351 priv->chatroom_manager = empathy_chatroom_manager_dup_singleton (NULL);
1352 chatrooms = empathy_chatroom_manager_get_chatrooms (
1353 priv->chatroom_manager, NULL);
1354 room = gtk_ui_manager_get_widget (priv->ui_manager,
1356 priv->room_menu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (room));
1357 priv->room_separator = gtk_ui_manager_get_widget (priv->ui_manager,
1358 "/menubar/room/room_separator");
1360 for (l = chatrooms; l; l = l->next) {
1361 main_window_favorite_chatroom_menu_add (window, l->data);
1365 gtk_widget_hide (priv->room_separator);
1368 gtk_action_set_sensitive (priv->room_join_favorites, chatrooms != NULL);
1370 g_signal_connect (priv->chatroom_manager, "chatroom-added",
1371 G_CALLBACK (main_window_favorite_chatroom_menu_added_cb),
1373 g_signal_connect (priv->chatroom_manager, "chatroom-removed",
1374 G_CALLBACK (main_window_favorite_chatroom_menu_removed_cb),
1377 g_list_free (chatrooms);
1381 main_window_room_join_new_cb (GtkAction *action,
1382 EmpathyMainWindow *window)
1384 empathy_new_chatroom_dialog_show (GTK_WINDOW (window));
1388 main_window_room_join_favorites_cb (GtkAction *action,
1389 EmpathyMainWindow *window)
1391 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1392 GList *chatrooms, *l;
1394 chatrooms = empathy_chatroom_manager_get_chatrooms (priv->chatroom_manager, NULL);
1395 for (l = chatrooms; l; l = l->next) {
1396 main_window_favorite_chatroom_join (l->data);
1398 g_list_free (chatrooms);
1402 main_window_room_manage_favorites_cb (GtkAction *action,
1403 EmpathyMainWindow *window)
1405 empathy_chatrooms_window_show (GTK_WINDOW (window));
1409 main_window_edit_cb (GtkAction *action,
1410 EmpathyMainWindow *window)
1412 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1415 /* FIXME: It should use the UIManager to merge the contact/group submenu */
1416 submenu = empathy_individual_view_get_individual_menu (
1417 priv->individual_view);
1422 item = GTK_MENU_ITEM (priv->edit_context);
1423 label = gtk_bin_get_child (GTK_BIN (item));
1424 gtk_label_set_text (GTK_LABEL (label), _("Contact"));
1426 gtk_widget_show (priv->edit_context);
1427 gtk_widget_show (priv->edit_context_separator);
1429 gtk_menu_item_set_submenu (item, submenu);
1434 submenu = empathy_individual_view_get_group_menu (
1435 priv->individual_view);
1440 item = GTK_MENU_ITEM (priv->edit_context);
1441 label = gtk_bin_get_child (GTK_BIN (item));
1442 gtk_label_set_text (GTK_LABEL (label), _("Group"));
1444 gtk_widget_show (priv->edit_context);
1445 gtk_widget_show (priv->edit_context_separator);
1447 gtk_menu_item_set_submenu (item, submenu);
1452 gtk_widget_hide (priv->edit_context);
1453 gtk_widget_hide (priv->edit_context_separator);
1459 main_window_edit_accounts_cb (GtkAction *action,
1460 EmpathyMainWindow *window)
1462 empathy_accounts_dialog_show_application (gdk_screen_get_default (),
1463 NULL, FALSE, FALSE);
1467 main_window_edit_personal_information_cb (GtkAction *action,
1468 EmpathyMainWindow *window)
1470 empathy_contact_personal_dialog_show (GTK_WINDOW (window));
1474 main_window_edit_blocked_contacts_cb (GtkAction *action,
1475 EmpathyMainWindow *window)
1479 dialog = empathy_contact_blocking_dialog_new (GTK_WINDOW (window));
1480 gtk_widget_show (dialog);
1481 g_signal_connect (dialog, "response",
1482 G_CALLBACK (gtk_widget_destroy), NULL);
1486 main_window_edit_preferences_cb (GtkAction *action,
1487 EmpathyMainWindow *window)
1489 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1491 if (priv->preferences == NULL) {
1492 priv->preferences = empathy_preferences_new (GTK_WINDOW (window));
1493 g_object_add_weak_pointer (G_OBJECT (priv->preferences),
1494 (gpointer) &priv->preferences);
1496 gtk_widget_show (priv->preferences);
1498 gtk_window_present (GTK_WINDOW (priv->preferences));
1503 main_window_help_about_cb (GtkAction *action,
1504 EmpathyMainWindow *window)
1506 empathy_about_dialog_new (GTK_WINDOW (window));
1510 main_window_help_debug_cb (GtkAction *action,
1511 EmpathyMainWindow *window)
1513 GdkDisplay *display;
1514 GError *error = NULL;
1517 GdkAppLaunchContext *context = NULL;
1519 /* Try to run from source directory if possible */
1520 path = g_build_filename (g_getenv ("EMPATHY_SRCDIR"), "src",
1521 "empathy-debugger", NULL);
1523 if (!g_file_test (path, G_FILE_TEST_EXISTS)) {
1525 path = g_build_filename (BIN_DIR, "empathy-debugger", NULL);
1528 app_info = g_app_info_create_from_commandline (path, NULL, 0, &error);
1529 if (app_info == NULL) {
1530 DEBUG ("Failed to create app info: %s", error->message);
1531 g_error_free (error);
1535 display = gdk_display_get_default ();
1536 context = gdk_display_get_app_launch_context (display);
1538 if (!g_app_info_launch (app_info, NULL, (GAppLaunchContext *) context,
1540 g_warning ("Failed to open debug window: %s", error->message);
1541 g_error_free (error);
1546 tp_clear_object (&app_info);
1547 tp_clear_object (&context);
1552 main_window_help_contents_cb (GtkAction *action,
1553 EmpathyMainWindow *window)
1555 empathy_url_show (GTK_WIDGET (window), "ghelp:empathy");
1559 main_window_throbber_button_press_event_cb (GtkWidget *throbber,
1560 GdkEventButton *event,
1561 EmpathyMainWindow *window)
1563 if (event->type != GDK_BUTTON_PRESS ||
1564 event->button != 1) {
1568 empathy_accounts_dialog_show_application (
1569 gtk_widget_get_screen (GTK_WIDGET (throbber)),
1570 NULL, FALSE, FALSE);
1576 main_window_account_removed_cb (TpAccountManager *manager,
1578 EmpathyMainWindow *window)
1580 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1583 a = tp_account_manager_get_valid_accounts (manager);
1585 gtk_action_set_sensitive (priv->view_history,
1586 g_list_length (a) > 0);
1590 /* remove errors if any */
1591 main_window_remove_error (window, account);
1595 main_window_account_validity_changed_cb (TpAccountManager *manager,
1598 EmpathyMainWindow *window)
1600 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1604 handler_id = GPOINTER_TO_UINT (g_hash_table_lookup (
1605 priv->status_changed_handlers, account));
1607 /* connect signal only if it was not connected yet */
1608 if (handler_id == 0) {
1609 handler_id = g_signal_connect (account,
1611 G_CALLBACK (main_window_connection_changed_cb),
1613 g_hash_table_insert (priv->status_changed_handlers,
1614 account, GUINT_TO_POINTER (handler_id));
1618 main_window_account_removed_cb (manager, account, window);
1622 main_window_notify_show_offline_cb (GSettings *gsettings,
1624 gpointer toggle_action)
1626 gtk_toggle_action_set_active (toggle_action,
1627 g_settings_get_boolean (gsettings, key));
1631 main_window_connection_items_setup (EmpathyMainWindow *window,
1634 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1638 const gchar *actions_connected[] = {
1640 "room_join_favorites",
1644 "edit_personal_information",
1645 "edit_blocked_contacts"
1648 for (i = 0, list = NULL; i < G_N_ELEMENTS (actions_connected); i++) {
1649 action = gtk_builder_get_object (gui, actions_connected[i]);
1650 list = g_list_prepend (list, action);
1653 priv->actions_connected = list;
1657 account_manager_prepared_cb (GObject *source_object,
1658 GAsyncResult *result,
1661 GList *accounts, *j;
1662 TpAccountManager *manager = TP_ACCOUNT_MANAGER (source_object);
1663 EmpathyMainWindow *window = user_data;
1664 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1665 GError *error = NULL;
1667 if (!tp_account_manager_prepare_finish (manager, result, &error)) {
1668 DEBUG ("Failed to prepare account manager: %s", error->message);
1669 g_error_free (error);
1673 accounts = tp_account_manager_get_valid_accounts (priv->account_manager);
1674 for (j = accounts; j != NULL; j = j->next) {
1675 TpAccount *account = TP_ACCOUNT (j->data);
1678 handler_id = g_signal_connect (account, "status-changed",
1679 G_CALLBACK (main_window_connection_changed_cb),
1681 g_hash_table_insert (priv->status_changed_handlers,
1682 account, GUINT_TO_POINTER (handler_id));
1685 g_signal_connect (manager, "account-validity-changed",
1686 G_CALLBACK (main_window_account_validity_changed_cb),
1689 main_window_update_status (window);
1691 /* Disable the "Previous Conversations" menu entry if there is no account */
1692 gtk_action_set_sensitive (priv->view_history,
1693 g_list_length (accounts) > 0);
1695 g_list_free (accounts);
1699 main_window_members_changed_cb (EmpathyContactList *list,
1700 EmpathyContact *contact,
1701 EmpathyContact *actor,
1705 EmpathyMainWindow *window)
1707 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1712 if (!empathy_migrate_butterfly_logs (contact)) {
1713 g_signal_handler_disconnect (list,
1714 priv->butterfly_log_migration_members_changed_id);
1715 priv->butterfly_log_migration_members_changed_id = 0;
1720 empathy_main_window_constructor (GType type,
1721 guint n_construct_params,
1722 GObjectConstructParam *construct_params)
1724 static GObject *window = NULL;
1727 return g_object_ref (window);
1729 window = G_OBJECT_CLASS (empathy_main_window_parent_class)->constructor (
1730 type, n_construct_params, construct_params);
1732 g_object_add_weak_pointer (window, (gpointer) &window);
1738 empathy_main_window_class_init (EmpathyMainWindowClass *klass)
1740 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1742 object_class->finalize = empathy_main_window_finalize;
1743 object_class->constructor = empathy_main_window_constructor;
1745 g_type_class_add_private (object_class, sizeof (EmpathyMainWindowPriv));
1749 empathy_main_window_init (EmpathyMainWindow *window)
1751 EmpathyMainWindowPriv *priv;
1752 EmpathyIndividualManager *individual_manager;
1755 GtkToggleAction *show_offline_widget;
1756 GtkAction *show_map_widget;
1758 gboolean show_offline;
1761 GtkTreeModel *model;
1763 priv = window->priv = G_TYPE_INSTANCE_GET_PRIVATE (window,
1764 EMPATHY_TYPE_MAIN_WINDOW, EmpathyMainWindowPriv);
1766 priv->gsettings_ui = g_settings_new (EMPATHY_PREFS_UI_SCHEMA);
1767 priv->gsettings_contacts = g_settings_new (EMPATHY_PREFS_CONTACTS_SCHEMA);
1769 priv->sound_mgr = empathy_sound_manager_dup_singleton ();
1771 gtk_window_set_title (GTK_WINDOW (window), _("Contact List"));
1772 gtk_window_set_role (GTK_WINDOW (window), "contact_list");
1773 gtk_window_set_default_size (GTK_WINDOW (window), 225, 325);
1775 /* Set up interface */
1776 filename = empathy_file_lookup ("empathy-main-window.ui", "src");
1777 gui = empathy_builder_get_file (filename,
1778 "main_vbox", &priv->main_vbox,
1779 "errors_vbox", &priv->errors_vbox,
1780 "auth_vbox", &priv->auth_vbox,
1781 "ui_manager", &priv->ui_manager,
1782 "view_show_offline", &show_offline_widget,
1783 "view_show_protocols", &priv->show_protocols,
1784 "view_sort_by_name", &priv->sort_by_name,
1785 "view_sort_by_status", &priv->sort_by_status,
1786 "view_normal_size_with_avatars", &priv->normal_with_avatars,
1787 "view_normal_size", &priv->normal_size,
1788 "view_compact_size", &priv->compact_size,
1789 "view_history", &priv->view_history,
1790 "view_show_map", &show_map_widget,
1791 "room_join_favorites", &priv->room_join_favorites,
1792 "presence_toolbar", &priv->presence_toolbar,
1793 "notebook", &priv->notebook,
1794 "no_entry_label", &priv->no_entry_label,
1795 "roster_scrolledwindow", &sw,
1799 gtk_container_add (GTK_CONTAINER (window), priv->main_vbox);
1800 gtk_widget_show (priv->main_vbox);
1802 g_signal_connect (window, "key-press-event",
1803 G_CALLBACK (main_window_key_press_event_cb), NULL);
1805 empathy_builder_connect (gui, window,
1806 "chat_quit", "activate", main_window_chat_quit_cb,
1807 "chat_new_message", "activate", main_window_chat_new_message_cb,
1808 "chat_new_call", "activate", main_window_chat_new_call_cb,
1809 "view_history", "activate", main_window_view_history_cb,
1810 "room_join_new", "activate", main_window_room_join_new_cb,
1811 "room_join_favorites", "activate", main_window_room_join_favorites_cb,
1812 "room_manage_favorites", "activate", main_window_room_manage_favorites_cb,
1813 "chat_add_contact", "activate", main_window_chat_add_contact_cb,
1814 "chat_search_contacts", "activate", main_window_chat_search_contacts_cb,
1815 "view_show_ft_manager", "activate", main_window_view_show_ft_manager,
1816 "view_show_offline", "toggled", main_window_view_show_offline_cb,
1817 "view_show_protocols", "toggled", main_window_view_show_protocols_cb,
1818 "view_sort_by_name", "changed", main_window_view_sort_contacts_cb,
1819 "view_normal_size_with_avatars", "changed", main_window_view_contacts_list_size_cb,
1820 "view_show_map", "activate", main_window_view_show_map_cb,
1821 "edit", "activate", main_window_edit_cb,
1822 "edit_accounts", "activate", main_window_edit_accounts_cb,
1823 "edit_personal_information", "activate", main_window_edit_personal_information_cb,
1824 "edit_blocked_contacts", "activate", main_window_edit_blocked_contacts_cb,
1825 "edit_preferences", "activate", main_window_edit_preferences_cb,
1826 "edit_search_contacts", "activate", main_window_edit_search_contacts_cb,
1827 "help_about", "activate", main_window_help_about_cb,
1828 "help_debug", "activate", main_window_help_debug_cb,
1829 "help_contents", "activate", main_window_help_contents_cb,
1832 /* Set up connection related widgets. */
1833 main_window_connection_items_setup (window, gui);
1835 g_object_ref (priv->ui_manager);
1836 g_object_unref (gui);
1838 #ifndef HAVE_LIBCHAMPLAIN
1839 gtk_action_set_visible (show_map_widget, FALSE);
1842 priv->account_manager = tp_account_manager_dup ();
1844 tp_account_manager_prepare_async (priv->account_manager, NULL,
1845 account_manager_prepared_cb, window);
1847 priv->errors = g_hash_table_new_full (g_direct_hash,
1852 priv->auths = g_hash_table_new (NULL, NULL);
1854 priv->status_changed_handlers = g_hash_table_new_full (g_direct_hash,
1860 main_window_favorite_chatroom_menu_setup (window);
1862 priv->edit_context = gtk_ui_manager_get_widget (priv->ui_manager,
1863 "/menubar/edit/edit_context");
1864 priv->edit_context_separator = gtk_ui_manager_get_widget (
1866 "/menubar/edit/edit_context_separator");
1867 gtk_widget_hide (priv->edit_context);
1868 gtk_widget_hide (priv->edit_context_separator);
1870 /* Set up contact list. */
1871 empathy_status_presets_get_all ();
1873 /* Set up presence chooser */
1874 priv->presence_chooser = empathy_presence_chooser_new ();
1875 gtk_widget_show (priv->presence_chooser);
1876 item = gtk_tool_item_new ();
1877 gtk_widget_show (GTK_WIDGET (item));
1878 gtk_widget_set_size_request (priv->presence_chooser, 10, -1);
1879 gtk_container_add (GTK_CONTAINER (item), priv->presence_chooser);
1880 gtk_tool_item_set_is_important (item, TRUE);
1881 gtk_tool_item_set_expand (item, TRUE);
1882 gtk_toolbar_insert (GTK_TOOLBAR (priv->presence_toolbar), item, -1);
1884 /* Set up the throbber */
1885 priv->throbber = gtk_spinner_new ();
1886 gtk_widget_set_size_request (priv->throbber, 16, -1);
1887 gtk_widget_set_tooltip_text (priv->throbber, _("Show and edit accounts"));
1888 gtk_widget_set_events (priv->throbber, GDK_BUTTON_PRESS_MASK);
1889 g_signal_connect (priv->throbber, "button-press-event",
1890 G_CALLBACK (main_window_throbber_button_press_event_cb),
1892 gtk_widget_show (priv->throbber);
1894 item = gtk_tool_item_new ();
1895 gtk_container_set_border_width (GTK_CONTAINER (item), 6);
1896 gtk_toolbar_insert (GTK_TOOLBAR (priv->presence_toolbar), item, -1);
1897 gtk_container_add (GTK_CONTAINER (item), priv->throbber);
1898 priv->throbber_tool_item = GTK_WIDGET (item);
1900 /* XXX: this class is designed to live for the duration of the program,
1901 * so it's got a race condition between its signal handlers and its
1902 * finalization. The class is planned to be removed, so we won't fix
1903 * this before then. */
1904 priv->contact_manager = EMPATHY_CONTACT_LIST (
1905 empathy_contact_manager_dup_singleton ());
1906 individual_manager = empathy_individual_manager_dup_singleton ();
1907 priv->individual_store = empathy_individual_store_new (
1908 individual_manager);
1909 g_object_unref (individual_manager);
1911 /* For the moment, we disallow Persona drops onto the main contact list (e.g. from things such as
1912 * the EmpathyPersonaView in the linking dialogue). No code is hooked up to do anything on a Persona
1913 * drop, so allowing them would achieve nothing except confusion. */
1914 priv->individual_view = empathy_individual_view_new (
1915 priv->individual_store,
1916 EMPATHY_INDIVIDUAL_VIEW_FEATURE_ALL ^ EMPATHY_INDIVIDUAL_VIEW_FEATURE_PERSONA_DROP,
1917 EMPATHY_INDIVIDUAL_FEATURE_ALL);
1919 priv->butterfly_log_migration_members_changed_id = g_signal_connect (
1920 priv->contact_manager, "members-changed",
1921 G_CALLBACK (main_window_members_changed_cb), window);
1923 gtk_widget_show (GTK_WIDGET (priv->individual_view));
1924 gtk_container_add (GTK_CONTAINER (sw),
1925 GTK_WIDGET (priv->individual_view));
1926 g_signal_connect (priv->individual_view, "row-activated",
1927 G_CALLBACK (main_window_row_activated_cb),
1930 /* Set up search bar */
1931 priv->search_bar = empathy_live_search_new (
1932 GTK_WIDGET (priv->individual_view));
1933 empathy_individual_view_set_live_search (priv->individual_view,
1934 EMPATHY_LIVE_SEARCH (priv->search_bar));
1935 gtk_box_pack_start (GTK_BOX (priv->main_vbox), priv->search_bar,
1937 g_signal_connect_swapped (window, "map",
1938 G_CALLBACK (gtk_widget_grab_focus), priv->individual_view);
1940 /* Connect to proper signals to check if contact list is empty or not */
1941 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->individual_view));
1943 g_signal_connect (model, "row-inserted",
1944 G_CALLBACK (main_window_row_inserted_cb),
1946 g_signal_connect (model, "row-deleted",
1947 G_CALLBACK (main_window_row_deleted_cb),
1950 /* Load user-defined accelerators. */
1951 main_window_accels_load ();
1953 /* Set window size. */
1954 empathy_geometry_bind (GTK_WINDOW (window), GEOMETRY_NAME);
1956 /* Enable event handling */
1957 priv->call_observer = empathy_call_observer_dup_singleton ();
1958 priv->event_manager = empathy_event_manager_dup_singleton ();
1960 g_signal_connect (priv->event_manager, "event-added",
1961 G_CALLBACK (main_window_event_added_cb), window);
1962 g_signal_connect (priv->event_manager, "event-removed",
1963 G_CALLBACK (main_window_event_removed_cb), window);
1964 g_signal_connect (priv->account_manager, "account-validity-changed",
1965 G_CALLBACK (main_window_account_validity_changed_cb),
1967 g_signal_connect (priv->account_manager, "account-removed",
1968 G_CALLBACK (main_window_account_removed_cb),
1970 g_signal_connect (priv->account_manager, "account-disabled",
1971 G_CALLBACK (main_window_account_disabled_cb),
1974 l = empathy_event_manager_get_events (priv->event_manager);
1976 main_window_event_added_cb (priv->event_manager, l->data,
1981 /* Show offline ? */
1982 show_offline = g_settings_get_boolean (priv->gsettings_ui,
1983 EMPATHY_PREFS_UI_SHOW_OFFLINE);
1984 g_signal_connect (priv->gsettings_ui,
1985 "changed::" EMPATHY_PREFS_UI_SHOW_OFFLINE,
1986 G_CALLBACK (main_window_notify_show_offline_cb),
1987 show_offline_widget);
1989 gtk_toggle_action_set_active (show_offline_widget, show_offline);
1991 /* Show protocol ? */
1992 g_signal_connect (priv->gsettings_ui,
1993 "changed::" EMPATHY_PREFS_UI_SHOW_PROTOCOLS,
1994 G_CALLBACK (main_window_notify_show_protocols_cb),
1997 main_window_notify_show_protocols_cb (priv->gsettings_ui,
1998 EMPATHY_PREFS_UI_SHOW_PROTOCOLS,
2001 /* Sort by name / by status ? */
2002 g_signal_connect (priv->gsettings_contacts,
2003 "changed::" EMPATHY_PREFS_CONTACTS_SORT_CRITERIUM,
2004 G_CALLBACK (main_window_notify_sort_contact_cb),
2007 main_window_notify_sort_contact_cb (priv->gsettings_contacts,
2008 EMPATHY_PREFS_CONTACTS_SORT_CRITERIUM,
2011 /* Contacts list size */
2012 g_signal_connect (priv->gsettings_ui,
2013 "changed::" EMPATHY_PREFS_UI_COMPACT_CONTACT_LIST,
2014 G_CALLBACK (main_window_notify_contact_list_size_cb),
2016 g_signal_connect (priv->gsettings_ui,
2017 "changed::" EMPATHY_PREFS_UI_SHOW_AVATARS,
2018 G_CALLBACK (main_window_notify_contact_list_size_cb),
2021 main_window_notify_contact_list_size_cb (priv->gsettings_ui,
2022 EMPATHY_PREFS_UI_SHOW_AVATARS,
2027 empathy_main_window_dup (void)
2029 return g_object_new (EMPATHY_TYPE_MAIN_WINDOW, NULL);