From 1016f82a2b2cf107e95da4e4955b623b972e9071 Mon Sep 17 00:00:00 2001 From: Spiros Date: Mon, 10 Jun 2024 04:58:15 +0300 Subject: [PATCH] Lay the groundwork for selftesting --- mainwindow.cpp | 26 +++++++- mainwindow.h | 2 + mainwindow.ui | 160 +++++++++++++++++++++++++++++-------------------- 3 files changed, 123 insertions(+), 65 deletions(-) diff --git a/mainwindow.cpp b/mainwindow.cpp index 0c7740f..f0df39f 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -41,6 +41,11 @@ MainWindow::MainWindow(QWidget *parent) nextButton->setFocusPolicy(Qt::NoFocus); prevButton->setFocusPolicy(Qt::NoFocus); + selfTestButton = ui->centralwidget->findChild("selfTestButton"); + toolMenu = new QMenu(selfTestButton); + selfTestButton->setMenu(toolMenu); + toolMenu->setToolTipsVisible(true); + goodColor = QColor(Qt::green); cautionColor = QColor(Qt::yellow); badColor = QColor(Qt::red); @@ -268,6 +273,7 @@ void MainWindow::updateUI() void MainWindow::populateWindow(const QJsonObject &localObj, const QString &health, const QVector>& nvmeLogOrdered) { QJsonArray attributes = localObj["ata_smart_attributes"].toObject()["table"].toArray(); + QJsonObject pollingMinutes = localObj["ata_smart_data"].toObject()["self_test"].toObject()["polling_minutes"].toObject(); QJsonObject nvmeLog = localObj["nvme_smart_health_information_log"].toObject(); QString modelName = localObj["model_name"].toString(); QString firmwareVersion = localObj["firmware_version"].toString(); @@ -294,6 +300,11 @@ void MainWindow::populateWindow(const QJsonObject &localObj, const QString &heal protocolLineEdit->setText(protocol); deviceNodeLineEdit->setText(name); + QStringList keys = pollingMinutes.keys(); + std::sort(keys.begin(), keys.end(), [&pollingMinutes](const QString& key1, const QString& key2) { + return pollingMinutes[key1].toInt() < pollingMinutes[key2].toInt(); + }); + int rotationRateInt = localObj["rotation_rate"].toInt(-1); QString rotationRate; if (rotationRateInt > 0) { @@ -480,8 +491,21 @@ void MainWindow::populateWindow(const QJsonObject &localObj, const QString &heal if (protocol != "NVMe") { addSmartAttributesTable(attributes); + selfTestButton->setEnabled(true); + toolMenu->clear(); + + int i = 0; + for (const QString& key : keys) { + QString minutes = QString::number(static_cast(pollingMinutes[key].toInt())); + QString actionLabel = key + " (" + minutes + tr(" Min.)"); + actionLabel[0] = actionLabel[0].toUpper(); + QAction *action = new QAction(actionLabel, this); + toolMenu->addAction(action); + i++; + } } else { addNvmeLogTable(nvmeLogOrdered); + selfTestButton->setDisabled(true); } } @@ -575,7 +599,7 @@ void MainWindow::addNvmeLogTable(const QVector>& nvmeLogOrde ++row; } - if(!warningMessage.isEmpty()) { + if (!warningMessage.isEmpty()) { QMessageBox::warning(nullptr, tr("Critical Warning"), warningMessage); } } diff --git a/mainwindow.h b/mainwindow.h index cd0276e..2a3ce5c 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -67,6 +67,8 @@ private: QJsonObject deviceJson; QSpacerItem *buttonStretch; QSettings settings; + QToolButton *selfTestButton; + QMenu *toolMenu; QJsonArray devices; QStringList deviceOutputs; diff --git a/mainwindow.ui b/mainwindow.ui index b57dd29..bc31314 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -26,70 +26,6 @@ - - - - - - - - - - - - - - - - - - - - - - - Qt::Orientation::Horizontal - - - - 40 - 20 - - - - - - - - <html><head/><body><p align="center"><span style=" font-size:14pt; font-weight:700;">Hard Drive Name</span></p></body></html> - - - - - - - Qt::Orientation::Horizontal - - - - 40 - 20 - - - - - - - - - - - - - - - - @@ -300,6 +236,70 @@ + + + + + + + + + + + + + + + + + + + + + + + Qt::Orientation::Horizontal + + + + 40 + 20 + + + + + + + + <html><head/><body><p align="center"><span style=" font-size:14pt; font-weight:700;">Hard Drive Name</span></p></body></html> + + + + + + + Qt::Orientation::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + + + + @@ -316,6 +316,33 @@ + + + + + + Start Self-test + + + QToolButton::ToolButtonPopupMode::InstantPopup + + + + + + + Qt::Orientation::Horizontal + + + + 40 + 20 + + + + + + @@ -434,6 +461,11 @@ &Use Fahrenheit + + + &Self Test + +