UI: Updated in settings (#21051)
* last update time + release notes * remove test * revert to previous constructor * change label name * time format for last update check * cleanup * add time formatting function * cleanup Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com>
This commit is contained in:
parent
1626017a4d
commit
e3f6360e45
|
@ -16,6 +16,7 @@
|
|||
#include "selfdrive/ui/qt/widgets/ssh_keys.h"
|
||||
#include "selfdrive/ui/qt/widgets/toggle.h"
|
||||
#include "selfdrive/ui/ui.h"
|
||||
#include "selfdrive/ui/qt/util.h"
|
||||
|
||||
TogglesPanel::TogglesPanel(QWidget *parent) : QWidget(parent) {
|
||||
QVBoxLayout *toggles_list = new QVBoxLayout();
|
||||
|
@ -214,13 +215,32 @@ void DeveloperPanel::showEvent(QShowEvent *event) {
|
|||
Params params = Params();
|
||||
std::string brand = params.getBool("Passive") ? "dashcam" : "openpilot";
|
||||
QList<QPair<QString, std::string>> dev_params = {
|
||||
{"Version", brand + " v" + params.get("Version", false).substr(0, 14)},
|
||||
{"Git Branch", params.get("GitBranch", false)},
|
||||
{"Git Commit", params.get("GitCommit", false).substr(0, 10)},
|
||||
{"Panda Firmware", params.get("PandaFirmwareHex", false)},
|
||||
{"OS Version", Hardware::get_os_version()},
|
||||
};
|
||||
|
||||
QString version = QString::fromStdString(brand + " v" + params.get("Version", false).substr(0, 14)).trimmed();
|
||||
QDateTime lastUpdateDate = QDateTime::fromString(QString::fromStdString(params.get("LastUpdateTime", false)), Qt::ISODate);
|
||||
QString lastUpdateTime = timeAgo(lastUpdateDate);
|
||||
|
||||
if (labels.size() < dev_params.size()) {
|
||||
versionLbl = new LabelControl("Version", version, QString::fromStdString(params.get("ReleaseNotes", false)).trimmed());
|
||||
layout()->addWidget(versionLbl);
|
||||
layout()->addWidget(horizontal_line());
|
||||
|
||||
lastUpdateTimeLbl = new LabelControl("Last Update Check", lastUpdateTime, "The last time openpilot checked for an update.");
|
||||
connect(lastUpdateTimeLbl, &LabelControl::showDescription, [=]() {
|
||||
std::system("pkill -1 -f selfdrive.updated");
|
||||
});
|
||||
layout()->addWidget(lastUpdateTimeLbl);
|
||||
layout()->addWidget(horizontal_line());
|
||||
} else {
|
||||
versionLbl->setText(version);
|
||||
lastUpdateTimeLbl->setText(lastUpdateTime);
|
||||
}
|
||||
|
||||
for (int i = 0; i < dev_params.size(); i++) {
|
||||
const auto &[name, value] = dev_params[i];
|
||||
QString val = QString::fromStdString(value).trimmed();
|
||||
|
|
|
@ -34,7 +34,11 @@ public:
|
|||
|
||||
protected:
|
||||
void showEvent(QShowEvent *event) override;
|
||||
|
||||
private:
|
||||
QList<LabelControl *> labels;
|
||||
LabelControl *versionLbl;
|
||||
LabelControl *lastUpdateTimeLbl;
|
||||
};
|
||||
|
||||
class SettingsWindow : public QFrame {
|
||||
|
|
|
@ -20,3 +20,25 @@ inline void clearLayout(QLayout* layout) {
|
|||
delete item;
|
||||
}
|
||||
}
|
||||
|
||||
inline QString timeAgo(const QDateTime &date) {
|
||||
int diff = date.secsTo(QDateTime::currentDateTime());
|
||||
|
||||
QString s;
|
||||
if (diff < 60) {
|
||||
s = "now";
|
||||
} else if (diff < 60 * 60) {
|
||||
int minutes = diff / 60;
|
||||
s = QString("%1 minute%2 ago").arg(minutes).arg(minutes > 1 ? "s" : "");
|
||||
} else if (diff < 60 * 60 * 24) {
|
||||
int hours = diff / (60 * 60);
|
||||
s = QString("%1 hour%2 ago").arg(hours).arg(hours > 1 ? "s" : "");
|
||||
} else if (diff < 3600 * 24 * 7) {
|
||||
int days = diff / (60 * 60 * 24);
|
||||
s = QString("%1 day%2 ago").arg(days).arg(days > 1 ? "s" : "");
|
||||
} else {
|
||||
s = date.date().toString();
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue