mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-11 08:34:34 +02:00
* Don't let the MusicScanner emit finished before all our stuff actually ended up in the database.
This commit is contained in:
@@ -213,8 +213,6 @@ Source::setOnline()
|
|||||||
void
|
void
|
||||||
Source::dbLoaded( unsigned int id, const QString& fname )
|
Source::dbLoaded( unsigned int id, const QString& fname )
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO << id << fname;
|
|
||||||
|
|
||||||
m_id = id;
|
m_id = id;
|
||||||
setFriendlyName( fname );
|
setFriendlyName( fname );
|
||||||
|
|
||||||
@@ -252,6 +250,7 @@ void
|
|||||||
Source::onStateChanged( DBSyncConnection::State newstate, DBSyncConnection::State oldstate, const QString& info )
|
Source::onStateChanged( DBSyncConnection::State newstate, DBSyncConnection::State oldstate, const QString& info )
|
||||||
{
|
{
|
||||||
Q_UNUSED( oldstate );
|
Q_UNUSED( oldstate );
|
||||||
|
|
||||||
QString msg;
|
QString msg;
|
||||||
switch( newstate )
|
switch( newstate )
|
||||||
{
|
{
|
||||||
|
@@ -195,13 +195,16 @@ MusicScanner::listerFinished()
|
|||||||
m_scannedfiles.clear();
|
m_scannedfiles.clear();
|
||||||
m_filesToDelete.clear();
|
m_filesToDelete.clear();
|
||||||
|
|
||||||
tDebug( LOGINFO ) << "Scanning complete, saving to database. "
|
tDebug( LOGINFO ) << "Scanning complete, saving to database. ( scanned" << m_scanned << "skipped" << m_skipped << ")";
|
||||||
"( scanned" << m_scanned << "skipped" << m_skipped << ")";
|
|
||||||
|
|
||||||
tDebug( LOGEXTRA ) << "Skipped the following files (no tags / no valid audio):";
|
tDebug( LOGEXTRA ) << "Skipped the following files (no tags / no valid audio):";
|
||||||
foreach ( const QString& s, m_skippedFiles )
|
foreach ( const QString& s, m_skippedFiles )
|
||||||
tDebug( LOGEXTRA ) << s;
|
tDebug( LOGEXTRA ) << s;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
MusicScanner::cleanup()
|
||||||
|
{
|
||||||
if ( !m_dirLister.isNull() )
|
if ( !m_dirLister.isNull() )
|
||||||
{
|
{
|
||||||
m_dirListerThreadController->quit();;
|
m_dirListerThreadController->quit();;
|
||||||
@@ -223,21 +226,38 @@ MusicScanner::commitBatch( const QVariantList& tracks, const QVariantList& delet
|
|||||||
{
|
{
|
||||||
tDebug( LOGINFO ) << Q_FUNC_INFO << "deleting" << deletethese.length() << "tracks";
|
tDebug( LOGINFO ) << Q_FUNC_INFO << "deleting" << deletethese.length() << "tracks";
|
||||||
source_ptr localsrc = SourceList::instance()->getLocal();
|
source_ptr localsrc = SourceList::instance()->getLocal();
|
||||||
Database::instance()->enqueue(
|
executeCommand( QSharedPointer<DatabaseCommand>( new DatabaseCommand_DeleteFiles( deletethese, SourceList::instance()->getLocal() ) ) );
|
||||||
QSharedPointer<DatabaseCommand>( new DatabaseCommand_DeleteFiles( deletethese, SourceList::instance()->getLocal() ) )
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( tracks.length() )
|
if ( tracks.length() )
|
||||||
{
|
{
|
||||||
tDebug( LOGINFO ) << Q_FUNC_INFO << "adding" << tracks.length() << "tracks";
|
tDebug( LOGINFO ) << Q_FUNC_INFO << "adding" << tracks.length() << "tracks";
|
||||||
source_ptr localsrc = SourceList::instance()->getLocal();
|
source_ptr localsrc = SourceList::instance()->getLocal();
|
||||||
Database::instance()->enqueue(
|
executeCommand( QSharedPointer<DatabaseCommand>( new DatabaseCommand_AddFiles( tracks, localsrc ) ) );
|
||||||
QSharedPointer<DatabaseCommand>( new DatabaseCommand_AddFiles( tracks, localsrc ) )
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
MusicScanner::executeCommand( QSharedPointer< DatabaseCommand > cmd )
|
||||||
|
{
|
||||||
|
m_cmdQueue << cmd.data();
|
||||||
|
connect( cmd.data(), SIGNAL( finished() ), SLOT( commandFinished() ) );
|
||||||
|
Database::instance()->enqueue( cmd );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
MusicScanner::commandFinished()
|
||||||
|
{
|
||||||
|
DatabaseCommand* cmd = qobject_cast< DatabaseCommand* >( sender() );
|
||||||
|
m_cmdQueue.removeAll( cmd );
|
||||||
|
|
||||||
|
if ( m_cmdQueue.isEmpty() )
|
||||||
|
cleanup();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
MusicScanner::scanFile( const QFileInfo& fi )
|
MusicScanner::scanFile( const QFileInfo& fi )
|
||||||
{
|
{
|
||||||
|
@@ -19,7 +19,8 @@
|
|||||||
#ifndef MUSICSCANNER_H
|
#ifndef MUSICSCANNER_H
|
||||||
#define MUSICSCANNER_H
|
#define MUSICSCANNER_H
|
||||||
|
|
||||||
#include <tomahawksettings.h>
|
#include "tomahawksettings.h"
|
||||||
|
#include "database/databasecommand.h"
|
||||||
|
|
||||||
/* taglib */
|
/* taglib */
|
||||||
#include <taglib/fileref.h>
|
#include <taglib/fileref.h>
|
||||||
@@ -34,6 +35,7 @@
|
|||||||
#include <QMutex>
|
#include <QMutex>
|
||||||
#include <QMutexLocker>
|
#include <QMutexLocker>
|
||||||
#include <QWeakPointer>
|
#include <QWeakPointer>
|
||||||
|
#include <database/database.h>
|
||||||
|
|
||||||
// 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.
|
||||||
@@ -90,6 +92,7 @@ signals:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
QVariant readFile( const QFileInfo& fi );
|
QVariant readFile( const QFileInfo& fi );
|
||||||
|
void executeCommand( QSharedPointer< DatabaseCommand > cmd );
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void listerFinished();
|
void listerFinished();
|
||||||
@@ -97,7 +100,9 @@ private slots:
|
|||||||
void setFileMtimes( const QMap< QString, QMap< unsigned int, unsigned int > >& m );
|
void setFileMtimes( const QMap< QString, QMap< unsigned int, unsigned int > >& m );
|
||||||
void startScan();
|
void startScan();
|
||||||
void scan();
|
void scan();
|
||||||
|
void cleanup();
|
||||||
void commitBatch( const QVariantList& tracks, const QVariantList& deletethese );
|
void commitBatch( const QVariantList& tracks, const QVariantList& deletethese );
|
||||||
|
void commandFinished();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QStringList m_dirs;
|
QStringList m_dirs;
|
||||||
@@ -106,9 +111,10 @@ private:
|
|||||||
unsigned int m_skipped;
|
unsigned int m_skipped;
|
||||||
|
|
||||||
QList<QString> m_skippedFiles;
|
QList<QString> m_skippedFiles;
|
||||||
|
|
||||||
QMap<QString, QMap< unsigned int, unsigned int > > m_filemtimes;
|
QMap<QString, QMap< unsigned int, unsigned int > > m_filemtimes;
|
||||||
|
|
||||||
|
QList<DatabaseCommand*> m_cmdQueue;
|
||||||
|
|
||||||
QVariantList m_scannedfiles;
|
QVariantList m_scannedfiles;
|
||||||
QVariantList m_filesToDelete;
|
QVariantList m_filesToDelete;
|
||||||
quint32 m_batchsize;
|
quint32 m_batchsize;
|
||||||
|
@@ -228,6 +228,7 @@ ScanManager::scannerFinished()
|
|||||||
delete m_musicScannerThreadController;
|
delete m_musicScannerThreadController;
|
||||||
m_musicScannerThreadController = 0;
|
m_musicScannerThreadController = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_scanTimer->start();
|
m_scanTimer->start();
|
||||||
SourceList::instance()->getLocal()->scanningFinished( 0 );
|
SourceList::instance()->getLocal()->scanningFinished( 0 );
|
||||||
emit finished();
|
emit finished();
|
||||||
|
Reference in New Issue
Block a user