Diffstat (limited to 'libopie2/opiecore/ofilenotify.h') (more/less context) (show whitespace changes)
-rw-r--r-- | libopie2/opiecore/ofilenotify.h | 63 |
1 files changed, 57 insertions, 6 deletions
diff --git a/libopie2/opiecore/ofilenotify.h b/libopie2/opiecore/ofilenotify.h index 3eb917e..5bbf421 100644 --- a/libopie2/opiecore/ofilenotify.h +++ b/libopie2/opiecore/ofilenotify.h | |||
@@ -21,48 +21,50 @@ _;:, .> :=|. This program is free software; you can | |||
21 | -. .:....=;==+<; You should have received a copy of the GNU | 21 | -. .:....=;==+<; You should have received a copy of the GNU |
22 | -_. . . )=. = Library General Public License along with | 22 | -_. . . )=. = Library General Public License along with |
23 | -- :-=` this library; see the file COPYING.LIB. | 23 | -- :-=` this library; see the file COPYING.LIB. |
24 | If not, write to the Free Software Foundation, | 24 | If not, write to the Free Software Foundation, |
25 | Inc., 59 Temple Place - Suite 330, | 25 | Inc., 59 Temple Place - Suite 330, |
26 | Boston, MA 02111-1307, USA. | 26 | Boston, MA 02111-1307, USA. |
27 | */ | 27 | */ |
28 | 28 | ||
29 | #ifndef OFILENOTIFY_H | 29 | #ifndef OFILENOTIFY_H |
30 | #define OFILENOTIFY_H | 30 | #define OFILENOTIFY_H |
31 | #if defined (__GNUC__) && (__GNUC__ < 3) | 31 | #if defined (__GNUC__) && (__GNUC__ < 3) |
32 | #define _GNU_SOURCE | 32 | #define _GNU_SOURCE |
33 | #endif | 33 | #endif |
34 | 34 | ||
35 | #include "linux_inotify.h" | 35 | #include "linux_inotify.h" |
36 | 36 | ||
37 | /* QT */ | 37 | /* QT */ |
38 | #include <qsocketnotifier.h> | 38 | #include <qsocketnotifier.h> |
39 | #include <qsignal.h> | 39 | #include <qsignal.h> |
40 | #include <qstring.h> | 40 | #include <qstring.h> |
41 | 41 | ||
42 | namespace Opie { | 42 | namespace Opie { |
43 | namespace Core { | 43 | namespace Core { |
44 | 44 | ||
45 | class OFileNotificationEvent; | ||
46 | |||
45 | /*====================================================================================== | 47 | /*====================================================================================== |
46 | * OFileNotificationType | 48 | * OFileNotificationType |
47 | *======================================================================================*/ | 49 | *======================================================================================*/ |
48 | 50 | ||
49 | /** | 51 | /** |
50 | * @brief An enumerate for the different types of file notifications | 52 | * @brief An enumerate for the different types of file notifications |
51 | * | 53 | * |
52 | * This enumerate provides a means to specify the type of events that you are interest in. | 54 | * This enumerate provides a means to specify the type of events that you are interest in. |
53 | * Valid values are: | 55 | * Valid values are: |
54 | * <ul> | 56 | * <ul> |
55 | * <li>Access: The file was accessed (read) | 57 | * <li>Access: The file was accessed (read) |
56 | * <li>Modify The file was modified (write,truncate) | 58 | * <li>Modify The file was modified (write,truncate) |
57 | * <li>Attrib = The file had its attributes changed (chmod,chown,chgrp) | 59 | * <li>Attrib = The file had its attributes changed (chmod,chown,chgrp) |
58 | * <li>CloseWrite = Writable file was closed | 60 | * <li>CloseWrite = Writable file was closed |
59 | * <li>CloseNoWrite = Unwritable file was closed | 61 | * <li>CloseNoWrite = Unwritable file was closed |
60 | * <li>Open = File was opened | 62 | * <li>Open = File was opened |
61 | * <li>MovedFrom = File was moved from X | 63 | * <li>MovedFrom = File was moved from X |
62 | * <li>MovedTo = File was moved to Y | 64 | * <li>MovedTo = File was moved to Y |
63 | * <li>DeleteSubdir = Subdir was deleted | 65 | * <li>DeleteSubdir = Subdir was deleted |
64 | * <li>DeleteFile = Subfile was deleted | 66 | * <li>DeleteFile = Subfile was deleted |
65 | * <li>CreateSubdir = Subdir was created | 67 | * <li>CreateSubdir = Subdir was created |
66 | * <li>CreateFile = Subfile was created | 68 | * <li>CreateFile = Subfile was created |
67 | * <li>DeleteSelf = Self was deleted | 69 | * <li>DeleteSelf = Self was deleted |
68 | * <li>Unmount = The backing filesystem was unmounted | 70 | * <li>Unmount = The backing filesystem was unmounted |
@@ -147,92 +149,141 @@ class OFileNotification : public QObject | |||
147 | **/ | 149 | **/ |
148 | int watch( const QString& path, bool sshot = false, OFileNotificationType type = Modify ); | 150 | int watch( const QString& path, bool sshot = false, OFileNotificationType type = Modify ); |
149 | /** | 151 | /** |
150 | * Stop watching for file events. | 152 | * Stop watching for file events. |
151 | **/ | 153 | **/ |
152 | void stop(); | 154 | void stop(); |
153 | /** | 155 | /** |
154 | * @returns the notification type as set by @ref start(). | 156 | * @returns the notification type as set by @ref start(). |
155 | **/ | 157 | **/ |
156 | OFileNotificationType type() const; | 158 | OFileNotificationType type() const; |
157 | /** | 159 | /** |
158 | * @returns the path to the file being watched by this instance. | 160 | * @returns the path to the file being watched by this instance. |
159 | **/ | 161 | **/ |
160 | QString path() const; | 162 | QString path() const; |
161 | /** | 163 | /** |
162 | * @returns if a file is currently being watched. | 164 | * @returns if a file is currently being watched. |
163 | **/ | 165 | **/ |
164 | bool isActive() const; | 166 | bool isActive() const; |
165 | /** | 167 | /** |
166 | * @internal | 168 | * @internal |
167 | */ | 169 | */ |
168 | int startWatching( const QString& path, bool sshot = false, OFileNotificationType type = Modify ); | 170 | int startWatching( const QString& path, bool sshot = false, OFileNotificationType type = Modify ); |
169 | 171 | ||
170 | signals: | 172 | signals: |
171 | /** | 173 | void triggered( const QString&, unsigned int, const QString& ); |
172 | * This signal is emitted if an event happens of the specified type happens to the file being watched. | 174 | void accessed( const QString& ); |
173 | **/ | 175 | void modified( const QString& ); |
174 | void triggered( const QString& name ); | 176 | void attributed( const QString& ); |
177 | void closed( const QString&, bool ); | ||
178 | void opened( const QString& ); | ||
179 | void movedTo( const QString&, const QString& ); | ||
180 | void movedFrom( const QString&, const QString& ); | ||
181 | void deletedSubdir( const QString&, const QString& ); | ||
182 | void deletedFile( const QString&, const QString& ); | ||
183 | void createdSubdir( const QString&, const QString& ); | ||
184 | void createdFile( const QString&, const QString& ); | ||
185 | void deleted( const QString& ); | ||
186 | void unmounted( const QString& ); | ||
175 | 187 | ||
176 | protected: | 188 | protected: |
177 | bool activate(); | 189 | bool activate( const OFileNotificationEvent* e ); |
178 | 190 | ||
179 | private slots: | 191 | private slots: |
180 | void inotifyEventHandler(); | 192 | void inotifyEventHandler(); |
181 | 193 | ||
182 | private: | 194 | private: |
183 | bool registerEventHandler(); | 195 | bool registerEventHandler(); |
184 | void unregisterEventHandler(); | 196 | void unregisterEventHandler(); |
185 | 197 | ||
186 | QString _path; | 198 | QString _path; |
187 | OFileNotificationType _type; | 199 | OFileNotificationType _type; |
188 | QSignal _signal; | 200 | QSignal _signal; |
189 | bool _active; | 201 | bool _active; |
190 | bool _multi; | 202 | bool _multi; |
191 | static QSocketNotifier* _sn; | 203 | static QSocketNotifier* _sn; |
192 | int _wd; // inotify watch descriptor | 204 | int _wd; // inotify watch descriptor |
193 | static int _fd; // inotify device descriptor | 205 | static int _fd; // inotify device descriptor |
206 | |||
207 | friend class OFileNotificationEvent; | ||
194 | }; | 208 | }; |
195 | 209 | ||
196 | /*====================================================================================== | 210 | /*====================================================================================== |
197 | * ODirNotification | 211 | * ODirNotification |
198 | *======================================================================================*/ | 212 | *======================================================================================*/ |
199 | 213 | ||
200 | /** | 214 | /** |
201 | * @brief Represents a directory notification | 215 | * @brief Represents a directory notification |
202 | * | 216 | * |
203 | * This class allows to watch for events happening to directories | 217 | * This class allows to watch for events happening to directories |
204 | * It uses the OFileNotification class | 218 | * It uses the OFileNotification class |
205 | * | 219 | * |
206 | * @see http://www.kernel.org/pub/linux/kernel/people/rml/inotify/ | 220 | * @see http://www.kernel.org/pub/linux/kernel/people/rml/inotify/ |
207 | * | 221 | * |
208 | * @author Michael 'Mickey' Lauer <mickey@vanille.de> | 222 | * @author Michael 'Mickey' Lauer <mickey@vanille.de> |
209 | * | 223 | * |
210 | **/ | 224 | **/ |
211 | 225 | ||
212 | class ODirNotification : public QObject | 226 | class ODirNotification : public QObject |
213 | { | 227 | { |
214 | Q_OBJECT | 228 | Q_OBJECT |
215 | 229 | ||
216 | public: | 230 | public: |
217 | ODirNotification( QObject* parent = 0, const char* name = 0 ); | 231 | ODirNotification( QObject* parent = 0, const char* name = 0 ); |
218 | ~ODirNotification(); | 232 | ~ODirNotification(); |
219 | /** | 233 | /** |
220 | * Starts to watch for @a type changes to @a path. Recurse @a recurse levels down the filesystem tree, | 234 | * Starts to watch for @a type changes to @a path. Recurse @a recurse levels down the filesystem tree, |
221 | * use 0 for no recursion and -1 for unlimited recursion. | 235 | * use 0 for no recursion and -1 for unlimited recursion. |
222 | * Set @a sshot to True if you want to be notified only once. | 236 | * Set @a sshot to True if you want to be notified only once. |
223 | **/ | 237 | **/ |
224 | int watch( const QString& path, bool sshot = false, OFileNotificationType type = Modify, int recurse = 0 ); | 238 | int watch( const QString& path, bool sshot = false, OFileNotificationType type = Modify, int recurse = 0 ); |
225 | 239 | ||
226 | signals: | 240 | signals: |
227 | /** | 241 | /** |
228 | * This signal is emitted if an event happens of the specified type happens to the directory being watched. | 242 | * This signal is emitted if an event happens of the specified type happens to the directory being watched. |
229 | **/ | 243 | **/ |
230 | void triggered( const QString& name ); | 244 | void triggered( const QString&, unsigned int, const QString& ); |
245 | void accessed( const QString& ); | ||
246 | void modified( const QString& ); | ||
247 | void attributed( const QString& ); | ||
248 | void closed( const QString&, bool ); | ||
249 | void opened( const QString& ); | ||
250 | void movedTo( const QString&, const QString& ); | ||
251 | void movedFrom( const QString&, const QString& ); | ||
252 | void deletedSubdir( const QString&, const QString& ); | ||
253 | void deletedFile( const QString&, const QString& ); | ||
254 | void createdSubdir( const QString&, const QString& ); | ||
255 | void createdFile( const QString&, const QString& ); | ||
256 | void deleted( const QString& ); | ||
257 | void unmounted( const QString& ); | ||
258 | }; | ||
259 | |||
260 | /*====================================================================================== | ||
261 | * OFileNotificationEvent | ||
262 | *======================================================================================*/ | ||
263 | |||
264 | class OFileNotificationEvent | ||
265 | { | ||
266 | public: | ||
267 | OFileNotificationEvent( OFileNotification* parent, int wd, unsigned int mask, unsigned int cookie, const QString& name ); | ||
268 | ~OFileNotificationEvent(); | ||
269 | OFileNotification* parent() const { return _parent; }; | ||
270 | int descriptor() const { return _wd; }; | ||
271 | unsigned int mask() const { return _mask; }; | ||
272 | unsigned int cookie() const { return _cookie; }; | ||
273 | QString name() const { return _name; }; | ||
274 | void activate() { _parent->activate( this ); }; | ||
275 | |||
276 | private: | ||
277 | OFileNotification* _parent; | ||
278 | int _wd; | ||
279 | unsigned int _mask; | ||
280 | unsigned int _cookie; | ||
281 | QString _name; | ||
231 | }; | 282 | }; |
232 | 283 | ||
233 | 284 | ||
234 | } | 285 | } |
235 | } | 286 | } |
236 | 287 | ||
237 | #endif | 288 | #endif |
238 | 289 | ||