Merge branch 'master' of ssh://pumpa.branchable.com
[larjonas-pumpa.git] / src / qasabstractobjectlist.h
blob416053e21d57732cb0b05f7b731fb27418e00cb5
1 /*
2 Copyright 2013-2015 Mats Sjöberg
4 This file is part of the Pumpa programme.
6 Pumpa is free software: you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 Pumpa is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with Pumpa. If not, see <http://www.gnu.org/licenses/>.
20 #ifndef _QASABSTRACTOBJECTLIST_H_
21 #define _QASABSTRACTOBJECTLIST_H_
23 #include "qasabstractobject.h"
25 #include <QSet>
27 //------------------------------------------------------------------------------
29 class QASAbstractObjectList : public QASAbstractObject {
30 Q_OBJECT
32 protected:
33 QASAbstractObjectList(int asType, QString url, QObject* parent);
35 public:
36 virtual void update(QVariantMap json, bool older, bool updateOnly=false);
38 QString prevLink() const {
39 return m_prevLink.isEmpty() ? m_url : m_prevLink;
41 QString nextLink() const { return m_nextLink; }
43 size_t size() const { return m_items.size(); }
45 QASAbstractObject* at(size_t i) const {
46 if (i >= size())
47 return NULL;
48 return m_items[i];
51 qulonglong totalItems() const { return m_totalItems; }
52 QString url() const { return m_url; }
53 QString urlOrProxy() const;
54 virtual QString apiLink() const { return urlOrProxy(); }
55 bool hasMore() const { return m_hasMore; }
57 void addObject(QASAbstractObject*);
58 void removeObject(QASAbstractObject*, bool signal=true);
59 bool contains(QASAbstractObject* obj) const {
60 return m_item_set.contains(obj);
63 bool firstTime() const { return m_firstTime; }
65 protected:
66 virtual QASAbstractObject* getAbstractObject(QVariantMap json,
67 QObject* parent) = 0;
69 QString m_displayName;
70 QString m_url;
71 qulonglong m_totalItems;
72 QString m_proxyUrl;
74 bool m_hasMore;
76 QList<QASAbstractObject*> m_items;
77 QSet<QASAbstractObject*> m_item_set;
79 QString m_prevLink, m_nextLink;
81 bool m_firstTime;
84 #endif /* _QASABSTRACTOBJECTLIST_H_ */