]> git.0d.be Git - empathy.git/blob - src/empathy-main-window.c
Include empathy-sound.h to make it build
[empathy.git] / src / empathy-main-window.c
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3  * Copyright (C) 2002-2007 Imendio AB
4  * Copyright (C) 2007-2008 Collabora Ltd.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License as
8  * published by the Free Software Foundation; either version 2 of the
9  * License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public
17  * License along with this program; if not, write to the
18  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19  * Boston, MA  02110-1301  USA
20  *
21  * Authors: Xavier Claessens <xclaesse@gmail.com>
22  */
23
24 #include <config.h>
25
26 #include <sys/stat.h>
27 #include <gtk/gtk.h>
28 #include <glib/gi18n.h>
29
30 #include <libempathy/empathy-contact.h>
31 #include <libempathy/empathy-utils.h>
32 #include <libempathy/empathy-account-manager.h>
33 #include <libempathy/empathy-dispatcher.h>
34 #include <libempathy/empathy-chatroom-manager.h>
35 #include <libempathy/empathy-chatroom.h>
36 #include <libempathy/empathy-contact-list.h>
37 #include <libempathy/empathy-contact-manager.h>
38 #include <libempathy/empathy-status-presets.h>
39
40 #include <libempathy-gtk/empathy-conf.h>
41 #include <libempathy-gtk/empathy-contact-dialogs.h>
42 #include <libempathy-gtk/empathy-contact-list-store.h>
43 #include <libempathy-gtk/empathy-contact-list-view.h>
44 #include <libempathy-gtk/empathy-geometry.h>
45 #include <libempathy-gtk/empathy-gtk-enum-types.h>
46 #include <libempathy-gtk/empathy-new-message-dialog.h>
47 #include <libempathy-gtk/empathy-log-window.h>
48 #include <libempathy-gtk/empathy-presence-chooser.h>
49 #include <libempathy-gtk/empathy-sound.h>
50 #include <libempathy-gtk/empathy-ui-utils.h>
51
52 #include <libmissioncontrol/mission-control.h>
53
54 #include "empathy-accounts-dialog.h"
55 #include "empathy-main-window.h"
56 #include "ephy-spinner.h"
57 #include "empathy-preferences.h"
58 #include "empathy-about-dialog.h"
59 #include "empathy-debug-dialog.h"
60 #include "empathy-new-chatroom-dialog.h"
61 #include "empathy-map-view.h"
62 #include "empathy-chatrooms-window.h"
63 #include "empathy-event-manager.h"
64 #include "empathy-ft-manager.h"
65
66 #define DEBUG_FLAG EMPATHY_DEBUG_OTHER
67 #include <libempathy/empathy-debug.h>
68
69 /* Flashing delay for icons (milliseconds). */
70 #define FLASH_TIMEOUT 500
71
72 /* Minimum width of roster window if something goes wrong. */
73 #define MIN_WIDTH 50
74
75 /* Accels (menu shortcuts) can be configured and saved */
76 #define ACCELS_FILENAME "accels.txt"
77
78 /* Name in the geometry file */
79 #define GEOMETRY_NAME "main-window"
80
81 typedef struct {
82         EmpathyContactListView  *list_view;
83         EmpathyContactListStore *list_store;
84         MissionControl          *mc;
85         EmpathyAccountManager   *account_manager;
86         EmpathyChatroomManager  *chatroom_manager;
87         EmpathyEventManager     *event_manager;
88         guint                    flash_timeout_id;
89         gboolean                 flash_on;
90
91         GtkWidget              *window;
92         GtkWidget              *main_vbox;
93         GtkWidget              *throbber;
94         GtkWidget              *presence_toolbar;
95         GtkWidget              *presence_chooser;
96         GtkWidget              *errors_vbox;
97
98         GtkUIManager           *ui_manager;
99         GtkAction              *view_history;
100         GtkAction              *room_join_favorites;
101         GtkWidget              *room_menu;
102         GtkWidget              *room_separator;
103         GtkWidget              *edit_context;
104         GtkWidget              *edit_context_separator;
105
106         guint                   size_timeout_id;
107         GHashTable             *errors;
108
109         /* Actions that are enabled when there are connected accounts */
110         GList                  *actions_connected;
111 } EmpathyMainWindow;
112
113 static EmpathyMainWindow *window = NULL;
114
115 static void
116 main_window_flash_stop (EmpathyMainWindow *window)
117 {
118         if (window->flash_timeout_id == 0) {
119                 return;
120         }
121
122         DEBUG ("Stop flashing");
123         g_source_remove (window->flash_timeout_id);
124         window->flash_timeout_id = 0;
125         window->flash_on = FALSE;
126 }
127
128 typedef struct {
129         EmpathyEvent *event;
130         gboolean      on;
131 } FlashForeachData;
132
133 static gboolean
134 main_window_flash_foreach (GtkTreeModel *model,
135                            GtkTreePath  *path,
136                            GtkTreeIter  *iter,
137                            gpointer      user_data)
138 {
139         FlashForeachData *data = (FlashForeachData *) user_data;
140         EmpathyContact   *contact;
141         const gchar      *icon_name;
142         GtkTreePath      *parent_path = NULL;
143         GtkTreeIter       parent_iter;
144
145         /* To be used with gtk_tree_model_foreach, update the status icon
146          * of the contact to show the event icon (on=TRUE) or the presence
147          * (on=FALSE) */
148         gtk_tree_model_get (model, iter,
149                             EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, &contact,
150                             -1);
151
152         if (contact != data->event->contact) {
153                 if (contact) {
154                         g_object_unref (contact);
155                 }
156                 return FALSE;
157         }
158
159         if (data->on) {
160                 icon_name = data->event->icon_name;
161         } else {
162                 icon_name = empathy_icon_name_for_contact (contact);
163         }
164
165         gtk_tree_store_set (GTK_TREE_STORE (model), iter,
166                             EMPATHY_CONTACT_LIST_STORE_COL_ICON_STATUS, icon_name,
167                             -1);
168
169         /* To make sure the parent is shown correctly, we emit
170          * the row-changed signal on the parent so it prompts
171          * it to be refreshed by the filter func.
172          */
173         if (gtk_tree_model_iter_parent (model, &parent_iter, iter)) {
174                 parent_path = gtk_tree_model_get_path (model, &parent_iter);
175         }
176         if (parent_path) {
177                 gtk_tree_model_row_changed (model, parent_path, &parent_iter);
178                 gtk_tree_path_free (parent_path);
179         }
180
181         g_object_unref (contact);
182
183         return FALSE;
184 }
185
186 static gboolean
187 main_window_flash_cb (EmpathyMainWindow *window)
188 {
189         GtkTreeModel     *model;
190         GSList           *events, *l;
191         gboolean          found_event = FALSE;
192         FlashForeachData  data;
193
194         window->flash_on = !window->flash_on;
195         data.on = window->flash_on;
196         model = GTK_TREE_MODEL (window->list_store);
197
198         events = empathy_event_manager_get_events (window->event_manager);
199         for (l = events; l; l = l->next) {
200                 data.event = l->data;
201                 if (!data.event->contact || !data.event->must_ack) {
202                         continue;
203                 }
204
205                 found_event = TRUE;
206                 gtk_tree_model_foreach (model,
207                                         main_window_flash_foreach,
208                                         &data);
209         }
210
211         if (!found_event) {
212                 main_window_flash_stop (window);
213         }
214
215         return TRUE;
216 }
217
218 static void
219 main_window_flash_start (EmpathyMainWindow *window)
220 {
221         if (window->flash_timeout_id != 0) {
222                 return;
223         }
224
225         DEBUG ("Start flashing");
226         window->flash_timeout_id = g_timeout_add (FLASH_TIMEOUT,
227                                                   (GSourceFunc) main_window_flash_cb,
228                                                   window);
229         main_window_flash_cb (window);
230 }
231
232 static void
233 main_window_event_added_cb (EmpathyEventManager *manager,
234                             EmpathyEvent        *event,
235                             EmpathyMainWindow   *window)
236 {
237         if (event->contact) {
238                 main_window_flash_start (window);
239         }
240 }
241
242 static void
243 main_window_event_removed_cb (EmpathyEventManager *manager,
244                               EmpathyEvent        *event,
245                               EmpathyMainWindow   *window)
246 {
247         FlashForeachData data;
248
249         if (!event->contact) {
250                 return;
251         }
252
253         data.on = FALSE;
254         data.event = event;
255         gtk_tree_model_foreach (GTK_TREE_MODEL (window->list_store),
256                                 main_window_flash_foreach,
257                                 &data);
258 }
259
260 static void
261 main_window_row_activated_cb (EmpathyContactListView *view,
262                               GtkTreePath            *path,
263                               GtkTreeViewColumn      *col,
264                               EmpathyMainWindow      *window)
265 {
266         EmpathyContact *contact;
267         GtkTreeModel   *model;
268         GtkTreeIter     iter;
269         GSList         *events, *l;
270
271         model = GTK_TREE_MODEL (window->list_store);
272         gtk_tree_model_get_iter (model, &iter, path);
273         gtk_tree_model_get (model, &iter,
274                             EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, &contact,
275                             -1);
276
277         if (!contact) {
278                 return;
279         }
280
281         /* If the contact has an event activate it, otherwise the
282          * default handler of row-activated will be called. */
283         events = empathy_event_manager_get_events (window->event_manager);
284         for (l = events; l; l = l->next) {
285                 EmpathyEvent *event = l->data;
286
287                 if (event->contact == contact) {
288                         DEBUG ("Activate event");
289                         empathy_event_activate (event);
290
291                         /* We don't want the default handler of this signal
292                          * (e.g. open a chat) */
293                         g_signal_stop_emission_by_name (view, "row-activated");
294                         break;
295                 }
296         }
297
298         g_object_unref (contact);
299 }
300
301 static void
302 main_window_error_edit_clicked_cb (GtkButton         *button,
303                                    EmpathyMainWindow *window)
304 {
305         McAccount *account;
306         GtkWidget *error_widget;
307
308         account = g_object_get_data (G_OBJECT (button), "account");
309         empathy_accounts_dialog_show (GTK_WINDOW (window->window), account);
310
311         error_widget = g_hash_table_lookup (window->errors, account);
312         gtk_widget_destroy (error_widget);
313         g_hash_table_remove (window->errors, account);
314 }
315
316 static void
317 main_window_error_clear_clicked_cb (GtkButton         *button,
318                                     EmpathyMainWindow *window)
319 {
320         McAccount *account;
321         GtkWidget *error_widget;
322
323         account = g_object_get_data (G_OBJECT (button), "account");
324         error_widget = g_hash_table_lookup (window->errors, account);
325         gtk_widget_destroy (error_widget);
326         g_hash_table_remove (window->errors, account);
327 }
328
329 static void
330 main_window_error_display (EmpathyMainWindow *window,
331                            McAccount         *account,
332                            const gchar       *message)
333 {
334         GtkWidget *child;
335         GtkWidget *table;
336         GtkWidget *image;
337         GtkWidget *button_edit;
338         GtkWidget *alignment;
339         GtkWidget *hbox;
340         GtkWidget *label;
341         GtkWidget *fixed;
342         GtkWidget *vbox;
343         GtkWidget *button_close;
344         gchar     *str;
345
346         child = g_hash_table_lookup (window->errors, account);
347         if (child) {
348                 label = g_object_get_data (G_OBJECT (child), "label");
349
350                 /* Just set the latest error and return */
351                 str = g_markup_printf_escaped ("<b>%s</b>\n%s",
352                                                mc_account_get_display_name (account),
353                                                message);
354                 gtk_label_set_markup (GTK_LABEL (label), str);
355                 g_free (str);
356
357                 return;
358         }
359
360         child = gtk_vbox_new (FALSE, 0);
361         gtk_box_pack_start (GTK_BOX (window->errors_vbox), child, FALSE, TRUE, 0);
362         gtk_container_set_border_width (GTK_CONTAINER (child), 6);
363         gtk_widget_show (child);
364
365         table = gtk_table_new (2, 4, FALSE);
366         gtk_widget_show (table);
367         gtk_box_pack_start (GTK_BOX (child), table, TRUE, TRUE, 0);
368         gtk_table_set_row_spacings (GTK_TABLE (table), 12);
369         gtk_table_set_col_spacings (GTK_TABLE (table), 6);
370
371         image = gtk_image_new_from_stock (GTK_STOCK_DISCONNECT, GTK_ICON_SIZE_MENU);
372         gtk_widget_show (image);
373         gtk_table_attach (GTK_TABLE (table), image, 0, 1, 0, 2,
374                           (GtkAttachOptions) (GTK_FILL),
375                           (GtkAttachOptions) (GTK_FILL), 0, 0);
376         gtk_misc_set_alignment (GTK_MISC (image), 0.5, 0);
377
378         button_edit = gtk_button_new ();
379         gtk_widget_show (button_edit);
380         gtk_table_attach (GTK_TABLE (table), button_edit, 1, 2, 1, 2,
381                           (GtkAttachOptions) (GTK_FILL),
382                           (GtkAttachOptions) (0), 0, 0);
383
384         alignment = gtk_alignment_new (0.5, 0.5, 0, 0);
385         gtk_widget_show (alignment);
386         gtk_container_add (GTK_CONTAINER (button_edit), alignment);
387
388         hbox = gtk_hbox_new (FALSE, 2);
389         gtk_widget_show (hbox);
390         gtk_container_add (GTK_CONTAINER (alignment), hbox);
391
392         image = gtk_image_new_from_stock (GTK_STOCK_EDIT, GTK_ICON_SIZE_BUTTON);
393         gtk_widget_show (image);
394         gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
395
396         label = gtk_label_new_with_mnemonic (_("_Edit account"));
397         gtk_widget_show (label);
398         gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
399
400         fixed = gtk_fixed_new ();
401         gtk_widget_show (fixed);
402         gtk_table_attach (GTK_TABLE (table), fixed, 2, 3, 1, 2,
403                           (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
404                           (GtkAttachOptions) (GTK_FILL), 0, 0);
405
406         vbox = gtk_vbox_new (FALSE, 6);
407         gtk_widget_show (vbox);
408         gtk_table_attach (GTK_TABLE (table), vbox, 3, 4, 0, 2,
409                           (GtkAttachOptions) (GTK_FILL),
410                           (GtkAttachOptions) (GTK_FILL), 0, 0);
411
412         button_close = gtk_button_new ();
413         gtk_widget_show (button_close);
414         gtk_box_pack_start (GTK_BOX (vbox), button_close, FALSE, FALSE, 0);
415         gtk_button_set_relief (GTK_BUTTON (button_close), GTK_RELIEF_NONE);
416
417
418         image = gtk_image_new_from_stock ("gtk-close", GTK_ICON_SIZE_MENU);
419         gtk_widget_show (image);
420         gtk_container_add (GTK_CONTAINER (button_close), image);
421
422         label = gtk_label_new ("");
423         gtk_widget_show (label);
424         gtk_table_attach (GTK_TABLE (table), label, 1, 3, 0, 1,
425                           (GtkAttachOptions) (GTK_EXPAND | GTK_SHRINK | GTK_FILL),
426                           (GtkAttachOptions) (GTK_EXPAND | GTK_SHRINK | GTK_FILL), 0, 0);
427         gtk_widget_set_size_request (label, 175, -1);
428         gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
429         gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
430         gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
431
432         str = g_markup_printf_escaped ("<b>%s</b>\n%s",
433                                        mc_account_get_display_name (account),
434                                        message);
435         gtk_label_set_markup (GTK_LABEL (label), str);
436         g_free (str);
437
438         g_object_set_data (G_OBJECT (child), "label", label);
439         g_object_set_data_full (G_OBJECT (button_edit),
440                                 "account", g_object_ref (account),
441                                 g_object_unref);
442         g_object_set_data_full (G_OBJECT (button_close),
443                                 "account", g_object_ref (account),
444                                 g_object_unref);
445
446         g_signal_connect (button_edit, "clicked",
447                           G_CALLBACK (main_window_error_edit_clicked_cb),
448                           window);
449
450         g_signal_connect (button_close, "clicked",
451                           G_CALLBACK (main_window_error_clear_clicked_cb),
452                           window);
453
454         gtk_widget_show (window->errors_vbox);
455
456         g_hash_table_insert (window->errors, g_object_ref (account), child);
457 }
458
459 static void
460 main_window_update_status (EmpathyMainWindow *window, EmpathyAccountManager *manager)
461 {
462         int  connected;
463         int  connecting;
464         GList *l;
465
466         /* Count number of connected/connecting/disconnected accounts */
467         connected = empathy_account_manager_get_connected_accounts (manager);
468         connecting = empathy_account_manager_get_connecting_accounts (manager);
469
470         /* Update the spinner state */
471         if (connecting > 0) {
472                 ephy_spinner_start (EPHY_SPINNER (window->throbber));
473         } else {
474                 ephy_spinner_stop (EPHY_SPINNER (window->throbber));
475         }
476
477         /* Update widgets sensibility */
478         for (l = window->actions_connected; l; l = l->next) {
479                 gtk_action_set_sensitive (l->data, (connected > 0));
480         }
481 }
482
483 static void
484 main_window_connection_changed_cb (EmpathyAccountManager *manager,
485                                    McAccount *account,
486                                    TpConnectionStatusReason reason,
487                                    TpConnectionStatus current,
488                                    TpConnectionStatus previous,
489                                    EmpathyMainWindow *window)
490 {
491         main_window_update_status (window, manager);
492
493         if (current == TP_CONNECTION_STATUS_DISCONNECTED &&
494             reason != TP_CONNECTION_STATUS_REASON_REQUESTED) {
495                 const gchar *message;
496
497                 switch (reason) {
498                 case TP_CONNECTION_STATUS_REASON_NONE_SPECIFIED:
499                         message = _("No error specified");
500                         break;
501                 case TP_CONNECTION_STATUS_REASON_NETWORK_ERROR:
502                         message = _("Network error");
503                         break;
504                 case TP_CONNECTION_STATUS_REASON_AUTHENTICATION_FAILED:
505                         message = _("Authentication failed");
506                         break;
507                 case TP_CONNECTION_STATUS_REASON_ENCRYPTION_ERROR:
508                         message = _("Encryption error");
509                         break;
510                 case TP_CONNECTION_STATUS_REASON_NAME_IN_USE:
511                         message = _("Name in use");
512                         break;
513                 case TP_CONNECTION_STATUS_REASON_CERT_NOT_PROVIDED:
514                         message = _("Certificate not provided");
515                         break;
516                 case TP_CONNECTION_STATUS_REASON_CERT_UNTRUSTED:
517                         message = _("Certificate untrusted");
518                         break;
519                 case TP_CONNECTION_STATUS_REASON_CERT_EXPIRED:
520                         message = _("Certificate expired");
521                         break;
522                 case TP_CONNECTION_STATUS_REASON_CERT_NOT_ACTIVATED:
523                         message = _("Certificate not activated");
524                         break;
525                 case TP_CONNECTION_STATUS_REASON_CERT_HOSTNAME_MISMATCH:
526                         message = _("Certificate hostname mismatch");
527                         break;
528                 case TP_CONNECTION_STATUS_REASON_CERT_FINGERPRINT_MISMATCH:
529                         message = _("Certificate fingerprint mismatch");
530                         break;
531                 case TP_CONNECTION_STATUS_REASON_CERT_SELF_SIGNED:
532                         message = _("Certificate self-signed");
533                         break;
534                 case TP_CONNECTION_STATUS_REASON_CERT_OTHER_ERROR:
535                         message = _("Certificate error");
536                         break;
537                 default:
538                         message = _("Unknown error");
539                         break;
540                 }
541
542                 main_window_error_display (window, account, message);
543         }
544
545         if (current == TP_CONNECTION_STATUS_DISCONNECTED) {
546                 empathy_sound_play (GTK_WIDGET (window->window),
547                                     EMPATHY_SOUND_ACCOUNT_DISCONNECTED);
548         }
549
550         if (current == TP_CONNECTION_STATUS_CONNECTED) {
551                 GtkWidget *error_widget;
552
553                 empathy_sound_play (GTK_WIDGET (window->window),
554                                     EMPATHY_SOUND_ACCOUNT_CONNECTED);
555
556                 /* Account connected without error, remove error message if any */
557                 error_widget = g_hash_table_lookup (window->errors, account);
558                 if (error_widget) {
559                         gtk_widget_destroy (error_widget);
560                         g_hash_table_remove (window->errors, account);
561                 }
562         }
563 }
564
565 static void
566 main_window_contact_presence_changed_cb (EmpathyContactMonitor *monitor,
567                                          EmpathyContact *contact,
568                                          TpConnectionPresenceType current,
569                                          TpConnectionPresenceType previous,
570                                          EmpathyMainWindow *window)
571 {
572         McAccount *account;
573         gboolean should_play;
574
575         account = empathy_contact_get_account (contact);
576         should_play = !empathy_account_manager_is_account_just_connected (window->account_manager, account);
577
578         if (!should_play) {
579                 return;
580         }
581
582   if (tp_connection_presence_type_cmp_availability (previous,
583      TP_CONNECTION_PRESENCE_TYPE_OFFLINE) > 0)
584     {
585       /* contact was online */
586       if (tp_connection_presence_type_cmp_availability (current,
587           TP_CONNECTION_PRESENCE_TYPE_OFFLINE) <= 0)
588         /* someone is logging off */
589         empathy_sound_play (GTK_WIDGET (window->window),
590           EMPATHY_SOUND_CONTACT_DISCONNECTED);
591     }
592   else
593     {
594       /* contact was offline */
595       if (tp_connection_presence_type_cmp_availability (current,
596           TP_CONNECTION_PRESENCE_TYPE_OFFLINE) > 0)
597         /* someone is logging in */
598         empathy_sound_play (GTK_WIDGET (window->window),
599           EMPATHY_SOUND_CONTACT_CONNECTED);
600     }
601 }
602
603 static void
604 main_window_accels_load (void)
605 {
606         gchar *filename;
607
608         filename = g_build_filename (g_get_home_dir (), ".gnome2", PACKAGE_NAME, ACCELS_FILENAME, NULL);
609         if (g_file_test (filename, G_FILE_TEST_EXISTS)) {
610                 DEBUG ("Loading from:'%s'", filename);
611                 gtk_accel_map_load (filename);
612         }
613
614         g_free (filename);
615 }
616
617 static void
618 main_window_accels_save (void)
619 {
620         gchar *dir;
621         gchar *file_with_path;
622
623         dir = g_build_filename (g_get_home_dir (), ".gnome2", PACKAGE_NAME, NULL);
624         g_mkdir_with_parents (dir, S_IRUSR | S_IWUSR | S_IXUSR);
625         file_with_path = g_build_filename (dir, ACCELS_FILENAME, NULL);
626         g_free (dir);
627
628         DEBUG ("Saving to:'%s'", file_with_path);
629         gtk_accel_map_save (file_with_path);
630
631         g_free (file_with_path);
632 }
633
634 static void
635 main_window_destroy_cb (GtkWidget         *widget,
636                         EmpathyMainWindow *window)
637 {
638         /* Save user-defined accelerators. */
639         main_window_accels_save ();
640
641         g_signal_handlers_disconnect_by_func (window->account_manager,
642                                               main_window_connection_changed_cb,
643                                               window);
644
645         if (window->size_timeout_id) {
646                 g_source_remove (window->size_timeout_id);
647         }
648
649         g_list_free (window->actions_connected);
650
651         g_object_unref (window->mc);
652         g_object_unref (window->account_manager);
653         g_object_unref (window->list_store);
654         g_hash_table_destroy (window->errors);
655
656         g_signal_handlers_disconnect_by_func (window->event_manager,
657                                               main_window_event_added_cb,
658                                               window);
659         g_signal_handlers_disconnect_by_func (window->event_manager,
660                                               main_window_event_removed_cb,
661                                               window);
662         g_object_unref (window->event_manager);
663         g_object_unref (window->ui_manager);
664
665         g_free (window);
666 }
667
668 static void
669 main_window_chat_quit_cb (GtkAction         *action,
670                           EmpathyMainWindow *window)
671 {
672         gtk_main_quit ();
673 }
674
675 static void
676 main_window_view_history_cb (GtkAction         *action,
677                              EmpathyMainWindow *window)
678 {
679         empathy_log_window_show (NULL, NULL, FALSE, GTK_WINDOW (window->window));
680 }
681
682 static void
683 main_window_chat_new_message_cb (GtkAction         *action,
684                                  EmpathyMainWindow *window)
685 {
686         empathy_new_message_dialog_show (GTK_WINDOW (window->window));
687 }
688
689 static void
690 main_window_chat_add_contact_cb (GtkAction         *action,
691                                  EmpathyMainWindow *window)
692 {
693         empathy_new_contact_dialog_show (GTK_WINDOW (window->window));
694 }
695
696 static void
697 main_window_view_show_ft_manager (GtkAction         *action,
698                                   EmpathyMainWindow *window)
699 {
700         empathy_ft_manager_show ();
701 }
702
703 static void
704 main_window_view_show_offline_cb (GtkToggleAction   *action,
705                                   EmpathyMainWindow *window)
706 {
707         gboolean current;
708
709         current = gtk_toggle_action_get_active (action);
710         empathy_conf_set_bool (empathy_conf_get (),
711                               EMPATHY_PREFS_CONTACTS_SHOW_OFFLINE,
712                               current);
713
714         /* Turn off sound just while we alter the contact list. */
715         // FIXME: empathy_sound_set_enabled (FALSE);
716         empathy_contact_list_store_set_show_offline (window->list_store, current);
717         //empathy_sound_set_enabled (TRUE);
718 }
719
720 static void
721 main_window_view_show_map_cb (GtkCheckMenuItem  *item,
722                               EmpathyMainWindow *window)
723 {
724 #if HAVE_LIBCHAMPLAIN
725         empathy_map_view_show ();
726 #endif
727 }
728
729 static void
730 main_window_favorite_chatroom_join (EmpathyChatroom *chatroom)
731 {
732         EmpathyAccountManager *manager;
733         McAccount      *account;
734         TpConnection   *connection;
735         const gchar    *room;
736
737         manager = empathy_account_manager_dup_singleton ();
738         account = empathy_chatroom_get_account (chatroom);
739         connection = empathy_account_manager_get_connection (manager, account);
740         room = empathy_chatroom_get_room (chatroom);
741         g_object_unref (manager);
742
743         if (connection != NULL) {
744                 DEBUG ("Requesting channel for '%s'", room);
745                 empathy_dispatcher_join_muc (connection, room, NULL, NULL);
746         }
747 }
748
749 static void
750 main_window_favorite_chatroom_menu_activate_cb (GtkMenuItem    *menu_item,
751                                                 EmpathyChatroom *chatroom)
752 {
753         main_window_favorite_chatroom_join (chatroom);
754 }
755
756 static void
757 main_window_favorite_chatroom_menu_add (EmpathyMainWindow *window,
758                                         EmpathyChatroom    *chatroom)
759 {
760         GtkWidget   *menu_item;
761         const gchar *name;
762
763         if (g_object_get_data (G_OBJECT (chatroom), "menu_item")) {
764                 return;
765         }
766
767         name = empathy_chatroom_get_name (chatroom);
768         menu_item = gtk_menu_item_new_with_label (name);
769
770         g_object_set_data (G_OBJECT (chatroom), "menu_item", menu_item);
771         g_signal_connect (menu_item, "activate",
772                           G_CALLBACK (main_window_favorite_chatroom_menu_activate_cb),
773                           chatroom);
774
775         gtk_menu_shell_insert (GTK_MENU_SHELL (window->room_menu),
776                                menu_item, 4);
777
778         gtk_widget_show (menu_item);
779 }
780
781 static void
782 main_window_favorite_chatroom_menu_added_cb (EmpathyChatroomManager *manager,
783                                              EmpathyChatroom        *chatroom,
784                                              EmpathyMainWindow     *window)
785 {
786         main_window_favorite_chatroom_menu_add (window, chatroom);
787         gtk_widget_show (window->room_separator);
788         gtk_action_set_sensitive (window->room_join_favorites, TRUE);
789 }
790
791 static void
792 main_window_favorite_chatroom_menu_removed_cb (EmpathyChatroomManager *manager,
793                                                EmpathyChatroom        *chatroom,
794                                                EmpathyMainWindow     *window)
795 {
796         GtkWidget *menu_item;
797         GList *chatrooms;
798
799         menu_item = g_object_get_data (G_OBJECT (chatroom), "menu_item");
800         g_object_set_data (G_OBJECT (chatroom), "menu_item", NULL);
801         gtk_widget_destroy (menu_item);
802
803         chatrooms = empathy_chatroom_manager_get_chatrooms (window->chatroom_manager, NULL);
804         if (chatrooms) {
805                 gtk_widget_show (window->room_separator);
806         } else {
807                 gtk_widget_hide (window->room_separator);
808         }
809
810         gtk_action_set_sensitive (window->room_join_favorites, chatrooms != NULL);
811         g_list_free (chatrooms);
812 }
813
814 static void
815 main_window_favorite_chatroom_menu_setup (EmpathyMainWindow *window)
816 {
817         GList *chatrooms, *l;
818         GtkWidget *room;
819
820         window->chatroom_manager = empathy_chatroom_manager_dup_singleton (NULL);
821         chatrooms = empathy_chatroom_manager_get_chatrooms (window->chatroom_manager, NULL);
822         room = gtk_ui_manager_get_widget (window->ui_manager,
823                 "/menubar/room");
824         window->room_menu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (room));
825         window->room_separator = gtk_ui_manager_get_widget (window->ui_manager,
826                 "/menubar/room/room_separator");
827
828         for (l = chatrooms; l; l = l->next) {
829                 main_window_favorite_chatroom_menu_add (window, l->data);
830         }
831
832         if (!chatrooms) {
833                 gtk_widget_hide (window->room_separator);
834         }
835
836         gtk_action_set_sensitive (window->room_join_favorites, chatrooms != NULL);
837
838         g_signal_connect (window->chatroom_manager, "chatroom-added",
839                           G_CALLBACK (main_window_favorite_chatroom_menu_added_cb),
840                           window);
841         g_signal_connect (window->chatroom_manager, "chatroom-removed",
842                           G_CALLBACK (main_window_favorite_chatroom_menu_removed_cb),
843                           window);
844
845         g_list_free (chatrooms);
846 }
847
848 static void
849 main_window_room_join_new_cb (GtkAction         *action,
850                               EmpathyMainWindow *window)
851 {
852         empathy_new_chatroom_dialog_show (GTK_WINDOW (window->window));
853 }
854
855 static void
856 main_window_room_join_favorites_cb (GtkAction         *action,
857                                     EmpathyMainWindow *window)
858 {
859         GList *chatrooms, *l;
860
861         chatrooms = empathy_chatroom_manager_get_chatrooms (window->chatroom_manager, NULL);
862         for (l = chatrooms; l; l = l->next) {
863                 main_window_favorite_chatroom_join (l->data);
864         }
865         g_list_free (chatrooms);
866 }
867
868 static void
869 main_window_room_manage_favorites_cb (GtkAction         *action,
870                                       EmpathyMainWindow *window)
871 {
872         empathy_chatrooms_window_show (GTK_WINDOW (window->window));
873 }
874
875 static void
876 main_window_edit_cb (GtkAction *action,
877                      EmpathyMainWindow *window)
878 {
879         GtkWidget *submenu;
880
881         /* FIXME: It should use the UIManager to merge the contact/group submenu */
882         submenu = empathy_contact_list_view_get_contact_menu (window->list_view);
883         if (submenu) {
884                 GtkMenuItem *item;
885                 GtkWidget   *label;
886
887                 item = GTK_MENU_ITEM (window->edit_context);
888                 label = gtk_bin_get_child (GTK_BIN (item));
889                 gtk_label_set_text (GTK_LABEL (label), _("Contact"));
890
891                 gtk_widget_show (window->edit_context);
892                 gtk_widget_show (window->edit_context_separator);
893
894                 gtk_menu_item_set_submenu (item, submenu);
895
896                 return;
897         }
898
899         submenu = empathy_contact_list_view_get_group_menu (window->list_view);
900         if (submenu) {
901                 GtkMenuItem *item;
902                 GtkWidget   *label;
903
904                 item = GTK_MENU_ITEM (window->edit_context);
905                 label = gtk_bin_get_child (GTK_BIN (item));
906                 gtk_label_set_text (GTK_LABEL (label), _("Group"));
907
908                 gtk_widget_show (window->edit_context);
909                 gtk_widget_show (window->edit_context_separator);
910
911                 gtk_menu_item_set_submenu (item, submenu);
912
913                 return;
914         }
915
916         gtk_widget_hide (window->edit_context);
917         gtk_widget_hide (window->edit_context_separator);
918
919         return;
920 }
921
922 static void
923 main_window_edit_accounts_cb (GtkAction         *action,
924                               EmpathyMainWindow *window)
925 {
926         empathy_accounts_dialog_show (GTK_WINDOW (window->window), NULL);
927 }
928
929 static void
930 main_window_edit_personal_information_cb (GtkAction         *action,
931                                           EmpathyMainWindow *window)
932 {
933         empathy_contact_personal_dialog_show (GTK_WINDOW (window->window));
934 }
935
936 static void
937 main_window_edit_preferences_cb (GtkAction         *action,
938                                  EmpathyMainWindow *window)
939 {
940         empathy_preferences_show (GTK_WINDOW (window->window));
941 }
942
943 static void
944 main_window_help_about_cb (GtkAction         *action,
945                            EmpathyMainWindow *window)
946 {
947         empathy_about_dialog_new (GTK_WINDOW (window->window));
948 }
949
950 static void
951 main_window_help_debug_cb (GtkAction         *action,
952                            EmpathyMainWindow *window)
953 {
954         empathy_debug_dialog_new (GTK_WINDOW (window->window));
955 }
956
957 static void
958 main_window_help_contents_cb (GtkAction         *action,
959                               EmpathyMainWindow *window)
960 {
961         empathy_url_show (window->window, "ghelp:empathy");
962 }
963
964 static gboolean
965 main_window_throbber_button_press_event_cb (GtkWidget         *throbber_ebox,
966                                             GdkEventButton    *event,
967                                             EmpathyMainWindow *window)
968 {
969         if (event->type != GDK_BUTTON_PRESS ||
970             event->button != 1) {
971                 return FALSE;
972         }
973
974         empathy_accounts_dialog_show (GTK_WINDOW (window->window), NULL);
975
976         return FALSE;
977 }
978
979 static gboolean
980 main_window_configure_event_timeout_cb (EmpathyMainWindow *window)
981 {
982         gint x, y, w, h;
983
984         gtk_window_get_size (GTK_WINDOW (window->window), &w, &h);
985         gtk_window_get_position (GTK_WINDOW (window->window), &x, &y);
986
987         empathy_geometry_save (GEOMETRY_NAME, x, y, w, h);
988
989         window->size_timeout_id = 0;
990
991         return FALSE;
992 }
993
994 static gboolean
995 main_window_configure_event_cb (GtkWidget         *widget,
996                                 GdkEventConfigure *event,
997                                 EmpathyMainWindow *window)
998 {
999         if (window->size_timeout_id) {
1000                 g_source_remove (window->size_timeout_id);
1001         }
1002
1003         window->size_timeout_id = g_timeout_add_seconds (1,
1004                                                          (GSourceFunc) main_window_configure_event_timeout_cb,
1005                                                          window);
1006
1007         return FALSE;
1008 }
1009
1010 static void
1011 main_window_account_created_or_deleted_cb (EmpathyAccountManager  *manager,
1012                                            McAccount              *account,
1013                                            EmpathyMainWindow      *window)
1014 {
1015         gtk_action_set_sensitive (window->view_history,
1016                 empathy_account_manager_get_count (manager) > 0);
1017 }
1018
1019 static void
1020 main_window_notify_show_offline_cb (EmpathyConf *conf,
1021                                     const gchar *key,
1022                                     gpointer     toggle_action)
1023 {
1024         gboolean show_offline;
1025
1026         if (empathy_conf_get_bool (conf, key, &show_offline)) {
1027                 gtk_toggle_action_set_active (toggle_action, show_offline);
1028         }
1029 }
1030
1031 static void
1032 main_window_notify_show_avatars_cb (EmpathyConf        *conf,
1033                                     const gchar       *key,
1034                                     EmpathyMainWindow *window)
1035 {
1036         gboolean show_avatars;
1037
1038         if (empathy_conf_get_bool (conf, key, &show_avatars)) {
1039                 empathy_contact_list_store_set_show_avatars (window->list_store,
1040                                                             show_avatars);
1041         }
1042 }
1043
1044 static void
1045 main_window_notify_compact_contact_list_cb (EmpathyConf        *conf,
1046                                             const gchar       *key,
1047                                             EmpathyMainWindow *window)
1048 {
1049         gboolean compact_contact_list;
1050
1051         if (empathy_conf_get_bool (conf, key, &compact_contact_list)) {
1052                 empathy_contact_list_store_set_is_compact (window->list_store,
1053                                                           compact_contact_list);
1054         }
1055 }
1056
1057 static void
1058 main_window_notify_sort_criterium_cb (EmpathyConf       *conf,
1059                                       const gchar       *key,
1060                                       EmpathyMainWindow *window)
1061 {
1062         gchar *str = NULL;
1063
1064         if (empathy_conf_get_string (conf, key, &str) && str) {
1065                 GType       type;
1066                 GEnumClass *enum_class;
1067                 GEnumValue *enum_value;
1068
1069                 type = empathy_contact_list_store_sort_get_type ();
1070                 enum_class = G_ENUM_CLASS (g_type_class_peek (type));
1071                 enum_value = g_enum_get_value_by_nick (enum_class, str);
1072                 g_free (str);
1073
1074                 if (enum_value) {
1075                         empathy_contact_list_store_set_sort_criterium (window->list_store,
1076                                                                        enum_value->value);
1077                 }
1078         }
1079 }
1080
1081 static void
1082 main_window_connection_items_setup (EmpathyMainWindow *window,
1083                                     GtkBuilder        *gui)
1084 {
1085         GList         *list;
1086         GObject       *action;
1087         gint           i;
1088         const gchar *actions_connected[] = {
1089                 "room",
1090                 "chat_new_message",
1091                 "chat_add_contact",
1092                 "edit_personal_information"
1093         };
1094
1095         for (i = 0, list = NULL; i < G_N_ELEMENTS (actions_connected); i++) {
1096                 action = gtk_builder_get_object (gui, actions_connected[i]);
1097                 list = g_list_prepend (list, action);
1098         }
1099
1100         window->actions_connected = list;
1101 }
1102
1103 GtkWidget *
1104 empathy_main_window_get (void)
1105 {
1106   return window != NULL ? window->window : NULL;
1107 }
1108
1109 GtkWidget *
1110 empathy_main_window_show (void)
1111 {
1112         EmpathyContactList       *list_iface;
1113         EmpathyContactMonitor    *monitor;
1114         GtkBuilder               *gui;
1115         EmpathyConf              *conf;
1116         GtkWidget                *sw;
1117         GtkToggleAction          *show_offline_widget;
1118         GtkWidget                *ebox;
1119         GtkAction                *show_map_widget;
1120         GtkToolItem              *item;
1121         gboolean                  show_offline;
1122         gboolean                  show_avatars;
1123         gboolean                  compact_contact_list;
1124         gint                      x, y, w, h;
1125         gchar                    *filename;
1126         GSList                   *l;
1127
1128         if (window) {
1129                 empathy_window_present (GTK_WINDOW (window->window), TRUE);
1130                 return window->window;
1131         }
1132
1133         window = g_new0 (EmpathyMainWindow, 1);
1134
1135         /* Set up interface */
1136         filename = empathy_file_lookup ("empathy-main-window.ui", "src");
1137         gui = empathy_builder_get_file (filename,
1138                                        "main_window", &window->window,
1139                                        "main_vbox", &window->main_vbox,
1140                                        "errors_vbox", &window->errors_vbox,
1141                                        "ui_manager", &window->ui_manager,
1142                                        "view_show_offline", &show_offline_widget,
1143                                        "view_history", &window->view_history,
1144                                        "view_show_map", &show_map_widget,
1145                                        "room_join_favorites", &window->room_join_favorites,
1146                                        "presence_toolbar", &window->presence_toolbar,
1147                                        "roster_scrolledwindow", &sw,
1148                                        NULL);
1149         g_free (filename);
1150
1151         empathy_builder_connect (gui, window,
1152                               "main_window", "destroy", main_window_destroy_cb,
1153                               "main_window", "configure_event", main_window_configure_event_cb,
1154                               "chat_quit", "activate", main_window_chat_quit_cb,
1155                               "chat_new_message", "activate", main_window_chat_new_message_cb,
1156                               "view_history", "activate", main_window_view_history_cb,
1157                               "room_join_new", "activate", main_window_room_join_new_cb,
1158                               "room_join_favorites", "activate", main_window_room_join_favorites_cb,
1159                               "room_manage_favorites", "activate", main_window_room_manage_favorites_cb,
1160                               "chat_add_contact", "activate", main_window_chat_add_contact_cb,
1161                               "view_show_ft_manager", "activate", main_window_view_show_ft_manager,
1162                               "view_show_offline", "toggled", main_window_view_show_offline_cb,
1163                               "view_show_map", "activate", main_window_view_show_map_cb,
1164                               "edit", "activate", main_window_edit_cb,
1165                               "edit_accounts", "activate", main_window_edit_accounts_cb,
1166                               "edit_personal_information", "activate", main_window_edit_personal_information_cb,
1167                               "edit_preferences", "activate", main_window_edit_preferences_cb,
1168                               "help_about", "activate", main_window_help_about_cb,
1169                               "help_debug", "activate", main_window_help_debug_cb,
1170                               "help_contents", "activate", main_window_help_contents_cb,
1171                               NULL);
1172
1173         /* Set up connection related widgets. */
1174         main_window_connection_items_setup (window, gui);
1175
1176         g_object_ref (window->ui_manager);
1177         g_object_unref (gui);
1178
1179 #if !HAVE_LIBCHAMPLAIN
1180         gtk_action_set_visible (show_map_widget, FALSE);
1181 #endif
1182
1183         window->mc = empathy_mission_control_dup_singleton ();
1184         window->account_manager = empathy_account_manager_dup_singleton ();
1185
1186         g_signal_connect (window->account_manager,
1187                           "account-connection-changed",
1188                           G_CALLBACK (main_window_connection_changed_cb), window);
1189
1190         window->errors = g_hash_table_new_full (empathy_account_hash,
1191                                                 empathy_account_equal,
1192                                                 g_object_unref,
1193                                                 NULL);
1194
1195         /* Set up menu */
1196         main_window_favorite_chatroom_menu_setup (window);
1197
1198         window->edit_context = gtk_ui_manager_get_widget (window->ui_manager,
1199                 "/menubar/edit/edit_context");
1200         window->edit_context_separator = gtk_ui_manager_get_widget (window->ui_manager,
1201                 "/menubar/edit/edit_context_separator");
1202         gtk_widget_hide (window->edit_context);
1203         gtk_widget_hide (window->edit_context_separator);
1204
1205         /* Set up contact list. */
1206         empathy_status_presets_get_all ();
1207
1208         /* Set up presence chooser */
1209         window->presence_chooser = empathy_presence_chooser_new ();
1210         gtk_widget_show (window->presence_chooser);
1211         item = gtk_tool_item_new ();
1212         gtk_widget_show (GTK_WIDGET (item));
1213         gtk_container_add (GTK_CONTAINER (item), window->presence_chooser);
1214         gtk_tool_item_set_is_important (item, TRUE);
1215         gtk_tool_item_set_expand (item, TRUE);
1216         gtk_toolbar_insert (GTK_TOOLBAR (window->presence_toolbar), item, -1);
1217
1218         /* Set up the throbber */
1219         ebox = gtk_event_box_new ();
1220         gtk_event_box_set_visible_window (GTK_EVENT_BOX (ebox), FALSE);
1221         gtk_widget_set_tooltip_text (ebox, _("Show and edit accounts"));
1222         g_signal_connect (ebox,
1223                           "button-press-event",
1224                           G_CALLBACK (main_window_throbber_button_press_event_cb),
1225                           window);
1226         gtk_widget_show (ebox);
1227
1228         window->throbber = ephy_spinner_new ();
1229         ephy_spinner_set_size (EPHY_SPINNER (window->throbber), GTK_ICON_SIZE_LARGE_TOOLBAR);
1230         gtk_container_add (GTK_CONTAINER (ebox), window->throbber);
1231         gtk_widget_show (window->throbber);
1232
1233         item = gtk_tool_item_new ();
1234         gtk_container_add (GTK_CONTAINER (item), ebox);
1235         gtk_toolbar_insert (GTK_TOOLBAR (window->presence_toolbar), item, -1);
1236         gtk_widget_show (GTK_WIDGET (item));
1237
1238         list_iface = EMPATHY_CONTACT_LIST (empathy_contact_manager_dup_singleton ());
1239         monitor = empathy_contact_list_get_monitor (list_iface);
1240         window->list_store = empathy_contact_list_store_new (list_iface);
1241         window->list_view = empathy_contact_list_view_new (window->list_store,
1242                                                            EMPATHY_CONTACT_LIST_FEATURE_ALL,
1243                                                            EMPATHY_CONTACT_FEATURE_ALL);
1244         g_signal_connect (monitor, "contact-presence-changed",
1245                           G_CALLBACK (main_window_contact_presence_changed_cb), window);
1246         g_object_unref (list_iface);
1247
1248         gtk_widget_show (GTK_WIDGET (window->list_view));
1249         gtk_container_add (GTK_CONTAINER (sw),
1250                            GTK_WIDGET (window->list_view));
1251         g_signal_connect (window->list_view, "row-activated",
1252                           G_CALLBACK (main_window_row_activated_cb),
1253                           window);
1254
1255         /* Load user-defined accelerators. */
1256         main_window_accels_load ();
1257
1258         /* Set window size. */
1259         empathy_geometry_load (GEOMETRY_NAME, &x, &y, &w, &h);
1260
1261         if (w >= 1 && h >= 1) {
1262                 /* Use the defaults from the ui file if we
1263                  * don't have good w, h geometry.
1264                  */
1265                 DEBUG ("Configuring window default size w:%d, h:%d", w, h);
1266                 gtk_window_set_default_size (GTK_WINDOW (window->window), w, h);
1267         }
1268
1269         if (x >= 0 && y >= 0) {
1270                 /* Let the window manager position it if we
1271                  * don't have good x, y coordinates.
1272                  */
1273                 DEBUG ("Configuring window default position x:%d, y:%d", x, y);
1274                 gtk_window_move (GTK_WINDOW (window->window), x, y);
1275         }
1276
1277         /* Enable event handling */
1278         window->event_manager = empathy_event_manager_dup_singleton ();
1279         g_signal_connect (window->event_manager, "event-added",
1280                           G_CALLBACK (main_window_event_added_cb),
1281                           window);
1282         g_signal_connect (window->event_manager, "event-removed",
1283                           G_CALLBACK (main_window_event_removed_cb),
1284                           window);
1285
1286         g_signal_connect (window->account_manager, "account-created",
1287                           G_CALLBACK (main_window_account_created_or_deleted_cb),
1288                           window);
1289         g_signal_connect (window->account_manager, "account-deleted",
1290                           G_CALLBACK (main_window_account_created_or_deleted_cb),
1291                           window);
1292         main_window_account_created_or_deleted_cb (window->account_manager, NULL, window);
1293
1294         l = empathy_event_manager_get_events (window->event_manager);
1295         while (l) {
1296                 main_window_event_added_cb (window->event_manager,
1297                                             l->data, window);
1298                 l = l->next;
1299         }
1300
1301         conf = empathy_conf_get ();
1302
1303         /* Show offline ? */
1304         empathy_conf_get_bool (conf,
1305                               EMPATHY_PREFS_CONTACTS_SHOW_OFFLINE,
1306                               &show_offline);
1307         empathy_conf_notify_add (conf,
1308                                 EMPATHY_PREFS_CONTACTS_SHOW_OFFLINE,
1309                                 main_window_notify_show_offline_cb,
1310                                 show_offline_widget);
1311
1312         gtk_toggle_action_set_active (show_offline_widget, show_offline);
1313
1314         /* Show avatars ? */
1315         empathy_conf_get_bool (conf,
1316                               EMPATHY_PREFS_UI_SHOW_AVATARS,
1317                               &show_avatars);
1318         empathy_conf_notify_add (conf,
1319                                 EMPATHY_PREFS_UI_SHOW_AVATARS,
1320                                 (EmpathyConfNotifyFunc) main_window_notify_show_avatars_cb,
1321                                 window);
1322         empathy_contact_list_store_set_show_avatars (window->list_store, show_avatars);
1323
1324         /* Is compact ? */
1325         empathy_conf_get_bool (conf,
1326                               EMPATHY_PREFS_UI_COMPACT_CONTACT_LIST,
1327                               &compact_contact_list);
1328         empathy_conf_notify_add (conf,
1329                                 EMPATHY_PREFS_UI_COMPACT_CONTACT_LIST,
1330                                 (EmpathyConfNotifyFunc) main_window_notify_compact_contact_list_cb,
1331                                 window);
1332         empathy_contact_list_store_set_is_compact (window->list_store, compact_contact_list);
1333
1334         /* Sort criterium */
1335         empathy_conf_notify_add (conf,
1336                                 EMPATHY_PREFS_CONTACTS_SORT_CRITERIUM,
1337                                 (EmpathyConfNotifyFunc) main_window_notify_sort_criterium_cb,
1338                                 window);
1339         main_window_notify_sort_criterium_cb (conf,
1340                                               EMPATHY_PREFS_CONTACTS_SORT_CRITERIUM,
1341                                               window);
1342
1343         main_window_update_status (window, window->account_manager);
1344
1345         return window->window;
1346 }
1347