summaryrefslogtreecommitdiffstats
path: root/examples/webdavcommon/webdav.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'examples/webdavcommon/webdav.cpp')
-rw-r--r--examples/webdavcommon/webdav.cpp67
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
241KAsync::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
247KAsync::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
253KAsync::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/*
261KAsync::Job<void> WebDavSynchronizer::createCollection(const KDAV2::DavCollection &collection)
262{
263 auto job = new KDAV2::DavCollectionCreateJob(collection);
264 return runJob(job);
265}
266*/
267
268KAsync::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/*
276KAsync::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
237QByteArray WebDavSynchronizer::resourceID(const KDAV2::DavCollection &collection) 283QByteArray 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
242QByteArray WebDavSynchronizer::resourceID(const KDAV2::DavItem &item) 288QByteArray WebDavSynchronizer::resourceID(const KDAV2::DavItem &item)
243{ 289{
244 return item.url().toDisplayString().toUtf8(); 290 return item.url().url().path().toUtf8();
291}
292
293KDAV2::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
303KDAV2::DavUrl WebDavSynchronizer::urlOf(const QByteArray &collectionRemoteId, const QString &itemPath)
304{
305 return urlOf(collectionRemoteId + "/" + itemPath.toUtf8());
245} 306}
246 307
247bool WebDavSynchronizer::unchanged(const KDAV2::DavCollection &collection) 308bool WebDavSynchronizer::unchanged(const KDAV2::DavCollection &collection)