CuteLogger
Fast and simple logging solution for Qt based applications
jobqueue.h
1 /*
2  * Copyright (c) 2012-2017 Meltytech, LLC
3  * Author: Dan Dennedy <dan@dennedy.org>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef JOBQUEUE_H
20 #define JOBQUEUE_H
21 
22 #include "jobs/abstractjob.h"
23 #include <QStandardItemModel>
24 #include <QMutex>
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 {
35  COLUMN_ICON,
36  COLUMN_OUTPUT,
37  COLUMN_STATUS,
38  COLUMN_COUNT
39  };
40 
41  static JobQueue& singleton(QObject* parent = 0);
42  void cleanup();
43  AbstractJob* add(AbstractJob *job);
44  AbstractJob* jobFromIndex(const QModelIndex& index) const;
45  void pause();
46  void resume();
47  bool isPaused() const;
48  bool hasIncomplete() const;
49  void remove(const QModelIndex& index);
50 
51 signals:
52  void jobAdded();
53 
54 public slots:
55  void onProgressUpdated(QStandardItem* standardItem, int percent);
56  void onFinished(AbstractJob* job, bool isSuccess);
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