diff --git a/examples/webdavcommon/webdav.h b/examples/webdavcommon/webdav.h --- a/examples/webdavcommon/webdav.h +++ b/examples/webdavcommon/webdav.h @@ -108,6 +108,8 @@ KDAV2::DavUrl serverUrl() const; private: + void updateLocalItemWrapper(const KDAV2::DavItem &item, const QByteArray &collectionLocalRid); + KDAV2::Protocol protocol; const QByteArray mCollectionType; const QByteArray mEntityType; diff --git a/examples/webdavcommon/webdav.cpp b/examples/webdavcommon/webdav.cpp --- a/examples/webdavcommon/webdav.cpp +++ b/examples/webdavcommon/webdav.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -185,8 +186,7 @@ } KAsync::Job WebDavSynchronizer::synchronizeCollection(const KDAV2::DavCollection &collection, - QSharedPointer progress, QSharedPointer total, - QSharedPointer> itemsResourceIDs) + QSharedPointer progress, QSharedPointer total, QSharedPointer> itemsResourceIDs) { auto collectionRid = resourceID(collection); auto ctag = collection.CTag().toLatin1(); @@ -198,45 +198,56 @@ return runJob(davItemsListJob, [](KJob *job) { return static_cast(job)->items(); }) - .then([this, total](const KDAV2::DavItem::List &items) { + .then([this, total, collectionUrl(collection.url())](const KDAV2::DavItem::List &items) { *total += items.size(); - return items; + QStringList itemsUrls; + for (const auto &item : items) { + itemsUrls << item.url().url().toDisplayString(); + } + return runJob(new KDAV2::DavItemsFetchJob(collectionUrl, itemsUrls), + [](KJob *job) { return static_cast(job)->items(); }); }) - .serialEach([this, collectionRid, localRid, progress(std::move(progress)), total(std::move(total)), - itemsResourceIDs(std::move(itemsResourceIDs))](const KDAV2::DavItem &item) { + .serialEach([ + this, collectionRid, localRid, progress(std::move(progress)), total(std::move(total)), + itemsResourceIDs(std::move(itemsResourceIDs)) + ](const KDAV2::DavItem &item) { auto itemRid = resourceID(item); - itemsResourceIDs->insert(itemRid); if (unchanged(item)) { SinkTrace() << "Item unchanged:" << itemRid; return KAsync::null(); } - SinkTrace() << "Syncing item:" << itemRid; - return synchronizeItem(item, localRid, progress, total); + updateLocalItemWrapper(item, collectionRid); + return KAsync::null(); }) .then([this, collectionRid, ctag] { // Update the local CTag to be able to tell if the collection is unchanged syncStore().writeValue(collectionRid + "_ctag", ctag); }); } +void WebDavSynchronizer::updateLocalItemWrapper(const KDAV2::DavItem &item, const QByteArray &collectionLocalRid) +{ + updateLocalItem(item, collectionLocalRid); + // Update the local ETag to be able to tell if the item is unchanged + syncStore().writeValue(resourceID(item) + "_etag", item.etag().toLatin1()); +} + KAsync::Job WebDavSynchronizer::synchronizeItem(const KDAV2::DavItem &item, const QByteArray &collectionLocalRid, QSharedPointer progress, QSharedPointer total) { + SinkTrace() << "Syncing item:" << resourceID(item); auto etag = item.etag().toLatin1(); auto itemFetchJob = new KDAV2::DavItemFetchJob(item); return runJob( itemFetchJob, [](KJob *job) { return static_cast(job)->item(); }) - .then([this, collectionLocalRid](const KDAV2::DavItem &item) { - updateLocalItem(item, collectionLocalRid); - return item; - }) - .then([this, etag, progress(std::move(progress)), total(std::move(total))](const KDAV2::DavItem &item) { - // Update the local ETag to be able to tell if the item is unchanged - syncStore().writeValue(resourceID(item) + "_etag", etag); + .then([ + this, collectionLocalRid, progress(std::move(progress)), total(std::move(total)) + ](const KDAV2::DavItem &item) { + updateLocalItemWrapper(item, collectionLocalRid); *progress += 1; reportProgress(*progress, *total);