Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setup: detailed error messages #27429

Merged
merged 13 commits into from
Feb 24, 2023
41 changes: 27 additions & 14 deletions selfdrive/ui/qt/setup/setup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ bool is_elf(char *fname) {
void Setup::download(QString url) {
CURL *curl = curl_easy_init();
if (!curl) {
emit finished(false);
emit finished(url, tr("Something went wrong. Reboot the device."));
return;
}

Expand All @@ -57,16 +57,19 @@ void Setup::download(QString url) {
int ret = curl_easy_perform(curl);
long res_status = 0;
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &res_status);
if (ret == CURLE_OK && res_status == 200 && is_elf(tmpfile)) {

if (ret != CURLE_OK || res_status != 200) {
emit finished(url, tr("Ensure the entered URL is valid, and the device’s internet connection is good."));
} else if (!is_elf(tmpfile)) {
emit finished(url, tr("No custom software found at this URL."));
} else {
rename(tmpfile, "/tmp/installer");

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

emit finished(true);
} else {
emit finished(false);
emit finished(url);
}

curl_slist_free_all(list);
Expand Down Expand Up @@ -239,10 +242,10 @@ QWidget * Setup::downloading() {
return widget;
}

QWidget * Setup::download_failed() {
QWidget * Setup::download_failed(QLabel *url, QLabel *body) {
QWidget *widget = new QWidget();
QVBoxLayout *main_layout = new QVBoxLayout(widget);
main_layout->setContentsMargins(55, 225, 55, 55);
main_layout->setContentsMargins(55, 185, 55, 55);
main_layout->setSpacing(0);

QLabel *title = new QLabel(tr("Download Failed"));
Expand All @@ -251,7 +254,13 @@ QWidget * Setup::download_failed() {

main_layout->addSpacing(67);

QLabel *body = new QLabel(tr("Ensure the entered URL is valid, and the device’s internet connection is good."));
url->setWordWrap(true);
url->setAlignment(Qt::AlignTop | Qt::AlignLeft);
url->setStyleSheet("font-family: \"JetBrains Mono\"; font-size: 64px; font-weight: 400; margin-right: 100px;");
main_layout->addWidget(url);

main_layout->addSpacing(48);

body->setWordWrap(true);
body->setAlignment(Qt::AlignTop | Qt::AlignLeft);
body->setStyleSheet("font-size: 80px; font-weight: 300; margin-right: 100px;");
Expand All @@ -276,7 +285,7 @@ QWidget * Setup::download_failed() {
restart->setProperty("primary", true);
blayout->addWidget(restart);
QObject::connect(restart, &QPushButton::clicked, this, [=]() {
setCurrentIndex(2);
setCurrentIndex(1);
});

widget->setStyleSheet(R"(
Expand Down Expand Up @@ -309,15 +318,19 @@ Setup::Setup(QWidget *parent) : QStackedWidget(parent) {
downloading_widget = downloading();
addWidget(downloading_widget);

failed_widget = download_failed();
QLabel *url_label = new QLabel();
QLabel *body_label = new QLabel();
failed_widget = download_failed(url_label, body_label);
addWidget(failed_widget);

QObject::connect(this, &Setup::finished, [=](bool success) {
// hide setup on success
qDebug() << "finished" << success;
if (success) {
QObject::connect(this, &Setup::finished, [=](const QString &url, const QString &error) {
qDebug() << "finished" << url << error;
if (error.isEmpty()) {
// hide setup on success
QTimer::singleShot(3000, this, &QWidget::hide);
} else {
url_label->setText(url);
body_label->setText(error);
setCurrentWidget(failed_widget);
}
});
Expand Down
5 changes: 3 additions & 2 deletions selfdrive/ui/qt/setup/setup.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include <QLabel>
#include <QStackedWidget>
#include <QString>
#include <QWidget>
Expand All @@ -15,13 +16,13 @@ class Setup : public QStackedWidget {
QWidget *getting_started();
QWidget *network_setup();
QWidget *downloading();
QWidget *download_failed();
QWidget *download_failed(QLabel *url, QLabel *body);

QWidget *failed_widget;
QWidget *downloading_widget;

signals:
void finished(bool success);
void finished(const QString &url, const QString &error = "");

public slots:
void nextPage();
Expand Down
8 changes: 8 additions & 0 deletions selfdrive/ui/translations/main_de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,14 @@ This may take up to a minute.</source>
<source>Start over</source>
<translation>Von neuem beginnen</translation>
</message>
<message>
<source>No custom software found at this URL.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Something went wrong. Reboot the device.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>SetupWidget</name>
Expand Down
8 changes: 8 additions & 0 deletions selfdrive/ui/translations/main_ja.ts
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,14 @@ This may take up to a minute.</source>
<source>Start over</source>
<translation>最初からやり直す</translation>
</message>
<message>
<source>No custom software found at this URL.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Something went wrong. Reboot the device.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>SetupWidget</name>
Expand Down
8 changes: 8 additions & 0 deletions selfdrive/ui/translations/main_ko.ts
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,14 @@ This may take up to a minute.</source>
<source>Start over</source>
<translation>다시 시작</translation>
</message>
<message>
<source>No custom software found at this URL.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Something went wrong. Reboot the device.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>SetupWidget</name>
Expand Down
8 changes: 8 additions & 0 deletions selfdrive/ui/translations/main_pt-BR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,14 @@ This may take up to a minute.</source>
<source>Start over</source>
<translation>Inicializar</translation>
</message>
<message>
<source>No custom software found at this URL.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Something went wrong. Reboot the device.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>SetupWidget</name>
Expand Down
8 changes: 8 additions & 0 deletions selfdrive/ui/translations/main_zh-CHS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,14 @@ This may take up to a minute.</source>
<source>Start over</source>
<translation>重来</translation>
</message>
<message>
<source>No custom software found at this URL.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Something went wrong. Reboot the device.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>SetupWidget</name>
Expand Down
8 changes: 8 additions & 0 deletions selfdrive/ui/translations/main_zh-CHT.ts
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,14 @@ This may take up to a minute.</source>
<source>Start over</source>
<translation>重新開始</translation>
</message>
<message>
<source>No custom software found at this URL.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Something went wrong. Reboot the device.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>SetupWidget</name>
Expand Down