]> git.0d.be Git - empathy.git/blobdiff - libempathy-gtk/empathy-main-window.c
Merge call branch from Elliot Fairweather with cleanups from Xavier Claessens.
[empathy.git] / libempathy-gtk / empathy-main-window.c
index a34ad5bffb082c0f12d0db808cbee671469cbcc1..951b80e95cc054dad3e6190d78b89af1fe123bf4 100644 (file)
@@ -1,5 +1,6 @@
 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
 /*
+ * Copyright (C) 2002-2007 Imendio AB
  * Copyright (C) 2007 Collabora Ltd.
  *
  * This program is free software; you can redistribute it and/or
 #include <glade/glade.h>
 #include <glib/gi18n.h>
 
-#include <libtelepathy/tp-helpers.h>
-#include <libmissioncontrol/mission-control.h>
-
-#include <libempathy/gossip-conf.h>
-#include <libempathy/gossip-contact.h>
-#include <libempathy/gossip-debug.h>
+#include <libempathy/empathy-contact.h>
+#include <libempathy/empathy-debug.h>
+#include <libempathy/empathy-utils.h>
+#include <libempathy/empathy-chatroom-manager.h>
+#include <libempathy/empathy-chatroom.h>
+#include <libempathy/empathy-contact-list.h>
+#include <libempathy/empathy-contact-manager.h>
+#include <libempathy/empathy-contact-factory.h>
+#include <libempathy/empathy-status-presets.h>
 
 #include "empathy-main-window.h"
+#include "empathy-contact-dialogs.h"
 #include "ephy-spinner.h"
-#include "gossip-contact-list.h"
-#include "gossip-presence-chooser.h"
-#include "gossip-ui-utils.h"
-#include "gossip-status-presets.h"
-#include "gossip-geometry.h"
-#include "gossip-preferences.h"
-#include "gossip-accounts-dialog.h"
+#include "empathy-contact-list-store.h"
+#include "empathy-contact-list-view.h"
+#include "empathy-presence-chooser.h"
+#include "empathy-ui-utils.h"
+#include "empathy-geometry.h"
+#include "empathy-conf.h"
+#include "empathy-preferences.h"
+#include "empathy-accounts-dialog.h"
+#include "empathy-about-dialog.h"
+#include "empathy-new-chatroom-dialog.h"
+#include "empathy-chatrooms-window.h"
+#include "empathy-log-window.h"
+#include "empathy-new-message-dialog.h"
+#include "empathy-gtk-enum-types.h"
 
 #define DEBUG_DOMAIN "MainWindow"
 
 /* Accels (menu shortcuts) can be configured and saved */
 #define ACCELS_FILENAME "accels.txt"
 
-/* Flashing delay for icons (milliseconds). */
-#define FLASH_TIMEOUT 500
-
 /* Name in the geometry file */
 #define GEOMETRY_NAME "main-window"
 
 typedef struct {
-       GossipContactList *contact_list;
-       MissionControl    *mc;
-
-       /* Main widgets */
-       GtkWidget         *window;
-       GtkWidget         *main_vbox;
-
-       /* Tooltips for all widgets */
-       GtkTooltips       *tooltips;
-
-       /* Menu widgets */
-       GtkWidget         *room;
-       GtkWidget         *room_menu;
-       GtkWidget         *room_sep;
-       GtkWidget         *room_join_favorites;
-       GtkWidget         *edit_context;
-       GtkWidget         *edit_context_separator;
-
-       /* Throbber */
-       GtkWidget         *throbber;
-
-       /* Widgets that are enabled when we're connected/disconnected */
-       GList             *widgets_connected;
-       GList             *widgets_disconnected;
-
-       /* Status popup */
-       GtkWidget         *presence_toolbar;
-       GtkWidget         *presence_chooser;
-
-       /* Misc */
-       guint              size_timeout_id;
+       EmpathyContactListView  *list_view;
+       EmpathyContactListStore *list_store;
+       MissionControl          *mc;
+       EmpathyChatroomManager  *chatroom_manager;
+
+       GtkWidget              *window;
+       GtkWidget              *main_vbox;
+       GtkWidget              *throbber;
+       GtkWidget              *presence_toolbar;
+       GtkWidget              *presence_chooser;
+       GtkWidget              *errors_vbox;
+
+       GtkWidget              *room;
+       GtkWidget              *room_menu;
+       GtkWidget              *room_sep;
+       GtkWidget              *room_join_favorites;
+       GtkWidget              *edit_context;
+       GtkWidget              *edit_context_separator;
+
+       guint                   size_timeout_id;
+       GHashTable             *errors;
+
+       /* Widgets that are enabled when there is... */
+       GList                  *widgets_connected;      /* ... connected accounts */
+       GList                  *widgets_disconnected;   /* ... disconnected accounts */
 } EmpathyMainWindow;
 
