diff options
-rw-r--r-- | archiveeditdialog.cpp (renamed from archiveeditwidget.cpp) | 8 | ||||
-rw-r--r-- | archiveeditdialog.h (renamed from archiveeditwidget.h) | 5 | ||||
-rw-r--r-- | archivefileview.cpp | 37 | ||||
-rw-r--r-- | archivefileview.h | 29 | ||||
-rw-r--r-- | archiveproxy.cpp | 69 | ||||
-rw-r--r-- | archiveproxy.h | 37 | ||||
-rw-r--r-- | archiveviewwidget.cpp | 96 | ||||
-rw-r--r-- | archiveviewwidget.h | 55 | ||||
-rw-r--r-- | movieitem.cpp | 4 | ||||
-rw-r--r-- | moviemodel.cpp | 13 | ||||
-rw-r--r-- | moviemodel.h | 2 | ||||
-rw-r--r-- | shemov.cpp | 11 | ||||
-rw-r--r-- | shemov.h | 5 | ||||
-rw-r--r-- | shemov.pro | 14 |
14 files changed, 365 insertions, 20 deletions
diff --git a/archiveeditwidget.cpp b/archiveeditdialog.cpp index 8f4d116..350597f 100644 --- a/archiveeditwidget.cpp +++ b/archiveeditdialog.cpp @@ -21,7 +21,7 @@ #include <QDebug> -#include "archiveeditwidget.h" +#include "archiveeditdialog.h" #include "archivefilewidget.h" #include "listeditor.h" #include "covereditor.h" @@ -30,11 +30,7 @@ #include "helper.h" #include "coveritem.h" -ArchiveEditDialog::ArchiveEditDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f){ - //init models - mGenreModel = new ListModel("genre", this); - mActorsModel = new ListModel("actor", this); - +ArchiveEditDialog::ArchiveEditDialog(ListModel *genre, ListModel *actors, QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f), mGenreModel(genre), mActorsModel(actors){ QSplitter *hSplitter = new QSplitter(Qt::Horizontal); QWidget *editorWidget = new QWidget; QVBoxLayout *editorLayout = new QVBoxLayout; diff --git a/archiveeditwidget.h b/archiveeditdialog.h index 731214a..23f8614 100644 --- a/archiveeditwidget.h +++ b/archiveeditdialog.h @@ -18,14 +18,13 @@ 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(ListModel *genre, ListModel *actors, QWidget *parent = 0, Qt::WindowFlags f = 0); ~ArchiveEditDialog() {}; - - public: void setFiles(const QStringList &files); void setMovieModel(MovieModel *model) { mMovieModel = model; }; void setDirModel(QDirModel *model) { mDirModel = model; }; diff --git a/archivefileview.cpp b/archivefileview.cpp new file mode 100644 index 0000000..333f292 --- /dev/null +++ b/archivefileview.cpp @@ -0,0 +1,37 @@ +/* + 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); + int ctr(0); + foreach(QAction *a, actions()){ + contextMenu.addAction(a); + if(false){ + contextMenu.addSeparator(); + } + ++ctr; + } + 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 new file mode 100644 index 0000000..180f706 --- /dev/null +++ b/archivefileview.h @@ -0,0 +1,29 @@ +/* + 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/archiveproxy.cpp b/archiveproxy.cpp new file mode 100644 index 0000000..6b1a9e7 --- /dev/null +++ b/archiveproxy.cpp @@ -0,0 +1,69 @@ +/* + 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 "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(); +} + diff --git a/archiveproxy.h b/archiveproxy.h new file mode 100644 index 0000000..94e8d19 --- /dev/null +++ b/archiveproxy.h @@ -0,0 +1,37 @@ +/* + 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(); + + private: + FilterMode mFilterMode; + QString mGenreFilter; + QString mActorFilter; + QString mTitleFilter; +}; + +#endif + diff --git a/archiveviewwidget.cpp b/archiveviewwidget.cpp new file mode 100644 index 0000000..9a0e76e --- /dev/null +++ b/archiveviewwidget.cpp @@ -0,0 +1,96 @@ +/* + 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 <QApplication> + +#include "archiveviewwidget.h" +#include "archivefileview.h" +#include "moviemodel.h" +#include "listmodel.h" +#include "archiveproxy.h" + +ArchiveViewWidget::ArchiveViewWidget(MovieModel *model, ListModel *genre, ListModel *actors, QWidget *parent) : QWidget(parent), mMovieModel(model), mGenreModel(genre), mActorsModel(actors){ + //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(currentIndexChanged(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(currentIndexChanged(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())); + filterLayout->addWidget(mFilter); + mClearFilter = new QPushButton(tr("Clear filter")); + filterLayout->addWidget(mClearFilter); + + //treeview + mFileView = new ArchiveFileView; + mProxy = new ArchiveProxy(this); + mProxy->setSourceModel(mMovieModel); + mFileView->setModel(mProxy); + mFileView->setSortingEnabled(true); + mFileView->setItemsExpandable(false); + mFileView->setRootIsDecorated(false); + connect(mClearFilter, SIGNAL(clicked()), mProxy, SLOT(clearFilter())); + + //main layout + QVBoxLayout *mainLayout = new QVBoxLayout; + mainLayout->addLayout(filterLayout); + mainLayout->addWidget(mFileView); + + connect(mFileView->selectionModel(), SIGNAL(currentRowChanged(const QModelIndex &, const QModelIndex)), this, SLOT(rowChanged(const QModelIndex &, const QModelIndex &))); + + setLayout(mainLayout); +} + +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::rowChanged(const QModelIndex ¤t, const QModelIndex & /*prev*/){ + if(current.isValid()){ + QModelIndex idx = current; + if(current.column() != 0){ + idx = mProxy->index(current.row(), 0, current.parent()); + } + QString title = QString(tr("%1 - %2")).arg(qApp->applicationName()).arg(idx.data().toString()); + emit windowTitle(title); + } +} diff --git a/archiveviewwidget.h b/archiveviewwidget.h new file mode 100644 index 0000000..ea90a6f --- /dev/null +++ b/archiveviewwidget.h @@ -0,0 +1,55 @@ +/* + 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> + +class MovieModel; +class ListModel; +class QComboBox; +class QLineEdit; +class QPushButton; +class QModelIndex; +class ArchiveFileView; +class ArchiveProxy; + +class ArchiveViewWidget : public QWidget { + Q_OBJECT + public: + ArchiveViewWidget(MovieModel *model, ListModel *genre, ListModel *actors, QWidget *parent = 0); + ~ArchiveViewWidget() {}; + ArchiveFileView* fileView() { return mFileView; }; + + signals: + void statusbarMessage(const QString &message); + void windowTitle(const QString &title); + + public slots: + void setFilter(); + void setGenreFilter(const QString &filter); + void setActorFilter(const QString &filter); + + private slots: + void rowChanged(const QModelIndex ¤t, const QModelIndex &prev); + + private: + QComboBox *mGenre; + QComboBox *mActors; + QLineEdit *mName; + QPushButton *mFilter; + QPushButton *mClearFilter; + MovieModel *mMovieModel; + ListModel *mGenreModel; + ListModel *mActorsModel; + ArchiveFileView *mFileView; + ArchiveProxy *mProxy; +}; + +#endif + diff --git a/movieitem.cpp b/movieitem.cpp index 9fb11e1..de2382c 100644 --- a/movieitem.cpp +++ b/movieitem.cpp @@ -57,8 +57,8 @@ void MovieItem::populate(){ movieData.prepare("SELECT ttitle, tfilename, cmd5sum, bisize, igenreid, iquality, idvd FROM movies WHERE imovid = :id"); movieData.bindValue(":id", mId); movieData.exec(); - for(int i = 0; i < mNumRows; ++i){ - if(movieData.next()){ + if(movieData.next()){ + for(int i = 0; i < mNumRows; ++i){ mRows[i] = movieData.value(i); } } diff --git a/moviemodel.cpp b/moviemodel.cpp index 3d93d41..389f456 100644 --- a/moviemodel.cpp +++ b/moviemodel.cpp @@ -6,6 +6,8 @@ */ #include <QSqlQuery> +#include <QStringList> +#include <QIcon> #include "moviemodel.h" #include "coveritem.h" @@ -71,15 +73,22 @@ QVariant MovieModel::data(const QModelIndex &index, int role) const{ if(!index.isValid()){ return QVariant(); } + MovieItem *item = static_cast<MovieItem*>(index.internalPointer()); + Q_ASSERT(item != 0); if(role == Qt::DisplayRole){ - MovieItem *item = static_cast<MovieItem*>(index.internalPointer()); - Q_ASSERT(item != 0); switch (index.column()){ case MovieItem::Dvd: return QVariant(QString(tr("DVD %1")).arg(QString::number(item->dataAt(MovieItem::Dvd).toInt()))); + break; } return item->dataAt(index.column()); } + if(role == ActorsRole){ + return item->actors(); + } + if((role == Qt::DecorationRole) && (index.column() == 0)){ + return QIcon(":/dildo.png"); + } return QVariant(); } diff --git a/moviemodel.h b/moviemodel.h index 2f3587a..cf2e1f2 100644 --- a/moviemodel.h +++ b/moviemodel.h @@ -20,7 +20,7 @@ class MovieModel : public QAbstractItemModel { Q_OBJECT Q_ENUMS(CustomRoles) public: - enum CustomRoles { Md5Role = Qt::UserRole + 1}; + enum CustomRoles { Md5Role = Qt::UserRole + 1, ActorsRole = Qt::UserRole +2 }; MovieModel(QObject *parent = 0); ~MovieModel(); QModelIndex index(int row, int column, const QModelIndex &parent) const; @@ -25,8 +25,10 @@ #include "filesystemwidget.h" #include "fileview.h" #include "configurationdialog.h" -#include "archiveeditwidget.h" +#include "archiveeditdialog.h" #include "moviemodel.h" +#include "listmodel.h" +#include "archiveviewwidget.h" SheMov::SheMov(QWidget *parent, Qt::WindowFlags flags) : QMainWindow(parent, flags) { qApp->setWindowIcon(QIcon(":/shemov.png")); @@ -46,14 +48,19 @@ SheMov::SheMov(QWidget *parent, Qt::WindowFlags flags) : QMainWindow(parent, fla } mMovieModel = new MovieModel(this); + mGenreModel = new ListModel("genre", this); + mActorModel = new ListModel("actor", this); 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 &))); - mAEdit = new ArchiveEditDialog(this); + mAEdit = new ArchiveEditDialog(mGenreModel, mActorModel, this); mAEdit->setMovieModel(mMovieModel); mFSWidget->setArchiveDialog(mAEdit); @@ -21,6 +21,8 @@ class QSignalMapper; class QMenu; class ArchiveEditDialog; class MovieModel; +class ListModel; +class ArchiveViewWidget; class SheMov : public QMainWindow { Q_OBJECT @@ -72,8 +74,11 @@ class SheMov : public QMainWindow { QTabWidget *mTab; FilesystemWidget *mFSWidget; + ArchiveViewWidget *mAVWidget; ArchiveEditDialog *mAEdit; MovieModel *mMovieModel; + ListModel *mGenreModel; + ListModel *mActorModel; }; #endif @@ -17,10 +17,13 @@ shemoviconprovider.cpp \ messagedialog.cpp \ configurationdialog.cpp \ extractordialog.cpp \ -archiveeditwidget.cpp \ +archiveeditdialog.cpp \ listeditor.cpp \ covereditor.cpp \ -archivefilewidget.cpp +archivefilewidget.cpp \ +archiveviewwidget.cpp \ +archivefileview.cpp \ +archiveproxy.cpp HEADERS = listitem.h \ listmodel.h \ movieitem.h \ @@ -36,10 +39,13 @@ shemoviconprovider.h \ messagedialog.h \ configurationdialog.h \ extractordialog.h \ -archiveeditwidget.h \ +archiveeditdialog.h \ listeditor.h \ covereditor.h \ -archivefilewidget.h +archivefilewidget.h \ +archiveviewwidget.h \ +archivefileview.h \ +archiveproxy.h LIBS += -lmagic LIBS += -lcryptopp INCLUDEPATH += /usr/include/cryptopp |