diff options
author | saturneric <[email protected]> | 2024-11-02 15:36:57 +0000 |
---|---|---|
committer | saturneric <[email protected]> | 2024-11-02 15:36:57 +0000 |
commit | 170b29aca537fc79837939cca67f8913964445c1 (patch) | |
tree | d7858dcd485a6a9d273c76ffe7179f6a2ef2d197 /src/core/model/GpgKeyTableProxyModel.cpp | |
parent | fix: should select channel before any gpg operation (diff) | |
download | GpgFrontend-170b29aca537fc79837939cca67f8913964445c1.tar.gz GpgFrontend-170b29aca537fc79837939cca67f8913964445c1.zip |
feat: support favorite key pairs for multi key databases
Diffstat (limited to 'src/core/model/GpgKeyTableProxyModel.cpp')
-rw-r--r-- | src/core/model/GpgKeyTableProxyModel.cpp | 30 |
1 files changed, 20 insertions, 10 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 |