Reduce update steps if it takes too long

This commit is contained in:
craig.p.drummond
2012-11-01 19:01:28 +00:00
committed by craig.p.drummond
parent b8f3e49e33
commit 7899bdbe62
2 changed files with 15 additions and 1 deletions

View File

@@ -43,6 +43,7 @@
#include <QtCore/QFileInfo>
#include <QtCore/QTextStream>
#include <QtCore/QTimer>
#include <time.h>
static const QLatin1String constCantataCacheFile("/.cache.xml");
@@ -62,6 +63,8 @@ MusicScanner::~MusicScanner()
void MusicScanner::run()
{
count=0;
lastUpdate=0;
step=25;
library = new MusicLibraryItemRoot;
scanFolder(folder, 0);
if (MPDParseUtils::groupSingle()) {
@@ -117,7 +120,16 @@ void MusicScanner::scanFolder(const QString &f, int level)
continue;
}
count++;
if (0!=count && 0==count%25) {
if (0!=count && 0==count%step) {
if (step>5) {
int t=time(NULL);
if (0!=lastUpdate) {
if ((t-lastUpdate)>3) {
step-=5;
}
}
lastUpdate=t;
}
emit songCount(count);
}

View File

@@ -63,6 +63,8 @@ private:
MusicLibraryItemRoot *library;
bool stopRequested;
int count;
int lastUpdate;
int step;
};
class FsDevice : public Device