diff options
author | am <am@f440f766-f032-0410-8965-dc7d17de2ca0> | 2009-07-19 16:12:02 +0000 |
---|---|---|
committer | am <am@f440f766-f032-0410-8965-dc7d17de2ca0> | 2009-07-19 16:12:02 +0000 |
commit | d2b854121266e32164290ee4e683c0c8388d7d41 (patch) | |
tree | 7e844a2920bc00d5d855da661a98f9b20ff13f2e /archiveeditwidget.cpp | |
parent | 80bf76dc318276f67eeec32b8f68e82cf4bb7e62 (diff) | |
download | SheMov-d2b854121266e32164290ee4e683c0c8388d7d41.tar.gz SheMov-d2b854121266e32164290ee4e683c0c8388d7d41.tar.bz2 SheMov-d2b854121266e32164290ee4e683c0c8388d7d41.zip |
-added ActorRole in MovieModel
-Fixed bug in MovieItem returning data and filling the model
-Started on archive viewing
git-svn-id: file:///var/svn/repos2/shemov/trunk@391 f440f766-f032-0410-8965-dc7d17de2ca0
Diffstat (limited to 'archiveeditwidget.cpp')
-rw-r--r-- | archiveeditwidget.cpp | 227 |
1 files changed, 0 insertions, 227 deletions
diff --git a/archiveeditwidget.cpp b/archiveeditwidget.cpp deleted file mode 100644 index 8f4d116..0000000 --- a/archiveeditwidget.cpp +++ /dev/null @@ -1,227 +0,0 @@ -/* - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License - as published by the Free Software Foundation; either version - 2 of the License, or (at your option) any later version. -*/ - -#include <QSplitter> -#include <QHBoxLayout> -#include <QVBoxLayout> -#include <QLabel> -#include <QApplication> -#include <QPushButton> -#include <QMessageBox> -#include <QFileInfo> -#include <QSettings> -#include <QDir> -#include <QList> -#include <QVariant> -#include <QFile> - -#include <QDebug> - -#include "archiveeditwidget.h" -#include "archivefilewidget.h" -#include "listeditor.h" -#include "covereditor.h" -#include "listmodel.h" -#include "moviemodel.h" -#include "helper.h" -#include "coveritem.h" - -ArchiveEditDialog::ArchiveEditDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f){ - //init models - mGenreModel = new ListModel("genre", this); - mActorsModel = new ListModel("actor", this); - - QSplitter *hSplitter = new QSplitter(Qt::Horizontal); - QWidget *editorWidget = new QWidget; - QVBoxLayout *editorLayout = new QVBoxLayout; - - //genre editor - QLabel *l1 = new QLabel(tr("Edit genres")); - mGenreEditor = new ListEditor(mGenreModel); - editorLayout->addWidget(l1); - editorLayout->addWidget(mGenreEditor); - - //actor editor - QLabel *l2 = new QLabel(tr("Edit actors")); - mActorsEditor = new ListEditor(mActorsModel); - editorLayout->addWidget(l2); - editorLayout->addWidget(mActorsEditor); - - //cover editor - QLabel *l3 = new QLabel(tr("Configure cover pictures")); - mCoverEditor = new CoverEditor; - editorLayout->addWidget(l3); - editorLayout->addWidget(mCoverEditor); - - editorLayout->addStretch(); - editorWidget->setLayout(editorLayout); - editorWidget->setMinimumWidth(300); - - //archive editor - mFileWidget = new ArchiveFileWidget; - mFileWidget->setMovieModel(mMovieModel); - mFileWidget->setGenreModel(mGenreModel); - mFileWidget->setActorsModel(mActorsModel); - - //join splitters - hSplitter->addWidget(mFileWidget); - hSplitter->addWidget(editorWidget); - hSplitter->setStretchFactor(0, 2); - hSplitter->setStretchFactor(1, 1); - - //button layout - QHBoxLayout *buttonLayout = new QHBoxLayout; - buttonLayout->addStretch(); - mArchive = new QPushButton(tr("Archive")); - connect(mArchive, SIGNAL(clicked()), this, SLOT(archive())); - buttonLayout->addWidget(mArchive); - mClose = new QPushButton(tr("Close")); - connect(mClose, SIGNAL(clicked()), this, SLOT(reject())); - buttonLayout->addWidget(mClose); - - QVBoxLayout *mainLayout = new QVBoxLayout; - mainLayout->addWidget(hSplitter); - mainLayout->addLayout(buttonLayout); - - setLayout(mainLayout); - QString winTitle = QString("%1 - Archive files").arg(qApp->applicationName()); - setWindowTitle(winTitle); -} - -void ArchiveEditDialog::setFiles(const QStringList &files){ - mFileWidget->setFiles(files); - mCoverEditor->setCovers(files); -} - -void ArchiveEditDialog::archive(){ - const QHash<QString, QString> md5 = mFileWidget->md5Sums(); - const QList<int> actors = mFileWidget->actorIds(); - int genre = mFileWidget->genreId(); - QString front = mCoverEditor->frontCover(); - QString back = mCoverEditor->backCover(); - QString general = mCoverEditor->covers(); - QString file = mCoverEditor->movie(); - QString title = mFileWidget->movieTitle().toLower(); - int quality = mFileWidget->quality(); - QStringList files; - files << front << back << general; - files.removeAll(QString()); - files << file; - if(checkInput(genre, actors, files, title, file, quality) && checkMd5(md5, files)){ - QSettings s; - QString archivePath = s.value("paths/archivedir").toString(); - if(archivePath.isEmpty()){ - QMessageBox::critical(this, tr("Error"), tr("No archive path found. Please set it via Edit->Configure!")); - return; - } - QFileInfo archiveInfo(archivePath); - if(!archiveInfo.exists()){ - QDir root = QDir::root(); - root.mkpath(archivePath); - } - archiveInfo = QFileInfo(archivePath); - if(!archiveInfo.isDir()){ - QString msg = QString(tr("Archive path %1 is not a directory. Aborting!")).arg(archivePath); - QMessageBox::critical(this, tr("Error"), msg); - return; - } - QList<QVariant> data; - QFileInfo movie(file); - data << title << movie.fileName() << md5.value(file) << movie.size() << genre << quality << -1; - QList<CoverItem> covers; - if(!front.isEmpty()){ - covers << coverItem(front, "front", md5.value(front)); - } - if(!back.isEmpty()){ - covers << coverItem(back, "back", md5.value(back)); - } - if(!general.isEmpty()){ - covers << coverItem(general, "general", md5.value(general)); - } - QList<QVariant> vAList; - foreach(int a, actors){ - vAList << a; - } - mMovieModel->addMovie(data, vAList, covers); - QStringList refreshDirs; - foreach(QString f, files){ - QFileInfo file(f); - QString hash = md5.value(f); - QString destDirS = QString("%1/%2/%3").arg(archivePath).arg(hash[0]).arg(hash[1]); - QString destFileS = QString("%1/%2/%3/%4").arg(archivePath).arg(hash[0]).arg(hash[1]).arg(file.fileName()); - QFileInfo dir(destDirS); - if(!dir.exists()){ - QDir root = QDir::root(); - root.mkpath(destDirS); - } - QFileInfo destFile(destFileS); - if(destFile.exists()){ - destFileS = QString("%1/%2/%3/%4_%5.%6").arg(archivePath).arg(hash[0]).arg(hash[1]).arg(destFile.completeBaseName()).arg(hash).arg(destFile.suffix()); - } - QFile::rename(f, destFileS); - QString refreshDir = file.absoluteFilePath(); - if(!refreshDirs.contains(refreshDir)){ - refreshDirs << refreshDir; - } - } - foreach(QString r, refreshDirs){ - QModelIndex idx = mDirModel->index(r); - mDirModel->refresh(idx); - } - } -} - -bool ArchiveEditDialog::checkInput(int genre, const QList<int> &actors, const QStringList &files, const QString &title, const QString &movie, int quality) { - if(genre < 0){ - QMessageBox::critical(this, tr("Error"), tr("Genre is invalid")); - return false; - } - if(actors.isEmpty()){ - int answer = QMessageBox::question(this, tr("Question"), tr("No actors selected. Continue anyway?"), QMessageBox::Yes | QMessageBox::No); - return (answer == QMessageBox::Yes); - } - foreach(QString f, files){ - QFileInfo info(f); - if(!info.isFile()){ - QString msg = QString(tr("%1 does not seem to be a file. Aborting")).arg(info.fileName()); - QMessageBox::critical(this, tr("Error"), msg); - return false; - } - } - QString mt = Helper::mimeType(movie); - if(!mt.toLower().startsWith("video")){ - QString msg = QString(tr("Movie %1 is not of MIME type video (%2). Continue anyway?")).arg(movie).arg(mt); - int answer = QMessageBox::question(this, tr("Question"), msg, QMessageBox::Yes | QMessageBox::No); - return (answer == QMessageBox::Yes); - } - if(title.isEmpty()){ - QMessageBox::critical(this, tr("Error"), tr("No movie title given!")); - return false; - } - if(quality == 0){ - int answer = QMessageBox::question(this, tr("Question"), tr("Quality is set to 0. Continue anyway?"), QMessageBox::Yes | QMessageBox::No); - return (answer == QMessageBox::Yes); - } - return true; -} - -bool ArchiveEditDialog::checkMd5(const QHash<QString, QString> &md5sums, const QStringList &files){ - foreach(QString f, files){ - if(!md5sums.contains(f)){ - QString msg = QString(tr("I don't have an MD5 hash for %1. Aborting!")).arg(f); - QMessageBox::critical(this, tr("Error"), msg); - return false; - } - } - return true; -} - -const CoverItem ArchiveEditDialog::coverItem(const QString &filePath, const QString type, const QString &md5) const{ - QFileInfo info(filePath); - return CoverItem(info.fileName(), type, md5); -} - |