aboutsummaryrefslogtreecommitdiffstats
path: root/src/ui/dialog/settings/SettingsGeneral.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/dialog/settings/SettingsGeneral.cpp')
-rw-r--r--src/ui/dialog/settings/SettingsGeneral.cpp110
1 files changed, 110 insertions, 0 deletions
diff --git a/src/ui/dialog/settings/SettingsGeneral.cpp b/src/ui/dialog/settings/SettingsGeneral.cpp
index 3c7bca32..680ed014 100644
--- a/src/ui/dialog/settings/SettingsGeneral.cpp
+++ b/src/ui/dialog/settings/SettingsGeneral.cpp
@@ -28,6 +28,8 @@
#include "SettingsGeneral.h"
+#include "core/GpgContext.h"
+
#ifdef MULTI_LANG_SUPPORT
#include "SettingsDialog.h"
#endif
@@ -70,6 +72,51 @@ GeneralTab::GeneralTab(QWidget* parent)
this, &GeneralTab::slot_language_changed);
#endif
+ connect(ui_->keyDatabseUseCustomCheckBox, &QCheckBox::stateChanged, this,
+ [=](int state) {
+ ui_->customKeyDatabasePathSelectButton->setDisabled(
+ state != Qt::CheckState::Checked);
+ // announce the restart
+ this->slot_key_databse_path_changed();
+ });
+
+ connect(ui_->keyDatabseUseCustomCheckBox, &QCheckBox::stateChanged, this,
+ &GeneralTab::slot_update_custom_key_database_path_label);
+
+ connect(
+ ui_->customKeyDatabasePathSelectButton, &QPushButton::clicked, this,
+ [=]() {
+ QString selected_custom_key_database_path =
+ QFileDialog::getExistingDirectory(
+ this, _("Open Directory"), {},
+ QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
+
+ LOG(INFO) << "key databse path selected"
+ << selected_custom_key_database_path.toStdString();
+
+ if (!selected_custom_key_database_path.isEmpty()) {
+ auto& settings = GlobalSettingStation::GetInstance().GetUISettings();
+ auto& general = settings["general"];
+
+ // 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();
+ }
+
+ // announce the restart
+ this->slot_key_databse_path_changed();
+
+ // update ui
+ this->slot_update_custom_key_database_path_label(
+ this->ui_->keyDatabseUseCustomCheckBox->checkState());
+ }
+ });
+
SetSettings();
}
@@ -132,6 +179,19 @@ void GeneralTab::SetSettings() {
} catch (...) {
LOG(ERROR) << _("Setting Operation Error") << _("non_ascii_when_export");
}
+
+ try {
+ bool use_custom_key_database_path =
+ settings.lookup("general.use_custom_key_database_path");
+ if (use_custom_key_database_path)
+ ui_->keyDatabseUseCustomCheckBox->setCheckState(Qt::Checked);
+ } catch (...) {
+ LOG(ERROR) << _("Setting Operation Error")
+ << _("use_custom_key_database_path");
+ }
+
+ this->slot_update_custom_key_database_path_label(
+ ui_->keyDatabseUseCustomCheckBox->checkState());
}
/***********************************
@@ -187,10 +247,60 @@ void GeneralTab::ApplySettings() {
general["confirm_import_keys"] =
ui_->importConfirmationCheckBox->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();
+ }
}
#ifdef MULTI_LANG_SUPPORT
void GeneralTab::slot_language_changed() { emit SignalRestartNeeded(true); }
#endif
+void GeneralTab::slot_update_custom_key_database_path_label(int state) {
+ if (state != Qt::CheckState::Checked) {
+ ui_->currentKeyDatabasePathLabel->setText(QString::fromStdString(
+ GpgContext::GetInstance().GetInfo().DatabasePath));
+
+ // hide label (not necessary to show the default path)
+ this->ui_->currentKeyDatabasePathLabel->setHidden(true);
+ } else {
+ // read from settings file
+ std::string custom_key_database_path;
+ try {
+ auto& settings =
+ GpgFrontend::GlobalSettingStation::GetInstance().GetUISettings();
+ custom_key_database_path = static_cast<std::string>(
+ settings.lookup("general.custom_key_database_path"));
+
+ } catch (...) {
+ LOG(ERROR) << _("Setting Operation Error")
+ << _("custom_key_database_path");
+ }
+
+ LOG(INFO) << "selected_custom_key_database_path from settings"
+ << custom_key_database_path;
+
+ // set label value
+ if (!custom_key_database_path.empty()) {
+ ui_->currentKeyDatabasePathLabel->setText(
+ QString::fromStdString(custom_key_database_path));
+ } else {
+ ui_->currentKeyDatabasePathLabel->setText(
+ _("None custom key database path."));
+ }
+
+ this->ui_->currentKeyDatabasePathLabel->setHidden(false);
+ }
+}
+
+void GeneralTab::slot_key_databse_path_changed() {
+ emit SignalDeepRestartNeeded(true);
+}
+
} // namespace GpgFrontend::UI