aboutsummaryrefslogtreecommitdiffstats
path: root/src/ui
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/UserInterfaceUtils.cpp6
-rw-r--r--src/ui/dialog/KeyDatabaseEditDialog.cpp89
-rw-r--r--src/ui/dialog/KeyDatabaseEditDialog.h60
-rw-r--r--src/ui/dialog/RevocationOptionsDialog.cpp1
-rw-r--r--src/ui/dialog/RevocationOptionsDialog.h1
-rw-r--r--src/ui/dialog/controller/GnuPGControllerDialog.cpp192
-rw-r--r--src/ui/dialog/controller/GnuPGControllerDialog.h25
-rw-r--r--src/ui/widgets/KeyList.cpp40
-rw-r--r--src/ui/widgets/KeyList.h9
-rw-r--r--src/ui/widgets/KeyTable.h6
10 files changed, 318 insertions, 111 deletions
diff --git a/src/ui/UserInterfaceUtils.cpp b/src/ui/UserInterfaceUtils.cpp
index 0f462cf7..0dfe9867 100644
--- a/src/ui/UserInterfaceUtils.cpp
+++ b/src/ui/UserInterfaceUtils.cpp
@@ -472,6 +472,7 @@ void CommonUtils::slot_update_key_status() {
[](DataObjectPtr) -> int {
// flush key cache for all GpgKeyGetter Intances.
for (const auto &channel_id : GpgKeyGetter::GetAllChannelId()) {
+ LOG_D() << "refreshing key database at channel: " << channel_id;
GpgKeyGetter::GetInstance(channel_id).FlushKeyCache();
}
return 0;
@@ -481,8 +482,9 @@ void CommonUtils::slot_update_key_status() {
&CommonUtils::SignalKeyDatabaseRefreshDone);
// post the task to the default task runner
- Thread::TaskRunnerGetter::GetInstance().GetTaskRunner()->PostTask(
- refresh_task);
+ Thread::TaskRunnerGetter::GetInstance()
+ .GetTaskRunner(Thread::TaskRunnerGetter::kTaskRunnerType_GPG)
+ ->PostTask(refresh_task);
}
void CommonUtils::slot_update_key_from_server_finished(
diff --git a/src/ui/dialog/KeyDatabaseEditDialog.cpp b/src/ui/dialog/KeyDatabaseEditDialog.cpp
new file mode 100644
index 00000000..15604f39
--- /dev/null
+++ b/src/ui/dialog/KeyDatabaseEditDialog.cpp
@@ -0,0 +1,89 @@
+/**
+ * Copyright (C) 2021-2024 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 "KeyDatabaseEditDialog.h"
+
+#include "core/utils/MemoryUtils.h"
+#include "ui_KeyDatabaseEditDialog.h"
+
+namespace GpgFrontend::UI {
+KeyDatabaseEditDialog::KeyDatabaseEditDialog(QWidget* parent)
+ : GeneralDialog("KeyDatabaseEditDialog", parent),
+ ui_(GpgFrontend::SecureCreateSharedObject<Ui_KeyDatabaseEditDialog>()) {
+ ui_->setupUi(this);
+
+ ui_->keyDBNameLabel->setText(tr("Key Database Name"));
+ ui_->keyDBPathLabel->setText(tr("Key Database Path"));
+ ui_->selectKeyDBButton->setText(tr("Select A Key Database Path"));
+
+ this->setWindowTitle(tr("Key Database Info"));
+
+ connect(ui_->selectKeyDBButton, &QPushButton::clicked, this, [this](bool) {
+ auto path = QFileDialog::getExistingDirectory(
+ this, tr("Open Directory"), {},
+ QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
+ if (!check_custom_gnupg_key_database_path(path)) {
+ QMessageBox::critical(this, tr("Illegal GnuPG Key Database Path"),
+ tr("Target GnuPG Key Database Path is not an "
+ "exists readable directory."));
+ }
+
+ path_ = QFileInfo(path).absoluteFilePath();
+ ui_->keyDBPathShowLabel->setText(path_);
+ });
+
+ connect(ui_->buttonBox, &QDialogButtonBox::accepted, this,
+ &KeyDatabaseEditDialog::slot_button_box_accepted);
+ connect(ui_->buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
+ connect(ui_->buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
+ setAttribute(Qt::WA_DeleteOnClose);
+ setModal(true);
+}
+
+void KeyDatabaseEditDialog::slot_button_box_accepted() {
+ name_ = ui_->keyDBNameLineEdit->text();
+ emit SignalKeyDatabaseInfoAccepted(name_, path_);
+}
+
+auto KeyDatabaseEditDialog::check_custom_gnupg_key_database_path(
+ const QString& path) -> bool {
+ if (path.isEmpty()) return false;
+
+ QFileInfo const dir_info(path);
+ return dir_info.exists() && dir_info.isReadable() && dir_info.isDir();
+}
+
+void KeyDatabaseEditDialog::SetDefaultName(QString name) {
+ name_ = std::move(name);
+}
+
+void KeyDatabaseEditDialog::SetDefaultPath(QString path) {
+ path_ = QFileInfo(path).absoluteFilePath();
+ ui_->keyDBPathShowLabel->setText(path_);
+}
+}; // namespace GpgFrontend::UI \ No newline at end of file
diff --git a/src/ui/dialog/KeyDatabaseEditDialog.h b/src/ui/dialog/KeyDatabaseEditDialog.h
new file mode 100644
index 00000000..287a97df
--- /dev/null
+++ b/src/ui/dialog/KeyDatabaseEditDialog.h
@@ -0,0 +1,60 @@
+/**
+ * Copyright (C) 2021-2024 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
+ *
+ */
+
+#pragma once
+
+#include <utility>
+
+#include "ui/dialog/GeneralDialog.h"
+
+class Ui_KeyDatabaseEditDialog;
+
+namespace GpgFrontend::UI {
+class KeyDatabaseEditDialog : public GeneralDialog {
+ Q_OBJECT
+ public:
+ explicit KeyDatabaseEditDialog(QWidget* parent);
+
+ void SetDefaultName(QString name);
+
+ void SetDefaultPath(QString path);
+
+ signals:
+ void SignalKeyDatabaseInfoAccepted(QString name, QString path);
+
+ private:
+ std::shared_ptr<Ui_KeyDatabaseEditDialog> ui_; ///<
+ QString name_;
+ QString path_;
+
+ void slot_button_box_accepted();
+
+ auto check_custom_gnupg_key_database_path(const QString& path) -> bool;
+};
+
+} // namespace GpgFrontend::UI \ No newline at end of file
diff --git a/src/ui/dialog/RevocationOptionsDialog.cpp b/src/ui/dialog/RevocationOptionsDialog.cpp
index e2bbba00..ea11d747 100644
--- a/src/ui/dialog/RevocationOptionsDialog.cpp
+++ b/src/ui/dialog/RevocationOptionsDialog.cpp
@@ -53,6 +53,7 @@ GpgFrontend::UI::RevocationOptionsDialog::RevocationOptionsDialog(
connect(ui_->buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
connect(ui_->buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
setAttribute(Qt::WA_DeleteOnClose);
+ setModal(true);
}
auto GpgFrontend::UI::RevocationOptionsDialog::Code() const -> int {
diff --git a/src/ui/dialog/RevocationOptionsDialog.h b/src/ui/dialog/RevocationOptionsDialog.h
index 0f404ca2..17356a4d 100644
--- a/src/ui/dialog/RevocationOptionsDialog.h
+++ b/src/ui/dialog/RevocationOptionsDialog.h
@@ -1,4 +1,3 @@
-
/**
* Copyright (C) 2021-2024 Saturneric <[email protected]>
*
diff --git a/src/ui/dialog/controller/GnuPGControllerDialog.cpp b/src/ui/dialog/controller/GnuPGControllerDialog.cpp
index 859c26aa..1ae1278b 100644
--- a/src/ui/dialog/controller/GnuPGControllerDialog.cpp
+++ b/src/ui/dialog/controller/GnuPGControllerDialog.cpp
@@ -30,9 +30,14 @@
#include "core/GpgModel.h"
#include "core/function/GlobalSettingStation.h"
+#include "core/model/SettingsObject.h"
#include "core/module/ModuleManager.h"
+#include "core/struct/settings_object/KeyDatabaseListSO.h"
#include "ui/UISignalStation.h"
#include "ui/dialog/GeneralDialog.h"
+#include "ui/dialog/KeyDatabaseEditDialog.h"
+
+//
#include "ui_GnuPGControllerDialog.h"
namespace GpgFrontend::UI {
@@ -42,9 +47,9 @@ GnuPGControllerDialog::GnuPGControllerDialog(QWidget* parent)
ui_(GpgFrontend::SecureCreateSharedObject<Ui_GnuPGControllerDialog>()) {
ui_->setupUi(this);
- ui_->generalBox->setTitle(tr("General"));
- ui_->keyDatabaseGroupBox->setTitle(tr("Key Database"));
- ui_->advanceGroupBox->setTitle(tr("Advanced"));
+ ui_->tab->setWindowTitle(tr("General"));
+ ui_->tab_2->setWindowTitle(tr("Key Database"));
+ ui_->tab_3->setWindowTitle(tr("Advanced"));
ui_->asciiModeCheckBox->setText(tr("Use Binary Mode for File Operations"));
ui_->usePinentryAsPasswordInputDialogCheckBox->setText(
@@ -52,10 +57,6 @@ 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_->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(
@@ -68,49 +69,25 @@ GnuPGControllerDialog::GnuPGControllerDialog(QWidget* parent)
tr("Tips: notice that modify any of these settings will cause an "
"Application restart."));
+ popup_menu_ = new QMenu(this);
+ popup_menu_->addAction(ui_->actionRemove_Selected_Key_Database);
+
// announce main window
connect(this, &GnuPGControllerDialog::SignalRestartNeeded,
UISignalStation::GetInstance(),
&UISignalStation::SignalRestartApplication);
- connect(ui_->keyDatabaseUseCustomCheckBox, &QCheckBox::stateChanged, this,
- [=](int state) {
- ui_->customKeyDatabasePathSelectButton->setDisabled(
- state != Qt::CheckState::Checked);
- });
-
connect(ui_->useCustomGnuPGInstallPathCheckBox, &QCheckBox::stateChanged,
this, [=](int state) {
ui_->useCustomGnuPGInstallPathButton->setDisabled(
state != Qt::CheckState::Checked);
});
- connect(ui_->keyDatabaseUseCustomCheckBox, &QCheckBox::stateChanged, this,
- &GnuPGControllerDialog::slot_update_custom_key_database_path_label);
-
connect(ui_->useCustomGnuPGInstallPathCheckBox, &QCheckBox::stateChanged,
this,
&GnuPGControllerDialog::slot_update_custom_gnupg_install_path_label);
connect(
- ui_->customKeyDatabasePathSelectButton, &QPushButton::clicked, this,
- [=]() {
- QString selected_custom_key_database_path =
- QFileDialog::getExistingDirectory(
- this, tr("Open Directory"), {},
- QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
-
- custom_key_database_path_ = selected_custom_key_database_path;
-
- // announce the restart
- this->slot_set_restart_needed(kDeepRestartCode);
-
- // update ui
- this->slot_update_custom_key_database_path_label(
- this->ui_->keyDatabaseUseCustomCheckBox->checkState());
- });
-
- connect(
ui_->useCustomGnuPGInstallPathButton, &QPushButton::clicked, this, [=]() {
QString selected_custom_gnupg_install_path =
QFileDialog::getExistingDirectory(
@@ -149,18 +126,18 @@ GnuPGControllerDialog::GnuPGControllerDialog(QWidget* parent)
this->slot_set_restart_needed(kDeepRestartCode);
});
- connect(ui_->keyDatabaseUseCustomCheckBox, &QCheckBox::stateChanged, this,
- [=](int) {
- // announce the restart
- this->slot_set_restart_needed(kDeepRestartCode);
- });
-
connect(ui_->useCustomGnuPGInstallPathCheckBox, &QCheckBox::stateChanged,
this, [=](int) {
// announce the restart
this->slot_set_restart_needed(kDeepRestartCode);
});
+ connect(ui_->addNewKeyDatabaseButton, &QPushButton::clicked, this,
+ &GnuPGControllerDialog::slot_add_new_key_database);
+
+ connect(ui_->actionRemove_Selected_Key_Database, &QAction::triggered, this,
+ &GnuPGControllerDialog::slot_remove_existing_key_database);
+
#if defined(__APPLE__) && defined(__MACH__)
// macOS style settings
ui_->buttonBox->setDisabled(true);
@@ -188,40 +165,6 @@ void GnuPGControllerDialog::SlotAccept() {
close();
}
-void GnuPGControllerDialog::slot_update_custom_key_database_path_label(
- int state) {
- // hide label (not necessary to show the default path)
- this->ui_->currentKeyDatabasePathLabel->setHidden(state !=
- Qt::CheckState::Checked);
- if (state == Qt::CheckState::Checked) {
- if (custom_key_database_path_.isEmpty()) {
- // read from settings file
- QString custom_key_database_path =
- GlobalSettingStation::GetInstance()
- .GetSettings()
- .value("gnupg/custom_key_database_path")
- .toString();
- custom_key_database_path_ = custom_key_database_path;
- }
-
- // notify the user
- if (!check_custom_gnupg_key_database_path(custom_key_database_path_)) {
- return;
- };
-
- // set label value
- if (!custom_key_database_path_.isEmpty()) {
- ui_->currentKeyDatabasePathLabel->setText(custom_key_database_path_);
- }
- }
-
- if (ui_->currentKeyDatabasePathLabel->text().isEmpty()) {
- const auto database_path = Module::RetrieveRTValueTypedOrDefault<>(
- "core", "gpgme.ctx.database_path", QString{});
- ui_->currentKeyDatabasePathLabel->setText(database_path);
- }
-}
-
void GnuPGControllerDialog::slot_update_custom_gnupg_install_path_label(
int state) {
// hide label (not necessary to show the default path)
@@ -268,12 +211,6 @@ void GnuPGControllerDialog::set_settings() {
ui_->asciiModeCheckBox->setCheckState(Qt::Checked);
}
- auto use_custom_key_database_path =
- settings.value("gnupg/use_custom_key_database_path", false).toBool();
- if (use_custom_key_database_path) {
- ui_->keyDatabaseUseCustomCheckBox->setCheckState(Qt::Checked);
- }
-
auto enable_gpgme_debug_log =
settings.value("gnupg/enable_gpgme_debug_log", false).toBool();
if (enable_gpgme_debug_log) {
@@ -286,9 +223,6 @@ void GnuPGControllerDialog::set_settings() {
ui_->killAllGnuPGDaemonCheckBox->setCheckState(Qt::Checked);
}
- this->slot_update_custom_key_database_path_label(
- ui_->keyDatabaseUseCustomCheckBox->checkState());
-
auto use_custom_gnupg_install_path =
settings.value("gnupg/use_custom_gnupg_install_path", false).toBool();
if (use_custom_gnupg_install_path) {
@@ -310,13 +244,16 @@ void GnuPGControllerDialog::set_settings() {
ui_->restartGpgAgentOnStartCheckBox->setCheckState(Qt::Checked);
}
- 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);
+
+ auto key_database_list =
+ KeyDatabaseListSO(SettingsObject("key_database_list"));
+ buffered_key_db_so_ = key_database_list.key_databases;
+
+ this->slot_refresh_key_database_table();
}
void GnuPGControllerDialog::apply_settings() {
@@ -325,22 +262,23 @@ void GnuPGControllerDialog::apply_settings() {
settings.setValue("gnupg/non_ascii_at_file_operation",
ui_->asciiModeCheckBox->isChecked());
- settings.setValue("gnupg/use_custom_key_database_path",
- ui_->keyDatabaseUseCustomCheckBox->isChecked());
settings.setValue("gnupg/use_custom_gnupg_install_path",
ui_->useCustomGnuPGInstallPathCheckBox->isChecked());
settings.setValue("gnupg/use_pinentry_as_password_input_dialog",
ui_->usePinentryAsPasswordInputDialogCheckBox->isChecked());
settings.setValue("gnupg/enable_gpgme_debug_log",
ui_->gpgmeDebugLogCheckBox->isChecked());
- settings.setValue("gnupg/custom_key_database_path",
- ui_->currentKeyDatabasePathLabel->text());
settings.setValue("gnupg/custom_gnupg_install_path",
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 so = SettingsObject("key_database_list");
+ auto key_database_list = KeyDatabaseListSO(so);
+ key_database_list.key_databases = buffered_key_db_so_;
+ so.Store(key_database_list.ToJson());
}
auto GnuPGControllerDialog::get_restart_needed() const -> int {
@@ -384,19 +322,73 @@ auto GnuPGControllerDialog::check_custom_gnupg_path(QString path) -> bool {
return true;
}
-auto GnuPGControllerDialog::check_custom_gnupg_key_database_path(QString path)
- -> bool {
- if (path.isEmpty()) return false;
+void GnuPGControllerDialog::slot_add_new_key_database() {
+ auto* dialog = new KeyDatabaseEditDialog(this);
+ connect(dialog, &KeyDatabaseEditDialog::SignalKeyDatabaseInfoAccepted, this,
+ [this](const QString& name, const QString& path) {
+ auto& key_databases = buffered_key_db_so_;
+ for (const auto& key_database : key_databases) {
+ if (QFileInfo(key_database.path) == QFileInfo(path)) {
+ QMessageBox::warning(
+ this, tr("Duplicate Key Database Paths"),
+ tr("The newly added key database path duplicates a "
+ "previously existing one."));
+ return;
+ }
+ }
+
+ LOG_D() << "new key database path, name: " << name
+ << "path: " << path;
+
+ KeyDatabaseItemSO key_database;
+ key_database.name = name;
+ key_database.path = path;
+ key_databases.append(key_database);
+
+ slot_refresh_key_database_table();
+ });
+ dialog->show();
+}
- 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 "
- "exists readable directory."));
- return false;
+void GnuPGControllerDialog::slot_refresh_key_database_table() {
+ auto key_databases = buffered_key_db_so_;
+ ui_->keyDatabaseTable->setRowCount(static_cast<int>(key_databases.size()));
+
+ int index = 0;
+ for (const auto& key_database : key_databases) {
+ LOG_D() << "key database table item index: " << index
+ << "name: " << key_database.name << "path: " << key_database.path;
+
+ auto* i_name = new QTableWidgetItem(key_database.name);
+ i_name->setTextAlignment(Qt::AlignCenter);
+ ui_->keyDatabaseTable->setItem(index, 0, i_name);
+
+ ui_->keyDatabaseTable->setItem(index, 1,
+ new QTableWidgetItem(key_database.path));
+
+ index++;
}
+ ui_->keyDatabaseTable->resizeColumnsToContents();
+}
- return true;
+void GnuPGControllerDialog::contextMenuEvent(QContextMenuEvent* event) {
+ QDialog::contextMenuEvent(event);
+ if (ui_->keyDatabaseTable->selectedItems().length() > 0) {
+ popup_menu_->exec(event->globalPos());
+ }
}
+void GnuPGControllerDialog::slot_remove_existing_key_database() {
+ const auto row_size = ui_->keyDatabaseTable->rowCount();
+
+ auto& key_databases = buffered_key_db_so_;
+ for (int i = 0; i < row_size; i++) {
+ auto* const item = ui_->keyDatabaseTable->item(i, 1);
+ if (!item->isSelected()) continue;
+ key_databases.remove(i);
+ break;
+ }
+
+ this->slot_refresh_key_database_table();
+}
} // namespace GpgFrontend::UI
diff --git a/src/ui/dialog/controller/GnuPGControllerDialog.h b/src/ui/dialog/controller/GnuPGControllerDialog.h
index ab2f305c..37ec2f62 100644
--- a/src/ui/dialog/controller/GnuPGControllerDialog.h
+++ b/src/ui/dialog/controller/GnuPGControllerDialog.h
@@ -28,6 +28,7 @@
#pragma once
+#include "core/struct/settings_object/KeyDatabaseItemSO.h"
#include "ui/dialog/GeneralDialog.h"
class Ui_GnuPGControllerDialog;
@@ -73,19 +74,33 @@ class GnuPGControllerDialog : public GeneralDialog {
* @brief
*
*/
- void slot_update_custom_key_database_path_label(int state);
+ void slot_update_custom_gnupg_install_path_label(int state);
/**
* @brief
*
*/
- void slot_update_custom_gnupg_install_path_label(int state);
+ void slot_add_new_key_database();
+
+ /**
+ * @brief
+ *
+ */
+ void slot_remove_existing_key_database();
+
+ /**
+ * @brief
+ *
+ */
+ void slot_refresh_key_database_table();
private:
std::shared_ptr<Ui_GnuPGControllerDialog> ui_; ///<
int restart_mode_{0}; ///<
QString custom_key_database_path_;
QString custom_gnupg_path_;
+ QMenu* popup_menu_{};
+ QList<KeyDatabaseItemSO> buffered_key_db_so_;
/**
* @brief Get the Restart Needed object
@@ -115,12 +130,12 @@ class GnuPGControllerDialog : public GeneralDialog {
*/
auto check_custom_gnupg_path(QString) -> bool;
+ protected:
/**
* @brief
*
- * @return true
- * @return false
+ * @param event
*/
- auto check_custom_gnupg_key_database_path(QString) -> bool;
+ void contextMenuEvent(QContextMenuEvent* event) override;
};
} // namespace GpgFrontend::UI
diff --git a/src/ui/widgets/KeyList.cpp b/src/ui/widgets/KeyList.cpp
index a9363e19..ff6f4e22 100644
--- a/src/ui/widgets/KeyList.cpp
+++ b/src/ui/widgets/KeyList.cpp
@@ -33,6 +33,7 @@
#include "core/function/GlobalSettingStation.h"
#include "core/function/gpg/GpgKeyGetter.h"
+#include "core/module/ModuleManager.h"
#include "ui/UISignalStation.h"
#include "ui/UserInterfaceUtils.h"
#include "ui/dialog/import_export/KeyImportDetailDialog.h"
@@ -69,6 +70,37 @@ void KeyList::init() {
KeyMenuAbility::kCOLUMN_FILTER);
ui_->searchBarEdit->setHidden(~menu_ability_ & KeyMenuAbility::kSEARCH_BAR);
+ auto* gpg_context_menu = new QMenu(this);
+ auto* gpg_context_groups = new QActionGroup(this);
+ gpg_context_groups->setExclusive(true);
+ auto context_index_list = Module::ListRTChildKeys("core", "gpgme.ctx.list");
+ for (auto& context_index : context_index_list) {
+ LOG_D() << "context grt key: " << context_index;
+
+ const auto grt_key_prefix = QString("gpgme.ctx.list.%1").arg(context_index);
+ auto channel = Module::RetrieveRTValueTypedOrDefault(
+ "core", grt_key_prefix + ".channel", -1);
+ auto database_name = Module::RetrieveRTValueTypedOrDefault(
+ "core", grt_key_prefix + ".database_name", QString{});
+
+ LOG_D() << "context grt channel: " << channel
+ << "GRT key prefix: " << grt_key_prefix
+ << "database name: " << database_name;
+
+ auto* switch_context_action =
+ new QAction(QString("%1: %2").arg(channel).arg(database_name), this);
+ switch_context_action->setCheckable(true);
+ switch_context_action->setChecked(channel == current_gpg_context_channel_);
+ connect(switch_context_action, &QAction::toggled, this,
+ [this, channel](bool checked) {
+ current_gpg_context_channel_ = channel;
+ emit SignalRefreshDatabase();
+ });
+ gpg_context_groups->addAction(switch_context_action);
+ gpg_context_menu->addAction(switch_context_action);
+ }
+ ui_->switchContextButton->setMenu(gpg_context_menu);
+
auto* column_type_menu = new QMenu(this);
key_id_column_action_ = new QAction(tr("Key ID"), this);
@@ -253,7 +285,8 @@ void KeyList::SlotRefresh() {
ui_->refreshKeyListButton->setDisabled(true);
ui_->syncButton->setDisabled(true);
- model_ = GpgKeyGetter::GetInstance().GetGpgKeyTableModel();
+ model_ = GpgKeyGetter::GetInstance(current_gpg_context_channel_)
+ .GetGpgKeyTableModel();
for (int i = 0; i < ui_->keyGroupTab->count(); i++) {
auto* key_table = qobject_cast<KeyTable*>(ui_->keyGroupTab->widget(i));
@@ -261,8 +294,6 @@ void KeyList::SlotRefresh() {
}
emit SignalRefreshStatusBar(tr("Refreshing Key List..."), 3000);
- this->model_ = GpgKeyGetter::GetInstance().GetGpgKeyTableModel();
-
this->SlotRefreshUI();
}
@@ -600,4 +631,7 @@ void KeyList::UpdateKeyTableColumnType(GpgKeyTableColumn column_type) {
emit SignalColumnTypeChange(fixed_columns_filter_ & global_column_filter_);
}
+auto KeyList::GetCurrentGpgContextChannel() const -> int {
+ return current_gpg_context_channel_;
+}
} // namespace GpgFrontend::UI
diff --git a/src/ui/widgets/KeyList.h b/src/ui/widgets/KeyList.h
index 8563df8f..47c4d2a1 100644
--- a/src/ui/widgets/KeyList.h
+++ b/src/ui/widgets/KeyList.h
@@ -209,6 +209,13 @@ class KeyList : public QWidget {
*/
void UpdateKeyTableColumnType(GpgKeyTableColumn);
+ /**
+ * @brief
+ *
+ * @return int
+ */
+ [[nodiscard]] auto GetCurrentGpgContextChannel() const -> int;
+
signals:
/**
* @brief
@@ -293,6 +300,8 @@ class KeyList : public QWidget {
QAction* subkeys_number_column_action_;
QAction* comment_column_action_;
+ int current_gpg_context_channel_ = kGpgFrontendDefaultChannel;
+
private slots:
/**
diff --git a/src/ui/widgets/KeyTable.h b/src/ui/widgets/KeyTable.h
index 11aca803..a03a1c83 100644
--- a/src/ui/widgets/KeyTable.h
+++ b/src/ui/widgets/KeyTable.h
@@ -166,6 +166,12 @@ struct KeyTable : public QTableView {
*/
void SignalColumnTypeChange(GpgKeyTableColumn);
+ /**
+ * @brief
+ *
+ */
+ void SignalGpgContextChannelChange(int);
+
private:
QSharedPointer<GpgKeyTableModel> model_;
GpgKeyTableProxyModel proxy_model_;