summaryrefslogtreecommitdiffstats
path: root/jobqueue.cpp
blob: be747d21f86c4983870847c7a5fb4a91bf3f7c8c (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
#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()));
	emit runningJob(job);
	job->runJob();
}
void JobQueue::jobCompleted()
{
	m_jobIsRunning = false;
	runNextJob();
}