mirror of
https://github.com/edisionnano/QDiskInfo.git
synced 2026-04-08 15:41:29 +03:00
Add selftest support
This commit is contained in:
@@ -181,7 +181,6 @@ void MainWindow::updateUI()
|
|||||||
QJsonObject attrObj = attr.toObject();
|
QJsonObject attrObj = attr.toObject();
|
||||||
if ((attrObj["id"] == 5 || attrObj["id"] == 197 || attrObj["id"] == 198 || (attrObj["id"] == 196 && !(ui->actionIgnore_C4_Reallocation_Event_Count->isChecked()))) && attrObj["raw"].toObject()["value"].toDouble()) {
|
if ((attrObj["id"] == 5 || attrObj["id"] == 197 || attrObj["id"] == 198 || (attrObj["id"] == 196 && !(ui->actionIgnore_C4_Reallocation_Event_Count->isChecked()))) && attrObj["raw"].toObject()["value"].toDouble()) {
|
||||||
caution = true;
|
caution = true;
|
||||||
qDebug() << "here";
|
|
||||||
}
|
}
|
||||||
if (attrObj["thresh"].toInt() && (attrObj["value"].toInt() < attrObj["thresh"].toInt())) {
|
if (attrObj["thresh"].toInt() && (attrObj["value"].toInt() < attrObj["thresh"].toInt())) {
|
||||||
bad = true;
|
bad = true;
|
||||||
@@ -501,8 +500,30 @@ void MainWindow::populateWindow(const QJsonObject &localObj, const QString &heal
|
|||||||
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);
|
toolMenu->addAction(action);
|
||||||
connect(action, &QAction::triggered, this, [this]() {
|
|
||||||
QMessageBox::warning(this, "Warning", "This is a warning message.");
|
QString mode;
|
||||||
|
if (key == "extended") {
|
||||||
|
mode = "long";
|
||||||
|
} else {
|
||||||
|
mode = key;
|
||||||
|
}
|
||||||
|
|
||||||
|
connect(action, &QAction::triggered, this, [this, mode, name]() {
|
||||||
|
QString output = initiateSelfTest(mode, name);
|
||||||
|
if (output.isEmpty()) {
|
||||||
|
QMessageBox::critical(this, tr("KDiskInfo Error"), tr("KDiskInfo needs root access in order to request a self-test!"));
|
||||||
|
} else {
|
||||||
|
QJsonDocument testDoc = QJsonDocument::fromJson(output.toUtf8());
|
||||||
|
QJsonObject testObj = testDoc.object();
|
||||||
|
QJsonObject smartctlObj = testObj.value("smartctl").toObject();
|
||||||
|
int exitStatus = smartctlObj.value("exit_status").toInt();
|
||||||
|
|
||||||
|
if (exitStatus == 4) {
|
||||||
|
QMessageBox::warning(this, tr("Test Already Running"), tr("A self-test is already being performed"));
|
||||||
|
} else if (exitStatus == 0) {
|
||||||
|
QMessageBox::information(this, tr("Test Requested"), tr("Self-test requested successfully"));
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
@@ -872,3 +893,18 @@ void MainWindow::on_actionUse_Fahrenheit_toggled(bool enabled)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString MainWindow::initiateSelfTest(const QString &testType, const QString &deviceNode)
|
||||||
|
{
|
||||||
|
QProcess process;
|
||||||
|
QString command = "pkexec";
|
||||||
|
QStringList arguments;
|
||||||
|
arguments << "smartctl" << "--json" << "-t" << testType << deviceNode;
|
||||||
|
|
||||||
|
process.start(command, arguments);
|
||||||
|
process.waitForFinished(-1);
|
||||||
|
|
||||||
|
QString output = process.readAllStandardOutput();
|
||||||
|
QString errorOutput = process.readAllStandardError();
|
||||||
|
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|||||||
@@ -89,5 +89,6 @@ private:
|
|||||||
QString getSmartctlOutput(const QStringList &arguments, bool root);
|
QString getSmartctlOutput(const QStringList &arguments, bool root);
|
||||||
QString toTitleCase(const QString& sentence);
|
QString toTitleCase(const QString& sentence);
|
||||||
void clearButtonGroup();
|
void clearButtonGroup();
|
||||||
|
QString initiateSelfTest(const QString &testType, const QString &deviceNode);
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -354,7 +354,7 @@
|
|||||||
</widget>
|
</widget>
|
||||||
<widget class="QMenu" name="menuDisk">
|
<widget class="QMenu" name="menuDisk">
|
||||||
<property name="title">
|
<property name="title">
|
||||||
<string>Disk</string>
|
<string>De&vice</string>
|
||||||
</property>
|
</property>
|
||||||
<addaction name="actionRescan_Refresh"/>
|
<addaction name="actionRescan_Refresh"/>
|
||||||
<addaction name="separator"/>
|
<addaction name="separator"/>
|
||||||
|
|||||||
Reference in New Issue
Block a user