1 | /* This file is part of the KDE libraries |
2 | * Copyright (C) 1999 David Faure <faure@kde.org> |
3 | * (C) 1999 Waldo Bastian <bastian@kde.org> |
4 | * |
5 | * This library is free software; you can redistribute it and/or |
6 | * modify it under the terms of the GNU Library General Public |
7 | * License version 2 as published by the Free Software Foundation; |
8 | * |
9 | * This library is distributed in the hope that it will be useful, |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 | * Library General Public License for more details. |
13 | * |
14 | * You should have received a copy of the GNU Library General Public License |
15 | * along with this library; see the file COPYING.LIB. If not, write to |
16 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
17 | * Boston, MA 02110-1301, USA. |
18 | **/ |
19 | |
20 | #ifndef KDED_H |
21 | #define KDED_H |
22 | |
23 | #include <QtCore/QObject> |
24 | #include <QtCore/QString> |
25 | #include <QtCore/QTimer> |
26 | #include <QtCore/QHash> |
27 | #include <QtCore/QSet> |
28 | |
29 | #include <QtDBus/QtDBus> |
30 | |
31 | #include <ksycoca.h> |
32 | #include <ksycocatype.h> |
33 | #include <kdedmodule.h> |
34 | #include <kservice.h> |
35 | |
36 | class QDBusServiceWatcher; |
37 | class KDirWatch; |
38 | |
39 | // No need for this in libkio - apps only get readonly access |
40 | class Kded : public QObject |
41 | { |
42 | Q_OBJECT |
43 | public: |
44 | Kded(); |
45 | virtual ~Kded(); |
46 | |
47 | static Kded *self() { return _self;} |
48 | static void messageFilter(const QDBusMessage &); |
49 | |
50 | void noDemandLoad(const QString &obj); // Don't load obj on demand |
51 | |
52 | KDEDModule *loadModule(const QString &obj, bool onDemand); |
53 | KDEDModule *loadModule(const KService::Ptr& service, bool onDemand); |
54 | QStringList loadedModules(); |
55 | bool unloadModule(const QString &obj); |
56 | //bool isWindowRegistered(qlonglong windowId) const; |
57 | /** |
58 | * Applications can register/unregister their windows with kded modules. |
59 | * This allows kpasswdserver and kcookiejar to delete authentication |
60 | * and cookies that are local to a particular window when closing it. |
61 | */ |
62 | //@{ |
63 | /** |
64 | * Register a window with KDED |
65 | */ |
66 | void registerWindowId(qlonglong windowId, const QString &sender); |
67 | /** |
68 | * Unregister a window previously registered with KDED |
69 | */ |
70 | void unregisterWindowId(qlonglong windowId, const QString &sender); |
71 | //@} |
72 | void recreate(const QDBusMessage&); |
73 | void recreate(bool initial); |
74 | void loadSecondPhase(); |
75 | |
76 | //@{ |
77 | /** |
78 | * Check if a module should be loaded on startup. |
79 | * |
80 | * @param module the name of the desktop file for the module, without the .desktop extension |
81 | * @return @c true if the module will be loaded at startup, @c false otherwise |
82 | */ |
83 | bool isModuleAutoloaded(const QString &module) const; |
84 | /** |
85 | * Check if a module should be loaded on startup. |
86 | * |
87 | * @param module a service description for the module |
88 | * @return @c true if the module will be loaded at startup, @c false otherwise |
89 | */ |
90 | bool isModuleAutoloaded(const KService::Ptr &module) const; |
91 | //@} |
92 | |
93 | //@{ |
94 | /** |
95 | * Check if a module should be loaded on demand |
96 | * |
97 | * @param module the name of the desktop file for the module, without the .desktop extension |
98 | * @return @c true if the module will be loaded when its D-Bus interface |
99 | * is requested, @c false otherwise |
100 | */ |
101 | bool isModuleLoadedOnDemand(const QString &module) const; |
102 | /** |
103 | * Check if a module should be loaded on demand |
104 | * |
105 | * @param module a service description for the module |
106 | * @return @c true if the module will be loaded when its D-Bus interface |
107 | * is requested, @c false otherwise |
108 | */ |
109 | bool isModuleLoadedOnDemand(const KService::Ptr &module) const; |
110 | //@} |
111 | |
112 | /** |
113 | * Configure whether a module should be loaded on startup |
114 | * |
115 | * If a module is set to be auto-loaded, it will be loaded at the start of a KDE |
116 | * session. Depending on the phase it is set to load in, it may also be loaded |
117 | * when the first KDE application is run outside of a KDE session. |
118 | * |
119 | * @param module the name of the desktop file for the module, without the .desktop extension |
120 | * @param autoload if @c true, the module will be loaded at startup, |
121 | * otherwise it will not |
122 | */ |
123 | void setModuleAutoloading(const QString &module, bool autoload); |
124 | |
125 | |
126 | public Q_SLOTS: |
127 | /** |
128 | * Loads / unloads modules according to config |
129 | */ |
130 | void initModules(); |
131 | |
132 | /** |
133 | * Recreate the database file |
134 | */ |
135 | void recreate(); |
136 | |
137 | /** |
138 | * Recreating finished |
139 | */ |
140 | void recreateDone(); |
141 | void recreateFailed(const QDBusError &error); |
142 | |
143 | /** |
144 | * Collect all directories to watch |
145 | */ |
146 | void updateDirWatch(); |
147 | |
148 | /** |
149 | * Update directories to watch |
150 | */ |
151 | void updateResourceList(); |
152 | |
153 | /** |
154 | * An application unregistered itself from DBus |
155 | */ |
156 | void slotApplicationRemoved(const QString&); |
157 | |
158 | /** |
159 | * A KDEDModule is about to get destroyed. |
160 | */ |
161 | void slotKDEDModuleRemoved(KDEDModule *); |
162 | |
163 | protected Q_SLOTS: |
164 | |
165 | /** |
166 | * @internal Triggers rebuilding |
167 | */ |
168 | void dirDeleted(const QString& path); |
169 | |
170 | /** |
171 | * @internal Triggers rebuilding |
172 | */ |
173 | void update (const QString& dir ); |
174 | |
175 | void runDelayedCheck(); |
176 | |
177 | private: |
178 | void afterRecreateFinished(); |
179 | |
180 | /** |
181 | * Scans dir for new files and new subdirectories. |
182 | */ |
183 | void readDirectory(const QString& dir ); |
184 | |
185 | /** |
186 | * Pointer to the dirwatch class which tells us, when some directories |
187 | * changed. |
188 | * Slower polling for remote file systems is now done in KDirWatch (JW). |
189 | */ |
190 | KDirWatch* m_pDirWatch; |
191 | |
192 | /** |
193 | * When a desktop file is updated, a timer is started (5 sec) |
194 | * before rebuilding the binary - so that multiple updates result |
195 | * in only one rebuilding. |
196 | */ |
197 | QTimer* m_pTimer; |
198 | |
199 | QList<QDBusMessage> m_recreateRequests; |
200 | int m_recreateCount; |
201 | bool m_recreateBusy; |
202 | |
203 | QHash<QString,KDEDModule *> m_modules; |
204 | //QHash<QString,KLibrary *> m_libs; |
205 | QHash<QString,QObject *> m_dontLoad; |
206 | |
207 | //window id tracking, with a QDBusServiceWatcher to remove them as needed |
208 | QDBusServiceWatcher *m_serviceWatcher; |
209 | QHash<QString,QList<qlonglong> > m_windowIdList; |
210 | QSet<long> m_globalWindowIdList; |
211 | |
212 | QStringList m_allResourceDirs; |
213 | bool m_needDelayedCheck; |
214 | |
215 | static Kded *_self; |
216 | }; |
217 | |
218 | class KBuildsycocaAdaptor: public QDBusAbstractAdaptor |
219 | { |
220 | Q_OBJECT |
221 | Q_CLASSINFO("D-Bus Interface" , "org.kde.kbuildsycoca" ) |
222 | public: |
223 | KBuildsycocaAdaptor(QObject *parent); |
224 | |
225 | public Q_SLOTS: |
226 | Q_NOREPLY void recreate(const QDBusMessage&); |
227 | }; |
228 | |
229 | |
230 | class KUpdateD : public QObject |
231 | { |
232 | Q_OBJECT |
233 | public: |
234 | KUpdateD(); |
235 | ~KUpdateD(); |
236 | |
237 | public Q_SLOTS: |
238 | void runKonfUpdate(); |
239 | void slotNewUpdateFile(); |
240 | |
241 | private: |
242 | /** |
243 | * Pointer to the dirwatch class which tells us, when some directories |
244 | * changed. |
245 | * Slower polling for remote file systems is now done in KDirWatch (JW). |
246 | */ |
247 | KDirWatch* m_pDirWatch; |
248 | |
249 | /** |
250 | * When a desktop file is updated, a timer is started (5 sec) |
251 | * before rebuilding the binary - so that multiple updates result |
252 | * in only one rebuilding. |
253 | */ |
254 | QTimer* m_pTimer; |
255 | }; |
256 | |
257 | class KHostnameD : public QObject |
258 | { |
259 | Q_OBJECT |
260 | public: |
261 | KHostnameD(int pollInterval); |
262 | ~KHostnameD(); |
263 | |
264 | public Q_SLOTS: |
265 | void checkHostname(); |
266 | |
267 | private: |
268 | /** |
269 | * Timer for interval hostname checking. |
270 | */ |
271 | QTimer m_Timer; |
272 | QByteArray m_hostname; |
273 | }; |
274 | |
275 | #endif |
276 | |