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