From 6a8abc0869565ab57d5a6ac73be39150926abb43 Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Thu, 26 Mar 2015 16:11:27 -0400 Subject: Streamline quite a bit of the background worker: 1) Make sure the background routine *only* runs if the directory has changed or been modified (changing the view/config will no longer re-scan the dir) 2) Cleanup the number of translated strings in the dir info routine, and make it easily modified for larger file sizes (already increased to TB now). 3) Ensure that the whole-dir info is re-displayed if the selection is cleared. --- lumina-fm/BackgroundWorker.cpp | 44 +++++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 18 deletions(-) (limited to 'lumina-fm/BackgroundWorker.cpp') diff --git a/lumina-fm/BackgroundWorker.cpp b/lumina-fm/BackgroundWorker.cpp index c8d7cb17..125e0e1c 100644 --- a/lumina-fm/BackgroundWorker.cpp +++ b/lumina-fm/BackgroundWorker.cpp @@ -90,26 +90,34 @@ void BackgroundWorker::startDirChecks(QString path){ void BackgroundWorker::createStatusBarMsg(QFileInfoList fileList, QString path, QString message){ //collect some statistics of dir and display them in statusbar - int i = 0; - qreal totalSizes = 0; - foreach (QFileInfo fileInfo, fileList ) - { - if (fileInfo.isFile()) totalSizes += fileInfo.size(); - i += 1; + //Get the total size of the items + double totalSizes = 0; + for(int i=0; i 1024){ + cunit++; + totalSizes = totalSizes/1024; } - QString msgStatusBar = QString(tr("%1: %2")).arg(message).arg(i); - if (i>0 and totalSizes>1024*1024*1024) - msgStatusBar += QString(tr(", size: %1 Gb")).arg(totalSizes/1024/1024/1024, 0,'f', 2); - else if (i>0 and totalSizes>1024*1024) - msgStatusBar += QString(tr(", size: %1 Mb")).arg(totalSizes/1024/1024, 0,'f',2); - else if (i>0 and totalSizes>1024) - msgStatusBar += QString(tr(", size: %1 Kb")).arg(totalSizes/1024, 0, 'f' , 2); - else - if (totalSizes > 0) { msgStatusBar += QString(tr(", size: %1 b")).arg(totalSizes, 0, 'f' , 2);} + //Assemble the message + QString msgStatusBar = QString(tr("%1: %2")).arg(message).arg(fileList.length()); + if(totalSizes > 0){ + totalSizes = qRound(totalSizes*100)/100.0; //round to 2 decimel places + msgStatusBar += " "+QString(tr("Total size: %1 %2")).arg(QString::number(totalSizes), units[cunit]); + } + //If a path given, get the total capacity of it (percantage) if (!path.isEmpty()) { //path could be empty when fileList is based on user's selection QString capacity = LOS::FileSystemCapacity(path) ; - if (msgStatusBar.isEmpty()) msgStatusBar += tr("Capacity: ") + capacity; - else msgStatusBar += tr(", Capacity: ") + capacity; + if (msgStatusBar.isEmpty()) msgStatusBar += QString(tr("Capacity: %1")).arg(capacity); + else msgStatusBar += " "+QString(tr("Capacity: %1")).arg(capacity); + } + //Emit the signal to show this on the UI + if (!msgStatusBar.isEmpty()){ + emit Si_DisplayStatusBar(msgStatusBar); } - if (!msgStatusBar.isEmpty()) emit Si_DisplayStatusBar(msgStatusBar); } -- cgit