-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmovie.cpp
333 lines (249 loc) · 7.79 KB
/
movie.cpp
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
#include <QtXml>
#include "movie.h"
movie::movie()
{
}
movie::movie(QDomElement movieelement)
{
setName(movieelement.attribute("name"));
QDomNode userinfos = movieelement.elementsByTagName("user_infos").at(0);
if(userinfos.isElement())
getUserInfosXML(userinfos.toElement());
QDomNode realinfos = movieelement.elementsByTagName("real_infos").at(0);
if(realinfos.isElement())
getRealInfosXML(realinfos.toElement());
}
void movie::getUserInfosXML(QDomElement userinfos)
{
QDomNode userReviewInfo = userinfos.elementsByTagName("user_review").at(0);
setUserReview(userReviewInfo.toElement().text());
QDomNode userMarkInfo = userinfos.elementsByTagName("user_rating").at(0);
setUserRating(userMarkInfo.toElement().text());
QDomNode userDateInfo = userinfos.elementsByTagName("date").at(0);
QDateTime dateTime;
QDate date;
date.setDate(userDateInfo.toElement().attribute("year").toInt(),
userDateInfo.toElement().attribute("month").toInt(),
userDateInfo.toElement().attribute("day").toInt());
dateTime.setDate(date);
setUserDate(dateTime);
}
void movie::getRealInfosXML(QDomElement realinfos)
{
QDomNode originalNameInfo = realinfos.elementsByTagName("name").at(0);
setOriginalName(originalNameInfo.toElement().text());
QDomNode ratingIngo = realinfos.elementsByTagName("rating").at(0);
setRating(ratingIngo.toElement().text());
QDomNode rtidinfo = realinfos.elementsByTagName("rtid").at(0);
setrtid(rtidinfo.toElement().text());
QDomNode yearinfo = realinfos.elementsByTagName("year").at(0);
setYear(yearinfo.toElement().text().toInt());
QDomNode posterinfo = realinfos.elementsByTagName("poster").at(0);
setPosterPath(posterinfo.toElement().text());
QDomNode synopsisinfo = realinfos.elementsByTagName("synopsis").at(0);
setSynopsis(synopsisinfo.toElement().text());
//QDomNode directorinfo = realinfos.elementsByTagName("director").at(0);
//setDirector(directorinfo.toElement().text());
//qDebug() << getDirector();
QDomNode runtimeinfo = realinfos.elementsByTagName("runtime").at(0);
setRuntime(runtimeinfo.toElement().text());
QDomNode genreInfos = realinfos.elementsByTagName("genres").at(0);
if(genreInfos.isElement())
getGenresXML(genreInfos.toElement());
QDomNode directorsInfos = realinfos.elementsByTagName("directors").at(0);
if(directorsInfos.isElement())
getDirectorsXML(directorsInfos.toElement());
QDomNode castinfo = realinfos.elementsByTagName("cast").at(0);
if(castinfo.isElement())
getCastXML(castinfo.toElement());
}
void movie::getGenresXML(QDomElement genreInfos)
{
QDomNodeList genresinfo = genreInfos.elementsByTagName("genre");
for(int i=0;i<genresinfo.count();i++) {
QDomNode genreinfo = genresinfo.at(i);
if(genreinfo.isElement()) {
addGenre(genreinfo.toElement().text());
}
}
}
void movie::getDirectorsXML(QDomElement directorsInfos)
{
QDomNodeList directorsInfo = directorsInfos.elementsByTagName("director");
for(int i=0;i<directorsInfo.count();i++) {
QDomNode directorInfo = directorsInfo.at(i);
if(directorInfo.isElement()) {
addDirector(directorInfo.toElement().text());
}
}
}
void movie::getCastXML(QDomElement castinfo)
{
QDomNodeList castinginfo = castinfo.elementsByTagName("actor");
for(int i=0;i<castinginfo.count();i++)
{
QDomNode actorinfo = castinginfo.at(i);
if(actorinfo.isElement())
{
QString name = actorinfo.toElement().attribute("name");
QString role = actorinfo.toElement().text();
addActor(actor(name,role));
//qDebug() << name + " " + role;
}
}
}
movie::~movie()
{
}
QString movie::getName() const {
return this->name;
}
void movie::setName(const QString &name) {
this->name = name;
}
int movie::getYear() const {
return this->year;
}
void movie::setYear(int year) {
this->year = year;
}
void movie::setPosterPath(const QString& posterPath) {
this->posterPath = posterPath;
}
QString movie::getPosterPath(void) const {
return this->posterPath;
}
void movie::setUserReview(const QString& userReview) {
this->userReview = userReview;
}
QString movie::getUserReview(void) const {
return userReview;
}
void movie::setUserRating(const QString& userRating) {
this->userRating = userRating;
}
QString movie::getUserRating(void) const {
return userRating;
}
void movie::setUserDate(const QDateTime& userDate) {
this->userDate = userDate;
}
QDateTime movie::getUserDate(void) const {
return userDate;
}
void movie::setOriginalName(const QString& originalName) {
this->originalName = originalName;
}
QString movie::getOriginalName(void) const {
return originalName;
}
void movie::setRating(const QString& rating) {
this->rating = rating;
}
QString movie::getRating(void) const {
return rating;
}
void movie::setSynopsis(const QString& synopsis) {
this->synopsis = synopsis;
}
QString movie::getSynopsis(void) const {
return synopsis;
}
void movie::setRuntime(const QString& runtime) {
this->runtime = runtime;
}
QString movie::getRuntime(void) const {
return runtime;
}
void movie::addGenre(const QString& genre) {
this->genres.push_back(genre);
}
int movie::genreCount(void) const {
return genres.count();
}
QString movie::genreAt(const int& position) const {
if(genres.count() <= position)
throw "Genre list limits exceeded!";
return genres[position];
}
void movie::removeGenre(const int& position) {
if(genres.count() <= position)
throw "Genre list limits esceeded!";
genres.removeAt(position);
}
void movie::removeGenre(const QString& genre) {
int position = -1;
for(;position < genres.count();position ++)
if(genres[position] == genre) {
break ;
}
if(position >= 0)
removeGenre(position);
}
QList<QString> movie::getGenres(void) const {
return this->genres;
}
void movie::addDirector(const QString& directorName) {
directors.push_back(directorName);
}
int movie::directorsCount(void) const {
return directors.count();
}
QString movie::directorAt(const int& position) const {
if(directors.count() <= position)
throw "Directors list limits exceeded!";
return directors[position];
}
void movie::removeDirector(const int& position) {
if(directors.count() <= position)
throw "Directors list limits esceeded!";
directors.removeAt(position);
}
void movie::removeDirector(const QString& directorName) {
int position = -1;
for(;position < directors.count();position ++)
if(directors[position] == directorName) {
break ;
}
if(position >= 0)
removeDirector(position);
}
QList<QString> movie::getDirectors(void) const {
return this->directors;
}
void movie::addActor(const actor& act) {
cast.push_back(act);
}
actor movie::actorAt(const int& position) const {
if(cast.count() <= position)
throw "Genre list limits exceeded!";
return cast.at(position);
}
int movie::actorCount(void) const {
return cast.count();
}
void movie::removeActor(const int& position) {
if(cast.count() <= position)
throw "Actor list limits exceeded!";
cast.removeAt(position);
}
void movie::setrtid(const QString& rtid) {
this->rtid = rtid;
}
QString movie::getrtid(void) const {
return rtid;
}
void movie::updateDBInformations(movie *mov) {
originalName = mov->originalName;
posterPath = mov->posterPath;
year = mov->year;
synopsis = mov->synopsis;
runtime = mov->runtime;
rating = mov->rating;
genres.clear();
genres = mov->genres;
directors.clear();
directors = mov->directors;
cast.clear();
cast = mov->cast;
}