File indexing completed on 2024-05-12 03:54:56

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 KCOMPOSITEJOB_H
0010 #define KCOMPOSITEJOB_H
0011 
0012 #include <kcoreaddons_export.h>
0013 #include <kjob.h>
0014 
0015 #include <QList>
0016 
0017 class KCompositeJobPrivate;
0018 /**
0019  * @class KCompositeJob kcompositejob.h KCompositeJob
0020  *
0021  * The base class for all jobs able to be composed of one
0022  * or more subjobs.
0023  */
0024 class KCOREADDONS_EXPORT KCompositeJob : public KJob
0025 {
0026     Q_OBJECT
0027 
0028 public:
0029     /**
0030      * Creates a new KCompositeJob object.
0031      *
0032      * @param parent the parent QObject
0033      */
0034     explicit KCompositeJob(QObject *parent = nullptr);
0035 
0036     /**
0037      * Destroys a KCompositeJob object.
0038      */
0039     ~KCompositeJob() override;
0040 
0041 protected:
0042     /**
0043      * Add a job that has to be finished before a result
0044      * is emitted. This has obviously to be called before
0045      * the result has been emitted by the job.
0046      *
0047      * Note that the composite job takes ownership of @p job
0048      *
0049      * @param job the subjob to add
0050      * @return true if the job has been added correctly, false otherwise
0051      */
0052     virtual bool addSubjob(KJob *job);
0053 
0054     /**
0055      * Mark a sub job as being done.
0056      *
0057      * The ownership of @p job is passed on to the caller.
0058      *
0059      * @param job the subjob to remove
0060      * @return true if the job has been removed correctly, false otherwise
0061      */
0062     virtual bool removeSubjob(KJob *job);
0063 
0064     /**
0065      * Checks if this job has subjobs running.
0066      *
0067      * @return true if we still have subjobs running, false otherwise
0068      */
0069     bool hasSubjobs() const;
0070 
0071     /**
0072      * Retrieves the list of the subjobs.
0073      *
0074      * @return the full list of sub jobs
0075      */
0076     const QList<KJob *> &subjobs() const;
0077 
0078     /**
0079      * Clears the list of subjobs.
0080      *
0081      * Note that this will *not* delete the subjobs.
0082      * Ownership of the subjobs is passed on to the caller.
0083      */
0084     void clearSubjobs();
0085 
0086 protected Q_SLOTS:
0087     /**
0088      * Called whenever a subjob finishes.
0089      * Default implementation checks for errors and propagates
0090      * to parent job, and in all cases it calls removeSubjob.
0091      *
0092      * @param job the subjob
0093      */
0094     virtual void slotResult(KJob *job);
0095 
0096     /**
0097      * Forward signal from subjob.
0098      *
0099      * @param job the subjob
0100      * @param message the info message
0101      * @see infoMessage()
0102      */
0103     virtual void slotInfoMessage(KJob *job, const QString &message);
0104 
0105 protected:
0106     KCOREADDONS_NO_EXPORT KCompositeJob(KCompositeJobPrivate &dd, QObject *parent);
0107 
0108 private:
0109     Q_DECLARE_PRIVATE(KCompositeJob)
0110 };
0111 
0112 #endif