File indexing completed on 2024-06-23 05:19:21
0001 /* 0002 SPDX-FileCopyrightText: 2023 Daniel Vrátil <dvratil@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "keycachememento.h" 0008 0009 #include <QTimer> 0010 0011 using namespace MimeTreeParser; 0012 0013 KeyCacheMemento::KeyCacheMemento(const std::shared_ptr<Kleo::KeyCache> &keyCache, GpgME::Protocol protocol) 0014 : m_keyCache(keyCache) 0015 , m_protocol(protocol) 0016 { 0017 } 0018 0019 KeyCacheMemento::~KeyCacheMemento() = default; 0020 0021 bool KeyCacheMemento::start() 0022 { 0023 if (m_keyCache->initialized()) { 0024 // delay completion 0025 QTimer::singleShot(0, this, &KeyCacheMemento::slotKeyCacheInitialized); 0026 } else { 0027 connect(m_keyCache.get(), &Kleo::KeyCache::keyListingDone, this, &KeyCacheMemento::slotKeyCacheInitialized); 0028 m_keyCache->startKeyListing(m_protocol); 0029 } 0030 0031 setRunning(true); 0032 return true; 0033 } 0034 0035 void KeyCacheMemento::exec() 0036 { 0037 setRunning(true); 0038 if (!m_keyCache->initialized()) { 0039 // This will start a nested eventloop internally that will block until the 0040 // key cache is initialized and can return a result. 0041 m_keyCache->findByFingerprint(""); 0042 } 0043 setRunning(false); 0044 } 0045 0046 void KeyCacheMemento::slotKeyCacheInitialized() 0047 { 0048 setRunning(false); 0049 notify(); 0050 } 0051 0052 #include "moc_keycachememento.cpp"