From a532d00f485fca1068e08c6010ba5304427715ce Mon Sep 17 00:00:00 2001 From: Nicolas Mailloux Date: Tue, 13 Jul 2021 15:18:59 -0400 Subject: [PATCH] Wi-Fi button/icon in MainWindow Dialog's coming soon, hopefully ... --- eink.qrc | 3 + mainwindow.cpp | 84 ++++++++++++++++++ mainwindow.h | 6 ++ mainwindow.ui | 173 ++++++++++++++++++++----------------- resources/wifi-standby.png | Bin 3560 -> 3559 bytes 5 files changed, 188 insertions(+), 78 deletions(-) diff --git a/eink.qrc b/eink.qrc index 06dc549..25d1780 100644 --- a/eink.qrc +++ b/eink.qrc @@ -57,5 +57,8 @@ resources/fonts/IbarraRealNova-Medium.ttf resources/fonts/IbarraRealNova-BoldItalic.ttf resources/fonts/IbarraRealNova-Bold.ttf + resources/wifi-connected.png + resources/wifi-off.png + resources/wifi-standby.png diff --git a/mainwindow.cpp b/mainwindow.cpp index 6676aac..f1353c9 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -36,6 +36,7 @@ MainWindow::MainWindow(QWidget *parent) ui->pushButton->setProperty("type", "borderless"); ui->brightnessBtn->setProperty("type", "borderless"); ui->homeBtn->setProperty("type", "borderless"); + ui->wifiBtn->setProperty("type", "borderless"); ui->settingsBtn->setText(""); ui->appsBtn->setText(""); @@ -45,6 +46,7 @@ MainWindow::MainWindow(QWidget *parent) ui->brightnessBtn->setText(""); ui->homeBtn->setText(""); ui->quoteLabel->setText(""); + ui->wifiBtn->setText(""); ui->quotePictureLabel->setText(""); @@ -72,6 +74,8 @@ MainWindow::MainWindow(QWidget *parent) brightnessIconHeight = sH / 24; homeIconWidth = sW / 18; homeIconHeight = sW / 18; + wifiIconWidth = sW / 20; + wifiIconHeight = sH / 20; } else if(checkconfig_str_val == "n905\n") { stdIconWidth = sW / 14; @@ -80,6 +84,8 @@ MainWindow::MainWindow(QWidget *parent) brightnessIconHeight = sH / 26; homeIconWidth = sW / 20; homeIconHeight = sW / 20; + wifiIconWidth = sW / 22; + wifiIconHeight = sH / 22; } else if(checkconfig_str_val == "n613\n") { stdIconWidth = sW / 12.5; @@ -88,6 +94,8 @@ MainWindow::MainWindow(QWidget *parent) brightnessIconHeight = sH / 24.5; homeIconWidth = sW / 18.5; homeIconHeight = sW / 18.5; + wifiIconWidth = sW / 20.5; + wifiIconHeight = sH / 20.5; } else { stdIconWidth = sW / 14; @@ -96,6 +104,8 @@ MainWindow::MainWindow(QWidget *parent) brightnessIconHeight = sH / 26; homeIconWidth = sW / 20; homeIconHeight = sW / 20; + wifiIconWidth = sW / 22; + wifiIconHeight = sH / 22; } // Setting icons up @@ -116,6 +126,8 @@ MainWindow::MainWindow(QWidget *parent) ui->brightnessBtn->setIcon(QIcon(":/resources/frontlight.png")); ui->brightnessBtn->setIconSize(QSize(brightnessIconWidth, brightnessIconHeight)); + setWifiIcon(); + updateWifiIcon(0); setBatteryIcon(); int id = QFontDatabase::addApplicationFont(":/resources/fonts/CrimsonPro-Regular.ttf"); @@ -132,6 +144,7 @@ MainWindow::MainWindow(QWidget *parent) ui->book4Btn->setStyleSheet("font-size: 11pt; padding: 25px"); ui->brightnessBtn->setStyleSheet("font-size: 9pt; padding-bottom: 5px; padding-top: 5px; padding-left: 8px; padding-right: 8px;"); + ui->wifiBtn->setStyleSheet("font-size: 9pt; padding-bottom: 0px; padding-top: 0px; padding-left: 8px; padding-right: 8px"); // Checking if we have a Mini or Touch there string_checkconfig_ro("/opt/inkbox_device"); @@ -141,6 +154,9 @@ MainWindow::MainWindow(QWidget *parent) else if(checkconfig_str_val == "n613\n") { ui->batteryIcon->setStyleSheet("font-size: 5pt; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; padding-right: 0px;"); } + else if(checkconfig_str_val == "n873\n") { + ui->batteryIcon->setStyleSheet("font-size: 5pt; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; padding-right: 0px;"); + } else { ui->batteryIcon->setStyleSheet("font-size: 5pt; padding-bottom: 0px; padding-top: 0px; padding-left: 8px; padding-right: 8px;"); } @@ -823,3 +839,71 @@ void MainWindow::setupSearchDialog() { ; } } + +int MainWindow::testPing() { + QString pingProg = "ping"; + QStringList pingArgs; + pingArgs << "-c" << "1" << "1.1.1.1"; + QProcess *pingProcess = new QProcess(); + pingProcess->start(pingProg, pingArgs); + pingProcess->waitForFinished(); + return pingProcess->exitCode(); +} + +void MainWindow::updateWifiIcon(int mode) { + /* Usage: + * mode 0: auto + * mode 1: off + * mode 2: standby + * mode 3: connected + */ + if(mode == 0) { + QTimer *wifiIconTimer = new QTimer(this); + wifiIconTimer->setInterval(60000); + connect(wifiIconTimer, SIGNAL(timeout()), this, SLOT(setWifiIcon())); + wifiIconTimer->start(); + } + if(mode == 1) { + ui->wifiBtn->setIcon(QIcon(":/resources/wifi-off.png")); + ui->wifiBtn->setIconSize(QSize(wifiIconWidth, wifiIconHeight)); + } + if(mode == 2) { + ui->wifiBtn->setIcon(QIcon(":/resources/wifi-standby.png")); + ui->wifiBtn->setIconSize(QSize(wifiIconWidth, wifiIconHeight)); + } + if(mode == 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 + */ + string_checkconfig_ro("/sys/class/net/eth0/operstate"); + if(checkconfig_str_val == "up\n") { + return true; + } + else { + return false; + } +} + +void MainWindow::setWifiIcon() { + if(checkWifiState() == true) { + if(testPing() == 0) { + ui->wifiBtn->setIcon(QIcon(":/resources/wifi-connected.png")); + ui->wifiBtn->setIconSize(QSize(wifiIconWidth, wifiIconHeight)); + } + else { + ui->wifiBtn->setIcon(QIcon(":/resources/wifi-standby.png")); + ui->wifiBtn->setIconSize(QSize(wifiIconWidth, wifiIconHeight)); + } + } + else { + ui->wifiBtn->setIcon(QIcon(":/resources/wifi-off.png")); + ui->wifiBtn->setIconSize(QSize(wifiIconWidth, wifiIconHeight)); + } +} diff --git a/mainwindow.h b/mainwindow.h index 65c92e7..c267a44 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -36,6 +36,8 @@ public: float brightnessIconHeight; float homeIconWidth; float homeIconHeight; + float wifiIconWidth; + float wifiIconHeight; float sW; float sH; @@ -51,6 +53,9 @@ public: void resetWindow(bool resetStackedWidget); void resetIcons(); void setBatteryIcon(); + void updateWifiIcon(int mode); + int testPing(); + bool checkWifiState(); public slots: @@ -70,6 +75,7 @@ private slots: void on_homeBtn_clicked(); void refreshScreen(); void setupSearchDialog(); + void setWifiIcon(); private: Ui::MainWindow *ui; diff --git a/mainwindow.ui b/mainwindow.ui index ec87f6e..ef9de69 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -17,60 +17,20 @@ - - + + + + QFrame::Plain + - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Brightness + Qt::Vertical - - - - - 75 - true - - + + - batt - - - - - - - - - - - - - - - 11 - 75 - true - - - - time - - - Qt::AlignCenter + Home @@ -89,13 +49,6 @@ - - - - batteryIcon - - - @@ -103,6 +56,57 @@ + + + + + + + + + + + Wi-Fi + + + + + + + Brightness + + + + + + + QFrame::Plain + + + Qt::Vertical + + + + + + + batteryIcon + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + @@ -116,30 +120,43 @@ - - - - QFrame::Plain + + + + + 75 + true + - - Qt::Vertical - - - - - - - QFrame::Plain - - - Qt::Vertical - - - - - - Home + batt + + + + + + + + 11 + 75 + true + + + + time + + + Qt::AlignCenter + + + + + + + QFrame::Plain + + + Qt::Vertical diff --git a/resources/wifi-standby.png b/resources/wifi-standby.png index 2d6427b04db66826782da75cdd2769be69dd665d..5fa26f2985c2504edd114e132f33eef64d59f120 100644 GIT binary patch literal 3559 zcmdUxd010d7QoMYSp~A7fFNKJ&;b=SRE1cO1fmtn)U_&%3jvFkRtbu-2!RJdUv{pwEZPM05}2ui&p{QNX3E8MB;Va-9Z2>EkZ6|5g?ZfqjoB{L~IKOaNV!k zzsSF4h1K5WtB*U)=Jp8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