Commit 5a7c75e4 authored by David Faure's avatar David Faure
Browse files

Port DavCollectionsMultiFetchJob to KCompositeJob

Summary: It's a little bit simpler (two members removed)

Test Plan: New test still passes

Reviewers: vkrause, ervin

Reviewed By: ervin

Subscribers: kde-pim

Tags: #kde_pim

Differential Revision: https://phabricator.kde.org/D28572
parent 1081b967
C: PROPFIND /does_not_exist HTTP/1.1
S: HTTP/1.1 404 Not found
X
......@@ -14,33 +14,31 @@ namespace KDAV {
class DavCollectionsMultiFetchJobPrivate
{
public:
DavUrl::List mUrls;
DavCollection::List mCollections;
int mSubJobCount = -1;
};
}
DavCollectionsMultiFetchJob::DavCollectionsMultiFetchJob(const DavUrl::List &urls, QObject *parent)
: KJob(parent)
: KCompositeJob(parent)
, d(new DavCollectionsMultiFetchJobPrivate)
{
d->mUrls = urls;
d->mSubJobCount = urls.size();
for (const DavUrl &url : qAsConst(urls)) {
DavCollectionsFetchJob *job = new DavCollectionsFetchJob(url, this);
connect(job, &DavCollectionsFetchJob::collectionDiscovered, this, &DavCollectionsMultiFetchJob::collectionDiscovered);
addSubjob(job);
}
}
DavCollectionsMultiFetchJob::~DavCollectionsMultiFetchJob() = default;
void DavCollectionsMultiFetchJob::start()
{
if (d->mUrls.isEmpty()) {
if (!hasSubjobs()) {
emitResult();
}
for (const DavUrl &url : qAsConst(d->mUrls)) {
DavCollectionsFetchJob *job = new DavCollectionsFetchJob(url, this);
connect(job, &DavCollectionsFetchJob::result, this, &DavCollectionsMultiFetchJob::davJobFinished);
connect(job, &DavCollectionsFetchJob::collectionDiscovered, this, &DavCollectionsMultiFetchJob::collectionDiscovered);
job->start();
} else {
for (KJob *job : subjobs()) {
job->start();
}
}
}
......@@ -49,18 +47,23 @@ DavCollection::List DavCollectionsMultiFetchJob::collections() const
return d->mCollections;
}
void DavCollectionsMultiFetchJob::davJobFinished(KJob *job)
void DavCollectionsMultiFetchJob::slotResult(KJob *job)
{
DavCollectionsFetchJob *fetchJob = qobject_cast<DavCollectionsFetchJob *>(job);
// If we use KCompositeJob::slotResult(job) we end up with behaviour that's very
// hard to unittest: the valid URLs might or might not get processed.
// Let's wait until all subjobs are done before emitting result.
if (job->error()) {
if (job->error() && !error()) {
// Store error only if first error
setError(job->error());
setErrorText(job->errorText());
} else {
}
if (!job->error()) {
DavCollectionsFetchJob *fetchJob = qobject_cast<DavCollectionsFetchJob *>(job);
d->mCollections << fetchJob->collections();
}
if (--d->mSubJobCount == 0) {
removeSubjob(job);
if (!hasSubjobs()) {
emitResult();
}
}
......@@ -12,7 +12,7 @@
#include "davcollection.h"
#include "davurl.h"
#include <KJob>
#include <KCompositeJob>
#include <memory>
......@@ -28,7 +28,7 @@ class DavCollectionsMultiFetchJobPrivate;
* @note This class just combines multiple calls of DavCollectionsFetchJob
* into one job.
*/
class KDAV_EXPORT DavCollectionsMultiFetchJob : public KJob
class KDAV_EXPORT DavCollectionsMultiFetchJob : public KCompositeJob
{
Q_OBJECT
......@@ -62,7 +62,7 @@ Q_SIGNALS:
void collectionDiscovered(KDAV::Protocol protocol, const QString &collectionUrl, const QString &configuredUrl);
private:
void davJobFinished(KJob *);
void slotResult(KJob *) override;
const std::unique_ptr<DavCollectionsMultiFetchJobPrivate> d;
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment