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