KCoreAddons

kcompositejob.cpp
1 /*
2  This file is part of the KDE project
3 
4  SPDX-FileCopyrightText: 2006 Kevin Ottens <[email protected]>
5 
6  SPDX-License-Identifier: LGPL-2.0-only
7 */
8 
9 #include "kcompositejob.h"
10 #include "kcompositejob_p.h"
11 
12 KCompositeJobPrivate::KCompositeJobPrivate()
13 {
14 }
15 
16 KCompositeJobPrivate::~KCompositeJobPrivate()
17 {
18 }
19 
21  : KJob(*new KCompositeJobPrivate, parent)
22 {
23 }
24 
25 KCompositeJob::KCompositeJob(KCompositeJobPrivate &dd, QObject *parent)
26  : KJob(dd, parent)
27 {
28 }
29 
31 {
32 }
33 
35 {
36  Q_D(KCompositeJob);
37  if (job == nullptr || d->subjobs.contains(job)) {
38  return false;
39  }
40 
41  job->setParent(this);
42  d->subjobs.append(job);
44 
45  // Forward information from that subjob.
47 
48  return true;
49 }
50 
52 {
53  Q_D(KCompositeJob);
54  // remove only Subjobs that are on the list
55  if (d->subjobs.removeAll(job) > 0) {
56  job->setParent(nullptr);
59  return true;
60  }
61  return false;
62 }
63 
65 {
66  return !d_func()->subjobs.isEmpty();
67 }
68 
70 {
71  return d_func()->subjobs;
72 }
73 
75 {
76  Q_D(KCompositeJob);
77  for (KJob *job : qAsConst(d->subjobs)) {
78  job->setParent(nullptr);
81  }
82  d->subjobs.clear();
83 }
84 
86 {
87  // Did job have an error ?
88  if (job->error() && !error()) {
89  // Store it in the parent only if first error
90  setError(job->error());
91  setErrorText(job->errorText());
92  // Finish this job
93  emitResult();
94  }
95  // After a subjob is done, we might want to start another one.
96  // Therefore do not emitResult
97  removeSubjob(job);
98 }
99 
100 void KCompositeJob::slotInfoMessage(KJob *job, const QString &plain, const QString &rich)
101 {
102  emit infoMessage(job, plain, rich);
103 }
104 
105 #include "moc_kcompositejob.cpp"
virtual bool addSubjob(KJob *job)
Add a job that has to be finished before a result is emitted.
void emitResult()
Utility function to emit the result signal, and suicide this job.
Definition: kjob.cpp:278
~KCompositeJob() override
Destroys a KCompositeJob object.
void setError(int errorCode)
Sets the error code.
Definition: kjob.cpp:225
virtual void slotInfoMessage(KJob *job, const QString &plain, const QString &rich)
Forward signal from subjob.
KCompositeJob(QObject *parent=nullptr)
Creates a new KCompositeJob object.
bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *method)
bool hasSubjobs() const
Checks if this job has subjobs running.
void setErrorText(const QString &errorText)
Sets the error text.
Definition: kjob.cpp:231
virtual void slotResult(KJob *job)
Called whenever a subjob finishes.
void setParent(QObject *parent)
void clearSubjobs()
Clears the list of subjobs.
const QList< KJob * > & subjobs() const
Retrieves the list of the subjobs.
KJob(QObject *parent=nullptr)
Creates a new KJob object.
Definition: kjob.cpp:32
void result(KJob *job)
Emitted when the job is finished (except when killed with KJob::Quietly).
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QObject * parent() const const
The base class for all jobs able to be composed of one or more subjobs.
Definition: kcompositejob.h:24
void infoMessage(KJob *job, const QString &plain, const QString &rich=QString())
Emitted to display state information about this job.
The base class for all jobs.
Definition: kjob.h:75
int error() const
Returns the error code, if there has been an error.
virtual bool removeSubjob(KJob *job)
Mark a sub job as being done.
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Thu Aug 6 2020 23:01:05 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.