Skip to content

Commit

Permalink
refactor: clean up code
Browse files Browse the repository at this point in the history
  • Loading branch information
saturneric committed Jan 27, 2025
1 parent af1870f commit 5d2b020
Show file tree
Hide file tree
Showing 24 changed files with 45 additions and 103 deletions.
4 changes: 2 additions & 2 deletions src/core/GpgCoreInit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ auto GetComponentPathsByGpgConf(const QString& gpgconf_install_fs_path)
}

auto DecideGpgConfPath(const QString& default_gpgconf_path) -> QString {
auto settings = GlobalSettingStation::GetInstance().GetSettings();
auto settings = GetSettings();
auto use_custom_gnupg_install_path =
settings.value("gnupg/use_custom_gnupg_install_path", false).toBool();
auto custom_gnupg_install_path =
Expand Down Expand Up @@ -470,7 +470,7 @@ auto InitGpgFrontendCore(CoreInitArgs args) -> int {
auto default_home_path = Module::RetrieveRTValueTypedOrDefault<>(
"core", "gpgme.ctx.default_database_path", QString{});

auto settings = GlobalSettingStation::GetInstance().GetSettings();
auto settings = GetSettings();

// read settings from config file
auto forbid_all_gnupg_connection =
Expand Down
5 changes: 1 addition & 4 deletions src/core/module/ModuleInit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,7 @@ auto LoadExternalMods() -> QMap<QString, bool> {
void LoadGpgFrontendModules(ModuleInitArgs) {
// give user ability to give up all modules
auto disable_loading_all_modules =
GlobalSettingStation::GetInstance()
.GetSettings()
.value("basic/disable_loading_all_modules", false)
.toBool();
GetSettings().value("basic/disable_loading_all_modules", false).toBool();
if (disable_loading_all_modules) return;

// must init at default thread before core
Expand Down
16 changes: 4 additions & 12 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,12 @@ int setenv(const char *name, const char *value, int overwrite) {
void InitGlobalPathEnv() {
// read settings
bool use_custom_gnupg_install_path =
GlobalSettingStation::GetInstance()
.GetSettings()
GetSettings()
.value("gnupg/use_custom_gnupg_install_path", false)
.toBool();

QString custom_gnupg_install_path =
GlobalSettingStation::GetInstance()
.GetSettings()
.value("gnupg/custom_gnupg_install_path")
.toString();
GetSettings().value("gnupg/custom_gnupg_install_path").toString();

// add custom gnupg install path into env $PATH
if (use_custom_gnupg_install_path && !custom_gnupg_install_path.isEmpty()) {
Expand All @@ -79,10 +75,7 @@ void InitGlobalPathEnv() {
QString modified_path_value = getenv("PATH");
}

if (GlobalSettingStation::GetInstance()
.GetSettings()
.value("gnupg/enable_gpgme_debug_log", false)
.toBool()) {
if (GetSettings().value("gnupg/enable_gpgme_debug_log", false).toBool()) {
qputenv("GPGME_DEBUG",
QString("9:%1").arg(QDir::currentPath() + "/gpgme.log").toUtf8());
}
Expand Down Expand Up @@ -142,8 +135,7 @@ void InitGlobalBasicEnv(const GFCxtWPtr &p_ctx, bool gui_mode) {
*/
void InitLocale() {
// get the instance of the GlobalSettingStation
auto settings =
GpgFrontend::GlobalSettingStation::GetInstance().GetSettings();
auto settings = GpgFrontend::GetSettings();

// read from settings file
auto lang = settings.value("basic/lang").toString();
Expand Down
2 changes: 1 addition & 1 deletion src/ui/GpgFrontendUIInit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ void InitGpgFrontendUI(QApplication* /*app*/) {
// init locale
InitUITranslations();

auto settings = GlobalSettingStation::GetInstance().GetSettings();
auto settings = GetSettings();
auto theme = settings.value("appearance/theme").toString();

#if defined(_WIN32) || defined(WIN32)
Expand Down
7 changes: 2 additions & 5 deletions src/ui/dialog/Wizard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,7 @@ Wizard::Wizard(QWidget* parent) : QWizard(parent) {
setPixmap(QWizard::LogoPixmap,
QPixmap(":/icons/gpgfrontend_logo.png").scaled(64, 64));

int next_page_id = GlobalSettingStation::GetInstance()
.GetSettings()
.value("wizard.next_page", -1)
.toInt();
int next_page_id = GetSettings().value("wizard.next_page", -1).toInt();
setStartId(next_page_id);

connect(this, &Wizard::accepted, this, &Wizard::slot_wizard_accepted);
Expand All @@ -57,7 +54,7 @@ Wizard::Wizard(QWidget* parent) : QWizard(parent) {
void Wizard::slot_wizard_accepted() {
// Don't show is mapped to show -> negation
try {
auto settings = GlobalSettingStation::GetInstance().GetSettings();
auto settings = GetSettings();
settings.setValue("wizard/show_wizard", false);
} catch (...) {
FLOG_W("setting operation error");
Expand Down
10 changes: 3 additions & 7 deletions src/ui/dialog/controller/GnuPGControllerDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,7 @@ void GnuPGControllerDialog::slot_update_custom_gnupg_install_path_label(
if (custom_gnupg_path_.isEmpty()) {
// read from settings file
QString custom_gnupg_install_path =
GlobalSettingStation::GetInstance()
.GetSettings()
.value("gnupg/custom_gnupg_install_path")
.toString();
GetSettings().value("gnupg/custom_gnupg_install_path").toString();
custom_gnupg_path_ = custom_gnupg_install_path;
}

Expand All @@ -232,7 +229,7 @@ void GnuPGControllerDialog::slot_update_custom_gnupg_install_path_label(
}

void GnuPGControllerDialog::set_settings() {
auto settings = GlobalSettingStation::GetInstance().GetSettings();
auto settings = GetSettings();

auto non_ascii_at_file_operation =
settings.value("gnupg/non_ascii_at_file_operation", true).toBool();
Expand Down Expand Up @@ -285,8 +282,7 @@ void GnuPGControllerDialog::set_settings() {
}

void GnuPGControllerDialog::apply_settings() {
auto settings =
GpgFrontend::GlobalSettingStation::GetInstance().GetSettings();
auto settings = GpgFrontend::GetSettings();

settings.setValue("gnupg/non_ascii_at_file_operation",
ui_->asciiModeCheckBox->isChecked());
Expand Down
5 changes: 1 addition & 4 deletions src/ui/dialog/controller/ModuleControllerDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,7 @@ ModuleControllerDialog::ModuleControllerDialog(QWidget* parent)

// give user ability to give up all modules
auto disable_loading_all_modules =
GlobalSettingStation::GetInstance()
.GetSettings()
.value("basic/disable_loading_all_modules", false)
.toBool();
GetSettings().value("basic/disable_loading_all_modules", false).toBool();
if (disable_loading_all_modules) {
ui_->tabWidget->setTabEnabled(0, false);
}
Expand Down
3 changes: 1 addition & 2 deletions src/ui/dialog/import_export/KeyServerImportDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ KeyServerImportDialog::KeyServerImportDialog(int channel, QWidget* parent)
: GeneralDialog("key_server_import_dialog", parent),
current_gpg_context_channel_(channel) {
auto forbid_all_gnupg_connection =
GlobalSettingStation::GetInstance()
.GetSettings()
GetSettings()
.value("network/forbid_all_gnupg_connection", false)
.toBool();
if (forbid_all_gnupg_connection) {
Expand Down
8 changes: 2 additions & 6 deletions src/ui/dialog/key_generate/KeygenDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,7 @@ KeyGenDialog::KeyGenDialog(int channel, QWidget* parent)
new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);

bool const longer_expiration_date =
GlobalSettingStation::GetInstance()
.GetSettings()
.value("basic/longer_expiration_date", false)
.toBool();
GetSettings().value("basic/longer_expiration_date", false).toBool();

max_date_time_ = longer_expiration_date
? QDateTime::currentDateTime().toLocalTime().addYears(30)
Expand Down Expand Up @@ -141,8 +138,7 @@ void KeyGenDialog::slot_key_gen_accept() {
}
}

if (!GlobalSettingStation::GetInstance()
.GetSettings()
if (!GetSettings()
.value("gnupg/use_pinentry_as_password_input_dialog",
QString::fromLocal8Bit(qgetenv("container")) != "flatpak")
.toBool() &&
Expand Down
5 changes: 1 addition & 4 deletions src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,7 @@ SubkeyGenerateDialog::SubkeyGenerateDialog(int channel, const KeyId& key_id,
assert(key_.IsGood());

bool longer_expiration_date =
GlobalSettingStation::GetInstance()
.GetSettings()
.value("basic/longer_expiration_date", false)
.toBool();
GetSettings().value("basic/longer_expiration_date", false).toBool();

max_date_time_ = longer_expiration_date
? QDateTime::currentDateTime().toLocalTime().addYears(30)
Expand Down
10 changes: 2 additions & 8 deletions src/ui/dialog/keypair_details/KeyPairDetailTab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,16 +306,10 @@ void KeyPairDetailTab::slot_refresh_key() {

void KeyPairDetailTab::slot_query_key_publish_state() {
bool forbid_all_gnupg_connection =
GlobalSettingStation::GetInstance()
.GetSettings()
.value("network/forbid_all_gnupg_connection")
.toBool();
GetSettings().value("network/forbid_all_gnupg_connection").toBool();

bool auto_fetch_key_publish_status =
GlobalSettingStation::GetInstance()
.GetSettings()
.value("network/auto_fetch_key_publish_status")
.toBool();
GetSettings().value("network/auto_fetch_key_publish_status").toBool();

if (forbid_all_gnupg_connection || !auto_fetch_key_publish_status) return;

Expand Down
2 changes: 1 addition & 1 deletion src/ui/dialog/keypair_details/KeyPairOperaTab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ KeyPairOperaTab::KeyPairOperaTab(int channel, const QString& key_id,

auto* advance_h_box_layout = new QHBoxLayout();

auto settings = GlobalSettingStation::GetInstance().GetSettings();
auto settings = GetSettings();

// read settings
bool forbid_all_gnupg_connection =
Expand Down
3 changes: 1 addition & 2 deletions src/ui/dialog/keypair_details/KeySetExpireDateDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ void KeySetExpireDateDialog::slot_confirm() {
void KeySetExpireDateDialog::init() {
ui_->setupUi(this);

auto settings =
GpgFrontend::GlobalSettingStation::GetInstance().GetSettings();
auto settings = GpgFrontend::GetSettings();

bool longer_expiration_date =
settings.value("basic/longer_expiration_date").toBool();
Expand Down
4 changes: 2 additions & 2 deletions src/ui/dialog/settings/SettingsAppearance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ void AppearanceTab::SetSettings() {
ui_->themeComboBox->addItem(s.toLower());
}

auto settings = GlobalSettingStation::GetInstance().GetSettings();
auto settings = GetSettings();
auto theme = settings.value("appearance/theme").toString();

auto target_theme_index = ui_->themeComboBox->findText(theme);
Expand Down Expand Up @@ -224,7 +224,7 @@ void AppearanceTab::ApplySettings() {

general_settings_state.Store(appearance.ToJson());

auto settings = GlobalSettingStation::GetInstance().GetSettings();
auto settings = GetSettings();
settings.setValue("appearance/theme", ui_->themeComboBox->currentText());
}

Expand Down
5 changes: 2 additions & 3 deletions src/ui/dialog/settings/SettingsGeneral.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ GeneralTab::GeneralTab(QWidget* parent)
}

void GeneralTab::SetSettings() {
auto settings = GlobalSettingStation::GetInstance().GetSettings();
auto settings = GetSettings();

auto clear_gpg_password_cache =
settings.value("basic/clear_gpg_password_cache", true).toBool();
Expand Down Expand Up @@ -147,8 +147,7 @@ void GeneralTab::SetSettings() {
}

void GeneralTab::ApplySettings() {
auto settings =
GpgFrontend::GlobalSettingStation::GetInstance().GetSettings();
auto settings = GpgFrontend::GetSettings();

settings.setValue("basic/longer_expiration_date",
ui_->longerKeyExpirationDateCheckBox->isChecked());
Expand Down
5 changes: 2 additions & 3 deletions src/ui/dialog/settings/SettingsNetwork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ GpgFrontend::UI::NetworkTab::NetworkTab(QWidget *parent)
}

void GpgFrontend::UI::NetworkTab::SetSettings() {
auto settings = GlobalSettingStation::GetInstance().GetSettings();
auto settings = GetSettings();

auto proxy_host = settings.value("proxy/proxy_host").toString();
ui_->proxyServerAddressEdit->setText(proxy_host);
Expand Down Expand Up @@ -146,8 +146,7 @@ void GpgFrontend::UI::NetworkTab::SetSettings() {
}

void GpgFrontend::UI::NetworkTab::ApplySettings() {
auto settings =
GpgFrontend::GlobalSettingStation::GetInstance().GetSettings();
auto settings = GpgFrontend::GetSettings();

settings.setValue("proxy/proxy_host", ui_->proxyServerAddressEdit->text());
settings.setValue("proxy/username", ui_->usernameEdit->text());
Expand Down
3 changes: 1 addition & 2 deletions src/ui/main_window/KeyMgmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,7 @@ void KeyMgmt::create_actions() {
});

bool const forbid_all_gnupg_connection =
GlobalSettingStation::GetInstance()
.GetSettings()
GetSettings()
.value("network/forbid_all_gnupg_connection", false)
.toBool();

Expand Down
4 changes: 2 additions & 2 deletions src/ui/main_window/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ void MainWindow::Init() noexcept {
Module::TriggerEvent("APPLICATION_LOADED");

// check version information
auto settings = GlobalSettingStation::GetInstance().GetSettings();
auto settings = GetSettings();
auto prohibit_update_checking =
settings.value("network/prohibit_update_checking").toBool();
if (!prohibit_update_checking) {
Expand Down Expand Up @@ -175,7 +175,7 @@ void MainWindow::restore_settings() {
if (key_server.server_list.empty()) key_server.ResetDefaultServerList();
if (key_server.default_server < 0) key_server.default_server = 0;

auto settings = GlobalSettingStation::GetInstance().GetSettings();
auto settings = GetSettings();
if (!settings.contains("gnupg/non_ascii_at_file_operation")) {
settings.setValue("gnupg/non_ascii_at_file_operation", true);
}
Expand Down
15 changes: 3 additions & 12 deletions src/ui/main_window/MainWindowFileSlotFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,10 +307,7 @@ void MainWindow::SlotFileEncrypt(const QStringList& paths) {
auto contexts = QSharedPointer<GpgOperaContexts>::create();

bool const non_ascii_at_file_operation =
GlobalSettingStation::GetInstance()
.GetSettings()
.value("gnupg/non_ascii_at_file_operation", true)
.toBool();
GetSettings().value("gnupg/non_ascii_at_file_operation", true).toBool();

contexts->ascii = !non_ascii_at_file_operation;

Expand Down Expand Up @@ -534,10 +531,7 @@ void MainWindow::SlotFileSign(const QStringList& paths) {
auto contexts = QSharedPointer<GpgOperaContexts>::create();

bool const non_ascii_at_file_operation =
GlobalSettingStation::GetInstance()
.GetSettings()
.value("gnupg/non_ascii_at_file_operation", true)
.toBool();
GetSettings().value("gnupg/non_ascii_at_file_operation", true).toBool();

contexts->ascii = !non_ascii_at_file_operation;

Expand Down Expand Up @@ -768,10 +762,7 @@ void MainWindow::SlotFileEncryptSign(const QStringList& paths) {
auto contexts = QSharedPointer<GpgOperaContexts>::create();

bool const non_ascii_at_file_operation =
GlobalSettingStation::GetInstance()
.GetSettings()
.value("gnupg/non_ascii_at_file_operation", true)
.toBool();
GetSettings().value("gnupg/non_ascii_at_file_operation", true).toBool();

contexts->ascii = !non_ascii_at_file_operation;

Expand Down
3 changes: 1 addition & 2 deletions src/ui/main_window/MainWindowUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,7 @@ void MainWindow::create_actions() {
});

bool forbid_all_gnupg_connection =
GlobalSettingStation::GetInstance()
.GetSettings()
GetSettings()
.value("network/forbid_all_gnupg_connection", false)
.toBool();

Expand Down
5 changes: 1 addition & 4 deletions src/ui/widgets/HelpPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,7 @@ auto HelpPage::localized_help(const QUrl& url) -> QUrl {
QStringList fileparts = filename.split(".");

// QSettings settings;
QString lang = GlobalSettingStation::GetInstance()
.GetSettings()
.value("int/lang", QLocale().name())
.toString();
QString lang = GetSettings().value("int/lang", QLocale().name()).toString();
if (lang.isEmpty()) {
lang = QLocale().name();
}
Expand Down
Loading

0 comments on commit 5d2b020

Please sign in to comment.