This commit is contained in:
Szybet 2022-08-19 21:35:39 +02:00
parent 2acd7adf1f
commit e310544fb5
11 changed files with 271 additions and 83 deletions

View file

@ -132,12 +132,12 @@ MainWindow::MainWindow(QWidget *parent)
ui->brightnessBtn->setIcon(QIcon(":/resources/frontlight.png")); ui->brightnessBtn->setIcon(QIcon(":/resources/frontlight.png"));
ui->brightnessBtn->setIconSize(QSize(brightnessIconWidth, brightnessIconHeight)); ui->brightnessBtn->setIconSize(QSize(brightnessIconWidth, brightnessIconHeight));
updateWifiState(); updateWifiAble();
if(global::device::isWifiAble == true) { if(global::device::isWifiAble == true) {
// Start wifi updater // Start wifi updater
QTimer *wifiIconTimer = new QTimer(this); QTimer *wifiIconTimer = new QTimer(this);
wifiIconTimer->setInterval(5000); wifiIconTimer->setInterval(2500);
connect(wifiIconTimer, SIGNAL(timeout()), this, SLOT(updateWifiState())); connect(wifiIconTimer, SIGNAL(timeout()), this, SLOT(updateWifiIcon()));
wifiIconTimer->start(); wifiIconTimer->start();
} }
setBatteryIcon(); setBatteryIcon();
@ -751,37 +751,84 @@ void MainWindow::setupSearchDialog() {
} }
} }
void MainWindow::updateWifiIcon(global::wifi::WifiState mode) { void MainWindow::updateWifiIcon() {
/* Usage: /* Usage:
* mode 0 is handled in mainwindow() * Mode 0 (looping it) is handled in mainwindow()
*/ */
if(mode == global::wifi::WifiState::Disabled) {
global::wifi::WifiState currentWifiState = checkWifiState();
// Its executing only in Enabled mode, which is a mode between connected and disabled so don't worry about performance
if(isConnecting == false and isReconecting == false) {
if(currentWifiState == global::wifi::WifiState::Enabled) {
if(checkProcessName("connection_manager.sh") == true) {
isConnecting = true;
}
else if(checkProcessName("connect_to_network.sh") == true){
isConnecting = true;
isReconecting = true;
}
}
}
if(lastWifiState != currentWifiState) {
if(currentWifiState == global::wifi::WifiState::Disabled) {
if(isConnecting == true) {
setDefaultWorkDir();
if(checkconfig(".config/17-wifi_connection_information/stopped") == false) {
QString wifiName = readFile(".config/17-wifi_connection_information/essid").replace("\n", "");
if(isReconecting == true) {
showToast("Failed to reconnect to " + wifiName);
isReconecting = false;
}
else {
showToast("Failed to connect to " + wifiName);
}
isConnecting = false;
QFile(".config/17-wifi_connection_information/essid").remove();
QFile(".config/17-wifi_connection_information/passphrase").remove();
}
else {
QFile(".config/17-wifi_connection_information/stopped").remove();
}
}
lastWifiState = global::wifi::WifiState::Disabled; lastWifiState = global::wifi::WifiState::Disabled;
ui->wifiBtn->setIcon(QIcon(":/resources/wifi-off.png")); ui->wifiBtn->setIcon(QIcon(":/resources/wifi-off.png"));
ui->wifiBtn->setIconSize(QSize(wifiIconWidth, wifiIconHeight)); ui->wifiBtn->setIconSize(QSize(wifiIconWidth, wifiIconHeight));
} }
if(mode == global::wifi::WifiState::Enabled) { if(currentWifiState == global::wifi::WifiState::Enabled) {
lastWifiState = global::wifi::WifiState::Enabled; lastWifiState = global::wifi::WifiState::Enabled;
ui->wifiBtn->setIcon(QIcon(":/resources/wifi-standby.png")); ui->wifiBtn->setIcon(QIcon(":/resources/wifi-standby.png"));
ui->wifiBtn->setIconSize(QSize(wifiIconWidth, wifiIconHeight)); ui->wifiBtn->setIconSize(QSize(wifiIconWidth, wifiIconHeight));
} }
if(mode == global::wifi::WifiState::Configured) { if(currentWifiState == global::wifi::WifiState::Configured) {
if(isConnecting == true) {
setDefaultWorkDir();
QString wifiName = readFile(".config/17-wifi_connection_information/essid").replace("\n", "");
if(isReconecting == true) {
showToast("Reconnected successfully to " + wifiName);
isReconecting = false;
}
else {
showToast("Connected successfully to " + wifiName);
}
isConnecting = false;
QFile(".config/17-wifi_connection_information/essid").remove();
QFile(".config/17-wifi_connection_information/passphrase").remove();
QFile(".config/17-wifi_connection_information/stopped").remove();
}
lastWifiState = global::wifi::WifiState::Configured; lastWifiState = global::wifi::WifiState::Configured;
ui->wifiBtn->setIcon(QIcon(":/resources/wifi-connected.png")); ui->wifiBtn->setIcon(QIcon(":/resources/wifi-connected.png"));
ui->wifiBtn->setIconSize(QSize(wifiIconWidth, wifiIconHeight)); ui->wifiBtn->setIconSize(QSize(wifiIconWidth, wifiIconHeight));
} }
} }
void MainWindow::updateWifiState() {
if(global::device::isWifiAble == true) {
global::wifi::WifiState currentWifiState = checkWifiState();
if(lastWifiState != currentWifiState) {
// This is handled by updateWifiIcon()
//lastWifiState = currentWifiState;
updateWifiIcon(currentWifiState);
} }
}
else { void MainWindow::updateWifiAble() {
if(global::device::isWifiAble == false) {
ui->wifiBtn->hide(); ui->wifiBtn->hide();
ui->line_9->hide(); ui->line_9->hide();
} }
@ -798,13 +845,13 @@ void MainWindow::showToast(QString messageToDisplay) {
global::toast::message = messageToDisplay; global::toast::message = messageToDisplay;
toastWindow = new toast(this); toastWindow = new toast(this);
toastWindow->setAttribute(Qt::WA_DeleteOnClose); toastWindow->setAttribute(Qt::WA_DeleteOnClose);
connect(toastWindow, SIGNAL(updateWifiIconSig(int)), SLOT(updateWifiIcon(int)));
connect(toastWindow, SIGNAL(refreshScreen()), SLOT(refreshScreen())); connect(toastWindow, SIGNAL(refreshScreen()), SLOT(refreshScreen()));
connect(toastWindow, SIGNAL(showToast(QString)), SLOT(showToast(QString))); connect(toastWindow, SIGNAL(showToast(QString)), SLOT(showToast(QString)));
connect(toastWindow, SIGNAL(closeIndefiniteToast()), SLOT(closeIndefiniteToast())); connect(toastWindow, SIGNAL(closeIndefiniteToast()), SLOT(closeIndefiniteToast()));
toastWindow->show(); toastWindow->show();
if(messageToDisplay == "Connection successful") { // I will soon manage the update thing in a more propper way somewhere else... ~ Szybet
if(messageToDisplay.contains("onnected successfully") == true) {
// Give the toast some time to vanish away, then launch OTA updater // Give the toast some time to vanish away, then launch OTA updater
QTimer::singleShot(5000, this, SLOT(launchOtaUpdater())); QTimer::singleShot(5000, this, SLOT(launchOtaUpdater()));
} }

View file

@ -51,7 +51,11 @@ public:
bool existing_recent_books = false; bool existing_recent_books = false;
bool reboot_after_update = false; bool reboot_after_update = false;
bool resetFullWindowException; bool resetFullWindowException;
global::wifi::WifiState lastWifiState = global::wifi::WifiState::Unknown; global::wifi::WifiState lastWifiState = global::wifi::WifiState::Unknown;
bool isConnecting = false;
bool isReconecting = false;
int timerTime = 0; int timerTime = 0;
QString relative_path; QString relative_path;
QString usbmsStatus; QString usbmsStatus;
@ -78,9 +82,9 @@ private slots:
void on_homeBtn_clicked(); void on_homeBtn_clicked();
void refreshScreen(); void refreshScreen();
void setupSearchDialog(); void setupSearchDialog();
void updateWifiState(); void updateWifiAble();
void on_wifiBtn_clicked(); void on_wifiBtn_clicked();
void updateWifiIcon(global::wifi::WifiState mode); void updateWifiIcon();
void hello(int testNumber); void hello(int testNumber);
void openUpdateDialogOTA(bool open); void openUpdateDialogOTA(bool open);
void launchOtaUpdater(); void launchOtaUpdater();

View file

@ -65,7 +65,7 @@ void connectiondialog::applyVariables() {
if(password.isEmpty() == false) { if(password.isEmpty() == false) {
log("found password: " + password, className); log("found password: " + password, className);
ui->showPasswordBtn->setIcon(QIcon("://resources/show.png")); ui->showPasswordBtn->setIcon(QIcon("://resources/show.png"));
showedPasword = false; showedPassword = false;
savedPassword = password; savedPassword = password;
ui->passwordTextEdit->setText("********"); ui->passwordTextEdit->setText("********");
@ -189,10 +189,10 @@ void connectiondialog::on_passwordTextEdit_selectionChanged()
void connectiondialog::on_passwordTextEdit_cursorPositionChanged(int oldpos, int newpos) void connectiondialog::on_passwordTextEdit_cursorPositionChanged(int oldpos, int newpos)
{ {
log("detected click on text edit", className); log("Detected click on text edit", className);
if(cursorPositionIgnore == true) { if(cursorPositionIgnore == true) {
if(newpos != 0) { if(newpos != 0) {
if(showedPasword == true) { if(showedPassword == true) {
ui->passwordTextEdit->setCursorPosition(0); ui->passwordTextEdit->setCursorPosition(0);
global::keyboard::keyboardDialog = true; global::keyboard::keyboardDialog = true;
global::keyboard::wifiPassphraseDialog = true; global::keyboard::wifiPassphraseDialog = true;
@ -208,12 +208,12 @@ void connectiondialog::on_passwordTextEdit_cursorPositionChanged(int oldpos, int
global::keyboard::keyboardDialog = false; global::keyboard::keyboardDialog = false;
global::keyboard::wifiPassphraseDialog = false; global::keyboard::wifiPassphraseDialog = false;
if(global::keyboard::keyboardText.isEmpty() == false) { if(global::keyboard::keyboardText.isEmpty() == false) {
// A bit hacky: avoid summoning the keyboard back when the text is changing ( and the cursor too ) showedPasword shouldnt be used for this, but it works and adding another bool would start being messy // A bit hacky: avoid summoning the keyboard back when the text is changing ( and the cursor too ) showedPassword shouldnt be used for this, but it works and adding another bool would start being messy
showedPasword = false; showedPassword = false;
ui->passwordTextEdit->setText(global::keyboard::keyboardText); ui->passwordTextEdit->setText(global::keyboard::keyboardText);
ui->showPasswordBtn->setIcon(QIcon("://resources/hide.png")); ui->showPasswordBtn->setIcon(QIcon("://resources/hide.png"));
ui->showPasswordBtn->show(); ui->showPasswordBtn->show();
showedPasword = true; showedPassword = true;
savedPassword = global::keyboard::keyboardText; savedPassword = global::keyboard::keyboardText;
} }
global::keyboard::keyboardText = ""; global::keyboard::keyboardText = "";
@ -232,13 +232,13 @@ void connectiondialog::showToastSlot(QString message) {
void connectiondialog::on_showPasswordBtn_clicked() void connectiondialog::on_showPasswordBtn_clicked()
{ {
if(showedPasword == false) { if(showedPassword == false) {
ui->showPasswordBtn->setIcon(QIcon("://resources/hide.png")); ui->showPasswordBtn->setIcon(QIcon("://resources/hide.png"));
ui->passwordTextEdit->setText(savedPassword); ui->passwordTextEdit->setText(savedPassword);
showedPasword = true; showedPassword = true;
} }
else { else {
showedPasword = false; showedPassword = false;
ui->showPasswordBtn->setIcon(QIcon("://resources/show.png")); ui->showPasswordBtn->setIcon(QIcon("://resources/show.png"));
ui->passwordTextEdit->setText("********"); ui->passwordTextEdit->setText("********");
} }
@ -267,7 +267,7 @@ void connectiondialog::on_connectBtn_clicked()
string_writeconfig("/run/wifi_network_essid", connectedNetworkData.name.toStdString()); string_writeconfig("/run/wifi_network_essid", connectedNetworkData.name.toStdString());
string_writeconfig("/run/wifi_network_passphrase", finalPassword.toStdString()); string_writeconfig("/run/wifi_network_passphrase", finalPassword.toStdString());
setDefaultWorkDir(); setDefaultWorkDir();
// this will be deleited later in mainwindow icon updater if it failed // This will be deleited later in mainwindow icon updater if it failed
string_writeconfig(".config/17-wifi_connection_information/essid", connectedNetworkData.name.toStdString()); string_writeconfig(".config/17-wifi_connection_information/essid", connectedNetworkData.name.toStdString());
string_writeconfig(".config/17-wifi_connection_information/passphrase", finalPassword.toStdString()); string_writeconfig(".config/17-wifi_connection_information/passphrase", finalPassword.toStdString());
finalConnectWait(); finalConnectWait();

View file

@ -31,8 +31,8 @@ public slots:
private slots: private slots:
// I know im opening / loading json many times, its maybe not efficient but: // I know im opening / loading json many times, its maybe not efficient but:
// 1. its modular // 1. Its modular
// 2. those operations are rare // 2. Those operations are rare
QString searchDatabase(QString key); QString searchDatabase(QString key);
void writeToDatabase(QString name, QString password); void writeToDatabase(QString name, QString password);
void removeFromDatabase(QString name); void removeFromDatabase(QString name);
@ -54,7 +54,7 @@ private slots:
private: private:
Ui::connectiondialog *ui; Ui::connectiondialog *ui;
bool cursorPositionIgnore = false; bool cursorPositionIgnore = false;
bool showedPasword; bool showedPassword;
QString savedPassword; QString savedPassword;
int waitTry = 0; int waitTry = 0;
}; };

View file

@ -29,9 +29,10 @@ network::~network()
} }
void network::applyVariables() { void network::applyVariables() {
log("Applying variables for network", className);
ui->signalStrengthLabel->setText(QString::number(mainData.signal) + "%"); ui->signalStrengthLabel->setText(QString::number(mainData.signal) + "%");
// limit name size, maybe device specific // Limit name size, maybe device specific
QString cuttedSingleData = mainData.name; QString cuttedSingleData = mainData.name;
if(cuttedSingleData.count() > 27) if(cuttedSingleData.count() > 27)
{ {

View file

@ -61,8 +61,13 @@ wifiDialog::wifiDialog(QWidget *parent) :
global::wifi::WifiState currentWifiState = checkWifiState(); global::wifi::WifiState currentWifiState = checkWifiState();
if(currentWifiState != global::wifi::WifiState::Disabled and currentWifiState != global::wifi::WifiState::Unknown) { if(currentWifiState != global::wifi::WifiState::Disabled and currentWifiState != global::wifi::WifiState::Unknown) {
ui->Wificheckbox->setChecked(true); ui->Wificheckbox->setChecked(true);
// To be sure nothing breaks
refreshFromWatcher = true;
ui->refreshBtn->click();
} else { } else {
wifiButtonEnabled = true; wifiButtonEnabled = true;
ui->stopBtn->setStyleSheet("background-color:grey;");
ui->stopBtn->setEnabled(false);
} }
QTimer::singleShot(relaunchMs, this, SLOT(theWatcher())); QTimer::singleShot(relaunchMs, this, SLOT(theWatcher()));
@ -173,16 +178,22 @@ void wifiDialog::on_refreshBtn_clicked()
{ {
log("Clicked refresh button", className); log("Clicked refresh button", className);
if(checkWifiState() == global::wifi::WifiState::Disabled) { if(checkWifiState() == global::wifi::WifiState::Disabled) {
if(refreshFromWatcher == true) {
refreshFromWatcher = false;
emit showToast("To scan, turn on wi-fi first"); emit showToast("To scan, turn on wi-fi first");
log("To scan, turn on wi-fi first", className); log("To scan, turn on wi-fi first", className);
} }
}
else { else {
refreshFromWatcher = false;
launchRefresh(); launchRefresh();
} }
} }
void wifiDialog::launchRefresh() { void wifiDialog::launchRefresh() {
// Order is important // Order is important
if(scanInProgress == false) {
scanInProgress = true;
ui->refreshBtn->setStyleSheet("background-color:grey;"); ui->refreshBtn->setStyleSheet("background-color:grey;");
ui->refreshBtn->setEnabled(false); ui->refreshBtn->setEnabled(false);
@ -192,12 +203,16 @@ void wifiDialog::launchRefresh() {
string_writeconfig("/opt/ibxd", "list_wifi_networks\n"); string_writeconfig("/opt/ibxd", "list_wifi_networks\n");
QTimer::singleShot(0, this, SLOT(refreshWait())); QTimer::singleShot(0, this, SLOT(refreshWait()));
} }
}
void wifiDialog::refreshWait() { void wifiDialog::refreshWait() {
if(fullList.exists() == false and formattedList.exists() == false) { if(fullList.exists() == false and formattedList.exists() == false) {
if(elapsedSeconds == 6) { if(elapsedSeconds == 6) {
emit showToast("Failed to get network list"); emit showToast("Failed to get network list");
log("Failed to get network list", className); log("Failed to get network list", className);
ui->refreshBtn->setStyleSheet("background-color:white;");
ui->refreshBtn->setEnabled(true);
scanInProgress = false;
} }
else { else {
elapsedSeconds = elapsedSeconds + 1; elapsedSeconds = elapsedSeconds + 1;
@ -252,6 +267,14 @@ void wifiDialog::refreshNetworksList() {
} }
} }
log("found valid networks: " + QString::number(pureNetworkList.count()), className); log("found valid networks: " + QString::number(pureNetworkList.count()), className);
if(pureNetworkList.count() == 0) {
log("No networks found, skipping", className);
showToastSlot("No networks found");
ui->refreshBtn->setEnabled(true);
ui->refreshBtn->setStyleSheet("background-color:white;");
scanInProgress = false;
return void();
}
QFile currentWifiNameFile = QFile("/external_root/run/current_wifi_name"); QFile currentWifiNameFile = QFile("/external_root/run/current_wifi_name");
currentWifiNameFile.remove(); currentWifiNameFile.remove();
string_writeconfig("/opt/ibxd", "get_current_wifi_name\n"); string_writeconfig("/opt/ibxd", "get_current_wifi_name\n");
@ -269,23 +292,30 @@ void wifiDialog::refreshNetworksList() {
log("Found current network in vector", className); log("Found current network in vector", className);
vectorNetworkLocation = countVec; vectorNetworkLocation = countVec;
currentNetwork = wifiNetwork.name; currentNetwork = wifiNetwork.name;
log("Test", className);
network* connectedNetwork = new network; network* connectedNetwork = new network;
connectedNetwork->mainData = wifiNetwork; connectedNetwork->mainData = wifiNetwork;
// to be really sure that the the info is put there log("Test", className);
// To be really sure that the the info is put there
connectedNetwork->currentlyConnectedNetwork = currentNetwork; connectedNetwork->currentlyConnectedNetwork = currentNetwork;
log("Test", className);
connectedNetworkDataParent = wifiNetwork; connectedNetworkDataParent = wifiNetwork;
wifiLoggerDialog->connectedNetworkData = connectedNetworkDataParent; connectedNetworkDataParentSetted = true;
log("Test", className);
// this doesnt work so a layout is needed // This doesnt work so a layout is needed
// ui->scrollArea->addScrollBarWidget(connectedNetwork, Qt::AlignTop); // ui->scrollArea->addScrollBarWidget(connectedNetwork, Qt::AlignTop);
connectedNetwork->applyVariables(); connectedNetwork->applyVariables();
log("Test", className);
connect(this, &wifiDialog::killNetworkWidgets, connectedNetwork, &network::closeWrapper); connect(this, &wifiDialog::killNetworkWidgets, connectedNetwork, &network::closeWrapper);
connect(connectedNetwork, &network::showToastSignal, this, &wifiDialog::showToastSlot); connect(connectedNetwork, &network::showToastSignal, this, &wifiDialog::showToastSlot);
connect(connectedNetwork, &network::refreshScreenSignal, this, &wifiDialog::refreshScreenSlot); connect(connectedNetwork, &network::refreshScreenSignal, this, &wifiDialog::refreshScreenSlot);
ui->scrollBarLayout->addWidget(connectedNetwork, Qt::AlignTop); ui->scrollBarLayout->addWidget(connectedNetwork, Qt::AlignTop);
} }
else {
countVec = countVec + 1; countVec = countVec + 1;
} }
}
if(vectorNetworkLocation != 9999) { if(vectorNetworkLocation != 9999) {
log("pureNetworkList size is: " + QString::number(pureNetworkList.count()) + " And i want to remove at: " + QString::number(vectorNetworkLocation), className); log("pureNetworkList size is: " + QString::number(pureNetworkList.count()) + " And i want to remove at: " + QString::number(vectorNetworkLocation), className);
pureNetworkList.removeAt(vectorNetworkLocation); pureNetworkList.removeAt(vectorNetworkLocation);
@ -312,7 +342,7 @@ void wifiDialog::refreshNetworksList() {
counter = counter + 1; counter = counter + 1;
} }
} }
// this happens if its the smallest value, so insert it at the end // This happens if its the smallest value, so insert it at the end
if(stopIterating == false) { if(stopIterating == false) {
sortedPureNetworkList.append(wifiNetwork); sortedPureNetworkList.append(wifiNetwork);
} }
@ -338,19 +368,27 @@ void wifiDialog::refreshNetworksList() {
scannedAtLeastOnce = true; scannedAtLeastOnce = true;
ui->refreshBtn->setEnabled(true); ui->refreshBtn->setEnabled(true);
ui->refreshBtn->setStyleSheet("background-color:white;"); ui->refreshBtn->setStyleSheet("background-color:white;");
scanInProgress = false;
} }
void wifiDialog::on_Wificheckbox_stateChanged(int arg1) void wifiDialog::on_Wificheckbox_stateChanged(int arg1)
{ {
connectedNetworkDataParentSetted = false;
log("wifi dialog clicked: " + QString::number(arg1), className); log("wifi dialog clicked: " + QString::number(arg1), className);
if(wifiButtonEnabled == true) { if(wifiButtonEnabled == true) {
if(arg1 == 2) { if(arg1 == 2) {
log("turning wifi on", className); log("turning wifi on", className);
// the watcher will scan wifi
forceRefresh = true;
QTimer::singleShot(0, this, SLOT(turnOnWifi())); QTimer::singleShot(0, this, SLOT(turnOnWifi()));
ui->stopBtn->setStyleSheet("background-color:white;");
ui->stopBtn->setEnabled(true);
} else { } else {
log("turning wifi off", className); log("turning wifi off", className);
QTimer::singleShot(0, this, SLOT(turnOffWifi())); QTimer::singleShot(0, this, SLOT(turnOffWifi()));
ui->stopBtn->setStyleSheet("background-color:grey;");
ui->stopBtn->setEnabled(false);
} }
emit killNetworkWidgets(); emit killNetworkWidgets();
} }
@ -375,10 +413,13 @@ void wifiDialog::on_logBtn_clicked()
log("Scanning at least once is needed"); log("Scanning at least once is needed");
emit showToast("Scan at least once"); emit showToast("Scan at least once");
} else { } else {
wifilogger* wifiLoggerDialog = new wifilogger;
if(connectedNetworkDataParentSetted == true) {
wifiLoggerDialog->connectedNetworkData = connectedNetworkDataParent; wifiLoggerDialog->connectedNetworkData = connectedNetworkDataParent;
wifiLoggerDialog->isThereData = true;
}
wifiLoggerDialog->exec(); wifiLoggerDialog->exec();
} }
} }
void wifiDialog::showToastSlot(QString message) { void wifiDialog::showToastSlot(QString message) {
@ -391,14 +432,14 @@ void wifiDialog::refreshScreenSlot() {
/* /*
Some documentation used by the watcher Some documentation used by the watcher
connection_manager.sh - manages all things, launches other processes connection_manager.sh - Manages all things, launches other processes
connect_to_network.sh - all in one connection manager. manages everything, used by ipd, should be used for recconections after sleeping / booting connect_to_network.sh - All in one connection manager. manages everything, used by ipd, should be used for recconections after sleeping / booting
get_dhcp.sh - Gets dhcp addresses get_dhcp.sh - Gets dhcp addresses
prepare_changing_wifi.sh - Kills everything, prepares to changing network prepare_changing_wifi.sh - Kills everything, prepares to changing network
smarter_time_sync.sh - synces time smarter_time_sync.sh - Synces time
toggle.sh - turns on / off toggle.sh - Turns on / off
list_networks.bin - well lists networks list_networks.bin - Well lists networks
the watcher first watches at processes that could kill other ones theWatcher() first watches at processes that could kill other ones
*/ */
void wifiDialog::theWatcher() { void wifiDialog::theWatcher() {
@ -407,12 +448,14 @@ void wifiDialog::theWatcher() {
bool changing = checkProcessName("prepare_changing_wifi.sh"); bool changing = checkProcessName("prepare_changing_wifi.sh");
if(killing == true) { if(killing == true) {
setStatusText("Changing wifi state"); setStatusText("Changing wifi state");
log("toggle.sh is active", className);
QTimer::singleShot(relaunchMs, this, SLOT(theWatcher())); QTimer::singleShot(relaunchMs, this, SLOT(theWatcher()));
return void(); return void();
} }
if(changing == true) { if(changing == true) {
setStatusText("Disconnecting from a network or cleaning"); setStatusText("Disconnecting from a network or cleaning");
log("prepare_changing_wifi.sh is active", className);
forceRefresh = true; forceRefresh = true;
QTimer::singleShot(relaunchMs, this, SLOT(theWatcher())); QTimer::singleShot(relaunchMs, this, SLOT(theWatcher()));
return void(); return void();
@ -456,7 +499,7 @@ void wifiDialog::theWatcher() {
return void(); return void();
} }
bool connecting = checkProcessName("connect_to_network.sh"); bool connecting = checkProcessName("connection_manager.sh");
if(connecting == true) { if(connecting == true) {
forceRefresh = true; forceRefresh = true;
setStatusText("Connecting to wifi..."); setStatusText("Connecting to wifi...");
@ -464,11 +507,21 @@ void wifiDialog::theWatcher() {
return void(); return void();
} }
if(ui->statusLabel->text() != "Idling") {
setStatusText("Idling"); setStatusText("Idling");
}
if(forceRefresh == true) { if(forceRefresh == true) {
forceRefresh = false; forceRefresh = false;
refreshFromWatcher = true;
ui->refreshBtn->click(); ui->refreshBtn->click();
} }
if(unlockCheckbox == true) {
ui->Wificheckbox->setEnabled(true);
unlockCheckbox = false;
}
QTimer::singleShot(relaunchMs, this, SLOT(theWatcher())); QTimer::singleShot(relaunchMs, this, SLOT(theWatcher()));
} }
@ -478,6 +531,27 @@ void wifiDialog::setStatusText(QString message) {
void wifiDialog::on_stopBtn_clicked() void wifiDialog::on_stopBtn_clicked()
{ {
connectedNetworkDataParentSetted = false;
ui->Wificheckbox->setEnabled(false);
unlockCheckbox = true;
// To inform the wifi icon GUI to don't show the connected / failed to connect message
string_writeconfig(".config/17-wifi_connection_information/stopped", "true");
// Maybe limit this, idk // Maybe limit this, idk
string_writeconfig("/opt/ibxd", "stop_wifi_operations\n"); string_writeconfig("/opt/ibxd", "stop_wifi_operations\n");
setDefaultWorkDir();
QFile(".config/17-wifi_connection_information/essid").remove();
QFile(".config/17-wifi_connection_information/passphrase").remove();
// This variable just avoids showing the toast so i can use it here too...
refreshFromWatcher = true;
ui->refreshBtn->click();
}
void wifiDialog::on_returnBtn_clicked()
{
this->deleteLater();
this->close();
} }

View file

@ -20,15 +20,15 @@ public:
explicit wifiDialog(QWidget *parent = nullptr); explicit wifiDialog(QWidget *parent = nullptr);
~wifiDialog(); ~wifiDialog();
global::wifi::wifiNetworkData connectedNetworkDataParent; global::wifi::wifiNetworkData connectedNetworkDataParent;
wifilogger* wifiLoggerDialog = new wifilogger; // well dont touch this until there is something, *** Error in `/tmp/exec': double free or corruption (fasttop): 0x025ed170 ***
bool connectedNetworkDataParentSetted = false;
private: private:
Ui::wifiDialog *ui; Ui::wifiDialog *ui;
bool wifiButtonEnabled = false; bool wifiButtonEnabled = false;
bool scannedAtLeastOnce = false; bool scannedAtLeastOnce = false;
// variables for refreshWait() and network refresh in general // Variables for refreshWait() and network refresh in general
int elapsedSeconds = 0; int elapsedSeconds = 0;
QFile fullList = QFile("/external_root/run/wifi_list_full"); QFile fullList = QFile("/external_root/run/wifi_list_full");
QFile formattedList = QFile("/external_root/run/wifi_list_format"); QFile formattedList = QFile("/external_root/run/wifi_list_format");
@ -36,6 +36,9 @@ private:
// Used by watcher // Used by watcher
bool forceRefresh = false; bool forceRefresh = false;
int relaunchMs = 300; int relaunchMs = 300;
bool refreshFromWatcher = false;
bool unlockCheckbox = false;
bool scanInProgress = false;
public slots: public slots:
void launchRefresh(); void launchRefresh();
@ -63,6 +66,7 @@ private slots:
void refreshWait(); void refreshWait();
void setStatusText(QString message); void setStatusText(QString message);
void on_stopBtn_clicked(); void on_stopBtn_clicked();
void on_returnBtn_clicked();
}; };
#endif // WIFIDIALOG_H #endif // WIFIDIALOG_H

View file

@ -47,6 +47,22 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item> <item>
<widget class="QPushButton" name="stopBtn"> <widget class="QPushButton" name="stopBtn">
<property name="sizePolicy"> <property name="sizePolicy">
@ -60,6 +76,22 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item> <item>
<widget class="QPushButton" name="refreshBtn"> <widget class="QPushButton" name="refreshBtn">
<property name="text"> <property name="text">

View file

@ -18,6 +18,7 @@ wifilogger::wifilogger(QWidget *parent) :
this->setModal(true); this->setModal(true);
log("Entered wifilogger", className);
setWifiInfoPage(); setWifiInfoPage();
ui->refreshBtn->setProperty("type", "borderless"); ui->refreshBtn->setProperty("type", "borderless");
@ -91,14 +92,25 @@ void wifilogger::changePage() {
} }
void wifilogger::getWifiInformations() { void wifilogger::getWifiInformations() {
log("getting wifi informations", className);
QFile wifiInformationsPath = QFile("/external_root/run/wifi_informations"); QFile wifiInformationsPath = QFile("/external_root/run/wifi_informations");
if(waitingForFile == false) {
wifiInformationsPath.remove(); wifiInformationsPath.remove();
log("Launching get_wifi_informations ibxd call", className);
string_writeconfig("/opt/ibxd", "get_wifi_informations\n"); string_writeconfig("/opt/ibxd", "get_wifi_informations\n");
while(wifiInformationsPath.exists() == false) { waitingForFile = true;
sleep(1);
} }
if(waitingForFile == true) {
if(wifiInformationsPath.exists() == false) {
QTimer::singleShot(1000, this, SLOT(getWifiInformations()));
return void();
}
}
waitingForFile = false;
log("Setting variables", className);
QString wifiInfo = readFile(wifiInformationsPath.fileName()); QString wifiInfo = readFile(wifiInformationsPath.fileName());
QStringList wifiInfoList = wifiInfo.split("\n"); QStringList wifiInfoList = wifiInfo.split("\n");
int counter = 0; int counter = 0;
@ -118,7 +130,7 @@ void wifilogger::getWifiInformations() {
counter = counter + 1; counter = counter + 1;
} }
if(connectedNetworkData.mac.isEmpty() == false) { if(isThereData == true) {
ui->encryptionLabel->setText(QVariant(connectedNetworkData.encryption).toString()); ui->encryptionLabel->setText(QVariant(connectedNetworkData.encryption).toString());
ui->signalLabel->setText(QString::number(connectedNetworkData.signal) + "%"); ui->signalLabel->setText(QString::number(connectedNetworkData.signal) + "%");
@ -138,6 +150,7 @@ void wifilogger::getWifiInformations() {
void wifilogger::on_returnBtn_clicked() void wifilogger::on_returnBtn_clicked()
{ {
log("Exiting wifilogger", className);
this->deleteLater(); this->deleteLater();
this->close(); this->close();
} }
@ -155,8 +168,10 @@ void wifilogger::updateLogs() {
void wifilogger::on_refreshBtn_clicked() void wifilogger::on_refreshBtn_clicked()
{ {
if(currentPage == 0) { if(currentPage == 0) {
if(waitingForFile == false) {
setWifiInfoPage(); setWifiInfoPage();
} }
}
else { else {
updateLogs(); updateLogs();
} }

View file

@ -17,6 +17,8 @@ public:
explicit wifilogger(QWidget *parent = nullptr); explicit wifilogger(QWidget *parent = nullptr);
~wifilogger(); ~wifilogger();
global::wifi::wifiNetworkData connectedNetworkData; global::wifi::wifiNetworkData connectedNetworkData;
// to the above value
bool isThereData = false;
private: private:
Ui::wifilogger *ui; Ui::wifilogger *ui;
@ -28,6 +30,7 @@ private:
int currentPage = 0; int currentPage = 0;
QFile fancyLogs = QFile("/external_root/run/wifi_stats"); QFile fancyLogs = QFile("/external_root/run/wifi_stats");
QFile allLogs = QFile("/external_root/run/wifi_logs"); QFile allLogs = QFile("/external_root/run/wifi_logs");
bool waitingForFile = false;
private slots: private slots:
void setWifiInfoPage(); void setWifiInfoPage();

View file

@ -20,7 +20,7 @@
<number>0</number> <number>0</number>
</property> </property>
<property name="currentIndex"> <property name="currentIndex">
<number>2</number> <number>3</number>
</property> </property>
<widget class="QWidget" name="page_0"> <widget class="QWidget" name="page_0">
<layout class="QVBoxLayout" name="verticalLayout_2"> <layout class="QVBoxLayout" name="verticalLayout_2">
@ -312,14 +312,22 @@
<widget class="QWidget" name="page_1"> <widget class="QWidget" name="page_1">
<layout class="QGridLayout" name="gridLayout_3"> <layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0"> <item row="0" column="0">
<widget class="QTextBrowser" name="fancyLogsText"/> <widget class="QTextBrowser" name="fancyLogsText">
<property name="textInteractionFlags">
<set>Qt::NoTextInteraction</set>
</property>
</widget>
</item> </item>
</layout> </layout>
</widget> </widget>
<widget class="QWidget" name="page_2"> <widget class="QWidget" name="page_2">
<layout class="QGridLayout" name="gridLayout_4"> <layout class="QGridLayout" name="gridLayout_4">
<item row="0" column="0"> <item row="0" column="0">
<widget class="QTextBrowser" name="allLogsText"/> <widget class="QTextBrowser" name="allLogsText">
<property name="textInteractionFlags">
<set>Qt::NoTextInteraction</set>
</property>
</widget>
</item> </item>
</layout> </layout>
</widget> </widget>