File indexing completed on 2024-04-21 03:56:23

0001 /*
0002     knewstuff3/entry.h.
0003     SPDX-FileCopyrightText: 2002 Cornelius Schumacher <schumacher@kde.org>
0004     SPDX-FileCopyrightText: 2003-2007 Josef Spillner <spillner@kde.org>
0005     SPDX-FileCopyrightText: 2009 Jeremy Whiting <jpwhiting@kde.org>
0006     SPDX-FileCopyrightText: 2009 Frederik Gladhorn <gladhorn@kde.org>
0007 
0008     SPDX-License-Identifier: LGPL-2.1-or-later
0009 */
0010 
0011 #ifndef KNEWSTUFF3_ENTRY
0012 #define KNEWSTUFF3_ENTRY
0013 
0014 #include <QDate>
0015 #include <QImage>
0016 #include <QString>
0017 #include <QUrl>
0018 
0019 #include "author.h"
0020 #include "knewstuffcore_export.h"
0021 
0022 class testEntry;
0023 class QDomElement;
0024 class QXmlStreamReader;
0025 
0026 namespace KNSCore
0027 {
0028 static const int PreviewWidth = 96;
0029 static const int PreviewHeight = 72;
0030 class EntryPrivate;
0031 
0032 /**
0033  function to remove bb code formatting that opendesktop sends
0034  */
0035 KNEWSTUFFCORE_EXPORT QString replaceBBCode(const QString &unformattedText);
0036 
0037 /**
0038  * @short KNewStuff data entry container.
0039  *
0040  * This class provides accessor methods to the data objects
0041  * as used by KNewStuff.
0042  *
0043  * @author Cornelius Schumacher (schumacher@kde.org)
0044  * \par Maintainer:
0045  * Jeremy Whiting (jpwhiting@kde.org)
0046  */
0047 class KNEWSTUFFCORE_EXPORT Entry
0048 {
0049     Q_GADGET
0050 public:
0051     typedef QList<Entry> List;
0052     Q_PROPERTY(QString providerId READ providerId)
0053     Q_PROPERTY(QString uniqueId READ uniqueId)
0054     Q_PROPERTY(KNSCore::Entry::Status status READ status)
0055     Q_PROPERTY(KNSCore::Entry::EntryType entryType READ entryType)
0056 
0057     Q_PROPERTY(QString name READ name)
0058     Q_PROPERTY(KNSCore::Author author READ author)
0059     Q_PROPERTY(QString shortSummary READ shortSummary)
0060     Q_PROPERTY(QString summary READ summary)
0061     // TODO  Q_PROPERTY(QString previews READ previews)
0062     Q_PROPERTY(QUrl homepage READ homepage)
0063     Q_PROPERTY(QString donationLink READ donationLink)
0064     Q_PROPERTY(int numberOfComments READ numberOfComments)
0065     Q_PROPERTY(int rating READ rating)
0066     Q_PROPERTY(int downloadCount READ downloadCount)
0067     Q_PROPERTY(QList<KNSCore::Entry::DownloadLinkInformation> downloadLinks READ downloadLinkInformationList)
0068 
0069     /**
0070      * Status of the entry. An entry will be downloadable from the provider's
0071      * site prior to the download. Once downloaded and installed, it will
0072      * be either installed or updateable, implying an out-of-date
0073      * installation. Finally, the entry can be deleted and hence show up as
0074      * downloadable again.
0075      * Entries not taking part in this cycle, for example those in upload,
0076      * have an invalid status.
0077      */
0078     enum Status {
0079         Invalid,
0080         Downloadable,
0081         Installed,
0082         Updateable,
0083         Deleted,
0084         Installing,
0085         Updating,
0086     };
0087     Q_ENUM(Status)
0088 
0089     /**
0090      * Source of the entry, A entry's data is coming from either cache, or an online provider
0091      * this helps the engine know which data to use when merging cached entries with online
0092      * entry data
0093      */
0094     enum Source {
0095         Cache,
0096         Online,
0097         Registry,
0098     };
0099 
0100     enum PreviewType {
0101         PreviewSmall1,
0102         PreviewSmall2,
0103         PreviewSmall3,
0104         PreviewBig1,
0105         PreviewBig2,
0106         PreviewBig3,
0107     };
0108 
0109     struct DownloadLinkInformation {
0110         QString name; // Displayed name.
0111         QString priceAmount; // Price formatted as a string.
0112         QString distributionType; // OCS Distribution Type, this is for which OS the file is useful.
0113         QString descriptionLink; // Link to intermediary description.
0114         int id; // Unique integer representing the download number in the list.
0115         bool isDownloadtypeLink;
0116         quint64 size = 0; // Size in kilobytes.
0117         QStringList tags; // variety of tags that can represent mimetype or url location.
0118     };
0119 
0120     enum EntryEvent {
0121         UnknownEvent = 0, ///< A generic event, not generally used
0122         StatusChangedEvent = 1, ///< Used when an event's status is set (use Entry::status() to get the new status)
0123         AdoptedEvent = 2, ///< Used when an entry has been successfully adopted (use this to determine whether a call to Engine::adoptEntry() succeeded)
0124         DetailsLoadedEvent = 3, ///< Used when more details have been added to an existing entry (such as the full description), and the UI should be updated
0125     };
0126     Q_ENUM(EntryEvent)
0127 
0128     /**
0129      * Represents whether the current entry is an actual catalog entry,
0130      * or an entry that represents a set of entries.
0131      * @since 5.83
0132      */
0133     enum EntryType {
0134         CatalogEntry = 0, ///< These are the main entries that KNewStuff can get the details about and download links for.
0135         GroupEntry ///< these are entries whose payload is another feed. Currently only used by the OPDS provider.
0136     };
0137     Q_ENUM(EntryType)
0138 
0139     /**
0140      * Constructor.
0141      */
0142     Entry();
0143 
0144     Entry(const Entry &other);
0145     Entry &operator=(const Entry &other);
0146 
0147     bool operator==(const Entry &other) const;
0148     bool operator<(const Entry &other) const;
0149 
0150     /**
0151      * Destructor.
0152      */
0153     ~Entry();
0154 
0155     bool isValid() const;
0156 
0157     /**
0158      * Sets the name for this data object.
0159      */
0160     void setName(const QString &name);
0161 
0162     /**
0163      * Retrieve the name of the data object.
0164      *
0165      * @return object name (potentially translated)
0166      */
0167     QString name() const;
0168 
0169     /**
0170      * Set the object's unique ID. This must be unique to the provider.
0171      *
0172      * @param id The unique ID of this entry as unique to this provider
0173      * @see KNSCore::Provider
0174      */
0175     void setUniqueId(const QString &id);
0176     /**
0177      * Get the object's unique ID. This will be unique to the provider.
0178      * This is not intended as user-facing information - though it can
0179      * be useful for certain purposes, this is supposed to only be used
0180      * for keeping track of the entry.
0181      *
0182      * @return The unique ID of this entry
0183      */
0184     QString uniqueId() const;
0185 
0186     /**
0187      * Sets the data category, e.g. "KWin Scripts" or "Plasma Theme".
0188      */
0189     void setCategory(const QString &category);
0190 
0191     /**
0192      * Retrieve the category of the data object. This is the category's
0193      * name or ID (as opposed to displayName).
0194      *
0195      * @see KNSCore::Provider::CategoryMetadata
0196      * @see KNSCore::Engine::categories()
0197      * @return object category
0198      */
0199     QString category() const;
0200 
0201     /**
0202      * Set a link to a website containing information about this entry
0203      *
0204      * @param page The URL representing the entry's website
0205      */
0206     void setHomepage(const QUrl &page);
0207     /**
0208      * A link to a website containing information about this entry
0209      *
0210      * @return The URL representing the entry's website
0211      */
0212     QUrl homepage() const;
0213 
0214     /**
0215      * Sets the author of the object.
0216      */
0217     void setAuthor(const Author &author);
0218 
0219     /**
0220      * Retrieve the author of the object.
0221      *
0222      * @return object author
0223      */
0224     Author author() const;
0225 
0226     /**
0227      * Sets the license (abbreviation) applicable to the object.
0228      */
0229     void setLicense(const QString &license);
0230 
0231     /**
0232      * Retrieve the license name of the object.
0233      *
0234      * @return object license
0235      */
0236     QString license() const;
0237 
0238     /**
0239      * Sets a description (which can potentially be very long)
0240      */
0241     void setSummary(const QString &summary);
0242 
0243     /**
0244      * Retrieve a short description of what the object is all about (should be very short)
0245      *
0246      * @return object license
0247      */
0248     QString shortSummary() const;
0249 
0250     /**
0251      * Sets a short description of what the object is all about (should be very short)
0252      */
0253     void setShortSummary(const QString &summary);
0254 
0255     /**
0256      * Retrieve a (potentially very long) description of the object.
0257      *
0258      * @return object description
0259      */
0260     QString summary() const;
0261 
0262     /**
0263      * The user written changelog
0264      */
0265     void setChangelog(const QString &changelog);
0266     QString changelog() const;
0267 
0268     /**
0269      * Sets the version number.
0270      */
0271     void setVersion(const QString &version);
0272 
0273     /**
0274      * Retrieve the version string of the object.
0275      *
0276      * @return object version
0277      */
0278     QString version() const;
0279 
0280     /**
0281      * Sets the release date.
0282      */
0283     void setReleaseDate(const QDate &releasedate);
0284 
0285     /**
0286      * Retrieve the date of the object's publication.
0287      *
0288      * @return object release date
0289      */
0290     QDate releaseDate() const;
0291 
0292     /**
0293      * Sets the version number that is available as update.
0294      */
0295     void setUpdateVersion(const QString &version);
0296 
0297     /**
0298      * Retrieve the version string of the object that is available as update.
0299      *
0300      * @return object version
0301      */
0302     QString updateVersion() const;
0303 
0304     /**
0305      * Sets the release date that is available as update.
0306      */
0307     void setUpdateReleaseDate(const QDate &releasedate);
0308 
0309     /**
0310      * Retrieve the date of the newer version that is available as update.
0311      *
0312      * @return object release date
0313      */
0314     QDate updateReleaseDate() const;
0315 
0316     /**
0317      * Sets the object's file.
0318      */
0319     void setPayload(const QString &url);
0320 
0321     /**
0322      * Retrieve the file name of the object.
0323      *
0324      * @return object filename
0325      */
0326     QString payload() const;
0327 
0328     /**
0329      * Sets the object's preview file, if available. This should be a
0330      * picture file.
0331      */
0332     void setPreviewUrl(const QString &url, PreviewType type = PreviewSmall1);
0333 
0334     /**
0335      * Retrieve the file name of an image containing a preview of the object.
0336      *
0337      * @return object preview filename
0338      */
0339     QString previewUrl(PreviewType type = PreviewSmall1) const;
0340 
0341     /**
0342      * This will not be loaded automatically, instead use Engine to load the actual images.
0343      */
0344     QImage previewImage(PreviewType type = PreviewSmall1) const;
0345     void setPreviewImage(const QImage &image, PreviewType type = PreviewSmall1);
0346 
0347     /**
0348      * Set the files that have been installed by the install command.
0349      * @param files local file names
0350      */
0351     void setInstalledFiles(const QStringList &files);
0352 
0353     /**
0354      * Retrieve the locally installed files.
0355      * @return file names
0356      */
0357     QStringList installedFiles() const;
0358 
0359     /**
0360      * Retrieve the locally uninstalled files.
0361      * @return file names
0362      * @since 4.1
0363      */
0364     QStringList uninstalledFiles() const;
0365 
0366     /**
0367      * Sets the rating between 0 (worst) and 100 (best).
0368      *
0369      * @internal
0370      */
0371     void setRating(int rating);
0372 
0373     /**
0374      * Retrieve the rating for the object, which has been determined by its
0375      * users and thus might change over time.
0376      *
0377      * @return object rating
0378      */
0379     int rating() const;
0380 
0381     /**
0382      * Sets the number of comments in the asset
0383      *
0384      * @internal
0385      */
0386     void setNumberOfComments(int comments);
0387 
0388     /**
0389      * @returns the number of comments against the asset
0390      */
0391     int numberOfComments() const;
0392 
0393     /**
0394      * Sets the number of downloads.
0395      *
0396      * @internal
0397      */
0398     void setDownloadCount(int downloads);
0399 
0400     /**
0401      * Retrieve the download count for the object, which has been determined
0402      * by its hosting sites and thus might change over time.
0403      *
0404      * @return object download count
0405      */
0406     int downloadCount() const;
0407 
0408     /**
0409      * How many people have marked themselves as fans of this entry
0410      *
0411      * @return The number of fans this entry has
0412      * @see KNSCore::Engine::becomeFan(const Entry& entry)
0413      */
0414     int numberFans() const;
0415     /**
0416      * Sets how many people are fans.
0417      * Note: This is purely informational. To become a fan, call the
0418      * KNSCore::Engine::becomeFan function.
0419      *
0420      * @param fans The number of fans this entry has
0421      * @see KNSCore::Engine::becomeFan(const Entry& entry)
0422      */
0423     void setNumberFans(int fans);
0424 
0425     /**
0426      * The number of entries in the knowledgebase for this entry
0427      * @return The number of knowledgebase entries
0428      */
0429     int numberKnowledgebaseEntries() const;
0430     /**
0431      * Set the number of knowledgebase entries for this entry
0432      * @param num The number of entries
0433      */
0434     void setNumberKnowledgebaseEntries(int num);
0435     /**
0436      * The link for the knowledgebase for this entry.
0437      * @return A string version of the URL for the knowledgebase
0438      */
0439     QString knowledgebaseLink() const;
0440     /**
0441      * Set the link for the knowledgebase.
0442      * Note: This is not checked for validity, the caller must do this.
0443      * @param link The string version of the URL for the knowledgebase
0444      */
0445     void setKnowledgebaseLink(const QString &link);
0446 
0447     /**
0448      * The number of available download options for this entry
0449      * @return The number of download options
0450      */
0451     int downloadLinkCount() const;
0452     /**
0453      * A list of downloadable data for this entry
0454      * @return The list of download options
0455      * @see DownloadLinkInformation
0456      */
0457     QList<DownloadLinkInformation> downloadLinkInformationList() const;
0458     /**
0459      * Add a new download option to this entry
0460      * @param info The new download option
0461      */
0462     void appendDownloadLinkInformation(const DownloadLinkInformation &info);
0463     /**
0464      * Remove all download options from this entry
0465      */
0466     void clearDownloadLinkInformation();
0467 
0468     /**
0469      * A string representing the URL for a website where the user can donate
0470      * to the author of this entry
0471      * @return The string version of the URL for the entry's donation website
0472      */
0473     QString donationLink() const;
0474     /**
0475      * Set a string representation of the URL for the donation website for this entry.
0476      * Note: This is not checked for validity, the caller must do this.
0477      * @param link String version of the URL for the entry's donation website
0478      */
0479     void setDonationLink(const QString &link);
0480 
0481     /**
0482      * The set of tags assigned specifically to this content item. This does not include
0483      * tags for the download links. To get those, you must concatenate the lists yourself.
0484      * @see downloadLinkInformationList()
0485      * @see DownloadLinkInformation
0486      * @see Engine::setTagFilter(QStringList)
0487      * @since 5.51
0488      */
0489     QStringList tags() const;
0490     /**
0491      * Set the tags for the content item.
0492      * @param tags A string list containing the tags for this entry
0493      * @since 5.51
0494      */
0495     void setTags(const QStringList &tags);
0496 
0497     /**
0498       The id of the provider this entry belongs to
0499       */
0500     QString providerId() const;
0501     void setProviderId(const QString &id);
0502 
0503     /**
0504       The source of this entry can be Cache, Registry or Online - @see source
0505       */
0506     void setSource(Source source);
0507     Source source() const;
0508 
0509     /**
0510      * The entry type is either catalog entry, or group entry.
0511      * @since 5.83
0512      */
0513     void setEntryType(EntryType type);
0514     EntryType entryType() const;
0515 
0516     /**
0517      * set the xml for the entry
0518      * parses the xml and sets the private members accordingly
0519      * used to deserialize data loaded from provider
0520      *
0521      * @param xmldata string to load xml data from
0522      *
0523      * @returns whether or not setting the values was successful
0524      *
0525      * @since 5.36
0526      */
0527     bool setEntryXML(QXmlStreamReader &reader);
0528 
0529     /**
0530      * Sets the entry's status. If no status is set, the default will be
0531      * \ref Invalid.
0532      *
0533      * Note that while this enum is currently found in KNS3::Entry,
0534      * it will be moved to this class once the binary compatibility
0535      * lock is lifted for Frameworks 6. For now, you should read any
0536      * reference to the KNS3::Entry::Status enumerator as KNSCore::Entry::Status
0537      *
0538      * @param status New status of the entry
0539      */
0540     void setStatus(KNSCore::Entry::Status status);
0541 
0542     /**
0543      * Retrieves the entry's status.
0544      *
0545      * @return Current status of the entry
0546      */
0547     KNSCore::Entry::Status status() const;
0548 
0549     /// @internal
0550     void setEntryDeleted();
0551 
0552 private:
0553     friend class StaticXmlProvider;
0554     friend class Cache;
0555     friend class Installation;
0556     friend class AtticaProvider;
0557     friend testEntry;
0558     KNEWSTUFFCORE_NO_EXPORT void setEntryRequestedId(const QString &id);
0559     QDomElement entryXML() const;
0560     bool setEntryXML(const QDomElement &xmldata);
0561     QExplicitlySharedDataPointer<EntryPrivate> d;
0562 };
0563 
0564 inline size_t qHash(const KNSCore::Entry &entry, size_t seed = 0)
0565 {
0566     return qHash(entry.uniqueId(), seed);
0567 }
0568 
0569 KNEWSTUFFCORE_EXPORT QDebug operator<<(QDebug debug, const KNSCore::Entry &entry);
0570 }
0571 
0572 Q_DECLARE_TYPEINFO(KNSCore::Entry, Q_RELOCATABLE_TYPE);
0573 
0574 #endif