From 46b7ecec8f5787d3a4b14a2fd2ec4f324a041345 Mon Sep 17 00:00:00 2001 From: saturneric Date: Wed, 24 Jul 2024 16:02:49 +0200 Subject: [PATCH] feat: move in GnuPGTab --- include/GFModuleCommonUtils.hpp | 45 ++- src/m_gpg_info/CMakeLists.txt | 18 +- src/m_gpg_info/GnuPGInfo.ui | 163 +++++++++ src/m_gpg_info/GnuPGInfoGatheringModule.cpp | 176 ++++------ src/m_gpg_info/GnuPGInfoGatheringModule.h | 2 +- src/m_gpg_info/GnupgTab.cpp | 330 ++++++++++++++++++ src/m_gpg_info/GnupgTab.h | 63 ++++ .../ts/ModuleGnuPGInfoGathering.de_DE.ts | 3 + .../ts/ModuleGnuPGInfoGathering.en_US.ts | 3 + .../ts/ModuleGnuPGInfoGathering.fr_FR.ts | 3 + .../ts/ModuleGnuPGInfoGathering.zh_CN.ts | 3 + src/m_ver_check/UpdateTab.cpp | 11 +- 12 files changed, 707 insertions(+), 113 deletions(-) create mode 100644 src/m_gpg_info/GnuPGInfo.ui create mode 100644 src/m_gpg_info/GnupgTab.cpp create mode 100644 src/m_gpg_info/GnupgTab.h create mode 100644 src/m_gpg_info/ts/ModuleGnuPGInfoGathering.de_DE.ts create mode 100644 src/m_gpg_info/ts/ModuleGnuPGInfoGathering.en_US.ts create mode 100644 src/m_gpg_info/ts/ModuleGnuPGInfoGathering.fr_FR.ts create mode 100644 src/m_gpg_info/ts/ModuleGnuPGInfoGathering.zh_CN.ts diff --git a/include/GFModuleCommonUtils.hpp b/include/GFModuleCommonUtils.hpp index c318a1c..a300ddc 100644 --- a/include/GFModuleCommonUtils.hpp +++ b/include/GFModuleCommonUtils.hpp @@ -39,6 +39,8 @@ #include "GFSDKModule.h" #define DUP(v) GFModuleStrDup(v) +#define UDUP(v) UnStrDup(v) +#define QDUP(v) QStrDup(v) inline void MLogDebug(const QString& s) { GFModuleLogDebug(s.toUtf8()); } inline void MLogInfo(const QString& s) { GFModuleLogInfo(s.toUtf8()); } @@ -52,7 +54,16 @@ inline void MLogError(const QString& s) { GFModuleLogError(s.toUtf8()); } #define MLogErrorS(format, ...) \ MLogError(QString::asprintf(format, __VA_ARGS__)) -auto QMapToMetaDataArray(const QMap& map) -> MetaData** { +inline auto QStrDup(QString str) -> char* { return DUP(str.toUtf8()); } + +inline auto UnStrDup(const char* src) -> QString { + auto qt_str = QString::fromUtf8(src); + GFFreeMemory(static_cast(const_cast(src))); + return qt_str; +} + +inline auto QMapToMetaDataArray(const QMap& map) + -> MetaData** { auto** meta_data_array = static_cast(GFAllocateMemory(sizeof(MetaData*) * map.size())); @@ -74,7 +85,7 @@ auto QMapToMetaDataArray(const QMap& map) -> MetaData** { return meta_data_array; } -auto QMapToGFModuleMetaDataList(const QMap& map) +inline auto QMapToGFModuleMetaDataList(const QMap& map) -> GFModuleMetaData* { GFModuleMetaData* head = nullptr; GFModuleMetaData* tail = nullptr; @@ -105,8 +116,36 @@ auto QMapToGFModuleMetaDataList(const QMap& map) return head; } -auto AllocBufferAndCopy(const QByteArray& b) -> char* { +inline auto AllocBufferAndCopy(const QByteArray& b) -> char* { auto* p = static_cast(GFAllocateMemory(sizeof(char) * b.size())); memcpy(p, b.constData(), b.size()); return p; } + +template +auto SecureCreateSharedObject(Args&&... args) -> std::shared_ptr { + void* mem = GFAllocateMemory(sizeof(T)); + if (!mem) throw std::bad_alloc(); + + try { + T* obj = new (mem) T(std::forward(args)...); + return std::shared_ptr(obj, [](T* ptr) { + ptr->~T(); + GFFreeMemory(ptr); + }); + } catch (...) { + GFFreeMemory(mem); + throw; + } +} + +inline auto CharArrayToQStringList(char** pl_components, int size) + -> QStringList { + QStringList list; + for (int i = 0; i < size; ++i) { + list.append(QString::fromUtf8(pl_components[i])); + GFFreeMemory(pl_components[i]); + } + GFFreeMemory(pl_components); + return list; +} \ No newline at end of file diff --git a/src/m_gpg_info/CMakeLists.txt b/src/m_gpg_info/CMakeLists.txt index 1d96a5a..6fa5db8 100644 --- a/src/m_gpg_info/CMakeLists.txt +++ b/src/m_gpg_info/CMakeLists.txt @@ -43,14 +43,26 @@ target_link_libraries(mod_gpg_info PRIVATE if(GPGFRONTEND_QT5_BUILD) # link Qt core - target_link_libraries(mod_gpg_info PRIVATE Qt5::Core) + target_link_libraries(mod_gpg_info PRIVATE Qt5::Core Qt5::Widgets) else() # link Qt core - target_link_libraries(mod_gpg_info PRIVATE Qt6::Core) + target_link_libraries(mod_gpg_info PRIVATE Qt6::Core Qt6::Widgets) endif() # using std c++ 17 target_compile_features(mod_gpg_info PRIVATE cxx_std_17) # ui -set(CMAKE_AUTOUIC_SEARCH_PATHS ${CMAKE_AUTOUIC_SEARCH_PATHS} ${CMAKE_CURRENT_SOURCE_DIR}/ui) \ No newline at end of file +set(CMAKE_AUTOUIC_SEARCH_PATHS ${CMAKE_AUTOUIC_SEARCH_PATHS} ${CMAKE_CURRENT_SOURCE_DIR}/ui) + +# i18n +set(LOCALE_TS_PATH ${CMAKE_CURRENT_SOURCE_DIR}/ts) +set(TS_FILES "${LOCALE_TS_PATH}/ModuleGnuPGInfoGathering.en_US.ts" + "${LOCALE_TS_PATH}/ModuleGnuPGInfoGathering.de_DE.ts" + "${LOCALE_TS_PATH}/ModuleGnuPGInfoGathering.fr_FR.ts" + "${LOCALE_TS_PATH}/ModuleGnuPGInfoGathering.zh_CN.ts") +qt_add_translations(mod_gpg_info + RESOURCE_PREFIX "/i18n" + TS_FILES ${TS_FILES} + SOURCES ${MODULE_SOURCE_FILES} + INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR}) \ No newline at end of file diff --git a/src/m_gpg_info/GnuPGInfo.ui b/src/m_gpg_info/GnuPGInfo.ui new file mode 100644 index 0000000..63e746a --- /dev/null +++ b/src/m_gpg_info/GnuPGInfo.ui @@ -0,0 +1,163 @@ + + + GnuPGInfo + + + + 0 + 0 + 535 + 568 + + + + GnuPG Info + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + + + + :/icons/gnupg.png + + + Qt::AlignCenter + + + 10 + + + + + + + Version + + + Qt::AlignCenter + + + 5 + + + + + + + + 0 + 0 + + + + Qt::Horizontal + + + + + + + QTabWidget::Rounded + + + 0 + + + false + + + + Components + + + + + + QAbstractScrollArea::AdjustToContents + + + 16 + + + QAbstractItemView::NoEditTriggers + + + + + + + 0 + + + -1 + + + false + + + + + + + + Directories + + + + + + QAbstractScrollArea::AdjustToContents + + + QAbstractItemView::NoEditTriggers + + + + + + + + Options + + + + + + + + + + + + + + + + + + diff --git a/src/m_gpg_info/GnuPGInfoGatheringModule.cpp b/src/m_gpg_info/GnuPGInfoGatheringModule.cpp index 8d400c8..d30a9cc 100644 --- a/src/m_gpg_info/GnuPGInfoGatheringModule.cpp +++ b/src/m_gpg_info/GnuPGInfoGatheringModule.cpp @@ -34,6 +34,7 @@ #include // qt +#include #include #include #include @@ -42,41 +43,11 @@ // c++ #include +#include "GFModuleCommonUtils.hpp" #include "GpgInfo.h" -template <> -struct fmt::formatter { - // Parses format specifications. - constexpr auto parse(format_parse_context &ctx) -> decltype(ctx.begin()) { - return ctx.begin(); - } - - // Formats the QString qstr and writes it to the output. - template - auto format(const QString &qstr, FormatContext &ctx) const - -> decltype(ctx.out()) { - // Convert QString to UTF-8 QString (to handle Unicode characters - // correctly) - QByteArray utf8_array = qstr.toUtf8(); - return fmt::format_to(ctx.out(), "{}", utf8_array.constData()); - } -}; - -template <> -struct fmt::formatter { - // Parses format specifications. - constexpr auto parse(format_parse_context &ctx) -> decltype(ctx.begin()) { - return ctx.begin(); - } - - // Formats the QString qstr and writes it to the output. - template - auto format(const QByteArray &qarray, FormatContext &ctx) const - -> decltype(ctx.out()) { - // Convert QString to UTF-8 QString (to handle Unicode characters - // correctly) - return fmt::format_to(ctx.out(), "{}", qarray.constData()); - } +class GTrC { + Q_DECLARE_TR_FUNCTIONS(GTrC) }; extern auto CalculateBinaryChacksum(const QString &path) @@ -88,6 +59,10 @@ extern void GetGpgDirectoryInfos(void *, int, const char *, const char *); extern void GetGpgOptionInfos(void *, int, const char *, const char *); +extern auto StartGatheringGnuPGInfo() -> int; + +extern auto GnupgTabFactory(const char *id) -> void *; + using Context = struct { QString gpgme_version; QString gpgconf_path; @@ -133,6 +108,11 @@ auto GFGetModuleMetaData() -> GFModuleMetaData * { auto GFRegisterModule() -> int { GFModuleLogDebug("gnupg info gathering module registering"); + + GFUIMountEntry(DUP("AboutDialogTabs"), + QMapToMetaDataArray({{"TabTitle", GTrC::tr("GnuPG")}}), 1, + GnupgTabFactory); + return 0; } @@ -144,24 +124,40 @@ auto GFActiveModule() -> int { } auto GFExecuteModule(GFModuleEvent *event) -> int { - GFModuleLogDebug( - fmt::format("gnupg info gathering module executing, event id: {}", - event->id) - .c_str()); + MLogDebug(QString("gnupg info gathering module executing, event id: %1") + .arg(event->id)); + StartGatheringGnuPGInfo(); + + char **event_argv = + static_cast(GFAllocateMemory(sizeof(char **) * 1)); + event_argv[0] = GFModuleStrDup("0"); + + GFModuleTriggerModuleEventCallback(event, GFGetModuleID(), 1, event_argv); + + GFModuleLogDebug("gnupg external info gathering done"); + return 0; +} + +auto GFDeactiveModule() -> int { return 0; } + +auto GFUnregisterModule() -> int { + GFModuleLogDebug("gnupg info gathering module unregistering"); + return 0; +} + +auto StartGatheringGnuPGInfo() -> int { GFModuleLogDebug("start to load extra info at module gnupginfogathering..."); const auto *const gpgme_version = GFModuleRetrieveRTValueOrDefault( GFModuleStrDup("core"), GFModuleStrDup("gpgme.version"), GFModuleStrDup("0.0.0")); - GFModuleLogDebug( - fmt::format("got gpgme version from rt: {}", gpgme_version).c_str()); + MLogDebug(QString("got gpgme version from rt: %1").arg(gpgme_version)); const auto *const gpgconf_path = GFModuleRetrieveRTValueOrDefault( GFModuleStrDup("core"), GFModuleStrDup("gpgme.ctx.gpgconf_path"), GFModuleStrDup("")); - GFModuleLogDebug( - fmt::format("got gpgconf path from rt: {}", gpgconf_path).c_str()); + MLogDebug(QString("got gpgconf path from rt: %1").arg(gpgconf_path)); auto context = Context{gpgme_version, gpgconf_path}; @@ -205,10 +201,8 @@ auto GFExecuteModule(GFModuleEvent *event) -> int { assert(jsonlized_component_info.isObject()); auto component_info = GpgComponentInfo(jsonlized_component_info.object()); - GFModuleLogDebug(fmt::format("gpgconf check options ready, " - "component: {}", - component_info.name) - .c_str()); + MLogDebug(QString("gpgconf check options ready, component: %1") + .arg(component_info.name)); if (component_info.name == "gpgme" || component_info.name == "gpgconf") { continue; @@ -230,40 +224,25 @@ auto GFExecuteModule(GFModuleEvent *event) -> int { GFModuleUpsertRTValueBool(GFGetModuleID(), GFModuleStrDup("gnupg.gathering_done"), 1); - char **event_argv = - static_cast(GFAllocateMemory(sizeof(char **) * 1)); - event_argv[0] = GFModuleStrDup("0"); - - GFModuleTriggerModuleEventCallback(event, GFGetModuleID(), 1, event_argv); - - GFModuleLogDebug("gnupg external info gathering done"); - return 0; -} - -auto GFDeactiveModule() -> int { return 0; } - -auto GFUnregisterModule() -> int { - GFModuleLogDebug("gnupg info gathering module unregistering"); return 0; } auto CalculateBinaryChacksum(const QString &path) -> std::optional { // check file info and access rights - QFileInfo info(path); + QFileInfo const info(path); if (!info.exists() || !info.isFile() || !info.isReadable()) { - GFModuleLogError(fmt::format("get info for file {} error, exists: {}", - info.filePath(), info.exists()) - .c_str()); + MLogDebug(QString("get info for file %1 error, exists: %2") + .arg(info.filePath()) + .arg(info.exists())); return {}; } // open and read file QFile f(info.filePath()); if (!f.open(QIODevice::ReadOnly)) { - GFModuleLogError(fmt::format("open {} to calculate checksum error: {}", - path.toStdString(), - f.errorString().toStdString()) - .c_str()); + MLogDebug(QString("open %1 to calculate checksum error: %2") + .arg(path) + .arg(f.errorString())); return {}; } @@ -274,10 +253,8 @@ auto CalculateBinaryChacksum(const QString &path) -> std::optional { while (!f.atEnd()) { QByteArray const buffer = f.read(buffer_size); if (buffer.isEmpty()) { - GFModuleLogError(fmt::format("error reading file {} during " - "checksum calculation", - path.toStdString()) - .c_str()); + MLogDebug(QString("error reading file %1 during checksum calculation") + .arg(path)); return {}; } hash_sha.addData(buffer); @@ -297,17 +274,15 @@ void GetGpgComponentInfos(void *data, int exit_code, const char *out, auto p_out = QString::fromUtf8(out); auto p_err = QString::fromUtf8(err); - GFModuleLogDebug(fmt::format("gpgconf components exit_code: {} " - "process stdout size: {}", - exit_code, p_out.size()) - .c_str()); + MLogDebug(QString("gpgconf components exit_code: %1 process stdout size: %2") + .arg(exit_code) + .arg(p_out.size())); if (exit_code != 0) { - GFModuleLogError(fmt::format("gpgconf execute error, process " - "stderr: {}, " - "process stdout: {}", - p_err, p_out) - .c_str()); + MLogDebug( + QString("gpgconf execute error, process stderr: %1, process stdout: %2") + .arg(p_err) + .arg(p_out)); return; } @@ -360,13 +335,12 @@ void GetGpgComponentInfos(void *data, int exit_code, const char *out, auto binary_checksum = CalculateBinaryChacksum(component_path); - GFModuleLogDebug( - fmt::format("gnupg component name: {} desc: " - "{} checksum: {} path: {} ", - component_name, component_desc, - binary_checksum.has_value() ? binary_checksum.value() : "/", - component_path) - .c_str()); + MLogDebug( + QString("gnupg component name: %1 desc: %2 checksum: %3 path: %4") + .arg(component_name) + .arg(component_desc) + .arg(binary_checksum.has_value() ? binary_checksum.value() : "/", + component_path)); QString version = "/"; @@ -425,10 +399,9 @@ void GetGpgDirectoryInfos(void *, int exit_code, const char *out, for (const auto &line : line_split_list) { auto info_split_list = line.split(":"); - GFModuleLogDebug(fmt::format("gpgconf direcrotries info line: " - "{} info size: {}", - line, info_split_list.size()) - .c_str()); + MLogDebug(QString("gpgconf direcrotries info line: %1 info size: %2") + .arg(line) + .arg(info_split_list.size())); if (info_split_list.size() != 2) continue; @@ -464,11 +437,12 @@ void GetGpgOptionInfos(void *data, int exit_code, const char *out, auto *context = reinterpret_cast(data); auto component_name = context->component_info.name; - GFModuleLogDebug(fmt::format("gpgconf {} avaliable options " - "exit_code: {} process stdout " - "size: {} ", - component_name, exit_code, p_out.size()) - .c_str()); + MLogDebug( + QString( + "gpgconf %1 avaliable options exit_code: %2 process stdout size: %3") + .arg(component_name) + .arg(exit_code) + .arg(p_out.size())); std::vector options_infos; @@ -477,10 +451,10 @@ void GetGpgOptionInfos(void *data, int exit_code, const char *out, for (const auto &line : line_split_list) { auto info_split_list = line.split(":"); - GFModuleLogDebug(fmt::format("component {} avaliable options " - "line: {} info size: {}", - component_name, line, info_split_list.size()) - .c_str()); + MLogDebug(QString("component %1 available options line: %2 info size: %3") + .arg(component_name) + .arg(line) + .arg(info_split_list.size())); if (info_split_list.size() < 10) continue; @@ -523,4 +497,4 @@ void GetGpgOptionInfos(void *data, int exit_code, const char *out, context->~Context(); GFFreeMemory(context); -} +} \ No newline at end of file diff --git a/src/m_gpg_info/GnuPGInfoGatheringModule.h b/src/m_gpg_info/GnuPGInfoGatheringModule.h index 35ee4ac..b8b73d0 100644 --- a/src/m_gpg_info/GnuPGInfoGatheringModule.h +++ b/src/m_gpg_info/GnuPGInfoGatheringModule.h @@ -53,4 +53,4 @@ auto GF_MODULE_EXPORT GFExecuteModule(GFModuleEvent *) -> int; auto GF_MODULE_EXPORT GFDeactiveModule() -> int; auto GF_MODULE_EXPORT GFUnregisterModule() -> int; -}; +}; \ No newline at end of file diff --git a/src/m_gpg_info/GnupgTab.cpp b/src/m_gpg_info/GnupgTab.cpp new file mode 100644 index 0000000..1317139 --- /dev/null +++ b/src/m_gpg_info/GnupgTab.cpp @@ -0,0 +1,330 @@ +/** + * Copyright (C) 2021 Saturneric + * + * 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 . + * + * 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 starting on May 12, 2021. + * + * SPDX-License-Identifier: GPL-3.0-or-later + * + */ + +// +// Created by eric on 2022/7/23. +// + +#include "GnupgTab.h" + +#include "GFModuleCommonUtils.hpp" +#include "GFSDKModule.h" +#include "GnuPGInfoGatheringModule.h" +#include "ui_GnuPGInfo.h" + +extern auto StartGatheringGnuPGInfo() -> int; + +GnupgTab::GnupgTab(QWidget* parent) + : QWidget(parent), ui_(SecureCreateSharedObject()) { + ui_->setupUi(this); + + QStringList components_column_titles; + components_column_titles << tr("Name") << tr("Description") << tr("Version") + << tr("Checksum") << tr("Binary Path"); + + ui_->tabWidget->setTabText(0, tr("Components")); + ui_->tabWidget->setTabText(1, tr("Directories")); + ui_->tabWidget->setTabText(2, tr("Options")); + + ui_->componentDetailsTable->setColumnCount(components_column_titles.length()); + ui_->componentDetailsTable->setHorizontalHeaderLabels( + components_column_titles); + ui_->componentDetailsTable->horizontalHeader()->setStretchLastSection(false); + ui_->componentDetailsTable->setSelectionBehavior( + QAbstractItemView::SelectRows); + + // table items not editable + ui_->componentDetailsTable->setEditTriggers( + QAbstractItemView::NoEditTriggers); + + // no focus (rectangle around table items) + // may be it should focus on whole row + ui_->componentDetailsTable->setFocusPolicy(Qt::NoFocus); + ui_->componentDetailsTable->setAlternatingRowColors(true); + + QStringList directories_column_titles; + directories_column_titles << tr("Directory Type") << tr("Path"); + + ui_->directoriesDetailsTable->setColumnCount( + static_cast(directories_column_titles.length())); + ui_->directoriesDetailsTable->setHorizontalHeaderLabels( + directories_column_titles); + ui_->directoriesDetailsTable->horizontalHeader()->setStretchLastSection( + false); + ui_->directoriesDetailsTable->setSelectionBehavior( + QAbstractItemView::SelectRows); + + // table items not editable + ui_->directoriesDetailsTable->setEditTriggers( + QAbstractItemView::NoEditTriggers); + + // no focus (rectangle around table items) + // may be it should focus on whole row + ui_->directoriesDetailsTable->setFocusPolicy(Qt::NoFocus); + ui_->directoriesDetailsTable->setAlternatingRowColors(true); + + QStringList options_column_titles; + options_column_titles << tr("Component") << tr("Group") << tr("Key") + << tr("Description") << tr("Default Value") + << tr("Value"); + + ui_->optionDetailsTable->setColumnCount(options_column_titles.length()); + ui_->optionDetailsTable->setHorizontalHeaderLabels(options_column_titles); + ui_->optionDetailsTable->horizontalHeader()->setStretchLastSection(false); + ui_->optionDetailsTable->setSelectionBehavior(QAbstractItemView::SelectRows); + + // table items not editable + ui_->optionDetailsTable->setEditTriggers(QAbstractItemView::NoEditTriggers); + + // no focus (rectangle around table items) + // may be it should focus on whole row + ui_->optionDetailsTable->setFocusPolicy(Qt::NoFocus); + ui_->optionDetailsTable->setAlternatingRowColors(true); + + if (GFModuleRetrieveRTValueOrDefaultBool( + DUP("ui"), DUP("env.state.gnupg_info_gathering"), 0) == 1) { + process_software_info(); + } else { + gather_gnupg_info(); + } +} + +void GnupgTab::process_software_info() { + const auto gnupg_version = UDUP(GFModuleRetrieveRTValueOrDefault( + DUP("core"), DUP("gpgme.ctx.gnupg_version"), DUP("2.0.0"))); + + ui_->gnupgVersionLabel->setText(QString("Version: %1").arg(gnupg_version)); + + char** pl_components; + auto pl_components_size = GFModuleListRTChildKeys( + GFGetModuleID(), DUP("gnupg.components"), &pl_components); + + auto components = CharArrayToQStringList(pl_components, pl_components_size); + MLogDebug( + QString("got gnupg components from rt, size: %1").arg(components.size())); + + ui_->componentDetailsTable->setRowCount(components.size()); + + int row = 0; + for (auto& component : components) { + auto component_info_json_bytes = UDUP(GFModuleRetrieveRTValueOrDefault( + GFGetModuleID(), QDUP(QString("gnupg.components.%1").arg(component)), + DUP(""))); + MLogDebug(QString("got gnupg component %1 info from rt").arg(component)); + + auto component_info_json = + QJsonDocument::fromJson(component_info_json_bytes.toUtf8()); + if (!component_info_json.isObject()) { + MLogWarn(QString("illegal gnupg component info, json: %1") + .arg(component_info_json_bytes)); + continue; + } + + auto component_info = component_info_json.object(); + if (!component_info.contains("name")) { + MLogWarn(QString("illegal gnupg component info. it doesn't have a " + "name, json: %1") + .arg(component_info_json_bytes)); + continue; + } + + auto* tmp0 = new QTableWidgetItem(component_info["name"].toString()); + tmp0->setTextAlignment(Qt::AlignCenter); + ui_->componentDetailsTable->setItem(row, 0, tmp0); + + auto* tmp1 = new QTableWidgetItem(component_info["desc"].toString()); + tmp1->setTextAlignment(Qt::AlignCenter); + ui_->componentDetailsTable->setItem(row, 1, tmp1); + + auto* tmp2 = new QTableWidgetItem(component_info["version"].toString()); + tmp2->setTextAlignment(Qt::AlignCenter); + ui_->componentDetailsTable->setItem(row, 2, tmp2); + + auto* tmp3 = + new QTableWidgetItem(component_info["binary_checksum"].toString()); + tmp3->setTextAlignment(Qt::AlignCenter); + ui_->componentDetailsTable->setItem(row, 3, tmp3); + + auto* tmp4 = new QTableWidgetItem(component_info["path"].toString()); + tmp4->setTextAlignment(Qt::AlignLeft); + ui_->componentDetailsTable->setItem(row, 4, tmp4); + + row++; + } + + ui_->componentDetailsTable->resizeColumnsToContents(); + + char** p_dirs; + auto p_dirs_size = + GFModuleListRTChildKeys(GFGetModuleID(), DUP("gnupg.dirs"), &p_dirs); + auto dirs = CharArrayToQStringList(p_dirs, p_dirs_size); + + ui_->directoriesDetailsTable->setRowCount(static_cast(p_dirs_size)); + + row = 0; + for (auto& dir : dirs) { + const auto dir_path = UDUP(GFModuleRetrieveRTValueOrDefault( + GFGetModuleID(), QDUP(QString("gnupg.dirs.%1").arg(dir)), DUP(""))); + + if (dir_path.isEmpty()) continue; + + auto* tmp0 = new QTableWidgetItem(dir); + tmp0->setTextAlignment(Qt::AlignCenter); + ui_->directoriesDetailsTable->setItem(row, 0, tmp0); + + auto* tmp1 = new QTableWidgetItem(dir_path); + tmp1->setTextAlignment(Qt::AlignCenter); + ui_->directoriesDetailsTable->setItem(row, 1, tmp1); + + row++; + } + + ui_->directoriesDetailsTable->resizeColumnsToContents(); + + // calculate the total row number of configuration table + row = 0; + for (auto& component : components) { + char** p_options; + auto p_options_size = GFModuleListRTChildKeys( + GFGetModuleID(), + QDUP(QString("gnupg.components.%1.options").arg(component)), + &p_options); + auto options = CharArrayToQStringList(p_options, p_options_size); + + for (auto& option : options) { + const auto option_info_json = QJsonDocument::fromJson( + UDUP(GFModuleRetrieveRTValueOrDefault( + GFGetModuleID(), + QDUP(QString("gnupg.components.%1.options.%2") + .arg(component) + .arg(option)), + DUP(""))) + .toUtf8()); + + if (!option_info_json.isObject()) continue; + + auto option_info = option_info_json.object(); + if (!option_info.contains("name") || option_info["flags"] == "1") { + continue; + } + row++; + } + } + + ui_->optionDetailsTable->setRowCount(row); + + row = 0; + QString configuration_group; + for (auto& component : components) { + char** pc_options; + auto pc_options_size = GFModuleListRTChildKeys( + GFGetModuleID(), + QDUP(QString("gnupg.components.%1.options").arg(component)), + &pc_options); + auto c_options = CharArrayToQStringList(pc_options, pc_options_size); + + for (auto& option : c_options) { + auto option_info_json_bytes = UDUP(GFModuleRetrieveRTValueOrDefault( + GFGetModuleID(), + QDUP(QString("gnupg.components.%1.options.%2") + .arg(component) + .arg(option)), + DUP(""))); + MLogDebug( + QString("got gnupg component's option %1 info from rt, info: %2") + .arg(component) + .arg(option_info_json_bytes)); + + auto option_info_json = + QJsonDocument::fromJson(option_info_json_bytes.toUtf8()); + + if (!option_info_json.isObject()) { + MLogWarn(QString("illegal gnupg option info, json: %1") + .arg(option_info_json_bytes)); + continue; + } + + auto option_info = option_info_json.object(); + if (!option_info.contains("name")) { + MLogWarn(QString("illegal gnupg configuation info. it doesn't have a " + "name, json: %1") + .arg(option_info_json_bytes)); + continue; + } + + if (option_info["flags"] == "1") { + configuration_group = option_info["name"].toString(); + continue; + } + + auto* tmp0 = new QTableWidgetItem(component); + tmp0->setTextAlignment(Qt::AlignCenter); + ui_->optionDetailsTable->setItem(row, 0, tmp0); + + auto* tmp1 = new QTableWidgetItem(configuration_group); + tmp1->setTextAlignment(Qt::AlignCenter); + ui_->optionDetailsTable->setItem(row, 1, tmp1); + + auto* tmp2 = new QTableWidgetItem(option_info["name"].toString()); + tmp2->setTextAlignment(Qt::AlignCenter); + ui_->optionDetailsTable->setItem(row, 2, tmp2); + + auto* tmp3 = new QTableWidgetItem(option_info["description"].toString()); + + tmp3->setTextAlignment(Qt::AlignLeft); + ui_->optionDetailsTable->setItem(row, 3, tmp3); + + auto* tmp4 = + new QTableWidgetItem(option_info["default_value"].toString()); + tmp4->setTextAlignment(Qt::AlignLeft); + ui_->optionDetailsTable->setItem(row, 4, tmp4); + + auto* tmp5 = new QTableWidgetItem(option_info["value"].toString()); + tmp5->setTextAlignment(Qt::AlignLeft); + ui_->optionDetailsTable->setItem(row, 5, tmp5); + + row++; + } + } + + ui_->loadProgressBar->hide(); + ui_->tabWidget->setDisabled(false); +} + +void GnupgTab::gather_gnupg_info() { + ui_->loadProgressBar->show(); + ui_->tabWidget->setDisabled(true); + + if (StartGatheringGnuPGInfo() >= 0) { + GFModuleUpsertRTValueBool(DUP("ui"), DUP("env.state.gnupg_info_gathering"), + 1); + process_software_info(); + } +} + +auto GnupgTabFactory(const char* id) -> void* { return new GnupgTab(); } \ No newline at end of file diff --git a/src/m_gpg_info/GnupgTab.h b/src/m_gpg_info/GnupgTab.h new file mode 100644 index 0000000..ed16a59 --- /dev/null +++ b/src/m_gpg_info/GnupgTab.h @@ -0,0 +1,63 @@ +/** + * Copyright (C) 2021 Saturneric + * + * 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 . + * + * 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 starting on May 12, 2021. + * + * SPDX-License-Identifier: GPL-3.0-or-later + * + */ + +// +// Created by eric on 2022/7/23. +// + +#pragma once + +#include + +class Ui_GnuPGInfo; + +class GnupgTab : public QWidget { + Q_OBJECT + public: + /** + * @brief Construct a new Info Tab object + * + * @param parent + */ + explicit GnupgTab(QWidget* parent = nullptr); + + private: + std::shared_ptr ui_; ///< + + /** + * @brief + * + */ + void process_software_info(); + + /** + * @brief + * + */ + void gather_gnupg_info(); +}; diff --git a/src/m_gpg_info/ts/ModuleGnuPGInfoGathering.de_DE.ts b/src/m_gpg_info/ts/ModuleGnuPGInfoGathering.de_DE.ts new file mode 100644 index 0000000..1f068c5 --- /dev/null +++ b/src/m_gpg_info/ts/ModuleGnuPGInfoGathering.de_DE.ts @@ -0,0 +1,3 @@ + + + diff --git a/src/m_gpg_info/ts/ModuleGnuPGInfoGathering.en_US.ts b/src/m_gpg_info/ts/ModuleGnuPGInfoGathering.en_US.ts new file mode 100644 index 0000000..1f068c5 --- /dev/null +++ b/src/m_gpg_info/ts/ModuleGnuPGInfoGathering.en_US.ts @@ -0,0 +1,3 @@ + + + diff --git a/src/m_gpg_info/ts/ModuleGnuPGInfoGathering.fr_FR.ts b/src/m_gpg_info/ts/ModuleGnuPGInfoGathering.fr_FR.ts new file mode 100644 index 0000000..1f068c5 --- /dev/null +++ b/src/m_gpg_info/ts/ModuleGnuPGInfoGathering.fr_FR.ts @@ -0,0 +1,3 @@ + + + diff --git a/src/m_gpg_info/ts/ModuleGnuPGInfoGathering.zh_CN.ts b/src/m_gpg_info/ts/ModuleGnuPGInfoGathering.zh_CN.ts new file mode 100644 index 0000000..1f068c5 --- /dev/null +++ b/src/m_gpg_info/ts/ModuleGnuPGInfoGathering.zh_CN.ts @@ -0,0 +1,3 @@ + + + diff --git a/src/m_ver_check/UpdateTab.cpp b/src/m_ver_check/UpdateTab.cpp index ea38780..e01d49c 100644 --- a/src/m_ver_check/UpdateTab.cpp +++ b/src/m_ver_check/UpdateTab.cpp @@ -28,6 +28,7 @@ #include "UpdateTab.h" +#include "GFModuleCommonUtils.hpp" #include "GFSDKBasic.h" #include "GFSDKLog.h" #include "GFSDKModule.h" @@ -82,7 +83,7 @@ UpdateTab::UpdateTab(QWidget* parent) : QWidget(parent) { void UpdateTab::showEvent(QShowEvent* event) { QWidget::showEvent(event); - GFModuleLogDebug("loading version loading info from rt"); + MLogDebug("loading version loading info from rt"); auto is_loading_done = GFModuleRetrieveRTValueOrDefaultBool( GFGetModuleID(), GFModuleStrDup("version.loading_done"), 0); @@ -102,14 +103,14 @@ void UpdateTab::showEvent(QShowEvent* event) { } void UpdateTab::slot_show_version_status() { - GFModuleLogDebug("loading version info from rt"); + MLogDebug("loading version info from rt"); this->pb_->setHidden(true); auto is_loading_done = GFModuleRetrieveRTValueOrDefaultBool( GFGetModuleID(), GFModuleStrDup("version.loading_done"), 0); if (is_loading_done == 0) { - GFModuleLogDebug("version info loading haven't been done yet."); + MLogDebug("version info loading haven't been done yet."); return; } @@ -123,9 +124,9 @@ void UpdateTab::slot_show_version_status() { auto is_current_version_released = GFModuleRetrieveRTValueOrDefaultBool( GFGetModuleID(), GFModuleStrDup("version.current_version_released"), 0); - QString const latest_version = GFModuleRetrieveRTValueOrDefault( + QString const latest_version = UDUP(GFModuleRetrieveRTValueOrDefault( GFGetModuleID(), GFModuleStrDup("version.latest_version"), - GFModuleStrDup("")); + GFModuleStrDup(""))); latest_version_label_->setText("
" + tr("Latest Version From Github") + ": " +