mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-03-02 21:23:56 +08:00
UI fixes (#20069)
We fix some UI issues. Also UI should be more resistant to network manager not running.
old-commit-hash: 43db36d829
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
#include <QtConcurrent>
|
||||
|
||||
#include "networking.hpp"
|
||||
#include "util.h"
|
||||
|
||||
void clearLayout(QLayout* layout) {
|
||||
while (QLayoutItem* item = layout->takeAt(0)) {
|
||||
@@ -43,29 +44,38 @@ std::string exec(const char* cmd) {
|
||||
|
||||
// Networking functions
|
||||
|
||||
Networking::Networking(QWidget* parent, bool show_advanced) : QWidget(parent){
|
||||
Networking::Networking(QWidget* parent, bool show_advanced) : QWidget(parent), show_advanced(show_advanced){
|
||||
s = new QStackedLayout;
|
||||
|
||||
QLabel* warning = new QLabel("Network manager is inactive!");
|
||||
warning->setStyleSheet(R"(font-size: 65px;)");
|
||||
|
||||
s->addWidget(warning);
|
||||
setLayout(s);
|
||||
|
||||
QTimer* timer = new QTimer(this);
|
||||
QObject::connect(timer, SIGNAL(timeout()), this, SLOT(refresh()));
|
||||
timer->start(5000);
|
||||
attemptInitialization();
|
||||
}
|
||||
|
||||
void Networking::attemptInitialization(){
|
||||
// Checks if network manager is active
|
||||
try {
|
||||
wifi = new WifiManager(this);
|
||||
} catch (std::exception &e) {
|
||||
QLabel* warning = new QLabel("Network manager is inactive!");
|
||||
warning->setStyleSheet(R"(font-size: 65px;)");
|
||||
|
||||
QVBoxLayout* warning_layout = new QVBoxLayout;
|
||||
warning_layout->addWidget(warning, 0, Qt::AlignCenter);
|
||||
setLayout(warning_layout);
|
||||
return;
|
||||
}
|
||||
connect(wifi, SIGNAL(wrongPassword(QString)), this, SLOT(wrongPassword(QString)));
|
||||
|
||||
s = new QStackedLayout;
|
||||
connect(wifi, SIGNAL(wrongPassword(QString)), this, SLOT(wrongPassword(QString)));
|
||||
|
||||
QVBoxLayout* vlayout = new QVBoxLayout;
|
||||
|
||||
if (show_advanced) {
|
||||
QPushButton* advancedSettings = new QPushButton("Advanced");
|
||||
advancedSettings->setStyleSheet(R"(margin-right: 30px)");
|
||||
advancedSettings->setFixedSize(300, 100);
|
||||
connect(advancedSettings, &QPushButton::released, [=](){s->setCurrentIndex(1);});
|
||||
advancedSettings->setFixedSize(350, 100);
|
||||
connect(advancedSettings, &QPushButton::released, [=](){s->setCurrentWidget(an);});
|
||||
vlayout->addSpacing(10);
|
||||
vlayout->addWidget(advancedSettings, 0, Qt::AlignRight);
|
||||
vlayout->addSpacing(10);
|
||||
@@ -75,24 +85,20 @@ Networking::Networking(QWidget* parent, bool show_advanced) : QWidget(parent){
|
||||
connect(wifiWidget, SIGNAL(connectToNetwork(Network)), this, SLOT(connectToNetwork(Network)));
|
||||
vlayout->addWidget(wifiWidget, 1);
|
||||
|
||||
s->addWidget(layoutToWidget(vlayout, this));
|
||||
wifiScreen = layoutToWidget(vlayout, this);
|
||||
s->addWidget(wifiScreen);
|
||||
|
||||
an = new AdvancedNetworking(this, wifi);
|
||||
connect(an, &AdvancedNetworking::backPress, [=](){s->setCurrentIndex(0);});
|
||||
connect(an, &AdvancedNetworking::backPress, [=](){s->setCurrentWidget(wifiScreen);});
|
||||
s->addWidget(an);
|
||||
|
||||
// Update network status
|
||||
QTimer* timer = new QTimer(this);
|
||||
QObject::connect(timer, SIGNAL(timeout()), this, SLOT(refresh()));
|
||||
timer->start(5000);
|
||||
|
||||
setStyleSheet(R"(
|
||||
QPushButton {
|
||||
font-size: 50px;
|
||||
margin: 0px;
|
||||
padding: 15px;
|
||||
border-width: 0;
|
||||
border-radius: 7px;
|
||||
border-radius: 30px;
|
||||
color: #dddddd;
|
||||
background-color: #444444;
|
||||
}
|
||||
@@ -101,13 +107,20 @@ Networking::Networking(QWidget* parent, bool show_advanced) : QWidget(parent){
|
||||
background-color: #222222;
|
||||
}
|
||||
)");
|
||||
setLayout(s);
|
||||
s->setCurrentWidget(wifiScreen);
|
||||
ui_setup_complete = true;
|
||||
}
|
||||
|
||||
void Networking::refresh(){
|
||||
if(!this->isVisible()){
|
||||
if (!this->isVisible()) {
|
||||
return;
|
||||
}
|
||||
if (!ui_setup_complete) {
|
||||
attemptInitialization();
|
||||
if (!ui_setup_complete) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
wifiWidget->refresh();
|
||||
an->refresh();
|
||||
}
|
||||
@@ -233,7 +246,7 @@ AdvancedNetworking::AdvancedNetworking(QWidget* parent, WifiManager* wifi): QWid
|
||||
s->addWidget(settingsWidget);
|
||||
|
||||
ssh = new SSH;
|
||||
connect(ssh, &SSH::closeSSHSettings, [=](){s->setCurrentIndex(0);});
|
||||
connect(ssh, &SSH::closeSSHSettings, [=](){s->setCurrentWidget(settingsWidget);});
|
||||
s->addWidget(ssh);
|
||||
|
||||
setLayout(s);
|
||||
@@ -319,14 +332,16 @@ void WifiUI::refresh() {
|
||||
// SSID
|
||||
hlayout->addSpacing(50);
|
||||
QString ssid = QString::fromUtf8(network.ssid);
|
||||
if(ssid.length() > 30){
|
||||
ssid = ssid.left(30)+"…";
|
||||
if(ssid.length() > 20){
|
||||
ssid = ssid.left(20 - 3) + "…";
|
||||
}
|
||||
QLabel *ssid_label = new QLabel(ssid);
|
||||
ssid += QString(20 - ssid.length(), ' ');
|
||||
|
||||
QLabel *ssid_label = new QLabel("<pre>" + ssid + "</pre>");
|
||||
ssid_label->setStyleSheet(R"(
|
||||
font-size: 55px;
|
||||
)");
|
||||
hlayout->addWidget(ssid_label);
|
||||
hlayout->addWidget(ssid_label, 0, Qt::AlignLeft);
|
||||
|
||||
// TODO: don't use images for this
|
||||
// strength indicator
|
||||
|
||||
@@ -72,13 +72,17 @@ public:
|
||||
explicit Networking(QWidget* parent = 0, bool show_advanced = true);
|
||||
|
||||
private:
|
||||
QStackedLayout* s = nullptr; // keyboard, wifiScreen, advanced
|
||||
QStackedLayout* s = nullptr; // nm_warning, keyboard, wifiScreen, advanced
|
||||
QWidget* wifiScreen = nullptr;
|
||||
AdvancedNetworking* an = nullptr;
|
||||
bool ui_setup_complete = false;
|
||||
bool show_advanced;
|
||||
|
||||
Network selectedNetwork;
|
||||
|
||||
WifiUI* wifiWidget;
|
||||
WifiManager* wifi = nullptr;
|
||||
void attemptInitialization();
|
||||
|
||||
private slots:
|
||||
void connectToNetwork(Network n);
|
||||
|
||||
@@ -2,8 +2,10 @@
|
||||
#include <set>
|
||||
#include <stdlib.h>
|
||||
#include <iostream>
|
||||
#include "wifiManager.hpp"
|
||||
|
||||
#include "common/params.h"
|
||||
#include "common/swaglog.h"
|
||||
#include "wifiManager.hpp"
|
||||
|
||||
/**
|
||||
* We are using a NetworkManager DBUS API : https://developer.gnome.org/NetworkManager/1.26/spec.html
|
||||
@@ -45,7 +47,12 @@ T get_response(QDBusMessage response) {
|
||||
QVariant first = response.arguments().at(0);
|
||||
QDBusVariant dbvFirst = first.value<QDBusVariant>();
|
||||
QVariant vFirst = dbvFirst.variant();
|
||||
return vFirst.value<T>();
|
||||
if (vFirst.canConvert<T>()) {
|
||||
return vFirst.value<T>();
|
||||
} else {
|
||||
LOGE("Variant unpacking failure");
|
||||
return T();
|
||||
}
|
||||
}
|
||||
|
||||
bool compare_by_strength(const Network &a, const Network &b) {
|
||||
@@ -229,10 +236,12 @@ void WifiManager::deactivate_connections(QString ssid) {
|
||||
QString active_connection = active_connection_raw.path();
|
||||
QDBusInterface nm(nm_service, active_connection, props_iface, bus);
|
||||
QDBusObjectPath pth = get_response<QDBusObjectPath>(nm.call("Get", connection_iface, "SpecificObject"));
|
||||
QString Ssid = get_property(pth.path(), "Ssid");
|
||||
if (Ssid == ssid) {
|
||||
QDBusInterface nm2(nm_service, nm_path, nm_iface, bus);
|
||||
nm2.call("DeactivateConnection", QVariant::fromValue(active_connection_raw));// TODO change to disconnect
|
||||
if (pth.path() != "" && pth.path() != "/") {
|
||||
QString Ssid = get_property(pth.path(), "Ssid");
|
||||
if (Ssid == ssid) {
|
||||
QDBusInterface nm2(nm_service, nm_path, nm_iface, bus);
|
||||
nm2.call("DeactivateConnection", QVariant::fromValue(active_connection_raw));// TODO change to disconnect
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -347,7 +356,7 @@ void WifiManager::change(unsigned int new_state, unsigned int previous_state, un
|
||||
|
||||
void WifiManager::disconnect() {
|
||||
QString active_ap = get_active_ap();
|
||||
if (active_ap!="" && active_ap!="/") {
|
||||
if (active_ap != "" && active_ap != "/") {
|
||||
deactivate_connections(get_property(active_ap, "Ssid"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,10 +45,13 @@ KeyboardLayout::KeyboardLayout(QWidget *parent, std::vector<QVector<QString>> la
|
||||
font-size: 65px;
|
||||
margin: 0px;
|
||||
padding: 0px;
|
||||
border-radius: 7px;
|
||||
border-radius: 30px;
|
||||
color: #dddddd;
|
||||
background-color: #444444;
|
||||
}
|
||||
QPushButton:pressed {
|
||||
background-color: #000000;
|
||||
}
|
||||
)");
|
||||
setLayout(vlayout);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user