diff --git a/src/lib/autofill/passwordmanager.cpp b/src/lib/autofill/passwordmanager.cpp index 1dc59b81f..22fd2be05 100644 --- a/src/lib/autofill/passwordmanager.cpp +++ b/src/lib/autofill/passwordmanager.cpp @@ -131,8 +131,10 @@ PasswordBackend* PasswordManager::activeBackend() return m_backend; } -void PasswordManager::switchBackend(PasswordBackend* backend) +void PasswordManager::switchBackend(const QString &backendID) { + PasswordBackend* backend = m_backends.value(backendID); + if (!backend) { return; } @@ -140,6 +142,13 @@ void PasswordManager::switchBackend(PasswordBackend* backend) m_backend->setActive(false); m_backend = backend; m_backend->setActive(true); + + Settings settings; + settings.beginGroup("PasswordManager"); + settings.setValue("Backend", backendID); + settings.endGroup(); + + emit passwordBackendChanged(); } bool PasswordManager::registerBackend(const QString &id, PasswordBackend* backend) diff --git a/src/lib/autofill/passwordmanager.h b/src/lib/autofill/passwordmanager.h index 939583bb7..770f3f280 100644 --- a/src/lib/autofill/passwordmanager.h +++ b/src/lib/autofill/passwordmanager.h @@ -74,7 +74,7 @@ public: QHash availableBackends(); PasswordBackend* activeBackend(); - void switchBackend(PasswordBackend* backend); + void switchBackend(const QString &backendID); bool registerBackend(const QString &id, PasswordBackend* backend); void unregisterBackend(PasswordBackend* backend); @@ -90,6 +90,9 @@ private: PasswordBackend* m_backend; DatabasePasswordBackend* m_databaseBackend; QHash m_backends; + +signals: + void passwordBackendChanged(); }; // Hint to QVector to use std::realloc on item moving diff --git a/src/lib/preferences/autofillmanager.cpp b/src/lib/preferences/autofillmanager.cpp index c773d4dee..6ac002e9a 100644 --- a/src/lib/preferences/autofillmanager.cpp +++ b/src/lib/preferences/autofillmanager.cpp @@ -46,6 +46,7 @@ AutoFillManager::AutoFillManager(QWidget* parent) connect(ui->search, SIGNAL(textChanged(QString)), ui->treePass, SLOT(filterString(QString))); connect(ui->changeBackend, SIGNAL(clicked()), this, SLOT(changePasswordBackend())); connect(ui->backendOptions, SIGNAL(clicked()), this, SLOT(showBackendOptions())); + connect(m_passwordManager, SIGNAL(passwordBackendChanged()), this, SLOT(currentPasswordBackendChanged())); connect(ui->removeExcept, SIGNAL(clicked()), this, SLOT(removeExcept())); connect(ui->removeAllExcept, SIGNAL(clicked()), this, SLOT(removeAllExcept())); @@ -119,9 +120,6 @@ void AutoFillManager::changePasswordBackend() // Switch backends if (!item.isEmpty()) { - Settings settings; - settings.beginGroup("PasswordManager"); - PasswordBackend* backend = 0; QHashIterator i(backends); @@ -129,21 +127,14 @@ void AutoFillManager::changePasswordBackend() i.next(); if (i.value()->name() == item) { backend = i.value(); - settings.setValue("Backend", i.key()); break; } } - settings.endGroup(); - if (backend) { - m_passwordManager->switchBackend(backend); - ui->backendOptions->setVisible(backend->hasSettings()); - ui->currentBackend->setText(QString("%1").arg(backend->name())); + m_passwordManager->switchBackend(backends.key(backend)); } } - - QTimer::singleShot(0, this, SLOT(loadPasswords())); } void AutoFillManager::showBackendOptions() @@ -335,6 +326,14 @@ void AutoFillManager::slotExportPasswords() QApplication::restoreOverrideCursor(); } +void AutoFillManager::currentPasswordBackendChanged() +{ + ui->currentBackend->setText(QString("%1").arg(m_passwordManager->activeBackend()->name())); + ui->backendOptions->setVisible(m_passwordManager->activeBackend()->hasSettings()); + + QTimer::singleShot(0, this, SLOT(loadPasswords())); +} + AutoFillManager::~AutoFillManager() { delete ui; diff --git a/src/lib/preferences/autofillmanager.h b/src/lib/preferences/autofillmanager.h index 60329f1ef..89e26740e 100644 --- a/src/lib/preferences/autofillmanager.h +++ b/src/lib/preferences/autofillmanager.h @@ -58,6 +58,8 @@ private slots: void slotImportPasswords(); void slotExportPasswords(); + void currentPasswordBackendChanged(); + private: Ui::AutoFillManager* ui;