diff options
-rw-r--r-- | .gitignore | 6 | ||||
-rw-r--r-- | AnyRip.pro | 12 | ||||
-rw-r--r-- | dvdimagejob.cpp (renamed from dvdimage.cpp) | 26 | ||||
-rw-r--r-- | dvdimagejob.h (renamed from dvdimage.h) | 15 | ||||
-rw-r--r-- | imagegui.cpp | 9 | ||||
-rw-r--r-- | imagegui.h | 1 | ||||
-rw-r--r-- | job.cpp | 19 | ||||
-rw-r--r-- | job.h | 25 | ||||
-rw-r--r-- | video.cpp | 34 | ||||
-rw-r--r-- | video.h | 22 |
10 files changed, 150 insertions, 19 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ebf3c5e --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +*.o +moc_*.cpp +*.pro.user +Makefile +*.iso +AnyRip @@ -1,7 +1,11 @@ SOURCES += main.cpp \ - dvdimage.cpp \ - imagegui.cpp -HEADERS += dvdimage.h \ - imagegui.h + dvdimagejob.cpp \ + imagegui.cpp \ + job.cpp \ + video.cpp +HEADERS += dvdimagejob.h \ + imagegui.h \ + job.h \ + video.h LIBS += -ldvdcss \ -ldvdread diff --git a/dvdimage.cpp b/dvdimagejob.cpp index 35b7a7b..89e89e0 100644 --- a/dvdimage.cpp +++ b/dvdimagejob.cpp @@ -1,7 +1,7 @@ // Much of the CSS logic comes from Bryan Ford's Netsteria // http://www.google.com/codesearch/p?hl=en&sa=N&cd=10&ct=rc#PY4_fj37fsw/uia/netsteria/dvd/read.cc&q=DVDCSS_SEEK_KEY -#include "dvdimage.h" +#include "dvdimagejob.h" #include <stdio.h> #include <stdlib.h> #include <limits.h> @@ -12,7 +12,13 @@ #include <QIODevice> #include <QFile> -int DVDImage::cmpvob(const void *p1, const void *p2) +DVDImageJob::DVDImageJob(Video *video) + : Job(video) +{ + //Initialize something... +} + +int DVDImageJob::cmpvob(const void *p1, const void *p2) { vobfile *v1 = (vobfile*)p1; vobfile *v2 = (vobfile*)p2; @@ -24,7 +30,17 @@ int DVDImage::cmpvob(const void *p1, const void *p2) return 0; } -bool DVDImage::saveImageToPath(const QString &dvdDevice, const QString &path) +bool DVDImageJob::executeJob() +{ + return saveImageToPath(QLatin1String("/dev/dvd"), QLatin1String("image.iso")); //Fix up +} + +Video::Jobs DVDImageJob::jobType() +{ + return Video::DVDImage; +} + +bool DVDImageJob::saveImageToPath(const QString &dvdDevice, const QString &path) { QFile file(path); file.open(QFile::WriteOnly); @@ -33,7 +49,7 @@ bool DVDImage::saveImageToPath(const QString &dvdDevice, const QString &path) return ret; } -bool DVDImage::saveImageToDevice(const QString &dvdDevice, QIODevice &out) +bool DVDImageJob::saveImageToDevice(const QString &dvdDevice, QIODevice &out) { dvd_reader_t *dvdr = DVDOpen(dvdDevice.toStdString().c_str()); if (!dvdr) { @@ -105,7 +121,7 @@ bool DVDImage::saveImageToDevice(const QString &dvdDevice, QIODevice &out) return false; } - int blkno = 0; + int blkno = 3943433; int curvob = 0; while (1) { //printf("% 3d%%: block %d of %d (byte %lld of %lld)\r", diff --git a/dvdimage.h b/dvdimagejob.h index 0ee1275..6d97b6b 100644 --- a/dvdimage.h +++ b/dvdimagejob.h @@ -1,15 +1,17 @@ -#ifndef DVDIMAGE_H -#define DVDIMAGE_H +#ifndef DVDIMAGEJOB_H +#define DVDIMAGEJOB_H -#include <QObject> +#include "job.h" class QIODevice; -class DVDImage : public QObject +class DVDImageJob : public Job { Q_OBJECT public: + DVDImageJob(Video *video); bool saveImageToDevice(const QString &dvdDevice, QIODevice &out); bool saveImageToPath(const QString &dvdDevice, const QString &path); + Video::Jobs jobType(); private: static int cmpvob(const void *p1, const void *p2); @@ -17,8 +19,11 @@ private: int32_t start, end; } vobfile; +protected: + bool executeJob(); + signals: void extractProgress(int current, int total); }; -#endif // DVDIMAGE_H +#endif // DVDIMAGEJOB_H diff --git a/imagegui.cpp b/imagegui.cpp index 9d09de2..5180c22 100644 --- a/imagegui.cpp +++ b/imagegui.cpp @@ -1,5 +1,5 @@ #include "imagegui.h" -#include "dvdimage.h" +#include "dvdimagejob.h" #include <dvdcss/dvdcss.h> #include <QPushButton> #include <QProgressBar> @@ -9,10 +9,11 @@ ImageGui::ImageGui() { - DVDImage *dvdImage = new DVDImage; + Video *video = new Video(); + Job *job = video->nextJob(); m_first = true; - connect(dvdImage, SIGNAL(extractProgress(int,int)), this, SLOT(extractProgress(int,int))); - QtConcurrent::run(dvdImage, &DVDImage::saveImageToPath, QLatin1String("/dev/dvd"), QLatin1String("image.iso")); + connect(job, SIGNAL(extractProgress(int,int)), this, SLOT(extractProgress(int,int))); + job->runJob(); } void ImageGui::extractProgress(int current, int maximum) { @@ -3,7 +3,6 @@ #include <QProgressBar> #include <QTime> -class DVDImage; class ImageGui : public QProgressBar { @@ -0,0 +1,19 @@ +#include "job.h" +#include "video.h" +#include <QtConcurrentRun> + +Job::Job(QObject *parent) + : QObject(parent) +{ + m_watcher = new QFutureWatcher<bool>; + m_watcher->setParent(this); + connect(m_watcher, SIGNAL(finished()), this, SLOT(jobFinished())); +} +void Job::runJob() +{ + m_watcher->setFuture(QtConcurrent::run(this, &Job::executeJob)); +} +void Job::jobFinished() +{ + emit completed(m_watcher->future().result()); +} @@ -0,0 +1,25 @@ +#ifndef JOB_H +#define JOB_H + +#include "video.h" +#include <QObject> +#include <QFutureWatcher> + +class Job : public QObject +{ + Q_OBJECT +public: + Job(QObject *parent = 0); + void runJob(); + virtual Video::Jobs jobType() = 0; +protected: + virtual bool executeJob() = 0; +private: + QFutureWatcher<bool> *m_watcher; +private slots: + void jobFinished(); +signals: + void completed(bool result); +}; + +#endif // JOB_H diff --git a/video.cpp b/video.cpp new file mode 100644 index 0000000..0daccf2 --- /dev/null +++ b/video.cpp @@ -0,0 +1,34 @@ +#include "video.h" +#include "job.h" +#include "dvdimagejob.h" + +Video::Video() : m_jobsCompleted(QBitArray(5)) +{ + //Do something +} +void Video::completedJob(bool success) +{ + Job *job = qobject_cast<Job*>(sender()); + qDebug() << "Job code" << job->jobType() << "completed" << success; + m_jobsCompleted.setBit(job->jobType(), success); + delete job; + + if (success) { + //queue next job function + ; + } else { + //failure mechanism + ; + } +} +Job* Video::nextJob() +{ + Job *job; + if (!m_jobsCompleted.at(Video::DVDImage)) { + job = new DVDImageJob(this); + } else { + return job = 0; //Other jobs... + } + connect(job, SIGNAL(completed(bool)), this, SLOT(completedJob(bool))); + return job; +} @@ -0,0 +1,22 @@ +#ifndef VIDEO_H +#define VIDEO_H + + +#include <QObject> +#include <QBitArray> + +class Job; +class Video : public QObject +{ + Q_OBJECT +public: + Video(); + enum Jobs { DVDImage, EncodeMP4, Upload, Subtitle, Poster }; + Job* nextJob(); +private: + QBitArray m_jobsCompleted; +private slots: + void completedJob(bool success); +}; + +#endif // VIDEO_H |