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-2008 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., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
21 * Authors: Xavier Claessens <xclaesse@gmail.com>
28 #include <glade/glade.h>
29 #include <glib/gi18n.h>
31 #include <libempathy/empathy-contact.h>
32 #include <libempathy/empathy-utils.h>
33 #include <libempathy/empathy-account-manager.h>
34 #include <libempathy/empathy-dispatcher.h>
35 #include <libempathy/empathy-chatroom-manager.h>
36 #include <libempathy/empathy-chatroom.h>
37 #include <libempathy/empathy-contact-list.h>
38 #include <libempathy/empathy-contact-manager.h>
39 #include <libempathy/empathy-contact-factory.h>
40 #include <libempathy/empathy-status-presets.h>
42 #include <libempathy-gtk/empathy-contact-dialogs.h>
43 #include <libempathy-gtk/empathy-contact-list-store.h>
44 #include <libempathy-gtk/empathy-contact-list-view.h>
45 #include <libempathy-gtk/empathy-presence-chooser.h>
46 #include <libempathy-gtk/empathy-ui-utils.h>
47 #include <libempathy-gtk/empathy-geometry.h>
48 #include <libempathy-gtk/empathy-conf.h>
49 #include <libempathy-gtk/empathy-log-window.h>
50 #include <libempathy-gtk/empathy-new-message-dialog.h>
51 #include <libempathy-gtk/empathy-gtk-enum-types.h>
53 #include <libmissioncontrol/mission-control.h>
55 #include "empathy-accounts-dialog.h"
56 #include "empathy-main-window.h"
57 #include "ephy-spinner.h"
58 #include "empathy-preferences.h"
59 #include "empathy-about-dialog.h"
60 #include "empathy-new-chatroom-dialog.h"
61 #include "empathy-chatrooms-window.h"
62 #include "empathy-event-manager.h"
64 #define DEBUG_FLAG EMPATHY_DEBUG_OTHER
65 #include <libempathy/empathy-debug.h>
67 /* Flashing delay for icons (milliseconds). */
68 #define FLASH_TIMEOUT 500
70 /* Minimum width of roster window if something goes wrong. */
73 /* Accels (menu shortcuts) can be configured and saved */
74 #define ACCELS_FILENAME "accels.txt"
76 /* Name in the geometry file */
77 #define GEOMETRY_NAME "main-window"
80 EmpathyContactListView *list_view;
81 EmpathyContactListStore *list_store;
83 EmpathyAccountManager *account_manager;
84 EmpathyChatroomManager *chatroom_manager;
85 EmpathyEventManager *event_manager;
86 guint flash_timeout_id;
92 GtkWidget *presence_toolbar;
93 GtkWidget *presence_chooser;
94 GtkWidget *errors_vbox;
99 GtkWidget *room_join_favorites;
100 GtkWidget *edit_context;
101 GtkWidget *edit_context_separator;
102 GtkWidget *chat_history_menu_item;
104 guint size_timeout_id;
107 /* Widgets that are enabled when there are connected accounts */
108 GList *widgets_connected;
111 static EmpathyMainWindow *window = NULL;
113 static void main_window_destroy_cb (GtkWidget *widget,
114 EmpathyMainWindow *window);
115 static void main_window_favorite_chatroom_menu_setup (EmpathyMainWindow *window);
116 static void main_window_favorite_chatroom_menu_added_cb (EmpathyChatroomManager *manager,
117 EmpathyChatroom *chatroom,
118 EmpathyMainWindow *window);
119 static void main_window_favorite_chatroom_menu_removed_cb (EmpathyChatroomManager *manager,
120 EmpathyChatroom *chatroom,
121 EmpathyMainWindow *window);
122 static void main_window_favorite_chatroom_menu_activate_cb (GtkMenuItem *menu_item,
123 EmpathyChatroom *chatroom);
124 static void main_window_favorite_chatroom_menu_update (EmpathyMainWindow *window);
125 static void main_window_favorite_chatroom_menu_add (EmpathyMainWindow *window,
126 EmpathyChatroom *chatroom);
127 static void main_window_favorite_chatroom_join (EmpathyChatroom *chatroom);
128 static void main_window_chat_quit_cb (GtkWidget *widget,
129 EmpathyMainWindow *window);
130 static void main_window_chat_new_message_cb (GtkWidget *widget,
131 EmpathyMainWindow *window);
132 static void main_window_chat_history_cb (GtkWidget *widget,
133 EmpathyMainWindow *window);
134 static void main_window_room_join_new_cb (GtkWidget *widget,
135 EmpathyMainWindow *window);
136 static void main_window_room_join_favorites_cb (GtkWidget *widget,
137 EmpathyMainWindow *window);
138 static void main_window_room_manage_favorites_cb (GtkWidget *widget,
139 EmpathyMainWindow *window);
140 static void main_window_chat_add_contact_cb (GtkWidget *widget,
141 EmpathyMainWindow *window);
142 static void main_window_chat_show_offline_cb (GtkCheckMenuItem *item,
143 EmpathyMainWindow *window);
144 static gboolean main_window_edit_button_press_event_cb (GtkWidget *widget,
145 GdkEventButton *event,
146 EmpathyMainWindow *window);
147 static void main_window_edit_accounts_cb (GtkWidget *widget,
148 EmpathyMainWindow *window);
149 static void main_window_edit_personal_information_cb (GtkWidget *widget,
150 EmpathyMainWindow *window);
151 static void main_window_edit_preferences_cb (GtkWidget *widget,
152 EmpathyMainWindow *window);
153 static void main_window_help_about_cb (GtkWidget *widget,
154 EmpathyMainWindow *window);
155 static void main_window_help_contents_cb (GtkWidget *widget,
156 EmpathyMainWindow *window);
157 static gboolean main_window_throbber_button_press_event_cb (GtkWidget *throbber_ebox,
158 GdkEventButton *event,
159 EmpathyMainWindow *window);
160 static void main_window_update_status (EmpathyMainWindow *window,
161 EmpathyAccountManager *manager);
162 static void main_window_error_display (EmpathyMainWindow *window,
164 const gchar *message);
165 static void main_window_accels_load (void);
166 static void main_window_accels_save (void);
167 static void main_window_connection_items_setup (EmpathyMainWindow *window,
169 static gboolean main_window_configure_event_timeout_cb (EmpathyMainWindow *window);
170 static gboolean main_window_configure_event_cb (GtkWidget *widget,
171 GdkEventConfigure *event,
172 EmpathyMainWindow *window);
173 static void main_window_notify_show_offline_cb (EmpathyConf *conf,
175 gpointer check_menu_item);
176 static void main_window_notify_show_avatars_cb (EmpathyConf *conf,
178 EmpathyMainWindow *window);
179 static void main_window_notify_compact_contact_list_cb (EmpathyConf *conf,
181 EmpathyMainWindow *window);
182 static void main_window_notify_sort_criterium_cb (EmpathyConf *conf,
184 EmpathyMainWindow *window);
185 static void main_window_account_created_or_deleted_cb (EmpathyAccountManager *manager,
187 EmpathyMainWindow *window);
190 main_window_flash_stop (EmpathyMainWindow *window)
192 if (window->flash_timeout_id == 0) {
196 DEBUG ("Stop flashing");
197 g_source_remove (window->flash_timeout_id);
198 window->flash_timeout_id = 0;
199 window->flash_on = FALSE;
208 main_window_flash_foreach (GtkTreeModel *model,
213 FlashForeachData *data = (FlashForeachData*) user_data;
214 EmpathyContact *contact;
215 const gchar *icon_name;
216 GtkTreePath *parent_path = NULL;
217 GtkTreeIter parent_iter;
219 /* To be used with gtk_tree_model_foreach, update the status icon
220 * of the contact to show the event icon (on=TRUE) or the presence
222 gtk_tree_model_get (model, iter,
223 EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, &contact,
226 if (contact != data->event->contact) {
228 g_object_unref (contact);
234 icon_name = data->event->icon_name;
236 icon_name = empathy_icon_name_for_contact (contact);
239 gtk_tree_store_set (GTK_TREE_STORE (model), iter,
240 EMPATHY_CONTACT_LIST_STORE_COL_ICON_STATUS, icon_name,
243 /* To make sure the parent is shown correctly, we emit
244 * the row-changed signal on the parent so it prompts
245 * it to be refreshed by the filter func.
247 if (gtk_tree_model_iter_parent (model, &parent_iter, iter)) {
248 parent_path = gtk_tree_model_get_path (model, &parent_iter);
251 gtk_tree_model_row_changed (model, parent_path, &parent_iter);
252 gtk_tree_path_free (parent_path);
255 g_object_unref (contact);
261 main_window_flash_cb (EmpathyMainWindow *window)
265 gboolean found_event = FALSE;
266 FlashForeachData data;
268 window->flash_on = !window->flash_on;
269 data.on = window->flash_on;
270 model = GTK_TREE_MODEL (window->list_store);
272 events = empathy_event_manager_get_events (window->event_manager);
273 for (l = events; l; l = l->next) {
274 data.event = l->data;
275 if (!data.event->contact) {
280 gtk_tree_model_foreach (model,
281 main_window_flash_foreach,
286 main_window_flash_stop (window);
293 main_window_flash_start (EmpathyMainWindow *window)
295 if (window->flash_timeout_id != 0) {
299 DEBUG ("Start flashing");
300 window->flash_timeout_id = g_timeout_add (FLASH_TIMEOUT,
301 (GSourceFunc) main_window_flash_cb,
303 main_window_flash_cb (window);
307 main_window_event_added_cb (EmpathyEventManager *manager,
309 EmpathyMainWindow *window)
311 if (event->contact) {
312 main_window_flash_start (window);
317 main_window_event_removed_cb (EmpathyEventManager *manager,
319 EmpathyMainWindow *window)
321 FlashForeachData data;
323 if (!event->contact) {
329 gtk_tree_model_foreach (GTK_TREE_MODEL (window->list_store),
330 main_window_flash_foreach,
335 main_window_row_activated_cb (EmpathyContactListView *view,
337 GtkTreeViewColumn *col,
338 EmpathyMainWindow *window)
340 EmpathyContact *contact;
345 model = GTK_TREE_MODEL (window->list_store);
346 gtk_tree_model_get_iter (model, &iter, path);
347 gtk_tree_model_get (model, &iter,
348 EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, &contact,
355 /* If the contact has an event activate it, otherwise the
356 * default handler of row-activated will be called. */
357 events = empathy_event_manager_get_events (window->event_manager);
358 for (l = events; l; l = l->next) {
359 EmpathyEvent *event = l->data;
361 if (event->contact == contact) {
362 DEBUG ("Activate event");
363 empathy_event_activate (event);
365 /* We don't want the default handler of this signal
366 * (e.g. open a chat) */
367 g_signal_stop_emission_by_name (view, "row-activated");
372 g_object_unref (contact);
376 main_window_connection_changed_cb (EmpathyAccountManager *manager,
378 TpConnectionStatusReason reason,
379 TpConnectionStatus current,
380 TpConnectionStatus previous,
381 EmpathyMainWindow *window)
383 main_window_update_status (window, manager);
385 if (current == TP_CONNECTION_STATUS_DISCONNECTED &&
386 reason != TP_CONNECTION_STATUS_REASON_REQUESTED) {
387 const gchar *message;
390 case TP_CONNECTION_STATUS_REASON_NONE_SPECIFIED:
391 message = _("No error specified");
393 case TP_CONNECTION_STATUS_REASON_NETWORK_ERROR:
394 message = _("Network error");
396 case TP_CONNECTION_STATUS_REASON_AUTHENTICATION_FAILED:
397 message = _("Authentication failed");
399 case TP_CONNECTION_STATUS_REASON_ENCRYPTION_ERROR:
400 message = _("Encryption error");
402 case TP_CONNECTION_STATUS_REASON_NAME_IN_USE:
403 message = _("Name in use");
405 case TP_CONNECTION_STATUS_REASON_CERT_NOT_PROVIDED:
406 message = _("Certificate not provided");
408 case TP_CONNECTION_STATUS_REASON_CERT_UNTRUSTED:
409 message = _("Certificate untrusted");
411 case TP_CONNECTION_STATUS_REASON_CERT_EXPIRED:
412 message = _("Certificate expired");
414 case TP_CONNECTION_STATUS_REASON_CERT_NOT_ACTIVATED:
415 message = _("Certificate not activated");
417 case TP_CONNECTION_STATUS_REASON_CERT_HOSTNAME_MISMATCH:
418 message = _("Certificate hostname mismatch");
420 case TP_CONNECTION_STATUS_REASON_CERT_FINGERPRINT_MISMATCH:
421 message = _("Certificate fingerprint mismatch");
423 case TP_CONNECTION_STATUS_REASON_CERT_SELF_SIGNED:
424 message = _("Certificate self-signed");
426 case TP_CONNECTION_STATUS_REASON_CERT_OTHER_ERROR:
427 message = _("Certificate error");
430 message = _("Unknown error");
434 main_window_error_display (window, account, message);
437 if (current == TP_CONNECTION_STATUS_DISCONNECTED) {
438 empathy_sound_play (GTK_WIDGET (window->window),
439 EMPATHY_SOUND_ACCOUNT_DISCONNECTED);
442 if (current == TP_CONNECTION_STATUS_CONNECTED) {
443 GtkWidget *error_widget;
445 empathy_sound_play (GTK_WIDGET (window->window),
446 EMPATHY_SOUND_ACCOUNT_CONNECTED);
448 /* Account connected without error, remove error message if any */
449 error_widget = g_hash_table_lookup (window->errors, account);
451 gtk_widget_destroy (error_widget);
452 g_hash_table_remove (window->errors, account);
458 main_window_contact_presence_changed_cb (EmpathyContactMonitor *monitor,
459 EmpathyContact *contact,
462 EmpathyMainWindow *window)
465 gboolean should_play;
467 account = empathy_contact_get_account (contact);
468 should_play = !empathy_account_manager_is_account_just_connected (window->account_manager, account);
474 if (previous < MC_PRESENCE_AVAILABLE && current > MC_PRESENCE_OFFLINE) {
475 /* someone is logging in */
476 empathy_sound_play (GTK_WIDGET (window->window),
477 EMPATHY_SOUND_CONTACT_CONNECTED);
481 if (previous > MC_PRESENCE_OFFLINE && current < MC_PRESENCE_AVAILABLE) {
482 /* someone is logging off */
483 empathy_sound_play (GTK_WIDGET (window->window),
484 EMPATHY_SOUND_CONTACT_DISCONNECTED);
489 empathy_main_window_get (void)
491 return window != NULL ? window->window : NULL;
495 empathy_main_window_show (void)
497 EmpathyContactList *list_iface;
498 EmpathyContactMonitor *monitor;
502 GtkWidget *show_offline_widget;
505 gboolean show_offline;
506 gboolean show_avatars;
507 gboolean compact_contact_list;
513 empathy_window_present (GTK_WINDOW (window->window), TRUE);
514 return window->window;
517 window = g_new0 (EmpathyMainWindow, 1);
519 /* Set up interface */
520 filename = empathy_file_lookup ("empathy-main-window.glade", "src");
521 glade = empathy_glade_get_file (filename,
524 "main_window", &window->window,
525 "main_vbox", &window->main_vbox,
526 "errors_vbox", &window->errors_vbox,
527 "chat_show_offline", &show_offline_widget,
528 "room", &window->room,
529 "room_sep", &window->room_sep,
530 "room_join_favorites", &window->room_join_favorites,
531 "edit_context", &window->edit_context,
532 "edit_context_separator", &window->edit_context_separator,
533 "presence_toolbar", &window->presence_toolbar,
534 "roster_scrolledwindow", &sw,
535 "chat_history", &window->chat_history_menu_item,
539 empathy_glade_connect (glade,
541 "main_window", "destroy", main_window_destroy_cb,
542 "main_window", "configure_event", main_window_configure_event_cb,
543 "chat_quit", "activate", main_window_chat_quit_cb,
544 "chat_new_message", "activate", main_window_chat_new_message_cb,
545 "chat_history", "activate", main_window_chat_history_cb,
546 "room_join_new", "activate", main_window_room_join_new_cb,
547 "room_join_favorites", "activate", main_window_room_join_favorites_cb,
548 "room_manage_favorites", "activate", main_window_room_manage_favorites_cb,
549 "chat_add_contact", "activate", main_window_chat_add_contact_cb,
550 "chat_show_offline", "toggled", main_window_chat_show_offline_cb,
551 "edit", "button-press-event", main_window_edit_button_press_event_cb,
552 "edit_accounts", "activate", main_window_edit_accounts_cb,
553 "edit_personal_information", "activate", main_window_edit_personal_information_cb,
554 "edit_preferences", "activate", main_window_edit_preferences_cb,
555 "help_about", "activate", main_window_help_about_cb,
556 "help_contents", "activate", main_window_help_contents_cb,
559 /* Set up connection related widgets. */
560 main_window_connection_items_setup (window, glade);
561 g_object_unref (glade);
563 window->mc = empathy_mission_control_dup_singleton ();
564 window->account_manager = empathy_account_manager_dup_singleton ();
566 g_signal_connect (window->account_manager,
567 "account-connection-changed",
568 G_CALLBACK (main_window_connection_changed_cb), window);
570 window->errors = g_hash_table_new_full (empathy_account_hash,
571 empathy_account_equal,
576 main_window_favorite_chatroom_menu_setup (window);
578 gtk_widget_hide (window->edit_context);
579 gtk_widget_hide (window->edit_context_separator);
581 /* Set up presence chooser */
582 window->presence_chooser = empathy_presence_chooser_new ();
583 gtk_widget_show (window->presence_chooser);
584 item = gtk_tool_item_new ();
585 gtk_widget_show (GTK_WIDGET (item));
586 gtk_container_add (GTK_CONTAINER (item), window->presence_chooser);
587 gtk_tool_item_set_is_important (item, TRUE);
588 gtk_tool_item_set_expand (item, TRUE);
589 gtk_toolbar_insert (GTK_TOOLBAR (window->presence_toolbar), item, -1);
591 /* Set up the throbber */
592 ebox = gtk_event_box_new ();
593 gtk_event_box_set_visible_window (GTK_EVENT_BOX (ebox), FALSE);
594 gtk_widget_set_tooltip_text (ebox, _("Show and edit accounts"));
595 g_signal_connect (ebox,
596 "button-press-event",
597 G_CALLBACK (main_window_throbber_button_press_event_cb),
599 gtk_widget_show (ebox);
601 window->throbber = ephy_spinner_new ();
602 ephy_spinner_set_size (EPHY_SPINNER (window->throbber), GTK_ICON_SIZE_LARGE_TOOLBAR);
603 gtk_container_add (GTK_CONTAINER (ebox), window->throbber);
604 gtk_widget_show (window->throbber);
606 item = gtk_tool_item_new ();
607 gtk_container_add (GTK_CONTAINER (item), ebox);
608 gtk_toolbar_insert (GTK_TOOLBAR (window->presence_toolbar), item, -1);
609 gtk_widget_show (GTK_WIDGET (item));
611 /* Set up contact list. */
612 empathy_status_presets_get_all ();
614 list_iface = EMPATHY_CONTACT_LIST (empathy_contact_manager_dup_singleton ());
615 monitor = empathy_contact_list_get_monitor (list_iface);
616 window->list_store = empathy_contact_list_store_new (list_iface);
617 window->list_view = empathy_contact_list_view_new (window->list_store,
618 EMPATHY_CONTACT_LIST_FEATURE_ALL,
619 EMPATHY_CONTACT_FEATURE_ALL);
620 g_signal_connect (monitor, "contact-presence-changed",
621 G_CALLBACK (main_window_contact_presence_changed_cb), window);
622 g_object_unref (list_iface);
624 gtk_widget_show (GTK_WIDGET (window->list_view));
625 gtk_container_add (GTK_CONTAINER (sw),
626 GTK_WIDGET (window->list_view));
627 g_signal_connect (window->list_view, "row-activated",
628 G_CALLBACK (main_window_row_activated_cb),
631 /* Load user-defined accelerators. */
632 main_window_accels_load ();
634 /* Set window size. */
635 empathy_geometry_load (GEOMETRY_NAME, &x, &y, &w, &h);
637 if (w >= 1 && h >= 1) {
638 /* Use the defaults from the glade file if we
639 * don't have good w, h geometry.
641 DEBUG ("Configuring window default size w:%d, h:%d", w, h);
642 gtk_window_set_default_size (GTK_WINDOW (window->window), w, h);
645 if (x >= 0 && y >= 0) {
646 /* Let the window manager position it if we
647 * don't have good x, y coordinates.
649 DEBUG ("Configuring window default position x:%d, y:%d", x, y);
650 gtk_window_move (GTK_WINDOW (window->window), x, y);
653 /* Enable event handling */
654 window->event_manager = empathy_event_manager_dup_singleton ();
655 g_signal_connect (window->event_manager, "event-added",
656 G_CALLBACK (main_window_event_added_cb),
658 g_signal_connect (window->event_manager, "event-removed",
659 G_CALLBACK (main_window_event_removed_cb),
662 g_signal_connect (window->account_manager, "account-created",
663 G_CALLBACK (main_window_account_created_or_deleted_cb),
665 g_signal_connect (window->account_manager, "account-deleted",
666 G_CALLBACK (main_window_account_created_or_deleted_cb),
668 main_window_account_created_or_deleted_cb (window->account_manager, NULL, window);
670 l = empathy_event_manager_get_events (window->event_manager);
672 main_window_event_added_cb (window->event_manager,
677 conf = empathy_conf_get ();
680 empathy_conf_get_bool (conf,
681 EMPATHY_PREFS_CONTACTS_SHOW_OFFLINE,
683 empathy_conf_notify_add (conf,
684 EMPATHY_PREFS_CONTACTS_SHOW_OFFLINE,
685 main_window_notify_show_offline_cb,
686 show_offline_widget);
688 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (show_offline_widget),
692 empathy_conf_get_bool (conf,
693 EMPATHY_PREFS_UI_SHOW_AVATARS,
695 empathy_conf_notify_add (conf,
696 EMPATHY_PREFS_UI_SHOW_AVATARS,
697 (EmpathyConfNotifyFunc) main_window_notify_show_avatars_cb,
699 empathy_contact_list_store_set_show_avatars (window->list_store, show_avatars);
702 empathy_conf_get_bool (conf,
703 EMPATHY_PREFS_UI_COMPACT_CONTACT_LIST,
704 &compact_contact_list);
705 empathy_conf_notify_add (conf,
706 EMPATHY_PREFS_UI_COMPACT_CONTACT_LIST,
707 (EmpathyConfNotifyFunc) main_window_notify_compact_contact_list_cb,
709 empathy_contact_list_store_set_is_compact (window->list_store, compact_contact_list);
712 empathy_conf_notify_add (conf,
713 EMPATHY_PREFS_CONTACTS_SORT_CRITERIUM,
714 (EmpathyConfNotifyFunc) main_window_notify_sort_criterium_cb,
716 main_window_notify_sort_criterium_cb (conf,
717 EMPATHY_PREFS_CONTACTS_SORT_CRITERIUM,
720 main_window_update_status (window, window->account_manager);
722 return window->window;
726 main_window_destroy_cb (GtkWidget *widget,
727 EmpathyMainWindow *window)
729 /* Save user-defined accelerators. */
730 main_window_accels_save ();
732 g_signal_handlers_disconnect_by_func (window->account_manager,
733 main_window_connection_changed_cb,
736 if (window->size_timeout_id) {
737 g_source_remove (window->size_timeout_id);
740 g_list_free (window->widgets_connected);
742 g_object_unref (window->mc);
743 g_object_unref (window->account_manager);
744 g_object_unref (window->list_store);
745 g_hash_table_destroy (window->errors);
747 g_signal_handlers_disconnect_by_func (window->event_manager,
748 main_window_event_added_cb,
750 g_signal_handlers_disconnect_by_func (window->event_manager,
751 main_window_event_removed_cb,
753 g_object_unref (window->event_manager);
759 main_window_favorite_chatroom_menu_setup (EmpathyMainWindow *window)
761 GList *chatrooms, *l;
763 window->chatroom_manager = empathy_chatroom_manager_dup_singleton (NULL);
764 chatrooms = empathy_chatroom_manager_get_chatrooms (window->chatroom_manager, NULL);
765 window->room_menu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (window->room));
767 for (l = chatrooms; l; l = l->next) {
768 main_window_favorite_chatroom_menu_add (window, l->data);
772 gtk_widget_hide (window->room_sep);
775 gtk_widget_set_sensitive (window->room_join_favorites, chatrooms != NULL);
777 g_signal_connect (window->chatroom_manager, "chatroom-added",
778 G_CALLBACK (main_window_favorite_chatroom_menu_added_cb),
780 g_signal_connect (window->chatroom_manager, "chatroom-removed",
781 G_CALLBACK (main_window_favorite_chatroom_menu_removed_cb),
784 g_list_free (chatrooms);
788 main_window_favorite_chatroom_menu_added_cb (EmpathyChatroomManager *manager,
789 EmpathyChatroom *chatroom,
790 EmpathyMainWindow *window)
792 main_window_favorite_chatroom_menu_add (window, chatroom);
793 gtk_widget_show (window->room_sep);
794 gtk_widget_set_sensitive (window->room_join_favorites, TRUE);
798 main_window_favorite_chatroom_menu_removed_cb (EmpathyChatroomManager *manager,
799 EmpathyChatroom *chatroom,
800 EmpathyMainWindow *window)
802 GtkWidget *menu_item;
804 menu_item = g_object_get_data (G_OBJECT (chatroom), "menu_item");
806 g_object_set_data (G_OBJECT (chatroom), "menu_item", NULL);
807 gtk_widget_destroy (menu_item);
809 main_window_favorite_chatroom_menu_update (window);
813 main_window_favorite_chatroom_menu_activate_cb (GtkMenuItem *menu_item,
814 EmpathyChatroom *chatroom)
816 main_window_favorite_chatroom_join (chatroom);
820 main_window_favorite_chatroom_menu_update (EmpathyMainWindow *window)
824 chatrooms = empathy_chatroom_manager_get_chatrooms (window->chatroom_manager, NULL);
827 gtk_widget_show (window->room_sep);
829 gtk_widget_hide (window->room_sep);
832 gtk_widget_set_sensitive (window->room_join_favorites, chatrooms != NULL);
833 g_list_free (chatrooms);
837 main_window_favorite_chatroom_menu_add (EmpathyMainWindow *window,
838 EmpathyChatroom *chatroom)
840 GtkWidget *menu_item;
843 if (g_object_get_data (G_OBJECT (chatroom), "menu_item")) {
847 name = empathy_chatroom_get_name (chatroom);
848 menu_item = gtk_menu_item_new_with_label (name);
850 g_object_set_data (G_OBJECT (chatroom), "menu_item", menu_item);
851 g_signal_connect (menu_item, "activate",
852 G_CALLBACK (main_window_favorite_chatroom_menu_activate_cb),
855 gtk_menu_shell_insert (GTK_MENU_SHELL (window->room_menu),
858 gtk_widget_show (menu_item);
862 main_window_favorite_chatroom_join (EmpathyChatroom *chatroom)
868 mc = empathy_mission_control_dup_singleton ();
869 account = empathy_chatroom_get_account (chatroom);
870 room = empathy_chatroom_get_room (chatroom);
872 if (mission_control_get_connection_status (mc, account, NULL) !=
873 TP_CONNECTION_STATUS_CONNECTED) {
877 DEBUG ("Requesting channel for '%s'", room);
878 empathy_dispatcher_join_muc (account, room, NULL, NULL);
884 main_window_chat_quit_cb (GtkWidget *widget,
885 EmpathyMainWindow *window)
891 main_window_chat_new_message_cb (GtkWidget *widget,
892 EmpathyMainWindow *window)
894 empathy_new_message_dialog_show (GTK_WINDOW (window->window));
898 main_window_chat_history_cb (GtkWidget *widget,
899 EmpathyMainWindow *window)
901 empathy_log_window_show (NULL, NULL, FALSE, GTK_WINDOW (window->window));
905 main_window_room_join_new_cb (GtkWidget *widget,
906 EmpathyMainWindow *window)
908 empathy_new_chatroom_dialog_show (GTK_WINDOW (window->window));
912 main_window_room_join_favorites_cb (GtkWidget *widget,
913 EmpathyMainWindow *window)
915 GList *chatrooms, *l;
917 chatrooms = empathy_chatroom_manager_get_chatrooms (window->chatroom_manager, NULL);
918 for (l = chatrooms; l; l = l->next) {
919 main_window_favorite_chatroom_join (l->data);
921 g_list_free (chatrooms);
925 main_window_room_manage_favorites_cb (GtkWidget *widget,
926 EmpathyMainWindow *window)
928 empathy_chatrooms_window_show (GTK_WINDOW (window->window));
932 main_window_chat_add_contact_cb (GtkWidget *widget,
933 EmpathyMainWindow *window)
935 empathy_new_contact_dialog_show (GTK_WINDOW (window->window));
939 main_window_chat_show_offline_cb (GtkCheckMenuItem *item,
940 EmpathyMainWindow *window)
944 current = gtk_check_menu_item_get_active (item);
946 empathy_conf_set_bool (empathy_conf_get (),
947 EMPATHY_PREFS_CONTACTS_SHOW_OFFLINE,
950 /* Turn off sound just while we alter the contact list. */
951 // FIXME: empathy_sound_set_enabled (FALSE);
952 empathy_contact_list_store_set_show_offline (window->list_store, current);
953 //empathy_sound_set_enabled (TRUE);
957 main_window_edit_button_press_event_cb (GtkWidget *widget,
958 GdkEventButton *event,
959 EmpathyMainWindow *window)
963 if (!event->button == 1) {
967 submenu = empathy_contact_list_view_get_contact_menu (window->list_view);
972 item = GTK_MENU_ITEM (window->edit_context);
973 label = gtk_bin_get_child (GTK_BIN (item));
974 gtk_label_set_text (GTK_LABEL (label), _("Contact"));
976 gtk_widget_show (window->edit_context);
977 gtk_widget_show (window->edit_context_separator);
979 gtk_menu_item_set_submenu (item, submenu);
984 submenu = empathy_contact_list_view_get_group_menu (window->list_view);
989 item = GTK_MENU_ITEM (window->edit_context);
990 label = gtk_bin_get_child (GTK_BIN (item));
991 gtk_label_set_text (GTK_LABEL (label), _("Group"));
993 gtk_widget_show (window->edit_context);
994 gtk_widget_show (window->edit_context_separator);
996 gtk_menu_item_set_submenu (item, submenu);
1001 gtk_widget_hide (window->edit_context);
1002 gtk_widget_hide (window->edit_context_separator);
1008 main_window_edit_accounts_cb (GtkWidget *widget,
1009 EmpathyMainWindow *window)
1011 empathy_accounts_dialog_show (GTK_WINDOW (window->window), NULL);
1015 main_window_edit_personal_information_cb (GtkWidget *widget,
1016 EmpathyMainWindow *window)
1020 accounts = mission_control_get_online_connections (window->mc, NULL);
1022 EmpathyContactFactory *factory;
1023 EmpathyContact *contact;
1026 account = accounts->data;
1027 factory = empathy_contact_factory_dup_singleton ();
1028 contact = empathy_contact_factory_get_user (factory, account);
1029 empathy_contact_run_until_ready (contact,
1030 EMPATHY_CONTACT_READY_HANDLE |
1031 EMPATHY_CONTACT_READY_ID,
1034 empathy_contact_information_dialog_show (contact,
1035 GTK_WINDOW (window->window),
1038 g_slist_foreach (accounts, (GFunc) g_object_unref, NULL);
1039 g_slist_free (accounts);
1040 g_object_unref (factory);
1041 g_object_unref (contact);
1046 main_window_edit_preferences_cb (GtkWidget *widget,
1047 EmpathyMainWindow *window)
1049 empathy_preferences_show (GTK_WINDOW (window->window));
1053 main_window_help_about_cb (GtkWidget *widget,
1054 EmpathyMainWindow *window)
1056 empathy_about_dialog_new (GTK_WINDOW (window->window));
1060 main_window_help_contents_cb (GtkWidget *widget,
1061 EmpathyMainWindow *window)
1063 empathy_url_show (widget, "ghelp:empathy");
1067 main_window_throbber_button_press_event_cb (GtkWidget *throbber_ebox,
1068 GdkEventButton *event,
1069 EmpathyMainWindow *window)
1071 if (event->type != GDK_BUTTON_PRESS ||
1072 event->button != 1) {
1076 empathy_accounts_dialog_show (GTK_WINDOW (window->window), NULL);
1082 main_window_error_edit_clicked_cb (GtkButton *button,
1083 EmpathyMainWindow *window)
1086 GtkWidget *error_widget;
1088 account = g_object_get_data (G_OBJECT (button), "account");
1089 empathy_accounts_dialog_show (GTK_WINDOW (window->window), account);
1091 error_widget = g_hash_table_lookup (window->errors, account);
1092 gtk_widget_destroy (error_widget);
1093 g_hash_table_remove (window->errors, account);
1097 main_window_error_clear_clicked_cb (GtkButton *button,
1098 EmpathyMainWindow *window)
1101 GtkWidget *error_widget;
1103 account = g_object_get_data (G_OBJECT (button), "account");
1104 error_widget = g_hash_table_lookup (window->errors, account);
1105 gtk_widget_destroy (error_widget);
1106 g_hash_table_remove (window->errors, account);
1110 main_window_error_display (EmpathyMainWindow *window,
1112 const gchar *message)
1117 GtkWidget *button_edit;
1118 GtkWidget *alignment;
1123 GtkWidget *button_close;
1126 child = g_hash_table_lookup (window->errors, account);
1128 label = g_object_get_data (G_OBJECT (child), "label");
1130 /* Just set the latest error and return */
1131 str = g_markup_printf_escaped ("<b>%s</b>\n%s",
1132 mc_account_get_display_name (account),
1134 gtk_label_set_markup (GTK_LABEL (label), str);
1140 child = gtk_vbox_new (FALSE, 0);
1141 gtk_box_pack_start (GTK_BOX (window->errors_vbox), child, FALSE, TRUE, 0);
1142 gtk_container_set_border_width (GTK_CONTAINER (child), 6);
1143 gtk_widget_show (child);
1145 table = gtk_table_new (2, 4, FALSE);
1146 gtk_widget_show (table);
1147 gtk_box_pack_start (GTK_BOX (child), table, TRUE, TRUE, 0);
1148 gtk_table_set_row_spacings (GTK_TABLE (table), 12);
1149 gtk_table_set_col_spacings (GTK_TABLE (table), 6);
1151 image = gtk_image_new_from_stock (GTK_STOCK_DISCONNECT, GTK_ICON_SIZE_MENU);
1152 gtk_widget_show (image);
1153 gtk_table_attach (GTK_TABLE (table), image, 0, 1, 0, 2,
1154 (GtkAttachOptions) (GTK_FILL),
1155 (GtkAttachOptions) (GTK_FILL), 0, 0);
1156 gtk_misc_set_alignment (GTK_MISC (image), 0.5, 0);
1158 button_edit = gtk_button_new ();
1159 gtk_widget_show (button_edit);
1160 gtk_table_attach (GTK_TABLE (table), button_edit, 1, 2, 1, 2,
1161 (GtkAttachOptions) (GTK_FILL),
1162 (GtkAttachOptions) (0), 0, 0);
1164 alignment = gtk_alignment_new (0.5, 0.5, 0, 0);
1165 gtk_widget_show (alignment);
1166 gtk_container_add (GTK_CONTAINER (button_edit), alignment);
1168 hbox = gtk_hbox_new (FALSE, 2);
1169 gtk_widget_show (hbox);
1170 gtk_container_add (GTK_CONTAINER (alignment), hbox);
1172 image = gtk_image_new_from_stock (GTK_STOCK_EDIT, GTK_ICON_SIZE_BUTTON);
1173 gtk_widget_show (image);
1174 gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
1176 label = gtk_label_new_with_mnemonic (_("_Edit account"));
1177 gtk_widget_show (label);
1178 gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
1180 fixed = gtk_fixed_new ();
1181 gtk_widget_show (fixed);
1182 gtk_table_attach (GTK_TABLE (table), fixed, 2, 3, 1, 2,
1183 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
1184 (GtkAttachOptions) (GTK_FILL), 0, 0);
1186 vbox = gtk_vbox_new (FALSE, 6);
1187 gtk_widget_show (vbox);
1188 gtk_table_attach (GTK_TABLE (table), vbox, 3, 4, 0, 2,
1189 (GtkAttachOptions) (GTK_FILL),
1190 (GtkAttachOptions) (GTK_FILL), 0, 0);
1192 button_close = gtk_button_new ();
1193 gtk_widget_show (button_close);
1194 gtk_box_pack_start (GTK_BOX (vbox), button_close, FALSE, FALSE, 0);
1195 gtk_button_set_relief (GTK_BUTTON (button_close), GTK_RELIEF_NONE);
1198 image = gtk_image_new_from_stock ("gtk-close", GTK_ICON_SIZE_MENU);
1199 gtk_widget_show (image);
1200 gtk_container_add (GTK_CONTAINER (button_close), image);
1202 label = gtk_label_new ("");
1203 gtk_widget_show (label);
1204 gtk_table_attach (GTK_TABLE (table), label, 1, 3, 0, 1,
1205 (GtkAttachOptions) (GTK_EXPAND | GTK_SHRINK | GTK_FILL),
1206 (GtkAttachOptions) (GTK_EXPAND | GTK_SHRINK | GTK_FILL), 0, 0);
1207 gtk_widget_set_size_request (label, 175, -1);
1208 gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
1209 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
1210 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
1212 str = g_markup_printf_escaped ("<b>%s</b>\n%s",
1213 mc_account_get_display_name (account),
1215 gtk_label_set_markup (GTK_LABEL (label), str);
1218 g_object_set_data (G_OBJECT (child), "label", label);
1219 g_object_set_data_full (G_OBJECT (button_edit),
1220 "account", g_object_ref (account),
1222 g_object_set_data_full (G_OBJECT (button_close),
1223 "account", g_object_ref (account),
1226 g_signal_connect (button_edit, "clicked",
1227 G_CALLBACK (main_window_error_edit_clicked_cb),
1230 g_signal_connect (button_close, "clicked",
1231 G_CALLBACK (main_window_error_clear_clicked_cb),
1234 gtk_widget_show (window->errors_vbox);
1236 g_hash_table_insert (window->errors, g_object_ref (account), child);
1240 main_window_update_status (EmpathyMainWindow *window, EmpathyAccountManager *manager)
1246 /* Count number of connected/connecting/disconnected accounts */
1247 connected = empathy_account_manager_get_connected_accounts (manager);
1248 connecting = empathy_account_manager_get_connecting_accounts (manager);
1250 /* Update the spinner state */
1251 if (connecting > 0) {
1252 ephy_spinner_start (EPHY_SPINNER (window->throbber));
1254 ephy_spinner_stop (EPHY_SPINNER (window->throbber));
1257 /* Update widgets sensibility */
1258 for (l = window->widgets_connected; l; l = l->next) {
1259 gtk_widget_set_sensitive (l->data, (connected > 0));
1267 main_window_accels_load (void)
1271 filename = g_build_filename (g_get_home_dir (), ".gnome2", PACKAGE_NAME, ACCELS_FILENAME, NULL);
1272 if (g_file_test (filename, G_FILE_TEST_EXISTS)) {
1273 DEBUG ("Loading from:'%s'", filename);
1274 gtk_accel_map_load (filename);
1281 main_window_accels_save (void)
1284 gchar *file_with_path;
1286 dir = g_build_filename (g_get_home_dir (), ".gnome2", PACKAGE_NAME, NULL);
1287 g_mkdir_with_parents (dir, S_IRUSR | S_IWUSR | S_IXUSR);
1288 file_with_path = g_build_filename (dir, ACCELS_FILENAME, NULL);
1291 DEBUG ("Saving to:'%s'", file_with_path);
1292 gtk_accel_map_save (file_with_path);
1294 g_free (file_with_path);
1298 main_window_connection_items_setup (EmpathyMainWindow *window,
1304 const gchar *widgets_connected[] = {
1308 "edit_personal_information"
1311 for (i = 0, list = NULL; i < G_N_ELEMENTS (widgets_connected); i++) {
1312 w = glade_xml_get_widget (glade, widgets_connected[i]);
1313 list = g_list_prepend (list, w);
1316 window->widgets_connected = list;
1320 main_window_configure_event_timeout_cb (EmpathyMainWindow *window)
1324 gtk_window_get_size (GTK_WINDOW (window->window), &w, &h);
1325 gtk_window_get_position (GTK_WINDOW (window->window), &x, &y);
1327 empathy_geometry_save (GEOMETRY_NAME, x, y, w, h);
1329 window->size_timeout_id = 0;
1335 main_window_configure_event_cb (GtkWidget *widget,
1336 GdkEventConfigure *event,
1337 EmpathyMainWindow *window)
1339 if (window->size_timeout_id) {
1340 g_source_remove (window->size_timeout_id);
1343 window->size_timeout_id = g_timeout_add_seconds (1,
1344 (GSourceFunc) main_window_configure_event_timeout_cb,
1351 main_window_notify_show_offline_cb (EmpathyConf *conf,
1353 gpointer check_menu_item)
1355 gboolean show_offline;
1357 if (empathy_conf_get_bool (conf, key, &show_offline)) {
1358 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (check_menu_item),
1364 main_window_notify_show_avatars_cb (EmpathyConf *conf,
1366 EmpathyMainWindow *window)
1368 gboolean show_avatars;
1370 if (empathy_conf_get_bool (conf, key, &show_avatars)) {
1371 empathy_contact_list_store_set_show_avatars (window->list_store,
1377 main_window_notify_compact_contact_list_cb (EmpathyConf *conf,
1379 EmpathyMainWindow *window)
1381 gboolean compact_contact_list;
1383 if (empathy_conf_get_bool (conf, key, &compact_contact_list)) {
1384 empathy_contact_list_store_set_is_compact (window->list_store,
1385 compact_contact_list);
1390 main_window_notify_sort_criterium_cb (EmpathyConf *conf,
1392 EmpathyMainWindow *window)
1396 if (empathy_conf_get_string (conf, key, &str) && str) {
1398 GEnumClass *enum_class;
1399 GEnumValue *enum_value;
1401 type = empathy_contact_list_store_sort_get_type ();
1402 enum_class = G_ENUM_CLASS (g_type_class_peek (type));
1403 enum_value = g_enum_get_value_by_nick (enum_class, str);
1407 empathy_contact_list_store_set_sort_criterium (window->list_store,
1414 main_window_account_created_or_deleted_cb (EmpathyAccountManager *manager,
1416 EmpathyMainWindow *window)
1418 gtk_widget_set_sensitive (GTK_WIDGET (window->chat_history_menu_item),
1419 empathy_account_manager_get_count (manager) > 0);