]> 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 e32e085b71b450c4028b82314648b3ed7c5951f5..064d4d21580e398900cb276955dcc84d0cf3b3f5 100644 (file)
  */
 
 #include "config.h"
-
-#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 "empathy-account-settings.h"
+
 #include "empathy-connection-managers.h"
 #include "empathy-keyring.h"
-#include "empathy-utils.h"
 #include "empathy-presence-manager.h"
+#include "empathy-utils.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)
 
@@ -76,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;
@@ -228,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
@@ -397,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)
     {
@@ -463,82 +457,10 @@ empathy_account_settings_get_password_cb (GObject *source,
   g_signal_emit (self, signals[PASSWORD_RETRIEVED], 0);
 }
 
-static void
-empathy_account_settings_migrate_password_cb (GObject *source,
-    GAsyncResult *result,
-    gpointer user_data)
-{
-  TpAccount *account = TP_ACCOUNT (source);
-  GError *error = NULL;
-  EmpathyAccountSettings *self = user_data;
-  EmpathyAccountSettingsPriv *priv = GET_PRIV (self);
-  GVariantBuilder *builder;
-  const gchar *unset[] = { "password", NULL };
-
-  if (!empathy_keyring_set_account_password_finish (account, result, &error))
-    {
-      DEBUG ("Failed to set password: %s", error->message);
-      g_clear_error (&error);
-      return;
-    }
-
-  /* Now clear the password MC has stored. */
-  builder = g_variant_builder_new (G_VARIANT_TYPE_VARDICT);
-
-  tp_account_update_parameters_vardict_async (priv->account,
-      g_variant_builder_end (builder), unset, NULL, NULL);
-
-  g_hash_table_remove (priv->parameters, "password");
-}
-
 static GVariant * empathy_account_settings_dup (
     EmpathyAccountSettings *settings,
     const gchar *param);
 
-static void
-empathy_account_settings_try_migrating_password (EmpathyAccountSettings *self)
-{
-  EmpathyAccountSettingsPriv *priv = GET_PRIV (self);
-  GVariant *v;
-  const gchar *password;
-
-  v = empathy_account_settings_dup (self, "password");
-  if (v == NULL)
-    return;
-
-  if (!priv->supports_sasl)
-    goto out;
-
-  /* mission-control still has our password, although the CM
-   * supports SASL. Let's try migrating it. */
-
-  DEBUG ("Trying to migrate password parameter from MC to the "
-      "keyring ourselves for account %s",
-      tp_account_get_path_suffix (priv->account));
-
-  /* I can't imagine why this would fail. */
-  if (!g_variant_is_of_type (v, G_VARIANT_TYPE_STRING))
-    goto out;
-
-  password = g_variant_get_string (v, NULL);
-
-  if (EMP_STR_EMPTY (password))
-    goto out;
-
-  empathy_keyring_set_account_password_async (priv->account, password,
-      empathy_account_settings_migrate_password_cb, self);
-
-  /* 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);
-
-out:
-  g_variant_unref (v);
-}
-
 static void
 empathy_account_settings_check_readyness (EmpathyAccountSettings *self)
 {
@@ -624,10 +546,6 @@ empathy_account_settings_check_readyness (EmpathyAccountSettings *self)
            (GDestroyNotify) tp_connection_manager_param_free);
     }
 
-  /* NOTE: When removing MC migration code, remove this call, and the
-   * function it's calling. That's it. */
-  empathy_account_settings_try_migrating_password (self);
-
   /* priv->account won't be a proper account if it's the account
    * assistant showing this widget. */
   if (priv->supports_sasl && !priv->password_requested
@@ -906,7 +824,6 @@ empathy_account_settings_unset (EmpathyAccountSettings *settings,
     {
       g_free (priv->password);
       priv->password = NULL;
-      priv->password_changed = TRUE;
       return;
     }
 
@@ -924,7 +841,6 @@ 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);
 
@@ -1146,7 +1062,6 @@ empathy_account_settings_set (EmpathyAccountSettings *settings,
     {
       g_free (priv->password);
       priv->password = g_variant_dup_string (v, NULL);
-      priv->password_changed = TRUE;
     }
   else
     {
@@ -1409,16 +1324,22 @@ empathy_account_settings_account_updated (GObject *source,
       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)
         {
           /* 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,
+          empathy_keyring_set_account_password_async (priv->account,
+              priv->password, priv->remember_password,
               empathy_account_settings_set_password_cb, settings);
         }
       else
@@ -1430,12 +1351,6 @@ empathy_account_settings_account_updated (GObject *source,
       return;
     }
 
-  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);
-
 out:
   empathy_account_settings_discard_changes (settings);
 
@@ -1473,7 +1388,8 @@ empathy_account_settings_created_cb (GObject *source,
            * 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, empathy_account_settings_set_password_cb,
+              priv->password, priv->remember_password,
+              empathy_account_settings_set_password_cb,
               settings);
           return;
         }
@@ -1532,6 +1448,12 @@ empathy_account_settings_do_create_account (EmpathyAccountSettings *self)
       tp_account_request_set_parameter (account_req, key, value);
     }
 
+  if (priv->storage_provider != NULL)
+    {
+      tp_account_request_set_storage_provider (account_req,
+          priv->storage_provider);
+    }
+
   tp_account_request_create_account_async (account_req,
       empathy_account_settings_created_cb, self);
 }
@@ -1784,3 +1706,22 @@ empathy_account_settings_has_uri_scheme_tel (
 
   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;
+}