KCoreAddons

kcompositejob.cpp
1/*
2 This file is part of the KDE project
3
4 SPDX-FileCopyrightText: 2006 Kevin Ottens <ervin@kde.org>
5
6 SPDX-License-Identifier: LGPL-2.0-or-later
7*/
8
9#include "kcompositejob.h"
10#include "kcompositejob_p.h"
11
12KCompositeJobPrivate::KCompositeJobPrivate()
13{
14}
15
16KCompositeJobPrivate::~KCompositeJobPrivate()
17{
18}
19
21 : KJob(*new KCompositeJobPrivate, parent)
22{
23}
24
25KCompositeJob::KCompositeJob(KCompositeJobPrivate &dd, QObject *parent)
26 : KJob(dd, parent)
27{
28}
29
33
35{
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{
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{
77 for (KJob *job : std::as_const(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
101{
102 Q_EMIT infoMessage(job, message);
103}
104
105#include "moc_kcompositejob.cpp"
The base class for all jobs able to be composed of one or more subjobs.
virtual void slotInfoMessage(KJob *job, const QString &message)
Forward signal from subjob.
virtual bool addSubjob(KJob *job)
Add a job that has to be finished before a result is emitted.
bool hasSubjobs() const
Checks if this job has subjobs running.
const QList< KJob * > & subjobs() const
Retrieves the list of the subjobs.
~KCompositeJob() override
Destroys a KCompositeJob object.
KCompositeJob(QObject *parent=nullptr)
Creates a new KCompositeJob object.
virtual bool removeSubjob(KJob *job)
Mark a sub job as being done.
virtual void slotResult(KJob *job)
Called whenever a subjob finishes.
void clearSubjobs()
Clears the list of subjobs.
The base class for all jobs.
Definition kjob.h:74
void setErrorText(const QString &errorText)
Sets the error text.
Definition kjob.cpp:285
void emitResult()
Utility function to emit the result signal, and end this job.
Definition kjob.cpp:354
void result(KJob *job)
Emitted when the job is finished (except when killed with KJob::Quietly).
void setError(int errorCode)
Sets the error code.
Definition kjob.cpp:279
void infoMessage(KJob *job, const QString &message)
Emitted to display state information about this job.
Q_EMITQ_EMIT
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
bool disconnect(const QMetaObject::Connection &connection)
void setParent(QObject *parent)
Q_D(Todo)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:04:24 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.