From 41ba42150d4232807299214a6fcfa44c669489b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Nicole?= Date: Thu, 3 May 2018 09:45:45 +0200 Subject: Implement replaying CalDAV events and calendars Summary: Notes: - For calendars, only removal is implemented because: - There is no DavCollectionCreateJob, possibly because there can't be an empty DAV collection - DavCollectionModifyJob only allows modifying "properties", which we don't use (except for the name, if the name is considered a property) - Currently, modifying an item with Sink overrides the one on the server, even if the store is not up-to-date Reviewers: cmollekopf Tags: #sink Differential Revision: https://phabricator.kde.org/D12611 --- examples/webdavcommon/webdav.cpp | 67 ++++++++++++++++++++++++++++++++++++++-- examples/webdavcommon/webdav.h | 39 +++++++++++++++++++++++ 2 files changed, 103 insertions(+), 3 deletions(-) (limited to 'examples/webdavcommon') diff --git a/examples/webdavcommon/webdav.cpp b/examples/webdavcommon/webdav.cpp index ad1af35..e5f4fab 100644 --- a/examples/webdavcommon/webdav.cpp +++ b/examples/webdavcommon/webdav.cpp @@ -22,8 +22,13 @@ #include "applicationdomaintype.h" #include "resourceconfig.h" +#include +#include #include +#include +#include #include +#include #include #include @@ -180,7 +185,6 @@ KAsync::Job WebDavSynchronizer::synchronizeCollection(const KDAV2::DavColl auto localRid = collectionLocalResourceID(collection); - // The ETag cache is useless here, since `sinkStore()` IS the cache. auto cache = std::make_shared(); auto davItemsListJob = new KDAV2::DavItemsListJob(collection.url(), std::move(cache)); @@ -234,14 +238,71 @@ KAsync::Job WebDavSynchronizer::synchronizeItem(const KDAV2::DavItem &item }); } +KAsync::Job WebDavSynchronizer::createItem(const KDAV2::DavItem &item) +{ + auto job = new KDAV2::DavItemCreateJob(item); + return runJob(job).then([] { SinkTrace() << "Done creating item"; }); +} + +KAsync::Job WebDavSynchronizer::removeItem(const KDAV2::DavItem &item) +{ + auto job = new KDAV2::DavItemDeleteJob(item); + return runJob(job).then([] { SinkTrace() << "Done removing item"; }); +} + +KAsync::Job WebDavSynchronizer::modifyItem(const KDAV2::DavItem &item) +{ + auto job = new KDAV2::DavItemModifyJob(item); + return runJob(job).then([] { SinkTrace() << "Done modifying item"; }); +} + +// There is no "DavCollectionCreateJob" +/* +KAsync::Job WebDavSynchronizer::createCollection(const KDAV2::DavCollection &collection) +{ + auto job = new KDAV2::DavCollectionCreateJob(collection); + return runJob(job); +} +*/ + +KAsync::Job WebDavSynchronizer::removeCollection(const KDAV2::DavUrl &url) +{ + auto job = new KDAV2::DavCollectionDeleteJob(url); + return runJob(job).then([] { SinkLog() << "Done removing collection"; }); +} + +// Useless without using the `setProperty` method of DavCollectionModifyJob +/* +KAsync::Job WebDavSynchronizer::modifyCollection(const KDAV2::DavUrl &url) +{ + auto job = new KDAV2::DavCollectionModifyJob(url); + return runJob(job).then([] { SinkLog() << "Done modifying collection"; }); +} +*/ + QByteArray WebDavSynchronizer::resourceID(const KDAV2::DavCollection &collection) { - return collection.url().toDisplayString().toUtf8(); + return collection.url().url().path().toUtf8(); } QByteArray WebDavSynchronizer::resourceID(const KDAV2::DavItem &item) { - return item.url().toDisplayString().toUtf8(); + return item.url().url().path().toUtf8(); +} + +KDAV2::DavUrl WebDavSynchronizer::urlOf(const QByteArray &remoteId) +{ + auto davurl = serverUrl(); + auto url = davurl.url(); + url.setPath(remoteId); + SinkLog() << "Returning URL:" << url.toEncoded(); + davurl.setUrl(url); + return davurl; +} + +KDAV2::DavUrl WebDavSynchronizer::urlOf(const QByteArray &collectionRemoteId, const QString &itemPath) +{ + return urlOf(collectionRemoteId + "/" + itemPath.toUtf8()); } bool WebDavSynchronizer::unchanged(const KDAV2::DavCollection &collection) diff --git a/examples/webdavcommon/webdav.h b/examples/webdavcommon/webdav.h index 3a4977c..ecb6a81 100644 --- a/examples/webdavcommon/webdav.h +++ b/examples/webdavcommon/webdav.h @@ -35,6 +35,32 @@ public: KAsync::Job synchronizeWithSource(const Sink::QueryBase &query) Q_DECL_OVERRIDE; protected: + + /** + * Called in a child synchronizer, when replaying a creation of an item. + */ + KAsync::Job createItem(const KDAV2::DavItem &); + + /** + * Called in a child synchronizer, when replaying a removal of an item. + */ + KAsync::Job removeItem(const KDAV2::DavItem &); + + /** + * Called in a child synchronizer, when replaying a modification of an item. + * + * The item to modify is chosen according to the given item's URL. + * The job will fail if the ETag does not match. + */ + KAsync::Job modifyItem(const KDAV2::DavItem &); + + /** + * See comments of the *Item version above + */ + KAsync::Job createCollection(const KDAV2::DavUrl &); + KAsync::Job removeCollection(const KDAV2::DavUrl &); + KAsync::Job modifyCollection(const KDAV2::DavUrl &); + /** * Called with the list of discovered collections. It's purpose should be * adding the said collections to the store. @@ -63,6 +89,19 @@ protected: static QByteArray resourceID(const KDAV2::DavCollection &); static QByteArray resourceID(const KDAV2::DavItem &); + /** + * Used to get the url of an item / collection with the given remote ID + */ + KDAV2::DavUrl urlOf(const QByteArray &remoteId); + + /** + * Used to get the url of an item / collection with the given remote ID, + * and append `itemPath` to the path of the URI. + * + * Useful when adding a new item to a collection + */ + KDAV2::DavUrl urlOf(const QByteArray &collectionRemoteId, const QString &itemPath); + bool unchanged(const KDAV2::DavCollection &); bool unchanged(const KDAV2::DavItem &); -- cgit v1.2.3