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