Attica

content.cpp
1/*
2 This file is part of KDE.
3
4 SPDX-FileCopyrightText: 2008 Cornelius Schumacher <schumacher@kde.org>
5
6 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
7*/
8
9#include "content.h"
10
11#include <QDateTime>
12
13using namespace Attica;
14
15class Q_DECL_HIDDEN Content::Private : public QSharedData
16{
17public:
18 QString m_id;
19 QString m_name;
20 int m_downloads;
21 int m_numberOfComments;
22 int m_rating;
23 QDateTime m_created;
24 QDateTime m_updated;
25 QList<Icon> m_icons;
26 QList<QUrl> m_videos;
27 QStringList m_tags;
28
29 QMap<QString, QString> m_extendedAttributes;
30
31 Private()
32 : m_downloads(0)
33 , m_numberOfComments(0)
34 , m_rating(0)
35 {
36 }
37};
38
40 : d(new Private)
41{
42}
43
45 : d(other.d)
46{
47}
48
50{
51 d = other.d;
52 return *this;
53}
54
58
59void Content::setId(const QString &u)
60{
61 d->m_id = u;
62}
63
65{
66 return d->m_id;
67}
68
69void Content::setName(const QString &name)
70{
71 d->m_name = name;
72}
73
75{
76 return d->m_name;
77}
78
80{
81 d->m_rating = v;
82}
83
84int Content::rating() const
85{
86 return d->m_rating;
87}
88
90{
91 d->m_downloads = v;
92}
93
95{
96 return d->m_downloads;
97}
98
100{
101 d->m_numberOfComments = v;
102}
103
105{
106 return d->m_numberOfComments;
107}
108
110{
111 d->m_created = date;
112}
113
115{
116 return d->m_created;
117}
118
120{
121 d->m_updated = date;
122}
123
125{
126 return d->m_updated;
127}
128
129void Content::addAttribute(const QString &key, const QString &value)
130{
131 d->m_extendedAttributes.insert(key, value);
132}
133
135{
136 return d->m_extendedAttributes.value(key);
137}
138
140{
141 return d->m_extendedAttributes;
142}
143
145{
146 return !(d->m_id.isEmpty());
147}
148
150{
151 return attribute(QStringLiteral("summary"));
152}
153
155{
156 return attribute(QStringLiteral("description"));
157}
158
160{
161 return QUrl(attribute(QStringLiteral("detailpage")));
162}
163
164QString Attica::Content::changelog() const
165{
166 return attribute(QStringLiteral("changelog"));
167}
168
169QString Attica::Content::depend() const
170{
171 return attribute(QStringLiteral("depend"));
172}
173
175{
177 QMap<QString, QString>::const_iterator iter = d->m_extendedAttributes.constBegin();
178 while (iter != d->m_extendedAttributes.constEnd()) {
179 const QString &key = iter.key();
180 static const QLatin1String tag("downloadname");
181 if (key.startsWith(tag)) {
182 bool ok;
183 // remove "downloadlink", get the rest as number
184 const int num = QStringView(key).right(key.size() - tag.size()).toInt(&ok);
185 if (ok) {
186 // check if the download actually has a name
187 if (!iter.value().isEmpty()) {
188 descriptions.append(downloadUrlDescription(num));
189 }
190 }
191 }
192 ++iter;
193 }
194 return descriptions;
195}
196
198{
199 QString num(QString::number(number));
201
202 Attica::DownloadDescription::Type downloadType = Attica::DownloadDescription::LinkDownload;
203 if (attribute(QLatin1String("downloadway") + num) == QLatin1Char('0')) {
204 downloadType = Attica::DownloadDescription::FileDownload;
205 } else if (attribute(QLatin1String("downloadway") + num) == QLatin1Char('1')) {
206 downloadType = Attica::DownloadDescription::LinkDownload;
207 } else if (attribute(QLatin1String("downloadway") + num) == QLatin1Char('2')) {
208 downloadType = Attica::DownloadDescription::PackageDownload;
209 }
210 desc.setType(downloadType);
211 desc.setId(number);
212 desc.setName(attribute(QLatin1String("downloadname") + num));
213 desc.setDistributionType(attribute(QLatin1String("downloadtype") + num));
214 desc.setHasPrice(attribute(QLatin1String("downloadbuy") + num) == QLatin1Char('1'));
215 desc.setLink(attribute(QLatin1String("downloadlink") + num));
216 desc.setPriceReason(attribute(QLatin1String("downloadreason") + num));
217 desc.setPriceAmount(attribute(QLatin1String("downloadprice") + num));
218 desc.setSize(attribute(QLatin1String("downloadsize") + num).toUInt());
219 desc.setGpgFingerprint(attribute(QLatin1String("downloadgpgfingerprint") + num));
220 desc.setGpgSignature(attribute(QLatin1String("downloadgpgsignature") + num));
221 desc.setPackageName(attribute(QLatin1String("downloadpackagename") + num));
222 desc.setRepository(attribute(QLatin1String("downloadrepository") + num));
223 desc.setTags(attribute(QLatin1String("downloadtags") + num).split(QLatin1Char(',')));
224 return desc;
225}
226
228{
230 QMap<QString, QString>::const_iterator iter = d->m_extendedAttributes.constBegin();
231 while (iter != d->m_extendedAttributes.constEnd()) {
232 QString key = iter.key();
233 if (key.startsWith(QLatin1String("homepagetype"))) {
234 bool ok;
235 // remove "homepage", get the rest as number
236 const int num = QStringView(key).right(key.size() - 12).toInt(&ok);
237 if (ok) {
238 // check if the homepage actually has a valid type
239 if (!iter.value().isEmpty()) {
240 homepages.append(homePageEntry(num));
241 }
242 }
243 }
244 ++iter;
245 }
246
247 return homepages;
248}
249
251{
252 QString num(QString::number(number));
253 HomePageEntry homepage;
254
255 if (number == 1 && attribute(QStringLiteral("homepage1")).isEmpty()) {
256 num.clear();
257 }
258 homepage.setType(attribute(QLatin1String("homepagetype") + num));
259 homepage.setUrl(QUrl(attribute(QLatin1String("homepage") + num)));
260 return homepage;
261}
262
263QString Attica::Content::version() const
264{
265 return attribute(QStringLiteral("version"));
266}
267
268QString Attica::Content::author() const
269{
270 return attribute(QStringLiteral("personid"));
271}
272
273QString Attica::Content::license() const
274{
275 return attribute(QStringLiteral("licensetype"));
276}
277
278QString Attica::Content::licenseName() const
279{
280 return attribute(QStringLiteral("license"));
281}
282
283QString Attica::Content::previewPicture(const QString &number) const
284{
285 return attribute(QLatin1String("previewpic") + number);
286}
287
288QString Attica::Content::smallPreviewPicture(const QString &number) const
289{
290 return attribute(QLatin1String("smallpreviewpic") + number);
291}
292
294{
295 return d->m_icons;
296}
297
299{
300 return d->m_icons;
301}
302
304{
305 d->m_icons = std::move(icons); // TODO KF6 Make QList const & and remove the std::move
306}
307
309{
310 return d->m_videos;
311}
312
314{
315 d->m_videos = std::move(videos);
316}
317
319{
320 return d->m_tags;
321}
322
324{
325 d->m_tags = tags;
326}
Represents a single content.
Definition content.h:33
QString description() const
A description of this content.
Definition content.cpp:154
int downloads() const
Gets the number of downloads for the Content (how often this has been downloaded from the server).
Definition content.cpp:94
int rating() const
Gets the rating of the Content.
Definition content.cpp:84
void setCreated(const QDateTime &created)
Sets the date and time the Content has been created.
Definition content.cpp:109
QDateTime created() const
Gets the date and time the Content has been created.
Definition content.cpp:114
QList< DownloadDescription > downloadUrlDescriptions() const
Get all possible downloads.
Definition content.cpp:174
QStringList tags() const
Get all the tags for this content.
Definition content.cpp:318
QString attribute(const QString &key) const
Get an attribute that is not included in the basis set of attributes exposed by the Content class.
Definition content.cpp:134
int numberOfComments() const
Gets the number of comments for the Content.
Definition content.cpp:104
void setIcons(QList< Icon > icons)
Set list of icons.
Definition content.cpp:303
void addAttribute(const QString &key, const QString &value)
Add an attribute that is not included in the basis set of attributes exposed by the Content class.
Definition content.cpp:129
void setVideos(QList< QUrl > videos)
Set list of videos.
Definition content.cpp:313
Content & operator=(const Content &other)
Assignment operator.
Definition content.cpp:49
HomePageEntry homePageEntry(int number) const
Get the details about a home page (a content can have multiple home pages, blog, bugs,...
Definition content.cpp:250
QList< Icon > icons()
Get all icons for this content.
Definition content.cpp:293
QUrl detailpage() const
A webpage with the detailed description of this content.
Definition content.cpp:159
QDateTime updated() const
Gets the date and time the Content has been last updated.
Definition content.cpp:124
QList< QUrl > videos()
Get all videos for this content.
Definition content.cpp:308
void setId(const QString &id)
Sets the id of the Content.
Definition content.cpp:59
QList< HomePageEntry > homePageEntries()
Get all home pages for this content.
Definition content.cpp:227
void setDownloads(int downloads)
Sets the number of downloads for the Content.
Definition content.cpp:89
void setName(const QString &name)
Sets the name of the Content.
Definition content.cpp:69
void setRating(int rating)
Sets the rating of the Content.
Definition content.cpp:79
void setNumberOfComments(int numComments)
Sets the number of comments for the Content.
Definition content.cpp:99
~Content()
Destructor.
Definition content.cpp:55
bool isValid() const
Checks whether this Content has an id.
Definition content.cpp:144
void setTags(const QStringList &tags)
Set the list of tags.
Definition content.cpp:323
QString summary() const
A summary description of this content.
Definition content.cpp:149
QMap< QString, QString > attributes() const
Get all attributes that are not included in the basis set of attributes exposed by the Content class.
Definition content.cpp:139
DownloadDescription downloadUrlDescription(int number) const
Get the details about a download (a content can have multiple links, eg for different distros).
Definition content.cpp:197
QString name() const
Gets the name of the Content.
Definition content.cpp:74
QString id() const
Gets the id of the Content.
Definition content.cpp:64
Content()
Creates an empty Content.
Definition content.cpp:39
void setUpdated(const QDateTime &updated)
Sets the time the Content has been last updated.
Definition content.cpp:119
Represents a download description.
void setTags(const QStringList &tags)
Set the list of tags for this download description.
The HomePageEntry class contains information about one home page entry.
The Attica namespace,.
void append(QList< T > &&value)
void clear()
QString number(double n, char format, int precision)
qsizetype size() const const
bool startsWith(QChar c, Qt::CaseSensitivity cs) const const
QStringView right(qsizetype length) const const
int toInt(bool *ok, int base) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 17 2024 11:54:33 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.