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