1/*
2 SPDX-FileCopyrightText: 2010 Tobias Koenig <tokoe@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "davcollectionsmultifetchjob.h"
8
9#include "davcollectionsfetchjob.h"
10
11using namespace KDAV;
12
13namespace KDAV
14{
15class DavCollectionsMultiFetchJobPrivate
16{
17public:
18 DavCollection::List mCollections;
19};
20}
21
22DavCollectionsMultiFetchJob::DavCollectionsMultiFetchJob(const DavUrl::List &urls, QObject *parent)
23 : KCompositeJob(parent)
24 , d(new DavCollectionsMultiFetchJobPrivate)
25{
26 for (const DavUrl &url : std::as_const(t: urls)) {
27 DavCollectionsFetchJob *job = new DavCollectionsFetchJob(url, this);
28 connect(sender: job, signal: &DavCollectionsFetchJob::collectionDiscovered, context: this, slot: &DavCollectionsMultiFetchJob::collectionDiscovered);
29 addSubjob(job);
30 }
31}
32
33DavCollectionsMultiFetchJob::~DavCollectionsMultiFetchJob() = default;
34
35void DavCollectionsMultiFetchJob::start()
36{
37 if (!hasSubjobs()) {
38 emitResult();
39 } else {
40 for (KJob *job : subjobs()) {
41 job->start();
42 }
43 }
44}
45
46DavCollection::List DavCollectionsMultiFetchJob::collections() const
47{
48 return d->mCollections;
49}
50
51void DavCollectionsMultiFetchJob::slotResult(KJob *job)
52{
53 // If we use KCompositeJob::slotResult(job) we end up with behaviour that's very
54 // hard to unittest: the valid URLs might or might not get processed.
55 // Let's wait until all subjobs are done before emitting result.
56
57 if (job->error() && !error()) {
58 // Store error only if first error
59 setError(job->error());
60 setErrorText(job->errorText());
61 }
62 if (!job->error()) {
63 DavCollectionsFetchJob *fetchJob = qobject_cast<DavCollectionsFetchJob *>(object: job);
64 d->mCollections << fetchJob->collections();
65 }
66 removeSubjob(job);
67 if (!hasSubjobs()) {
68 emitResult();
69 }
70}
71
72#include "moc_davcollectionsmultifetchjob.cpp"
73

source code of kdav/src/common/davcollectionsmultifetchjob.cpp