File indexing completed on 2024-06-23 05:19:20
0001 /* 0002 SPDX-FileCopyrightText: 2023 Daniel Vrátil <dvratil@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include "cryptobodypartmemento.h" 0010 0011 #include <memory> 0012 #include <type_traits> 0013 0014 namespace MimeTreeParser 0015 { 0016 0017 class CompositeMemento : public CryptoBodyPartMemento 0018 { 0019 Q_OBJECT 0020 public: 0021 explicit CompositeMemento() = default; 0022 ~CompositeMemento() override; 0023 0024 bool start() override; 0025 void exec() override; 0026 0027 void addMemento(CryptoBodyPartMemento *memento); 0028 0029 QVector<CryptoBodyPartMemento *> mementos() const 0030 { 0031 return mMementos; 0032 } 0033 0034 auto size() const 0035 { 0036 return mMementos.size(); 0037 } 0038 0039 template<typename T> 0040 T *memento() const 0041 { 0042 auto it = std::find_if(mMementos.begin(), mMementos.end(), [](auto *memento) { 0043 return qobject_cast<std::decay_t<T> *>(memento) != nullptr; 0044 }); 0045 if (it != mMementos.cend()) { 0046 return static_cast<T *>(*it); 0047 } 0048 0049 return nullptr; 0050 } 0051 0052 private Q_SLOTS: 0053 void subMementoFinished(); 0054 0055 private: 0056 QVector<CryptoBodyPartMemento *> mMementos; 0057 int mRunningMementos = 0; 0058 }; 0059 0060 } // namespace