summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2018-03-29 17:52:59 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2018-03-29 17:52:59 +0200
commitb24ac86241841ea42495617549e1387ec86b9c01 (patch)
tree8630b1d30e44acc3ecf824d85892ff007034017e
parent9f35ec4fc9b00d004e6dca563b1f3e044d25b1a0 (diff)
downloadsink-b24ac86241841ea42495617549e1387ec86b9c01.tar.gz
sink-b24ac86241841ea42495617549e1387ec86b9c01.zip
Job objects delete themselves
-rw-r--r--examples/webdavcommon/webdav.cpp30
1 files changed, 8 insertions, 22 deletions
diff --git a/examples/webdavcommon/webdav.cpp b/examples/webdavcommon/webdav.cpp
index 35f7fc2..a33511d 100644
--- a/examples/webdavcommon/webdav.cpp
+++ b/examples/webdavcommon/webdav.cpp
@@ -45,27 +45,15 @@ static int translateDavError(KJob *job)
45 return ErrorCode::UnknownError; 45 return ErrorCode::UnknownError;
46} 46}
47 47
48static KAsync::Job<void> runJob(QSharedPointer<KJob> job) 48static KAsync::Job<void> runJob(KJob *job)
49{ 49{
50 return KAsync::start<void>([job(std::move(job))] {
51 if (job->exec()) {
52 SinkTrace() << "Job exec success";
53 } else {
54 SinkTrace() << "Job exec failure";
55 }
56 });
57
58 // For some reason, this code doesn't work
59
60 /*
61 return KAsync::start<void>([job](KAsync::Future<void> &future) { 50 return KAsync::start<void>([job](KAsync::Future<void> &future) {
62 QObject::connect(job, &KJob::result, [&future](KJob *job) { 51 QObject::connect(job, &KJob::result, [&future](KJob *job) {
63 SinkTrace() << "Job done: " << job->metaObject()->className(); 52 SinkTrace() << "Job done: " << job->metaObject()->className();
64 if (job->error()) { 53 if (job->error()) {
65 SinkWarning() 54 SinkWarning() << "Job failed: " << job->errorString() << job->metaObject()->className() << job->error();
66 << "Job failed: " << job->errorString() << job->metaObject()->className() 55 auto proxyError = translateDavError(job);
67 << job->error() << static_cast<KDAV2::DavJobBase *>(job)->latestResponseCode(); 56 future.setError(proxyError, job->errorString());
68 future.setError(translateDavError(job), job->errorString());
69 } else { 57 } else {
70 future.setFinished(); 58 future.setFinished();
71 } 59 }
@@ -73,7 +61,6 @@ static KAsync::Job<void> runJob(QSharedPointer<KJob> job)
73 SinkTrace() << "Starting job: " << job->metaObject()->className(); 61 SinkTrace() << "Starting job: " << job->metaObject()->className();
74 job->start(); 62 job->start();
75 }); 63 });
76 */
77} 64}
78 65
79WebDavSynchronizer::WebDavSynchronizer(const Sink::ResourceContext &context, 66WebDavSynchronizer::WebDavSynchronizer(const Sink::ResourceContext &context,
@@ -113,11 +100,10 @@ KAsync::Job<void> WebDavSynchronizer::synchronizeWithSource(const Sink::QueryBas
113 100
114 SinkLog() << "Synchronizing" << query.type() << "through WebDAV at:" << serverUrl().url(); 101 SinkLog() << "Synchronizing" << query.type() << "through WebDAV at:" << serverUrl().url();
115 102
116 auto collectionsFetchJob = QSharedPointer<KDAV2::DavCollectionsFetchJob>::create(serverUrl()); 103 auto collectionsFetchJob = new KDAV2::DavCollectionsFetchJob{serverUrl()};
117
118 auto job = runJob(collectionsFetchJob).then([this, collectionsFetchJob](const KAsync::Error &error) { 104 auto job = runJob(collectionsFetchJob).then([this, collectionsFetchJob](const KAsync::Error &error) {
119 if (error) { 105 if (error) {
120 SinkWarning() << "Failed to synchronize collections:" << collectionsFetchJob->errorString(); 106 SinkWarning() << "Failed to synchronize collections:" << error;
121 } else { 107 } else {
122 updateLocalCollections(collectionsFetchJob->collections()); 108 updateLocalCollections(collectionsFetchJob->collections());
123 } 109 }
@@ -189,7 +175,7 @@ KAsync::Job<void> WebDavSynchronizer::synchronizeCollection(const KDAV2::DavColl
189 175
190 // The ETag cache is useless here, since `sinkStore()` IS the cache. 176 // The ETag cache is useless here, since `sinkStore()` IS the cache.
191 auto cache = std::make_shared<KDAV2::EtagCache>(); 177 auto cache = std::make_shared<KDAV2::EtagCache>();
192 auto davItemsListJob = QSharedPointer<KDAV2::DavItemsListJob>::create(collection.url(), std::move(cache)); 178 auto davItemsListJob = new KDAV2::DavItemsListJob(collection.url(), std::move(cache));
193 179
194 return runJob(davItemsListJob) 180 return runJob(davItemsListJob)
195 .then([this, davItemsListJob, total] { 181 .then([this, davItemsListJob, total] {
@@ -222,7 +208,7 @@ KAsync::Job<void> WebDavSynchronizer::synchronizeItem(const KDAV2::DavItem &item
222{ 208{
223 auto etag = item.etag().toLatin1(); 209 auto etag = item.etag().toLatin1();
224 210
225 auto itemFetchJob = QSharedPointer<KDAV2::DavItemFetchJob>::create(item); 211 auto itemFetchJob = new KDAV2::DavItemFetchJob(item);
226 return runJob(itemFetchJob) 212 return runJob(itemFetchJob)
227 .then([this, itemFetchJob(std::move(itemFetchJob)), collectionLocalRid] { 213 .then([this, itemFetchJob(std::move(itemFetchJob)), collectionLocalRid] {
228 auto item = itemFetchJob->item(); 214 auto item = itemFetchJob->item();