mirror of
https://github.com/Quill-OS/quill.git
synced 2024-10-31 21:33:22 -07:00
scanning networks
This commit is contained in:
parent
f2d269033d
commit
ec81f72d2d
7 changed files with 265 additions and 26 deletions
|
@ -175,6 +175,13 @@ namespace global {
|
|||
Unknown, // to not confuse lastWifiState
|
||||
};
|
||||
inline bool isConnected;
|
||||
class wifiNetworkData {
|
||||
public:
|
||||
QString mac;
|
||||
QString name;
|
||||
bool encryption;
|
||||
int signal;
|
||||
};
|
||||
}
|
||||
inline QString systemInfoText;
|
||||
inline bool forbidOpenSearchDialog;
|
||||
|
|
14
src/widgets/dialogs/wifi/network.cpp
Normal file
14
src/widgets/dialogs/wifi/network.cpp
Normal file
|
@ -0,0 +1,14 @@
|
|||
#include "network.h"
|
||||
#include "ui_network.h"
|
||||
|
||||
network::network(QWidget *parent) :
|
||||
QWidget(parent),
|
||||
ui(new Ui::network)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
}
|
||||
|
||||
network::~network()
|
||||
{
|
||||
delete ui;
|
||||
}
|
26
src/widgets/dialogs/wifi/network.h
Normal file
26
src/widgets/dialogs/wifi/network.h
Normal file
|
@ -0,0 +1,26 @@
|
|||
#ifndef NETWORK_H
|
||||
#define NETWORK_H
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
#include "functions.h"
|
||||
|
||||
namespace Ui {
|
||||
class network;
|
||||
}
|
||||
|
||||
class network : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit network(QWidget *parent = nullptr);
|
||||
~network();
|
||||
global::wifi::wifiNetworkData mainData;
|
||||
QString currentlyConnectedNetwork;
|
||||
|
||||
private:
|
||||
Ui::network *ui;
|
||||
};
|
||||
|
||||
#endif // NETWORK_H
|
92
src/widgets/dialogs/wifi/network.ui
Normal file
92
src/widgets/dialogs/wifi/network.ui
Normal file
|
@ -0,0 +1,92 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>network</class>
|
||||
<widget class="QWidget" name="network">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>605</width>
|
||||
<height>62</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QFrame" name="frame">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="QLabel" name="signalStrengthLabel">
|
||||
<property name="text">
|
||||
<string>SIgnal strenth</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="nameLabel">
|
||||
<property name="text">
|
||||
<string>wifi name</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="encryptionIcon">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="enterButton">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../../../eink.qrc">
|
||||
<normaloff>:/resources/chevron-right.png</normaloff>:/resources/chevron-right.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources>
|
||||
<include location="../../../eink.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
</ui>
|
|
@ -8,6 +8,7 @@
|
|||
#include "ui_wifidialog.h"
|
||||
#include "functions.h"
|
||||
#include "mainwindow.h"
|
||||
#include "network.h"
|
||||
|
||||
wifiDialog::wifiDialog(QWidget *parent) :
|
||||
QDialog(parent),
|
||||
|
@ -57,22 +58,6 @@ wifiDialog::~wifiDialog()
|
|||
delete ui;
|
||||
}
|
||||
|
||||
void wifiDialog::refreshScreenNative() {
|
||||
emit refreshScreen();
|
||||
}
|
||||
|
||||
void wifiDialog::updateWifiIcon(int mode) {
|
||||
emit updateWifiIconSig(mode);
|
||||
}
|
||||
|
||||
void wifiDialog::showToastNative(QString messageToDisplay) {
|
||||
emit showToast(messageToDisplay);
|
||||
}
|
||||
|
||||
void wifiDialog::closeIndefiniteToastNative() {
|
||||
emit closeIndefiniteToast();
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
this->hide();
|
||||
|
@ -168,3 +153,112 @@ void wifiDialog::closeIndefiniteToastNative() {
|
|||
}
|
||||
}
|
||||
*/
|
||||
|
||||
void wifiDialog::on_refreshBtn_clicked()
|
||||
{
|
||||
if(checkWifiState() == global::wifi::WifiState::Disabled) {
|
||||
emit showToast("To scan, turn on wi-fi first");
|
||||
log("To scan, turn on wi-fi first", className);
|
||||
}
|
||||
else {
|
||||
if(launchRefresh() == true) {
|
||||
refreshNetworksList();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool wifiDialog::launchRefresh() {
|
||||
QFile fullList = QFile("/external_root/run/wifi_list_full");
|
||||
QFile formattedList = QFile("/external_root/run/wifi_list_format");
|
||||
fullList.remove();
|
||||
formattedList.remove();
|
||||
string_writeconfig("/opt/ibxd", "list_wifi_networks\n");
|
||||
QElapsedTimer elapsedTime;
|
||||
elapsedTime.start();
|
||||
bool continueLoop = true;
|
||||
while(fullList.exists() == false and formattedList.exists() == false and continueLoop == true) {
|
||||
sleep(1);
|
||||
if(elapsedTime.elapsed() > 6000) {
|
||||
log("Searching for networks took too long");
|
||||
continueLoop = false;
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
void wifiDialog::refreshNetworksList() {
|
||||
emit killNetworkWidgets();
|
||||
QStringList networkList = readFile("/external_root/run/wifi_list_format").split("%%==SPLIT==%%\n");
|
||||
QVector<global::wifi::wifiNetworkData> pureNetworkList;
|
||||
for(QString network: networkList) {
|
||||
QStringList data = network.split("\n");
|
||||
int count = 1;
|
||||
global::wifi::wifiNetworkData singleNetwork;
|
||||
if(data.count() < 4) {
|
||||
log("Data lines count is below 4, skipping");
|
||||
continue;
|
||||
}
|
||||
for(QString singleData: data) {
|
||||
if(count == 1) {
|
||||
singleNetwork.mac = singleData;
|
||||
log("Mac is: " + singleData, className);
|
||||
}
|
||||
if(count == 2) {
|
||||
log("wifi name is: " + singleData, className);
|
||||
if(singleData.isEmpty() == true) {
|
||||
log("Wifi name is empty", className);
|
||||
}
|
||||
singleNetwork.name = singleData;
|
||||
}
|
||||
if(count == 3) {
|
||||
log("encryption is: " + singleData, className);
|
||||
singleNetwork.encryption = QVariant(singleData).toBool();
|
||||
}
|
||||
if(count == 4) {
|
||||
log("signal strength is: " + singleData, className);
|
||||
singleNetwork.signal = QVariant(singleData).toInt();
|
||||
}
|
||||
if(count >= 5) {
|
||||
log("Skipping additionall items in wifi", className);
|
||||
}
|
||||
count = count + 1;
|
||||
}
|
||||
pureNetworkList.append(singleNetwork);
|
||||
}
|
||||
log("found valid networks: " + QString::number(pureNetworkList.count()));
|
||||
QFile currentWifiNameFile = QFile("/external_root/run/current_wifi_name");
|
||||
currentWifiNameFile.remove();
|
||||
string_writeconfig("/opt/ibxd", "get_current_wifi_name\n");
|
||||
usleep(300000); // 0.3s
|
||||
// Here its looking for the now connected network to put it on top
|
||||
QString currentNetwork = "";
|
||||
if(currentWifiNameFile.exists() == true) {
|
||||
QString currentWifiNetwork = readFile(currentWifiNameFile.fileName());
|
||||
currentWifiNetwork = currentWifiNetwork.replace("\n", "");
|
||||
log("current network name is: " + currentWifiNetwork, className);
|
||||
int countVec = 0;
|
||||
int vectorNetworkLocation = 9999;
|
||||
for(global::wifi::wifiNetworkData wifiNetwork: pureNetworkList) {
|
||||
if(wifiNetwork.name.contains(currentWifiNetwork) == true) {
|
||||
log("Found current network in vector", className);
|
||||
vectorNetworkLocation = countVec;
|
||||
currentNetwork = wifiNetwork.name;
|
||||
network* connectedNetwork = new network;
|
||||
connectedNetwork->mainData = wifiNetwork;
|
||||
connectedNetwork->currentlyConnectedNetwork = currentNetwork;
|
||||
// this doesnt work so a layout is needed
|
||||
// ui->scrollArea->addScrollBarWidget(connectedNetwork, Qt::AlignTop);
|
||||
ui->scrollBarLayout->addWidget(connectedNetwork, Qt::AlignTop);
|
||||
}
|
||||
countVec = countVec + 1;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -22,17 +22,19 @@ public:
|
|||
private:
|
||||
Ui::wifiDialog *ui;
|
||||
|
||||
public slots:
|
||||
bool launchRefresh();
|
||||
void refreshNetworksList();
|
||||
|
||||
signals:
|
||||
void refreshScreen();
|
||||
void updateWifiIconSig(int mode);
|
||||
void showToast(QString messageToDisplay);
|
||||
void closeIndefiniteToast();
|
||||
|
||||
void killNetworkWidgets();
|
||||
|
||||
private slots:
|
||||
void refreshScreenNative();
|
||||
void updateWifiIcon(int mode);
|
||||
void showToastNative(QString messageToDisplay);
|
||||
void closeIndefiniteToastNative();
|
||||
void on_refreshBtn_clicked();
|
||||
};
|
||||
|
||||
#endif // WIFIDIALOG_H
|
||||
|
|
|
@ -131,13 +131,13 @@
|
|||
<item>
|
||||
<widget class="QScrollArea" name="scrollArea">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::Box</enum>
|
||||
<enum>QFrame::NoFrame</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Plain</enum>
|
||||
</property>
|
||||
<property name="lineWidth">
|
||||
<number>3</number>
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="horizontalScrollBarPolicy">
|
||||
<enum>Qt::ScrollBarAlwaysOff</enum>
|
||||
|
@ -150,11 +150,15 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>759</width>
|
||||
<height>570</height>
|
||||
<width>765</width>
|
||||
<height>576</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2"/>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="scrollBarLayout"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
|
|
Loading…
Reference in a new issue