summaryrefslogtreecommitdiffstats
path: root/newdvdgui.cpp
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2009-09-26 22:25:02 -0400
committerJason A. Donenfeld <Jason@zx2c4.com>2009-09-26 22:25:02 -0400
commit2f0ace0e367489eb20a75a69c95d463fcb04830f (patch)
tree0d84316b9ecb04bc0becc8670e55bb7d946f33ab /newdvdgui.cpp
parentMore HandBrake progress (diff)
downloadAnyRip-2f0ace0e367489eb20a75a69c95d463fcb04830f.tar.xz
AnyRip-2f0ace0e367489eb20a75a69c95d463fcb04830f.zip
More gui work and dvd loading.
Diffstat (limited to 'newdvdgui.cpp')
-rw-r--r--newdvdgui.cpp84
1 files changed, 84 insertions, 0 deletions
diff --git a/newdvdgui.cpp b/newdvdgui.cpp
new file mode 100644
index 0000000..defa9ff
--- /dev/null
+++ b/newdvdgui.cpp
@@ -0,0 +1,84 @@
+#include "newdvdgui.h"
+#include "dvddrive.h"
+#include "encodemp4job.h"
+#include <QLabel>
+#include <QLineEdit>
+#include <QPushButton>
+#include <QVBoxLayout>
+#include <QSettings>
+#include <QHBoxLayout>
+#include <QtConcurrentRun>
+
+NewDVDGui::NewDVDGui() :
+ m_insertDvd(tr("Please insert video DVD.")),
+ m_loadingTitles(tr("<i>%1 inserted. Scanning titles...</i>")),
+ m_ripping(tr("Created new video from DVD."))
+{
+ m_watcher = new QFutureWatcher<QMap<int, QString> >;
+ m_watcher->setParent(this);
+ connect(m_watcher, SIGNAL(finished()), this, SLOT(loadedTitles()));
+ m_status = new QLabel;
+ m_dvdName = new QLineEdit;
+ connect(m_dvdName, SIGNAL(textChanged(QString)), this, SLOT(validateName(QString)));
+ m_rip = new QPushButton(tr("&Rip DVD"));
+ connect(m_rip, SIGNAL(clicked()), this, SLOT(rip()));
+ m_eject = new QPushButton(tr("&Eject"));
+ connect(m_eject, SIGNAL(clicked()), DVDDrive::instance(), SLOT(eject()));
+ QHBoxLayout *buttons = new QHBoxLayout;
+ buttons->addWidget(m_rip);
+ buttons->addWidget(m_eject);
+ QVBoxLayout *layout = new QVBoxLayout;
+ layout->addWidget(m_status, 0, Qt::AlignHCenter);
+ layout->addWidget(m_dvdName);
+ layout->addLayout(buttons);
+ if (DVDDrive::instance()->dvdInserted())
+ dvdAdded();
+ else
+ dvdRemoved();
+ connect(DVDDrive::instance(), SIGNAL(dvdAdded()), this, SLOT(dvdAdded()));
+ connect(DVDDrive::instance(), SIGNAL(dvdRemoved()), this, SLOT(dvdRemoved()));
+ setFrameStyle(QFrame::StyledPanel);
+ setLayout(layout);
+}
+void NewDVDGui::dvdAdded()
+{
+ QString name = DVDDrive::instance()->dvdName();
+ m_status->setText(m_loadingTitles.arg(name));
+ m_dvdName->setText(name); //Calls validateName
+ m_dvdName->setVisible(false);
+ m_status->setVisible(true);
+ m_rip->setVisible(false);
+ m_eject->setVisible(false);
+ m_watcher->setFuture(QtConcurrent::run(&EncodeMP4Job::titles, DVDDrive::instance()->dvdDevice()));
+}
+void NewDVDGui::validateName(const QString &name)
+{
+ QSettings settings;
+ settings.beginGroup(QLatin1String("Videos"));
+ m_rip->setEnabled(!settings.childGroups().contains(name));
+}
+void NewDVDGui::loadedTitles()
+{
+ m_titles = m_watcher->result();
+ m_rip->setVisible(true);
+ m_eject->setVisible(true);
+ m_status->setVisible(false);
+ m_dvdName->setVisible(true);
+}
+void NewDVDGui::rip()
+{
+ m_rip->setEnabled(false);
+ m_dvdName->setVisible(false);
+ m_status->setText(m_ripping);
+ m_status->setVisible(true);
+ emit newDVD(m_dvdName->text(), m_titles);
+}
+
+void NewDVDGui::dvdRemoved()
+{
+ m_status->setText(m_insertDvd);
+ m_status->setVisible(true);
+ m_dvdName->setVisible(false);
+ m_rip->setVisible(false);
+ m_eject->setVisible(false);
+}