aboutsummaryrefslogtreecommitdiffstats
path: root/src/ui/dialog/settings
diff options
context:
space:
mode:
authorSaturn&Eric <[email protected]>2023-03-31 21:27:08 +0000
committerGitHub <[email protected]>2023-03-31 21:27:08 +0000
commit3cb863592a548edc074dde045493e0f83e5d694a (patch)
tree242534c257e723f49080428db22118c75706e233 /src/ui/dialog/settings
parentMerge pull request #91 from saturneric/dev/2.0.10/main (diff)
parentfeat: add project security document (diff)
downloadGpgFrontend-2.1.0.tar.gz
GpgFrontend-2.1.0.zip
Merge pull request #93 from saturneric/dev/2.0.10/mainv2.1.0
Develop 2.1.0.2
Diffstat (limited to 'src/ui/dialog/settings')
-rw-r--r--src/ui/dialog/settings/SettingsGeneral.cpp29
-rw-r--r--src/ui/dialog/settings/SettingsKeyServer.cpp5
-rw-r--r--src/ui/dialog/settings/SettingsNetwork.cpp133
3 files changed, 123 insertions, 44 deletions
diff --git a/src/ui/dialog/settings/SettingsGeneral.cpp b/src/ui/dialog/settings/SettingsGeneral.cpp
index 7e48b4e1..17d9251c 100644
--- a/src/ui/dialog/settings/SettingsGeneral.cpp
+++ b/src/ui/dialog/settings/SettingsGeneral.cpp
@@ -47,7 +47,7 @@ GeneralTab::GeneralTab(QWidget* parent)
ui_->saveCheckedKeysCheckBox->setText(
_("Save checked private keys on exit and restore them on next start."));
ui_->clearGpgPasswordCacheCheckBox->setText(
- "Clear gpg password cache when closing GpgFrontend.");
+ _("Clear gpg password cache when closing GpgFrontend."));
ui_->importConfirmationBox->setTitle(_("Operation"));
ui_->longerKeyExpirationDateCheckBox->setText(
@@ -57,6 +57,8 @@ GeneralTab::GeneralTab(QWidget* parent)
ui_->gnupgDatabaseBox->setTitle(_("GnuPG"));
ui_->asciiModeCheckBox->setText(_("No ASCII Mode"));
+ ui_->usePinentryAsPasswordInputDialogCheckBox->setText(
+ _("Use Pinentry as Password Input Dialog"));
ui_->useCustomGnuPGInstallPathCheckBox->setText(_("Use Custom GnuPG"));
ui_->useCustomGnuPGInstallPathButton->setText(_("Select GnuPG Path"));
ui_->keyDatabseUseCustomCheckBox->setText(
@@ -167,6 +169,12 @@ GeneralTab::GeneralTab(QWidget* parent)
}
});
+ connect(ui_->usePinentryAsPasswordInputDialogCheckBox,
+ &QCheckBox::stateChanged, this, [=](int state) {
+ // announce the restart
+ this->slot_gnupg_stettings_changed();
+ });
+
SetSettings();
}
@@ -260,6 +268,16 @@ void GeneralTab::SetSettings() {
SPDLOG_ERROR("setting operation error: use_custom_gnupg_install_path");
}
+ try {
+ bool use_pinentry_as_password_input_dialog =
+ settings.lookup("general.use_pinentry_as_password_input_dialog");
+ if (use_pinentry_as_password_input_dialog)
+ ui_->usePinentryAsPasswordInputDialogCheckBox->setCheckState(Qt::Checked);
+ } catch (...) {
+ SPDLOG_ERROR(
+ "setting operation error: use_pinentry_as_password_input_dialog");
+ }
+
this->slot_update_custom_gnupg_install_path_label(
ui_->useCustomGnuPGInstallPathCheckBox->checkState());
}
@@ -343,6 +361,15 @@ void GeneralTab::ApplySettings() {
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();
+ }
}
#ifdef MULTI_LANG_SUPPORT
diff --git a/src/ui/dialog/settings/SettingsKeyServer.cpp b/src/ui/dialog/settings/SettingsKeyServer.cpp
index 8719ab9a..83bd2c80 100644
--- a/src/ui/dialog/settings/SettingsKeyServer.cpp
+++ b/src/ui/dialog/settings/SettingsKeyServer.cpp
@@ -284,6 +284,11 @@ void KeyserverTab::slot_test_listed_key_server() {
Thread::TaskRunnerGetter::GetInstance()
.GetTaskRunner(Thread::TaskRunnerGetter::kTaskRunnerType_Network)
->PostTask(task);
+
+ QEventLoop loop;
+ connect(task, &Thread::Task::SignalTaskEnd, &loop, &QEventLoop::quit);
+ connect(waiting_dialog, &QProgressDialog::canceled, &loop, &QEventLoop::quit);
+ loop.exec();
}
void KeyserverTab::contextMenuEvent(QContextMenuEvent* event) {
diff --git a/src/ui/dialog/settings/SettingsNetwork.cpp b/src/ui/dialog/settings/SettingsNetwork.cpp
index fe3d450e..0713856d 100644
--- a/src/ui/dialog/settings/SettingsNetwork.cpp
+++ b/src/ui/dialog/settings/SettingsNetwork.cpp
@@ -29,7 +29,7 @@
#include "SettingsNetwork.h"
#include "core/function/GlobalSettingStation.h"
-#include "ui/thread/ProxyConnectionTestThread.h"
+#include "ui/thread/ProxyConnectionTestTask.h"
#include "ui_NetworkSettings.h"
GpgFrontend::UI::NetworkTab::NetworkTab(QWidget *parent)
@@ -37,7 +37,28 @@ GpgFrontend::UI::NetworkTab::NetworkTab(QWidget *parent)
ui_->setupUi(this);
connect(ui_->enableProxyCheckBox, &QCheckBox::stateChanged, this,
- [=](int state) { switch_ui_enabled(state == Qt::Checked); });
+ [=](int state) {
+ switch_ui_enabled(state == Qt::Checked);
+ // when selecting no proxy option, apply it immediately
+ if (state != Qt::Checked) apply_proxy_settings();
+ });
+
+ connect(
+ ui_->autoImportMissingKeyCheckBox, &QCheckBox::stateChanged, this,
+ [=](int state) {
+ ui_->forbidALLGnuPGNetworkConnectionCheckBox->setCheckState(
+ state == Qt::Checked
+ ? Qt::Unchecked
+ : ui_->forbidALLGnuPGNetworkConnectionCheckBox->checkState());
+ });
+
+ connect(ui_->forbidALLGnuPGNetworkConnectionCheckBox,
+ &QCheckBox::stateChanged, this, [=](int state) {
+ ui_->autoImportMissingKeyCheckBox->setCheckState(
+ state == Qt::Checked
+ ? Qt::Unchecked
+ : ui_->autoImportMissingKeyCheckBox->checkState());
+ });
connect(
ui_->proxyTypeComboBox, &QComboBox::currentTextChanged, this,
@@ -47,7 +68,7 @@ GpgFrontend::UI::NetworkTab::NetworkTab(QWidget *parent)
&NetworkTab::slot_test_proxy_connection_result);
ui_->proxyGroupBox->setTitle(_("Proxy"));
- ui_->capabilityGroupBox->setTitle(_("Network Capability"));
+ ui_->capabilityGroupBox->setTitle(_("Network Ability"));
ui_->operationsGroupBox->setTitle(_("Operations"));
ui_->enableProxyCheckBox->setText(_("Enable Proxy"));
@@ -59,12 +80,18 @@ GpgFrontend::UI::NetworkTab::NetworkTab(QWidget *parent)
ui_->usernameLabel->setText(_("Username"));
ui_->passwordLabel->setText(_("Password"));
- ui_->forbidALLCheckBox->setText(_("Forbid all network connection."));
- ui_->forbidALLCheckBox->setDisabled(true);
+ ui_->checkProxyConnectionButton->setText(
+ _("Apply Proxy Settings and Check Proxy Connection"));
+ ui_->forbidALLGnuPGNetworkConnectionCheckBox->setText(
+ _("Forbid all GnuPG network connection."));
ui_->prohibitUpdateCheck->setText(
_("Prohibit checking for version updates when the program starts."));
- ui_->checkProxyConnectionButton->setText(_("Check Proxy Connection"));
+ ui_->autoImportMissingKeyCheckBox->setText(
+ _("Automatically import a missing key for signature verification."));
+ ui_->networkAbilityTipsLabel->setText(
+ _("Tips: These Option Changes take effect only after the "
+ "application restart."));
SetSettings();
}
@@ -120,21 +147,17 @@ void GpgFrontend::UI::NetworkTab::SetSettings() {
SPDLOG_ERROR("setting operation error: proxy_enable");
}
- {
- auto state = ui_->enableProxyCheckBox->checkState();
- switch_ui_enabled(state == Qt::Checked);
- }
-
- ui_->forbidALLCheckBox->setCheckState(Qt::Unchecked);
+ ui_->forbidALLGnuPGNetworkConnectionCheckBox->setCheckState(Qt::Unchecked);
try {
- bool forbid_all_connection =
- settings.lookup("network.forbid_all_connection");
- if (forbid_all_connection)
- ui_->forbidALLCheckBox->setCheckState(Qt::Checked);
+ bool forbid_all_gnupg_connection =
+ settings.lookup("network.forbid_all_gnupg_connection");
+ if (forbid_all_gnupg_connection)
+ ui_->forbidALLGnuPGNetworkConnectionCheckBox->setCheckState(Qt::Checked);
else
- ui_->forbidALLCheckBox->setCheckState(Qt::Unchecked);
+ ui_->forbidALLGnuPGNetworkConnectionCheckBox->setCheckState(
+ Qt::Unchecked);
} catch (...) {
- SPDLOG_ERROR("setting operation error: forbid_all_connection");
+ SPDLOG_ERROR("setting operation error: forbid_all_gnupg_connection");
}
ui_->prohibitUpdateCheck->setCheckState(Qt::Unchecked);
@@ -148,6 +171,21 @@ void GpgFrontend::UI::NetworkTab::SetSettings() {
} catch (...) {
SPDLOG_ERROR("setting operation error: prohibit_update_checking");
}
+
+ 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 (...) {
+ SPDLOG_ERROR("setting operation error: auto_import_missing_key");
+ }
+
+ switch_ui_enabled(ui_->enableProxyCheckBox->isChecked());
+ switch_ui_proxy_type(ui_->proxyTypeComboBox->currentText());
}
void GpgFrontend::UI::NetworkTab::ApplySettings() {
@@ -207,11 +245,13 @@ void GpgFrontend::UI::NetworkTab::ApplySettings() {
auto &network = settings["network"];
- if (!network.exists("forbid_all_connection"))
- network.add("forbid_all_connection", libconfig::Setting::TypeBoolean) =
- ui_->forbidALLCheckBox->isChecked();
+ if (!network.exists("forbid_all_gnupg_connection"))
+ network.add("forbid_all_gnupg_connection",
+ libconfig::Setting::TypeBoolean) =
+ ui_->forbidALLGnuPGNetworkConnectionCheckBox->isChecked();
else {
- network["forbid_all_connection"] = ui_->forbidALLCheckBox->isChecked();
+ network["forbid_all_gnupg_connection"] =
+ ui_->forbidALLGnuPGNetworkConnectionCheckBox->isChecked();
}
if (!network.exists("prohibit_update_checking"))
@@ -221,6 +261,14 @@ void GpgFrontend::UI::NetworkTab::ApplySettings() {
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();
+ }
+
apply_proxy_settings();
}
@@ -232,9 +280,9 @@ void GpgFrontend::UI::NetworkTab::slot_test_proxy_connection_result() {
tr("Server Url"), QLineEdit::Normal,
"https://", &ok);
if (ok && !url.isEmpty()) {
- auto thread = new ProxyConnectionTestThread(url, 800, this);
- connect(thread,
- &GpgFrontend::UI::ProxyConnectionTestThread::
+ auto task = new ProxyConnectionTestTask(url, 800);
+ connect(task,
+ &GpgFrontend::UI::ProxyConnectionTestTask::
SignalProxyConnectionTestResult,
this, [=](const QString &result) {
if (result == "Reachable") {
@@ -248,7 +296,6 @@ void GpgFrontend::UI::NetworkTab::slot_test_proxy_connection_result() {
"proxy server. Proxy settings may be invalid."));
}
});
- connect(thread, &QThread::finished, thread, &QThread::deleteLater);
// Waiting Dialog
auto *waiting_dialog = new QProgressDialog(this);
@@ -261,43 +308,43 @@ void GpgFrontend::UI::NetworkTab::slot_test_proxy_connection_result() {
waiting_dialog_label->setWordWrap(true);
waiting_dialog->setLabel(waiting_dialog_label);
waiting_dialog->resize(420, 120);
- connect(thread, &QThread::finished, [=]() {
- waiting_dialog->finished(0);
+ connect(task, &Thread::Task::SignalTaskEnd, [=]() {
+ waiting_dialog->close();
waiting_dialog->deleteLater();
});
- connect(waiting_dialog, &QProgressDialog::canceled, [=]() {
- SPDLOG_DEBUG("cancel clicked");
- if (thread->isRunning()) thread->terminate();
- });
// Show Waiting Dialog
waiting_dialog->show();
waiting_dialog->setFocus();
- thread->start();
+ Thread::TaskRunnerGetter::GetInstance()
+ .GetTaskRunner(Thread::TaskRunnerGetter::kTaskRunnerType_Network)
+ ->PostTask(task);
+
QEventLoop loop;
- connect(thread, &QThread::finished, &loop, &QEventLoop::quit);
+ connect(task, &Thread::Task::SignalTaskEnd, &loop, &QEventLoop::quit);
+ connect(waiting_dialog, &QProgressDialog::canceled, &loop,
+ &QEventLoop::quit);
loop.exec();
}
}
void GpgFrontend::UI::NetworkTab::apply_proxy_settings() {
// apply settings
- QNetworkProxy _proxy;
+ QNetworkProxy proxy;
if (ui_->enableProxyCheckBox->isChecked() &&
proxy_type_ != QNetworkProxy::DefaultProxy) {
- _proxy.setType(proxy_type_);
- _proxy.setHostName(ui_->proxyServerAddressEdit->text());
- _proxy.setPort(ui_->portSpin->value());
+ proxy.setType(proxy_type_);
+ proxy.setHostName(ui_->proxyServerAddressEdit->text());
+ proxy.setPort(ui_->portSpin->value());
if (!ui_->usernameEdit->text().isEmpty()) {
- _proxy.setUser(ui_->usernameEdit->text());
- _proxy.setPassword(ui_->passwordEdit->text());
+ proxy.setUser(ui_->usernameEdit->text());
+ proxy.setPassword(ui_->passwordEdit->text());
}
} else {
- _proxy.setType(proxy_type_);
+ proxy.setType(proxy_type_);
}
-
- QNetworkProxy::setApplicationProxy(_proxy);
+ QNetworkProxy::setApplicationProxy(proxy);
}
void GpgFrontend::UI::NetworkTab::switch_ui_enabled(bool enabled) {