File indexing completed on 2024-05-19 04:39:57
0001 /* 0002 This file is part of the KDE project 0003 0004 SPDX-FileCopyrightText: 2006 Kevin Ottens <ervin@kde.org> 0005 0006 SPDX-License-Identifier: LGPL-2.0-or-later 0007 */ 0008 0009 #ifndef KCOMPOUNDJOB_H 0010 #define KCOMPOUNDJOB_H 0011 0012 #include <util/utilexport.h> 0013 0014 #include <KJob> 0015 0016 #include <QList> 0017 0018 namespace KDevCoreAddons 0019 { 0020 class KCompoundJobPrivate; 0021 /** 0022 * @class KCompoundJob kcompoundjob.h KCompoundJob 0023 * 0024 * The base class for all jobs able to be composed of one 0025 * or more subjobs. 0026 */ 0027 class KDEVPLATFORMUTIL_EXPORT KCompoundJob : public KJob 0028 { 0029 Q_OBJECT 0030 0031 public: 0032 /** 0033 * Creates a new KCompoundJob object. 0034 * 0035 * @param parent the parent QObject 0036 */ 0037 explicit KCompoundJob(QObject *parent = nullptr); 0038 0039 /** 0040 * Destroys a KCompoundJob object. 0041 */ 0042 ~KCompoundJob() override; 0043 0044 protected: 0045 /** 0046 * Add a job that has to be finished before a result 0047 * is emitted. This has obviously to be called before 0048 * the finished() signal has been emitted by the job. 0049 * 0050 * Note that the compound job takes ownership of @p job 0051 * 0052 * @param job the subjob to add 0053 * @return true if the job has been added correctly, false otherwise 0054 */ 0055 virtual bool addSubjob(KJob *job); 0056 0057 /** 0058 * Mark a sub job as being done. 0059 * 0060 * The ownership of @p job is passed on to the caller. 0061 * 0062 * @param job the subjob to remove 0063 * @return true if the job has been removed correctly, false otherwise 0064 */ 0065 virtual bool removeSubjob(KJob *job); 0066 0067 /** 0068 * Checks if this job has subjobs running. 0069 * 0070 * @return true if we still have subjobs running, false otherwise 0071 */ 0072 bool hasSubjobs() const; 0073 0074 /** 0075 * Retrieves the list of the subjobs. 0076 * 0077 * @return the full list of sub jobs 0078 */ 0079 const QList<KJob *> &subjobs() const; 0080 0081 /** 0082 * Clears the list of subjobs. 0083 * 0084 * Note that this will *not* delete the subjobs. 0085 * Ownership of the subjobs is passed on to the caller. 0086 */ 0087 virtual void clearSubjobs(); 0088 0089 protected Q_SLOTS: 0090 /** 0091 * Called whenever a subjob finishes. 0092 * Default implementation checks for errors and propagates 0093 * to parent job, and in all cases it calls removeSubjob. 0094 * 0095 * @param job the subjob 0096 */ 0097 virtual void subjobFinished(KJob *job); 0098 0099 /** 0100 * Forward signal from subjob. 0101 * 0102 * @param job the subjob 0103 * @param plain the info message in plain text version 0104 * @param rich the info message in rich text version 0105 * @see infoMessage() 0106 */ 0107 virtual void subjobInfoMessage(KJob *job, const QString &plain, const QString &rich); 0108 0109 protected: 0110 std::unique_ptr<KCompoundJobPrivate> const d_ptr; 0111 KCompoundJob(KCompoundJobPrivate &dd, QObject *parent); 0112 0113 private: 0114 Q_DECLARE_PRIVATE(KCompoundJob) 0115 }; 0116 0117 } // namespace KDevCoreAddons 0118 0119 #endif