Index: libs/database/collectionscanner.h =================================================================== --- libs/database/collectionscanner.h (revision 1156900) +++ libs/database/collectionscanner.h (working copy) @@ -59,6 +59,7 @@ CollectionScanner(); ~CollectionScanner(); + void completeScanWorker(const CollectionLocation &location); /** * Carries out a full scan on all available parts of the collection. * Only a full scan can finally remove deleted files from the database, Index: libs/database/collectionscanner.cpp =================================================================== --- libs/database/collectionscanner.cpp (revision 1156900) +++ libs/database/collectionscanner.cpp (working copy) @@ -203,6 +203,14 @@ d->observer = observer; } +void CollectionScanner::completeScanWorker(const CollectionLocation &location) +{ + // lock database + DatabaseTransaction transaction; + + scanAlbumRoot(location); +} + void CollectionScanner::completeScan() { QTime time; @@ -210,12 +218,6 @@ emit startCompleteScan(); - // lock database - DatabaseTransaction transaction; - - loadNameFilters(); - d->resetRemovedItemsTime(); - //TODO: Implement a mechanism to watch for album root changes while we keep this list QList allLocations = CollectionManager::instance()->allAvailableLocations(); @@ -229,6 +231,9 @@ emit totalFilesToScan(count); } + loadNameFilters(); + d->resetRemovedItemsTime(); + if (!d->checkObserver()) { emit cancelled(); @@ -251,8 +256,16 @@ emit startScanningAlbumRoots(); foreach (const CollectionLocation& location, allLocations) - scanAlbumRoot(location); + { + completeScanWorker(location); + if (!d->checkObserver()) + { + emit cancelled(); + return; + } + } + // do not continue to clean up without a complete scan! if (!d->checkObserver()) { @@ -630,10 +643,12 @@ itemIdSet << scanInfos[i].id; } - const QFileInfoList list = dir.entryInfoList(QDir::AllDirs | QDir::Files | QDir::NoDotAndDotDot); + int counter = -1, totalFiles = 0; + + { + const QFileInfoList list = dir.entryInfoList(QDir::Files); QFileInfoList::const_iterator fi; - int counter = -1; for (fi = list.constBegin(); fi != list.constEnd(); ++fi) { if (!d->checkObserver()) @@ -680,8 +695,27 @@ } } } - else if ( fi->isDir() ) + } + totalFiles = list.count(); + } + { + const QFileInfoList list = dir.entryInfoList(QDir::AllDirs | QDir::NoDotAndDotDot); + QFileInfoList::const_iterator fi; + + for (fi = list.constBegin(); fi != list.constEnd(); ++fi) + { + if (!d->checkObserver()) + return; // return directly, do not go to cleanup code after loop! + + counter++; + if (d->wantSignals && counter && (counter % 100 == 0)) { + emit scannedFiles(counter); + counter = 0; + } + + if ( fi->isDir() ) + { QString subalbum; if (album == "/") subalbum = '/' + fi->fileName(); @@ -691,6 +725,8 @@ scanAlbum( location, subalbum ); } } + totalFiles += list.count(); + } if (d->wantSignals && counter) emit scannedFiles(counter); @@ -706,7 +742,7 @@ d->scannedAlbums << albumID; if (d->wantSignals) - emit finishedScanningAlbum(location.albumRootPath(), album, list.count()); + emit finishedScanningAlbum(location.albumRootPath(), album, totalFiles); } void CollectionScanner::scanFileNormal(const QFileInfo& fi, const ItemScanInfo& scanInfo)