mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-02-05 01:15:33 -05:00
Implement opening databases with key files.
This commit is contained in:
parent
61dc295fa0
commit
566b239a50
@ -18,6 +18,10 @@
|
||||
#include "KeyOpenDialog.h"
|
||||
#include "ui_KeyOpenDialog.h"
|
||||
|
||||
#include <QtGui/QFileDialog>
|
||||
#include <QtGui/QMessageBox>
|
||||
|
||||
#include "keys/FileKey.h"
|
||||
#include "keys/PasswordKey.h"
|
||||
|
||||
KeyOpenDialog::KeyOpenDialog(QWidget* parent)
|
||||
@ -26,9 +30,21 @@ KeyOpenDialog::KeyOpenDialog(QWidget* parent)
|
||||
{
|
||||
m_ui->setupUi(this);
|
||||
|
||||
m_ui->comboKeyFile->addItem("");
|
||||
m_ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
|
||||
|
||||
connect(m_ui->buttonTogglePassword, SIGNAL(toggled(bool)), SLOT(togglePassword(bool)));
|
||||
connect(m_ui->buttonBrowseFile, SIGNAL(clicked()), SLOT(browseKeyFile()));
|
||||
|
||||
connect(m_ui->editPassword, SIGNAL(textChanged(QString)), SLOT(activatePassword()));
|
||||
connect(m_ui->comboKeyFile, SIGNAL(editTextChanged(QString)), SLOT(activateKeyFile()));
|
||||
|
||||
connect(m_ui->checkPassword, 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->buttonBox, SIGNAL(accepted()), SLOT(createKey()));
|
||||
connect(m_ui->buttonBox, SIGNAL(rejected()), SLOT(reject()));
|
||||
}
|
||||
|
||||
KeyOpenDialog::~KeyOpenDialog()
|
||||
@ -47,8 +63,16 @@ void KeyOpenDialog::createKey()
|
||||
}
|
||||
|
||||
if (m_ui->checkKeyFile->isChecked()) {
|
||||
// TODO read key file
|
||||
FileKey key;
|
||||
QString errorMsg;
|
||||
if (!key.load(m_ui->comboKeyFile->currentText(), &errorMsg)) {
|
||||
QMessageBox::warning(this, tr("Error"), tr("Can't open key file:\n%1").arg(errorMsg));
|
||||
return;
|
||||
}
|
||||
m_key.addKey(key);
|
||||
}
|
||||
|
||||
accept();
|
||||
}
|
||||
|
||||
void KeyOpenDialog::togglePassword(bool checked)
|
||||
@ -60,3 +84,25 @@ void KeyOpenDialog::activatePassword()
|
||||
{
|
||||
m_ui->checkPassword->setChecked(true);
|
||||
}
|
||||
|
||||
void KeyOpenDialog::activateKeyFile()
|
||||
{
|
||||
m_ui->checkKeyFile->setChecked(true);
|
||||
}
|
||||
|
||||
void KeyOpenDialog::setOkButtonEnabled()
|
||||
{
|
||||
bool enable = m_ui->checkPassword->isChecked() || (m_ui->checkKeyFile->isChecked() && !m_ui->comboKeyFile->currentText().isEmpty());
|
||||
|
||||
m_ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(enable);
|
||||
}
|
||||
|
||||
void KeyOpenDialog::browseKeyFile()
|
||||
{
|
||||
QString filters = QString("%1 (*);;%2 (*.key)").arg(tr("All files"), tr("Key files"));
|
||||
QString filename = QFileDialog::getOpenFileName(this, "Select key file", QString(), filters);
|
||||
|
||||
if (!filename.isEmpty()) {
|
||||
m_ui->comboKeyFile->setItemText(0, filename);
|
||||
}
|
||||
}
|
||||
|
@ -40,6 +40,9 @@ private Q_SLOTS:
|
||||
void createKey();
|
||||
void togglePassword(bool checked);
|
||||
void activatePassword();
|
||||
void activateKeyFile();
|
||||
void setOkButtonEnabled();
|
||||
void browseKeyFile();
|
||||
|
||||
private:
|
||||
QScopedPointer<Ui::KeyOpenDialog> m_ui;
|
||||
|
@ -62,6 +62,9 @@
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="editable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
@ -86,38 +89,5 @@
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>KeyOpenDialog</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>248</x>
|
||||
<y>254</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>KeyOpenDialog</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>316</x>
|
||||
<y>260</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
Loading…
x
Reference in New Issue
Block a user