Changeset 6edfd8a
 Timestamp:
 08/06/13 09:20:48 (17 months ago)
 Branches:
 master, 9.2release, releng/10.0, releng/10.0.1, releng/10.0.2, releng/10.0.3, releng/10.1
 Children:
 7369d56
 Parents:
 e5460e1
 Location:
 srcqt4/pcmounttray
 Files:

 3 edited
Legend:
 Unmodified
 Added
 Removed

srcqt4/pcmounttray/fsDialog.cpp
r891636a r6edfd8a 30 30 QString name = fsList[i].section("::",0,0); 31 31 QString filesystem = fsList[i].section("::",1,1); 32 int totalK = fsList[i].section("::",2,2).toInt();33 int usedK = fsList[i].section("::",3,3).toInt();32 double totalK = fsList[i].section("::",2,2).toDouble(); 33 double usedK = fsList[i].section("::",3,3).toDouble(); 34 34 int percent = fsList[i].section("::",4,4).toInt(); 35 35 //Create item for the data 36 36 QStringList text; //column text 37 text << name << filesystem.toUpper() << FSWatcher:: intToDisplay(usedK)+"/"+FSWatcher::intToDisplay(totalK) << QString::number(percent)+"%";37 text << name << filesystem.toUpper() << FSWatcher::doubleToDisplay(usedK)+"/"+FSWatcher::doubleToDisplay(totalK) << QString::number(percent)+"%"; 38 38 QTreeWidgetItem *tmp = new QTreeWidgetItem(text); 39 39 
srcqt4/pcmounttray/fsWatcher.cpp
r781fd04 r6edfd8a 35 35 QString avail = tmp[1].section(" ",0,0,QString::SectionSkipEmpty); 36 36 QString used = tmp[1].section(" ",1,1,QString::SectionSkipEmpty); 37 int iUsed = displayToInt(used);38 int iTotal = displayToInt(avail) + iUsed;37 double iUsed = floor(displayToDouble(used)); 38 double iTotal = floor(displayToDouble(avail)) + iUsed; 39 39 int percent = calculatePercentage(iUsed, iTotal); 40 40 //qDebug() << "Percent calc: tot:"<<iTotal<<"used"<<iUsed<<"percent"<<percent; … … 60 60 QString used = dfout[i].section(" ",3,3,QString::SectionSkipEmpty).simplified(); 61 61 //Calculate the percent 62 int iUsed = displayToInt(used);63 int iTotal = displayToInt(total);62 double iUsed = displayToDouble(used); 63 double iTotal = displayToDouble(total); 64 64 int percent = calculatePercentage(iUsed, iTotal); 65 65 //qDebug() << "df Item:" << dfout[i]; … … 76 76 } 77 77 78 int FSWatcher::displayTo Int(QString entry){78 int FSWatcher::displayToDouble(QString entry){ 79 79 //split the number from the size label 80 80 //qDebug() << "Display to Int conversion:" << entry; … … 83 83 double num = entry.toDouble(); 84 84 //qDebug() << "initial number:" << num << "units:" << units; 85 if(units=="K"){} //Kilobytes (no change) 86 else if(units=="M"){ num=num*1024; } //Megabytes to K 87 else if(units=="G"){ num=num*1048576; } //Gigabytes to K 88 else{ num=0; } //smaller than a KB 85 QStringList unitL; unitL << "K" << "M" << "G" << "T" << "P" << "E" << "Z" << "Y"; 86 bool ok = false; 87 for(int i=0; i< unitL.length(); i++){ 88 if(units == unitL[i]){ num = num*pow(1024.0,i); ok = true; break;} 89 } 90 if(!ok){num=0; } 89 91 //qDebug() << "number:" << num; 90 92 return num; 91 93 } 92 94 93 QString FSWatcher:: intToDisplay(intK){95 QString FSWatcher::doubleToDisplay(double K){ 94 96 QString num; 95 97 //qDebug() << "Int to Display:" << K; 96 98 double kdb = K; //using pure integers causes errors with large numbers 97 if( K > 1048576 ){ num = QString::number( int((kdb*100)/1048576)/100.0 ) +"G"; } 98 else if(K > 1024){ num = QString::number( int((kdb*100)/1024)/100.0 ) +"M"; } 99 else{ num = QString::number(K) +"K"; } 99 QStringList units; units << "K" << "M" << "G" << "T" << "P" << "E" << "Z" << "Y"; 100 int i=0; 101 while( (kdb > 1000) && (i < 8) ){ 102 kdb = kdb/1024; 103 i++; 104 } 105 if(i<8){ 106 num = QString::number( int((kdb*100))/100.0) + units[i]; 107 }else{ 108 num = "??"; 109 } 100 110 //qDebug() << "Display:" << num; 101 111 return num; … … 134 144 135 145 //===== Calculate Percentages ===== 136 int FSWatcher::calculatePercentage( int used, inttotal){146 int FSWatcher::calculatePercentage(double used, double total){ 137 147 double U = used; 138 148 double T = total; 
srcqt4/pcmounttray/fsWatcher.h
r781fd04 r6edfd8a 12 12 #include <QTime> 13 13 14 #include <math.h> 14 15 15 16 class FSWatcher : public QObject … … 25 26 26 27 static QStringList getFSmountpoints(); 27 static QString intToDisplay(int);28 static int displayTo Int(QString);28 static QString doubleToDisplay(double); 29 static int displayToDouble(QString); 29 30 30 31 private: … … 33 34 34 35 static QStringList runCMD(QString); 35 static int calculatePercentage( int,int);36 static int calculatePercentage(double,double); 36 37 37 38 public slots:
Note: See TracChangeset
for help on using the changeset viewer.