-static void     main_window_destroy_cb                     (GtkWidget           *widget,
-                                                           EmpathyMainWindow   *window);
-static void     main_window_favorite_chatroom_menu_setup   (void);
-static void     main_window_chat_quit_cb                   (GtkWidget           *widget,
-                                                           EmpathyMainWindow   *window);
-static void     main_window_chat_new_message_cb            (GtkWidget           *widget,
-                                                           EmpathyMainWindow   *window);
-static void     main_window_chat_history_cb                (GtkWidget           *widget,
-                                                           EmpathyMainWindow   *window);
-static void     main_window_room_join_new_cb               (GtkWidget           *widget,
-                                                           EmpathyMainWindow   *window);
-static void     main_window_room_join_favorites_cb         (GtkWidget           *widget,
-                                                           EmpathyMainWindow   *window);
-static void     main_window_room_manage_favorites_cb       (GtkWidget           *widget,
-                                                           EmpathyMainWindow   *window);
-static void     main_window_chat_add_contact_cb            (GtkWidget           *widget,
-                                                           EmpathyMainWindow   *window);
-static void     main_window_chat_show_offline_cb           (GtkCheckMenuItem    *item,
-                                                           EmpathyMainWindow   *window);
-static gboolean main_window_edit_button_press_event_cb     (GtkWidget           *widget,
-                                                           GdkEventButton      *event,
-                                                           EmpathyMainWindow   *window);
-static void     main_window_edit_accounts_cb               (GtkWidget           *widget,
-                                                           EmpathyMainWindow   *window);
-static void     main_window_edit_personal_information_cb   (GtkWidget           *widget,
-                                                           EmpathyMainWindow   *window);
-static void     main_window_edit_preferences_cb            (GtkWidget           *widget,
-                                                           EmpathyMainWindow   *window);
-static void     main_window_help_about_cb                  (GtkWidget           *widget,
-                                                           EmpathyMainWindow   *window);
-static void     main_window_help_contents_cb               (GtkWidget           *widget,
-                                                           EmpathyMainWindow   *window);
-static gboolean main_window_throbber_button_press_event_cb (GtkWidget           *throbber_ebox,
-                                                           GdkEventButton      *event,
-                                                           gpointer             user_data);
-static void     main_window_accels_load                    (void);
-static void     main_window_accels_save                    (void);
-static void     main_window_connection_items_setup         (EmpathyMainWindow   *window,
-                                                           GladeXML            *glade);
-//static void     main_window_connection_items_update        (void);
-static void     main_window_presence_changed_cb            (DBusGProxy          *proxy,
-                                                           McPresence           state,
-                                                           EmpathyMainWindow   *window);
-static void     main_window_presence_chooser_changed_cb    (GtkWidget           *chooser,
-                                                           McPresence           state,
-                                                           const gchar         *status,
-                                                           EmpathyMainWindow   *window);
-static gboolean main_window_configure_event_timeout_cb     (EmpathyMainWindow   *window);
-static gboolean main_window_configure_event_cb             (GtkWidget           *widget,
-                                                           GdkEventConfigure   *event,
-                                                           EmpathyMainWindow   *window);
-static void     main_window_notify_show_offline_cb         (GossipConf          *conf,
-                                                           const gchar         *key,
-                                                           gpointer             check_menu_item);
-static void     main_window_notify_show_avatars_cb         (GossipConf          *conf,
-                                                           const gchar         *key,
-                                                           EmpathyMainWindow   *window);
-static void     main_window_notify_compact_contact_list_cb (GossipConf          *conf,
-                                                           const gchar         *key,
-                                                           EmpathyMainWindow   *window);
-static void     main_window_notify_sort_criterium_cb       (GossipConf          *conf,
-                                                           const gchar         *key,
-                                                           EmpathyMainWindow   *window);
+static void     main_window_destroy_cb                         (GtkWidget                *widget,
+                                                               EmpathyMainWindow        *window);
+static void     main_window_favorite_chatroom_menu_setup       (EmpathyMainWindow        *window);
+static void     main_window_favorite_chatroom_menu_added_cb    (EmpathyChatroomManager   *manager,
+                                                               EmpathyChatroom          *chatroom,
+                                                               EmpathyMainWindow        *window);
+static void     main_window_favorite_chatroom_menu_removed_cb  (EmpathyChatroomManager   *manager,
+                                                               EmpathyChatroom          *chatroom,
+                                                               EmpathyMainWindow        *window);
+static void     main_window_favorite_chatroom_menu_activate_cb (GtkMenuItem              *menu_item,
+                                                               EmpathyChatroom          *chatroom);
+static void     main_window_favorite_chatroom_menu_update      (EmpathyMainWindow        *window);
+static void     main_window_favorite_chatroom_menu_add         (EmpathyMainWindow        *window,
+                                                               EmpathyChatroom          *chatroom);
+static void     main_window_favorite_chatroom_join             (EmpathyChatroom          *chatroom);
+static void     main_window_chat_quit_cb                       (GtkWidget                *widget,
+                                                               EmpathyMainWindow        *window);
+static void     main_window_chat_new_message_cb                (GtkWidget                *widget,
+                                                               EmpathyMainWindow        *window);
+static void     main_window_chat_history_cb                    (GtkWidget                *widget,
+                                                               EmpathyMainWindow        *window);
+static void     main_window_room_join_new_cb                   (GtkWidget                *widget,
+                                                               EmpathyMainWindow        *window);
+static void     main_window_room_join_favorites_cb             (GtkWidget                *widget,
+                                                               EmpathyMainWindow        *window);
+static void     main_window_room_manage_favorites_cb           (GtkWidget                *widget,
+                                                               EmpathyMainWindow        *window);
+static void     main_window_chat_add_contact_cb                (GtkWidget                *widget,
+                                                               EmpathyMainWindow        *window);
+static void     main_window_chat_show_offline_cb               (GtkCheckMenuItem         *item,
+                                                               EmpathyMainWindow        *window);
+static gboolean main_window_edit_button_press_event_cb         (GtkWidget                *widget,
+                                                               GdkEventButton           *event,
+                                                               EmpathyMainWindow        *window);
+static void     main_window_edit_accounts_cb                   (GtkWidget                *widget,
+                                                               EmpathyMainWindow        *window);
+static void     main_window_edit_personal_information_cb       (GtkWidget                *widget,
+                                                               EmpathyMainWindow        *window);
+static void     main_window_edit_preferences_cb                (GtkWidget                *widget,
+                                                               EmpathyMainWindow        *window);
+static void     main_window_help_about_cb                      (GtkWidget                *widget,
+                                                               EmpathyMainWindow        *window);
+static void     main_window_help_contents_cb                   (GtkWidget                *widget,
+                                                               EmpathyMainWindow        *window);
+static gboolean main_window_throbber_button_press_event_cb     (GtkWidget                *throbber_ebox,
+                                                               GdkEventButton           *event,
+                                                               EmpathyMainWindow        *window);
+static void     main_window_status_changed_cb                  (MissionControl           *mc,
+                                                               TpConnectionStatus        status,
+                                                               McPresence                presence,
+                                                               TpConnectionStatusReason  reason,
+                                                               const gchar              *unique_name,
+                                                               EmpathyMainWindow        *window);
+static void     main_window_update_status                      (EmpathyMainWindow        *window);
+static void     main_window_accels_load                        (void);
+static void     main_window_accels_save                        (void);
+static void     main_window_connection_items_setup             (EmpathyMainWindow        *window,
+                                                               GladeXML                 *glade);
+static gboolean main_window_configure_event_timeout_cb         (EmpathyMainWindow        *window);
+static gboolean main_window_configure_event_cb                 (GtkWidget                *widget,
+                                                               GdkEventConfigure        *event,
+                                                               EmpathyMainWindow        *window);
+static void     main_window_notify_show_offline_cb             (EmpathyConf              *conf,
+                                                               const gchar              *key,
+                                                               gpointer                  check_menu_item);
+static void     main_window_notify_show_avatars_cb             (EmpathyConf              *conf,
+                                                               const gchar              *key,
+                                                               EmpathyMainWindow        *window);
+static void     main_window_notify_compact_contact_list_cb     (EmpathyConf              *conf,
+                                                               const gchar              *key,
+                                                               EmpathyMainWindow        *window);
+static void     main_window_notify_sort_criterium_cb           (EmpathyConf              *conf,
+                                                               const gchar              *key,
+                                                               EmpathyMainWindow        *window);
 
 GtkWidget *
 empathy_main_window_show (void)
 {
        static EmpathyMainWindow *window = NULL;
+       EmpathyContactList       *list_iface;
        GladeXML                 *glade;
-       GossipConf               *conf;
+       EmpathyConf               *conf;
        GtkWidget                *sw;
        GtkWidget                *show_offline_widget;
        GtkWidget                *ebox;
        GtkToolItem              *item;
-       gchar                    *str;
-       McPresence                state;
        gboolean                  show_offline;
        gboolean                  show_avatars;
        gboolean                  compact_contact_list;
@@ -181,11 +194,12 @@ empathy_main_window_show (void)
        window = g_new0 (EmpathyMainWindow, 1);
 
        /* Set up interface */
-       glade = gossip_glade_get_file ("empathy-main-window.glade",
+       glade = empathy_glade_get_file ("empathy-main-window.glade",
                                       "main_window",
                                       NULL,
                                       "main_window", &window->window,
                                       "main_vbox", &window->main_vbox,
+                                      "errors_vbox", &window->errors_vbox,
                                       "chat_show_offline", &show_offline_widget,
                                       "room", &window->room,
                                       "room_sep", &window->room_sep,
@@ -196,7 +210,7 @@ empathy_main_window_show (void)
                                       "roster_scrolledwindow", &sw,
                                       NULL);
 
-       gossip_glade_connect (glade,
+       empathy_glade_connect (glade,
                              window,
                              "main_window", "destroy", main_window_destroy_cb,
                              "main_window", "configure_event", main_window_configure_event_cb,
@@ -220,35 +234,25 @@ empathy_main_window_show (void)
        main_window_connection_items_setup (window, glade);
        g_object_unref (glade);
 
-       window->tooltips = g_object_ref_sink (gtk_tooltips_new ());
+       window->mc = empathy_mission_control_new ();
+       dbus_g_proxy_connect_signal (DBUS_G_PROXY (window->mc), "AccountStatusChanged",
+                                    G_CALLBACK (main_window_status_changed_cb),
+                                    window, NULL);
+
+       window->errors = g_hash_table_new_full (empathy_account_hash,
+                                               empathy_account_equal,
+                                               g_object_unref,
+                                               NULL);
 
        /* Set up menu */
-       main_window_favorite_chatroom_menu_setup ();
+       main_window_favorite_chatroom_menu_setup (window);
 
        gtk_widget_hide (window->edit_context);
        gtk_widget_hide (window->edit_context_separator);
 
-       /* Set up presence chooser
-        * FIXME: Update status message not yet supported by MC 
-        */
-       window->mc = mission_control_new (tp_get_bus ());
-       window->presence_chooser = gossip_presence_chooser_new ();
+       /* Set up presence chooser */
+       window->presence_chooser = empathy_presence_chooser_new ();
        gtk_widget_show (window->presence_chooser);
-       gossip_presence_chooser_set_flash_interval (GOSSIP_PRESENCE_CHOOSER (window->presence_chooser),
-                                                   FLASH_TIMEOUT);
-       state = mission_control_get_presence (window->mc, NULL);
-       gossip_presence_chooser_set_state (GOSSIP_PRESENCE_CHOOSER (window->presence_chooser),
-                                          state);
-       dbus_g_proxy_connect_signal (DBUS_G_PROXY (window->mc),
-                                    "PresenceStatusRequested",
-                                    G_CALLBACK (main_window_presence_changed_cb),
-                                    window, NULL);
-       g_signal_connect (window->presence_chooser,
-                         "changed",
-                         G_CALLBACK (main_window_presence_chooser_changed_cb),
-                         window);
-
-
        item = gtk_tool_item_new ();
        gtk_widget_show (GTK_WIDGET (item));
        gtk_container_add (GTK_CONTAINER (item), window->presence_chooser);
@@ -256,50 +260,50 @@ empathy_main_window_show (void)
        gtk_tool_item_set_expand (item, TRUE);
        gtk_toolbar_insert (GTK_TOOLBAR (window->presence_toolbar), item, -1);
 
-       window->widgets_connected = g_list_prepend (window->widgets_connected,
-                                                 window->presence_chooser);
-
        /* Set up the throbber */
        ebox = gtk_event_box_new ();
        gtk_event_box_set_visible_window (GTK_EVENT_BOX (ebox), FALSE);
+       gtk_widget_set_tooltip_text (ebox, _("Show and edit accounts"));
+       g_signal_connect (ebox,
+                         "button-press-event",
+                         G_CALLBACK (main_window_throbber_button_press_event_cb),
+                         window);
+       gtk_widget_show (ebox);
 
        window->throbber = ephy_spinner_new ();
        ephy_spinner_set_size (EPHY_SPINNER (window->throbber), GTK_ICON_SIZE_LARGE_TOOLBAR);
        gtk_container_add (GTK_CONTAINER (ebox), window->throbber);
+       gtk_widget_show (window->throbber);
 
        item = gtk_tool_item_new ();
        gtk_container_add (GTK_CONTAINER (item), ebox);
-       gtk_widget_show_all (GTK_WIDGET (item));
-
        gtk_toolbar_insert (GTK_TOOLBAR (window->presence_toolbar), item, -1);
+       gtk_widget_show (GTK_WIDGET (item));
 
-       str = _("Show and edit accounts");
-       gtk_tooltips_set_tip (GTK_TOOLTIPS (window->tooltips),
-                             ebox, str, str);
+       /* Set up contact list. */
+       empathy_status_presets_get_all ();
 
-       g_signal_connect (ebox,
-                         "button-press-event",
-                         G_CALLBACK (main_window_throbber_button_press_event_cb),
-                         NULL);
+       list_iface = EMPATHY_CONTACT_LIST (empathy_contact_manager_new ());
+       window->list_store = empathy_contact_list_store_new (list_iface);
+       window->list_view = empathy_contact_list_view_new (window->list_store,
+                                                          EMPATHY_CONTACT_LIST_FEATURE_ALL);
+       g_object_unref (list_iface);
 
-       /* Set up contact list. */
-       gossip_status_presets_get_all ();
-       window->contact_list = gossip_contact_list_new ();
-       gtk_widget_show (GTK_WIDGET (window->contact_list));
+       gtk_widget_show (GTK_WIDGET (window->list_view));
        gtk_container_add (GTK_CONTAINER (sw),
-                          GTK_WIDGET (window->contact_list));
+                          GTK_WIDGET (window->list_view));
 
        /* Load user-defined accelerators. */
        main_window_accels_load ();
 
        /* Set window size. */
-       gossip_geometry_load (GEOMETRY_NAME, &x, &y, &w, &h);
+       empathy_geometry_load (GEOMETRY_NAME, &x, &y, &w, &h);
 
        if (w >= 1 && h >= 1) {
                /* Use the defaults from the glade file if we
                 * don't have good w, h geometry.
                 */
-               gossip_debug (DEBUG_DOMAIN, "Configuring window default size w:%d, h:%d", w, h);
+               empathy_debug (DEBUG_DOMAIN, "Configuring window default size w:%d, h:%d", w, h);
                gtk_window_set_default_size (GTK_WINDOW (window->window), w, h);
        }
 
@@ -307,18 +311,18 @@ empathy_main_window_show (void)
                /* Let the window manager position it if we
                 * don't have good x, y coordinates.
                 */
-               gossip_debug (DEBUG_DOMAIN, "Configuring window default position x:%d, y:%d", x, y);
+               empathy_debug (DEBUG_DOMAIN, "Configuring window default position x:%d, y:%d", x, y);
                gtk_window_move (GTK_WINDOW (window->window), x, y);
        }
 
-       conf = gossip_conf_get ();
+       conf = empathy_conf_get ();
        
        /* Show offline ? */
-       gossip_conf_get_bool (conf,
-                             GOSSIP_PREFS_CONTACTS_SHOW_OFFLINE,
+       empathy_conf_get_bool (conf,
+                             EMPATHY_PREFS_CONTACTS_SHOW_OFFLINE,
                              &show_offline);
-       gossip_conf_notify_add (conf,
-                               GOSSIP_PREFS_CONTACTS_SHOW_OFFLINE,
+       empathy_conf_notify_add (conf,
+                               EMPATHY_PREFS_CONTACTS_SHOW_OFFLINE,
                                main_window_notify_show_offline_cb,
                                show_offline_widget);
 
@@ -326,35 +330,35 @@ empathy_main_window_show (void)
                                        show_offline);
 
        /* Show avatars ? */
-       gossip_conf_get_bool (conf,
-                             GOSSIP_PREFS_UI_SHOW_AVATARS,
+       empathy_conf_get_bool (conf,
+                             EMPATHY_PREFS_UI_SHOW_AVATARS,
                              &show_avatars);
-       gossip_conf_notify_add (conf,
-                               GOSSIP_PREFS_UI_SHOW_AVATARS,
-                               (GossipConfNotifyFunc) main_window_notify_show_avatars_cb,
+       empathy_conf_notify_add (conf,
+                               EMPATHY_PREFS_UI_SHOW_AVATARS,
+                               (EmpathyConfNotifyFunc) main_window_notify_show_avatars_cb,
                                window);
-       gossip_contact_list_set_show_avatars (window->contact_list, show_avatars);
+       empathy_contact_list_store_set_show_avatars (window->list_store, show_avatars);
 
        /* Is compact ? */
-       gossip_conf_get_bool (conf,
-                             GOSSIP_PREFS_UI_COMPACT_CONTACT_LIST,
+       empathy_conf_get_bool (conf,
+                             EMPATHY_PREFS_UI_COMPACT_CONTACT_LIST,
                              &compact_contact_list);
-       gossip_conf_notify_add (conf,
-                               GOSSIP_PREFS_UI_COMPACT_CONTACT_LIST,
-                               (GossipConfNotifyFunc) main_window_notify_compact_contact_list_cb,
+       empathy_conf_notify_add (conf,
+                               EMPATHY_PREFS_UI_COMPACT_CONTACT_LIST,
+                               (EmpathyConfNotifyFunc) main_window_notify_compact_contact_list_cb,
                                window);
-       gossip_contact_list_set_is_compact (window->contact_list, compact_contact_list);
+       empathy_contact_list_store_set_is_compact (window->list_store, compact_contact_list);
 
        /* Sort criterium */
-       gossip_conf_notify_add (conf,
-                               GOSSIP_PREFS_CONTACTS_SORT_CRITERIUM,
-                               (GossipConfNotifyFunc) main_window_notify_sort_criterium_cb,
+       empathy_conf_notify_add (conf,
+                               EMPATHY_PREFS_CONTACTS_SORT_CRITERIUM,
+                               (EmpathyConfNotifyFunc) main_window_notify_sort_criterium_cb,
                                window);
        main_window_notify_sort_criterium_cb (conf,
-                                             GOSSIP_PREFS_CONTACTS_SORT_CRITERIUM,
+                                             EMPATHY_PREFS_CONTACTS_SORT_CRITERIUM,
                                              window);
 
-       gtk_widget_show (window->window);
+       main_window_update_status (window);
 
        return window->window;
 }
@@ -366,6 +370,10 @@ main_window_destroy_cb (GtkWidget         *widget,
        /* Save user-defined accelerators. */
        main_window_accels_save ();
 
+       dbus_g_proxy_disconnect_signal (DBUS_G_PROXY (window->mc), "AccountStatusChanged",
+                                       G_CALLBACK (main_window_status_changed_cb),
+                                       window);
+
        if (window->size_timeout_id) {
                g_source_remove (window->size_timeout_id);
        }
@@ -373,64 +381,191 @@ main_window_destroy_cb (GtkWidget         *widget,
        g_list_free (window->widgets_connected);
        g_list_free (window->widgets_disconnected);
 
-       g_object_unref (window->tooltips);
        g_object_unref (window->mc);
+       g_object_unref (window->list_store);
+       g_hash_table_destroy (window->errors);
 
        g_free (window);
 }
 
 static void
-main_window_favorite_chatroom_menu_setup (void)
+main_window_favorite_chatroom_menu_setup (EmpathyMainWindow *window)
+{
+       GList *chatrooms, *l;
+
+       window->chatroom_manager = empathy_chatroom_manager_new ();
+       chatrooms = empathy_chatroom_manager_get_chatrooms (window->chatroom_manager, NULL);
+       window->room_menu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (window->room));
+
+       for (l = chatrooms; l; l = l->next) {
+               main_window_favorite_chatroom_menu_add (window, l->data);
+       }
+
+       if (!chatrooms) {
+               gtk_widget_hide (window->room_sep);
+       }
+
+       gtk_widget_set_sensitive (window->room_join_favorites, chatrooms != NULL);
+
+       g_signal_connect (window->chatroom_manager, "chatroom-added",
+                         G_CALLBACK (main_window_favorite_chatroom_menu_added_cb),
+                         window);
+       g_signal_connect (window->chatroom_manager, "chatroom-removed",
+                         G_CALLBACK (main_window_favorite_chatroom_menu_removed_cb),
+                         window);
+
+       g_list_free (chatrooms);
+}
+
+static void
+main_window_favorite_chatroom_menu_added_cb (EmpathyChatroomManager *manager,
+                                            EmpathyChatroom        *chatroom,
+                                            EmpathyMainWindow     *window)
+{
+       main_window_favorite_chatroom_menu_add (window, chatroom);
+       gtk_widget_show (window->room_sep);
+       gtk_widget_set_sensitive (window->room_join_favorites, TRUE);
+}
+
+static void
+main_window_favorite_chatroom_menu_removed_cb (EmpathyChatroomManager *manager,
+                                              EmpathyChatroom        *chatroom,
+                                              EmpathyMainWindow     *window)
+{
+       GtkWidget *menu_item;
+
+       menu_item = g_object_get_data (G_OBJECT (chatroom), "menu_item");
+
+       g_object_set_data (G_OBJECT (chatroom), "menu_item", NULL);
+       gtk_widget_destroy (menu_item);
+
+       main_window_favorite_chatroom_menu_update (window);
+}
+
+static void
+main_window_favorite_chatroom_menu_activate_cb (GtkMenuItem    *menu_item,
+                                               EmpathyChatroom *chatroom)
+{
+       main_window_favorite_chatroom_join (chatroom);
+}
+
+static void
+main_window_favorite_chatroom_menu_update (EmpathyMainWindow *window)
+{
+       GList *chatrooms;
+
+       chatrooms = empathy_chatroom_manager_get_chatrooms (window->chatroom_manager, NULL);
+
+       if (chatrooms) {
+               gtk_widget_show (window->room_sep);
+       } else {
+               gtk_widget_hide (window->room_sep);
+       }
+
+       gtk_widget_set_sensitive (window->room_join_favorites, chatrooms != NULL);
+       g_list_free (chatrooms);
+}
+
+static void
+main_window_favorite_chatroom_menu_add (EmpathyMainWindow *window,
+                                       EmpathyChatroom    *chatroom)
+{
+       GtkWidget   *menu_item;
+       const gchar *name;
+
+       if (g_object_get_data (G_OBJECT (chatroom), "menu_item")) {
+               return;
+       }
+
+       name = empathy_chatroom_get_name (chatroom);
+       menu_item = gtk_menu_item_new_with_label (name);
+
+       g_object_set_data (G_OBJECT (chatroom), "menu_item", menu_item);
+       g_signal_connect (menu_item, "activate",
+                         G_CALLBACK (main_window_favorite_chatroom_menu_activate_cb),
+                         chatroom);
+
+       gtk_menu_shell_insert (GTK_MENU_SHELL (window->room_menu),
+                              menu_item, 3);
+
+       gtk_widget_show (menu_item);
+}
+
+static void
+main_window_favorite_chatroom_join (EmpathyChatroom *chatroom)
 {
+       MissionControl *mc;
+       McAccount      *account;
+       const gchar    *room;
+
+       mc = empathy_mission_control_new ();
+       account = empathy_chatroom_get_account (chatroom);
+       room = empathy_chatroom_get_room (chatroom);
+
+       empathy_debug (DEBUG_DOMAIN, "Requesting channel for '%s'", room);
+
+       mission_control_request_channel_with_string_handle (mc,
+                                                           account,
+                                                           TP_IFACE_CHANNEL_TYPE_TEXT,
+                                                           room,
+                                                           TP_HANDLE_TYPE_ROOM,
+                                                           NULL, NULL);        
+       g_object_unref (mc);
 }
 
 static void
 main_window_chat_quit_cb (GtkWidget         *widget,
                          EmpathyMainWindow *window)
 {
-       gtk_widget_destroy (window->window);
+       gtk_main_quit ();
 }
 
 static void
 main_window_chat_new_message_cb (GtkWidget         *widget,
                                 EmpathyMainWindow *window)
 {
-       //gossip_new_message_dialog_show (GTK_WINDOW (window->window));
+       empathy_new_message_dialog_show (GTK_WINDOW (window->window));
 }
 
 static void
 main_window_chat_history_cb (GtkWidget         *widget,
                             EmpathyMainWindow *window)
 {
-       //gossip_log_window_show (NULL, NULL);
+       empathy_log_window_show (NULL, NULL, FALSE, GTK_WINDOW (window->window));
 }
 
 static void
 main_window_room_join_new_cb (GtkWidget         *widget,
                              EmpathyMainWindow *window)
 {
-       //gossip_new_chatroom_dialog_show (GTK_WINDOW (window->window));
+       empathy_new_chatroom_dialog_show (GTK_WINDOW (window->window));
 }
 
 static void
 main_window_room_join_favorites_cb (GtkWidget         *widget,
                                    EmpathyMainWindow *window)
 {
-       //gossip_session_chatroom_join_favorites (window->session);
+       GList *chatrooms, *l;
+
+       chatrooms = empathy_chatroom_manager_get_chatrooms (window->chatroom_manager, NULL);
+       for (l = chatrooms; l; l = l->next) {
+               main_window_favorite_chatroom_join (l->data);
+       }
+       g_list_free (chatrooms);
 }
 
 static void
 main_window_room_manage_favorites_cb (GtkWidget         *widget,
                                      EmpathyMainWindow *window)
 {
-       //gossip_chatrooms_window_show (NULL, FALSE);
+       empathy_chatrooms_window_show (GTK_WINDOW (window->window));
 }
 
 static void
 main_window_chat_add_contact_cb (GtkWidget         *widget,
                                 EmpathyMainWindow *window)
 {
-       //gossip_add_contact_dialog_show (GTK_WINDOW (window->window), NULL);
+       empathy_new_contact_dialog_show (GTK_WINDOW (window->window));
 }
 
 static void
@@ -441,14 +576,14 @@ main_window_chat_show_offline_cb (GtkCheckMenuItem  *item,
 
        current = gtk_check_menu_item_get_active (item);
 
-       gossip_conf_set_bool (gossip_conf_get (),
-                             GOSSIP_PREFS_CONTACTS_SHOW_OFFLINE,
+       empathy_conf_set_bool (empathy_conf_get (),
+                             EMPATHY_PREFS_CONTACTS_SHOW_OFFLINE,
                              current);
 
        /* Turn off sound just while we alter the contact list. */
-       // FIXME: gossip_sound_set_enabled (FALSE);
-       g_object_set (window->contact_list, "show_offline", current, NULL);
-       //gossip_sound_set_enabled (TRUE);
+       // FIXME: empathy_sound_set_enabled (FALSE);
+       empathy_contact_list_store_set_show_offline (window->list_store, current);
+       //empathy_sound_set_enabled (TRUE);
 }
 
 static gboolean
@@ -456,14 +591,14 @@ main_window_edit_button_press_event_cb (GtkWidget         *widget,
                                        GdkEventButton    *event,
                                        EmpathyMainWindow *window)
 {
-       GossipContact *contact;
+       EmpathyContact *contact;
        gchar         *group;
 
        if (!event->button == 1) {
                return FALSE;
        }
 
-       group = gossip_contact_list_get_selected_group (window->contact_list);
+       group = empathy_contact_list_view_get_selected_group (window->list_view);
        if (group) {
                GtkMenuItem *item;
                GtkWidget   *label;
@@ -476,7 +611,7 @@ main_window_edit_button_press_event_cb (GtkWidget         *widget,
                gtk_widget_show (window->edit_context);
                gtk_widget_show (window->edit_context_separator);
 
-               submenu = gossip_contact_list_get_group_menu (window->contact_list);
+               submenu = empathy_contact_list_view_get_group_menu (window->list_view);
                gtk_menu_item_set_submenu (item, submenu);
 
                g_free (group);
@@ -484,7 +619,7 @@ main_window_edit_button_press_event_cb (GtkWidget         *widget,
                return FALSE;
        }
 
-       contact = gossip_contact_list_get_selected (window->contact_list);
+       contact = empathy_contact_list_view_get_selected (window->list_view);
        if (contact) {
                GtkMenuItem *item;
                GtkWidget   *label;
@@ -497,8 +632,8 @@ main_window_edit_button_press_event_cb (GtkWidget         *widget,
                gtk_widget_show (window->edit_context);
                gtk_widget_show (window->edit_context_separator);
 
-               submenu = gossip_contact_list_get_contact_menu (window->contact_list,
-                                                               contact);
+               submenu = empathy_contact_list_view_get_contact_menu (window->list_view,
+                                                                    contact);
                gtk_menu_item_set_submenu (item, submenu);
 
                g_object_unref (contact);
@@ -516,154 +651,353 @@ static void
 main_window_edit_accounts_cb (GtkWidget         *widget,
                              EmpathyMainWindow *window)
 {
-       gossip_accounts_dialog_show ();
+       empathy_accounts_dialog_show (GTK_WINDOW (window->window));
 }
 
 static void
 main_window_edit_personal_information_cb (GtkWidget         *widget,
                                          EmpathyMainWindow *window)
 {
-       //gossip_vcard_dialog_show (GTK_WINDOW (window->window));
+       GSList *accounts;
+
+       accounts = mission_control_get_online_connections (window->mc, NULL);
+       if (accounts) {
+               EmpathyContactFactory *factory;
+               EmpathyContact        *contact;
+               McAccount             *account;
+
+               account = accounts->data;
+               factory = empathy_contact_factory_new ();
+               contact = empathy_contact_factory_get_user (factory, account);
+               empathy_contact_information_dialog_show (contact,
+                                                        GTK_WINDOW (window->window),
+                                                        TRUE, TRUE);
+               g_slist_foreach (accounts, (GFunc) g_object_unref, NULL);
+               g_slist_free (accounts);
+               g_object_unref (factory);
+               g_object_unref (contact);
+       }
 }
 
 static void
 main_window_edit_preferences_cb (GtkWidget         *widget,
                                 EmpathyMainWindow *window)
 {
-       gossip_preferences_show ();
+       empathy_preferences_show (GTK_WINDOW (window->window));
 }
 
 static void
 main_window_help_about_cb (GtkWidget         *widget,
                           EmpathyMainWindow *window)
 {
-       //gossip_about_dialog_new (GTK_WINDOW (window->window));
+       empathy_about_dialog_new (GTK_WINDOW (window->window));
 }
 
 static void
 main_window_help_contents_cb (GtkWidget         *widget,
                              EmpathyMainWindow *window)
 {
-       //gossip_help_show ();
+       //empathy_help_show ();
 }
 
 static gboolean
-main_window_throbber_button_press_event_cb (GtkWidget      *throbber_ebox,
-                                           GdkEventButton *event,
-                                           gpointer        user_data)
+main_window_throbber_button_press_event_cb (GtkWidget         *throbber_ebox,
+                                           GdkEventButton    *event,
+                                           EmpathyMainWindow *window)
 {
        if (event->type != GDK_BUTTON_PRESS ||
            event->button != 1) {
                return FALSE;
        }
 
-       gossip_accounts_dialog_show ();
+       empathy_accounts_dialog_show (GTK_WINDOW (window->window));
 
        return FALSE;
 }
-#if 0
+
 static void
-main_window_session_protocol_connecting_cb (GossipSession  *session,
-                                   GossipAccount  *account,
-                                   GossipProtocol *protocol,
-                                   gpointer        user_data)
+main_window_error_edit_clicked_cb (GtkButton         *button,
+                                  EmpathyMainWindow *window)
 {
-       GossipAppPriv *priv;
-       const gchar   *name;
+       McAccount *account;
+       GtkWidget *error_widget;
 
-       priv = GET_PRIV (app);
+       empathy_accounts_dialog_show (GTK_WINDOW (window->window));
 
-       name = gossip_account_get_name (account);
-       gossip_debug (DEBUG_DOMAIN, "Connecting account:'%s'", name);
-
-       ephy_spinner_start (EPHY_SPINNER (window->throbber));
+       account = g_object_get_data (G_OBJECT (button), "account");
+       error_widget = g_hash_table_lookup (window->errors, account);
+       gtk_widget_destroy (error_widget);
+       g_hash_table_remove (window->errors, account);
 }
 
 static void
-main_window_session_protocol_connected_cb (GossipSession  *session,
-                                  GossipAccount  *account,
-                                  GossipProtocol *protocol,
-                                  gpointer        user_data)
+main_window_error_clear_clicked_cb (GtkButton         *button,
+                                   EmpathyMainWindow *window)
 {
-       GossipAppPriv *priv;
-       gboolean       connecting;
-       const gchar   *name;
-
-       priv = GET_PRIV (app);
+       McAccount *account;
+       GtkWidget *error_widget;
 
-       name = gossip_account_get_name (account);
-       gossip_debug (DEBUG_DOMAIN, "Connected account:'%s'", name);
-
-       gossip_session_count_accounts (window->session,
-                                      NULL,
-                                      &connecting,
-                                      NULL);
+       account = g_object_get_data (G_OBJECT (button), "account");
+       error_widget = g_hash_table_lookup (window->errors, account);
+       gtk_widget_destroy (error_widget);
+       g_hash_table_remove (window->errors, account);
+}
 
-       if (connecting < 1) {
-               ephy_spinner_stop (EPHY_SPINNER (window->throbber));
+static void
+main_window_error_display (EmpathyMainWindow *window,
+                          McAccount         *account,
+                          const gchar       *message)
+{
+       GtkWidget *child;
+       GtkWidget *table;
+       GtkWidget *image;
+       GtkWidget *button_edit;
+       GtkWidget *alignment;
+       GtkWidget *hbox;
+       GtkWidget *label;
+       GtkWidget *fixed;
+       GtkWidget *vbox;
+       GtkWidget *button_close;
+       gchar     *str;
+
+       child = g_hash_table_lookup (window->errors, account);
+       if (child) {
+               label = g_object_get_data (G_OBJECT (child), "label");
+
+               /* Just set the latest error and return */
+               str = g_markup_printf_escaped ("<b>%s</b>\n%s",
+                                              mc_account_get_display_name (account),
+                                              message);
+               gtk_label_set_markup (GTK_LABEL (label), str);
+               g_free (str);
+
+               return;
        }
 
-       g_hash_table_remove (window->errors, account);
-       g_hash_table_remove (window->reconnects, account);
+       child = gtk_vbox_new (FALSE, 0);
+       gtk_box_pack_start (GTK_BOX (window->errors_vbox), child, FALSE, TRUE, 0);
+       gtk_container_set_border_width (GTK_CONTAINER (child), 6);
+       gtk_widget_show (child);
+
+       table = gtk_table_new (2, 4, FALSE);
+       gtk_widget_show (table);
+       gtk_box_pack_start (GTK_BOX (child), table, TRUE, TRUE, 0);
+       gtk_table_set_row_spacings (GTK_TABLE (table), 12);
+       gtk_table_set_col_spacings (GTK_TABLE (table), 6);
+
+       image = gtk_image_new_from_stock (GTK_STOCK_DISCONNECT, GTK_ICON_SIZE_MENU);
+       gtk_widget_show (image);
+       gtk_table_attach (GTK_TABLE (table), image, 0, 1, 0, 2,
+                         (GtkAttachOptions) (GTK_FILL),
+                         (GtkAttachOptions) (GTK_FILL), 0, 0);
+       gtk_misc_set_alignment (GTK_MISC (image), 0.5, 0);
+
+       button_edit = gtk_button_new ();
+       gtk_widget_show (button_edit);
+       gtk_table_attach (GTK_TABLE (table), button_edit, 1, 2, 1, 2,
+                         (GtkAttachOptions) (GTK_FILL),
+                         (GtkAttachOptions) (0), 0, 0);
+
+       alignment = gtk_alignment_new (0.5, 0.5, 0, 0);
+       gtk_widget_show (alignment);
+       gtk_container_add (GTK_CONTAINER (button_edit), alignment);
+
+       hbox = gtk_hbox_new (FALSE, 2);
+       gtk_widget_show (hbox);
+       gtk_container_add (GTK_CONTAINER (alignment), hbox);
+
+       image = gtk_image_new_from_stock (GTK_STOCK_EDIT, GTK_ICON_SIZE_BUTTON);
+       gtk_widget_show (image);
+       gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
+
+       label = gtk_label_new_with_mnemonic (_("_Edit account"));
+       gtk_widget_show (label);
+       gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
+
+       fixed = gtk_fixed_new ();
+       gtk_widget_show (fixed);
+       gtk_table_attach (GTK_TABLE (table), fixed, 2, 3, 1, 2,
+                         (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
+                         (GtkAttachOptions) (GTK_FILL), 0, 0);
+
+       vbox = gtk_vbox_new (FALSE, 6);
+       gtk_widget_show (vbox);
+       gtk_table_attach (GTK_TABLE (table), vbox, 3, 4, 0, 2,
+                         (GtkAttachOptions) (GTK_FILL),
+                         (GtkAttachOptions) (GTK_FILL), 0, 0);
+
+       button_close = gtk_button_new ();
+       gtk_widget_show (button_close);
+       gtk_box_pack_start (GTK_BOX (vbox), button_close, FALSE, FALSE, 0);
+       gtk_button_set_relief (GTK_BUTTON (button_close), GTK_RELIEF_NONE);
+
+
+       image = gtk_image_new_from_stock ("gtk-close", GTK_ICON_SIZE_MENU);
+       gtk_widget_show (image);
+       gtk_container_add (GTK_CONTAINER (button_close), image);
+
+       label = gtk_label_new ("");
+       gtk_widget_show (label);
+       gtk_table_attach (GTK_TABLE (table), label, 1, 3, 0, 1,
+                         (GtkAttachOptions) (GTK_EXPAND | GTK_SHRINK | GTK_FILL),
+                         (GtkAttachOptions) (GTK_EXPAND | GTK_SHRINK | GTK_FILL), 0, 0);
+       gtk_widget_set_size_request (label, 175, -1);
+       gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
+       gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
+       gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
+
+       str = g_markup_printf_escaped ("<b>%s</b>\n%s",
+                                      mc_account_get_display_name (account),
+                                      message);
+       gtk_label_set_markup (GTK_LABEL (label), str);
+       g_free (str);
+
+       g_object_set_data (G_OBJECT (child), "label", label);
+       g_object_set_data_full (G_OBJECT (button_edit),
+                               "account", g_object_ref (account),
+                               g_object_unref);
+       g_object_set_data_full (G_OBJECT (button_close),
+                               "account", g_object_ref (account),
+                               g_object_unref);
+
+       g_signal_connect (button_edit, "clicked",
+                         G_CALLBACK (main_window_error_edit_clicked_cb),
+                         window);
 
-       app_connection_items_update ();
-       app_favorite_chatroom_menu_update ();
+       g_signal_connect (button_close, "clicked",
+                         G_CALLBACK (main_window_error_clear_clicked_cb),
+                         window);
 
-       /* Use saved presence */
-       gossip_app_set_presence (gossip_status_presets_get_default_state (),
-                                gossip_status_presets_get_default_status());
+       gtk_widget_show (window->errors_vbox);
 
-       app_presence_updated ();
+       g_hash_table_insert (window->errors, g_object_ref (account), child);
 }
 
 static void
-main_window_session_protocol_disconnected_cb (GossipSession  *session,
-                                     GossipAccount  *account,
-                                     GossipProtocol *protocol,
-                                     gint            reason,
-                                     gpointer        user_data)
+main_window_status_changed_cb (MissionControl           *mc,
+                              TpConnectionStatus        status,
+                              McPresence                presence,
+                              TpConnectionStatusReason  reason,
+                              const gchar              *unique_name,
+                              EmpathyMainWindow        *window)
 {
-       GossipAppPriv *priv;
-       gboolean       connecting;
-       gboolean       should_reconnect;
-       const gchar   *name;
-
-       priv = GET_PRIV (app);
+       McAccount *account;
+
+       main_window_update_status (window);
+
+       account = mc_account_lookup (unique_name);
+
+       if (status == TP_CONNECTION_STATUS_DISCONNECTED &&
+           reason > TP_CONNECTION_STATUS_REASON_REQUESTED) {
+               const gchar *message;
+
+               switch (reason) {
+               case TP_CONNECTION_STATUS_REASON_NETWORK_ERROR:
+                       message = _("Network error");
+                       break;
+               case TP_CONNECTION_STATUS_REASON_AUTHENTICATION_FAILED:
+                       message = _("Authentication failed");
+                       break;
+               case TP_CONNECTION_STATUS_REASON_ENCRYPTION_ERROR:
+                       message = _("Encryption error");
+                       break;
+               case TP_CONNECTION_STATUS_REASON_NAME_IN_USE:
+                       message = _("Name in use");
+                       break;
+               case TP_CONNECTION_STATUS_REASON_CERT_NOT_PROVIDED:
+                       message = _("Certificate not provided");
+                       break;
+               case TP_CONNECTION_STATUS_REASON_CERT_UNTRUSTED:
+                       message = _("Certificate untrusted");
+                       break;
+               case TP_CONNECTION_STATUS_REASON_CERT_EXPIRED:
+                       message = _("Certificate expired");
+                       break;
+               case TP_CONNECTION_STATUS_REASON_CERT_NOT_ACTIVATED:
+                       message = _("Certificate not activated");
+                       break;
+               case TP_CONNECTION_STATUS_REASON_CERT_HOSTNAME_MISMATCH:
+                       message = _("Certificate hostname mismatch");
+                       break;
+               case TP_CONNECTION_STATUS_REASON_CERT_FINGERPRINT_MISMATCH:
+                       message = _("Certificate fingerprint mismatch");
+                       break;
+               case TP_CONNECTION_STATUS_REASON_CERT_SELF_SIGNED:
+                       message = _("Certificate self signed");
+                       break;
+               case TP_CONNECTION_STATUS_REASON_CERT_OTHER_ERROR:
+                       message = _("Certificate error");
+                       break;
+               default:
+                       message = _("Unknown error");
+                       break;
+               }
 
-       name = gossip_account_get_name (account);
-       gossip_debug (DEBUG_DOMAIN, "Disconnected account:'%s'", name);
+               main_window_error_display (window, account, message);
+       }
 
-       gossip_session_count_accounts (window->session,
-                                      NULL,
-                                      &connecting,
-                                      NULL);
+       if (status == TP_CONNECTION_STATUS_CONNECTED) {
+               GtkWidget *error_widget;
 
-       if (connecting < 1) {
-               ephy_spinner_stop (EPHY_SPINNER (window->throbber));
+               /* Account connected without error, remove error message if any */
+               error_widget = g_hash_table_lookup (window->errors, account);
+               if (error_widget) {
+                       gtk_widget_destroy (error_widget);
+                       g_hash_table_remove (window->errors, account);
+               }
        }
 
-       app_connection_items_update ();
-       app_favorite_chatroom_menu_update ();
-       app_presence_updated ();
+       g_object_unref (account);
+}
 
-       should_reconnect = reason != GOSSIP_PROTOCOL_DISCONNECT_ASKED;
+static void
+main_window_update_status (EmpathyMainWindow *window)
+{
+       GList *accounts, *l;
+       guint  connected = 0;
+       guint  connecting = 0;
+       guint  disconnected = 0;
+
+       /* Count number of connected/connecting/disconnected accounts */
+       accounts = mc_accounts_list (); 
+       for (l = accounts; l; l = l->next) {
+               McAccount *account;
+               guint      status;
+
+               account = l->data;
+
+               status = mission_control_get_connection_status (window->mc,
+                                                               account,
+                                                               NULL);
+
+               if (status == 0) {
+                       connected++;
+               } else if (status == 1) {
+                       connecting++;
+               } else if (status == 2) {
+                       disconnected++;
+               }
 
+               g_object_unref (account);
+       }
+       g_list_free (accounts);
 
-       should_reconnect &= !g_hash_table_lookup (window->reconnects, account);
+       /* Update the spinner state */
+       if (connecting > 0) {
+               ephy_spinner_start (EPHY_SPINNER (window->throbber));
+       } else {
+               ephy_spinner_stop (EPHY_SPINNER (window->throbber));
+       }
 
-       if (should_reconnect) {
-               guint id;
+       /* Update widgets sensibility */
+       for (l = window->widgets_connected; l; l = l->next) {
+               gtk_widget_set_sensitive (l->data, (connected > 0));
+       }
 
-               /* Unexpected disconnection, try to reconnect */
-               id = g_timeout_add (RETRY_CONNECT_TIMEOUT * 1000,
-                                   (GSourceFunc) app_reconnect_cb,
-                                   account);
-               g_hash_table_insert (window->reconnects,
-                                    g_object_ref (account),
-                                    &id);
+       for (l = window->widgets_disconnected; l; l = l->next) {
+               gtk_widget_set_sensitive (l->data, (disconnected > 0));
        }
 }
-#endif
 
 /*
  * Accels
@@ -675,7 +1009,7 @@ main_window_accels_load (void)
 
        filename = g_build_filename (g_get_home_dir (), ".gnome2", PACKAGE_NAME, ACCELS_FILENAME, NULL);
        if (g_file_test (filename, G_FILE_TEST_EXISTS)) {
-               gossip_debug (DEBUG_DOMAIN, "Loading from:'%s'", filename);
+               empathy_debug (DEBUG_DOMAIN, "Loading from:'%s'", filename);
                gtk_accel_map_load (filename);
        }
 
@@ -693,7 +1027,7 @@ main_window_accels_save (void)
        file_with_path = g_build_filename (dir, ACCELS_FILENAME, NULL);
        g_free (dir);
 
-       gossip_debug (DEBUG_DOMAIN, "Saving to:'%s'", file_with_path);
+       empathy_debug (DEBUG_DOMAIN, "Saving to:'%s'", file_with_path);
        gtk_accel_map_save (file_with_path);
 
        g_free (file_with_path);
@@ -707,14 +1041,12 @@ main_window_connection_items_setup (EmpathyMainWindow *window,
        GtkWidget     *w;
        gint           i;
        const gchar *widgets_connected[] = {
-               "chat_disconnect",
                "room",
                "chat_new_message",
                "chat_add_contact",
                "edit_personal_information"
        };
        const gchar *widgets_disconnected[] = {
-               "chat_connect"
        };
 
        for (i = 0, list = NULL; i < G_N_ELEMENTS (widgets_connected); i++) {
@@ -732,55 +1064,6 @@ main_window_connection_items_setup (EmpathyMainWindow *window,
        window->widgets_disconnected = list;
 }
 
-#if 0
-FIXME:
-static void
-main_window_connection_items_update (void)
-{
-       GList         *l;
-       guint          connected = 0;
-       guint          disconnected = 0;
-
-       /* Get account count for:
-        *  - connected and disabled,
-        *  - connected and enabled
-        *  - disabled and enabled
-        */
-       gossip_session_count_accounts (window->session,
-                                      &connected,
-                                      NULL,
-                                      &disconnected);
-
-       for (l = window->widgets_connected; l; l = l->next) {
-               gtk_widget_set_sensitive (l->data, (connected > 0));
-       }
-
-       for (l = window->widgets_disconnected; l; l = l->next) {
-               gtk_widget_set_sensitive (l->data, (disconnected > 0));
-       }
-}
-#endif
-
-static void
-main_window_presence_changed_cb (DBusGProxy        *proxy,
-                                McPresence         state,
-                                EmpathyMainWindow *window)
-{
-       gossip_debug (DEBUG_DOMAIN, "presence changed to %d", state);
-       gossip_presence_chooser_set_state (GOSSIP_PRESENCE_CHOOSER (window->presence_chooser),
-                                          state);
-}
-
-static void
-main_window_presence_chooser_changed_cb (GtkWidget         *chooser,
-                                        McPresence         state,
-                                        const gchar       *status,
-                                        EmpathyMainWindow *window)
-{
-       gossip_status_presets_set_default (state, status);
-       mission_control_set_presence (window->mc, state, status, NULL, NULL);
-}
-
 static gboolean
 main_window_configure_event_timeout_cb (EmpathyMainWindow *window)
 {
@@ -789,7 +1072,7 @@ main_window_configure_event_timeout_cb (EmpathyMainWindow *window)
        gtk_window_get_size (GTK_WINDOW (window->window), &w, &h);
        gtk_window_get_position (GTK_WINDOW (window->window), &x, &y);
 
-       gossip_geometry_save (GEOMETRY_NAME, x, y, w, h);
+       empathy_geometry_save (GEOMETRY_NAME, x, y, w, h);
 
        window->size_timeout_id = 0;
 
@@ -805,71 +1088,72 @@ main_window_configure_event_cb (GtkWidget         *widget,
                g_source_remove (window->size_timeout_id);
        }
 
-       window->size_timeout_id = g_timeout_add (500,
-                                              (GSourceFunc) main_window_configure_event_timeout_cb,
-                                              window);
+       window->size_timeout_id = g_timeout_add_seconds (1,
+                                                        (GSourceFunc) main_window_configure_event_timeout_cb,
+                                                        window);
 
        return FALSE;
 }
 
 static void
-main_window_notify_show_offline_cb (GossipConf  *conf,
+main_window_notify_show_offline_cb (EmpathyConf  *conf,
                                    const gchar *key,
                                    gpointer     check_menu_item)
 {
        gboolean show_offline;
 
-       if (gossip_conf_get_bool (conf, key, &show_offline)) {
+       if (empathy_conf_get_bool (conf, key, &show_offline)) {
                gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (check_menu_item),
                                                show_offline);
        }
 }
 
 static void
-main_window_notify_show_avatars_cb (GossipConf        *conf,
+main_window_notify_show_avatars_cb (EmpathyConf        *conf,
                                    const gchar       *key,
                                    EmpathyMainWindow *window)
 {
        gboolean show_avatars;
 
-       if (gossip_conf_get_bool (conf, key, &show_avatars)) {
-               gossip_contact_list_set_show_avatars (window->contact_list,
-                                                     show_avatars);
+       if (empathy_conf_get_bool (conf, key, &show_avatars)) {
+               empathy_contact_list_store_set_show_avatars (window->list_store,
+                                                           show_avatars);
        }
 }
 
 static void
-main_window_notify_compact_contact_list_cb (GossipConf        *conf,
+main_window_notify_compact_contact_list_cb (EmpathyConf        *conf,
                                            const gchar       *key,
                                            EmpathyMainWindow *window)
 {
        gboolean compact_contact_list;
 
-       if (gossip_conf_get_bool (conf, key, &compact_contact_list)) {
-               gossip_contact_list_set_is_compact (window->contact_list,
-                                                   compact_contact_list);
+       if (empathy_conf_get_bool (conf, key, &compact_contact_list)) {
+               empathy_contact_list_store_set_is_compact (window->list_store,
+                                                         compact_contact_list);
        }
 }
 
 static void
-main_window_notify_sort_criterium_cb (GossipConf        *conf,
+main_window_notify_sort_criterium_cb (EmpathyConf       *conf,
                                      const gchar       *key,
                                      EmpathyMainWindow *window)
 {
        gchar *str = NULL;
 
-       if (gossip_conf_get_string (conf, key, &str)) {
+       if (empathy_conf_get_string (conf, key, &str) && str) {
                GType       type;
                GEnumClass *enum_class;
                GEnumValue *enum_value;
 
-               type = gossip_contact_list_sort_get_type ();
+               type = empathy_contact_list_store_sort_get_type ();
                enum_class = G_ENUM_CLASS (g_type_class_peek (type));
                enum_value = g_enum_get_value_by_nick (enum_class, str);
+               g_free (str);
 
                if (enum_value) {
-                       gossip_contact_list_set_sort_criterium (window->contact_list
-                                                               enum_value->value);
+                       empathy_contact_list_store_set_sort_criterium (window->list_store
+                                                                      enum_value->value);
                }
        }
 }