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

source code of knewstuff/src/core/cache2_p.h