From b24ac86241841ea42495617549e1387ec86b9c01 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Thu, 29 Mar 2018 17:52:59 +0200 Subject: Job objects delete themselves --- examples/webdavcommon/webdav.cpp | 30 ++++++++---------------------- 1 file changed, 8 insertions(+), 22 deletions(-) (limited to 'examples/webdavcommon') 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) return ErrorCode::UnknownError; } -static KAsync::Job runJob(QSharedPointer job) +static KAsync::Job runJob(KJob *job) { - return KAsync::start([job(std::move(job))] { - if (job->exec()) { - SinkTrace() << "Job exec success"; - } else { - SinkTrace() << "Job exec failure"; - } - }); - - // For some reason, this code doesn't work - - /* return KAsync::start([job](KAsync::Future &future) { QObject::connect(job, &KJob::result, [&future](KJob *job) { SinkTrace() << "Job done: " << job->metaObject()->className(); if (job->error()) { - SinkWarning() - << "Job failed: " << job->errorString() << job->metaObject()->className() - << job->error() << static_cast(job)->latestResponseCode(); - future.setError(translateDavError(job), job->errorString()); + SinkWarning() << "Job failed: " << job->errorString() << job->metaObject()->className() << job->error(); + auto proxyError = translateDavError(job); + future.setError(proxyError, job->errorString()); } else { future.setFinished(); } @@ -73,7 +61,6 @@ static KAsync::Job runJob(QSharedPointer job) SinkTrace() << "Starting job: " << job->metaObject()->className(); job->start(); }); - */ } WebDavSynchronizer::WebDavSynchronizer(const Sink::ResourceContext &context, @@ -113,11 +100,10 @@ KAsync::Job WebDavSynchronizer::synchronizeWithSource(const Sink::QueryBas SinkLog() << "Synchronizing" << query.type() << "through WebDAV at:" << serverUrl().url(); - auto collectionsFetchJob = QSharedPointer::create(serverUrl()); - + auto collectionsFetchJob = new KDAV2::DavCollectionsFetchJob{serverUrl()}; auto job = runJob(collectionsFetchJob).then([this, collectionsFetchJob](const KAsync::Error &error) { if (error) { - SinkWarning() << "Failed to synchronize collections:" << collectionsFetchJob->errorString(); + SinkWarning() << "Failed to synchronize collections:" << error; } else { updateLocalCollections(collectionsFetchJob->collections()); } @@ -189,7 +175,7 @@ KAsync::Job WebDavSynchronizer::synchronizeCollection(const KDAV2::DavColl // The ETag cache is useless here, since `sinkStore()` IS the cache. auto cache = std::make_shared(); - auto davItemsListJob = QSharedPointer::create(collection.url(), std::move(cache)); + auto davItemsListJob = new KDAV2::DavItemsListJob(collection.url(), std::move(cache)); return runJob(davItemsListJob) .then([this, davItemsListJob, total] { @@ -222,7 +208,7 @@ KAsync::Job WebDavSynchronizer::synchronizeItem(const KDAV2::DavItem &item { auto etag = item.etag().toLatin1(); - auto itemFetchJob = QSharedPointer::create(item); + auto itemFetchJob = new KDAV2::DavItemFetchJob(item); return runJob(itemFetchJob) .then([this, itemFetchJob(std::move(itemFetchJob)), collectionLocalRid] { auto item = itemFetchJob->item(); -- cgit v1.2.3