feat: move in GnuPGTab

This commit is contained in:
saturneric 2024-07-24 16:02:49 +02:00
parent 988b0257e5
commit 46b7ecec8f
12 changed files with 707 additions and 113 deletions

View File

@ -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<QString, QString>& 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<void*>(const_cast<char*>(src)));
return qt_str;
}
inline auto QMapToMetaDataArray(const QMap<QString, QString>& map)
-> MetaData** {
auto** meta_data_array =
static_cast<MetaData**>(GFAllocateMemory(sizeof(MetaData*) * map.size()));
@ -74,7 +85,7 @@ auto QMapToMetaDataArray(const QMap<QString, QString>& map) -> MetaData** {
return meta_data_array;
}
auto QMapToGFModuleMetaDataList(const QMap<QString, QString>& map)
inline auto QMapToGFModuleMetaDataList(const QMap<QString, QString>& map)
-> GFModuleMetaData* {
GFModuleMetaData* head = nullptr;
GFModuleMetaData* tail = nullptr;
@ -105,8 +116,36 @@ auto QMapToGFModuleMetaDataList(const QMap<QString, QString>& map)
return head;
}
auto AllocBufferAndCopy(const QByteArray& b) -> char* {
inline auto AllocBufferAndCopy(const QByteArray& b) -> char* {
auto* p = static_cast<char*>(GFAllocateMemory(sizeof(char) * b.size()));
memcpy(p, b.constData(), b.size());
return p;
}
template <typename T, typename... Args>
auto SecureCreateSharedObject(Args&&... args) -> std::shared_ptr<T> {
void* mem = GFAllocateMemory(sizeof(T));
if (!mem) throw std::bad_alloc();
try {
T* obj = new (mem) T(std::forward<Args>(args)...);
return std::shared_ptr<T>(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;
}

View File

@ -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)
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})

163
src/m_gpg_info/GnuPGInfo.ui Normal file
View File

@ -0,0 +1,163 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>GnuPGInfo</class>
<widget class="QWidget" name="GnuPGInfo">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>535</width>
<height>568</height>
</rect>
</property>
<property name="windowTitle">
<string>GnuPG Info</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,0,0,0">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string/>
</property>
<property name="pixmap">
<pixmap resource="../gpgfrontend.qrc">:/icons/gnupg.png</pixmap>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
<property name="margin">
<number>10</number>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="gnupgVersionLabel">
<property name="text">
<string>Version</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
<property name="margin">
<number>5</number>
</property>
</widget>
</item>
<item>
<widget class="Line" name="line">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="tabShape">
<enum>QTabWidget::Rounded</enum>
</property>
<property name="currentIndex">
<number>0</number>
</property>
<property name="tabBarAutoHide">
<bool>false</bool>
</property>
<widget class="QWidget" name="tab">
<attribute name="title">
<string>Components</string>
</attribute>
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0">
<widget class="QTableWidget" name="componentDetailsTable">
<property name="sizeAdjustPolicy">
<enum>QAbstractScrollArea::AdjustToContents</enum>
</property>
<property name="autoScrollMargin">
<number>16</number>
</property>
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QProgressBar" name="loadProgressBar">
<property name="maximum">
<number>0</number>
</property>
<property name="value">
<number>-1</number>
</property>
<property name="textVisible">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_2">
<attribute name="title">
<string>Directories</string>
</attribute>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QTableWidget" name="directoriesDetailsTable">
<property name="sizeAdjustPolicy">
<enum>QAbstractScrollArea::AdjustToContents</enum>
</property>
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_3">
<attribute name="title">
<string>Options</string>
</attribute>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QTableWidget" name="optionDetailsTable"/>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources>
<include location="../gpgfrontend.qrc"/>
</resources>
<connections/>
</ui>

View File

@ -34,6 +34,7 @@
#include <spdlog/spdlog.h>
// qt
#include <QCoreApplication>
#include <QCryptographicHash>
#include <QFileInfo>
#include <QJsonDocument>
@ -42,41 +43,11 @@
// c++
#include <optional>
#include "GFModuleCommonUtils.hpp"
#include "GpgInfo.h"
template <>
struct fmt::formatter<QString> {
// 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 <typename FormatContext>
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<QByteArray> {
// 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 <typename FormatContext>
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<char **>(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<char **>(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<QString> {
// 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<QString> {
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<Context *>(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<GpgOptionsInfo> 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);
}
}

View File

@ -53,4 +53,4 @@ auto GF_MODULE_EXPORT GFExecuteModule(GFModuleEvent *) -> int;
auto GF_MODULE_EXPORT GFDeactiveModule() -> int;
auto GF_MODULE_EXPORT GFUnregisterModule() -> int;
};
};

330
src/m_gpg_info/GnupgTab.cpp Normal file
View File

@ -0,0 +1,330 @@
/**
* Copyright (C) 2021 Saturneric <eric@bktus.com>
*
* 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 <eric@bktus.com> 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_GnuPGInfo>()) {
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<int>(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<int>(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(); }

63
src/m_gpg_info/GnupgTab.h Normal file
View File

@ -0,0 +1,63 @@
/**
* Copyright (C) 2021 Saturneric <eric@bktus.com>
*
* 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 <eric@bktus.com> starting on May 12, 2021.
*
* SPDX-License-Identifier: GPL-3.0-or-later
*
*/
//
// Created by eric on 2022/7/23.
//
#pragma once
#include <QtWidgets/QtWidgets>
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_GnuPGInfo> ui_; ///<
/**
* @brief
*
*/
void process_software_info();
/**
* @brief
*
*/
void gather_gnupg_info();
};

View File

@ -0,0 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS/>

View File

@ -0,0 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS/>

View File

@ -0,0 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS/>

View File

@ -0,0 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS/>

View File

@ -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("<center><b>" +
tr("Latest Version From Github") + ": " +