|
|
|
@ -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); |
|
|
|
|
|
|
|
|
|
main_layout->addSpacing(50); |
|
|
|
|
|
|
|
|
|
QPushButton *dashcam_btn = new QPushButton("Dashcam"); |
|
|
|
|
main_layout->addWidget(dashcam_btn); |
|
|
|
|
QObject::connect(dashcam_btn, SIGNAL(released()), this, SLOT(nextPage())); |
|
|
|
|
QObject::connect(dashcam_btn, &QPushButton::released, this, [=]() { |
|
|
|
|
this->download("https://dashcam.comma.ai"); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
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 *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"( |
|
|
|
|