mirror of
https://github.com/edisionnano/QDiskInfo.git
synced 2026-04-11 15:01:27 +03:00
Merge branch 'main' into includes
This commit is contained in:
@@ -8,6 +8,7 @@ set(CMAKE_AUTORCC ON)
|
|||||||
|
|
||||||
set(CMAKE_CXX_STANDARD 17)
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
|
set(CMAKE_CXX_FLAGS "-Wall -Wextra -Wpedantic -Wuseless-cast -Wconversion -Wsign-conversion -Wshadow")
|
||||||
|
|
||||||
if(NOT DEFINED QT_VERSION_MAJOR)
|
if(NOT DEFINED QT_VERSION_MAJOR)
|
||||||
set(QT_VERSION_MAJOR 6)
|
set(QT_VERSION_MAJOR 6)
|
||||||
|
|||||||
@@ -3,8 +3,8 @@
|
|||||||
#include <QFontMetrics>
|
#include <QFontMetrics>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
|
||||||
CustomButton::CustomButton(const QString &text1, const QString &text2, const QString &text3, const QColor &lineColor, QWidget *parent)
|
CustomButton::CustomButton(const QString &text1_, const QString &text2_, const QString &text3_, const QColor &lineColor_, QWidget *parent)
|
||||||
: QPushButton(parent), text1(text1), text2(text2), text3(text3), lineColor(lineColor) {
|
: QPushButton(parent), text1(text1_), text2(text2_), text3(text3_), lineColor(lineColor_) {
|
||||||
setMinimumHeight(60);
|
setMinimumHeight(60);
|
||||||
adjustWidthToFitText();
|
adjustWidthToFitText();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ class CustomButton : public QPushButton {
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CustomButton(const QString &text1, const QString &text2, const QString &text3, const QColor &lineColor, QWidget *parent = nullptr);
|
CustomButton(const QString &text1_, const QString &text2_, const QString &text3_, const QColor &lineColor_, QWidget *parent = nullptr);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void paintEvent(QPaintEvent *event) override;
|
void paintEvent(QPaintEvent *event) override;
|
||||||
|
|||||||
@@ -30,10 +30,10 @@ QVector<QPair<QString, int>> JsonParser::parse(const QString &json)
|
|||||||
if (trimmedLine.contains("}")) {
|
if (trimmedLine.contains("}")) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
int colon_pos = trimmedLine.indexOf(":");
|
qsizetype colonPos = trimmedLine.indexOf(":");
|
||||||
if (colon_pos != -1) {
|
if (colonPos != -1) {
|
||||||
QString key = removeQuotes(trimmedLine.left(colon_pos));
|
QString key = removeQuotes(trimmedLine.left(colonPos));
|
||||||
QString valueString = trimmedLine.mid(colon_pos + 1).trimmed();
|
QString valueString = trimmedLine.mid(colonPos + 1).trimmed();
|
||||||
valueString.chop(1);
|
valueString.chop(1);
|
||||||
int value = valueString.toInt();
|
int value = valueString.toInt();
|
||||||
data.append(qMakePair(key, value));
|
data.append(qMakePair(key, value));
|
||||||
|
|||||||
@@ -110,21 +110,21 @@ MainWindow::~MainWindow()
|
|||||||
|
|
||||||
void MainWindow::onNextButtonClicked()
|
void MainWindow::onNextButtonClicked()
|
||||||
{
|
{
|
||||||
int currentIndex = buttonGroup->buttons().indexOf(buttonGroup->checkedButton());
|
qsizetype currentIndex = buttonGroup->buttons().indexOf(buttonGroup->checkedButton());
|
||||||
int nextIndex = (currentIndex + 1) % buttonGroup->buttons().size();
|
qsizetype nextIndex = (currentIndex + 1) % buttonGroup->buttons().size();
|
||||||
buttonGroup->buttons().at(nextIndex)->click();
|
buttonGroup->buttons().at(nextIndex)->click();
|
||||||
updateNavigationButtons(nextIndex);
|
updateNavigationButtons(nextIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::onPrevButtonClicked()
|
void MainWindow::onPrevButtonClicked()
|
||||||
{
|
{
|
||||||
int currentIndex = buttonGroup->buttons().indexOf(buttonGroup->checkedButton());
|
qsizetype currentIndex = buttonGroup->buttons().indexOf(buttonGroup->checkedButton());
|
||||||
int prevIndex = (currentIndex - 1 + buttonGroup->buttons().size()) % buttonGroup->buttons().size();
|
qsizetype prevIndex = (currentIndex - 1 + buttonGroup->buttons().size()) % buttonGroup->buttons().size();
|
||||||
buttonGroup->buttons().at(prevIndex)->click();
|
buttonGroup->buttons().at(prevIndex)->click();
|
||||||
updateNavigationButtons(prevIndex);
|
updateNavigationButtons(prevIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::updateNavigationButtons(int currentIndex)
|
void MainWindow::updateNavigationButtons(qsizetype currentIndex)
|
||||||
{
|
{
|
||||||
prevButton->setEnabled(currentIndex > 0 || (ui->actionCyclic_Navigation->isChecked() && buttonGroup->buttons().size() > 1)); // We can use setVisible if we want to mimic CrystalDiskInfo
|
prevButton->setEnabled(currentIndex > 0 || (ui->actionCyclic_Navigation->isChecked() && buttonGroup->buttons().size() > 1)); // We can use setVisible if we want to mimic CrystalDiskInfo
|
||||||
nextButton->setEnabled(currentIndex < buttonGroup->buttons().size() - 1 || ui->actionCyclic_Navigation->isChecked());
|
nextButton->setEnabled(currentIndex < buttonGroup->buttons().size() - 1 || ui->actionCyclic_Navigation->isChecked());
|
||||||
@@ -157,7 +157,7 @@ void MainWindow::updateUI()
|
|||||||
QString health;
|
QString health;
|
||||||
QColor healthColor;
|
QColor healthColor;
|
||||||
|
|
||||||
float diskCapacityGB = localObj.value("user_capacity").toObject().value("bytes").toDouble() / 1e9;
|
double diskCapacityGB = localObj.value("user_capacity").toObject().value("bytes").toDouble() / 1e9;
|
||||||
QString gbSymbol = locale.formattedDataSize(1 << 30, 1, QLocale::DataSizeTraditionalFormat).split(' ')[1];
|
QString gbSymbol = locale.formattedDataSize(1 << 30, 1, QLocale::DataSizeTraditionalFormat).split(' ')[1];
|
||||||
QString tbSymbol = locale.formattedDataSize(qint64(1) << 40, 1, QLocale::DataSizeTraditionalFormat).split(' ')[1];
|
QString tbSymbol = locale.formattedDataSize(qint64(1) << 40, 1, QLocale::DataSizeTraditionalFormat).split(' ')[1];
|
||||||
QString diskCapacityString;
|
QString diskCapacityString;
|
||||||
@@ -249,7 +249,7 @@ void MainWindow::updateUI()
|
|||||||
button->setCheckable(true);
|
button->setCheckable(true);
|
||||||
button->setAutoExclusive(true);
|
button->setAutoExclusive(true);
|
||||||
|
|
||||||
int buttonIndex = buttonGroup->buttons().indexOf(button);
|
qsizetype buttonIndex = buttonGroup->buttons().indexOf(button);
|
||||||
|
|
||||||
auto updateWindow = [=]() {
|
auto updateWindow = [=]() {
|
||||||
if (isNvme) {
|
if (isNvme) {
|
||||||
@@ -301,7 +301,7 @@ void MainWindow::populateWindow(const QJsonObject &localObj, const QString &heal
|
|||||||
QJsonObject nvmeLog = localObj["nvme_smart_health_information_log"].toObject();
|
QJsonObject nvmeLog = localObj["nvme_smart_health_information_log"].toObject();
|
||||||
QString modelName = localObj["model_name"].toString();
|
QString modelName = localObj["model_name"].toString();
|
||||||
QString firmwareVersion = localObj["firmware_version"].toString();
|
QString firmwareVersion = localObj["firmware_version"].toString();
|
||||||
float diskCapacityGB = localObj.value("user_capacity").toObject().value("bytes").toDouble() / 1e9;
|
double diskCapacityGB = localObj.value("user_capacity").toObject().value("bytes").toDouble() / 1e9;
|
||||||
int diskCapacityGbInt = static_cast<int>(diskCapacityGB);
|
int diskCapacityGbInt = static_cast<int>(diskCapacityGB);
|
||||||
int temperatureInt = localObj["temperature"].toObject()["current"].toInt();
|
int temperatureInt = localObj["temperature"].toObject()["current"].toInt();
|
||||||
int totalWritesInt = 0;
|
int totalWritesInt = 0;
|
||||||
@@ -335,32 +335,38 @@ void MainWindow::populateWindow(const QJsonObject &localObj, const QString &heal
|
|||||||
|
|
||||||
auto createTablePopup = [=](QJsonArray selfTestsTable) {
|
auto createTablePopup = [=](QJsonArray selfTestsTable) {
|
||||||
QWidget *popup = new QWidget();
|
QWidget *popup = new QWidget();
|
||||||
QTableWidget *tableWidget = new QTableWidget();
|
QTableWidget *selfTestsTableWidget = new QTableWidget();
|
||||||
|
selfTestsTableWidget->setFocusPolicy(Qt::NoFocus);
|
||||||
|
|
||||||
tableWidget->setRowCount(selfTestsTable.size());
|
qsizetype rowCount = selfTestsTable.size();
|
||||||
tableWidget->setColumnCount(3);
|
if (rowCount > std::numeric_limits<int>::max()) {
|
||||||
tableWidget->verticalHeader()->setVisible(false);
|
rowCount = std::numeric_limits<int>::max();
|
||||||
tableWidget->setHorizontalHeaderLabels({tr("Type"), tr("Status"), tr("Power On Hours")});
|
}
|
||||||
|
|
||||||
for (int i = 0; i < selfTestsTable.size(); ++i) {
|
selfTestsTableWidget->setRowCount(static_cast<int>(rowCount));
|
||||||
|
selfTestsTableWidget->setColumnCount(3);
|
||||||
|
selfTestsTableWidget->verticalHeader()->setVisible(false);
|
||||||
|
selfTestsTableWidget->setHorizontalHeaderLabels({tr("Type"), tr("Status"), tr("Power On Hours")});
|
||||||
|
|
||||||
|
for (int i = 0; i < rowCount; ++i) {
|
||||||
QJsonObject entry = selfTestsTable[i].toObject();
|
QJsonObject entry = selfTestsTable[i].toObject();
|
||||||
QTableWidgetItem *item;
|
QTableWidgetItem *item;
|
||||||
|
|
||||||
if (isNvme) {
|
if (isNvme) {
|
||||||
tableWidget->setItem(i, 0, new QTableWidgetItem(entry["self_test_code"].toObject()["string"].toString()));
|
selfTestsTableWidget->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()));
|
selfTestsTableWidget->setItem(i, 1, new QTableWidgetItem(entry["self_test_result"].toObject()["string"].toString()));
|
||||||
item = new QTableWidgetItem(QString::number(entry["power_on_hours"].toInt()));
|
item = new QTableWidgetItem(QString::number(entry["power_on_hours"].toInt()));
|
||||||
} else {
|
} else {
|
||||||
tableWidget->setItem(i, 0, new QTableWidgetItem(entry["type"].toObject()["string"].toString()));
|
selfTestsTableWidget->setItem(i, 0, new QTableWidgetItem(entry["type"].toObject()["string"].toString()));
|
||||||
tableWidget->setItem(i, 1, new QTableWidgetItem(entry["status"].toObject()["string"].toString()));
|
selfTestsTableWidget->setItem(i, 1, new QTableWidgetItem(entry["status"].toObject()["string"].toString()));
|
||||||
item = new QTableWidgetItem(QString::number(entry["lifetime_hours"].toInt()));
|
item = new QTableWidgetItem(QString::number(entry["lifetime_hours"].toInt()));
|
||||||
}
|
}
|
||||||
item->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter);
|
item->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter);
|
||||||
tableWidget->setItem(i, 2, item);
|
selfTestsTableWidget->setItem(i, 2, item);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < tableWidget->columnCount(); ++i) {
|
for (int i = 0; i < selfTestsTableWidget->columnCount(); ++i) {
|
||||||
QTableWidgetItem *headerItem = tableWidget->horizontalHeaderItem(i);
|
QTableWidgetItem *headerItem = selfTestsTableWidget->horizontalHeaderItem(i);
|
||||||
if (headerItem) {
|
if (headerItem) {
|
||||||
if (i == 2) {
|
if (i == 2) {
|
||||||
headerItem->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter);
|
headerItem->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter);
|
||||||
@@ -371,19 +377,19 @@ void MainWindow::populateWindow(const QJsonObject &localObj, const QString &heal
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
tableWidget->horizontalHeader()->setSectionResizeMode(1, QHeaderView::Stretch);
|
selfTestsTableWidget->horizontalHeader()->setSectionResizeMode(1, QHeaderView::Stretch);
|
||||||
for (int i = 0; i < tableWidget->columnCount(); ++i) {
|
for (int i = 0; i < selfTestsTableWidget->columnCount(); ++i) {
|
||||||
if (i != 1) {
|
if (i != 1) {
|
||||||
tableWidget->horizontalHeader()->setSectionResizeMode(i, QHeaderView::ResizeToContents);
|
selfTestsTableWidget->horizontalHeader()->setSectionResizeMode(i, QHeaderView::ResizeToContents);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tableWidget->verticalHeader()->setSectionResizeMode(QHeaderView::Fixed);
|
selfTestsTableWidget->verticalHeader()->setSectionResizeMode(QHeaderView::Fixed);
|
||||||
tableWidget->verticalHeader()->setDefaultSectionSize(31);
|
selfTestsTableWidget->verticalHeader()->setDefaultSectionSize(31);
|
||||||
tableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
selfTestsTableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
||||||
|
|
||||||
QVBoxLayout *layout = new QVBoxLayout;
|
QVBoxLayout *layout = new QVBoxLayout;
|
||||||
layout->addWidget(tableWidget);
|
layout->addWidget(selfTestsTableWidget);
|
||||||
popup->setLayout(layout);
|
popup->setLayout(layout);
|
||||||
popup->setWindowTitle(tr("Self Test Log"));
|
popup->setWindowTitle(tr("Self Test Log"));
|
||||||
popup->resize(400, 400);
|
popup->resize(400, 400);
|
||||||
@@ -455,10 +461,10 @@ void MainWindow::populateWindow(const QJsonObject &localObj, const QString &heal
|
|||||||
double gigabytes = (attrObj["raw"].toObject()["value"].toInt() * 32 * 1024.0 * 1024.0) / 1e9;
|
double gigabytes = (attrObj["raw"].toObject()["value"].toInt() * 32 * 1024.0 * 1024.0) / 1e9;
|
||||||
totalWritesInt = static_cast<int>(gigabytes);
|
totalWritesInt = static_cast<int>(gigabytes);
|
||||||
} else if (attrObj["name"] == "Total_LBAs_Written") {
|
} else if (attrObj["name"] == "Total_LBAs_Written") {
|
||||||
unsigned int logicalBlockSize = localObj["logical_block_size"].toInt();
|
int logicalBlockSize = localObj["logical_block_size"].toInt();
|
||||||
unsigned long long lbaWritten = attrObj["raw"].toObject()["value"].toVariant().toLongLong();
|
qlonglong lbaWritten = attrObj["raw"].toObject()["value"].toVariant().toLongLong();
|
||||||
unsigned long long oneGB = static_cast<unsigned long long>(std::pow(2, 30));
|
qlonglong oneGB = static_cast<qlonglong>(std::pow(2, 30));
|
||||||
unsigned long long gigabytes = (lbaWritten * logicalBlockSize) / oneGB;
|
qlonglong gigabytes = (lbaWritten * logicalBlockSize) / oneGB;
|
||||||
totalWritesInt = static_cast<int>(gigabytes);
|
totalWritesInt = static_cast<int>(gigabytes);
|
||||||
} else if (attrObj["name"] == "Host_Writes_GiB" || attrObj["name"] == "Lifetime_Writes_GiB") {
|
} else if (attrObj["name"] == "Host_Writes_GiB" || attrObj["name"] == "Lifetime_Writes_GiB") {
|
||||||
double gibibytes = attrObj["raw"].toObject()["value"].toDouble();
|
double gibibytes = attrObj["raw"].toObject()["value"].toDouble();
|
||||||
@@ -476,10 +482,10 @@ void MainWindow::populateWindow(const QJsonObject &localObj, const QString &heal
|
|||||||
double gigabytes = (attrObj["raw"].toObject()["value"].toInt() * 32 * 1024.0 * 1024.0) / 1e9;
|
double gigabytes = (attrObj["raw"].toObject()["value"].toInt() * 32 * 1024.0 * 1024.0) / 1e9;
|
||||||
totalReadsInt = static_cast<int>(gigabytes);
|
totalReadsInt = static_cast<int>(gigabytes);
|
||||||
} else if (attrObj["name"] == "Total_LBAs_Read") {
|
} else if (attrObj["name"] == "Total_LBAs_Read") {
|
||||||
unsigned int logicalBlockSize = localObj["logical_block_size"].toInt();
|
int logicalBlockSize = localObj["logical_block_size"].toInt();
|
||||||
unsigned long long lbaRead = attrObj["raw"].toObject()["value"].toVariant().toLongLong();
|
qlonglong lbaRead = attrObj["raw"].toObject()["value"].toVariant().toLongLong();
|
||||||
unsigned long long oneGB = static_cast<unsigned long long>(std::pow(2, 30));
|
qlonglong oneGB = static_cast<qlonglong>(std::pow(2, 30));
|
||||||
unsigned long long gigabytes = (lbaRead * logicalBlockSize) / oneGB;
|
qlonglong gigabytes = (lbaRead * logicalBlockSize) / oneGB;
|
||||||
totalReadsInt = static_cast<int>(gigabytes);
|
totalReadsInt = static_cast<int>(gigabytes);
|
||||||
} else if (attrObj["name"] == "Host_Reads_GiB" || attrObj["name"] == "Lifetime_Reads_GiB") {
|
} else if (attrObj["name"] == "Host_Reads_GiB" || attrObj["name"] == "Lifetime_Reads_GiB") {
|
||||||
double gibibytes = attrObj["raw"].toObject()["value"].toDouble();
|
double gibibytes = attrObj["raw"].toObject()["value"].toDouble();
|
||||||
@@ -491,10 +497,10 @@ void MainWindow::populateWindow(const QJsonObject &localObj, const QString &heal
|
|||||||
}
|
}
|
||||||
} else if (attrObj["id"] == 246) { // MX500
|
} else if (attrObj["id"] == 246) { // MX500
|
||||||
if (attrObj["name"] == "Total_LBAs_Written") {
|
if (attrObj["name"] == "Total_LBAs_Written") {
|
||||||
unsigned int logicalBlockSize = localObj["logical_block_size"].toInt();
|
int logicalBlockSize = localObj["logical_block_size"].toInt();
|
||||||
unsigned long long lbaWritten = attrObj["raw"].toObject()["value"].toVariant().toLongLong();
|
qlonglong lbaWritten = attrObj["raw"].toObject()["value"].toVariant().toLongLong();
|
||||||
unsigned long long oneGB = static_cast<unsigned long long>(std::pow(2, 30));
|
qlonglong oneGB = static_cast<qlonglong>(std::pow(2, 30));
|
||||||
unsigned long long gigabytes = (lbaWritten * logicalBlockSize) / oneGB;
|
qlonglong gigabytes = (lbaWritten * logicalBlockSize) / oneGB;
|
||||||
totalWritesInt = static_cast<int>(gigabytes);
|
totalWritesInt = static_cast<int>(gigabytes);
|
||||||
}
|
}
|
||||||
} else if (attrObj["name"] == "Remaining_Lifetime_Perc") {
|
} else if (attrObj["name"] == "Remaining_Lifetime_Perc") {
|
||||||
@@ -574,7 +580,7 @@ void MainWindow::populateWindow(const QJsonObject &localObj, const QString &heal
|
|||||||
nvmeHasSelfTest = true;
|
nvmeHasSelfTest = true;
|
||||||
}
|
}
|
||||||
} else if (stringValue.startsWith("Warning Comp. Temp. Threshold")) {
|
} else if (stringValue.startsWith("Warning Comp. Temp. Threshold")) {
|
||||||
int pos = stringValue.indexOf(':');
|
qsizetype pos = stringValue.indexOf(':');
|
||||||
if (pos != -1) {
|
if (pos != -1) {
|
||||||
QString thresholdStr = stringValue.mid(pos + 1).trimmed();
|
QString thresholdStr = stringValue.mid(pos + 1).trimmed();
|
||||||
int temperature = thresholdStr.section(' ', 0, 0).toInt();
|
int temperature = thresholdStr.section(' ', 0, 0).toInt();
|
||||||
@@ -583,7 +589,7 @@ void MainWindow::populateWindow(const QJsonObject &localObj, const QString &heal
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (stringValue.startsWith("Critical Comp. Temp. Threshold")) {
|
} else if (stringValue.startsWith("Critical Comp. Temp. Threshold")) {
|
||||||
int pos = stringValue.indexOf(':');
|
qsizetype pos = stringValue.indexOf(':');
|
||||||
if (pos != -1) {
|
if (pos != -1) {
|
||||||
QString thresholdStr = stringValue.mid(pos + 1).trimmed();
|
QString thresholdStr = stringValue.mid(pos + 1).trimmed();
|
||||||
int temperature = thresholdStr.section(' ', 0, 0).toInt();
|
int temperature = thresholdStr.section(' ', 0, 0).toInt();
|
||||||
@@ -649,7 +655,7 @@ void MainWindow::populateWindow(const QJsonObject &localObj, const QString &heal
|
|||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (const QString& key : keys) {
|
for (const QString& key : keys) {
|
||||||
QString minutes = QString::number(static_cast<int>(pollingMinutes[key].toInt()));
|
QString minutes = QString::number(pollingMinutes[key].toInt());
|
||||||
QString keyTranslated;
|
QString keyTranslated;
|
||||||
if (key == "short") {
|
if (key == "short") {
|
||||||
keyTranslated = tr("Short");
|
keyTranslated = tr("Short");
|
||||||
@@ -727,11 +733,17 @@ void MainWindow::addNvmeLogTable(const QVector<QPair<QString, int>>& nvmeLogOrde
|
|||||||
{
|
{
|
||||||
QString warningMessage = "";
|
QString warningMessage = "";
|
||||||
|
|
||||||
|
qsizetype rowCount = nvmeLogOrdered.size();
|
||||||
|
if (rowCount > std::numeric_limits<int>::max()) {
|
||||||
|
rowCount = std::numeric_limits<int>::max();
|
||||||
|
}
|
||||||
|
|
||||||
|
tableWidget->setRowCount(static_cast<int>(rowCount));
|
||||||
tableWidget->setColumnCount(4);
|
tableWidget->setColumnCount(4);
|
||||||
tableWidget->setHorizontalHeaderLabels({"", tr("ID"), tr("Attribute Name"), tr("Raw Values")});
|
tableWidget->setHorizontalHeaderLabels({"", tr("ID"), tr("Attribute Name"), tr("Raw Values")});
|
||||||
tableWidget->verticalHeader()->setVisible(false);
|
tableWidget->verticalHeader()->setVisible(false);
|
||||||
tableWidget->setItemDelegateForColumn(0, new StatusDot(tableWidget));
|
tableWidget->setItemDelegateForColumn(0, new StatusDot(tableWidget));
|
||||||
tableWidget->setRowCount(nvmeLogOrdered.size());
|
|
||||||
|
|
||||||
tableWidget->horizontalHeaderItem(2)->setTextAlignment(Qt::AlignLeft | Qt::AlignVCenter);
|
tableWidget->horizontalHeaderItem(2)->setTextAlignment(Qt::AlignLeft | Qt::AlignVCenter);
|
||||||
tableWidget->horizontalHeaderItem(3)->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter);
|
tableWidget->horizontalHeaderItem(3)->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter);
|
||||||
@@ -823,11 +835,16 @@ void MainWindow::addNvmeLogTable(const QVector<QPair<QString, int>>& nvmeLogOrde
|
|||||||
|
|
||||||
void MainWindow::addSmartAttributesTable(const QJsonArray &attributes)
|
void MainWindow::addSmartAttributesTable(const QJsonArray &attributes)
|
||||||
{
|
{
|
||||||
|
qsizetype rowCount = attributes.size();
|
||||||
|
if (rowCount > std::numeric_limits<int>::max()) {
|
||||||
|
rowCount = std::numeric_limits<int>::max();
|
||||||
|
}
|
||||||
|
|
||||||
|
tableWidget->setRowCount(static_cast<int>(rowCount));
|
||||||
tableWidget->setColumnCount(7);
|
tableWidget->setColumnCount(7);
|
||||||
tableWidget->setHorizontalHeaderLabels({"", tr("ID"), tr("Attribute Name"), tr("Current"), tr("Worst"), tr("Threshold"), tr("Raw Values")});
|
tableWidget->setHorizontalHeaderLabels({"", tr("ID"), tr("Attribute Name"), tr("Current"), tr("Worst"), tr("Threshold"), tr("Raw Values")});
|
||||||
tableWidget->verticalHeader()->setVisible(false);
|
tableWidget->verticalHeader()->setVisible(false);
|
||||||
tableWidget->setItemDelegateForColumn(0, new StatusDot(tableWidget));
|
tableWidget->setItemDelegateForColumn(0, new StatusDot(tableWidget));
|
||||||
tableWidget->setRowCount(attributes.size());
|
|
||||||
|
|
||||||
for (int i = 0; i < tableWidget->columnCount(); ++i) {
|
for (int i = 0; i < tableWidget->columnCount(); ++i) {
|
||||||
QTableWidgetItem *headerItem = tableWidget->horizontalHeaderItem(i);
|
QTableWidgetItem *headerItem = tableWidget->horizontalHeaderItem(i);
|
||||||
@@ -851,7 +868,7 @@ void MainWindow::addSmartAttributesTable(const QJsonArray &attributes)
|
|||||||
QString rawString = attrObj["raw"].toObject()["string"].toString();
|
QString rawString = attrObj["raw"].toObject()["string"].toString();
|
||||||
QString rawHEX = rawString;
|
QString rawHEX = rawString;
|
||||||
|
|
||||||
int spaceIndex = rawHEX.indexOf(' ');
|
qsizetype spaceIndex = rawHEX.indexOf(' ');
|
||||||
if (spaceIndex != -1) {
|
if (spaceIndex != -1) {
|
||||||
rawHEX = rawHEX.left(spaceIndex);
|
rawHEX = rawHEX.left(spaceIndex);
|
||||||
}
|
}
|
||||||
@@ -981,7 +998,7 @@ void MainWindow::on_actionAbout_triggered()
|
|||||||
|
|
||||||
void MainWindow::on_actionIgnore_C4_Reallocation_Event_Count_toggled(bool enabled)
|
void MainWindow::on_actionIgnore_C4_Reallocation_Event_Count_toggled(bool enabled)
|
||||||
{
|
{
|
||||||
settings.setValue("IgnoreC4", ui->actionIgnore_C4_Reallocation_Event_Count->isChecked());
|
settings.setValue("IgnoreC4", enabled);
|
||||||
if (!initializing) {
|
if (!initializing) {
|
||||||
Utils.clearButtonGroup(buttonGroup, horizontalLayout, buttonStretch, menuDisk);
|
Utils.clearButtonGroup(buttonGroup, horizontalLayout, buttonStretch, menuDisk);
|
||||||
updateUI();
|
updateUI();
|
||||||
@@ -990,7 +1007,7 @@ void MainWindow::on_actionIgnore_C4_Reallocation_Event_Count_toggled(bool enable
|
|||||||
|
|
||||||
void MainWindow::on_actionHEX_toggled(bool enabled)
|
void MainWindow::on_actionHEX_toggled(bool enabled)
|
||||||
{
|
{
|
||||||
settings.setValue("HEX", ui->actionHEX->isChecked());
|
settings.setValue("HEX", enabled);
|
||||||
if (!initializing) {
|
if (!initializing) {
|
||||||
Utils.clearButtonGroup(buttonGroup, horizontalLayout, buttonStretch, menuDisk);
|
Utils.clearButtonGroup(buttonGroup, horizontalLayout, buttonStretch, menuDisk);
|
||||||
updateUI();
|
updateUI();
|
||||||
@@ -999,7 +1016,7 @@ void MainWindow::on_actionHEX_toggled(bool enabled)
|
|||||||
|
|
||||||
void MainWindow::on_actionUse_Fahrenheit_toggled(bool enabled)
|
void MainWindow::on_actionUse_Fahrenheit_toggled(bool enabled)
|
||||||
{
|
{
|
||||||
settings.setValue("Fahrenheit", ui->actionUse_Fahrenheit->isChecked());
|
settings.setValue("Fahrenheit", enabled);
|
||||||
if (!initializing) {
|
if (!initializing) {
|
||||||
Utils.clearButtonGroup(buttonGroup, horizontalLayout, buttonStretch, menuDisk);
|
Utils.clearButtonGroup(buttonGroup, horizontalLayout, buttonStretch, menuDisk);
|
||||||
updateUI();
|
updateUI();
|
||||||
@@ -1008,14 +1025,14 @@ void MainWindow::on_actionUse_Fahrenheit_toggled(bool enabled)
|
|||||||
|
|
||||||
void MainWindow::on_actionCyclic_Navigation_toggled(bool cyclicNavigation)
|
void MainWindow::on_actionCyclic_Navigation_toggled(bool cyclicNavigation)
|
||||||
{
|
{
|
||||||
settings.setValue("CyclicNavigation", ui->actionCyclic_Navigation->isChecked());
|
settings.setValue("CyclicNavigation", cyclicNavigation);
|
||||||
int currentIndex = buttonGroup->buttons().indexOf(buttonGroup->checkedButton());
|
qsizetype currentIndex = buttonGroup->buttons().indexOf(buttonGroup->checkedButton());
|
||||||
updateNavigationButtons(currentIndex);
|
updateNavigationButtons(currentIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_actionUse_GB_instead_of_TB_toggled(bool gigabytes)
|
void MainWindow::on_actionUse_GB_instead_of_TB_toggled(bool gigabytes)
|
||||||
{
|
{
|
||||||
settings.setValue("UseGB", ui->actionUse_GB_instead_of_TB->isChecked());
|
settings.setValue("UseGB", gigabytes);
|
||||||
if (!initializing) {
|
if (!initializing) {
|
||||||
Utils.clearButtonGroup(buttonGroup, horizontalLayout, buttonStretch, menuDisk);
|
Utils.clearButtonGroup(buttonGroup, horizontalLayout, buttonStretch, menuDisk);
|
||||||
updateUI();
|
updateUI();
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ QT_END_NAMESPACE
|
|||||||
class MainWindow : public QMainWindow
|
class MainWindow : public QMainWindow
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
bool initializing;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MainWindow(QWidget *parent = nullptr);
|
MainWindow(QWidget *parent = nullptr);
|
||||||
@@ -33,27 +32,20 @@ public:
|
|||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void on_actionQuit_triggered();
|
void on_actionQuit_triggered();
|
||||||
|
|
||||||
void on_actionSave_JSON_triggered();
|
void on_actionSave_JSON_triggered();
|
||||||
|
|
||||||
void on_actionGitHub_triggered();
|
void on_actionGitHub_triggered();
|
||||||
|
|
||||||
void on_actionRescan_Refresh_triggered();
|
void on_actionRescan_Refresh_triggered();
|
||||||
|
|
||||||
void on_actionAbout_triggered();
|
void on_actionAbout_triggered();
|
||||||
|
|
||||||
void on_actionIgnore_C4_Reallocation_Event_Count_toggled(bool enabled);
|
void on_actionIgnore_C4_Reallocation_Event_Count_toggled(bool enabled);
|
||||||
|
|
||||||
void on_actionHEX_toggled(bool enabled);
|
void on_actionHEX_toggled(bool enabled);
|
||||||
|
|
||||||
void on_actionUse_Fahrenheit_toggled(bool enabled);
|
void on_actionUse_Fahrenheit_toggled(bool enabled);
|
||||||
|
|
||||||
void on_actionCyclic_Navigation_toggled(bool arg1);
|
void on_actionCyclic_Navigation_toggled(bool arg1);
|
||||||
|
|
||||||
void on_actionUse_GB_instead_of_TB_toggled(bool arg1);
|
void on_actionUse_GB_instead_of_TB_toggled(bool arg1);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::MainWindow *ui;
|
Ui::MainWindow *ui;
|
||||||
|
QSettings settings;
|
||||||
|
bool initializing;
|
||||||
QLocale locale;
|
QLocale locale;
|
||||||
utils Utils;
|
utils Utils;
|
||||||
QButtonGroup *buttonGroup;
|
QButtonGroup *buttonGroup;
|
||||||
@@ -66,15 +58,12 @@ private:
|
|||||||
QColor goodColor, cautionColor, badColor, naColor;
|
QColor goodColor, cautionColor, badColor, naColor;
|
||||||
QJsonObject deviceJson;
|
QJsonObject deviceJson;
|
||||||
QSpacerItem *buttonStretch;
|
QSpacerItem *buttonStretch;
|
||||||
QSettings settings;
|
|
||||||
QAction *actionCyclic_Navigation;
|
QAction *actionCyclic_Navigation;
|
||||||
|
|
||||||
QMenu *menuDevice;
|
QMenu *menuDevice;
|
||||||
QMenu *menuDisk;
|
QMenu *menuDisk;
|
||||||
QMenu *selfTestMenu;
|
QMenu *selfTestMenu;
|
||||||
QAction *selfTestLogAction;
|
QAction *selfTestLogAction;
|
||||||
QActionGroup *disksGroup;
|
QActionGroup *disksGroup;
|
||||||
|
|
||||||
QJsonArray devices;
|
QJsonArray devices;
|
||||||
QStringList deviceOutputs;
|
QStringList deviceOutputs;
|
||||||
QJsonObject globalObj;
|
QJsonObject globalObj;
|
||||||
@@ -84,10 +73,12 @@ private:
|
|||||||
|
|
||||||
void onNextButtonClicked();
|
void onNextButtonClicked();
|
||||||
void onPrevButtonClicked();
|
void onPrevButtonClicked();
|
||||||
void updateNavigationButtons(int currentIndex);
|
void updateNavigationButtons(qsizetype currentIndex);
|
||||||
void updateUI();
|
void updateUI();
|
||||||
void populateWindow(const QJsonObject &tempObj, const QString &health, const QVector<QPair<QString, int>>& nvmeLogOrdered = QVector<QPair<QString, int>>());
|
void populateWindow(const QJsonObject &tempObj, const QString &health, const QVector<QPair<QString, int>>& nvmeLogOrdered = QVector<QPair<QString, int>>());
|
||||||
void addNvmeLogTable(const QVector<QPair<QString, int>>& nvmeLogOrdered);
|
void addNvmeLogTable(const QVector<QPair<QString, int>>& nvmeLogOrdered);
|
||||||
void addSmartAttributesTable(const QJsonArray &attributes);
|
void addSmartAttributesTable(const QJsonArray &attributes);
|
||||||
void mousePressEvent(QMouseEvent*);
|
void mousePressEvent(QMouseEvent*);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ void StatusDot::paint(QPainter *painter, const QStyleOptionViewItem &option, con
|
|||||||
painter->save();
|
painter->save();
|
||||||
painter->setRenderHint(QPainter::Antialiasing, true);
|
painter->setRenderHint(QPainter::Antialiasing, true);
|
||||||
QRect dotRect(opt.rect.center().x() - dotSize / 2, opt.rect.center().y() - dotSize / 2, dotSize, dotSize);
|
QRect dotRect(opt.rect.center().x() - dotSize / 2, opt.rect.center().y() - dotSize / 2, dotSize, dotSize);
|
||||||
QColor color = QColor(index.data(Qt::BackgroundRole).value<QColor>());
|
QColor color = index.data(Qt::BackgroundRole).value<QColor>();
|
||||||
painter->setBrush(color);
|
painter->setBrush(color);
|
||||||
painter->setPen(Qt::NoPen);
|
painter->setPen(Qt::NoPen);
|
||||||
painter->drawEllipse(dotRect);
|
painter->drawEllipse(dotRect);
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ void utils::clearButtonGroup(QButtonGroup* buttonGroup, QHBoxLayout* horizontalL
|
|||||||
menuDisk->clear();
|
menuDisk->clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString utils::getSmartctlPath(bool initializing) {
|
QString utils::getSmartctlPath() {
|
||||||
QStringList paths = QString::fromLocal8Bit(qgetenv("PATH")).split(QDir::listSeparator(), Qt::SkipEmptyParts);
|
QStringList paths = QString::fromLocal8Bit(qgetenv("PATH")).split(QDir::listSeparator(), Qt::SkipEmptyParts);
|
||||||
|
|
||||||
paths << "/usr/sbin" << "/usr/local/sbin";
|
paths << "/usr/sbin" << "/usr/local/sbin";
|
||||||
@@ -45,10 +45,10 @@ QString utils::getSmartctlOutput(const QStringList &arguments, bool root, bool i
|
|||||||
if (root) {
|
if (root) {
|
||||||
command = "pkexec";
|
command = "pkexec";
|
||||||
} else {
|
} else {
|
||||||
command = getSmartctlPath(initializing);
|
command = getSmartctlPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!getSmartctlPath(initializing).isEmpty()) {
|
if (!getSmartctlPath().isEmpty()) {
|
||||||
process.start(command, arguments);
|
process.start(command, arguments);
|
||||||
process.waitForFinished(-1);
|
process.waitForFinished(-1);
|
||||||
}
|
}
|
||||||
@@ -75,14 +75,14 @@ QPair<QStringList, QJsonArray> utils::scanDevices(bool initializing)
|
|||||||
QJsonDocument doc = QJsonDocument::fromJson(output.toUtf8());
|
QJsonDocument doc = QJsonDocument::fromJson(output.toUtf8());
|
||||||
QJsonObject jsonObj = doc.object();
|
QJsonObject jsonObj = doc.object();
|
||||||
QJsonArray devices = jsonObj["devices"].toArray();
|
QJsonArray devices = jsonObj["devices"].toArray();
|
||||||
QString smartctlPath = getSmartctlPath(initializing);
|
QString smartctlPath = getSmartctlPath();
|
||||||
QStringList commandList;
|
QStringList commandList;
|
||||||
QStringList deviceOutputs;
|
QStringList deviceOutputs;
|
||||||
|
|
||||||
for (const QJsonValue &value : std::as_const(devices)) {
|
for (const QJsonValue &value : std::as_const(devices)) {
|
||||||
QJsonObject device = value.toObject();
|
QJsonObject device = value.toObject();
|
||||||
QString deviceName = device["name"].toString();
|
QString deviceName = device["name"].toString();
|
||||||
commandList.append(QString(smartctlPath + " --all --json=o %1").arg(deviceName));
|
commandList.append((smartctlPath + " --all --json=o %1").arg(deviceName));
|
||||||
}
|
}
|
||||||
QString command = commandList.join(" ; ");
|
QString command = commandList.join(" ; ");
|
||||||
|
|
||||||
@@ -93,8 +93,8 @@ QPair<QStringList, QJsonArray> utils::scanDevices(bool initializing)
|
|||||||
|
|
||||||
QString allDevicesOutput = getSmartctlOutput({"sh", "-c", command}, true, initializing);
|
QString allDevicesOutput = getSmartctlOutput({"sh", "-c", command}, true, initializing);
|
||||||
|
|
||||||
int startIndex = 0;
|
qsizetype startIndex = 0;
|
||||||
int endIndex = 0;
|
qsizetype endIndex = 0;
|
||||||
|
|
||||||
static const QRegularExpression regex("\\}\\n\\{");
|
static const QRegularExpression regex("\\}\\n\\{");
|
||||||
|
|
||||||
@@ -120,7 +120,7 @@ QPair<QStringList, QJsonArray> utils::scanDevices(bool initializing)
|
|||||||
QString utils::initiateSelfTest(const QString &testType, const QString &deviceNode)
|
QString utils::initiateSelfTest(const QString &testType, const QString &deviceNode)
|
||||||
{
|
{
|
||||||
QProcess process;
|
QProcess process;
|
||||||
QString command = getSmartctlPath(false);
|
QString command = getSmartctlPath();
|
||||||
QStringList arguments;
|
QStringList arguments;
|
||||||
arguments << command << "--json=o" << "-t" << testType << deviceNode;
|
arguments << command << "--json=o" << "-t" << testType << deviceNode;
|
||||||
|
|
||||||
@@ -137,7 +137,7 @@ QString utils::initiateSelfTest(const QString &testType, const QString &deviceNo
|
|||||||
void utils::cancelSelfTest(const QString &deviceNode)
|
void utils::cancelSelfTest(const QString &deviceNode)
|
||||||
{
|
{
|
||||||
QProcess process;
|
QProcess process;
|
||||||
QString command = getSmartctlPath(false);
|
QString command = getSmartctlPath();
|
||||||
QStringList arguments;
|
QStringList arguments;
|
||||||
arguments << command << "-X" << deviceNode;
|
arguments << command << "-X" << deviceNode;
|
||||||
|
|
||||||
@@ -161,8 +161,6 @@ void utils::selfTestHandler(const QString &mode, const QString &name, const QStr
|
|||||||
QJsonDocument testDoc = QJsonDocument::fromJson(output.toUtf8());
|
QJsonDocument testDoc = QJsonDocument::fromJson(output.toUtf8());
|
||||||
QJsonObject testObj = testDoc.object();
|
QJsonObject testObj = testDoc.object();
|
||||||
QJsonObject smartctlObj = testObj.value("smartctl").toObject();
|
QJsonObject smartctlObj = testObj.value("smartctl").toObject();
|
||||||
QJsonObject deviceObj = testObj.value("device").toObject();
|
|
||||||
QString name = deviceObj.value("name").toString();
|
|
||||||
int exitStatus = smartctlObj.value("exit_status").toInt();
|
int exitStatus = smartctlObj.value("exit_status").toInt();
|
||||||
|
|
||||||
QJsonArray outputArray = smartctlObj["output"].toArray();
|
QJsonArray outputArray = smartctlObj["output"].toArray();
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ public:
|
|||||||
utils() = default;
|
utils() = default;
|
||||||
|
|
||||||
void clearButtonGroup(QButtonGroup* buttonGroup, QHBoxLayout* horizontalLayout, QSpacerItem* buttonStretch, QMenu* menuDisk);
|
void clearButtonGroup(QButtonGroup* buttonGroup, QHBoxLayout* horizontalLayout, QSpacerItem* buttonStretch, QMenu* menuDisk);
|
||||||
QString getSmartctlPath(bool initializing);
|
QString getSmartctlPath();
|
||||||
QString getSmartctlOutput(const QStringList &arguments, bool root, bool initializing);
|
QString getSmartctlOutput(const QStringList &arguments, bool root, bool initializing);
|
||||||
QPair<QStringList, QJsonArray> scanDevices(bool initializing);
|
QPair<QStringList, QJsonArray> scanDevices(bool initializing);
|
||||||
QString initiateSelfTest(const QString &testType, const QString &deviceNode);
|
QString initiateSelfTest(const QString &testType, const QString &deviceNode);
|
||||||
@@ -20,3 +20,5 @@ public:
|
|||||||
void selfTestHandler(const QString &mode, const QString &name, const QString &minutes);
|
void selfTestHandler(const QString &mode, const QString &name, const QString &minutes);
|
||||||
QString toTitleCase(const QString& sentence);
|
QString toTitleCase(const QString& sentence);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user