diff options
author | saturneric <[email protected]> | 2025-02-02 17:02:44 +0000 |
---|---|---|
committer | saturneric <[email protected]> | 2025-02-02 17:02:44 +0000 |
commit | 1e95a70ab32fcdb8ef42e7ce8df5ba40b1f251ab (patch) | |
tree | 8c9cdb0cf18d5a81f68d26ff229a5618bfd5920d /src/ui | |
parent | fix: solve lower/upper case name conflict (diff) | |
download | GpgFrontend-1e95a70ab32fcdb8ef42e7ce8df5ba40b1f251ab.tar.gz GpgFrontend-1e95a70ab32fcdb8ef42e7ce8df5ba40b1f251ab.zip |
feat: improve KeyGenerateDialog
Diffstat (limited to 'src/ui')
-rw-r--r-- | src/ui/dialog/Wizard.cpp | 2 | ||||
-rw-r--r-- | src/ui/dialog/key_generate/KeyGenerateDialog.cpp | 210 | ||||
-rw-r--r-- | src/ui/dialog/key_generate/KeyGenerateDialog.h | 23 | ||||
-rw-r--r-- | src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp | 127 | ||||
-rw-r--r-- | src/ui/dialog/key_generate/SubkeyGenerateDialog.h | 6 | ||||
-rw-r--r-- | src/ui/main_window/KeyMgmt.cpp | 2 |
6 files changed, 214 insertions, 156 deletions
diff --git a/src/ui/dialog/Wizard.cpp b/src/ui/dialog/Wizard.cpp index 243fb846..8e77dada 100644 --- a/src/ui/dialog/Wizard.cpp +++ b/src/ui/dialog/Wizard.cpp @@ -195,7 +195,7 @@ KeyGenPage::KeyGenPage(QWidget* parent) : QWizardPage(parent) { int KeyGenPage::nextId() const { return Wizard::kPAGE_CONCLUSION; } void KeyGenPage::slot_generate_key_dialog() { - (new KeyGenDialog(kGpgFrontendDefaultChannel, this))->show(); + (new KeyGenerateDialog(kGpgFrontendDefaultChannel, this))->show(); wizard()->next(); } diff --git a/src/ui/dialog/key_generate/KeyGenerateDialog.cpp b/src/ui/dialog/key_generate/KeyGenerateDialog.cpp index 49425e5b..27c587a1 100644 --- a/src/ui/dialog/key_generate/KeyGenerateDialog.cpp +++ b/src/ui/dialog/key_generate/KeyGenerateDialog.cpp @@ -95,13 +95,13 @@ void SetKeyLengthComboxBoxByAlgo(QComboBox* combo, combo->addItems(key_lengths); } -KeyGenDialog::KeyGenDialog(int channel, QWidget* parent) - : GeneralDialog(typeid(KeyGenDialog).name(), parent), +KeyGenerateDialog::KeyGenerateDialog(int channel, QWidget* parent) + : GeneralDialog(typeid(KeyGenerateDialog).name(), parent), ui_(QSharedPointer<Ui_KeyGenDialog>::create()), - gen_key_info_(QSharedPointer<GenKeyInfo>::create()), + gen_key_info_(QSharedPointer<KeyGenerateInfo>::create()), gen_subkey_info_(nullptr), - supported_primary_key_algos_(GenKeyInfo::GetSupportedKeyAlgo()), - supported_subkey_algos_(GenKeyInfo::GetSupportedSubkeyAlgo()), + supported_primary_key_algos_(KeyGenerateInfo::GetSupportedKeyAlgo()), + supported_subkey_algos_(KeyGenerateInfo::GetSupportedSubkeyAlgo()), channel_(channel) { ui_->setupUi(this); @@ -128,6 +128,42 @@ KeyGenDialog::KeyGenDialog(int channel, QWidget* parent) tr("Non Expired"), }); + ui_->easyCombinationComboBox->addItems({ + tr("Primary Key Only"), + tr("Primary Key With Subkey"), + }); + + ui_->nameLabel->setText(tr("Name")); + ui_->emailLabel->setText(tr("Email")); + ui_->commentLabel->setText(tr("Comment")); + ui_->keyDBLabel->setText(tr("Key Database")); + ui_->easyAlgoLabel->setText(tr("Algorithm")); + ui_->easyValidPeriodLabel->setText(tr("Validity Period")); + + ui_->pAlgoLabel->setText(tr("Algorithm")); + ui_->pValidPeriodLabel->setText(tr("Validity Period")); + ui_->pKeyLengthLabel->setText(tr("Key Length")); + ui_->pUsageLabel->setText(tr("Usage")); + ui_->pEncrCheckBox->setText(tr("Encrypt")); + ui_->pSignCheckBox->setText(tr("Sign")); + ui_->pAuthCheckBox->setText(tr("Authentication")); + ui_->noPassphraseCheckBox->setText(tr("No Passphrase")); + ui_->pExpireCheckBox->setText(tr("Non Expired")); + + ui_->sAlgoLabel->setText(tr("Algorithm")); + ui_->sValidPeriodLabel->setText(tr("Validity Period")); + ui_->sKeyLengthLabel->setText(tr("Key Length")); + ui_->sUsageLabel->setText(tr("Usage")); + ui_->sEncrCheckBox->setText(tr("Encrypt")); + ui_->sSignCheckBox->setText(tr("Sign")); + ui_->sAuthCheckBox->setText(tr("Authentication")); + ui_->sExpireCheckBox->setText(tr("Non Expired")); + + ui_->tabWidget->setTabText(0, tr("Easy Mode")); + ui_->tabWidget->setTabText(0, tr("Primary Key")); + ui_->tabWidget->setTabText(0, tr("Subkey")); + ui_->generateButton->setText(tr("Generate")); + QSet<QString> p_algo_set; for (const auto& algo : supported_primary_key_algos_) { p_algo_set.insert(algo.Name()); @@ -156,21 +192,32 @@ KeyGenDialog::KeyGenDialog(int channel, QWidget* parent) this->setModal(true); } -void KeyGenDialog::slot_key_gen_accept() { +void KeyGenerateDialog::slot_key_gen_accept() { QString buffer; - QTextStream error_stream(&buffer); + QTextStream err_stream(&buffer); if (ui_->nameEdit->text().size() < 5) { - error_stream << " -> " << tr("Name must contain at least five characters.") - << Qt::endl; + err_stream << " -> " << tr("Name must contain at least five characters.") + << Qt::endl; } if (ui_->emailEdit->text().isEmpty() || !check_email_address(ui_->emailEdit->text())) { - error_stream << " -> " << tr("Please give a valid email address.") - << Qt::endl; + err_stream << " -> " << tr("Please give a valid email address.") + << Qt::endl; + } + + if (gen_key_info_->GetAlgo() == KeyGenerateInfo::kNoneAlgo) { + err_stream << " -> " << tr("Please give a valid primary key algorithm.") + << Qt::endl; } - const auto err_string = error_stream.readAll(); + if (gen_subkey_info_ != nullptr && + gen_subkey_info_->GetAlgo() == KeyGenerateInfo::kNoneAlgo) { + err_stream << " -> " << tr("Please give a valid subkey algorithm.") + << Qt::endl; + } + + const auto err_string = err_stream.readAll(); if (!err_string.isEmpty()) { ui_->statusPlainTextEdit->clear(); ui_->statusPlainTextEdit->appendPlainText(err_string); @@ -199,44 +246,13 @@ void KeyGenDialog::slot_key_gen_accept() { } } - if (!GetSettings() - .value("gnupg/use_pinentry_as_password_input_dialog", - QString::fromLocal8Bit(qgetenv("container")) != "flatpak") - .toBool() && - !ui_->noPassphraseCheckBox->isChecked()) { - SetCacheValue("PinentryContext", "NEW_PASSPHRASE"); - } - LOG_D() << "try to generate key at gpg context channel: " << channel_; - GpgOperaHelper::WaitForOpera( - this, tr("Generating"), - [this, gen_key_info = this->gen_key_info_](const OperaWaitingHd& hd) { - GpgKeyOpera::GetInstance(channel_).GenerateKeyWithSubkey( - gen_key_info, gen_subkey_info_, - [this, hd](GpgError err, const DataObjectPtr&) { - // stop showing waiting dialog - hd(); - - if (CheckGpgError(err) == GPG_ERR_USER_1) { - QMessageBox::critical(this, tr("Error"), - tr("Unknown error occurred")); - return; - } - - CommonUtils::RaiseMessageBox( - this->parentWidget() != nullptr ? this->parentWidget() : this, - err); - if (CheckGpgError(err) == GPG_ERR_NO_ERROR) { - emit SignalKeyGenerated(); - } - }); - }); - + do_generate(); this->done(0); } -void KeyGenDialog::refresh_widgets_state() { +void KeyGenerateDialog::refresh_widgets_state() { ui_->pAlgoComboBox->blockSignals(true); ui_->pAlgoComboBox->setCurrentText(gen_key_info_->GetAlgo().Name()); ui_->pAlgoComboBox->blockSignals(false); @@ -280,7 +296,7 @@ void KeyGenDialog::refresh_widgets_state() { ui_->pExpireCheckBox->blockSignals(false); if (gen_subkey_info_ == nullptr) { - ui_->tab_3->setDisabled(true); + ui_->sTab->setDisabled(true); ui_->sAlgoComboBox->blockSignals(true); ui_->sAlgoComboBox->setCurrentText(tr("None")); @@ -310,10 +326,14 @@ void KeyGenDialog::refresh_widgets_state() { ui_->sExpireCheckBox->blockSignals(true); ui_->sExpireCheckBox->setCheckState(Qt::Unchecked); ui_->sExpireCheckBox->blockSignals(false); + + ui_->easyCombinationComboBox->blockSignals(true); + ui_->easyCombinationComboBox->setCurrentText(tr("Primary Key Only")); + ui_->easyCombinationComboBox->blockSignals(false); return; } - ui_->tab_3->setDisabled(false); + ui_->sTab->setDisabled(false); ui_->sAlgoComboBox->blockSignals(true); ui_->sAlgoComboBox->setCurrentText(gen_subkey_info_->GetAlgo().Name()); @@ -357,11 +377,15 @@ void KeyGenDialog::refresh_widgets_state() { ui_->sExpireCheckBox->blockSignals(true); ui_->sExpireCheckBox->setChecked(gen_subkey_info_->IsNonExpired()); ui_->sExpireCheckBox->blockSignals(false); + + ui_->easyCombinationComboBox->blockSignals(true); + ui_->easyCombinationComboBox->setCurrentText(tr("Primary Key With Subkey")); + ui_->easyCombinationComboBox->blockSignals(false); } -void KeyGenDialog::set_signal_slot_config() { +void KeyGenerateDialog::set_signal_slot_config() { connect(ui_->generateButton, &QPushButton::clicked, this, - &KeyGenDialog::slot_key_gen_accept); + &KeyGenerateDialog::slot_key_gen_accept); connect(ui_->pExpireCheckBox, &QCheckBox::stateChanged, this, [this](int state) { @@ -425,10 +449,10 @@ void KeyGenDialog::set_signal_slot_config() { }); connect(ui_->easyAlgoComboBox, &QComboBox::currentTextChanged, this, - &KeyGenDialog::slot_easy_mode_changed); + &KeyGenerateDialog::slot_easy_mode_changed); connect(ui_->easyValidityPeriodComboBox, &QComboBox::currentTextChanged, this, - &KeyGenDialog::slot_easy_valid_date_changed); + &KeyGenerateDialog::slot_easy_valid_date_changed); connect(ui_->pValidityPeriodDateTimeEdit, &QDateTimeEdit::dateTimeChanged, this, [=](const QDateTime& dt) { @@ -447,16 +471,19 @@ void KeyGenDialog::set_signal_slot_config() { connect(ui_->keyDBIndexComboBox, &QComboBox::currentIndexChanged, this, [=](int index) { channel_ = index; }); - connect(this, &KeyGenDialog::SignalKeyGenerated, + connect(ui_->easyCombinationComboBox, &QComboBox::currentTextChanged, this, + &KeyGenerateDialog::slot_easy_combination_changed); + + connect(this, &KeyGenerateDialog::SignalKeyGenerated, UISignalStation::GetInstance(), &UISignalStation::SignalKeyDatabaseRefresh); } -auto KeyGenDialog::check_email_address(const QString& str) -> bool { +auto KeyGenerateDialog::check_email_address(const QString& str) -> bool { return re_email_.match(str).hasMatch(); } -void KeyGenDialog::sync_gen_key_info() { +void KeyGenerateDialog::sync_gen_key_info() { auto [found, algo] = GetAlgoByName(ui_->pAlgoComboBox->currentText(), supported_primary_key_algos_); @@ -468,7 +495,7 @@ void KeyGenDialog::sync_gen_key_info() { } } -void KeyGenDialog::sync_gen_subkey_info() { +void KeyGenerateDialog::sync_gen_subkey_info() { if (gen_subkey_info_ != nullptr) { auto [s_found, algo] = GetAlgoByName(ui_->sAlgoComboBox->currentText(), supported_subkey_algos_); @@ -478,54 +505,54 @@ void KeyGenDialog::sync_gen_subkey_info() { } } -void KeyGenDialog::slot_easy_mode_changed(const QString& mode) { +void KeyGenerateDialog::slot_easy_mode_changed(const QString& mode) { if (mode == "RSA") { - auto [found, algo] = GenKeyInfo::SearchPrimaryKeyAlgo("rsa2048"); + auto [found, algo] = KeyGenerateInfo::SearchPrimaryKeyAlgo("rsa2048"); if (found) gen_key_info_->SetAlgo(algo); gen_subkey_info_ = nullptr; } else if (mode == "DSA") { - auto [found, algo] = GenKeyInfo::SearchPrimaryKeyAlgo("dsa2048"); + auto [found, algo] = KeyGenerateInfo::SearchPrimaryKeyAlgo("dsa2048"); if (found) gen_key_info_->SetAlgo(algo); if (gen_subkey_info_ == nullptr) { - gen_subkey_info_ = QSharedPointer<GenKeyInfo>::create(true); + gen_subkey_info_ = QSharedPointer<KeyGenerateInfo>::create(true); } - auto [s_found, s_algo] = GenKeyInfo::SearchSubKeyAlgo("elg2048"); + auto [s_found, s_algo] = KeyGenerateInfo::SearchSubKeyAlgo("elg2048"); if (s_found) gen_subkey_info_->SetAlgo(s_algo); } else if (mode == "ECC (25519)") { - auto [found, algo] = GenKeyInfo::SearchPrimaryKeyAlgo("ed25519"); + auto [found, algo] = KeyGenerateInfo::SearchPrimaryKeyAlgo("ed25519"); if (found) gen_key_info_->SetAlgo(algo); if (gen_subkey_info_ == nullptr) { - gen_subkey_info_ = QSharedPointer<GenKeyInfo>::create(true); + gen_subkey_info_ = QSharedPointer<KeyGenerateInfo>::create(true); } - auto [s_found, s_algo] = GenKeyInfo::SearchSubKeyAlgo("cv25519"); + auto [s_found, s_algo] = KeyGenerateInfo::SearchSubKeyAlgo("cv25519"); if (s_found) gen_subkey_info_->SetAlgo(s_algo); } else { - auto [found, algo] = GenKeyInfo::SearchPrimaryKeyAlgo("rsa2048"); + auto [found, algo] = KeyGenerateInfo::SearchPrimaryKeyAlgo("rsa2048"); if (found) gen_key_info_->SetAlgo(algo); if (gen_subkey_info_ == nullptr) { - gen_subkey_info_ = QSharedPointer<GenKeyInfo>::create(true); + gen_subkey_info_ = QSharedPointer<KeyGenerateInfo>::create(true); } - auto [s_found, s_algo] = GenKeyInfo::SearchSubKeyAlgo("rsa2048"); + auto [s_found, s_algo] = KeyGenerateInfo::SearchSubKeyAlgo("rsa2048"); if (s_found) gen_subkey_info_->SetAlgo(s_algo); } refresh_widgets_state(); } -void KeyGenDialog::slot_easy_valid_date_changed(const QString& mode) { +void KeyGenerateDialog::slot_easy_valid_date_changed(const QString& mode) { if (mode == tr("3 Months")) { gen_key_info_->SetNonExpired(false); gen_key_info_->SetExpireTime(QDateTime::currentDateTime().addMonths(3)); @@ -575,15 +602,60 @@ void KeyGenDialog::slot_easy_valid_date_changed(const QString& mode) { refresh_widgets_state(); } -void KeyGenDialog::slot_set_easy_valid_date_2_custom() { +void KeyGenerateDialog::slot_set_easy_valid_date_2_custom() { ui_->easyValidityPeriodComboBox->blockSignals(true); ui_->easyValidityPeriodComboBox->setCurrentText(tr("Custom")); ui_->easyValidityPeriodComboBox->blockSignals(false); } -void KeyGenDialog::slot_set_easy_key_algo_2_custom() { +void KeyGenerateDialog::slot_set_easy_key_algo_2_custom() { ui_->easyAlgoComboBox->blockSignals(true); ui_->easyAlgoComboBox->setCurrentText(tr("Custom")); ui_->easyAlgoComboBox->blockSignals(false); } + +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); + } + + slot_set_easy_key_algo_2_custom(); + refresh_widgets_state(); +} + +void KeyGenerateDialog::do_generate() { + if (!GetSettings() + .value("gnupg/use_pinentry_as_password_input_dialog", + QString::fromLocal8Bit(qgetenv("container")) != "flatpak") + .toBool() && + !ui_->noPassphraseCheckBox->isChecked()) { + SetCacheValue("PinentryContext", "NEW_PASSPHRASE"); + } + + auto f = [this, + gen_key_info = this->gen_key_info_](const OperaWaitingHd& hd) { + GpgKeyOpera::GetInstance(channel_).GenerateKeyWithSubkey( + gen_key_info, gen_subkey_info_, + [this, hd](GpgError err, const DataObjectPtr&) { + // stop showing waiting dialog + hd(); + + if (CheckGpgError(err) == GPG_ERR_USER_1) { + QMessageBox::critical(this, tr("Error"), + tr("Unknown error occurred")); + return; + } + + CommonUtils::RaiseMessageBox( + this->parentWidget() != nullptr ? this->parentWidget() : this, + err); + if (CheckGpgError(err) == GPG_ERR_NO_ERROR) { + emit SignalKeyGenerated(); + } + }); + }; + GpgOperaHelper::WaitForOpera(this, tr("Generating"), f); +} } // namespace GpgFrontend::UI diff --git a/src/ui/dialog/key_generate/KeyGenerateDialog.h b/src/ui/dialog/key_generate/KeyGenerateDialog.h index 63690831..a4d27900 100644 --- a/src/ui/dialog/key_generate/KeyGenerateDialog.h +++ b/src/ui/dialog/key_generate/KeyGenerateDialog.h @@ -28,7 +28,7 @@ #pragma once -#include "core/model/GpgGenKeyInfo.h" +#include "core/model/GpgKeyGenerateInfo.h" #include "ui/dialog/GeneralDialog.h" class Ui_KeyGenDialog; @@ -39,7 +39,7 @@ namespace GpgFrontend::UI { * @brief * */ -class KeyGenDialog : public GeneralDialog { +class KeyGenerateDialog : public GeneralDialog { Q_OBJECT public: @@ -50,7 +50,7 @@ class KeyGenDialog : public GeneralDialog { * @param key The key to show details of * @param parent The parent of this widget */ - explicit KeyGenDialog(int channel, QWidget* parent = nullptr); + explicit KeyGenerateDialog(int channel, QWidget* parent = nullptr); signals: /** @@ -93,6 +93,13 @@ class KeyGenDialog : public GeneralDialog { */ void slot_set_easy_key_algo_2_custom(); + /** + * @brief + * + * @param mode + */ + void slot_easy_combination_changed(const QString& mode); + private: /** * @brief @@ -109,8 +116,8 @@ class KeyGenDialog : public GeneralDialog { ///< entries of line edits QSharedPointer<Ui_KeyGenDialog> ui_; - QSharedPointer<GenKeyInfo> gen_key_info_; ///< - QSharedPointer<GenKeyInfo> gen_subkey_info_; ///< + QSharedPointer<KeyGenerateInfo> gen_key_info_; ///< + QSharedPointer<KeyGenerateInfo> gen_subkey_info_; ///< QContainer<KeyAlgo> supported_primary_key_algos_; QContainer<KeyAlgo> supported_subkey_algos_; @@ -148,6 +155,12 @@ class KeyGenDialog : public GeneralDialog { * */ void sync_gen_subkey_info(); + + /** + * @brief + * + */ + void do_generate(); }; } // namespace GpgFrontend::UI diff --git a/src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp b/src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp index b55e4b28..a2f7a4ae 100644 --- a/src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp +++ b/src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp @@ -127,10 +127,10 @@ QGroupBox* SubkeyGenerateDialog::create_basic_info_group_box() { key_type_combo_box_ = new QComboBox(this); no_pass_phrase_check_box_ = new QCheckBox(this); - for (const auto& algo : GenKeyInfo::GetSupportedSubkeyAlgo()) { + for (const auto& algo : KeyGenerateInfo::GetSupportedSubkeyAlgo()) { key_type_combo_box_->addItem(algo.Name()); } - if (!GenKeyInfo::GetSupportedSubkeyAlgo().empty()) { + if (!KeyGenerateInfo::GetSupportedSubkeyAlgo().empty()) { key_type_combo_box_->setCurrentIndex(0); } @@ -189,7 +189,7 @@ void SubkeyGenerateDialog::set_signal_slot() { connect(no_pass_phrase_check_box_, &QCheckBox::stateChanged, this, [this](int state) -> void { - gen_key_info_->SetNonPassPhrase(state != 0); + gen_subkey_info_->SetNonPassPhrase(state != 0); }); } @@ -202,49 +202,49 @@ void SubkeyGenerateDialog::slot_expire_box_changed() { } void SubkeyGenerateDialog::refresh_widgets_state() { - if (gen_key_info_->IsAllowEncryption()) { + 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_key_info_->IsAllowChangeEncryption()) { + if (gen_subkey_info_->IsAllowChangeEncryption()) { key_usage_check_boxes_[0]->setDisabled(false); } else { key_usage_check_boxes_[0]->setDisabled(true); } - if (gen_key_info_->IsAllowSigning()) { + 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_key_info_->IsAllowChangeSigning()) { + if (gen_subkey_info_->IsAllowChangeSigning()) { key_usage_check_boxes_[1]->setDisabled(false); } else { key_usage_check_boxes_[1]->setDisabled(true); } - if (gen_key_info_->IsAllowCertification()) { + if (gen_subkey_info_->IsAllowCertification()) { key_usage_check_boxes_[2]->setCheckState(Qt::CheckState::Checked); } else { key_usage_check_boxes_[2]->setCheckState(Qt::CheckState::Unchecked); } - if (gen_key_info_->IsAllowChangeCertification()) { + if (gen_subkey_info_->IsAllowChangeCertification()) { key_usage_check_boxes_[2]->setDisabled(false); } else { key_usage_check_boxes_[2]->setDisabled(true); } - if (gen_key_info_->IsAllowAuthentication()) { + 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_key_info_->IsAllowChangeAuthentication()) { + if (gen_subkey_info_->IsAllowChangeAuthentication()) { key_usage_check_boxes_[3]->setDisabled(false); } else { key_usage_check_boxes_[3]->setDisabled(true); @@ -252,103 +252,76 @@ void SubkeyGenerateDialog::refresh_widgets_state() { } void SubkeyGenerateDialog::slot_key_gen_accept() { - QString buffer; - QTextStream err_stream(&buffer); - - /** - * primary keys should have a reasonable expiration date (no more than 2 years - * in the future) - */ - if (date_edit_->dateTime() > QDateTime::currentDateTime().addYears(2)) { - err_stream << " " << tr("Expiration time no more than 2 years.") << " "; - } - - auto err_string = err_stream.readAll(); - - if (err_string.isEmpty()) { - if (expire_check_box_->checkState() != 0U) { - gen_key_info_->SetNonExpired(true); - } else { - gen_key_info_->SetExpireTime(date_edit_->dateTime()); - } - - GpgOperaHelper::WaitForOpera( - this, tr("Generating"), - [this, key = this->key_, - gen_key_info = this->gen_key_info_](const OperaWaitingHd& hd) { - GpgKeyOpera::GetInstance(current_gpg_context_channel_) - .GenerateSubkey(key, gen_key_info, - [this, hd](GpgError err, const DataObjectPtr&) { - // stop showing waiting dialog - hd(); - - if (CheckGpgError(err) == GPG_ERR_USER_1) { - QMessageBox::critical( - this, tr("Error"), - tr("Unknown error occurred")); - return; - } - - CommonUtils::RaiseMessageBox(this, err); - if (CheckGpgError(err) == GPG_ERR_NO_ERROR) { - emit UISignalStation::GetInstance() - -> SignalKeyDatabaseRefresh(); - } - }); - }); - this->done(0); - + if (expire_check_box_->checkState() != 0U) { + gen_subkey_info_->SetNonExpired(true); } else { - /** - * create error message - */ - error_label_->setAutoFillBackground(true); - QPalette error = error_label_->palette(); - error.setColor(QPalette::Window, "#ff8080"); - error_label_->setPalette(error); - error_label_->setText(err_string); - - this->show(); + gen_subkey_info_->SetExpireTime(date_edit_->dateTime()); } + + GpgOperaHelper::WaitForOpera( + this, tr("Generating"), + [this, key = this->key_, + gen_key_info = this->gen_subkey_info_](const OperaWaitingHd& hd) { + GpgKeyOpera::GetInstance(current_gpg_context_channel_) + .GenerateSubkey(key, gen_key_info, + [this, hd](GpgError err, const DataObjectPtr&) { + // stop showing waiting dialog + hd(); + + if (CheckGpgError(err) == GPG_ERR_USER_1) { + QMessageBox::critical( + this, tr("Error"), + tr("Unknown error occurred")); + return; + } + + CommonUtils::RaiseMessageBox(this, err); + if (CheckGpgError(err) == GPG_ERR_NO_ERROR) { + emit UISignalStation::GetInstance() + -> SignalKeyDatabaseRefresh(); + } + }); + }); + this->done(0); } void SubkeyGenerateDialog::slot_encryption_box_changed(int state) { if (state == 0) { - gen_key_info_->SetAllowEncryption(false); + gen_subkey_info_->SetAllowEncryption(false); } else { - gen_key_info_->SetAllowEncryption(true); + gen_subkey_info_->SetAllowEncryption(true); } } void SubkeyGenerateDialog::slot_signing_box_changed(int state) { if (state == 0) { - gen_key_info_->SetAllowSigning(false); + gen_subkey_info_->SetAllowSigning(false); } else { - gen_key_info_->SetAllowSigning(true); + gen_subkey_info_->SetAllowSigning(true); } } void SubkeyGenerateDialog::slot_certification_box_changed(int state) { if (state == 0) { - gen_key_info_->SetAllowCertification(false); + gen_subkey_info_->SetAllowCertification(false); } else { - gen_key_info_->SetAllowCertification(true); + gen_subkey_info_->SetAllowCertification(true); } } void SubkeyGenerateDialog::slot_authentication_box_changed(int state) { if (state == 0) { - gen_key_info_->SetAllowAuthentication(false); + gen_subkey_info_->SetAllowAuthentication(false); } else { - gen_key_info_->SetAllowAuthentication(true); + gen_subkey_info_->SetAllowAuthentication(true); } } void SubkeyGenerateDialog::slot_activated_key_type(int index) { // check - assert(gen_key_info_->GetSupportedSubkeyAlgo().size() > + assert(gen_subkey_info_->GetSupportedSubkeyAlgo().size() > static_cast<size_t>(index)); - gen_key_info_->SetAlgo(gen_key_info_->GetSupportedSubkeyAlgo()[index]); + gen_subkey_info_->SetAlgo(gen_subkey_info_->GetSupportedSubkeyAlgo()[index]); refresh_widgets_state(); } diff --git a/src/ui/dialog/key_generate/SubkeyGenerateDialog.h b/src/ui/dialog/key_generate/SubkeyGenerateDialog.h index b8c525bd..ad47bbf2 100644 --- a/src/ui/dialog/key_generate/SubkeyGenerateDialog.h +++ b/src/ui/dialog/key_generate/SubkeyGenerateDialog.h @@ -31,8 +31,8 @@ #include <memory> #include "core/function/gpg/GpgContext.h" -#include "core/model/GpgGenKeyInfo.h" #include "core/model/GpgKey.h" +#include "core/model/GpgKeyGenerateInfo.h" #include "core/typedef/GpgTypedef.h" #include "core/utils/MemoryUtils.h" #include "ui/GpgFrontendUI.h" @@ -60,8 +60,8 @@ class SubkeyGenerateDialog : public GeneralDialog { int current_gpg_context_channel_; ///< GpgKey key_; ///< - QSharedPointer<GenKeyInfo> gen_key_info_ = - QSharedPointer<GenKeyInfo>::create(true); ///< + QSharedPointer<KeyGenerateInfo> gen_subkey_info_ = + QSharedPointer<KeyGenerateInfo>::create(true); ///< QGroupBox* key_usage_group_box_{}; QDialogButtonBox* button_box_; ///< Box for standard buttons diff --git a/src/ui/main_window/KeyMgmt.cpp b/src/ui/main_window/KeyMgmt.cpp index f83226ed..38a5399c 100644 --- a/src/ui/main_window/KeyMgmt.cpp +++ b/src/ui/main_window/KeyMgmt.cpp @@ -441,7 +441,7 @@ void KeyMgmt::SlotExportKeyToClipboard() { } void KeyMgmt::SlotGenerateKeyDialog() { - (new KeyGenDialog(key_list_->GetCurrentGpgContextChannel(), this))->exec(); + (new KeyGenerateDialog(key_list_->GetCurrentGpgContextChannel(), this))->exec(); this->raise(); } |