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