aboutsummaryrefslogtreecommitdiffstats
path: root/src/ui
diff options
context:
space:
mode:
authorsaturneric <[email protected]>2025-04-16 18:05:00 +0000
committersaturneric <[email protected]>2025-04-16 18:05:00 +0000
commit272cf34f21ab1741d24673a7e3b7c95567a74cec (patch)
tree4497435e41a8bbdd7560cee57b2c8c4171099951 /src/ui
parentfix: found bugs (diff)
downloadGpgFrontend-272cf34f21ab1741d24673a7e3b7c95567a74cec.tar.gz
GpgFrontend-272cf34f21ab1741d24673a7e3b7c95567a74cec.zip
fix: testing and solve bugs found
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/UserInterfaceUtils.cpp27
-rw-r--r--src/ui/dialog/ADSKsPicker.cpp55
-rw-r--r--src/ui/dialog/ADSKsPicker.h13
-rw-r--r--src/ui/dialog/KeyGroupCreationDialog.cpp31
-rw-r--r--src/ui/dialog/KeyGroupManageDialog.cpp28
-rw-r--r--src/ui/dialog/KeyGroupManageDialog.h12
-rw-r--r--src/ui/dialog/import_export/KeyImportDetailDialog.cpp12
-rw-r--r--src/ui/dialog/import_export/KeyServerImportDialog.cpp12
-rw-r--r--src/ui/dialog/import_export/KeyUploadDialog.cpp1
-rw-r--r--src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp1
-rw-r--r--src/ui/dialog/keypair_details/KeyNewUIDDialog.cpp2
-rw-r--r--src/ui/dialog/keypair_details/KeyPairDetailTab.cpp2
-rw-r--r--src/ui/dialog/keypair_details/KeyPairOperaTab.cpp148
-rw-r--r--src/ui/dialog/keypair_details/KeyPairOperaTab.h11
-rw-r--r--src/ui/dialog/keypair_details/KeyPairSubkeyTab.cpp51
-rw-r--r--src/ui/dialog/keypair_details/KeyPairUIDTab.cpp2
-rw-r--r--src/ui/dialog/keypair_details/KeySetExpireDateDialog.cpp2
-rw-r--r--src/ui/main_window/KeyMgmt.cpp50
-rw-r--r--src/ui/main_window/KeyMgmt.h9
-rw-r--r--src/ui/main_window/MainWindow.cpp61
-rw-r--r--src/ui/main_window/MainWindow.h23
-rw-r--r--src/ui/main_window/MainWindowSlotUI.cpp17
-rw-r--r--src/ui/main_window/MainWindowUI.cpp2
-rw-r--r--src/ui/widgets/KeyList.cpp62
-rw-r--r--src/ui/widgets/KeyList.h20
-rw-r--r--src/ui/widgets/KeyTreeView.cpp12
26 files changed, 373 insertions, 293 deletions
diff --git a/src/ui/UserInterfaceUtils.cpp b/src/ui/UserInterfaceUtils.cpp
index e66a775c..7cae0648 100644
--- a/src/ui/UserInterfaceUtils.cpp
+++ b/src/ui/UserInterfaceUtils.cpp
@@ -184,9 +184,17 @@ void CommonUtils::SlotImportKeys(QWidget *parent, int channel,
LOG_D() << "try to import key(s) to channel: " << channel;
auto info =
GpgKeyImportExporter::GetInstance(channel).ImportKey(GFBuffer(in_buffer));
- emit SignalKeyStatusUpdated();
- (new KeyImportDetailDialog(channel, info, parent));
+ auto *connection = new QMetaObject::Connection;
+ *connection =
+ connect(UISignalStation::GetInstance(),
+ &UISignalStation::SignalKeyDatabaseRefreshDone, this, [=]() {
+ (new KeyImportDetailDialog(channel, info, parent));
+ QObject::disconnect(*connection);
+ delete connection;
+ });
+
+ emit SignalKeyStatusUpdated();
}
void CommonUtils::SlotImportKeyFromFile(QWidget *parent, int channel) {
@@ -332,6 +340,9 @@ void CommonUtils::SlotImportKeyFromKeyServer(
.GetTaskRunner(Thread::TaskRunnerGetter::kTaskRunnerType_Network)
->PostTask(new Thread::Task(
[=](const DataObjectPtr &data_obj) -> int {
+ // rate limit
+ QThread::msleep(200);
+ // call
Module::TriggerEvent(
"REQUEST_GET_PUBLIC_KEY_BY_KEY_ID",
{
@@ -374,8 +385,6 @@ void CommonUtils::SlotImportKeyFromKeyServer(
},
QString("key_%1_import_task").arg(key_id)));
- // not too fast to hit rate limit
- QThread::msleep(200);
current_index++;
}
@@ -480,8 +489,14 @@ void CommonUtils::slot_update_key_from_server_finished(
// refresh the key database
emit UISignalStation::GetInstance() -> SignalKeyDatabaseRefresh();
- // show details
- (new KeyImportDetailDialog(channel, std::move(info), this))->exec();
+ auto *connection = new QMetaObject::Connection;
+ *connection =
+ connect(UISignalStation::GetInstance(),
+ &UISignalStation::SignalKeyDatabaseRefreshDone, this, [=]() {
+ (new KeyImportDetailDialog(channel, info, this));
+ QObject::disconnect(*connection);
+ delete connection;
+ });
}
void CommonUtils::SlotRestartApplication(int code) {
diff --git a/src/ui/dialog/ADSKsPicker.cpp b/src/ui/dialog/ADSKsPicker.cpp
index 9d9fa4c3..09648355 100644
--- a/src/ui/dialog/ADSKsPicker.cpp
+++ b/src/ui/dialog/ADSKsPicker.cpp
@@ -28,12 +28,14 @@
#include "ADSKsPicker.h"
-#include "core/GpgModel.h"
+#include "core/function/gpg/GpgKeyOpera.h"
+#include "core/utils/GpgUtils.h"
+#include "ui/UISignalStation.h"
#include "ui/widgets/KeyTreeView.h"
namespace GpgFrontend::UI {
-ADSKsPicker::ADSKsPicker(int channel,
+ADSKsPicker::ADSKsPicker(int channel, GpgKeyPtr key,
const GpgKeyTreeProxyModel::KeyFilter& filter,
QWidget* parent)
: GeneralDialog(typeid(ADSKsPicker).name(), parent),
@@ -47,14 +49,22 @@ ADSKsPicker::ADSKsPicker(int channel,
(k->KeyType() == GpgAbstractKeyType::kGPG_SUBKEY &&
k->IsHasEncrCap())) &&
filter(k);
- })) {
+ })),
+ channel_(channel),
+ key_(std::move(key)) {
auto* confirm_button = new QPushButton(tr("Confirm"));
auto* cancel_button = new QPushButton(tr("Cancel"));
connect(confirm_button, &QPushButton::clicked, this, [=]() {
- emit SignalSubkeyChecked(tree_view_->GetAllCheckedSubKey());
+ if (tree_view_->GetAllCheckedSubKey().isEmpty()) {
+ QMessageBox::information(this, tr("No Subkeys Selected"),
+ tr("Please select at least one s_key."));
+
+ return;
+ }
+ slot_add_adsk(tree_view_->GetAllCheckedSubKey());
+ accept();
});
- connect(confirm_button, &QPushButton::clicked, this, &QDialog::accept);
connect(cancel_button, &QPushButton::clicked, this, &QDialog::reject);
tree_view_->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
@@ -88,4 +98,39 @@ ADSKsPicker::ADSKsPicker(int channel,
this->activateWindow();
}
+void ADSKsPicker::slot_add_adsk(const QContainer<GpgSubKey>& s_keys) {
+ QContainer<QString> err_sub_key_infos;
+ for (const auto& s_key : s_keys) {
+ auto [err, data_object] =
+ GpgKeyOpera::GetInstance(channel_).AddADSKSync(key_, s_key);
+ if (CheckGpgError(err) == GPG_ERR_NO_ERROR) continue;
+
+ err_sub_key_infos.append(tr("Key ID: %1 Reason: %2")
+ .arg(s_key.ID())
+ .arg(DescribeGpgErrCode(err).second));
+ }
+
+ if (!err_sub_key_infos.isEmpty()) {
+ QStringList failed_info;
+ for (const auto& info : err_sub_key_infos) {
+ failed_info.append(info);
+ }
+ QString details = failed_info.join("\n\n");
+
+ auto* msg_box = new QMessageBox(nullptr);
+ msg_box->setIcon(QMessageBox::Warning);
+ msg_box->setWindowTitle(err_sub_key_infos.size() == s_keys.size()
+ ? tr("Failed")
+ : tr("Partially Failed"));
+ msg_box->setText(err_sub_key_infos.size() == s_keys.size()
+ ? tr("Failed to add all selected subkeys.")
+ : tr("Some subkeys failed to be added as ADSKs."));
+ msg_box->setDetailedText(details);
+ msg_box->show();
+
+ return;
+ }
+
+ emit UISignalStation::GetInstance() -> SignalKeyDatabaseRefresh();
+}
} // namespace GpgFrontend::UI
diff --git a/src/ui/dialog/ADSKsPicker.h b/src/ui/dialog/ADSKsPicker.h
index 59c7b06b..577ac06a 100644
--- a/src/ui/dialog/ADSKsPicker.h
+++ b/src/ui/dialog/ADSKsPicker.h
@@ -50,16 +50,23 @@ class ADSKsPicker : public GeneralDialog {
*
* @param parent
*/
- explicit ADSKsPicker(int channel,
+ explicit ADSKsPicker(int channel, GpgKeyPtr key,
const GpgKeyTreeProxyModel::KeyFilter& filter,
QWidget* parent = nullptr);
- signals:
- void SignalSubkeyChecked(QContainer<GpgSubKey>);
+ private slots:
+ /**
+ * @brief
+ *
+ * @param s_keys
+ */
+ void slot_add_adsk(const QContainer<GpgSubKey>& s_keys);
private:
KeyTreeView* tree_view_; ///<
bool accepted_ = false;
+ int channel_;
+ GpgKeyPtr key_;
};
} // namespace GpgFrontend::UI
diff --git a/src/ui/dialog/KeyGroupCreationDialog.cpp b/src/ui/dialog/KeyGroupCreationDialog.cpp
index 506c173d..16e34536 100644
--- a/src/ui/dialog/KeyGroupCreationDialog.cpp
+++ b/src/ui/dialog/KeyGroupCreationDialog.cpp
@@ -46,20 +46,29 @@ KeyGroupCreationDialog::KeyGroupCreationDialog(int channel, QStringList key_ids,
email_->setMinimumWidth(240);
comment_ = new QLineEdit();
comment_->setMinimumWidth(240);
- create_button_ = new QPushButton("Create");
+ create_button_ = new QPushButton(tr("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);
+ auto* description_label = new QLabel(tr(
+ "A Key Group is a collection of keys. It allows you to encrypt data for "
+ "multiple recipients at once by grouping their public keys together."));
+ description_label->setWordWrap(true);
+ description_label->setStyleSheet("color: gray; font-size: 11px;");
- grid_layout->addWidget(create_button_, 3, 0, 1, 2);
- grid_layout->addWidget(error_label_, 4, 0, 1, 2);
+ grid_layout->addWidget(description_label, 0, 0, 2, 2);
+
+ grid_layout->addWidget(new QLabel(tr("Name")), 2, 0);
+ grid_layout->addWidget(new QLabel(tr("Email")), 3, 0);
+ grid_layout->addWidget(new QLabel(tr("Comment")), 4, 0);
+
+ grid_layout->addWidget(name_, 2, 1);
+ grid_layout->addWidget(email_, 3, 1);
+ grid_layout->addWidget(comment_, 4, 1);
+
+ grid_layout->addWidget(create_button_, 5, 0, 1, 2);
+ grid_layout->addWidget(error_label_, 6, 0, 1, 2);
connect(create_button_, &QPushButton::clicked, this,
&KeyGroupCreationDialog::slot_create_new_uid);
@@ -68,8 +77,10 @@ KeyGroupCreationDialog::KeyGroupCreationDialog(int channel, QStringList key_ids,
UISignalStation::GetInstance(),
&UISignalStation::SignalKeyDatabaseRefresh);
+ setMinimumHeight(250);
+
this->setLayout(grid_layout);
- this->setWindowTitle(tr("Create New Key Group"));
+ this->setWindowTitle(tr("New Key Group"));
this->setAttribute(Qt::WA_DeleteOnClose, true);
this->setModal(true);
}
diff --git a/src/ui/dialog/KeyGroupManageDialog.cpp b/src/ui/dialog/KeyGroupManageDialog.cpp
index cbd70b61..88892ada 100644
--- a/src/ui/dialog/KeyGroupManageDialog.cpp
+++ b/src/ui/dialog/KeyGroupManageDialog.cpp
@@ -54,7 +54,8 @@ KeyGroupManageDialog::KeyGroupManageDialog(
ui_->keyGroupKeyList->Init(
channel, KeyMenuAbility::kCOLUMN_FILTER | KeyMenuAbility::kSEARCH_BAR,
GpgKeyTableColumn::kTYPE | GpgKeyTableColumn::kNAME |
- GpgKeyTableColumn::kEMAIL_ADDRESS | GpgKeyTableColumn::kKEY_ID);
+ GpgKeyTableColumn::kEMAIL_ADDRESS | GpgKeyTableColumn::kKEY_ID |
+ GpgKeyTableColumn::kUSAGE);
ui_->keyGroupKeyList->AddListGroupTab(
tr("Key Group"), "key-group",
GpgKeyTableDisplayMode::kPRIVATE_KEY |
@@ -78,6 +79,14 @@ KeyGroupManageDialog::KeyGroupManageDialog(
});
ui_->keyList->SlotRefresh();
+ connect(ui_->keyList, &KeyList::SignalKeyChecked, this,
+ &KeyGroupManageDialog::slot_set_add_button_state);
+ connect(ui_->keyGroupKeyList, &KeyList::SignalKeyChecked, this,
+ &KeyGroupManageDialog::slot_set_remove_button_state);
+
+ ui_->addButton->setDisabled(true);
+ ui_->removeButton->setDisabled(true);
+
QTimer::singleShot(200, [=]() { slot_notify_invalid_key_ids(); });
this->setModal(true);
@@ -104,6 +113,8 @@ void KeyGroupManageDialog::slot_add_to_key_group() {
ui_->keyGroupKeyList->RefreshKeyTable(0);
ui_->keyList->RefreshKeyTable(0);
+ slot_set_add_button_state();
+ slot_set_remove_button_state();
if (!failed_keys.isEmpty()) {
QStringList failed_ids;
@@ -127,6 +138,8 @@ void KeyGroupManageDialog::slot_remove_from_key_group() {
ui_->keyGroupKeyList->RefreshKeyTable(0);
ui_->keyList->RefreshKeyTable(0);
+ slot_set_add_button_state();
+ slot_set_remove_button_state();
}
void KeyGroupManageDialog::slot_notify_invalid_key_ids() {
@@ -138,9 +151,7 @@ void KeyGroupManageDialog::slot_notify_invalid_key_ids() {
if (key == nullptr) invalid_key_ids.push_back(key_id);
}
- if (invalid_key_ids.isEmpty()) {
- return;
- }
+ if (invalid_key_ids.isEmpty()) return;
const QString id_list = invalid_key_ids.join(", ");
const auto message =
@@ -163,4 +174,13 @@ void KeyGroupManageDialog::slot_notify_invalid_key_ids() {
emit UISignalStation::GetInstance() -> SignalKeyDatabaseRefresh();
}
+
+void KeyGroupManageDialog::slot_set_add_button_state() {
+ ui_->addButton->setDisabled(ui_->keyList->GetCheckedKeys().isEmpty());
+}
+
+void KeyGroupManageDialog::slot_set_remove_button_state() {
+ ui_->removeButton->setDisabled(
+ ui_->keyGroupKeyList->GetCheckedKeys().isEmpty());
+}
} // namespace GpgFrontend::UI
diff --git a/src/ui/dialog/KeyGroupManageDialog.h b/src/ui/dialog/KeyGroupManageDialog.h
index 66211d28..902bbb59 100644
--- a/src/ui/dialog/KeyGroupManageDialog.h
+++ b/src/ui/dialog/KeyGroupManageDialog.h
@@ -74,6 +74,18 @@ class KeyGroupManageDialog : public GeneralDialog {
*/
void slot_notify_invalid_key_ids();
+ /**
+ * @brief
+ *
+ */
+ void slot_set_add_button_state();
+
+ /**
+ * @brief
+ *
+ */
+ void slot_set_remove_button_state();
+
private:
QSharedPointer<Ui_KeyGroupManageDialog> ui_; ///<
int channel_;
diff --git a/src/ui/dialog/import_export/KeyImportDetailDialog.cpp b/src/ui/dialog/import_export/KeyImportDetailDialog.cpp
index 24062796..92e45eb6 100644
--- a/src/ui/dialog/import_export/KeyImportDetailDialog.cpp
+++ b/src/ui/dialog/import_export/KeyImportDetailDialog.cpp
@@ -28,7 +28,7 @@
#include "KeyImportDetailDialog.h"
-#include "core/function/gpg/GpgKeyGetter.h"
+#include "core/function/gpg/GpgAbstractKeyGetter.h"
#include "core/model/GpgImportInformation.h"
namespace GpgFrontend::UI {
@@ -147,11 +147,13 @@ void KeyImportDetailDialog::create_keys_table() {
int row = 0;
for (const auto& imp_key : m_result_->imported_keys) {
keys_table_->setRowCount(row + 1);
- auto key = GpgKeyGetter::GetInstance(current_gpg_context_channel_)
+
+ auto key = GpgAbstractKeyGetter::GetInstance(current_gpg_context_channel_)
.GetKey(imp_key.fpr);
- if (!key.IsGood()) continue;
- keys_table_->setItem(row, 0, new QTableWidgetItem(key.Name()));
- keys_table_->setItem(row, 1, new QTableWidgetItem(key.Email()));
+ if (key == nullptr) continue;
+
+ keys_table_->setItem(row, 0, new QTableWidgetItem(key->Name()));
+ keys_table_->setItem(row, 1, new QTableWidgetItem(key->Email()));
keys_table_->setItem(
row, 2, new QTableWidgetItem(get_status_string(imp_key.import_status)));
keys_table_->setItem(row, 3, new QTableWidgetItem(imp_key.fpr));
diff --git a/src/ui/dialog/import_export/KeyServerImportDialog.cpp b/src/ui/dialog/import_export/KeyServerImportDialog.cpp
index 03ee6c4a..8e01bd4b 100644
--- a/src/ui/dialog/import_export/KeyServerImportDialog.cpp
+++ b/src/ui/dialog/import_export/KeyServerImportDialog.cpp
@@ -422,10 +422,14 @@ void KeyServerImportDialog::slot_import_finished(
// refresh the key database
emit SignalKeyImported();
- // show details
- (new KeyImportDetailDialog(current_gpg_context_channel_, std::move(info),
- this))
- ->exec();
+ auto* connection = new QMetaObject::Connection;
+ *connection = connect(
+ UISignalStation::GetInstance(),
+ &UISignalStation::SignalKeyDatabaseRefreshDone, this, [=]() {
+ (new KeyImportDetailDialog(current_gpg_context_channel_, info, this));
+ QObject::disconnect(*connection);
+ delete connection;
+ });
}
void KeyServerImportDialog::set_loading(bool status) {
diff --git a/src/ui/dialog/import_export/KeyUploadDialog.cpp b/src/ui/dialog/import_export/KeyUploadDialog.cpp
index 346be765..8abcc8de 100644
--- a/src/ui/dialog/import_export/KeyUploadDialog.cpp
+++ b/src/ui/dialog/import_export/KeyUploadDialog.cpp
@@ -29,7 +29,6 @@
#include "KeyUploadDialog.h"
#include <QtNetwork>
-#include <utility>
#include "core/function/gpg/GpgKeyImportExporter.h"
#include "core/model/SettingsObject.h"
diff --git a/src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp b/src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp
index 662ac77a..b182e017 100644
--- a/src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp
+++ b/src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp
@@ -30,7 +30,6 @@
#include <cassert>
#include <cstddef>
-#include <utility>
#include "core/function/gpg/GpgKeyOpera.h"
#include "core/utils/GpgUtils.h"
diff --git a/src/ui/dialog/keypair_details/KeyNewUIDDialog.cpp b/src/ui/dialog/keypair_details/KeyNewUIDDialog.cpp
index d05154d5..6a6745da 100644
--- a/src/ui/dialog/keypair_details/KeyNewUIDDialog.cpp
+++ b/src/ui/dialog/keypair_details/KeyNewUIDDialog.cpp
@@ -28,8 +28,6 @@
#include "KeyNewUIDDialog.h"
-#include <utility>
-
#include "core/function/gpg/GpgUIDOperator.h"
#include "ui/UISignalStation.h"
diff --git a/src/ui/dialog/keypair_details/KeyPairDetailTab.cpp b/src/ui/dialog/keypair_details/KeyPairDetailTab.cpp
index fcdc139e..b5a6c1d2 100644
--- a/src/ui/dialog/keypair_details/KeyPairDetailTab.cpp
+++ b/src/ui/dialog/keypair_details/KeyPairDetailTab.cpp
@@ -28,8 +28,6 @@
#include "KeyPairDetailTab.h"
-#include <utility>
-
#include "core/function/GlobalSettingStation.h"
#include "core/function/gpg/GpgKeyGetter.h"
#include "core/model/GpgKey.h"
diff --git a/src/ui/dialog/keypair_details/KeyPairOperaTab.cpp b/src/ui/dialog/keypair_details/KeyPairOperaTab.cpp
index dddbb545..a06ec835 100644
--- a/src/ui/dialog/keypair_details/KeyPairOperaTab.cpp
+++ b/src/ui/dialog/keypair_details/KeyPairOperaTab.cpp
@@ -34,6 +34,7 @@
#include "core/function/gpg/GpgKeyOpera.h"
#include "core/model/GpgKey.h"
#include "core/module/ModuleManager.h"
+#include "core/thread/TaskRunnerGetter.h"
#include "core/typedef/GpgTypedef.h"
#include "core/utils/GpgUtils.h"
#include "core/utils/IOUtils.h"
@@ -131,8 +132,9 @@ KeyPairOperaTab::KeyPairOperaTab(int channel, GpgKeyPtr key, QWidget* parent)
opera_key_box->setLayout(vbox_p_k);
m_vbox->addWidget(opera_key_box);
// modify owner trust of public key
- if (!m_key_->IsPrivateKey())
+ if (!m_key_->IsPrivateKey()) {
vbox_p_k->addWidget(set_owner_trust_level_button);
+ }
vbox_p_k->addWidget(modify_tofu_button);
m_vbox->addStretch(0);
@@ -212,37 +214,68 @@ void KeyPairOperaTab::CreateOperaMenu() {
rev_cert_opera_menu_->addAction(rev_cert_gen_action);
}
-void KeyPairOperaTab::slot_export_public_key() {
- auto [err, gf_buffer] =
- GpgKeyImportExporter::GetInstance(current_gpg_context_channel_)
- .ExportKey(m_key_, false, true, false);
- if (CheckGpgError(err) != GPG_ERR_NO_ERROR) {
- CommonUtils::RaiseMessageBox(this, err);
- return;
- }
+void KeyPairOperaTab::slot_export_key(bool secret, bool ascii, bool shortest,
+ const QString& type) {
+ auto* task = new Thread::Task(
+ [=](const DataObjectPtr& data_object) -> int {
+ auto [err, gf_buffer] =
+ GpgKeyImportExporter::GetInstance(current_gpg_context_channel_)
+ .ExportKey(m_key_, secret, ascii, shortest);
+ data_object->Swap({err, gf_buffer});
+ return 0;
+ },
+ "key_export", TransferParams(),
+ [=](int ret, const DataObjectPtr& data_object) {
+ if (ret < 0) {
+ QMessageBox::critical(
+ this, tr("Unknown Error"),
+ tr("Caught unknown error while exporting the key."));
+ return;
+ }
- // generate a file name
+ // 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_name = QString("%1[%2](%3)_%4.asc");
#else
- auto file_string = m_key_->Name() + "<" + m_key_->Email() + ">(" +
- m_key_->ID() + ")_pub.asc";
+ auto file_name = QString("%1<%2[(%3)_%4.asc");
#endif
- std::replace(file_string.begin(), file_string.end(), ' ', '_');
- auto file_name = QFileDialog::getSaveFileName(
- this, tr("Export Key To File"), file_string,
- tr("Key Files") + " (*.asc *.txt);;All Files (*)");
+ file_name =
+ file_name.arg(m_key_->Name(), m_key_->Email(), m_key_->ID(), type);
- if (file_name.isEmpty()) return;
+ if (!data_object->Check<GpgError, GFBuffer>()) return;
- if (!WriteFileGFBuffer(file_name, gf_buffer)) {
- QMessageBox::critical(this, tr("Export Error"),
- tr("Couldn't open %1 for writing").arg(file_name));
- return;
- }
+ auto err = ExtractParams<GpgError>(data_object, 0);
+ auto gf_buffer = ExtractParams<GFBuffer>(data_object, 1);
+
+ if (CheckGpgError(err) != GPG_ERR_NO_ERROR) {
+ CommonUtils::RaiseMessageBox(this, err);
+ return;
+ }
+
+ file_name.replace(' ', '_');
+
+ auto filepath = QFileDialog::getSaveFileName(
+ this, tr("Export Key To File"), file_name,
+ tr("Key Files") + " (*.asc *.txt);;All Files (*)");
+
+ if (filepath.isEmpty()) return;
+
+ if (!WriteFileGFBuffer(filepath, gf_buffer)) {
+ QMessageBox::critical(
+ this, tr("Export Error"),
+ tr("Couldn't open %1 for writing").arg(file_name));
+ return;
+ }
+ });
+
+ Thread::TaskRunnerGetter::GetInstance()
+ .GetTaskRunner(Thread::TaskRunnerGetter::kTaskRunnerType_GPG)
+ ->PostTask(task);
+}
+
+void KeyPairOperaTab::slot_export_public_key() {
+ slot_export_key(false, true, false, "pub");
}
void KeyPairOperaTab::slot_export_short_private_key() {
@@ -261,38 +294,9 @@ void KeyPairOperaTab::slot_export_short_private_key() {
QMessageBox::Cancel | QMessageBox::Ok);
// export key, if ok was clicked
- if (ret == QMessageBox::Ok) {
- auto [err, gf_buffer] =
- GpgKeyImportExporter::GetInstance(current_gpg_context_channel_)
- .ExportKey(m_key_, true, true, true);
- if (CheckGpgError(err) != GPG_ERR_NO_ERROR) {
- CommonUtils::RaiseMessageBox(this, err);
- return;
- }
-
- // generate a file name
-#if defined(_WIN32) || defined(WIN32)
-
- 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";
-#endif
- std::replace(file_string.begin(), file_string.end(), ' ', '_');
-
- auto file_name = QFileDialog::getSaveFileName(
- this, tr("Export Key To File"), file_string,
- tr("Key Files") + " (*.asc *.txt);;All Files (*)");
-
- if (file_name.isEmpty()) return;
+ if (ret != QMessageBox::Ok) return;
- if (!WriteFileGFBuffer(file_name, gf_buffer)) {
- QMessageBox::critical(this, tr("Export Error"),
- tr("Couldn't open %1 for writing").arg(file_name));
- return;
- }
- }
+ slot_export_key(true, true, false, "short_secret");
}
void KeyPairOperaTab::slot_export_private_key() {
@@ -313,37 +317,9 @@ void KeyPairOperaTab::slot_export_private_key() {
QMessageBox::Cancel | QMessageBox::Ok);
// export key, if ok was clicked
- if (ret == QMessageBox::Ok) {
- auto [err, gf_buffer] =
- GpgKeyImportExporter::GetInstance(current_gpg_context_channel_)
- .ExportKey(m_key_, true, true, false);
- if (CheckGpgError(err) != GPG_ERR_NO_ERROR) {
- CommonUtils::RaiseMessageBox(this, err);
- return;
- }
-
- // generate a file name
-#if defined(_WIN32) || defined(WIN32)
- 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";
-#endif
- std::replace(file_string.begin(), file_string.end(), ' ', '_');
-
- auto file_name = QFileDialog::getSaveFileName(
- this, tr("Export Key To File"), file_string,
- tr("Key Files") + " (*.asc *.txt);;All Files (*)");
-
- if (file_name.isEmpty()) return;
+ if (ret != QMessageBox::Ok) return;
- if (!WriteFileGFBuffer(file_name, gf_buffer)) {
- QMessageBox::critical(this, tr("Export Error"),
- tr("Couldn't open %1 for writing").arg(file_name));
- return;
- }
- }
+ slot_export_key(true, true, false, "full_secret");
}
void KeyPairOperaTab::slot_modify_edit_datetime() {
diff --git a/src/ui/dialog/keypair_details/KeyPairOperaTab.h b/src/ui/dialog/keypair_details/KeyPairOperaTab.h
index 729a7d74..02566b61 100644
--- a/src/ui/dialog/keypair_details/KeyPairOperaTab.h
+++ b/src/ui/dialog/keypair_details/KeyPairOperaTab.h
@@ -138,6 +138,17 @@ class KeyPairOperaTab : public QWidget {
*/
void slot_import_paper_key();
+ /**
+ * @brief
+ *
+ * @param secret
+ * @param ascii
+ * @param shortest
+ * @param type
+ */
+ void slot_export_key(bool secret, bool ascii, bool shortest,
+ const QString& type);
+
private:
int current_gpg_context_channel_;
GpgKeyPtr m_key_; ///<
diff --git a/src/ui/dialog/keypair_details/KeyPairSubkeyTab.cpp b/src/ui/dialog/keypair_details/KeyPairSubkeyTab.cpp
index fa0c5c34..90bd3537 100644
--- a/src/ui/dialog/keypair_details/KeyPairSubkeyTab.cpp
+++ b/src/ui/dialog/keypair_details/KeyPairSubkeyTab.cpp
@@ -28,8 +28,6 @@
#include "KeyPairSubkeyTab.h"
-#include <utility>
-
#include "core/function/gpg/GpgKeyGetter.h"
#include "core/function/gpg/GpgKeyImportExporter.h"
#include "core/function/gpg/GpgKeyManager.h"
@@ -291,57 +289,12 @@ void KeyPairSubkeyTab::slot_add_adsk() {
except_key_ids.append(s_key.ID());
}
- auto* dialog = new ADSKsPicker(
- current_gpg_context_channel_,
+ new ADSKsPicker(
+ current_gpg_context_channel_, key_,
[=](const GpgAbstractKey* key) {
return !except_key_ids.contains(key->ID());
},
this);
-
- connect(dialog, &ADSKsPicker::SignalSubkeyChecked, this,
- [=](const QContainer<GpgSubKey>& s_keys) {
- if (s_keys.isEmpty()) {
- QMessageBox::information(this, tr("No Subkeys Selected"),
- tr("Please select at least one s_key."));
-
- return;
- }
-
- QContainer<GpgSubKey> err_sub_keys;
- for (const auto& s_key : s_keys) {
- auto [err, data_object] =
- GpgKeyOpera::GetInstance(current_gpg_context_channel_)
- .AddADSKSync(key_, s_key);
- if (CheckGpgError(err) == GPG_ERR_NO_ERROR) continue;
-
- err_sub_keys.append(s_key);
- }
-
- if (!err_sub_keys.isEmpty()) {
- QStringList failed_info;
- for (const auto& s_key : err_sub_keys) {
- QString key_id = s_key.ID();
- failed_info << tr("Key ID: %1").arg(key_id);
- }
-
- QString details = failed_info.join("\n\n");
-
- QMessageBox msg_box(this);
- msg_box.setIcon(QMessageBox::Warning);
- msg_box.setWindowTitle(err_sub_keys.size() == s_keys.size()
- ? tr("Failed")
- : tr("Partially Failed"));
- msg_box.setText(
- err_sub_keys.size() == s_keys.size()
- ? tr("Failed to add all selected subkeys.")
- : tr("Some subkeys failed to be added as ADSKs."));
- msg_box.setDetailedText(details);
- msg_box.exec();
- }
-
- emit SignalKeyDatabaseRefresh();
- });
- dialog->show();
}
void KeyPairSubkeyTab::slot_refresh_subkey_detail() {
diff --git a/src/ui/dialog/keypair_details/KeyPairUIDTab.cpp b/src/ui/dialog/keypair_details/KeyPairUIDTab.cpp
index e720b9b0..bc9e422c 100644
--- a/src/ui/dialog/keypair_details/KeyPairUIDTab.cpp
+++ b/src/ui/dialog/keypair_details/KeyPairUIDTab.cpp
@@ -28,8 +28,6 @@
#include "KeyPairUIDTab.h"
-#include <utility>
-
#include "core/function/gpg/GpgKeyGetter.h"
#include "core/function/gpg/GpgKeyManager.h"
#include "core/function/gpg/GpgUIDOperator.h"
diff --git a/src/ui/dialog/keypair_details/KeySetExpireDateDialog.cpp b/src/ui/dialog/keypair_details/KeySetExpireDateDialog.cpp
index b2d8d424..b1a33450 100644
--- a/src/ui/dialog/keypair_details/KeySetExpireDateDialog.cpp
+++ b/src/ui/dialog/keypair_details/KeySetExpireDateDialog.cpp
@@ -28,8 +28,6 @@
#include "KeySetExpireDateDialog.h"
-#include <utility>
-
#include "core/function/GlobalSettingStation.h"
#include "core/function/gpg/GpgKeyOpera.h"
#include "core/utils/GpgUtils.h"
diff --git a/src/ui/main_window/KeyMgmt.cpp b/src/ui/main_window/KeyMgmt.cpp
index cd5a9f05..e3128231 100644
--- a/src/ui/main_window/KeyMgmt.cpp
+++ b/src/ui/main_window/KeyMgmt.cpp
@@ -121,12 +121,17 @@ KeyMgmt::KeyMgmt(QWidget* parent)
setWindowTitle(tr("KeyPair Management"));
setMinimumSize(QSize(640, 480));
- key_list_->AddMenuAction(generate_subkey_act_);
- key_list_->AddMenuAction(delete_selected_keys_act_);
- key_list_->AddSeparator();
- key_list_->AddMenuAction(set_owner_trust_of_key_act_);
- key_list_->AddSeparator();
- key_list_->AddMenuAction(show_key_details_act_);
+ popup_menu_ = new QMenu(this);
+
+ popup_menu_->addAction(generate_subkey_act_);
+ popup_menu_->addAction(delete_selected_keys_act_);
+ popup_menu_->addSeparator();
+ popup_menu_->addAction(set_owner_trust_of_key_act_);
+ popup_menu_->addSeparator();
+ popup_menu_->addAction(show_key_details_act_);
+
+ connect(key_list_, &KeyList::SignalRequestContextMenu, this,
+ &KeyMgmt::slot_popup_menu_by_key_list);
connect(this, &KeyMgmt::SignalKeyStatusUpdated,
UISignalStation::GetInstance(),
@@ -292,7 +297,7 @@ void KeyMgmt::create_tool_bars() {
QToolBar* key_tool_bar = addToolBar(tr("Key"));
key_tool_bar->setObjectName("keytoolbar");
- // genrate key pair
+ // generate key pair
key_tool_bar->addAction(generate_key_pair_act_);
key_tool_bar->addSeparator();
@@ -587,13 +592,36 @@ void KeyMgmt::SlotImportKeyPackage() {
emit SignalStatusBarChanged(tr("key(s) imported"));
emit SignalKeyStatusUpdated();
- auto* dialog = new KeyImportDetailDialog(
- key_list_->GetCurrentGpgContextChannel(),
- SecureCreateSharedObject<GpgImportInformation>(info), this);
- dialog->exec();
+ auto* connection = new QMetaObject::Connection;
+ *connection = connect(
+ UISignalStation::GetInstance(),
+ &UISignalStation::SignalKeyDatabaseRefreshDone, this,
+ [=]() {
+ (new KeyImportDetailDialog(
+ key_list_->GetCurrentGpgContextChannel(),
+ SecureCreateSharedObject<GpgImportInformation>(info),
+ this));
+ QObject::disconnect(*connection);
+ delete connection;
+ });
}
});
});
}
+void KeyMgmt::slot_popup_menu_by_key_list(QContextMenuEvent* event,
+ KeyTable* key_table) {
+ if (event == nullptr || key_table == nullptr) return;
+
+ auto keys = key_table->GetSelectedKeys();
+ if (keys.isEmpty()) return;
+
+ auto key = keys.front();
+ generate_subkey_act_->setDisabled(key->KeyType() !=
+ GpgAbstractKeyType::kGPG_KEY);
+ set_owner_trust_of_key_act_->setDisabled(key->KeyType() !=
+ GpgAbstractKeyType::kGPG_KEY);
+
+ popup_menu_->exec(event->globalPos());
+}
} // namespace GpgFrontend::UI
diff --git a/src/ui/main_window/KeyMgmt.h b/src/ui/main_window/KeyMgmt.h
index b25cfaaa..c0a8502a 100644
--- a/src/ui/main_window/KeyMgmt.h
+++ b/src/ui/main_window/KeyMgmt.h
@@ -34,6 +34,7 @@
namespace GpgFrontend::UI {
class KeyList;
+struct KeyTable;
/**
* @brief
@@ -120,6 +121,10 @@ class KeyMgmt : public GeneralMainWindow {
*/
void SignalKeyStatusUpdated();
+ private slots:
+
+ void slot_popup_menu_by_key_list(QContextMenuEvent* event, KeyTable*);
+
private:
KeyList* key_list_; ///<
QMenu* file_menu_{}; ///<
@@ -128,6 +133,8 @@ class KeyMgmt : public GeneralMainWindow {
QMenu* import_key_menu_{}; ///<
QMenu* export_key_menu_{}; /// <
+ QMenu* popup_menu_;
+
QAction* open_key_file_act_{}; ///<
QAction* export_key_to_file_act_{}; ///<
QAction* export_key_as_open_ssh_format_{}; ///<
@@ -143,7 +150,7 @@ class KeyMgmt : public GeneralMainWindow {
QAction* import_keys_from_key_package_act_{}; ///<
QAction* close_act_{}; ///<
QAction* show_key_details_act_{}; ///<
- QAction* set_owner_trust_of_key_act_{};
+ QAction* set_owner_trust_of_key_act_{}; ///<
/**
* @brief Create a menus object
diff --git a/src/ui/main_window/MainWindow.cpp b/src/ui/main_window/MainWindow.cpp
index 5ebfbb00..e17dacca 100644
--- a/src/ui/main_window/MainWindow.cpp
+++ b/src/ui/main_window/MainWindow.cpp
@@ -105,27 +105,36 @@ void MainWindow::Init() noexcept {
[=](const QString& message, int timeout) {
statusBar()->showMessage(message, timeout);
});
- connect(UISignalStation::GetInstance(),
- &UISignalStation::SignalMainWindowUpdateBasicOperaMenu, this,
- &MainWindow::SlotUpdateCryptoMenuStatus);
+ connect(
+ UISignalStation::GetInstance(),
+ &UISignalStation::SignalMainWindowUpdateBasicOperaMenu, this,
+ [=](unsigned int mask) {
+ operations_menu_mask_ = mask;
+ slot_update_operations_menu_by_checked_keys(operations_menu_mask_);
+ });
connect(UISignalStation::GetInstance(),
&UISignalStation::SignalMainWindowOpenFile, this,
&MainWindow::SlotOpenFile);
- m_key_list_->AddMenuAction(append_selected_keys_act_);
- m_key_list_->AddMenuAction(append_key_create_date_to_editor_act_);
- m_key_list_->AddMenuAction(append_key_expire_date_to_editor_act_);
- m_key_list_->AddMenuAction(append_key_fingerprint_to_editor_act_);
- m_key_list_->AddSeparator();
- m_key_list_->AddMenuAction(copy_mail_address_to_clipboard_act_);
- m_key_list_->AddMenuAction(copy_key_default_uid_to_clipboard_act_);
- m_key_list_->AddMenuAction(copy_key_id_to_clipboard_act_);
- m_key_list_->AddMenuAction(set_owner_trust_of_key_act_);
- m_key_list_->AddMenuAction(add_key_2_favourite_act_);
- m_key_list_->AddMenuAction(remove_key_from_favourtie_act_);
-
- m_key_list_->AddSeparator();
- m_key_list_->AddMenuAction(show_key_details_act_);
+ popup_menu_ = new QMenu(this);
+
+ popup_menu_->addAction(append_selected_keys_act_);
+ popup_menu_->addAction(append_key_create_date_to_editor_act_);
+ popup_menu_->addAction(append_key_expire_date_to_editor_act_);
+ popup_menu_->addAction(append_key_fingerprint_to_editor_act_);
+ popup_menu_->addSeparator();
+ popup_menu_->addAction(copy_mail_address_to_clipboard_act_);
+ popup_menu_->addAction(copy_key_default_uid_to_clipboard_act_);
+ popup_menu_->addAction(copy_key_id_to_clipboard_act_);
+ popup_menu_->addAction(set_owner_trust_of_key_act_);
+ popup_menu_->addAction(add_key_2_favourite_act_);
+ popup_menu_->addAction(remove_key_from_favourtie_act_);
+
+ popup_menu_->addSeparator();
+ popup_menu_->addAction(show_key_details_act_);
+
+ connect(m_key_list_, &KeyList::SignalRequestContextMenu, this,
+ &MainWindow::slot_popup_menu_by_key_list);
restore_settings();
@@ -139,7 +148,7 @@ 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();
+ slot_update_operations_menu_by_checked_keys(~0);
// check if need to open wizard window
if (GetSettings().value("wizard/show_wizard", true).toBool()) {
@@ -307,4 +316,20 @@ void MainWindow::check_update_at_startup() {
Module::TriggerEvent("CHECK_APPLICATION_VERSION");
}
}
+
+void MainWindow::slot_popup_menu_by_key_list(QContextMenuEvent* event,
+ KeyTable* key_table) {
+ if (event == nullptr || key_table == nullptr) return;
+
+ const auto key_table_name = key_table->objectName();
+ if (key_table_name == "favourite") {
+ remove_key_from_favourtie_act_->setDisabled(true);
+ add_key_2_favourite_act_->setDisabled(false);
+ } else {
+ remove_key_from_favourtie_act_->setDisabled(false);
+ add_key_2_favourite_act_->setDisabled(true);
+ }
+
+ popup_menu_->popup(event->globalPos());
+}
} // namespace GpgFrontend::UI
diff --git a/src/ui/main_window/MainWindow.h b/src/ui/main_window/MainWindow.h
index 6eb4da65..d89356aa 100644
--- a/src/ui/main_window/MainWindow.h
+++ b/src/ui/main_window/MainWindow.h
@@ -46,6 +46,7 @@ class TextEdit;
class InfoBoardWidget;
struct GpgOperaContext;
struct GpgOperaContextBasement;
+struct KeyTable;
/**
* @brief
@@ -121,11 +122,6 @@ class MainWindow : public GeneralMainWindow {
public slots:
/**
- * @details refresh and enable specify crypto-menu actions.
- */
- void SlotUpdateCryptoMenuStatus(unsigned int type);
-
- /**
* @details Open a new tab for path
*/
void SlotOpenFile(const QString& path);
@@ -523,11 +519,23 @@ class MainWindow : public GeneralMainWindow {
const QContainer<GpgOperaResult>& results);
/**
+ * @details refresh and enable specify crypto-menu actions.
+ */
+ void slot_update_crypto_operations_menu(unsigned int mask);
+
+ /**
* @brief
*
* @param results
*/
- void slot_update_operations_menu_by_checked_keys();
+ void slot_update_operations_menu_by_checked_keys(unsigned int type);
+
+ /**
+ * @brief
+ *
+ * @param event
+ */
+ void slot_popup_menu_by_key_list(QContextMenuEvent* event, KeyTable*);
private:
/**
@@ -771,9 +779,12 @@ class MainWindow : public GeneralMainWindow {
InfoBoardWidget* info_board_{}; ///<
QMap<QString, QPointer<QAction>> buffered_actions_;
+ QMenu* popup_menu_;
+
bool attachment_dock_created_{}; ///<
int restart_mode_{0}; ///<
bool prohibit_update_checking_ = false; ///<
+ unsigned int operations_menu_mask_ = ~0;
};
} // namespace GpgFrontend::UI
diff --git a/src/ui/main_window/MainWindowSlotUI.cpp b/src/ui/main_window/MainWindowSlotUI.cpp
index 51de7d23..49958c9f 100644
--- a/src/ui/main_window/MainWindowSlotUI.cpp
+++ b/src/ui/main_window/MainWindowSlotUI.cpp
@@ -167,8 +167,8 @@ void MainWindow::slot_cut_pgp_header() {
void MainWindow::SlotSetRestartNeeded(int mode) { this->restart_mode_ = mode; }
-void MainWindow::SlotUpdateCryptoMenuStatus(unsigned int type) {
- OperationMenu::OperationType opera_type = type;
+void MainWindow::slot_update_crypto_operations_menu(unsigned int mask) {
+ OperationMenu::OperationType opera_type = mask;
// refresh status to disable all
verify_act_->setDisabled(true);
@@ -346,13 +346,14 @@ void MainWindow::slot_restart_gpg_components(bool) {
});
}
-void MainWindow::slot_update_operations_menu_by_checked_keys() {
+void MainWindow::slot_update_operations_menu_by_checked_keys(
+ unsigned int mask) {
auto keys = m_key_list_->GetCheckedKeys();
- OperationMenu::OperationType type = ~0;
+ unsigned int temp = ~0;
if (keys.isEmpty()) {
- type &= ~(OperationMenu::kEncrypt | OperationMenu::kEncryptAndSign |
+ temp &= ~(OperationMenu::kEncrypt | OperationMenu::kEncryptAndSign |
OperationMenu::kSign);
} else {
@@ -360,15 +361,15 @@ void MainWindow::slot_update_operations_menu_by_checked_keys() {
if (key == nullptr || key->IsDisabled()) continue;
if (!key->IsHasEncrCap()) {
- type &= ~(OperationMenu::kEncrypt | OperationMenu::kEncryptAndSign);
+ temp &= ~(OperationMenu::kEncrypt | OperationMenu::kEncryptAndSign);
}
if (!key->IsHasSignCap()) {
- type &= ~(OperationMenu::kSign);
+ temp &= ~(OperationMenu::kSign);
}
}
}
- SlotUpdateCryptoMenuStatus(type);
+ slot_update_crypto_operations_menu(operations_menu_mask_ & mask & temp);
}
} // namespace GpgFrontend::UI
diff --git a/src/ui/main_window/MainWindowUI.cpp b/src/ui/main_window/MainWindowUI.cpp
index 26c3a8ad..41463b7a 100644
--- a/src/ui/main_window/MainWindowUI.cpp
+++ b/src/ui/main_window/MainWindowUI.cpp
@@ -611,7 +611,7 @@ void MainWindow::create_dock_windows() {
view_menu_->addAction(info_board_dock_->toggleViewAction());
connect(m_key_list_, &KeyList::SignalKeyChecked, this,
- &MainWindow::slot_update_operations_menu_by_checked_keys);
+ [=]() { slot_update_operations_menu_by_checked_keys(~0); });
}
} // namespace GpgFrontend::UI
diff --git a/src/ui/widgets/KeyList.cpp b/src/ui/widgets/KeyList.cpp
index 53adb316..dfabe885 100644
--- a/src/ui/widgets/KeyList.cpp
+++ b/src/ui/widgets/KeyList.cpp
@@ -222,7 +222,6 @@ void KeyList::init() {
ui_->columnTypeButton->setMenu(column_type_menu);
ui_->keyGroupTab->clear();
- popup_menu_ = new QMenu(this);
auto forbid_all_gnupg_connection =
GetSettings()
@@ -409,37 +408,11 @@ void KeyList::contextMenuEvent(QContextMenuEvent* event) {
return;
}
- QString current_tab_widget_obj_name =
- ui_->keyGroupTab->widget(ui_->keyGroupTab->currentIndex())->objectName();
- if (current_tab_widget_obj_name == "favourite") {
- auto actions = popup_menu_->actions();
- for (QAction* action : actions) {
- if (action->data().toString() == "remove_key_from_favourtie_action") {
- action->setVisible(true);
- } else if (action->data().toString() == "add_key_2_favourite_action") {
- action->setVisible(false);
- }
- }
- } else {
- auto actions = popup_menu_->actions();
- for (QAction* action : actions) {
- if (action->data().toString() == "remove_key_from_favourtie_action") {
- action->setVisible(false);
- } else if (action->data().toString() == "add_key_2_favourite_action") {
- action->setVisible(true);
- }
- }
- }
-
if (key_table->GetRowSelected() >= 0) {
- popup_menu_->exec(event->globalPos());
+ emit SignalRequestContextMenu(event, key_table);
}
}
-void KeyList::AddSeparator() { popup_menu_->addSeparator(); }
-
-void KeyList::AddMenuAction(QAction* act) { popup_menu_->addAction(act); }
-
void KeyList::dropEvent(QDropEvent* event) {
auto* dialog = new QDialog();
@@ -501,9 +474,17 @@ void KeyList::import_keys(const QByteArray& in_buffer) {
LOG_D() << "importing keys to channel:" << current_gpg_context_channel_;
auto result = GpgKeyImportExporter::GetInstance(current_gpg_context_channel_)
.ImportKey(GFBuffer(in_buffer));
- emit SignalRefreshDatabase();
- (new KeyImportDetailDialog(current_gpg_context_channel_, result, this));
+ auto* connection = new QMetaObject::Connection;
+ *connection = connect(
+ UISignalStation::GetInstance(),
+ &UISignalStation::SignalKeyDatabaseRefreshDone, this, [=]() {
+ new KeyImportDetailDialog(current_gpg_context_channel_, result, this);
+ QObject::disconnect(*connection);
+ delete connection;
+ });
+
+ emit SignalRefreshDatabase();
}
auto KeyList::GetSelectedKey() -> GpgAbstractKeyPtr {
@@ -529,10 +510,8 @@ auto KeyList::GetSelectedGpgKeys() -> GpgKeyPtrList {
}
void KeyList::slot_sync_with_key_server() {
- auto target_keys = GetCheckedPublicKey();
-
- KeyIdArgsList key_ids;
- if (target_keys.empty()) {
+ auto keys = GetCheckedPublicKey();
+ if (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 "
@@ -542,32 +521,25 @@ void KeyList::slot_sync_with_key_server() {
if (reply == QMessageBox::No) return;
- target_keys = model_->GetAllKeys();
- }
-
- for (auto& key : target_keys) {
- if (key->KeyType() != GpgAbstractKeyType::kGPG_KEY) continue;
- key_ids.push_back(key->ID());
+ keys = model_->GetAllKeys();
}
+ auto key_ids = ConvertKey2GpgKeyIdList(current_gpg_context_channel_, keys);
if (key_ids.empty()) return;
ui_->refreshKeyListButton->setDisabled(true);
ui_->syncButton->setDisabled(true);
emit SignalRefreshStatusBar(tr("Syncing Key List..."), 3000);
+
CommonUtils::SlotImportKeyFromKeyServer(
current_gpg_context_channel_, key_ids,
[=](const QString& key_id, const QString& status, size_t current_index,
size_t all_index) {
- auto key = GpgKeyGetter::GetInstance(current_gpg_context_channel_)
- .GetKey(key_id);
- assert(key.IsGood());
-
auto status_str = tr("Sync [%1/%2] %3 %4")
.arg(current_index)
.arg(all_index)
- .arg(key.UIDs().front().GetUID())
+ .arg(key_id)
.arg(status);
emit SignalRefreshStatusBar(status_str, 1500);
diff --git a/src/ui/widgets/KeyList.h b/src/ui/widgets/KeyList.h
index 0b0b9be6..bb48c63b 100644
--- a/src/ui/widgets/KeyList.h
+++ b/src/ui/widgets/KeyList.h
@@ -135,19 +135,6 @@ class KeyList : public QWidget {
void SetColumnWidth(int row, int size);
/**
- * @brief
- *
- * @param act
- */
- void AddMenuAction(QAction* act);
-
- /**
- * @brief
- *
- */
- void AddSeparator();
-
- /**
* @brief Get the Checked Keys object
*
* @return QStringList
@@ -288,6 +275,12 @@ class KeyList : public QWidget {
*/
void SignalKeyChecked();
+ /**
+ * @brief
+ *
+ */
+ void SignalRequestContextMenu(QContextMenuEvent* event, KeyTable*);
+
protected:
/**
* @brief
@@ -326,7 +319,6 @@ class KeyList : public QWidget {
private:
std::shared_ptr<Ui_KeyList> ui_; ///<
- QMenu* popup_menu_{}; ///<
std::function<void(const GpgKey&, QWidget*)> m_action_ = nullptr; ///<
int current_gpg_context_channel_;
KeyMenuAbility menu_ability_ = KeyMenuAbility::kALL; ///<
diff --git a/src/ui/widgets/KeyTreeView.cpp b/src/ui/widgets/KeyTreeView.cpp
index 46cfa2db..a6fb23bf 100644
--- a/src/ui/widgets/KeyTreeView.cpp
+++ b/src/ui/widgets/KeyTreeView.cpp
@@ -28,9 +28,7 @@
#include "ui/widgets/KeyTreeView.h"
-#include <utility>
-
-#include "core/function/gpg/GpgKeyGetter.h"
+#include "core/function/gpg/GpgAbstractKeyGetter.h"
#include "ui/UISignalStation.h"
#include "ui/UserInterfaceUtils.h"
#include "ui/model/GpgKeyTreeProxyModel.h"
@@ -41,7 +39,7 @@ KeyTreeView::KeyTreeView(QWidget* parent)
: QTreeView(parent),
channel_(kGpgFrontendDefaultChannel),
model_(QSharedPointer<GpgKeyTreeModel>::create(
- channel_, GpgKeyGetter::GetInstance(channel_).FetchKey(),
+ channel_, GpgAbstractKeyGetter::GetInstance(channel_).Fetch(),
[](auto) { return false; }, this)),
proxy_model_(
model_, GpgKeyTreeDisplayMode::kALL, [](auto) { return false; },
@@ -56,7 +54,7 @@ KeyTreeView::KeyTreeView(int channel,
: QTreeView(parent),
channel_(channel),
model_(QSharedPointer<GpgKeyTreeModel>::create(
- channel_, GpgKeyGetter::GetInstance(channel_).FetchKey(),
+ channel_, GpgAbstractKeyGetter::GetInstance(channel_).Fetch(),
checkable_detector, this)),
proxy_model_(model_, GpgKeyTreeDisplayMode::kALL, std::move(filter),
this) {
@@ -120,7 +118,7 @@ void KeyTreeView::init() {
connect(UISignalStation::GetInstance(),
&UISignalStation::SignalKeyDatabaseRefresh, this, [=] {
model_ = QSharedPointer<GpgKeyTreeModel>::create(
- channel_, GpgKeyGetter::GetInstance(channel_).FetchKey(),
+ channel_, GpgAbstractKeyGetter::GetInstance(channel_).Fetch(),
[](auto) { return false; }, this);
proxy_model_.setSourceModel(model_.get());
proxy_model_.invalidate();
@@ -138,7 +136,7 @@ void KeyTreeView::SetChannel(int channel) {
channel_ = channel;
init_ = false;
model_ = QSharedPointer<GpgKeyTreeModel>::create(
- channel_, GpgKeyGetter::GetInstance(channel_).FetchKey(),
+ channel_, GpgAbstractKeyGetter::GetInstance(channel_).Fetch(),
[](auto) { return false; }, this);
proxy_model_.setSourceModel(model_.get());
proxy_model_.invalidate();