mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-06-28 18:12:05 +08:00
UI: refactor SoftwarePanel (#21244)
* refactor cleanup * one params Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> old-commit-hash: 7009ba0344834f18adc93b34960fa97d1ebf2efc
This commit is contained in:
@@ -201,16 +201,40 @@ DevicePanel::DevicePanel(QWidget* parent) : QWidget(parent) {
|
||||
}
|
||||
|
||||
SoftwarePanel::SoftwarePanel(QWidget* parent) : QWidget(parent) {
|
||||
setLayout(new QVBoxLayout());
|
||||
gitBranchLbl = new LabelControl("Git Branch");
|
||||
gitCommitLbl = new LabelControl("Git Commit");
|
||||
osVersionLbl = new LabelControl("OS Version");
|
||||
versionLbl = new LabelControl("Version", "", QString::fromStdString(params.get("ReleaseNotes")).trimmed());
|
||||
lastUpdateLbl = new LabelControl("Last Update Check", "", "The last time openpilot successfully checked for an update. The updater only runs while the car is off.");
|
||||
updateBtn = new ButtonControl("Check for Update", "", "", [=]() {
|
||||
if (params.getBool("IsOffroad")) {
|
||||
const QString paramsPath = QString::fromStdString(params.getParamsPath());
|
||||
fs_watch->addPath(paramsPath + "/d/LastUpdateTime");
|
||||
fs_watch->addPath(paramsPath + "/d/UpdateFailedCount");
|
||||
updateBtn->setText("CHECKING");
|
||||
updateBtn->setEnabled(false);
|
||||
}
|
||||
std::system("pkill -1 -f selfdrive.updated");
|
||||
}, "", this);
|
||||
|
||||
QVBoxLayout *main_layout = new QVBoxLayout(this);
|
||||
QWidget *widgets[] = {versionLbl, lastUpdateLbl, updateBtn, gitBranchLbl, gitCommitLbl, osVersionLbl};
|
||||
for (int i = 0; i < std::size(widgets); ++i) {
|
||||
main_layout->addWidget(widgets[i]);
|
||||
if (i < std::size(widgets) - 1) {
|
||||
main_layout->addWidget(horizontal_line());
|
||||
}
|
||||
}
|
||||
|
||||
setStyleSheet(R"(QLabel {font-size: 50px;})");
|
||||
|
||||
fs_watch = new QFileSystemWatcher(this);
|
||||
QObject::connect(fs_watch, &QFileSystemWatcher::fileChanged, [=](const QString path) {
|
||||
int update_failed_count = Params().get<int>("UpdateFailedCount").value_or(0);
|
||||
int update_failed_count = params.get<int>("UpdateFailedCount").value_or(0);
|
||||
if (path.contains("UpdateFailedCount") && update_failed_count > 0) {
|
||||
lastUpdateTimeLbl->setText("failed to fetch update");
|
||||
updateButton->setText("CHECK");
|
||||
updateButton->setEnabled(true);
|
||||
lastUpdateLbl->setText("failed to fetch update");
|
||||
updateBtn->setText("CHECK");
|
||||
updateBtn->setEnabled(true);
|
||||
} else if (path.contains("LastUpdateTime")) {
|
||||
updateLabels();
|
||||
}
|
||||
@@ -222,62 +246,19 @@ void SoftwarePanel::showEvent(QShowEvent *event) {
|
||||
}
|
||||
|
||||
void SoftwarePanel::updateLabels() {
|
||||
Params params = Params();
|
||||
QList<QPair<QString, std::string>> dev_params = {
|
||||
{"Git Branch", params.get("GitBranch")},
|
||||
{"Git Commit", params.get("GitCommit").substr(0, 10)},
|
||||
{"OS Version", Hardware::get_os_version()},
|
||||
};
|
||||
|
||||
QString lastUpdateTime = "";
|
||||
|
||||
std::string last_update_param = params.get("LastUpdateTime");
|
||||
if (!last_update_param.empty()) {
|
||||
QDateTime lastUpdateDate = QDateTime::fromString(QString::fromStdString(last_update_param + "Z"), Qt::ISODate);
|
||||
lastUpdateTime = timeAgo(lastUpdateDate);
|
||||
QString lastUpdate = "";
|
||||
auto tm = params.get("LastUpdateTime");
|
||||
if (!tm.empty()) {
|
||||
lastUpdate = timeAgo(QDateTime::fromString(QString::fromStdString(tm + "Z"), Qt::ISODate));
|
||||
}
|
||||
|
||||
if (labels.size() < dev_params.size()) {
|
||||
versionLbl = new LabelControl("Version", getBrandVersion(), QString::fromStdString(params.get("ReleaseNotes")).trimmed());
|
||||
layout()->addWidget(versionLbl);
|
||||
layout()->addWidget(horizontal_line());
|
||||
|
||||
lastUpdateTimeLbl = new LabelControl("Last Update Check", lastUpdateTime, "The last time openpilot successfully checked for an update. The updater only runs while the car is off.");
|
||||
layout()->addWidget(lastUpdateTimeLbl);
|
||||
layout()->addWidget(horizontal_line());
|
||||
|
||||
updateButton = new ButtonControl("Check for Update", "CHECK", "", [=]() {
|
||||
Params params = Params();
|
||||
if (params.getBool("IsOffroad")) {
|
||||
fs_watch->addPath(QString::fromStdString(params.getParamsPath()) + "/d/LastUpdateTime");
|
||||
fs_watch->addPath(QString::fromStdString(params.getParamsPath()) + "/d/UpdateFailedCount");
|
||||
updateButton->setText("CHECKING");
|
||||
updateButton->setEnabled(false);
|
||||
}
|
||||
std::system("pkill -1 -f selfdrive.updated");
|
||||
}, "", this);
|
||||
layout()->addWidget(updateButton);
|
||||
layout()->addWidget(horizontal_line());
|
||||
} else {
|
||||
versionLbl->setText(getBrandVersion());
|
||||
lastUpdateTimeLbl->setText(lastUpdateTime);
|
||||
updateButton->setText("CHECK");
|
||||
updateButton->setEnabled(true);
|
||||
}
|
||||
|
||||
for (int i = 0; i < dev_params.size(); i++) {
|
||||
const auto &[name, value] = dev_params[i];
|
||||
QString val = QString::fromStdString(value).trimmed();
|
||||
if (labels.size() > i) {
|
||||
labels[i]->setText(val);
|
||||
} else {
|
||||
labels.push_back(new LabelControl(name, val));
|
||||
layout()->addWidget(labels[i]);
|
||||
if (i < (dev_params.size() - 1)) {
|
||||
layout()->addWidget(horizontal_line());
|
||||
}
|
||||
}
|
||||
}
|
||||
versionLbl->setText(getBrandVersion());
|
||||
lastUpdateLbl->setText(lastUpdate);
|
||||
updateBtn->setText("CHECK");
|
||||
updateBtn->setEnabled(true);
|
||||
gitBranchLbl->setText(QString::fromStdString(params.get("GitBranch")));
|
||||
gitCommitLbl->setText(QString::fromStdString(params.get("GitCommit")).left(10));
|
||||
osVersionLbl->setText(QString::fromStdString(Hardware::get_os_version()));
|
||||
}
|
||||
|
||||
QWidget * network_panel(QWidget * parent) {
|
||||
|
||||
@@ -35,16 +35,18 @@ class SoftwarePanel : public QWidget {
|
||||
public:
|
||||
explicit SoftwarePanel(QWidget* parent = nullptr);
|
||||
|
||||
protected:
|
||||
void showEvent(QShowEvent *event) override;
|
||||
|
||||
private:
|
||||
QList<LabelControl *> labels;
|
||||
LabelControl *versionLbl;
|
||||
LabelControl *lastUpdateTimeLbl;
|
||||
ButtonControl *updateButton;
|
||||
void showEvent(QShowEvent *event) override;
|
||||
void updateLabels();
|
||||
|
||||
LabelControl *gitBranchLbl;
|
||||
LabelControl *gitCommitLbl;
|
||||
LabelControl *osVersionLbl;
|
||||
LabelControl *versionLbl;
|
||||
LabelControl *lastUpdateLbl;
|
||||
ButtonControl *updateBtn;
|
||||
|
||||
Params params;
|
||||
QFileSystemWatcher *fs_watch;
|
||||
};
|
||||
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
#include "selfdrive/ui/qt/widgets/toggle.h"
|
||||
|
||||
QFrame *horizontal_line(QWidget *parent = nullptr);
|
||||
|
||||
class AbstractControl : public QFrame {
|
||||
Q_OBJECT
|
||||
|
||||
@@ -42,7 +41,7 @@ class LabelControl : public AbstractControl {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
LabelControl(const QString &title, const QString &text, const QString &desc = "", QWidget *parent = nullptr) : AbstractControl(title, desc, "", parent) {
|
||||
LabelControl(const QString &title, const QString &text = "", const QString &desc = "", QWidget *parent = nullptr) : AbstractControl(title, desc, "", parent) {
|
||||
label.setText(text);
|
||||
label.setAlignment(Qt::AlignRight | Qt::AlignVCenter);
|
||||
hlayout->addWidget(&label);
|
||||
|
||||
Reference in New Issue
Block a user