diff --git a/README.md b/README.md --- a/README.md +++ b/README.md @@ -11,18 +11,64 @@ ## Usage -If you are using CMake, you need to have +There are three parts to KNewStuff: - find_package(KF5NewStuff NO_MODULE) +* *KNewStuffCore* - The core functionality, which takes care of the actual work + (downloading data and interacting with the remote services). Importantly, this + library has no dependencies past Tier 1, and so while the entire framework is + to be considered Tier 3, the KNewStuffCore library can be considered Tier 2 + for integration purposes. +* *KNewStuff* - A Qt Widget based UI library, designed for ease of implementation of + various UI patterns found through KDE applications (such as the Get New Stuff buttons, + as well as generic download and upload dialogues) +* *KNewStuffQuick* - A set of Qt Quick based components designed to provide similar + pattern support as KNewStuff, except for Qt Quick based applications, and specifically + in Kirigami based applications. -(or similar) in your CMakeLists.txt file, and you need to link to KF5::NewStuff. +If you are using CMake, you need to find the modules, which can be done by doing one of +the following in your CMakeLists.txt: -Application authors should use KNS3::DownloadDialog for downloading application -content. For uploading KNS3::UploadDialog is used. +Either use the more modern (and compact) component based method (only actually add the +component you need, since both NewStuff and NewStuffQuick depend on NewStuffCore): -Related information such as creation of *.knsrc files can be found on -techbase in the [Get Hot New Stuff -tutorials](http://techbase.kde.org/Development/Tutorials#Get_Hot_New_Stuff). + find_package(KF5 COMPONENTS NewStuffCore NewStuff NewStuffQuick) + +Or use the old-fashioned syntax + + find_package(KF5NewStuffCore CONFIG) # for the KNewStuffCore library only + find_package(KF5NewStuff CONFIG) # for the KNewStuff UI library, will pull in KNewStuffCore for you + find_package(KF5NewStuffQuick CONFIG) # for the KNewStuffQuick UI library, will pull in KNewStuffCore for you + +Also remember to link to the library you are using (either KF5::NewStuff or +KF5::NewStuffCore), and for the Qt Quick NewStuffQuick module, add the following +to the QML files where you wish to use the components: + + import org.kde.newstuff 1.0 +Finally, because KNewStuffQuick is not a link time requirement, it would be good form +to mark it as a runtime requirement (and describing why you need them), which is done +by adding the following in your CMakeLists.txt sometime after the find statement: + set_package_properties(KF5NewStuffQuick PROPERTIES + DESCRIPTION "Qt Quick components used for interacting with remote data services" + URL "https://api.kde.org/frameworks/knewstuff/html/index.html" + PURPOSE "Required to Get Hot New Stuff for my applicaton" + TYPE RUNTIME) +## Which module should you use? + +When building applications designed to fit in with other classic, widget based +applications, the application authors should use KNS3::DownloadDialog for +downloading application content. For uploading KNS3::UploadDialog is used. + +When building Qt Quick (and in particular Kirigami) based applications, you can +use the NewStuffList item from the org.kde.newstuff import to achieve a similar +functionality to KNS3::DownloadDialog. You can also use the ItemsModel directly, +if this is not featureful enough. Uploading is currently not exposed in KNewStuffQuick. + +If neither of these options are powerful enough for your needs, you can access +the functionality directly through the classes in the KNSCore namespace. + +Related information such as creation of *.knsrc files can be found on +techbase in the [Get Hot New Stuff +tutorials](http://techbase.kde.org/Development/Tutorials#Get_Hot_New_Stuff). diff --git a/src/core/engine.h b/src/core/engine.h --- a/src/core/engine.h +++ b/src/core/engine.h @@ -40,6 +40,19 @@ class Provider; } +/** + * Contains the core functionality for handling interaction with NewStuff providers. + * The entrypoint for most things will be the creation of an instance of KNSCore::Engine + * which will other classes then either use or get instantiated from directly. + * + * NOTE: When implementing anything on top of KNSCore, without using either KNS3 or the + * Qt Quick components, you will need to implement a custom QuestionListener (see that + * class for instructions) + * + * @see KNSCore::Engine + * @see KNSCore::ItemsModel + * @see KNSCore::QuestionListener + */ namespace KNSCore { class Cache; @@ -50,8 +63,6 @@ * An engine keeps track of data which is available locally and remote * and offers high-level synchronization calls as well as upload and download * primitives using an underlying GHNS protocol. - * - * @internal */ class KNEWSTUFFCORE_EXPORT Engine : public QObject { @@ -98,42 +109,172 @@ */ void uninstall(KNSCore::EntryInternal entry); + /** + * Attempt to load a specific preview for the specified entry. + * + * @param entry The entry to fetch a preview for + * @param type The particular preview to fetch + * + * @see signalEntryPreviewLoaded(KNSCore::EntryInternal, KNSCore::EntryInternal::PreviewType); + * @see signalPreviewFailed(); + */ void loadPreview(const KNSCore::EntryInternal &entry, EntryInternal::PreviewType type); + /** + * Get the full details of a specific entry + * + * @param entry The entry to get full details for + * + * @see Entry::signalEntryDetailsLoaded(KNSCore::EntryInternal) + */ void loadDetails(const KNSCore::EntryInternal &entry); + /** + * Set the order the search results are returned in. + * + * Search requests default to showing the newest entries first. + * + * Note: This will automatically launch a search, which means + * you do not need to call requestData manually. + * + * @see KNSCore::Provider::SearchRequest + * @param mode The order you want search results to come back in. + */ void setSortMode(Provider::SortMode mode); + /** + * Set a filter for results (defaults to none), which will allow you + * to show only installed entries, installed entries which have updates, + * or a specific item with a specified ID. The latter further requires + * the search term to be the exact ID of the entry you wish to retrieve. + * + * Note: This will automatically launch a search, which means + * you do not need to call requestData manually. + * + * @see fetchEntryById(QString) + * @see setSearchTerm(QString) + * @param filter The type of results you wish to see + */ void setFilter(Provider::Filter filter); /** - Set the categories that will be included in searches - */ + * Set the categories that will be included in searches + * + * Note: This will automatically launch a search, which means + * you do not need to call requestData manually. + * + * @see KNSCore::Engine::categories() + * @param categories A list of strings of categories + */ void setCategoriesFilter(const QStringList &categories); + /** + * Sets a string search term. + * + * Note: This will automatically launch a search, which means + * you do not need to call requestData manually. + * + * @param searchString The search term you wish to search for + */ void setSearchTerm(const QString &searchString); void reloadEntries(); void requestMoreData(); void requestData(int page, int pageSize); void checkForUpdates(); void checkForInstalled(); + /** + * Convenience method to launch a search for one specific entry. + * + * @param id The ID of the entry you wish to fetch + */ void fetchEntryById(const QString &id); /** * Try to contact the author of the entry by email or showing their homepage. */ void contactAuthor(const EntryInternal &entry); + /** + * Whether or not a user is able to vote on the passed entry. + * + * @param entry The entry to check votability on + * @return True if the user is able to vote on the entry + */ bool userCanVote(const EntryInternal &entry); + /** + * Cast a vote on the passed entry. + * + * @param entry The entry to vote on + * @param rating A number from 0 to 100, 50 being neutral, 0 being most negative and 100 being most positive. + */ void vote(const EntryInternal &entry, uint rating); + + /** + * Whether or not the user is allowed to become a fan of + * a particular entry. + * Not all providers (and consequently entries) support the fan functionality + * and you can use this function to determine this ability. + * @param entry The entry the user might wish to be a fan of + * @return Whether or not it is possible for the user to become a fan of that entry + */ bool userCanBecomeFan(const EntryInternal &entry); + /** + * This will mark the user who is currently authenticated as a fan + * of the entry passed to the function. + * @param entry The entry the user wants to be a fan of + */ void becomeFan(const EntryInternal &entry); + // FIXME There is currently no exposed API to remove the fan status + /** + * The list of the server-side names of the categories handled by this + * engine instance. This corresponds directly to the list of categories + * in your knsrc file. This is not supposed to be used as user-facing + * strings - @see categoriesMetadata() for that. + * + * @return The categories which this instance of Engine handles + */ QStringList categories() const; + /** + * The list of categories searches will actually show results from. This + * is a subset of the categories() list. + * + * @see KNSCore::Engine::setCategoriesFilter(QString) + */ QStringList categoriesFilter() const; + /** + * The list of metadata for the categories handled by this engine instance. + * If you wish to show the categories to the user, this is the data to use. + * The category name is the string used to set categories for the filter, + * and also what is returned by both categories() and categoriesFilter(). + * The human-readable name is displayName, and the only thing which should + * be shown to the user. + * + * @return The metadata for all categories handled by this engine + */ QList categoriesMetadata(); + /** + * The adoption command can be used to allow a user to make use of an entry's + * installed data. For example, this command might be used to ask the system to + * switch to a wallpaper or icon theme which was installed with KNS. + * + * The following is how this might look in a knsrc file. The example shows how + * an external tool is called on the installed file represented by %d. + *
+       AdoptionCommand=/usr/lib64/libexec/plasma-changeicons %d
+     * 
+ * + * @param entry The entry to return an adoption command for + * @return The command to run to adopt this entry's installed data + */ QString adoptionCommand(const KNSCore::EntryInternal &entry) const; + /** + * Whether or not an adoption command exists for this engine + * + * @see adoptionCommand(KNSCore::EntryInternal) + * @return True if an adoption command exists + */ bool hasAdoptionCommand() const; /** diff --git a/src/core/entryinternal.h b/src/core/entryinternal.h --- a/src/core/entryinternal.h +++ b/src/core/entryinternal.h @@ -121,22 +121,49 @@ */ QString name() const; + /** + * Set the object's unique ID. This must be unique to the provider. + * + * @param id The unique ID of this entry as unique to this provider + * @see KNSCore::Provider + */ void setUniqueId(const QString &id); + /** + * Get the object's unique ID. This will be unique to the provider. + * This is not intended as user-facing information - though it can + * be useful for certain purposes, this is supposed to only be used + * for keeping track of the entry. + * + * @return The unique ID of this entry + */ QString uniqueId() const; /** - * Sets the data category, e.g. 'kdesktop/wallpaper'. + * Sets the data category, e.g. "KWin Scripts" or "Plasma Theme". */ void setCategory(const QString &category); /** - * Retrieve the category of the data object. + * Retrieve the category of the data object. This is the category's + * name or ID (as opposed to displayName). * + * @see KNSCore::Provider::CategoryMetadata + * @see KNSCore::Engine::categories() * @return object category */ QString category() const; + /** + * Set a link to a website containing information about this entry + * + * @param page The URL representing the entry's website + */ void setHomepage(const QUrl &page); + /** + * A link to a website containing information about this entry + * + * @return The URL representing the entry's website + */ QUrl homepage() const; /** @@ -164,24 +191,24 @@ QString license() const; /** - * Sets a short description on what the object is all about. + * Sets a description (which can potentially be very long) */ void setSummary(const QString &summary); /** - * Retrieve the license name of the object. + * Retrieve a short description of what the object is all about (should be very short) * * @return object license */ QString shortSummary() const; /** - * Sets a short description on what the object is all about. + * Sets a short description of what the object is all about (should be very short) */ void setShortSummary(const QString &summary); /** - * Retrieve a short description about the object. + * Retrieve a (potentially very long) description of the object. * * @return object description */ @@ -340,20 +367,77 @@ */ int downloadCount() const; + /** + * How many people have marked themselves as fans of this entry + * + * @return The number of fans this entry has + * @see KNSCore::Engine::becomeFan(const EntryInternal& entry) + */ int numberFans() const; + /** + * Sets how many people are fans. + * Note: This is purely informational. To become a fan, call the + * KNSCore::Engine::becomeFan function. + * + * @param fans The number of fans this entry has + * @see KNSCore::Engine::becomeFan(const EntryInternal& entry) + */ void setNumberFans(int fans); + /** + * The number of entries in the knowledgebase for this entry + * @return The number of knowledgebase entries + */ int numberKnowledgebaseEntries() const; + /** + * Set the number of knowledgebase entries for this entry + * @param num The number of entries + */ void setNumberKnowledgebaseEntries(int num); + /** + * The link for the knowledgebase for this entry. + * @return A string version of the URL for the knowledgebase + */ QString knowledgebaseLink() const; + /** + * Set the link for the knowledgebase. + * Note: This is not checked for validity, the caller must do this. + * @param link The string version of the URL for the knowledgebase + */ void setKnowledgebaseLink(const QString &link); + /** + * The number of available download options for this entry + * @return The number of download options + */ int downloadLinkCount() const; + /** + * A list of downloadable data for this entry + * @return The list of download options + * @see DownloadLinkInformation + */ QList downloadLinkInformationList() const; + /** + * Add a new download option to this entry + * @param info The new download option + */ void appendDownloadLinkInformation(const DownloadLinkInformation &info); + /** + * Remove all download options from this entry + */ void clearDownloadLinkInformation(); + /** + * A string representing the URL for a website where the user can donate + * to the author of this entry + * @return The string version of the URL for the entry's donation website + */ QString donationLink() const; + /** + * Set a string representation of the URL for the donation website for this entry. + * Note: This is not checked for validity, the caller must do this. + * @param link String version of the URL for the entry's donation website + */ void setDonationLink(const QString &link); /** @@ -435,6 +519,11 @@ * Sets the entry's status. If no status is set, the default will be * \ref Invalid. * + * Note that while this enum is currently found in KNS3::Entry, + * it will be moved to this class once the binary compatibility + * lock is lifted for Frameworks 6. For now, you should read any + * reference to the KNS3::Entry::Status enumerator as KNSCore::Entry::Status + * * @param status New status of the entry */ void setStatus(KNS3::Entry::Status status); diff --git a/src/downloaddialog.h b/src/downloaddialog.h --- a/src/downloaddialog.h +++ b/src/downloaddialog.h @@ -46,7 +46,7 @@ * * \section knsrc knsrc Files * The Dialog is configured by a .knsrc file containing the KHotNewStuff configuration. - * Your application should install a file called: $KDEDIR/share/config/appname.knsrc + * Your application should install a file into the XDG configuration location called: /etc/xdg/appname.knsrc * * The file could look like this for wallpapers: *
diff --git a/src/qtquick/downloadlinkinfo.h b/src/qtquick/downloadlinkinfo.h
--- a/src/qtquick/downloadlinkinfo.h
+++ b/src/qtquick/downloadlinkinfo.h
@@ -26,6 +26,13 @@
 
 #include "entryinternal.h"
 
