From dda7a2f6b34e1c52f3c8d6628b8a1ae946e7f6df Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Thu, 24 Feb 2011 03:25:05 +0100 Subject: [PATCH] * While debugging I ended up cleaning some code. For what it's worth. --- src/musicscanner.cpp | 59 ++++++++++++++++++++++++++++++++++-------- src/musicscanner.h | 36 +++----------------------- src/scanmanager.cpp | 5 +++- src/tomahawkwindow.cpp | 19 ++------------ 4 files changed, 57 insertions(+), 62 deletions(-) diff --git a/src/musicscanner.cpp b/src/musicscanner.cpp index 68a47e562..7454b320f 100644 --- a/src/musicscanner.cpp +++ b/src/musicscanner.cpp @@ -9,6 +9,38 @@ using namespace Tomahawk; +void +DirLister::scanDir( QDir dir, int depth ) +{ + QFileInfoList dirs; + const uint mtime = QFileInfo( dir.absolutePath() ).lastModified().toUTC().toTime_t(); + m_newdirmtimes.insert( dir.absolutePath(), mtime ); + + if ( m_dirmtimes.contains( dir.absolutePath() ) && + mtime == m_dirmtimes.value( dir.absolutePath() ) ) + { + // dont scan this dir, unchanged since last time. + } + else + { + dir.setFilter( QDir::Files | QDir::Readable | QDir::NoDotAndDotDot ); + dir.setSorting( QDir::Name ); + dirs = dir.entryInfoList(); + foreach( const QFileInfo& di, dirs ) + { + emit fileToScan( di ); + } + } + dir.setFilter( QDir::Dirs | QDir::Readable | QDir::NoDotAndDotDot ); + dirs = dir.entryInfoList(); + + foreach( const QFileInfo& di, dirs ) + { + scanDir( di.absoluteFilePath(), depth + 1 ); + } +} + + MusicScanner::MusicScanner( const QString& dir, quint32 bs ) : QObject() , m_dir( dir ) @@ -31,9 +63,11 @@ MusicScanner::MusicScanner( const QString& dir, quint32 bs ) // m_ext2mime.insert( "mp4", "audio/mp4" ); } + MusicScanner::~MusicScanner() { qDebug() << Q_FUNC_INFO; + if( m_dirListerThreadController ) { m_dirListerThreadController->quit(); @@ -41,7 +75,7 @@ MusicScanner::~MusicScanner() while( !m_dirListerThreadController->isFinished() ) { QCoreApplication::processEvents( QEventLoop::AllEvents, 200 ); - TomahawkUtils::Sleep::msleep(100); + TomahawkUtils::Sleep::msleep( 100 ); } if( m_dirLister ) @@ -55,6 +89,7 @@ MusicScanner::~MusicScanner() } } + void MusicScanner::startScan() { @@ -64,9 +99,9 @@ MusicScanner::startScan() // trigger the scan once we've loaded old mtimes for dirs below our path DatabaseCommand_DirMtimes* cmd = new DatabaseCommand_DirMtimes( m_dir ); - connect( cmd, SIGNAL( done( const QMap& ) ), - SLOT( setMtimes( const QMap& ) ) ); - connect( cmd, SIGNAL( done( const QMap& ) ), + connect( cmd, SIGNAL( done( QMap ) ), + SLOT( setMtimes( QMap ) ) ); + connect( cmd, SIGNAL( done( QMap ) ), SLOT( scan() ) ); Database::instance()->enqueue( QSharedPointer(cmd) ); @@ -96,8 +131,8 @@ MusicScanner::scan() SLOT( scanFile( QFileInfo ) ), Qt::QueuedConnection ); // queued, so will only fire after all dirs have been scanned: - connect( m_dirLister, SIGNAL( finished( const QMap& ) ), - SLOT( listerFinished( const QMap& ) ), Qt::QueuedConnection ); + connect( m_dirLister, SIGNAL( finished( QMap ) ), + SLOT( listerFinished( QMap ) ), Qt::QueuedConnection ); m_dirListerThreadController->start(); QMetaObject::invokeMethod( m_dirLister, "go" ); @@ -128,6 +163,7 @@ MusicScanner::listerFinished( const QMap& newmtimes ) qDebug() << s; } + void MusicScanner::deleteLister() { @@ -136,6 +172,7 @@ MusicScanner::deleteLister() m_dirListerThreadController->quit(); } + void MusicScanner::listerQuit() { @@ -145,6 +182,7 @@ MusicScanner::listerQuit() m_dirLister = 0; } + void MusicScanner::listerDestroyed( QObject* dirLister ) { @@ -154,6 +192,7 @@ MusicScanner::listerDestroyed( QObject* dirLister ) emit finished(); } + void MusicScanner::commitBatch( const QVariantList& tracks ) { @@ -172,12 +211,11 @@ void MusicScanner::scanFile( const QFileInfo& fi ) { QVariant m = readFile( fi ); - if( m.toMap().isEmpty() ) + if ( m.toMap().isEmpty() ) return; m_scannedfiles << m; - if( m_batchsize != 0 && - (quint32)m_scannedfiles.length() >= m_batchsize ) + if ( m_batchsize != 0 && (quint32)m_scannedfiles.length() >= m_batchsize ) { qDebug() << "batchReady, size:" << m_scannedfiles.length(); emit batchReady( m_scannedfiles ); @@ -220,17 +258,16 @@ MusicScanner::readFile( const QFileInfo& fi ) int bitrate = 0; int duration = 0; TagLib::Tag *tag = f.tag(); - if ( f.audioProperties() ) { TagLib::AudioProperties *properties = f.audioProperties(); duration = properties->length(); bitrate = properties->bitrate(); } + QString artist = TStringToQString( tag->artist() ).trimmed(); QString album = TStringToQString( tag->album() ).trimmed(); QString track = TStringToQString( tag->title() ).trimmed(); - if ( artist.isEmpty() || track.isEmpty() ) { // FIXME: do some clever filename guessing diff --git a/src/musicscanner.h b/src/musicscanner.h index a0e60db72..d76c2d06d 100644 --- a/src/musicscanner.h +++ b/src/musicscanner.h @@ -10,8 +10,6 @@ #include #include #include - - #include // descend dir tree comparing dir mtimes to last known mtime @@ -19,7 +17,8 @@ // finally, emit the list of new mtimes we observed. class DirLister : public QObject { - Q_OBJECT +Q_OBJECT + public: DirLister( QDir d, QMap& mtimes ) : QObject(), m_dir( d ), m_dirmtimes( mtimes ) @@ -43,36 +42,7 @@ private slots: emit finished( m_newdirmtimes ); } - void scanDir( QDir dir, int depth ) - { - QFileInfoList dirs; - const uint mtime = QFileInfo( dir.absolutePath() ).lastModified().toUTC().toTime_t(); - m_newdirmtimes.insert( dir.absolutePath(), mtime ); - - if ( m_dirmtimes.contains( dir.absolutePath() ) && - mtime == m_dirmtimes.value( dir.absolutePath() ) - ) - { - // dont scan this dir, unchanged since last time. - } - else - { - dir.setFilter( QDir::Files | QDir::Readable | QDir::NoDotAndDotDot ); - dir.setSorting( QDir::Name ); - dirs = dir.entryInfoList(); - foreach( QFileInfo di, dirs ) - { - emit fileToScan( di ); - } - } - dir.setFilter( QDir::Dirs | QDir::Readable | QDir::NoDotAndDotDot ); - dirs = dir.entryInfoList(); - - foreach( QFileInfo di, dirs ) - { - scanDir( di.absoluteFilePath(), depth + 1 ); - } - } + void scanDir( QDir dir, int depth ); private: QDir m_dir; diff --git a/src/scanmanager.cpp b/src/scanmanager.cpp index 29ee7383d..911381fc2 100644 --- a/src/scanmanager.cpp +++ b/src/scanmanager.cpp @@ -40,7 +40,7 @@ ScanManager::~ScanManager() while( !m_musicScannerThreadController->isFinished() ) { QCoreApplication::processEvents( QEventLoop::AllEvents, 200 ); - TomahawkUtils::Sleep::msleep(100); + TomahawkUtils::Sleep::msleep( 100 ); } if( m_scanner ) @@ -80,6 +80,7 @@ ScanManager::runManualScan( const QString& path ) qDebug() << "Could not run manual scan, old scan still running"; } + void ScanManager::scannerFinished() { @@ -88,6 +89,7 @@ ScanManager::scannerFinished() m_musicScannerThreadController->quit(); } + void ScanManager::scannerQuit() { @@ -97,6 +99,7 @@ ScanManager::scannerQuit() m_scanner = 0; } + void ScanManager::scannerDestroyed( QObject* scanner ) { diff --git a/src/tomahawkwindow.cpp b/src/tomahawkwindow.cpp index 4f03fd1a6..0767af108 100644 --- a/src/tomahawkwindow.cpp +++ b/src/tomahawkwindow.cpp @@ -321,7 +321,8 @@ TomahawkWindow::createAutomaticPlaylist() } -void TomahawkWindow::createStation() +void +TomahawkWindow::createStation() { bool ok; QString name = QInputDialog::getText( this, "Create New Station", "Name:", QLineEdit::Normal, "New Station", &ok ); @@ -341,23 +342,7 @@ void TomahawkWindow::createStation() void TomahawkWindow::createPlaylist() { - PlaylistManager::instance()->show( new NewPlaylistWidget() ); - -/* bool ok; - QString name = QInputDialog::getText( this, "Create New Playlist", "Name:", QLineEdit::Normal, "New Playlist", &ok ); - if ( !ok || name.isEmpty() ) - return; - - source_ptr author = SourceList::instance()->getLocal(); - QString id = uuid(); - QString info = ""; // FIXME - QString creator = "someone"; // FIXME - if( dynamic ) - DynamicPlaylist::create( author, id, name, info, creator, false ); - else - Playlist::create( author, id, name, info, creator, false ); */ - }