diff options
author | saturneric <[email protected]> | 2025-04-18 17:56:51 +0000 |
---|---|---|
committer | saturneric <[email protected]> | 2025-04-18 17:56:51 +0000 |
commit | a7ea8e6de4bb205d2a3783d5cb9bde8bee0086b9 (patch) | |
tree | 54838273836a155033d33b246ec4a4200291825b /src/ui | |
parent | fix: issues found by testing (diff) | |
parent | fix: spelling mistake on project config by nightly build (diff) | |
download | GpgFrontend-a7ea8e6de4bb205d2a3783d5cb9bde8bee0086b9.tar.gz GpgFrontend-a7ea8e6de4bb205d2a3783d5cb9bde8bee0086b9.zip |
Merge branch 'develop'
Diffstat (limited to 'src/ui')
-rw-r--r-- | src/ui/UserInterfaceUtils.cpp | 20 | ||||
-rw-r--r-- | src/ui/UserInterfaceUtils.h | 10 | ||||
-rw-r--r-- | src/ui/dialog/ADSKsPicker.cpp | 3 | ||||
-rw-r--r-- | src/ui/dialog/controller/GnuPGControllerDialog.cpp | 3 | ||||
-rw-r--r-- | src/ui/dialog/controller/SmartCardControllerDialog.cpp | 73 | ||||
-rw-r--r-- | src/ui/dialog/key_generate/KeyGenerateDialog.cpp | 9 | ||||
-rw-r--r-- | src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp | 7 | ||||
-rw-r--r-- | src/ui/dialog/keypair_details/KeyPairSubkeyTab.cpp | 15 | ||||
-rw-r--r-- | src/ui/dialog/keypair_details/KeyPairSubkeyTab.h | 100 | ||||
-rw-r--r-- | src/ui/function/GpgOperaHelper.cpp | 22 | ||||
-rw-r--r-- | src/ui/main_window/KeyMgmt.cpp | 19 | ||||
-rw-r--r-- | src/ui/main_window/MainWindow.cpp | 22 | ||||
-rw-r--r-- | src/ui/main_window/MainWindow.h | 2 | ||||
-rw-r--r-- | src/ui/main_window/MainWindowSlotUI.cpp | 80 |
14 files changed, 239 insertions, 146 deletions
diff --git a/src/ui/UserInterfaceUtils.cpp b/src/ui/UserInterfaceUtils.cpp index 8d277ab4..dbc3f7e3 100644 --- a/src/ui/UserInterfaceUtils.cpp +++ b/src/ui/UserInterfaceUtils.cpp @@ -167,16 +167,24 @@ void CommonUtils::RaiseMessageBox(QWidget *parent, GpgError err) { } } -void CommonUtils::RaiseFailureMessageBox(QWidget *parent, GpgError err) { +void CommonUtils::RaiseMessageBoxNotSupported(QWidget *parent) { + QMessageBox::warning( + parent, tr("Operation Not Supported"), + tr("The current GnuPG version is too low and does not support this " + "operation. Please upgrade your GnuPG version to continue.")); +} + +void CommonUtils::RaiseFailureMessageBox(QWidget *parent, GpgError err, + const QString &msg) { GpgErrorDesc desc = DescribeGpgErrCode(err); GpgErrorCode err_code = CheckGpgError2ErrCode(err); QMessageBox::critical(parent, tr("Failure"), - tr("Gpg Operation failed.\n\nError code: %1\nSource: " - " %2\nDescription: %3") - .arg(err_code) - .arg(desc.first) - .arg(desc.second)); + tr("Gpg Operation failed.") + "\n\n" + + tr("Error code: %1").arg(err_code) + "\n\n\n" + + tr("Source: %1").arg(desc.first) + "\n" + + tr("Description: %1").arg(desc.second) + "\n" + + tr("Error Message: %1").arg(msg)); } void CommonUtils::SlotImportKeys(QWidget *parent, int channel, diff --git a/src/ui/UserInterfaceUtils.h b/src/ui/UserInterfaceUtils.h index fe912fcf..86b83e7f 100644 --- a/src/ui/UserInterfaceUtils.h +++ b/src/ui/UserInterfaceUtils.h @@ -113,7 +113,15 @@ class CommonUtils : public QWidget { * * @param err */ - static void RaiseFailureMessageBox(QWidget* parent, GpgError err); + static void RaiseMessageBoxNotSupported(QWidget* parent); + + /** + * @brief + * + * @param err + */ + static void RaiseFailureMessageBox(QWidget* parent, GpgError err, + const QString& msg = {}); /** * @brief diff --git a/src/ui/dialog/ADSKsPicker.cpp b/src/ui/dialog/ADSKsPicker.cpp index 878c5e96..56039a15 100644 --- a/src/ui/dialog/ADSKsPicker.cpp +++ b/src/ui/dialog/ADSKsPicker.cpp @@ -115,8 +115,7 @@ void ADSKsPicker::slot_add_adsk(const QContainer<GpgSubKey>& s_keys) { for (const auto& info : err_sub_key_infos) { failed_info.append(info); } - QString details = failed_info.join("\n\n"); - + auto 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() diff --git a/src/ui/dialog/controller/GnuPGControllerDialog.cpp b/src/ui/dialog/controller/GnuPGControllerDialog.cpp index 5dacae65..3f21b57b 100644 --- a/src/ui/dialog/controller/GnuPGControllerDialog.cpp +++ b/src/ui/dialog/controller/GnuPGControllerDialog.cpp @@ -333,7 +333,8 @@ auto GnuPGControllerDialog::check_custom_gnupg_path(QString path) -> bool { QMessageBox::critical(this, tr("Illegal GnuPG Path"), tr("Target GnuPG Path is not an absolute path.")); } -#ifdef __MINGW32__ + +#if defined(_WIN32) || defined(WIN32) QFileInfo const gpgconf_info(path + "/gpgconf.exe"); #else QFileInfo const gpgconf_info(path + "/gpgconf"); diff --git a/src/ui/dialog/controller/SmartCardControllerDialog.cpp b/src/ui/dialog/controller/SmartCardControllerDialog.cpp index 73dd48b9..797fe052 100644 --- a/src/ui/dialog/controller/SmartCardControllerDialog.cpp +++ b/src/ui/dialog/controller/SmartCardControllerDialog.cpp @@ -33,6 +33,7 @@ #include "core/function/gpg/GpgSmartCardManager.h" #include "core/utils/GpgUtils.h" #include "ui/UISignalStation.h" +#include "ui/UserInterfaceUtils.h" #include "ui/dialog/key_generate/GenerateCardKeyDialog.h" // @@ -110,18 +111,22 @@ SmartCardControllerDialog::SmartCardControllerDialog(QWidget* parent) [=](bool) { modify_key_pin("OPENPGP.2"); }); connect(ui_->restartGpgAgentButton, &QPushButton::clicked, this, [=](bool) { - GpgFrontend::GpgAdvancedOperator::RestartGpgComponents( - [=](int err, DataObjectPtr) { - if (err >= 0) { - QMessageBox::information( - this, tr("Successful Operation"), - tr("Restart all the GnuPG's components successfully")); - } else { - QMessageBox::critical( - this, tr("Failed Operation"), - tr("Failed to restart all or one of the GnuPG's component(s)")); - } - }); + bool ret = true; + const auto size = GpgContext::GetAllChannelId().size(); + for (auto i = 0; i < size; i++) { + ret = GpgAdvancedOperator::GetInstance().RestartGpgComponents(); + if (!ret) break; + } + + if (ret) { + QMessageBox::information( + this, tr("Successful Operation"), + tr("Restart all the GnuPG's components successfully")); + } else { + QMessageBox::critical( + this, tr("Failed Operation"), + tr("Failed to restart all or one of the GnuPG's component(s)")); + } }); connect(ui_->generateKeysButton, &QPushButton::clicked, this, [=](bool) { @@ -163,11 +168,13 @@ void SmartCardControllerDialog::select_smart_card_by_serial_number( return; } - auto [ret, err] = + auto [err, status] = GpgSmartCardManager::GetInstance(channel_).SelectCardBySerialNumber( serial_number); - if (!ret) { - LOG_E() << "select card by serial number failed: " << err; + if (err != GPG_ERR_NO_ERROR) { + LOG_E() << "select card by serial number failed, err:" << CheckGpgError(err) + << "status:" << status; + CommonUtils::RaiseFailureMessageBox(this, err, status); reset_status(); return; } @@ -188,6 +195,7 @@ void SmartCardControllerDialog::fetch_smart_card_info( GpgSmartCardManager::GetInstance(channel_).FetchCardInfoBySerialNumber( serial_number); if (card_info == nullptr) { + LOG_E() << "card info is nullptr, serial number:" << serial_number; reset_status(); return; } @@ -446,9 +454,14 @@ void SmartCardControllerDialog::slot_disable_controllers(bool disable) { void SmartCardControllerDialog::slot_fetch_smart_card_keys() { ui_->fetchButton->setDisabled(true); - GpgSmartCardManager::GetInstance().Fetch( + auto err = GpgSmartCardManager::GetInstance().Fetch( ui_->currentCardComboBox->currentText()); + if (err != GPG_ERR_NO_ERROR) { + CommonUtils::RaiseFailureMessageBox(this, err); + return; + } + QTimer::singleShot(1000, [=]() { GpgCommandExecutor::GetInstance(channel_).GpgExecuteSync( {{}, @@ -524,14 +537,13 @@ void SmartCardControllerDialog::modify_key_attribute(const QString& attr) { } } - auto [r, err] = + auto [err, status] = GpgSmartCardManager::GetInstance(channel_).ModifyAttr(attr, value); - if (!r) { - LOG_D() << "SCD SETATTR command failed for attr" << attr; - QMessageBox::critical( - this, tr("Failed"), - tr("Failed to set attribute '%1'. Reason: %2. ").arg(attr).arg(err)); + if (err != GPG_ERR_NO_ERROR) { + LOG_D() << "SCD SETATTR command failed for attr:" << attr + << ", err:" << CheckGpgError(err); + CommonUtils::RaiseFailureMessageBox(this, err, status); return; } QMessageBox::information(this, tr("Success"), @@ -540,22 +552,11 @@ void SmartCardControllerDialog::modify_key_attribute(const QString& attr) { } void SmartCardControllerDialog::modify_key_pin(const QString& pinref) { - auto [success, err] = + auto [err, status] = GpgSmartCardManager::GetInstance(channel_).ModifyPin(pinref); - if (!success) { - QString message; - if (pinref == "OPENPGP.3") { - message = tr("Failed to change Admin PIN."); - } else if (pinref == "OPENPGP.2") { - message = tr("Failed to set the Reset Code."); - } else { - message = tr("Failed to change PIN."); - } - - message += tr("Reason: ") + err; - - QMessageBox::critical(this, tr("Error"), message); + if (err != GPG_ERR_NO_ERROR) { + CommonUtils::RaiseFailureMessageBox(this, err, status); return; } diff --git a/src/ui/dialog/key_generate/KeyGenerateDialog.cpp b/src/ui/dialog/key_generate/KeyGenerateDialog.cpp index d738029d..df8b5232 100644 --- a/src/ui/dialog/key_generate/KeyGenerateDialog.cpp +++ b/src/ui/dialog/key_generate/KeyGenerateDialog.cpp @@ -49,8 +49,9 @@ KeyGenerateDialog::KeyGenerateDialog(int channel, QWidget* parent) ui_(QSharedPointer<Ui_KeyGenDialog>::create()), gen_key_info_(QSharedPointer<KeyGenerateInfo>::create()), gen_subkey_info_(nullptr), - supported_primary_key_algos_(KeyGenerateInfo::GetSupportedKeyAlgo()), - supported_subkey_algos_(KeyGenerateInfo::GetSupportedSubkeyAlgo()), + supported_primary_key_algos_( + KeyGenerateInfo::GetSupportedKeyAlgo(channel)), + supported_subkey_algos_(KeyGenerateInfo::GetSupportedSubkeyAlgo(channel)), channel_(channel) { ui_->setupUi(this); @@ -146,6 +147,10 @@ KeyGenerateDialog::KeyGenerateDialog(int channel, QWidget* parent) this->setWindowTitle(tr("Generate Key")); this->setAttribute(Qt::WA_DeleteOnClose); this->setModal(true); + + this->show(); + this->raise(); + this->activateWindow(); } void KeyGenerateDialog::slot_key_gen_accept() { diff --git a/src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp b/src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp index fd592733..68c68765 100644 --- a/src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp +++ b/src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp @@ -50,7 +50,8 @@ SubkeyGenerateDialog::SubkeyGenerateDialog(int channel, GpgKeyPtr key, current_gpg_context_channel_(channel), key_(std::move(key)), gen_subkey_info_(QSharedPointer<KeyGenerateInfo>::create(true)), - supported_subkey_algos_(KeyGenerateInfo::GetSupportedSubkeyAlgo()) { + supported_subkey_algos_(KeyGenerateInfo::GetSupportedSubkeyAlgo( + current_gpg_context_channel_)) { ui_->setupUi(this); assert(key_ != nullptr); @@ -88,6 +89,10 @@ SubkeyGenerateDialog::SubkeyGenerateDialog(int channel, GpgKeyPtr key, set_signal_slot_config(); refresh_widgets_state(); + + this->show(); + this->raise(); + this->activateWindow(); } void SubkeyGenerateDialog::set_signal_slot_config() { diff --git a/src/ui/dialog/keypair_details/KeyPairSubkeyTab.cpp b/src/ui/dialog/keypair_details/KeyPairSubkeyTab.cpp index 73e7f4e5..64e4d029 100644 --- a/src/ui/dialog/keypair_details/KeyPairSubkeyTab.cpp +++ b/src/ui/dialog/keypair_details/KeyPairSubkeyTab.cpp @@ -31,7 +31,6 @@ #include "core/function/gpg/GpgKeyGetter.h" #include "core/function/gpg/GpgKeyImportExporter.h" #include "core/function/gpg/GpgKeyManager.h" -#include "core/function/gpg/GpgKeyOpera.h" #include "core/utils/CommonUtils.h" #include "core/utils/GpgUtils.h" #include "core/utils/IOUtils.h" @@ -66,6 +65,11 @@ KeyPairSubkeyTab::KeyPairSubkeyTab(int channel, GpgKeyPtr key, QWidget* parent) add_adsk_button->hide(); } + if (!CheckGpgVersion(channel, "2.4.1")) { + add_adsk_button->setDisabled(true); + add_adsk_button->hide(); + } + uid_buttons_layout->addWidget(add_subkey_button, 0, 0); uid_buttons_layout->addWidget(add_adsk_button, 0, 1); @@ -277,9 +281,12 @@ void KeyPairSubkeyTab::slot_refresh_subkey_list() { } void KeyPairSubkeyTab::slot_add_subkey() { - auto* dialog = - new SubkeyGenerateDialog(current_gpg_context_channel_, key_, this); - dialog->show(); + if (!CheckGpgVersion(current_gpg_context_channel_, "2.2.0")) { + CommonUtils::RaiseMessageBoxNotSupported(this); + return; + } + + new SubkeyGenerateDialog(current_gpg_context_channel_, key_, this); } void KeyPairSubkeyTab::slot_add_adsk() { diff --git a/src/ui/dialog/keypair_details/KeyPairSubkeyTab.h b/src/ui/dialog/keypair_details/KeyPairSubkeyTab.h index 3d9eeb50..c7d7a08a 100644 --- a/src/ui/dialog/keypair_details/KeyPairSubkeyTab.h +++ b/src/ui/dialog/keypair_details/KeyPairSubkeyTab.h @@ -47,55 +47,13 @@ class KeyPairSubkeyTab : public QWidget { */ KeyPairSubkeyTab(int channel, GpgKeyPtr key, QWidget* parent); - private: - /** - * @brief Create a subkey list object - * - */ - void create_subkey_list(); - - /** - * @brief Create a subkey opera menu object - * - */ - void create_subkey_opera_menu(); - + protected: /** - * @brief Get the selected subkey object + * @brief * - * @return const GpgSubKey& + * @param event */ - auto get_selected_subkey() -> const GpgSubKey&; - - int current_gpg_context_channel_; - GpgKeyPtr key_; ///< - QTableWidget* subkey_list_{}; ///< - QContainer<GpgSubKey> buffered_subkeys_; ///< - - QGroupBox* list_box_; ///< - QGroupBox* detail_box_; ///< - - QMenu* subkey_opera_menu_{}; ///< - - QLabel* key_type_var_label_; - QLabel* key_size_var_label_; ///< Label containing the keys key size - QLabel* expire_var_label_; ///< Label containing the keys expiration date - QLabel* revoke_var_label_; - QLabel* created_var_label_; ///< Label containing the keys creation date - QLabel* algorithm_var_label_; ///< Label containing the keys algorithm - QLabel* algorithm_detail_var_label_; ///< - QLabel* key_id_var_label_; ///< Label containing the keys keyid - QLabel* fingerprint_var_label_; ///< Label containing the keys fingerprint - QLabel* usage_var_label_; ///< - QLabel* master_key_exist_var_label_; ///< - QLabel* card_key_label_; ///< - - QPushButton* export_subkey_button_; - QAction* export_subkey_act_; - - QAction* edit_subkey_act_; - QAction* delete_subkey_act_; - QAction* revoke_subkey_act_; + void contextMenuEvent(QContextMenuEvent* event) override; private slots: @@ -161,13 +119,55 @@ class KeyPairSubkeyTab : public QWidget { */ void SignalKeyDatabaseRefresh(); - protected: + private: + int current_gpg_context_channel_; + GpgKeyPtr key_; ///< + QTableWidget* subkey_list_{}; ///< + QContainer<GpgSubKey> buffered_subkeys_; ///< + + QGroupBox* list_box_; ///< + QGroupBox* detail_box_; ///< + + QMenu* subkey_opera_menu_{}; ///< + + QLabel* key_type_var_label_; + QLabel* key_size_var_label_; ///< Label containing the keys key size + QLabel* expire_var_label_; ///< Label containing the keys expiration date + QLabel* revoke_var_label_; + QLabel* created_var_label_; ///< Label containing the keys creation date + QLabel* algorithm_var_label_; ///< Label containing the keys algorithm + QLabel* algorithm_detail_var_label_; ///< + QLabel* key_id_var_label_; ///< Label containing the keys keyid + QLabel* fingerprint_var_label_; ///< Label containing the keys fingerprint + QLabel* usage_var_label_; ///< + QLabel* master_key_exist_var_label_; ///< + QLabel* card_key_label_; ///< + + QPushButton* export_subkey_button_; + QAction* export_subkey_act_; + + QAction* edit_subkey_act_; + QAction* delete_subkey_act_; + QAction* revoke_subkey_act_; + /** - * @brief + * @brief Create a subkey list object * - * @param event */ - void contextMenuEvent(QContextMenuEvent* event) override; + void create_subkey_list(); + + /** + * @brief Create a subkey opera menu object + * + */ + void create_subkey_opera_menu(); + + /** + * @brief Get the selected subkey object + * + * @return const GpgSubKey& + */ + auto get_selected_subkey() -> const GpgSubKey&; }; } // namespace GpgFrontend::UI diff --git a/src/ui/function/GpgOperaHelper.cpp b/src/ui/function/GpgOperaHelper.cpp index 91bc6c38..82742b93 100644 --- a/src/ui/function/GpgOperaHelper.cpp +++ b/src/ui/function/GpgOperaHelper.cpp @@ -90,6 +90,12 @@ auto GpgOperaHelper::BuildSimpleGpgFileOperasHelper( // stop waiting op_hd(); + if (CheckGpgError(err) == GPG_ERR_NOT_SUPPORTED) { + opera_results.append({-1, "# " + tr("Operation Not Supported"), + QFileInfo(path).fileName()}); + return; + } + if (CheckGpgError(err) == GPG_ERR_USER_1 || data_obj == nullptr || !data_obj->Check<ResultType>()) { opera_results.append( @@ -126,6 +132,12 @@ auto GpgOperaHelper::BuildComplexGpgFileOperasHelper( // stop waiting op_hd(); + if (CheckGpgError(err) == GPG_ERR_NOT_SUPPORTED) { + opera_results.append({-1, "# " + tr("Operation Not Supported"), + QFileInfo(path).fileName()}); + return; + } + if (CheckGpgError(err) == GPG_ERR_USER_1 || data_obj == nullptr || !data_obj->Check<ResultTypeA, ResultTypeB>()) { opera_results.append( @@ -169,6 +181,11 @@ auto GpgOperaHelper::BuildSimpleGpgOperasHelper( // stop waiting op_hd(); + if (CheckGpgError(err) == GPG_ERR_NOT_SUPPORTED) { + opera_results.append({-1, "# " + tr("Operation Not Supported"), {}}); + return; + } + if (CheckGpgError(err) == GPG_ERR_USER_1 || data_obj == nullptr || !data_obj->Check<ResultType, GFBuffer>()) { opera_results.append({-1, "# " + tr("Critical Error"), {}}); @@ -207,6 +224,11 @@ auto GpgOperaHelper::BuildComplexGpgOperasHelper( // stop waiting op_hd(); + if (CheckGpgError(err) == GPG_ERR_NOT_SUPPORTED) { + opera_results.append({-1, "# " + tr("Operation Not Supported"), {}}); + return; + } + if (CheckGpgError(err) == GPG_ERR_USER_1 || data_obj == nullptr || !data_obj->Check<ResultTypeA, ResultTypeB, GFBuffer>()) { opera_results.append({-1, "# " + tr("Critical Error"), {}}); diff --git a/src/ui/main_window/KeyMgmt.cpp b/src/ui/main_window/KeyMgmt.cpp index e3128231..f9364ecf 100644 --- a/src/ui/main_window/KeyMgmt.cpp +++ b/src/ui/main_window/KeyMgmt.cpp @@ -428,12 +428,20 @@ void KeyMgmt::SlotExportKeyToClipboard() { } void KeyMgmt::SlotGenerateKeyDialog() { - (new KeyGenerateDialog(key_list_->GetCurrentGpgContextChannel(), this)) - ->exec(); - this->raise(); + if (!CheckGpgVersion(key_list_->GetCurrentGpgContextChannel(), "2.2.0")) { + CommonUtils::RaiseMessageBoxNotSupported(this); + return; + } + + new KeyGenerateDialog(key_list_->GetCurrentGpgContextChannel(), this); } void KeyMgmt::SlotGenerateSubKey() { + if (!CheckGpgVersion(key_list_->GetCurrentGpgContextChannel(), "2.2.0")) { + CommonUtils::RaiseMessageBoxNotSupported(this); + return; + } + auto key = key_list_->GetSelectedGpgKey(); if (key == nullptr) return; @@ -444,10 +452,7 @@ void KeyMgmt::SlotGenerateSubKey() { return; } - (new SubkeyGenerateDialog(key_list_->GetCurrentGpgContextChannel(), key, - this)) - ->exec(); - this->raise(); + new SubkeyGenerateDialog(key_list_->GetCurrentGpgContextChannel(), key, this); } void KeyMgmt::SlotExportAsOpenSSHFormat() { diff --git a/src/ui/main_window/MainWindow.cpp b/src/ui/main_window/MainWindow.cpp index 104f54d8..8c8fd55e 100644 --- a/src/ui/main_window/MainWindow.cpp +++ b/src/ui/main_window/MainWindow.cpp @@ -31,6 +31,8 @@ #include "core/function/GlobalSettingStation.h" #include "core/model/SettingsObject.h" #include "core/module/ModuleManager.h" +#include "core/utils/CommonUtils.h" +#include "core/utils/GpgUtils.h" #include "ui/UISignalStation.h" #include "ui/main_window/GeneralMainWindow.h" #include "ui/struct/settings_object/AppearanceSO.h" @@ -115,6 +117,25 @@ void MainWindow::Init() noexcept { &UISignalStation::SignalMainWindowOpenFile, this, &MainWindow::SlotOpenFile); +#if !(defined(_WIN32) || defined(WIN32)) + connect(this, &MainWindow::SignalLoaded, this, [=]() { + QTimer::singleShot(3000, [self = QPointer<MainWindow>(this)]() { + if (self != nullptr && DecidePinentry().isEmpty() && !IsFlatpakENV()) { + QMessageBox::warning( + self, tr("GUI Pinentry Not Found"), + tr("No suitable *graphical* Pinentry program was found on your " + "system.\n\n" + "Please install a GUI-based Pinentry (e.g., 'pinentry-qt', " + "'pinentry-gnome3', or 'pinentry-mac' on macOS).\n\n" + "Without a GUI Pinentry, GnuPG cannot prompt you for " + "passwords or passphrases.\n\n" + "After installing it, please restart GpgFrontend. The " + "configuration file will be updated automatically.")); + } + }); + }); +#endif + popup_menu_ = new QMenu(this); popup_menu_->addAction(append_selected_keys_act_); @@ -152,7 +173,6 @@ void MainWindow::Init() noexcept { // loading process is done emit SignalLoaded(); Module::TriggerEvent("APPLICATION_LOADED"); - } catch (...) { LOG_W() << tr("Critical error occur while loading GpgFrontend."); QMessageBox::critical( diff --git a/src/ui/main_window/MainWindow.h b/src/ui/main_window/MainWindow.h index 15fb9fb1..16092609 100644 --- a/src/ui/main_window/MainWindow.h +++ b/src/ui/main_window/MainWindow.h @@ -528,7 +528,7 @@ class MainWindow : public GeneralMainWindow { * * @param results */ - void slot_update_operations_menu_by_checked_keys(unsigned int type); + void slot_update_operations_menu_by_checked_keys(unsigned int mask); /** * @brief diff --git a/src/ui/main_window/MainWindowSlotUI.cpp b/src/ui/main_window/MainWindowSlotUI.cpp index e0a72ed1..6b945beb 100644 --- a/src/ui/main_window/MainWindowSlotUI.cpp +++ b/src/ui/main_window/MainWindowSlotUI.cpp @@ -311,46 +311,58 @@ void MainWindow::SlotGeneralDecryptVerify(bool) { } void MainWindow::slot_clean_gpg_password_cache(bool) { - GpgFrontend::GpgAdvancedOperator::ClearGpgPasswordCache( - [=](int err, DataObjectPtr) { - if (err >= 0) { - QMessageBox::information(this, tr("Successful Operation"), - tr("Clear password cache successfully")); - } else { - QMessageBox::critical(this, tr("Failed Operation"), - tr("Failed to clear password cache of GnuPG")); - } - }); + bool ret = true; + const auto size = GpgContext::GetAllChannelId().size(); + for (auto i = 0; i < size; i++) { + ret = GpgAdvancedOperator::GetInstance().ClearGpgPasswordCache(); + if (!ret) break; + } + + if (ret) { + QMessageBox::information(this, tr("Successful Operation"), + tr("Clear password cache successfully")); + } else { + QMessageBox::critical(this, tr("Failed Operation"), + tr("Failed to clear password cache of GnuPG")); + } } void MainWindow::slot_reload_gpg_components(bool) { - GpgFrontend::GpgAdvancedOperator::ReloadGpgComponents( - [=](int err, DataObjectPtr) { - if (err >= 0) { - QMessageBox::information( - this, tr("Successful Operation"), - tr("Reload all the GnuPG's components successfully")); - } else { - QMessageBox::critical( - this, tr("Failed Operation"), - tr("Failed to reload all or one of the GnuPG's component(s)")); - } - }); + bool ret = true; + const auto size = GpgContext::GetAllChannelId().size(); + for (auto i = 0; i < size; i++) { + ret = GpgAdvancedOperator::GetInstance().ReloadAllGpgComponents(); + if (!ret) break; + } + + if (ret) { + QMessageBox::information( + this, tr("Successful Operation"), + tr("Reload all the GnuPG's components successfully")); + } else { + QMessageBox::critical( + this, tr("Failed Operation"), + tr("Failed to reload all or one of the GnuPG's component(s)")); + } } void MainWindow::slot_restart_gpg_components(bool) { - GpgFrontend::GpgAdvancedOperator::RestartGpgComponents( - [=](int err, DataObjectPtr) { - if (err >= 0) { - QMessageBox::information( - this, tr("Successful Operation"), - tr("Restart all the GnuPG's components successfully")); - } else { - QMessageBox::critical( - this, tr("Failed Operation"), - tr("Failed to restart all or one of the GnuPG's component(s)")); - } - }); + bool ret = true; + const auto size = GpgContext::GetAllChannelId().size(); + for (auto i = 0; i < size; i++) { + ret = GpgAdvancedOperator::GetInstance().RestartGpgComponents(); + if (!ret) break; + } + + if (ret) { + QMessageBox::information( + this, tr("Successful Operation"), + tr("Restart all the GnuPG's components successfully")); + } else { + QMessageBox::critical( + this, tr("Failed Operation"), + tr("Failed to restart all or one of the GnuPG's component(s)")); + } } void MainWindow::slot_update_operations_menu_by_checked_keys( |