mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-07-23 18:22:13 +08:00
qt setup keyboard (#2663)
* add keyboard for custom url * it works * cleanup old-commit-hash: 8de4adac61a9d3fd5eb9044da0d44e36f32806c5
This commit is contained in:
@@ -2,29 +2,29 @@
|
||||
#include <stdlib.h>
|
||||
#include <curl/curl.h>
|
||||
|
||||
#include <QString>
|
||||
#include <QLabel>
|
||||
#include <QWidget>
|
||||
#include <QLineEdit>
|
||||
#include <QPushButton>
|
||||
#include <QVBoxLayout>
|
||||
#include <QApplication>
|
||||
|
||||
#include "setup.hpp"
|
||||
#include "offroad/wifi.hpp"
|
||||
#include "widgets/input_field.hpp"
|
||||
#include "qt_window.hpp"
|
||||
|
||||
#define USER_AGENT "AGNOSSetup-0.1"
|
||||
|
||||
int download(std::string url) {
|
||||
void Setup::download(QString url) {
|
||||
setCurrentIndex(count() - 1);
|
||||
|
||||
CURL *curl;
|
||||
curl = curl_easy_init();
|
||||
if (!curl) return -1;
|
||||
// TODO: exit with return code
|
||||
if (!curl) return;
|
||||
|
||||
char tmpfile[] = "/tmp/installer_XXXXXX";
|
||||
FILE *fp = fdopen(mkstemp(tmpfile), "w");
|
||||
|
||||
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
|
||||
curl_easy_setopt(curl, CURLOPT_URL, url.toStdString().c_str());
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, NULL);
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
|
||||
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
|
||||
@@ -34,7 +34,6 @@ int download(std::string url) {
|
||||
fclose(fp);
|
||||
|
||||
rename(tmpfile, "/tmp/installer");
|
||||
return 0;
|
||||
}
|
||||
|
||||
QLabel * title_label(QString text) {
|
||||
@@ -98,25 +97,43 @@ QWidget * Setup::software_selection() {
|
||||
|
||||
main_layout->addWidget(title_label("Choose Software"), 0, Qt::AlignCenter);
|
||||
|
||||
QPushButton *dashcam_btn = new QPushButton("Dashcam");
|
||||
main_layout->addWidget(dashcam_btn);
|
||||
QObject::connect(dashcam_btn, SIGNAL(released()), this, SLOT(nextPage()));
|
||||
|
||||
main_layout->addSpacing(50);
|
||||
|
||||
url_input = new QLineEdit();
|
||||
url_input->setStyleSheet(R"(
|
||||
color: black;
|
||||
background-color: white;
|
||||
font-size: 55px;
|
||||
padding: 40px;
|
||||
)");
|
||||
main_layout->addWidget(url_input);
|
||||
QPushButton *dashcam_btn = new QPushButton("Dashcam");
|
||||
main_layout->addWidget(dashcam_btn);
|
||||
QObject::connect(dashcam_btn, &QPushButton::released, this, [=]() {
|
||||
this->download("https://dashcam.comma.ai");
|
||||
});
|
||||
|
||||
main_layout->addSpacing(50);
|
||||
|
||||
QPushButton *custom_btn = new QPushButton("Custom");
|
||||
main_layout->addWidget(custom_btn);
|
||||
QObject::connect(custom_btn, SIGNAL(released()), this, SLOT(nextPage()));
|
||||
|
||||
main_layout->addSpacing(100);
|
||||
|
||||
QPushButton *prev_btn = new QPushButton("Back");
|
||||
main_layout->addWidget(prev_btn);
|
||||
QObject::connect(prev_btn, SIGNAL(released()), this, SLOT(prevPage()));
|
||||
|
||||
QWidget *widget = new QWidget();
|
||||
widget->setLayout(main_layout);
|
||||
return widget;
|
||||
}
|
||||
|
||||
QWidget * Setup::custom_software() {
|
||||
QVBoxLayout *main_layout = new QVBoxLayout();
|
||||
main_layout->setMargin(50);
|
||||
|
||||
main_layout->addWidget(title_label("Custom Software"), Qt::AlignTop | Qt::AlignHCenter);
|
||||
|
||||
InputField *input = new InputField();
|
||||
input->setPromptText("Enter URL");
|
||||
main_layout->addWidget(input);
|
||||
|
||||
QObject::connect(input, SIGNAL(emitText(QString)), this, SLOT(download(QString)));
|
||||
|
||||
QWidget *widget = new QWidget();
|
||||
widget->setLayout(main_layout);
|
||||
return widget;
|
||||
@@ -132,20 +149,19 @@ QWidget * Setup::downloading() {
|
||||
return widget;
|
||||
}
|
||||
|
||||
void Setup::prevPage() {
|
||||
setCurrentIndex(currentIndex() - 1);
|
||||
}
|
||||
|
||||
void Setup::nextPage() {
|
||||
setCurrentIndex(currentIndex() + 1);
|
||||
|
||||
// start download
|
||||
if (currentIndex() == count() - 1) {
|
||||
std::string url = url_input->text().toStdString();
|
||||
download(url);
|
||||
}
|
||||
}
|
||||
|
||||
Setup::Setup(QWidget *parent) {
|
||||
addWidget(getting_started());
|
||||
addWidget(network_setup());
|
||||
addWidget(software_selection());
|
||||
addWidget(custom_software());
|
||||
addWidget(downloading());
|
||||
|
||||
setStyleSheet(R"(
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#include <QString>
|
||||
#include <QWidget>
|
||||
#include <QLineEdit>
|
||||
#include <QPushButton>
|
||||
@@ -16,8 +17,11 @@ private:
|
||||
QWidget *getting_started();
|
||||
QWidget *network_setup();
|
||||
QWidget *software_selection();
|
||||
QWidget *custom_software();
|
||||
QWidget *downloading();
|
||||
|
||||
public slots:
|
||||
void nextPage();
|
||||
void prevPage();
|
||||
void download(QString url);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user