summaryrefslogtreecommitdiffstats
path: root/newimagegui.cpp
blob: 69298ad519e11422df09142e5506328e786f5d66 (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
#include "newimagegui.h"
#include <QLabel>
#include <QLineEdit>
#include <QPushButton>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QFile>
#include <QFileInfo>
#include <QFileDialog>
#include <QSettings>

NewImageGui::NewImageGui()
{
	m_dvdName = new QLineEdit;
	m_dvdName->setVisible(false);
	connect(m_dvdName, SIGNAL(textChanged(QString)), this, SLOT(validateName(QString)));
	m_imagePath = new QLineEdit(tr("Select a DVD image"));
	m_imagePath->setEnabled(false);
	connect(m_imagePath, SIGNAL(textChanged(QString)), this, SLOT(validatePath(QString)));
	QPushButton *browseButton = new QPushButton(tr("&Browse"));
	connect(browseButton, SIGNAL(clicked()), this, SLOT(browse()));
	m_importImageButton = new QPushButton(tr("&Import Image"));
	m_importImageButton->setEnabled(false);
	connect(m_importImageButton, SIGNAL(clicked()), this, SLOT(importImage()));
	QHBoxLayout *pathArea = new QHBoxLayout;
	pathArea->addWidget(m_imagePath);
	pathArea->addWidget(browseButton);
	QVBoxLayout *layout = new QVBoxLayout;
	layout->addLayout(pathArea);
	layout->addWidget(m_dvdName);
	layout->addWidget(m_importImageButton);
	setLayout(layout);
	setTitle(tr("New Video from DVD Image"));
	setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
}
void NewImageGui::validatePath(const QString &path)
{
	if (path.toLower().endsWith(".iso") && QFile::exists(path)) {
		m_dvdName->setText(QFileInfo(path).baseName());
		m_dvdName->setVisible(true);
	} else {
		m_dvdName->setText(QString());
		m_dvdName->setVisible(false);
		m_importImageButton->setEnabled(false);
	}
}
void NewImageGui::validateName(const QString &name)
{
	QSettings settings;
	settings.beginGroup(QLatin1String("Videos"));
	m_importImageButton->setEnabled(!settings.childGroups().contains(QString(name).replace(QChar('/'), QChar('-'))) && !name.trimmed().isEmpty());
}
void NewImageGui::browse()
{
	QString path = QFileDialog::getOpenFileName(this, tr("Select DVD Image"), QString(), tr("DVD Images (*.iso)"));
	if (!path.isNull())
		m_imagePath->setText(path);
}
void NewImageGui::importImage()
{
	m_importImageButton->setEnabled(false);
	emit newImage(m_imagePath->text(), m_dvdName->text());
}