File indexing completed on 2025-02-16 04:49:14

0001 /*
0002     Copyright (c) 2010 Tobias Koenig <tokoe@kde.org>
0003 
0004     This program is free software; you can redistribute it and/or modify
0005     it under the terms of the GNU General Public License as published by
0006     the Free Software Foundation; either version 2 of the License, or
0007     (at your option) any later version.
0008 
0009     This program is distributed in the hope that it will be useful,
0010     but WITHOUT ANY WARRANTY; without even the implied warranty of
0011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0012     GNU General Public License for more details.
0013 
0014     You should have received a copy of the GNU General Public License
0015     along with this program; if not, write to the Free Software
0016     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
0017 */
0018 
0019 #include "davcollectionsmultifetchjob.h"
0020 
0021 #include "davcollectionsfetchjob.h"
0022 
0023 using namespace KDAV2;
0024 
0025 DavCollectionsMultiFetchJob::DavCollectionsMultiFetchJob(const DavUrl::List &urls, QObject *parent)
0026     : KJob(parent), mUrls(urls), mSubJobCount(urls.size())
0027 {
0028 }
0029 
0030 void DavCollectionsMultiFetchJob::start()
0031 {
0032     if (mUrls.isEmpty()) {
0033         emitResult();
0034     }
0035 
0036     foreach (const DavUrl &url, mUrls) {
0037         DavCollectionsFetchJob *job = new DavCollectionsFetchJob(url, this);
0038         connect(job, &DavCollectionsFetchJob::result, this, &DavCollectionsMultiFetchJob::davJobFinished);
0039         connect(job, &DavCollectionsFetchJob::collectionDiscovered, this, &DavCollectionsMultiFetchJob::collectionDiscovered);
0040         job->start();
0041     }
0042 }
0043 
0044 DavCollection::List DavCollectionsMultiFetchJob::collections() const
0045 {
0046     return mCollections;
0047 }
0048 
0049 void DavCollectionsMultiFetchJob::davJobFinished(KJob *job)
0050 {
0051     DavCollectionsFetchJob *fetchJob = qobject_cast<DavCollectionsFetchJob *>(job);
0052 
0053     if (job->error()) {
0054         setError(job->error());
0055         setErrorText(job->errorText());
0056     } else {
0057         mCollections << fetchJob->collections();
0058     }
0059 
0060     if (--mSubJobCount == 0) {
0061         emitResult();
0062     }
0063 }
0064