diff options
author | saturneric <[email protected]> | 2024-07-24 14:00:36 +0000 |
---|---|---|
committer | saturneric <[email protected]> | 2024-07-24 14:01:55 +0000 |
commit | 71ca9724b8cc8b6041641121776177b088935919 (patch) | |
tree | 7b229b347f4b904e4a461b3c1f8f50b5a058868c | |
parent | feat: add some ui apis to sdk (diff) | |
download | GpgFrontend-71ca9724b8cc8b6041641121776177b088935919.tar.gz GpgFrontend-71ca9724b8cc8b6041641121776177b088935919.zip |
feat: move out GnuPGTab
-rw-r--r-- | src/sdk/GFSDKUI.cpp | 15 | ||||
-rw-r--r-- | src/sdk/private/CommonUtils.cpp | 2 | ||||
-rw-r--r-- | src/ui/GpgFrontendUIInit.cpp | 1 | ||||
-rw-r--r-- | src/ui/UIModuleManager.cpp | 6 | ||||
-rw-r--r-- | src/ui/dialog/help/AboutDialog.cpp | 6 | ||||
-rw-r--r-- | src/ui/dialog/help/GnupgTab.cpp | 336 | ||||
-rw-r--r-- | src/ui/dialog/help/GnupgTab.h | 65 | ||||
-rw-r--r-- | ui/GnuPGInfo.ui | 163 |
8 files changed, 19 insertions, 575 deletions
diff --git a/src/sdk/GFSDKUI.cpp b/src/sdk/GFSDKUI.cpp index 2222fca2..a48f306a 100644 --- a/src/sdk/GFSDKUI.cpp +++ b/src/sdk/GFSDKUI.cpp @@ -57,8 +57,15 @@ auto GFUIMountEntry(const char* id, MetaData** meta_data_array, if (id == nullptr || factory == nullptr) return -1; auto meta_data = MetaDataArrayToQMap(meta_data_array, meta_data_array_size); - return GpgFrontend::UI::UIModuleManager::GetInstance().MountEntry( - GFUnStrDup(id), meta_data, factory) - ? 0 - : -1; + auto qid = GFUnStrDup(id); + + QMetaObject::invokeMethod( + QApplication::instance()->thread(), [qid, meta_data, factory]() -> int { + return GpgFrontend::UI::UIModuleManager::GetInstance().MountEntry( + qid, meta_data, factory) + ? 0 + : -1; + }); + + return 0; } diff --git a/src/sdk/private/CommonUtils.cpp b/src/sdk/private/CommonUtils.cpp index 7d72415e..16dc2db6 100644 --- a/src/sdk/private/CommonUtils.cpp +++ b/src/sdk/private/CommonUtils.cpp @@ -79,4 +79,4 @@ auto QMapToCharArray(const QMap<QString, QString>& map, int& size) -> char** { } return char_array; -}
\ No newline at end of file +} diff --git a/src/ui/GpgFrontendUIInit.cpp b/src/ui/GpgFrontendUIInit.cpp index b0b9c28e..b3050a63 100644 --- a/src/ui/GpgFrontendUIInit.cpp +++ b/src/ui/GpgFrontendUIInit.cpp @@ -270,6 +270,7 @@ void InitUITranslations() { auto InstallTranslatorFromQMData(const QByteArray& data) -> bool { auto* translator = new QTranslator(QCoreApplication::instance()); + if (translator->load(reinterpret_cast<uchar*>(const_cast<char*>(data.data())), data.size())) { GF_UI_LOG_DEBUG("load target translation file done, locale: {}", diff --git a/src/ui/UIModuleManager.cpp b/src/ui/UIModuleManager.cpp index 8d5e3ca6..0779492e 100644 --- a/src/ui/UIModuleManager.cpp +++ b/src/ui/UIModuleManager.cpp @@ -68,6 +68,12 @@ auto UIModuleManager::MountEntry(const QString& id, MountedUIEntry m_entry; m_entry.id_ = id; + + for (const auto& meta : meta_data.asKeyValueRange()) { + meta_data[meta.first] = + QApplication::translate("GTrC", meta.second.toUtf8()); + } + m_entry.meta_data_ = std::move(meta_data); m_entry.factory_ = factory; diff --git a/src/ui/dialog/help/AboutDialog.cpp b/src/ui/dialog/help/AboutDialog.cpp index 307dfca6..b4410942 100644 --- a/src/ui/dialog/help/AboutDialog.cpp +++ b/src/ui/dialog/help/AboutDialog.cpp @@ -33,7 +33,6 @@ #include "core/module/ModuleManager.h" #include "core/utils/BuildInfoUtils.h" #include "ui/UIModuleManager.h" -#include "ui/dialog/help/GnupgTab.h" namespace GpgFrontend::UI { @@ -47,11 +46,6 @@ AboutDialog::AboutDialog(const QString& default_tab_name, QWidget* parent) tab_widget->addTab(info_tab, tr("About GpgFrontend")); - if (Module::IsModuleActivate(kGnuPGInfoGatheringModuleID)) { - auto* gnupg_tab = new GnupgTab(); - tab_widget->addTab(gnupg_tab, tr("GnuPG")); - } - tab_widget->addTab(translators_tab, tr("Translators")); auto entries = diff --git a/src/ui/dialog/help/GnupgTab.cpp b/src/ui/dialog/help/GnupgTab.cpp deleted file mode 100644 index ac018def..00000000 --- a/src/ui/dialog/help/GnupgTab.cpp +++ /dev/null @@ -1,336 +0,0 @@ -/** - * 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 - * - */ - -// -// Created by eric on 2022/7/23. -// - -#include "GnupgTab.h" - -#include "core/module/ModuleManager.h" -#include "ui_GnuPGInfo.h" - -namespace GpgFrontend::UI { - -GnupgTab::GnupgTab(QWidget* parent) - : QWidget(parent), - ui_(GpgFrontend::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 (Module::RetrieveRTValueTypedOrDefault( - "ui", "env.state.gnupg_info_gathering", 0) == 1) { - process_software_info(); - } else { - gather_gnupg_info(); - } -} - -void GnupgTab::process_software_info() { - const auto gnupg_version = Module::RetrieveRTValueTypedOrDefault<>( - "core", "gpgme.ctx.gnupg_version", QString{"2.0.0"}); - GF_UI_LOG_DEBUG("got gnupg version from rt: {}", gnupg_version); - - ui_->gnupgVersionLabel->setText( - QString::fromStdString(fmt::format("Version: {}", gnupg_version))); - - auto components = - Module::ListRTChildKeys(kGnuPGInfoGatheringModuleID, "gnupg.components"); - GF_UI_LOG_DEBUG("got gnupg components from rt, size: {}", components.size()); - - ui_->componentDetailsTable->setRowCount(components.size()); - - int row = 0; - for (auto& component : components) { - auto component_info_json_bytes = Module::RetrieveRTValueTypedOrDefault( - kGnuPGInfoGatheringModuleID, - 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.toUtf8()); - if (!component_info_json.isObject()) { - GF_UI_LOG_WARN("illegal gnupg component info, json: {}", - QString(component_info_json_bytes)); - continue; - } - - auto component_info = component_info_json.object(); - if (!component_info.contains("name")) { - GF_UI_LOG_WARN( - "illegal gnupg component info. it doesn't have a name, json: {}", - QString(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(); - - auto directories = Module::ListRTChildKeys(kGnuPGInfoGatheringModuleID, - QString("gnupg.dirs")); - - ui_->directoriesDetailsTable->setRowCount( - static_cast<int>(directories.size())); - - row = 0; - for (auto& dir : directories) { - const auto dir_path = Module::RetrieveRTValueTypedOrDefault( - kGnuPGInfoGatheringModuleID, QString("gnupg.dirs.%1").arg(dir), - QString{}); - - 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) { - auto options = Module::ListRTChildKeys( - kGnuPGInfoGatheringModuleID, - QString("gnupg.components.%1.options").arg(component)); - for (auto& option : options) { - const auto option_info_json = - QJsonDocument::fromJson(Module::RetrieveRTValueTypedOrDefault( - kGnuPGInfoGatheringModuleID, - QString("gnupg.components.%1.options.%2") - .arg(component) - .arg(option), - QString{}) - .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) { - auto options = Module::ListRTChildKeys( - kGnuPGInfoGatheringModuleID, - QString("gnupg.components.%1.options").arg(component)); - - for (auto& option : options) { - auto option_info_json_bytes = Module::RetrieveRTValueTypedOrDefault( - kGnuPGInfoGatheringModuleID, - QString("gnupg.components.%1.options.%2").arg(component).arg(option), - 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.toUtf8()); - - if (!option_info_json.isObject()) { - GF_UI_LOG_WARN("illegal gnupg option info, json: {}", - QString(option_info_json_bytes)); - continue; - } - - auto option_info = option_info_json.object(); - if (!option_info.contains("name")) { - GF_UI_LOG_WARN( - "illegal gnupg configuation info. it doesn't have a name, json: {}", - QString(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() { - // if gnupg_info_gathering module activated - if (Module::IsModuleActivate(kGnuPGInfoGatheringModuleID)) { - GF_CORE_LOG_DEBUG( - "module gnupg_info_gathering is activated, " - "loading external gnupg info..."); - - ui_->loadProgressBar->show(); - ui_->tabWidget->setDisabled(true); - - // gather external gnupg info - Module::TriggerEvent( - "REQUEST_GATHERING_GNUPG_INFO", - [=](const Module::EventIdentifier& /*e*/, - const Module::Event::ListenerIdentifier& l_id, DataObjectPtr o) { - GF_CORE_LOG_DEBUG( - "received event REQUEST_GATHERING_GNUPG_INFO callback " - "from module: {}", - l_id); - - if (l_id == kGnuPGInfoGatheringModuleID) { - Module::UpsertRTValue("ui", "env.state.gnupg_info_gathering", 1); - - // gnupg info gathering process finished - GF_CORE_LOG_INFO("gnupg information gathering finished"); - process_software_info(); - } - }); - } -} - -} // namespace GpgFrontend::UI
\ No newline at end of file diff --git a/src/ui/dialog/help/GnupgTab.h b/src/ui/dialog/help/GnupgTab.h deleted file mode 100644 index 60abd048..00000000 --- a/src/ui/dialog/help/GnupgTab.h +++ /dev/null @@ -1,65 +0,0 @@ -/** - * 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 - * - */ - -// -// Created by eric on 2022/7/23. -// - -#pragma once - -#include "core/function/gpg/GpgContext.h" -#include "ui/GpgFrontendUI.h" - -class Ui_GnuPGInfo; -namespace GpgFrontend::UI { -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(); -}; -} // namespace GpgFrontend::UI diff --git a/ui/GnuPGInfo.ui b/ui/GnuPGInfo.ui deleted file mode 100644 index 63e746a5..00000000 --- a/ui/GnuPGInfo.ui +++ /dev/null @@ -1,163 +0,0 @@ -<?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> |