summaryrefslogtreecommitdiffstats
path: root/jobqueue.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'jobqueue.cpp')
-rw-r--r--jobqueue.cpp31
1 files changed, 31 insertions, 0 deletions
diff --git a/jobqueue.cpp b/jobqueue.cpp
new file mode 100644
index 0000000..c18ffee
--- /dev/null
+++ b/jobqueue.cpp
@@ -0,0 +1,31 @@
+#include "jobqueue.h"
+#include "job.h"
+
+#include <QDebug>
+
+JobQueue::JobQueue(QObject *parent) :
+ QObject(parent),
+ m_jobIsRunning(false)
+{
+}
+void JobQueue::addJob(Job *job)
+{
+ m_queue.enqueue(job);
+ if (!m_jobIsRunning)
+ runNextJob();
+}
+void JobQueue::runNextJob()
+{
+ if (m_queue.isEmpty())
+ return;
+ m_jobIsRunning = true;
+ Job *job = m_queue.dequeue();
+ qDebug() << "running job" << job->jobType() << "for video" << qobject_cast<Video*>(job->parent())->title();
+ connect(job, SIGNAL(completed(bool)), this, SLOT(jobCompleted()));
+ job->runJob();
+}
+void JobQueue::jobCompleted()
+{
+ m_jobIsRunning = false;
+ runNextJob();
+}