diff options
author | saturneric <[email protected]> | 2024-04-12 09:14:37 +0000 |
---|---|---|
committer | saturneric <[email protected]> | 2024-04-12 09:14:37 +0000 |
commit | 26e24222e434036e5ec13f8ec99b958faf325154 (patch) | |
tree | 2a7145ae6f480713a529a20a29a90de4c436c399 /src/ui/dialog/help/GnupgTab.cpp | |
parent | fix: find and solve some issues on module management (diff) | |
download | GpgFrontend-26e24222e434036e5ec13f8ec99b958faf325154.tar.gz GpgFrontend-26e24222e434036e5ec13f8ec99b958faf325154.zip |
feat: add auto activate function and optimums for some structures
Diffstat (limited to 'src/ui/dialog/help/GnupgTab.cpp')
-rw-r--r-- | src/ui/dialog/help/GnupgTab.cpp | 70 |
1 files changed, 54 insertions, 16 deletions
diff --git a/src/ui/dialog/help/GnupgTab.cpp b/src/ui/dialog/help/GnupgTab.cpp index 5d3f21aa..218426b6 100644 --- a/src/ui/dialog/help/GnupgTab.cpp +++ b/src/ui/dialog/help/GnupgTab.cpp @@ -35,7 +35,12 @@ #include "core/module/ModuleManager.h" #include "ui_GnuPGInfo.h" -GpgFrontend::UI::GnupgTab::GnupgTab(QWidget* parent) +namespace GpgFrontend::UI { + +const QString kGnuPGInfoGatheringModuleID = + "com.bktus.gpgfrontend.module.integrated.gnupg_info_gathering"; + +GnupgTab::GnupgTab(QWidget* parent) : QWidget(parent), ui_(GpgFrontend::SecureCreateSharedObject<Ui_GnuPGInfo>()) { ui_->setupUi(this); @@ -103,10 +108,15 @@ GpgFrontend::UI::GnupgTab::GnupgTab(QWidget* parent) ui_->optionDetailsTable->setFocusPolicy(Qt::NoFocus); ui_->optionDetailsTable->setAlternatingRowColors(true); - process_software_info(); + if (Module::RetrieveRTValueTypedOrDefault( + "ui", "env.state.gnupg_info_gathering", 0) == 1) { + process_software_info(); + } else { + gather_gnupg_info(); + } } -void GpgFrontend::UI::GnupgTab::process_software_info() { +void GnupgTab::process_software_info() { const auto gnupg_version = Module::RetrieveRTValueTypedOrDefault<>( "core", "gpgme.ctx.gnupg_version", QString{"2.0.0"}); GF_UI_LOG_DEBUG("got gnupg version from rt: {}", gnupg_version); @@ -114,9 +124,8 @@ void GpgFrontend::UI::GnupgTab::process_software_info() { ui_->gnupgVersionLabel->setText( QString::fromStdString(fmt::format("Version: {}", gnupg_version))); - auto components = Module::ListRTChildKeys( - "com.bktus.gpgfrontend.module.integrated.gnupg_info_gathering", - "gnupg.components"); + auto components = + Module::ListRTChildKeys(kGnuPGInfoGatheringModuleID, "gnupg.components"); GF_UI_LOG_DEBUG("got gnupg components from rt, size: {}", components.size()); ui_->componentDetailsTable->setRowCount(components.size()); @@ -124,7 +133,7 @@ void GpgFrontend::UI::GnupgTab::process_software_info() { int row = 0; for (auto& component : components) { auto component_info_json_bytes = Module::RetrieveRTValueTypedOrDefault( - "com.bktus.gpgfrontend.module.integrated.gnupg_info_gathering", + kGnuPGInfoGatheringModuleID, QString("gnupg.components.%1").arg(component), QByteArray{}); GF_UI_LOG_DEBUG("got gnupg component {} info from rt", component); @@ -170,17 +179,16 @@ void GpgFrontend::UI::GnupgTab::process_software_info() { ui_->componentDetailsTable->resizeColumnsToContents(); - auto directories = Module::ListRTChildKeys( - "com.bktus.gpgfrontend.module.integrated.gnupg_info_gathering", - QString("gnupg.dirs")); + auto directories = Module::ListRTChildKeys(kGnuPGInfoGatheringModuleID, + QString("gnupg.dirs")); ui_->directoriesDetailsTable->setRowCount(directories.size()); row = 0; for (auto& dir : directories) { const auto dir_path = Module::RetrieveRTValueTypedOrDefault( - "com.bktus.gpgfrontend.module.integrated.gnupg_info_gathering", - QString("gnupg.dirs.%1").arg(dir), QString{}); + kGnuPGInfoGatheringModuleID, QString("gnupg.dirs.%1").arg(dir), + QString{}); if (dir_path.isEmpty()) continue; @@ -201,12 +209,12 @@ void GpgFrontend::UI::GnupgTab::process_software_info() { row = 0; for (auto& component : components) { auto options = Module::ListRTChildKeys( - "com.bktus.gpgfrontend.module.integrated.gnupg_info_gathering", + kGnuPGInfoGatheringModuleID, QString("gnupg.components.%1.options").arg(component)); for (auto& option : options) { const auto option_info_json = QJsonDocument::fromJson(Module::RetrieveRTValueTypedOrDefault( - "com.bktus.gpgfrontend.module.integrated.gnupg_info_gathering", + kGnuPGInfoGatheringModuleID, QString("gnupg.components.%1.options.%2") .arg(component) .arg(option), @@ -228,12 +236,12 @@ void GpgFrontend::UI::GnupgTab::process_software_info() { QString configuration_group; for (auto& component : components) { auto options = Module::ListRTChildKeys( - "com.bktus.gpgfrontend.module.integrated.gnupg_info_gathering", + kGnuPGInfoGatheringModuleID, QString("gnupg.components.%1.options").arg(component)); for (auto& option : options) { auto option_info_json_bytes = Module::RetrieveRTValueTypedOrDefault( - "com.bktus.gpgfrontend.module.integrated.gnupg_info_gathering", + kGnuPGInfoGatheringModuleID, QString("gnupg.components.%1.options.%2").arg(component).arg(option), QByteArray{}); GF_UI_LOG_DEBUG("got gnupg component's option {} info from rt, info: {}", @@ -291,3 +299,33 @@ void GpgFrontend::UI::GnupgTab::process_software_info() { } // ui_->configurationDetailsTable->resizeColumnsToContents(); } + +void GnupgTab::gather_gnupg_info() { + // if gnupg_info_gathering module activated + if (Module::IsModuleAcivate(kGnuPGInfoGatheringModuleID)) { + GF_CORE_LOG_DEBUG( + "module gnupg_info_gathering is activated, " + "loading external gnupg info..."); + + // gather external gnupg info + Module::TriggerEvent( + "REQUEST_GATHERING_GNUPG_INFO", + [=](const Module::EventIdentifier& /*e*/, + const Module::Event::ListenerIdentifier& l_id, DataObjectPtr o) { + GF_CORE_LOG_DEBUG( + "received event REQUEST_GATHERING_GNUPG_INFO callback " + "from module: {}", + l_id); + + if (l_id == kGnuPGInfoGatheringModuleID) { + Module::UpsertRTValue("ui", "env.state.gnupg_info_gathering", 1); + + // gnupg info gathering process finished + GF_CORE_LOG_INFO("gnupg information gathering finished"); + process_software_info(); + } + }); + } +} + +} // namespace GpgFrontend::UI
\ No newline at end of file |