From 90c19c36ee4a4b8769675532b66d74952e6aafb9 Mon Sep 17 00:00:00 2001 From: spiros Date: Thu, 30 May 2024 04:01:07 +0300 Subject: [PATCH] Lay the groundwork for NVMe support --- .gitignore | 79 +++++++++++++++++++++++++++++++++----------------- mainwindow.cpp | 33 ++++++++++++++------- 2 files changed, 75 insertions(+), 37 deletions(-) diff --git a/.gitignore b/.gitignore index 259148f..5620586 100644 --- a/.gitignore +++ b/.gitignore @@ -1,32 +1,57 @@ -# Prerequisites -*.d - -# Compiled Object files +# C++ objects and libs *.slo *.lo *.o -*.obj - -# Precompiled Headers -*.gch -*.pch - -# Compiled Dynamic libraries -*.so -*.dylib -*.dll - -# Fortran module files -*.mod -*.smod - -# Compiled Static libraries -*.lai -*.la *.a -*.lib +*.la +*.lai +*.so +*.so.* +*.dll +*.dylib -# Executables -*.exe -*.out -*.app +# Qt-es +object_script.*.Release +object_script.*.Debug +*_plugin_import.cpp +/.qmake.cache +/.qmake.stash +*.pro.user +*.pro.user.* +*.qbs.user +*.qbs.user.* +*.moc +moc_*.cpp +moc_*.h +qrc_*.cpp +ui_*.h +*.qmlc +*.jsc +Makefile* +*build-* +*.qm +*.prl + +# Qt unit tests +target_wrapper.* + +# QtCreator +*.autosave + +# QtCreator Qml +*.qmlproject.user +*.qmlproject.user.* + +# QtCreator CMake +CMakeLists.txt.user* + +# QtCreator 4.8< compilation database +compile_commands.json + +# QtCreator local machine specific files for imported projects +*creator.user* + +*_qmlcache.qrc + +# The entire build directory +build/ diff --git a/mainwindow.cpp b/mainwindow.cpp index b5b3134..d062d8e 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -69,6 +69,7 @@ void MainWindow::scanDevices() QJsonObject localObj = localDoc.object(); QJsonArray attributes = localObj["ata_smart_attributes"].toObject()["table"].toArray(); + QJsonArray nvmeLog = localObj["nvme_smart_health_information_log"].toArray(); QString temperature = "N/A"; bool healthPassed = localObj["smart_status"].toObject()["passed"].toBool(); bool caution = false; @@ -86,11 +87,13 @@ void MainWindow::scanDevices() temperature = QString::number(temperatureInt) + " °C"; } - for (const QJsonValue &attr : attributes) { - QJsonObject attrObj = attr.toObject(); - if (!isNvme && (attrObj["id"] == 5 || attrObj["id"] == 197 || attrObj["id"] == 198) && (attrObj["raw"].toObject()["value"].toInt() != 0)) { - caution = true; - break; + if (!isNvme) { + for (const QJsonValue &attr : attributes) { + QJsonObject attrObj = attr.toObject(); + if (!isNvme && (attrObj["id"] == 5 || attrObj["id"] == 197 || attrObj["id"] == 198) && (attrObj["raw"].toObject()["value"].toInt() != 0)) { + caution = true; + break; + } } } @@ -121,9 +124,8 @@ void MainWindow::scanDevices() globalObj = localObj; globalHealth = health; button->setChecked(true); + firstTime = false; } - - firstTime = false; } horizontalLayout->addStretch(); populateWindow(globalObj, globalHealth); @@ -132,6 +134,7 @@ void MainWindow::scanDevices() void MainWindow::populateWindow(const QJsonObject &localObj, const QString &health) { QJsonArray attributes = localObj["ata_smart_attributes"].toObject()["table"].toArray(); + QJsonArray nvmeLog = localObj["nvme_smart_health_information_log"].toArray(); QString modelName = localObj["model_name"].toString(); QString firmwareVersion = localObj["firmware_version"].toString(); float userCapacityGB = localObj.value("user_capacity").toObject().value("bytes").toDouble() / 1e9; @@ -195,9 +198,19 @@ void MainWindow::populateWindow(const QJsonObject &localObj, const QString &heal for (const QJsonValue &attr : attributes) { //Need different logic for NVMe QJsonObject attrObj = attr.toObject(); if (attrObj["id"] == 241 && !isNvme) { - totalWrites = QString::number(attrObj["raw"].toObject()["value"].toInt()) + " GB"; + if (attrObj["name"] == "Host_Writes_32MiB") { + totalWrites = QString::number(attrObj["raw"].toObject()["value"].toInt()) + " GB"; + } else if (attrObj["name"] == "Host_Writes_32MiB") { + double gibibytes = (attrObj["raw"].toObject()["value"].toInt() * 32 * 1024.0 * 1024.0) / 1e9; + totalWrites = QString::number(static_cast(gibibytes)) + " GB"; + } } else if (attrObj["id"] == 242 && !isNvme) { - totalReads = QString::number(attrObj["raw"].toObject()["value"].toInt()) + " GB"; + if (attrObj["name"] == "Total_Reads_GB") { + totalReads = QString::number(attrObj["raw"].toObject()["value"].toInt()) + " GB"; + } else if (attrObj["name"] == "Host_Reads_32MiB") { + double gibibytes = (attrObj["raw"].toObject()["value"].toInt() * 32 * 1024.0 * 1024.0) / 1e9; + totalReads = QString::number(static_cast(gibibytes)) + " GB"; + } } } @@ -323,7 +336,7 @@ QString MainWindow::getSmartctlOutput(const QStringList &arguments, bool root) QProcess process; QString command; QStringList commandArgs; - if(root) { + if (root) { command = "pkexec"; commandArgs = {"smartctl"}; } else {