From 2027237de006cb9fa40a73365cbbc8911572969c Mon Sep 17 00:00:00 2001 From: saturneric Date: Wed, 16 Apr 2025 02:53:22 +0200 Subject: fix: found bugs --- modules | 2 +- src/core/function/gpg/GpgKeyOpera.cpp | 5 +- src/ui/GpgFrontendUIInit.cpp | 34 ++++----- src/ui/UserInterfaceUtils.cpp | 1 - src/ui/dialog/ADSKsPicker.cpp | 11 +-- src/ui/dialog/ADSKsPicker.h | 14 +--- src/ui/dialog/KeyGroupManageDialog.cpp | 3 + src/ui/dialog/controller/GnuPGControllerDialog.cpp | 1 - .../dialog/import_export/KeyServerImportDialog.cpp | 1 - src/ui/dialog/keypair_details/KeyNewUIDDialog.cpp | 4 +- src/ui/dialog/keypair_details/KeyPairSubkeyTab.cpp | 85 ++++++++++------------ src/ui/dialog/keypair_details/KeyPairUIDTab.cpp | 2 - src/ui/dialog/settings/SettingsDialog.cpp | 1 - src/ui/dialog/settings/SettingsKeyServer.cpp | 6 +- src/ui/dialog/settings/SettingsNetwork.cpp | 6 +- src/ui/function/GpgOperaHelper.cpp | 2 - src/ui/widgets/KeyList.cpp | 8 +- 17 files changed, 81 insertions(+), 105 deletions(-) diff --git a/modules b/modules index 6b0ca127..c2d072e6 160000 --- a/modules +++ b/modules @@ -1 +1 @@ -Subproject commit 6b0ca127c868e0c132dd79c59ea038b60b722e33 +Subproject commit c2d072e60a83ec2ce17fb4e3168b99b001bb5ae9 diff --git a/src/core/function/gpg/GpgKeyOpera.cpp b/src/core/function/gpg/GpgKeyOpera.cpp index 3e4fe6d4..e97eebd8 100644 --- a/src/core/function/gpg/GpgKeyOpera.cpp +++ b/src/core/function/gpg/GpgKeyOpera.cpp @@ -121,8 +121,9 @@ void GpgKeyOpera::GenerateRevokeCert(const GpgKeyPtr& key, // get all components GpgCommandExecutor::ExecuteSync( {app_path, - QStringList{"--command-fd", "0", "--status-fd", "1", "--no-tty", "-o", - output_path, "--gen-revoke", key->Fingerprint()}, + QStringList{"--homedir", ctx_.HomeDirectory(), "--command-fd", "0", + "--status-fd", "1", "--no-tty", "-o", output_path, + "--gen-revoke", key->Fingerprint()}, [=](int exit_code, const QString& p_out, const QString& p_err) { if (exit_code != 0) { LOG_W() << "gnupg gen revoke execute error, process stderr: " diff --git a/src/ui/GpgFrontendUIInit.cpp b/src/ui/GpgFrontendUIInit.cpp index ed9584b9..1ee59d12 100644 --- a/src/ui/GpgFrontendUIInit.cpp +++ b/src/ui/GpgFrontendUIInit.cpp @@ -51,9 +51,9 @@ void WaitEnvCheckingProcess() { FLOG_D("need to wait for env checking process"); // create and show loading window before starting the main window - auto* waiting_dialog = new QProgressDialog(); - waiting_dialog->setMaximum(0); - waiting_dialog->setMinimum(0); + auto* progress_dialog = new QProgressDialog(); + progress_dialog->setMaximum(0); + progress_dialog->setMinimum(0); auto* waiting_dialog_label = new QLabel( QCoreApplication::tr("Loading Gnupg Info...") + "

" + QCoreApplication::tr( @@ -62,22 +62,22 @@ void WaitEnvCheckingProcess() { "file (depending " "on the network situation in your country or region).")); waiting_dialog_label->setWordWrap(true); - waiting_dialog->setLabel(waiting_dialog_label); - waiting_dialog->resize(420, 120); + progress_dialog->setLabel(waiting_dialog_label); + progress_dialog->resize(420, 120); QApplication::connect(CoreSignalStation::GetInstance(), &CoreSignalStation::SignalCoreFullyLoaded, - waiting_dialog, [=]() { + progress_dialog, [=]() { LOG_D() << "ui caught signal: core fully loaded"; - waiting_dialog->finished(0); - waiting_dialog->deleteLater(); + progress_dialog->finished(0); + progress_dialog->deleteLater(); }); QApplication::connect(CoreSignalStation::GetInstance(), - &CoreSignalStation::SignalBadGnupgEnv, waiting_dialog, + &CoreSignalStation::SignalBadGnupgEnv, progress_dialog, [=]() { LOG_D() << "ui caught signal: core loading failed"; - waiting_dialog->finished(0); - waiting_dialog->deleteLater(); + progress_dialog->finished(0); + progress_dialog->deleteLater(); }); // new local event looper @@ -86,7 +86,7 @@ void WaitEnvCheckingProcess() { &CoreSignalStation::SignalCoreFullyLoaded, &looper, &QEventLoop::quit); - QApplication::connect(waiting_dialog, &QProgressDialog::canceled, [=]() { + QApplication::connect(progress_dialog, &QProgressDialog::canceled, [=]() { FLOG_D("cancel clicked on waiting dialog"); QApplication::quit(); exit(0); @@ -99,15 +99,15 @@ void WaitEnvCheckingProcess() { // check twice to avoid some unlucky sitations if (env_state == 1) { FLOG_D("env state turned initialized before the looper start"); - waiting_dialog->finished(0); - waiting_dialog->deleteLater(); + progress_dialog->finished(0); + progress_dialog->deleteLater(); return; } // show the loading window - waiting_dialog->setModal(true); - waiting_dialog->setFocus(); - waiting_dialog->show(); + progress_dialog->setModal(true); + progress_dialog->setFocus(); + progress_dialog->show(); // block the main thread until the gpg context is loaded looper.exec(); diff --git a/src/ui/UserInterfaceUtils.cpp b/src/ui/UserInterfaceUtils.cpp index ea5893c1..e66a775c 100644 --- a/src/ui/UserInterfaceUtils.cpp +++ b/src/ui/UserInterfaceUtils.cpp @@ -307,7 +307,6 @@ void CommonUtils::SlotExecuteGpgCommand( gpg_process->start(); looper.exec(); dialog->close(); - dialog->deleteLater(); } void CommonUtils::SlotImportKeyFromKeyServer( diff --git a/src/ui/dialog/ADSKsPicker.cpp b/src/ui/dialog/ADSKsPicker.cpp index a8afb9bf..9d9fa4c3 100644 --- a/src/ui/dialog/ADSKsPicker.cpp +++ b/src/ui/dialog/ADSKsPicker.cpp @@ -51,8 +51,9 @@ ADSKsPicker::ADSKsPicker(int channel, auto* confirm_button = new QPushButton(tr("Confirm")); auto* cancel_button = new QPushButton(tr("Cancel")); - connect(confirm_button, &QPushButton::clicked, - [=]() { this->accepted_ = true; }); + connect(confirm_button, &QPushButton::clicked, this, [=]() { + emit SignalSubkeyChecked(tree_view_->GetAllCheckedSubKey()); + }); connect(confirm_button, &QPushButton::clicked, this, &QDialog::accept); connect(cancel_button, &QPushButton::clicked, this, &QDialog::reject); @@ -87,10 +88,4 @@ ADSKsPicker::ADSKsPicker(int channel, this->activateWindow(); } -auto ADSKsPicker::GetCheckedSubkeys() -> QContainer { - return tree_view_->GetAllCheckedSubKey(); -} - -auto ADSKsPicker::GetStatus() const -> bool { return this->accepted_; } - } // namespace GpgFrontend::UI diff --git a/src/ui/dialog/ADSKsPicker.h b/src/ui/dialog/ADSKsPicker.h index e5c08c9c..59c7b06b 100644 --- a/src/ui/dialog/ADSKsPicker.h +++ b/src/ui/dialog/ADSKsPicker.h @@ -54,18 +54,8 @@ class ADSKsPicker : public GeneralDialog { const GpgKeyTreeProxyModel::KeyFilter& filter, QWidget* parent = nullptr); - /** - * @brief Get the Checked Signers object - * - * @return GpgFrontend::KeyIdArgsListPtr - */ - auto GetCheckedSubkeys() -> QContainer; - - /** - * - * @return - */ - [[nodiscard]] auto GetStatus() const -> bool; + signals: + void SignalSubkeyChecked(QContainer); private: KeyTreeView* tree_view_; ///< diff --git a/src/ui/dialog/KeyGroupManageDialog.cpp b/src/ui/dialog/KeyGroupManageDialog.cpp index 1a994585..cbd70b61 100644 --- a/src/ui/dialog/KeyGroupManageDialog.cpp +++ b/src/ui/dialog/KeyGroupManageDialog.cpp @@ -29,6 +29,7 @@ #include "KeyGroupManageDialog.h" #include "core/function/gpg/GpgAbstractKeyGetter.h" +#include "ui/UISignalStation.h" #include "ui/widgets/KeyList.h" // @@ -159,5 +160,7 @@ void KeyGroupManageDialog::slot_notify_invalid_key_ids() { getter.RemoveKeyFromKeyGroup(key_group_->ID(), key_id); } } + + emit UISignalStation::GetInstance() -> SignalKeyDatabaseRefresh(); } } // namespace GpgFrontend::UI diff --git a/src/ui/dialog/controller/GnuPGControllerDialog.cpp b/src/ui/dialog/controller/GnuPGControllerDialog.cpp index e68e208a..0ad1a6ca 100644 --- a/src/ui/dialog/controller/GnuPGControllerDialog.cpp +++ b/src/ui/dialog/controller/GnuPGControllerDialog.cpp @@ -173,7 +173,6 @@ GnuPGControllerDialog::GnuPGControllerDialog(QWidget* parent) ui_->buttonBox->setHidden(true); connect(this, &QDialog::finished, this, &GnuPGControllerDialog::SlotAccept); - connect(this, &QDialog::finished, this, &GnuPGControllerDialog::deleteLater); #else connect(ui_->buttonBox, &QDialogButtonBox::accepted, this, &GnuPGControllerDialog::SlotAccept); diff --git a/src/ui/dialog/import_export/KeyServerImportDialog.cpp b/src/ui/dialog/import_export/KeyServerImportDialog.cpp index e3c66245..03ee6c4a 100644 --- a/src/ui/dialog/import_export/KeyServerImportDialog.cpp +++ b/src/ui/dialog/import_export/KeyServerImportDialog.cpp @@ -49,7 +49,6 @@ KeyServerImportDialog::KeyServerImportDialog(int channel, QWidget* parent) if (forbid_all_gnupg_connection) { QMessageBox::critical(this, "Forbidden", "GnuPG is in offline mode now."); this->close(); - this->deleteLater(); } // Buttons diff --git a/src/ui/dialog/keypair_details/KeyNewUIDDialog.cpp b/src/ui/dialog/keypair_details/KeyNewUIDDialog.cpp index d641c4d3..d05154d5 100644 --- a/src/ui/dialog/keypair_details/KeyNewUIDDialog.cpp +++ b/src/ui/dialog/keypair_details/KeyNewUIDDialog.cpp @@ -75,6 +75,8 @@ KeyNewUIDDialog::KeyNewUIDDialog(int channel, GpgKeyPtr key, QWidget* parent) connect(this, &KeyNewUIDDialog::SignalUIDCreated, UISignalStation::GetInstance(), &UISignalStation::SignalKeyDatabaseRefresh); + connect(this, &KeyNewUIDDialog::SignalUIDCreated, this, + &KeyNewUIDDialog::close); } void KeyNewUIDDialog::slot_create_new_uid() { @@ -117,7 +119,7 @@ void KeyNewUIDDialog::slot_create_new_uid() { } } -bool KeyNewUIDDialog::check_email_address(const QString& str) { +auto KeyNewUIDDialog::check_email_address(const QString& str) -> bool { return re_email_.match(str).hasMatch(); } } // namespace GpgFrontend::UI diff --git a/src/ui/dialog/keypair_details/KeyPairSubkeyTab.cpp b/src/ui/dialog/keypair_details/KeyPairSubkeyTab.cpp index 011ea1ed..fa0c5c34 100644 --- a/src/ui/dialog/keypair_details/KeyPairSubkeyTab.cpp +++ b/src/ui/dialog/keypair_details/KeyPairSubkeyTab.cpp @@ -297,58 +297,51 @@ void KeyPairSubkeyTab::slot_add_adsk() { return !except_key_ids.contains(key->ID()); }, this); - dialog->exec(); - if (!dialog->GetStatus()) { - dialog->deleteLater(); - return; - } - - auto sub_keys = dialog->GetCheckedSubkeys(); - dialog->deleteLater(); - - if (sub_keys.isEmpty()) { - QMessageBox::information(this, tr("No Subkeys Selected"), - tr("Please select at least one s_key.")); - return; - } + connect(dialog, &ADSKsPicker::SignalSubkeyChecked, this, + [=](const QContainer& s_keys) { + if (s_keys.isEmpty()) { + QMessageBox::information(this, tr("No Subkeys Selected"), + tr("Please select at least one s_key.")); - QContainer err_sub_keys; - for (const auto& sub_key : sub_keys) { - auto [err, data_object] = - GpgKeyOpera::GetInstance(current_gpg_context_channel_) - .AddADSKSync(key_, sub_key); - if (CheckGpgError(err) == GPG_ERR_NO_ERROR) continue; + return; + } - err_sub_keys.append(sub_key); - } + QContainer 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; - if (err_sub_keys.isEmpty()) { - QMessageBox::information( - this, tr("Success"), - tr("All selected subkeys were successfully added as ADSKs.")); - } else { - 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); - } + err_sub_keys.append(s_key); + } - QString details = failed_info.join("\n\n"); - - QMessageBox msg_box(this); - msg_box.setIcon(QMessageBox::Warning); - msg_box.setWindowTitle(err_sub_keys.size() == sub_keys.size() - ? tr("Failed") - : tr("Partially Failed")); - msg_box.setText(err_sub_keys.size() == sub_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(); - } + 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(); + 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 73428f39..e720b9b0 100644 --- a/src/ui/dialog/keypair_details/KeyPairUIDTab.cpp +++ b/src/ui/dialog/keypair_details/KeyPairUIDTab.cpp @@ -318,8 +318,6 @@ void KeyPairUIDTab::slot_add_uid() { 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, - &KeyPairUIDTab::deleteLater); key_new_uid_dialog->show(); } diff --git a/src/ui/dialog/settings/SettingsDialog.cpp b/src/ui/dialog/settings/SettingsDialog.cpp index 87868eb4..79910229 100644 --- a/src/ui/dialog/settings/SettingsDialog.cpp +++ b/src/ui/dialog/settings/SettingsDialog.cpp @@ -57,7 +57,6 @@ SettingsDialog::SettingsDialog(QWidget* parent) #if defined(__APPLE__) && defined(__MACH__) connect(this, &QDialog::finished, this, &SettingsDialog::SlotAccept); - connect(this, &QDialog::finished, this, &SettingsDialog::deleteLater); setWindowTitle(tr("Preference")); #else button_box_ = diff --git a/src/ui/dialog/settings/SettingsKeyServer.cpp b/src/ui/dialog/settings/SettingsKeyServer.cpp index e73363d6..c35900cc 100644 --- a/src/ui/dialog/settings/SettingsKeyServer.cpp +++ b/src/ui/dialog/settings/SettingsKeyServer.cpp @@ -264,10 +264,8 @@ void KeyserverTab::slot_test_listed_key_server() { waiting_dialog->setLabel(waiting_dialog_label); waiting_dialog->resize(420, 120); waiting_dialog->setModal(true); - connect(task, &Thread::Task::SignalTaskEnd, [=]() { - waiting_dialog->close(); - waiting_dialog->deleteLater(); - }); + connect(task, &Thread::Task::SignalTaskEnd, + [=]() { waiting_dialog->close(); }); // Show Waiting Dialog waiting_dialog->show(); waiting_dialog->setFocus(); diff --git a/src/ui/dialog/settings/SettingsNetwork.cpp b/src/ui/dialog/settings/SettingsNetwork.cpp index 66f3abb1..efbf4ec5 100644 --- a/src/ui/dialog/settings/SettingsNetwork.cpp +++ b/src/ui/dialog/settings/SettingsNetwork.cpp @@ -203,10 +203,8 @@ void GpgFrontend::UI::NetworkTab::slot_test_proxy_connection_result() { waiting_dialog_label->setWordWrap(true); waiting_dialog->setLabel(waiting_dialog_label); waiting_dialog->resize(420, 120); - connect(task, &Thread::Task::SignalTaskEnd, [=]() { - waiting_dialog->close(); - waiting_dialog->deleteLater(); - }); + connect(task, &Thread::Task::SignalTaskEnd, + [=]() { waiting_dialog->close(); }); // Show Waiting Dialog waiting_dialog->show(); diff --git a/src/ui/function/GpgOperaHelper.cpp b/src/ui/function/GpgOperaHelper.cpp index 4bcd9960..50269b90 100644 --- a/src/ui/function/GpgOperaHelper.cpp +++ b/src/ui/function/GpgOperaHelper.cpp @@ -435,7 +435,6 @@ void GpgOperaHelper::WaitForMultipleOperas( QPointer const dialog = new WaitingDialog(title, operas.size() > 1, parent); connect(dialog, &QDialog::finished, &looper, &QEventLoop::quit); - connect(dialog, &QDialog::finished, dialog, &QDialog::deleteLater); dialog->show(); std::atomic remaining_tasks(static_cast(operas.size())); @@ -540,7 +539,6 @@ void GpgOperaHelper::WaitForOpera(QWidget* parent, const QString& title, QPointer const dialog = new WaitingDialog(title, false, parent); connect(dialog, &QDialog::finished, &looper, &QEventLoop::quit); - connect(dialog, &QDialog::finished, dialog, &QDialog::deleteLater); dialog->show(); QTimer::singleShot(64, parent, [=]() { diff --git a/src/ui/widgets/KeyList.cpp b/src/ui/widgets/KeyList.cpp index 429a5bd1..53adb316 100644 --- a/src/ui/widgets/KeyList.cpp +++ b/src/ui/widgets/KeyList.cpp @@ -507,11 +507,15 @@ void KeyList::import_keys(const QByteArray& in_buffer) { } auto KeyList::GetSelectedKey() -> GpgAbstractKeyPtr { - return GetSelectedKeys().front(); + auto k = GetSelectedKeys(); + if (k.empty()) return nullptr; + return k.front(); } auto KeyList::GetSelectedGpgKey() -> GpgKeyPtr { - return GetSelectedGpgKeys().front(); + auto k = GetSelectedGpgKeys(); + if (k.empty()) return nullptr; + return k.front(); } auto KeyList::GetSelectedGpgKeys() -> GpgKeyPtrList { -- cgit v1.2.3