1/* This file is part of the KDE project
2 Copyright (C) 2006 Kevin Ottens <ervin@kde.org>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License version 2 as published by the Free Software Foundation.
7
8 This library is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 Library General Public License for more details.
12
13 You should have received a copy of the GNU Library General Public License
14 along with this library; see the file COPYING.LIB. If not, write to
15 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 Boston, MA 02110-1301, USA.
17
18*/
19
20#ifndef KCOMPOSITEJOB_H
21#define KCOMPOSITEJOB_H
22
23#include <kdecore_export.h>
24#include <kjob.h>
25
26#include <QtCore/QList>
27
28class KCompositeJobPrivate;
29/**
30 * The base class for all jobs able to be composed of one
31 * or more subjobs.
32 */
33class KDECORE_EXPORT KCompositeJob : public KJob
34{
35 Q_OBJECT
36
37public:
38 /**
39 * Creates a new KCompositeJob object.
40 *
41 * @param parent the parent QObject
42 */
43 explicit KCompositeJob( QObject *parent = 0 );
44
45 /**
46 * Destroys a KCompositeJob object.
47 */
48 virtual ~KCompositeJob();
49
50protected:
51 /**
52 * Add a job that has to be finished before a result
53 * is emitted. This has obviously to be called before
54 * the result has been emitted by the job.
55 *
56 * Note that the composite job takes ownership of @p job
57 *
58 * @param job the subjob to add
59 * @return true if the job has been added correctly, false otherwise
60 */
61 virtual bool addSubjob( KJob *job );
62
63 /**
64 * Mark a sub job as being done.
65 *
66 * The ownership of @p job is passed on to the caller.
67 *
68 * @param job the subjob to remove
69 * @return true if the job has been removed correctly, false otherwise
70 */
71 virtual bool removeSubjob( KJob *job );
72
73 /**
74 * Checks if this job has subjobs running.
75 *
76 * @return true if we still have subjobs running, false otherwise
77 */
78 bool hasSubjobs();
79
80 /**
81 * Retrieves the list of the subjobs.
82 *
83 * @return the full list of sub jobs
84 */
85 const QList<KJob*> &subjobs() const;
86
87 /**
88 * Clears the list of subjobs.
89 *
90 * Note that this will *not* delete the subjobs.
91 * Ownership of the subjobs is passed on to the caller.
92 */
93 void clearSubjobs();
94
95protected Q_SLOTS:
96 /**
97 * Called whenever a subjob finishes.
98 * Default implementation checks for errors and propagates
99 * to parent job, and in all cases it calls removeSubjob.
100 *
101 * @param job the subjob
102 */
103 virtual void slotResult( KJob *job );
104
105 /**
106 * Forward signal from subjob.
107 *
108 * @param job the subjob
109 * @param plain the info message in plain text version
110 * @param rich the info message in rich text version
111 * @see infoMessage()
112 */
113 virtual void slotInfoMessage( KJob *job, const QString &plain, const QString &rich );
114
115protected:
116 KCompositeJob(KCompositeJobPrivate &dd, QObject *parent);
117private:
118 Q_DECLARE_PRIVATE(KCompositeJob)
119};
120
121#endif
122