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

KDE's Doxygen guidelines are available online.