diff options
Diffstat (limited to '')
32 files changed, 303 insertions, 164 deletions
diff --git a/src/core/GpgCoreInit.cpp b/src/core/GpgCoreInit.cpp index 8b2dbbed..42991564 100644 --- a/src/core/GpgCoreInit.cpp +++ b/src/core/GpgCoreInit.cpp @@ -276,7 +276,6 @@ void InitGpgFrontendCore(CoreInitArgs args) { // initialize global register table Module::UpsertRTValue("core", "env.state.gpgme", 0); Module::UpsertRTValue("core", "env.state.ctx", 0); - Module::UpsertRTValue("core", "env.state.gnupg", 0); Module::UpsertRTValue("core", "env.state.basic", 0); Module::UpsertRTValue("core", "env.state.all", 0); @@ -409,60 +408,22 @@ void InitGpgFrontendCore(CoreInitArgs args) { QCoreApplication::tr("Gpg Key Detabase initiation failed")); }; } + GF_CORE_LOG_DEBUG( - "basic env checking finished, " - "including gpgme, ctx, and key infos"); + "basic env checking finished, including gpgme, ctx, and key infos"); + Module::UpsertRTValue("core", "env.state.basic", 1); CoreSignalStation::GetInstance()->SignalGoodGnupgEnv(); - // if gnupg_info_gathering module activated - if (args.gather_external_gnupg_info && - Module::IsModuleAcivate("com.bktus.gpgfrontend.module." - "integrated.gnupg_info_gathering")) { - GF_CORE_LOG_DEBUG( - "module gnupg_info_gathering is activated, " - "loading external gnupg info..."); - - // gather external gnupg info - Module::TriggerEvent( - "GPGFRONTEND_CORE_INITLIZED", - [](const Module::EventIdentifier& /*e*/, - const Module::Event::ListenerIdentifier& l_id, - DataObjectPtr o) { - GF_CORE_LOG_DEBUG( - "received event GPGFRONTEND_CORE_INITLIZED callback " - "from module: {}", - l_id); - - if (l_id == - "com.bktus.gpgfrontend.module.integrated.gnupg-info-" - "gathering") { - GF_CORE_LOG_DEBUG( - "received callback from gnupg_info_gathering "); - - // try to restart all components - auto settings = - GlobalSettingStation::GetInstance().GetSettings(); - auto restart_all_gnupg_components_on_start = - settings.value("gnupg/restart_gpg_agent_on_start", false) - .toBool(); - - if (restart_all_gnupg_components_on_start) { - GpgAdvancedOperator::RestartGpgComponents(); - } - Module::UpsertRTValue("core", "env.state.gnupg", 1); + // try to restart all components + auto restart_all_gnupg_components_on_start = + settings.value("gnupg/restart_gpg_agent_on_start", false).toBool(); - // announce that all checkings were finished - GF_CORE_LOG_INFO( - "all env checking finished, including gpgme, " - "ctx and gnupg"); - Module::UpsertRTValue("core", "env.state.all", 1); - } - }); - } else { - GF_CORE_LOG_DEBUG("gnupg_info_gathering is not activated"); - Module::UpsertRTValue("core", "env.state.all", 1); + if (restart_all_gnupg_components_on_start) { + GpgAdvancedOperator::RestartGpgComponents(); } + + Module::UpsertRTValue("core", "env.state.all", 1); return 0; }, "core_init_task"); diff --git a/src/ui/struct/CacheObject.cpp b/src/core/model/CacheObject.cpp index bd3b9818..37dedd92 100644 --- a/src/ui/struct/CacheObject.cpp +++ b/src/core/model/CacheObject.cpp @@ -30,7 +30,7 @@ #include "core/function/CacheManager.h" -namespace GpgFrontend::UI { +namespace GpgFrontend { CacheObject::CacheObject(QString cache_name) : cache_name_(std::move(cache_name)) { @@ -42,4 +42,4 @@ CacheObject::~CacheObject() { CacheManager::GetInstance().SaveDurableCache(cache_name_, *this); } -} // namespace GpgFrontend::UI
\ No newline at end of file +} // namespace GpgFrontend
\ No newline at end of file diff --git a/src/ui/struct/CacheObject.h b/src/core/model/CacheObject.h index ae8aa056..3cfa8083 100644 --- a/src/ui/struct/CacheObject.h +++ b/src/core/model/CacheObject.h @@ -28,9 +28,11 @@ #pragma once -namespace GpgFrontend::UI { +#include "core/GpgFrontendCoreExport.h" -class CacheObject : public QJsonDocument { +namespace GpgFrontend { + +class GPGFRONTEND_CORE_EXPORT CacheObject : public QJsonDocument { public: /** * @brief Construct a new Cache Object object @@ -49,4 +51,4 @@ class CacheObject : public QJsonDocument { QString cache_name_; ///< }; -} // namespace GpgFrontend::UI
\ No newline at end of file +} // namespace GpgFrontend
\ No newline at end of file diff --git a/src/ui/struct/SettingsObject.cpp b/src/core/model/SettingsObject.cpp index cc5e85bf..09824f12 100644 --- a/src/ui/struct/SettingsObject.cpp +++ b/src/core/model/SettingsObject.cpp @@ -30,25 +30,25 @@ #include "core/function/DataObjectOperator.h" -namespace GpgFrontend::UI { +namespace GpgFrontend { SettingsObject::SettingsObject(QString settings_name) : settings_name_(std::move(settings_name)) { try { - GF_UI_LOG_DEBUG("loading settings from: {}", this->settings_name_); + GF_CORE_LOG_DEBUG("loading settings from: {}", this->settings_name_); auto json_optional = DataObjectOperator::GetInstance().GetDataObject(settings_name_); if (json_optional.has_value() && json_optional->isObject()) { - GF_UI_LOG_DEBUG("settings object: {} loaded.", settings_name_); + GF_CORE_LOG_DEBUG("settings object: {} loaded.", settings_name_); QJsonObject::operator=(json_optional.value().object()); } else { - GF_UI_LOG_DEBUG("settings object: {} not found.", settings_name_); + GF_CORE_LOG_DEBUG("settings object: {} not found.", settings_name_); QJsonObject::operator=({}); } } catch (std::exception& e) { - GF_UI_LOG_ERROR("load setting object error: {}", e.what()); + GF_CORE_LOG_ERROR("load setting object error: {}", e.what()); } } @@ -66,4 +66,4 @@ void SettingsObject::Store(const QJsonObject& json) { auto* parent = (static_cast<QJsonObject*>(this)); *parent = json; } -} // namespace GpgFrontend::UI
\ No newline at end of file +} // namespace GpgFrontend
\ No newline at end of file diff --git a/src/ui/struct/SettingsObject.h b/src/core/model/SettingsObject.h index a9e5819f..4b52f31d 100644 --- a/src/ui/struct/SettingsObject.h +++ b/src/core/model/SettingsObject.h @@ -28,14 +28,16 @@ #pragma once -namespace GpgFrontend::UI { +#include "core/GpgFrontendCoreExport.h" + +namespace GpgFrontend { /** * @brief The SettingsObject class * This class is used to store data for the application securely. * */ -class SettingsObject : public QJsonObject { +class GPGFRONTEND_CORE_EXPORT SettingsObject : public QJsonObject { public: /** * @brief Construct a new Settings Object object @@ -66,4 +68,4 @@ class SettingsObject : public QJsonObject { private: QString settings_name_; ///< }; -} // namespace GpgFrontend::UI +} // namespace GpgFrontend diff --git a/src/core/module/GlobalModuleContext.cpp b/src/core/module/GlobalModuleContext.cpp index 6032e090..1744ba72 100644 --- a/src/core/module/GlobalModuleContext.cpp +++ b/src/core/module/GlobalModuleContext.cpp @@ -327,6 +327,7 @@ class GlobalModuleContext::Impl { for (const auto& module : module_register_table_) { module_ids.append(module.first); } + module_ids.sort(); return module_ids; } diff --git a/src/core/module/ModuleManager.cpp b/src/core/module/ModuleManager.cpp index 253ea8eb..0e1f6984 100644 --- a/src/core/module/ModuleManager.cpp +++ b/src/core/module/ModuleManager.cpp @@ -34,9 +34,11 @@ #include "GpgConstants.h" #include "core/function/SecureMemoryAllocator.h" #include "core/function/basic/GpgFunctionObject.h" +#include "core/model/SettingsObject.h" #include "core/module/GlobalModuleContext.h" #include "core/module/GlobalRegisterTable.h" #include "core/module/Module.h" +#include "core/struct/settings_object/ModuleSO.h" #include "core/thread/Task.h" #include "core/thread/TaskRunnerGetter.h" #include "core/utils/MemoryUtils.h" @@ -75,7 +77,22 @@ class ModuleManager::Impl { } module->SetGPC(gmc_.get()); - return gmc_->RegisterModule(module) ? 0 : -1; + if (!gmc_->RegisterModule(module)) return -1; + + SettingsObject so( + QString("module.%1.so").arg(module->GetModuleIdentifier())); + ModuleSO module_so(so); + + // if user has set auto active enable + if (module_so.module_id == module->GetModuleIdentifier() && + module_so.module_hash == module->GetModuleHash() && + module_so.auto_activate) { + if (gmc_->ActiveModule(module->GetModuleIdentifier())) { + return -1; + } + } + + return 0; }, __func__, nullptr)); } diff --git a/src/core/struct/settings_object/ModuleSO.h b/src/core/struct/settings_object/ModuleSO.h new file mode 100644 index 00000000..a161885c --- /dev/null +++ b/src/core/struct/settings_object/ModuleSO.h @@ -0,0 +1,68 @@ +/** + * 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 { + +struct ModuleSO { + QString module_id; + QString module_version; + QString module_hash; + bool auto_activate; + + ModuleSO() = default; + + explicit ModuleSO(const QJsonObject& j) { + if (const auto v = j["module_id"]; v.isString()) { + module_id = v.toString(); + } + + if (const auto v = j["module_version"]; v.isString()) { + module_version = v.toString(); + } + + if (const auto v = j["module_hash"]; v.isString()) { + module_hash = v.toString(); + } + + if (const auto v = j["auto_activate"]; v.isBool()) { + auto_activate = v.toBool(); + } + } + + [[nodiscard]] auto ToJson() const -> QJsonObject { + QJsonObject j; + j["module_id"] = module_id; + j["module_version"] = module_version; + j["module_hash"] = module_hash; + j["auto_activate"] = auto_activate; + return j; + } +}; +} // namespace GpgFrontend
\ No newline at end of file diff --git a/src/module/integrated/gnupg_info_gathering_module/GnuPGInfoGatheringModule.cpp b/src/module/integrated/gnupg_info_gathering_module/GnuPGInfoGatheringModule.cpp index c5c760b0..e4c30164 100644 --- a/src/module/integrated/gnupg_info_gathering_module/GnuPGInfoGatheringModule.cpp +++ b/src/module/integrated/gnupg_info_gathering_module/GnuPGInfoGatheringModule.cpp @@ -130,7 +130,7 @@ auto GFRegisterModule() -> int { auto GFActiveModule() -> int { GFModuleLogDebug("gnupg info gathering module activating"); GFModuleListenEvent(GFGetModuleID(), - GFModuleStrDup("GPGFRONTEND_CORE_INITLIZED")); + GFModuleStrDup("REQUEST_GATHERING_GNUPG_INFO")); return 0; } @@ -185,6 +185,8 @@ auto GFExecuteModule(GFModuleEvent *event) -> int { GFModuleStrDup(QString("gnupg.components.%1").arg(component).toUtf8()), nullptr); + if (component_info_json == nullptr) continue; + auto jsonlized_component_info = QJsonDocument::fromJson(component_info_json); assert(jsonlized_component_info.isObject()); diff --git a/src/ui/UserInterfaceUtils.cpp b/src/ui/UserInterfaceUtils.cpp index 5e24c8eb..1fd5c3bb 100644 --- a/src/ui/UserInterfaceUtils.cpp +++ b/src/ui/UserInterfaceUtils.cpp @@ -33,7 +33,9 @@ #include "core/GpgConstants.h" #include "core/function/CoreSignalStation.h" #include "core/function/gpg/GpgKeyGetter.h" +#include "core/model/CacheObject.h" #include "core/model/GpgImportInformation.h" +#include "core/model/SettingsObject.h" #include "core/module/ModuleManager.h" #include "core/thread/Task.h" #include "core/thread/TaskRunnerGetter.h" @@ -46,9 +48,7 @@ #include "ui/dialog/WaitingDialog.h" #include "ui/dialog/controller/GnuPGControllerDialog.h" #include "ui/dialog/import_export/KeyServerImportDialog.h" -#include "ui/struct/CacheObject.h" -#include "ui/struct/SettingsObject.h" -#include "ui/struct/settings/KeyServerSO.h" +#include "ui/struct/settings_object/KeyServerSO.h" #include "ui/widgets/TextEdit.h" namespace GpgFrontend::UI { diff --git a/src/ui/dialog/GeneralDialog.cpp b/src/ui/dialog/GeneralDialog.cpp index 386573a3..2015322f 100644 --- a/src/ui/dialog/GeneralDialog.cpp +++ b/src/ui/dialog/GeneralDialog.cpp @@ -28,8 +28,8 @@ #include "GeneralDialog.h" -#include "ui/struct/SettingsObject.h" -#include "ui/struct/settings/WindowStateSO.h" +#include "core/model/SettingsObject.h" +#include "ui/struct/settings_object/WindowStateSO.h" namespace GpgFrontend { diff --git a/src/ui/dialog/controller/ModuleControllerDialog.cpp b/src/ui/dialog/controller/ModuleControllerDialog.cpp index ad2bf918..ee23b80d 100644 --- a/src/ui/dialog/controller/ModuleControllerDialog.cpp +++ b/src/ui/dialog/controller/ModuleControllerDialog.cpp @@ -28,6 +28,8 @@ #include "ModuleControllerDialog.h" +#include "core/model/SettingsObject.h" +#include "core/struct/settings_object/ModuleSO.h" #include "ui_ModuleControllerDialog.h" // @@ -64,6 +66,18 @@ ModuleControllerDialog::ModuleControllerDialog(QWidget* parent) QTimer::singleShot(1000, [=]() { slot_load_module_details(module_id); }); }); + connect(ui_->autoActivateButton, &QPushButton::clicked, this, [=]() { + auto module_id = model_list_view_->GetCurrentModuleID(); + SettingsObject so(QString("module.%1.so").arg(module_id)); + ModuleSO module_so(so); + + module_so.auto_activate = + ui_->autoActivateButton->text() == tr("Enable Auto Activate"); + so.Store(module_so.ToJson()); + + QTimer::singleShot(1000, [=]() { slot_load_module_details(module_id); }); + }); + connect(ui_->triggerEventButton, &QPushButton::clicked, this, [=]() { auto event_id = QInputDialog::getText(this, "Please provide an Event ID", "Event ID"); @@ -74,48 +88,67 @@ ModuleControllerDialog::ModuleControllerDialog(QWidget* parent) void ModuleControllerDialog::slot_load_module_details( Module::ModuleIdentifier module_id) { GF_UI_LOG_DEBUG("loading module details, module id: {}", module_id); - auto module = module_manager_->SearchModule(module_id); + SettingsObject so(QString("module.%1.so").arg(module_id)); + ModuleSO module_so(so); + + if (module_so.module_id != module_id || + module_so.module_hash != module->GetModuleHash()) { + module_so.module_id = module_id; + module_so.module_hash = module->GetModuleHash(); + module_so.auto_activate = false; + GF_UI_LOG_DEBUG("reseting module settings object, module id: {}", + module_id); + so.Store(module_so.ToJson()); + } QString buffer; QTextStream info(&buffer); - info << "# BASIC INFO" << Qt::endl << Qt::endl; - info << tr("ID") << ": " << module->GetModuleIdentifier() << Qt::endl; - info << tr("Version") << ": " << module->GetModuleVersion() << Qt::endl; - info << tr("SDK Version") << ": " << module->GetModuleSDKVersion() + info << " - " << tr("ID") << ": " << module->GetModuleIdentifier() + << Qt::endl; + info << " - " << tr("Version") << ": " << module->GetModuleVersion() << Qt::endl; - info << tr("Qt ENV Version") << ": " << module->GetModuleQtEnvVersion() + info << " - " << tr("SDK Version") << ": " << module->GetModuleSDKVersion() << Qt::endl; - info << tr("Hash") << ": " << module->GetModuleHash() << Qt::endl; - info << tr("Path") << ": " << module->GetModulePath() << Qt::endl; + info << " - " << tr("Qt ENV Version") << ": " + << module->GetModuleQtEnvVersion() << Qt::endl; + info << " - " << tr("Hash") << ": " << module->GetModuleHash() << Qt::endl; + info << " - " << tr("Path") << ": " << module->GetModulePath() << Qt::endl; bool if_activated = module_manager_->IsModuleActivated(module_id); - info << tr("Active") << ": " << (if_activated ? tr("True") : tr("False")) - << Qt::endl; + info << " - " << tr("Auto Activate") << ": " + << (module_so.auto_activate ? tr("True") : tr("False")) << Qt::endl; + info << " - " << tr("Active") << ": " + << (if_activated ? tr("True") : tr("False")) << Qt::endl; info << Qt::endl; info << "# METADATA" << Qt::endl << Qt::endl; for (const auto& metadata : module->GetModuleMetaData()) { - info << metadata.first << ": " << metadata.second << "\n"; + info << " - " << metadata.first << ": " << metadata.second << "\n"; } info << Qt::endl; - info << "# Listening Event" << Qt::endl << Qt::endl; + if (if_activated) { + info << "# Listening Event" << Qt::endl << Qt::endl; - auto listening_event_ids = module_manager_->GetModuleListening(module_id); - for (const auto& event_id : listening_event_ids) { - info << " - " << event_id << "\n"; + auto listening_event_ids = module_manager_->GetModuleListening(module_id); + for (const auto& event_id : listening_event_ids) { + info << " - " << event_id << "\n"; + } } ui_->moduleInfoTextBrowser->setText(buffer); ui_->activateOrDeactiveButton->setText(if_activated ? tr("Deactivate") : tr("Activate")); + ui_->autoActivateButton->setText(module_so.auto_activate + ? tr("Disable Auto Activate") + : tr("Enable Auto Activate")); } } // namespace GpgFrontend::UI diff --git a/src/ui/dialog/help/AboutDialog.cpp b/src/ui/dialog/help/AboutDialog.cpp index cd577f89..e3aa0a6c 100644 --- a/src/ui/dialog/help/AboutDialog.cpp +++ b/src/ui/dialog/help/AboutDialog.cpp @@ -36,7 +36,10 @@ namespace GpgFrontend::UI { -AboutDialog::AboutDialog(int defaultIndex, QWidget* parent) +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()); @@ -46,16 +49,15 @@ AboutDialog::AboutDialog(int defaultIndex, QWidget* parent) tab_widget->addTab(info_tab, tr("About GpgFrontend")); - if (Module::IsModuleAcivate("com.bktus.gpgfrontend.module." - "integrated.gnupg_info_gathering")) { + if (Module::IsModuleAcivate( + "com.bktus.gpgfrontend.module.integrated.gnupg_info_gathering")) { auto* gnupg_tab = new GnupgTab(); tab_widget->addTab(gnupg_tab, tr("GnuPG")); } tab_widget->addTab(translators_tab, tr("Translators")); - if (Module::IsModuleAcivate("com.bktus.gpgfrontend.module." - "integrated.version_checking")) { + if (Module::IsModuleAcivate(kVersionCheckingModuleID)) { auto* update_tab = new UpdateTab(); tab_widget->addTab(update_tab, tr("Update")); } @@ -63,8 +65,15 @@ AboutDialog::AboutDialog(int defaultIndex, QWidget* parent) connect(tab_widget, &QTabWidget::currentChanged, this, [&](int index) { GF_UI_LOG_DEBUG("current index: {}", index); }); - if (defaultIndex < tab_widget->count() && defaultIndex >= 0) { - tab_widget->setCurrentIndex(defaultIndex); + int default_index = 0; + for (int i = 0; i < tab_widget->count(); i++) { + if (tab_widget->tabText(i) == default_tab_name) { + default_index = i; + } + } + + if (default_index < tab_widget->count() && default_index >= 0) { + tab_widget->setCurrentIndex(default_index); } auto* button_box = new QDialogButtonBox(QDialogButtonBox::Ok); @@ -198,17 +207,15 @@ void UpdateTab::showEvent(QShowEvent* event) { GF_UI_LOG_DEBUG("loading version loading 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); if (!is_loading_done) { 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 " - "version upgrade"); + "version_checking module version.loading_done changed, calling " + "slot version upgrade"); this->slot_show_version_status(); }); Module::TriggerEvent("CHECK_APPLICATION_VERSION"); @@ -222,29 +229,24 @@ void UpdateTab::slot_show_version_status() { this->pb_->setHidden(true); auto is_loading_done = Module::RetrieveRTValueTypedOrDefault<>( - "com.bktus.gpgfrontend.module.integrated.version_checking", - "version.loading_done", false); + kVersionCheckingModuleID, "version.loading_done", false); if (!is_loading_done) { - GF_UI_LOG_DEBUG("version info loading havn't been done yet."); + GF_UI_LOG_DEBUG("version info loading haven't been done yet."); return; } 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{}); latest_version_label_->setText("<center><b>" + tr("Latest Version From Github") + ": " + diff --git a/src/ui/dialog/help/AboutDialog.h b/src/ui/dialog/help/AboutDialog.h index 86576123..6d152afb 100644 --- a/src/ui/dialog/help/AboutDialog.h +++ b/src/ui/dialog/help/AboutDialog.h @@ -120,7 +120,7 @@ class AboutDialog : public GeneralDialog { * @param defaultIndex * @param parent */ - explicit AboutDialog(int defaultIndex, QWidget* parent); + explicit AboutDialog(const QString& default_tab_name, QWidget* parent); protected: /** diff --git a/src/ui/dialog/help/GnupgTab.cpp b/src/ui/dialog/help/GnupgTab.cpp index 5d3f21aa..218426b6 100644 --- a/src/ui/dialog/help/GnupgTab.cpp +++ b/src/ui/dialog/help/GnupgTab.cpp @@ -35,7 +35,12 @@ #include "core/module/ModuleManager.h" #include "ui_GnuPGInfo.h" -GpgFrontend::UI::GnupgTab::GnupgTab(QWidget* parent) +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>()) { ui_->setupUi(this); @@ -103,10 +108,15 @@ GpgFrontend::UI::GnupgTab::GnupgTab(QWidget* parent) ui_->optionDetailsTable->setFocusPolicy(Qt::NoFocus); ui_->optionDetailsTable->setAlternatingRowColors(true); - process_software_info(); + if (Module::RetrieveRTValueTypedOrDefault( + "ui", "env.state.gnupg_info_gathering", 0) == 1) { + process_software_info(); + } else { + gather_gnupg_info(); + } } -void GpgFrontend::UI::GnupgTab::process_software_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); @@ -114,9 +124,8 @@ void GpgFrontend::UI::GnupgTab::process_software_info() { ui_->gnupgVersionLabel->setText( QString::fromStdString(fmt::format("Version: {}", gnupg_version))); - auto components = Module::ListRTChildKeys( - "com.bktus.gpgfrontend.module.integrated.gnupg_info_gathering", - "gnupg.components"); + auto components = + Module::ListRTChildKeys(kGnuPGInfoGatheringModuleID, "gnupg.components"); GF_UI_LOG_DEBUG("got gnupg components from rt, size: {}", components.size()); ui_->componentDetailsTable->setRowCount(components.size()); @@ -124,7 +133,7 @@ void GpgFrontend::UI::GnupgTab::process_software_info() { int row = 0; for (auto& component : components) { auto component_info_json_bytes = Module::RetrieveRTValueTypedOrDefault( - "com.bktus.gpgfrontend.module.integrated.gnupg_info_gathering", + kGnuPGInfoGatheringModuleID, QString("gnupg.components.%1").arg(component), QByteArray{}); GF_UI_LOG_DEBUG("got gnupg component {} info from rt", component); @@ -170,17 +179,16 @@ void GpgFrontend::UI::GnupgTab::process_software_info() { ui_->componentDetailsTable->resizeColumnsToContents(); - auto directories = Module::ListRTChildKeys( - "com.bktus.gpgfrontend.module.integrated.gnupg_info_gathering", - QString("gnupg.dirs")); + auto directories = Module::ListRTChildKeys(kGnuPGInfoGatheringModuleID, + QString("gnupg.dirs")); ui_->directoriesDetailsTable->setRowCount(directories.size()); row = 0; for (auto& dir : directories) { const auto dir_path = Module::RetrieveRTValueTypedOrDefault( - "com.bktus.gpgfrontend.module.integrated.gnupg_info_gathering", - QString("gnupg.dirs.%1").arg(dir), QString{}); + kGnuPGInfoGatheringModuleID, QString("gnupg.dirs.%1").arg(dir), + QString{}); if (dir_path.isEmpty()) continue; @@ -201,12 +209,12 @@ void GpgFrontend::UI::GnupgTab::process_software_info() { row = 0; for (auto& component : components) { auto options = Module::ListRTChildKeys( - "com.bktus.gpgfrontend.module.integrated.gnupg_info_gathering", + kGnuPGInfoGatheringModuleID, QString("gnupg.components.%1.options").arg(component)); for (auto& option : options) { const auto option_info_json = QJsonDocument::fromJson(Module::RetrieveRTValueTypedOrDefault( - "com.bktus.gpgfrontend.module.integrated.gnupg_info_gathering", + kGnuPGInfoGatheringModuleID, QString("gnupg.components.%1.options.%2") .arg(component) .arg(option), @@ -228,12 +236,12 @@ void GpgFrontend::UI::GnupgTab::process_software_info() { QString configuration_group; for (auto& component : components) { auto options = Module::ListRTChildKeys( - "com.bktus.gpgfrontend.module.integrated.gnupg_info_gathering", + kGnuPGInfoGatheringModuleID, QString("gnupg.components.%1.options").arg(component)); for (auto& option : options) { auto option_info_json_bytes = Module::RetrieveRTValueTypedOrDefault( - "com.bktus.gpgfrontend.module.integrated.gnupg_info_gathering", + kGnuPGInfoGatheringModuleID, QString("gnupg.components.%1.options.%2").arg(component).arg(option), QByteArray{}); GF_UI_LOG_DEBUG("got gnupg component's option {} info from rt, info: {}", @@ -291,3 +299,33 @@ void GpgFrontend::UI::GnupgTab::process_software_info() { } // ui_->configurationDetailsTable->resizeColumnsToContents(); } + +void GnupgTab::gather_gnupg_info() { + // if gnupg_info_gathering module activated + if (Module::IsModuleAcivate(kGnuPGInfoGatheringModuleID)) { + GF_CORE_LOG_DEBUG( + "module gnupg_info_gathering is activated, " + "loading external gnupg info..."); + + // 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 index 9e6191db..60abd048 100644 --- a/src/ui/dialog/help/GnupgTab.h +++ b/src/ui/dialog/help/GnupgTab.h @@ -50,6 +50,16 @@ class GnupgTab : public QWidget { private: std::shared_ptr<Ui_GnuPGInfo> ui_; ///< + /** + * @brief + * + */ void process_software_info(); + + /** + * @brief + * + */ + void gather_gnupg_info(); }; } // namespace GpgFrontend::UI diff --git a/src/ui/dialog/import_export/KeyServerImportDialog.cpp b/src/ui/dialog/import_export/KeyServerImportDialog.cpp index 4d999a49..575a97e4 100644 --- a/src/ui/dialog/import_export/KeyServerImportDialog.cpp +++ b/src/ui/dialog/import_export/KeyServerImportDialog.cpp @@ -31,9 +31,9 @@ #include "core/GpgModel.h" #include "core/function/GlobalSettingStation.h" #include "core/function/gpg/GpgKeyImportExporter.h" +#include "core/model/SettingsObject.h" #include "ui/UISignalStation.h" -#include "ui/struct/SettingsObject.h" -#include "ui/struct/settings/KeyServerSO.h" +#include "ui/struct/settings_object/KeyServerSO.h" #include "ui/thread/KeyServerImportTask.h" #include "ui/thread/KeyServerSearchTask.h" diff --git a/src/ui/dialog/import_export/KeyUploadDialog.cpp b/src/ui/dialog/import_export/KeyUploadDialog.cpp index 3fc37c83..7ab34c49 100644 --- a/src/ui/dialog/import_export/KeyUploadDialog.cpp +++ b/src/ui/dialog/import_export/KeyUploadDialog.cpp @@ -33,11 +33,11 @@ #include "core/GpgModel.h" #include "core/function/gpg/GpgKeyGetter.h" #include "core/function/gpg/GpgKeyImportExporter.h" +#include "core/model/SettingsObject.h" #include "core/utils/BuildInfoUtils.h" #include "core/utils/GpgUtils.h" #include "ui/UserInterfaceUtils.h" -#include "ui/struct/SettingsObject.h" -#include "ui/struct/settings/KeyServerSO.h" +#include "ui/struct/settings_object/KeyServerSO.h" namespace GpgFrontend::UI { diff --git a/src/ui/dialog/settings/SettingsAppearance.cpp b/src/ui/dialog/settings/SettingsAppearance.cpp index d4f97c4c..b756ae05 100644 --- a/src/ui/dialog/settings/SettingsAppearance.cpp +++ b/src/ui/dialog/settings/SettingsAppearance.cpp @@ -28,9 +28,9 @@ #include "SettingsAppearance.h" +#include "core/model/SettingsObject.h" #include "core/utils/MemoryUtils.h" -#include "ui/struct/SettingsObject.h" -#include "ui/struct/settings/AppearanceSO.h" +#include "ui/struct/settings_object/AppearanceSO.h" #include "ui_AppearanceSettings.h" namespace GpgFrontend::UI { diff --git a/src/ui/dialog/settings/SettingsKeyServer.cpp b/src/ui/dialog/settings/SettingsKeyServer.cpp index 5613ed45..fb6e624c 100644 --- a/src/ui/dialog/settings/SettingsKeyServer.cpp +++ b/src/ui/dialog/settings/SettingsKeyServer.cpp @@ -31,10 +31,10 @@ #include <cstddef> #include "core/function/GlobalSettingStation.h" +#include "core/model/SettingsObject.h" #include "core/thread/Task.h" #include "core/thread/TaskRunnerGetter.h" -#include "ui/struct/SettingsObject.h" -#include "ui/struct/settings/KeyServerSO.h" +#include "ui/struct/settings_object/KeyServerSO.h" #include "ui/thread/ListedKeyServerTestTask.h" #include "ui_KeyServerSettings.h" diff --git a/src/ui/main_window/GeneralMainWindow.cpp b/src/ui/main_window/GeneralMainWindow.cpp index f58326f9..f925eb18 100644 --- a/src/ui/main_window/GeneralMainWindow.cpp +++ b/src/ui/main_window/GeneralMainWindow.cpp @@ -28,9 +28,9 @@ #include "GeneralMainWindow.h" -#include "ui/struct/SettingsObject.h" -#include "ui/struct/settings/AppearanceSO.h" -#include "ui/struct/settings/WindowStateSO.h" +#include "core/model/SettingsObject.h" +#include "ui/struct/settings_object/AppearanceSO.h" +#include "ui/struct/settings_object/WindowStateSO.h" namespace GpgFrontend::UI { diff --git a/src/ui/main_window/MainWindow.cpp b/src/ui/main_window/MainWindow.cpp index c7acb5bc..fec7f6bf 100644 --- a/src/ui/main_window/MainWindow.cpp +++ b/src/ui/main_window/MainWindow.cpp @@ -33,11 +33,11 @@ #include "core/function/GlobalSettingStation.h" #include "core/function/gpg/GpgAdvancedOperator.h" #include "core/model/GpgPassphraseContext.h" +#include "core/model/SettingsObject.h" #include "core/module/ModuleManager.h" #include "ui/UISignalStation.h" #include "ui/main_window/GeneralMainWindow.h" -#include "ui/struct/SettingsObject.h" -#include "ui/struct/settings/KeyServerSO.h" +#include "ui/struct/settings_object/KeyServerSO.h" #include "ui/widgets/KeyList.h" #include "ui/widgets/TextEdit.h" diff --git a/src/ui/main_window/MainWindowSlotFunction.cpp b/src/ui/main_window/MainWindowSlotFunction.cpp index 8483b578..e75e20bc 100644 --- a/src/ui/main_window/MainWindowSlotFunction.cpp +++ b/src/ui/main_window/MainWindowSlotFunction.cpp @@ -304,7 +304,7 @@ void MainWindow::slot_version_upgrade_nofity() { 30000); auto* update_button = new QPushButton("Update GpgFrontend", this); connect(update_button, &QPushButton::clicked, [=]() { - auto* about_dialog = new AboutDialog(2, this); + auto* about_dialog = new AboutDialog(tr("Update"), this); about_dialog->show(); }); statusBar()->addPermanentWidget(update_button, 0); diff --git a/src/ui/main_window/MainWindowSlotUI.cpp b/src/ui/main_window/MainWindowSlotUI.cpp index 99a26626..897c1950 100644 --- a/src/ui/main_window/MainWindowSlotUI.cpp +++ b/src/ui/main_window/MainWindowSlotUI.cpp @@ -29,12 +29,12 @@ #include "MainWindow.h" #include "core/GpgConstants.h" #include "core/model/GpgPassphraseContext.h" +#include "core/model/SettingsObject.h" #include "ui/UserInterfaceUtils.h" #include "ui/dialog/Wizard.h" #include "ui/function/RaisePinentry.h" #include "ui/main_window/KeyMgmt.h" -#include "ui/struct/SettingsObject.h" -#include "ui/struct/settings/AppearanceSO.h" +#include "ui/struct/settings_object/AppearanceSO.h" #include "ui/widgets/TextEdit.h" namespace GpgFrontend::UI { diff --git a/src/ui/main_window/MainWindowUI.cpp b/src/ui/main_window/MainWindowUI.cpp index 3d321264..c38684d7 100644 --- a/src/ui/main_window/MainWindowUI.cpp +++ b/src/ui/main_window/MainWindowUI.cpp @@ -421,26 +421,29 @@ void MainWindow::create_actions() { connect(about_act_, &QAction::triggered, this, [=]() { new AboutDialog(0, this); }); - gnupg_act_ = new QAction(tr("GnuPG"), this); - gnupg_act_->setIcon(QIcon(":/icons/help.png")); - gnupg_act_->setToolTip(tr("Information about Gnupg")); - connect(gnupg_act_, &QAction::triggered, this, - [=]() { new AboutDialog(1, this); }); + if (Module::IsModuleAcivate( + "com.bktus.gpgfrontend.module.integrated.gnupg_info_gathering")) { + gnupg_act_ = new QAction(tr("GnuPG"), this); + gnupg_act_->setIcon(QIcon(":/icons/help.png")); + gnupg_act_->setToolTip(tr("Information about Gnupg")); + connect(gnupg_act_, &QAction::triggered, this, + [=]() { new AboutDialog(tr("GnuPG"), this); }); + } translate_act_ = new QAction(tr("Translate"), this); translate_act_->setIcon(QIcon(":/icons/help.png")); translate_act_->setToolTip(tr("Information about translation")); connect(translate_act_, &QAction::triggered, this, - [=]() { new AboutDialog(2, this); }); - - /* - * Check Update Menu - */ - 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")); - connect(check_update_act_, &QAction::triggered, this, - [=]() { new AboutDialog(3, this); }); + [=]() { new AboutDialog(tr("Translators"), this); }); + + if (Module::IsModuleAcivate( + "com.bktus.gpgfrontend.module.integrated.version_checking")) { + 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")); + connect(check_update_act_, &QAction::triggered, this, + [=]() { new AboutDialog(tr("Update"), this); }); + } start_wizard_act_ = new QAction(tr("Open Wizard"), this); start_wizard_act_->setToolTip(tr("Open the wizard")); diff --git a/src/ui/struct/settings/AppearanceSO.h b/src/ui/struct/settings_object/AppearanceSO.h index 25262f22..25262f22 100644 --- a/src/ui/struct/settings/AppearanceSO.h +++ b/src/ui/struct/settings_object/AppearanceSO.h diff --git a/src/ui/struct/settings/KeyServerSO.h b/src/ui/struct/settings_object/KeyServerSO.h index 3c9320d2..3c9320d2 100644 --- a/src/ui/struct/settings/KeyServerSO.h +++ b/src/ui/struct/settings_object/KeyServerSO.h diff --git a/src/ui/struct/settings/WindowStateSO.h b/src/ui/struct/settings_object/WindowStateSO.h index 3fa56f3c..3fa56f3c 100644 --- a/src/ui/struct/settings/WindowStateSO.h +++ b/src/ui/struct/settings_object/WindowStateSO.h diff --git a/src/ui/thread/KeyServerImportTask.cpp b/src/ui/thread/KeyServerImportTask.cpp index ed8b7646..8bcb2eab 100644 --- a/src/ui/thread/KeyServerImportTask.cpp +++ b/src/ui/thread/KeyServerImportTask.cpp @@ -29,9 +29,9 @@ #include "ui/thread/KeyServerImportTask.h" #include "core/function/gpg/GpgKeyImportExporter.h" +#include "core/model/SettingsObject.h" #include "core/utils/BuildInfoUtils.h" -#include "ui/struct/SettingsObject.h" -#include "ui/struct/settings/KeyServerSO.h" +#include "ui/struct/settings_object/KeyServerSO.h" GpgFrontend::UI::KeyServerImportTask::KeyServerImportTask( QString keyserver_url, std::vector<QString> keyids) diff --git a/src/ui/widgets/InfoBoardWidget.cpp b/src/ui/widgets/InfoBoardWidget.cpp index d1a006c5..425e6ccd 100644 --- a/src/ui/widgets/InfoBoardWidget.cpp +++ b/src/ui/widgets/InfoBoardWidget.cpp @@ -29,9 +29,9 @@ #include "ui/widgets/InfoBoardWidget.h" #include "core/GpgModel.h" +#include "core/model/SettingsObject.h" #include "ui/UISignalStation.h" -#include "ui/struct/SettingsObject.h" -#include "ui/struct/settings/AppearanceSO.h" +#include "ui/struct/settings_object/AppearanceSO.h" #include "ui_InfoBoard.h" namespace GpgFrontend::UI { diff --git a/src/ui/widgets/PlainTextEditorPage.cpp b/src/ui/widgets/PlainTextEditorPage.cpp index 8f4890cc..874bbf3b 100644 --- a/src/ui/widgets/PlainTextEditorPage.cpp +++ b/src/ui/widgets/PlainTextEditorPage.cpp @@ -28,10 +28,10 @@ #include "PlainTextEditorPage.h" +#include "core/model/SettingsObject.h" #include "core/thread/FileReadTask.h" #include "core/thread/TaskRunnerGetter.h" -#include "ui/struct/SettingsObject.h" -#include "ui/struct/settings/AppearanceSO.h" +#include "ui/struct/settings_object/AppearanceSO.h" #include "ui_PlainTextEditor.h" namespace GpgFrontend::UI { diff --git a/src/ui/widgets/TextEdit.cpp b/src/ui/widgets/TextEdit.cpp index 1373c5d9..25fce9b8 100644 --- a/src/ui/widgets/TextEdit.cpp +++ b/src/ui/widgets/TextEdit.cpp @@ -34,8 +34,8 @@ #include "core/GpgModel.h" #include "core/function/GlobalSettingStation.h" +#include "core/model/CacheObject.h" #include "ui/UISignalStation.h" -#include "ui/struct/CacheObject.h" namespace GpgFrontend::UI { |