aboutsummaryrefslogtreecommitdiff
path: root/lumina-fm/BackgroundWorker.cpp
diff options
context:
space:
mode:
authorKen Moore <ken@pcbsd.org>2015-03-26 16:11:27 -0400
committerKen Moore <ken@pcbsd.org>2015-03-26 16:11:27 -0400
commit6a8abc0869565ab57d5a6ac73be39150926abb43 (patch)
tree1c199f778c924daba4fc9f214c5a79c2ec9938c1 /lumina-fm/BackgroundWorker.cpp
parentClean up the new filesystemusage functions a bit. Make sure that the director... (diff)
downloadlumina-6a8abc0869565ab57d5a6ac73be39150926abb43.tar.gz
lumina-6a8abc0869565ab57d5a6ac73be39150926abb43.tar.bz2
lumina-6a8abc0869565ab57d5a6ac73be39150926abb43.zip
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.
Diffstat (limited to 'lumina-fm/BackgroundWorker.cpp')
-rw-r--r--lumina-fm/BackgroundWorker.cpp44
1 files changed, 26 insertions, 18 deletions
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<fileList.length(); i++){
+ if(!fileList[i].isDir()){
+ totalSizes += fileList[i].size(); //in Bytes
+ }
+ }
+ //Convert the size into display units
+ static QStringList units = QStringList() << tr("B") << tr("KB") << tr("MB") << tr("GB") << tr("TB");
+ int cunit = 0;
+ while(cunit < units.length() && totalSizes > 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);
}
bgstack15