CuteLogger
Fast and simple logging solution for Qt based applications
jobqueue.h
1 /*
2  * Copyright (c) 2012-2024 Meltytech, LLC
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef JOBQUEUE_H
19 #define JOBQUEUE_H
20 
21 #include "jobs/abstractjob.h"
22 
23 #include <QMutex>
24 #include <QStandardItemModel>
25 
26 class JobQueue : public QStandardItemModel
27 {
28  Q_OBJECT
29 protected:
30  JobQueue(QObject *parent);
31  void startNextJob();
32 
33 public:
34  enum ColumnRole { COLUMN_ICON, COLUMN_OUTPUT, COLUMN_STATUS, COLUMN_COUNT };
35 
36  static JobQueue &singleton(QObject *parent = 0);
37  void cleanup();
38  AbstractJob *add(AbstractJob *job);
39  AbstractJob *jobFromIndex(const QModelIndex &index) const;
40  void pause();
41  void pauseCurrent();
42  void resume();
43  void resumeCurrent();
44  bool isPaused() const;
45  bool hasIncomplete() const;
46  void remove(const QModelIndex &index);
47  void removeFinished();
48  QList<AbstractJob *> jobs() const { return m_jobs; }
49  bool targetIsInProgress(const QString &target);
50 
51 signals:
52  void jobAdded();
53 
54 public slots:
55  void onProgressUpdated(QStandardItem *standardItem, int percent);
56  void onFinished(AbstractJob *job, bool isSuccess, QString time);
57 
58 private:
59  QList<AbstractJob *> m_jobs;
60  QMutex m_mutex; // protects m_jobs
61  bool m_paused;
62 };
63 
64 #define JOBS JobQueue::singleton()
65 
66 #endif // JOBQUEUE_H