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