diff options
author | saturneric <[email protected]> | 2025-04-18 15:54:54 +0000 |
---|---|---|
committer | saturneric <[email protected]> | 2025-04-18 15:54:54 +0000 |
commit | 8f14fdc7325cb9635e3d92873baaa58f430fca01 (patch) | |
tree | 323f462c283ac2151a23cfffd08d52a678c06541 /src/ui | |
parent | fix: add missing libGLESv2.dll on windows platform (diff) | |
download | GpgFrontend-8f14fdc7325cb9635e3d92873baaa58f430fca01.tar.gz GpgFrontend-8f14fdc7325cb9635e3d92873baaa58f430fca01.zip |
feat: add more info check
Diffstat (limited to 'src/ui')
-rw-r--r-- | src/ui/UserInterfaceUtils.cpp | 13 | ||||
-rw-r--r-- | src/ui/UserInterfaceUtils.h | 3 | ||||
-rw-r--r-- | src/ui/dialog/ADSKsPicker.cpp | 3 | ||||
-rw-r--r-- | src/ui/dialog/controller/SmartCardControllerDialog.cpp | 73 | ||||
-rw-r--r-- | src/ui/function/GpgOperaHelper.cpp | 22 | ||||
-rw-r--r-- | src/ui/main_window/MainWindow.h | 2 | ||||
-rw-r--r-- | src/ui/main_window/MainWindowSlotUI.cpp | 80 |
7 files changed, 116 insertions, 80 deletions
diff --git a/src/ui/UserInterfaceUtils.cpp b/src/ui/UserInterfaceUtils.cpp index 8d277ab4..ed76824a 100644 --- a/src/ui/UserInterfaceUtils.cpp +++ b/src/ui/UserInterfaceUtils.cpp @@ -167,16 +167,17 @@ void CommonUtils::RaiseMessageBox(QWidget *parent, GpgError err) { } } -void CommonUtils::RaiseFailureMessageBox(QWidget *parent, GpgError err) { +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..b544ffc3 100644 --- a/src/ui/UserInterfaceUtils.h +++ b/src/ui/UserInterfaceUtils.h @@ -113,7 +113,8 @@ class CommonUtils : public QWidget { * * @param err */ - static void RaiseFailureMessageBox(QWidget* parent, GpgError 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/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/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/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( |