mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-02-05 09:25:24 -05:00
Move the code to open database files from DatabaseTabWidget to DatabaseOpenDialog.
This commit is contained in:
parent
9d1838a0fe
commit
8fc68045f6
@ -22,12 +22,15 @@
|
|||||||
|
|
||||||
#include "core/Config.h"
|
#include "core/Config.h"
|
||||||
#include "gui/FileDialog.h"
|
#include "gui/FileDialog.h"
|
||||||
|
#include "format/KeePass2Reader.h"
|
||||||
#include "keys/FileKey.h"
|
#include "keys/FileKey.h"
|
||||||
#include "keys/PasswordKey.h"
|
#include "keys/PasswordKey.h"
|
||||||
|
|
||||||
DatabaseOpenDialog::DatabaseOpenDialog(const QString& filename, QWidget* parent)
|
DatabaseOpenDialog::DatabaseOpenDialog(QFile* file, QString filename, QWidget* parent)
|
||||||
: QDialog(parent)
|
: QDialog(parent)
|
||||||
, m_ui(new Ui::DatabaseOpenDialog())
|
, m_ui(new Ui::DatabaseOpenDialog())
|
||||||
|
, m_db(0)
|
||||||
|
, m_file(file)
|
||||||
, m_filename(filename)
|
, m_filename(filename)
|
||||||
{
|
{
|
||||||
m_ui->setupUi(this);
|
m_ui->setupUi(this);
|
||||||
@ -44,7 +47,7 @@ DatabaseOpenDialog::DatabaseOpenDialog(const QString& filename, QWidget* parent)
|
|||||||
connect(m_ui->checkKeyFile, SIGNAL(toggled(bool)), SLOT(setOkButtonEnabled()));
|
connect(m_ui->checkKeyFile, SIGNAL(toggled(bool)), SLOT(setOkButtonEnabled()));
|
||||||
connect(m_ui->comboKeyFile, SIGNAL(editTextChanged(QString)), SLOT(setOkButtonEnabled()));
|
connect(m_ui->comboKeyFile, SIGNAL(editTextChanged(QString)), SLOT(setOkButtonEnabled()));
|
||||||
|
|
||||||
connect(m_ui->buttonBox, SIGNAL(accepted()), SLOT(createKey()));
|
connect(m_ui->buttonBox, SIGNAL(accepted()), SLOT(openDatabase()));
|
||||||
connect(m_ui->buttonBox, SIGNAL(rejected()), SLOT(reject()));
|
connect(m_ui->buttonBox, SIGNAL(rejected()), SLOT(reject()));
|
||||||
|
|
||||||
QHash<QString,QVariant> lastKeyFiles = config()->get("LastKeyFiles").toHash();
|
QHash<QString,QVariant> lastKeyFiles = config()->get("LastKeyFiles").toHash();
|
||||||
@ -58,15 +61,18 @@ DatabaseOpenDialog::~DatabaseOpenDialog()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
CompositeKey DatabaseOpenDialog::key()
|
Database* DatabaseOpenDialog::database()
|
||||||
{
|
{
|
||||||
return m_key;
|
return m_db;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DatabaseOpenDialog::createKey()
|
void DatabaseOpenDialog::openDatabase()
|
||||||
{
|
{
|
||||||
|
KeePass2Reader reader;
|
||||||
|
CompositeKey masterKey;
|
||||||
|
|
||||||
if (m_ui->checkPassword->isChecked()) {
|
if (m_ui->checkPassword->isChecked()) {
|
||||||
m_key.addKey(PasswordKey(m_ui->editPassword->text()));
|
masterKey.addKey(PasswordKey(m_ui->editPassword->text()));
|
||||||
}
|
}
|
||||||
|
|
||||||
QHash<QString,QVariant> lastKeyFiles = config()->get("LastKeyFiles").toHash();
|
QHash<QString,QVariant> lastKeyFiles = config()->get("LastKeyFiles").toHash();
|
||||||
@ -79,7 +85,7 @@ void DatabaseOpenDialog::createKey()
|
|||||||
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);
|
masterKey.addKey(key);
|
||||||
lastKeyFiles[m_filename] = keyFilename;
|
lastKeyFiles[m_filename] = keyFilename;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -88,8 +94,17 @@ void DatabaseOpenDialog::createKey()
|
|||||||
|
|
||||||
config()->set("LastKeyFiles", lastKeyFiles);
|
config()->set("LastKeyFiles", lastKeyFiles);
|
||||||
|
|
||||||
|
m_file->reset();
|
||||||
|
m_db = reader.readDatabase(m_file, masterKey);
|
||||||
|
|
||||||
|
if (m_db) {
|
||||||
accept();
|
accept();
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
QMessageBox::warning(this, tr("Error"), tr("Unable to open the database.\n%1").arg(reader.errorString()));
|
||||||
|
m_ui->editPassword->clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void DatabaseOpenDialog::togglePassword(bool checked)
|
void DatabaseOpenDialog::togglePassword(bool checked)
|
||||||
{
|
{
|
||||||
|
@ -23,6 +23,9 @@
|
|||||||
|
|
||||||
#include "keys/CompositeKey.h"
|
#include "keys/CompositeKey.h"
|
||||||
|
|
||||||
|
class Database;
|
||||||
|
class QFile;
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class DatabaseOpenDialog;
|
class DatabaseOpenDialog;
|
||||||
}
|
}
|
||||||
@ -32,12 +35,12 @@ class DatabaseOpenDialog : public QDialog
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit DatabaseOpenDialog(const QString& filename, QWidget* parent = 0);
|
explicit DatabaseOpenDialog(QFile* file, QString filename, QWidget* parent = 0);
|
||||||
~DatabaseOpenDialog();
|
~DatabaseOpenDialog();
|
||||||
CompositeKey key();
|
Database* database();
|
||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void createKey();
|
void openDatabase();
|
||||||
void togglePassword(bool checked);
|
void togglePassword(bool checked);
|
||||||
void activatePassword();
|
void activatePassword();
|
||||||
void activateKeyFile();
|
void activateKeyFile();
|
||||||
@ -46,7 +49,8 @@ private Q_SLOTS:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
QScopedPointer<Ui::DatabaseOpenDialog> m_ui;
|
QScopedPointer<Ui::DatabaseOpenDialog> m_ui;
|
||||||
CompositeKey m_key;
|
Database* m_db;
|
||||||
|
QFile* m_file;
|
||||||
QString m_filename;
|
QString m_filename;
|
||||||
|
|
||||||
Q_DISABLE_COPY(DatabaseOpenDialog)
|
Q_DISABLE_COPY(DatabaseOpenDialog)
|
||||||
|
@ -86,7 +86,7 @@ void DatabaseTabWidget::openDatabase(const QString& fileName)
|
|||||||
|
|
||||||
void DatabaseTabWidget::openDatabaseDialog()
|
void DatabaseTabWidget::openDatabaseDialog()
|
||||||
{
|
{
|
||||||
m_curKeyDialog = new DatabaseOpenDialog(m_curDbStruct.fileName, m_window);
|
m_curKeyDialog = new DatabaseOpenDialog(m_curDbStruct.file, m_curDbStruct.fileName, m_window);
|
||||||
connect(m_curKeyDialog, SIGNAL(accepted()), SLOT(openDatabaseRead()));
|
connect(m_curKeyDialog, SIGNAL(accepted()), SLOT(openDatabaseRead()));
|
||||||
connect(m_curKeyDialog, SIGNAL(rejected()), SLOT(openDatabaseCleanup()));
|
connect(m_curKeyDialog, SIGNAL(rejected()), SLOT(openDatabaseCleanup()));
|
||||||
m_curKeyDialog->setModal(true);
|
m_curKeyDialog->setModal(true);
|
||||||
@ -95,20 +95,15 @@ void DatabaseTabWidget::openDatabaseDialog()
|
|||||||
|
|
||||||
void DatabaseTabWidget::openDatabaseRead()
|
void DatabaseTabWidget::openDatabaseRead()
|
||||||
{
|
{
|
||||||
m_curDbStruct.file->reset();
|
Database* db = m_curKeyDialog->database();
|
||||||
Database* db = m_reader.readDatabase(m_curDbStruct.file, m_curKeyDialog->key());
|
|
||||||
delete m_curKeyDialog;
|
delete m_curKeyDialog;
|
||||||
m_curKeyDialog = 0;
|
m_curKeyDialog = 0;
|
||||||
|
|
||||||
if (!db) {
|
|
||||||
openDatabaseDialog();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
m_curDbStruct.dbWidget = new DatabaseWidget(db, this);
|
m_curDbStruct.dbWidget = new DatabaseWidget(db, this);
|
||||||
insertDatabase(db, m_curDbStruct);
|
insertDatabase(db, m_curDbStruct);
|
||||||
m_curDbStruct = DatabaseManagerStruct();
|
m_curDbStruct = DatabaseManagerStruct();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void DatabaseTabWidget::openDatabaseCleanup()
|
void DatabaseTabWidget::openDatabaseCleanup()
|
||||||
{
|
{
|
||||||
|
@ -81,7 +81,6 @@ private:
|
|||||||
void insertDatabase(Database* db, const DatabaseManagerStruct& dbStruct);
|
void insertDatabase(Database* db, const DatabaseManagerStruct& dbStruct);
|
||||||
|
|
||||||
QWidget* m_window;
|
QWidget* m_window;
|
||||||
KeePass2Reader m_reader;
|
|
||||||
KeePass2Writer m_writer;
|
KeePass2Writer m_writer;
|
||||||
QHash<Database*, DatabaseManagerStruct> m_dbList;
|
QHash<Database*, DatabaseManagerStruct> m_dbList;
|
||||||
DatabaseManagerStruct m_curDbStruct;
|
DatabaseManagerStruct m_curDbStruct;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user