diff --git a/src/eink.qrc b/src/eink.qrc
index 2cac456..08704b5 100644
--- a/src/eink.qrc
+++ b/src/eink.qrc
@@ -86,5 +86,7 @@
resources/view-highlights.png
resources/stop.png
resources/refresh.png
+ resources/lock-fill.png
+ resources/lock-unlock-fill.png
diff --git a/src/functions.h b/src/functions.h
index 88cb271..81e7e26 100644
--- a/src/functions.h
+++ b/src/functions.h
@@ -1072,6 +1072,7 @@ namespace {
global::wifi::WifiState checkWifiState() {
QProcess *wifiStateProcess = new QProcess();
// Important to remember thats its in chroot...
+ // What can be run in the chroot, should be run here. ibxd is a bit a mess
QString path = "/external_root/usr/local/bin/wifi/wifi_status.sh";
QStringList args;
wifiStateProcess->start(path, args);
diff --git a/src/resources/lock-fill.png b/src/resources/lock-fill.png
new file mode 100644
index 0000000..b6de073
Binary files /dev/null and b/src/resources/lock-fill.png differ
diff --git a/src/resources/lock-unlock-fill.png b/src/resources/lock-unlock-fill.png
new file mode 100644
index 0000000..8795cdf
Binary files /dev/null and b/src/resources/lock-unlock-fill.png differ
diff --git a/src/widgets/dialogs/wifi/network.cpp b/src/widgets/dialogs/wifi/network.cpp
index 9dd9a60..0b6ed15 100644
--- a/src/widgets/dialogs/wifi/network.cpp
+++ b/src/widgets/dialogs/wifi/network.cpp
@@ -6,9 +6,49 @@ network::network(QWidget *parent) :
ui(new Ui::network)
{
ui->setupUi(this);
+
+ // Stylesheet, style & misc.
+ QFile stylesheetFile("/mnt/onboard/.adds/inkbox/eink.qss");
+ stylesheetFile.open(QFile::ReadOnly);
+ this->setStyleSheet(stylesheetFile.readAll());
+ stylesheetFile.close();
+
+ // Buttons
+ ui->encryptionIcon->setProperty("type", "borderless");
+ ui->encryptionIcon->setStyleSheet("QPushButton[type='borderless']:pressed { background: white; color: white; border: none; }");
+
+ ui->enterButton->setProperty("type", "borderless");
+
+
}
network::~network()
{
delete ui;
}
+
+void network::applyVariables() {
+ ui->signalStrengthLabel->setText(QString::number(mainData.signal) + "%");
+
+ // limit name size, maybe device specific
+ QString cuttedSingleData = mainData.name;
+ if(cuttedSingleData.count() > 27)
+ {
+ cuttedSingleData = cuttedSingleData.remove(24, cuttedSingleData.count() - 24);
+ cuttedSingleData.append("...");
+ }
+ ui->nameLabel->setText(cuttedSingleData);
+
+ if(mainData.encryption == true) {
+ ui->encryptionIcon->setIcon(QIcon("://resources/lock-fill.png"));
+ }
+ else {
+ ui->encryptionIcon->setIcon(QIcon("://resources/lock-unlock-fill.png"));
+ }
+
+ if(currentlyConnectedNetwork == mainData.name) {
+ ui->frame->setStyleSheet(".QFrame{background-color: grey; border: 3px solid black; border-radius: 10px;}");
+ } else {
+ ui->frame->setStyleSheet(".QFrame{background-color: white; border: 3px solid black; border-radius: 10px;}");
+ }
+}
diff --git a/src/widgets/dialogs/wifi/network.h b/src/widgets/dialogs/wifi/network.h
index ab12625..171d5bc 100644
--- a/src/widgets/dialogs/wifi/network.h
+++ b/src/widgets/dialogs/wifi/network.h
@@ -19,6 +19,9 @@ public:
global::wifi::wifiNetworkData mainData;
QString currentlyConnectedNetwork;
+public slots:
+ void applyVariables();
+
private:
Ui::network *ui;
};
diff --git a/src/widgets/dialogs/wifi/network.ui b/src/widgets/dialogs/wifi/network.ui
index 152a22c..6487348 100644
--- a/src/widgets/dialogs/wifi/network.ui
+++ b/src/widgets/dialogs/wifi/network.ui
@@ -20,6 +20,18 @@
Form
+
+ 17
+
+
+ 4
+
+
+ 17
+
+
+ 4
+
-
@@ -32,9 +44,24 @@
QFrame::StyledPanel
- QFrame::Raised
+ QFrame::Plain
+
+
+ 3
+
+ 3
+
+
+ 3
+
+
+ 3
+
+
+ 3
+
-
@@ -42,6 +69,19 @@
+ -
+
+
+ QFrame::Plain
+
+
+ 3
+
+
+ Qt::Vertical
+
+
+
-
diff --git a/src/widgets/dialogs/wifi/wifidialog.cpp b/src/widgets/dialogs/wifi/wifidialog.cpp
index 5ec212f..2c81f13 100644
--- a/src/widgets/dialogs/wifi/wifidialog.cpp
+++ b/src/widgets/dialogs/wifi/wifidialog.cpp
@@ -3,6 +3,7 @@
#include
#include
#include
+#include
#include "wifidialog.h"
#include "ui_wifidialog.h"
@@ -29,6 +30,12 @@ wifiDialog::wifiDialog(QWidget *parent) :
ui->Wificheckbox->setStyleSheet("QCheckBox::indicator { width:50px; height: 50px; }");
+ ui->returnBtn->setProperty("type", "borderless");
+
+ // Scroll bar
+ // Needed for the nia.
+ ui->scrollArea->verticalScrollBar()->setStyleSheet("QScrollBar:vertical { width: 50px; }");
+
// Size
QRect screenGeometry = QGuiApplication::screens()[0]->geometry();
this->setFixedWidth(screenGeometry.width());
@@ -49,7 +56,13 @@ wifiDialog::wifiDialog(QWidget *parent) :
ui->logBtn->setFixedHeight(ui->logBtn->height() + heighIncrease);
ui->refreshBtn->setFixedHeight(ui->refreshBtn->height() + heighIncrease);
- //ui->cancelBtn->setProperty("type", "borderless");
+ // And set wifi checkbox state. also ignore this first call
+ global::wifi::WifiState currentWifiState = checkWifiState();
+ if(currentWifiState != global::wifi::WifiState::Disabled and currentWifiState != global::wifi::WifiState::Unknown) {
+ ui->Wificheckbox->setChecked(true);
+ } else {
+ wifiButtonEnabled = true;
+ }
}
@@ -161,13 +174,11 @@ void wifiDialog::on_refreshBtn_clicked()
log("To scan, turn on wi-fi first", className);
}
else {
- if(launchRefresh() == true) {
- refreshNetworksList();
- }
+ QTimer::singleShot(0, this, SLOT(launchRefresh()));
}
}
-bool wifiDialog::launchRefresh() {
+void wifiDialog::launchRefresh() {
QFile fullList = QFile("/external_root/run/wifi_list_full");
QFile formattedList = QFile("/external_root/run/wifi_list_format");
fullList.remove();
@@ -186,10 +197,9 @@ bool wifiDialog::launchRefresh() {
if(fullList.exists() == false or formattedList.exists() == false) {
emit showToast("Failed to get network list");
log("Failed to get network list", className);
- return false;
}
log("Happily got network list", className);
- return true;
+ refreshNetworksList();
}
void wifiDialog::refreshNetworksList() {
@@ -229,7 +239,10 @@ void wifiDialog::refreshNetworksList() {
}
count = count + 1;
}
- pureNetworkList.append(singleNetwork);
+ // Really filter out empty networks
+ if(singleNetwork.name.isEmpty() == false) {
+ pureNetworkList.append(singleNetwork);
+ }
}
log("found valid networks: " + QString::number(pureNetworkList.count()));
QFile currentWifiNameFile = QFile("/external_root/run/current_wifi_name");
@@ -245,7 +258,7 @@ void wifiDialog::refreshNetworksList() {
int countVec = 0;
int vectorNetworkLocation = 9999;
for(global::wifi::wifiNetworkData wifiNetwork: pureNetworkList) {
- if(wifiNetwork.name.contains(currentWifiNetwork) == true) {
+ if(currentWifiNetwork.isEmpty() == false and wifiNetwork.name.contains(currentWifiNetwork) == true) {
log("Found current network in vector", className);
vectorNetworkLocation = countVec;
currentNetwork = wifiNetwork.name;
@@ -254,11 +267,68 @@ void wifiDialog::refreshNetworksList() {
connectedNetwork->currentlyConnectedNetwork = currentNetwork;
// this doesnt work so a layout is needed
// ui->scrollArea->addScrollBarWidget(connectedNetwork, Qt::AlignTop);
+ connectedNetwork->applyVariables();
ui->scrollBarLayout->addWidget(connectedNetwork, Qt::AlignTop);
}
countVec = countVec + 1;
}
+ if(vectorNetworkLocation != 9999) {
+ pureNetworkList.removeAt(vectorNetworkLocation);
+ }
+ }
+ // Sort based on signal strength
+ QVector sortedPureNetworkList;
+ sortedPureNetworkList.append(pureNetworkList.first());
+ pureNetworkList.removeFirst();
+ for(global::wifi::wifiNetworkData wifiNetwork: pureNetworkList) {
+ bool stopIterating = false;
+ int counter = 0;
+ for(global::wifi::wifiNetworkData wifiNetworkToSort: sortedPureNetworkList) {
+ if(stopIterating == false) {
+ if(wifiNetwork.signal > wifiNetworkToSort.signal) {
+ sortedPureNetworkList.insert(counter, wifiNetwork);
+ stopIterating = true;
+ }
+ counter = counter + 1;
+ }
+ }
+ }
+
+ // And now rest of the networks
+ for(global::wifi::wifiNetworkData wifiNetwork: sortedPureNetworkList) {
+ network* connectedNetwork = new network;
+ connectedNetwork->mainData = wifiNetwork;
+ connectedNetwork->currentlyConnectedNetwork = currentNetwork;
+ connectedNetwork->applyVariables();
+ connect(this, SIGNAL(killNetworkWidgets()), connectedNetwork, SLOT(close()));
+ ui->scrollBarLayout->addWidget(connectedNetwork, Qt::AlignTop);
}
}
+
+void wifiDialog::on_Wificheckbox_stateChanged(int arg1)
+{
+ log("wifi dialog clicked: " + QString::number(arg1), className);
+ if(wifiButtonEnabled == true) {
+ if(arg1 == 2) {
+ log("turning wifi on", className);
+ QTimer::singleShot(0, this, SLOT(turnOnWifi()));
+ } else {
+ log("turning wifi off", className);
+ QTimer::singleShot(0, this, SLOT(turnOffWifi()));
+ }
+ }
+
+ if(wifiButtonEnabled == false){
+ wifiButtonEnabled = true;
+ }
+}
+
+void wifiDialog::turnOnWifi() {
+ string_writeconfig("/opt/ibxd", "toggle_wifi_on\n");
+}
+
+void wifiDialog::turnOffWifi() {
+ string_writeconfig("/opt/ibxd", "toggle_wifi_off\n");
+}
diff --git a/src/widgets/dialogs/wifi/wifidialog.h b/src/widgets/dialogs/wifi/wifidialog.h
index 072647f..1f30049 100644
--- a/src/widgets/dialogs/wifi/wifidialog.h
+++ b/src/widgets/dialogs/wifi/wifidialog.h
@@ -21,9 +21,10 @@ public:
private:
Ui::wifiDialog *ui;
+ bool wifiButtonEnabled = false;
public slots:
- bool launchRefresh();
+ void launchRefresh();
void refreshNetworksList();
signals:
@@ -35,6 +36,9 @@ signals:
private slots:
void on_refreshBtn_clicked();
+ void on_Wificheckbox_stateChanged(int arg1);
+ void turnOnWifi();
+ void turnOffWifi();
};
#endif // WIFIDIALOG_H
diff --git a/src/widgets/dialogs/wifi/wifidialog.ui b/src/widgets/dialogs/wifi/wifidialog.ui
index 60a2f32..f25e754 100644
--- a/src/widgets/dialogs/wifi/wifidialog.ui
+++ b/src/widgets/dialogs/wifi/wifidialog.ui
@@ -31,6 +31,9 @@
-
+
+ 10
+
-
@@ -139,6 +142,9 @@
0
+
+ Qt::ScrollBarAsNeeded
+
Qt::ScrollBarAlwaysOff
@@ -151,17 +157,62 @@
0
0
765
- 576
+ 567
+
+ 0
+
+
+ 9
+
+
+ 0
+
-
-
+
+
+ 0
+
+
+ 0
+
+
-
+
+
+ -
+
+
+ Qt::Vertical
+
+
+
+ 20
+ 40
+
+
+
+
+
+ -
+
+
+ QFrame::Plain
+
+
+ 3
+
+
+ Qt::Horizontal
+
+
+
-