aboutsummaryrefslogtreecommitdiffstats
path: root/src/ui/dialog
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/dialog')
-rw-r--r--src/ui/dialog/ADSKsPicker.cpp9
-rw-r--r--src/ui/dialog/KeyGroupCreationDialog.cpp119
-rw-r--r--src/ui/dialog/KeyGroupCreationDialog.h90
-rw-r--r--src/ui/dialog/KeyGroupManageDialog.cpp163
-rw-r--r--src/ui/dialog/KeyGroupManageDialog.h83
-rw-r--r--src/ui/dialog/SignersPicker.cpp14
-rw-r--r--src/ui/dialog/SignersPicker.h8
-rw-r--r--src/ui/dialog/controller/SmartCardControllerDialog.h1
-rw-r--r--src/ui/dialog/import_export/ExportKeyPackageDialog.cpp26
-rw-r--r--src/ui/dialog/import_export/ExportKeyPackageDialog.h6
-rw-r--r--src/ui/dialog/import_export/KeyImportDetailDialog.cpp1
-rw-r--r--src/ui/dialog/import_export/KeyUploadDialog.cpp14
-rw-r--r--src/ui/dialog/import_export/KeyUploadDialog.h6
-rw-r--r--src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp9
-rw-r--r--src/ui/dialog/key_generate/SubkeyGenerateDialog.h5
-rw-r--r--src/ui/dialog/keypair_details/KeyDetailsDialog.cpp23
-rw-r--r--src/ui/dialog/keypair_details/KeyDetailsDialog.h2
-rw-r--r--src/ui/dialog/keypair_details/KeyNewUIDDialog.cpp14
-rw-r--r--src/ui/dialog/keypair_details/KeyNewUIDDialog.h6
-rw-r--r--src/ui/dialog/keypair_details/KeyPairDetailTab.cpp76
-rw-r--r--src/ui/dialog/keypair_details/KeyPairDetailTab.h5
-rw-r--r--src/ui/dialog/keypair_details/KeyPairOperaTab.cpp101
-rw-r--r--src/ui/dialog/keypair_details/KeyPairOperaTab.h7
-rw-r--r--src/ui/dialog/keypair_details/KeyPairSubkeyTab.cpp43
-rw-r--r--src/ui/dialog/keypair_details/KeyPairSubkeyTab.h4
-rw-r--r--src/ui/dialog/keypair_details/KeyPairUIDTab.cpp27
-rw-r--r--src/ui/dialog/keypair_details/KeyPairUIDTab.h4
-rw-r--r--src/ui/dialog/keypair_details/KeySetExpireDateDialog.cpp25
-rw-r--r--src/ui/dialog/keypair_details/KeySetExpireDateDialog.h6
-rw-r--r--src/ui/dialog/keypair_details/KeyUIDSignDialog.cpp24
-rw-r--r--src/ui/dialog/keypair_details/KeyUIDSignDialog.h6
31 files changed, 672 insertions, 255 deletions
diff --git a/src/ui/dialog/ADSKsPicker.cpp b/src/ui/dialog/ADSKsPicker.cpp
index f10a936a..a8afb9bf 100644
--- a/src/ui/dialog/ADSKsPicker.cpp
+++ b/src/ui/dialog/ADSKsPicker.cpp
@@ -38,9 +38,14 @@ ADSKsPicker::ADSKsPicker(int channel,
QWidget* parent)
: GeneralDialog(typeid(ADSKsPicker).name(), parent),
tree_view_(new KeyTreeView(
- channel, [](GpgAbstractKey* k) { return k->IsSubKey(); },
+ channel,
+ [](GpgAbstractKey* k) {
+ return k->KeyType() == GpgAbstractKeyType::kGPG_SUBKEY;
+ },
[=](const GpgAbstractKey* k) {
- return (!k->IsSubKey() || (k->IsSubKey() && k->IsHasEncrCap())) &&
+ return (k->KeyType() != GpgAbstractKeyType::kGPG_SUBKEY ||
+ (k->KeyType() == GpgAbstractKeyType::kGPG_SUBKEY &&
+ k->IsHasEncrCap())) &&
filter(k);
})) {
auto* confirm_button = new QPushButton(tr("Confirm"));
diff --git a/src/ui/dialog/KeyGroupCreationDialog.cpp b/src/ui/dialog/KeyGroupCreationDialog.cpp
new file mode 100644
index 00000000..506c173d
--- /dev/null
+++ b/src/ui/dialog/KeyGroupCreationDialog.cpp
@@ -0,0 +1,119 @@
+/**
+ * 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 "KeyGroupCreationDialog.h"
+
+#include "core/function/gpg/GpgKeyGroupGetter.h"
+#include "core/model/GpgKeyGroup.h"
+#include "ui/UISignalStation.h"
+
+namespace GpgFrontend::UI {
+KeyGroupCreationDialog::KeyGroupCreationDialog(int channel, QStringList key_ids,
+ QWidget* parent)
+ : GeneralDialog(typeid(KeyGroupCreationDialog).name(), parent),
+ current_gpg_context_channel_(channel),
+ key_ids_(key_ids) {
+ assert(!key_ids.isEmpty());
+
+ name_ = new QLineEdit();
+ name_->setMinimumWidth(240);
+ email_ = new QLineEdit();
+ email_->setMinimumWidth(240);
+ comment_ = new QLineEdit();
+ comment_->setMinimumWidth(240);
+ create_button_ = new QPushButton("Create");
+ error_label_ = new QLabel();
+
+ auto* grid_layout = new QGridLayout();
+ grid_layout->addWidget(new QLabel(tr("Name")), 0, 0);
+ grid_layout->addWidget(new QLabel(tr("Email")), 1, 0);
+ grid_layout->addWidget(new QLabel(tr("Comment")), 2, 0);
+
+ grid_layout->addWidget(name_, 0, 1);
+ grid_layout->addWidget(email_, 1, 1);
+ grid_layout->addWidget(comment_, 2, 1);
+
+ grid_layout->addWidget(create_button_, 3, 0, 1, 2);
+ grid_layout->addWidget(error_label_, 4, 0, 1, 2);
+
+ connect(create_button_, &QPushButton::clicked, this,
+ &KeyGroupCreationDialog::slot_create_new_uid);
+
+ connect(this, &KeyGroupCreationDialog::SignalCreated,
+ UISignalStation::GetInstance(),
+ &UISignalStation::SignalKeyDatabaseRefresh);
+
+ this->setLayout(grid_layout);
+ this->setWindowTitle(tr("Create New Key Group"));
+ this->setAttribute(Qt::WA_DeleteOnClose, true);
+ this->setModal(true);
+}
+
+void KeyGroupCreationDialog::slot_create_new_uid() {
+ QString buffer;
+ QTextStream error_stream(&buffer);
+
+ /**
+ * check for errors in keygen dialog input
+ */
+ if ((name_->text()).size() < 5) {
+ error_stream << " " << tr("Name must contain at least five characters.")
+ << Qt::endl;
+ }
+ if (email_->text().isEmpty() || !check_email_address(email_->text())) {
+ error_stream << " " << tr("Please give a email address.") << Qt::endl;
+ }
+ auto error_string = error_stream.readAll();
+ if (error_string.isEmpty()) {
+ auto p_kg =
+ GpgKeyGroup{name_->text(), email_->text(), comment_->text(), key_ids_};
+ GpgKeyGroupGetter::GetInstance(current_gpg_context_channel_)
+ .AddKeyGroup(p_kg);
+
+ emit SignalCreated();
+ this->close();
+ } 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(error_string);
+
+ this->show();
+ this->raise();
+ this->activateWindow();
+ }
+}
+
+auto KeyGroupCreationDialog::check_email_address(const QString& str) -> bool {
+ return re_email_.match(str).hasMatch();
+}
+} // namespace GpgFrontend::UI
diff --git a/src/ui/dialog/KeyGroupCreationDialog.h b/src/ui/dialog/KeyGroupCreationDialog.h
new file mode 100644
index 00000000..634c9148
--- /dev/null
+++ b/src/ui/dialog/KeyGroupCreationDialog.h
@@ -0,0 +1,90 @@
+/**
+ * Copyright (C) 2021-2024 Saturneric <[email protected]>
+ *
+ * This file is part of GpgFrontend.
+ *
+ * GpgFrontend is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GpgFrontend is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GpgFrontend. If not, see <https://www.gnu.org/licenses/>.
+ *
+ * The initial version of the source code is inherited from
+ * the gpg4usb project, which is under GPL-3.0-or-later.
+ *
+ * All the source code of GpgFrontend was modified and released by
+ * Saturneric <[email protected]> starting on May 12, 2021.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ *
+ */
+
+#pragma once
+
+#include "core/function/gpg/GpgContext.h"
+#include "core/model/GpgKey.h"
+#include "core/typedef/GpgTypedef.h"
+#include "ui/dialog/GeneralDialog.h"
+
+namespace GpgFrontend::UI {
+class KeyGroupCreationDialog : public GeneralDialog {
+ Q_OBJECT
+
+ public:
+ /**
+ * @brief Construct a new Key New U I D Dialog object
+ *
+ * @param key
+ * @param parent
+ */
+ KeyGroupCreationDialog(int channel, QStringList key_ids,
+ QWidget* parent = nullptr);
+
+ signals:
+ /**
+ * @brief
+ *
+ */
+ void SignalCreated();
+
+ private slots:
+
+ /**
+ * @brief
+ *
+ */
+ void slot_create_new_uid();
+
+ private:
+ int current_gpg_context_channel_;
+ QStringList key_ids_; ///<
+
+ QLineEdit* name_{}; ///<
+ QLineEdit* email_{}; ///<
+ QLineEdit* comment_{}; ///<
+
+ QPushButton* create_button_{}; ///<
+
+ QStringList error_messages_; ///<
+ QLabel* error_label_{}; ///<
+
+ 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
+ */
+ auto check_email_address(const QString& str) -> bool;
+};
+} // namespace GpgFrontend::UI
diff --git a/src/ui/dialog/KeyGroupManageDialog.cpp b/src/ui/dialog/KeyGroupManageDialog.cpp
new file mode 100644
index 00000000..1a994585
--- /dev/null
+++ b/src/ui/dialog/KeyGroupManageDialog.cpp
@@ -0,0 +1,163 @@
+/**
+ * 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 "KeyGroupManageDialog.h"
+
+#include "core/function/gpg/GpgAbstractKeyGetter.h"
+#include "ui/widgets/KeyList.h"
+
+//
+#include "ui_KeyGroupManageDialog.h"
+
+namespace GpgFrontend::UI {
+
+KeyGroupManageDialog::KeyGroupManageDialog(
+ int channel, const QSharedPointer<GpgKeyGroup>& key_group, QWidget* parent)
+ : GeneralDialog(typeid(KeyGroupManageDialog).name(), parent),
+ ui_(QSharedPointer<Ui_KeyGroupManageDialog>::create()),
+ channel_(channel),
+ key_group_(key_group) {
+ ui_->setupUi(this);
+
+ connect(ui_->addButton, &QPushButton::clicked, this,
+ &KeyGroupManageDialog::slot_add_to_key_group);
+
+ connect(ui_->removeButton, &QPushButton::clicked, this,
+ &KeyGroupManageDialog::slot_remove_from_key_group);
+
+ ui_->keyGroupKeyList->Init(
+ channel, KeyMenuAbility::kCOLUMN_FILTER | KeyMenuAbility::kSEARCH_BAR,
+ GpgKeyTableColumn::kTYPE | GpgKeyTableColumn::kNAME |
+ GpgKeyTableColumn::kEMAIL_ADDRESS | GpgKeyTableColumn::kKEY_ID);
+ ui_->keyGroupKeyList->AddListGroupTab(
+ tr("Key Group"), "key-group",
+ GpgKeyTableDisplayMode::kPRIVATE_KEY |
+ GpgKeyTableDisplayMode::kPUBLIC_KEY,
+ [=](const GpgAbstractKey* key) -> bool {
+ return key_group_->KeyIds().contains(key->ID());
+ });
+ ui_->keyGroupKeyList->SlotRefresh();
+
+ ui_->keyList->Init(
+ channel, KeyMenuAbility::kCOLUMN_FILTER | KeyMenuAbility::kSEARCH_BAR,
+ GpgKeyTableColumn::kTYPE | GpgKeyTableColumn::kNAME |
+ GpgKeyTableColumn::kEMAIL_ADDRESS | GpgKeyTableColumn::kKEY_ID);
+ ui_->keyList->AddListGroupTab(
+ tr("Default"), "default",
+ GpgKeyTableDisplayMode::kPRIVATE_KEY |
+ GpgKeyTableDisplayMode::kPUBLIC_KEY,
+ [=](const GpgAbstractKey* key) -> bool {
+ return key->IsHasEncrCap() && key->ID() != key_group_->ID() &&
+ !key_group_->KeyIds().contains(key->ID());
+ });
+ ui_->keyList->SlotRefresh();
+
+ QTimer::singleShot(200, [=]() { slot_notify_invalid_key_ids(); });
+
+ this->setModal(true);
+ this->setWindowTitle(tr("Key Group Management"));
+
+ movePosition2CenterOfParent();
+
+ this->show();
+ this->raise();
+ this->activateWindow();
+}
+
+void KeyGroupManageDialog::slot_add_to_key_group() {
+ auto keys = ui_->keyList->GetCheckedKeys();
+ QSet<QString> set;
+
+ GpgAbstractKeyPtrList failed_keys;
+ auto& getter = GpgKeyGroupGetter::GetInstance(channel_);
+ for (const auto& key : keys) {
+ if (!getter.AddKey2KeyGroup(key_group_->ID(), key)) {
+ failed_keys.push_back(key);
+ }
+ }
+
+ ui_->keyGroupKeyList->RefreshKeyTable(0);
+ ui_->keyList->RefreshKeyTable(0);
+
+ if (!failed_keys.isEmpty()) {
+ QStringList failed_ids;
+ for (const auto& key : failed_keys) {
+ failed_ids << key->ID();
+ }
+
+ QMessageBox::warning(this, tr("Some Keys Failed"),
+ tr("Some keys could not be added to the group:\n%1")
+ .arg(failed_ids.join(", ")));
+ }
+}
+
+void KeyGroupManageDialog::slot_remove_from_key_group() {
+ auto keys = ui_->keyGroupKeyList->GetCheckedKeys();
+
+ auto& getter = GpgKeyGroupGetter::GetInstance(channel_);
+ for (const auto& key : keys) {
+ getter.RemoveKeyFromKeyGroup(key_group_->ID(), key->ID());
+ }
+
+ ui_->keyGroupKeyList->RefreshKeyTable(0);
+ ui_->keyList->RefreshKeyTable(0);
+}
+
+void KeyGroupManageDialog::slot_notify_invalid_key_ids() {
+ auto key_ids = key_group_->KeyIds();
+
+ QStringList invalid_key_ids;
+ for (const auto& key_id : key_ids) {
+ auto key = GpgAbstractKeyGetter::GetInstance(channel_).GetKey(key_id);
+ if (key == nullptr) invalid_key_ids.push_back(key_id);
+ }
+
+ if (invalid_key_ids.isEmpty()) {
+ return;
+ }
+
+ const QString id_list = invalid_key_ids.join(", ");
+ const auto message =
+ tr("This Key Group contains some invalid keys:\n\n%1\n\n"
+ "These keys are no longer available. Do you want to remove them from "
+ "the group?")
+ .arg(id_list);
+
+ const auto reply = QMessageBox::question(
+ this, tr("Invalid Keys in Group"), message,
+ QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
+
+ if (reply == QMessageBox::Yes) {
+ auto key_ids = key_group_->KeyIds();
+ auto& getter = GpgKeyGroupGetter::GetInstance(channel_);
+ for (const auto& key_id : invalid_key_ids) {
+ getter.RemoveKeyFromKeyGroup(key_group_->ID(), key_id);
+ }
+ }
+}
+} // namespace GpgFrontend::UI
diff --git a/src/ui/dialog/KeyGroupManageDialog.h b/src/ui/dialog/KeyGroupManageDialog.h
new file mode 100644
index 00000000..66211d28
--- /dev/null
+++ b/src/ui/dialog/KeyGroupManageDialog.h
@@ -0,0 +1,83 @@
+/**
+ * Copyright (C) 2021-2024 Saturneric <[email protected]>
+ *
+ * This file is part of GpgFrontend.
+ *
+ * GpgFrontend is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GpgFrontend is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GpgFrontend. If not, see <https://www.gnu.org/licenses/>.
+ *
+ * The initial version of the source code is inherited from
+ * the gpg4usb project, which is under GPL-3.0-or-later.
+ *
+ * All the source code of GpgFrontend was modified and released by
+ * Saturneric <[email protected]> starting on May 12, 2021.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ *
+ */
+
+#pragma once
+
+#include "core/model/GpgKeyGroup.h"
+#include "ui/dialog//GeneralDialog.h"
+
+class Ui_KeyGroupManageDialog;
+
+namespace GpgFrontend::UI {
+
+class KeyList;
+
+/**
+ * @brief
+ *
+ */
+class KeyGroupManageDialog : public GeneralDialog {
+ Q_OBJECT
+
+ public:
+ /**
+ * @brief Construct a new Signers Picker object
+ *
+ * @param parent
+ */
+ explicit KeyGroupManageDialog(int channel,
+ const QSharedPointer<GpgKeyGroup>& key_group,
+ QWidget* parent = nullptr);
+
+ private slots:
+
+ /**
+ * @brief
+ *
+ */
+ void slot_add_to_key_group();
+
+ /**
+ * @brief
+ *
+ */
+ void slot_remove_from_key_group();
+
+ /**
+ * @brief
+ *
+ */
+ void slot_notify_invalid_key_ids();
+
+ private:
+ QSharedPointer<Ui_KeyGroupManageDialog> ui_; ///<
+ int channel_;
+ QSharedPointer<GpgKeyGroup> key_group_;
+};
+
+} // namespace GpgFrontend::UI
diff --git a/src/ui/dialog/SignersPicker.cpp b/src/ui/dialog/SignersPicker.cpp
index fa72287e..94a8f8df 100644
--- a/src/ui/dialog/SignersPicker.cpp
+++ b/src/ui/dialog/SignersPicker.cpp
@@ -51,7 +51,7 @@ SignersPicker::SignersPicker(int channel, QWidget* parent)
this);
key_list_->AddListGroupTab(
tr("Signers"), "signers", GpgKeyTableDisplayMode::kPRIVATE_KEY,
- [](const GpgKey& key) -> bool { return key.IsHasActualSignCap(); });
+ [](const GpgAbstractKey* key) -> bool { return key->IsHasSignCap(); });
key_list_->SlotRefresh();
auto* vbox2 = new QVBoxLayout();
@@ -79,20 +79,10 @@ SignersPicker::SignersPicker(int channel, QWidget* parent)
this->activateWindow();
}
-auto SignersPicker::GetCheckedSigners() -> GpgFrontend::KeyIdArgsList {
+auto SignersPicker::GetCheckedSigners() -> GpgAbstractKeyPtrList {
return key_list_->GetCheckedPrivateKey();
}
-auto SignersPicker::GetCheckedSignerKeyIds() -> GpgFrontend::KeyIdArgsList {
- auto priv_keys = key_list_->GetCheckedPrivateKey();
-
- QStringList r;
- for (const auto& priv_key : priv_keys) {
- r.append(priv_key);
- }
- return r;
-}
-
auto SignersPicker::GetStatus() const -> bool { return this->accepted_; }
} // namespace GpgFrontend::UI
diff --git a/src/ui/dialog/SignersPicker.h b/src/ui/dialog/SignersPicker.h
index 826ccfab..25f3d440 100644
--- a/src/ui/dialog/SignersPicker.h
+++ b/src/ui/dialog/SignersPicker.h
@@ -56,15 +56,9 @@ class SignersPicker : public GeneralDialog {
*
* @return GpgFrontend::KeyIdArgsListPtr
*/
- auto GetCheckedSigners() -> KeyIdArgsList;
+ auto GetCheckedSigners() -> GpgAbstractKeyPtrList;
/**
- * @brief Get the Checked Signer Key Ids object
- *
- * @return QStringList
- */
- auto GetCheckedSignerKeyIds() -> KeyIdArgsList;
- /**
*
* @return
*/
diff --git a/src/ui/dialog/controller/SmartCardControllerDialog.h b/src/ui/dialog/controller/SmartCardControllerDialog.h
index 83a717ee..affe01a8 100644
--- a/src/ui/dialog/controller/SmartCardControllerDialog.h
+++ b/src/ui/dialog/controller/SmartCardControllerDialog.h
@@ -29,7 +29,6 @@
#pragma once
#include "core/model/GpgOpenPGPCard.h"
-#include "core/typedef/CoreTypedef.h"
#include "ui/dialog/GeneralDialog.h"
class Ui_SmartCardControllerDialog;
diff --git a/src/ui/dialog/import_export/ExportKeyPackageDialog.cpp b/src/ui/dialog/import_export/ExportKeyPackageDialog.cpp
index 7aab31b5..325eba98 100644
--- a/src/ui/dialog/import_export/ExportKeyPackageDialog.cpp
+++ b/src/ui/dialog/import_export/ExportKeyPackageDialog.cpp
@@ -28,18 +28,16 @@
#include "ExportKeyPackageDialog.h"
-#include "core/GpgModel.h"
#include "core/function/KeyPackageOperator.h"
-#include "core/function/gpg/GpgKeyGetter.h"
#include "ui/function/GpgOperaHelper.h"
#include "ui_ExportKeyPackageDialog.h"
GpgFrontend::UI::ExportKeyPackageDialog::ExportKeyPackageDialog(
- int channel, KeyIdArgsList key_ids, QWidget* parent)
+ int channel, GpgAbstractKeyPtrList keys, QWidget* parent)
: GeneralDialog(typeid(ExportKeyPackageDialog).name(), parent),
ui_(GpgFrontend::SecureCreateSharedObject<Ui_exportKeyPackageDialog>()),
current_gpg_context_channel_(channel),
- key_ids_(std::move(key_ids)) {
+ keys_(std::move(keys)) {
ui_->setupUi(this);
ui_->nameValueLabel->setText(KeyPackageOperator::GenerateKeyPackageName());
@@ -95,29 +93,23 @@ GpgFrontend::UI::ExportKeyPackageDialog::ExportKeyPackageDialog(
return;
}
- // get suitable key ids
- auto keys = GpgKeyGetter::GetInstance(current_gpg_context_channel_)
- .GetKeys(key_ids_);
- 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) {
- return ui_->noPublicKeyCheckBox->isChecked() && !key.IsPrivateKey();
+ auto it =
+ 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(it, keys_.end());
- if (keys.empty()) {
+ if (keys_.empty()) {
QMessageBox::critical(this, tr("Error"),
tr("No key is suitable to export."));
return;
}
GpgOperaHelper::WaitForOpera(
- this, tr("Generating"), [this, keys](const OperaWaitingHd& op_hd) {
+ this, tr("Generating"), [this](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 07722a21..f457e405 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, KeyIdArgsList key_ids,
+ explicit ExportKeyPackageDialog(int channel, GpgAbstractKeyPtrList keys,
QWidget* parent);
private:
std::shared_ptr<Ui_exportKeyPackageDialog> ui_; ///<
int current_gpg_context_channel_;
- KeyIdArgsList key_ids_; ///<
- QString passphrase_; ///<
+ GpgAbstractKeyPtrList keys_; ///<
+ QString passphrase_; ///<
};
} // namespace GpgFrontend::UI
diff --git a/src/ui/dialog/import_export/KeyImportDetailDialog.cpp b/src/ui/dialog/import_export/KeyImportDetailDialog.cpp
index 34a050ce..24062796 100644
--- a/src/ui/dialog/import_export/KeyImportDetailDialog.cpp
+++ b/src/ui/dialog/import_export/KeyImportDetailDialog.cpp
@@ -28,7 +28,6 @@
#include "KeyImportDetailDialog.h"
-#include "core/GpgModel.h"
#include "core/function/gpg/GpgKeyGetter.h"
#include "core/model/GpgImportInformation.h"
diff --git a/src/ui/dialog/import_export/KeyUploadDialog.cpp b/src/ui/dialog/import_export/KeyUploadDialog.cpp
index efa72802..346be765 100644
--- a/src/ui/dialog/import_export/KeyUploadDialog.cpp
+++ b/src/ui/dialog/import_export/KeyUploadDialog.cpp
@@ -29,9 +29,8 @@
#include "KeyUploadDialog.h"
#include <QtNetwork>
+#include <utility>
-#include "core/GpgModel.h"
-#include "core/function/gpg/GpgKeyGetter.h"
#include "core/function/gpg/GpgKeyImportExporter.h"
#include "core/model/SettingsObject.h"
#include "core/utils/BuildInfoUtils.h"
@@ -41,14 +40,13 @@
namespace GpgFrontend::UI {
-KeyUploadDialog::KeyUploadDialog(int channel, const KeyIdArgsList& keys_ids,
+KeyUploadDialog::KeyUploadDialog(int channel, GpgAbstractKeyPtrList keys,
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(),
- [](const auto& key) { return key.IsGood(); }));
+ keys_(std::move(keys)) {
+ assert(std::all_of(keys_.begin(), keys_.end(),
+ [](const auto& key) { return key->IsGood(); }));
auto* pb = new QProgressBar();
pb->setRange(0, 0);
@@ -70,7 +68,7 @@ KeyUploadDialog::KeyUploadDialog(int channel, const KeyIdArgsList& keys_ids,
void KeyUploadDialog::SlotUpload() {
GpgKeyImportExporter::GetInstance(current_gpg_context_channel_)
- .ExportKeys(m_keys_, false, true, false, false,
+ .ExportKeys(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 36616037..8d3be02f 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 KeyIdArgsList& keys_ids,
+ explicit KeyUploadDialog(int channel, GpgAbstractKeyPtrList keys,
QWidget* parent);
public slots:
@@ -76,8 +76,8 @@ class KeyUploadDialog : public GeneralDialog {
private:
int current_gpg_context_channel_;
- GpgKeyList m_keys_; ///<
- QByteArray m_key_data_; ///<
+ GpgAbstractKeyPtrList keys_; ///<
+ QByteArray m_key_data_; ///<
};
} // namespace GpgFrontend::UI
diff --git a/src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp b/src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp
index 58734c7d..662ac77a 100644
--- a/src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp
+++ b/src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp
@@ -30,8 +30,8 @@
#include <cassert>
#include <cstddef>
+#include <utility>
-#include "core/function/gpg/GpgKeyGetter.h"
#include "core/function/gpg/GpgKeyOpera.h"
#include "core/utils/GpgUtils.h"
#include "ui/UISignalStation.h"
@@ -44,17 +44,16 @@
namespace GpgFrontend::UI {
-SubkeyGenerateDialog::SubkeyGenerateDialog(int channel, const KeyId& key_id,
+SubkeyGenerateDialog::SubkeyGenerateDialog(int channel, GpgKeyPtr key,
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)),
+ key_(std::move(key)),
gen_subkey_info_(QSharedPointer<KeyGenerateInfo>::create(true)),
supported_subkey_algos_(KeyGenerateInfo::GetSupportedSubkeyAlgo()) {
ui_->setupUi(this);
- assert(key_.IsGood());
+ assert(key_ != nullptr);
ui_->algoLabel->setText(tr("Algorithm"));
ui_->keyLengthLabel->setText(tr("Key Length"));
diff --git a/src/ui/dialog/key_generate/SubkeyGenerateDialog.h b/src/ui/dialog/key_generate/SubkeyGenerateDialog.h
index 96dee49e..683c3b66 100644
--- a/src/ui/dialog/key_generate/SubkeyGenerateDialog.h
+++ b/src/ui/dialog/key_generate/SubkeyGenerateDialog.h
@@ -53,8 +53,7 @@ class SubkeyGenerateDialog : public GeneralDialog {
* @param key_id
* @param parent
*/
- explicit SubkeyGenerateDialog(int channel, const KeyId& key_id,
- QWidget* parent);
+ explicit SubkeyGenerateDialog(int channel, GpgKeyPtr key, QWidget* parent);
private slots:
@@ -68,7 +67,7 @@ class SubkeyGenerateDialog : public GeneralDialog {
QSharedPointer<Ui_SubkeyGenDialog> ui_; ///<
int current_gpg_context_channel_; ///<
- GpgKey key_; ///<
+ GpgKeyPtr key_; ///<
QSharedPointer<KeyGenerateInfo> gen_subkey_info_; ///<
QContainer<KeyAlgo> supported_subkey_algos_; ///<
diff --git a/src/ui/dialog/keypair_details/KeyDetailsDialog.cpp b/src/ui/dialog/keypair_details/KeyDetailsDialog.cpp
index b3cb3a9d..273d3316 100644
--- a/src/ui/dialog/keypair_details/KeyDetailsDialog.cpp
+++ b/src/ui/dialog/keypair_details/KeyDetailsDialog.cpp
@@ -36,29 +36,28 @@
#include "ui/dialog/keypair_details/KeyPairUIDTab.h"
namespace GpgFrontend::UI {
-KeyDetailsDialog::KeyDetailsDialog(int channel, const GpgKey& key,
+KeyDetailsDialog::KeyDetailsDialog(int channel, const GpgKeyPtr& key,
QWidget* parent)
: GeneralDialog(typeid(KeyDetailsDialog).name(), parent),
current_gpg_context_channel_(channel) {
tab_widget_ = new QTabWidget();
tab_widget_->addTab(
- new KeyPairDetailTab(current_gpg_context_channel_, key.ID(), tab_widget_),
+ new KeyPairDetailTab(current_gpg_context_channel_, key, tab_widget_),
tr("KeyPair"));
- if (!key.IsRevoked()) {
+ if (!key->IsRevoked()) {
tab_widget_->addTab(
- new KeyPairUIDTab(current_gpg_context_channel_, key.ID(), tab_widget_),
+ new KeyPairUIDTab(current_gpg_context_channel_, key, tab_widget_),
tr("UIDs"));
-
- tab_widget_->addTab(new KeyPairSubkeyTab(current_gpg_context_channel_,
- key.ID(), tab_widget_),
- tr("Keychain"));
- tab_widget_->addTab(new KeyPairOperaTab(current_gpg_context_channel_,
- key.ID(), tab_widget_),
- tr("Operations"));
+ tab_widget_->addTab(
+ new KeyPairSubkeyTab(current_gpg_context_channel_, key, tab_widget_),
+ tr("Keychain"));
+ tab_widget_->addTab(
+ new KeyPairOperaTab(current_gpg_context_channel_, key, tab_widget_),
+ tr("Operations"));
}
- QString m_key_id = key.ID();
+ QString m_key_id = key->ID();
connect(UISignalStation::GetInstance(), &UISignalStation::SignalKeyRevoked,
this, [this, m_key_id](const QString& key_id) {
if (key_id == m_key_id) this->close();
diff --git a/src/ui/dialog/keypair_details/KeyDetailsDialog.h b/src/ui/dialog/keypair_details/KeyDetailsDialog.h
index 2c7121d1..35694a27 100644
--- a/src/ui/dialog/keypair_details/KeyDetailsDialog.h
+++ b/src/ui/dialog/keypair_details/KeyDetailsDialog.h
@@ -39,7 +39,7 @@ class KeyDetailsDialog : public GeneralDialog {
Q_OBJECT
public:
- explicit KeyDetailsDialog(int channel, const GpgKey& key,
+ explicit KeyDetailsDialog(int channel, const GpgKeyPtr& key,
QWidget* parent = nullptr);
private:
diff --git a/src/ui/dialog/keypair_details/KeyNewUIDDialog.cpp b/src/ui/dialog/keypair_details/KeyNewUIDDialog.cpp
index 754999a2..d641c4d3 100644
--- a/src/ui/dialog/keypair_details/KeyNewUIDDialog.cpp
+++ b/src/ui/dialog/keypair_details/KeyNewUIDDialog.cpp
@@ -28,19 +28,17 @@
#include "KeyNewUIDDialog.h"
-#include "core/GpgModel.h"
-#include "core/function/gpg/GpgKeyGetter.h"
+#include <utility>
+
#include "core/function/gpg/GpgUIDOperator.h"
#include "ui/UISignalStation.h"
namespace GpgFrontend::UI {
-KeyNewUIDDialog::KeyNewUIDDialog(int channel, const KeyId& key_id,
- QWidget* parent)
+KeyNewUIDDialog::KeyNewUIDDialog(int channel, GpgKeyPtr key, QWidget* parent)
: GeneralDialog(typeid(KeyNewUIDDialog).name(), parent),
current_gpg_context_channel_(channel),
- m_key_(GpgKeyGetter::GetInstance(current_gpg_context_channel_)
- .GetKey(key_id)) {
- assert(m_key_.IsGood());
+ m_key_(std::move(key)) {
+ assert(m_key_ != nullptr);
name_ = new QLineEdit();
name_->setMinimumWidth(240);
@@ -51,7 +49,7 @@ KeyNewUIDDialog::KeyNewUIDDialog(int channel, const KeyId& key_id,
create_button_ = new QPushButton("Create");
error_label_ = new QLabel();
- auto grid_layout = new QGridLayout();
+ auto* grid_layout = new QGridLayout();
grid_layout->addWidget(new QLabel(tr("Name")), 0, 0);
grid_layout->addWidget(new QLabel(tr("Email")), 1, 0);
grid_layout->addWidget(new QLabel(tr("Comment")), 2, 0);
diff --git a/src/ui/dialog/keypair_details/KeyNewUIDDialog.h b/src/ui/dialog/keypair_details/KeyNewUIDDialog.h
index 45124665..f298a46b 100644
--- a/src/ui/dialog/keypair_details/KeyNewUIDDialog.h
+++ b/src/ui/dialog/keypair_details/KeyNewUIDDialog.h
@@ -45,7 +45,7 @@ class KeyNewUIDDialog : public GeneralDialog {
* @param key
* @param parent
*/
- KeyNewUIDDialog(int channel, const KeyId& key, QWidget* parent = nullptr);
+ KeyNewUIDDialog(int channel, GpgKeyPtr key, QWidget* parent = nullptr);
signals:
/**
@@ -64,7 +64,7 @@ class KeyNewUIDDialog : public GeneralDialog {
private:
int current_gpg_context_channel_;
- GpgKey m_key_; ///<
+ GpgKeyPtr m_key_; ///<
QLineEdit* name_{}; ///<
QLineEdit* email_{}; ///<
@@ -85,6 +85,6 @@ class KeyNewUIDDialog : public GeneralDialog {
* @return true
* @return false
*/
- bool check_email_address(const QString& str);
+ auto check_email_address(const QString& str) -> bool;
};
} // namespace GpgFrontend::UI
diff --git a/src/ui/dialog/keypair_details/KeyPairDetailTab.cpp b/src/ui/dialog/keypair_details/KeyPairDetailTab.cpp
index 5a646ec0..fcdc139e 100644
--- a/src/ui/dialog/keypair_details/KeyPairDetailTab.cpp
+++ b/src/ui/dialog/keypair_details/KeyPairDetailTab.cpp
@@ -28,23 +28,21 @@
#include "KeyPairDetailTab.h"
-#include "core/GpgModel.h"
+#include <utility>
+
#include "core/function/GlobalSettingStation.h"
#include "core/function/gpg/GpgKeyGetter.h"
#include "core/model/GpgKey.h"
#include "core/module/ModuleManager.h"
-#include "core/thread/TaskRunnerGetter.h"
#include "core/utils/CommonUtils.h"
#include "ui/UISignalStation.h"
namespace GpgFrontend::UI {
-KeyPairDetailTab::KeyPairDetailTab(int channel, const QString& key_id,
- QWidget* parent)
+KeyPairDetailTab::KeyPairDetailTab(int channel, GpgKeyPtr key, QWidget* parent)
: QWidget(parent),
current_gpg_context_channel_(channel),
- key_(GpgKeyGetter::GetInstance(current_gpg_context_channel_)
- .GetKey(key_id)) {
- assert(key_.IsGood());
+ key_(std::move(key)) {
+ assert(key_->IsGood());
owner_box_ = new QGroupBox(tr("Owner"));
key_box_ = new QGroupBox(tr("Primary Key"));
@@ -183,8 +181,8 @@ void KeyPairDetailTab::slot_copy_fingerprint() {
void KeyPairDetailTab::slot_refresh_key_info() {
// Show the situation that primary key not exists.
primary_key_exist_var_label_->setText(
- key_.IsHasMasterKey() ? tr("Exists") : tr("Not Exists"));
- if (!key_.IsHasMasterKey()) {
+ key_->IsHasMasterKey() ? tr("Exists") : tr("Not Exists"));
+ if (!key_->IsHasMasterKey()) {
auto palette_expired = primary_key_exist_var_label_->palette();
palette_expired.setColor(primary_key_exist_var_label_->foregroundRole(),
Qt::red);
@@ -196,7 +194,7 @@ void KeyPairDetailTab::slot_refresh_key_info() {
primary_key_exist_var_label_->setPalette(palette_valid);
}
- if (key_.IsExpired()) {
+ if (key_->IsExpired()) {
auto palette_expired = expire_var_label_->palette();
palette_expired.setColor(expire_var_label_->foregroundRole(), Qt::red);
expire_var_label_->setPalette(palette_expired);
@@ -206,42 +204,42 @@ void KeyPairDetailTab::slot_refresh_key_info() {
expire_var_label_->setPalette(palette_valid);
}
- name_var_label_->setText(key_.Name());
- email_var_label_->setText(key_.Email());
+ name_var_label_->setText(key_->Name());
+ email_var_label_->setText(key_->Email());
- comment_var_label_->setText(key_.Comment());
- key_id_var_label_->setText(key_.ID());
+ comment_var_label_->setText(key_->Comment());
+ key_id_var_label_->setText(key_->ID());
QString buffer;
QTextStream usage_steam(&buffer);
- if (key_.IsHasCertCap()) {
+ if (key_->IsHasCertCap()) {
usage_steam << tr("Certificate") << " ";
}
- if (key_.IsHasEncrCap()) usage_steam << tr("Encrypt") << " ";
- if (key_.IsHasSignCap()) usage_steam << tr("Sign") << " ";
- if (key_.IsHasAuthCap()) 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_.IsHasActualCertCap()) {
+ if (key_->IsHasActualCertCap()) {
actual_usage_steam << tr("Certificate") << " ";
}
- if (key_.IsHasActualEncrCap()) {
+ if (key_->IsHasActualEncrCap()) {
actual_usage_steam << tr("Encrypt") << " ";
}
- if (key_.IsHasActualSignCap()) {
+ if (key_->IsHasActualSignCap()) {
actual_usage_steam << tr("Sign") << " ";
}
- if (key_.IsHasActualAuthCap()) {
+ if (key_->IsHasActualAuthCap()) {
actual_usage_steam << tr("Auth") << " ";
}
actual_usage_var_label_->setText(actual_usage_steam.readAll());
- owner_trust_var_label_->setText(key_.OwnerTrust());
+ owner_trust_var_label_->setText(key_->OwnerTrust());
QString key_size_val;
QString key_expire_val;
@@ -250,41 +248,41 @@ void KeyPairDetailTab::slot_refresh_key_info() {
QString key_algo_detail_val;
QString key_last_update_val;
- key_size_val = QString::number(key_.PrimaryKeyLength());
+ key_size_val = QString::number(key_->PrimaryKeyLength());
- if (key_.ExpirationTime().toSecsSinceEpoch() == 0) {
+ if (key_->ExpirationTime().toSecsSinceEpoch() == 0) {
expire_var_label_->setText(tr("Never Expire"));
} else {
- expire_var_label_->setText(QLocale().toString((key_.ExpirationTime())));
+ expire_var_label_->setText(QLocale().toString((key_->ExpirationTime())));
}
- key_algo_val = key_.PublicKeyAlgo();
- key_algo_detail_val = key_.Algo();
+ key_algo_val = key_->PublicKeyAlgo();
+ key_algo_detail_val = key_->Algo();
- created_var_label_->setText(QLocale().toString(key_.CreationTime()));
+ created_var_label_->setText(QLocale().toString(key_->CreationTime()));
- if (key_.LastUpdateTime().toSecsSinceEpoch() == 0) {
+ if (key_->LastUpdateTime().toSecsSinceEpoch() == 0) {
last_update_var_label_->setText(tr("No Data"));
} else {
- last_update_var_label_->setText(QLocale().toString(key_.LastUpdateTime()));
+ last_update_var_label_->setText(QLocale().toString(key_->LastUpdateTime()));
}
key_size_var_label_->setText(key_size_val);
algorithm_var_label_->setText(key_algo_val);
algorithm_detail_var_label_->setText(key_algo_detail_val);
- fingerprint_var_label_->setText(BeautifyFingerprint(key_.Fingerprint()));
+ fingerprint_var_label_->setText(BeautifyFingerprint(key_->Fingerprint()));
fingerprint_var_label_->setWordWrap(true); // for x448 and ed448
icon_label_->hide();
exp_label_->hide();
- if (key_.IsExpired()) {
+ if (key_->IsExpired()) {
slot_refresh_notice(":/icons/warning.png",
tr("Warning: The primary key has expired."));
- } else if (key_.IsRevoked()) {
+ } else if (key_->IsRevoked()) {
slot_refresh_notice(":/icons/warning.png",
tr("Warning: The primary key has been revoked."));
- } else if (key_.IsPrivateKey() && !key_.IsHasMasterKey()) {
+ } else if (key_->IsPrivateKey() && !key_->IsHasMasterKey()) {
slot_refresh_notice(":/icons/warning.png",
tr("Warning: The primary key is not exists."));
} else {
@@ -294,9 +292,9 @@ void KeyPairDetailTab::slot_refresh_key_info() {
void KeyPairDetailTab::slot_refresh_key() {
// refresh the key
- GpgKey refreshed_key =
- GpgKeyGetter::GetInstance(current_gpg_context_channel_).GetKey(key_.ID());
- assert(refreshed_key.IsGood());
+ auto refreshed_key = GpgKeyGetter::GetInstance(current_gpg_context_channel_)
+ .GetKeyPtr(key_->ID());
+ assert(refreshed_key != nullptr);
std::swap(this->key_, refreshed_key);
@@ -316,7 +314,7 @@ void KeyPairDetailTab::slot_query_key_publish_state() {
return;
}
- const auto fpr = key_.Fingerprint();
+ const auto fpr = key_->Fingerprint();
Module::TriggerEvent(
"REQUEST_GET_PUBLIC_KEY_BY_FINGERPRINT",
diff --git a/src/ui/dialog/keypair_details/KeyPairDetailTab.h b/src/ui/dialog/keypair_details/KeyPairDetailTab.h
index da58e36e..d388a4af 100644
--- a/src/ui/dialog/keypair_details/KeyPairDetailTab.h
+++ b/src/ui/dialog/keypair_details/KeyPairDetailTab.h
@@ -29,6 +29,7 @@
#pragma once
#include "core/model/GpgKey.h"
+#include "core/typedef/GpgTypedef.h"
namespace GpgFrontend::UI {
@@ -68,7 +69,7 @@ class KeyPairDetailTab : public QWidget {
private:
int current_gpg_context_channel_;
- GpgKey key_; ///<
+ GpgKeyPtr key_; ///<
QGroupBox* owner_box_; ///< Groupbox containing owner information
QGroupBox* key_box_; ///< Groupbox containing key information
@@ -103,7 +104,7 @@ class KeyPairDetailTab : public QWidget {
* @param key_id
* @param parent
*/
- explicit KeyPairDetailTab(int channel, const QString& key_id,
+ explicit KeyPairDetailTab(int channel, GpgKeyPtr key,
QWidget* parent = nullptr);
};
diff --git a/src/ui/dialog/keypair_details/KeyPairOperaTab.cpp b/src/ui/dialog/keypair_details/KeyPairOperaTab.cpp
index 936997a9..dddbb545 100644
--- a/src/ui/dialog/keypair_details/KeyPairOperaTab.cpp
+++ b/src/ui/dialog/keypair_details/KeyPairOperaTab.cpp
@@ -30,7 +30,6 @@
#include "KeySetExpireDateDialog.h"
#include "core/function/GlobalSettingStation.h"
-#include "core/function/gpg//GpgKeyGetter.h"
#include "core/function/gpg/GpgKeyImportExporter.h"
#include "core/function/gpg/GpgKeyOpera.h"
#include "core/model/GpgKey.h"
@@ -46,13 +45,9 @@
namespace GpgFrontend::UI {
-KeyPairOperaTab::KeyPairOperaTab(int channel, const QString& key_id,
- QWidget* parent)
- : QWidget(parent),
- current_gpg_context_channel_(channel),
- m_key_(GpgKeyGetter::GetInstance(current_gpg_context_channel_)
- .GetKey(key_id)) {
- assert(m_key_.IsGood());
+KeyPairOperaTab::KeyPairOperaTab(int channel, GpgKeyPtr key, QWidget* parent)
+ : QWidget(parent), current_gpg_context_channel_(channel), m_key_(key) {
+ assert(m_key_ != nullptr);
// Set Menu
CreateOperaMenu();
@@ -69,13 +64,13 @@ KeyPairOperaTab::KeyPairOperaTab(int channel, const QString& key_id,
connect(export_public_button, &QPushButton::clicked, this,
&KeyPairOperaTab::slot_export_public_key);
- if (m_key_.IsPrivateKey()) {
+ if (m_key_->IsPrivateKey()) {
auto* export_private_button = new QPushButton(tr("Export Private Key"));
export_private_button->setStyleSheet("text-align:center;");
export_private_button->setMenu(secret_key_export_opera_menu_);
export_h_box_layout->addWidget(export_private_button);
- if (m_key_.IsHasMasterKey()) {
+ if (m_key_->IsHasMasterKey()) {
auto* edit_expires_button =
new QPushButton(tr("Modify Expiration Datetime (Primary Key)"));
connect(edit_expires_button, &QPushButton::clicked, this,
@@ -104,7 +99,7 @@ KeyPairOperaTab::KeyPairOperaTab(int channel, const QString& key_id,
advance_h_box_layout->addWidget(key_server_opera_button);
if (Module::IsModuleActivate(kPaperKeyModuleID)) {
- if (!m_key_.IsPrivateKey()) {
+ if (!m_key_->IsPrivateKey()) {
auto* import_paper_key_button = new QPushButton(tr("Import A Paper Key"));
import_paper_key_button->setStyleSheet("text-align:center;");
connect(import_paper_key_button, &QPushButton::clicked, this,
@@ -113,7 +108,7 @@ KeyPairOperaTab::KeyPairOperaTab(int channel, const QString& key_id,
}
}
- if (m_key_.IsPrivateKey() && m_key_.IsHasMasterKey()) {
+ if (m_key_->IsPrivateKey() && m_key_->IsHasMasterKey()) {
auto* revoke_cert_opera_button =
new QPushButton(tr("Revoke Certificate Operation"));
revoke_cert_opera_button->setStyleSheet("text-align:center;");
@@ -136,7 +131,8 @@ KeyPairOperaTab::KeyPairOperaTab(int channel, const QString& key_id,
opera_key_box->setLayout(vbox_p_k);
m_vbox->addWidget(opera_key_box);
// modify owner trust of public key
- if (!m_key_.IsPrivateKey()) vbox_p_k->addWidget(set_owner_trust_level_button);
+ if (!m_key_->IsPrivateKey())
+ vbox_p_k->addWidget(set_owner_trust_level_button);
vbox_p_k->addWidget(modify_tofu_button);
m_vbox->addStretch(0);
@@ -155,7 +151,7 @@ void KeyPairOperaTab::CreateOperaMenu() {
new QAction(tr("Publish Public Key to Key Server"), this);
connect(upload_key_pair, &QAction::triggered, this,
&KeyPairOperaTab::slot_publish_key_to_server);
- if (!(m_key_.IsPrivateKey() && m_key_.IsHasMasterKey())) {
+ if (!(m_key_->IsPrivateKey() && m_key_->IsHasMasterKey())) {
upload_key_pair->setDisabled(true);
}
@@ -165,7 +161,7 @@ void KeyPairOperaTab::CreateOperaMenu() {
&KeyPairOperaTab::slot_update_key_from_server);
// when a key has primary key, it should always upload to keyserver.
- if (m_key_.IsHasMasterKey()) {
+ if (m_key_->IsHasMasterKey()) {
update_key_pair->setDisabled(true);
}
@@ -178,7 +174,7 @@ void KeyPairOperaTab::CreateOperaMenu() {
new QAction(tr("Export Full Secret Key"), this);
connect(export_full_secret_key, &QAction::triggered, this,
&KeyPairOperaTab::slot_export_private_key);
- if (!m_key_.IsPrivateKey()) export_full_secret_key->setDisabled(true);
+ if (!m_key_->IsPrivateKey()) export_full_secret_key->setDisabled(true);
auto* export_shortest_secret_key =
new QAction(tr("Export Shortest Secret Key"), this);
@@ -189,12 +185,12 @@ void KeyPairOperaTab::CreateOperaMenu() {
secret_key_export_opera_menu_->addAction(export_shortest_secret_key);
// only work with RSA
- if (m_key_.Algo() == "RSA" && Module::IsModuleActivate(kPaperKeyModuleID)) {
+ if (m_key_->Algo() == "RSA" && Module::IsModuleActivate(kPaperKeyModuleID)) {
auto* export_secret_key_as_paper_key = new QAction(
tr("Export Secret Key As A Paper Key") + QString(" (BETA)"), this);
connect(export_secret_key_as_paper_key, &QAction::triggered, this,
&KeyPairOperaTab::slot_export_paper_key);
- if (!m_key_.IsPrivateKey()) {
+ if (!m_key_->IsPrivateKey()) {
export_secret_key_as_paper_key->setDisabled(true);
}
secret_key_export_opera_menu_->addAction(export_secret_key_as_paper_key);
@@ -228,11 +224,11 @@ void KeyPairOperaTab::slot_export_public_key() {
// generate a file name
#if defined(_WIN32) || defined(WIN32)
- auto file_string =
- m_key_.Name() + "[" + m_key_.Email() + "](" + m_key_.ID() + ")_pub.asc";
+ auto file_string = m_key_->Name() + "[" + m_key_->Email() + "](" +
+ m_key_->ID() + ")_pub.asc";
#else
- auto file_string =
- m_key_.Name() + "<" + m_key_.Email() + ">(" + m_key_.ID() + ")_pub.asc";
+ auto file_string = m_key_->Name() + "<" + m_key_->Email() + ">(" +
+ m_key_->ID() + ")_pub.asc";
#endif
std::replace(file_string.begin(), file_string.end(), ' ', '_');
@@ -277,11 +273,11 @@ void KeyPairOperaTab::slot_export_short_private_key() {
// generate a file name
#if defined(_WIN32) || defined(WIN32)
- auto file_string = m_key_.Name() + "[" + m_key_.Email() + "](" +
- m_key_.ID() + ")_short_secret.asc";
+ auto file_string = m_key_->Name() + "[" + m_key_->Email() + "](" +
+ m_key_->ID() + ")_short_secret.asc";
#else
- auto file_string = m_key_.Name() + "<" + m_key_.Email() + ">(" +
- m_key_.ID() + ")_short_secret.asc";
+ auto file_string = m_key_->Name() + "<" + m_key_->Email() + ">(" +
+ m_key_->ID() + ")_short_secret.asc";
#endif
std::replace(file_string.begin(), file_string.end(), ' ', '_');
@@ -328,11 +324,11 @@ void KeyPairOperaTab::slot_export_private_key() {
// generate a file name
#if defined(_WIN32) || defined(WIN32)
- auto file_string = m_key_.Name() + "[" + m_key_.Email() + "](" +
- m_key_.ID() + ")_full_secret.asc";
+ auto file_string = m_key_->Name() + "[" + m_key_->Email() + "](" +
+ m_key_->ID() + ")_full_secret.asc";
#else
- auto file_string = m_key_.Name() + "<" + m_key_.Email() + ">(" +
- m_key_.ID() + ")_full_secret.asc";
+ auto file_string = m_key_->Name() + "<" + m_key_->Email() + ">(" +
+ m_key_->ID() + ")_full_secret.asc";
#endif
std::replace(file_string.begin(), file_string.end(), ' ', '_');
@@ -351,8 +347,8 @@ void KeyPairOperaTab::slot_export_private_key() {
}
void KeyPairOperaTab::slot_modify_edit_datetime() {
- auto* dialog = new KeySetExpireDateDialog(current_gpg_context_channel_,
- m_key_.ID(), this);
+ auto* dialog =
+ new KeySetExpireDateDialog(current_gpg_context_channel_, m_key_, this);
dialog->show();
}
@@ -362,7 +358,7 @@ void KeyPairOperaTab::slot_publish_key_to_server() {
GpgKeyImportExporter::GetInstance(current_gpg_context_channel_)
.ExportKey(m_key_, false, true, false);
- auto fpr = m_key_.Fingerprint();
+ auto fpr = m_key_->Fingerprint();
auto key_text = gf_buffer.ConvertToQByteArray();
Module::TriggerEvent(
@@ -434,8 +430,9 @@ void KeyPairOperaTab::slot_publish_key_to_server() {
return;
}
- auto keys = KeyIdArgsList{m_key_.ID()};
- auto* dialog = new KeyUploadDialog(current_gpg_context_channel_, keys, this);
+ auto keys = KeyIdArgsList{m_key_->ID()};
+ auto* dialog =
+ new KeyUploadDialog(current_gpg_context_channel_, {m_key_}, this);
dialog->show();
dialog->SlotUpload();
}
@@ -443,11 +440,11 @@ void KeyPairOperaTab::slot_publish_key_to_server() {
void KeyPairOperaTab::slot_update_key_from_server() {
if (Module::IsModuleActivate(kKeyServerSyncModuleID)) {
CommonUtils::GetInstance()->ImportKeyByKeyServerSyncModule(
- this, current_gpg_context_channel_, {m_key_.Fingerprint()});
+ this, current_gpg_context_channel_, {m_key_->Fingerprint()});
return;
}
- CommonUtils::GetInstance()->ImportKeyFromKeyServer(
- current_gpg_context_channel_, {m_key_.ID()});
+ CommonUtils::GetInstance()->ImportGpgKeyFromKeyServer(
+ current_gpg_context_channel_, {m_key_});
}
void KeyPairOperaTab::slot_gen_revoke_cert() {
@@ -464,11 +461,11 @@ void KeyPairOperaTab::slot_gen_revoke_cert() {
QString m_output_file_name;
#if defined(_WIN32) || defined(WIN32)
- auto file_string = m_key_.Name() + "[" + m_key_.Email() + "](" +
- m_key_.ID() + ").rev";
+ auto file_string = m_key_->Name() + "[" + m_key_->Email() + "](" +
+ m_key_->ID() + ").rev";
#else
- auto file_string = m_key_.Name() + "<" + m_key_.Email() +
- ">(" + m_key_.ID() + ").rev";
+ auto file_string = m_key_->Name() + "<" + m_key_->Email() +
+ ">(" + m_key_->ID() + ").rev";
#endif
QFileDialog dialog(this, tr("Generate revocation certificate"),
@@ -529,7 +526,7 @@ void KeyPairOperaTab::slot_modify_tofu_policy() {
void KeyPairOperaTab::slot_set_owner_trust_level() {
auto* function = new SetOwnerTrustLevel(this);
- function->Exec(current_gpg_context_channel_, m_key_.ID());
+ function->Exec(current_gpg_context_channel_, m_key_);
function->deleteLater();
}
@@ -581,7 +578,7 @@ void KeyPairOperaTab::slot_import_revoke_cert() {
return;
}
- emit UISignalStation::GetInstance() -> SignalKeyRevoked(m_key_.ID());
+ emit UISignalStation::GetInstance() -> SignalKeyRevoked(m_key_->ID());
CommonUtils::GetInstance()->SlotImportKeys(
nullptr, current_gpg_context_channel_, rev_file.readAll());
}
@@ -620,11 +617,11 @@ void KeyPairOperaTab::slot_export_paper_key() {
// generate a file name
#if defined(_WIN32) || defined(WIN32)
- auto file_string = m_key_.Name() + "[" + m_key_.Email() + "](" +
- m_key_.ID() + ")_paper_key.txt";
+ auto file_string = m_key_->Name() + "[" + m_key_->Email() + "](" +
+ m_key_->ID() + ")_paper_key.txt";
#else
- auto file_string = m_key_.Name() + "<" + m_key_.Email() + ">(" +
- m_key_.ID() + ")_paper_key.txt";
+ auto file_string = m_key_->Name() + "<" + m_key_->Email() + ">(" +
+ m_key_->ID() + ")_paper_key.txt";
#endif
std::replace(file_string.begin(), file_string.end(), ' ', '_');
@@ -674,11 +671,11 @@ void KeyPairOperaTab::slot_import_paper_key() {
// generate a file name
#if defined(_WIN32) || defined(WIN32)
- auto file_string = m_key_.Name() + "[" + m_key_.Email() + "](" + m_key_.ID() +
- ")_paper_key.txt";
+ auto file_string = m_key_->Name() + "[" + m_key_->Email() + "](" +
+ m_key_->ID() + ")_paper_key.txt";
#else
- auto file_string = m_key_.Name() + "<" + m_key_.Email() + ">(" + m_key_.ID() +
- ")_paper_key.txt";
+ auto file_string = m_key_->Name() + "<" + m_key_->Email() + ">(" +
+ m_key_->ID() + ")_paper_key.txt";
#endif
std::replace(file_string.begin(), file_string.end(), ' ', '_');
diff --git a/src/ui/dialog/keypair_details/KeyPairOperaTab.h b/src/ui/dialog/keypair_details/KeyPairOperaTab.h
index 9e1f2a23..729a7d74 100644
--- a/src/ui/dialog/keypair_details/KeyPairOperaTab.h
+++ b/src/ui/dialog/keypair_details/KeyPairOperaTab.h
@@ -28,7 +28,7 @@
#pragma once
-#include "core/model/GpgKey.h"
+#include "core/typedef/GpgTypedef.h"
namespace GpgFrontend {
class GpgImportInformation;
@@ -44,7 +44,7 @@ class KeyPairOperaTab : public QWidget {
* @param key_id
* @param parent
*/
- KeyPairOperaTab(int channel, const QString& key_id, QWidget* parent);
+ KeyPairOperaTab(int channel, GpgKeyPtr key, QWidget* parent);
/**
* @brief Create a Opera Menu object
@@ -140,10 +140,9 @@ class KeyPairOperaTab : public QWidget {
private:
int current_gpg_context_channel_;
- GpgKey m_key_; ///<
+ GpgKeyPtr m_key_; ///<
QMenu* key_server_opera_menu_{}; ///<
QMenu* rev_cert_opera_menu_{};
QMenu* secret_key_export_opera_menu_{}; ///<
-
};
} // namespace GpgFrontend::UI
diff --git a/src/ui/dialog/keypair_details/KeyPairSubkeyTab.cpp b/src/ui/dialog/keypair_details/KeyPairSubkeyTab.cpp
index c4e93b62..011ea1ed 100644
--- a/src/ui/dialog/keypair_details/KeyPairSubkeyTab.cpp
+++ b/src/ui/dialog/keypair_details/KeyPairSubkeyTab.cpp
@@ -28,7 +28,8 @@
#include "KeyPairSubkeyTab.h"
-#include "core/GpgModel.h"
+#include <utility>
+
#include "core/function/gpg/GpgKeyGetter.h"
#include "core/function/gpg/GpgKeyImportExporter.h"
#include "core/function/gpg/GpgKeyManager.h"
@@ -43,13 +44,11 @@
namespace GpgFrontend::UI {
-KeyPairSubkeyTab::KeyPairSubkeyTab(int channel, const QString& key_id,
- QWidget* parent)
+KeyPairSubkeyTab::KeyPairSubkeyTab(int channel, GpgKeyPtr key, QWidget* parent)
: QWidget(parent),
current_gpg_context_channel_(channel),
- key_(GpgKeyGetter::GetInstance(current_gpg_context_channel_)
- .GetKey(key_id)) {
- assert(key_.IsGood());
+ key_(std::move(key)) {
+ assert(key_ != nullptr);
create_subkey_list();
create_subkey_opera_menu();
@@ -61,7 +60,7 @@ KeyPairSubkeyTab::KeyPairSubkeyTab(int channel, const QString& key_id,
auto* add_subkey_button = new QPushButton(tr("New Subkey"));
auto* add_adsk_button = new QPushButton(tr("Add ADSK(s)"));
- if (!key_.IsPrivateKey() || !key_.IsHasMasterKey()) {
+ if (!key_->IsPrivateKey() || !key_->IsHasMasterKey()) {
add_subkey_button->setDisabled(true);
add_subkey_button->hide();
@@ -202,7 +201,7 @@ void KeyPairSubkeyTab::slot_refresh_subkey_list() {
subkey_list_->setSelectionMode(QAbstractItemView::SingleSelection);
this->buffered_subkeys_.clear();
- for (auto& s_key : key_.SubKeys()) {
+ for (auto& s_key : key_->SubKeys()) {
this->buffered_subkeys_.push_back(std::move(s_key));
}
@@ -281,14 +280,14 @@ void KeyPairSubkeyTab::slot_refresh_subkey_list() {
void KeyPairSubkeyTab::slot_add_subkey() {
auto* dialog =
- new SubkeyGenerateDialog(current_gpg_context_channel_, key_.ID(), this);
+ new SubkeyGenerateDialog(current_gpg_context_channel_, key_, this);
dialog->show();
}
void KeyPairSubkeyTab::slot_add_adsk() {
QStringList except_key_ids;
- except_key_ids.append(key_.ID());
- for (const auto& s_key : key_.SubKeys()) {
+ except_key_ids.append(key_->ID());
+ for (const auto& s_key : key_->SubKeys()) {
except_key_ids.append(s_key.ID());
}
@@ -382,7 +381,7 @@ void KeyPairSubkeyTab::slot_refresh_subkey_detail() {
QString buffer;
QTextStream usage_steam(&buffer);
- usage_var_label_->setText(GetUsagesBySubkey(s_key));
+ usage_var_label_->setText(GetUsagesByAbstractKey(&s_key));
// Show the situation that secret key not exists.
master_key_exist_var_label_->setText(s_key.IsSecretKey() ? tr("Exists")
@@ -424,7 +423,7 @@ void KeyPairSubkeyTab::slot_refresh_subkey_detail() {
export_subkey_button_->setText(s_key.IsHasCertCap() ? tr("Export Primary Key")
: tr("Export Subkey"));
export_subkey_button_->setDisabled(
- !key_.IsPrivateKey() || s_key.IsHasCertCap() || !s_key.IsSecretKey());
+ !key_->IsPrivateKey() || s_key.IsHasCertCap() || !s_key.IsSecretKey());
key_type_var_label_->setText(s_key.IsHasCertCap() ? tr("Primary Key")
: tr("Subkey"));
@@ -467,14 +466,14 @@ void KeyPairSubkeyTab::create_subkey_opera_menu() {
void KeyPairSubkeyTab::slot_edit_subkey() {
auto* dialog =
- new KeySetExpireDateDialog(current_gpg_context_channel_, key_.ID(),
+ new KeySetExpireDateDialog(current_gpg_context_channel_, key_,
get_selected_subkey().Fingerprint(), this);
dialog->show();
}
void KeyPairSubkeyTab::contextMenuEvent(QContextMenuEvent* event) {
// must have primary key before do any actions on subkey
- if (key_.IsHasMasterKey() && !subkey_list_->selectedItems().isEmpty()) {
+ if (key_->IsHasMasterKey() && !subkey_list_->selectedItems().isEmpty()) {
const auto& s_key = get_selected_subkey();
if (s_key.IsHasCertCap()) return;
@@ -501,9 +500,9 @@ auto KeyPairSubkeyTab::get_selected_subkey() -> const GpgSubKey& {
}
void KeyPairSubkeyTab::slot_refresh_key_info() {
- key_ =
- GpgKeyGetter::GetInstance(current_gpg_context_channel_).GetKey(key_.ID());
- assert(key_.IsGood());
+ key_ = GpgKeyGetter::GetInstance(current_gpg_context_channel_)
+ .GetKeyPtr(key_->ID());
+ assert(key_ != nullptr);
}
void KeyPairSubkeyTab::slot_export_subkey() {
@@ -532,10 +531,10 @@ void KeyPairSubkeyTab::slot_export_subkey() {
// generate a file name
#if defined(_WIN32) || defined(WIN32)
auto file_string =
- key_.Name() + "[" + key_.Email() + "](" + s_key.ID() + ")_s_key.asc";
+ key_->Name() + "[" + key_->Email() + "](" + s_key.ID() + ")_s_key.asc";
#else
auto file_string =
- key_.Name() + "<" + key_.Email() + ">(" + s_key.ID() + ")_s_key.asc";
+ key_->Name() + "<" + key_->Email() + ">(" + s_key.ID() + ")_s_key.asc";
#endif
std::replace(file_string.begin(), file_string.end(), ' ', '_');
@@ -567,7 +566,7 @@ void KeyPairSubkeyTab::slot_delete_subkey() {
if (ret != QMessageBox::Yes) return;
int index = 0;
- for (const auto& sk : key_.SubKeys()) {
+ for (const auto& sk : key_->SubKeys()) {
if (sk.Fingerprint() == s_key.Fingerprint()) {
break;
}
@@ -616,7 +615,7 @@ void KeyPairSubkeyTab::slot_revoke_subkey() {
if (ret != QMessageBox::Yes) return;
int index = 0;
- for (const auto& sk : key_.SubKeys()) {
+ for (const auto& sk : key_->SubKeys()) {
if (sk.Fingerprint() == s_key.Fingerprint()) {
break;
}
diff --git a/src/ui/dialog/keypair_details/KeyPairSubkeyTab.h b/src/ui/dialog/keypair_details/KeyPairSubkeyTab.h
index d06ee032..3d9eeb50 100644
--- a/src/ui/dialog/keypair_details/KeyPairSubkeyTab.h
+++ b/src/ui/dialog/keypair_details/KeyPairSubkeyTab.h
@@ -45,7 +45,7 @@ class KeyPairSubkeyTab : public QWidget {
* @param key
* @param parent
*/
- KeyPairSubkeyTab(int channel, const QString& key, QWidget* parent);
+ KeyPairSubkeyTab(int channel, GpgKeyPtr key, QWidget* parent);
private:
/**
@@ -68,7 +68,7 @@ class KeyPairSubkeyTab : public QWidget {
auto get_selected_subkey() -> const GpgSubKey&;
int current_gpg_context_channel_;
- GpgKey key_; ///<
+ GpgKeyPtr key_; ///<
QTableWidget* subkey_list_{}; ///<
QContainer<GpgSubKey> buffered_subkeys_; ///<
diff --git a/src/ui/dialog/keypair_details/KeyPairUIDTab.cpp b/src/ui/dialog/keypair_details/KeyPairUIDTab.cpp
index a010a6ea..73428f39 100644
--- a/src/ui/dialog/keypair_details/KeyPairUIDTab.cpp
+++ b/src/ui/dialog/keypair_details/KeyPairUIDTab.cpp
@@ -28,7 +28,8 @@
#include "KeyPairUIDTab.h"
-#include "core/GpgModel.h"
+#include <utility>
+
#include "core/function/gpg/GpgKeyGetter.h"
#include "core/function/gpg/GpgKeyManager.h"
#include "core/function/gpg/GpgUIDOperator.h"
@@ -40,13 +41,11 @@
namespace GpgFrontend::UI {
-KeyPairUIDTab::KeyPairUIDTab(int channel, const QString& key_id,
- QWidget* parent)
+KeyPairUIDTab::KeyPairUIDTab(int channel, GpgKeyPtr key, QWidget* parent)
: QWidget(parent),
current_gpg_context_channel_(channel),
- m_key_(GpgKeyGetter::GetInstance(current_gpg_context_channel_)
- .GetKey(key_id)) {
- assert(m_key_.IsGood());
+ m_key_(std::move(key)) {
+ assert(m_key_ != nullptr);
create_uid_list();
create_sign_list();
@@ -57,7 +56,7 @@ KeyPairUIDTab::KeyPairUIDTab(int channel, const QString& key_id,
auto* add_uid_button = new QPushButton(tr("New UID"));
- if (!m_key_.IsHasMasterKey()) {
+ if (!m_key_->IsHasMasterKey()) {
add_uid_button->setDisabled(true);
}
uid_buttons_layout->addWidget(add_uid_button);
@@ -176,7 +175,7 @@ void KeyPairUIDTab::slot_refresh_uid_list() {
this->buffered_uids_.clear();
- for (auto& uid : m_key_.UIDs()) {
+ for (auto& uid : m_key_->UIDs()) {
this->buffered_uids_.push_back(std::move(uid));
}
@@ -316,7 +315,7 @@ void KeyPairUIDTab::slot_add_sign() {
void KeyPairUIDTab::slot_add_uid() {
auto* key_new_uid_dialog =
- new KeyNewUIDDialog(current_gpg_context_channel_, m_key_.ID(), this);
+ new KeyNewUIDDialog(current_gpg_context_channel_, m_key_, this);
connect(key_new_uid_dialog, &KeyNewUIDDialog::finished, this,
&KeyPairUIDTab::slot_add_uid_result);
connect(key_new_uid_dialog, &KeyNewUIDDialog::finished, key_new_uid_dialog,
@@ -434,7 +433,7 @@ void KeyPairUIDTab::create_uid_popup_menu() {
connect(del_uid_act_, &QAction::triggered, this,
&KeyPairUIDTab::slot_del_uid);
- if (m_key_.IsHasMasterKey()) {
+ if (m_key_->IsHasMasterKey()) {
uid_popup_menu_->addAction(set_primary_uid_act_);
uid_popup_menu_->addAction(sign_uid_act_);
uid_popup_menu_->addAction(rev_uid_act_);
@@ -516,9 +515,9 @@ void KeyPairUIDTab::slot_del_sign() {
void KeyPairUIDTab::slot_refresh_key() {
// refresh the key
- GpgKey refreshed_key = GpgKeyGetter::GetInstance(current_gpg_context_channel_)
- .GetKey(m_key_.ID());
- assert(refreshed_key.IsGood());
+ auto refreshed_key = GpgKeyGetter::GetInstance(current_gpg_context_channel_)
+ .GetKeyPtr(m_key_->ID());
+ assert(refreshed_key != nullptr);
std::swap(this->m_key_, refreshed_key);
@@ -537,7 +536,7 @@ void KeyPairUIDTab::slot_rev_uid() {
return;
}
- const auto uids = m_key_.UIDs();
+ const auto uids = m_key_->UIDs();
QString message = tr("<h3>Revoke UID Confirmation</h3><br />"
"<b>UID:</b> %1<br /><br />"
diff --git a/src/ui/dialog/keypair_details/KeyPairUIDTab.h b/src/ui/dialog/keypair_details/KeyPairUIDTab.h
index 3f98e54b..ecae16b5 100644
--- a/src/ui/dialog/keypair_details/KeyPairUIDTab.h
+++ b/src/ui/dialog/keypair_details/KeyPairUIDTab.h
@@ -43,7 +43,7 @@ class KeyPairUIDTab : public QWidget {
* @param key_id
* @param parent
*/
- KeyPairUIDTab(int channel, const QString& key_id, QWidget* parent);
+ KeyPairUIDTab(int channel, GpgKeyPtr key, QWidget* parent);
signals:
@@ -138,7 +138,7 @@ class KeyPairUIDTab : public QWidget {
private:
int current_gpg_context_channel_;
- GpgKey m_key_;
+ GpgKeyPtr m_key_;
QTableWidget* uid_list_{}; ///<
QTableWidget* sig_list_{}; ///<
QTabWidget* tofu_tabs_{}; ///<
diff --git a/src/ui/dialog/keypair_details/KeySetExpireDateDialog.cpp b/src/ui/dialog/keypair_details/KeySetExpireDateDialog.cpp
index 4880bd3d..b2d8d424 100644
--- a/src/ui/dialog/keypair_details/KeySetExpireDateDialog.cpp
+++ b/src/ui/dialog/keypair_details/KeySetExpireDateDialog.cpp
@@ -28,8 +28,9 @@
#include "KeySetExpireDateDialog.h"
+#include <utility>
+
#include "core/function/GlobalSettingStation.h"
-#include "core/function/gpg/GpgKeyGetter.h"
#include "core/function/gpg/GpgKeyOpera.h"
#include "core/utils/GpgUtils.h"
#include "ui/UISignalStation.h"
@@ -37,29 +38,27 @@
namespace GpgFrontend::UI {
-KeySetExpireDateDialog::KeySetExpireDateDialog(int channel, const KeyId& key_id,
+KeySetExpireDateDialog::KeySetExpireDateDialog(int channel, GpgKeyPtr key,
QWidget* parent)
: GeneralDialog(typeid(KeySetExpireDateDialog).name(), parent),
ui_(GpgFrontend::SecureCreateSharedObject<
Ui_ModifiedExpirationDateTime>()),
current_gpg_context_channel_(channel),
- m_key_(GpgKeyGetter::GetInstance(current_gpg_context_channel_)
- .GetKey(key_id)) {
- assert(m_key_.IsGood());
+ m_key_(std::move(key)) {
+ assert(m_key_->IsGood());
init();
}
-KeySetExpireDateDialog::KeySetExpireDateDialog(int channel, const KeyId& key_id,
+KeySetExpireDateDialog::KeySetExpireDateDialog(int channel, GpgKeyPtr key,
QString subkey_fpr,
QWidget* parent)
: GeneralDialog(typeid(KeySetExpireDateDialog).name(), parent),
ui_(GpgFrontend::SecureCreateSharedObject<
Ui_ModifiedExpirationDateTime>()),
current_gpg_context_channel_(channel),
- m_key_(GpgKeyGetter::GetInstance(current_gpg_context_channel_)
- .GetKey(key_id)),
+ m_key_(std::move(key)),
m_subkey_(std::move(subkey_fpr)) {
- assert(m_key_.IsGood());
+ assert(m_key_ != nullptr);
init();
}
@@ -101,7 +100,7 @@ void KeySetExpireDateDialog::init() {
ui_->dateEdit->setMinimumDateTime(min_date_time);
// set default date time to expire date time
- auto current_expire_time = m_key_.ExpirationTime();
+ auto current_expire_time = m_key_->ExpirationTime();
ui_->dateEdit->setDateTime(current_expire_time);
ui_->timeEdit->setDateTime(current_expire_time);
@@ -114,11 +113,11 @@ void KeySetExpireDateDialog::init() {
UISignalStation::GetInstance(),
&UISignalStation::SignalKeyDatabaseRefresh);
- if (m_key_.ExpirationTime().toSecsSinceEpoch() == 0) {
+ if (m_key_->ExpirationTime().toSecsSinceEpoch() == 0) {
ui_->noExpirationCheckBox->setCheckState(Qt::Checked);
} else {
- ui_->dateEdit->setDateTime(m_key_.ExpirationTime());
- ui_->timeEdit->setDateTime(m_key_.ExpirationTime());
+ ui_->dateEdit->setDateTime(m_key_->ExpirationTime());
+ ui_->timeEdit->setDateTime(m_key_->ExpirationTime());
}
ui_->titleLabel->setText(tr("Modified Expiration Date (Local Time)"));
diff --git a/src/ui/dialog/keypair_details/KeySetExpireDateDialog.h b/src/ui/dialog/keypair_details/KeySetExpireDateDialog.h
index 6617ff83..b75339a0 100644
--- a/src/ui/dialog/keypair_details/KeySetExpireDateDialog.h
+++ b/src/ui/dialog/keypair_details/KeySetExpireDateDialog.h
@@ -47,7 +47,7 @@ class KeySetExpireDateDialog : public GeneralDialog {
* @param key_id
* @param parent
*/
- explicit KeySetExpireDateDialog(int channel, const KeyId& key_id,
+ explicit KeySetExpireDateDialog(int channel, GpgKeyPtr key_id,
QWidget* parent = nullptr);
/**
@@ -57,7 +57,7 @@ class KeySetExpireDateDialog : public GeneralDialog {
* @param subkey_fpr
* @param parent
*/
- explicit KeySetExpireDateDialog(int channel, const KeyId& key_id,
+ explicit KeySetExpireDateDialog(int channel, GpgKeyPtr key,
QString subkey_fpr,
QWidget* parent = nullptr);
@@ -77,7 +77,7 @@ class KeySetExpireDateDialog : public GeneralDialog {
std::shared_ptr<Ui_ModifiedExpirationDateTime> ui_; ///<
int current_gpg_context_channel_; ///<
- const GpgKey m_key_; ///<
+ const GpgKeyPtr m_key_; ///<
const SubkeyId m_subkey_; ///<
private slots:
diff --git a/src/ui/dialog/keypair_details/KeyUIDSignDialog.cpp b/src/ui/dialog/keypair_details/KeyUIDSignDialog.cpp
index 2c4a8c59..46027428 100644
--- a/src/ui/dialog/keypair_details/KeyUIDSignDialog.cpp
+++ b/src/ui/dialog/keypair_details/KeyUIDSignDialog.cpp
@@ -28,22 +28,21 @@
#include "KeyUIDSignDialog.h"
-#include "core/function/gpg/GpgKeyGetter.h"
#include "core/function/gpg/GpgKeyManager.h"
#include "ui/UISignalStation.h"
#include "ui/widgets/KeyList.h"
namespace GpgFrontend::UI {
-KeyUIDSignDialog::KeyUIDSignDialog(int channel, const GpgKey& key,
+KeyUIDSignDialog::KeyUIDSignDialog(int channel, const GpgKeyPtr& key,
const QString& uid, QWidget* parent)
: GeneralDialog(typeid(KeyUIDSignDialog).name(), parent),
current_gpg_context_channel_(channel),
m_uid_(uid),
m_key_(key) {
- assert(m_key_.IsGood());
+ assert(m_key_ != nullptr);
+ const auto key_id = m_key_->ID();
- const auto key_id = m_key_.ID();
m_key_list_ = new KeyList(
channel, KeyMenuAbility::kCOLUMN_FILTER | KeyMenuAbility::kSEARCH_BAR,
GpgKeyTableColumn::kNAME | GpgKeyTableColumn::kEMAIL_ADDRESS |
@@ -51,10 +50,11 @@ KeyUIDSignDialog::KeyUIDSignDialog(int channel, const GpgKey& key,
this);
m_key_list_->AddListGroupTab(
tr("Signers"), "signers", GpgKeyTableDisplayMode::kPRIVATE_KEY,
- [key_id](const GpgKey& key) -> bool {
- return !(key.IsDisabled() || !key.IsHasCertCap() ||
- !key.IsHasMasterKey() || key.IsExpired() || key.IsRevoked() ||
- key_id == key.ID());
+ [key_id](const GpgAbstractKey* key) -> bool {
+ if (key->KeyType() != GpgAbstractKeyType::kGPG_KEY) return false;
+ return !(key->IsDisabled() || !key->IsHasCertCap() ||
+ !dynamic_cast<const GpgKey*>(key)->IsHasMasterKey() ||
+ key->IsExpired() || key->IsRevoked() || key_id == key->ID());
});
m_key_list_->SlotRefresh();
@@ -103,13 +103,11 @@ KeyUIDSignDialog::KeyUIDSignDialog(int channel, const GpgKey& key,
&UISignalStation::SignalKeyDatabaseRefresh);
}
-void KeyUIDSignDialog::slot_sign_key(bool clicked) {
+void KeyUIDSignDialog::slot_sign_key(bool) {
// Set Signers
- auto key_ids = m_key_list_->GetChecked();
- auto keys =
- GpgKeyGetter::GetInstance(current_gpg_context_channel_).GetKeys(key_ids);
+ auto keys = m_key_list_->GetSelectedKeys();
assert(std::all_of(keys.begin(), keys.end(),
- [](const auto& key) { return key.IsGood(); }));
+ [](const auto& key) { return key->IsGood(); }));
auto expires = std::make_unique<QDateTime>(expires_edit_->dateTime());
diff --git a/src/ui/dialog/keypair_details/KeyUIDSignDialog.h b/src/ui/dialog/keypair_details/KeyUIDSignDialog.h
index e40529fd..317cffdf 100644
--- a/src/ui/dialog/keypair_details/KeyUIDSignDialog.h
+++ b/src/ui/dialog/keypair_details/KeyUIDSignDialog.h
@@ -45,8 +45,8 @@ class KeyUIDSignDialog : public GeneralDialog {
* @param uid
* @param parent
*/
- explicit KeyUIDSignDialog(int channel, const GpgKey& key, const QString& uid,
- QWidget* parent = nullptr);
+ explicit KeyUIDSignDialog(int channel, const GpgKeyPtr& key,
+ const QString& uid, QWidget* parent = nullptr);
signals:
/**
@@ -63,7 +63,7 @@ class KeyUIDSignDialog : public GeneralDialog {
QCheckBox* non_expire_check_; ///<
QString m_uid_; ///<
- const GpgKey& m_key_; ///<
+ const GpgKeyPtr& m_key_; ///<
private slots:
/**