]> git.0d.be Git - empathy.git/blobdiff - libempathy/empathy-account-settings.c
Merge branch 'gnome-3-8'
[empathy.git] / libempathy / empathy-account-settings.c
index 647c88d60feaf0974b09a53c43e28e1b9b4121ba..064d4d21580e398900cb276955dcc84d0cf3b3f5 100644 (file)
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#include <telepathy-glib/account-manager.h>
-#include <telepathy-glib/util.h>
-#include <telepathy-glib/interfaces.h>
-#include <telepathy-glib/gtypes.h>
-
+#include "config.h"
 #include "empathy-account-settings.h"
+
 #include "empathy-connection-managers.h"
 #include "empathy-keyring.h"
+#include "empathy-presence-manager.h"
 #include "empathy-utils.h"
-#include "empathy-idle.h"
 
 #define DEBUG_FLAG EMPATHY_DEBUG_ACCOUNT
-#include <libempathy/empathy-debug.h>
+#include "empathy-debug.h"
 
 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyAccountSettings)
 
@@ -75,11 +68,12 @@ struct _EmpathyAccountSettingsPriv
   gchar *service;
   gchar *display_name;
   gchar *icon_name;
+  gchar *storage_provider;
   gboolean display_name_overridden;
   gboolean ready;
 
   gboolean supports_sasl;
-  gboolean password_changed;
+  gboolean remember_password;
 
   gchar *password;
   gchar *password_original;
@@ -87,7 +81,7 @@ struct _EmpathyAccountSettingsPriv
   gboolean password_retrieved;
   gboolean password_requested;
 
-  /* Parameter name (gchar *) -> parameter value (GValue) */
+  /* Parameter name (gchar *) -> parameter value (GVariant) */
   GHashTable *parameters;
   /* Keys are parameter names from the hash above (gchar *).
    * Values are regular expresions that should match corresponding parameter
@@ -100,6 +94,12 @@ struct _EmpathyAccountSettingsPriv
   gulong managers_ready_id;
   gboolean preparing_protocol;
 
+  /* If TRUE, the account should have 'tel' in its
+   * Account.Interface.Addressing.URISchemes property. */
+  gboolean uri_scheme_tel;
+  /* If TRUE, Service property needs to be updated when applying changes */
+  gboolean update_service;
+
   GSimpleAsyncResult *apply_result;
 };
 
@@ -116,7 +116,7 @@ empathy_account_settings_init (EmpathyAccountSettings *obj)
   priv->account_manager = tp_account_manager_dup ();
 
   priv->parameters = g_hash_table_new_full (g_str_hash, g_str_equal,
-    g_free, (GDestroyNotify) tp_g_value_slice_free);
+    g_free, (GDestroyNotify) g_variant_unref);
 
   priv->param_regexps = g_hash_table_new_full (g_str_hash, g_str_equal,
     g_free, (GDestroyNotify) g_regex_unref);
@@ -221,9 +221,9 @@ empathy_account_settings_constructed (GObject *object)
       g_free (priv->service);
 
       priv->cm_name =
-        g_strdup (tp_account_get_connection_manager (priv->account));
+        g_strdup (tp_account_get_cm_name (priv->account));
       priv->protocol =
-        g_strdup (tp_account_get_protocol (priv->account));
+        g_strdup (tp_account_get_protocol_name (priv->account));
       priv->service =
         g_strdup (tp_account_get_service (priv->account));
       priv->icon_name = g_strdup
@@ -243,6 +243,7 @@ empathy_account_settings_constructed (GObject *object)
       GQuark features[] = {
           TP_ACCOUNT_FEATURE_CORE,
           TP_ACCOUNT_FEATURE_STORAGE,
+          TP_ACCOUNT_FEATURE_ADDRESSING,
           0 };
 
       if (priv->account != NULL)
@@ -331,7 +332,7 @@ empathy_account_settings_class_init (
       g_signal_new ("password-retrieved",
           G_TYPE_FROM_CLASS (empathy_account_settings_class),
           G_SIGNAL_RUN_LAST, 0, NULL, NULL,
-          g_cclosure_marshal_VOID__VOID,
+          g_cclosure_marshal_generic,
           G_TYPE_NONE, 0);
 }
 
@@ -389,6 +390,7 @@ empathy_account_settings_finalize (GObject *object)
   g_free (priv->icon_name);
   g_free (priv->password);
   g_free (priv->password_original);
+  g_free (priv->storage_provider);
 
   if (priv->required_params != NULL)
     {
@@ -397,11 +399,11 @@ empathy_account_settings_finalize (GObject *object)
       g_list_free (priv->required_params);
     }
 
-  g_hash_table_destroy (priv->parameters);
-  g_hash_table_destroy (priv->param_regexps);
+  g_hash_table_unref (priv->parameters);
+  g_hash_table_unref (priv->param_regexps);
 
   empathy_account_settings_free_unset_parameters (self);
-  g_array_free (priv->unset_parameters, TRUE);
+  g_array_unref (priv->unset_parameters);
 
   G_OBJECT_CLASS (empathy_account_settings_parent_class)->finalize (object);
 }
