Changeset 6edfd8a


Ignore:
Timestamp:
08/06/13 09:20:48 (14 months ago)
Author:
Ken Moore <ken@…>
Branches:
master, 9.2-release, releng/10.0, releng/10.0.1, releng/10.0.2, releng/10.0.3
Children:
7369d56
Parents:
e5460e1
Message:

Fix the mount tray disk space monitor: it should now work up to yottabyes of space, instead of just gigabytes.

Location:
src-qt4/pc-mounttray
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src-qt4/pc-mounttray/fsDialog.cpp

    r891636a r6edfd8a  
    3030      QString name = fsList[i].section("::",0,0); 
    3131      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(); 
    3434      int percent = fsList[i].section("::",4,4).toInt(); 
    3535      //Create item for the data 
    3636      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)+"%"; 
    3838      QTreeWidgetItem *tmp = new QTreeWidgetItem(text); 
    3939       
  • src-qt4/pc-mounttray/fsWatcher.cpp

    r781fd04 r6edfd8a  
    3535      QString avail = tmp[1].section(" ",0,0,QString::SectionSkipEmpty); 
    3636      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; 
    3939      int percent = calculatePercentage(iUsed, iTotal); 
    4040      //qDebug() << "Percent calc: tot:"<<iTotal<<"used"<<iUsed<<"percent"<<percent; 
     
    6060        QString used = dfout[i].section("  ",3,3,QString::SectionSkipEmpty).simplified(); 
    6161        //Calculate the percent 
    62         int iUsed = displayToInt(used); 
    63         int iTotal = displayToInt(total); 
     62        double iUsed = displayToDouble(used); 
     63        double iTotal = displayToDouble(total); 
    6464        int percent = calculatePercentage(iUsed, iTotal); 
    6565        //qDebug() << "df Item:" << dfout[i]; 
     
    7676} 
    7777 
    78 int FSWatcher::displayToInt(QString entry){ 
     78int FSWatcher::displayToDouble(QString entry){ 
    7979  //split the number from the size label 
    8080  //qDebug() << "Display to Int conversion:" << entry; 
     
    8383  double num = entry.toDouble(); 
    8484  //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; } 
    8991  //qDebug() << "number:" << num; 
    9092  return num; 
    9193} 
    9294 
    93 QString FSWatcher::intToDisplay(int K){ 
     95QString FSWatcher::doubleToDisplay(double K){ 
    9496  QString num; 
    9597  //qDebug() << "Int to Display:" << K; 
    9698  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  } 
    100110  //qDebug() << "Display:" << num; 
    101111  return num; 
     
    134144 
    135145//===== Calculate Percentages ===== 
    136 int FSWatcher::calculatePercentage(int used, int total){ 
     146int FSWatcher::calculatePercentage(double used, double total){ 
    137147  double U = used; 
    138148  double T = total; 
  • src-qt4/pc-mounttray/fsWatcher.h

    r781fd04 r6edfd8a  
    1212#include <QTime> 
    1313 
     14#include <math.h> 
    1415 
    1516class FSWatcher : public QObject 
     
    2526   
    2627  static QStringList getFSmountpoints(); 
    27   static QString intToDisplay(int); 
    28   static int displayToInt(QString);  
     28  static QString doubleToDisplay(double); 
     29  static int displayToDouble(QString);  
    2930   
    3031private: 
     
    3334   
    3435  static QStringList runCMD(QString); 
    35   static int calculatePercentage(int,int); 
     36  static int calculatePercentage(double,double); 
    3637   
    3738public slots: 
Note: See TracChangeset for help on using the changeset viewer.