aboutsummaryrefslogtreecommitdiff
path: root/libLumina/LuminaUtils.cpp
diff options
context:
space:
mode:
authorKen Moore <moorekou@gmail.com>2015-08-19 17:15:56 -0400
committerKen Moore <moorekou@gmail.com>2015-08-19 17:15:56 -0400
commit40943240fc262d501e6a175f988e421a873d90b7 (patch)
tree0e8b33b03c31f177087514cceff879785c846580 /libLumina/LuminaUtils.cpp
parentAdd the XDG_DATA_* path support for relative application paths given in the m... (diff)
downloadlumina-40943240fc262d501e6a175f988e421a873d90b7.tar.gz
lumina-40943240fc262d501e6a175f988e421a873d90b7.tar.bz2
lumina-40943240fc262d501e6a175f988e421a873d90b7.zip
Add a function to convert a number of bytes into a display string (3 digits)
Diffstat (limited to 'libLumina/LuminaUtils.cpp')
-rw-r--r--libLumina/LuminaUtils.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/libLumina/LuminaUtils.cpp b/libLumina/LuminaUtils.cpp
index 06101774..63875172 100644
--- a/libLumina/LuminaUtils.cpp
+++ b/libLumina/LuminaUtils.cpp
@@ -265,6 +265,35 @@ double LUtils::DisplaySizeToBytes(QString num){
return N;
}
+QString LUtils::BytesToDisplaySize(qint64 ibytes){
+ static QStringList labs = QStringList();
+ if(labs.isEmpty()){ labs << "B" << "K" << "M" << "G" << "T" << "P"; }
+ //Now get the dominant unit
+ int c=0;
+ double bytes = ibytes; //need to keep decimel places for calculations
+ while(bytes>=1000 && c<labs.length() ){
+ bytes = bytes/1024;
+ c++;
+ } //labs[c] is the unit
+ //Bytes are now
+ //Now format the number (up to 3 digits, not including decimel places)
+ QString num;
+ if(bytes>=100){
+ //No decimel places
+ num = QString::number(qRound(bytes));
+ }else if(bytes>=10){
+ //need 1 decimel place
+ num = QString::number( (qRound(bytes*10)/10.0) );
+ }else if(bytes>1){
+ //need 2 decimel places
+ num = QString::number( (qRound(bytes*100)/100.0) );
+ }else{
+ //Fully decimel (3 places)
+ num = "0."+QString::number(qRound(bytes*1000));
+ }
+ return (num+labs[c]);
+}
+
//Various function for finding valid QtQuick plugins on the system
bool LUtils::validQuickPlugin(QString ID){
return ( !LUtils::findQuickPluginFile(ID).isEmpty() );
bgstack15