feat: simplify settings lookup
This commit is contained in:
parent
7cdf67cfab
commit
25dc98b395
@ -30,6 +30,7 @@
|
|||||||
|
|
||||||
#include <gpg-error.h>
|
#include <gpg-error.h>
|
||||||
#include <gpgme.h>
|
#include <gpgme.h>
|
||||||
|
#include <spdlog/spdlog.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
@ -37,14 +38,11 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "core/GpgConstants.h"
|
#include "core/GpgConstants.h"
|
||||||
#include "core/GpgModel.h"
|
|
||||||
#include "core/common/CoreCommonUtil.h"
|
#include "core/common/CoreCommonUtil.h"
|
||||||
#include "core/function/CoreSignalStation.h"
|
#include "core/function/CoreSignalStation.h"
|
||||||
#include "core/function/GlobalSettingStation.h"
|
|
||||||
#include "core/function/gpg/GpgCommandExecutor.h"
|
#include "core/function/gpg/GpgCommandExecutor.h"
|
||||||
|
#include "core/thread/Task.h"
|
||||||
#include "core/thread/TaskRunnerGetter.h"
|
#include "core/thread/TaskRunnerGetter.h"
|
||||||
#include "spdlog/spdlog.h"
|
|
||||||
#include "thread/Task.h"
|
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
@ -232,19 +230,8 @@ void GpgContext::post_init_ctx() {
|
|||||||
// preload info
|
// preload info
|
||||||
auto &info = GetInfo();
|
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
|
// use custom qt dialog to replace pinentry
|
||||||
if (!use_pinentry_as_password_input_dialog) {
|
if (!args_.use_pinentry) {
|
||||||
SetPassphraseCb(custom_passphrase_cb);
|
SetPassphraseCb(custom_passphrase_cb);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,10 +32,8 @@
|
|||||||
#include <optional>
|
#include <optional>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "GpgConstants.h"
|
|
||||||
#include "GpgFunctionObject.h"
|
#include "GpgFunctionObject.h"
|
||||||
#include "GpgInfo.h"
|
#include "GpgInfo.h"
|
||||||
#include "GpgModel.h"
|
|
||||||
|
|
||||||
namespace GpgFrontend {
|
namespace GpgFrontend {
|
||||||
|
|
||||||
@ -59,6 +57,8 @@ struct GpgContextInitArgs {
|
|||||||
bool custom_gpgconf = false;
|
bool custom_gpgconf = false;
|
||||||
std::string custom_gpgconf_path;
|
std::string custom_gpgconf_path;
|
||||||
|
|
||||||
|
bool use_pinentry = false;
|
||||||
|
|
||||||
GpgContextInitArgs() = default;
|
GpgContextInitArgs() = default;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -33,6 +33,7 @@
|
|||||||
#include <spdlog/sinks/stdout_color_sinks.h>
|
#include <spdlog/sinks/stdout_color_sinks.h>
|
||||||
|
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include "GpgFunctionObject.h"
|
#include "GpgFunctionObject.h"
|
||||||
#include "core/GpgContext.h"
|
#include "core/GpgContext.h"
|
||||||
@ -108,76 +109,58 @@ void init_gpgfrontend_core() {
|
|||||||
gpgme_set_locale(nullptr, LC_MESSAGES, setlocale(LC_MESSAGES, nullptr));
|
gpgme_set_locale(nullptr, LC_MESSAGES, setlocale(LC_MESSAGES, nullptr));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// get settings
|
|
||||||
auto& settings = GlobalSettingStation::GetInstance().GetUISettings();
|
|
||||||
|
|
||||||
// read settings
|
// read settings
|
||||||
bool forbid_all_gnupg_connection = false;
|
bool forbid_all_gnupg_connection =
|
||||||
try {
|
GlobalSettingStation::GetInstance().LookupSettings(
|
||||||
forbid_all_gnupg_connection =
|
"network.forbid_all_gnupg_connection", false);
|
||||||
settings.lookup("network.forbid_all_gnupg_connection");
|
|
||||||
} catch (...) {
|
|
||||||
SPDLOG_ERROR("setting operation error: forbid_all_gnupg_connection");
|
|
||||||
}
|
|
||||||
|
|
||||||
bool auto_import_missing_key = false;
|
bool auto_import_missing_key =
|
||||||
try {
|
GlobalSettingStation::GetInstance().LookupSettings(
|
||||||
auto_import_missing_key =
|
"network.auto_import_missing_key", false);
|
||||||
settings.lookup("network.auto_import_missing_key");
|
|
||||||
} catch (...) {
|
|
||||||
SPDLOG_ERROR("setting operation error: auto_import_missing_key");
|
|
||||||
}
|
|
||||||
|
|
||||||
// read from settings file
|
bool use_custom_key_database_path =
|
||||||
bool use_custom_key_database_path = false;
|
GlobalSettingStation::GetInstance().LookupSettings(
|
||||||
try {
|
"general.use_custom_key_database_path", false);
|
||||||
use_custom_key_database_path =
|
|
||||||
settings.lookup("general.use_custom_key_database_path");
|
std::string custom_key_database_path =
|
||||||
} catch (...) {
|
GlobalSettingStation::GetInstance().LookupSettings(
|
||||||
SPDLOG_ERROR("setting operation error: use_custom_key_database_path");
|
"general.custom_key_database_path", std::string{});
|
||||||
}
|
|
||||||
|
bool use_custom_gnupg_install_path =
|
||||||
|
GlobalSettingStation::GetInstance().LookupSettings(
|
||||||
|
"general.use_custom_gnupg_install_path", false);
|
||||||
|
|
||||||
|
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: {}",
|
SPDLOG_DEBUG("core loaded if use custom key databse path: {}",
|
||||||
use_custom_key_database_path);
|
use_custom_key_database_path);
|
||||||
|
|
||||||
std::string custom_key_database_path;
|
|
||||||
try {
|
|
||||||
custom_key_database_path = static_cast<std::string>(
|
|
||||||
settings.lookup("general.custom_key_database_path"));
|
|
||||||
|
|
||||||
} catch (...) {
|
|
||||||
SPDLOG_ERROR("setting operation error: custom_key_database_path");
|
|
||||||
}
|
|
||||||
|
|
||||||
SPDLOG_DEBUG("core loaded custom key databse path: {}",
|
SPDLOG_DEBUG("core loaded custom key databse path: {}",
|
||||||
custom_key_database_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
|
// 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;
|
use_custom_gnupg_install_path = false;
|
||||||
SPDLOG_ERROR("core loaded custom gpgconf path error: {}",
|
SPDLOG_ERROR("core loaded custom gpgconf path is illegal: {}",
|
||||||
custom_gnupg_install_path.u8string());
|
custom_gnupg_install_fs_path.u8string());
|
||||||
} else {
|
} else {
|
||||||
SPDLOG_DEBUG("core loaded custom gpgconf path: {}",
|
SPDLOG_DEBUG("core loaded custom gpgconf path: {}",
|
||||||
custom_gnupg_install_path.u8string());
|
custom_gnupg_install_fs_path.u8string());
|
||||||
}
|
}
|
||||||
|
|
||||||
// init default channel
|
// init default channel
|
||||||
@ -190,22 +173,22 @@ void init_gpgfrontend_core() {
|
|||||||
args.db_path = custom_key_database_path;
|
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) {
|
if (use_custom_gnupg_install_path) {
|
||||||
args.custom_gpgconf = true;
|
args.custom_gpgconf = true;
|
||||||
args.custom_gpgconf_path =
|
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));
|
return std::unique_ptr<ChannelObject>(new GpgContext(args));
|
||||||
});
|
});
|
||||||
|
|
||||||
// exit if failed
|
// exit if failed
|
||||||
if (!default_ctx.good()) {
|
if (!default_ctx.good()) {
|
||||||
SPDLOG_ERROR("default gpgme context init error, exit.");
|
SPDLOG_ERROR("default gnupg context init error");
|
||||||
return;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// async init no-ascii channel
|
// async init no-ascii channel
|
||||||
@ -226,13 +209,20 @@ void init_gpgfrontend_core() {
|
|||||||
args.db_path = custom_key_database_path;
|
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.offline_mode = forbid_all_gnupg_connection;
|
||||||
args.auto_import_missing_key = auto_import_missing_key;
|
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));
|
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;
|
return ctx.good() ? 0 : -1;
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
@ -56,11 +56,8 @@ GpgFrontend::GlobalSettingStation::GlobalSettingStation(int channel) noexcept
|
|||||||
SPDLOG_INFO("app conf path: {}", ui_config_path_.u8string());
|
SPDLOG_INFO("app conf path: {}", ui_config_path_.u8string());
|
||||||
|
|
||||||
if (!is_directory(app_configure_path_)) create_directory(app_configure_path_);
|
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_data_path_)) create_directory(app_data_path_);
|
||||||
|
|
||||||
if (!is_directory(app_log_path_)) create_directory(app_log_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 (!is_directory(ui_config_dir_path_)) create_directory(ui_config_dir_path_);
|
||||||
|
|
||||||
if (!exists(ui_config_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() {}
|
void GpgFrontend::GlobalSettingStation::init_app_secure_key() {}
|
||||||
|
|
||||||
GpgFrontend::GlobalSettingStation::~GlobalSettingStation() noexcept = default;
|
GpgFrontend::GlobalSettingStation::~GlobalSettingStation() noexcept = default;
|
||||||
|
@ -60,7 +60,23 @@ class GPGFRONTEND_CORE_EXPORT GlobalSettingStation
|
|||||||
*
|
*
|
||||||
* @return libconfig::Setting&
|
* @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
|
* @brief Get the App Dir object
|
||||||
|
27
src/init.cpp
27
src/init.cpp
@ -32,6 +32,7 @@
|
|||||||
#include <spdlog/sinks/stdout_color_sinks.h>
|
#include <spdlog/sinks/stdout_color_sinks.h>
|
||||||
|
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include "GpgFrontend.h"
|
#include "GpgFrontend.h"
|
||||||
#include "GpgFrontendBuildInfo.h"
|
#include "GpgFrontendBuildInfo.h"
|
||||||
@ -90,26 +91,14 @@ void shutdown_logging_system() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void init_global_path_env() {
|
void init_global_path_env() {
|
||||||
auto &settings =
|
// read settings
|
||||||
GpgFrontend::GlobalSettingStation::GetInstance().GetUISettings();
|
bool use_custom_gnupg_install_path =
|
||||||
|
GpgFrontend::GlobalSettingStation::GetInstance().LookupSettings(
|
||||||
|
"general.use_custom_gnupg_install_path", false);
|
||||||
|
|
||||||
bool use_custom_gnupg_install_path = false;
|
std::string custom_gnupg_install_path =
|
||||||
try {
|
GpgFrontend::GlobalSettingStation::GetInstance().LookupSettings(
|
||||||
use_custom_gnupg_install_path =
|
"general.custom_gnupg_install_path", std::string{});
|
||||||
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");
|
|
||||||
}
|
|
||||||
|
|
||||||
// add custom gnupg install path into env $PATH
|
// add custom gnupg install path into env $PATH
|
||||||
if (use_custom_gnupg_install_path && !custom_gnupg_install_path.empty()) {
|
if (use_custom_gnupg_install_path && !custom_gnupg_install_path.empty()) {
|
||||||
|
@ -33,6 +33,8 @@
|
|||||||
#include <spdlog/sinks/rotating_file_sink.h>
|
#include <spdlog/sinks/rotating_file_sink.h>
|
||||||
#include <spdlog/sinks/stdout_color_sinks.h>
|
#include <spdlog/sinks/stdout_color_sinks.h>
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include "core/GpgConstants.h"
|
#include "core/GpgConstants.h"
|
||||||
#include "core/function/GlobalSettingStation.h"
|
#include "core/function/GlobalSettingStation.h"
|
||||||
#include "core/thread/CtxCheckTask.h"
|
#include "core/thread/CtxCheckTask.h"
|
||||||
@ -74,25 +76,26 @@ void InitGpgFrontendUI(QApplication* app) {
|
|||||||
CommonUtils::GetInstance();
|
CommonUtils::GetInstance();
|
||||||
|
|
||||||
// application proxy configure
|
// application proxy configure
|
||||||
|
bool proxy_enable =
|
||||||
auto& settings = GlobalSettingStation::GetInstance().GetUISettings();
|
GlobalSettingStation::GetInstance().LookupSettings("proxy.enable", false);
|
||||||
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);
|
|
||||||
|
|
||||||
// if enable proxy for application
|
// if enable proxy for application
|
||||||
if (proxy_enable) {
|
if (proxy_enable) {
|
||||||
try {
|
try {
|
||||||
std::string proxy_type = settings.lookup("proxy.proxy_type");
|
std::string proxy_type =
|
||||||
std::string proxy_host = settings.lookup("proxy.proxy_host");
|
GlobalSettingStation::GetInstance().LookupSettings("proxy.proxy_type",
|
||||||
int proxy_port = settings.lookup("proxy.port");
|
std::string{});
|
||||||
std::string proxy_username = settings.lookup("proxy.username");
|
std::string proxy_host =
|
||||||
std::string proxy_password = settings.lookup("proxy.password");
|
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,
|
SPDLOG_DEBUG("proxy settings: type {}, host {}, port: {}", proxy_type,
|
||||||
proxy_host, proxy_port);
|
proxy_host, proxy_port);
|
||||||
|
|
||||||
|
@ -47,13 +47,8 @@ Wizard::Wizard(QWidget* parent) : QWizard(parent) {
|
|||||||
setPixmap(QWizard::LogoPixmap, QPixmap(":/logo_small.png"));
|
setPixmap(QWizard::LogoPixmap, QPixmap(":/logo_small.png"));
|
||||||
setPixmap(QWizard::BannerPixmap, QPixmap(":/banner.png"));
|
setPixmap(QWizard::BannerPixmap, QPixmap(":/banner.png"));
|
||||||
|
|
||||||
auto& settings = GlobalSettingStation::GetInstance().GetUISettings();
|
int next_page_id = GlobalSettingStation::GetInstance().LookupSettings(
|
||||||
int next_page_id = -1;
|
"wizard.next_page", -1);
|
||||||
try {
|
|
||||||
next_page_id = settings.lookup("wizard.next_page");
|
|
||||||
} catch (...) {
|
|
||||||
SPDLOG_ERROR("setting operation error");
|
|
||||||
}
|
|
||||||
setStartId(next_page_id);
|
setStartId(next_page_id);
|
||||||
|
|
||||||
connect(this, &Wizard::accepted, this, &Wizard::slot_wizard_accepted);
|
connect(this, &Wizard::accepted, this, &Wizard::slot_wizard_accepted);
|
||||||
|
@ -47,16 +47,9 @@ KeyServerImportDialog::KeyServerImportDialog(bool automatic, QWidget* parent)
|
|||||||
// Layout for messagebox
|
// Layout for messagebox
|
||||||
auto* message_layout = new QHBoxLayout();
|
auto* message_layout = new QHBoxLayout();
|
||||||
|
|
||||||
// get settings
|
bool forbid_all_gnupg_connection =
|
||||||
auto& settings = GlobalSettingStation::GetInstance().GetUISettings();
|
GlobalSettingStation::GetInstance().LookupSettings(
|
||||||
// read settings
|
"network.forbid_all_gnupg_connection", false);
|
||||||
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");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (forbid_all_gnupg_connection) {
|
if (forbid_all_gnupg_connection) {
|
||||||
QMessageBox::critical(this, "Forbidden", "GnuPG is in offline mode now.");
|
QMessageBox::critical(this, "Forbidden", "GnuPG is in offline mode now.");
|
||||||
|
@ -43,26 +43,14 @@ KeyGenDialog::KeyGenDialog(QWidget* parent)
|
|||||||
button_box_ =
|
button_box_ =
|
||||||
new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
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 use_pinentry_as_password_input_dialog =
|
||||||
bool longer_expiration_date = false;
|
GlobalSettingStation::GetInstance().LookupSettings(
|
||||||
try {
|
"general.use_pinentry_as_password_input_dialog", false);
|
||||||
longer_expiration_date = settings.lookup("general.longer_expiration_date");
|
|
||||||
SPDLOG_DEBUG("longer_expiration_date: {}", longer_expiration_date);
|
|
||||||
|
|
||||||
} 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;
|
use_pinentry_ = use_pinentry_as_password_input_dialog;
|
||||||
|
|
||||||
max_date_time_ = longer_expiration_date
|
max_date_time_ = longer_expiration_date
|
||||||
|
@ -40,26 +40,14 @@ namespace GpgFrontend::UI {
|
|||||||
SubkeyGenerateDialog::SubkeyGenerateDialog(const KeyId& key_id, QWidget* parent)
|
SubkeyGenerateDialog::SubkeyGenerateDialog(const KeyId& key_id, QWidget* parent)
|
||||||
: GeneralDialog(typeid(SubkeyGenerateDialog).name(), parent),
|
: GeneralDialog(typeid(SubkeyGenerateDialog).name(), parent),
|
||||||
key_(GpgKeyGetter::GetInstance().GetKey(key_id)) {
|
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 use_pinentry_as_password_input_dialog =
|
||||||
bool longer_expiration_date = false;
|
GlobalSettingStation::GetInstance().LookupSettings(
|
||||||
try {
|
"general.use_pinentry_as_password_input_dialog", false);
|
||||||
longer_expiration_date = settings.lookup("general.longer_expiration_date");
|
|
||||||
SPDLOG_DEBUG("longer expiration date: {}", longer_expiration_date);
|
|
||||||
|
|
||||||
} 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;
|
use_pinentry_ = use_pinentry_as_password_input_dialog;
|
||||||
|
|
||||||
max_date_time_ = longer_expiration_date
|
max_date_time_ = longer_expiration_date
|
||||||
|
@ -55,22 +55,15 @@ AdvancedTab::AdvancedTab(QWidget* parent) : QWidget(parent) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void AdvancedTab::SetSettings() {
|
void AdvancedTab::SetSettings() {
|
||||||
auto& settings = GlobalSettingStation::GetInstance().GetUISettings();
|
int stegano_checked = GlobalSettingStation::GetInstance().LookupSettings(
|
||||||
try {
|
"advanced.stegano_checked", false);
|
||||||
bool stegano_checked = settings.lookup("advanced.stegano_checked");
|
|
||||||
if (stegano_checked) stegano_check_box_->setCheckState(Qt::Checked);
|
if (stegano_checked) stegano_check_box_->setCheckState(Qt::Checked);
|
||||||
} catch (...) {
|
|
||||||
SPDLOG_ERROR("setting operation error: stegano_checked");
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
int auto_pubkey_exchange_checked =
|
||||||
bool auto_pubkey_exchange_checked =
|
GlobalSettingStation::GetInstance().LookupSettings(
|
||||||
settings.lookup("advanced.auto_pubkey_exchange_checked");
|
"advanced.auto_pubkey_exchange_checked", false);
|
||||||
if (auto_pubkey_exchange_checked)
|
if (auto_pubkey_exchange_checked)
|
||||||
auto_pubkey_exchange_check_box_->setCheckState(Qt::Checked);
|
auto_pubkey_exchange_check_box_->setCheckState(Qt::Checked);
|
||||||
} catch (...) {
|
|
||||||
SPDLOG_ERROR("setting operation error: auto_pubkey_exchange_checked");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AdvancedTab::ApplySettings() {
|
void AdvancedTab::ApplySettings() {
|
||||||
|
@ -104,8 +104,6 @@ KeyMgmt::KeyMgmt(QWidget* parent)
|
|||||||
qobject_cast<MainWindow*>(this->parent()),
|
qobject_cast<MainWindow*>(this->parent()),
|
||||||
&MainWindow::SlotSetStatusBarText);
|
&MainWindow::SlotSetStatusBarText);
|
||||||
|
|
||||||
auto& settings = GlobalSettingStation::GetInstance().GetUISettings();
|
|
||||||
|
|
||||||
this->statusBar()->show();
|
this->statusBar()->show();
|
||||||
|
|
||||||
setWindowTitle(_("KeyPair Management"));
|
setWindowTitle(_("KeyPair Management"));
|
||||||
@ -165,16 +163,9 @@ void KeyMgmt::create_actions() {
|
|||||||
CommonUtils::GetInstance()->SlotImportKeyFromClipboard(this);
|
CommonUtils::GetInstance()->SlotImportKeyFromClipboard(this);
|
||||||
});
|
});
|
||||||
|
|
||||||
// get settings
|
bool forbid_all_gnupg_connection =
|
||||||
auto& settings = GlobalSettingStation::GetInstance().GetUISettings();
|
GlobalSettingStation::GetInstance().LookupSettings(
|
||||||
// read settings
|
"network.forbid_all_gnupg_connection", false);
|
||||||
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");
|
|
||||||
}
|
|
||||||
|
|
||||||
import_key_from_key_server_act_ = new QAction(_("Keyserver"), this);
|
import_key_from_key_server_act_ = new QAction(_("Keyserver"), this);
|
||||||
import_key_from_key_server_act_->setIcon(
|
import_key_from_key_server_act_->setIcon(
|
||||||
|
@ -144,12 +144,8 @@ void MainWindow::Init() noexcept {
|
|||||||
connect(qApp, &QCoreApplication::aboutToQuit, this, []() {
|
connect(qApp, &QCoreApplication::aboutToQuit, this, []() {
|
||||||
SPDLOG_DEBUG("about to quit process started");
|
SPDLOG_DEBUG("about to quit process started");
|
||||||
|
|
||||||
auto &settings = GlobalSettingStation::GetInstance().GetUISettings();
|
if (GlobalSettingStation::GetInstance().LookupSettings(
|
||||||
try {
|
"general.clear_gpg_password_cache", false)) {
|
||||||
bool clear_gpg_password_cache =
|
|
||||||
settings.lookup("general.clear_gpg_password_cache");
|
|
||||||
|
|
||||||
if (clear_gpg_password_cache) {
|
|
||||||
if (GpgFrontend::GpgAdvancedOperator::GetInstance()
|
if (GpgFrontend::GpgAdvancedOperator::GetInstance()
|
||||||
.ClearGpgPasswordCache()) {
|
.ClearGpgPasswordCache()) {
|
||||||
SPDLOG_DEBUG("clear gpg password cache done");
|
SPDLOG_DEBUG("clear gpg password cache done");
|
||||||
@ -157,10 +153,6 @@ void MainWindow::Init() noexcept {
|
|||||||
SPDLOG_ERROR("clear gpg password cache error");
|
SPDLOG_ERROR("clear gpg password cache error");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (...) {
|
|
||||||
SPDLOG_ERROR("setting operation error: clear_gpg_password_cache");
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
@ -244,10 +236,8 @@ void MainWindow::restore_settings() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::save_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
|
// keyid-list of private checked keys
|
||||||
if (save_key_checked) {
|
if (save_key_checked) {
|
||||||
@ -259,11 +249,9 @@ void MainWindow::save_settings() {
|
|||||||
for (const auto &key_id : *key_ids_need_to_store)
|
for (const auto &key_id : *key_ids_need_to_store)
|
||||||
default_key_checked.push_back(key_id);
|
default_key_checked.push_back(key_id);
|
||||||
} else {
|
} else {
|
||||||
|
auto &settings = GlobalSettingStation::GetInstance().GetUISettings();
|
||||||
settings["general"].remove("save_key_checked");
|
settings["general"].remove("save_key_checked");
|
||||||
}
|
}
|
||||||
} catch (...) {
|
|
||||||
SPDLOG_ERROR("cannot save settings");
|
|
||||||
};
|
|
||||||
|
|
||||||
GlobalSettingStation::GetInstance().SyncSettings();
|
GlobalSettingStation::GetInstance().SyncSettings();
|
||||||
}
|
}
|
||||||
|
@ -167,14 +167,9 @@ void MainWindow::SlotFileEncrypt() {
|
|||||||
GpgError error;
|
GpgError error;
|
||||||
bool if_error = false;
|
bool if_error = false;
|
||||||
|
|
||||||
// Detect ascii mode
|
bool non_ascii_when_export =
|
||||||
auto& settings = GlobalSettingStation::GetInstance().GetUISettings();
|
GlobalSettingStation::GetInstance().LookupSettings(
|
||||||
bool non_ascii_when_export = true;
|
"general.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");
|
|
||||||
}
|
|
||||||
|
|
||||||
// get file info
|
// get file info
|
||||||
QFileInfo file_info(path);
|
QFileInfo file_info(path);
|
||||||
@ -390,14 +385,9 @@ void MainWindow::SlotFileSign() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Detect ascii mode
|
bool non_ascii_when_export =
|
||||||
auto& settings = GlobalSettingStation::GetInstance().GetUISettings();
|
GlobalSettingStation::GetInstance().LookupSettings(
|
||||||
bool non_ascii_when_export = true;
|
"general.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");
|
|
||||||
}
|
|
||||||
|
|
||||||
auto _channel = GPGFRONTEND_DEFAULT_CHANNEL;
|
auto _channel = GPGFRONTEND_DEFAULT_CHANNEL;
|
||||||
auto _extension = ".asc";
|
auto _extension = ".asc";
|
||||||
@ -469,14 +459,9 @@ void MainWindow::SlotFileVerify() {
|
|||||||
|
|
||||||
std::filesystem::path sign_file_path = in_path, data_file_path;
|
std::filesystem::path sign_file_path = in_path, data_file_path;
|
||||||
|
|
||||||
// Detect ascii mode
|
bool non_ascii_when_export =
|
||||||
auto& settings = GlobalSettingStation::GetInstance().GetUISettings();
|
GlobalSettingStation::GetInstance().LookupSettings(
|
||||||
bool non_ascii_when_export = true;
|
"general.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");
|
|
||||||
}
|
|
||||||
|
|
||||||
auto _channel = GPGFRONTEND_DEFAULT_CHANNEL;
|
auto _channel = GPGFRONTEND_DEFAULT_CHANNEL;
|
||||||
if (non_ascii_when_export) {
|
if (non_ascii_when_export) {
|
||||||
@ -581,14 +566,9 @@ void MainWindow::SlotFileEncryptSign() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// detect ascii mode
|
bool non_ascii_when_export =
|
||||||
auto& settings = GlobalSettingStation::GetInstance().GetUISettings();
|
GlobalSettingStation::GetInstance().LookupSettings(
|
||||||
bool non_ascii_when_export = true;
|
"general.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");
|
|
||||||
}
|
|
||||||
|
|
||||||
// get file info
|
// get file info
|
||||||
QFileInfo file_info(path);
|
QFileInfo file_info(path);
|
||||||
|
@ -253,16 +253,9 @@ void MainWindow::create_actions() {
|
|||||||
CommonUtils::GetInstance()->SlotImportKeyFromClipboard(this);
|
CommonUtils::GetInstance()->SlotImportKeyFromClipboard(this);
|
||||||
});
|
});
|
||||||
|
|
||||||
// get settings
|
bool forbid_all_gnupg_connection =
|
||||||
auto& settings = GlobalSettingStation::GetInstance().GetUISettings();
|
GlobalSettingStation::GetInstance().LookupSettings(
|
||||||
// read settings
|
"network.forbid_all_gnupg_connection", false);
|
||||||
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");
|
|
||||||
}
|
|
||||||
|
|
||||||
import_key_from_key_server_act_ = new QAction(_("Keyserver"), this);
|
import_key_from_key_server_act_ = new QAction(_("Keyserver"), this);
|
||||||
import_key_from_key_server_act_->setIcon(
|
import_key_from_key_server_act_->setIcon(
|
||||||
|
@ -60,6 +60,13 @@ void KeyList::init() {
|
|||||||
ui_->keyGroupTab->clear();
|
ui_->keyGroupTab->clear();
|
||||||
popup_menu_ = new QMenu(this);
|
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
|
// register key database refresh signal
|
||||||
connect(this, &KeyList::SignalRefreshDatabase, SignalStation::GetInstance(),
|
connect(this, &KeyList::SignalRefreshDatabase, SignalStation::GetInstance(),
|
||||||
&SignalStation::SignalKeyDatabaseRefresh);
|
&SignalStation::SignalKeyDatabaseRefresh);
|
||||||
@ -313,15 +320,9 @@ void KeyList::dropEvent(QDropEvent* event) {
|
|||||||
// "always import keys"-CheckBox
|
// "always import keys"-CheckBox
|
||||||
auto* checkBox = new QCheckBox(_("Always import without bothering."));
|
auto* checkBox = new QCheckBox(_("Always import without bothering."));
|
||||||
|
|
||||||
auto& settings = GlobalSettingStation::GetInstance().GetUISettings();
|
bool confirm_import_keys = GlobalSettingStation::GetInstance().LookupSettings(
|
||||||
bool confirm_import_keys = true;
|
"general.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);
|
if (confirm_import_keys) checkBox->setCheckState(Qt::Checked);
|
||||||
} catch (...) {
|
|
||||||
SPDLOG_ERROR("setting operation error: confirm_import_keys");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Buttons for ok and cancel
|
// Buttons for ok and cancel
|
||||||
auto* buttonBox =
|
auto* buttonBox =
|
||||||
@ -340,6 +341,8 @@ void KeyList::dropEvent(QDropEvent* event) {
|
|||||||
dialog->exec();
|
dialog->exec();
|
||||||
if (dialog->result() == QDialog::Rejected) return;
|
if (dialog->result() == QDialog::Rejected) return;
|
||||||
|
|
||||||
|
auto& settings = GlobalSettingStation::GetInstance().GetUISettings();
|
||||||
|
|
||||||
if (!settings.exists("general") ||
|
if (!settings.exists("general") ||
|
||||||
settings.lookup("general").getType() != libconfig::Setting::TypeGroup)
|
settings.lookup("general").getType() != libconfig::Setting::TypeGroup)
|
||||||
settings.add("general", 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) {
|
[[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) {
|
void KeyList::import_keys(const QByteArray& inBuffer) {
|
||||||
|
@ -42,16 +42,9 @@ VerifyKeyDetailBox::VerifyKeyDetailBox(const GpgSignature& signature,
|
|||||||
case GPG_ERR_NO_PUBKEY: {
|
case GPG_ERR_NO_PUBKEY: {
|
||||||
this->setTitle("A Error Signature");
|
this->setTitle("A Error Signature");
|
||||||
|
|
||||||
// get settings
|
bool forbid_all_gnupg_connection =
|
||||||
auto& settings = GlobalSettingStation::GetInstance().GetUISettings();
|
GlobalSettingStation::GetInstance().LookupSettings(
|
||||||
// read settings
|
"network.forbid_all_gnupg_connection", false);
|
||||||
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");
|
|
||||||
}
|
|
||||||
|
|
||||||
auto* import_button = new QPushButton(_("Import from keyserver"));
|
auto* import_button = new QPushButton(_("Import from keyserver"));
|
||||||
import_button->setDisabled(forbid_all_gnupg_connection);
|
import_button->setDisabled(forbid_all_gnupg_connection);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user