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

List:       kde-commits
Subject:    =?utf-8?q?=5Bamarok=5D_src/core-impl/collections/db=3A_Don=27t_b?=
From:       Ralf Engels <ralf-engels () gmx ! de>
Date:       2011-02-26 23:57:27
Message-ID: 20110226235727.1C5D6A60B0 () git ! kde ! org
[Download RAW message or body]

Git commit 06aaf797cdd7525399b716eb9c044061d902e973 by Ralf Engels.
Committed on 26/02/2011 at 21:39.
Pushed by rengels into branch 'master'.

Don't block preparing KDirWatch
KDirWatch might take a while adding recursive collection directories. Now we use a \
job for that.

M  +68   -38   src/core-impl/collections/db/ScanManager.cpp     
M  +23   -3    src/core-impl/collections/db/ScanManager.h     

http://commits.kde.org/amarok/06aaf797cdd7525399b716eb9c044061d902e973

diff --git a/src/core-impl/collections/db/ScanManager.cpp \
b/src/core-impl/collections/db/ScanManager.cpp index 4e88bfc..7c5d251 100644
--- a/src/core-impl/collections/db/ScanManager.cpp
+++ b/src/core-impl/collections/db/ScanManager.cpp
@@ -58,9 +58,9 @@ ScanManager::ScanManager( Collections::DatabaseCollection \
*collection, QObject *  , m_blockCount( 0 )
     , m_fullScanRequested( false )
     , m_importRequested( 0 )
+    , m_watcherJob( 0 )
     , m_checkDirsTimer( 0 )
     , m_delayedScanTimer( 0 )
-    , m_watcher( 0 )
     , m_mutex( QMutex::Recursive )
 {
     // -- check the scanner version timer
@@ -284,56 +284,25 @@ ScanManager::checkForDirectoryChanges()
 
     if( !AmarokConfig::monitorChanges() )
     {
-        if( m_watcher )
-            m_watcher->stopScan();
+        if( m_watcherJob )
+            m_watcherJob->setPaused( true );
         return;
     }
     else
     {
         // TODO: re-create the watcher if scanRecursively has changed
-        if( m_watcher )
+        if( m_watcherJob )
         {
-            if( m_watcher->isStopped() )
-                m_watcher->startScan( true );
+            m_watcherJob->setPaused( false );
         }
         else
         {
             // -- Check if directories changed while we didn't have a watcher
             requestIncrementalScan();
 
-            // -- create a new watcher
-            m_watcher = new KDirWatch( this );
-
-            connect( m_watcher, SIGNAL( dirty(const QString &) ),
-                     this, SLOT( delayedIncrementalScan(const QString &) ) );
-            connect( m_watcher, SIGNAL( created(const QString &) ),
-                     this, SLOT( delayedIncrementalScanParent(const QString &) ) );
-            connect( m_watcher, SIGNAL( deleted(const QString &) ),
-                     this, SLOT( delayedIncrementalScanParent(const QString &) ) );
-
-            m_watcher->startScan( false );
-        }
-
-        // -- update the KDirWatch with the current set of directories
-        QSet<QString> dirs = \
                m_collection->mountPointManager()->collectionFolders().toSet();
-
-        // - add new
-        QSet<QString> newDirs = dirs - m_oldWatchDirs;
-        foreach( const QString& dir, newDirs )
-        {
-            m_watcher->addDir( dir,
-                               AmarokConfig::scanRecursively() ? \
KDirWatch::WatchSubDirs : KDirWatch::WatchDirOnly ); +            m_watcherJob = new \
DirWatchJob( this, m_collection ); +            \
ThreadWeaver::Weaver::instance()->enqueue( m_watcherJob );  }
-
-        // - remove old
-        QSet<QString> removeDirs = m_oldWatchDirs - dirs;
-        foreach( const QString& dir, removeDirs )
-        {
-            m_watcher->removeDir( dir );
-        }
-
-        m_oldWatchDirs = dirs;
-
     }
 }
 
@@ -360,6 +329,67 @@ ScanManager::slotJobDone()
     m_scanner = 0;
 }
 
