|
|
@ -55,6 +55,7 @@ WifiUI::WifiUI(QWidget *parent) : QWidget(parent) { |
|
|
|
|
|
|
|
|
|
|
|
// Scan on startup
|
|
|
|
// Scan on startup
|
|
|
|
wifi->request_scan(); |
|
|
|
wifi->request_scan(); |
|
|
|
|
|
|
|
page = 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void WifiUI::refresh() { |
|
|
|
void WifiUI::refresh() { |
|
|
@ -74,49 +75,81 @@ void WifiUI::refresh() { |
|
|
|
for (Network &network : wifi->seen_networks){ |
|
|
|
for (Network &network : wifi->seen_networks){ |
|
|
|
QHBoxLayout *hlayout = new QHBoxLayout; |
|
|
|
QHBoxLayout *hlayout = new QHBoxLayout; |
|
|
|
|
|
|
|
|
|
|
|
// SSID
|
|
|
|
if(page * networks_per_page <= i && i < (page + 1) * networks_per_page){ |
|
|
|
hlayout->addSpacing(50); |
|
|
|
// SSID
|
|
|
|
hlayout->addWidget(new QLabel(QString::fromUtf8(network.ssid))); |
|
|
|
hlayout->addSpacing(50); |
|
|
|
|
|
|
|
hlayout->addWidget(new QLabel(QString::fromUtf8(network.ssid))); |
|
|
|
// strength indicator
|
|
|
|
|
|
|
|
unsigned int strength_scale = network.strength / 17; |
|
|
|
// strength indicator
|
|
|
|
QPixmap pix("../assets/images/network_" + QString::number(strength_scale) + ".png"); |
|
|
|
unsigned int strength_scale = network.strength / 17; |
|
|
|
QLabel *icon = new QLabel(); |
|
|
|
QPixmap pix("../assets/images/network_" + QString::number(strength_scale) + ".png"); |
|
|
|
icon->setPixmap(pix.scaledToWidth(100, Qt::SmoothTransformation)); |
|
|
|
QLabel *icon = new QLabel(); |
|
|
|
icon->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed)); |
|
|
|
icon->setPixmap(pix.scaledToWidth(100, Qt::SmoothTransformation)); |
|
|
|
hlayout->addWidget(icon); |
|
|
|
icon->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed)); |
|
|
|
hlayout->addSpacing(20); |
|
|
|
hlayout->addWidget(icon); |
|
|
|
|
|
|
|
hlayout->addSpacing(20); |
|
|
|
// connect button
|
|
|
|
|
|
|
|
QPushButton* btn = new QPushButton(network.connected ? "Connected" : "Connect"); |
|
|
|
// connect button
|
|
|
|
btn->setFixedWidth(300); |
|
|
|
QPushButton* btn = new QPushButton(network.connected ? "Connected" : "Connect"); |
|
|
|
btn->setDisabled(network.connected || network.security_type == SecurityType::UNSUPPORTED); |
|
|
|
btn->setFixedWidth(300); |
|
|
|
hlayout->addWidget(btn); |
|
|
|
btn->setDisabled(network.connected || network.security_type == SecurityType::UNSUPPORTED); |
|
|
|
hlayout->addSpacing(20); |
|
|
|
hlayout->addWidget(btn); |
|
|
|
|
|
|
|
hlayout->addSpacing(20); |
|
|
|
connectButtons->addButton(btn, i++); |
|
|
|
|
|
|
|
|
|
|
|
connectButtons->addButton(btn, i); |
|
|
|
QWidget * w = new QWidget; |
|
|
|
|
|
|
|
w->setLayout(hlayout); |
|
|
|
QWidget * w = new QWidget; |
|
|
|
vlayout->addWidget(w); |
|
|
|
w->setLayout(hlayout); |
|
|
|
w->setStyleSheet(R"( |
|
|
|
vlayout->addWidget(w); |
|
|
|
QLabel { |
|
|
|
w->setStyleSheet(R"( |
|
|
|
font-size: 40px; |
|
|
|
QLabel { |
|
|
|
} |
|
|
|
font-size: 40px; |
|
|
|
QPushButton:enabled { |
|
|
|
} |
|
|
|
background-color: #114265; |
|
|
|
QPushButton:enabled { |
|
|
|
} |
|
|
|
background-color: #114265; |
|
|
|
QPushButton:disabled { |
|
|
|
} |
|
|
|
background-color: #323C43; |
|
|
|
QPushButton:disabled { |
|
|
|
} |
|
|
|
background-color: #323C43; |
|
|
|
* { |
|
|
|
} |
|
|
|
background-color: #114265; |
|
|
|
* { |
|
|
|
} |
|
|
|
background-color: #114265; |
|
|
|
)"); |
|
|
|
} |
|
|
|
if(i > 10){ |
|
|
|
)"); |
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
i+=1; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
QHBoxLayout *prev_next_buttons = new QHBoxLayout; |
|
|
|
|
|
|
|
QPushButton* prev = new QPushButton("Previous"); |
|
|
|
|
|
|
|
prev->setEnabled(page); |
|
|
|
|
|
|
|
prev->setFixedHeight(100); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QPushButton* next = new QPushButton("Next"); |
|
|
|
|
|
|
|
next->setFixedHeight(100); |
|
|
|
|
|
|
|
//If there are more visible networks then we can show, enable going to next page
|
|
|
|
|
|
|
|
if(wifi->seen_networks.size() > (page + 1) * networks_per_page){ |
|
|
|
|
|
|
|
next->setEnabled(true); |
|
|
|
|
|
|
|
}else{ |
|
|
|
|
|
|
|
next->setDisabled(true); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
QObject::connect(prev, SIGNAL(released()), this, SLOT(prevPage())); |
|
|
|
|
|
|
|
QObject::connect(next, SIGNAL(released()), this, SLOT(nextPage())); |
|
|
|
|
|
|
|
prev_next_buttons->addWidget(prev); |
|
|
|
|
|
|
|
prev_next_buttons->addWidget(next); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QWidget * w = new QWidget; |
|
|
|
|
|
|
|
w->setLayout(prev_next_buttons); |
|
|
|
|
|
|
|
w->setStyleSheet(R"( |
|
|
|
|
|
|
|
QPushButton:enabled { |
|
|
|
|
|
|
|
background-color: #114265; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
QPushButton:disabled { |
|
|
|
|
|
|
|
background-color: #323C43; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
* { |
|
|
|
|
|
|
|
background-color: #114265; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
)"); |
|
|
|
|
|
|
|
vlayout->addWidget(w); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void WifiUI::handleButton(QAbstractButton* button) { |
|
|
|
void WifiUI::handleButton(QAbstractButton* button) { |
|
|
@ -130,7 +163,6 @@ void WifiUI::handleButton(QAbstractButton* button) { |
|
|
|
wifi->connect(n); |
|
|
|
wifi->connect(n); |
|
|
|
} else if (n.security_type == SecurityType::WPA){ |
|
|
|
} else if (n.security_type == SecurityType::WPA){ |
|
|
|
QString password = getStringFromUser(); |
|
|
|
QString password = getStringFromUser(); |
|
|
|
|
|
|
|
|
|
|
|
if(password.size()){ |
|
|
|
if(password.size()){ |
|
|
|
wifi->connect(n, password); |
|
|
|
wifi->connect(n, password); |
|
|
|
} |
|
|
|
} |
|
|
@ -150,3 +182,11 @@ void WifiUI::receiveText(QString t) { |
|
|
|
loop.quit(); |
|
|
|
loop.quit(); |
|
|
|
text = t; |
|
|
|
text = t; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void WifiUI::prevPage() { |
|
|
|
|
|
|
|
page--; |
|
|
|
|
|
|
|
refresh(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
void WifiUI::nextPage() { |
|
|
|
|
|
|
|
page++; |
|
|
|
|
|
|
|
refresh(); |
|
|
|
|
|
|
|
} |
|
|
|