mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-02-09 03:08:32 -05:00
Remember last key file.
This commit is contained in:
parent
62e7ba6e55
commit
256dc89466
@ -80,7 +80,7 @@ void DatabaseManager::openDatabase(const QString& fileName)
|
|||||||
Database* db;
|
Database* db;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
QScopedPointer<KeyOpenDialog> keyDialog(new KeyOpenDialog(m_window));
|
QScopedPointer<KeyOpenDialog> keyDialog(new KeyOpenDialog(fileName, m_window));
|
||||||
if (keyDialog->exec() == QDialog::Rejected) {
|
if (keyDialog->exec() == QDialog::Rejected) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -21,16 +21,17 @@
|
|||||||
#include <QtGui/QFileDialog>
|
#include <QtGui/QFileDialog>
|
||||||
#include <QtGui/QMessageBox>
|
#include <QtGui/QMessageBox>
|
||||||
|
|
||||||
|
#include "core/Config.h"
|
||||||
#include "keys/FileKey.h"
|
#include "keys/FileKey.h"
|
||||||
#include "keys/PasswordKey.h"
|
#include "keys/PasswordKey.h"
|
||||||
|
|
||||||
KeyOpenDialog::KeyOpenDialog(QWidget* parent)
|
KeyOpenDialog::KeyOpenDialog(const QString& filename, QWidget* parent)
|
||||||
: QDialog(parent)
|
: QDialog(parent)
|
||||||
, m_ui(new Ui::KeyOpenDialog())
|
, m_ui(new Ui::KeyOpenDialog())
|
||||||
|
, m_filename(filename)
|
||||||
{
|
{
|
||||||
m_ui->setupUi(this);
|
m_ui->setupUi(this);
|
||||||
|
|
||||||
m_ui->comboKeyFile->addItem("");
|
|
||||||
m_ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
|
m_ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
|
||||||
|
|
||||||
connect(m_ui->buttonTogglePassword, SIGNAL(toggled(bool)), SLOT(togglePassword(bool)));
|
connect(m_ui->buttonTogglePassword, SIGNAL(toggled(bool)), SLOT(togglePassword(bool)));
|
||||||
@ -45,6 +46,12 @@ KeyOpenDialog::KeyOpenDialog(QWidget* parent)
|
|||||||
|
|
||||||
connect(m_ui->buttonBox, SIGNAL(accepted()), SLOT(createKey()));
|
connect(m_ui->buttonBox, SIGNAL(accepted()), SLOT(createKey()));
|
||||||
connect(m_ui->buttonBox, SIGNAL(rejected()), SLOT(reject()));
|
connect(m_ui->buttonBox, SIGNAL(rejected()), SLOT(reject()));
|
||||||
|
|
||||||
|
QHash<QString,QVariant> lastKeyFiles = config()->get("LastKeyFiles").toHash();
|
||||||
|
if (lastKeyFiles.contains(m_filename)) {
|
||||||
|
m_ui->checkKeyFile->setChecked(true);
|
||||||
|
m_ui->comboKeyFile->addItem(lastKeyFiles[m_filename].toString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
KeyOpenDialog::~KeyOpenDialog()
|
KeyOpenDialog::~KeyOpenDialog()
|
||||||
@ -62,15 +69,24 @@ void KeyOpenDialog::createKey()
|
|||||||
m_key.addKey(PasswordKey(m_ui->editPassword->text()));
|
m_key.addKey(PasswordKey(m_ui->editPassword->text()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QHash<QString,QVariant> lastKeyFiles = config()->get("LastKeyFiles").toHash();
|
||||||
|
|
||||||
if (m_ui->checkKeyFile->isChecked()) {
|
if (m_ui->checkKeyFile->isChecked()) {
|
||||||
FileKey key;
|
FileKey key;
|
||||||
|
QString keyFilename = m_ui->comboKeyFile->currentText();
|
||||||
QString errorMsg;
|
QString errorMsg;
|
||||||
if (!key.load(m_ui->comboKeyFile->currentText(), &errorMsg)) {
|
if (!key.load(keyFilename, &errorMsg)) {
|
||||||
QMessageBox::warning(this, tr("Error"), tr("Can't open key file:\n%1").arg(errorMsg));
|
QMessageBox::warning(this, tr("Error"), tr("Can't open key file:\n%1").arg(errorMsg));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
m_key.addKey(key);
|
m_key.addKey(key);
|
||||||
|
lastKeyFiles[m_filename] = keyFilename;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
lastKeyFiles.remove(m_filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
config()->set("LastKeyFiles", lastKeyFiles);
|
||||||
|
|
||||||
accept();
|
accept();
|
||||||
}
|
}
|
||||||
@ -103,6 +119,6 @@ void KeyOpenDialog::browseKeyFile()
|
|||||||
QString filename = QFileDialog::getOpenFileName(this, tr("Select key file"), QString(), filters);
|
QString filename = QFileDialog::getOpenFileName(this, tr("Select key file"), QString(), filters);
|
||||||
|
|
||||||
if (!filename.isEmpty()) {
|
if (!filename.isEmpty()) {
|
||||||
m_ui->comboKeyFile->setItemText(0, filename);
|
m_ui->comboKeyFile->lineEdit()->setText(filename);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ class KeyOpenDialog : public QDialog
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit KeyOpenDialog(QWidget* parent = 0);
|
explicit KeyOpenDialog(const QString& filename, QWidget* parent = 0);
|
||||||
~KeyOpenDialog();
|
~KeyOpenDialog();
|
||||||
CompositeKey key();
|
CompositeKey key();
|
||||||
|
|
||||||
@ -47,6 +47,7 @@ private Q_SLOTS:
|
|||||||
private:
|
private:
|
||||||
QScopedPointer<Ui::KeyOpenDialog> m_ui;
|
QScopedPointer<Ui::KeyOpenDialog> m_ui;
|
||||||
CompositeKey m_key;
|
CompositeKey m_key;
|
||||||
|
QString m_filename;
|
||||||
|
|
||||||
Q_DISABLE_COPY(KeyOpenDialog)
|
Q_DISABLE_COPY(KeyOpenDialog)
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user