]> git.0d.be Git - empathy.git/blobdiff - src/empathy-accounts-dialog.c
Updated Polish translation
[empathy.git] / src / empathy-accounts-dialog.c
index ea61732c4e3b4c4c86fc61dbdcbc124de4e907dc..d8489ee92c261b2acdcf9cfb13ab8134ea29923e 100644 (file)
 #include <glib/gi18n.h>
 #include <dbus/dbus-glib.h>
 
+#include <telepathy-glib/account-manager.h>
+#include <telepathy-glib/defs.h>
 #include <telepathy-glib/util.h>
 
 #include <libempathy/empathy-utils.h>
-#include <libempathy/empathy-account-manager.h>
 #include <libempathy/empathy-connection-managers.h>
+#include <libempathy/empathy-connectivity.h>
 #include <libempathy-gtk/empathy-ui-utils.h>
 
 #include <libempathy-gtk/empathy-protocol-chooser.h>
@@ -50,6 +52,7 @@
 #include "empathy-accounts-dialog.h"
 #include "empathy-import-dialog.h"
 #include "empathy-import-utils.h"
+#include "ephy-spinner.h"
 
 #define DEBUG_FLAG EMPATHY_DEBUG_ACCOUNT
 #include <libempathy/empathy-debug.h>
 /* The primary text of the dialog shown to the user when he is about to lose
  * unsaved changes */
 #define PENDING_CHANGES_QUESTION_PRIMARY_TEXT \
-  _("There are unsaved modification regarding your %s account.")
+  _("There are unsaved modifications to your %s account.")
+/* The primary text of the dialog shown to the user when he is about to lose
+ * an unsaved new account */
+#define UNSAVED_NEW_ACCOUNT_QUESTION_PRIMARY_TEXT \
+  _("Your new account has not been saved yet.")
 
 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyAccountsDialog)
