mirror of
https://github.com/edisionnano/QDiskInfo.git
synced 2026-04-19 18:23:19 +03:00
Add option to cancel test
This commit is contained in:
@@ -299,10 +299,11 @@ void MainWindow::selfTestHandler(const QString &mode, const QString &name, const
|
|||||||
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();
|
||||||
|
|
||||||
static const QRegularExpression regex("\\((\\d+%)\\s*(\\w+)\\)");
|
static const QRegularExpression regex("\\((\\d+%)\\s*(\\w+)\\)");
|
||||||
|
|
||||||
QString percentage;
|
QString percentage;
|
||||||
@@ -315,15 +316,28 @@ void MainWindow::selfTestHandler(const QString &mode, const QString &name, const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (exitStatus == 4) {
|
if (exitStatus == 4) {
|
||||||
QMessageBox::warning(this, tr("Test Already Running"), tr("A self-test is already being performed ") + percentage);
|
QMessageBox msgBox;
|
||||||
|
msgBox.setWindowTitle(tr("Test Already Running"));
|
||||||
|
msgBox.setText(tr("A self-test is already being performed ") + percentage + tr("\nYou can press the Cancel button in order to abort the test that is currently running"));
|
||||||
|
msgBox.setIcon(QMessageBox::Warning);
|
||||||
|
|
||||||
|
QPushButton *cancelButton = msgBox.addButton(QMessageBox::Cancel);
|
||||||
|
msgBox.addButton(QMessageBox::Ok);
|
||||||
|
|
||||||
|
msgBox.exec();
|
||||||
|
|
||||||
|
if (msgBox.clickedButton() == cancelButton) {
|
||||||
|
cancelSelfTest(name);
|
||||||
|
}
|
||||||
} else if (exitStatus == 0) {
|
} else if (exitStatus == 0) {
|
||||||
QString infoMessage = tr("A self-test has been requested successfully");
|
QString infoMessage = tr("A self-test has been requested successfully");
|
||||||
if (minutes != "0") {
|
if (minutes != "0") {
|
||||||
infoMessage = infoMessage + tr("\nIt will be completed after ") + minutes + tr(" minutes");
|
infoMessage = infoMessage + tr("\nIt will be completed after ") + minutes + tr(" minutes");
|
||||||
}
|
}
|
||||||
QMessageBox::information(this, tr("Test Requested"), infoMessage);
|
QMessageBox::information(this, tr("Test Requested"), infoMessage);
|
||||||
|
} else {
|
||||||
|
QMessageBox::critical(this, tr("KDiskInfo Error"), tr("Error: Something went wrong"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -952,3 +966,20 @@ QString MainWindow::initiateSelfTest(const QString &testType, const QString &dev
|
|||||||
return QString();
|
return QString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::cancelSelfTest(const QString &deviceNode)
|
||||||
|
{
|
||||||
|
QProcess process;
|
||||||
|
QString command = getSmartctlPath();
|
||||||
|
QStringList arguments;
|
||||||
|
arguments << command << "-X" << deviceNode;
|
||||||
|
|
||||||
|
process.start("pkexec", arguments);
|
||||||
|
process.waitForFinished(-1);
|
||||||
|
|
||||||
|
if (process.exitCode() == QProcess::NormalExit) {
|
||||||
|
QMessageBox::information(this, tr("Test Requested"), tr("The self-test has been aborted"));
|
||||||
|
} else {
|
||||||
|
QMessageBox::critical(this, tr("KDiskInfo Error"), tr("Error: Something went wrong"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -91,5 +91,6 @@ private:
|
|||||||
QString toTitleCase(const QString& sentence);
|
QString toTitleCase(const QString& sentence);
|
||||||
void clearButtonGroup();
|
void clearButtonGroup();
|
||||||
QString initiateSelfTest(const QString &testType, const QString &deviceNode);
|
QString initiateSelfTest(const QString &testType, const QString &deviceNode);
|
||||||
|
void cancelSelfTest(const QString &deviceNode);
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user