Ask for password once

This commit is contained in:
Spiros
2024-06-05 11:02:22 +03:00
parent f988c67182
commit ef4d104087

View File

@@ -93,17 +93,47 @@ void MainWindow::scanDevices()
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();
QStringList commandList;
for (const QJsonValue &value : devices) {
QJsonObject device = value.toObject();
QString deviceName = device["name"].toString();
commandList.append(QString("smartctl --all --json %1").arg(deviceName));
}
QString command = commandList.join(" ; ");
QString allDevicesOutput = getSmartctlOutput({"sh", "-c", command}, true);
QStringList deviceOutputs;
int startIndex = 0;
int endIndex = 0;
while ((endIndex = allDevicesOutput.indexOf(QRegExp("\\}\\n\\{"), startIndex)) != -1) {
++endIndex;
QString jsonFragment = allDevicesOutput.mid(startIndex, endIndex - startIndex);
deviceOutputs.append(jsonFragment);
startIndex = endIndex;
}
if (startIndex < allDevicesOutput.size()) {
QString jsonFragment = allDevicesOutput.mid(startIndex);
deviceOutputs.append(jsonFragment);
}
QJsonObject globalObj; QJsonObject globalObj;
QString globalHealth; QString globalHealth;
QVector<QPair<QString, int>> globalNvmeSmartOrdered; QVector<QPair<QString, int>> globalNvmeSmartOrdered;
bool firstTime = true; bool firstTime = true;
bool globalIsNvme = false; bool globalIsNvme = false;
for (const QJsonValue &value : devices) { for (int i = 0; i < devices.size(); ++i) {
QJsonObject device = value.toObject(); QJsonObject device = devices[i].toObject();
QString deviceName = device["name"].toString(); QString deviceName = device["name"].toString();
QString allOutput = getSmartctlOutput({"smartctl", "--all", "--json", deviceName}, true); QString allOutput;
if (i >= 0 && i < deviceOutputs.size()) {
allOutput = deviceOutputs[i];
}
QJsonDocument localDoc = QJsonDocument::fromJson(allOutput.toUtf8()); QJsonDocument localDoc = QJsonDocument::fromJson(allOutput.toUtf8());
QJsonObject localObj = localDoc.object(); QJsonObject localObj = localDoc.object();
@@ -118,11 +148,8 @@ void MainWindow::scanDevices()
QString health; QString health;
QColor healthColor; QColor healthColor;
bool isNvme = false;
QString protocol = localObj["device"].toObject()["protocol"].toString(); QString protocol = localObj["device"].toObject()["protocol"].toString();
if (protocol == "NVMe") { bool isNvme = (protocol == "NVMe");
isNvme = true;
}
int temperatureInt = localObj["temperature"].toObject()["current"].toInt(); int temperatureInt = localObj["temperature"].toObject()["current"].toInt();
if (temperatureInt > 0) { if (temperatureInt > 0) {
@@ -239,10 +266,7 @@ 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();
bool isNvme = false; bool isNvme = (protocol == "NVMe");
if (protocol == "NVMe") {
isNvme = true;
}
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>");
firmwareLineEdit->setText(firmwareVersion); firmwareLineEdit->setText(firmwareVersion);