diff options
author | saturneric <[email protected]> | 2024-04-14 12:56:18 +0000 |
---|---|---|
committer | saturneric <[email protected]> | 2024-04-14 12:56:18 +0000 |
commit | cb2672ca430c54244df7bd46ef97256c3d840cbf (patch) | |
tree | a54bb28d61cf9dbf608261782c4f3febec72ea8c /src | |
parent | fix: use qt designer placeholder instead of custom initialized (diff) | |
download | GpgFrontend-cb2672ca430c54244df7bd46ef97256c3d840cbf.tar.gz GpgFrontend-cb2672ca430c54244df7bd46ef97256c3d840cbf.zip |
feat: add a grt viewer and solve some issues in gnupg info tab
Diffstat (limited to '')
-rw-r--r-- | src/core/GpgConstants.h | 6 | ||||
-rw-r--r-- | src/core/function/gpg/GpgAdvancedOperator.cpp | 18 | ||||
-rw-r--r-- | src/core/module/GlobalRegisterTable.cpp | 238 | ||||
-rw-r--r-- | src/core/module/GlobalRegisterTable.h | 4 | ||||
-rw-r--r-- | src/core/module/GlobalRegisterTableTreeModel.h | 61 | ||||
-rw-r--r-- | src/core/module/ModuleManager.cpp | 5 | ||||
-rw-r--r-- | src/core/module/ModuleManager.h | 3 | ||||
-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 | 25 | ||||
-rw-r--r-- | src/module/integrated/version_checking_module/VersionCheckingModule.cpp | 10 | ||||
-rw-r--r-- | src/ui/dialog/help/AboutDialog.cpp | 6 | ||||
-rw-r--r-- | src/ui/dialog/help/GnupgTab.cpp | 23 | ||||
-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/main_window/MainWindowUI.cpp | 6 | ||||
-rw-r--r-- | src/ui/widgets/GRTTreeView.cpp | 42 | ||||
-rw-r--r-- | src/ui/widgets/GRTTreeView.h | 41 |
17 files changed, 419 insertions, 89 deletions
diff --git a/src/core/GpgConstants.h b/src/core/GpgConstants.h index c2125650..d339e4f6 100644 --- a/src/core/GpgConstants.h +++ b/src/core/GpgConstants.h @@ -51,4 +51,10 @@ constexpr const char* PGP_PUBLIC_KEY_BEGIN = constexpr const char* PGP_PRIVATE_KEY_BEGIN = "-----BEGIN PGP PRIVATE KEY BLOCK-----"; ///< +// MODULE ID +const QString kGnuPGInfoGatheringModuleID = + "com.bktus.gpgfrontend.module.gnupg_info_gathering"; +const QString kVersionCheckingModuleID = + "com.bktus.gpgfrontend.module.version_checking"; + } // namespace GpgFrontend diff --git a/src/core/function/gpg/GpgAdvancedOperator.cpp b/src/core/function/gpg/GpgAdvancedOperator.cpp index 6e67bfb7..205fe1aa 100644 --- a/src/core/function/gpg/GpgAdvancedOperator.cpp +++ b/src/core/function/gpg/GpgAdvancedOperator.cpp @@ -140,13 +140,11 @@ void GpgFrontend::GpgAdvancedOperator::ResetConfigures(OperationCallback cb) { void GpgFrontend::GpgAdvancedOperator::StartGpgAgent(OperationCallback cb) { const auto gpg_agent_path = Module::RetrieveRTValueTypedOrDefault<>( - "com.bktus.gpgfrontend.module.integrated.gnupg_info_gathering", - "gnupg.gpg_agent_path", QString{}); + kGnuPGInfoGatheringModuleID, "gnupg.gpg_agent_path", QString{}); GF_CORE_LOG_DEBUG("got gnupg agent path from rt: {}", gpg_agent_path); const auto home_path = Module::RetrieveRTValueTypedOrDefault<>( - "com.bktus.gpgfrontend.module.integrated.gnupg_info_gathering", - "gnupg.home_path", QString{}); + kGnuPGInfoGatheringModuleID, "gnupg.home_path", QString{}); GF_CORE_LOG_DEBUG("got gnupg home path from rt: {}", home_path); if (gpg_agent_path.isEmpty()) { @@ -165,13 +163,11 @@ void GpgFrontend::GpgAdvancedOperator::StartGpgAgent(OperationCallback cb) { void GpgFrontend::GpgAdvancedOperator::StartDirmngr(OperationCallback cb) { const auto dirmngr_path = Module::RetrieveRTValueTypedOrDefault<>( - "com.bktus.gpgfrontend.module.integrated.gnupg_info_gathering", - "gnupg.dirmngr_path", QString{}); + kGnuPGInfoGatheringModuleID, "gnupg.dirmngr_path", QString{}); GF_CORE_LOG_DEBUG("got gnupg dirmngr path from rt: {}", dirmngr_path); const auto home_path = Module::RetrieveRTValueTypedOrDefault<>( - "com.bktus.gpgfrontend.module.integrated.gnupg_info_gathering", - "gnupg.home_path", QString{}); + kGnuPGInfoGatheringModuleID, "gnupg.home_path", QString{}); GF_CORE_LOG_DEBUG("got gnupg home path from rt: {}", home_path); if (dirmngr_path.isEmpty()) { @@ -190,13 +186,11 @@ void GpgFrontend::GpgAdvancedOperator::StartDirmngr(OperationCallback cb) { void GpgFrontend::GpgAdvancedOperator::StartKeyBoxd(OperationCallback cb) { const auto keyboxd_path = Module::RetrieveRTValueTypedOrDefault<>( - "com.bktus.gpgfrontend.module.integrated.gnupg_info_gathering", - "gnupg.keyboxd_path", QString{}); + kGnuPGInfoGatheringModuleID, "gnupg.keyboxd_path", QString{}); GF_CORE_LOG_DEBUG("got gnupg keyboxd path from rt: {}", keyboxd_path); const auto home_path = Module::RetrieveRTValueTypedOrDefault<>( - "com.bktus.gpgfrontend.module.integrated.gnupg_info_gathering", - "gnupg.home_path", QString{}); + kGnuPGInfoGatheringModuleID, "gnupg.home_path", QString{}); GF_CORE_LOG_DEBUG("got gnupg home path from rt: {}", home_path); if (keyboxd_path.isEmpty()) { diff --git a/src/core/module/GlobalRegisterTable.cpp b/src/core/module/GlobalRegisterTable.cpp index c16eba37..006118b3 100644 --- a/src/core/module/GlobalRegisterTable.cpp +++ b/src/core/module/GlobalRegisterTable.cpp @@ -31,10 +31,10 @@ #include <any> #include <optional> #include <shared_mutex> -#include <sstream> -#include <unordered_map> +#include <utility> #include <vector> +#include "GlobalRegisterTableTreeModel.h" #include "function/SecureMemoryAllocator.h" #include "utils/MemoryUtils.h" @@ -43,33 +43,45 @@ namespace GpgFrontend::Module { class GlobalRegisterTable::Impl { public: struct RTNode { - std::optional<std::any> value = std::nullopt; - std::unordered_map<QString, SecureUniquePtr<RTNode>> children; + QString name; + QString type = "NODE"; int version = 0; - const std::type_info* type = nullptr; + const std::type_info* value_type = nullptr; + std::optional<std::any> value = std::nullopt; + QMap<QString, QSharedPointer<RTNode>> children; + QWeakPointer<RTNode> parent; + + explicit RTNode(QString name, const QSharedPointer<RTNode>& parent) + : name(std::move(name)), parent(parent) {} }; - explicit Impl(GlobalRegisterTable* parent) : parent_(parent) {} + using RTNodePtr = QSharedPointer<RTNode>; + + explicit Impl(GlobalRegisterTable* parent) + : parent_(parent), + root_node_(SecureCreateQSharedObject<RTNode>("", nullptr)) {} auto PublishKV(const Namespace& n, const Key& k, std::any v) -> bool { - QStringList const segments = k.split('.'); + QStringList const segments = (n + "." + k).split('.'); int version = 0; { std::unique_lock lock(lock_); - auto& root_rt_node = - global_register_table_.emplace(n, SecureCreateUniqueObject<RTNode>()) - .first->second; - RTNode* current = root_rt_node.get(); + auto current = root_node_; for (const QString& segment : segments) { - current = current->children - .emplace(segment, SecureCreateUniqueObject<RTNode>()) - .first->second.get(); + auto it = current->children.find(segment); + if (it == current->children.end()) { + it = current->children.insert( + segment, SecureCreateQSharedObject<RTNode>(segment, current)); + } + current = it.value(); } + current->name = segments.back(); + current->type = "LEAF"; current->value = v; - current->type = &v.type(); + current->value_type = &v.type(); version = ++current->version; } @@ -78,19 +90,17 @@ class GlobalRegisterTable::Impl { } auto LookupKV(const Namespace& n, const Key& k) -> std::optional<std::any> { - QStringList const segments = k.split('.'); + QStringList const segments = (n + "." + k).split('.'); std::optional<std::any> rtn = std::nullopt; { std::shared_lock const lock(lock_); - auto it = global_register_table_.find(n); - if (it == global_register_table_.end()) return std::nullopt; - RTNode* current = it->second.get(); + auto current = root_node_; for (const QString& segment : segments) { auto it = current->children.find(segment); if (it == current->children.end()) return std::nullopt; - current = it->second.get(); + current = it.value(); } rtn = current->value; } @@ -98,24 +108,20 @@ class GlobalRegisterTable::Impl { } auto ListChildKeys(const Namespace& n, const Key& k) -> std::vector<Key> { - QStringList const segments = k.split('.'); + QStringList const segments = (n + "." + k).split('.'); 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(); + auto current = root_node_; for (const QString& segment : segments) { auto it = current->children.find(segment); if (it == current->children.end()) return {}; - current = it->second.get(); + current = it.value(); } - for (auto& it : current->children) { - rtn.emplace_back(it.first); - } + for (auto& key : current->children.keys()) rtn.emplace_back(key); } return rtn; } @@ -132,12 +138,149 @@ class GlobalRegisterTable::Impl { }) == nullptr; } + auto RootRTNode() -> RTNode* { return root_node_.get(); } + private: - using Table = std::map<Namespace, SecureUniquePtr<RTNode>>; std::shared_mutex lock_; GlobalRegisterTable* parent_; - Table global_register_table_; + RTNodePtr root_node_; +}; + +class GlobalRegisterTableTreeModel::Impl { + public: + using RTNode = GlobalRegisterTable::Impl::RTNode; + + Impl(GlobalRegisterTableTreeModel* parent, GlobalRegisterTable::Impl* grt) + : parent_(parent), root_node_(grt->RootRTNode()) {} + + [[nodiscard]] auto RowCount(const QModelIndex& parent) const -> int { + auto* parent_node = !parent.isValid() + ? root_node_.get() + : static_cast<RTNode*>(parent.internalPointer()); + return parent_node->children.size(); + } + + [[nodiscard]] auto ColumnCount(const QModelIndex& parent) const -> int { + return 4; + } + + [[nodiscard]] auto Data(const QModelIndex& index, int role) const + -> QVariant { + if (!index.isValid()) return {}; + + if (role == Qt::DisplayRole) { + auto* node = static_cast<RTNode*>(index.internalPointer()); + switch (index.column()) { + case 0: + return node->name; + case 1: + return node->type; + case 2: + return QString(node->value && node->value.has_value() + ? node->value->type().name() + : ""); + case 3: + return Any2QVariant(node->value); + default: + return {}; + } + } + return {}; + } + + static auto Any2QVariant(std::optional<std::any> op) -> QVariant { + if (!op) return "<EMPTY>"; + + auto& o = op.value(); + if (o.type() == typeid(QString)) { + return QVariant::fromValue(std::any_cast<QString>(o)); + } + if (o.type() == typeid(std::string)) { + return QVariant::fromValue( + QString::fromStdString(std::any_cast<std::string>(o))); + } + if (o.type() == typeid(int)) { + return QVariant::fromValue(std::any_cast<int>(o)); + } + if (o.type() == typeid(long)) { + return QVariant::fromValue( + static_cast<qlonglong>(std::any_cast<long>(o))); + } + if (o.type() == typeid(long long)) { + return QVariant::fromValue(std::any_cast<long long>(o)); + } + if (o.type() == typeid(unsigned)) { + return QVariant::fromValue(std::any_cast<unsigned>(o)); + } + if (o.type() == typeid(unsigned long)) { + return QVariant::fromValue( + static_cast<qulonglong>(std::any_cast<unsigned long>(o))); + } + if (o.type() == typeid(unsigned long long)) { + return QVariant::fromValue(std::any_cast<unsigned long long>(o)); + } + if (o.type() == typeid(float)) { + return QVariant::fromValue(std::any_cast<float>(o)); + } + if (o.type() == typeid(double)) { + return QVariant::fromValue(std::any_cast<double>(o)); + } + if (o.type() == typeid(bool)) { + return QVariant::fromValue(std::any_cast<bool>(o)); + } + return "<UNSUPPORTED>"; + } + + [[nodiscard]] auto Index(int row, int column, const QModelIndex& parent) const + -> QModelIndex { + if (!parent_->hasIndex(row, column, parent)) return {}; + + auto* parent_node = !parent.isValid() + ? root_node_.get() + : static_cast<RTNode*>(parent.internalPointer()); + auto key = parent_node->children.keys().at(row); + auto child_node = parent_node->children.value(key); + return parent_->createIndex(row, column, child_node.get()); + } + + [[nodiscard]] auto Parent(const QModelIndex& index) const -> QModelIndex { + if (!index.isValid()) return {}; + + auto* child_node = static_cast<RTNode*>(index.internalPointer()); + auto parent_node = child_node->parent.lock(); + + if (!parent_node || parent_node == root_node_) return {}; + + int row = + parent_node->parent.lock()->children.keys().indexOf(parent_node->name); + return parent_->createIndex(row, 0, parent_node.data()); + } + + [[nodiscard]] static auto HeaderData(int section, Qt::Orientation orientation, + int role) -> QVariant { + if (role != Qt::DisplayRole) return QVariant(); + + if (orientation == Qt::Horizontal) { + switch (section) { + case 0: + return QString("Key"); + case 1: + return QString("Type"); + case 2: + return QString("Value Type"); + case 3: + return QString("Value"); + default: + return {}; + } + } + return {}; + } + + private: + GlobalRegisterTableTreeModel* parent_; + GlobalRegisterTable::Impl::RTNodePtr root_node_; }; GlobalRegisterTable::GlobalRegisterTable() @@ -164,4 +307,39 @@ auto GlobalRegisterTable::ListChildKeys(Namespace n, Key k) return p_->ListChildKeys(n, k); } +GlobalRegisterTableTreeModel::GlobalRegisterTableTreeModel( + GlobalRegisterTable* grt) + : p_(SecureCreateUniqueObject<Impl>(this, grt->p_.get())) {} + +auto GlobalRegisterTableTreeModel::rowCount(const QModelIndex& parent) const + -> int { + return p_->RowCount(parent); +} + +auto GlobalRegisterTableTreeModel::columnCount(const QModelIndex& parent) const + -> int { + return p_->ColumnCount(parent); +} + +auto GlobalRegisterTableTreeModel::data(const QModelIndex& index, + int role) const -> QVariant { + return p_->Data(index, role); +} + +auto GlobalRegisterTableTreeModel::index(int row, int column, + const QModelIndex& parent) const + -> QModelIndex { + return p_->Index(row, column, parent); +} + +auto GlobalRegisterTableTreeModel::parent(const QModelIndex& index) const + -> QModelIndex { + return p_->Parent(index); +} + +auto GlobalRegisterTableTreeModel::headerData(int section, + Qt::Orientation orientation, + int role) const -> QVariant { + return p_->HeaderData(section, orientation, role); +} } // namespace GpgFrontend::Module
\ No newline at end of file diff --git a/src/core/module/GlobalRegisterTable.h b/src/core/module/GlobalRegisterTable.h index db68c888..1d3e43da 100644 --- a/src/core/module/GlobalRegisterTable.h +++ b/src/core/module/GlobalRegisterTable.h @@ -32,7 +32,7 @@ #include <functional> #include <optional> -#include "function/SecureMemoryAllocator.h" +#include "core/function/SecureMemoryAllocator.h" namespace GpgFrontend::Module { @@ -43,6 +43,8 @@ using LPCallback = std::function<void(Namespace, Key, int, std::any)>; class GlobalRegisterTable : public QObject { Q_OBJECT public: + friend class GlobalRegisterTableTreeModel; + GlobalRegisterTable(); ~GlobalRegisterTable() override; diff --git a/src/core/module/GlobalRegisterTableTreeModel.h b/src/core/module/GlobalRegisterTableTreeModel.h new file mode 100644 index 00000000..fe4242a2 --- /dev/null +++ b/src/core/module/GlobalRegisterTableTreeModel.h @@ -0,0 +1,61 @@ +/** + * Copyright (C) 2021 Saturneric <[email protected]> + * + * This file is part of GpgFrontend. + * + * GpgFrontend is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GpgFrontend is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GpgFrontend. If not, see <https://www.gnu.org/licenses/>. + * + * The initial version of the source code is inherited from + * the gpg4usb project, which is under GPL-3.0-or-later. + * + * All the source code of GpgFrontend was modified and released by + * Saturneric <[email protected]> starting on May 12, 2021. + * + * SPDX-License-Identifier: GPL-3.0-or-later + * + */ + +#pragma once + +#include "core/module/GlobalRegisterTable.h" + +namespace GpgFrontend::Module { +class GPGFRONTEND_CORE_EXPORT GlobalRegisterTableTreeModel + : public QAbstractItemModel { + public: + explicit GlobalRegisterTableTreeModel(GlobalRegisterTable *grt); + + [[nodiscard]] auto rowCount(const QModelIndex &parent) const -> int override; + + [[nodiscard]] auto columnCount(const QModelIndex &parent) const + -> int override; + + [[nodiscard]] auto data(const QModelIndex &index, int role) const + -> QVariant override; + + [[nodiscard]] auto index(int row, int column, const QModelIndex &parent) const + -> QModelIndex override; + + [[nodiscard]] auto parent(const QModelIndex &index) const + -> QModelIndex override; + + [[nodiscard]] auto headerData(int section, Qt::Orientation orientation, + int role) const -> QVariant override; + + private: + class Impl; + SecureUniquePtr<Impl> p_; +}; + +}; // namespace GpgFrontend::Module
\ No newline at end of file diff --git a/src/core/module/ModuleManager.cpp b/src/core/module/ModuleManager.cpp index 6da48eec..e00c8c8c 100644 --- a/src/core/module/ModuleManager.cpp +++ b/src/core/module/ModuleManager.cpp @@ -196,6 +196,8 @@ class ModuleManager::Impl { return gmc_->IsModuleActivated(id); } + auto GRT() -> GlobalRegisterTable* { return grt_.get(); } + private: static ModuleMangerPtr global_module_manager; SecureUniquePtr<GlobalModuleContext> gmc_; @@ -299,4 +301,7 @@ auto ModuleManager::IsModuleActivated(ModuleIdentifier id) -> bool { auto ModuleManager::ListAllRegisteredModuleID() -> QList<ModuleIdentifier> { return p_->ListAllRegisteredModuleID(); }; + +auto ModuleManager::GRT() -> GlobalRegisterTable* { return p_->GRT(); } + } // namespace GpgFrontend::Module
\ No newline at end of file diff --git a/src/core/module/ModuleManager.h b/src/core/module/ModuleManager.h index d5cd8387..fa8d2264 100644 --- a/src/core/module/ModuleManager.h +++ b/src/core/module/ModuleManager.h @@ -48,6 +48,7 @@ class Event; class Module; class GlobalModuleContext; class ModuleManager; +class GlobalRegisterTable; using EventRefrernce = std::shared_ptr<Event>; using ModuleIdentifier = QString; @@ -97,6 +98,8 @@ class GPGFRONTEND_CORE_EXPORT ModuleManager auto ListRTChildKeys(const QString&, const QString&) -> std::vector<Key>; + auto GRT() -> GlobalRegisterTable*; + private: class Impl; SecureUniquePtr<Impl> p_; diff --git a/src/module/integrated/gnupg_info_gathering_module/CMakeLists.txt b/src/module/integrated/gnupg_info_gathering_module/CMakeLists.txt index 21219031..3f1645eb 100644 --- a/src/module/integrated/gnupg_info_gathering_module/CMakeLists.txt +++ b/src/module/integrated/gnupg_info_gathering_module/CMakeLists.txt @@ -60,8 +60,6 @@ target_link_libraries(gpgfrontend_gnupg_info_gathering PRIVATE Qt6::Core) - - # property set_property(TARGET gpgfrontend_gnupg_info_gathering PROPERTY AUTOMOC ON) diff --git a/src/module/integrated/gnupg_info_gathering_module/GnuPGInfoGatheringModule.cpp b/src/module/integrated/gnupg_info_gathering_module/GnuPGInfoGatheringModule.cpp index e4c30164..3965c661 100644 --- a/src/module/integrated/gnupg_info_gathering_module/GnuPGInfoGatheringModule.cpp +++ b/src/module/integrated/gnupg_info_gathering_module/GnuPGInfoGatheringModule.cpp @@ -99,8 +99,7 @@ auto GFGetModuleQtEnvVersion() -> const char * { } auto GFGetModuleID() -> const char * { - return GFModuleStrDup( - "com.bktus.gpgfrontend.module.integrated.gnupg_info_gathering"); + return GFModuleStrDup("com.bktus.gpgfrontend.module.gnupg_info_gathering"); } auto GFGetModuleVersion() -> const char * { return GFModuleStrDup("1.0.0"); } @@ -110,6 +109,12 @@ auto GFGetModuleMetaData() -> GFModuleMetaData * { GFAllocateMemory(sizeof(GFModuleMetaData))); auto *h_meta = p_meta; + p_meta->key = "Name"; + p_meta->value = "GatherGnupgInfo"; + p_meta->next = static_cast<GFModuleMetaData *>( + GFAllocateMemory(sizeof(GFModuleMetaData))); + p_meta = p_meta->next; + p_meta->key = "Description"; p_meta->value = "Try gathering gnupg informations"; p_meta->next = static_cast<GFModuleMetaData *>( @@ -200,21 +205,20 @@ auto GFExecuteModule(GFModuleEvent *event) -> int { continue; } - auto context = Context{gpgme_version, gpgconf_path, component_info}; - + auto *context = new Context{gpgme_version, gpgconf_path, component_info}; const char **argv_0 = static_cast<const char **>(GFAllocateMemory(sizeof(const char *) * 2)); argv_0[0] = GFModuleStrDup("--list-options"), argv_0[1] = GFModuleStrDup(component_info.name.toUtf8()); exec_contexts.push_back( - {gpgconf_path, 2, argv_0, GetGpgDirectoryInfos, &context}); + {gpgconf_path, 2, argv_0, GetGpgOptionInfos, context}); } GFExecuteCommandBatchSync(static_cast<int32_t>(exec_contexts.size()), exec_contexts.constData()); GFModuleUpsertRTValueBool(GFGetModuleID(), - GFModuleStrDup("gnupg.gathering_done"), 0); + GFModuleStrDup("gnupg.gathering_done"), 1); char **event_argv = static_cast<char **>(GFAllocateMemory(sizeof(char **) * 1)); @@ -443,11 +447,12 @@ void GetGpgOptionInfos(void *data, int exit_code, const char *out, auto p_out = QString::fromUtf8(out); auto p_err = QString::fromUtf8(err); auto *context = reinterpret_cast<Context *>(data); + auto component_name = context->component_info.name; GFModuleLogDebug( fmt::format("gpgconf {} avaliable options exit_code: {} process stdout " "size: {} ", - context->component_info.name, exit_code, p_out.size()) + component_name, exit_code, p_out.size()) .c_str()); std::vector<GpgOptionsInfo> options_infos; @@ -459,7 +464,7 @@ void GetGpgOptionInfos(void *data, int exit_code, const char *out, GFModuleLogDebug( fmt::format("component {} avaliable options line: {} info size: {}", - context->component_info.name, line, info_split_list.size()) + component_name, line, info_split_list.size()) .c_str()); if (info_split_list.size() < 10) continue; @@ -494,10 +499,12 @@ void GetGpgOptionInfos(void *data, int exit_code, const char *out, GFModuleUpsertRTValue( GFGetModuleID(), GFModuleStrDup(QString("gnupg.components.%1.options.%2") - .arg(context->component_info.name) + .arg(component_name) .arg(option_name) .toUtf8()), GFModuleStrDup(QJsonDocument(jsonlized_option_info).toJson())); options_infos.push_back(info); } + + GFFreeMemory(context); } diff --git a/src/module/integrated/version_checking_module/VersionCheckingModule.cpp b/src/module/integrated/version_checking_module/VersionCheckingModule.cpp index 0db00485..35d3b82e 100644 --- a/src/module/integrated/version_checking_module/VersionCheckingModule.cpp +++ b/src/module/integrated/version_checking_module/VersionCheckingModule.cpp @@ -51,8 +51,7 @@ auto GFGetModuleQtEnvVersion() -> const char* { } auto GFGetModuleID() -> const char* { - return GFModuleStrDup( - "com.bktus.gpgfrontend.module.integrated.version_checking"); + return GFModuleStrDup("com.bktus.gpgfrontend.module.version_checking"); } auto GFGetModuleVersion() -> const char* { return GFModuleStrDup("1.0.0"); } @@ -62,11 +61,18 @@ auto GFGetModuleMetaData() -> GFModuleMetaData* { GFAllocateMemory(sizeof(GFModuleMetaData))); auto* h_meta = p_meta; + p_meta->key = "Name"; + p_meta->value = "VersionChecking"; + p_meta->next = static_cast<GFModuleMetaData*>( + GFAllocateMemory(sizeof(GFModuleMetaData))); + p_meta = p_meta->next; + p_meta->key = "Description"; p_meta->value = "Try checking gpgfrontend version"; p_meta->next = static_cast<GFModuleMetaData*>( GFAllocateMemory(sizeof(GFModuleMetaData))); p_meta = p_meta->next; + p_meta->key = "Author"; p_meta->value = "Saturneric"; p_meta->next = nullptr; diff --git a/src/ui/dialog/help/AboutDialog.cpp b/src/ui/dialog/help/AboutDialog.cpp index 260cd5a7..ddc17fe7 100644 --- a/src/ui/dialog/help/AboutDialog.cpp +++ b/src/ui/dialog/help/AboutDialog.cpp @@ -36,9 +36,6 @@ namespace GpgFrontend::UI { -const QString kVersionCheckingModuleID = - "com.bktus.gpgfrontend.module.integrated.version_checking"; - AboutDialog::AboutDialog(const QString& default_tab_name, QWidget* parent) : GeneralDialog(typeid(AboutDialog).name(), parent) { this->setWindowTitle(tr("About") + " " + qApp->applicationName()); @@ -49,8 +46,7 @@ AboutDialog::AboutDialog(const QString& default_tab_name, QWidget* parent) tab_widget->addTab(info_tab, tr("About GpgFrontend")); - if (Module::IsModuleActivate( - "com.bktus.gpgfrontend.module.integrated.gnupg_info_gathering")) { + if (Module::IsModuleActivate(kGnuPGInfoGatheringModuleID)) { auto* gnupg_tab = new GnupgTab(); tab_widget->addTab(gnupg_tab, tr("GnuPG")); } diff --git a/src/ui/dialog/help/GnupgTab.cpp b/src/ui/dialog/help/GnupgTab.cpp index 7722960d..3dfdd994 100644 --- a/src/ui/dialog/help/GnupgTab.cpp +++ b/src/ui/dialog/help/GnupgTab.cpp @@ -37,9 +37,6 @@ 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>()) { @@ -134,11 +131,11 @@ void GnupgTab::process_software_info() { for (auto& component : components) { auto component_info_json_bytes = Module::RetrieveRTValueTypedOrDefault( kGnuPGInfoGatheringModuleID, - QString("gnupg.components.%1").arg(component), QByteArray{}); + QString("gnupg.components.%1").arg(component), QString{}); GF_UI_LOG_DEBUG("got gnupg component {} info from rt", component); auto component_info_json = - QJsonDocument::fromJson(component_info_json_bytes); + QJsonDocument::fromJson(component_info_json_bytes.toUtf8()); if (!component_info_json.isObject()) { GF_UI_LOG_WARN("illegal gnupg component info, json: {}", QString(component_info_json_bytes)); @@ -214,11 +211,12 @@ void GnupgTab::process_software_info() { for (auto& option : options) { const auto option_info_json = QJsonDocument::fromJson(Module::RetrieveRTValueTypedOrDefault( - kGnuPGInfoGatheringModuleID, - QString("gnupg.components.%1.options.%2") - .arg(component) - .arg(option), - QByteArray{})); + kGnuPGInfoGatheringModuleID, + QString("gnupg.components.%1.options.%2") + .arg(component) + .arg(option), + QString{}) + .toUtf8()); if (!option_info_json.isObject()) continue; @@ -243,11 +241,12 @@ void GnupgTab::process_software_info() { auto option_info_json_bytes = Module::RetrieveRTValueTypedOrDefault( kGnuPGInfoGatheringModuleID, QString("gnupg.components.%1.options.%2").arg(component).arg(option), - QByteArray{}); + QString{}); GF_UI_LOG_DEBUG("got gnupg component's option {} info from rt, info: {}", component, option_info_json_bytes); - auto option_info_json = QJsonDocument::fromJson(option_info_json_bytes); + auto option_info_json = + QJsonDocument::fromJson(option_info_json_bytes.toUtf8()); if (!option_info_json.isObject()) { GF_UI_LOG_WARN("illegal gnupg option info, json: {}", diff --git a/src/ui/main_window/MainWindow.cpp b/src/ui/main_window/MainWindow.cpp index fec7f6bf..e1c355c4 100644 --- a/src/ui/main_window/MainWindow.cpp +++ b/src/ui/main_window/MainWindow.cpp @@ -131,8 +131,7 @@ void MainWindow::Init() noexcept { edit_->CurTextPage()->setFocus(); Module::ListenRTPublishEvent( - this, "com.bktus.gpgfrontend.module.integrated.version_checking", - "version.loading_done", + this, kVersionCheckingModuleID, "version.loading_done", [=](Module::Namespace, Module::Key, int, std::any) { GF_UI_LOG_DEBUG( "versionchecking version.loading_done changed, calling slot " diff --git a/src/ui/main_window/MainWindowSlotFunction.cpp b/src/ui/main_window/MainWindowSlotFunction.cpp index e75e20bc..4a95d450 100644 --- a/src/ui/main_window/MainWindowSlotFunction.cpp +++ b/src/ui/main_window/MainWindowSlotFunction.cpp @@ -266,8 +266,7 @@ void MainWindow::slot_version_upgrade_nofity() { GF_UI_LOG_DEBUG( "slot version upgrade notify called, checking version info from rt..."); auto is_loading_done = Module::RetrieveRTValueTypedOrDefault<>( - "com.bktus.gpgfrontend.module.integrated.version_checking", - "version.loading_done", false); + kVersionCheckingModuleID, "version.loading_done", false); GF_UI_LOG_DEBUG("checking version info from rt, is loading done state: {}", is_loading_done); @@ -277,20 +276,16 @@ void MainWindow::slot_version_upgrade_nofity() { } auto is_need_upgrade = Module::RetrieveRTValueTypedOrDefault<>( - "com.bktus.gpgfrontend.module.integrated.version_checking", - "version.need_upgrade", false); + kVersionCheckingModuleID, "version.need_upgrade", false); auto is_current_a_withdrawn_version = Module::RetrieveRTValueTypedOrDefault<>( - "com.bktus.gpgfrontend.module.integrated.version_checking", - "version.current_a_withdrawn_version", false); + kVersionCheckingModuleID, "version.current_a_withdrawn_version", false); auto is_current_version_released = Module::RetrieveRTValueTypedOrDefault<>( - "com.bktus.gpgfrontend.module.integrated.version_checking", - "version.current_version_released", false); + kVersionCheckingModuleID, "version.current_version_released", false); auto latest_version = Module::RetrieveRTValueTypedOrDefault<>( - "com.bktus.gpgfrontend.module.integrated.version_checking", - "version.latest_version", QString{}); + kVersionCheckingModuleID, "version.latest_version", QString{}); GF_UI_LOG_DEBUG( "got version info from rt, need upgrade: {}, with drawn: {}, " diff --git a/src/ui/main_window/MainWindowUI.cpp b/src/ui/main_window/MainWindowUI.cpp index 0f8dfdb8..475eed0e 100644 --- a/src/ui/main_window/MainWindowUI.cpp +++ b/src/ui/main_window/MainWindowUI.cpp @@ -421,8 +421,7 @@ void MainWindow::create_actions() { connect(about_act_, &QAction::triggered, this, [=]() { new AboutDialog(0, this); }); - if (Module::IsModuleActivate( - "com.bktus.gpgfrontend.module.integrated.gnupg_info_gathering")) { + if (Module::IsModuleActivate(kGnuPGInfoGatheringModuleID)) { gnupg_act_ = new QAction(tr("GnuPG"), this); gnupg_act_->setIcon(QIcon(":/icons/help.png")); gnupg_act_->setToolTip(tr("Information about Gnupg")); @@ -436,8 +435,7 @@ void MainWindow::create_actions() { connect(translate_act_, &QAction::triggered, this, [=]() { new AboutDialog(tr("Translators"), this); }); - if (Module::IsModuleActivate( - "com.bktus.gpgfrontend.module.integrated.version_checking")) { + if (Module::IsModuleActivate(kVersionCheckingModuleID)) { check_update_act_ = new QAction(tr("Check for Updates"), this); check_update_act_->setIcon(QIcon(":/icons/help.png")); check_update_act_->setToolTip(tr("Check for updates")); diff --git a/src/ui/widgets/GRTTreeView.cpp b/src/ui/widgets/GRTTreeView.cpp new file mode 100644 index 00000000..f2ae42c2 --- /dev/null +++ b/src/ui/widgets/GRTTreeView.cpp @@ -0,0 +1,42 @@ +/** + * Copyright (C) 2021 Saturneric <[email protected]> + * + * This file is part of GpgFrontend. + * + * GpgFrontend is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GpgFrontend is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GpgFrontend. If not, see <https://www.gnu.org/licenses/>. + * + * The initial version of the source code is inherited from + * the gpg4usb project, which is under GPL-3.0-or-later. + * + * All the source code of GpgFrontend was modified and released by + * Saturneric <[email protected]> starting on May 12, 2021. + * + * SPDX-License-Identifier: GPL-3.0-or-later + * + */ + +#include "GRTTreeView.h" + +#include "core/module/GlobalRegisterTableTreeModel.h" +#include "core/module/ModuleManager.h" + +namespace GpgFrontend::UI { + +GRTTreeView::GRTTreeView(QWidget *parent) : QTreeView(parent) { + setModel(new Module::GlobalRegisterTableTreeModel( + Module::ModuleManager::GetInstance().GRT())); +} + +GRTTreeView::~GRTTreeView() = default; +} // namespace GpgFrontend::UI
\ No newline at end of file diff --git a/src/ui/widgets/GRTTreeView.h b/src/ui/widgets/GRTTreeView.h new file mode 100644 index 00000000..e730b698 --- /dev/null +++ b/src/ui/widgets/GRTTreeView.h @@ -0,0 +1,41 @@ +/** + * Copyright (C) 2021 Saturneric <[email protected]> + * + * This file is part of GpgFrontend. + * + * GpgFrontend is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GpgFrontend is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GpgFrontend. If not, see <https://www.gnu.org/licenses/>. + * + * The initial version of the source code is inherited from + * the gpg4usb project, which is under GPL-3.0-or-later. + * + * All the source code of GpgFrontend was modified and released by + * Saturneric <[email protected]> starting on May 12, 2021. + * + * SPDX-License-Identifier: GPL-3.0-or-later + * + */ + +#pragma once + +namespace GpgFrontend::UI { + +class GRTTreeView : public QTreeView { + Q_OBJECT + public: + explicit GRTTreeView(QWidget *parent); + + virtual ~GRTTreeView() override; +}; + +} // namespace GpgFrontend::UI
\ No newline at end of file |