File indexing completed on 2024-04-28 03:53:55
0001 /* 0002 SPDX-FileCopyrightText: 2010 Tobias Koenig <tokoe@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "davcollectionsmultifetchjob.h" 0008 0009 #include "davcollectionsfetchjob.h" 0010 0011 using namespace KDAV; 0012 0013 namespace KDAV 0014 { 0015 class DavCollectionsMultiFetchJobPrivate 0016 { 0017 public: 0018 DavCollection::List mCollections; 0019 }; 0020 } 0021 0022 DavCollectionsMultiFetchJob::DavCollectionsMultiFetchJob(const DavUrl::List &urls, QObject *parent) 0023 : KCompositeJob(parent) 0024 , d(new DavCollectionsMultiFetchJobPrivate) 0025 { 0026 for (const DavUrl &url : std::as_const(urls)) { 0027 DavCollectionsFetchJob *job = new DavCollectionsFetchJob(url, this); 0028 connect(job, &DavCollectionsFetchJob::collectionDiscovered, this, &DavCollectionsMultiFetchJob::collectionDiscovered); 0029 addSubjob(job); 0030 } 0031 } 0032 0033 DavCollectionsMultiFetchJob::~DavCollectionsMultiFetchJob() = default; 0034 0035 void DavCollectionsMultiFetchJob::start() 0036 { 0037 if (!hasSubjobs()) { 0038 emitResult(); 0039 } else { 0040 for (KJob *job : subjobs()) { 0041 job->start(); 0042 } 0043 } 0044 } 0045 0046 DavCollection::List DavCollectionsMultiFetchJob::collections() const 0047 { 0048 return d->mCollections; 0049 } 0050 0051 void DavCollectionsMultiFetchJob::slotResult(KJob *job) 0052 { 0053 // If we use KCompositeJob::slotResult(job) we end up with behaviour that's very 0054 // hard to unittest: the valid URLs might or might not get processed. 0055 // Let's wait until all subjobs are done before emitting result. 0056 0057 if (job->error() && !error()) { 0058 // Store error only if first error 0059 setError(job->error()); 0060 setErrorText(job->errorText()); 0061 } 0062 if (!job->error()) { 0063 DavCollectionsFetchJob *fetchJob = qobject_cast<DavCollectionsFetchJob *>(job); 0064 d->mCollections << fetchJob->collections(); 0065 } 0066 removeSubjob(job); 0067 if (!hasSubjobs()) { 0068 emitResult(); 0069 } 0070 } 0071 0072 #include "moc_davcollectionsmultifetchjob.cpp"