aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsaturneric <[email protected]>2024-05-03 15:13:14 +0000
committersaturneric <[email protected]>2024-05-03 15:13:14 +0000
commit3d3c3d954bd2e8422e1ee3c0ba767993de1e4615 (patch)
tree6bdcf066f44390cfd90d904065099a32486a62cf
parentfix: min size of main windows is 640 * 480 (diff)
downloadGpgFrontend-3d3c3d954bd2e8422e1ee3c0ba767993de1e4615.tar.gz
GpgFrontend-3d3c3d954bd2e8422e1ee3c0ba767993de1e4615.zip
feat: add option to close all gnupg daemon at close
-rw-r--r--src/core/GpgCoreInit.cpp12
-rw-r--r--src/core/function/gpg/GpgAdvancedOperator.cpp28
-rw-r--r--src/core/function/gpg/GpgAdvancedOperator.h6
-rw-r--r--src/ui/dialog/controller/GnuPGControllerDialog.cpp53
-rw-r--r--src/ui/dialog/controller/ModuleControllerDialog.cpp2
-rw-r--r--ui/GnuPGControllerDialog.ui9
6 files changed, 86 insertions, 24 deletions
diff --git a/src/core/GpgCoreInit.cpp b/src/core/GpgCoreInit.cpp
index 42991564..2952d6e4 100644
--- a/src/core/GpgCoreInit.cpp
+++ b/src/core/GpgCoreInit.cpp
@@ -45,7 +45,17 @@
namespace GpgFrontend {
-void DestroyGpgFrontendCore() { SingletonStorageCollection::Destroy(); }
+void DestroyGpgFrontendCore() {
+ // kill all daemon if necessary
+ auto settings = GlobalSettingStation::GetInstance().GetSettings();
+ auto kill_all_gnupg_daemon_at_close =
+ settings.value("gnupg/kill_all_gnupg_daemon_at_close", false).toBool();
+ if (kill_all_gnupg_daemon_at_close) {
+ GpgAdvancedOperator::KillAllGpgComponents();
+ }
+
+ SingletonStorageCollection::Destroy();
+}
auto VerifyGpgconfPath(const QFileInfo& gnupg_install_fs_path) -> bool {
return gnupg_install_fs_path.isAbsolute() && gnupg_install_fs_path.exists() &&
diff --git a/src/core/function/gpg/GpgAdvancedOperator.cpp b/src/core/function/gpg/GpgAdvancedOperator.cpp
index a99429ce..cb8fec00 100644
--- a/src/core/function/gpg/GpgAdvancedOperator.cpp
+++ b/src/core/function/gpg/GpgAdvancedOperator.cpp
@@ -76,6 +76,34 @@ void GpgFrontend::GpgAdvancedOperator::ReloadGpgComponents(
}});
}
+void GpgFrontend::GpgAdvancedOperator::KillAllGpgComponents() {
+ const auto gpgconf_path = Module::RetrieveRTValueTypedOrDefault<>(
+ "core", "gpgme.ctx.gpgconf_path", QString{});
+ GF_CORE_LOG_DEBUG("got gpgconf path from rt: {}", gpgconf_path);
+
+ if (gpgconf_path.isEmpty()) {
+ GF_CORE_LOG_ERROR("cannot get valid gpgconf path from rt, abort.");
+ return;
+ }
+
+ GpgFrontend::GpgCommandExecutor::ExecuteSync(
+ {gpgconf_path, QStringList{"--verbose", "--kill", "all"},
+ [=](int exit_code, const QString &p_out, const QString &p_err) {
+ GF_CORE_LOG_DEBUG("gpgconf --kill all command got exit code: {}",
+ exit_code);
+ bool success = true;
+ if (exit_code != 0) {
+ success = false;
+ GF_CORE_LOG_ERROR(
+ "gpgconf execute error, process stderr: {}, process stdout: {}",
+ p_err, p_out);
+ return;
+ }
+
+ GF_CORE_LOG_DEBUG("gpgconf --kill --all execute result: {}", success);
+ }});
+}
+
void GpgFrontend::GpgAdvancedOperator::RestartGpgComponents() {
const auto gpgconf_path = Module::RetrieveRTValueTypedOrDefault<>(
"core", "gpgme.ctx.gpgconf_path", QString{});
diff --git a/src/core/function/gpg/GpgAdvancedOperator.h b/src/core/function/gpg/GpgAdvancedOperator.h
index d6b57095..26391e03 100644
--- a/src/core/function/gpg/GpgAdvancedOperator.h
+++ b/src/core/function/gpg/GpgAdvancedOperator.h
@@ -93,6 +93,12 @@ class GPGFRONTEND_CORE_EXPORT GpgAdvancedOperator {
* @return false
*/
static void StartKeyBoxd(OperationCallback);
+
+ /**
+ * @brief
+ *
+ */
+ static void KillAllGpgComponents();
};
} // namespace GpgFrontend
diff --git a/src/ui/dialog/controller/GnuPGControllerDialog.cpp b/src/ui/dialog/controller/GnuPGControllerDialog.cpp
index 4614fed7..b35d2a7d 100644
--- a/src/ui/dialog/controller/GnuPGControllerDialog.cpp
+++ b/src/ui/dialog/controller/GnuPGControllerDialog.cpp
@@ -52,16 +52,18 @@ GnuPGControllerDialog::GnuPGControllerDialog(QWidget* parent)
ui_->gpgmeDebugLogCheckBox->setText(tr("Enable GpgME Debug Log"));
ui_->useCustomGnuPGInstallPathCheckBox->setText(tr("Use Custom GnuPG"));
ui_->useCustomGnuPGInstallPathButton->setText(tr("Select GnuPG Path"));
- ui_->keyDatabseUseCustomCheckBox->setText(
+ ui_->keyDatabaseUseCustomCheckBox->setText(
tr("Use Custom GnuPG Key Database Path"));
ui_->customKeyDatabasePathSelectButton->setText(
tr("Select Key Database Path"));
ui_->restartGpgAgentOnStartCheckBox->setText(
tr("Restart Gpg Agent on start"));
+ ui_->killAllGnuPGDaemonCheckBox->setText(
+ tr("Kill all gnupg daemon at close"));
// tips
ui_->customGnuPGPathTipsLabel->setText(
- tr("Tips: please select a directroy where \"gpgconf\" is located in."));
+ tr("Tips: please select a directory where \"gpgconf\" is located in."));
ui_->restartTipsLabel->setText(
tr("Tips: notice that modify any of these settings will cause an "
"Application restart."));
@@ -71,7 +73,7 @@ GnuPGControllerDialog::GnuPGControllerDialog(QWidget* parent)
UISignalStation::GetInstance(),
&UISignalStation::SignalRestartApplication);
- connect(ui_->keyDatabseUseCustomCheckBox, &QCheckBox::stateChanged, this,
+ connect(ui_->keyDatabaseUseCustomCheckBox, &QCheckBox::stateChanged, this,
[=](int state) {
ui_->customKeyDatabasePathSelectButton->setDisabled(
state != Qt::CheckState::Checked);
@@ -83,7 +85,7 @@ GnuPGControllerDialog::GnuPGControllerDialog(QWidget* parent)
state != Qt::CheckState::Checked);
});
- connect(ui_->keyDatabseUseCustomCheckBox, &QCheckBox::stateChanged, this,
+ connect(ui_->keyDatabaseUseCustomCheckBox, &QCheckBox::stateChanged, this,
&GnuPGControllerDialog::slot_update_custom_key_database_path_label);
connect(ui_->useCustomGnuPGInstallPathCheckBox, &QCheckBox::stateChanged,
@@ -98,7 +100,7 @@ GnuPGControllerDialog::GnuPGControllerDialog(QWidget* parent)
this, tr("Open Directory"), {},
QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
- GF_UI_LOG_DEBUG("key databse path selected: {}",
+ GF_UI_LOG_DEBUG("key database path selected: {}",
selected_custom_key_database_path);
custom_key_database_path_ = selected_custom_key_database_path;
@@ -108,7 +110,7 @@ GnuPGControllerDialog::GnuPGControllerDialog(QWidget* parent)
// update ui
this->slot_update_custom_key_database_path_label(
- this->ui_->keyDatabseUseCustomCheckBox->checkState());
+ this->ui_->keyDatabaseUseCustomCheckBox->checkState());
});
connect(
@@ -263,33 +265,40 @@ void GnuPGControllerDialog::slot_update_custom_gnupg_install_path_label(
void GnuPGControllerDialog::set_settings() {
auto settings = GlobalSettingStation::GetInstance().GetSettings();
- bool non_ascii_at_file_operation =
+ auto non_ascii_at_file_operation =
settings.value("gnupg/non_ascii_at_file_operation", true).toBool();
- if (non_ascii_at_file_operation)
+ if (non_ascii_at_file_operation) {
ui_->asciiModeCheckBox->setCheckState(Qt::Checked);
+ }
- bool const use_custom_key_database_path =
+ auto use_custom_key_database_path =
settings.value("gnupg/use_custom_key_database_path", false).toBool();
if (use_custom_key_database_path) {
- ui_->keyDatabseUseCustomCheckBox->setCheckState(Qt::Checked);
+ ui_->keyDatabaseUseCustomCheckBox->setCheckState(Qt::Checked);
}
- bool const enable_gpgme_debug_log =
+ auto enable_gpgme_debug_log =
settings.value("gnupg/enable_gpgme_debug_log", false).toBool();
if (enable_gpgme_debug_log) {
ui_->gpgmeDebugLogCheckBox->setCheckState(Qt::Checked);
}
+ auto kill_all_gnupg_daemon_at_close =
+ settings.value("gnupg/kill_all_gnupg_daemon_at_close", false).toBool();
+ if (kill_all_gnupg_daemon_at_close) {
+ ui_->killAllGnuPGDaemonCheckBox->setCheckState(Qt::Checked);
+ }
+
this->slot_update_custom_key_database_path_label(
- ui_->keyDatabseUseCustomCheckBox->checkState());
+ ui_->keyDatabaseUseCustomCheckBox->checkState());
- bool const use_custom_gnupg_install_path =
+ auto use_custom_gnupg_install_path =
settings.value("gnupg/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 =
+ auto use_pinentry_as_password_input_dialog =
settings
.value("gnupg/use_pinentry_as_password_input_dialog",
QString::fromLocal8Bit(qgetenv("container")) != "flatpak")
@@ -298,7 +307,7 @@ void GnuPGControllerDialog::set_settings() {
ui_->usePinentryAsPasswordInputDialogCheckBox->setCheckState(Qt::Checked);
}
- bool const restart_gpg_agent_on_start =
+ auto restart_gpg_agent_on_start =
settings.value("gnupg/restart_gpg_agent_on_start", false).toBool();
if (restart_gpg_agent_on_start) {
ui_->restartGpgAgentOnStartCheckBox->setCheckState(Qt::Checked);
@@ -320,7 +329,7 @@ void GnuPGControllerDialog::apply_settings() {
settings.setValue("gnupg/non_ascii_at_file_operation",
ui_->asciiModeCheckBox->isChecked());
settings.setValue("gnupg/use_custom_key_database_path",
- ui_->keyDatabseUseCustomCheckBox->isChecked());
+ ui_->keyDatabaseUseCustomCheckBox->isChecked());
settings.setValue("gnupg/use_custom_gnupg_install_path",
ui_->useCustomGnuPGInstallPathCheckBox->isChecked());
settings.setValue("gnupg/use_pinentry_as_password_input_dialog",
@@ -333,6 +342,8 @@ void GnuPGControllerDialog::apply_settings() {
ui_->currentCustomGnuPGInstallPathLabel->text());
settings.setValue("gnupg/restart_gpg_agent_on_start",
ui_->restartGpgAgentOnStartCheckBox->isChecked());
+ settings.setValue("gnupg/kill_all_gnupg_daemon_at_close",
+ ui_->killAllGnuPGDaemonCheckBox->isChecked());
}
auto GnuPGControllerDialog::get_restart_needed() const -> int {
@@ -347,7 +358,7 @@ void GnuPGControllerDialog::slot_set_restart_needed(int mode) {
auto GnuPGControllerDialog::check_custom_gnupg_path(QString path) -> bool {
if (path.isEmpty()) return false;
- QFileInfo dir_info(path);
+ QFileInfo const dir_info(path);
if (!dir_info.exists() || !dir_info.isReadable() || !dir_info.isDir()) {
QMessageBox::critical(
this, tr("Illegal GnuPG Path"),
@@ -355,15 +366,15 @@ auto GnuPGControllerDialog::check_custom_gnupg_path(QString path) -> bool {
return false;
}
- QDir dir(path);
+ QDir const dir(path);
if (!dir.isAbsolute()) {
QMessageBox::critical(this, tr("Illegal GnuPG Path"),
tr("Target GnuPG Path is not an absolute path."));
}
#ifdef WINDOWS
- QFileInfo gpgconf_info(path + "/gpgconf.exe");
+ QFileInfo const gpgconf_info(path + "/gpgconf.exe");
#else
- QFileInfo gpgconf_info(path + "/gpgconf");
+ QFileInfo const gpgconf_info(path + "/gpgconf");
#endif
if (!gpgconf_info.exists() || !gpgconf_info.isFile() ||
@@ -381,7 +392,7 @@ auto GnuPGControllerDialog::check_custom_gnupg_key_database_path(QString path)
-> bool {
if (path.isEmpty()) return false;
- QFileInfo dir_info(path);
+ QFileInfo const dir_info(path);
if (!dir_info.exists() || !dir_info.isReadable() || !dir_info.isDir()) {
QMessageBox::critical(this, tr("Illegal GnuPG Key Database Path"),
tr("Target GnuPG Key Database Path is not an "
diff --git a/src/ui/dialog/controller/ModuleControllerDialog.cpp b/src/ui/dialog/controller/ModuleControllerDialog.cpp
index e99e84a3..8dfd8dd6 100644
--- a/src/ui/dialog/controller/ModuleControllerDialog.cpp
+++ b/src/ui/dialog/controller/ModuleControllerDialog.cpp
@@ -126,7 +126,7 @@ void ModuleControllerDialog::slot_load_module_details(
info << " - " << tr("Hash") << ": " << module->GetModuleHash() << Qt::endl;
info << " - " << tr("Path") << ": " << module->GetModulePath() << Qt::endl;
- bool if_activated = module_manager_->IsModuleActivated(module_id);
+ auto if_activated = module_manager_->IsModuleActivated(module_id);
info << " - " << tr("Auto Activate") << ": "
<< (module_so.auto_activate ? tr("True") : tr("False")) << Qt::endl;
diff --git a/ui/GnuPGControllerDialog.ui b/ui/GnuPGControllerDialog.ui
index e79fc041..4f0bdfc6 100644
--- a/ui/GnuPGControllerDialog.ui
+++ b/ui/GnuPGControllerDialog.ui
@@ -52,6 +52,13 @@
</property>
</widget>
</item>
+ <item>
+ <widget class="QCheckBox" name="killAllGnuPGDaemonCheckBox">
+ <property name="text">
+ <string>Kill all gnupg daemon at close</string>
+ </property>
+ </widget>
+ </item>
</layout>
</item>
</layout>
@@ -75,7 +82,7 @@
<item row="0" column="0">
<layout class="QVBoxLayout" name="verticalLayout_6">
<item>
- <widget class="QCheckBox" name="keyDatabseUseCustomCheckBox">
+ <widget class="QCheckBox" name="keyDatabaseUseCustomCheckBox">
<property name="text">
<string>Use Custom GnuPG Key Database Path</string>
</property>