Warning, file /frameworks/knewstuff/src/core/engine.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 knewstuff3/engine.h. 0003 SPDX-FileCopyrightText: 2007 Josef Spillner <spillner@kde.org> 0004 SPDX-FileCopyrightText: 2007-2010 Frederik Gladhorn <gladhorn@kde.org> 0005 SPDX-FileCopyrightText: 2009 Jeremy Whiting <jpwhiting@kde.org> 0006 0007 SPDX-License-Identifier: LGPL-2.1-or-later 0008 */ 0009 0010 #ifndef KNEWSTUFF3_ENGINE_P_H 0011 #define KNEWSTUFF3_ENGINE_P_H 0012 0013 #include <QHash> 0014 #include <QObject> 0015 #include <QSharedPointer> 0016 #include <QString> 0017 0018 #include "entryinternal.h" 0019 #include "errorcode.h" 0020 #include "provider.h" 0021 0022 #include "knewstuffcore_export.h" 0023 0024 #include <memory> 0025 0026 class QTimer; 0027 class KJob; 0028 class EnginePrivate; 0029 0030 namespace Attica 0031 { 0032 class Provider; 0033 } 0034 0035 /** 0036 * Contains the core functionality for handling interaction with NewStuff providers. 0037 * The entrypoint for most things will be the creation of an instance of KNSCore::Engine 0038 * which will other classes then either use or get instantiated from directly. 0039 * 0040 * NOTE: When implementing anything on top of KNSCore, without using either KNS3 or the 0041 * Qt Quick components, you will need to implement a custom QuestionListener (see that 0042 * class for instructions) 0043 * 0044 * @see KNSCore::Engine 0045 * @see KNSCore::ItemsModel 0046 * @see KNSCore::QuestionListener 0047 */ 0048 namespace KNSCore 0049 { 0050 class Cache; 0051 class CommentsModel; 0052 class Installation; 0053 0054 /** 0055 * KNewStuff engine. 0056 * An engine keeps track of data which is available locally and remote 0057 * and offers high-level synchronization calls as well as upload and download 0058 * primitives using an underlying GHNS protocol. 0059 */ 0060 class KNEWSTUFFCORE_EXPORT Engine : public QObject 0061 { 0062 Q_OBJECT 0063 0064 /** 0065 * Current state of the engine, the state con contain multiple operations 0066 * an empty BusyState represents the idle status 0067 * @since 5.74 0068 */ 0069 Q_PROPERTY(BusyState busyState READ busyState WRITE setBusyState NOTIFY busyStateChanged) 0070 0071 /** 0072 * String representation of the engines busy state, in the case of idle this string is empty 0073 * @since 5.74 0074 */ 0075 Q_PROPERTY(QString busyMessage READ busyMessage WRITE setBusyMessage NOTIFY busyMessageChanged) 0076 0077 /** 0078 * Text that should be displayed for the adoption button, this defaults to "Use" 0079 * @since 5.77 0080 */ 0081 Q_PROPERTY(QString useLabel READ useLabel NOTIFY useLabelChanged) 0082 0083 /** 0084 * Whether or not the configuration says that the providers are expected to support uploading. 0085 * As it stands, this is used to determine whether or not to show the Upload... action where 0086 * that is displayed (primarily NewStuff.Page). 0087 * @since 5.85 0088 */ 0089 Q_PROPERTY(bool uploadEnabled READ uploadEnabled NOTIFY uploadEnabledChanged) 0090 0091 /** 0092 * @since 5.85 0093 */ 0094 Q_PROPERTY(QStringList providerIDs READ providerIDs NOTIFY providersChanged) 0095 public: 0096 /** 0097 * Constructor. 0098 */ 0099 explicit Engine(QObject *parent = nullptr); 0100 0101 /** 0102 * Destructor. Frees up all the memory again which might be taken 0103 * by cached entries and providers. 0104 */ 0105 ~Engine() override; 0106 0107 enum class BusyOperation { 0108 Initializing, 0109 LoadingData, 0110 LoadingPreview, 0111 InstallingEntry, 0112 }; 0113 Q_DECLARE_FLAGS(BusyState, BusyOperation) 0114 0115 /** 0116 * Initializes the engine. This step is application-specific and relies 0117 * on an external configuration file, which determines all the details 0118 * about the initialization. 0119 * 0120 * @param configfile KNewStuff2 configuration file (*.knsrc) 0121 * @return \b true if any valid configuration was found, \b false otherwise 0122 * @see KNS3::DownloadDialog 0123 */ 0124 bool init(const QString &configfile); 0125 0126 /** 0127 * The name as defined by the knsrc file 0128 * @return The name associated with the engine's configuration file 0129 * @since 5.63 0130 */ 0131 QString name() const; 0132 0133 /** 0134 * Installs an entry's payload file. This includes verification, if 0135 * necessary, as well as decompression and other steps according to the 0136 * application's *.knsrc file. 0137 * 0138 * @param entry Entry to be installed 0139 * 0140 * @see signalInstallationFinished 0141 * @see signalInstallationFailed 0142 */ 0143 void install(KNSCore::EntryInternal entry, int linkId = 1); 0144 0145 /** 0146 * Uninstalls an entry. It reverses the steps which were performed 0147 * during the installation. 0148 * 0149 * @param entry The entry to deinstall 0150 */ 0151 void uninstall(KNSCore::EntryInternal entry); 0152 0153 /** 0154 * Attempt to load a specific preview for the specified entry. 0155 * 0156 * @param entry The entry to fetch a preview for 0157 * @param type The particular preview to fetch 0158 * 0159 * @see signalEntryPreviewLoaded(KNSCore::EntryInternal, KNSCore::EntryInternal::PreviewType); 0160 * @see signalPreviewFailed(); 0161 */ 0162 void loadPreview(const KNSCore::EntryInternal &entry, EntryInternal::PreviewType type); 0163 /** 0164 * Get the full details of a specific entry 0165 * 0166 * @param entry The entry to get full details for 0167 * 0168 * @see Entry::signalEntryDetailsLoaded(KNSCore::EntryInternal) 0169 */ 0170 void loadDetails(const KNSCore::EntryInternal &entry); 0171 0172 /** 0173 * Set the order the search results are returned in. 0174 * 0175 * Search requests default to showing the newest entries first. 0176 * 0177 * Note: This will automatically launch a search, which means 0178 * you do not need to call requestData manually. 0179 * 0180 * @see KNSCore::Provider::SearchRequest 0181 * @param mode The order you want search results to come back in. 0182 */ 0183 void setSortMode(Provider::SortMode mode); 0184 /** 0185 * The sort mode set on the current request 0186 * @see setSortMode(Provider::SortMode) 0187 * @since 5.63 0188 */ 0189 Provider::SortMode sortMode() const; 0190 /** 0191 * Set a filter for results (defaults to none), which will allow you 0192 * to show only installed entries, installed entries which have updates, 0193 * or a specific item with a specified ID. The latter further requires 0194 * the search term to be the exact ID of the entry you wish to retrieve. 0195 * 0196 * Note: This will automatically launch a search, which means 0197 * you do not need to call requestData manually. 0198 * 0199 * @see fetchEntryById(QString) 0200 * @see setSearchTerm(QString) 0201 * @param filter The type of results you wish to see 0202 */ 0203 void setFilter(Provider::Filter filter); 0204 /** 0205 * The result filter set on the current request 0206 * @see setFilter(Provider::Filter) 0207 * @since 5.63 0208 */ 0209 Provider::Filter filter() const; 0210 0211 /** 0212 * Set the categories that will be included in searches 0213 * 0214 * Note: This will automatically launch a search, which means 0215 * you do not need to call requestData manually. 0216 * 0217 * @see KNSCore::Engine::categories() 0218 * @param categories A list of strings of categories 0219 */ 0220 void setCategoriesFilter(const QStringList &categories); 0221 /** 0222 * Sets a string search term. 0223 * 0224 * Note: This will automatically launch a search, which means 0225 * you do not need to call requestData manually. 0226 * 0227 * @param searchString The search term you wish to search for 0228 */ 0229 void setSearchTerm(const QString &searchString); 0230 /** 0231 * The search term for the current search (empty if none is set) 0232 * @return The current search term 0233 * @since 5.63 0234 */ 0235 QString searchTerm() const; 0236 void reloadEntries(); 0237 void requestMoreData(); 0238 void requestData(int page, int pageSize); 0239 0240 /** 0241 * Set a filter for results, which filters out all entries which do not match 0242 * the filter, as applied to the tags for the entry. This filters only on the 0243 * tags specified for the entry itself. To filter the downloadlinks, use 0244 * setDownloadTagFilter(QStringList). 0245 * 0246 * @note The default filter if one is not set from your knsrc file will filter 0247 * out entries marked as ghns_excluded=1. To retain this when setting a custom 0248 * filter, add "ghns_excluded!=1" as one of the filters. 0249 * 0250 * @note Some tags provided by OCS do not supply a value (and are simply passed 0251 * as a key). These will be interpreted as having the value 1 for filtering 0252 * purposes. An example of this might be ghns_excluded, which in reality will 0253 * generally be passed through ocs as "ghns_excluded" rather than "ghns_excluded=1" 0254 * 0255 * @note As tags are metadata, they are provided in the form of adjectives. They 0256 * are never supplied as action verbs or instructions (as an example, a good tag 0257 * to suggest that for example a wallpaper is painted would be "painted" as opposed 0258 * to "paint", and another example might be that an item should be "excluded" as 0259 * opposed to "exclude"). 0260 * 0261 * == Examples of use == 0262 * Value for tag "tagname" must be exactly "tagdata": 0263 * tagname==tagdata 0264 * 0265 * Value for tag "tagname" must be different from "tagdata": 0266 * tagname!=tagdata 0267 * 0268 * == KNSRC entry == 0269 * A tag filter line in a .knsrc file, which is a comma separated list of 0270 * tag/value pairs, might look like: 0271 * 0272 * TagFilter=ghns_excluded!=1,data##mimetype==application/cbr+zip,data##mimetype==application/cbr+rar 0273 * which would honour the exclusion and filter out anything that does not 0274 * include a comic book archive in either zip or rar format in one or more 0275 * of the download items. 0276 * Notice in particular that there are two data##mimetype entries. Use this 0277 * for when a tag may have multiple values. 0278 * 0279 * TagFilter=application##architecture==x86_64 0280 * which would not honour the exclusion, and would filter out all entries 0281 * which do not mark themselves as having a 64bit application binary in at 0282 * least one download item. 0283 * 0284 * The value does not current support wildcards. The list should be considered 0285 * a binary AND operation (that is, all filter entries must match for the data 0286 * entry to be included in the return data) 0287 * 0288 * @param filter The filter in the form of a list of strings 0289 * @see setDownloadTagFilter(QStringList) 0290 * @since 5.51 0291 */ 0292 void setTagFilter(const QStringList &filter); 0293 /** 0294 * Gets the current tag filter list 0295 * @see setTagFilter(QStringList) 0296 * @since 5.51 0297 */ 0298 QStringList tagFilter() const; 0299 /** 0300 * Add a single filter entry to the entry tag filter. The filter should be in 0301 * the same form as the filter lines in the list used by setTagFilter(QStringList) 0302 * @param filter The filter in the form of a string 0303 * @see setTagFilter(QStringList) 0304 * @since 5.51 0305 */ 0306 void addTagFilter(const QString &filter); 0307 /** 0308 * Sets a filter to be applied to the downloads for an entry. The logic is the 0309 * same as used in setTagFilter(QStringList), but vitally, only one downloadlink 0310 * is required to match the filter for the list to be valid. If you do not wish 0311 * to show the others in your client, you must hide them yourself. 0312 * 0313 * For an entry to be accepted when a download tag filter is set, it must also 0314 * be accepted by the entry filter (so, for example, while a list of downloads 0315 * might be accepted, if the entry has ghns_excluded set, and the default entry 0316 * filter is set, the entry will still be filtered out). 0317 * 0318 * In your knsrc file, set DownloadTagFilter to the filter you wish to apply, 0319 * using the same logic as described for the entry tagfilter. 0320 * 0321 * @param filter The filter in the form of a list of strings 0322 * @see setTagFilter(QStringList) 0323 * @since 5.51 0324 */ 0325 void setDownloadTagFilter(const QStringList &filter); 0326 /** 0327 * Gets the current downloadlink tag filter list 0328 * @see setDownloadTagFilter(QStringList) 0329 * @since 5.51 0330 */ 0331 QStringList downloadTagFilter() const; 0332 /** 0333 * Add a single filter entry to the download tag filter. The filter should be in 0334 * the same form as the filter lines in the list used by setDownloadsTagFilter(QStringList) 0335 * @param filter The filter in the form of a string 0336 * @see setTagFilter(QStringList) 0337 * @see setDownloadTagFilter(QStringList) 0338 * @since 5.51 0339 */ 0340 void addDownloadTagFilter(const QString &filter); 0341 0342 /** 0343 * Request for packages that are installed and need update 0344 * 0345 * These will be reported through the signal @see signalUpdateableEntriesLoaded(). 0346 */ 0347 void checkForUpdates(); 0348 0349 /** 0350 * Requests installed packages with an up to date state 0351 * 0352 * @see signalEntriesLoaded() 0353 */ 0354 void checkForInstalled(); 0355 0356 /** 0357 * Convenience method to launch a search for one specific entry. 0358 * 0359 * @note it will reset the engine state (use storeSearch() and restoreSearch() to handle this if needed) 0360 * 0361 * @param id The ID of the entry you wish to fetch 0362 */ 0363 Q_INVOKABLE void fetchEntryById(const QString &id); 0364 0365 /** 0366 * Restore a previously saved search to be current 0367 * Also emits the appropriate signals so any views depending 0368 * on the information can be updated) 0369 * 0370 * @since 5.79 0371 */ 0372 Q_INVOKABLE void restoreSearch(); 0373 0374 /** 0375 * Stores the current search parameters internally 0376 * This might for example be used to allow you to restore the current view state 0377 * after performing a single-entry fetch with fetchEntryById(QString). That function 0378 * does not perform this action itself, because it may well not be the desired 0379 * outcome. 0380 * 0381 * @since 5.79 0382 */ 0383 Q_INVOKABLE void storeSearch(); 0384 0385 /** 0386 * Try to contact the author of the entry by email or showing their homepage. 0387 */ 0388 void contactAuthor(const EntryInternal &entry); 0389 0390 /** 0391 * Whether or not a user is able to vote on the passed entry. 0392 * 0393 * @param entry The entry to check votability on 0394 * @return True if the user is able to vote on the entry 0395 */ 0396 bool userCanVote(const EntryInternal &entry); 0397 /** 0398 * Cast a vote on the passed entry. 0399 * 0400 * @param entry The entry to vote on 0401 * @param rating A number from 0 to 100, 50 being neutral, 0 being most negative and 100 being most positive. 0402 */ 0403 void vote(const EntryInternal &entry, uint rating); 0404 0405 /** 0406 * Whether or not the user is allowed to become a fan of 0407 * a particular entry. 0408 * Not all providers (and consequently entries) support the fan functionality 0409 * and you can use this function to determine this ability. 0410 * @param entry The entry the user might wish to be a fan of 0411 * @return Whether or not it is possible for the user to become a fan of that entry 0412 */ 0413 bool userCanBecomeFan(const EntryInternal &entry); 0414 /** 0415 * This will mark the user who is currently authenticated as a fan 0416 * of the entry passed to the function. 0417 * @param entry The entry the user wants to be a fan of 0418 */ 0419 void becomeFan(const EntryInternal &entry); 0420 // FIXME There is currently no exposed API to remove the fan status 0421 0422 /** 0423 * The list of the server-side names of the categories handled by this 0424 * engine instance. This corresponds directly to the list of categories 0425 * in your knsrc file. This is not supposed to be used as user-facing 0426 * strings - @see categoriesMetadata() for that. 0427 * 0428 * @return The categories which this instance of Engine handles 0429 */ 0430 QStringList categories() const; 0431 /** 0432 * The list of categories searches will actually show results from. This 0433 * is a subset of the categories() list. 0434 * 0435 * @see KNSCore::Engine::setCategoriesFilter(QString) 0436 */ 0437 QStringList categoriesFilter() const; 0438 0439 /** 0440 * The list of metadata for the categories handled by this engine instance. 0441 * If you wish to show the categories to the user, this is the data to use. 0442 * The category name is the string used to set categories for the filter, 0443 * and also what is returned by both categories() and categoriesFilter(). 0444 * The human-readable name is displayName, and the only thing which should 0445 * be shown to the user. 0446 * 0447 * @return The metadata for all categories handled by this engine 0448 */ 0449 QList<Provider::CategoryMetadata> categoriesMetadata(); 0450 0451 QList<Provider::SearchPreset> searchPresets(); 0452 0453 #if KNEWSTUFFCORE_ENABLE_DEPRECATED_SINCE(5, 77) 0454 /** 0455 * The adoption command can be used to allow a user to make use of an entry's 0456 * installed data. For example, this command might be used to ask the system to 0457 * switch to a wallpaper or icon theme which was installed with KNS. 0458 * 0459 * The following is how this might look in a knsrc file. The example shows how 0460 * an external tool is called on the directory containing the installed file 0461 * represented by %d. If you wish to directly point to the installed file, the 0462 * substitution variable is %f. 0463 * <pre> 0464 AdoptionCommand=/usr/lib64/libexec/plasma-changeicons %d 0465 * </pre> 0466 * 0467 * @param entry The entry to return an adoption command for 0468 * @return The command to run to adopt this entry's installed data 0469 * @deprecated Since 5.77, use Engine::adoptEntry(const KNSCore::EntryInternal &entry) instead 0470 */ 0471 KNEWSTUFFCORE_DEPRECATED_VERSION(5, 77, "Use Engine::adoptEntry(const KNSCore::EntryInternal &entry) instead") 0472 QString adoptionCommand(const KNSCore::EntryInternal &entry) const; 0473 #endif 0474 0475 /** 0476 * Whether or not an adoption command exists for this engine 0477 * 0478 * @see adoptionCommand(KNSCore::EntryInternal) 0479 * @return True if an adoption command exists 0480 */ 0481 bool hasAdoptionCommand() const; 0482 0483 /** 0484 * Adopt an entry using the adoption command. This will also take care of displaying error messages 0485 * @param entry Entry that should be adopted 0486 * @see signalErrorCode 0487 * @see signalEntryEvent 0488 * @since 5.77 0489 */ 0490 Q_INVOKABLE void adoptEntry(const KNSCore::EntryInternal &entry); 0491 0492 /** 0493 * Text that should be displayed for the adoption button, this defaults to i18n("Use") 0494 * @since 5.77 0495 */ 0496 QString useLabel() const; 0497 0498 /** 0499 * Signal gets emitted when the useLabel property changes 0500 * @since 5.77 0501 */ 0502 Q_SIGNAL void useLabelChanged(); 0503 0504 /** 0505 * Set the page size for requests not made explicitly with requestData(int,int) 0506 * @param pageSize the default number of entries to request from the provider 0507 * @see requestData(int,int) 0508 */ 0509 void setPageSize(int pageSize); 0510 0511 /** 0512 * @returns the page size we previously set 0513 * @see requestData(int,int) 0514 * 0515 * @since 5.95 0516 */ 0517 int pageSize() const; 0518 0519 #if KNEWSTUFFCORE_ENABLE_DEPRECATED_SINCE(5, 83) 0520 /** 0521 * Get a list of all the locations which will be used when searching for knsrc 0522 * files, in the order in which the search will occur. 0523 * 0524 * @param includeFallbackLocations Whether or not the deprecated search locations are included 0525 * @return The search list for knsrc files 0526 * @since 5.57 0527 * @deprecated Since 5.83, use Engine::availableConfigFiles instead 0528 */ 0529 KNEWSTUFFCORE_DEPRECATED_VERSION(5, 83, "Use Engine::availableConfigFiles instead") 0530 static QStringList configSearchLocations(bool includeFallbackLocations = false); 0531 #endif 0532 0533 #if KNEWSTUFFCORE_ENABLE_DEPRECATED_SINCE(5, 83) 0534 /** 0535 * Sets whether or not the config file location discovery fallback should be active. 0536 * If enabled (default), if the config file is not found in the knsrcfiles location, 0537 * then the engine will also look in the systemwide config location (usually /etc/xdg 0538 * on linux). If disabled, this fallback location will not be searched. 0539 * 0540 * @param enableFallback Whether or not the fallback discovery should be enabled 0541 * @since 5.57 0542 * @deprecated Since 5.83, the engine includes the fallback paths by default 0543 */ 0544 KNEWSTUFFCORE_DEPRECATED_VERSION(5, 83, "The engine includes the fallback paths by default") 0545 void setConfigLocationFallback(bool enableFallback); 0546 #endif 0547 0548 /** 0549 * List of all available config files. This list will contain no duplicated filenames. 0550 * The returned file paths are absolute. 0551 * @since 5.83 0552 */ 0553 static QStringList availableConfigFiles(); 0554 0555 /** 0556 * The Provider instance with the passed ID 0557 * 0558 * @param providerId The ID of the Provider to fetch 0559 * @return The Provider with the passed ID, or null if non such Provider exists 0560 * @since 5.63 0561 */ 0562 QSharedPointer<Provider> provider(const QString &providerId) const; 0563 0564 /** 0565 * Return the first provider in the providers list (usually the default provider) 0566 * @return The first Provider (or null if the engine is not initialized) 0567 * @since 5.63 0568 */ 0569 QSharedPointer<Provider> defaultProvider() const; 0570 0571 /** 0572 * The IDs of all providers known by this engine. Use this in combination with 0573 * provider(const QString&) to iterate over all providers. 0574 * @return The string IDs of all known providers 0575 * @since 5.85 0576 */ 0577 QStringList providerIDs() const; 0578 0579 /** 0580 * Fired whenever the list of providers changes 0581 * @since 5.85 0582 */ 0583 Q_SIGNAL void providersChanged(); 0584 0585 /** 0586 * This function will return an instance of a model which contains comments for 0587 * the entry passed to it. The model may be empty (if there are no comments for 0588 * the entry, which also covers situations where the entry's provider does not 0589 * support commenting) 0590 * 0591 * @param entry The entry to fetch comments for 0592 * @return A model which contains the comments for the specified entry 0593 * @since 5.63 0594 */ 0595 CommentsModel *commentsForEntry(const KNSCore::EntryInternal &entry); 0596 0597 /** 0598 * String representation of the engines busy state 0599 * @since 5.74 0600 */ 0601 QString busyMessage() const; 0602 0603 /** 0604 * @since 5.74 0605 * @see setBusy 0606 * @see setBusyState 0607 */ 0608 void setBusyMessage(const QString &busyMessage); 0609 0610 /** 0611 * Signal gets emitted when the busy message changes 0612 * @since 5.74 String representation of the engines busy state 0613 */ 0614 Q_SIGNAL void busyMessageChanged(); 0615 0616 /** 0617 * Busy state of the engine 0618 * @since 5.74 0619 */ 0620 BusyState busyState() const; 0621 0622 /** 0623 * Sets the busy state of the engine 0624 * @since 5.74 0625 * @see setBusy 0626 * @see setBusyMessage 0627 */ 0628 void setBusyState(BusyState state); 0629 0630 /** 0631 * Signal gets emitted when the busy state changes 0632 * @since 5.74 0633 */ 0634 Q_SIGNAL void busyStateChanged(); 0635 0636 /** 0637 * Utility method to set both the state and busyMessage 0638 * @since 5.74 0639 */ 0640 void setBusy(BusyState state, const QString &busyMessage); 0641 0642 /** 0643 * Get the entries cache for this engine (note that it may be null if the engine is 0644 * not yet initialized). 0645 * @return The cache for this engine (or null if the engine is not initialized) 0646 * @since 5.74 0647 */ 0648 QSharedPointer<Cache> cache() const; 0649 0650 /** 0651 * If the same engine gets reused and the user could have used the delete functionality of the KCMs the cache could 0652 * be out of sync. If the RemoveDeadEntries option is set to true this will remove deleted entries from the cache 0653 * and the signalEntryChanged slot will be emitted with the updated entry 0654 * @since 5.74 0655 */ 0656 Q_INVOKABLE void revalidateCacheEntries(); 0657 0658 /** 0659 * Whether or not the configuration says that the providers are expected to support uploading. 0660 * @return True if the providers are expected to support uploading 0661 * @since 5.85 0662 */ 0663 bool uploadEnabled() const; 0664 0665 /** 0666 * Fired when the uploadEnabled property changes 0667 * @since 5.85 0668 */ 0669 Q_SIGNAL void uploadEnabledChanged(); 0670 0671 /** 0672 * @returns the list of attica (OCS) providers this engine is connected to 0673 * @since 5.92 0674 */ 0675 QVector<Attica::Provider *> atticaProviders() const; 0676 0677 Q_SIGNALS: 0678 /** 0679 * Indicates a message to be added to the ui's log, or sent to a messagebox 0680 */ 0681 void signalMessage(const QString &message); 0682 0683 void signalProvidersLoaded(); 0684 void signalEntriesLoaded(const KNSCore::EntryInternal::List &entries); 0685 void signalUpdateableEntriesLoaded(const KNSCore::EntryInternal::List &entries); 0686 0687 #if KNEWSTUFFCORE_ENABLE_DEPRECATED_SINCE(5, 77) 0688 KNEWSTUFFCORE_DEPRECATED_VERSION(5, 77, "Use Engine::signalEntryEvent instead") 0689 void signalEntryChanged(const KNSCore::EntryInternal &entry); 0690 #endif 0691 0692 #if KNEWSTUFFCORE_ENABLE_DEPRECATED_SINCE(5, 77) 0693 KNEWSTUFFCORE_DEPRECATED_VERSION(5, 77, "Use Engine::signalEntryEvent instead") 0694 void signalEntryDetailsLoaded(const KNSCore::EntryInternal &entry); 0695 #endif 0696 0697 // a new search result is there, clear the list of items 0698 void signalResetView(); 0699 0700 void signalEntryPreviewLoaded(const KNSCore::EntryInternal &, KNSCore::EntryInternal::PreviewType); 0701 void signalPreviewFailed(); 0702 0703 void signalEntryUploadFinished(); 0704 void signalEntryUploadFailed(); 0705 0706 void signalDownloadDialogDone(KNSCore::EntryInternal::List); 0707 void jobStarted(KJob *, const QString &); 0708 0709 #if KNEWSTUFFCORE_ENABLE_DEPRECATED_SINCE(5, 53) 0710 KNEWSTUFFCORE_DEPRECATED_VERSION(5, 53, "Use Engine::signalErrorCode(const KNSCore::ErrorCode &, const QString &, const QVariant &)") 0711 void signalError(const QString &); 0712 #endif 0713 #if KNEWSTUFFCORE_ENABLE_DEPRECATED_SINCE(5, 74) 0714 KNEWSTUFFCORE_DEPRECATED_VERSION(5, 74, "Use Engine::busyStateChanged() and Engine::busyMessageChanged() instead") 0715 void signalBusy(const QString &); 0716 #endif 0717 #if KNEWSTUFFCORE_ENABLE_DEPRECATED_SINCE(5, 74) 0718 KNEWSTUFFCORE_DEPRECATED_VERSION(5, 74, "Use Engine::busyStateChanged() and Engine::busyMessageChanged() instead") 0719 void signalIdle(const QString &); 0720 #endif 0721 0722 /** 0723 * Fires in the case of any critical or serious errors, such as network or API problems. 0724 * @param errorCode Represents the specific type of error which has occurred 0725 * @param message A human-readable message which can be shown to the end user 0726 * @param metadata Any additional data which might be hepful to further work out the details of the error (see KNSCore::EntryInternal::ErrorCode for the 0727 * metadata details) 0728 * @see KNSCore::EntryInternal::ErrorCode 0729 * @since 5.53 0730 */ 0731 void signalErrorCode(const KNSCore::ErrorCode &errorCode, const QString &message, const QVariant &metadata); 0732 0733 void signalCategoriesMetadataLoded(const QList<Provider::CategoryMetadata> &categories); 0734 0735 /** 0736 * Fires when the engine has loaded search presets. These represent interesting 0737 * searches for the user, such as recommendations. 0738 * @since 5.83 0739 */ 0740 void signalSearchPresetsLoaded(const QList<Provider::SearchPreset> &presets); 0741 /** 0742 * This is fired for any event related directly to a single EntryInternal instance 0743 * @see EntryInternal::EntryEvent for details on which specific event is being notified 0744 * @since 5.77 0745 */ 0746 void signalEntryEvent(const EntryInternal &entry, EntryInternal::EntryEvent event); 0747 0748 private Q_SLOTS: 0749 // the .knsrc file was loaded 0750 KNEWSTUFFCORE_NO_EXPORT void slotProviderFileLoaded(const QDomDocument &doc); 0751 // instead of getting providers from knsrc, use what was configured in ocs systemsettings 0752 KNEWSTUFFCORE_NO_EXPORT void atticaProviderLoaded(const Attica::Provider &provider); 0753 0754 // loading the .knsrc file failed 0755 KNEWSTUFFCORE_NO_EXPORT void slotProvidersFailed(); 0756 0757 // called when a provider is ready to work 0758 KNEWSTUFFCORE_NO_EXPORT void providerInitialized(KNSCore::Provider *); 0759 0760 KNEWSTUFFCORE_NO_EXPORT void slotEntriesLoaded(const KNSCore::Provider::SearchRequest &, KNSCore::EntryInternal::List); 0761 KNEWSTUFFCORE_NO_EXPORT void slotEntryDetailsLoaded(const KNSCore::EntryInternal &entry); 0762 KNEWSTUFFCORE_NO_EXPORT void slotPreviewLoaded(const KNSCore::EntryInternal &entry, KNSCore::EntryInternal::PreviewType type); 0763 0764 KNEWSTUFFCORE_NO_EXPORT void slotSearchTimerExpired(); 0765 0766 KNEWSTUFFCORE_NO_EXPORT void slotEntryChanged(const KNSCore::EntryInternal &entry); 0767 KNEWSTUFFCORE_NO_EXPORT void slotInstallationFinished(); 0768 KNEWSTUFFCORE_NO_EXPORT void slotInstallationFailed(const QString &message); 0769 KNEWSTUFFCORE_NO_EXPORT void downloadLinkLoaded(const KNSCore::EntryInternal &entry); 0770 0771 KNEWSTUFFCORE_NO_EXPORT void providerJobStarted(KJob *); 0772 0773 private: 0774 /** 0775 * load providers from the providersurl in the knsrc file 0776 * creates providers based on their type and adds them to the list of providers 0777 */ 0778 void loadProviders(); 0779 0780 /** 0781 Add a provider and connect it to the right slots 0782 */ 0783 void addProvider(QSharedPointer<KNSCore::Provider> provider); 0784 0785 void updateStatus(); 0786 0787 void doRequest(); 0788 0789 // FIXME KF6: move all of this in EnginePrivate 0790 // handle installation of entries 0791 Installation *m_installation; 0792 // read/write cache of entries 0793 QSharedPointer<Cache> m_cache; 0794 QTimer *m_searchTimer; 0795 // The url of the file containing information about content providers 0796 /// TODO KF6 This really wants to be turned into a QUrl (which will have implications for our public API, so not doing it just now) 0797 QString m_providerFileUrl; 0798 // Categories from knsrc file 0799 QStringList m_categories; 0800 0801 QHash<QString, QSharedPointer<KNSCore::Provider>> m_providers; 0802 0803 QString m_adoptionCommand; 0804 0805 // the current request from providers 0806 Provider::SearchRequest m_currentRequest; 0807 0808 const std::unique_ptr<EnginePrivate> d; 0809 0810 // the page that is currently displayed, so it is not requested repeatedly 0811 int m_currentPage; 0812 0813 // when requesting entries from a provider, how many to ask for 0814 int m_pageSize; 0815 0816 int m_numDataJobs; 0817 int m_numPictureJobs; 0818 int m_numInstallJobs; 0819 // If the provider is ready to be used 0820 bool m_initialized; 0821 0822 Q_DISABLE_COPY(Engine) 0823 }; 0824 0825 } 0826 0827 #endif