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