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-debug.h>
33 #include <libempathy/empathy-utils.h>
34 #include <libempathy/empathy-chatroom-manager.h>
35 #include <libempathy/empathy-chatroom.h>
36 #include <libempathy/empathy-contact-list.h>
37 #include <libempathy/empathy-contact-manager.h>
38 #include <libempathy/empathy-contact-factory.h>
39 #include <libempathy/empathy-status-presets.h>
41 #include <libempathy-gtk/empathy-contact-dialogs.h>
42 #include <libempathy-gtk/empathy-contact-list-store.h>
43 #include <libempathy-gtk/empathy-contact-list-view.h>
44 #include <libempathy-gtk/empathy-presence-chooser.h>
45 #include <libempathy-gtk/empathy-ui-utils.h>
46 #include <libempathy-gtk/empathy-geometry.h>
47 #include <libempathy-gtk/empathy-conf.h>
48 #include <libempathy-gtk/empathy-accounts-dialog.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 "empathy-main-window.h"
54 #include "ephy-spinner.h"
55 #include "empathy-preferences.h"
56 #include "empathy-about-dialog.h"
57 #include "empathy-new-chatroom-dialog.h"
58 #include "empathy-chatrooms-window.h"
60 #define DEBUG_DOMAIN "MainWindow"
62 /* Minimum width of roster window if something goes wrong. */
65 /* Accels (menu shortcuts) can be configured and saved */
66 #define ACCELS_FILENAME "accels.txt"
68 /* Name in the geometry file */
69 #define GEOMETRY_NAME "main-window"
72 EmpathyContactListView *list_view;
73 EmpathyContactListStore *list_store;
75 EmpathyChatroomManager *chatroom_manager;
80 GtkWidget *presence_toolbar;
81 GtkWidget *presence_chooser;
82 GtkWidget *errors_vbox;
87 GtkWidget *room_join_favorites;
88 GtkWidget *edit_context;
89 GtkWidget *edit_context_separator;
91 guint size_timeout_id;
94 /* Widgets that are enabled when there is... */
95 GList *widgets_connected; /* ... connected accounts */
96 GList *widgets_disconnected; /* ... disconnected accounts */
99 static void main_window_destroy_cb (GtkWidget *widget,
100 EmpathyMainWindow *window);
101 static void main_window_favorite_chatroom_menu_setup (EmpathyMainWindow *window);
102 static void main_window_favorite_chatroom_menu_added_cb (EmpathyChatroomManager *manager,
103 EmpathyChatroom *chatroom,
104 EmpathyMainWindow *window);
105 static void main_window_favorite_chatroom_menu_removed_cb (EmpathyChatroomManager *manager,
106 EmpathyChatroom *chatroom,
107 EmpathyMainWindow *window);
108 static void main_window_favorite_chatroom_menu_activate_cb (GtkMenuItem *menu_item,
109 EmpathyChatroom *chatroom);
110 static void main_window_favorite_chatroom_menu_update (EmpathyMainWindow *window);
111 static void main_window_favorite_chatroom_menu_add (EmpathyMainWindow *window,
112 EmpathyChatroom *chatroom);
113 static void main_window_favorite_chatroom_join (EmpathyChatroom *chatroom);
114 static void main_window_chat_quit_cb (GtkWidget *widget,
115 EmpathyMainWindow *window);
116 static void main_window_chat_new_message_cb (GtkWidget *widget,
117 EmpathyMainWindow *window);
118 static void main_window_chat_history_cb (GtkWidget *widget,
119 EmpathyMainWindow *window);
120 static void main_window_room_join_new_cb (GtkWidget *widget,
121 EmpathyMainWindow *window);
122 static void main_window_room_join_favorites_cb (GtkWidget *widget,
123 EmpathyMainWindow *window);
124 static void main_window_room_manage_favorites_cb (GtkWidget *widget,
125 EmpathyMainWindow *window);
126 static void main_window_chat_add_contact_cb (GtkWidget *widget,
127 EmpathyMainWindow *window);
128 static void main_window_chat_show_offline_cb (GtkCheckMenuItem *item,
129 EmpathyMainWindow *window);
130 static gboolean main_window_edit_button_press_event_cb (GtkWidget *widget,
131 GdkEventButton *event,
132 EmpathyMainWindow *window);
133 static void main_window_edit_accounts_cb (GtkWidget *widget,
134 EmpathyMainWindow *window);
135 static void main_window_edit_personal_information_cb (GtkWidget *widget,
136 EmpathyMainWindow *window);
137 static void main_window_edit_preferences_cb (GtkWidget *widget,
138 EmpathyMainWindow *window);
139 static void main_window_help_about_cb (GtkWidget *widget,
140 EmpathyMainWindow *window);
141 static void main_window_help_contents_cb (GtkWidget *widget,
142 EmpathyMainWindow *window);
143 static gboolean main_window_throbber_button_press_event_cb (GtkWidget *throbber_ebox,
144 GdkEventButton *event,
145 EmpathyMainWindow *window);
146 static void main_window_status_changed_cb (MissionControl *mc,
147 TpConnectionStatus status,
149 TpConnectionStatusReason reason,
150 const gchar *unique_name,
151 EmpathyMainWindow *window);
152 static void main_window_update_status (EmpathyMainWindow *window);
153 static void main_window_accels_load (void);
154 static void main_window_accels_save (void);
155 static void main_window_connection_items_setup (EmpathyMainWindow *window,
157 static gboolean main_window_configure_event_timeout_cb (EmpathyMainWindow *window);
158 static gboolean main_window_configure_event_cb (GtkWidget *widget,
159 GdkEventConfigure *event,
160 EmpathyMainWindow *window);
161 static void main_window_notify_show_offline_cb (EmpathyConf *conf,
163 gpointer check_menu_item);
164 static void main_window_notify_show_avatars_cb (EmpathyConf *conf,
166 EmpathyMainWindow *window);
167 static void main_window_notify_compact_contact_list_cb (EmpathyConf *conf,
169 EmpathyMainWindow *window);
170 static void main_window_notify_sort_criterium_cb (EmpathyConf *conf,
172 EmpathyMainWindow *window);
175 empathy_main_window_show (void)
177 static EmpathyMainWindow *window = NULL;
178 EmpathyContactList *list_iface;
182 GtkWidget *show_offline_widget;
185 gboolean show_offline;
186 gboolean show_avatars;
187 gboolean compact_contact_list;
191 empathy_window_present (GTK_WINDOW (window->window), TRUE);
192 return window->window;
195 window = g_new0 (EmpathyMainWindow, 1);
197 /* Set up interface */
198 glade = empathy_glade_get_file ("empathy-main-window.glade",
201 "main_window", &window->window,
202 "main_vbox", &window->main_vbox,
203 "errors_vbox", &window->errors_vbox,
204 "chat_show_offline", &show_offline_widget,
205 "room", &window->room,
206 "room_sep", &window->room_sep,
207 "room_join_favorites", &window->room_join_favorites,
208 "edit_context", &window->edit_context,
209 "edit_context_separator", &window->edit_context_separator,
210 "presence_toolbar", &window->presence_toolbar,
211 "roster_scrolledwindow", &sw,
214 empathy_glade_connect (glade,
216 "main_window", "destroy", main_window_destroy_cb,
217 "main_window", "configure_event", main_window_configure_event_cb,
218 "chat_quit", "activate", main_window_chat_quit_cb,
219 "chat_new_message", "activate", main_window_chat_new_message_cb,
220 "chat_history", "activate", main_window_chat_history_cb,
221 "room_join_new", "activate", main_window_room_join_new_cb,
222 "room_join_favorites", "activate", main_window_room_join_favorites_cb,
223 "room_manage_favorites", "activate", main_window_room_manage_favorites_cb,
224 "chat_add_contact", "activate", main_window_chat_add_contact_cb,
225 "chat_show_offline", "toggled", main_window_chat_show_offline_cb,
226 "edit", "button-press-event", main_window_edit_button_press_event_cb,
227 "edit_accounts", "activate", main_window_edit_accounts_cb,
228 "edit_personal_information", "activate", main_window_edit_personal_information_cb,
229 "edit_preferences", "activate", main_window_edit_preferences_cb,
230 "help_about", "activate", main_window_help_about_cb,
231 "help_contents", "activate", main_window_help_contents_cb,
234 /* Set up connection related widgets. */
235 main_window_connection_items_setup (window, glade);
236 g_object_unref (glade);
238 window->mc = empathy_mission_control_new ();
239 dbus_g_proxy_connect_signal (DBUS_G_PROXY (window->mc), "AccountStatusChanged",
240 G_CALLBACK (main_window_status_changed_cb),
243 window->errors = g_hash_table_new_full (empathy_account_hash,
244 empathy_account_equal,
249 main_window_favorite_chatroom_menu_setup (window);
251 gtk_widget_hide (window->edit_context);
252 gtk_widget_hide (window->edit_context_separator);
254 /* Set up presence chooser */
255 window->presence_chooser = empathy_presence_chooser_new ();
256 gtk_widget_show (window->presence_chooser);
257 item = gtk_tool_item_new ();
258 gtk_widget_show (GTK_WIDGET (item));
259 gtk_container_add (GTK_CONTAINER (item), window->presence_chooser);
260 gtk_tool_item_set_is_important (item, TRUE);
261 gtk_tool_item_set_expand (item, TRUE);
262 gtk_toolbar_insert (GTK_TOOLBAR (window->presence_toolbar), item, -1);
264 /* Set up the throbber */
265 ebox = gtk_event_box_new ();
266 gtk_event_box_set_visible_window (GTK_EVENT_BOX (ebox), FALSE);
267 gtk_widget_set_tooltip_text (ebox, _("Show and edit accounts"));
268 g_signal_connect (ebox,
269 "button-press-event",
270 G_CALLBACK (main_window_throbber_button_press_event_cb),
272 gtk_widget_show (ebox);
274 window->throbber = ephy_spinner_new ();
275 ephy_spinner_set_size (EPHY_SPINNER (window->throbber), GTK_ICON_SIZE_LARGE_TOOLBAR);
276 gtk_container_add (GTK_CONTAINER (ebox), window->throbber);
277 gtk_widget_show (window->throbber);
279 item = gtk_tool_item_new ();
280 gtk_container_add (GTK_CONTAINER (item), ebox);
281 gtk_toolbar_insert (GTK_TOOLBAR (window->presence_toolbar), item, -1);
282 gtk_widget_show (GTK_WIDGET (item));
284 /* Set up contact list. */
285 empathy_status_presets_get_all ();
287 list_iface = EMPATHY_CONTACT_LIST (empathy_contact_manager_new ());
288 window->list_store = empathy_contact_list_store_new (list_iface);
289 window->list_view = empathy_contact_list_view_new (window->list_store,
290 EMPATHY_CONTACT_LIST_FEATURE_ALL);
291 g_object_unref (list_iface);
293 gtk_widget_show (GTK_WIDGET (window->list_view));
294 gtk_container_add (GTK_CONTAINER (sw),
295 GTK_WIDGET (window->list_view));
297 /* Load user-defined accelerators. */
298 main_window_accels_load ();
300 /* Set window size. */
301 empathy_geometry_load (GEOMETRY_NAME, &x, &y, &w, &h);
303 if (w >= 1 && h >= 1) {
304 /* Use the defaults from the glade file if we
305 * don't have good w, h geometry.
307 empathy_debug (DEBUG_DOMAIN, "Configuring window default size w:%d, h:%d", w, h);
308 gtk_window_set_default_size (GTK_WINDOW (window->window), w, h);
311 if (x >= 0 && y >= 0) {
312 /* Let the window manager position it if we
313 * don't have good x, y coordinates.
315 empathy_debug (DEBUG_DOMAIN, "Configuring window default position x:%d, y:%d", x, y);
316 gtk_window_move (GTK_WINDOW (window->window), x, y);
319 conf = empathy_conf_get ();
322 empathy_conf_get_bool (conf,
323 EMPATHY_PREFS_CONTACTS_SHOW_OFFLINE,
325 empathy_conf_notify_add (conf,
326 EMPATHY_PREFS_CONTACTS_SHOW_OFFLINE,
327 main_window_notify_show_offline_cb,
328 show_offline_widget);
330 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (show_offline_widget),
334 empathy_conf_get_bool (conf,
335 EMPATHY_PREFS_UI_SHOW_AVATARS,
337 empathy_conf_notify_add (conf,
338 EMPATHY_PREFS_UI_SHOW_AVATARS,
339 (EmpathyConfNotifyFunc) main_window_notify_show_avatars_cb,
341 empathy_contact_list_store_set_show_avatars (window->list_store, show_avatars);
344 empathy_conf_get_bool (conf,
345 EMPATHY_PREFS_UI_COMPACT_CONTACT_LIST,
346 &compact_contact_list);
347 empathy_conf_notify_add (conf,
348 EMPATHY_PREFS_UI_COMPACT_CONTACT_LIST,
349 (EmpathyConfNotifyFunc) main_window_notify_compact_contact_list_cb,
351 empathy_contact_list_store_set_is_compact (window->list_store, compact_contact_list);
354 empathy_conf_notify_add (conf,
355 EMPATHY_PREFS_CONTACTS_SORT_CRITERIUM,
356 (EmpathyConfNotifyFunc) main_window_notify_sort_criterium_cb,
358 main_window_notify_sort_criterium_cb (conf,
359 EMPATHY_PREFS_CONTACTS_SORT_CRITERIUM,
362 main_window_update_status (window);
364 return window->window;
368 main_window_destroy_cb (GtkWidget *widget,
369 EmpathyMainWindow *window)
371 /* Save user-defined accelerators. */
372 main_window_accels_save ();
374 dbus_g_proxy_disconnect_signal (DBUS_G_PROXY (window->mc), "AccountStatusChanged",
375 G_CALLBACK (main_window_status_changed_cb),
378 if (window->size_timeout_id) {
379 g_source_remove (window->size_timeout_id);
382 g_list_free (window->widgets_connected);
383 g_list_free (window->widgets_disconnected);
385 g_object_unref (window->mc);
386 g_object_unref (window->list_store);
387 g_hash_table_destroy (window->errors);
393 main_window_favorite_chatroom_menu_setup (EmpathyMainWindow *window)
395 GList *chatrooms, *l;
397 window->chatroom_manager = empathy_chatroom_manager_new ();
398 chatrooms = empathy_chatroom_manager_get_chatrooms (window->chatroom_manager, NULL);
399 window->room_menu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (window->room));
401 for (l = chatrooms; l; l = l->next) {
402 main_window_favorite_chatroom_menu_add (window, l->data);
406 gtk_widget_hide (window->room_sep);
409 gtk_widget_set_sensitive (window->room_join_favorites, chatrooms != NULL);
411 g_signal_connect (window->chatroom_manager, "chatroom-added",
412 G_CALLBACK (main_window_favorite_chatroom_menu_added_cb),
414 g_signal_connect (window->chatroom_manager, "chatroom-removed",
415 G_CALLBACK (main_window_favorite_chatroom_menu_removed_cb),
418 g_list_free (chatrooms);
422 main_window_favorite_chatroom_menu_added_cb (EmpathyChatroomManager *manager,
423 EmpathyChatroom *chatroom,
424 EmpathyMainWindow *window)
426 main_window_favorite_chatroom_menu_add (window, chatroom);
427 gtk_widget_show (window->room_sep);
428 gtk_widget_set_sensitive (window->room_join_favorites, TRUE);
432 main_window_favorite_chatroom_menu_removed_cb (EmpathyChatroomManager *manager,
433 EmpathyChatroom *chatroom,
434 EmpathyMainWindow *window)
436 GtkWidget *menu_item;
438 menu_item = g_object_get_data (G_OBJECT (chatroom), "menu_item");
440 g_object_set_data (G_OBJECT (chatroom), "menu_item", NULL);
441 gtk_widget_destroy (menu_item);
443 main_window_favorite_chatroom_menu_update (window);
447 main_window_favorite_chatroom_menu_activate_cb (GtkMenuItem *menu_item,
448 EmpathyChatroom *chatroom)
450 main_window_favorite_chatroom_join (chatroom);
454 main_window_favorite_chatroom_menu_update (EmpathyMainWindow *window)
458 chatrooms = empathy_chatroom_manager_get_chatrooms (window->chatroom_manager, NULL);
461 gtk_widget_show (window->room_sep);
463 gtk_widget_hide (window->room_sep);
466 gtk_widget_set_sensitive (window->room_join_favorites, chatrooms != NULL);
467 g_list_free (chatrooms);
471 main_window_favorite_chatroom_menu_add (EmpathyMainWindow *window,
472 EmpathyChatroom *chatroom)
474 GtkWidget *menu_item;
477 if (g_object_get_data (G_OBJECT (chatroom), "menu_item")) {
481 name = empathy_chatroom_get_name (chatroom);
482 menu_item = gtk_menu_item_new_with_label (name);
484 g_object_set_data (G_OBJECT (chatroom), "menu_item", menu_item);
485 g_signal_connect (menu_item, "activate",
486 G_CALLBACK (main_window_favorite_chatroom_menu_activate_cb),
489 gtk_menu_shell_insert (GTK_MENU_SHELL (window->room_menu),
492 gtk_widget_show (menu_item);
496 main_window_favorite_chatroom_join (EmpathyChatroom *chatroom)
502 mc = empathy_mission_control_new ();
503 account = empathy_chatroom_get_account (chatroom);
504 room = empathy_chatroom_get_room (chatroom);
506 empathy_debug (DEBUG_DOMAIN, "Requesting channel for '%s'", room);
508 mission_control_request_channel_with_string_handle (mc,
510 TP_IFACE_CHANNEL_TYPE_TEXT,
518 main_window_chat_quit_cb (GtkWidget *widget,
519 EmpathyMainWindow *window)
525 main_window_chat_new_message_cb (GtkWidget *widget,
526 EmpathyMainWindow *window)
528 empathy_new_message_dialog_show (GTK_WINDOW (window->window));
532 main_window_chat_history_cb (GtkWidget *widget,
533 EmpathyMainWindow *window)
535 empathy_log_window_show (NULL, NULL, FALSE, GTK_WINDOW (window->window));
539 main_window_room_join_new_cb (GtkWidget *widget,
540 EmpathyMainWindow *window)
542 empathy_new_chatroom_dialog_show (GTK_WINDOW (window->window));
546 main_window_room_join_favorites_cb (GtkWidget *widget,
547 EmpathyMainWindow *window)
549 GList *chatrooms, *l;
551 chatrooms = empathy_chatroom_manager_get_chatrooms (window->chatroom_manager, NULL);
552 for (l = chatrooms; l; l = l->next) {
553 main_window_favorite_chatroom_join (l->data);
555 g_list_free (chatrooms);
559 main_window_room_manage_favorites_cb (GtkWidget *widget,
560 EmpathyMainWindow *window)
562 empathy_chatrooms_window_show (GTK_WINDOW (window->window));
566 main_window_chat_add_contact_cb (GtkWidget *widget,
567 EmpathyMainWindow *window)
569 empathy_new_contact_dialog_show (GTK_WINDOW (window->window));
573 main_window_chat_show_offline_cb (GtkCheckMenuItem *item,
574 EmpathyMainWindow *window)
578 current = gtk_check_menu_item_get_active (item);
580 empathy_conf_set_bool (empathy_conf_get (),
581 EMPATHY_PREFS_CONTACTS_SHOW_OFFLINE,
584 /* Turn off sound just while we alter the contact list. */
585 // FIXME: empathy_sound_set_enabled (FALSE);
586 empathy_contact_list_store_set_show_offline (window->list_store, current);
587 //empathy_sound_set_enabled (TRUE);
591 main_window_edit_button_press_event_cb (GtkWidget *widget,
592 GdkEventButton *event,
593 EmpathyMainWindow *window)
595 EmpathyContact *contact;
598 if (!event->button == 1) {
602 group = empathy_contact_list_view_get_selected_group (window->list_view);
608 item = GTK_MENU_ITEM (window->edit_context);
609 label = gtk_bin_get_child (GTK_BIN (item));
610 gtk_label_set_text (GTK_LABEL (label), _("Group"));
612 gtk_widget_show (window->edit_context);
613 gtk_widget_show (window->edit_context_separator);
615 submenu = empathy_contact_list_view_get_group_menu (window->list_view);
616 gtk_menu_item_set_submenu (item, submenu);
623 contact = empathy_contact_list_view_get_selected (window->list_view);
629 item = GTK_MENU_ITEM (window->edit_context);
630 label = gtk_bin_get_child (GTK_BIN (item));
631 gtk_label_set_text (GTK_LABEL (label), _("Contact"));
633 gtk_widget_show (window->edit_context);
634 gtk_widget_show (window->edit_context_separator);
636 submenu = empathy_contact_list_view_get_contact_menu (window->list_view,
638 gtk_menu_item_set_submenu (item, submenu);
640 g_object_unref (contact);
645 gtk_widget_hide (window->edit_context);
646 gtk_widget_hide (window->edit_context_separator);
652 main_window_edit_accounts_cb (GtkWidget *widget,
653 EmpathyMainWindow *window)
655 empathy_accounts_dialog_show (GTK_WINDOW (window->window));
659 main_window_edit_personal_information_cb (GtkWidget *widget,
660 EmpathyMainWindow *window)
664 accounts = mission_control_get_online_connections (window->mc, NULL);
666 EmpathyContactFactory *factory;
667 EmpathyContact *contact;
670 account = accounts->data;
671 factory = empathy_contact_factory_new ();
672 contact = empathy_contact_factory_get_user (factory, account);
673 empathy_contact_run_until_ready (contact,
674 EMPATHY_CONTACT_READY_HANDLE |
675 EMPATHY_CONTACT_READY_ID,
678 empathy_contact_information_dialog_show (contact,
679 GTK_WINDOW (window->window),
682 g_slist_foreach (accounts, (GFunc) g_object_unref, NULL);
683 g_slist_free (accounts);
684 g_object_unref (factory);
685 g_object_unref (contact);
690 main_window_edit_preferences_cb (GtkWidget *widget,
691 EmpathyMainWindow *window)
693 empathy_preferences_show (GTK_WINDOW (window->window));
697 main_window_help_about_cb (GtkWidget *widget,
698 EmpathyMainWindow *window)
700 empathy_about_dialog_new (GTK_WINDOW (window->window));
704 main_window_help_contents_cb (GtkWidget *widget,
705 EmpathyMainWindow *window)
707 //empathy_help_show ();
711 main_window_throbber_button_press_event_cb (GtkWidget *throbber_ebox,
712 GdkEventButton *event,
713 EmpathyMainWindow *window)
715 if (event->type != GDK_BUTTON_PRESS ||
716 event->button != 1) {
720 empathy_accounts_dialog_show (GTK_WINDOW (window->window));
726 main_window_error_edit_clicked_cb (GtkButton *button,
727 EmpathyMainWindow *window)
730 GtkWidget *error_widget;
732 empathy_accounts_dialog_show (GTK_WINDOW (window->window));
734 account = g_object_get_data (G_OBJECT (button), "account");
735 error_widget = g_hash_table_lookup (window->errors, account);
736 gtk_widget_destroy (error_widget);
737 g_hash_table_remove (window->errors, account);
741 main_window_error_clear_clicked_cb (GtkButton *button,
742 EmpathyMainWindow *window)
745 GtkWidget *error_widget;
747 account = g_object_get_data (G_OBJECT (button), "account");
748 error_widget = g_hash_table_lookup (window->errors, account);
749 gtk_widget_destroy (error_widget);
750 g_hash_table_remove (window->errors, account);
754 main_window_error_display (EmpathyMainWindow *window,
756 const gchar *message)
761 GtkWidget *button_edit;
762 GtkWidget *alignment;
767 GtkWidget *button_close;
770 child = g_hash_table_lookup (window->errors, account);
772 label = g_object_get_data (G_OBJECT (child), "label");
774 /* Just set the latest error and return */
775 str = g_markup_printf_escaped ("<b>%s</b>\n%s",
776 mc_account_get_display_name (account),
778 gtk_label_set_markup (GTK_LABEL (label), str);
784 child = gtk_vbox_new (FALSE, 0);
785 gtk_box_pack_start (GTK_BOX (window->errors_vbox), child, FALSE, TRUE, 0);
786 gtk_container_set_border_width (GTK_CONTAINER (child), 6);
787 gtk_widget_show (child);
789 table = gtk_table_new (2, 4, FALSE);
790 gtk_widget_show (table);
791 gtk_box_pack_start (GTK_BOX (child), table, TRUE, TRUE, 0);
792 gtk_table_set_row_spacings (GTK_TABLE (table), 12);
793 gtk_table_set_col_spacings (GTK_TABLE (table), 6);
795 image = gtk_image_new_from_stock (GTK_STOCK_DISCONNECT, GTK_ICON_SIZE_MENU);
796 gtk_widget_show (image);
797 gtk_table_attach (GTK_TABLE (table), image, 0, 1, 0, 2,
798 (GtkAttachOptions) (GTK_FILL),
799 (GtkAttachOptions) (GTK_FILL), 0, 0);
800 gtk_misc_set_alignment (GTK_MISC (image), 0.5, 0);
802 button_edit = gtk_button_new ();
803 gtk_widget_show (button_edit);
804 gtk_table_attach (GTK_TABLE (table), button_edit, 1, 2, 1, 2,
805 (GtkAttachOptions) (GTK_FILL),
806 (GtkAttachOptions) (0), 0, 0);
808 alignment = gtk_alignment_new (0.5, 0.5, 0, 0);
809 gtk_widget_show (alignment);
810 gtk_container_add (GTK_CONTAINER (button_edit), alignment);
812 hbox = gtk_hbox_new (FALSE, 2);
813 gtk_widget_show (hbox);
814 gtk_container_add (GTK_CONTAINER (alignment), hbox);
816 image = gtk_image_new_from_stock (GTK_STOCK_EDIT, GTK_ICON_SIZE_BUTTON);
817 gtk_widget_show (image);
818 gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
820 label = gtk_label_new_with_mnemonic (_("_Edit account"));
821 gtk_widget_show (label);
822 gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
824 fixed = gtk_fixed_new ();
825 gtk_widget_show (fixed);
826 gtk_table_attach (GTK_TABLE (table), fixed, 2, 3, 1, 2,
827 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
828 (GtkAttachOptions) (GTK_FILL), 0, 0);
830 vbox = gtk_vbox_new (FALSE, 6);
831 gtk_widget_show (vbox);
832 gtk_table_attach (GTK_TABLE (table), vbox, 3, 4, 0, 2,
833 (GtkAttachOptions) (GTK_FILL),
834 (GtkAttachOptions) (GTK_FILL), 0, 0);
836 button_close = gtk_button_new ();
837 gtk_widget_show (button_close);
838 gtk_box_pack_start (GTK_BOX (vbox), button_close, FALSE, FALSE, 0);
839 gtk_button_set_relief (GTK_BUTTON (button_close), GTK_RELIEF_NONE);
842 image = gtk_image_new_from_stock ("gtk-close", GTK_ICON_SIZE_MENU);
843 gtk_widget_show (image);
844 gtk_container_add (GTK_CONTAINER (button_close), image);
846 label = gtk_label_new ("");
847 gtk_widget_show (label);
848 gtk_table_attach (GTK_TABLE (table), label, 1, 3, 0, 1,
849 (GtkAttachOptions) (GTK_EXPAND | GTK_SHRINK | GTK_FILL),
850 (GtkAttachOptions) (GTK_EXPAND | GTK_SHRINK | GTK_FILL), 0, 0);
851 gtk_widget_set_size_request (label, 175, -1);
852 gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
853 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
854 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
856 str = g_markup_printf_escaped ("<b>%s</b>\n%s",
857 mc_account_get_display_name (account),
859 gtk_label_set_markup (GTK_LABEL (label), str);
862 g_object_set_data (G_OBJECT (child), "label", label);
863 g_object_set_data_full (G_OBJECT (button_edit),
864 "account", g_object_ref (account),
866 g_object_set_data_full (G_OBJECT (button_close),
867 "account", g_object_ref (account),
870 g_signal_connect (button_edit, "clicked",
871 G_CALLBACK (main_window_error_edit_clicked_cb),
874 g_signal_connect (button_close, "clicked",
875 G_CALLBACK (main_window_error_clear_clicked_cb),
878 gtk_widget_show (window->errors_vbox);
880 g_hash_table_insert (window->errors, g_object_ref (account), child);
884 main_window_status_changed_cb (MissionControl *mc,
885 TpConnectionStatus status,
887 TpConnectionStatusReason reason,
888 const gchar *unique_name,
889 EmpathyMainWindow *window)
893 main_window_update_status (window);
895 account = mc_account_lookup (unique_name);
897 if (status == TP_CONNECTION_STATUS_DISCONNECTED &&
898 reason > TP_CONNECTION_STATUS_REASON_REQUESTED) {
899 const gchar *message;
902 case TP_CONNECTION_STATUS_REASON_NETWORK_ERROR:
903 message = _("Network error");
905 case TP_CONNECTION_STATUS_REASON_AUTHENTICATION_FAILED:
906 message = _("Authentication failed");
908 case TP_CONNECTION_STATUS_REASON_ENCRYPTION_ERROR:
909 message = _("Encryption error");
911 case TP_CONNECTION_STATUS_REASON_NAME_IN_USE:
912 message = _("Name in use");
914 case TP_CONNECTION_STATUS_REASON_CERT_NOT_PROVIDED:
915 message = _("Certificate not provided");
917 case TP_CONNECTION_STATUS_REASON_CERT_UNTRUSTED:
918 message = _("Certificate untrusted");
920 case TP_CONNECTION_STATUS_REASON_CERT_EXPIRED:
921 message = _("Certificate expired");
923 case TP_CONNECTION_STATUS_REASON_CERT_NOT_ACTIVATED:
924 message = _("Certificate not activated");
926 case TP_CONNECTION_STATUS_REASON_CERT_HOSTNAME_MISMATCH:
927 message = _("Certificate hostname mismatch");
929 case TP_CONNECTION_STATUS_REASON_CERT_FINGERPRINT_MISMATCH:
930 message = _("Certificate fingerprint mismatch");
932 case TP_CONNECTION_STATUS_REASON_CERT_SELF_SIGNED:
933 message = _("Certificate self signed");
935 case TP_CONNECTION_STATUS_REASON_CERT_OTHER_ERROR:
936 message = _("Certificate error");
939 message = _("Unknown error");
943 main_window_error_display (window, account, message);
946 if (status == TP_CONNECTION_STATUS_CONNECTED) {
947 GtkWidget *error_widget;
949 /* Account connected without error, remove error message if any */
950 error_widget = g_hash_table_lookup (window->errors, account);
952 gtk_widget_destroy (error_widget);
953 g_hash_table_remove (window->errors, account);
957 g_object_unref (account);
961 main_window_update_status (EmpathyMainWindow *window)
965 guint connecting = 0;
966 guint disconnected = 0;
968 /* Count number of connected/connecting/disconnected accounts */
969 accounts = mc_accounts_list ();
970 for (l = accounts; l; l = l->next) {
976 status = mission_control_get_connection_status (window->mc,
982 } else if (status == 1) {
984 } else if (status == 2) {
988 g_object_unref (account);
990 g_list_free (accounts);
992 /* Update the spinner state */
993 if (connecting > 0) {
994 ephy_spinner_start (EPHY_SPINNER (window->throbber));
996 ephy_spinner_stop (EPHY_SPINNER (window->throbber));
999 /* Update widgets sensibility */
1000 for (l = window->widgets_connected; l; l = l->next) {
1001 gtk_widget_set_sensitive (l->data, (connected > 0));
1004 for (l = window->widgets_disconnected; l; l = l->next) {
1005 gtk_widget_set_sensitive (l->data, (disconnected > 0));
1013 main_window_accels_load (void)
1017 filename = g_build_filename (g_get_home_dir (), ".gnome2", PACKAGE_NAME, ACCELS_FILENAME, NULL);
1018 if (g_file_test (filename, G_FILE_TEST_EXISTS)) {
1019 empathy_debug (DEBUG_DOMAIN, "Loading from:'%s'", filename);
1020 gtk_accel_map_load (filename);
1027 main_window_accels_save (void)
1030 gchar *file_with_path;
1032 dir = g_build_filename (g_get_home_dir (), ".gnome2", PACKAGE_NAME, NULL);
1033 g_mkdir_with_parents (dir, S_IRUSR | S_IWUSR | S_IXUSR);
1034 file_with_path = g_build_filename (dir, ACCELS_FILENAME, NULL);
1037 empathy_debug (DEBUG_DOMAIN, "Saving to:'%s'", file_with_path);
1038 gtk_accel_map_save (file_with_path);
1040 g_free (file_with_path);
1044 main_window_connection_items_setup (EmpathyMainWindow *window,
1050 const gchar *widgets_connected[] = {
1054 "edit_personal_information"
1056 const gchar *widgets_disconnected[] = {
1059 for (i = 0, list = NULL; i < G_N_ELEMENTS (widgets_connected); i++) {
1060 w = glade_xml_get_widget (glade, widgets_connected[i]);
1061 list = g_list_prepend (list, w);
1064 window->widgets_connected = list;
1066 for (i = 0, list = NULL; i < G_N_ELEMENTS (widgets_disconnected); i++) {
1067 w = glade_xml_get_widget (glade, widgets_disconnected[i]);
1068 list = g_list_prepend (list, w);
1071 window->widgets_disconnected = list;
1075 main_window_configure_event_timeout_cb (EmpathyMainWindow *window)
1079 gtk_window_get_size (GTK_WINDOW (window->window), &w, &h);
1080 gtk_window_get_position (GTK_WINDOW (window->window), &x, &y);
1082 empathy_geometry_save (GEOMETRY_NAME, x, y, w, h);
1084 window->size_timeout_id = 0;
1090 main_window_configure_event_cb (GtkWidget *widget,
1091 GdkEventConfigure *event,
1092 EmpathyMainWindow *window)
1094 if (window->size_timeout_id) {
1095 g_source_remove (window->size_timeout_id);
1098 window->size_timeout_id = g_timeout_add_seconds (1,
1099 (GSourceFunc) main_window_configure_event_timeout_cb,
1106 main_window_notify_show_offline_cb (EmpathyConf *conf,
1108 gpointer check_menu_item)
1110 gboolean show_offline;
1112 if (empathy_conf_get_bool (conf, key, &show_offline)) {
1113 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (check_menu_item),
1119 main_window_notify_show_avatars_cb (EmpathyConf *conf,
1121 EmpathyMainWindow *window)
1123 gboolean show_avatars;
1125 if (empathy_conf_get_bool (conf, key, &show_avatars)) {
1126 empathy_contact_list_store_set_show_avatars (window->list_store,
1132 main_window_notify_compact_contact_list_cb (EmpathyConf *conf,
1134 EmpathyMainWindow *window)
1136 gboolean compact_contact_list;
1138 if (empathy_conf_get_bool (conf, key, &compact_contact_list)) {
1139 empathy_contact_list_store_set_is_compact (window->list_store,
1140 compact_contact_list);
1145 main_window_notify_sort_criterium_cb (EmpathyConf *conf,
1147 EmpathyMainWindow *window)
1151 if (empathy_conf_get_string (conf, key, &str) && str) {
1153 GEnumClass *enum_class;
1154 GEnumValue *enum_value;
1156 type = empathy_contact_list_store_sort_get_type ();
1157 enum_class = G_ENUM_CLASS (g_type_class_peek (type));
1158 enum_value = g_enum_get_value_by_nick (enum_class, str);
1162 empathy_contact_list_store_set_sort_criterium (window->list_store,