mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-20 02:36:34 +01:00
[PasswordBackends] Added possibility to change backends in preferences.
This commit is contained in:
parent
95a44ded44
commit
34f8162615
@ -18,6 +18,7 @@
|
||||
#include "databasepasswordbackend.h"
|
||||
#include "mainapplication.h"
|
||||
#include "databasewriter.h"
|
||||
#include "autofill.h"
|
||||
|
||||
#include <QVector>
|
||||
#include <QSqlQuery>
|
||||
@ -27,6 +28,11 @@ DatabasePasswordBackend::DatabasePasswordBackend()
|
||||
{
|
||||
}
|
||||
|
||||
QString DatabasePasswordBackend::name() const
|
||||
{
|
||||
return AutoFill::tr("Database (plaintext)");
|
||||
}
|
||||
|
||||
QVector<PasswordEntry> DatabasePasswordBackend::getEntries(const QUrl &url)
|
||||
{
|
||||
const QString &host = PasswordManager::createHost(url);
|
||||
|
@ -25,6 +25,8 @@ class DatabasePasswordBackend : public PasswordBackend
|
||||
public:
|
||||
explicit DatabasePasswordBackend();
|
||||
|
||||
QString name() const;
|
||||
|
||||
QVector<PasswordEntry> getEntries(const QUrl &url);
|
||||
QVector<PasswordEntry> getAllEntries();
|
||||
|
||||
|
@ -26,6 +26,8 @@ public:
|
||||
explicit PasswordBackend();
|
||||
virtual ~PasswordBackend() { }
|
||||
|
||||
virtual QString name() const = 0;
|
||||
|
||||
virtual QVector<PasswordEntry> getEntries(const QUrl &url) = 0;
|
||||
virtual QVector<PasswordEntry> getAllEntries() = 0;
|
||||
|
||||
|
@ -116,6 +116,16 @@ void PasswordManager::removeAllEntries()
|
||||
m_backend->removeAll();
|
||||
}
|
||||
|
||||
QHash<QString, PasswordBackend*> PasswordManager::availableBackends() const
|
||||
{
|
||||
return m_backends;
|
||||
}
|
||||
|
||||
PasswordBackend* PasswordManager::activeBackend() const
|
||||
{
|
||||
return m_backend;
|
||||
}
|
||||
|
||||
bool PasswordManager::registerBackend(const QString &id, PasswordBackend* backend)
|
||||
{
|
||||
if (m_backends.contains(id)) {
|
||||
|
@ -65,6 +65,9 @@ public:
|
||||
void removeEntry(const PasswordEntry &entry);
|
||||
void removeAllEntries();
|
||||
|
||||
QHash<QString, PasswordBackend*> availableBackends() const;
|
||||
PasswordBackend* activeBackend() const;
|
||||
|
||||
bool registerBackend(const QString &id, PasswordBackend* backend);
|
||||
void unregisterBackend(PasswordBackend* backend);
|
||||
|
||||
|
@ -16,17 +16,19 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* ============================================================ */
|
||||
#include "autofillmanager.h"
|
||||
#include "ui_autofillmanager.h"
|
||||
#include "autofill.h"
|
||||
#include "passwordmanager.h"
|
||||
#include "passwordbackends/passwordbackend.h"
|
||||
#include "mainapplication.h"
|
||||
#include "ui_autofillmanager.h"
|
||||
#include "settings.h"
|
||||
|
||||
#include <QUrl>
|
||||
#include <QMenu>
|
||||
#include <QTimer>
|
||||
#include <QSqlQuery>
|
||||
#include <QMessageBox>
|
||||
#include <QInputDialog>
|
||||
#include <QUrl>
|
||||
#include <QFileDialog>
|
||||
|
||||
AutoFillManager::AutoFillManager(QWidget* parent)
|
||||
@ -41,6 +43,7 @@ AutoFillManager::AutoFillManager(QWidget* parent)
|
||||
connect(ui->editPass, SIGNAL(clicked()), this, SLOT(editPass()));
|
||||
connect(ui->showPasswords, SIGNAL(clicked()), this, SLOT(showPasswords()));
|
||||
connect(ui->search, SIGNAL(textChanged(QString)), ui->treePass, SLOT(filterString(QString)));
|
||||
connect(ui->changeBackend, SIGNAL(clicked()), this, SLOT(changePasswordBackend()));
|
||||
|
||||
connect(ui->removeExcept, SIGNAL(clicked()), this, SLOT(removeExcept()));
|
||||
connect(ui->removeAllExcept, SIGNAL(clicked()), this, SLOT(removeAllExcept()));
|
||||
@ -52,6 +55,10 @@ AutoFillManager::AutoFillManager(QWidget* parent)
|
||||
ui->importExport->setPopupMode(QToolButton::InstantPopup);
|
||||
ui->search->setPlaceholderText(tr("Search"));
|
||||
|
||||
// Password backends
|
||||
ui->currentBackend->setText(QString("<b>%1</b>").arg(mApp->autoFill()->passwordManager()->activeBackend()->name()));
|
||||
|
||||
// Load passwords
|
||||
QTimer::singleShot(0, this, SLOT(loadPasswords()));
|
||||
}
|
||||
|
||||
@ -89,6 +96,41 @@ void AutoFillManager::loadPasswords()
|
||||
ui->treeExcept->sortByColumn(-1);
|
||||
}
|
||||
|
||||
void AutoFillManager::changePasswordBackend()
|
||||
{
|
||||
QHash<QString, PasswordBackend*> backends = mApp->autoFill()->passwordManager()->availableBackends();
|
||||
QStringList items;
|
||||
|
||||
int current = 0;
|
||||
|
||||
foreach (const QString &key, backends.keys()) {
|
||||
if (backends[key] == mApp->autoFill()->passwordManager()->activeBackend()) {
|
||||
current = items.size();
|
||||
}
|
||||
|
||||
items << backends[key]->name();
|
||||
}
|
||||
|
||||
QString item = QInputDialog::getItem(this, tr("Change backend..."), tr("Change backend:"), items, current, false);
|
||||
|
||||
if (!item.isEmpty()) {
|
||||
Settings settings;
|
||||
settings.beginGroup("PasswordManager");
|
||||
|
||||
foreach (const QString &key, backends.keys()) {
|
||||
if (backends[key]->name() == item) {
|
||||
settings.setValue("Backend", key);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
settings.endGroup();
|
||||
}
|
||||
|
||||
mApp->autoFill()->passwordManager()->loadSettings();
|
||||
QTimer::singleShot(0, this, SLOT(loadPasswords()));
|
||||
}
|
||||
|
||||
void AutoFillManager::showPasswords()
|
||||
{
|
||||
if (m_passwordsShown) {
|
||||
|
@ -39,6 +39,7 @@ public:
|
||||
|
||||
private slots:
|
||||
void loadPasswords();
|
||||
void changePasswordBackend();
|
||||
|
||||
void removePass();
|
||||
void removeAllPass();
|
||||
|
@ -7,10 +7,50 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>537</width>
|
||||
<height>348</height>
|
||||
<height>372</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Passwords are stored in:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="currentBackend"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="changeBackend">
|
||||
<property name="text">
|
||||
<string>Change backend</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QTabWidget" name="tabWidget">
|
||||
<property name="focusPolicy">
|
||||
|
@ -16,6 +16,7 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* ============================================================ */
|
||||
#include "kwalletpasswordbackend.h"
|
||||
#include "kwalletplugin.h"
|
||||
|
||||
#include <QDateTime>
|
||||
#include <QDebug>
|
||||
@ -42,6 +43,11 @@ KWalletPasswordBackend::KWalletPasswordBackend()
|
||||
{
|
||||
}
|
||||
|
||||
QString KWalletPasswordBackend::name() const
|
||||
{
|
||||
return KWalletPlugin::tr("KWallet");
|
||||
}
|
||||
|
||||
static bool compareEntries(const PasswordEntry &e1, const PasswordEntry &e2)
|
||||
{
|
||||
return e1.id.toString() > e2.id.toString();
|
||||
|
@ -30,6 +30,8 @@ public:
|
||||
explicit KWalletPasswordBackend();
|
||||
~KWalletPasswordBackend();
|
||||
|
||||
QString name() const;
|
||||
|
||||
QVector<PasswordEntry> getEntries(const QUrl &url);
|
||||
QVector<PasswordEntry> getAllEntries();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user