From 5217199d0a9f5f0c175723a2133eed74539fbf72 Mon Sep 17 00:00:00 2001 From: Thom Troy Date: Sun, 10 Jun 2012 17:26:35 +0100 Subject: [PATCH] Implement create key file in ChangeMasterKeyWidget --- src/gui/ChangeMasterKeyWidget.cpp | 25 +++++++++++++++++++++++++ src/gui/ChangeMasterKeyWidget.h | 1 + 2 files changed, 26 insertions(+) diff --git a/src/gui/ChangeMasterKeyWidget.cpp b/src/gui/ChangeMasterKeyWidget.cpp index d22e07746..d75776c7d 100644 --- a/src/gui/ChangeMasterKeyWidget.cpp +++ b/src/gui/ChangeMasterKeyWidget.cpp @@ -22,6 +22,7 @@ #include "keys/FileKey.h" #include "keys/PasswordKey.h" +#include "gui/FileDialog.h" ChangeMasterKeyWidget::ChangeMasterKeyWidget(QWidget* parent) : DialogyWidget(parent) @@ -32,6 +33,7 @@ ChangeMasterKeyWidget::ChangeMasterKeyWidget(QWidget* parent) connect(m_ui->buttonBox, SIGNAL(accepted()), SLOT(generateKey())); connect(m_ui->buttonBox, SIGNAL(rejected()), SLOT(reject())); connect(m_ui->togglePasswordButton, SIGNAL(toggled(bool)), SLOT(togglePassword(bool))); + connect(m_ui->createKeyFileButton, SIGNAL(clicked()), SLOT(createKeyFile())); } ChangeMasterKeyWidget::~ChangeMasterKeyWidget() @@ -44,6 +46,29 @@ void ChangeMasterKeyWidget::togglePassword(bool checked) m_ui->repeatPasswordEdit->setEchoMode(checked ? QLineEdit::Password : QLineEdit::Normal); } +void ChangeMasterKeyWidget::createKeyFile() +{ + QString fileName = fileDialog()->getSaveFileName(this, tr("CreateKeyFile..."), QString(), + tr("Key Files") + " (*.key);;" + tr("All files (*)")); + + if (!fileName.isEmpty()) { + QString errorMsg; + bool created = FileKey::create(fileName, &errorMsg); + if(!created) + { + QMessageBox::warning(this, tr("Error"), tr("Unable to create Key File : ") + errorMsg); + } + else + { + if(m_ui->keyFileGroup->isEnabled()) + { + m_ui->keyFileCombo->setEditText(fileName); + } + return; + } + } +} + void ChangeMasterKeyWidget::clearForms() { m_key.clear(); diff --git a/src/gui/ChangeMasterKeyWidget.h b/src/gui/ChangeMasterKeyWidget.h index 9382e4171..ef9ab18d4 100644 --- a/src/gui/ChangeMasterKeyWidget.h +++ b/src/gui/ChangeMasterKeyWidget.h @@ -46,6 +46,7 @@ private Q_SLOTS: void generateKey(); void reject(); void togglePassword(bool checked); + void createKeyFile(); private: const QScopedPointer m_ui;