-rw-r--r-- | examples/opiecore/onotifytest/main.cpp | 2 | ||||
-rw-r--r-- | libopie2/opiecore/linux/ofilenotify.cpp | 79 | ||||
-rw-r--r-- | libopie2/opiecore/linux/ofilenotify.h | 13 |
3 files changed, 67 insertions, 27 deletions
diff --git a/examples/opiecore/onotifytest/main.cpp b/examples/opiecore/onotifytest/main.cpp index 8374c59..b773da9 100644 --- a/examples/opiecore/onotifytest/main.cpp +++ b/examples/opiecore/onotifytest/main.cpp | |||
@@ -35,3 +35,3 @@ App::App( int argc, char** argv ) : QApplication( argc, argv ) | |||
35 | 35 | ||
36 | int result = tmpfoo->watch( "/tmp/foo", false, CreateFile, 1 ); | 36 | int result = tmpfoo->watch( "/tmp/foo", false, CreateFile, 2 ); |
37 | QObject::connect( tmpfoo, SIGNAL(triggered(const QString&,unsigned int,const QString&)), | 37 | QObject::connect( tmpfoo, SIGNAL(triggered(const QString&,unsigned int,const QString&)), |
diff --git a/libopie2/opiecore/linux/ofilenotify.cpp b/libopie2/opiecore/linux/ofilenotify.cpp index 3096f7e..a7820ee 100644 --- a/libopie2/opiecore/linux/ofilenotify.cpp +++ b/libopie2/opiecore/linux/ofilenotify.cpp | |||
@@ -228,2 +228,8 @@ QString OFileNotification::path() const | |||
228 | 228 | ||
229 | bool OFileNotification::isSingleShot() const | ||
230 | { | ||
231 | return !_multi; | ||
232 | } | ||
233 | |||
234 | |||
229 | bool OFileNotification::activate( const OFileNotificationEvent* e ) | 235 | bool OFileNotification::activate( const OFileNotificationEvent* e ) |
@@ -333,3 +339,3 @@ void OFileNotification::unregisterEventHandler() | |||
333 | ODirNotification::ODirNotification( QObject* parent, const char* name ) | 339 | ODirNotification::ODirNotification( QObject* parent, const char* name ) |
334 | :QObject( parent, name ) | 340 | :QObject( parent, name ), _topfilenotification( 0 ), _type( Nothing ), _depth( -123 ) |
335 | { | 341 | { |
@@ -344,2 +350,20 @@ ODirNotification::~ODirNotification() | |||
344 | 350 | ||
351 | /* | ||
352 | Love-Trowbridge recursive directory scanning algorithm: | ||
353 | |||
354 | Step 1. Start at initial directory foo. Add watch. | ||
355 | |||
356 | Step 2. Setup handlers for watch created in Step 1. | ||
357 | Specifically, ensure that a directory created | ||
358 | in foo will result in a handled CREATE_SUBDIR | ||
359 | event. | ||
360 | |||
361 | Step 3. Read the contents of foo. | ||
362 | |||
363 | Step 4. For each subdirectory of foo read in step 3, repeat | ||
364 | step 1. | ||
365 | |||
366 | Step 5. For any CREATE_SUBDIR event on bar, if a watch is | ||
367 | not yet created on bar, repeat step 1 on bar. | ||
368 | */ | ||
345 | 369 | ||
@@ -347,8 +371,14 @@ int ODirNotification::watch( const QString& path, bool sshot, OFileNotificationT | |||
347 | { | 371 | { |
348 | qDebug( "ODirNotification::watch( %s, %d, 0x%08x, %d )", (const char*) path, sshot, type, recurse ); | 372 | if ( _type == Nothing ) _type = type; // only set it once - for the top level call |
349 | 373 | OFileNotificationType subtype = ( recurse != 0 ) ? (OFileNotificationType) int( _type | CreateSubdir ) : _type; | |
374 | qDebug( "ODirNotification::watch( %s, %d, 0x%08x, %d )", (const char*) path, sshot, subtype, recurse ); | ||
350 | OFileNotification* fn = new OFileNotification( this, "ODirNotification delegate" ); | 375 | OFileNotification* fn = new OFileNotification( this, "ODirNotification delegate" ); |
351 | int result = fn->startWatching( path, sshot, type ); | 376 | |
377 | int result = fn->startWatching( path, sshot, subtype ); | ||
352 | if ( result != -1 ) | 378 | if ( result != -1 ) |
353 | { | 379 | { |
380 | |||
381 | if ( !_topfilenotification ) _topfilenotification = fn; // only set it once - for the top level call | ||
382 | if ( _depth == -123 ) _depth = recurse; // only set it once - for the top level call | ||
383 | |||
354 | connect( fn, SIGNAL( triggered( const QString&, unsigned int, const QString& ) ), this, SIGNAL( triggered( const QString&, unsigned int, const QString& ) ) ); | 384 | connect( fn, SIGNAL( triggered( const QString&, unsigned int, const QString& ) ), this, SIGNAL( triggered( const QString&, unsigned int, const QString& ) ) ); |
@@ -368,4 +398,6 @@ int ODirNotification::watch( const QString& path, bool sshot, OFileNotificationT | |||
368 | 398 | ||
369 | if ( recurse ) | 399 | if ( recurse != 0 ) |
370 | { | 400 | { |
401 | connect( fn, SIGNAL( createdSubdir( const QString&, const QString& ) ), this, SLOT( subdirCreated( const QString&, const QString& ) ) ); | ||
402 | |||
371 | QDir directory( path ); | 403 | QDir directory( path ); |
@@ -377,3 +409,3 @@ int ODirNotification::watch( const QString& path, bool sshot, OFileNotificationT | |||
377 | QString subpath = QString( "%1/%2" ).arg( path ).arg( *it ); | 409 | QString subpath = QString( "%1/%2" ).arg( path ).arg( *it ); |
378 | int subresult = watch( subpath, sshot, type, recurse-1 ); | 410 | int subresult = watch( subpath, sshot, subtype, recurse-1 ); |
379 | if ( subresult == -1 ) | 411 | if ( subresult == -1 ) |
@@ -385,3 +417,2 @@ int ODirNotification::watch( const QString& path, bool sshot, OFileNotificationT | |||
385 | } | 417 | } |
386 | //connect( fn, SIGNAL( triggered( const QString&, unsigned int, const QString& ) ), this, SIGNAL( triggered( const QString&, unsigned int, const QString& ) ) ); | ||
387 | } | 418 | } |
@@ -391,23 +422,19 @@ int ODirNotification::watch( const QString& path, bool sshot, OFileNotificationT | |||
391 | 422 | ||
392 | // void ODirNotification::subdirCreated( const QString& name ) | 423 | void ODirNotification::subdirCreated( const QString& dir, const QString& subdir ) |
393 | 424 | { | |
394 | 425 | qDebug( "*** ODirNotification::subdirCreated '%s/%s'", (const char*) dir, (const char*) subdir ); | |
395 | /* | 426 | QString newdir = dir; |
396 | Love-Trowbridge recursive directory scanning algorithm: | 427 | if ( newdir.startsWith( _topfilenotification->path() ) ) |
397 | 428 | { | |
398 | Step 1. Start at initial directory foo. Add watch. | 429 | newdir.replace( _topfilenotification->path(), "" ); |
399 | 430 | int level = newdir.contains( '/' ); | |
400 | Step 2. Setup handlers for watch created in Step 1. | 431 | qDebug( "*** dirpart = '%s' ==> level = %d", (const char*) newdir, level ); |
401 | Specifically, ensure that a directory created | ||
402 | in foo will result in a handled CREATE_SUBDIR | ||
403 | event. | ||
404 | |||
405 | Step 3. Read the contents of foo. | ||
406 | 432 | ||
407 | Step 4. For each subdirectory of foo read in step 3, repeat | 433 | if ( _depth == -1 || _depth > level ) |
408 | step 1. | 434 | { |
435 | watch( QString( "%1/%2" ).arg( dir ).arg( subdir ), _topfilenotification->isSingleShot(), _topfilenotification->type(), _depth == -1 ? -1 : _depth-level-1 ); | ||
436 | } | ||
409 | 437 | ||
410 | Step 5. For any CREATE_SUBDIR event on bar, if a watch is | 438 | } |
411 | not yet created on bar, repeat step 1 on bar. | 439 | } |
412 | */ | ||
413 | 440 | ||
diff --git a/libopie2/opiecore/linux/ofilenotify.h b/libopie2/opiecore/linux/ofilenotify.h index 05343b9..17e6b5d 100644 --- a/libopie2/opiecore/linux/ofilenotify.h +++ b/libopie2/opiecore/linux/ofilenotify.h | |||
@@ -113,2 +113,3 @@ enum OFileNotificationType | |||
113 | { | 113 | { |
114 | Nothing = 0, | ||
114 | Access = IN_ACCESS, | 115 | Access = IN_ACCESS, |
@@ -200,2 +201,6 @@ class OFileNotification : public QObject | |||
200 | /** | 201 | /** |
202 | * @returns if the notification is single-shot | ||
203 | */ | ||
204 | bool isSingleShot() const; | ||
205 | /** | ||
201 | * @returns if a file is currently being watched. | 206 | * @returns if a file is currently being watched. |
@@ -294,2 +299,10 @@ class ODirNotification : public QObject | |||
294 | void unmounted( const QString& ); | 299 | void unmounted( const QString& ); |
300 | |||
301 | private slots: | ||
302 | void subdirCreated( const QString&, const QString& ); | ||
303 | |||
304 | private: | ||
305 | OFileNotification* _topfilenotification; | ||
306 | OFileNotificationType _type; | ||
307 | int _depth; | ||
295 | }; | 308 | }; |