@@ -434,7 +436,7 @@ empathy_account_settings_get_password_cb (GObject *source,
   const gchar *password;
   GError *error = NULL;
 
-  password = empathy_keyring_get_password_finish (TP_ACCOUNT (source),
+  password = empathy_keyring_get_account_password_finish (TP_ACCOUNT (source),
       result, &error);
 
   if (error != NULL)
@@ -455,64 +457,14 @@ empathy_account_settings_get_password_cb (GObject *source,
   g_signal_emit (self, signals[PASSWORD_RETRIEVED], 0);
 }
 
-static void
-empathy_account_settings_try_migrating_password (EmpathyAccountSettings *self)
-{
-  EmpathyAccountSettingsPriv *priv = GET_PRIV (self);
-  const GValue *v;
-  const gchar *account_id, *password;
-  const gchar *unset[] = { "password", NULL };
-  GHashTable *empty;
-
-  if (!priv->supports_sasl || empathy_account_settings_get (
-          self, "password") == NULL)
-    return;
-
-  /* mission-control still has our password, although the CM
-   * supports SASL. Let's try migrating it. */
-
-  account_id = tp_proxy_get_object_path (priv->account)
-    + strlen (TP_ACCOUNT_OBJECT_PATH_BASE);
-
-  DEBUG ("Trying to migrate password parameter from MC to the "
-      "keyring ourselves for account %s", account_id);
-
-  v = empathy_account_settings_get (self, "password");
-
-  /* I can't imagine why this would fail. */
-  if (!G_VALUE_HOLDS_STRING (v))
-    return;
-
-  password = g_value_get_string (v);
-
-  if (EMP_STR_EMPTY (password))
-    return;
-
-  empathy_keyring_set_password_async (priv->account, password,
-      NULL, NULL);
-
-  /* We don't want to request the password again, we
-   * already know it. */
-  priv->password_requested = TRUE;
-
-  priv->password = g_strdup (password);
-  priv->password_original = g_strdup (password);
-
-  /* Now clear the password MC has stored. */
-  empty = tp_asv_new (NULL, NULL);
-  tp_account_update_parameters_async (priv->account,
-      empty, unset, NULL, NULL);
-
-  g_hash_table_remove (priv->parameters, "password");
-
-  g_hash_table_unref (empty);
-}
+static GVariant * empathy_account_settings_dup (
+    EmpathyAccountSettings *settings,
+    const gchar *param);
 
 static void
 empathy_account_settings_check_readyness (EmpathyAccountSettings *self)
 {
   EmpathyAccountSettingsPriv *priv = GET_PRIV (self);
-  const TpConnectionManagerProtocol *tp_protocol;
   GQuark features[] = { TP_PROTOCOL_FEATURE_CORE, 0 };
 
   if (priv->ready)
@@ -545,36 +497,15 @@ empathy_account_settings_check_readyness (EmpathyAccountSettings *self)
       g_free (priv->icon_name);
       priv->icon_name =
         g_strdup (tp_account_get_icon_name (priv->account));
-    }
-
-  tp_protocol = tp_connection_manager_get_protocol (priv->manager,
-    priv->protocol);
-
-  if (tp_protocol == NULL)
-    {
-      priv->manager = NULL;
-      return;
-    }
-
-  if (priv->required_params == NULL)
-    {
-      TpConnectionManagerParam *cur;
 
-      for (cur = tp_protocol->params; cur->name != NULL; cur++)
-        {
-          if (tp_connection_manager_param_is_required (cur))
-            {
-              priv->required_params = g_list_append (priv->required_params,
-                                                     g_strdup (cur->name));
-            }
-        }
+      priv->uri_scheme_tel = empathy_account_has_uri_scheme_tel (priv->account);
     }
 
   if (priv->protocol_obj == NULL)
     {
       priv->protocol_obj = g_object_ref (
           tp_connection_manager_get_protocol_object (priv->manager,
-              priv->protocol));
+            priv->protocol));
     }
 
   if (!tp_proxy_is_prepared (priv->protocol_obj, TP_PROTOCOL_FEATURE_CORE)
@@ -595,8 +526,25 @@ empathy_account_settings_check_readyness (EmpathyAccountSettings *self)
         }
     }
 
+  if (priv->required_params == NULL)
+    {
+      GList *params, *l;
 
-  empathy_account_settings_try_migrating_password (self);
+      params = tp_protocol_dup_params (priv->protocol_obj);
+      for (l = params; l != NULL; l = g_list_next (l))
+        {
+          TpConnectionManagerParam *cur = l->data;
+
+          if (tp_connection_manager_param_is_required (cur))
+            {
+              priv->required_params = g_list_append (priv->required_params,
+                  g_strdup (tp_connection_manager_param_get_name (cur)));
+            }
+        }
+
+       g_list_free_full (params,
+           (GDestroyNotify) tp_connection_manager_param_free);
+    }
 
   /* priv->account won't be a proper account if it's the account
    * assistant showing this widget. */
@@ -607,7 +555,7 @@ empathy_account_settings_check_readyness (EmpathyAccountSettings *self)
 
       /* Make this call but don't block on its readiness. We'll signal
        * if it's updated later with ::password-retrieved. */
-      empathy_keyring_get_password_async (priv->account,
+      empathy_keyring_get_account_password_async (priv->account,
           empathy_account_settings_get_password_cb, self);
     }
 
@@ -666,25 +614,14 @@ empathy_account_settings_new_for_account (TpAccount *account)
       NULL);
 }
 
-TpConnectionManagerParam *
-empathy_account_settings_get_tp_params (EmpathyAccountSettings *settings)
+GList *
+empathy_account_settings_dup_tp_params (EmpathyAccountSettings *settings)
 {
   EmpathyAccountSettingsPriv *priv = GET_PRIV (settings);
-  const TpConnectionManagerProtocol *tp_protocol;
 
-  g_return_val_if_fail (priv->manager != NULL, NULL);
-  g_return_val_if_fail (priv->protocol != NULL, NULL);
-
-  tp_protocol = tp_connection_manager_get_protocol (priv->manager,
-     priv->protocol);
-  if (tp_protocol == NULL)
-    {
-      DEBUG ("Can't retrieve TpConnectionManagerProtocol for protocol '%s'",
-          priv->protocol);
-      return NULL;
-    }
+  g_return_val_if_fail (priv->protocol_obj != NULL, NULL);
 
-  return tp_protocol->params;
+  return tp_protocol_dup_params (priv->protocol_obj);
 }
 
 gboolean
@@ -719,6 +656,21 @@ empathy_account_settings_get_service (EmpathyAccountSettings *settings)
   return priv->service;
 }
 
