Skip to content

Commit bc9ab0a

Browse files
committed
less widgets more better
1 parent 6c4e434 commit bc9ab0a

File tree

8 files changed

+35
-100
lines changed

8 files changed

+35
-100
lines changed

selfdrive/ui/qt/setup/setup.cc

+21-78
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ bool is_elf(char *fname) {
3434
void Setup::download(QString url) {
3535
CURL *curl = curl_easy_init();
3636
if (!curl) {
37-
emit finished(DownloadResult::error, url);
37+
emit finished(url, tr("Something went wrong. Reboot the device."));
3838
return;
3939
}
4040

@@ -59,17 +59,17 @@ void Setup::download(QString url) {
5959
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &res_status);
6060

6161
if (ret != CURLE_OK || res_status != 200) {
62-
emit finished(DownloadResult::error, url);
62+
emit finished(url, tr("Ensure the entered URL is valid, and the device’s internet connection is good."));
6363
} else if (!is_elf(tmpfile)) {
64-
emit finished(DownloadResult::notExecutable, url);
64+
emit finished(url, tr("No custom software found at this URL."));
6565
} else {
6666
rename(tmpfile, "/tmp/installer");
6767

6868
FILE *fp_url = fopen("/tmp/installer_url", "w");
6969
fprintf(fp_url, "%s", url.toStdString().c_str());
7070
fclose(fp_url);
7171

72-
emit finished(DownloadResult::ok, url);
72+
emit finished(url);
7373
}
7474

7575
curl_slist_free_all(list);
@@ -242,10 +242,10 @@ QWidget * Setup::downloading() {
242242
return widget;
243243
}
244244

245-
QWidget * Setup::download_failed() {
245+
QWidget * Setup::download_failed(QLabel *url, QLabel *body) {
246246
QWidget *widget = new QWidget();
247247
QVBoxLayout *main_layout = new QVBoxLayout(widget);
248-
main_layout->setContentsMargins(55, 225, 55, 55);
248+
main_layout->setContentsMargins(55, 185, 55, 55);
249249
main_layout->setSpacing(0);
250250

251251
QLabel *title = new QLabel(tr("Download Failed"));
@@ -254,62 +254,13 @@ QWidget * Setup::download_failed() {
254254

255255
main_layout->addSpacing(67);
256256

257-
QLabel *body = new QLabel(tr("Ensure the entered URL is valid, and the device’s internet connection is good."));
258-
body->setWordWrap(true);
259-
body->setAlignment(Qt::AlignTop | Qt::AlignLeft);
260-
body->setStyleSheet("font-size: 80px; font-weight: 300; margin-right: 100px;");
261-
main_layout->addWidget(body);
262-
263-
main_layout->addStretch();
264-
265-
// reboot + start over buttons
266-
QHBoxLayout *blayout = new QHBoxLayout();
267-
blayout->setSpacing(50);
268-
main_layout->addLayout(blayout, 0);
269-
270-
QPushButton *reboot = new QPushButton(tr("Reboot device"));
271-
reboot->setObjectName("navBtn");
272-
blayout->addWidget(reboot);
273-
QObject::connect(reboot, &QPushButton::clicked, this, [=]() {
274-
Hardware::reboot();
275-
});
276-
277-
QPushButton *restart = new QPushButton(tr("Start over"));
278-
restart->setObjectName("navBtn");
279-
restart->setProperty("primary", true);
280-
blayout->addWidget(restart);
281-
QObject::connect(restart, &QPushButton::clicked, this, [=]() {
282-
setCurrentIndex(1);
283-
});
284-
285-
widget->setStyleSheet(R"(
286-
QLabel {
287-
margin-left: 117;
288-
}
289-
)");
290-
return widget;
291-
}
292-
293-
QWidget * Setup::download_invalid_url(QLabel *url) {
294-
QWidget *widget = new QWidget();
295-
QVBoxLayout *main_layout = new QVBoxLayout(widget);
296-
main_layout->setContentsMargins(55, 225, 55, 55);
297-
main_layout->setSpacing(0);
298-
299-
QLabel *title = new QLabel(tr("Invalid Custom Software URL"));
300-
title->setStyleSheet("font-size: 90px; font-weight: 500;");
301-
main_layout->addWidget(title, 0, Qt::AlignTop | Qt::AlignLeft);
302-
303-
main_layout->addSpacing(67);
304-
305257
url->setWordWrap(true);
306258
url->setAlignment(Qt::AlignTop | Qt::AlignLeft);
307-
url->setStyleSheet("font-family: \"JetBrains Mono\"; font-size: 64px; font-weight: 400; margin-right: 100px;");
259+
url->setStyleSheet("font-family: \"JetBrains Mono\"; font-size: 56px; font-weight: 400; margin-right: 100px;");
308260
main_layout->addWidget(url);
309261

310-
main_layout->addSpacing(60);
262+
main_layout->addSpacing(48);
311263

312-
QLabel *body = new QLabel(tr("No custom software found at this URL."));
313264
body->setWordWrap(true);
314265
body->setAlignment(Qt::AlignTop | Qt::AlignLeft);
315266
body->setStyleSheet("font-size: 80px; font-weight: 300; margin-right: 100px;");
@@ -339,7 +290,7 @@ QWidget * Setup::download_invalid_url(QLabel *url) {
339290

340291
widget->setStyleSheet(R"(
341292
QLabel {
342-
margin-left: 117px;
293+
margin-left: 117;
343294
}
344295
)");
345296
return widget;
@@ -367,28 +318,20 @@ Setup::Setup(QWidget *parent) : QStackedWidget(parent) {
367318
downloading_widget = downloading();
368319
addWidget(downloading_widget);
369320

370-
failed_widget = download_failed();
321+
QLabel *url_label = new QLabel();
322+
QLabel *body_label = new QLabel();
323+
failed_widget = download_failed(url_label, body_label);
371324
addWidget(failed_widget);
372325

373-
QLabel *url_label = new QLabel();
374-
invalid_url_widget = download_invalid_url(url_label);
375-
addWidget(invalid_url_widget);
376-
377-
QObject::connect(this, &Setup::finished, [=](const DownloadResult &result, const QString &url) {
378-
qDebug() << "finished" << result << url;
379-
switch (result) {
380-
case DownloadResult::ok:
381-
// hide setup on success
382-
QTimer::singleShot(3000, this, &QWidget::hide);
383-
break;
384-
case DownloadResult::notExecutable:
385-
url_label->setText(url);
386-
setCurrentWidget(invalid_url_widget);
387-
break;
388-
case DownloadResult::error:
389-
default:
390-
setCurrentWidget(failed_widget);
391-
break;
326+
QObject::connect(this, &Setup::finished, [=](const QString &url, const QString &error) {
327+
qDebug() << "finished" << url << error;
328+
if (error.isEmpty()) {
329+
// hide setup on success
330+
QTimer::singleShot(3000, this, &QWidget::hide);
331+
} else {
332+
url_label->setText(url);
333+
body_label->setText(error);
334+
setCurrentWidget(failed_widget);
392335
}
393336
});
394337

selfdrive/ui/qt/setup/setup.h

+2-10
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,6 @@
55
#include <QString>
66
#include <QWidget>
77

8-
enum DownloadResult {
9-
ok,
10-
notExecutable,
11-
error,
12-
};
13-
148
class Setup : public QStackedWidget {
159
Q_OBJECT
1610

@@ -22,15 +16,13 @@ class Setup : public QStackedWidget {
2216
QWidget *getting_started();
2317
QWidget *network_setup();
2418
QWidget *downloading();
25-
QWidget *download_failed();
26-
QWidget *download_invalid_url(QLabel *url);
19+
QWidget *download_failed(QLabel *url, QLabel *body);
2720

2821
QWidget *failed_widget;
29-
QWidget *invalid_url_widget;
3022
QWidget *downloading_widget;
3123

3224
signals:
33-
void finished(const DownloadResult &result, const QString &url);
25+
void finished(const QString &url, const QString &error = "");
3426

3527
public slots:
3628
void nextPage();

selfdrive/ui/translations/main_de.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -704,11 +704,11 @@ This may take up to a minute.</source>
704704
<translation>Von neuem beginnen</translation>
705705
</message>
706706
<message>
707-
<source>Invalid Custom Software URL</source>
707+
<source>No custom software found at this URL.</source>
708708
<translation type="unfinished"></translation>
709709
</message>
710710
<message>
711-
<source>No custom software found at this URL.</source>
711+
<source>Something went wrong. Reboot the device.</source>
712712
<translation type="unfinished"></translation>
713713
</message>
714714
</context>

selfdrive/ui/translations/main_ja.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -702,11 +702,11 @@ This may take up to a minute.</source>
702702
<translation>最初からやり直す</translation>
703703
</message>
704704
<message>
705-
<source>Invalid Custom Software URL</source>
705+
<source>No custom software found at this URL.</source>
706706
<translation type="unfinished"></translation>
707707
</message>
708708
<message>
709-
<source>No custom software found at this URL.</source>
709+
<source>Something went wrong. Reboot the device.</source>
710710
<translation type="unfinished"></translation>
711711
</message>
712712
</context>

selfdrive/ui/translations/main_ko.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -702,11 +702,11 @@ This may take up to a minute.</source>
702702
<translation>다시 시작</translation>
703703
</message>
704704
<message>
705-
<source>Invalid Custom Software URL</source>
705+
<source>No custom software found at this URL.</source>
706706
<translation type="unfinished"></translation>
707707
</message>
708708
<message>
709-
<source>No custom software found at this URL.</source>
709+
<source>Something went wrong. Reboot the device.</source>
710710
<translation type="unfinished"></translation>
711711
</message>
712712
</context>

selfdrive/ui/translations/main_pt-BR.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -706,11 +706,11 @@ This may take up to a minute.</source>
706706
<translation>Inicializar</translation>
707707
</message>
708708
<message>
709-
<source>Invalid Custom Software URL</source>
709+
<source>No custom software found at this URL.</source>
710710
<translation type="unfinished"></translation>
711711
</message>
712712
<message>
713-
<source>No custom software found at this URL.</source>
713+
<source>Something went wrong. Reboot the device.</source>
714714
<translation type="unfinished"></translation>
715715
</message>
716716
</context>

selfdrive/ui/translations/main_zh-CHS.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -700,11 +700,11 @@ This may take up to a minute.</source>
700700
<translation>重来</translation>
701701
</message>
702702
<message>
703-
<source>Invalid Custom Software URL</source>
703+
<source>No custom software found at this URL.</source>
704704
<translation type="unfinished"></translation>
705705
</message>
706706
<message>
707-
<source>No custom software found at this URL.</source>
707+
<source>Something went wrong. Reboot the device.</source>
708708
<translation type="unfinished"></translation>
709709
</message>
710710
</context>

selfdrive/ui/translations/main_zh-CHT.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -702,11 +702,11 @@ This may take up to a minute.</source>
702702
<translation>重新開始</translation>
703703
</message>
704704
<message>
705-
<source>Invalid Custom Software URL</source>
705+
<source>No custom software found at this URL.</source>
706706
<translation type="unfinished"></translation>
707707
</message>
708708
<message>
709-
<source>No custom software found at this URL.</source>
709+
<source>Something went wrong. Reboot the device.</source>
710710
<translation type="unfinished"></translation>
711711
</message>
712712
</context>

0 commit comments

Comments
 (0)