From 158eaf4ddadac36b6c2a35956b68bfc0fcebd147 Mon Sep 17 00:00:00 2001 From: Jason Wen Date: Thu, 30 Jan 2025 22:20:58 -0500 Subject: [PATCH] introduce `getPlatformBundle` --- .../settings/vehicle/platform_selector.cc | 28 +++++++++---------- .../settings/vehicle/platform_selector.h | 1 + 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/selfdrive/ui/sunnypilot/qt/offroad/settings/vehicle/platform_selector.cc b/selfdrive/ui/sunnypilot/qt/offroad/settings/vehicle/platform_selector.cc index 8076261318..c3e65941be 100644 --- a/selfdrive/ui/sunnypilot/qt/offroad/settings/vehicle/platform_selector.cc +++ b/selfdrive/ui/sunnypilot/qt/offroad/settings/vehicle/platform_selector.cc @@ -13,6 +13,17 @@ #include #include +QVariant PlatformSelector::getPlatformBundle(const QString &key) { + QString platform_bundle = QString::fromStdString(params.get("CarPlatformBundle")); + if (!platform_bundle.isEmpty()) { + QJsonDocument json = QJsonDocument::fromJson(platform_bundle.toUtf8()); + if (!json.isNull() && json.isObject()) { + return json.object().value(key).toVariant(); + } + } + return {}; +} + PlatformSelector::PlatformSelector() : ButtonControl(tr("Vehicle"), "", "") { QObject::connect(this, &ButtonControl::clicked, [=]() { if (text() == tr("SEARCH")) { @@ -33,20 +44,9 @@ PlatformSelector::PlatformSelector() : ButtonControl(tr("Vehicle"), "", "") { } void PlatformSelector::refresh(bool _offroad) { - QString platform_bundle = QString::fromStdString(params.get("CarPlatformBundle")); - if (!platform_bundle.isEmpty()) { - QJsonDocument json = QJsonDocument::fromJson(platform_bundle.toUtf8()); - - if (!json.isNull() && json.isObject()) { - setValue(json.object()["name"].toString()); - } else { - setValue(""); - } - setText("REMOVE"); - } else { - setValue(""); - setText("SEARCH"); - } + QString name = getPlatformBundle("name").toString(); + setValue(name); + setText(name.isEmpty() ? tr("SEARCH") : tr("SELECT")); setEnabled(true); offroad = _offroad; diff --git a/selfdrive/ui/sunnypilot/qt/offroad/settings/vehicle/platform_selector.h b/selfdrive/ui/sunnypilot/qt/offroad/settings/vehicle/platform_selector.h index 69d88f910e..6a53a5b95a 100644 --- a/selfdrive/ui/sunnypilot/qt/offroad/settings/vehicle/platform_selector.h +++ b/selfdrive/ui/sunnypilot/qt/offroad/settings/vehicle/platform_selector.h @@ -14,6 +14,7 @@ class PlatformSelector : public ButtonControl { public: PlatformSelector(); + QVariant getPlatformBundle(const QString &key); public slots: void refresh(bool _offroad);