summaryrefslogtreecommitdiffstats
path: root/mainwindow.cpp
blob: e89df5aea3f943c644975576b227a6b8de591a98 (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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include "mainwindow.h"
#include "video.h"
#include "videogui.h"
#include "videoqueue.h"
#include "dvddrive.h"
#include "job.h"
#include "newdvdgui.h"
#include "newimagegui.h"
#include <QGridLayout>
#include <QHBoxLayout>
#include <QSettings>
#include <QLabel>
#include <QPushButton>
#include <QDebug>

MainWindow::MainWindow()
{
	QSettings settings;
	settings.beginGroup(QLatin1String("Videos"));
	//We delay adding because addVideo needs things to be contructed.
	//We need to remove bad entries though because other constructors here rely on our settings
	QList<Video*> toAdd;
	foreach(QString title, settings.childGroups()) {
		Video *video = new Video(title, this);
		if (video->isJobCompleted(Video::DVDImage))
			toAdd.append(video);
		else
			settings.remove(title);
	}
	m_queue = new VideoQueue;
	connect(m_queue, SIGNAL(runningJob(Job*)), this, SLOT(runningJob(Job*)));
	m_videoGuis = new QVBoxLayout;
	m_jobGuis = new QVBoxLayout;
	QGridLayout *layout = new QGridLayout;
	layout->addWidget(new QLabel(tr("<b>Video Queue</b>")), 0, 0, Qt::AlignTop | Qt::AlignHCenter);
	layout->addWidget(new QLabel(tr("<b>Job Queue</b>")), 0, 1, Qt::AlignTop | Qt::AlignHCenter);
	layout->addLayout(m_videoGuis, 1, 0, Qt::AlignTop);
	layout->addLayout(m_jobGuis, 1, 1, Qt::AlignTop);
	NewDVDGui *newDvdGui = new NewDVDGui;
	connect(newDvdGui, SIGNAL(newDVD(QString,QMap<int,QString>)), this, SLOT(newVideoFromDVD(QString,QMap<int,QString>)));
	m_jobGuis->addWidget(newDvdGui, 0, Qt::AlignTop);
	NewImageGui *newImageGui = new NewImageGui;
	connect(newImageGui, SIGNAL(newImage(QString,QString)), this, SLOT(newVideoFromImage(QString,QString)));
	m_jobGuis->addWidget(newImageGui, 0, Qt::AlignTop);
	foreach (Video *video, toAdd)
		addVideo(video);
	setLayout(layout);
}
void MainWindow::addVideo(Video *video)
{
	m_videoGuis->addWidget(video->widget(), 0, Qt::AlignTop);
	m_queue->newVideo(video);
}
void MainWindow::newVideoFromDVD(QString name, QMap<int, QString> titles) //TODO: use const QString &name
{
	Video *video = new Video(name, this);
	video->setDvdTitles(titles);
	addVideo(video);
}
void MainWindow::newVideoFromImage(const QString &path, const QString &name)
{
	Video *video = new Video(name, this);
	video->setDvdImage(path);
	addVideo(video);
}
void MainWindow::runningJob(Job *job)
{
	connect(job, SIGNAL(completed(bool)), this, SLOT(completedJob(bool)));
	m_jobGuis->addWidget(job->widget(), 0, Qt::AlignTop);
}
void MainWindow::completedJob(bool success)
{
	//TODO: do something with [lack of] success
	delete qobject_cast<Job*>(sender())->widget();
}