Messagelib

compositememento.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 "compositememento.h"
8 #include <QEventLoop>
9 
10 using namespace MimeTreeParser;
11 
12 CompositeMemento::~CompositeMemento()
13 {
14  for (auto *memento : mMementos) {
15  memento->detach();
16  delete memento;
17  }
18  mMementos.clear();
19 }
20 
22 {
23  mRunningMementos = 0;
24  for (auto *memento : mMementos) {
25  connect(memento, &CryptoBodyPartMemento::update, this, &CompositeMemento::subMementoFinished);
26  ++mRunningMementos;
27  memento->start();
28  }
29 
30  return true;
31 }
32 
33 void CompositeMemento::exec()
34 {
35  int counter = 0;
36  QEventLoop el;
37  for (auto *memento : mMementos) {
38  connect(memento, &CryptoBodyPartMemento::update, this, [&el, &counter]() {
39  --counter;
40  if (counter == 0) {
41  el.quit();
42  }
43  });
44  memento->start();
45  ++counter;
46  }
47  el.exec();
48 }
49 
50 void CompositeMemento::addMemento(CryptoBodyPartMemento *memento)
51 {
52  mMementos.push_back(memento);
53 }
54 
55 void CompositeMemento::subMementoFinished()
56 {
57  --mRunningMementos;
58  if (mRunningMementos == 0) {
59  notify();
60  }
61 }
62 
63 #include "moc_compositememento.cpp"
Q_SCRIPTABLE Q_NOREPLY void start()
int exec(QEventLoop::ProcessEventsFlags flags)
void quit()
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Thu Feb 15 2024 03:55:19 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.