diff --git a/src/libtomahawk/database/databasecommand_filemtimes.cpp b/src/libtomahawk/database/databasecommand_filemtimes.cpp index f7e83311c..7aada7f10 100644 --- a/src/libtomahawk/database/databasecommand_filemtimes.cpp +++ b/src/libtomahawk/database/databasecommand_filemtimes.cpp @@ -40,7 +40,8 @@ DatabaseCommand_FileMtimes::execSelect( DatabaseImpl* dbi ) TomahawkSqlQuery query = dbi->newquery(); if( m_prefix.isEmpty() && m_prefixes.isEmpty() ) { - query.exec( "SELECT url, id, mtime FROM file WHERE source IS NULL" ); + QString limit( m_checkonly ? QString( " LIMIT 1" ) : QString() ); + query.exec( QString( "SELECT url, id, mtime FROM file WHERE source IS NULL%1" ).arg( limit ) ); while( query.next() ) { QMap< unsigned int, unsigned int > map; diff --git a/src/libtomahawk/database/databasecommand_filemtimes.h b/src/libtomahawk/database/databasecommand_filemtimes.h index 7322620cf..5d38cd775 100644 --- a/src/libtomahawk/database/databasecommand_filemtimes.h +++ b/src/libtomahawk/database/databasecommand_filemtimes.h @@ -36,13 +36,18 @@ Q_OBJECT public: explicit DatabaseCommand_FileMtimes( const QString& prefix = QString(), QObject* parent = 0 ) - : DatabaseCommand( parent ), m_prefix( prefix ) + : DatabaseCommand( parent ), m_prefix( prefix ), m_checkonly( false ) {} explicit DatabaseCommand_FileMtimes( const QStringList& prefixes, QObject* parent = 0 ) - : DatabaseCommand( parent ), m_prefixes( prefixes ) + : DatabaseCommand( parent ), m_prefixes( prefixes ), m_checkonly( false ) {} + //NOTE: when this is called we actually ignore the boolean flag; it's just used to give us the right constructor + explicit DatabaseCommand_FileMtimes( bool /*checkonly*/, QObject* parent = 0 ) + : DatabaseCommand( parent ), m_checkonly( true ) + {} + virtual void exec( DatabaseImpl* ); virtual bool doesMutates() const { return false; } virtual QString commandname() const { return "filemtimes"; } @@ -57,6 +62,7 @@ private: void execSelect( DatabaseImpl* dbi ); QString m_prefix; QStringList m_prefixes; + bool m_checkonly; }; #endif // DATABASECOMMAND_FILEMTIMES_H diff --git a/src/scanmanager.cpp b/src/scanmanager.cpp index 27e03c2a4..f54e27dd8 100644 --- a/src/scanmanager.cpp +++ b/src/scanmanager.cpp @@ -20,7 +20,6 @@ #include #include -#include #include #include "musicscanner.h" @@ -29,7 +28,7 @@ #include "libtomahawk/sourcelist.h" #include "database/database.h" -#include "database/databasecommand_dirmtimes.h" +#include "database/databasecommand_filemtimes.h" #include "database/databasecommand_deletefiles.h" #include "utils/logger.h" @@ -136,17 +135,39 @@ ScanManager::runScan( bool manualFull ) if ( !Database::instance() || ( Database::instance() && !Database::instance()->isReady() ) ) return; - if ( !manualFull ) + if ( manualFull ) { - runDirScan( TomahawkSettings::instance()->scannerPaths() ); + DatabaseCommand_DeleteFiles *cmd = new DatabaseCommand_DeleteFiles( SourceList::instance()->getLocal() ); + connect( cmd, SIGNAL( done( const QStringList&, const Tomahawk::collection_ptr& ) ), + SLOT( filesDeleted( const QStringList&, const Tomahawk::collection_ptr& ) ) ); + + Database::instance()->enqueue( QSharedPointer< DatabaseCommand >( cmd ) ); return; } - DatabaseCommand_DeleteFiles *cmd = new DatabaseCommand_DeleteFiles( SourceList::instance()->getLocal() ); - connect( cmd, SIGNAL( done( const QStringList&, const Tomahawk::collection_ptr& ) ), - SLOT( filesDeleted( const QStringList&, const Tomahawk::collection_ptr& ) ) ); - + DatabaseCommand_FileMtimes *cmd = new DatabaseCommand_FileMtimes( true ); + connect( cmd, SIGNAL( done( const QMap< QString, QMap< unsigned int, unsigned int > >& ) ), + SLOT( fileMtimesCheck( const QMap< QString, QMap< unsigned int, unsigned int > >& ) ) ); + Database::instance()->enqueue( QSharedPointer< DatabaseCommand >( cmd ) ); + +} + + +void +ScanManager::fileMtimesCheck( const QMap< QString, QMap< unsigned int, unsigned int > >& mtimes ) +{ + if ( !mtimes.isEmpty() && TomahawkSettings::instance()->scannerPaths().isEmpty() ) + { + DatabaseCommand_DeleteFiles *cmd = new DatabaseCommand_DeleteFiles( SourceList::instance()->getLocal() ); + connect( cmd, SIGNAL( done( const QStringList&, const Tomahawk::collection_ptr& ) ), + SLOT( filesDeleted( const QStringList&, const Tomahawk::collection_ptr& ) ) ); + + Database::instance()->enqueue( QSharedPointer< DatabaseCommand >( cmd ) ); + return; + } + + runDirScan(); } @@ -156,24 +177,20 @@ ScanManager::filesDeleted( const QStringList& files, const Tomahawk::collection_ Q_UNUSED( files ); Q_UNUSED( collection ); if ( !TomahawkSettings::instance()->scannerPaths().isEmpty() ) - runDirScan( TomahawkSettings::instance()->scannerPaths() ); + runDirScan(); } void -ScanManager::runDirScan( const QStringList& paths ) +ScanManager::runDirScan() { qDebug() << Q_FUNC_INFO; if ( !Database::instance() || ( Database::instance() && !Database::instance()->isReady() ) ) return; - if ( paths.isEmpty() ) - { - Database::instance()->enqueue( QSharedPointer< DatabaseCommand >( new DatabaseCommand_DeleteFiles( SourceList::instance()->getLocal() ) ) ); - return; - } - + QStringList paths = TomahawkSettings::instance()->scannerPaths(); + if ( !m_musicScannerThreadController && m_scanner.isNull() ) //still running if these are not zero { m_scanTimer->stop(); diff --git a/src/scanmanager.h b/src/scanmanager.h index fda5229a9..5688029dd 100644 --- a/src/scanmanager.h +++ b/src/scanmanager.h @@ -48,7 +48,7 @@ signals: public slots: void runScan( bool manualFull = false ); - void runDirScan( const QStringList& paths ); + void runDirScan(); private slots: void scannerFinished(); @@ -58,6 +58,7 @@ private slots: void onSettingsChanged(); + void fileMtimesCheck( const QMap< QString, QMap< unsigned int, unsigned int > >& mtimes ); void filesDeleted( const QStringList& files, const Tomahawk::collection_ptr& collection ); private: