[empathy/mc5: 135/483] Port to using EmpathyAccountSettings



commit 9c3db97dcf9bd237784d401ae3215326a1d77ae2
Author: Sjoerd Simons <sjoerd simons collabora co uk>
Date:   Tue Jul 21 16:56:22 2009 +0100

    Port to using EmpathyAccountSettings

 libempathy-gtk/empathy-account-widget-irc.c |   61 +++--
 libempathy-gtk/empathy-account-widget-irc.h |    4 +-
 libempathy-gtk/empathy-account-widget-sip.c |   22 +-
 libempathy-gtk/empathy-account-widget-sip.h |    4 +-
 libempathy-gtk/empathy-account-widget.c     |  264 ++++++++++++--------
 libempathy-gtk/empathy-account-widget.h     |   25 +-
 src/empathy-accounts-dialog.c               |  363 +++++++++++++++++++--------
 7 files changed, 475 insertions(+), 268 deletions(-)
---
diff --git a/libempathy-gtk/empathy-account-widget-irc.c b/libempathy-gtk/empathy-account-widget-irc.c
index b2383a0..ae41f1e 100644
--- a/libempathy-gtk/empathy-account-widget-irc.c
+++ b/libempathy-gtk/empathy-account-widget-irc.c
@@ -41,7 +41,7 @@
 #define IRC_NETWORKS_FILENAME "irc-networks.xml"
 
 typedef struct {
-  EmpathyAccount *account;
+  EmpathyAccountSettings *settings;
   EmpathyIrcNetworkManager *network_manager;
 
   GtkWidget *vbox_settings;
@@ -59,7 +59,7 @@ account_widget_irc_destroy_cb (GtkWidget *widget,
                                EmpathyAccountWidgetIrc *settings)
 {
   g_object_unref (settings->network_manager);
-  g_object_unref (settings->account);
+  g_object_unref (settings->settings);
   g_slice_free (EmpathyAccountWidgetIrc, settings);
 }
 
@@ -67,9 +67,9 @@ static void
 unset_server_params (EmpathyAccountWidgetIrc *settings)
 {
   DEBUG ("Unset server, port and use-ssl");
-  empathy_account_unset_param (settings->account, "server");
-  empathy_account_unset_param (settings->account, "port");
-  empathy_account_unset_param (settings->account, "use-ssl");
+  empathy_account_settings_unset (settings->settings, "server");
+  empathy_account_settings_unset (settings->settings, "port");
+  empathy_account_settings_unset (settings->settings, "use-ssl");
 }
 
 static void
@@ -95,7 +95,7 @@ update_server_params (EmpathyAccountWidgetIrc *settings)
 
   g_object_get (network, "charset", &charset, NULL);
   DEBUG ("Setting charset to %s", charset);
-  empathy_account_set_param_string (settings->account, "charset", charset);
+  empathy_account_settings_set_string (settings->settings, "charset", charset);
   g_free (charset);
 
   servers = empathy_irc_network_get_servers (network);
@@ -114,11 +114,13 @@ update_server_params (EmpathyAccountWidgetIrc *settings)
           NULL);
 
       DEBUG ("Setting server to %s", address);
-      empathy_account_set_param_string (settings->account, "server", address);
+      empathy_account_settings_set_string (settings->settings,
+        "server", address);
       DEBUG ("Setting port to %u", port);
-      empathy_account_set_param_int (settings->account, "port", port);
+      empathy_account_settings_set_uint32 (settings->settings, "port", port);
       DEBUG ("Setting use-ssl to %s", ssl ? "TRUE": "FALSE" );
-      empathy_account_set_param_boolean (settings->account, "use-ssl", ssl);
+      empathy_account_settings_set_boolean (settings->settings,
+        "use-ssl", ssl);
 
       g_free (address);
     }
@@ -329,17 +331,19 @@ account_widget_irc_setup (EmpathyAccountWidgetIrc *settings)
   gboolean ssl = FALSE;
   EmpathyIrcNetwork *network = NULL;
 
-  nick = empathy_account_get_param_string (settings->account, "account");
-  fullname = empathy_account_get_param_string (settings->account, "fullname");
-  server = empathy_account_get_param_string (settings->account, "server");
-  charset = empathy_account_get_param_string (settings->account, "charset");
-  port = empathy_account_get_param_int (settings->account, "port");
-  ssl = empathy_account_get_param_boolean (settings->account, "use-ssl");
+  nick = empathy_account_settings_get_string (settings->settings, "account");
+  fullname = empathy_account_settings_get_string (settings->settings,
+      "fullname");
+  server = empathy_account_settings_get_string (settings->settings, "server");
+  charset = empathy_account_settings_get_string (settings->settings, "charset");
+  port = empathy_account_settings_get_uint32 (settings->settings, "port");
+  ssl = empathy_account_settings_get_boolean (settings->settings, "use-ssl");
 
   if (!nick)
     {
       nick = g_strdup (g_get_user_name ());
-      empathy_account_set_param_string (settings->account, "account", nick);
+      empathy_account_settings_set_string (settings->settings,
+        "account", nick);
     }
 
   if (!fullname)
@@ -349,7 +353,8 @@ account_widget_irc_setup (EmpathyAccountWidgetIrc *settings)
         {
           fullname = g_strdup (nick);
         }
-      empathy_account_set_param_string (settings->account, "fullname", fullname);
+      empathy_account_settings_set_string (settings->settings,
+          "fullname", fullname);
     }
 
   if (server != NULL)
@@ -406,14 +411,14 @@ account_widget_irc_setup (EmpathyAccountWidgetIrc *settings)
 
 /**
  * empathy_account_widget_irc_new:
- * @account: the #EmpathyAccount to configure
+ * @settings: the #EmpathyAccountSettings to configure
  *
  * Creates a new IRC account widget to configure a given #EmpathyAccount
  *
  * Returns: The toplevel container of the configuration widget
  */
 GtkWidget *
