• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.10.2 API Reference
  • KDE Home
  • Contact Us
 

KNewStuff

  • knewstuff
  • knewstuff3
  • core
entryinternal.cpp
Go to the documentation of this file.
1 /*
2  This file is part of KNewStuff2.
3  Copyright (c) 2002 Cornelius Schumacher <schumacher@kde.org>
4  Copyright (c) 2003 - 2007 Josef Spillner <spillner@kde.org>
5  Copyright (C) 2009 Frederik Gladhorn <gladhorn@kde.org>
6 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Lesser General Public
9  License as published by the Free Software Foundation; either
10  version 2.1 of the License, or (at your option) any later version.
11 
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Lesser General Public License for more details.
16 
17  You should have received a copy of the GNU Lesser General Public
18  License along with this library. If not, see <http://www.gnu.org/licenses/>.
19 */
20 
21 #include "entryinternal.h"
22 
23 #include <QtCore/QStringList>
24 #include <QtGui/QImage>
25 #include <kdebug.h>
26 
27 #include "core/xmlloader.h"
28 
29 #include <knewstuff3/entry_p.h>
30 
31 
32 using namespace KNS3;
33 
34 class EntryInternal::Private : public QSharedData
35 {
36  public:
37  Private()
38  : mReleaseDate(QDate::currentDate())
39  , mRating(0)
40  , mDownloadCount(0)
41  , mNumberFans(0)
42  , mNumberKnowledgebaseEntries(0)
43  , mStatus(Entry::Invalid)
44  , mSource(EntryInternal::Online)
45  {}
46 
47  bool operator==(const Private& other) const
48  {
49  return mUniqueId == other.mUniqueId && mProviderId == other.mProviderId;
50  }
51 
52  QString mUniqueId;
53  QString mName;
54  KUrl mHomepage;
55  QString mCategory;
56  QString mLicense;
57  QString mVersion;
58  QDate mReleaseDate;
59 
60  // Version and date if a newer version is found (updateable)
61  QString mUpdateVersion;
62  QDate mUpdateReleaseDate;
63 
64  Author mAuthor;
65  int mRating;
66  int mDownloadCount;
67  int mNumberFans;
68  int mNumberKnowledgebaseEntries;
69  QString mKnowledgebaseLink;
70  QString mSummary;
71  QString mChangelog;
72  QString mPayload;
73  QStringList mInstalledFiles;
74  QString mProviderId;
75  QStringList mUnInstalledFiles;
76  QString mDonationLink;
77 
78  QString mChecksum;
79  QString mSignature;
80  Entry::Status mStatus;
81  EntryInternal::Source mSource;
82 
83  QString mPreviewUrl[6];
84  QImage mPreviewImage[6];
85 
86  QList<EntryInternal::DownloadLinkInformation> mDownloadLinkInformationList;
87 };
88 
89 EntryInternal::EntryInternal()
90  : d(new Private)
91 {
92 }
93 
94 EntryInternal::EntryInternal(const EntryInternal& other)
95  : d(other.d)
96 {
97 }
98 
99 EntryInternal& EntryInternal::operator=(const EntryInternal& other)
100 {
101  d = other.d;
102  return *this;
103 }
104 
105 bool EntryInternal::operator<(const KNS3::EntryInternal& other) const
106 {
107  return d->mUniqueId < other.d->mUniqueId;
108 }
109 
110 bool EntryInternal::operator==(const KNS3::EntryInternal& other) const
111 {
112  return d->mUniqueId == other.d->mUniqueId && d->mProviderId == other.d->mProviderId;
113 }
114 
115 EntryInternal::~EntryInternal()
116 {
117 }
118 
119 bool EntryInternal::isValid() const
120 {
121  return !d->mUniqueId.isEmpty();
122 }
123 
124 QString EntryInternal::name() const
125 {
126  return d->mName;
127 }
128 
129 void EntryInternal::setName(const QString& name)
130 {
131  d->mName = name;
132 }
133 
134 QString EntryInternal::uniqueId() const
135 {
136  return d->mUniqueId;
137 }
138 
139 void EntryInternal::setUniqueId(const QString& id)
140 {
141  d->mUniqueId = id;
142 }
143 
144 QString EntryInternal::providerId() const
145 {
146  return d->mProviderId;
147 }
148 
149 void EntryInternal::setProviderId(const QString& id)
150 {
151  d->mProviderId = id;
152 }
153 
154 QString EntryInternal::category() const
155 {
156  return d->mCategory;
157 }
158 
159 void EntryInternal::setCategory(const QString& category)
160 {
161  d->mCategory = category;
162 }
163 
164 KUrl EntryInternal::homepage() const
165 {
166  return d->mHomepage;
167 }
168 
169 void EntryInternal::setHomepage(const KUrl& page)
170 {
171  d->mHomepage = page;
172 }
173 
174 Author EntryInternal::author() const
175 {
176  return d->mAuthor;
177 }
178 
179 void EntryInternal::setAuthor(const KNS3::Author& author)
180 {
181  d->mAuthor = author;
182 }
183 
184 QString EntryInternal::license() const
185 {
186  return d->mLicense;
187 }
188 
189 void EntryInternal::setLicense(const QString& license)
190 {
191  d->mLicense = license;
192 }
193 
194 QString EntryInternal::summary() const
195 {
196  return d->mSummary;
197 }
198 
199 void EntryInternal::setSummary(const QString& summary)
200 {
201  d->mSummary = summary;
202 }
203 
204 void EntryInternal::setChangelog(const QString& changelog)
205 {
206  d->mChangelog = changelog;
207 }
208 
209 QString EntryInternal::changelog() const
210 {
211  return d->mChangelog;
212 }
213 
214 QString EntryInternal::version() const
215 {
216  return d->mVersion;
217 }
218 
219 void EntryInternal::setVersion(const QString& version)
220 {
221  d->mVersion = version;
222 }
223 
224 QDate EntryInternal::releaseDate() const
225 {
226  return d->mReleaseDate;
227 }
228 
229 void EntryInternal::setReleaseDate(const QDate& releasedate)
230 {
231  d->mReleaseDate = releasedate;
232 }
233 
234 QString EntryInternal::payload() const
235 {
236  return d->mPayload;
237 }
238 
239 void EntryInternal::setPayload(const QString& url)
240 {
241  d->mPayload = url;
242 }
243 
244 QDate EntryInternal::updateReleaseDate() const
245 {
246  return d->mUpdateReleaseDate;
247 }
248 
249 void EntryInternal::setUpdateReleaseDate(const QDate& releasedate)
250 {
251  d->mUpdateReleaseDate = releasedate;
252 }
253 
254 QString EntryInternal::updateVersion() const
255 {
256  return d->mUpdateVersion;
257 }
258 
259 void EntryInternal::setUpdateVersion(const QString& version)
260 {
261  d->mUpdateVersion = version;
262 }
263 
264 QString EntryInternal::previewUrl(PreviewType type) const
265 {
266  return d->mPreviewUrl[type];
267 }
268 
269 void EntryInternal::setPreviewUrl(const QString& url, PreviewType type)
270 {
271  d->mPreviewUrl[type] = url;
272 }
273 
274 QImage EntryInternal::previewImage(PreviewType type) const
275 {
276  return d->mPreviewImage[type];
277 }
278 
279 void EntryInternal::setPreviewImage(const QImage& image, PreviewType type)
280 {
281  d->mPreviewImage[type] = image;
282 }
283 
284 int EntryInternal::rating() const
285 {
286  return d->mRating;
287 }
288 
289 void EntryInternal::setRating(int rating)
290 {
291  d->mRating = rating;
292 }
293 
294 int EntryInternal::downloadCount() const
295 {
296  return d->mDownloadCount;
297 }
298 
299 void EntryInternal::setDownloadCount(int downloads)
300 {
301  d->mDownloadCount = downloads;
302 }
303 
304 int EntryInternal::numberFans() const
305 {
306  return d->mNumberFans;
307 }
308 
309 void EntryInternal::setNumberFans(int fans)
310 {
311  d->mNumberFans = fans;
312 }
313 
314 QString EntryInternal::donationLink() const
315 {
316  return d->mDonationLink;
317 }
318 
319 void EntryInternal::setDonationLink(const QString& link)
320 {
321  d->mDonationLink = link;
322 }
323 
324 int EntryInternal::numberKnowledgebaseEntries() const
325 {
326  return d->mNumberKnowledgebaseEntries;
327 }
328 void EntryInternal::setNumberKnowledgebaseEntries(int num)
329 {
330  d->mNumberKnowledgebaseEntries = num;
331 }
332 
333 QString EntryInternal::knowledgebaseLink() const
334 {
335  return d->mKnowledgebaseLink;
336 }
337 void EntryInternal::setKnowledgebaseLink(const QString& link)
338 {
339  d->mKnowledgebaseLink = link;
340 }
341 
342 
343 /*
344 QString EntryInternal::checksum() const
345 {
346 
347  return d->mChecksum;
348 }
349 
350 QString EntryInternal::signature() const
351 {
352 
353  return d->mSignature;
354 }
355 */
356 
357 EntryInternal::Source EntryInternal::source() const
358 {
359  return d->mSource;
360 }
361 
362 void EntryInternal::setSource(Source source)
363 {
364  d->mSource = source;
365 }
366 
367 Entry::Status EntryInternal::status() const
368 {
369  return d->mStatus;
370 }
371 
372 void EntryInternal::setStatus(Entry::Status status)
373 {
374  d->mStatus = status;
375 }
376 
377 void KNS3::EntryInternal::setInstalledFiles(const QStringList & files)
378 {
379  d->mInstalledFiles = files;
380 }
381 
382 QStringList KNS3::EntryInternal::installedFiles() const
383 {
384  return d->mInstalledFiles;
385 }
386 
387 void KNS3::EntryInternal::setUnInstalledFiles(const QStringList & files)
388 {
389  d->mUnInstalledFiles = files;
390 }
391 
392 QStringList KNS3::EntryInternal::uninstalledFiles() const
393 {
394  return d->mUnInstalledFiles;
395 }
396 
397 int KNS3::EntryInternal::downloadLinkCount() const
398 {
399  return d->mDownloadLinkInformationList.size();
400 }
401 
402 QList<KNS3::EntryInternal::DownloadLinkInformation> KNS3::EntryInternal::downloadLinkInformationList() const
403 {
404  return d->mDownloadLinkInformationList;
405 }
406 
407 void KNS3::EntryInternal::appendDownloadLinkInformation(const KNS3::EntryInternal::DownloadLinkInformation& info)
408 {
409  d->mDownloadLinkInformationList.append(info);
410 }
411 
412 void EntryInternal::clearDownloadLinkInformation()
413 {
414  d->mDownloadLinkInformationList.clear();
415 }
416 
417 bool KNS3::EntryInternal::setEntryXML(const QDomElement & xmldata)
418 {
419  if (xmldata.tagName() != "stuff") {
420  kWarning() << "Parsing Entry from invalid XML";
421  return false;
422  }
423 
424  d->mCategory = xmldata.attribute("category");
425 
426  QDomNode n;
427  for (n = xmldata.firstChild(); !n.isNull(); n = n.nextSibling()) {
428  QDomElement e = n.toElement();
429  if (e.tagName() == "name") {
430  // TODO maybe do something with the language attribute? QString lang = e.attribute("lang");
431  d->mName = e.text().trimmed();
432  } else if (e.tagName() == "author") {
433  QString email = e.attribute("email");
434  QString jabber = e.attribute("im");
435  QString homepage = e.attribute("homepage");
436  d->mAuthor.setName(e.text().trimmed());
437  d->mAuthor.setEmail(email);
438  d->mAuthor.setJabber(jabber);
439  d->mAuthor.setHomepage(homepage);
440  } else if (e.tagName() == "providerid") {
441  d->mProviderId = e.text();
442  } else if (e.tagName() == "homepage") {
443  d->mHomepage = e.text();
444  } else if (e.tagName() == "licence") { // krazy:exclude=spelling
445  d->mLicense = e.text().trimmed();
446  } else if (e.tagName() == "summary") {
447  d->mSummary = e.text();
448  } else if (e.tagName() == "changelog") {
449  d->mChangelog = e.text();
450  } else if (e.tagName() == "version") {
451  d->mVersion = e.text().trimmed();
452  } else if (e.tagName() == "releasedate") {
453  d->mReleaseDate = QDate::fromString(e.text().trimmed(), Qt::ISODate);
454  } else if (e.tagName() == "preview") {
455  // TODO support for all 6 image links
456  d->mPreviewUrl[PreviewSmall1] = e.text().trimmed();
457  } else if (e.tagName() == "previewBig") {
458  d->mPreviewUrl[PreviewBig1] = e.text().trimmed();
459  } else if (e.tagName() == "payload") {
460  d->mPayload = e.text().trimmed();
461  } else if (e.tagName() == "rating") {
462  d->mRating = e.text().toInt();
463  } else if (e.tagName() == "downloads") {
464  d->mDownloadCount = e.text().toInt();
465  } else if (e.tagName() == "category") {
466  d->mCategory = e.text();
467  } else if (e.tagName() == "signature") {
468  d->mSignature = e.text();
469  } else if (e.tagName() == "checksum") {
470  d->mChecksum = e.text();
471  } else if (e.tagName() == "installedfile") {
472  d->mInstalledFiles.append(e.text());
473  } else if (e.tagName() == "id") {
474  d->mUniqueId = e.text();
475  } else if (e.tagName() == "status") {
476  QString statusText = e.text();
477  if (statusText == "installed") {
478  kDebug() << "Found an installed entry in registry";
479  d->mStatus = Entry::Installed;
480  } else if (statusText == "updateable") {
481  d->mStatus = Entry::Updateable;
482  }
483  }
484  }
485 
486  // Validation
487  if (d->mName.isEmpty()) {
488  kWarning(550) << "Entry: no name given";
489  return false;
490  }
491 
492  if (d->mUniqueId.isEmpty()) {
493  if (!d->mPayload.isEmpty()) {
494  d->mUniqueId = d->mPayload;
495  } else {
496  d->mUniqueId = d->mName;
497  }
498  }
499 
500  if (d->mPayload.isEmpty()) {
501  kWarning(550) << "Entry: no payload URL given for: " << d->mName << " - " << d->mUniqueId;
502  return false;
503  }
504  return true;
505 }
506 
510 QDomElement KNS3::EntryInternal::entryXML() const
511 {
512  Q_ASSERT(!d->mUniqueId.isEmpty());
513  Q_ASSERT(!d->mProviderId.isEmpty());
514 
515  QDomDocument doc;
516 
517  QDomElement el = doc.createElement("stuff");
518  el.setAttribute("category", d->mCategory);
519 
520  QString name = d->mName;
521 
522  QDomElement e;
523  e = addElement(doc, el, "name", name);
524  // todo: add language attribute
525  (void)addElement(doc, el, "providerid", d->mProviderId);
526 
527  QDomElement author = addElement(doc, el, "author", d->mAuthor.name());
528  if (!d->mAuthor.email().isEmpty())
529  author.setAttribute("email", d->mAuthor.email());
530  if (!d->mAuthor.homepage().isEmpty())
531  author.setAttribute("homepage", d->mAuthor.homepage());
532  if (!d->mAuthor.jabber().isEmpty())
533  author.setAttribute("im", d->mAuthor.jabber());
534  // FIXME: 'jabber' or 'im'? consult with kopete guys...
535  addElement(doc, el, "homepage", d->mHomepage.url());
536  (void)addElement(doc, el, "licence", d->mLicense); // krazy:exclude=spelling
537  (void)addElement(doc, el, "version", d->mVersion);
538  if ((d->mRating > 0) || (d->mDownloadCount > 0)) {
539  (void)addElement(doc, el, "rating", QString::number(d->mRating));
540  (void)addElement(doc, el, "downloads", QString::number(d->mDownloadCount));
541  }
542  if (!d->mSignature.isEmpty()) {
543  (void)addElement(doc, el, "signature", d->mSignature);
544  }
545  if (!d->mChecksum.isEmpty()) {
546  (void)addElement(doc, el, "checksum", d->mChecksum);
547  }
548  foreach(const QString &file, d->mInstalledFiles) {
549  (void)addElement(doc, el, "installedfile", file);
550  }
551  if (!d->mUniqueId.isEmpty()) {
552  addElement(doc, el, "id", d->mUniqueId);
553  }
554 
555  (void)addElement(doc, el, "releasedate",
556  d->mReleaseDate.toString(Qt::ISODate));
557 
558  e = addElement(doc, el, "summary", d->mSummary);
559  e = addElement(doc, el, "changelog", d->mChangelog);
560  e = addElement(doc, el, "preview", d->mPreviewUrl[PreviewSmall1]);
561  e = addElement(doc, el, "previewBig", d->mPreviewUrl[PreviewBig1]);
562  e = addElement(doc, el, "payload", d->mPayload);
563 
564  if (d->mStatus == Entry::Installed) {
565  (void)addElement(doc, el, "status", "installed");
566  }
567  if (d->mStatus == Entry::Updateable) {
568  (void)addElement(doc, el, "status", "updateable");
569  }
570 
571  return el;
572 }
573 
574 Entry EntryInternal::toEntry() const
575 {
576  Entry e;
577  e.d->e = *this;
578  return e;
579 }
580 
581 KNS3::EntryInternal EntryInternal::fromEntry(const KNS3::Entry& entry)
582 {
583  return entry.d->e;
584 }
585 
586 QString KNS3::replaceBBCode(const QString& unformattedText)
587 {
588  QString text(unformattedText);
589  text.replace("[b]", "<b>");
590  text.replace("[/b]", "</b>");
591  text.replace("[i]", "<i>");
592  text.replace("[/i]", "</i>");
593  text.replace("[u]", "<i>");
594  text.replace("[/u]", "</i>");
595  text.replace("\\\"", "\"");
596  text.replace("\\\'", "\'");
597  text.replace("[li]", "* "); // TODO: better replacement for list elements?
598  text.remove("[/li]");
599  text.remove("[url]");
600  text.remove("[/url]");
601  return text;
602 }
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Sat Apr 20 2013 06:04:28 by doxygen 1.8.3.1 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KNewStuff

Skip menu "KNewStuff"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdelibs-4.10.2 API Reference

Skip menu "kdelibs-4.10.2 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal