[empathy] Remember password at least until session restart



commit 4f0673c142e6529b6aaa0022b8463fa67b2ff060
Author: Xavier Claessens <xavier claessens collabora co uk>
Date:   Fri Aug 24 10:14:43 2012 +0200

    Remember password at least until session restart
    
    https://bugzilla.gnome.org/show_bug.cgi?id=680776

 libempathy-gtk/empathy-account-widget.c  |   14 ++++----------
 libempathy/empathy-account-settings.c    |   16 ++++++++++++++--
 libempathy/empathy-account-settings.h    |    4 ++++
 libempathy/empathy-keyring.c             |    5 ++++-
 libempathy/empathy-keyring.h             |    2 +-
 libempathy/empathy-server-sasl-handler.c |   12 ++++--------
 6 files changed, 31 insertions(+), 22 deletions(-)
---
diff --git a/libempathy-gtk/empathy-account-widget.c b/libempathy-gtk/empathy-account-widget.c
index c71b24f..aea76cf 100644
--- a/libempathy-gtk/empathy-account-widget.c
+++ b/libempathy-gtk/empathy-account-widget.c
@@ -1864,16 +1864,8 @@ static void
 remember_password_toggled_cb (GtkToggleButton *button,
     EmpathyAccountWidget *self)
 {
-  if (gtk_toggle_button_get_active (button))
-    {
-      gtk_widget_set_sensitive (self->priv->param_password_widget, TRUE);
-    }
-  else
-    {
-      gtk_widget_set_sensitive (self->priv->param_password_widget, FALSE);
-      gtk_entry_set_text (GTK_ENTRY (self->priv->param_password_widget), "");
-      empathy_account_settings_unset (self->priv->settings, "password");
-    }
+  empathy_account_settings_set_remember_password (self->priv->settings,
+      gtk_toggle_button_get_active (button));
 }
 
 static void
@@ -2015,6 +2007,8 @@ do_constructed (GObject *obj)
       && !empathy_account_settings_supports_sasl (self->priv->settings))
     {
       gtk_widget_set_visible (self->priv->remember_password_widget, FALSE);
+      empathy_account_settings_set_remember_password (self->priv->settings,
+          TRUE);
     }
 
   /* dup and init the account-manager */
diff --git a/libempathy/empathy-account-settings.c b/libempathy/empathy-account-settings.c
index 12154eb..ee0cb34 100644
--- a/libempathy/empathy-account-settings.c
+++ b/libempathy/empathy-account-settings.c
@@ -82,6 +82,7 @@ struct _EmpathyAccountSettingsPriv
 
   gboolean supports_sasl;
   gboolean password_changed;
+  gboolean remember_password;
 
   gchar *password;
   gchar *password_original;
@@ -1344,7 +1345,8 @@ empathy_account_settings_account_updated (GObject *source,
           /* 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
@@ -1399,7 +1401,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;
         }
@@ -1726,3 +1729,12 @@ empathy_account_settings_set_storage_provider (EmpathyAccountSettings *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;
+}
diff --git a/libempathy/empathy-account-settings.h b/libempathy/empathy-account-settings.h
index 7f17e33..c540652 100644
--- a/libempathy/empathy-account-settings.h
+++ b/libempathy/empathy-account-settings.h
@@ -197,6 +197,10 @@ void empathy_account_settings_set_storage_provider (
     EmpathyAccountSettings *self,
     const gchar *storage);
 
+void empathy_account_settings_set_remember_password (
+    EmpathyAccountSettings *self,
+    gboolean remember);
+
 G_END_DECLS
 
 #endif /* #ifndef __EMPATHY_ACCOUNT_SETTINGS_H__*/
diff --git a/libempathy/empathy-keyring.c b/libempathy/empathy-keyring.c
index 5b69cc2..f9ca476 100644
--- a/libempathy/empathy-keyring.c
+++ b/libempathy/empathy-keyring.c
@@ -181,6 +181,7 @@ store_password_cb (GObject *source,
 void
 empathy_keyring_set_account_password_async (TpAccount *account,
     const gchar *password,
+    gboolean remember,
     GAsyncReadyCallback callback,
     gpointer user_data)
 {
@@ -202,7 +203,9 @@ empathy_keyring_set_account_password_async (TpAccount *account,
   name = g_strdup_printf (_("IM account password for %s (%s)"),
       tp_account_get_display_name (account), account_id);
 
-  secret_password_store (&account_keyring_schema, NULL, name, password,
+  secret_password_store (&account_keyring_schema,
+      remember ? NULL : SECRET_COLLECTION_SESSION,
+      name, password,
       NULL, store_password_cb, simple,
       "account-id", account_id,
       "param-name", "password",
diff --git a/libempathy/empathy-keyring.h b/libempathy/empathy-keyring.h
index 92c8a6e..05c460e 100644
--- a/libempathy/empathy-keyring.h
+++ b/libempathy/empathy-keyring.h
@@ -41,7 +41,7 @@ const gchar * empathy_keyring_get_room_password_finish (TpAccount *account,
     GAsyncResult *result, GError **error);
 
 void empathy_keyring_set_account_password_async (TpAccount *account,
-    const gchar *password, GAsyncReadyCallback callback,
+    const gchar *password, gboolean remember, GAsyncReadyCallback callback,
     gpointer user_data);
 
 gboolean empathy_keyring_set_account_password_finish (TpAccount *account,
diff --git a/libempathy/empathy-server-sasl-handler.c b/libempathy/empathy-server-sasl-handler.c
index 1518f33..db7ba1b 100644
--- a/libempathy/empathy-server-sasl-handler.c
+++ b/libempathy/empathy-server-sasl-handler.c
@@ -115,14 +115,10 @@ sasl_status_changed_cb (TpChannel *channel,
 
   if (status == TP_SASL_STATUS_SERVER_SUCCEEDED)
     {
-      if (priv->save_password)
-        {
-          DEBUG ("Saving password in keyring");
-
-          empathy_keyring_set_account_password_async (priv->account,
-              priv->password, empathy_server_sasl_handler_set_password_cb,
-              NULL);
-        }
+      empathy_keyring_set_account_password_async (priv->account,
+          priv->password, priv->save_password,
+          empathy_server_sasl_handler_set_password_cb,
+          NULL);
 
       DEBUG ("Calling AcceptSASL");
       tp_cli_channel_interface_sasl_authentication_call_accept_sasl (



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