aboutsummaryrefslogtreecommitdiffstats
path: root/src/ui/dialog/controller
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/ui/dialog/controller/GnuPGControllerDialog.cpp (renamed from src/ui/dialog/gnupg/GnuPGControllerDialog.cpp)74
-rw-r--r--src/ui/dialog/controller/GnuPGControllerDialog.h (renamed from src/ui/dialog/gnupg/GnuPGControllerDialog.h)2
-rw-r--r--src/ui/dialog/controller/ModuleControllerDialog.cpp186
-rw-r--r--src/ui/dialog/controller/ModuleControllerDialog.h (renamed from src/module/integrated/gnupg_info_gathering_module/GnuPGInfoGatheringModule.h)44
4 files changed, 253 insertions, 53 deletions
diff --git a/src/ui/dialog/gnupg/GnuPGControllerDialog.cpp b/src/ui/dialog/controller/GnuPGControllerDialog.cpp
index ea0a27c9..1874e255 100644
--- a/src/ui/dialog/gnupg/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(
@@ -185,9 +187,6 @@ void GnuPGControllerDialog::SlotAccept() {
void GnuPGControllerDialog::slot_update_custom_key_database_path_label(
int state) {
- // announce the restart
- this->slot_set_restart_needed(kDeepRestartCode);
-
// hide label (not necessary to show the default path)
this->ui_->currentKeyDatabasePathLabel->setHidden(state !=
Qt::CheckState::Checked);
@@ -225,9 +224,6 @@ void GnuPGControllerDialog::slot_update_custom_key_database_path_label(
void GnuPGControllerDialog::slot_update_custom_gnupg_install_path_label(
int state) {
- // announce the restart
- this->slot_set_restart_needed(kDeepRestartCode);
-
// hide label (not necessary to show the default path)
this->ui_->currentCustomGnuPGInstallPathLabel->setHidden(
state != Qt::CheckState::Checked);
@@ -269,52 +265,61 @@ 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 =
- settings.value("gnupg/use_pinentry_as_password_input_dialog", true)
+ auto use_pinentry_as_password_input_dialog =
+ settings
+ .value("gnupg/use_pinentry_as_password_input_dialog",
+ QString::fromLocal8Bit(qgetenv("container")) != "flatpak")
.toBool();
if (use_pinentry_as_password_input_dialog) {
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);
}
- this->slot_set_restart_needed(false);
-
this->slot_update_custom_key_database_path_label(
use_custom_key_database_path ? Qt::Checked : Qt::Unchecked);
this->slot_update_custom_gnupg_install_path_label(
use_custom_gnupg_install_path ? Qt::Checked : Qt::Unchecked);
+
+ this->slot_set_restart_needed(kNonRestartCode);
}
void GnuPGControllerDialog::apply_settings() {
@@ -324,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",
@@ -337,20 +342,23 @@ 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());
}
-int GnuPGControllerDialog::get_restart_needed() const {
- return this->restart_needed_;
+auto GnuPGControllerDialog::get_restart_needed() const -> int {
+ return this->restart_mode_;
}
void GnuPGControllerDialog::slot_set_restart_needed(int mode) {
- this->restart_needed_ = mode;
+ GF_UI_LOG_INFO("announce restart needed, mode: {}", mode);
+ this->restart_mode_ = 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"),
@@ -358,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() ||
@@ -384,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/gnupg/GnuPGControllerDialog.h b/src/ui/dialog/controller/GnuPGControllerDialog.h
index 6e8ef797..e8a4b83c 100644
--- a/src/ui/dialog/gnupg/GnuPGControllerDialog.h
+++ b/src/ui/dialog/controller/GnuPGControllerDialog.h
@@ -83,7 +83,7 @@ class GnuPGControllerDialog : public GeneralDialog {
private:
std::shared_ptr<Ui_GnuPGControllerDialog> ui_; ///<
- int restart_needed_{0}; ///<
+ int restart_mode_{0}; ///<
QString custom_key_database_path_;
QString custom_gnupg_path_;
diff --git a/src/ui/dialog/controller/ModuleControllerDialog.cpp b/src/ui/dialog/controller/ModuleControllerDialog.cpp
new file mode 100644
index 00000000..4c727b48
--- /dev/null
+++ b/src/ui/dialog/controller/ModuleControllerDialog.cpp
@@ -0,0 +1,186 @@
+/**
+ * Copyright (C) 2021 Saturneric <[email protected]>
+ *
+ * This file is part of GpgFrontend.
+ *
+ * GpgFrontend is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GpgFrontend is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GpgFrontend. If not, see <https://www.gnu.org/licenses/>.
+ *
+ * The initial version of the source code is inherited from
+ * the gpg4usb project, which is under GPL-3.0-or-later.
+ *
+ * All the source code of GpgFrontend was modified and released by
+ * Saturneric <[email protected]> starting on May 12, 2021.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ *
+ */
+
+#include "ModuleControllerDialog.h"
+
+#include "core/function/GlobalSettingStation.h"
+#include "core/model/SettingsObject.h"
+#include "core/struct/settings_object/ModuleSO.h"
+#include "ui_ModuleControllerDialog.h"
+
+//
+#include "core/module/ModuleManager.h"
+#include "ui/widgets/ModuleListView.h"
+
+namespace GpgFrontend::UI {
+
+ModuleControllerDialog::ModuleControllerDialog(QWidget* parent)
+ : QDialog(parent),
+ ui_(std::make_shared<Ui_ModuleControllerDialog>()),
+ module_manager_(&Module::ModuleManager::GetInstance()) {
+ ui_->setupUi(this);
+ ui_->actionsGroupBox->hide();
+
+ ui_->moduleInfoLabel->setText(tr("Module Informations"));
+ ui_->actionsGroupBox->setTitle(tr("Actions"));
+ ui_->showModsDirButton->setText(tr("Show Mods Directory"));
+
+ ui_->tabWidget->setTabText(0, tr("Registered Modules"));
+ ui_->tabWidget->setTabText(1, tr("Global Register Table"));
+ ui_->tabWidget->setTabText(2, tr("Debugger"));
+
+ ui_->tipsLabel->setText(
+ tr("Tips: Module name front with \"*\" stands for integrated module."));
+
+ this->setWindowTitle(tr("Module Controller"));
+
+ connect(ui_->moduleListView, &ModuleListView::SignalSelectModule, this,
+ &ModuleControllerDialog::slot_load_module_details);
+
+ connect(ui_->activateOrDeactiveButton, &QPushButton::clicked, this, [=]() {
+ auto module_id = ui_->moduleListView->GetCurrentModuleID();
+ if (module_id.isEmpty()) return;
+
+ if (!module_manager_->IsModuleActivated(module_id)) {
+ module_manager_->ActiveModule(module_id);
+ } else {
+ module_manager_->DeactiveModule(module_id);
+ }
+
+ QTimer::singleShot(1000, [=]() { slot_load_module_details(module_id); });
+ });
+
+ connect(ui_->autoActivateButton, &QPushButton::clicked, this, [=]() {
+ auto module_id = ui_->moduleListView->GetCurrentModuleID();
+ SettingsObject so(QString("module.%1.so").arg(module_id));
+ ModuleSO module_so(so);
+
+ module_so.auto_activate =
+ ui_->autoActivateButton->text() == tr("Enable Auto Activate");
+ so.Store(module_so.ToJson());
+
+ QTimer::singleShot(1000, [=]() { slot_load_module_details(module_id); });
+ });
+
+ connect(ui_->triggerEventButton, &QPushButton::clicked, this, [=]() {
+ auto event_id =
+ QInputDialog::getText(this, "Please provide an Event ID", "Event ID");
+ Module::TriggerEvent(event_id);
+ });
+
+ connect(ui_->showModsDirButton, &QPushButton::clicked, this, [=]() {
+ QDesktopServices::openUrl(QUrl::fromLocalFile(
+ GlobalSettingStation::GetInstance().GetModulesDir()));
+ });
+
+#ifdef RELEASE
+ ui_->tabWidget->setTabEnabled(2, false);
+#endif
+}
+
+void ModuleControllerDialog::slot_load_module_details(
+ Module::ModuleIdentifier module_id) {
+ GF_UI_LOG_DEBUG("loading module details, module id: {}", module_id);
+ auto module = module_manager_->SearchModule(module_id);
+ SettingsObject so(QString("module.%1.so").arg(module_id));
+ ModuleSO module_so(so);
+
+ if (module_id.isEmpty() || module == nullptr) {
+ ui_->actionsGroupBox->hide();
+ return;
+ }
+
+ ui_->actionsGroupBox->show();
+
+ if (module_so.module_id != module_id ||
+ module_so.module_hash != module->GetModuleHash()) {
+ module_so.module_id = module_id;
+ module_so.module_hash = module->GetModuleHash();
+ module_so.auto_activate = false;
+ GF_UI_LOG_DEBUG("reseting module settings object, module id: {}",
+ module_id);
+ so.Store(module_so.ToJson());
+ }
+
+ QString buffer;
+ QTextStream info(&buffer);
+
+ info << "# " << tr("BASIC INFO") << Qt::endl << Qt::endl;
+
+ info << " - " << tr("ID") << ": " << module->GetModuleIdentifier()
+ << Qt::endl;
+ info << " - " << tr("Version") << ": " << module->GetModuleVersion()
+ << Qt::endl;
+ info << " - " << tr("SDK Version") << ": " << module->GetModuleSDKVersion()
+ << Qt::endl;
+ info << " - " << tr("Qt ENV Version") << ": "
+ << module->GetModuleQtEnvVersion() << Qt::endl;
+ info << " - " << tr("Hash") << ": " << module->GetModuleHash() << Qt::endl;
+ info << " - " << tr("Path") << ": " << module->GetModulePath() << Qt::endl;
+
+ auto if_activated = module_manager_->IsModuleActivated(module_id);
+
+ info << " - " << tr("Auto Activate") << ": "
+ << (module_so.auto_activate ? tr("True") : tr("False")) << Qt::endl;
+ info << " - " << tr("Active") << ": "
+ << (if_activated ? tr("True") : tr("False")) << Qt::endl;
+
+ info << Qt::endl;
+
+ info << "# " << tr("METADATA") << Qt::endl << Qt::endl;
+
+#ifdef QT5_BUILD
+ auto map = module->GetModuleMetaData();
+ for (auto it = map.keyValueBegin(); it != map.keyValueEnd(); ++it) {
+ info << " - " << it->first << ": " << it->second << "\n";
+ }
+#else
+ for (const auto& metadata : module->GetModuleMetaData().asKeyValueRange()) {
+ info << " - " << metadata.first << ": " << metadata.second << "\n";
+ }
+#endif
+
+ info << Qt::endl;
+
+ if (if_activated) {
+ info << "# " << tr("Listening Event") << Qt::endl << Qt::endl;
+
+ auto listening_event_ids = module_manager_->GetModuleListening(module_id);
+ for (const auto& event_id : listening_event_ids) {
+ info << " - " << event_id << "\n";
+ }
+ }
+
+ ui_->moduleInfoTextBrowser->setText(buffer);
+ ui_->activateOrDeactiveButton->setText(if_activated ? tr("Deactivate")
+ : tr("Activate"));
+ ui_->autoActivateButton->setText(module_so.auto_activate
+ ? tr("Disable Auto Activate")
+ : tr("Enable Auto Activate"));
+}
+} // namespace GpgFrontend::UI
diff --git a/src/module/integrated/gnupg_info_gathering_module/GnuPGInfoGatheringModule.h b/src/ui/dialog/controller/ModuleControllerDialog.h
index 88f64d7d..6ded4808 100644
--- a/src/module/integrated/gnupg_info_gathering_module/GnuPGInfoGatheringModule.h
+++ b/src/ui/dialog/controller/ModuleControllerDialog.h
@@ -28,28 +28,34 @@
#pragma once
-#include "GpgFrontendModuleExport.h"
#include "core/module/Module.h"
-namespace GpgFrontend::Module::Integrated::GnuPGInfoGatheringModule {
+class Ui_ModuleControllerDialog;
-/**
- * @brief Use to record some info about gnupg
- *
- */
-class GPGFRONTEND_INTEGRATED_MODULE_GNUPG_INFO_GATHERING_EXPORT
- GnuPGInfoGatheringModule : public Module {
- public:
- GnuPGInfoGatheringModule();
-
- ~GnuPGInfoGatheringModule() override;
+namespace GpgFrontend::UI {
- auto Register() -> bool override;
+class ModuleListView;
- auto Active() -> bool override;
-
- auto Exec(EventRefrernce) -> int override;
-
- auto Deactive() -> bool override;
+class ModuleControllerDialog : public QDialog {
+ Q_OBJECT
+ public:
+ /**
+ * @brief Construct a new Module Controller Dialog object
+ *
+ * @param parent
+ */
+ explicit ModuleControllerDialog(QWidget* parent);
+
+ private slots:
+ /**
+ * @brief
+ *
+ */
+ void slot_load_module_details(Module::ModuleIdentifier);
+
+ private:
+ std::shared_ptr<Ui_ModuleControllerDialog> ui_; ///<
+ Module::ModuleManager* module_manager_;
};
-} // namespace GpgFrontend::Module::Integrated::GnuPGInfoGatheringModule
+
+} // namespace GpgFrontend::UI