1 | /* |
2 | This file is part of the KDE libraries |
3 | SPDX-FileCopyrightText: 1999 David Faure <faure@kde.org> |
4 | |
5 | SPDX-License-Identifier: LGPL-2.0-only |
6 | */ |
7 | |
8 | #ifndef KBUILDSYCOCA_H |
9 | #define KBUILDSYCOCA_H |
10 | |
11 | #include "kbuildsycocainterface_p.h" |
12 | |
13 | #include <kservice.h> |
14 | #include <ksycoca.h> |
15 | |
16 | #include "vfolder_menu_p.h" |
17 | |
18 | class KBuildServiceGroupFactory; |
19 | class QDataStream; |
20 | class KCTimeFactory; |
21 | class KCTimeDict; |
22 | |
23 | /** |
24 | * @internal |
25 | * Exported for kbuildsycoca, but not installed. |
26 | */ |
27 | class KSERVICE_EXPORT KBuildSycoca : public KSycoca, public KBuildSycocaInterface |
28 | { |
29 | Q_OBJECT |
30 | public: |
31 | explicit KBuildSycoca(); |
32 | ~KBuildSycoca() override; |
33 | |
34 | /** |
35 | * Recreate the database file. |
36 | * @return true if it was indeed recreated (by us or possibly by someone else), false on error |
37 | */ |
38 | bool recreate(bool incremental = true); |
39 | |
40 | void setTrackId(const QString &id) |
41 | { |
42 | m_trackId = id; |
43 | } |
44 | |
45 | void (bool b) |
46 | { |
47 | m_menuTest = b; |
48 | } |
49 | |
50 | static QStringList factoryResourceDirs(); |
51 | static QStringList (); |
52 | static QStringList existingResourceDirs(); |
53 | |
54 | /** |
55 | * Returns a number that identifies the current version of the file @p filename, |
56 | * which is located under GenericDataLocation (including local overrides). |
57 | * |
58 | * When a change is made to the file this number will change. |
59 | */ |
60 | static quint32 calcResourceHash(const QString &subdir, const QString &filename); |
61 | |
62 | /** |
63 | * Compare our current settings (language, prefixes...) with the ones from the existing ksycoca global header. |
64 | * @return true if they match (= we can reuse this ksycoca), false otherwise (full build) |
65 | */ |
66 | bool (); |
67 | |
68 | /** |
69 | * @brief path to the sycoca file, for the crash handler in kbuildsycoca |
70 | */ |
71 | static const char *sycocaPath(); |
72 | |
73 | private: |
74 | /** |
75 | * Add single entry to the sycoca database. |
76 | * Either from a previous database or regenerated from file. |
77 | */ |
78 | KSERVICE_NO_EXPORT KSycocaEntry::Ptr createEntry(KSycocaFactory *currentFactory, const QString &file); |
79 | |
80 | /** |
81 | * Implementation of KBuildSycocaInterface |
82 | * Create service and return it. The caller must add it to the servicefactory. |
83 | */ |
84 | KService::Ptr createService(const QString &path) override; |
85 | |
86 | /** |
87 | * Convert a VFolderMenu::SubMenu to KServiceGroups. |
88 | */ |
89 | KSERVICE_NO_EXPORT void (const QString &caption, const QString &name, VFolderMenu::SubMenu *); |
90 | |
91 | /** |
92 | * Build the whole system cache, from .desktop files |
93 | */ |
94 | KSERVICE_NO_EXPORT bool build(); |
95 | |
96 | /** |
97 | * Save the ksycoca file |
98 | */ |
99 | KSERVICE_NO_EXPORT void save(QDataStream *str); |
100 | |
101 | /** |
102 | * Clear the factories |
103 | */ |
104 | KSERVICE_NO_EXPORT void clear(); |
105 | |
106 | /** |
107 | * @internal |
108 | * @return true if building (i.e. if a KBuildSycoca); |
109 | */ |
110 | bool isBuilding() override |
111 | { |
112 | return true; |
113 | } |
114 | |
115 | QMap<QString, qint64> m_allResourceDirs; // dir, mtime in ms since epoch |
116 | QMap<QString, qint64> ; // file, mtime in ms since epoch |
117 | QString m_trackId; |
118 | |
119 | QByteArray m_resource; // e.g. "services" (old resource name, now only used for the signal, see kctimefactory.cpp) |
120 | QString m_resourceSubdir; // e.g. "mime" (xdgdata subdir) |
121 | |
122 | KSycocaEntry::List m_tempStorage; |
123 | typedef QList<KSycocaEntry::List> KSycocaEntryListList; |
124 | KSycocaEntryListList *m_allEntries; // entries from existing ksycoca |
125 | KBuildServiceGroupFactory *m_buildServiceGroupFactory = nullptr; |
126 | KCTimeFactory *m_ctimeFactory = nullptr; |
127 | KCTimeDict *m_ctimeDict; // old timestamps |
128 | typedef QHash<QString, KSycocaEntry::Ptr> KBSEntryDict; |
129 | KBSEntryDict *m_currentEntryDict = nullptr; |
130 | KBSEntryDict *m_serviceGroupEntryDict = nullptr; |
131 | VFolderMenu *m_vfolder = nullptr; |
132 | qint64 m_newTimestamp; |
133 | |
134 | bool ; |
135 | bool m_changed; |
136 | }; |
137 | |
138 | #endif |
139 | |