diff options
author | Lorn Potter <lorn.potter@nokia.com> | 2011-03-21 15:21:58 +1000 |
---|---|---|
committer | Lorn Potter <lorn.potter@nokia.com> | 2011-03-21 15:21:58 +1000 |
commit | e16f6f72db2be785c281e00671c33afdf9f113ae (patch) | |
tree | 9914e114400174b9945042f7c4a2211d47e65c76 /examples/sysinfo/dialog.cpp | |
parent | 8bda6edf43633196c3458f497d74d862f462ca0c (diff) |
add color per storage state and make storage size human readable.
Diffstat (limited to 'examples/sysinfo/dialog.cpp')
-rw-r--r-- | examples/sysinfo/dialog.cpp | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/examples/sysinfo/dialog.cpp b/examples/sysinfo/dialog.cpp index 0b9ed3a921..357eb0da3d 100644 --- a/examples/sysinfo/dialog.cpp +++ b/examples/sysinfo/dialog.cpp @@ -41,6 +41,8 @@ #include "dialog.h" #include <QMessageBox> #include <QTimer> +#include <math.h> + Dialog::Dialog() : QWidget(), @@ -309,16 +311,46 @@ void Dialog::updateStorage() QStringList items; items << volName; items << type; - items << QString::number(sti->totalDiskSpace(volName)); - items << QString::number(sti->availableDiskSpace(volName)); + items << sizeToString(sti->totalDiskSpace(volName)); + items << sizeToString(sti->availableDiskSpace(volName)); items << sti->uriForDrive(volName); items << storageStateToString(sti->getStorageState(volName)); QTreeWidgetItem *item = new QTreeWidgetItem(items); + + for (int i = 0; i < 5; i++) { + item->setBackground( i ,brushForStorageState( sti->getStorageState(volName))); + } storageTreeWidget->addTopLevelItem(item); } } +QBrush Dialog::brushForStorageState(QSystemStorageInfo::StorageState state) +{ + if (state == QSystemStorageInfo::CriticalStorageState) { + return QBrush(Qt::red); + } + if (state== QSystemStorageInfo::VeryLowStorageState) { + return QBrush(Qt::magenta); + } + if (state == QSystemStorageInfo::LowStorageState) { + return QBrush(Qt::yellow); + } + return QBrush(); +} + +QString Dialog:: sizeToString(qlonglong size) +{ + float fSize = size; + int i = 0; + const char* units[] = {"B", "kB", "MB", "GB", "TB"}; + while (fSize > 1024) { + fSize /= 1024.0; + i++; + } + fSize = round((fSize)*100)/100; + return QString::number(fSize)+" "+ units[i]; +} void Dialog::setupNetwork() { |