+/**
+ * @short One downloadable item as contained within one content item
+ *
+ * A simple data container which wraps a KNSCore::EntryInternal::DownloadLinkInformation
+ * instance and provides property accessors for each of the pieces of information stored
+ * in it.
+ */
 class DownloadLinkInfo : public QObject
 {
     Q_OBJECT
diff --git a/src/qtquick/quickengine.h b/src/qtquick/quickengine.h
--- a/src/qtquick/quickengine.h
+++ b/src/qtquick/quickengine.h
@@ -24,6 +24,14 @@
 
 #include 
 
+/**
+ * @short Encapsulates a KNSCore::Engine for use in Qt Quick
+ *
+ * This class takes care of initialisation of a KNSCore::Engine when assigned a config file.
+ * The actual KNSCore:Engine can be read through the Engine::engine property.
+ *
+ * @see ItemsModel
+ */
 class Engine : public QObject
 {
     Q_OBJECT
diff --git a/src/qtquick/quickitemsmodel.h b/src/qtquick/quickitemsmodel.h
--- a/src/qtquick/quickitemsmodel.h
+++ b/src/qtquick/quickitemsmodel.h
@@ -24,6 +24,41 @@
 
 #include 
 
+/**
+ * @short A model which shows the contents found in an Engine
+ *
+ * Use an instance of this model to show the content items represented by the configuration
+ * file passed to an engine. The following sample assumes you are using the Engine component,
+ * however it is also possible to pass a KNSCore::Engine instance created from C++ to this
+ * property, if you have specific requirements not covered by the convenience component.
+ *
+ * Most data in the model is simple, but the DownloadLinks role will return a list of
+ * DownloadLinkInfo entries, which you will need to manage in some way.
+ *
+ * You might also look at NewStuffList and NewStuffItem to see some more detail on what can be
+ * done with the data.
+ *
+ * @see NewStuffList
+ * @see NewStuffItem
+ *
+ * \code
+    import org.kde.newstuff 1.0 as NewStuff
+    Item {
+        NewStuff.ItemsModel {
+            id: newStuffModel;
+            engine: newStuffEngine.engine;
+        }
+        NewStuff.Engine {
+            id: newStuffEngine;
+            configFile: "/some/filesystem/location/wallpaper.knsrc";
+            onMessage: console.log("KNS Message: " + message);
+            onIdleMessage: console.log("KNS Idle: " + message);
+            onBusyMessage: console.log("KNS Busy: " + message);
+            onErrorMessage: console.log("KNS Error: " + message);
+        }
+    }
+    \endcode
+ */
 class ItemsModel : public QAbstractListModel
 {
     Q_OBJECT
diff --git a/src/upload/atticahelper_p.h b/src/upload/atticahelper_p.h
--- a/src/upload/atticahelper_p.h
+++ b/src/upload/atticahelper_p.h
@@ -34,6 +34,18 @@
 namespace KNSCore
 {
 class HTTPJob;
+/**
+ * @short Upload helper for Attica based providers
+ *
+ * Use this class to help you build upload functionality into applications
+ * which do not fit the KNS3::UploadDialog use case, such as situations where
+ * you have to fit the uploading into the middle of another workflow.
+ *
+ * As uploading is not entirely trivial, we suggest you look at the code in
+ * uploaddialog.cpp to see an example of an actual implementation.
+ *
+ * @see KNS3::UploadDialog
+ */
 class KNEWSTUFFCORE_EXPORT AtticaHelper : public QObject
 {
     Q_OBJECT