aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/core/GpgContext.cpp19
-rw-r--r--src/core/GpgContext.h4
-rw-r--r--src/core/GpgCoreInit.cpp116
-rw-r--r--src/core/function/GlobalSettingStation.cpp8
-rw-r--r--src/core/function/GlobalSettingStation.h18
-rw-r--r--src/init.cpp29
-rw-r--r--src/ui/GpgFrontendUIInit.cpp33
-rw-r--r--src/ui/dialog/Wizard.cpp9
-rw-r--r--src/ui/dialog/import_export/KeyServerImportDialog.cpp13
-rw-r--r--src/ui/dialog/key_generate/KeygenDialog.cpp24
-rw-r--r--src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp24
-rw-r--r--src/ui/dialog/settings/SettingsAdvanced.cpp23
-rw-r--r--src/ui/main_window/KeyMgmt.cpp15
-rw-r--r--src/ui/main_window/MainWindow.cpp52
-rw-r--r--src/ui/main_window/MainWindowFileSlotFunction.cpp44
-rw-r--r--src/ui/main_window/MainWindowUI.cpp13
-rw-r--r--src/ui/widgets/KeyList.cpp25
-rw-r--r--src/ui/widgets/VerifyKeyDetailBox.cpp13
18 files changed, 188 insertions, 294 deletions
diff --git a/src/core/GpgContext.cpp b/src/core/GpgContext.cpp
index 47ff77c4..1cb137e6 100644
--- a/src/core/GpgContext.cpp
+++ b/src/core/GpgContext.cpp
@@ -30,6 +30,7 @@
#include <gpg-error.h>
#include <gpgme.h>
+#include <spdlog/spdlog.h>
#include <unistd.h>
#include <mutex>
@@ -37,14 +38,11 @@
#include <string>
#include "core/GpgConstants.h"
-#include "core/GpgModel.h"
#include "core/common/CoreCommonUtil.h"
#include "core/function/CoreSignalStation.h"
-#include "core/function/GlobalSettingStation.h"
#include "core/function/gpg/GpgCommandExecutor.h"
+#include "core/thread/Task.h"
#include "core/thread/TaskRunnerGetter.h"
-#include "spdlog/spdlog.h"
-#include "thread/Task.h"
#ifdef _WIN32
#include <windows.h>
@@ -232,19 +230,8 @@ void GpgContext::post_init_ctx() {
// preload info
auto &info = GetInfo();
- auto &settings = GlobalSettingStation::GetInstance().GetUISettings();
-
- bool use_pinentry_as_password_input_dialog = false;
- try {
- use_pinentry_as_password_input_dialog =
- settings.lookup("general.use_pinentry_as_password_input_dialog");
- } catch (...) {
- SPDLOG_ERROR(
- "setting operation error: use_pinentry_as_password_input_dialog");
- }
-
// use custom qt dialog to replace pinentry
- if (!use_pinentry_as_password_input_dialog) {
+ if (!args_.use_pinentry) {
SetPassphraseCb(custom_passphrase_cb);
}
diff --git a/src/core/GpgContext.h b/src/core/GpgContext.h
index a199e62d..474530c6 100644
--- a/src/core/GpgContext.h
+++ b/src/core/GpgContext.h
@@ -32,10 +32,8 @@
#include <optional>
#include <string>
-#include "GpgConstants.h"
#include "GpgFunctionObject.h"
#include "GpgInfo.h"
-#include "GpgModel.h"
namespace GpgFrontend {
@@ -59,6 +57,8 @@ struct GpgContextInitArgs {
bool custom_gpgconf = false;
std::string custom_gpgconf_path;
+ bool use_pinentry = false;
+
GpgContextInitArgs() = default;
};
diff --git a/src/core/GpgCoreInit.cpp b/src/core/GpgCoreInit.cpp
index 48883048..b4d7f1fc 100644
--- a/src/core/GpgCoreInit.cpp
+++ b/src/core/GpgCoreInit.cpp
@@ -33,6 +33,7 @@
#include <spdlog/sinks/stdout_color_sinks.h>
#include <filesystem>
+#include <string>
#include "GpgFunctionObject.h"
#include "core/GpgContext.h"
@@ -108,76 +109,58 @@ void init_gpgfrontend_core() {
gpgme_set_locale(nullptr, LC_MESSAGES, setlocale(LC_MESSAGES, nullptr));
#endif
- // get settings
- auto& settings = GlobalSettingStation::GetInstance().GetUISettings();
-
// read settings
- bool forbid_all_gnupg_connection = false;
- try {
- forbid_all_gnupg_connection =
- settings.lookup("network.forbid_all_gnupg_connection");
- } catch (...) {
- SPDLOG_ERROR("setting operation error: forbid_all_gnupg_connection");
- }
+ bool forbid_all_gnupg_connection =
+ GlobalSettingStation::GetInstance().LookupSettings(
+ "network.forbid_all_gnupg_connection", false);
- bool auto_import_missing_key = false;
- try {
- auto_import_missing_key =
- settings.lookup("network.auto_import_missing_key");
- } catch (...) {
- SPDLOG_ERROR("setting operation error: auto_import_missing_key");
- }
+ bool auto_import_missing_key =
+ GlobalSettingStation::GetInstance().LookupSettings(
+ "network.auto_import_missing_key", false);
- // read from settings file
- bool use_custom_key_database_path = false;
- try {
- use_custom_key_database_path =
- settings.lookup("general.use_custom_key_database_path");
- } catch (...) {
- SPDLOG_ERROR("setting operation error: use_custom_key_database_path");
- }
+ bool use_custom_key_database_path =
+ GlobalSettingStation::GetInstance().LookupSettings(
+ "general.use_custom_key_database_path", false);
- SPDLOG_DEBUG("core loaded if use custom key databse path: {}",
- use_custom_key_database_path);
+ std::string custom_key_database_path =
+ GlobalSettingStation::GetInstance().LookupSettings(
+ "general.custom_key_database_path", std::string{});
- std::string custom_key_database_path;
- try {
- custom_key_database_path = static_cast<std::string>(
- settings.lookup("general.custom_key_database_path"));
+ bool use_custom_gnupg_install_path =
+ GlobalSettingStation::GetInstance().LookupSettings(
+ "general.use_custom_gnupg_install_path", false);
- } catch (...) {
- SPDLOG_ERROR("setting operation error: custom_key_database_path");
- }
+ std::string custom_gnupg_install_path =
+ GlobalSettingStation::GetInstance().LookupSettings(
+ "general.custom_gnupg_install_path", std::string{});
+
+ bool use_pinentry_as_password_input_dialog =
+ GpgFrontend::GlobalSettingStation::GetInstance().LookupSettings(
+ "general.use_pinentry_as_password_input_dialog", false);
+ SPDLOG_DEBUG("core loaded if use custom key databse path: {}",
+ use_custom_key_database_path);
SPDLOG_DEBUG("core loaded custom key databse path: {}",
custom_key_database_path);
- bool use_custom_gnupg_install_path = false;
- try {
- use_custom_gnupg_install_path =
- settings.lookup("general.use_custom_gnupg_install_path");
- } catch (...) {
- SPDLOG_ERROR("setting operation error: use_custom_gnupg_install_path");
- }
-
- // read from settings file
- std::filesystem::path custom_gnupg_install_path;
- try {
- custom_gnupg_install_path = std::filesystem::path(static_cast<std::string>(
- settings.lookup("general.custom_gnupg_install_path")));
-
- } catch (...) {
- SPDLOG_ERROR("setting operation error: custom_gnupg_install_path");
- }
-
// check gpgconf path
- if (!custom_gnupg_install_path.is_absolute()) {
+ std::filesystem::path custom_gnupg_install_fs_path =
+ custom_gnupg_install_path;
+#ifdef WINDOWS
+ custom_gnupg_install_fs_path /= "gpgconf.exe";
+#else
+ custom_gnupg_install_fs_path /= "gpgconf";
+#endif
+
+ if (!custom_gnupg_install_fs_path.is_absolute() ||
+ !std::filesystem::exists(custom_gnupg_install_fs_path) ||
+ !std::filesystem::is_regular_file(custom_gnupg_install_fs_path)) {
use_custom_gnupg_install_path = false;
- SPDLOG_ERROR("core loaded custom gpgconf path error: {}",
- custom_gnupg_install_path.u8string());
+ SPDLOG_ERROR("core loaded custom gpgconf path is illegal: {}",
+ custom_gnupg_install_fs_path.u8string());
} else {
SPDLOG_DEBUG("core loaded custom gpgconf path: {}",
- custom_gnupg_install_path.u8string());
+ custom_gnupg_install_fs_path.u8string());
}
// init default channel
@@ -190,22 +173,22 @@ void init_gpgfrontend_core() {
args.db_path = custom_key_database_path;
}
- args.offline_mode = forbid_all_gnupg_connection;
- args.auto_import_missing_key = auto_import_missing_key;
-
if (use_custom_gnupg_install_path) {
args.custom_gpgconf = true;
args.custom_gpgconf_path =
- (custom_gnupg_install_path / "gpgconf").u8string();
+ (custom_gnupg_install_fs_path / "gpgconf").u8string();
}
+ args.offline_mode = forbid_all_gnupg_connection;
+ args.auto_import_missing_key = auto_import_missing_key;
+ args.use_pinentry = use_pinentry_as_password_input_dialog;
+
return std::unique_ptr<ChannelObject>(new GpgContext(args));
});
// exit if failed
if (!default_ctx.good()) {
- SPDLOG_ERROR("default gpgme context init error, exit.");
- return;
+ SPDLOG_ERROR("default gnupg context init error");
};
// async init no-ascii channel
@@ -226,13 +209,20 @@ void init_gpgfrontend_core() {
args.db_path = custom_key_database_path;
}
+ if (use_custom_gnupg_install_path) {
+ args.custom_gpgconf = true;
+ args.custom_gpgconf_path =
+ (custom_gnupg_install_fs_path / "gpgconf").u8string();
+ }
+
args.offline_mode = forbid_all_gnupg_connection;
args.auto_import_missing_key = auto_import_missing_key;
+ args.use_pinentry = use_pinentry_as_password_input_dialog;
return std::unique_ptr<ChannelObject>(new GpgContext(args));
});
- if (!ctx.good()) SPDLOG_ERROR("no-ascii channel init error");
+ if (!ctx.good()) SPDLOG_ERROR("no-ascii channel init error");
return ctx.good() ? 0 : -1;
}));
diff --git a/src/core/function/GlobalSettingStation.cpp b/src/core/function/GlobalSettingStation.cpp
index 79c47408..cc126ebd 100644
--- a/src/core/function/GlobalSettingStation.cpp
+++ b/src/core/function/GlobalSettingStation.cpp
@@ -56,11 +56,8 @@ GpgFrontend::GlobalSettingStation::GlobalSettingStation(int channel) noexcept
SPDLOG_INFO("app conf path: {}", ui_config_path_.u8string());
if (!is_directory(app_configure_path_)) create_directory(app_configure_path_);
-
if (!is_directory(app_data_path_)) create_directory(app_data_path_);
-
if (!is_directory(app_log_path_)) create_directory(app_log_path_);
-
if (!is_directory(ui_config_dir_path_)) create_directory(ui_config_dir_path_);
if (!exists(ui_config_path_)) {
@@ -88,6 +85,11 @@ GpgFrontend::GlobalSettingStation::GlobalSettingStation(int channel) noexcept
}
}
+libconfig::Setting &
+GpgFrontend::GlobalSettingStation::GetUISettings() noexcept {
+ return ui_cfg_.getRoot();
+}
+
void GpgFrontend::GlobalSettingStation::init_app_secure_key() {}
GpgFrontend::GlobalSettingStation::~GlobalSettingStation() noexcept = default;
diff --git a/src/core/function/GlobalSettingStation.h b/src/core/function/GlobalSettingStation.h
index 8811623f..d70b3b63 100644
--- a/src/core/function/GlobalSettingStation.h
+++ b/src/core/function/GlobalSettingStation.h
@@ -60,7 +60,23 @@ class GPGFRONTEND_CORE_EXPORT GlobalSettingStation
*
* @return libconfig::Setting&
*/
- libconfig::Setting &GetUISettings() noexcept { return ui_cfg_.getRoot(); }
+ libconfig::Setting &GetUISettings() noexcept;
+
+ /**
+ * @brief
+ *
+ * @return libconfig::Setting&
+ */
+ template <typename T>
+ T LookupSettings(std::string path, T default_value) noexcept {
+ T value = default_value;
+ try {
+ value = static_cast<T>(GetUISettings().lookup(path));
+ } catch (...) {
+ SPDLOG_WARN("setting not found: {}", path);
+ }
+ return value;
+ }
/**
* @brief Get the App Dir object
diff --git a/src/init.cpp b/src/init.cpp
index 955b8a55..ddab4add 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -32,6 +32,7 @@
#include <spdlog/sinks/stdout_color_sinks.h>
#include <filesystem>
+#include <string>
#include "GpgFrontend.h"
#include "GpgFrontendBuildInfo.h"
@@ -90,26 +91,14 @@ void shutdown_logging_system() {
}
void init_global_path_env() {
- auto &settings =
- GpgFrontend::GlobalSettingStation::GetInstance().GetUISettings();
-
- bool use_custom_gnupg_install_path = false;
- try {
- use_custom_gnupg_install_path =
- settings.lookup("general.use_custom_gnupg_install_path");
- } catch (...) {
- SPDLOG_ERROR("setting operation error: use_custom_gnupg_install_path");
- }
-
- // read from settings file
- std::string custom_gnupg_install_path;
- try {
- custom_gnupg_install_path = static_cast<std::string>(
- settings.lookup("general.custom_gnupg_install_path"));
-
- } catch (...) {
- SPDLOG_ERROR("setting operation error: custom_gnupg_install_path");
- }
+ // read settings
+ bool use_custom_gnupg_install_path =
+ GpgFrontend::GlobalSettingStation::GetInstance().LookupSettings(
+ "general.use_custom_gnupg_install_path", false);
+
+ std::string custom_gnupg_install_path =
+ GpgFrontend::GlobalSettingStation::GetInstance().LookupSettings(
+ "general.custom_gnupg_install_path", std::string{});
// add custom gnupg install path into env $PATH
if (use_custom_gnupg_install_path && !custom_gnupg_install_path.empty()) {
diff --git a/src/ui/GpgFrontendUIInit.cpp b/src/ui/GpgFrontendUIInit.cpp
index c6360ca7..bfe4d828 100644
--- a/src/ui/GpgFrontendUIInit.cpp
+++ b/src/ui/GpgFrontendUIInit.cpp
@@ -33,6 +33,8 @@
#include <spdlog/sinks/rotating_file_sink.h>
#include <spdlog/sinks/stdout_color_sinks.h>
+#include <string>
+
#include "core/GpgConstants.h"
#include "core/function/GlobalSettingStation.h"
#include "core/thread/CtxCheckTask.h"
@@ -74,25 +76,26 @@ void InitGpgFrontendUI(QApplication* app) {
CommonUtils::GetInstance();
// application proxy configure
-
- auto& settings = GlobalSettingStation::GetInstance().GetUISettings();
- bool proxy_enable = false;
- try {
- proxy_enable = settings.lookup("proxy.enable");
- } catch (...) {
- SPDLOG_ERROR("setting operation error: proxy_enable");
- }
- SPDLOG_DEBUG("loading proxy configure, proxy_enable: {}", proxy_enable);
+ bool proxy_enable =
+ GlobalSettingStation::GetInstance().LookupSettings("proxy.enable", false);
// if enable proxy for application
if (proxy_enable) {
try {
- std::string proxy_type = settings.lookup("proxy.proxy_type");
- std::string proxy_host = settings.lookup("proxy.proxy_host");
- int proxy_port = settings.lookup("proxy.port");
- std::string proxy_username = settings.lookup("proxy.username");
- std::string proxy_password = settings.lookup("proxy.password");
-
+ std::string proxy_type =
+ GlobalSettingStation::GetInstance().LookupSettings("proxy.proxy_type",
+ std::string{});
+ std::string proxy_host =
+ GlobalSettingStation::GetInstance().LookupSettings("proxy.proxy_host",
+ std::string{});
+ int proxy_port =
+ GlobalSettingStation::GetInstance().LookupSettings("proxy.port", 0);
+ std::string proxy_username =
+ GlobalSettingStation::GetInstance().LookupSettings("proxy.username",
+ std::string{});
+ std::string proxy_password =
+ GlobalSettingStation::GetInstance().LookupSettings("proxy.password",
+ std::string{});
SPDLOG_DEBUG("proxy settings: type {}, host {}, port: {}", proxy_type,
proxy_host, proxy_port);
diff --git a/src/ui/dialog/Wizard.cpp b/src/ui/dialog/Wizard.cpp
index 57aefcfb..5235a5dd 100644
--- a/src/ui/dialog/Wizard.cpp
+++ b/src/ui/dialog/Wizard.cpp
@@ -47,13 +47,8 @@ Wizard::Wizard(QWidget* parent) : QWizard(parent) {
setPixmap(QWizard::LogoPixmap, QPixmap(":/logo_small.png"));
setPixmap(QWizard::BannerPixmap, QPixmap(":/banner.png"));
- auto& settings = GlobalSettingStation::GetInstance().GetUISettings();
- int next_page_id = -1;
- try {
- next_page_id = settings.lookup("wizard.next_page");
- } catch (...) {
- SPDLOG_ERROR("setting operation error");
- }
+ int next_page_id = GlobalSettingStation::GetInstance().LookupSettings(
+ "wizard.next_page", -1);
setStartId(next_page_id);
connect(this, &Wizard::accepted, this, &Wizard::slot_wizard_accepted);
diff --git a/src/ui/dialog/import_export/KeyServerImportDialog.cpp b/src/ui/dialog/import_export/KeyServerImportDialog.cpp
index 5692f607..cf4fbe55 100644
--- a/src/ui/dialog/import_export/KeyServerImportDialog.cpp
+++ b/src/ui/dialog/import_export/KeyServerImportDialog.cpp
@@ -47,16 +47,9 @@ KeyServerImportDialog::KeyServerImportDialog(bool automatic, QWidget* parent)
// Layout for messagebox
auto* message_layout = new QHBoxLayout();
- // get settings
- auto& settings = GlobalSettingStation::GetInstance().GetUISettings();
- // read settings
- bool forbid_all_gnupg_connection = false;
- try {
- forbid_all_gnupg_connection =
- settings.lookup("network.forbid_all_gnupg_connection");
- } catch (...) {
- SPDLOG_ERROR("setting operation error: forbid_all_gnupg_connection");
- }
+ bool forbid_all_gnupg_connection =
+ GlobalSettingStation::GetInstance().LookupSettings(
+ "network.forbid_all_gnupg_connection", false);
if (forbid_all_gnupg_connection) {
QMessageBox::critical(this, "Forbidden", "GnuPG is in offline mode now.");
diff --git a/src/ui/dialog/key_generate/KeygenDialog.cpp b/src/ui/dialog/key_generate/KeygenDialog.cpp
index ea874ed2..02e0d1c8 100644
--- a/src/ui/dialog/key_generate/KeygenDialog.cpp
+++ b/src/ui/dialog/key_generate/KeygenDialog.cpp
@@ -43,26 +43,14 @@ KeyGenDialog::KeyGenDialog(QWidget* parent)
button_box_ =
new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
- auto& settings = GlobalSettingStation::GetInstance().GetUISettings();
+ bool longer_expiration_date =
+ GlobalSettingStation::GetInstance().LookupSettings(
+ "general.longer_expiration_date", false);
- // max expire date time
- bool longer_expiration_date = false;
- try {
- longer_expiration_date = settings.lookup("general.longer_expiration_date");
- SPDLOG_DEBUG("longer_expiration_date: {}", longer_expiration_date);
+ bool use_pinentry_as_password_input_dialog =
+ GlobalSettingStation::GetInstance().LookupSettings(
+ "general.use_pinentry_as_password_input_dialog", false);
- } catch (...) {
- SPDLOG_ERROR("setting operation error: longer_expiration_date");
- }
-
- bool use_pinentry_as_password_input_dialog = false;
- try {
- use_pinentry_as_password_input_dialog =
- settings.lookup("general.use_pinentry_as_password_input_dialog");
- } catch (...) {
- SPDLOG_ERROR(
- "setting operation error: use_pinentry_as_password_input_dialog");
- }
use_pinentry_ = use_pinentry_as_password_input_dialog;
max_date_time_ = longer_expiration_date
diff --git a/src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp b/src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp
index f4263962..abf17c67 100644
--- a/src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp
+++ b/src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp
@@ -40,26 +40,14 @@ namespace GpgFrontend::UI {
SubkeyGenerateDialog::SubkeyGenerateDialog(const KeyId& key_id, QWidget* parent)
: GeneralDialog(typeid(SubkeyGenerateDialog).name(), parent),
key_(GpgKeyGetter::GetInstance().GetKey(key_id)) {
- auto& settings = GlobalSettingStation::GetInstance().GetUISettings();
+ bool longer_expiration_date =
+ GlobalSettingStation::GetInstance().LookupSettings(
+ "general.longer_expiration_date", false);
- // max expire date time
- bool longer_expiration_date = false;
- try {
- longer_expiration_date = settings.lookup("general.longer_expiration_date");
- SPDLOG_DEBUG("longer expiration date: {}", longer_expiration_date);
+ bool use_pinentry_as_password_input_dialog =
+ GlobalSettingStation::GetInstance().LookupSettings(
+ "general.use_pinentry_as_password_input_dialog", false);
- } catch (...) {
- SPDLOG_ERROR("setting operation error: longer_expiration_date");
- }
-
- bool use_pinentry_as_password_input_dialog = false;
- try {
- use_pinentry_as_password_input_dialog =
- settings.lookup("general.use_pinentry_as_password_input_dialog");
- } catch (...) {
- SPDLOG_ERROR(
- "setting operation error: use_pinentry_as_password_input_dialog");
- }
use_pinentry_ = use_pinentry_as_password_input_dialog;
max_date_time_ = longer_expiration_date
diff --git a/src/ui/dialog/settings/SettingsAdvanced.cpp b/src/ui/dialog/settings/SettingsAdvanced.cpp
index e10b5dd1..9a02f473 100644
--- a/src/ui/dialog/settings/SettingsAdvanced.cpp
+++ b/src/ui/dialog/settings/SettingsAdvanced.cpp
@@ -55,22 +55,15 @@ AdvancedTab::AdvancedTab(QWidget* parent) : QWidget(parent) {
}
void AdvancedTab::SetSettings() {
- auto& settings = GlobalSettingStation::GetInstance().GetUISettings();
- try {
- bool stegano_checked = settings.lookup("advanced.stegano_checked");
- if (stegano_checked) stegano_check_box_->setCheckState(Qt::Checked);
- } catch (...) {
- SPDLOG_ERROR("setting operation error: stegano_checked");
- }
+ int stegano_checked = GlobalSettingStation::GetInstance().LookupSettings(
+ "advanced.stegano_checked", false);
+ if (stegano_checked) stegano_check_box_->setCheckState(Qt::Checked);
- try {
- bool auto_pubkey_exchange_checked =
- settings.lookup("advanced.auto_pubkey_exchange_checked");
- if (auto_pubkey_exchange_checked)
- auto_pubkey_exchange_check_box_->setCheckState(Qt::Checked);
- } catch (...) {
- SPDLOG_ERROR("setting operation error: auto_pubkey_exchange_checked");
- }
+ int auto_pubkey_exchange_checked =
+ GlobalSettingStation::GetInstance().LookupSettings(
+ "advanced.auto_pubkey_exchange_checked", false);
+ if (auto_pubkey_exchange_checked)
+ auto_pubkey_exchange_check_box_->setCheckState(Qt::Checked);
}
void AdvancedTab::ApplySettings() {
diff --git a/src/ui/main_window/KeyMgmt.cpp b/src/ui/main_window/KeyMgmt.cpp
index 949ef071..758a7af1 100644
--- a/src/ui/main_window/KeyMgmt.cpp
+++ b/src/ui/main_window/KeyMgmt.cpp
@@ -104,8 +104,6 @@ KeyMgmt::KeyMgmt(QWidget* parent)
qobject_cast<MainWindow*>(this->parent()),
&MainWindow::SlotSetStatusBarText);
- auto& settings = GlobalSettingStation::GetInstance().GetUISettings();
-
this->statusBar()->show();
setWindowTitle(_("KeyPair Management"));
@@ -165,16 +163,9 @@ void KeyMgmt::create_actions() {
CommonUtils::GetInstance()->SlotImportKeyFromClipboard(this);
});
- // get settings
- auto& settings = GlobalSettingStation::GetInstance().GetUISettings();
- // read settings
- bool forbid_all_gnupg_connection = false;
- try {
- forbid_all_gnupg_connection =
- settings.lookup("network.forbid_all_gnupg_connection");
- } catch (...) {
- SPDLOG_ERROR("setting operation error: forbid_all_gnupg_connection");
- }
+ bool forbid_all_gnupg_connection =
+ GlobalSettingStation::GetInstance().LookupSettings(
+ "network.forbid_all_gnupg_connection", false);
import_key_from_key_server_act_ = new QAction(_("Keyserver"), this);
import_key_from_key_server_act_->setIcon(
diff --git a/src/ui/main_window/MainWindow.cpp b/src/ui/main_window/MainWindow.cpp
index c59ce13c..9e02c095 100644
--- a/src/ui/main_window/MainWindow.cpp
+++ b/src/ui/main_window/MainWindow.cpp
@@ -144,22 +144,14 @@ void MainWindow::Init() noexcept {
connect(qApp, &QCoreApplication::aboutToQuit, this, []() {
SPDLOG_DEBUG("about to quit process started");
- auto &settings = GlobalSettingStation::GetInstance().GetUISettings();
- try {
- bool clear_gpg_password_cache =
- settings.lookup("general.clear_gpg_password_cache");
-
- if (clear_gpg_password_cache) {
- if (GpgFrontend::GpgAdvancedOperator::GetInstance()
- .ClearGpgPasswordCache()) {
- SPDLOG_DEBUG("clear gpg password cache done");
- } else {
- SPDLOG_ERROR("clear gpg password cache error");
- }
+ 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");
}
-
- } catch (...) {
- SPDLOG_ERROR("setting operation error: clear_gpg_password_cache");
}
});
@@ -244,26 +236,22 @@ void MainWindow::restore_settings() {
}
void MainWindow::save_settings() {
- auto &settings = GlobalSettingStation::GetInstance().GetUISettings();
+ bool save_key_checked = GlobalSettingStation::GetInstance().LookupSettings(
+ "general.save_key_checked", false);
- try {
- bool save_key_checked = settings.lookup("general.save_key_checked");
+ // keyid-list of private checked keys
+ if (save_key_checked) {
+ auto key_ids_need_to_store = m_key_list_->GetChecked();
- // keyid-list of private checked keys
- if (save_key_checked) {
- auto key_ids_need_to_store = m_key_list_->GetChecked();
+ SettingsObject default_key_checked("default_key_checked");
+ default_key_checked.clear();
- SettingsObject default_key_checked("default_key_checked");
- default_key_checked.clear();
-
- for (const auto &key_id : *key_ids_need_to_store)
- default_key_checked.push_back(key_id);
- } else {
- settings["general"].remove("save_key_checked");
- }
- } catch (...) {
- SPDLOG_ERROR("cannot save settings");
- };
+ for (const auto &key_id : *key_ids_need_to_store)
+ default_key_checked.push_back(key_id);
+ } else {
+ auto &settings = GlobalSettingStation::GetInstance().GetUISettings();
+ settings["general"].remove("save_key_checked");
+ }
GlobalSettingStation::GetInstance().SyncSettings();
}
diff --git a/src/ui/main_window/MainWindowFileSlotFunction.cpp b/src/ui/main_window/MainWindowFileSlotFunction.cpp
index 598ba33c..6fe8062b 100644
--- a/src/ui/main_window/MainWindowFileSlotFunction.cpp
+++ b/src/ui/main_window/MainWindowFileSlotFunction.cpp
@@ -167,14 +167,9 @@ void MainWindow::SlotFileEncrypt() {
GpgError error;
bool if_error = false;
- // Detect ascii mode
- auto& settings = GlobalSettingStation::GetInstance().GetUISettings();
- bool non_ascii_when_export = true;
- try {
- non_ascii_when_export = settings.lookup("general.non_ascii_when_export");
- } catch (...) {
- SPDLOG_ERROR("setting operation error: non_ascii_when_export");
- }
+ bool non_ascii_when_export =
+ GlobalSettingStation::GetInstance().LookupSettings(
+ "general.non_ascii_when_export", true);
// get file info
QFileInfo file_info(path);
@@ -390,14 +385,9 @@ void MainWindow::SlotFileSign() {
}
}
- // Detect ascii mode
- auto& settings = GlobalSettingStation::GetInstance().GetUISettings();
- bool non_ascii_when_export = true;
- try {
- non_ascii_when_export = settings.lookup("general.non_ascii_when_export");
- } catch (...) {
- SPDLOG_ERROR("setting operation error: non_ascii_when_export");
- }
+ bool non_ascii_when_export =
+ GlobalSettingStation::GetInstance().LookupSettings(
+ "general.non_ascii_when_export", true);
auto _channel = GPGFRONTEND_DEFAULT_CHANNEL;
auto _extension = ".asc";
@@ -469,14 +459,9 @@ void MainWindow::SlotFileVerify() {
std::filesystem::path sign_file_path = in_path, data_file_path;
- // Detect ascii mode
- auto& settings = GlobalSettingStation::GetInstance().GetUISettings();
- bool non_ascii_when_export = true;
- try {
- non_ascii_when_export = settings.lookup("general.non_ascii_when_export");
- } catch (...) {
- SPDLOG_ERROR("setting operation error: non_ascii_when_export");
- }
+ bool non_ascii_when_export =
+ GlobalSettingStation::GetInstance().LookupSettings(
+ "general.non_ascii_when_export", true);
auto _channel = GPGFRONTEND_DEFAULT_CHANNEL;
if (non_ascii_when_export) {
@@ -581,14 +566,9 @@ void MainWindow::SlotFileEncryptSign() {
}
}
- // detect ascii mode
- auto& settings = GlobalSettingStation::GetInstance().GetUISettings();
- bool non_ascii_when_export = true;
- try {
- non_ascii_when_export = settings.lookup("general.non_ascii_when_export");
- } catch (...) {
- SPDLOG_ERROR("setting operation error: non_ascii_when_export");
- }
+ bool non_ascii_when_export =
+ GlobalSettingStation::GetInstance().LookupSettings(
+ "general.non_ascii_when_export", true);
// get file info
QFileInfo file_info(path);
diff --git a/src/ui/main_window/MainWindowUI.cpp b/src/ui/main_window/MainWindowUI.cpp
index d1a72c83..6e664988 100644
--- a/src/ui/main_window/MainWindowUI.cpp
+++ b/src/ui/main_window/MainWindowUI.cpp
@@ -253,16 +253,9 @@ void MainWindow::create_actions() {
CommonUtils::GetInstance()->SlotImportKeyFromClipboard(this);
});
- // get settings
- auto& settings = GlobalSettingStation::GetInstance().GetUISettings();
- // read settings
- bool forbid_all_gnupg_connection = false;
- try {
- forbid_all_gnupg_connection =
- settings.lookup("network.forbid_all_gnupg_connection");
- } catch (...) {
- SPDLOG_ERROR("setting operation error: forbid_all_gnupg_connection");
- }
+ bool forbid_all_gnupg_connection =
+ GlobalSettingStation::GetInstance().LookupSettings(
+ "network.forbid_all_gnupg_connection", false);
import_key_from_key_server_act_ = new QAction(_("Keyserver"), this);
import_key_from_key_server_act_->setIcon(
diff --git a/src/ui/widgets/KeyList.cpp b/src/ui/widgets/KeyList.cpp
index e426ed48..2d4c925a 100644
--- a/src/ui/widgets/KeyList.cpp
+++ b/src/ui/widgets/KeyList.cpp
@@ -60,6 +60,13 @@ void KeyList::init() {
ui_->keyGroupTab->clear();
popup_menu_ = new QMenu(this);
+ bool forbid_all_gnupg_connection =
+ GlobalSettingStation::GetInstance().LookupSettings(
+ "network.forbid_all_gnupg_connection", false);
+
+ // forbidden networks connections
+ if (forbid_all_gnupg_connection) ui_->syncButton->setDisabled(true);
+
// register key database refresh signal
connect(this, &KeyList::SignalRefreshDatabase, SignalStation::GetInstance(),
&SignalStation::SignalKeyDatabaseRefresh);
@@ -313,15 +320,9 @@ void KeyList::dropEvent(QDropEvent* event) {
// "always import keys"-CheckBox
auto* checkBox = new QCheckBox(_("Always import without bothering."));
- auto& settings = GlobalSettingStation::GetInstance().GetUISettings();
- bool confirm_import_keys = true;
- try {
- confirm_import_keys = settings.lookup("general.confirm_import_keys");
- SPDLOG_DEBUG("confirm_import_keys: {}", confirm_import_keys);
- if (confirm_import_keys) checkBox->setCheckState(Qt::Checked);
- } catch (...) {
- SPDLOG_ERROR("setting operation error: confirm_import_keys");
- }
+ bool confirm_import_keys = GlobalSettingStation::GetInstance().LookupSettings(
+ "general.confirm_import_keys", true);
+ if (confirm_import_keys) checkBox->setCheckState(Qt::Checked);
// Buttons for ok and cancel
auto* buttonBox =
@@ -340,6 +341,8 @@ void KeyList::dropEvent(QDropEvent* event) {
dialog->exec();
if (dialog->result() == QDialog::Rejected) return;
+ auto& settings = GlobalSettingStation::GetInstance().GetUISettings();
+
if (!settings.exists("general") ||
settings.lookup("general").getType() != libconfig::Setting::TypeGroup)
settings.add("general", libconfig::Setting::TypeGroup);
@@ -378,7 +381,9 @@ void KeyList::dragEnterEvent(QDragEnterEvent* event) {
*
*/
[[maybe_unused]] void KeyList::MarkKeys(QStringList* keyIds) {
- foreach (QString id, *keyIds) { spdlog::debug("marked: ", id.toStdString()); }
+ foreach (QString id, *keyIds) {
+ spdlog::debug("marked: ", id.toStdString());
+ }
}
void KeyList::import_keys(const QByteArray& inBuffer) {
diff --git a/src/ui/widgets/VerifyKeyDetailBox.cpp b/src/ui/widgets/VerifyKeyDetailBox.cpp
index 555414b4..192b09f3 100644
--- a/src/ui/widgets/VerifyKeyDetailBox.cpp
+++ b/src/ui/widgets/VerifyKeyDetailBox.cpp
@@ -42,16 +42,9 @@ VerifyKeyDetailBox::VerifyKeyDetailBox(const GpgSignature& signature,
case GPG_ERR_NO_PUBKEY: {
this->setTitle("A Error Signature");
- // get settings
- auto& settings = GlobalSettingStation::GetInstance().GetUISettings();
- // read settings
- bool forbid_all_gnupg_connection = false;
- try {
- forbid_all_gnupg_connection =
- settings.lookup("network.forbid_all_gnupg_connection");
- } catch (...) {
- SPDLOG_ERROR("setting operation error: forbid_all_gnupg_connection");
- }
+ bool forbid_all_gnupg_connection =
+ GlobalSettingStation::GetInstance().LookupSettings(
+ "network.forbid_all_gnupg_connection", false);
auto* import_button = new QPushButton(_("Import from keyserver"));
import_button->setDisabled(forbid_all_gnupg_connection);