]> git.0d.be Git - empathy.git/blob - src/empathy-main-window.c
Use its own ListStore of contacts instead of borrowing the Contact
[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                                          McPresence current,
567                                          McPresence 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 (previous < MC_PRESENCE_AVAILABLE && current > MC_PRESENCE_OFFLINE) {
581                 /* someone is logging in */
582                 empathy_sound_play (GTK_WIDGET (window->window),
583                                     EMPATHY_SOUND_CONTACT_CONNECTED);
584                 return;
585         }
586
587         if (previous > MC_PRESENCE_OFFLINE && current < MC_PRESENCE_AVAILABLE) {
588                 /* someone is logging off */
589                 empathy_sound_play (GTK_WIDGET (window->window),
590                                     EMPATHY_SOUND_CONTACT_DISCONNECTED);
591         }
592 }
593
594 static void
595 main_window_accels_load (void)
596 {
597         gchar *filename;
598
599         filename = g_build_filename (g_get_home_dir (), ".gnome2", PACKAGE_NAME, ACCELS_FILENAME, NULL);
600         if (g_file_test (filename, G_FILE_TEST_EXISTS)) {
601                 DEBUG ("Loading from:'%s'", filename);
602                 gtk_accel_map_load (filename);
603         }
604
605         g_free (filename);
606 }
607
608 static void
609 main_window_accels_save (void)
610 {
611         gchar *dir;
612         gchar *file_with_path;
613
614         dir = g_build_filename (g_get_home_dir (), ".gnome2", PACKAGE_NAME, NULL);
615         g_mkdir_with_parents (dir, S_IRUSR | S_IWUSR | S_IXUSR);
616         file_with_path = g_build_filename (dir, ACCELS_FILENAME, NULL);
617         g_free (dir);
618
619         DEBUG ("Saving to:'%s'", file_with_path);
620         gtk_accel_map_save (file_with_path);
621
622         g_free (file_with_path);
623 }
624
625 static void
626 main_window_destroy_cb (GtkWidget         *widget,
627                         EmpathyMainWindow *window)
628 {
629         /* Save user-defined accelerators. */
630         main_window_accels_save ();
631
632         g_signal_handlers_disconnect_by_func (window->account_manager,
633                                               main_window_connection_changed_cb,
634                                               window);
635
636         if (window->size_timeout_id) {
637                 g_source_remove (window->size_timeout_id);
638         }
639
640         g_list_free (window->actions_connected);
641
642         g_object_unref (window->mc);
643         g_object_unref (window->account_manager);
644         g_object_unref (window->list_store);
645         g_hash_table_destroy (window->errors);
646
647         g_signal_handlers_disconnect_by_func (window->event_manager,
648                                               main_window_event_added_cb,
649                                               window);
650         g_signal_handlers_disconnect_by_func (window->event_manager,
651                                               main_window_event_removed_cb,
652                                               window);
653         g_object_unref (window->event_manager);
654         g_object_unref (window->ui_manager);
655
656         g_free (window);
657 }
658
659 static void
660 main_window_chat_quit_cb (GtkAction         *action,
661                           EmpathyMainWindow *window)
662 {
663         gtk_main_quit ();
664 }
665
666 static void
667 main_window_view_history_cb (GtkAction         *action,
668                              EmpathyMainWindow *window)
669 {
670         empathy_log_window_show (NULL, NULL, FALSE, GTK_WINDOW (window->window));
671 }
672
673 static void
674 main_window_chat_new_message_cb (GtkAction         *action,
675                                  EmpathyMainWindow *window)
676 {
677         empathy_new_message_dialog_show (GTK_WINDOW (window->window));
678 }
679
680 static void
681 main_window_chat_add_contact_cb (GtkAction         *action,
682                                  EmpathyMainWindow *window)
683 {
684         empathy_new_contact_dialog_show (GTK_WINDOW (window->window));
685 }
686
687 static void
688 main_window_view_show_ft_manager (GtkAction         *action,
689                                   EmpathyMainWindow *window)
690 {
691         EmpathyFTManager *manager;
692         GtkWidget *dialog;
693
694         manager = empathy_ft_manager_dup_singleton ();
695         dialog = empathy_ft_manager_get_dialog (manager);
696
697         gtk_window_present (GTK_WINDOW (dialog));
698         g_object_unref (manager);
699 }
700
701 static void
702 main_window_view_show_offline_cb (GtkToggleAction   *action,
703                                   EmpathyMainWindow *window)
704 {
705         gboolean current;
706
707         current = gtk_toggle_action_get_active (action);
708         empathy_conf_set_bool (empathy_conf_get (),
709                               EMPATHY_PREFS_CONTACTS_SHOW_OFFLINE,
710                               current);
711
712         /* Turn off sound just while we alter the contact list. */
713         // FIXME: empathy_sound_set_enabled (FALSE);
714         empathy_contact_list_store_set_show_offline (window->list_store, current);
715         //empathy_sound_set_enabled (TRUE);
716 }
717
718 #if HAVE_LIBCHAMPLAIN
719 static void
720 main_window_view_show_map_cb (GtkCheckMenuItem  *item,
721                               EmpathyMainWindow *window)
722 {
723         empathy_map_view_show ();
724 }
725 #endif
726
727 static void
728 main_window_favorite_chatroom_join (EmpathyChatroom *chatroom)
729 {
730         EmpathyAccountManager *manager;
731         McAccount      *account;
732         TpConnection   *connection;
733         const gchar    *room;
734
735         manager = empathy_account_manager_dup_singleton ();
736         account = empathy_chatroom_get_account (chatroom);
737         connection = empathy_account_manager_get_connection (manager, account);
738         room = empathy_chatroom_get_room (chatroom);
739         g_object_unref (manager);
740
741         if (connection != NULL) {
742                 DEBUG ("Requesting channel for '%s'", room);
743                 empathy_dispatcher_join_muc (connection, room, NULL, NULL);
744         }
745 }
746
747 static void
748 main_window_favorite_chatroom_menu_activate_cb (GtkMenuItem    *menu_item,
749                                                 EmpathyChatroom *chatroom)
750 {
751         main_window_favorite_chatroom_join (chatroom);
752 }
753
754 static void
755 main_window_favorite_chatroom_menu_add (EmpathyMainWindow *window,
756                                         EmpathyChatroom    *chatroom)
757 {
758         GtkWidget   *menu_item;
759         const gchar *name;
760
761         if (g_object_get_data (G_OBJECT (chatroom), "menu_item")) {
762                 return;
763         }
764
765         name = empathy_chatroom_get_name (chatroom);
766         menu_item = gtk_menu_item_new_with_label (name);
767
768         g_object_set_data (G_OBJECT (chatroom), "menu_item", menu_item);
769         g_signal_connect (menu_item, "activate",
770                           G_CALLBACK (main_window_favorite_chatroom_menu_activate_cb),
771                           chatroom);
772
773         gtk_menu_shell_insert (GTK_MENU_SHELL (window->room_menu),
774                                menu_item, 4);
775
776         gtk_widget_show (menu_item);
777 }
778
779 static void
780 main_window_favorite_chatroom_menu_added_cb (EmpathyChatroomManager *manager,
781                                              EmpathyChatroom        *chatroom,
782                                              EmpathyMainWindow     *window)
783 {
784         main_window_favorite_chatroom_menu_add (window, chatroom);
785         gtk_widget_show (window->room_separator);
786         gtk_action_set_sensitive (window->room_join_favorites, TRUE);
787 }
788
789 static void
790 main_window_favorite_chatroom_menu_removed_cb (EmpathyChatroomManager *manager,
791                                                EmpathyChatroom        *chatroom,
792                                                EmpathyMainWindow     *window)
793 {
794         GtkWidget *menu_item;
795         GList *chatrooms;
796
797         menu_item = g_object_get_data (G_OBJECT (chatroom), "menu_item");
798         g_object_set_data (G_OBJECT (chatroom), "menu_item", NULL);
799         gtk_widget_destroy (menu_item);
800
801         chatrooms = empathy_chatroom_manager_get_chatrooms (window->chatroom_manager, NULL);
802         if (chatrooms) {
803                 gtk_widget_show (window->room_separator);
804         } else {
805                 gtk_widget_hide (window->room_separator);
806         }
807
808         gtk_action_set_sensitive (window->room_join_favorites, chatrooms != NULL);
809         g_list_free (chatrooms);
810 }
811
812 static void
813 main_window_favorite_chatroom_menu_setup (EmpathyMainWindow *window)
814 {
815         GList *chatrooms, *l;
816         GtkWidget *room;
817
818         window->chatroom_manager = empathy_chatroom_manager_dup_singleton (NULL);
819         chatrooms = empathy_chatroom_manager_get_chatrooms (window->chatroom_manager, NULL);
820         room = gtk_ui_manager_get_widget (window->ui_manager,
821                 "/menubar/room");
822         window->room_menu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (room));
823         window->room_separator = gtk_ui_manager_get_widget (window->ui_manager,
824                 "/menubar/room/room_separator");
825
826         for (l = chatrooms; l; l = l->next) {
827                 main_window_favorite_chatroom_menu_add (window, l->data);
828         }
829
830         if (!chatrooms) {
831                 gtk_widget_hide (window->room_separator);
832         }
833
834         gtk_action_set_sensitive (window->room_join_favorites, chatrooms != NULL);
835
836         g_signal_connect (window->chatroom_manager, "chatroom-added",
837                           G_CALLBACK (main_window_favorite_chatroom_menu_added_cb),
838                           window);
839         g_signal_connect (window->chatroom_manager, "chatroom-removed",
840                           G_CALLBACK (main_window_favorite_chatroom_menu_removed_cb),
841                           window);
842
843         g_list_free (chatrooms);
844 }
845
846 static void
847 main_window_room_join_new_cb (GtkAction         *action,
848                               EmpathyMainWindow *window)
849 {
850         empathy_new_chatroom_dialog_show (GTK_WINDOW (window->window));
851 }
852
853 static void
854 main_window_room_join_favorites_cb (GtkAction         *action,
855                                     EmpathyMainWindow *window)
856 {
857         GList *chatrooms, *l;
858
859         chatrooms = empathy_chatroom_manager_get_chatrooms (window->chatroom_manager, NULL);
860         for (l = chatrooms; l; l = l->next) {
861                 main_window_favorite_chatroom_join (l->data);
862         }
863         g_list_free (chatrooms);
864 }
865
866 static void
867 main_window_room_manage_favorites_cb (GtkAction         *action,
868                                       EmpathyMainWindow *window)
869 {
870         empathy_chatrooms_window_show (GTK_WINDOW (window->window));
871 }
872
873 static void
874 main_window_edit_cb (GtkAction *action,
875                      EmpathyMainWindow *window)
876 {
877         GtkWidget *submenu;
878
879         /* FIXME: It should use the UIManager to merge the contact/group submenu */
880         submenu = empathy_contact_list_view_get_contact_menu (window->list_view);
881         if (submenu) {
882                 GtkMenuItem *item;
883                 GtkWidget   *label;
884
885                 item = GTK_MENU_ITEM (window->edit_context);
886                 label = gtk_bin_get_child (GTK_BIN (item));
887                 gtk_label_set_text (GTK_LABEL (label), _("Contact"));
888
889                 gtk_widget_show (window->edit_context);
890                 gtk_widget_show (window->edit_context_separator);
891
892                 gtk_menu_item_set_submenu (item, submenu);
893
894                 return;
895         }
896
897         submenu = empathy_contact_list_view_get_group_menu (window->list_view);
898         if (submenu) {
899                 GtkMenuItem *item;
900                 GtkWidget   *label;
901
902                 item = GTK_MENU_ITEM (window->edit_context);
903                 label = gtk_bin_get_child (GTK_BIN (item));
904                 gtk_label_set_text (GTK_LABEL (label), _("Group"));
905
906                 gtk_widget_show (window->edit_context);
907                 gtk_widget_show (window->edit_context_separator);
908
909                 gtk_menu_item_set_submenu (item, submenu);
910
911                 return;
912         }
913
914         gtk_widget_hide (window->edit_context);
915         gtk_widget_hide (window->edit_context_separator);
916
917         return;
918 }
919
920 static void
921 main_window_edit_accounts_cb (GtkAction         *action,
922                               EmpathyMainWindow *window)
923 {
924         empathy_accounts_dialog_show (GTK_WINDOW (window->window), NULL);
925 }
926
927 static void
928 main_window_edit_personal_information_cb (GtkAction         *action,
929                                           EmpathyMainWindow *window)
930 {
931         empathy_contact_personal_dialog_show (GTK_WINDOW (window->window));
932 }
933
934 static void
935 main_window_edit_preferences_cb (GtkAction         *action,
936                                  EmpathyMainWindow *window)
937 {
938         empathy_preferences_show (GTK_WINDOW (window->window));
939 }
940
941 static void
942 main_window_help_about_cb (GtkAction         *action,
943                            EmpathyMainWindow *window)
944 {
945         empathy_about_dialog_new (GTK_WINDOW (window->window));
946 }
947
948 static void
949 main_window_help_contents_cb (GtkAction         *action,
950                               EmpathyMainWindow *window)
951 {
952         empathy_url_show (window->window, "ghelp:empathy");
953 }
954
955 static gboolean
956 main_window_throbber_button_press_event_cb (GtkWidget         *throbber_ebox,
957                                             GdkEventButton    *event,
958                                             EmpathyMainWindow *window)
959 {
960         if (event->type != GDK_BUTTON_PRESS ||
961             event->button != 1) {
962                 return FALSE;
963         }
964
965         empathy_accounts_dialog_show (GTK_WINDOW (window->window), NULL);
966
967         return FALSE;
968 }
969
970 static gboolean
971 main_window_configure_event_timeout_cb (EmpathyMainWindow *window)
972 {
973         gint x, y, w, h;
974
975         gtk_window_get_size (GTK_WINDOW (window->window), &w, &h);
976         gtk_window_get_position (GTK_WINDOW (window->window), &x, &y);
977
978         empathy_geometry_save (GEOMETRY_NAME, x, y, w, h);
979
980         window->size_timeout_id = 0;
981
982         return FALSE;
983 }
984
985 static gboolean
986 main_window_configure_event_cb (GtkWidget         *widget,
987                                 GdkEventConfigure *event,
988                                 EmpathyMainWindow *window)
989 {
990         if (window->size_timeout_id) {
991                 g_source_remove (window->size_timeout_id);
992         }
993
994         window->size_timeout_id = g_timeout_add_seconds (1,
995                                                          (GSourceFunc) main_window_configure_event_timeout_cb,
996                                                          window);
997
998         return FALSE;
999 }
1000
1001 static void
1002 main_window_account_created_or_deleted_cb (EmpathyAccountManager  *manager,
1003                                            McAccount              *account,
1004                                            EmpathyMainWindow      *window)
1005 {
1006         gtk_action_set_sensitive (window->view_history,
1007                 empathy_account_manager_get_count (manager) > 0);
1008 }
1009
1010 static void
1011 main_window_notify_show_offline_cb (EmpathyConf *conf,
1012                                     const gchar *key,
1013                                     gpointer     toggle_action)
1014 {
1015         gboolean show_offline;
1016
1017         if (empathy_conf_get_bool (conf, key, &show_offline)) {
1018                 gtk_toggle_action_set_active (toggle_action, show_offline);
1019         }
1020 }
1021
1022 static void
1023 main_window_notify_show_avatars_cb (EmpathyConf        *conf,
1024                                     const gchar       *key,
1025                                     EmpathyMainWindow *window)
1026 {
1027         gboolean show_avatars;
1028
1029         if (empathy_conf_get_bool (conf, key, &show_avatars)) {
1030                 empathy_contact_list_store_set_show_avatars (window->list_store,
1031                                                             show_avatars);
1032         }
1033 }
1034
1035 static void
1036 main_window_notify_compact_contact_list_cb (EmpathyConf        *conf,
1037                                             const gchar       *key,
1038                                             EmpathyMainWindow *window)
1039 {
1040         gboolean compact_contact_list;
1041
1042         if (empathy_conf_get_bool (conf, key, &compact_contact_list)) {
1043                 empathy_contact_list_store_set_is_compact (window->list_store,
1044                                                           compact_contact_list);
1045         }
1046 }
1047
1048 static void
1049 main_window_notify_sort_criterium_cb (EmpathyConf       *conf,
1050                                       const gchar       *key,
1051                                       EmpathyMainWindow *window)
1052 {
1053         gchar *str = NULL;
1054
1055         if (empathy_conf_get_string (conf, key, &str) && str) {
1056                 GType       type;
1057                 GEnumClass *enum_class;
1058                 GEnumValue *enum_value;
1059
1060                 type = empathy_contact_list_store_sort_get_type ();
1061                 enum_class = G_ENUM_CLASS (g_type_class_peek (type));
1062                 enum_value = g_enum_get_value_by_nick (enum_class, str);
1063                 g_free (str);
1064
1065                 if (enum_value) {
1066                         empathy_contact_list_store_set_sort_criterium (window->list_store,
1067                                                                        enum_value->value);
1068                 }
1069         }
1070 }
1071
1072 static void
1073 main_window_connection_items_setup (EmpathyMainWindow *window,
1074                                     GtkBuilder        *gui)
1075 {
1076         GList         *list;
1077         GObject       *action;
1078         gint           i;
1079         const gchar *actions_connected[] = {
1080                 "room",
1081                 "chat_new_message",
1082                 "chat_add_contact",
1083                 "edit_personal_information"
1084         };
1085
1086         for (i = 0, list = NULL; i < G_N_ELEMENTS (actions_connected); i++) {
1087                 action = gtk_builder_get_object (gui, actions_connected[i]);
1088                 list = g_list_prepend (list, action);
1089         }
1090
1091         window->actions_connected = list;
1092 }
1093
1094 GtkWidget *
1095 empathy_main_window_get (void)
1096 {
1097   return window != NULL ? window->window : NULL;
1098 }
1099
1100 GtkWidget *
1101 empathy_main_window_show (void)
1102 {
1103         EmpathyContactList       *list_iface;
1104         EmpathyContactMonitor    *monitor;
1105         GtkBuilder               *gui;
1106         EmpathyConf              *conf;
1107         GtkWidget                *sw;
1108         GtkToggleAction          *show_offline_widget;
1109         GtkWidget                *ebox;
1110         GtkWidget                *show_map_widget;
1111         GtkToolItem              *item;
1112         gboolean                  show_offline;
1113         gboolean                  show_avatars;
1114         gboolean                  compact_contact_list;
1115         gint                      x, y, w, h;
1116         gchar                    *filename;
1117         GSList                   *l;
1118
1119         if (window) {
1120                 empathy_window_present (GTK_WINDOW (window->window), TRUE);
1121                 return window->window;
1122         }
1123
1124         window = g_new0 (EmpathyMainWindow, 1);
1125
1126         /* Set up interface */
1127         filename = empathy_file_lookup ("empathy-main-window.ui", "src");
1128         gui = empathy_builder_get_file (filename,
1129                                        "main_window", &window->window,
1130                                        "main_vbox", &window->main_vbox,
1131                                        "errors_vbox", &window->errors_vbox,
1132                                        "ui_manager", &window->ui_manager,
1133                                        "view_show_offline", &show_offline_widget,
1134                                        "view_history", &window->view_history,
1135                                        "view_show_map", &show_map_widget,
1136                                        "room_join_favorites", &window->room_join_favorites,
1137                                        "presence_toolbar", &window->presence_toolbar,
1138                                        "roster_scrolledwindow", &sw,
1139                                        NULL);
1140         g_free (filename);
1141
1142         empathy_builder_connect (gui, window,
1143                               "main_window", "destroy", main_window_destroy_cb,
1144                               "main_window", "configure_event", main_window_configure_event_cb,
1145                               "chat_quit", "activate", main_window_chat_quit_cb,
1146                               "chat_new_message", "activate", main_window_chat_new_message_cb,
1147                               "view_history", "activate", main_window_view_history_cb,
1148                               "room_join_new", "activate", main_window_room_join_new_cb,
1149                               "room_join_favorites", "activate", main_window_room_join_favorites_cb,
1150                               "room_manage_favorites", "activate", main_window_room_manage_favorites_cb,
1151                               "chat_add_contact", "activate", main_window_chat_add_contact_cb,
1152                               "view_show_ft_manager", "activate", main_window_view_show_ft_manager,
1153                               "view_show_offline", "toggled", main_window_view_show_offline_cb,
1154 #if HAVE_LIBCHAMPLAIN
1155                               "view_show_map", "activate", main_window_view_show_map_cb,
1156 #endif
1157                               "edit", "activate", main_window_edit_cb,
1158                               "edit_accounts", "activate", main_window_edit_accounts_cb,
1159                               "edit_personal_information", "activate", main_window_edit_personal_information_cb,
1160                               "edit_preferences", "activate", main_window_edit_preferences_cb,
1161                               "help_about", "activate", main_window_help_about_cb,
1162                               "help_contents", "activate", main_window_help_contents_cb,
1163                               NULL);
1164
1165         /* Set up connection related widgets. */
1166         main_window_connection_items_setup (window, gui);
1167
1168         g_object_ref (window->ui_manager);
1169         g_object_unref (gui);
1170
1171 #if !HAVE_LIBCHAMPLAIN
1172         gtk_widget_hide (show_map_widget);
1173 #endif
1174
1175         window->mc = empathy_mission_control_dup_singleton ();
1176         window->account_manager = empathy_account_manager_dup_singleton ();
1177
1178         g_signal_connect (window->account_manager,
1179                           "account-connection-changed",
1180                           G_CALLBACK (main_window_connection_changed_cb), window);
1181
1182         window->errors = g_hash_table_new_full (empathy_account_hash,
1183                                                 empathy_account_equal,
1184                                                 g_object_unref,
1185                                                 NULL);
1186
1187         /* Set up menu */
1188         main_window_favorite_chatroom_menu_setup (window);
1189
1190         window->edit_context = gtk_ui_manager_get_widget (window->ui_manager,
1191                 "/menubar/edit/edit_context");
1192         window->edit_context_separator = gtk_ui_manager_get_widget (window->ui_manager,
1193                 "/menubar/edit/edit_context_separator");
1194         gtk_widget_hide (window->edit_context);
1195         gtk_widget_hide (window->edit_context_separator);
1196
1197         /* Set up contact list. */
1198         empathy_status_presets_get_all ();
1199
1200         /* Set up presence chooser */
1201         window->presence_chooser = empathy_presence_chooser_new ();
1202         gtk_widget_show (window->presence_chooser);
1203         item = gtk_tool_item_new ();
1204         gtk_widget_show (GTK_WIDGET (item));
1205         gtk_container_add (GTK_CONTAINER (item), window->presence_chooser);
1206         gtk_tool_item_set_is_important (item, TRUE);
1207         gtk_tool_item_set_expand (item, TRUE);
1208         gtk_toolbar_insert (GTK_TOOLBAR (window->presence_toolbar), item, -1);
1209
1210         /* Set up the throbber */
1211         ebox = gtk_event_box_new ();
1212         gtk_event_box_set_visible_window (GTK_EVENT_BOX (ebox), FALSE);
1213         gtk_widget_set_tooltip_text (ebox, _("Show and edit accounts"));
1214         g_signal_connect (ebox,
1215                           "button-press-event",
1216                           G_CALLBACK (main_window_throbber_button_press_event_cb),
1217                           window);
1218         gtk_widget_show (ebox);
1219
1220         window->throbber = ephy_spinner_new ();
1221         ephy_spinner_set_size (EPHY_SPINNER (window->throbber), GTK_ICON_SIZE_LARGE_TOOLBAR);
1222         gtk_container_add (GTK_CONTAINER (ebox), window->throbber);
1223         gtk_widget_show (window->throbber);
1224
1225         item = gtk_tool_item_new ();
1226         gtk_container_add (GTK_CONTAINER (item), ebox);
1227         gtk_toolbar_insert (GTK_TOOLBAR (window->presence_toolbar), item, -1);
1228         gtk_widget_show (GTK_WIDGET (item));
1229
1230         list_iface = EMPATHY_CONTACT_LIST (empathy_contact_manager_dup_singleton ());
1231         monitor = empathy_contact_list_get_monitor (list_iface);
1232         window->list_store = empathy_contact_list_store_new (list_iface);
1233         window->list_view = empathy_contact_list_view_new (window->list_store,
1234                                                            EMPATHY_CONTACT_LIST_FEATURE_ALL,
1235                                                            EMPATHY_CONTACT_FEATURE_ALL);
1236         g_signal_connect (monitor, "contact-presence-changed",
1237                           G_CALLBACK (main_window_contact_presence_changed_cb), window);
1238         g_object_unref (list_iface);
1239
1240         gtk_widget_show (GTK_WIDGET (window->list_view));
1241         gtk_container_add (GTK_CONTAINER (sw),
1242                            GTK_WIDGET (window->list_view));
1243         g_signal_connect (window->list_view, "row-activated",
1244                           G_CALLBACK (main_window_row_activated_cb),
1245                           window);
1246
1247         /* Load user-defined accelerators. */
1248         main_window_accels_load ();
1249
1250         /* Set window size. */
1251         empathy_geometry_load (GEOMETRY_NAME, &x, &y, &w, &h);
1252
1253         if (w >= 1 && h >= 1) {
1254                 /* Use the defaults from the ui file if we
1255                  * don't have good w, h geometry.
1256                  */
1257                 DEBUG ("Configuring window default size w:%d, h:%d", w, h);
1258                 gtk_window_set_default_size (GTK_WINDOW (window->window), w, h);
1259         }
1260
1261         if (x >= 0 && y >= 0) {
1262                 /* Let the window manager position it if we
1263                  * don't have good x, y coordinates.
1264                  */
1265                 DEBUG ("Configuring window default position x:%d, y:%d", x, y);
1266                 gtk_window_move (GTK_WINDOW (window->window), x, y);
1267         }
1268
1269         /* Enable event handling */
1270         window->event_manager = empathy_event_manager_dup_singleton ();
1271         g_signal_connect (window->event_manager, "event-added",
1272                           G_CALLBACK (main_window_event_added_cb),
1273                           window);
1274         g_signal_connect (window->event_manager, "event-removed",
1275                           G_CALLBACK (main_window_event_removed_cb),
1276                           window);
1277
1278         g_signal_connect (window->account_manager, "account-created",
1279                           G_CALLBACK (main_window_account_created_or_deleted_cb),
1280                           window);
1281         g_signal_connect (window->account_manager, "account-deleted",
1282                           G_CALLBACK (main_window_account_created_or_deleted_cb),
1283                           window);
1284         main_window_account_created_or_deleted_cb (window->account_manager, NULL, window);
1285
1286         l = empathy_event_manager_get_events (window->event_manager);
1287         while (l) {
1288                 main_window_event_added_cb (window->event_manager,
1289                                             l->data, window);
1290                 l = l->next;
1291         }
1292
1293         conf = empathy_conf_get ();
1294
1295         /* Show offline ? */
1296         empathy_conf_get_bool (conf,
1297                               EMPATHY_PREFS_CONTACTS_SHOW_OFFLINE,
1298                               &show_offline);
1299         empathy_conf_notify_add (conf,
1300                                 EMPATHY_PREFS_CONTACTS_SHOW_OFFLINE,
1301                                 main_window_notify_show_offline_cb,
1302                                 show_offline_widget);
1303
1304         gtk_toggle_action_set_active (show_offline_widget, show_offline);
1305
1306         /* Show avatars ? */
1307         empathy_conf_get_bool (conf,
1308                               EMPATHY_PREFS_UI_SHOW_AVATARS,
1309                               &show_avatars);
1310         empathy_conf_notify_add (conf,
1311                                 EMPATHY_PREFS_UI_SHOW_AVATARS,
1312                                 (EmpathyConfNotifyFunc) main_window_notify_show_avatars_cb,
1313                                 window);
1314         empathy_contact_list_store_set_show_avatars (window->list_store, show_avatars);
1315
1316         /* Is compact ? */
1317         empathy_conf_get_bool (conf,
1318                               EMPATHY_PREFS_UI_COMPACT_CONTACT_LIST,
1319                               &compact_contact_list);
1320         empathy_conf_notify_add (conf,
1321                                 EMPATHY_PREFS_UI_COMPACT_CONTACT_LIST,
1322                                 (EmpathyConfNotifyFunc) main_window_notify_compact_contact_list_cb,
1323                                 window);
1324         empathy_contact_list_store_set_is_compact (window->list_store, compact_contact_list);
1325
1326         /* Sort criterium */
1327         empathy_conf_notify_add (conf,
1328                                 EMPATHY_PREFS_CONTACTS_SORT_CRITERIUM,
1329                                 (EmpathyConfNotifyFunc) main_window_notify_sort_criterium_cb,
1330                                 window);
1331         main_window_notify_sort_criterium_cb (conf,
1332                                               EMPATHY_PREFS_CONTACTS_SORT_CRITERIUM,
1333                                               window);
1334
1335         main_window_update_status (window, window->account_manager);
1336
1337         return window->window;
1338 }
1339