mirror of
https://github.com/edisionnano/QDiskInfo.git
synced 2026-04-22 10:53:20 +03:00
Add nvme self test log
This commit is contained in:
@@ -52,9 +52,12 @@ MainWindow::MainWindow(QWidget *parent)
|
|||||||
menuDevice = ui->menuDevice;
|
menuDevice = ui->menuDevice;
|
||||||
menuDisk = ui->menuDisk;
|
menuDisk = ui->menuDisk;
|
||||||
|
|
||||||
toolMenu = new QMenu("Self Test", this);
|
selfTestMenu = new QMenu("Start Self Test", this);
|
||||||
menuDevice->addMenu(toolMenu);
|
menuDevice->addMenu(selfTestMenu);
|
||||||
toolMenu->setToolTipsVisible(true);
|
selfTestMenu->setToolTipsVisible(true);
|
||||||
|
|
||||||
|
selfTestLogAction = new QAction("Self Test Log", this);
|
||||||
|
menuDevice->addAction(selfTestLogAction);
|
||||||
|
|
||||||
disksGroup = new QActionGroup(this);
|
disksGroup = new QActionGroup(this);
|
||||||
disksGroup->setExclusive(true);
|
disksGroup->setExclusive(true);
|
||||||
@@ -401,8 +404,53 @@ void MainWindow::populateWindow(const QJsonObject &localObj, const QString &heal
|
|||||||
QString type = deviceObj["type"].toString();
|
QString type = deviceObj["type"].toString();
|
||||||
QString name = deviceObj["name"].toString();
|
QString name = deviceObj["name"].toString();
|
||||||
|
|
||||||
|
QJsonArray nvmeSelfTestsTable = localObj["nvme_self_test_log"].toObject()["table"].toArray();
|
||||||
|
QJsonArray ataSelfTestsTable = localObj["ata_smart_self_test_log"].toObject()["standard"].toObject()["table"].toArray();
|
||||||
|
|
||||||
bool isNvme = (protocol == "NVMe");
|
bool isNvme = (protocol == "NVMe");
|
||||||
|
|
||||||
|
auto createTablePopup = [=](QJsonArray selfTestsTable) {
|
||||||
|
QWidget *popup = new QWidget();
|
||||||
|
QTableWidget *tableWidget = new QTableWidget();
|
||||||
|
|
||||||
|
tableWidget->setRowCount(selfTestsTable.size());
|
||||||
|
tableWidget->setColumnCount(3);
|
||||||
|
tableWidget->verticalHeader()->setVisible(false);
|
||||||
|
tableWidget->setHorizontalHeaderLabels({tr("Type"), tr("Status"), tr("Power On Hours")});
|
||||||
|
|
||||||
|
for (int i = 0; i < selfTestsTable.size(); ++i) {
|
||||||
|
QJsonObject entry = selfTestsTable[i].toObject();
|
||||||
|
if (isNvme) {
|
||||||
|
tableWidget->setItem(i, 0, new QTableWidgetItem(entry["self_test_code"].toObject()["string"].toString()));
|
||||||
|
tableWidget->setItem(i, 1, new QTableWidgetItem(entry["self_test_result"].toObject()["string"].toString()));
|
||||||
|
tableWidget->setItem(i, 2, new QTableWidgetItem(QString::number(entry["power_on_hours"].toInt())));
|
||||||
|
} else {
|
||||||
|
tableWidget->setItem(i, 0, new QTableWidgetItem(entry["type"].toObject()["string"].toString()));
|
||||||
|
tableWidget->setItem(i, 1, new QTableWidgetItem(entry["status"].toObject()["string"].toString()));
|
||||||
|
tableWidget->setItem(i, 2, new QTableWidgetItem(QString::number(entry["lifetime_hours"].toInt())));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tableWidget->horizontalHeader()->setSectionResizeMode(2, QHeaderView::Stretch);
|
||||||
|
for (int i = 0; i < tableWidget->columnCount(); ++i) {
|
||||||
|
if (i != 2) {
|
||||||
|
tableWidget->horizontalHeader()->setSectionResizeMode(i, QHeaderView::ResizeToContents);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tableWidget->verticalHeader()->setSectionResizeMode(QHeaderView::Fixed);
|
||||||
|
tableWidget->verticalHeader()->setDefaultSectionSize(31);
|
||||||
|
tableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
||||||
|
|
||||||
|
QVBoxLayout *layout = new QVBoxLayout;
|
||||||
|
layout->addWidget(tableWidget);
|
||||||
|
popup->setLayout(layout);
|
||||||
|
|
||||||
|
popup->setWindowTitle(tr("Self Test Log"));
|
||||||
|
popup->resize(500, 400);
|
||||||
|
popup->show();
|
||||||
|
};
|
||||||
|
|
||||||
deviceJson = localObj;
|
deviceJson = localObj;
|
||||||
|
|
||||||
diskName->setText("<html><head/><body><p><span style='font-size:14pt; font-weight:bold;'>" + modelName + " " + userCapacityString + "</span></p></body></html>");
|
diskName->setText("<html><head/><body><p><span style='font-size:14pt; font-weight:bold;'>" + modelName + " " + userCapacityString + "</span></p></body></html>");
|
||||||
@@ -609,7 +657,13 @@ void MainWindow::populateWindow(const QJsonObject &localObj, const QString &heal
|
|||||||
|
|
||||||
if (protocol != "NVMe") {
|
if (protocol != "NVMe") {
|
||||||
addSmartAttributesTable(attributes);
|
addSmartAttributesTable(attributes);
|
||||||
toolMenu->clear();
|
selfTestMenu->clear();
|
||||||
|
|
||||||
|
if (keys.isEmpty()) {
|
||||||
|
selfTestMenu->setDisabled(true);
|
||||||
|
} else {
|
||||||
|
selfTestMenu->setEnabled(true);
|
||||||
|
}
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (const QString& key : keys) {
|
for (const QString& key : keys) {
|
||||||
@@ -617,7 +671,7 @@ void MainWindow::populateWindow(const QJsonObject &localObj, const QString &heal
|
|||||||
QString actionLabel = key + " (" + minutes + tr(" Min.)");
|
QString actionLabel = key + " (" + minutes + tr(" Min.)");
|
||||||
actionLabel[0] = actionLabel[0].toUpper();
|
actionLabel[0] = actionLabel[0].toUpper();
|
||||||
QAction *action = new QAction(actionLabel, this);
|
QAction *action = new QAction(actionLabel, this);
|
||||||
toolMenu->addAction(action);
|
selfTestMenu->addAction(action);
|
||||||
|
|
||||||
QString mode;
|
QString mode;
|
||||||
if (key == "extended") {
|
if (key == "extended") {
|
||||||
@@ -632,21 +686,42 @@ void MainWindow::populateWindow(const QJsonObject &localObj, const QString &heal
|
|||||||
|
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ataSelfTestsTable.isEmpty()) {
|
||||||
|
selfTestLogAction->setDisabled(true);
|
||||||
|
} else {
|
||||||
|
selfTestLogAction->setEnabled(true);
|
||||||
|
selfTestLogAction->disconnect();
|
||||||
|
connect(selfTestLogAction, &QAction::triggered, this, [=]() {
|
||||||
|
createTablePopup(ataSelfTestsTable);
|
||||||
|
});
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
addNvmeLogTable(nvmeLogOrdered);
|
addNvmeLogTable(nvmeLogOrdered);
|
||||||
toolMenu->clear();
|
selfTestMenu->clear();
|
||||||
|
selfTestMenu->setEnabled(true);
|
||||||
|
|
||||||
QAction *actionShort = new QAction("Short", this);
|
QAction *actionShort = new QAction("Short", this);
|
||||||
toolMenu->addAction(actionShort);
|
selfTestMenu->addAction(actionShort);
|
||||||
connect(actionShort, &QAction::triggered, this, [this, mode = "short", name, minutes = "0"]() {
|
connect(actionShort, &QAction::triggered, this, [this, mode = "short", name, minutes = "0"]() {
|
||||||
selfTestHandler(mode, name, minutes);
|
selfTestHandler(mode, name, minutes);
|
||||||
});
|
});
|
||||||
|
|
||||||
QAction *actionLong = new QAction("Extended", this);
|
QAction *actionLong = new QAction("Extended", this);
|
||||||
toolMenu->addAction(actionLong);
|
selfTestMenu->addAction(actionLong);
|
||||||
connect(actionLong , &QAction::triggered, this, [this, mode = "long", name, minutes = "0"]() {
|
connect(actionLong , &QAction::triggered, this, [this, mode = "long", name, minutes = "0"]() {
|
||||||
selfTestHandler(mode, name, minutes);
|
selfTestHandler(mode, name, minutes);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (nvmeSelfTestsTable.isEmpty()) {
|
||||||
|
selfTestLogAction->setDisabled(true);
|
||||||
|
} else {
|
||||||
|
selfTestLogAction->setEnabled(true);
|
||||||
|
selfTestLogAction->disconnect();
|
||||||
|
connect(selfTestLogAction, &QAction::triggered, this, [=]() {
|
||||||
|
createTablePopup(nvmeSelfTestsTable);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -76,7 +76,8 @@ private:
|
|||||||
|
|
||||||
QMenu *menuDevice;
|
QMenu *menuDevice;
|
||||||
QMenu *menuDisk;
|
QMenu *menuDisk;
|
||||||
QMenu *toolMenu;
|
QMenu *selfTestMenu;
|
||||||
|
QAction *selfTestLogAction;
|
||||||
QActionGroup *disksGroup;
|
QActionGroup *disksGroup;
|
||||||
|
|
||||||
QJsonArray devices;
|
QJsonArray devices;
|
||||||
|
|||||||
Reference in New Issue
Block a user