Merge pull request #34 from Szybet/master

Complete Wi-Fi framework redesign
This commit is contained in:
Nicolas Mailloux 2022-08-28 17:45:38 -04:00 committed by GitHub
commit d1b3559357
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
40 changed files with 2821 additions and 519 deletions

View file

@ -32,6 +32,9 @@ SOURCES += \
src/apps/calendarapp.cpp \
src/widgets/dialogs/reader/highlightslistdialog.cpp \
src/widgets/dialogs/reader/textdialog.cpp \
src/widgets/dialogs/wifi/connectiondialog.cpp \
src/widgets/dialogs/wifi/network.cpp \
src/widgets/dialogs/wifi/wifilogger.cpp \
src/widgets/reader/dictionarywidget.cpp \
src/encfs/encryptionmanager.cpp \
src/widgets/dialogs/generaldialog.cpp \
@ -54,7 +57,7 @@ SOURCES += \
src/settings/settingschooser.cpp \
src/widgets/text/textwidget.cpp \
src/widgets/interfaceWidgets/toast.cpp \
src/splash/usbms_splash.cpp \
src/splash/usbmsSplash.cpp \
src/apps/userapps.cpp \
src/widgets/virtualKeyboard/virtualkeyboard.cpp \
src/widgets/virtualKeyboard/virtualkeypad.cpp \
@ -72,6 +75,9 @@ HEADERS += \
src/apps/calendarapp.h \
src/widgets/dialogs/reader/highlightslistdialog.h \
src/widgets/dialogs/reader/textdialog.h \
src/widgets/dialogs/wifi/connectiondialog.h \
src/widgets/dialogs/wifi/network.h \
src/widgets/dialogs/wifi/wifilogger.h \
src/widgets/reader/dictionarywidget.h \
src/encfs/encryptionmanager.h \
src/functions.h \
@ -94,7 +100,7 @@ HEADERS += \
src/settings/settingschooser.h \
src/widgets/text/textwidget.h \
src/widgets/interfaceWidgets/toast.h \
src/splash/usbms_splash.h \
src/splash/usbmsSplash.h \
src/apps/userapps.h \
src/widgets/virtualKeyboard/virtualkeyboard.h \
src/widgets/virtualKeyboard/virtualkeypad.h \
@ -112,6 +118,9 @@ FORMS += \
src/apps/calendarapp.ui \
src/widgets/dialogs/reader/highlightslistdialog.ui \
src/widgets/dialogs/reader/textdialog.ui \
src/widgets/dialogs/wifi/connectiondialog.ui \
src/widgets/dialogs/wifi/network.ui \
src/widgets/dialogs/wifi/wifilogger.ui \
src/widgets/reader/dictionarywidget.ui \
src/encfs/encryptionmanager.ui \
src/widgets/dialogs/generaldialog.ui \
@ -131,7 +140,7 @@ FORMS += \
src/settings/settingschooser.ui \
src/widgets/text/textwidget.ui \
src/widgets/interfaceWidgets/toast.ui \
src/splash/usbms_splash.ui \
src/splash/usbmsSplash.ui \
src/apps/userapps.ui \
src/widgets/virtualKeyboard/virtualkeyboard.ui \
src/widgets/virtualKeyboard/virtualkeypad.ui \

View file

