purging old cold, some new

This commit is contained in:
Szybet 2022-08-15 21:10:32 +02:00
parent aa8214a297
commit f2d269033d
17 changed files with 357 additions and 411 deletions

View file

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

View file

@ -84,5 +84,7 @@
<file>resources/highlight.png</file> <file>resources/highlight.png</file>
<file>resources/unhighlight.png</file> <file>resources/unhighlight.png</file>
<file>resources/view-highlights.png</file> <file>resources/view-highlights.png</file>
<file>resources/stop.png</file>
<file>resources/refresh.png</file>
</qresource> </qresource>
</RCC> </RCC>

View file

@ -92,7 +92,6 @@ namespace global {
} }
namespace toast { namespace toast {
inline QString message; inline QString message;
inline bool wifiToast;
inline bool modalToast; inline bool modalToast;
inline bool indefiniteToast; inline bool indefiniteToast;
inline int delay; inline int delay;
@ -100,9 +99,6 @@ namespace global {
namespace device { namespace device {
inline bool isWifiAble; inline bool isWifiAble;
} }
namespace network {
inline bool isConnected;
}
namespace otaUpdate { namespace otaUpdate {
inline bool isUpdateOta; inline bool isUpdateOta;
inline bool downloadOta; inline bool downloadOta;
@ -169,6 +165,17 @@ namespace global {
namespace highlightsListDialog { namespace highlightsListDialog {
inline QString bookPath; inline QString bookPath;
} }
namespace wifi {
// This is the correct way to do this.
enum class WifiState
{
Configured,
Enabled,
Disabled,
Unknown, // to not confuse lastWifiState
};
inline bool isConnected;
}
inline QString systemInfoText; inline QString systemInfoText;
inline bool forbidOpenSearchDialog; inline bool forbidOpenSearchDialog;
inline bool isN705 = false; inline bool isN705 = false;
@ -780,41 +787,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() { int get_warmth() {
QString sysfsWarmthPath; QString sysfsWarmthPath;
if(global::deviceID == "n873\n") { if(global::deviceID == "n873\n") {
@ -866,51 +838,6 @@ namespace {
return !!ptr; 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() { void updateUserAppsMainJsonFile() {
QDirIterator appsDir("/mnt/onboard/onboard/.apps", QDirIterator::NoIteratorFlags); QDirIterator appsDir("/mnt/onboard/onboard/.apps", QDirIterator::NoIteratorFlags);
QFile newJsonFile = QFile{"/mnt/onboard/onboard/.apps/apps.json"}; QFile newJsonFile = QFile{"/mnt/onboard/onboard/.apps/apps.json"};
@ -1135,6 +1062,55 @@ namespace {
return 2; return 2;
} }
} }
global::wifi::WifiState checkWifiState() {
QProcess *wifiStateProcess = new QProcess();
// Important to remember thats its in chroot...
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 doesnt exist");
}
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;
log("Critical error, checkWifiState()", "functions.h");
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;
}
} }
#endif // FUNCTIONS_H #endif // FUNCTIONS_H

View file

@ -65,8 +65,6 @@ MainWindow::MainWindow(QWidget *parent)
global::usbms::koboxExportExtensions = false; global::usbms::koboxExportExtensions = false;
global::mainwindow::tabSwitcher::repaint = true; global::mainwindow::tabSwitcher::repaint = true;
resetFullWindowException = false; resetFullWindowException = false;
wifiIconClickedWhileReconnecting = false;
lastWifiState = 0;
// Getting the screen's size // Getting the screen's size
sW = QGuiApplication::screens()[0]->size().width(); sW = QGuiApplication::screens()[0]->size().width();
@ -134,9 +132,13 @@ MainWindow::MainWindow(QWidget *parent)
ui->brightnessBtn->setIcon(QIcon(":/resources/frontlight.png")); ui->brightnessBtn->setIcon(QIcon(":/resources/frontlight.png"));
ui->brightnessBtn->setIconSize(QSize(brightnessIconWidth, brightnessIconHeight)); ui->brightnessBtn->setIconSize(QSize(brightnessIconWidth, brightnessIconHeight));
setWifiIcon(); updateWifiState();
if(global::device::isWifiAble == true) { if(global::device::isWifiAble == true) {
updateWifiIcon(0); // Start wifi updater
QTimer *wifiIconTimer = new QTimer(this);
wifiIconTimer->setInterval(5000);
connect(wifiIconTimer, SIGNAL(timeout()), this, SLOT(updateWifiState()));
wifiIconTimer->start();
} }
setBatteryIcon(); setBatteryIcon();
@ -749,90 +751,34 @@ void MainWindow::setupSearchDialog() {
} }
} }
void MainWindow::updateWifiIcon(int mode) { void MainWindow::updateWifiIcon(global::wifi::WifiState mode) {
/* Usage: /* Usage:
* mode 0: auto * mode 0 is handled in mainwindow()
* mode 1: off
* mode 2: standby
* mode 3: connected
*/ */
if(mode == 0) { if(mode == global::wifi::WifiState::Disabled) {
lastWifiState = 0; lastWifiState = global::wifi::WifiState::Disabled;
QTimer *wifiIconTimer = new QTimer(this);
wifiIconTimer->setInterval(10000);
connect(wifiIconTimer, SIGNAL(timeout()), this, SLOT(setWifiIcon()));
wifiIconTimer->start();
}
if(mode == 1) {
lastWifiState = 1;
ui->wifiBtn->setIcon(QIcon(":/resources/wifi-off.png")); ui->wifiBtn->setIcon(QIcon(":/resources/wifi-off.png"));
ui->wifiBtn->setIconSize(QSize(wifiIconWidth, wifiIconHeight)); ui->wifiBtn->setIconSize(QSize(wifiIconWidth, wifiIconHeight));
} }
if(mode == 2) { if(mode == global::wifi::WifiState::Enabled) {
lastWifiState = 2; lastWifiState = global::wifi::WifiState::Enabled;
ui->wifiBtn->setIcon(QIcon(":/resources/wifi-standby.png")); ui->wifiBtn->setIcon(QIcon(":/resources/wifi-standby.png"));
ui->wifiBtn->setIconSize(QSize(wifiIconWidth, wifiIconHeight)); ui->wifiBtn->setIconSize(QSize(wifiIconWidth, wifiIconHeight));
} }
if(mode == 3) { if(mode == global::wifi::WifiState::Configured) {
lastWifiState = 3; lastWifiState = global::wifi::WifiState::Configured;
ui->wifiBtn->setIcon(QIcon(":/resources/wifi-connected.png")); ui->wifiBtn->setIcon(QIcon(":/resources/wifi-connected.png"));
ui->wifiBtn->setIconSize(QSize(wifiIconWidth, wifiIconHeight)); ui->wifiBtn->setIconSize(QSize(wifiIconWidth, wifiIconHeight));
} }
} }
bool MainWindow::checkWifiState() { void MainWindow::updateWifiState() {
/* Return value:
* true: interface UP
* false: interface DOWN
*/
if(global::deviceID == "n437\n") {
string_checkconfig_ro("/sys/class/net/wlan0/operstate");
}
else {
string_checkconfig_ro("/sys/class/net/eth0/operstate");
}
if(checkconfig_str_val == "up\n") {
return true;
}
else {
return false;
}
}
void MainWindow::setWifiIcon() {
if(global::device::isWifiAble == true) { if(global::device::isWifiAble == true) {
if(checkWifiState() == true) { global::wifi::WifiState currentWifiState = checkWifiState();
// testPing() the non-blocking way if(lastWifiState != currentWifiState) {
QProcess * pingProcess = new QProcess(); // This is handled by updateWifiIcon()
QString pingProg = "sh"; //lastWifiState = currentWifiState;
QStringList pingArgs; updateWifiIcon(currentWifiState);
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"));
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 { else {
@ -841,31 +787,10 @@ void MainWindow::setWifiIcon() {
} }
} }
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() void MainWindow::on_wifiBtn_clicked()
{ {
openWifiDialog(); wifiDialog* newWIfiDialog = new wifiDialog();
newWIfiDialog->exec();
} }
void MainWindow::showToast(QString messageToDisplay) { void MainWindow::showToast(QString messageToDisplay) {
@ -963,7 +888,7 @@ void MainWindow::openEncfsRepackDialog() {
void MainWindow::on_libraryButton_clicked() void MainWindow::on_libraryButton_clicked()
{ {
log("Launching Online Library", className); log("Launching Online Library", className);
if(testPing(true) == 0 or global::deviceID == "emu\n") { if(testPing() == 0 or global::deviceID == "emu\n") {
resetFullWindowException = true; resetFullWindowException = true;
resetWindow(false); resetWindow(false);
if(global::mainwindow::tabSwitcher::libraryWidgetSelected != true) { if(global::mainwindow::tabSwitcher::libraryWidgetSelected != true) {
@ -1000,7 +925,7 @@ void MainWindow::resetFullWindow() {
} }
void MainWindow::checkForOtaUpdate() { void MainWindow::checkForOtaUpdate() {
if(global::network::isConnected == true) { if(global::wifi::isConnected == true) {
string_checkconfig_ro("/external_root/opt/storage/update/last_sync"); string_checkconfig_ro("/external_root/opt/storage/update/last_sync");
if(!checkconfig_str_val.isEmpty()) { if(!checkconfig_str_val.isEmpty()) {
unsigned long currentEpoch = QDateTime::currentSecsSinceEpoch(); unsigned long currentEpoch = QDateTime::currentSecsSinceEpoch();
@ -1016,10 +941,6 @@ void MainWindow::checkForOtaUpdate() {
} }
} }
void MainWindow::resetWifiIconClickedWhileReconnecting() {
wifiIconClickedWhileReconnecting = false;
}
void MainWindow::setupLocalLibraryWidget() { void MainWindow::setupLocalLibraryWidget() {
localLibraryWidgetWindow = new localLibraryWidget(this); localLibraryWidgetWindow = new localLibraryWidget(this);
QObject::connect(localLibraryWidgetWindow, &localLibraryWidget::openBookSignal, this, &MainWindow::openBookFile); QObject::connect(localLibraryWidgetWindow, &localLibraryWidget::openBookSignal, this, &MainWindow::openBookFile);

View file

@ -51,8 +51,7 @@ public:
bool existing_recent_books = false; bool existing_recent_books = false;
bool reboot_after_update = false; bool reboot_after_update = false;
bool resetFullWindowException; bool resetFullWindowException;
bool wifiIconClickedWhileReconnecting; global::wifi::WifiState lastWifiState = global::wifi::WifiState::Unknown;
int lastWifiState;
int timerTime = 0; int timerTime = 0;
QString relative_path; QString relative_path;
QString usbmsStatus; QString usbmsStatus;
@ -62,7 +61,6 @@ public:
void openUsbmsDialog(); void openUsbmsDialog();
void resetIcons(); void resetIcons();
void setBatteryIcon(); void setBatteryIcon();
bool checkWifiState();
public slots: public slots:
@ -74,14 +72,13 @@ private slots:
void on_quitBtn_clicked(); void on_quitBtn_clicked();
void on_brightnessBtn_clicked(); void on_brightnessBtn_clicked();
void openUpdateDialog(); void openUpdateDialog();
void openWifiDialog();
void setInitialBrightness(); void setInitialBrightness();
void on_homeBtn_clicked(); void on_homeBtn_clicked();
void refreshScreen(); void refreshScreen();
void setupSearchDialog(); void setupSearchDialog();
void setWifiIcon(); void updateWifiState();
void on_wifiBtn_clicked(); void on_wifiBtn_clicked();
void updateWifiIcon(int mode); void updateWifiIcon(global::wifi::WifiState mode);
void hello(int testNumber); void hello(int testNumber);
void showToast(QString messageToDisplay); void showToast(QString messageToDisplay);
void closeIndefiniteToast(); void closeIndefiniteToast();
@ -95,7 +92,6 @@ private slots:
void on_libraryButton_clicked(); void on_libraryButton_clicked();
void resetWindow(bool resetStackedWidget); void resetWindow(bool resetStackedWidget);
void resetFullWindow(); void resetFullWindow();
void resetWifiIconClickedWhileReconnecting();
void setupLocalLibraryWidget(); void setupLocalLibraryWidget();
void setupHomePageWidget(); void setupHomePageWidget();

View file

@ -41,6 +41,9 @@ int main(int argc, char *argv[])
global::logger::status = true; global::logger::status = true;
} }
} }
// Szybet testing
global::logger::status = true;
global::deviceID = readFile("/opt/inkbox_device"); global::deviceID = readFile("/opt/inkbox_device");
log("Running on device " + global::deviceID, "main", true); log("Running on device " + global::deviceID, "main", true);
@ -226,7 +229,8 @@ int main(int argc, char *argv[])
} }
const QScreen * screen = qApp->primaryScreen(); const QScreen * screen = qApp->primaryScreen();
w.setGeometry(QRect(QPoint(0,0), screen->geometry ().size())); w.setGeometry(QRect(QPoint(0,0), screen->geometry().size()));
w.setFixedSize(QSize(screen->geometry().height(), screen->geometry().width()));
w.show(); w.show();
return a.exec(); return a.exec();
} }

BIN
src/resources/refresh.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: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.5 KiB

After

Width:  |  Height:  |  Size: 15 KiB

View file

@ -846,7 +846,7 @@ void settings::on_globalReadingSettingsCheckBox_toggled(bool checked)
void settings::on_checkOtaUpdateBtn_clicked() void settings::on_checkOtaUpdateBtn_clicked()
{ {
log("'Check for OTA update' button clicked", className); 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(); launchOtaUpdater();
} }
else { else {

View file

@ -419,7 +419,7 @@ void generalDialog::on_okBtn_clicked()
} }
} }
else if(ui->searchComboBox->currentText() == "Online library") { 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"); string_writeconfig("/inkbox/searchComboBoxFunction", "Online library");
log("Searching online library for '" + global::keyboard::keyboardText + "'", className); log("Searching online library for '" + global::keyboard::keyboardText + "'", className);
@ -648,20 +648,6 @@ void generalDialog::startVNC(QString server, QString password, QString port) {
qApp->quit(); 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) { void generalDialog::startOtaUpdate(bool wasDownloadSuccessful) {
emit closeIndefiniteToast(); emit closeIndefiniteToast();
if(wasDownloadSuccessful == true) { if(wasDownloadSuccessful == true) {

View file

@ -63,7 +63,6 @@ private slots:
void adjust_size(); void adjust_size();
void restartSearchDialog(); void restartSearchDialog();
void refreshScreenNative(); void refreshScreenNative();
void connectToNetworkSlot();
void startOtaUpdate(bool wasDownloadSuccessful); void startOtaUpdate(bool wasDownloadSuccessful);
void openBookFileNative(QString book, bool relativePath); void openBookFileNative(QString book, bool relativePath);
void showToastNative(QString messageToDisplay); void showToastNative(QString messageToDisplay);

View file

@ -14,7 +14,6 @@ wifiDialog::wifiDialog(QWidget *parent) :
ui(new Ui::wifiDialog) ui(new Ui::wifiDialog)
{ {
ui->setupUi(this); ui->setupUi(this);
wifiListTimer = new QTimer(this);
// Stylesheet, style & misc. // Stylesheet, style & misc.
QFile stylesheetFile("/mnt/onboard/.adds/inkbox/eink.qss"); QFile stylesheetFile("/mnt/onboard/.adds/inkbox/eink.qss");
@ -23,15 +22,34 @@ wifiDialog::wifiDialog(QWidget *parent) :
stylesheetFile.close(); stylesheetFile.close();
this->setModal(true); this->setModal(true);
ui->cancelBtn->setProperty("type", "borderless"); ui->stopBtn->setIcon(QIcon(":/resources/stop.png"));
ui->connectBtn->setProperty("type", "borderless"); ui->logBtn->setIcon(QIcon(":/resources/file-text.png"));
ui->cancelBtn->setStyleSheet("font-size: 9pt; padding: 10px; font-weight: bold; background: lightGrey"); ui->refreshBtn->setIcon(QIcon(":/resources/refresh.png"));
ui->connectBtn->setStyleSheet("font-size: 9pt; padding: 10px; font-weight: bold; background: lightGrey");
ui->mainLabel->setStyleSheet("padding-left: 125px; padding-right: 125px"); ui->Wificheckbox->setStyleSheet("QCheckBox::indicator { width:50px; height: 50px; }");
ui->networksListWidget->setFont(QFont("u001"));
ui->networksListWidget->setStyleSheet("font-size: 9pt"); // Size
QRect screenGeometry = QGuiApplication::screens()[0]->geometry();
this->setFixedWidth(screenGeometry.width());
int halfOfHalfHeight = ((screenGeometry.height() / 2) / 2) / 2;
int finalHeight = screenGeometry.height() - halfOfHalfHeight * 2;
this->setFixedHeight(finalHeight);
this->move(0, halfOfHalfHeight);
// Button sizes
ui->stopBtn->setFixedWidth(screenGeometry.width() / 8);
ui->logBtn->setFixedWidth(screenGeometry.width() / 8);
ui->refreshBtn->setFixedWidth(screenGeometry.width() / 8);
int heighIncrease = 20;
ui->stopBtn->setFixedHeight(ui->stopBtn->height() + heighIncrease);
ui->logBtn->setFixedHeight(ui->logBtn->height() + heighIncrease);
ui->refreshBtn->setFixedHeight(ui->refreshBtn->height() + heighIncrease);
//ui->cancelBtn->setProperty("type", "borderless");
checkWifiNetworks();
} }
wifiDialog::~wifiDialog() wifiDialog::~wifiDialog()
@ -39,93 +57,6 @@ wifiDialog::~wifiDialog()
delete ui; 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();
}
} );
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);
}
}
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::on_cancelBtn_clicked()
{
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()
{
index = ui->networksListWidget->currentIndex();
itemText = index.data(Qt::DisplayRole).toString();
if(itemText.isEmpty()) {
showToast("You must select a network");
}
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();
}
}
void wifiDialog::refreshScreenNative() { void wifiDialog::refreshScreenNative() {
emit refreshScreen(); emit refreshScreen();
} }
@ -141,3 +72,99 @@ void wifiDialog::showToastNative(QString messageToDisplay) {
void wifiDialog::closeIndefiniteToastNative() { void wifiDialog::closeIndefiniteToastNative() {
emit closeIndefiniteToast(); emit closeIndefiniteToast();
} }
/*
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();
*/
/*
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 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.
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;
}
}
*/

View file

@ -18,29 +18,17 @@ public:
QString className = this->metaObject()->className(); QString className = this->metaObject()->className();
explicit wifiDialog(QWidget *parent = nullptr); explicit wifiDialog(QWidget *parent = nullptr);
~wifiDialog(); ~wifiDialog();
QString wifiNetworksList;
QString itemText;
QModelIndex index;
void checkWifiNetworks();
void printWifiNetworks();
void centerDialog();
private: private:
Ui::wifiDialog *ui; Ui::wifiDialog *ui;
QTimer * wifiListTimer;
generalDialog * generalDialogWindow;
signals: signals:
void wifiNetworksListReady(int networksFound);
void quit(int exitCode);
void refreshScreen(); void refreshScreen();
void updateWifiIconSig(int mode); void updateWifiIconSig(int mode);
void showToast(QString messageToDisplay); void showToast(QString messageToDisplay);
void closeIndefiniteToast(); void closeIndefiniteToast();
private slots: private slots:
void on_cancelBtn_clicked();
void on_connectBtn_clicked();
void refreshScreenNative(); void refreshScreenNative();
void updateWifiIcon(int mode); void updateWifiIcon(int mode);
void showToastNative(QString messageToDisplay); void showToastNative(QString messageToDisplay);

View file

@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>400</width> <width>783</width>
<height>300</height> <height>679</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -15,83 +15,162 @@
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<item> <item>
<layout class="QGridLayout" name="gridLayout"> <layout class="QHBoxLayout" name="horizontalLayout">
<item row="2" column="0"> <property name="sizeConstraint">
<widget class="QStackedWidget" name="stackedWidget"> <enum>QLayout::SetFixedSize</enum>
<property name="currentIndex"> </property>
<number>0</number> <item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="sizeConstraint">
<enum>QLayout::SetMaximumSize</enum>
</property> </property>
<widget class="QWidget" name="page_2"> <item>
<layout class="QVBoxLayout" name="verticalLayout_3"> <layout class="QVBoxLayout" name="verticalLayout_3">
<property name="leftMargin"> <property name="spacing">
<number>0</number> <number>2</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property> </property>
<item> <item>
<layout class="QGridLayout" name="gridLayout_4"> <layout class="QHBoxLayout" name="horizontalLayout_4">
<item row="1" column="0"> <item>
<widget class="QListView" name="networksListWidget"> <widget class="QPushButton" name="logBtn">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding"> <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<property name="text">
<string/>
</property>
</widget> </widget>
</item> </item>
<item row="0" column="0"> <item>
<widget class="QLabel" name="mainLabel"> <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="QPushButton" name="refreshBtn">
<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>
<widget class="QLabel" name="statusLabel">
<property name="font"> <property name="font">
<font> <font>
<weight>75</weight> <pointsize>9</pointsize>
<bold>true</bold>
</font> </font>
</property> </property>
<property name="text"> <property name="text">
<string>Select a network</string> <string>Wifi status</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property> </property>
</widget> </widget>
</item> </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> </layout>
</item> </item>
</layout> </layout>
</widget> </item>
</widget> <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="label">
<property name="text">
<string>Wifi</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="Wificheckbox">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</item> </item>
</layout> </layout>
</item> </item>
<item>
<widget class="QScrollArea" name="scrollArea">
<property name="frameShape">
<enum>QFrame::Box</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="lineWidth">
<number>3</number>
</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>759</width>
<height>570</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2"/>
</widget>
</widget>
</item>
<item>
<widget class="QPushButton" name="returnBtn">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Return</string>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
<resources/> <resources/>

View file

@ -27,27 +27,12 @@ toast::toast(QWidget *parent) :
global::toast::delay = 5000; global::toast::delay = 5000;
} }
} }
if(global::toast::wifiToast == true) { if(global::toast::indefiniteToast == false) {
global::toast::wifiToast = false; QTimer::singleShot(global::toast::delay, this, SLOT(close()));
this->setModal(true); global::toast::delay = 0;
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 { else {
if(global::toast::indefiniteToast == false) { global::toast::indefiniteToast = false;
QTimer::singleShot(global::toast::delay, this, SLOT(close()));
global::toast::delay = 0;
}
else {
global::toast::indefiniteToast = false;
}
} }
} }
@ -56,16 +41,6 @@ toast::~toast()
delete ui; delete ui;
} }
void toast::showWifiDialog(int networksFound) {
if(networksFound == 1) {
emit updateWifiIconSig(2);
this->hide();
wifiDialogWindow->show();
wifiDialogWindow->adjustSize();
wifiDialogWindow->centerDialog();
}
}
void toast::centerToast() { void toast::centerToast() {
// Centering toast (https://stackoverflow.com/a/58682351) // Centering toast (https://stackoverflow.com/a/58682351)
// Get current screen size // Get current screen size
@ -91,10 +66,6 @@ void toast::refreshScreenNative() {
emit refreshScreen(); emit refreshScreen();
} }
void toast::updateWifiIcon(int mode) {
emit updateWifiIconSig(mode);
}
void toast::showToastNative(QString messageToDisplay) { void toast::showToastNative(QString messageToDisplay) {
emit showToast(messageToDisplay); emit showToast(messageToDisplay);
} }

View file

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