File indexing completed on 2024-04-28 15:28:54
0001 /* 0002 SPDX-FileCopyrightText: 2010 Frederik Gladhorn <gladhorn@kde.org> 0003 SPDX-FileCopyrightText: 2016 Dan Leinir Turthra Jensen <admin@leinir.dk> 0004 0005 SPDX-License-Identifier: LGPL-2.1-or-later 0006 */ 0007 0008 #ifndef KNSCORE_DownloadManager_H 0009 #define KNSCORE_DownloadManager_H 0010 0011 #include "entryinternal.h" 0012 #include "knewstuffcore_export.h" 0013 0014 #if KNEWSTUFFCORE_ENABLE_DEPRECATED_SINCE(5, 79) 0015 namespace KNSCore 0016 { 0017 class DownloadManagerPrivate; 0018 /** 0019 * KNewStuff update checker. 0020 * This class can be used to search for KNewStuff items 0021 * without using the widgets and to look for updates of 0022 * already installed items without showing the dialog. 0023 */ 0024 class KNEWSTUFFCORE_EXPORT DownloadManager : public QObject 0025 { 0026 Q_OBJECT 0027 0028 public: 0029 enum SortOrder { 0030 Newest, 0031 Alphabetical, 0032 Rating, 0033 Downloads, 0034 }; 0035 0036 /** 0037 * Create a DownloadManager 0038 * It will try to find a appname.knsrc file. 0039 * Appname is the name of your application as provided in the about data-> 0040 * 0041 * @param parent the parent of the dialog 0042 */ 0043 // clang-format off 0044 KNEWSTUFF_DEPRECATED_VERSION(5, 79, "Use KNSCore::Cache for details on installed entries, or KNSCore::Engine directly for update and installation functionality") 0045 explicit DownloadManager(QObject *parent = nullptr); 0046 // clang-format on 0047 0048 /** 0049 * Create a DownloadManager. Manually specifying the name of the .knsrc file. 0050 * 0051 * @param configFile the name of the configuration file 0052 * @param parent the parent of the dialog 0053 */ 0054 // clang-format off 0055 KNEWSTUFF_DEPRECATED_VERSION(5, 79, "Use KNSCore::Cache for details on installed entries, or KNSCore::Engine directly for update and installation functionality") 0056 explicit DownloadManager(const QString &configFile, QObject *parent = nullptr); 0057 // clang-format on 0058 0059 /** 0060 * destructor 0061 */ 0062 ~DownloadManager() override; 0063 0064 /** 0065 Search for a list of entries. searchResult will be emitted with the requested list. 0066 */ 0067 void search(int page = 0, int pageSize = 100); 0068 0069 /** 0070 Check for available updates. 0071 Use searchResult to get notified as soon as an update has been found. 0072 */ 0073 void checkForUpdates(); 0074 0075 /** 0076 Check for installed resources 0077 Use searchResult to get notified about installed entries. 0078 0079 @since 5.28 0080 */ 0081 void checkForInstalled(); 0082 0083 /** 0084 Installs or updates an entry 0085 @param entry The entry you wish to install or update 0086 */ 0087 void installEntry(const EntryInternal &entry); 0088 0089 /** 0090 * Uninstalls the given entry. 0091 * @param entry The entry which will be uninstalled. 0092 */ 0093 void uninstallEntry(const EntryInternal &entry); 0094 0095 /** 0096 Sets the search term to filter the results on the server. 0097 Note that this function does not trigger a search. Use search after setting this. 0098 @param searchTerm The term you wish to search for 0099 */ 0100 void setSearchTerm(const QString &searchTerm); 0101 0102 /** 0103 Set the sort order of the results. This depends on the server. 0104 Note that this function does not trigger a search. Use search after setting this. 0105 @see SortOrder 0106 @param order The way you want the results to be sorted 0107 */ 0108 void setSearchOrder(SortOrder order); 0109 0110 /** 0111 * Triggers a search for an entry with @p id as its unique id 0112 * 0113 * @see searchResult 0114 * 0115 * @since 5.28 0116 */ 0117 void fetchEntryById(const QString &id); 0118 0119 Q_SIGNALS: 0120 /** 0121 Returns the search result. 0122 This can be the list of updates after checkForUpdates or the result of a search. 0123 @param entries the list of results. entries is empty when nothing was found. 0124 */ 0125 void searchResult(const EntryInternal::List &entries); 0126 0127 /** 0128 The entry status has changed: emitted when the entry has been installed, updated or removed. 0129 Use EntryInternal::status() to check the current status. 0130 @param entry the item that has been updated. 0131 */ 0132 void entryStatusChanged(const EntryInternal &entry); 0133 0134 /** 0135 * Notifies that the engine couldn't be loaded properly and won't be suitable 0136 */ 0137 void errorFound(const QString &errorMessage); 0138 0139 public Q_SLOTS: 0140 void slotProvidersLoaded(); 0141 0142 private: 0143 DownloadManagerPrivate *const d; 0144 Q_DISABLE_COPY(DownloadManager) 0145 }; 0146 0147 } 0148 #endif 0149 #endif