From 90a4200981a398b7f8a053179f03c319e381d058 Mon Sep 17 00:00:00 2001 From: nowrep Date: Sat, 18 May 2013 13:29:11 +0200 Subject: [PATCH] [PasswordManager] Correctly switch password backends. --- src/lib/autofill/passwordmanager.cpp | 11 +++++++++++ src/lib/autofill/passwordmanager.h | 1 + src/lib/preferences/autofillmanager.cpp | 5 ++++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/lib/autofill/passwordmanager.cpp b/src/lib/autofill/passwordmanager.cpp index be548ecee..3a1198f55 100644 --- a/src/lib/autofill/passwordmanager.cpp +++ b/src/lib/autofill/passwordmanager.cpp @@ -126,6 +126,17 @@ PasswordBackend* PasswordManager::activeBackend() const return m_backend; } +void PasswordManager::switchBackend(PasswordBackend* backend) +{ + if (!backend) { + return; + } + + m_backend->setActive(false); + m_backend = backend; + m_backend->setActive(true); +} + bool PasswordManager::registerBackend(const QString &id, PasswordBackend* backend) { if (m_backends.contains(id)) { diff --git a/src/lib/autofill/passwordmanager.h b/src/lib/autofill/passwordmanager.h index e8deab72d..d11993aa2 100644 --- a/src/lib/autofill/passwordmanager.h +++ b/src/lib/autofill/passwordmanager.h @@ -67,6 +67,7 @@ public: QHash availableBackends() const; PasswordBackend* activeBackend() const; + void switchBackend(PasswordBackend* backend); bool registerBackend(const QString &id, PasswordBackend* backend); void unregisterBackend(PasswordBackend* backend); diff --git a/src/lib/preferences/autofillmanager.cpp b/src/lib/preferences/autofillmanager.cpp index ef285b213..2dee6b40d 100644 --- a/src/lib/preferences/autofillmanager.cpp +++ b/src/lib/preferences/autofillmanager.cpp @@ -117,17 +117,20 @@ void AutoFillManager::changePasswordBackend() Settings settings; settings.beginGroup("PasswordManager"); + PasswordBackend* backend = 0; foreach (const QString &key, backends.keys()) { if (backends[key]->name() == item) { + backend = backends[key]; settings.setValue("Backend", key); break; } } settings.endGroup(); + + mApp->autoFill()->passwordManager()->switchBackend(backend); } - mApp->autoFill()->passwordManager()->loadSettings(); QTimer::singleShot(0, this, SLOT(loadPasswords())); }