mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-13 17:43:59 +02:00
Make scanning more async so if you quit in the middle you don't have to sit there waiting for the entire scan to finish
This commit is contained in:
@@ -61,19 +61,35 @@ DirLister::go()
|
|||||||
}
|
}
|
||||||
|
|
||||||
foreach( QString dir, m_dirs )
|
foreach( QString dir, m_dirs )
|
||||||
scanDir( QDir( dir, 0 ), 0, ( m_recursive ? DirLister::Recursive : DirLister::NonRecursive ) );
|
{
|
||||||
emit finished( m_newdirmtimes );
|
m_opcount++;
|
||||||
|
QMetaObject::invokeMethod( this, "scanDir", Qt::QueuedConnection, Q_ARG( QDir, QDir( dir, 0 ) ), Q_ARG( int, 0 ), Q_ARG( DirLister::Mode, ( m_recursive ? DirLister::Recursive : DirLister::NonRecursive ) ) );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
DirLister::scanDir( QDir dir, int depth, DirLister::Mode mode )
|
DirLister::scanDir( QDir dir, int depth, DirLister::Mode mode )
|
||||||
{
|
{
|
||||||
|
if ( isDeleting() )
|
||||||
|
{
|
||||||
|
m_opcount--;
|
||||||
|
if ( m_opcount == 0 )
|
||||||
|
emit finished( m_newdirmtimes );
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
//qDebug() << "DirLister::scanDir scanning: " << dir.canonicalPath() << " with mode " << mode;
|
//qDebug() << "DirLister::scanDir scanning: " << dir.canonicalPath() << " with mode " << mode;
|
||||||
|
|
||||||
if( !dir.exists() )
|
if( !dir.exists() )
|
||||||
{
|
{
|
||||||
qDebug() << "Dir no longer exists, not scanning";
|
qDebug() << "Dir no longer exists, not scanning";
|
||||||
|
|
||||||
|
m_opcount--;
|
||||||
|
if ( m_opcount == 0 )
|
||||||
|
emit finished( m_newdirmtimes );
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,9 +113,7 @@ DirLister::scanDir( QDir dir, int depth, DirLister::Mode mode )
|
|||||||
dir.setSorting( QDir::Name );
|
dir.setSorting( QDir::Name );
|
||||||
dirs = dir.entryInfoList();
|
dirs = dir.entryInfoList();
|
||||||
foreach( const QFileInfo& di, dirs )
|
foreach( const QFileInfo& di, dirs )
|
||||||
{
|
|
||||||
emit fileToScan( di );
|
emit fileToScan( di );
|
||||||
}
|
|
||||||
}
|
}
|
||||||
dir.setFilter( QDir::Dirs | QDir::Readable | QDir::NoDotAndDotDot );
|
dir.setFilter( QDir::Dirs | QDir::Readable | QDir::NoDotAndDotDot );
|
||||||
dirs = dir.entryInfoList();
|
dirs = dir.entryInfoList();
|
||||||
@@ -111,9 +125,14 @@ DirLister::scanDir( QDir dir, int depth, DirLister::Mode mode )
|
|||||||
const bool haveDi = m_dirmtimes.contains( canonical );
|
const bool haveDi = m_dirmtimes.contains( canonical );
|
||||||
//qDebug() << "m_dirmtimes contains it?" << haveDi;
|
//qDebug() << "m_dirmtimes contains it?" << haveDi;
|
||||||
if( !m_newdirmtimes.contains( canonical ) && ( mode == DirLister::Recursive || !haveDi ) ) {
|
if( !m_newdirmtimes.contains( canonical ) && ( mode == DirLister::Recursive || !haveDi ) ) {
|
||||||
scanDir( di.canonicalFilePath(), depth + 1, DirLister::Recursive );
|
m_opcount++;
|
||||||
|
QMetaObject::invokeMethod( this, "scanDir", Qt::QueuedConnection, Q_ARG( QDir, di.canonicalFilePath() ), Q_ARG( int, depth + 1 ), Q_ARG( DirLister::Mode, DirLister::Recursive ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_opcount--;
|
||||||
|
if ( m_opcount == 0 )
|
||||||
|
emit finished( m_newdirmtimes );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -143,7 +162,8 @@ MusicScanner::~MusicScanner()
|
|||||||
|
|
||||||
if ( !m_dirLister.isNull() )
|
if ( !m_dirLister.isNull() )
|
||||||
{
|
{
|
||||||
QMetaObject::invokeMethod( m_dirLister.data(), "deleteLater", Qt::QueuedConnection );
|
m_dirLister.data()->setIsDeleting();
|
||||||
|
QMetaObject::invokeMethod( m_dirLister.data(), "deleteLater", Qt::DirectConnection );
|
||||||
while( !m_dirLister.isNull() )
|
while( !m_dirLister.isNull() )
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO << " scanner not deleted";
|
qDebug() << Q_FUNC_INFO << " scanner not deleted";
|
||||||
@@ -242,7 +262,7 @@ MusicScanner::scan()
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
MusicScanner::listerFinished( const QMap<QString, unsigned int>& newmtimes )
|
MusicScanner::listerFinished( const QMap<QString, unsigned int>& newmtimes )
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO;
|
qDebug() << Q_FUNC_INFO;
|
||||||
|
|
||||||
@@ -263,50 +283,19 @@ MusicScanner::listerFinished( const QMap<QString, unsigned int>& newmtimes )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// save mtimes, then quit thread
|
|
||||||
DatabaseCommand_DirMtimes* cmd = new DatabaseCommand_DirMtimes( newmtimes );
|
|
||||||
connect( cmd, SIGNAL( finished() ), SLOT( deleteLister() ) );
|
|
||||||
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>(cmd) );
|
|
||||||
|
|
||||||
qDebug() << "Scanning complete, saving to database. "
|
qDebug() << "Scanning complete, saving to database. "
|
||||||
"( scanned" << m_scanned << "skipped" << m_skipped << ")";
|
"( scanned" << m_scanned << "skipped" << m_skipped << ")";
|
||||||
|
|
||||||
qDebug() << "Skipped the following files (no tags / no valid audio):";
|
qDebug() << "Skipped the following files (no tags / no valid audio):";
|
||||||
foreach( const QString& s, m_skippedFiles )
|
foreach( const QString& s, m_skippedFiles )
|
||||||
qDebug() << s;
|
qDebug() << s;
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
// save mtimes, then quit thread
|
||||||
MusicScanner::deleteLister()
|
DatabaseCommand_DirMtimes* cmd = new DatabaseCommand_DirMtimes( newmtimes );
|
||||||
{
|
connect( cmd, SIGNAL( finished() ), SIGNAL( finished() ) );
|
||||||
if ( !m_dirLister.isNull() )
|
|
||||||
{
|
|
||||||
QMetaObject::invokeMethod( m_dirLister.data(), "deleteLater", Qt::QueuedConnection );
|
|
||||||
while( !m_dirLister.isNull() )
|
|
||||||
{
|
|
||||||
qDebug() << Q_FUNC_INFO << " scanner not deleted, processing events";
|
|
||||||
QCoreApplication::processEvents( QEventLoop::AllEvents, 200 );
|
|
||||||
TomahawkUtils::Sleep::msleep( 100 );
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( m_dirListerThreadController )
|
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>(cmd) );
|
||||||
m_dirListerThreadController->quit();
|
|
||||||
|
|
||||||
if( m_dirListerThreadController )
|
|
||||||
{
|
|
||||||
while( !m_dirListerThreadController->isFinished() )
|
|
||||||
{
|
|
||||||
qDebug() << Q_FUNC_INFO << " scanner thread controller not finished, processing events";
|
|
||||||
QCoreApplication::processEvents( QEventLoop::AllEvents, 200 );
|
|
||||||
TomahawkUtils::Sleep::msleep( 100 );
|
|
||||||
}
|
|
||||||
|
|
||||||
delete m_dirListerThreadController;
|
|
||||||
m_dirListerThreadController = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
emit finished();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -50,7 +50,7 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
DirLister( const QStringList& dirs, const QMap<QString, unsigned int>& dirmtimes, TomahawkSettings::ScannerMode mode, bool manualFull, bool recursive )
|
DirLister( const QStringList& dirs, const QMap<QString, unsigned int>& dirmtimes, TomahawkSettings::ScannerMode mode, bool manualFull, bool recursive )
|
||||||
: QObject(), m_dirs( dirs ), m_dirmtimes( dirmtimes ), m_mode( mode ), m_manualFull( manualFull ), m_recursive( recursive )
|
: QObject(), m_dirs( dirs ), m_dirmtimes( dirmtimes ), m_mode( mode ), m_manualFull( manualFull ), m_recursive( recursive ), m_opcount( 0 ), m_deleting( false )
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO;
|
qDebug() << Q_FUNC_INFO;
|
||||||
}
|
}
|
||||||
@@ -60,6 +60,9 @@ public:
|
|||||||
qDebug() << Q_FUNC_INFO;
|
qDebug() << Q_FUNC_INFO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool isDeleting() { QMutexLocker locker( &m_deletingMutex ); return m_deleting; };
|
||||||
|
void setIsDeleting() { QMutexLocker locker( &m_deletingMutex ); m_deleting = true; };
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void fileToScan( QFileInfo );
|
void fileToScan( QFileInfo );
|
||||||
void finished( const QMap<QString, unsigned int>& );
|
void finished( const QMap<QString, unsigned int>& );
|
||||||
@@ -76,6 +79,10 @@ private:
|
|||||||
bool m_recursive;
|
bool m_recursive;
|
||||||
|
|
||||||
QMap<QString, unsigned int> m_newdirmtimes;
|
QMap<QString, unsigned int> m_newdirmtimes;
|
||||||
|
|
||||||
|
uint m_opcount;
|
||||||
|
QMutex m_deletingMutex;
|
||||||
|
bool m_deleting;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -97,7 +104,6 @@ private:
|
|||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void listerFinished( const QMap<QString, unsigned int>& newmtimes );
|
void listerFinished( const QMap<QString, unsigned int>& newmtimes );
|
||||||
void deleteLister();
|
|
||||||
void scanFile( const QFileInfo& fi );
|
void scanFile( const QFileInfo& fi );
|
||||||
void startScan();
|
void startScan();
|
||||||
void scan();
|
void scan();
|
||||||
|
@@ -71,10 +71,10 @@ ScanManager::~ScanManager()
|
|||||||
|
|
||||||
if ( !m_scanner.isNull() )
|
if ( !m_scanner.isNull() )
|
||||||
{
|
{
|
||||||
QMetaObject::invokeMethod( m_scanner.data(), "deleteLater", Qt::QueuedConnection );
|
QMetaObject::invokeMethod( m_scanner.data(), "deleteLater", Qt::DirectConnection );
|
||||||
while( !m_scanner.isNull() )
|
while( !m_scanner.isNull() )
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO << " scanner not delete";
|
qDebug() << Q_FUNC_INFO << " scanner not deleted";
|
||||||
TomahawkUtils::Sleep::msleep( 50 );
|
TomahawkUtils::Sleep::msleep( 50 );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -179,12 +179,11 @@ ScanManager::scannerFinished()
|
|||||||
{
|
{
|
||||||
if ( !m_scanner.isNull() )
|
if ( !m_scanner.isNull() )
|
||||||
{
|
{
|
||||||
QMetaObject::invokeMethod( m_scanner.data(), "deleteLater", Qt::QueuedConnection );
|
QMetaObject::invokeMethod( m_scanner.data(), "deleteLater", Qt::DirectConnection );
|
||||||
while( !m_scanner.isNull() )
|
while( !m_scanner.isNull() )
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO << " scanner not deleted, processing events";
|
qDebug() << Q_FUNC_INFO << " scanner not deleted";
|
||||||
QCoreApplication::processEvents( QEventLoop::AllEvents, 200 );
|
TomahawkUtils::Sleep::msleep( 50 );
|
||||||
TomahawkUtils::Sleep::msleep( 100 );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( m_musicScannerThreadController )
|
if ( m_musicScannerThreadController )
|
||||||
@@ -194,9 +193,8 @@ ScanManager::scannerFinished()
|
|||||||
{
|
{
|
||||||
while( !m_musicScannerThreadController->isFinished() )
|
while( !m_musicScannerThreadController->isFinished() )
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO << " scanner thread controller not finished, processing events";
|
qDebug() << Q_FUNC_INFO << " scanner thread controller not finished";
|
||||||
QCoreApplication::processEvents( QEventLoop::AllEvents, 200 );
|
TomahawkUtils::Sleep::msleep( 50 );
|
||||||
TomahawkUtils::Sleep::msleep( 100 );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
delete m_musicScannerThreadController;
|
delete m_musicScannerThreadController;
|
||||||
|
@@ -51,6 +51,7 @@
|
|||||||
#include "globalactionmanager.h"
|
#include "globalactionmanager.h"
|
||||||
#include "webcollection.h"
|
#include "webcollection.h"
|
||||||
#include "database/localcollection.h"
|
#include "database/localcollection.h"
|
||||||
|
#include "musicscanner.h"
|
||||||
|
|
||||||
#include "audio/audioengine.h"
|
#include "audio/audioengine.h"
|
||||||
#include "utils/xspfloader.h"
|
#include "utils/xspfloader.h"
|
||||||
@@ -364,6 +365,7 @@ TomahawkApp::registerMetaTypes()
|
|||||||
qRegisterMetaType< QTcpSocket* >("QTcpSocket*");
|
qRegisterMetaType< QTcpSocket* >("QTcpSocket*");
|
||||||
qRegisterMetaType< QSharedPointer<QIODevice> >("QSharedPointer<QIODevice>");
|
qRegisterMetaType< QSharedPointer<QIODevice> >("QSharedPointer<QIODevice>");
|
||||||
qRegisterMetaType< QFileInfo >("QFileInfo");
|
qRegisterMetaType< QFileInfo >("QFileInfo");
|
||||||
|
qRegisterMetaType< QDir >("QDir");
|
||||||
qRegisterMetaType< QHostAddress >("QHostAddress");
|
qRegisterMetaType< QHostAddress >("QHostAddress");
|
||||||
qRegisterMetaType< QMap<QString, unsigned int> >("QMap<QString, unsigned int>");
|
qRegisterMetaType< QMap<QString, unsigned int> >("QMap<QString, unsigned int>");
|
||||||
qRegisterMetaType< QMap< QString, plentry_ptr > >("QMap< QString, plentry_ptr >");
|
qRegisterMetaType< QMap< QString, plentry_ptr > >("QMap< QString, plentry_ptr >");
|
||||||
@@ -404,6 +406,8 @@ TomahawkApp::registerMetaTypes()
|
|||||||
qRegisterMetaType< QHash< QString, QString > >( "Tomahawk::InfoSystem::InfoCriteriaHash" );
|
qRegisterMetaType< QHash< QString, QString > >( "Tomahawk::InfoSystem::InfoCriteriaHash" );
|
||||||
qRegisterMetaType< Tomahawk::InfoSystem::InfoType >( "Tomahawk::InfoSystem::InfoType" );
|
qRegisterMetaType< Tomahawk::InfoSystem::InfoType >( "Tomahawk::InfoSystem::InfoType" );
|
||||||
qRegisterMetaType< QWeakPointer< Tomahawk::InfoSystem::InfoSystemCache > >( "QWeakPointer< Tomahawk::InfoSystem::InfoSystemCache >" );
|
qRegisterMetaType< QWeakPointer< Tomahawk::InfoSystem::InfoSystemCache > >( "QWeakPointer< Tomahawk::InfoSystem::InfoSystemCache >" );
|
||||||
|
|
||||||
|
qRegisterMetaType< DirLister::Mode >("DirLister::Mode");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user