| 1 | /* |
| 2 | SPDX-FileCopyrightText: 2009 Frederik Gladhorn <gladhorn@kde.org> |
| 3 | SPDX-FileCopyrightText: 2010 Matthias Fuchs <mat69@gmx.net> |
| 4 | |
| 5 | SPDX-License-Identifier: LGPL-2.1-or-later |
| 6 | */ |
| 7 | |
| 8 | #ifndef CACHE_H |
| 9 | #define CACHE_H |
| 10 | |
| 11 | #include <QObject> |
| 12 | #include <QSet> |
| 13 | |
| 14 | #include "entry.h" |
| 15 | #include "provider.h" |
| 16 | |
| 17 | #include "knewstuffcore_export.h" |
| 18 | |
| 19 | #include <memory.h> |
| 20 | |
| 21 | namespace KNSCore |
| 22 | { |
| 23 | class CachePrivate; |
| 24 | class KNEWSTUFFCORE_EXPORT KNEWSTUFFCORE_DEPRECATED_VERSION(6, 9, "Do not use the cache directly." ) Cache : public QObject |
| 25 | { |
| 26 | Q_OBJECT |
| 27 | |
| 28 | public: |
| 29 | /** |
| 30 | * Returns an instance of a shared cache for appName |
| 31 | * That way it is made sure, that there do not exist different |
| 32 | * instances of cache, with different contents |
| 33 | * @param appName The file name of the registry - this is usually |
| 34 | * the application name, it will be stored in "apps/knewstuff3/appname.knsregistry" |
| 35 | */ |
| 36 | static QSharedPointer<Cache> getCache(const QString &appName); |
| 37 | |
| 38 | ~Cache() override; |
| 39 | |
| 40 | /// Read the installed entries (on startup) |
| 41 | void readRegistry(); |
| 42 | /// All entries that have been installed by a certain provider |
| 43 | Entry::List registryForProvider(const QString &providerId); |
| 44 | |
| 45 | /// All entries known by the cache (this corresponds with entries which are installed, regardless of status) |
| 46 | Entry::List registry() const; |
| 47 | |
| 48 | /// Save the list of installed entries |
| 49 | void writeRegistry(); |
| 50 | |
| 51 | void insertRequest(const KNSCore::Provider::SearchRequest &, const KNSCore::Entry::List &entries); |
| 52 | Entry::List requestFromCache(const KNSCore::Provider::SearchRequest &); |
| 53 | |
| 54 | /** |
| 55 | * This will run through all entries in the cache, and remove all entries |
| 56 | * where all the installed files they refer to no longer exist. |
| 57 | * |
| 58 | * This cannot be done wholesale for all caches, as some consumers will allow |
| 59 | * this to happen (or indeed expect it to), and so we have to do this on a |
| 60 | * per-type basis |
| 61 | * |
| 62 | * This will also cause the cache store to be updated |
| 63 | * |
| 64 | * @since 5.71 |
| 65 | */ |
| 66 | void removeDeletedEntries(); |
| 67 | |
| 68 | /** |
| 69 | * Get the entry which installed the passed file. If no entry lists the |
| 70 | * passed file as having been installed by it, an invalid entry will be |
| 71 | * returned. |
| 72 | * @param installedFile The full path name for an installed file |
| 73 | * @return An entry if one was found, or an invalid entry if no entry says it installed that file |
| 74 | * since 5.74 |
| 75 | */ |
| 76 | KNSCore::Entry entryFromInstalledFile(const QString &installedFile) const; |
| 77 | |
| 78 | /** |
| 79 | * Emitted when the cache has changed underneath us, and need users of the cache to know |
| 80 | * that this has happened. |
| 81 | * @param entry The entry which has changed |
| 82 | * @since 5.75 |
| 83 | */ |
| 84 | Q_SIGNAL void entryChanged(const KNSCore::Entry &entry); |
| 85 | |
| 86 | public Q_SLOTS: |
| 87 | void registerChangedEntry(const KNSCore::Entry &entry); |
| 88 | |
| 89 | private: |
| 90 | Q_DISABLE_COPY(Cache) |
| 91 | Cache(const QString &appName); |
| 92 | |
| 93 | private: |
| 94 | std::unique_ptr<CachePrivate> d; |
| 95 | }; |
| 96 | |
| 97 | } |
| 98 | |
| 99 | #endif |
| 100 | |