7#include "collectionfetchjob.h"
8#include "collectionfetchscope.h"
9#include "itemfetchjob.h"
10#include "itemfetchscope.h"
11#include "recursivemover_p.h"
15RecursiveMover::RecursiveMover(AgentBasePrivate *parent)
18 , m_currentAction(
None)
22void RecursiveMover::start()
24 Q_ASSERT(receivers(SIGNAL(result(
KJob *))));
27 connect(job, &CollectionFetchJob::finished,
this, &RecursiveMover::collectionListResult);
32void RecursiveMover::setCollection(
const Collection &collection,
const Collection &parentCollection)
34 m_movedCollection = collection;
35 m_collections.insert(collection.id(), m_movedCollection);
36 m_collections.insert(parentCollection.id(), parentCollection);
39void RecursiveMover::collectionListResult(
KJob *job)
41 Q_ASSERT(m_pendingCollections.isEmpty());
50 auto fetchJob = qobject_cast<CollectionFetchJob *>(job);
54 colTree[col.parentCollection().id()] << col;
55 m_collections.
insert(col.id(), col);
59 m_pendingCollections.
push_back(m_movedCollection);
61 toBeProcessed.
enqueue(m_movedCollection);
62 while (!toBeProcessed.
isEmpty()) {
68 m_pendingCollections += children;
74 replayNextCollection();
77void RecursiveMover::collectionFetchResult(
KJob *job)
79 Q_ASSERT(m_currentCollection.isValid());
86 auto fetchJob = qobject_cast<CollectionFetchJob *>(job);
87 if (fetchJob->collections().size() == 1) {
88 m_currentCollection = fetchJob->collections().at(0);
89 m_currentCollection.setParentCollection(m_collections.value(m_currentCollection.parentCollection().id()));
90 m_collections.insert(m_currentCollection.id(), m_currentCollection);
95 if (!m_runningJobs && m_pendingReplay) {
100void RecursiveMover::itemListResult(
KJob *job)
108 for (
const Item &item : lstItems) {
109 if (item.remoteId().isEmpty()) {
110 m_pendingItems.push_back(item);
114 if (!m_runningJobs && m_pendingReplay) {
119void RecursiveMover::itemFetchResult(
KJob *job)
121 Q_ASSERT(m_currentAction == None);
128 auto fetchJob = qobject_cast<ItemFetchJob *>(job);
129 if (fetchJob->items().size() == 1) {
130 m_currentAction = AddItem;
131 m_agentBase->itemAdded(fetchJob->items().at(0), m_currentCollection);
134 m_currentItem =
Item();
139void RecursiveMover::replayNextCollection()
141 if (!m_pendingCollections.isEmpty()) {
142 m_currentCollection = m_pendingCollections.takeFirst();
144 connect(job, &ItemFetchJob::result,
this, &RecursiveMover::itemListResult);
148 if (m_currentCollection.remoteId().isEmpty()) {
149 Q_ASSERT(m_currentAction == None);
150 m_currentAction = AddCollection;
151 m_agentBase->collectionAdded(m_currentCollection, m_collections.value(m_currentCollection.parentCollection().id()));
155 m_pendingReplay =
true;
164void RecursiveMover::replayNextItem()
166 Q_ASSERT(m_currentCollection.isValid());
167 if (m_pendingItems.isEmpty()) {
168 replayNextCollection();
171 Q_ASSERT(m_currentAction == None);
172 m_currentItem = m_pendingItems.takeFirst();
174 job->fetchScope().fetchFullPayload();
175 connect(job, &ItemFetchJob::result,
this, &RecursiveMover::itemFetchResult);
181void RecursiveMover::changeProcessed()
183 Q_ASSERT(m_currentAction != None);
185 if (m_currentAction == AddCollection) {
186 Q_ASSERT(m_currentCollection.isValid());
188 job->fetchScope().setAncestorRetrieval(CollectionFetchScope::All);
189 connect(job, &CollectionFetchJob::result,
this, &RecursiveMover::collectionFetchResult);
194 m_currentAction =
None;
197void RecursiveMover::replayNext()
201 m_pendingReplay =
true;
205 m_pendingReplay =
false;
207 if (m_currentCollection.isValid()) {
210 replayNextCollection();
214#include "moc_recursivemover_p.cpp"
Job that fetches collections from the Akonadi storage.
@ Recursive
List all sub-collections.
@ Base
Only fetch the base collection.
Represents a collection of PIM items.
Job that fetches items from the Akonadi storage.
Helper integration between Akonadi and Qt.
iterator insert(const Key &key, const T &value)
T value(const Key &key) const const
bool isEmpty() const const
void push_back(parameter_type value)
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)