aboutsummaryrefslogtreecommitdiffstats
path: root/src/ui/dialog
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/dialog')
-rw-r--r--src/ui/dialog/KeyDatabaseEditDialog.cpp9
-rw-r--r--src/ui/dialog/SignersPicker.cpp14
-rw-r--r--src/ui/dialog/SignersPicker.h4
-rw-r--r--src/ui/dialog/WaitingDialog.cpp19
-rw-r--r--src/ui/dialog/WaitingDialog.h23
-rw-r--r--src/ui/dialog/Wizard.cpp25
-rw-r--r--src/ui/dialog/Wizard.h13
-rw-r--r--src/ui/dialog/controller/GnuPGControllerDialog.cpp109
-rw-r--r--src/ui/dialog/controller/GnuPGControllerDialog.h7
-rw-r--r--src/ui/dialog/controller/ModuleControllerDialog.cpp5
-rw-r--r--src/ui/dialog/import_export/ExportKeyPackageDialog.cpp16
-rw-r--r--src/ui/dialog/import_export/ExportKeyPackageDialog.h6
-rw-r--r--src/ui/dialog/import_export/KeyServerImportDialog.cpp18
-rw-r--r--src/ui/dialog/import_export/KeyServerImportDialog.h6
-rw-r--r--src/ui/dialog/import_export/KeyUploadDialog.cpp6
-rw-r--r--src/ui/dialog/import_export/KeyUploadDialog.h4
-rw-r--r--src/ui/dialog/key_generate/KeyGenerateDialog.cpp641
-rw-r--r--src/ui/dialog/key_generate/KeyGenerateDialog.h (renamed from src/ui/dialog/key_generate/KeygenDialog.h)115
-rw-r--r--src/ui/dialog/key_generate/KeygenDialog.cpp482
-rw-r--r--src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp447
-rw-r--r--src/ui/dialog/key_generate/SubkeyGenerateDialog.h91
-rw-r--r--src/ui/dialog/keypair_details/KeyPairDetailTab.cpp26
-rw-r--r--src/ui/dialog/keypair_details/KeyPairOperaTab.cpp6
-rw-r--r--src/ui/dialog/keypair_details/KeyPairSubkeyTab.cpp29
-rw-r--r--src/ui/dialog/keypair_details/KeyPairSubkeyTab.h6
-rw-r--r--src/ui/dialog/keypair_details/KeyPairUIDTab.cpp13
-rw-r--r--src/ui/dialog/keypair_details/KeyPairUIDTab.h16
-rw-r--r--src/ui/dialog/keypair_details/KeySetExpireDateDialog.cpp17
-rw-r--r--src/ui/dialog/keypair_details/KeyUIDSignDialog.cpp6
-rw-r--r--src/ui/dialog/settings/SettingsAppearance.cpp31
-rw-r--r--src/ui/dialog/settings/SettingsGeneral.cpp14
-rw-r--r--src/ui/dialog/settings/SettingsGeneral.h3
-rw-r--r--src/ui/dialog/settings/SettingsKeyServer.cpp3
-rw-r--r--src/ui/dialog/settings/SettingsNetwork.cpp5
34 files changed, 1104 insertions, 1131 deletions
diff --git a/src/ui/dialog/KeyDatabaseEditDialog.cpp b/src/ui/dialog/KeyDatabaseEditDialog.cpp
index cc6e2cf9..bde50f0c 100644
--- a/src/ui/dialog/KeyDatabaseEditDialog.cpp
+++ b/src/ui/dialog/KeyDatabaseEditDialog.cpp
@@ -30,6 +30,7 @@
#include <utility>
+#include "core/function/GlobalSettingStation.h"
#include "core/struct/settings_object/KeyDatabaseItemSO.h"
#include "core/utils/MemoryUtils.h"
#include "ui_KeyDatabaseEditDialog.h"
@@ -43,10 +44,13 @@ KeyDatabaseEditDialog::KeyDatabaseEditDialog(
ui_->setupUi(this);
ui_->keyDBPathShowLabel->setHidden(true);
+ ui_->convert2RelativePathCheckBox->setChecked(
+ GlobalSettingStation::GetInstance().IsProtableMode());
ui_->keyDBNameLabel->setText(tr("Key Database Name"));
ui_->keyDBPathLabel->setText(tr("Key Database Path"));
ui_->selectKeyDBButton->setText(tr("Select A Key Database Path"));
+ ui_->convert2RelativePathCheckBox->setText(tr("Convert to Relative Path"));
this->setWindowTitle(tr("Key Database Info"));
@@ -96,6 +100,11 @@ void KeyDatabaseEditDialog::slot_button_box_accepted() {
}
}
+ if (ui_->convert2RelativePathCheckBox->isChecked()) {
+ path_ = QDir(GlobalSettingStation::GetInstance().GetAppDir())
+ .relativeFilePath(path_);
+ }
+
slot_clear_err_msg();
emit SignalKeyDatabaseInfoAccepted(name_, path_);
this->accept();
diff --git a/src/ui/dialog/SignersPicker.cpp b/src/ui/dialog/SignersPicker.cpp
index dcd23a6b..61a31606 100644
--- a/src/ui/dialog/SignersPicker.cpp
+++ b/src/ui/dialog/SignersPicker.cpp
@@ -49,11 +49,9 @@ SignersPicker::SignersPicker(int channel, QWidget* parent)
GpgKeyTableColumn::kNAME | GpgKeyTableColumn::kEMAIL_ADDRESS |
GpgKeyTableColumn::kKEY_ID | GpgKeyTableColumn::kUSAGE,
this);
- key_list_->AddListGroupTab(tr("Signers"), "signers",
- GpgKeyTableDisplayMode::kPRIVATE_KEY,
- [](const GpgKey& key) -> bool {
- return key.IsHasActualSigningCapability();
- });
+ key_list_->AddListGroupTab(
+ tr("Signers"), "signers", GpgKeyTableDisplayMode::kPRIVATE_KEY,
+ [](const GpgKey& key) -> bool { return key.IsHasActualSignCap(); });
key_list_->SlotRefresh();
auto* vbox2 = new QVBoxLayout();
@@ -78,15 +76,15 @@ SignersPicker::SignersPicker(int channel, QWidget* parent)
this->show();
}
-auto SignersPicker::GetCheckedSigners() -> GpgFrontend::KeyIdArgsListPtr {
+auto SignersPicker::GetCheckedSigners() -> GpgFrontend::KeyIdArgsList {
return key_list_->GetCheckedPrivateKey();
}
-auto SignersPicker::GetCheckedSignerKeyIds() -> QStringList {
+auto SignersPicker::GetCheckedSignerKeyIds() -> GpgFrontend::KeyIdArgsList {
auto priv_keys = key_list_->GetCheckedPrivateKey();
QStringList r;
- for (const auto& priv_key : *priv_keys) {
+ for (const auto& priv_key : priv_keys) {
r.append(priv_key);
}
return r;
diff --git a/src/ui/dialog/SignersPicker.h b/src/ui/dialog/SignersPicker.h
index accf6952..826ccfab 100644
--- a/src/ui/dialog/SignersPicker.h
+++ b/src/ui/dialog/SignersPicker.h
@@ -56,14 +56,14 @@ class SignersPicker : public GeneralDialog {
*
* @return GpgFrontend::KeyIdArgsListPtr
*/
- auto GetCheckedSigners() -> KeyIdArgsListPtr;
+ auto GetCheckedSigners() -> KeyIdArgsList;
/**
* @brief Get the Checked Signer Key Ids object
*
* @return QStringList
*/
- auto GetCheckedSignerKeyIds() -> QStringList;
+ auto GetCheckedSignerKeyIds() -> KeyIdArgsList;
/**
*
* @return
diff --git a/src/ui/dialog/WaitingDialog.cpp b/src/ui/dialog/WaitingDialog.cpp
index da620ebf..e9d28f26 100644
--- a/src/ui/dialog/WaitingDialog.cpp
+++ b/src/ui/dialog/WaitingDialog.cpp
@@ -32,15 +32,14 @@
namespace GpgFrontend::UI {
-WaitingDialog::WaitingDialog(const QString& title, QWidget* parent)
- : GeneralDialog("WaitingDialog", parent) {
- auto* pb = new QProgressBar();
- pb->setRange(0, 0);
- pb->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
- pb->setTextVisible(false);
+WaitingDialog::WaitingDialog(const QString& title, bool range, QWidget* parent)
+ : GeneralDialog("WaitingDialog", parent), pb_(new QProgressBar()) {
+ pb_->setRange(0, range ? 100 : 0);
+ pb_->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
+ pb_->setTextVisible(false);
auto* layout = new QVBoxLayout();
- layout->addWidget(pb);
+ layout->addWidget(pb_);
this->setLayout(layout);
this->setModal(true);
@@ -50,8 +49,14 @@ WaitingDialog::WaitingDialog(const QString& title, QWidget* parent)
this->setAttribute(Qt::WA_DeleteOnClose);
this->setFixedSize(240, 42);
+ connect(this, &WaitingDialog::SignalUpdateValue, this,
+ &WaitingDialog::SlotUpdateValue);
+
this->movePosition2CenterOfParent();
this->show();
}
+void WaitingDialog::SlotUpdateValue(int value) {
+ if (pb_->maximum() > 0) pb_->setValue(value);
+}
} // namespace GpgFrontend::UI
diff --git a/src/ui/dialog/WaitingDialog.h b/src/ui/dialog/WaitingDialog.h
index 6b0877fe..1fb9fe17 100644
--- a/src/ui/dialog/WaitingDialog.h
+++ b/src/ui/dialog/WaitingDialog.h
@@ -46,7 +46,28 @@ class WaitingDialog : public GeneralDialog {
* @param title
* @param parent
*/
- WaitingDialog(const QString& title, QWidget* parent);
+ explicit WaitingDialog(const QString& title, bool range,
+ QWidget* parent = nullptr);
+
+ public slots:
+
+ /**
+ * @brief max 100, min 0
+ *
+ */
+ void SlotUpdateValue(int value);
+
+ signals:
+
+ /**
+ * @brief
+ *
+ * @param value
+ */
+ void SignalUpdateValue(int value);
+
+ private:
+ QProgressBar* pb_;
};
} // namespace GpgFrontend::UI
diff --git a/src/ui/dialog/Wizard.cpp b/src/ui/dialog/Wizard.cpp
index 3a3c0800..8e77dada 100644
--- a/src/ui/dialog/Wizard.cpp
+++ b/src/ui/dialog/Wizard.cpp
@@ -29,14 +29,16 @@
#include "Wizard.h"
#include "core/function/GlobalSettingStation.h"
+#include "ui/GpgFrontendUI.h"
+#include "ui/dialog/key_generate/KeyGenerateDialog.h"
namespace GpgFrontend::UI {
Wizard::Wizard(QWidget* parent) : QWizard(parent) {
- setPage(Page_Intro, new IntroPage(this));
- setPage(Page_Choose, new ChoosePage(this));
- setPage(Page_GenKey, new KeyGenPage(this));
- setPage(Page_Conclusion, new ConclusionPage(this));
+ setPage(kPAGE_INTRO, new IntroPage(this));
+ setPage(kPAGE_CHOOSE, new ChoosePage(this));
+ setPage(kPAGE_GEN_KEY, new KeyGenPage(this));
+ setPage(kPAGE_CONCLUSION, new ConclusionPage(this));
#ifndef Q_WS_MAC
setWizardStyle(ModernStyle);
#endif
@@ -45,10 +47,7 @@ Wizard::Wizard(QWidget* parent) : QWizard(parent) {
setPixmap(QWizard::LogoPixmap,
QPixmap(":/icons/gpgfrontend_logo.png").scaled(64, 64));
- int next_page_id = GlobalSettingStation::GetInstance()
- .GetSettings()
- .value("wizard.next_page", -1)
- .toInt();
+ int next_page_id = GetSettings().value("wizard.next_page", -1).toInt();
setStartId(next_page_id);
connect(this, &Wizard::accepted, this, &Wizard::slot_wizard_accepted);
@@ -57,7 +56,7 @@ Wizard::Wizard(QWidget* parent) : QWizard(parent) {
void Wizard::slot_wizard_accepted() {
// Don't show is mapped to show -> negation
try {
- auto settings = GlobalSettingStation::GetInstance().GetSettings();
+ auto settings = GetSettings();
settings.setValue("wizard/show_wizard", false);
} catch (...) {
FLOG_W("setting operation error");
@@ -101,7 +100,7 @@ IntroPage::IntroPage(QWidget* parent) : QWizardPage(parent) {
setLayout(layout);
}
-int IntroPage::nextId() const { return Wizard::Page_Choose; }
+int IntroPage::nextId() const { return Wizard::kPAGE_CHOOSE; }
ChoosePage::ChoosePage(QWidget* parent) : QWizardPage(parent) {
setTitle(tr("Choose your action..."));
@@ -146,7 +145,7 @@ ChoosePage::ChoosePage(QWidget* parent) : QWizardPage(parent) {
layout->addWidget(encr_decy_text_label);
layout->addWidget(sign_verify_text_label);
setLayout(layout);
- next_page_ = Wizard::Page_Conclusion;
+ next_page_ = Wizard::kPAGE_CONCLUSION;
}
int ChoosePage::nextId() const { return next_page_; }
@@ -193,10 +192,10 @@ KeyGenPage::KeyGenPage(QWidget* parent) : QWizardPage(parent) {
setLayout(layout);
}
-int KeyGenPage::nextId() const { return Wizard::Page_Conclusion; }
+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/Wizard.h b/src/ui/dialog/Wizard.h
index eae1d73d..91a5f846 100644
--- a/src/ui/dialog/Wizard.h
+++ b/src/ui/dialog/Wizard.h
@@ -29,10 +29,6 @@
#pragma once
#include "core/GpgConstants.h"
-#include "main_window/KeyMgmt.h"
-#include "ui/GpgFrontendUI.h"
-#include "ui/dialog/key_generate/KeygenDialog.h"
-#include "ui/dialog/settings/SettingsDialog.h"
namespace GpgFrontend::UI {
@@ -45,7 +41,12 @@ class Wizard : public QWizard {
Q_ENUMS(WizardPages)
public:
- enum WizardPages { Page_Intro, Page_Choose, Page_GenKey, Page_Conclusion };
+ enum WizardPages {
+ kPAGE_INTRO,
+ kPAGE_CHOOSE,
+ kPAGE_GEN_KEY,
+ kPAGE_CONCLUSION,
+ };
/**
* @brief Construct a new Wizard object
@@ -176,7 +177,7 @@ class ConclusionPage : public QWizardPage {
*
* @return int
*/
- [[nodiscard]] int nextId() const override;
+ [[nodiscard]] auto nextId() const -> int override;
private:
QCheckBox* dont_show_wizard_checkbox_; ///<
diff --git a/src/ui/dialog/controller/GnuPGControllerDialog.cpp b/src/ui/dialog/controller/GnuPGControllerDialog.cpp
index 5b8e96dd..e68e208a 100644
--- a/src/ui/dialog/controller/GnuPGControllerDialog.cpp
+++ b/src/ui/dialog/controller/GnuPGControllerDialog.cpp
@@ -45,7 +45,8 @@ namespace GpgFrontend::UI {
GnuPGControllerDialog::GnuPGControllerDialog(QWidget* parent)
: GeneralDialog("GnuPGControllerDialog", parent),
- ui_(GpgFrontend::SecureCreateSharedObject<Ui_GnuPGControllerDialog>()) {
+ ui_(GpgFrontend::SecureCreateSharedObject<Ui_GnuPGControllerDialog>()),
+ app_path_(GlobalSettingStation::GetInstance().GetAppDir()) {
ui_->setupUi(this);
ui_->asciiModeCheckBox->setText(tr("Use Binary Mode for File Operations"));
@@ -73,7 +74,7 @@ GnuPGControllerDialog::GnuPGControllerDialog(QWidget* parent)
ui_->keyDatabaseTable->clear();
QStringList column_titles;
- column_titles << tr("Name") << tr("Path");
+ column_titles << tr("Name") << tr("Status") << tr("Path") << tr("Real Path");
ui_->keyDatabaseTable->setColumnCount(static_cast<int>(column_titles.size()));
ui_->keyDatabaseTable->setHorizontalHeaderLabels(column_titles);
@@ -203,10 +204,7 @@ void GnuPGControllerDialog::slot_update_custom_gnupg_install_path_label(
if (custom_gnupg_path_.isEmpty()) {
// read from settings file
QString custom_gnupg_install_path =
- GlobalSettingStation::GetInstance()
- .GetSettings()
- .value("gnupg/custom_gnupg_install_path")
- .toString();
+ GetSettings().value("gnupg/custom_gnupg_install_path").toString();
custom_gnupg_path_ = custom_gnupg_install_path;
}
@@ -231,7 +229,7 @@ void GnuPGControllerDialog::slot_update_custom_gnupg_install_path_label(
}
void GnuPGControllerDialog::set_settings() {
- auto settings = GlobalSettingStation::GetInstance().GetSettings();
+ auto settings = GetSettings();
auto non_ascii_at_file_operation =
settings.value("gnupg/non_ascii_at_file_operation", true).toBool();
@@ -277,18 +275,14 @@ void GnuPGControllerDialog::set_settings() {
this->slot_set_restart_needed(kNonRestartCode);
- buffered_key_db_so_ = GetGpgKeyDatabaseInfos();
- editable_key_db_so_ = buffered_key_db_so_;
- if (!editable_key_db_so_.isEmpty()) {
- editable_key_db_so_.pop_front();
- }
+ key_db_infos_ = GetKeyDatabaseInfoBySettings();
+ active_key_db_infos_ = GetGpgKeyDatabaseInfos();
this->slot_refresh_key_database_table();
}
void GnuPGControllerDialog::apply_settings() {
- auto settings =
- GpgFrontend::GlobalSettingStation::GetInstance().GetSettings();
+ auto settings = GpgFrontend::GetSettings();
settings.setValue("gnupg/non_ascii_at_file_operation",
ui_->asciiModeCheckBox->isChecked());
@@ -308,7 +302,10 @@ void GnuPGControllerDialog::apply_settings() {
auto so = SettingsObject("key_database_list");
auto key_database_list = KeyDatabaseListSO(so);
key_database_list.key_databases.clear();
- for (const auto& key_db_info : editable_key_db_so_) {
+
+ int index = 0;
+ for (auto& key_db_info : key_db_infos_) {
+ key_db_info.channel = index++;
key_database_list.key_databases.append(KeyDatabaseItemSO(key_db_info));
}
so.Store(key_database_list.ToJson());
@@ -356,9 +353,9 @@ auto GnuPGControllerDialog::check_custom_gnupg_path(QString path) -> bool {
}
void GnuPGControllerDialog::slot_add_new_key_database() {
- auto* dialog = new KeyDatabaseEditDialog(editable_key_db_so_, this);
+ auto* dialog = new KeyDatabaseEditDialog(key_db_infos_, this);
- if (editable_key_db_so_.size() >= 8) {
+ if (key_db_infos_.size() >= 8) {
QMessageBox::critical(
this, tr("Maximum Key Database Limit Reached"),
tr("Currently, GpgFrontend supports a maximum of 8 key databases. "
@@ -368,7 +365,7 @@ void GnuPGControllerDialog::slot_add_new_key_database() {
connect(dialog, &KeyDatabaseEditDialog::SignalKeyDatabaseInfoAccepted, this,
[this](const QString& name, const QString& path) {
- auto& key_databases = buffered_key_db_so_;
+ auto& key_databases = key_db_infos_;
for (const auto& key_database : key_databases) {
if (QFileInfo(key_database.path) == QFileInfo(path)) {
QMessageBox::warning(
@@ -379,20 +376,25 @@ void GnuPGControllerDialog::slot_add_new_key_database() {
}
}
+ auto key_db_fs_path =
+ GpgFrontend::GetCanonicalKeyDatabasePath(app_path_, path);
+ if (key_db_fs_path.isEmpty()) {
+ QMessageBox::warning(this, tr("Invalid Key Database Paths"),
+ tr("The edited key database path is not a "
+ "valid path that GpgFrontend can use"));
+ return;
+ }
+
LOG_D() << "new key database path, name: " << name
- << "path: " << path;
+ << "path: " << path << "canonical path: " << key_db_fs_path;
KeyDatabaseInfo key_database;
key_database.name = name;
- key_database.path = path;
- key_database.channel = buffered_key_db_so_.size();
+ key_database.path = key_db_fs_path;
+ key_database.origin_path = path;
+ key_database.channel = static_cast<int>(key_databases.size());
key_databases.append(key_database);
- editable_key_db_so_ = buffered_key_db_so_;
- if (!editable_key_db_so_.isEmpty()) {
- editable_key_db_so_.pop_front();
- }
-
// refresh ui
slot_refresh_key_database_table();
@@ -403,23 +405,34 @@ void GnuPGControllerDialog::slot_add_new_key_database() {
}
void GnuPGControllerDialog::slot_refresh_key_database_table() {
- auto& key_databases = editable_key_db_so_;
+ auto& key_databases = key_db_infos_;
ui_->keyDatabaseTable->setRowCount(static_cast<int>(key_databases.size()));
int index = 0;
- for (const auto& key_database : key_databases) {
+ for (const auto& key_db : key_databases) {
LOG_D() << "key database table item index: " << index
- << "name: " << key_database.name << "path: " << key_database.path;
+ << "name: " << key_db.name << "path: " << key_db.path;
- auto* i_name = new QTableWidgetItem(key_database.name);
+ auto* i_name = new QTableWidgetItem(key_db.name);
i_name->setTextAlignment(Qt::AlignCenter);
ui_->keyDatabaseTable->setVerticalHeaderItem(
index, new QTableWidgetItem(QString::number(index + 1)));
ui_->keyDatabaseTable->setItem(index, 0, i_name);
- ui_->keyDatabaseTable->setItem(index, 1,
- new QTableWidgetItem(key_database.path));
+ auto is_active =
+ std::find_if(active_key_db_infos_.begin(), active_key_db_infos_.end(),
+ [key_db](const KeyDatabaseInfo& i) {
+ return i.name == key_db.name;
+ }) != active_key_db_infos_.end();
+ ui_->keyDatabaseTable->setItem(
+ index, 1,
+ new QTableWidgetItem(is_active ? tr("Active") : tr("Inactive")));
+
+ ui_->keyDatabaseTable->setItem(index, 2,
+ new QTableWidgetItem(key_db.origin_path));
+
+ ui_->keyDatabaseTable->setItem(index, 3, new QTableWidgetItem(key_db.path));
index++;
}
@@ -436,7 +449,7 @@ void GnuPGControllerDialog::contextMenuEvent(QContextMenuEvent* event) {
void GnuPGControllerDialog::slot_remove_existing_key_database() {
const auto row_size = ui_->keyDatabaseTable->rowCount();
- auto& key_databases = editable_key_db_so_;
+ auto& key_databases = key_db_infos_;
for (int i = 0; i < row_size; i++) {
auto* const item = ui_->keyDatabaseTable->item(i, 1);
if (!item->isSelected()) continue;
@@ -463,7 +476,7 @@ void GnuPGControllerDialog::slot_remove_existing_key_database() {
void GnuPGControllerDialog::slot_open_key_database() {
const auto row_size = ui_->keyDatabaseTable->rowCount();
- auto& key_databases = editable_key_db_so_;
+ auto& key_databases = key_db_infos_;
for (int i = 0; i < row_size; i++) {
auto* const item = ui_->keyDatabaseTable->item(i, 1);
if (!item->isSelected()) continue;
@@ -478,7 +491,7 @@ void GnuPGControllerDialog::slot_move_up_key_database() {
if (row_size <= 0) return;
- auto& key_databases = editable_key_db_so_;
+ auto& key_databases = key_db_infos_;
for (int i = 0; i < row_size; i++) {
auto* const item = ui_->keyDatabaseTable->item(i, 1);
@@ -508,7 +521,7 @@ void GnuPGControllerDialog::slot_move_to_top_key_database() {
if (row_size <= 0) return;
- auto& key_databases = editable_key_db_so_;
+ auto& key_databases = key_db_infos_;
for (int i = 0; i < row_size; i++) {
auto* const item = ui_->keyDatabaseTable->item(i, 1);
@@ -541,7 +554,7 @@ void GnuPGControllerDialog::slot_move_down_key_database() {
if (row_size <= 0) return;
- auto& key_databases = editable_key_db_so_;
+ auto& key_databases = key_db_infos_;
for (int i = row_size - 1; i >= 0; i--) {
auto* const item = ui_->keyDatabaseTable->item(i, 1);
@@ -586,16 +599,16 @@ void GnuPGControllerDialog::slot_edit_key_database() {
return;
}
- auto& key_databases = editable_key_db_so_;
+ auto& key_databases = key_db_infos_;
KeyDatabaseInfo& selected_key_database = key_databases[selected_row];
- auto* dialog = new KeyDatabaseEditDialog(editable_key_db_so_, this);
+ auto* dialog = new KeyDatabaseEditDialog(key_databases, this);
dialog->SetDefaultName(selected_key_database.name);
dialog->SetDefaultPath(selected_key_database.path);
connect(dialog, &KeyDatabaseEditDialog::SignalKeyDatabaseInfoAccepted, this,
[this, selected_row, selected_key_database](const QString& name,
const QString& path) {
- auto& all_key_databases = buffered_key_db_so_;
+ auto& all_key_databases = key_db_infos_;
if (selected_key_database.path != path) {
for (int i = 0; i < all_key_databases.size(); i++) {
@@ -610,12 +623,22 @@ void GnuPGControllerDialog::slot_edit_key_database() {
}
}
+ auto key_db_fs_path =
+ GpgFrontend::GetCanonicalKeyDatabasePath(app_path_, path);
+ if (key_db_fs_path.isEmpty()) {
+ QMessageBox::warning(this, tr("Invalid Key Database Paths"),
+ tr("The edited key database path is not a "
+ "valid path that GpgFrontend can use"));
+ return;
+ }
+
LOG_D() << "edit key database path, name: " << name
- << "path: " << path;
+ << "path: " << path << "canonical path: " << key_db_fs_path;
- KeyDatabaseInfo& key_database = editable_key_db_so_[selected_row];
+ KeyDatabaseInfo& key_database = key_db_infos_[selected_row];
key_database.name = name;
- key_database.path = path;
+ key_database.path = key_db_fs_path;
+ key_database.origin_path = path;
slot_refresh_key_database_table();
diff --git a/src/ui/dialog/controller/GnuPGControllerDialog.h b/src/ui/dialog/controller/GnuPGControllerDialog.h
index 9c42180c..f0994c27 100644
--- a/src/ui/dialog/controller/GnuPGControllerDialog.h
+++ b/src/ui/dialog/controller/GnuPGControllerDialog.h
@@ -126,12 +126,13 @@ class GnuPGControllerDialog : public GeneralDialog {
private:
std::shared_ptr<Ui_GnuPGControllerDialog> ui_; ///<
- int restart_mode_{0}; ///<
+ const QString app_path_;
+ int restart_mode_{0}; ///<
QString custom_key_database_path_;
QString custom_gnupg_path_;
QMenu* popup_menu_{};
- QList<KeyDatabaseInfo> buffered_key_db_so_;
- QList<KeyDatabaseInfo> editable_key_db_so_;
+ QList<KeyDatabaseInfo> active_key_db_infos_;
+ QList<KeyDatabaseInfo> key_db_infos_;
/**
* @brief Get the Restart Needed object
diff --git a/src/ui/dialog/controller/ModuleControllerDialog.cpp b/src/ui/dialog/controller/ModuleControllerDialog.cpp
index 77949a61..2b842c7f 100644
--- a/src/ui/dialog/controller/ModuleControllerDialog.cpp
+++ b/src/ui/dialog/controller/ModuleControllerDialog.cpp
@@ -108,10 +108,7 @@ ModuleControllerDialog::ModuleControllerDialog(QWidget* parent)
// give user ability to give up all modules
auto disable_loading_all_modules =
- GlobalSettingStation::GetInstance()
- .GetSettings()
- .value("basic/disable_loading_all_modules", false)
- .toBool();
+ GetSettings().value("basic/disable_loading_all_modules", false).toBool();
if (disable_loading_all_modules) {
ui_->tabWidget->setTabEnabled(0, false);
}
diff --git a/src/ui/dialog/import_export/ExportKeyPackageDialog.cpp b/src/ui/dialog/import_export/ExportKeyPackageDialog.cpp
index 762c79b7..7aab31b5 100644
--- a/src/ui/dialog/import_export/ExportKeyPackageDialog.cpp
+++ b/src/ui/dialog/import_export/ExportKeyPackageDialog.cpp
@@ -31,11 +31,11 @@
#include "core/GpgModel.h"
#include "core/function/KeyPackageOperator.h"
#include "core/function/gpg/GpgKeyGetter.h"
-#include "ui/UserInterfaceUtils.h"
+#include "ui/function/GpgOperaHelper.h"
#include "ui_ExportKeyPackageDialog.h"
GpgFrontend::UI::ExportKeyPackageDialog::ExportKeyPackageDialog(
- int channel, KeyIdArgsListPtr key_ids, QWidget* parent)
+ int channel, KeyIdArgsList key_ids, QWidget* parent)
: GeneralDialog(typeid(ExportKeyPackageDialog).name(), parent),
ui_(GpgFrontend::SecureCreateSharedObject<Ui_exportKeyPackageDialog>()),
current_gpg_context_channel_(channel),
@@ -98,26 +98,26 @@ GpgFrontend::UI::ExportKeyPackageDialog::ExportKeyPackageDialog(
// get suitable key ids
auto keys = GpgKeyGetter::GetInstance(current_gpg_context_channel_)
.GetKeys(key_ids_);
- assert(std::all_of(keys->begin(), keys->end(),
+ assert(std::all_of(keys.begin(), keys.end(),
[](const auto& key) { return key.IsGood(); }));
auto keys_new_end =
- std::remove_if(keys->begin(), keys->end(), [this](const auto& key) {
+ std::remove_if(keys.begin(), keys.end(), [this](const auto& key) {
return ui_->noPublicKeyCheckBox->isChecked() && !key.IsPrivateKey();
});
- keys->erase(keys_new_end, keys->end());
+ keys.erase(keys_new_end, keys.end());
- if (keys->empty()) {
+ if (keys.empty()) {
QMessageBox::critical(this, tr("Error"),
tr("No key is suitable to export."));
return;
}
- CommonUtils::WaitForOpera(
+ GpgOperaHelper::WaitForOpera(
this, tr("Generating"), [this, keys](const OperaWaitingHd& op_hd) {
KeyPackageOperator::GenerateKeyPackage(
ui_->outputPathLabel->text(), ui_->nameValueLabel->text(),
- current_gpg_context_channel_, *keys, passphrase_,
+ current_gpg_context_channel_, keys, passphrase_,
ui_->includeSecretKeyCheckBox->isChecked(),
[=](GFError err, const DataObjectPtr&) {
// stop waiting
diff --git a/src/ui/dialog/import_export/ExportKeyPackageDialog.h b/src/ui/dialog/import_export/ExportKeyPackageDialog.h
index bf8e92a6..07722a21 100644
--- a/src/ui/dialog/import_export/ExportKeyPackageDialog.h
+++ b/src/ui/dialog/import_export/ExportKeyPackageDialog.h
@@ -50,13 +50,13 @@ class ExportKeyPackageDialog : public GeneralDialog {
* @param key_ids
* @param parent
*/
- explicit ExportKeyPackageDialog(int channel, KeyIdArgsListPtr key_ids,
+ explicit ExportKeyPackageDialog(int channel, KeyIdArgsList key_ids,
QWidget* parent);
private:
std::shared_ptr<Ui_exportKeyPackageDialog> ui_; ///<
int current_gpg_context_channel_;
- KeyIdArgsListPtr key_ids_; ///<
- QString passphrase_; ///<
+ KeyIdArgsList key_ids_; ///<
+ QString passphrase_; ///<
};
} // namespace GpgFrontend::UI
diff --git a/src/ui/dialog/import_export/KeyServerImportDialog.cpp b/src/ui/dialog/import_export/KeyServerImportDialog.cpp
index e81cc2e8..e3c66245 100644
--- a/src/ui/dialog/import_export/KeyServerImportDialog.cpp
+++ b/src/ui/dialog/import_export/KeyServerImportDialog.cpp
@@ -43,8 +43,7 @@ KeyServerImportDialog::KeyServerImportDialog(int channel, QWidget* parent)
: GeneralDialog("key_server_import_dialog", parent),
current_gpg_context_channel_(channel) {
auto forbid_all_gnupg_connection =
- GlobalSettingStation::GetInstance()
- .GetSettings()
+ GetSettings()
.value("network/forbid_all_gnupg_connection", false)
.toBool();
if (forbid_all_gnupg_connection) {
@@ -360,7 +359,7 @@ void KeyServerImportDialog::slot_search_finished(
}
void KeyServerImportDialog::slot_import() {
- std::vector<QString> key_ids;
+ KeyIdArgsList key_ids;
const int row_count = keys_table_->rowCount();
for (int i = 0; i < row_count; ++i) {
if (keys_table_->item(i, 2)->isSelected()) {
@@ -377,7 +376,7 @@ void KeyServerImportDialog::slot_import() {
}
}
-void KeyServerImportDialog::SlotImport(const KeyIdArgsListPtr& keys) {
+void KeyServerImportDialog::SlotImport(const KeyIdArgsList& keys) {
// keyserver host url
QString target_keyserver;
@@ -388,18 +387,17 @@ void KeyServerImportDialog::SlotImport(const KeyIdArgsListPtr& keys) {
KeyServerSO key_server(SettingsObject("key_server"));
target_keyserver = key_server.GetTargetServer();
}
- std::vector<QString> key_ids;
- for (const auto& key_id : *keys) {
+ KeyIdArgsList key_ids;
+ for (const auto& key_id : keys) {
key_ids.push_back(key_id);
}
SlotImport(key_ids, target_keyserver);
}
-void KeyServerImportDialog::SlotImport(std::vector<QString> key_ids,
+void KeyServerImportDialog::SlotImport(QStringList key_ids,
QString keyserver_url) {
- auto* task =
- new KeyServerImportTask(std::move(keyserver_url),
- current_gpg_context_channel_, std::move(key_ids));
+ auto* task = new KeyServerImportTask(keyserver_url,
+ current_gpg_context_channel_, key_ids);
connect(task, &KeyServerImportTask::SignalKeyServerImportResult, this,
&KeyServerImportDialog::slot_import_finished);
diff --git a/src/ui/dialog/import_export/KeyServerImportDialog.h b/src/ui/dialog/import_export/KeyServerImportDialog.h
index e4ee2367..25c55c3e 100644
--- a/src/ui/dialog/import_export/KeyServerImportDialog.h
+++ b/src/ui/dialog/import_export/KeyServerImportDialog.h
@@ -59,7 +59,7 @@ class KeyServerImportDialog : public GeneralDialog {
*
* @param keys
*/
- void SlotImport(const KeyIdArgsListPtr& keys);
+ void SlotImport(const KeyIdArgsList& keys);
/**
* @brief
@@ -67,7 +67,7 @@ class KeyServerImportDialog : public GeneralDialog {
* @param keyIds
* @param keyserverUrl
*/
- void SlotImport(std::vector<QString> key_ids_list, QString keyserver_url);
+ void SlotImport(KeyIdArgsList key_ids_list, QString keyserver_url);
signals:
@@ -127,7 +127,7 @@ class KeyServerImportDialog : public GeneralDialog {
*
* @param in_data
*/
- void import_keys(ByteArrayPtr in_data);
+ void import_keys(ByteArray in_data);
/**
* @brief Set the loading object
diff --git a/src/ui/dialog/import_export/KeyUploadDialog.cpp b/src/ui/dialog/import_export/KeyUploadDialog.cpp
index 9a02ea0e..efa72802 100644
--- a/src/ui/dialog/import_export/KeyUploadDialog.cpp
+++ b/src/ui/dialog/import_export/KeyUploadDialog.cpp
@@ -41,13 +41,13 @@
namespace GpgFrontend::UI {
-KeyUploadDialog::KeyUploadDialog(int channel, const KeyIdArgsListPtr& keys_ids,
+KeyUploadDialog::KeyUploadDialog(int channel, const KeyIdArgsList& keys_ids,
QWidget* parent)
: GeneralDialog(typeid(KeyUploadDialog).name(), parent),
current_gpg_context_channel_(channel),
m_keys_(GpgKeyGetter::GetInstance(current_gpg_context_channel_)
.GetKeys(keys_ids)) {
- assert(std::all_of(m_keys_->begin(), m_keys_->end(),
+ assert(std::all_of(m_keys_.begin(), m_keys_.end(),
[](const auto& key) { return key.IsGood(); }));
auto* pb = new QProgressBar();
@@ -70,7 +70,7 @@ KeyUploadDialog::KeyUploadDialog(int channel, const KeyIdArgsListPtr& keys_ids,
void KeyUploadDialog::SlotUpload() {
GpgKeyImportExporter::GetInstance(current_gpg_context_channel_)
- .ExportKeys(*m_keys_, false, true, false, false,
+ .ExportKeys(m_keys_, false, true, false, false,
[=](GpgError err, const DataObjectPtr& data_obj) {
if (CheckGpgError(err) != GPG_ERR_NO_ERROR) {
CommonUtils::RaiseMessageBox(this, err);
diff --git a/src/ui/dialog/import_export/KeyUploadDialog.h b/src/ui/dialog/import_export/KeyUploadDialog.h
index 3085ba0a..36616037 100644
--- a/src/ui/dialog/import_export/KeyUploadDialog.h
+++ b/src/ui/dialog/import_export/KeyUploadDialog.h
@@ -48,7 +48,7 @@ class KeyUploadDialog : public GeneralDialog {
* @param keys_ids
* @param parent
*/
- explicit KeyUploadDialog(int channel, const KeyIdArgsListPtr& keys_ids,
+ explicit KeyUploadDialog(int channel, const KeyIdArgsList& keys_ids,
QWidget* parent);
public slots:
@@ -76,7 +76,7 @@ class KeyUploadDialog : public GeneralDialog {
private:
int current_gpg_context_channel_;
- KeyListPtr m_keys_; ///<
+ GpgKeyList m_keys_; ///<
QByteArray m_key_data_; ///<
};
diff --git a/src/ui/dialog/key_generate/KeyGenerateDialog.cpp b/src/ui/dialog/key_generate/KeyGenerateDialog.cpp
new file mode 100644
index 00000000..ab3a5ac8
--- /dev/null
+++ b/src/ui/dialog/key_generate/KeyGenerateDialog.cpp
@@ -0,0 +1,641 @@
+/**
+ * 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 "KeyGenerateDialog.h"
+
+#include "core/GpgModel.h"
+#include "core/function/GlobalSettingStation.h"
+#include "core/function/gpg/GpgKeyOpera.h"
+#include "core/typedef/GpgTypedef.h"
+#include "core/utils/CacheUtils.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_KeyGenDialog.h"
+
+namespace GpgFrontend::UI {
+
+KeyGenerateDialog::KeyGenerateDialog(int channel, QWidget* parent)
+ : GeneralDialog(typeid(KeyGenerateDialog).name(), parent),
+ ui_(QSharedPointer<Ui_KeyGenDialog>::create()),
+ gen_key_info_(QSharedPointer<KeyGenerateInfo>::create()),
+ gen_subkey_info_(nullptr),
+ supported_primary_key_algos_(KeyGenerateInfo::GetSupportedKeyAlgo()),
+ supported_subkey_algos_(KeyGenerateInfo::GetSupportedSubkeyAlgo()),
+ channel_(channel) {
+ ui_->setupUi(this);
+
+ for (const auto& key_db : GetGpgKeyDatabaseInfos()) {
+ ui_->keyDBIndexComboBox->insertItem(
+ key_db.channel, QString("%1: %2").arg(key_db.channel).arg(key_db.name));
+ }
+
+ ui_->easyAlgoComboBox->addItems({
+ tr("Custom"),
+ "RSA",
+ "DSA",
+ "ECC (25519)",
+ });
+
+ ui_->easyValidityPeriodComboBox->addItems({
+ tr("Custom"),
+ tr("3 Months"),
+ tr("6 Months"),
+ tr("1 Year"),
+ tr("2 Years"),
+ tr("5 Years"),
+ tr("10 Years"),
+ 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_->pExpireDateLabel->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_->sExpireDateLabel->setText(tr("Expire Date"));
+ 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"));
+
+ assert(ui_->tabWidget->count() == 3);
+ ui_->tabWidget->setTabText(0, tr("Easy Mode"));
+ ui_->tabWidget->setTabText(1, tr("Primary Key"));
+ ui_->tabWidget->setTabText(2, tr("Subkey"));
+ ui_->tabWidget->setCurrentIndex(0);
+
+ ui_->generateButton->setText(tr("Generate"));
+
+ const auto min_date_time = QDateTime::currentDateTime().addDays(3);
+ ui_->pExpireDateTimeEdit->setMinimumDateTime(min_date_time);
+ ui_->sExpireDateTimeEdit->setMinimumDateTime(min_date_time);
+
+ QSet<QString> p_algo_set;
+ for (const auto& algo : supported_primary_key_algos_) {
+ p_algo_set.insert(algo.Name());
+ }
+ ui_->pAlgoComboBox->addItems(
+ QStringList(p_algo_set.cbegin(), p_algo_set.cend()));
+
+ QSet<QString> s_algo_set;
+ for (const auto& algo : supported_subkey_algos_) {
+ s_algo_set.insert(algo.Name());
+ }
+ ui_->sAlgoComboBox->addItem(tr("None"));
+ ui_->sAlgoComboBox->addItems(
+ QStringList(s_algo_set.cbegin(), s_algo_set.cend()));
+
+ ui_->easyAlgoComboBox->setCurrentText("RSA");
+ ui_->easyValidityPeriodComboBox->setCurrentText(tr("2 Years"));
+
+ set_signal_slot_config();
+
+ slot_easy_mode_changed("RSA");
+ slot_easy_valid_date_changed(tr("2 Years"));
+
+ this->setWindowTitle(tr("Generate Key"));
+ this->setAttribute(Qt::WA_DeleteOnClose);
+ this->setModal(true);
+}
+
+void KeyGenerateDialog::slot_key_gen_accept() {
+ QString buffer;
+ QTextStream err_stream(&buffer);
+
+ if (ui_->nameEdit->text().size() < 5) {
+ err_stream << " -> " << tr("Name must contain at least five characters.")
+ << Qt::endl;
+ }
+ if (ui_->emailEdit->text().isEmpty() ||
+ !check_email_address(ui_->emailEdit->text())) {
+ 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 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();
+ ui_->statusPlainTextEdit->appendPlainText(err_string);
+ return;
+ }
+
+ gen_key_info_->SetName(ui_->nameEdit->text());
+ gen_key_info_->SetEmail(ui_->emailEdit->text());
+ gen_key_info_->SetComment(ui_->commentEdit->text());
+
+ LOG_D() << "try to generate key at gpg context channel: " << channel_;
+
+ do_generate();
+ this->done(0);
+}
+
+void KeyGenerateDialog::refresh_widgets_state() {
+ ui_->pAlgoComboBox->blockSignals(true);
+ ui_->pAlgoComboBox->setCurrentText(gen_key_info_->GetAlgo().Name());
+ ui_->pAlgoComboBox->blockSignals(false);
+
+ ui_->pKeyLengthComboBox->blockSignals(true);
+ SetKeyLengthComboxBoxByAlgo(
+ ui_->pKeyLengthComboBox,
+ SearchAlgoByName(ui_->pAlgoComboBox->currentText(),
+ supported_primary_key_algos_));
+ ui_->pKeyLengthComboBox->setCurrentText(
+ QString::number(gen_key_info_->GetKeyLength()));
+ ui_->pKeyLengthComboBox->blockSignals(false);
+
+ ui_->pEncrCheckBox->blockSignals(true);
+ ui_->pEncrCheckBox->setCheckState(
+ gen_key_info_->IsAllowEncr() ? Qt::Checked : Qt::Unchecked);
+ ui_->pEncrCheckBox->setEnabled(gen_key_info_->IsAllowModifyEncr());
+ ui_->pEncrCheckBox->blockSignals(false);
+
+ ui_->pSignCheckBox->blockSignals(true);
+ ui_->pSignCheckBox->setCheckState(
+ gen_key_info_->IsAllowSign() ? Qt::Checked : Qt::Unchecked);
+ ui_->pSignCheckBox->setEnabled(gen_key_info_->IsAllowModifySign());
+ ui_->pSignCheckBox->blockSignals(false);
+
+ ui_->pAuthCheckBox->blockSignals(true);
+ ui_->pAuthCheckBox->setCheckState(
+ gen_key_info_->IsAllowAuth() ? Qt::Checked : Qt::Unchecked);
+ ui_->pAuthCheckBox->setEnabled(gen_key_info_->IsAllowModifyAuth());
+ ui_->pAuthCheckBox->blockSignals(false);
+
+ ui_->noPassphraseCheckBox->setEnabled(gen_key_info_->IsAllowNoPassPhrase());
+
+ 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());
+ ui_->pExpireCheckBox->blockSignals(false);
+
+ ui_->generateButton->setDisabled(false);
+
+ if (gen_subkey_info_ == nullptr) {
+ ui_->sTab->setDisabled(true);
+
+ ui_->sAlgoComboBox->blockSignals(true);
+ ui_->sAlgoComboBox->setCurrentText(tr("None"));
+ ui_->sAlgoComboBox->blockSignals(false);
+
+ ui_->sKeyLengthComboBox->blockSignals(true);
+ ui_->sKeyLengthComboBox->clear();
+ ui_->sKeyLengthComboBox->blockSignals(false);
+
+ ui_->sEncrCheckBox->blockSignals(true);
+ ui_->sEncrCheckBox->setCheckState(Qt::Unchecked);
+ ui_->sEncrCheckBox->blockSignals(false);
+
+ ui_->sSignCheckBox->blockSignals(true);
+ ui_->sSignCheckBox->setCheckState(Qt::Unchecked);
+ ui_->sSignCheckBox->blockSignals(false);
+
+ ui_->sAuthCheckBox->blockSignals(true);
+ ui_->sAuthCheckBox->setCheckState(Qt::Unchecked);
+ ui_->sAuthCheckBox->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);
+ ui_->sExpireCheckBox->blockSignals(false);
+
+ ui_->easyCombinationComboBox->blockSignals(true);
+ ui_->easyCombinationComboBox->setCurrentText(tr("Primary Key Only"));
+ ui_->easyCombinationComboBox->blockSignals(false);
+ return;
+ }
+
+ ui_->sTab->setDisabled(false);
+
+ ui_->sAlgoComboBox->blockSignals(true);
+ ui_->sAlgoComboBox->setCurrentText(gen_subkey_info_->GetAlgo().Name());
+ ui_->sAlgoComboBox->blockSignals(false);
+
+ ui_->sKeyLengthComboBox->blockSignals(true);
+ SetKeyLengthComboxBoxByAlgo(
+ ui_->sKeyLengthComboBox,
+ SearchAlgoByName(ui_->sAlgoComboBox->currentText(),
+ supported_subkey_algos_));
+ ui_->sKeyLengthComboBox->setCurrentText(
+ QString::number(gen_subkey_info_->GetKeyLength()));
+ ui_->sKeyLengthComboBox->blockSignals(false);
+
+ ui_->sEncrCheckBox->blockSignals(true);
+ ui_->sEncrCheckBox->setCheckState(
+ gen_subkey_info_->IsAllowEncr() ? Qt::Checked : Qt::Unchecked);
+ ui_->sEncrCheckBox->setEnabled(gen_subkey_info_->IsAllowModifyEncr());
+ ui_->sEncrCheckBox->blockSignals(false);
+
+ ui_->sSignCheckBox->blockSignals(true);
+ ui_->sSignCheckBox->setCheckState(
+ gen_subkey_info_->IsAllowSign() ? Qt::Checked : Qt::Unchecked);
+ ui_->sSignCheckBox->setEnabled(gen_subkey_info_->IsAllowModifySign());
+ ui_->sSignCheckBox->blockSignals(false);
+
+ ui_->sAuthCheckBox->blockSignals(true);
+ ui_->sAuthCheckBox->setCheckState(
+ gen_subkey_info_->IsAllowAuth() ? Qt::Checked : Qt::Unchecked);
+ ui_->sAuthCheckBox->setEnabled(gen_subkey_info_->IsAllowModifyAuth());
+ ui_->sAuthCheckBox->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());
+ ui_->sExpireCheckBox->blockSignals(false);
+
+ ui_->easyCombinationComboBox->blockSignals(true);
+ ui_->easyCombinationComboBox->setCurrentText(tr("Primary Key With Subkey"));
+ ui_->easyCombinationComboBox->blockSignals(false);
+}
+
+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) {
+ 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) {
+ 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,
+ [this](int state) { gen_key_info_->SetAllowEncr(state == Qt::Checked); });
+ connect(
+ ui_->pSignCheckBox, &QCheckBox::stateChanged, this,
+ [this](int state) { gen_key_info_->SetAllowSign(state == Qt::Checked); });
+ connect(
+ ui_->pAuthCheckBox, &QCheckBox::stateChanged, this,
+ [this](int state) { gen_key_info_->SetAllowAuth(state == Qt::Checked); });
+
+ connect(ui_->sEncrCheckBox, &QCheckBox::stateChanged, this,
+ [this](int state) {
+ gen_subkey_info_->SetAllowEncr(state == Qt::Checked);
+ });
+ connect(ui_->sSignCheckBox, &QCheckBox::stateChanged, this,
+ [this](int state) {
+ gen_subkey_info_->SetAllowSign(state == Qt::Checked);
+ });
+ connect(ui_->sAuthCheckBox, &QCheckBox::stateChanged, this,
+ [this](int state) {
+ gen_subkey_info_->SetAllowAuth(state == Qt::Checked);
+ });
+
+ connect(ui_->noPassphraseCheckBox, &QCheckBox::stateChanged, this,
+ [this](int state) -> void {
+ gen_key_info_->SetNonPassPhrase(state != 0);
+ if (gen_subkey_info_ != nullptr) {
+ gen_subkey_info_->SetNonPassPhrase(state != 0);
+ }
+ });
+
+ connect(ui_->pAlgoComboBox, &QComboBox::currentTextChanged, this,
+ [=](const QString&) {
+ 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_algo_info();
+ slot_set_easy_key_algo_2_custom();
+ refresh_widgets_state();
+ });
+
+ connect(ui_->easyAlgoComboBox, &QComboBox::currentTextChanged, this,
+ &KeyGenerateDialog::slot_easy_mode_changed);
+
+ connect(ui_->easyValidityPeriodComboBox, &QComboBox::currentTextChanged, this,
+ &KeyGenerateDialog::slot_easy_valid_date_changed);
+
+ connect(ui_->pExpireDateTimeEdit, &QDateTimeEdit::dateTimeChanged, this,
+ [=](const QDateTime& dt) {
+ gen_key_info_->SetExpireTime(dt);
+
+ slot_set_easy_valid_date_2_custom();
+ });
+
+ connect(ui_->sExpireDateTimeEdit, &QDateTimeEdit::dateTimeChanged, this,
+ [=](const QDateTime& dt) {
+ gen_subkey_info_->SetExpireTime(dt);
+
+ slot_set_easy_valid_date_2_custom();
+ });
+
+ connect(ui_->keyDBIndexComboBox, &QComboBox::currentIndexChanged, this,
+ [=](int index) { channel_ = index; });
+
+ 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);
+}
+
+auto KeyGenerateDialog::check_email_address(const QString& str) -> bool {
+ return re_email_.match(str).hasMatch();
+}
+
+void KeyGenerateDialog::sync_gen_key_algo_info() {
+ auto [found, algo] = GetAlgoByName(ui_->pAlgoComboBox->currentText(),
+
+ supported_primary_key_algos_);
+
+ if (found) gen_key_info_->SetAlgo(found ? algo : KeyGenerateInfo::kNoneAlgo);
+}
+
+void KeyGenerateDialog::sync_gen_subkey_algo_info() {
+ if (gen_subkey_info_ != nullptr) {
+ auto [s_found, algo] = GetAlgoByName(ui_->sAlgoComboBox->currentText(),
+ supported_subkey_algos_);
+
+ if (s_found) {
+ gen_subkey_info_->SetAlgo(s_found ? algo : KeyGenerateInfo::kNoneAlgo);
+ }
+ }
+}
+
+void KeyGenerateDialog::slot_easy_mode_changed(const QString& mode) {
+ if (mode == "RSA") {
+ auto [found, algo] = KeyGenerateInfo::SearchPrimaryKeyAlgo("rsa2048");
+ if (found) gen_key_info_->SetAlgo(algo);
+
+ gen_subkey_info_ = nullptr;
+ }
+
+ else if (mode == "DSA") {
+ auto [found, algo] = KeyGenerateInfo::SearchPrimaryKeyAlgo("dsa2048");
+ if (found) gen_key_info_->SetAlgo(algo);
+
+ if (gen_subkey_info_ == nullptr) {
+ create_sync_gen_subkey_info();
+ }
+
+ 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] = KeyGenerateInfo::SearchPrimaryKeyAlgo("ed25519");
+ if (found) gen_key_info_->SetAlgo(algo);
+
+ if (gen_subkey_info_ == nullptr) {
+ create_sync_gen_subkey_info();
+ }
+
+ auto [s_found, s_algo] = KeyGenerateInfo::SearchSubKeyAlgo("cv25519");
+ if (s_found) gen_subkey_info_->SetAlgo(s_algo);
+ }
+
+ else {
+ auto [found, algo] = KeyGenerateInfo::SearchPrimaryKeyAlgo("rsa2048");
+ if (found) gen_key_info_->SetAlgo(algo);
+
+ if (gen_subkey_info_ == nullptr) {
+ create_sync_gen_subkey_info();
+ }
+
+ auto [s_found, s_algo] = KeyGenerateInfo::SearchSubKeyAlgo("rsa2048");
+ if (s_found) gen_subkey_info_->SetAlgo(s_algo);
+ }
+
+ refresh_widgets_state();
+}
+
+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));
+ }
+
+ else if (mode == tr("6 Months")) {
+ gen_key_info_->SetNonExpired(false);
+ gen_key_info_->SetExpireTime(QDateTime::currentDateTime().addMonths(6));
+ }
+
+ else if (mode == tr("1 Year")) {
+ gen_key_info_->SetNonExpired(false);
+ gen_key_info_->SetExpireTime(QDateTime::currentDateTime().addYears(1));
+ }
+
+ else if (mode == tr("2 Years")) {
+ gen_key_info_->SetNonExpired(false);
+ gen_key_info_->SetExpireTime(QDateTime::currentDateTime().addYears(2));
+ }
+
+ else if (mode == tr("5 Years")) {
+ gen_key_info_->SetNonExpired(false);
+ gen_key_info_->SetExpireTime(QDateTime::currentDateTime().addYears(5));
+ }
+
+ else if (mode == tr("10 Years")) {
+ gen_key_info_->SetNonExpired(false);
+ gen_key_info_->SetExpireTime(QDateTime::currentDateTime().addYears(10));
+
+ }
+
+ else if (mode == tr("Non Expired")) {
+ gen_key_info_->SetNonExpired(true);
+ gen_key_info_->SetExpireTime(QDateTime::currentDateTime());
+ }
+
+ else {
+ gen_key_info_->SetNonExpired(false);
+ gen_key_info_->SetExpireTime(QDateTime::currentDateTime().addYears(2));
+ }
+
+ if (gen_subkey_info_ != nullptr) {
+ gen_subkey_info_->SetNonExpired(gen_key_info_->IsNonExpired());
+ gen_subkey_info_->SetExpireTime(gen_key_info_->GetExpireTime());
+ }
+
+ refresh_widgets_state();
+}
+
+void KeyGenerateDialog::slot_set_easy_valid_date_2_custom() {
+ ui_->easyValidityPeriodComboBox->blockSignals(true);
+ ui_->easyValidityPeriodComboBox->setCurrentText(tr("Custom"));
+ ui_->easyValidityPeriodComboBox->blockSignals(false);
+}
+
+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 {
+ create_sync_gen_subkey_info();
+ }
+
+ 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);
+}
+
+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/KeygenDialog.h b/src/ui/dialog/key_generate/KeyGenerateDialog.h
index 8b9757d5..ad927446 100644
--- a/src/ui/dialog/key_generate/KeygenDialog.h
+++ b/src/ui/dialog/key_generate/KeyGenerateDialog.h
@@ -28,20 +28,18 @@
#pragma once
-#include <memory>
-
-#include "core/model/GpgGenKeyInfo.h"
-#include "core/utils/MemoryUtils.h"
-#include "ui/GpgFrontendUI.h"
+#include "core/model/GpgKeyGenerateInfo.h"
#include "ui/dialog/GeneralDialog.h"
+class Ui_KeyGenDialog;
+
namespace GpgFrontend::UI {
/**
* @brief
*
*/
-class KeyGenDialog : public GeneralDialog {
+class KeyGenerateDialog : public GeneralDialog {
Q_OBJECT
public:
@@ -52,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:
/**
@@ -61,131 +59,114 @@ class KeyGenDialog : public GeneralDialog {
*/
void SignalKeyGenerated();
- private:
+ private slots:
+
/**
- * @brief Create a key usage group box object
- *
- * @return QGroupBox*
+ * @details check all lineedits for false entries. Show error, when there
+ * is one, otherwise generate the key
*/
- QGroupBox* create_key_usage_group_box();
+ void slot_key_gen_accept();
/**
- * @brief Create a basic info group box object
+ * @brief
*
- * @return QGroupBox*
+ * @param mode
*/
- QGroupBox* create_basic_info_group_box();
+ void slot_easy_mode_changed(const QString& mode);
/**
* @brief
*
+ * @param mode
*/
- QRegularExpression re_email_{
- R"((?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9]))\.){3}(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9])|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\]))"};
+ void slot_easy_valid_date_changed(const QString& mode);
/**
* @brief
*
*/
- QStringList error_messages_; ///< List of errors occurring when checking
- ///< entries of line edits
-
- std::shared_ptr<GenKeyInfo> gen_key_info_ =
- SecureCreateSharedObject<GenKeyInfo>(); ///<
- std::shared_ptr<GenKeyInfo> gen_subkey_info_ = nullptr; ///<
-
- QDialogButtonBox* button_box_; ///< Box for standard buttons
- QLabel* error_label_{}; ///< Label containing error message
- QLineEdit* name_edit_{}; ///< Line edit for the keys name
- QLineEdit* email_edit_{}; ///< Line edit for the keys email
- QLineEdit* comment_edit_{}; ///< Line edit for the keys comment
- QSpinBox* key_size_spin_box_{}; ///< Spinbox for the keys size (in bit)
- QComboBox* key_type_combo_box_{}; ///< Combobox for Key type
- QDateTimeEdit* date_edit_{}; ///< Date edit for expiration date
- QCheckBox* expire_check_box_{}; ///< Checkbox, if key should expire
- QCheckBox* no_pass_phrase_check_box_{};
- QGroupBox* key_usage_group_box_{}; ///< Group of Widgets detecting the usage
- ///< of the Key
- QDateTime max_date_time_; ///<
- std::vector<QCheckBox*> key_usage_check_boxes_; ///< ENCR, SIGN, CERT, AUTH
- QComboBox* gpg_contexts_combo_box_{};
-
- int default_gpg_context_channel_;
+ void slot_set_easy_valid_date_2_custom();
/**
* @brief
*
*/
- void generate_key_dialog();
+ void slot_set_easy_key_algo_2_custom();
/**
- * @details Refresh widgets state by GenKeyInfo
+ * @brief
+ *
+ * @param mode
*/
- void refresh_widgets_state();
+ void slot_easy_combination_changed(const QString& mode);
+ private:
/**
- * @brief Set the signal slot object
+ * @brief
*
*/
- void set_signal_slot();
+ QRegularExpression re_email_{
+ R"((?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9]))\.){3}(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9])|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\]))"};
/**
* @brief
*
- * @param str
- * @return true
- * @return false
*/
- bool check_email_address(const QString& str);
+ QStringList error_messages_; ///< List of errors occurring when checking
+ ///< entries of line edits
- private slots:
+ QSharedPointer<Ui_KeyGenDialog> ui_;
+ QSharedPointer<KeyGenerateInfo> gen_key_info_; ///<
+ QSharedPointer<KeyGenerateInfo> gen_subkey_info_; ///<
+
+ QContainer<KeyAlgo> supported_primary_key_algos_;
+ QContainer<KeyAlgo> supported_subkey_algos_;
+
+ int channel_;
/**
- * @details when expirebox was checked/unchecked, enable/disable the
- * expiration date box
+ * @details Refresh widgets state by GenKeyInfo
*/
- void slot_expire_box_changed();
+ void refresh_widgets_state();
/**
- * @details check all lineedits for false entries. Show error, when there is
- * one, otherwise generate the key
+ * @brief Set the signal slot object
+ *
*/
- void slot_key_gen_accept();
+ void set_signal_slot_config();
/**
* @brief
*
- * @param state
+ * @param str
+ * @return true
+ * @return false
*/
- void slot_encryption_box_changed(int state);
+ auto check_email_address(const QString& str) -> bool;
/**
* @brief
*
- * @param state
*/
- void slot_signing_box_changed(int state);
+ void sync_gen_key_algo_info();
/**
* @brief
*
- * @param state
*/
- void slot_certification_box_changed(int state);
+ void sync_gen_subkey_algo_info();
/**
* @brief
*
- * @param state
*/
- void slot_authentication_box_changed(int state);
+ void create_sync_gen_subkey_info();
/**
* @brief
*
- * @param index
*/
- void slot_activated_key_type(int index);
+ void do_generate();
};
} // namespace GpgFrontend::UI
diff --git a/src/ui/dialog/key_generate/KeygenDialog.cpp b/src/ui/dialog/key_generate/KeygenDialog.cpp
deleted file mode 100644
index e29f6b64..00000000
--- a/src/ui/dialog/key_generate/KeygenDialog.cpp
+++ /dev/null
@@ -1,482 +0,0 @@
-/**
- * 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 "KeygenDialog.h"
-
-#include "core/GpgModel.h"
-#include "core/function/GlobalSettingStation.h"
-#include "core/function/gpg/GpgKeyOpera.h"
-#include "core/model/DataObject.h"
-#include "core/module/ModuleManager.h"
-#include "core/typedef/GpgTypedef.h"
-#include "core/utils/CacheUtils.h"
-#include "core/utils/GpgUtils.h"
-#include "ui/UISignalStation.h"
-#include "ui/UserInterfaceUtils.h"
-
-namespace GpgFrontend::UI {
-
-KeyGenDialog::KeyGenDialog(int channel, QWidget* parent)
- : GeneralDialog(typeid(KeyGenDialog).name(), parent),
- default_gpg_context_channel_(channel) {
- button_box_ =
- new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
-
- bool const longer_expiration_date =
- GlobalSettingStation::GetInstance()
- .GetSettings()
- .value("basic/longer_expiration_date", false)
- .toBool();
-
- max_date_time_ = longer_expiration_date
- ? QDateTime::currentDateTime().toLocalTime().addYears(30)
- : QDateTime::currentDateTime().toLocalTime().addYears(2);
-
- connect(this, &KeyGenDialog::SignalKeyGenerated,
- UISignalStation::GetInstance(),
- &UISignalStation::SignalKeyDatabaseRefresh);
-
- generate_key_dialog();
-
- this->setWindowTitle(tr("Generate Key"));
- this->setAttribute(Qt::WA_DeleteOnClose);
- this->setModal(true);
-}
-
-void KeyGenDialog::generate_key_dialog() {
- 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);
-
- auto* name_list = new QWidget(this);
- name_list->setLayout(group_grid);
-
- auto* vbox2 = new QVBoxLayout();
- vbox2->addWidget(name_list);
- vbox2->addWidget(error_label_);
- vbox2->addWidget(button_box_);
-
- this->setLayout(vbox2);
-
- set_signal_slot();
- refresh_widgets_state();
-}
-
-void KeyGenDialog::slot_key_gen_accept() {
- QString buffer;
- QTextStream error_stream(&buffer);
-
- /**
- * check for errors in keygen dialog input
- */
- if ((name_edit_->text()).size() < 5) {
- error_stream << " " << tr("Name must contain at least five characters.")
- << '\n';
- }
- if (email_edit_->text().isEmpty() ||
- !check_email_address(email_edit_->text())) {
- error_stream << " " << tr("Please give a email address.") << '\n';
- }
-
- /**
- * primary keys should have a reasonable expiration date (no more than 2 years
- * in the future)
- */
- if (date_edit_->dateTime() > max_date_time_) {
- error_stream << " " << tr("Expiration time too long.") << '\n';
- }
-
- auto err_string = error_stream.readAll();
- if (err_string.isEmpty()) {
- /**
- * create the string for key generation
- */
- gen_key_info_->SetName(name_edit_->text());
- gen_key_info_->SetEmail(email_edit_->text());
- gen_key_info_->SetComment(comment_edit_->text());
-
- gen_key_info_->SetKeyLength(key_size_spin_box_->value());
-
- if (no_pass_phrase_check_box_->checkState() != 0U) {
- gen_key_info_->SetNonPassPhrase(true);
- if (gen_subkey_info_ != nullptr) {
- gen_subkey_info_->SetNonPassPhrase(true);
- }
- }
-
- if (expire_check_box_->checkState() != 0U) {
- gen_key_info_->SetNonExpired(true);
- if (gen_subkey_info_ != nullptr) gen_subkey_info_->SetNonExpired(true);
- } else {
- gen_key_info_->SetExpireTime(date_edit_->dateTime());
- if (gen_subkey_info_ != nullptr) {
- gen_subkey_info_->SetExpireTime(date_edit_->dateTime());
- }
- }
-
- if (!GlobalSettingStation::GetInstance()
- .GetSettings()
- .value("gnupg/use_pinentry_as_password_input_dialog",
- QString::fromLocal8Bit(qgetenv("container")) != "flatpak")
- .toBool() &&
- !no_pass_phrase_check_box_->isChecked()) {
- SetCacheValue("PinentryContext", "NEW_PASSPHRASE");
- }
-
- auto selected_gpg_context_channel = gpg_contexts_combo_box_->currentIndex();
- LOG_D() << "try to generate key at gpg context channel: "
- << selected_gpg_context_channel;
-
- CommonUtils::WaitForOpera(
- this, tr("Generating"),
- [this, gen_key_info = this->gen_key_info_,
- selected_gpg_context_channel](const OperaWaitingHd& hd) {
- GpgKeyOpera::GetInstance(selected_gpg_context_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();
- }
- });
- });
-
- this->done(0);
-
- } 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();
- }
-}
-
-void KeyGenDialog::slot_expire_box_changed() {}
-
-auto KeyGenDialog::create_key_usage_group_box() -> QGroupBox* {
- 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;
-}
-
-void KeyGenDialog::slot_encryption_box_changed(int state) {
- if (state == 0) {
- gen_key_info_->SetAllowEncryption(false);
- } else {
- gen_key_info_->SetAllowEncryption(true);
- }
-}
-
-void KeyGenDialog::slot_signing_box_changed(int state) {
- if (state == 0) {
- gen_key_info_->SetAllowSigning(false);
- } else {
- gen_key_info_->SetAllowSigning(true);
- }
-}
-
-void KeyGenDialog::slot_certification_box_changed(int state) {
- if (state == 0) {
- gen_key_info_->SetAllowCertification(false);
- } else {
- gen_key_info_->SetAllowCertification(true);
- }
-}
-
-void KeyGenDialog::slot_authentication_box_changed(int state) {
- if (state == 0) {
- gen_key_info_->SetAllowAuthentication(false);
- } else {
- gen_key_info_->SetAllowAuthentication(true);
- }
-}
-
-void KeyGenDialog::slot_activated_key_type(int index) {
- // check
- assert(gen_key_info_->GetSupportedKeyAlgo().size() >
- static_cast<size_t>(index));
-
- const auto [name, key_algo, subkey_algo] =
- gen_key_info_->GetSupportedKeyAlgo()[index];
-
- assert(!key_algo.isEmpty());
- gen_key_info_->SetAlgo(key_algo);
-
- if (!subkey_algo.isEmpty()) {
- if (gen_subkey_info_ == nullptr) {
- gen_subkey_info_ = SecureCreateSharedObject<GenKeyInfo>(true);
- }
- gen_subkey_info_->SetAlgo(subkey_algo);
- } else {
- gen_subkey_info_ = nullptr;
- }
-
- refresh_widgets_state();
-}
-
-void KeyGenDialog::refresh_widgets_state() {
- if (gen_key_info_->IsAllowEncryption() ||
- (gen_subkey_info_ != nullptr && 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() ||
- (gen_subkey_info_ != nullptr &&
- gen_subkey_info_->IsAllowChangeEncryption())) {
- key_usage_check_boxes_[0]->setDisabled(false);
- } else {
- key_usage_check_boxes_[0]->setDisabled(true);
- }
-
- if (gen_key_info_->IsAllowSigning() ||
- (gen_subkey_info_ != nullptr && 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() ||
- (gen_subkey_info_ != nullptr &&
- gen_subkey_info_->IsAllowChangeSigning())) {
- key_usage_check_boxes_[1]->setDisabled(false);
- } else {
- key_usage_check_boxes_[1]->setDisabled(true);
- }
-
- if (gen_key_info_->IsAllowCertification() ||
- (gen_subkey_info_ != nullptr &&
- 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() ||
- (gen_subkey_info_ != nullptr &&
- gen_subkey_info_->IsAllowChangeCertification())) {
- key_usage_check_boxes_[2]->setDisabled(false);
- } else {
- key_usage_check_boxes_[2]->setDisabled(true);
- }
-
- if (gen_key_info_->IsAllowAuthentication() ||
- (gen_subkey_info_ != nullptr &&
- 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() ||
- (gen_subkey_info_ != nullptr &&
- gen_subkey_info_->IsAllowChangeAuthentication())) {
- key_usage_check_boxes_[3]->setDisabled(false);
- } else {
- key_usage_check_boxes_[3]->setDisabled(true);
- }
-
- if (gen_key_info_->IsAllowNoPassPhrase()) {
- no_pass_phrase_check_box_->setDisabled(false);
- } else {
- no_pass_phrase_check_box_->setDisabled(true);
- }
-
- if (gen_key_info_->GetSuggestMinKeySize() == -1 ||
- gen_key_info_->GetSuggestMaxKeySize() == -1) {
- key_size_spin_box_->setDisabled(true);
- key_size_spin_box_->setRange(0, 0);
- key_size_spin_box_->setValue(0);
- key_size_spin_box_->setSingleStep(0);
- } else {
- key_size_spin_box_->setDisabled(false);
- key_size_spin_box_->setRange(gen_key_info_->GetSuggestMinKeySize(),
- gen_key_info_->GetSuggestMaxKeySize());
- key_size_spin_box_->setValue(gen_key_info_->GetKeyLength());
- key_size_spin_box_->setSingleStep(gen_key_info_->GetSizeChangeStep());
- }
-}
-
-void KeyGenDialog::set_signal_slot() {
- connect(button_box_, &QDialogButtonBox::accepted, this,
- &KeyGenDialog::slot_key_gen_accept);
- connect(button_box_, &QDialogButtonBox::rejected, this,
- &KeyGenDialog::reject);
-
- connect(expire_check_box_, &QCheckBox::stateChanged, this, [this]() {
- date_edit_->setDisabled(expire_check_box_->checkState() != 0U);
- });
-
- connect(key_usage_check_boxes_[0], &QCheckBox::stateChanged, this,
- &KeyGenDialog::slot_encryption_box_changed);
- connect(key_usage_check_boxes_[1], &QCheckBox::stateChanged, this,
- &KeyGenDialog::slot_signing_box_changed);
- connect(key_usage_check_boxes_[2], &QCheckBox::stateChanged, this,
- &KeyGenDialog::slot_certification_box_changed);
- connect(key_usage_check_boxes_[3], &QCheckBox::stateChanged, this,
- &KeyGenDialog::slot_authentication_box_changed);
-
- connect(key_type_combo_box_, qOverload<int>(&QComboBox::currentIndexChanged),
- this, &KeyGenDialog::slot_activated_key_type);
-
- connect(no_pass_phrase_check_box_, &QCheckBox::stateChanged, this,
- [this](int state) -> void {
- gen_key_info_->SetNonPassPhrase(state != 0);
- if (gen_subkey_info_ != nullptr) {
- gen_subkey_info_->SetNonPassPhrase(state != 0);
- }
- });
-}
-
-auto KeyGenDialog::check_email_address(const QString& str) -> bool {
- return re_email_.match(str).hasMatch();
-}
-
-auto KeyGenDialog::create_basic_info_group_box() -> QGroupBox* {
- error_label_ = new QLabel();
- name_edit_ = new QLineEdit(this);
- email_edit_ = new QLineEdit(this);
- comment_edit_ = new QLineEdit(this);
- key_size_spin_box_ = new QSpinBox(this);
- key_type_combo_box_ = new QComboBox(this);
- gpg_contexts_combo_box_ = new QComboBox(this);
-
- auto gpg_context_index_list =
- Module::ListRTChildKeys("core", "gpgme.ctx.list");
-
- for (auto& context_index : gpg_context_index_list) {
- const auto grt_key_prefix = QString("gpgme.ctx.list.%1").arg(context_index);
- auto channel = Module::RetrieveRTValueTypedOrDefault(
- "core", grt_key_prefix + ".channel", -1);
- auto database_name = Module::RetrieveRTValueTypedOrDefault(
- "core", grt_key_prefix + ".database_name", QString{});
- gpg_contexts_combo_box_->addItem(
- QString("%1: %2").arg(channel).arg(database_name));
- }
- gpg_contexts_combo_box_->setCurrentIndex(default_gpg_context_channel_);
-
- for (const auto& algo : GenKeyInfo::GetSupportedKeyAlgo()) {
- key_type_combo_box_->addItem(std::get<0>(algo));
- }
- if (!GenKeyInfo::GetSupportedKeyAlgo().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);
-
- no_pass_phrase_check_box_ = new QCheckBox(this);
- no_pass_phrase_check_box_->setCheckState(Qt::Unchecked);
-
- auto* vbox1 = new QGridLayout;
-
- vbox1->addWidget(new QLabel(tr("Key Database") + ": "), 0, 0);
- vbox1->addWidget(new QLabel(tr("Name") + ": "), 1, 0);
- vbox1->addWidget(new QLabel(tr("Email Address") + ": "), 2, 0);
- vbox1->addWidget(new QLabel(tr("Comment") + ": "), 3, 0);
- vbox1->addWidget(new QLabel(tr("Expiration Date") + ": "), 4, 0);
- vbox1->addWidget(new QLabel(tr("Never Expire") + ": "), 4, 3);
- vbox1->addWidget(new QLabel(tr("KeySize (in Bit)") + ": "), 5, 0);
- vbox1->addWidget(new QLabel(tr("Key Type") + ": "), 6, 0);
- vbox1->addWidget(new QLabel(tr("Non Pass Phrase")), 7, 0);
-
- vbox1->addWidget(gpg_contexts_combo_box_, 0, 1, 1, 3);
- vbox1->addWidget(name_edit_, 1, 1, 1, 3);
- vbox1->addWidget(email_edit_, 2, 1, 1, 3);
- vbox1->addWidget(comment_edit_, 3, 1, 1, 3);
- vbox1->addWidget(date_edit_, 4, 1);
- vbox1->addWidget(expire_check_box_, 4, 2);
- vbox1->addWidget(key_size_spin_box_, 5, 1);
- vbox1->addWidget(key_type_combo_box_, 6, 1);
- vbox1->addWidget(no_pass_phrase_check_box_, 7, 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;
-}
-
-} // namespace GpgFrontend::UI
diff --git a/src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp b/src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp
index dd88aac2..58734c7d 100644
--- a/src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp
+++ b/src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp
@@ -31,345 +31,200 @@
#include <cassert>
#include <cstddef>
-#include "core/function/GlobalSettingStation.h"
#include "core/function/gpg/GpgKeyGetter.h"
#include "core/function/gpg/GpgKeyOpera.h"
-#include "core/utils/CacheUtils.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 =
- GlobalSettingStation::GetInstance()
- .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);
+ 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_->nonExpiredCheckBox->setText(tr("Non Expired"));
+ ui_->nonPassphraseCheckBox->setText(tr("No Passphrase"));
- key_usage_group_box_ = create_key_usage_group_box();
+ const auto min_date_time = QDateTime::currentDateTime().addDays(3);
+ ui_->expireDateTimeEdit->setMinimumDateTime(min_date_time);
- 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);
-
- 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 : GenKeyInfo::GetSupportedSubkeyAlgo()) {
- key_type_combo_box_->addItem(std::get<0>(algo));
- }
- if (!GenKeyInfo::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_->SetAllowEncr(state == Qt::Checked);
+ });
+ connect(ui_->signCheckBox, &QCheckBox::stateChanged, this, [this](int state) {
+ gen_subkey_info_->SetAllowSign(state == Qt::Checked);
+ });
+ connect(ui_->authCheckBox, &QCheckBox::stateChanged, this, [this](int state) {
+ gen_subkey_info_->SetAllowAuth(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_key_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_key_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()) {
- key_usage_check_boxes_[0]->setDisabled(false);
- } else {
- key_usage_check_boxes_[0]->setDisabled(true);
- }
-
- if (gen_key_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()) {
- key_usage_check_boxes_[1]->setDisabled(false);
- } else {
- key_usage_check_boxes_[1]->setDisabled(true);
- }
-
- if (gen_key_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()) {
- key_usage_check_boxes_[2]->setDisabled(false);
- } else {
- key_usage_check_boxes_[2]->setDisabled(true);
- }
-
- if (gen_key_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()) {
- key_usage_check_boxes_[3]->setDisabled(false);
- } else {
- key_usage_check_boxes_[3]->setDisabled(true);
- }
-
- if (gen_key_info_->GetSuggestMinKeySize() == -1 ||
- gen_key_info_->GetSuggestMaxKeySize() == -1) {
- key_size_spin_box_->setDisabled(true);
- key_size_spin_box_->setRange(0, 0);
- key_size_spin_box_->setValue(0);
- key_size_spin_box_->setSingleStep(0);
- } else {
- key_size_spin_box_->setDisabled(false);
- key_size_spin_box_->setRange(gen_key_info_->GetSuggestMinKeySize(),
- gen_key_info_->GetSuggestMaxKeySize());
- key_size_spin_box_->setValue(gen_key_info_->GetKeyLength());
- key_size_spin_box_->setSingleStep(gen_key_info_->GetSizeChangeStep());
- }
+ 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_->IsAllowEncr());
+ ui_->encrCheckBox->setEnabled(gen_subkey_info_->IsAllowModifyEncr());
+ ui_->encrCheckBox->blockSignals(false);
+
+ ui_->signCheckBox->blockSignals(true);
+ ui_->signCheckBox->setChecked(gen_subkey_info_->IsAllowSign());
+ ui_->signCheckBox->setEnabled(gen_subkey_info_->IsAllowModifySign());
+ ui_->signCheckBox->blockSignals(false);
+
+ ui_->authCheckBox->blockSignals(true);
+ ui_->authCheckBox->setChecked(gen_subkey_info_->IsAllowAuth());
+ ui_->authCheckBox->setEnabled(gen_subkey_info_->IsAllowModifyAuth());
+ 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);
}
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()) {
- gen_key_info_->SetKeyLength(key_size_spin_box_->value());
-
- if (expire_check_box_->checkState() != 0U) {
- gen_key_info_->SetNonExpired(true);
- } else {
- gen_key_info_->SetExpireTime(date_edit_->dateTime());
- }
-
- CommonUtils::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);
-
- } 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();
- }
-}
-
-void SubkeyGenerateDialog::slot_encryption_box_changed(int state) {
- if (state == 0) {
- gen_key_info_->SetAllowEncryption(false);
- } else {
- gen_key_info_->SetAllowEncryption(true);
- }
-}
-
-void SubkeyGenerateDialog::slot_signing_box_changed(int state) {
- if (state == 0) {
- gen_key_info_->SetAllowSigning(false);
- } else {
- gen_key_info_->SetAllowSigning(true);
- }
-}
-
-void SubkeyGenerateDialog::slot_certification_box_changed(int state) {
- if (state == 0) {
- gen_key_info_->SetAllowCertification(false);
- } else {
- gen_key_info_->SetAllowCertification(true);
- }
-}
-
-void SubkeyGenerateDialog::slot_authentication_box_changed(int state) {
- if (state == 0) {
- gen_key_info_->SetAllowAuthentication(false);
- } else {
- gen_key_info_->SetAllowAuthentication(true);
- }
-}
-
-void SubkeyGenerateDialog::slot_activated_key_type(int index) {
- // check
- assert(gen_key_info_->GetSupportedSubkeyAlgo().size() >
- static_cast<size_t>(index));
- gen_key_info_->SetAlgo(
- std::get<2>(gen_key_info_->GetSupportedSubkeyAlgo()[index]));
- refresh_widgets_state();
+ 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() <
+ QDateTime::currentDateTime().addSecs(120)) {
+ 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();
+ ui_->statusPlainTextEdit->appendPlainText(err_string);
+ return;
+ }
+
+ 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);
}
} // namespace GpgFrontend::UI
diff --git a/src/ui/dialog/key_generate/SubkeyGenerateDialog.h b/src/ui/dialog/key_generate/SubkeyGenerateDialog.h
index f0a4fed6..96dee49e 100644
--- a/src/ui/dialog/key_generate/SubkeyGenerateDialog.h
+++ b/src/ui/dialog/key_generate/SubkeyGenerateDialog.h
@@ -28,16 +28,16 @@
#pragma once
-#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"
#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_; ///<
-
- std::shared_ptr<GenKeyInfo> gen_key_info_ =
- SecureCreateSharedObject<GenKeyInfo>(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
-
- std::vector<QCheckBox*> key_usage_check_boxes_; ///< ENCR, SIGN, CERT, AUTH
- QDateTime max_date_time_; ///<
-
- /**
- * @brief Create a key usage group box object
- *
- * @return QGroupBox*
- */
- QGroupBox* create_key_usage_group_box();
-
- /**
- * @brief Create a basic info group box object
- *
- * @return QGroupBox*
- */
- QGroupBox* create_basic_info_group_box();
- /**
- * @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/dialog/keypair_details/KeyPairDetailTab.cpp b/src/ui/dialog/keypair_details/KeyPairDetailTab.cpp
index 21c16107..88c7fbf5 100644
--- a/src/ui/dialog/keypair_details/KeyPairDetailTab.cpp
+++ b/src/ui/dialog/keypair_details/KeyPairDetailTab.cpp
@@ -215,28 +215,28 @@ void KeyPairDetailTab::slot_refresh_key_info() {
QString buffer;
QTextStream usage_steam(&buffer);
- if (key_.IsHasCertificationCapability()) {
+ if (key_.IsHasCertCap()) {
usage_steam << tr("Certificate") << " ";
}
- if (key_.IsHasEncryptionCapability()) usage_steam << tr("Encrypt") << " ";
- if (key_.IsHasSigningCapability()) usage_steam << tr("Sign") << " ";
- if (key_.IsHasAuthenticationCapability()) usage_steam << tr("Auth") << " ";
+ if (key_.IsHasEncrCap()) usage_steam << tr("Encrypt") << " ";
+ if (key_.IsHasSignCap()) usage_steam << tr("Sign") << " ";
+ if (key_.IsHasAuthCap()) usage_steam << tr("Auth") << " ";
usage_var_label_->setText(usage_steam.readAll());
QString buffer_2;
QTextStream actual_usage_steam(&buffer_2);
- if (key_.IsHasActualCertificationCapability()) {
+ if (key_.IsHasActualCertCap()) {
actual_usage_steam << tr("Certificate") << " ";
}
- if (key_.IsHasActualEncryptionCapability()) {
+ if (key_.IsHasActualEncrCap()) {
actual_usage_steam << tr("Encrypt") << " ";
}
- if (key_.IsHasActualSigningCapability()) {
+ if (key_.IsHasActualSignCap()) {
actual_usage_steam << tr("Sign") << " ";
}
- if (key_.IsHasActualAuthenticationCapability()) {
+ if (key_.IsHasActualAuthCap()) {
actual_usage_steam << tr("Auth") << " ";
}
@@ -306,16 +306,10 @@ void KeyPairDetailTab::slot_refresh_key() {
void KeyPairDetailTab::slot_query_key_publish_state() {
bool forbid_all_gnupg_connection =
- GlobalSettingStation::GetInstance()
- .GetSettings()
- .value("network/forbid_all_gnupg_connection")
- .toBool();
+ GetSettings().value("network/forbid_all_gnupg_connection").toBool();
bool auto_fetch_key_publish_status =
- GlobalSettingStation::GetInstance()
- .GetSettings()
- .value("network/auto_fetch_key_publish_status")
- .toBool();
+ GetSettings().value("network/auto_fetch_key_publish_status").toBool();
if (forbid_all_gnupg_connection || !auto_fetch_key_publish_status) return;
diff --git a/src/ui/dialog/keypair_details/KeyPairOperaTab.cpp b/src/ui/dialog/keypair_details/KeyPairOperaTab.cpp
index 56103d62..c4f0dad1 100644
--- a/src/ui/dialog/keypair_details/KeyPairOperaTab.cpp
+++ b/src/ui/dialog/keypair_details/KeyPairOperaTab.cpp
@@ -35,7 +35,6 @@
#include "core/function/gpg/GpgKeyOpera.h"
#include "core/model/GpgKey.h"
#include "core/module/ModuleManager.h"
-#include "core/thread/TaskRunnerGetter.h"
#include "core/typedef/GpgTypedef.h"
#include "core/utils/GpgUtils.h"
#include "core/utils/IOUtils.h"
@@ -92,7 +91,7 @@ KeyPairOperaTab::KeyPairOperaTab(int channel, const QString& key_id,
auto* advance_h_box_layout = new QHBoxLayout();
- auto settings = GlobalSettingStation::GetInstance().GetSettings();
+ auto settings = GetSettings();
// read settings
bool forbid_all_gnupg_connection =
@@ -436,8 +435,7 @@ void KeyPairOperaTab::slot_publish_key_to_server() {
return;
}
- auto keys = std::make_unique<KeyIdArgsList>();
- keys->push_back(m_key_.GetId());
+ auto keys = KeyIdArgsList{m_key_.GetId()};
auto* dialog = new KeyUploadDialog(current_gpg_context_channel_, keys, this);
dialog->show();
dialog->SlotUpload();
diff --git a/src/ui/dialog/keypair_details/KeyPairSubkeyTab.cpp b/src/ui/dialog/keypair_details/KeyPairSubkeyTab.cpp
index b37f610f..548b3473 100644
--- a/src/ui/dialog/keypair_details/KeyPairSubkeyTab.cpp
+++ b/src/ui/dialog/keypair_details/KeyPairSubkeyTab.cpp
@@ -205,9 +205,8 @@ void KeyPairSubkeyTab::slot_refresh_subkey_list() {
tmp0->setTextAlignment(Qt::AlignCenter);
subkey_list_->setItem(row, 0, tmp0);
- auto* tmp1 = new QTableWidgetItem(subkey.IsHasCertificationCapability()
- ? tr("Primary Key")
- : tr("Subkey"));
+ auto* tmp1 = new QTableWidgetItem(subkey.IsHasCertCap() ? tr("Primary Key")
+ : tr("Subkey"));
tmp1->setTextAlignment(Qt::AlignCenter);
subkey_list_->setItem(row, 1, tmp1);
@@ -307,12 +306,12 @@ void KeyPairSubkeyTab::slot_refresh_subkey_detail() {
QString buffer;
QTextStream usage_steam(&buffer);
- if (subkey.IsHasCertificationCapability()) {
+ if (subkey.IsHasCertCap()) {
usage_steam << tr("Certificate") << " ";
}
- if (subkey.IsHasEncryptionCapability()) usage_steam << tr("Encrypt") << " ";
- if (subkey.IsHasSigningCapability()) usage_steam << tr("Sign") << " ";
- if (subkey.IsHasAuthenticationCapability()) usage_steam << tr("Auth") << " ";
+ if (subkey.IsHasEncrCap()) usage_steam << tr("Encrypt") << " ";
+ if (subkey.IsHasSignCap()) usage_steam << tr("Sign") << " ";
+ if (subkey.IsHasAuthCap()) usage_steam << tr("Auth") << " ";
usage_var_label_->setText(usage_steam.readAll());
@@ -348,15 +347,13 @@ void KeyPairSubkeyTab::slot_refresh_subkey_detail() {
fingerprint_var_label_->setText(BeautifyFingerprint(subkey.GetFingerprint()));
fingerprint_var_label_->setWordWrap(true); // for x448 and ed448
- export_subkey_button_->setText(subkey.IsHasCertificationCapability()
- ? tr("Export Primary Key")
- : tr("Export Subkey"));
- export_subkey_button_->setDisabled(!key_.IsPrivateKey() ||
- subkey.IsHasCertificationCapability() ||
- !subkey.IsSecretKey());
+ export_subkey_button_->setText(
+ subkey.IsHasCertCap() ? tr("Export Primary Key") : tr("Export Subkey"));
+ export_subkey_button_->setDisabled(
+ !key_.IsPrivateKey() || subkey.IsHasCertCap() || !subkey.IsSecretKey());
- key_type_var_label_->setText(
- subkey.IsHasCertificationCapability() ? tr("Primary Key") : tr("Subkey"));
+ key_type_var_label_->setText(subkey.IsHasCertCap() ? tr("Primary Key")
+ : tr("Subkey"));
revoke_var_label_->setText(subkey.IsRevoked() ? tr("Yes") : tr("No"));
if (!subkey.IsRevoked()) {
@@ -406,7 +403,7 @@ void KeyPairSubkeyTab::contextMenuEvent(QContextMenuEvent* event) {
if (key_.IsHasMasterKey() && !subkey_list_->selectedItems().isEmpty()) {
const auto& subkey = get_selected_subkey();
- if (subkey.IsHasCertificationCapability()) return;
+ if (subkey.IsHasCertCap()) return;
export_subkey_act_->setDisabled(!subkey.IsSecretKey());
edit_subkey_act_->setDisabled(!subkey.IsSecretKey());
diff --git a/src/ui/dialog/keypair_details/KeyPairSubkeyTab.h b/src/ui/dialog/keypair_details/KeyPairSubkeyTab.h
index 9c8daeb9..b4aa9a00 100644
--- a/src/ui/dialog/keypair_details/KeyPairSubkeyTab.h
+++ b/src/ui/dialog/keypair_details/KeyPairSubkeyTab.h
@@ -68,9 +68,9 @@ class KeyPairSubkeyTab : public QWidget {
const GpgSubKey& get_selected_subkey();
int current_gpg_context_channel_;
- GpgKey key_; ///<
- QTableWidget* subkey_list_{}; ///<
- std::vector<GpgSubKey> buffered_subkeys_; ///<
+ GpgKey key_; ///<
+ QTableWidget* subkey_list_{}; ///<
+ QContainer<GpgSubKey> buffered_subkeys_; ///<
QGroupBox* list_box_; ///<
QGroupBox* detail_box_; ///<
diff --git a/src/ui/dialog/keypair_details/KeyPairUIDTab.cpp b/src/ui/dialog/keypair_details/KeyPairUIDTab.cpp
index 9fc13690..1d1231c7 100644
--- a/src/ui/dialog/keypair_details/KeyPairUIDTab.cpp
+++ b/src/ui/dialog/keypair_details/KeyPairUIDTab.cpp
@@ -408,12 +408,12 @@ void KeyPairUIDTab::slot_set_primary_uid() {
}
}
-auto KeyPairUIDTab::get_sign_selected() -> SignIdArgsListPtr {
- auto signatures = std::make_unique<SignIdArgsList>();
+auto KeyPairUIDTab::get_sign_selected() -> SignIdArgsList {
+ auto signatures = SignIdArgsList{};
for (int i = 0; i < sig_list_->rowCount(); i++) {
if (sig_list_->item(i, 0)->isSelected()) {
auto& sign = buffered_signatures_[i];
- signatures->push_back({sign.GetKeyID(), sign.GetUID()});
+ signatures.push_back({sign.GetKeyID(), sign.GetUID()});
}
}
return signatures;
@@ -476,7 +476,7 @@ void KeyPairUIDTab::create_sign_popup_menu() {
void KeyPairUIDTab::slot_del_sign() {
auto selected_signs = get_sign_selected();
- if (selected_signs->empty()) {
+ if (selected_signs.empty()) {
QMessageBox::information(
nullptr, tr("Invalid Operation"),
tr("Please select one Key Signature before doing this operation."));
@@ -484,7 +484,7 @@ void KeyPairUIDTab::slot_del_sign() {
}
if (!GpgKeyGetter::GetInstance(current_gpg_context_channel_)
- .GetKey(selected_signs->front().first)
+ .GetKey(selected_signs.front().first)
.IsGood()) {
QMessageBox::critical(
nullptr, tr("Invalid Operation"),
@@ -495,7 +495,7 @@ void KeyPairUIDTab::slot_del_sign() {
QString keynames;
- keynames.append(selected_signs->front().second);
+ keynames.append(selected_signs.front().second);
keynames.append("<br/>");
int ret = QMessageBox::warning(this, tr("Deleting Key Signature"),
@@ -514,6 +514,7 @@ void KeyPairUIDTab::slot_del_sign() {
}
}
}
+
void KeyPairUIDTab::slot_refresh_key() {
// refresh the key
GpgKey refreshed_key = GpgKeyGetter::GetInstance(current_gpg_context_channel_)
diff --git a/src/ui/dialog/keypair_details/KeyPairUIDTab.h b/src/ui/dialog/keypair_details/KeyPairUIDTab.h
index d97ea2d8..3f98e54b 100644
--- a/src/ui/dialog/keypair_details/KeyPairUIDTab.h
+++ b/src/ui/dialog/keypair_details/KeyPairUIDTab.h
@@ -139,13 +139,13 @@ class KeyPairUIDTab : public QWidget {
private:
int current_gpg_context_channel_;
GpgKey m_key_;
- QTableWidget* uid_list_{}; ///<
- QTableWidget* sig_list_{}; ///<
- QTabWidget* tofu_tabs_{}; ///<
- QMenu* uid_popup_menu_{}; ///<
- QMenu* sign_popup_menu_{}; ///<
- std::vector<GpgUID> buffered_uids_; ///<
- std::vector<GpgKeySignature> buffered_signatures_; ///<
+ QTableWidget* uid_list_{}; ///<
+ QTableWidget* sig_list_{}; ///<
+ QTabWidget* tofu_tabs_{}; ///<
+ QMenu* uid_popup_menu_{}; ///<
+ QMenu* sign_popup_menu_{}; ///<
+ QContainer<GpgUID> buffered_uids_; ///<
+ QContainer<GpgKeySignature> buffered_signatures_; ///<
QAction* set_primary_uid_act_;
QAction* sign_uid_act_;
@@ -181,7 +181,7 @@ class KeyPairUIDTab : public QWidget {
*
* @return SignIdArgsListPtr
*/
- auto get_sign_selected() -> SignIdArgsListPtr;
+ auto get_sign_selected() -> SignIdArgsList;
/**
* @brief Get the sign selected object
diff --git a/src/ui/dialog/keypair_details/KeySetExpireDateDialog.cpp b/src/ui/dialog/keypair_details/KeySetExpireDateDialog.cpp
index d621e261..2f86b603 100644
--- a/src/ui/dialog/keypair_details/KeySetExpireDateDialog.cpp
+++ b/src/ui/dialog/keypair_details/KeySetExpireDateDialog.cpp
@@ -95,20 +95,9 @@ void KeySetExpireDateDialog::slot_confirm() {
void KeySetExpireDateDialog::init() {
ui_->setupUi(this);
- auto settings =
- GpgFrontend::GlobalSettingStation::GetInstance().GetSettings();
-
- bool longer_expiration_date =
- settings.value("basic/longer_expiration_date").toBool();
-
- auto max_date_time =
- longer_expiration_date
- ? QDateTime::currentDateTime().toLocalTime().addYears(30)
- : QDateTime::currentDateTime().toLocalTime().addYears(2);
+ auto settings = GpgFrontend::GetSettings();
auto min_date_time = QDateTime::currentDateTime().addDays(7);
-
- ui_->dateEdit->setMaximumDateTime(max_date_time);
ui_->dateEdit->setMinimumDateTime(min_date_time);
// set default date time to expire date time
@@ -133,10 +122,6 @@ void KeySetExpireDateDialog::init() {
}
ui_->titleLabel->setText(tr("Modified Expiration Date (Local Time)"));
- ui_->label->setText(tr(
- "Tips: For the sake of security, the key is valid for up to two years. "
- "If you are an expert user, please unlock it for a longer time in the "
- "settings."));
ui_->noExpirationCheckBox->setText(tr("No Expiration"));
this->setWindowTitle(tr("Modified Expiration Date"));
this->setAttribute(Qt::WA_DeleteOnClose);
diff --git a/src/ui/dialog/keypair_details/KeyUIDSignDialog.cpp b/src/ui/dialog/keypair_details/KeyUIDSignDialog.cpp
index e079e683..4b9d4726 100644
--- a/src/ui/dialog/keypair_details/KeyUIDSignDialog.cpp
+++ b/src/ui/dialog/keypair_details/KeyUIDSignDialog.cpp
@@ -52,7 +52,7 @@ KeyUIDSignDialog::KeyUIDSignDialog(int channel, const GpgKey& key,
m_key_list_->AddListGroupTab(
tr("Signers"), "signers", GpgKeyTableDisplayMode::kPRIVATE_KEY,
[key_id](const GpgKey& key) -> bool {
- return !(key.IsDisabled() || !key.IsHasCertificationCapability() ||
+ return !(key.IsDisabled() || !key.IsHasCertCap() ||
!key.IsHasMasterKey() || key.IsExpired() || key.IsRevoked() ||
key_id == key.GetId());
});
@@ -108,14 +108,14 @@ void KeyUIDSignDialog::slot_sign_key(bool clicked) {
auto key_ids = m_key_list_->GetChecked();
auto keys =
GpgKeyGetter::GetInstance(current_gpg_context_channel_).GetKeys(key_ids);
- assert(std::all_of(keys->begin(), keys->end(),
+ assert(std::all_of(keys.begin(), keys.end(),
[](const auto& key) { return key.IsGood(); }));
auto expires = std::make_unique<QDateTime>(expires_edit_->dateTime());
// Sign For mKey
if (!GpgKeyManager::GetInstance(current_gpg_context_channel_)
- .SignKey(m_key_, *keys, m_uid_, expires)) {
+ .SignKey(m_key_, keys, m_uid_, expires)) {
QMessageBox::critical(
nullptr, tr("Unsuccessful Operation"),
tr("Signature operation failed for UID %1").arg(m_uid_));
diff --git a/src/ui/dialog/settings/SettingsAppearance.cpp b/src/ui/dialog/settings/SettingsAppearance.cpp
index d2648498..2c675251 100644
--- a/src/ui/dialog/settings/SettingsAppearance.cpp
+++ b/src/ui/dialog/settings/SettingsAppearance.cpp
@@ -135,7 +135,7 @@ void AppearanceTab::SetSettings() {
ui_->themeComboBox->addItem(s.toLower());
}
- auto settings = GlobalSettingStation::GetInstance().GetSettings();
+ auto settings = GetSettings();
auto theme = settings.value("appearance/theme").toString();
auto target_theme_index = ui_->themeComboBox->findText(theme);
@@ -150,6 +150,19 @@ void AppearanceTab::SetSettings() {
} else {
ui_->themeComboBox->setCurrentIndex(target_theme_index);
}
+
+ ui_->encrCheckBox->setChecked(
+ (appearance.tool_bar_crypto_operas_type & GpgOperation::kENCRYPT) != 0);
+ ui_->decrCheckBox->setChecked(
+ (appearance.tool_bar_crypto_operas_type & GpgOperation::kDECRYPT) != 0);
+ ui_->signCheckBox->setChecked(
+ (appearance.tool_bar_crypto_operas_type & GpgOperation::kSIGN) != 0);
+ ui_->verifyCheckBox->setChecked(
+ (appearance.tool_bar_crypto_operas_type & GpgOperation::kVERIFY) != 0);
+ ui_->encrSignCheckBox->setChecked((appearance.tool_bar_crypto_operas_type &
+ GpgOperation::kENCRYPT_SIGN) != 0);
+ ui_->decrVerifyCheckBox->setChecked((appearance.tool_bar_crypto_operas_type &
+ GpgOperation::kDECRYPT_VERIFY) != 0);
}
void AppearanceTab::ApplySettings() {
@@ -195,9 +208,23 @@ void AppearanceTab::ApplySettings() {
appearance.text_editor_font_size =
ui_->fontSizeTextEditorLabelSpinBox->value();
+ appearance.tool_bar_crypto_operas_type = 0;
+ appearance.tool_bar_crypto_operas_type |=
+ ui_->encrCheckBox->isChecked() ? kENCRYPT : kNONE;
+ appearance.tool_bar_crypto_operas_type |=
+ ui_->decrCheckBox->isChecked() ? kDECRYPT : kNONE;
+ appearance.tool_bar_crypto_operas_type |=
+ ui_->signCheckBox->isChecked() ? kSIGN : kNONE;
+ appearance.tool_bar_crypto_operas_type |=
+ ui_->verifyCheckBox->isChecked() ? kVERIFY : kNONE;
+ appearance.tool_bar_crypto_operas_type |=
+ ui_->encrSignCheckBox->isChecked() ? kENCRYPT_SIGN : kNONE;
+ appearance.tool_bar_crypto_operas_type |=
+ ui_->decrVerifyCheckBox->isChecked() ? kDECRYPT_VERIFY : kNONE;
+
general_settings_state.Store(appearance.ToJson());
- auto settings = GlobalSettingStation::GetInstance().GetSettings();
+ auto settings = GetSettings();
settings.setValue("appearance/theme", ui_->themeComboBox->currentText());
}
diff --git a/src/ui/dialog/settings/SettingsGeneral.cpp b/src/ui/dialog/settings/SettingsGeneral.cpp
index 73599729..73d8bccd 100644
--- a/src/ui/dialog/settings/SettingsGeneral.cpp
+++ b/src/ui/dialog/settings/SettingsGeneral.cpp
@@ -48,8 +48,6 @@ GeneralTab::GeneralTab(QWidget* parent)
"crash."));
ui_->importConfirmationBox->setTitle(tr("Operation"));
- ui_->longerKeyExpirationDateCheckBox->setText(
- tr("Enable to use longer key expiration date."));
ui_->importConfirmationCheckBox->setText(
tr("Import files dropped on the Key List without confirmation."));
ui_->disableLoadingModulesCheckBox->setText(
@@ -109,7 +107,7 @@ GeneralTab::GeneralTab(QWidget* parent)
}
void GeneralTab::SetSettings() {
- auto settings = GlobalSettingStation::GetInstance().GetSettings();
+ auto settings = GetSettings();
auto clear_gpg_password_cache =
settings.value("basic/clear_gpg_password_cache", true).toBool();
@@ -121,11 +119,6 @@ void GeneralTab::SetSettings() {
ui_->restoreTextEditorPageCheckBox->setCheckState(
restore_text_editor_page ? Qt::Checked : Qt::Unchecked);
- auto longer_expiration_date =
- settings.value("basic/longer_expiration_date", false).toBool();
- ui_->longerKeyExpirationDateCheckBox->setCheckState(
- longer_expiration_date ? Qt::Checked : Qt::Unchecked);
-
auto confirm_import_keys =
settings.value("basic/confirm_import_keys", false).toBool();
ui_->importConfirmationCheckBox->setCheckState(
@@ -147,11 +140,8 @@ void GeneralTab::SetSettings() {
}
void GeneralTab::ApplySettings() {
- auto settings =
- GpgFrontend::GlobalSettingStation::GetInstance().GetSettings();
+ auto settings = GpgFrontend::GetSettings();
- settings.setValue("basic/longer_expiration_date",
- ui_->longerKeyExpirationDateCheckBox->isChecked());
settings.setValue("basic/clear_gpg_password_cache",
ui_->clearGpgPasswordCacheCheckBox->isChecked());
settings.setValue("basic/restore_text_editor_page",
diff --git a/src/ui/dialog/settings/SettingsGeneral.h b/src/ui/dialog/settings/SettingsGeneral.h
index 6dc35d58..2bd717d0 100644
--- a/src/ui/dialog/settings/SettingsGeneral.h
+++ b/src/ui/dialog/settings/SettingsGeneral.h
@@ -28,6 +28,7 @@
#pragma once
+#include "core/typedef/CoreTypedef.h"
#include "ui/GpgFrontendUI.h"
class Ui_GeneralSettings;
@@ -81,7 +82,7 @@ class GeneralTab : public QWidget {
private:
std::shared_ptr<Ui_GeneralSettings> ui_; ///<
QHash<QString, QString> lang_; ///<
- std::vector<QString> key_ids_list_; ///<
+ QStringList key_ids_list_; ///<
KeyList* m_key_list_{}; ///<
};
} // namespace GpgFrontend::UI
diff --git a/src/ui/dialog/settings/SettingsKeyServer.cpp b/src/ui/dialog/settings/SettingsKeyServer.cpp
index 38256c8e..e73363d6 100644
--- a/src/ui/dialog/settings/SettingsKeyServer.cpp
+++ b/src/ui/dialog/settings/SettingsKeyServer.cpp
@@ -233,8 +233,7 @@ void KeyserverTab::slot_test_listed_key_server() {
task,
&GpgFrontend::UI::ListedKeyServerTestTask::SignalKeyServerListTestResult,
this,
- [=](std::vector<ListedKeyServerTestTask::KeyServerTestResultType>
- result) {
+ [=](QContainer<ListedKeyServerTestTask::KeyServerTestResultType> result) {
const size_t row_size = ui_->keyServerListTable->rowCount();
if (result.size() != row_size) return;
ui_->keyServerListTable->blockSignals(true);
diff --git a/src/ui/dialog/settings/SettingsNetwork.cpp b/src/ui/dialog/settings/SettingsNetwork.cpp
index 8a95c177..66f3abb1 100644
--- a/src/ui/dialog/settings/SettingsNetwork.cpp
+++ b/src/ui/dialog/settings/SettingsNetwork.cpp
@@ -101,7 +101,7 @@ GpgFrontend::UI::NetworkTab::NetworkTab(QWidget *parent)
}
void GpgFrontend::UI::NetworkTab::SetSettings() {
- auto settings = GlobalSettingStation::GetInstance().GetSettings();
+ auto settings = GetSettings();
auto proxy_host = settings.value("proxy/proxy_host").toString();
ui_->proxyServerAddressEdit->setText(proxy_host);
@@ -146,8 +146,7 @@ void GpgFrontend::UI::NetworkTab::SetSettings() {
}
void GpgFrontend::UI::NetworkTab::ApplySettings() {
- auto settings =
- GpgFrontend::GlobalSettingStation::GetInstance().GetSettings();
+ auto settings = GpgFrontend::GetSettings();
settings.setValue("proxy/proxy_host", ui_->proxyServerAddressEdit->text());
settings.setValue("proxy/username", ui_->usernameEdit->text());