From 7899bdbe62fbef0da07d5c460ebbfee57bb84ff3 Mon Sep 17 00:00:00 2001 From: "craig.p.drummond" Date: Thu, 1 Nov 2012 19:01:28 +0000 Subject: [PATCH] Reduce update steps if it takes too long --- devices/fsdevice.cpp | 14 +++++++++++++- devices/fsdevice.h | 2 ++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/devices/fsdevice.cpp b/devices/fsdevice.cpp index b874756c3..24099fc20 100644 --- a/devices/fsdevice.cpp +++ b/devices/fsdevice.cpp @@ -43,6 +43,7 @@ #include #include #include +#include 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); } diff --git a/devices/fsdevice.h b/devices/fsdevice.h index cd578f8bd..885d355fa 100644 --- a/devices/fsdevice.h +++ b/devices/fsdevice.h @@ -63,6 +63,8 @@ private: MusicLibraryItemRoot *library; bool stopRequested; int count; + int lastUpdate; + int step; }; class FsDevice : public Device