diff options
Diffstat (limited to 'archiveviewwidget.cpp')
-rw-r--r-- | archiveviewwidget.cpp | 120 |
1 files changed, 113 insertions, 7 deletions
diff --git a/archiveviewwidget.cpp b/archiveviewwidget.cpp index e6ffb4b..cc018b2 100644 --- a/archiveviewwidget.cpp +++ b/archiveviewwidget.cpp @@ -16,6 +16,8 @@ #include <QApplication> #include <QSettings> #include <QProcess> +#include <QDir> +#include <QRegExp> #include <QDebug> @@ -130,19 +132,14 @@ void ArchiveViewWidget::addMovie(){ void ArchiveViewWidget::showMovie(const QModelIndex &movie){ QModelIndex real = mProxy->mapToSource(movie); - QModelIndex dvd = mMovieModel->index(real.row(), MovieItem::Dvd, QModelIndex()); - int dvdno = dvd.data().toInt(); - if(dvdno != -1){ + if(real.data(MovieModel::DvdRole).toInt() != -1){ emit statusbarMessage(tr("Movie is not present on filesystem")); return; } - QModelIndex fnIdx = mMovieModel->index(real.row(), MovieItem::Filename, QModelIndex()); - QModelIndex md5Idx = mMovieModel->index(real.row(), MovieItem::Md5Sum, QModelIndex()); - QString path = Helper::createArchivePath(fnIdx.data().toString(), md5Idx.data().toString()); QSettings s; QString playerPath = s.value("paths/movieviewer").toString(); QStringList args = s.value("paths/movieviewerargs").toStringList(); - args << path; + args << real.data(MovieModel::FullPathRole).toString(); QProcess::startDetached(playerPath, args); } @@ -169,6 +166,115 @@ void ArchiveViewWidget::setActorFilter(const QString &filter){ mProxy->setFilter(filter, ArchiveProxy::ActorFilter); } +void ArchiveViewWidget::moveBurn(){ + QModelIndexList sel = fileView()->selectionModel()->selectedRows(); + if(sel.isEmpty()){ + return; + } + QSettings s; + QString destBase = QString("%1/%2").arg(s.value("paths/start").toString()).arg(tr("burn")); + QFileInfo dbi(destBase); + if(!dbi.exists()){ + QDir bd(s.value("paths/start").toString()); + bool success = bd.mkdir(tr("burn")); + if(!success){ + QString msg = QString("Failed to create dir %1 in %2").arg(s.value("paths/start").toString()).arg(tr("burn")); + emit statusbarMessage(msg); + return; + } + }else{ + if(!dbi.isDir()){ + QString msg = QString("%1 exists but is not a directory").arg(destBase); + emit statusbarMessage(msg); + return; + } + } + QString question = QString(tr("Really move selected files and covers to %1?")).arg(destBase); + int answer = QMessageBox::question(this, tr("Question"), question, QMessageBox::Yes | QMessageBox::No); + if(answer == QMessageBox::Yes){ + QDir destDir(destBase); + foreach(QModelIndex idx, sel){ + QModelIndex real = mProxy->mapToSource(idx); + QString file = real.data(MovieModel::FullPathRole).toString(); + QList<QVariant> covers = real.data(MovieModel::CoverPathRole).toList(); + QFileInfo fi(file); + if(!fi.exists()){ + QString msg = QString(tr("%1 does not exist on the filesystem")).arg(file); + emit statusbarMessage(msg); + return; + } + QString destDirName(real.data(MovieModel::TitleBaseRole).toString()); + if(real.data(MovieModel::SeriesNoRole).toInt() != -1){ + destDirName.append(QString(".%1").arg(QString::number(real.data(MovieModel::SeriesNoRole).toInt()))); + } + QRegExp ws("\\s+"); + destDirName.replace(ws, "."); + destDir.mkdir(destDirName); + QString finalDestDir = QString("%1/%2").arg(destBase).arg(destDirName); + QString newFn = QString("%1/%2").arg(finalDestDir).arg(fi.fileName()); + QFile::rename(file, newFn); + foreach(QVariant c, covers){ + QFileInfo ci(c.toString()); + QString newCover = QString("%1/%2").arg(finalDestDir).arg(ci.fileName()); + QFile::copy(c.toString(), newCover); + } + } + emit refreshDir(destBase); + } +} + +void ArchiveViewWidget::setDvdNo(){ + int dvdno = mMovieModel->maxValue(MovieItem::Dvd).toInt(); + QModelIndexList idx = fileView()->selectionModel()->selectedRows(); + if(idx.isEmpty()){ + return; + } + if(dvdno != 0){ + ++dvdno; + TextEnterDialog dlg(tr("Enter Dvd No."), this); + dlg.setText(QString::number(dvdno)); + int retval = dlg.exec(); + if(retval == QDialog::Accepted){ + QString noString = dlg.text(); + bool success(false); + int no = noString.toLongLong(&success); + if(success){ + foreach(QModelIndex i, idx){ + QModelIndex real = mProxy->mapToSource(i); + if(real.column() != MovieItem::Dvd){ + real = mMovieModel->index(real.row(), MovieItem::Dvd, QModelIndex()); + } + mMovieModel->setDataAt(real, no); + } + } + } + } +} + +void ArchiveViewWidget::deleteFromArchive(){ + QModelIndexList selected = fileView()->selectionModel()->selectedRows(); + if(selected.isEmpty()){ + return; + } + QString question = QString(tr("Really delete %1 file(s) from archive?")).arg(QString::number(selected.count())); + int retval = QMessageBox::question(this, tr("Question"), question, QMessageBox::Yes | QMessageBox::No); + if(retval == QMessageBox::Yes){ + foreach(QModelIndex i, selected){ + QModelIndex real = mProxy->mapToSource(i); + QString path = real.data(MovieModel::FullPathRole).toString(); + QList<QVariant> covers = real.data(MovieModel::CoverPathRole).toList(); + bool r = QFile::remove(path); + if(r){ + mMovieModel->removeMovie(real); + } + foreach(QVariant c, covers){ + QString cpath = c.toString(); + QFile::remove(cpath); + } + } + } +} + void ArchiveViewWidget::rowChanged(const QModelIndex &/*current*/, const QModelIndex & /*prev*/){ QModelIndex idx = getSourceColumnZero(); mWindowTitle = QString(tr("%1 - %2")).arg(qApp->applicationName()).arg(idx.data().toString()); |