From de9e304c724b5de421a231bcc449a6f3dd0eb48b Mon Sep 17 00:00:00 2001 From: Minijackson Date: Mon, 30 Apr 2018 13:48:50 +0200 Subject: Add replay of events --- examples/webdavcommon/webdav.cpp | 83 ++++++++++++++++++++++++++++++++++++++-- examples/webdavcommon/webdav.h | 39 +++++++++++++++++++ 2 files changed, 119 insertions(+), 3 deletions(-) (limited to 'examples/webdavcommon') diff --git a/examples/webdavcommon/webdav.cpp b/examples/webdavcommon/webdav.cpp index ad1af35..f97a866 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,87 @@ 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([] { + SinkLog() << "Done creating item"; + }); +} + +KAsync::Job WebDavSynchronizer::removeItem(const KDAV2::DavItem &item) +{ + auto job = new KDAV2::DavItemDeleteJob(item); + return runJob(job).then([] { + SinkLog() << "Done removing item"; + }); +} + +KAsync::Job WebDavSynchronizer::modifyItem(const KDAV2::DavItem &item) +{ + auto job = new KDAV2::DavItemModifyJob(item); + return runJob(job).then([] { + SinkLog() << "Done modifying item"; + }); +} + +/* +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); +} + +KAsync::Job WebDavSynchronizer::modifyCollection(const KDAV2::DavUrl &url) +{ + auto job = new KDAV2::DavCollectionModifyJob(url); + return runJob(job); +} + +/* +KAsync::Job WebDavSynchronizer::replay(const Contact &, Sink::Operation operation, + const QByteArray &oldRemoteId, const QList &changedProperties) +{ + return replayItem(Sink::ApplicationDomain::getTypeName(), operation, oldRemoteId, +changedProperties); +} + +KAsync::Job WebDavSynchronizer::replay(const Addressbook &, Sink::Operation operation, + const QByteArray &oldRemoteId, const QList &changedProperties) +{ + return replayCollection(Sink::ApplicationDomain::getTypeName(), operation, + oldRemoteId, changedProperties); +} +*/ + QByteArray WebDavSynchronizer::resourceID(const KDAV2::DavCollection &collection) { - return collection.url().toDisplayString().toUtf8(); + return collection.url().url().toEncoded(); } QByteArray WebDavSynchronizer::resourceID(const KDAV2::DavItem &item) { - return item.url().toDisplayString().toUtf8(); + return item.url().url().toEncoded(); +} + +KDAV2::DavUrl WebDavSynchronizer::urlOf(const QByteArray &remoteId) +{ + auto url = QUrl::fromEncoded(remoteId); + auto davurl = serverUrl(); + 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