diff options
Diffstat (limited to 'addmoviewizard.cpp')
-rw-r--r-- | addmoviewizard.cpp | 88 |
1 files changed, 87 insertions, 1 deletions
diff --git a/addmoviewizard.cpp b/addmoviewizard.cpp index b7dfbf2..71eb1af 100644 --- a/addmoviewizard.cpp +++ b/addmoviewizard.cpp @@ -13,6 +13,13 @@ #include <QSpinBox> #include <QComboBox> #include <QModelIndex> +#include <QSignalMapper> +#include <QPushButton> +#include <QFileDialog> +#include <QSettings> +#include <QFileInfo> +#include <QFile> +#include <QHash> #include "addmoviewizard.h" #include "listmodelsingleton.h" @@ -20,12 +27,14 @@ #include "listeditor.h" #include "moviemodelsingleton.h" #include "moviemodel.h" +#include "helper.h" AddMovieWizard::AddMovieWizard(QWidget *parent) : QWizard(parent){ addPage(new MovieNamePage); addPage(new MovieActorPage); addPage(new MovieGenrePage); + addPage(new MovieCoverPage); } void AddMovieWizard::accept(){ @@ -61,6 +70,23 @@ void AddMovieWizard::accept(){ } } + QHash<QString, QString> covers; + covers.insert("front", field("frontCover").toString()); + covers.insert("back", field("backCover").toString()); + covers.insert("general", field("generalCover").toString()); + + QList<CoverItem> coverItems; + foreach(QString type, covers.keys()){ + if(covers[type].isEmpty()){ + continue; + } + QString md5sum = Helper::md5Sum(covers[type]); + QString destFile = Helper::moveToArchive(covers[type], md5sum); + if(!destFile.isEmpty()){ + coverItems << CoverItem(covers[type], type, md5sum); + } + } + movieData[MovieItem::Md5Sum] = md5; movieData[MovieItem::Genre] = genreId; movieData[MovieItem::Dvd] = dvdno; @@ -69,7 +95,7 @@ void AddMovieWizard::accept(){ movieData[MovieItem::Quality] = quality; movieData[MovieItem::SeriesNo] = seriesno; movieData[MovieItem::PartNo] = partno; - model->addMovie(movieData, actorIds, QList<CoverItem>()); + model->addMovie(movieData, actorIds, coverItems); QDialog::accept(); } @@ -172,3 +198,63 @@ MovieGenrePage::MovieGenrePage(QWidget *parent) : QWizardPage(parent){ setLayout(mainLayout); } + +/* MovieCoverPage */ +MovieCoverPage::MovieCoverPage(QWidget *parent) : QWizardPage(parent){ + setTitle(tr("Covers")); + setSubTitle(tr("Select covers for the movie")); + setPixmap(QWizard::LogoPixmap, QPixmap(":/shemov.png")); + + QSignalMapper *mapper = new QSignalMapper(this); + QGridLayout *mainLayout = new QGridLayout; + + QLabel *l1 = new QLabel(tr("Front cover")); + mFrontCover = new QLineEdit; + mSelectFront = new QPushButton(tr("Browse...")); + connect(mSelectFront, SIGNAL(clicked()), mapper, SLOT(map())); + mapper->setMapping(mSelectFront, mFrontCover); + mainLayout->addWidget(l1, 0, 0); + mainLayout->addWidget(mFrontCover, 0, 1); + mainLayout->addWidget(mSelectFront, 0, 2); + + QLabel *l2 = new QLabel(tr("Back cover")); + mBackCover = new QLineEdit; + mSelectBack = new QPushButton(tr("Browse...")); + connect(mSelectBack, SIGNAL(clicked()), mapper, SLOT(map())); + mapper->setMapping(mSelectBack, mBackCover); + mainLayout->addWidget(l2, 1, 0); + mainLayout->addWidget(mBackCover, 1, 1); + mainLayout->addWidget(mSelectBack, 1, 2); + + QLabel *l3 = new QLabel(tr("General cover")); + mGeneralCover = new QLineEdit; + mSelectGeneral = new QPushButton(tr("Browse...")); + connect(mSelectGeneral, SIGNAL(clicked()), mapper, SLOT(map())); + mapper->setMapping(mSelectGeneral, mGeneralCover); + mainLayout->addWidget(l3, 2, 0); + mainLayout->addWidget(mGeneralCover, 2, 1); + mainLayout->addWidget(mSelectGeneral, 2, 2); + + registerField("frontCover", mFrontCover); + registerField("backCover", mBackCover); + registerField("generalCover", mGeneralCover); + + connect(mapper, SIGNAL(mapped(QWidget*)), this, SLOT(selectFile(QWidget*))); + + setLayout(mainLayout); +} + +void MovieCoverPage::selectFile(QWidget *lineEdit){ + QLineEdit *curLineEdit = static_cast<QLineEdit*>(lineEdit); + Q_ASSERT(curLineEdit); + QSettings s; + if(mLastOpenedDir.isEmpty()){ + mLastOpenedDir = s.value("paths/selecteddir", QDir::homePath()).toString(); + } + QString file = QFileDialog::getOpenFileName(this, tr("Select cover"), mLastOpenedDir); + curLineEdit->setText(file); + if(!file.isEmpty()){ + QFileInfo fi(file); + mLastOpenedDir = fi.absolutePath(); + } +} |