diff options
Diffstat (limited to 'src/ui/main_window')
-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 |
4 files changed, 80 insertions, 43 deletions
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( |