diff --git a/src/libtomahawk/utils/tomahawkutils.h b/src/libtomahawk/utils/tomahawkutils.h index ebe2562b4..331afa931 100644 --- a/src/libtomahawk/utils/tomahawkutils.h +++ b/src/libtomahawk/utils/tomahawkutils.h @@ -37,23 +37,6 @@ class QNetworkProxy; namespace TomahawkUtils { - class DLLEXPORT Sleep : public QThread - { - public: - static void sleep( unsigned long secs ) - { - QThread::sleep( secs ); - } - static void msleep( unsigned long msecs ) - { - QThread::msleep( msecs ); - } - static void usleep( unsigned long usecs ) - { - QThread::usleep( usecs ); - } - }; - class DLLEXPORT NetworkProxyFactory : public QNetworkProxyFactory { public: diff --git a/src/musicscanner.cpp b/src/musicscanner.cpp index 8472dcade..34ad9e823 100644 --- a/src/musicscanner.cpp +++ b/src/musicscanner.cpp @@ -136,29 +136,12 @@ MusicScanner::~MusicScanner() 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 ); - } + m_dirListerThreadController->quit();; + m_dirListerThreadController->wait( 60000 ); - if ( m_dirListerThreadController ) - 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; - } + delete m_dirLister.data(); + delete m_dirListerThreadController; + m_dirListerThreadController = 0; } } @@ -257,29 +240,12 @@ MusicScanner::deleteLister() { 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 ); - } + m_dirListerThreadController->quit();; + m_dirListerThreadController->wait( 60000 ); - if ( m_dirListerThreadController ) - 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; - } + delete m_dirLister.data(); + delete m_dirListerThreadController; + m_dirListerThreadController = 0; } emit finished(); } diff --git a/src/scanmanager.cpp b/src/scanmanager.cpp index cf12153c9..5a824f508 100644 --- a/src/scanmanager.cpp +++ b/src/scanmanager.cpp @@ -85,29 +85,12 @@ ScanManager::~ScanManager() if ( !m_scanner.isNull() ) { - QMetaObject::invokeMethod( m_scanner.data(), "deleteLater", Qt::QueuedConnection ); - while( !m_scanner.isNull() ) - { - qDebug() << Q_FUNC_INFO << " scanner not deleted, processing events"; - QCoreApplication::processEvents( QEventLoop::AllEvents, 200 ); - TomahawkUtils::Sleep::msleep( 100 ); - } + m_musicScannerThreadController->quit(); + m_musicScannerThreadController->wait( 60000 ); - if ( m_musicScannerThreadController ) - m_musicScannerThreadController->quit(); - - if( m_musicScannerThreadController ) - { - while( !m_musicScannerThreadController->isFinished() ) - { - qDebug() << Q_FUNC_INFO << " scanner thread controller not finished, processing events"; - QCoreApplication::processEvents( QEventLoop::AllEvents, 200 ); - TomahawkUtils::Sleep::msleep( 100 ); - } - - delete m_musicScannerThreadController; - m_musicScannerThreadController = 0; - } + delete m_scanner.data(); + delete m_musicScannerThreadController; + m_musicScannerThreadController = 0; } } @@ -250,29 +233,12 @@ ScanManager::scannerFinished() { if ( !m_scanner.isNull() ) { - QMetaObject::invokeMethod( m_scanner.data(), "deleteLater", Qt::QueuedConnection ); - while( !m_scanner.isNull() ) - { - qDebug() << Q_FUNC_INFO << " scanner not deleted, processing events"; - QCoreApplication::processEvents( QEventLoop::AllEvents, 200 ); - TomahawkUtils::Sleep::msleep( 100 ); - } + m_musicScannerThreadController->quit(); + m_musicScannerThreadController->wait( 60000 ); - if ( m_musicScannerThreadController ) - m_musicScannerThreadController->quit(); - - if( m_musicScannerThreadController ) - { - while( !m_musicScannerThreadController->isFinished() ) - { - qDebug() << Q_FUNC_INFO << " scanner thread controller not finished, processing events"; - QCoreApplication::processEvents( QEventLoop::AllEvents, 200 ); - TomahawkUtils::Sleep::msleep( 100 ); - } - - delete m_musicScannerThreadController; - m_musicScannerThreadController = 0; - } + delete m_scanner.data(); + delete m_musicScannerThreadController; + m_musicScannerThreadController = 0; } emit finished(); }