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#include <QStandardItemModel>
23#include <QMutex>
24
25class JobQueue : public QStandardItemModel
26{
27 Q_OBJECT
28protected:
29 JobQueue(QObject *parent);
30 void startNextJob();
31
32public:
33 enum ColumnRole {
34 COLUMN_ICON,
35 COLUMN_OUTPUT,
36 COLUMN_STATUS,
37 COLUMN_COUNT
38 };
39
40 static JobQueue &singleton(QObject *parent = 0);
41 void cleanup();
42 AbstractJob *add(AbstractJob *job);
43 AbstractJob *jobFromIndex(const QModelIndex &index) const;
44 void pause();
45 void pauseCurrent();
46 void resume();
47 void resumeCurrent();
48 bool isPaused() const;
49 bool hasIncomplete() const;
50 void remove(const QModelIndex &index);
51 void removeFinished();
52 QList<AbstractJob *> jobs() const
53 {
54 return m_jobs;
55 }
56
57signals:
58 void jobAdded();
59
60public slots:
61 void onProgressUpdated(QStandardItem *standardItem, int percent);
62 void onFinished(AbstractJob *job, bool isSuccess, QString time);
63
64private:
65 QList<AbstractJob *> m_jobs;
66 QMutex m_mutex; // protects m_jobs
67 bool m_paused;
68};
69
70#define JOBS JobQueue::singleton()
71
72#endif // JOBQUEUE_H