CuteLogger
Fast and simple logging solution for Qt based applications
jobqueue.h
1/*
2 * Copyright (c) 2012-2019 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 resume();
46 bool isPaused() const;
47 bool hasIncomplete() const;
48 void remove(const QModelIndex &index);
49 void removeFinished();
50 QList<AbstractJob *> jobs() const
51 {
52 return m_jobs;
53 }
54
55signals:
56 void jobAdded();
57
58public slots:
59 void onProgressUpdated(QStandardItem *standardItem, int percent);
60 void onFinished(AbstractJob *job, bool isSuccess, QString time);
61
62private:
63 QList<AbstractJob *> m_jobs;
64 QMutex m_mutex; // protects m_jobs
65 bool m_paused;
66};
67
68#define JOBS JobQueue::singleton()
69
70#endif // JOBQUEUE_H