diff options
author | Arno <am@disconnect.de> | 2010-07-23 21:25:34 +0200 |
---|---|---|
committer | Arno <am@disconnect.de> | 2010-07-23 21:25:34 +0200 |
commit | d617e0679b42680d5068513a951b6f6db10b0565 (patch) | |
tree | ce368fd13628e75406191b1c8118664136a4207e | |
parent | a59ac6eb3cebdd4e3f41552c21f14165203c1ab2 (diff) | |
download | SheMov-d617e0679b42680d5068513a951b6f6db10b0565.tar.gz SheMov-d617e0679b42680d5068513a951b6f6db10b0565.tar.bz2 SheMov-d617e0679b42680d5068513a951b6f6db10b0565.zip |
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.
48 files changed, 78 insertions, 4405 deletions
@@ -0,0 +1,55 @@ +SheMov (MainWindow) + -> FileSystemWidget (mFSWidget) + -> ArchiveEditDialog (QDialog), replaced by NewMovieWizard + -> ArchiveFileWidget + -> ListEditor + -> CoverEditor + -> ArchiveViewWidget (mAVWidget) + -> ArchiveFileView (QTreeView) + -> ArchiveProxy (QSortFilterProxyModel) + -> ArchiveItemEditDialog (QDialog) + -> ArchiveItemInfoEdit + -> ArchiveItemCoverEdit + -> CoverItem + -> SizeDelegate (QAbstractItemDelegate) + -> ArchivedDelegate (QAbstractItemDelegate) + -> TextEnterDialog (QDialog) + -> MoviePropertiesDialog (QDialog) + -> AddMovieWizard (QWizard) + + + + +TODOS: +-updateSelectionCount for TreeView +-tabChanged for TreeView +-File properties for TreeView +-Fix database access for good! +-Fix statistics menu! +-rename "Tree" +-act on doubleclick in TreeView +-Finish this file +-Fix Unable to free statement on exit + +GOOD FILES TO REMOVE: +*archiveeditdialog +*listeditor +*covereditor +*archivefilewidget +*addmoviewizard +*archivefileview +*archiveproxy +*sizedelegate +*archivedidelegate +*archiveitemeditdialog +*coveritem +*movieitem +*moviemodel +*moviemodelsingleton +*listmodel +*listmodelsingleton +*archiveviewwidget +*archiveiteminfoedit +*archiveitemcoveredit +*fileinfoitem +*fileinfomodel diff --git a/addmoviewizard.cpp b/addmoviewizard.cpp deleted file mode 100644 index 71eb1af..0000000 --- a/addmoviewizard.cpp +++ /dev/null @@ -1,260 +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 <QGridLayout> -#include <QVBoxLayout> -#include <QHBoxLayout> -#include <QLabel> -#include <QLineEdit> -#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" -#include "actorwidget.h" -#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(){ - QString movieName = field("movieName").toString(); - int partno = field("partNo").toInt(); - int seriesno = field("seriesNo").toInt(); - int quality = field("quality").toInt(); - QStringList actors = field("actors").toStringList(); - QString genre = field("genre").toString(); - int dvdno = field("dvdNo").toInt(); - - MovieModel *model = MovieModelSingleton::instance(); - ListModel *genreModel = ListModelSingleton::instance()->model("genre"); - ListModel *actorModel = ListModelSingleton::instance()->model("actor"); - - QList<QVariant> movieData; - movieData << movieName; - for(int i = 1; i < MovieItem::NumRows; ++i){ - movieData << QVariant(); - } - QString md5(32, '0'); - QModelIndex genreIdx = genreModel->index(genre); - int genreId = genreModel->defaultId(); - if(genreIdx.isValid()){ - genreId = genreIdx.data(ListModel::IdRole).toInt(); - } - - QList<QVariant> actorIds; - foreach(QVariant a, actors){ - QModelIndex actorIdx = actorModel->index(a.toString()); - if(actorIdx.isValid()){ - actorIds << actorIdx.data(ListModel::IdRole).toInt(); - } - } - - 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; - movieData[MovieItem::Filename] = tr("(DVD)"); - movieData[MovieItem::Size] = Q_INT64_C(4707319808); - movieData[MovieItem::Quality] = quality; - movieData[MovieItem::SeriesNo] = seriesno; - movieData[MovieItem::PartNo] = partno; - model->addMovie(movieData, actorIds, coverItems); - - QDialog::accept(); -} - -/* MovieNamePage */ -MovieNamePage::MovieNamePage(QWidget *parent) : QWizardPage(parent){ - setTitle(tr("Basic Movie Information")); - setSubTitle(tr("Enter basic Movie information here. The series no. is the series part, e.g. Rogue adventures 14. The part no. only has to be set if the movie is split in several parts. Set -1 for none.")); - setPixmap(QWizard::LogoPixmap, QPixmap(":/shemov.png")); - - QGridLayout *mainLayout = new QGridLayout; - QLabel *l1 = new QLabel(tr("Movie name")); - mainLayout->addWidget(l1, 0, 0); - mMovieName = new QLineEdit; - mainLayout->addWidget(mMovieName, 0, 1); - QLabel *l2 = new QLabel(tr("Series no.")); - mainLayout->addWidget(l2, 1, 0); - mSeriesNo = new QSpinBox; - mSeriesNo->setMinimum(-1); - mSeriesNo->setValue(-1); - mainLayout->addWidget(mSeriesNo, 1, 1); - QLabel *l3 = new QLabel(tr("Part no.")); - mainLayout->addWidget(l3, 2, 0); - mPartNo = new QSpinBox; - mPartNo->setMinimum(-1); - mPartNo->setValue(-1); - mainLayout->addWidget(mPartNo, 2, 1); - QLabel *l4 = new QLabel(tr("Quality")); - mainLayout->addWidget(l4, 3, 0); - mQuality = new QSpinBox; - mQuality->setMaximum(10); - mQuality->setMinimum(0); - mQuality->setValue(10); - mainLayout->addWidget(mQuality, 3, 1); - MovieModel *movieModel = MovieModelSingleton::instance(); - int dvdno = movieModel->maxValue(MovieItem::Dvd).toInt(); - QLabel *l5 = new QLabel(tr("DVD no.")); - mainLayout->addWidget(l5, 4, 0); - mDvdNo = new QSpinBox; - mDvdNo->setMinimum(0); - mDvdNo->setValue(++dvdno); - mainLayout->addWidget(mDvdNo, 4, 1); - - registerField("movieName*", mMovieName); - registerField("seriesNo", mSeriesNo); - registerField("partNo", mPartNo); - registerField("quality", mQuality); - registerField("dvdNo", mDvdNo); - - setLayout(mainLayout); -} - -/* MovieActorPage */ -MovieActorPage::MovieActorPage(QWidget *parent) : QWizardPage(parent){ - setTitle(tr("Actors")); - setSubTitle(tr("Enter actors here")); - setPixmap(QWizard::LogoPixmap, QPixmap(":/shemov.png")); - - QHBoxLayout *mainLayout = new QHBoxLayout; - mActorWidget = new ActorWidget; - mainLayout->addWidget(mActorWidget); - QVBoxLayout *actorEditorLayout = new QVBoxLayout; - ListEditor *actorsEditor = new ListEditor(ListModelSingleton::instance()->model("actor")); - actorEditorLayout->addWidget(actorsEditor); - actorEditorLayout->addStretch(); - mainLayout->addLayout(actorEditorLayout); - connect(actorsEditor, SIGNAL(itemAdded(const QString &)), this, SLOT(addActor(const QString &))); - - registerField("actors", mActorWidget, "actors"); - - setLayout(mainLayout); -} - -void MovieActorPage::addActor(const QString &actor){ - mActorWidget->addActor(actor); -} - -/* MovieGenrePage */ -MovieGenrePage::MovieGenrePage(QWidget *parent) : QWizardPage(parent){ - setTitle(tr("Genre")); - setSubTitle(tr("Set the genre of the movie")); - setPixmap(QWizard::LogoPixmap, QPixmap(":/shemov.png")); - - QVBoxLayout *mainLayout = new QVBoxLayout; - QLabel *l1 = new QLabel(tr("Select genre")); - mainLayout->addWidget(l1); - mGenre = new QComboBox; - mGenre->setModel(ListModelSingleton::instance()->model("genre")); - int idx = mGenre->findText("shemale"); - if(idx != -1){ - mGenre->setCurrentIndex(idx); - } - mainLayout->addWidget(mGenre); - - ListEditor *genreEditor = new ListEditor(ListModelSingleton::instance()->model("genre")); - mainLayout->addWidget(genreEditor); - mainLayout->addStretch(); - - registerField("genre", mGenre, "currentText"); - - 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(); - } -} diff --git a/addmoviewizard.h b/addmoviewizard.h deleted file mode 100644 index ba4816e..0000000 --- a/addmoviewizard.h +++ /dev/null @@ -1,80 +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. -*/ - -#ifndef ADDMOVIEWIZARD_H -#define ADDMOVIEWIZARD_H - -#include <QWizard> -#include <QWizardPage> - -class QLineEdit; -class QSpinBox; -class QComboBox; -class QPushButton; -class ActorWidget; - -class AddMovieWizard : public QWizard { - Q_OBJECT - public: - explicit AddMovieWizard(QWidget *parent = 0); - void accept(); -}; - -class MovieNamePage : public QWizardPage { - Q_OBJECT - public: - explicit MovieNamePage(QWidget *parent = 0); - - private: - QLineEdit *mMovieName; - QSpinBox *mSeriesNo; - QSpinBox *mPartNo; - QSpinBox *mQuality; - QSpinBox *mDvdNo; -}; - -class MovieActorPage : public QWizardPage { - Q_OBJECT - public: - explicit MovieActorPage(QWidget *parent = 0); - - private slots: - void addActor(const QString &actor); - - private: - ActorWidget *mActorWidget; - -}; - -class MovieGenrePage : public QWizardPage { - Q_OBJECT - public: - explicit MovieGenrePage(QWidget *parent = 0); - - private: - QComboBox *mGenre; -}; - -class MovieCoverPage : public QWizardPage { - Q_OBJECT - public: - explicit MovieCoverPage(QWidget *parent = 0); - - private slots: - void selectFile(QWidget *lineEdit); - - private: - QLineEdit *mFrontCover; - QLineEdit *mBackCover; - QLineEdit *mGeneralCover; - QPushButton *mSelectFront; - QPushButton *mSelectBack; - QPushButton *mSelectGeneral; - QString mLastOpenedDir; -}; - -#endif diff --git a/archiveddelegate.cpp b/archiveddelegate.cpp deleted file mode 100644 index 54282b8..0000000 --- a/archiveddelegate.cpp +++ /dev/null @@ -1,42 +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 <QFontMetrics> -#include <QPainter> -#include <QApplication> - -#include "archiveddelegate.h" - -ArchivedDelegate::ArchivedDelegate(QObject *parent) : QAbstractItemDelegate(parent) {}; - -void ArchivedDelegate::paint(QPainter *p, const QStyleOptionViewItem &option, const QModelIndex &index) const{ - p->save(); - qApp->style()->drawControl(QStyle::CE_ItemViewItem, &option, p); - QColor c(QColor(Qt::darkGreen)); - QString text(tr("No")); - if(index.data().toInt() > -1){ - c = QColor(Qt::red); - text = QString(tr("On DVD # %1")).arg(QString::number(index.data().toInt())); - } - p->setPen(QPen(c)); - p->drawText(option.rect, Qt::AlignLeft | Qt::AlignVCenter, text); - p->restore(); -} - -QSize ArchivedDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const { - QString text; - if(index.data().toInt() == -1){ - text = QString(tr("On DVD # %1")).arg(QString::number(index.data().toInt())); - }else if(index.data().toInt() == -2){ - text = tr("(unknown"); - }else{ - text = tr("No"); - } - QFontMetrics metrics(option.font); - return metrics.size(Qt::TextSingleLine, text); -} - diff --git a/archiveddelegate.h b/archiveddelegate.h deleted file mode 100644 index a7a4c09..0000000 --- a/archiveddelegate.h +++ /dev/null @@ -1,23 +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. -*/ - -#ifndef ARCHIVEDDELEGATE_H -#define ARCHIVEDDELEGATE_H - -#include <QAbstractItemDelegate> - -class ArchivedDelegate : public QAbstractItemDelegate { - Q_OBJECT - public: - ArchivedDelegate(QObject *parent = 0); - ~ArchivedDelegate() {}; - void paint(QPainter *p, const QStyleOptionViewItem &option, const QModelIndex &index) const; - QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const; -}; - -#endif - diff --git a/archiveeditdialog.cpp b/archiveeditdialog.cpp deleted file mode 100644 index 41f303f..0000000 --- a/archiveeditdialog.cpp +++ /dev/null @@ -1,245 +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 <QHash> - -#include "archiveeditdialog.h" -#include "archivefilewidget.h" -#include "listeditor.h" -#include "covereditor.h" -#include "listmodel.h" -#include "moviemodel.h" -#include "helper.h" -#include "coveritem.h" -#include "listmodelsingleton.h" -#include "moviemodelsingleton.h" - -ArchiveEditDialog::ArchiveEditDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f) { - //setup - mGenreModel = ListModelSingleton::instance()->model("genre"); - mActorsModel = ListModelSingleton::instance()->model("actor"); - mMovieModel = MovieModelSingleton::instance(); - - QSplitter *hSplitter = new QSplitter(Qt::Horizontal); - QWidget *editorWidget = new QWidget; - QVBoxLayout *editorLayout = new QVBoxLayout; - - //genre editor - mGenreEditor = new ListEditor(mGenreModel); - editorLayout->addWidget(mGenreEditor); - - //actor editor - mActorsEditor = new ListEditor(mActorsModel); - 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; - connect(mActorsEditor, SIGNAL(itemAdded(const QString &)), mFileWidget, SLOT(setActor(const QString &))); - - //join splitters - hSplitter->addWidget(mFileWidget); - hSplitter->addWidget(editorWidget); - hSplitter->setStretchFactor(0, 2); - hSplitter->setStretchFactor(1, 1); - - //button layout - QHBoxLayout *buttonLayout = new QHBoxLayout; - buttonLayout->addStretch(); - mGuess = new QPushButton(tr("Guess values")); - connect(mGuess, SIGNAL(clicked()), this, SLOT(guess())); - buttonLayout->addWidget(mGuess); - 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 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(); - int seriesno = mFileWidget->seriesNo(); - int partno = mFileWidget->partNo(); - QStringList files; - files << front << back << general; - files.removeAll(QString()); - files << file; - QHash<QString, QString> md5Sums; - foreach(QString f, files){ - md5Sums[f] = Helper::md5Sum(f); - } - if(checkInput(genre, actors, files, title, file, quality)){ - 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() << md5Sums.value(file) << movie.size() << genre << quality << -1 << seriesno << partno; - QList<CoverItem> covers; - if(!front.isEmpty()){ - covers << coverItem(front, "front", md5Sums.value(front)); - } - if(!back.isEmpty()){ - covers << coverItem(back, "back", md5Sums.value(back)); - } - if(!general.isEmpty()){ - covers << coverItem(general, "general", md5Sums.value(general)); - } - QList<QVariant> vAList; - foreach(int a, actors){ - vAList << a; - } - mMovieModel->addMovie(data, vAList, covers); - foreach(QString f, files){ - QFileInfo file(f); - QString hash = md5Sums.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); - } - } -} - -void ArchiveEditDialog::guess(){ - QString fileName = mCoverEditor->movie(); - if(fileName.isEmpty()){ - return; - } - QFileInfo fi(fileName); - QString rfn = fi.completeBaseName(); - rfn.chop(1); - QModelIndexList idx = mMovieModel->columnContains(rfn, MovieItem::Filename); - if(idx.size() > 0){ - QModelIndex cur = idx.at(0); - QList<QVariant> actors = cur.data(MovieModel::ActorsRole).toList(); - foreach(QVariant v, actors){ - mFileWidget->setActor(v.toString()); - } - mFileWidget->setMovieTitle(cur.data(MovieModel::TitleBaseRole).toString()); - mFileWidget->setQuality(cur.data(MovieModel::QualityRole).toInt()); - mFileWidget->setSeriesNo(cur.data(MovieModel::SeriesNoRole).toInt()); - int partno = cur.data(MovieModel::PartNoRole).toInt() + 1; - mFileWidget->setPartNo(partno); - } -} - -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.absoluteFilePath()); - 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); -} - diff --git a/archiveeditdialog.h b/archiveeditdialog.h deleted file mode 100644 index 39e3dc9..0000000 --- a/archiveeditdialog.h +++ /dev/null @@ -1,53 +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. -*/ - -#ifndef ARCHIVEEDITDIALOG_H -#define ARCHIVEEDITDIALOG_H - -#include <QDialog> -#include <QDirModel> - -class ArchiveFileWidget; -class ListEditor; -class CoverEditor; -class ListModel; -class MovieModel; -class QPushButton; -class CoverItem; -class ListModel; - -class ArchiveEditDialog : public QDialog { - Q_OBJECT - public: - ArchiveEditDialog(QWidget *parent = 0, Qt::WindowFlags f = 0); - ~ArchiveEditDialog() {}; - void setFiles(const QStringList &files); - - private slots: - void archive(); - void guess(); - - private: - bool checkInput(int genre, const QList<int> &actors, const QStringList &files, const QString &title, const QString &movie, int quality); - bool checkMd5(const QHash<QString, QString> &md5sums, const QStringList &files); - const CoverItem coverItem(const QString &filePath, const QString type, const QString &md5) const; - ArchiveFileWidget *mFileWidget; - ListEditor *mGenreEditor; - ListEditor *mActorsEditor; - CoverEditor *mCoverEditor; - ListModel *mGenreModel; - ListModel *mActorsModel; - MovieModel *mMovieModel; - QDirModel *mDirModel; - QPushButton *mGuess; - QPushButton *mArchive; - QPushButton *mClose; - -}; - -#endif - diff --git a/archivefileview.cpp b/archivefileview.cpp deleted file mode 100644 index 915dd50..0000000 --- a/archivefileview.cpp +++ /dev/null @@ -1,32 +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 <QContextMenuEvent> -#include <QResizeEvent> -#include <QMenu> -#include <QAction> - -#include "archivefileview.h" - -ArchiveFileView::ArchiveFileView(QWidget *parent) : QTreeView(parent) {}; - -void ArchiveFileView::contextMenuEvent(QContextMenuEvent *e){ - QMenu contextMenu(this); - foreach(QAction *a, actions()){ - contextMenu.addAction(a); - } - contextMenu.exec(e->globalPos()); -} - -void ArchiveFileView::resizeEvent(QResizeEvent *e){ - if(e->size().width() != e->oldSize().width()){ - int width = e->size().width(); - int newWidth = (width / 3 * 2) / 2; - setColumnWidth(0, newWidth); - setColumnWidth(1, newWidth); - } -} diff --git a/archivefileview.h b/archivefileview.h deleted file mode 100644 index 180f706..0000000 --- a/archivefileview.h +++ /dev/null @@ -1,29 +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. -*/ - -#ifndef ARCHIVEFILEVIEW_H -#define ARCHIVEFILEVIEW_H - -#include <QTreeView> - -class QContextMenuEvent; -class QResizeEvent; - -class ArchiveFileView : public QTreeView { - Q_OBJECT - public: - ArchiveFileView(QWidget *parent = 0); - ~ArchiveFileView() {}; - - protected: - virtual void contextMenuEvent(QContextMenuEvent *e); - virtual void resizeEvent(QResizeEvent *e); - -}; - -#endif - diff --git a/archivefilewidget.cpp b/archivefilewidget.cpp deleted file mode 100644 index ce824aa..0000000 --- a/archivefilewidget.cpp +++ /dev/null @@ -1,153 +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 <QLabel> -#include <QTextEdit> -#include <QVBoxLayout> -#include <QHBoxLayout> -#include <QFont> -#include <QComboBox> -#include <QPushButton> -#include <QColor> -#include <QLocale> -#include <QFileInfo> -#include <QScrollArea> -#include <QTreeView> - -#include "archivefilewidget.h" -#include "moviemodel.h" -#include "listmodel.h" -#include "helper.h" -#include "actorwidget.h" -#include "fileinfomodel.h" -#include "listmodelsingleton.h" -#include "moviemodelsingleton.h" - -ArchiveFileWidget::ArchiveFileWidget(QWidget *parent, Qt::WindowFlags f) : QWidget(parent, f){ - //setup - mModel = MovieModelSingleton::instance(); - mGenreModel = ListModelSingleton::instance()->model("genre"); - mActorsModel = ListModelSingleton::instance()->model("actor"); - QVBoxLayout *mainLayout = new QVBoxLayout; - - //selected files - QLabel *l1 = new QLabel(tr("Selected files:")); - mFiles = new QTreeView; - mFiles->setHeaderHidden(true); - mInfoModel = new FileInfoModel(this); - mFiles->setModel(mInfoModel); - - mainLayout->addWidget(l1); - mainLayout->addWidget(mFiles); - - //genre combobox - QHBoxLayout *genreLayout = new QHBoxLayout; - QLabel *l2 = new QLabel(tr("Select genre")); - mGenre = new QComboBox; - mGenre->setModel(mGenreModel); - int idx = mGenre->findText("shemale"); - if(idx != -1){ - mGenre->setCurrentIndex(idx); - } - genreLayout->addWidget(l2); - genreLayout->addWidget(mGenre); - mainLayout->addLayout(genreLayout); - - //actors - mActorWidget = new ActorWidget; - mainLayout->addWidget(mActorWidget); - - //quality and movie title - QHBoxLayout *qualityTitleLayout = new QHBoxLayout; - QLabel *l4 = new QLabel(tr("Select quality")); - mQuality = new QSpinBox; - mQuality->setMinimum(0); - mQuality->setMaximum(10); - QLabel *l5 = new QLabel(tr("Set movie title")); - mTitle = new QLineEdit; - qualityTitleLayout->addWidget(l4); - qualityTitleLayout->addWidget(mQuality); - qualityTitleLayout->addWidget(l5); - qualityTitleLayout->addWidget(mTitle); - mainLayout->addLayout(qualityTitleLayout); - - //series number and part number - QHBoxLayout *numbersLayout = new QHBoxLayout; - QLabel *l6 = new QLabel(tr("Select &series number")); - mSeriesNo = new QSpinBox; - mSeriesNo->setMinimum(-1); - mSeriesNo->setMaximum(1000); - mSeriesNo->setValue(-1); - l6->setBuddy(mSeriesNo); - QLabel *l7 = new QLabel(tr("Select &part number")); - mPartNo = new QSpinBox; - mPartNo->setMinimum(-1); - mPartNo->setMaximum(100); - mPartNo->setValue(-1); - l7->setBuddy(mPartNo); - numbersLayout->addWidget(l6); - numbersLayout->addWidget(mSeriesNo); - numbersLayout->addWidget(l7); - numbersLayout->addWidget(mPartNo); - numbersLayout->addStretch(); - mainLayout->addLayout(numbersLayout); - - setLayout(mainLayout); - setMinimumWidth(600); -} - -void ArchiveFileWidget::setFiles(const QStringList &files){ - mFileList = files; - mInfoModel->clear(); - mInfoModel->addFiles(files); - mFiles->expandAll(); - mFiles->resizeColumnToContents(0); - mActorWidget->clear(); - mTitle->clear(); -} - -const QList<int> ArchiveFileWidget::actorIds() const{ - QList<int> retval; - foreach(const QString s, mActorWidget->actors()){ - QModelIndex idx = mActorsModel->index(s); - if(idx.isValid()){ - retval << idx.data(ListModel::IdRole).toInt(); - } - } - return retval; -} - -int ArchiveFileWidget::genreId() const{ - QString selectedGenre = mGenre->currentText(); - QModelIndex idx = mGenreModel->index(selectedGenre); - int retval(-1); - if(idx.isValid()){ - retval = mGenreModel->data(idx, ListModel::IdRole).toInt(); - } - return retval; -} - -void ArchiveFileWidget::setActor(const QString &actor){ - mActorWidget->addActor(actor); -} - -void ArchiveFileWidget::setQuality(int quality){ - mQuality->setValue(quality); -} - -void ArchiveFileWidget::setMovieTitle(const QString &title){ - mTitle->setText(title.toLower().trimmed()); -} - -void ArchiveFileWidget::setSeriesNo(int seriesno){ - mSeriesNo->setValue(seriesno); -} - -void ArchiveFileWidget::setPartNo(int partno){ - mPartNo->setValue(partno); -} - diff --git a/archivefilewidget.h b/archivefilewidget.h deleted file mode 100644 index 499ac45..0000000 --- a/archivefilewidget.h +++ /dev/null @@ -1,67 +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. -*/ - -#ifndef ARCHIVEFILEWIDGET_H -#define ARCHIVEFILEWIDGET_H - -#include <QWidget> -#include <QHash> -#include <QList> -#include <QLineEdit> -#include <QSpinBox> - -class QTextEdit; -class QComboBox; -class QPushButton; -class QStringList; -class MovieModel; -class ListModel; -class ActorWidget; -class QTreeView; -class FileInfoModel; - -class ArchiveFileWidget : public QWidget { - Q_OBJECT - public: - ArchiveFileWidget(QWidget *parent = 0, Qt::WindowFlags f = 0); - ~ArchiveFileWidget() {}; - void setFiles(const QStringList &files); - const QList<int> actorIds() const; - int genreId() const; - int quality() const { return mQuality->value(); }; - int seriesNo() const { return mSeriesNo->value(); }; - int partNo() const { return mPartNo->value(); }; - const QString movieTitle() const { return mTitle->text(); }; - - signals: - void statusbarMessage(const QString &message); - void archive(); - - public slots: - void setActor(const QString &actor); - void setQuality(int quality); - void setMovieTitle(const QString &title); - void setSeriesNo(int seriesno); - void setPartNo(int partno); - - private: - MovieModel *mModel; - ListModel *mGenreModel; - ListModel *mActorsModel; - FileInfoModel *mInfoModel; - QTreeView *mFiles; - ActorWidget *mActorWidget; - QComboBox *mGenre; - QSpinBox *mQuality; - QSpinBox *mSeriesNo; - QSpinBox *mPartNo; - QLineEdit *mTitle; - QStringList mFileList; -}; - -#endif - diff --git a/archiveitemcoveredit.cpp b/archiveitemcoveredit.cpp deleted file mode 100644 index 5f0deb6..0000000 --- a/archiveitemcoveredit.cpp +++ /dev/null @@ -1,222 +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 <QLabel> -#include <QVBoxLayout> -#include <QGridLayout> -#include <QSignalMapper> -#include <QLineEdit> -#include <QPushButton> -#include <QCheckBox> -#include <QFileDialog> -#include <QSettings> -#include <QSettings> -#include <QFileInfo> -#include <QPalette> - -#include <algorithm> - -#include "archiveitemcoveredit.h" -#include "pictureviewer.h" -#include "coveritem.h" -#include "helper.h" - -ArchiveItemCoverEdit::ArchiveItemCoverEdit(QWidget *parent) : QWidget(parent) { - //Widget setup - QVBoxLayout *mainLayout = new QVBoxLayout; - mPicViewer = new PictureViewer; - QSignalMapper *viewMapper = new QSignalMapper(this); - QSignalMapper *browseMapper = new QSignalMapper(this); - QSignalMapper *unlockMapper = new QSignalMapper(this); - QGridLayout *coverLayout = new QGridLayout; - - //Warning - QLabel *descriptionLabel = new QLabel(tr("Edit covers of movie - if the movie already has covers you have to unlock the specific cover for changing it. Then click browse to select a new cover. WARNING: The old cover will be deleted from archive if you submit the changes!")); - descriptionLabel->setWordWrap(true); - descriptionLabel->setAutoFillBackground(true); - descriptionLabel->setFrameStyle(QFrame::Box); - descriptionLabel->setMargin(5); - QPalette palette = descriptionLabel->palette(); - palette.setColor(QPalette::Window, Qt::white); - descriptionLabel->setPalette(palette); - mainLayout->addWidget(descriptionLabel); - mainLayout->addSpacing(15); - - //Front cover - QLabel *frontCoverLabel = new QLabel(tr("Front cover")); - coverLayout->addWidget(frontCoverLabel, 0, 0); - mFrontCover = new QLineEdit; - mInitialValue.insert(mFrontCover, QString()); - coverLayout->addWidget(mFrontCover, 0, 1); - mBrowseFront = new QPushButton(tr("Browse...")); - connect(mBrowseFront, SIGNAL(clicked()), browseMapper, SLOT(map())); - browseMapper->setMapping(mBrowseFront, mFrontCover); - coverLayout->addWidget(mBrowseFront, 0, 2); - mViewFront = new QPushButton(tr("View")); - connect(mViewFront, SIGNAL(clicked()), viewMapper, SLOT(map())); - viewMapper->setMapping(mViewFront, mFrontCover); - coverLayout->addWidget(mViewFront, 0, 3); - mUnlockFront = new QCheckBox; - mCheckboxTexts.insert(mUnlockFront, qMakePair(tr("Unlock front cover"), tr("Reset and lock front cover"))); - mUnlockFront->setText(mCheckboxTexts.value(mUnlockFront).first); - mLineEditMapping.insert(mFrontCover, mUnlockFront); - mBrowseMap.insert(mUnlockFront, mBrowseFront); - connect(mUnlockFront, SIGNAL(stateChanged(int)), unlockMapper, SLOT(map())); - unlockMapper->setMapping(mUnlockFront, mFrontCover); - coverLayout->addWidget(mUnlockFront, 1, 2, 1, 2, Qt::AlignLeft); - - //Back cover - QLabel *backCoverLabel = new QLabel(tr("Back cover")); - coverLayout->addWidget(backCoverLabel, 2, 0); - mBackCover = new QLineEdit; - mInitialValue.insert(mBackCover, QString()); - coverLayout->addWidget(mBackCover, 2, 1); - mBrowseBack = new QPushButton(tr("Browse...")); - connect(mBrowseBack, SIGNAL(clicked()), browseMapper, SLOT(map())); - browseMapper->setMapping(mBrowseBack, mBackCover); - coverLayout->addWidget(mBrowseBack, 2, 2); - mViewBack = new QPushButton(tr("View")); - connect(mViewBack, SIGNAL(clicked()), viewMapper, SLOT(map())); - viewMapper->setMapping(mViewBack, mBackCover); - coverLayout->addWidget(mViewBack, 2, 3); - mUnlockBack = new QCheckBox; - mCheckboxTexts.insert(mUnlockBack, qMakePair(tr("Unlock back cover"), tr("Reset and lock back cover"))); - mUnlockBack->setText(mCheckboxTexts.value(mUnlockBack).first); - mLineEditMapping.insert(mBackCover, mUnlockBack); - mBrowseMap.insert(mUnlockBack, mBrowseBack); - connect(mUnlockBack, SIGNAL(stateChanged(int)), unlockMapper, SLOT(map())); - unlockMapper->setMapping(mUnlockBack, mBackCover); - coverLayout->addWidget(mUnlockBack, 3, 2, 1, 2, Qt::AlignLeft); - - //General cover - QLabel *generalCoverLabel = new QLabel(tr("General cover")); - coverLayout->addWidget(generalCoverLabel, 4, 0); - mGeneralCover = new QLineEdit; - mInitialValue.insert(mGeneralCover, QString()); - coverLayout->addWidget(mGeneralCover, 4, 1); - mBrowseGeneral = new QPushButton(tr("Browse...")); - connect(mBrowseGeneral, SIGNAL(clicked()), browseMapper, SLOT(map())); - browseMapper->setMapping(mBrowseGeneral, mGeneralCover); - coverLayout->addWidget(mBrowseGeneral, 4, 2); - mViewGeneral = new QPushButton(tr("View")); - connect(mViewGeneral, SIGNAL(clicked()), viewMapper, SLOT(map())); - viewMapper->setMapping(mViewGeneral, mGeneralCover); - coverLayout->addWidget(mViewGeneral, 4, 3); - mUnlockGeneral = new QCheckBox; - mCheckboxTexts.insert(mUnlockGeneral, qMakePair(tr("Unlock general cover"), tr("Reset and lock general cover"))); - mUnlockGeneral->setText(mCheckboxTexts.value(mUnlockGeneral).first); - mLineEditMapping.insert(mGeneralCover, mUnlockGeneral); - mBrowseMap.insert(mUnlockGeneral, mBrowseGeneral); - connect(mUnlockGeneral, SIGNAL(stateChanged(int)), unlockMapper, SLOT(map())); - unlockMapper->setMapping(mUnlockGeneral, mGeneralCover); - coverLayout->addWidget(mUnlockGeneral, 5, 2, 1, 2, Qt::AlignLeft); - - //Connect QSignalMappers - connect(unlockMapper, SIGNAL(mapped(QWidget*)), this, SLOT(unlock(QWidget*))); - connect(browseMapper, SIGNAL(mapped(QWidget*)), this, SLOT(browse(QWidget*))); - connect(viewMapper, SIGNAL(mapped(QWidget*)), this, SLOT(view(QWidget*))); - - //Setup Widget - mainLayout->addLayout(coverLayout); - mainLayout->addStretch(); - setLayout(mainLayout); -} - -void ArchiveItemCoverEdit::setCovers(const QList<QVariant> &covers){ - QList<QVariant>::const_iterator it; - - //Set front cover - it = std::find_if(covers.constBegin(), covers.constEnd(), std::bind2nd(CoverItem::findType(), "front")); - QString initialValue; - if(it != covers.constEnd()){ - initialValue = it->value<CoverItem>().fullPath(); - } - mFrontCover->setText(initialValue); - mInitialValue[mFrontCover] = initialValue; - initialValue.clear(); - mUnlockFront->setChecked(true); - - //Set back cover - it = std::find_if(covers.constBegin(), covers.constEnd(), std::bind2nd(CoverItem::findType(), "back")); - if(it != covers.constEnd()){ - initialValue = it->value<CoverItem>().fullPath(); - } - mBackCover->setText(initialValue); - mInitialValue[mBackCover] = initialValue; - initialValue.clear(); - mUnlockBack->setChecked(true); - - //Set general cover - it = std::find_if(covers.constBegin(), covers.constEnd(), std::bind2nd(CoverItem::findType(), "general")); - if(it != covers.constEnd()){ - initialValue = it->value<CoverItem>().fullPath(); - } - mGeneralCover->setText(initialValue); - mInitialValue[mGeneralCover] = initialValue; - initialValue.clear(); - mUnlockGeneral->setChecked(true); -} - -QList<QVariant> ArchiveItemCoverEdit::covers() const { - QList<QVariant> retval; - QString frontCover = mFrontCover->text(); - if(!frontCover.isEmpty()){ - QString md5Sum = Helper::md5Sum(frontCover); - retval << QVariant::fromValue(CoverItem(frontCover, "front", md5Sum)); - } - QString backCover = mBackCover->text(); - if(!backCover.isEmpty()){ - QString md5Sum = Helper::md5Sum(backCover); - retval << QVariant::fromValue(CoverItem(backCover, "back", md5Sum)); - } - QString generalCover = mGeneralCover->text(); - if(!generalCover.isEmpty()){ - QString md5Sum = Helper::md5Sum(generalCover); - retval << QVariant::fromValue(CoverItem(generalCover, "general", md5Sum)); - } - return retval; -} - -void ArchiveItemCoverEdit::unlock(QWidget *lineEdit){ - QLineEdit *editor = static_cast<QLineEdit*>(lineEdit); - Q_ASSERT(editor); - QCheckBox *checkBox = mLineEditMapping.value(editor); - if(!checkBox->isChecked()){ - editor->setEnabled(true); - mBrowseMap.value(checkBox)->setEnabled(true); - checkBox->setText(mCheckboxTexts.value(checkBox).second); - }else{ - editor->setText(mInitialValue.value(editor)); - editor->setEnabled(false); - mBrowseMap.value(checkBox)->setEnabled(false); - checkBox->setText(mCheckboxTexts.value(checkBox).first); - } -} - -void ArchiveItemCoverEdit::browse(QWidget *lineEdit){ - QLineEdit *editor = static_cast<QLineEdit*>(lineEdit); - Q_ASSERT(editor); - if(mLastOpenedDir.isEmpty()){ - QSettings s; - mLastOpenedDir = s.value("paths/selecteddir", QDir::homePath()).toString(); - } - QString cover = QFileDialog::getOpenFileName(this, "Select cover", mLastOpenedDir); - editor->setText(cover); - if(!cover.isEmpty()){ - QFileInfo fi(cover); - mLastOpenedDir = fi.absoluteFilePath(); - } -} - -void ArchiveItemCoverEdit::view(QWidget *lineEdit){ - QLineEdit *editor = static_cast<QLineEdit*>(lineEdit); - Q_ASSERT(editor); - QString file = editor->text(); - if(!file.isEmpty()){ - mPicViewer->showPic(file, false); - } -} diff --git a/archiveitemcoveredit.h b/archiveitemcoveredit.h deleted file mode 100644 index 7f91a49..0000000 --- a/archiveitemcoveredit.h +++ /dev/null @@ -1,54 +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. -*/ - -#ifndef ARCHIVEITEMCOVEREDIT_H -#define ARCHIVEITEMCOVEREDIT_H - -#include <QWidget> -#include <QHash> -#include <QPair> -#include <QList> - -class QLineEdit; -class QPushButton; -class QCheckBox; -class PictureViewer; - -class ArchiveItemCoverEdit : public QWidget { - Q_OBJECT - public: - explicit ArchiveItemCoverEdit(QWidget *parent = 0); - void setCovers(const QList<QVariant> &covers); - QList<QVariant> covers() const; - - private slots: - void unlock(QWidget *lineEdit); - void browse(QWidget *lineEdit); - void view(QWidget *lineEdit); - - private: - QLineEdit *mFrontCover; - QLineEdit *mBackCover; - QLineEdit *mGeneralCover; - QPushButton *mBrowseFront; - QPushButton *mBrowseBack; - QPushButton *mBrowseGeneral; - QPushButton *mViewFront; - QPushButton *mViewBack; - QPushButton *mViewGeneral; - QCheckBox *mUnlockFront; - QCheckBox *mUnlockBack; - QCheckBox *mUnlockGeneral; - QHash<QLineEdit*, QCheckBox*> mLineEditMapping; - QHash<QLineEdit*, QString> mInitialValue; - QHash<QCheckBox*, QPair<QString, QString> > mCheckboxTexts; - QHash<QCheckBox*, QPushButton*> mBrowseMap; - QString mLastOpenedDir; - PictureViewer *mPicViewer; -}; - -#endif diff --git a/archiveitemeditdialog.cpp b/archiveitemeditdialog.cpp deleted file mode 100644 index 90aa1df..0000000 --- a/archiveitemeditdialog.cpp +++ /dev/null @@ -1,180 +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 <QVBoxLayout> -#include <QHBoxLayout> -#include <QPushButton> -#include <QTabWidget> - -#include <algorithm> - -#include "archiveitemeditdialog.h" -#include "archiveiteminfoedit.h" -#include "archiveitemcoveredit.h" -#include "moviemodelsingleton.h" -#include "moviemodel.h" -#include "movieitem.h" -#include "fileinfomodel.h" -#include "listmodelsingleton.h" -#include "listmodel.h" -#include "coveritem.h" -#include "helper.h" - -ArchiveItemEditDialog::ArchiveItemEditDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f), mMovieId(-1){ - //Init dialog - QVBoxLayout *mainLayout = new QVBoxLayout; - - //Tab widget - mTab = new QTabWidget; - mInfoEdit = new ArchiveItemInfoEdit; - mTab->addTab(mInfoEdit, tr("General")); - mCoverEdit = new ArchiveItemCoverEdit; - mTab->addTab(mCoverEdit, tr("Covers")); - mainLayout->addWidget(mTab); - - //Button layout - QHBoxLayout *buttonLayout = new QHBoxLayout; - mCancel = new QPushButton(tr("Cancel")); - connect(mCancel, SIGNAL(clicked()), this, SLOT(reject())); - mUpdate = new QPushButton(tr("Update")); - connect(mUpdate, SIGNAL(clicked()), this, SLOT(accept())); - buttonLayout->addStretch(); - buttonLayout->addWidget(mCancel); - buttonLayout->addWidget(mUpdate); - mainLayout->addLayout(buttonLayout); - - setLayout(mainLayout); -} - -void ArchiveItemEditDialog::setMovie(const QModelIndex &idx){ - if(!idx.isValid()){ - return; - } - - //Numbers and title setup - mInfoEdit->setTitle(idx.data(MovieModel::TitleBaseRole).toString()); - mInfoEdit->setDvd(idx.data(MovieModel::DvdRole).toInt()); - mInfoEdit->setSeries(idx.data(MovieModel::SeriesNoRole).toInt()); - mInfoEdit->setPart(idx.data(MovieModel::PartNoRole).toInt()); - mInfoEdit->setGenre(idx.data(MovieModel::GenreRole).toString()); - mInfoEdit->setQuality(idx.data(MovieModel::QualityRole).toInt()); - - //File and actor info - mInfoEdit->setup(idx); - - //Set covers - mCoverEdit->setCovers(idx.data(MovieModel::CoverRole).toList()); - - //Store ID - mMovieId = idx.data(MovieModel::IdRole).toInt(); - - //Window Title - QString title = QString(tr("Edit %1")).arg(idx.data().toString()); - setWindowTitle(title); -} - -void ArchiveItemEditDialog::accept(){ - //Get Models - ListModel *actorModel = ListModelSingleton::instance()->model("actor"); - ListModel *genreModel = ListModelSingleton::instance()->model("genre"); - MovieModel *movieModel = MovieModelSingleton::instance(); - - //Update actors - QStringList actors = mInfoEdit->actors(); - QList<QVariant> actorIds; - foreach(QString a, actors){ - QModelIndex idx = actorModel->index(a); - if(idx.isValid()){ - actorIds << idx.data(ListModel::IdRole); - } - } - movieModel->setActors(mMovieId, actorIds); - - //Update genre - QString genre = mInfoEdit->genre(); - QVariant genreId = genreModel->index(genre).data(ListModel::IdRole); - QModelIndex movieModelIndex = movieModel->index(mMovieId, MovieItem::Genre); - movieModel->setDataAt(movieModelIndex, genreId); - - //Update quality - movieModelIndex = movieModel->index(mMovieId, MovieItem::Quality); - movieModel->setDataAt(movieModelIndex, mInfoEdit->quality()); - - //Update dvdno - movieModelIndex = movieModel->index(mMovieId, MovieItem::Dvd); - movieModel->setDataAt(movieModelIndex, mInfoEdit->dvd()); - - //Update seriesno - movieModelIndex = movieModel->index(mMovieId, MovieItem::SeriesNo); - movieModel->setDataAt(movieModelIndex, mInfoEdit->series()); - - //Update partno - movieModelIndex = movieModel->index(mMovieId, MovieItem::PartNo); - movieModel->setDataAt(movieModelIndex, mInfoEdit->part()); - - //Update title - movieModelIndex = movieModel->index(mMovieId, MovieItem::Title); - if(!mInfoEdit->title().isEmpty()){ - movieModel->setDataAt(movieModelIndex, mInfoEdit->title()); - } - - //Update covers - updateCovers(); - - QDialog::accept(); -} - -void ArchiveItemEditDialog::updateCovers(){ - //Get model and covers - MovieModel *movieModel = MovieModelSingleton::instance(); - QModelIndex movieIdx = movieModel->index(mMovieId); - QList<QVariant> currentCovers = movieIdx.data(MovieModel::CoverRole).toList(); - QList<QVariant> newCovers = mCoverEdit->covers(); - - //Front - CoverItem curFront = cover(currentCovers, "front"); - CoverItem newFront = cover(newCovers, "front"); - updateCover(curFront, newFront); - - //Back - CoverItem curBack = cover(currentCovers, "back"); - CoverItem newBack = cover(newCovers, "back"); - updateCover(curBack, newBack); - - //General - CoverItem curGeneral = cover(currentCovers, "general"); - CoverItem newGeneral = cover(newCovers, "general"); - updateCover(curGeneral, newGeneral); - - //Update database - QList<CoverItem> coverList; - foreach(QVariant c, newCovers){ - coverList << c.value<CoverItem>(); - } - movieModel->setCovers(mMovieId, coverList); -} - -void ArchiveItemEditDialog::updateCover(const CoverItem &oldCover, const CoverItem &newCover){ - if(oldCover == newCover){ - return; - } - if(oldCover != CoverItem()){ - Helper::removeFromArchive(oldCover.fileName(), oldCover.md5()); - } - if(newCover != CoverItem()){ - Helper::moveToArchive(newCover.fullPath(), newCover.md5()); - } -} - -CoverItem ArchiveItemEditDialog::cover(const QList<QVariant> &coverList, const QString &type) const{ - QList<QVariant>::const_iterator it = std::find_if(coverList.constBegin(), coverList.constEnd(), std::bind2nd(CoverItem::findType(), type)); - CoverItem retval = CoverItem(); - if(it != coverList.constEnd()){ - retval = it->value<CoverItem>(); - } - return retval; -} diff --git a/archiveitemeditdialog.h b/archiveitemeditdialog.h deleted file mode 100644 index de87bed..0000000 --- a/archiveitemeditdialog.h +++ /dev/null @@ -1,41 +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. -*/ - -#ifndef ARCHIVEITEMEDITDIALOG_H -#define ARCHIVEITEMEDITDIALOG_H - -#include <QDialog> - -class QPushButton; -class QTabWidget; -class QModelIndex; -class ArchiveItemInfoEdit; -class ArchiveItemCoverEdit; -class CoverItem; - -class ArchiveItemEditDialog : public QDialog { - Q_OBJECT - public: - explicit ArchiveItemEditDialog(QWidget *parent = 0, Qt::WindowFlags f = 0); - void setMovie(const QModelIndex &idx); - - public slots: - void accept(); - - private: - void updateCovers(); - void updateCover(const CoverItem &oldCover, const CoverItem &newCover); - CoverItem cover(const QList<QVariant> &coverList, const QString &type) const; - QPushButton *mUpdate; - QPushButton *mCancel; - QTabWidget *mTab; - ArchiveItemInfoEdit *mInfoEdit; - ArchiveItemCoverEdit *mCoverEdit; - int mMovieId; -}; - -#endif diff --git a/archiveiteminfoedit.cpp b/archiveiteminfoedit.cpp deleted file mode 100644 index 70e5afe..0000000 --- a/archiveiteminfoedit.cpp +++ /dev/null @@ -1,209 +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 <QVBoxLayout> -#include <QHBoxLayout> -#include <QLabel> -#include <QTreeView> -#include <QComboBox> -#include <QSpinBox> -#include <QLineEdit> -#include <QSplitter> -#include <QModelIndex> - -#include "archiveiteminfoedit.h" -#include "fileinfomodel.h" -#include "actorwidget.h" -#include "listmodelsingleton.h" -#include "listeditor.h" -#include "moviemodel.h" - - -ArchiveItemInfoEdit::ArchiveItemInfoEdit(QWidget *parent) : QWidget(parent){ - //Models - mGenreModel = ListModelSingleton::instance()->model("genre"); - mActorModel = ListModelSingleton::instance()->model("actor"); - - //InfoWidget - QWidget *infoWidget = new QWidget; - QVBoxLayout *infoWidgetLayout = new QVBoxLayout; - - //Movie Information - QLabel *infoCaption = new QLabel(tr("Movie Information")); - infoWidgetLayout->addWidget(infoCaption); - mInfoView = new QTreeView; - mInfoModel = new FileInfoModel; - mInfoView->setModel(mInfoModel); - infoWidgetLayout->addWidget(mInfoView); - - //Actor Information - mActorView = new ActorWidget; - infoWidgetLayout->addWidget(mActorView); - - //Genre Information - QLabel *genreLabel = new QLabel(tr("Select genre")); - mGenre = new QComboBox; - mGenre->setModel(mGenreModel); - QHBoxLayout *genreLayout = new QHBoxLayout; - genreLayout->addWidget(genreLabel); - genreLayout->addWidget(mGenre); - infoWidgetLayout->addLayout(genreLayout); - - //Quality, Series, Part + DVD Infomation - QHBoxLayout *miscInfoLayout = new QHBoxLayout; - - //Quality - QLabel *qualityLabel = new QLabel(tr("Quality")); - mQuality = new QSpinBox; - mQuality->setMinimum(0); - mQuality->setMaximum(10); - miscInfoLayout->addWidget(qualityLabel); - miscInfoLayout->addWidget(mQuality); - - //DVD - QLabel *dvdLabel = new QLabel(tr("DVD no.")); - mDvd = new QSpinBox; - mDvd->setMinimum(-1); - mDvd->setMaximum(1000); - miscInfoLayout->addWidget(dvdLabel); - miscInfoLayout->addWidget(mDvd); - miscInfoLayout->addStretch(); - - //Series - QLabel *seriesLabel = new QLabel(tr("Series no.")); - mSeries = new QSpinBox; - mSeries->setMinimum(-1); - mSeries->setMaximum(1000); - miscInfoLayout->addWidget(seriesLabel); - miscInfoLayout->addWidget(mSeries); - - //Part - QLabel *partLabel = new QLabel(tr("Part no.")); - mPart = new QSpinBox; - mPart->setMinimum(-1); - mPart->setMaximum(100); - miscInfoLayout->addWidget(partLabel); - miscInfoLayout->addWidget(mPart); - - //Add to infoWidget - infoWidgetLayout->addLayout(miscInfoLayout); - - //Title - QHBoxLayout *titleLayout = new QHBoxLayout; - QLabel *titleLabel = new QLabel(tr("Movie title")); - mTitle = new QLineEdit; - titleLayout->addWidget(titleLabel); - titleLayout->addWidget(mTitle); - infoWidgetLayout->addLayout(titleLayout); - - //Create widget - infoWidget->setLayout(infoWidgetLayout); - - //ListEditorWidget - QWidget *editorWidget = new QWidget; - QVBoxLayout *editorWidgetLayout = new QVBoxLayout; - - //GenreEditor - ListEditor *genreEditor = new ListEditor(mGenreModel); - editorWidgetLayout->addWidget(genreEditor); - - //ActorEditor - ListEditor *actorEditor = new ListEditor(mActorModel); - editorWidgetLayout->addWidget(actorEditor); - connect(actorEditor, SIGNAL(itemAdded(QString)), this, SLOT(addActor(QString))); - editorWidgetLayout->addStretch(); - - //Create widget - editorWidget->setLayout(editorWidgetLayout); - - //Splitter - QSplitter *splitter = new QSplitter; - splitter->addWidget(infoWidget); - splitter->addWidget(editorWidget); - - //Create this widget - QVBoxLayout *mainLayout = new QVBoxLayout; - mainLayout->addWidget(splitter); - setLayout(mainLayout); -} - -void ArchiveItemInfoEdit::setup(const QModelIndex &idx) { - //Movie Info - QString title = QString(idx.data().toString()); - mInfoModel->clear(); - mInfoModel->addIndex(title, idx); - mInfoView->resizeColumnToContents(0); - mInfoView->setHeaderHidden(true); - mInfoView->expandAll(); - - //Actors - mActorView->clear(); - QStringList actors = idx.data(MovieModel::ActorsRole).toStringList(); - qSort(actors); - foreach(QString a, actors){ - mActorView->addActor(a); - } -} - -const QString ArchiveItemInfoEdit::genre() const { - return mGenre->currentText(); -} - -const QString ArchiveItemInfoEdit::title() const { - return mTitle->text().trimmed().toLower(); -} - -const QStringList ArchiveItemInfoEdit::actors() const { - return mActorView->actors(); -} - -int ArchiveItemInfoEdit::quality() const { - return mQuality->value(); -} - -int ArchiveItemInfoEdit::dvd() const { - return mDvd->value(); -} - -int ArchiveItemInfoEdit::series() const { - return mSeries->value(); -} - -int ArchiveItemInfoEdit::part() const { - return mPart->value(); -} - -void ArchiveItemInfoEdit::setGenre(const QString &genre){ - QModelIndex idx = mGenreModel->index(genre); - if(idx.isValid()){ - mGenre->setCurrentIndex(idx.row()); - } -} - -void ArchiveItemInfoEdit::setTitle(const QString &title){ - mTitle->setText(title); -} - -void ArchiveItemInfoEdit::setQuality(int quality){ - mQuality->setValue(quality); -} - -void ArchiveItemInfoEdit::setDvd(int dvd){ - mDvd->setValue(dvd); -} - -void ArchiveItemInfoEdit::setSeries(int series){ - mSeries->setValue(series); -} - -void ArchiveItemInfoEdit::setPart(int part){ - mPart->setValue(part); -} - -void ArchiveItemInfoEdit::addActor(const QString &actor){ - mActorView->addActor(actor); -} diff --git a/archiveiteminfoedit.h b/archiveiteminfoedit.h deleted file mode 100644 index 98a1736..0000000 --- a/archiveiteminfoedit.h +++ /dev/null @@ -1,60 +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. -*/ - -#ifndef ARCHIVEITEMINFOEDIT_H -#define ARCHIVEITEMINFOEDIT_H - -#include <QWidget> - -class QTreeView; -class QComboBox; -class QSpinBox; -class QLineEdit; -class FileInfoModel; -class ActorWidget; -class ListModel; -class QModelIndex; - -class ArchiveItemInfoEdit : public QWidget { - Q_OBJECT - public: - explicit ArchiveItemInfoEdit(QWidget *parent = 0); - void setup(const QModelIndex &idx); - const QString genre() const; - const QString title() const; - const QStringList actors() const; - int quality() const; - int dvd() const; - int series() const; - int part() const; - - public slots: - void setGenre(const QString &genre); - void setTitle(const QString &title); - void setQuality(int quality); - void setDvd(int dvd); - void setSeries(int series); - void setPart(int part); - - private slots: - void addActor(const QString &actor); - - private: - QTreeView *mInfoView; - QComboBox *mGenre; - QSpinBox *mQuality; - QSpinBox *mDvd; - QSpinBox *mSeries; - QSpinBox *mPart; - QLineEdit *mTitle; - ActorWidget *mActorView; - FileInfoModel *mInfoModel; - ListModel *mGenreModel; - ListModel *mActorModel; -}; - -#endif diff --git a/archiveproxy.cpp b/archiveproxy.cpp deleted file mode 100644 index 90374c6..0000000 --- a/archiveproxy.cpp +++ /dev/null @@ -1,92 +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 <QStringList> -#include <QRegExp> -#include <QList> - -#include "archiveproxy.h" -#include "moviemodel.h" - -ArchiveProxy::ArchiveProxy(QObject *parent) : QSortFilterProxyModel(parent){}; - -void ArchiveProxy::setFilter(const QString &filter, FilterMode mode){ - mFilterMode = mode; - switch(mFilterMode){ - case NoFilter: - mGenreFilter = QString(); - mActorFilter = QString(); - mTitleFilter = QString(); - break; - case GenreFilter: - mGenreFilter = filter; - break; - case ActorFilter: - mActorFilter = filter; - break; - case TitleFilter: - mTitleFilter = filter.toLower(); - break; - } - invalidate(); -} - -bool ArchiveProxy::filterAcceptsRow(int sourceRow, const QModelIndex & /*sourceParent*/) const{ - if(mFilterMode == NoFilter){ - return true; - } - MovieModel *model = static_cast<MovieModel*>(sourceModel()); - Q_ASSERT(model != 0); - if(mFilterMode == ActorFilter){ - QModelIndex idx = model->index(sourceRow, 0, QModelIndex()); - QStringList actors = model->data(idx, MovieModel::ActorsRole).toStringList(); - return actors.contains(mActorFilter); - } - if(mFilterMode == GenreFilter){ - QModelIndex idx = model->index(sourceRow, 4, QModelIndex()); - QString genre = idx.data().toString(); - return (genre == mGenreFilter); - } - if(mFilterMode == TitleFilter){ - QModelIndex idx = model->index(sourceRow, 0, QModelIndex()); - QString title = idx.data().toString(); - QRegExp re(mTitleFilter); - return( re.indexIn(title) != -1); - } - return true; -} - -void ArchiveProxy::clearFilter(){ - mFilterMode = NoFilter; - mGenreFilter = QString(); - mActorFilter = QString(); - mTitleFilter = QString(); - invalidate(); -} - -bool ArchiveProxy::lessThan(const QModelIndex &left, const QModelIndex &right) const{ - if(left.column() > 0){ - return QSortFilterProxyModel::lessThan(left, right); - } - QString lbase = left.data(MovieModel::TitleBaseRole).toString(); - QString rbase = right.data(MovieModel::TitleBaseRole).toString(); - if(lbase == rbase){ - int lseriesno = left.data(MovieModel::SeriesNoRole).toInt(); - int rseriesno = right.data(MovieModel::SeriesNoRole).toInt(); - if(lseriesno == rseriesno){ - int lpartno = left.data(MovieModel::PartNoRole).toInt(); - int rpartno = right.data(MovieModel::PartNoRole).toInt(); - return (lpartno < rpartno); - }else{ - return (lseriesno < rseriesno); - } - }else{ - return (lbase < rbase); - } - return QSortFilterProxyModel::lessThan(left, right); -} - diff --git a/archiveproxy.h b/archiveproxy.h deleted file mode 100644 index 346b770..0000000 --- a/archiveproxy.h +++ /dev/null @@ -1,40 +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. -*/ - -#ifndef ARCHIVEPROXY_H -#define ARCHIVEPROXY_H - -#include <QSortFilterProxyModel> - -class QString; -class QModelIndex; - -class ArchiveProxy : public QSortFilterProxyModel { - Q_OBJECT - Q_ENUMS(FilterMode) - public: - enum FilterMode { NoFilter, GenreFilter, ActorFilter, TitleFilter }; - ArchiveProxy(QObject *parent = 0); - ~ArchiveProxy() {}; - void setFilter(const QString &filter, FilterMode mode); - virtual bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const; - - public slots: - void clearFilter(); - - protected: - virtual bool lessThan(const QModelIndex &left, const QModelIndex &right) const; - - private: - FilterMode mFilterMode; - QString mGenreFilter; - QString mActorFilter; - QString mTitleFilter; -}; - -#endif - 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 <QComboBox> -#include <QLineEdit> -#include <QLineEdit> -#include <QLabel> -#include <QHBoxLayout> -#include <QVBoxLayout> -#include <QPushButton> -#include <QMessageBox> -#include <QApplication> -#include <QSettings> -#include <QProcess> -#include <QDir> -#include <QRegExp> -#include <QHash> - -#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<QString, QStringList> 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<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(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<QVariant> 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<QString, QStringList> 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<QString, QVariant> actorMap = idx.data(MovieModel::ActorsMap).toHash(); - QList<QVariant> actorIds; - foreach(QVariant id, actorMap.values()){ - actorIds << id.toInt(); - } - QList<CoverItem> covers; - foreach(QVariant cover, idx.data(MovieModel::CoverRole).toList()){ - covers << cover.value<CoverItem>(); - } - QList<QVariant> 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<QString, QStringList> ArchiveViewWidget::playerData(const QString &preferred){ - QSettings s; - QHash<QString, QVariant> data = s.value("programs_movieviewer/data").toHash(); - if(!preferred.isEmpty()){ - if(data.keys().contains(preferred)){ - QHash<QString, QVariant> pData = data.value(preferred).toHash(); - return qMakePair(pData.value("path").toString(), pData.value("args").toStringList()); - } - return QPair<QString, QStringList>(); - } - QString defaultPlayer = s.value("programs_movieviewer/default").toString(); - if(data.keys().contains(defaultPlayer)){ - QHash<QString, QVariant> pData = data.value(defaultPlayer).toHash(); - return qMakePair(pData.value("path").toString(), pData.value("args").toStringList()); - } - return QPair<QString, QStringList>(); -} - -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; -} diff --git a/archiveviewwidget.h b/archiveviewwidget.h deleted file mode 100644 index c171707..0000000 --- a/archiveviewwidget.h +++ /dev/null @@ -1,79 +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. -*/ - -#ifndef ARCHIVEVIEWWIDGET_H -#define ARCHIVEVIEWWIDGET_H - -#include <QWidget> -#include <QPair> - -#include "archivefileview.h" - -class MovieModel; -class ListModel; -class QComboBox; -class QLineEdit; -class QPushButton; -class QModelIndex; -class ArchiveFileView; -class ArchiveProxy; -class ArchiveItemEditDialog; - -class ArchiveViewWidget : public QWidget { - Q_OBJECT - public: - ArchiveViewWidget(MovieModel *model, ListModel *genre, ListModel *actors, QWidget *parent = 0); - ~ArchiveViewWidget() {}; - ArchiveFileView* fileView() { return mFileView; }; - void setEditDialog(ArchiveItemEditDialog *dlg) { mEditDialog = dlg; }; - const QString &windowTitle() const { return mWindowTitle; }; - qint64 currentSize() const { return mSize; }; - - public slots: - void editFile(); - void addMovie(); - void showMovie(const QModelIndex &movie); - void properties(); - void setFilter(); - void setGenreFilter(const QString &filter); - void setActorFilter(const QString &filter); - void moveBurn(); - void setDvdNo(); - void deleteFromArchive(); - void playSelected(const QString &player = QString()); - void copyToParts(); - - signals: - void statusbarMessage(const QString &message); - void windowTitle(const QString &title); - void refreshDir(const QString &dir); - - private slots: - void rowChanged(const QModelIndex ¤t, const QModelIndex &prev); - void calcSize(); - - private: - const QModelIndex getSourceColumnZero(); - QPair<QString, QStringList> playerData(const QString &preferred); - QStringList selectedFiles(); - QComboBox *mGenre; - QComboBox *mActors; - QLineEdit *mName; - QPushButton *mFilter; - QPushButton *mClearFilter; - MovieModel *mMovieModel; - ListModel *mGenreModel; - ListModel *mActorsModel; - ArchiveFileView *mFileView; - ArchiveProxy *mProxy; - ArchiveItemEditDialog *mEditDialog; - QString mWindowTitle; - qint64 mSize; -}; - -#endif - diff --git a/covereditor.cpp b/covereditor.cpp deleted file mode 100644 index f7a7120..0000000 --- a/covereditor.cpp +++ /dev/null @@ -1,132 +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 <QComboBox> -#include <QStringList> -#include <QLabel> -#include <QGridLayout> -#include <QFileDialog> -#include <QPushButton> -#include <QSettings> - -#include "covereditor.h" - -CoverEditor::CoverEditor(QWidget *parent, Qt::WindowFlags f) : QWidget(parent, f){ - QGridLayout *mainLayout = new QGridLayout; - QLabel *l1 = new QLabel(tr("Front cover")); - mFrontCover = new QComboBox; - mainLayout->addWidget(l1, 0, 0); - mainLayout->addWidget(mFrontCover, 0, 1); - QLabel *l2 = new QLabel(tr("Back cover")); - mBackCover = new QComboBox; - mainLayout->addWidget(l2, 1, 0); - mainLayout->addWidget(mBackCover, 1, 1); - QLabel *l3 = new QLabel(tr("General cover")); - mCovers = new QComboBox; - mainLayout->addWidget(l3, 2, 0); - mainLayout->addWidget(mCovers, 2, 1); - QLabel *l4 = new QLabel(tr("Movie file")); - mMovie = new QComboBox; - mainLayout->addWidget(l4, 3, 0); - mainLayout->addWidget(mMovie, 3, 1); - mainLayout->setContentsMargins(0, 0, 0, 0); - setLayout(mainLayout); -} - -void CoverEditor::setCovers(const QStringList &covers){ - mCoverPaths = covers; - QStringList coverNames("-"); - QString front, back, movie; - int idx(-1); - foreach(QString c, mCoverPaths){ - if((idx = c.lastIndexOf('/')) != -1){ - c.remove(0, idx + 1); - } - if(c.toLower().contains("front")){ - front = c; - } - if(c.toLower().contains("back")){ - back = c; - } - if(c.toLower().endsWith(".avi")){ - movie = c; - } - coverNames << c; - } - mFrontCover->clear(); - mFrontCover->addItems(coverNames); - mBackCover->clear(); - mBackCover->addItems(coverNames); - mCovers->clear(); - mCovers->addItems(coverNames); - mMovie->clear(); - mMovie->addItems(coverNames); - if(!front.isEmpty()){ - int idx = mFrontCover->findText(front); - if(idx != -1){ - mFrontCover->setCurrentIndex(idx); - } - } - if(!back.isEmpty()){ - int idx = mBackCover->findText(back); - if(idx != -1){ - mBackCover->setCurrentIndex(idx); - } - } - if(!movie.isEmpty()){ - int idx = mMovie->findText(movie); - if(idx != -1){ - mMovie->setCurrentIndex(idx); - } - } -} - -const QString CoverEditor::frontCover() const{ - QString sel = mFrontCover->currentText(); - if(sel.isEmpty() || (sel == "-")){ - return QString(); - } - return findPath(sel); -} - -const QString CoverEditor::backCover() const{ - QString sel = mBackCover->currentText(); - if(sel.isEmpty() || (sel == "-")){ - return QString(); - } - return findPath(sel); -} - -const QString CoverEditor::covers() const{ - QString sel = mCovers->currentText(); - if(sel.isEmpty() || (sel == "-")){ - return QString(); - } - return findPath(sel); - -} - -const QString CoverEditor::movie() const{ - QString sel = mMovie->currentText(); - if(sel.isEmpty() || (sel == "-")){ - return QString(); - } - return findPath(sel); - -} - -const QString CoverEditor::findPath(const QString &name) const{ - QString retval; - foreach(QString s, mCoverPaths){ - if(s.endsWith(name)){ - retval = s; - break; - } - } - return retval; -} - diff --git a/covereditor.h b/covereditor.h deleted file mode 100644 index c702ef8..0000000 --- a/covereditor.h +++ /dev/null @@ -1,37 +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. -*/ - -#ifndef COVEREDITOR_H -#define COVEREDITOR_H - -#include <QWidget> - -class QComboBox; -class QStringList; - -class CoverEditor : public QWidget { - Q_OBJECT - public: - CoverEditor(QWidget *parent = 0, Qt::WindowFlags f = 0); - ~CoverEditor() {}; - void setCovers(const QStringList &covers); - const QString frontCover() const; - const QString backCover() const; - const QString covers() const; - const QString movie() const; - - private: - const QString findPath(const QString &name) const; - QComboBox *mFrontCover; - QComboBox *mBackCover; - QComboBox *mCovers; - QComboBox *mMovie; - QStringList mCoverPaths; -}; - -#endif - diff --git a/coveritem.cpp b/coveritem.cpp deleted file mode 100644 index ab72844..0000000 --- a/coveritem.cpp +++ /dev/null @@ -1,51 +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 <QString> -#include <QFileInfo> -#include <QVariant> - -#include "coveritem.h" - -bool CoverItem::findType::operator()(const QVariant item, const QString type) const{ - CoverItem i = item.value<CoverItem>(); - return (i.type() == type); -} - -bool CoverItem::findFilename::operator()(const QVariant item, const QString filename) const{ - CoverItem i = item.value<CoverItem>(); - return (i.fileName() == filename); -} - -CoverItem::CoverItem(const QString &fullPath, const QString &type, const QString &md5) : mFullPath(fullPath), mType(type), mMd5(md5){ - setFileName(); -} - -CoverItem::CoverItem() {}; - -bool CoverItem::operator==(const CoverItem &i) const{ - return ((mFullPath == i.fullPath()) && (mFilename == i.fileName()) && (mType == i.type()) && (mMd5 == mMd5)); -} - -bool CoverItem::operator!=(const CoverItem &i) const{ - return !(*this == i); -} - -void CoverItem::setMd5(const QString &md5){ - mMd5 = md5; -} - -void CoverItem::setFullPath(const QString &fullPath){ - mFullPath = fullPath; - setFileName(); -} - -void CoverItem::setFileName(){ - QFileInfo info(mFullPath); - mFilename = info.fileName(); -} - diff --git a/coveritem.h b/coveritem.h deleted file mode 100644 index f20f5e9..0000000 --- a/coveritem.h +++ /dev/null @@ -1,50 +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. -*/ - -#ifndef COVERITEM_H -#define COVERITEM_H - -#include <QMetaType> - -class QString; -class QVariant; - -class CoverItem { - public: - class findType : public std::binary_function<QVariant, QString, bool> { - public: - bool operator()(const QVariant item, const QString type) const; - }; - class findFilename : public std::binary_function<QVariant, QString, bool> { - public: - bool operator()(const QVariant item, const QString filename) const; - }; - CoverItem(); - CoverItem(const QString &fullPath, const QString &type, const QString &md5); - ~CoverItem() {}; - bool operator==(const CoverItem &i) const; - bool operator!=(const CoverItem &i) const; - const QString fileName() const { return mFilename; }; - const QString fullPath() const { return mFullPath; }; - const QString type() const { return mType; }; - const QString md5() const { return mMd5; }; - void setType(const QString &type) { mType = type; }; - void setMd5(const QString &md5); - void setFullPath(const QString &fullPath); - - private: - void setFileName(); - QString mFullPath; - QString mFilename; - QString mType; - QString mMd5; -}; - -Q_DECLARE_METATYPE(CoverItem) - -#endif - diff --git a/fileinfoitem.cpp b/fileinfoitem.cpp deleted file mode 100644 index 0d2e605..0000000 --- a/fileinfoitem.cpp +++ /dev/null @@ -1,133 +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 <QFileInfo> -#include <QVariant> -#include <QLocale> - -#include "fileinfoitem.h" -#include "moviemodel.h" -#include "helper.h" - -FileInfoItem::FileInfoItem(const QString &fn, FileInfoItem *parent, QObject *oParent) : QObject(oParent){ - mParent = parent; - mFullFilename = fn; - QFileInfo fi(fn); - mData << fi.fileName() << QVariant(); -} - -FileInfoItem::FileInfoItem(const QList<QVariant> &data, FileInfoItem *parent, QObject *oParent) : QObject(oParent){ - mParent = parent; - mData = data; -} - -FileInfoItem::FileInfoItem(const QString &title, const QModelIndex &index, FileInfoItem *parent, QObject *oParent) : QObject(oParent){ - mIndex = index; - mParent = parent; - mData << title << QVariant(); -} - -FileInfoItem::~FileInfoItem() { - qDeleteAll(mChildren); - mChildren.clear(); -} - -FileInfoItem* FileInfoItem::child(int row){ - return mChildren.value(row); -} - -int FileInfoItem::childCount() const { - return mChildren.count(); -} - -int FileInfoItem::row() const { - if(mParent){ - return mParent->mChildren.indexOf(const_cast<FileInfoItem*>(this)); - } - return 0; -} - -int FileInfoItem::columnCount() const { - return mData.count(); -} - -QVariant FileInfoItem::data(int column) const { - return mData.value(column); -} - -FileInfoItem *FileInfoItem::parent() { - return mParent; -} - -void FileInfoItem::populate() { - QFileInfo fi(mFullFilename); - QList<QVariant> d1; - d1 << tr("Size") << fi.size(); - FileInfoItem *fi1 = new FileInfoItem(d1, this); - mChildren.append(fi1); - QString md5sum = Helper::md5Sum(mFullFilename); - QList<QVariant> d2; - d2 << tr("MD5-Sum") << md5sum; - FileInfoItem *fi2 = new FileInfoItem(d2, this); - mChildren.append(fi2); - QString mt = Helper::mimeType(mFullFilename); - QList<QVariant> d3; - d3 << tr("MIME-Type") << mt; - FileInfoItem *fi3 = new FileInfoItem(d3, this); - mChildren.append(fi3); -} - -void FileInfoItem::populateFromIndex() { - const MovieModel *movieModel = static_cast<const MovieModel*>(mIndex.model()); - Q_ASSERT(movieModel); - QLocale l; - QModelIndex idx = movieModel->index(mIndex.row(), MovieItem::Title, QModelIndex()); - QList<QVariant> data1; - data1 << tr("Filename") << idx.data(MovieModel::FilenameRole); - FileInfoItem *fi1 = new FileInfoItem(data1, this); - mChildren.append(fi1); - QList<QVariant> data2; - data2 << tr("MD5-Sum") << idx.data(MovieModel::Md5Role); - FileInfoItem *fi2 = new FileInfoItem(data2, this); - mChildren.append(fi2); - QList<QVariant> data3; - data3 << tr("Size") << l.toString(idx.data(MovieModel::SizeRole).toLongLong()); - FileInfoItem *fi3 = new FileInfoItem(data3, this); - mChildren.append(fi3); - QList<QVariant> data4; - data4 << tr("Genre") << idx.data(MovieModel::GenreRole); - FileInfoItem *fi4 = new FileInfoItem(data4, this); - mChildren.append(fi4); - QList<QVariant> data5; - data5 << tr("Quality") << idx.data(MovieModel::QualityRole); - FileInfoItem *fi5 = new FileInfoItem(data5, this); - mChildren.append(fi5); - QList<QVariant> data6; - data6 << tr("DVD"); - int dvd = idx.data(MovieModel::DvdRole).toInt(); - if(dvd != -1){ - QString nr = QString("#%1").arg(dvd); - data6 << nr; - }else{ - data6 << tr("(local)"); - } - FileInfoItem *fi6 = new FileInfoItem(data6, this); - mChildren.append(fi6); -} - -void FileInfoItem::appendChild(FileInfoItem *item) { - mChildren.append(item); -} - -void FileInfoItem::removeChild(int row) { - if(row >= mChildren.count()){ - return; - } - FileInfoItem *item = mChildren.takeAt(row); - delete item; -} - diff --git a/fileinfoitem.h b/fileinfoitem.h deleted file mode 100644 index 067fd06..0000000 --- a/fileinfoitem.h +++ /dev/null @@ -1,41 +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. -*/ - -#ifndef FILEINFOITEM_H -#define FILEINFOITEM_H - -#include <QObject> -#include <QModelIndex> - -class FileInfoItem : public QObject { - Q_OBJECT - public: - FileInfoItem(const QString &fn, FileInfoItem *parent = 0, QObject *oParent = 0); - FileInfoItem(const QList<QVariant> &data, FileInfoItem *parent, QObject *oParent = 0); - FileInfoItem(const QString &title, const QModelIndex &index, FileInfoItem *parent, QObject *oParent = 0); - virtual ~FileInfoItem(); - FileInfoItem *child(int row); - int childCount() const; - int row() const; - int columnCount() const; - QVariant data(int column) const; - FileInfoItem *parent(); - void populate(); - void populateFromIndex(); - void appendChild(FileInfoItem *item); - void removeChild(int row); - - private: - FileInfoItem *mParent; - QList<QVariant> mData; - QString mFullFilename; - QModelIndex mIndex; - QList<FileInfoItem*> mChildren; -}; - -#endif - diff --git a/fileinfomodel.cpp b/fileinfomodel.cpp deleted file mode 100644 index 681f1a1..0000000 --- a/fileinfomodel.cpp +++ /dev/null @@ -1,185 +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 <QIcon> -#include <QColor> -#include <QPalette> -#include <QApplication> - -#include "fileinfomodel.h" -#include "fileinfoitem.h" - -FileInfoModel::FileInfoModel(QObject *parent) : QAbstractItemModel(parent) { - QList<QVariant> rootData; - rootData << QVariant() << QVariant(); - mRootItem = new FileInfoItem(rootData, 0); -} - -FileInfoModel::~FileInfoModel() { - delete mRootItem; -} - -QModelIndex FileInfoModel::index(int row, int column, const QModelIndex &parent) const{ - if(!hasIndex(row, column, parent)){ - return QModelIndex(); - } - FileInfoItem *parentItem; - if(!parent.isValid()){ - parentItem = mRootItem; - }else{ - parentItem = static_cast<FileInfoItem*>(parent.internalPointer()); - } - FileInfoItem *childItem = parentItem->child(row); - if(childItem){ - return createIndex(row, column, childItem); - } - return QModelIndex(); -} - -QModelIndex FileInfoModel::parent(const QModelIndex &index) const { - if(!index.isValid()){ - return QModelIndex(); - } - FileInfoItem *childItem = static_cast<FileInfoItem*>(index.internalPointer()); - Q_ASSERT(childItem); - if(!childItem){ - return QModelIndex(); - } - FileInfoItem *parentItem = childItem->parent(); - if(parentItem == mRootItem){ - return QModelIndex(); - } - if(parentItem->row() == -1){ - return QModelIndex(); - } - return createIndex(parentItem->row(), 0, parentItem); -} - -int FileInfoModel::rowCount(const QModelIndex &parent) const { - FileInfoItem *parentItem; - if(parent.column() > 0){ - return 0; - } - if(!parent.isValid()){ - parentItem = mRootItem; - }else{ - parentItem = static_cast<FileInfoItem*>(parent.internalPointer()); - } - return parentItem->childCount(); -} - -int FileInfoModel::columnCount(const QModelIndex &parent) const { - if(!parent.isValid()){ - return mRootItem->columnCount(); - } - FileInfoItem *item = static_cast<FileInfoItem*>(parent.internalPointer()); - return item->columnCount(); -} - -QVariant FileInfoModel::data(const QModelIndex &index, int role) const { - if(!index.isValid()){ - return QVariant(); - } - FileInfoItem *item = static_cast<FileInfoItem*>(index.internalPointer()); - switch(role) { - case Qt::DisplayRole: - return item->data(index.column()); - break; - case Qt::DecorationRole: { - if((item->parent() == mRootItem) && (index.column() == 0)){ - return QIcon(":/dildo.png"); - } - break; - } - case Qt::ForegroundRole: - if((item->parent() == mRootItem) && (index.column() == 0)){ - qApp->palette().color(QPalette::WindowText); - } - return Qt::blue; - break; - } - return QVariant(); -} - -Qt::ItemFlags FileInfoModel::flags(const QModelIndex &) const { - return Qt::ItemIsSelectable | Qt::ItemIsEnabled; -} - -QVariant FileInfoModel::headerData(int, Qt::Orientation, int) const { - return QVariant(); -} - -void FileInfoModel::addFiles(const QStringList &files){ - mCurrentIndex = QModelIndex(); - mTitle = QString(); - mMode = File; - mCurrentFiles = files; - insertRows(0, files.count(), createIndex(0, 0, mRootItem)); -} - -void FileInfoModel::addIndex(const QString &title, const QModelIndex &idx){ - mCurrentFiles.clear(); - mMode = Index; - mCurrentIndex = idx; - mTitle = title; - insertRows(0, 1, createIndex(0, 0, mRootItem)); -} - -bool FileInfoModel::insertRows(int row, int count, const QModelIndex &parent){ - if(mMode == File){ - if(count != mCurrentFiles.count()){ - return false; - } - }else{ - if((count != 1) || !mCurrentIndex.isValid()){ - return false; - } - } - beginInsertRows(parent, row, row + count - 1); - int i(0), j(0); - FileInfoItem *p = static_cast<FileInfoItem*>(parent.internalPointer()); - if(!p){ - p = mRootItem; - } - for(i = row, j = 0; i < (row + count); ++i, ++j){ - FileInfoItem *item = 0; - if(mMode == File){ - item = new FileInfoItem(mCurrentFiles.at(j), p); - item->populate(); - }else{ - item = new FileInfoItem(mTitle, mCurrentIndex, p); - item->populateFromIndex(); - } - p->appendChild(item); - } - endInsertRows(); - emit layoutChanged(); - mCurrentFiles.clear(); - return true; -} - -bool FileInfoModel::removeRows(int row, int count, const QModelIndex &parent){ - FileInfoItem *item = static_cast<FileInfoItem*>(parent.internalPointer()); - if(!item){ - item = mRootItem; - } - if(((row + count - 1) >= item->childCount()) || (count == 0)) { - return false; - } - beginRemoveRows(parent, row, row + (count - 1)); - for(int i = row + count; i > row; --i){ - item->removeChild(i - 1); - } - endRemoveRows(); - emit layoutChanged(); - return true; -} - -void FileInfoModel::clear(){ - removeRows(0, mRootItem->childCount(), QModelIndex()); -} - diff --git a/fileinfomodel.h b/fileinfomodel.h deleted file mode 100644 index 326a88e..0000000 --- a/fileinfomodel.h +++ /dev/null @@ -1,47 +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. -*/ - -#ifndef FILEINFOMODEL_H -#define FILEINFOMODEL_H - -#include <QAbstractItemModel> -#include <QStringList> - -class FileInfoItem; - -class FileInfoModel : public QAbstractItemModel { - Q_OBJECT - public: - enum Mode { File, Index }; - FileInfoModel(QObject *parent = 0); - virtual ~FileInfoModel(); - QModelIndex index(int row, int column, const QModelIndex &parent) const; - QModelIndex parent(const QModelIndex &index) const; - int rowCount(const QModelIndex &parent) const; - int columnCount(const QModelIndex &parent) const; - QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; - Qt::ItemFlags flags(const QModelIndex &index) const; - QVariant headerData(int section, Qt::Orientation o, int role) const; - void addFiles(const QStringList &files); - void addIndex(const QString &title, const QModelIndex &idx); - void clear(); - - protected: - bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex()); - bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()); - - private: - FileInfoItem *mRootItem; - QStringList mCurrentFiles; - QModelIndex mCurrentIndex; - QString mTitle; - Mode mMode; - -}; - -#endif - diff --git a/filesystemwidget.cpp b/filesystemwidget.cpp index c420719..4959a66 100644 --- a/filesystemwidget.cpp +++ b/filesystemwidget.cpp @@ -29,7 +29,6 @@ #include "filesystemfileproxy.h" #include "helper.h" #include "messagedialog.h" -#include "archiveeditdialog.h" #include "pictureviewer.h" FilesystemWidget::FilesystemWidget(QWidget *parent) : QWidget(parent) { @@ -107,10 +106,6 @@ FilesystemWidget::FilesystemWidget(QWidget *parent) : QWidget(parent) { setLayout(mainLayout); } -void FilesystemWidget::setArchiveDialog(ArchiveEditDialog *dlg){ - mAEDialog = dlg; -} - void FilesystemWidget::directoryChanged(const QModelIndex &selected, const QModelIndex & /* deselected */){ QModelIndex real = mDirProxy->mapToSource(selected); if(!real.isValid()){ @@ -323,23 +318,6 @@ void FilesystemWidget::setTemplate(){ emit newTemplate(mTemplate); } -void FilesystemWidget::archiveFiles(){ - QModelIndexList selected = fileView()->selectionModel()->selectedRows(); - if(selected.isEmpty()){ - return; - } - QSortFilterProxyModel *proxy = static_cast<QSortFilterProxyModel*>(fileView()->model()); - QStringList files; - foreach(QModelIndex idx, selected){ - QModelIndex src = proxy->mapToSource(idx); - files << mModel->filePath(src); - } - mAEDialog->setFiles(files); - mAEDialog->show(); - mAEDialog->raise(); - mAEDialog->activateWindow(); -} - void FilesystemWidget::playSelected(const QString &player){ QStringList files = selectedFiles(); if(files.isEmpty()){ diff --git a/filesystemwidget.h b/filesystemwidget.h index 0f70bea..09563f4 100644 --- a/filesystemwidget.h +++ b/filesystemwidget.h @@ -22,7 +22,6 @@ class QFileInfo; class QAction; class QVariant; class MessageDialog; -class ArchiveEditDialog; class PictureViewer; class FilesystemWidget : public QWidget { @@ -34,7 +33,6 @@ class FilesystemWidget : public QWidget { FilesystemFileProxy *fileProxy() { return mFileProxy; }; QFileSystemModel *dirModel() { return mModel; }; const QString windowTitle() const { return mWindowTitle; }; - void setArchiveDialog(ArchiveEditDialog *dlg); PictureViewer *pictureViewer() { return mPicViewer; }; signals: @@ -53,7 +51,6 @@ class FilesystemWidget : public QWidget { void renameFile(); void renameCover(const QString &infix); void setTemplate(); - void archiveFiles(); void playSelected(const QString &player = QString()); void readSettings(); void writeSettings(); @@ -79,7 +76,6 @@ class FilesystemWidget : public QWidget { QString mWindowTitle; MessageDialog *mRenameDialog; QString mTemplate; - ArchiveEditDialog *mAEDialog; qint64 mSize; QAction *mRefreshAction; PictureViewer *mPicViewer; diff --git a/listeditor.cpp b/listeditor.cpp deleted file mode 100644 index 244b11c..0000000 --- a/listeditor.cpp +++ /dev/null @@ -1,82 +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 <QComboBox> -#include <QLineEdit> -#include <QPushButton> -#include <QHBoxLayout> -#include <QVBoxLayout> -#include <QCompleter> -#include <QLabel> - -#include "listeditor.h" -#include "listmodel.h" - -ListEditor::ListEditor(ListModel *model, QWidget *parent) : QWidget(parent), mModel(model){ - QString caption = QString(tr("Edit %1s")).arg(model->table()); - QLabel *l1 = new QLabel(caption); - - mItems = new QComboBox; - mItems->setModel(mModel); - - mEdit = new QLineEdit; - QCompleter *completer = new QCompleter(this); - completer->setModel(mModel); - completer->setCompletionRole(Qt::DisplayRole); - mEdit->setCompleter(completer); - - mAdd = new QPushButton(tr("Add")); - connect(mAdd, SIGNAL(clicked()), this, SLOT(addItem())); - mRemove = new QPushButton(tr("Remove")); - connect(mRemove, SIGNAL(clicked()), this, SLOT(removeItem())); - mRename = new QPushButton(tr("Rename")); - connect(mRename, SIGNAL(clicked()), this, SLOT(renameItem())); - - QHBoxLayout *buttonLayout = new QHBoxLayout; - buttonLayout->addWidget(mAdd); - buttonLayout->addWidget(mRemove); - - QVBoxLayout *mainLayout = new QVBoxLayout; - mainLayout->addWidget(l1); - mainLayout->addWidget(mItems); - mainLayout->addWidget(mEdit); - mainLayout->addLayout(buttonLayout); - mainLayout->setContentsMargins(0, 0, 0, 0); - - setLayout(mainLayout); -} - -void ListEditor::addItem(){ - if(mEdit->text().isEmpty()){ - return; - } - QString newItem = mEdit->text().toLower().trimmed(); - QModelIndex idx = mModel->index(newItem); - if(idx == QModelIndex()){ - mModel->addItem(newItem); - emit itemAdded(newItem); - }else{ - emit itemAdded(idx.data().toString()); - } -} - -void ListEditor::removeItem(){ - mModel->removeItem(mItems->currentText()); -} - -void ListEditor::renameItem(){ - QString oldName = mItems->currentText(); - QString newName = mEdit->text(); - if(!newName.isEmpty()){ - mModel->renameItem(oldName, newName); - } -} - -void ListEditor::itemChanged(const QString &name){ - mEdit->setText(name); -} - diff --git a/listeditor.h b/listeditor.h deleted file mode 100644 index 634fb15..0000000 --- a/listeditor.h +++ /dev/null @@ -1,43 +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. -*/ - -#ifndef LISTEDITOR_H -#define LISTEDITOR_H - -#include <QWidget> - -class ListModel; -class QComboBox; -class QLineEdit; -class QPushButton; - -class ListEditor : public QWidget { - Q_OBJECT - public: - ListEditor(ListModel *model, QWidget *parent = 0); - ListEditor() {}; - - signals: - void itemAdded(const QString &); - - private slots: - void addItem(); - void removeItem(); - void renameItem(); - void itemChanged(const QString &name); - - private: - ListModel *mModel; - QComboBox *mItems; - QPushButton *mAdd; - QPushButton *mRemove; - QPushButton *mRename; - QLineEdit *mEdit; -}; - -#endif - diff --git a/listmodel.cpp b/listmodel.cpp deleted file mode 100644 index 2f32f1c..0000000 --- a/listmodel.cpp +++ /dev/null @@ -1,206 +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 <QString> -#include <QSqlQuery> - -#include <QSqlError> - -#include "listmodel.h" -#include "listitem.h" - -ListModel::ListModel(const QString table, QObject *parent) : QAbstractItemModel(parent), mTable(table){ - QString updateQuery = QString("UPDATE %1 SET t%1name = :name WHERE i%1id = :id").arg(mTable); - mUpdateQuery = new QSqlQuery; - mUpdateQuery->prepare(updateQuery); - QString insertQuery = QString("INSERT INTO %1 (t%1name) VALUES(:name)").arg(mTable); - mInsertQuery = new QSqlQuery; - mInsertQuery->prepare(insertQuery); - QString deleteQuery = QString("DELETE FROM %1 WHERE t%1name = :name").arg(mTable); - mDeleteQuery = new QSqlQuery; - mDeleteQuery->prepare(deleteQuery); - QString idQuery = QString("SELECT i%1id FROM %1 WHERE t%1name = :name").arg(mTable); - mIdQuery = new QSqlQuery; - mIdQuery->prepare(idQuery); - populate(); -} - -ListModel::~ListModel(){ - qDeleteAll(mItems); -} - -QModelIndex ListModel::index(int row, int column, const QModelIndex &) const{ - if((column != 0) || (row >= mItems.size()) || (row < 0)){ - return QModelIndex(); - } - return createIndex(row, 0, mItems.at(row)); -} - -QModelIndex ListModel::index(const QVariant &data) const{ - for(int i = 0; i < rowCount(); ++i){ - ListItem *item = mItems.at(i); - if(data.toString() == item->name()){ - return createIndex(i, 0, item); - } - } - return QModelIndex(); -} - -int ListModel::rowCount(const QModelIndex &) const{ - return mItems.size(); -} - -QVariant ListModel::data(const QModelIndex &index, int role) const{ - if(!index.isValid()){ - return QVariant(); - } - if(index.column() > 0){ - return QVariant(); - } - if(index.row() > mItems.size()){ - return QVariant(); - } - ListItem *item = static_cast<ListItem*>(index.internalPointer()); - Q_ASSERT(item != 0); - switch (role){ - case Qt::DisplayRole: - return item->name(); - break; - case IdRole: - return item->id(); - } - return QVariant(); -} - -bool ListModel::insertRows(int row, int count, const QModelIndex &){ - beginInsertRows(QModelIndex(), row, row + count - 1); - for(int i = row; i < (row + count); ++i){ - ListItem *newItem = new ListItem(QString(), -1); - mItems.insert(i, newItem); - } - endInsertRows(); - return true; -} - -bool ListModel::removeRows(int row, int count, const QModelIndex&){ - if(row > mItems.size()){ - return false; - } - if((row + count) > rowCount()){ - return false; - } - beginRemoveRows(QModelIndex(), row, row + (count - 1)); - for(int i = row; i < (row + count); ++i){ - ListItem *delItem = mItems.at(i); - delete delItem; - mItems.removeAt(i); - } - endRemoveRows(); - return true; -} - -bool ListModel::setData(const QModelIndex &idx, const QVariant &data, int role){ - if((!idx.isValid()) || (role != Qt::EditRole) || (idx.column() != 0)){ - return false; - } - ListItem *item = static_cast<ListItem*>(idx.internalPointer()); - Q_ASSERT(item != 0); - int id = item->id(); - bool success = false; - if(id > -1){ - //this is an update - mUpdateQuery->bindValue(":id", id); - success = mUpdateQuery->exec(); - }else{ - //this is an insert - mInsertQuery->bindValue(":name", data); - success = mInsertQuery->exec(); - if(success){ - mIdQuery->bindValue(":name", data); - success = mIdQuery->exec(); - int count = 0; - while(mIdQuery->next()){ - id = mIdQuery->value(0).toInt(); - ++count; - } - Q_ASSERT(count == 1); - item->setName(data.toString()); - item->setId(id); - } - } - if(success){ - qSort(mItems.begin(), mItems.end(), sortListItems); - dataChanged(index(0, 0), index((mItems.size() - 1), 0)); - } - return success; -} - -bool ListModel::addItem(const QVariant &item){ - bool success = false; - if(insertRows(0, 1, QModelIndex())){ - QModelIndex idx = index(0, 0); - if(idx.isValid()){ - success = setData(idx, item, Qt::EditRole); - } - } - return success; -} - -bool ListModel::removeItem(const QVariant &item){ - QString text = item.toString(); - int rowToDelete = -1; - for(int row = 0; row < rowCount(); ++row){ - QString data = index(row, 0).data().toString(); - if(data == text){ - rowToDelete = row; - break; - } - } - if(rowToDelete == -1){ - return false; - } - mDeleteQuery->bindValue(":name", item.toString()); - bool success = mDeleteQuery->exec(); - if(success){ - success = removeRows(rowToDelete, 1, QModelIndex()); - } - return success; -} - -bool ListModel::renameItem(const QVariant &oldName, const QVariant &newName){ - QModelIndex idx = QModelIndex(); - bool success = false; - for(int i = 0; i < rowCount(); ++i){ - idx = index(i, 0); - if(idx.data().toString() == oldName.toString()){ - success = setData(idx, newName); - } - } - return success; -} - -int ListModel::defaultId(){ - if(!mItems.isEmpty()){ - return mItems.at(0)->id(); - } - addItem("(default)"); - return mItems.at(0)->id(); -} - -void ListModel::populate(){ - QString query = QString("SELECT i%1id, t%1name FROM %1 ORDER BY t%1name").arg(mTable); - QSqlQuery q(query); - while(q.next()){ - ListItem *newItem = new ListItem(q.value(1).toString(), q.value(0).toInt()); - mItems << newItem; - } -} - -bool sortListItems(const ListItem *lhs, const ListItem *rhs){ - return lhs->name().toLower() < rhs->name().toLower(); -} diff --git a/listmodel.h b/listmodel.h deleted file mode 100644 index fb3612d..0000000 --- a/listmodel.h +++ /dev/null @@ -1,54 +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. -*/ - -#ifndef LISTMODEL_H -#define LISTMODEL_H - -#include <QAbstractItemModel> -#include <QList> - -class QString; -class ListItem; -class QModelIndex; -class QSqlQuery; - -class ListModel : public QAbstractItemModel { - Q_OBJECT - Q_ENUMS(CustomRoles) - public: - enum CustomRoles {IdRole = Qt::UserRole + 1}; - ListModel(const QString table, QObject *parent); - ~ListModel(); - QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const; - QModelIndex index(const QVariant &data) const; - QModelIndex parent(const QModelIndex &) const { return QModelIndex(); }; - const QString table() const { return mTable; }; - int rowCount(const QModelIndex &parent = QModelIndex()) const; - int columnCount(const QModelIndex &) const { return 1; }; - QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; - bool insertRows(int row, int count, const QModelIndex &parent); - bool removeRows(int row, int count, const QModelIndex &parent); - bool setData(const QModelIndex &idx, const QVariant &data, int role = Qt::EditRole); - bool addItem(const QVariant &item); - bool removeItem(const QVariant &item); - bool renameItem(const QVariant &oldName, const QVariant &newName); - int defaultId(); - - private: - void populate(); - QString mTable; - QList<ListItem*> mItems; - QSqlQuery *mUpdateQuery; - QSqlQuery *mInsertQuery; - QSqlQuery *mDeleteQuery; - QSqlQuery *mIdQuery; -}; - -bool sortListItems(const ListItem *lhs, const ListItem *rhs); - -#endif - diff --git a/listmodelsingleton.cpp b/listmodelsingleton.cpp deleted file mode 100644 index 69d028d..0000000 --- a/listmodelsingleton.cpp +++ /dev/null @@ -1,27 +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 "listmodelsingleton.h" - -ListModelSingleton *ListModelSingleton::mInstance = 0; - -ListModelSingleton::ListModelSingleton() {} - -ListModelSingleton *ListModelSingleton::instance(){ - if(mInstance == 0){ - mInstance = new ListModelSingleton(); - } - return mInstance; -} - -ListModel* ListModelSingleton::model(const QString &which){ - if(!mModels.contains(which)){ - ListModel *newModel = new ListModel(which, 0); - mModels.insert(which, newModel); - } - return mModels.value(which); -} diff --git a/listmodelsingleton.h b/listmodelsingleton.h deleted file mode 100644 index f67bf46..0000000 --- a/listmodelsingleton.h +++ /dev/null @@ -1,28 +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. -*/ - -#ifndef LISTMODELSINGLETON_H -#define LISTMODELSINGLETON_H - -#include <QHash> - -#include "listmodel.h" - -class ListModelSingleton { - public: - static ListModelSingleton *instance(); - ListModel *model(const QString &which); - - private: - ListModelSingleton(); - ListModelSingleton(const ListModelSingleton &other); - ListModelSingleton & operator=(const ListModelSingleton &other); - QHash<QString, ListModel*> mModels; - static ListModelSingleton *mInstance; -}; - -#endif // LISTMODELSINGLETON_H diff --git a/movieitem.cpp b/movieitem.cpp deleted file mode 100644 index d4760f9..0000000 --- a/movieitem.cpp +++ /dev/null @@ -1,132 +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 <QSqlQuery> - -#include "movieitem.h" -#include "coveritem.h" -#include "helper.h" - -MovieItem::MovieItem(int id, QObject *parent) : QObject(parent), mNumRows(9), mId(id), mGenreId(-1) { - for(int i = 0; i < mNumRows; ++i){ - mRows << QVariant(); - } - if(mId != -1){ - populate(); - setGenreName(); - setActors(); - setCovers(); - } -} - -void MovieItem::setId(int id){ - mId = id; - populate(); - setGenreName(); - setActors(); - setCovers(); -} - -bool MovieItem::setData(const QList<QVariant> &data){ - if(!data.size() == mNumRows){ - return false; - } - mRows = data; - return true; -} - -void MovieItem::setDataAt(int column, const QVariant &data){ - mRows[column] = data; - if(column == Genre){ - setGenreName(); - } -} - -const QList<QVariant> MovieItem::data() const { - return mRows; -} - -const QVariant MovieItem::dataAt(int column) const { - if(column >= NumRows){ - return QVariant(); - } - return mRows[column]; -} - -void MovieItem::populate(){ - QSqlQuery movieData; - movieData.prepare("SELECT ttitle, tfilename, cmd5sum, bisize, igenreid, iquality, idvd, iseriesno, ipartno FROM movies WHERE imovid = :id"); - movieData.bindValue(":id", mId); - movieData.exec(); - if(movieData.next()){ - for(int i = 0; i < mNumRows; ++i){ - mRows[i] = movieData.value(i); - } - } -} - -void MovieItem::setGenreName(){ - qint32 genreId = dataAt(Genre).toInt(); - QSqlQuery genreQuery; - genreQuery.prepare("SELECT tgenrename FROM genre WHERE igenreid = :id"); - genreQuery.bindValue(":id", genreId); - genreQuery.exec(); - while(genreQuery.next()){ - setDataAt(Genre, genreQuery.value(0)); - } -} - -void MovieItem::setActors(){ - mActors.clear(); - mActorIdMap.clear(); - QSqlQuery actorQuery; - actorQuery.prepare("SELECT actor.iactorid, actor.tactorname FROM actor, movieactormap WHERE movieactormap.iactorid = actor.iactorid AND movieactormap.imovid = :id"); - actorQuery.bindValue(":id", mId); - actorQuery.exec(); - while(actorQuery.next()){ - QVariant actorId = actorQuery.value(0); - QString actorName = actorQuery.value(1).toString(); - mActors << actorName; - mActorIdMap.insert(actorName, actorId); - } -} - -void MovieItem::setCovers(){ - mCovers.clear(); - QSqlQuery coverQuery; - coverQuery.prepare("SELECT tfilename, tcovertype, cmd5sum FROM covers WHERE imovid = :id"); - coverQuery.bindValue(":id", mId); - coverQuery.exec(); - while(coverQuery.next()){ - QString filename = coverQuery.value(0).toString(); - QString md5 = coverQuery.value(2).toString(); - QString coverType = coverQuery.value(1).toString(); - QString fullPath = Helper::createArchivePath(filename, md5); - CoverItem item(fullPath, coverType, md5); - QVariant i; - i.setValue(item); - mCovers << i; - } -} - -void MovieItem::setSize(){ - qint64 size = dataAt(Size).toInt(); - QString sizeString(tr("%1 %2iB")); - if(size > 1024){ - double value = size / 1024.0; - setDataAt(Size, sizeString.arg(QString::number(value, 'f', 2), "K")); - } - if(size > (1024 * 1024)){ - double value = size / (1024.0 * 1024.0); - setDataAt(Size, sizeString.arg(QString::number(value, 'f', 2), "M")); - } - if(size > (1024 * 1024 * 1024)){ - double value = size / (1024.0 * 1024.0 * 1024.0); - setDataAt(Size, sizeString.arg(QString::number(value, 'f', 2), "G")); - } -} - diff --git a/movieitem.h b/movieitem.h deleted file mode 100644 index a20cf52..0000000 --- a/movieitem.h +++ /dev/null @@ -1,55 +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. -*/ - -#ifndef MOVIEITEM_H -#define MOVIEITEM_H - -#include <QObject> -#include <QList> -#include <QVariant> -#include <QHash> - -#include "coveritem.h" - -class QSqlQuery; - -class MovieItem : public QObject { - Q_OBJECT - Q_ENUMS(Columns) - public: - enum Columns { Title = 0, Filename = 1, Md5Sum = 2, Size = 3, Genre = 4, Quality = 5, Dvd = 6, SeriesNo = 7, PartNo = 8 }; - enum { NumRows = 9 }; - MovieItem(int id = -1, QObject *parent = 0); - ~MovieItem() {}; - int id() const { return mId; }; - void setId(int id); - int genreId() const { return mGenreId; }; - bool setData(const QList<QVariant> &data); - void setDataAt(int column, const QVariant &data); - const QList<QVariant> data() const; - const QVariant dataAt(int column) const; - const QList<QVariant> actors() const { return mActors; }; - const QHash<QString, QVariant> actorMap() const { return mActorIdMap; }; - const QList<QVariant> covers() const { return mCovers; }; - void populate(); - void setActors(); - void setCovers(); - - private: - void setGenreName(); - void setSize(); - const int mNumRows; - int mId; - int mGenreId; - QList<QVariant> mRows; - QList<QVariant> mActors; - QHash<QString, QVariant> mActorIdMap; - QList<QVariant> mCovers; -}; - -#endif - diff --git a/moviemodel.cpp b/moviemodel.cpp deleted file mode 100644 index c77172d..0000000 --- a/moviemodel.cpp +++ /dev/null @@ -1,397 +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 <QSqlQuery> -#include <QStringList> -#include <QIcon> -#include <QSettings> - -#include "moviemodel.h" -#include "coveritem.h" - -MovieModel::MovieModel(QObject *parent) : QAbstractItemModel(parent) { - mHeaders << tr("Title") << tr("Filename") << tr("MD5Sum") << tr("Size") << tr("Genre") << tr("Quality") << tr("Archived"); - mInsertQuery = new QSqlQuery; - mInsertQuery->prepare("SELECT insert_movie(:title, :filename, :md5, :filesize, :genre, :quality, :dvd, :seriesno, :partno)"); - mDeleteQuery = new QSqlQuery; - mDeleteQuery->prepare("DELETE FROM movies WHERE imovid = :id"); - mDeleteActorsForMovie = new QSqlQuery; - mDeleteActorsForMovie->prepare("DELETE FROM movieactormap WHERE imovid = :id"); - mInsertActorsForMovie = new QSqlQuery; - mInsertActorsForMovie->prepare("INSERT INTO movieactormap VALUES(:movid, :actorid)"); - mDeleteCovers = new QSqlQuery; - mDeleteCovers->prepare("DELETE FROM covers WHERE imovid = :id"); - mInsertCovers = new QSqlQuery; - mInsertCovers->prepare("INSERT INTO covers VALUES(:filename, :movid, :covertype, :md5sum)"); - mOtherPartsQuery = new QSqlQuery; - mOtherPartsQuery->prepare("SELECT imovid FROM movies WHERE ttitle = :title AND iseriesno = :seriesno AND imovid != :id"); - QSqlQuery *c1 = new QSqlQuery; - c1->prepare("UPDATE movies SET ttitle = :value WHERE imovid = :id"); - mColumnQueries << c1; - QSqlQuery *c2 = new QSqlQuery; - c2->prepare("UPDATE movies SET tfilename = :value WHERE imovid = :id"); - mColumnQueries << c2; - QSqlQuery *c3 = new QSqlQuery; - c3->prepare("UPDATE movies SET cmd5sum = :value WHERE imovid = :id"); - mColumnQueries << c3; - QSqlQuery *c4 = new QSqlQuery; - c4->prepare("UPDATE movies SET bisize = :value WHERE imovid = :id"); - mColumnQueries << c4; - QSqlQuery *c5 = new QSqlQuery; - c5->prepare("UPDATE movies SET igenreid = :value WHERE imovid = :id"); - mColumnQueries << c5; - QSqlQuery *c6 = new QSqlQuery; - c6->prepare("UPDATE movies SET iquality = :value WHERE imovid = :id"); - mColumnQueries << c6; - QSqlQuery *c7 = new QSqlQuery; - c7->prepare("UPDATE movies SET idvd = :value WHERE imovid = :id"); - mColumnQueries << c7; - QSqlQuery *c8 = new QSqlQuery; - c8->prepare("UPDATE movies SET iseriesno = :value WHERE imovid = :id"); - mColumnQueries << c8; - QSqlQuery *c9 = new QSqlQuery; - c9->prepare("UPDATE movies set ipartno = :value WHERE imovid = :id"); - mColumnQueries << c9; - //populate(); -} - -MovieModel::~MovieModel(){ - qDeleteAll(mItems); - qDeleteAll(mColumnQueries); - delete mInsertQuery; - delete mDeleteQuery; - delete mDeleteActorsForMovie; - delete mInsertActorsForMovie; - delete mDeleteCovers; - delete mInsertCovers; - delete mOtherPartsQuery; -} - -QModelIndex MovieModel::index(int row, int column, const QModelIndex &parent) const{ - if((parent != QModelIndex()) || (!hasIndex(row, column, parent)) || (row > mItems.size())){ - return QModelIndex(); - } - MovieItem *internal = mItems.at(row); - return createIndex(row, column, internal); -} - -QModelIndex MovieModel::index(int movieId, int column) const{ - QModelIndex retval = QModelIndex(); - for(int i = 0; i < rowCount(QModelIndex()); ++i){ - MovieItem *item = mItems.at(i); - if(item->id() == movieId){ - retval = createIndex(i, column, item); - break; - } - } - return retval; -} - -QModelIndexList MovieModel::columnContains(const QVariant &content, int column) const{ - QModelIndexList retval; - if((column == MovieItem::Title) || (column == MovieItem::Filename) || (column == MovieItem::Md5Sum)){ - QString part = content.toString(); - for(int i = 0; i < mItems.size(); ++i){ - QString current = mItems.at(i)->dataAt(column).toString(); - if(current.contains(part)){ - retval << createIndex(i, column, mItems.at(i)); - } - } - }else{ - qint64 value = content.toLongLong(); - for(int i = 0; i < mItems.size(); ++i){ - qint64 current = mItems.at(i)->dataAt(column).toLongLong(); - if(value == current){ - retval << createIndex(i, column, mItems.at(i)); - } - } - } - return retval; -} - -QVariant MovieModel::data(const QModelIndex &index, int role) const{ - if(!index.isValid()){ - return QVariant(); - } - QSettings s; - MovieItem *item = static_cast<MovieItem*>(index.internalPointer()); - Q_ASSERT(item != 0); - if(role == Qt::DisplayRole){ - if(index.column() == 0){ - QString retval = item->dataAt(MovieItem::Title).toString(); - int seriesno = item->dataAt(MovieItem::SeriesNo).toInt(); - int partno = item->dataAt(MovieItem::PartNo).toInt(); - if(seriesno != -1){ - retval.append(QString(" %1").arg(QString::number(seriesno))); - } - if(partno != -1){ - retval.append(QString(" (part %1)").arg(QString::number(partno))); - } - return retval; - }else{ - return item->dataAt(index.column()); - } - } - if(role == ActorsRole){ - return item->actors(); - } - if(role == ActorsMap){ - return QVariant(item->actorMap()); - } - if(role == CoverRole){ - return item->covers(); - } - if(role == IdRole){ - return item->id(); - } - if(role == TitleBaseRole){ - return item->dataAt(MovieItem::Title); - } - if(role == SeriesNoRole){ - return item->dataAt(MovieItem::SeriesNo); - } - if(role == PartNoRole){ - return item->dataAt(MovieItem::PartNo); - } - if(role == FilenameRole){ - return item->dataAt(MovieItem::Filename); - } - if(role == Md5Role){ - return item->dataAt(MovieItem::Md5Sum); - } - if(role == SizeRole){ - return item->dataAt(MovieItem::Size); - } - if(role == GenreRole){ - return item->dataAt(MovieItem::Genre); - } - if(role == QualityRole){ - return item->dataAt(MovieItem::Quality); - } - if(role == DvdRole){ - return item->dataAt(MovieItem::Dvd); - } - if(role == FullPathRole){ - QString archivePath = s.value("paths/archivedir").toString(); - QString md5 = item->dataAt(MovieItem::Md5Sum).toString(); - QString fileName = item->dataAt(MovieItem::Filename).toString(); - QString retval = QString("%1/%2/%3/%4").arg(archivePath).arg(md5.at(0)).arg(md5.at(1)).arg(fileName); - return retval; - } - if(role == CoverPathRole){ - QList<QVariant> retval; - QList<QVariant> covers = item->covers(); - foreach(QVariant c, covers){ - CoverItem i = c.value<CoverItem>(); - retval << i.fullPath(); - } - return retval; - } - if(role == OtherPartsRole){ - QList<QVariant> retval; - mOtherPartsQuery->bindValue(":title", item->dataAt(MovieItem::Title)); - mOtherPartsQuery->bindValue(":seriesno", item->dataAt(MovieItem::SeriesNo)); - mOtherPartsQuery->bindValue(":id", item->id()); - mOtherPartsQuery->exec(); - while(mOtherPartsQuery->next()){ - retval << mOtherPartsQuery->value(0); - } - return retval; - } - if((role == Qt::DecorationRole) && (index.column() == 0)){ - return QIcon(":/dildo.png"); - } - return QVariant(); -} - -Qt::ItemFlags MovieModel::flags(const QModelIndex &index) const{ - if(!index.isValid()){ - return 0; - } - return Qt::ItemIsEnabled | Qt::ItemIsSelectable; -} - -QVariant MovieModel::headerData(int section, Qt::Orientation o, int role) const{ - if((o == Qt::Horizontal) && (role == Qt::DisplayRole)){ - if(section < mHeaders.size()){ - return mHeaders.at(section); - } - } - return QVariant(); -} - -bool MovieModel::insertRows(int row, int count, const QModelIndex &){ - if(row > rowCount(QModelIndex())){ - return false; - } - beginInsertRows(QModelIndex(), row, row); - for(int i = row; i < (row + count); ++i){ - MovieItem *newItem = new MovieItem(-1, 0); - mItems.insert(row, newItem); - } - endInsertRows(); - return true; -} - -bool MovieModel::removeRows(int row, int count, const QModelIndex &){ - if(row >= rowCount(QModelIndex())){ - return false; - } - beginRemoveRows(QModelIndex(), row, row + count - 1); - for(int i = row; i < (row + count); ++i){ - MovieItem *item = mItems.at(i); - delete item; - mItems.removeAt(i); - } - endRemoveRows(); - return true; -} - -bool MovieModel::setRow(const QModelIndex &idx, const QList<QVariant> &data, const QList<QVariant> &actors, const QList<CoverItem> &covers){ - if(!idx.isValid() || (data.size() > MovieItem::NumRows)){ - return false; - } - MovieItem *item = static_cast<MovieItem*>(idx.internalPointer()); - Q_ASSERT(item != 0); - if(item->id() != -1){ - qWarning("ID not as expected: item->id() == %d", item->id()); - return false; - } - for(int i = 0; i < MovieItem::NumRows; ++i){ - mInsertQuery->bindValue(i, data[i]); - } - mInsertQuery->exec(); - int id(0); - while(mInsertQuery->next()){ - id = mInsertQuery->value(0).toInt(); - } - if(id == -1){ - return false; - } - if(!actors.isEmpty()){ - setActors(id, actors); - } - if(!covers.isEmpty()){ - setCovers(id, covers); - } - item->setId(id); - QModelIndex start = index(idx.row(), 0, QModelIndex()); - QModelIndex end = index(idx.row(), MovieItem::NumRows - 1, QModelIndex()); - emit dataChanged(start, end); - return true; -} - -bool MovieModel::setDataAt(const QModelIndex &idx, const QVariant &data){ - if(!idx.isValid()){ - return false; - } - MovieItem *item = static_cast<MovieItem *>(idx.internalPointer()); - Q_ASSERT(item != 0); - int id = item->id(); - int column = idx.column(); - QSqlQuery *query = mColumnQueries.at(column); - query->bindValue(":value", data); - query->bindValue(":id", id); - if(!query->exec()){ - return false; - } - item->setDataAt(column, data); - emit dataChanged(idx, idx); - return true; -} - -void MovieModel::setActors(int id, const QList<QVariant> &actors){ - mDeleteActorsForMovie->bindValue(":id", id); - mDeleteActorsForMovie->exec(); - foreach(QVariant a, actors){ - mInsertActorsForMovie->bindValue(":movid", id); - mInsertActorsForMovie->bindValue(":actorid", a); - mInsertActorsForMovie->exec(); - } - foreach(MovieItem *m, mItems){ - if(m->id() == id){ - m->setActors(); - } - } -} - -void MovieModel::setCovers(int id, const QList<CoverItem> &covers){ - mDeleteCovers->bindValue(":id", id); - mDeleteCovers->exec(); - foreach(CoverItem c, covers){ - mInsertCovers->bindValue(":filename", c.fileName()); - mInsertCovers->bindValue(":movid", id); - mInsertCovers->bindValue(":covertype", c.type()); - mInsertCovers->bindValue(":md5", c.md5()); - mInsertCovers->exec(); - } - foreach(MovieItem *m, mItems){ - if(m->id() == id){ - m->setCovers(); - } - } -} - -void MovieModel::addMovie(const QList<QVariant> &data, const QList<QVariant> &actors, const QList<CoverItem> &covers){ - int row = rowCount(QModelIndex()); - insertRows(row, 1, QModelIndex()); - QModelIndex i = index(row, 0, QModelIndex()); - setRow(i, data, actors, covers); - emit moviesChanged(); -} - -void MovieModel::removeMovie(const QModelIndex &idx){ - if(!idx.isValid()){ - return; - } - MovieItem *item = static_cast<MovieItem*>(idx.internalPointer()); - Q_ASSERT(item != 0); - int id = item->id(); - mDeleteQuery->bindValue(":id", id); - if(!mDeleteQuery->exec()){ - return; - } - removeRows(idx.row(), 1, QModelIndex()); -} - -const QVariant MovieModel::maxValue(int column) const{ - if(mItems.isEmpty()){ - return QVariant(); - } - QVariant sample = mItems.at(0)->dataAt(column); - if(sample.canConvert(QVariant::LongLong)){ - qint64 retval(-1); - foreach(MovieItem* i, mItems){ - qint64 value = i->dataAt(column).toLongLong(); - if(value > retval){ - retval = value; - } - } - return retval; - } - if(sample.canConvert(QVariant::String)){ - QString retval; - foreach(MovieItem *i, mItems){ - QString value = i->dataAt(column).toString(); - if(value > retval){ - retval = value; - } - } - return retval; - } - return QVariant(); -} - -void MovieModel::populate(){ - QSqlQuery movieQuery("SELECT imovid FROM movies"); - while(movieQuery.next()){ - int id = movieQuery.value(0).toInt(); - MovieItem *item = new MovieItem(id); - mItems << item; - } -} - diff --git a/moviemodel.h b/moviemodel.h deleted file mode 100644 index d9950b4..0000000 --- a/moviemodel.h +++ /dev/null @@ -1,63 +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. -*/ - -#ifndef MOVIEMODEL_H -#define MOVIEMODEL_H - -#include <QAbstractItemModel> -#include <QVariant> - -class QSqlQuery; -class CoverItem; - -#include "movieitem.h" - -class MovieModel : public QAbstractItemModel { - Q_OBJECT - Q_ENUMS(CustomRoles) - public: - enum CustomRoles { Md5Role = Qt::UserRole + 1, ActorsRole = Qt::UserRole + 2, ActorsMap = Qt::UserRole + 3, CoverRole = Qt::UserRole + 4, IdRole = Qt::UserRole + 5, TitleBaseRole = Qt::UserRole + 6, SeriesNoRole = Qt::UserRole + 7, PartNoRole = Qt::UserRole + 8, FilenameRole = Qt::UserRole + 9, SizeRole = Qt::UserRole + 10, GenreRole = Qt::UserRole + 11, QualityRole = Qt::UserRole + 12, DvdRole = Qt::UserRole + 13, FullPathRole = Qt::UserRole + 14, CoverPathRole = Qt::UserRole + 15, OtherPartsRole = Qt::UserRole + 16 }; - MovieModel(QObject *parent = 0); - ~MovieModel(); - QModelIndex index(int row, int column, const QModelIndex &parent) const; - QModelIndex index(int movieId, int column = 0) const; - QModelIndexList columnContains(const QVariant &content, int column) const; - QModelIndex parent(const QModelIndex &) const { return QModelIndex(); }; - int columnCount(const QModelIndex &) const { return MovieItem::NumRows; }; - int rowCount(const QModelIndex &) const { return mItems.size(); }; - QVariant data(const QModelIndex &index, int role) const; - Qt::ItemFlags flags(const QModelIndex &index) const; - QVariant headerData(int section, Qt::Orientation o, int role) const; - bool insertRows(int row, int count, const QModelIndex &); - bool removeRows(int row, int count, const QModelIndex &); - bool setRow(const QModelIndex &idx, const QList<QVariant> &data, const QList<QVariant> &actors, const QList<CoverItem> &covers); - bool setDataAt(const QModelIndex &idx, const QVariant &data); - void setActors(int id, const QList<QVariant> &actors); - void setCovers(int id, const QList<CoverItem> &covers); - void addMovie(const QList<QVariant> &data, const QList<QVariant> &actors, const QList<CoverItem> &covers); - void removeMovie(const QModelIndex &idx); - const QVariant maxValue(int column) const; - - signals: - void moviesChanged(); - - private: - void populate(); - QList<MovieItem*> mItems; - QList<QVariant> mHeaders; - QList<QSqlQuery*> mColumnQueries; - QSqlQuery *mInsertQuery; - QSqlQuery *mDeleteQuery; - QSqlQuery *mDeleteActorsForMovie; - QSqlQuery *mInsertActorsForMovie; - QSqlQuery *mDeleteCovers; - QSqlQuery *mInsertCovers; - QSqlQuery *mOtherPartsQuery; -}; - -#endif - diff --git a/moviemodelsingleton.cpp b/moviemodelsingleton.cpp deleted file mode 100644 index 4300de1..0000000 --- a/moviemodelsingleton.cpp +++ /dev/null @@ -1,20 +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 "moviemodelsingleton.h" -#include "moviemodel.h" - -MovieModel *MovieModelSingleton::mInstance = 0; - -MovieModelSingleton::MovieModelSingleton() {} - -MovieModel *MovieModelSingleton::instance() { - if(!mInstance){ - mInstance = new MovieModel; - } - return mInstance; -} diff --git a/moviemodelsingleton.h b/moviemodelsingleton.h deleted file mode 100644 index a19dc45..0000000 --- a/moviemodelsingleton.h +++ /dev/null @@ -1,24 +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. -*/ - -#ifndef MOVIEMODELSINGLETON_H -#define MOVIEMODELSINGLETON_H - -class MovieModel; - -class MovieModelSingleton { - public: - static MovieModel *instance(); - - private: - MovieModelSingleton(); - MovieModelSingleton(const MovieModelSingleton &other); - MovieModelSingleton & operator=(const MovieModelSingleton &other); - static MovieModel *mInstance; -}; - -#endif @@ -18,7 +18,6 @@ #include <QSettings> #include <QMessageBox> #include <QSqlDatabase> -#include <QSqlError> #include <QImage> #include <QPainter> #include <QFont> @@ -34,15 +33,9 @@ #include "filesystemwidget.h" #include "fileview.h" #include "configurationdialog.h" -#include "archiveeditdialog.h" -#include "moviemodel.h" -#include "listmodel.h" -#include "archiveviewwidget.h" -#include "archiveitemeditdialog.h" +//#include "archiveeditdialog.h" #include "statisticsdialog.h" #include "filesystemfileproxy.h" -#include "moviemodelsingleton.h" -#include "listmodelsingleton.h" #include "pictureviewer.h" #include "archivetreeview.h" #include "smmodelsingleton.h" @@ -67,29 +60,18 @@ SheMov::SheMov(QWidget *parent, Qt::WindowFlags flags) : QMainWindow(parent, fla QMessageBox::critical(this, tr("Error"), tr("Could not open database. Please configure the database and restart the program")); } - mMovieModel = MovieModelSingleton::instance(); - mGenreModel = ListModelSingleton::instance()->model("genre"); - mActorModel = ListModelSingleton::instance()->model("actor"); - + //FileSystemWidget + TabWidget mFSWidget = new FilesystemWidget; setWindowTitle(mFSWidget->windowTitle()); - mTab = new QTabWidget; mTab->addTab(mFSWidget, tr("Filemanager")); - mAVWidget = new ArchiveViewWidget(mMovieModel, mGenreModel, mActorModel); - mTab->addTab(mAVWidget, tr("Archive")); - connect(mAVWidget, SIGNAL(windowTitle(const QString &)), this, SLOT(newWindowTitle(const QString &))); + + //ArchiveTreeView mATree = new ArchiveTreeView; mTab->addTab(mATree, "Tree"); connect(mATree->filesWidget(), SIGNAL(statusMessage(QString)), this, SLOT(statusbarMessage(QString))); connect(mATree->filesWidget(), SIGNAL(sizeChanged(qint64)), this, SLOT(setSize(qint64))); - mAEdit = new ArchiveEditDialog(this); - mFSWidget->setArchiveDialog(mAEdit); - - mAItemEdit = new ArchiveItemEditDialog(this); - mAVWidget->setEditDialog(mAItemEdit); - QVBoxLayout *mainLayout = new QVBoxLayout; mainLayout->addWidget(mTab); @@ -99,19 +81,15 @@ SheMov::SheMov(QWidget *parent, Qt::WindowFlags flags) : QMainWindow(parent, fla setFsFree(); connect(mFSWidget->fileView()->selectionModel(), SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)), this, SLOT(updateSelectionCount(const QItemSelection &, const QItemSelection &))); - connect(mAVWidget->fileView()->selectionModel(), SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)), this, SLOT(updateSelectionCount(const QItemSelection &, const QItemSelection &))); connect(mFSWidget, SIGNAL(windowTitle(const QString &)), this, SLOT(newWindowTitle(const QString &))); connect(mFSWidget->fileView(), SIGNAL(statusbarMessage(const QString &)), this, SLOT(statusbarMessage(const QString &))); connect(mFSWidget, SIGNAL(statusbarMessage(const QString &)), this, SLOT(statusbarMessage(const QString &))); connect(mFSWidget, SIGNAL(newTemplate(const QString &)), this, SLOT(setTemplate(const QString &))); - connect(mAVWidget, SIGNAL(statusbarMessage(const QString &)), this, SLOT(statusbarMessage(const QString &))); connect(mTab, SIGNAL(currentChanged(int)), this, SLOT(tabChanged(int))); connect(mFSWidget->dirModel(), SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(setFsFree())); connect(mFSWidget->dirModel(), SIGNAL(layoutChanged()), this, SLOT(setFsFree())); connect(mFSWidget->dirModel(), SIGNAL(rowsRemoved(QModelIndex,int,int)), this, SLOT(setFsFree())); - //NewMovieWizard = new NewMovieWizard(this); - QWidget *centralWidget = new QWidget; centralWidget->setLayout(mainLayout); setCentralWidget(centralWidget); @@ -148,17 +126,6 @@ void SheMov::updateSelectionCount(const QItemSelection & /* sel */, const QItemS mSelectedSize->setText(QString(tr("<span style=\"color:#000000\">%1</span>")).arg(l.toString((selSize)))); break; } - case 1: - mSelectedItems->setText(QString::number(mAVWidget->fileView()->selectionModel()->selectedRows().count())); - qint64 s = mAVWidget->currentSize(); - QString val; - if(s < Q_INT64_C(4707319808)){ - val = QString("<span style=\"color:#008000\">%1</span>").arg(l.toString(s)); - }else{ - val = QString("<span style=\"color:#ff0000\">%1</span>").arg(l.toString(s)); - } - mSelectedSize->setText(val); - break; } } @@ -183,13 +150,9 @@ void SheMov::configure(){ void SheMov::tabChanged(int newTab){ mEditFSMenuA->setVisible(newTab == 0); - mEditArchiveMenuA->setVisible(newTab == 1); if(newTab == 0){ setWindowTitle(mFSWidget->windowTitle()); } - if(newTab == 1){ - setWindowTitle(mAVWidget->windowTitle()); - } updateSelectionCount(QItemSelection(), QItemSelection()); } @@ -324,9 +287,6 @@ void SheMov::createActions(){ connect(mRenameA, SIGNAL(triggered()), mFSWidget, SLOT(renameFile())); mConfigA = new QAction(tr("Configure..."), this); connect(mConfigA, SIGNAL(triggered()), this, SLOT(configure())); - mArchiveA = new QAction(tr("Archive files..."), this); - mArchiveA->setShortcut(tr("CTRL+a")); - connect(mArchiveA, SIGNAL(triggered()), mFSWidget, SLOT(archiveFiles())); //Edit menu rename submenu mTemplateA = new QAction(tr("Set as template"), this); @@ -351,25 +311,6 @@ void SheMov::createActions(){ mRenameCoverCA->setData("RenameMenu"); connect(mRenameMapper, SIGNAL(mapped(const QString &)), mFSWidget, SLOT(renameCover(const QString &))); - //Edit menu (archive) - mPlaySelectedAVA = new QAction(tr("Play selected movies..."), this); - connect(mPlaySelectedAVA, SIGNAL(triggered()), mAVWidget, SLOT(playSelected())); - mEditArchiveFileA = new QAction(tr("Edit file..."), this); - mEditArchiveFileA->setShortcut(tr("CTRL+e")); - connect(mEditArchiveFileA, SIGNAL(triggered()), mAVWidget, SLOT(editFile())); - mCopyToPartsA = new QAction(tr("Copy data to other parts"), this); - connect(mCopyToPartsA, SIGNAL(triggered()), mAVWidget, SLOT(copyToParts())); - mAddMovieManuallyA = new QAction(tr("Add movie manually..."), this); - connect(mAddMovieManuallyA, SIGNAL(triggered()), mAVWidget, SLOT(addMovie())); - mPropertiesA = new QAction(tr("Properties..."), this); - connect(mPropertiesA, SIGNAL(triggered()), mAVWidget, SLOT(properties())); - mMoveBurnA = new QAction(tr("Move for burning..."), this); - connect(mMoveBurnA, SIGNAL(triggered()), mAVWidget, SLOT(moveBurn())); - mSetDvdA = new QAction(tr("Set DVD No. for selected..."), this); - connect(mSetDvdA, SIGNAL(triggered()), mAVWidget, SLOT(setDvdNo())); - mDeleteFromArchiveA = new QAction(tr("Delete from archive..."), this); - connect(mDeleteFromArchiveA, SIGNAL(triggered()), mAVWidget, SLOT(deleteFromArchive())); - //Help menu QString aboutLabel = QString(tr("About %1...")).arg(qApp->applicationName()); mAboutShemovA = new QAction(aboutLabel, this); @@ -435,12 +376,16 @@ void SheMov::createActions(){ } void SheMov::createMenus(){ + //file menu QMenu *fileMenu = new QMenu(tr("&File"), this); fileMenu->addAction(mPlaySelectedFSA); fileMenu->addSeparator(); fileMenu->addAction(mNewMovieWizardA); fileMenu->addSeparator(); fileMenu->addAction(mQuitA); + menuBar()->addMenu(fileMenu); + + //filesystem edit menu mEditFSMenu = new QMenu(tr("&Edit"), this); mEditFSMenu->addAction(mCdupA); mEditFSMenu->addSeparator(); @@ -453,7 +398,6 @@ void SheMov::createMenus(){ mEditFSMenu->addAction(mCopyA); mEditFSMenu->addAction(mMoveA); mEditFSMenu->addAction(mRenameA); - mEditFSMenu->addAction(mArchiveA); mRenameMenu = new QMenu(tr("&Rename..."), this); mRenameMenu->addAction(mTemplateA); mRenameMenu->addAction(mRenameCoverFA); @@ -464,22 +408,7 @@ void SheMov::createMenus(){ mEditFSMenu->addAction(mRenameMenuA); mEditFSMenu->addSeparator(); mEditFSMenu->addAction(mConfigA); - - mEditArchiveMenu = new QMenu(tr("&Edit archive"), this); - mEditArchiveMenu->addAction(mEditArchiveFileA); - mEditArchiveMenu->addAction(mCopyToPartsA); - mEditArchiveMenu->addSeparator(); - mEditArchiveMenu->addAction(mPropertiesA); - mEditArchiveMenu->addSeparator(); - mEditArchiveMenu->addAction(mMoveBurnA); - mEditArchiveMenu->addAction(mSetDvdA); - mEditArchiveMenu->addSeparator(); - mEditArchiveMenu->addAction(mDeleteFromArchiveA); - - menuBar()->addMenu(fileMenu); mEditFSMenuA = menuBar()->addMenu(mEditFSMenu); - mEditArchiveMenuA = menuBar()->addMenu(mEditArchiveMenu); - mEditArchiveMenuA->setVisible(false); //TreeView view menu mTreeViewMenu = new QMenu(tr("View"), this); @@ -520,67 +449,39 @@ void SheMov::createMenus(){ mFSWidget->fileView()->addAction(mCopyA); mFSWidget->fileView()->addAction(mMoveA); mFSWidget->fileView()->addAction(mRenameMenuA); - QAction *sep4 = new QAction(this); - sep4->setSeparator(true); - mFSWidget->fileView()->addAction(sep4); - mFSWidget->fileView()->addAction(mArchiveA); - - //ArchiveViewWidget context menu - /*mOpenWithMenuAV = new QMenu(tr("Open with"), this); - mAVWidget->fileView()->addAction(mPlaySelectedAVA); - createOpenWithMenuAV(); - mOpenWithMenuAVA = new QAction(tr("Open with"), this); - mOpenWithMenuAVA->setMenu(mOpenWithMenuAV); - mAVWidget->fileView()->addAction(mOpenWithMenuAVA); - QAction *sep5 = new QAction(this); - sep5->setSeparator(true); - mAVWidget->fileView()->addAction(sep5);*/ - mAVWidget->fileView()->addAction(mEditArchiveFileA); - mAVWidget->fileView()->addAction(mCopyToPartsA); - mAVWidget->fileView()->addAction(mAddMovieManuallyA); - mAVWidget->fileView()->addAction(mDeleteFromArchiveA); - mAVWidget->fileView()->addAction(mSetDvdA); - QAction *sep6 = new QAction(this); - sep6->setSeparator(true); - mAVWidget->fileView()->addAction(sep6); - mAVWidget->fileView()->addAction(mMoveBurnA); - QAction *sep7 = new QAction(this); - sep7->setSeparator(true); - mAVWidget->fileView()->addAction(sep7); - mAVWidget->fileView()->addAction(mPropertiesA); //ArchiveTreeView context menu mATree->seriesWidget()->seriesTree()->addAction(mNewSeriesA); mATree->seriesWidget()->seriesTree()->addAction(mDeleteFromSeriesA); - QAction *sep8 = new QAction(this); - sep8->setSeparator(true); - mATree->seriesWidget()->seriesTree()->addAction(sep8); + QAction *sep4 = new QAction(this); + sep4->setSeparator(true); + mATree->seriesWidget()->seriesTree()->addAction(sep4); mOpenWithMenuAV = new QMenu(tr("Open with"), this); mATree->seriesWidget()->seriesTree()->addAction(mPlaySelectedAVA); createOpenWithMenuAV(); mOpenWithMenuAVA = new QAction(tr("Open with"), this); mOpenWithMenuAVA->setMenu(mOpenWithMenuAV); mATree->seriesWidget()->seriesTree()->addAction(mOpenWithMenuAVA); - QAction *sep9 = new QAction(this); - sep9->setSeparator(true); - mATree->seriesWidget()->seriesTree()->addAction(sep9); + QAction *sep5 = new QAction(this); + sep5->setSeparator(true); + mATree->seriesWidget()->seriesTree()->addAction(sep5); mATree->seriesWidget()->seriesTree()->addAction(mExpandCurrentA); mATree->seriesWidget()->seriesTree()->addAction(mExpandAllSeriesA); mATree->seriesWidget()->seriesTree()->addAction(mCollapseAllSeriesA); - QAction *sep12 = new QAction(this); - sep12->setSeparator(true); - mATree->seriesWidget()->seriesTree()->addAction(sep12); + QAction *sep6 = new QAction(this); + sep6->setSeparator(true); + mATree->seriesWidget()->seriesTree()->addAction(sep6); mATree->seriesWidget()->seriesTree()->addAction(mAddCoverA); //ArchiveTreeView fileWidget context menu mATree->filesWidget()->filesTree()->addAction(mMoveToBurnA); - QAction *sep10 = new QAction(this); - sep10->setSeparator(true); - mATree->filesWidget()->filesTree()->addAction(sep10); + QAction *sep7 = new QAction(this); + sep7->setSeparator(true); + mATree->filesWidget()->filesTree()->addAction(sep7); mATree->filesWidget()->filesTree()->addAction(mSetDvdNoA); - QAction *sep11 = new QAction(this); - sep11->setSeparator(true); - mATree->filesWidget()->filesTree()->addAction(sep11); + QAction *sep8 = new QAction(this); + sep8->setSeparator(true); + mATree->filesWidget()->filesTree()->addAction(sep8); mATree->filesWidget()->filesTree()->addAction(mDeleteFilesFromTreeA); } @@ -13,19 +13,12 @@ class QTabWidget; class FilesystemWidget; -class ArchiveEditWidget; class QAction; class QLabel; class QItemSelection; class QSignalMapper; class QMenu; class QActionGroup; -class ArchiveEditDialog; -class MovieModel; -class ListModel; -class ArchiveViewWidget; -class EditArchiveItemDialog; -class ArchiveItemEditDialog; class ArchiveTreeView; class NewMovieWizard; @@ -82,13 +75,6 @@ class SheMov : public QMainWindow { QAction *mRenameCoverCA; QAction *mTemplateA; QAction *mConfigA; - QAction *mArchiveA; - QAction *mEditArchiveFileA; - QAction *mAddMovieManuallyA; - QAction *mPropertiesA; - QAction *mMoveBurnA; - QAction *mSetDvdA; - QAction *mDeleteFromArchiveA; QAction *mAboutShemovA; QAction *mAboutQtA; QAction *mStatisticsA; @@ -97,7 +83,6 @@ class SheMov : public QMainWindow { QAction *mOpenWithMenuFSA; QAction *mOpenWithMenuAVA; QAction *mRenameMenuA; - QAction *mCopyToPartsA; //TreeView Actions //Series Actions @@ -125,28 +110,19 @@ class SheMov : public QMainWindow { //EndActions QSignalMapper *mRenameMapper; - QSignalMapper *mExtractMapper; QSignalMapper *mOpenWithMapperFS; QSignalMapper *mOpenWithMapperAV; QMenu *mEditFSMenu; - QMenu *mEditArchiveMenu; QMenu *mOpenWithMenuFS; QMenu *mOpenWithMenuAV; QMenu *mRenameMenu; QMenu *mTreeViewMenu; QAction *mEditFSMenuA; - QAction *mEditArchiveMenuA; QTabWidget *mTab; FilesystemWidget *mFSWidget; - ArchiveViewWidget *mAVWidget; ArchiveTreeView *mATree; - ArchiveEditDialog *mAEdit; - ArchiveItemEditDialog *mAItemEdit; - MovieModel *mMovieModel; - ListModel *mGenreModel; - ListModel *mActorModel; NewMovieWizard *mNewMovieWizard; }; @@ -6,10 +6,6 @@ CONFIG += warn_on \ CONFIG -= release QT += sql SOURCES = main.cpp \ - listmodel.cpp \ - movieitem.cpp \ - moviemodel.cpp \ - coveritem.cpp \ filesystemdirproxy.cpp \ filesystemwidget.cpp \ fileview.cpp \ @@ -19,33 +15,16 @@ SOURCES = main.cpp \ shemoviconprovider.cpp \ messagedialog.cpp \ configurationdialog.cpp \ - archiveeditdialog.cpp \ - listeditor.cpp \ - covereditor.cpp \ - archivefilewidget.cpp \ - archiveviewwidget.cpp \ - archivefileview.cpp \ - archiveproxy.cpp \ - sizedelegate.cpp \ - archiveddelegate.cpp \ textenterdialog.cpp \ moviepropertiesdialog.cpp \ statisticsdialog.cpp \ actorwidget.cpp \ actormodel.cpp \ - fileinfoitem.cpp \ - fileinfomodel.cpp \ actorcountmodel.cpp \ graphbarwidget.cpp \ programconfigurator.cpp \ - addmoviewizard.cpp \ - listmodelsingleton.cpp \ - moviemodelsingleton.cpp \ pictureviewer.cpp \ pictureviewerinfoitem.cpp \ - archiveiteminfoedit.cpp \ - archiveitemcoveredit.cpp \ - archiveitemeditdialog.cpp \ smtreeitem.cpp \ smtreemodel.cpp \ smmodelsingleton.cpp \ @@ -58,10 +37,6 @@ SOURCES = main.cpp \ mappingtablewidget.cpp \ newmoviewizard.cpp HEADERS = listitem.h \ - listmodel.h \ - movieitem.h \ - moviemodel.h \ - coveritem.h \ filesystemdirproxy.h \ filesystemwidget.h \ fileview.h \ @@ -71,33 +46,16 @@ HEADERS = listitem.h \ shemoviconprovider.h \ messagedialog.h \ configurationdialog.h \ - archiveeditdialog.h \ - listeditor.h \ - covereditor.h \ - archivefilewidget.h \ - archiveviewwidget.h \ - archivefileview.h \ - archiveproxy.h \ - sizedelegate.h \ - archiveddelegate.h \ textenterdialog.h \ moviepropertiesdialog.h \ statisticsdialog.h \ actorwidget.h \ actormodel.h \ - fileinfoitem.h \ - fileinfomodel.h \ actorcountmodel.h \ graphbarwidget.h \ programconfigurator.h \ - addmoviewizard.h \ - listmodelsingleton.h \ - moviemodelsingleton.h \ pictureviewer.h \ pictureviewerinfoitem.h \ - archiveiteminfoedit.h \ - archiveitemcoveredit.h \ - archiveitemeditdialog.h \ smtreeitem.h \ smtreemodel.h \ smmodelsingleton.h \ diff --git a/sizedelegate.cpp b/sizedelegate.cpp deleted file mode 100644 index 804670f..0000000 --- a/sizedelegate.cpp +++ /dev/null @@ -1,41 +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 <QFontMetrics> -#include <QLocale> -#include <QPainter> -#include <QApplication> - -#include "sizedelegate.h" - -SizeDelegate::SizeDelegate(QObject *parent) : QAbstractItemDelegate(parent) {}; - -void SizeDelegate::paint(QPainter *p, const QStyleOptionViewItem &option, const QModelIndex &index) const{ - p->save(); - qint64 size = index.data().toLongLong(); - qint64 maxSize = Q_INT64_C(2147483648); - QColor c(QColor(Qt::darkGreen)); - if(size > maxSize){ - c = QColor(Qt::red); - } - qApp->style()->drawControl(QStyle::CE_ItemViewItem, &option, p); - p->setPen(QPen(c)); - p->setFont(option.font); - QLocale l; - QString text = l.toString(size); - p->drawText(option.rect, Qt::AlignRight | Qt::AlignCenter | Qt::AlignVCenter, text); - p->restore(); -} - -QSize SizeDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const { - QFont font = option.font; - QFontMetrics metrics(font); - QLocale l; - QString size = l.toString(index.data().toLongLong()); - return metrics.size(Qt::TextSingleLine, size); -} - diff --git a/sizedelegate.h b/sizedelegate.h deleted file mode 100644 index a1c1d47..0000000 --- a/sizedelegate.h +++ /dev/null @@ -1,23 +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. -*/ - -#ifndef SIZEDELEGATE_H -#define SIZEDELEGATE_H - -#include <QAbstractItemDelegate> - -class SizeDelegate : public QAbstractItemDelegate { - Q_OBJECT - public: - SizeDelegate(QObject *parent = 0); - ~SizeDelegate() {}; - void paint(QPainter *p, const QStyleOptionViewItem &option, const QModelIndex &index) const; - QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const; -}; - -#endif - |