diff options
author | Felix Geyer <debfx@fobos.de> | 2011-12-24 22:19:52 +0400 |
---|---|---|
committer | Felix Geyer <debfx@fobos.de> | 2011-12-24 22:19:52 +0400 |
commit | 566b239a502bfd499cfaccf92d2c7543a9062263 (patch) | |
tree | 190d36f7806ae8a550bb95d46e65dc01be58bfe4 /src | |
parent | 61dc295fa0c83aa0a2ce28067e64fe7bdd46bec9 (diff) |
Implement opening databases with key files.
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/KeyOpenDialog.cpp | 48 | ||||
-rw-r--r-- | src/gui/KeyOpenDialog.h | 3 | ||||
-rw-r--r-- | src/gui/KeyOpenDialog.ui | 38 |
3 files changed, 54 insertions, 35 deletions
diff --git a/src/gui/KeyOpenDialog.cpp b/src/gui/KeyOpenDialog.cpp index 225534ed0..aa2d30e46 100644 --- a/src/gui/KeyOpenDialog.cpp +++ b/src/gui/KeyOpenDialog.cpp @@ -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); + } +} diff --git a/src/gui/KeyOpenDialog.h b/src/gui/KeyOpenDialog.h index a92ded7a6..26ab91cfd 100644 --- a/src/gui/KeyOpenDialog.h +++ b/src/gui/KeyOpenDialog.h @@ -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; diff --git a/src/gui/KeyOpenDialog.ui b/src/gui/KeyOpenDialog.ui index 4fcee5207..6f4aee6e7 100644 --- a/src/gui/KeyOpenDialog.ui +++ b/src/gui/KeyOpenDialog.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> |