diff options
Diffstat (limited to 'src/core/function/gpg/GpgKeyGetter.cpp')
-rw-r--r-- | src/core/function/gpg/GpgKeyGetter.cpp | 45 |
1 files changed, 30 insertions, 15 deletions
diff --git a/src/core/function/gpg/GpgKeyGetter.cpp b/src/core/function/gpg/GpgKeyGetter.cpp index 4a35d3cd..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<GpgKeyGetter::Impl> { public: explicit Impl(int channel) - : SingletonFunctionObject<GpgKeyGetter::Impl>(channel) { - GF_CORE_LOG_DEBUG("called channel: {}", channel); - } + : SingletonFunctionObject<GpgKeyGetter::Impl>(channel) {} auto GetKey(const QString& fpr, bool use_cache) -> GpgKey { // find in cache first @@ -56,7 +54,8 @@ class GpgKeyGetter::Impl : public SingletonFunctionObject<GpgKeyGetter::Impl> { 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<GpgKeyGetter::Impl> { 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)); } @@ -92,9 +91,23 @@ class GpgKeyGetter::Impl : public SingletonFunctionObject<GpgKeyGetter::Impl> { return keys_list; } - auto FlushKeyCache() -> bool { - GF_CORE_LOG_DEBUG("flush key channel called, channel: {}", GetChannel()); + auto FetchGpgKeyList() -> GpgKeyList { + if (keys_search_cache_.empty()) { + FlushKeyCache(); + } + auto keys_list = GpgKeyList{}; + { + // get the lock + std::lock_guard<std::mutex> lock(keys_cache_mutex_); + for (const auto& key : keys_cache_) { + keys_list.push_back(key); + } + } + return keys_list; + } + + auto FlushKeyCache() -> bool { // clear the keys cache keys_cache_.clear(); keys_search_cache_.clear(); @@ -129,17 +142,12 @@ class GpgKeyGetter::Impl : public SingletonFunctionObject<GpgKeyGetter::Impl> { } } - GF_CORE_LOG_DEBUG("flush key channel cache address: {} object address: {}", - static_cast<void*>(&keys_search_cache_), - static_cast<void*>(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; } @@ -165,6 +173,11 @@ class GpgKeyGetter::Impl : public SingletonFunctionObject<GpgKeyGetter::Impl> { return keys_copy; } + auto GetGpgKeyTableModel() -> QSharedPointer<GpgKeyTableModel> { + return SecureCreateQSharedObject<GpgKeyTableModel>(FetchGpgKeyList(), + nullptr); + } + private: /** * @brief Get the gpgme context object @@ -218,9 +231,7 @@ class GpgKeyGetter::Impl : public SingletonFunctionObject<GpgKeyGetter::Impl> { GpgKeyGetter::GpgKeyGetter(int channel) : SingletonFunctionObject<GpgKeyGetter>(channel), - p_(SecureCreateUniqueObject<Impl>(channel)) { - GF_CORE_LOG_DEBUG("called channel: {}", channel); -} + p_(SecureCreateUniqueObject<Impl>(channel)) {} GpgKeyGetter::~GpgKeyGetter() = default; @@ -248,4 +259,8 @@ auto GpgKeyGetter::GetKeysCopy(const KeyListPtr& keys) -> KeyListPtr { auto GpgKeyGetter::FetchKey() -> KeyLinkListPtr { return p_->FetchKey(); } +auto GpgKeyGetter::GetGpgKeyTableModel() -> QSharedPointer<GpgKeyTableModel> { + return p_->GetGpgKeyTableModel(); +} + } // namespace GpgFrontend |