File indexing completed on 2025-01-05 04:46:24
0001 /* 0002 SPDX-FileCopyrightText: 2012 Volker Krause <vkrause@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include "agentbase_p.h" 0010 #include "collection.h" 0011 #include "item.h" 0012 0013 #include <KCompositeJob> 0014 0015 namespace Akonadi 0016 { 0017 /** 0018 * Helper class for expanding inter-resource collection moves inside ResourceBase. 0019 * 0020 * @note This is intentionally not an Akonadi::Job since we don't need autostarting 0021 * here. 0022 */ 0023 class RecursiveMover : public KCompositeJob 0024 { 0025 Q_OBJECT 0026 public: 0027 explicit RecursiveMover(AgentBasePrivate *parent); 0028 0029 /// Set the collection that is actually moved. 0030 void setCollection(const Akonadi::Collection &collection, const Akonadi::Collection &parentCollection); 0031 0032 void start() override; 0033 0034 /// Call once the last replayed change has been processed. 0035 void changeProcessed(); 0036 0037 public Q_SLOTS: 0038 /// Trigger the next change replay, will call emitResult() once everything has been replayed 0039 void replayNext(); 0040 0041 private: 0042 void replayNextCollection(); 0043 void replayNextItem(); 0044 0045 private Q_SLOTS: 0046 void collectionListResult(KJob *job); 0047 void collectionFetchResult(KJob *job); 0048 void itemListResult(KJob *job); 0049 void itemFetchResult(KJob *job); 0050 0051 private: 0052 AgentBasePrivate *const m_agentBase; 0053 Collection m_movedCollection; 0054 /// sorted queue of collections still to be processed 0055 Collection::List m_pendingCollections; 0056 /// holds up-to-date full collection objects, used for e.g. having proper parent collections for collectionAdded 0057 QHash<Collection::Id, Collection> m_collections; 0058 Item::List m_pendingItems; 0059 0060 Collection m_currentCollection; 0061 Item m_currentItem; 0062 0063 enum CurrentAction { None, AddCollection, AddItem } m_currentAction; 0064 0065 int m_runningJobs = 0; 0066 bool m_pendingReplay = false; 0067 }; 0068 0069 } 0070 0071 Q_DECLARE_METATYPE(Akonadi::RecursiveMover *)