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;
1282 if (g_object_get_data (G_OBJECT (chatroom), "menu_item")) {
1286 name = empathy_chatroom_get_name (chatroom);
1287 menu_item = gtk_menu_item_new_with_label (name);
1288 g_object_set_data (G_OBJECT (menu_item), "is_favorite",
1289 GUINT_TO_POINTER (TRUE));
1291 g_object_set_data (G_OBJECT (chatroom), "menu_item", menu_item);
1292 g_signal_connect (menu_item, "activate",
1293 G_CALLBACK (main_window_favorite_chatroom_menu_activate_cb),
1296 gtk_menu_shell_insert (GTK_MENU_SHELL (priv->room_menu),
1299 gtk_widget_show (menu_item);
1303 main_window_favorite_chatroom_menu_added_cb (EmpathyChatroomManager *manager,
1304 EmpathyChatroom *chatroom,
1305 EmpathyMainWindow *window)
1307 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1309 main_window_favorite_chatroom_menu_add (window, chatroom);
1310 gtk_widget_show (priv->room_separator);
1311 gtk_action_set_sensitive (priv->room_join_favorites, TRUE);
1315 main_window_favorite_chatroom_menu_removed_cb (EmpathyChatroomManager *manager,
1316 EmpathyChatroom *chatroom,
1317 EmpathyMainWindow *window)
1319 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1320 GtkWidget *menu_item;
1323 menu_item = g_object_get_data (G_OBJECT (chatroom), "menu_item");
1324 g_object_set_data (G_OBJECT (chatroom), "menu_item", NULL);
1325 gtk_widget_destroy (menu_item);
1327 chatrooms = empathy_chatroom_manager_get_chatrooms (priv->chatroom_manager, NULL);
1329 gtk_widget_show (priv->room_separator);
1331 gtk_widget_hide (priv->room_separator);
1334 gtk_action_set_sensitive (priv->room_join_favorites, chatrooms != NULL);
1335 g_list_free (chatrooms);
1339 main_window_favorite_chatroom_menu_setup (EmpathyMainWindow *window)
1341 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1342 GList *chatrooms, *l;
1345 priv->chatroom_manager = empathy_chatroom_manager_dup_singleton (NULL);
1346 chatrooms = empathy_chatroom_manager_get_chatrooms (
1347 priv->chatroom_manager, NULL);
1348 room = gtk_ui_manager_get_widget (priv->ui_manager,
1350 priv->room_menu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (room));
1351 priv->room_separator = gtk_ui_manager_get_widget (priv->ui_manager,
1352 "/menubar/room/room_separator");
1354 for (l = chatrooms; l; l = l->next) {
1355 main_window_favorite_chatroom_menu_add (window, l->data);
1359 gtk_widget_hide (priv->room_separator);
1362 gtk_action_set_sensitive (priv->room_join_favorites, chatrooms != NULL);
1364 g_signal_connect (priv->chatroom_manager, "chatroom-added",
1365 G_CALLBACK (main_window_favorite_chatroom_menu_added_cb),
1367 g_signal_connect (priv->chatroom_manager, "chatroom-removed",
1368 G_CALLBACK (main_window_favorite_chatroom_menu_removed_cb),
1371 g_list_free (chatrooms);
1375 main_window_room_join_new_cb (GtkAction *action,
1376 EmpathyMainWindow *window)
1378 empathy_new_chatroom_dialog_show (GTK_WINDOW (window));
1382 main_window_room_join_favorites_cb (GtkAction *action,
1383 EmpathyMainWindow *window)
1385 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1386 GList *chatrooms, *l;
1388 chatrooms = empathy_chatroom_manager_get_chatrooms (priv->chatroom_manager, NULL);
1389 for (l = chatrooms; l; l = l->next) {
1390 main_window_favorite_chatroom_join (l->data);
1392 g_list_free (chatrooms);
1396 main_window_room_manage_favorites_cb (GtkAction *action,
1397 EmpathyMainWindow *window)
1399 empathy_chatrooms_window_show (GTK_WINDOW (window));
1403 main_window_edit_cb (GtkAction *action,
1404 EmpathyMainWindow *window)
1406 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1409 /* FIXME: It should use the UIManager to merge the contact/group submenu */
1410 submenu = empathy_individual_view_get_individual_menu (
1411 priv->individual_view);
1416 item = GTK_MENU_ITEM (priv->edit_context);
1417 label = gtk_bin_get_child (GTK_BIN (item));
1418 gtk_label_set_text (GTK_LABEL (label), _("Contact"));
1420 gtk_widget_show (priv->edit_context);
1421 gtk_widget_show (priv->edit_context_separator);
1423 gtk_menu_item_set_submenu (item, submenu);
1428 submenu = empathy_individual_view_get_group_menu (
1429 priv->individual_view);
1434 item = GTK_MENU_ITEM (priv->edit_context);
1435 label = gtk_bin_get_child (GTK_BIN (item));
1436 gtk_label_set_text (GTK_LABEL (label), _("Group"));
1438 gtk_widget_show (priv->edit_context);
1439 gtk_widget_show (priv->edit_context_separator);
1441 gtk_menu_item_set_submenu (item, submenu);
1446 gtk_widget_hide (priv->edit_context);
1447 gtk_widget_hide (priv->edit_context_separator);
1453 main_window_edit_accounts_cb (GtkAction *action,
1454 EmpathyMainWindow *window)
1456 empathy_accounts_dialog_show_application (gdk_screen_get_default (),
1457 NULL, FALSE, FALSE);
1461 main_window_edit_personal_information_cb (GtkAction *action,
1462 EmpathyMainWindow *window)
1464 empathy_contact_personal_dialog_show (GTK_WINDOW (window));
1468 main_window_edit_blocked_contacts_cb (GtkAction *action,
1469 EmpathyMainWindow *window)
1473 dialog = empathy_contact_blocking_dialog_new (GTK_WINDOW (window));
1474 gtk_widget_show (dialog);
1475 g_signal_connect (dialog, "response",
1476 G_CALLBACK (gtk_widget_destroy), NULL);
1480 main_window_edit_preferences_cb (GtkAction *action,
1481 EmpathyMainWindow *window)
1483 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1485 if (priv->preferences == NULL) {
1486 priv->preferences = empathy_preferences_new (GTK_WINDOW (window));
1487 g_object_add_weak_pointer (G_OBJECT (priv->preferences),
1488 (gpointer) &priv->preferences);
1490 gtk_widget_show (priv->preferences);
1492 gtk_window_present (GTK_WINDOW (priv->preferences));
1497 main_window_help_about_cb (GtkAction *action,
1498 EmpathyMainWindow *window)
1500 empathy_about_dialog_new (GTK_WINDOW (window));
1504 main_window_help_debug_cb (GtkAction *action,
1505 EmpathyMainWindow *window)
1507 GdkDisplay *display;
1508 GError *error = NULL;
1511 GdkAppLaunchContext *context = NULL;
1513 /* Try to run from source directory if possible */
1514 path = g_build_filename (g_getenv ("EMPATHY_SRCDIR"), "src",
1515 "empathy-debugger", NULL);
1517 if (!g_file_test (path, G_FILE_TEST_EXISTS)) {
1519 path = g_build_filename (BIN_DIR, "empathy-debugger", NULL);
1522 app_info = g_app_info_create_from_commandline (path, NULL, 0, &error);
1523 if (app_info == NULL) {
1524 DEBUG ("Failed to create app info: %s", error->message);
1525 g_error_free (error);
1529 display = gdk_display_get_default ();
1530 context = gdk_display_get_app_launch_context (display);
1532 if (!g_app_info_launch (app_info, NULL, (GAppLaunchContext *) context,
1534 g_warning ("Failed to open debug window: %s", error->message);
1535 g_error_free (error);
1540 tp_clear_object (&app_info);
1541 tp_clear_object (&context);
1546 main_window_help_contents_cb (GtkAction *action,
1547 EmpathyMainWindow *window)
1549 empathy_url_show (GTK_WIDGET (window), "ghelp:empathy");
1553 main_window_throbber_button_press_event_cb (GtkWidget *throbber,
1554 GdkEventButton *event,
1555 EmpathyMainWindow *window)
1557 if (event->type != GDK_BUTTON_PRESS ||
1558 event->button != 1) {
1562 empathy_accounts_dialog_show_application (
1563 gtk_widget_get_screen (GTK_WIDGET (throbber)),
1564 NULL, FALSE, FALSE);
1570 main_window_account_removed_cb (TpAccountManager *manager,
1572 EmpathyMainWindow *window)
1574 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1577 a = tp_account_manager_get_valid_accounts (manager);
1579 gtk_action_set_sensitive (priv->view_history,
1580 g_list_length (a) > 0);
1584 /* remove errors if any */
1585 main_window_remove_error (window, account);
1589 main_window_account_validity_changed_cb (TpAccountManager *manager,
1592 EmpathyMainWindow *window)
1594 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1598 handler_id = GPOINTER_TO_UINT (g_hash_table_lookup (
1599 priv->status_changed_handlers, account));
1601 /* connect signal only if it was not connected yet */
1602 if (handler_id == 0) {
1603 handler_id = g_signal_connect (account,
1605 G_CALLBACK (main_window_connection_changed_cb),
1607 g_hash_table_insert (priv->status_changed_handlers,
1608 account, GUINT_TO_POINTER (handler_id));
1612 main_window_account_removed_cb (manager, account, window);
1616 main_window_notify_show_offline_cb (GSettings *gsettings,
1618 gpointer toggle_action)
1620 gtk_toggle_action_set_active (toggle_action,
1621 g_settings_get_boolean (gsettings, key));
1625 main_window_connection_items_setup (EmpathyMainWindow *window,
1628 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1632 const gchar *actions_connected[] = {
1634 "room_join_favorites",
1638 "edit_personal_information",
1639 "edit_blocked_contacts"
1642 for (i = 0, list = NULL; i < G_N_ELEMENTS (actions_connected); i++) {
1643 action = gtk_builder_get_object (gui, actions_connected[i]);
1644 list = g_list_prepend (list, action);
1647 priv->actions_connected = list;
1651 account_manager_prepared_cb (GObject *source_object,
1652 GAsyncResult *result,
1655 GList *accounts, *j;
1656 TpAccountManager *manager = TP_ACCOUNT_MANAGER (source_object);
1657 EmpathyMainWindow *window = user_data;
1658 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1659 GError *error = NULL;
1661 if (!tp_account_manager_prepare_finish (manager, result, &error)) {
1662 DEBUG ("Failed to prepare account manager: %s", error->message);
1663 g_error_free (error);
1667 accounts = tp_account_manager_get_valid_accounts (priv->account_manager);
1668 for (j = accounts; j != NULL; j = j->next) {
1669 TpAccount *account = TP_ACCOUNT (j->data);
1672 handler_id = g_signal_connect (account, "status-changed",
1673 G_CALLBACK (main_window_connection_changed_cb),
1675 g_hash_table_insert (priv->status_changed_handlers,
1676 account, GUINT_TO_POINTER (handler_id));
1679 g_signal_connect (manager, "account-validity-changed",
1680 G_CALLBACK (main_window_account_validity_changed_cb),
1683 main_window_update_status (window);
1685 /* Disable the "Previous Conversations" menu entry if there is no account */
1686 gtk_action_set_sensitive (priv->view_history,
1687 g_list_length (accounts) > 0);
1689 g_list_free (accounts);
1693 main_window_members_changed_cb (EmpathyContactList *list,
1694 EmpathyContact *contact,
1695 EmpathyContact *actor,
1699 EmpathyMainWindow *window)
1701 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1706 if (!empathy_migrate_butterfly_logs (contact)) {
1707 g_signal_handler_disconnect (list,
1708 priv->butterfly_log_migration_members_changed_id);
1709 priv->butterfly_log_migration_members_changed_id = 0;
1714 empathy_main_window_constructor (GType type,
1715 guint n_construct_params,
1716 GObjectConstructParam *construct_params)
1718 static GObject *window = NULL;
1721 return g_object_ref (window);
1723 window = G_OBJECT_CLASS (empathy_main_window_parent_class)->constructor (
1724 type, n_construct_params, construct_params);
1726 g_object_add_weak_pointer (window, (gpointer) &window);
1732 empathy_main_window_class_init (EmpathyMainWindowClass *klass)
1734 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1736 object_class->finalize = empathy_main_window_finalize;
1737 object_class->constructor = empathy_main_window_constructor;
1739 g_type_class_add_private (object_class, sizeof (EmpathyMainWindowPriv));
1743 empathy_main_window_init (EmpathyMainWindow *window)
1745 EmpathyMainWindowPriv *priv;
1746 EmpathyIndividualManager *individual_manager;
1749 GtkToggleAction *show_offline_widget;
1750 GtkAction *show_map_widget;
1752 gboolean show_offline;
1755 GtkTreeModel *model;
1757 priv = window->priv = G_TYPE_INSTANCE_GET_PRIVATE (window,
1758 EMPATHY_TYPE_MAIN_WINDOW, EmpathyMainWindowPriv);
1760 priv->gsettings_ui = g_settings_new (EMPATHY_PREFS_UI_SCHEMA);
1761 priv->gsettings_contacts = g_settings_new (EMPATHY_PREFS_CONTACTS_SCHEMA);
1763 priv->sound_mgr = empathy_sound_manager_dup_singleton ();
1765 gtk_window_set_title (GTK_WINDOW (window), _("Contact List"));
1766 gtk_window_set_role (GTK_WINDOW (window), "contact_list");
1767 gtk_window_set_default_size (GTK_WINDOW (window), 225, 325);
1769 /* Set up interface */
1770 filename = empathy_file_lookup ("empathy-main-window.ui", "src");
1771 gui = empathy_builder_get_file (filename,
1772 "main_vbox", &priv->main_vbox,
1773 "errors_vbox", &priv->errors_vbox,
1774 "auth_vbox", &priv->auth_vbox,
1775 "ui_manager", &priv->ui_manager,
1776 "view_show_offline", &show_offline_widget,
1777 "view_show_protocols", &priv->show_protocols,
1778 "view_sort_by_name", &priv->sort_by_name,
1779 "view_sort_by_status", &priv->sort_by_status,
1780 "view_normal_size_with_avatars", &priv->normal_with_avatars,
1781 "view_normal_size", &priv->normal_size,
1782 "view_compact_size", &priv->compact_size,
1783 "view_history", &priv->view_history,
1784 "view_show_map", &show_map_widget,
1785 "room_join_favorites", &priv->room_join_favorites,
1786 "presence_toolbar", &priv->presence_toolbar,
1787 "notebook", &priv->notebook,
1788 "no_entry_label", &priv->no_entry_label,
1789 "roster_scrolledwindow", &sw,
1793 gtk_container_add (GTK_CONTAINER (window), priv->main_vbox);
1794 gtk_widget_show (priv->main_vbox);
1796 g_signal_connect (window, "key-press-event",
1797 G_CALLBACK (main_window_key_press_event_cb), NULL);
1799 empathy_builder_connect (gui, window,
1800 "chat_quit", "activate", main_window_chat_quit_cb,
1801 "chat_new_message", "activate", main_window_chat_new_message_cb,
1802 "chat_new_call", "activate", main_window_chat_new_call_cb,
1803 "view_history", "activate", main_window_view_history_cb,
1804 "room_join_new", "activate", main_window_room_join_new_cb,
1805 "room_join_favorites", "activate", main_window_room_join_favorites_cb,
1806 "room_manage_favorites", "activate", main_window_room_manage_favorites_cb,
1807 "chat_add_contact", "activate", main_window_chat_add_contact_cb,
1808 "chat_search_contacts", "activate", main_window_chat_search_contacts_cb,
1809 "view_show_ft_manager", "activate", main_window_view_show_ft_manager,
1810 "view_show_offline", "toggled", main_window_view_show_offline_cb,
1811 "view_show_protocols", "toggled", main_window_view_show_protocols_cb,
1812 "view_sort_by_name", "changed", main_window_view_sort_contacts_cb,
1813 "view_normal_size_with_avatars", "changed", main_window_view_contacts_list_size_cb,
1814 "view_show_map", "activate", main_window_view_show_map_cb,
1815 "edit", "activate", main_window_edit_cb,
1816 "edit_accounts", "activate", main_window_edit_accounts_cb,
1817 "edit_personal_information", "activate", main_window_edit_personal_information_cb,
1818 "edit_blocked_contacts", "activate", main_window_edit_blocked_contacts_cb,
1819 "edit_preferences", "activate", main_window_edit_preferences_cb,
1820 "edit_search_contacts", "activate", main_window_edit_search_contacts_cb,
1821 "help_about", "activate", main_window_help_about_cb,
1822 "help_debug", "activate", main_window_help_debug_cb,
1823 "help_contents", "activate", main_window_help_contents_cb,
1826 /* Set up connection related widgets. */
1827 main_window_connection_items_setup (window, gui);
1829 g_object_ref (priv->ui_manager);
1830 g_object_unref (gui);
1832 #ifndef HAVE_LIBCHAMPLAIN
1833 gtk_action_set_visible (show_map_widget, FALSE);
1836 priv->account_manager = tp_account_manager_dup ();
1838 tp_account_manager_prepare_async (priv->account_manager, NULL,
1839 account_manager_prepared_cb, window);
1841 priv->errors = g_hash_table_new_full (g_direct_hash,
1846 priv->auths = g_hash_table_new (NULL, NULL);
1848 priv->status_changed_handlers = g_hash_table_new_full (g_direct_hash,
1854 main_window_favorite_chatroom_menu_setup (window);
1856 priv->edit_context = gtk_ui_manager_get_widget (priv->ui_manager,
1857 "/menubar/edit/edit_context");
1858 priv->edit_context_separator = gtk_ui_manager_get_widget (
1860 "/menubar/edit/edit_context_separator");
1861 gtk_widget_hide (priv->edit_context);
1862 gtk_widget_hide (priv->edit_context_separator);
1864 /* Set up contact list. */
1865 empathy_status_presets_get_all ();
1867 /* Set up presence chooser */
1868 priv->presence_chooser = empathy_presence_chooser_new ();
1869 gtk_widget_show (priv->presence_chooser);
1870 item = gtk_tool_item_new ();
1871 gtk_widget_show (GTK_WIDGET (item));
1872 gtk_widget_set_size_request (priv->presence_chooser, 10, -1);
1873 gtk_container_add (GTK_CONTAINER (item), priv->presence_chooser);
1874 gtk_tool_item_set_is_important (item, TRUE);
1875 gtk_tool_item_set_expand (item, TRUE);
1876 gtk_toolbar_insert (GTK_TOOLBAR (priv->presence_toolbar), item, -1);
1878 /* Set up the throbber */
1879 priv->throbber = gtk_spinner_new ();
1880 gtk_widget_set_size_request (priv->throbber, 16, -1);
1881 gtk_widget_set_tooltip_text (priv->throbber, _("Show and edit accounts"));
1882 gtk_widget_set_events (priv->throbber, GDK_BUTTON_PRESS_MASK);
1883 g_signal_connect (priv->throbber, "button-press-event",
1884 G_CALLBACK (main_window_throbber_button_press_event_cb),
1886 gtk_widget_show (priv->throbber);
1888 item = gtk_tool_item_new ();
1889 gtk_container_set_border_width (GTK_CONTAINER (item), 6);
1890 gtk_toolbar_insert (GTK_TOOLBAR (priv->presence_toolbar), item, -1);
1891 gtk_container_add (GTK_CONTAINER (item), priv->throbber);
1892 priv->throbber_tool_item = GTK_WIDGET (item);
1894 /* XXX: this class is designed to live for the duration of the program,
1895 * so it's got a race condition between its signal handlers and its
1896 * finalization. The class is planned to be removed, so we won't fix
1897 * this before then. */
1898 priv->contact_manager = EMPATHY_CONTACT_LIST (
1899 empathy_contact_manager_dup_singleton ());
1900 individual_manager = empathy_individual_manager_dup_singleton ();
1901 priv->individual_store = empathy_individual_store_new (
1902 individual_manager);
1903 g_object_unref (individual_manager);
1905 /* For the moment, we disallow Persona drops onto the main contact list (e.g. from things such as
1906 * the EmpathyPersonaView in the linking dialogue). No code is hooked up to do anything on a Persona
1907 * drop, so allowing them would achieve nothing except confusion. */
1908 priv->individual_view = empathy_individual_view_new (
1909 priv->individual_store,
1910 EMPATHY_INDIVIDUAL_VIEW_FEATURE_ALL ^ EMPATHY_INDIVIDUAL_VIEW_FEATURE_PERSONA_DROP,
1911 EMPATHY_INDIVIDUAL_FEATURE_ALL);
1913 priv->butterfly_log_migration_members_changed_id = g_signal_connect (
1914 priv->contact_manager, "members-changed",
1915 G_CALLBACK (main_window_members_changed_cb), window);
1917 gtk_widget_show (GTK_WIDGET (priv->individual_view));
1918 gtk_container_add (GTK_CONTAINER (sw),
1919 GTK_WIDGET (priv->individual_view));
1920 g_signal_connect (priv->individual_view, "row-activated",
1921 G_CALLBACK (main_window_row_activated_cb),
1924 /* Set up search bar */
1925 priv->search_bar = empathy_live_search_new (
1926 GTK_WIDGET (priv->individual_view));
1927 empathy_individual_view_set_live_search (priv->individual_view,
1928 EMPATHY_LIVE_SEARCH (priv->search_bar));
1929 gtk_box_pack_start (GTK_BOX (priv->main_vbox), priv->search_bar,
1931 g_signal_connect_swapped (window, "map",
1932 G_CALLBACK (gtk_widget_grab_focus), priv->individual_view);
1934 /* Connect to proper signals to check if contact list is empty or not */
1935 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->individual_view));
1937 g_signal_connect (model, "row-inserted",
1938 G_CALLBACK (main_window_row_inserted_cb),
1940 g_signal_connect (model, "row-deleted",
1941 G_CALLBACK (main_window_row_deleted_cb),
1944 /* Load user-defined accelerators. */
1945 main_window_accels_load ();
1947 /* Set window size. */
1948 empathy_geometry_bind (GTK_WINDOW (window), GEOMETRY_NAME);
1950 /* Enable event handling */
1951 priv->call_observer = empathy_call_observer_dup_singleton ();
1952 priv->event_manager = empathy_event_manager_dup_singleton ();
1954 g_signal_connect (priv->event_manager, "event-added",
1955 G_CALLBACK (main_window_event_added_cb), window);
1956 g_signal_connect (priv->event_manager, "event-removed",
1957 G_CALLBACK (main_window_event_removed_cb), window);
1958 g_signal_connect (priv->account_manager, "account-validity-changed",
1959 G_CALLBACK (main_window_account_validity_changed_cb),
1961 g_signal_connect (priv->account_manager, "account-removed",
1962 G_CALLBACK (main_window_account_removed_cb),
1964 g_signal_connect (priv->account_manager, "account-disabled",
1965 G_CALLBACK (main_window_account_disabled_cb),
1968 l = empathy_event_manager_get_events (priv->event_manager);
1970 main_window_event_added_cb (priv->event_manager, l->data,
1975 /* Show offline ? */
1976 show_offline = g_settings_get_boolean (priv->gsettings_ui,
1977 EMPATHY_PREFS_UI_SHOW_OFFLINE);
1978 g_signal_connect (priv->gsettings_ui,
1979 "changed::" EMPATHY_PREFS_UI_SHOW_OFFLINE,
1980 G_CALLBACK (main_window_notify_show_offline_cb),
1981 show_offline_widget);
1983 gtk_toggle_action_set_active (show_offline_widget, show_offline);
1985 /* Show protocol ? */
1986 g_signal_connect (priv->gsettings_ui,
1987 "changed::" EMPATHY_PREFS_UI_SHOW_PROTOCOLS,
1988 G_CALLBACK (main_window_notify_show_protocols_cb),
1991 main_window_notify_show_protocols_cb (priv->gsettings_ui,
1992 EMPATHY_PREFS_UI_SHOW_PROTOCOLS,
1995 /* Sort by name / by status ? */
1996 g_signal_connect (priv->gsettings_contacts,
1997 "changed::" EMPATHY_PREFS_CONTACTS_SORT_CRITERIUM,
1998 G_CALLBACK (main_window_notify_sort_contact_cb),
2001 main_window_notify_sort_contact_cb (priv->gsettings_contacts,
2002 EMPATHY_PREFS_CONTACTS_SORT_CRITERIUM,
2005 /* Contacts list size */
2006 g_signal_connect (priv->gsettings_ui,
2007 "changed::" EMPATHY_PREFS_UI_COMPACT_CONTACT_LIST,
2008 G_CALLBACK (main_window_notify_contact_list_size_cb),
2010 g_signal_connect (priv->gsettings_ui,
2011 "changed::" EMPATHY_PREFS_UI_SHOW_AVATARS,
2012 G_CALLBACK (main_window_notify_contact_list_size_cb),
2015 main_window_notify_contact_list_size_cb (priv->gsettings_ui,
2016 EMPATHY_PREFS_UI_SHOW_AVATARS,
2021 empathy_main_window_dup (void)
2023 return g_object_new (EMPATHY_TYPE_MAIN_WINDOW, NULL);