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 | #ifndef KCOMPOSITEJOB_H |
10 | #define KCOMPOSITEJOB_H |
11 | |
12 | #include <kcoreaddons_export.h> |
13 | #include <kjob.h> |
14 | |
15 | #include <QList> |
16 | |
17 | class KCompositeJobPrivate; |
18 | /*! |
19 | * \class KCompositeJob |
20 | * \inmodule KCoreAddons |
21 | * |
22 | * \brief The base class for all jobs able to be composed of one |
23 | * or more subjobs. |
24 | */ |
25 | class KCOREADDONS_EXPORT KCompositeJob : public KJob |
26 | { |
27 | Q_OBJECT |
28 | |
29 | public: |
30 | /*! |
31 | * Creates a new KCompositeJob object. |
32 | * |
33 | * \a parent the parent QObject |
34 | */ |
35 | explicit KCompositeJob(QObject *parent = nullptr); |
36 | |
37 | ~KCompositeJob() override; |
38 | |
39 | protected: |
40 | /*! |
41 | * Add a job that has to be finished before a result |
42 | * is emitted. This has obviously to be called before |
43 | * the result has been emitted by the job. |
44 | * |
45 | * Note that the composite job takes ownership of \a job |
46 | * |
47 | * \a job the subjob to add |
48 | * |
49 | * Returns \c true if the job has been added correctly, false otherwise |
50 | */ |
51 | virtual bool addSubjob(KJob *job); |
52 | |
53 | /*! |
54 | * Mark a sub job as being done. |
55 | * |
56 | * The ownership of \a job is passed on to the caller. |
57 | * |
58 | * \a job the subjob to remove |
59 | * |
60 | * Returns \c true if the job has been removed correctly, false otherwise |
61 | */ |
62 | virtual bool removeSubjob(KJob *job); |
63 | |
64 | /*! |
65 | * Checks if this job has subjobs running. |
66 | * |
67 | * Returns \c true if we still have subjobs running, false otherwise |
68 | */ |
69 | bool hasSubjobs() const; |
70 | |
71 | /*! |
72 | * Returns the full list of sub jobs |
73 | */ |
74 | const QList<KJob *> &subjobs() const; |
75 | |
76 | /*! |
77 | * Clears the list of subjobs. |
78 | * |
79 | * Note that this will *not* delete the subjobs. |
80 | * Ownership of the subjobs is passed on to the caller. |
81 | */ |
82 | void clearSubjobs(); |
83 | |
84 | protected Q_SLOTS: |
85 | /*! |
86 | * Called whenever a subjob finishes. |
87 | * |
88 | * Default implementation checks for errors and propagates |
89 | * to parent job, and in all cases it calls removeSubjob. |
90 | * |
91 | * \a job the subjob |
92 | */ |
93 | virtual void slotResult(KJob *job); |
94 | |
95 | /*! |
96 | * Forward signal from subjob. |
97 | * |
98 | * \a job the subjob |
99 | * |
100 | * \a message the info message |
101 | * |
102 | * \sa infoMessage() |
103 | */ |
104 | virtual void slotInfoMessage(KJob *job, const QString &message); |
105 | |
106 | protected: |
107 | KCOREADDONS_NO_EXPORT KCompositeJob(KCompositeJobPrivate &dd, QObject *parent); |
108 | |
109 | private: |
110 | Q_DECLARE_PRIVATE(KCompositeJob) |
111 | }; |
112 | |
113 | #endif |
114 | |