summaryrefslogtreecommitdiff
path: root/libopie2/opiecore/ofilenotify.h
Unidiff
Diffstat (limited to 'libopie2/opiecore/ofilenotify.h') (more/less context) (show whitespace changes)
-rw-r--r--libopie2/opiecore/ofilenotify.h63
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
@@ -33,24 +33,26 @@ _;:,     .>    :=|. This program is free software; you can
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
42namespace Opie { 42namespace Opie {
43namespace Core { 43namespace Core {
44 44
45class 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)
@@ -159,47 +161,59 @@ class OFileNotification : public QObject
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 *
@@ -218,21 +232,58 @@ class ODirNotification : public QObject
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
264class 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