00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef OFILENOTIFY_H
00030 #define OFILENOTIFY_H
00031 #if defined (__GNUC__) && (__GNUC__ < 3)
00032 #define _GNU_SOURCE
00033 #endif
00034
00035 #include "linux_inotify.h"
00036
00037
00038 #include <qsocketnotifier.h>
00039 #include <qsignal.h>
00040 #include <qstring.h>
00041 #include <qobject.h>
00042 #include <qfile.h>
00043
00044 namespace Opie {
00045 namespace Core {
00046
00047 class OFile : public QObject, public QFile
00048 {
00049 Q_OBJECT
00050
00051 public:
00052 OFile();
00053 OFile( const QString & name );
00054 virtual ~OFile();
00055
00056 protected:
00057 virtual void connectNotify( const char* signal );
00058 virtual void disconnectNotify( const char* signal );
00059
00060 private:
00061 int startWatch( int mode );
00062
00063 signals:
00064 void accessed( const QString& );
00065 void modified( const QString& );
00066 void attributed( const QString& );
00067 void closed( const QString&, bool );
00068 void opened( const QString& );
00069 void deleted( const QString& );
00070 void unmounted( const QString& );
00071 };
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082 class OFileNotificationEvent;
00083
00084
00085
00086
00087
00112 enum OFileNotificationType
00113 {
00114 Nothing = 0,
00115 Access = IN_ACCESS,
00116 Modify = IN_MODIFY,
00117 Attrib = IN_ATTRIB,
00118 CloseWrite = IN_CLOSE_WRITE,
00119 CloseNoWrite = IN_CLOSE_NOWRITE,
00120 Open = IN_OPEN,
00121 MovedFrom = IN_MOVED_FROM,
00122 MovedTo = IN_MOVED_TO,
00123 DeleteSubdir = IN_DELETE_SUBDIR,
00124 DeleteFile = IN_DELETE_FILE,
00125 CreateSubdir = IN_CREATE_SUBDIR,
00126 CreateFile = IN_CREATE_FILE,
00127 DeleteSelf = IN_DELETE_SELF,
00128 Unmount = IN_UNMOUNT,
00129 _QueueOverflow = IN_Q_OVERFLOW,
00130 _Ignored = IN_IGNORED,
00131 };
00132
00133
00134
00135
00136
00149 class OFileNotification : public QObject
00150 {
00151 Q_OBJECT
00152
00153 public:
00154 OFileNotification( QObject* parent = 0, const char* name = 0 );
00155 ~OFileNotification();
00183 static bool singleShot( const QString& path, QObject* receiver, const char* member, OFileNotificationType type = Modify );
00188 int watch( const QString& path, bool sshot = false, OFileNotificationType type = Modify );
00192 void stop();
00196 OFileNotificationType type() const;
00200 QString path() const;
00204 bool isSingleShot() const;
00208 bool isActive() const;
00212 int startWatching( const QString& path, bool sshot = false, OFileNotificationType type = Modify );
00213
00214 signals:
00215 void triggered( const QString&, unsigned int, const QString& );
00216 void accessed( const QString& );
00217 void modified( const QString& );
00218 void attributed( const QString& );
00219 void closed( const QString&, bool );
00220 void opened( const QString& );
00221 void movedTo( const QString&, const QString& );
00222 void movedFrom( const QString&, const QString& );
00223 void deletedSubdir( const QString&, const QString& );
00224 void deletedFile( const QString&, const QString& );
00225 void createdSubdir( const QString&, const QString& );
00226 void createdFile( const QString&, const QString& );
00227 void deleted( const QString& );
00228 void unmounted( const QString& );
00229
00230 protected:
00231 bool activate( const OFileNotificationEvent* e );
00232
00233 private slots:
00234 void inotifyEventHandler();
00235
00236 private:
00237 bool registerEventHandler();
00238 void unregisterEventHandler();
00239
00240 QString _path;
00241 OFileNotificationType _type;
00242 QSignal _signal;
00243 bool _active;
00244 bool _multi;
00245 static QSocketNotifier* _sn;
00246 int _wd;
00247 static int _fd;
00248
00249 friend class OFileNotificationEvent;
00250 };
00251
00252
00253
00254
00255
00269 class ODirNotification : public QObject
00270 {
00271 Q_OBJECT
00272
00273 public:
00274 ODirNotification( QObject* parent = 0, const char* name = 0 );
00275 ~ODirNotification();
00281 int watch( const QString& path, bool sshot = false, OFileNotificationType type = Modify, int recurse = 0 );
00282
00283 signals:
00287 void triggered( const QString&, unsigned int, const QString& );
00288 void accessed( const QString& );
00289 void modified( const QString& );
00290 void attributed( const QString& );
00291 void closed( const QString&, bool );
00292 void opened( const QString& );
00293 void movedTo( const QString&, const QString& );
00294 void movedFrom( const QString&, const QString& );
00295 void deletedSubdir( const QString&, const QString& );
00296 void deletedFile( const QString&, const QString& );
00297 void createdSubdir( const QString&, const QString& );
00298 void createdFile( const QString&, const QString& );
00299 void deleted( const QString& );
00300 void unmounted( const QString& );
00301
00302 private slots:
00303 void subdirCreated( const QString&, const QString& );
00304
00305 private:
00306 OFileNotification* _topfilenotification;
00307 OFileNotificationType _type;
00308 int _depth;
00309 };
00310
00311
00312
00313
00314
00315 class OFileNotificationEvent
00316 {
00317 public:
00318 OFileNotificationEvent( OFileNotification* parent, int wd, unsigned int mask, unsigned int cookie, const QString& name );
00319 ~OFileNotificationEvent();
00320 OFileNotification* parent() const { return _parent; };
00321 int descriptor() const { return _wd; };
00322 unsigned int mask() const { return _mask; };
00323 unsigned int cookie() const { return _cookie; };
00324 QString name() const { return _name; };
00325 void activate() { _parent->activate( this ); };
00326
00327 private:
00328 OFileNotification* _parent;
00329 int _wd;
00330 unsigned int _mask;
00331 unsigned int _cookie;
00332 QString _name;
00333 };
00334
00335
00336 }
00337 }
00338
00339 #endif
00340