mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-01 03:40:16 +02:00
More work on dir watchers -- it's mostly there except for the actual DB modifications
This commit is contained in:
@@ -38,21 +38,33 @@ DatabaseCommand_DirMtimes::execSelect( DatabaseImpl* dbi )
|
|||||||
{
|
{
|
||||||
QMap<QString,unsigned int> mtimes;
|
QMap<QString,unsigned int> mtimes;
|
||||||
TomahawkSqlQuery query = dbi->newquery();
|
TomahawkSqlQuery query = dbi->newquery();
|
||||||
if( m_prefix.isEmpty() )
|
if( m_prefix.isEmpty() && m_prefixes.isEmpty() )
|
||||||
query.exec( "SELECT name, mtime FROM dirs_scanned" );
|
query.exec( "SELECT name, mtime FROM dirs_scanned" );
|
||||||
|
else if( m_prefixes.isEmpty() )
|
||||||
|
execSelectPath( dbi, m_prefix, mtimes );
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
if( !m_prefix.isEmpty() )
|
||||||
|
execSelectPath( dbi, m_prefix, mtimes );
|
||||||
|
foreach( QString path, m_prefixes )
|
||||||
|
execSelectPath( dbi, path, mtimes );
|
||||||
|
}
|
||||||
|
emit done( mtimes );
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
DatabaseCommand_DirMtimes::execSelectPath( DatabaseImpl *dbi, QString &path, QMap<QString, unsigned int> &mtimes )
|
||||||
|
{
|
||||||
|
TomahawkSqlQuery query = dbi->newquery();
|
||||||
query.prepare( QString( "SELECT name, mtime "
|
query.prepare( QString( "SELECT name, mtime "
|
||||||
"FROM dirs_scanned "
|
"FROM dirs_scanned "
|
||||||
"WHERE name LIKE '%1%'" ).arg( m_prefix.replace( '\'',"''" ) ) );
|
"WHERE name LIKE '%1%'" ).arg( path.replace( '\'',"''" ) ) );
|
||||||
query.exec();
|
query.exec();
|
||||||
}
|
|
||||||
while( query.next() )
|
while( query.next() )
|
||||||
{
|
{
|
||||||
mtimes.insert( query.value( 0 ).toString(), query.value( 1 ).toUInt() );
|
mtimes.insert( query.value( 0 ).toString(), query.value( 1 ).toUInt() );
|
||||||
}
|
}
|
||||||
|
|
||||||
emit done( mtimes );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -38,6 +38,10 @@ public:
|
|||||||
: DatabaseCommand( parent ), m_prefix( prefix ), m_update( false )
|
: DatabaseCommand( parent ), m_prefix( prefix ), m_update( false )
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
explicit DatabaseCommand_DirMtimes( const QStringList& prefixes = QStringList(), QObject* parent = 0 )
|
||||||
|
: DatabaseCommand( parent ), m_prefixes( prefixes ), m_update( false )
|
||||||
|
{}
|
||||||
|
|
||||||
explicit DatabaseCommand_DirMtimes( QMap<QString, unsigned int> tosave, QObject* parent = 0 )
|
explicit DatabaseCommand_DirMtimes( QMap<QString, unsigned int> tosave, QObject* parent = 0 )
|
||||||
: DatabaseCommand( parent ), m_update( true ), m_tosave( tosave )
|
: DatabaseCommand( parent ), m_update( true ), m_tosave( tosave )
|
||||||
{}
|
{}
|
||||||
@@ -52,9 +56,12 @@ signals:
|
|||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void execSelectPath( DatabaseImpl *dbi, QString &path, QMap<QString, unsigned int> &mtimes );
|
||||||
|
|
||||||
void execSelect( DatabaseImpl* dbi );
|
void execSelect( DatabaseImpl* dbi );
|
||||||
void execUpdate( DatabaseImpl* dbi );
|
void execUpdate( DatabaseImpl* dbi );
|
||||||
QString m_prefix;
|
QString m_prefix;
|
||||||
|
QStringList m_prefixes;
|
||||||
bool m_update;
|
bool m_update;
|
||||||
QMap<QString, unsigned int> m_tosave;
|
QMap<QString, unsigned int> m_tosave;
|
||||||
};
|
};
|
||||||
|
@@ -185,9 +185,12 @@ MusicScanner::listerFinished( const QMap<QString, unsigned int>& newmtimes )
|
|||||||
{
|
{
|
||||||
qDebug() << "Removing stale dir:" << path;
|
qDebug() << "Removing stale dir:" << path;
|
||||||
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( new DatabaseCommand_DeleteFiles( path, SourceList::instance()->getLocal() ) ) );
|
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( new DatabaseCommand_DeleteFiles( path, SourceList::instance()->getLocal() ) ) );
|
||||||
|
emit removeWatchedDir( path );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
emit addWatchedDirs( newmtimes.keys() );
|
||||||
|
|
||||||
// save mtimes, then quit thread
|
// save mtimes, then quit thread
|
||||||
DatabaseCommand_DirMtimes* cmd = new DatabaseCommand_DirMtimes( newmtimes );
|
DatabaseCommand_DirMtimes* cmd = new DatabaseCommand_DirMtimes( newmtimes );
|
||||||
connect( cmd, SIGNAL( finished() ), SLOT( deleteLister() ) );
|
connect( cmd, SIGNAL( finished() ), SLOT( deleteLister() ) );
|
||||||
|
@@ -76,6 +76,8 @@ signals:
|
|||||||
//void fileScanned( QVariantMap );
|
//void fileScanned( QVariantMap );
|
||||||
void finished();
|
void finished();
|
||||||
void batchReady( const QVariantList& );
|
void batchReady( const QVariantList& );
|
||||||
|
void addWatchedDirs( const QStringList & );
|
||||||
|
void removeWatchedDir( const QString & );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QVariant readFile( const QFileInfo& fi );
|
QVariant readFile( const QFileInfo& fi );
|
||||||
|
@@ -22,11 +22,15 @@
|
|||||||
#include <QThread>
|
#include <QThread>
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
#include <QFileSystemWatcher>
|
#include <QFileSystemWatcher>
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
#include "musicscanner.h"
|
#include "musicscanner.h"
|
||||||
#include "tomahawksettings.h"
|
#include "tomahawksettings.h"
|
||||||
#include "tomahawkutils.h"
|
#include "tomahawkutils.h"
|
||||||
|
|
||||||
|
#include "database/database.h"
|
||||||
|
#include "database/databasecommand_dirmtimes.h"
|
||||||
|
|
||||||
ScanManager* ScanManager::s_instance = 0;
|
ScanManager* ScanManager::s_instance = 0;
|
||||||
|
|
||||||
|
|
||||||
@@ -53,8 +57,8 @@ ScanManager::ScanManager( QObject* parent )
|
|||||||
if ( TomahawkSettings::instance()->hasScannerPath() )
|
if ( TomahawkSettings::instance()->hasScannerPath() )
|
||||||
m_currScannerPath = TomahawkSettings::instance()->scannerPath();
|
m_currScannerPath = TomahawkSettings::instance()->scannerPath();
|
||||||
|
|
||||||
m_dirWatcher->addPaths( m_currScannerPath );
|
qDebug() << "loading initial directories to watch";
|
||||||
qDebug() << "filewatcher dirs = " << m_dirWatcher->directories();
|
QTimer::singleShot( 1000, this, SLOT( startupWatchPaths() ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -98,6 +102,36 @@ ScanManager::onSettingsChanged()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
ScanManager::startupWatchPaths()
|
||||||
|
{
|
||||||
|
qDebug() << Q_FUNC_INFO;
|
||||||
|
|
||||||
|
if( !Database::instance() )
|
||||||
|
{
|
||||||
|
QTimer::singleShot( 1000, this, SLOT( startupWatchPaths() ) );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
DatabaseCommand_DirMtimes* cmd = new DatabaseCommand_DirMtimes( m_currScannerPath );
|
||||||
|
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 );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ScanManager::runManualScan( const QStringList& path )
|
ScanManager::runManualScan( const QStringList& path )
|
||||||
{
|
{
|
||||||
@@ -109,6 +143,8 @@ ScanManager::runManualScan( const QStringList& path )
|
|||||||
m_scanner = new MusicScanner( path );
|
m_scanner = new MusicScanner( path );
|
||||||
m_scanner->moveToThread( m_musicScannerThreadController );
|
m_scanner->moveToThread( m_musicScannerThreadController );
|
||||||
connect( m_scanner, SIGNAL( finished() ), SLOT( scannerFinished() ) );
|
connect( m_scanner, SIGNAL( finished() ), SLOT( scannerFinished() ) );
|
||||||
|
connect( m_scanner, SIGNAL( addWatchedDirs( const QStringList & ) ), SLOT( addWatchedDirs( const QStringList & ) ) );
|
||||||
|
connect( m_scanner, SIGNAL( removeWatchedDir( const QString & ) ), SLOT( removeWatchedDir( const QString & ) ) );
|
||||||
m_musicScannerThreadController->start( QThread::IdlePriority );
|
m_musicScannerThreadController->start( QThread::IdlePriority );
|
||||||
QMetaObject::invokeMethod( m_scanner, "startScan" );
|
QMetaObject::invokeMethod( m_scanner, "startScan" );
|
||||||
}
|
}
|
||||||
@@ -116,6 +152,28 @@ ScanManager::runManualScan( const QStringList& path )
|
|||||||
qDebug() << "Could not run manual scan, old scan still running";
|
qDebug() << "Could not run manual scan, old scan still running";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ScanManager::addWatchedDirs( const QStringList& paths )
|
||||||
|
{
|
||||||
|
qDebug() << Q_FUNC_INFO;
|
||||||
|
QStringList currentWatchedPaths = m_dirWatcher->directories();
|
||||||
|
foreach( QString path, paths )
|
||||||
|
{
|
||||||
|
if( !currentWatchedPaths.contains( path ) )
|
||||||
|
{
|
||||||
|
qDebug() << "adding " << path << " to watched dirs";
|
||||||
|
m_dirWatcher->addPath( path );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ScanManager::removeWatchedDir( const QString& path )
|
||||||
|
{
|
||||||
|
qDebug() << Q_FUNC_INFO;
|
||||||
|
qDebug() << "removing " << path << " from watched dirs";
|
||||||
|
m_dirWatcher->removePath( path );
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ScanManager::handleChangedDir( const QString& path )
|
ScanManager::handleChangedDir( const QString& path )
|
||||||
|
@@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
|
#include <QMap>
|
||||||
|
|
||||||
#include "dllmacro.h"
|
#include "dllmacro.h"
|
||||||
|
|
||||||
@@ -45,12 +46,17 @@ signals:
|
|||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void handleChangedDir( const QString& path );
|
void handleChangedDir( const QString& path );
|
||||||
|
void addWatchedDirs( const QStringList& paths );
|
||||||
|
void removeWatchedDir( const QString& path );
|
||||||
|
void setInitialPaths( QMap<QString, unsigned int> pathMap );
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void scannerQuit();
|
void scannerQuit();
|
||||||
void scannerFinished();
|
void scannerFinished();
|
||||||
void scannerDestroyed( QObject* scanner );
|
void scannerDestroyed( QObject* scanner );
|
||||||
|
|
||||||
|
void startupWatchPaths();
|
||||||
|
|
||||||
void onSettingsChanged();
|
void onSettingsChanged();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Reference in New Issue
Block a user