-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtraktpersonshowsmodel.cpp
47 lines (36 loc) · 1.18 KB
/
traktpersonshowsmodel.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
#include "traktpersonshowsmodel.h"
#include "traktperson.h"
TraktPersonShowsModel::TraktPersonShowsModel(TraktPerson *person, QObject *parent) :
TraktShowsModel(buildRequest(person), parent)
{
}
TraktRequest *TraktPersonShowsModel::buildRequest(TraktPerson *person) const
{
TraktRequest *request = new TraktRequest();
request->setPath(QString("/people/%1/shows").arg(person->ids()->trakt()));
request->addQueryItem("extended", "full,images");
return request;
}
void TraktPersonShowsModel::onReplyReceived(TraktReply *reply)
{
reply->deleteLater();
QVariantMap value = reply->asMap();
QList<TraktShow*> newItems;
addItems(newItems, value.value("cast").toList());
QVariantMap crew = value.value("crew").toMap();
foreach (QString type, crew.keys()) {
addItems(newItems, crew.value(type).toList());
}
beginResetModel();
m_items.append(newItems);
endResetModel();
this->setLoading(false);
this->setLoaded(true);
}
void TraktPersonShowsModel::addItems(QList<TraktShow*> &list, const QVariantList &items)
{
foreach (QVariant item, items) {
QVariantMap map = item.toMap();
list.append(convertItem(map));
}
}