File indexing completed on 2024-04-28 15:28:54
0001 /* 0002 SPDX-FileCopyrightText: 2009 Frederik Gladhorn <gladhorn@kde.org> 0003 SPDX-FileCopyrightText: 2010 Matthias Fuchs <mat69@gmx.net> 0004 0005 SPDX-License-Identifier: LGPL-2.1-or-later 0006 */ 0007 0008 #ifndef CACHE_H 0009 #define CACHE_H 0010 0011 #include <QObject> 0012 #include <QSet> 0013 0014 #include "engine.h" 0015 #include "entryinternal.h" 0016 0017 #include "knewstuffcore_export.h" 0018 0019 #include <memory.h> 0020 0021 namespace KNSCore 0022 { 0023 class CachePrivate; 0024 class KNEWSTUFFCORE_EXPORT Cache : public QObject 0025 { 0026 Q_OBJECT 0027 0028 public: 0029 /** 0030 * Returns an instance of a shared cache for appName 0031 * That way it is made sure, that there do not exist different 0032 * instances of cache, with different contents 0033 * @param appName The file name of the registry - this is usually 0034 * the application name, it will be stored in "apps/knewstuff3/appname.knsregistry" 0035 */ 0036 static QSharedPointer<Cache> getCache(const QString &appName); 0037 0038 ~Cache() override; 0039 0040 /// Read the installed entries (on startup) 0041 void readRegistry(); 0042 /// All entries that have been installed by a certain provider 0043 EntryInternal::List registryForProvider(const QString &providerId); 0044 0045 /// All entries known by the cache (this corresponds with entries which are installed, regardless of status) 0046 EntryInternal::List registry() const; 0047 0048 /// Save the list of installed entries 0049 void writeRegistry(); 0050 0051 void insertRequest(const KNSCore::Provider::SearchRequest &, const KNSCore::EntryInternal::List &entries); 0052 EntryInternal::List requestFromCache(const KNSCore::Provider::SearchRequest &); 0053 0054 /** 0055 * This will run through all entries in the cache, and remove all entries 0056 * where all the installed files they refer to no longer exist. 0057 * 0058 * This cannot be done wholesale for all caches, as some consumers will allow 0059 * this to happen (or indeed expect it to), and so we have to do this on a 0060 * per-type basis 0061 * 0062 * This will also cause the cache store to be updated 0063 * 0064 * @since 5.71 0065 */ 0066 void removeDeletedEntries(); 0067 0068 /** 0069 * Get the entry which installed the passed file. If no entry lists the 0070 * passed file as having been installed by it, an invalid entry will be 0071 * returned. 0072 * @param installedFile The full path name for an installed file 0073 * @return An entry if one was found, or an invalid entry if no entry says it installed that file 0074 * since 5.74 0075 */ 0076 KNSCore::EntryInternal entryFromInstalledFile(const QString &installedFile) const; 0077 0078 /** 0079 * Emitted when the cache has changed underneath us, and need users of the cache to know 0080 * that this has happened. 0081 * @param entry The entry which has changed 0082 * @since 5.75 0083 */ 0084 Q_SIGNAL void entryChanged(const KNSCore::EntryInternal &entry); 0085 0086 public Q_SLOTS: 0087 void registerChangedEntry(const KNSCore::EntryInternal &entry); 0088 0089 private: 0090 Q_DISABLE_COPY(Cache) 0091 Cache(const QString &appName); 0092 0093 #if KNEWSTUFFCORE_ENABLE_DEPRECATED_SINCE(5, 77) 0094 // compatibility with KNS2 0095 void readKns2MetaFiles(); 0096 #endif 0097 0098 private: 0099 // The file that is used to keep track of downloaded entries 0100 QString registryFile; 0101 0102 // The component name that was used in KNS2 to keep track of .meta files 0103 // This is only for compatibility with the former version - KNewStuff2. 0104 QString m_kns2ComponentName; 0105 0106 QSet<EntryInternal> cache; 0107 0108 std::unique_ptr<CachePrivate> d; 0109 }; 0110 0111 } 0112 0113 #endif