diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-03-09 12:41:54 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-03-09 12:42:26 +0100 |
commit | 45aaa4a4b2a0718d6e23dd5ac8a5c594d774e949 (patch) | |
tree | 469a8b635285e25b53712aa22c69749dda563954 /examples/davresource/davresource.cpp | |
parent | c5e3f33870d6da2d68bb2ed3cc120524b06f56e9 (diff) | |
download | sink-45aaa4a4b2a0718d6e23dd5ac8a5c594d774e949.tar.gz sink-45aaa4a4b2a0718d6e23dd5ac8a5c594d774e949.zip |
Dav cleanup
Diffstat (limited to 'examples/davresource/davresource.cpp')
-rw-r--r-- | examples/davresource/davresource.cpp | 32 |
1 files changed, 21 insertions, 11 deletions
diff --git a/examples/davresource/davresource.cpp b/examples/davresource/davresource.cpp index de4c0b0..df2c4b4 100644 --- a/examples/davresource/davresource.cpp +++ b/examples/davresource/davresource.cpp | |||
@@ -284,6 +284,7 @@ public: | |||
284 | list << Synchronizer::SyncRequest{query}; | 284 | list << Synchronizer::SyncRequest{query}; |
285 | } else { | 285 | } else { |
286 | //We want to synchronize everything | 286 | //We want to synchronize everything |
287 | list << Synchronizer::SyncRequest{Sink::QueryBase(ApplicationDomain::getTypeName<ApplicationDomain::Folder>())}; | ||
287 | list << Synchronizer::SyncRequest{Sink::QueryBase(ApplicationDomain::getTypeName<ApplicationDomain::Contact>())}; | 288 | list << Synchronizer::SyncRequest{Sink::QueryBase(ApplicationDomain::getTypeName<ApplicationDomain::Contact>())}; |
288 | } | 289 | } |
289 | return list; | 290 | return list; |
@@ -292,37 +293,43 @@ public: | |||
292 | KAsync::Job<void> synchronizeWithSource(const Sink::QueryBase &query) Q_DECL_OVERRIDE | 293 | KAsync::Job<void> synchronizeWithSource(const Sink::QueryBase &query) Q_DECL_OVERRIDE |
293 | { | 294 | { |
294 | if (query.type() == ApplicationDomain::getTypeName<ApplicationDomain::Folder>()) { | 295 | if (query.type() == ApplicationDomain::getTypeName<ApplicationDomain::Folder>()) { |
296 | SinkLogCtx(mLogCtx) << "Synchronizing folders:" << mResourceUrl.url(); | ||
295 | auto collectionsFetchJob = new KDAV::DavCollectionsFetchJob(mResourceUrl); | 297 | auto collectionsFetchJob = new KDAV::DavCollectionsFetchJob(mResourceUrl); |
296 | auto job = runJob(collectionsFetchJob).then<void>([this, collectionsFetchJob] { | 298 | auto job = runJob(collectionsFetchJob).then([this, collectionsFetchJob] (const KAsync::Error &error) { |
297 | synchronizeAddressbooks(collectionsFetchJob ->collections()); | 299 | if (error) { |
300 | SinkWarningCtx(mLogCtx) << "Failed to synchronize folders." << collectionsFetchJob->errorString(); | ||
301 | } else { | ||
302 | synchronizeAddressbooks(collectionsFetchJob ->collections()); | ||
303 | } | ||
298 | }); | 304 | }); |
299 | return job; | 305 | return job; |
300 | } else if (query.type() == ApplicationDomain::getTypeName<ApplicationDomain::Contact>()) { | 306 | } else if (query.type() == ApplicationDomain::getTypeName<ApplicationDomain::Contact>()) { |
307 | SinkLogCtx(mLogCtx) << "Synchronizing contacts."; | ||
301 | auto ridList = QSharedPointer<QByteArrayList>::create(); | 308 | auto ridList = QSharedPointer<QByteArrayList>::create(); |
302 | auto collectionsFetchJob = new KDAV::DavCollectionsFetchJob(mResourceUrl); | 309 | auto collectionsFetchJob = new KDAV::DavCollectionsFetchJob(mResourceUrl); |
303 | auto job = runJob(collectionsFetchJob).then<KDAV::DavCollection::List>([this, collectionsFetchJob] { | 310 | auto job = runJob(collectionsFetchJob).then([this, collectionsFetchJob] { |
304 | synchronizeAddressbooks(collectionsFetchJob ->collections()); | 311 | synchronizeAddressbooks(collectionsFetchJob ->collections()); |
305 | return collectionsFetchJob->collections(); | 312 | return collectionsFetchJob->collections(); |
306 | }) | 313 | }) |
307 | .serialEach<void>([this, ridList](const KDAV::DavCollection &collection) { | 314 | .serialEach([this, ridList](const KDAV::DavCollection &collection) { |
308 | auto collId = collection.url().toDisplayString().toLatin1(); | 315 | auto collId = collection.url().toDisplayString().toLatin1(); |
309 | auto ctag = collection.CTag().toLatin1(); | 316 | auto ctag = collection.CTag().toLatin1(); |
310 | if (ctag != syncStore().readValue(collId + "_ctagXX")) { | 317 | if (ctag != syncStore().readValue(collId + "_ctagXX")) { |
311 | SinkTrace() << "Syncing " << collId; | 318 | SinkTraceCtx(mLogCtx) << "Syncing " << collId; |
312 | auto cache = std::shared_ptr<KDAV::EtagCache>(new KDAV::EtagCache()); | 319 | auto cache = std::shared_ptr<KDAV::EtagCache>(new KDAV::EtagCache()); |
313 | auto davItemsListJob = new KDAV::DavItemsListJob(collection.url(), cache); | 320 | auto davItemsListJob = new KDAV::DavItemsListJob(collection.url(), cache); |
314 | const QByteArray bufferType = ENTITY_TYPE_CONTACT; | 321 | const QByteArray bufferType = ENTITY_TYPE_CONTACT; |
315 | QHash<QByteArray, Query::Comparator> mergeCriteria; | 322 | QHash<QByteArray, Query::Comparator> mergeCriteria; |
316 | auto colljob = runJob(davItemsListJob).then<KDAV::DavItem::List>([davItemsListJob] { | 323 | auto colljob = runJob(davItemsListJob).then([davItemsListJob] { |
317 | return KAsync::value(davItemsListJob->items()); | 324 | return KAsync::value(davItemsListJob->items()); |
318 | }) | 325 | }) |
319 | .serialEach<QByteArray>([this, ridList, bufferType, mergeCriteria] (const KDAV::DavItem &item) { | 326 | .serialEach([this, ridList, bufferType, mergeCriteria] (const KDAV::DavItem &item) { |
320 | QByteArray rid = item.url().toDisplayString().toUtf8(); | 327 | QByteArray rid = item.url().toDisplayString().toUtf8(); |
321 | if (item.etag().toLatin1() != syncStore().readValue(rid + "_etag")){ | 328 | if (item.etag().toLatin1() != syncStore().readValue(rid + "_etag")){ |
322 | SinkTrace() << "Updating " << rid; | 329 | SinkTrace() << "Updating " << rid; |
323 | auto davItemFetchJob = new KDAV::DavItemFetchJob(item); | 330 | auto davItemFetchJob = new KDAV::DavItemFetchJob(item); |
324 | auto itemjob = runJob(davItemFetchJob) | 331 | auto itemjob = runJob(davItemFetchJob) |
325 | .then<KDAV::DavItem>([this, davItemFetchJob, bufferType, mergeCriteria] { | 332 | .then([this, davItemFetchJob, bufferType, mergeCriteria] { |
326 | const auto item = davItemFetchJob->item(); | 333 | const auto item = davItemFetchJob->item(); |
327 | const auto rid = item.url().toDisplayString().toUtf8(); | 334 | const auto rid = item.url().toDisplayString().toUtf8(); |
328 | Sink::ApplicationDomain::Contact contact; | 335 | Sink::ApplicationDomain::Contact contact; |
@@ -330,7 +337,7 @@ public: | |||
330 | createOrModify(bufferType, rid, contact, mergeCriteria); | 337 | createOrModify(bufferType, rid, contact, mergeCriteria); |
331 | return item; | 338 | return item; |
332 | }) | 339 | }) |
333 | .then<QByteArray>([this, ridList] (const KDAV::DavItem &item) { | 340 | .then([this, ridList] (const KDAV::DavItem &item) { |
334 | const auto rid = item.url().toDisplayString().toUtf8(); | 341 | const auto rid = item.url().toDisplayString().toUtf8(); |
335 | syncStore().writeValue(rid + "_etag", item.etag().toLatin1()); | 342 | syncStore().writeValue(rid + "_etag", item.etag().toLatin1()); |
336 | ridList->append(rid); | 343 | ridList->append(rid); |
@@ -342,11 +349,12 @@ public: | |||
342 | return KAsync::value(rid); | 349 | return KAsync::value(rid); |
343 | } | 350 | } |
344 | }) | 351 | }) |
345 | .then<void>([this, collId, ctag] () { | 352 | .then([this, collId, ctag] () { |
346 | syncStore().writeValue(collId + "_ctag", ctag); | 353 | syncStore().writeValue(collId + "_ctag", ctag); |
347 | }); | 354 | }); |
348 | return colljob; | 355 | return colljob; |
349 | } else { | 356 | } else { |
357 | SinkTraceCtx(mLogCtx) << "Collection unchanged: " << ctag; | ||
350 | // for(const auto &item : addressbook) { | 358 | // for(const auto &item : addressbook) { |
351 | // ridList->append(rid); | 359 | // ridList->append(rid); |
352 | // } | 360 | // } |
@@ -530,7 +538,9 @@ DavResource::DavResource(const Sink::ResourceContext &resourceContext) | |||
530 | 538 | ||
531 | DavResourceFactory::DavResourceFactory(QObject *parent) | 539 | DavResourceFactory::DavResourceFactory(QObject *parent) |
532 | : Sink::ResourceFactory(parent, | 540 | : Sink::ResourceFactory(parent, |
533 | {"-folder.rename"} | 541 | {Sink::ApplicationDomain::ResourceCapabilities::Contact::contact, |
542 | Sink::ApplicationDomain::ResourceCapabilities::Mail::folder, | ||
543 | "-folder.rename"} | ||
534 | ) | 544 | ) |
535 | { | 545 | { |
536 | } | 546 | } |