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