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

List:       kde-commits
Subject:    extragear/multimedia/amarok/src
From:       Mark Kretschmann <markey () web ! de>
Date:       2005-11-03 8:43:53
Message-ID: 1131007433.593330.12729.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 477155 by markey:

Add initial code for incremental scanning.

 M  +63 -8     scancontroller.cpp  
 M  +12 -7     scancontroller.h  


--- trunk/extragear/multimedia/amarok/src/scancontroller.cpp #477154:477155
@@ -27,6 +27,10 @@
 #include "scancontroller.h"
 #include "statusbar.h"
 
+#include <sys/stat.h>  //stat
+#include <sys/types.h> //stat
+#include <unistd.h>    //stat
+
 #include <klocale.h>
 #include <kprocio.h>
 
@@ -55,11 +59,13 @@
 // class ScanController
 ////////////////////////////////////////////////////////////////////////////////
 
-ScanController::ScanController( QObject* parent, QStringList folders )
+ScanController::ScanController( QObject* parent, const QStringList& folders, bool \
incremental )  : QObject( parent )
     , QXmlDefaultHandler()
     , m_db( CollectionDB::instance()->getStaticDbConnection() )
     , m_scanner( new ScannerProcIO() )
+    , m_folders( folders )
+    , m_incremental( incremental )
     , m_steps( 0 )
     , m_success( false )
 {
@@ -69,10 +75,13 @@
         deleteLater();
         return;
     }
+    if( m_incremental )
+        initIncrementalScanner();
+
     CollectionDB::instance()->createTables( m_db );
 
     StatusBar::instance()->newProgressOperation( this )
-            .setDescription( i18n( "Building Collection" ) )
+            .setDescription( m_incremental ? i18n( "Updating Collection" ) : i18n( \
                "Building Collection" ) )
             .setAbortSlot( this, SLOT( deleteLater() ) )
             .setTotalSteps( 100 );
 
@@ -80,9 +89,9 @@
     m_reader.parse( &m_source, true );
 
     *m_scanner << "amarokcollectionscanner";
-    if( AmarokConfig::importPlaylists() ) *m_scanner << "-i";
+    if( AmarokConfig::importPlaylists() && !m_incremental ) *m_scanner << "-i";
     if( AmarokConfig::scanRecursively() ) *m_scanner << "-r";
-    *m_scanner << folders;
+    *m_scanner << m_folders;
 
     connect( m_scanner, SIGNAL( readReady( KProcIO* ) ),      SLOT( slotReadReady() \
                ) );
     connect( m_scanner, SIGNAL( processExited( KProcess* ) ), SLOT( \
slotProcessExited() ) ); @@ -107,6 +116,50 @@
 }
 
 
+void
+ScanController::initIncrementalScanner()
+{
+    /**
+     * The Incremental Reader works as follows: Here we check the mtime of every \
directory in the "directories" +     * table and store all changed directories in \
m_folders. +     *
+     * These directories are then scanned in CollectionReader::doJob(), with \
m_recursively set according to the +     * user's preference, so the user can add \
directories or whole directory trees, too. Since we don't want to +     * rescan \
unchanged subdirectories, CollectionReader::readDir() checks if we are scanning \
recursively and +     * prevents that.
+     */
+
+    //TODO Replace stat() with Qt methods
+
+    DEBUG_BLOCK
+
+    struct stat statBuf;
+    const QStringList values = CollectionDB::instance()->query( "SELECT dir, \
changedate FROM directories;" ); +
+    foreach( values ) {
+        const QString folder = *it;
+        const QString mtime  = *++it;
+
+        if( stat( QFile::encodeName( folder ), &statBuf ) == 0 ) {
+            if( QString::number( (long)statBuf.st_mtime ) != mtime ) {
+                m_folders << folder;
+                debug() << "Collection dir changed: " << folder << endl;
+            }
+        }
+        else {
+            // this folder has been removed
+            m_folders << folder;
+            debug() << "Collection dir removed: " << folder << endl;
+        }
+    }
+
+    if( !m_folders.isEmpty() ) {
+//         m_hasChanged = true;
+        StatusBar::instance()->shortMessage( i18n( "Updating Collection..." ) );
+    }
+}
+
+
 bool
 ScanController::startElement( const QString&, const QString& localName, const \
QString&, const QXmlAttributes& attrs )  {
@@ -139,7 +192,7 @@
             bundle.setSampleRate( attrs.value( "samplerate" ).toInt() );
         }
 
-        CollectionDB::instance()->addSong( &bundle, false /*m_incremental*/, m_db );
+        CollectionDB::instance()->addSong( &bundle, m_incremental, m_db );
     }
 
 
@@ -169,8 +222,12 @@
     DEBUG_BLOCK
 
     if( m_scanner->normalExit() ) {
+        if ( m_incremental )
+            foreach( m_folders ) CollectionDB::instance()->removeSongsInDir( *it );
+        else
+            CollectionDB::instance()->clearTables();
+
         m_success = true;
-        CollectionDB::instance()->clearTables();
         CollectionDB::instance()->moveTempTables( m_db ); // rename tables
     }
     else
@@ -181,5 +238,3 @@
 
 
 #include "scancontroller.moc"
-
-
--- trunk/extragear/multimedia/amarok/src/scancontroller.h #477154:477155
@@ -20,8 +20,8 @@
 #ifndef AMAROK_SCANCONTROLLER_H
 #define AMAROK_SCANCONTROLLER_H
 
-#include <qobject.h>
-#include <qxml.h>
+#include <qobject.h>     //baseclass
+#include <qxml.h>        //baseclass
 
 class DbConnection;
 class KProcIO;
@@ -34,7 +34,7 @@
     Q_OBJECT
 
     public:
-        ScanController( QObject* parent, QStringList folders );
+        ScanController( QObject* parent, const QStringList& folders, bool \
incremental = false );  ~ScanController();
 
     private slots:
@@ -42,15 +42,20 @@
         void slotProcessExited();
 
     private:
+        void initIncrementalScanner();
         bool startElement( const QString&, const QString &localName, const QString&, \
const QXmlAttributes &attrs );  
 
         DbConnection* const m_db;
-        KProcIO* m_scanner;
-        QXmlInputSource m_source;
+        KProcIO*            m_scanner;
+        QStringList         m_folders;
+
+        QXmlInputSource  m_source;
         QXmlSimpleReader m_reader;
-        int m_steps;
-        int m_totalSteps;
+
+        bool m_incremental;
+        int  m_steps;
+        int  m_totalSteps;
         bool m_success;
 };
 


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

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