1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
|
/*
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 "archiveviewwidget.h"
#include "archivefileview.h"
#include "moviemodel.h"
#include "listmodel.h"
#include "archiveproxy.h"
#include "editarchiveitemdialog.h"
#include "sizedelegate.h"
#include "archiveddelegate.h"
#include "coverarchiveeditor.h"
#include "textenterdialog.h"
#include "helper.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(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()));
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->setColumnHidden(MovieItem::Md5Sum, 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(currentRowChanged(const QModelIndex &, const QModelIndex)), this, SLOT(rowChanged(const QModelIndex &, const QModelIndex &)));
connect(mFileView, SIGNAL(doubleClicked(const QModelIndex &)), this, SLOT(showMovie(const QModelIndex &)));
setLayout(mainLayout);
}
void ArchiveViewWidget::editFile(){
QModelIndexList selected = mFileView->selectionModel()->selectedRows();
if(!selected.isEmpty()){
QModelIndex idx = selected.at(0);
QModelIndex real = mProxy->mapToSource(idx);
mEditDialog->setMovie(real);
mEditDialog->show();
mEditDialog->raise();
mEditDialog->activateWindow();
}
}
void ArchiveViewWidget::editCovers(){
QModelIndexList selected = mFileView->selectionModel()->selectedRows();
if(!selected.isEmpty()){
QModelIndex idx = selected.at(0);
QModelIndex real = mProxy->mapToSource(idx);
mCoverEditDialog->setMovie(real);
mCoverEditDialog->show();
mCoverEditDialog->raise();
mCoverEditDialog->activateWindow();
}
}
void ArchiveViewWidget::addMovie(){
TextEnterDialog dlg(tr("Enter movie title"), this);
dlg.exec();
if(dlg.result() == QDialog::Accepted){
QString title = dlg.text().toLower().trimmed();
QModelIndex idx = mMovieModel->index(title);
if(idx != QModelIndex()){
QString msg = QString(tr("Already have an entry with title %1")).arg(title);
QMessageBox::critical(this, tr("Error"), msg);
return;
}
QList<QVariant> movieData;
movieData << title;
for(int i = 1; i < MovieItem::NumRows; ++i){
movieData << QVariant();
}
QString md5(32, '0');
movieData[MovieItem::Md5Sum] = md5;
movieData[MovieItem::Genre] = mGenreModel->defaultId();
movieData[MovieItem::Dvd] = -2;
movieData[MovieItem::Filename] = tr("(DVD)");
movieData[MovieItem::Size] = Q_INT64_C(4707319808);
movieData[MovieItem::Quality] = 0;
mMovieModel->addMovie(movieData, QList<QVariant>(), QList<CoverItem>());
}
}
void ArchiveViewWidget::showMovie(const QModelIndex &movie){
QModelIndex real = mProxy->mapToSource(movie);
QModelIndex dvd = mMovieModel->index(real.row(), MovieItem::Dvd, QModelIndex());
int dvdno = dvd.data().toInt();
if(dvdno != -1){
emit statusbarMessage(tr("Movie is not present on filesystem"));
return;
}
QModelIndex fnIdx = mMovieModel->index(real.row(), MovieItem::Filename, QModelIndex());
QModelIndex md5Idx = mMovieModel->index(real.row(), MovieItem::Md5Sum, QModelIndex());
QString path = Helper::createArchivePath(fnIdx.data().toString(), md5Idx.data().toString());
QSettings s;
QString playerPath = s.value("paths/movieviewer").toString();
QStringList args = s.value("paths/movieviewerargs").toStringList();
args << path;
QProcess::startDetached(playerPath, args);
}
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);
}
}
|