mirror of
https://github.com/edisionnano/QDiskInfo.git
synced 2026-04-06 02:31:26 +03:00
Update values live
Am I overengineering again?
This commit is contained in:
@@ -4,6 +4,7 @@ MainWindow::MainWindow(QWidget *parent)
|
|||||||
: QMainWindow(parent)
|
: QMainWindow(parent)
|
||||||
, ui(new Ui::MainWindow)
|
, ui(new Ui::MainWindow)
|
||||||
, settings("KDiskInfo", "KDiskInfo")
|
, settings("KDiskInfo", "KDiskInfo")
|
||||||
|
, initializing(true)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
@@ -61,8 +62,8 @@ MainWindow::MainWindow(QWidget *parent)
|
|||||||
});
|
});
|
||||||
|
|
||||||
scanDevices();
|
scanDevices();
|
||||||
|
|
||||||
this->setFocus();
|
this->setFocus();
|
||||||
|
initializing = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow::~MainWindow()
|
MainWindow::~MainWindow()
|
||||||
@@ -97,10 +98,10 @@ void MainWindow::scanDevices()
|
|||||||
QString output = getSmartctlOutput({"--scan", "--json"}, false);
|
QString output = getSmartctlOutput({"--scan", "--json"}, false);
|
||||||
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();
|
devices = jsonObj["devices"].toArray();
|
||||||
QStringList commandList;
|
QStringList commandList;
|
||||||
|
|
||||||
for (const QJsonValue &value : devices) {
|
for (const QJsonValue &value : qAsConst(devices)) {
|
||||||
QJsonObject device = value.toObject();
|
QJsonObject device = value.toObject();
|
||||||
QString deviceName = device["name"].toString();
|
QString deviceName = device["name"].toString();
|
||||||
commandList.append(QString("smartctl --all --json %1").arg(deviceName));
|
commandList.append(QString("smartctl --all --json %1").arg(deviceName));
|
||||||
@@ -109,7 +110,6 @@ void MainWindow::scanDevices()
|
|||||||
|
|
||||||
QString allDevicesOutput = getSmartctlOutput({"sh", "-c", command}, true);
|
QString allDevicesOutput = getSmartctlOutput({"sh", "-c", command}, true);
|
||||||
|
|
||||||
QStringList deviceOutputs;
|
|
||||||
int startIndex = 0;
|
int startIndex = 0;
|
||||||
int endIndex = 0;
|
int endIndex = 0;
|
||||||
|
|
||||||
@@ -127,11 +127,13 @@ void MainWindow::scanDevices()
|
|||||||
deviceOutputs.append(jsonFragment);
|
deviceOutputs.append(jsonFragment);
|
||||||
}
|
}
|
||||||
|
|
||||||
QJsonObject globalObj;
|
updateUI();
|
||||||
QString globalHealth;
|
}
|
||||||
QVector<QPair<QString, int>> globalNvmeSmartOrdered;
|
|
||||||
|
void MainWindow::updateUI()
|
||||||
|
{
|
||||||
bool firstTime = true;
|
bool firstTime = true;
|
||||||
bool globalIsNvme = false;
|
globalIsNvme = false;
|
||||||
|
|
||||||
for (int i = 0; i < devices.size(); ++i) {
|
for (int i = 0; i < devices.size(); ++i) {
|
||||||
QJsonObject device = devices[i].toObject();
|
QJsonObject device = devices[i].toObject();
|
||||||
@@ -741,6 +743,17 @@ QString MainWindow::toTitleCase(const QString& sentence) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::clearButtonGroup()
|
||||||
|
{
|
||||||
|
QList<QAbstractButton*> buttons = buttonGroup->buttons();
|
||||||
|
for (QAbstractButton* button : buttons) {
|
||||||
|
buttonGroup->removeButton(button);
|
||||||
|
delete button;
|
||||||
|
}
|
||||||
|
horizontalLayout->removeItem(buttonStretch);
|
||||||
|
delete buttonStretch;
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::on_actionExit_triggered()
|
void MainWindow::on_actionExit_triggered()
|
||||||
{
|
{
|
||||||
qApp->quit();
|
qApp->quit();
|
||||||
@@ -784,13 +797,7 @@ void MainWindow::on_actionGitHub_triggered()
|
|||||||
|
|
||||||
void MainWindow::on_actionRescan_Refresh_triggered()
|
void MainWindow::on_actionRescan_Refresh_triggered()
|
||||||
{
|
{
|
||||||
QList<QAbstractButton*> buttons = buttonGroup->buttons();
|
clearButtonGroup();
|
||||||
for (QAbstractButton* button : buttons) {
|
|
||||||
buttonGroup->removeButton(button);
|
|
||||||
delete button;
|
|
||||||
}
|
|
||||||
horizontalLayout->removeItem(buttonStretch);
|
|
||||||
delete buttonStretch;
|
|
||||||
scanDevices();
|
scanDevices();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -813,11 +820,19 @@ 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("actionHEX", ui->actionHEX->isChecked());
|
settings.setValue("actionHEX", ui->actionHEX->isChecked());
|
||||||
|
if (!initializing) {
|
||||||
|
clearButtonGroup();
|
||||||
|
updateUI();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void MainWindow::on_actionUse_Fahrenheit_toggled(bool enabled)
|
void MainWindow::on_actionUse_Fahrenheit_toggled(bool enabled)
|
||||||
{
|
{
|
||||||
settings.setValue("actionUse_Fahrenheit", ui->actionUse_Fahrenheit->isChecked());
|
settings.setValue("actionUse_Fahrenheit", ui->actionUse_Fahrenheit->isChecked());
|
||||||
|
if (!initializing) {
|
||||||
|
clearButtonGroup();
|
||||||
|
updateUI();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
10
mainwindow.h
10
mainwindow.h
@@ -31,6 +31,7 @@ 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);
|
||||||
@@ -67,14 +68,23 @@ private:
|
|||||||
QSpacerItem *buttonStretch;
|
QSpacerItem *buttonStretch;
|
||||||
QSettings settings;
|
QSettings settings;
|
||||||
|
|
||||||
|
QJsonArray devices;
|
||||||
|
QStringList deviceOutputs;
|
||||||
|
QJsonObject globalObj;
|
||||||
|
QString globalHealth;
|
||||||
|
bool globalIsNvme;
|
||||||
|
QVector<QPair<QString, int>> globalNvmeSmartOrdered;
|
||||||
|
|
||||||
void onNextButtonClicked();
|
void onNextButtonClicked();
|
||||||
void onPrevButtonClicked();
|
void onPrevButtonClicked();
|
||||||
void updateNavigationButtons(int currentIndex);
|
void updateNavigationButtons(int currentIndex);
|
||||||
void scanDevices();
|
void scanDevices();
|
||||||
|
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);
|
||||||
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();
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user