diff options
author | Saturneric <[email protected]> | 2023-11-29 09:49:54 +0000 |
---|---|---|
committer | Saturneric <[email protected]> | 2023-11-29 09:49:54 +0000 |
commit | 9d16c9d5dfcd1171d713c3ba87a69d0f0fac4f33 (patch) | |
tree | 3e85ce5236d134b59d70277cf0cb713561aa2a53 /src | |
parent | style: tidy up core/model (diff) | |
download | GpgFrontend-9d16c9d5dfcd1171d713c3ba87a69d0f0fac4f33.tar.gz GpgFrontend-9d16c9d5dfcd1171d713c3ba87a69d0f0fac4f33.zip |
fix: repair gnupg info listing funtion
Diffstat (limited to '')
-rw-r--r-- | src/core/GpgCoreInit.cpp | 9 | ||||
-rw-r--r-- | src/core/function/gpg/GpgAdvancedOperator.cpp | 18 | ||||
-rw-r--r-- | src/core/module/GlobalRegisterTable.cpp | 43 | ||||
-rw-r--r-- | src/core/module/GlobalRegisterTable.h | 2 | ||||
-rw-r--r-- | src/core/module/Module.cpp | 2 | ||||
-rw-r--r-- | src/core/module/ModuleManager.cpp | 29 | ||||
-rw-r--r-- | src/core/module/ModuleManager.h | 12 | ||||
-rw-r--r-- | src/module/integrated/gnupg_info_gathering_module/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/module/integrated/gnupg_info_gathering_module/GnuPGInfoGatheringModule.cpp | 66 | ||||
-rw-r--r-- | src/module/integrated/version_checking_module/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/module/integrated/version_checking_module/VersionCheckingModule.cpp | 3 | ||||
-rw-r--r-- | src/ui/dialog/gnupg/GnuPGControllerDialog.cpp | 3 | ||||
-rw-r--r-- | src/ui/dialog/help/AboutDialog.cpp | 55 | ||||
-rw-r--r-- | src/ui/dialog/help/GnupgTab.cpp | 203 | ||||
-rw-r--r-- | src/ui/main_window/MainWindow.cpp | 3 | ||||
-rw-r--r-- | src/ui/main_window/MainWindowSlotFunction.cpp | 15 | ||||
-rw-r--r-- | src/ui/widgets/PlainTextEditorPage.cpp | 1 |
17 files changed, 280 insertions, 188 deletions
diff --git a/src/core/GpgCoreInit.cpp b/src/core/GpgCoreInit.cpp index e6d7f784..cbf07b62 100644 --- a/src/core/GpgCoreInit.cpp +++ b/src/core/GpgCoreInit.cpp @@ -245,11 +245,12 @@ void InitGpgFrontendCore() { "GPGFRONTEND_CORE_INITLIZED", [](const Module::EventIdentifier& /*e*/, const Module::Event::ListenerIdentifier& l_id, DataObjectPtr o) { - if (l_id == Module::GetRealModuleIdentifier( - "com.bktus.gpgfrontend.module.integrated." - "gnupginfogathering")) { + if (l_id == + "com.bktus.gpgfrontend.module.integrated." + "gnupginfogathering") { SPDLOG_DEBUG( - "gnupginfogathering gnupg.gathering_done changed, restarting gpg " + "gnupg-info-gathering gnupg.gathering_done changed, restarting " + "gpg " "components"); // try to restart all components GpgFrontend::GpgAdvancedOperator::RestartGpgComponents(); diff --git a/src/core/function/gpg/GpgAdvancedOperator.cpp b/src/core/function/gpg/GpgAdvancedOperator.cpp index 7ef89ce7..0f8d1718 100644 --- a/src/core/function/gpg/GpgAdvancedOperator.cpp +++ b/src/core/function/gpg/GpgAdvancedOperator.cpp @@ -176,14 +176,12 @@ auto GpgFrontend::GpgAdvancedOperator::StartGpgAgent() -> bool { bool success = false; const auto gpg_agent_path = Module::RetrieveRTValueTypedOrDefault<>( - Module::GetRealModuleIdentifier( - "com.bktus.gpgfrontend.module.integrated.gnupginfogathering"), + "com.bktus.gpgfrontend.module.integrated.gnupg-info-gathering", "gnupg.gpg_agent_path", std::string{}); SPDLOG_DEBUG("got gnupg agent path from rt: {}", gpg_agent_path); const auto home_path = Module::RetrieveRTValueTypedOrDefault<>( - Module::GetRealModuleIdentifier( - "com.bktus.gpgfrontend.module.integrated.gnupginfogathering"), + "com.bktus.gpgfrontend.module.integrated.gnupg-info-gathering", "gnupg.home_path", std::string{}); SPDLOG_DEBUG("got gnupg home path from rt: {}", home_path); @@ -218,14 +216,12 @@ auto GpgFrontend::GpgAdvancedOperator::StartDirmngr() -> bool { bool success = false; const auto dirmngr_path = Module::RetrieveRTValueTypedOrDefault<>( - Module::GetRealModuleIdentifier( - "com.bktus.gpgfrontend.module.integrated.gnupginfogathering"), + "com.bktus.gpgfrontend.module.integrated.gnupg-info-gathering", "gnupg.dirmngr_path", std::string{}); SPDLOG_DEBUG("got gnupg dirmngr path from rt: {}", dirmngr_path); const auto home_path = Module::RetrieveRTValueTypedOrDefault<>( - Module::GetRealModuleIdentifier( - "com.bktus.gpgfrontend.module.integrated.gnupginfogathering"), + "com.bktus.gpgfrontend.module.integrated.gnupg-info-gathering", "gnupg.home_path", std::string{}); SPDLOG_DEBUG("got gnupg home path from rt: {}", home_path); @@ -259,14 +255,12 @@ auto GpgFrontend::GpgAdvancedOperator::StartKeyBoxd() -> bool { bool success = false; const auto keyboxd_path = Module::RetrieveRTValueTypedOrDefault<>( - Module::GetRealModuleIdentifier( - "com.bktus.gpgfrontend.module.integrated.gnupginfogathering"), + "com.bktus.gpgfrontend.module.integrated.gnupg-info-gathering", "gnupg.keyboxd_path", std::string{}); SPDLOG_DEBUG("got gnupg keyboxd path from rt: {}", keyboxd_path); const auto home_path = Module::RetrieveRTValueTypedOrDefault<>( - Module::GetRealModuleIdentifier( - "com.bktus.gpgfrontend.module.integrated.gnupginfogathering"), + "com.bktus.gpgfrontend.module.integrated.gnupg-info-gathering", "gnupg.home_path", std::string{}); SPDLOG_DEBUG("got gnupg home path from rt: {}", home_path); diff --git a/src/core/module/GlobalRegisterTable.cpp b/src/core/module/GlobalRegisterTable.cpp index 4aba1b6c..09c39dae 100644 --- a/src/core/module/GlobalRegisterTable.cpp +++ b/src/core/module/GlobalRegisterTable.cpp @@ -31,8 +31,10 @@ #include <any> #include <optional> #include <shared_mutex> +#include <sstream> #include <unordered_map> #include <utility> +#include <vector> namespace GpgFrontend::Module { @@ -47,10 +49,7 @@ class GlobalRegisterTable::Impl { explicit Impl(GlobalRegisterTable* parent) : parent_(parent) {} - auto PublishKV(Namespace n, Key k, std::any v) -> bool { - SPDLOG_DEBUG("publishing kv to rt, n: {}, k: {}, v type: {}", n, k, - v.type().name()); - + auto PublishKV(const Namespace& n, const Key& k, std::any v) -> bool { std::istringstream iss(k); std::string segment; @@ -77,9 +76,7 @@ class GlobalRegisterTable::Impl { return true; } - auto LookupKV(Namespace n, Key k) -> std::optional<std::any> { - SPDLOG_DEBUG("looking up kv in rt, n: {}, k: {}", n, k); - + auto LookupKV(const Namespace& n, const Key& k) -> std::optional<std::any> { std::istringstream iss(k); std::string segment; @@ -100,7 +97,32 @@ class GlobalRegisterTable::Impl { return rtn; } - auto ListenPublish(QObject* o, Namespace n, Key k, LPCallback c) -> bool { + auto ListChildKeys(const Namespace& n, const Key& k) -> std::vector<Key> { + std::istringstream iss(k); + std::string segment; + + std::vector<Key> rtn; + { + std::shared_lock lock(lock_); + auto it = global_register_table_.find(n); + if (it == global_register_table_.end()) return {}; + + RTNode* current = it->second.get(); + while (std::getline(iss, segment, '.')) { + auto it = current->children.find(segment); + if (it == current->children.end()) return {}; + current = it->second.get(); + } + + for (auto& it : current->children) { + rtn.emplace_back(it.first); + } + } + return rtn; + } + + auto ListenPublish(QObject* o, const Namespace& n, const Key& k, LPCallback c) + -> bool { if (o == nullptr) return false; return QObject::connect(parent_, &GlobalRegisterTable::SignalPublish, o, [n, k, c](const Namespace& pn, const Key& pk, @@ -137,4 +159,9 @@ auto GlobalRegisterTable::ListenPublish(QObject* o, Namespace n, Key k, return p_->ListenPublish(o, n, k, c); } +auto GlobalRegisterTable::ListChildKeys(Namespace n, Key k) + -> std::vector<Key> { + return p_->ListChildKeys(n, k); +} + } // namespace GpgFrontend::Module
\ No newline at end of file diff --git a/src/core/module/GlobalRegisterTable.h b/src/core/module/GlobalRegisterTable.h index ee7b881c..09627841 100644 --- a/src/core/module/GlobalRegisterTable.h +++ b/src/core/module/GlobalRegisterTable.h @@ -51,6 +51,8 @@ class GlobalRegisterTable : public QObject { auto ListenPublish(QObject *, Namespace, Key, LPCallback) -> bool; + auto ListChildKeys(Namespace n, Key k) -> std::vector<Key>; + signals: void SignalPublish(Namespace, Key, int, std::any); diff --git a/src/core/module/Module.cpp b/src/core/module/Module.cpp index d66773ff..642aadf8 100644 --- a/src/core/module/Module.cpp +++ b/src/core/module/Module.cpp @@ -43,7 +43,7 @@ class Module::Impl { Impl(ModuleRawPtr m_ptr, ModuleIdentifier id, ModuleVersion version, ModuleMetaData meta_data) : m_ptr_(m_ptr), - identifier_((boost::format("__module_%1%") % id).str()), + identifier_(id), version_(version), meta_data_(meta_data) {} diff --git a/src/core/module/ModuleManager.cpp b/src/core/module/ModuleManager.cpp index 1c778197..4400a92d 100644 --- a/src/core/module/ModuleManager.cpp +++ b/src/core/module/ModuleManager.cpp @@ -95,6 +95,11 @@ class ModuleManager::Impl { return grt_->ListenPublish(o, n, k, c); } + auto ListRTChildKeys(const std::string& n, const std::string& k) + -> std::vector<Key> { + return grt_->ListChildKeys(n, k); + } + private: static ModuleMangerPtr global_module_manager; TaskRunnerPtr task_runner_; @@ -108,11 +113,16 @@ auto UpsertRTValue(const std::string& namespace_, const std::string& key, std::any(value)); } -auto GPGFRONTEND_CORE_EXPORT ListenRTPublishEvent(QObject* o, Namespace n, - Key k, LPCallback c) -> bool { +auto ListenRTPublishEvent(QObject* o, Namespace n, Key k, LPCallback c) + -> bool { return ModuleManager::GetInstance()->ListenRTPublish(o, n, k, c); } +auto ListRTChildKeys(const std::string& namespace_, const std::string& key) + -> std::vector<Key> { + return ModuleManager::GetInstance()->ListRTChildKeys(namespace_, key); +} + ModuleManager::ModuleManager() : p_(std::make_unique<Impl>()) {} ModuleManager::~ModuleManager() = default; @@ -130,13 +140,13 @@ void ModuleManager::TriggerEvent(EventRefrernce event) { return p_->TriggerEvent(event); } -void ModuleManager::ActiveModule(ModuleIdentifier identifier) { - return p_->ActiveModule(identifier); +void ModuleManager::ActiveModule(ModuleIdentifier id) { + return p_->ActiveModule(id); } -auto ModuleManager::GetTaskRunner(ModuleIdentifier module_id) +auto ModuleManager::GetTaskRunner(ModuleIdentifier id) -> std::optional<TaskRunnerPtr> { - return p_->GetTaskRunner(std::move(module_id)); + return p_->GetTaskRunner(std::move(id)); } auto ModuleManager::UpsertRTValue(Namespace n, Key k, std::any v) -> bool { @@ -153,10 +163,9 @@ auto ModuleManager::ListenRTPublish(QObject* o, Namespace n, Key k, return p_->ListenPublish(o, n, k, c); } -auto GetRealModuleIdentifier(const ModuleIdentifier& m_id) -> ModuleIdentifier { - // WARNING: when YOU need to CHANGE this line, YOU SHOULD change the same code - // in Module.cpp as well. - return (boost::format("__module_%1%") % m_id).str(); +auto ModuleManager::ListRTChildKeys(const std::string& n, const std::string& k) + -> std::vector<Key> { + return p_->ListRTChildKeys(n, k); } } // namespace GpgFrontend::Module
\ No newline at end of file diff --git a/src/core/module/ModuleManager.h b/src/core/module/ModuleManager.h index 55325ab6..cf845f96 100644 --- a/src/core/module/ModuleManager.h +++ b/src/core/module/ModuleManager.h @@ -28,6 +28,8 @@ #pragma once +#include <vector> + #include "core/module/Event.h" namespace GpgFrontend::Thread { @@ -52,9 +54,6 @@ using Namespace = std::string; using Key = std::string; using LPCallback = std::function<void(Namespace, Key, int, std::any)>; -auto GPGFRONTEND_CORE_EXPORT GetRealModuleIdentifier(const ModuleIdentifier& id) - -> ModuleIdentifier; - class GPGFRONTEND_CORE_EXPORT ModuleManager : public QObject { Q_OBJECT public: @@ -78,6 +77,9 @@ class GPGFRONTEND_CORE_EXPORT ModuleManager : public QObject { auto ListenRTPublish(QObject*, Namespace, Key, LPCallback) -> bool; + auto ListRTChildKeys(const std::string&, const std::string&) + -> std::vector<Key>; + private: class Impl; std::unique_ptr<Impl> p_; @@ -114,6 +116,10 @@ auto GPGFRONTEND_CORE_EXPORT UpsertRTValue(const std::string& namespace_, auto GPGFRONTEND_CORE_EXPORT ListenRTPublishEvent(QObject*, Namespace, Key, LPCallback) -> bool; +auto GPGFRONTEND_CORE_EXPORT ListRTChildKeys(const std::string& namespace_, + const std::string& key) + -> std::vector<Key>; + template <typename T> auto RetrieveRTValueTyped(const std::string& namespace_, const std::string& key) -> std::optional<T> { diff --git a/src/module/integrated/gnupg_info_gathering_module/CMakeLists.txt b/src/module/integrated/gnupg_info_gathering_module/CMakeLists.txt index bdc7ff15..2a62b08e 100644 --- a/src/module/integrated/gnupg_info_gathering_module/CMakeLists.txt +++ b/src/module/integrated/gnupg_info_gathering_module/CMakeLists.txt @@ -23,7 +23,7 @@ # # SPDX-License-Identifier: GPL-3.0-or-later -# com.bktus.gpgfrontend.module.integrated.gnupginfogathering +# com.bktus.gpgfrontend.module.integrated.gnupg-info-gathering aux_source_directory(. INTEGRATED_MODULE_SOURCE) diff --git a/src/module/integrated/gnupg_info_gathering_module/GnuPGInfoGatheringModule.cpp b/src/module/integrated/gnupg_info_gathering_module/GnuPGInfoGatheringModule.cpp index 12a03c10..492c87f1 100644 --- a/src/module/integrated/gnupg_info_gathering_module/GnuPGInfoGatheringModule.cpp +++ b/src/module/integrated/gnupg_info_gathering_module/GnuPGInfoGatheringModule.cpp @@ -74,7 +74,8 @@ std::optional<std::string> check_binary_chacksum(std::filesystem::path path) { GnuPGInfoGatheringModule::GnuPGInfoGatheringModule() : Module( - "com.bktus.gpgfrontend.module.integrated.gnupginfogathering", "1.0.0", + "com.bktus.gpgfrontend.module.integrated.gnupg-info-gathering", + "1.0.0", ModuleMetaData{{"description", "try to gathering gnupg informations"}, {"author", "saturneric"}}) {} @@ -127,7 +128,7 @@ int GnuPGInfoGatheringModule::Exec(EventRefrernce event) { GpgComponentInfo c_i_gpgme; c_i_gpgme.name = "gpgme"; c_i_gpgme.desc = "GPG Made Easy"; - c_i_gpgme.version = "gpgme_version"; + c_i_gpgme.version = gpgme_version; c_i_gpgme.path = _("Embedded In"); c_i_gpgme.binary_checksum = "/"; @@ -146,10 +147,12 @@ int GnuPGInfoGatheringModule::Exec(EventRefrernce event) { nlohmann::json jsonlized_gpgme_component_info = c_i_gpgme; nlohmann::json jsonlized_gpgconf_component_info = c_i_gpgconf; - UpsertRTValue(GetModuleIdentifier(), "gnupg.components.gpgme", - std::string(jsonlized_gpgme_component_info.dump())); - UpsertRTValue(GetModuleIdentifier(), "gnupg.components.gpgconf", - std::string(jsonlized_gpgme_component_info.dump())); + UpsertRTValue( + GetModuleIdentifier(), "gnupg.components.gpgme", + static_cast<std::string>(jsonlized_gpgme_component_info.dump())); + UpsertRTValue( + GetModuleIdentifier(), "gnupg.components.gpgconf", + static_cast<std::string>(jsonlized_gpgme_component_info.dump())); std::vector<std::string> line_split_list; boost::split(line_split_list, p_out, boost::is_any_of("\n")); @@ -213,19 +216,11 @@ int GnuPGInfoGatheringModule::Exec(EventRefrernce event) { UpsertRTValue( GetModuleIdentifier(), (boost::format("gnupg.components.%1%") % component_name).str(), - std::string(jsonlized_component_info.dump())); + static_cast<std::string>(jsonlized_component_info.dump())); component_infos.push_back(c_i); } } - - nlohmann::json jsonlized_components_info; - for (auto &component_info : component_infos) { - jsonlized_components_info.emplace_back(component_info); - } - - UpsertRTValue(GetModuleIdentifier(), "gnupg.components_info", - std::string(jsonlized_components_info.dump())); }, getTaskRunner()}); @@ -283,32 +278,25 @@ int GnuPGInfoGatheringModule::Exec(EventRefrernce event) { }, getTaskRunner()}); - const std::string components_info_json = RetrieveRTValueTypedOrDefault( - GetModuleIdentifier(), "gnupg.components_info", std::string{}); - if (components_info_json.empty()) { - MODULE_LOG_ERROR("cannot get components inforamtion of gnupg from rt"); - return -1; - } - - nlohmann::json jsonlized_components_info = nlohmann::json::parse( - components_info_json, nullptr, false, true); // parse without exception - MODULE_LOG_DEBUG("start to check components options info, components: {}", - jsonlized_components_info); + auto components = ListRTChildKeys( + "com.bktus.gpgfrontend.module.integrated.gnupg-info-gathering", + "gnupg.components"); - if (!jsonlized_components_info.is_array()) { - MODULE_LOG_ERROR( - "cannot parse components inforamtion of gnupg to json from rt"); - return -1; - } + for (const auto &component : components) { + auto component_info_json = RetrieveRTValueTypedOrDefault( + "com.bktus.gpgfrontend.module.integrated.gnupg-info-gathering", + (boost::format("gnupg.components.%1%") % component).str(), + std::string{}); - for (const auto &jsonlized_component_info : jsonlized_components_info) { + auto jsonlized_component_info = nlohmann::json::parse(component_info_json); GpgComponentInfo component_info = jsonlized_component_info.get<GpgComponentInfo>(); MODULE_LOG_DEBUG("gpgconf check options ready, component: {}", component_info.name); - if (component_info.name == "gpgme" || component_info.name == "gpgconf") + if (component_info.name == "gpgme" || component_info.name == "gpgconf") { continue; + } exec_contexts.emplace_back(GpgCommandExecutor::ExecuteContext{ gpgconf_path, @@ -397,18 +385,6 @@ int GnuPGInfoGatheringModule::Exec(EventRefrernce event) { static_cast<std::string>(jsonlized_option_info.dump())); options_infos.push_back(info); } - - nlohmann::json jsonlized_options_info; - for (auto &option_info : options_infos) { - jsonlized_options_info.emplace_back(option_info); - } - UpsertRTValue( - GetModuleIdentifier(), - (boost::format("gnupg.components.%1%" - ".options_info") % - component_info.name) - .str(), - static_cast<std::string>(jsonlized_options_info.dump())); }, getTaskRunner()}); } diff --git a/src/module/integrated/version_checking_module/CMakeLists.txt b/src/module/integrated/version_checking_module/CMakeLists.txt index b6e3fb2c..e0996764 100644 --- a/src/module/integrated/version_checking_module/CMakeLists.txt +++ b/src/module/integrated/version_checking_module/CMakeLists.txt @@ -23,7 +23,7 @@ # # SPDX-License-Identifier: GPL-3.0-or-later -# com.bktus.gpgfrontend.module.integrated.versionchecking +# com.bktus.gpgfrontend.module.integrated.version-checking aux_source_directory(. INTEGRATED_MODULE_SOURCE) diff --git a/src/module/integrated/version_checking_module/VersionCheckingModule.cpp b/src/module/integrated/version_checking_module/VersionCheckingModule.cpp index 115db32a..b1eb7a16 100644 --- a/src/module/integrated/version_checking_module/VersionCheckingModule.cpp +++ b/src/module/integrated/version_checking_module/VersionCheckingModule.cpp @@ -41,7 +41,8 @@ namespace GpgFrontend::Module::Integrated::VersionCheckingModule { VersionCheckingModule::VersionCheckingModule() - : Module("com.bktus.gpgfrontend.module.integrated.versionchecking", "1.0.0", + : Module("com.bktus.gpgfrontend.module.integrated.version-checking", + "1.0.0", ModuleMetaData{{"description", "try to check gpgfrontend version"}, {"author", "saturneric"}}) {} diff --git a/src/ui/dialog/gnupg/GnuPGControllerDialog.cpp b/src/ui/dialog/gnupg/GnuPGControllerDialog.cpp index 92b4201d..ebb4cc61 100644 --- a/src/ui/dialog/gnupg/GnuPGControllerDialog.cpp +++ b/src/ui/dialog/gnupg/GnuPGControllerDialog.cpp @@ -245,8 +245,7 @@ void GnuPGControllerDialog::slot_update_custom_gnupg_install_path_label( this->slot_set_restart_needed(kDeepRestartCode); const auto home_path = Module::RetrieveRTValueTypedOrDefault<>( - Module::GetRealModuleIdentifier( - "com.bktus.gpgfrontend.module.integrated.gnupginfogathering"), + "com.bktus.gpgfrontend.module.integrated.gnupg-info-gathering", "gnupg.home_path", std::string{}); SPDLOG_DEBUG("got gnupg home path from rt: {}", home_path); diff --git a/src/ui/dialog/help/AboutDialog.cpp b/src/ui/dialog/help/AboutDialog.cpp index f308b75c..8d5ad896 100644 --- a/src/ui/dialog/help/AboutDialog.cpp +++ b/src/ui/dialog/help/AboutDialog.cpp @@ -37,7 +37,6 @@ #include "core/function/GlobalSettingStation.h" #include "core/module/Module.h" #include "core/module/ModuleManager.h" -#include "core/thread/TaskRunnerGetter.h" #include "ui/dialog/help/GnupgTab.h" namespace GpgFrontend::UI { @@ -64,13 +63,13 @@ AboutDialog::AboutDialog(int defaultIndex, QWidget* parent) tab_widget->setCurrentIndex(defaultIndex); } - auto* buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok); - connect(buttonBox, &QDialogButtonBox::accepted, this, &AboutDialog::close); + auto* button_box = new QDialogButtonBox(QDialogButtonBox::Ok); + connect(button_box, &QDialogButtonBox::accepted, this, &AboutDialog::close); - auto* mainLayout = new QVBoxLayout; - mainLayout->addWidget(tab_widget); - mainLayout->addWidget(buttonBox); - setLayout(mainLayout); + auto* main_layout = new QVBoxLayout; + main_layout->addWidget(tab_widget); + main_layout->addWidget(button_box); + setLayout(main_layout); this->resize(550, 650); this->setMinimumWidth(450); @@ -106,14 +105,14 @@ InfoTab::InfoTab(QWidget* parent) : QWidget(parent) { _("Built at") + " " + BUILD_TIMESTAMP + "</center>"); auto* layout = new QGridLayout(); - auto* pixmapLabel = new QLabel(); - pixmapLabel->setPixmap(*pixmap); - layout->addWidget(pixmapLabel, 0, 0, 1, -1, Qt::AlignCenter); - auto* aboutLabel = new QLabel(); - aboutLabel->setText(*text); - aboutLabel->setWordWrap(true); - aboutLabel->setOpenExternalLinks(true); - layout->addWidget(aboutLabel, 1, 0, 1, -1); + auto* pixmap_label = new QLabel(); + pixmap_label->setPixmap(*pixmap); + layout->addWidget(pixmap_label, 0, 0, 1, -1, Qt::AlignCenter); + auto* about_label = new QLabel(); + about_label->setText(*text); + about_label->setWordWrap(true); + about_label->setOpenExternalLinks(true); + layout->addWidget(about_label, 1, 0, 1, -1); layout->addItem( new QSpacerItem(20, 10, QSizePolicy::Minimum, QSizePolicy::Fixed), 2, 1, 1, 1); @@ -141,7 +140,7 @@ TranslatorsTab::TranslatorsTab(QWidget* parent) : QWidget(parent) { main_layout->addWidget(label); main_layout->addStretch(); - auto notice_label = new QLabel( + auto* notice_label = new QLabel( _("If you think there are any problems with the translation, why not " "participate in the translation work? If you want to participate, " "please " @@ -163,7 +162,7 @@ UpdateTab::UpdateTab(QWidget* parent) : QWidget(parent) { current_version_ = QString("v") + VERSION_MAJOR + "." + VERSION_MINOR + "." + VERSION_PATCH; - auto tips_label = new QLabel(); + auto* tips_label = new QLabel(); tips_label->setText( "<center>" + QString(_("It is recommended that you always check the version " @@ -209,15 +208,12 @@ void UpdateTab::showEvent(QShowEvent* event) { SPDLOG_DEBUG("loading version loading info from rt"); auto is_loading_done = Module::RetrieveRTValueTypedOrDefault<>( - Module::GetRealModuleIdentifier( - "com.bktus.gpgfrontend.module.integrated.versionchecking"), + "com.bktus.gpgfrontend.module.integrated.version-checking", "version.loading_done", false); if (!is_loading_done) { Module::ListenRTPublishEvent( - this, - Module::GetRealModuleIdentifier( - "com.bktus.gpgfrontend.module.integrated.versionchecking"), + this, "com.bktus.gpgfrontend.module.integrated.version-checking", "version.loading_done", [=](Module::Namespace, Module::Key, int, std::any) { SPDLOG_DEBUG( @@ -236,8 +232,7 @@ void UpdateTab::slot_show_version_status() { this->pb_->setHidden(true); auto is_loading_done = Module::RetrieveRTValueTypedOrDefault<>( - Module::GetRealModuleIdentifier( - "com.bktus.gpgfrontend.module.integrated.versionchecking"), + "com.bktus.gpgfrontend.module.integrated.version-checking", "version.loading_done", false); if (!is_loading_done) { @@ -246,23 +241,19 @@ void UpdateTab::slot_show_version_status() { } auto is_need_upgrade = Module::RetrieveRTValueTypedOrDefault<>( - Module::GetRealModuleIdentifier( - "com.bktus.gpgfrontend.module.integrated.versionchecking"), + "com.bktus.gpgfrontend.module.integrated.version-checking", "version.need_upgrade", false); auto is_current_a_withdrawn_version = Module::RetrieveRTValueTypedOrDefault<>( - Module::GetRealModuleIdentifier( - "com.bktus.gpgfrontend.module.integrated.versionchecking"), + "com.bktus.gpgfrontend.module.integrated.version-checking", "version.current_a_withdrawn_version", false); auto is_current_version_released = Module::RetrieveRTValueTypedOrDefault<>( - Module::GetRealModuleIdentifier( - "com.bktus.gpgfrontend.module.integrated.versionchecking"), + "com.bktus.gpgfrontend.module.integrated.version-checking", "version.current_version_released", false); auto latest_version = Module::RetrieveRTValueTypedOrDefault<>( - Module::GetRealModuleIdentifier( - "com.bktus.gpgfrontend.module.integrated.versionchecking"), + "com.bktus.gpgfrontend.module.integrated.version-checking", "version.latest_version", std::string{}); latest_version_label_->setText( diff --git a/src/ui/dialog/help/GnupgTab.cpp b/src/ui/dialog/help/GnupgTab.cpp index 4780dbf1..260ca29d 100644 --- a/src/ui/dialog/help/GnupgTab.cpp +++ b/src/ui/dialog/help/GnupgTab.cpp @@ -32,6 +32,8 @@ #include "GnupgTab.h" +#include <boost/format.hpp> +#include <nlohmann/json.hpp> #include <shared_mutex> #include "core/module/ModuleManager.h" @@ -57,7 +59,9 @@ GpgFrontend::UI::GnupgTab::GnupgTab(QWidget* parent) QAbstractItemView::SelectRows); QStringList configurations_column_titles; - configurations_column_titles << _("Key") << _("Value"); + configurations_column_titles << _("Component") << _("Group") << _("Key") + << _("Description") << _("Default Value") + << _("Value"); ui_->configurationDetailsTable->setColumnCount( configurations_column_titles.length()); @@ -88,59 +92,146 @@ void GpgFrontend::UI::GnupgTab::process_software_info() { ui_->gnupgVersionLabel->setText( QString::fromStdString(fmt::format("Version: {}", gnupg_version))); - // ui_->componentDetailsTable->setRowCount(ctx_info.ComponentsInfo.size()); - - // int row = 0; - // for (const auto& info : ctx_info.ComponentsInfo) { - // if (info.second.size() != 4) continue; - - // auto* tmp0 = new QTableWidgetItem(QString::fromStdString(info.first)); - // tmp0->setTextAlignment(Qt::AlignCenter); - // ui_->componentDetailsTable->setItem(row, 0, tmp0); - - // auto* tmp1 = new - // QTableWidgetItem(QString::fromStdString(info.second[0])); - // tmp1->setTextAlignment(Qt::AlignCenter); - // ui_->componentDetailsTable->setItem(row, 1, tmp1); - - // auto* tmp2 = new - // QTableWidgetItem(QString::fromStdString(info.second[1])); - // tmp2->setTextAlignment(Qt::AlignCenter); - // ui_->componentDetailsTable->setItem(row, 2, tmp2); - - // auto* tmp3 = new - // QTableWidgetItem(QString::fromStdString(info.second[3])); - // tmp3->setTextAlignment(Qt::AlignCenter); - // ui_->componentDetailsTable->setItem(row, 3, tmp3); - - // auto* tmp4 = new - // QTableWidgetItem(QString::fromStdString(info.second[2])); - // tmp4->setTextAlignment(Qt::AlignLeft); - // ui_->componentDetailsTable->setItem(row, 4, tmp4); - - // row++; - // } - - // ui_->componentDetailsTable->resizeColumnsToContents(); - - // ui_->configurationDetailsTable->setRowCount( - // ctx_info.ConfigurationsInfo.size()); - - // row = 0; - // for (const auto& info : ctx_info.ConfigurationsInfo) { - // if (info.second.size() != 1) continue; - - // auto* tmp0 = new QTableWidgetItem(QString::fromStdString(info.first)); - // tmp0->setTextAlignment(Qt::AlignCenter); - // ui_->configurationDetailsTable->setItem(row, 0, tmp0); - - // auto* tmp1 = new - // QTableWidgetItem(QString::fromStdString(info.second[0])); - // tmp1->setTextAlignment(Qt::AlignCenter); - // ui_->configurationDetailsTable->setItem(row, 1, tmp1); - - // row++; - // } - - // ui_->configurationDetailsTable->resizeColumnsToContents(); + auto components = Module::ListRTChildKeys( + "com.bktus.gpgfrontend.module.integrated.gnupg-info-gathering", + "gnupg.components"); + SPDLOG_DEBUG("got gnupg components from rt, size: {}", components.size()); + + ui_->componentDetailsTable->setRowCount(components.size()); + + int row = 0; + for (auto& component : components) { + auto component_info_json = Module::RetrieveRTValueTypedOrDefault( + "com.bktus.gpgfrontend.module.integrated.gnupg-info-gathering", + (boost::format("gnupg.components.%1%") % component).str(), + std::string{}); + SPDLOG_DEBUG("got gnupg component {} info from rt, info: {}", component, + component_info_json); + + auto component_info = nlohmann::json::parse(component_info_json); + + if (!component_info.contains("name")) { + SPDLOG_WARN("illegal gnupg component info, json: {}", + component_info_json); + continue; + } + + auto* tmp0 = new QTableWidgetItem( + QString::fromStdString(component_info.value("name", ""))); + tmp0->setTextAlignment(Qt::AlignCenter); + ui_->componentDetailsTable->setItem(row, 0, tmp0); + + auto* tmp1 = new QTableWidgetItem( + QString::fromStdString(component_info.value("desc", ""))); + tmp1->setTextAlignment(Qt::AlignCenter); + ui_->componentDetailsTable->setItem(row, 1, tmp1); + + auto* tmp2 = new QTableWidgetItem( + QString::fromStdString(component_info.value("version", ""))); + tmp2->setTextAlignment(Qt::AlignCenter); + ui_->componentDetailsTable->setItem(row, 2, tmp2); + + auto* tmp3 = new QTableWidgetItem( + QString::fromStdString(component_info.value("binary_checksum", ""))); + tmp3->setTextAlignment(Qt::AlignCenter); + ui_->componentDetailsTable->setItem(row, 3, tmp3); + + auto* tmp4 = new QTableWidgetItem( + QString::fromStdString(component_info.value("path", ""))); + tmp4->setTextAlignment(Qt::AlignLeft); + ui_->componentDetailsTable->setItem(row, 4, tmp4); + + row++; + } + + ui_->componentDetailsTable->resizeColumnsToContents(); + + // calcualte the total row number of configuration table + row = 0; + for (auto& component : components) { + auto options = Module::ListRTChildKeys( + "com.bktus.gpgfrontend.module.integrated.gnupg-info-gathering", + (boost::format("gnupg.components.%1%.options") % component).str()); + for (auto& option : options) { + const auto option_info = + nlohmann::json::parse(Module::RetrieveRTValueTypedOrDefault( + "com.bktus.gpgfrontend.module.integrated.gnupg-info-gathering", + (boost::format("gnupg.components.%1%.options.%2%") % component % + option) + .str(), + std::string{})); + if (!option_info.contains("name") || + option_info.value("flags", "1") == "1") { + continue; + } + row++; + } + } + ui_->configurationDetailsTable->setRowCount(row); + + row = 0; + std::string configuration_group; + for (auto& component : components) { + auto options = Module::ListRTChildKeys( + "com.bktus.gpgfrontend.module.integrated.gnupg-info-gathering", + (boost::format("gnupg.components.%1%.options") % component).str()); + + for (auto& option : options) { + auto option_info_json = Module::RetrieveRTValueTypedOrDefault( + "com.bktus.gpgfrontend.module.integrated.gnupg-info-gathering", + (boost::format("gnupg.components.%1%.options.%2%") % component % + option) + .str(), + std::string{}); + SPDLOG_DEBUG("got gnupg component's option {} info from rt, info: {}", + component, option_info_json); + + auto option_info = nlohmann::json::parse(option_info_json); + + if (!option_info.contains("name")) { + SPDLOG_WARN("illegal gnupg configuation info, json: {}", + option_info_json); + continue; + } + + if (option_info.value("flags", "1") == "1") { + configuration_group = option_info.value("name", ""); + continue; + } + + auto* tmp0 = new QTableWidgetItem(QString::fromStdString(component)); + tmp0->setTextAlignment(Qt::AlignCenter); + ui_->configurationDetailsTable->setItem(row, 0, tmp0); + + auto* tmp1 = + new QTableWidgetItem(QString::fromStdString(configuration_group)); + tmp1->setTextAlignment(Qt::AlignCenter); + ui_->configurationDetailsTable->setItem(row, 1, tmp1); + + auto* tmp2 = new QTableWidgetItem( + QString::fromStdString(option_info.value("name", ""))); + tmp2->setTextAlignment(Qt::AlignCenter); + ui_->configurationDetailsTable->setItem(row, 2, tmp2); + + auto* tmp3 = new QTableWidgetItem( + QString::fromStdString(option_info.value("description", ""))); + + tmp3->setTextAlignment(Qt::AlignLeft); + ui_->configurationDetailsTable->setItem(row, 3, tmp3); + + auto* tmp4 = new QTableWidgetItem( + QString::fromStdString(option_info.value("default_value", ""))); + tmp4->setTextAlignment(Qt::AlignLeft); + ui_->configurationDetailsTable->setItem(row, 4, tmp4); + + auto* tmp5 = new QTableWidgetItem( + QString::fromStdString(option_info.value("value", ""))); + tmp5->setTextAlignment(Qt::AlignLeft); + ui_->configurationDetailsTable->setItem(row, 5, tmp5); + + row++; + } + } + // ui_->configurationDetailsTable->resizeColumnsToContents(); + } diff --git a/src/ui/main_window/MainWindow.cpp b/src/ui/main_window/MainWindow.cpp index cbe27ffb..0b683bbe 100644 --- a/src/ui/main_window/MainWindow.cpp +++ b/src/ui/main_window/MainWindow.cpp @@ -133,8 +133,7 @@ void MainWindow::Init() noexcept { Module::ListenRTPublishEvent( this, - Module::GetRealModuleIdentifier( - "com.bktus.gpgfrontend.module.integrated.versionchecking"), + "com.bktus.gpgfrontend.module.integrated.version-checking", "version.loading_done", [=](Module::Namespace, Module::Key, int, std::any) { SPDLOG_DEBUG( diff --git a/src/ui/main_window/MainWindowSlotFunction.cpp b/src/ui/main_window/MainWindowSlotFunction.cpp index dbcfb01e..2c1d92ac 100644 --- a/src/ui/main_window/MainWindowSlotFunction.cpp +++ b/src/ui/main_window/MainWindowSlotFunction.cpp @@ -810,8 +810,7 @@ void MainWindow::slot_version_upgrade_nofity() { SPDLOG_DEBUG( "slot version upgrade notify called, checking version info from rt..."); auto is_loading_done = Module::RetrieveRTValueTypedOrDefault<>( - Module::GetRealModuleIdentifier( - "com.bktus.gpgfrontend.module.integrated.versionchecking"), + "com.bktus.gpgfrontend.module.integrated.version-checking", "version.loading_done", false); SPDLOG_DEBUG("checking version info from rt, is loading done state: {}", @@ -822,23 +821,19 @@ void MainWindow::slot_version_upgrade_nofity() { } auto is_need_upgrade = Module::RetrieveRTValueTypedOrDefault<>( - Module::GetRealModuleIdentifier( - "com.bktus.gpgfrontend.module.integrated.versionchecking"), + "com.bktus.gpgfrontend.module.integrated.version-checking", "version.need_upgrade", false); auto is_current_a_withdrawn_version = Module::RetrieveRTValueTypedOrDefault<>( - Module::GetRealModuleIdentifier( - "com.bktus.gpgfrontend.module.integrated.versionchecking"), + "com.bktus.gpgfrontend.module.integrated.version-checking", "version.current_a_withdrawn_version", false); auto is_current_version_released = Module::RetrieveRTValueTypedOrDefault<>( - Module::GetRealModuleIdentifier( - "com.bktus.gpgfrontend.module.integrated.versionchecking"), + "com.bktus.gpgfrontend.module.integrated.version-checking", "version.current_version_released", false); auto latest_version = Module::RetrieveRTValueTypedOrDefault<>( - Module::GetRealModuleIdentifier( - "com.bktus.gpgfrontend.module.integrated.versionchecking"), + "com.bktus.gpgfrontend.module.integrated.version-checking", "version.latest_version", std::string{}); SPDLOG_DEBUG( diff --git a/src/ui/widgets/PlainTextEditorPage.cpp b/src/ui/widgets/PlainTextEditorPage.cpp index 9cd76886..fa7e138b 100644 --- a/src/ui/widgets/PlainTextEditorPage.cpp +++ b/src/ui/widgets/PlainTextEditorPage.cpp @@ -29,6 +29,7 @@ #include "PlainTextEditorPage.h" #include <boost/format.hpp> +#include <sstream> #include <string> #include <utility> |