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 
11 using namespace MimeTreeParser;
12 
13 KeyCacheMemento::KeyCacheMemento(const std::shared_ptr<Kleo::KeyCache> &keyCache, GpgME::Protocol protocol)
14  : m_keyCache(keyCache)
15  , m_protocol(protocol)
16 {
17 }
18 
19 KeyCacheMemento::~KeyCacheMemento() = default;
20 
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 
35 void 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 
46 void KeyCacheMemento::slotKeyCacheInitialized()
47 {
48  setRunning(false);
49  notify();
50 }
51 
52 #include "moc_keycachememento.cpp"
Q_SCRIPTABLE Q_NOREPLY void start()
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Thu Feb 15 2024 03:55:20 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.