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
10using namespace MimeTreeParser;
11
12CompositeMemento::~CompositeMemento()
13{
14 for (auto *memento : mMementos) {
15 memento->detach();
16 delete memento;
17 }
18 mMementos.clear();
19}
20
21bool CompositeMemento::start()
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
33void CompositeMemento::exec()
34{
35 int counter = 0;
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
50void CompositeMemento::addMemento(CryptoBodyPartMemento *memento)
51{
52 mMementos.push_back(memento);
53}
54
55void CompositeMemento::subMementoFinished()
56{
57 --mRunningMementos;
58 if (mRunningMementos == 0) {
59 notify();
60 }
61}
62
63#include "moc_compositememento.cpp"
void clear()
void push_back(parameter_type value)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
T qobject_cast(QObject *object)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 3 2024 11:43:26 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.