KDAV

davcollectionsmultifetchjob.cpp
1 /*
2  SPDX-FileCopyrightText: 2010 Tobias Koenig <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #include "davcollectionsmultifetchjob.h"
8 
9 #include "davcollectionsfetchjob.h"
10 
11 using namespace KDAV;
12 
13 namespace KDAV {
14 class DavCollectionsMultiFetchJobPrivate
15 {
16 public:
17  DavCollection::List mCollections;
18 };
19 }
20 
22  : KCompositeJob(parent)
23  , d(new DavCollectionsMultiFetchJobPrivate)
24 {
25  for (const DavUrl &url : qAsConst(urls)) {
26  DavCollectionsFetchJob *job = new DavCollectionsFetchJob(url, this);
28  addSubjob(job);
29  }
30 }
31 
32 DavCollectionsMultiFetchJob::~DavCollectionsMultiFetchJob() = default;
33 
35 {
36  if (!hasSubjobs()) {
37  emitResult();
38  } else {
39  for (KJob *job : subjobs()) {
40  job->start();
41  }
42  }
43 }
44 
46 {
47  return d->mCollections;
48 }
49 
50 void DavCollectionsMultiFetchJob::slotResult(KJob *job)
51 {
52  // If we use KCompositeJob::slotResult(job) we end up with behaviour that's very
53  // hard to unittest: the valid URLs might or might not get processed.
54  // Let's wait until all subjobs are done before emitting result.
55 
56  if (job->error() && !error()) {
57  // Store error only if first error
58  setError(job->error());
59  setErrorText(job->errorText());
60  }
61  if (!job->error()) {
63  d->mCollections << fetchJob->collections();
64  }
65  removeSubjob(job);
66  if (!hasSubjobs()) {
67  emitResult();
68  }
69 }
DavCollectionsMultiFetchJob(const DavUrl::List &urls, QObject *parent=nullptr)
Creates a new DAV collections multi fetch job.
virtual bool addSubjob(KJob *job)
void emitResult()
void setError(int errorCode)
A helper class to combine URL and protocol of a DAV URL.
Definition: davurl.h:25
void collectionDiscovered(KDAV::Protocol protocol, const QString &collectionUrl, const QString &configuredUrl)
This signal is emitted every time a new collection has been discovered.
DavCollection::List collections() const
Returns the list of fetched DAV collections.
bool hasSubjobs() const
A job that fetches all DAV collection.
void setErrorText(const QString &errorText)
The KDAV namespace.
Definition: davcollection.h:22
DavCollection::List collections() const
Returns the list of fetched DAV collections.
const QList< KJob * > & subjobs() const
void collectionDiscovered(KDAV::Protocol protocol, const QString &collectionUrl, const QString &configuredUrl)
This signal is emitted every time a new collection has been discovered.
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
T qobject_cast(QObject *object)
QString errorText() const
int error() const
virtual bool removeSubjob(KJob *job)
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Fri Dec 4 2020 22:57:45 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.