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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
|
#include <QLabel>
#include <QLineEdit>
#include <QRadioButton>
#include <QGroupBox>
#include <QPushButton>
#include <QSqlDatabase>
#include <QSqlQuery>
#include <QIntValidator>
#include <QCompleter>
#include <QStandardItemModel>
#include <QAction>
#include <QGridLayout>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QApplication>
#include "moviepropertiesdialog.h"
#include "smview.h"
#include "sminputdialog.h"
MoviePropertiesDialog::MoviePropertiesDialog(QWidget *parent) : QDialog(parent){
mActorDlg = new SmInputDialog(tr("Actor"), this);
mGenreDlg = new SmInputDialog(tr("Genre"), this);
setupDialog();
}
void MoviePropertiesDialog::setupDialog(){
QLabel *seriesNameL = new QLabel(tr("Name"));
mSeriesNameLE = new QLineEdit;
QGridLayout *seriesGrid = new QGridLayout;
seriesGrid->addWidget(seriesNameL, 0, 0);
seriesGrid->addWidget(mSeriesNameLE, 0, 1);
QLabel *seriesSubtitleL = new QLabel(tr("Subtitle"));
mSubtitleLE = new QLineEdit;
seriesGrid->addWidget(seriesSubtitleL, 1, 0);
seriesGrid->addWidget(mSubtitleLE, 1, 1);
QLabel *commentL = new QLabel(tr("Comment"));
mCommentLE = new QLineEdit;
seriesGrid->addWidget(commentL, 2, 0);
seriesGrid->addWidget(mCommentLE, 2, 1);
QGroupBox *seriesGB = new QGroupBox(tr("Series"));
seriesGB->setLayout(seriesGrid);
QIntValidator *validator = new QIntValidator(this);
mReleaseYearLE = new QLineEdit("0000");
mReleaseYearLE->setValidator(validator);
QGroupBox *releaseYearGB = new QGroupBox(tr("Rel. year"));
QHBoxLayout *releaseYearGBL = new QHBoxLayout;
releaseYearGBL->addWidget(mReleaseYearLE);
releaseYearGB->setLayout(releaseYearGBL);
mSeriesPartLE = new QLineEdit("00");
mSeriesPartLE->setValidator(validator);
QGroupBox *partNoGB = new QGroupBox(tr("Part No."));
QHBoxLayout *partNoGBL = new QHBoxLayout;
partNoGBL->addWidget(mSeriesPartLE);
partNoGB->setLayout(partNoGBL);
mTorrentRB = new QRadioButton(tr("BitTorrent"));
mUsenetRB = new QRadioButton(tr("Usenet"));
QGroupBox *sourceGB = new QGroupBox(tr("Source"));
QHBoxLayout *sourceGBL = new QHBoxLayout;
sourceGBL->addWidget(mTorrentRB);
sourceGBL->addWidget(mUsenetRB);
sourceGB->setLayout(sourceGBL);
QHBoxLayout *variousL = new QHBoxLayout;
variousL->addWidget(releaseYearGB);
variousL->addWidget(partNoGB);
variousL->addWidget(sourceGB);
mActorV = new SmView;
mActorV->setPalette(qApp->palette());
mActorV->setAlternatingRowColors(true);
mActorM = new QStandardItemModel;
mActorV->setModel(mActorM);
QAction *addActorA = new QAction(QIcon(":/spreadingpants.png"), tr("Add actor..."), this);
connect(addActorA, &QAction::triggered, [=] { addItem(mActorDlg, mActorM, QIcon(":/diaper.png")); });
QAction *removeActorA = new QAction(QIcon(":/delete.png"), tr("Remove actor"), this);
mActorV->addActions(QList<QAction*>() << addActorA << removeActorA);
QGroupBox *actorsGB = new QGroupBox(tr("Actors"));
QHBoxLayout *actorsGBL = new QHBoxLayout;
actorsGBL->addWidget(mActorV);
actorsGB->setLayout(actorsGBL);
mGenreV = new SmView;
mGenreV->setPalette(qApp->palette());
mGenreV->setAlternatingRowColors(true);
mGenreM = new QStandardItemModel;
mGenreV->setModel(mGenreM);
QAction *addGenreA = new QAction(QIcon(":/spreadingpants.png"), tr("Add genre..."), this);
connect(addGenreA, &QAction::triggered, [=] { addItem(mGenreDlg, mGenreM, QIcon(":/dick_in_cage.png")); });
QAction *removeGenreA = new QAction(QIcon(":/delete.png"), tr("Remove genre"), this);
mGenreV->addActions(QList<QAction*>() << addGenreA << removeGenreA);
QGroupBox *genresGB = new QGroupBox(tr("Genres"));
QHBoxLayout *genresGBL = new QHBoxLayout;
genresGBL->addWidget(mGenreV);
genresGB->setLayout(genresGBL);
QHBoxLayout *viewL = new QHBoxLayout;
viewL->addWidget(actorsGB);
viewL->addWidget(genresGB);
QPushButton *updatePB = new QPushButton(tr("Update!"));
QPushButton *cancelPB = new QPushButton(tr("Cancel"));
connect(cancelPB, &QPushButton::clicked, this, &MoviePropertiesDialog::reject);
QHBoxLayout *buttonLayout = new QHBoxLayout;
buttonLayout->addStretch();
buttonLayout->addWidget(cancelPB);
buttonLayout->addWidget(updatePB);
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addWidget(seriesGB);
mainLayout->addLayout(variousL);
mainLayout->addLayout(viewL);
mainLayout->addLayout(buttonLayout);
setLayout(mainLayout);
}
void MoviePropertiesDialog::init(int seriesPartsId){
QSqlDatabase db = QSqlDatabase::database("treedb");
QSqlQuery genQ(db);
genQ.prepare("SELECT series.tseries_name, seriesparts.tsubtitle, seriesparts.iseriespart, metadata.tcomment, metadata.sireleaseyear, metadata.tsourcemedium FROM series, seriesparts, metadata WHERE seriesparts.iseriesparts_id = :id AND seriesparts.iseries_id = series.iseries_id AND metadata.iseriespart_id = seriesparts.iseriesparts_id");
genQ.bindValue(":id", seriesPartsId);
genQ.exec();
while(genQ.next()){
mSeriesNameLE->setText(genQ.value(0).toString());
mSubtitleLE->setText(genQ.value(1).toString());
mSeriesPartLE->setText(genQ.value(2).toString());
mCommentLE->setText(genQ.value(3).toString());
mReleaseYearLE->setText(genQ.value(4).toString());
QString src = genQ.value(5).toString().toLower();
if(src == "usenet"){
mUsenetRB->setChecked(true);
}
if(src == "torrent"){
mTorrentRB->setChecked(true);
}
}
mActorM->clear();
mActorM->setHorizontalHeaderLabels(QStringList() << tr("Name"));
mActorV->setRootIsDecorated(false);
QStandardItem *actorsRootItem = mActorM->invisibleRootItem();
QSqlQuery actorsQ(db);
actorsQ.prepare("SELECT actors.tactorname, actors.iactors_id FROM actors, seriesparts_actormap WHERE seriesparts_actormap.iseriesparts_id = :id AND seriesparts_actormap.iactors_id = actors.iactors_id ORDER BY actors.tactorname");
actorsQ.bindValue(":id", seriesPartsId);
actorsQ.exec();
while(actorsQ.next()){
QStandardItem *i = new QStandardItem;
i->setEditable(false);
i->setIcon(QIcon(":/diaper.png"));
i->setText(actorsQ.value(0).toString());
i->setData(actorsQ.value(1), ActorIdRole);
actorsRootItem->appendRow(i);
}
mGenreM->clear();
mGenreM->setHorizontalHeaderLabels(QStringList() << tr("Genre"));
mGenreV->setRootIsDecorated(false);
QStandardItem *genresRootItem = mGenreM->invisibleRootItem();
QSqlQuery genresQ(db);
genresQ.prepare("SELECT genres.tgenrename, genres.igenres_id FROM genres, seriesparts_genremap WHERE seriesparts_genremap.iseriesparts_id = :id AND seriesparts_genremap.igenres_id = genres.igenres_id ORDER BY genres.tgenrename");
genresQ.bindValue(":id", seriesPartsId);
genresQ.exec();
while(genresQ.next()){
QStandardItem *i = new QStandardItem;
i->setEditable(false);
i->setIcon(QIcon(":/dick_in_cage.png"));
i->setText(genresQ.value(0).toString());
i->setData(genresQ.value(1), GenreIdRole);
genresRootItem->appendRow(i);
}
QStringList seriesNames;
QSqlQuery allSeriesNamesQ("SELECT tseries_name FROM series", db);
while(allSeriesNamesQ.next()){
seriesNames << allSeriesNamesQ.value(0).toString();
}
QCompleter *snCompleter = new QCompleter(seriesNames);
mSeriesNameLE->setCompleter(snCompleter);
QStringList actorNames;
QSqlQuery allActorsQ("SELECT tactorname FROM actors", db);
while(allActorsQ.next()){
actorNames << allActorsQ.value(0).toString();
}
QCompleter *actorCompleter = new QCompleter(actorNames, mActorDlg);
mActorDlg->setCompleter(actorCompleter);
QStringList genreNames;
QSqlQuery allGenresQ("SELECT tgenrename FROM genres", db);
while(allGenresQ.next()){
genreNames << allGenresQ.value(0).toString();
}
QCompleter *genreCompleter = new QCompleter(genreNames, mGenreDlg);
mGenreDlg->setCompleter(genreCompleter);
}
void MoviePropertiesDialog::addItem(SmInputDialog *dlg, QStandardItemModel *model, QIcon icon){
int retval = dlg->exec();
if(retval == QDialog::Accepted){
QString itemName = dlg->text().toLower();
int idx = 0;
while(idx != model->rowCount()){
QStandardItem *curItem = model->item(idx, 0);
if(curItem->text() == itemName){
return;
}
if(curItem->text() > itemName){
break;
}
++idx;
}
QStandardItem *newItem = new QStandardItem;
newItem->setEditable(false);
newItem->setIcon(icon);
newItem->setText(itemName);
model->insertRow(idx, newItem);
}
}
|