From e39a03e098c704a7144d44bb75a1ba1d55038a0c Mon Sep 17 00:00:00 2001 From: Dean Lee Date: Sat, 12 Jun 2021 08:20:29 +0800 Subject: [PATCH] qt/util.h: new functions getBrand&getBrandVersion (#21238) old-commit-hash: 5baad4692da08c1b3063fc50bf337b1b58f96406 --- selfdrive/ui/qt/home.cc | 4 ++-- selfdrive/ui/qt/offroad/settings.cc | 9 +++------ selfdrive/ui/qt/util.h | 11 +++++++++++ 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/selfdrive/ui/qt/home.cc b/selfdrive/ui/qt/home.cc index 0a737f5576..5db715966d 100644 --- a/selfdrive/ui/qt/home.cc +++ b/selfdrive/ui/qt/home.cc @@ -9,6 +9,7 @@ #include "selfdrive/common/swaglog.h" #include "selfdrive/common/timing.h" #include "selfdrive/common/util.h" +#include "selfdrive/ui/qt/util.h" #include "selfdrive/ui/qt/widgets/drive_stats.h" #include "selfdrive/ui/qt/widgets/setup.h" @@ -102,8 +103,7 @@ OffroadHome::OffroadHome(QWidget* parent) : QFrame(parent) { QObject::connect(alert_notification, &QPushButton::released, this, &OffroadHome::openAlerts); header_layout->addWidget(alert_notification, 0, Qt::AlignHCenter | Qt::AlignRight); - std::string brand = Params().getBool("Passive") ? "dashcam" : "openpilot"; - QLabel* version = new QLabel(QString::fromStdString(brand + " v" + Params().get("Version"))); + QLabel* version = new QLabel(getBrandVersion()); version->setStyleSheet(R"(font-size: 55px;)"); header_layout->addWidget(version, 0, Qt::AlignHCenter | Qt::AlignRight); diff --git a/selfdrive/ui/qt/offroad/settings.cc b/selfdrive/ui/qt/offroad/settings.cc index 51a76c2257..e40e4abb9c 100644 --- a/selfdrive/ui/qt/offroad/settings.cc +++ b/selfdrive/ui/qt/offroad/settings.cc @@ -157,8 +157,7 @@ DevicePanel::DevicePanel(QWidget* parent) : QWidget(parent) { } }, "", this)); - QString brand = params.getBool("Passive") ? "dashcam" : "openpilot"; - offroad_btns.append(new ButtonControl("Uninstall " + brand, "UNINSTALL", "", [=]() { + offroad_btns.append(new ButtonControl("Uninstall " + getBrand(), "UNINSTALL", "", [=]() { if (ConfirmationDialog::confirm("Are you sure you want to uninstall?", this)) { Params().putBool("DoUninstall", true); } @@ -228,7 +227,6 @@ void SoftwarePanel::showEvent(QShowEvent *event) { void SoftwarePanel::updateLabels() { Params params = Params(); - std::string brand = params.getBool("Passive") ? "dashcam" : "openpilot"; QList> dev_params = { {"Git Branch", params.get("GitBranch")}, {"Git Commit", params.get("GitCommit").substr(0, 10)}, @@ -236,7 +234,6 @@ void SoftwarePanel::updateLabels() { {"OS Version", Hardware::get_os_version()}, }; - QString version = QString::fromStdString(brand + " v" + params.get("Version").substr(0, 14)).trimmed(); QString lastUpdateTime = ""; std::string last_update_param = params.get("LastUpdateTime"); @@ -246,7 +243,7 @@ void SoftwarePanel::updateLabels() { } if (labels.size() < dev_params.size()) { - versionLbl = new LabelControl("Version", version, QString::fromStdString(params.get("ReleaseNotes")).trimmed()); + versionLbl = new LabelControl("Version", getBrandVersion(), QString::fromStdString(params.get("ReleaseNotes")).trimmed()); layout()->addWidget(versionLbl); layout()->addWidget(horizontal_line()); @@ -267,7 +264,7 @@ void SoftwarePanel::updateLabels() { layout()->addWidget(updateButton); layout()->addWidget(horizontal_line()); } else { - versionLbl->setText(version); + versionLbl->setText(getBrandVersion()); lastUpdateTimeLbl->setText(lastUpdateTime); updateButton->setText("CHECK"); updateButton->setEnabled(true); diff --git a/selfdrive/ui/qt/util.h b/selfdrive/ui/qt/util.h index 53bf6683d2..81c06d8a5c 100644 --- a/selfdrive/ui/qt/util.h +++ b/selfdrive/ui/qt/util.h @@ -2,6 +2,17 @@ #include +#include "selfdrive/common/params.h" + + +inline QString getBrand() { + return Params().getBool("Passive") ? "dashcam" : "openpilot"; +} + +inline QString getBrandVersion() { + return getBrand() + " v" + QString::fromStdString(Params().get("Version")).left(14).trimmed(); +} + inline void configFont(QPainter &p, const QString &family, int size, const QString &style) { QFont f(family); f.setPixelSize(size);