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