aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/core/GpgCoreInit.cpp4
-rw-r--r--src/init.cpp39
-rw-r--r--src/main.cpp20
-rw-r--r--src/ui/dialog/settings/SettingsGeneral.cpp130
-rw-r--r--src/ui/dialog/settings/SettingsGeneral.h8
-rw-r--r--ui/GeneralSettings.ui134
6 files changed, 243 insertions, 92 deletions
diff --git a/src/core/GpgCoreInit.cpp b/src/core/GpgCoreInit.cpp
index ad4e395d..cdda3a67 100644
--- a/src/core/GpgCoreInit.cpp
+++ b/src/core/GpgCoreInit.cpp
@@ -35,6 +35,7 @@
#include "GpgFunctionObject.h"
#include "core/GpgContext.h"
#include "core/function/GlobalSettingStation.h"
+#include "function/gpg/GpgAdvancedOperator.h"
namespace GpgFrontend {
@@ -138,6 +139,9 @@ void init_gpgfrontend_core() {
return std::unique_ptr<ChannelObject>(new GpgContext(args));
});
+
+ // try to restart all components
+ GpgFrontend::GpgAdvancedOperator::GetInstance().RestartGpgComponents();
}
void reset_gpgfrontend_core() { SingletonStorageCollection::GetInstance(true); }
diff --git a/src/init.cpp b/src/init.cpp
index 8793b3b2..6aa2084e 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -31,6 +31,8 @@
#include <spdlog/sinks/rotating_file_sink.h>
#include <spdlog/sinks/stdout_color_sinks.h>
+#include <filesystem>
+
#include "GpgFrontend.h"
#include "GpgFrontendBuildInfo.h"
#include "core/function/GlobalSettingStation.h"
@@ -65,3 +67,40 @@ void init_logging_system() {
// register it as default logger
spdlog::set_default_logger(main_logger);
}
+
+void init_global_path_env() {
+ auto& settings =
+ GpgFrontend::GlobalSettingStation::GetInstance().GetUISettings();
+
+ bool use_custom_gnupg_install_path = false;
+ try {
+ use_custom_gnupg_install_path =
+ settings.lookup("general.use_custom_gnupg_install_path");
+ } catch (...) {
+ SPDLOG_ERROR("setting operation error: use_custom_gnupg_install_path");
+ }
+
+ // read from settings file
+ std::string custom_gnupg_install_path;
+ try {
+ custom_gnupg_install_path = static_cast<std::string>(
+ settings.lookup("general.custom_gnupg_install_path"));
+
+ } catch (...) {
+ SPDLOG_ERROR("setting operation error: custom_gnupg_install_path");
+ }
+
+ // add custom gnupg install path into env $PATH
+ if (use_custom_gnupg_install_path && !custom_gnupg_install_path.empty()) {
+ std::string path_value = getenv("PATH");
+ SPDLOG_DEBUG("PATH: {}", path_value);
+ setenv(
+ "PATH",
+ ((std::filesystem::path{custom_gnupg_install_path} / "bin").u8string() +
+ ":" + path_value)
+ .c_str(),
+ 1);
+ std::string modified_path_value = getenv("PATH");
+ SPDLOG_DEBUG("Modified PATH: {}", modified_path_value);
+ }
+}
diff --git a/src/main.cpp b/src/main.cpp
index 01964f6a..8243c068 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -74,6 +74,12 @@ extern void before_exit();
extern void init_logging_system();
/**
+ * @brief init global PATH env
+ *
+ */
+extern void init_global_path_env();
+
+/**
*
* @param argc
* @param argv
@@ -104,19 +110,7 @@ int main(int argc, char* argv[]) {
GpgFrontend::InitLoggingSystem();
// change path to search for related
- std::string path_value = getenv("PATH");
- SPDLOG_DEBUG("PATH: {}", path_value);
- setenv("PATH",
- ((GpgFrontend::GlobalSettingStation::GetInstance()
- .GetAppDir()
- .parent_path() /
- "GnuPG" / "bin")
- .u8string() +
- ":" + path_value)
- .c_str(),
- 1);
- std::string modified_path_value = getenv("PATH");
- SPDLOG_DEBUG("Modified PATH: {}", modified_path_value);
+ init_global_path_env();
/**
* internationalisation. loop to restart main window
diff --git a/src/ui/dialog/settings/SettingsGeneral.cpp b/src/ui/dialog/settings/SettingsGeneral.cpp
index 1c7b7c27..34e77278 100644
--- a/src/ui/dialog/settings/SettingsGeneral.cpp
+++ b/src/ui/dialog/settings/SettingsGeneral.cpp
@@ -49,27 +49,26 @@ GeneralTab::GeneralTab(QWidget* parent)
ui_->clearGpgPasswordCacheCheckBox->setText(
"Clear gpg password cache when closing GpgFrontend.");
- ui_->longerKeyExpirationDateBox->setTitle(_("Longer Key Expiration Date"));
+ ui_->importConfirmationBox->setTitle(_("Operation"));
ui_->longerKeyExpirationDateCheckBox->setText(
- _("Unlock key expiration date setting up to 30 years."));
- ui_->importConfirmationBox->setTitle(_("Confirm drag'n'drop key import"));
+ _("Enable to use longer key expiration date."));
ui_->importConfirmationCheckBox->setText(
_("Import files dropped on the Key List without confirmation."));
- ui_->asciiModeBox->setTitle(_("ASCII Mode"));
- ui_->asciiModeCheckBox->setText(
- _("ASCII encoding is not used when file encrypting and "
- "signing."));
+ ui_->gnupgDatabaseBox->setTitle(_("GnuPG"));
+ ui_->asciiModeCheckBox->setText(_("No ASCII Mode"));
+ ui_->useCustomGnuPGInstallPathCheckBox->setText(_("Use Custom GnuPG"));
+ ui_->useCustomGnuPGInstallPathButton->setText(_("Select GnuPG Path"));
+ ui_->keyDatabseUseCustomCheckBox->setText(
+ _("Use Custom GnuPG Key Database Path"));
+ ui_->customKeyDatabasePathSelectButton->setText(
+ _("Select Key Database Path"));
ui_->langBox->setTitle(_("Language"));
ui_->langNoteLabel->setText(
"<b>" + QString(_("NOTE")) + _(": ") + "</b>" +
_("GpgFrontend will restart automatically if you change the language!"));
- ui_->gnupgDatabaseBox->setTitle(_("GnuPG Key Database Path"));
- ui_->keyDatabseUseCustomCheckBox->setText(_("Use Custom Path"));
- ui_->customKeyDatabasePathSelectButton->setText(_("Select Custom Path"));
-
#ifdef MULTI_LANG_SUPPORT
lang_ = SettingsDialog::ListLanguages();
for (const auto& l : lang_) {
@@ -84,12 +83,23 @@ GeneralTab::GeneralTab(QWidget* parent)
ui_->customKeyDatabasePathSelectButton->setDisabled(
state != Qt::CheckState::Checked);
// announce the restart
- this->slot_key_databse_path_changed();
+ this->slot_gnupg_stettings_changed();
+ });
+
+ connect(ui_->useCustomGnuPGInstallPathCheckBox, &QCheckBox::stateChanged,
+ this, [=](int state) {
+ ui_->useCustomGnuPGInstallPathButton->setDisabled(
+ state != Qt::CheckState::Checked);
+ // announce the restart
+ this->slot_gnupg_stettings_changed();
});
connect(ui_->keyDatabseUseCustomCheckBox, &QCheckBox::stateChanged, this,
&GeneralTab::slot_update_custom_key_database_path_label);
+ connect(ui_->useCustomGnuPGInstallPathCheckBox, &QCheckBox::stateChanged,
+ this, &GeneralTab::slot_update_custom_gnupg_install_path_label);
+
connect(
ui_->customKeyDatabasePathSelectButton, &QPushButton::clicked, this,
[=]() {
@@ -116,7 +126,7 @@ GeneralTab::GeneralTab(QWidget* parent)
}
// announce the restart
- this->slot_key_databse_path_changed();
+ this->slot_gnupg_stettings_changed();
// update ui
this->slot_update_custom_key_database_path_label(
@@ -124,6 +134,39 @@ GeneralTab::GeneralTab(QWidget* parent)
}
});
+ connect(
+ ui_->useCustomGnuPGInstallPathButton, &QPushButton::clicked, this, [=]() {
+ QString selected_custom_gnupg_install_path =
+ QFileDialog::getExistingDirectory(
+ this, _("Open Directory"), {},
+ QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
+
+ SPDLOG_INFO("gnupg install path selected: {}",
+ selected_custom_gnupg_install_path.toStdString());
+
+ if (!selected_custom_gnupg_install_path.isEmpty()) {
+ auto& settings = GlobalSettingStation::GetInstance().GetUISettings();
+ 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();
+ }
+
+ // announce the restart
+ this->slot_gnupg_stettings_changed();
+
+ // update ui
+ this->slot_update_custom_gnupg_install_path_label(
+ this->ui_->useCustomGnuPGInstallPathCheckBox->checkState());
+ }
+ });
+
SetSettings();
}
@@ -207,6 +250,18 @@ void GeneralTab::SetSettings() {
this->slot_update_custom_key_database_path_label(
ui_->keyDatabseUseCustomCheckBox->checkState());
+
+ try {
+ bool use_custom_gnupg_install_path =
+ settings.lookup("general.use_custom_gnupg_install_path");
+ if (use_custom_gnupg_install_path)
+ ui_->useCustomGnuPGInstallPathCheckBox->setCheckState(Qt::Checked);
+ } catch (...) {
+ SPDLOG_ERROR("setting operation error: use_custom_gnupg_install_path");
+ }
+
+ this->slot_update_custom_gnupg_install_path_label(
+ ui_->useCustomGnuPGInstallPathCheckBox->checkState());
}
/***********************************
@@ -279,6 +334,15 @@ void GeneralTab::ApplySettings() {
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();
+ }
}
#ifdef MULTI_LANG_SUPPORT
@@ -312,16 +376,48 @@ void GeneralTab::slot_update_custom_key_database_path_label(int state) {
if (!custom_key_database_path.empty()) {
ui_->currentKeyDatabasePathLabel->setText(
QString::fromStdString(custom_key_database_path));
+ this->ui_->currentKeyDatabasePathLabel->setHidden(false);
} else {
- ui_->currentKeyDatabasePathLabel->setText(
- _("None custom key database path."));
+ this->ui_->currentKeyDatabasePathLabel->setHidden(true);
}
+ }
+}
- this->ui_->currentKeyDatabasePathLabel->setHidden(false);
+void GeneralTab::slot_update_custom_gnupg_install_path_label(int state) {
+ if (state != Qt::CheckState::Checked) {
+ ui_->currentCustomGnuPGInstallPathLabel->setText(QString::fromStdString(
+ GpgContext::GetInstance().GetInfo(false).GnuPGHomePath));
+
+ // hide label (not necessary to show the default path)
+ this->ui_->currentCustomGnuPGInstallPathLabel->setHidden(true);
+ } else {
+ // read from settings file
+ std::string custom_gnupg_install_path;
+ try {
+ auto& settings =
+ GpgFrontend::GlobalSettingStation::GetInstance().GetUISettings();
+ custom_gnupg_install_path = static_cast<std::string>(
+ settings.lookup("general.custom_gnupg_install_path"));
+
+ } catch (...) {
+ SPDLOG_ERROR("setting operation error: custom_gnupg_install_path");
+ }
+
+ SPDLOG_INFO("custom_gnupg_install_path from settings: {}",
+ custom_gnupg_install_path);
+
+ // set label value
+ if (!custom_gnupg_install_path.empty()) {
+ ui_->currentCustomGnuPGInstallPathLabel->setText(
+ QString::fromStdString(custom_gnupg_install_path));
+ this->ui_->currentCustomGnuPGInstallPathLabel->setHidden(false);
+ } else {
+ this->ui_->currentCustomGnuPGInstallPathLabel->setHidden(true);
+ }
}
}
-void GeneralTab::slot_key_databse_path_changed() {
+void GeneralTab::slot_gnupg_stettings_changed() {
emit SignalDeepRestartNeeded(true);
}
diff --git a/src/ui/dialog/settings/SettingsGeneral.h b/src/ui/dialog/settings/SettingsGeneral.h
index 4543df7d..ecd2809e 100644
--- a/src/ui/dialog/settings/SettingsGeneral.h
+++ b/src/ui/dialog/settings/SettingsGeneral.h
@@ -109,7 +109,13 @@ class GeneralTab : public QWidget {
* @brief
*
*/
- void slot_key_databse_path_changed();
+ void slot_update_custom_gnupg_install_path_label(int state);
+
+ /**
+ * @brief
+ *
+ */
+ void slot_gnupg_stettings_changed();
#endif
};
diff --git a/ui/GeneralSettings.ui b/ui/GeneralSettings.ui
index 678f02a9..75aef6b2 100644
--- a/ui/GeneralSettings.ui
+++ b/ui/GeneralSettings.ui
@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>643</width>
- <height>656</height>
+ <height>721</height>
</rect>
</property>
<property name="windowTitle">
@@ -17,26 +17,6 @@
<item row="0" column="0">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
- <widget class="QGroupBox" name="longerKeyExpirationDateBox">
- <property name="title">
- <string>Longer Key Expiration Date</string>
- </property>
- <layout class="QGridLayout" name="gridLayout_2">
- <item row="0" column="0">
- <layout class="QVBoxLayout" name="verticalLayout_2">
- <item>
- <widget class="QCheckBox" name="longerKeyExpirationDateCheckBox">
- <property name="text">
- <string>Unlock key expiration date setting up to 30 years.</string>
- </property>
- </widget>
- </item>
- </layout>
- </item>
- </layout>
- </widget>
- </item>
- <item>
<widget class="QGroupBox" name="cacheBox">
<property name="title">
<string>Cache</string>
@@ -47,7 +27,7 @@
<item>
<widget class="QCheckBox" name="saveCheckedKeysCheckBox">
<property name="text">
- <string>Save checked private keys on exit and restore them on next start.</string>
+ <string>Save checked keys in Key ToolBox on exit and restore them on next start.</string>
</property>
</widget>
</item>
@@ -66,7 +46,7 @@
<item>
<widget class="QGroupBox" name="importConfirmationBox">
<property name="title">
- <string>Confirm drag'n'drop key import</string>
+ <string>Operation</string>
</property>
<layout class="QGridLayout" name="gridLayout_4">
<item row="0" column="0">
@@ -78,70 +58,75 @@
</property>
</widget>
</item>
+ <item>
+ <widget class="QCheckBox" name="longerKeyExpirationDateCheckBox">
+ <property name="text">
+ <string>Enable to use longer key expiration date.</string>
+ </property>
+ </widget>
+ </item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
- <widget class="QGroupBox" name="asciiModeBox">
+ <widget class="QGroupBox" name="gnupgDatabaseBox">
<property name="title">
- <string>ASCII Mode</string>
+ <string>GnuPG</string>
</property>
- <layout class="QGridLayout" name="gridLayout_6">
+ <layout class="QGridLayout" name="gridLayout_7">
<item row="0" column="0">
- <layout class="QVBoxLayout" name="verticalLayout_6">
+ <layout class="QVBoxLayout" name="verticalLayout_7">
<item>
<widget class="QCheckBox" name="asciiModeCheckBox">
<property name="text">
- <string>ASCII encoding is not used when file encrypting and signing.</string>
+ <string>No ASCII Mode</string>
</property>
</widget>
</item>
- </layout>
- </item>
- </layout>
- </widget>
- </item>
- <item>
- <widget class="QGroupBox" name="langBox">
- <property name="title">
- <string>Language</string>
- </property>
- <layout class="QGridLayout" name="gridLayout_5">
- <item row="0" column="0">
- <layout class="QVBoxLayout" name="verticalLayout_5">
<item>
- <widget class="QComboBox" name="langSelectBox">
- <property name="sizeAdjustPolicy">
- <enum>QComboBox::AdjustToContents</enum>
+ <widget class="Line" name="line_2">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
- <widget class="QLabel" name="langNoteLabel">
+ <widget class="QCheckBox" name="useCustomGnuPGInstallPathCheckBox">
<property name="text">
- <string>NOTE: GpgFrontend will restart automatically if you change the language!</string>
+ <string>Use Custom GnuPG</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="currentCustomGnuPGInstallPathLabel">
+ <property name="text">
+ <string/>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="useCustomGnuPGInstallPathButton">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ <property name="text">
+ <string>Select GnuPG Path</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="Line" name="line">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
- </layout>
- </item>
- </layout>
- </widget>
- </item>
- <item>
- <widget class="QGroupBox" name="gnupgDatabaseBox">
- <property name="title">
- <string>GnuPG Key Database Path</string>
- </property>
- <layout class="QGridLayout" name="gridLayout_7">
- <item row="0" column="0">
- <layout class="QVBoxLayout" name="verticalLayout_7">
<item>
<widget class="QCheckBox" name="keyDatabseUseCustomCheckBox">
<property name="text">
- <string>Use Custom Path</string>
+ <string>Use Custom GnuPG Key Database Path</string>
</property>
</widget>
</item>
@@ -161,7 +146,34 @@
<bool>false</bool>
</property>
<property name="text">
- <string>Select Custom Path</string>
+ <string>Select Key Database Path</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item>
+ <widget class="QGroupBox" name="langBox">
+ <property name="title">
+ <string>Language</string>
+ </property>
+ <layout class="QGridLayout" name="gridLayout_5">
+ <item row="0" column="0">
+ <layout class="QVBoxLayout" name="verticalLayout_5">
+ <item>
+ <widget class="QComboBox" name="langSelectBox">
+ <property name="sizeAdjustPolicy">
+ <enum>QComboBox::AdjustToContents</enum>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="langNoteLabel">
+ <property name="text">
+ <string>NOTE: GpgFrontend will restart automatically if you change the language!</string>
</property>
</widget>
</item>