From 6726c0af8409bafee259991bd4ccc8e8cbdb4544 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Sun, 27 Sep 2009 01:59:19 -0400 Subject: Add from ISO --- AnyRip.pro | 6 +++-- dvdimagejobgui.cpp | 4 ++-- dvdimagejobgui.h | 4 ++-- encodemp4jobgui.cpp | 4 ++-- encodemp4jobgui.h | 4 ++-- mainwindow.cpp | 28 ++++++++++++++++-------- mainwindow.h | 1 + newdvdgui.cpp | 3 ++- newdvdgui.h | 4 ++-- newimagegui.cpp | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++ newimagegui.h | 26 ++++++++++++++++++++++ video.cpp | 35 ++++++++++++++++++++++++++--- video.h | 1 + videogui.cpp | 33 +++++++++++++++++++++++----- videogui.h | 7 ++++-- 15 files changed, 190 insertions(+), 33 deletions(-) create mode 100644 newimagegui.cpp create mode 100644 newimagegui.h diff --git a/AnyRip.pro b/AnyRip.pro index 2bf4c2e..46cbd14 100644 --- a/AnyRip.pro +++ b/AnyRip.pro @@ -12,7 +12,8 @@ SOURCES += main.cpp \ videogui.cpp \ mainwindow.cpp \ encodemp4jobgui.cpp \ - newdvdgui.cpp + newdvdgui.cpp \ + newimagegui.cpp HEADERS += dvdimagejob.h \ dvdimagejobgui.h \ job.h \ @@ -26,7 +27,8 @@ HEADERS += dvdimagejob.h \ videogui.h \ mainwindow.h \ encodemp4jobgui.h \ - newdvdgui.h + newdvdgui.h \ + newimagegui.h LIBS += -ldvdcss \ -ldvdread QT += dbus diff --git a/dvdimagejobgui.cpp b/dvdimagejobgui.cpp index 6d88a61..7341617 100644 --- a/dvdimagejobgui.cpp +++ b/dvdimagejobgui.cpp @@ -12,11 +12,11 @@ DVDImageJobGui::DVDImageJobGui(DVDImageJob *job) : m_progressBar = new QProgressBar; m_progressLabel = new QLabel; QVBoxLayout *layout = new QVBoxLayout; - layout->addWidget(new QLabel(tr("Copying DVD ISO of %1").arg(job->video()->title()))); layout->addWidget(m_progressBar); layout->addWidget(m_progressLabel); setLayout(layout); - setFrameStyle(QFrame::StyledPanel); + setTitle(tr("Copying DVD ISO of %1").arg(job->video()->title())); + setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); connect(job, SIGNAL(extractProgress(int,int)), this, SLOT(extractProgress(int,int))); } void DVDImageJobGui::extractProgress(int current, int maximum) diff --git a/dvdimagejobgui.h b/dvdimagejobgui.h index 58a7fa9..ec7679f 100644 --- a/dvdimagejobgui.h +++ b/dvdimagejobgui.h @@ -1,13 +1,13 @@ #ifndef DVDIMAGEJOBGUI_H #define DVDIMAGEJOBGUI_H -#include +#include #include class QLabel; class QProgressBar; class DVDImageJob; -class DVDImageJobGui : public QFrame +class DVDImageJobGui : public QGroupBox { Q_OBJECT diff --git a/encodemp4jobgui.cpp b/encodemp4jobgui.cpp index 5a679f1..034bb10 100644 --- a/encodemp4jobgui.cpp +++ b/encodemp4jobgui.cpp @@ -10,11 +10,11 @@ EncodeMP4JobGui::EncodeMP4JobGui(EncodeMP4Job *job) m_progressBar->setMaximum(10000); m_progressLabel = new QLabel; QVBoxLayout *layout = new QVBoxLayout; - layout->addWidget(new QLabel(tr("Encoding MP4 of %1").arg(job->video()->title()))); layout->addWidget(m_progressBar); layout->addWidget(m_progressLabel); setLayout(layout); - setFrameStyle(QFrame::StyledPanel); + setTitle(tr("Encoding MP4 of %1").arg(job->video()->title())); + setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); connect(job, SIGNAL(encodeProgress(int,int,float,float,float,QTime)), this, SLOT(encodeProgress(int,int,float,float,float,QTime))); } void EncodeMP4JobGui::encodeProgress(int currentTask, int totalTasks, float percent, float currentFps, float avgFps, QTime timeRemaining) diff --git a/encodemp4jobgui.h b/encodemp4jobgui.h index cd90d5c..24646fe 100644 --- a/encodemp4jobgui.h +++ b/encodemp4jobgui.h @@ -1,13 +1,13 @@ #ifndef ENCODEMP4JOBGUI_H #define ENCODEMP4JOBGUI_H -#include +#include #include class QLabel; class QProgressBar; class EncodeMP4Job; -class EncodeMP4JobGui : public QFrame +class EncodeMP4JobGui : public QGroupBox { Q_OBJECT diff --git a/mainwindow.cpp b/mainwindow.cpp index 9723e70..29925ec 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -5,6 +5,7 @@ #include "dvddrive.h" #include "job.h" #include "newdvdgui.h" +#include "newimagegui.h" #include #include #include @@ -19,13 +20,16 @@ MainWindow::MainWindow() m_videoGuis = new QVBoxLayout; m_jobGuis = new QVBoxLayout; QGridLayout *layout = new QGridLayout; - layout->addWidget(new QLabel(tr("Video Queue")), 0, 0); - layout->addWidget(new QLabel(tr("Job Queue")), 0, 1); - layout->addLayout(m_videoGuis, 1, 0); - layout->addLayout(m_jobGuis, 1, 1); + layout->addWidget(new QLabel(tr("Video Queue")), 0, 0, Qt::AlignTop | Qt::AlignHCenter); + layout->addWidget(new QLabel(tr("Job Queue")), 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)), this, SLOT(newVideoFromDVD(QString,QMap))); - m_jobGuis->addWidget(newDvdGui); + 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); QSettings settings; settings.beginGroup(QLatin1String("Videos")); foreach(QString title, settings.childGroups()) { @@ -39,19 +43,25 @@ MainWindow::MainWindow() } void MainWindow::addVideo(Video *video) { - m_videoGuis->addWidget(video->widget()); + m_videoGuis->addWidget(video->widget(), 0, Qt::AlignTop); m_queue->newVideo(video); } -void MainWindow::newVideoFromDVD(QString name, QMap titles) +void MainWindow::newVideoFromDVD(QString name, QMap titles) //TODO: use const QString &name { - Video *video = new Video(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()); + m_jobGuis->addWidget(job->widget(), 0, Qt::AlignTop); } void MainWindow::completedJob(bool success) { diff --git a/mainwindow.h b/mainwindow.h index 18ac521..f2f0af7 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -22,6 +22,7 @@ private: void addVideo(Video *video); private slots: void newVideoFromDVD(QString name, QMap titles); + void newVideoFromImage(const QString &path, const QString &name); void runningJob(Job *job); void completedJob(bool success); }; diff --git a/newdvdgui.cpp b/newdvdgui.cpp index defa9ff..3bceaa2 100644 --- a/newdvdgui.cpp +++ b/newdvdgui.cpp @@ -37,7 +37,8 @@ NewDVDGui::NewDVDGui() : dvdRemoved(); connect(DVDDrive::instance(), SIGNAL(dvdAdded()), this, SLOT(dvdAdded())); connect(DVDDrive::instance(), SIGNAL(dvdRemoved()), this, SLOT(dvdRemoved())); - setFrameStyle(QFrame::StyledPanel); + setTitle(tr("New Video from DVD")); + setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); setLayout(layout); } void NewDVDGui::dvdAdded() diff --git a/newdvdgui.h b/newdvdgui.h index 0096de4..28d97c5 100644 --- a/newdvdgui.h +++ b/newdvdgui.h @@ -1,14 +1,14 @@ #ifndef NEWDVDGUI_H #define NEWDVDGUI_H -#include +#include #include #include class QLineEdit; class QLabel; class QPushButton; -class NewDVDGui : public QFrame +class NewDVDGui : public QGroupBox { Q_OBJECT public: diff --git a/newimagegui.cpp b/newimagegui.cpp new file mode 100644 index 0000000..ebda750 --- /dev/null +++ b/newimagegui.cpp @@ -0,0 +1,63 @@ +#include "newimagegui.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include + +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(name)); +} +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()); +} diff --git a/newimagegui.h b/newimagegui.h new file mode 100644 index 0000000..bc43668 --- /dev/null +++ b/newimagegui.h @@ -0,0 +1,26 @@ +#ifndef NEWIMAGEGUI_H +#define NEWIMAGEGUI_H + +#include +class QLineEdit; +class QPushButton; + +class NewImageGui : public QGroupBox +{ + Q_OBJECT +public: + NewImageGui(); +private: + QLineEdit *m_dvdName; + QLineEdit *m_imagePath; + QPushButton *m_importImageButton; +private slots: + void validatePath(const QString &path); + void validateName(const QString &name); + void browse(); + void importImage(); +signals: + void newImage(const QString &path, const QString &name); +}; + +#endif // NEWIMAGEGUI_H diff --git a/video.cpp b/video.cpp index 39d1e8a..041fb48 100644 --- a/video.cpp +++ b/video.cpp @@ -7,6 +7,8 @@ #include "videogui.h" #include "dvddrive.h" #include +#include +#include #include Video::Video(QString title, QObject *parent) : @@ -15,10 +17,12 @@ Video::Video(QString title, QObject *parent) : m_jobsInProgress(QBitArray(6)), m_dvdTitle(1) { - QString topKey = QString("Videos/%1").arg(title.replace(QChar('/'), QChar('-'))); - m_settingsKey = topKey.append(QLatin1String("/%1")); + title = title.replace(QChar('/'), QChar('-')); + m_settingsKey = QString("Videos/%1/%2").arg(title); QSettings settings; - if (settings.contains(topKey)) { + settings.beginGroup("Videos"); + if (settings.childGroups().contains(title)) { + settings.endGroup(); m_jobsCompleted = settings.value(m_settingsKey.arg("Jobs Completed")).toBitArray(); if (m_jobsCompleted.size() != 6) m_jobsCompleted.resize(6); @@ -120,6 +124,20 @@ void Video::setSubtitle(const QIODevice &input) m_jobsInProgress.setBit(Video::Subtitle, false); emit jobCompleted(Video::Subtitle, true); } +void Video::setDvdImage(const QString &path) +{ + m_jobsInProgress.setBit(Video::DVDImage, true); + QFileInfo image(m_imagePath); + if (image.exists() && image != QFileInfo(path)) + QFile::remove(m_imagePath); + QFile::rename(path, m_imagePath); + m_dvdTitle = 1; + m_dvdTitles = EncodeMP4Job::titles(m_imagePath); + m_jobsCompleted.setBit(Video::DVDImage, true); + saveState(); + m_jobsInProgress.setBit(Video::DVDImage, false); + emit jobCompleted(Video::DVDImage, true); +} void Video::setPoster(const QIODevice &input) { m_jobsInProgress.setBit(Video::Poster, true); @@ -147,7 +165,18 @@ int Video::dvdTitle() const } void Video::setDvdTitle(int title) { + if (m_dvdTitle == title) + return; m_dvdTitle = title; + if (m_jobsCompleted.at(Video::EncodeMP4)) { + m_jobsCompleted.setBit(Video::EncodeMP4, false); + emit jobCompleted(Video::EncodeMP4, false); + if(m_jobsCompleted.at(Video::Upload)) { + m_jobsCompleted.setBit(Video::Upload, false); + emit jobCompleted(Video::Upload, false); + } + //TODO: if its already encoding or uploading, cancel those jobs + } saveState(); } QMap Video::dvdTitles() const diff --git a/video.h b/video.h index 139dbf6..e5449dc 100644 --- a/video.h +++ b/video.h @@ -22,6 +22,7 @@ public: enum Jobs { DVDImage, EncodeMP4, Upload, TitleLoad, Subtitle, Poster }; void setSubtitle(const QIODevice &input); void setPoster(const QIODevice &input); + void setDvdImage(const QString &path); DVDImageJob* dvdImageJob(); EncodeMP4Job* encodeMP4Job(); UploadJob* uploadJob(); diff --git a/videogui.cpp b/videogui.cpp index 02aad03..139bfb8 100644 --- a/videogui.cpp +++ b/videogui.cpp @@ -1,7 +1,10 @@ #include "videogui.h" #include #include +#include #include +#include +#include VideoGui::VideoGui(Video *video) : m_video(video) @@ -19,6 +22,23 @@ VideoGui::VideoGui(Video *video) : m_titleLoadCheck = new QCheckBox(tr("Title-Loaded"), this); m_titleLoadCheck->setChecked(video->isJobCompleted(Video::TitleLoad)); m_titleLoadCheck->setEnabled(false); + m_titleSelector = new QComboBox; + QMapIterator i(video->dvdTitles()); + while (i.hasNext()) { + i.next(); + m_titleSelector->addItem(QString("Title %1: %2").arg(QString::number(i.key())).arg(i.value()), i.key()); + } + int currentIndex = m_titleSelector->findData(video->dvdTitle()); + if (currentIndex == -1) + currentIndex = 0; + m_titleSelector->setCurrentIndex(currentIndex); + connect(m_titleSelector, SIGNAL(currentIndexChanged(int)), this, SLOT(titleChanged(int))); + QGridLayout *checkGrid = new QGridLayout; + checkGrid->addWidget(m_imageCheck, 0, 0); + checkGrid->addWidget(m_encodeCheck, 0, 1); + checkGrid->addWidget(m_uploadCheck, 1, 0); + checkGrid->addWidget(m_titleLoadCheck, 1, 1); + checkGrid->addWidget(m_titleSelector, 0, 2); m_subtitleCheck = new QCheckBox(tr("Found Subtitle"), this); m_subtitleCheck->setChecked(video->isJobCompleted(Video::Subtitle)); m_posterCheck = new QCheckBox(tr("Found Poster"), this); @@ -26,15 +46,12 @@ VideoGui::VideoGui(Video *video) : //TODO: actions for checking subtitle and poster check to actually do it connect(video, SIGNAL(jobCompleted(Video::Jobs,bool)), this, SLOT(jobCompleted(Video::Jobs,bool))); QHBoxLayout *layout = new QHBoxLayout; - layout->addWidget(new QLabel(QString("%1: ").arg(video->title()))); - layout->addWidget(m_imageCheck); - layout->addWidget(m_encodeCheck); - layout->addWidget(m_uploadCheck); - layout->addWidget(m_titleLoadCheck); + layout->addLayout(checkGrid); layout->addWidget(m_subtitleCheck); layout->addWidget(m_posterCheck); setLayout(layout); - setFrameStyle(QFrame::StyledPanel); + setTitle(video->title()); + setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); } void VideoGui::jobCompleted(Video::Jobs jobType, bool success) { @@ -59,3 +76,7 @@ void VideoGui::jobCompleted(Video::Jobs jobType, bool success) break; } } +void VideoGui::titleChanged(int index) +{ + m_video->setDvdTitle(m_titleSelector->itemData(index).toInt()); +} diff --git a/videogui.h b/videogui.h index 58e20ad..dfbb1d2 100644 --- a/videogui.h +++ b/videogui.h @@ -1,12 +1,13 @@ #ifndef VIDEOGUI_H #define VIDEOGUI_H -#include +#include #include "video.h" class QCheckBox; +class QComboBox; class Video; -class VideoGui : public QFrame +class VideoGui : public QGroupBox { Q_OBJECT public: @@ -18,9 +19,11 @@ private: QCheckBox *m_titleLoadCheck; QCheckBox *m_subtitleCheck; QCheckBox *m_posterCheck; + QComboBox *m_titleSelector; Video *m_video; private slots: void jobCompleted(Video::Jobs jobType, bool success); + void titleChanged(int index); }; #endif // VIDEOGUI_H -- cgit v1.2.3-59-g8ed1b