From 03b1e15af6f1f176e02877d499dada17a428861a Mon Sep 17 00:00:00 2001 From: Spiros Date: Sun, 2 Jun 2024 21:40:09 +0300 Subject: [PATCH] Show health percentage for NVMe drives --- mainwindow.cpp | 10 +++++++++- mainwindow.ui | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/mainwindow.cpp b/mainwindow.cpp index 66d524a..b520562 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -223,6 +223,7 @@ void MainWindow::populateWindow(const QJsonObject &localObj, const QString &heal QString userCapacityString = QString::number(static_cast(userCapacityGB)) + "." + QString::number(static_cast((userCapacityGB - static_cast(userCapacityGB)) * 10)) + " GB"; QString totalReads = "----"; QString totalWrites = "----"; + QString percentage = ""; QString serialNumber = localObj["serial_number"].toString(); QJsonObject deviceObj = localObj["device"].toObject(); QString protocol = deviceObj["protocol"].toString(); @@ -341,6 +342,9 @@ void MainWindow::populateWindow(const QJsonObject &localObj, const QString &heal double dataUnitsRead = value.toDouble(); double totalGbRead = (dataUnitsRead * 512) / 1'000'000; totalReads = QString::number(static_cast(totalGbRead)) + " GB"; + } else if (key == "percentage_used") { + int percentageUsed = 100 - value.toInt(); + percentage = QString::number(percentageUsed) + " %"; } } } @@ -387,7 +391,11 @@ void MainWindow::populateWindow(const QJsonObject &localObj, const QString &heal healthStatusValue->setStyleSheet("background-color: " + QColor(Qt::green).name() + ";"); } - healthStatusValue->setText("

" + health + "

"); + QString percentageText = ""; + if (!percentage.isEmpty()) { + percentageText = "
" + percentage; + } + healthStatusValue->setText("

" + health + percentageText + "

"); healthStatusValue->setAlignment(Qt::AlignCenter); if (protocol != "NVMe") { diff --git a/mainwindow.ui b/mainwindow.ui index 2566a31..6beb178 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -107,7 +107,7 @@ background-color: rgb(0, 255, 0); - <html><head/><body><p align="center"><span style=" font-size:12pt; font-weight:700; color:#000000;">Good</span></p></body></html> + <html><head/><body><p align="center"><span style=" font-size:12pt; font-weight:700; color:#000000;">Good</span></p><p align="center"><span style=" font-size:12pt; font-weight:700; color:#000000;">100 %</span></p></body></html>