aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/CMakeLists.txt4
-rw-r--r--src/GpgFrontend.h.in12
-rw-r--r--src/core/CMakeLists.txt3
-rw-r--r--src/core/GpgCoreInit.cpp31
-rw-r--r--src/core/function/DataObjectOperator.h2
-rw-r--r--src/core/function/GlobalSettingStation.cpp133
-rw-r--r--src/core/function/GlobalSettingStation.h58
-rw-r--r--src/init.cpp23
-rw-r--r--src/test/GpgFrontendTest.cpp41
-rw-r--r--src/ui/GpgFrontendApplication.cpp10
-rw-r--r--src/ui/GpgFrontendUIInit.cpp53
-rw-r--r--src/ui/dialog/Wizard.cpp19
-rw-r--r--src/ui/dialog/gnupg/GnuPGControllerDialog.cpp121
-rw-r--r--src/ui/dialog/import_export/KeyServerImportDialog.cpp8
-rw-r--r--src/ui/dialog/key_generate/KeygenDialog.cpp6
-rw-r--r--src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp6
-rw-r--r--src/ui/dialog/keypair_details/KeyPairOperaTab.cpp14
-rw-r--r--src/ui/dialog/keypair_details/KeySetExpireDateDialog.cpp13
-rw-r--r--src/ui/dialog/settings/SettingsAdvanced.cpp99
-rw-r--r--src/ui/dialog/settings/SettingsAdvanced.h52
-rw-r--r--src/ui/dialog/settings/SettingsDialog.cpp3
-rw-r--r--src/ui/dialog/settings/SettingsGeneral.cpp162
-rw-r--r--src/ui/dialog/settings/SettingsNetwork.cpp204
-rw-r--r--src/ui/main_window/KeyMgmt.cpp6
-rw-r--r--src/ui/main_window/MainWindow.cpp81
-rw-r--r--src/ui/main_window/MainWindow.h5
-rw-r--r--src/ui/main_window/MainWindowFileSlotFunction.cpp30
-rw-r--r--src/ui/main_window/MainWindowSlotUI.cpp1
-rw-r--r--src/ui/main_window/MainWindowUI.cpp6
-rw-r--r--src/ui/widgets/KeyList.cpp28
-rw-r--r--src/ui/widgets/TextEdit.cpp21
-rw-r--r--src/ui/widgets/VerifyKeyDetailBox.cpp6
32 files changed, 331 insertions, 930 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 8607975d..ef262dd1 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -223,10 +223,6 @@ if (BUILD_APPLICATION)
list(APPEND ALL_RUNTIME_DEP_PATH_LIST ${_libDllPath})
unset(_libDllPath)
- file(GLOB _libDllPath "${_libDllBinPath}/libconfig++-*.dll")
- list(APPEND ALL_RUNTIME_DEP_PATH_LIST ${_libDllPath})
-
- unset(_libDllPath)
file(GLOB _libDllPath "${_libDllBinPath}/libarchive-*.dll")
list(APPEND ALL_RUNTIME_DEP_PATH_LIST ${_libDllPath})
diff --git a/src/GpgFrontend.h.in b/src/GpgFrontend.h.in
index e23abd1e..29f2ab1c 100644
--- a/src/GpgFrontend.h.in
+++ b/src/GpgFrontend.h.in
@@ -51,15 +51,3 @@
#define PROJECT_NAME "@CMAKE_PROJECT_NAME@"
#define OS_PLATFORM "@OS_PLATFORM@"
#define LOCALE_DIR "@LOCALE_DIR@"
-
-// macros to find resource files
-#if defined(MACOS) && defined(RELEASE)
-#define RESOURCE_DIR(appDir) (appDir + "/../Resources/")
-#define RESOURCE_DIR_BOOST_PATH(appDir) (appDir / ".." / "Resources")
-#elif defined(LINUX) && defined(RELEASE)
-#define RESOURCE_DIR(appDir) (appDir + "/../share/")
-#define RESOURCE_DIR_BOOST_PATH(appDir) (appDir / ".." / "share")
-#else
-#define RESOURCE_DIR(appDir) (appDir)
-#define RESOURCE_DIR_BOOST_PATH(appDir) (appDir)
-#endif
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt
index 8d39f824..53c3c7eb 100644
--- a/src/core/CMakeLists.txt
+++ b/src/core/CMakeLists.txt
@@ -49,9 +49,8 @@ if(NOT APPLE)
endif()
# link third-party libraries
-target_link_libraries(gpgfrontend_core PUBLIC config++)
if (NOT LINUX)
- target_link_libraries(gpgfrontend_core PUBLIC config++ intl)
+ target_link_libraries(gpgfrontend_core PUBLIC intl)
endif ()
# qt-aes
diff --git a/src/core/GpgCoreInit.cpp b/src/core/GpgCoreInit.cpp
index 40e6d9f1..a30a407a 100644
--- a/src/core/GpgCoreInit.cpp
+++ b/src/core/GpgCoreInit.cpp
@@ -203,34 +203,37 @@ void InitGpgFrontendCore(CoreInitArgs args) {
.GetTaskRunner(Thread::TaskRunnerGetter::kTaskRunnerType_Default)
->PostTask(new Thread::Task(
[args](const DataObjectPtr&) -> int {
+ auto settings = GlobalSettingStation::GetInstance().GetSettings();
// read settings from config file
auto forbid_all_gnupg_connection =
- GlobalSettingStation::GetInstance().LookupSettings(
- "network.forbid_all_gnupg_connection", false);
+ settings.value("network/forbid_all_gnupg_connection", false)
+ .toBool();
auto auto_import_missing_key =
- GlobalSettingStation::GetInstance().LookupSettings(
- "network.auto_import_missing_key", false);
+ settings.value("network/auto_import_missing_key", false)
+ .toBool();
auto use_custom_key_database_path =
- GlobalSettingStation::GetInstance().LookupSettings(
- "general.use_custom_key_database_path", false);
+ settings.value("general/use_custom_key_database_path", false)
+ .toBool();
auto custom_key_database_path =
- GlobalSettingStation::GetInstance().LookupSettings(
- "general.custom_key_database_path", QString{});
+ settings.value("general/custom_key_database_path", QString{})
+ .toString();
auto use_custom_gnupg_install_path =
- GlobalSettingStation::GetInstance().LookupSettings(
- "general.use_custom_gnupg_install_path", false);
+ settings.value("general/use_custom_gnupg_install_path", false)
+ .toBool();
auto custom_gnupg_install_path =
- GlobalSettingStation::GetInstance().LookupSettings(
- "general.custom_gnupg_install_path", QString{});
+ settings.value("general/custom_gnupg_install_path", QString{})
+ .toString();
auto use_pinentry_as_password_input_dialog =
- GpgFrontend::GlobalSettingStation::GetInstance().LookupSettings(
- "general.use_pinentry_as_password_input_dialog", false);
+ settings
+ .value("general/use_pinentry_as_password_input_dialog",
+ false)
+ .toBool();
GF_CORE_LOG_DEBUG("core loaded if use custom key databse path: {}",
use_custom_key_database_path);
diff --git a/src/core/function/DataObjectOperator.h b/src/core/function/DataObjectOperator.h
index 992b0c46..fedbd905 100644
--- a/src/core/function/DataObjectOperator.h
+++ b/src/core/function/DataObjectOperator.h
@@ -62,7 +62,7 @@ class GPGFRONTEND_CORE_EXPORT DataObjectOperator
GlobalSettingStation &global_setting_station_ =
GlobalSettingStation::GetInstance(); ///< GlobalSettingStation
QString app_secure_path_ =
- global_setting_station_.GetAppConfigPath() +
+ global_setting_station_.GetAppDataPath() +
"/secure"; ///< Where sensitive information is stored
QString app_secure_key_path_ =
app_secure_path_ +
diff --git a/src/core/function/GlobalSettingStation.cpp b/src/core/function/GlobalSettingStation.cpp
index f6403765..d24e2894 100644
--- a/src/core/function/GlobalSettingStation.cpp
+++ b/src/core/function/GlobalSettingStation.cpp
@@ -28,11 +28,21 @@
#include "GlobalSettingStation.h"
-#include <filesystem>
-
#include "core/module/ModuleManager.h"
#include "core/utils/FilesystemUtils.h"
+// macros to find resource files
+#if defined(MACOS) && defined(RELEASE)
+#define RESOURCE_DIR(appDir) (appDir + "/../Resources/")
+#define RESOURCE_DIR_PATH(appDir) (appDir / ".." / "Resources")
+#elif defined(LINUX) && defined(RELEASE)
+#define RESOURCE_DIR(appDir) (appDir + "/../share/")
+#define RESOURCE_DIR_PATH(appDir) (appDir / ".." / "share")
+#else
+#define RESOURCE_DIR(appDir) (appDir)
+#define RESOURCE_DIR_PATH(appDir) (appDir)
+#endif
+
namespace GpgFrontend {
class GlobalSettingStation::Impl {
@@ -42,70 +52,37 @@ class GlobalSettingStation::Impl {
*
*/
explicit Impl() noexcept {
- GF_CORE_LOG_INFO("app path: {}", working_path_);
+ GF_CORE_LOG_INFO("app path: {}", GetAppDir());
+ GF_CORE_LOG_INFO("app working path: {}", working_path_);
+
auto portable_file_path = working_path_ + "/PORTABLE.txt";
if (QFileInfo(portable_file_path).exists()) {
GF_CORE_LOG_INFO(
"dectected portable mode, reconfiguring config and data path...");
Module::UpsertRTValue("core", "env.state.portable", 1);
- app_configure_path_ = working_path_;
- config_dir_path_ = app_configure_path_ + "/conf";
- main_config_path_ = config_dir_path_ + "/main.cfg";
- module_config_path_ = config_dir_path_ + "/module.cfg";
-
app_data_path_ = working_path_;
app_log_path_ = app_data_path_ + "/logs";
app_data_objs_path_ = app_data_path_ + "/data_objs";
+
+ portable_mode_ = true;
}
- GF_CORE_LOG_INFO("app configure path: {}", app_configure_path_);
GF_CORE_LOG_INFO("app data path: {}", app_data_path_);
GF_CORE_LOG_INFO("app log path: {}", app_log_path_);
GF_CORE_LOG_INFO("app locale path: {}", app_locale_path_);
- GF_CORE_LOG_INFO("app conf path: {}", main_config_path_);
GF_CORE_LOG_INFO("app log files total size: {}", GetLogFilesSize());
GF_CORE_LOG_INFO("app data objects files total size: {}",
GetDataObjectsFilesSize());
- if (!QDir(app_configure_path_).exists()) {
- QDir(app_configure_path_).mkpath(".");
- }
if (!QDir(app_data_path_).exists()) QDir(app_data_path_).mkpath(".");
if (!QDir(app_log_path_).exists()) QDir(app_log_path_).mkpath(".");
- if (!QDir(config_dir_path_).exists()) QDir(config_dir_path_).mkpath(".");
-
- if (!QDir(main_config_path_).exists()) {
- try {
- this->ui_cfg_.writeFile(main_config_path_.toUtf8());
- GF_CORE_LOG_DEBUG(
- "user interface configuration successfully written to {}",
- main_config_path_);
-
- } catch (const libconfig::FileIOException &fioex) {
- GF_CORE_LOG_DEBUG(
- "i/o error while writing UserInterface configuration file {}",
- main_config_path_);
- }
- } else {
- try {
- this->ui_cfg_.readFile(main_config_path_.toUtf8());
- GF_CORE_LOG_DEBUG(
- "user interface configuration successfully read from {}",
- main_config_path_);
- } catch (const libconfig::FileIOException &fioex) {
- GF_CORE_LOG_ERROR(
- "i/o error while reading UserInterface configure file");
- } catch (const libconfig::ParseException &pex) {
- GF_CORE_LOG_ERROR("parse error at {} : {} - {}", pex.getFile(),
- pex.getLine(), pex.getError());
- }
- }
}
- auto GetMainSettings() noexcept -> libconfig::Setting & {
- return ui_cfg_.getRoot();
+ [[nodiscard]] auto GetSettings() -> QSettings {
+ if (!portable_mode_) return QSettings();
+ return {app_portable_config_path_, QSettings::IniFormat};
}
[[nodiscard]] auto GetLogFilesSize() const -> QString {
@@ -126,28 +103,19 @@ class GlobalSettingStation::Impl {
}
/**
- * @brief
+ * @brief Get the App Dir object
*
- * @return libconfig::Setting&
+ * @return QString
*/
- template <typename T>
- auto LookupSettings(QString path, T default_value) noexcept -> T {
- T value = default_value;
- try {
- value = static_cast<T>(GetMainSettings().lookup(path.toStdString()));
- } catch (...) {
- GF_CORE_LOG_WARN("setting not found: {}", path);
- }
- return value;
+ [[nodiscard]] auto GetAppDir() const -> QString {
+ return QCoreApplication::applicationDirPath();
}
/**
- * @brief Get the App Dir object
+ * @brief Get the App Data Path object
*
* @return QString
*/
- [[nodiscard]] auto GetAppDir() const -> QString { return working_path_; }
-
[[nodiscard]] auto GetAppDataPath() const -> QString {
return app_data_path_;
}
@@ -160,15 +128,6 @@ class GlobalSettingStation::Impl {
[[nodiscard]] auto GetLogDir() const -> QString { return app_log_path_; }
/**
- * @brief Get the App Config Path object
- *
- * @return QString
- */
- [[nodiscard]] auto GetAppConfigPath() const -> QString {
- return app_configure_path_;
- }
-
- /**
* @brief Get the Locale Dir object
*
* @return QString
@@ -195,22 +154,6 @@ class GlobalSettingStation::Impl {
return app_resource_path_ + "/certs";
}
- /**
- * @brief sync the settings to the file
- *
- */
- void SyncSettings() noexcept {
- try {
- ui_cfg_.writeFile(main_config_path_.toUtf8());
- GF_CORE_LOG_DEBUG("updated ui configuration successfully written to {}",
- main_config_path_);
-
- } catch (const libconfig::FileIOException &fioex) {
- GF_CORE_LOG_ERROR("i/o error while writing ui configuration file: {}",
- main_config_path_);
- }
- }
-
private:
QString working_path_ = QDir::currentPath();
@@ -228,7 +171,7 @@ class GlobalSettingStation::Impl {
QString(APP_LOCALSTATE_PATH) / "gpgfrontend"; ///< Program Data Location
#else
QString app_resource_path_ =
- RESOURCE_DIR_BOOST_PATH(working_path_); ///< Program Data Location
+ RESOURCE_DIR_PATH(GetAppDir()); ///< Program Data Location
#endif
#ifdef LINUX_INSTALL_BUILD
@@ -239,17 +182,9 @@ class GlobalSettingStation::Impl {
app_resource_path_ + "/locales"; ///< Program Data Location
#endif
- QString app_configure_path_ = QString{QStandardPaths::writableLocation(
- QStandardPaths::AppConfigLocation)} +
- "/GpgFrontend"; ///< Program Configure Location
- QString config_dir_path_ =
- app_configure_path_ + "/conf"; ///< Configure File Directory Location
- QString main_config_path_ =
- config_dir_path_ + "/main.cfg"; ///< Main Configure File Location
- QString module_config_path_ =
- config_dir_path_ + "/module.cfg"; ///< Main Configure File Location
-
- libconfig::Config ui_cfg_; ///< UI Configure File
+ bool portable_mode_ = true; ///<
+ QString app_portable_config_path_ =
+ working_path_ + "/config.ini"; ///< take effect only in portable mode
/**
* @brief
@@ -264,10 +199,8 @@ GlobalSettingStation::GlobalSettingStation(int channel) noexcept
GlobalSettingStation::~GlobalSettingStation() noexcept = default;
-void GlobalSettingStation::SyncSettings() noexcept { p_->SyncSettings(); }
-
-auto GlobalSettingStation::GetMainSettings() noexcept -> libconfig::Setting & {
- return p_->GetMainSettings();
+auto GlobalSettingStation::GetSettings() const -> QSettings {
+ return p_->GetSettings();
}
auto GlobalSettingStation::GetAppDir() const -> QString {
@@ -282,10 +215,6 @@ auto GlobalSettingStation::GetAppDataPath() const -> QString {
return p_->GetLogDir();
}
-auto GlobalSettingStation::GetAppConfigPath() const -> QString {
- return p_->GetAppConfigPath();
-}
-
auto GlobalSettingStation::GetLocaleDir() const -> QString {
return p_->GetLocaleDir();
}
diff --git a/src/core/function/GlobalSettingStation.h b/src/core/function/GlobalSettingStation.h
index cd1b331b..f8d3068e 100644
--- a/src/core/function/GlobalSettingStation.h
+++ b/src/core/function/GlobalSettingStation.h
@@ -28,8 +28,6 @@
#pragma once
-#include <libconfig.h++>
-
#include "core/function/basic/GpgFunctionObject.h"
namespace GpgFrontend {
@@ -58,11 +56,11 @@ class GPGFRONTEND_CORE_EXPORT GlobalSettingStation
~GlobalSettingStation() noexcept override;
/**
- * @brief
+ * @brief Get the Settings object
*
- * @return libconfig::Setting&
+ * @return QSettings
*/
- auto GetMainSettings() noexcept -> libconfig::Setting &;
+ [[nodiscard]] auto GetSettings() const -> QSettings;
/**
* @brief Get the App Dir object
@@ -85,13 +83,6 @@ class GPGFRONTEND_CORE_EXPORT GlobalSettingStation
[[nodiscard]] auto GetLogDir() const -> QString;
/**
- * @brief Get the App Config Path object
- *
- * @return QString
- */
- [[nodiscard]] auto GetAppConfigPath() const -> QString;
-
- /**
* @brief Get the Locale Dir object
*
* @return QString
@@ -138,49 +129,6 @@ class GPGFRONTEND_CORE_EXPORT GlobalSettingStation
*/
void ClearAllDataObjects() const;
- /**
- * @brief sync the settings to the file
- *
- */
- void SyncSettings() noexcept;
-
- /**
- * @brief Looks up a setting by path.
- * @param path The path to the setting.
- * @param default_value The default value to return if setting is not found.
- * @return The setting value.
- */
- template <typename T>
- auto LookupSettings(QString path, T default_value) noexcept -> T {
- T value = default_value;
- try {
- value = static_cast<T>(GetMainSettings().lookup(path.toStdString()));
- } catch (...) {
- GF_CORE_LOG_WARN("setting not found: {}", path);
- }
- return value;
- }
-
- /**
- * @brief Looks up a setting by path.
- * @param path The path to the setting.
- * @param default_value The default value to return if setting is not found.
- * @return The setting value.
- */
- template <typename T>
- auto SaveSettings(QString path, libconfig::Setting::Type type,
- T value) noexcept -> T {
- try {
- if (!GetMainSettings().exists(path.toStdString())) {
- // TODO
- GetMainSettings().add(path.toStdString(), type);
- }
- } catch (...) {
- GF_CORE_LOG_WARN("setting not found: {}", path);
- }
- return value;
- }
-
private:
class Impl;
SecureUniquePtr<Impl> p_;
diff --git a/src/init.cpp b/src/init.cpp
index e82bccd1..3720056e 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -76,21 +76,24 @@ void InitLoggingSystem(const GFCxtSPtr &ctx) {
void InitGlobalPathEnv() {
// read settings
bool use_custom_gnupg_install_path =
- GlobalSettingStation::GetInstance().LookupSettings(
- "general.use_custom_gnupg_install_path", false);
+ GlobalSettingStation::GetInstance()
+ .GetSettings()
+ .value("general/use_custom_gnupg_install_path", false)
+ .toBool();
- std::string custom_gnupg_install_path =
- GlobalSettingStation::GetInstance().LookupSettings(
- "general.custom_gnupg_install_path", std::string{});
+ QString custom_gnupg_install_path =
+ GlobalSettingStation::GetInstance()
+ .GetSettings()
+ .value("general/custom_gnupg_install_path")
+ .toString();
// add custom gnupg install path into env $PATH
- if (use_custom_gnupg_install_path && !custom_gnupg_install_path.empty()) {
- std::string path_value = getenv("PATH");
+ if (use_custom_gnupg_install_path && !custom_gnupg_install_path.isEmpty()) {
+ QString path_value = getenv("PATH");
GF_MAIN_LOG_DEBUG("Current System PATH: {}", path_value);
setenv("PATH",
- ((std::filesystem::path{custom_gnupg_install_path}).u8string() +
- ":" + path_value)
- .c_str(),
+ (QDir(custom_gnupg_install_path).absolutePath() + ":" + path_value)
+ .toUtf8(),
1);
std::string modified_path_value = getenv("PATH");
GF_MAIN_LOG_DEBUG("Modified System PATH: {}", modified_path_value);
diff --git a/src/test/GpgFrontendTest.cpp b/src/test/GpgFrontendTest.cpp
index 34698863..2aac1450 100644
--- a/src/test/GpgFrontendTest.cpp
+++ b/src/test/GpgFrontendTest.cpp
@@ -74,43 +74,36 @@ void ConfigureGpgContext() {
});
}
-void ImportPrivateKeys(const QString& data_path,
- const libconfig::Setting& config) {
- if (config.exists("load_keys.private_keys")) {
- auto& private_keys = config.lookup("load_keys.private_keys");
- for (auto& private_key : private_keys) {
- if (private_key.exists("filename")) {
- std::string filename;
- private_key.lookupValue("filename", filename);
- auto data_file_path =
- data_path + "/" + QString::fromStdString(filename);
-
- auto [success, gf_buffer] = ReadFileGFBuffer(data_file_path);
- if (success) {
- GpgKeyImportExporter::GetInstance(kGpgFrontendDefaultChannel)
- .ImportKey(gf_buffer);
- } else {
- GF_TEST_LOG_ERROR("read from file faild: {}", data_file_path);
- }
+void ImportPrivateKeys(const QString& data_path, QSettings settings) {
+ if (settings.contains("load_keys/private_keys")) {
+ int size = settings.beginReadArray("load_keys/private_keys");
+ for (int i = 0; i < size; ++i) {
+ settings.setArrayIndex(i);
+ auto key_filename = settings.value("filename").toString();
+ auto target_file_path = data_path + "/" + key_filename;
+ auto [success, gf_buffer] = ReadFileGFBuffer(target_file_path);
+ if (success) {
+ GpgKeyImportExporter::GetInstance(kGpgFrontendDefaultChannel)
+ .ImportKey(gf_buffer);
+ } else {
+ GF_TEST_LOG_ERROR("read from file faild: {}", target_file_path);
}
}
+ settings.endArray();
}
}
void SetupGlobalTestEnv() {
auto app_path = GlobalSettingStation::GetInstance().GetAppDir();
auto test_path = app_path + "/test";
- auto test_config_path = test_path + "/conf/test.cfg";
+ auto test_config_path = test_path + "/conf/test.ini";
auto test_data_path = test_path + "/data";
GF_TEST_LOG_INFO("test config file path: {}", test_config_path);
GF_TEST_LOG_INFO("test data file path: {}", test_data_path);
- libconfig::Config cfg;
- ASSERT_NO_THROW(cfg.readFile(test_config_path.toUtf8()));
-
- auto& root = cfg.getRoot();
- ImportPrivateKeys(test_data_path, root);
+ ImportPrivateKeys(test_data_path,
+ QSettings(test_config_path, QSettings::IniFormat));
}
auto ExecuteAllTestCase(GpgFrontendContext args) -> int {
diff --git a/src/ui/GpgFrontendApplication.cpp b/src/ui/GpgFrontendApplication.cpp
index df59d0c6..f7fc5635 100644
--- a/src/ui/GpgFrontendApplication.cpp
+++ b/src/ui/GpgFrontendApplication.cpp
@@ -41,12 +41,14 @@ GpgFrontendApplication::GpgFrontendApplication(int &argc, char *argv[])
#endif
// set the extra information of the build
- this->setApplicationVersion(BUILD_VERSION);
- this->setApplicationName(PROJECT_NAME);
- this->setQuitOnLastWindowClosed(true);
+ GpgFrontendApplication::setApplicationVersion(BUILD_VERSION);
+ GpgFrontendApplication::setApplicationName(PROJECT_NAME);
+ GpgFrontendApplication::setApplicationDisplayName(PROJECT_NAME);
+ GpgFrontendApplication::setOrganizationName(PROJECT_NAME);
+ GpgFrontendApplication::setQuitOnLastWindowClosed(true);
// don't show icons in menus
- this->setAttribute(Qt::AA_DontShowIconsInMenus);
+ GpgFrontendApplication::setAttribute(Qt::AA_DontShowIconsInMenus);
// unicode in source
QTextCodec::setCodecForLocale(QTextCodec::codecForName("utf-8"));
diff --git a/src/ui/GpgFrontendUIInit.cpp b/src/ui/GpgFrontendUIInit.cpp
index 900bc948..83de2a0e 100644
--- a/src/ui/GpgFrontendUIInit.cpp
+++ b/src/ui/GpgFrontendUIInit.cpp
@@ -84,7 +84,6 @@ void WaitEnvCheckingProcess() {
auto env_state =
Module::RetrieveRTValueTypedOrDefault<>("core", "env.state.basic", 0);
-
GF_UI_LOG_DEBUG("ui is ready to wating for env initialized, env_state: {}",
env_state);
@@ -129,25 +128,23 @@ void InitGpgFrontendUI(QApplication* /*app*/) {
// init common utils
CommonUtils::GetInstance();
+ auto settings = GlobalSettingStation::GetInstance().GetSettings();
+
// application proxy configure
- bool proxy_enable =
- GlobalSettingStation::GetInstance().LookupSettings("proxy.enable", false);
+ bool proxy_enable = settings.value("proxy/enable", false).toBool();
// if enable proxy for application
if (proxy_enable) {
try {
- QString proxy_type = GlobalSettingStation::GetInstance().LookupSettings(
- "proxy.proxy_type", QString{});
- QString proxy_host = GlobalSettingStation::GetInstance().LookupSettings(
- "proxy.proxy_host", QString{});
- int proxy_port =
- GlobalSettingStation::GetInstance().LookupSettings("proxy.port", 0);
+ QString proxy_type =
+ settings.value("proxy/proxy_type", QString{}).toString();
+ QString proxy_host =
+ settings.value("proxy/proxy_host", QString{}).toString();
+ int proxy_port = settings.value("prox/port", 0).toInt();
QString proxy_username =
- GlobalSettingStation::GetInstance().LookupSettings("proxy.username",
- QString{});
+ settings.value("proxy/username", QString{}).toString();
QString proxy_password =
- GlobalSettingStation::GetInstance().LookupSettings("proxy.password",
- QString{});
+ settings.value("proxy/password", QString{}).toString();
GF_UI_LOG_DEBUG("proxy settings: type {}, host {}, port: {}", proxy_type,
proxy_host, proxy_port);
@@ -225,31 +222,13 @@ void GPGFRONTEND_UI_EXPORT DestroyGpgFrontendUI() {}
*/
void InitLocale() {
// get the instance of the GlobalSettingStation
- auto& settings =
- GpgFrontend::GlobalSettingStation::GetInstance().GetMainSettings();
-
- // create general settings if not exist
- if (!settings.exists("general") ||
- settings.lookup("general").getType() != libconfig::Setting::TypeGroup) {
- settings.add("general", libconfig::Setting::TypeGroup);
- }
-
- // set system default at first
- auto& general = settings["general"];
- if (!general.exists("lang")) {
- general.add("lang", libconfig::Setting::TypeString) = "";
- }
-
- // sync the settings to the file
- GpgFrontend::GlobalSettingStation::GetInstance().SyncSettings();
+ auto settings =
+ GpgFrontend::GlobalSettingStation::GetInstance().GetSettings();
GF_UI_LOG_DEBUG("current system locale: {}", setlocale(LC_ALL, nullptr));
// read from settings file
- std::string lang;
- if (!general.lookupValue("lang", lang)) {
- GF_UI_LOG_ERROR(_("could not read properly from configure file"));
- };
+ auto lang = settings.value("general/lang", QString{}).toString();
GF_UI_LOG_DEBUG("lang from settings: {}", lang);
GF_UI_LOG_DEBUG("project name: {}", PROJECT_NAME);
@@ -258,8 +237,8 @@ void InitLocale() {
GpgFrontend::GlobalSettingStation::GetInstance().GetLocaleDir());
#ifndef WINDOWS
- if (!lang.empty()) {
- QString lc = QString::fromStdString(lang) + ".UTF-8";
+ if (!lang.isEmpty()) {
+ QString lc = lang + ".UTF-8";
// set LC_ALL
auto* locale_name = setlocale(LC_ALL, lc.toUtf8());
@@ -275,7 +254,7 @@ void InitLocale() {
}
#else
if (!lang.empty()) {
- QString lc = QString::fromStdString(lang);
+ QString lc = lang;
// set LC_ALL
auto* locale_name = setlocale(LC_ALL, lc.toUtf8());
diff --git a/src/ui/dialog/Wizard.cpp b/src/ui/dialog/Wizard.cpp
index bdb7a669..65a5d822 100644
--- a/src/ui/dialog/Wizard.cpp
+++ b/src/ui/dialog/Wizard.cpp
@@ -48,8 +48,10 @@ Wizard::Wizard(QWidget* parent) : QWizard(parent) {
setPixmap(QWizard::LogoPixmap, QPixmap(":/logo_small.png"));
setPixmap(QWizard::BannerPixmap, QPixmap(":/banner.png"));
- int next_page_id = GlobalSettingStation::GetInstance().LookupSettings(
- "wizard.next_page", -1);
+ int next_page_id = GlobalSettingStation::GetInstance()
+ .GetSettings()
+ .value("wizard.next_page", -1)
+ .toInt();
setStartId(next_page_id);
connect(this, &Wizard::accepted, this, &Wizard::slot_wizard_accepted);
@@ -58,17 +60,8 @@ Wizard::Wizard(QWidget* parent) : QWizard(parent) {
void Wizard::slot_wizard_accepted() {
// Don't show is mapped to show -> negation
try {
- auto& settings = GlobalSettingStation::GetInstance().GetMainSettings();
- if (!settings.exists("wizard")) {
- settings.add("wizard", libconfig::Setting::TypeGroup);
- }
- auto& wizard = settings["wizard"];
- if (!wizard.exists("show_wizard")) {
- wizard.add("show_wizard", libconfig::Setting::TypeBoolean) = false;
- } else {
- wizard["show_wizard"] = false;
- }
- GlobalSettingStation::GetInstance().SyncSettings();
+ auto settings = GlobalSettingStation::GetInstance().GetSettings();
+ settings.setValue("wizard/show_wizard", false);
} catch (...) {
GF_UI_LOG_ERROR("setting operation error");
}
diff --git a/src/ui/dialog/gnupg/GnuPGControllerDialog.cpp b/src/ui/dialog/gnupg/GnuPGControllerDialog.cpp
index 992258ae..70aa2f92 100644
--- a/src/ui/dialog/gnupg/GnuPGControllerDialog.cpp
+++ b/src/ui/dialog/gnupg/GnuPGControllerDialog.cpp
@@ -103,17 +103,12 @@ GnuPGControllerDialog::GnuPGControllerDialog(QWidget* parent)
return;
}
- auto& settings = GlobalSettingStation::GetInstance().GetMainSettings();
- auto& general = settings["general"];
+ auto settings = GlobalSettingStation::GetInstance().GetSettings();
// update settings
- if (!general.exists("custom_key_database_path"))
- general.add("custom_key_database_path",
- libconfig::Setting::TypeString) =
- selected_custom_key_database_path.toStdString();
- else {
- general["custom_key_database_path"] =
- selected_custom_key_database_path.toStdString();
+ if (!settings.contains("general/custom_key_database_path")) {
+ settings.setValue("general/custom_key_database_path",
+ selected_custom_key_database_path);
}
// announce the restart
@@ -139,17 +134,10 @@ GnuPGControllerDialog::GnuPGControllerDialog(QWidget* parent)
return;
}
- auto& settings = GlobalSettingStation::GetInstance().GetMainSettings();
- auto& general = settings["general"];
-
- // update settings
- if (!general.exists("custom_gnupg_install_path"))
- general.add("custom_gnupg_install_path",
- libconfig::Setting::TypeString) =
- selected_custom_gnupg_install_path.toStdString();
- else {
- general["custom_gnupg_install_path"] =
- selected_custom_gnupg_install_path.toStdString();
+ auto settings = GlobalSettingStation::GetInstance().GetSettings();
+ if (!settings.contains("general/custom_gnupg_install_path")) {
+ settings.setValue("general/custom_gnupg_install_path",
+ selected_custom_gnupg_install_path);
}
// announce the restart
@@ -189,12 +177,8 @@ void GnuPGControllerDialog::SlotAccept() {
apply_settings();
GF_UI_LOG_DEBUG("gnupg controller apply done");
-
- // write settings to filesystem
- GlobalSettingStation::GetInstance().SyncSettings();
-
GF_UI_LOG_DEBUG("restart needed: {}", get_restart_needed());
- if (get_restart_needed()) {
+ if (get_restart_needed() != 0) {
emit SignalRestartNeeded(get_restart_needed());
}
close();
@@ -217,8 +201,10 @@ void GnuPGControllerDialog::slot_update_custom_key_database_path_label(
} else {
// read from settings file
QString custom_key_database_path =
- GlobalSettingStation::GetInstance().LookupSettings(
- "general.custom_key_database_path", QString{});
+ GlobalSettingStation::GetInstance()
+ .GetSettings()
+ .value("general/custom_key_database_path")
+ .toString();
GF_UI_LOG_DEBUG("selected_custom_key_database_path from settings: {}",
custom_key_database_path);
@@ -254,8 +240,10 @@ void GnuPGControllerDialog::slot_update_custom_gnupg_install_path_label(
} else {
// read from settings file
QString custom_gnupg_install_path =
- GlobalSettingStation::GetInstance().LookupSettings(
- "general.custom_gnupg_install_path", QString{});
+ GlobalSettingStation::GetInstance()
+ .GetSettings()
+ .value("general/custom_gnupg_install_path")
+ .toString();
GF_UI_LOG_DEBUG("custom_gnupg_install_path from settings: {}",
custom_gnupg_install_path);
@@ -277,13 +265,16 @@ void GnuPGControllerDialog::slot_update_custom_gnupg_install_path_label(
void GnuPGControllerDialog::set_settings() {
auto& settings_station = GlobalSettingStation::GetInstance();
- bool non_ascii_when_export =
- settings_station.LookupSettings("general.non_ascii_when_export", true);
+ bool non_ascii_when_export = settings_station.GetSettings()
+ .value("general/non_ascii_when_export", true)
+ .toBool();
GF_UI_LOG_DEBUG("non_ascii_when_export: {}", non_ascii_when_export);
if (non_ascii_when_export) ui_->asciiModeCheckBox->setCheckState(Qt::Checked);
- bool const use_custom_key_database_path = settings_station.LookupSettings(
- "general.use_custom_key_database_path", false);
+ bool const use_custom_key_database_path =
+ settings_station.GetSettings()
+ .value("general/use_custom_key_database_path", false)
+ .toBool();
if (use_custom_key_database_path) {
ui_->keyDatabseUseCustomCheckBox->setCheckState(Qt::Checked);
}
@@ -291,15 +282,18 @@ void GnuPGControllerDialog::set_settings() {
this->slot_update_custom_key_database_path_label(
ui_->keyDatabseUseCustomCheckBox->checkState());
- bool const use_custom_gnupg_install_path = settings_station.LookupSettings(
- "general.use_custom_gnupg_install_path", false);
+ bool const use_custom_gnupg_install_path =
+ settings_station.GetSettings()
+ .value("general/use_custom_gnupg_install_path", false)
+ .toBool();
if (use_custom_gnupg_install_path) {
ui_->useCustomGnuPGInstallPathCheckBox->setCheckState(Qt::Checked);
}
bool const use_pinentry_as_password_input_dialog =
- settings_station.LookupSettings(
- "general.use_pinentry_as_password_input_dialog", false);
+ settings_station.GetSettings()
+ .value("general/use_pinentry_as_password_input_dialog", false)
+ .toBool();
if (use_pinentry_as_password_input_dialog) {
ui_->usePinentryAsPasswordInputDialogCheckBox->setCheckState(Qt::Checked);
}
@@ -311,48 +305,17 @@ void GnuPGControllerDialog::set_settings() {
}
void GnuPGControllerDialog::apply_settings() {
- auto& settings =
- GpgFrontend::GlobalSettingStation::GetInstance().GetMainSettings();
-
- if (!settings.exists("general") ||
- settings.lookup("general").getType() != libconfig::Setting::TypeGroup)
- settings.add("general", libconfig::Setting::TypeGroup);
-
- auto& general = settings["general"];
-
- if (!general.exists("non_ascii_when_export"))
- general.add("non_ascii_when_export", libconfig::Setting::TypeBoolean) =
- ui_->asciiModeCheckBox->isChecked();
- else {
- general["non_ascii_when_export"] = ui_->asciiModeCheckBox->isChecked();
- }
-
- if (!general.exists("use_custom_key_database_path"))
- general.add("use_custom_key_database_path",
- libconfig::Setting::TypeBoolean) =
- ui_->keyDatabseUseCustomCheckBox->isChecked();
- else {
- general["use_custom_key_database_path"] =
- ui_->keyDatabseUseCustomCheckBox->isChecked();
- }
-
- if (!general.exists("use_custom_gnupg_install_path"))
- general.add("use_custom_gnupg_install_path",
- libconfig::Setting::TypeBoolean) =
- ui_->useCustomGnuPGInstallPathCheckBox->isChecked();
- else {
- general["use_custom_gnupg_install_path"] =
- ui_->useCustomGnuPGInstallPathCheckBox->isChecked();
- }
-
- if (!general.exists("use_pinentry_as_password_input_dialog"))
- general.add("use_pinentry_as_password_input_dialog",
- libconfig::Setting::TypeBoolean) =
- ui_->usePinentryAsPasswordInputDialogCheckBox->isChecked();
- else {
- general["use_pinentry_as_password_input_dialog"] =
- ui_->usePinentryAsPasswordInputDialogCheckBox->isChecked();
- }
+ auto settings =
+ GpgFrontend::GlobalSettingStation::GetInstance().GetSettings();
+
+ settings.setValue("general/non_ascii_when_export",
+ ui_->asciiModeCheckBox->isChecked());
+ settings.setValue("general/use_custom_key_database_path",
+ ui_->keyDatabseUseCustomCheckBox->isChecked());
+ settings.setValue("general/use_custom_gnupg_install_path",
+ ui_->useCustomGnuPGInstallPathCheckBox->isChecked());
+ settings.setValue("general/use_pinentry_as_password_input_dialog",
+ ui_->usePinentryAsPasswordInputDialogCheckBox->isChecked());
}
int GnuPGControllerDialog::get_restart_needed() const {
diff --git a/src/ui/dialog/import_export/KeyServerImportDialog.cpp b/src/ui/dialog/import_export/KeyServerImportDialog.cpp
index 823b5ac9..7cafaaca 100644
--- a/src/ui/dialog/import_export/KeyServerImportDialog.cpp
+++ b/src/ui/dialog/import_export/KeyServerImportDialog.cpp
@@ -29,8 +29,6 @@
#include "KeyServerImportDialog.h"
#include <QRegExp>
-#include <string>
-#include <utility>
#include "core/GpgModel.h"
#include "core/function/GlobalSettingStation.h"
@@ -46,8 +44,10 @@ namespace GpgFrontend::UI {
KeyServerImportDialog::KeyServerImportDialog(QWidget* parent)
: GeneralDialog("key_server_import_dialog", parent) {
auto forbid_all_gnupg_connection =
- GlobalSettingStation::GetInstance().LookupSettings(
- "network.forbid_all_gnupg_connection", false);
+ GlobalSettingStation::GetInstance()
+ .GetSettings()
+ .value("network/forbid_all_gnupg_connection", false)
+ .toBool();
if (forbid_all_gnupg_connection) {
QMessageBox::critical(this, "Forbidden", "GnuPG is in offline mode now.");
this->close();
diff --git a/src/ui/dialog/key_generate/KeygenDialog.cpp b/src/ui/dialog/key_generate/KeygenDialog.cpp
index 893ebb54..e6495481 100644
--- a/src/ui/dialog/key_generate/KeygenDialog.cpp
+++ b/src/ui/dialog/key_generate/KeygenDialog.cpp
@@ -49,8 +49,10 @@ KeyGenDialog::KeyGenDialog(QWidget* parent)
new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
bool const longer_expiration_date =
- GlobalSettingStation::GetInstance().LookupSettings(
- "general.longer_expiration_date", false);
+ GlobalSettingStation::GetInstance()
+ .GetSettings()
+ .value("general/longer_expiration_date", false)
+ .toBool();
max_date_time_ = longer_expiration_date
? QDateTime::currentDateTime().toLocalTime().addYears(30)
diff --git a/src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp b/src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp
index 9af2c0e9..ab538366 100644
--- a/src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp
+++ b/src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp
@@ -44,8 +44,10 @@ SubkeyGenerateDialog::SubkeyGenerateDialog(const KeyId& key_id, QWidget* parent)
: GeneralDialog(typeid(SubkeyGenerateDialog).name(), parent),
key_(GpgKeyGetter::GetInstance().GetKey(key_id)) {
bool longer_expiration_date =
- GlobalSettingStation::GetInstance().LookupSettings(
- "general.longer_expiration_date", false);
+ GlobalSettingStation::GetInstance()
+ .GetSettings()
+ .value("general/longer_expiration_date", false)
+ .toBool();
max_date_time_ = longer_expiration_date
? QDateTime::currentDateTime().toLocalTime().addYears(30)
diff --git a/src/ui/dialog/keypair_details/KeyPairOperaTab.cpp b/src/ui/dialog/keypair_details/KeyPairOperaTab.cpp
index df5fc77b..e024b8f0 100644
--- a/src/ui/dialog/keypair_details/KeyPairOperaTab.cpp
+++ b/src/ui/dialog/keypair_details/KeyPairOperaTab.cpp
@@ -81,16 +81,12 @@ KeyPairOperaTab::KeyPairOperaTab(const QString& key_id, QWidget* parent)
auto* advance_h_box_layout = new QHBoxLayout();
- // get settings
- auto& settings = GlobalSettingStation::GetInstance().GetMainSettings();
+ auto settings =
+ GpgFrontend::GlobalSettingStation::GetInstance().GetSettings();
+
// read settings
- bool forbid_all_gnupg_connection = false;
- try {
- forbid_all_gnupg_connection =
- settings.lookup("network.forbid_all_gnupg_connection");
- } catch (...) {
- GF_UI_LOG_ERROR("setting operation error: forbid_all_gnupg_connection");
- }
+ bool forbid_all_gnupg_connection =
+ settings.value("network/forbid_all_gnupg_connection").toBool();
auto* key_server_opera_button =
new QPushButton(_("Key Server Operation (Pubkey)"));
diff --git a/src/ui/dialog/keypair_details/KeySetExpireDateDialog.cpp b/src/ui/dialog/keypair_details/KeySetExpireDateDialog.cpp
index c9738f98..d44341a4 100644
--- a/src/ui/dialog/keypair_details/KeySetExpireDateDialog.cpp
+++ b/src/ui/dialog/keypair_details/KeySetExpireDateDialog.cpp
@@ -98,16 +98,11 @@ void KeySetExpireDateDialog::slot_confirm() {
void KeySetExpireDateDialog::init() {
ui_->setupUi(this);
- auto& settings = GlobalSettingStation::GetInstance().GetMainSettings();
+ auto settings =
+ GpgFrontend::GlobalSettingStation::GetInstance().GetSettings();
- bool longer_expiration_date = false;
- try {
- longer_expiration_date = settings.lookup("general.longer_expiration_date");
- GF_UI_LOG_DEBUG("longer_expiration_date: {}", longer_expiration_date);
-
- } catch (...) {
- GF_UI_LOG_ERROR("setting operation error: longer_expiration_date");
- }
+ bool longer_expiration_date = longer_expiration_date =
+ settings.value("general/longer_expiration_date").toBool();
auto max_date_time =
longer_expiration_date
diff --git a/src/ui/dialog/settings/SettingsAdvanced.cpp b/src/ui/dialog/settings/SettingsAdvanced.cpp
deleted file mode 100644
index 6d8a2b4a..00000000
--- a/src/ui/dialog/settings/SettingsAdvanced.cpp
+++ /dev/null
@@ -1,99 +0,0 @@
-/**
- * Copyright (C) 2021 Saturneric <[email protected]>
- *
- * This file is part of GpgFrontend.
- *
- * GpgFrontend is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * GpgFrontend is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with GpgFrontend. If not, see <https://www.gnu.org/licenses/>.
- *
- * The initial version of the source code is inherited from
- * the gpg4usb project, which is under GPL-3.0-or-later.
- *
- * All the source code of GpgFrontend was modified and released by
- * Saturneric <[email protected]> starting on May 12, 2021.
- *
- * SPDX-License-Identifier: GPL-3.0-or-later
- *
- */
-
-#include "SettingsAdvanced.h"
-
-#include "core/function/GlobalSettingStation.h"
-
-namespace GpgFrontend::UI {
-
-AdvancedTab::AdvancedTab(QWidget* parent) : QWidget(parent) {
- auto* stegano_box = new QGroupBox(_("Show Steganography Options"));
- auto* stegano_box_layout = new QHBoxLayout();
- stegano_check_box_ = new QCheckBox(_("Show Steganography Options."), this);
- stegano_box_layout->addWidget(stegano_check_box_);
- stegano_box->setLayout(stegano_box_layout);
-
- auto* pubkey_exchange_box = new QGroupBox(_("Pubkey Exchange"));
- auto* pubkey_exchange_box_layout = new QHBoxLayout();
- auto_pubkey_exchange_check_box_ =
- new QCheckBox(_("Auto Pubkey Exchange"), this);
- pubkey_exchange_box_layout->addWidget(auto_pubkey_exchange_check_box_);
- pubkey_exchange_box->setLayout(pubkey_exchange_box_layout);
-
- auto* main_layout = new QVBoxLayout;
- main_layout->addWidget(stegano_box);
- main_layout->addWidget(pubkey_exchange_box);
- SetSettings();
- main_layout->addStretch(1);
- setLayout(main_layout);
-}
-
-void AdvancedTab::SetSettings() {
- auto const stegano_checked =
- GlobalSettingStation::GetInstance().LookupSettings(
- "advanced.stegano_checked", false);
- if (stegano_checked) stegano_check_box_->setCheckState(Qt::Checked);
-
- auto const 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() {
- auto& settings =
- GpgFrontend::GlobalSettingStation::GetInstance().GetMainSettings();
-
- if (!settings.exists("advanced") ||
- settings.lookup("advanced").getType() != libconfig::Setting::TypeGroup) {
- settings.add("advanced", libconfig::Setting::TypeGroup);
- }
-
- auto& advanced = settings["advanced"];
-
- if (!advanced.exists("stegano_checked")) {
- advanced.add("stegano_checked", libconfig::Setting::TypeBoolean) =
- stegano_check_box_->isChecked();
- } else {
- advanced["stegano_checked"] = stegano_check_box_->isChecked();
- }
-
- if (!advanced.exists("auto_pubkey_exchange_checked")) {
- advanced.add("auto_pubkey_exchange_checked",
- libconfig::Setting::TypeBoolean) =
- auto_pubkey_exchange_check_box_->isChecked();
- } else {
- advanced["auto_pubkey_exchange_checked"] =
- auto_pubkey_exchange_check_box_->isChecked();
- }
-}
-
-} // namespace GpgFrontend::UI
diff --git a/src/ui/dialog/settings/SettingsAdvanced.h b/src/ui/dialog/settings/SettingsAdvanced.h
deleted file mode 100644
index 1f7efbb2..00000000
--- a/src/ui/dialog/settings/SettingsAdvanced.h
+++ /dev/null
@@ -1,52 +0,0 @@
-/**
- * Copyright (C) 2021 Saturneric <[email protected]>
- *
- * This file is part of GpgFrontend.
- *
- * GpgFrontend is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * GpgFrontend is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with GpgFrontend. If not, see <https://www.gnu.org/licenses/>.
- *
- * The initial version of the source code is inherited from
- * the gpg4usb project, which is under GPL-3.0-or-later.
- *
- * All the source code of GpgFrontend was modified and released by
- * Saturneric <[email protected]> starting on May 12, 2021.
- *
- * SPDX-License-Identifier: GPL-3.0-or-later
- *
- */
-
-#pragma once
-
-#include "ui/GpgFrontendUI.h"
-
-namespace GpgFrontend::UI {
-class AdvancedTab : public QWidget {
- Q_OBJECT
-
- public:
- explicit AdvancedTab(QWidget* parent = nullptr);
-
- void SetSettings();
-
- void ApplySettings();
-
- private:
- QCheckBox* stegano_check_box_;
- QCheckBox* auto_pubkey_exchange_check_box_;
-
- signals:
-
- void SignalRestartNeeded(bool needed);
-};
-} // namespace GpgFrontend::UI
diff --git a/src/ui/dialog/settings/SettingsDialog.cpp b/src/ui/dialog/settings/SettingsDialog.cpp
index d0e90cd9..834f1096 100644
--- a/src/ui/dialog/settings/SettingsDialog.cpp
+++ b/src/ui/dialog/settings/SettingsDialog.cpp
@@ -116,9 +116,6 @@ void SettingsDialog::SlotAccept() {
key_server_tab_->ApplySettings();
network_tab_->ApplySettings();
- // write settings to filesystem
- GlobalSettingStation::GetInstance().SyncSettings();
-
GF_UI_LOG_DEBUG("restart needed: {}", get_restart_needed());
if (get_restart_needed() != 0) {
emit SignalRestartNeeded(get_restart_needed());
diff --git a/src/ui/dialog/settings/SettingsGeneral.cpp b/src/ui/dialog/settings/SettingsGeneral.cpp
index ff459a0e..ba8ce7ca 100644
--- a/src/ui/dialog/settings/SettingsGeneral.cpp
+++ b/src/ui/dialog/settings/SettingsGeneral.cpp
@@ -106,132 +106,56 @@ GeneralTab::GeneralTab(QWidget* parent)
SetSettings();
}
-/**********************************
- * Read the settings from config
- * and set the buttons and checkboxes
- * appropriately
- **********************************/
void GeneralTab::SetSettings() {
- auto& settings = GlobalSettingStation::GetInstance().GetMainSettings();
-
- try {
- bool clear_gpg_password_cache =
- settings.lookup("general.clear_gpg_password_cache");
- if (clear_gpg_password_cache) {
- ui_->clearGpgPasswordCacheCheckBox->setCheckState(Qt::Checked);
- }
- } catch (...) {
- GF_UI_LOG_ERROR("setting operation error: clear_gpg_password_cache");
- }
-
- try {
- bool restore_text_editor_page =
- settings.lookup("general.restore_text_editor_page");
- if (restore_text_editor_page) {
- ui_->restoreTextEditorPageCheckBox->setCheckState(Qt::Checked);
- }
- } catch (...) {
- GF_UI_LOG_ERROR("setting operation error: restore_text_editor_page");
- }
-
- try {
- bool longer_expiration_date =
- settings.lookup("general.longer_expiration_date");
- GF_UI_LOG_DEBUG("longer_expiration_date: {}", longer_expiration_date);
- if (longer_expiration_date) {
- ui_->longerKeyExpirationDateCheckBox->setCheckState(Qt::Checked);
- }
- } catch (...) {
- GF_UI_LOG_ERROR("setting operation error: longer_expiration_date");
- }
-
-#ifdef SUPPORT_MULTI_LANG
- try {
- QString lang_key = QString::fromStdString(settings.lookup("general.lang"));
- QString lang_value = lang_.value(lang_key);
- GF_UI_LOG_DEBUG("lang settings current: {}", lang_value.toStdString());
- if (!lang_.empty()) {
- ui_->langSelectBox->setCurrentIndex(
- ui_->langSelectBox->findText(lang_value));
- } else {
- ui_->langSelectBox->setCurrentIndex(0);
- }
- } catch (...) {
- GF_UI_LOG_ERROR("setting operation error: lang");
- }
-#endif
-
- try {
- bool confirm_import_keys = settings.lookup("general.confirm_import_keys");
- GF_UI_LOG_DEBUG("confirm_import_keys: {}", confirm_import_keys);
- if (confirm_import_keys) {
- ui_->importConfirmationCheckBox->setCheckState(Qt::Checked);
- }
- } catch (...) {
- GF_UI_LOG_ERROR("setting operation error: confirm_import_keys");
+ auto settings = GlobalSettingStation::GetInstance().GetSettings();
+
+ bool clear_gpg_password_cache =
+ settings.value("general/clear_gpg_password_cache", true).toBool();
+ ui_->clearGpgPasswordCacheCheckBox->setCheckState(
+ clear_gpg_password_cache ? Qt::Checked : Qt::Unchecked);
+
+ bool restore_text_editor_page =
+ settings.value("general/restore_text_editor_page", true).toBool();
+ ui_->restoreTextEditorPageCheckBox->setCheckState(
+ restore_text_editor_page ? Qt::Checked : Qt::Unchecked);
+
+ bool longer_expiration_date =
+ settings.value("general/longer_expiration_date", false).toBool();
+ ui_->longerKeyExpirationDateCheckBox->setCheckState(
+ longer_expiration_date ? Qt::Checked : Qt::Unchecked);
+
+ bool confirm_import_keys =
+ settings.value("general/confirm_import_keys", false).toBool();
+ ui_->importConfirmationCheckBox->setCheckState(
+ confirm_import_keys ? Qt::Checked : Qt::Unchecked);
+
+ QString lang_key = settings.value("general/lang").toString();
+ QString lang_value = lang_.value(lang_key);
+ GF_UI_LOG_DEBUG("lang settings current: {}", lang_value.toStdString());
+ if (!lang_.empty()) {
+ ui_->langSelectBox->setCurrentIndex(
+ ui_->langSelectBox->findText(lang_value));
+ } else {
+ ui_->langSelectBox->setCurrentIndex(0);
}
}
-/***********************************
- * get the values of the buttons and
- * write them to settings-file
- *************************************/
void GeneralTab::ApplySettings() {
- auto& settings =
- GpgFrontend::GlobalSettingStation::GetInstance().GetMainSettings();
-
- if (!settings.exists("general") ||
- settings.lookup("general").getType() != libconfig::Setting::TypeGroup) {
- settings.add("general", libconfig::Setting::TypeGroup);
- }
-
- auto& general = settings["general"];
-
- if (!general.exists("longer_expiration_date")) {
- general.add("longer_expiration_date", libconfig::Setting::TypeBoolean) =
- ui_->longerKeyExpirationDateCheckBox->isChecked();
- } else {
- general["longer_expiration_date"] =
- ui_->longerKeyExpirationDateCheckBox->isChecked();
- }
-
- if (!general.exists("clear_gpg_password_cache")) {
- general.add("clear_gpg_password_cache", libconfig::Setting::TypeBoolean) =
- ui_->clearGpgPasswordCacheCheckBox->isChecked();
- } else {
- general["clear_gpg_password_cache"] =
- ui_->clearGpgPasswordCacheCheckBox->isChecked();
- }
-
- if (!general.exists("restore_text_editor_page")) {
- general.add("restore_text_editor_page", libconfig::Setting::TypeBoolean) =
- ui_->restoreTextEditorPageCheckBox->isChecked();
- } else {
- general["restore_text_editor_page"] =
- ui_->restoreTextEditorPageCheckBox->isChecked();
- }
-
-#ifdef SUPPORT_MULTI_LANG
- if (!general.exists("lang")) {
- general.add("lang", libconfig::Setting::TypeBoolean) =
- lang_.key(ui_->langSelectBox->currentText()).toStdString();
- } else {
- general["lang"] =
- lang_.key(ui_->langSelectBox->currentText()).toStdString();
- }
-#endif
-
- if (!general.exists("confirm_import_keys")) {
- general.add("confirm_import_keys", libconfig::Setting::TypeBoolean) =
- ui_->importConfirmationCheckBox->isChecked();
- } else {
- general["confirm_import_keys"] =
- ui_->importConfirmationCheckBox->isChecked();
- }
+ auto settings =
+ GpgFrontend::GlobalSettingStation::GetInstance().GetSettings();
+
+ settings.setValue("general/longer_expiration_date",
+ ui_->longerKeyExpirationDateCheckBox->isChecked());
+ settings.setValue("general/clear_gpg_password_cache",
+ ui_->clearGpgPasswordCacheCheckBox->isChecked());
+ settings.setValue("general/restore_text_editor_page",
+ ui_->restoreTextEditorPageCheckBox->isChecked());
+ settings.setValue("general/confirm_import_keys",
+ ui_->importConfirmationCheckBox->isChecked());
+ settings.setValue("general/lang",
+ lang_.key(ui_->langSelectBox->currentText()));
}
-#ifdef SUPPORT_MULTI_LANG
void GeneralTab::slot_language_changed() { emit SignalRestartNeeded(true); }
-#endif
} // namespace GpgFrontend::UI
diff --git a/src/ui/dialog/settings/SettingsNetwork.cpp b/src/ui/dialog/settings/SettingsNetwork.cpp
index 211894a1..ac6160e8 100644
--- a/src/ui/dialog/settings/SettingsNetwork.cpp
+++ b/src/ui/dialog/settings/SettingsNetwork.cpp
@@ -98,181 +98,67 @@ GpgFrontend::UI::NetworkTab::NetworkTab(QWidget *parent)
}
void GpgFrontend::UI::NetworkTab::SetSettings() {
- auto &settings = GlobalSettingStation::GetInstance().GetMainSettings();
-
- try {
- QString proxy_host =
- QString::fromStdString(settings.lookup("proxy.proxy_host"));
- ui_->proxyServerAddressEdit->setText(proxy_host);
- } catch (...) {
- GF_UI_LOG_ERROR("setting operation error: proxy_host");
- }
+ auto settings = GlobalSettingStation::GetInstance().GetSettings();
- try {
- QString std_username =
- QString::fromStdString(settings.lookup("proxy.username"));
- ui_->usernameEdit->setText(std_username);
- } catch (...) {
- GF_UI_LOG_ERROR("setting operation error: username");
- }
+ QString proxy_host = settings.value("proxy/proxy_host").toString();
+ ui_->proxyServerAddressEdit->setText(proxy_host);
+ QString username = settings.value("proxy/username").toString();
+ ui_->usernameEdit->setText(username);
+ QString password = settings.value("proxy/password").toString();
+ ui_->passwordEdit->setText(password);
- try {
- QString std_password =
- QString::fromStdString(settings.lookup("proxy.password"));
- ui_->passwordEdit->setText(std_password);
- } catch (...) {
- GF_UI_LOG_ERROR("setting operation error: password");
- }
-
- try {
- int port = settings.lookup("proxy.port");
- ui_->portSpin->setValue(port);
- } catch (...) {
- GF_UI_LOG_ERROR("setting operation error: port");
- }
+ int port = settings.value("proxy/port", 0).toInt();
+ ui_->portSpin->setValue(port);
ui_->proxyTypeComboBox->setCurrentText("HTTP");
- try {
- QString proxy_type =
- QString::fromStdString(settings.lookup("proxy.proxy_type"));
- ui_->proxyTypeComboBox->setCurrentText(proxy_type);
- } catch (...) {
- GF_UI_LOG_ERROR("setting operation error: proxy_type");
- }
+
+ QString proxy_type = settings.value("proxy/proxy_type").toString();
+ ui_->proxyTypeComboBox->setCurrentText(proxy_type);
+
switch_ui_proxy_type(ui_->proxyTypeComboBox->currentText());
ui_->enableProxyCheckBox->setCheckState(Qt::Unchecked);
- try {
- bool proxy_enable = settings.lookup("proxy.enable");
- if (proxy_enable)
- ui_->enableProxyCheckBox->setCheckState(Qt::Checked);
- else
- ui_->enableProxyCheckBox->setCheckState(Qt::Unchecked);
- } catch (...) {
- GF_UI_LOG_ERROR("setting operation error: proxy_enable");
- }
- ui_->forbidALLGnuPGNetworkConnectionCheckBox->setCheckState(Qt::Unchecked);
- try {
- bool forbid_all_gnupg_connection =
- settings.lookup("network.forbid_all_gnupg_connection");
- if (forbid_all_gnupg_connection)
- ui_->forbidALLGnuPGNetworkConnectionCheckBox->setCheckState(Qt::Checked);
- else
- ui_->forbidALLGnuPGNetworkConnectionCheckBox->setCheckState(
- Qt::Unchecked);
- } catch (...) {
- GF_UI_LOG_ERROR("setting operation error: forbid_all_gnupg_connection");
- }
+ bool proxy_enable = settings.value("proxy/enable", false).toBool();
+ ui_->enableProxyCheckBox->setCheckState(proxy_enable ? Qt::Checked
+ : Qt::Unchecked);
- ui_->prohibitUpdateCheck->setCheckState(Qt::Unchecked);
- try {
- bool prohibit_update_checking =
- settings.lookup("network.prohibit_update_checking");
- if (prohibit_update_checking)
- ui_->prohibitUpdateCheck->setCheckState(Qt::Checked);
- else
- ui_->prohibitUpdateCheck->setCheckState(Qt::Unchecked);
- } catch (...) {
- GF_UI_LOG_ERROR("setting operation error: prohibit_update_checking");
- }
+ bool forbid_all_gnupg_connection =
+ settings.value("network/forbid_all_gnupg_connection").toBool();
+ ui_->forbidALLGnuPGNetworkConnectionCheckBox->setCheckState(
+ forbid_all_gnupg_connection ? Qt::Checked : Qt::Unchecked);
- ui_->autoImportMissingKeyCheckBox->setCheckState(Qt::Unchecked);
- try {
- bool auto_import_missing_key =
- settings.lookup("network.auto_import_missing_key");
- if (auto_import_missing_key)
- ui_->autoImportMissingKeyCheckBox->setCheckState(Qt::Checked);
- else
- ui_->autoImportMissingKeyCheckBox->setCheckState(Qt::Unchecked);
- } catch (...) {
- GF_UI_LOG_ERROR("setting operation error: auto_import_missing_key");
- }
+ bool prohibit_update_checking =
+ settings.value("network/prohibit_update_checking").toBool();
+ ui_->prohibitUpdateCheck->setCheckState(
+ prohibit_update_checking ? Qt::Checked : Qt::Unchecked);
+
+ bool auto_import_missing_key =
+ settings.value("network/auto_import_missing_key", true).toBool();
+ ui_->autoImportMissingKeyCheckBox->setCheckState(
+ auto_import_missing_key ? Qt::Checked : Qt::Unchecked);
switch_ui_enabled(ui_->enableProxyCheckBox->isChecked());
switch_ui_proxy_type(ui_->proxyTypeComboBox->currentText());
}
void GpgFrontend::UI::NetworkTab::ApplySettings() {
- auto &settings =
- GpgFrontend::GlobalSettingStation::GetInstance().GetMainSettings();
-
- if (!settings.exists("proxy") ||
- settings.lookup("proxy").getType() != libconfig::Setting::TypeGroup)
- settings.add("proxy", libconfig::Setting::TypeGroup);
-
- auto &proxy = settings["proxy"];
-
- if (!proxy.exists("proxy_host"))
- proxy.add("proxy_host", libconfig::Setting::TypeString) =
- ui_->proxyServerAddressEdit->text().toStdString();
- else {
- proxy["proxy_host"] = ui_->proxyServerAddressEdit->text().toStdString();
- }
-
- if (!proxy.exists("username"))
- proxy.add("username", libconfig::Setting::TypeString) =
- ui_->usernameEdit->text().toStdString();
- else {
- proxy["username"] = ui_->usernameEdit->text().toStdString();
- }
-
- if (!proxy.exists("password"))
- proxy.add("password", libconfig::Setting::TypeString) =
- ui_->passwordEdit->text().toStdString();
- else {
- proxy["password"] = ui_->passwordEdit->text().toStdString();
- }
-
- if (!proxy.exists("port"))
- proxy.add("port", libconfig::Setting::TypeInt) = ui_->portSpin->value();
- else {
- proxy["port"] = ui_->portSpin->value();
- }
-
- if (!proxy.exists("proxy_type"))
- proxy.add("proxy_type", libconfig::Setting::TypeString) =
- ui_->proxyTypeComboBox->currentText().toStdString();
- else {
- proxy["proxy_type"] = ui_->proxyTypeComboBox->currentText().toStdString();
- }
-
- if (!proxy.exists("enable"))
- proxy.add("enable", libconfig::Setting::TypeBoolean) =
- ui_->enableProxyCheckBox->isChecked();
- else {
- proxy["enable"] = ui_->enableProxyCheckBox->isChecked();
- }
-
- if (!settings.exists("network") ||
- settings.lookup("network").getType() != libconfig::Setting::TypeGroup)
- settings.add("network", libconfig::Setting::TypeGroup);
-
- auto &network = settings["network"];
-
- if (!network.exists("forbid_all_gnupg_connection"))
- network.add("forbid_all_gnupg_connection",
- libconfig::Setting::TypeBoolean) =
- ui_->forbidALLGnuPGNetworkConnectionCheckBox->isChecked();
- else {
- network["forbid_all_gnupg_connection"] =
- ui_->forbidALLGnuPGNetworkConnectionCheckBox->isChecked();
- }
-
- if (!network.exists("prohibit_update_checking"))
- network.add("prohibit_update_checking", libconfig::Setting::TypeBoolean) =
- ui_->prohibitUpdateCheck->isChecked();
- else {
- network["prohibit_update_checking"] = ui_->prohibitUpdateCheck->isChecked();
- }
-
- if (!network.exists("auto_import_missing_key"))
- network.add("auto_import_missing_key", libconfig::Setting::TypeBoolean) =
- ui_->autoImportMissingKeyCheckBox->isChecked();
- else {
- network["auto_import_missing_key"] =
- ui_->autoImportMissingKeyCheckBox->isChecked();
- }
+ auto settings =
+ GpgFrontend::GlobalSettingStation::GetInstance().GetSettings();
+
+ settings.setValue("proxy/proxy_host", ui_->proxyServerAddressEdit->text());
+ settings.setValue("proxy/username", ui_->usernameEdit->text());
+ settings.setValue("proxy/password", ui_->passwordEdit->text());
+ settings.setValue("proxy/port", ui_->portSpin->value());
+ settings.setValue("proxy/proxy_type", ui_->proxyTypeComboBox->currentText());
+ settings.setValue("proxy/enable", ui_->enableProxyCheckBox->isChecked());
+
+ settings.setValue("network/forbid_all_gnupg_connection",
+ ui_->forbidALLGnuPGNetworkConnectionCheckBox->isChecked());
+ settings.setValue("network/prohibit_update_checking",
+ ui_->prohibitUpdateCheck->isChecked());
+ settings.setValue("network/auto_import_missing_key",
+ ui_->autoImportMissingKeyCheckBox->isChecked());
apply_proxy_settings();
}
diff --git a/src/ui/main_window/KeyMgmt.cpp b/src/ui/main_window/KeyMgmt.cpp
index 87b576b8..a26637f0 100644
--- a/src/ui/main_window/KeyMgmt.cpp
+++ b/src/ui/main_window/KeyMgmt.cpp
@@ -177,8 +177,10 @@ void KeyMgmt::create_actions() {
});
bool const forbid_all_gnupg_connection =
- GlobalSettingStation::GetInstance().LookupSettings(
- "network.forbid_all_gnupg_connection", false);
+ GlobalSettingStation::GetInstance()
+ .GetSettings()
+ .value("network/forbid_all_gnupg_connection", false)
+ .toBool();
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 0faa7379..0ae6d409 100644
--- a/src/ui/main_window/MainWindow.cpp
+++ b/src/ui/main_window/MainWindow.cpp
@@ -127,8 +127,10 @@ void MainWindow::Init() noexcept {
connect(qApp, &QCoreApplication::aboutToQuit, this, []() {
GF_UI_LOG_DEBUG("about to quit process started");
- if (GlobalSettingStation::GetInstance().LookupSettings(
- "general.clear_gpg_password_cache", false)) {
+ if (GlobalSettingStation::GetInstance()
+ .GetSettings()
+ .value("general/clear_gpg_password_cache", false)
+ .toBool()) {
if (GpgFrontend::GpgAdvancedOperator::ClearGpgPasswordCache()) {
GF_UI_LOG_DEBUG("clear gpg password cache done");
} else {
@@ -155,28 +157,9 @@ void MainWindow::Init() noexcept {
recover_editor_unsaved_pages_from_cache();
// check if need to open wizard window
- auto &settings = GlobalSettingStation::GetInstance().GetMainSettings();
-
- if (!settings.exists("wizard") ||
- settings.lookup("wizard").getType() != libconfig::Setting::TypeGroup)
- settings.add("wizard", libconfig::Setting::TypeGroup);
-
- auto &wizard = settings["wizard"];
-
- // Show wizard, if the don't show wizard message box wasn't checked
- // and keylist doesn't contain a private key
-
- if (!wizard.exists("show_wizard"))
- wizard.add("show_wizard", libconfig::Setting::TypeBoolean) = true;
-
- bool show_wizard = true;
- wizard.lookupValue("show_wizard", show_wizard);
-
- GF_UI_LOG_DEBUG("wizard show_wizard: {}", show_wizard);
-
- if (show_wizard) {
- slot_start_wizard();
- }
+ auto settings = GlobalSettingStation::GetInstance().GetSettings();
+ bool show_wizard = settings.value("wizard/show_wizard", true).toBool();
+ if (show_wizard) slot_start_wizard();
} catch (...) {
GF_UI_LOG_ERROR(_("Critical error occur while loading GpgFrontend."));
@@ -188,44 +171,23 @@ void MainWindow::Init() noexcept {
}
void MainWindow::restore_settings() {
- try {
- GF_UI_LOG_DEBUG("restore settings key_server");
-
- KeyServerSO key_server(SettingsObject("key_server"));
-
- if (key_server.server_list.empty()) key_server.ResetDefaultServerList();
- if (key_server.default_server < 0) key_server.default_server = 0;
+ GF_UI_LOG_DEBUG("restore settings for main windows");
- auto &settings = GlobalSettingStation::GetInstance().GetMainSettings();
+ KeyServerSO key_server(SettingsObject("key_server"));
+ if (key_server.server_list.empty()) key_server.ResetDefaultServerList();
+ if (key_server.default_server < 0) key_server.default_server = 0;
- if (!settings.exists("general") ||
- settings.lookup("general").getType() != libconfig::Setting::TypeGroup) {
- settings.add("general", libconfig::Setting::TypeGroup);
- }
-
- auto &general = settings["general"];
-
- if (!general.exists("non_ascii_when_export")) {
- general.add("non_ascii_when_export", libconfig::Setting::TypeBoolean) =
- true;
- }
+ auto settings = GlobalSettingStation::GetInstance().GetSettings();
+ if (!settings.contains("general/non_ascii_when_export")) {
+ settings.setValue("general/non_ascii_when_export", true);
+ }
- // set appearance
- import_button_->setToolButtonStyle(icon_style_);
+ // set appearance
+ import_button_->setToolButtonStyle(icon_style_);
- prohibit_update_checking_ = false;
- try {
- prohibit_update_checking_ =
- settings.lookup("network.prohibit_update_checking");
- } catch (...) {
- GF_UI_LOG_ERROR("setting operation error: prohibit_update_checking");
- }
+ prohibit_update_checking_ =
+ settings.value("network/prohibit_update_check").toBool();
- } catch (...) {
- GF_UI_LOG_ERROR("cannot resolve settings");
- }
-
- GlobalSettingStation::GetInstance().SyncSettings();
GF_UI_LOG_DEBUG("settings restored");
}
@@ -268,10 +230,6 @@ void MainWindow::recover_editor_unsaved_pages_from_cache() {
}
}
-void MainWindow::save_settings() {
- GlobalSettingStation::GetInstance().SyncSettings();
-}
-
void MainWindow::close_attachment_dock() {
if (!attachment_dock_created_) {
return;
@@ -287,7 +245,6 @@ void MainWindow::closeEvent(QCloseEvent *event) {
* modified documents in any tab
*/
if (edit_->MaybeSaveAnyTab()) {
- save_settings();
event->accept();
} else {
event->ignore();
diff --git a/src/ui/main_window/MainWindow.h b/src/ui/main_window/MainWindow.h
index a88ed483..66b61d68 100644
--- a/src/ui/main_window/MainWindow.h
+++ b/src/ui/main_window/MainWindow.h
@@ -419,11 +419,6 @@ class MainWindow : public GeneralMainWindow {
void recover_editor_unsaved_pages_from_cache();
/**
- * @details Save settings to ini-file.
- */
- void save_settings();
-
- /**
* @brief return true, if restart is needed
*/
[[nodiscard]] int get_restart_needed() const;
diff --git a/src/ui/main_window/MainWindowFileSlotFunction.cpp b/src/ui/main_window/MainWindowFileSlotFunction.cpp
index fee4d493..c4cce04f 100644
--- a/src/ui/main_window/MainWindowFileSlotFunction.cpp
+++ b/src/ui/main_window/MainWindowFileSlotFunction.cpp
@@ -51,8 +51,10 @@ void MainWindow::SlotFileEncrypt(const QString& path) {
}
bool const non_ascii_when_export =
- GlobalSettingStation::GetInstance().LookupSettings(
- "general.non_ascii_when_export", true);
+ GlobalSettingStation::GetInstance()
+ .GetSettings()
+ .value("general/non_ascii_when_export", true)
+ .toBool();
auto out_path =
SetExtensionOfOutputFile(path, kENCRYPT, !non_ascii_when_export);
@@ -157,8 +159,10 @@ void MainWindow::SlotDirectoryEncrypt(const QString& path) {
}
bool const non_ascii_when_export =
- GlobalSettingStation::GetInstance().LookupSettings(
- "general.non_ascii_when_export", true);
+ GlobalSettingStation::GetInstance()
+ .GetSettings()
+ .value("general/non_ascii_when_export", true)
+ .toBool();
auto out_path = SetExtensionOfOutputFileForArchive(path, kENCRYPT,
!non_ascii_when_export);
@@ -379,8 +383,10 @@ void MainWindow::SlotFileSign(const QString& path) {
}
bool const non_ascii_when_export =
- GlobalSettingStation::GetInstance().LookupSettings(
- "general.non_ascii_when_export", true);
+ GlobalSettingStation::GetInstance()
+ .GetSettings()
+ .value("general/non_ascii_when_export", true)
+ .toBool();
auto sig_file_path =
SetExtensionOfOutputFile(path, kSIGN, !non_ascii_when_export);
@@ -528,8 +534,10 @@ void MainWindow::SlotFileEncryptSign(const QString& path) {
}
bool const non_ascii_when_export =
- GlobalSettingStation::GetInstance().LookupSettings(
- "general.non_ascii_when_export", true);
+ GlobalSettingStation::GetInstance()
+ .GetSettings()
+ .value("general/non_ascii_when_export", true)
+ .toBool();
auto out_path =
SetExtensionOfOutputFile(path, kENCRYPT_SIGN, !non_ascii_when_export);
@@ -627,8 +635,10 @@ void MainWindow::SlotDirectoryEncryptSign(const QString& path) {
}
bool const non_ascii_when_export =
- GlobalSettingStation::GetInstance().LookupSettings(
- "general.non_ascii_when_export", true);
+ GlobalSettingStation::GetInstance()
+ .GetSettings()
+ .value("general/non_ascii_when_export", true)
+ .toBool();
auto out_path = SetExtensionOfOutputFileForArchive(path, kENCRYPT_SIGN,
!non_ascii_when_export);
diff --git a/src/ui/main_window/MainWindowSlotUI.cpp b/src/ui/main_window/MainWindowSlotUI.cpp
index 2c7a6f62..4988d392 100644
--- a/src/ui/main_window/MainWindowSlotUI.cpp
+++ b/src/ui/main_window/MainWindowSlotUI.cpp
@@ -121,7 +121,6 @@ void MainWindow::slot_open_settings_dialog() {
// restart mainwindow if necessary
if (get_restart_needed() != 0) {
if (edit_->MaybeSaveAnyTab()) {
- save_settings();
emit SignalRestartApplication(get_restart_needed());
}
}
diff --git a/src/ui/main_window/MainWindowUI.cpp b/src/ui/main_window/MainWindowUI.cpp
index 3e16ab28..3bc2ba23 100644
--- a/src/ui/main_window/MainWindowUI.cpp
+++ b/src/ui/main_window/MainWindowUI.cpp
@@ -315,8 +315,10 @@ void MainWindow::create_actions() {
});
bool forbid_all_gnupg_connection =
- GlobalSettingStation::GetInstance().LookupSettings(
- "network.forbid_all_gnupg_connection", false);
+ GlobalSettingStation::GetInstance()
+ .GetSettings()
+ .value("network/forbid_all_gnupg_connection", false)
+ .toBool();
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 0f97a2c9..ea33e494 100644
--- a/src/ui/widgets/KeyList.cpp
+++ b/src/ui/widgets/KeyList.cpp
@@ -62,8 +62,10 @@ void KeyList::init() {
popup_menu_ = new QMenu(this);
bool forbid_all_gnupg_connection =
- GlobalSettingStation::GetInstance().LookupSettings(
- "network.forbid_all_gnupg_connection", false);
+ GlobalSettingStation::GetInstance()
+ .GetSettings()
+ .value("network/forbid_all_gnupg_connection", false)
+ .toBool();
// forbidden networks connections
if (forbid_all_gnupg_connection) ui_->syncButton->setDisabled(true);
@@ -358,8 +360,10 @@ void KeyList::dropEvent(QDropEvent* event) {
// "always import keys"-CheckBox
auto* check_box = new QCheckBox(_("Always import without bothering."));
- bool confirm_import_keys = GlobalSettingStation::GetInstance().LookupSettings(
- "general.confirm_import_keys", true);
+ bool confirm_import_keys = GlobalSettingStation::GetInstance()
+ .GetSettings()
+ .value("general/confirm_import_keys", true)
+ .toBool();
if (confirm_import_keys) check_box->setCheckState(Qt::Checked);
// Buttons for ok and cancel
@@ -379,20 +383,8 @@ void KeyList::dropEvent(QDropEvent* event) {
dialog->exec();
if (dialog->result() == QDialog::Rejected) return;
- auto& settings = GlobalSettingStation::GetInstance().GetMainSettings();
-
- if (!settings.exists("general") ||
- settings.lookup("general").getType() != libconfig::Setting::TypeGroup) {
- settings.add("general", libconfig::Setting::TypeGroup);
- }
- auto& general = settings["general"];
- if (!general.exists("confirm_import_keys")) {
- general.add("confirm_import_keys", libconfig::Setting::TypeBoolean) =
- check_box->isChecked();
- } else {
- general["confirm_import_keys"] = check_box->isChecked();
- }
- GlobalSettingStation::GetInstance().SyncSettings();
+ auto settings = GlobalSettingStation::GetInstance().GetSettings();
+ settings.setValue("general/confirm_import_keys", check_box->isChecked());
}
if (event->mimeData()->hasUrls()) {
diff --git a/src/ui/widgets/TextEdit.cpp b/src/ui/widgets/TextEdit.cpp
index 1f1f0242..61fdd609 100644
--- a/src/ui/widgets/TextEdit.cpp
+++ b/src/ui/widgets/TextEdit.cpp
@@ -368,12 +368,11 @@ void TextEdit::SlotAppendText2CurTextPage(const QString& text) {
}
FilePage* TextEdit::CurFilePage() const {
- auto* curFilePage = qobject_cast<FilePage*>(tab_widget_->currentWidget());
- if (curFilePage != nullptr) {
- return curFilePage;
- } else {
- return nullptr;
+ auto* cur_file_page = qobject_cast<FilePage*>(tab_widget_->currentWidget());
+ if (cur_file_page != nullptr) {
+ return cur_file_page;
}
+ return nullptr;
}
int TextEdit::TabCount() const { return tab_widget_->count(); }
@@ -610,15 +609,11 @@ void TextEdit::slot_file_page_path_changed(const QString& path) const {
void TextEdit::slot_save_status_to_cache_for_revovery() {
if (this->text_page_data_modified_count_++ % 8 != 0) return;
- auto& settings = GlobalSettingStation::GetInstance().GetMainSettings();
- bool restore_text_editor_page = false;
- try {
- restore_text_editor_page =
- settings.lookup("general.restore_text_editor_page");
- } catch (...) {
- GF_UI_LOG_ERROR("setting operation error: restore_text_editor_page");
- }
+ auto settings =
+ GpgFrontend::GlobalSettingStation::GetInstance().GetSettings();
+ bool restore_text_editor_page =
+ settings.value("general/restore_text_editor_page", false).toBool();
if (!restore_text_editor_page) {
GF_UI_LOG_DEBUG("restore_text_editor_page is false, ignoring...");
return;
diff --git a/src/ui/widgets/VerifyKeyDetailBox.cpp b/src/ui/widgets/VerifyKeyDetailBox.cpp
index a2c130ad..db81ffa8 100644
--- a/src/ui/widgets/VerifyKeyDetailBox.cpp
+++ b/src/ui/widgets/VerifyKeyDetailBox.cpp
@@ -45,8 +45,10 @@ VerifyKeyDetailBox::VerifyKeyDetailBox(const GpgSignature& signature,
this->setTitle("A Error Signature");
bool forbid_all_gnupg_connection =
- GlobalSettingStation::GetInstance().LookupSettings(
- "network.forbid_all_gnupg_connection", false);
+ GlobalSettingStation::GetInstance()
+ .GetSettings()
+ .value("network/forbid_all_gnupg_connection", false)
+ .toBool();
auto* import_button = new QPushButton(_("Import from keyserver"));
import_button->setDisabled(forbid_all_gnupg_connection);