-G_DEFINE_TYPE (EmpathyAccountsDialog, empathy_accounts_dialog, G_TYPE_OBJECT);
-
-static EmpathyAccountsDialog *dialog_singleton = NULL;
+G_DEFINE_TYPE (EmpathyAccountsDialog, empathy_accounts_dialog, GTK_TYPE_DIALOG);
 
 typedef struct {
-  GtkWidget *window;
-
   GtkWidget *alignment_settings;
+  GtkWidget *alignment_infobar;
 
   GtkWidget *vbox_details;
+  GtkWidget *infobar;
+  GtkWidget *label_status;
+  GtkWidget *image_status;
+  GtkWidget *throbber;
   GtkWidget *frame_no_protocol;
 
   GtkWidget *treeview;
 
   GtkWidget *button_add;
+  GtkWidget *button_remove;
   GtkWidget *button_import;
 
-  GtkWidget *frame_new_account;
   GtkWidget *combobox_protocol;
-  GtkWidget *hbox_type;
-  GtkWidget *button_create;
-  GtkWidget *button_back;
-  GtkWidget *radiobutton_reuse;
-  GtkWidget *radiobutton_register;
+  GtkWidget *hbox_protocol;
 
   GtkWidget *image_type;
   GtkWidget *label_name;
@@ -107,11 +111,11 @@ typedef struct {
   gulong  settings_ready_id;
   EmpathyAccountSettings *settings_ready;
 
-  EmpathyAccountManager *account_manager;
+  TpAccountManager *account_manager;
   EmpathyConnectionManagers *cms;
 
   GtkWindow *parent_window;
-  EmpathyAccount *initial_selection;
+  TpAccount *initial_selection;
 
   /* Those are needed when changing the selected row. When a user selects
    * another account and there are unsaved changes on the currently selected
@@ -121,14 +125,14 @@ typedef struct {
   gboolean force_change_row;
   GtkTreeRowReference *destination_row;
 
-
+  gboolean dispose_has_run;
 } EmpathyAccountsDialogPriv;
 
 enum {
   COL_NAME,
   COL_STATUS,
-  COL_ACCOUNT_POINTER,
-  COL_ACCOUNT_SETTINGS_POINTER,
+  COL_ACCOUNT,
+  COL_ACCOUNT_SETTINGS,
   COL_COUNT
 };
 
@@ -136,11 +140,6 @@ enum {
   PROP_PARENT = 1
 };
 
-static void accounts_dialog_account_display_name_changed_cb (
-    EmpathyAccount *account,
-    GParamSpec *pspec,
-    gpointer user_data);
-
 static EmpathyAccountSettings * accounts_dialog_model_get_selected_settings (
     EmpathyAccountsDialog *dialog);
 
@@ -151,12 +150,33 @@ static gboolean accounts_dialog_get_settings_iter (
 
 static void accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog);
 
-static void accounts_dialog_update (EmpathyAccountsDialog *dialog,
+static void accounts_dialog_update_settings (EmpathyAccountsDialog *dialog,
     EmpathyAccountSettings *settings);
 
-static void accounts_dialog_update_settings (EmpathyAccountsDialog *dialog,
+static void accounts_dialog_add (EmpathyAccountsDialog *dialog,
+    EmpathyAccountSettings *settings);
+
+static void accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog,
     EmpathyAccountSettings *settings);
 
+static void accounts_dialog_connection_changed_cb (TpAccount *account,
+    guint old_status,
+    guint current,
+    guint reason,
+    gchar *dbus_error_name,
+    GHashTable *details,
+    EmpathyAccountsDialog *dialog);
+
+static void accounts_dialog_presence_changed_cb (TpAccount *account,
+    guint presence,
+    gchar *status,
+    gchar *status_message,
+    EmpathyAccountsDialog *dialog);
+
+static void accounts_dialog_model_selection_changed (
+    GtkTreeSelection *selection,
+    EmpathyAccountsDialog *dialog);
+
 static void
 accounts_dialog_update_name_label (EmpathyAccountsDialog *dialog,
     const gchar *display_name)
@@ -164,12 +184,168 @@ accounts_dialog_update_name_label (EmpathyAccountsDialog *dialog,
   gchar *text;
   EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
 
-  text = g_markup_printf_escaped ("<big><b>%s</b></big>", display_name);
+  text = g_markup_printf_escaped ("<b>%s</b>", display_name);
   gtk_label_set_markup (GTK_LABEL (priv->label_name), text);
 
   g_free (text);
 }
 
+static void
+accounts_dialog_update_status_infobar (EmpathyAccountsDialog *dialog,
+    TpAccount *account)
+{
+  EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
+  const gchar               *message;
+  gchar                     *message_markup;
+  gchar                     *status_message = NULL;
+  guint                     status;
+  guint                     reason;
+  guint                     presence;
+  EmpathyConnectivity       *connectivity;
+  GtkTreeView               *view;
+  GtkTreeModel              *model;
+  GtkTreeSelection          *selection;
+  GtkTreeIter               iter;
+  TpAccount                 *selected_account;
+  gboolean                  account_enabled;
+  gboolean                  creating_account;
+
+  view = GTK_TREE_VIEW (priv->treeview);
+  selection = gtk_tree_view_get_selection (view);
+
+  if (!gtk_tree_selection_get_selected (selection, &model, &iter))
+    return;
+
+  gtk_tree_model_get (model, &iter, COL_ACCOUNT, &selected_account, -1);
+  if (selected_account != NULL)
+    g_object_unref (selected_account);
+
+  /* do not update the infobar when the account is not selected */
+  if (account != selected_account)
+    return;
+
+  if (account != NULL)
+    {
+      status = tp_account_get_connection_status (account, &reason);
+      presence = tp_account_get_current_presence (account, NULL, &status_message);
+      account_enabled = tp_account_is_enabled (account);
+      creating_account = FALSE;
+
+      if (status == TP_CONNECTION_STATUS_CONNECTED &&
+          (presence == TP_CONNECTION_PRESENCE_TYPE_OFFLINE ||
+           presence == TP_CONNECTION_PRESENCE_TYPE_UNSET))
+        /* If presence is Unset (CM doesn't implement SimplePresence) but we
+         * are connected, consider ourself as Available.
+         * We also check Offline because of this MC5 bug: fd.o #26060 */
+        presence = TP_CONNECTION_PRESENCE_TYPE_AVAILABLE;
+
+      /* set presence to offline if account is disabled
+       * (else no icon is shown in infobar)*/
+      if (!account_enabled)
+        presence = TP_CONNECTION_PRESENCE_TYPE_OFFLINE;
+    }
+  else
+    {
+      status = TP_CONNECTION_STATUS_DISCONNECTED;
+      presence = TP_CONNECTION_PRESENCE_TYPE_OFFLINE;
+      account_enabled = FALSE;
+      creating_account = TRUE;
+    }
+
+  gtk_image_set_from_icon_name (GTK_IMAGE (priv->image_status),
+      empathy_icon_name_for_presence (presence), GTK_ICON_SIZE_SMALL_TOOLBAR);
+
+  if (account_enabled)
+    {
+      switch (status)
+        {
+          case TP_CONNECTION_STATUS_CONNECTING:
+            message = _("Connecting…");
+            gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
+                GTK_MESSAGE_INFO);
+
+            ephy_spinner_start (EPHY_SPINNER (priv->throbber));
+            gtk_widget_show (priv->throbber);
+            gtk_widget_hide (priv->image_status);
+            break;
+          case TP_CONNECTION_STATUS_CONNECTED:
+            if (g_strcmp0 (status_message, "") == 0)
+              {
+                message = g_strdup_printf ("%s",
+                    empathy_presence_get_default_message (presence));
+              }
+            else
+              {
+                message = g_strdup_printf ("%s — %s",
+                    empathy_presence_get_default_message (presence),
+                    status_message);
+              }
+            gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
+                GTK_MESSAGE_INFO);
+
+            gtk_widget_show (priv->image_status);
+            gtk_widget_hide (priv->throbber);
+            break;
+          case TP_CONNECTION_STATUS_DISCONNECTED:
+            message = g_strdup_printf (_("Disconnected — %s"),
+                empathy_status_reason_get_default_message (reason));
+
+            if (reason == TP_CONNECTION_STATUS_REASON_REQUESTED)
+              {
+                message = g_strdup_printf (_("Offline — %s"),
+                    empathy_status_reason_get_default_message (reason));
+                gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
+                    GTK_MESSAGE_WARNING);
+              }
+            else
+              {
+                gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
+                    GTK_MESSAGE_ERROR);
+              }
+
+            connectivity = empathy_connectivity_dup_singleton ();
+            if (!empathy_connectivity_is_online (connectivity))
+               message = _("Offline — No Network Connection");
+
+            g_object_unref (connectivity);
+            ephy_spinner_stop (EPHY_SPINNER (priv->throbber));
+            gtk_widget_show (priv->image_status);
+            gtk_widget_hide (priv->throbber);
+            break;
+          default:
+            message = _("Unknown Status");
+            gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
+                GTK_MESSAGE_WARNING);
+
+            ephy_spinner_stop (EPHY_SPINNER (priv->throbber));
+            gtk_widget_hide (priv->image_status);
+            gtk_widget_hide (priv->throbber);
+        }
+    }
+  else
+    {
+      message = _("Offline — Account Disabled");
+
+      gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
+          GTK_MESSAGE_WARNING);
+      ephy_spinner_stop (EPHY_SPINNER (priv->throbber));
+      gtk_widget_show (priv->image_status);
+      gtk_widget_hide (priv->throbber);
+    }
+
+  message_markup = g_markup_printf_escaped ("<i>%s</i>", message);
+  gtk_label_set_markup (GTK_LABEL (priv->label_status), message_markup);
+  gtk_widget_show (priv->label_status);
+
+  if (!creating_account)
+    gtk_widget_show (priv->infobar);
+  else
+    gtk_widget_hide (priv->infobar);
+
+  g_free (status_message);
+  g_free (message_markup);
+}
+
 static void
 empathy_account_dialog_widget_cancelled_cb (
     EmpathyAccountWidget *widget_object,
@@ -180,7 +356,7 @@ empathy_account_dialog_widget_cancelled_cb (
   GtkTreeSelection *selection;
   GtkTreeIter iter;
   EmpathyAccountSettings *settings;
-  EmpathyAccount *account;
+  TpAccount *account;
   EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
 
   view = GTK_TREE_VIEW (priv->treeview);
@@ -190,8 +366,8 @@ empathy_account_dialog_widget_cancelled_cb (
     return;
 
   gtk_tree_model_get (model, &iter,
-      COL_ACCOUNT_SETTINGS_POINTER, &settings,
-      COL_ACCOUNT_POINTER, &account, -1);
+      COL_ACCOUNT_SETTINGS, &settings,
+      COL_ACCOUNT, &account, -1);
 
   empathy_account_widget_discard_pending_changes (priv->setting_widget_object);
 
@@ -208,90 +384,82 @@ empathy_account_dialog_widget_cancelled_cb (
       g_object_unref (account);
     }
 
+  gtk_widget_set_sensitive (priv->treeview, TRUE);
+  gtk_widget_set_sensitive (priv->button_add, TRUE);
+  gtk_widget_set_sensitive (priv->button_remove, TRUE);
+  gtk_widget_set_sensitive (priv->button_import, TRUE);
+
   if (settings != NULL)
     g_object_unref (settings);
 }
 
-static gchar *
-get_default_display_name (EmpathyAccountSettings *settings)
-{
-  const gchar *login_id;
-  const gchar *protocol;
-  gchar *default_display_name;
-
-  login_id = empathy_account_settings_get_string (settings, "account");
-  protocol = empathy_account_settings_get_protocol (settings);
-
-  if (login_id != NULL)
-    {
-      if (!tp_strdiff (protocol, "irc"))
-        {
-          const gchar* server;
-          server = empathy_account_settings_get_string (settings, "server");
-
-          /* To translators: The first parameter is the login id and the
-           * second one is the server. The resulting string will be something
-           * like: "MyUserName on chat.freenode.net".
-           * You should reverse the order of these arguments if the
-           * server should come before the login id in your locale.*/
-          default_display_name = g_strdup_printf (_("%1$s on %2$s"),
-              login_id, server);
-        }
-      else
-        {
-          default_display_name = g_strdup (login_id);
-        }
-    }
-  else if (protocol != NULL)
-    {
-      /* To translators: The parameter is the protocol name. The resulting
-       * string will be something like: "Jabber Account" */
-      default_display_name = g_strdup_printf (_("%s Account"), protocol);
-    }
-  else
-    {
-      default_display_name = g_strdup (_("New account"));
-    }
-
-  return default_display_name;
-}
-
 static void
 empathy_account_dialog_account_created_cb (EmpathyAccountWidget *widget_object,
+    TpAccount *account,
     EmpathyAccountsDialog *dialog)
 {
-  gchar *display_name;
   EmpathyAccountSettings *settings =
       accounts_dialog_model_get_selected_settings (dialog);
+  EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
 
-  display_name = get_default_display_name (settings);
-
-  empathy_account_settings_set_display_name_async (settings,
-      display_name, NULL, NULL);
+  accounts_dialog_update_settings (dialog, settings);
+  accounts_dialog_update_status_infobar (dialog,
+      empathy_account_settings_get_account (settings));
 
-  g_free (display_name);
+  gtk_widget_set_sensitive (priv->treeview, TRUE);
+  gtk_widget_set_sensitive (priv->button_add, TRUE);
+  gtk_widget_set_sensitive (priv->button_remove, TRUE);
+  gtk_widget_set_sensitive (priv->button_import, TRUE);
 
-  accounts_dialog_update_settings (dialog, settings);
+  empathy_signal_connect_weak (account, "status-changed",
+      G_CALLBACK (accounts_dialog_connection_changed_cb), G_OBJECT (dialog));
+  empathy_signal_connect_weak (account, "presence-changed",
+      G_CALLBACK (accounts_dialog_presence_changed_cb), G_OBJECT (dialog));
 
   if (settings)
     g_object_unref (settings);
 }
 
+static gboolean
+accounts_dialog_has_valid_accounts (EmpathyAccountsDialog *dialog)
+{
+  EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
+  GtkTreeModel *model;
+  GtkTreeIter iter;
+  gboolean creating;
+
+  g_object_get (priv->setting_widget_object,
+      "creating-account", &creating, NULL);
+
+  if (!creating)
+    return TRUE;
+
+  model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
+
+  if (gtk_tree_model_get_iter_first (model, &iter))
+    return gtk_tree_model_iter_next (model, &iter);
+
+  return FALSE;
+}
+
 static void
 account_dialog_create_settings_widget (EmpathyAccountsDialog *dialog,
     EmpathyAccountSettings *settings)
 {
   EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
-  gchar *icon_name;
+  gchar                     *icon_name;
+  TpAccount                 *account;
 
   priv->setting_widget_object =
       empathy_account_widget_new_for_protocol (settings, FALSE);
 
-  priv->settings_widget =
-      empathy_account_widget_get_widget (priv->setting_widget_object);
+  if (accounts_dialog_has_valid_accounts (dialog))
+    empathy_account_widget_set_other_accounts_exist (
+        priv->setting_widget_object, TRUE);
 
   priv->settings_widget =
       empathy_account_widget_get_widget (priv->setting_widget_object);
+
   g_signal_connect (priv->setting_widget_object, "account-created",
         G_CALLBACK (empathy_account_dialog_account_created_cb), dialog);
   g_signal_connect (priv->setting_widget_object, "cancelled",
@@ -319,6 +487,9 @@ account_dialog_create_settings_widget (EmpathyAccountsDialog *dialog,
 
   accounts_dialog_update_name_label (dialog,
       empathy_account_settings_get_display_name (settings));
+
+  account = empathy_account_settings_get_account (settings);
+  accounts_dialog_update_status_infobar (dialog, account);
 }
 
 static void
@@ -356,7 +527,7 @@ accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog)
 
 static gboolean
 accounts_dialog_has_pending_change (EmpathyAccountsDialog *dialog,
-    EmpathyAccount **account)
+    TpAccount **account)
 {
   GtkTreeIter iter;
   GtkTreeModel *model;
@@ -366,79 +537,136 @@ accounts_dialog_has_pending_change (EmpathyAccountsDialog *dialog,
   selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
 
   if (gtk_tree_selection_get_selected (selection, &model, &iter))
-    gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, account, -1);
+    gtk_tree_model_get (model, &iter, COL_ACCOUNT, account, -1);
 
-  return *account != NULL && priv->setting_widget_object != NULL
+  return priv->setting_widget_object != NULL
       && empathy_account_widget_contains_pending_changes (
           priv->setting_widget_object);
 }
 
 static void
-accounts_dialog_protocol_changed_cb (GtkWidget *widget,
-    EmpathyAccountsDialog *dialog)
+accounts_dialog_setup_ui_to_add_account (EmpathyAccountsDialog *dialog)
 {
+  EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
+  EmpathyAccountSettings *settings;
+  gchar *str;
+  const gchar *name, *display_name;
   TpConnectionManager *cm;
   TpConnectionManagerProtocol *proto;
-  gboolean is_gtalk;
-  EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
+  gboolean is_gtalk, is_facebook;
 
   cm = empathy_protocol_chooser_dup_selected (
-      EMPATHY_PROTOCOL_CHOOSER (priv->combobox_protocol), &proto, &is_gtalk);
-
+      EMPATHY_PROTOCOL_CHOOSER (priv->combobox_protocol), &proto, &is_gtalk,
+      &is_facebook);
   if (cm == NULL)
     return;
 
-  if (proto == NULL)
-    {
-      g_object_unref (cm);
-      return;
-    }
-
-#ifndef HAVE_MOBLIN
-  if (tp_connection_manager_protocol_can_register (proto) && !is_gtalk)
-    {
-      gtk_widget_show (priv->radiobutton_register);
-      gtk_widget_show (priv->radiobutton_reuse);
-    }
+  if (is_gtalk)
+    name = "gtalk";
+  else if (is_facebook)
+    name ="facebook";
   else
-    {
-      gtk_widget_hide (priv->radiobutton_register);
-      gtk_widget_hide (priv->radiobutton_reuse);
-    }
-#else
-  gtk_widget_hide (priv->radiobutton_register);
-  gtk_widget_hide (priv->radiobutton_reuse);
-#endif
+    name = proto->name;
+
+  display_name = empathy_protocol_name_to_display_name (name);
+  if (display_name == NULL)
+    display_name = proto->name;
+
+  /* Create account */
+  /* To translator: %s is the name of the protocol, such as "Google Talk" or
+   * "Yahoo!"
+   */
+  str = g_strdup_printf (_("New %s account"), display_name);
+  settings = empathy_account_settings_new (cm->name, proto->name, str);
+
+  g_free (str);
+
+  if (is_gtalk)
+    empathy_account_settings_set_icon_name_async (settings, "im-google-talk",
+        NULL, NULL);
+  else if (is_facebook)
+    empathy_account_settings_set_icon_name_async (settings, "im-facebook",
+        NULL, NULL);
+
+  accounts_dialog_add (dialog, settings);
+  accounts_dialog_model_set_selected (dialog, settings);
+
+  gtk_widget_show_all (priv->hbox_protocol);
 
+  g_object_unref (settings);
   g_object_unref (cm);
 }
 
 static void
