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