mirror of
https://github.com/Quill-OS/quill.git
synced 2024-10-31 21:33:22 -07:00
purging old cold, some new
This commit is contained in:
parent
aa8214a297
commit
f2d269033d
17 changed files with 357 additions and 411 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -84,5 +84,7 @@
|
|||
<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>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
|
144
src/functions.h
144
src/functions.h
|
@ -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,17 @@ namespace global {
|
|||
namespace highlightsListDialog {
|
||||
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 bool forbidOpenSearchDialog;
|
||||
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() {
|
||||
QString sysfsWarmthPath;
|
||||
if(global::deviceID == "n873\n") {
|
||||
|
@ -866,51 +838,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 +1062,55 @@ namespace {
|
|||
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
|
||||
|
|
|
@ -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();
|
||||
updateWifiState();
|
||||
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();
|
||||
|
||||
|
@ -749,90 +751,34 @@ void MainWindow::setupSearchDialog() {
|
|||
}
|
||||
}
|
||||
|
||||
void MainWindow::updateWifiIcon(int mode) {
|
||||
void MainWindow::updateWifiIcon(global::wifi::WifiState mode) {
|
||||
/* Usage:
|
||||
* mode 0: auto
|
||||
* mode 1: off
|
||||
* mode 2: standby
|
||||
* mode 3: connected
|
||||
* mode 0 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();
|
||||
}
|
||||
if(mode == 1) {
|
||||
lastWifiState = 1;
|
||||
if(mode == global::wifi::WifiState::Disabled) {
|
||||
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(mode == 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;
|
||||
if(mode == global::wifi::WifiState::Configured) {
|
||||
lastWifiState = global::wifi::WifiState::Configured;
|
||||
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");
|
||||
}
|
||||
else {
|
||||
string_checkconfig_ro("/sys/class/net/eth0/operstate");
|
||||
}
|
||||
|
||||
if(checkconfig_str_val == "up\n") {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::setWifiIcon() {
|
||||
void MainWindow::updateWifiState() {
|
||||
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"));
|
||||
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));
|
||||
}
|
||||
global::wifi::WifiState currentWifiState = checkWifiState();
|
||||
if(lastWifiState != currentWifiState) {
|
||||
// This is handled by updateWifiIcon()
|
||||
//lastWifiState = currentWifiState;
|
||||
updateWifiIcon(currentWifiState);
|
||||
}
|
||||
}
|
||||
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()
|
||||
{
|
||||
openWifiDialog();
|
||||
wifiDialog* newWIfiDialog = new wifiDialog();
|
||||
newWIfiDialog->exec();
|
||||
}
|
||||
|
||||
void MainWindow::showToast(QString messageToDisplay) {
|
||||
|
@ -963,7 +888,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 +925,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 +941,6 @@ void MainWindow::checkForOtaUpdate() {
|
|||
}
|
||||
}
|
||||
|
||||
void MainWindow::resetWifiIconClickedWhileReconnecting() {
|
||||
wifiIconClickedWhileReconnecting = false;
|
||||
}
|
||||
|
||||
void MainWindow::setupLocalLibraryWidget() {
|
||||
localLibraryWidgetWindow = new localLibraryWidget(this);
|
||||
QObject::connect(localLibraryWidgetWindow, &localLibraryWidget::openBookSignal, this, &MainWindow::openBookFile);
|
||||
|
|
|
@ -51,8 +51,7 @@ 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;
|
||||
int timerTime = 0;
|
||||
QString relative_path;
|
||||
QString usbmsStatus;
|
||||
|
@ -62,7 +61,6 @@ public:
|
|||
void openUsbmsDialog();
|
||||
void resetIcons();
|
||||
void setBatteryIcon();
|
||||
bool checkWifiState();
|
||||
|
||||
public slots:
|
||||
|
||||
|
@ -74,14 +72,13 @@ 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 updateWifiState();
|
||||
void on_wifiBtn_clicked();
|
||||
void updateWifiIcon(int mode);
|
||||
void updateWifiIcon(global::wifi::WifiState mode);
|
||||
void hello(int testNumber);
|
||||
void showToast(QString messageToDisplay);
|
||||
void closeIndefiniteToast();
|
||||
|
@ -95,7 +92,6 @@ private slots:
|
|||
void on_libraryButton_clicked();
|
||||
void resetWindow(bool resetStackedWidget);
|
||||
void resetFullWindow();
|
||||
void resetWifiIconClickedWhileReconnecting();
|
||||
void setupLocalLibraryWidget();
|
||||
void setupHomePageWidget();
|
||||
|
||||
|
|
|
@ -41,6 +41,9 @@ int main(int argc, char *argv[])
|
|||
global::logger::status = true;
|
||||
}
|
||||
}
|
||||
// Szybet testing
|
||||
global::logger::status = true;
|
||||
|
||||
global::deviceID = readFile("/opt/inkbox_device");
|
||||
log("Running on device " + global::deviceID, "main", true);
|
||||
|
||||
|
@ -226,7 +229,8 @@ int main(int argc, char *argv[])
|
|||
}
|
||||
|
||||
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();
|
||||
return a.exec();
|
||||
}
|
||||
|
|
BIN
src/resources/refresh.png
Normal file
BIN
src/resources/refresh.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 13 KiB |
BIN
src/resources/stop.png
Normal file
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 |
|
@ -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 {
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -14,7 +14,6 @@ wifiDialog::wifiDialog(QWidget *parent) :
|
|||
ui(new Ui::wifiDialog)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
wifiListTimer = new QTimer(this);
|
||||
|
||||
// Stylesheet, style & misc.
|
||||
QFile stylesheetFile("/mnt/onboard/.adds/inkbox/eink.qss");
|
||||
|
@ -23,15 +22,34 @@ 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->stopBtn->setIcon(QIcon(":/resources/stop.png"));
|
||||
ui->logBtn->setIcon(QIcon(":/resources/file-text.png"));
|
||||
ui->refreshBtn->setIcon(QIcon(":/resources/refresh.png"));
|
||||
|
||||
ui->Wificheckbox->setStyleSheet("QCheckBox::indicator { width:50px; height: 50px; }");
|
||||
|
||||
// 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()
|
||||
|
@ -39,93 +57,6 @@ 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();
|
||||
}
|
||||
} );
|
||||
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() {
|
||||
emit refreshScreen();
|
||||
}
|
||||
|
@ -141,3 +72,99 @@ void wifiDialog::showToastNative(QString messageToDisplay) {
|
|||
void wifiDialog::closeIndefiniteToastNative() {
|
||||
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;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
|
|
@ -18,29 +18,17 @@ public:
|
|||
QString className = this->metaObject()->className();
|
||||
explicit wifiDialog(QWidget *parent = nullptr);
|
||||
~wifiDialog();
|
||||
QString wifiNetworksList;
|
||||
QString itemText;
|
||||
QModelIndex index;
|
||||
void checkWifiNetworks();
|
||||
void printWifiNetworks();
|
||||
void centerDialog();
|
||||
|
||||
private:
|
||||
Ui::wifiDialog *ui;
|
||||
QTimer * wifiListTimer;
|
||||
generalDialog * generalDialogWindow;
|
||||
|
||||
signals:
|
||||
void wifiNetworksListReady(int networksFound);
|
||||
void quit(int exitCode);
|
||||
void refreshScreen();
|
||||
void updateWifiIconSig(int mode);
|
||||
void showToast(QString messageToDisplay);
|
||||
void closeIndefiniteToast();
|
||||
|
||||
private slots:
|
||||
void on_cancelBtn_clicked();
|
||||
void on_connectBtn_clicked();
|
||||
void refreshScreenNative();
|
||||
void updateWifiIcon(int mode);
|
||||
void showToastNative(QString messageToDisplay);
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>300</height>
|
||||
<width>783</width>
|
||||
<height>679</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
|
@ -15,83 +15,162 @@
|
|||
</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">
|
||||
<number>0</number>
|
||||
<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>
|
||||
<widget class="QWidget" name="page_2">
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_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 name="spacing">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<item>
|
||||
<layout class="QGridLayout" name="gridLayout_4">
|
||||
<item row="1" column="0">
|
||||
<widget class="QListView" name="networksListWidget">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_4">
|
||||
<item>
|
||||
<widget class="QPushButton" name="logBtn">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="mainLabel">
|
||||
<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="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">
|
||||
<font>
|
||||
<weight>75</weight>
|
||||
<bold>true</bold>
|
||||
<pointsize>9</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Select a network</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
<string>Wifi status</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>
|
||||
<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>
|
||||
</layout>
|
||||
</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>
|
||||
</widget>
|
||||
<resources/>
|
||||
|
|
|
@ -27,27 +27,12 @@ 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()));
|
||||
if(global::toast::indefiniteToast == false) {
|
||||
QTimer::singleShot(global::toast::delay, this, SLOT(close()));
|
||||
global::toast::delay = 0;
|
||||
}
|
||||
else {
|
||||
if(global::toast::indefiniteToast == false) {
|
||||
QTimer::singleShot(global::toast::delay, this, SLOT(close()));
|
||||
global::toast::delay = 0;
|
||||
}
|
||||
else {
|
||||
global::toast::indefiniteToast = false;
|
||||
}
|
||||
global::toast::indefiniteToast = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -56,16 +41,6 @@ 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);
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
Loading…
Reference in a new issue