1 | /* |
2 | This file is part of the KDE libraries |
3 | SPDX-FileCopyrightText: 1999 David Faure <faure@kde.org> |
4 | SPDX-FileCopyrightText: 1999 Waldo Bastian <bastian@kde.org> |
5 | |
6 | SPDX-License-Identifier: LGPL-2.0-only |
7 | */ |
8 | |
9 | #ifndef KDED_H |
10 | #define KDED_H |
11 | |
12 | #include <QHash> |
13 | #include <QObject> |
14 | #include <QSet> |
15 | #include <QString> |
16 | #include <QTimer> |
17 | |
18 | #include <QDBusAbstractAdaptor> |
19 | |
20 | #include <KDEDModule> |
21 | #include <ksycoca.h> |
22 | |
23 | class QDBusMessage; |
24 | class QDBusServiceWatcher; |
25 | class KPluginMetaData; |
26 | class KDirWatch; |
27 | |
28 | class Kded : public QObject |
29 | { |
30 | Q_OBJECT |
31 | public: |
32 | Kded(); |
33 | ~Kded() override; |
34 | |
35 | static Kded *self() |
36 | { |
37 | return _self; |
38 | } |
39 | static void messageFilter(const QDBusMessage &); |
40 | |
41 | void noDemandLoad(const QString &obj); // Don't load obj on demand |
42 | |
43 | QStringList loadedModules(); |
44 | bool unloadModule(const QString &obj); |
45 | // bool isWindowRegistered(qlonglong windowId) const; |
46 | /** |
47 | * Applications can register/unregister their windows with kded modules. |
48 | * This allows kpasswdserver and kcookiejar to delete authentication |
49 | * and cookies that are local to a particular window when closing it. |
50 | */ |
51 | //@{ |
52 | /** |
53 | * Register a window with KDED |
54 | */ |
55 | void registerWindowId(qlonglong windowId, const QString &sender); |
56 | /** |
57 | * Unregister a window previously registered with KDED |
58 | */ |
59 | void unregisterWindowId(qlonglong windowId, const QString &sender); |
60 | //@} |
61 | void recreate(bool initial); |
62 | |
63 | //@{ |
64 | /** |
65 | * Check if a module should be loaded on startup. |
66 | * |
67 | * @param module the name of the desktop file for the module, without the .desktop extension |
68 | * @return @c true if the module will be loaded at startup, @c false otherwise |
69 | */ |
70 | bool isModuleAutoloaded(const QString &module) const; |
71 | //@} |
72 | |
73 | //@{ |
74 | /** |
75 | * Check if a module is supported on the current QPA |
76 | */ |
77 | bool platformSupportsModule(const KPluginMetaData &module) const; |
78 | //@} |
79 | |
80 | //@{ |
81 | /** |
82 | * Check if a module should be loaded on demand |
83 | * |
84 | * @param module the name of the desktop file for the module, without the .desktop extension |
85 | * @return @c true if the module will be loaded when its D-Bus interface |
86 | * is requested, @c false otherwise |
87 | */ |
88 | bool isModuleLoadedOnDemand(const QString &module) const; |
89 | //@} |
90 | |
91 | /** |
92 | * Configure whether a module should be loaded on startup |
93 | * |
94 | * If a module is set to be auto-loaded, it will be loaded at the start of a KDE |
95 | * session. Depending on the phase it is set to load in, it may also be loaded |
96 | * when the first KDE application is run outside of a KDE session. |
97 | * |
98 | * @param module the name of the desktop file for the module, without the .desktop extension |
99 | * @param autoload if @c true, the module will be loaded at startup, |
100 | * otherwise it will not |
101 | */ |
102 | void setModuleAutoloading(const QString &module, bool autoload); |
103 | |
104 | public Q_SLOTS: |
105 | KDEDModule *loadModule(const QString &obj, bool onDemand); |
106 | |
107 | /** |
108 | * Loads / unloads modules according to config |
109 | */ |
110 | void initModules(); |
111 | |
112 | /** |
113 | * Recreate the database file |
114 | */ |
115 | void recreate(); |
116 | |
117 | /** |
118 | * Recreating finished |
119 | */ |
120 | void recreateDone(); |
121 | |
122 | /** |
123 | * Collect all directories to watch |
124 | */ |
125 | void updateDirWatch(); |
126 | |
127 | /** |
128 | * Update directories to watch |
129 | */ |
130 | void updateResourceList(); |
131 | |
132 | /** |
133 | * An application unregistered itself from DBus |
134 | */ |
135 | void slotApplicationRemoved(const QString &); |
136 | |
137 | protected Q_SLOTS: |
138 | |
139 | /** |
140 | * @internal Triggers rebuilding |
141 | */ |
142 | void dirDeleted(const QString &path); |
143 | |
144 | /** |
145 | * @internal Triggers rebuilding |
146 | */ |
147 | void update(const QString &dir); |
148 | |
149 | void runDelayedCheck(); |
150 | |
151 | protected: |
152 | /** |
153 | * Scans dir for new files and new subdirectories. |
154 | */ |
155 | void readDirectory(const QString &dir); |
156 | /** |
157 | * Check if a module should be loaded on demand |
158 | * |
159 | * @param module a service description for the module |
160 | * @return @c true if the module will be loaded when its D-Bus interface |
161 | * is requested, @c false otherwise |
162 | */ |
163 | bool isModuleLoadedOnDemand(const KPluginMetaData &module) const; |
164 | |
165 | /** |
166 | * Check if a module should be loaded on startup. |
167 | * |
168 | * @param module a service description for the module |
169 | * @return @c true if the module will be loaded at startup, @c false otherwise |
170 | */ |
171 | bool isModuleAutoloaded(const KPluginMetaData &module) const; |
172 | |
173 | KDEDModule *loadModule(const KPluginMetaData &module, bool onDemand); |
174 | |
175 | QList<KPluginMetaData> availableModules() const; |
176 | /** |
177 | * Pointer to the dirwatch class which tells us, when some directories |
178 | * changed. |
179 | * Slower polling for remote file systems is now done in KDirWatch (JW). |
180 | */ |
181 | KDirWatch *m_pDirWatch = nullptr; |
182 | |
183 | /** |
184 | * When a desktop file is updated, a timer is started (5 sec) |
185 | * before rebuilding the binary - so that multiple updates result |
186 | * in only one rebuilding. |
187 | */ |
188 | QTimer *m_pTimer; |
189 | |
190 | QHash<QString, KDEDModule *> m_modules; |
191 | // QHash<QString,KLibrary *> m_libs; |
192 | QHash<QString, QObject *> m_dontLoad; |
193 | |
194 | // window id tracking, with a QDBusServiceWatcher to remove them as needed |
195 | QDBusServiceWatcher *m_serviceWatcher; |
196 | QHash<QString, QList<qlonglong>> m_windowIdList; |
197 | QSet<long> m_globalWindowIdList; |
198 | |
199 | QStringList m_allResourceDirs; |
200 | bool m_needDelayedCheck; |
201 | |
202 | static Kded *_self; |
203 | }; |
204 | |
205 | class KUpdateD : public QObject |
206 | { |
207 | Q_OBJECT |
208 | public: |
209 | KUpdateD(); |
210 | ~KUpdateD() override; |
211 | |
212 | public Q_SLOTS: |
213 | void runKonfUpdate(); |
214 | void slotNewUpdateFile(const QString &); |
215 | |
216 | private: |
217 | /** |
218 | * Pointer to the dirwatch class which tells us, when some directories |
219 | * changed. |
220 | * Slower polling for remote file systems is now done in KDirWatch (JW). |
221 | */ |
222 | KDirWatch *m_pDirWatch = nullptr; |
223 | |
224 | /** |
225 | * When a desktop file is updated, a timer is started (5 sec) |
226 | * before rebuilding the binary - so that multiple updates result |
227 | * in only one rebuilding. |
228 | */ |
229 | QTimer *m_pTimer; |
230 | }; |
231 | |
232 | #endif |
233 | |