+void
+empathy_account_settings_set_service (EmpathyAccountSettings *settings,
+    const gchar *service)
+{
+  EmpathyAccountSettingsPriv *priv = GET_PRIV (settings);
+
+  if (!tp_strdiff (priv->service, service))
+    return;
+
+  g_free (priv->service);
+  priv->service = g_strdup (service);
+  g_object_notify (G_OBJECT (settings), "service");
+  priv->update_service = TRUE;
+}
+
 gchar *
 empathy_account_settings_get_icon_name (EmpathyAccountSettings *settings)
 {
@@ -762,23 +714,20 @@ empathy_account_settings_is_unset (EmpathyAccountSettings *settings,
   return FALSE;
 }
 
-static TpConnectionManagerParam *
+static const TpConnectionManagerParam *
 empathy_account_settings_get_tp_param (EmpathyAccountSettings *settings,
     const gchar *param)
 {
-  TpConnectionManagerParam *tp_params =
-      empathy_account_settings_get_tp_params (settings);
-  TpConnectionManagerParam *p;
-
-  for (p = tp_params; p != NULL && p->name != NULL; p++)
-    {
-      if (tp_strdiff (p->name, param))
-        continue;
+  EmpathyAccountSettingsPriv *priv = GET_PRIV (settings);
 
-      return p;
-    }
+  return tp_protocol_get_param (priv->protocol_obj, param);
+}
 
-  return NULL;
+gboolean
+empathy_account_settings_have_tp_param (EmpathyAccountSettings *settings,
+    const gchar *param)
+{
+  return (empathy_account_settings_get_tp_param (settings, param) != NULL);
 }
 
 static void
@@ -804,61 +753,62 @@ account_settings_remove_from_unset (EmpathyAccountSettings *settings,
     }
 }
 
