diff options
author | saturneric <[email protected]> | 2025-02-02 18:43:46 +0000 |
---|---|---|
committer | saturneric <[email protected]> | 2025-02-02 18:43:46 +0000 |
commit | bec8f5e614884cb86e7f1c597b7a0767c99349d9 (patch) | |
tree | bfe24598ec22d7bef7e439d1f64dcd81e772fd98 | |
parent | feat: improve KeyGenerateDialog (diff) | |
download | GpgFrontend-bec8f5e614884cb86e7f1c597b7a0767c99349d9.tar.gz GpgFrontend-bec8f5e614884cb86e7f1c597b7a0767c99349d9.zip |
refactor: rewrite subkey generate dialog and fix some issues discovered
-rw-r--r-- | src/core/model/GpgKeyGenerateInfo.cpp | 4 | ||||
-rw-r--r-- | src/core/model/GpgKeyGenerateInfo.h | 2 | ||||
-rw-r--r-- | src/ui/dialog/key_generate/KeyGenerateDialog.cpp | 205 | ||||
-rw-r--r-- | src/ui/dialog/key_generate/KeyGenerateDialog.h | 10 | ||||
-rw-r--r-- | src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp | 344 | ||||
-rw-r--r-- | src/ui/dialog/key_generate/SubkeyGenerateDialog.h | 89 | ||||
-rw-r--r-- | src/ui/function/KeyGenerateHelper.cpp | 84 | ||||
-rw-r--r-- | src/ui/function/KeyGenerateHelper.h | 47 | ||||
-rw-r--r-- | ui/KeyGenDialog.ui | 76 | ||||
-rw-r--r-- | ui/SubkeyGenDialog.ui | 134 |
10 files changed, 542 insertions, 453 deletions
diff --git a/src/core/model/GpgKeyGenerateInfo.cpp b/src/core/model/GpgKeyGenerateInfo.cpp index fda6d09a..1493c3af 100644 --- a/src/core/model/GpgKeyGenerateInfo.cpp +++ b/src/core/model/GpgKeyGenerateInfo.cpp @@ -135,7 +135,9 @@ auto KeyGenerateInfo::GetSupportedSubkeyAlgo() -> QContainer<KeyAlgo> { } KeyGenerateInfo::KeyGenerateInfo(bool is_subkey) - : subkey_(is_subkey), algo_(kNoneAlgo) {} + : subkey_(is_subkey), + algo_(kNoneAlgo), + expired_(QDateTime::currentDateTime().toLocalTime().addYears(2)) {} auto KeyGenerateInfo::SearchPrimaryKeyAlgo(const QString &algo_id) -> std::tuple<bool, KeyAlgo> { diff --git a/src/core/model/GpgKeyGenerateInfo.h b/src/core/model/GpgKeyGenerateInfo.h index 0f3f2d70..54ec5a29 100644 --- a/src/core/model/GpgKeyGenerateInfo.h +++ b/src/core/model/GpgKeyGenerateInfo.h @@ -358,7 +358,7 @@ class GPGFRONTEND_CORE_EXPORT KeyGenerateInfo { QString comment_; ///< KeyAlgo algo_; ///< - QDateTime expired_ = QDateTime::currentDateTime().addYears(2); + QDateTime expired_; bool non_expired_ = false; ///< bool no_passphrase_ = false; ///< diff --git a/src/ui/dialog/key_generate/KeyGenerateDialog.cpp b/src/ui/dialog/key_generate/KeyGenerateDialog.cpp index 27c587a1..0251df8b 100644 --- a/src/ui/dialog/key_generate/KeyGenerateDialog.cpp +++ b/src/ui/dialog/key_generate/KeyGenerateDialog.cpp @@ -37,64 +37,13 @@ #include "ui/UISignalStation.h" #include "ui/UserInterfaceUtils.h" #include "ui/function/GpgOperaHelper.h" +#include "ui/function/KeyGenerateHelper.h" // #include "ui_KeyGenDialog.h" namespace GpgFrontend::UI { -auto SearchAlgoByName(const QString& name, - const QContainer<KeyAlgo>& algos) -> QContainer<KeyAlgo> { - QContainer<KeyAlgo> res; - - for (const auto& algo : algos) { - if (algo.Name() != name) continue; - res.append(algo); - } - - return res; -} - -auto GetAlgoByNameAndKeyLength(const QString& name, int key_length, - const QContainer<KeyAlgo>& algos) - -> std::tuple<bool, KeyAlgo> { - for (const auto& algo : algos) { - if (algo.Name() != name) continue; - if (algo.KeyLength() != key_length) continue; - return {true, algo}; - } - - return {}; -} - -auto GetAlgoByName(const QString& name, const QContainer<KeyAlgo>& algos) - -> std::tuple<bool, KeyAlgo> { - for (const auto& algo : algos) { - if (algo.Name() != name) continue; - return {true, algo}; - } - - return {}; -} - -void SetKeyLengthComboxBoxByAlgo(QComboBox* combo, - const QContainer<KeyAlgo>& algos) { - combo->clear(); - - QContainer<KeyAlgo> sorted_algos(algos.begin(), algos.end()); - std::sort(sorted_algos.begin(), sorted_algos.end(), - [](const KeyAlgo& a, const KeyAlgo& b) { - return a.KeyLength() < b.KeyLength(); - }); - - QStringList key_lengths; - for (const auto& algo : sorted_algos) { - key_lengths.append(QString::number(algo.KeyLength())); - } - - combo->addItems(key_lengths); -} - KeyGenerateDialog::KeyGenerateDialog(int channel, QWidget* parent) : GeneralDialog(typeid(KeyGenerateDialog).name(), parent), ui_(QSharedPointer<Ui_KeyGenDialog>::create()), @@ -141,7 +90,7 @@ KeyGenerateDialog::KeyGenerateDialog(int channel, QWidget* parent) ui_->easyValidPeriodLabel->setText(tr("Validity Period")); ui_->pAlgoLabel->setText(tr("Algorithm")); - ui_->pValidPeriodLabel->setText(tr("Validity Period")); + ui_->pExpireDateLabel->setText(tr("Validity Period")); ui_->pKeyLengthLabel->setText(tr("Key Length")); ui_->pUsageLabel->setText(tr("Usage")); ui_->pEncrCheckBox->setText(tr("Encrypt")); @@ -151,7 +100,7 @@ KeyGenerateDialog::KeyGenerateDialog(int channel, QWidget* parent) ui_->pExpireCheckBox->setText(tr("Non Expired")); ui_->sAlgoLabel->setText(tr("Algorithm")); - ui_->sValidPeriodLabel->setText(tr("Validity Period")); + ui_->sExpireDateLabel->setText(tr("Expire Date")); ui_->sKeyLengthLabel->setText(tr("Key Length")); ui_->sUsageLabel->setText(tr("Usage")); ui_->sEncrCheckBox->setText(tr("Encrypt")); @@ -159,9 +108,12 @@ KeyGenerateDialog::KeyGenerateDialog(int channel, QWidget* parent) ui_->sAuthCheckBox->setText(tr("Authentication")); ui_->sExpireCheckBox->setText(tr("Non Expired")); + assert(ui_->tabWidget->count() == 3); ui_->tabWidget->setTabText(0, tr("Easy Mode")); - ui_->tabWidget->setTabText(0, tr("Primary Key")); - ui_->tabWidget->setTabText(0, tr("Subkey")); + ui_->tabWidget->setTabText(1, tr("Primary Key")); + ui_->tabWidget->setTabText(2, tr("Subkey")); + ui_->tabWidget->setCurrentIndex(0); + ui_->generateButton->setText(tr("Generate")); QSet<QString> p_algo_set; @@ -211,12 +163,31 @@ void KeyGenerateDialog::slot_key_gen_accept() { << Qt::endl; } - if (gen_subkey_info_ != nullptr && - gen_subkey_info_->GetAlgo() == KeyGenerateInfo::kNoneAlgo) { - err_stream << " -> " << tr("Please give a valid subkey algorithm.") + const auto min_expire_date = QDateTime::currentDateTime().addSecs(120); + + if (!gen_key_info_->IsNonExpired() && + gen_key_info_->GetExpireTime() < min_expire_date) { + err_stream << " -> " + << tr("Time to primary key expiration must not be less than 120 " + "seconds.") << Qt::endl; } + if (gen_subkey_info_ != nullptr) { + if (gen_subkey_info_->GetAlgo() == KeyGenerateInfo::kNoneAlgo) { + err_stream << " -> " << tr("Please give a valid subkey algorithm.") + << Qt::endl; + } + + if (!gen_subkey_info_->IsNonExpired() && + gen_subkey_info_->GetExpireTime() < min_expire_date) { + err_stream + << " -> " + << tr("Time to subkey expiration must not be less than 120 seconds.") + << Qt::endl; + } + } + const auto err_string = err_stream.readAll(); if (!err_string.isEmpty()) { ui_->statusPlainTextEdit->clear(); @@ -228,24 +199,6 @@ void KeyGenerateDialog::slot_key_gen_accept() { gen_key_info_->SetEmail(ui_->emailEdit->text()); gen_key_info_->SetComment(ui_->commentEdit->text()); - if (ui_->noPassphraseCheckBox->checkState() != 0U) { - gen_key_info_->SetNonPassPhrase(true); - if (gen_subkey_info_ != nullptr) { - gen_subkey_info_->SetNonPassPhrase(true); - } - } - - if (ui_->pExpireCheckBox->checkState() != 0U) { - gen_key_info_->SetNonExpired(true); - if (gen_subkey_info_ != nullptr) gen_subkey_info_->SetNonExpired(true); - } else { - gen_key_info_->SetExpireTime(ui_->pValidityPeriodDateTimeEdit->dateTime()); - if (gen_subkey_info_ != nullptr) { - gen_subkey_info_->SetExpireTime( - ui_->sValidityPeriodDateTimeEdit->dateTime()); - } - } - LOG_D() << "try to generate key at gpg context channel: " << channel_; do_generate(); @@ -286,10 +239,10 @@ void KeyGenerateDialog::refresh_widgets_state() { ui_->noPassphraseCheckBox->setEnabled(gen_key_info_->IsAllowNoPassPhrase()); - ui_->pValidityPeriodDateTimeEdit->blockSignals(true); - ui_->pValidityPeriodDateTimeEdit->setDateTime(gen_key_info_->GetExpireTime()); - ui_->pValidityPeriodDateTimeEdit->setDisabled(gen_key_info_->IsNonExpired()); - ui_->pValidityPeriodDateTimeEdit->blockSignals(false); + ui_->pExpireDateTimeEdit->blockSignals(true); + ui_->pExpireDateTimeEdit->setDateTime(gen_key_info_->GetExpireTime()); + ui_->pExpireDateTimeEdit->setDisabled(gen_key_info_->IsNonExpired()); + ui_->pExpireDateTimeEdit->blockSignals(false); ui_->pExpireCheckBox->blockSignals(true); ui_->pExpireCheckBox->setChecked(gen_key_info_->IsNonExpired()); @@ -318,10 +271,10 @@ void KeyGenerateDialog::refresh_widgets_state() { ui_->sAuthCheckBox->setCheckState(Qt::Unchecked); ui_->sAuthCheckBox->blockSignals(false); - ui_->sValidityPeriodDateTimeEdit->blockSignals(true); - ui_->sValidityPeriodDateTimeEdit->setDateTime(QDateTime::currentDateTime()); - ui_->sValidityPeriodDateTimeEdit->setDisabled(true); - ui_->sValidityPeriodDateTimeEdit->blockSignals(false); + ui_->sExpireDateTimeEdit->blockSignals(true); + ui_->sExpireDateTimeEdit->setDateTime(QDateTime::currentDateTime()); + ui_->sExpireDateTimeEdit->setDisabled(true); + ui_->sExpireDateTimeEdit->blockSignals(false); ui_->sExpireCheckBox->blockSignals(true); ui_->sExpireCheckBox->setCheckState(Qt::Unchecked); @@ -367,12 +320,10 @@ void KeyGenerateDialog::refresh_widgets_state() { gen_subkey_info_->IsAllowChangeAuthentication()); ui_->sAuthCheckBox->blockSignals(false); - ui_->sValidityPeriodDateTimeEdit->blockSignals(true); - ui_->sValidityPeriodDateTimeEdit->setDateTime( - gen_subkey_info_->GetExpireTime()); - ui_->sValidityPeriodDateTimeEdit->setDisabled( - gen_subkey_info_->IsNonExpired()); - ui_->sValidityPeriodDateTimeEdit->blockSignals(false); + ui_->sExpireDateTimeEdit->blockSignals(true); + ui_->sExpireDateTimeEdit->setDateTime(gen_subkey_info_->GetExpireTime()); + ui_->sExpireDateTimeEdit->setDisabled(gen_subkey_info_->IsNonExpired()); + ui_->sExpireDateTimeEdit->blockSignals(false); ui_->sExpireCheckBox->blockSignals(true); ui_->sExpireCheckBox->setChecked(gen_subkey_info_->IsNonExpired()); @@ -387,17 +338,20 @@ void KeyGenerateDialog::set_signal_slot_config() { connect(ui_->generateButton, &QPushButton::clicked, this, &KeyGenerateDialog::slot_key_gen_accept); - connect(ui_->pExpireCheckBox, &QCheckBox::stateChanged, this, - [this](int state) { - ui_->pValidityPeriodDateTimeEdit->setDisabled(state == Qt::Checked); - - slot_set_easy_valid_date_2_custom(); - }); + connect( + ui_->pExpireCheckBox, &QCheckBox::stateChanged, this, [this](int state) { + gen_key_info_->SetNonExpired(state == Qt::Checked); + gen_key_info_->SetExpireTime(QDateTime::currentDateTime().addYears(2)); + slot_set_easy_valid_date_2_custom(); + refresh_widgets_state(); + }); connect(ui_->sExpireCheckBox, &QCheckBox::stateChanged, this, [this](int state) { - ui_->sValidityPeriodDateTimeEdit->setDisabled(state == Qt::Checked); - + gen_subkey_info_->SetNonExpired(state == Qt::Checked); + gen_subkey_info_->SetExpireTime( + QDateTime::currentDateTime().addYears(2)); slot_set_easy_valid_date_2_custom(); + refresh_widgets_state(); }); connect(ui_->pEncrCheckBox, &QCheckBox::stateChanged, this, @@ -436,14 +390,14 @@ void KeyGenerateDialog::set_signal_slot_config() { connect(ui_->pAlgoComboBox, &QComboBox::currentTextChanged, this, [=](const QString&) { - sync_gen_key_info(); + sync_gen_key_algo_info(); slot_set_easy_key_algo_2_custom(); refresh_widgets_state(); }); connect(ui_->sAlgoComboBox, &QComboBox::currentTextChanged, this, [=](const QString&) { - sync_gen_subkey_info(); + sync_gen_subkey_algo_info(); slot_set_easy_key_algo_2_custom(); refresh_widgets_state(); }); @@ -454,15 +408,15 @@ void KeyGenerateDialog::set_signal_slot_config() { connect(ui_->easyValidityPeriodComboBox, &QComboBox::currentTextChanged, this, &KeyGenerateDialog::slot_easy_valid_date_changed); - connect(ui_->pValidityPeriodDateTimeEdit, &QDateTimeEdit::dateTimeChanged, - this, [=](const QDateTime& dt) { + connect(ui_->pExpireDateTimeEdit, &QDateTimeEdit::dateTimeChanged, this, + [=](const QDateTime& dt) { gen_key_info_->SetExpireTime(dt); slot_set_easy_valid_date_2_custom(); }); - connect(ui_->sValidityPeriodDateTimeEdit, &QDateTimeEdit::dateTimeChanged, - this, [=](const QDateTime& dt) { + connect(ui_->sExpireDateTimeEdit, &QDateTimeEdit::dateTimeChanged, this, + [=](const QDateTime& dt) { gen_subkey_info_->SetExpireTime(dt); slot_set_easy_valid_date_2_custom(); @@ -474,6 +428,24 @@ void KeyGenerateDialog::set_signal_slot_config() { connect(ui_->easyCombinationComboBox, &QComboBox::currentTextChanged, this, &KeyGenerateDialog::slot_easy_combination_changed); + connect(ui_->pKeyLengthComboBox, &QComboBox::currentTextChanged, this, + [this](const QString& text) -> void { + auto [found, algo] = GetAlgoByNameAndKeyLength( + ui_->pAlgoComboBox->currentText(), text.toInt(), + supported_primary_key_algos_); + + if (found) gen_key_info_->SetAlgo(algo); + }); + + connect(ui_->sKeyLengthComboBox, &QComboBox::currentTextChanged, this, + [this](const QString& text) -> void { + auto [found, algo] = GetAlgoByNameAndKeyLength( + ui_->sAlgoComboBox->currentText(), text.toInt(), + supported_subkey_algos_); + + if (found) gen_subkey_info_->SetAlgo(algo); + }); + connect(this, &KeyGenerateDialog::SignalKeyGenerated, UISignalStation::GetInstance(), &UISignalStation::SignalKeyDatabaseRefresh); @@ -483,7 +455,7 @@ auto KeyGenerateDialog::check_email_address(const QString& str) -> bool { return re_email_.match(str).hasMatch(); } -void KeyGenerateDialog::sync_gen_key_info() { +void KeyGenerateDialog::sync_gen_key_algo_info() { auto [found, algo] = GetAlgoByName(ui_->pAlgoComboBox->currentText(), supported_primary_key_algos_); @@ -495,7 +467,7 @@ void KeyGenerateDialog::sync_gen_key_info() { } } -void KeyGenerateDialog::sync_gen_subkey_info() { +void KeyGenerateDialog::sync_gen_subkey_algo_info() { if (gen_subkey_info_ != nullptr) { auto [s_found, algo] = GetAlgoByName(ui_->sAlgoComboBox->currentText(), supported_subkey_algos_); @@ -518,7 +490,7 @@ void KeyGenerateDialog::slot_easy_mode_changed(const QString& mode) { if (found) gen_key_info_->SetAlgo(algo); if (gen_subkey_info_ == nullptr) { - gen_subkey_info_ = QSharedPointer<KeyGenerateInfo>::create(true); + create_sync_gen_subkey_info(); } auto [s_found, s_algo] = KeyGenerateInfo::SearchSubKeyAlgo("elg2048"); @@ -530,7 +502,7 @@ void KeyGenerateDialog::slot_easy_mode_changed(const QString& mode) { if (found) gen_key_info_->SetAlgo(algo); if (gen_subkey_info_ == nullptr) { - gen_subkey_info_ = QSharedPointer<KeyGenerateInfo>::create(true); + create_sync_gen_subkey_info(); } auto [s_found, s_algo] = KeyGenerateInfo::SearchSubKeyAlgo("cv25519"); @@ -542,7 +514,7 @@ void KeyGenerateDialog::slot_easy_mode_changed(const QString& mode) { if (found) gen_key_info_->SetAlgo(algo); if (gen_subkey_info_ == nullptr) { - gen_subkey_info_ = QSharedPointer<KeyGenerateInfo>::create(true); + create_sync_gen_subkey_info(); } auto [s_found, s_algo] = KeyGenerateInfo::SearchSubKeyAlgo("rsa2048"); @@ -595,8 +567,8 @@ void KeyGenerateDialog::slot_easy_valid_date_changed(const QString& mode) { } if (gen_subkey_info_ != nullptr) { - gen_subkey_info_->SetExpireTime(gen_key_info_->GetExpireTime()); gen_subkey_info_->SetNonExpired(gen_key_info_->IsNonExpired()); + gen_subkey_info_->SetExpireTime(gen_key_info_->GetExpireTime()); } refresh_widgets_state(); @@ -618,7 +590,7 @@ void KeyGenerateDialog::slot_easy_combination_changed(const QString& mode) { if (mode == tr("Primary Key Only")) { gen_subkey_info_ = nullptr; } else { - gen_subkey_info_ = QSharedPointer<KeyGenerateInfo>::create(true); + create_sync_gen_subkey_info(); } slot_set_easy_key_algo_2_custom(); @@ -658,4 +630,13 @@ void KeyGenerateDialog::do_generate() { }; GpgOperaHelper::WaitForOpera(this, tr("Generating"), f); } + +void KeyGenerateDialog::create_sync_gen_subkey_info() { + if (gen_subkey_info_ == nullptr) { + gen_subkey_info_ = QSharedPointer<KeyGenerateInfo>::create(true); + } + + sync_gen_subkey_algo_info(); + slot_easy_valid_date_changed(ui_->easyValidityPeriodComboBox->currentText()); +} } // namespace GpgFrontend::UI diff --git a/src/ui/dialog/key_generate/KeyGenerateDialog.h b/src/ui/dialog/key_generate/KeyGenerateDialog.h index a4d27900..ad927446 100644 --- a/src/ui/dialog/key_generate/KeyGenerateDialog.h +++ b/src/ui/dialog/key_generate/KeyGenerateDialog.h @@ -148,13 +148,19 @@ class KeyGenerateDialog : public GeneralDialog { * @brief * */ - void sync_gen_key_info(); + void sync_gen_key_algo_info(); /** * @brief * */ - void sync_gen_subkey_info(); + void sync_gen_subkey_algo_info(); + + /** + * @brief + * + */ + void create_sync_gen_subkey_info(); /** * @brief diff --git a/src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp b/src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp index a2f7a4ae..0c4d30c4 100644 --- a/src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp +++ b/src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp @@ -31,231 +31,171 @@ #include <cassert> #include <cstddef> -#include "core/function/GlobalSettingStation.h" #include "core/function/gpg/GpgKeyGetter.h" #include "core/function/gpg/GpgKeyOpera.h" #include "core/utils/GpgUtils.h" #include "ui/UISignalStation.h" #include "ui/UserInterfaceUtils.h" #include "ui/function/GpgOperaHelper.h" +#include "ui/function/KeyGenerateHelper.h" + +// +#include "ui_SubkeyGenDialog.h" namespace GpgFrontend::UI { SubkeyGenerateDialog::SubkeyGenerateDialog(int channel, const KeyId& key_id, QWidget* parent) : GeneralDialog(typeid(SubkeyGenerateDialog).name(), parent), + ui_(QSharedPointer<Ui_SubkeyGenDialog>::create()), current_gpg_context_channel_(channel), key_(GpgKeyGetter::GetInstance(current_gpg_context_channel_) - .GetKey(key_id)) { + .GetKey(key_id)), + gen_subkey_info_(QSharedPointer<KeyGenerateInfo>::create(true)), + supported_subkey_algos_(KeyGenerateInfo::GetSupportedSubkeyAlgo()) { + ui_->setupUi(this); assert(key_.IsGood()); - bool longer_expiration_date = - GetSettings().value("basic/longer_expiration_date", false).toBool(); - - max_date_time_ = longer_expiration_date - ? QDateTime::currentDateTime().toLocalTime().addYears(30) - : QDateTime::currentDateTime().toLocalTime().addYears(2); - - button_box_ = - new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); - - key_usage_group_box_ = create_key_usage_group_box(); - - auto* group_grid = new QGridLayout(this); - group_grid->addWidget(create_basic_info_group_box(), 0, 0); - group_grid->addWidget(key_usage_group_box_, 1, 0); + ui_->algoLabel->setText(tr("Algorithm")); + ui_->keyLengthLabel->setText(tr("Key Length")); + ui_->expireLabel->setText(tr("Expire Date")); + ui_->usageLabel->setText(tr("Usage")); + ui_->encrCheckBox->setText(tr("Encrypt")); + ui_->signCheckBox->setText(tr("Sign")); + ui_->authCheckBox->setText(tr("Authentication")); + ui_->expireLabel->setText(tr("Non Expired")); + ui_->nonPassphraseCheckBox->setText(tr("No Passphrase")); - auto* tipps_label = - new QLabel(tr("Tipps: if the key pair has a passphrase, the subkey's " - "passphrase must be equal to it.")); - tipps_label->setWordWrap(true); - group_grid->addWidget(tipps_label); + QSet<QString> algo_set; + for (const auto& algo : supported_subkey_algos_) { + algo_set.insert(algo.Name()); + } + ui_->algoComboBox->addItems(QStringList(algo_set.cbegin(), algo_set.cend())); - auto* name_list = new QWidget(this); - name_list->setLayout(group_grid); + ui_->expireDateTimeEdit->setDateTime(gen_subkey_info_->GetExpireTime()); + ui_->expireDateTimeEdit->setDisabled(gen_subkey_info_->IsNonExpired()); - auto* vbox2 = new QVBoxLayout(); - vbox2->addWidget(name_list); - vbox2->addWidget(error_label_); - vbox2->addWidget(button_box_); + ui_->statusPlainTextEdit->appendPlainText( + tr("Tipps: if the key pair has a passphrase, the subkey's " + "passphrase must be equal to it.")); this->setWindowTitle(tr("Generate New Subkey")); - this->setLayout(vbox2); this->setAttribute(Qt::WA_DeleteOnClose); this->setModal(true); - set_signal_slot(); + set_signal_slot_config(); refresh_widgets_state(); } -QGroupBox* SubkeyGenerateDialog::create_key_usage_group_box() { - auto* group_box = new QGroupBox(this); - auto* grid = new QGridLayout(this); - - group_box->setTitle(tr("Key Usage")); - - auto* encrypt = new QCheckBox(tr("Encryption"), group_box); - encrypt->setTristate(false); - - auto* sign = new QCheckBox(tr("Signing"), group_box); - sign->setTristate(false); - - auto* cert = new QCheckBox(tr("Certification"), group_box); - cert->setTristate(false); - - auto* auth = new QCheckBox(tr("Authentication"), group_box); - auth->setTristate(false); - - key_usage_check_boxes_.push_back(encrypt); - key_usage_check_boxes_.push_back(sign); - key_usage_check_boxes_.push_back(cert); - key_usage_check_boxes_.push_back(auth); - - grid->addWidget(encrypt, 0, 0); - grid->addWidget(sign, 0, 1); - grid->addWidget(cert, 1, 0); - grid->addWidget(auth, 1, 1); - - group_box->setLayout(grid); - - return group_box; -} - -QGroupBox* SubkeyGenerateDialog::create_basic_info_group_box() { - error_label_ = new QLabel(); - key_size_spin_box_ = new QSpinBox(this); - key_type_combo_box_ = new QComboBox(this); - no_pass_phrase_check_box_ = new QCheckBox(this); - - for (const auto& algo : KeyGenerateInfo::GetSupportedSubkeyAlgo()) { - key_type_combo_box_->addItem(algo.Name()); - } - if (!KeyGenerateInfo::GetSupportedSubkeyAlgo().empty()) { - key_type_combo_box_->setCurrentIndex(0); - } - - date_edit_ = - new QDateTimeEdit(QDateTime::currentDateTime().addYears(2), this); - date_edit_->setMinimumDateTime(QDateTime::currentDateTime()); - date_edit_->setMaximumDateTime(max_date_time_); - date_edit_->setDisplayFormat("dd/MM/yyyy hh:mm:ss"); - date_edit_->setCalendarPopup(true); - date_edit_->setEnabled(true); - - expire_check_box_ = new QCheckBox(this); - expire_check_box_->setCheckState(Qt::Unchecked); - - auto* vbox1 = new QGridLayout; - - vbox1->addWidget(new QLabel(tr("Key Type") + ": "), 0, 0); - vbox1->addWidget(new QLabel(tr("KeySize (in Bit)") + ": "), 1, 0); - vbox1->addWidget(new QLabel(tr("Expiration Date") + ": "), 2, 0); - vbox1->addWidget(new QLabel(tr("Never Expire")), 2, 3); - vbox1->addWidget(new QLabel(tr("Non Pass Phrase")), 3, 0); - - vbox1->addWidget(key_type_combo_box_, 0, 1); - vbox1->addWidget(key_size_spin_box_, 1, 1); - vbox1->addWidget(date_edit_, 2, 1); - vbox1->addWidget(expire_check_box_, 2, 2); - vbox1->addWidget(no_pass_phrase_check_box_, 3, 1); - - auto* basic_info_group_box = new QGroupBox(); - basic_info_group_box->setLayout(vbox1); - basic_info_group_box->setTitle(tr("Basic Information")); - - return basic_info_group_box; -} - -void SubkeyGenerateDialog::set_signal_slot() { - connect(button_box_, &QDialogButtonBox::accepted, this, +void SubkeyGenerateDialog::set_signal_slot_config() { + connect(ui_->generateButton, &QPushButton::clicked, this, &SubkeyGenerateDialog::slot_key_gen_accept); - connect(button_box_, &QDialogButtonBox::rejected, this, - &SubkeyGenerateDialog::reject); - connect(expire_check_box_, &QCheckBox::stateChanged, this, - &SubkeyGenerateDialog::slot_expire_box_changed); - - connect(key_usage_check_boxes_[0], &QCheckBox::stateChanged, this, - &SubkeyGenerateDialog::slot_encryption_box_changed); - connect(key_usage_check_boxes_[1], &QCheckBox::stateChanged, this, - &SubkeyGenerateDialog::slot_signing_box_changed); - connect(key_usage_check_boxes_[2], &QCheckBox::stateChanged, this, - &SubkeyGenerateDialog::slot_certification_box_changed); - connect(key_usage_check_boxes_[3], &QCheckBox::stateChanged, this, - &SubkeyGenerateDialog::slot_authentication_box_changed); + connect(ui_->nonExpiredCheckBox, &QCheckBox::stateChanged, this, + [=](int state) { + gen_subkey_info_->SetNonExpired(state == Qt::Checked); + refresh_widgets_state(); + }); - connect(key_type_combo_box_, qOverload<int>(&QComboBox::currentIndexChanged), - this, &SubkeyGenerateDialog::slot_activated_key_type); + connect(ui_->encrCheckBox, &QCheckBox::stateChanged, this, [this](int state) { + gen_subkey_info_->SetAllowEncryption(state == Qt::Checked); + }); + connect(ui_->signCheckBox, &QCheckBox::stateChanged, this, [this](int state) { + gen_subkey_info_->SetAllowSigning(state == Qt::Checked); + }); + connect(ui_->authCheckBox, &QCheckBox::stateChanged, this, [this](int state) { + gen_subkey_info_->SetAllowAuthentication(state == Qt::Checked); + }); + + connect(ui_->algoComboBox, &QComboBox::currentTextChanged, this, + [=](const QString& text) { + auto [found, algo] = GetAlgoByName(text, supported_subkey_algos_); + ui_->generateButton->setDisabled(!found); + if (found) gen_subkey_info_->SetAlgo(algo); + + refresh_widgets_state(); + }); - connect(no_pass_phrase_check_box_, &QCheckBox::stateChanged, this, + connect(ui_->nonPassphraseCheckBox, &QCheckBox::stateChanged, this, [this](int state) -> void { - gen_subkey_info_->SetNonPassPhrase(state != 0); + gen_subkey_info_->SetNonPassPhrase(state == Qt::Checked); }); -} -void SubkeyGenerateDialog::slot_expire_box_changed() { - if (expire_check_box_->checkState() != 0U) { - date_edit_->setEnabled(false); - } else { - date_edit_->setEnabled(true); - } + connect(ui_->keyLengthComboBox, &QComboBox::currentTextChanged, this, + [this](const QString& text) -> void { + auto [found, algo] = GetAlgoByNameAndKeyLength( + ui_->algoComboBox->currentText(), text.toInt(), + supported_subkey_algos_); + + if (found) gen_subkey_info_->SetAlgo(algo); + }); } void SubkeyGenerateDialog::refresh_widgets_state() { - if (gen_subkey_info_->IsAllowEncryption()) { - key_usage_check_boxes_[0]->setCheckState(Qt::CheckState::Checked); - } else { - key_usage_check_boxes_[0]->setCheckState(Qt::CheckState::Unchecked); - } - - if (gen_subkey_info_->IsAllowChangeEncryption()) { - key_usage_check_boxes_[0]->setDisabled(false); - } else { - key_usage_check_boxes_[0]->setDisabled(true); - } - - if (gen_subkey_info_->IsAllowSigning()) { - key_usage_check_boxes_[1]->setCheckState(Qt::CheckState::Checked); - } else { - key_usage_check_boxes_[1]->setCheckState(Qt::CheckState::Unchecked); - } - - if (gen_subkey_info_->IsAllowChangeSigning()) { - key_usage_check_boxes_[1]->setDisabled(false); - } else { - key_usage_check_boxes_[1]->setDisabled(true); - } - - if (gen_subkey_info_->IsAllowCertification()) { - key_usage_check_boxes_[2]->setCheckState(Qt::CheckState::Checked); - } else { - key_usage_check_boxes_[2]->setCheckState(Qt::CheckState::Unchecked); - } + ui_->algoComboBox->blockSignals(true); + ui_->algoComboBox->setCurrentText(gen_subkey_info_->GetAlgo().Name()); + ui_->algoComboBox->blockSignals(false); + + ui_->keyLengthComboBox->blockSignals(true); + SetKeyLengthComboxBoxByAlgo(ui_->keyLengthComboBox, + SearchAlgoByName(ui_->algoComboBox->currentText(), + supported_subkey_algos_)); + ui_->keyLengthComboBox->setCurrentText( + QString::number(gen_subkey_info_->GetKeyLength())); + ui_->keyLengthComboBox->blockSignals(false); + + ui_->encrCheckBox->blockSignals(true); + ui_->encrCheckBox->setChecked(gen_subkey_info_->IsAllowEncryption()); + ui_->encrCheckBox->setEnabled(gen_subkey_info_->IsAllowChangeEncryption()); + ui_->encrCheckBox->blockSignals(false); + + ui_->signCheckBox->blockSignals(true); + ui_->signCheckBox->setChecked(gen_subkey_info_->IsAllowSigning()); + ui_->signCheckBox->setEnabled(gen_subkey_info_->IsAllowChangeSigning()); + ui_->signCheckBox->blockSignals(false); + + ui_->authCheckBox->blockSignals(true); + ui_->authCheckBox->setChecked(gen_subkey_info_->IsAllowAuthentication()); + ui_->authCheckBox->setEnabled( + gen_subkey_info_->IsAllowChangeAuthentication()); + ui_->authCheckBox->blockSignals(false); + + ui_->nonPassphraseCheckBox->setEnabled( + gen_subkey_info_->IsAllowNoPassPhrase()); + + ui_->expireDateTimeEdit->blockSignals(true); + ui_->expireDateTimeEdit->setDateTime(gen_subkey_info_->GetExpireTime()); + ui_->expireDateTimeEdit->setDisabled(gen_subkey_info_->IsNonExpired()); + ui_->expireDateTimeEdit->blockSignals(false); + + ui_->nonExpiredCheckBox->blockSignals(true); + ui_->nonExpiredCheckBox->setChecked(gen_subkey_info_->IsNonExpired()); + ui_->nonExpiredCheckBox->blockSignals(false); +} - if (gen_subkey_info_->IsAllowChangeCertification()) { - key_usage_check_boxes_[2]->setDisabled(false); - } else { - key_usage_check_boxes_[2]->setDisabled(true); - } +void SubkeyGenerateDialog::slot_key_gen_accept() { + QString buffer; + QTextStream err_stream(&buffer); - if (gen_subkey_info_->IsAllowAuthentication()) { - key_usage_check_boxes_[3]->setCheckState(Qt::CheckState::Checked); - } else { - key_usage_check_boxes_[3]->setCheckState(Qt::CheckState::Unchecked); + if (gen_subkey_info_->GetAlgo() == KeyGenerateInfo::kNoneAlgo) { + err_stream << " -> " << tr("Please give a valid subkey algorithm.") + << Qt::endl; } - if (gen_subkey_info_->IsAllowChangeAuthentication()) { - key_usage_check_boxes_[3]->setDisabled(false); - } else { - key_usage_check_boxes_[3]->setDisabled(true); + if (!gen_subkey_info_->IsNonExpired() && + gen_subkey_info_->GetExpireTime() < + QDateTime::currentDateTime().addSecs(120)) { + err_stream + << " -> " + << tr("Time to subkey expiration must not be less than 120 seconds.") + << Qt::endl; } -} -void SubkeyGenerateDialog::slot_key_gen_accept() { - if (expire_check_box_->checkState() != 0U) { - gen_subkey_info_->SetNonExpired(true); - } else { - gen_subkey_info_->SetExpireTime(date_edit_->dateTime()); + const auto err_string = err_stream.readAll(); + if (!err_string.isEmpty()) { + ui_->statusPlainTextEdit->clear(); + ui_->statusPlainTextEdit->appendPlainText(err_string); + return; } GpgOperaHelper::WaitForOpera( @@ -285,44 +225,4 @@ void SubkeyGenerateDialog::slot_key_gen_accept() { this->done(0); } -void SubkeyGenerateDialog::slot_encryption_box_changed(int state) { - if (state == 0) { - gen_subkey_info_->SetAllowEncryption(false); - } else { - gen_subkey_info_->SetAllowEncryption(true); - } -} - -void SubkeyGenerateDialog::slot_signing_box_changed(int state) { - if (state == 0) { - gen_subkey_info_->SetAllowSigning(false); - } else { - gen_subkey_info_->SetAllowSigning(true); - } -} - -void SubkeyGenerateDialog::slot_certification_box_changed(int state) { - if (state == 0) { - gen_subkey_info_->SetAllowCertification(false); - } else { - gen_subkey_info_->SetAllowCertification(true); - } -} - -void SubkeyGenerateDialog::slot_authentication_box_changed(int state) { - if (state == 0) { - gen_subkey_info_->SetAllowAuthentication(false); - } else { - gen_subkey_info_->SetAllowAuthentication(true); - } -} - -void SubkeyGenerateDialog::slot_activated_key_type(int index) { - // check - assert(gen_subkey_info_->GetSupportedSubkeyAlgo().size() > - static_cast<size_t>(index)); - gen_subkey_info_->SetAlgo(gen_subkey_info_->GetSupportedSubkeyAlgo()[index]); - refresh_widgets_state(); -} - } // namespace GpgFrontend::UI diff --git a/src/ui/dialog/key_generate/SubkeyGenerateDialog.h b/src/ui/dialog/key_generate/SubkeyGenerateDialog.h index ad47bbf2..96dee49e 100644 --- a/src/ui/dialog/key_generate/SubkeyGenerateDialog.h +++ b/src/ui/dialog/key_generate/SubkeyGenerateDialog.h @@ -28,8 +28,6 @@ #pragma once -#include <memory> - #include "core/function/gpg/GpgContext.h" #include "core/model/GpgKey.h" #include "core/model/GpgKeyGenerateInfo.h" @@ -38,6 +36,8 @@ #include "ui/GpgFrontendUI.h" #include "ui/dialog/GeneralDialog.h" +class Ui_SubkeyGenDialog; + namespace GpgFrontend::UI { /** * @brief @@ -56,97 +56,32 @@ class SubkeyGenerateDialog : public GeneralDialog { explicit SubkeyGenerateDialog(int channel, const KeyId& key_id, QWidget* parent); - private: - int current_gpg_context_channel_; ///< - GpgKey key_; ///< - - QSharedPointer<KeyGenerateInfo> gen_subkey_info_ = - QSharedPointer<KeyGenerateInfo>::create(true); ///< - - QGroupBox* key_usage_group_box_{}; - QDialogButtonBox* button_box_; ///< Box for standard buttons - QLabel* error_label_{}; ///< Label containing error message - QSpinBox* key_size_spin_box_{}; ///< Spinbox for the keys size (in bit) - QComboBox* key_type_combo_box_{}; ///< Combobox for Key tpe - QDateTimeEdit* date_edit_{}; ///< Date edit for expiration date - QCheckBox* expire_check_box_{}; ///< Checkbox, if key should expire - QCheckBox* no_pass_phrase_check_box_{}; ///< Checkbox, if key should expire - - QContainer<QCheckBox*> key_usage_check_boxes_; ///< ENCR, SIGN, CERT, AUTH - QDateTime max_date_time_; ///< - - /** - * @brief Create a key usage group box object - * - * @return QGroupBox* - */ - auto create_key_usage_group_box() -> QGroupBox*; - - /** - * @brief Create a basic info group box object - * - * @return QGroupBox* - */ - auto create_basic_info_group_box() -> QGroupBox*; - /** - * @brief Set the signal slot object - * - */ - void set_signal_slot(); - - /** - * @details Refresh widgets state by GenKeyInfo - */ - void refresh_widgets_state(); - private slots: /** - * @details when expire box was checked/unchecked, enable/disable the - * expiration date box - */ - void slot_expire_box_changed(); - - /** * @details check all line edits for false entries. Show error, when there is * one, otherwise generate the key */ void slot_key_gen_accept(); - /** - * @brief - * - * @param state - */ - void slot_encryption_box_changed(int state); - - /** - * @brief - * - * @param state - */ - void slot_signing_box_changed(int state); + private: + QSharedPointer<Ui_SubkeyGenDialog> ui_; ///< + int current_gpg_context_channel_; ///< - /** - * @brief - * - * @param state - */ - void slot_certification_box_changed(int state); + GpgKey key_; ///< + QSharedPointer<KeyGenerateInfo> gen_subkey_info_; ///< + QContainer<KeyAlgo> supported_subkey_algos_; ///< /** - * @brief + * @brief Set the signal slot object * - * @param state */ - void slot_authentication_box_changed(int state); + void set_signal_slot_config(); /** - * @brief - * - * @param index + * @details Refresh widgets state by GenKeyInfo */ - void slot_activated_key_type(int index); + void refresh_widgets_state(); }; } // namespace GpgFrontend::UI diff --git a/src/ui/function/KeyGenerateHelper.cpp b/src/ui/function/KeyGenerateHelper.cpp new file mode 100644 index 00000000..4cd40dea --- /dev/null +++ b/src/ui/function/KeyGenerateHelper.cpp @@ -0,0 +1,84 @@ +/** + * Copyright (C) 2021-2024 Saturneric <[email protected]> + * + * This file is part of GpgFrontend. + * + * GpgFrontend is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GpgFrontend is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GpgFrontend. If not, see <https://www.gnu.org/licenses/>. + * + * The initial version of the source code is inherited from + * the gpg4usb project, which is under GPL-3.0-or-later. + * + * All the source code of GpgFrontend was modified and released by + * Saturneric <[email protected]> starting on May 12, 2021. + * + * SPDX-License-Identifier: GPL-3.0-or-later + * + */ + +#include "KeyGenerateHelper.h" + +namespace GpgFrontend::UI { + +auto SearchAlgoByName(const QString& name, + const QContainer<KeyAlgo>& algos) -> QContainer<KeyAlgo> { + QContainer<KeyAlgo> res; + + for (const auto& algo : algos) { + if (algo.Name() != name) continue; + res.append(algo); + } + + return res; +} + +auto GetAlgoByNameAndKeyLength(const QString& name, int key_length, + const QContainer<KeyAlgo>& algos) + -> std::tuple<bool, KeyAlgo> { + for (const auto& algo : algos) { + if (algo.Name() != name) continue; + if (algo.KeyLength() != key_length) continue; + return {true, algo}; + } + + return {}; +} + +auto GetAlgoByName(const QString& name, const QContainer<KeyAlgo>& algos) + -> std::tuple<bool, KeyAlgo> { + for (const auto& algo : algos) { + if (algo.Name() != name) continue; + return {true, algo}; + } + + return {}; +} + +void SetKeyLengthComboxBoxByAlgo(QComboBox* combo, + const QContainer<KeyAlgo>& algos) { + combo->clear(); + + QContainer<KeyAlgo> sorted_algos(algos.begin(), algos.end()); + std::sort(sorted_algos.begin(), sorted_algos.end(), + [](const KeyAlgo& a, const KeyAlgo& b) { + return a.KeyLength() < b.KeyLength(); + }); + + QStringList key_lengths; + for (const auto& algo : sorted_algos) { + key_lengths.append(QString::number(algo.KeyLength())); + } + + combo->addItems(key_lengths); +} +} // namespace GpgFrontend::UI
\ No newline at end of file diff --git a/src/ui/function/KeyGenerateHelper.h b/src/ui/function/KeyGenerateHelper.h new file mode 100644 index 00000000..0641dbd8 --- /dev/null +++ b/src/ui/function/KeyGenerateHelper.h @@ -0,0 +1,47 @@ +/** + * Copyright (C) 2021-2024 Saturneric <[email protected]> + * + * This file is part of GpgFrontend. + * + * GpgFrontend is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GpgFrontend is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GpgFrontend. If not, see <https://www.gnu.org/licenses/>. + * + * The initial version of the source code is inherited from + * the gpg4usb project, which is under GPL-3.0-or-later. + * + * All the source code of GpgFrontend was modified and released by + * Saturneric <[email protected]> starting on May 12, 2021. + * + * SPDX-License-Identifier: GPL-3.0-or-later + * + */ + +#pragma once + +#include "core/model/GpgKeyGenerateInfo.h" + +namespace GpgFrontend::UI { + +auto SearchAlgoByName(const QString& name, + const QContainer<KeyAlgo>& algos) -> QContainer<KeyAlgo>; + +auto GetAlgoByNameAndKeyLength(const QString& name, int key_length, + const QContainer<KeyAlgo>& algos) + -> std::tuple<bool, KeyAlgo>; + +auto GetAlgoByName(const QString& name, const QContainer<KeyAlgo>& algos) + -> std::tuple<bool, KeyAlgo>; + +void SetKeyLengthComboxBoxByAlgo(QComboBox* combo, + const QContainer<KeyAlgo>& algos); +} // namespace GpgFrontend::UI diff --git a/ui/KeyGenDialog.ui b/ui/KeyGenDialog.ui index 8e850f1b..052f748b 100644 --- a/ui/KeyGenDialog.ui +++ b/ui/KeyGenDialog.ui @@ -147,20 +147,23 @@ <layout class="QVBoxLayout" name="verticalLayout_4"> <item> <layout class="QGridLayout" name="gridLayout_2"> - <item row="3" column="0"> - <widget class="QLabel" name="pKeyLengthLabel"> + <item row="2" column="0"> + <widget class="QLabel" name="pExpireDateLabel"> <property name="text"> - <string>Key Length</string> + <string>Expire Date</string> </property> </widget> </item> - <item row="1" column="0"> - <widget class="QLabel" name="pValidPeriodLabel"> + <item row="7" column="0" colspan="3"> + <widget class="QCheckBox" name="pExpireCheckBox"> <property name="text"> - <string>Validity Period</string> + <string>Non Expired</string> </property> </widget> </item> + <item row="2" column="1" colspan="2"> + <widget class="QDateTimeEdit" name="pExpireDateTimeEdit"/> + </item> <item row="0" column="0"> <widget class="QLabel" name="pAlgoLabel"> <property name="text"> @@ -168,17 +171,14 @@ </property> </widget> </item> - <item row="4" column="0"> + <item row="5" column="0"> <widget class="QLabel" name="pUsageLabel"> <property name="text"> <string>Usage</string> </property> </widget> </item> - <item row="0" column="1" colspan="2"> - <widget class="QComboBox" name="pAlgoComboBox"/> - </item> - <item row="4" column="1" colspan="2"> + <item row="5" column="1" colspan="2"> <layout class="QHBoxLayout" name="horizontalLayout_2"> <item> <widget class="QCheckBox" name="pEncrCheckBox"> @@ -203,26 +203,26 @@ </item> </layout> </item> - <item row="3" column="1" colspan="2"> - <widget class="QComboBox" name="pKeyLengthComboBox"/> - </item> - <item row="1" column="1" colspan="2"> - <widget class="QDateTimeEdit" name="pValidityPeriodDateTimeEdit"/> + <item row="0" column="1" colspan="2"> + <widget class="QComboBox" name="pAlgoComboBox"/> </item> - <item row="5" column="0" colspan="3"> + <item row="6" column="0" colspan="3"> <widget class="QCheckBox" name="noPassphraseCheckBox"> <property name="text"> <string>No Passphrase</string> </property> </widget> </item> - <item row="6" column="0" colspan="3"> - <widget class="QCheckBox" name="pExpireCheckBox"> + <item row="1" column="0"> + <widget class="QLabel" name="pKeyLengthLabel"> <property name="text"> - <string>Non Expired</string> + <string>Key Length</string> </property> </widget> </item> + <item row="1" column="1" colspan="2"> + <widget class="QComboBox" name="pKeyLengthComboBox"/> + </item> </layout> </item> <item> @@ -247,37 +247,34 @@ <layout class="QVBoxLayout" name="verticalLayout_7"> <item> <layout class="QGridLayout" name="gridLayout_4"> - <item row="1" column="0"> - <widget class="QLabel" name="sValidPeriodLabel"> + <item row="2" column="0"> + <widget class="QLabel" name="sExpireDateLabel"> <property name="text"> - <string>Validity Period</string> + <string>Expire Date</string> </property> </widget> </item> - <item row="4" column="0"> - <widget class="QLabel" name="sUsageLabel"> + <item row="6" column="0" colspan="3"> + <widget class="QCheckBox" name="sExpireCheckBox"> <property name="text"> - <string>Usage</string> + <string>Non Expired</string> </property> </widget> </item> - <item row="1" column="1" colspan="2"> - <widget class="QDateTimeEdit" name="sValidityPeriodDateTimeEdit"/> - </item> - <item row="3" column="0"> - <widget class="QLabel" name="sKeyLengthLabel"> + <item row="5" column="0"> + <widget class="QLabel" name="sUsageLabel"> <property name="text"> - <string>Key Length</string> + <string>Usage</string> </property> </widget> </item> - <item row="3" column="1" colspan="2"> - <widget class="QComboBox" name="sKeyLengthComboBox"/> + <item row="2" column="1" colspan="2"> + <widget class="QDateTimeEdit" name="sExpireDateTimeEdit"/> </item> <item row="0" column="1" colspan="2"> <widget class="QComboBox" name="sAlgoComboBox"/> </item> - <item row="4" column="1" colspan="2"> + <item row="5" column="1" colspan="2"> <layout class="QHBoxLayout" name="horizontalLayout_3"> <item> <widget class="QCheckBox" name="sEncrCheckBox"> @@ -309,13 +306,16 @@ </property> </widget> </item> - <item row="5" column="0" colspan="3"> - <widget class="QCheckBox" name="sExpireCheckBox"> + <item row="1" column="0"> + <widget class="QLabel" name="sKeyLengthLabel"> <property name="text"> - <string>Non Expired</string> + <string>Key Length</string> </property> </widget> </item> + <item row="1" column="1" colspan="2"> + <widget class="QComboBox" name="sKeyLengthComboBox"/> + </item> </layout> </item> <item> diff --git a/ui/SubkeyGenDialog.ui b/ui/SubkeyGenDialog.ui new file mode 100644 index 00000000..ad1e6293 --- /dev/null +++ b/ui/SubkeyGenDialog.ui @@ -0,0 +1,134 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>SubkeyGenDialog</class> + <widget class="QDialog" name="SubkeyGenDialog"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>521</width> + <height>391</height> + </rect> + </property> + <property name="windowTitle"> + <string>Subkey Generation</string> + </property> + <layout class="QVBoxLayout" name="verticalLayout"> + <item> + <layout class="QGridLayout" name="gridLayout_3"> + <property name="topMargin"> + <number>5</number> + </property> + <item row="2" column="1"> + <widget class="QDateTimeEdit" name="expireDateTimeEdit"/> + </item> + <item row="2" column="0"> + <widget class="QLabel" name="expireLabel"> + <property name="text"> + <string>Expiration Date</string> + </property> + </widget> + </item> + <item row="0" column="0"> + <widget class="QLabel" name="algoLabel"> + <property name="text"> + <string>Algorithm</string> + </property> + </widget> + </item> + <item row="0" column="1"> + <widget class="QComboBox" name="algoComboBox"/> + </item> + <item row="1" column="0"> + <widget class="QLabel" name="keyLengthLabel"> + <property name="text"> + <string>Key Length</string> + </property> + </widget> + </item> + <item row="1" column="1"> + <widget class="QComboBox" name="keyLengthComboBox"/> + </item> + <item row="3" column="0"> + <widget class="QLabel" name="usageLabel"> + <property name="text"> + <string>Usage</string> + </property> + </widget> + </item> + <item row="3" column="1"> + <layout class="QHBoxLayout" name="horizontalLayout"> + <item> + <widget class="QCheckBox" name="encrCheckBox"> + <property name="text"> + <string>Encrypt</string> + </property> + </widget> + </item> + <item> + <widget class="QCheckBox" name="signCheckBox"> + <property name="text"> + <string>Sign</string> + </property> + </widget> + </item> + <item> + <widget class="QCheckBox" name="authCheckBox"> + <property name="text"> + <string>Authentication</string> + </property> + </widget> + </item> + </layout> + </item> + <item row="4" column="0" colspan="2"> + <widget class="QCheckBox" name="nonExpiredCheckBox"> + <property name="text"> + <string>Non Expired</string> + </property> + </widget> + </item> + <item row="5" column="0" colspan="2"> + <widget class="QCheckBox" name="nonPassphraseCheckBox"> + <property name="text"> + <string>No Passphrase</string> + </property> + </widget> + </item> + </layout> + </item> + <item> + <widget class="Line" name="line"> + <property name="orientation"> + <enum>Qt::Orientation::Horizontal</enum> + </property> + </widget> + </item> + <item> + <spacer name="verticalSpacer"> + <property name="orientation"> + <enum>Qt::Orientation::Vertical</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>20</width> + <height>40</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QPlainTextEdit" name="statusPlainTextEdit"/> + </item> + <item> + <widget class="QPushButton" name="generateButton"> + <property name="text"> + <string>Generate</string> + </property> + </widget> + </item> + </layout> + </widget> + <resources/> + <connections/> +</ui> |