@ -185,7 +185,7 @@ bool userapps::manageRequiredFeatures()
if(featureId == 0) {
// Double 'if' conditions to avoid launching unnecesery testPing() in emu
if(global::deviceID != "emu\n") {
if(testPing(true) != 0) {
if(testPing() != 0) {
global::userApps::appCompatibilityText = "<font face='u001'>This app needs a Wi-Fi connection, continue anyway</font><font face='Inter'>?</font>";
launchDialog = true;
}

View file

@ -84,5 +84,19 @@
<file>resources/highlight.png</file>
<file>resources/unhighlight.png</file>
<file>resources/view-highlights.png</file>
<file>resources/stop.png</file>
<file>resources/refresh.png</file>
<file>resources/hide.png</file>
<file>resources/show.png</file>
<file>resources/christie.jpg</file>
<file>resources/encryption-small.png</file>
<file>resources/lock.png</file>
<file>resources/public.png</file>
<file>resources/wifi-0.png</file>
<file>resources/wifi-25.png</file>
<file>resources/wifi-50.png</file>
<file>resources/wifi-75.png</file>
<file>resources/wifi-100.png</file>
<file>resources/log.png</file>
</qresource>
</RCC>

View file

@ -8,7 +8,7 @@
#include <QTimer>
#include <QMessageBox>
#include <QDateTime>
#include "usbms_splash.h"
#include "usbmsSplash.h"
#include "functions.h"
encryptionManager::encryptionManager(QWidget *parent) :
@ -346,7 +346,7 @@ void encryptionManager::on_usbmsBtn_clicked()
{
log("Showing USBMS splash", className);
global::usbms::launchUsbms = true;
usbmsWindow = new usbms_splash();
usbmsWindow = new usbmsSplash();
usbmsWindow->setAttribute(Qt::WA_DeleteOnClose);
usbmsWindow->setGeometry(QRect(QPoint(0,0), screen()->geometry ().size()));
usbmsWindow->show();

View file

@ -48,7 +48,7 @@ private:
toast * toastWindow;
hourglassAnimationWidget * hourglassAnimationWidgetWindow;
alert * alertWindow;
usbms_splash *usbmsWindow;
usbmsSplash *usbmsWindow;
};
#endif // ENCRYPTIONMANAGER_H

View file

@ -92,7 +92,6 @@ namespace global {
}
namespace toast {
inline QString message;
inline bool wifiToast;
inline bool modalToast;
inline bool indefiniteToast;
inline int delay;
@ -100,9 +99,6 @@ namespace global {
namespace device {
inline bool isWifiAble;
}
namespace network {
inline bool isConnected;
}
namespace otaUpdate {
inline bool isUpdateOta;
inline bool downloadOta;
@ -169,6 +165,22 @@ namespace global {
namespace highlightsListDialog {
inline QString bookPath;
}
namespace wifi {
enum class wifiState {
configured,
enabled,
disabled,
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;
inline bool isN705 = false;
@ -780,41 +792,6 @@ namespace {
}
}
}
bool connectToNetwork(QString essid, QString passphrase) {
log("Connecting to network '" + essid + "'", "functions");
std::string essid_str = essid.toStdString();
std::string passphrase_str = passphrase.toStdString();
string_writeconfig("/run/wifi_network_essid", essid_str);
string_writeconfig("/run/wifi_network_passphrase", passphrase_str);
string_writeconfig("/opt/ibxd", "connect_to_wifi_network\n");
int connectionSuccessful = 0;
while(connectionSuccessful == 0) {
if(QFile::exists("/run/wifi_connected_successfully")) {
if(checkconfig("/run/wifi_connected_successfully") == true) {
QFile::remove("/run/wifi_connected_successfully");
connectionSuccessful = 1;
global::network::isConnected = true;
setDefaultWorkDir();
string_writeconfig(".config/17-wifi_connection_information/essid", essid_str);
string_writeconfig(".config/17-wifi_connection_information/passphrase", passphrase_str);
QString function = __func__; log(function + ": Connection successful", "functions");
return true;
}
else {
QFile::remove("/run/wifi_connected_successfully");
connectionSuccessful = 0;
global::network::isConnected = false;
QString function = __func__; log(function + ": Connection failed", "functions");
return false;
}
}
else {
QThread::msleep(100);
}
}
}
int get_warmth() {
QString sysfsWarmthPath;
if(global::deviceID == "n873\n") {
@ -866,51 +843,6 @@ namespace {
return !!ptr;
}
}
int testPing(bool blocking) {
QProcess *pingProcess = new QProcess();
if(blocking == true) {
QString pingProg = "ping";
QStringList pingArgs;
pingArgs << "-c" << "1" << "1.1.1.1";
pingProcess->start(pingProg, pingArgs);
pingProcess->waitForFinished();
int exitCode = pingProcess->exitCode();
pingProcess->deleteLater();
if(exitCode == 0) {
global::network::isConnected = true;
}
else {
global::network::isConnected = false;
}
return exitCode;
}
/* For some reason, implementing a non-blocking version of this functions triggers a "terminate called without an active exception" error with a platform plugin compiled with a newer GCC 11 toolchain. The problem has been solved by transplanting this function into the related area which uses it.
else {
QString pingProg = "sh";
QStringList pingArgs;
pingArgs << "/mnt/onboard/.adds/inkbox/test_ping.sh";
pingProcess->startDetached(pingProg, pingArgs);
}
*/
pingProcess->deleteLater();
}
bool getTestPingResults() {
// To be used when the testPing() function is used in non-blocking mode.
if(QFile::exists("/run/test_ping_status")) {
if(checkconfig("/run/test_ping_status") == true) {
global::network::isConnected = true;
return true;
}
else {
global::network::isConnected = false;
return false;
}
}
else {
global::network::isConnected = false;
return false;
}
}
void updateUserAppsMainJsonFile() {
QDirIterator appsDir("/mnt/onboard/onboard/.apps", QDirIterator::NoIteratorFlags);
QFile newJsonFile = QFile{"/mnt/onboard/onboard/.apps/apps.json"};
@ -1135,6 +1067,72 @@ namespace {
return 2;
}
}
global::wifi::wifiState checkWifiState() {
QProcess *wifiStateProcess = new QProcess();
QString path = "/external_root/usr/local/bin/wifi/wifi_status.sh";
QStringList args;
wifiStateProcess->start(path, args);
wifiStateProcess->waitForFinished();
wifiStateProcess->deleteLater();
QString currentWifiState;
if(QFile("/run/wifi_status").exists() == true) {
currentWifiState = readFile("/run/wifi_status");
} else {
log("/run/wifi_status doesn't exist", "functions");
}
if (currentWifiState.contains("configured") == true) {
global::wifi::isConnected = true;
return global::wifi::wifiState::configured;
}
else if (currentWifiState.contains("enabled") == true) {
global::wifi::isConnected = false;
return global::wifi::wifiState::enabled;
}
else if (currentWifiState.contains("disabled") == true) {
global::wifi::isConnected = false;
return global::wifi::wifiState::disabled;
} else {
global::wifi::isConnected = false;
QString function = __func__; log(function + ": Critical error", "functions");
return global::wifi::wifiState::unknown;
}
}
int testPing() {
// For some reason, implementing a non-blocking version of this functions triggers a "terminate called without an active exception" error with a platform plugin compiled with a newer GCC 11 toolchain. The problem has been solved by transplanting this function into the related area which uses it.
QProcess *pingProcess = new QProcess();
QString pingProg = "ping";
QStringList pingArgs;
pingArgs << "-c" << "1" << "1.1.1.1";
pingProcess->start(pingProg, pingArgs);
pingProcess->waitForFinished();
int exitCode = pingProcess->exitCode();
pingProcess->deleteLater();
if(exitCode == 0) {
global::wifi::isConnected = true;
}
else {
global::wifi::isConnected = false;
}
return exitCode;
}
bool checkProcessName(QString name) {
QDirIterator appsDir("/proc", QDirIterator::NoIteratorFlags);
while (appsDir.hasNext()) {
QDir dir(appsDir.next());
QFile process = QFile(dir.path() + "/cmdline");
if(process.exists() == true) {
process.open(QIODevice::ReadOnly);
QTextStream stream(&process);
if(stream.readLine().contains(name) == true) {
process.close();
return true;
}
process.close();
}
}
return false;
}
}
#endif // FUNCTIONS_H

View file

@ -65,8 +65,6 @@ MainWindow::MainWindow(QWidget *parent)
global::usbms::koboxExportExtensions = false;
global::mainwindow::tabSwitcher::repaint = true;
resetFullWindowException = false;
wifiIconClickedWhileReconnecting = false;
lastWifiState = 0;
// Getting the screen's size
sW = QGuiApplication::screens()[0]->size().width();
@ -134,9 +132,13 @@ MainWindow::MainWindow(QWidget *parent)
ui->brightnessBtn->setIcon(QIcon(":/resources/frontlight.png"));
ui->brightnessBtn->setIconSize(QSize(brightnessIconWidth, brightnessIconHeight));
setWifiIcon();
updateWifiAble();
if(global::device::isWifiAble == true) {
updateWifiIcon(0);
// Start Wi-Fi icon updater
QTimer *wifiIconTimer = new QTimer(this);
wifiIconTimer->setInterval(2500);
connect(wifiIconTimer, SIGNAL(timeout()), this, SLOT(updateWifiIcon()));
wifiIconTimer->start();
}
setBatteryIcon();
@ -632,13 +634,13 @@ void MainWindow::setBatteryIcon() {
stdIconHeight = sH / 16;
QPixmap chargingPixmap(":/resources/battery_charging.png");
QPixmap scaledChargingPixmap = chargingPixmap.scaled(stdIconWidth, stdIconHeight, Qt::KeepAspectRatio);
QPixmap scaledChargingPixmap = chargingPixmap.scaled(stdIconWidth, stdIconHeight, Qt::KeepAspectRatio, Qt::SmoothTransformation);
QPixmap fullPixmap(":/resources/battery_full.png");
QPixmap scaledFullPixmap = fullPixmap.scaled(stdIconWidth, stdIconHeight, Qt::KeepAspectRatio);
QPixmap scaledFullPixmap = fullPixmap.scaled(stdIconWidth, stdIconHeight, Qt::KeepAspectRatio, Qt::SmoothTransformation);
QPixmap halfPixmap(":/resources/battery_half.png");
QPixmap scaledHalfPixmap = halfPixmap.scaled(stdIconWidth, stdIconHeight, Qt::KeepAspectRatio);
QPixmap scaledHalfPixmap = halfPixmap.scaled(stdIconWidth, stdIconHeight, Qt::KeepAspectRatio, Qt::SmoothTransformation);
QPixmap emptyPixmap(":/resources/battery_empty.png");
QPixmap scaledEmptyPixmap = emptyPixmap.scaled(stdIconWidth, stdIconHeight, Qt::KeepAspectRatio);
QPixmap scaledEmptyPixmap = emptyPixmap.scaled(stdIconWidth, stdIconHeight, Qt::KeepAspectRatio, Qt::SmoothTransformation);
// Checking battery level and status, then displaying the relevant icon on batteryIcon
if(isUsbPluggedIn() == true) {
@ -662,13 +664,13 @@ void MainWindow::setBatteryIcon() {
stdIconWidth = sW / 19;
stdIconHeight = sH / 19;
QPixmap chargingPixmap(":/resources/battery_charging.png");
QPixmap scaledChargingPixmap = chargingPixmap.scaled(stdIconWidth, stdIconHeight, Qt::KeepAspectRatio);
QPixmap scaledChargingPixmap = chargingPixmap.scaled(stdIconWidth, stdIconHeight, Qt::KeepAspectRatio, Qt::SmoothTransformation);
QPixmap fullPixmap(":/resources/battery_full.png");
QPixmap scaledFullPixmap = fullPixmap.scaled(stdIconWidth, stdIconHeight, Qt::KeepAspectRatio);
QPixmap scaledFullPixmap = fullPixmap.scaled(stdIconWidth, stdIconHeight, Qt::KeepAspectRatio, Qt::SmoothTransformation);
QPixmap halfPixmap(":/resources/battery_half.png");
QPixmap scaledHalfPixmap = halfPixmap.scaled(stdIconWidth, stdIconHeight, Qt::KeepAspectRatio);
QPixmap scaledHalfPixmap = halfPixmap.scaled(stdIconWidth, stdIconHeight, Qt::KeepAspectRatio, Qt::SmoothTransformation);
QPixmap emptyPixmap(":/resources/battery_empty.png");
QPixmap scaledEmptyPixmap = emptyPixmap.scaled(stdIconWidth, stdIconHeight, Qt::KeepAspectRatio);
QPixmap scaledEmptyPixmap = emptyPixmap.scaled(stdIconWidth, stdIconHeight, Qt::KeepAspectRatio, Qt::SmoothTransformation);
// Checking battery level and status, then displaying the relevant icon on batteryIcon
if(isUsbPluggedIn() == true) {
@ -709,11 +711,12 @@ void MainWindow::setInitialBrightness() {
// Coming from OOBE setup; not doing that fancy stuff again ;p
QFile::remove("/tmp/oobe-inkbox_completed");
pre_set_brightness(brightness_value);
log("Ignoring cinematic brightness call because it has already been done", className);
}
else {
// Fancy brightness fade-in
if(checkconfig("/tmp/inkbox-cinematic_brightness_auto") == true) {
QFile::remove("/tmp/inkbox-cinematic_brightness_auto");
if(checkconfig("/tmp/inkbox-cinematicBrightness_auto") == true) {
QFile::remove("/tmp/inkbox-cinematicBrightness_auto");
cinematicBrightness(brightness_value, 2);
}
else {
@ -721,6 +724,9 @@ void MainWindow::setInitialBrightness() {
string_writeconfig("/tmp/inkbox-cinematicBrightness_ran", "true");
cinematicBrightness(brightness_value, 0);
}
else {
log("Ignoring cinematic brightness call because it has already been done", className);
}
}
}
}
@ -749,136 +755,102 @@ void MainWindow::setupSearchDialog() {
}
}
void MainWindow::updateWifiIcon(int mode) {
void MainWindow::updateWifiIcon() {
/* Usage:
* mode 0: auto
* mode 1: off
* mode 2: standby
* mode 3: connected
* Mode 0 (looping it) is handled in MainWindow
*/
if(mode == 0) {
lastWifiState = 0;
QTimer *wifiIconTimer = new QTimer(this);
wifiIconTimer->setInterval(10000);
connect(wifiIconTimer, SIGNAL(timeout()), this, SLOT(setWifiIcon()));
wifiIconTimer->start();
global::wifi::wifiState currentWifiState = checkWifiState();
// It's executing only in enabled mode, which is a mode between connected and disabled, so don't worry about performance
if(isConnecting == false and isReconnecting == false) {
if(currentWifiState == global::wifi::wifiState::enabled) {
if(checkProcessName("connection_manager.sh") == true) {
isConnecting = true;
}
if(mode == 1) {
lastWifiState = 1;
else if(checkProcessName("connect_to_network.sh") == true){
isConnecting = true;
isReconnecting = true;
}
}
}
// ms can make a difference, so:
currentWifiState = checkWifiState();
if(lastWifiState != currentWifiState) {
if(currentWifiState == global::wifi::wifiState::disabled) {
if(isConnecting == true) {
if(checkconfig("/mnt/onboard/.adds/inkbox/.config/17-wifi_connection_information/stopped") == false) {
if(isReconnecting == true) {
showToast("Reconnection failed");
isReconnecting = false;
}
else {
showToast("Connection failed");
}
isConnecting = false;
QFile("/mnt/onboard/.adds/inkbox/.config/17-wifi_connection_information/essid").remove();
QFile("/mnt/onboard/.adds/inkbox/.config/17-wifi_connection_information/passphrase").remove();
}
else {
QFile("/mnt/onboard/.adds/inkbox/.config/17-wifi_connection_information/stopped").remove();
}
}
lastWifiState = global::wifi::wifiState::disabled;
ui->wifiBtn->setIcon(QIcon(":/resources/wifi-off.png"));
ui->wifiBtn->setIconSize(QSize(wifiIconWidth, wifiIconHeight));
}
if(mode == 2) {
lastWifiState = 2;
if(currentWifiState == global::wifi::wifiState::enabled) {
lastWifiState = global::wifi::wifiState::enabled;
ui->wifiBtn->setIcon(QIcon(":/resources/wifi-standby.png"));
ui->wifiBtn->setIconSize(QSize(wifiIconWidth, wifiIconHeight));
}
if(mode == 3) {
lastWifiState = 3;
ui->wifiBtn->setIcon(QIcon(":/resources/wifi-connected.png"));
ui->wifiBtn->setIconSize(QSize(wifiIconWidth, wifiIconHeight));
}
}
bool MainWindow::checkWifiState() {
/* Return value:
* true: interface UP
* false: interface DOWN
*/
if(global::deviceID == "n437\n") {
string_checkconfig_ro("/sys/class/net/wlan0/operstate");
if(currentWifiState == global::wifi::wifiState::configured) {
if(isConnecting == true) {
setDefaultWorkDir();
if(isReconnecting == true) {
showToast("Reconnection successful");
isReconnecting = false;
}
else {
string_checkconfig_ro("/sys/class/net/eth0/operstate");
showToast("Connection successful");
}
if(checkconfig_str_val == "up\n") {
return true;
isConnecting = false;
QFile("/mnt/onboard/.adds/inkbox/.config/17-wifi_connection_information/stopped").remove();
}
else {
return false;
}
}
void MainWindow::setWifiIcon() {
if(global::device::isWifiAble == true) {
if(checkWifiState() == true) {
// testPing() the non-blocking way
QProcess * pingProcess = new QProcess();
QString pingProg = "sh";
QStringList pingArgs;
pingArgs << "/mnt/onboard/.adds/inkbox/test_ping.sh";
pingProcess->startDetached(pingProg, pingArgs);
pingProcess->deleteLater();
getTestPingResults();
if(global::network::isConnected == true) {
if(lastWifiState != 3) {
lastWifiState = 3;
ui->wifiBtn->setIcon(QIcon(":/resources/wifi-connected.png"));
ui->wifiBtn->setIconSize(QSize(wifiIconWidth, wifiIconHeight));
}
}
else {
if(lastWifiState != 2) {
lastWifiState = 2;
ui->wifiBtn->setIcon(QIcon(":/resources/wifi-standby.png"));
lastWifiState = global::wifi::wifiState::configured;
ui->wifiBtn->setIcon(QIcon(":/resources/wifi-100.png"));
ui->wifiBtn->setIconSize(QSize(wifiIconWidth, wifiIconHeight));
}
}
}
else {
if(lastWifiState != 1) {
lastWifiState = 1;
ui->wifiBtn->setIcon(QIcon(":/resources/wifi-off.png"));
ui->wifiBtn->setIconSize(QSize(wifiIconWidth, wifiIconHeight));
}
}
}
else {
void MainWindow::updateWifiAble() {
if(global::device::isWifiAble == false) {
ui->wifiBtn->hide();
ui->line_9->hide();
}
}
void MainWindow::openWifiDialog() {
log("Opening Wi-Fi connection interface", className);
if(checkconfig("/external_root/run/was_connected_to_wifi") == true and wifiIconClickedWhileReconnecting == false) {
showToast("Reconnection in progress\nTap again to cancel");
wifiIconClickedWhileReconnecting = true;
QTimer::singleShot(10000, this, SLOT(resetWifiIconClickedWhileReconnecting()));
}
else {
if(wifiIconClickedWhileReconnecting == true) {
string_writeconfig("/opt/ibxd", "stop_wifi_reconnection\n");
while(true) {
if(QFile::exists("/run/stop_wifi_reconnection_done")) {
QFile::remove("/run/stop_wifi_reconnection_done");
break;
}
}
}
global::toast::wifiToast = true;
showToast("Searching for networks");
}
}
void MainWindow::on_wifiBtn_clicked()
{
openWifiDialog();
wifiDialog* newWifiDialog = new wifiDialog();
QObject::connect(newWifiDialog, &wifiDialog::showToast, this, &MainWindow::showToast);
newWifiDialog->exec();
}
void MainWindow::showToast(QString messageToDisplay) {
global::toast::message = messageToDisplay;
toastWindow = new toast(this);
toastWindow->setAttribute(Qt::WA_DeleteOnClose);
connect(toastWindow, SIGNAL(updateWifiIconSig(int)), SLOT(updateWifiIcon(int)));
connect(toastWindow, SIGNAL(refreshScreen()), SLOT(refreshScreen()));
connect(toastWindow, SIGNAL(showToast(QString)), SLOT(showToast(QString)));
connect(toastWindow, SIGNAL(closeIndefiniteToast()), SLOT(closeIndefiniteToast()));
toastWindow->show();
if(messageToDisplay == "Connection successful") {
// I will soon manage the update thing in a more proper way somewhere else... ~ Szybet
if(messageToDisplay.contains("onnected successfully") == true) {
// Give the toast some time to vanish away, then launch OTA updater
QTimer::singleShot(5000, this, SLOT(launchOtaUpdater()));
}
@ -963,7 +935,7 @@ void MainWindow::openEncfsRepackDialog() {
void MainWindow::on_libraryButton_clicked()
{
log("Launching Online Library", className);
if(testPing(true) == 0 or global::deviceID == "emu\n") {
if(testPing() == 0 or global::deviceID == "emu\n") {
resetFullWindowException = true;
resetWindow(false);
if(global::mainwindow::tabSwitcher::libraryWidgetSelected != true) {
@ -1000,7 +972,7 @@ void MainWindow::resetFullWindow() {
}
void MainWindow::checkForOtaUpdate() {
if(global::network::isConnected == true) {
if(global::wifi::isConnected == true) {
string_checkconfig_ro("/external_root/opt/storage/update/last_sync");
if(!checkconfig_str_val.isEmpty()) {
unsigned long currentEpoch = QDateTime::currentSecsSinceEpoch();
@ -1016,10 +988,6 @@ void MainWindow::checkForOtaUpdate() {
}
}
void MainWindow::resetWifiIconClickedWhileReconnecting() {
wifiIconClickedWhileReconnecting = false;
}
void MainWindow::setupLocalLibraryWidget() {
localLibraryWidgetWindow = new localLibraryWidget(this);
QObject::connect(localLibraryWidgetWindow, &localLibraryWidget::openBookSignal, this, &MainWindow::openBookFile);

View file

@ -8,7 +8,7 @@
#include "reader.h"
#include "quit.h"
#include "alert.h"
#include "usbms_splash.h"
#include "usbmsSplash.h"
#include "brightnessdialog.h"
#include "generaldialog.h"
#include "koboxsettings.h"
@ -51,8 +51,11 @@ public:
bool existing_recent_books = false;
bool reboot_after_update = false;
bool resetFullWindowException;
bool wifiIconClickedWhileReconnecting;
int lastWifiState;
global::wifi::wifiState lastWifiState = global::wifi::wifiState::unknown;
bool isConnecting = false;
bool isReconnecting = false;
int timerTime = 0;
QString relative_path;
QString usbmsStatus;
@ -62,9 +65,10 @@ public:
void openUsbmsDialog();
void resetIcons();
void setBatteryIcon();
bool checkWifiState();
public slots:
void showToast(QString messageToDisplay);
void closeIndefiniteToast();
private slots:
void on_settingsBtn_clicked();
@ -74,17 +78,14 @@ private slots:
void on_quitBtn_clicked();
void on_brightnessBtn_clicked();
void openUpdateDialog();
void openWifiDialog();
void setInitialBrightness();
void on_homeBtn_clicked();
void refreshScreen();
void setupSearchDialog();
void setWifiIcon();
void updateWifiAble();
void on_wifiBtn_clicked();
void updateWifiIcon(int mode);
void updateWifiIcon();
void hello(int testNumber);
void showToast(QString messageToDisplay);
void closeIndefiniteToast();
void openUpdateDialogOTA(bool open);
void launchOtaUpdater();
void openBookFile(QString book, bool relativePath);
@ -95,7 +96,6 @@ private slots:
void on_libraryButton_clicked();
void resetWindow(bool resetStackedWidget);
void resetFullWindow();
void resetWifiIconClickedWhileReconnecting();
void setupLocalLibraryWidget();
void setupHomePageWidget();
@ -106,7 +106,7 @@ private:
reader * readerWindow;
quit * quitWindow;
alert * alertWindow;
usbms_splash * usbmsWindow;
usbmsSplash * usbmsWindow;
brightnessDialog * brightnessDialogWindow;
generalDialog * generalDialogWindow;
koboxSettings * koboxSettingsWindow;

View file

@ -41,6 +41,7 @@ int main(int argc, char *argv[])
global::logger::status = true;
}
}
global::deviceID = readFile("/opt/inkbox_device");
log("Running on device " + global::deviceID, "main", true);

View file

@ -366,30 +366,24 @@ reader::reader(QWidget *parent) :
float sH = QGuiApplication::screens()[0]->size().height();
// Defining what the icons' size will be
if(checkconfig("/opt/inkbox_genuine") == true) {
float stdIconWidth;
float stdIconHeight;
if(global::deviceID == "n705\n" or global::deviceID == "n905\n" or global::deviceID == "n613\n" or global::deviceID == "n236\n" or global::deviceID == "n437\n" or global::deviceID == "n306\n" or global::deviceID == "kt\n" or global::deviceID == "emu\n") {
float stdIconWidth = sW / 16;
float stdIconHeight = sW / 16;
QPixmap chargingPixmap(":/resources/battery_charging.png");
scaledChargingPixmap = chargingPixmap.scaled(stdIconWidth, stdIconHeight, Qt::KeepAspectRatio);
QPixmap fullPixmap(":/resources/battery_full.png");
scaledFullPixmap = fullPixmap.scaled(stdIconWidth, stdIconHeight, Qt::KeepAspectRatio);
QPixmap halfPixmap(":/resources/battery_half.png");
scaledHalfPixmap = halfPixmap.scaled(stdIconWidth, stdIconHeight, Qt::KeepAspectRatio);
QPixmap emptyPixmap(":/resources/battery_empty.png");
scaledEmptyPixmap = emptyPixmap.scaled(stdIconWidth, stdIconHeight, Qt::KeepAspectRatio);
stdIconWidth = sW / 16;
stdIconHeight = sW / 16;
}
else {
float stdIconWidth = sW / 19;
float stdIconHeight = sH / 19;
QPixmap chargingPixmap(":/resources/battery_charging.png");
scaledChargingPixmap = chargingPixmap.scaled(stdIconWidth, stdIconHeight, Qt::KeepAspectRatio);
QPixmap fullPixmap(":/resources/battery_full.png");
scaledFullPixmap = fullPixmap.scaled(stdIconWidth, stdIconHeight, Qt::KeepAspectRatio);
QPixmap halfPixmap(":/resources/battery_half.png");
scaledHalfPixmap = halfPixmap.scaled(stdIconWidth, stdIconHeight, Qt::KeepAspectRatio);
QPixmap emptyPixmap(":/resources/battery_empty.png");
scaledEmptyPixmap = emptyPixmap.scaled(stdIconWidth, stdIconHeight, Qt::KeepAspectRatio);
stdIconWidth = sW / 19;
stdIconHeight = sH / 19;
}
QPixmap chargingPixmap(":/resources/battery_charging.png");
scaledChargingPixmap = chargingPixmap.scaled(stdIconWidth, stdIconHeight, Qt::KeepAspectRatio, Qt::SmoothTransformation);
QPixmap fullPixmap(":/resources/battery_full.png");
scaledFullPixmap = fullPixmap.scaled(stdIconWidth, stdIconHeight, Qt::KeepAspectRatio, Qt::SmoothTransformation);
QPixmap halfPixmap(":/resources/battery_half.png");
scaledHalfPixmap = halfPixmap.scaled(stdIconWidth, stdIconHeight, Qt::KeepAspectRatio, Qt::SmoothTransformation);
QPixmap emptyPixmap(":/resources/battery_empty.png");
scaledEmptyPixmap = emptyPixmap.scaled(stdIconWidth, stdIconHeight, Qt::KeepAspectRatio, Qt::SmoothTransformation);
}
else {
float stdIconWidth = sW / 19;
@ -1282,7 +1276,7 @@ void reader::on_homeBtn_clicked()
// Remount tmpfs
string_writeconfig("/inkbox/remount", "true");
// Specify cinematic brightness mode
string_writeconfig("/tmp/inkbox-cinematic_brightness_auto", "true");
string_writeconfig("/tmp/inkbox-cinematicBrightness_auto", "true");
// Relaunching process
quit_restart();

BIN
src/resources/hide.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

BIN
src/resources/log.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.3 KiB

After

Width:  |  Height:  |  Size: 7.6 KiB

BIN
src/resources/show.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

BIN
src/resources/stop.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

View file

@ -126,7 +126,7 @@ void koboxSettings::on_pushButton_clicked()
log("Exporting KoBox extensions onboard storage via USB", className);
log("Showing USBMS splash", className);
usbmsWindow = new usbms_splash();
usbmsWindow = new usbmsSplash();
usbmsWindow->setAttribute(Qt::WA_DeleteOnClose);
usbmsWindow->setGeometry(QRect(QPoint(0,0), screen()->geometry ().size()));
usbmsWindow->show();

View file

@ -4,7 +4,7 @@
#include <QWidget>
#include "generaldialog.h"
#include "usbms_splash.h"
#include "usbmsSplash.h"
namespace Ui {
class koboxSettings;
@ -33,7 +33,7 @@ private slots:
private:
Ui::koboxSettings *ui;
generalDialog *generalDialogWindow;
usbms_splash *usbmsWindow;
usbmsSplash *usbmsWindow;
};
#endif // KOBOXSETTINGS_H

View file

@ -846,7 +846,7 @@ void settings::on_globalReadingSettingsCheckBox_toggled(bool checked)
void settings::on_checkOtaUpdateBtn_clicked()
{
log("'Check for OTA update' button clicked", className);
if(testPing(true) == 0 or global::deviceID == "emu\n") {
if(testPing() == 0 or global::deviceID == "emu\n") {
launchOtaUpdater();
}
else {
@ -901,7 +901,7 @@ void settings::usbms_launch()
log("Showing USBMS splash", className);
global::usbms::launchUsbms = true;
usbmsWindow = new usbms_splash();
usbmsWindow = new usbmsSplash();
usbmsWindow->setAttribute(Qt::WA_DeleteOnClose);
usbmsWindow->setGeometry(QRect(QPoint(0,0), screen()->geometry ().size()));
usbmsWindow->show();

View file

@ -3,7 +3,7 @@
#include <QWidget>
#include <usbms_splash.h>
#include <usbmsSplash.h>
#include "generaldialog.h"
#include "otamanager.h"
#include "toast.h"
@ -79,7 +79,7 @@ signals:
private:
Ui::settings *ui;
usbms_splash *usbmsWindow;
usbmsSplash *usbmsWindow;
generalDialog *generalDialogWindow;
otaManager *otaManagerWindow;
toast *toastWindow;

View file

@ -1,5 +1,5 @@
#include "usbms_splash.h"
#include "ui_usbms_splash.h"
#include "usbmsSplash.h"
#include "ui_usbmsSplash.h"
#include <QPixmap>
#include <QScreen>
@ -7,12 +7,12 @@
#include "functions.h"
usbms_splash::usbms_splash(QWidget *parent) :
usbmsSplash::usbmsSplash(QWidget *parent) :
QWidget(parent),
ui(new Ui::usbms_splash)
ui(new Ui::usbmsSplash)
{
ui->setupUi(this);
usbms_splash::setFont(QFont("u001"));
usbmsSplash::setFont(QFont("u001"));
ui->label->setFont(QFont("Inter"));
// Getting the screen's size
@ -60,11 +60,11 @@ usbms_splash::usbms_splash(QWidget *parent) :
if(global::usbms::launchUsbms == true) {
global::usbms::launchUsbms = false;
usbms_launch();
usbmsLaunch();
}
}
void usbms_splash::usbms_launch()
void usbmsSplash::usbmsLaunch()
{
log("Entering USBMS session", className);
string_writeconfig("/tmp/in_usbms", "true");
@ -169,16 +169,17 @@ void usbms_splash::usbms_launch()
usbms_t->start();
}
usbms_splash::~usbms_splash()
usbmsSplash::~usbmsSplash()
{
delete ui;
}
void usbms_splash::brightnessDown() {
void usbmsSplash::brightnessDown() {
cinematicBrightness(0, 1);
writeFile("/tmp/inkbox-cinematicBrightness_ran", "false");
}
void usbms_splash::quit_restart() {
void usbmsSplash::quit_restart() {
// If existing, cleaning bookconfig_mount mountpoint
string_writeconfig("/opt/ibxd", "bookconfig_unmount\n");
@ -188,7 +189,7 @@ void usbms_splash::quit_restart() {
qApp->quit();
}
void usbms_splash::restartServices() {
void usbmsSplash::restartServices() {
// Restarting USBNet
// NOTE: USBNet is only started if required conditions are met (see https://github.com/Kobo-InkBox/rootfs/blob/master/etc/init.d/usbnet)
string_writeconfig("/opt/ibxd", "usbnet_start\n");

View file

@ -4,22 +4,22 @@
#include <QWidget>
namespace Ui {
class usbms_splash;
class usbmsSplash;
}
class usbms_splash : public QWidget
class usbmsSplash : public QWidget
{
Q_OBJECT
public:
QString className = this->metaObject()->className();
explicit usbms_splash(QWidget *parent = nullptr);
~usbms_splash();
explicit usbmsSplash(QWidget *parent = nullptr);
~usbmsSplash();
float sW;
float sH;
QString massStorageModule;
void usbms_launch();
void usbmsLaunch();
private slots:
void brightnessDown();
@ -27,7 +27,7 @@ private slots:
void restartServices();
private:
Ui::usbms_splash *ui;
Ui::usbmsSplash *ui;
};
#endif // USBMS_SPLASH_H

View file

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>usbms_splash</class>
<widget class="QWidget" name="usbms_splash">
<class>usbmsSplash</class>
<widget class="QWidget" name="usbmsSplash">
<property name="geometry">
<rect>
<x>0</x>

View file

@ -337,7 +337,7 @@ void generalDialog::on_okBtn_clicked()
global::usbms::usbmsDialog = false;
global::usbms::launchUsbms = true;
usbmsWindow = new usbms_splash();
usbmsWindow = new usbmsSplash();
usbmsWindow->setAttribute(Qt::WA_DeleteOnClose);
usbmsWindow->setGeometry(QRect(QPoint(0,0), screen()->geometry ().size()));
usbmsWindow->show();
@ -419,7 +419,7 @@ void generalDialog::on_okBtn_clicked()
}
}
else if(ui->searchComboBox->currentText() == "Online library") {
if(testPing(true) == 0 or global::deviceID == "emu\n") {
if(testPing() == 0 or global::deviceID == "emu\n") {
string_writeconfig("/inkbox/searchComboBoxFunction", "Online library");
log("Searching online library for '" + global::keyboard::keyboardText + "'", className);
@ -495,15 +495,13 @@ void generalDialog::on_okBtn_clicked()
}
else if(global::keyboard::wifiPassphraseDialog == true) {
if(!global::keyboard::keyboardText.isEmpty()) {
log("Attempting connection to Wi-Fi network '" + wifiEssid + "'", className);
this->hide();
wifiPassphrase = global::keyboard::keyboardText;
global::toast::indefiniteToast = true;
global::toast::modalToast = true;
emit showToast("Connecting");
QTimer::singleShot(100, this, SLOT(connectToNetworkSlot()));
global::keyboard::wifiPassphraseDialog = false;
global::keyboard::keyboardDialog = false;
if(global::keyboard::keyboardText.count() < 8) {
global::toast::delay = 3000;
showToast("Minimum passphrase length is 8 characters");
}
else {
generalDialog::close();
}
}
else {
global::toast::delay = 3000;
@ -596,6 +594,7 @@ void generalDialog::restartSearchDialog() {
}
void generalDialog::setupKeyboardDialog() {
adjust_size();
ui->stackedWidget->setCurrentIndex(0);
keyboardDialog = true;
ui->stackedWidget->setVisible(true);
@ -612,7 +611,7 @@ void generalDialog::setupKeyboardDialog() {
}
else if(global::keyboard::wifiPassphraseDialog == true) {
ui->headerLabel->setText("Enter the network's passphrase");
ui->okBtn->setText("Connect");
ui->okBtn->setText("Enter");
ui->cancelBtn->setText("Cancel");
}
else if(global::keyboard::encfsDialog == true) {
@ -629,6 +628,7 @@ void generalDialog::setupKeyboardDialog() {
connect(keyboardWidget, SIGNAL(adjust_size()), SLOT(adjust_size()));
ui->mainStackedWidget->insertWidget(1, keyboardWidget);
ui->mainStackedWidget->setCurrentIndex(1);
adjust_size();
QTimer::singleShot(1000, this, SLOT(adjust_size()));
}
@ -648,20 +648,6 @@ void generalDialog::startVNC(QString server, QString password, QString port) {
qApp->quit();
}
void generalDialog::connectToNetworkSlot() {
if(connectToNetwork(wifiEssid, wifiPassphrase) == true) {
emit updateWifiIcon(3);
emit closeIndefiniteToast();
emit showToast("Connection successful");
}
else {
emit updateWifiIcon(2);
emit closeIndefiniteToast();
emit showToast("Connection failed");
}
generalDialog::close();
}
void generalDialog::startOtaUpdate(bool wasDownloadSuccessful) {
emit closeIndefiniteToast();
if(wasDownloadSuccessful == true) {

View file

@ -3,7 +3,7 @@
#include <QDialog>
#include "usbms_splash.h"
#include "usbmsSplash.h"
#include "textwidget.h"
#include "virtualkeyboard.h"
#include "virtualkeypad.h"
@ -63,7 +63,6 @@ private slots:
void adjust_size();
void restartSearchDialog();
void refreshScreenNative();
void connectToNetworkSlot();
void startOtaUpdate(bool wasDownloadSuccessful);
void openBookFileNative(QString book, bool relativePath);
void showToastNative(QString messageToDisplay);
@ -74,7 +73,7 @@ private slots:
private:
Ui::generalDialog *ui;
usbms_splash *usbmsWindow;
usbmsSplash *usbmsWindow;
textwidget *textwidgetWindow;
virtualkeyboard *keyboardWidget;
virtualkeypad *keypadWidget;

View file

@ -166,7 +166,7 @@ void koboxAppsDialog::on_launchBtn_clicked()
// Re-use USBMS splash window for KoBox splash, since it's pretty much the same layout
log("Showing KoBox splash", className);
usbmsSplashWindow = new usbms_splash();
usbmsSplashWindow = new usbmsSplash();
usbmsSplashWindow->setAttribute(Qt::WA_DeleteOnClose);
usbmsSplashWindow->setGeometry(QRect(QPoint(0,0), screen()->geometry().size()));
usbmsSplashWindow->show();

View file

@ -4,7 +4,7 @@
#include <QDialog>
#include <QModelIndex>
#include "usbms_splash.h"
#include "usbmsSplash.h"
namespace Ui {
class koboxAppsDialog;
@ -36,7 +36,7 @@ signals:
private:
Ui::koboxAppsDialog *ui;
usbms_splash *usbmsSplashWindow;
usbmsSplash *usbmsSplashWindow;
};
#endif // KOBOXAPPSDIALOG_H

View file

@ -0,0 +1,387 @@
#include <QFile>
#include <QScreen>
#include "connectiondialog.h"
#include "ui_connectiondialog.h"
#include "generaldialog.h"
#include "functions.h"
connectiondialog::connectiondialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::connectiondialog)
{
ui->setupUi(this);
this->setFont(QFont("u001"));
ui->passphraseTextEdit->setFont(QFont("Noto Mono"));
ui->label->setFont(QFont("Inter"));
ui->label_2->setFont(QFont("Inter"));
// Stylesheet, style & misc.
QFile stylesheetFile("/mnt/onboard/.adds/inkbox/eink.qss");
stylesheetFile.open(QFile::ReadOnly);
this->setStyleSheet(stylesheetFile.readAll());
stylesheetFile.close();
ui->cancelBtn->setProperty("type", "borderless");
ui->connectBtn->setProperty("type", "borderless");
ui->showPassphraseBtn->setProperty("type", "borderless");
ui->label->setStyleSheet("font-weight: bold");
ui->label_2->setStyleSheet("font-weight: bold");
ui->cancelBtn->setIcon(QIcon(":/resources/close.png"));
ui->connectBtn->setIcon(QIcon(":/resources/arrow-right.png"));
// Size
QRect screenGeometry = QGuiApplication::screens()[0]->geometry();
if(global::deviceID == "n705\n") {
this->setFixedWidth(screenGeometry.width() / 1.2);
}
else {
this->setFixedWidth(screenGeometry.width() / 1.5);
}
int halfOfHalfHeight = ((screenGeometry.height() / 2) / 2) / 2;
int finalHeight;
if(global::deviceID == "n705\n") {
finalHeight = screenGeometry.height() - halfOfHalfHeight * 5.9;
}
else {
finalHeight = screenGeometry.height() - halfOfHalfHeight * 6.3;
}
this->setFixedHeight(finalHeight);
// Centering dialog
int x = (screenGeometry.width() - this->width()) / 2;
int y = (screenGeometry.height() - this->height()) / 2;
this->move(x, y);
}
connectiondialog::~connectiondialog()
{
delete ui;
}
void connectiondialog::applyVariables() {
// Limit name size
int truncateThreshold;
if(global::deviceID == "n705\n") {
truncateThreshold = 20;
}
else {
truncateThreshold = 30;
}
int nameLength = connectedNetworkData.name.length();
QString name = connectedNetworkData.name;
if(nameLength > truncateThreshold) {
name.chop(nameLength - truncateThreshold);
name.append("...");
}
ui->nameLabel->setText(name);
ui->macLabel->setText(connectedNetworkData.mac);
ui->signalLabel->setText(QString::number(connectedNetworkData.signal) + "%");
if(connectedNetworkData.encryption == false) {
ui->showPassphraseBtn->hide();
ui->passphraseTextEdit->setText("No passphrase required");
ui->passphraseTextEdit->setDisabled(true);
}
else {
if(passphraseDatabase.exists() == false) {
log("Creating empty database", className);
// https://forum.qt.io/topic/104791/how-i-can-create-json-format-in-qt/5
QJsonObject root;
QJsonArray array;
QJsonDocument newJsonDocument;
root["list"] = array;
newJsonDocument.setObject(root);
passphraseDatabase.open(QFile::WriteOnly | QFile::Text | QFile::Truncate);
passphraseDatabase.write(newJsonDocument.toJson());
passphraseDatabase.flush();
passphraseDatabase.close();
}
QString passphrase = searchDatabase(connectedNetworkData.name);
if(passphrase.isEmpty() == false) {
log("Found passphrase: '" + passphrase + "'", className);
ui->showPassphraseBtn->setIcon(QIcon(":/resources/show.png"));
showedPassphrase = false;
savedPassphrase = passphrase;
int passphraseLength = passphrase.length();
QString hiddenPassphrase;
for(int i = 0; i < passphraseLength; i++) {
hiddenPassphrase.append("");
}
ui->passphraseTextEdit->setText(hiddenPassphrase);
}
else {
log("No passphrase found", className);
ui->passphraseTextEdit->setText("No passphrase was saved");
showedPassphrase = true;
ui->showPassphraseBtn->hide();
}
}
}
QString connectiondialog::searchDatabase(QString key) {
passphraseDatabase.open(QIODevice::ReadOnly | QIODevice::Text);
QString fileRead = passphraseDatabase.readAll();
passphraseDatabase.close();
QJsonDocument jsonDocument = QJsonDocument::fromJson(fileRead.toUtf8());
if(jsonDocument["list"].isArray() == true) {
QJsonArray jsonArray = jsonDocument["list"].toArray();
for(QJsonValueRef refJsonObject: jsonArray) {
QJsonObject jsonMainObject = refJsonObject.toObject();
QString searchedName = jsonMainObject.keys().first().toUtf8();
log("Found in database: '" + searchedName + "'", className);
if(searchedName == key) {
QString returnedPassphrase = jsonMainObject.value(key).toString();
log("Searched name '" + searchedName + "' matched '" + key + "' and the passphrase is: '" + returnedPassphrase + "'", className);
return returnedPassphrase;
}
else {
log("Searched name '" + searchedName + "' doesn't match '" + key + "'", className);
}
}
return "";
}
else {
log("Something went horribly wrong", className);
}
}
void connectiondialog::writeToDatabase(QString name, QString passphrase) {
if(searchDatabase(name).isEmpty() == false) {
removeFromDatabase(name);
}
passphraseDatabase.open(QIODevice::ReadOnly | QIODevice::Text);
QString fileRead = passphraseDatabase.readAll();
passphraseDatabase.close();
QJsonDocument jsonDocument = QJsonDocument::fromJson(fileRead.toUtf8());
if(jsonDocument["list"].isArray() == true) {
QJsonArray jsonArray = jsonDocument["list"].toArray();
QJsonValue newValue;
// https://stackoverflow.com/questions/26804660/how-to-initialize-qjsonobject-from-qstring
// I hoped this would be easier
QJsonObject newObject = QJsonDocument::fromJson(QString("{\"" + name + "\" : \"" + passphrase + "\" }").toUtf8()).object();
jsonArray.append(newObject);
QJsonDocument newJsonDocument;
QJsonObject root;
root["list"] = jsonArray;
newJsonDocument.setObject(root);
passphraseDatabase.open(QFile::WriteOnly | QFile::Text | QFile::Truncate);
passphraseDatabase.write(newJsonDocument.toJson());
passphraseDatabase.flush();
passphraseDatabase.close();
}
else {
log("Something went horribly wrong", className);
}
}
void connectiondialog::removeFromDatabase(QString name) {
passphraseDatabase.open(QIODevice::ReadOnly | QIODevice::Text);
QString fileRead = passphraseDatabase.readAll();
passphraseDatabase.close();
QJsonDocument jsonDocument = QJsonDocument::fromJson(fileRead.toUtf8());
int counter = 0;
bool remove = false;
if(jsonDocument["list"].isArray() == true) {
QJsonArray jsonArray = jsonDocument["list"].toArray();
for(QJsonValueRef refJsonObject: jsonArray) {
QJsonObject jsonMainObject = refJsonObject.toObject();
QString searchedName = jsonMainObject.keys().first().toUtf8();
log("Found in database: '" + searchedName + "'", className);
if(searchedName == name) {
remove = true;
}
if(remove == false) {
counter = counter + 1;
}
}
if(remove == true) {
jsonArray.removeAt(counter);
QJsonDocument newJsonDocument;
QJsonObject root;
root["list"] = jsonArray;
newJsonDocument.setObject(root);
passphraseDatabase.open(QFile::WriteOnly | QFile::Text | QFile::Truncate);
passphraseDatabase.write(newJsonDocument.toJson());
passphraseDatabase.flush();
passphraseDatabase.close();
}
else {
log("ERROR: tried to remove from database, but couldn't find key", className);
}
}
}
void connectiondialog::on_cancelBtn_clicked()
{
this->deleteLater();
this->close();
}
void connectiondialog::on_passphraseTextEdit_selectionChanged()
{
ui->passphraseTextEdit->setSelection(0, 0);
}
void connectiondialog::on_passphraseTextEdit_cursorPositionChanged(int oldpos, int newpos)
{
log("Detected click on text edit widget", className);
if(cursorPositionIgnore == true) {
if(newpos != 0) {
if(showedPassphrase == true) {
ui->passphraseTextEdit->setCursorPosition(0);
global::keyboard::keyboardDialog = true;
global::keyboard::wifiPassphraseDialog = true;
global::keyboard::keyboardText = "";
generalDialog* generalDialogWindow = new generalDialog();
generalDialogWindow->setAttribute(Qt::WA_DeleteOnClose);
generalDialogWindow->wifiEssid = connectedNetworkData.name;
connect(generalDialogWindow, &generalDialog::showToast, this, &connectiondialog::showToastSlot);
connect(generalDialogWindow, &generalDialog::refreshScreen, this, &connectiondialog::refreshScreenSlot);
generalDialogWindow->exec();
global::keyboard::keyboardDialog = false;
global::keyboard::wifiPassphraseDialog = false;
if(global::keyboard::keyboardText.isEmpty() == false) {
// A bit hacky: avoid summoning the keyboard back when the text is changing (and the cursor too) showedPassphrase shouldn't be used for this, but it works and adding another boolean would start being messy
showedPassphrase = false;
ui->passphraseTextEdit->setText(global::keyboard::keyboardText);
ui->showPassphraseBtn->setIcon(QIcon(":/resources/hide.png"));
ui->showPassphraseBtn->show();
showedPassphrase = true;
savedPassphrase = global::keyboard::keyboardText;
ui->showPassphraseBtn->show();
}
global::keyboard::keyboardText = "";
}
else {
log("Passphrase is not saved; ignoring text edit widget call", className);
}
}
}
else {
log("Ignoring click on text edit widget", className);
cursorPositionIgnore = true;
}
}
void connectiondialog::showToastSlot(QString message) {
emit showToastSignal(message);
}
void connectiondialog::on_showPassphraseBtn_clicked()
{
if(showedPassphrase == false) {
ui->showPassphraseBtn->setIcon(QIcon(":/resources/hide.png"));
ui->passphraseTextEdit->setText(savedPassphrase);
showedPassphrase = true;
}
else {
showedPassphrase = false;
ui->showPassphraseBtn->setIcon(QIcon(":/resources/show.png"));
int passphraseLength = searchDatabase(connectedNetworkData.name).length();
if(passphraseLength != 0) {
QString hiddenPassphrase;
for(int i = 0; i < passphraseLength; i++) {
hiddenPassphrase.append("");
}
ui->passphraseTextEdit->setText(hiddenPassphrase);
}
else {
// This is executed if the user asks to hide the passphrase but it isn't saved yet (upon first connection to a network)
QString hiddenPassphrase;
int passphraseLength = ui->passphraseTextEdit->text().length();
for(int i = 0; i < passphraseLength; i++) {
hiddenPassphrase.append("");
}
ui->passphraseTextEdit->setText(hiddenPassphrase);
}
}
}
void connectiondialog::refreshScreenSlot() {
this->repaint();
emit refreshScreenSignal();
}
void connectiondialog::on_connectBtn_clicked()
{
QString finalPassphrase;
if(connectedNetworkData.encryption == false) {
finalPassphrase = "NONE";
}
else {
if(savedPassphrase.isEmpty() == false) {
finalPassphrase = savedPassphrase;
writeToDatabase(connectedNetworkData.name, savedPassphrase);
}
else {
showToastSlot("Provide a passphrase first");
return void();
}
}
passphraseForReconnecting = finalPassphrase;
ui->cancelBtn->setEnabled(false);
if(checkWifiState() == global::wifi::wifiState::configured) {
string_writeconfig("/opt/ibxd", "stop_wifi_operations\n");
}
writeFile("/run/wifi_network_essid", connectedNetworkData.name);
writeFile("/run/wifi_network_passphrase", finalPassphrase);
finalConnectWait();
}
void connectiondialog::finalConnectWait() {
if(checkIfWifiBusy() == true) {
// To be sure
if(waitTry == 10) {
string_writeconfig("/opt/ibxd", "stop_wifi_operations\n");
}
// Wait for everything to shut down; 10 seconds timeout
if(waitTry == 20) {
string_writeconfig("/opt/ibxd", "stop_wifi_operations\n");
emit showToastSignal("Failed to stop other Wi-Fi processes");
ui->cancelBtn->setEnabled(true);
}
else {
QTimer::singleShot(500, this, SLOT(finalConnectWait()));
waitTry = waitTry + 1;
}
}
else {
string_writeconfig("/opt/ibxd", "connect_to_wifi_network\n");
// This will be deleted later in MainWindow's icon updater if it failed. It is also deleted in the Wi-Fi stop script
log("Writing to config directory with connection information data", className);
string_writeconfig("/mnt/onboard/.adds/inkbox/.config/17-wifi_connection_information/essid", connectedNetworkData.name.toStdString());
string_writeconfig("/mnt/onboard/.adds/inkbox/.config/17-wifi_connection_information/passphrase", passphraseForReconnecting.toStdString());
this->deleteLater();
this->close();
}
}
bool connectiondialog::checkIfWifiBusy() {
if(checkProcessName("connect_to_network.sh") == true or checkProcessName("connection_manager.sh") == true or checkProcessName("prepare_changing_wifi.sh") == true) {
return true;
}
else {
return false;
}
}

View file

@ -0,0 +1,58 @@
#ifndef CONNECTIONDIALOG_H
#define CONNECTIONDIALOG_H
#include <QDialog>
#include "functions.h"
namespace Ui {
class connectiondialog;
}
class connectiondialog : public QDialog
{
Q_OBJECT
public:
QString className = this->metaObject()->className();
explicit connectiondialog(QWidget *parent = nullptr);
~connectiondialog();
global::wifi::wifiNetworkData connectedNetworkData;
QString currentlyConnectedNetworkName;
QFile passphraseDatabase = QFile("/mnt/onboard/.adds/inkbox/.config/17-wifi_connection_information/passphrases.json");
signals:
void showToastSignal(QString message);
void refreshScreenSignal();
public slots:
void applyVariables();
void showToastSlot(QString message);
void refreshScreenSlot();
private slots:
// We are opening/loading the JSON database many times, it might not be efficient, but:
// 1. It's modular
// 2. Those operations are rare
QString searchDatabase(QString key);
void writeToDatabase(QString name, QString passphrase);
void removeFromDatabase(QString name);
void finalConnectWait();
bool checkIfWifiBusy();
void on_cancelBtn_clicked();
void on_passphraseTextEdit_selectionChanged();
void on_passphraseTextEdit_cursorPositionChanged(int arg1, int arg2);
void on_showPassphraseBtn_clicked();
void on_connectBtn_clicked();
private:
Ui::connectiondialog *ui;
bool cursorPositionIgnore = false;
bool showedPassphrase;
QString savedPassphrase;
int waitTry = 0;
QString passphraseForReconnecting;
};
#endif // CONNECTIONDIALOG_H

View file

@ -0,0 +1,189 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>connectiondialog</class>
<widget class="QDialog" name="connectiondialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>263</width>
<height>136</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="sizeConstraint">
<enum>QLayout::SetFixedSize</enum>
</property>
<item>
<widget class="QPushButton" name="cancelBtn">
<property name="text">
<string></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="QLabel" name="nameLabel">
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<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="connectBtn">
<property name="text">
<string></string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLineEdit" name="passphraseTextEdit">
<property name="cursor">
<cursorShape>BlankCursor</cursorShape>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="showPassphraseBtn">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QLabel" name="label">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Signal strength:</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="signalLabel">
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QLabel" name="label_2">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>MAC address:</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="macLabel">
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View file

@ -0,0 +1,119 @@
#include "network.h"
#include "ui_network.h"
#include "connectiondialog.h"
#include <QScreen>
network::network(QWidget *parent) :
QWidget(parent),
ui(new Ui::network)
{
ui->setupUi(this);
this->setFont(QFont("u001"));
// 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->signalStrengthIcon->setProperty("type", "borderless");
ui->signalStrengthIcon->setStyleSheet("QPushButton[type='borderless']:pressed { background: white; color: white; border: none; }");
ui->enterButton->setProperty("type", "borderless");
}
network::~network()
{
delete ui;
}
void network::applyVariables() {
log("Applying variables for network", className);
QString percent = "%";
if(mainData.signal < 100) {
percent.append(" ");
}
ui->signalStrengthLabel->setText(QString::number(mainData.signal) + percent);
// Limit name size
int truncateThreshold;
if(global::deviceID == "n705\n") {
truncateThreshold = 12;
}
else {
truncateThreshold = 20;
}
int nameLength = mainData.name.length();
QString name = mainData.name;
if(nameLength > truncateThreshold) {
name.chop(nameLength - truncateThreshold);
name.append("...");
}
ui->nameLabel->setText(name);
if(mainData.encryption == true) {
ui->encryptionIcon->setIcon(QIcon(":/resources/lock.png"));
}
else {
ui->encryptionIcon->setIcon(QIcon(":/resources/public.png"));
}
if(currentlyConnectedNetwork == mainData.name) {
ui->frame->setStyleSheet(".QFrame{background-color: lightGray; border: 2px solid black; border-radius: 10px;}");
ui->signalStrengthLabel->setStyleSheet("background-color: lightGray;");
ui->nameLabel->setStyleSheet("background-color: lightGray;");
ui->encryptionIcon->setStyleSheet("background-color: lightGray;");
ui->enterButton->setStyleSheet("background-color: lightGray;");
ui->signalStrengthIcon->setStyleSheet("QPushButton {background-color: lightGray; border: none}; QPushButton[type='borderless']:pressed { background: lightGray; color: lightGray; border: none; }");
ui->encryptionIcon->setStyleSheet("QPushButton {background-color: lightGray; border: none}; QPushButton[type='borderless']:pressed { background: lightGray; color: lightGray; border: none; }");
ui->enterButton->setStyleSheet("QPushButton {background-color: lightGray; border: none}; QPushButton[type='borderless']:pressed { background: lightGray; color: lightGray; border: none; }");
}
else {
ui->frame->setStyleSheet(".QFrame{background-color: white; border: 2px solid black; border-radius: 10px;}");
}
if(mainData.signal >= 0 and mainData.signal <= 25) {
ui->signalStrengthIcon->setIcon(QIcon(":/resources/wifi-0.png"));
}
else if(mainData.signal >= 25 and mainData.signal < 50) {
ui->signalStrengthIcon->setIcon(QIcon(":/resources/wifi-25.png"));
}
else if(mainData.signal >= 50 and mainData.signal < 75) {
ui->signalStrengthIcon->setIcon(QIcon(":/resources/wifi-50.png"));
}
else if(mainData.signal >= 75 and mainData.signal < 100) {
ui->signalStrengthIcon->setIcon(QIcon(":/resources/wifi-75.png"));
}
else if(mainData.signal == 100) {
ui->signalStrengthIcon->setIcon(QIcon(":/resources/wifi-100.png"));
}
}
void network::on_enterButton_clicked()
{
connectiondialog* newConnectionDialog = new connectiondialog;
newConnectionDialog->connectedNetworkData = mainData;
newConnectionDialog->currentlyConnectedNetworkName = currentlyConnectedNetwork;
newConnectionDialog->applyVariables();
connect(newConnectionDialog, &connectiondialog::showToastSignal, this, &network::showToastSlot);
connect(newConnectionDialog, &connectiondialog::refreshScreenSignal, this, &network::refreshScreenSlot);
newConnectionDialog->exec();
}
void network::closeWrapper() {
this->deleteLater();
this->close();
}
void network::showToastSlot(QString message) {
emit showToastSignal(message);
}
void network::refreshScreenSlot() {
emit refreshScreenSignal();
}

View file

@ -0,0 +1,40 @@
#ifndef NETWORK_H
#define NETWORK_H
#include <QWidget>
#include "functions.h"
namespace Ui {
class network;
}
class network : public QWidget
{
Q_OBJECT
public:
QString className = this->metaObject()->className();
explicit network(QWidget *parent = nullptr);
~network();
global::wifi::wifiNetworkData mainData;
QString currentlyConnectedNetwork;
signals:
void showToastSignal(QString message);
void refreshScreenSignal();
public slots:
void applyVariables();
void closeWrapper();
void showToastSlot(QString message);
void refreshScreenSlot();
private slots:
void on_enterButton_clicked();
private:
Ui::network *ui;
};
#endif // NETWORK_H

View file

@ -0,0 +1,149 @@
<?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">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>4</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>4</number>
</property>
<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::Plain</enum>
</property>
<property name="lineWidth">
<number>1</number>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="leftMargin">
<number>16</number>
</property>
<property name="topMargin">
<number>10</number>
</property>
<property name="rightMargin">
<number>3</number>
</property>
<property name="bottomMargin">
<number>10</number>
</property>
<item>
<widget class="QPushButton" name="signalStrengthIcon">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="signalStrengthLabel">
<property name="font">
<font>
<family>U001</family>
</font>
</property>
<property name="text">
<string>Signal strength</string>
</property>
</widget>
</item>
<item>
<widget class="Line" name="line">
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="lineWidth">
<number>1</number>
</property>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="nameLabel">
<property name="font">
<font>
<family>U001</family>
</font>
</property>
<property name="text">
<string>Wi-Fi network 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>

View file

@ -3,18 +3,21 @@
#include <QScreen>
#include <QDesktopWidget>
#include <QMessageBox>
#include <QScrollBar>
#include "wifidialog.h"
#include "ui_wifidialog.h"
#include "functions.h"
#include "mainwindow.h"
#include "network.h"
#include "wifilogger.h"
wifiDialog::wifiDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::wifiDialog)
{
ui->setupUi(this);
wifiListTimer = new QTimer(this);
this->setFont(QFont("u001"));
// Stylesheet, style & misc.
QFile stylesheetFile("/mnt/onboard/.adds/inkbox/eink.qss");
@ -23,15 +26,60 @@ wifiDialog::wifiDialog(QWidget *parent) :
stylesheetFile.close();
this->setModal(true);
ui->cancelBtn->setProperty("type", "borderless");
ui->connectBtn->setProperty("type", "borderless");
ui->cancelBtn->setStyleSheet("font-size: 9pt; padding: 10px; font-weight: bold; background: lightGrey");
ui->connectBtn->setStyleSheet("font-size: 9pt; padding: 10px; font-weight: bold; background: lightGrey");
ui->mainLabel->setStyleSheet("padding-left: 125px; padding-right: 125px");
ui->networksListWidget->setFont(QFont("u001"));
ui->networksListWidget->setStyleSheet("font-size: 9pt");
ui->wifiCheckBox->setFont(QFont("Inter"));
ui->returnBtn->setFont(QFont("Inter"));
ui->returnBtn->setStyleSheet("font-weight: bold");
checkWifiNetworks();
ui->refreshBtn->setProperty("type", "borderless");
ui->stopBtn->setProperty("type", "borderless");
ui->logBtn->setProperty("type", "borderless");
ui->returnBtn->setProperty("type", "borderless");
ui->refreshBtn->setIcon(QIcon(":/resources/refresh.png"));
ui->stopBtn->setIcon(QIcon(":/resources/stop.png"));
ui->logBtn->setIcon(QIcon(":/resources/log.png"));
// Size
QRect screenGeometry = QGuiApplication::screens()[0]->geometry();
this->setFixedWidth(screenGeometry.width() / 1.1);
int halfOfHalfHeight = ((screenGeometry.height() / 2) / 2) / 2;
int finalHeight = screenGeometry.height() - halfOfHalfHeight * 2;
this->setFixedHeight(finalHeight);
// Centering dialog
int x = (screenGeometry.width() - this->width()) / 2;
int y = (screenGeometry.height() - this->height()) / 2;
this->move(x, y);
// Button sizes
if(global::deviceID == "n705\n") {
ui->refreshBtn->setStyleSheet("padding: 20px;");
ui->stopBtn->setStyleSheet("padding: 20px;");
ui->logBtn->setStyleSheet("padding: 20px;");
}
else {
ui->refreshBtn->setStyleSheet("padding: 25px;");
ui->stopBtn->setStyleSheet("padding: 25px;");
ui->logBtn->setStyleSheet("padding: 25px;");
}
// Set Wi-Fi checkbox state. Ignore the first call.
global::wifi::wifiState currentWifiState = checkWifiState();
if(currentWifiState != global::wifi::wifiState::disabled and currentWifiState != global::wifi::wifiState::unknown) {
ui->wifiCheckBox->setChecked(true);
// To be sure nothing breaks
refreshFromWatcher = true;
ui->refreshBtn->click();
} else {
wifiButtonEnabled = true;
ui->stopBtn->setStyleSheet(ui->stopBtn->styleSheet() + "background-color: lightGray;");
ui->stopBtn->setEnabled(false);
}
// To avoid confusion with reconnecting
QTimer::singleShot(0, this, SLOT(watcher()));
}
wifiDialog::~wifiDialog()
@ -39,105 +87,443 @@ wifiDialog::~wifiDialog()
delete ui;
}
void wifiDialog::checkWifiNetworks() {
string_writeconfig("/opt/ibxd", "list_wifi_networks\n");
wifiListTimer->setInterval(100);
connect(wifiListTimer, &QTimer::timeout, [&]() {
if(QFile::exists("/run/wifi_networks_list")) {
printWifiNetworks();
wifiListTimer->stop();
void wifiDialog::on_refreshBtn_clicked()
{
log("Clicked refresh button", className);
if(checkWifiState() == global::wifi::wifiState::disabled) {
if(refreshFromWatcher == true) {
refreshFromWatcher = false;
emit showToast("To scan, turn Wi-Fi on first");
}
} );
wifiListTimer->start();
}
void wifiDialog::printWifiNetworks() {
if(readFile("/run/wifi_networks_list").isEmpty()) {
log("Wi-Fi networks list empty", className);
QFile::remove("/run/wifi_networks_list");
emit quit(1);
wifiDialog::close();
}
else {
log("Parsing Wi-Fi networks list", className);
QFile wifiNetworksListFile("/run/wifi_networks_list");
wifiNetworksListFile.open(QIODevice::ReadWrite);
QTextStream in (&wifiNetworksListFile);
wifiNetworksList = in.readAll();
wifiNetworksListFile.close();
QFile::remove("/run/wifi_networks_list");
QStringListModel* model = new QStringListModel(this);
QStringList list = wifiNetworksList.split("\n", QString::SkipEmptyParts);
model->setStringList(list);
ui->networksListWidget->setModel(model);
ui->networksListWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);
emit wifiNetworksListReady(1);
refreshFromWatcher = false;
launchRefresh();
}
}
void wifiDialog::centerDialog() {
// Centering dialog
// Get current screen size
QRect rec = QGuiApplication::screenAt(this->pos())->geometry();
// Using minimum size of window
QSize size = this->minimumSize();
// Set top left point
QPoint topLeft = QPoint((rec.width() / 2) - (size.width() / 2), (rec.height() / 2) - (size.height() / 2));
// set window position
setGeometry(QRect(topLeft, size));
void wifiDialog::launchRefresh() {
// Order is important
if(scanInProgress == false) {
scanInProgress = true;
ui->refreshBtn->setStyleSheet(ui->refreshBtn->styleSheet() + "background-color: lightGray;");
ui->refreshBtn->setEnabled(false);
elapsedSeconds = 0;
fullList.remove();
formattedList.remove();
writeFile("/opt/ibxd", "list_wifi_networks\n");
QTimer::singleShot(0, this, SLOT(refreshWait()));
}
else {
log("Scan is already in progress", className);
}
}
void wifiDialog::on_cancelBtn_clicked()
void wifiDialog::refreshWait() {
if(fullList.exists() == false and formattedList.exists() == false) {
if(elapsedSeconds == 6) {
emit showToast("Failed to get networks list");
ui->refreshBtn->setStyleSheet(ui->refreshBtn->styleSheet() + "background-color: white;");
ui->refreshBtn->setEnabled(true);
scanInProgress = false;
}
else {
elapsedSeconds = elapsedSeconds + 1;
QTimer::singleShot(1000, this, SLOT(refreshWait()));
}
} else {
log("Retrieved network list successfully", className);
refreshNetworksList();
}
}
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", className);
continue;
}
for(QString singleData: data) {
if(count == 1) {
singleNetwork.mac = singleData;
log("MAC is: " + singleData, className);
}
if(count == 2) {
if(singleData.isEmpty() == true) {
log("Network name is empty", className);
}
else {
log("Network name is: '" + singleData + "'", className);
}
singleNetwork.name = singleData;
}
if(count == 3) {
log("Encryption type 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 additional items from network information", className);
}
count = count + 1;
}
// Filter out remaining empty networks
if(singleNetwork.name.isEmpty() == false) {
pureNetworkList.append(singleNetwork);
}
}
log("Found " + QString::number(pureNetworkList.count()) + " valid networks", className);
if(pureNetworkList.count() == 0) {
if(secondScanTry == false) {
secondScanTry = true;
if(checkWifiState() != global::wifi::wifiState::disabled) {
scanInProgress = false;
QTimer::singleShot(0, this, SLOT(launchRefresh()));
log("No networks found. Trying one more time");
return void();
}
else {
return void();
}
}
else {
secondScanTry = false;
log("No networks found, skipping", className);
showToastSlot("No networks found");
ui->refreshBtn->setEnabled(true);
ui->refreshBtn->setStyleSheet(ui->refreshBtn->styleSheet() + "background-color: white;");
scanInProgress = false;
return void();
}
}
QFile currentWifiNameFile = QFile("/external_root/run/current_wifi_name");
currentWifiNameFile.remove();
writeFile("/opt/ibxd", "get_current_wifi_name\n");
usleep(300000); // 0.3s
// Here, it's looking for the currently connected network to put it on top of the list
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(currentWifiNetwork.isEmpty() == false and wifiNetwork.name == currentWifiNetwork) {
log("Found current network in vector", className);
vectorNetworkLocation = countVec;
currentNetwork = wifiNetwork.name;
network* connectedNetwork = new network;
connectedNetwork->mainData = wifiNetwork;
// To be really sure that the the info is put there
connectedNetwork->currentlyConnectedNetwork = currentNetwork;
connectedNetworkDataParent = wifiNetwork;
connectedNetworkDataParentSet = true;
// This doesn't work, so a layout is needed
// ui->scrollArea->addScrollBarWidget(connectedNetwork, Qt::AlignTop);
connectedNetwork->applyVariables();
connect(this, &wifiDialog::killNetworkWidgets, connectedNetwork, &network::closeWrapper);
connect(connectedNetwork, &network::showToastSignal, this, &wifiDialog::showToastSlot);
connect(connectedNetwork, &network::refreshScreenSignal, this, &wifiDialog::refreshScreenSlot);
ui->scrollBarLayout->addWidget(connectedNetwork, Qt::AlignTop);
}
else {
countVec = countVec + 1;
}
}
if(vectorNetworkLocation != 9999) {
log("pureNetworkList size is: " + QString::number(pureNetworkList.count()) + ", entry at " + QString::number(vectorNetworkLocation) + " slated for removal", className);
pureNetworkList.removeAt(vectorNetworkLocation);
}
}
// Sort based on signal strength
QVector<global::wifi::wifiNetworkData> sortedPureNetworkList;
sortedPureNetworkList.append(pureNetworkList.first());
pureNetworkList.removeFirst();
// Possible fix for a segmentation fault
if(pureNetworkList.isEmpty() == false) {
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;
}
}
// This happens if it's the smallest value, so insert it at the end
if(stopIterating == false) {
sortedPureNetworkList.append(wifiNetwork);
}
}
}
log("There are " + QString::number(sortedPureNetworkList.count()) + " sorted networks", className);
for(global::wifi::wifiNetworkData wifiNetwork: sortedPureNetworkList) {
log("Signal strength with sorting: " + QString::number(wifiNetwork.signal), className);
}
// And now, handle the remainder of the networks
for(global::wifi::wifiNetworkData wifiNetwork: sortedPureNetworkList) {
network* connectedNetwork = new network;
connectedNetwork->mainData = wifiNetwork;
connectedNetwork->currentlyConnectedNetwork = currentNetwork;
connectedNetwork->applyVariables();
connect(this, &wifiDialog::killNetworkWidgets, connectedNetwork, &network::closeWrapper);
connect(connectedNetwork, &network::showToastSignal, this, &wifiDialog::showToastSlot);
connect(connectedNetwork, &network::refreshScreenSignal, this, &wifiDialog::refreshScreenSlot);
ui->scrollBarLayout->addWidget(connectedNetwork, Qt::AlignTop);
}
scannedAtLeastOnce = true;
ui->refreshBtn->setEnabled(true);
ui->refreshBtn->setStyleSheet(ui->refreshBtn->styleSheet() + "background-color: white;");
scanInProgress = false;
secondScanTry = false;
}
void wifiDialog::on_wifiCheckBox_stateChanged(int arg1)
{
if(ignoreCheckBoxCall == false) {
connectedNetworkDataParentSet = false;
log("Wi-Fi dialog checkbox clicked: " + QString::number(arg1), className);
if(wifiButtonEnabled == true) {
if(arg1 == 2) {
log("Turning Wi-Fi on", className);
// The watcher will scan Wi-Fi
QTimer::singleShot(0, this, SLOT(turnOnWifi()));
ui->stopBtn->setStyleSheet(ui->stopBtn->styleSheet() + "background-color: white;");
ui->stopBtn->setEnabled(true);
} else {
log("Turning Wi-Fi off", className);
QTimer::singleShot(0, this, SLOT(turnOffWifi()));
// To inform the Wi-Fi icon updater to not show the connected/failed to connect message
string_writeconfig("/mnt/onboard/.adds/inkbox/.config/17-wifi_connection_information/stopped", "true");
ui->stopBtn->setStyleSheet(ui->stopBtn->styleSheet() + "background-color: lightGray;");
ui->stopBtn->setEnabled(false);
}
emit killNetworkWidgets();
}
if(wifiButtonEnabled == false){
wifiButtonEnabled = true;
}
}
else {
ignoreCheckBoxCall = false;
if(checkWifiState() != global::wifi::wifiState::disabled) {
emit killNetworkWidgets();
forceRefresh = true;
}
else {
emit killNetworkWidgets();
}
}
}
void wifiDialog::turnOnWifi() {
string_writeconfig("/opt/ibxd", "toggle_wifi_on\n");
// No one will notice this freeze :>
waitToScan();
}
void wifiDialog::turnOffWifi() {
string_writeconfig("/opt/ibxd", "toggle_wifi_off\n");
while(true) {
if(QFile::exists("/run/toggle_wifi_off_done")) {
QFile::remove("/run/toggle_wifi_off_done");
break;
}
}
emit quit(0);
wifiDialog::close();
}
void wifiDialog::on_connectBtn_clicked()
void wifiDialog::on_logBtn_clicked()
{
index = ui->networksListWidget->currentIndex();
itemText = index.data(Qt::DisplayRole).toString();
if(itemText.isEmpty()) {
showToast("You must select a network");
// To avoid half of the information
if(scannedAtLeastOnce == false and checkWifiState() == global::wifi::wifiState::configured) {
log("Scanning at least once is needed");
emit showToast("Scan at least once");
} else {
wifilogger* wifiLoggerDialog = new wifilogger;
if(connectedNetworkDataParentSet == true) {
wifiLoggerDialog->connectedNetworkData = connectedNetworkDataParent;
wifiLoggerDialog->isThereData = true;
}
wifiLoggerDialog->exec();
}
}
void wifiDialog::showToastSlot(QString message) {
emit showToast(message);
}
void wifiDialog::refreshScreenSlot() {
this->repaint();
}
/*
Some documentation used by the watcher
* 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 Wi-Fi reconnections after sleeping/booting
* get_dhcp.sh - Gets dhcp addresses
* prepare_changing_wifi.sh - Kills everything, prepares to changing network
* timesync.sh - Syncs time
* toggle.sh - Turns Wi-Fi adapter on/off
* list_networks - Lists networks
* check_wifi_passphrase.sh - Checks Wi-Fi network passphrase
* watcher() first watches at processes that could kill other ones
*/
void wifiDialog::watcher() {
bool killing = checkProcessName("toggle.sh");
bool changing = checkProcessName("prepare_changing_wifi.sh");
if(killing == true) {
setStatusText("Changing Wi-Fi adapter status");
isToggleRunning = true;
QTimer::singleShot(relaunchMs, this, SLOT(watcher()));
return void();
}
if(changing == true) {
setStatusText("Disconnecting from a network or cleaning up");
log("prepare_changing_wifi.sh is active", className);
QTimer::singleShot(relaunchMs, this, SLOT(watcher()));
return void();
}
bool reconnection = checkProcessName("connect_to_network.sh");
if(reconnection == true) {
forceRefresh = true;
QFile recName = QFile("/mnt/onboard/.adds/inkbox/.config/17-wifi_connection_information/essid");
if(recName.exists() == true) {
setStatusText("Reconnecting after suspending to " + readFile(recName.fileName()).replace("\n", ""));
}
else {
this->hide();
global::keyboard::keyboardDialog = true;
global::keyboard::wifiPassphraseDialog = true;
global::keyboard::keyboardText = "";
generalDialogWindow = new generalDialog();
generalDialogWindow->setAttribute(Qt::WA_DeleteOnClose);
generalDialogWindow->wifiEssid = itemText;
connect(generalDialogWindow, SIGNAL(refreshScreen()), SLOT(refreshScreenNative()));
connect(generalDialogWindow, SIGNAL(updateWifiIcon(int)), SLOT(updateWifiIcon(int)));
connect(generalDialogWindow, SIGNAL(showToast(QString)), SLOT(showToastNative(QString)));
connect(generalDialogWindow, SIGNAL(closeIndefiniteToast()), SLOT(closeIndefiniteToastNative()));
connect(generalDialogWindow, SIGNAL(destroyed(QObject*)), SLOT(close()));
generalDialogWindow->show();
// Shouldn't be possible
setStatusText("Reconnecting after sleep");
}
QTimer::singleShot(relaunchMs, this, SLOT(watcher()));
return void();
}
bool listing = checkProcessName("list_networks");
if(listing == true) {
setStatusText("Scanning available networks");
QTimer::singleShot(relaunchMs, this, SLOT(watcher()));
return void();
}
bool dhcp = checkProcessName("get_dhcp.sh");
if(dhcp == true) {
forceRefresh = true;
setStatusText("Getting IP address");
QTimer::singleShot(relaunchMs, this, SLOT(watcher()));
return void();
}
bool passphraseCheck = checkProcessName("check_wifi_passphrase.sh");
if(passphraseCheck == true) {
forceRefresh = true;
setStatusText("Checking Wi-Fi network passphrase");
QTimer::singleShot(relaunchMs, this, SLOT(watcher()));
return void();
}
bool time = checkProcessName("timesync.sh");
if(time == true) {
forceRefresh = true;
setStatusText("Syncing time");
QTimer::singleShot(relaunchMs, this, SLOT(watcher()));
return void();
}
bool connecting = checkProcessName("connection_manager.sh");
if(connecting == true) {
forceRefresh = true;
setStatusText("Connecting to Wi-Fi network");
QTimer::singleShot(relaunchMs, this, SLOT(watcher()));
return void();
}
if(ui->statusLabel->text() != "Idle") {
setStatusText("Idle");
}
if(unlockCheckBox == true) {
ui->wifiCheckBox->setEnabled(true);
unlockCheckBox = false;
}
if(isToggleRunning == true) {
isToggleRunning = false;
// Make sure the checkbox is in the right state
if(checkWifiState() == global::wifi::wifiState::disabled) {
// In this state, ignore forceRefresh to avoid message
forceRefresh = false;
if(ui->wifiCheckBox->isChecked() == true) {
ignoreCheckBoxCall = true;
ui->wifiCheckBox->setChecked(false);
}
}
else {
if(ui->wifiCheckBox->isChecked() == false) {
ignoreCheckBoxCall = true;
ui->wifiCheckBox->setChecked(true);
}
}
}
void wifiDialog::refreshScreenNative() {
emit refreshScreen();
if(forceRefresh == true) {
forceRefresh = false;
refreshFromWatcher = true;
QTimer::singleShot(1500, this, SLOT(waitToScan()));
}
void wifiDialog::updateWifiIcon(int mode) {
emit updateWifiIconSig(mode);
QTimer::singleShot(relaunchMs, this, SLOT(watcher()));
}
void wifiDialog::showToastNative(QString messageToDisplay) {
emit showToast(messageToDisplay);
void wifiDialog::setStatusText(QString message) {
ui->statusLabel->setText(message);
}
void wifiDialog::closeIndefiniteToastNative() {
emit closeIndefiniteToast();
void wifiDialog::on_stopBtn_clicked()
{
log("Stop button was clicked", className);
connectedNetworkDataParentSet = false;
ui->wifiCheckBox->setEnabled(false);
unlockCheckBox = true;
// To inform the wifi icon GUI to don't show the connected/failed to connect message
writeFile("/mnt/onboard/.adds/inkbox/.config/17-wifi_connection_information/stopped", "true");
writeFile("/opt/ibxd", "stop_wifi_operations\n");
QFile("/mnt/onboard/.adds/inkbox/.config/17-wifi_connection_information/essid").remove();
QFile("/mnt/onboard/.adds/inkbox/.config/17-wifi_connection_information/passphrase").remove();
// This variable just avoids showing the toast, so it is usable here too
waitToScan();
}
void wifiDialog::on_returnBtn_clicked()
{
this->deleteLater();
this->close();
}
void wifiDialog::waitToScan() {
if(checkWifiState() != global::wifi::wifiState::disabled) {
ui->refreshBtn->click();
}
else {
QTimer::singleShot(750, this, SLOT(waitToScan()));
}
}

View file

@ -5,6 +5,7 @@
#include <QModelIndex>
#include "generaldialog.h"
#include "wifilogger.h"
namespace Ui {
class wifiDialog;
@ -18,33 +19,60 @@ public:
QString className = this->metaObject()->className();
explicit wifiDialog(QWidget *parent = nullptr);
~wifiDialog();
QString wifiNetworksList;
QString itemText;
QModelIndex index;
void checkWifiNetworks();
void printWifiNetworks();
void centerDialog();
global::wifi::wifiNetworkData connectedNetworkDataParent;
bool connectedNetworkDataParentSet = false;
private:
Ui::wifiDialog *ui;
QTimer * wifiListTimer;
generalDialog * generalDialogWindow;
bool wifiButtonEnabled = false;
bool scannedAtLeastOnce = false;
// Variables for refreshWait() and network refresh in general
int elapsedSeconds = 0;
QFile fullList = QFile("/external_root/run/wifi_list_full");
QFile formattedList = QFile("/external_root/run/wifi_list_format");
// Used by watcher
bool forceRefresh = false;
int relaunchMs = 300;
bool refreshFromWatcher = false;
bool unlockCheckBox = false;
bool scanInProgress = false;
bool isToggleRunning = false;
bool ignoreCheckBoxCall = false;
bool secondScanTry = false;
public slots:
void launchRefresh();
void refreshNetworksList();
void showToastSlot(QString message);
void refreshScreenSlot();
// Shows status of Wi-Fi processes, like reconnection and others. Also manages refreshing the networks list after connection
void watcher();
signals:
void wifiNetworksListReady(int networksFound);
void quit(int exitCode);
void refreshScreen();
void updateWifiIconSig(int mode);
void showToast(QString messageToDisplay);
void closeIndefiniteToast();
void killNetworkWidgets();
private slots:
void on_cancelBtn_clicked();
void on_connectBtn_clicked();
void refreshScreenNative();
void updateWifiIcon(int mode);
void showToastNative(QString messageToDisplay);
void closeIndefiniteToastNative();
void on_refreshBtn_clicked();
void on_wifiCheckBox_stateChanged(int arg1);
void turnOnWifi();
void turnOffWifi();
void on_logBtn_clicked();
// This function is a more clever sleep(1), non-blocking
void refreshWait();
void setStatusText(QString message);
void on_stopBtn_clicked();
void on_returnBtn_clicked();
void waitToScan();
};
#endif // WIFIDIALOG_H

View file

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
<width>603</width>
<height>679</height>
</rect>
</property>
<property name="windowTitle">
@ -15,14 +15,197 @@
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="2" column="0">
<widget class="QStackedWidget" name="stackedWidget">
<property name="currentIndex">
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="sizeConstraint">
<enum>QLayout::SetFixedSize</enum>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="sizeConstraint">
<enum>QLayout::SetMaximumSize</enum>
</property>
<item>
<layout class="QVBoxLayout" name="verticalLayout_3">
<property name="spacing">
<number>2</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<property name="spacing">
<number>10</number>
</property>
<item>
<widget class="QPushButton" name="refreshBtn">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="Line" name="line_2">
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="stopBtn">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="Line" name="line_3">
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="logBtn">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3"/>
</item>
</layout>
</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="QCheckBox" name="wifiCheckBox">
<property name="layoutDirection">
<enum>Qt::RightToLeft</enum>
</property>
<property name="styleSheet">
<string notr="true">font-family: Inter; font-weight: bold</string>
</property>
<property name="text">
<string>Wi-Fi</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
<item>
<widget class="Line" name="line_4">
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="statusLabel">
<property name="font">
<font>
<family>u001</family>
<pointsize>9</pointsize>
</font>
</property>
<property name="styleSheet">
<string notr="true">padding-left: 10px; font-family: u001</string>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="Line" name="line_5">
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<widget class="QScrollArea" name="scrollArea">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="lineWidth">
<number>0</number>
</property>
<property name="verticalScrollBarPolicy">
<enum>Qt::ScrollBarAsNeeded</enum>
</property>
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>591</width>
<height>526</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="spacing">
<number>0</number>
</property>
<widget class="QWidget" name="page_2">
<layout class="QVBoxLayout" name="verticalLayout_3">
<property name="leftMargin">
<number>0</number>
</property>
@ -36,19 +219,56 @@
<number>0</number>
</property>
<item>
<layout class="QGridLayout" name="gridLayout_4">
<item row="1" column="0">
<widget class="QListView" name="networksListWidget">
<layout class="QVBoxLayout" name="scrollBarLayoutParent">
<property name="spacing">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<item>
<layout class="QVBoxLayout" name="scrollBarLayout"/>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
</widget>
</item>
<item>
<widget class="Line" name="line">
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="lineWidth">
<number>2</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="returnBtn">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="mainLabel">
<property name="font">
<font>
<weight>75</weight>
@ -56,42 +276,10 @@
</font>
</property>
<property name="text">
<string>Select a network</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
<string>Return</string>
</property>
</widget>
</item>
<item row="2" column="0">
<layout class="QGridLayout" name="gridLayout_2">
<property name="bottomMargin">
<number>0</number>
</property>
<item row="0" column="1">
<widget class="QPushButton" name="connectBtn">
<property name="text">
<string>Connect</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QPushButton" name="cancelBtn">
<property name="text">
<string>Cancel</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>

View file

@ -0,0 +1,206 @@
#include <QFile>
#include <QScrollBar>
#include <QScreen>
#include "wifilogger.h"
#include "ui_wifilogger.h"
#include "functions.h"
wifilogger::wifilogger(QWidget *parent) :
QDialog(parent),
ui(new Ui::wifilogger)
{
ui->setupUi(this);
this->setFont(QFont("u001"));
// 'Not currently connected to a network' label
ui->label_8->setFont(QFont("Inter"));
ui->returnBtn->setFont(QFont("Inter"));
ui->nameLabel->setFont(QFont("Inter"));
ui->allLogsText->setFont(QFont("Noto Mono"));
ui->fancyLogsText->setFont(QFont("Noto Mono"));
ui->nameLabel->setStyleSheet("font-weight: bold");
ui->returnBtn->setStyleSheet("font-weight: bold");
ui->allLogsText->setStyleSheet("font-size: 7pt");
ui->fancyLogsText->setStyleSheet("font-size: 7pt");
// Stylesheet, style & misc.
QFile stylesheetFile("/mnt/onboard/.adds/inkbox/eink.qss");
stylesheetFile.open(QFile::ReadOnly);
this->setStyleSheet(stylesheetFile.readAll());
stylesheetFile.close();
this->setModal(true);
// Scroll bar
// Needed for the nia.
// ui->allLogsText->verticalScrollBar()->setStyleSheet("QScrollBar:vertical { width: 50px; }");
// ui->fancyLogsText->verticalScrollBar()->setStyleSheet("QScrollBar:vertical { width: 50px; }");
log("Entered wifilogger", className);
setWifiInfoPage();
ui->previousBtn->setProperty("type", "borderless");
ui->nextBtn->setProperty("type", "borderless");
ui->returnBtn->setProperty("type", "borderless");
ui->refreshBtn->setProperty("type", "borderless");
// Size
QRect screenGeometry = QGuiApplication::screens()[0]->geometry();
this->setFixedWidth(screenGeometry.width() / 1.2);
int halfOfHalfHeight = ((screenGeometry.height() / 2) / 2) / 2;
int finalHeight = screenGeometry.height() - halfOfHalfHeight * 2.4;
this->setFixedHeight(finalHeight);
// Centering dialog
int x = (screenGeometry.width() - this->width()) / 2;
int y = (screenGeometry.height() - this->height()) / 2;
this->move(x, y);
}
wifilogger::~wifilogger()
{
delete ui;
}
void wifilogger::setWifiInfoPage() {
if(checkWifiState() == global::wifi::wifiState::configured) {
getWifiInformationTimer.singleShot(0, this, SLOT(getWifiInformation()));
ui->stackedWidget->setCurrentIndex(0);
ui->nameLabel->setText("Network information");
}
else {
ui->stackedWidget->setCurrentIndex(1);
ui->nameLabel->setText("Not connected to a network");
}
}
void wifilogger::setFancyLoggingPage() {
updateLogs();
ui->stackedWidget->setCurrentIndex(2);
ui->nameLabel->setText("Important logs");
}
void wifilogger::setAllLogsPage() {
updateLogs();
ui->stackedWidget->setCurrentIndex(3);
ui->nameLabel->setText("All logs");
}
void wifilogger::on_nextBtn_clicked()
{
if(currentPage == 2) {
currentPage = 0;
}
else {
currentPage = currentPage + 1;
}
changePage();
}
void wifilogger::on_previousBtn_clicked()
{
if(currentPage == 0) {
currentPage = 2;
}
else {
currentPage = currentPage - 1;
}
changePage();
}
void wifilogger::changePage() {
if(currentPage == 0) {
setWifiInfoPage();
}
else if(currentPage == 1) {
setFancyLoggingPage();
}
else if(currentPage == 2) {
setAllLogsPage();
}
else {
log("This shouldn't happen", className);
}
}
void wifilogger::getWifiInformation() {
log("Retrieving Wi-Fi information", className);
QFile wifiInformationPath = QFile("/external_root/run/wifi_information");
if(waitingForFile == false) {
wifiInformationPath.remove();
log("Sending get_wifi_information ibxd call", className);
string_writeconfig("/opt/ibxd", "get_wifi_information\n");
waitingForFile = true;
}
if(waitingForFile == true) {
if(wifiInformationPath.exists() == false) {
getWifiInformationTimer.singleShot(1000, this, SLOT(getWifiInformation()));
return void();
}
}
waitingForFile = false;
log("Setting variables", className);
QString wifiInfo = readFile(wifiInformationPath.fileName());
QStringList wifiInfoList = wifiInfo.split("\n");
int counter = 0;
for(QString infomation: wifiInfoList) {
if(counter == 0) {
ui->netNameLabel->setText(infomation);
}
if(counter == 1) {
ui->ipLabel->setText(infomation);
}
if(counter == 2) {
ui->maskLabel->setText(infomation);
}
if(counter == 3) {
ui->gatewayLabel->setText(infomation);
}
counter = counter + 1;
}
if(isThereData == true) {
ui->encryptionLabel->setText(QVariant(connectedNetworkData.encryption).toString());
ui->signalLabel->setText(QString::number(connectedNetworkData.signal) + "%");
ui->macLabel->setText(connectedNetworkData.mac);
}
else {
// Shouldn't happen for 99%, but if anyway... it's designed to be non-blocking, so I can't really wait for this.
ui->encryptionLabel->setText("Rescan needed");
ui->signalLabel->setText("Rescan needed");
ui->macLabel->setText("Rescan needed");
}
}
void wifilogger::on_returnBtn_clicked()
{
log("Exiting wifilogger", className);
getWifiInformationTimer.stop();
this->deleteLater();
this->close();
}
void wifilogger::updateLogs() {
if(fancyLogs.exists() == true and allLogs.exists() == true) {
QString fancyLogsText = readFile(fancyLogs.fileName());
QString allLogsText = readFile(allLogs.fileName());
ui->fancyLogsText->setText(fancyLogsText);
ui->allLogsText->setText(allLogsText);
}
}
void wifilogger::on_refreshBtn_clicked()
{
if(currentPage == 0) {
if(waitingForFile == false) {
setWifiInfoPage();
}
}
else {
updateLogs();
}
}

View file

@ -0,0 +1,49 @@
#ifndef WIFILOGGER_H
#define WIFILOGGER_H
#include <QDialog>
#include "functions.h"
namespace Ui {
class wifilogger;
}
class wifilogger : public QDialog
{
Q_OBJECT
public:
QString className = this->metaObject()->className();
explicit wifilogger(QWidget *parent = nullptr);
~wifilogger();
global::wifi::wifiNetworkData connectedNetworkData;
// To the above value
bool isThereData = false;
private:
Ui::wifilogger *ui;
/*
* 0 Is Wi-Fi info/no Wi-Fi info page
* 1 Is fancy logs page
* 2 Is all logs page
*/
int currentPage = 0;
QFile fancyLogs = QFile("/external_root/run/wifi_stats");
QFile allLogs = QFile("/external_root/var/log/wifi.log");
bool waitingForFile = false;
QTimer getWifiInformationTimer;
private slots:
void setWifiInfoPage();
void setFancyLoggingPage();
void setAllLogsPage();
void on_nextBtn_clicked();
void on_previousBtn_clicked();
void changePage();
void getWifiInformation();
void on_returnBtn_clicked();
void updateLogs();
void on_refreshBtn_clicked();
};
#endif // WIFILOGGER_H

View file

@ -0,0 +1,565 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>wifilogger</class>
<widget class="QDialog" name="wifilogger">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>476</width>
<height>317</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="1" column="0">
<widget class="QScrollArea" name="scrollArea">
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents_2">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>460</width>
<height>210</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="leftMargin">
<number>9</number>
</property>
<property name="topMargin">
<number>9</number>
</property>
<property name="rightMargin">
<number>9</number>
</property>
<property name="bottomMargin">
<number>9</number>
</property>
<item>
<widget class="QStackedWidget" name="stackedWidget">
<property name="lineWidth">
<number>0</number>
</property>
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="page_0">
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QLabel" name="label_3">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Network name: </string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="netNameLabel">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="label">
<property name="font">
<font>
<weight>75</weight>
<italic>false</italic>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>IP address:</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="ipLabel">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QLabel" name="label_4">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Mask: </string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="maskLabel">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_5">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_7">
<item>
<widget class="QLabel" name="label_5">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Gateway: </string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="gatewayLabel">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_6">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_10">
<item>
<widget class="QLabel" name="label_6">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Passphrase-protected:</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="encryptionLabel">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_7">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_12">
<item>
<widget class="QLabel" name="label_2">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Signal strength: </string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="signalLabel">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_8">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_15">
<item>
<widget class="QLabel" name="label_7">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>MAC address: </string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="macLabel">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_9">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
<widget class="QWidget" name="page_0_fallback">
<layout class="QGridLayout" name="gridLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item row="0" column="0">
<widget class="QLabel" name="label_8">
<property name="font">
<font>
<family>Inter</family>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="styleSheet">
<string notr="true">font-family: Inter; font-weight: bold</string>
</property>
<property name="lineWidth">
<number>0</number>
</property>
<property name="text">
<string>Not currently connected to a network</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="page_1">
<layout class="QGridLayout" name="gridLayout_3">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item row="0" column="0">
<widget class="QTextBrowser" name="fancyLogsText">
<property name="textInteractionFlags">
<set>Qt::NoTextInteraction</set>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="page_2">
<layout class="QGridLayout" name="gridLayout_4">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item row="0" column="0">
<widget class="QTextBrowser" name="allLogsText">
<property name="textInteractionFlags">
<set>Qt::NoTextInteraction</set>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
<item row="0" column="0">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QPushButton" name="previousBtn">
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../../../eink.qrc">
<normaloff>:/resources/chevron-left.png</normaloff>:/resources/chevron-left.png</iconset>
</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="QLabel" name="nameLabel">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<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="nextBtn">
<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>
</item>
<item row="4" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<property name="topMargin">
<number>0</number>
</property>
<item>
<widget class="QPushButton" name="returnBtn">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Return</string>
</property>
</widget>
</item>
<item>
<widget class="Line" name="line">
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="refreshBtn">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../../../eink.qrc">
<normaloff>:/resources/refresh.png</normaloff>:/resources/refresh.png</iconset>
</property>
</widget>
</item>
</layout>
</item>
<item row="2" column="0">
<widget class="Line" name="line_2">
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="lineWidth">
<number>2</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
</layout>
</widget>
<resources>
<include location="../../../eink.qrc"/>
</resources>
<connections/>
</ui>

View file

@ -27,20 +27,6 @@ toast::toast(QWidget *parent) :
global::toast::delay = 5000;
}
}
if(global::toast::wifiToast == true) {
global::toast::wifiToast = false;
this->setModal(true);
wifiDialogWindow = new wifiDialog(this);
wifiDialogWindow->setAttribute(Qt::WA_DeleteOnClose);
connect(wifiDialogWindow, SIGNAL(wifiNetworksListReady(int)), SLOT(showWifiDialog(int)));
connect(wifiDialogWindow, SIGNAL(quit(int)), SLOT(exitSlot(int)));
connect(wifiDialogWindow, SIGNAL(refreshScreen()), SLOT(refreshScreenNative()));
connect(wifiDialogWindow, SIGNAL(updateWifiIconSig(int)), SLOT(updateWifiIcon(int)));
connect(wifiDialogWindow, SIGNAL(showToast(QString)), SLOT(showToastNative(QString)));
connect(wifiDialogWindow, SIGNAL(closeIndefiniteToast()), SLOT(closeIndefiniteToastNative()));
connect(wifiDialogWindow, SIGNAL(destroyed(QObject*)), SLOT(close()));
}
else {
if(global::toast::indefiniteToast == false) {
QTimer::singleShot(global::toast::delay, this, SLOT(close()));
global::toast::delay = 0;
@ -49,23 +35,12 @@ toast::toast(QWidget *parent) :
global::toast::indefiniteToast = false;
}
}
}
toast::~toast()
{
delete ui;
}
void toast::showWifiDialog(int networksFound) {
if(networksFound == 1) {
emit updateWifiIconSig(2);
this->hide();
wifiDialogWindow->show();
wifiDialogWindow->adjustSize();
wifiDialogWindow->centerDialog();
}
}
void toast::centerToast() {
// Centering toast (https://stackoverflow.com/a/58682351)
// Get current screen size
@ -91,10 +66,6 @@ void toast::refreshScreenNative() {
emit refreshScreen();
}
void toast::updateWifiIcon(int mode) {
emit updateWifiIconSig(mode);
}
void toast::showToastNative(QString messageToDisplay) {
emit showToast(messageToDisplay);
}

View file

@ -21,13 +21,10 @@ public:
private:
Ui::toast *ui;
wifiDialog *wifiDialogWindow;
private slots:
void showWifiDialog(int networksFound);
void exitSlot(int exitCode);
void refreshScreenNative();
void updateWifiIcon(int mode);
void showToastNative(QString messageToDisplay);
void closeIndefiniteToastNative();