File indexing completed on 2024-04-21 04:21:08

0001 // SPDX-FileCopyrightText: 2012 Jesper K. Pedersen <blackie@kde.org>
0002 // SPDX-FileCopyrightText: 2022 Johannes Zarl-Zierl <johannes@zarl-zierl.at>
0003 //
0004 // SPDX-License-Identifier: GPL-2.0-or-later
0005 
0006 #ifndef JOBMANAGER_H
0007 #define JOBMANAGER_H
0008 
0009 #include "JobInterface.h"
0010 #include "PriorityQueue.h"
0011 
0012 #include <QObject>
0013 
0014 namespace BackgroundTaskManager
0015 {
0016 class JobManager : public QObject
0017 {
0018     Q_OBJECT
0019 public:
0020     void addJob(JobInterface *job);
0021     static JobManager *instance();
0022     int activeJobCount() const;
0023     JobInfo *activeJob(int index) const;
0024     int futureJobCount() const;
0025     JobInfo *futureJob(int index) const;
0026     bool isPaused() const;
0027     bool hasActiveJobs() const;
0028     void togglePaused();
0029 
0030 Q_SIGNALS:
0031     void jobStarted(JobInterface *job);
0032     void jobEnded(JobInterface *job);
0033 
0034 private Q_SLOTS:
0035     void execute();
0036     void jobCompleted();
0037 
0038 private:
0039     JobManager();
0040     static JobManager *s_instance;
0041     bool shouldExecute() const;
0042 
0043     int maxJobCount() const;
0044 
0045     QList<JobInterface *> m_active;
0046     PriorityQueue m_queue;
0047     bool m_isPaused;
0048 };
0049 
0050 }
0051 
0052 #endif // JOBMANAGER_H
0053 // vi:expandtab:tabstop=4 shiftwidth=4: