diff options
author | saturneric <[email protected]> | 2024-01-15 17:02:40 +0000 |
---|---|---|
committer | saturneric <[email protected]> | 2024-01-15 17:02:40 +0000 |
commit | d54f52ce70cba15f5199e93d3c6fb122143b0526 (patch) | |
tree | f75224f8d020c4c7498bd1ffb97c834e12ec8a2c /src/ui/dialog | |
parent | fix: clean up useless code and make life easier (diff) | |
download | GpgFrontend-d54f52ce70cba15f5199e93d3c6fb122143b0526.tar.gz GpgFrontend-d54f52ce70cba15f5199e93d3c6fb122143b0526.zip |
refactor: remove libconfig++ form project
Diffstat (limited to 'src/ui/dialog')
-rw-r--r-- | src/ui/dialog/Wizard.cpp | 19 | ||||
-rw-r--r-- | src/ui/dialog/gnupg/GnuPGControllerDialog.cpp | 121 | ||||
-rw-r--r-- | src/ui/dialog/import_export/KeyServerImportDialog.cpp | 8 | ||||
-rw-r--r-- | src/ui/dialog/key_generate/KeygenDialog.cpp | 6 | ||||
-rw-r--r-- | src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp | 6 | ||||
-rw-r--r-- | src/ui/dialog/keypair_details/KeyPairOperaTab.cpp | 14 | ||||
-rw-r--r-- | src/ui/dialog/keypair_details/KeySetExpireDateDialog.cpp | 13 | ||||
-rw-r--r-- | src/ui/dialog/settings/SettingsAdvanced.cpp | 99 | ||||
-rw-r--r-- | src/ui/dialog/settings/SettingsAdvanced.h | 52 | ||||
-rw-r--r-- | src/ui/dialog/settings/SettingsDialog.cpp | 3 | ||||
-rw-r--r-- | src/ui/dialog/settings/SettingsGeneral.cpp | 162 | ||||
-rw-r--r-- | src/ui/dialog/settings/SettingsNetwork.cpp | 204 |
12 files changed, 157 insertions, 550 deletions
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(); } |