mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-10 16:14:40 +02:00
Make dirlister also delete in-thread
This commit is contained in:
@@ -115,7 +115,6 @@ MusicScanner::MusicScanner( const QStringList& dirs, bool recursive, quint32 bs
|
|||||||
, m_dirs( dirs )
|
, m_dirs( dirs )
|
||||||
, m_recursive( recursive )
|
, m_recursive( recursive )
|
||||||
, m_batchsize( bs )
|
, m_batchsize( bs )
|
||||||
, m_dirLister( 0 )
|
|
||||||
, m_dirListerThreadController( 0 )
|
, m_dirListerThreadController( 0 )
|
||||||
{
|
{
|
||||||
m_ext2mime.insert( "mp3", TomahawkUtils::extensionToMimetype( "mp3" ) );
|
m_ext2mime.insert( "mp3", TomahawkUtils::extensionToMimetype( "mp3" ) );
|
||||||
@@ -133,25 +132,32 @@ MusicScanner::~MusicScanner()
|
|||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO;
|
qDebug() << Q_FUNC_INFO;
|
||||||
|
|
||||||
if( m_dirListerThreadController )
|
if ( !m_dirLister.isNull() )
|
||||||
{
|
{
|
||||||
m_dirListerThreadController->quit();
|
QMetaObject::invokeMethod( m_dirLister.data(), "deleteLater", Qt::QueuedConnection );
|
||||||
|
while( !m_dirLister.isNull() )
|
||||||
while( !m_dirListerThreadController->isFinished() )
|
|
||||||
{
|
{
|
||||||
|
qDebug() << Q_FUNC_INFO << " scanner not deleted, processing events";
|
||||||
QCoreApplication::processEvents( QEventLoop::AllEvents, 200 );
|
QCoreApplication::processEvents( QEventLoop::AllEvents, 200 );
|
||||||
TomahawkUtils::Sleep::msleep( 100 );
|
TomahawkUtils::Sleep::msleep( 100 );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( m_dirLister )
|
if ( m_dirListerThreadController )
|
||||||
|
m_dirListerThreadController->quit();
|
||||||
|
|
||||||
|
if( m_dirListerThreadController )
|
||||||
{
|
{
|
||||||
delete m_dirLister;
|
while( !m_dirListerThreadController->isFinished() )
|
||||||
m_dirLister = 0;
|
{
|
||||||
|
qDebug() << Q_FUNC_INFO << " scanner thread controller not finished, processing events";
|
||||||
|
QCoreApplication::processEvents( QEventLoop::AllEvents, 200 );
|
||||||
|
TomahawkUtils::Sleep::msleep( 100 );
|
||||||
}
|
}
|
||||||
|
|
||||||
delete m_dirListerThreadController;
|
delete m_dirListerThreadController;
|
||||||
m_dirListerThreadController = 0;
|
m_dirListerThreadController = 0;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -190,18 +196,18 @@ MusicScanner::scan()
|
|||||||
|
|
||||||
m_dirListerThreadController = new QThread( this );
|
m_dirListerThreadController = new QThread( this );
|
||||||
|
|
||||||
m_dirLister = new DirLister( m_dirs, m_dirmtimes, m_recursive );
|
m_dirLister = QWeakPointer< DirLister >( new DirLister( m_dirs, m_dirmtimes, m_recursive ) );
|
||||||
m_dirLister->moveToThread( m_dirListerThreadController );
|
m_dirLister.data()->moveToThread( m_dirListerThreadController );
|
||||||
|
|
||||||
connect( m_dirLister, SIGNAL( fileToScan( QFileInfo ) ),
|
connect( m_dirLister.data(), SIGNAL( fileToScan( QFileInfo ) ),
|
||||||
SLOT( scanFile( QFileInfo ) ), Qt::QueuedConnection );
|
SLOT( scanFile( QFileInfo ) ), Qt::QueuedConnection );
|
||||||
|
|
||||||
// queued, so will only fire after all dirs have been scanned:
|
// queued, so will only fire after all dirs have been scanned:
|
||||||
connect( m_dirLister, SIGNAL( finished( QMap<QString, unsigned int> ) ),
|
connect( m_dirLister.data(), SIGNAL( finished( QMap<QString, unsigned int> ) ),
|
||||||
SLOT( listerFinished( QMap<QString, unsigned int> ) ), Qt::QueuedConnection );
|
SLOT( listerFinished( QMap<QString, unsigned int> ) ), Qt::QueuedConnection );
|
||||||
|
|
||||||
m_dirListerThreadController->start();
|
m_dirListerThreadController->start();
|
||||||
QMetaObject::invokeMethod( m_dirLister, "go" );
|
QMetaObject::invokeMethod( m_dirLister.data(), "go" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -247,29 +253,32 @@ MusicScanner::listerFinished( const QMap<QString, unsigned int>& newmtimes )
|
|||||||
void
|
void
|
||||||
MusicScanner::deleteLister()
|
MusicScanner::deleteLister()
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO;
|
if ( !m_dirLister.isNull() )
|
||||||
connect( m_dirListerThreadController, SIGNAL( finished() ), SLOT( listerQuit() ) );
|
{
|
||||||
|
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 )
|
||||||
m_dirListerThreadController->quit();
|
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 );
|
||||||
|
}
|
||||||
|
|
||||||
void
|
delete m_dirListerThreadController;
|
||||||
MusicScanner::listerQuit()
|
|
||||||
{
|
|
||||||
qDebug() << Q_FUNC_INFO;
|
|
||||||
connect( m_dirLister, SIGNAL( destroyed( QObject* ) ), SLOT( listerDestroyed( QObject* ) ) );
|
|
||||||
delete m_dirLister;
|
|
||||||
m_dirLister = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
MusicScanner::listerDestroyed( QObject* dirLister )
|
|
||||||
{
|
|
||||||
Q_UNUSED( dirLister );
|
|
||||||
qDebug() << Q_FUNC_INFO;
|
|
||||||
m_dirListerThreadController->deleteLater();
|
|
||||||
m_dirListerThreadController = 0;
|
m_dirListerThreadController = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
emit finished();
|
emit finished();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -30,6 +30,7 @@
|
|||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
#include <QWeakPointer>
|
||||||
|
|
||||||
// descend dir tree comparing dir mtimes to last known mtime
|
// descend dir tree comparing dir mtimes to last known mtime
|
||||||
// emit signal for any dir with new content, so we can scan it.
|
// emit signal for any dir with new content, so we can scan it.
|
||||||
@@ -94,8 +95,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 deleteLister();
|
||||||
void listerQuit();
|
|
||||||
void listerDestroyed( QObject* dirLister );
|
|
||||||
void scanFile( const QFileInfo& fi );
|
void scanFile( const QFileInfo& fi );
|
||||||
void startScan();
|
void startScan();
|
||||||
void scan();
|
void scan();
|
||||||
@@ -117,7 +116,7 @@ private:
|
|||||||
bool m_recursive;
|
bool m_recursive;
|
||||||
quint32 m_batchsize;
|
quint32 m_batchsize;
|
||||||
|
|
||||||
DirLister* m_dirLister;
|
QWeakPointer< DirLister > m_dirLister;
|
||||||
QThread* m_dirListerThreadController;
|
QThread* m_dirListerThreadController;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user