diff options
Diffstat (limited to 'src/ui/dialog/help')
-rw-r--r-- | src/ui/dialog/help/AboutDialog.cpp | 50 | ||||
-rw-r--r-- | src/ui/dialog/help/AboutDialog.h | 2 | ||||
-rw-r--r-- | src/ui/dialog/help/GnupgTab.cpp | 70 | ||||
-rw-r--r-- | src/ui/dialog/help/GnupgTab.h | 10 |
4 files changed, 91 insertions, 41 deletions
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 |