blob: 10bfa4e009519f177f1637840b9694d0c335c104 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
#include "jobqueue.h"
#include "job.h"
#include <QDebug>
JobQueue::JobQueue(QObject *parent) :
QObject(parent),
m_jobIsRunning(false),
m_currentJob(0)
{
}
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();
m_currentJob = job;
qDebug() << "running job" << job->jobType() << "for video" << qobject_cast<Video*>(job->parent())->title();
connect(job, SIGNAL(completed(bool)), this, SLOT(jobCompleted()));
emit runningJob(job);
job->runJob();
}
void JobQueue::jobCompleted()
{
Job *job = qobject_cast<Job*>(sender());
if (job == m_currentJob) {
m_jobIsRunning = false;
m_currentJob = 0;
runNextJob();
} else
m_queue.removeAll(job);
}
|