Hi Sebastian

How to block signals:
> 1. Use QObject::blockSignals()
>

Didn't work! :-( I've seen the disconnect/reconnect approach being used
successfully as well. There must be something special about this case. I'll
check it out tom.

* There is no real need to optimize the folder list in the filewatch
> service. StrigiServiceConfig already does that before giving the list to
> the IndexScheduler


I thought it's better to optimize it once before saving it rather than
optimize it every time while loading. Anyway, I've removed the optimization
code. It's now redundant.


> * I think we need a better name than "restart". Maybe "ignore last
> config change" or something like that.
>

I've changed it to "ignore changes". Is that okay?


> * Any chance the config handling in IndexScheduler could be moved to
> StrigiServiceConfig? Just so config handling is restricted to the one
> class.
>

Done.


> * Now for the only critical use case: imagine filewatch changes the
> config, then the kcm changes the folders, and only then strigi gets to
> the config. I am not sure if that can even happen but if so strigi would
> ignore the new config. But I suppose this is very unlikely to happen or
> even impossible.
>

The probability of this happening is very low. However I've edited KCM to
make sure it doesn't occur.

I've modified the patch to remove auto adding of sub folders to indexed list
as that is what everyone wanted. (I don't!)

- Vishesh Handa
Index: services/strigi/indexscheduler.cpp
===================================================================
--- services/strigi/indexscheduler.cpp	(revision 1125086)
+++ services/strigi/indexscheduler.cpp	(working copy)
@@ -129,9 +129,6 @@ Nepomuk::IndexScheduler::IndexScheduler(
       m_speed( FullSpeed )
 {
     m_analyzerConfig = new StoppableConfiguration;
-
-    connect( StrigiServiceConfig::self(), SIGNAL( configChanged() ),
-             this, SLOT( slotConfigChanged() ) );
 }
 
 
@@ -487,14 +484,6 @@ void Nepomuk::IndexScheduler::queueAllFo
 }
 
 
-void Nepomuk::IndexScheduler::slotConfigChanged()
-{
-    // restart to make sure we update all folders and removeOldAndUnwantedEntries
-    if ( isRunning() )
-        restart();
-}
-
-
 namespace {
     class QDataStreamStrigiBufferedStream : public Strigi::BufferedStream<char>
     {
Index: services/strigi/indexscheduler.h
===================================================================
--- services/strigi/indexscheduler.h	(revision 1125086)
+++ services/strigi/indexscheduler.h	(working copy)
@@ -172,9 +172,6 @@ namespace Nepomuk {
         void indexingFolder( const QString& );
         void indexingSuspended( bool suspended );
 
-    private Q_SLOTS:
-        void slotConfigChanged();
-
     private:
         void run();
 
Index: services/strigi/strigiservice.cpp
===================================================================
--- services/strigi/strigiservice.cpp	(revision 1125086)
+++ services/strigi/strigiservice.cpp	(working copy)
@@ -60,9 +60,9 @@ Nepomuk::StrigiService::StrigiService( Q
         // monitor all kinds of events
         ( void )new EventMonitor( m_indexScheduler, this );
 
-        // update the watches if the config changes
+        // watch for config changes
         connect( StrigiServiceConfig::self(), SIGNAL( configChanged() ),
-                 this, SLOT( updateWatches() ) );
+                 this, SLOT( slotConfigChanged() ) );
 
         // export on dbus
         ( void )new StrigiServiceAdaptor( this );
@@ -129,6 +129,39 @@ void Nepomuk::StrigiService::finishIniti
 }
 
 
+void Nepomuk::StrigiService::slotConfigChanged()
+{
+    KConfig config("nepomukstrigirc");
+    bool shouldRestart = !config.group( "General" ).readEntry( "ignore changes", false );
+    
+    kDebug() << "Should Restart : " << shouldRestart;
+    
+    if( shouldRestart ) {
+        // restart the index scheduler to update all folders and removeOldAndUnwantedEntries
+        m_indexScheduler->restart();
+        updateWatches();
+    }
+    else {
+        // The metadata mover updated the strigiconfig file because some folders were moved.
+        // We donot want to restart, as the filewatcher is still updating the metadata and 
+        // IndexScheduler::removeOldAndUnwantedEntries would cause certain not yet 
+        // updated entries to be deleted. 
+        
+        StrigiServiceConfig::self()->blockSignals( true );
+        
+        //Update the strigi config as don't want it ignore changes any longer.
+        kDebug() << "Updating strigiconfig to not restart";
+        {
+            KConfig config("nepomukstrigirc");
+            config.group( "General" ).writeEntry( "ignore changes", false );
+        }
+        kDebug() << "Should have changed";
+        
+        StrigiServiceConfig::self()->blockSignals( false );
+    }
+}
+
+
 void Nepomuk::StrigiService::updateWatches()
 {
     org::kde::nepomuk::FileWatch filewatch( "org.kde.nepomuk.services.nepomukfilewatch",
Index: services/strigi/strigiservice.h
===================================================================
--- services/strigi/strigiservice.h	(revision 1125086)
+++ services/strigi/strigiservice.h	(working copy)
@@ -64,6 +64,7 @@ namespace Nepomuk {
     private Q_SLOTS:
         void finishInitialization();
         void updateWatches();
+        void slotConfigChanged();
 
     private:
         void updateStrigiConfig();
Index: services/filewatch/nepomukfilewatch.cpp
===================================================================
--- services/filewatch/nepomukfilewatch.cpp	(revision 1125086)
+++ services/filewatch/nepomukfilewatch.cpp	(working copy)
@@ -28,11 +28,15 @@
 
 #include <QtCore/QDir>
 #include <QtCore/QThread>
+#include <QtCore/QRegExp>
 #include <QtDBus/QDBusConnection>
 
 #include <KDebug>
 #include <KUrl>
 #include <KPluginFactory>
+#include <KDirWatch>
+#include <KConfigGroup>
+#include <KStandardDirs>
 
 #include <Nepomuk/ResourceManager>
 
@@ -140,6 +144,19 @@ void Nepomuk::FileWatch::watchFolder( co
                               KInotify::WatchEvents( KInotify::EventMove|KInotify::EventDelete|KInotify::EventDeleteSelf|KInotify::EventCreate ),
                               KInotify::WatchFlags() );
 #endif
+
+    //Tracking Strigi indexed folder list
+    
+    KDirWatch* dirWatch = KDirWatch::self();
+    connect( dirWatch, SIGNAL( dirty( const QString& ) ),
+             this, SLOT( slotStrigiConfigChanged() ) );
+    connect( dirWatch, SIGNAL( created( const QString& ) ),
+             this, SLOT( slotStrigiConfigChanged() ) );
+
+    KConfig config("nepomukstrigirc");
+    dirWatch->addFile( KStandardDirs::locateLocal( "config", config.name() ) );
+
+    slotStrigiConfigChanged();
 }
 
 
@@ -151,6 +168,8 @@ void Nepomuk::FileWatch::slotFileMoved( 
     kDebug() << from << to;
 
     m_metadataMover->moveFileMetadata( from, to );
+
+    handleStrigiIndexedFolder( urlFrom, urlTo );
 }
 
 
@@ -202,4 +221,44 @@ void Nepomuk::FileWatch::slotInotifyWatc
 }
 #endif
 
+
+void Nepomuk::FileWatch::slotStrigiConfigChanged()
+{
+    m_strigiFoldersHash.clear();
+    KConfig config("nepomukstrigirc");
+    
+    QStringList include = config.group( "General" ).readPathEntry( "folders", QStringList());
+    foreach( QString path, include ) {
+        m_strigiFoldersHash.insert( path, true );
+    }
+
+    QStringList exclude = config.group( "General" ).readPathEntry( "exclude folders", QStringList());
+    foreach( QString path, exclude ) {
+        m_strigiFoldersHash.insert( path, false );
+    }
+}
+
+
+void Nepomuk::FileWatch::handleStrigiIndexedFolder( const QString& urlFrom, const QString& urlTo )
+{    
+    if( !m_strigiFoldersHash.contains( urlFrom ) )
+        return;
+            
+    KConfig config("nepomukstrigirc");
+    
+    // We want to select urlFrom and all UrlFrom/something but not UrlFromSomething.
+    // Therefore the trailing slash and everything after that is optional (/.*)?
+    QRegExp regex( urlFrom + "(/.*)?$" );
+    
+    QStringList includeFolders = config.group( "General" ).readPathEntry( "folders", QStringList());
+    includeFolders.replaceInStrings( regex, urlTo + "\\1" );
+
+    QStringList excludeFolders = config.group( "General" ).readPathEntry( "exclude folders", QStringList());
+    excludeFolders.replaceInStrings( regex, urlTo + "\\1" );
+    
+    config.group( "General" ).writePathEntry( "folders", includeFolders );
+    config.group( "General" ).writePathEntry( "exclude folders", excludeFolders );
+    config.group( "General" ).writeEntry( "ignore changes", true );
+}
+
 #include "nepomukfilewatch.moc"
Index: services/filewatch/nepomukfilewatch.h
===================================================================
--- services/filewatch/nepomukfilewatch.h	(revision 1125086)
+++ services/filewatch/nepomukfilewatch.h	(working copy)
@@ -23,6 +23,7 @@
 
 #include <QtCore/QUrl>
 #include <QtCore/QVariant>
+#include <QtCore/QHash>
 
 namespace Soprano {
     class Model;
@@ -60,9 +61,12 @@ namespace Nepomuk {
 #ifdef BUILD_KINOTIFY
         void slotInotifyWatchUserLimitReached();
 #endif
+        void slotStrigiConfigChanged();
 
     private:
         MetadataMover* m_metadataMover;
+        QHash<QString, bool> m_strigiFoldersHash;
+        void handleStrigiIndexedFolder( const QString& from, const QString& to );
 
 #ifdef BUILD_KINOTIFY
         KInotify* m_dirWatch;
Index: kcm/nepomukserverkcm.cpp
===================================================================
--- kcm/nepomukserverkcm.cpp	(revision 1125086)
+++ kcm/nepomukserverkcm.cpp	(working copy)
@@ -223,7 +223,7 @@ void Nepomuk::ServerConfigModule::save()
     strigiConfig.group( "General" ).writeEntry( "exclude filters", m_editStrigiExcludeFilters->items() );
     strigiConfig.group( "General" ).writeEntry( "index hidden folders", m_checkShowHiddenFolders->isChecked() );
     strigiConfig.group( "General" ).writeEntry( "index newly mounted", m_checkIndexRemovableMedia->isChecked() );
-
+    strigiConfig.group( "General" ).writeEntry( "ignore changes", false );
 
     // 3. update the current state of the nepomuk server
     if ( m_serverInterface.isValid() ) {
_______________________________________________
Nepomuk mailing list
[email protected]
https://mail.kde.org/mailman/listinfo/nepomuk

Reply via email to