From d617e0679b42680d5068513a951b6f6db10b0565 Mon Sep 17 00:00:00 2001 From: Arno Date: Fri, 23 Jul 2010 21:25:34 +0200 Subject: Big code cleanup hopefully removed all code connected to ArchiveViewWidget in this tree. Files removed ({h,cpp}): *archiveeditdialog *listeditor *covereditor *archivefilewidget *addmoviewizard *archivefileview *archiveproxy *sizedelegate *archivedidelegate *archiveitemeditdialog *coveritem *movieitem *moviemodel *moviemodelsingleton *listmodel *listmodelsingleton *archiveviewwidget *archiveiteminfoedit *archiveitemcoveredit *fileinfoitem *fileinfomodel See added file TODOS for stuff that needs fixes. --- archiveviewwidget.cpp | 359 -------------------------------------------------- 1 file changed, 359 deletions(-) delete mode 100644 archiveviewwidget.cpp (limited to 'archiveviewwidget.cpp') diff --git a/archiveviewwidget.cpp b/archiveviewwidget.cpp deleted file mode 100644 index 062d090..0000000 --- a/archiveviewwidget.cpp +++ /dev/null @@ -1,359 +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 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "archiveviewwidget.h" -#include "archivefileview.h" -#include "moviemodel.h" -#include "listmodel.h" -#include "archiveproxy.h" -#include "sizedelegate.h" -#include "archiveddelegate.h" -#include "textenterdialog.h" -#include "helper.h" -#include "moviepropertiesdialog.h" -#include "addmoviewizard.h" -#include "archiveitemeditdialog.h" -#include "coveritem.h" - -ArchiveViewWidget::ArchiveViewWidget(MovieModel *model, ListModel *genre, ListModel *actors, QWidget *parent) : QWidget(parent), mMovieModel(model), mGenreModel(genre), mActorsModel(actors), mSize(0){ - //filter bar - QHBoxLayout *filterLayout = new QHBoxLayout; - QLabel *l1 = new QLabel(tr("Filter by &genre")); - mGenre = new QComboBox; - l1->setBuddy(mGenre); - mGenre->setModel(mGenreModel); - connect(mGenre, SIGNAL(activated(const QString &)), this, SLOT(setGenreFilter(const QString &))); - filterLayout->addWidget(l1); - filterLayout->addWidget(mGenre); - QLabel *l2 = new QLabel(tr("Filter by &actor")); - mActors = new QComboBox; - mActors->setModel(mActorsModel); - connect(mActors, SIGNAL(activated(const QString &)), this, SLOT(setActorFilter(const QString &))); - l2->setBuddy(mActors); - filterLayout->addWidget(l2); - filterLayout->addWidget(mActors); - QLabel *l3 = new QLabel(tr("Filter by &title")); - mName = new QLineEdit; - l3->setBuddy(mName); - filterLayout->addWidget(l3); - filterLayout->addWidget(mName); - mFilter = new QPushButton(tr("Filter")); - connect(mFilter, SIGNAL(clicked()), this, SLOT(setFilter())); - connect(mName, SIGNAL(returnPressed()), this, SLOT(setFilter())); - filterLayout->addWidget(mFilter); - mClearFilter = new QPushButton(tr("Clear filter")); - filterLayout->addWidget(mClearFilter); - - //treeview - mFileView = new ArchiveFileView; - mFileView->setItemDelegateForColumn(MovieItem::Size, new SizeDelegate(this)); - mFileView->setItemDelegateForColumn(MovieItem::Dvd, new ArchivedDelegate(this)); - mProxy = new ArchiveProxy(this); - mProxy->setSourceModel(mMovieModel); - mFileView->setModel(mProxy); - mFileView->setSortingEnabled(true); - mFileView->setItemsExpandable(false); - mFileView->setRootIsDecorated(false); - mFileView->setSelectionBehavior(QAbstractItemView::SelectRows); - mFileView->setSelectionMode(QAbstractItemView::ExtendedSelection); - mFileView->setColumnHidden(MovieItem::Md5Sum, true); - mFileView->setColumnHidden(MovieItem::SeriesNo, true); - mFileView->setColumnHidden(MovieItem::PartNo, true); - connect(mClearFilter, SIGNAL(clicked()), mProxy, SLOT(clearFilter())); - connect(mMovieModel, SIGNAL(moviesChanged()), mProxy, SLOT(invalidate())); - - //main layout - QVBoxLayout *mainLayout = new QVBoxLayout; - mainLayout->addLayout(filterLayout); - mainLayout->addWidget(mFileView); - - connect(mFileView->selectionModel(), SIGNAL(currentChanged(const QModelIndex &, const QModelIndex)), this, SLOT(rowChanged(const QModelIndex &, const QModelIndex &))); - connect(mFileView, SIGNAL(doubleClicked(const QModelIndex &)), this, SLOT(showMovie(const QModelIndex &))); - connect(mFileView->selectionModel(), SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)), this, SLOT(calcSize())); - - mWindowTitle = QString("%1 - nothing selected").arg(qApp->applicationName()); - setLayout(mainLayout); -} - -void ArchiveViewWidget::editFile(){ - QModelIndex real = getSourceColumnZero(); - mEditDialog->setMovie(real); - mEditDialog->show(); - mEditDialog->raise(); - mEditDialog->activateWindow(); -} - -void ArchiveViewWidget::addMovie(){ - AddMovieWizard wiz(this); - wiz.exec(); -} - -void ArchiveViewWidget::showMovie(const QModelIndex &movie){ - QModelIndex real = mProxy->mapToSource(movie); - if(real.data(MovieModel::DvdRole).toInt() != -1){ - emit statusbarMessage(tr("Movie is not present on filesystem")); - return; - } - QPair pData = playerData(QString()); - QString playerPath = pData.first; - QStringList args = pData.second; - args << real.data(MovieModel::FullPathRole).toString(); - QProcess::startDetached(playerPath, args); -} - -void ArchiveViewWidget::properties(){ - QModelIndex real = getSourceColumnZero(); - int movid = real.data(MovieModel::IdRole).toInt(); - MoviePropertiesDialog dlg(movid, this); - dlg.exec(); -} - -void ArchiveViewWidget::setFilter(){ - QString filter = mName->text().toLower(); - if(filter.isEmpty()){ - return; - } - mProxy->setFilter(filter, ArchiveProxy::TitleFilter); -} - -void ArchiveViewWidget::setGenreFilter(const QString &filter){ - mProxy->setFilter(filter, ArchiveProxy::GenreFilter); -} - -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 burnDir = s.value("paths/burn").toString(); - if(burnDir.isEmpty()){ - QMessageBox::critical(this, tr("Error"), tr("Directory for burning not set. Please configure it in Configure->Paths.")); - return; - - } - QFileInfo dbi(burnDir); - if(!dbi.exists()){ - QString msg = QString(tr("Directory %1 does not exist!")).arg(burnDir); - emit statusbarMessage(msg); - return; - }else{ - if(!dbi.isDir()){ - QString msg = QString("%1 exists but is not a directory").arg(burnDir); - emit statusbarMessage(msg); - return; - } - } - QString question = QString(tr("Really move selected files and covers to %1?")).arg(burnDir); - int answer = QMessageBox::question(this, tr("Question"), question, QMessageBox::Yes | QMessageBox::No); - if(answer == QMessageBox::Yes){ - QDir destDir(burnDir); - foreach(QModelIndex idx, sel){ - QModelIndex real = mProxy->mapToSource(idx); - QString file = real.data(MovieModel::FullPathRole).toString(); - QList 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(burnDir).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(burnDir); - } -} - -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 covers = real.data(MovieModel::CoverPathRole).toList(); - QFile::remove(path); - mMovieModel->removeMovie(real); - foreach(QVariant c, covers){ - QString cpath = c.toString(); - QFile::remove(cpath); - } - } - } -} - -void ArchiveViewWidget::playSelected(const QString &player){ - QStringList selectedMovies = selectedFiles(); - if(selectedMovies.isEmpty()){ - return; - } - QPair pData = playerData(player); - QString prog = pData.first; - QStringList args = pData.second; - args << selectedMovies; - QProcess::startDetached(prog, args); -} - -void ArchiveViewWidget::copyToParts(){ - QModelIndex idx = getSourceColumnZero(); - QVariant quality = idx.data(MovieModel::QualityRole); - QVariant dvdno = idx.data(MovieModel::DvdRole); - QVariant genre = idx.data(MovieModel::GenreRole); - QHash actorMap = idx.data(MovieModel::ActorsMap).toHash(); - QList actorIds; - foreach(QVariant id, actorMap.values()){ - actorIds << id.toInt(); - } - QList covers; - foreach(QVariant cover, idx.data(MovieModel::CoverRole).toList()){ - covers << cover.value(); - } - QList otherParts = idx.data(MovieModel::OtherPartsRole).toList(); - if(otherParts.isEmpty()){ - statusbarMessage(tr("No other parts found.")); - return; - } - foreach(QVariant part, otherParts){ - int id = part.toInt(); - QModelIndex movieModelIndex = mMovieModel->index(id, MovieItem::Genre); - mMovieModel->setDataAt(movieModelIndex, genre); - movieModelIndex = mMovieModel->index(id, MovieItem::Quality); - mMovieModel->setDataAt(movieModelIndex, quality); - movieModelIndex = mMovieModel->index(id, MovieItem::Dvd); - mMovieModel->setDataAt(movieModelIndex, dvdno); - mMovieModel->setActors(id, actorIds); - mMovieModel->setCovers(id, covers); - } - QString message = QString(tr("Copied data to %1 movie(s)")).arg(otherParts.count()); - statusbarMessage(message); -} - -void ArchiveViewWidget::rowChanged(const QModelIndex &/*current*/, const QModelIndex & /*prev*/){ - QModelIndex idx = getSourceColumnZero(); - mWindowTitle = QString(tr("%1 - %2")).arg(qApp->applicationName()).arg(idx.data().toString()); - emit windowTitle(mWindowTitle); -} - -void ArchiveViewWidget::calcSize(){ - QModelIndexList sel = mFileView->selectionModel()->selectedRows(MovieItem::Size); - mSize = 0; - foreach(QModelIndex idx, sel){ - mSize += idx.data().toLongLong(); - } -} - -const QModelIndex ArchiveViewWidget::getSourceColumnZero(){ - QModelIndex retval; - QModelIndex idx = mFileView->currentIndex(); - if(idx.column() != 0){ - idx = mProxy->index(idx.row(), 0); - } - QModelIndex real = mProxy->mapToSource(idx); - if(real.column() != 0){ - retval = mMovieModel->index(real.row(), 0); - }else{ - retval = real; - } - return retval; -} - -QPair ArchiveViewWidget::playerData(const QString &preferred){ - QSettings s; - QHash data = s.value("programs_movieviewer/data").toHash(); - if(!preferred.isEmpty()){ - if(data.keys().contains(preferred)){ - QHash pData = data.value(preferred).toHash(); - return qMakePair(pData.value("path").toString(), pData.value("args").toStringList()); - } - return QPair(); - } - QString defaultPlayer = s.value("programs_movieviewer/default").toString(); - if(data.keys().contains(defaultPlayer)){ - QHash pData = data.value(defaultPlayer).toHash(); - return qMakePair(pData.value("path").toString(), pData.value("args").toStringList()); - } - return QPair(); -} - -QStringList ArchiveViewWidget::selectedFiles(){ - QModelIndexList selected = fileView()->selectionModel()->selectedRows(); - if(selected.isEmpty()){ - return QStringList(); - } - QStringList retval; - foreach(QModelIndex idx, selected){ - if(idx.data(MovieModel::DvdRole).toInt() == -1){ - retval << idx.data(MovieModel::FullPathRole).toString(); - } - } - return retval; -} -- cgit v1.2.3-70-g09d2