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