20#include "recursivemover_p.h"
21#include "collectionfetchjob.h"
22#include "itemfetchjob.h"
23#include "itemfetchscope.h"
24#include "collectionfetchscope.h"
29 : KCompositeJob(parent)
31 , m_currentAction(None)
33 , m_pendingReplay(false)
37void RecursiveMover::start()
39 Q_ASSERT(receivers(SIGNAL(result(KJob*))));
42 connect(job, SIGNAL(finished(KJob*)), SLOT(collectionListResult(KJob*)));
49 m_movedCollection = collection;
50 m_collections.insert(collection.id(), m_movedCollection);
51 m_collections.insert(parentCollection.
id(), parentCollection);
54void RecursiveMover::collectionListResult(KJob *job)
56 Q_ASSERT(m_pendingCollections.isEmpty());
66 QHash<Collection::Id, Collection::List> colTree;
69 m_collections.insert(col.id(), col);
73 m_pendingCollections.push_back(m_movedCollection);
74 QQueue<Collection> toBeProcessed;
75 toBeProcessed.enqueue(m_movedCollection);
76 while (!toBeProcessed.isEmpty()) {
77 const Collection col = toBeProcessed.dequeue();
79 if (children.isEmpty()) {
82 m_pendingCollections.append(children);
83 foreach (
const Collection &child, children) {
84 toBeProcessed.enqueue(child);
88 replayNextCollection();
91void RecursiveMover::collectionFetchResult(KJob *job)
93 Q_ASSERT(m_currentCollection.isValid());
100 CollectionFetchJob *fetchJob = qobject_cast<CollectionFetchJob *>(job);
102 m_currentCollection = fetchJob->
collections().first();
103 m_currentCollection.setParentCollection(m_collections.value(m_currentCollection.parentCollection().id()));
104 m_collections.insert(m_currentCollection.id(), m_currentCollection);
109 if (!m_runningJobs && m_pendingReplay) {
114void RecursiveMover::itemListResult(KJob *job)
122 foreach (
const Item &item, qobject_cast<ItemFetchJob *>(job)->items()) {
123 if (item.remoteId().isEmpty()) {
124 m_pendingItems.push_back(item);
128 if (!m_runningJobs && m_pendingReplay) {
133void RecursiveMover::itemFetchResult(KJob *job)
135 Q_ASSERT(m_currentAction == None);
142 ItemFetchJob *fetchJob = qobject_cast<ItemFetchJob *>(job);
143 if (fetchJob->
items().size() == 1) {
144 m_currentAction = AddItem;
145 m_agentBase->itemAdded(fetchJob->
items().first(), m_currentCollection);
148 m_currentItem = Item();
153void RecursiveMover::replayNextCollection()
155 if (!m_pendingCollections.isEmpty()) {
157 m_currentCollection = m_pendingCollections.takeFirst();
158 ItemFetchJob *job =
new ItemFetchJob(m_currentCollection,
this);
159 connect(job, SIGNAL(result(KJob*)), SLOT(itemListResult(KJob*)));
163 if (m_currentCollection.remoteId().isEmpty()) {
164 Q_ASSERT(m_currentAction == None);
165 m_currentAction = AddCollection;
166 m_agentBase->collectionAdded(m_currentCollection, m_collections.value(m_currentCollection.parentCollection().id()));
170 m_pendingReplay =
true;
179void RecursiveMover::replayNextItem()
181 Q_ASSERT(m_currentCollection.isValid());
182 if (m_pendingItems.isEmpty()) {
183 replayNextCollection();
186 Q_ASSERT(m_currentAction == None);
187 m_currentItem = m_pendingItems.takeFirst();
188 ItemFetchJob *job =
new ItemFetchJob(m_currentItem,
this);
190 connect(job, SIGNAL(result(KJob*)), SLOT(itemFetchResult(KJob*)));
198 Q_ASSERT(m_currentAction != None);
200 if (m_currentAction == AddCollection) {
201 Q_ASSERT(m_currentCollection.isValid());
204 connect(job, SIGNAL(result(KJob*)), SLOT(collectionFetchResult(KJob*)));
209 m_currentAction = None;
216 m_pendingReplay =
true;
220 m_pendingReplay =
false;
222 if (m_currentCollection.isValid()) {
225 replayNextCollection();
229#include "moc_recursivemover_p.cpp"
Job that fetches collections from the Akonadi storage.
CollectionFetchScope & fetchScope()
Returns the collection fetch scope.
@ Recursive
List all sub-collections.
@ Base
Only fetch the base collection.
Collection::List collections() const
Returns the list of fetched collection.
void setAncestorRetrieval(AncestorRetrieval ancestorDepth)
Sets how many levels of ancestor collections should be included in the retrieval.
@ All
Retrieve all ancestors, up to Collection::root()
Represents a collection of PIM items.
QList< Collection > List
Describes a list of collections.
Collection parentCollection() const
Returns the parent collection of this object.
Id id() const
Returns the unique identifier of the entity.
ItemFetchScope & fetchScope()
Returns the item fetch scope.
Item::List items() const
Returns the fetched items.
void fetchFullPayload(bool fetch=true)
Sets whether the full payload shall be fetched.
void replayNext()
Trigger the next change replay, will call emitResult() once everything has been replayed.
void changeProcessed()
Call once the last replayed change has been processed.
void setCollection(const Akonadi::Collection &collection, const Akonadi::Collection &parentCollection)
Set the collection that is actually moved.
FreeBusyManager::Singleton.