-const GValue *
-empathy_account_settings_get_default (EmpathyAccountSettings *settings,
+GVariant *
+empathy_account_settings_dup_default (EmpathyAccountSettings *settings,
     const gchar *param)
 {
-  TpConnectionManagerParam *p;
+  const TpConnectionManagerParam *p;
 
   p = empathy_account_settings_get_tp_param (settings, param);
-
-  if (p == NULL || !(p->flags & TP_CONN_MGR_PARAM_FLAG_HAS_DEFAULT))
+  if (p == NULL)
     return NULL;
 
-  return &(p->default_value);
+  return tp_connection_manager_param_dup_default_variant (p);
 }
 
 const gchar *
 empathy_account_settings_get_dbus_signature (EmpathyAccountSettings *settings,
     const gchar *param)
 {
-  TpConnectionManagerParam *p;
+  const TpConnectionManagerParam *p;
 
   p = empathy_account_settings_get_tp_param (settings, param);
 
   if (p == NULL)
     return NULL;
 
-  return p->dbus_signature;
+  return tp_connection_manager_param_get_dbus_signature (p);
 }
 
-const GValue *
-empathy_account_settings_get (EmpathyAccountSettings *settings,
+static GVariant *
+empathy_account_settings_dup (EmpathyAccountSettings *settings,
     const gchar *param)
 {
   EmpathyAccountSettingsPriv *priv = GET_PRIV (settings);
-  const GValue *result = NULL;
+  GVariant *result;
 
   /* Lookup the update parameters we set */
-  result = tp_asv_lookup (priv->parameters, param);
+  result = g_hash_table_lookup (priv->parameters, param);
   if (result != NULL)
-    return result;
+    return g_variant_ref (result);
 
   /* If the parameters isn't unset use the accounts setting if any */
   if (priv->account != NULL
       && !empathy_account_settings_is_unset (settings, param))
     {
-      const GHashTable *parameters;
+      GVariant *parameters;
 
-      parameters = tp_account_get_parameters (priv->account);
-      result = tp_asv_lookup (parameters, param);
+      parameters = tp_account_dup_parameters_vardict (priv->account);
+      result = g_variant_lookup_value (parameters, param, NULL);
+      g_variant_unref (parameters);
 
       if (result != NULL)
+        /* g_variant_lookup_value() is (transfer full) */
         return result;
     }
 
   /* fallback to the default */
-  return empathy_account_settings_get_default (settings, param);
+  return empathy_account_settings_dup_default (settings, param);
 }
 
 void
@@ -874,7 +824,6 @@ empathy_account_settings_unset (EmpathyAccountSettings *settings,
     {
       g_free (priv->password);
       priv->password = NULL;
-      priv->password_changed = TRUE;
       return;
     }
 
@@ -892,81 +841,89 @@ empathy_account_settings_discard_changes (EmpathyAccountSettings *settings)
   g_hash_table_remove_all (priv->parameters);
   empathy_account_settings_free_unset_parameters (settings);
 
-  priv->password_changed = FALSE;
   g_free (priv->password);
   priv->password = g_strdup (priv->password_original);
+
+  if (priv->account != NULL)
+    priv->uri_scheme_tel = empathy_account_has_uri_scheme_tel (priv->account);
+  else
+    priv->uri_scheme_tel = FALSE;
 }
 
-const gchar *
-empathy_account_settings_get_string (EmpathyAccountSettings *settings,
+gchar *
+empathy_account_settings_dup_string (EmpathyAccountSettings *settings,
     const gchar *param)
 {
   EmpathyAccountSettingsPriv *priv = GET_PRIV (settings);
-  const GValue *v;
+  GVariant *v;
+  gchar *result = NULL;
 
   if (!tp_strdiff (param, "password") && priv->supports_sasl)
     {
-      return priv->password;
+      return g_strdup (priv->password);
     }
 
-  v = empathy_account_settings_get (settings, param);
-
-  if (v == NULL || !G_VALUE_HOLDS_STRING (v))
+  v = empathy_account_settings_dup (settings, param);
+  if (v == NULL)
     return NULL;
 
-  return g_value_get_string (v);
+  if (g_variant_is_of_type (v, G_VARIANT_TYPE_STRING))
+    result = g_variant_dup_string (v, NULL);
+
+  g_variant_unref (v);
+  return result;
 }
 
-const gchar * const *
-empathy_account_settings_get_strv (EmpathyAccountSettings *settings,
+GStrv
+empathy_account_settings_dup_strv (EmpathyAccountSettings *settings,
     const gchar *param)
 {
-  const GValue *v;
+  GVariant *v;
+  GStrv result = NULL;
 
-  v = empathy_account_settings_get (settings, param);
-
-  if (v == NULL || !G_VALUE_HOLDS (v, G_TYPE_STRV))
+  v = empathy_account_settings_dup (settings, param);
+  if (v == NULL)
     return NULL;
 
-  return g_value_get_boxed (v);
+  if (g_variant_is_of_type (v, G_VARIANT_TYPE_STRING_ARRAY))
+    result = g_variant_dup_strv (v, NULL);
+
+  g_variant_unref (v);
+  return result;
 }
 
 gint32
 empathy_account_settings_get_int32 (EmpathyAccountSettings *settings,
     const gchar *param)
 {
-  const GValue *v;
+  GVariant *v;
   gint32 ret = 0;
 
-  v = empathy_account_settings_get (settings, param);
-
+  v = empathy_account_settings_dup (settings, param);
   if (v == NULL)
     return 0;
 
-  switch G_VALUE_TYPE (v)
+  if (g_variant_is_of_type (v, G_VARIANT_TYPE_BYTE))
+    ret = g_variant_get_byte (v);
+  else if (g_variant_is_of_type (v, G_VARIANT_TYPE_INT32))
+    ret = g_variant_get_int32 (v);
+  else if (g_variant_is_of_type (v, G_VARIANT_TYPE_UINT32))
+    ret = CLAMP (g_variant_get_uint32 (v), (guint) G_MININT32,
+        G_MAXINT32);
+  else if (g_variant_is_of_type (v, G_VARIANT_TYPE_INT64))
+    ret = CLAMP (g_variant_get_int64 (v), G_MININT32, G_MAXINT32);
+  else if (g_variant_is_of_type (v, G_VARIANT_TYPE_UINT64))
+    ret = CLAMP (g_variant_get_uint64 (v), (guint64) G_MININT32, G_MAXINT32);
+  else
     {
-      case G_TYPE_UCHAR:
-        ret = g_value_get_uchar (v);
-        break;
-      case G_TYPE_INT:
-        ret = g_value_get_int (v);
-        break;
-      case G_TYPE_UINT:
-        ret = CLAMP (g_value_get_uint (v), (guint) G_MININT32,
-            G_MAXINT32);
-        break;
-      case G_TYPE_INT64:
-        ret = CLAMP (g_value_get_int64 (v), G_MININT32, G_MAXINT32);
-        break;
-      case G_TYPE_UINT64:
-        ret = CLAMP (g_value_get_uint64 (v), (guint64) G_MININT32,
-            G_MAXINT32);
-        break;
-      default:
-        ret = 0;
-        break;
+      gchar *tmp;
+
+      tmp = g_variant_print (v, TRUE);
+      DEBUG ("Unsupported type for param '%s': %s'", param, tmp);
+      g_free (tmp);
     }
 
+  g_variant_unref (v);
   return ret;
 }
 
@@ -974,35 +931,33 @@ gint64
 empathy_account_settings_get_int64 (EmpathyAccountSettings *settings,
     const gchar *param)
 {
-  const GValue *v;
+  GVariant *v;
   gint64 ret = 0;
 
-  v = empathy_account_settings_get (settings, param);
+  v = empathy_account_settings_dup (settings, param);
   if (v == NULL)
     return 0;
 
-  switch G_VALUE_TYPE (v)
+  if (g_variant_is_of_type (v, G_VARIANT_TYPE_BYTE))
+    ret = g_variant_get_byte (v);
+  else if (g_variant_is_of_type (v, G_VARIANT_TYPE_INT32))
+    ret = g_variant_get_int32 (v);
+  else if (g_variant_is_of_type (v, G_VARIANT_TYPE_UINT32))
+    ret = g_variant_get_uint32 (v);
+  else if (g_variant_is_of_type (v, G_VARIANT_TYPE_INT64))
+    ret = g_variant_get_int64 (v);
+  else if (g_variant_is_of_type (v, G_VARIANT_TYPE_UINT64))
+    ret = CLAMP (g_variant_get_uint64 (v), (guint64) G_MININT64, G_MAXINT64);
+  else
     {
-      case G_TYPE_UCHAR:
-        ret = g_value_get_uchar (v);
-        break;
-      case G_TYPE_INT:
-        ret = g_value_get_int (v);
-        break;
-      case G_TYPE_UINT:
-        ret = g_value_get_uint (v);
-        break;
-      case G_TYPE_INT64:
-        ret = g_value_get_int64 (v);
-        break;
-      case G_TYPE_UINT64:
-        ret = CLAMP (g_value_get_uint64 (v), (guint64) G_MININT64, G_MAXINT64);
-        break;
-      default:
-        ret = 0;
-        break;
+      gchar *tmp;
+
+      tmp = g_variant_print (v, TRUE);
+      DEBUG ("Unsupported type for param '%s': %s'", param, tmp);
+      g_free (tmp);
     }
 
+  g_variant_unref (v);
   return ret;
 }
 
@@ -1010,35 +965,33 @@ guint32
 empathy_account_settings_get_uint32 (EmpathyAccountSettings *settings,
     const gchar *param)
 {
-  const GValue *v;
-  guint32 ret;
+  GVariant *v;
+  guint32 ret = 0;
 
-  v = empathy_account_settings_get (settings, param);
+  v = empathy_account_settings_dup (settings, param);
   if (v == NULL)
     return 0;
 
-  switch G_VALUE_TYPE (v)
+  if (g_variant_is_of_type (v, G_VARIANT_TYPE_BYTE))
+    ret = g_variant_get_byte (v);
+  else if (g_variant_is_of_type (v, G_VARIANT_TYPE_INT32))
+    ret = MAX (0, g_variant_get_int32 (v));
+  else if (g_variant_is_of_type (v, G_VARIANT_TYPE_UINT32))
+    ret = g_variant_get_uint32 (v);
+  else if (g_variant_is_of_type (v, G_VARIANT_TYPE_INT64))
+    ret = CLAMP (g_variant_get_int64 (v), 0, G_MAXUINT32);
+  else if (g_variant_is_of_type (v, G_VARIANT_TYPE_UINT64))
+    ret = MIN (g_variant_get_uint64 (v), G_MAXUINT32);
+  else
     {
-      case G_TYPE_UCHAR:
-        ret = g_value_get_uchar (v);
-        break;
-      case G_TYPE_INT:
-        ret = MAX (0, g_value_get_int (v));
-        break;
-      case G_TYPE_UINT:
-        ret = g_value_get_uint (v);
-        break;
-      case G_TYPE_INT64:
-        ret = CLAMP (g_value_get_int64 (v), 0, G_MAXUINT32);
-        break;
-      case G_TYPE_UINT64:
-        ret = MIN (g_value_get_uint64 (v), G_MAXUINT32);
-        break;
-      default:
-        ret = 0;
-        break;
+      gchar *tmp;
+
+      tmp = g_variant_print (v, TRUE);
+      DEBUG ("Unsupported type for param '%s': %s'", param, tmp);
+      g_free (tmp);
     }
 
+  g_variant_unref (v);
   return ret;
 }
 
@@ -1046,36 +999,34 @@ guint64
 empathy_account_settings_get_uint64 (EmpathyAccountSettings *settings,
     const gchar *param)
 {
-  const GValue *v;
+  GVariant *v;
   guint64 ret = 0;
 
-  v = empathy_account_settings_get (settings, param);
-
-  if (v == NULL || !G_VALUE_HOLDS_INT (v))
+  v = empathy_account_settings_dup (settings, param);
+  if (v == NULL)
     return 0;
 
-  switch G_VALUE_TYPE (v)
+  if (g_variant_is_of_type (v, G_VARIANT_TYPE_BYTE))
+    ret = g_variant_get_byte (v);
+  else if (g_variant_is_of_type (v, G_VARIANT_TYPE_INT32))
+    ret = MAX (0, g_variant_get_int32 (v));
+  else if (g_variant_is_of_type (v, G_VARIANT_TYPE_UINT32))
+    ret = g_variant_get_uint32 (v);
+  else if (g_variant_is_of_type (v, G_VARIANT_TYPE_INT64))
+    ret = MAX (0, g_variant_get_int64 (v));
+  else if (g_variant_is_of_type (v, G_VARIANT_TYPE_UINT64))
+    ret = g_variant_get_uint64 (v);
+  else
     {
-      case G_TYPE_UCHAR:
-        ret = g_value_get_uchar (v);
-        break;
-      case G_TYPE_INT:
-        ret = MAX (0, g_value_get_int (v));
-        break;
-      case G_TYPE_UINT:
-        ret = g_value_get_uint (v);
-        break;
-      case G_TYPE_INT64:
-        ret = MAX (0, g_value_get_int64 (v));
-        break;
-      case G_TYPE_UINT64:
-        ret = g_value_get_uint64 (v);
-        break;
-      default:
-        ret = 0;
-        break;
+      gchar *tmp;
+
+      tmp = g_variant_print (v, TRUE);
+      DEBUG ("Unsupported type for param '%s': %s'", param, tmp);
+      g_free (tmp);
     }
 
+
+  g_variant_unref (v);
   return ret;
 }
 
@@ -1083,125 +1034,44 @@ gboolean
 empathy_account_settings_get_boolean (EmpathyAccountSettings *settings,
     const gchar *param)
 {
-  const GValue *v;
+  GVariant *v;
+  gboolean result = FALSE;
 
-  v = empathy_account_settings_get (settings, param);
+  v = empathy_account_settings_dup (settings, param);
+  if (v == NULL)
+    return result;
 
-  if (v == NULL || !G_VALUE_HOLDS_BOOLEAN (v))
-    return FALSE;
+  if (g_variant_is_of_type (v, G_VARIANT_TYPE_BOOLEAN))
+    result = g_variant_get_boolean (v);
 
-  return g_value_get_boolean (v);
+  return result;
 }
 
 void
-empathy_account_settings_set_string (EmpathyAccountSettings *settings,
+empathy_account_settings_set (EmpathyAccountSettings *settings,
     const gchar *param,
-    const gchar *value)
+    GVariant *v)
 {
   EmpathyAccountSettingsPriv *priv = GET_PRIV (settings);
 
   g_return_if_fail (param != NULL);
-  g_return_if_fail (value != NULL);
+  g_return_if_fail (v != NULL);
 
-  if (!tp_strdiff (param, "password") && priv->supports_sasl)
+  if (!tp_strdiff (param, "password") && priv->supports_sasl &&
+      g_variant_is_of_type (v, G_VARIANT_TYPE_STRING))
     {
       g_free (priv->password);
-      priv->password = g_strdup (value);
-      priv->password_changed = TRUE;
+      priv->password = g_variant_dup_string (v, NULL);
     }
   else
     {
-      tp_asv_set_string (priv->parameters, g_strdup (param), value);
+      g_hash_table_insert (priv->parameters, g_strdup (param),
+          g_variant_ref_sink (v));
     }
 
   account_settings_remove_from_unset (settings, param);
 }
 
-void
-empathy_account_settings_set_strv (EmpathyAccountSettings *settings,
-    const gchar *param,
-    gchar **value)
-{
-  EmpathyAccountSettingsPriv *priv = GET_PRIV (settings);
-
-  g_return_if_fail (param != NULL);
-  g_return_if_fail (value != NULL);
-
-  tp_asv_set_strv (priv->parameters, g_strdup (param), value);
-
-  account_settings_remove_from_unset (settings, param);
-}
-
-void
-empathy_account_settings_set_int32 (EmpathyAccountSettings *settings,
-    const gchar *param,
-    gint32 value)
-{
-  EmpathyAccountSettingsPriv *priv = GET_PRIV (settings);
-
-  g_return_if_fail (param != NULL);
-
-  tp_asv_set_int32 (priv->parameters, g_strdup (param), value);
-
-  account_settings_remove_from_unset (settings, param);
-}
-
-void
-empathy_account_settings_set_int64 (EmpathyAccountSettings *settings,
-    const gchar *param,
-    gint64 value)
-{
-  EmpathyAccountSettingsPriv *priv = GET_PRIV (settings);
-
-  g_return_if_fail (param != NULL);
-
-  tp_asv_set_int64 (priv->parameters, g_strdup (param), value);
-
-  account_settings_remove_from_unset (settings, param);
-}
-
-void
-empathy_account_settings_set_uint32 (EmpathyAccountSettings *settings,
-    const gchar *param,
-    guint32 value)
-{
-  EmpathyAccountSettingsPriv *priv = GET_PRIV (settings);
-
-  g_return_if_fail (param != NULL);
-
-  tp_asv_set_uint32 (priv->parameters, g_strdup (param), value);
-
-  account_settings_remove_from_unset (settings, param);
-}
-
-void
-empathy_account_settings_set_uint64 (EmpathyAccountSettings *settings,
-    const gchar *param,
-    guint64 value)
-{
-  EmpathyAccountSettingsPriv *priv = GET_PRIV (settings);
-
-  g_return_if_fail (param != NULL);
-
-  tp_asv_set_uint64 (priv->parameters, g_strdup (param), value);
-
-  account_settings_remove_from_unset (settings, param);
-}
-
-void
-empathy_account_settings_set_boolean (EmpathyAccountSettings *settings,
-    const gchar *param,
-    gboolean value)
-{
-  EmpathyAccountSettingsPriv *priv = GET_PRIV (settings);
-
-  g_return_if_fail (param != NULL);
-
-  tp_asv_set_boolean (priv->parameters, g_strdup (param), value);
-
-  account_settings_remove_from_unset (settings, param);
-}
-
 static void
 account_settings_display_name_set_cb (GObject *src,
     GAsyncResult *res,
@@ -1384,7 +1254,7 @@ empathy_account_settings_set_password_cb (GObject *source,
     gpointer user_data)
 {
   empathy_account_settings_processed_password (source, result, user_data,
-      empathy_keyring_set_password_finish);
+      empathy_keyring_set_account_password_finish);
 }
 
 static void
@@ -1393,7 +1263,46 @@ empathy_account_settings_delete_password_cb (GObject *source,
     gpointer user_data)
 {
   empathy_account_settings_processed_password (source, result, user_data,
-      empathy_keyring_delete_password_finish);
+      empathy_keyring_delete_account_password_finish);
+}
+
+static void
+update_account_uri_schemes (EmpathyAccountSettings *self)
+{
+  EmpathyAccountSettingsPriv *priv = GET_PRIV (self);
+
+  if (priv->uri_scheme_tel == empathy_account_has_uri_scheme_tel (
+        priv->account))
+    return;
+
+  tp_account_set_uri_scheme_association_async (priv->account, "tel",
+      priv->uri_scheme_tel, NULL, NULL);
+}
+
+static void
+set_service_cb (GObject *source,
+    GAsyncResult *result,
+    gpointer user_data)
+{
+  GError *error = NULL;
+
+  if (!tp_account_set_service_finish (TP_ACCOUNT (source), result, &error))
+    {
+      DEBUG ("Failed to set Account.Service: %s", error->message);
+      g_error_free (error);
+    }
+}
+
+static void
+update_account_service (EmpathyAccountSettings *self)
+{
+  EmpathyAccountSettingsPriv *priv = GET_PRIV (self);
+
+  if (!priv->update_service)
+    return;
+
+  tp_account_set_service_async (priv->account,
+      priv->service != NULL ? priv->service : "", set_service_cb, self);
 }
 
 static void
@@ -1405,27 +1314,37 @@ empathy_account_settings_account_updated (GObject *source,
   EmpathyAccountSettingsPriv *priv = GET_PRIV (settings);
   GSimpleAsyncResult *r;
   GError *error = NULL;
+  GStrv reconnect_required = NULL;
 
-  if (!tp_account_update_parameters_finish (TP_ACCOUNT (source),
-          result, NULL, &error))
+  if (!tp_account_update_parameters_vardict_finish (TP_ACCOUNT (source),
+          result, &reconnect_required, &error))
     {
       g_simple_async_result_set_from_error (priv->apply_result, error);
       g_error_free (error);
       goto out;
     }
 
-  /* Only set the password in the keyring if the CM supports SASL and
-   * it's changed. */
-  if (priv->supports_sasl && priv->password_changed)
+  update_account_uri_schemes (settings);
+  update_account_service (settings);
+
+  g_simple_async_result_set_op_res_gboolean (priv->apply_result,
+      g_strv_length (reconnect_required) > 0);
+
+  /* Only set the password in the keyring if the CM supports SASL. */
+  if (priv->supports_sasl)
     {
       if (priv->password != NULL)
         {
-          empathy_keyring_set_password_async (priv->account, priv->password,
+          /* FIXME: we shouldn't save the password if we
+           * can't (MaySaveResponse=False) but we don't have API to check that
+           * at this point (fdo #35382). */
+          empathy_keyring_set_account_password_async (priv->account,
+              priv->password, priv->remember_password,
               empathy_account_settings_set_password_cb, settings);
         }
       else
         {
-          empathy_keyring_delete_password_async (priv->account,
+          empathy_keyring_delete_account_password_async (priv->account,
               empathy_account_settings_delete_password_cb, settings);
         }
 
@@ -1440,6 +1359,7 @@ out:
 
   g_simple_async_result_complete (r);
   g_object_unref (r);
+  g_strfreev (reconnect_required);
 }
 
 static void
@@ -1449,20 +1369,33 @@ empathy_account_settings_created_cb (GObject *source,
 {
   EmpathyAccountSettings *settings = EMPATHY_ACCOUNT_SETTINGS (user_data);
   EmpathyAccountSettingsPriv *priv = GET_PRIV (settings);
-  TpAccount *account;
   GError *error = NULL;
   GSimpleAsyncResult *r;
 
-  account = tp_account_manager_create_account_finish (
-    TP_ACCOUNT_MANAGER (source), result, &error);
+  priv->account = tp_account_request_create_account_finish (
+      TP_ACCOUNT_REQUEST (source), result, &error);
 
-  if (account == NULL)
+  if (priv->account == NULL)
     {
       g_simple_async_result_set_from_error (priv->apply_result, error);
     }
   else
     {
-      priv->account = g_object_ref (account);
+      if (priv->supports_sasl && priv->password != NULL)
+        {
+          /* Save the password before connecting */
+          /* FIXME: we shouldn't save the password if we
+           * can't (MaySaveResponse=False) but we don't have API to check that
+           * at this point (fdo #35382). */
+          empathy_keyring_set_account_password_async (priv->account,
+              priv->password, priv->remember_password,
+              empathy_account_settings_set_password_cb,
+              settings);
+          return;
+        }
+
+      update_account_uri_schemes (settings);
+
       empathy_account_settings_discard_changes (settings);
     }
 
@@ -1473,84 +1406,82 @@ empathy_account_settings_created_cb (GObject *source,
   g_object_unref (r);
 }
 
-
 static void
-empathy_account_settings_do_create_account (EmpathyAccountSettings *settings)
+empathy_account_settings_do_create_account (EmpathyAccountSettings *self)
 {
-  EmpathyAccountSettingsPriv *priv = GET_PRIV (settings);
-  GHashTable *properties;
+  EmpathyAccountSettingsPriv *priv = GET_PRIV (self);
+  TpAccountRequest *account_req;
   TpConnectionPresenceType type;
   gchar *status;
   gchar *message;
-  EmpathyIdle *idle;
+  EmpathyPresenceManager *presence_mgr;
+  GHashTableIter iter;
+  gpointer k, v;
 
-  properties = tp_asv_new (NULL, NULL);
+  account_req = tp_account_request_new (priv->account_manager, priv->cm_name,
+      priv->protocol, "New Account");
 
-  idle = empathy_idle_dup_singleton ();
-  type = empathy_idle_get_requested_presence (idle, &status, &message);
-  g_object_unref (idle);
+  presence_mgr = empathy_presence_manager_dup_singleton ();
+  type = empathy_presence_manager_get_requested_presence (presence_mgr, &status,
+      &message);
+  g_object_unref (presence_mgr);
 
   if (type != TP_CONNECTION_PRESENCE_TYPE_UNSET)
     {
-      /* Create the account with the requested presence the same as the current
-        * global requested presence, but don't enable it */
-      GValueArray *presence;
-      GValue vtype = { 0, };
-      GValue vstatus = { 0, };
-      GValue vmessage = { 0, };
+      tp_account_request_set_requested_presence (account_req, type,
+          status, message);
+    }
 
-      presence = g_value_array_new (3);
+  tp_account_request_set_icon_name (account_req, priv->icon_name);
 
-      g_value_init (&vtype, G_TYPE_UINT);
-      g_value_set_uint (&vtype, type);
-      g_value_array_append (presence, &vtype);
+  tp_account_request_set_display_name (account_req, priv->display_name);
 
-      g_value_init (&vstatus, G_TYPE_STRING);
-      g_value_take_string (&vstatus, status);
-      g_value_array_append (presence, &vstatus);
+  if (priv->service != NULL)
+    tp_account_request_set_service (account_req, priv->service);
 
-      g_value_init (&vmessage, G_TYPE_STRING);
-      g_value_take_string (&vmessage, message);
-      g_value_array_append (presence, &vmessage);
+  g_hash_table_iter_init (&iter, priv->parameters);
+  while (g_hash_table_iter_next (&iter, &k, &v))
+    {
+      const gchar *key = k;
+      GVariant *value = v;
 
-      tp_asv_take_boxed (properties, TP_IFACE_ACCOUNT ".RequestedPresence",
-        TP_STRUCT_TYPE_SIMPLE_PRESENCE, presence);
+      tp_account_request_set_parameter (account_req, key, value);
     }
 
-  tp_asv_set_string (properties, TP_IFACE_ACCOUNT ".Icon",
-      priv->icon_name);
-
-  if (priv->service != NULL)
-    tp_asv_set_string (properties, TP_PROP_ACCOUNT_SERVICE, priv->service);
-
-  tp_account_manager_create_account_async (priv->account_manager,
-    priv->cm_name, priv->protocol, priv->display_name,
-    priv->parameters, properties,
-    empathy_account_settings_created_cb,
-    settings);
+  if (priv->storage_provider != NULL)
+    {
+      tp_account_request_set_storage_provider (account_req,
+          priv->storage_provider);
+    }
 
-  g_hash_table_unref (properties);
+  tp_account_request_create_account_async (account_req,
+      empathy_account_settings_created_cb, self);
 }
 
-static void
-empathy_account_settings_manager_ready_cb (GObject *source_object,
-    GAsyncResult *result,
-    gpointer user_data)
+static GVariant *
+build_parameters_variant (EmpathyAccountSettings *self)
 {
-  EmpathyAccountSettings *settings = EMPATHY_ACCOUNT_SETTINGS (user_data);
-  EmpathyAccountSettingsPriv *priv = GET_PRIV (settings);
-  TpAccountManager *account_manager = TP_ACCOUNT_MANAGER (source_object);
-  GError *error = NULL;
+  EmpathyAccountSettingsPriv *priv = GET_PRIV (self);
+  GVariantBuilder *builder;
+  GHashTableIter iter;
+  gpointer k, v;
 
-  if (!tp_account_manager_prepare_finish (account_manager, result, &error))
+  builder = g_variant_builder_new (G_VARIANT_TYPE_VARDICT);
+
+  g_hash_table_iter_init (&iter, priv->parameters);
+  while (g_hash_table_iter_next (&iter, &k, &v))
     {
-      DEBUG ("Failed to prepare account manager: %s", error->message);
-      g_error_free (error);
-      return;
+      const gchar *key = k;
+      GVariant *value = v;
+      GVariant *entry;
+
+      entry = g_variant_new_dict_entry (g_variant_new_string (key),
+          g_variant_new_variant (value));
+
+      g_variant_builder_add_value (builder, entry);
     }
 
-  g_assert (priv->apply_result != NULL && priv->account == NULL);
-  empathy_account_settings_do_create_account (settings);
+  return g_variant_builder_end (builder);
 }
 
 void
@@ -1571,15 +1502,21 @@ empathy_account_settings_apply_async (EmpathyAccountSettings *settings,
   priv->apply_result = g_simple_async_result_new (G_OBJECT (settings),
       callback, user_data, empathy_account_settings_apply_finish);
 
+  /* We'll have to reconnect only if we change none DBus_Property on an
+   * existing account. */
+  g_simple_async_result_set_op_res_gboolean (priv->apply_result, FALSE);
+
   if (priv->account == NULL)
     {
-      tp_account_manager_prepare_async (priv->account_manager, NULL,
-          empathy_account_settings_manager_ready_cb, settings);
+      g_assert (priv->apply_result != NULL && priv->account == NULL);
+
+      empathy_account_settings_do_create_account (settings);
     }
   else
     {
-      tp_account_update_parameters_async (priv->account,
-          priv->parameters, (const gchar **)priv->unset_parameters->data,
+      tp_account_update_parameters_vardict_async (priv->account,
+          build_parameters_variant (settings),
+          (const gchar **) priv->unset_parameters->data,
           empathy_account_settings_account_updated, settings);
     }
 }
@@ -1587,6 +1524,7 @@ empathy_account_settings_apply_async (EmpathyAccountSettings *settings,
 gboolean
 empathy_account_settings_apply_finish (EmpathyAccountSettings *settings,
     GAsyncResult *result,
+    gboolean *reconnect_required,
     GError **error)
 {
   if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result),
@@ -1596,6 +1534,10 @@ empathy_account_settings_apply_finish (EmpathyAccountSettings *settings,
   g_return_val_if_fail (g_simple_async_result_is_valid (result,
     G_OBJECT (settings), empathy_account_settings_apply_finish), FALSE);
 
+  if (reconnect_required != NULL)
+    *reconnect_required = g_simple_async_result_get_op_res_gboolean (
+        G_SIMPLE_ASYNC_RESULT (result));
+
   return TRUE;
 }
 
@@ -1628,8 +1570,16 @@ empathy_account_settings_set_regex (EmpathyAccountSettings *settings,
 {
   EmpathyAccountSettingsPriv *priv = GET_PRIV (settings);
   GRegex *regex;
+  GError *error = NULL;
+
+  regex = g_regex_new (pattern, 0, 0, &error);
+  if (regex == NULL)
+    {
+      g_warning ("Failed to create reg exp: %s", error->message);
+      g_error_free (error);
+      return;
+    }
 
-  regex = g_regex_new (pattern, 0, 0, NULL);
   g_hash_table_insert (priv->param_regexps, g_strdup (param), regex);
 }
 
@@ -1640,7 +1590,6 @@ empathy_account_settings_parameter_is_valid (
 {
   EmpathyAccountSettingsPriv *priv;
   const GRegex *regex;
-  const gchar *value;
 
   g_return_val_if_fail (EMPATHY_IS_ACCOUNT_SETTINGS (settings), FALSE);
 
@@ -1649,7 +1598,7 @@ empathy_account_settings_parameter_is_valid (
   if (g_list_find_custom (priv->required_params, param, (GCompareFunc) strcmp))
     {
       /* first, look if it's set in our own parameters */
-      if (tp_asv_lookup (priv->parameters, param))
+      if (g_hash_table_lookup (priv->parameters, param) != NULL)
         goto test_regex;
 
       /* if we did not unset the parameter, look if it's in the account */
@@ -1671,9 +1620,17 @@ test_regex:
   regex = g_hash_table_lookup (priv->param_regexps, param);
   if (regex)
     {
-      value = empathy_account_settings_get_string (settings, param);
-      if (value != NULL && !g_regex_match (regex, value, 0, NULL))
+      gchar *value;
+      gboolean match;
+
+      value = empathy_account_settings_dup_string (settings, param);
+      if (value == NULL)
         return FALSE;
+
+      match = g_regex_match (regex, value, 0, NULL);
+
+      g_free (value);
+      return match;
     }
 
   return TRUE;
@@ -1707,12 +1664,12 @@ empathy_account_settings_is_valid (EmpathyAccountSettings *settings)
   return TRUE;
 }
 
-const TpConnectionManagerProtocol *
+TpProtocol *
 empathy_account_settings_get_tp_protocol (EmpathyAccountSettings *self)
 {
   EmpathyAccountSettingsPriv *priv = GET_PRIV (self);
 
-  return tp_connection_manager_get_protocol (priv->manager, priv->protocol);
+  return priv->protocol_obj;
 }
 
 gboolean
@@ -1722,3 +1679,49 @@ empathy_account_settings_supports_sasl (EmpathyAccountSettings *self)
 
   return priv->supports_sasl;
 }
+
+gboolean
+empathy_account_settings_param_is_supported (EmpathyAccountSettings *self,
+    const gchar *param)
+{
+  EmpathyAccountSettingsPriv *priv = GET_PRIV (self);
+
+  return tp_protocol_has_param (priv->protocol_obj, param);
+}
+
+void
+empathy_account_settings_set_uri_scheme_tel (EmpathyAccountSettings *self,
+    gboolean associate)
+{
+  EmpathyAccountSettingsPriv *priv = GET_PRIV (self);
+
+  priv->uri_scheme_tel = associate;
+}
+
+gboolean
+empathy_account_settings_has_uri_scheme_tel (
+    EmpathyAccountSettings *self)
+{
+  EmpathyAccountSettingsPriv *priv = GET_PRIV (self);
+
+  return priv->uri_scheme_tel;
+}
+
+void
+empathy_account_settings_set_storage_provider (EmpathyAccountSettings *self,
+    const gchar *storage)
+{
+  EmpathyAccountSettingsPriv *priv = GET_PRIV (self);
+
+  g_free (priv->storage_provider);
+  priv->storage_provider = g_strdup (storage);
+}
+
+void
+empathy_account_settings_set_remember_password (EmpathyAccountSettings *self,
+    gboolean remember)
+{
+  EmpathyAccountSettingsPriv *priv = GET_PRIV (self);
+
+  priv->remember_password = remember;
+}