bye bye qt, part 1 (#35741)
parent
a8fd55740b
commit
e9d78958c1
5 changed files with 1 additions and 388 deletions
@ -1,141 +0,0 @@ |
|||||||
#include <QApplication> |
|
||||||
#include <QHBoxLayout> |
|
||||||
#include <QLabel> |
|
||||||
#include <QPushButton> |
|
||||||
#include <QTimer> |
|
||||||
#include <QVBoxLayout> |
|
||||||
|
|
||||||
#include "selfdrive/ui/qt/qt_window.h" |
|
||||||
#include "selfdrive/ui/qt/setup/reset.h" |
|
||||||
|
|
||||||
#define NVME "/dev/nvme0n1" |
|
||||||
#define USERDATA "/dev/disk/by-partlabel/userdata" |
|
||||||
|
|
||||||
void Reset::doErase() { |
|
||||||
// best effort to wipe nvme
|
|
||||||
std::system("sudo umount " NVME); |
|
||||||
std::system("yes | sudo mkfs.ext4 " NVME); |
|
||||||
|
|
||||||
int rm = std::system("sudo rm -rf /data/*"); |
|
||||||
std::system("sudo umount " USERDATA); |
|
||||||
int fmt = std::system("yes | sudo mkfs.ext4 " USERDATA); |
|
||||||
|
|
||||||
if (rm == 0 || fmt == 0) { |
|
||||||
std::system("sudo reboot"); |
|
||||||
} |
|
||||||
body->setText(tr("Reset failed. Reboot to try again.")); |
|
||||||
rebootBtn->show(); |
|
||||||
} |
|
||||||
|
|
||||||
void Reset::startReset() { |
|
||||||
body->setText(tr("Resetting device...\nThis may take up to a minute.")); |
|
||||||
rejectBtn->hide(); |
|
||||||
rebootBtn->hide(); |
|
||||||
confirmBtn->hide(); |
|
||||||
#ifdef __aarch64__ |
|
||||||
QTimer::singleShot(100, this, &Reset::doErase); |
|
||||||
#endif |
|
||||||
} |
|
||||||
|
|
||||||
void Reset::confirm() { |
|
||||||
const QString confirm_txt = tr("Are you sure you want to reset your device?"); |
|
||||||
if (body->text() != confirm_txt) { |
|
||||||
body->setText(confirm_txt); |
|
||||||
} else { |
|
||||||
startReset(); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
Reset::Reset(ResetMode mode, QWidget *parent) : QWidget(parent) { |
|
||||||
QVBoxLayout *main_layout = new QVBoxLayout(this); |
|
||||||
main_layout->setContentsMargins(45, 220, 45, 45); |
|
||||||
main_layout->setSpacing(0); |
|
||||||
|
|
||||||
QLabel *title = new QLabel(tr("System Reset")); |
|
||||||
title->setStyleSheet("font-size: 90px; font-weight: 600;"); |
|
||||||
main_layout->addWidget(title, 0, Qt::AlignTop | Qt::AlignLeft); |
|
||||||
|
|
||||||
main_layout->addSpacing(60); |
|
||||||
|
|
||||||
body = new QLabel(tr("System reset triggered. Press confirm to erase all content and settings. Press cancel to resume boot.")); |
|
||||||
body->setWordWrap(true); |
|
||||||
body->setStyleSheet("font-size: 80px; font-weight: light;"); |
|
||||||
main_layout->addWidget(body, 1, Qt::AlignTop | Qt::AlignLeft); |
|
||||||
|
|
||||||
QHBoxLayout *blayout = new QHBoxLayout(); |
|
||||||
main_layout->addLayout(blayout); |
|
||||||
blayout->setSpacing(50); |
|
||||||
|
|
||||||
rejectBtn = new QPushButton(tr("Cancel")); |
|
||||||
blayout->addWidget(rejectBtn); |
|
||||||
QObject::connect(rejectBtn, &QPushButton::clicked, QCoreApplication::instance(), &QCoreApplication::quit); |
|
||||||
|
|
||||||
rebootBtn = new QPushButton(tr("Reboot")); |
|
||||||
blayout->addWidget(rebootBtn); |
|
||||||
#ifdef __aarch64__ |
|
||||||
QObject::connect(rebootBtn, &QPushButton::clicked, [=]{ |
|
||||||
std::system("sudo reboot"); |
|
||||||
}); |
|
||||||
#endif |
|
||||||
|
|
||||||
confirmBtn = new QPushButton(tr("Confirm")); |
|
||||||
confirmBtn->setStyleSheet(R"( |
|
||||||
QPushButton { |
|
||||||
background-color: #465BEA; |
|
||||||
} |
|
||||||
QPushButton:pressed { |
|
||||||
background-color: #3049F4; |
|
||||||
} |
|
||||||
)"); |
|
||||||
blayout->addWidget(confirmBtn); |
|
||||||
QObject::connect(confirmBtn, &QPushButton::clicked, this, &Reset::confirm); |
|
||||||
|
|
||||||
bool recover = mode == ResetMode::RECOVER; |
|
||||||
rejectBtn->setVisible(!recover); |
|
||||||
rebootBtn->setVisible(recover); |
|
||||||
if (recover) { |
|
||||||
body->setText(tr("Unable to mount data partition. Partition may be corrupted. Press confirm to erase and reset your device.")); |
|
||||||
} |
|
||||||
|
|
||||||
// automatically start if we're just finishing up an ABL reset
|
|
||||||
if (mode == ResetMode::FORMAT) { |
|
||||||
startReset(); |
|
||||||
} |
|
||||||
|
|
||||||
setStyleSheet(R"( |
|
||||||
* { |
|
||||||
font-family: Inter; |
|
||||||
color: white; |
|
||||||
background-color: black; |
|
||||||
} |
|
||||||
QLabel { |
|
||||||
margin-left: 140; |
|
||||||
} |
|
||||||
QPushButton { |
|
||||||
height: 160; |
|
||||||
font-size: 55px; |
|
||||||
font-weight: 400; |
|
||||||
border-radius: 10px; |
|
||||||
background-color: #333333; |
|
||||||
} |
|
||||||
QPushButton:pressed { |
|
||||||
background-color: #444444; |
|
||||||
} |
|
||||||
)"); |
|
||||||
} |
|
||||||
|
|
||||||
int main(int argc, char *argv[]) { |
|
||||||
ResetMode mode = ResetMode::USER_RESET; |
|
||||||
if (argc > 1) { |
|
||||||
if (strcmp(argv[1], "--recover") == 0) { |
|
||||||
mode = ResetMode::RECOVER; |
|
||||||
} else if (strcmp(argv[1], "--format") == 0) { |
|
||||||
mode = ResetMode::FORMAT; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
QApplication a(argc, argv); |
|
||||||
Reset reset(mode); |
|
||||||
setMainWindow(&reset); |
|
||||||
return a.exec(); |
|
||||||
} |
|
@ -1,27 +0,0 @@ |
|||||||
#include <QLabel> |
|
||||||
#include <QPushButton> |
|
||||||
#include <QWidget> |
|
||||||
|
|
||||||
enum ResetMode { |
|
||||||
USER_RESET, // user initiated a factory reset from openpilot
|
|
||||||
RECOVER, // userdata is corrupt for some reason, give a chance to recover
|
|
||||||
FORMAT, // finish up a factory reset from a tool that doesn't flash an empty partition to userdata
|
|
||||||
}; |
|
||||||
|
|
||||||
class Reset : public QWidget { |
|
||||||
Q_OBJECT |
|
||||||
|
|
||||||
public: |
|
||||||
explicit Reset(ResetMode mode, QWidget *parent = 0); |
|
||||||
|
|
||||||
private: |
|
||||||
QLabel *body; |
|
||||||
QPushButton *rejectBtn; |
|
||||||
QPushButton *rebootBtn; |
|
||||||
QPushButton *confirmBtn; |
|
||||||
void doErase(); |
|
||||||
void startReset(); |
|
||||||
|
|
||||||
private slots: |
|
||||||
void confirm(); |
|
||||||
}; |
|
@ -1,186 +0,0 @@ |
|||||||
#include <QDebug> |
|
||||||
#include <QTimer> |
|
||||||
#include <QVBoxLayout> |
|
||||||
|
|
||||||
#include "system/hardware/hw.h" |
|
||||||
#include "selfdrive/ui/qt/util.h" |
|
||||||
#include "selfdrive/ui/qt/qt_window.h" |
|
||||||
#include "selfdrive/ui/qt/setup/updater.h" |
|
||||||
#include "selfdrive/ui/qt/network/networking.h" |
|
||||||
|
|
||||||
Updater::Updater(const QString &updater_path, const QString &manifest_path, QWidget *parent) |
|
||||||
: updater(updater_path), manifest(manifest_path), QStackedWidget(parent) { |
|
||||||
|
|
||||||
assert(updater.size()); |
|
||||||
assert(manifest.size()); |
|
||||||
|
|
||||||
// initial prompt screen
|
|
||||||
prompt = new QWidget; |
|
||||||
{ |
|
||||||
QVBoxLayout *layout = new QVBoxLayout(prompt); |
|
||||||
layout->setContentsMargins(100, 250, 100, 100); |
|
||||||
|
|
||||||
QLabel *title = new QLabel(tr("Update Required")); |
|
||||||
title->setStyleSheet("font-size: 80px; font-weight: bold;"); |
|
||||||
layout->addWidget(title); |
|
||||||
|
|
||||||
layout->addSpacing(75); |
|
||||||
|
|
||||||
QLabel *desc = new QLabel(tr("An operating system update is required. Connect your device to Wi-Fi for the fastest update experience. The download size is approximately 1GB.")); |
|
||||||
desc->setWordWrap(true); |
|
||||||
desc->setStyleSheet("font-size: 65px;"); |
|
||||||
layout->addWidget(desc); |
|
||||||
|
|
||||||
layout->addStretch(); |
|
||||||
|
|
||||||
QHBoxLayout *hlayout = new QHBoxLayout; |
|
||||||
hlayout->setSpacing(30); |
|
||||||
layout->addLayout(hlayout); |
|
||||||
|
|
||||||
QPushButton *connect = new QPushButton(tr("Connect to Wi-Fi")); |
|
||||||
connect->setObjectName("navBtn"); |
|
||||||
QObject::connect(connect, &QPushButton::clicked, [=]() { |
|
||||||
setCurrentWidget(wifi); |
|
||||||
}); |
|
||||||
hlayout->addWidget(connect); |
|
||||||
|
|
||||||
QPushButton *install = new QPushButton(tr("Install")); |
|
||||||
install->setObjectName("navBtn"); |
|
||||||
install->setStyleSheet(R"( |
|
||||||
QPushButton { |
|
||||||
background-color: #465BEA; |
|
||||||
} |
|
||||||
QPushButton:pressed { |
|
||||||
background-color: #3049F4; |
|
||||||
} |
|
||||||
)"); |
|
||||||
QObject::connect(install, &QPushButton::clicked, this, &Updater::installUpdate); |
|
||||||
hlayout->addWidget(install); |
|
||||||
} |
|
||||||
|
|
||||||
// wifi connection screen
|
|
||||||
wifi = new QWidget; |
|
||||||
{ |
|
||||||
QVBoxLayout *layout = new QVBoxLayout(wifi); |
|
||||||
layout->setContentsMargins(100, 100, 100, 100); |
|
||||||
|
|
||||||
Networking *networking = new Networking(this, false); |
|
||||||
networking->setStyleSheet("Networking { background-color: #292929; border-radius: 13px; }"); |
|
||||||
layout->addWidget(networking, 1); |
|
||||||
|
|
||||||
QPushButton *back = new QPushButton(tr("Back")); |
|
||||||
back->setObjectName("navBtn"); |
|
||||||
back->setStyleSheet("padding-left: 60px; padding-right: 60px;"); |
|
||||||
QObject::connect(back, &QPushButton::clicked, [=]() { |
|
||||||
setCurrentWidget(prompt); |
|
||||||
}); |
|
||||||
layout->addWidget(back, 0, Qt::AlignLeft); |
|
||||||
} |
|
||||||
|
|
||||||
// progress screen
|
|
||||||
progress = new QWidget; |
|
||||||
{ |
|
||||||
QVBoxLayout *layout = new QVBoxLayout(progress); |
|
||||||
layout->setContentsMargins(150, 330, 150, 150); |
|
||||||
layout->setSpacing(0); |
|
||||||
|
|
||||||
text = new QLabel(tr("Loading...")); |
|
||||||
text->setStyleSheet("font-size: 90px; font-weight: 600;"); |
|
||||||
layout->addWidget(text, 0, Qt::AlignTop); |
|
||||||
|
|
||||||
layout->addSpacing(100); |
|
||||||
|
|
||||||
bar = new QProgressBar(); |
|
||||||
bar->setRange(0, 100); |
|
||||||
bar->setTextVisible(false); |
|
||||||
bar->setFixedHeight(72); |
|
||||||
layout->addWidget(bar, 0, Qt::AlignTop); |
|
||||||
|
|
||||||
layout->addStretch(); |
|
||||||
|
|
||||||
reboot = new QPushButton(tr("Reboot")); |
|
||||||
reboot->setObjectName("navBtn"); |
|
||||||
reboot->setStyleSheet("padding-left: 60px; padding-right: 60px;"); |
|
||||||
QObject::connect(reboot, &QPushButton::clicked, [=]() { |
|
||||||
Hardware::reboot(); |
|
||||||
}); |
|
||||||
layout->addWidget(reboot, 0, Qt::AlignLeft); |
|
||||||
reboot->hide(); |
|
||||||
|
|
||||||
layout->addStretch(); |
|
||||||
} |
|
||||||
|
|
||||||
addWidget(prompt); |
|
||||||
addWidget(wifi); |
|
||||||
addWidget(progress); |
|
||||||
|
|
||||||
setStyleSheet(R"( |
|
||||||
* { |
|
||||||
color: white; |
|
||||||
outline: none; |
|
||||||
font-family: Inter; |
|
||||||
} |
|
||||||
Updater { |
|
||||||
color: white; |
|
||||||
background-color: black; |
|
||||||
} |
|
||||||
QPushButton#navBtn { |
|
||||||
height: 160; |
|
||||||
font-size: 55px; |
|
||||||
font-weight: 400; |
|
||||||
border-radius: 10px; |
|
||||||
background-color: #333333; |
|
||||||
} |
|
||||||
QPushButton#navBtn:pressed { |
|
||||||
background-color: #444444; |
|
||||||
} |
|
||||||
QProgressBar { |
|
||||||
border: none; |
|
||||||
background-color: #292929; |
|
||||||
} |
|
||||||
QProgressBar::chunk { |
|
||||||
background-color: #364DEF; |
|
||||||
} |
|
||||||
)"); |
|
||||||
} |
|
||||||
|
|
||||||
void Updater::installUpdate() { |
|
||||||
setCurrentWidget(progress); |
|
||||||
QObject::connect(&proc, &QProcess::readyReadStandardOutput, this, &Updater::readProgress); |
|
||||||
QObject::connect(&proc, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished), this, &Updater::updateFinished); |
|
||||||
proc.setProcessChannelMode(QProcess::ForwardedErrorChannel); |
|
||||||
proc.start(updater, {"--swap", manifest}); |
|
||||||
} |
|
||||||
|
|
||||||
void Updater::readProgress() { |
|
||||||
auto lines = QString(proc.readAllStandardOutput()); |
|
||||||
for (const QString &line : lines.trimmed().split("\n")) { |
|
||||||
auto parts = line.split(":"); |
|
||||||
if (parts.size() == 2) { |
|
||||||
text->setText(parts[0]); |
|
||||||
bar->setValue((int)parts[1].toDouble()); |
|
||||||
} else { |
|
||||||
qDebug() << line; |
|
||||||
} |
|
||||||
} |
|
||||||
update(); |
|
||||||
} |
|
||||||
|
|
||||||
void Updater::updateFinished(int exitCode, QProcess::ExitStatus exitStatus) { |
|
||||||
qDebug() << "finished with " << exitCode; |
|
||||||
if (exitCode == 0) { |
|
||||||
Hardware::reboot(); |
|
||||||
} else { |
|
||||||
text->setText(tr("Update failed")); |
|
||||||
reboot->show(); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
int main(int argc, char *argv[]) { |
|
||||||
initApp(argc, argv); |
|
||||||
QApplication a(argc, argv); |
|
||||||
Updater updater(argv[1], argv[2]); |
|
||||||
setMainWindow(&updater); |
|
||||||
a.installEventFilter(&updater); |
|
||||||
return a.exec(); |
|
||||||
} |
|
@ -1,29 +0,0 @@ |
|||||||
#pragma once |
|
||||||
|
|
||||||
#include <QLabel> |
|
||||||
#include <QProcess> |
|
||||||
#include <QPushButton> |
|
||||||
#include <QProgressBar> |
|
||||||
#include <QStackedWidget> |
|
||||||
#include <QWidget> |
|
||||||
|
|
||||||
class Updater : public QStackedWidget { |
|
||||||
Q_OBJECT |
|
||||||
|
|
||||||
public: |
|
||||||
explicit Updater(const QString &updater_path, const QString &manifest_path, QWidget *parent = 0); |
|
||||||
|
|
||||||
private slots: |
|
||||||
void installUpdate(); |
|
||||||
void readProgress(); |
|
||||||
void updateFinished(int exitCode, QProcess::ExitStatus exitStatus); |
|
||||||
|
|
||||||
private: |
|
||||||
QProcess proc; |
|
||||||
QString updater, manifest; |
|
||||||
|
|
||||||
QLabel *text; |
|
||||||
QProgressBar *bar; |
|
||||||
QPushButton *reboot; |
|
||||||
QWidget *prompt, *wifi, *progress; |
|
||||||
}; |
|
Loading…
Reference in new issue