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)
37 void 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);
54 void 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);
84 toBeProcessed.enqueue(child);
88 replayNextCollection();
91 void RecursiveMover::collectionFetchResult(KJob *job)
93 Q_ASSERT(m_currentCollection.isValid());
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) {
114 void 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) {
133 void RecursiveMover::itemFetchResult(KJob *job)
135 Q_ASSERT(m_currentAction == None);
143 if (fetchJob->
items().size() == 1) {
144 m_currentAction = AddItem;
145 m_agentBase->itemAdded(fetchJob->
items().first(), m_currentCollection);
148 m_currentItem = Item();
153 void RecursiveMover::replayNextCollection()
155 if (!m_pendingCollections.isEmpty()) {
157 m_currentCollection = m_pendingCollections.takeFirst();
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;
179 void 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();
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" Collection parentCollection() const
Returns the parent collection of this object.
Represents a collection of PIM items.
Job that fetches collections from the Akonadi storage.
void changeProcessed()
Call once the last replayed change has been processed.
Collection::List collections() const
Returns the list of fetched collection.
void fetchFullPayload(bool fetch=true)
Sets whether the full payload shall be fetched.
Only fetch the base collection.
ItemFetchScope & fetchScope()
Returns the item fetch scope.
Item::List items() const
Returns the fetched items.
Retrieve all ancestors, up to Collection::root()
Id id() const
Returns the unique identifier of the entity.
FreeBusyManager::Singleton.
void setCollection(const Akonadi::Collection &collection, const Akonadi::Collection &parentCollection)
Set the collection that is actually moved.
Job that fetches items from the Akonadi storage.
void replayNext()
Trigger the next change replay, will call emitResult() once everything has been replayed.
List all sub-collections.
QList< Collection > List
Describes a list of collections.