aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSaturneric <[email protected]>2023-04-04 16:15:06 +0000
committerSaturneric <[email protected]>2023-04-04 16:15:06 +0000
commitc18fda02ba7d42056d417dc1bf3401d867f99cb4 (patch)
tree37be8a1c499b079d9b5e54f6d80bd0f2ae93c080
parentfeat: improve deep restart progress (diff)
downloadGpgFrontend-c18fda02ba7d42056d417dc1bf3401d867f99cb4.tar.gz
GpgFrontend-c18fda02ba7d42056d417dc1bf3401d867f99cb4.zip
feat: remove gnupg settings from general tab
-rw-r--r--src/ui/SignalStation.h6
-rw-r--r--src/ui/UserInterfaceUtils.cpp57
-rw-r--r--src/ui/UserInterfaceUtils.h19
-rw-r--r--src/ui/dialog/settings/SettingsGeneral.cpp257
-rw-r--r--src/ui/dialog/settings/SettingsGeneral.h19
-rw-r--r--ui/GeneralSettings.ui92
6 files changed, 78 insertions, 372 deletions
diff --git a/src/ui/SignalStation.h b/src/ui/SignalStation.h
index 48651f1b..5037ef4f 100644
--- a/src/ui/SignalStation.h
+++ b/src/ui/SignalStation.h
@@ -91,6 +91,12 @@ class SignalStation : public QObject {
*
*/
void SignalNeedUserInputPassphrase();
+
+ /**
+ * @brief
+ *
+ */
+ void SignalRestartApplication(int);
};
} // namespace GpgFrontend::UI
diff --git a/src/ui/UserInterfaceUtils.cpp b/src/ui/UserInterfaceUtils.cpp
index 5a11e119..dcc14f50 100644
--- a/src/ui/UserInterfaceUtils.cpp
+++ b/src/ui/UserInterfaceUtils.cpp
@@ -32,6 +32,7 @@
#include <utility>
#include <vector>
+#include "core/GpgConstants.h"
#include "core/common/CoreCommonUtil.h"
#include "core/function/CoreSignalStation.h"
#include "core/function/FileOperator.h"
@@ -40,6 +41,7 @@
#include "core/thread/Task.h"
#include "core/thread/TaskRunner.h"
#include "core/thread/TaskRunnerGetter.h"
+#include "dialog/gnupg/GnuPGControllerDialog.h"
#include "spdlog/spdlog.h"
#include "ui/SignalStation.h"
#include "ui/dialog/WaitingDialog.h"
@@ -171,15 +173,46 @@ CommonUtils::CommonUtils() : QWidget(nullptr) {
&CoreSignalStation::SignalNeedUserInputPassphrase, this,
&CommonUtils::slot_popup_passphrase_input_dialog);
- connect(this, &CommonUtils::SignalGnupgNotInstall, this, []() {
- QMessageBox::critical(
- nullptr, _("ENV Loading Failed"),
+ connect(this, &CommonUtils::SignalRestartApplication,
+ SignalStation::GetInstance(),
+ &SignalStation::SignalRestartApplication);
+
+ connect(SignalStation::GetInstance(),
+ &SignalStation::SignalRestartApplication, this,
+ &CommonUtils::SlotRestartApplication);
+
+ connect(this, &CommonUtils::SignalGnupgNotInstall, this, [=]() {
+ QMessageBox msgBox;
+ msgBox.setText(_("GnuPG Context Loading Failed"));
+ msgBox.setInformativeText(
_("Gnupg(gpg) is not installed correctly, please follow "
"<a href='https://www.gpgfrontend.pub/#/"
"faq?id=how-to-deal-with-39env-loading-failed39'>this notes</a>"
" in FAQ to install Gnupg and then open "
- "GpgFrontend."));
- QCoreApplication::quit();
+ "GpgFrontend. Or, you can open GnuPG Controller to set a custom "
+ "GnuPG "
+ "which GpgFrontend should use. Then, GpgFrontend will restart."));
+ msgBox.setStandardButtons(QMessageBox::Open | QMessageBox::Cancel);
+ msgBox.setDefaultButton(QMessageBox::Save);
+ int ret = msgBox.exec();
+
+ switch (ret) {
+ case QMessageBox::Open:
+ (new GnuPGControllerDialog(this))->exec();
+ // restart application when loop start
+ application_need_to_restart_at_once_ = true;
+ // restart application, core and ui
+ emit SignalRestartApplication(DEEP_RESTART_CODE);
+ break;
+ case QMessageBox::Cancel:
+ // close application
+ emit SignalRestartApplication(0);
+ break;
+ default:
+ // close application
+ emit SignalRestartApplication(0);
+ break;
+ }
});
}
@@ -431,4 +464,18 @@ void CommonUtils::slot_popup_passphrase_input_dialog() {
emit SignalUserInputPassphraseDone(password);
}
+void CommonUtils::SlotRestartApplication(int code) {
+ SPDLOG_DEBUG("application need restart, code: {}", code);
+
+ if (code == 0) {
+ std::exit(0);
+ } else {
+ QCoreApplication::exit(code);
+ }
+}
+
+bool CommonUtils::isApplicationNeedRestart() {
+ return application_need_to_restart_at_once_;
+}
+
} // namespace GpgFrontend::UI \ No newline at end of file
diff --git a/src/ui/UserInterfaceUtils.h b/src/ui/UserInterfaceUtils.h
index 7761de7b..7dd7bb1e 100644
--- a/src/ui/UserInterfaceUtils.h
+++ b/src/ui/UserInterfaceUtils.h
@@ -144,6 +144,12 @@ class CommonUtils : public QWidget {
*/
static CommonUtils* GetInstance();
+ /**
+ * @brief
+ *
+ */
+ bool isApplicationNeedRestart();
+
signals:
/**
* @brief
@@ -175,6 +181,12 @@ class CommonUtils : public QWidget {
*/
void SignalUserInputPassphraseDone(QString passphrase);
+ /**
+ * @brief
+ *
+ */
+ void SignalRestartApplication(int);
+
public slots:
/**
* @brief
@@ -235,6 +247,12 @@ class CommonUtils : public QWidget {
void SlotExecuteCommand(const std::string& cmd, const QStringList& arguments,
const std::function<void(QProcess*)>& interact_func);
+ /**
+ * @brief
+ *
+ */
+ void SlotRestartApplication(int);
+
private slots:
/**
@@ -251,6 +269,7 @@ class CommonUtils : public QWidget {
private:
static std::unique_ptr<CommonUtils> instance_; ///<
+ bool application_need_to_restart_at_once_ = false;
};
} // namespace GpgFrontend::UI
diff --git a/src/ui/dialog/settings/SettingsGeneral.cpp b/src/ui/dialog/settings/SettingsGeneral.cpp
index 17d9251c..c967b8fd 100644
--- a/src/ui/dialog/settings/SettingsGeneral.cpp
+++ b/src/ui/dialog/settings/SettingsGeneral.cpp
@@ -55,17 +55,6 @@ GeneralTab::GeneralTab(QWidget* parent)
ui_->importConfirmationCheckBox->setText(
_("Import files dropped on the Key List without confirmation."));
- 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(
- _("Use Custom GnuPG Key Database Path"));
- ui_->customKeyDatabasePathSelectButton->setText(
- _("Select Key Database Path"));
-
ui_->langBox->setTitle(_("Language"));
ui_->langNoteLabel->setText(
"<b>" + QString(_("NOTE")) + _(": ") + "</b>" +
@@ -80,101 +69,6 @@ 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_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,
- [=]() {
- QString selected_custom_key_database_path =
- QFileDialog::getExistingDirectory(
- this, _("Open Directory"), {},
- QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
-
- SPDLOG_DEBUG("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_gnupg_stettings_changed();
-
- // update ui
- this->slot_update_custom_key_database_path_label(
- this->ui_->keyDatabseUseCustomCheckBox->checkState());
- }
- });
-
- connect(
- ui_->useCustomGnuPGInstallPathButton, &QPushButton::clicked, this, [=]() {
- QString selected_custom_gnupg_install_path =
- QFileDialog::getExistingDirectory(
- this, _("Open Directory"), {},
- QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
-
- SPDLOG_DEBUG("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());
- }
- });
-
- connect(ui_->usePinentryAsPasswordInputDialogCheckBox,
- &QCheckBox::stateChanged, this, [=](int state) {
- // announce the restart
- this->slot_gnupg_stettings_changed();
- });
-
SetSettings();
}
@@ -185,6 +79,7 @@ GeneralTab::GeneralTab(QWidget* parent)
**********************************/
void GeneralTab::SetSettings() {
auto& settings = GlobalSettingStation::GetInstance().GetUISettings();
+
try {
bool save_key_checked = settings.lookup("general.save_key_checked");
if (save_key_checked)
@@ -236,50 +131,6 @@ void GeneralTab::SetSettings() {
} catch (...) {
SPDLOG_ERROR("setting operation error: confirm_import_keys");
}
-
- try {
- bool non_ascii_when_export =
- settings.lookup("general.non_ascii_when_export");
- SPDLOG_DEBUG("non_ascii_when_export: {}", non_ascii_when_export);
- if (non_ascii_when_export)
- ui_->asciiModeCheckBox->setCheckState(Qt::Checked);
- } catch (...) {
- SPDLOG_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 (...) {
- SPDLOG_ERROR("setting operation error: use_custom_key_database_path");
- }
-
- 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");
- }
-
- 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());
}
/***********************************
@@ -319,13 +170,6 @@ void GeneralTab::ApplySettings() {
ui_->saveCheckedKeysCheckBox->isChecked();
}
- if (!general.exists("non_ascii_when_export"))
- general.add("non_ascii_when_export", libconfig::Setting::TypeBoolean) =
- ui_->asciiModeCheckBox->isChecked();
- else {
- general["non_ascii_when_export"] = ui_->asciiModeCheckBox->isChecked();
- }
-
#ifdef MULTI_LANG_SUPPORT
if (!general.exists("lang"))
general.add("lang", libconfig::Setting::TypeBoolean) =
@@ -343,109 +187,10 @@ 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();
- }
-
- 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();
- }
-
- 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
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(false).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 (...) {
- SPDLOG_ERROR("setting operation error: custom_key_database_path");
- }
-
- SPDLOG_DEBUG("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));
- this->ui_->currentKeyDatabasePathLabel->setHidden(false);
- } else {
- this->ui_->currentKeyDatabasePathLabel->setHidden(true);
- }
- }
-}
-
-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_DEBUG("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_gnupg_stettings_changed() {
- emit SignalDeepRestartNeeded(true);
-}
-
} // namespace GpgFrontend::UI
diff --git a/src/ui/dialog/settings/SettingsGeneral.h b/src/ui/dialog/settings/SettingsGeneral.h
index ecd2809e..be145b1f 100644
--- a/src/ui/dialog/settings/SettingsGeneral.h
+++ b/src/ui/dialog/settings/SettingsGeneral.h
@@ -98,25 +98,6 @@ class GeneralTab : public QWidget {
*
*/
void slot_language_changed();
-
- /**
- * @brief
- *
- */
- void slot_update_custom_key_database_path_label(int state);
-
- /**
- * @brief
- *
- */
- void slot_update_custom_gnupg_install_path_label(int state);
-
- /**
- * @brief
- *
- */
- void slot_gnupg_stettings_changed();
-
#endif
};
} // namespace GpgFrontend::UI
diff --git a/ui/GeneralSettings.ui b/ui/GeneralSettings.ui
index 668d3396..f957a3ac 100644
--- a/ui/GeneralSettings.ui
+++ b/ui/GeneralSettings.ui
@@ -71,98 +71,6 @@
</widget>
</item>
<item>
- <widget class="QGroupBox" name="gnupgDatabaseBox">
- <property name="title">
- <string>GnuPG</string>
- </property>
- <layout class="QGridLayout" name="gridLayout_7">
- <item row="0" column="0">
- <layout class="QVBoxLayout" name="verticalLayout_7">
- <item>
- <widget class="QCheckBox" name="asciiModeCheckBox">
- <property name="text">
- <string>No ASCII Mode</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QCheckBox" name="usePinentryAsPasswordInputDialogCheckBox">
- <property name="text">
- <string>Use Pinentry as Password Input Dialog</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="Line" name="line_2">
- <property name="orientation">
- <enum>Qt::Horizontal</enum>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QCheckBox" name="useCustomGnuPGInstallPathCheckBox">
- <property name="text">
- <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>
- <item>
- <widget class="QCheckBox" name="keyDatabseUseCustomCheckBox">
- <property name="text">
- <string>Use Custom GnuPG Key Database Path</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QLabel" name="currentKeyDatabasePathLabel">
- <property name="enabled">
- <bool>false</bool>
- </property>
- <property name="text">
- <string/>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QPushButton" name="customKeyDatabasePathSelectButton">
- <property name="enabled">
- <bool>false</bool>
- </property>
- <property name="text">
- <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>