aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/core/GpgFunctionObject.h2
-rw-r--r--src/core/function/CacheManager.cpp4
-rw-r--r--src/core/module/GlobalRegisterTable.cpp59
-rw-r--r--src/core/module/ModuleManager.cpp13
-rw-r--r--src/core/module/ModuleManager.h11
-rw-r--r--src/module/integrated/version_checking_module/VersionCheckingModule.cpp48
-rw-r--r--src/ui/main_window/GeneralMainWindow.cpp2
-rw-r--r--src/ui/main_window/MainWindow.cpp74
-rw-r--r--src/ui/main_window/MainWindow.h14
-rw-r--r--src/ui/main_window/MainWindowSlotFunction.cpp37
-rw-r--r--src/ui/thread/ListedKeyServerTestTask.cpp4
11 files changed, 137 insertions, 131 deletions
diff --git a/src/core/GpgFunctionObject.h b/src/core/GpgFunctionObject.h
index 37315b68..7a26828a 100644
--- a/src/core/GpgFunctionObject.h
+++ b/src/core/GpgFunctionObject.h
@@ -225,7 +225,7 @@ class SingletonFunctionObject : public ChannelObject {
if (_p_pbj == nullptr) {
return *(
- T*)(p_storage->SetObjectInChannel(channel, std::move(factory())));
+ T*)(p_storage->SetObjectInChannel(channel, factory()));
} else
return *_p_pbj;
}
diff --git a/src/core/function/CacheManager.cpp b/src/core/function/CacheManager.cpp
index 1794735a..27133957 100644
--- a/src/core/function/CacheManager.cpp
+++ b/src/core/function/CacheManager.cpp
@@ -36,8 +36,8 @@
#include "spdlog/spdlog.h"
GpgFrontend::CacheManager::CacheManager(int channel)
- : m_timer_(new QTimer(this)),
- SingletonFunctionObject<CacheManager>(channel) {
+ : SingletonFunctionObject<CacheManager>(channel),
+ m_timer_(new QTimer(this)) {
connect(m_timer_, &QTimer::timeout, this, &CacheManager::flush_cache_storage);
m_timer_->start(15000);
diff --git a/src/core/module/GlobalRegisterTable.cpp b/src/core/module/GlobalRegisterTable.cpp
index a4910f9f..42a8f1f7 100644
--- a/src/core/module/GlobalRegisterTable.cpp
+++ b/src/core/module/GlobalRegisterTable.cpp
@@ -52,42 +52,51 @@ class GlobalRegisterTable::Impl {
: parent_(parent), global_register_table_() {}
bool PublishKV(Namespace n, Key k, std::any v) {
- std::unique_lock lock(lock_);
SPDLOG_DEBUG("publishing kv to rt, n: {}, k: {}, v type: {}", n, k,
v.type().name());
- auto& sub_table =
- global_register_table_.emplace(n, SubTable{}).first->second;
-
- auto sub_it = sub_table.find(k);
- if (sub_it == sub_table.end()) {
- sub_it = sub_table.emplace(k, std::make_unique<Value>(Value{v})).first;
- SPDLOG_DEBUG("new kv in rt, created n: {}, k: {}, v type: {}", n, k,
- v.type().name());
- } else {
- if (sub_it->second->type != v.type()) {
- return false;
+ int version = 0;
+
+ {
+ std::unique_lock lock(lock_);
+ auto& sub_table =
+ global_register_table_.emplace(n, SubTable{}).first->second;
+
+ auto sub_it = sub_table.find(k);
+ if (sub_it == sub_table.end()) {
+ sub_it = sub_table.emplace(k, std::make_unique<Value>(Value{v})).first;
+ SPDLOG_DEBUG("new kv in rt, created n: {}, k: {}, v type: {}", n, k,
+ v.type().name());
+ } else {
+ if (sub_it->second->type != v.type()) {
+ return false;
+ }
+ sub_it->second->value = v;
}
- sub_it->second->value = v;
+ version = ++sub_it->second->version;
}
- sub_it->second->version++;
- emit parent_->SignalPublish(n, k, sub_it->second->version);
+ emit parent_->SignalPublish(n, k, version);
+ SPDLOG_DEBUG("published kv to rt, n: {}, k: {}", n, k);
return true;
}
std::optional<std::any> LookupKV(Namespace n, Key k) {
- std::shared_lock lock(lock_);
SPDLOG_DEBUG("looking up kv in rt, n: {}, k: {}", n, k);
-
- auto it = global_register_table_.find(n);
- if (it == global_register_table_.end()) return std::nullopt;
-
- auto& sub_table = it->second;
- auto sub_it = sub_table.find(k);
- return (sub_it != sub_table.end())
- ? std::optional<std::any>{sub_it->second->value}
- : std::nullopt;
+ std::optional<std::any> rtn = std::nullopt;
+ {
+ std::shared_lock lock(lock_);
+ auto it = global_register_table_.find(n);
+ if (it == global_register_table_.end()) return std::nullopt;
+
+ auto& sub_table = it->second;
+ auto sub_it = sub_table.find(k);
+ rtn = (sub_it != sub_table.end())
+ ? std::optional<std::any>{sub_it->second->value}
+ : std::nullopt;
+ }
+ SPDLOG_DEBUG("looking up kv in rt done, n: {}, k: {}", n, k);
+ return rtn;
}
bool ListenPublish(QObject* o, Namespace n, Key k, LPCallback c) {
diff --git a/src/core/module/ModuleManager.cpp b/src/core/module/ModuleManager.cpp
index 20f9ab28..c151ebb1 100644
--- a/src/core/module/ModuleManager.cpp
+++ b/src/core/module/ModuleManager.cpp
@@ -100,12 +100,17 @@ class ModuleManager::Impl {
GRTPtr grt_;
};
-bool UpsertRTValueTyped(const std::string& namespace_, const std::string& key,
- const std::any& value) {
+bool UpsertRTValue(const std::string& namespace_, const std::string& key,
+ const std::any& value) {
return ModuleManager::GetInstance()->UpsertRTValue(namespace_, key,
std::any(value));
}
+bool GPGFRONTEND_CORE_EXPORT ListenRTPublishEvent(QObject* o, Namespace n,
+ Key k, LPCallback c) {
+ return ModuleManager::GetInstance()->ListenRTPublish(o, n, k, c);
+}
+
ModuleManager::ModuleManager() : p_(std::make_unique<Impl>()) {}
ModuleManager::~ModuleManager() = default;
@@ -140,8 +145,8 @@ std::optional<std::any> ModuleManager::RetrieveRTValue(Namespace n, Key k) {
return p_->RetrieveRTValue(n, k);
}
-bool ModuleManager::ListenPublish(QObject* o, Namespace n, Key k,
- LPCallback c) {
+bool ModuleManager::ListenRTPublish(QObject* o, Namespace n, Key k,
+ LPCallback c) {
return p_->ListenPublish(o, n, k, c);
}
diff --git a/src/core/module/ModuleManager.h b/src/core/module/ModuleManager.h
index 586627b6..865f196b 100644
--- a/src/core/module/ModuleManager.h
+++ b/src/core/module/ModuleManager.h
@@ -76,7 +76,7 @@ class GPGFRONTEND_CORE_EXPORT ModuleManager : public QObject {
std::optional<std::any> RetrieveRTValue(Namespace, Key);
- bool ListenPublish(QObject*, Namespace, Key, LPCallback);
+ bool ListenRTPublish(QObject*, Namespace, Key, LPCallback);
private:
class Impl;
@@ -106,9 +106,12 @@ void TriggerEvent(const EventIdentifier& event_id, Args&&... args) {
std::move(MakeEvent(event_id, std::forward<Args>(args)...)));
}
-bool GPGFRONTEND_CORE_EXPORT UpsertRTValueTyped(const std::string& namespace_,
- const std::string& key,
- const std::any& value);
+bool GPGFRONTEND_CORE_EXPORT UpsertRTValue(const std::string& namespace_,
+ const std::string& key,
+ const std::any& value);
+
+bool GPGFRONTEND_CORE_EXPORT ListenRTPublishEvent(QObject*, Namespace, Key,
+ LPCallback);
template <typename T>
std::optional<T> RetrieveRTValueTyped(const std::string& namespace_,
diff --git a/src/module/integrated/version_checking_module/VersionCheckingModule.cpp b/src/module/integrated/version_checking_module/VersionCheckingModule.cpp
index bab30c33..52277394 100644
--- a/src/module/integrated/version_checking_module/VersionCheckingModule.cpp
+++ b/src/module/integrated/version_checking_module/VersionCheckingModule.cpp
@@ -75,31 +75,29 @@ bool VersionCheckingModule::Deactive() { return true; }
void VersionCheckingModule::SlotVersionCheckDone(SoftwareVersion version) {
MODULE_LOG_DEBUG("registering software information info to rt");
- UpsertRTValueTyped(GetModuleIdentifier(), "version.current_version",
- version.current_version);
- UpsertRTValueTyped(GetModuleIdentifier(), "version.loading_done",
- version.loading_done);
- UpsertRTValueTyped(GetModuleIdentifier(), "version.latest_version",
- version.latest_version);
- UpsertRTValueTyped(GetModuleIdentifier(),
- "version.current_version_is_drafted",
- version.current_version_is_drafted);
- UpsertRTValueTyped(GetModuleIdentifier(),
- "version.current_version_is_a_prerelease",
- version.current_version_is_a_prerelease);
- UpsertRTValueTyped(GetModuleIdentifier(),
- "version.current_version_publish_in_remote",
- version.current_version_publish_in_remote);
- UpsertRTValueTyped(GetModuleIdentifier(),
- "version.latest_prerelease_version_from_remote",
- version.latest_prerelease_version_from_remote);
- UpsertRTValueTyped(GetModuleIdentifier(), "version.need_upgrade",
- version.NeedUpgrade());
- UpsertRTValueTyped(GetModuleIdentifier(), "version.current_version_released",
- version.CurrentVersionReleased());
- UpsertRTValueTyped(GetModuleIdentifier(),
- "version.current_a_withdrawn_version",
- version.VersionWithdrawn());
+ UpsertRTValue(GetModuleIdentifier(), "version.current_version",
+ version.current_version);
+ UpsertRTValue(GetModuleIdentifier(), "version.latest_version",
+ version.latest_version);
+ UpsertRTValue(GetModuleIdentifier(), "version.current_version_is_drafted",
+ version.current_version_is_drafted);
+ UpsertRTValue(GetModuleIdentifier(),
+ "version.current_version_is_a_prerelease",
+ version.current_version_is_a_prerelease);
+ UpsertRTValue(GetModuleIdentifier(),
+ "version.current_version_publish_in_remote",
+ version.current_version_publish_in_remote);
+ UpsertRTValue(GetModuleIdentifier(),
+ "version.latest_prerelease_version_from_remote",
+ version.latest_prerelease_version_from_remote);
+ UpsertRTValue(GetModuleIdentifier(), "version.need_upgrade",
+ version.NeedUpgrade());
+ UpsertRTValue(GetModuleIdentifier(), "version.current_version_released",
+ version.CurrentVersionReleased());
+ UpsertRTValue(GetModuleIdentifier(), "version.current_a_withdrawn_version",
+ version.VersionWithdrawn());
+ UpsertRTValue(GetModuleIdentifier(), "version.loading_done",
+ version.loading_done);
MODULE_LOG_DEBUG("register software information to rt done");
}
} // namespace GpgFrontend::Module::Integrated::VersionCheckingModule
diff --git a/src/ui/main_window/GeneralMainWindow.cpp b/src/ui/main_window/GeneralMainWindow.cpp
index 6dd94cea..a62d862c 100644
--- a/src/ui/main_window/GeneralMainWindow.cpp
+++ b/src/ui/main_window/GeneralMainWindow.cpp
@@ -34,7 +34,7 @@
GpgFrontend::UI::GeneralMainWindow::GeneralMainWindow(std::string name,
QWidget *parent)
- : name_(std::move(name)), QMainWindow(parent) {
+ : QMainWindow(parent), name_(std::move(name)) {
slot_restore_settings();
}
diff --git a/src/ui/main_window/MainWindow.cpp b/src/ui/main_window/MainWindow.cpp
index 96210219..31fec620 100644
--- a/src/ui/main_window/MainWindow.cpp
+++ b/src/ui/main_window/MainWindow.cpp
@@ -28,17 +28,14 @@
#include "MainWindow.h"
-#include "core/GpgConstants.h"
#include "core/function/CacheManager.h"
#include "core/function/GlobalSettingStation.h"
#include "core/function/gpg/GpgAdvancedOperator.h"
#include "core/module/ModuleManager.h"
-#include "main_window/GeneralMainWindow.h"
-#include "spdlog/spdlog.h"
#include "ui/SignalStation.h"
-#include "ui/UserInterfaceUtils.h"
+#include "ui/main_window/GeneralMainWindow.h"
#include "ui/struct/SettingsObject.h"
-#include "widgets/KeyList.h"
+#include "ui/widgets/KeyList.h"
namespace GpgFrontend::UI {
@@ -119,6 +116,40 @@ void MainWindow::Init() noexcept {
edit_->CurTextPage()->setFocus();
+ // before application exit
+ connect(qApp, &QCoreApplication::aboutToQuit, this, []() {
+ SPDLOG_DEBUG("about to quit process started");
+
+ if (GlobalSettingStation::GetInstance().LookupSettings(
+ "general.clear_gpg_password_cache", false)) {
+ if (GpgFrontend::GpgAdvancedOperator::GetInstance()
+ .ClearGpgPasswordCache()) {
+ SPDLOG_DEBUG("clear gpg password cache done");
+ } else {
+ SPDLOG_ERROR("clear gpg password cache error");
+ }
+ }
+ });
+
+ Module::ListenRTPublishEvent(
+ this,
+ Module::GetRealModuleIdentifier(
+ "com.bktus.gpgfrontend.module.integrated.versionchecking"),
+ "version.loading_done", [=](Module::Namespace, Module::Key, int) {
+ SPDLOG_DEBUG(
+ "versionchecking version.loading_done changed, calling slot "
+ "version upgrade");
+ this->slot_version_upgrade_nofity();
+ });
+
+ // loading process is done
+ emit SignalLoaded();
+ Module::TriggerEvent("APPLICATION_LOADED");
+
+ // recover unsaved page from cache if it exists
+ recover_editor_unsaved_pages_from_cache();
+
+ // check if need to open wizard window
auto &settings = GlobalSettingStation::GetInstance().GetMainSettings();
if (!settings.exists("wizard") ||
@@ -142,39 +173,6 @@ void MainWindow::Init() noexcept {
slot_start_wizard();
}
- emit SignalLoaded();
- Module::TriggerEvent("APPLICATION_LOADED");
-
- // if not prohibit update checking
- if (!prohibit_update_checking_) {
- // auto *version_task = new VersionCheckTask();
-
- // connect(version_task, &VersionCheckTask::SignalUpgradeVersion, this,
- // &MainWindow::slot_version_upgrade);
-
- // Thread::TaskRunnerGetter::GetInstance()
- // .GetTaskRunner(Thread::TaskRunnerGetter::kTaskRunnerType_Network)
- // ->PostTask(version_task);
- }
-
- // before application exit
- connect(qApp, &QCoreApplication::aboutToQuit, this, []() {
- SPDLOG_DEBUG("about to quit process started");
-
- if (GlobalSettingStation::GetInstance().LookupSettings(
- "general.clear_gpg_password_cache", false)) {
- if (GpgFrontend::GpgAdvancedOperator::GetInstance()
- .ClearGpgPasswordCache()) {
- SPDLOG_DEBUG("clear gpg password cache done");
- } else {
- SPDLOG_ERROR("clear gpg password cache error");
- }
- }
- });
-
- // recover unsaved page from cache if it exists
- recover_editor_unsaved_pages_from_cache();
-
} catch (...) {
SPDLOG_ERROR(_("Critical error occur while loading GpgFrontend."));
QMessageBox::critical(nullptr, _("Loading Failed"),
diff --git a/src/ui/main_window/MainWindow.h b/src/ui/main_window/MainWindow.h
index 34cdf5b2..f26a0a36 100644
--- a/src/ui/main_window/MainWindow.h
+++ b/src/ui/main_window/MainWindow.h
@@ -28,19 +28,7 @@
#pragma once
-#include "KeyMgmt.h"
-#include "core/GpgConstants.h"
-#include "core/function/result_analyse/GpgDecryptResultAnalyse.h"
-#include "core/function/result_analyse/GpgEncryptResultAnalyse.h"
-#include "core/function/result_analyse/GpgSignResultAnalyse.h"
-#include "ui/GpgFrontendUI.h"
-#include "ui/dialog/WaitingDialog.h"
-#include "ui/dialog/Wizard.h"
-#include "ui/dialog/help/AboutDialog.h"
-#include "ui/dialog/import_export/KeyUploadDialog.h"
-#include "ui/dialog/settings/SettingsDialog.h"
#include "ui/main_window/GeneralMainWindow.h"
-#include "ui/widgets/FindWidget.h"
#include "ui/widgets/InfoBoardWidget.h"
#include "ui/widgets/TextEdit.h"
@@ -314,7 +302,7 @@ class MainWindow : public GeneralMainWindow {
/**
* @details called when need to upgrade.
*/
- void slot_version_upgrade();
+ void slot_version_upgrade_nofity();
/**
* @details
diff --git a/src/ui/main_window/MainWindowSlotFunction.cpp b/src/ui/main_window/MainWindowSlotFunction.cpp
index 35f7f5ed..dc4b3965 100644
--- a/src/ui/main_window/MainWindowSlotFunction.cpp
+++ b/src/ui/main_window/MainWindowSlotFunction.cpp
@@ -28,24 +28,26 @@
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/date_time/posix_time/posix_time_io.hpp>
-#include <memory>
-#include <string>
-#include <utility>
#include "MainWindow.h"
#include "core/GpgConstants.h"
-#include "core/GpgContext.h"
#include "core/GpgModel.h"
#include "core/function/gpg/GpgBasicOperator.h"
#include "core/function/gpg/GpgKeyGetter.h"
#include "core/function/gpg/GpgKeyImportExporter.h"
#include "core/function/gpg/GpgKeyManager.h"
+#include "core/function/result_analyse/GpgDecryptResultAnalyse.h"
+#include "core/function/result_analyse/GpgEncryptResultAnalyse.h"
+#include "core/function/result_analyse/GpgSignResultAnalyse.h"
+#include "core/function/result_analyse/GpgVerifyResultAnalyse.h"
#include "core/module/ModuleManager.h"
#include "core/thread/DataObject.h"
-#include "dialog/SignersPicker.h"
-#include "spdlog/spdlog.h"
#include "ui/UserInterfaceUtils.h"
+#include "ui/dialog/SignersPicker.h"
#include "ui/dialog/help/AboutDialog.h"
+#include "ui/dialog/import_export/KeyUploadDialog.h"
+#include "ui/dialog/keypair_details/KeyDetailsDialog.h"
+#include "ui/widgets/FindWidget.h"
namespace GpgFrontend::UI {
/**
@@ -60,8 +62,8 @@ void MainWindow::slot_encrypt() {
auto key_ids = m_key_list_->GetChecked();
// data to transfer into task
- auto data_object = Thread::TransferParams(std::move(
- edit_->CurTextPage()->GetTextPage()->toPlainText().toStdString()));
+ auto data_object = Thread::TransferParams(
+ edit_->CurTextPage()->GetTextPage()->toPlainText().toStdString());
// the callback function
auto result_callback = [this](int rtn, Thread::DataObjectPtr data_object) {
@@ -121,7 +123,6 @@ void MainWindow::slot_encrypt() {
};
} else {
- auto& key_getter = GpgFrontend::GpgKeyGetter::GetInstance();
auto keys = GpgKeyGetter::GetInstance().GetKeys(key_ids);
for (const auto& key : *keys) {
if (!key.IsHasActualEncryptionCapability()) {
@@ -435,8 +436,7 @@ void MainWindow::slot_encrypt_sign() {
// data to transfer into task
auto data_object = Thread::TransferParams(
std::move(signer_keys), std::move(keys),
- std::move(
- edit_->CurTextPage()->GetTextPage()->toPlainText().toStdString()));
+ edit_->CurTextPage()->GetTextPage()->toPlainText().toStdString());
auto encrypt_sign_runner = [](Thread::DataObjectPtr data_object) -> int {
// check the size of the data object
@@ -506,8 +506,8 @@ void MainWindow::slot_decrypt_verify() {
}
// data to transfer into task
- auto data_object = Thread::TransferParams(std::move(
- edit_->CurTextPage()->GetTextPage()->toPlainText().toStdString()));
+ auto data_object = Thread::TransferParams(
+ edit_->CurTextPage()->GetTextPage()->toPlainText().toStdString());
auto decrypt_verify_runner = [](Thread::DataObjectPtr data_object) -> int {
// check the size of the data object
@@ -816,14 +816,18 @@ void MainWindow::upload_key_to_server() {
void MainWindow::SlotOpenFile(QString& path) { edit_->SlotOpenFile(path); }
-void MainWindow::slot_version_upgrade() {
+void MainWindow::slot_version_upgrade_nofity() {
+ SPDLOG_DEBUG(
+ "slot version upgrade notify called, checking version info from rt...");
auto is_loading_done = Module::RetrieveRTValueTypedOrDefault<>(
Module::GetRealModuleIdentifier(
"com.bktus.gpgfrontend.module.integrated.versionchecking"),
"version.loading_done", false);
+ SPDLOG_DEBUG("checking version info from rt, is loading done state: {}",
+ is_loading_done);
if (!is_loading_done) {
- SPDLOG_ERROR("invalid version info from rt");
+ SPDLOG_ERROR("invalid version info from rt, loading hasn't done yet");
return;
}
@@ -848,7 +852,8 @@ void MainWindow::slot_version_upgrade() {
"version.latest_version", std::string{});
SPDLOG_DEBUG(
- "version info, need upgrade: {}, with drawn: {}, current version "
+ "got version info from rt, need upgrade: {}, with drawn: {}, current "
+ "version "
"released: {}",
is_need_upgrade, is_current_a_withdrawn_version,
is_current_version_released);
diff --git a/src/ui/thread/ListedKeyServerTestTask.cpp b/src/ui/thread/ListedKeyServerTestTask.cpp
index 38495f55..28eb33f7 100644
--- a/src/ui/thread/ListedKeyServerTestTask.cpp
+++ b/src/ui/thread/ListedKeyServerTestTask.cpp
@@ -35,9 +35,9 @@ GpgFrontend::UI::ListedKeyServerTestTask::ListedKeyServerTestTask(
const QStringList& urls, int timeout, QWidget* parent)
: Task("listed_key_server_test_task"),
urls_(urls),
- timeout_(timeout),
+ result_(urls_.size(), kTestResultType_Error),
network_manager_(new QNetworkAccessManager(this)),
- result_(urls_.size(), kTestResultType_Error) {
+ timeout_(timeout) {
HoldOnLifeCycle(true);
qRegisterMetaType<std::vector<KeyServerTestResultType>>(
"std::vector<KeyServerTestResultType>");