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;
192 empathy_window_present (GTK_WINDOW (window->window), TRUE);
193 return window->window;
196 window = g_new0 (EmpathyMainWindow, 1);
198 /* Set up interface */
199 filename = empathy_file_lookup ("empathy-main-window.glade", "src");
200 glade = empathy_glade_get_file (filename,
203 "main_window", &window->window,
204 "main_vbox", &window->main_vbox,
205 "errors_vbox", &window->errors_vbox,
206 "chat_show_offline", &show_offline_widget,
207 "room", &window->room,
208 "room_sep", &window->room_sep,
209 "room_join_favorites", &window->room_join_favorites,
210 "edit_context", &window->edit_context,
211 "edit_context_separator", &window->edit_context_separator,
212 "presence_toolbar", &window->presence_toolbar,
213 "roster_scrolledwindow", &sw,
217 empathy_glade_connect (glade,
219 "main_window", "destroy", main_window_destroy_cb,
220 "main_window", "configure_event", main_window_configure_event_cb,
221 "chat_quit", "activate", main_window_chat_quit_cb,
222 "chat_new_message", "activate", main_window_chat_new_message_cb,
223 "chat_history", "activate", main_window_chat_history_cb,
224 "room_join_new", "activate", main_window_room_join_new_cb,
225 "room_join_favorites", "activate", main_window_room_join_favorites_cb,
226 "room_manage_favorites", "activate", main_window_room_manage_favorites_cb,
227 "chat_add_contact", "activate", main_window_chat_add_contact_cb,
228 "chat_show_offline", "toggled", main_window_chat_show_offline_cb,
229 "edit", "button-press-event", main_window_edit_button_press_event_cb,
230 "edit_accounts", "activate", main_window_edit_accounts_cb,
231 "edit_personal_information", "activate", main_window_edit_personal_information_cb,
232 "edit_preferences", "activate", main_window_edit_preferences_cb,
233 "help_about", "activate", main_window_help_about_cb,
234 "help_contents", "activate", main_window_help_contents_cb,
237 /* Set up connection related widgets. */
238 main_window_connection_items_setup (window, glade);
239 g_object_unref (glade);
241 window->mc = empathy_mission_control_new ();
242 dbus_g_proxy_connect_signal (DBUS_G_PROXY (window->mc), "AccountStatusChanged",
243 G_CALLBACK (main_window_status_changed_cb),
246 window->errors = g_hash_table_new_full (empathy_account_hash,
247 empathy_account_equal,
252 main_window_favorite_chatroom_menu_setup (window);
254 gtk_widget_hide (window->edit_context);
255 gtk_widget_hide (window->edit_context_separator);
257 /* Set up presence chooser */
258 window->presence_chooser = empathy_presence_chooser_new ();
259 gtk_widget_show (window->presence_chooser);
260 item = gtk_tool_item_new ();
261 gtk_widget_show (GTK_WIDGET (item));
262 gtk_container_add (GTK_CONTAINER (item), window->presence_chooser);
263 gtk_tool_item_set_is_important (item, TRUE);
264 gtk_tool_item_set_expand (item, TRUE);
265 gtk_toolbar_insert (GTK_TOOLBAR (window->presence_toolbar), item, -1);
267 /* Set up the throbber */
268 ebox = gtk_event_box_new ();
269 gtk_event_box_set_visible_window (GTK_EVENT_BOX (ebox), FALSE);
270 gtk_widget_set_tooltip_text (ebox, _("Show and edit accounts"));
271 g_signal_connect (ebox,
272 "button-press-event",
273 G_CALLBACK (main_window_throbber_button_press_event_cb),
275 gtk_widget_show (ebox);
277 window->throbber = ephy_spinner_new ();
278 ephy_spinner_set_size (EPHY_SPINNER (window->throbber), GTK_ICON_SIZE_LARGE_TOOLBAR);
279 gtk_container_add (GTK_CONTAINER (ebox), window->throbber);
280 gtk_widget_show (window->throbber);
282 item = gtk_tool_item_new ();
283 gtk_container_add (GTK_CONTAINER (item), ebox);
284 gtk_toolbar_insert (GTK_TOOLBAR (window->presence_toolbar), item, -1);
285 gtk_widget_show (GTK_WIDGET (item));
287 /* Set up contact list. */
288 empathy_status_presets_get_all ();
290 list_iface = EMPATHY_CONTACT_LIST (empathy_contact_manager_new ());
291 window->list_store = empathy_contact_list_store_new (list_iface);
292 window->list_view = empathy_contact_list_view_new (window->list_store,
293 EMPATHY_CONTACT_LIST_FEATURE_ALL);
294 g_object_unref (list_iface);
296 gtk_widget_show (GTK_WIDGET (window->list_view));
297 gtk_container_add (GTK_CONTAINER (sw),
298 GTK_WIDGET (window->list_view));
300 /* Load user-defined accelerators. */
301 main_window_accels_load ();
303 /* Set window size. */
304 empathy_geometry_load (GEOMETRY_NAME, &x, &y, &w, &h);
306 if (w >= 1 && h >= 1) {
307 /* Use the defaults from the glade file if we
308 * don't have good w, h geometry.
310 empathy_debug (DEBUG_DOMAIN, "Configuring window default size w:%d, h:%d", w, h);
311 gtk_window_set_default_size (GTK_WINDOW (window->window), w, h);
314 if (x >= 0 && y >= 0) {
315 /* Let the window manager position it if we
316 * don't have good x, y coordinates.
318 empathy_debug (DEBUG_DOMAIN, "Configuring window default position x:%d, y:%d", x, y);
319 gtk_window_move (GTK_WINDOW (window->window), x, y);
322 conf = empathy_conf_get ();
325 empathy_conf_get_bool (conf,
326 EMPATHY_PREFS_CONTACTS_SHOW_OFFLINE,
328 empathy_conf_notify_add (conf,
329 EMPATHY_PREFS_CONTACTS_SHOW_OFFLINE,
330 main_window_notify_show_offline_cb,
331 show_offline_widget);
333 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (show_offline_widget),
337 empathy_conf_get_bool (conf,
338 EMPATHY_PREFS_UI_SHOW_AVATARS,
340 empathy_conf_notify_add (conf,
341 EMPATHY_PREFS_UI_SHOW_AVATARS,
342 (EmpathyConfNotifyFunc) main_window_notify_show_avatars_cb,
344 empathy_contact_list_store_set_show_avatars (window->list_store, show_avatars);
347 empathy_conf_get_bool (conf,
348 EMPATHY_PREFS_UI_COMPACT_CONTACT_LIST,
349 &compact_contact_list);
350 empathy_conf_notify_add (conf,
351 EMPATHY_PREFS_UI_COMPACT_CONTACT_LIST,
352 (EmpathyConfNotifyFunc) main_window_notify_compact_contact_list_cb,
354 empathy_contact_list_store_set_is_compact (window->list_store, compact_contact_list);
357 empathy_conf_notify_add (conf,
358 EMPATHY_PREFS_CONTACTS_SORT_CRITERIUM,
359 (EmpathyConfNotifyFunc) main_window_notify_sort_criterium_cb,
361 main_window_notify_sort_criterium_cb (conf,
362 EMPATHY_PREFS_CONTACTS_SORT_CRITERIUM,
365 main_window_update_status (window);
367 return window->window;
371 main_window_destroy_cb (GtkWidget *widget,
372 EmpathyMainWindow *window)
374 /* Save user-defined accelerators. */
375 main_window_accels_save ();
377 dbus_g_proxy_disconnect_signal (DBUS_G_PROXY (window->mc), "AccountStatusChanged",
378 G_CALLBACK (main_window_status_changed_cb),
381 if (window->size_timeout_id) {
382 g_source_remove (window->size_timeout_id);
385 g_list_free (window->widgets_connected);
386 g_list_free (window->widgets_disconnected);
388 g_object_unref (window->mc);
389 g_object_unref (window->list_store);
390 g_hash_table_destroy (window->errors);
396 main_window_favorite_chatroom_menu_setup (EmpathyMainWindow *window)
398 GList *chatrooms, *l;
400 window->chatroom_manager = empathy_chatroom_manager_new ();
401 chatrooms = empathy_chatroom_manager_get_chatrooms (window->chatroom_manager, NULL);
402 window->room_menu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (window->room));
404 for (l = chatrooms; l; l = l->next) {
405 main_window_favorite_chatroom_menu_add (window, l->data);
409 gtk_widget_hide (window->room_sep);
412 gtk_widget_set_sensitive (window->room_join_favorites, chatrooms != NULL);
414 g_signal_connect (window->chatroom_manager, "chatroom-added",
415 G_CALLBACK (main_window_favorite_chatroom_menu_added_cb),
417 g_signal_connect (window->chatroom_manager, "chatroom-removed",
418 G_CALLBACK (main_window_favorite_chatroom_menu_removed_cb),
421 g_list_free (chatrooms);
425 main_window_favorite_chatroom_menu_added_cb (EmpathyChatroomManager *manager,
426 EmpathyChatroom *chatroom,
427 EmpathyMainWindow *window)
429 main_window_favorite_chatroom_menu_add (window, chatroom);
430 gtk_widget_show (window->room_sep);
431 gtk_widget_set_sensitive (window->room_join_favorites, TRUE);
435 main_window_favorite_chatroom_menu_removed_cb (EmpathyChatroomManager *manager,
436 EmpathyChatroom *chatroom,
437 EmpathyMainWindow *window)
439 GtkWidget *menu_item;
441 menu_item = g_object_get_data (G_OBJECT (chatroom), "menu_item");
443 g_object_set_data (G_OBJECT (chatroom), "menu_item", NULL);
444 gtk_widget_destroy (menu_item);
446 main_window_favorite_chatroom_menu_update (window);
450 main_window_favorite_chatroom_menu_activate_cb (GtkMenuItem *menu_item,
451 EmpathyChatroom *chatroom)
453 main_window_favorite_chatroom_join (chatroom);
457 main_window_favorite_chatroom_menu_update (EmpathyMainWindow *window)
461 chatrooms = empathy_chatroom_manager_get_chatrooms (window->chatroom_manager, NULL);
464 gtk_widget_show (window->room_sep);
466 gtk_widget_hide (window->room_sep);
469 gtk_widget_set_sensitive (window->room_join_favorites, chatrooms != NULL);
470 g_list_free (chatrooms);
474 main_window_favorite_chatroom_menu_add (EmpathyMainWindow *window,
475 EmpathyChatroom *chatroom)
477 GtkWidget *menu_item;
480 if (g_object_get_data (G_OBJECT (chatroom), "menu_item")) {
484 name = empathy_chatroom_get_name (chatroom);
485 menu_item = gtk_menu_item_new_with_label (name);
487 g_object_set_data (G_OBJECT (chatroom), "menu_item", menu_item);
488 g_signal_connect (menu_item, "activate",
489 G_CALLBACK (main_window_favorite_chatroom_menu_activate_cb),
492 gtk_menu_shell_insert (GTK_MENU_SHELL (window->room_menu),
495 gtk_widget_show (menu_item);
499 main_window_favorite_chatroom_join (EmpathyChatroom *chatroom)
505 mc = empathy_mission_control_new ();
506 account = empathy_chatroom_get_account (chatroom);
507 room = empathy_chatroom_get_room (chatroom);
509 empathy_debug (DEBUG_DOMAIN, "Requesting channel for '%s'", room);
511 mission_control_request_channel_with_string_handle (mc,
513 TP_IFACE_CHANNEL_TYPE_TEXT,
521 main_window_chat_quit_cb (GtkWidget *widget,
522 EmpathyMainWindow *window)
528 main_window_chat_new_message_cb (GtkWidget *widget,
529 EmpathyMainWindow *window)
531 empathy_new_message_dialog_show (GTK_WINDOW (window->window));
535 main_window_chat_history_cb (GtkWidget *widget,
536 EmpathyMainWindow *window)
538 empathy_log_window_show (NULL, NULL, FALSE, GTK_WINDOW (window->window));
542 main_window_room_join_new_cb (GtkWidget *widget,
543 EmpathyMainWindow *window)
545 empathy_new_chatroom_dialog_show (GTK_WINDOW (window->window));
549 main_window_room_join_favorites_cb (GtkWidget *widget,
550 EmpathyMainWindow *window)
552 GList *chatrooms, *l;
554 chatrooms = empathy_chatroom_manager_get_chatrooms (window->chatroom_manager, NULL);
555 for (l = chatrooms; l; l = l->next) {
556 main_window_favorite_chatroom_join (l->data);
558 g_list_free (chatrooms);
562 main_window_room_manage_favorites_cb (GtkWidget *widget,
563 EmpathyMainWindow *window)
565 empathy_chatrooms_window_show (GTK_WINDOW (window->window));
569 main_window_chat_add_contact_cb (GtkWidget *widget,
570 EmpathyMainWindow *window)
572 empathy_new_contact_dialog_show (GTK_WINDOW (window->window));
576 main_window_chat_show_offline_cb (GtkCheckMenuItem *item,
577 EmpathyMainWindow *window)
581 current = gtk_check_menu_item_get_active (item);
583 empathy_conf_set_bool (empathy_conf_get (),
584 EMPATHY_PREFS_CONTACTS_SHOW_OFFLINE,
587 /* Turn off sound just while we alter the contact list. */
588 // FIXME: empathy_sound_set_enabled (FALSE);
589 empathy_contact_list_store_set_show_offline (window->list_store, current);
590 //empathy_sound_set_enabled (TRUE);
594 main_window_edit_button_press_event_cb (GtkWidget *widget,
595 GdkEventButton *event,
596 EmpathyMainWindow *window)
598 EmpathyContact *contact;
601 if (!event->button == 1) {
605 group = empathy_contact_list_view_get_selected_group (window->list_view);
611 item = GTK_MENU_ITEM (window->edit_context);
612 label = gtk_bin_get_child (GTK_BIN (item));
613 gtk_label_set_text (GTK_LABEL (label), _("Group"));
615 gtk_widget_show (window->edit_context);
616 gtk_widget_show (window->edit_context_separator);
618 submenu = empathy_contact_list_view_get_group_menu (window->list_view);
619 gtk_menu_item_set_submenu (item, submenu);
626 contact = empathy_contact_list_view_get_selected (window->list_view);
632 item = GTK_MENU_ITEM (window->edit_context);
633 label = gtk_bin_get_child (GTK_BIN (item));
634 gtk_label_set_text (GTK_LABEL (label), _("Contact"));
636 gtk_widget_show (window->edit_context);
637 gtk_widget_show (window->edit_context_separator);
639 submenu = empathy_contact_list_view_get_contact_menu (window->list_view,
641 gtk_menu_item_set_submenu (item, submenu);
643 g_object_unref (contact);
648 gtk_widget_hide (window->edit_context);
649 gtk_widget_hide (window->edit_context_separator);
655 main_window_edit_accounts_cb (GtkWidget *widget,
656 EmpathyMainWindow *window)
658 empathy_accounts_dialog_show (GTK_WINDOW (window->window));
662 main_window_edit_personal_information_cb (GtkWidget *widget,
663 EmpathyMainWindow *window)
667 accounts = mission_control_get_online_connections (window->mc, NULL);
669 EmpathyContactFactory *factory;
670 EmpathyContact *contact;
673 account = accounts->data;
674 factory = empathy_contact_factory_new ();
675 contact = empathy_contact_factory_get_user (factory, account);
676 empathy_contact_run_until_ready (contact,
677 EMPATHY_CONTACT_READY_HANDLE |
678 EMPATHY_CONTACT_READY_ID,
681 empathy_contact_information_dialog_show (contact,
682 GTK_WINDOW (window->window),
685 g_slist_foreach (accounts, (GFunc) g_object_unref, NULL);
686 g_slist_free (accounts);
687 g_object_unref (factory);
688 g_object_unref (contact);
693 main_window_edit_preferences_cb (GtkWidget *widget,
694 EmpathyMainWindow *window)
696 empathy_preferences_show (GTK_WINDOW (window->window));
700 main_window_help_about_cb (GtkWidget *widget,
701 EmpathyMainWindow *window)
703 empathy_about_dialog_new (GTK_WINDOW (window->window));
707 main_window_help_contents_cb (GtkWidget *widget,
708 EmpathyMainWindow *window)
710 //empathy_help_show ();
714 main_window_throbber_button_press_event_cb (GtkWidget *throbber_ebox,
715 GdkEventButton *event,
716 EmpathyMainWindow *window)
718 if (event->type != GDK_BUTTON_PRESS ||
719 event->button != 1) {
723 empathy_accounts_dialog_show (GTK_WINDOW (window->window));
729 main_window_error_edit_clicked_cb (GtkButton *button,
730 EmpathyMainWindow *window)
733 GtkWidget *error_widget;
735 empathy_accounts_dialog_show (GTK_WINDOW (window->window));
737 account = g_object_get_data (G_OBJECT (button), "account");
738 error_widget = g_hash_table_lookup (window->errors, account);
739 gtk_widget_destroy (error_widget);
740 g_hash_table_remove (window->errors, account);
744 main_window_error_clear_clicked_cb (GtkButton *button,
745 EmpathyMainWindow *window)
748 GtkWidget *error_widget;
750 account = g_object_get_data (G_OBJECT (button), "account");
751 error_widget = g_hash_table_lookup (window->errors, account);
752 gtk_widget_destroy (error_widget);
753 g_hash_table_remove (window->errors, account);
757 main_window_error_display (EmpathyMainWindow *window,
759 const gchar *message)
764 GtkWidget *button_edit;
765 GtkWidget *alignment;
770 GtkWidget *button_close;
773 child = g_hash_table_lookup (window->errors, account);
775 label = g_object_get_data (G_OBJECT (child), "label");
777 /* Just set the latest error and return */
778 str = g_markup_printf_escaped ("<b>%s</b>\n%s",
779 mc_account_get_display_name (account),
781 gtk_label_set_markup (GTK_LABEL (label), str);
787 child = gtk_vbox_new (FALSE, 0);
788 gtk_box_pack_start (GTK_BOX (window->errors_vbox), child, FALSE, TRUE, 0);
789 gtk_container_set_border_width (GTK_CONTAINER (child), 6);
790 gtk_widget_show (child);
792 table = gtk_table_new (2, 4, FALSE);
793 gtk_widget_show (table);
794 gtk_box_pack_start (GTK_BOX (child), table, TRUE, TRUE, 0);
795 gtk_table_set_row_spacings (GTK_TABLE (table), 12);
796 gtk_table_set_col_spacings (GTK_TABLE (table), 6);
798 image = gtk_image_new_from_stock (GTK_STOCK_DISCONNECT, GTK_ICON_SIZE_MENU);
799 gtk_widget_show (image);
800 gtk_table_attach (GTK_TABLE (table), image, 0, 1, 0, 2,
801 (GtkAttachOptions) (GTK_FILL),
802 (GtkAttachOptions) (GTK_FILL), 0, 0);
803 gtk_misc_set_alignment (GTK_MISC (image), 0.5, 0);
805 button_edit = gtk_button_new ();
806 gtk_widget_show (button_edit);
807 gtk_table_attach (GTK_TABLE (table), button_edit, 1, 2, 1, 2,
808 (GtkAttachOptions) (GTK_FILL),
809 (GtkAttachOptions) (0), 0, 0);
811 alignment = gtk_alignment_new (0.5, 0.5, 0, 0);
812 gtk_widget_show (alignment);
813 gtk_container_add (GTK_CONTAINER (button_edit), alignment);
815 hbox = gtk_hbox_new (FALSE, 2);
816 gtk_widget_show (hbox);
817 gtk_container_add (GTK_CONTAINER (alignment), hbox);
819 image = gtk_image_new_from_stock (GTK_STOCK_EDIT, GTK_ICON_SIZE_BUTTON);
820 gtk_widget_show (image);
821 gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
823 label = gtk_label_new_with_mnemonic (_("_Edit account"));
824 gtk_widget_show (label);
825 gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
827 fixed = gtk_fixed_new ();
828 gtk_widget_show (fixed);
829 gtk_table_attach (GTK_TABLE (table), fixed, 2, 3, 1, 2,
830 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
831 (GtkAttachOptions) (GTK_FILL), 0, 0);
833 vbox = gtk_vbox_new (FALSE, 6);
834 gtk_widget_show (vbox);
835 gtk_table_attach (GTK_TABLE (table), vbox, 3, 4, 0, 2,
836 (GtkAttachOptions) (GTK_FILL),
837 (GtkAttachOptions) (GTK_FILL), 0, 0);
839 button_close = gtk_button_new ();
840 gtk_widget_show (button_close);
841 gtk_box_pack_start (GTK_BOX (vbox), button_close, FALSE, FALSE, 0);
842 gtk_button_set_relief (GTK_BUTTON (button_close), GTK_RELIEF_NONE);
845 image = gtk_image_new_from_stock ("gtk-close", GTK_ICON_SIZE_MENU);
846 gtk_widget_show (image);
847 gtk_container_add (GTK_CONTAINER (button_close), image);
849 label = gtk_label_new ("");
850 gtk_widget_show (label);
851 gtk_table_attach (GTK_TABLE (table), label, 1, 3, 0, 1,
852 (GtkAttachOptions) (GTK_EXPAND | GTK_SHRINK | GTK_FILL),
853 (GtkAttachOptions) (GTK_EXPAND | GTK_SHRINK | GTK_FILL), 0, 0);
854 gtk_widget_set_size_request (label, 175, -1);
855 gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
856 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
857 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
859 str = g_markup_printf_escaped ("<b>%s</b>\n%s",
860 mc_account_get_display_name (account),
862 gtk_label_set_markup (GTK_LABEL (label), str);
865 g_object_set_data (G_OBJECT (child), "label", label);
866 g_object_set_data_full (G_OBJECT (button_edit),
867 "account", g_object_ref (account),
869 g_object_set_data_full (G_OBJECT (button_close),
870 "account", g_object_ref (account),
873 g_signal_connect (button_edit, "clicked",
874 G_CALLBACK (main_window_error_edit_clicked_cb),
877 g_signal_connect (button_close, "clicked",
878 G_CALLBACK (main_window_error_clear_clicked_cb),
881 gtk_widget_show (window->errors_vbox);
883 g_hash_table_insert (window->errors, g_object_ref (account), child);
887 main_window_status_changed_cb (MissionControl *mc,
888 TpConnectionStatus status,
890 TpConnectionStatusReason reason,
891 const gchar *unique_name,
892 EmpathyMainWindow *window)
896 main_window_update_status (window);
898 account = mc_account_lookup (unique_name);
900 if (status == TP_CONNECTION_STATUS_DISCONNECTED &&
901 reason > TP_CONNECTION_STATUS_REASON_REQUESTED) {
902 const gchar *message;
905 case TP_CONNECTION_STATUS_REASON_NETWORK_ERROR:
906 message = _("Network error");
908 case TP_CONNECTION_STATUS_REASON_AUTHENTICATION_FAILED:
909 message = _("Authentication failed");
911 case TP_CONNECTION_STATUS_REASON_ENCRYPTION_ERROR:
912 message = _("Encryption error");
914 case TP_CONNECTION_STATUS_REASON_NAME_IN_USE:
915 message = _("Name in use");
917 case TP_CONNECTION_STATUS_REASON_CERT_NOT_PROVIDED:
918 message = _("Certificate not provided");
920 case TP_CONNECTION_STATUS_REASON_CERT_UNTRUSTED:
921 message = _("Certificate untrusted");
923 case TP_CONNECTION_STATUS_REASON_CERT_EXPIRED:
924 message = _("Certificate expired");
926 case TP_CONNECTION_STATUS_REASON_CERT_NOT_ACTIVATED:
927 message = _("Certificate not activated");
929 case TP_CONNECTION_STATUS_REASON_CERT_HOSTNAME_MISMATCH:
930 message = _("Certificate hostname mismatch");
932 case TP_CONNECTION_STATUS_REASON_CERT_FINGERPRINT_MISMATCH:
933 message = _("Certificate fingerprint mismatch");
935 case TP_CONNECTION_STATUS_REASON_CERT_SELF_SIGNED:
936 message = _("Certificate self signed");
938 case TP_CONNECTION_STATUS_REASON_CERT_OTHER_ERROR:
939 message = _("Certificate error");
942 message = _("Unknown error");
946 main_window_error_display (window, account, message);
949 if (status == TP_CONNECTION_STATUS_CONNECTED) {
950 GtkWidget *error_widget;
952 /* Account connected without error, remove error message if any */
953 error_widget = g_hash_table_lookup (window->errors, account);
955 gtk_widget_destroy (error_widget);
956 g_hash_table_remove (window->errors, account);
960 g_object_unref (account);
964 main_window_update_status (EmpathyMainWindow *window)
968 guint connecting = 0;
969 guint disconnected = 0;
971 /* Count number of connected/connecting/disconnected accounts */
972 accounts = mc_accounts_list ();
973 for (l = accounts; l; l = l->next) {
979 status = mission_control_get_connection_status (window->mc,
985 } else if (status == 1) {
987 } else if (status == 2) {
991 g_object_unref (account);
993 g_list_free (accounts);
995 /* Update the spinner state */
996 if (connecting > 0) {
997 ephy_spinner_start (EPHY_SPINNER (window->throbber));
999 ephy_spinner_stop (EPHY_SPINNER (window->throbber));
1002 /* Update widgets sensibility */
1003 for (l = window->widgets_connected; l; l = l->next) {
1004 gtk_widget_set_sensitive (l->data, (connected > 0));
1007 for (l = window->widgets_disconnected; l; l = l->next) {
1008 gtk_widget_set_sensitive (l->data, (disconnected > 0));
1016 main_window_accels_load (void)
1020 filename = g_build_filename (g_get_home_dir (), ".gnome2", PACKAGE_NAME, ACCELS_FILENAME, NULL);
1021 if (g_file_test (filename, G_FILE_TEST_EXISTS)) {
1022 empathy_debug (DEBUG_DOMAIN, "Loading from:'%s'", filename);
1023 gtk_accel_map_load (filename);
1030 main_window_accels_save (void)
1033 gchar *file_with_path;
1035 dir = g_build_filename (g_get_home_dir (), ".gnome2", PACKAGE_NAME, NULL);
1036 g_mkdir_with_parents (dir, S_IRUSR | S_IWUSR | S_IXUSR);
1037 file_with_path = g_build_filename (dir, ACCELS_FILENAME, NULL);
1040 empathy_debug (DEBUG_DOMAIN, "Saving to:'%s'", file_with_path);
1041 gtk_accel_map_save (file_with_path);
1043 g_free (file_with_path);
1047 main_window_connection_items_setup (EmpathyMainWindow *window,
1053 const gchar *widgets_connected[] = {
1057 "edit_personal_information"
1059 const gchar *widgets_disconnected[] = {
1062 for (i = 0, list = NULL; i < G_N_ELEMENTS (widgets_connected); i++) {
1063 w = glade_xml_get_widget (glade, widgets_connected[i]);
1064 list = g_list_prepend (list, w);
1067 window->widgets_connected = list;
1069 for (i = 0, list = NULL; i < G_N_ELEMENTS (widgets_disconnected); i++) {
1070 w = glade_xml_get_widget (glade, widgets_disconnected[i]);
1071 list = g_list_prepend (list, w);
1074 window->widgets_disconnected = list;
1078 main_window_configure_event_timeout_cb (EmpathyMainWindow *window)
1082 gtk_window_get_size (GTK_WINDOW (window->window), &w, &h);
1083 gtk_window_get_position (GTK_WINDOW (window->window), &x, &y);
1085 empathy_geometry_save (GEOMETRY_NAME, x, y, w, h);
1087 window->size_timeout_id = 0;
1093 main_window_configure_event_cb (GtkWidget *widget,
1094 GdkEventConfigure *event,
1095 EmpathyMainWindow *window)
1097 if (window->size_timeout_id) {
1098 g_source_remove (window->size_timeout_id);
1101 window->size_timeout_id = g_timeout_add_seconds (1,
1102 (GSourceFunc) main_window_configure_event_timeout_cb,
1109 main_window_notify_show_offline_cb (EmpathyConf *conf,
1111 gpointer check_menu_item)
1113 gboolean show_offline;
1115 if (empathy_conf_get_bool (conf, key, &show_offline)) {
1116 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (check_menu_item),
1122 main_window_notify_show_avatars_cb (EmpathyConf *conf,
1124 EmpathyMainWindow *window)
1126 gboolean show_avatars;
1128 if (empathy_conf_get_bool (conf, key, &show_avatars)) {
1129 empathy_contact_list_store_set_show_avatars (window->list_store,
1135 main_window_notify_compact_contact_list_cb (EmpathyConf *conf,
1137 EmpathyMainWindow *window)
1139 gboolean compact_contact_list;
1141 if (empathy_conf_get_bool (conf, key, &compact_contact_list)) {
1142 empathy_contact_list_store_set_is_compact (window->list_store,
1143 compact_contact_list);
1148 main_window_notify_sort_criterium_cb (EmpathyConf *conf,
1150 EmpathyMainWindow *window)
1154 if (empathy_conf_get_string (conf, key, &str) && str) {
1156 GEnumClass *enum_class;
1157 GEnumValue *enum_value;
1159 type = empathy_contact_list_store_sort_get_type ();
1160 enum_class = G_ENUM_CLASS (g_type_class_peek (type));
1161 enum_value = g_enum_get_value_by_nick (enum_class, str);
1165 empathy_contact_list_store_set_sort_criterium (window->list_store,