1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * Copyright (C) 2007 Collabora Ltd.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of the
8 * License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public
16 * License along with this program; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
20 * Authors: Xavier Claessens <xclaesse@gmail.com>
27 #include <glade/glade.h>
28 #include <glib/gi18n.h>
30 #include <libempathy/empathy-conf.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>
40 #include "empathy-main-window.h"
41 #include "empathy-contact-dialogs.h"
42 #include "ephy-spinner.h"
43 #include "empathy-contact-list-store.h"
44 #include "empathy-contact-list-view.h"
45 #include "empathy-presence-chooser.h"
46 #include "empathy-ui-utils.h"
47 #include "empathy-status-presets.h"
48 #include "empathy-geometry.h"
49 #include "empathy-preferences.h"
50 #include "empathy-accounts-dialog.h"
51 #include "empathy-about-dialog.h"
52 #include "empathy-new-chatroom-dialog.h"
53 #include "empathy-chatrooms-window.h"
54 #include "empathy-log-window.h"
55 #include "empathy-gtk-enum-types.h"
57 #define DEBUG_DOMAIN "MainWindow"
59 /* Minimum width of roster window if something goes wrong. */
62 /* Accels (menu shortcuts) can be configured and saved */
63 #define ACCELS_FILENAME "accels.txt"
65 /* Name in the geometry file */
66 #define GEOMETRY_NAME "main-window"
69 EmpathyContactListView *list_view;
70 EmpathyContactListStore *list_store;
72 EmpathyChatroomManager *chatroom_manager;
78 /* Tooltips for all widgets */
79 GtkTooltips *tooltips;
85 GtkWidget *room_join_favorites;
86 GtkWidget *edit_context;
87 GtkWidget *edit_context_separator;
92 /* Widgets that are enabled when there is... */
93 GList *widgets_connected; /* ... connected accounts */
94 GList *widgets_disconnected; /* ... disconnected accounts */
97 GtkWidget *presence_toolbar;
98 GtkWidget *presence_chooser;
101 guint size_timeout_id;
104 static void main_window_destroy_cb (GtkWidget *widget,
105 EmpathyMainWindow *window);
106 static void main_window_favorite_chatroom_menu_setup (EmpathyMainWindow *window);
107 static void main_window_favorite_chatroom_menu_added_cb (EmpathyChatroomManager *manager,
108 EmpathyChatroom *chatroom,
109 EmpathyMainWindow *window);
110 static void main_window_favorite_chatroom_menu_removed_cb (EmpathyChatroomManager *manager,
111 EmpathyChatroom *chatroom,
112 EmpathyMainWindow *window);
113 static void main_window_favorite_chatroom_menu_activate_cb (GtkMenuItem *menu_item,
114 EmpathyChatroom *chatroom);
115 static void main_window_favorite_chatroom_menu_update (EmpathyMainWindow *window);
116 static void main_window_favorite_chatroom_menu_add (EmpathyMainWindow *window,
117 EmpathyChatroom *chatroom);
118 static void main_window_favorite_chatroom_join (EmpathyChatroom *chatroom);
119 static void main_window_chat_quit_cb (GtkWidget *widget,
120 EmpathyMainWindow *window);
121 static void main_window_chat_new_message_cb (GtkWidget *widget,
122 EmpathyMainWindow *window);
123 static void main_window_chat_history_cb (GtkWidget *widget,
124 EmpathyMainWindow *window);
125 static void main_window_room_join_new_cb (GtkWidget *widget,
126 EmpathyMainWindow *window);
127 static void main_window_room_join_favorites_cb (GtkWidget *widget,
128 EmpathyMainWindow *window);
129 static void main_window_room_manage_favorites_cb (GtkWidget *widget,
130 EmpathyMainWindow *window);
131 static void main_window_chat_add_contact_cb (GtkWidget *widget,
132 EmpathyMainWindow *window);
133 static void main_window_chat_show_offline_cb (GtkCheckMenuItem *item,
134 EmpathyMainWindow *window);
135 static gboolean main_window_edit_button_press_event_cb (GtkWidget *widget,
136 GdkEventButton *event,
137 EmpathyMainWindow *window);
138 static void main_window_edit_accounts_cb (GtkWidget *widget,
139 EmpathyMainWindow *window);
140 static void main_window_edit_personal_information_cb (GtkWidget *widget,
141 EmpathyMainWindow *window);
142 static void main_window_edit_preferences_cb (GtkWidget *widget,
143 EmpathyMainWindow *window);
144 static void main_window_help_about_cb (GtkWidget *widget,
145 EmpathyMainWindow *window);
146 static void main_window_help_contents_cb (GtkWidget *widget,
147 EmpathyMainWindow *window);
148 static gboolean main_window_throbber_button_press_event_cb (GtkWidget *throbber_ebox,
149 GdkEventButton *event,
150 EmpathyMainWindow *window);
151 static void main_window_status_changed_cb (MissionControl *mc,
152 TelepathyConnectionStatus status,
154 TelepathyConnectionStatusReason reason,
155 const gchar *unique_name,
156 EmpathyMainWindow *window);
157 static void main_window_update_status (EmpathyMainWindow *window);
158 static void main_window_accels_load (void);
159 static void main_window_accels_save (void);
160 static void main_window_connection_items_setup (EmpathyMainWindow *window,
162 static gboolean main_window_configure_event_timeout_cb (EmpathyMainWindow *window);
163 static gboolean main_window_configure_event_cb (GtkWidget *widget,
164 GdkEventConfigure *event,
165 EmpathyMainWindow *window);
166 static void main_window_notify_show_offline_cb (EmpathyConf *conf,
168 gpointer check_menu_item);
169 static void main_window_notify_show_avatars_cb (EmpathyConf *conf,
171 EmpathyMainWindow *window);
172 static void main_window_notify_compact_contact_list_cb (EmpathyConf *conf,
174 EmpathyMainWindow *window);
175 static void main_window_notify_sort_criterium_cb (EmpathyConf *conf,
177 EmpathyMainWindow *window);
180 empathy_main_window_show (void)
182 static EmpathyMainWindow *window = NULL;
183 EmpathyContactList *list_iface;
187 GtkWidget *show_offline_widget;
191 gboolean show_offline;
192 gboolean show_avatars;
193 gboolean compact_contact_list;
197 gtk_window_present (GTK_WINDOW (window->window));
198 return window->window;
201 window = g_new0 (EmpathyMainWindow, 1);
203 /* Set up interface */
204 glade = empathy_glade_get_file ("empathy-main-window.glade",
207 "main_window", &window->window,
208 "main_vbox", &window->main_vbox,
209 "chat_show_offline", &show_offline_widget,
210 "room", &window->room,
211 "room_sep", &window->room_sep,
212 "room_join_favorites", &window->room_join_favorites,
213 "edit_context", &window->edit_context,
214 "edit_context_separator", &window->edit_context_separator,
215 "presence_toolbar", &window->presence_toolbar,
216 "roster_scrolledwindow", &sw,
219 empathy_glade_connect (glade,
221 "main_window", "destroy", main_window_destroy_cb,
222 "main_window", "configure_event", main_window_configure_event_cb,
223 "chat_quit", "activate", main_window_chat_quit_cb,
224 "chat_new_message", "activate", main_window_chat_new_message_cb,
225 "chat_history", "activate", main_window_chat_history_cb,
226 "room_join_new", "activate", main_window_room_join_new_cb,
227 "room_join_favorites", "activate", main_window_room_join_favorites_cb,
228 "room_manage_favorites", "activate", main_window_room_manage_favorites_cb,
229 "chat_add_contact", "activate", main_window_chat_add_contact_cb,
230 "chat_show_offline", "toggled", main_window_chat_show_offline_cb,
231 "edit", "button-press-event", main_window_edit_button_press_event_cb,
232 "edit_accounts", "activate", main_window_edit_accounts_cb,
233 "edit_personal_information", "activate", main_window_edit_personal_information_cb,
234 "edit_preferences", "activate", main_window_edit_preferences_cb,
235 "help_about", "activate", main_window_help_about_cb,
236 "help_contents", "activate", main_window_help_contents_cb,
239 /* Set up connection related widgets. */
240 main_window_connection_items_setup (window, glade);
241 g_object_unref (glade);
243 window->tooltips = g_object_ref_sink (gtk_tooltips_new ());
244 window->mc = empathy_mission_control_new ();
245 dbus_g_proxy_connect_signal (DBUS_G_PROXY (window->mc), "AccountStatusChanged",
246 G_CALLBACK (main_window_status_changed_cb),
250 main_window_favorite_chatroom_menu_setup (window);
252 gtk_widget_hide (window->edit_context);
253 gtk_widget_hide (window->edit_context_separator);
255 /* Set up presence chooser */
256 window->presence_chooser = empathy_presence_chooser_new ();
257 gtk_widget_show (window->presence_chooser);
258 item = gtk_tool_item_new ();
259 gtk_widget_show (GTK_WIDGET (item));
260 gtk_container_add (GTK_CONTAINER (item), window->presence_chooser);
261 gtk_tool_item_set_is_important (item, TRUE);
262 gtk_tool_item_set_expand (item, TRUE);
263 gtk_toolbar_insert (GTK_TOOLBAR (window->presence_toolbar), item, -1);
265 /* Set up the throbber */
266 ebox = gtk_event_box_new ();
267 gtk_event_box_set_visible_window (GTK_EVENT_BOX (ebox), FALSE);
269 window->throbber = ephy_spinner_new ();
270 ephy_spinner_set_size (EPHY_SPINNER (window->throbber), GTK_ICON_SIZE_LARGE_TOOLBAR);
271 gtk_container_add (GTK_CONTAINER (ebox), window->throbber);
273 item = gtk_tool_item_new ();
274 gtk_container_add (GTK_CONTAINER (item), ebox);
275 gtk_widget_show_all (GTK_WIDGET (item));
277 gtk_toolbar_insert (GTK_TOOLBAR (window->presence_toolbar), item, -1);
279 str = _("Show and edit accounts");
280 gtk_tooltips_set_tip (GTK_TOOLTIPS (window->tooltips),
283 g_signal_connect (ebox,
284 "button-press-event",
285 G_CALLBACK (main_window_throbber_button_press_event_cb),
288 /* Set up contact list. */
289 empathy_status_presets_get_all ();
291 list_iface = EMPATHY_CONTACT_LIST (empathy_contact_manager_new ());
292 window->list_store = empathy_contact_list_store_new (list_iface);
293 window->list_view = empathy_contact_list_view_new (window->list_store);
294 empathy_contact_list_view_set_interactive (window->list_view, TRUE);
295 g_object_unref (list_iface);
297 gtk_widget_show (GTK_WIDGET (window->list_view));
298 gtk_container_add (GTK_CONTAINER (sw),
299 GTK_WIDGET (window->list_view));
301 /* Load user-defined accelerators. */
302 main_window_accels_load ();
304 /* Set window size. */
305 empathy_geometry_load (GEOMETRY_NAME, &x, &y, &w, &h);
307 if (w >= 1 && h >= 1) {
308 /* Use the defaults from the glade file if we
309 * don't have good w, h geometry.
311 empathy_debug (DEBUG_DOMAIN, "Configuring window default size w:%d, h:%d", w, h);
312 gtk_window_set_default_size (GTK_WINDOW (window->window), w, h);
315 if (x >= 0 && y >= 0) {
316 /* Let the window manager position it if we
317 * don't have good x, y coordinates.
319 empathy_debug (DEBUG_DOMAIN, "Configuring window default position x:%d, y:%d", x, y);
320 gtk_window_move (GTK_WINDOW (window->window), x, y);
323 conf = empathy_conf_get ();
326 empathy_conf_get_bool (conf,
327 EMPATHY_PREFS_CONTACTS_SHOW_OFFLINE,
329 empathy_conf_notify_add (conf,
330 EMPATHY_PREFS_CONTACTS_SHOW_OFFLINE,
331 main_window_notify_show_offline_cb,
332 show_offline_widget);
334 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (show_offline_widget),
338 empathy_conf_get_bool (conf,
339 EMPATHY_PREFS_UI_SHOW_AVATARS,
341 empathy_conf_notify_add (conf,
342 EMPATHY_PREFS_UI_SHOW_AVATARS,
343 (EmpathyConfNotifyFunc) main_window_notify_show_avatars_cb,
345 empathy_contact_list_store_set_show_avatars (window->list_store, show_avatars);
348 empathy_conf_get_bool (conf,
349 EMPATHY_PREFS_UI_COMPACT_CONTACT_LIST,
350 &compact_contact_list);
351 empathy_conf_notify_add (conf,
352 EMPATHY_PREFS_UI_COMPACT_CONTACT_LIST,
353 (EmpathyConfNotifyFunc) main_window_notify_compact_contact_list_cb,
355 empathy_contact_list_store_set_is_compact (window->list_store, compact_contact_list);
358 empathy_conf_notify_add (conf,
359 EMPATHY_PREFS_CONTACTS_SORT_CRITERIUM,
360 (EmpathyConfNotifyFunc) main_window_notify_sort_criterium_cb,
362 main_window_notify_sort_criterium_cb (conf,
363 EMPATHY_PREFS_CONTACTS_SORT_CRITERIUM,
366 main_window_update_status (window);
368 return window->window;
372 main_window_destroy_cb (GtkWidget *widget,
373 EmpathyMainWindow *window)
375 /* Save user-defined accelerators. */
376 main_window_accels_save ();
378 dbus_g_proxy_disconnect_signal (DBUS_G_PROXY (window->mc), "AccountStatusChanged",
379 G_CALLBACK (main_window_status_changed_cb),
382 if (window->size_timeout_id) {
383 g_source_remove (window->size_timeout_id);
386 g_list_free (window->widgets_connected);
387 g_list_free (window->widgets_disconnected);
389 g_object_unref (window->tooltips);
390 g_object_unref (window->mc);
391 g_object_unref (window->list_store);
397 main_window_favorite_chatroom_menu_setup (EmpathyMainWindow *window)
399 GList *chatrooms, *l;
401 window->chatroom_manager = empathy_chatroom_manager_new ();
402 chatrooms = empathy_chatroom_manager_get_chatrooms (window->chatroom_manager, NULL);
403 window->room_menu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (window->room));
405 for (l = chatrooms; l; l = l->next) {
406 main_window_favorite_chatroom_menu_add (window, l->data);
410 gtk_widget_hide (window->room_sep);
413 gtk_widget_set_sensitive (window->room_join_favorites, chatrooms != NULL);
415 g_signal_connect (window->chatroom_manager, "chatroom-added",
416 G_CALLBACK (main_window_favorite_chatroom_menu_added_cb),
418 g_signal_connect (window->chatroom_manager, "chatroom-removed",
419 G_CALLBACK (main_window_favorite_chatroom_menu_removed_cb),
422 g_list_free (chatrooms);
426 main_window_favorite_chatroom_menu_added_cb (EmpathyChatroomManager *manager,
427 EmpathyChatroom *chatroom,
428 EmpathyMainWindow *window)
430 main_window_favorite_chatroom_menu_add (window, chatroom);
431 gtk_widget_show (window->room_sep);
432 gtk_widget_set_sensitive (window->room_join_favorites, TRUE);
436 main_window_favorite_chatroom_menu_removed_cb (EmpathyChatroomManager *manager,
437 EmpathyChatroom *chatroom,
438 EmpathyMainWindow *window)
440 GtkWidget *menu_item;
442 menu_item = g_object_get_data (G_OBJECT (chatroom), "menu_item");
444 g_object_set_data (G_OBJECT (chatroom), "menu_item", NULL);
445 gtk_widget_destroy (menu_item);
447 main_window_favorite_chatroom_menu_update (window);
451 main_window_favorite_chatroom_menu_activate_cb (GtkMenuItem *menu_item,
452 EmpathyChatroom *chatroom)
454 main_window_favorite_chatroom_join (chatroom);
458 main_window_favorite_chatroom_menu_update (EmpathyMainWindow *window)
462 chatrooms = empathy_chatroom_manager_get_chatrooms (window->chatroom_manager, NULL);
465 gtk_widget_show (window->room_sep);
467 gtk_widget_hide (window->room_sep);
470 gtk_widget_set_sensitive (window->room_join_favorites, chatrooms != NULL);
471 g_list_free (chatrooms);
475 main_window_favorite_chatroom_menu_add (EmpathyMainWindow *window,
476 EmpathyChatroom *chatroom)
478 GtkWidget *menu_item;
481 if (g_object_get_data (G_OBJECT (chatroom), "menu_item")) {
485 name = empathy_chatroom_get_name (chatroom);
486 menu_item = gtk_menu_item_new_with_label (name);
488 g_object_set_data (G_OBJECT (chatroom), "menu_item", menu_item);
489 g_signal_connect (menu_item, "activate",
490 G_CALLBACK (main_window_favorite_chatroom_menu_activate_cb),
493 gtk_menu_shell_insert (GTK_MENU_SHELL (window->room_menu),
496 gtk_widget_show (menu_item);
500 main_window_favorite_chatroom_join (EmpathyChatroom *chatroom)
506 mc = empathy_mission_control_new ();
507 account = empathy_chatroom_get_account (chatroom);
508 room = empathy_chatroom_get_room (chatroom);
510 empathy_debug (DEBUG_DOMAIN, "Requesting channel for '%s'", room);
512 mission_control_request_channel_with_string_handle (mc,
514 TP_IFACE_CHANNEL_TYPE_TEXT,
522 main_window_chat_quit_cb (GtkWidget *widget,
523 EmpathyMainWindow *window)
529 main_window_chat_new_message_cb (GtkWidget *widget,
530 EmpathyMainWindow *window)
532 //empathy_new_message_dialog_show (GTK_WINDOW (window->window));
536 main_window_chat_history_cb (GtkWidget *widget,
537 EmpathyMainWindow *window)
539 empathy_log_window_show (NULL, NULL, FALSE, GTK_WINDOW (window->window));
543 main_window_room_join_new_cb (GtkWidget *widget,
544 EmpathyMainWindow *window)
546 empathy_new_chatroom_dialog_show (GTK_WINDOW (window->window));
550 main_window_room_join_favorites_cb (GtkWidget *widget,
551 EmpathyMainWindow *window)
553 GList *chatrooms, *l;
555 chatrooms = empathy_chatroom_manager_get_chatrooms (window->chatroom_manager, NULL);
556 for (l = chatrooms; l; l = l->next) {
557 main_window_favorite_chatroom_join (l->data);
559 g_list_free (chatrooms);
563 main_window_room_manage_favorites_cb (GtkWidget *widget,
564 EmpathyMainWindow *window)
566 empathy_chatrooms_window_show (GTK_WINDOW (window->window));
570 main_window_chat_add_contact_cb (GtkWidget *widget,
571 EmpathyMainWindow *window)
573 empathy_new_contact_dialog_show (GTK_WINDOW (window->window));
577 main_window_chat_show_offline_cb (GtkCheckMenuItem *item,
578 EmpathyMainWindow *window)
582 current = gtk_check_menu_item_get_active (item);
584 empathy_conf_set_bool (empathy_conf_get (),
585 EMPATHY_PREFS_CONTACTS_SHOW_OFFLINE,
588 /* Turn off sound just while we alter the contact list. */
589 // FIXME: empathy_sound_set_enabled (FALSE);
590 empathy_contact_list_store_set_show_offline (window->list_store, current);
591 //empathy_sound_set_enabled (TRUE);
595 main_window_edit_button_press_event_cb (GtkWidget *widget,
596 GdkEventButton *event,
597 EmpathyMainWindow *window)
599 EmpathyContact *contact;
602 if (!event->button == 1) {
606 group = empathy_contact_list_view_get_selected_group (window->list_view);
612 item = GTK_MENU_ITEM (window->edit_context);
613 label = gtk_bin_get_child (GTK_BIN (item));
614 gtk_label_set_text (GTK_LABEL (label), _("Group"));
616 gtk_widget_show (window->edit_context);
617 gtk_widget_show (window->edit_context_separator);
619 submenu = empathy_contact_list_view_get_group_menu (window->list_view);
620 gtk_menu_item_set_submenu (item, submenu);
627 contact = empathy_contact_list_view_get_selected (window->list_view);
633 item = GTK_MENU_ITEM (window->edit_context);
634 label = gtk_bin_get_child (GTK_BIN (item));
635 gtk_label_set_text (GTK_LABEL (label), _("Contact"));
637 gtk_widget_show (window->edit_context);
638 gtk_widget_show (window->edit_context_separator);
640 submenu = empathy_contact_list_view_get_contact_menu (window->list_view,
642 gtk_menu_item_set_submenu (item, submenu);
644 g_object_unref (contact);
649 gtk_widget_hide (window->edit_context);
650 gtk_widget_hide (window->edit_context_separator);
656 main_window_edit_accounts_cb (GtkWidget *widget,
657 EmpathyMainWindow *window)
659 empathy_accounts_dialog_show (GTK_WINDOW (window->window));
663 main_window_edit_personal_information_cb (GtkWidget *widget,
664 EmpathyMainWindow *window)
668 accounts = mission_control_get_online_connections (window->mc, NULL);
670 EmpathyContactFactory *factory;
671 EmpathyContact *contact;
674 account = accounts->data;
675 factory = empathy_contact_factory_new ();
676 contact = empathy_contact_factory_get_user (factory, account);
677 empathy_contact_information_dialog_show (contact,
678 GTK_WINDOW (window->window),
680 g_slist_foreach (accounts, (GFunc) g_object_unref, NULL);
681 g_slist_free (accounts);
682 g_object_unref (factory);
687 main_window_edit_preferences_cb (GtkWidget *widget,
688 EmpathyMainWindow *window)
690 empathy_preferences_show (GTK_WINDOW (window->window));
694 main_window_help_about_cb (GtkWidget *widget,
695 EmpathyMainWindow *window)
697 empathy_about_dialog_new (GTK_WINDOW (window->window));
701 main_window_help_contents_cb (GtkWidget *widget,
702 EmpathyMainWindow *window)
704 //empathy_help_show ();
708 main_window_throbber_button_press_event_cb (GtkWidget *throbber_ebox,
709 GdkEventButton *event,
710 EmpathyMainWindow *window)
712 if (event->type != GDK_BUTTON_PRESS ||
713 event->button != 1) {
717 empathy_accounts_dialog_show (GTK_WINDOW (window->window));
723 main_window_status_changed_cb (MissionControl *mc,
724 TelepathyConnectionStatus status,
726 TelepathyConnectionStatusReason reason,
727 const gchar *unique_name,
728 EmpathyMainWindow *window)
730 main_window_update_status (window);
734 main_window_update_status (EmpathyMainWindow *window)
738 guint connecting = 0;
739 guint disconnected = 0;
741 /* Count number of connected/connecting/disconnected accounts */
742 accounts = mc_accounts_list ();
743 for (l = accounts; l; l = l->next) {
749 status = mission_control_get_connection_status (window->mc,
755 } else if (status == 1) {
757 } else if (status == 2) {
761 g_object_unref (account);
763 g_list_free (accounts);
765 /* Update the spinner state */
766 if (connecting > 0) {
767 ephy_spinner_start (EPHY_SPINNER (window->throbber));
769 ephy_spinner_stop (EPHY_SPINNER (window->throbber));
772 /* Update widgets sensibility */
773 for (l = window->widgets_connected; l; l = l->next) {
774 gtk_widget_set_sensitive (l->data, (connected > 0));
777 for (l = window->widgets_disconnected; l; l = l->next) {
778 gtk_widget_set_sensitive (l->data, (disconnected > 0));
786 main_window_accels_load (void)
790 filename = g_build_filename (g_get_home_dir (), ".gnome2", PACKAGE_NAME, ACCELS_FILENAME, NULL);
791 if (g_file_test (filename, G_FILE_TEST_EXISTS)) {
792 empathy_debug (DEBUG_DOMAIN, "Loading from:'%s'", filename);
793 gtk_accel_map_load (filename);
800 main_window_accels_save (void)
803 gchar *file_with_path;
805 dir = g_build_filename (g_get_home_dir (), ".gnome2", PACKAGE_NAME, NULL);
806 g_mkdir_with_parents (dir, S_IRUSR | S_IWUSR | S_IXUSR);
807 file_with_path = g_build_filename (dir, ACCELS_FILENAME, NULL);
810 empathy_debug (DEBUG_DOMAIN, "Saving to:'%s'", file_with_path);
811 gtk_accel_map_save (file_with_path);
813 g_free (file_with_path);
817 main_window_connection_items_setup (EmpathyMainWindow *window,
823 const gchar *widgets_connected[] = {
827 "edit_personal_information"
829 const gchar *widgets_disconnected[] = {
832 for (i = 0, list = NULL; i < G_N_ELEMENTS (widgets_connected); i++) {
833 w = glade_xml_get_widget (glade, widgets_connected[i]);
834 list = g_list_prepend (list, w);
837 window->widgets_connected = list;
839 for (i = 0, list = NULL; i < G_N_ELEMENTS (widgets_disconnected); i++) {
840 w = glade_xml_get_widget (glade, widgets_disconnected[i]);
841 list = g_list_prepend (list, w);
844 window->widgets_disconnected = list;
848 main_window_configure_event_timeout_cb (EmpathyMainWindow *window)
852 gtk_window_get_size (GTK_WINDOW (window->window), &w, &h);
853 gtk_window_get_position (GTK_WINDOW (window->window), &x, &y);
855 empathy_geometry_save (GEOMETRY_NAME, x, y, w, h);
857 window->size_timeout_id = 0;
863 main_window_configure_event_cb (GtkWidget *widget,
864 GdkEventConfigure *event,
865 EmpathyMainWindow *window)
867 if (window->size_timeout_id) {
868 g_source_remove (window->size_timeout_id);
871 window->size_timeout_id = g_timeout_add (500,
872 (GSourceFunc) main_window_configure_event_timeout_cb,
879 main_window_notify_show_offline_cb (EmpathyConf *conf,
881 gpointer check_menu_item)
883 gboolean show_offline;
885 if (empathy_conf_get_bool (conf, key, &show_offline)) {
886 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (check_menu_item),
892 main_window_notify_show_avatars_cb (EmpathyConf *conf,
894 EmpathyMainWindow *window)
896 gboolean show_avatars;
898 if (empathy_conf_get_bool (conf, key, &show_avatars)) {
899 empathy_contact_list_store_set_show_avatars (window->list_store,
905 main_window_notify_compact_contact_list_cb (EmpathyConf *conf,
907 EmpathyMainWindow *window)
909 gboolean compact_contact_list;
911 if (empathy_conf_get_bool (conf, key, &compact_contact_list)) {
912 empathy_contact_list_store_set_is_compact (window->list_store,
913 compact_contact_list);
918 main_window_notify_sort_criterium_cb (EmpathyConf *conf,
920 EmpathyMainWindow *window)
924 if (empathy_conf_get_string (conf, key, &str) && str) {
926 GEnumClass *enum_class;
927 GEnumValue *enum_value;
929 type = empathy_contact_list_store_sort_get_type ();
930 enum_class = G_ENUM_CLASS (g_type_class_peek (type));
931 enum_value = g_enum_get_value_by_nick (enum_class, str);
935 empathy_contact_list_store_set_sort_criterium (window->list_store,