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 GtkActionGroup *balance_action_group;
150 guint size_timeout_id;
152 /* reffed TpAccount* => visible GtkInfoBar* */
155 /* EmpathyEvent* => visible GtkInfoBar* */
158 /* stores a mapping from TpAccount to Handler ID to prevent
159 * to listen more than once to the status-changed signal */
160 GHashTable *status_changed_handlers;
162 /* Actions that are enabled when there are connected accounts */
163 GList *actions_connected;
165 /* The idle event source to migrate butterfly's logs */
166 guint butterfly_log_migration_members_changed_id;
170 main_window_flash_stop (EmpathyMainWindow *window)
172 EmpathyMainWindowPriv *priv = GET_PRIV (window);
174 if (priv->flash_timeout_id == 0) {
178 DEBUG ("Stop flashing");
179 g_source_remove (priv->flash_timeout_id);
180 priv->flash_timeout_id = 0;
181 priv->flash_on = FALSE;
187 EmpathyMainWindow *window;
191 main_window_flash_foreach (GtkTreeModel *model,
196 FlashForeachData *data = (FlashForeachData *) user_data;
197 FolksIndividual *individual;
198 EmpathyContact *contact;
199 const gchar *icon_name;
200 GtkTreePath *parent_path = NULL;
201 GtkTreeIter parent_iter;
202 GdkPixbuf *pixbuf = NULL;
204 gtk_tree_model_get (model, iter,
205 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL,
209 if (individual == NULL)
212 contact = empathy_contact_dup_from_folks_individual (individual);
213 if (contact != data->event->contact) {
214 tp_clear_object (&contact);
219 icon_name = data->event->icon_name;
220 pixbuf = empathy_pixbuf_from_icon_name (icon_name, GTK_ICON_SIZE_MENU);
222 pixbuf = empathy_individual_store_get_individual_status_icon (
223 GET_PRIV (data->window)->individual_store,
226 g_object_ref (pixbuf);
229 gtk_tree_store_set (GTK_TREE_STORE (model), iter,
230 EMPATHY_INDIVIDUAL_STORE_COL_ICON_STATUS, pixbuf,
233 /* To make sure the parent is shown correctly, we emit
234 * the row-changed signal on the parent so it prompts
235 * it to be refreshed by the filter func.
237 if (gtk_tree_model_iter_parent (model, &parent_iter, iter)) {
238 parent_path = gtk_tree_model_get_path (model, &parent_iter);
241 gtk_tree_model_row_changed (model, parent_path, &parent_iter);
242 gtk_tree_path_free (parent_path);
245 g_object_unref (individual);
246 tp_clear_object (&contact);
247 tp_clear_object (&pixbuf);
253 main_window_flash_cb (EmpathyMainWindow *window)
255 EmpathyMainWindowPriv *priv = GET_PRIV (window);
258 gboolean found_event = FALSE;
259 FlashForeachData data;
261 priv->flash_on = !priv->flash_on;
262 data.on = priv->flash_on;
263 model = GTK_TREE_MODEL (priv->individual_store);
265 events = empathy_event_manager_get_events (priv->event_manager);
266 for (l = events; l; l = l->next) {
267 data.event = l->data;
268 data.window = window;
269 if (!data.event->contact || !data.event->must_ack) {
274 gtk_tree_model_foreach (model,
275 main_window_flash_foreach,
280 main_window_flash_stop (window);
287 main_window_flash_start (EmpathyMainWindow *window)
289 EmpathyMainWindowPriv *priv = GET_PRIV (window);
291 if (priv->flash_timeout_id != 0) {
295 DEBUG ("Start flashing");
296 priv->flash_timeout_id = g_timeout_add (FLASH_TIMEOUT,
297 (GSourceFunc) main_window_flash_cb,
299 main_window_flash_cb (window);
303 main_window_remove_auth (EmpathyMainWindow *window,
306 EmpathyMainWindowPriv *priv = GET_PRIV (window);
307 GtkWidget *error_widget;
309 error_widget = g_hash_table_lookup (priv->auths, event);
310 if (error_widget != NULL) {
311 gtk_widget_destroy (error_widget);
312 g_hash_table_remove (priv->auths, event);
317 main_window_auth_add_clicked_cb (GtkButton *button,
318 EmpathyMainWindow *window)
322 event = g_object_get_data (G_OBJECT (button), "event");
324 empathy_event_approve (event);
326 main_window_remove_auth (window, event);
330 main_window_auth_close_clicked_cb (GtkButton *button,
331 EmpathyMainWindow *window)
335 event = g_object_get_data (G_OBJECT (button), "event");
337 empathy_event_decline (event);
338 main_window_remove_auth (window, event);
342 main_window_auth_display (EmpathyMainWindow *window,
345 EmpathyMainWindowPriv *priv = GET_PRIV (window);
346 TpAccount *account = event->account;
348 GtkWidget *content_area;
351 GtkWidget *add_button;
352 GtkWidget *close_button;
353 GtkWidget *action_area;
354 GtkWidget *action_table;
355 const gchar *icon_name;
358 if (g_hash_table_lookup (priv->auths, event) != NULL) {
362 info_bar = gtk_info_bar_new ();
363 gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_QUESTION);
365 gtk_widget_set_no_show_all (info_bar, TRUE);
366 gtk_box_pack_start (GTK_BOX (priv->auth_vbox), info_bar, FALSE, TRUE, 0);
367 gtk_widget_show (info_bar);
369 icon_name = tp_account_get_icon_name (account);
370 image = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_SMALL_TOOLBAR);
371 gtk_widget_show (image);
373 str = g_markup_printf_escaped ("<b>%s</b>\n%s",
374 tp_account_get_display_name (account),
375 _("Password required"));
377 label = gtk_label_new (str);
378 gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
379 gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_END);
380 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
381 gtk_widget_show (label);
385 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
386 gtk_box_pack_start (GTK_BOX (content_area), image, FALSE, FALSE, 0);
387 gtk_box_pack_start (GTK_BOX (content_area), label, TRUE, TRUE, 0);
389 image = gtk_image_new_from_stock (GTK_STOCK_ADD, GTK_ICON_SIZE_BUTTON);
390 add_button = gtk_button_new ();
391 gtk_button_set_image (GTK_BUTTON (add_button), image);
392 gtk_widget_set_tooltip_text (add_button, _("Provide Password"));
393 gtk_widget_show (add_button);
395 image = gtk_image_new_from_stock (GTK_STOCK_CLOSE, GTK_ICON_SIZE_BUTTON);
396 close_button = gtk_button_new ();
397 gtk_button_set_image (GTK_BUTTON (close_button), image);
398 gtk_widget_set_tooltip_text (close_button, _("Disconnect"));
399 gtk_widget_show (close_button);
401 action_table = gtk_table_new (1, 2, FALSE);
402 gtk_table_set_col_spacings (GTK_TABLE (action_table), 6);
403 gtk_widget_show (action_table);
405 action_area = gtk_info_bar_get_action_area (GTK_INFO_BAR (info_bar));
406 gtk_box_pack_start (GTK_BOX (action_area), action_table, FALSE, FALSE, 0);
408 gtk_table_attach (GTK_TABLE (action_table), add_button, 0, 1, 0, 1,
409 (GtkAttachOptions) (GTK_SHRINK),
410 (GtkAttachOptions) (GTK_SHRINK), 0, 0);
411 gtk_table_attach (GTK_TABLE (action_table), close_button, 1, 2, 0, 1,
412 (GtkAttachOptions) (GTK_SHRINK),
413 (GtkAttachOptions) (GTK_SHRINK), 0, 0);
415 g_object_set_data_full (G_OBJECT (info_bar),
416 "event", event, NULL);
417 g_object_set_data_full (G_OBJECT (add_button),
418 "event", event, NULL);
419 g_object_set_data_full (G_OBJECT (close_button),
420 "event", event, NULL);
422 g_signal_connect (add_button, "clicked",
423 G_CALLBACK (main_window_auth_add_clicked_cb),
425 g_signal_connect (close_button, "clicked",
426 G_CALLBACK (main_window_auth_close_clicked_cb),
429 gtk_widget_show (priv->auth_vbox);
431 g_hash_table_insert (priv->auths, event, info_bar);
435 main_window_event_added_cb (EmpathyEventManager *manager,
437 EmpathyMainWindow *window)
439 if (event->contact) {
440 main_window_flash_start (window);
441 } else if (event->type == EMPATHY_EVENT_TYPE_AUTH) {
442 main_window_auth_display (window, event);
447 main_window_event_removed_cb (EmpathyEventManager *manager,
449 EmpathyMainWindow *window)
451 EmpathyMainWindowPriv *priv = GET_PRIV (window);
452 FlashForeachData data;
454 if (event->type == EMPATHY_EVENT_TYPE_AUTH) {
455 main_window_remove_auth (window, event);
459 if (!event->contact) {
465 data.window = window;
466 gtk_tree_model_foreach (GTK_TREE_MODEL (priv->individual_store),
467 main_window_flash_foreach,
472 main_window_row_activated_cb (EmpathyContactListView *view,
474 GtkTreeViewColumn *col,
475 EmpathyMainWindow *window)
477 EmpathyMainWindowPriv *priv = GET_PRIV (window);
478 EmpathyContact *contact = NULL;
479 FolksIndividual *individual;
484 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->individual_view));
485 gtk_tree_model_get_iter (model, &iter, path);
487 gtk_tree_model_get (model, &iter,
488 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL,
492 if (individual != NULL) {
493 contact = empathy_contact_dup_from_folks_individual (individual);
500 /* If the contact has an event activate it, otherwise the
501 * default handler of row-activated will be called. */
502 events = empathy_event_manager_get_events (priv->event_manager);
503 for (l = events; l; l = l->next) {
504 EmpathyEvent *event = l->data;
506 if (event->contact == contact) {
507 DEBUG ("Activate event");
508 empathy_event_activate (event);
510 /* We don't want the default handler of this signal
511 * (e.g. open a chat) */
512 g_signal_stop_emission_by_name (view, "row-activated");
517 g_object_unref (contact);
519 tp_clear_object (&individual);
523 main_window_row_deleted_cb (GtkTreeModel *model,
525 EmpathyMainWindow *window)
527 EmpathyMainWindowPriv *priv = GET_PRIV (window);
528 GtkTreeIter help_iter;
530 if (!gtk_tree_model_get_iter_first (model, &help_iter)) {
533 if (empathy_individual_view_is_searching (
534 priv->individual_view)) {
537 tmp = g_strdup_printf ("<b><span size='xx-large'>%s</span></b>",
538 _("No match found"));
540 gtk_label_set_markup (GTK_LABEL (priv->no_entry_label), tmp);
543 gtk_label_set_line_wrap (GTK_LABEL (priv->no_entry_label),
546 gtk_notebook_set_current_page (
547 GTK_NOTEBOOK (priv->notebook), PAGE_NO_MATCH);
553 main_window_row_inserted_cb (GtkTreeModel *model,
556 EmpathyMainWindow *window)
558 EmpathyMainWindowPriv *priv = GET_PRIV (window);
562 gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook),
564 gtk_widget_grab_focus (GTK_WIDGET (priv->individual_view));
569 main_window_remove_error (EmpathyMainWindow *window,
572 EmpathyMainWindowPriv *priv = GET_PRIV (window);
573 GtkWidget *error_widget;
575 error_widget = g_hash_table_lookup (priv->errors, account);
576 if (error_widget != NULL) {
577 gtk_widget_destroy (error_widget);
578 g_hash_table_remove (priv->errors, account);
583 main_window_account_disabled_cb (TpAccountManager *manager,
585 EmpathyMainWindow *window)
587 main_window_remove_error (window, account);
591 main_window_error_retry_clicked_cb (GtkButton *button,
592 EmpathyMainWindow *window)
596 account = g_object_get_data (G_OBJECT (button), "account");
597 tp_account_reconnect_async (account, NULL, NULL);
599 main_window_remove_error (window, account);
603 main_window_error_edit_clicked_cb (GtkButton *button,
604 EmpathyMainWindow *window)
608 account = g_object_get_data (G_OBJECT (button), "account");
610 empathy_accounts_dialog_show_application (
611 gtk_widget_get_screen (GTK_WIDGET (button)),
612 account, FALSE, FALSE);
614 main_window_remove_error (window, account);
618 main_window_error_close_clicked_cb (GtkButton *button,
619 EmpathyMainWindow *window)
623 account = g_object_get_data (G_OBJECT (button), "account");
624 main_window_remove_error (window, account);
628 main_window_error_display (EmpathyMainWindow *window,
631 EmpathyMainWindowPriv *priv = GET_PRIV (window);
633 GtkWidget *content_area;
636 GtkWidget *retry_button;
637 GtkWidget *edit_button;
638 GtkWidget *close_button;
639 GtkWidget *action_area;
640 GtkWidget *action_table;
642 const gchar *icon_name;
643 const gchar *error_message;
644 gboolean user_requested;
647 empathy_account_get_error_message (account, &user_requested);
649 if (user_requested) {
653 str = g_markup_printf_escaped ("<b>%s</b>\n%s",
654 tp_account_get_display_name (account),
657 info_bar = g_hash_table_lookup (priv->errors, account);
659 label = g_object_get_data (G_OBJECT (info_bar), "label");
661 /* Just set the latest error and return */
662 gtk_label_set_markup (GTK_LABEL (label), str);
668 info_bar = gtk_info_bar_new ();
669 gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_ERROR);
671 gtk_widget_set_no_show_all (info_bar, TRUE);
672 gtk_box_pack_start (GTK_BOX (priv->errors_vbox), info_bar, FALSE, TRUE, 0);
673 gtk_widget_show (info_bar);
675 icon_name = tp_account_get_icon_name (account);
676 image = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_SMALL_TOOLBAR);
677 gtk_widget_show (image);
679 label = gtk_label_new (str);
680 gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
681 gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_END);
682 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
683 gtk_widget_show (label);
686 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
687 gtk_box_pack_start (GTK_BOX (content_area), image, FALSE, FALSE, 0);
688 gtk_box_pack_start (GTK_BOX (content_area), label, TRUE, TRUE, 0);
690 image = gtk_image_new_from_stock (GTK_STOCK_REFRESH, GTK_ICON_SIZE_BUTTON);
691 retry_button = gtk_button_new ();
692 gtk_button_set_image (GTK_BUTTON (retry_button), image);
693 gtk_widget_set_tooltip_text (retry_button, _("Reconnect"));
694 gtk_widget_show (retry_button);
696 image = gtk_image_new_from_stock (GTK_STOCK_EDIT, GTK_ICON_SIZE_BUTTON);
697 edit_button = gtk_button_new ();
698 gtk_button_set_image (GTK_BUTTON (edit_button), image);
699 gtk_widget_set_tooltip_text (edit_button, _("Edit Account"));
700 gtk_widget_show (edit_button);
702 image = gtk_image_new_from_stock (GTK_STOCK_CLOSE, GTK_ICON_SIZE_BUTTON);
703 close_button = gtk_button_new ();
704 gtk_button_set_image (GTK_BUTTON (close_button), image);
705 gtk_widget_set_tooltip_text (close_button, _("Close"));
706 gtk_widget_show (close_button);
708 action_table = gtk_table_new (1, 3, FALSE);
709 gtk_table_set_col_spacings (GTK_TABLE (action_table), 2);
710 gtk_widget_show (action_table);
712 action_area = gtk_info_bar_get_action_area (GTK_INFO_BAR (info_bar));
713 gtk_box_pack_start (GTK_BOX (action_area), action_table, FALSE, FALSE, 0);
715 gtk_table_attach (GTK_TABLE (action_table), retry_button, 0, 1, 0, 1,
716 (GtkAttachOptions) (GTK_SHRINK),
717 (GtkAttachOptions) (GTK_SHRINK), 0, 0);
718 gtk_table_attach (GTK_TABLE (action_table), edit_button, 1, 2, 0, 1,
719 (GtkAttachOptions) (GTK_SHRINK),
720 (GtkAttachOptions) (GTK_SHRINK), 0, 0);
721 gtk_table_attach (GTK_TABLE (action_table), close_button, 2, 3, 0, 1,
722 (GtkAttachOptions) (GTK_SHRINK),
723 (GtkAttachOptions) (GTK_SHRINK), 0, 0);
725 g_object_set_data (G_OBJECT (info_bar), "label", label);
726 g_object_set_data_full (G_OBJECT (info_bar),
727 "account", g_object_ref (account),
729 g_object_set_data_full (G_OBJECT (edit_button),
730 "account", g_object_ref (account),
732 g_object_set_data_full (G_OBJECT (close_button),
733 "account", g_object_ref (account),
735 g_object_set_data_full (G_OBJECT (retry_button),
736 "account", g_object_ref (account),
739 g_signal_connect (edit_button, "clicked",
740 G_CALLBACK (main_window_error_edit_clicked_cb),
742 g_signal_connect (close_button, "clicked",
743 G_CALLBACK (main_window_error_close_clicked_cb),
745 g_signal_connect (retry_button, "clicked",
746 G_CALLBACK (main_window_error_retry_clicked_cb),
749 gtk_widget_set_tooltip_text (priv->errors_vbox, error_message);
750 gtk_widget_show (priv->errors_vbox);
752 g_hash_table_insert (priv->errors, g_object_ref (account), info_bar);
756 main_window_update_status (EmpathyMainWindow *window)
758 EmpathyMainWindowPriv *priv = GET_PRIV (window);
759 gboolean connected, connecting;
762 connected = empathy_account_manager_get_accounts_connected (&connecting);
764 /* Update the spinner state */
766 gtk_spinner_start (GTK_SPINNER (priv->throbber));
767 gtk_widget_show (priv->throbber_tool_item);
769 gtk_spinner_stop (GTK_SPINNER (priv->throbber));
770 gtk_widget_hide (priv->throbber_tool_item);
773 /* Update widgets sensibility */
774 for (l = priv->actions_connected; l; l = l->next) {
775 gtk_action_set_sensitive (l->data, connected);
778 /* Update favourite rooms sensitivity */
779 children = gtk_container_get_children (GTK_CONTAINER (priv->room_menu));
780 for (l = children; l != NULL; l = l->next) {
781 if (g_object_get_data (G_OBJECT (l->data), "is_favorite") != NULL) {
782 gtk_widget_set_sensitive (GTK_WIDGET (l->data), connected);
785 g_list_free (children);
789 main_window_account_to_action_name (TpAccount *account)
793 /* action names can't have '/' in them, replace it with '.' */
794 r = g_strdup (tp_account_get_path_suffix (account));
795 r = g_strdelimit (r, "/", '.');
801 main_window_balance_activate_cb (GtkAction *action,
802 EmpathyMainWindow *window)
806 uri = g_object_get_data (G_OBJECT (action), "manage-credit-uri");
808 if (!tp_str_empty (uri)) {
809 DEBUG ("Top-up credit URI: %s", uri);
810 empathy_url_show (GTK_WIDGET (window), uri);
812 DEBUG ("unknown protocol for top-up");
817 main_window_balance_update_balance (GtkAction *action,
818 GValueArray *balance)
820 TpAccount *account = g_object_get_data (G_OBJECT (action), "account");
822 guint scale = G_MAXINT32;
823 const char *currency = "";
827 tp_value_array_unpack (balance, 3,
833 scale == G_MAXINT32 &&
834 tp_str_empty (currency)) {
835 /* unknown balance */
836 str = g_strdup_printf ("%s (--)",
837 tp_account_get_display_name (account));
839 char *money = empathy_format_currency (amount, scale, currency);
841 str = g_strdup_printf ("%s (%s %s)",
842 tp_account_get_display_name (account),
847 gtk_action_set_label (action, str);
852 main_window_setup_balance_got_balance_props (TpProxy *conn,
854 const GError *in_error,
858 GValueArray *balance = NULL;
861 if (in_error != NULL) {
862 DEBUG ("Failed to get account balance properties: %s",
867 balance = tp_asv_get_boxed (props, "AccountBalance",
868 TP_STRUCT_TYPE_CURRENCY_AMOUNT);
869 uri = tp_asv_get_string (props, "ManageCreditURI");
871 g_object_set_data_full (action, "manage-credit-uri",
872 g_strdup (uri), g_free);
873 gtk_action_set_sensitive (GTK_ACTION (action), !tp_str_empty (uri));
876 main_window_balance_update_balance (GTK_ACTION (action), balance);
880 main_window_balance_changed_cb (TpConnection *conn,
881 const GValueArray *balance,
885 main_window_balance_update_balance (GTK_ACTION (action),
886 (GValueArray *) balance);
890 main_window_setup_balance_conn_ready (GObject *conn,
891 GAsyncResult *result,
894 EmpathyMainWindow *window = user_data;
895 EmpathyMainWindowPriv *priv = GET_PRIV (window);
896 TpAccount *account = g_object_get_data (conn, "account");
900 GError *error = NULL;
902 if (!tp_proxy_prepare_finish (conn, result, &error)) {
903 DEBUG ("Failed to prepare connection: %s", error->message);
905 g_error_free (error);
909 if (!tp_proxy_has_interface_by_id (conn,
910 TP_IFACE_QUARK_CONNECTION_INTERFACE_BALANCE)) {
914 DEBUG ("Setting up balance for acct: %s",
915 tp_account_get_display_name (account));
917 if (priv->balance_action_group == NULL) {
918 /* create the action group */
919 priv->balance_action_group =
920 gtk_action_group_new ("balance-action-group");
922 gtk_ui_manager_insert_action_group (priv->ui_manager,
923 priv->balance_action_group, -1);
926 /* create the action */
927 name = main_window_account_to_action_name (account);
928 action = gtk_action_new (name,
929 tp_account_get_display_name (account),
930 _("Top up account credit"),
931 tp_account_get_icon_name (account));
933 g_object_set_data (G_OBJECT (action), "account", account);
934 g_signal_connect (action, "activate",
935 G_CALLBACK (main_window_balance_activate_cb), window);
937 gtk_action_group_add_action (priv->balance_action_group, action);
938 g_object_unref (action);
940 ui = g_strdup_printf (
942 " <menubar name='menubar'>"
943 " <menu action='view'>"
944 " <placeholder name='view_balance_placeholder'>"
945 " <menuitem action='%s'/>"
952 merge_id = gtk_ui_manager_add_ui_from_string (priv->ui_manager,
954 g_object_set_data (G_OBJECT (action),
955 "merge-id", GUINT_TO_POINTER (merge_id));
961 DEBUG ("Failed to add balance UI for %s: %s",
962 tp_account_get_display_name (account),
964 g_error_free (error);
968 /* request the current balance and monitor for any changes */
969 tp_cli_dbus_properties_call_get_all (conn, -1,
970 TP_IFACE_CONNECTION_INTERFACE_BALANCE,
971 main_window_setup_balance_got_balance_props,
972 window, NULL, G_OBJECT (action));
974 tp_cli_connection_interface_balance_connect_to_balance_changed (
975 TP_CONNECTION (conn), main_window_balance_changed_cb,
976 window, NULL, G_OBJECT (action), NULL);
980 main_window_setup_balance (EmpathyMainWindow *window,
983 TpConnection *conn = tp_account_get_connection (account);
988 /* need to prepare the connection:
989 * store the account on the connection */
990 g_object_set_data (G_OBJECT (conn), "account", account);
991 tp_proxy_prepare_async (conn, NULL,
992 main_window_setup_balance_conn_ready, window);
996 main_window_connection_changed_cb (TpAccount *account,
1000 gchar *dbus_error_name,
1001 GHashTable *details,
1002 EmpathyMainWindow *window)
1004 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1006 main_window_update_status (window);
1008 if (current == TP_CONNECTION_STATUS_DISCONNECTED &&
1009 reason != TP_CONNECTION_STATUS_REASON_REQUESTED) {
1010 main_window_error_display (window, account);
1013 if (current == TP_CONNECTION_STATUS_DISCONNECTED) {
1014 empathy_sound_manager_play (priv->sound_mgr, GTK_WIDGET (window),
1015 EMPATHY_SOUND_ACCOUNT_DISCONNECTED);
1017 /* remove balance action if required */
1018 if (priv->balance_action_group != NULL) {
1022 name = main_window_account_to_action_name (account);
1024 action = gtk_action_group_get_action (
1025 priv->balance_action_group, name);
1027 if (action != NULL) {
1030 DEBUG ("Removing action");
1032 merge_id = GPOINTER_TO_UINT (g_object_get_data (
1036 gtk_ui_manager_remove_ui (priv->ui_manager,
1038 gtk_action_group_remove_action (
1039 priv->balance_action_group, action);
1046 if (current == TP_CONNECTION_STATUS_CONNECTED) {
1047 empathy_sound_manager_play (priv->sound_mgr, GTK_WIDGET (window),
1048 EMPATHY_SOUND_ACCOUNT_CONNECTED);
1050 /* Account connected without error, remove error message if any */
1051 main_window_remove_error (window, account);
1052 main_window_setup_balance (window, account);
1057 main_window_accels_load (void)
1061 filename = g_build_filename (g_get_user_config_dir (), PACKAGE_NAME, ACCELS_FILENAME, NULL);
1062 if (g_file_test (filename, G_FILE_TEST_EXISTS)) {
1063 DEBUG ("Loading from:'%s'", filename);
1064 gtk_accel_map_load (filename);
1071 main_window_accels_save (void)
1074 gchar *file_with_path;
1076 dir = g_build_filename (g_get_user_config_dir (), PACKAGE_NAME, NULL);
1077 g_mkdir_with_parents (dir, S_IRUSR | S_IWUSR | S_IXUSR);
1078 file_with_path = g_build_filename (dir, ACCELS_FILENAME, NULL);
1081 DEBUG ("Saving to:'%s'", file_with_path);
1082 gtk_accel_map_save (file_with_path);
1084 g_free (file_with_path);
1088 empathy_main_window_finalize (GObject *window)
1090 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1091 GHashTableIter iter;
1092 gpointer key, value;
1094 /* Save user-defined accelerators. */
1095 main_window_accels_save ();
1097 g_list_free (priv->actions_connected);
1099 g_object_unref (priv->account_manager);
1100 g_object_unref (priv->individual_store);
1101 g_object_unref (priv->contact_manager);
1102 g_object_unref (priv->sound_mgr);
1103 g_hash_table_destroy (priv->errors);
1104 g_hash_table_destroy (priv->auths);
1106 /* disconnect all handlers of status-changed signal */
1107 g_hash_table_iter_init (&iter, priv->status_changed_handlers);
1108 while (g_hash_table_iter_next (&iter, &key, &value))
1109 g_signal_handler_disconnect (TP_ACCOUNT (key),
1110 GPOINTER_TO_UINT (value));
1112 g_hash_table_destroy (priv->status_changed_handlers);
1114 g_signal_handlers_disconnect_by_func (priv->event_manager,
1115 main_window_event_added_cb,
1117 g_signal_handlers_disconnect_by_func (priv->event_manager,
1118 main_window_event_removed_cb,
1120 g_object_unref (priv->call_observer);
1121 g_object_unref (priv->event_manager);
1122 g_object_unref (priv->ui_manager);
1123 g_object_unref (priv->chatroom_manager);
1125 g_object_unref (priv->gsettings_ui);
1126 g_object_unref (priv->gsettings_contacts);
1128 G_OBJECT_CLASS (empathy_main_window_parent_class)->finalize (window);
1132 main_window_key_press_event_cb (GtkWidget *window,
1136 EmpathyChatManager *chat_manager;
1138 if (event->keyval == GDK_KEY_T
1139 && event->state & GDK_SHIFT_MASK
1140 && event->state & GDK_CONTROL_MASK) {
1141 chat_manager = empathy_chat_manager_dup_singleton ();
1142 empathy_chat_manager_undo_closed_chat (chat_manager);
1143 g_object_unref (chat_manager);
1149 main_window_chat_quit_cb (GtkAction *action,
1150 EmpathyMainWindow *window)
1156 main_window_view_history_cb (GtkAction *action,
1157 EmpathyMainWindow *window)
1159 empathy_log_window_show (NULL, NULL, FALSE, GTK_WINDOW (window));
1163 main_window_chat_new_message_cb (GtkAction *action,
1164 EmpathyMainWindow *window)
1166 empathy_new_message_dialog_show (GTK_WINDOW (window));
1170 main_window_chat_new_call_cb (GtkAction *action,
1171 EmpathyMainWindow *window)
1173 empathy_new_call_dialog_show (GTK_WINDOW (window));
1177 main_window_chat_add_contact_cb (GtkAction *action,
1178 EmpathyMainWindow *window)
1180 empathy_new_individual_dialog_show (GTK_WINDOW (window));
1184 main_window_chat_search_contacts_cb (GtkAction *action,
1185 EmpathyMainWindow *window)
1187 GtkWidget *dialog = empathy_contact_search_dialog_new (
1188 GTK_WINDOW (window));
1189 gtk_widget_show (dialog);
1193 main_window_view_show_ft_manager (GtkAction *action,
1194 EmpathyMainWindow *window)
1196 empathy_ft_manager_show ();
1200 main_window_view_show_offline_cb (GtkToggleAction *action,
1201 EmpathyMainWindow *window)
1203 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1206 current = gtk_toggle_action_get_active (action);
1207 g_settings_set_boolean (priv->gsettings_ui,
1208 EMPATHY_PREFS_UI_SHOW_OFFLINE,
1211 empathy_individual_view_set_show_offline (priv->individual_view,
1216 main_window_notify_sort_contact_cb (GSettings *gsettings,
1218 EmpathyMainWindow *window)
1220 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1223 str = g_settings_get_string (gsettings, key);
1227 GEnumClass *enum_class;
1228 GEnumValue *enum_value;
1230 type = empathy_individual_store_sort_get_type ();
1231 enum_class = G_ENUM_CLASS (g_type_class_peek (type));
1232 enum_value = g_enum_get_value_by_nick (enum_class, str);
1234 /* By changing the value of the GtkRadioAction,
1235 it emits a signal that calls main_window_view_sort_contacts_cb
1236 which updates the contacts list */
1237 gtk_radio_action_set_current_value (priv->sort_by_name,
1240 g_warning ("Wrong value for sort_criterium configuration : %s", str);
1247 main_window_view_sort_contacts_cb (GtkRadioAction *action,
1248 GtkRadioAction *current,
1249 EmpathyMainWindow *window)
1251 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1252 EmpathyContactListStoreSort value;
1255 GEnumClass *enum_class;
1256 GEnumValue *enum_value;
1258 value = gtk_radio_action_get_current_value (action);
1259 group = gtk_radio_action_get_group (action);
1261 /* Get string from index */
1262 type = empathy_individual_store_sort_get_type ();
1263 enum_class = G_ENUM_CLASS (g_type_class_peek (type));
1264 enum_value = g_enum_get_value (enum_class, g_slist_index (group, current));
1267 g_warning ("No GEnumValue for EmpathyContactListSort with GtkRadioAction index:%d",
1268 g_slist_index (group, action));
1270 g_settings_set_string (priv->gsettings_contacts,
1271 EMPATHY_PREFS_CONTACTS_SORT_CRITERIUM,
1272 enum_value->value_nick);
1274 empathy_individual_store_set_sort_criterium (priv->individual_store,
1279 main_window_view_show_protocols_cb (GtkToggleAction *action,
1280 EmpathyMainWindow *window)
1282 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1285 value = gtk_toggle_action_get_active (action);
1287 g_settings_set_boolean (priv->gsettings_ui,
1288 EMPATHY_PREFS_UI_SHOW_PROTOCOLS,
1290 empathy_individual_store_set_show_protocols (priv->individual_store,
1294 /* Matches GtkRadioAction values set in empathy-main-window.ui */
1295 #define CONTACT_LIST_NORMAL_SIZE_WITH_AVATARS 0
1296 #define CONTACT_LIST_NORMAL_SIZE 1
1297 #define CONTACT_LIST_COMPACT_SIZE 2
1300 main_window_view_contacts_list_size_cb (GtkRadioAction *action,
1301 GtkRadioAction *current,
1302 EmpathyMainWindow *window)
1304 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1305 GSettings *gsettings_ui;
1308 value = gtk_radio_action_get_current_value (action);
1309 /* create a new GSettings, so we can delay the setting until both
1311 gsettings_ui = g_settings_new (EMPATHY_PREFS_UI_SCHEMA);
1313 DEBUG ("radio button toggled, value = %i", value);
1315 g_settings_delay (gsettings_ui);
1316 g_settings_set_boolean (gsettings_ui,
1317 EMPATHY_PREFS_UI_SHOW_AVATARS,
1318 value == CONTACT_LIST_NORMAL_SIZE_WITH_AVATARS);
1320 g_settings_set_boolean (gsettings_ui,
1321 EMPATHY_PREFS_UI_COMPACT_CONTACT_LIST,
1322 value == CONTACT_LIST_COMPACT_SIZE);
1323 g_settings_apply (gsettings_ui);
1325 /* FIXME: these enums probably have the wrong namespace */
1326 empathy_individual_store_set_show_avatars (priv->individual_store,
1327 value == CONTACT_LIST_NORMAL_SIZE_WITH_AVATARS);
1328 empathy_individual_store_set_is_compact (priv->individual_store,
1329 value == CONTACT_LIST_COMPACT_SIZE);
1331 g_object_unref (gsettings_ui);
1334 static void main_window_notify_show_protocols_cb (GSettings *gsettings,
1336 EmpathyMainWindow *window)
1338 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1340 gtk_toggle_action_set_active (priv->show_protocols,
1341 g_settings_get_boolean (gsettings,
1342 EMPATHY_PREFS_UI_SHOW_PROTOCOLS));
1347 main_window_notify_contact_list_size_cb (GSettings *gsettings,
1349 EmpathyMainWindow *window)
1351 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1354 if (g_settings_get_boolean (gsettings,
1355 EMPATHY_PREFS_UI_COMPACT_CONTACT_LIST)) {
1356 value = CONTACT_LIST_COMPACT_SIZE;
1357 } else if (g_settings_get_boolean (gsettings,
1358 EMPATHY_PREFS_UI_SHOW_AVATARS)) {
1359 value = CONTACT_LIST_NORMAL_SIZE_WITH_AVATARS;
1361 value = CONTACT_LIST_NORMAL_SIZE;
1364 DEBUG ("setting changed, value = %i", value);
1366 /* By changing the value of the GtkRadioAction,
1367 it emits a signal that calls main_window_view_contacts_list_size_cb
1368 which updates the contacts list */
1369 gtk_radio_action_set_current_value (priv->normal_with_avatars, value);
1373 main_window_edit_search_contacts_cb (GtkCheckMenuItem *item,
1374 EmpathyMainWindow *window)
1376 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1378 empathy_individual_view_start_search (priv->individual_view);
1382 main_window_view_show_map_cb (GtkCheckMenuItem *item,
1383 EmpathyMainWindow *window)
1385 #ifdef HAVE_LIBCHAMPLAIN
1386 empathy_map_view_show ();
1391 join_chatroom (EmpathyChatroom *chatroom,
1397 account = empathy_chatroom_get_account (chatroom);
1398 room = empathy_chatroom_get_room (chatroom);
1400 DEBUG ("Requesting channel for '%s'", room);
1401 empathy_join_muc (account, room, timestamp);
1407 EmpathyChatroom *chatroom;
1411 } join_fav_account_sig_ctx;
1413 static join_fav_account_sig_ctx *
1414 join_fav_account_sig_ctx_new (TpAccount *account,
1415 EmpathyChatroom *chatroom,
1418 join_fav_account_sig_ctx *ctx = g_slice_new0 (
1419 join_fav_account_sig_ctx);
1421 ctx->account = g_object_ref (account);
1422 ctx->chatroom = g_object_ref (chatroom);
1423 ctx->timestamp = timestamp;
1428 join_fav_account_sig_ctx_free (join_fav_account_sig_ctx *ctx)
1430 g_object_unref (ctx->account);
1431 g_object_unref (ctx->chatroom);
1432 g_slice_free (join_fav_account_sig_ctx, ctx);
1436 account_status_changed_cb (TpAccount *account,
1437 TpConnectionStatus old_status,
1438 TpConnectionStatus new_status,
1440 gchar *dbus_error_name,
1441 GHashTable *details,
1444 join_fav_account_sig_ctx *ctx = user_data;
1446 switch (new_status) {
1447 case TP_CONNECTION_STATUS_DISCONNECTED:
1448 /* Don't wait any longer */
1452 case TP_CONNECTION_STATUS_CONNECTING:
1456 case TP_CONNECTION_STATUS_CONNECTED:
1457 /* We can join the room */
1461 g_assert_not_reached ();
1464 join_chatroom (ctx->chatroom, ctx->timestamp);
1467 g_source_remove (ctx->timeout);
1468 g_signal_handler_disconnect (account, ctx->sig_id);
1471 #define JOIN_FAVORITE_TIMEOUT 5
1474 join_favorite_timeout_cb (gpointer data)
1476 join_fav_account_sig_ctx *ctx = data;
1478 /* stop waiting for joining the favorite room */
1479 g_signal_handler_disconnect (ctx->account, ctx->sig_id);
1484 main_window_favorite_chatroom_join (EmpathyChatroom *chatroom)
1488 account = empathy_chatroom_get_account (chatroom);
1489 if (tp_account_get_connection_status (account, NULL) !=
1490 TP_CONNECTION_STATUS_CONNECTED) {
1491 join_fav_account_sig_ctx *ctx;
1493 ctx = join_fav_account_sig_ctx_new (account, chatroom,
1494 gtk_get_current_event_time ());
1496 ctx->sig_id = g_signal_connect_data (account, "status-changed",
1497 G_CALLBACK (account_status_changed_cb), ctx,
1498 (GClosureNotify) join_fav_account_sig_ctx_free, 0);
1500 ctx->timeout = g_timeout_add_seconds (JOIN_FAVORITE_TIMEOUT,
1501 join_favorite_timeout_cb, ctx);
1505 join_chatroom (chatroom, gtk_get_current_event_time ());
1509 main_window_favorite_chatroom_menu_activate_cb (GtkMenuItem *menu_item,
1510 EmpathyChatroom *chatroom)
1512 main_window_favorite_chatroom_join (chatroom);
1516 main_window_favorite_chatroom_menu_add (EmpathyMainWindow *window,
1517 EmpathyChatroom *chatroom)
1519 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1520 GtkWidget *menu_item;
1523 if (g_object_get_data (G_OBJECT (chatroom), "menu_item")) {
1527 name = empathy_chatroom_get_name (chatroom);
1528 menu_item = gtk_menu_item_new_with_label (name);
1529 g_object_set_data (G_OBJECT (menu_item), "is_favorite",
1530 GUINT_TO_POINTER (TRUE));
1532 g_object_set_data (G_OBJECT (chatroom), "menu_item", menu_item);
1533 g_signal_connect (menu_item, "activate",
1534 G_CALLBACK (main_window_favorite_chatroom_menu_activate_cb),
1537 gtk_menu_shell_insert (GTK_MENU_SHELL (priv->room_menu),
1540 gtk_widget_show (menu_item);
1544 main_window_favorite_chatroom_menu_added_cb (EmpathyChatroomManager *manager,
1545 EmpathyChatroom *chatroom,
1546 EmpathyMainWindow *window)
1548 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1550 main_window_favorite_chatroom_menu_add (window, chatroom);
1551 gtk_widget_show (priv->room_separator);
1552 gtk_action_set_sensitive (priv->room_join_favorites, TRUE);
1556 main_window_favorite_chatroom_menu_removed_cb (EmpathyChatroomManager *manager,
1557 EmpathyChatroom *chatroom,
1558 EmpathyMainWindow *window)
1560 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1561 GtkWidget *menu_item;
1564 menu_item = g_object_get_data (G_OBJECT (chatroom), "menu_item");
1565 g_object_set_data (G_OBJECT (chatroom), "menu_item", NULL);
1566 gtk_widget_destroy (menu_item);
1568 chatrooms = empathy_chatroom_manager_get_chatrooms (priv->chatroom_manager, NULL);
1570 gtk_widget_show (priv->room_separator);
1572 gtk_widget_hide (priv->room_separator);
1575 gtk_action_set_sensitive (priv->room_join_favorites, chatrooms != NULL);
1576 g_list_free (chatrooms);
1580 main_window_favorite_chatroom_menu_setup (EmpathyMainWindow *window)
1582 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1583 GList *chatrooms, *l;
1586 priv->chatroom_manager = empathy_chatroom_manager_dup_singleton (NULL);
1587 chatrooms = empathy_chatroom_manager_get_chatrooms (
1588 priv->chatroom_manager, NULL);
1589 room = gtk_ui_manager_get_widget (priv->ui_manager,
1591 priv->room_menu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (room));
1592 priv->room_separator = gtk_ui_manager_get_widget (priv->ui_manager,
1593 "/menubar/room/room_separator");
1595 for (l = chatrooms; l; l = l->next) {
1596 main_window_favorite_chatroom_menu_add (window, l->data);
1600 gtk_widget_hide (priv->room_separator);
1603 gtk_action_set_sensitive (priv->room_join_favorites, chatrooms != NULL);
1605 g_signal_connect (priv->chatroom_manager, "chatroom-added",
1606 G_CALLBACK (main_window_favorite_chatroom_menu_added_cb),
1608 g_signal_connect (priv->chatroom_manager, "chatroom-removed",
1609 G_CALLBACK (main_window_favorite_chatroom_menu_removed_cb),
1612 g_list_free (chatrooms);
1616 main_window_room_join_new_cb (GtkAction *action,
1617 EmpathyMainWindow *window)
1619 empathy_new_chatroom_dialog_show (GTK_WINDOW (window));
1623 main_window_room_join_favorites_cb (GtkAction *action,
1624 EmpathyMainWindow *window)
1626 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1627 GList *chatrooms, *l;
1629 chatrooms = empathy_chatroom_manager_get_chatrooms (priv->chatroom_manager, NULL);
1630 for (l = chatrooms; l; l = l->next) {
1631 main_window_favorite_chatroom_join (l->data);
1633 g_list_free (chatrooms);
1637 main_window_room_manage_favorites_cb (GtkAction *action,
1638 EmpathyMainWindow *window)
1640 empathy_chatrooms_window_show (GTK_WINDOW (window));
1644 main_window_edit_cb (GtkAction *action,
1645 EmpathyMainWindow *window)
1647 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1650 /* FIXME: It should use the UIManager to merge the contact/group submenu */
1651 submenu = empathy_individual_view_get_individual_menu (
1652 priv->individual_view);
1657 item = GTK_MENU_ITEM (priv->edit_context);
1658 label = gtk_bin_get_child (GTK_BIN (item));
1659 gtk_label_set_text (GTK_LABEL (label), _("Contact"));
1661 gtk_widget_show (priv->edit_context);
1662 gtk_widget_show (priv->edit_context_separator);
1664 gtk_menu_item_set_submenu (item, submenu);
1669 submenu = empathy_individual_view_get_group_menu (
1670 priv->individual_view);
1675 item = GTK_MENU_ITEM (priv->edit_context);
1676 label = gtk_bin_get_child (GTK_BIN (item));
1677 gtk_label_set_text (GTK_LABEL (label), _("Group"));
1679 gtk_widget_show (priv->edit_context);
1680 gtk_widget_show (priv->edit_context_separator);
1682 gtk_menu_item_set_submenu (item, submenu);
1687 gtk_widget_hide (priv->edit_context);
1688 gtk_widget_hide (priv->edit_context_separator);
1694 main_window_edit_accounts_cb (GtkAction *action,
1695 EmpathyMainWindow *window)
1697 empathy_accounts_dialog_show_application (gdk_screen_get_default (),
1698 NULL, FALSE, FALSE);
1702 main_window_edit_personal_information_cb (GtkAction *action,
1703 EmpathyMainWindow *window)
1705 empathy_contact_personal_dialog_show (GTK_WINDOW (window));
1709 main_window_edit_blocked_contacts_cb (GtkAction *action,
1710 EmpathyMainWindow *window)
1714 dialog = empathy_contact_blocking_dialog_new (GTK_WINDOW (window));
1715 gtk_widget_show (dialog);
1716 g_signal_connect (dialog, "response",
1717 G_CALLBACK (gtk_widget_destroy), NULL);
1721 main_window_edit_preferences_cb (GtkAction *action,
1722 EmpathyMainWindow *window)
1724 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1726 if (priv->preferences == NULL) {
1727 priv->preferences = empathy_preferences_new (GTK_WINDOW (window));
1728 g_object_add_weak_pointer (G_OBJECT (priv->preferences),
1729 (gpointer) &priv->preferences);
1731 gtk_widget_show (priv->preferences);
1733 gtk_window_present (GTK_WINDOW (priv->preferences));
1738 main_window_help_about_cb (GtkAction *action,
1739 EmpathyMainWindow *window)
1741 empathy_about_dialog_new (GTK_WINDOW (window));
1745 main_window_help_debug_cb (GtkAction *action,
1746 EmpathyMainWindow *window)
1748 GdkDisplay *display;
1749 GError *error = NULL;
1752 GdkAppLaunchContext *context = NULL;
1754 /* Try to run from source directory if possible */
1755 path = g_build_filename (g_getenv ("EMPATHY_SRCDIR"), "src",
1756 "empathy-debugger", NULL);
1758 if (!g_file_test (path, G_FILE_TEST_EXISTS)) {
1760 path = g_build_filename (BIN_DIR, "empathy-debugger", NULL);
1763 app_info = g_app_info_create_from_commandline (path, NULL, 0, &error);
1764 if (app_info == NULL) {
1765 DEBUG ("Failed to create app info: %s", error->message);
1766 g_error_free (error);
1770 display = gdk_display_get_default ();
1771 context = gdk_display_get_app_launch_context (display);
1773 if (!g_app_info_launch (app_info, NULL, (GAppLaunchContext *) context,
1775 g_warning ("Failed to open debug window: %s", error->message);
1776 g_error_free (error);
1781 tp_clear_object (&app_info);
1782 tp_clear_object (&context);
1787 main_window_help_contents_cb (GtkAction *action,
1788 EmpathyMainWindow *window)
1790 empathy_url_show (GTK_WIDGET (window), "ghelp:empathy");
1794 main_window_throbber_button_press_event_cb (GtkWidget *throbber,
1795 GdkEventButton *event,
1796 EmpathyMainWindow *window)
1798 if (event->type != GDK_BUTTON_PRESS ||
1799 event->button != 1) {
1803 empathy_accounts_dialog_show_application (
1804 gtk_widget_get_screen (GTK_WIDGET (throbber)),
1805 NULL, FALSE, FALSE);
1811 main_window_account_removed_cb (TpAccountManager *manager,
1813 EmpathyMainWindow *window)
1815 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1818 a = tp_account_manager_get_valid_accounts (manager);
1820 gtk_action_set_sensitive (priv->view_history,
1821 g_list_length (a) > 0);
1825 /* remove errors if any */
1826 main_window_remove_error (window, account);
1830 main_window_account_validity_changed_cb (TpAccountManager *manager,
1833 EmpathyMainWindow *window)
1835 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1839 handler_id = GPOINTER_TO_UINT (g_hash_table_lookup (
1840 priv->status_changed_handlers, account));
1842 /* connect signal only if it was not connected yet */
1843 if (handler_id == 0) {
1844 handler_id = g_signal_connect (account,
1846 G_CALLBACK (main_window_connection_changed_cb),
1848 g_hash_table_insert (priv->status_changed_handlers,
1849 account, GUINT_TO_POINTER (handler_id));
1853 main_window_account_removed_cb (manager, account, window);
1857 main_window_notify_show_offline_cb (GSettings *gsettings,
1859 gpointer toggle_action)
1861 gtk_toggle_action_set_active (toggle_action,
1862 g_settings_get_boolean (gsettings, key));
1866 main_window_connection_items_setup (EmpathyMainWindow *window,
1869 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1873 const gchar *actions_connected[] = {
1875 "room_join_favorites",
1879 "edit_personal_information",
1880 "edit_blocked_contacts"
1883 for (i = 0, list = NULL; i < G_N_ELEMENTS (actions_connected); i++) {
1884 action = gtk_builder_get_object (gui, actions_connected[i]);
1885 list = g_list_prepend (list, action);
1888 priv->actions_connected = list;
1892 account_manager_prepared_cb (GObject *source_object,
1893 GAsyncResult *result,
1896 GList *accounts, *j;
1897 TpAccountManager *manager = TP_ACCOUNT_MANAGER (source_object);
1898 EmpathyMainWindow *window = user_data;
1899 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1900 GError *error = NULL;
1902 if (!tp_account_manager_prepare_finish (manager, result, &error)) {
1903 DEBUG ("Failed to prepare account manager: %s", error->message);
1904 g_error_free (error);
1908 accounts = tp_account_manager_get_valid_accounts (priv->account_manager);
1909 for (j = accounts; j != NULL; j = j->next) {
1910 TpAccount *account = TP_ACCOUNT (j->data);
1913 handler_id = g_signal_connect (account, "status-changed",
1914 G_CALLBACK (main_window_connection_changed_cb),
1916 g_hash_table_insert (priv->status_changed_handlers,
1917 account, GUINT_TO_POINTER (handler_id));
1919 main_window_setup_balance (window, account);
1922 g_signal_connect (manager, "account-validity-changed",
1923 G_CALLBACK (main_window_account_validity_changed_cb),
1926 main_window_update_status (window);
1928 /* Disable the "Previous Conversations" menu entry if there is no account */
1929 gtk_action_set_sensitive (priv->view_history,
1930 g_list_length (accounts) > 0);
1932 g_list_free (accounts);
1936 main_window_members_changed_cb (EmpathyContactList *list,
1937 EmpathyContact *contact,
1938 EmpathyContact *actor,
1942 EmpathyMainWindow *window)
1944 EmpathyMainWindowPriv *priv = GET_PRIV (window);
1949 if (!empathy_migrate_butterfly_logs (contact)) {
1950 g_signal_handler_disconnect (list,
1951 priv->butterfly_log_migration_members_changed_id);
1952 priv->butterfly_log_migration_members_changed_id = 0;
1957 empathy_main_window_constructor (GType type,
1958 guint n_construct_params,
1959 GObjectConstructParam *construct_params)
1961 static GObject *window = NULL;
1964 return g_object_ref (window);
1966 window = G_OBJECT_CLASS (empathy_main_window_parent_class)->constructor (
1967 type, n_construct_params, construct_params);
1969 g_object_add_weak_pointer (window, (gpointer) &window);
1975 empathy_main_window_class_init (EmpathyMainWindowClass *klass)
1977 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1979 object_class->finalize = empathy_main_window_finalize;
1980 object_class->constructor = empathy_main_window_constructor;
1982 g_type_class_add_private (object_class, sizeof (EmpathyMainWindowPriv));
1986 empathy_main_window_init (EmpathyMainWindow *window)
1988 EmpathyMainWindowPriv *priv;
1989 EmpathyIndividualManager *individual_manager;
1992 GtkToggleAction *show_offline_widget;
1993 GtkAction *show_map_widget;
1995 gboolean show_offline;
1998 GtkTreeModel *model;
2000 priv = window->priv = G_TYPE_INSTANCE_GET_PRIVATE (window,
2001 EMPATHY_TYPE_MAIN_WINDOW, EmpathyMainWindowPriv);
2003 priv->gsettings_ui = g_settings_new (EMPATHY_PREFS_UI_SCHEMA);
2004 priv->gsettings_contacts = g_settings_new (EMPATHY_PREFS_CONTACTS_SCHEMA);
2006 priv->sound_mgr = empathy_sound_manager_dup_singleton ();
2008 gtk_window_set_title (GTK_WINDOW (window), _("Contact List"));
2009 gtk_window_set_role (GTK_WINDOW (window), "contact_list");
2010 gtk_window_set_default_size (GTK_WINDOW (window), 225, 325);
2012 /* Set up interface */
2013 filename = empathy_file_lookup ("empathy-main-window.ui", "src");
2014 gui = empathy_builder_get_file (filename,
2015 "main_vbox", &priv->main_vbox,
2016 "errors_vbox", &priv->errors_vbox,
2017 "auth_vbox", &priv->auth_vbox,
2018 "ui_manager", &priv->ui_manager,
2019 "view_show_offline", &show_offline_widget,
2020 "view_show_protocols", &priv->show_protocols,
2021 "view_sort_by_name", &priv->sort_by_name,
2022 "view_sort_by_status", &priv->sort_by_status,
2023 "view_normal_size_with_avatars", &priv->normal_with_avatars,
2024 "view_normal_size", &priv->normal_size,
2025 "view_compact_size", &priv->compact_size,
2026 "view_history", &priv->view_history,
2027 "view_show_map", &show_map_widget,
2028 "room_join_favorites", &priv->room_join_favorites,
2029 "presence_toolbar", &priv->presence_toolbar,
2030 "notebook", &priv->notebook,
2031 "no_entry_label", &priv->no_entry_label,
2032 "roster_scrolledwindow", &sw,
2036 gtk_container_add (GTK_CONTAINER (window), priv->main_vbox);
2037 gtk_widget_show (priv->main_vbox);
2039 g_signal_connect (window, "key-press-event",
2040 G_CALLBACK (main_window_key_press_event_cb), NULL);
2042 empathy_builder_connect (gui, window,
2043 "chat_quit", "activate", main_window_chat_quit_cb,
2044 "chat_new_message", "activate", main_window_chat_new_message_cb,
2045 "chat_new_call", "activate", main_window_chat_new_call_cb,
2046 "view_history", "activate", main_window_view_history_cb,
2047 "room_join_new", "activate", main_window_room_join_new_cb,
2048 "room_join_favorites", "activate", main_window_room_join_favorites_cb,
2049 "room_manage_favorites", "activate", main_window_room_manage_favorites_cb,
2050 "chat_add_contact", "activate", main_window_chat_add_contact_cb,
2051 "chat_search_contacts", "activate", main_window_chat_search_contacts_cb,
2052 "view_show_ft_manager", "activate", main_window_view_show_ft_manager,
2053 "view_show_offline", "toggled", main_window_view_show_offline_cb,
2054 "view_show_protocols", "toggled", main_window_view_show_protocols_cb,
2055 "view_sort_by_name", "changed", main_window_view_sort_contacts_cb,
2056 "view_normal_size_with_avatars", "changed", main_window_view_contacts_list_size_cb,
2057 "view_show_map", "activate", main_window_view_show_map_cb,
2058 "edit", "activate", main_window_edit_cb,
2059 "edit_accounts", "activate", main_window_edit_accounts_cb,
2060 "edit_personal_information", "activate", main_window_edit_personal_information_cb,
2061 "edit_blocked_contacts", "activate", main_window_edit_blocked_contacts_cb,
2062 "edit_preferences", "activate", main_window_edit_preferences_cb,
2063 "edit_search_contacts", "activate", main_window_edit_search_contacts_cb,
2064 "help_about", "activate", main_window_help_about_cb,
2065 "help_debug", "activate", main_window_help_debug_cb,
2066 "help_contents", "activate", main_window_help_contents_cb,
2069 /* Set up connection related widgets. */
2070 main_window_connection_items_setup (window, gui);
2072 g_object_ref (priv->ui_manager);
2073 g_object_unref (gui);
2075 #ifndef HAVE_LIBCHAMPLAIN
2076 gtk_action_set_visible (show_map_widget, FALSE);
2079 priv->account_manager = tp_account_manager_dup ();
2081 tp_account_manager_prepare_async (priv->account_manager, NULL,
2082 account_manager_prepared_cb, window);
2084 priv->errors = g_hash_table_new_full (g_direct_hash,
2089 priv->auths = g_hash_table_new (NULL, NULL);
2091 priv->status_changed_handlers = g_hash_table_new_full (g_direct_hash,
2097 main_window_favorite_chatroom_menu_setup (window);
2099 priv->edit_context = gtk_ui_manager_get_widget (priv->ui_manager,
2100 "/menubar/edit/edit_context");
2101 priv->edit_context_separator = gtk_ui_manager_get_widget (
2103 "/menubar/edit/edit_context_separator");
2104 gtk_widget_hide (priv->edit_context);
2105 gtk_widget_hide (priv->edit_context_separator);
2107 /* Set up contact list. */
2108 empathy_status_presets_get_all ();
2110 /* Set up presence chooser */
2111 priv->presence_chooser = empathy_presence_chooser_new ();
2112 gtk_widget_show (priv->presence_chooser);
2113 item = gtk_tool_item_new ();
2114 gtk_widget_show (GTK_WIDGET (item));
2115 gtk_widget_set_size_request (priv->presence_chooser, 10, -1);
2116 gtk_container_add (GTK_CONTAINER (item), priv->presence_chooser);
2117 gtk_tool_item_set_is_important (item, TRUE);
2118 gtk_tool_item_set_expand (item, TRUE);
2119 gtk_toolbar_insert (GTK_TOOLBAR (priv->presence_toolbar), item, -1);
2121 /* Set up the throbber */
2122 priv->throbber = gtk_spinner_new ();
2123 gtk_widget_set_size_request (priv->throbber, 16, -1);
2124 gtk_widget_set_tooltip_text (priv->throbber, _("Show and edit accounts"));
2125 gtk_widget_set_events (priv->throbber, GDK_BUTTON_PRESS_MASK);
2126 g_signal_connect (priv->throbber, "button-press-event",
2127 G_CALLBACK (main_window_throbber_button_press_event_cb),
2129 gtk_widget_show (priv->throbber);
2131 item = gtk_tool_item_new ();
2132 gtk_container_set_border_width (GTK_CONTAINER (item), 6);
2133 gtk_toolbar_insert (GTK_TOOLBAR (priv->presence_toolbar), item, -1);
2134 gtk_container_add (GTK_CONTAINER (item), priv->throbber);
2135 priv->throbber_tool_item = GTK_WIDGET (item);
2137 /* XXX: this class is designed to live for the duration of the program,
2138 * so it's got a race condition between its signal handlers and its
2139 * finalization. The class is planned to be removed, so we won't fix
2140 * this before then. */
2141 priv->contact_manager = EMPATHY_CONTACT_LIST (
2142 empathy_contact_manager_dup_singleton ());
2143 individual_manager = empathy_individual_manager_dup_singleton ();
2144 priv->individual_store = empathy_individual_store_new (
2145 individual_manager);
2146 g_object_unref (individual_manager);
2148 /* For the moment, we disallow Persona drops onto the main contact list (e.g. from things such as
2149 * the EmpathyPersonaView in the linking dialogue). No code is hooked up to do anything on a Persona
2150 * drop, so allowing them would achieve nothing except confusion. */
2151 priv->individual_view = empathy_individual_view_new (
2152 priv->individual_store,
2153 EMPATHY_INDIVIDUAL_VIEW_FEATURE_ALL ^ EMPATHY_INDIVIDUAL_VIEW_FEATURE_PERSONA_DROP,
2154 EMPATHY_INDIVIDUAL_FEATURE_ALL);
2156 priv->butterfly_log_migration_members_changed_id = g_signal_connect (
2157 priv->contact_manager, "members-changed",
2158 G_CALLBACK (main_window_members_changed_cb), window);
2160 gtk_widget_show (GTK_WIDGET (priv->individual_view));
2161 gtk_container_add (GTK_CONTAINER (sw),
2162 GTK_WIDGET (priv->individual_view));
2163 g_signal_connect (priv->individual_view, "row-activated",
2164 G_CALLBACK (main_window_row_activated_cb),
2167 /* Set up search bar */
2168 priv->search_bar = empathy_live_search_new (
2169 GTK_WIDGET (priv->individual_view));
2170 empathy_individual_view_set_live_search (priv->individual_view,
2171 EMPATHY_LIVE_SEARCH (priv->search_bar));
2172 gtk_box_pack_start (GTK_BOX (priv->main_vbox), priv->search_bar,
2174 g_signal_connect_swapped (window, "map",
2175 G_CALLBACK (gtk_widget_grab_focus), priv->individual_view);
2177 /* Connect to proper signals to check if contact list is empty or not */
2178 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->individual_view));
2180 g_signal_connect (model, "row-inserted",
2181 G_CALLBACK (main_window_row_inserted_cb),
2183 g_signal_connect (model, "row-deleted",
2184 G_CALLBACK (main_window_row_deleted_cb),
2187 /* Load user-defined accelerators. */
2188 main_window_accels_load ();
2190 /* Set window size. */
2191 empathy_geometry_bind (GTK_WINDOW (window), GEOMETRY_NAME);
2193 /* Enable event handling */
2194 priv->call_observer = empathy_call_observer_dup_singleton ();
2195 priv->event_manager = empathy_event_manager_dup_singleton ();
2197 g_signal_connect (priv->event_manager, "event-added",
2198 G_CALLBACK (main_window_event_added_cb), window);
2199 g_signal_connect (priv->event_manager, "event-removed",
2200 G_CALLBACK (main_window_event_removed_cb), window);
2201 g_signal_connect (priv->account_manager, "account-validity-changed",
2202 G_CALLBACK (main_window_account_validity_changed_cb),
2204 g_signal_connect (priv->account_manager, "account-removed",
2205 G_CALLBACK (main_window_account_removed_cb),
2207 g_signal_connect (priv->account_manager, "account-disabled",
2208 G_CALLBACK (main_window_account_disabled_cb),
2211 l = empathy_event_manager_get_events (priv->event_manager);
2213 main_window_event_added_cb (priv->event_manager, l->data,
2218 /* Show offline ? */
2219 show_offline = g_settings_get_boolean (priv->gsettings_ui,
2220 EMPATHY_PREFS_UI_SHOW_OFFLINE);
2221 g_signal_connect (priv->gsettings_ui,
2222 "changed::" EMPATHY_PREFS_UI_SHOW_OFFLINE,
2223 G_CALLBACK (main_window_notify_show_offline_cb),
2224 show_offline_widget);
2226 gtk_toggle_action_set_active (show_offline_widget, show_offline);
2228 /* Show protocol ? */
2229 g_signal_connect (priv->gsettings_ui,
2230 "changed::" EMPATHY_PREFS_UI_SHOW_PROTOCOLS,
2231 G_CALLBACK (main_window_notify_show_protocols_cb),
2234 main_window_notify_show_protocols_cb (priv->gsettings_ui,
2235 EMPATHY_PREFS_UI_SHOW_PROTOCOLS,
2238 /* Sort by name / by status ? */
2239 g_signal_connect (priv->gsettings_contacts,
2240 "changed::" EMPATHY_PREFS_CONTACTS_SORT_CRITERIUM,
2241 G_CALLBACK (main_window_notify_sort_contact_cb),
2244 main_window_notify_sort_contact_cb (priv->gsettings_contacts,
2245 EMPATHY_PREFS_CONTACTS_SORT_CRITERIUM,
2248 /* Contacts list size */
2249 g_signal_connect (priv->gsettings_ui,
2250 "changed::" EMPATHY_PREFS_UI_COMPACT_CONTACT_LIST,
2251 G_CALLBACK (main_window_notify_contact_list_size_cb),
2253 g_signal_connect (priv->gsettings_ui,
2254 "changed::" EMPATHY_PREFS_UI_SHOW_AVATARS,
2255 G_CALLBACK (main_window_notify_contact_list_size_cb),
2258 main_window_notify_contact_list_size_cb (priv->gsettings_ui,
2259 EMPATHY_PREFS_UI_SHOW_AVATARS,
2264 empathy_main_window_dup (void)
2266 return g_object_new (EMPATHY_TYPE_MAIN_WINDOW, NULL);