-empathy_account_widget_irc_new (EmpathyAccount *account)
+empathy_account_widget_irc_new (EmpathyAccountSettings *account_settings)
 {
   EmpathyAccountWidgetIrc *settings;
   gchar *dir, *user_file_with_path, *global_file_with_path;
@@ -423,7 +428,7 @@ empathy_account_widget_irc_new (EmpathyAccount *account)
   gchar *filename;
 
   settings = g_slice_new0 (EmpathyAccountWidgetIrc);
-  settings->account = g_object_ref (account);
+  settings->settings = g_object_ref (settings);
 
   dir = g_build_filename (g_get_home_dir (), ".gnome2", PACKAGE_NAME, NULL);
   g_mkdir_with_parents (dir, S_IRUSR | S_IWUSR | S_IXUSR);
@@ -476,7 +481,7 @@ empathy_account_widget_irc_new (EmpathyAccount *account)
 
   account_widget_irc_setup (settings);
 
-  empathy_account_widget_handle_params (account, gui,
+  empathy_account_widget_handle_params (account_settings, gui,
       "entry_nick", "account",
       "entry_fullname", "fullname",
       "entry_password", "password",
@@ -485,13 +490,19 @@ empathy_account_widget_irc_new (EmpathyAccount *account)
 
   empathy_builder_connect (gui, settings,
       "vbox_irc_settings", "destroy", account_widget_irc_destroy_cb,
-      "button_network", "clicked", account_widget_irc_button_edit_network_clicked_cb,
-      "button_add_network", "clicked", account_widget_irc_button_add_network_clicked_cb,
-      "button_remove_network", "clicked", account_widget_irc_button_remove_clicked_cb,
-      "combobox_network", "changed", account_widget_irc_combobox_network_changed_cb,
+      "button_network", "clicked",
+          account_widget_irc_button_edit_network_clicked_cb,
+      "button_add_network", "clicked",
+          account_widget_irc_button_add_network_clicked_cb,
+      "button_remove_network", "clicked",
+          account_widget_irc_button_remove_clicked_cb,
+      "combobox_network", "changed",
+          account_widget_irc_combobox_network_changed_cb,
       NULL);
 
   empathy_account_widget_set_default_focus (gui, "entry_nick");
+  empathy_account_widget_add_apply_button (account_settings,
+    settings->vbox_settings);
 
   return empathy_builder_unref_and_keep_widget (gui, settings->vbox_settings);
 }
diff --git a/libempathy-gtk/empathy-account-widget-irc.h b/libempathy-gtk/empathy-account-widget-irc.h
index 40e58bb..0373238 100644
--- a/libempathy-gtk/empathy-account-widget-irc.h
+++ b/libempathy-gtk/empathy-account-widget-irc.h
@@ -22,11 +22,11 @@
 #define __EMPATHY_ACCOUNT_WIDGET_IRC_H__
 
 #include <gtk/gtk.h>
-#include <libempathy/empathy-account.h>
+#include <libempathy/empathy-account-settings.h>
 
 G_BEGIN_DECLS
 
-GtkWidget * empathy_account_widget_irc_new (EmpathyAccount *account);
+GtkWidget * empathy_account_widget_irc_new (EmpathyAccountSettings *settings);
 
 G_END_DECLS
 
diff --git a/libempathy-gtk/empathy-account-widget-sip.c b/libempathy-gtk/empathy-account-widget-sip.c
index ad8cd7d..9f08046 100644
--- a/libempathy-gtk/empathy-account-widget-sip.c
+++ b/libempathy-gtk/empathy-account-widget-sip.c
@@ -35,7 +35,7 @@
 #include "empathy-ui-utils.h"
 
 typedef struct {
-  EmpathyAccount *account;
+  EmpathyAccountSettings *settings;
 
   GtkWidget *vbox_settings;
 
@@ -48,7 +48,7 @@ static void
 account_widget_sip_destroy_cb (GtkWidget *widget,
                                EmpathyAccountWidgetSip *settings)
 {
-  g_object_unref (settings->account);
+  g_object_unref (settings->settings);
   g_slice_free (EmpathyAccountWidgetSip, settings);
 }
 
@@ -73,14 +73,14 @@ account_widget_sip_discover_stun_toggled_cb (
  * Returns: The toplevel container of the configuration widget
  */
 GtkWidget *
-empathy_account_widget_sip_new (EmpathyAccount *account)
+empathy_account_widget_sip_new (EmpathyAccountSettings *account_settings)
 {
   EmpathyAccountWidgetSip *settings;
   GtkBuilder *gui;
   gchar *filename;
 
   settings = g_slice_new0 (EmpathyAccountWidgetSip);
-  settings->account = g_object_ref (account);
+  settings->settings = g_object_ref (account_settings);
 
   filename = empathy_file_lookup ("empathy-account-widget-sip.ui",
       "libempathy-gtk");
@@ -92,7 +92,7 @@ empathy_account_widget_sip_new (EmpathyAccount *account)
       NULL);
   g_free (filename);
 
-  empathy_account_widget_handle_params (account, gui,
+  empathy_account_widget_handle_params (account_settings, gui,
       "entry_userid", "account",
       "entry_password", "password",
       "checkbutton_discover-stun", "discover-stun",
@@ -100,19 +100,23 @@ empathy_account_widget_sip_new (EmpathyAccount *account)
       "spinbutton_stun-port", "stun-port",
       NULL);
 
-  empathy_account_widget_add_forget_button (account, gui,
+  empathy_account_widget_add_forget_button (account_settings, gui,
                                             "button_forget",
                                             "entry_password");
 
-  account_widget_sip_discover_stun_toggled_cb (settings->checkbutton_discover_stun,
-                                               settings);
+  account_widget_sip_discover_stun_toggled_cb (
+    settings->checkbutton_discover_stun,
+    settings);
 
   empathy_builder_connect (gui, settings,
       "vbox_sip_settings", "destroy", account_widget_sip_destroy_cb,
-      "checkbutton_discover-stun", "toggled", account_widget_sip_discover_stun_toggled_cb,
+      "checkbutton_discover-stun", "toggled",
+          account_widget_sip_discover_stun_toggled_cb,
       NULL);
 
   empathy_account_widget_set_default_focus (gui, "entry_userid");
+  empathy_account_widget_add_apply_button (account_settings,
+    settings->vbox_settings);
 
   return empathy_builder_unref_and_keep_widget (gui, settings->vbox_settings);
 }
diff --git a/libempathy-gtk/empathy-account-widget-sip.h b/libempathy-gtk/empathy-account-widget-sip.h
index 69f60aa..15dd724 100644
--- a/libempathy-gtk/empathy-account-widget-sip.h
+++ b/libempathy-gtk/empathy-account-widget-sip.h
@@ -22,11 +22,11 @@
 #define __EMPATHY_ACCOUNT_WIDGET_SIP_H__
 
 #include <gtk/gtk.h>
-#include <libempathy/empathy-account.h>
+#include <libempathy/empathy-account-settings.h>
 
 G_BEGIN_DECLS
 
-GtkWidget * empathy_account_widget_sip_new (EmpathyAccount *account);
+GtkWidget * empathy_account_widget_sip_new (EmpathyAccountSettings *settings);
 
 G_END_DECLS
 
diff --git a/libempathy-gtk/empathy-account-widget.c b/libempathy-gtk/empathy-account-widget.c
index 783a48a..ea0a05b 100644
--- a/libempathy-gtk/empathy-account-widget.c
+++ b/libempathy-gtk/empathy-account-widget.c
@@ -33,6 +33,7 @@
 #include <libempathy/empathy-account.h>
 
 #include <telepathy-glib/connection-manager.h>
+#include <dbus/dbus-protocol.h>
 
 #include "empathy-account-widget.h"
 #include "empathy-ui-utils.h"
@@ -43,7 +44,7 @@
 static gboolean
 account_widget_entry_focus_cb (GtkWidget     *widget,
 			       GdkEventFocus *event,
-			       EmpathyAccount     *account)
+			       EmpathyAccountSettings *settings)
 {
 	const gchar *str;
 	const gchar *param_name;
@@ -54,14 +55,14 @@ account_widget_entry_focus_cb (GtkWidget     *widget,
 	if (EMP_STR_EMPTY (str)) {
 		const gchar *value = NULL;
 
-		empathy_account_unset_param (account, param_name);
-		value = empathy_account_get_param_string (account, param_name);
+		empathy_account_settings_unset (settings, param_name);
+		value = empathy_account_settings_get_string (settings, param_name);
 		DEBUG ("Unset %s and restore to %s", param_name, value);
 		gtk_entry_set_text (GTK_ENTRY (widget), value ? value : "");
 	} else {
 		DEBUG ("Setting %s to %s", param_name,
 			strstr (param_name, "password") ? "***" : str);
-		empathy_account_set_param_string (account, param_name, str);
+		empathy_account_settings_set_string (settings, param_name, str);
 	}
 
 	return FALSE;
@@ -69,28 +70,44 @@ account_widget_entry_focus_cb (GtkWidget     *widget,
 
 static void
 account_widget_int_changed_cb (GtkWidget *widget,
-			       EmpathyAccount *account)
+			       EmpathyAccountSettings *settings)
 {
 	const gchar *param_name;
 	gint         value;
+	const gchar *signature;
 
 	value = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (widget));
 	param_name = g_object_get_data (G_OBJECT (widget), "param_name");
 
-	if (value == 0) {
-		empathy_account_unset_param (account, param_name);
-		value = empathy_account_get_param_int (account, param_name);
-		DEBUG ("Unset %s and restore to %d", param_name, value);
-		gtk_spin_button_set_value (GTK_SPIN_BUTTON (widget), value);
-	} else {
-		DEBUG ("Setting %s to %d", param_name, value);
-		empathy_account_set_param_int (account, param_name, value);
-	}
+	signature = empathy_settings_get_dbus_signature (settings, param_name);
+	g_return_if_fail (signature != NULL);
+
+	DEBUG ("Setting %s to %d", param_name, value);
+
+	switch ((int)*signature)
+		{
+			case DBUS_TYPE_INT16:
+			case DBUS_TYPE_INT32:
+				empathy_account_settings_set_int32 (settings, param_name, value);
+				break;
+			case DBUS_TYPE_INT64:
+				empathy_account_settings_set_int64 (settings, param_name, value);
+				break;
+			case DBUS_TYPE_UINT16:
+			case DBUS_TYPE_UINT32:
+				empathy_account_settings_set_uint32 (settings, param_name, value);
+				break;
+			case DBUS_TYPE_UINT64:
+				empathy_account_settings_set_uint64 (settings, param_name, value);
+				break;
+			default:
+				g_return_if_reached ();
+		}
 }
 
 static void
 account_widget_checkbutton_toggled_cb (GtkWidget *widget,
-				       EmpathyAccount *account)
+				       EmpathyAccountSettings *settings)
 {
 	gboolean     value;
 	gboolean     default_value;
@@ -102,14 +119,14 @@ account_widget_checkbutton_toggled_cb (GtkWidget *widget,
 	/* FIXME: This is ugly! checkbox don't have a "not-set" value so we
 	 * always unset the param and set the value if different from the
 	 * default value. */
-	empathy_account_unset_param (account, param_name);
-	default_value = empathy_account_get_param_boolean (account, param_name);
+	empathy_account_settings_unset (settings, param_name);
+	default_value = empathy_account_settings_get_boolean (settings, param_name);
 
 	if (default_value == value) {
 		DEBUG ("Unset %s and restore to %d", param_name, default_value);
 	} else {
 		DEBUG ("Setting %s to %d", param_name, value);
-		empathy_account_set_param_boolean (account, param_name, value);
+		empathy_account_settings_set_boolean (settings, param_name, value);
 	}
 }
 
@@ -117,14 +134,14 @@ static void
 account_widget_forget_clicked_cb (GtkWidget *button,
 				  GtkWidget *entry)
 {
-	EmpathyAccount   *account;
+	EmpathyAccountSettings *settings;
 	const gchar *param_name;
 
 	param_name = g_object_get_data (G_OBJECT (entry), "param_name");
-	account = g_object_get_data (G_OBJECT (entry), "account");
+	settings = g_object_get_data (G_OBJECT (entry), "settings");
 
 	DEBUG ("Unset %s", param_name);
-	empathy_account_unset_param (account, param_name);
+	empathy_account_settings_unset (settings, param_name);
 	gtk_entry_set_text (GTK_ENTRY (entry), "");
 }
 
@@ -142,13 +159,13 @@ static void
 account_widget_jabber_ssl_toggled_cb (GtkWidget *checkbutton_ssl,
 				      GtkWidget *spinbutton_port)
 {
-	EmpathyAccount *account;
+	EmpathyAccountSettings *settings;
 	gboolean   value;
-	gint       port = 0;
+	gint32       port = 0;
 
 	value = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (checkbutton_ssl));
-	account = g_object_get_data (G_OBJECT (spinbutton_port), "account");
-	port = empathy_account_get_param_int (account, "port");
+	settings = g_object_get_data (G_OBJECT (spinbutton_port), "settings");
+	port = empathy_account_settings_get_uint32 (settings, "port");
 
 	if (value) {
 		if (port == 5222 || port == 0) {
@@ -165,28 +182,51 @@ account_widget_jabber_ssl_toggled_cb (GtkWidget *checkbutton_ssl,
 
 static void
 account_widget_setup_widget (GtkWidget   *widget,
-			     EmpathyAccount   *account,
+			     EmpathyAccountSettings *settings,
 			     const gchar *param_name)
 {
 	g_object_set_data_full (G_OBJECT (widget), "param_name",
 				g_strdup (param_name), g_free);
-	g_object_set_data_full (G_OBJECT (widget), "account",
-				g_object_ref (account), g_object_unref);
+	g_object_set_data_full (G_OBJECT (widget), "settings",
+				g_object_ref (settings), g_object_unref);
 
 	if (GTK_IS_SPIN_BUTTON (widget)) {
 		gint value = 0;
+		const gchar *signature;
+
+		signature = empathy_settings_get_dbus_signature (settings, param_name);
+		g_return_if_fail (signature != NULL);
+
+		switch ((int)*signature)
+			{
+				case DBUS_TYPE_INT16:
+				case DBUS_TYPE_INT32:
+					value = empathy_account_settings_get_int32 (settings, param_name);
+					break;
+				case DBUS_TYPE_INT64:
+					value = empathy_account_settings_get_int64 (settings, param_name);
+					break;
+				case DBUS_TYPE_UINT16:
+				case DBUS_TYPE_UINT32:
+					value = empathy_account_settings_get_uint32 (settings, param_name);
+					break;
+				case DBUS_TYPE_UINT64:
+					value = empathy_account_settings_get_uint64 (settings, param_name);
+					break;
+				default:
+					g_return_if_reached ();
+			}
 
-		value = empathy_account_get_param_int (account, param_name);
 		gtk_spin_button_set_value (GTK_SPIN_BUTTON (widget), value);
 
 		g_signal_connect (widget, "value-changed",
 				  G_CALLBACK (account_widget_int_changed_cb),
-				  account);
+				  settings);
 	}
 	else if (GTK_IS_ENTRY (widget)) {
 		const gchar *str = NULL;
 
-		str = empathy_account_get_param_string (account, param_name);
+		str = empathy_account_settings_get_string (settings, param_name);
 		gtk_entry_set_text (GTK_ENTRY (widget), str ? str : "");
 
 		if (strstr (param_name, "password")) {
@@ -195,17 +235,17 @@ account_widget_setup_widget (GtkWidget   *widget,
 
 		g_signal_connect (widget, "focus-out-event",
 				  G_CALLBACK (account_widget_entry_focus_cb),
-				  account);
+				  settings);
 	}
 	else if (GTK_IS_TOGGLE_BUTTON (widget)) {
 		gboolean value = FALSE;
 
-		value = empathy_account_get_param_boolean (account, param_name);
+		value = empathy_account_settings_get_boolean (settings, param_name);
 		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), value);
 
 		g_signal_connect (widget, "toggled",
 				  G_CALLBACK (account_widget_checkbutton_toggled_cb),
-				  account);
+				  settings);
 	} else {
 		DEBUG ("Unknown type of widget for param %s", param_name);
 	}
@@ -236,14 +276,15 @@ account_widget_generic_format_param_name (const gchar *param_name)
 }
 
 static void
-accounts_widget_generic_setup (EmpathyAccount *account,
-			       TpConnectionManagerParam *params,
+accounts_widget_generic_setup (EmpathyAccountSettings *settings,
 			       GtkWidget *table_common_settings,
 			       GtkWidget *table_advanced_settings)
 {
-	TpConnectionManagerParam *param;
+	TpConnectionManagerParam *params, *param;
+
+	params = empathy_account_settings_get_tp_params (settings);
 
-	for (param = params; param != NULL; param++) {
+	for (param = params; param != NULL && param->name != NULL; param++) {
 		GtkWidget       *table_settings;
 		guint            n_rows = 0;
 		GtkWidget       *widget = NULL;
@@ -350,7 +391,7 @@ accounts_widget_generic_setup (EmpathyAccount *account,
 		}
 
 		if (widget) {
-			account_widget_setup_widget (widget, account, param->name);
+			account_widget_setup_widget (widget, settings, param->name);
 		}
 
 		g_free (param_name_formatted);
@@ -358,7 +399,7 @@ accounts_widget_generic_setup (EmpathyAccount *account,
 }
 
 static void
-account_widget_handle_params_valist (EmpathyAccount   *account,
+account_widget_handle_params_valist (EmpathyAccountSettings   *settings,
 				     GtkBuilder  *gui,
 				     const gchar *first_widget,
 				     va_list      args)
@@ -377,12 +418,12 @@ account_widget_handle_params_valist (EmpathyAccount   *account,
 			continue;
 		}
 
-		account_widget_setup_widget (GTK_WIDGET (object), account, param_name);
+		account_widget_setup_widget (GTK_WIDGET (object), settings, param_name);
 	}
 }
 
 void
-empathy_account_widget_handle_params (EmpathyAccount   *account,
+empathy_account_widget_handle_params (EmpathyAccountSettings   *settings,
 				      GtkBuilder  *gui,
 				      const gchar *first_widget,
 				      ...)
@@ -392,12 +433,35 @@ empathy_account_widget_handle_params (EmpathyAccount   *account,
 	g_return_if_fail (GTK_IS_BUILDER (gui));
 
 	va_start (args, first_widget);
-	account_widget_handle_params_valist (account, gui, first_widget, args);
+	account_widget_handle_params_valist (settings, gui, first_widget, args);
 	va_end (args);
 }
 
+static void
+account_widget_apply_clicked_cb (GtkWidget *button,
+				 EmpathyAccountSettings *settings)
+{
+  empathy_account_settings_apply_async (settings, NULL, NULL);
+}
+
+void
+empathy_account_widget_add_apply_button (EmpathyAccountSettings *settings,
+					 GtkWidget *vbox)
+{
+	GtkWidget *button;
+
+	button = gtk_button_new_from_stock (GTK_STOCK_APPLY);
+
+	gtk_box_pack_end (GTK_BOX (vbox), button, FALSE, FALSE, 3);
+
+	g_signal_connect (button, "clicked",
+			  G_CALLBACK (account_widget_apply_clicked_cb),
+			  settings);
+	gtk_widget_show (button);
+}
+
 void
-empathy_account_widget_add_forget_button (EmpathyAccount   *account,
+empathy_account_widget_add_forget_button (EmpathyAccountSettings   *settings,
 					  GtkBuilder  *gui,
 					  const gchar *button,
 					  const gchar *entry)
@@ -409,7 +473,7 @@ empathy_account_widget_add_forget_button (EmpathyAccount   *account,
 	button_forget = GTK_WIDGET (gtk_builder_get_object (gui, button));
 	entry_password = GTK_WIDGET (gtk_builder_get_object (gui, entry));
 
-	password = empathy_account_get_param_string (account, "password");
+	password = empathy_account_settings_get_string (settings, "password");
 	gtk_widget_set_sensitive (button_forget, !EMP_STR_EMPTY (password));
 
 	g_signal_connect (button_forget, "clicked",
@@ -433,37 +497,33 @@ empathy_account_widget_set_default_focus (GtkBuilder  *gui,
 }
 
 static void
-account_widget_tp_cm_ready_cb (TpConnectionManager *cm, const GError *error,
-		gpointer user_data, GObject *weak_object)
+account_widget_setup_generic (EmpathyAccountSettings *settings,
+  GtkBuilder *builder)
 {
-	GtkBuilder *builder;
-	EmpathyAccount *account;
 	GtkWidget *table_common_settings;
 	GtkWidget *table_advanced_settings;
-	const TpConnectionManagerProtocol *protocol;
-
-	if (error != NULL) {
-		DEBUG ("CM wasn't happy: %s", error->message);
-		return;
-	}
-
-	account = EMPATHY_ACCOUNT (user_data);
-	builder = GTK_BUILDER (weak_object);
 
 	table_common_settings = GTK_WIDGET (gtk_builder_get_object (builder,
 		"table_common_settings"));
 	table_advanced_settings = GTK_WIDGET (gtk_builder_get_object (builder,
 		"table_advanced_settings"));
 
-	protocol = tp_connection_manager_get_protocol (cm,
-		empathy_account_get_protocol (account));
+	accounts_widget_generic_setup (settings, table_common_settings,
+		table_advanced_settings);
+}
 
-	accounts_widget_generic_setup (account, protocol->params,
-		table_common_settings, table_advanced_settings);
+static void
+account_widget_settings_ready_cb (EmpathyAccountSettings *settings,
+  GParamSpec *pspec, gpointer user_data)
+{
+	GtkBuilder *builder = GTK_BUILDER (user_data);
+
+	if (empathy_account_settings_is_ready (settings))
+		account_widget_setup_generic (settings, builder);
 }
 
 GtkWidget *
-empathy_account_widget_generic_new (EmpathyAccount *account)
+empathy_account_widget_generic_new (EmpathyAccountSettings *settings)
 {
 	GtkBuilder *gui;
 	GtkWidget *widget;
@@ -475,38 +535,19 @@ empathy_account_widget_generic_new (EmpathyAccount *account)
 					"vbox_generic_settings", &widget,
 					NULL);
 
-	/* If the profile isn't installed get_protocol will return NULL with MC4 */
-	if (empathy_account_get_protocol (account) != NULL) {
-		TpDBusDaemon *dbus;
-		TpConnectionManager *cm;
-		GError *error;
-
-		dbus = tp_dbus_daemon_dup (NULL);
+	if (empathy_account_settings_is_ready (settings))
+		account_widget_setup_generic (settings, gui);
+	else
+		g_signal_connect (settings, "notify::ready",
+			G_CALLBACK (account_widget_settings_ready_cb), gui);
 
-		cm = tp_connection_manager_new (dbus,
-			empathy_account_get_connection_manager (account), NULL, &error);
-
-		if (cm == NULL) {
-			DEBUG ("failed to get the cm: %s", error->message);
-			g_error_free (error);
-			g_object_unref (gui);
-			return NULL;
-		}
-
-		tp_connection_manager_call_when_ready (cm, account_widget_tp_cm_ready_cb,
-			account, g_object_unref, G_OBJECT (gui));
-
-		g_object_unref (dbus);
-	} else {
-		/* no protocol information available :(( */
-		return empathy_builder_unref_and_keep_widget (gui, widget);
-	}
+	empathy_account_widget_add_apply_button (settings, widget);
 
 	return g_object_ref (widget);
 }
 
 GtkWidget *
-empathy_account_widget_salut_new (EmpathyAccount *account)
+empathy_account_widget_salut_new (EmpathyAccountSettings *settings)
 {
 	GtkBuilder *gui;
 	GtkWidget *widget;
@@ -519,7 +560,7 @@ empathy_account_widget_salut_new (EmpathyAccount *account)
 					NULL);
 	g_free (filename);
 
-	empathy_account_widget_handle_params (account, gui,
+	empathy_account_widget_handle_params (settings, gui,
 			"entry_published", "published-name",
 			"entry_nickname", "nickname",
 			"entry_first_name", "first-name",
@@ -534,7 +575,7 @@ empathy_account_widget_salut_new (EmpathyAccount *account)
 }
 
 GtkWidget *
-empathy_account_widget_msn_new (EmpathyAccount *account)
+empathy_account_widget_msn_new (EmpathyAccountSettings *settings)
 {
 	GtkBuilder *gui;
 	GtkWidget *widget;
@@ -547,14 +588,14 @@ empathy_account_widget_msn_new (EmpathyAccount *account)
 					NULL);
 	g_free (filename);
 
-	empathy_account_widget_handle_params (account, gui,
+	empathy_account_widget_handle_params (settings, gui,
 			"entry_id", "account",
 			"entry_password", "password",
 			"entry_server", "server",
 			"spinbutton_port", "port",
 			NULL);
 
-	empathy_account_widget_add_forget_button (account, gui,
+	empathy_account_widget_add_forget_button (settings, gui,
 						  "button_forget",
 						  "entry_password");
 
@@ -564,7 +605,7 @@ empathy_account_widget_msn_new (EmpathyAccount *account)
 }
 
 GtkWidget *
-empathy_account_widget_jabber_new (EmpathyAccount *account)
+empathy_account_widget_jabber_new (EmpathyAccountSettings *settings)
 {
 	GtkBuilder *gui;
 	GtkWidget *widget;
@@ -581,7 +622,7 @@ empathy_account_widget_jabber_new (EmpathyAccount *account)
 				        NULL);
 	g_free (filename);
 
-	empathy_account_widget_handle_params (account, gui,
+	empathy_account_widget_handle_params (settings, gui,
 			"entry_id", "account",
 			"entry_password", "password",
 			"entry_resource", "resource",
@@ -593,7 +634,7 @@ empathy_account_widget_jabber_new (EmpathyAccount *account)
 			"checkbutton_encryption", "require-encryption",
 			NULL);
 
-	empathy_account_widget_add_forget_button (account, gui,
+	empathy_account_widget_add_forget_button (settings, gui,
 						  "button_forget",
 						  "entry_password");
 
@@ -603,11 +644,13 @@ empathy_account_widget_jabber_new (EmpathyAccount *account)
 			  G_CALLBACK (account_widget_jabber_ssl_toggled_cb),
 			  spinbutton_port);
 
+	empathy_account_widget_add_apply_button (settings, widget);
+
 	return empathy_builder_unref_and_keep_widget (gui, widget);
 }
 
 GtkWidget *
-empathy_account_widget_icq_new (EmpathyAccount *account)
+empathy_account_widget_icq_new (EmpathyAccountSettings *settings)
 {
 	GtkBuilder *gui;
 	GtkWidget *widget;
@@ -622,7 +665,7 @@ empathy_account_widget_icq_new (EmpathyAccount *account)
 				        NULL);
 	g_free (filename);
 
-	empathy_account_widget_handle_params (account, gui,
+	empathy_account_widget_handle_params (settings, gui,
 			"entry_uin", "account",
 			"entry_password", "password",
 			"entry_server", "server",
@@ -630,17 +673,19 @@ empathy_account_widget_icq_new (EmpathyAccount *account)
 			"entry_charset", "charset",
 			NULL);
 
-	empathy_account_widget_add_forget_button (account, gui,
+	empathy_account_widget_add_forget_button (settings, gui,
 						  "button_forget",
 						  "entry_password");
 
 	empathy_account_widget_set_default_focus (gui, "entry_uin");
 
+	empathy_account_widget_add_apply_button (settings, widget);
+
 	return empathy_builder_unref_and_keep_widget (gui, widget);
 }
 
 GtkWidget *
-empathy_account_widget_aim_new (EmpathyAccount *account)
+empathy_account_widget_aim_new (EmpathyAccountSettings *settings)
 {
 	GtkBuilder *gui;
 	GtkWidget *widget;
@@ -655,24 +700,25 @@ empathy_account_widget_aim_new (EmpathyAccount *account)
 				        NULL);
 	g_free (filename);
 
-	empathy_account_widget_handle_params (account, gui,
+	empathy_account_widget_handle_params (settings, gui,
 			"entry_screenname", "account",
 			"entry_password", "password",
 			"entry_server", "server",
 			"spinbutton_port", "port",
 			NULL);
 
-	empathy_account_widget_add_forget_button (account, gui,
+	empathy_account_widget_add_forget_button (settings, gui,
 						  "button_forget",
 						  "entry_password");
 
 	empathy_account_widget_set_default_focus (gui, "entry_screenname");
+	empathy_account_widget_add_apply_button (settings, widget);
 
 	return empathy_builder_unref_and_keep_widget (gui, widget);
 }
 
 GtkWidget *
-empathy_account_widget_yahoo_new (EmpathyAccount *account)
+empathy_account_widget_yahoo_new (EmpathyAccountSettings *settings)
 {
 	GtkBuilder *gui;
 	GtkWidget *widget;
@@ -685,7 +731,7 @@ empathy_account_widget_yahoo_new (EmpathyAccount *account)
 					NULL);
 	g_free (filename);
 
-	empathy_account_widget_handle_params (account, gui,
+	empathy_account_widget_handle_params (settings, gui,
 			"entry_id", "account",
 			"entry_password", "password",
 			"entry_server", "server",
@@ -696,17 +742,18 @@ empathy_account_widget_yahoo_new (EmpathyAccount *account)
 			"checkbutton_ignore_invites", "ignore-invites",
 			NULL);
 
-	empathy_account_widget_add_forget_button (account, gui,
+	empathy_account_widget_add_forget_button (settings, gui,
 						  "button_forget",
 						  "entry_password");
 
 	empathy_account_widget_set_default_focus (gui, "entry_id");
+	empathy_account_widget_add_apply_button (settings, widget);
 
 	return empathy_builder_unref_and_keep_widget (gui, widget);
 }
 
 GtkWidget *
-empathy_account_widget_groupwise_new (EmpathyAccount *account)
+empathy_account_widget_groupwise_new (EmpathyAccountSettings *settings)
 {
 	GtkBuilder *gui;
 	GtkWidget *widget;
@@ -719,18 +766,19 @@ empathy_account_widget_groupwise_new (EmpathyAccount *account)
 					NULL);
 	g_free (filename);
 
-	empathy_account_widget_handle_params (account, gui,
+	empathy_account_widget_handle_params (settings, gui,
 			"entry_id", "account",
 			"entry_password", "password",
 			"entry_server", "server",
 			"spinbutton_port", "port",
 			NULL);
 
-	empathy_account_widget_add_forget_button (account, gui,
+	empathy_account_widget_add_forget_button (settings, gui,
 						  "button_forget",
 						  "entry_password");
 
 	empathy_account_widget_set_default_focus (gui, "entry_id");
+	empathy_account_widget_add_apply_button (settings, widget);
 
 	return empathy_builder_unref_and_keep_widget (gui, widget);
 }
diff --git a/libempathy-gtk/empathy-account-widget.h b/libempathy-gtk/empathy-account-widget.h
index 7a76db9..f05c660 100644
--- a/libempathy-gtk/empathy-account-widget.h
+++ b/libempathy-gtk/empathy-account-widget.h
@@ -27,28 +27,31 @@
 
 #include <gtk/gtk.h>
 
-#include <libempathy/empathy-account.h>
+#include <libempathy/empathy-account-settings.h>
 
 G_BEGIN_DECLS
 
-void       empathy_account_widget_handle_params     (EmpathyAccount   *account,
+void       empathy_account_widget_handle_params     (EmpathyAccountSettings   *settings,
 						     GtkBuilder  *gui,
 						     const gchar *first_widget,
 						     ...);
-void       empathy_account_widget_add_forget_button (EmpathyAccount   *account,
+void       empathy_account_widget_add_forget_button (EmpathyAccountSettings   *settings,
 						     GtkBuilder  *gui,
 						     const gchar *button,
 						     const gchar *entry);
+void empathy_account_widget_add_apply_button (EmpathyAccountSettings *settings,
+					      GtkWidget *vbox);
+
 void	   empathy_account_widget_set_default_focus (GtkBuilder  *gui,
 						     const gchar *entry);
-GtkWidget *empathy_account_widget_generic_new       (EmpathyAccount   *account);
-GtkWidget *empathy_account_widget_salut_new         (EmpathyAccount   *account);
-GtkWidget *empathy_account_widget_msn_new           (EmpathyAccount   *account);
-GtkWidget *empathy_account_widget_jabber_new        (EmpathyAccount   *account);
-GtkWidget *empathy_account_widget_icq_new           (EmpathyAccount   *account);
-GtkWidget *empathy_account_widget_aim_new           (EmpathyAccount   *account);
-GtkWidget *empathy_account_widget_yahoo_new         (EmpathyAccount   *account);
-GtkWidget *empathy_account_widget_groupwise_new     (EmpathyAccount   *account);
+GtkWidget *empathy_account_widget_generic_new       (EmpathyAccountSettings   *settings);
+GtkWidget *empathy_account_widget_salut_new         (EmpathyAccountSettings   *settings);
+GtkWidget *empathy_account_widget_msn_new           (EmpathyAccountSettings   *settings);
+GtkWidget *empathy_account_widget_jabber_new        (EmpathyAccountSettings   *settings);
+GtkWidget *empathy_account_widget_icq_new           (EmpathyAccountSettings   *settings);
+GtkWidget *empathy_account_widget_aim_new           (EmpathyAccountSettings   *settings);
+GtkWidget *empathy_account_widget_yahoo_new         (EmpathyAccountSettings   *settings);
+GtkWidget *empathy_account_widget_groupwise_new     (EmpathyAccountSettings   *settings);
 
 G_END_DECLS
 
diff --git a/src/empathy-accounts-dialog.c b/src/empathy-accounts-dialog.c
index 080a6ca..d6a29ea 100644
--- a/src/empathy-accounts-dialog.c
+++ b/src/empathy-accounts-dialog.c
@@ -84,6 +84,9 @@ typedef struct {
 	gboolean          connecting_show;
 	guint             connecting_id;
 
+	gulong            settings_ready_id;
+	EmpathyAccountSettings *settings_ready;
+
 	EmpathyAccountManager *account_manager;
 } EmpathyAccountsDialog;
 
@@ -92,11 +95,12 @@ enum {
 	COL_NAME,
 	COL_STATUS,
 	COL_ACCOUNT_POINTER,
+	COL_ACCOUNT_SETTINGS_POINTER,
 	COL_COUNT
 };
 
-static void       accounts_dialog_update_account            (EmpathyAccountsDialog    *dialog,
-							     EmpathyAccount           *account);
+static void       accounts_dialog_update (EmpathyAccountsDialog    *dialog,
+							     EmpathyAccountSettings           *settings);
 static void       accounts_dialog_model_setup               (EmpathyAccountsDialog    *dialog);
 static void       accounts_dialog_model_add_columns         (EmpathyAccountsDialog    *dialog);
 static void       accounts_dialog_name_editing_started_cb   (GtkCellRenderer          *renderer,
@@ -109,14 +113,11 @@ static void       accounts_dialog_model_pixbuf_data_func    (GtkTreeViewColumn
 							     GtkTreeModel             *model,
 							     GtkTreeIter              *iter,
 							     EmpathyAccountsDialog    *dialog);
-static EmpathyAccount *accounts_dialog_model_get_selected        (EmpathyAccountsDialog    *dialog);
 static void       accounts_dialog_model_set_selected        (EmpathyAccountsDialog    *dialog,
-							     EmpathyAccount           *account);
+							     EmpathyAccountSettings *settings);
 static gboolean   accounts_dialog_model_remove_selected     (EmpathyAccountsDialog    *dialog);
 static void       accounts_dialog_model_selection_changed   (GtkTreeSelection         *selection,
 							     EmpathyAccountsDialog    *dialog);
-static void       accounts_dialog_add_or_update_account     (EmpathyAccountsDialog    *dialog,
-							     EmpathyAccount           *account);
 static void       accounts_dialog_account_added_cb          (EmpathyAccountManager    *manager,
 							     EmpathyAccount           *account,
 							     EmpathyAccountsDialog    *dialog);
@@ -157,24 +158,24 @@ static void       accounts_dialog_destroy_cb                (GtkWidget
 
 static void
 accounts_dialog_update_name_label (EmpathyAccountsDialog *dialog,
-				   EmpathyAccount        *account)
+				   EmpathyAccountSettings *settings)
 {
 	gchar *text;
 
 	text = g_markup_printf_escaped ("<big><b>%s</b></big>",
-			empathy_account_get_display_name (account));
+			empathy_account_settings_get_display_name (settings));
 	gtk_label_set_markup (GTK_LABEL (dialog->label_name), text);
 
 	g_free (text);
 }
 
-typedef GtkWidget *CreateWidget (EmpathyAccount *);
+typedef GtkWidget *CreateWidget (EmpathyAccountSettings *);
 
 static GtkWidget *
-get_account_setup_widget (EmpathyAccount *account)
+get_account_setup_widget (EmpathyAccountSettings *settings)
 {
-	const gchar *cm = empathy_account_get_connection_manager (account);
-	const gchar *proto = empathy_account_get_protocol (account);
+	const gchar *cm = empathy_account_settings_get_cm (settings);
+	const gchar *proto = empathy_account_settings_get_protocol (settings);
 	struct {
 		const gchar *cm;
 		const gchar *proto;
@@ -196,18 +197,53 @@ get_account_setup_widget (EmpathyAccount *account)
 	for (i = 0; dialogs[i].cm != NULL; i++) {
 		if (!tp_strdiff (cm, dialogs[i].cm)
 			&& !tp_strdiff (proto, dialogs[i].proto))
-				return dialogs[i].cb(account);
+				return dialogs[i].cb (settings);
 	}
 
-	return empathy_account_widget_generic_new (account);
+	return empathy_account_widget_generic_new (settings);
 }
 
 
 static void
-accounts_dialog_update_account (EmpathyAccountsDialog *dialog,
-				EmpathyAccount       *account)
+account_dialog_create_settings_widget (EmpathyAccountsDialog *dialog,
+	EmpathyAccountSettings *settings)
+{
+	dialog->settings_widget = get_account_setup_widget (settings);
+
+	gtk_container_add (GTK_CONTAINER (dialog->alignment_settings),
+			   dialog->settings_widget);
+	gtk_widget_show (dialog->settings_widget);
+
+
+	gtk_image_set_from_icon_name (GTK_IMAGE (dialog->image_type),
+				      empathy_account_settings_get_icon_name (settings),
+				      GTK_ICON_SIZE_DIALOG);
+	gtk_widget_set_tooltip_text (dialog->image_type,
+				     empathy_account_settings_get_protocol (settings));
+
+	accounts_dialog_update_name_label (dialog, settings);
+}
+
+static void
+account_dialog_settings_ready_cb (EmpathyAccountSettings *settings,
+	GParamSpec *spec, EmpathyAccountsDialog *dialog)
+{
+	if (empathy_account_settings_is_ready (settings))
+		account_dialog_create_settings_widget (dialog, settings);
+}
+
+static void
+accounts_dialog_update_settings (EmpathyAccountsDialog *dialog,
+				EmpathyAccountSettings       *settings)
 {
-	if (!account) {
+	if (dialog->settings_ready != NULL) {
+			g_signal_handler_disconnect (dialog->settings_ready,
+				dialog->settings_ready_id);
+			dialog->settings_ready = NULL;
+			dialog->settings_ready_id = 0;
+	}
+
+	if (!settings) {
 		GtkTreeView  *view;
 		GtkTreeModel *model;
 
@@ -251,20 +287,18 @@ accounts_dialog_update_account (EmpathyAccountsDialog *dialog,
 		dialog->settings_widget = NULL;
 	}
 
-	dialog->settings_widget = get_account_setup_widget (account);
-
-	gtk_container_add (GTK_CONTAINER (dialog->alignment_settings),
-			   dialog->settings_widget);
-	gtk_widget_show (dialog->settings_widget);
-
-
-	gtk_image_set_from_icon_name (GTK_IMAGE (dialog->image_type),
-				      empathy_account_get_icon_name (account),
-				      GTK_ICON_SIZE_DIALOG);
-	gtk_widget_set_tooltip_text (dialog->image_type,
-				     empathy_account_get_protocol (account));
+	if (empathy_account_settings_is_ready (settings))
+		{
+			account_dialog_create_settings_widget (dialog, settings);
+		}
+	else
+		{
+			dialog->settings_ready = settings;
+			dialog->settings_ready_id =
+				g_signal_connect (settings, "notify::ready",
+					G_CALLBACK (account_dialog_settings_ready_cb), dialog);
+		}
 
-	accounts_dialog_update_name_label (dialog, account);
 }
 
 static void
@@ -277,7 +311,8 @@ accounts_dialog_model_setup (EmpathyAccountsDialog *dialog)
 				    G_TYPE_BOOLEAN,        /* enabled */
 				    G_TYPE_STRING,         /* name */
 				    G_TYPE_UINT,           /* status */
-				    EMPATHY_TYPE_ACCOUNT); /* account */
+				    EMPATHY_TYPE_ACCOUNT,   /* account */
+				    EMPATHY_TYPE_ACCOUNT_SETTINGS); /* settings */
 
 	gtk_tree_view_set_model (GTK_TREE_VIEW (dialog->treeview),
 				 GTK_TREE_MODEL (store));
@@ -303,7 +338,7 @@ accounts_dialog_name_edited_cb (GtkCellRendererText   *renderer,
 				gchar                 *new_text,
 				EmpathyAccountsDialog *dialog)
 {
-	EmpathyAccount    *account;
+	EmpathyAccountSettings    *settings;
 	GtkTreeModel *model;
 	GtkTreePath  *treepath;
 	GtkTreeIter   iter;
@@ -318,15 +353,16 @@ 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_POINTER, &account,
+			    COL_ACCOUNT_SETTINGS_POINTER, &settings,
 			    -1);
 	gtk_list_store_set (GTK_LIST_STORE (model), &iter,
 			    COL_NAME, new_text,
 			    -1);
 	gtk_tree_path_free (treepath);
 
-	empathy_account_set_display_name (account, new_text);
-	g_object_unref (account);
+	empathy_account_settings_set_display_name_async (settings, new_text,
+		NULL, NULL);
+	g_object_unref (settings);
 }
 
 static void
@@ -348,6 +384,9 @@ accounts_dialog_enable_toggled_cb (GtkCellRendererToggle *cell_renderer,
 			    -1);
 	gtk_tree_path_free (treepath);
 
+	if (account == NULL)
+		return;
+
 	enabled = empathy_account_is_enabled (account);
 	empathy_account_set_enabled (account, !enabled);
 
@@ -438,7 +477,7 @@ accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog)
 		selection = gtk_tree_view_get_selection (view);
 		gtk_tree_selection_select_iter (selection, &iter);
 	} else {
-		accounts_dialog_update_account (dialog, NULL);
+		accounts_dialog_update_settings (dialog, NULL);
 	}
 }
 
@@ -449,17 +488,17 @@ accounts_dialog_model_pixbuf_data_func (GtkTreeViewColumn    *tree_column,
 					GtkTreeIter          *iter,
 					EmpathyAccountsDialog *dialog)
 {
-	EmpathyAccount     *account;
+	EmpathyAccountSettings  *settings;
 	const gchar        *icon_name;
 	GdkPixbuf          *pixbuf;
 	TpConnectionStatus  status;
 
 	gtk_tree_model_get (model, iter,
 			    COL_STATUS, &status,
-			    COL_ACCOUNT_POINTER, &account,
+			    COL_ACCOUNT_SETTINGS_POINTER, &settings,
 			    -1);
 
-	icon_name = empathy_account_get_icon_name (account);
+	icon_name = empathy_account_settings_get_icon_name (settings);
 	pixbuf = empathy_pixbuf_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON);
 
 	if (pixbuf) {
@@ -488,15 +527,15 @@ accounts_dialog_model_pixbuf_data_func (GtkTreeViewColumn    *tree_column,
 		      "pixbuf", pixbuf,
 		      NULL);
 
-	g_object_unref (account);
+	g_object_unref (settings);
 	if (pixbuf) {
 		g_object_unref (pixbuf);
 	}
 }
 
 static gboolean
-accounts_dialog_get_account_iter (EmpathyAccountsDialog *dialog,
-				 EmpathyAccount        *account,
+accounts_dialog_get_settings_iter (EmpathyAccountsDialog *dialog,
+				 EmpathyAccountSettings *settings,
 				 GtkTreeIter           *iter)
 {
 	GtkTreeView      *view;
@@ -512,6 +551,42 @@ accounts_dialog_get_account_iter (EmpathyAccountsDialog *dialog,
 	for (ok = gtk_tree_model_get_iter_first (model, iter);
 	     ok;
 	     ok = gtk_tree_model_iter_next (model, iter)) {
+		EmpathyAccountSettings *this_settings;
+		gboolean   equal;
+
+		gtk_tree_model_get (model, iter,
+				    COL_ACCOUNT_SETTINGS_POINTER, &this_settings,
+				    -1);
+
+		equal = (this_settings == settings);
+		g_object_unref (this_settings);
+
+		if (equal) {
+			return TRUE;
+		}
+	}
+
+	return FALSE;
+}
+
+static gboolean
+accounts_dialog_get_account_iter (EmpathyAccountsDialog *dialog,
+				 EmpathyAccount *account,
+				 GtkTreeIter    *iter)
+{
+	GtkTreeView      *view;
+	GtkTreeSelection *selection;
+	GtkTreeModel     *model;
+	gboolean          ok;
+
+	/* Update the status in the model */
+	view = GTK_TREE_VIEW (dialog->treeview);
+	selection = gtk_tree_view_get_selection (view);
+	model = gtk_tree_view_get_model (view);
+
+	for (ok = gtk_tree_model_get_iter_first (model, iter);
+	     ok;
+	     ok = gtk_tree_model_iter_next (model, iter)) {
 		EmpathyAccount *this_account;
 		gboolean   equal;
 
@@ -519,7 +594,7 @@ accounts_dialog_get_account_iter (EmpathyAccountsDialog *dialog,
 				    COL_ACCOUNT_POINTER, &this_account,
 				    -1);
 
-		equal = empathy_account_equal (this_account, account);
+		equal = (this_account == account);
 		g_object_unref (this_account);
 
 		if (equal) {
@@ -530,8 +605,31 @@ accounts_dialog_get_account_iter (EmpathyAccountsDialog *dialog,
 	return FALSE;
 }
 
+static EmpathyAccountSettings *
+accounts_dialog_model_get_selected_settings (EmpathyAccountsDialog *dialog)
+{
+	GtkTreeView      *view;
+	GtkTreeModel     *model;
+	GtkTreeSelection *selection;
+	GtkTreeIter       iter;
+	EmpathyAccountSettings   *settings;
+
+	view = GTK_TREE_VIEW (dialog->treeview);
+	selection = gtk_tree_view_get_selection (view);
+
+	if (!gtk_tree_selection_get_selected (selection, &model, &iter)) {
+		return NULL;
+	}
+
+	gtk_tree_model_get (model, &iter,
+		COL_ACCOUNT_SETTINGS_POINTER, &settings, -1);
+
+	return settings;
+}
+
+
 static EmpathyAccount *
-accounts_dialog_model_get_selected (EmpathyAccountsDialog *dialog)
+accounts_dialog_model_get_selected_account (EmpathyAccountsDialog *dialog)
 {
 	GtkTreeView      *view;
 	GtkTreeModel     *model;
@@ -553,13 +651,13 @@ accounts_dialog_model_get_selected (EmpathyAccountsDialog *dialog)
 
 static void
 accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog,
-				    EmpathyAccount        *account)
+				    EmpathyAccountSettings        *settings)
 {
 	GtkTreeSelection *selection;
 	GtkTreeIter       iter;
 
 	selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dialog->treeview));
-	if (accounts_dialog_get_account_iter (dialog, account, &iter)) {
+	if (accounts_dialog_get_settings_iter (dialog, settings, &iter)) {
 		gtk_tree_selection_select_iter (selection, &iter);
 	}
 }
@@ -586,25 +684,48 @@ static void
 accounts_dialog_model_selection_changed (GtkTreeSelection     *selection,
 					 EmpathyAccountsDialog *dialog)
 {
-	EmpathyAccount    *account;
+	EmpathyAccountSettings *settings;
 	GtkTreeModel *model;
 	GtkTreeIter   iter;
 	gboolean      is_selection;
 
 	is_selection = gtk_tree_selection_get_selected (selection, &model, &iter);
 
-	account = accounts_dialog_model_get_selected (dialog);
-	accounts_dialog_update_account (dialog, account);
+	settings = accounts_dialog_model_get_selected_settings (dialog);
+	accounts_dialog_update_settings (dialog, settings);
 
-	if (account) {
-		g_object_unref (account);
+	if (settings) {
+		g_object_unref (settings);
 	}
 }
 
 static void
-accounts_dialog_add_or_update_account (EmpathyAccountsDialog *dialog,
+accounts_dialog_add (EmpathyAccountsDialog *dialog,
+				       EmpathyAccountSettings        *settings)
+{
+	GtkTreeModel       *model;
+	GtkTreeIter         iter;
+	const gchar        *name;
+
+	model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
+	name = empathy_account_settings_get_display_name (settings);
+
+	gtk_list_store_append (GTK_LIST_STORE (model), &iter);
+
+	gtk_list_store_set (GTK_LIST_STORE (model), &iter,
+			    COL_ENABLED, FALSE,
+			    COL_NAME, name,
+			    COL_STATUS, TP_CONNECTION_STATUS_DISCONNECTED,
+			    COL_ACCOUNT_SETTINGS_POINTER, settings,
+			    -1);
+}
+
+
+static void
+accounts_dialog_add_account (EmpathyAccountsDialog *dialog,
 				       EmpathyAccount        *account)
 {
+	EmpathyAccountSettings *settings;
 	GtkTreeModel       *model;
 	GtkTreeIter         iter;
 	TpConnectionStatus  status;
@@ -616,16 +737,16 @@ accounts_dialog_add_or_update_account (EmpathyAccountsDialog *dialog,
 	name = empathy_account_get_display_name (account);
 	enabled = empathy_account_is_enabled (account);
 
-	if (!accounts_dialog_get_account_iter (dialog, account, &iter)) {
-		DEBUG ("Adding new account");
-		gtk_list_store_append (GTK_LIST_STORE (model), &iter);
-	}
+	gtk_list_store_append (GTK_LIST_STORE (model), &iter);
+
+	settings = empathy_account_settings_new_for_account (account);
 
 	gtk_list_store_set (GTK_LIST_STORE (model), &iter,
 			    COL_ENABLED, enabled,
 			    COL_NAME, name,
 			    COL_STATUS, status,
 			    COL_ACCOUNT_POINTER, account,
+			    COL_ACCOUNT_SETTINGS_POINTER, settings,
 			    -1);
 
 	accounts_dialog_connection_changed_cb (dialog->account_manager,
@@ -634,6 +755,39 @@ accounts_dialog_add_or_update_account (EmpathyAccountsDialog *dialog,
 					       status,
 					       TP_CONNECTION_STATUS_DISCONNECTED,
 					       dialog);
+
+	g_object_unref (settings);
+}
+
+static void
+accounts_dialog_update (EmpathyAccountsDialog *dialog,
+				       EmpathyAccountSettings        *settings)
+{
+	GtkTreeModel       *model;
+	GtkTreeIter         iter;
+	TpConnectionStatus  status = TP_CONNECTION_STATUS_DISCONNECTED;
+	const gchar        *name;
+	gboolean            enabled = FALSE;
+	EmpathyAccount     *account;
+
+	model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
+	name = empathy_account_settings_get_display_name (settings);
+
+	account = empathy_account_settings_get_account (settings);
+	if (account != NULL)
+		{
+			enabled = empathy_account_is_enabled (account);
+			g_object_get (account, "connection-status", &status, NULL);
+		}
+
+	accounts_dialog_get_settings_iter (dialog, settings, &iter);
+	gtk_list_store_set (GTK_LIST_STORE (model), &iter,
+			    COL_ENABLED, enabled,
+			    COL_NAME, name,
+			    COL_STATUS, status,
+			    COL_ACCOUNT_POINTER, account,
+			    COL_ACCOUNT_SETTINGS_POINTER, settings,
+			    -1);
 }
 
 static void
@@ -641,43 +795,20 @@ accounts_dialog_account_added_cb (EmpathyAccountManager *manager,
 				  EmpathyAccount *account,
 				  EmpathyAccountsDialog *dialog)
 {
-	const gchar *current_name;
-	const gchar       *account_param = NULL;
-
-	accounts_dialog_add_or_update_account (dialog, account);
-
-	/* Change the display name to "%s (%s)" % (protocol, account).
-	 *  - The protocol is the display name of the profile.
-	 *  - The account should be the normalized name of the EmpathyAccount but
-	 *    it's not set until first connection, so we get the "account"
-	 *    parameter for CM that have it. */
-	current_name = empathy_account_get_display_name (account);
-	account_param = empathy_account_get_param_string (account, "account");
-	if (!EMP_STR_EMPTY (account_param)) {
-		gchar       *new_name;
-
-		new_name = g_strdup_printf ("%s (%s)",
-					    empathy_account_get_protocol (account),
-					    account_param);
-
-		DEBUG ("Setting new display name for account %s: '%s'",
-		       empathy_account_get_unique_name (account), new_name);
-
-		empathy_account_set_display_name (account, new_name);
-		g_free (new_name);
-	} else {
-		/* FIXME: This CM has no account parameter, what can be done? */
-	}
+	accounts_dialog_add_account (dialog, account);
 }
 
+
 static void
 accounts_dialog_account_removed_cb (EmpathyAccountManager *manager,
 				    EmpathyAccount       *account,
 				    EmpathyAccountsDialog *dialog)
 {
+	GtkTreeIter iter;
 
-	accounts_dialog_model_set_selected (dialog, account);
-	accounts_dialog_model_remove_selected (dialog);
+	if (accounts_dialog_get_account_iter (dialog, account, &iter))
+		gtk_list_store_remove (GTK_LIST_STORE (
+			gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview))), &iter);
 }
 
 static gboolean
@@ -791,20 +922,31 @@ accounts_dialog_account_changed_cb (EmpathyAccountManager *manager,
 				    EmpathyAccount        *account,
 				    EmpathyAccountsDialog  *dialog)
 {
-	EmpathyAccount *selected_account;
+	EmpathyAccountSettings *settings, *selected_settings;
+	GtkTreeModel *model;
+	GtkTreeIter iter;
 
-	accounts_dialog_add_or_update_account (dialog, account);
-	selected_account = accounts_dialog_model_get_selected (dialog);
-	if (empathy_account_equal (account, selected_account)) {
-		accounts_dialog_update_name_label (dialog, account);
-	}
+	model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->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, settings);
 }
 
 static void
 accounts_dialog_button_create_clicked_cb (GtkWidget             *button,
 					  EmpathyAccountsDialog  *dialog)
 {
-	EmpathyAccount *account;
+	EmpathyAccountSettings *settings;
 	gchar     *str;
 	TpConnectionManager *cm;
 	TpConnectionManagerProtocol *proto;
@@ -816,30 +958,23 @@ accounts_dialog_button_create_clicked_cb (GtkWidget             *button,
 	/* To translator: %s is the protocol name */
 	str = g_strdup_printf (_("New %s account"), proto->name);
 
-	account = empathy_account_manager_create (dialog->account_manager,
-		cm->name, proto->name, str);
+	settings = empathy_account_settings_new (cm->name, proto->name, str);
 
 	g_free (str);
 
-	if (account == NULL) {
-		/* We can't display an error to the user as MC doesn't give us
-		 * any clue about the reason of the failure... */
-		return;
-	}
-
 	if (tp_connection_manager_protocol_can_register (proto)) {
 		gboolean active;
 
 		active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->radiobutton_register));
 		if (active) {
-			empathy_account_set_param_boolean (account, "register", TRUE);
+			empathy_account_settings_set_boolean (settings, "register", TRUE);
 		}
 	}
 
-	accounts_dialog_add_or_update_account (dialog, account);
-	accounts_dialog_model_set_selected (dialog, account);
+	accounts_dialog_add (dialog, settings);
+	accounts_dialog_model_set_selected (dialog, settings);
 
-	g_object_unref (account);
+	g_object_unref (settings);
 	g_object_unref (cm);
 }
 
@@ -847,10 +982,10 @@ static void
 accounts_dialog_button_back_clicked_cb (GtkWidget             *button,
 					EmpathyAccountsDialog  *dialog)
 {
-	EmpathyAccount *account;
+	EmpathyAccountSettings *settings;
 
-	account = accounts_dialog_model_get_selected (dialog);
-	accounts_dialog_update_account (dialog, account);
+	settings = accounts_dialog_model_get_selected_settings (dialog);
+	accounts_dialog_update (dialog, settings);
 }
 
 static void
@@ -921,9 +1056,9 @@ accounts_dialog_button_remove_clicked_cb (GtkWidget            *button,
 	GtkWidget *message_dialog;
 	gint       res;
 
-	account = accounts_dialog_model_get_selected (dialog);
+	account = accounts_dialog_model_get_selected_account (dialog);
 
-	if (!empathy_account_is_valid (account)) {
+	if (account == NULL || !empathy_account_is_valid (account)) {
 		accounts_dialog_model_remove_selected (dialog);
 		accounts_dialog_model_select_first (dialog);
 		return;
@@ -1127,13 +1262,19 @@ empathy_accounts_dialog_show (GtkWindow *parent,
 	/* Add existing accounts */
 	accounts = empathy_account_manager_dup_accounts (dialog->account_manager);
 	for (l = accounts; l; l = l->next) {
-		accounts_dialog_add_or_update_account (dialog, l->data);
+		accounts_dialog_add_account (dialog, l->data);
 		g_object_unref (l->data);
 	}
 	g_list_free (accounts);
 
 	if (selected_account) {
-		accounts_dialog_model_set_selected (dialog, selected_account);
+		GtkTreeSelection *selection;
+		GtkTreeIter       iter;
+
+		selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dialog->treeview));
+		if (accounts_dialog_get_account_iter (dialog, selected_account, &iter)) {
+			gtk_tree_selection_select_iter (selection, &iter);
+		}
 	} else {
 		accounts_dialog_model_select_first (dialog);
 	}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]