aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ui/MainWindow.cpp174
-rw-r--r--src/ui/settings/SettingsSendMail.cpp129
2 files changed, 92 insertions, 211 deletions
diff --git a/src/ui/MainWindow.cpp b/src/ui/MainWindow.cpp
index a5416fe9..a528184f 100644
--- a/src/ui/MainWindow.cpp
+++ b/src/ui/MainWindow.cpp
@@ -29,6 +29,7 @@
#include "ui/thread/VersionCheckThread.h"
#endif
#include "ui/SignalStation.h"
+#include "ui/data_struct/SettingsObj.h"
#include "ui/settings/GlobalSettingStation.h"
namespace GpgFrontend::UI {
@@ -143,62 +144,25 @@ void MainWindow::restoreSettings() {
LOG(INFO) << _("Called");
try {
- auto& settings = GlobalSettingStation::GetInstance().GetUISettings();
-
- if (!settings.exists("window") ||
- settings.lookup("window").getType() != libconfig::Setting::TypeGroup)
- settings.add("window", libconfig::Setting::TypeGroup);
-
- auto& window = settings["window"];
+ SettingsObj main_windows_state("main_windows_state");
- if (!window.exists("window_state"))
- window.add("window_state", libconfig::Setting::TypeString) =
- saveState().toBase64().toStdString();
-
- std::string window_state = settings.lookup("window.window_state");
+ std::string window_state = main_windows_state.Check(
+ "window_state", saveState().toBase64().toStdString());
// state sets pos & size of dock-widgets
this->restoreState(
QByteArray::fromBase64(QByteArray::fromStdString(window_state)));
- if (!window.exists("window_save"))
- window.add("window_save", libconfig::Setting::TypeBoolean) = true;
-
- bool window_save;
- window.lookupValue("window_save", window_save);
+ bool window_save = main_windows_state.Check("window_save", true);
// Restore window size & location
if (window_save) {
- if (!window.exists("window_pos"))
- window.add("window_pos", libconfig::Setting::TypeGroup);
-
- auto& window_pos = window["window_pos"];
-
- if (!window_pos.exists("x"))
- window_pos.add("x", libconfig::Setting::TypeInt) = 100;
-
- if (!window_pos.exists("y"))
- window_pos.add("y", libconfig::Setting::TypeInt) = 100;
-
- int x, y;
- window_pos.lookupValue("x", x);
- window_pos.lookupValue("y", y);
+ int x = main_windows_state.Check("window_pos").Check("x", 100),
+ y = main_windows_state.Check("window_pos").Check("y", 100);
auto pos = QPoint(x, y);
- if (!window.exists("window_size"))
- window.add("window_size", libconfig::Setting::TypeGroup);
-
- auto& window_size = window["window_size"];
-
- if (!window_size.exists("width"))
- window_size.add("width", libconfig::Setting::TypeInt) = 800;
-
- if (!window_size.exists("height"))
- window_size.add("height", libconfig::Setting::TypeInt) = 450;
-
- int width, height;
- window_size.lookupValue("width", width);
- window_size.lookupValue("height", height);
+ int width = main_windows_state.Check("window_size").Check("width", 800),
+ height = main_windows_state.Check("window_size").Check("height", 450);
auto size = QSize(width, height);
this->resize(size);
@@ -208,61 +172,36 @@ void MainWindow::restoreSettings() {
this->move(QPoint(100, 100));
}
- if (!window.exists("icon_size"))
- window.add("icon_size", libconfig::Setting::TypeGroup);
-
- auto& icon_size = window["icon_size"];
-
- if (!icon_size.exists("width"))
- icon_size.add("width", libconfig::Setting::TypeInt) = 24;
-
- if (!icon_size.exists("height"))
- icon_size.add("height", libconfig::Setting::TypeInt) = 24;
-
- int width = icon_size["width"], height = icon_size["height"];
+ int width = main_windows_state.Check("icon_size").Check("width", 24),
+ height = main_windows_state.Check("icon_size").Check("height", 24);
LOG(INFO) << "icon_size" << width << height;
- // info board font size
- if (!window.exists("info_font_size"))
- window.add("info_font_size", libconfig::Setting::TypeInt) = 10;
+ main_windows_state.Check("info_font_size", 10);
+
+ // icon_style
+ int s_icon_style =
+ main_windows_state.Check("icon_style", Qt::ToolButtonTextUnderIcon);
+ auto icon_style = static_cast<Qt::ToolButtonStyle>(s_icon_style);
+ this->setToolButtonStyle(icon_style);
+ importButton->setToolButtonStyle(icon_style);
// icons ize
this->setIconSize(QSize(width, height));
importButton->setIconSize(QSize(width, height));
- if (!settings.exists("keyserver") ||
- settings.lookup("keyserver").getType() != libconfig::Setting::TypeGroup)
- settings.add("keyserver", libconfig::Setting::TypeGroup);
-
- auto& keyserver = settings["keyserver"];
-
- if (!keyserver.exists("server_list")) {
- keyserver.add("server_list", libconfig::Setting::TypeList);
-
- auto& server_list = keyserver["server_list"];
- server_list.add(libconfig::Setting::TypeString) = "http://keys.gnupg.net";
- server_list.add(libconfig::Setting::TypeString) =
- "https://keyserver.ubuntu.com";
- server_list.add(libconfig::Setting::TypeString) =
- "http://pool.sks-keyservers.net";
- }
+ SettingsObj key_server_json("key_server");
- if (!keyserver.exists("default_server")) {
- keyserver.add("default_server", libconfig::Setting::TypeString) =
- "https://keyserver.ubuntu.com";
+ if (!key_server_json.contains("server_list")) {
+ key_server_json["server_list"] = {"https://keyserver.ubuntu.com",
+ "http://keys.gnupg.net",
+ "http://pool.sks-keyservers.net"};
}
- if (!window.exists("icon_style")) {
- window.add("icon_style", libconfig::Setting::TypeInt) =
- Qt::ToolButtonTextUnderIcon;
+ if (!key_server_json.contains("default_server")) {
+ key_server_json["default_server"] = 0;
}
- int s_icon_style = window.lookup("icon_style");
-
- // icon_style
- auto icon_style = static_cast<Qt::ToolButtonStyle>(s_icon_style);
- this->setToolButtonStyle(icon_style);
- importButton->setToolButtonStyle(icon_style);
+ auto& settings = GlobalSettingStation::GetInstance().GetUISettings();
if (!settings.exists("general") ||
settings.lookup("general").getType() != libconfig::Setting::TypeGroup)
@@ -282,28 +221,24 @@ void MainWindow::restoreSettings() {
bool save_key_checked = true;
general.lookupValue("save_key_checked", save_key_checked);
- // Checked Keys
- if (save_key_checked) {
- if (!general.exists("save_key_checked_key_ids")) {
- general.add("save_key_checked_key_ids", libconfig::Setting::TypeList);
- }
- auto key_ids_ptr = std::make_unique<KeyIdArgsList>();
- auto& save_key_checked_key_ids = general["save_key_checked_key_ids"];
- const auto key_ids_size =
- general.lookup("save_key_checked_key_ids").getLength();
- for (auto i = 0; i < key_ids_size; i++) {
- std::string key_id = save_key_checked_key_ids[i];
- LOG(INFO) << "get checked key id" << key_id;
- key_ids_ptr->push_back(key_id);
+ try {
+ // Checked Keys
+ SettingsObj default_key_checked("default_key_checked");
+ if (save_key_checked) {
+ auto key_ids_ptr = std::make_unique<KeyIdArgsList>();
+ for (auto& it : default_key_checked) {
+ std::string key_id = it;
+ LOG(INFO) << "get checked key id" << key_id;
+ key_ids_ptr->push_back(key_id);
+ }
+ mKeyList->setChecked(std::move(key_ids_ptr));
}
- mKeyList->setChecked(std::move(key_ids_ptr));
+ } catch (...) {
+ LOG(ERROR) << "restore default_key_checked failed";
}
- auto& smtp = settings["smtp"];
-
- if (!smtp.exists("enable")) {
- smtp.add("enable", libconfig::Setting::TypeBoolean) = true;
- }
+ SettingsObj smtp_passport("smtp_passport");
+ smtp_passport.Check("enable", false);
prohibit_update_checking_ = false;
try {
@@ -325,28 +260,27 @@ void MainWindow::saveSettings() {
auto& settings = GlobalSettingStation::GetInstance().GetUISettings();
try {
+ SettingsObj main_windows_state("main_windows_state");
+
// window position and size
- settings["window"]["window_state"] = saveState().toBase64().toStdString();
- settings["window"]["window_pos"]["x"] = pos().x();
- settings["window"]["window_pos"]["y"] = pos().y();
+ main_windows_state["window_state"] = saveState().toBase64().toStdString();
+ main_windows_state["window_pos"]["x"] = pos().x();
+ main_windows_state["window_pos"]["y"] = pos().y();
- settings["window"]["window_size"]["width"] = size().width();
- settings["window"]["window_size"]["height"] = size().height();
+ main_windows_state["window_size"]["width"] = size().width();
+ main_windows_state["window_size"]["height"] = size().height();
bool save_key_checked = settings.lookup("general.save_key_checked");
// keyid-list of private checked keys
if (save_key_checked) {
- auto& key_ids = settings.lookup("general.save_key_checked_key_ids");
- const int key_ids_size = key_ids.getLength();
- for (auto i = 0; i < key_ids_size; i++) key_ids.remove(i);
auto key_ids_need_to_store = mKeyList->getChecked();
- for (size_t i = 0; i < key_ids_need_to_store->size(); i++) {
- std::string key_id = (*key_ids_need_to_store)[i];
- key_ids.add(libconfig::Setting::TypeString) = key_id;
- }
-
+ SettingsObj default_key_checked("default_key_checked");
+ default_key_checked.clear();
+
+ for (const auto& key_id : *key_ids_need_to_store)
+ default_key_checked.push_back(key_id);
} else {
settings["general"].remove("save_key_checked");
}
diff --git a/src/ui/settings/SettingsSendMail.cpp b/src/ui/settings/SettingsSendMail.cpp
index 17b903f3..680cd07f 100644
--- a/src/ui/settings/SettingsSendMail.cpp
+++ b/src/ui/settings/SettingsSendMail.cpp
@@ -28,7 +28,7 @@
#include "smtp/SmtpMime"
#endif
-#include "ui/settings/GlobalSettingStation.h"
+#include "ui/data_struct/SettingsObj.h"
#include "ui/thread/SMTPSendMailThread.h"
#include "ui/thread/SMTPTestThread.h"
#include "ui_SendMailSettings.h"
@@ -97,95 +97,39 @@ SendMailTab::SendMailTab(QWidget* parent)
}
void SendMailTab::setSettings() {
- auto json_optional =
- GlobalSettingStation::GetInstance().GetDataObject("smtp_passport");
+ auto smtp_passport = SettingsObj("smtp_passport");
- if (!json_optional.has_value()) {
- LOG(WARNING) << "no smtp passport found";
- return;
- }
+ ui->smtpServerAddressEdit->setText(
+ std::string{smtp_passport.Check("smtp_address", {})}.c_str());
- auto& smtp_passport_json = json_optional.value();
+ ui->usernameEdit->setText(
+ std::string{smtp_passport.Check("username", {})}.c_str());
- try {
- std::string smtp_address = smtp_passport_json["smtp_address"];
- ui->smtpServerAddressEdit->setText(smtp_address.c_str());
- } catch (...) {
- LOG(ERROR) << _("Setting Operation Error") << _("smtp_address");
- }
+ ui->passwordEdit->setText(
+ std::string{smtp_passport.Check("password", {})}.c_str());
- try {
- std::string std_username = smtp_passport_json["username"];
- ui->usernameEdit->setText(std_username.c_str());
- } catch (...) {
- LOG(ERROR) << _("Setting Operation Error") << _("username");
- }
+ ui->portSpin->setValue(int{smtp_passport.Check("port", 25)});
- try {
- std::string std_password = smtp_passport_json["password"];
- ui->passwordEdit->setText(std_password.c_str());
- } catch (...) {
- LOG(ERROR) << _("Setting Operation Error") << _("password");
- }
-
- try {
- int port = smtp_passport_json["port"];
- ui->portSpin->setValue(port);
- } catch (...) {
- LOG(ERROR) << _("Setting Operation Error") << _("port");
- }
+ ui->connextionSecurityComboBox->setCurrentText(
+ std::string{smtp_passport.Check("connection_type", "None")}.c_str());
- ui->connextionSecurityComboBox->setCurrentText("None");
- try {
- std::string connection_type = smtp_passport_json["connection_type"];
- ui->connextionSecurityComboBox->setCurrentText(connection_type.c_str());
- } catch (...) {
- LOG(ERROR) << _("Setting Operation Error") << _("connection_type");
- }
+ ui->defaultSenderEmailEdit->setText(
+ std::string{smtp_passport.Check("default_sender", {})}.c_str());
- try {
- std::string default_sender = smtp_passport_json["default_sender"];
- ui->defaultSenderEmailEdit->setText(default_sender.c_str());
- } catch (...) {
- LOG(ERROR) << _("Setting Operation Error") << _("default_sender");
- }
+ ui->gpgKeyIDEdit->setText(
+ std::string{smtp_passport.Check("default_sender_gpg_key_id", {})}
+ .c_str());
- try {
- std::string default_sender_gpg_key_id =
- smtp_passport_json["default_sender_gpg_key_id"];
- ui->gpgKeyIDEdit->setText(default_sender_gpg_key_id.c_str());
- } catch (...) {
- LOG(ERROR) << _("Setting Operation Error")
- << _("default_sender_gpg_key_id");
- }
+ ui->identityCheckBox->setChecked(
+ bool{smtp_passport.Check("identity_enable", false)});
- ui->identityCheckBox->setCheckState(Qt::Unchecked);
- try {
- bool identity_enable = smtp_passport_json["identity_enable"];
- if (identity_enable)
- ui->identityCheckBox->setCheckState(Qt::Checked);
- else
- ui->identityCheckBox->setCheckState(Qt::Unchecked);
- } catch (...) {
- LOG(ERROR) << _("Setting Operation Error") << _("identity_enable");
- }
+ ui->enableCheckBox->setChecked(bool{smtp_passport.Check("enable", false)});
{
auto state = ui->identityCheckBox->checkState();
switch_ui_identity_enabled(state == Qt::Checked);
}
- ui->enableCheckBox->setCheckState(Qt::Unchecked);
- try {
- bool smtp_enable = smtp_passport_json["enable"];
- if (smtp_enable)
- ui->enableCheckBox->setCheckState(Qt::Checked);
- else
- ui->enableCheckBox->setCheckState(Qt::Unchecked);
- } catch (...) {
- LOG(ERROR) << _("Setting Operation Error") << _("enable");
- }
-
{
auto state = ui->enableCheckBox->checkState();
switch_ui_enabled(state == Qt::Checked);
@@ -193,31 +137,34 @@ void SendMailTab::setSettings() {
}
void SendMailTab::applySettings() {
- nlohmann::json smtp_passport_json;
- smtp_passport_json["smtp_address"] =
- ui->smtpServerAddressEdit->text().toStdString();
+ try {
+ auto smtp_passport = SettingsObj("smtp_passport");
+
+ smtp_passport["smtp_address"] =
+ ui->smtpServerAddressEdit->text().toStdString();
- smtp_passport_json["username"] = ui->usernameEdit->text().toStdString();
+ smtp_passport["username"] = ui->usernameEdit->text().toStdString();
- smtp_passport_json["password"] = ui->passwordEdit->text().toStdString();
+ smtp_passport["password"] = ui->passwordEdit->text().toStdString();
- smtp_passport_json["port"] = ui->portSpin->value();
+ smtp_passport["port"] = ui->portSpin->value();
- smtp_passport_json["connection_type"] =
- ui->connextionSecurityComboBox->currentText().toStdString();
+ smtp_passport["connection_type"] =
+ ui->connextionSecurityComboBox->currentText().toStdString();
- smtp_passport_json["default_sender"] =
- ui->defaultSenderEmailEdit->text().toStdString();
+ smtp_passport["default_sender"] =
+ ui->defaultSenderEmailEdit->text().toStdString();
- smtp_passport_json["default_sender_gpg_key_id"] =
- ui->gpgKeyIDEdit->text().toStdString();
+ smtp_passport["default_sender_gpg_key_id"] =
+ ui->gpgKeyIDEdit->text().toStdString();
- smtp_passport_json["identity_enable"] = ui->identityCheckBox->isChecked();
+ smtp_passport["identity_enable"] = ui->identityCheckBox->isChecked();
- smtp_passport_json["enable"] = ui->enableCheckBox->isChecked();
+ smtp_passport["enable"] = ui->enableCheckBox->isChecked();
- GpgFrontend::UI::GlobalSettingStation::GetInstance().SaveDataObj(
- "smtp_passport", smtp_passport_json);
+ } catch (...) {
+ LOG(ERROR) << _("apply settings failed");
+ }
}
#ifdef SMTP_SUPPORT