+///////////////////////////////////////////////////////////////////////////////
+// class DirWatchJob
+///////////////////////////////////////////////////////////////////////////////
+
+DirWatchJob::DirWatchJob( QObject *parent, Collections::DatabaseCollection \
*collection ) +    : ThreadWeaver::Job( parent )
+    , m_collection( collection )
+{
+    DEBUG_BLOCK;
+
+    // -- create a new watcher
+    m_watcher = new KDirWatch( this );
+
+    connect( m_watcher, SIGNAL( dirty(const QString &) ),
+             parent, SLOT( delayedIncrementalScan(const QString &) ) );
+    connect( m_watcher, SIGNAL( created(const QString &) ),
+             parent, SLOT( delayedIncrementalScanParent(const QString &) ) );
+    connect( m_watcher, SIGNAL( deleted(const QString &) ),
+             parent, SLOT( delayedIncrementalScanParent(const QString &) ) );
+
+    m_watcher->startScan( false );
+}
+
+void
+DirWatchJob::run()
+{
+    DEBUG_BLOCK;
+
+    // -- update the KDirWatch with the current set of directories
+    QSet<QString> dirs = \
m_collection->mountPointManager()->collectionFolders().toSet(); +
+    // - add new
+    QSet<QString> newDirs = dirs - m_oldWatchDirs;
+    foreach( const QString& dir, newDirs )
+    {
+        m_watcher->addDir( dir,
+                           AmarokConfig::scanRecursively() ?
+                           KDirWatch::WatchSubDirs : KDirWatch::WatchDirOnly );
+    }
+
+    // - remove old
+    QSet<QString> removeDirs = m_oldWatchDirs - dirs;
+    foreach( const QString& dir, removeDirs )
+    {
+        m_watcher->removeDir( dir );
+    }
+
+    m_oldWatchDirs = dirs;
+}
+
+void
+DirWatchJob::setPaused( bool pause )
+{
+    DEBUG_BLOCK;
+
+    if( pause && !m_watcher->isStopped() )
+        m_watcher->stopScan();
+    else if( !pause && m_watcher->isStopped() )
+        m_watcher->startScan( true );
+}
+
 
 ///////////////////////////////////////////////////////////////////////////////
 // class ScannerJob
diff --git a/src/core-impl/collections/db/ScanManager.h \
b/src/core-impl/collections/db/ScanManager.h index 9f88e69..a8f7a05 100644
--- a/src/core-impl/collections/db/ScanManager.h
+++ b/src/core-impl/collections/db/ScanManager.h
@@ -36,6 +36,7 @@
 #include <threadweaver/Job.h>
 #include <KUrl>
 
+class DirWatchJob;
 class ScannerJob;
 
 class QTimer;
@@ -150,11 +151,10 @@ class AMAROK_DATABASECOLLECTION_EXPORT_TESTS ScanManager : \
public QObject  QSet<QString> m_scanDirsRequested;
         QIODevice *m_importRequested;
 
+        DirWatchJob *m_watcherJob;
+
         QTimer* m_checkDirsTimer;
         QTimer* m_delayedScanTimer;
-        QSet<QString> m_oldWatchDirs;
-        KDirWatch *m_watcher;
-
         /**
            This mutex is protecting the variables:
            m_fullScanRequested, m_scanDirsRequested, m_importRequested, m_scanner
@@ -162,6 +162,26 @@ class AMAROK_DATABASECOLLECTION_EXPORT_TESTS ScanManager : \
public QObject  QMutex m_mutex;
 };
 
+/** This is the job only owns the KDirWatch and adds folders it.
+    This will prevent the directory adding from blocking the UI.
+*/
+class DirWatchJob : public ThreadWeaver::Job
+{
+    Q_OBJECT
+
+    public:
+        DirWatchJob( QObject *parent, Collections::DatabaseCollection *collection );
+
+        void run();
+        void setPaused( bool pause );
+
+    private:
+        Collections::DatabaseCollection *m_collection;
+
+        QSet<QString> m_oldWatchDirs;
+        KDirWatch *m_watcher;
+};
+
 /** This is the job that does all the hard work with scanning.
     It will receive new data from the scanner process, parse it and call the
     ScanResultProcessor.


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

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