summaryrefslogtreecommitdiff
authormickeyl <mickeyl>2005-05-06 19:47:16 (UTC)
committer mickeyl <mickeyl>2005-05-06 19:47:16 (UTC)
commit8b1a64ffe497f5395544c6702225003aca293f80 (patch) (unidiff)
tree98d8aa7db946ae0bc9f96f51fd040627a125dceb
parente73cc9ec4596e1b5e9eed13af710606f358860ba (diff)
downloadopie-8b1a64ffe497f5395544c6702225003aca293f80.zip
opie-8b1a64ffe497f5395544c6702225003aca293f80.tar.gz
opie-8b1a64ffe497f5395544c6702225003aca293f80.tar.bz2
fix a couple of issues with OFileNotification, seems to work with single and multiple file notifications now
add a named trigger
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--libopie2/opiecore/ofilenotify.cpp55
-rw-r--r--libopie2/opiecore/ofilenotify.h42
2 files changed, 84 insertions, 13 deletions
diff --git a/libopie2/opiecore/ofilenotify.cpp b/libopie2/opiecore/ofilenotify.cpp
index c221e58..efd041a 100644
--- a/libopie2/opiecore/ofilenotify.cpp
+++ b/libopie2/opiecore/ofilenotify.cpp
@@ -82,4 +82,15 @@ int OFileNotification::watch( const QString& path, bool sshot, OFileNotification
82{ 82{
83 if ( QFile::exists( path ) ) 83 // check if path exists and is a regular file
84 struct stat s;
85 if ( ::stat( (const char*) path, &s ) == -1 )
84 { 86 {
87 qWarning( "OFileNotification::watch(): Can't watch '%s': %s.", (const char*) path, strerror( errno ) );
88 return -1;
89 }
90 if ( !S_ISREG( s.st_mode ) )
91 {
92 qWarning( "OFileNotification::watch(): Can't watch '%s': %s.", (const char*) path, "not a regular file" );
93 return -1;
94 }
95
85 if ( notification_list.isEmpty() ) 96 if ( notification_list.isEmpty() )
@@ -89,2 +100,8 @@ int OFileNotification::watch( const QString& path, bool sshot, OFileNotification
89 100
101 return startWatching( path, sshot, type );
102}
103
104
105int OFileNotification::startWatching( const QString& path, bool sshot, OFileNotificationType type )
106{
90 struct inotify_watch_request iwr; 107 struct inotify_watch_request iwr;
@@ -103,2 +120,3 @@ int OFileNotification::watch( const QString& path, bool sshot, OFileNotification
103 notification_list.insert( _wd, this ); 120 notification_list.insert( _wd, this );
121 _path = path;
104 _multi = !sshot; 122 _multi = !sshot;
@@ -109,8 +127,2 @@ int OFileNotification::watch( const QString& path, bool sshot, OFileNotification
109 } 127 }
110 else
111 {
112 qWarning( "OFileNotification::watch(): Can't watch '%s': %s.", (const char*) path, strerror( errno ) );
113 return -1;
114 }
115}
116 128
@@ -144,3 +156,3 @@ bool OFileNotification::activate()
144{ 156{
145 emit triggered(); 157 emit triggered( _path );
146 _signal.activate(); 158 _signal.activate();
@@ -151,3 +163,3 @@ bool OFileNotification::activate()
151 163
152void OFileNotification::singleShot( const QString& path, QObject* receiver, const char* member, OFileNotificationType type ) 164bool OFileNotification::singleShot( const QString& path, QObject* receiver, const char* member, OFileNotificationType type )
153{ 165{
@@ -155,3 +167,3 @@ void OFileNotification::singleShot( const QString& path, QObject* receiver, cons
155 ofn->_signal.connect( receiver, member ); 167 ofn->_signal.connect( receiver, member );
156 ofn->watch( path, true, type ); 168 return ofn->watch( path, true, type ) != -1;
157} 169}
@@ -220,2 +232,3 @@ void OFileNotification::unregisterEventHandler()
220{ 232{
233 if ( _sn ) delete _sn;
221 if ( OFileNotification::_fd ) 234 if ( OFileNotification::_fd )
@@ -225,4 +238,26 @@ void OFileNotification::unregisterEventHandler()
225 238
239//=================================================================================================
240// ODirNotification
241//=================================================================================================
242ODirNotification::ODirNotification( QObject* parent, const char* name )
243 :QObject( parent, name )
244{
245 qDebug( "ODirNotification::ODirNotification()" );
246}
247
248
249ODirNotification::~ODirNotification()
250{
251 qDebug( "ODirNotification::~ODirNotification()" );
252}
253
226 254
255int ODirNotification::watch( const QString& path, bool sshot, OFileNotificationType type, int recurse )
256{
257 qDebug( "ODirNotification::watch( %s, %d, 0x%08x, %d )", (const char*) path, sshot, type, recurse );
258 return 0;
227} 259}
260
261}
262
228} 263}
diff --git a/libopie2/opiecore/ofilenotify.h b/libopie2/opiecore/ofilenotify.h
index ea525e9..41ba84d 100644
--- a/libopie2/opiecore/ofilenotify.h
+++ b/libopie2/opiecore/ofilenotify.h
@@ -100,3 +100,3 @@ enum OFileNotificationType
100 * This class allows to watch for events happening to files. 100 * This class allows to watch for events happening to files.
101 * It uses the inotify kernel interface 101 * It uses the inotify linux (2.6.x) kernel interface.
102 * 102 *
@@ -142,3 +142,3 @@ class OFileNotification : public QObject
142 **/ 142 **/
143 static void singleShot( const QString& path, QObject* receiver, const char* member, OFileNotificationType type = Modify ); 143 static bool singleShot( const QString& path, QObject* receiver, const char* member, OFileNotificationType type = Modify );
144 /** 144 /**
@@ -164,2 +164,6 @@ class OFileNotification : public QObject
164 bool isActive() const; 164 bool isActive() const;
165 /**
166 * @internal
167 */
168 int startWatching( const QString& path, bool sshot = false, OFileNotificationType type = Modify );
165 169
@@ -169,3 +173,3 @@ class OFileNotification : public QObject
169 **/ 173 **/
170 void triggered(); 174 void triggered( const QString& name );
171 175
@@ -191,2 +195,34 @@ class OFileNotification : public QObject
191 195
196/*======================================================================================
197 * ODirNotification
198 *======================================================================================*/
199
200/**
201 * @brief Represents a directory notification
202 *
203 * This class allows to watch for events happening to directories
204 * It uses the OFileNotification class
205 *
206 * @see http://www.kernel.org/pub/linux/kernel/people/rml/inotify/
207 *
208 * @author Michael 'Mickey' Lauer <mickey@vanille.de>
209 *
210 **/
211
212class ODirNotification : public QObject
213{
214 Q_OBJECT
215
216 public:
217 ODirNotification( QObject* parent = 0, const char* name = 0 );
218 ~ODirNotification();
219 /**
220 * 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.
222 * Set @a sshot to True if you want to be notified only once.
223 **/
224 int watch( const QString& path, bool sshot = false, OFileNotificationType type = Modify, int recurse = 0 );
225};
226
227
192} 228}