Attica

content.cpp
1 /*
2  This file is part of KDE.
3 
4  SPDX-FileCopyrightText: 2008 Cornelius Schumacher <[email protected]>
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 
13 using namespace Attica;
14 
15 class Content::Private : public QSharedData
16 {
17 public:
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 
56 {
57 }
58 
59 void Content::setId(const QString &u)
60 {
61  d->m_id = u;
62 }
63 
65 {
66  return d->m_id;
67 }
68 
70 {
71  d->m_name = name;
72 }
73 
75 {
76  return d->m_name;
77 }
78 
79 void Content::setRating(int v)
80 {
81  d->m_rating = v;
82 }
83 
84 int Content::rating() const
85 {
86  return d->m_rating;
87 }
88 
90 {
91  d->m_downloads = v;
92 }
93 
94 int Content::downloads() const
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 
129 void 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 
144 bool Content::isValid() const
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 
164 QString Attica::Content::changelog() const
165 {
166  return attribute(QStringLiteral("changelog"));
167 
168 }
169 
170 QString 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  QString key = iter.key();
181  if (key.startsWith(QLatin1String("downloadname"))) {
182  bool ok;
183  // remove "downloadlink", get the rest as number
184  int num = key.rightRef(key.size() - 12).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 
197 Attica::DownloadDescription Attica::Content::downloadUrlDescription(int number) const
198 {
199  QString num(QString::number(number));
200  DownloadDescription desc;
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  int num = key.rightRef(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 
263 QString Attica::Content::version() const
264 {
265  return attribute(QStringLiteral("version"));
266 }
267 
268 QString Attica::Content::author() const
269 {
270  return attribute(QStringLiteral("personid"));
271 }
272 
273 QString Attica::Content::license() const
274 {
275  return attribute(QStringLiteral("licensetype"));
276 }
277 
278 QString Attica::Content::licenseName() const
279 {
280  return attribute(QStringLiteral("license"));
281 }
282 
283 QString Attica::Content::previewPicture(const QString &number) const
284 {
285  return attribute(QLatin1String("previewpic") + number);
286 }
287 
288 QString 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:31
void setUpdated(const QDateTime &updated)
Sets the time the Content has been last updated.
Definition: content.cpp:119
void setNumberOfComments(int numComments)
Sets the number of comments for the Content.
Definition: content.cpp:99
Content()
Creates an empty Content.
Definition: content.cpp:39
~Content()
Destructor.
Definition: content.cpp:55
void setVideos(QList< QUrl > videos)
Set list of videos.
Definition: content.cpp:313
QString summary() const
A summary description of this content.
Definition: content.cpp:149
int size() const const
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
The HomePageEntry class contains information about one home page entry.
Definition: homepageentry.h:24
void setId(const QString &id)
Sets the id of the Content.
Definition: content.cpp:59
void clear()
int downloads() const
Gets the number of downloads for the Content (how often this has been downloaded from the server)...
Definition: content.cpp:94
QString number(int n, int base)
void append(const T &value)
QList< QUrl > videos()
Get all videos for this content.
Definition: content.cpp:308
int numberOfComments() const
Gets the number of comments for the Content.
Definition: content.cpp:104
QStringList tags() const
Get all the tags for this content.
Definition: content.cpp:318
Content & operator=(const Content &other)
Assignment operator.
Definition: content.cpp:49
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const const
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
bool isValid() const
Checks whether this Content has an id.
Definition: content.cpp:144
QStringRef rightRef(int n) const const
QString id() const
Gets the id of the Content.
Definition: content.cpp:64
QDateTime updated() const
Gets the date and time the Content has been last updated.
Definition: content.cpp:124
QDateTime created() const
Gets the date and time the Content has been created.
Definition: content.cpp:114
void setCreated(const QDateTime &created)
Sets the date and time the Content has been created.
Definition: content.cpp:109
QString description() const
A description of this content.
Definition: content.cpp:154
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
const Key key(const T &value, const Key &defaultKey) const const
QList< Icon > icons()
Get all icons for this content.
Definition: content.cpp:293
QString name() const
Gets the name of the Content.
Definition: content.cpp:74
void setIcons(QList< Icon > icons)
Set list of icons.
Definition: content.cpp:303
QUrl detailpage() const
A webpage with the detailed description of this content.
Definition: content.cpp:159
void setName(const QString &name)
Sets the name of the Content.
Definition: content.cpp:69
void setTags(const QStringList &tags)
Set the list of tags.
Definition: content.cpp:323
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
void setDownloads(int downloads)
Sets the number of downloads for the Content.
Definition: content.cpp:89
void setRating(int rating)
Sets the rating of the Content.
Definition: content.cpp:79
int rating() const
Gets the rating of the Content.
Definition: content.cpp:84
QList< DownloadDescription > downloadUrlDescriptions() const
Get all possible downloads.
Definition: content.cpp:175
QList< HomePageEntry > homePageEntries()
Get all home pages for this content.
Definition: content.cpp:227
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
const T value(const Key &key, const T &defaultValue) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Mon Jan 25 2021 23:06:24 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.