1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-13 17:43:59 +02:00

Don't add directories to the watcher if watch for changes is disabled

This commit is contained in:
Jeff Mitchell
2011-04-14 16:50:38 -04:00
parent 3ce41c50bc
commit 4b13467e4c
2 changed files with 18 additions and 34 deletions

View File

@@ -67,10 +67,12 @@ ScanManager::ScanManager( QObject* parent )
connect( m_dirWatcher, SIGNAL( directoryChanged( const QString & ) ), SLOT( handleChangedDir( const QString & ) ) );
if ( TomahawkSettings::instance()->hasScannerPaths() )
{
m_currScannerPaths = TomahawkSettings::instance()->scannerPaths();
qDebug() << "loading initial directories to watch";
QTimer::singleShot( 1000, this, SLOT( startupWatchPaths() ) );
if ( TomahawkSettings::instance()->watchForChanges() )
QTimer::singleShot( 1000, this, SLOT( runStartupScan() ) );
}
m_deferredScanTimer->start();
}
@@ -109,7 +111,6 @@ ScanManager::onSettingsChanged()
{
m_currScannerPaths = TomahawkSettings::instance()->scannerPaths();
m_dirWatcher->removePaths( m_dirWatcher->directories() );
m_dirWatcher->addPaths( m_currScannerPaths );
runManualScan( m_currScannerPaths );
}
@@ -119,35 +120,13 @@ ScanManager::onSettingsChanged()
}
void
ScanManager::startupWatchPaths()
void ScanManager::runStartupScan()
{
qDebug() << Q_FUNC_INFO;
if( !Database::instance() || ( Database::instance() && !Database::instance()->isReady() ) )
{
QTimer::singleShot( 1000, this, SLOT( startupWatchPaths() ) );
return;
}
DatabaseCommand_DirMtimes* cmd = new DatabaseCommand_DirMtimes( m_currScannerPaths );
connect( cmd, SIGNAL( done( QMap< QString, unsigned int > ) ),
SLOT( setInitialPaths( QMap< QString, unsigned int > ) ) );
Database::instance()->enqueue( QSharedPointer< DatabaseCommand >( cmd ) );
}
void
ScanManager::setInitialPaths( QMap< QString, unsigned int > pathMap )
{
qDebug() << Q_FUNC_INFO;
foreach( QString path, pathMap.keys() )
{
qDebug() << "Adding " << path << " to watcher";
m_dirWatcher->addPath( path );
}
if( TomahawkSettings::instance()->hasScannerPaths() && TomahawkSettings::instance()->watchForChanges() )
runManualScan( TomahawkSettings::instance()->scannerPaths() );
QTimer::singleShot( 1000, this, SLOT( runStartupScan() ) );
else
runManualScan( m_currScannerPaths );
}
@@ -156,6 +135,9 @@ ScanManager::runManualScan( const QStringList& paths, bool recursive )
{
qDebug() << Q_FUNC_INFO;
if( !Database::instance() || ( Database::instance() && !Database::instance()->isReady() ) )
return;
if ( !m_musicScannerThreadController && !m_scanner ) //still running if these are not zero
{
m_musicScannerThreadController = new QThread( this );
@@ -193,10 +175,13 @@ void
ScanManager::addWatchedDirs( const QStringList& paths )
{
qDebug() << Q_FUNC_INFO;
if ( !TomahawkSettings::instance()->watchForChanges() )
return;
QStringList currentWatchedPaths = m_dirWatcher->directories();
foreach( QString path, paths )
foreach ( QString path, paths )
{
if( !currentWatchedPaths.contains( path ) )
if ( !currentWatchedPaths.contains( path ) )
{
qDebug() << "adding " << path << " to watched dirs";
m_dirWatcher->addPath( path );

View File

@@ -49,14 +49,13 @@ public slots:
void handleChangedDir( const QString& path );
void addWatchedDirs( const QStringList& paths );
void removeWatchedDir( const QString& path );
void setInitialPaths( QMap< QString, unsigned int > pathMap );
private slots:
void scannerQuit();
void scannerFinished();
void scannerDestroyed( QObject* scanner );
void startupWatchPaths();
void runStartupScan();
void queuedScanTimeout();
void deferredScanTimeout();