]> git.0d.be Git - empathy.git/blob - libempathy-gtk/empathy-main-window.c
[darcs-to-svn @ Move schemas to data/ and hide main window by default]
[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
335         return window->window;
336 }
337
338 static void
339 main_window_destroy_cb (GtkWidget         *widget,
340                         EmpathyMainWindow *window)
341 {
342         /* Save user-defined accelerators. */
343         main_window_accels_save ();
344
345         dbus_g_proxy_disconnect_signal (DBUS_G_PROXY (window->mc), "AccountStatusChanged",
346                                         G_CALLBACK (main_window_status_changed_cb),
347                                         window);
348
349         if (window->size_timeout_id) {
350                 g_source_remove (window->size_timeout_id);
351         }
352
353         g_list_free (window->widgets_connected);
354         g_list_free (window->widgets_disconnected);
355
356         g_object_unref (window->tooltips);
357         g_object_unref (window->mc);
358
359         g_free (window);
360 }
361
362 static void
363 main_window_favorite_chatroom_menu_setup (void)
364 {
365 }
366
367 static void
368 main_window_chat_quit_cb (GtkWidget         *widget,
369                           EmpathyMainWindow *window)
370 {
371         gtk_main_quit ();
372 }
373
374 static void
375 main_window_chat_new_message_cb (GtkWidget         *widget,
376                                  EmpathyMainWindow *window)
377 {
378         //gossip_new_message_dialog_show (GTK_WINDOW (window->window));
379 }
380
381 static void
382 main_window_chat_history_cb (GtkWidget         *widget,
383                              EmpathyMainWindow *window)
384 {
385         //gossip_log_window_show (NULL, NULL);
386 }
387
388 static void
389 main_window_room_join_new_cb (GtkWidget         *widget,
390                               EmpathyMainWindow *window)
391 {
392         //gossip_new_chatroom_dialog_show (GTK_WINDOW (window->window));
393 }
394
395 static void
396 main_window_room_join_favorites_cb (GtkWidget         *widget,
397                                     EmpathyMainWindow *window)
398 {
399         //gossip_session_chatroom_join_favorites (window->session);
400 }
401
402 static void
403 main_window_room_manage_favorites_cb (GtkWidget         *widget,
404                                       EmpathyMainWindow *window)
405 {
406         //gossip_chatrooms_window_show (NULL, FALSE);
407 }
408
409 static void
410 main_window_chat_add_contact_cb (GtkWidget         *widget,
411                                  EmpathyMainWindow *window)
412 {
413         //gossip_add_contact_dialog_show (GTK_WINDOW (window->window), NULL);
414 }
415
416 static void
417 main_window_chat_show_offline_cb (GtkCheckMenuItem  *item,
418                                   EmpathyMainWindow *window)
419 {
420         gboolean current;
421
422         current = gtk_check_menu_item_get_active (item);
423
424         gossip_conf_set_bool (gossip_conf_get (),
425                               GOSSIP_PREFS_CONTACTS_SHOW_OFFLINE,
426                               current);
427
428         /* Turn off sound just while we alter the contact list. */
429         // FIXME: gossip_sound_set_enabled (FALSE);
430         g_object_set (window->contact_list, "show_offline", current, NULL);
431         //gossip_sound_set_enabled (TRUE);
432 }
433
434 static gboolean
435 main_window_edit_button_press_event_cb (GtkWidget         *widget,
436                                         GdkEventButton    *event,
437                                         EmpathyMainWindow *window)
438 {
439         GossipContact *contact;
440         gchar         *group;
441
442         if (!event->button == 1) {
443                 return FALSE;
444         }
445
446         group = gossip_contact_list_get_selected_group (window->contact_list);
447         if (group) {
448                 GtkMenuItem *item;
449                 GtkWidget   *label;
450                 GtkWidget   *submenu;
451
452                 item = GTK_MENU_ITEM (window->edit_context);
453                 label = gtk_bin_get_child (GTK_BIN (item));
454                 gtk_label_set_text (GTK_LABEL (label), _("Group"));
455
456                 gtk_widget_show (window->edit_context);
457                 gtk_widget_show (window->edit_context_separator);
458
459                 submenu = gossip_contact_list_get_group_menu (window->contact_list);
460                 gtk_menu_item_set_submenu (item, submenu);
461
462                 g_free (group);
463
464                 return FALSE;
465         }
466
467         contact = gossip_contact_list_get_selected (window->contact_list);
468         if (contact) {
469                 GtkMenuItem *item;
470                 GtkWidget   *label;
471                 GtkWidget   *submenu;
472
473                 item = GTK_MENU_ITEM (window->edit_context);
474                 label = gtk_bin_get_child (GTK_BIN (item));
475                 gtk_label_set_text (GTK_LABEL (label), _("Contact"));
476
477                 gtk_widget_show (window->edit_context);
478                 gtk_widget_show (window->edit_context_separator);
479
480                 submenu = gossip_contact_list_get_contact_menu (window->contact_list,
481                                                                 contact);
482                 gtk_menu_item_set_submenu (item, submenu);
483
484                 g_object_unref (contact);
485
486                 return FALSE;
487         }
488
489         gtk_widget_hide (window->edit_context);
490         gtk_widget_hide (window->edit_context_separator);
491
492         return FALSE;
493 }
494
495 static void
496 main_window_edit_accounts_cb (GtkWidget         *widget,
497                               EmpathyMainWindow *window)
498 {
499         gossip_accounts_dialog_show ();
500 }
501
502 static void
503 main_window_edit_personal_information_cb (GtkWidget         *widget,
504                                           EmpathyMainWindow *window)
505 {
506         //gossip_vcard_dialog_show (GTK_WINDOW (window->window));
507 }
508
509 static void
510 main_window_edit_preferences_cb (GtkWidget         *widget,
511                                  EmpathyMainWindow *window)
512 {
513         gossip_preferences_show ();
514 }
515
516 static void
517 main_window_help_about_cb (GtkWidget         *widget,
518                            EmpathyMainWindow *window)
519 {
520         //gossip_about_dialog_new (GTK_WINDOW (window->window));
521 }
522
523 static void
524 main_window_help_contents_cb (GtkWidget         *widget,
525                               EmpathyMainWindow *window)
526 {
527         //gossip_help_show ();
528 }
529
530 static gboolean
531 main_window_throbber_button_press_event_cb (GtkWidget      *throbber_ebox,
532                                             GdkEventButton *event,
533                                             gpointer        user_data)
534 {
535         if (event->type != GDK_BUTTON_PRESS ||
536             event->button != 1) {
537                 return FALSE;
538         }
539
540         gossip_accounts_dialog_show ();
541
542         return FALSE;
543 }
544
545 static void
546 main_window_status_changed_cb (MissionControl                  *mc,
547                                TelepathyConnectionStatus        status,
548                                McPresence                       presence,
549                                TelepathyConnectionStatusReason  reason,
550                                const gchar                     *unique_name,
551                                EmpathyMainWindow               *window)
552 {
553         main_window_update_status (window);
554 }
555
556 static void
557 main_window_update_status (EmpathyMainWindow *window)
558 {
559         GList *accounts, *l;
560         guint  connected = 0;
561         guint  connecting = 0;
562         guint  disconnected = 0;
563
564         /* Count number of connected/connecting/disconnected accounts */
565         accounts = mc_accounts_list (); 
566         for (l = accounts; l; l = l->next) {
567                 McAccount *account;
568                 guint      status;
569
570                 account = l->data;
571
572                 status = mission_control_get_connection_status (window->mc,
573                                                                 account,
574                                                                 NULL);
575
576                 if (status == 0) {
577                         connected++;
578                 } else if (status == 1) {
579                         connecting++;
580                 } else if (status == 2) {
581                         disconnected++;
582                 }
583
584                 g_object_unref (account);
585         }
586         g_list_free (accounts);
587
588         /* Update the spinner state */
589         if (connecting > 0) {
590                 ephy_spinner_start (EPHY_SPINNER (window->throbber));
591         } else {
592                 ephy_spinner_stop (EPHY_SPINNER (window->throbber));
593         }
594
595         /* Update widgets sensibility */
596         for (l = window->widgets_connected; l; l = l->next) {
597                 gtk_widget_set_sensitive (l->data, (connected > 0));
598         }
599
600         for (l = window->widgets_disconnected; l; l = l->next) {
601                 gtk_widget_set_sensitive (l->data, (disconnected > 0));
602         }
603
604         //app_favorite_chatroom_menu_update (); 
605 }
606
607 /*
608  * Accels
609  */
610 static void
611 main_window_accels_load (void)
612 {
613         gchar *filename;
614
615         filename = g_build_filename (g_get_home_dir (), ".gnome2", PACKAGE_NAME, ACCELS_FILENAME, NULL);
616         if (g_file_test (filename, G_FILE_TEST_EXISTS)) {
617                 gossip_debug (DEBUG_DOMAIN, "Loading from:'%s'", filename);
618                 gtk_accel_map_load (filename);
619         }
620
621         g_free (filename);
622 }
623
624 static void
625 main_window_accels_save (void)
626 {
627         gchar *dir;
628         gchar *file_with_path;
629
630         dir = g_build_filename (g_get_home_dir (), ".gnome2", PACKAGE_NAME, NULL);
631         g_mkdir_with_parents (dir, S_IRUSR | S_IWUSR | S_IXUSR);
632         file_with_path = g_build_filename (dir, ACCELS_FILENAME, NULL);
633         g_free (dir);
634
635         gossip_debug (DEBUG_DOMAIN, "Saving to:'%s'", file_with_path);
636         gtk_accel_map_save (file_with_path);
637
638         g_free (file_with_path);
639 }
640
641 static void
642 main_window_connection_items_setup (EmpathyMainWindow *window,
643                                     GladeXML          *glade)
644 {
645         GList         *list;
646         GtkWidget     *w;
647         gint           i;
648         const gchar *widgets_connected[] = {
649                 "room",
650                 "chat_new_message",
651                 "chat_add_contact",
652                 "edit_personal_information"
653         };
654         const gchar *widgets_disconnected[] = {
655         };
656
657         for (i = 0, list = NULL; i < G_N_ELEMENTS (widgets_connected); i++) {
658                 w = glade_xml_get_widget (glade, widgets_connected[i]);
659                 list = g_list_prepend (list, w);
660         }
661
662         window->widgets_connected = list;
663
664         for (i = 0, list = NULL; i < G_N_ELEMENTS (widgets_disconnected); i++) {
665                 w = glade_xml_get_widget (glade, widgets_disconnected[i]);
666                 list = g_list_prepend (list, w);
667         }
668
669         window->widgets_disconnected = list;
670 }
671
672 static gboolean
673 main_window_configure_event_timeout_cb (EmpathyMainWindow *window)
674 {
675         gint x, y, w, h;
676
677         gtk_window_get_size (GTK_WINDOW (window->window), &w, &h);
678         gtk_window_get_position (GTK_WINDOW (window->window), &x, &y);
679
680         gossip_geometry_save (GEOMETRY_NAME, x, y, w, h);
681
682         window->size_timeout_id = 0;
683
684         return FALSE;
685 }
686
687 static gboolean
688 main_window_configure_event_cb (GtkWidget         *widget,
689                                 GdkEventConfigure *event,
690                                 EmpathyMainWindow *window)
691 {
692         if (window->size_timeout_id) {
693                 g_source_remove (window->size_timeout_id);
694         }
695
696         window->size_timeout_id = g_timeout_add (500,
697                                                (GSourceFunc) main_window_configure_event_timeout_cb,
698                                                window);
699
700         return FALSE;
701 }
702
703 static void
704 main_window_notify_show_offline_cb (GossipConf  *conf,
705                                     const gchar *key,
706                                     gpointer     check_menu_item)
707 {
708         gboolean show_offline;
709
710         if (gossip_conf_get_bool (conf, key, &show_offline)) {
711                 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (check_menu_item),
712                                                 show_offline);
713         }
714 }
715
716 static void
717 main_window_notify_show_avatars_cb (GossipConf        *conf,
718                                     const gchar       *key,
719                                     EmpathyMainWindow *window)
720 {
721         gboolean show_avatars;
722
723         if (gossip_conf_get_bool (conf, key, &show_avatars)) {
724                 gossip_contact_list_set_show_avatars (window->contact_list,
725                                                       show_avatars);
726         }
727 }
728
729 static void
730 main_window_notify_compact_contact_list_cb (GossipConf        *conf,
731                                             const gchar       *key,
732                                             EmpathyMainWindow *window)
733 {
734         gboolean compact_contact_list;
735
736         if (gossip_conf_get_bool (conf, key, &compact_contact_list)) {
737                 gossip_contact_list_set_is_compact (window->contact_list,
738                                                     compact_contact_list);
739         }
740 }
741
742 static void
743 main_window_notify_sort_criterium_cb (GossipConf        *conf,
744                                       const gchar       *key,
745                                       EmpathyMainWindow *window)
746 {
747         gchar *str = NULL;
748
749         if (gossip_conf_get_string (conf, key, &str)) {
750                 GType       type;
751                 GEnumClass *enum_class;
752                 GEnumValue *enum_value;
753
754                 type = gossip_contact_list_sort_get_type ();
755                 enum_class = G_ENUM_CLASS (g_type_class_peek (type));
756                 enum_value = g_enum_get_value_by_nick (enum_class, str);
757
758                 if (enum_value) {
759                         gossip_contact_list_set_sort_criterium (window->contact_list, 
760                                                                 enum_value->value);
761                 }
762         }
763 }
764