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