File indexing completed on 2024-05-19 04:39:57
0001 /* 0002 This file is part of the KDE project 0003 0004 SPDX-FileCopyrightText: 2007-2008 Hamish Rodda <rodda@kde.org> 0005 SPDX-FileCopyrightText: 2023 Igor Kushnir <igorkuo@gmail.com> 0006 0007 SPDX-License-Identifier: LGPL-2.0-or-later 0008 */ 0009 0010 #ifndef KSEQUENTIALCOMPOUNDJOB_H 0011 #define KSEQUENTIALCOMPOUNDJOB_H 0012 0013 #include "kcompoundjob.h" 0014 0015 #include <util/utilexport.h> 0016 0017 namespace KDevCoreAddons 0018 { 0019 class KSequentialCompoundJobPrivate; 0020 /** 0021 * @class KSequentialCompoundJob ksequentialcompoundjob.h KSequentialCompoundJob 0022 * 0023 * A compound job that executes its subjobs one by one in order and finishes 0024 * when the last subjob finishes. Killing is propagated to subjobs. State 0025 * information, overall progress and errors are propagated from subjobs. 0026 * 0027 * The public API does not allow to add subjobs, so KSequentialCompoundJob is 0028 * usable only as a base class. addSubjob() is protected because it should be 0029 * called before start(). A derived class that adds subjobs itself can keep 0030 * addSubjob() protected. KSimpleSequentialCompoundJob makes addSubjob() public 0031 * and can be used on its own. 0032 */ 0033 class KDEVPLATFORMUTIL_EXPORT KSequentialCompoundJob : public KCompoundJob 0034 { 0035 Q_OBJECT 0036 public: 0037 /** 0038 * Creates a new KSequentialCompoundJob object. 0039 * 0040 * @param parent the parent QObject 0041 */ 0042 explicit KSequentialCompoundJob(QObject *parent = nullptr); 0043 0044 /** 0045 * Destroys a KSequentialCompoundJob object. 0046 */ 0047 ~KSequentialCompoundJob() override; 0048 0049 /** 0050 * Configures whether this compound job finishes as soon as 0051 * a subjob finishes with error. 0052 * 0053 * By default, unless @p abort is set to @c false, when a subjob 0054 * finishes with error, a compound job ignores any remaining subjobs 0055 * and finishes with the subjob's error. 0056 */ 0057 void setAbortOnSubjobError(bool abort); 0058 0059 /** 0060 * Starts running subjobs beginning with the first subjob in the list 0061 */ 0062 void start() override; 0063 0064 protected Q_SLOTS: 0065 /** 0066 * @warning The default implementations of removeSubjob() and clearSubjobs() 0067 * are inherited from KCompoundJob. They simply deregister subjobs and never 0068 * finish the compound job or start the next subjob in the list. They also 0069 * do not adjust progress data. As a result, if these functions are called, 0070 * the compound job's progress will likely never reach 100%. 0071 * 0072 * @sa addSubjob() 0073 */ 0074 0075 /** 0076 * This slot is connected to each subjob's percentChanged() signal. 0077 * 0078 * The default implementation calculates total percent value assuming equal 0079 * time is spent in each subjob and passes the value to KJob::emitPercent(). 0080 */ 0081 virtual void subjobPercentChanged(KJob *job, unsigned long percent); 0082 0083 void subjobFinished(KJob *job) override; 0084 0085 protected: 0086 /** 0087 * Adds a subjob that will run once all preceding subjobs finish 0088 * 0089 * If possible, all subjobs should be added before calling start(). 0090 * If a subjob is added after the compound job's percent() becomes 0091 * greater than zero, the overall progress can jump back. 0092 * 0093 * @see KCompoundJob::addSubjob() 0094 */ 0095 bool addSubjob(KJob *job) override; 0096 0097 bool doKill() override; 0098 0099 KSequentialCompoundJob(KSequentialCompoundJobPrivate &dd, QObject *parent); 0100 0101 private: 0102 Q_DECLARE_PRIVATE(KSequentialCompoundJob) 0103 }; 0104 0105 } // namespace KDevCoreAddons 0106 0107 #endif