From e7694f9a0729cb88064eda6623c99070f5a46dc0 Mon Sep 17 00:00:00 2001 From: saturneric Date: Sun, 2 Jun 2024 22:03:59 +0200 Subject: feat: rewrite key list structure and logic --- src/core/function/gpg/GpgKeyGetter.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'src/core/function/gpg/GpgKeyGetter.cpp') diff --git a/src/core/function/gpg/GpgKeyGetter.cpp b/src/core/function/gpg/GpgKeyGetter.cpp index 4a35d3cd..870e68b3 100644 --- a/src/core/function/gpg/GpgKeyGetter.cpp +++ b/src/core/function/gpg/GpgKeyGetter.cpp @@ -92,6 +92,22 @@ class GpgKeyGetter::Impl : public SingletonFunctionObject { return keys_list; } + auto FetchGpgKeyList() -> GpgKeyList { + if (keys_search_cache_.empty()) { + FlushKeyCache(); + } + + auto keys_list = GpgKeyList{}; + { + // get the lock + std::lock_guard lock(keys_cache_mutex_); + for (const auto& key : keys_cache_) { + keys_list.push_back(key); + } + } + return keys_list; + } + auto FlushKeyCache() -> bool { GF_CORE_LOG_DEBUG("flush key channel called, channel: {}", GetChannel()); @@ -165,6 +181,11 @@ class GpgKeyGetter::Impl : public SingletonFunctionObject { return keys_copy; } + auto GetGpgKeyTableModel() -> QSharedPointer { + return SecureCreateQSharedObject(FetchGpgKeyList(), + nullptr); + } + private: /** * @brief Get the gpgme context object @@ -248,4 +269,8 @@ auto GpgKeyGetter::GetKeysCopy(const KeyListPtr& keys) -> KeyListPtr { auto GpgKeyGetter::FetchKey() -> KeyLinkListPtr { return p_->FetchKey(); } +auto GpgKeyGetter::GetGpgKeyTableModel() -> QSharedPointer { + return p_->GetGpgKeyTableModel(); +} + } // namespace GpgFrontend -- cgit v1.2.3 From 37a62a8d0b590710b902376ca3320cc05e954b63 Mon Sep 17 00:00:00 2001 From: saturneric Date: Fri, 26 Jul 2024 18:24:34 +0200 Subject: feat: remove spdlog and clean up log --- src/core/function/gpg/GpgKeyGetter.cpp | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) (limited to 'src/core/function/gpg/GpgKeyGetter.cpp') diff --git a/src/core/function/gpg/GpgKeyGetter.cpp b/src/core/function/gpg/GpgKeyGetter.cpp index 870e68b3..8b78b754 100644 --- a/src/core/function/gpg/GpgKeyGetter.cpp +++ b/src/core/function/gpg/GpgKeyGetter.cpp @@ -42,9 +42,7 @@ namespace GpgFrontend { class GpgKeyGetter::Impl : public SingletonFunctionObject { public: explicit Impl(int channel) - : SingletonFunctionObject(channel) { - GF_CORE_LOG_DEBUG("called channel: {}", channel); - } + : SingletonFunctionObject(channel) {} auto GetKey(const QString& fpr, bool use_cache) -> GpgKey { // find in cache first @@ -56,7 +54,8 @@ class GpgKeyGetter::Impl : public SingletonFunctionObject { gpgme_key_t p_key = nullptr; gpgme_get_key(ctx_.DefaultContext(), fpr.toUtf8(), &p_key, 1); if (p_key == nullptr) { - GF_CORE_LOG_WARN("GpgKeyGetter GetKey Private _p_key Null fpr", fpr); + qCWarning(core) << "GpgKeyGetter GetKey Private _p_key Null, fpr: " + << fpr; return GetPubkey(fpr, true); } return GpgKey(std::move(p_key)); @@ -72,7 +71,7 @@ class GpgKeyGetter::Impl : public SingletonFunctionObject { gpgme_key_t p_key = nullptr; gpgme_get_key(ctx_.DefaultContext(), fpr.toUtf8(), &p_key, 0); if (p_key == nullptr) - GF_CORE_LOG_WARN("GpgKeyGetter GetKey _p_key Null", fpr); + qCWarning(core) << "GpgKeyGetter GetKey _p_key Null, fpr: " << fpr; return GpgKey(std::move(p_key)); } @@ -109,8 +108,6 @@ class GpgKeyGetter::Impl : public SingletonFunctionObject { } auto FlushKeyCache() -> bool { - GF_CORE_LOG_DEBUG("flush key channel called, channel: {}", GetChannel()); - // clear the keys cache keys_cache_.clear(); keys_search_cache_.clear(); @@ -145,17 +142,12 @@ class GpgKeyGetter::Impl : public SingletonFunctionObject { } } - GF_CORE_LOG_DEBUG("flush key channel cache address: {} object address: {}", - static_cast(&keys_search_cache_), - static_cast(this)); - // for debug assert(CheckGpgError2ErrCode(err, GPG_ERR_EOF) == GPG_ERR_EOF); err = gpgme_op_keylist_end(ctx_.DefaultContext()); assert(CheckGpgError2ErrCode(err, GPG_ERR_EOF) == GPG_ERR_NO_ERROR); - GF_CORE_LOG_DEBUG("flush key channel done, channel: {}", GetChannel()); return true; } @@ -239,9 +231,7 @@ class GpgKeyGetter::Impl : public SingletonFunctionObject { GpgKeyGetter::GpgKeyGetter(int channel) : SingletonFunctionObject(channel), - p_(SecureCreateUniqueObject(channel)) { - GF_CORE_LOG_DEBUG("called channel: {}", channel); -} + p_(SecureCreateUniqueObject(channel)) {} GpgKeyGetter::~GpgKeyGetter() = default; -- cgit v1.2.3