b10f6c8d60e0288db1a5bf74ad5b33882f58441d
[empathy.git] / libempathy-gtk / empathy-main-window.c
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3  * Copyright (C) 2007 Collabora Ltd.
4  *
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.
9  *
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.
14  *
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.
19  * 
20  * Authors: Xavier Claessens <xclaesse@gmail.com>
21  */
22
23 #include <config.h>
24
25 #include <sys/stat.h>
26 #include <gtk/gtk.h>
27 #include <glade/glade.h>
28 #include <glib/gi18n.h>
29
30 #include <libempathy/gossip-conf.h>
31 #include <libempathy/gossip-contact.h>
32 #include <libempathy/gossip-debug.h>
33 #include <libempathy/gossip-utils.h>
34 #include <libempathy/empathy-contact-list.h>
35 #include <libempathy/empathy-contact-manager.h>
36
37 #include "empathy-main-window.h"
38 #include "ephy-spinner.h"
39 #include "gossip-contact-list-store.h"
40 #include "gossip-contact-list-view.h"
41 #include "gossip-presence-chooser.h"
42 #include "gossip-ui-utils.h"
43 #include "gossip-status-presets.h"
44 #include "gossip-geometry.h"
45 #include "gossip-preferences.h"
46 #include "gossip-accounts-dialog.h"
47 #include "gossip-about-dialog.h"
48 #include "gossip-new-chatroom-dialog.h"
49
50 #define DEBUG_DOMAIN "MainWindow"
51
52 /* Minimum width of roster window if something goes wrong. */
53 #define MIN_WIDTH 50
54
55 /* Accels (menu shortcuts) can be configured and saved */
56 #define ACCELS_FILENAME "accels.txt"
57
58 /* Name in the geometry file */
59 #define GEOMETRY_NAME "main-window"
60
61 typedef struct {
62         GossipContactListView  *list_view;
63         GossipContactListStore *list_store;
64         MissionControl         *mc;
65
66         /* Main widgets */
67         GtkWidget              *window;
68         GtkWidget              *main_vbox;
69
70         /* Tooltips for all widgets */
71         GtkTooltips            *tooltips;
72
73         /* Menu widgets */
74         GtkWidget              *room;
75         GtkWidget              *room_menu;
76         GtkWidget              *room_sep;
77         GtkWidget              *room_join_favorites;
78         GtkWidget              *edit_context;
79         GtkWidget              *edit_context_separator;
80
81         /* Throbber */
82         GtkWidget              *throbber;
83
84         /* Widgets that are enabled when there is... */
85         GList                  *widgets_connected;      /* ... connected accounts */
86         GList                  *widgets_disconnected;   /* ... disconnected accounts */
87
88         /* Status popup */
89         GtkWidget              *presence_toolbar;
90         GtkWidget              *presence_chooser;
91
92         /* Misc */
93         guint                   size_timeout_id;
94 } EmpathyMainWindow;
95
96 static void     main_window_destroy_cb                     (GtkWidget                       *widget,
97                                                             EmpathyMainWindow               *window);
98 static void     main_window_favorite_chatroom_menu_setup   (void);
99 static void     main_window_chat_quit_cb                   (GtkWidget                       *widget,
100                                                             EmpathyMainWindow               *window);
101 static void     main_window_chat_new_message_cb            (GtkWidget                       *widget,
102                                                             EmpathyMainWindow               *window);
103 static void     main_window_chat_history_cb                (GtkWidget                       *widget,
104                                                             EmpathyMainWindow               *window);
105 static void     main_window_room_join_new_cb               (GtkWidget                       *widget,
106                                                             EmpathyMainWindow               *window);
107 static void     main_window_room_join_favorites_cb         (GtkWidget                       *widget,
108                                                             EmpathyMainWindow               *window);
109 static void     main_window_room_manage_favorites_cb       (GtkWidget                       *widget,
110                                                             EmpathyMainWindow               *window);
111 static void     main_window_chat_add_contact_cb            (GtkWidget                       *widget,
112                                                             EmpathyMainWindow               *window);
113 static void     main_window_chat_show_offline_cb           (GtkCheckMenuItem                *item,
114                                                             EmpathyMainWindow               *window);
115 static gboolean main_window_edit_button_press_event_cb     (GtkWidget                       *widget,
116                                                             GdkEventButton                  *event,
117                                                             EmpathyMainWindow               *window);
118 static void     main_window_edit_accounts_cb               (GtkWidget                       *widget,
119                                                             EmpathyMainWindow               *window);
120 static void     main_window_edit_personal_information_cb   (GtkWidget                       *widget,
121                                                             EmpathyMainWindow               *window);
122 static void     main_window_edit_preferences_cb            (GtkWidget                       *widget,
123                                                             EmpathyMainWindow               *window);
124 static void     main_window_help_about_cb                  (GtkWidget                       *widget,
125                                                             EmpathyMainWindow               *window);
126 static void     main_window_help_contents_cb               (GtkWidget                       *widget,
127                                                             EmpathyMainWindow               *window);
128 static gboolean main_window_throbber_button_press_event_cb (GtkWidget                       *throbber_ebox,
129                                                             GdkEventButton                  *event,
130                                                             gpointer                         user_data);
131 static void     main_window_status_changed_cb              (MissionControl                  *mc,
132                                                             TelepathyConnectionStatus        status,
133                                                             McPresence                       presence,
134                                                             TelepathyConnectionStatusReason  reason,
135                                                             const gchar                     *unique_name,
136                                                             EmpathyMainWindow               *window);
137 static void     main_window_update_status                  (EmpathyMainWindow               *window);
138 static void     main_window_accels_load                    (void);
139 static void     main_window_accels_save                    (void);
140 static void     main_window_connection_items_setup         (EmpathyMainWindow               *window,
141                                                             GladeXML                        *glade);
142 static gboolean main_window_configure_event_timeout_cb     (EmpathyMainWindow               *window);
143 static gboolean main_window_configure_event_cb             (GtkWidget                       *widget,
144                                                             GdkEventConfigure               *event,
145                                                             EmpathyMainWindow               *window);
146 static void     main_window_notify_show_offline_cb         (GossipConf                      *conf,
147                                                             const gchar                     *key,
148                                                             gpointer                         check_menu_item);
149 static void     main_window_notify_show_avatars_cb         (GossipConf                      *conf,
150                                                             const gchar                     *key,
151                                                             EmpathyMainWindow               *window);
152 static void     main_window_notify_compact_contact_list_cb (GossipConf                      *conf,
153                                                             const gchar                     *key,
154                                                             EmpathyMainWindow               *window);
155 static void     main_window_notify_sort_criterium_cb       (GossipConf                      *conf,
156                                                             const gchar                     *key,
157                                                             EmpathyMainWindow               *window);
158
159 GtkWidget *
160 empathy_main_window_show (void)
161 {
162         static EmpathyMainWindow *window = NULL;
163         EmpathyContactList       *list_iface;
164         GladeXML                 *glade;
165         GossipConf               *conf;
166         GtkWidget                *sw;
167         GtkWidget                *show_offline_widget;
168         GtkWidget                *ebox;
169         GtkToolItem              *item;
170         gchar                    *str;
171         gboolean                  show_offline;
172         gboolean                  show_avatars;
173         gboolean                  compact_contact_list;
174         gint                      x, y, w, h;
175
176         if (window) {
177                 gtk_window_present (GTK_WINDOW (window->window));
178                 return window->window;
179         }
180
181         window = g_new0 (EmpathyMainWindow, 1);
182
183         /* Set up interface */
184         glade = gossip_glade_get_file ("empathy-main-window.glade",
185                                        "main_window",
186                                        NULL,
187                                        "main_window", &window->window,
188                                        "main_vbox", &window->main_vbox,
189                                        "chat_show_offline", &show_offline_widget,
190                                        "room", &window->room,
191                                        "room_sep", &window->room_sep,
192                                        "room_join_favorites", &window->room_join_favorites,
193                                        "edit_context", &window->edit_context,
194                                        "edit_context_separator", &window->edit_context_separator,
195                                        "presence_toolbar", &window->presence_toolbar,
196                                        "roster_scrolledwindow", &sw,
197                                        NULL);
198
199         gossip_glade_connect (glade,
200                               window,
201                               "main_window", "destroy", main_window_destroy_cb,
202                               "main_window", "configure_event", main_window_configure_event_cb,
203                               "chat_quit", "activate", main_window_chat_quit_cb,
204                               "chat_new_message", "activate", main_window_chat_new_message_cb,
205                               "chat_history", "activate", main_window_chat_history_cb,
206                               "room_join_new", "activate", main_window_room_join_new_cb,
207                               "room_join_favorites", "activate", main_window_room_join_favorites_cb,
208                               "room_manage_favorites", "activate", main_window_room_manage_favorites_cb,
209                               "chat_add_contact", "activate", main_window_chat_add_contact_cb,
210                               "chat_show_offline", "toggled", main_window_chat_show_offline_cb,
211                               "edit", "button-press-event", main_window_edit_button_press_event_cb,
212                               "edit_accounts", "activate", main_window_edit_accounts_cb,
213                               "edit_personal_information", "activate", main_window_edit_personal_information_cb,
214                               "edit_preferences", "activate", main_window_edit_preferences_cb,
215                               "help_about", "activate", main_window_help_about_cb,
216                               "help_contents", "activate", main_window_help_contents_cb,
217                               NULL);
218
219         /* Set up connection related widgets. */
220         main_window_connection_items_setup (window, glade);
221         g_object_unref (glade);
222
223         window->tooltips = g_object_ref_sink (gtk_tooltips_new ());
224         window->mc = gossip_mission_control_new ();
225         dbus_g_proxy_connect_signal (DBUS_G_PROXY (window->mc), "AccountStatusChanged",
226                                      G_CALLBACK (main_window_status_changed_cb),
227                                      window, NULL);
228
229         /* Set up menu */
230         main_window_favorite_chatroom_menu_setup ();
231
232         gtk_widget_hide (window->edit_context);
233         gtk_widget_hide (window->edit_context_separator);
234
235         /* Set up presence chooser */
236         window->presence_chooser = gossip_presence_chooser_new ();
237         gtk_widget_show (window->presence_chooser);
238         item = gtk_tool_item_new ();
239         gtk_widget_show (GTK_WIDGET (item));
240         gtk_container_add (GTK_CONTAINER (item), window->presence_chooser);
241         gtk_tool_item_set_is_important (item, TRUE);
242         gtk_tool_item_set_expand (item, TRUE);
243         gtk_toolbar_insert (GTK_TOOLBAR (window->presence_toolbar), item, -1);
244
245         /* Set up the throbber */
246         ebox = gtk_event_box_new ();
247         gtk_event_box_set_visible_window (GTK_EVENT_BOX (ebox), FALSE);
248
249         window->throbber = ephy_spinner_new ();
250         ephy_spinner_set_size (EPHY_SPINNER (window->throbber), GTK_ICON_SIZE_LARGE_TOOLBAR);
251         gtk_container_add (GTK_CONTAINER (ebox), window->throbber);
252
253         item = gtk_tool_item_new ();
254         gtk_container_add (GTK_CONTAINER (item), ebox);
255         gtk_widget_show_all (GTK_WIDGET (item));
256
257         gtk_toolbar_insert (GTK_TOOLBAR (window->presence_toolbar), item, -1);
258
259         str = _("Show and edit accounts");
260         gtk_tooltips_set_tip (GTK_TOOLTIPS (window->tooltips),
261                               ebox, str, str);
262
263         g_signal_connect (ebox,
264                           "button-press-event",
265                           G_CALLBACK (main_window_throbber_button_press_event_cb),
266                           NULL);
267
268         /* Set up contact list. */
269         gossip_status_presets_get_all ();
270
271         list_iface = EMPATHY_CONTACT_LIST (empathy_contact_manager_new ());
272         empathy_contact_list_setup (list_iface);
273         window->list_store = gossip_contact_list_store_new (list_iface);
274         window->list_view = gossip_contact_list_view_new (window->list_store);
275         g_object_unref (list_iface);
276
277         gtk_widget_show (GTK_WIDGET (window->list_view));
278         gtk_container_add (GTK_CONTAINER (sw),
279                            GTK_WIDGET (window->list_view));
280
281         /* Load user-defined accelerators. */
282         main_window_accels_load ();
283
284         /* Set window size. */
285         gossip_geometry_load (GEOMETRY_NAME, &x, &y, &w, &h);
286
287         if (w >= 1 && h >= 1) {
288                 /* Use the defaults from the glade file if we
289                  * don't have good w, h geometry.
290                  */
291                 gossip_debug (DEBUG_DOMAIN, "Configuring window default size w:%d, h:%d", w, h);
292                 gtk_window_set_default_size (GTK_WINDOW (window->window), w, h);
293         }
294
295         if (x >= 0 && y >= 0) {
296                 /* Let the window manager position it if we
297                  * don't have good x, y coordinates.
298                  */
299                 gossip_debug (DEBUG_DOMAIN, "Configuring window default position x:%d, y:%d", x, y);
300                 gtk_window_move (GTK_WINDOW (window->window), x, y);
301         }
302
303         conf = gossip_conf_get ();
304         
305         /* Show offline ? */
306         gossip_conf_get_bool (conf,
307                               GOSSIP_PREFS_CONTACTS_SHOW_OFFLINE,
308                               &show_offline);
309         gossip_conf_notify_add (conf,
310                                 GOSSIP_PREFS_CONTACTS_SHOW_OFFLINE,
311                                 main_window_notify_show_offline_cb,
312                                 show_offline_widget);
313
314         gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (show_offline_widget),
315                                         show_offline);
316
317         /* Show avatars ? */
318         gossip_conf_get_bool (conf,
319                               GOSSIP_PREFS_UI_SHOW_AVATARS,
320                               &show_avatars);
321         gossip_conf_notify_add (conf,
322                                 GOSSIP_PREFS_UI_SHOW_AVATARS,
323                                 (GossipConfNotifyFunc) main_window_notify_show_avatars_cb,
324                                 window);
325         gossip_contact_list_store_set_show_avatars (window->list_store, show_avatars);
326
327         /* Is compact ? */
328         gossip_conf_get_bool (conf,
329                               GOSSIP_PREFS_UI_COMPACT_CONTACT_LIST,
330                               &compact_contact_list);
331         gossip_conf_notify_add (conf,
332                                 GOSSIP_PREFS_UI_COMPACT_CONTACT_LIST,
333                                 (GossipConfNotifyFunc) main_window_notify_compact_contact_list_cb,
334                                 window);
335         gossip_contact_list_store_set_is_compact (window->list_store, compact_contact_list);
336
337         /* Sort criterium */
338         gossip_conf_notify_add (conf,
339                                 GOSSIP_PREFS_CONTACTS_SORT_CRITERIUM,
340                                 (GossipConfNotifyFunc) main_window_notify_sort_criterium_cb,
341                                 window);
342         main_window_notify_sort_criterium_cb (conf,
343                                               GOSSIP_PREFS_CONTACTS_SORT_CRITERIUM,
344                                               window);
345
346         main_window_update_status (window);
347
348         return window->window;
349 }
350
351 static void
352 main_window_destroy_cb (GtkWidget         *widget,
353                         EmpathyMainWindow *window)
354 {
355         /* Save user-defined accelerators. */
356         main_window_accels_save ();
357
358         dbus_g_proxy_disconnect_signal (DBUS_G_PROXY (window->mc), "AccountStatusChanged",
359                                         G_CALLBACK (main_window_status_changed_cb),
360                                         window);
361
362         if (window->size_timeout_id) {
363                 g_source_remove (window->size_timeout_id);
364         }
365
366         g_list_free (window->widgets_connected);
367         g_list_free (window->widgets_disconnected);
368
369         g_object_unref (window->tooltips);
370         g_object_unref (window->mc);
371         g_object_unref (window->list_store);
372
373         g_free (window);
374 }
375
376 static void
377 main_window_favorite_chatroom_menu_setup (void)
378 {
379 }
380
381 static void
382 main_window_chat_quit_cb (GtkWidget         *widget,
383                           EmpathyMainWindow *window)
384 {
385         gtk_main_quit ();
386 }
387
388 static void
389 main_window_chat_new_message_cb (GtkWidget         *widget,
390                                  EmpathyMainWindow *window)
391 {
392         //gossip_new_message_dialog_show (GTK_WINDOW (window->window));
393 }
394
395 static void
396 main_window_chat_history_cb (GtkWidget         *widget,
397                              EmpathyMainWindow *window)
398 {
399         //gossip_log_window_show (NULL, NULL);
400 }
401
402 static void
403 main_window_room_join_new_cb (GtkWidget         *widget,
404                               EmpathyMainWindow *window)
405 {
406         gossip_new_chatroom_dialog_show (GTK_WINDOW (window->window));
407 }
408
409 static void
410 main_window_room_join_favorites_cb (GtkWidget         *widget,
411                                     EmpathyMainWindow *window)
412 {
413         //gossip_session_chatroom_join_favorites (window->session);
414 }
415
416 static void
417 main_window_room_manage_favorites_cb (GtkWidget         *widget,
418                                       EmpathyMainWindow *window)
419 {
420         //gossip_chatrooms_window_show (NULL, FALSE);
421 }
422
423 static void
424 main_window_chat_add_contact_cb (GtkWidget         *widget,
425                                  EmpathyMainWindow *window)
426 {
427         //gossip_add_contact_dialog_show (GTK_WINDOW (window->window), NULL);
428 }
429
430 static void
431 main_window_chat_show_offline_cb (GtkCheckMenuItem  *item,
432                                   EmpathyMainWindow *window)
433 {
434         gboolean current;
435
436         current = gtk_check_menu_item_get_active (item);
437
438         gossip_conf_set_bool (gossip_conf_get (),
439                               GOSSIP_PREFS_CONTACTS_SHOW_OFFLINE,
440                               current);
441
442         /* Turn off sound just while we alter the contact list. */
443         // FIXME: gossip_sound_set_enabled (FALSE);
444         gossip_contact_list_store_set_show_offline (window->list_store, current);
445         //gossip_sound_set_enabled (TRUE);
446 }
447
448 static gboolean
449 main_window_edit_button_press_event_cb (GtkWidget         *widget,
450                                         GdkEventButton    *event,
451                                         EmpathyMainWindow *window)
452 {
453         GossipContact *contact;
454         gchar         *group;
455
456         if (!event->button == 1) {
457                 return FALSE;
458         }
459
460         group = gossip_contact_list_view_get_selected_group (window->list_view);
461         if (group) {
462                 GtkMenuItem *item;
463                 GtkWidget   *label;
464                 GtkWidget   *submenu;
465
466                 item = GTK_MENU_ITEM (window->edit_context);
467                 label = gtk_bin_get_child (GTK_BIN (item));
468                 gtk_label_set_text (GTK_LABEL (label), _("Group"));
469
470                 gtk_widget_show (window->edit_context);
471                 gtk_widget_show (window->edit_context_separator);
472
473                 submenu = gossip_contact_list_view_get_group_menu (window->list_view);
474                 gtk_menu_item_set_submenu (item, submenu);
475
476                 g_free (group);
477
478                 return FALSE;
479         }
480
481         contact = gossip_contact_list_view_get_selected (window->list_view);
482         if (contact) {
483                 GtkMenuItem *item;
484                 GtkWidget   *label;
485                 GtkWidget   *submenu;
486
487                 item = GTK_MENU_ITEM (window->edit_context);
488                 label = gtk_bin_get_child (GTK_BIN (item));
489                 gtk_label_set_text (GTK_LABEL (label), _("Contact"));
490
491                 gtk_widget_show (window->edit_context);
492                 gtk_widget_show (window->edit_context_separator);
493
494                 submenu = gossip_contact_list_view_get_contact_menu (window->list_view,
495                                                                      contact);
496                 gtk_menu_item_set_submenu (item, submenu);
497
498                 g_object_unref (contact);
499
500                 return FALSE;
501         }
502
503         gtk_widget_hide (window->edit_context);
504         gtk_widget_hide (window->edit_context_separator);
505
506         return FALSE;
507 }
508
509 static void
510 main_window_edit_accounts_cb (GtkWidget         *widget,
511                               EmpathyMainWindow *window)
512 {
513         gossip_accounts_dialog_show ();
514 }
515
516 static void
517 main_window_edit_personal_information_cb (GtkWidget         *widget,
518                                           EmpathyMainWindow *window)
519 {
520         //gossip_vcard_dialog_show (GTK_WINDOW (window->window));
521 }
522
523 static void
524 main_window_edit_preferences_cb (GtkWidget         *widget,
525                                  EmpathyMainWindow *window)
526 {
527         gossip_preferences_show ();
528 }
529
530 static void
531 main_window_help_about_cb (GtkWidget         *widget,
532                            EmpathyMainWindow *window)
533 {
534         gossip_about_dialog_new (GTK_WINDOW (window->window));
535 }
536
537 static void
538 main_window_help_contents_cb (GtkWidget         *widget,
539                               EmpathyMainWindow *window)
540 {
541         //gossip_help_show ();
542 }
543
544 static gboolean
545 main_window_throbber_button_press_event_cb (GtkWidget      *throbber_ebox,
546                                             GdkEventButton *event,
547                                             gpointer        user_data)
548 {
549         if (event->type != GDK_BUTTON_PRESS ||
550             event->button != 1) {
551                 return FALSE;
552         }
553
554         gossip_accounts_dialog_show ();
555
556         return FALSE;
557 }
558
559 static void
560 main_window_status_changed_cb (MissionControl                  *mc,
561                                TelepathyConnectionStatus        status,
562                                McPresence                       presence,
563                                TelepathyConnectionStatusReason  reason,
564                                const gchar                     *unique_name,
565                                EmpathyMainWindow               *window)
566 {
567         main_window_update_status (window);
568 }
569
570 static void
571 main_window_update_status (EmpathyMainWindow *window)
572 {
573         GList *accounts, *l;
574         guint  connected = 0;
575         guint  connecting = 0;
576         guint  disconnected = 0;
577
578         /* Count number of connected/connecting/disconnected accounts */
579         accounts = mc_accounts_list (); 
580         for (l = accounts; l; l = l->next) {
581                 McAccount *account;
582                 guint      status;
583
584                 account = l->data;
585
586                 status = mission_control_get_connection_status (window->mc,
587                                                                 account,
588                                                                 NULL);
589
590                 if (status == 0) {
591                         connected++;
592                 } else if (status == 1) {
593                         connecting++;
594                 } else if (status == 2) {
595                         disconnected++;
596                 }
597
598                 g_object_unref (account);
599         }
600         g_list_free (accounts);
601
602         /* Update the spinner state */
603         if (connecting > 0) {
604                 ephy_spinner_start (EPHY_SPINNER (window->throbber));
605         } else {
606                 ephy_spinner_stop (EPHY_SPINNER (window->throbber));
607         }
608
609         /* Update widgets sensibility */
610         for (l = window->widgets_connected; l; l = l->next) {
611                 gtk_widget_set_sensitive (l->data, (connected > 0));
612         }
613
614         for (l = window->widgets_disconnected; l; l = l->next) {
615                 gtk_widget_set_sensitive (l->data, (disconnected > 0));
616         }
617
618         //app_favorite_chatroom_menu_update (); 
619 }
620
621 /*
622  * Accels
623  */
624 static void
625 main_window_accels_load (void)
626 {
627         gchar *filename;
628
629         filename = g_build_filename (g_get_home_dir (), ".gnome2", PACKAGE_NAME, ACCELS_FILENAME, NULL);
630         if (g_file_test (filename, G_FILE_TEST_EXISTS)) {
631                 gossip_debug (DEBUG_DOMAIN, "Loading from:'%s'", filename);
632                 gtk_accel_map_load (filename);
633         }
634
635         g_free (filename);
636 }
637
638 static void
639 main_window_accels_save (void)
640 {
641         gchar *dir;
642         gchar *file_with_path;
643
644         dir = g_build_filename (g_get_home_dir (), ".gnome2", PACKAGE_NAME, NULL);
645         g_mkdir_with_parents (dir, S_IRUSR | S_IWUSR | S_IXUSR);
646         file_with_path = g_build_filename (dir, ACCELS_FILENAME, NULL);
647         g_free (dir);
648
649         gossip_debug (DEBUG_DOMAIN, "Saving to:'%s'", file_with_path);
650         gtk_accel_map_save (file_with_path);
651
652         g_free (file_with_path);
653 }
654
655 static void
656 main_window_connection_items_setup (EmpathyMainWindow *window,
657                                     GladeXML          *glade)
658 {
659         GList         *list;
660         GtkWidget     *w;
661         gint           i;
662         const gchar *widgets_connected[] = {
663                 "room",
664                 "chat_new_message",
665                 "chat_add_contact",
666                 "edit_personal_information"
667         };
668         const gchar *widgets_disconnected[] = {
669         };
670
671         for (i = 0, list = NULL; i < G_N_ELEMENTS (widgets_connected); i++) {
672                 w = glade_xml_get_widget (glade, widgets_connected[i]);
673                 list = g_list_prepend (list, w);
674         }
675
676         window->widgets_connected = list;
677
678         for (i = 0, list = NULL; i < G_N_ELEMENTS (widgets_disconnected); i++) {
679                 w = glade_xml_get_widget (glade, widgets_disconnected[i]);
680                 list = g_list_prepend (list, w);
681         }
682
683         window->widgets_disconnected = list;
684 }
685
686 static gboolean
687 main_window_configure_event_timeout_cb (EmpathyMainWindow *window)
688 {
689         gint x, y, w, h;
690
691         gtk_window_get_size (GTK_WINDOW (window->window), &w, &h);
692         gtk_window_get_position (GTK_WINDOW (window->window), &x, &y);
693
694         gossip_geometry_save (GEOMETRY_NAME, x, y, w, h);
695
696         window->size_timeout_id = 0;
697
698         return FALSE;
699 }
700
701 static gboolean
702 main_window_configure_event_cb (GtkWidget         *widget,
703                                 GdkEventConfigure *event,
704                                 EmpathyMainWindow *window)
705 {
706         if (window->size_timeout_id) {
707                 g_source_remove (window->size_timeout_id);
708         }
709
710         window->size_timeout_id = g_timeout_add (500,
711                                                (GSourceFunc) main_window_configure_event_timeout_cb,
712                                                window);
713
714         return FALSE;
715 }
716
717 static void
718 main_window_notify_show_offline_cb (GossipConf  *conf,
719                                     const gchar *key,
720                                     gpointer     check_menu_item)
721 {
722         gboolean show_offline;
723
724         if (gossip_conf_get_bool (conf, key, &show_offline)) {
725                 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (check_menu_item),
726                                                 show_offline);
727         }
728 }
729
730 static void
731 main_window_notify_show_avatars_cb (GossipConf        *conf,
732                                     const gchar       *key,
733                                     EmpathyMainWindow *window)
734 {
735         gboolean show_avatars;
736
737         if (gossip_conf_get_bool (conf, key, &show_avatars)) {
738                 gossip_contact_list_store_set_show_avatars (window->list_store,
739                                                             show_avatars);
740         }
741 }
742
743 static void
744 main_window_notify_compact_contact_list_cb (GossipConf        *conf,
745                                             const gchar       *key,
746                                             EmpathyMainWindow *window)
747 {
748         gboolean compact_contact_list;
749
750         if (gossip_conf_get_bool (conf, key, &compact_contact_list)) {
751                 gossip_contact_list_store_set_is_compact (window->list_store,
752                                                           compact_contact_list);
753         }
754 }
755
756 static void
757 main_window_notify_sort_criterium_cb (GossipConf        *conf,
758                                       const gchar       *key,
759                                       EmpathyMainWindow *window)
760 {
761         gchar *str = NULL;
762
763         if (gossip_conf_get_string (conf, key, &str)) {
764                 GType       type;
765                 GEnumClass *enum_class;
766                 GEnumValue *enum_value;
767
768                 type = gossip_contact_list_store_sort_get_type ();
769                 enum_class = G_ENUM_CLASS (g_type_class_peek (type));
770                 enum_value = g_enum_get_value_by_nick (enum_class, str);
771
772                 if (enum_value) {
773                         gossip_contact_list_store_set_sort_criterium (window->list_store, 
774                                                                       enum_value->value);
775                 }
776         }
777 }
778