diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/core/model/GpgKeyTableProxyModel.cpp | 30 | ||||
-rw-r--r-- | src/core/model/GpgKeyTableProxyModel.h | 8 | ||||
-rw-r--r-- | src/core/model/KeyDatabaseInfo.h | 41 | ||||
-rw-r--r-- | src/core/struct/cache_object/AllFavoriteKeyPairsCO.h | 74 | ||||
-rw-r--r-- | src/core/struct/cache_object/FavoriteKeyPairsByKeyDatabaseCO.h | 58 | ||||
-rw-r--r-- | src/core/utils/GpgUtils.cpp | 42 | ||||
-rw-r--r-- | src/core/utils/GpgUtils.h | 15 | ||||
-rw-r--r-- | src/ui/UserInterfaceUtils.cpp | 59 | ||||
-rw-r--r-- | src/ui/UserInterfaceUtils.h | 9 | ||||
-rw-r--r-- | src/ui/main_window/MainWindow.h | 4 | ||||
-rw-r--r-- | src/ui/main_window/MainWindowSlotFunction.cpp | 16 | ||||
-rw-r--r-- | src/ui/main_window/MainWindowUI.cpp | 18 | ||||
-rw-r--r-- | src/ui/widgets/KeyList.cpp | 18 |
13 files changed, 326 insertions, 66 deletions
diff --git a/src/core/model/GpgKeyTableProxyModel.cpp b/src/core/model/GpgKeyTableProxyModel.cpp index 49ce211f..9e23b707 100644 --- a/src/core/model/GpgKeyTableProxyModel.cpp +++ b/src/core/model/GpgKeyTableProxyModel.cpp @@ -33,6 +33,8 @@ #include "core/function/gpg/GpgKeyGetter.h" #include "core/model/CacheObject.h" #include "core/model/GpgKey.h" +#include "core/struct/cache_object/AllFavoriteKeyPairsCO.h" +#include "core/utils/GpgUtils.h" namespace GpgFrontend { @@ -77,8 +79,12 @@ auto GpgKeyTableProxyModel::filterAcceptsRow( if (!custom_filter_(key)) return false; + if (display_mode_ & GpgKeyTableDisplayMode::kFAVORITES) { + LOG_D() << "kFAVORITES Mode" << "key id" << key_id << "favorite_key_ids_" + << favorite_key_ids_; + } if (display_mode_ & GpgKeyTableDisplayMode::kFAVORITES && - !favorite_fingerprints_.contains(key.GetFingerprint())) { + !favorite_key_ids_.contains(key_id)) { return false; } @@ -159,15 +165,7 @@ void GpgKeyTableProxyModel::SetSearchKeywords(const QString &keywords) { } void GpgKeyTableProxyModel::slot_update_favorites() { - // load cache - auto json_data = CacheObject("favourite_key_pair"); - if (!json_data.isArray()) return; - - auto key_fprs = json_data.array(); - for (const auto &key_fpr : key_fprs) { - if (key_fpr.isString()) favorite_fingerprints_.append(key_fpr.toString()); - } - + slot_update_favorites_cache(); invalidateFilter(); } @@ -185,6 +183,18 @@ void GpgKeyTableProxyModel::slot_update_column_type( void GpgKeyTableProxyModel::ResetGpgKeyTableModel( QSharedPointer<GpgKeyTableModel> model) { model_ = std::move(model); + slot_update_favorites_cache(); setSourceModel(model_.get()); } + +void GpgKeyTableProxyModel::slot_update_favorites_cache() { + auto json_data = CacheObject("all_favorite_key_pairs"); + auto cache_obj = AllFavoriteKeyPairsCO(json_data.object()); + + auto key_db_name = GetGpgKeyDatabaseName(model_->GetGpgContextChannel()); + + if (cache_obj.key_dbs.contains(key_db_name)) { + favorite_key_ids_ = cache_obj.key_dbs[key_db_name].key_ids; + } +} } // namespace GpgFrontend
\ No newline at end of file diff --git a/src/core/model/GpgKeyTableProxyModel.h b/src/core/model/GpgKeyTableProxyModel.h index 6f31aa16..573d938b 100644 --- a/src/core/model/GpgKeyTableProxyModel.h +++ b/src/core/model/GpgKeyTableProxyModel.h @@ -84,12 +84,18 @@ class GPGFRONTEND_CORE_EXPORT GpgKeyTableProxyModel */ void slot_update_column_type(GpgKeyTableColumn); + /** + * @brief + * + */ + void slot_update_favorites_cache(); + private: QSharedPointer<GpgKeyTableModel> model_; GpgKeyTableDisplayMode display_mode_; GpgKeyTableColumn filter_columns_; QString filter_keywords_; - QList<QString> favorite_fingerprints_; + QList<QString> favorite_key_ids_; KeyFilter custom_filter_; }; diff --git a/src/core/model/KeyDatabaseInfo.h b/src/core/model/KeyDatabaseInfo.h new file mode 100644 index 00000000..b5bfc1ea --- /dev/null +++ b/src/core/model/KeyDatabaseInfo.h @@ -0,0 +1,41 @@ +/** + * 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 + +namespace GpgFrontend { + +struct KeyDatabaseInfo { + int channel; + QString name; + QString path; + + KeyDatabaseInfo() = default; +}; + +} // namespace GpgFrontend
\ No newline at end of file diff --git a/src/core/struct/cache_object/AllFavoriteKeyPairsCO.h b/src/core/struct/cache_object/AllFavoriteKeyPairsCO.h new file mode 100644 index 00000000..1086e2e6 --- /dev/null +++ b/src/core/struct/cache_object/AllFavoriteKeyPairsCO.h @@ -0,0 +1,74 @@ +/** + * 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 "FavoriteKeyPairsByKeyDatabaseCO.h" + +namespace GpgFrontend { + +struct AllFavoriteKeyPairsCO { + QMap<QString, FavoriteKeyPairsByKeyDatabaseCO> key_dbs; + + explicit AllFavoriteKeyPairsCO(const QJsonObject& j) { + if (j.contains("key_dbs") && j["key_dbs"].isArray()) { + for (const auto& o : j["key_dbs"].toArray()) { + if (!o.isObject()) continue; + auto mapping = o.toObject(); + + if (!mapping.contains("key_db_name") || !mapping.contains("key_db")) { + continue; + } + + if (!mapping["key_db_name"].isString() || + !mapping["key_db"].isObject()) { + continue; + } + + key_dbs.insert( + mapping["key_db_name"].toString(), + FavoriteKeyPairsByKeyDatabaseCO(mapping["key_db"].toObject())); + } + } + } + + [[nodiscard]] auto ToJson() const -> QJsonObject { + QJsonObject j; + auto j_key_dbs = QJsonArray(); + for (const auto& k : key_dbs.asKeyValueRange()) { + QJsonObject o; + o["key_db_name"] = k.first; + o["key_db"] = k.second.ToJson(); + j_key_dbs.append(o); + } + j["key_dbs"] = j_key_dbs; + return j; + } +}; + +} // namespace GpgFrontend
\ No newline at end of file diff --git a/src/core/struct/cache_object/FavoriteKeyPairsByKeyDatabaseCO.h b/src/core/struct/cache_object/FavoriteKeyPairsByKeyDatabaseCO.h new file mode 100644 index 00000000..4722dd56 --- /dev/null +++ b/src/core/struct/cache_object/FavoriteKeyPairsByKeyDatabaseCO.h @@ -0,0 +1,58 @@ +/** + * 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 + +namespace GpgFrontend { + +struct FavoriteKeyPairsByKeyDatabaseCO { + QList<QString> key_ids; + + FavoriteKeyPairsByKeyDatabaseCO() = default; + + explicit FavoriteKeyPairsByKeyDatabaseCO(const QJsonObject& j) { + if (!j.contains("key_ids") || !j["key_ids"].isArray()) return; + for (const auto& i : j["key_ids"].toArray()) { + if (!i.isString()) continue; + + key_ids.append(i.toString()); + } + } + + [[nodiscard]] auto ToJson() const -> QJsonObject { + QJsonObject j; + auto a = QJsonArray(); + for (const auto& k : key_ids) { + a.push_back(k); + } + j["key_ids"] = a; + return j; + } +}; + +} // namespace GpgFrontend
\ No newline at end of file diff --git a/src/core/utils/GpgUtils.cpp b/src/core/utils/GpgUtils.cpp index 3d584b8f..8d337d66 100644 --- a/src/core/utils/GpgUtils.cpp +++ b/src/core/utils/GpgUtils.cpp @@ -28,6 +28,9 @@ #include "GpgUtils.h" +#include "core/model/KeyDatabaseInfo.h" +#include "core/module/ModuleManager.h" + namespace GpgFrontend { inline auto Trim(QString& s) -> QString { return s.trimmed(); } @@ -169,4 +172,43 @@ auto SetExtensionOfOutputFileForArchive(const QString& path, GpgOperation opera, return file_info.absolutePath() + "/" + file_info.baseName(); } +static QList<KeyDatabaseInfo> gpg_key_database_info_cache; + +auto GPGFRONTEND_CORE_EXPORT GetGpgKeyDatabaseInfos() + -> QList<KeyDatabaseInfo> { + if (!gpg_key_database_info_cache.empty()) return gpg_key_database_info_cache; + + auto context_index_list = Module::ListRTChildKeys("core", "gpgme.ctx.list"); + gpg_key_database_info_cache.resize( + static_cast<qsizetype>(context_index_list.size())); + + 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{}); + auto database_path = Module::RetrieveRTValueTypedOrDefault( + "core", grt_key_prefix + ".database_path", QString{}); + + LOG_D() << "context grt channel: " << channel + << "GRT key prefix: " << grt_key_prefix + << "database name: " << database_name; + + auto i = KeyDatabaseInfo(); + i.channel = channel; + i.name = database_name; + i.path = database_path; + gpg_key_database_info_cache[channel] = i; + } + + return gpg_key_database_info_cache; +} +auto GPGFRONTEND_CORE_EXPORT GetGpgKeyDatabaseName(int channel) -> QString { + auto info = GetGpgKeyDatabaseInfos(); + if (channel >= info.size()) return {}; + return info[channel].name; +} } // namespace GpgFrontend diff --git a/src/core/utils/GpgUtils.h b/src/core/utils/GpgUtils.h index a12fcbf2..3cdef574 100644 --- a/src/core/utils/GpgUtils.h +++ b/src/core/utils/GpgUtils.h @@ -29,6 +29,7 @@ #pragma once #include "core/function/result_analyse/GpgResultAnalyse.h" +#include "core/model/KeyDatabaseInfo.h" #include "core/typedef/CoreTypedef.h" #include "core/typedef/GpgTypedef.h" @@ -105,4 +106,18 @@ auto GPGFRONTEND_CORE_EXPORT SetExtensionOfOutputFile(const QString& path, auto GPGFRONTEND_CORE_EXPORT SetExtensionOfOutputFileForArchive( const QString& path, GpgOperation opera, bool ascii) -> QString; +/** + * @brief + * + * @return QList<KeyDatabaseItemSO> + */ +auto GPGFRONTEND_CORE_EXPORT GetGpgKeyDatabaseInfos() -> QList<KeyDatabaseInfo>; + +/** + * @brief + * + * @return QList<KeyDatabaseItemSO> + */ +auto GPGFRONTEND_CORE_EXPORT GetGpgKeyDatabaseName(int channel) -> QString; + } // namespace GpgFrontend
\ No newline at end of file diff --git a/src/ui/UserInterfaceUtils.cpp b/src/ui/UserInterfaceUtils.cpp index 13298d2c..040a57a7 100644 --- a/src/ui/UserInterfaceUtils.cpp +++ b/src/ui/UserInterfaceUtils.cpp @@ -38,6 +38,7 @@ #include "core/model/GpgImportInformation.h" #include "core/model/SettingsObject.h" #include "core/module/ModuleManager.h" +#include "core/struct/cache_object/AllFavoriteKeyPairsCO.h" #include "core/thread/Task.h" #include "core/thread/TaskRunnerGetter.h" #include "core/typedef/GpgTypedef.h" @@ -523,43 +524,53 @@ auto CommonUtils::isApplicationNeedRestart() -> bool { return application_need_to_restart_at_once_; } -auto CommonUtils::KeyExistsinFavouriteList(const GpgKey &key) -> bool { +auto CommonUtils::KeyExistsInFavoriteList(const QString &key_db_name, + const GpgKey &key) -> bool { // load cache - auto json_data = CacheObject("favourite_key_pair"); - if (!json_data.isArray()) json_data.setArray(QJsonArray()); + auto json_data = CacheObject("all_favorite_key_pairs"); + auto cache_obj = AllFavoriteKeyPairsCO(json_data.object()); - auto key_fpr_array = json_data.array(); - return std::find(key_fpr_array.begin(), key_fpr_array.end(), - key.GetFingerprint()) != key_fpr_array.end(); + if (!cache_obj.key_dbs.contains(key_db_name)) return false; + + auto &key_ids = cache_obj.key_dbs[key_db_name].key_ids; + + return key_ids.contains(key.GetId()); } -void CommonUtils::AddKey2Favourtie(const GpgKey &key) { +void CommonUtils::AddKey2Favorite(const QString &key_db_name, + const GpgKey &key) { { - auto json_data = CacheObject("favourite_key_pair"); - QJsonArray key_array; - if (json_data.isArray()) key_array = json_data.array(); + auto json_data = CacheObject("all_favorite_key_pairs"); + auto cache_obj = AllFavoriteKeyPairsCO(json_data.object()); + + if (!cache_obj.key_dbs.contains(key_db_name)) { + cache_obj.key_dbs[key_db_name] = FavoriteKeyPairsByKeyDatabaseCO(); + } - key_array.push_back(key.GetFingerprint()); - json_data.setArray(key_array); + auto &key_ids = cache_obj.key_dbs[key_db_name].key_ids; + if (!key_ids.contains(key.GetId())) key_ids.append(key.GetId()); + + json_data.setObject(cache_obj.ToJson()); + LOG_D() << "current favorite key pairs: " << json_data; } emit SignalFavoritesChanged(); } -void CommonUtils::RemoveKeyFromFavourite(const GpgKey &key) { +void CommonUtils::RemoveKeyFromFavorite(const QString &key_db_name, + const GpgKey &key) { { - auto json_data = CacheObject("favourite_key_pair"); - QJsonArray key_array; - if (json_data.isArray()) key_array = json_data.array(); - - auto fingerprint = key.GetFingerprint(); - QJsonArray new_key_array; - for (auto &&item : key_array) { - if (item.isString() && item.toString() != fingerprint) { - new_key_array.append(item); - } + auto json_data = CacheObject("all_favorite_key_pairs"); + auto cache_obj = AllFavoriteKeyPairsCO(json_data.object()); + + if (!cache_obj.key_dbs.contains(key_db_name)) return; + + QMutableListIterator<QString> i(cache_obj.key_dbs[key_db_name].key_ids); + while (i.hasNext()) { + if (i.next() == key.GetId()) i.remove(); } - json_data.setArray(new_key_array); + json_data.setObject(cache_obj.ToJson()); + LOG_D() << "current favorite key pairs: " << json_data; } emit SignalFavoritesChanged(); diff --git a/src/ui/UserInterfaceUtils.h b/src/ui/UserInterfaceUtils.h index 6a99659b..fd5de9de 100644 --- a/src/ui/UserInterfaceUtils.h +++ b/src/ui/UserInterfaceUtils.h @@ -163,25 +163,26 @@ class CommonUtils : public QWidget { * @brief * */ - bool isApplicationNeedRestart(); + auto isApplicationNeedRestart() -> bool; /** * @brief * */ - bool KeyExistsinFavouriteList(const GpgKey& key); + auto KeyExistsInFavoriteList(const QString& key_db_name, + const GpgKey& key) -> bool; /** * @brief * */ - void AddKey2Favourtie(const GpgKey& key); + void AddKey2Favorite(const QString& key_db_name, const GpgKey& key); /** * @brief * */ - void RemoveKeyFromFavourite(const GpgKey& key); + void RemoveKeyFromFavorite(const QString& key_db_name, const GpgKey& key); /** * @brief diff --git a/src/ui/main_window/MainWindow.h b/src/ui/main_window/MainWindow.h index 917ab85a..6a5b081e 100644 --- a/src/ui/main_window/MainWindow.h +++ b/src/ui/main_window/MainWindow.h @@ -357,12 +357,12 @@ class MainWindow : public GeneralMainWindow { /** * @details */ - void slot_add_key_2_favourite(); + void slot_add_key_2_favorite(); /** * @details */ - void slot_remove_key_from_favourite(); + void slot_remove_key_from_favorite(); /** * @details diff --git a/src/ui/main_window/MainWindowSlotFunction.cpp b/src/ui/main_window/MainWindowSlotFunction.cpp index 4cfd87d8..cea105b7 100644 --- a/src/ui/main_window/MainWindowSlotFunction.cpp +++ b/src/ui/main_window/MainWindowSlotFunction.cpp @@ -216,7 +216,7 @@ void MainWindow::slot_show_key_details() { } } -void MainWindow::slot_add_key_2_favourite() { +void MainWindow::slot_add_key_2_favorite() { auto key_ids = m_key_list_->GetSelected(); if (key_ids->empty()) return; @@ -225,11 +225,16 @@ void MainWindow::slot_add_key_2_favourite() { .GetKey(key_ids->front()); if (!key.IsGood()) return; - CommonUtils::GetInstance()->AddKey2Favourtie(key); + auto key_db_name = + GetGpgKeyDatabaseName(m_key_list_->GetCurrentGpgContextChannel()); + + LOG_D() << "add key" << key.GetId() << "to favorite at key db" << key_db_name; + + CommonUtils::GetInstance()->AddKey2Favorite(key_db_name, key); emit SignalUIRefresh(); } -void MainWindow::slot_remove_key_from_favourite() { +void MainWindow::slot_remove_key_from_favorite() { auto key_ids = m_key_list_->GetSelected(); if (key_ids->empty()) return; @@ -238,7 +243,10 @@ void MainWindow::slot_remove_key_from_favourite() { .GetKey(key_ids->front()); assert(key.IsGood()); - CommonUtils::GetInstance()->RemoveKeyFromFavourite(key); + auto key_db_name = + GetGpgKeyDatabaseName(m_key_list_->GetCurrentGpgContextChannel()); + + CommonUtils::GetInstance()->RemoveKeyFromFavorite(key_db_name, key); emit SignalUIRefresh(); } diff --git a/src/ui/main_window/MainWindowUI.cpp b/src/ui/main_window/MainWindowUI.cpp index f2108c95..2163f382 100644 --- a/src/ui/main_window/MainWindowUI.cpp +++ b/src/ui/main_window/MainWindowUI.cpp @@ -30,6 +30,7 @@ #include "core/function/GlobalSettingStation.h" #include "core/function/gpg/GpgAdvancedOperator.h" #include "core/module/ModuleManager.h" +#include "core/utils/GpgUtils.h" #include "dialog/controller/ModuleControllerDialog.h" #include "ui/UserInterfaceUtils.h" #include "ui/dialog/controller/GnuPGControllerDialog.h" @@ -517,7 +518,7 @@ void MainWindow::create_actions() { add_key_2_favourite_act_->setToolTip(tr("Add this key to Favourite Table")); add_key_2_favourite_act_->setData(QVariant("add_key_2_favourite_action")); connect(add_key_2_favourite_act_, &QAction::triggered, this, - &MainWindow::slot_add_key_2_favourite); + &MainWindow::slot_add_key_2_favorite); remove_key_from_favourtie_act_ = new QAction(tr("Remove From Favourite"), this); @@ -526,7 +527,7 @@ void MainWindow::create_actions() { remove_key_from_favourtie_act_->setData( QVariant("remove_key_from_favourtie_action")); connect(remove_key_from_favourtie_act_, &QAction::triggered, this, - &MainWindow::slot_remove_key_from_favourite); + &MainWindow::slot_remove_key_from_favorite); set_owner_trust_of_key_act_ = new QAction(tr("Set Owner Trust Level"), this); set_owner_trust_of_key_act_->setToolTip(tr("Set Owner Trust Level")); @@ -723,14 +724,11 @@ void MainWindow::create_dock_windows() { return !(key.IsRevoked() || key.IsDisabled() || key.IsExpired()); }); - m_key_list_->AddListGroupTab( - tr("Favourite"), "favourite", - GpgKeyTableDisplayMode::kPUBLIC_KEY | - GpgKeyTableDisplayMode::kPRIVATE_KEY | - GpgKeyTableDisplayMode::kFAVORITES, - [](const GpgKey& key) -> bool { - return CommonUtils::GetInstance()->KeyExistsinFavouriteList(key); - }); + m_key_list_->AddListGroupTab(tr("Favourite"), "favourite", + GpgKeyTableDisplayMode::kPUBLIC_KEY | + GpgKeyTableDisplayMode::kPRIVATE_KEY | + GpgKeyTableDisplayMode::kFAVORITES, + [](const GpgKey&) -> bool { return true; }); m_key_list_->AddListGroupTab( tr("Only Public Key"), "only_public_key", diff --git a/src/ui/widgets/KeyList.cpp b/src/ui/widgets/KeyList.cpp index 5994abda..209cc4b7 100644 --- a/src/ui/widgets/KeyList.cpp +++ b/src/ui/widgets/KeyList.cpp @@ -34,6 +34,7 @@ #include "core/function/GlobalSettingStation.h" #include "core/function/gpg/GpgKeyGetter.h" #include "core/module/ModuleManager.h" +#include "core/utils/GpgUtils.h" #include "ui/UISignalStation.h" #include "ui/UserInterfaceUtils.h" #include "ui/dialog/import_export/KeyImportDetailDialog.h" @@ -76,22 +77,17 @@ void KeyList::init() { 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; + auto key_db_infos = GetGpgKeyDatabaseInfos(); - 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{}); + for (auto& key_db_info : key_db_infos) { + auto channel = key_db_info.channel; + auto key_db_name = key_db_info.name; LOG_D() << "context grt channel: " << channel - << "GRT key prefix: " << grt_key_prefix - << "database name: " << database_name; + << "database name: " << key_db_name; auto* switch_context_action = - new QAction(QString("%1: %2").arg(channel).arg(database_name), this); + new QAction(QString("%1: %2").arg(channel).arg(key_db_name), this); switch_context_action->setCheckable(true); switch_context_action->setChecked(channel == current_gpg_context_channel_); connect(switch_context_action, &QAction::toggled, this, |