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 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-conf.h>
32 #include <libempathy/empathy-contact.h>
33 #include <libempathy/empathy-debug.h>
34 #include <libempathy/empathy-utils.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>
41 #include "empathy-main-window.h"
42 #include "empathy-contact-dialogs.h"
43 #include "ephy-spinner.h"
44 #include "empathy-contact-list-store.h"
45 #include "empathy-contact-list-view.h"
46 #include "empathy-presence-chooser.h"
47 #include "empathy-ui-utils.h"
48 #include "empathy-status-presets.h"
49 #include "empathy-geometry.h"
50 #include "empathy-preferences.h"
51 #include "empathy-accounts-dialog.h"
52 #include "empathy-about-dialog.h"
53 #include "empathy-new-chatroom-dialog.h"
54 #include "empathy-chatrooms-window.h"
55 #include "empathy-log-window.h"
56 #include "empathy-gtk-enum-types.h"
58 #define DEBUG_DOMAIN "MainWindow"
60 /* Minimum width of roster window if something goes wrong. */
63 /* Accels (menu shortcuts) can be configured and saved */
64 #define ACCELS_FILENAME "accels.txt"
66 /* Name in the geometry file */
67 #define GEOMETRY_NAME "main-window"
70 EmpathyContactListView *list_view;
71 EmpathyContactListStore *list_store;
73 EmpathyChatroomManager *chatroom_manager;
78 GtkWidget *presence_toolbar;
79 GtkWidget *presence_chooser;
80 GtkWidget *errors_vbox;
85 GtkWidget *room_join_favorites;
86 GtkWidget *edit_context;
87 GtkWidget *edit_context_separator;
89 guint size_timeout_id;
92 /* Widgets that are enabled when there is... */
93 GList *widgets_connected; /* ... connected accounts */
94 GList *widgets_disconnected; /* ... disconnected accounts */
97 static void main_window_destroy_cb (GtkWidget *widget,
98 EmpathyMainWindow *window);
99 static void main_window_favorite_chatroom_menu_setup (EmpathyMainWindow *window);
100 static void main_window_favorite_chatroom_menu_added_cb (EmpathyChatroomManager *manager,
101 EmpathyChatroom *chatroom,
102 EmpathyMainWindow *window);
103 static void main_window_favorite_chatroom_menu_removed_cb (EmpathyChatroomManager *manager,
104 EmpathyChatroom *chatroom,
105 EmpathyMainWindow *window);
106 static void main_window_favorite_chatroom_menu_activate_cb (GtkMenuItem *menu_item,
107 EmpathyChatroom *chatroom);
108 static void main_window_favorite_chatroom_menu_update (EmpathyMainWindow *window);
109 static void main_window_favorite_chatroom_menu_add (EmpathyMainWindow *window,
110 EmpathyChatroom *chatroom);
111 static void main_window_favorite_chatroom_join (EmpathyChatroom *chatroom);
112 static void main_window_chat_quit_cb (GtkWidget *widget,
113 EmpathyMainWindow *window);
114 static void main_window_chat_new_message_cb (GtkWidget *widget,
115 EmpathyMainWindow *window);
116 static void main_window_chat_history_cb (GtkWidget *widget,
117 EmpathyMainWindow *window);
118 static void main_window_room_join_new_cb (GtkWidget *widget,
119 EmpathyMainWindow *window);
120 static void main_window_room_join_favorites_cb (GtkWidget *widget,
121 EmpathyMainWindow *window);
122 static void main_window_room_manage_favorites_cb (GtkWidget *widget,
123 EmpathyMainWindow *window);
124 static void main_window_chat_add_contact_cb (GtkWidget *widget,
125 EmpathyMainWindow *window);
126 static void main_window_chat_show_offline_cb (GtkCheckMenuItem *item,
127 EmpathyMainWindow *window);
128 static gboolean main_window_edit_button_press_event_cb (GtkWidget *widget,
129 GdkEventButton *event,
130 EmpathyMainWindow *window);
131 static void main_window_edit_accounts_cb (GtkWidget *widget,
132 EmpathyMainWindow *window);
133 static void main_window_edit_personal_information_cb (GtkWidget *widget,
134 EmpathyMainWindow *window);
135 static void main_window_edit_preferences_cb (GtkWidget *widget,
136 EmpathyMainWindow *window);
137 static void main_window_help_about_cb (GtkWidget *widget,
138 EmpathyMainWindow *window);
139 static void main_window_help_contents_cb (GtkWidget *widget,
140 EmpathyMainWindow *window);
141 static gboolean main_window_throbber_button_press_event_cb (GtkWidget *throbber_ebox,
142 GdkEventButton *event,
143 EmpathyMainWindow *window);
144 static void main_window_status_changed_cb (MissionControl *mc,
145 TelepathyConnectionStatus status,
147 TelepathyConnectionStatusReason reason,
148 const gchar *unique_name,
149 EmpathyMainWindow *window);
150 static void main_window_update_status (EmpathyMainWindow *window);
151 static void main_window_accels_load (void);
152 static void main_window_accels_save (void);
153 static void main_window_connection_items_setup (EmpathyMainWindow *window,
155 static gboolean main_window_configure_event_timeout_cb (EmpathyMainWindow *window);
156 static gboolean main_window_configure_event_cb (GtkWidget *widget,
157 GdkEventConfigure *event,
158 EmpathyMainWindow *window);
159 static void main_window_notify_show_offline_cb (EmpathyConf *conf,
161 gpointer check_menu_item);
162 static void main_window_notify_show_avatars_cb (EmpathyConf *conf,
164 EmpathyMainWindow *window);
165 static void main_window_notify_compact_contact_list_cb (EmpathyConf *conf,
167 EmpathyMainWindow *window);
168 static void main_window_notify_sort_criterium_cb (EmpathyConf *conf,
170 EmpathyMainWindow *window);
173 empathy_main_window_show (void)
175 static EmpathyMainWindow *window = NULL;
176 EmpathyContactList *list_iface;
180 GtkWidget *show_offline_widget;
183 gboolean show_offline;
184 gboolean show_avatars;
185 gboolean compact_contact_list;
189 gtk_window_present (GTK_WINDOW (window->window));
190 return window->window;
193 window = g_new0 (EmpathyMainWindow, 1);
195 /* Set up interface */
196 glade = empathy_glade_get_file ("empathy-main-window.glade",
199 "main_window", &window->window,
200 "main_vbox", &window->main_vbox,
201 "errors_vbox", &window->errors_vbox,
202 "chat_show_offline", &show_offline_widget,
203 "room", &window->room,
204 "room_sep", &window->room_sep,
205 "room_join_favorites", &window->room_join_favorites,
206 "edit_context", &window->edit_context,
207 "edit_context_separator", &window->edit_context_separator,
208 "presence_toolbar", &window->presence_toolbar,
209 "roster_scrolledwindow", &sw,
212 empathy_glade_connect (glade,
214 "main_window", "destroy", main_window_destroy_cb,
215 "main_window", "configure_event", main_window_configure_event_cb,
216 "chat_quit", "activate", main_window_chat_quit_cb,
217 "chat_new_message", "activate", main_window_chat_new_message_cb,
218 "chat_history", "activate", main_window_chat_history_cb,
219 "room_join_new", "activate", main_window_room_join_new_cb,
220 "room_join_favorites", "activate", main_window_room_join_favorites_cb,
221 "room_manage_favorites", "activate", main_window_room_manage_favorites_cb,
222 "chat_add_contact", "activate", main_window_chat_add_contact_cb,
223 "chat_show_offline", "toggled", main_window_chat_show_offline_cb,
224 "edit", "button-press-event", main_window_edit_button_press_event_cb,
225 "edit_accounts", "activate", main_window_edit_accounts_cb,
226 "edit_personal_information", "activate", main_window_edit_personal_information_cb,
227 "edit_preferences", "activate", main_window_edit_preferences_cb,
228 "help_about", "activate", main_window_help_about_cb,
229 "help_contents", "activate", main_window_help_contents_cb,
232 /* Set up connection related widgets. */
233 main_window_connection_items_setup (window, glade);
234 g_object_unref (glade);
236 window->mc = empathy_mission_control_new ();
237 dbus_g_proxy_connect_signal (DBUS_G_PROXY (window->mc), "AccountStatusChanged",
238 G_CALLBACK (main_window_status_changed_cb),
241 window->errors = g_hash_table_new_full (empathy_account_hash,
242 empathy_account_equal,
247 main_window_favorite_chatroom_menu_setup (window);
249 gtk_widget_hide (window->edit_context);
250 gtk_widget_hide (window->edit_context_separator);
252 /* Set up presence chooser */
253 window->presence_chooser = empathy_presence_chooser_new ();
254 gtk_widget_show (window->presence_chooser);
255 item = gtk_tool_item_new ();
256 gtk_widget_show (GTK_WIDGET (item));
257 gtk_container_add (GTK_CONTAINER (item), window->presence_chooser);
258 gtk_tool_item_set_is_important (item, TRUE);
259 gtk_tool_item_set_expand (item, TRUE);
260 gtk_toolbar_insert (GTK_TOOLBAR (window->presence_toolbar), item, -1);
262 /* Set up the throbber */
263 ebox = gtk_event_box_new ();
264 gtk_event_box_set_visible_window (GTK_EVENT_BOX (ebox), FALSE);
265 gtk_widget_set_tooltip_text (ebox, _("Show and edit accounts"));
266 g_signal_connect (ebox,
267 "button-press-event",
268 G_CALLBACK (main_window_throbber_button_press_event_cb),
270 gtk_widget_show (ebox);
272 window->throbber = ephy_spinner_new ();
273 ephy_spinner_set_size (EPHY_SPINNER (window->throbber), GTK_ICON_SIZE_LARGE_TOOLBAR);
274 gtk_container_add (GTK_CONTAINER (ebox), window->throbber);
275 gtk_widget_show (window->throbber);
277 item = gtk_tool_item_new ();
278 gtk_container_add (GTK_CONTAINER (item), ebox);
279 gtk_toolbar_insert (GTK_TOOLBAR (window->presence_toolbar), item, -1);
280 gtk_widget_show (GTK_WIDGET (item));
282 /* Set up contact list. */
283 empathy_status_presets_get_all ();
285 list_iface = EMPATHY_CONTACT_LIST (empathy_contact_manager_new ());
286 window->list_store = empathy_contact_list_store_new (list_iface);
287 window->list_view = empathy_contact_list_view_new (window->list_store);
288 empathy_contact_list_view_set_interactive (window->list_view, TRUE);
289 g_object_unref (list_iface);
291 gtk_widget_show (GTK_WIDGET (window->list_view));
292 gtk_container_add (GTK_CONTAINER (sw),
293 GTK_WIDGET (window->list_view));
295 /* Load user-defined accelerators. */
296 main_window_accels_load ();
298 /* Set window size. */
299 empathy_geometry_load (GEOMETRY_NAME, &x, &y, &w, &h);
301 if (w >= 1 && h >= 1) {
302 /* Use the defaults from the glade file if we
303 * don't have good w, h geometry.
305 empathy_debug (DEBUG_DOMAIN, "Configuring window default size w:%d, h:%d", w, h);
306 gtk_window_set_default_size (GTK_WINDOW (window->window), w, h);
309 if (x >= 0 && y >= 0) {
310 /* Let the window manager position it if we
311 * don't have good x, y coordinates.
313 empathy_debug (DEBUG_DOMAIN, "Configuring window default position x:%d, y:%d", x, y);
314 gtk_window_move (GTK_WINDOW (window->window), x, y);
317 conf = empathy_conf_get ();
320 empathy_conf_get_bool (conf,
321 EMPATHY_PREFS_CONTACTS_SHOW_OFFLINE,
323 empathy_conf_notify_add (conf,
324 EMPATHY_PREFS_CONTACTS_SHOW_OFFLINE,
325 main_window_notify_show_offline_cb,
326 show_offline_widget);
328 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (show_offline_widget),
332 empathy_conf_get_bool (conf,
333 EMPATHY_PREFS_UI_SHOW_AVATARS,
335 empathy_conf_notify_add (conf,
336 EMPATHY_PREFS_UI_SHOW_AVATARS,
337 (EmpathyConfNotifyFunc) main_window_notify_show_avatars_cb,
339 empathy_contact_list_store_set_show_avatars (window->list_store, show_avatars);
342 empathy_conf_get_bool (conf,
343 EMPATHY_PREFS_UI_COMPACT_CONTACT_LIST,
344 &compact_contact_list);
345 empathy_conf_notify_add (conf,
346 EMPATHY_PREFS_UI_COMPACT_CONTACT_LIST,
347 (EmpathyConfNotifyFunc) main_window_notify_compact_contact_list_cb,
349 empathy_contact_list_store_set_is_compact (window->list_store, compact_contact_list);
352 empathy_conf_notify_add (conf,
353 EMPATHY_PREFS_CONTACTS_SORT_CRITERIUM,
354 (EmpathyConfNotifyFunc) main_window_notify_sort_criterium_cb,
356 main_window_notify_sort_criterium_cb (conf,
357 EMPATHY_PREFS_CONTACTS_SORT_CRITERIUM,
360 main_window_update_status (window);
362 return window->window;
366 main_window_destroy_cb (GtkWidget *widget,
367 EmpathyMainWindow *window)
369 /* Save user-defined accelerators. */
370 main_window_accels_save ();
372 dbus_g_proxy_disconnect_signal (DBUS_G_PROXY (window->mc), "AccountStatusChanged",
373 G_CALLBACK (main_window_status_changed_cb),
376 if (window->size_timeout_id) {
377 g_source_remove (window->size_timeout_id);
380 g_list_free (window->widgets_connected);
381 g_list_free (window->widgets_disconnected);
383 g_object_unref (window->mc);
384 g_object_unref (window->list_store);
385 g_hash_table_destroy (window->errors);
391 main_window_favorite_chatroom_menu_setup (EmpathyMainWindow *window)
393 GList *chatrooms, *l;
395 window->chatroom_manager = empathy_chatroom_manager_new ();
396 chatrooms = empathy_chatroom_manager_get_chatrooms (window->chatroom_manager, NULL);
397 window->room_menu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (window->room));
399 for (l = chatrooms; l; l = l->next) {
400 main_window_favorite_chatroom_menu_add (window, l->data);
404 gtk_widget_hide (window->room_sep);
407 gtk_widget_set_sensitive (window->room_join_favorites, chatrooms != NULL);
409 g_signal_connect (window->chatroom_manager, "chatroom-added",
410 G_CALLBACK (main_window_favorite_chatroom_menu_added_cb),
412 g_signal_connect (window->chatroom_manager, "chatroom-removed",
413 G_CALLBACK (main_window_favorite_chatroom_menu_removed_cb),
416 g_list_free (chatrooms);
420 main_window_favorite_chatroom_menu_added_cb (EmpathyChatroomManager *manager,
421 EmpathyChatroom *chatroom,
422 EmpathyMainWindow *window)
424 main_window_favorite_chatroom_menu_add (window, chatroom);
425 gtk_widget_show (window->room_sep);
426 gtk_widget_set_sensitive (window->room_join_favorites, TRUE);
430 main_window_favorite_chatroom_menu_removed_cb (EmpathyChatroomManager *manager,
431 EmpathyChatroom *chatroom,
432 EmpathyMainWindow *window)
434 GtkWidget *menu_item;
436 menu_item = g_object_get_data (G_OBJECT (chatroom), "menu_item");
438 g_object_set_data (G_OBJECT (chatroom), "menu_item", NULL);
439 gtk_widget_destroy (menu_item);
441 main_window_favorite_chatroom_menu_update (window);
445 main_window_favorite_chatroom_menu_activate_cb (GtkMenuItem *menu_item,
446 EmpathyChatroom *chatroom)
448 main_window_favorite_chatroom_join (chatroom);
452 main_window_favorite_chatroom_menu_update (EmpathyMainWindow *window)
456 chatrooms = empathy_chatroom_manager_get_chatrooms (window->chatroom_manager, NULL);
459 gtk_widget_show (window->room_sep);
461 gtk_widget_hide (window->room_sep);
464 gtk_widget_set_sensitive (window->room_join_favorites, chatrooms != NULL);
465 g_list_free (chatrooms);
469 main_window_favorite_chatroom_menu_add (EmpathyMainWindow *window,
470 EmpathyChatroom *chatroom)
472 GtkWidget *menu_item;
475 if (g_object_get_data (G_OBJECT (chatroom), "menu_item")) {
479 name = empathy_chatroom_get_name (chatroom);
480 menu_item = gtk_menu_item_new_with_label (name);
482 g_object_set_data (G_OBJECT (chatroom), "menu_item", menu_item);
483 g_signal_connect (menu_item, "activate",
484 G_CALLBACK (main_window_favorite_chatroom_menu_activate_cb),
487 gtk_menu_shell_insert (GTK_MENU_SHELL (window->room_menu),
490 gtk_widget_show (menu_item);
494 main_window_favorite_chatroom_join (EmpathyChatroom *chatroom)
500 mc = empathy_mission_control_new ();
501 account = empathy_chatroom_get_account (chatroom);
502 room = empathy_chatroom_get_room (chatroom);
504 empathy_debug (DEBUG_DOMAIN, "Requesting channel for '%s'", room);
506 mission_control_request_channel_with_string_handle (mc,
508 TP_IFACE_CHANNEL_TYPE_TEXT,
516 main_window_chat_quit_cb (GtkWidget *widget,
517 EmpathyMainWindow *window)
523 main_window_chat_new_message_cb (GtkWidget *widget,
524 EmpathyMainWindow *window)
526 //empathy_new_message_dialog_show (GTK_WINDOW (window->window));
530 main_window_chat_history_cb (GtkWidget *widget,
531 EmpathyMainWindow *window)
533 empathy_log_window_show (NULL, NULL, FALSE, GTK_WINDOW (window->window));
537 main_window_room_join_new_cb (GtkWidget *widget,
538 EmpathyMainWindow *window)
540 empathy_new_chatroom_dialog_show (GTK_WINDOW (window->window));
544 main_window_room_join_favorites_cb (GtkWidget *widget,
545 EmpathyMainWindow *window)
547 GList *chatrooms, *l;
549 chatrooms = empathy_chatroom_manager_get_chatrooms (window->chatroom_manager, NULL);
550 for (l = chatrooms; l; l = l->next) {
551 main_window_favorite_chatroom_join (l->data);
553 g_list_free (chatrooms);
557 main_window_room_manage_favorites_cb (GtkWidget *widget,
558 EmpathyMainWindow *window)
560 empathy_chatrooms_window_show (GTK_WINDOW (window->window));
564 main_window_chat_add_contact_cb (GtkWidget *widget,
565 EmpathyMainWindow *window)
567 empathy_new_contact_dialog_show (GTK_WINDOW (window->window));
571 main_window_chat_show_offline_cb (GtkCheckMenuItem *item,
572 EmpathyMainWindow *window)
576 current = gtk_check_menu_item_get_active (item);
578 empathy_conf_set_bool (empathy_conf_get (),
579 EMPATHY_PREFS_CONTACTS_SHOW_OFFLINE,
582 /* Turn off sound just while we alter the contact list. */
583 // FIXME: empathy_sound_set_enabled (FALSE);
584 empathy_contact_list_store_set_show_offline (window->list_store, current);
585 //empathy_sound_set_enabled (TRUE);
589 main_window_edit_button_press_event_cb (GtkWidget *widget,
590 GdkEventButton *event,
591 EmpathyMainWindow *window)
593 EmpathyContact *contact;
596 if (!event->button == 1) {
600 group = empathy_contact_list_view_get_selected_group (window->list_view);
606 item = GTK_MENU_ITEM (window->edit_context);
607 label = gtk_bin_get_child (GTK_BIN (item));
608 gtk_label_set_text (GTK_LABEL (label), _("Group"));
610 gtk_widget_show (window->edit_context);
611 gtk_widget_show (window->edit_context_separator);
613 submenu = empathy_contact_list_view_get_group_menu (window->list_view);
614 gtk_menu_item_set_submenu (item, submenu);
621 contact = empathy_contact_list_view_get_selected (window->list_view);
627 item = GTK_MENU_ITEM (window->edit_context);
628 label = gtk_bin_get_child (GTK_BIN (item));
629 gtk_label_set_text (GTK_LABEL (label), _("Contact"));
631 gtk_widget_show (window->edit_context);
632 gtk_widget_show (window->edit_context_separator);
634 submenu = empathy_contact_list_view_get_contact_menu (window->list_view,
636 gtk_menu_item_set_submenu (item, submenu);
638 g_object_unref (contact);
643 gtk_widget_hide (window->edit_context);
644 gtk_widget_hide (window->edit_context_separator);
650 main_window_edit_accounts_cb (GtkWidget *widget,
651 EmpathyMainWindow *window)
653 empathy_accounts_dialog_show (GTK_WINDOW (window->window));
657 main_window_edit_personal_information_cb (GtkWidget *widget,
658 EmpathyMainWindow *window)
662 accounts = mission_control_get_online_connections (window->mc, NULL);
664 EmpathyContactFactory *factory;
665 EmpathyContact *contact;
668 account = accounts->data;
669 factory = empathy_contact_factory_new ();
670 contact = empathy_contact_factory_get_user (factory, account);
671 empathy_contact_information_dialog_show (contact,
672 GTK_WINDOW (window->window),
674 g_slist_foreach (accounts, (GFunc) g_object_unref, NULL);
675 g_slist_free (accounts);
676 g_object_unref (factory);
677 g_object_unref (contact);
682 main_window_edit_preferences_cb (GtkWidget *widget,
683 EmpathyMainWindow *window)
685 empathy_preferences_show (GTK_WINDOW (window->window));
689 main_window_help_about_cb (GtkWidget *widget,
690 EmpathyMainWindow *window)
692 empathy_about_dialog_new (GTK_WINDOW (window->window));
696 main_window_help_contents_cb (GtkWidget *widget,
697 EmpathyMainWindow *window)
699 //empathy_help_show ();
703 main_window_throbber_button_press_event_cb (GtkWidget *throbber_ebox,
704 GdkEventButton *event,
705 EmpathyMainWindow *window)
707 if (event->type != GDK_BUTTON_PRESS ||
708 event->button != 1) {
712 empathy_accounts_dialog_show (GTK_WINDOW (window->window));
718 main_window_error_edit_clicked_cb (GtkButton *button,
719 EmpathyMainWindow *window)
722 GtkWidget *error_widget;
724 empathy_accounts_dialog_show (GTK_WINDOW (window->window));
726 account = g_object_get_data (G_OBJECT (button), "account");
727 error_widget = g_hash_table_lookup (window->errors, account);
728 gtk_widget_destroy (error_widget);
729 g_hash_table_remove (window->errors, account);
733 main_window_error_clear_clicked_cb (GtkButton *button,
734 EmpathyMainWindow *window)
737 GtkWidget *error_widget;
739 account = g_object_get_data (G_OBJECT (button), "account");
740 error_widget = g_hash_table_lookup (window->errors, account);
741 gtk_widget_destroy (error_widget);
742 g_hash_table_remove (window->errors, account);
746 main_window_error_display (EmpathyMainWindow *window,
748 const gchar *message)
753 GtkWidget *button_edit;
754 GtkWidget *alignment;
759 GtkWidget *button_close;
762 child = g_hash_table_lookup (window->errors, account);
764 label = g_object_get_data (G_OBJECT (child), "label");
766 /* Just set the latest error and return */
767 str = g_markup_printf_escaped ("<b>%s</b>\n%s",
768 mc_account_get_display_name (account),
770 gtk_label_set_markup (GTK_LABEL (label), str);
776 child = gtk_vbox_new (FALSE, 0);
777 gtk_box_pack_start (GTK_BOX (window->errors_vbox), child, FALSE, TRUE, 0);
778 gtk_container_set_border_width (GTK_CONTAINER (child), 6);
779 gtk_widget_show (child);
781 table = gtk_table_new (2, 4, FALSE);
782 gtk_widget_show (table);
783 gtk_box_pack_start (GTK_BOX (child), table, TRUE, TRUE, 0);
784 gtk_table_set_row_spacings (GTK_TABLE (table), 12);
785 gtk_table_set_col_spacings (GTK_TABLE (table), 6);
787 image = gtk_image_new_from_stock (GTK_STOCK_DISCONNECT, GTK_ICON_SIZE_MENU);
788 gtk_widget_show (image);
789 gtk_table_attach (GTK_TABLE (table), image, 0, 1, 0, 2,
790 (GtkAttachOptions) (GTK_FILL),
791 (GtkAttachOptions) (GTK_FILL), 0, 0);
792 gtk_misc_set_alignment (GTK_MISC (image), 0.5, 0);
794 button_edit = gtk_button_new ();
795 gtk_widget_show (button_edit);
796 gtk_table_attach (GTK_TABLE (table), button_edit, 1, 2, 1, 2,
797 (GtkAttachOptions) (GTK_FILL),
798 (GtkAttachOptions) (0), 0, 0);
800 alignment = gtk_alignment_new (0.5, 0.5, 0, 0);
801 gtk_widget_show (alignment);
802 gtk_container_add (GTK_CONTAINER (button_edit), alignment);
804 hbox = gtk_hbox_new (FALSE, 2);
805 gtk_widget_show (hbox);
806 gtk_container_add (GTK_CONTAINER (alignment), hbox);
808 image = gtk_image_new_from_stock (GTK_STOCK_EDIT, GTK_ICON_SIZE_BUTTON);
809 gtk_widget_show (image);
810 gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
812 label = gtk_label_new_with_mnemonic (_("Edit Account _Details"));
813 gtk_widget_show (label);
814 gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
816 fixed = gtk_fixed_new ();
817 gtk_widget_show (fixed);
818 gtk_table_attach (GTK_TABLE (table), fixed, 2, 3, 1, 2,
819 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
820 (GtkAttachOptions) (GTK_FILL), 0, 0);
822 vbox = gtk_vbox_new (FALSE, 6);
823 gtk_widget_show (vbox);
824 gtk_table_attach (GTK_TABLE (table), vbox, 3, 4, 0, 2,
825 (GtkAttachOptions) (GTK_FILL),
826 (GtkAttachOptions) (GTK_FILL), 0, 0);
828 button_close = gtk_button_new ();
829 gtk_widget_show (button_close);
830 gtk_box_pack_start (GTK_BOX (vbox), button_close, FALSE, FALSE, 0);
831 gtk_button_set_relief (GTK_BUTTON (button_close), GTK_RELIEF_NONE);
834 image = gtk_image_new_from_stock ("gtk-close", GTK_ICON_SIZE_MENU);
835 gtk_widget_show (image);
836 gtk_container_add (GTK_CONTAINER (button_close), image);
838 label = gtk_label_new ("");
839 gtk_widget_show (label);
840 gtk_table_attach (GTK_TABLE (table), label, 1, 3, 0, 1,
841 (GtkAttachOptions) (GTK_EXPAND | GTK_SHRINK | GTK_FILL),
842 (GtkAttachOptions) (GTK_EXPAND | GTK_SHRINK | GTK_FILL), 0, 0);
843 gtk_widget_set_size_request (label, 175, -1);
844 gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
845 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
846 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
848 str = g_markup_printf_escaped ("<b>%s</b>\n%s",
849 mc_account_get_display_name (account),
851 gtk_label_set_markup (GTK_LABEL (label), str);
854 g_object_set_data (G_OBJECT (child), "label", label);
855 g_object_set_data_full (G_OBJECT (button_edit),
856 "account", g_object_ref (account),
858 g_object_set_data_full (G_OBJECT (button_close),
859 "account", g_object_ref (account),
862 g_signal_connect (button_edit, "clicked",
863 G_CALLBACK (main_window_error_edit_clicked_cb),
866 g_signal_connect (button_close, "clicked",
867 G_CALLBACK (main_window_error_clear_clicked_cb),
870 gtk_widget_show (window->errors_vbox);
872 g_hash_table_insert (window->errors, g_object_ref (account), child);
876 main_window_status_changed_cb (MissionControl *mc,
877 TelepathyConnectionStatus status,
879 TelepathyConnectionStatusReason reason,
880 const gchar *unique_name,
881 EmpathyMainWindow *window)
885 main_window_update_status (window);
887 account = mc_account_lookup (unique_name);
889 if (status == TP_CONN_STATUS_DISCONNECTED &&
890 reason > TP_CONN_STATUS_REASON_REQUESTED) {
891 const gchar *message;
894 case TP_CONN_STATUS_REASON_NETWORK_ERROR:
895 message = _("Network error");
897 case TP_CONN_STATUS_REASON_AUTHENTICATION_FAILED:
898 message = _("Authentication failed");
900 case TP_CONN_STATUS_REASON_ENCRYPTION_ERROR:
901 message = _("Encryption error");
903 case TP_CONN_STATUS_REASON_NAME_IN_USE:
904 message = _("Name in use");
906 case TP_CONN_STATUS_REASON_CERT_NOT_PROVIDED:
907 message = _("Certificate not provided");
909 case TP_CONN_STATUS_REASON_CERT_UNTRUSTED:
910 message = _("Certificate untrusted");
912 case TP_CONN_STATUS_REASON_CERT_EXPIRED:
913 message = _("Certificate expired");
915 case TP_CONN_STATUS_REASON_CERT_NOT_ACTIVATED:
916 message = _("Certificate not activated");
918 case TP_CONN_STATUS_REASON_CERT_HOSTNAME_MISMATCH:
919 message = _("Certificate hostname mismatch");
921 case TP_CONN_STATUS_REASON_CERT_FINGERPRINT_MISMATCH:
922 message = _("Certificate fingerprint mismatch");
924 case TP_CONN_STATUS_REASON_CERT_SELF_SIGNED:
925 message = _("Certificate self signed");
927 case TP_CONN_STATUS_REASON_CERT_OTHER_ERROR:
928 message = _("Certificate error");
931 message = _("Unknown error");
935 main_window_error_display (window, account, message);
938 if (status == TP_CONN_STATUS_CONNECTED) {
939 GtkWidget *error_widget;
941 /* Account connected without error, remove error message if any */
942 error_widget = g_hash_table_lookup (window->errors, account);
944 gtk_widget_destroy (error_widget);
945 g_hash_table_remove (window->errors, account);
949 g_object_unref (account);
953 main_window_update_status (EmpathyMainWindow *window)
957 guint connecting = 0;
958 guint disconnected = 0;
960 /* Count number of connected/connecting/disconnected accounts */
961 accounts = mc_accounts_list ();
962 for (l = accounts; l; l = l->next) {
968 status = mission_control_get_connection_status (window->mc,
974 } else if (status == 1) {
976 } else if (status == 2) {
980 g_object_unref (account);
982 g_list_free (accounts);
984 /* Update the spinner state */
985 if (connecting > 0) {
986 ephy_spinner_start (EPHY_SPINNER (window->throbber));
988 ephy_spinner_stop (EPHY_SPINNER (window->throbber));
991 /* Update widgets sensibility */
992 for (l = window->widgets_connected; l; l = l->next) {
993 gtk_widget_set_sensitive (l->data, (connected > 0));
996 for (l = window->widgets_disconnected; l; l = l->next) {
997 gtk_widget_set_sensitive (l->data, (disconnected > 0));
1005 main_window_accels_load (void)
1009 filename = g_build_filename (g_get_home_dir (), ".gnome2", PACKAGE_NAME, ACCELS_FILENAME, NULL);
1010 if (g_file_test (filename, G_FILE_TEST_EXISTS)) {
1011 empathy_debug (DEBUG_DOMAIN, "Loading from:'%s'", filename);
1012 gtk_accel_map_load (filename);
1019 main_window_accels_save (void)
1022 gchar *file_with_path;
1024 dir = g_build_filename (g_get_home_dir (), ".gnome2", PACKAGE_NAME, NULL);
1025 g_mkdir_with_parents (dir, S_IRUSR | S_IWUSR | S_IXUSR);
1026 file_with_path = g_build_filename (dir, ACCELS_FILENAME, NULL);
1029 empathy_debug (DEBUG_DOMAIN, "Saving to:'%s'", file_with_path);
1030 gtk_accel_map_save (file_with_path);
1032 g_free (file_with_path);
1036 main_window_connection_items_setup (EmpathyMainWindow *window,
1042 const gchar *widgets_connected[] = {
1046 "edit_personal_information"
1048 const gchar *widgets_disconnected[] = {
1051 for (i = 0, list = NULL; i < G_N_ELEMENTS (widgets_connected); i++) {
1052 w = glade_xml_get_widget (glade, widgets_connected[i]);
1053 list = g_list_prepend (list, w);
1056 window->widgets_connected = list;
1058 for (i = 0, list = NULL; i < G_N_ELEMENTS (widgets_disconnected); i++) {
1059 w = glade_xml_get_widget (glade, widgets_disconnected[i]);
1060 list = g_list_prepend (list, w);
1063 window->widgets_disconnected = list;
1067 main_window_configure_event_timeout_cb (EmpathyMainWindow *window)
1071 gtk_window_get_size (GTK_WINDOW (window->window), &w, &h);
1072 gtk_window_get_position (GTK_WINDOW (window->window), &x, &y);
1074 empathy_geometry_save (GEOMETRY_NAME, x, y, w, h);
1076 window->size_timeout_id = 0;
1082 main_window_configure_event_cb (GtkWidget *widget,
1083 GdkEventConfigure *event,
1084 EmpathyMainWindow *window)
1086 if (window->size_timeout_id) {
1087 g_source_remove (window->size_timeout_id);
1090 window->size_timeout_id = g_timeout_add_seconds (1,
1091 (GSourceFunc) main_window_configure_event_timeout_cb,
1098 main_window_notify_show_offline_cb (EmpathyConf *conf,
1100 gpointer check_menu_item)
1102 gboolean show_offline;
1104 if (empathy_conf_get_bool (conf, key, &show_offline)) {
1105 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (check_menu_item),
1111 main_window_notify_show_avatars_cb (EmpathyConf *conf,
1113 EmpathyMainWindow *window)
1115 gboolean show_avatars;
1117 if (empathy_conf_get_bool (conf, key, &show_avatars)) {
1118 empathy_contact_list_store_set_show_avatars (window->list_store,
1124 main_window_notify_compact_contact_list_cb (EmpathyConf *conf,
1126 EmpathyMainWindow *window)
1128 gboolean compact_contact_list;
1130 if (empathy_conf_get_bool (conf, key, &compact_contact_list)) {
1131 empathy_contact_list_store_set_is_compact (window->list_store,
1132 compact_contact_list);
1137 main_window_notify_sort_criterium_cb (EmpathyConf *conf,
1139 EmpathyMainWindow *window)
1143 if (empathy_conf_get_string (conf, key, &str) && str) {
1145 GEnumClass *enum_class;
1146 GEnumValue *enum_value;
1148 type = empathy_contact_list_store_sort_get_type ();
1149 enum_class = G_ENUM_CLASS (g_type_class_peek (type));
1150 enum_value = g_enum_get_value_by_nick (enum_class, str);
1154 empathy_contact_list_store_set_sort_criterium (window->list_store,