-accounts_dialog_setup_ui_to_add_account (EmpathyAccountsDialog *dialog)
+accounts_dialog_protocol_changed_cb (GtkWidget *widget,
+    EmpathyAccountsDialog *dialog)
 {
-  GtkTreeView *view;
-  GtkTreeModel *model;
   EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
+  GtkTreeSelection *selection;
+  GtkTreeModel *model;
+  GtkTreeIter iter;
+  gboolean creating;
+  EmpathyAccountSettings *settings;
+  gchar *account = NULL, *password = NULL;
 
-  view = GTK_TREE_VIEW (priv->treeview);
-  model = gtk_tree_view_get_model (view);
+  /* The "changed" signal is fired during the initiation of the
+   * EmpathyProtocolChooser while populating the widget. Such signals should
+   * be ignored so we check if we are actually creating a new account. */
+  if (priv->setting_widget_object == NULL)
+    return;
 
-  gtk_widget_set_sensitive (priv->button_add, FALSE);
-  gtk_widget_hide (priv->vbox_details);
-  gtk_widget_hide (priv->frame_no_protocol);
-  gtk_widget_show (priv->frame_new_account);
+  g_object_get (priv->setting_widget_object,
+      "creating-account", &creating, NULL);
+  if (!creating)
+    return;
 
-  /* If we have no account, no need of a back button */
-  if (gtk_tree_model_iter_n_children (model, NULL) > 0)
-    gtk_widget_show (priv->button_back);
-  else
-    gtk_widget_hide (priv->button_back);
+  selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
+
+  if (!gtk_tree_selection_get_selected (selection, &model, &iter))
+    return;
+
+  /* Save "account" and "password" parameters */
+  g_object_get (priv->setting_widget_object, "settings", &settings, NULL);
+
+  if (settings != NULL)
+    {
+      account = g_strdup (empathy_account_settings_get_string (settings,
+            "account"));
+      password = g_strdup (empathy_account_settings_get_string (settings,
+            "password"));
+      g_object_unref (settings);
+    }
 
-  accounts_dialog_protocol_changed_cb (priv->radiobutton_register, dialog);
-  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->radiobutton_reuse),
-      TRUE);
-  gtk_combo_box_set_active (GTK_COMBO_BOX (priv->combobox_protocol), 0);
-  gtk_widget_grab_focus (priv->combobox_protocol);
+  /* We are creating a new widget to replace the current one, don't ask
+   * confirmation to the user. */
+  priv->force_change_row = TRUE;
+
+  /* We'll update the selection after we create the new account widgets;
+   * updating it right now causes problems for the # of accounts = zero case */
+  g_signal_handlers_block_by_func (selection,
+      accounts_dialog_model_selection_changed, dialog);
+
+  gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
+
+  g_signal_handlers_unblock_by_func (selection,
+      accounts_dialog_model_selection_changed, dialog);
+
+  accounts_dialog_setup_ui_to_add_account (dialog);
+
+  /* Restore "account" and "password" parameters in the new widget */
+  if (account != NULL)
+    {
+      empathy_account_widget_set_account_param (priv->setting_widget_object,
+          account);
+      g_free (account);
+    }
+
+  if (password != NULL)
+    {
+      empathy_account_widget_set_password_param (priv->setting_widget_object,
+          password);
+      g_free (password);
+    }
 }
 
 static void
