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

List:       kde-commits
Subject:    branches/KDE/4.4/kdebase/runtime/nepomuk/services/strigi
From:       Sebastian Trueg <sebastian () trueg ! de>
Date:       2010-03-11 17:15:08
Message-ID: 1268327708.995502.8855.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 1102044 by trueg:

Backport: Take the exclude filters and the hidden folders config into account.

CCMAIL: nlecureuil@mandriva.com


 M  +54 -3     strigiserviceconfig.cpp  
 M  +10 -1     strigiserviceconfig.h  


--- branches/KDE/4.4/kdebase/runtime/nepomuk/services/strigi/strigiserviceconfig.cpp \
#1102043:1102044 @@ -36,6 +36,8 @@
     connect( dirWatch, SIGNAL( created( const QString& ) ),
              this, SLOT( slotConfigDirty() ) );
     dirWatch->addFile( KStandardDirs::locateLocal( "config", m_config.name() ) );
+
+    buildExcludeFilterRegExpCache();
 }
 
 
@@ -92,6 +94,7 @@
 void Nepomuk::StrigiServiceConfig::slotConfigDirty()
 {
     m_config.reparseConfiguration();
+    buildExcludeFilterRegExpCache();
     emit configChanged();
 }
 
@@ -102,11 +105,47 @@
 }
 
 
+namespace {
+    /// recursively check if a folder is hidden
+    bool isDirHidden( QDir& dir ) {
+        if ( QFileInfo( dir.path() ).isHidden() )
+            return true;
+        else if ( dir.cdUp() )
+            return isDirHidden( dir );
+        else
+            return false;
+    }
+}
+
 bool Nepomuk::StrigiServiceConfig::shouldFolderBeIndexed( const QString& path )
 {
-    QStringList inDirs = folders();
-    QStringList exDirs = excludeFolders();
+    if ( folderInFolderList( path, folders(), excludeFolders() ) ) {
+        // check for hidden folders
+        QDir dir( path );
+        if ( !indexHiddenFolders() && isDirHidden( dir ) )
+            return false;
 
+        // reset dir
+        dir = path;
+
+        // check the filters
+        const QString dirName = dir.dirName();
+        foreach( const QRegExp& filter, m_excludeFilterRegExpCache ) {
+            if ( filter.exactMatch( dirName ) ) {
+                return false;
+            }
+        }
+
+        return true;
+    }
+    else {
+        return false;
+    }
+}
+
+
+bool Nepomuk::StrigiServiceConfig::folderInFolderList( const QString& path, const \
QStringList& inDirs, const QStringList& exDirs ) const +{
     if( inDirs.contains( path ) ) {
         return true;
     }
@@ -119,9 +158,21 @@
             return false;
         }
         else {
-            return shouldFolderBeIndexed( parent );
+            return folderInFolderList( parent, inDirs, exDirs );
         }
     }
 }
 
+
+void Nepomuk::StrigiServiceConfig::buildExcludeFilterRegExpCache()
+{
+    m_excludeFilterRegExpCache.clear();
+    foreach( const QString& filter, excludeFilters() ) {
+        QString filterRxStr = QRegExp::escape( filter );
+        filterRxStr.replace( "\\*", QLatin1String( ".*" ) );
+        filterRxStr.replace( "\\?", QLatin1String( "." ) );
+        m_excludeFilterRegExpCache << QRegExp( filterRxStr );
+    }
+}
+
 #include "strigiserviceconfig.moc"
--- branches/KDE/4.4/kdebase/runtime/nepomuk/services/strigi/strigiserviceconfig.h \
#1102043:1102044 @@ -20,6 +20,8 @@
 #define _NEPOMUK_STRIGI_SERVICE_CONFIG_H_
 
 #include <QtCore/QObject>
+#include <QtCore/QList>
+#include <QtCore/QRegExp>
 
 #include <kconfig.h>
 #include <kio/global.h>
@@ -67,7 +69,7 @@
         bool isInitialRun() const;
 
         /**
-         * Check if the folder should be indexed based on 
+         * Check if the folder should be indexed based on
          * folders() and excludeFolders()
          */
         bool shouldFolderBeIndexed( const QString& );
@@ -81,7 +83,14 @@
     private:
         StrigiServiceConfig();
 
+        bool folderInFolderList( const QString& path, const QStringList& include, \
const QStringList& exclude ) const; +        void buildExcludeFilterRegExpCache();
+
         KConfig m_config;
+
+        /// cache of regexp objects for all exclude filters
+        /// to prevent regexp parsing over and over
+        QList<QRegExp> m_excludeFilterRegExpCache;
     };
 }
 


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

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