aboutsummaryrefslogtreecommitdiffstats
path: root/src/ui
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/GpgFrontendUIInit.cpp2
-rw-r--r--src/ui/UserInterfaceUtils.cpp47
-rw-r--r--src/ui/UserInterfaceUtils.h18
-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
-rw-r--r--src/ui/function/SetOwnerTrustLevel.cpp13
-rw-r--r--src/ui/function/SetOwnerTrustLevel.h3
-rw-r--r--src/ui/main_window/KeyMgmt.cpp197
-rw-r--r--src/ui/main_window/KeyMgmt.h50
-rw-r--r--src/ui/main_window/MainWindow.cpp5
-rw-r--r--src/ui/main_window/MainWindow.h13
-rw-r--r--src/ui/main_window/MainWindowGpgOperaFunction.cpp49
-rw-r--r--src/ui/main_window/MainWindowSlotFunction.cpp145
-rw-r--r--src/ui/main_window/MainWindowSlotUI.cpp41
-rw-r--r--src/ui/main_window/MainWindowUI.cpp32
-rw-r--r--src/ui/model/GpgKeyTableProxyModel.cpp43
-rw-r--r--src/ui/model/GpgKeyTableProxyModel.h4
-rw-r--r--src/ui/model/GpgKeyTreeProxyModel.cpp3
-rw-r--r--src/ui/struct/GpgOperaResultContext.h4
-rw-r--r--src/ui/widgets/KeyList.cpp249
-rw-r--r--src/ui/widgets/KeyList.h140
-rw-r--r--src/ui/widgets/KeyTable.cpp64
-rw-r--r--src/ui/widgets/KeyTable.h44
-rw-r--r--src/ui/widgets/KeyTreeView.cpp26
-rw-r--r--src/ui/widgets/KeyTreeView.h8
-rw-r--r--src/ui/widgets/VerifyKeyDetailBox.cpp23
-rw-r--r--src/ui/widgets/VerifyKeyDetailBox.h2
56 files changed, 1347 insertions, 805 deletions
diff --git a/src/ui/GpgFrontendUIInit.cpp b/src/ui/GpgFrontendUIInit.cpp
index e9c99dbc..ed9584b9 100644
--- a/src/ui/GpgFrontendUIInit.cpp
+++ b/src/ui/GpgFrontendUIInit.cpp
@@ -217,7 +217,7 @@ void WaitingAllInitializationFinished() {
auto RunGpgFrontendUI(QApplication* app) -> int {
// create main window and show it
- auto main_window = SecureCreateUniqueObject<GpgFrontend::UI::MainWindow>();
+ auto* main_window = new GpgFrontend::UI::MainWindow();
// pre-check, if application need to restart
if (CommonUtils::GetInstance()->IsApplicationNeedRestart()) {
diff --git a/src/ui/UserInterfaceUtils.cpp b/src/ui/UserInterfaceUtils.cpp
index f23eada0..ea5893c1 100644
--- a/src/ui/UserInterfaceUtils.cpp
+++ b/src/ui/UserInterfaceUtils.cpp
@@ -32,7 +32,7 @@
#include "core/GpgConstants.h"
#include "core/function/CoreSignalStation.h"
-#include "core/function/gpg/GpgKeyGetter.h"
+#include "core/function/gpg/GpgAbstractKeyGetter.h"
#include "core/model/CacheObject.h"
#include "core/model/GpgImportInformation.h"
#include "core/model/SettingsObject.h"
@@ -44,12 +44,14 @@
#include "core/utils/BuildInfoUtils.h"
#include "core/utils/GpgUtils.h"
#include "core/utils/IOUtils.h"
-#include "thread/KeyServerImportTask.h"
#include "ui/UISignalStation.h"
+#include "ui/dialog/KeyGroupManageDialog.h"
#include "ui/dialog/WaitingDialog.h"
#include "ui/dialog/controller/GnuPGControllerDialog.h"
#include "ui/dialog/import_export/KeyServerImportDialog.h"
+#include "ui/dialog/keypair_details/KeyDetailsDialog.h"
#include "ui/struct/settings_object/KeyServerSO.h"
+#include "ui/thread/KeyServerImportTask.h"
namespace GpgFrontend::UI {
@@ -450,7 +452,7 @@ void CommonUtils::slot_update_key_status() {
// flush key cache for all GpgKeyGetter Intances.
for (const auto &channel_id : GpgContext::GetAllChannelId()) {
LOG_D() << "refreshing key database at channel: " << channel_id;
- GpgKeyGetter::GetInstance(channel_id).FlushKeyCache();
+ GpgAbstractKeyGetter::GetInstance(channel_id).FlushCache();
}
LOG_D() << "refreshing key database at all channel done";
return 0;
@@ -509,7 +511,7 @@ auto CommonUtils::KeyExistsInFavoriteList(const QString &key_db_name,
}
void CommonUtils::AddKey2Favorite(const QString &key_db_name,
- const GpgKey &key) {
+ const GpgAbstractKeyPtr &key) {
{
auto json_data = CacheObject("all_favorite_key_pairs");
auto cache_obj = AllFavoriteKeyPairsCO(json_data.object());
@@ -519,7 +521,7 @@ void CommonUtils::AddKey2Favorite(const QString &key_db_name,
}
auto &key_ids = cache_obj.key_dbs[key_db_name].key_ids;
- if (!key_ids.contains(key.ID())) key_ids.append(key.ID());
+ if (!key_ids.contains(key->ID())) key_ids.append(key->ID());
json_data.setObject(cache_obj.ToJson());
LOG_D() << "current favorite key pairs: " << json_data;
@@ -529,7 +531,7 @@ void CommonUtils::AddKey2Favorite(const QString &key_db_name,
}
void CommonUtils::RemoveKeyFromFavorite(const QString &key_db_name,
- const GpgKey &key) {
+ const GpgAbstractKeyPtr &key) {
{
auto json_data = CacheObject("all_favorite_key_pairs");
auto cache_obj = AllFavoriteKeyPairsCO(json_data.object());
@@ -538,7 +540,7 @@ void CommonUtils::RemoveKeyFromFavorite(const QString &key_db_name,
QMutableListIterator<QString> i(cache_obj.key_dbs[key_db_name].key_ids);
while (i.hasNext()) {
- if (i.next() == key.ID()) i.remove();
+ if (i.next() == key->ID()) i.remove();
}
json_data.setObject(cache_obj.ToJson());
LOG_D() << "current favorite key pairs: " << json_data;
@@ -551,11 +553,16 @@ void CommonUtils::RemoveKeyFromFavorite(const QString &key_db_name,
* @brief
*
*/
-void CommonUtils::ImportKeyFromKeyServer(int channel,
- const KeyIdArgsList &key_ids) {
+void CommonUtils::ImportGpgKeyFromKeyServer(int channel,
+ const GpgKeyPtrList &keys) {
KeyServerSO key_server(SettingsObject("key_server"));
auto target_keyserver = key_server.GetTargetServer();
+ QStringList key_ids;
+ for (const auto &key : keys) {
+ key_ids.push_back(key->ID());
+ }
+
auto *task = new KeyServerImportTask(target_keyserver, channel, key_ids);
connect(task, &KeyServerImportTask::SignalKeyServerImportResult, this,
&CommonUtils::slot_update_key_from_server_finished);
@@ -619,4 +626,26 @@ void CommonUtils::ImportKeyByKeyServerSyncModule(QWidget *parent, int channel,
QString("key_%1_import_task").arg(fpr)));
}
}
+
+void CommonUtils::OpenDetailsDialogByKey(QWidget *parent, int channel,
+ const GpgAbstractKeyPtr &key) {
+ if (key == nullptr) {
+ QMessageBox::critical(parent, tr("Error"), tr("Key Not Found."));
+ return;
+ }
+
+ switch (key->KeyType()) {
+ case GpgAbstractKeyType::kGPG_KEY:
+ new KeyDetailsDialog(channel, qSharedPointerDynamicCast<GpgKey>(key),
+ parent);
+ break;
+ case GpgAbstractKeyType::kGPG_KEYGROUP:
+ new KeyGroupManageDialog(
+ channel, qSharedPointerDynamicCast<GpgKeyGroup>(key), parent);
+ case GpgAbstractKeyType::kNONE:
+ case GpgAbstractKeyType::kGPG_SUBKEY:
+ break;
+ }
+}
+
} // namespace GpgFrontend::UI \ No newline at end of file
diff --git a/src/ui/UserInterfaceUtils.h b/src/ui/UserInterfaceUtils.h
index 372bc55a..9f79cec2 100644
--- a/src/ui/UserInterfaceUtils.h
+++ b/src/ui/UserInterfaceUtils.h
@@ -62,7 +62,6 @@ void show_verify_details(QWidget* parent, InfoBoardWidget* info_board,
*/
void ImportUnknownKeyFromKeyserver(QWidget* parent,
const GpgVerifyResultAnalyse& verify_res);
-
/**
* @brief
*
@@ -133,19 +132,30 @@ class CommonUtils : public QWidget {
* @brief
*
*/
- void AddKey2Favorite(const QString& key_db_name, const GpgKey& key);
+ void AddKey2Favorite(const QString& key_db_name,
+ const GpgAbstractKeyPtr& key);
/**
* @brief
*
*/
- void RemoveKeyFromFavorite(const QString& key_db_name, const GpgKey& key);
+ void RemoveKeyFromFavorite(const QString& key_db_name,
+ const GpgAbstractKeyPtr& key);
/**
* @brief
*
*/
- void ImportKeyFromKeyServer(int channel, const KeyIdArgsList&);
+ void ImportGpgKeyFromKeyServer(int channel, const GpgKeyPtrList&);
+
+ /**
+ * @brief
+ *
+ * @param parent
+ * @param key
+ */
+ static void OpenDetailsDialogByKey(QWidget* parent, int channel,
+ const GpgAbstractKeyPtr& key);
signals:
/**
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:
/**
diff --git a/src/ui/function/SetOwnerTrustLevel.cpp b/src/ui/function/SetOwnerTrustLevel.cpp
index e99c3fa0..ed034250 100644
--- a/src/ui/function/SetOwnerTrustLevel.cpp
+++ b/src/ui/function/SetOwnerTrustLevel.cpp
@@ -28,8 +28,6 @@
#include "SetOwnerTrustLevel.h"
-#include "core/GpgModel.h"
-#include "core/function/gpg/GpgKeyGetter.h"
#include "core/function/gpg/GpgKeyManager.h"
#include "ui/UISignalStation.h"
@@ -37,13 +35,8 @@ namespace GpgFrontend::UI {
SetOwnerTrustLevel::SetOwnerTrustLevel(QWidget* parent) : QWidget(parent) {}
-auto SetOwnerTrustLevel::Exec(int channel, const QString& key_id) -> bool {
- if (key_id.isEmpty()) {
- return false;
- }
-
- auto key = GpgKeyGetter::GetInstance(channel).GetKey(key_id);
- assert(key.IsGood());
+auto SetOwnerTrustLevel::Exec(int channel, const GpgKeyPtr& key) -> bool {
+ assert(key->IsGood());
QStringList items;
@@ -52,7 +45,7 @@ auto SetOwnerTrustLevel::Exec(int channel, const QString& key_id) -> bool {
bool ok;
QString item = QInputDialog::getItem(this, tr("Modify Owner Trust Level"),
tr("Trust for the Key Pair:"), items,
- key.OwnerTrustLevel(), false, &ok);
+ key->OwnerTrustLevel(), false, &ok);
if (ok && !item.isEmpty()) {
int trust_level = 0; // Unknown Level
diff --git a/src/ui/function/SetOwnerTrustLevel.h b/src/ui/function/SetOwnerTrustLevel.h
index ee2e98c8..00309f4d 100644
--- a/src/ui/function/SetOwnerTrustLevel.h
+++ b/src/ui/function/SetOwnerTrustLevel.h
@@ -29,6 +29,7 @@
#pragma once
#include "GpgFrontendUI.h"
+#include "core/typedef/GpgTypedef.h"
namespace GpgFrontend::UI {
@@ -49,7 +50,7 @@ class SetOwnerTrustLevel : public QWidget {
* @return true
* @return false
*/
- auto Exec(int channel, const QString& key_id) -> bool;
+ auto Exec(int channel, const GpgKeyPtr& key) -> bool;
};
} // namespace GpgFrontend::UI \ No newline at end of file
diff --git a/src/ui/main_window/KeyMgmt.cpp b/src/ui/main_window/KeyMgmt.cpp
index 59e7a658..cd5a9f05 100644
--- a/src/ui/main_window/KeyMgmt.cpp
+++ b/src/ui/main_window/KeyMgmt.cpp
@@ -30,7 +30,6 @@
#include "core/function/GlobalSettingStation.h"
#include "core/function/KeyPackageOperator.h"
-#include "core/function/gpg/GpgKeyGetter.h"
#include "core/function/gpg/GpgKeyImportExporter.h"
#include "core/function/gpg/GpgKeyOpera.h"
#include "core/model/GpgImportInformation.h"
@@ -43,7 +42,6 @@
#include "ui/dialog/import_export/KeyImportDetailDialog.h"
#include "ui/dialog/key_generate/KeyGenerateDialog.h"
#include "ui/dialog/key_generate/SubkeyGenerateDialog.h"
-#include "ui/dialog/keypair_details/KeyDetailsDialog.h"
#include "ui/function/GpgOperaHelper.h"
#include "ui/main_window/MainWindow.h"
#include "ui/widgets/KeyList.h"
@@ -62,25 +60,28 @@ KeyMgmt::KeyMgmt(QWidget* parent)
key_list_->AddListGroupTab(
tr("Only Public Key"), "only_public_key",
- GpgKeyTableDisplayMode::kPUBLIC_KEY, [](const GpgKey& key) -> bool {
- return !key.IsPrivateKey() &&
- !(key.IsRevoked() || key.IsDisabled() || key.IsExpired());
+ GpgKeyTableDisplayMode::kPUBLIC_KEY,
+ [](const GpgAbstractKey* key) -> bool {
+ return !key->IsPrivateKey() &&
+ !(key->IsRevoked() || key->IsDisabled() || key->IsExpired());
});
key_list_->AddListGroupTab(
tr("Has Private Key"), "has_private_key",
- GpgKeyTableDisplayMode::kPRIVATE_KEY, [](const GpgKey& key) -> bool {
- return key.IsPrivateKey() &&
- !(key.IsRevoked() || key.IsDisabled() || key.IsExpired());
+ GpgKeyTableDisplayMode::kPRIVATE_KEY,
+ [](const GpgAbstractKey* key) -> bool {
+ return key->IsPrivateKey() &&
+ !(key->IsRevoked() || key->IsDisabled() || key->IsExpired());
});
key_list_->AddListGroupTab(
tr("No Primary Key"), "no_primary_key",
GpgKeyTableDisplayMode::kPUBLIC_KEY |
GpgKeyTableDisplayMode::kPRIVATE_KEY,
- [](const GpgKey& key) -> bool {
- return !key.IsHasMasterKey() &&
- !(key.IsRevoked() || key.IsDisabled() || key.IsExpired());
+ [](const GpgAbstractKey* key) -> bool {
+ if (key->KeyType() != GpgAbstractKeyType::kGPG_KEY) return false;
+ return !dynamic_cast<const GpgKey*>(key)->IsHasMasterKey() &&
+ !(key->IsRevoked() || key->IsDisabled() || key->IsExpired());
});
key_list_->AddListGroupTab(
@@ -88,14 +89,20 @@ KeyMgmt::KeyMgmt(QWidget* parent)
GpgKeyTableDisplayMode::kPUBLIC_KEY |
GpgKeyTableDisplayMode::kPRIVATE_KEY,
- [](const GpgKey& key) -> bool { return key.IsRevoked(); });
+ [](const GpgAbstractKey* key) -> bool { return key->IsRevoked(); });
key_list_->AddListGroupTab(
tr("Expired"), "expired",
GpgKeyTableDisplayMode::kPUBLIC_KEY |
GpgKeyTableDisplayMode::kPRIVATE_KEY,
- [](const GpgKey& key) -> bool { return key.IsExpired(); });
+ [](const GpgAbstractKey* key) -> bool { return key->IsExpired(); });
+
+ key_list_->AddListGroupTab(
+ tr("Disabled"), "disabled",
+ GpgKeyTableDisplayMode::kPUBLIC_KEY |
+ GpgKeyTableDisplayMode::kPRIVATE_KEY,
+ [](const GpgAbstractKey* key) -> bool { return key->IsDisabled(); });
setCentralWidget(key_list_);
@@ -248,12 +255,11 @@ void KeyMgmt::create_actions() {
set_owner_trust_of_key_act_->setToolTip(tr("Set Owner Trust Level"));
set_owner_trust_of_key_act_->setData(QVariant("set_owner_trust_level"));
connect(set_owner_trust_of_key_act_, &QAction::triggered, this, [this]() {
- auto keys_selected = key_list_->GetSelected();
- if (keys_selected.empty()) return;
+ auto key = key_list_->GetSelectedGpgKey();
+ if (key == nullptr) return;
auto* function = new SetOwnerTrustLevel(this);
- function->Exec(key_list_->GetCurrentGpgContextChannel(),
- keys_selected.front());
+ function->Exec(key_list_->GetCurrentGpgContextChannel(), key);
function->deleteLater();
});
}
@@ -313,29 +319,22 @@ void KeyMgmt::create_tool_bars() {
}
void KeyMgmt::SlotDeleteSelectedKeys() {
- delete_keys_with_warning(key_list_->GetSelected());
+ delete_keys_with_warning(key_list_->GetSelectedKeys());
}
void KeyMgmt::SlotDeleteCheckedKeys() {
- delete_keys_with_warning(key_list_->GetChecked());
+ delete_keys_with_warning(key_list_->GetCheckedKeys());
}
-void KeyMgmt::delete_keys_with_warning(KeyIdArgsList uid_list) {
- /**
- * TODO: Different Messages for private/public key, check if
- * more than one selected... compare to seahorse "delete-dialog"
- */
+void KeyMgmt::delete_keys_with_warning(const GpgAbstractKeyPtrList& keys) {
+ if (keys.empty()) return;
- if (uid_list.empty()) return;
QString keynames;
- for (const auto& key_id : uid_list) {
- auto key =
- GpgKeyGetter::GetInstance(key_list_->GetCurrentGpgContextChannel())
- .GetKey(key_id);
- if (!key.IsGood()) continue;
- keynames.append(key.Name());
+ for (const auto& key : keys) {
+ if (!key->IsGood()) continue;
+ keynames.append(key->Name());
keynames.append("<i> &lt;");
- keynames.append(key.Email());
+ keynames.append(key->Email());
keynames.append("&gt; </i><br/>");
}
@@ -348,96 +347,79 @@ void KeyMgmt::delete_keys_with_warning(KeyIdArgsList uid_list) {
if (ret == QMessageBox::Yes) {
GpgKeyOpera::GetInstance(key_list_->GetCurrentGpgContextChannel())
- .DeleteKeys(std::move(uid_list));
+ .DeleteKeys(keys);
emit SignalKeyStatusUpdated();
}
}
void KeyMgmt::SlotShowKeyDetails() {
- auto [succ, key] = key_list_->GetSelectedGpgKey();
- if (!succ) return;
+ auto keys = key_list_->GetSelectedKeys();
+ if (keys.isEmpty()) return;
- new KeyDetailsDialog(key_list_->GetCurrentGpgContextChannel(), key, this);
+ CommonUtils::OpenDetailsDialogByKey(
+ this, key_list_->GetCurrentGpgContextChannel(), keys.front());
}
void KeyMgmt::SlotExportKeyToKeyPackage() {
- auto keys_checked = key_list_->GetChecked();
- if (keys_checked.empty()) {
+ auto keys = key_list_->GetCheckedKeys();
+ if (keys.empty()) {
QMessageBox::critical(
this, tr("Forbidden"),
tr("Please check some keys before doing this operation."));
return;
}
+
auto* dialog = new ExportKeyPackageDialog(
- key_list_->GetCurrentGpgContextChannel(), std::move(keys_checked), this);
+ key_list_->GetCurrentGpgContextChannel(), keys, this);
dialog->exec();
emit SignalStatusBarChanged(tr("key(s) exported"));
}
void KeyMgmt::SlotExportKeyToClipboard() {
- auto keys_checked = key_list_->GetChecked();
- if (keys_checked.empty()) {
+ auto keys = key_list_->GetCheckedKeys();
+ if (keys.empty()) {
QMessageBox::critical(
this, tr("Forbidden"),
tr("Please check some keys before doing this operation."));
return;
}
- if (keys_checked.size() == 1) {
- auto key =
- GpgKeyGetter::GetInstance(key_list_->GetCurrentGpgContextChannel())
- .GetKey(keys_checked.front());
- assert(key.IsGood());
-
- auto [err, gf_buffer] = GpgKeyImportExporter::GetInstance(
- key_list_->GetCurrentGpgContextChannel())
- .ExportKey(key, false, true, false);
- if (CheckGpgError(err) != GPG_ERR_NO_ERROR) {
- CommonUtils::RaiseMessageBox(this, err);
- return;
- }
- QApplication::clipboard()->setText(gf_buffer.ConvertToQByteArray());
- } else {
- auto keys =
- GpgKeyGetter::GetInstance(key_list_->GetCurrentGpgContextChannel())
- .GetKeys(keys_checked);
- assert(std::all_of(keys.begin(), keys.end(),
- [](const auto& key) { return key.IsGood(); }));
-
- GpgOperaHelper::WaitForOpera(
- this, tr("Exporting"), [=](const OperaWaitingHd& op_hd) {
- GpgKeyImportExporter::GetInstance(
- key_list_->GetCurrentGpgContextChannel())
- .ExportKeys(
- keys, false, true, false, false,
- [=](GpgError err, const DataObjectPtr& data_obj) {
- // stop waiting
- op_hd();
-
- if (CheckGpgError(err) == GPG_ERR_USER_1) {
- QMessageBox::critical(this, tr("Error"),
- tr("Unknown error occurred"));
- return;
- }
-
- if (CheckGpgError(err) != GPG_ERR_NO_ERROR) {
- CommonUtils::RaiseMessageBox(this, err);
- return;
- }
-
- if (data_obj == nullptr || !data_obj->Check<GFBuffer>()) {
- FLOG_W("data object checking failed");
- QMessageBox::critical(this, tr("Error"),
- tr("Unknown error occurred"));
- return;
- }
-
- auto gf_buffer = ExtractParams<GFBuffer>(data_obj, 0);
- QApplication::clipboard()->setText(
- gf_buffer.ConvertToQByteArray());
- });
- });
- }
+ assert(std::all_of(keys.begin(), keys.end(),
+ [](const auto& key) { return key->IsGood(); }));
+
+ GpgOperaHelper::WaitForOpera(
+ this, tr("Exporting"), [=](const OperaWaitingHd& op_hd) {
+ GpgKeyImportExporter::GetInstance(
+ key_list_->GetCurrentGpgContextChannel())
+ .ExportKeys(
+ keys, false, true, false, false,
+ [=](GpgError err, const DataObjectPtr& data_obj) {
+ // stop waiting
+ op_hd();
+
+ if (CheckGpgError(err) == GPG_ERR_USER_1) {
+ QMessageBox::critical(this, tr("Error"),
+ tr("Unknown error occurred"));
+ return;
+ }
+
+ if (CheckGpgError(err) != GPG_ERR_NO_ERROR) {
+ CommonUtils::RaiseMessageBox(this, err);
+ return;
+ }
+
+ if (data_obj == nullptr || !data_obj->Check<GFBuffer>()) {
+ FLOG_W("data object checking failed");
+ QMessageBox::critical(this, tr("Error"),
+ tr("Unknown error occurred"));
+ return;
+ }
+
+ auto gf_buffer = ExtractParams<GFBuffer>(data_obj, 0);
+ QApplication::clipboard()->setText(
+ gf_buffer.ConvertToQByteArray());
+ });
+ });
}
void KeyMgmt::SlotGenerateKeyDialog() {
@@ -447,43 +429,40 @@ void KeyMgmt::SlotGenerateKeyDialog() {
}
void KeyMgmt::SlotGenerateSubKey() {
- auto [succ, key] = key_list_->GetSelectedGpgKey();
- if (!succ) return;
+ auto key = key_list_->GetSelectedGpgKey();
+ if (key == nullptr) return;
- if (!key.IsPrivateKey()) {
+ if (!key->IsPrivateKey()) {
QMessageBox::critical(this, tr("Invalid Operation"),
tr("If a key pair does not have a private key then "
"it will not be able to generate sub-keys."));
return;
}
- (new SubkeyGenerateDialog(key_list_->GetCurrentGpgContextChannel(), key.ID(),
+ (new SubkeyGenerateDialog(key_list_->GetCurrentGpgContextChannel(), key,
this))
->exec();
this->raise();
}
void KeyMgmt::SlotExportAsOpenSSHFormat() {
- auto keys_checked = key_list_->GetChecked();
- if (keys_checked.empty()) {
+ auto keys = key_list_->GetCheckedKeys();
+ if (keys.empty()) {
QMessageBox::critical(
this, tr("Forbidden"),
tr("Please check a key before performing this operation."));
return;
}
- if (keys_checked.size() > 1) {
+ assert(std::all_of(keys.begin(), keys.end(),
+ [](const auto& key) { return key->IsGood(); }));
+
+ if (keys.size() > 1) {
QMessageBox::critical(this, tr("Forbidden"),
tr("This operation accepts just a single key."));
return;
}
- auto keys =
- GpgKeyGetter::GetInstance(key_list_->GetCurrentGpgContextChannel())
- .GetKeys(keys_checked);
- assert(std::all_of(keys.begin(), keys.end(),
- [](const auto& key) { return key.IsGood(); }));
-
GpgOperaHelper::WaitForOpera(
this, tr("Exporting"), [this, keys](const OperaWaitingHd& op_hd) {
GpgKeyImportExporter::GetInstance(
diff --git a/src/ui/main_window/KeyMgmt.h b/src/ui/main_window/KeyMgmt.h
index c0c004af..b25cfaaa 100644
--- a/src/ui/main_window/KeyMgmt.h
+++ b/src/ui/main_window/KeyMgmt.h
@@ -121,31 +121,6 @@ class KeyMgmt : public GeneralMainWindow {
void SignalKeyStatusUpdated();
private:
- /**
- * @brief Create a menus object
- *
- */
- void create_menus();
-
- /**
- * @brief Create a actions object
- *
- */
- void create_actions();
-
- /**
- * @brief Create a tool bars object
- *
- */
- void create_tool_bars();
-
- /**
- * @brief
- *
- * @param uidList
- */
- void delete_keys_with_warning(KeyIdArgsList uid_list);
-
KeyList* key_list_; ///<
QMenu* file_menu_{}; ///<
QMenu* key_menu_{}; ///<
@@ -169,6 +144,31 @@ class KeyMgmt : public GeneralMainWindow {
QAction* close_act_{}; ///<
QAction* show_key_details_act_{}; ///<
QAction* set_owner_trust_of_key_act_{};
+
+ /**
+ * @brief Create a menus object
+ *
+ */
+ void create_menus();
+
+ /**
+ * @brief Create a actions object
+ *
+ */
+ void create_actions();
+
+ /**
+ * @brief Create a tool bars object
+ *
+ */
+ void create_tool_bars();
+
+ /**
+ * @brief
+ *
+ * @param uidList
+ */
+ void delete_keys_with_warning(const GpgAbstractKeyPtrList& keys);
};
} // namespace GpgFrontend::UI
diff --git a/src/ui/main_window/MainWindow.cpp b/src/ui/main_window/MainWindow.cpp
index 698cd535..5ebfbb00 100644
--- a/src/ui/main_window/MainWindow.cpp
+++ b/src/ui/main_window/MainWindow.cpp
@@ -60,7 +60,8 @@ void MainWindow::Init() noexcept {
kGpgFrontendDefaultChannel,
KeyMenuAbility::kREFRESH | KeyMenuAbility::kCHECK_ALL |
KeyMenuAbility::kUNCHECK_ALL | KeyMenuAbility::kCOLUMN_FILTER |
- KeyMenuAbility::kSEARCH_BAR | KeyMenuAbility::kKEY_DATABASE,
+ KeyMenuAbility::kSEARCH_BAR | KeyMenuAbility::kKEY_DATABASE |
+ KeyMenuAbility::kKEY_GROUP,
GpgKeyTableColumn::kTYPE | GpgKeyTableColumn::kNAME |
GpgKeyTableColumn::kKEY_ID | GpgKeyTableColumn::kEMAIL_ADDRESS |
GpgKeyTableColumn::kUSAGE | GpgKeyTableColumn::kOWNER_TRUST |
@@ -138,6 +139,8 @@ void MainWindow::Init() noexcept {
// recover unsaved page from cache if it exists
recover_editor_unsaved_pages_from_cache();
+ slot_update_operations_menu_by_checked_keys();
+
// check if need to open wizard window
if (GetSettings().value("wizard/show_wizard", true).toBool()) {
slot_start_wizard();
diff --git a/src/ui/main_window/MainWindow.h b/src/ui/main_window/MainWindow.h
index 58aa406d..6eb4da65 100644
--- a/src/ui/main_window/MainWindow.h
+++ b/src/ui/main_window/MainWindow.h
@@ -522,6 +522,13 @@ class MainWindow : public GeneralMainWindow {
void slot_gpg_opera_buffer_show_helper(
const QContainer<GpgOperaResult>& results);
+ /**
+ * @brief
+ *
+ * @param results
+ */
+ void slot_update_operations_menu_by_checked_keys();
+
private:
/**
* @details Create actions for the main-menu and the context-menu of the
@@ -625,9 +632,9 @@ class MainWindow : public GeneralMainWindow {
* @return GpgKeyList
*/
auto check_keys_helper(
- const KeyIdArgsList& key_ids,
- const std::function<bool(const GpgKey&)>& capability_check,
- const QString& capability_err_string) -> GpgKeyList;
+ const GpgAbstractKeyPtrList& keys,
+ const std::function<bool(const GpgAbstractKeyPtr&)>& capability_check,
+ const QString& capability_err_string) -> GpgAbstractKeyPtrList;
/**
* @brief
diff --git a/src/ui/main_window/MainWindowGpgOperaFunction.cpp b/src/ui/main_window/MainWindowGpgOperaFunction.cpp
index dc65fd1c..925950eb 100644
--- a/src/ui/main_window/MainWindowGpgOperaFunction.cpp
+++ b/src/ui/main_window/MainWindowGpgOperaFunction.cpp
@@ -27,8 +27,6 @@
*/
#include "MainWindow.h"
-#include "core/function/GlobalSettingStation.h"
-#include "core/function/gpg/GpgKeyGetter.h"
#include "core/utils/GpgUtils.h"
#include "core/utils/IOUtils.h"
#include "ui/UserInterfaceUtils.h"
@@ -42,10 +40,10 @@ namespace GpgFrontend::UI {
auto MainWindow::encrypt_operation_key_validate(
const QSharedPointer<GpgOperaContextBasement>& contexts) -> bool {
- auto key_ids = m_key_list_->GetChecked();
+ auto keys = m_key_list_->GetCheckedKeys();
// symmetric encryption
- if (key_ids.isEmpty()) {
+ if (keys.isEmpty()) {
auto ret = QMessageBox::information(
this, tr("Symmetric Encryption"),
tr("No Key Selected. Do you want to encrypt with a "
@@ -56,7 +54,7 @@ auto MainWindow::encrypt_operation_key_validate(
contexts->keys = {};
} else {
contexts->keys = check_keys_helper(
- key_ids, [](const GpgKey& key) { return key.IsHasActualEncrCap(); },
+ keys, [](const GpgAbstractKeyPtr& key) { return key->IsHasEncrCap(); },
tr("The selected keypair cannot be used for encryption."));
if (contexts->keys.empty()) return false;
}
@@ -75,12 +73,9 @@ auto MainWindow::sign_operation_key_validate(
// return when canceled
if (!signers_picker->GetStatus()) return false;
- auto signer_key_ids = signers_picker->GetCheckedSigners();
- auto signer_keys =
- GpgKeyGetter::GetInstance(m_key_list_->GetCurrentGpgContextChannel())
- .GetKeys(signer_key_ids);
+ auto signer_keys = signers_picker->GetCheckedSigners();
assert(std::all_of(signer_keys.begin(), signer_keys.end(),
- [](const auto& key) { return key.IsGood(); }));
+ [](const auto& key) { return key->IsGood(); }));
contexts->singer_keys = signer_keys;
@@ -150,21 +145,18 @@ auto MainWindow::check_write_file_paths_helper(const QStringList& o_paths)
}
auto MainWindow::check_keys_helper(
- const KeyIdArgsList& key_ids,
- const std::function<bool(const GpgKey&)>& capability_check,
- const QString& capability_err_string) -> GpgKeyList {
- if (key_ids.empty()) {
+ const GpgAbstractKeyPtrList& keys,
+ const std::function<bool(const GpgAbstractKeyPtr&)>& capability_check,
+ const QString& capability_err_string) -> GpgAbstractKeyPtrList {
+ if (keys.isEmpty()) {
QMessageBox::critical(
this, tr("No Key Checked"),
tr("Please check the key in the key toolbox on the right."));
return {};
}
- auto keys =
- GpgKeyGetter::GetInstance(m_key_list_->GetCurrentGpgContextChannel())
- .GetKeys(key_ids);
assert(std::all_of(keys.begin(), keys.end(),
- [](const auto& key) { return key.IsGood(); }));
+ [](const auto& key) { return key->IsGood(); }));
// check key abilities
for (const auto& key : keys) {
@@ -172,7 +164,7 @@ auto MainWindow::check_keys_helper(
QMessageBox::critical(nullptr, tr("Invalid KeyPair"),
capability_err_string + "<br/><br/>" +
tr("For example the Following Key:") +
- " <br/>" + key.UIDs().front().GetUID());
+ " <br/>" + key->Email());
return {};
}
}
@@ -202,9 +194,10 @@ void MainWindow::SlotSign() {
auto contexts = QSharedPointer<GpgOperaContextBasement>::create();
contexts->ascii = true;
- auto key_ids = m_key_list_->GetChecked();
+ auto keys = m_key_list_->GetCheckedKeys();
+
contexts->keys = check_keys_helper(
- key_ids, [](const GpgKey& key) { return key.IsHasActualSignCap(); },
+ keys, [](const GpgAbstractKeyPtr& key) { return key->IsHasSignCap(); },
tr("The selected key contains a key that does not actually have a "
"sign usage."));
if (contexts->keys.empty()) return;
@@ -255,9 +248,10 @@ void MainWindow::SlotEncryptSign() {
auto contexts = QSharedPointer<GpgOperaContextBasement>::create();
contexts->ascii = true;
- auto key_ids = m_key_list_->GetChecked();
+ auto keys = m_key_list_->GetCheckedKeys();
+
contexts->keys = check_keys_helper(
- key_ids, [](const GpgKey& key) { return key.IsHasActualEncrCap(); },
+ keys, [](const GpgAbstractKeyPtr& key) { return key->IsHasEncrCap(); },
tr("The selected keypair cannot be used for encryption."));
if (contexts->keys.empty()) return;
@@ -363,9 +357,10 @@ void MainWindow::SlotFileSign(const QStringList& paths, bool ascii) {
contexts->ascii = ascii;
- auto key_ids = m_key_list_->GetChecked();
+ auto keys = m_key_list_->GetCheckedKeys();
+
contexts->keys = check_keys_helper(
- key_ids, [](const GpgKey& key) { return key.IsHasActualSignCap(); },
+ keys, [](const GpgAbstractKeyPtr& key) { return key->IsHasSignCap(); },
tr("The selected key contains a key that does not actually have a "
"sign usage."));
if (contexts->keys.empty()) return;
@@ -442,9 +437,9 @@ void MainWindow::SlotFileEncryptSign(const QStringList& paths, bool ascii) {
auto contexts = QSharedPointer<GpgOperaContextBasement>::create();
contexts->ascii = ascii;
- auto key_ids = m_key_list_->GetChecked();
+ auto keys = m_key_list_->GetCheckedKeys();
contexts->keys = check_keys_helper(
- key_ids, [](const GpgKey& key) { return key.IsHasActualEncrCap(); },
+ keys, [](const GpgAbstractKeyPtr& key) { return key->IsHasEncrCap(); },
tr("The selected keypair cannot be used for encryption."));
if (contexts->keys.empty()) return;
diff --git a/src/ui/main_window/MainWindowSlotFunction.cpp b/src/ui/main_window/MainWindowSlotFunction.cpp
index fb4f9e73..b19c15e8 100644
--- a/src/ui/main_window/MainWindowSlotFunction.cpp
+++ b/src/ui/main_window/MainWindowSlotFunction.cpp
@@ -27,7 +27,6 @@
*/
#include "MainWindow.h"
-#include "core/function/gpg/GpgKeyGetter.h"
#include "core/function/gpg/GpgKeyImportExporter.h"
#include "core/function/result_analyse/GpgDecryptResultAnalyse.h"
#include "core/function/result_analyse/GpgEncryptResultAnalyse.h"
@@ -45,7 +44,6 @@
#include "ui/dialog/SignersPicker.h"
#include "ui/dialog/help/AboutDialog.h"
#include "ui/dialog/import_export/KeyUploadDialog.h"
-#include "ui/dialog/keypair_details/KeyDetailsDialog.h"
#include "ui/function/GpgOperaHelper.h"
#include "ui/function/SetOwnerTrustLevel.h"
#include "ui/struct/GpgOperaResult.h"
@@ -71,25 +69,12 @@ void MainWindow::slot_find() {
* Append the selected (not checked!) Key(s) To Textedit
*/
void MainWindow::slot_append_selected_keys() {
- auto key_ids = m_key_list_->GetSelected();
-
- if (key_ids.empty()) {
- FLOG_W("no key is selected to export");
- return;
- }
-
- auto key =
- GpgKeyGetter::GetInstance(m_key_list_->GetCurrentGpgContextChannel())
- .GetKey(key_ids.front());
- if (!key.IsGood()) {
- LOG_W() << "selected key for exporting is invalid, key id: "
- << key_ids.front();
- return;
- }
+ auto keys = m_key_list_->GetSelectedKeys();
+ if (keys.empty()) return;
auto [err, gf_buffer] = GpgKeyImportExporter::GetInstance(
m_key_list_->GetCurrentGpgContextChannel())
- .ExportKey(key, false, true, false);
+ .ExportKey(keys.front(), false, true, false);
if (CheckGpgError(err) != GPG_ERR_NO_ERROR) {
CommonUtils::RaiseMessageBox(this, err);
return;
@@ -99,123 +84,121 @@ void MainWindow::slot_append_selected_keys() {
}
void MainWindow::slot_append_keys_create_datetime() {
- auto [succ, key] = m_key_list_->GetSelectedGpgKey();
- if (!succ) return;
+ auto key = m_key_list_->GetSelectedKey();
+ if (key == nullptr) return;
auto create_datetime_format_str_local =
- QLocale().toString(key.CreationTime()) + " (" + tr("Localize") + ") " +
+ QLocale().toString(key->CreationTime()) + " (" + tr("Localize") + ") " +
"\n";
auto create_datetime_format_str =
- QLocale().toString(key.CreationTime().toUTC()) + " (" + tr("UTC") + ") " +
- "\n ";
+ QLocale().toString(key->CreationTime().toUTC()) + " (" + tr("UTC") +
+ ") " + "\n ";
edit_->SlotAppendText2CurTextPage(create_datetime_format_str_local +
create_datetime_format_str);
}
void MainWindow::slot_append_keys_expire_datetime() {
- auto [succ, key] = m_key_list_->GetSelectedGpgKey();
- if (!succ) return;
+ auto key = m_key_list_->GetSelectedKey();
+ if (key == nullptr) return;
auto expire_datetime_format_str_local =
- QLocale().toString(key.ExpirationTime()) + " (" + tr("Local Time") +
+ QLocale().toString(key->ExpirationTime()) + " (" + tr("Local Time") +
") " + "\n";
auto expire_datetime_format_str =
- QLocale().toString(key.ExpirationTime().toUTC()) + " (UTC) " + "\n";
+ QLocale().toString(key->ExpirationTime().toUTC()) + " (UTC) " + "\n";
edit_->SlotAppendText2CurTextPage(expire_datetime_format_str_local +
expire_datetime_format_str);
}
void MainWindow::slot_append_keys_fingerprint() {
- auto [succ, key] = m_key_list_->GetSelectedGpgKey();
- if (!succ) return;
+ auto key = m_key_list_->GetSelectedKey();
+ if (key == nullptr) return;
- auto fingerprint_format_str = BeautifyFingerprint(key.Fingerprint()) + "\n";
+ auto fingerprint_format_str = BeautifyFingerprint(key->Fingerprint()) + "\n";
edit_->SlotAppendText2CurTextPage(fingerprint_format_str);
}
void MainWindow::slot_copy_mail_address_to_clipboard() {
- auto [succ, key] = m_key_list_->GetSelectedGpgKey();
- if (!succ) return;
+ auto key = m_key_list_->GetSelectedKey();
+ if (key == nullptr) return;
QClipboard* cb = QApplication::clipboard();
- cb->setText(key.Email());
+ cb->setText(key->Email());
}
void MainWindow::slot_copy_default_uid_to_clipboard() {
- auto [succ, key] = m_key_list_->GetSelectedGpgKey();
- if (!succ) return;
+ auto key = m_key_list_->GetSelectedKey();
+ if (key == nullptr || key->KeyType() != GpgAbstractKeyType::kGPG_KEY) return;
QClipboard* cb = QApplication::clipboard();
- cb->setText(key.UIDs().front().GetUID());
+ cb->setText(qSharedPointerDynamicCast<GpgKey>(key)->UIDs().front().GetUID());
}
void MainWindow::slot_copy_key_id_to_clipboard() {
- auto [succ, key] = m_key_list_->GetSelectedGpgKey();
- if (!succ) return;
+ auto key = m_key_list_->GetSelectedKey();
+ if (key == nullptr) return;
QClipboard* cb = QApplication::clipboard();
- cb->setText(key.ID());
+ cb->setText(key->ID());
}
void MainWindow::slot_show_key_details() {
- auto [succ, key] = m_key_list_->GetSelectedGpgKey();
- if (!succ) return;
+ auto keys = m_key_list_->GetSelectedKeys();
+ if (keys.isEmpty()) return;
- new KeyDetailsDialog(m_key_list_->GetCurrentGpgContextChannel(), key, this);
+ CommonUtils::OpenDetailsDialogByKey(
+ this, m_key_list_->GetCurrentGpgContextChannel(), keys.front());
}
void MainWindow::slot_add_key_2_favorite() {
- auto [succ, key] = m_key_list_->GetSelectedGpgKey();
- if (!succ) return;
+ auto key = m_key_list_->GetSelectedKey();
+ if (key == nullptr) return;
auto key_db_name =
GetGpgKeyDatabaseName(m_key_list_->GetCurrentGpgContextChannel());
- LOG_D() << "add key" << key.ID() << "to favorite at key db" << key_db_name;
+ LOG_D() << "add key" << key->ID() << "to favorite at key db" << key_db_name;
CommonUtils::GetInstance()->AddKey2Favorite(key_db_name, key);
emit SignalUIRefresh();
}
void MainWindow::slot_remove_key_from_favorite() {
- auto key_ids = m_key_list_->GetSelected();
- if (key_ids.empty()) return;
-
- auto key =
- GpgKeyGetter::GetInstance(m_key_list_->GetCurrentGpgContextChannel())
- .GetKey(key_ids.front());
- assert(key.IsGood());
+ auto keys = m_key_list_->GetSelectedKeys();
+ if (keys.empty()) return;
auto key_db_name =
GetGpgKeyDatabaseName(m_key_list_->GetCurrentGpgContextChannel());
- CommonUtils::GetInstance()->RemoveKeyFromFavorite(key_db_name, key);
+ CommonUtils::GetInstance()->RemoveKeyFromFavorite(key_db_name, keys.front());
emit SignalUIRefresh();
}
void MainWindow::refresh_keys_from_key_server() {
- auto key_ids = m_key_list_->GetSelected();
- if (key_ids.empty()) return;
- CommonUtils::GetInstance()->ImportKeyFromKeyServer(
- m_key_list_->GetCurrentGpgContextChannel(), key_ids);
+ auto keys = m_key_list_->GetSelectedGpgKeys();
+ if (keys.empty()) return;
+ CommonUtils::GetInstance()->ImportGpgKeyFromKeyServer(
+ m_key_list_->GetCurrentGpgContextChannel(), keys);
}
void MainWindow::slot_set_owner_trust_level_of_key() {
- auto key_ids = m_key_list_->GetSelected();
- if (key_ids.empty()) return;
+ auto keys = m_key_list_->GetSelectedGpgKeys();
+ if (keys.empty()) return;
auto* function = new SetOwnerTrustLevel(this);
- function->Exec(m_key_list_->GetCurrentGpgContextChannel(), key_ids.front());
+ function->Exec(m_key_list_->GetCurrentGpgContextChannel(), keys.front());
function->deleteLater();
}
void MainWindow::upload_key_to_server() {
- auto key_ids = m_key_list_->GetSelected();
+ auto keys = m_key_list_->GetSelectedKeys();
+ if (keys.empty()) return;
+
auto* dialog = new KeyUploadDialog(m_key_list_->GetCurrentGpgContextChannel(),
- key_ids, this);
+ keys, this);
dialog->show();
dialog->SlotUpload();
}
@@ -640,25 +623,28 @@ void MainWindow::decrypt_email_by_eml_data_result_helper(
void MainWindow::SlotEncryptEML() {
if (edit_->TabCount() == 0 || edit_->CurEMailPage() == nullptr) return;
- auto checked_keys = m_key_list_->GetCheckedKeys();
+ auto keys = m_key_list_->GetCheckedKeys();
- if (checked_keys.isEmpty()) {
+ if (keys.isEmpty()) {
QMessageBox::warning(this, tr("No Key Selected"),
tr("Please select a key for encrypt the EML."));
return;
}
auto buffer = edit_->CurPlainText().toUtf8();
+ auto key_ids =
+ ConvertKey2GpgKeyIdList(m_key_list_->GetCurrentGpgContextChannel(), keys);
+
GpgOperaHelper::WaitForOpera(
this, tr("Encrypting"),
- [this, buffer, checked_keys](const OperaWaitingHd& hd) {
+ [this, buffer, key_ids](const OperaWaitingHd& hd) {
Module::TriggerEvent(
"EMAIL_ENCRYPT_EML_DATA",
{
{"body_data", QString::fromLatin1(buffer.toBase64())},
{"channel",
QString::number(m_key_list_->GetCurrentGpgContextChannel())},
- {"encrypt_keys", checked_keys.join(';')},
+ {"encrypt_keys", key_ids.join(';')},
},
[=](Module::EventIdentifier i, Module::Event::ListenerIdentifier ei,
@@ -700,32 +686,33 @@ void MainWindow::SlotEncryptEML() {
void MainWindow::SlotSignEML() {
if (edit_->TabCount() == 0 || edit_->CurEMailPage() == nullptr) return;
- auto checked_keys = m_key_list_->GetCheckedKeys();
+ auto keys = m_key_list_->GetCheckedKeys();
- if (checked_keys.isEmpty()) {
+ if (keys.isEmpty()) {
QMessageBox::warning(this, tr("No Key Selected"),
tr("Please select a key for signing the EML."));
return;
}
- if (checked_keys.size() > 1) {
+ if (keys.size() > 1) {
QMessageBox::warning(this, tr("Multiple Keys Selected"),
tr("Please select only one key to sign the EML."));
return;
}
auto buffer = edit_->CurPlainText().toUtf8();
+ auto key_ids =
+ ConvertKey2GpgKeyIdList(m_key_list_->GetCurrentGpgContextChannel(), keys);
GpgOperaHelper::WaitForOpera(
- this, tr("Signing"),
- [this, buffer, checked_keys](const OperaWaitingHd& hd) {
+ this, tr("Signing"), [this, buffer, key_ids](const OperaWaitingHd& hd) {
Module::TriggerEvent(
"EMAIL_SIGN_EML_DATA",
{
{"body_data", QString::fromLatin1(buffer.toBase64())},
{"channel",
QString::number(m_key_list_->GetCurrentGpgContextChannel())},
- {"sign_key", checked_keys.front()},
+ {"sign_key", key_ids.front()},
},
[=](Module::EventIdentifier i, Module::Event::ListenerIdentifier ei,
Module::Event::Params p) {
@@ -766,9 +753,9 @@ void MainWindow::SlotSignEML() {
void MainWindow::SlotEncryptSignEML() {
if (edit_->TabCount() == 0 || edit_->CurEMailPage() == nullptr) return;
- auto checked_keys = m_key_list_->GetCheckedKeys();
+ auto keys = m_key_list_->GetCheckedKeys();
- if (checked_keys.isEmpty()) {
+ if (keys.isEmpty()) {
QMessageBox::warning(this, tr("No Key Selected"),
tr("Please select a key for encrypt the EML."));
return;
@@ -783,7 +770,7 @@ void MainWindow::SlotEncryptSignEML() {
// return when canceled
if (!signers_picker->GetStatus()) return;
- auto signer_keys = signers_picker->GetCheckedSignerKeyIds();
+ auto signer_keys = signers_picker->GetCheckedSigners();
if (signer_keys.isEmpty()) {
QMessageBox::warning(this, tr("No Key Selected"),
@@ -798,18 +785,20 @@ void MainWindow::SlotEncryptSignEML() {
}
auto buffer = edit_->CurPlainText().toUtf8();
+ auto key_ids =
+ ConvertKey2GpgKeyIdList(m_key_list_->GetCurrentGpgContextChannel(), keys);
GpgOperaHelper::WaitForOpera(
this, tr("Encrypting and Signing"),
- [this, buffer, checked_keys, signer_keys](const OperaWaitingHd& hd) {
+ [this, buffer, key_ids, signer_keys](const OperaWaitingHd& hd) {
Module::TriggerEvent(
"EMAIL_ENCRYPT_SIGN_EML_DATA",
{
{"body_data", QString::fromLatin1(buffer.toBase64())},
{"channel",
QString::number(m_key_list_->GetCurrentGpgContextChannel())},
- {"sign_key", signer_keys.front()},
- {"encrypt_keys", checked_keys.front()},
+ {"sign_key", signer_keys.front()->ID()},
+ {"encrypt_keys", key_ids.front()},
},
[=](Module::EventIdentifier i, Module::Event::ListenerIdentifier ei,
Module::Event::Params p) {
diff --git a/src/ui/main_window/MainWindowSlotUI.cpp b/src/ui/main_window/MainWindowSlotUI.cpp
index 248e6488..51de7d23 100644
--- a/src/ui/main_window/MainWindowSlotUI.cpp
+++ b/src/ui/main_window/MainWindowSlotUI.cpp
@@ -29,7 +29,6 @@
#include "MainWindow.h"
#include "core/GpgConstants.h"
#include "core/function/CacheManager.h"
-#include "core/function/GlobalSettingStation.h"
#include "core/function/gpg/GpgAdvancedOperator.h"
#include "core/model/SettingsObject.h"
#include "ui/UserInterfaceUtils.h"
@@ -37,6 +36,7 @@
#include "ui/dialog/settings/SettingsDialog.h"
#include "ui/main_window/KeyMgmt.h"
#include "ui/struct/settings_object/AppearanceSO.h"
+#include "ui/widgets/KeyList.h"
#include "ui/widgets/TextEdit.h"
namespace GpgFrontend::UI {
@@ -168,7 +168,7 @@ void MainWindow::slot_cut_pgp_header() {
void MainWindow::SlotSetRestartNeeded(int mode) { this->restart_mode_ = mode; }
void MainWindow::SlotUpdateCryptoMenuStatus(unsigned int type) {
- MainWindow::OperationMenu::OperationType opera_type = type;
+ OperationMenu::OperationType opera_type = type;
// refresh status to disable all
verify_act_->setDisabled(true);
@@ -179,22 +179,22 @@ void MainWindow::SlotUpdateCryptoMenuStatus(unsigned int type) {
decrypt_verify_act_->setDisabled(true);
// gnupg operations
- if ((opera_type & MainWindow::OperationMenu::kVerify) != 0U) {
+ if ((opera_type & OperationMenu::kVerify) != 0U) {
verify_act_->setDisabled(false);
}
- if ((opera_type & MainWindow::OperationMenu::kSign) != 0U) {
+ if ((opera_type & OperationMenu::kSign) != 0U) {
sign_act_->setDisabled(false);
}
- if ((opera_type & MainWindow::OperationMenu::kEncrypt) != 0U) {
+ if ((opera_type & OperationMenu::kEncrypt) != 0U) {
encrypt_act_->setDisabled(false);
}
- if ((opera_type & MainWindow::OperationMenu::kEncryptAndSign) != 0U) {
+ if ((opera_type & OperationMenu::kEncryptAndSign) != 0U) {
encrypt_sign_act_->setDisabled(false);
}
- if ((opera_type & MainWindow::OperationMenu::kDecrypt) != 0U) {
+ if ((opera_type & OperationMenu::kDecrypt) != 0U) {
decrypt_act_->setDisabled(false);
}
- if ((opera_type & MainWindow::OperationMenu::kDecryptAndVerify) != 0U) {
+ if ((opera_type & OperationMenu::kDecryptAndVerify) != 0U) {
decrypt_verify_act_->setDisabled(false);
}
}
@@ -346,4 +346,29 @@ void MainWindow::slot_restart_gpg_components(bool) {
});
}
+void MainWindow::slot_update_operations_menu_by_checked_keys() {
+ auto keys = m_key_list_->GetCheckedKeys();
+
+ OperationMenu::OperationType type = ~0;
+
+ if (keys.isEmpty()) {
+ type &= ~(OperationMenu::kEncrypt | OperationMenu::kEncryptAndSign |
+ OperationMenu::kSign);
+
+ } else {
+ for (const auto& key : keys) {
+ if (key == nullptr || key->IsDisabled()) continue;
+
+ if (!key->IsHasEncrCap()) {
+ type &= ~(OperationMenu::kEncrypt | OperationMenu::kEncryptAndSign);
+ }
+ if (!key->IsHasSignCap()) {
+ type &= ~(OperationMenu::kSign);
+ }
+ }
+ }
+
+ SlotUpdateCryptoMenuStatus(type);
+}
+
} // namespace GpgFrontend::UI
diff --git a/src/ui/main_window/MainWindowUI.cpp b/src/ui/main_window/MainWindowUI.cpp
index 6598aede..26c3a8ad 100644
--- a/src/ui/main_window/MainWindowUI.cpp
+++ b/src/ui/main_window/MainWindowUI.cpp
@@ -570,28 +570,31 @@ void MainWindow::create_dock_windows() {
tr("Default"), "default",
GpgKeyTableDisplayMode::kPUBLIC_KEY |
GpgKeyTableDisplayMode::kPRIVATE_KEY,
- [](const GpgKey& key) -> bool {
- return !(key.IsRevoked() || key.IsDisabled() || key.IsExpired());
+ [](const GpgAbstractKey* key) -> bool {
+ return !(key->IsRevoked() || key->IsDisabled() || key->IsExpired());
});
- m_key_list_->AddListGroupTab(tr("Favourite"), "favourite",
- GpgKeyTableDisplayMode::kPUBLIC_KEY |
- GpgKeyTableDisplayMode::kPRIVATE_KEY |
- GpgKeyTableDisplayMode::kFAVORITES,
- [](const GpgKey&) -> bool { return true; });
+ m_key_list_->AddListGroupTab(
+ tr("Favourite"), "favourite",
+ GpgKeyTableDisplayMode::kPUBLIC_KEY |
+ GpgKeyTableDisplayMode::kPRIVATE_KEY |
+ GpgKeyTableDisplayMode::kFAVORITES,
+ [](const GpgAbstractKey*) -> bool { return true; });
m_key_list_->AddListGroupTab(
tr("Only Public Key"), "only_public_key",
- GpgKeyTableDisplayMode::kPUBLIC_KEY, [](const GpgKey& key) -> bool {
- return !key.IsPrivateKey() &&
- !(key.IsRevoked() || key.IsDisabled() || key.IsExpired());
+ GpgKeyTableDisplayMode::kPUBLIC_KEY,
+ [](const GpgAbstractKey* key) -> bool {
+ return !key->IsPrivateKey() &&
+ !(key->IsRevoked() || key->IsDisabled() || key->IsExpired());
});
m_key_list_->AddListGroupTab(
tr("Has Private Key"), "has_private_key",
- GpgKeyTableDisplayMode::kPRIVATE_KEY, [](const GpgKey& key) -> bool {
- return key.IsPrivateKey() &&
- !(key.IsRevoked() || key.IsDisabled() || key.IsExpired());
+ GpgKeyTableDisplayMode::kPRIVATE_KEY,
+ [](const GpgAbstractKey* key) -> bool {
+ return key->IsPrivateKey() &&
+ !(key->IsRevoked() || key->IsDisabled() || key->IsExpired());
});
m_key_list_->SlotRefresh();
@@ -606,6 +609,9 @@ void MainWindow::create_dock_windows() {
info_board_dock_->setWidget(info_board_);
info_board_dock_->widget()->layout()->setContentsMargins(0, 0, 0, 0);
view_menu_->addAction(info_board_dock_->toggleViewAction());
+
+ connect(m_key_list_, &KeyList::SignalKeyChecked, this,
+ &MainWindow::slot_update_operations_menu_by_checked_keys);
}
} // namespace GpgFrontend::UI
diff --git a/src/ui/model/GpgKeyTableProxyModel.cpp b/src/ui/model/GpgKeyTableProxyModel.cpp
index 746f3344..90bf16d3 100644
--- a/src/ui/model/GpgKeyTableProxyModel.cpp
+++ b/src/ui/model/GpgKeyTableProxyModel.cpp
@@ -28,9 +28,10 @@
#include "GpgKeyTableProxyModel.h"
-#include "core/function/gpg/GpgKeyGetter.h"
+#include "core/function/gpg/GpgAbstractKeyGetter.h"
#include "core/model/CacheObject.h"
#include "core/model/GpgKey.h"
+#include "core/model/GpgKeyTableModel.h"
#include "core/struct/cache_object/AllFavoriteKeyPairsCO.h"
#include "core/utils/GpgUtils.h"
@@ -57,34 +58,31 @@ GpgKeyTableProxyModel::GpgKeyTableProxyModel(
}
auto GpgKeyTableProxyModel::filterAcceptsRow(
- int source_row, const QModelIndex &sourceParent) const -> bool {
- auto index = sourceModel()->index(source_row, 6, sourceParent);
- auto key_id = sourceModel()->data(index).toString();
+ int sourceRow, const QModelIndex &sourceParent) const -> bool {
+ auto index = sourceModel()->index(sourceRow, 0, sourceParent);
- auto key =
- GpgKeyGetter::GetInstance(model_->GetGpgContextChannel()).GetKey(key_id);
- LOG_D() << "get key: " << key_id
- << "from channel: " << model_->GetGpgContextChannel();
- assert(key.IsGood());
+ auto *i = index.isValid()
+ ? static_cast<GpgKeyTableItem *>(index.internalPointer())
+ : nullptr;
+ assert(i != nullptr);
+
+ auto *key = i->Key();
+ assert(key->IsGood());
if (!(display_mode_ & GpgKeyTableDisplayMode::kPRIVATE_KEY) &&
- key.IsPrivateKey()) {
+ key->IsPrivateKey()) {
return false;
}
if (!(display_mode_ & GpgKeyTableDisplayMode::kPUBLIC_KEY) &&
- !key.IsPrivateKey()) {
+ !key->IsPrivateKey()) {
return false;
}
if (!custom_filter_(key)) return false;
- if (display_mode_ & GpgKeyTableDisplayMode::kFAVORITES) {
- LOG_D() << "kFAVORITES Mode" << "key id" << key_id << "favorite_key_ids_"
- << favorite_key_ids_;
- }
if (display_mode_ & GpgKeyTableDisplayMode::kFAVORITES &&
- !favorite_key_ids_.contains(key_id)) {
+ !favorite_key_ids_.contains(key->ID())) {
return false;
}
@@ -92,11 +90,14 @@ auto GpgKeyTableProxyModel::filterAcceptsRow(
QStringList infos;
for (int column = 0; column < sourceModel()->columnCount(); ++column) {
- auto index = sourceModel()->index(source_row, column, sourceParent);
+ auto index = sourceModel()->index(sourceRow, column, sourceParent);
infos << sourceModel()->data(index).toString();
- for (const auto &uid : key.UIDs()) {
- infos << uid.GetUID();
+ if (key->KeyType() == GpgAbstractKeyType::kGPG_KEY) {
+ auto *k = dynamic_cast<GpgKey *>(key);
+ for (const auto &uid : k->UIDs()) {
+ infos << uid.GetUID();
+ }
}
}
@@ -197,4 +198,8 @@ void GpgKeyTableProxyModel::slot_update_favorites_cache() {
}
}
+void GpgKeyTableProxyModel::SetFilter(const KeyFilter &filter) {
+ this->custom_filter_ = filter;
+ invalidateFilter();
+}
} // namespace GpgFrontend::UI \ No newline at end of file
diff --git a/src/ui/model/GpgKeyTableProxyModel.h b/src/ui/model/GpgKeyTableProxyModel.h
index bad1aa97..5b9c0336 100644
--- a/src/ui/model/GpgKeyTableProxyModel.h
+++ b/src/ui/model/GpgKeyTableProxyModel.h
@@ -38,7 +38,7 @@ namespace GpgFrontend::UI {
class GpgKeyTableProxyModel : public QSortFilterProxyModel {
Q_OBJECT
public:
- using KeyFilter = std::function<bool(const GpgKey &)>;
+ using KeyFilter = std::function<bool(const GpgAbstractKey *)>;
explicit GpgKeyTableProxyModel(QSharedPointer<GpgKeyTableModel> model,
GpgKeyTableDisplayMode display_mode,
@@ -47,6 +47,8 @@ class GpgKeyTableProxyModel : public QSortFilterProxyModel {
void SetSearchKeywords(const QString &keywords);
+ void SetFilter(const KeyFilter &filter);
+
void ResetGpgKeyTableModel(QSharedPointer<GpgKeyTableModel> model);
protected:
diff --git a/src/ui/model/GpgKeyTreeProxyModel.cpp b/src/ui/model/GpgKeyTreeProxyModel.cpp
index 2f46f548..bff18dd6 100644
--- a/src/ui/model/GpgKeyTreeProxyModel.cpp
+++ b/src/ui/model/GpgKeyTreeProxyModel.cpp
@@ -28,7 +28,6 @@
#include "GpgKeyTreeProxyModel.h"
-#include "core/function/gpg/GpgKeyGetter.h"
#include "core/model/CacheObject.h"
#include "core/model/GpgKey.h"
#include "core/model/GpgKeyTreeModel.h"
@@ -83,7 +82,7 @@ auto GpgKeyTreeProxyModel::filterAcceptsRow(
auto index = sourceModel()->index(source_row, column, sourceParent);
infos << sourceModel()->data(index).toString();
- if (!key->IsSubKey()) {
+ if (key->KeyType() != GpgAbstractKeyType::kGPG_SUBKEY) {
for (const auto &uid : dynamic_cast<const GpgKey *>(key)->UIDs()) {
infos << uid.GetUID();
}
diff --git a/src/ui/struct/GpgOperaResultContext.h b/src/ui/struct/GpgOperaResultContext.h
index 58da0dc8..10a1bad9 100644
--- a/src/ui/struct/GpgOperaResultContext.h
+++ b/src/ui/struct/GpgOperaResultContext.h
@@ -48,8 +48,8 @@ struct GpgOperaContext;
struct GpgOperaContextBasement {
QContainer<OperaWaitingCb> operas;
QContainer<GpgOperaResult> opera_results;
- GpgKeyList keys;
- GpgKeyList singer_keys;
+ GpgAbstractKeyPtrList keys;
+ GpgAbstractKeyPtrList singer_keys;
QStringList unknown_fprs;
bool ascii;
diff --git a/src/ui/widgets/KeyList.cpp b/src/ui/widgets/KeyList.cpp
index fb26295f..429a5bd1 100644
--- a/src/ui/widgets/KeyList.cpp
+++ b/src/ui/widgets/KeyList.cpp
@@ -31,34 +31,50 @@
#include <cstddef>
#include "core/function/GlobalSettingStation.h"
+#include "core/function/gpg/GpgAbstractKeyGetter.h"
#include "core/function/gpg/GpgKeyGetter.h"
#include "core/utils/GpgUtils.h"
#include "ui/UISignalStation.h"
#include "ui/UserInterfaceUtils.h"
+#include "ui/dialog/KeyGroupCreationDialog.h"
#include "ui/dialog/import_export/KeyImportDetailDialog.h"
+
+//
#include "ui_KeyList.h"
namespace GpgFrontend::UI {
+KeyList::KeyList(QWidget* parent)
+ : QWidget(parent),
+ ui_(GpgFrontend::SecureCreateSharedObject<Ui_KeyList>()),
+ model_(GpgAbstractKeyGetter::GetInstance(kGpgFrontendDefaultChannel)
+ .GetGpgKeyTableModel()),
+ global_column_filter_(static_cast<GpgKeyTableColumn>(
+ GetSettings()
+ .value("keys/global_columns_filter",
+ static_cast<unsigned int>(GpgKeyTableColumn::kALL))
+ .toUInt())) {
+ ui_->setupUi(this);
+}
+
KeyList::KeyList(int channel, KeyMenuAbility menu_ability,
GpgKeyTableColumn fixed_columns_filter, QWidget* parent)
: QWidget(parent),
ui_(GpgFrontend::SecureCreateSharedObject<Ui_KeyList>()),
current_gpg_context_channel_(channel),
menu_ability_(menu_ability),
- model_(GpgKeyGetter::GetInstance(channel).GetGpgKeyTableModel()),
+ model_(GpgAbstractKeyGetter::GetInstance(channel).GetGpgKeyTableModel()),
fixed_columns_filter_(fixed_columns_filter),
global_column_filter_(static_cast<GpgKeyTableColumn>(
GetSettings()
.value("keys/global_columns_filter",
static_cast<unsigned int>(GpgKeyTableColumn::kALL))
.toUInt())) {
+ ui_->setupUi(this);
init();
}
void KeyList::init() {
- ui_->setupUi(this);
-
ui_->menuWidget->setHidden(menu_ability_ == KeyMenuAbility::kNONE);
ui_->refreshKeyListButton->setHidden(~menu_ability_ &
KeyMenuAbility::kREFRESH);
@@ -70,6 +86,7 @@ void KeyList::init() {
ui_->searchBarEdit->setHidden(~menu_ability_ & KeyMenuAbility::kSEARCH_BAR);
ui_->switchContextButton->setHidden(~menu_ability_ &
KeyMenuAbility::kKEY_DATABASE);
+ ui_->keyGroupButton->setHidden(~menu_ability_ & KeyMenuAbility::kKEY_GROUP);
auto* gpg_context_menu = new QMenu(this);
auto* gpg_context_groups = new QActionGroup(this);
@@ -243,6 +260,16 @@ void KeyList::init() {
GetSettings().setValue("keys/global_columns_filter",
static_cast<unsigned int>(global_column_filter_));
});
+ connect(ui_->keyGroupButton, &QPushButton::clicked, this,
+ &KeyList::slot_new_key_group);
+ connect(this, &KeyList::SignalKeyChecked, this, [=]() {
+ auto keys = GetCheckedKeys();
+
+ ui_->keyGroupButton->setDisabled(keys.empty());
+ for (const auto& key : keys) {
+ if (!key->IsHasEncrCap()) ui_->keyGroupButton->setDisabled(true);
+ }
+ });
setAcceptDrops(true);
@@ -261,10 +288,10 @@ void KeyList::init() {
ui_->searchBarEdit->setPlaceholderText(tr("Search for keys..."));
}
-void KeyList::AddListGroupTab(const QString& name, const QString& id,
- GpgKeyTableDisplayMode display_mode,
- GpgKeyTableProxyModel::KeyFilter search_filter,
- GpgKeyTableColumn custom_columns_filter) {
+auto KeyList::AddListGroupTab(
+ const QString& name, const QString& id, GpgKeyTableDisplayMode display_mode,
+ GpgKeyTableProxyModel::KeyFilter search_filter,
+ GpgKeyTableColumn custom_columns_filter) -> KeyTable* {
auto* key_table =
new KeyTable(this, model_, display_mode, custom_columns_filter,
std::move(search_filter));
@@ -274,8 +301,13 @@ void KeyList::AddListGroupTab(const QString& name, const QString& id,
connect(this, &KeyList::SignalColumnTypeChange, key_table,
&KeyTable::SignalColumnTypeChange);
+ connect(key_table, &KeyTable::SignalKeyChecked, this, [=]() {
+ if (sender() != ui_->keyGroupTab->currentWidget()) return;
+ emit SignalKeyChecked();
+ });
UpdateKeyTableColumnType(global_column_filter_);
+ return key_table;
}
void KeyList::SlotRefresh() {
@@ -284,7 +316,7 @@ void KeyList::SlotRefresh() {
LOG_D() << "request new key table module, current gpg context channel: "
<< current_gpg_context_channel_;
- model_ = GpgKeyGetter::GetInstance(current_gpg_context_channel_)
+ model_ = GpgAbstractKeyGetter::GetInstance(current_gpg_context_channel_)
.GetGpgKeyTableModel();
for (int i = 0; i < ui_->keyGroupTab->count(); i++) {
@@ -300,112 +332,54 @@ void KeyList::SlotRefreshUI() {
emit SignalRefreshStatusBar(tr("Key List Refreshed."), 1000);
ui_->refreshKeyListButton->setDisabled(false);
ui_->syncButton->setDisabled(false);
+ emit SignalKeyChecked();
}
-auto KeyList::GetChecked(const KeyTable& key_table) -> KeyIdArgsList {
- auto ret = KeyIdArgsList{};
- for (int i = 0; i < key_table.GetRowCount(); i++) {
- if (key_table.IsRowChecked(i)) {
- ret.push_back(key_table.GetKeyIdByRow(i));
- }
- }
- return ret;
-}
-
-auto KeyList::GetChecked() -> KeyIdArgsList {
+auto KeyList::GetCheckedKeys() -> GpgAbstractKeyPtrList {
auto* key_table = qobject_cast<KeyTable*>(ui_->keyGroupTab->currentWidget());
- auto ret = KeyIdArgsList{};
- for (int i = 0; i < key_table->GetRowCount(); i++) {
- if (key_table->IsRowChecked(i)) {
- ret.push_back(key_table->GetKeyIdByRow(i));
- }
- }
- return ret;
-}
-auto KeyList::GetCheckedKeys() -> QStringList {
- auto* key_table = qobject_cast<KeyTable*>(ui_->keyGroupTab->currentWidget());
- QStringList key_id_list;
- for (int i = 0; i < key_table->GetRowCount(); i++) {
- if (key_table->IsRowChecked(i)) {
- key_id_list.append(key_table->GetKeyIdByRow(i));
- }
- }
- return key_id_list;
-}
+ assert(key_table != nullptr);
+ if (key_table == nullptr) return {};
-auto KeyList::GetAllPrivateKeys() -> KeyIdArgsList {
- auto* key_table = qobject_cast<KeyTable*>(ui_->keyGroupTab->currentWidget());
- auto ret = KeyIdArgsList{};
- for (int i = 0; i < key_table->GetRowCount(); i++) {
- if (key_table->IsPrivateKeyByRow(i)) {
- ret.push_back(key_table->GetKeyIdByRow(i));
- }
- }
- return ret;
+ return key_table->GetCheckedKeys();
}
-auto KeyList::GetCheckedPrivateKey() -> KeyIdArgsList {
- auto ret = KeyIdArgsList{};
- if (ui_->keyGroupTab->size().isEmpty()) return ret;
-
- auto* key_table = qobject_cast<KeyTable*>(ui_->keyGroupTab->currentWidget());
+auto KeyList::GetCheckedPrivateKey() -> GpgAbstractKeyPtrList {
+ auto ret = GpgAbstractKeyPtrList{};
- for (int i = 0; i < key_table->GetRowCount(); i++) {
- if (key_table->IsRowChecked(i) && key_table->IsPrivateKeyByRow(i)) {
- ret.push_back(key_table->GetKeyIdByRow(i));
- }
+ auto keys = GetCheckedKeys();
+ for (const auto& key : keys) {
+ if (key->IsPrivateKey()) ret.push_back(key);
}
+
return ret;
}
-auto KeyList::GetCheckedPublicKey() -> KeyIdArgsList {
- auto ret = KeyIdArgsList{};
- if (ui_->keyGroupTab->size().isEmpty()) return ret;
+auto KeyList::GetCheckedPublicKey() -> GpgAbstractKeyPtrList {
+ auto ret = GpgAbstractKeyPtrList{};
- auto* key_table = qobject_cast<KeyTable*>(ui_->keyGroupTab->currentWidget());
-
- for (int i = 0; i < key_table->GetRowCount(); i++) {
- if (key_table->IsRowChecked(i) && key_table->IsPublicKeyByRow(i)) {
- ret.push_back(key_table->GetKeyIdByRow(i));
- }
+ auto keys = GetCheckedKeys();
+ for (const auto& key : keys) {
+ if (!key->IsPrivateKey()) ret.push_back(key);
}
+
return ret;
}
-void KeyList::SetChecked(const KeyIdArgsList& keyIds,
+void KeyList::SetChecked(const KeyIdArgsList& key_ids,
const KeyTable& key_table) {
- if (!keyIds.empty()) {
+ if (!key_ids.empty()) {
for (int i = 0; i < key_table.GetRowCount(); i++) {
- if (std::find(keyIds.begin(), keyIds.end(), key_table.GetKeyIdByRow(i)) !=
- keyIds.end()) {
+ if (std::find(
+ key_ids.begin(), key_ids.end(),
+ key_table.GetKeyByIndex(key_table.model()->index(i, 0))->ID()) !=
+ key_ids.end()) {
key_table.SetRowChecked(i);
}
}
}
}
-auto KeyList::GetSelected() -> KeyIdArgsList {
- auto ret = KeyIdArgsList{};
- if (ui_->keyGroupTab->size().isEmpty()) return ret;
-
- auto* key_table = qobject_cast<KeyTable*>(ui_->keyGroupTab->currentWidget());
- if (key_table == nullptr) {
- FLOG_W("fail to get current key table, nullptr");
- return ret;
- }
-
- QItemSelectionModel* select = key_table->selectionModel();
- for (auto index : select->selectedRows()) {
- ret.push_back(key_table->GetKeyIdByRow(index.row()));
- }
-
- if (ret.empty()) {
- FLOG_W("nothing is selected at key list");
- }
- return ret;
-}
-
[[maybe_unused]] auto KeyList::ContainsPrivateKeys() -> bool {
if (ui_->keyGroupTab->size().isEmpty()) return false;
auto* key_table =
@@ -532,24 +506,29 @@ void KeyList::import_keys(const QByteArray& in_buffer) {
(new KeyImportDetailDialog(current_gpg_context_channel_, result, this));
}
-auto KeyList::GetSelectedKey() -> QString {
- if (ui_->keyGroupTab->size().isEmpty()) return {};
-
- auto* key_table = qobject_cast<KeyTable*>(ui_->keyGroupTab->currentWidget());
-
- QItemSelectionModel* select = key_table->selectionModel();
+auto KeyList::GetSelectedKey() -> GpgAbstractKeyPtr {
+ return GetSelectedKeys().front();
+}
- auto selected_rows = select->selectedRows();
- if (selected_rows.empty()) return {};
+auto KeyList::GetSelectedGpgKey() -> GpgKeyPtr {
+ return GetSelectedGpgKeys().front();
+}
- return key_table->GetKeyIdByRow(selected_rows.first().row());
+auto KeyList::GetSelectedGpgKeys() -> GpgKeyPtrList {
+ auto keys = GetSelectedKeys();
+ auto g_keys = GpgKeyPtrList{};
+ for (const auto& key : keys) {
+ if (key->KeyType() != GpgAbstractKeyType::kGPG_KEY) continue;
+ g_keys.push_back(qSharedPointerDynamicCast<GpgKey>(key));
+ }
+ return g_keys;
}
void KeyList::slot_sync_with_key_server() {
- auto checked_public_keys = GetCheckedPublicKey();
+ auto target_keys = GetCheckedPublicKey();
KeyIdArgsList key_ids;
- if (checked_public_keys.empty()) {
+ if (target_keys.empty()) {
QMessageBox::StandardButton const reply = QMessageBox::question(
this, QCoreApplication::tr("Sync All Public Key"),
QCoreApplication::tr("You have not checked any public keys that you "
@@ -559,13 +538,12 @@ void KeyList::slot_sync_with_key_server() {
if (reply == QMessageBox::No) return;
- auto all_key_ids = model_->GetAllKeyIds();
- for (auto& key_id : all_key_ids) {
- key_ids.push_back(key_id);
- }
+ target_keys = model_->GetAllKeys();
+ }
- } else {
- key_ids = checked_public_keys;
+ for (auto& key : target_keys) {
+ if (key->KeyType() != GpgAbstractKeyType::kGPG_KEY) continue;
+ key_ids.push_back(key->ID());
}
if (key_ids.empty()) return;
@@ -633,18 +611,59 @@ auto KeyList::GetCurrentGpgContextChannel() const -> int {
return current_gpg_context_channel_;
}
-auto KeyList::GetSelectedGpgKey() -> std::tuple<bool, GpgKey> {
- auto key_ids = GetSelected();
- if (key_ids.empty()) return {false, GpgKey()};
+auto KeyList::GetSelectedKeys() -> GpgAbstractKeyPtrList {
+ auto* key_table = qobject_cast<KeyTable*>(ui_->keyGroupTab->currentWidget());
+
+ assert(key_table != nullptr);
+ if (key_table == nullptr) return {};
+
+ return key_table->GetSelectedKeys();
+}
+
+void KeyList::slot_new_key_group() {
+ auto keys = GetCheckedKeys();
+
+ QStringList proper_key_ids;
+ for (const auto& key : keys) {
+ if (!key->IsHasEncrCap()) continue;
+ proper_key_ids.append(key->ID());
+ }
+
+ if (proper_key_ids.isEmpty()) return;
+
+ auto* dialog =
+ new KeyGroupCreationDialog(current_gpg_context_channel_, proper_key_ids);
+ dialog->exec();
+}
+
+void KeyList::UpdateKeyTableFilter(
+ int index, const GpgKeyTableProxyModel::KeyFilter& filter) {
+ if (ui_->keyGroupTab->size().isEmpty() ||
+ ui_->keyGroupTab->widget(index) == nullptr) {
+ return;
+ }
- auto key = GpgKeyGetter::GetInstance(GetCurrentGpgContextChannel())
- .GetKey(key_ids.front());
+ auto* key_table = qobject_cast<KeyTable*>(ui_->keyGroupTab->widget(index));
+ key_table->SetFilter(filter);
+}
- if (!key.IsGood()) {
- QMessageBox::critical(this, tr("Error"), tr("Key Not Found."));
- return {false, GpgKey()};
+void KeyList::RefreshKeyTable(int index) {
+ if (ui_->keyGroupTab->size().isEmpty() ||
+ ui_->keyGroupTab->widget(index) == nullptr) {
+ return;
}
- return {true, key};
+ auto* key_table = qobject_cast<KeyTable*>(ui_->keyGroupTab->widget(index));
+ key_table->RefreshProxyModel();
+}
+
+void KeyList::Init(int channel, KeyMenuAbility menu_ability,
+ GpgKeyTableColumn fixed_column_filter) {
+ current_gpg_context_channel_ = channel;
+ menu_ability_ = menu_ability;
+ fixed_columns_filter_ = fixed_column_filter;
+ model_ = GpgAbstractKeyGetter::GetInstance(channel).GetGpgKeyTableModel();
+
+ init();
}
} // namespace GpgFrontend::UI
diff --git a/src/ui/widgets/KeyList.h b/src/ui/widgets/KeyList.h
index 868c5b07..0b0b9be6 100644
--- a/src/ui/widgets/KeyList.h
+++ b/src/ui/widgets/KeyList.h
@@ -47,6 +47,7 @@ enum class KeyMenuAbility : unsigned int {
kCOLUMN_FILTER = 1 << 4,
kSEARCH_BAR = 1 << 5,
kKEY_DATABASE = 1 << 6,
+ kKEY_GROUP = 1 << 7,
kALL = ~0U
};
@@ -84,6 +85,12 @@ class KeyList : public QWidget {
/**
* @brief Construct a new Key List object
*
+ */
+ explicit KeyList(QWidget* parent = nullptr);
+
+ /**
+ * @brief Construct a new Key List object
+ *
* @param menu_ability
* @param parent
*/
@@ -95,18 +102,29 @@ class KeyList : public QWidget {
/**
* @brief
*
+ * @param channel
+ * @param menu_ability
+ * @param fixed_column_filter
+ */
+ void Init(int channel, KeyMenuAbility menu_ability,
+ GpgKeyTableColumn fixed_column_filter = GpgKeyTableColumn::kALL);
+
+ /**
+ * @brief
+ *
* @param name
* @param selectType
* @param infoType
* @param filter
*/
- void AddListGroupTab(
+ auto AddListGroupTab(
const QString& name, const QString& id,
GpgKeyTableDisplayMode display_mode =
GpgKeyTableDisplayMode::kPRIVATE_KEY,
GpgKeyTableProxyModel::KeyFilter search_filter =
- [](const GpgKey&) -> bool { return true; },
- GpgKeyTableColumn custom_columns_filter = GpgKeyTableColumn::kALL);
+ [](const GpgAbstractKey*) -> bool { return true; },
+ GpgKeyTableColumn custom_columns_filter = GpgKeyTableColumn::kALL)
+ -> KeyTable*;
/**
* @brief Set the Column Width object
@@ -130,18 +148,11 @@ class KeyList : public QWidget {
void AddSeparator();
/**
- * @brief Get the Checked object
- *
- * @return KeyIdArgsListPtr
- */
- auto GetChecked() -> KeyIdArgsList;
-
- /**
* @brief Get the Checked Keys object
*
* @return QStringList
*/
- auto GetCheckedKeys() -> QStringList;
+ auto GetCheckedKeys() -> GpgAbstractKeyPtrList;
/**
* @brief Get the Checked object
@@ -149,28 +160,21 @@ class KeyList : public QWidget {
* @param key_table
* @return KeyIdArgsListPtr
*/
- static auto GetChecked(const KeyTable& key_table) -> KeyIdArgsList;
+ static auto GetChecked(const KeyTable& key_table) -> GpgAbstractKeyPtrList;
/**
* @brief Get the Private Checked object
*
* @return KeyIdArgsListPtr
*/
- auto GetCheckedPrivateKey() -> KeyIdArgsList;
+ auto GetCheckedPrivateKey() -> GpgAbstractKeyPtrList;
/**
* @brief
*
* @return KeyIdArgsListPtr
*/
- auto GetCheckedPublicKey() -> KeyIdArgsList;
-
- /**
- * @brief Get the All Private Keys object
- *
- * @return KeyIdArgsListPtr
- */
- auto GetAllPrivateKeys() -> KeyIdArgsList;
+ auto GetCheckedPublicKey() -> GpgAbstractKeyPtrList;
/**
* @brief Set the Checked object
@@ -182,25 +186,32 @@ class KeyList : public QWidget {
const KeyTable& key_table);
/**
- * @brief Get the Selected object
+ * @brief Get the Selected Key object
*
- * @return KeyIdArgsListPtr
+ * @return QString
*/
- auto GetSelected() -> KeyIdArgsList;
+ auto GetSelectedKey() -> GpgAbstractKeyPtr;
+
+ /**
+ * @brief Get the Selected Keys object
+ *
+ * @return GpgAbstractKeyPtrList
+ */
+ auto GetSelectedKeys() -> GpgAbstractKeyPtrList;
/**
* @brief Get the Selected Key object
*
* @return QString
*/
- auto GetSelectedKey() -> QString;
+ auto GetSelectedGpgKey() -> GpgKeyPtr;
/**
- * @brief Get the Selected Gpg Key object
+ * @brief Get the Selected Keys object
*
- * @return GpgKey
+ * @return GpgAbstractKeyPtrList
*/
- auto GetSelectedGpgKey() -> std::tuple<bool, GpgKey>;
+ auto GetSelectedGpgKeys() -> GpgKeyPtrList;
/**
* @brief
@@ -223,6 +234,33 @@ class KeyList : public QWidget {
*/
[[nodiscard]] auto GetCurrentGpgContextChannel() const -> int;
+ /**
+ * @brief
+ *
+ */
+ void UpdateKeyTableFilter(int index, const GpgKeyTableProxyModel::KeyFilter&);
+
+ /**
+ * @brief
+ *
+ * @param index
+ */
+ void RefreshKeyTable(int index);
+
+ public slots:
+
+ /**
+ * @brief
+ *
+ */
+ void SlotRefresh();
+
+ /**
+ * @brief
+ *
+ */
+ void SlotRefreshUI();
+
signals:
/**
* @brief
@@ -244,52 +282,49 @@ class KeyList : public QWidget {
*/
void SignalColumnTypeChange(GpgKeyTableColumn);
- public slots:
-
/**
* @brief
*
*/
- void SlotRefresh();
+ void SignalKeyChecked();
+ protected:
/**
* @brief
*
+ * @param event
*/
- void SlotRefreshUI();
+ void contextMenuEvent(QContextMenuEvent* event) override;
- private:
/**
* @brief
*
+ * @param event
*/
- void init();
+ void dragEnterEvent(QDragEnterEvent* event) override;
/**
* @brief
*
- * @param inBuffer
+ * @param event
*/
- void import_keys(const QByteArray& in_buffer);
+ void dropEvent(QDropEvent* event) override;
- /**
- * @brief
- *
- */
- void uncheck_all();
+ private slots:
/**
* @brief
*
*/
- void check_all();
+ void slot_sync_with_key_server();
/**
* @brief
*
*/
- void filter_by_keyword();
+ void slot_new_key_group();
+ private:
std::shared_ptr<Ui_KeyList> ui_; ///<
QMenu* popup_menu_{}; ///<
std::function<void(const GpgKey&, QWidget*)> m_action_ = nullptr; ///<
@@ -306,35 +341,36 @@ class KeyList : public QWidget {
QAction* subkeys_number_column_action_;
QAction* comment_column_action_;
- private slots:
+ /**
+ * @brief
+ *
+ */
+ void init();
/**
* @brief
*
+ * @param inBuffer
*/
- void slot_sync_with_key_server();
+ void import_keys(const QByteArray& in_buffer);
- protected:
/**
* @brief
*
- * @param event
*/
- void contextMenuEvent(QContextMenuEvent* event) override;
+ void uncheck_all();
/**
* @brief
*
- * @param event
*/
- void dragEnterEvent(QDragEnterEvent* event) override;
+ void check_all();
/**
* @brief
*
- * @param event
*/
- void dropEvent(QDropEvent* event) override;
+ void filter_by_keyword();
};
} // namespace GpgFrontend::UI
diff --git a/src/ui/widgets/KeyTable.cpp b/src/ui/widgets/KeyTable.cpp
index 10ebe6eb..d1135279 100644
--- a/src/ui/widgets/KeyTable.cpp
+++ b/src/ui/widgets/KeyTable.cpp
@@ -28,16 +28,16 @@
#include "ui/widgets/KeyTable.h"
-#include "core/function/gpg/GpgKeyGetter.h"
#include "ui/UserInterfaceUtils.h"
-#include "ui/dialog/keypair_details/KeyDetailsDialog.h"
namespace GpgFrontend::UI {
-auto KeyTable::GetChecked() const -> KeyIdArgsList {
- auto ret = KeyIdArgsList{};
+auto KeyTable::GetCheckedKeys() const -> GpgAbstractKeyPtrList {
+ auto ret = GpgAbstractKeyPtrList{};
for (decltype(GetRowCount()) i = 0; i < GetRowCount(); i++) {
- if (IsRowChecked(i)) ret.push_back(GetKeyIdByRow(i));
+ if (IsRowChecked(i)) {
+ ret.push_back(GetKeyByIndex(model()->index(i, 0)));
+ }
}
return ret;
}
@@ -76,15 +76,20 @@ KeyTable::KeyTable(QWidget* parent, QSharedPointer<GpgKeyTableModel> model,
});
connect(this, &QTableView::doubleClicked, this,
[this](const QModelIndex& index) {
- if (!index.isValid() || index.column() == 0) return;
-
- auto key = GpgKeyGetter::GetInstance(model_->GetGpgContextChannel())
- .GetKey(GetKeyIdByRow(index.row()));
- if (!key.IsGood()) {
- QMessageBox::critical(this, tr("Error"), tr("Key Not Found."));
- return;
- }
- new KeyDetailsDialog(model_->GetGpgContextChannel(), key, this);
+ if (!index.isValid()) return;
+
+ auto key = GetKeyByIndex(index);
+ if (key == nullptr) return;
+
+ CommonUtils::OpenDetailsDialogByKey(
+ this, model_->GetGpgContextChannel(), key);
+ });
+
+ connect(&proxy_model_, &GpgKeyTableProxyModel::dataChanged, this,
+ [=](const QModelIndex&, const QModelIndex&,
+ const QContainer<int>& roles) {
+ if (!roles.contains(Qt::CheckStateRole)) return;
+ emit SignalKeyChecked();
});
}
@@ -104,22 +109,22 @@ auto KeyTable::IsRowChecked(int row) const -> bool {
auto KeyTable::GetRowCount() const -> int { return model()->rowCount(); }
-auto KeyTable::GetKeyIdByRow(int row) const -> QString {
- if (row < 0 || row >= model()->rowCount()) return {};
- auto origin_row = model()->index(row, 0).data().toInt();
- return model_->GetKeyIDByRow(origin_row);
-}
+auto KeyTable::GetKeyByIndex(QModelIndex index) const -> GpgAbstractKeyPtr {
+ auto idx = proxy_model_.mapToSource(index);
+ auto* i = idx.isValid() ? static_cast<GpgKeyTableItem*>(idx.internalPointer())
+ : nullptr;
+ assert(i != nullptr);
-auto KeyTable::IsPrivateKeyByRow(int row) const -> bool {
- if (row < 0 || row >= model()->rowCount()) return false;
- auto origin_row = model()->index(row, 0).data().toInt();
- return model_->IsPrivateKeyByRow(origin_row);
+ return i->SharedKey();
}
-auto KeyTable::IsPublicKeyByRow(int row) const -> bool {
- if (row < 0 || row >= model()->rowCount()) return false;
- auto origin_row = model()->index(row, 0).data().toInt();
- return !model_->IsPrivateKeyByRow(origin_row);
+auto KeyTable::GetSelectedKeys() const -> GpgAbstractKeyPtrList {
+ GpgAbstractKeyPtrList ret;
+ QItemSelectionModel* select = selectionModel();
+ for (auto index : select->selectedRows()) {
+ ret.push_back(GetKeyByIndex(index));
+ }
+ return ret;
}
void KeyTable::SetRowChecked(int row) const {
@@ -148,4 +153,9 @@ void KeyTable::UncheckAll() {
return selected_indexes.first().row();
}
+void KeyTable::SetFilter(const GpgKeyTableProxyModel::KeyFilter& filter) {
+ proxy_model_.SetFilter(filter);
+}
+
+void KeyTable::RefreshProxyModel() { proxy_model_.invalidate(); }
} // namespace GpgFrontend::UI \ No newline at end of file
diff --git a/src/ui/widgets/KeyTable.h b/src/ui/widgets/KeyTable.h
index fe73bc98..9f6d1ba5 100644
--- a/src/ui/widgets/KeyTable.h
+++ b/src/ui/widgets/KeyTable.h
@@ -54,9 +54,8 @@ struct KeyTable : public QTableView {
KeyTable(
QWidget* parent, QSharedPointer<GpgKeyTableModel> model,
GpgKeyTableDisplayMode _select_type, GpgKeyTableColumn _info_type,
- GpgKeyTableProxyModel::KeyFilter _filter = [](const GpgKey&) -> bool {
- return true;
- });
+ GpgKeyTableProxyModel::KeyFilter _filter =
+ [](const GpgAbstractKey*) -> bool { return true; });
/**
* @brief
@@ -70,7 +69,7 @@ struct KeyTable : public QTableView {
*
* @return KeyIdArgsListPtr&
*/
- [[nodiscard]] auto GetChecked() const -> KeyIdArgsList;
+ [[nodiscard]] auto GetCheckedKeys() const -> GpgAbstractKeyPtrList;
/**
* @brief
@@ -121,42 +120,45 @@ struct KeyTable : public QTableView {
[[nodiscard]] auto GetRowCount() const -> int;
/**
- * @brief Get the Key Id By Row object
+ * @brief
*
- * @param row
- * @return QString
+ * @param index
+ * @return GpgAbstractKeyPtr
+ */
+ [[nodiscard]] auto GetKeyByIndex(QModelIndex index) const
+ -> GpgAbstractKeyPtr;
+
+ /**
+ * @brief Get the Selected Keys object
+ *
+ * @param index
+ * @return GpgAbstractKeyPtrList
*/
- [[nodiscard]] auto GetKeyIdByRow(int row) const -> QString;
+ [[nodiscard]] auto GetSelectedKeys() const -> GpgAbstractKeyPtrList;
/**
* @brief
*
- * @param row
- * @return true
- * @return false
*/
- [[nodiscard]] auto IsPublicKeyByRow(int row) const -> bool;
+ void CheckAll();
/**
* @brief
*
- * @param row
- * @return true
- * @return false
*/
- [[nodiscard]] auto IsPrivateKeyByRow(int row) const -> bool;
+ void UncheckAll();
/**
* @brief
*
*/
- void CheckAll();
+ void SetFilter(const GpgKeyTableProxyModel::KeyFilter&);
/**
* @brief
*
*/
- void UncheckAll();
+ void RefreshProxyModel();
signals:
@@ -172,6 +174,12 @@ struct KeyTable : public QTableView {
*/
void SignalGpgContextChannelChange(int);
+ /**
+ * @brief
+ *
+ */
+ void SignalKeyChecked();
+
private:
QSharedPointer<GpgKeyTableModel> model_;
GpgKeyTableProxyModel proxy_model_;
diff --git a/src/ui/widgets/KeyTreeView.cpp b/src/ui/widgets/KeyTreeView.cpp
index c0a00c4e..46cfa2db 100644
--- a/src/ui/widgets/KeyTreeView.cpp
+++ b/src/ui/widgets/KeyTreeView.cpp
@@ -31,9 +31,8 @@
#include <utility>
#include "core/function/gpg/GpgKeyGetter.h"
-#include "core/utils/GpgUtils.h"
#include "ui/UISignalStation.h"
-#include "ui/dialog/keypair_details/KeyDetailsDialog.h"
+#include "ui/UserInterfaceUtils.h"
#include "ui/model/GpgKeyTreeProxyModel.h"
namespace GpgFrontend::UI {
@@ -109,18 +108,13 @@ void KeyTreeView::init() {
connect(this, &QTableView::doubleClicked, this,
[this](const QModelIndex& index) {
- if (!index.isValid() || index.column() == 0) return;
+ if (!index.isValid()) return;
- QModelIndex source_index = proxy_model_.mapToSource(index);
- auto key =
- GetGpgKeyByGpgAbstractKey(model_->GetKeyByIndex(source_index));
+ auto key = GetKeyByIndex(index);
+ if (key == nullptr) return;
- if (!key.IsGood()) {
- QMessageBox::critical(this, tr("Error"), tr("Key Not Found."));
- return;
- }
-
- new KeyDetailsDialog(model_->GetGpgContextChannel(), key, this);
+ CommonUtils::OpenDetailsDialogByKey(
+ this, model_->GetGpgContextChannel(), key);
});
connect(UISignalStation::GetInstance(),
@@ -150,4 +144,12 @@ void KeyTreeView::SetChannel(int channel) {
proxy_model_.invalidate();
}
+auto KeyTreeView::GetKeyByIndex(QModelIndex index) -> GpgAbstractKeyPtr {
+ auto* i = index.isValid()
+ ? static_cast<GpgKeyTreeItem*>(index.internalPointer())
+ : nullptr;
+ assert(i != nullptr);
+
+ return i->SharedKey();
+}
} // namespace GpgFrontend::UI
diff --git a/src/ui/widgets/KeyTreeView.h b/src/ui/widgets/KeyTreeView.h
index 0e12ad0b..af903273 100644
--- a/src/ui/widgets/KeyTreeView.h
+++ b/src/ui/widgets/KeyTreeView.h
@@ -64,6 +64,14 @@ class KeyTreeView : public QTreeView {
QWidget* parent = nullptr);
/**
+ * @brief Get the Key By Index object
+ *
+ * @param index
+ * @return GpgAbstractKeyPtr
+ */
+ static auto GetKeyByIndex(QModelIndex index) -> GpgAbstractKeyPtr;
+
+ /**
* @brief Get the All Checked Key Ids object
*
* @return KeyIdArgsList
diff --git a/src/ui/widgets/VerifyKeyDetailBox.cpp b/src/ui/widgets/VerifyKeyDetailBox.cpp
index eca7f03c..0cad1b6e 100644
--- a/src/ui/widgets/VerifyKeyDetailBox.cpp
+++ b/src/ui/widgets/VerifyKeyDetailBox.cpp
@@ -28,7 +28,6 @@
#include "ui/widgets/VerifyKeyDetailBox.h"
-#include "core/GpgModel.h"
#include "core/function/GlobalSettingStation.h"
#include "core/function/gpg/GpgKeyGetter.h"
#include "core/utils/CommonUtils.h"
@@ -41,7 +40,8 @@ VerifyKeyDetailBox::VerifyKeyDetailBox(int channel,
QWidget* parent)
: QGroupBox(parent),
current_gpg_context_channel_(channel),
- fpr_(signature.GetFingerprint()) {
+ key_(GpgKeyGetter::GetInstance(channel).GetKeyPtr(
+ signature.GetFingerprint())) {
auto* vbox = new QVBoxLayout();
switch (gpg_err_code(signature.GetStatus())) {
@@ -58,7 +58,7 @@ VerifyKeyDetailBox::VerifyKeyDetailBox(int channel,
connect(import_button, &QPushButton::clicked, this,
&VerifyKeyDetailBox::slot_import_form_key_server);
- this->setTitle(tr("Key not present with id 0x") + fpr_);
+ this->setTitle(tr("Key not present with id 0x") + key_->ID());
auto* grid = new QGridLayout();
@@ -166,27 +166,26 @@ VerifyKeyDetailBox::VerifyKeyDetailBox(int channel,
}
void VerifyKeyDetailBox::slot_import_form_key_server() {
- CommonUtils::GetInstance()->ImportKeyFromKeyServer(
- current_gpg_context_channel_, {fpr_});
+ CommonUtils::GetInstance()->ImportGpgKeyFromKeyServer(
+ current_gpg_context_channel_, {key_});
}
auto VerifyKeyDetailBox::create_key_info_grid(const GpgSignature& signature)
-> QGridLayout* {
auto* grid = new QGridLayout();
- auto key =
- GpgKeyGetter::GetInstance(current_gpg_context_channel_).GetKey(fpr_);
- assert(key.IsGood());
- if (!key.IsGood()) return nullptr;
+ assert(key_->IsGood());
+ if (!key_->IsGood()) return nullptr;
+
grid->addWidget(new QLabel(tr("Signer Name") + ":"), 0, 0);
grid->addWidget(new QLabel(tr("Signer Email") + ":"), 1, 0);
grid->addWidget(new QLabel(tr("Key's Fingerprint") + ":"), 2, 0);
grid->addWidget(new QLabel(tr("Valid") + ":"), 3, 0);
grid->addWidget(new QLabel(tr("Flags") + ":"), 4, 0);
- grid->addWidget(new QLabel(key.Name()), 0, 1);
- grid->addWidget(new QLabel(key.Email()), 1, 1);
- grid->addWidget(new QLabel(BeautifyFingerprint(fpr_)), 2, 1);
+ grid->addWidget(new QLabel(key_->Name()), 0, 1);
+ grid->addWidget(new QLabel(key_->Email()), 1, 1);
+ grid->addWidget(new QLabel(BeautifyFingerprint(key_->Fingerprint())), 2, 1);
if ((signature.GetSummary() & GPGME_SIGSUM_VALID) != 0U) {
grid->addWidget(new QLabel(tr("Fully Valid")), 3, 1);
diff --git a/src/ui/widgets/VerifyKeyDetailBox.h b/src/ui/widgets/VerifyKeyDetailBox.h
index 55bcb7ec..39f2aaca 100644
--- a/src/ui/widgets/VerifyKeyDetailBox.h
+++ b/src/ui/widgets/VerifyKeyDetailBox.h
@@ -65,7 +65,7 @@ class VerifyKeyDetailBox : public QGroupBox {
QGridLayout* create_key_info_grid(const GpgSignature& signature);
int current_gpg_context_channel_;
- QString fpr_; ///< fingerprint of the key
+ GpgKeyPtr key_; ///< fingerprint of the key
};
} // namespace GpgFrontend::UI