16#include <QXmlStreamReader>
17#include <knewstuffcore_debug.h>
19#include "xmlloader_p.h"
21using namespace KNSCore;
24 : d(new EntryPrivate())
41 return d->mUniqueId < other.d->mUniqueId;
46 return d->mUniqueId == other.d->mUniqueId && d->mProviderId == other.d->mProviderId;
51bool Entry::isValid()
const
53 return !d->mUniqueId.isEmpty();
68 return d->mUniqueId.isEmpty() ? d->mRequestedUniqueId : d->mUniqueId;
78 return d->mProviderId;
81void Entry::setProviderId(
const QString &
id)
143 d->mSummary = summary;
148 return d->mShortSummary;
153 d->mShortSummary = summary;
158 d->mChangelog = changelog;
161QString Entry::changelog()
const
163 return d->mChangelog;
178 return d->mReleaseDate;
183 d->mReleaseDate = releasedate;
198 return d->mUpdateReleaseDate;
203 d->mUpdateReleaseDate = releasedate;
208 return d->mUpdateVersion;
218 return d->mPreviewUrl[type];
223 d->mPreviewUrl[type] = url;
228 return d->mPreviewImage[type];
231void Entry::setPreviewImage(
const QImage &image, PreviewType type)
233 d->mPreviewImage[type] = image;
236int Entry::rating()
const
246int Entry::numberOfComments()
const
248 return d->mNumberOfComments;
253 d->mNumberOfComments = comments;
256int Entry::downloadCount()
const
258 return d->mDownloadCount;
263 d->mDownloadCount = downloads;
268 return d->mNumberFans;
273 d->mNumberFans = fans;
278 return d->mDonationLink;
283 d->mDonationLink = link;
288 return d->mNumberKnowledgebaseEntries;
292 d->mNumberKnowledgebaseEntries = num;
297 return d->mKnowledgebaseLink;
301 d->mKnowledgebaseLink = link;
311 d->mEntryType = type;
316 return d->mEntryType;
336 d->mInstalledFiles = files;
341 return d->mInstalledFiles;
346 return d->mUnInstalledFiles;
351 return d->mDownloadLinkInformationList.size();
356 const auto infos = d->mDownloadLinkInformationList;
359 for (
const auto &info : infos) {
360 ret.
append({.name = info.name,
361 .priceAmount = info.priceAmount,
362 .distributionType = info.distributionType,
363 .descriptionLink = info.descriptionLink,
365 .isDownloadtypeLink = info.isDownloadtypeLink,
374 d->mDownloadLinkInformationList.
append({.name = info.name,
375 .priceAmount = info.priceAmount,
376 .distributionType = info.distributionType,
377 .descriptionLink = info.descriptionLink,
379 .isDownloadtypeLink = info.isDownloadtypeLink,
387 d->mDownloadLinkInformationList.clear();
402 const auto token = readNextSkipComments(xml);
415 readNextSkipComments(xml);
424 int ret = readText(xml).
toInt();
434 qCWarning(KNEWSTUFFCORE) <<
"Parsing Entry from invalid XML. Reader tag name was expected to be \"stuff\", but was found as:" << reader.
name();
440 while (!reader.
atEnd()) {
441 const auto token = readNextSkipComments(&reader);
456 const auto homepage = reader.
attributes().
value(QStringLiteral(
"homepage"));
457 d->mAuthor.setEmail(email.toString());
458 d->mAuthor.setJabber(jabber.toString());
459 d->mAuthor.setHomepage(homepage.toString());
460 d->mAuthor.setName(readStringTrimmed(&reader));
466 d->mLicense = readStringTrimmed(&reader);
472 d->mVersion = readStringTrimmed(&reader);
477 d->mPreviewUrl[PreviewSmall1] = readStringTrimmed(&reader);
479 d->mPreviewUrl[PreviewBig1] = readStringTrimmed(&reader);
481 d->mPayload = readStringTrimmed(&reader);
483 d->mRating = readInt(&reader);
485 d->mDownloadCount = readInt(&reader);
499 const auto statusText = readText(&reader);
501 qCDebug(KNEWSTUFFCORE) <<
"Found an installed entry in registry";
502 d->mStatus = KNSCore::Entry::Installed;
504 d->mStatus = KNSCore::Entry::Updateable;
507 readNextSkipComments(&reader);
512 QStringLiteral(
"token name was %1 and the type was %2").arg(reader.
name().
toString(), reader.
tokenString()).toLocal8Bit().data());
516 if (d->mName.isEmpty()) {
517 qWarning() <<
"Entry: no name given";
521 if (d->mUniqueId.isEmpty()) {
522 if (!d->mPayload.isEmpty()) {
523 d->mUniqueId = d->mPayload;
525 d->mUniqueId = d->mName;
529 if (d->mPayload.isEmpty()) {
530 qWarning() <<
"Entry: no payload URL given for: " << d->mName <<
" - " << d->mUniqueId;
539 qWarning() <<
"Parsing Entry from invalid XML";
543 d->mCategory = xmldata.
attribute(QStringLiteral(
"category"));
556 d->mAuthor.setEmail(email);
557 d->mAuthor.setJabber(jabber);
558 d->mAuthor.setHomepage(homepage);
560 d->mProviderId = e.
text();
566 d->mSummary = e.
text();
568 d->mChangelog = e.
text();
575 d->mPreviewUrl[PreviewSmall1] = e.
text().
trimmed();
585 d->mCategory = e.
text();
587 d->mSignature = e.
text();
589 d->mChecksum = e.
text();
593 d->mInstalledFiles.append(e.
text());
595 d->mUniqueId = e.
text();
601 qCDebug(KNEWSTUFFCORE) <<
"Found an installed entry in registry";
602 d->mStatus = KNSCore::Entry::Installed;
604 d->mStatus = KNSCore::Entry::Updateable;
610 if (d->mName.isEmpty()) {
611 qWarning() <<
"Entry: no name given";
615 if (d->mUniqueId.isEmpty()) {
616 if (!d->mPayload.isEmpty()) {
617 d->mUniqueId = d->mPayload;
619 d->mUniqueId = d->mName;
623 if (d->mPayload.isEmpty()) {
624 qWarning() <<
"Entry: no payload URL given for: " << d->mName <<
" - " << d->mUniqueId;
635 Q_ASSERT(!d->mUniqueId.isEmpty());
636 Q_ASSERT(!d->mProviderId.isEmpty());
641 el.
setAttribute(QStringLiteral(
"category"), d->mCategory);
646 e = addElement(doc, el, QStringLiteral(
"name"), name);
648 (void)addElement(doc, el, QStringLiteral(
"providerid"), d->mProviderId);
650 QDomElement author = addElement(doc, el, QStringLiteral(
"author"), d->mAuthor.name());
651 if (!d->mAuthor.email().isEmpty()) {
652 author.
setAttribute(QStringLiteral(
"email"), d->mAuthor.email());
654 if (!d->mAuthor.homepage().isEmpty()) {
655 author.
setAttribute(QStringLiteral(
"homepage"), d->mAuthor.homepage());
657 if (!d->mAuthor.jabber().isEmpty()) {
658 author.
setAttribute(QStringLiteral(
"im"), d->mAuthor.jabber());
661 addElement(doc, el, QStringLiteral(
"homepage"), d->mHomepage.url());
662 (void)addElement(doc, el, QStringLiteral(
"licence"), d->mLicense);
663 (void)addElement(doc, el, QStringLiteral(
"version"), d->mVersion);
664 if ((d->mRating > 0) || (d->mDownloadCount > 0)) {
665 (void)addElement(doc, el, QStringLiteral(
"rating"),
QString::number(d->mRating));
666 (void)addElement(doc, el, QStringLiteral(
"downloads"),
QString::number(d->mDownloadCount));
668 if (!d->mSignature.isEmpty()) {
669 (void)addElement(doc, el, QStringLiteral(
"signature"), d->mSignature);
671 if (!d->mChecksum.isEmpty()) {
672 (void)addElement(doc, el, QStringLiteral(
"checksum"), d->mChecksum);
674 for (
const QString &file : std::as_const(d->mInstalledFiles)) {
675 (void)addElement(doc, el, QStringLiteral(
"installedfile"), file);
677 if (!d->mUniqueId.isEmpty()) {
678 addElement(doc, el, QStringLiteral(
"id"), d->mUniqueId);
681 (void)addElement(doc, el, QStringLiteral(
"releasedate"), d->mReleaseDate.toString(
Qt::ISODate));
683 e = addElement(doc, el, QStringLiteral(
"summary"), d->mSummary);
684 e = addElement(doc, el, QStringLiteral(
"changelog"), d->mChangelog);
685 e = addElement(doc, el, QStringLiteral(
"preview"), d->mPreviewUrl[PreviewSmall1]);
686 e = addElement(doc, el, QStringLiteral(
"previewBig"), d->mPreviewUrl[PreviewBig1]);
687 e = addElement(doc, el, QStringLiteral(
"payload"), d->mPayload);
688 e = addElement(doc, el, QStringLiteral(
"tags"), d->mTags.join(
QLatin1Char(
',')));
690 if (d->mStatus == KNSCore::Entry::Installed) {
691 (void)addElement(doc, el, QStringLiteral(
"status"), QStringLiteral(
"installed"));
693 if (d->mStatus == KNSCore::Entry::Updateable) {
694 (void)addElement(doc, el, QStringLiteral(
"status"), QStringLiteral(
"updateable"));
702 setStatus(Entry::Deleted);
703 d->mUnInstalledFiles = installedFiles();
707void KNSCore::Entry::setEntryRequestedId(
const QString &
id)
709 d->mRequestedUniqueId = id;
724 text.remove(QStringLiteral(
"[/li]"));
725 text.remove(QStringLiteral(
"[url]"));
726 text.remove(QStringLiteral(
"[/url]"));
735 bool deleted = entry.status() == Entry::Status::Deleted;
737 debug.
nospace() <<
"KNSCore::Entry(uniqueId: " << entry.uniqueId() <<
", name:" << entry.name() <<
", status: " << metaEnum.
valueToKey(entry.status())
738 <<
", " << (deleted ?
"uninstalled" :
"installed") <<
"Files: "
743#include "moc_entry.cpp"
KNewStuff author information.
KNewStuff data entry container.
void setInstalledFiles(const QStringList &files)
Set the files that have been installed by the install command.
void setRating(int rating)
Sets the rating between 0 (worst) and 100 (best).
void setLicense(const QString &license)
Sets the license (abbreviation) applicable to the object.
bool setEntryXML(QXmlStreamReader &reader)
set the xml for the entry parses the xml and sets the private members accordingly used to deserialize...
QDate releaseDate() const
Retrieve the date of the object's publication.
void setPayload(const QString &url)
Sets the object's file.
QList< DownloadLinkInformation > downloadLinkInformationList() const
A list of downloadable data for this entry.
void setHomepage(const QUrl &page)
Set a link to a website containing information about this entry.
void setChangelog(const QString &changelog)
The user written changelog.
QString updateVersion() const
Retrieve the version string of the object that is available as update.
QString knowledgebaseLink() const
The link for the knowledgebase for this entry.
QStringList installedFiles() const
Retrieve the locally installed files.
QString payload() const
Retrieve the file name of the object.
QImage previewImage(PreviewType type=PreviewSmall1) const
This will not be loaded automatically, instead use Engine to load the actual images.
EntryType
Represents whether the current entry is an actual catalog entry, or an entry that represents a set of...
void setVersion(const QString &version)
Sets the version number.
void setSummary(const QString &summary)
Sets a description (which can potentially be very long)
void setShortSummary(const QString &summary)
Sets a short description of what the object is all about (should be very short)
void setStatus(KNSCore::Entry::Status status)
Sets the entry's status.
void setUpdateVersion(const QString &version)
Sets the version number that is available as update.
QString category() const
Retrieve the category of the data object.
QDate updateReleaseDate() const
Retrieve the date of the newer version that is available as update.
QString previewUrl(PreviewType type=PreviewSmall1) const
Retrieve the file name of an image containing a preview of the object.
Status
Status of the entry.
int downloadLinkCount() const
The number of available download options for this entry.
void setEntryType(EntryType type)
The entry type is either catalog entry, or group entry.
void setReleaseDate(const QDate &releasedate)
Sets the release date.
void setName(const QString &name)
Sets the name for this data object.
void setUpdateReleaseDate(const QDate &releasedate)
Sets the release date that is available as update.
void setCategory(const QString &category)
Sets the data category, e.g.
void setAuthor(const Author &author)
Sets the author of the object.
void setSource(Source source)
The source of this entry can be Cache, Registry or Online -.
int numberKnowledgebaseEntries() const
The number of entries in the knowledgebase for this entry.
QStringList tags() const
The set of tags assigned specifically to this content item.
QString version() const
Retrieve the version string of the object.
void appendDownloadLinkInformation(const DownloadLinkInformation &info)
Add a new download option to this entry.
void setNumberOfComments(int comments)
Sets the number of comments in the asset.
void setNumberKnowledgebaseEntries(int num)
Set the number of knowledgebase entries for this entry.
void clearDownloadLinkInformation()
Remove all download options from this entry.
void setNumberFans(int fans)
Sets how many people are fans.
void setKnowledgebaseLink(const QString &link)
Set the link for the knowledgebase.
void setTags(const QStringList &tags)
Set the tags for the content item.
Source
Source of the entry, A entry's data is coming from either cache, or an online provider this helps the...
void setDownloadCount(int downloads)
Sets the number of downloads.
QStringList uninstalledFiles() const
Retrieve the locally uninstalled files.
void setUniqueId(const QString &id)
Set the object's unique ID.
void setPreviewUrl(const QString &url, PreviewType type=PreviewSmall1)
Sets the object's preview file, if available.
int numberFans() const
How many people have marked themselves as fans of this entry.
QString license() const
Retrieve the license name of the object.
void setDonationLink(const QString &link)
Set a string representation of the URL for the donation website for this entry.
Q_SCRIPTABLE CaptureState status()
QString name(GameStandardAction id)
QDate fromString(QStringView string, QStringView format, QCalendar cal)
QDomElement createElement(const QString &tagName)
QString attribute(const QString &name, const QString &defValue) const const
void setAttribute(const QString &name, const QString &value)
QString tagName() const const
QString text() const const
QDomNode firstChild() const const
bool isNull() const const
QDomNode nextSibling() const const
QDomElement toElement() const const
void append(QList< T > &&value)
void reserve(qsizetype size)
QString number(double n, char format, int precision)
QStringList split(QChar sep, Qt::SplitBehavior behavior, Qt::CaseSensitivity cs) const const
int toInt(bool *ok, int base) const const
QString trimmed() const const
bool isEmpty() const const
QString toString() const const
QStringView trimmed() const const
QStringView value(QAnyStringView namespaceUri, QAnyStringView name) const const
QXmlStreamAttributes attributes() const const
QStringView name() const const
QString readElementText(ReadElementTextBehaviour behaviour)
QStringView text() const const
QString tokenString() const const
TokenType tokenType() const const