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/>.
23 #include "qasabstractobject.h"
30 //------------------------------------------------------------------------------
32 class QASLocation
: public QObject
{
36 QASLocation(QObject
* parent
);
38 bool isEmpty() const { return m_displayName
.isEmpty(); }
39 void update(QVariantMap json
);
41 QString
osmURL(int level
) const {
42 return QString("http://www.openstreetmap.org/#map=%1/%2/%3").
43 arg(level
).arg(m_latitude
).arg(m_longitude
);
46 bool hasPosition() const { return m_hasPosition
; }
47 double latitude() const { return m_latitude
; }
48 double longitude() const { return m_longitude
; }
49 QString
displayName() const { return m_displayName
; }
52 void updatePosition(QVariantMap json
);
56 QString m_displayName
;
61 //------------------------------------------------------------------------------
63 class QASObject
: public QASAbstractObject
{
67 QASObject(QString id
, QObject
* parent
);
70 static void clearCache();
71 static int cacheItems() { return s_objects
.count(); }
72 static int objectsUnconnected();
74 int connections() const;
76 static QASObject
* getObject(QVariantMap json
, QObject
* parent
,
77 bool ignoreLike
=false);
78 static QASObject
* getObject(QString id
) {
79 return s_objects
.contains(id
) ? s_objects
[id
] : NULL
;
82 virtual void update(QVariantMap json
, bool ignoreLike
);
83 virtual void update(QVariantMap json
) { update(json
, false); }
87 qint64
sortInt() const { return sortIntByDateTime(m_updated
); }
88 QDateTime
updatedDate() const { return m_updated
; }
90 QString
id() const { return m_id
; }
91 QString
content() const;
92 QString
type() const { return m_objectType
; }
93 QString
url() const { return m_url
; }
94 QString
imageUrl() const { return m_imageUrl
; }
95 QString
fullImageUrl() const { return m_fullImageUrl
; }
96 QString
displayName() const { return m_displayName
; }
97 virtual QString
apiLink() const;
98 QString
proxyUrl() const { return m_proxyUrl
; }
99 QString
urlOrProxy() const {
100 return m_proxyUrl
.isEmpty() ? m_url
: m_proxyUrl
;
102 QString
fileUrl() const { return m_fileUrl
; }
103 QString
mimeType() const { return m_mimeType
; }
105 QASLocation
* location() const { return m_location
; }
106 QString
streamUrl(bool orig
=false) const {
107 return m_streamUrlProxy
.isEmpty() || orig
? m_streamUrl
: m_streamUrlProxy
;
110 QDateTime
published() const { return m_published
; }
113 bool liked() const { return m_liked
; }
114 size_t numLikes() const;
115 void addLike(QASActor
* actor
, bool like
);
116 QASActorList
* likes() const { return m_likes
; }
118 bool shared() const { return m_shared
; }
119 size_t numShares() const;
120 void addShare(QASActor
* actor
);
121 QASActorList
* shares() const { return m_shares
; }
123 size_t numReplies() const;
124 QASObjectList
* replies() const { return m_replies
; }
125 void addReply(QASObject
* obj
);
127 QASActor
* author() const { return m_author
; }
128 void setAuthor(QASActor
* a
) { m_author
= a
; }
129 QASObject
* inReplyTo() const { return m_inReplyTo
; }
131 // currently just a minimal variant needed for the API e.g. when
132 // favouriting the object
133 QVariantMap
toJson() const;
135 virtual bool isDeleted() const { return !m_deleted
.isNull(); }
136 QDateTime
deletedDate() const { return m_deleted
; }
138 QString
excerpt() const;
140 QASActivity
* postingActivity() const { return m_postingActivity
; }
141 void setPostingActivity(QASActivity
* a
) { m_postingActivity
= a
; }
144 QString
deletedText() const;
150 QString m_objectType
;
153 QString m_fullImageUrl
;
154 QString m_displayName
;
158 QString m_streamUrlProxy
;
162 QDateTime m_published
;
166 QASLocation
* m_location
;
168 QASObject
* m_inReplyTo
;
170 QASObjectList
* m_replies
;
171 QASActorList
* m_likes
;
172 QASActorList
* m_shares
;
174 QASActivity
* m_postingActivity
;
176 static QMap
<QString
, QASObject
*> s_objects
;
179 typedef QList
<QASObject
*> RecipientList
;
181 #endif /* _QASOBJECT_H_ */