[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-core-devel
Subject:    [PATCH] kdirwatch.cpp
From:       Otto Bruggeman <bruggie () home ! nl>
Date:       2002-09-21 23:59:37
[Download RAW message or body]

Hi,

this patch implements the code for the parameters watchFiles and recursive
of addDir in KDirWatch, i hope i did it the right way. Anyway i know it is a
bit late for 3.1 so i dont expect it to go in but i would like your opinion
about the patch anyway.

greetings,
Otto



["kdirwatch.cpp.diff" (text/x-diff)]

? kdirwatch.cpp.diff
Index: kdirwatch.cpp
===================================================================
RCS file: /home/kde/kdelibs/kio/kio/kdirwatch.cpp,v
retrieving revision 1.85
diff -u -3 -r1.85 kdirwatch.cpp
--- kdirwatch.cpp	2002/09/10 10:11:47	1.85
+++ kdirwatch.cpp	2002/09/21 21:33:31
@@ -1193,15 +1193,46 @@
 }
 
 
-// TODO: add watchFiles/recursive support
 void KDirWatch::addDir( const QString& _path,
 			bool watchFiles, bool recursive)
 {
-  if (watchFiles || recursive) {
-    kdDebug(7001) << "addDir - recursive/watchFiles not supported in KDE 3.0"
-		  << endl;
-  }
+  // Always add the dir to the list
   if (d) d->addEntry(this, _path, 0, true);
+
+  if ( watchFiles ) {
+    kdDebug(7001) << "addDir - Watching the files in the directory as well" << endl;
+
+    QDir dir(_path, QString::null, QDir::Unsorted, QDir::Files|QDir::Dirs|QDir::Hidden);
+
+    QStringList files = dir.entryList( "*", QDir::Files|QDir::Hidden, QDir::Unsorted );
+
+    for ( QStringList::Iterator filesIt = files.begin(); filesIt != files.end(); ++filesIt ) {
+      if (d) d->addEntry(this, _path+"/"+*filesIt, 0, false);
+    }
+
+    if ( recursive ) {
+      kdDebug(7001) << "addDir - Also watching the directories in this dir recursively" << endl;
+      QStringList dirs = dir.entryList( "*", QDir::Dirs|QDir::Hidden, QDir::Unsorted );
+      for ( QStringList::Iterator dirsIt = dirs.begin(); dirsIt != dirs.end(); ++dirsIt ) {
+        if (*dirsIt == "." || *dirsIt == "..")
+          continue;
+        addDir(_path+"/"+*dirsIt, true, true);
+      }
+    }
+  }
+  else {
+    if ( recursive ) {
+      kdDebug(7001) << "addDir - Watching the directories in this dir recursively" << endl;
+      QDir dir( _path, "*", QDir::Unsorted, QDir::Dirs|QDir::Hidden);
+
+      QStringList dirs = dir.entryList( "*", QDir::Dirs|QDir::Hidden, QDir::Unsorted );
+      for ( QStringList::Iterator dirsIt = dirs.begin(); dirsIt != dirs.end(); ++dirsIt ) {
+        if (*dirsIt == "." || *dirsIt == "..")
+          continue;
+        addDir(_path+"/"+*dirsIt, false, true);
+      }
+    }
+  }
 }
 
 void KDirWatch::addFile( const QString& _path )


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic