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

List:       kde-commits
Subject:    extragear/multimedia/amarok/src/collectionscanner
From:       Jeff Mitchell <kde-dev () emailgoeshere ! com>
Date:       2009-03-07 21:45:03
Message-ID: 1236462303.921773.26707.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 936550 by mitchell:

Checkin of incremental work towards incremental batchmode scanning



 M  +39 -2     CollectionScanner.cpp  
 M  +4 -0      CollectionScanner.h  
 M  +3 -3      main.cpp  


--- trunk/extragear/multimedia/amarok/src/collectionscanner/CollectionScanner.cpp \
#936549:936550 @@ -82,12 +82,14 @@
         , m_batch( batch )
         , m_importPlaylists( importPlaylists )
         , m_folders( folders )
+        , m_batchFolderTime()
         , m_recursively( recursive )
         , m_incremental( incremental )
         , m_restart( restart )
         , m_logfile( batch ? ( incremental ? \
"amarokcollectionscanner_batchincrementalscan.log" : \
"amarokcollectionscanner_batchfullscan.log" )  : saveLocation() + \
"collection_scan.log" )  , m_rpath( rpath )
+        , m_amarokCollectionInterface( 0 )
 {
     kapp->setObjectName( "amarokcollectionscanner" );
     if( !restart )
@@ -100,9 +102,14 @@
         else
             m_amarokCollectionInterface = new QDBusInterface( "org.kde.amarok-" + \
amarokPid, "/SqlCollection/" + collectionId );  }
-    else
-        m_amarokCollectionInterface = 0;
 
+    if( m_batch && m_incremental )
+    {
+        bool success = readBatchIncrementalFile();
+        if( !success )
+            return;
+    }
+
     QTimer::singleShot( 0, this, SLOT( doJob() ) );
 }
 
@@ -112,7 +119,37 @@
     delete m_amarokCollectionInterface;
 }
 
+//Populates m_folders with folders from that pointed to file, but only if the mtime \
of the folder +//is greater than the mtime of the file itself
+bool
+CollectionScanner::readBatchIncrementalFile()
+{
+    QStringList newFolders;
+    if( !QFile::exists( m_folders.first() ) )
+        return false;
 
+    QFile folderFile( m_folders.first() );
+    if( !folderFile.open( QIODevice::ReadOnly ) )
+        return false;
+
+    m_folders.clear();
+    
+    QTextStream folderStream;
+    folderStream.setDevice( &folderFile );
+
+    QString temp = folderStream.readLine();
+    while( !temp.isEmpty() )
+    {
+        //TODO: check mtimes here
+        //TODO: rpath substitution?
+        m_folders << temp;
+        temp = folderStream.readLine();
+    }
+    
+    folderFile.close();
+    return true;
+}
+
 void
 CollectionScanner::doJob() //SLOT
 {
--- trunk/extragear/multimedia/amarok/src/collectionscanner/CollectionScanner.h \
#936549:936550 @@ -27,6 +27,7 @@
 #include <sys/stat.h>
 #include <unistd.h>
 
+#include <QDateTime>
 #include <QDBusInterface>
 #include <QHash>
 #include <QStringList>
@@ -77,6 +78,8 @@
 
     inline QString saveLocation() const { return KGlobal::dirs()->saveLocation( \
"data", QString("amarok/"), true ); }  
+    bool readBatchIncrementalFile();
+
     void readDir( const QString& dir, QStringList& entries );
     void scanFiles( const QStringList& entries );
     
@@ -134,6 +137,7 @@
     const bool    m_batch;
     const bool    m_importPlaylists;
     QStringList   m_folders;
+    QDateTime     m_batchFolderTime;
     const bool    m_recursively;
     const bool    m_incremental;
     const bool    m_restart;
--- trunk/extragear/multimedia/amarok/src/collectionscanner/main.cpp #936549:936550
@@ -39,7 +39,7 @@
     KCmdLineArgs::init( argc, argv, &about ); //calls \
KCmdLineArgs::addStdCmdLineOptions()  
     KCmdLineOptions options;
-    options.add("+Folder(s)", ki18n( "Folders to scan" ));
+    options.add("+Folder(s)", ki18n( "Folders to scan; in batch incremental mode, \
the path to the folders file generated by Amarok" ));  options.add("r");
     options.add("recursive", ki18n( "Scan folders recursively" ));
     options.add("i");
@@ -62,14 +62,14 @@
     for( int i = 0; i < args->count(); i++ )
         folders << args->arg( i );
 
-    const bool recursive        = args->isSet( "recursive" );
     const bool batch            = args->isSet( "batch" );
-    const bool incremental      = ( batch ? false : args->isSet( "incremental" ) );
+    const bool incremental      = args->isSet( "incremental" );
     const bool importplaylists  = args->isSet( "importplaylists" );
     const bool restart          = args->isSet( "restart" );
     const QString rpath         = args->getOption( "rpath" );
     const QString pid           = args->getOption( "pid" );
     const QString collectionId  = args->getOption( "collectionid" );
+    const bool recursive        = ( ( batch && incremental ) ? false : args->isSet( \
"recursive" ) );  
     CollectionScanner scanner( folders, pid, collectionId, recursive, incremental, \
importplaylists, restart, batch, rpath );  


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

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