diff options
author | Rémi Nicole <nicole@kolabsystems.com> | 2018-05-03 09:45:45 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2018-05-03 09:47:35 +0200 |
commit | 41ba42150d4232807299214a6fcfa44c669489b0 (patch) | |
tree | 117ff2c2afbc5fa2170c7d56a55f80b7811be235 /examples/webdavcommon/webdav.cpp | |
parent | 7a166895a54c4037749229b9ec9d0c90d60987b5 (diff) | |
download | sink-41ba42150d4232807299214a6fcfa44c669489b0.tar.gz sink-41ba42150d4232807299214a6fcfa44c669489b0.zip |
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
Diffstat (limited to 'examples/webdavcommon/webdav.cpp')
-rw-r--r-- | examples/webdavcommon/webdav.cpp | 67 |
1 files changed, 64 insertions, 3 deletions
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 @@ | |||
22 | #include "applicationdomaintype.h" | 22 | #include "applicationdomaintype.h" |
23 | #include "resourceconfig.h" | 23 | #include "resourceconfig.h" |
24 | 24 | ||
25 | #include <KDAV2/DavCollectionDeleteJob> | ||
26 | #include <KDAV2/DavCollectionModifyJob> | ||
25 | #include <KDAV2/DavCollectionsFetchJob> | 27 | #include <KDAV2/DavCollectionsFetchJob> |
28 | #include <KDAV2/DavItemCreateJob> | ||
29 | #include <KDAV2/DavItemDeleteJob> | ||
26 | #include <KDAV2/DavItemFetchJob> | 30 | #include <KDAV2/DavItemFetchJob> |
31 | #include <KDAV2/DavItemModifyJob> | ||
27 | #include <KDAV2/DavItemsListJob> | 32 | #include <KDAV2/DavItemsListJob> |
28 | #include <KDAV2/EtagCache> | 33 | #include <KDAV2/EtagCache> |
29 | 34 | ||
@@ -180,7 +185,6 @@ KAsync::Job<void> WebDavSynchronizer::synchronizeCollection(const KDAV2::DavColl | |||
180 | 185 | ||
181 | auto localRid = collectionLocalResourceID(collection); | 186 | auto localRid = collectionLocalResourceID(collection); |
182 | 187 | ||
183 | // The ETag cache is useless here, since `sinkStore()` IS the cache. | ||
184 | auto cache = std::make_shared<KDAV2::EtagCache>(); | 188 | auto cache = std::make_shared<KDAV2::EtagCache>(); |
185 | auto davItemsListJob = new KDAV2::DavItemsListJob(collection.url(), std::move(cache)); | 189 | auto davItemsListJob = new KDAV2::DavItemsListJob(collection.url(), std::move(cache)); |
186 | 190 | ||
@@ -234,14 +238,71 @@ KAsync::Job<void> WebDavSynchronizer::synchronizeItem(const KDAV2::DavItem &item | |||
234 | }); | 238 | }); |
235 | } | 239 | } |
236 | 240 | ||
241 | KAsync::Job<void> WebDavSynchronizer::createItem(const KDAV2::DavItem &item) | ||
242 | { | ||
243 | auto job = new KDAV2::DavItemCreateJob(item); | ||
244 | return runJob(job).then([] { SinkTrace() << "Done creating item"; }); | ||
245 | } | ||
246 | |||
247 | KAsync::Job<void> WebDavSynchronizer::removeItem(const KDAV2::DavItem &item) | ||
248 | { | ||
249 | auto job = new KDAV2::DavItemDeleteJob(item); | ||
250 | return runJob(job).then([] { SinkTrace() << "Done removing item"; }); | ||
251 | } | ||
252 | |||
253 | KAsync::Job<void> WebDavSynchronizer::modifyItem(const KDAV2::DavItem &item) | ||
254 | { | ||
255 | auto job = new KDAV2::DavItemModifyJob(item); | ||
256 | return runJob(job).then([] { SinkTrace() << "Done modifying item"; }); | ||
257 | } | ||
258 | |||
259 | // There is no "DavCollectionCreateJob" | ||
260 | /* | ||
261 | KAsync::Job<void> WebDavSynchronizer::createCollection(const KDAV2::DavCollection &collection) | ||
262 | { | ||
263 | auto job = new KDAV2::DavCollectionCreateJob(collection); | ||
264 | return runJob(job); | ||
265 | } | ||
266 | */ | ||
267 | |||
268 | KAsync::Job<void> WebDavSynchronizer::removeCollection(const KDAV2::DavUrl &url) | ||
269 | { | ||
270 | auto job = new KDAV2::DavCollectionDeleteJob(url); | ||
271 | return runJob(job).then([] { SinkLog() << "Done removing collection"; }); | ||
272 | } | ||
273 | |||
274 | // Useless without using the `setProperty` method of DavCollectionModifyJob | ||
275 | /* | ||
276 | KAsync::Job<void> WebDavSynchronizer::modifyCollection(const KDAV2::DavUrl &url) | ||
277 | { | ||
278 | auto job = new KDAV2::DavCollectionModifyJob(url); | ||
279 | return runJob(job).then([] { SinkLog() << "Done modifying collection"; }); | ||
280 | } | ||
281 | */ | ||
282 | |||
237 | QByteArray WebDavSynchronizer::resourceID(const KDAV2::DavCollection &collection) | 283 | QByteArray WebDavSynchronizer::resourceID(const KDAV2::DavCollection &collection) |
238 | { | 284 | { |
239 | return collection.url().toDisplayString().toUtf8(); | 285 | return collection.url().url().path().toUtf8(); |
240 | } | 286 | } |
241 | 287 | ||
242 | QByteArray WebDavSynchronizer::resourceID(const KDAV2::DavItem &item) | 288 | QByteArray WebDavSynchronizer::resourceID(const KDAV2::DavItem &item) |
243 | { | 289 | { |
244 | return item.url().toDisplayString().toUtf8(); | 290 | return item.url().url().path().toUtf8(); |
291 | } | ||
292 | |||
293 | KDAV2::DavUrl WebDavSynchronizer::urlOf(const QByteArray &remoteId) | ||
294 | { | ||
295 | auto davurl = serverUrl(); | ||
296 | auto url = davurl.url(); | ||
297 | url.setPath(remoteId); | ||
298 | SinkLog() << "Returning URL:" << url.toEncoded(); | ||
299 | davurl.setUrl(url); | ||
300 | return davurl; | ||
301 | } | ||
302 | |||
303 | KDAV2::DavUrl WebDavSynchronizer::urlOf(const QByteArray &collectionRemoteId, const QString &itemPath) | ||
304 | { | ||
305 | return urlOf(collectionRemoteId + "/" + itemPath.toUtf8()); | ||
245 | } | 306 | } |
246 | 307 | ||
247 | bool WebDavSynchronizer::unchanged(const KDAV2::DavCollection &collection) | 308 | bool WebDavSynchronizer::unchanged(const KDAV2::DavCollection &collection) |