@@ -453,9 +681,8 @@ accounts_dialog_show_question_dialog (EmpathyAccountsDialog *dialog,
   va_list button_args;
   GtkWidget *message_dialog;
   const gchar *button_text;
-  EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
 
-  message_dialog = gtk_message_dialog_new (GTK_WINDOW (priv->window),
+  message_dialog = gtk_message_dialog_new (GTK_WINDOW (dialog),
       GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
       GTK_MESSAGE_QUESTION,
       GTK_BUTTONS_NONE,
@@ -500,17 +727,32 @@ accounts_dialog_add_pending_changes_response_cb (GtkDialog *message_dialog,
     }
 }
 
+static gchar *
+get_dialog_primary_text (TpAccount *account)
+{
+  if (account != NULL)
+    {
+      /* Existing account */
+      return g_strdup_printf (PENDING_CHANGES_QUESTION_PRIMARY_TEXT,
+          tp_account_get_display_name (account));
+    }
+  else
+    {
+      /* Newly created account */
+      return g_strdup (UNSAVED_NEW_ACCOUNT_QUESTION_PRIMARY_TEXT);
+    }
+}
+
 static void
 accounts_dialog_button_add_clicked_cb (GtkWidget *button,
     EmpathyAccountsDialog *dialog)
 {
-  EmpathyAccount *account = NULL;
+  TpAccount *account = NULL;
+  EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
 
   if (accounts_dialog_has_pending_change (dialog, &account))
     {
-      gchar *question_dialog_primary_text = g_strdup_printf (
-          PENDING_CHANGES_QUESTION_PRIMARY_TEXT,
-          empathy_account_get_display_name (account));
+      gchar *question_dialog_primary_text = get_dialog_primary_text (account);
 
       accounts_dialog_show_question_dialog (dialog,
           question_dialog_primary_text,
@@ -526,7 +768,14 @@ accounts_dialog_button_add_clicked_cb (GtkWidget *button,
   else
     {
       accounts_dialog_setup_ui_to_add_account (dialog);
+      gtk_widget_set_sensitive (priv->treeview, FALSE);
+      gtk_widget_set_sensitive (priv->button_add, FALSE);
+      gtk_widget_set_sensitive (priv->button_remove, FALSE);
+      gtk_widget_set_sensitive (priv->button_import, FALSE);
     }
+
+  if (account != NULL)
+    g_object_unref (account);
 }
 
 static void
@@ -547,14 +796,19 @@ accounts_dialog_update_settings (EmpathyAccountsDialog *dialog,
     {
       GtkTreeView  *view;
       GtkTreeModel *model;
+      GtkTreeSelection *selection;
 
       view = GTK_TREE_VIEW (priv->treeview);
       model = gtk_tree_view_get_model (view);
+      selection = gtk_tree_view_get_selection (view);
 
       if (gtk_tree_model_iter_n_children (model, NULL) > 0)
         {
-          /* We have configured accounts, select the first one */
-          accounts_dialog_model_select_first (dialog);
+          /* We have configured accounts, select the first one if there
+           * is no other account selected already. */
+          if (!gtk_tree_selection_get_selected (selection, NULL, NULL))
+            accounts_dialog_model_select_first (dialog);
+
           return;
         }
       if (empathy_connection_managers_get_cms_num (priv->cms) > 0)
@@ -569,7 +823,6 @@ accounts_dialog_update_settings (EmpathyAccountsDialog *dialog,
 
       /* No account and no profile, warn the user */
       gtk_widget_hide (priv->vbox_details);
-      gtk_widget_hide (priv->frame_new_account);
       gtk_widget_show (priv->frame_no_protocol);
       gtk_widget_set_sensitive (priv->button_add, FALSE);
       return;
@@ -577,10 +830,9 @@ accounts_dialog_update_settings (EmpathyAccountsDialog *dialog,
 
   /* We have an account selected, destroy old settings and create a new
    * one for the account selected */
-  gtk_widget_hide (priv->frame_new_account);
   gtk_widget_hide (priv->frame_no_protocol);
   gtk_widget_show (priv->vbox_details);
-  gtk_widget_set_sensitive (priv->button_add, TRUE);
+  gtk_widget_hide (priv->hbox_protocol);
 
   if (priv->settings_widget)
     {
@@ -616,8 +868,77 @@ accounts_dialog_name_editing_started_cb (GtkCellRenderer *renderer,
   DEBUG ("Editing account name started; stopping flashing");
 }
 
+static const gchar *
+get_status_icon_for_account (EmpathyAccountsDialog *self,
+    TpAccount *account)
+{
+  EmpathyAccountsDialogPriv *priv = GET_PRIV (self);
+  TpConnectionStatus status;
+  TpConnectionStatusReason reason;
+  TpConnectionPresenceType presence;
+
+  if (account == NULL)
+    return empathy_icon_name_for_presence (TP_CONNECTION_PRESENCE_TYPE_OFFLINE);
+
+  if (!tp_account_is_enabled (account))
+    return empathy_icon_name_for_presence (TP_CONNECTION_PRESENCE_TYPE_OFFLINE);
+
+  status = tp_account_get_connection_status (account, &reason);
+
+  if (status == TP_CONNECTION_STATUS_DISCONNECTED)
+    {
+      if (reason != TP_CONNECTION_STATUS_REASON_REQUESTED)
+        /* An error occured */
+        return GTK_STOCK_DIALOG_ERROR;
+
+      presence = TP_CONNECTION_PRESENCE_TYPE_OFFLINE;
+    }
+  else if (status == TP_CONNECTION_STATUS_CONNECTING)
+    {
+      /* Account is connecting. Display a blinking account alternating between
+       * the offline icon and the requested presence. */
+      if (priv->connecting_show)
+        presence = tp_account_get_requested_presence (account, NULL, NULL);
+      else
+        presence = TP_CONNECTION_PRESENCE_TYPE_OFFLINE;
+    }
+  else
+    {
+      /* status == TP_CONNECTION_STATUS_CONNECTED */
+      presence = tp_account_get_current_presence (account, NULL, NULL);
+
+      /* If presence is Unset (CM doesn't implement SimplePresence),
+       * display the 'available' icon.
+       * We also check Offline because of this MC5 bug: fd.o #26060 */
+      if (presence == TP_CONNECTION_PRESENCE_TYPE_OFFLINE ||
+          presence == TP_CONNECTION_PRESENCE_TYPE_UNSET)
+        presence = TP_CONNECTION_PRESENCE_TYPE_AVAILABLE;
+    }
+
+  return empathy_icon_name_for_presence (presence);
+}
+
+static void
+accounts_dialog_model_status_pixbuf_data_func (GtkTreeViewColumn *tree_column,
+    GtkCellRenderer *cell,
+    GtkTreeModel *model,
+    GtkTreeIter *iter,
+    EmpathyAccountsDialog *dialog)
+{
+  TpAccount *account;
+
+  gtk_tree_model_get (model, iter, COL_ACCOUNT, &account, -1);
+
+  g_object_set (cell,
+      "icon-name", get_status_icon_for_account (dialog, account),
+      NULL);
+
+  if (account != NULL)
+    g_object_unref (account);
+}
+
 static void
-accounts_dialog_model_pixbuf_data_func (GtkTreeViewColumn *tree_column,
+accounts_dialog_model_protocol_pixbuf_data_func (GtkTreeViewColumn *tree_column,
     GtkCellRenderer *cell,
     GtkTreeModel *model,
     GtkTreeIter *iter,
@@ -627,39 +948,15 @@ accounts_dialog_model_pixbuf_data_func (GtkTreeViewColumn *tree_column,
   gchar              *icon_name;
   GdkPixbuf          *pixbuf;
   TpConnectionStatus  status;
-  EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
 
   gtk_tree_model_get (model, iter,
       COL_STATUS, &status,
-      COL_ACCOUNT_SETTINGS_POINTER, &settings,
+      COL_ACCOUNT_SETTINGS, &settings,
       -1);
 
   icon_name = empathy_account_settings_get_icon_name (settings);
   pixbuf = empathy_pixbuf_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON);
 
-  if (pixbuf)
-    {
-      if (status == TP_CONNECTION_STATUS_DISCONNECTED ||
-          (status == TP_CONNECTION_STATUS_CONNECTING &&
-              !priv->connecting_show))
-        {
-          GdkPixbuf *modded_pixbuf;
-
-          modded_pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
-              TRUE,
-              8,
-              gdk_pixbuf_get_width (pixbuf),
-              gdk_pixbuf_get_height (pixbuf));
-
-          gdk_pixbuf_saturate_and_pixelate (pixbuf,
-              modded_pixbuf,
-              1.0,
-              TRUE);
-          g_object_unref (pixbuf);
-          pixbuf = modded_pixbuf;
-        }
-    }
-
   g_object_set (cell,
       "visible", TRUE,
       "pixbuf", pixbuf,
@@ -710,9 +1007,11 @@ accounts_dialog_name_edited_cb (GtkCellRendererText *renderer,
   GtkTreePath  *treepath;
   GtkTreeIter   iter;
   EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
+  gboolean connecting;
 
-  if (empathy_account_manager_get_connecting_accounts
-      (priv->account_manager) > 0)
+  empathy_account_manager_get_accounts_connected (&connecting);
+
+  if (connecting)
     {
       priv->connecting_id = g_timeout_add (FLASH_TIMEOUT,
           (GSourceFunc) accounts_dialog_flash_connecting_cb,
@@ -723,7 +1022,7 @@ accounts_dialog_name_edited_cb (GtkCellRendererText *renderer,
   treepath = gtk_tree_path_new_from_string (path);
   gtk_tree_model_get_iter (model, &iter, treepath);
   gtk_tree_model_get (model, &iter,
-      COL_ACCOUNT_SETTINGS_POINTER, &settings,
+      COL_ACCOUNT_SETTINGS, &settings,
       -1);
   gtk_list_store_set (GTK_LIST_STORE (model), &iter,
       COL_NAME, new_text,
@@ -741,7 +1040,7 @@ accounts_dialog_delete_account_response_cb (GtkDialog *message_dialog,
   gint response_id,
   gpointer user_data)
 {
-  EmpathyAccount *account;
+  TpAccount *account;
   GtkTreeModel *model;
   GtkTreeIter iter;
   GtkTreeSelection *selection;
@@ -755,18 +1054,26 @@ accounts_dialog_delete_account_response_cb (GtkDialog *message_dialog,
       if (!gtk_tree_selection_get_selected (selection, &model, &iter))
         return;
 
-      gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, &account, -1);
+      gtk_tree_model_get (model, &iter, COL_ACCOUNT, &account, -1);
 
       if (account != NULL)
         {
-          g_signal_handlers_disconnect_by_func (account,
-              accounts_dialog_account_display_name_changed_cb, account_dialog);
-          empathy_account_remove_async (account, NULL, NULL);
+          tp_account_remove_async (account, NULL, NULL);
           g_object_unref (account);
           account = NULL;
         }
 
+      /* No need to call accounts_dialog_model_selection_changed while
+       * removing as we are going to call accounts_dialog_model_select_first
+       * right after which will update the selection. */
+      g_signal_handlers_block_by_func (selection,
+          accounts_dialog_model_selection_changed, account_dialog);
+
       gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
+
+      g_signal_handlers_unblock_by_func (selection,
+          accounts_dialog_model_selection_changed, account_dialog);
+
       accounts_dialog_model_select_first (account_dialog);
     }
 
@@ -774,74 +1081,88 @@ accounts_dialog_delete_account_response_cb (GtkDialog *message_dialog,
 }
 
 static void
-accounts_dialog_view_delete_activated_cb (EmpathyCellRendererActivatable *cell,
-    const gchar *path_string,
-    EmpathyAccountsDialog *dialog)
+accounts_dialog_remove_account_iter (EmpathyAccountsDialog *dialog,
+    GtkTreeIter *iter)
 {
-  EmpathyAccount *account;
+  EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
+  TpAccount *account;
   GtkTreeModel *model;
-  GtkTreeIter iter;
   gchar *question_dialog_primary_text;
-  EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
 
   model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
 
-  if (!gtk_tree_model_get_iter_from_string (model, &iter, path_string))
-    return;
-
-  gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, &account, -1);
+  gtk_tree_model_get (model, iter, COL_ACCOUNT, &account, -1);
 
-  if (account == NULL || !empathy_account_is_valid (account))
+  if (account == NULL || !tp_account_is_valid (account))
     {
-      gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
+      if (account != NULL)
+        g_object_unref (account);
+      gtk_list_store_remove (GTK_LIST_STORE (model), iter);
       accounts_dialog_model_select_first (dialog);
       return;
     }
 
   question_dialog_primary_text = g_strdup_printf (
-#ifndef HAVE_MOBLIN
-      _("You are about to remove your %s account!\n"
-          "Are you sure you want to proceed?"),
-#else
-      /* Translators: this is used only when built on a moblin platform */
       _("Do you want to remove %s from your computer?"),
-#endif /* HAVE_MOBLIN */
-      empathy_account_get_display_name (account));
+      tp_account_get_display_name (account));
 
   accounts_dialog_show_question_dialog (dialog, question_dialog_primary_text,
-#ifndef HAVE_MOBLIN
-      _("Any associated conversations and chat rooms will NOT be "
-          "removed if you decide to proceed.\n"
-          "\n"
-          "Should you decide to add the account back at a later time, "
-          "they will still be available."),
-#else
-      /* Translators: this is used only when built on a moblin platform */
       _("This will not remove your account on the server."),
-#endif /* HAVE_MOBLIN */
       G_CALLBACK (accounts_dialog_delete_account_response_cb),
       dialog,
       GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
       GTK_STOCK_REMOVE, GTK_RESPONSE_YES, NULL);
 
   g_free (question_dialog_primary_text);
-
-  if (account != NULL)
-    {
-      g_object_unref (account);
-      account = NULL;
-    }
+  g_object_unref (account);
 }
 
 static void
-accounts_dialog_model_add_columns (EmpathyAccountsDialog *dialog)
+accounts_dialog_button_remove_clicked_cb (GtkWidget *button,
+    EmpathyAccountsDialog *dialog)
 {
-  GtkTreeView       *view;
-  GtkTreeViewColumn *column;
-  GtkCellRenderer   *cell;
   EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
-
-  view = GTK_TREE_VIEW (priv->treeview);
+  GtkTreeView  *view;
+  GtkTreeModel *model;
+  GtkTreeSelection *selection;
+  GtkTreeIter iter;
+
+  view = GTK_TREE_VIEW (priv->treeview);
+  model = gtk_tree_view_get_model (view);
+  selection = gtk_tree_view_get_selection (view);
+  if (!gtk_tree_selection_get_selected (selection, NULL, &iter))
+      return;
+
+  accounts_dialog_remove_account_iter (dialog, &iter);
+}
+
+#ifdef HAVE_MEEGO
+static void
+accounts_dialog_view_delete_activated_cb (EmpathyCellRendererActivatable *cell,
+    const gchar *path_string,
+    EmpathyAccountsDialog *dialog)
+{
+  EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
+  GtkTreeModel *model;
+  GtkTreeIter iter;
+
+  model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
+  if (!gtk_tree_model_get_iter_from_string (model, &iter, path_string))
+    return;
+
+  accounts_dialog_remove_account_iter (dialog, &iter);
+}
+#endif /* HAVE_MEEGO */
+
+static void
+accounts_dialog_model_add_columns (EmpathyAccountsDialog *dialog)
+{
+  GtkTreeView       *view;
+  GtkTreeViewColumn *column;
+  GtkCellRenderer   *cell;
+  EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
+
+  view = GTK_TREE_VIEW (priv->treeview);
   gtk_tree_view_set_headers_visible (view, FALSE);
 
   /* Account column */
@@ -849,17 +1170,23 @@ accounts_dialog_model_add_columns (EmpathyAccountsDialog *dialog)
   gtk_tree_view_column_set_expand (column, TRUE);
   gtk_tree_view_append_column (view, column);
 
-  /* Icon renderer */
+  /* Status icon renderer */
   cell = gtk_cell_renderer_pixbuf_new ();
   gtk_tree_view_column_pack_start (column, cell, FALSE);
   gtk_tree_view_column_set_cell_data_func (column, cell,
       (GtkTreeCellDataFunc)
-      accounts_dialog_model_pixbuf_data_func,
+      accounts_dialog_model_status_pixbuf_data_func,
+      dialog,
+      NULL);
+
+  /* Protocol icon renderer */
+  cell = gtk_cell_renderer_pixbuf_new ();
+  gtk_tree_view_column_pack_start (column, cell, FALSE);
+  gtk_tree_view_column_set_cell_data_func (column, cell,
+      (GtkTreeCellDataFunc)
+      accounts_dialog_model_protocol_pixbuf_data_func,
       dialog,
       NULL);
-#ifdef HAVE_MOBLIN
-  g_object_set (cell, "ypad", 4, NULL);
-#endif
 
   /* Name renderer */
   cell = gtk_cell_renderer_text_new ();
@@ -876,20 +1203,21 @@ accounts_dialog_model_add_columns (EmpathyAccountsDialog *dialog)
   g_signal_connect (cell, "editing-started",
       G_CALLBACK (accounts_dialog_name_editing_started_cb),
       dialog);
+  g_object_set (cell, "ypad", 4, NULL);
 
+#ifdef HAVE_MEEGO
   /* Delete column */
   cell = empathy_cell_renderer_activatable_new ();
   gtk_tree_view_column_pack_start (column, cell, FALSE);
   g_object_set (cell,
         "icon-name", GTK_STOCK_DELETE,
-#ifdef HAVE_MOBLIN
         "show-on-select", TRUE,
-#endif
         NULL);
 
   g_signal_connect (cell, "path-activated",
       G_CALLBACK (accounts_dialog_view_delete_activated_cb),
       dialog);
+#endif /* HAVE_MEEGO */
 }
 
 static EmpathyAccountSettings *
@@ -909,7 +1237,7 @@ accounts_dialog_model_get_selected_settings (EmpathyAccountsDialog *dialog)
     return NULL;
 
   gtk_tree_model_get (model, &iter,
-      COL_ACCOUNT_SETTINGS_POINTER, &settings, -1);
+      COL_ACCOUNT_SETTINGS, &settings, -1);
 
   return settings;
 }
@@ -918,10 +1246,12 @@ static void
 accounts_dialog_model_selection_changed (GtkTreeSelection *selection,
     EmpathyAccountsDialog *dialog)
 {
+  EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
   EmpathyAccountSettings *settings;
   GtkTreeModel *model;
   GtkTreeIter   iter;
   gboolean      is_selection;
+  gboolean creating = FALSE;
 
   is_selection = gtk_tree_selection_get_selected (selection, &model, &iter);
 
@@ -930,6 +1260,15 @@ accounts_dialog_model_selection_changed (GtkTreeSelection *selection,
 
   if (settings != NULL)
     g_object_unref (settings);
+
+  if (priv->setting_widget_object != NULL)
+    {
+      g_object_get (priv->setting_widget_object,
+          "creating-account", &creating, NULL);
+    }
+
+  /* Update remove button sensitivity */
+  gtk_widget_set_sensitive (priv->button_remove, is_selection && !creating);
 }
 
 static void
@@ -981,9 +1320,10 @@ accounts_dialog_account_selection_change (GtkTreeSelection *selection,
     gboolean path_currently_selected,
     gpointer data)
 {
-  EmpathyAccount *account = NULL;
+  TpAccount *account = NULL;
   EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (data);
   EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
+  gboolean ret;
 
   if (priv->force_change_row)
     {
@@ -999,13 +1339,9 @@ accounts_dialog_account_selection_change (GtkTreeSelection *selection,
       /* The currently selected account has some unsaved changes. We ask
        * the user if he really wants to lose his changes and select another
        * account */
-      gchar *question_dialog_primary_text;
+      gchar *question_dialog_primary_text = get_dialog_primary_text (account);
       priv->destination_row = gtk_tree_row_reference_new (model, path);
 
-      question_dialog_primary_text = g_strdup_printf (
-          PENDING_CHANGES_QUESTION_PRIMARY_TEXT,
-          empathy_account_get_display_name (account));
-
       accounts_dialog_show_question_dialog (dialog,
           question_dialog_primary_text,
           _("You are about to select another account, which will discard\n"
@@ -1016,13 +1352,17 @@ accounts_dialog_account_selection_change (GtkTreeSelection *selection,
           GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
 
       g_free (question_dialog_primary_text);
+      ret = FALSE;
     }
   else
     {
-      return TRUE;
+      ret = TRUE;
     }
 
-  return FALSE;
+  if (account != NULL)
+    g_object_unref (account);
+
+  return ret;
 }
 
 static void
@@ -1035,7 +1375,7 @@ accounts_dialog_model_setup (EmpathyAccountsDialog *dialog)
   store = gtk_list_store_new (COL_COUNT,
       G_TYPE_STRING,         /* name */
       G_TYPE_UINT,           /* status */
-      EMPATHY_TYPE_ACCOUNT,   /* account */
+      TP_TYPE_ACCOUNT,   /* account */
       EMPATHY_TYPE_ACCOUNT_SETTINGS); /* settings */
 
   gtk_tree_view_set_model (GTK_TREE_VIEW (priv->treeview),
@@ -1082,7 +1422,7 @@ accounts_dialog_get_settings_iter (EmpathyAccountsDialog *dialog,
       gboolean   equal;
 
       gtk_tree_model_get (model, iter,
-          COL_ACCOUNT_SETTINGS_POINTER, &this_settings,
+          COL_ACCOUNT_SETTINGS, &this_settings,
           -1);
 
       equal = (this_settings == settings);
@@ -1097,7 +1437,7 @@ accounts_dialog_get_settings_iter (EmpathyAccountsDialog *dialog,
 
 static gboolean
 accounts_dialog_get_account_iter (EmpathyAccountsDialog *dialog,
-    EmpathyAccount *account,
+    TpAccount *account,
     GtkTreeIter *iter)
 {
   GtkTreeView      *view;
@@ -1119,7 +1459,7 @@ accounts_dialog_get_account_iter (EmpathyAccountsDialog *dialog,
       gboolean   equal;
 
       gtk_tree_model_get (model, iter,
-          COL_ACCOUNT_SETTINGS_POINTER, &settings,
+          COL_ACCOUNT_SETTINGS, &settings,
           -1);
 
       equal = empathy_account_settings_has_account (settings, account);
@@ -1161,16 +1501,17 @@ accounts_dialog_add (EmpathyAccountsDialog *dialog,
   gtk_list_store_set (GTK_LIST_STORE (model), &iter,
       COL_NAME, name,
       COL_STATUS, TP_CONNECTION_STATUS_DISCONNECTED,
-      COL_ACCOUNT_SETTINGS_POINTER, settings,
+      COL_ACCOUNT_SETTINGS, settings,
       -1);
 }
 
 static void
-accounts_dialog_connection_changed_cb     (EmpathyAccountManager *manager,
-    EmpathyAccount *account,
-    TpConnectionStatusReason reason,
-    TpConnectionStatus current,
-    TpConnectionStatus previous,
+accounts_dialog_connection_changed_cb (TpAccount *account,
+    guint old_status,
+    guint current,
+    guint reason,
+    gchar *dbus_error_name,
+    GHashTable *details,
     EmpathyAccountsDialog *dialog)
 {
   GtkTreeModel *model;
@@ -1178,6 +1519,9 @@ accounts_dialog_connection_changed_cb     (EmpathyAccountManager *manager,
   gboolean      found;
   EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
 
+  /* Update the status-infobar in the details view */
+  accounts_dialog_update_status_infobar (dialog, account);
+
   /* Update the status in the model */
   model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
 
@@ -1194,7 +1538,7 @@ accounts_dialog_connection_changed_cb     (EmpathyAccountManager *manager,
       gtk_tree_path_free (path);
     }
 
-  found = (empathy_account_manager_get_connecting_accounts (manager) > 0);
+  empathy_account_manager_get_accounts_connected (&found);
 
   if (!found && priv->connecting_id)
     {
@@ -1209,7 +1553,39 @@ accounts_dialog_connection_changed_cb     (EmpathyAccountManager *manager,
 }
 
 static void
-accounts_dialog_account_display_name_changed_cb (EmpathyAccount *account,
+update_account_in_treeview (EmpathyAccountsDialog *self,
+    TpAccount *account)
+{
+  EmpathyAccountsDialogPriv *priv = GET_PRIV (self);
+  GtkTreeIter iter;
+  GtkTreeModel *model;
+
+  model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
+  if (accounts_dialog_get_account_iter (self, account, &iter))
+    {
+      GtkTreePath *path;
+
+      path = gtk_tree_model_get_path (model, &iter);
+      gtk_tree_model_row_changed (model, path, &iter);
+      gtk_tree_path_free (path);
+    }
+}
+
+static void
+accounts_dialog_presence_changed_cb (TpAccount *account,
+    guint presence,
+    gchar *status,
+    gchar *status_message,
+    EmpathyAccountsDialog *dialog)
+{
+  /* Update the status-infobar in the details view */
+  accounts_dialog_update_status_infobar (dialog, account);
+
+  update_account_in_treeview (dialog, account);
+}
+
+static void
+accounts_dialog_account_display_name_changed_cb (TpAccount *account,
   GParamSpec *pspec,
   gpointer user_data)
 {
@@ -1217,13 +1593,16 @@ accounts_dialog_account_display_name_changed_cb (EmpathyAccount *account,
   GtkTreeIter iter;
   GtkTreeModel *model;
   EmpathyAccountSettings *settings;
-  EmpathyAccount *selected_account;
+  TpAccount *selected_account;
   EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
   EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
 
-  display_name = empathy_account_get_display_name (account);
+  display_name = tp_account_get_display_name (account);
   model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
   settings = accounts_dialog_model_get_selected_settings (dialog);
+  if (settings == NULL)
+    return;
+
   selected_account = empathy_account_settings_get_account (settings);
 
   if (accounts_dialog_get_account_iter (dialog, account, &iter))
@@ -1241,7 +1620,7 @@ accounts_dialog_account_display_name_changed_cb (EmpathyAccount *account,
 
 static void
 accounts_dialog_add_account (EmpathyAccountsDialog *dialog,
-    EmpathyAccount *account)
+    TpAccount *account)
 {
   EmpathyAccountSettings *settings;
   GtkTreeModel       *model;
@@ -1252,9 +1631,9 @@ accounts_dialog_add_account (EmpathyAccountsDialog *dialog,
   EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
 
   model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
-  g_object_get (account, "connection-status", &status, NULL);
-  name = empathy_account_get_display_name (account);
-  enabled = empathy_account_is_enabled (account);
+  status = tp_account_get_connection_status (account, NULL);
+  name = tp_account_get_display_name (account);
+  enabled = tp_account_is_enabled (account);
 
   settings = empathy_account_settings_new_for_account (account);
 
@@ -1264,226 +1643,142 @@ accounts_dialog_add_account (EmpathyAccountsDialog *dialog,
   gtk_list_store_set (GTK_LIST_STORE (model), &iter,
       COL_NAME, name,
       COL_STATUS, status,
-      COL_ACCOUNT_POINTER, account,
-      COL_ACCOUNT_SETTINGS_POINTER, settings,
+      COL_ACCOUNT, account,
+      COL_ACCOUNT_SETTINGS, settings,
       -1);
 
-  accounts_dialog_connection_changed_cb (priv->account_manager,
-      account,
-      TP_CONNECTION_STATUS_REASON_NONE_SPECIFIED,
+  accounts_dialog_connection_changed_cb (account,
+      0,
       status,
-      TP_CONNECTION_STATUS_DISCONNECTED,
+      TP_CONNECTION_STATUS_REASON_NONE_SPECIFIED,
+      NULL,
+      NULL,
       dialog);
 
-  g_signal_connect (account, "notify::display-name",
-      G_CALLBACK (accounts_dialog_account_display_name_changed_cb), dialog);
+  empathy_signal_connect_weak (account, "notify::display-name",
+      G_CALLBACK (accounts_dialog_account_display_name_changed_cb),
+      G_OBJECT (dialog));
 
   g_object_unref (settings);
 }
 
 static void
-accounts_dialog_update (EmpathyAccountsDialog *dialog,
-    EmpathyAccountSettings *settings)
+account_prepare_cb (GObject *source_object,
+    GAsyncResult *result,
+    gpointer user_data)
 {
-  GtkTreeModel       *model;
-  GtkTreeIter         iter;
-  TpConnectionStatus  status = TP_CONNECTION_STATUS_DISCONNECTED;
-  const gchar        *name;
-  gboolean            enabled = FALSE;
-  EmpathyAccount     *account;
-  EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
-
-  model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
-  name = empathy_account_settings_get_display_name (settings);
+  EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
+  TpAccount *account = TP_ACCOUNT (source_object);
+  GError *error = NULL;
 
-  account = empathy_account_settings_get_account (settings);
-  if (account != NULL)
+  if (!tp_account_prepare_finish (account, result, &error))
     {
-      enabled = empathy_account_is_enabled (account);
-      g_object_get (account, "connection-status", &status, NULL);
+      DEBUG ("Failed to prepare account: %s", error->message);
+      g_error_free (error);
+      return;
     }
 
-  accounts_dialog_get_settings_iter (dialog, settings, &iter);
-  gtk_list_store_set (GTK_LIST_STORE (model), &iter,
-      COL_NAME, name,
-      COL_STATUS, status,
-      COL_ACCOUNT_POINTER, account,
-      COL_ACCOUNT_SETTINGS_POINTER, settings,
-      -1);
+  accounts_dialog_add_account (dialog, account);
 }
 
 static void
-accounts_dialog_account_added_cb (EmpathyAccountManager *manager,
-    EmpathyAccount *account,
+accounts_dialog_account_validity_changed_cb (TpAccountManager *manager,
+    TpAccount *account,
+    gboolean valid,
     EmpathyAccountsDialog *dialog)
 {
-  accounts_dialog_add_account (dialog, account);
+  tp_account_prepare_async (account, NULL, account_prepare_cb, dialog);
 }
 
-
 static void
-accounts_dialog_account_removed_cb (EmpathyAccountManager *manager,
-    EmpathyAccount *account,
+accounts_dialog_accounts_model_row_inserted_cb (GtkTreeModel *model,
+    GtkTreePath *path,
+    GtkTreeIter *iter,
     EmpathyAccountsDialog *dialog)
 {
-  GtkTreeIter iter;
   EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
 
-  if (accounts_dialog_get_account_iter (dialog, account, &iter))
+  if (priv->setting_widget_object != NULL &&
+      accounts_dialog_has_valid_accounts (dialog))
     {
-      g_signal_handlers_disconnect_by_func (account,
-          accounts_dialog_account_display_name_changed_cb, dialog);
-      gtk_list_store_remove (GTK_LIST_STORE (
-            gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview))), &iter);
+      empathy_account_widget_set_other_accounts_exist (
+          priv->setting_widget_object, TRUE);
     }
 }
 
 static void
-enable_or_disable_account (EmpathyAccountsDialog *dialog,
-    EmpathyAccount *account,
-    gboolean enabled)
+accounts_dialog_accounts_model_row_deleted_cb (GtkTreeModel *model,
+    GtkTreePath *path,
+    EmpathyAccountsDialog *dialog)
 {
-  GtkTreeModel *model;
   EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
 
-  /* Update the status in the model */
-  model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
-
-  DEBUG ("Account %s is now %s",
-      empathy_account_get_display_name (account),
-      enabled ? "enabled" : "disabled");
-}
-
-static void
-accounts_dialog_account_disabled_cb (EmpathyAccountManager *manager,
-    EmpathyAccount *account,
-    EmpathyAccountsDialog *dialog)
-{
-  enable_or_disable_account (dialog, account, FALSE);
+  if (priv->setting_widget_object != NULL &&
+      !accounts_dialog_has_valid_accounts (dialog))
+    {
+      empathy_account_widget_set_other_accounts_exist (
+          priv->setting_widget_object, FALSE);
+    }
 }
 
 static void
-accounts_dialog_account_enabled_cb (EmpathyAccountManager *manager,
-    EmpathyAccount *account,
+accounts_dialog_account_removed_cb (TpAccountManager *manager,
+    TpAccount *account,
     EmpathyAccountsDialog *dialog)
 {
-  enable_or_disable_account (dialog, account, TRUE);
-}
-
-static void
-accounts_dialog_account_changed_cb (EmpathyAccountManager *manager,
-    EmpathyAccount *account,
-    EmpathyAccountsDialog  *dialog)
-{
-  EmpathyAccountSettings *settings, *selected_settings;
-  GtkTreeModel *model;
   GtkTreeIter iter;
   EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
 
-  model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
-
-  if (!accounts_dialog_get_account_iter (dialog, account, &iter))
-    return;
-
-  gtk_tree_model_get (model, &iter,
-      COL_ACCOUNT_SETTINGS_POINTER, &settings,
-      -1);
-
-  accounts_dialog_update (dialog, settings);
-  selected_settings = accounts_dialog_model_get_selected_settings (dialog);
-
-  if (settings == selected_settings)
-    accounts_dialog_update_name_label (dialog,
-        empathy_account_settings_get_display_name (settings));
-
-  if (settings)
-    g_object_unref (settings);
-
-  if (selected_settings)
-    g_object_unref (selected_settings);
+  if (accounts_dialog_get_account_iter (dialog, account, &iter))
+    {
+      gtk_list_store_remove (GTK_LIST_STORE (
+          gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview))), &iter);
+    }
 }
 
 static void
-accounts_dialog_button_create_clicked_cb (GtkWidget *button,
-    EmpathyAccountsDialog *dialog)
+enable_or_disable_account (EmpathyAccountsDialog *dialog,
+    TpAccount *account,
+    gboolean enabled)
 {
-  EmpathyAccountSettings *settings;
-  gchar *str;
-  const gchar *display_name;
-  TpConnectionManager *cm;
-  TpConnectionManagerProtocol *proto;
+  GtkTreeModel *model;
   EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
-  gboolean is_gtalk;
-
-  cm = empathy_protocol_chooser_dup_selected (
-      EMPATHY_PROTOCOL_CHOOSER (priv->combobox_protocol), &proto, &is_gtalk);
-
-  display_name = empathy_protocol_name_to_display_name (
-      is_gtalk ? "gtalk" : proto->name);
-
-  if (display_name == NULL)
-    display_name = proto->name;
-
-  /* Create account */
-  /* To translator: %s is the name of the protocol, such as "Google Talk" or
-   * "Yahoo!"
-   */
-  str = g_strdup_printf (_("New %s account"), display_name);
-  settings = empathy_account_settings_new (cm->name, proto->name, str);
 
-  g_free (str);
-
-#ifndef HAVE_MOBLIN
-  if (tp_connection_manager_protocol_can_register (proto))
-    {
-      gboolean active;
-
-      active = gtk_toggle_button_get_active
-        (GTK_TOGGLE_BUTTON (priv->radiobutton_register));
-      if (active)
-        empathy_account_settings_set_boolean (settings, "register", TRUE);
-    }
-#endif
-
-  if (is_gtalk)
-    empathy_account_settings_set_icon_name_async (settings, "im-google-talk",
-        NULL, NULL);
+  /* Update the status in the model */
+  model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
 
-  accounts_dialog_add (dialog, settings);
-  accounts_dialog_model_set_selected (dialog, settings);
+  /* Update the status-infobar in the details view */
+  accounts_dialog_update_status_infobar (dialog, account);
 
-  g_object_unref (settings);
-  g_object_unref (cm);
+  DEBUG ("Account %s is now %s",
+      tp_account_get_display_name (account),
+      enabled ? "enabled" : "disabled");
 }
 
 static void
-accounts_dialog_button_back_clicked_cb (GtkWidget *button,
+accounts_dialog_account_disabled_cb (TpAccountManager *manager,
+    TpAccount *account,
     EmpathyAccountsDialog *dialog)
 {
-  EmpathyAccountSettings *settings;
-
-  settings = accounts_dialog_model_get_selected_settings (dialog);
-  accounts_dialog_update_settings (dialog, settings);
-
-  if (settings)
-    g_object_unref (settings);
+  enable_or_disable_account (dialog, account, FALSE);
+  update_account_in_treeview (dialog, account);
 }
 
 static void
-accounts_dialog_button_help_clicked_cb (GtkWidget *button,
+accounts_dialog_account_enabled_cb (TpAccountManager *manager,
+    TpAccount *account,
     EmpathyAccountsDialog *dialog)
 {
-  empathy_url_show (button, "ghelp:empathy?accounts-window");
+  enable_or_disable_account (dialog, account, TRUE);
 }
 
 static void
 accounts_dialog_button_import_clicked_cb (GtkWidget *button,
     EmpathyAccountsDialog *dialog)
 {
-  EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
   GtkWidget *import_dialog;
 
-  import_dialog = empathy_import_dialog_new (GTK_WINDOW (priv->window),
+  import_dialog = empathy_import_dialog_new (GTK_WINDOW (dialog),
       FALSE);
   gtk_widget_show (import_dialog);
 }
@@ -1501,36 +1796,6 @@ accounts_dialog_close_response_cb (GtkDialog *message_dialog,
     gtk_widget_destroy (account_dialog);
 }
 
-static void
-accounts_dialog_response_cb (GtkWidget *widget,
-    gint response,
-    EmpathyAccountsDialog *dialog)
-{
-  EmpathyAccount *account = NULL;
-
-  if (accounts_dialog_has_pending_change (dialog, &account))
-    {
-      gchar *question_dialog_primary_text;
-      question_dialog_primary_text = g_strdup_printf (
-          PENDING_CHANGES_QUESTION_PRIMARY_TEXT,
-          empathy_account_get_display_name (account));
-
-      accounts_dialog_show_question_dialog (dialog,
-          question_dialog_primary_text,
-          _("You are about to close the window, which will discard\n"
-              "your changes. Are you sure you want to proceed?"),
-          G_CALLBACK (accounts_dialog_close_response_cb),
-          widget,
-          GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
-          GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
-
-      g_free (question_dialog_primary_text);
-    }
-  else if (response == GTK_RESPONSE_CLOSE ||
-           response == GTK_RESPONSE_DELETE_EVENT)
-    gtk_widget_destroy (widget);
-}
-
 static gboolean
 accounts_dialog_delete_event_cb (GtkWidget *widget,
     GdkEvent *event,
@@ -1540,18 +1805,9 @@ accounts_dialog_delete_event_cb (GtkWidget *widget,
   return TRUE;
 }
 
-static void
-accounts_dialog_destroy_cb (GtkObject *obj,
-    EmpathyAccountsDialog *dialog)
-{
-  DEBUG ("%p", obj);
-
-  g_object_unref (dialog);
-}
-
 static void
 accounts_dialog_set_selected_account (EmpathyAccountsDialog *dialog,
-    EmpathyAccount *account)
+    TpAccount *account)
 {
   GtkTreeSelection *selection;
   GtkTreeIter       iter;
@@ -1563,23 +1819,24 @@ accounts_dialog_set_selected_account (EmpathyAccountsDialog *dialog,
 }
 
 static void
-accounts_dialog_cms_ready_cb (EmpathyConnectionManagers *cms,
-    GParamSpec *pspec,
-    EmpathyAccountsDialog *dialog)
+accounts_dialog_cms_prepare_cb (GObject *source,
+    GAsyncResult *result,
+    gpointer user_data)
 {
+  EmpathyConnectionManagers *cms = EMPATHY_CONNECTION_MANAGERS (source);
+  EmpathyAccountsDialog *dialog = user_data;
   EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
 
-  if (empathy_connection_managers_is_ready (cms))
-    {
-      accounts_dialog_update_settings (dialog, NULL);
+  if (!empathy_connection_managers_prepare_finish (cms, result, NULL))
+    return;
 
-      if (priv->initial_selection != NULL)
-        {
-          accounts_dialog_set_selected_account
-              (dialog, priv->initial_selection);
-          g_object_unref (priv->initial_selection);
-          priv->initial_selection = NULL;
-        }
+  accounts_dialog_update_settings (dialog, NULL);
+
+  if (priv->initial_selection != NULL)
+    {
+      accounts_dialog_set_selected_account (dialog, priv->initial_selection);
+      g_object_unref (priv->initial_selection);
+      priv->initial_selection = NULL;
     }
 }
 
@@ -1589,10 +1846,10 @@ accounts_dialog_accounts_setup (EmpathyAccountsDialog *dialog)
   EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
   GList *accounts, *l;
 
-  g_signal_connect (priv->account_manager, "account-created",
-      G_CALLBACK (accounts_dialog_account_added_cb),
+  g_signal_connect (priv->account_manager, "account-validity-changed",
+      G_CALLBACK (accounts_dialog_account_validity_changed_cb),
       dialog);
-  g_signal_connect (priv->account_manager, "account-deleted",
+  g_signal_connect (priv->account_manager, "account-removed",
       G_CALLBACK (accounts_dialog_account_removed_cb),
       dialog);
   g_signal_connect (priv->account_manager, "account-enabled",
@@ -1601,106 +1858,224 @@ accounts_dialog_accounts_setup (EmpathyAccountsDialog *dialog)
   g_signal_connect (priv->account_manager, "account-disabled",
       G_CALLBACK (accounts_dialog_account_disabled_cb),
       dialog);
-  g_signal_connect (priv->account_manager, "account-changed",
-      G_CALLBACK (accounts_dialog_account_changed_cb),
-      dialog);
-  g_signal_connect (priv->account_manager, "account-connection-changed",
-      G_CALLBACK (accounts_dialog_connection_changed_cb),
-      dialog);
 
   /* Add existing accounts */
-  accounts = empathy_account_manager_dup_accounts (priv->account_manager);
+  accounts = tp_account_manager_get_valid_accounts (priv->account_manager);
   for (l = accounts; l; l = l->next)
     {
       accounts_dialog_add_account (dialog, l->data);
-      g_object_unref (l->data);
+
+      empathy_signal_connect_weak (l->data, "status-changed",
+          G_CALLBACK (accounts_dialog_connection_changed_cb), G_OBJECT (dialog));
+      empathy_signal_connect_weak (l->data, "presence-changed",
+          G_CALLBACK (accounts_dialog_presence_changed_cb), G_OBJECT (dialog));
     }
   g_list_free (accounts);
 
   priv->cms = empathy_connection_managers_dup_singleton ();
-  if (!empathy_connection_managers_is_ready (priv->cms))
-    g_signal_connect (priv->cms, "notify::ready",
-        G_CALLBACK (accounts_dialog_cms_ready_cb), dialog);
+
+  empathy_connection_managers_prepare_async (priv->cms,
+      accounts_dialog_cms_prepare_cb, dialog);
 
   accounts_dialog_model_select_first (dialog);
 }
 
 static void
-accounts_dialog_manager_ready_cb (EmpathyAccountManager *manager,
-    GParamSpec *pspec,
+accounts_dialog_manager_ready_cb (GObject *source_object,
+    GAsyncResult *result,
     gpointer user_data)
 {
-  if (!empathy_account_manager_is_ready (manager))
-    return;
+  TpAccountManager *manager = TP_ACCOUNT_MANAGER (source_object);
+  GError *error = NULL;
+
+  if (!tp_account_manager_prepare_finish (manager, result, &error))
+    {
+      DEBUG ("Failed to prepare account manager: %s", error->message);
+      g_error_free (error);
+      return;
+    }
 
   accounts_dialog_accounts_setup (user_data);
 }
 
+static void
+dialog_response_cb (GtkWidget *widget,
+    gint response_id,
+    gpointer user_data)
+{
+  EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (widget);
+
+  if (response_id == GTK_RESPONSE_HELP)
+    {
+      empathy_url_show (widget, "ghelp:empathy?accounts-window");
+    }
+  else if (response_id == GTK_RESPONSE_CLOSE ||
+      response_id == GTK_RESPONSE_DELETE_EVENT)
+    {
+      TpAccount *account = NULL;
+
+      if (accounts_dialog_has_pending_change (dialog, &account))
+        {
+          gchar *question_dialog_primary_text = get_dialog_primary_text (
+              account);
+
+          accounts_dialog_show_question_dialog (dialog,
+              question_dialog_primary_text,
+              _("You are about to close the window, which will discard\n"
+                  "your changes. Are you sure you want to proceed?"),
+              G_CALLBACK (accounts_dialog_close_response_cb),
+              widget,
+              GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
+              GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
+
+          g_free (question_dialog_primary_text);
+        }
+      else
+        {
+          gtk_widget_destroy (widget);
+        }
+
+      if (account != NULL)
+        g_object_unref (account);
+    }
+}
+
 static void
 accounts_dialog_build_ui (EmpathyAccountsDialog *dialog)
 {
+  GtkWidget *top_hbox;
   GtkBuilder                   *gui;
   gchar                        *filename;
   EmpathyAccountsDialogPriv    *priv = GET_PRIV (dialog);
-#ifdef HAVE_MOBLIN
-  GtkWidget                    *action_area;
-#endif
+  GtkWidget                    *content_area;
+  GtkWidget *action_area, *vbox, *hbox, *align;
 
   filename = empathy_file_lookup ("empathy-accounts-dialog.ui", "src");
 
   gui = empathy_builder_get_file (filename,
-      "accounts_dialog", &priv->window,
+      "accounts_dialog_hbox", &top_hbox,
       "vbox_details", &priv->vbox_details,
       "frame_no_protocol", &priv->frame_no_protocol,
       "alignment_settings", &priv->alignment_settings,
+      "alignment_infobar", &priv->alignment_infobar,
       "treeview", &priv->treeview,
-      "frame_new_account", &priv->frame_new_account,
-      "hbox_type", &priv->hbox_type,
-      "button_create", &priv->button_create,
-      "button_back", &priv->button_back,
-      "radiobutton_reuse", &priv->radiobutton_reuse,
-      "radiobutton_register", &priv->radiobutton_register,
-      "image_type", &priv->image_type,
-      "label_name", &priv->label_name,
       "button_add", &priv->button_add,
+      "button_remove", &priv->button_remove,
       "button_import", &priv->button_import,
+      "hbox_protocol", &priv->hbox_protocol,
       NULL);
   g_free (filename);
 
+  gtk_widget_set_no_show_all (priv->frame_no_protocol, TRUE);
+
   empathy_builder_connect (gui, dialog,
-      "accounts_dialog", "response", accounts_dialog_response_cb,
-      "accounts_dialog", "destroy", accounts_dialog_destroy_cb,
-      "accounts_dialog", "delete-event", accounts_dialog_delete_event_cb,
-      "button_create", "clicked", accounts_dialog_button_create_clicked_cb,
-      "button_back", "clicked", accounts_dialog_button_back_clicked_cb,
       "button_add", "clicked", accounts_dialog_button_add_clicked_cb,
-      "button_help", "clicked", accounts_dialog_button_help_clicked_cb,
+      "button_remove", "clicked", accounts_dialog_button_remove_clicked_cb,
       "button_import", "clicked", accounts_dialog_button_import_clicked_cb,
       NULL);
 
+  content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
+
+  gtk_container_add (GTK_CONTAINER (content_area), top_hbox);
+
   g_object_unref (gui);
 
-#ifdef HAVE_MOBLIN
-  action_area = gtk_dialog_get_action_area (GTK_DIALOG (priv->window));
+  action_area = gtk_dialog_get_action_area (GTK_DIALOG (dialog));
+
+#ifdef HAVE_MEEGO
   gtk_widget_hide (action_area);
+  gtk_widget_hide (priv->button_remove);
+#endif /* HAVE_MEEGO */
 
-  /* Translators: this is used only when built on a moblin platform */
-  gtk_button_set_label (GTK_BUTTON (priv->button_create), _("_Next"));
-  gtk_button_set_use_underline (GTK_BUTTON (priv->button_create), TRUE);
-#endif
+  /* Remove button is unsensitive until we have a selected account */
+  gtk_widget_set_sensitive (priv->button_remove, FALSE);
 
   priv->combobox_protocol = empathy_protocol_chooser_new ();
-  gtk_box_pack_start (GTK_BOX (priv->hbox_type),
-      priv->combobox_protocol,
+  gtk_box_pack_start (GTK_BOX (priv->hbox_protocol), priv->combobox_protocol,
       TRUE, TRUE, 0);
-  gtk_widget_show (priv->combobox_protocol);
   g_signal_connect (priv->combobox_protocol, "changed",
       G_CALLBACK (accounts_dialog_protocol_changed_cb),
       dialog);
 
   if (priv->parent_window)
-    gtk_window_set_transient_for (GTK_WINDOW (priv->window),
+    gtk_window_set_transient_for (GTK_WINDOW (dialog),
         priv->parent_window);
+
+  priv->infobar = gtk_info_bar_new ();
+  gtk_container_add (GTK_CONTAINER (priv->alignment_infobar),
+      priv->infobar);
+  gtk_widget_show (priv->infobar);
+
+  content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (priv->infobar));
+
+  priv->image_type = gtk_image_new_from_stock (GTK_STOCK_CUT,
+      GTK_ICON_SIZE_DIALOG);
+  gtk_misc_set_alignment (GTK_MISC (priv->image_type), 0.0, 0.5);
+  gtk_box_pack_start (GTK_BOX (content_area), priv->image_type, FALSE, FALSE, 0);
+  gtk_widget_show (priv->image_type);
+
+  vbox = gtk_vbox_new (FALSE, 6);
+  gtk_box_pack_start (GTK_BOX (content_area), vbox, TRUE, TRUE, 0);
+  gtk_widget_show (vbox);
+
+  /* first row */
+  align = gtk_alignment_new (0.5, 0.0, 0.0, 0.0);
+  gtk_widget_show (align);
+
+  priv->label_name = gtk_label_new (NULL);
+  gtk_container_add (GTK_CONTAINER (align), priv->label_name);
+  gtk_widget_show (priv->label_name);
+
+  gtk_box_pack_start (GTK_BOX (vbox), align, TRUE, TRUE, 0);
+
+  /* second row */
+  align = gtk_alignment_new (0.5, 0.0, 0.0, 0.0);
+  gtk_widget_show (align);
+  hbox = gtk_hbox_new (FALSE, 6);
+  gtk_widget_show (hbox);
+  gtk_container_add (GTK_CONTAINER (align), hbox);
+
+  gtk_box_pack_start (GTK_BOX (vbox), align, TRUE, TRUE, 0);
+
+  /* set up spinner */
+  priv->throbber = ephy_spinner_new ();
+  ephy_spinner_set_size (EPHY_SPINNER (priv->throbber), GTK_ICON_SIZE_SMALL_TOOLBAR);
+
+  priv->image_status = gtk_image_new_from_icon_name (
+            empathy_icon_name_for_presence (
+            TP_CONNECTION_PRESENCE_TYPE_OFFLINE), GTK_ICON_SIZE_SMALL_TOOLBAR);
+
+  priv->label_status = gtk_label_new (NULL);
+  gtk_label_set_line_wrap (GTK_LABEL (priv->label_status), TRUE);
+  gtk_widget_show (priv->label_status);
+
+  gtk_box_pack_start (GTK_BOX (hbox), priv->throbber, FALSE, FALSE, 0);
+  gtk_box_pack_start (GTK_BOX (hbox), priv->image_status, FALSE, FALSE, 3);
+  gtk_box_pack_start (GTK_BOX (hbox), priv->label_status, TRUE, TRUE, 0);
+
+  /* Tweak the dialog */
+  gtk_window_set_title (GTK_WINDOW (dialog), _("Accounts"));
+  gtk_window_set_role (GTK_WINDOW (dialog), "accounts");
+
+  gtk_window_set_default_size (GTK_WINDOW (dialog), 640, -1);
+
+  gtk_window_set_type_hint (GTK_WINDOW (dialog), GDK_WINDOW_TYPE_HINT_DIALOG);
+
+  gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE);
+
+  /* add dialog buttons */
+  gtk_button_box_set_layout (GTK_BUTTON_BOX (action_area), GTK_BUTTONBOX_END);
+
+  gtk_dialog_add_buttons (GTK_DIALOG (dialog),
+      GTK_STOCK_HELP, GTK_RESPONSE_HELP,
+      GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
+      NULL);
+
+  g_signal_connect (dialog, "response",
+      G_CALLBACK (dialog_response_cb), dialog);
+
+  g_signal_connect (dialog, "delete-event",
+      G_CALLBACK (accounts_dialog_delete_event_cb), dialog);
 }
 
 static void
@@ -1708,10 +2083,22 @@ do_dispose (GObject *obj)
 {
   EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (obj);
   EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
+  GtkTreeModel *model;
+
+  if (priv->dispose_has_run)
+    return;
+
+  priv->dispose_has_run = TRUE;
 
   /* Disconnect signals */
+  model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
+  g_signal_handlers_disconnect_by_func (model,
+      accounts_dialog_accounts_model_row_inserted_cb, dialog);
+  g_signal_handlers_disconnect_by_func (model,
+      accounts_dialog_accounts_model_row_deleted_cb, dialog);
+
   g_signal_handlers_disconnect_by_func (priv->account_manager,
-      accounts_dialog_account_added_cb,
+      accounts_dialog_account_validity_changed_cb,
       dialog);
   g_signal_handlers_disconnect_by_func (priv->account_manager,
       accounts_dialog_account_removed_cb,
@@ -1722,12 +2109,6 @@ do_dispose (GObject *obj)
   g_signal_handlers_disconnect_by_func (priv->account_manager,
       accounts_dialog_account_disabled_cb,
       dialog);
-  g_signal_handlers_disconnect_by_func (priv->account_manager,
-      accounts_dialog_account_changed_cb,
-      dialog);
-  g_signal_handlers_disconnect_by_func (priv->account_manager,
-      accounts_dialog_connection_changed_cb,
-      dialog);
   g_signal_handlers_disconnect_by_func (priv->account_manager,
       accounts_dialog_manager_ready_cb,
       dialog);
@@ -1754,31 +2135,6 @@ do_dispose (GObject *obj)
   G_OBJECT_CLASS (empathy_accounts_dialog_parent_class)->dispose (obj);
 }
 
-static GObject *
-do_constructor (GType type,
-    guint n_props,
-    GObjectConstructParam *props)
-{
-  GObject *retval;
-
-  if (dialog_singleton)
-    {
-      retval = G_OBJECT (dialog_singleton);
-      g_object_ref (retval);
-    }
-  else
-    {
-      retval =
-        G_OBJECT_CLASS (empathy_accounts_dialog_parent_class)->constructor
-            (type, n_props, props);
-
-      dialog_singleton = EMPATHY_ACCOUNTS_DIALOG (retval);
-      g_object_add_weak_pointer (retval, (gpointer) &dialog_singleton);
-    }
-
-  return retval;
-}
-
 static void
 do_get_property (GObject *object,
     guint property_id,
@@ -1821,18 +2177,22 @@ do_constructed (GObject *object)
   EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (object);
   EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
   gboolean import_asked;
+  GtkTreeModel *model;
 
   accounts_dialog_build_ui (dialog);
   accounts_dialog_model_setup (dialog);
 
+  model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
+  g_signal_connect (model, "row-inserted",
+      (GCallback) accounts_dialog_accounts_model_row_inserted_cb, dialog);
+  g_signal_connect (model, "row-deleted",
+      (GCallback) accounts_dialog_accounts_model_row_deleted_cb, dialog);
+
   /* Set up signalling */
-  priv->account_manager = empathy_account_manager_dup_singleton ();
+  priv->account_manager = tp_account_manager_dup ();
 
-  if (!empathy_account_manager_is_ready (priv->account_manager))
-    g_signal_connect (priv->account_manager, "notify::ready",
-        G_CALLBACK (accounts_dialog_manager_ready_cb), dialog);
-  else
-    accounts_dialog_accounts_setup (dialog);
+  tp_account_manager_prepare_async (priv->account_manager, NULL,
+      accounts_dialog_manager_ready_cb, dialog);
 
   empathy_conf_get_bool (empathy_conf_get (),
       EMPATHY_PREFS_IMPORT_ASKED, &import_asked);
@@ -1847,7 +2207,7 @@ do_constructed (GObject *object)
 
           empathy_conf_set_bool (empathy_conf_get (),
               EMPATHY_PREFS_IMPORT_ASKED, TRUE);
-          import_dialog = empathy_import_dialog_new (GTK_WINDOW (priv->window),
+          import_dialog = empathy_import_dialog_new (GTK_WINDOW (dialog),
               FALSE);
           gtk_widget_show (import_dialog);
         }
@@ -1860,7 +2220,6 @@ empathy_accounts_dialog_class_init (EmpathyAccountsDialogClass *klass)
   GObjectClass *oclass = G_OBJECT_CLASS (klass);
   GParamSpec *param_spec;
 
-  oclass->constructor = do_constructor;
   oclass->dispose = do_dispose;
   oclass->constructed = do_constructed;
   oclass->set_property = do_set_property;
@@ -1890,7 +2249,7 @@ empathy_accounts_dialog_init (EmpathyAccountsDialog *dialog)
 
 GtkWidget *
 empathy_accounts_dialog_show (GtkWindow *parent,
-    EmpathyAccount *selected_account)
+    TpAccount *selected_account)
 {
   EmpathyAccountsDialog *dialog;
   EmpathyAccountsDialogPriv *priv;
@@ -1902,7 +2261,7 @@ empathy_accounts_dialog_show (GtkWindow *parent,
 
   if (selected_account)
     {
-      if (empathy_connection_managers_is_ready (priv->cms))
+      if (priv->cms != NULL && empathy_connection_managers_is_ready (priv->cms))
         accounts_dialog_set_selected_account (dialog, selected_account);
       else
         /* save the selection to set it later when the cms
@@ -1911,7 +2270,77 @@ empathy_accounts_dialog_show (GtkWindow *parent,
         priv->initial_selection = g_object_ref (selected_account);
     }
 
-  gtk_window_present (GTK_WINDOW (priv->window));
+  gtk_window_present (GTK_WINDOW (dialog));
+
+  return GTK_WIDGET (dialog);
+}
+
+void
+empathy_accounts_dialog_show_application (GdkScreen *screen,
+    GChildWatchFunc application_exit_cb,
+    gpointer user_data,
+    TpAccount *selected_account,
+    gboolean if_needed,
+    gboolean hidden)
+{
+  gint command_pid;
+  GError *error = NULL;
+  gchar *argv[4] = { NULL, };
+  gint i = 0;
+  gchar *account_option = NULL;
+  gchar *path;
+
+  g_return_if_fail (GDK_IS_SCREEN (screen));
+  g_return_if_fail (!selected_account || TP_IS_ACCOUNT (selected_account));
+
+  /* Try to run from source directory if possible */
+  path = g_build_filename (g_getenv ("EMPATHY_SRCDIR"), "src",
+      "empathy-accounts", NULL);
+
+  if (!g_file_test (path, G_FILE_TEST_EXISTS))
+    {
+      g_free (path);
+      path = g_build_filename (BIN_DIR, "empathy-accounts", NULL);
+    }
+
+  argv[i++] = path;
+
+  if (selected_account)
+    {
+      const gchar *account_path;
+
+      account_path = tp_proxy_get_object_path (TP_PROXY (selected_account));
+      account_option = g_strdup_printf ("--select-account=%s",
+          &account_path[strlen (TP_ACCOUNT_OBJECT_PATH_BASE)]);
+
+      argv[i++] = account_option;
+    }
+
+  if (if_needed)
+    argv[i++] = "--if-needed";
+
+  if (hidden)
+    argv[i++] = "--hidden";
+
+  DEBUG ("Launching empathy-accounts (if_needed: %d, hidden: %d, account: %s)",
+    if_needed, hidden,
+    selected_account == NULL ? "<none selected>" :
+      tp_proxy_get_object_path (TP_PROXY (selected_account)));
+
+  gdk_spawn_on_screen (screen, NULL, argv, NULL,
+      G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD, NULL, NULL,
+      &command_pid, &error);
+  if (error)
+    {
+      g_warning ("Failed to open accounts dialog: %s", error->message);
+      g_error_free (error);
+    }
+
+  /* XXX: unportable cast to GPid; then again, gdk_spawn_on_screen() seems
+   * unportable since it always takes a gint* for the PID */
+  if (application_exit_cb)
+    g_child_watch_add ((GPid) command_pid, application_exit_cb, NULL);
 
-  return priv->window;
+  g_free (account_option);
+  g_free (path);
 }