diff --git a/selfdrive/ui/qt/offroad/networking.cc b/selfdrive/ui/qt/offroad/networking.cc index d44b5b7e75..6502576beb 100644 --- a/selfdrive/ui/qt/offroad/networking.cc +++ b/selfdrive/ui/qt/offroad/networking.cc @@ -5,7 +5,6 @@ #include #include #include -#include #include #include "common/params.h" @@ -30,20 +29,6 @@ QWidget* layoutToWidget(QLayout* l, QWidget* parent){ return q; } -// https://stackoverflow.com/questions/478898/how-do-i-execute-a-command-and-get-the-output-of-the-command-within-c-using-po -std::string exec(const char* cmd) { - std::array buffer; - std::string result; - std::unique_ptr pipe(popen(cmd, "r"), pclose); - if (!pipe) { - throw std::runtime_error("popen() failed!"); - } - while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr) { - result += buffer.data(); - } - return result; -} - // Networking functions Networking::Networking(QWidget* parent, bool show_advanced) : QWidget(parent), show_advanced(show_advanced){ @@ -131,23 +116,19 @@ void Networking::connectToNetwork(Network n) { if (n.security_type == SecurityType::OPEN) { wifi->connect(n); } else if (n.security_type == SecurityType::WPA) { - QString pass = InputDialog::getText("Enter password for \"" + n.ssid + "\""); + QString pass = InputDialog::getText("Enter password for \"" + n.ssid + "\"", 8); wifi->connect(n, pass); } } void Networking::wrongPassword(QString ssid) { - return; // TODO: add this back - /* for (Network n : wifi->seen_networks) { if (n.ssid == ssid) { - inputField->setPromptText("Wrong password for \"" + n.ssid +"\""); - s->setCurrentIndex(0); - emit openKeyboard(); + QString pass = InputDialog::getText("Wrong password for \"" + n.ssid +"\"", 8); + wifi->connect(n, pass); return; } } - */ } QFrame* hline(QWidget* parent = 0){ @@ -193,7 +174,7 @@ AdvancedNetworking::AdvancedNetworking(QWidget* parent, WifiManager* wifi): QWid editPasswordButton = new QPushButton("EDIT"); editPasswordButton->setFixedWidth(500); connect(editPasswordButton, &QPushButton::released, [=](){ - QString pass = InputDialog::getText("Enter new tethering password"); + QString pass = InputDialog::getText("Enter new tethering password", 8); if (pass.size()) { wifi->changeTetheringPassword(pass); } @@ -255,16 +236,11 @@ AdvancedNetworking::AdvancedNetworking(QWidget* parent, WifiManager* wifi): QWid } bool AdvancedNetworking::isSSHEnabled(){ - QString response = QString::fromStdString(exec("systemctl is-active ssh")); - return response.startsWith("active"); + return Params().get("SshEnabled") == "1"; } void AdvancedNetworking::refresh(){ ipLabel->setText(wifi->ipv4_address); - // Don't refresh while changing SSH state - if(!toggle_switch_SSH->getEnabled()){ - return; - } if (toggle_switch_SSH->on != isSSHEnabled()) { toggle_switch_SSH->togglePosition(); } @@ -281,23 +257,8 @@ void AdvancedNetworking::toggleTethering(int enable) { editPasswordButton->setEnabled(!enable); } -void enableSSH(Toggle* toggle_switch_SSH){ - Params().write_db_value("SshEnabled", "1"); - toggle_switch_SSH->setEnabled(true); -} - -void disableSSH(Toggle* toggle_switch_SSH){ - Params().write_db_value("SshEnabled", "0"); - toggle_switch_SSH->setEnabled(true); -} - void AdvancedNetworking::toggleSSH(int enable) { - toggle_switch_SSH->setEnabled(false); - if (enable) { - QtConcurrent::run(enableSSH, toggle_switch_SSH); - } else { - QtConcurrent::run(disableSSH, toggle_switch_SSH); - } + Params().write_db_value("SshEnabled", QString::number(enable).toStdString()); } diff --git a/selfdrive/ui/qt/widgets/input_field.cc b/selfdrive/ui/qt/widgets/input_field.cc index 402b50a882..8f7731d421 100644 --- a/selfdrive/ui/qt/widgets/input_field.cc +++ b/selfdrive/ui/qt/widgets/input_field.cc @@ -3,7 +3,7 @@ #include "input_field.hpp" #include "qt_window.hpp" -InputDialog::InputDialog(QString prompt_text, QWidget *parent): QDialog(parent) { +InputDialog::InputDialog(QString prompt_text, QWidget *parent):QDialog(parent) { layout = new QVBoxLayout(); layout->setContentsMargins(50, 50, 50, 50); layout->setSpacing(20); @@ -56,8 +56,9 @@ InputDialog::InputDialog(QString prompt_text, QWidget *parent): QDialog(parent) setLayout(layout); } -QString InputDialog::getText(const QString prompt) { +QString InputDialog::getText(const QString prompt, int minLength) { InputDialog d = InputDialog(prompt); + d.setMinLength(minLength); const int ret = d.exec(); if (ret) { return d.text(); @@ -81,8 +82,12 @@ void InputDialog::handleInput(QString s) { } if (!QString::compare(s,"⏎")) { - done(QDialog::Accepted); - emitText(line->text()); + if (line->text().length() > minLength){ + done(QDialog::Accepted); + emitText(line->text()); + } else { + setMessage("Need at least "+QString::number(minLength)+" characters!", false); + } } QVector control_buttons {"⇧", "↑", "ABC", "⏎", "#+=", "⌫", "123"}; @@ -105,3 +110,7 @@ void InputDialog::setMessage(QString message, bool clearInputField){ line->setText(""); } } + +void InputDialog::setMinLength(int length){ + minLength = length; +} \ No newline at end of file diff --git a/selfdrive/ui/qt/widgets/input_field.hpp b/selfdrive/ui/qt/widgets/input_field.hpp index 118347aa19..5889f84a5b 100644 --- a/selfdrive/ui/qt/widgets/input_field.hpp +++ b/selfdrive/ui/qt/widgets/input_field.hpp @@ -14,12 +14,14 @@ class InputDialog : public QDialog { public: explicit InputDialog(QString prompt_text, QWidget* parent = 0); - static QString getText(QString prompt); + static QString getText(QString prompt, int minLength = -1); QString text(); void show(); void setMessage(QString message, bool clearInputField=true); + void setMinLength(int length); private: + int minLength; QLineEdit *line; Keyboard *k; QLabel *label; diff --git a/selfdrive/ui/qt/widgets/keyboard.cc b/selfdrive/ui/qt/widgets/keyboard.cc index 8a8006ed99..f5b6f7ff81 100644 --- a/selfdrive/ui/qt/widgets/keyboard.cc +++ b/selfdrive/ui/qt/widgets/keyboard.cc @@ -13,14 +13,14 @@ const int SPACEBAR_STRETCH = 3; KeyboardLayout::KeyboardLayout(QWidget *parent, std::vector> layout) : QWidget(parent) { QVBoxLayout* vlayout = new QVBoxLayout; vlayout->setMargin(0); - vlayout->setSpacing(15); + vlayout->setSpacing(35); QButtonGroup* btn_group = new QButtonGroup(this); QObject::connect(btn_group, SIGNAL(buttonClicked(QAbstractButton*)), parent, SLOT(handleButton(QAbstractButton*))); for (const auto &s : layout) { QHBoxLayout *hlayout = new QHBoxLayout; - hlayout->setSpacing(30); + hlayout->setSpacing(25); if (vlayout->count() == 1) { hlayout->addSpacing(90); @@ -28,7 +28,7 @@ KeyboardLayout::KeyboardLayout(QWidget *parent, std::vector> la for (const QString &p : s) { QPushButton* btn = new QPushButton(p); - btn->setFixedHeight(120); + btn->setFixedHeight(135); btn_group->addButton(btn); hlayout->addWidget(btn, p == QString(" ") ? SPACEBAR_STRETCH : DEFAULT_STRETCH); }