Messagelib

keycachememento.cpp
1/*
2 SPDX-FileCopyrightText: 2023 Daniel Vrátil <dvratil@kde.org>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#include "keycachememento.h"
8
9#include <QTimer>
10
11using namespace MimeTreeParser;
12
13KeyCacheMemento::KeyCacheMemento(const std::shared_ptr<Kleo::KeyCache> &keyCache, GpgME::Protocol protocol)
14 : m_keyCache(keyCache)
15 , m_protocol(protocol)
16{
17}
18
19KeyCacheMemento::~KeyCacheMemento() = default;
20
21bool KeyCacheMemento::start()
22{
23 if (m_keyCache->initialized()) {
24 // delay completion
25 QTimer::singleShot(0, this, &KeyCacheMemento::slotKeyCacheInitialized);
26 } else {
27 connect(m_keyCache.get(), &Kleo::KeyCache::keyListingDone, this, &KeyCacheMemento::slotKeyCacheInitialized);
28 m_keyCache->startKeyListing(m_protocol);
29 }
30
31 setRunning(true);
32 return true;
33}
34
35void KeyCacheMemento::exec()
36{
37 setRunning(true);
38 if (!m_keyCache->initialized()) {
39 // This will start a nested eventloop internally that will block until the
40 // key cache is initialized and can return a result.
41 m_keyCache->findByFingerprint("");
42 }
43 setRunning(false);
44}
45
46void KeyCacheMemento::slotKeyCacheInitialized()
47{
48 setRunning(false);
49 notify();
50}
51
52#include "moc_keycachememento.cpp"
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:33:26 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.