diff --git a/src/homeWidget/mainwindow.cpp b/src/homeWidget/mainwindow.cpp index d7d4d56..cb24d71 100644 --- a/src/homeWidget/mainwindow.cpp +++ b/src/homeWidget/mainwindow.cpp @@ -790,6 +790,7 @@ void MainWindow::updateWifiState() { void MainWindow::on_wifiBtn_clicked() { wifiDialog* newWIfiDialog = new wifiDialog(); + QObject::connect(newWIfiDialog, &wifiDialog::showToast, this, &MainWindow::showToast); newWIfiDialog->exec(); } diff --git a/src/homeWidget/mainwindow.h b/src/homeWidget/mainwindow.h index fc76401..43110d7 100644 --- a/src/homeWidget/mainwindow.h +++ b/src/homeWidget/mainwindow.h @@ -63,6 +63,8 @@ public: void setBatteryIcon(); public slots: + void showToast(QString messageToDisplay); + void closeIndefiniteToast(); private slots: void on_settingsBtn_clicked(); @@ -80,8 +82,6 @@ private slots: void on_wifiBtn_clicked(); void updateWifiIcon(global::wifi::WifiState mode); void hello(int testNumber); - void showToast(QString messageToDisplay); - void closeIndefiniteToast(); void openUpdateDialogOTA(bool open); void launchOtaUpdater(); void openBookFile(QString book, bool relativePath); diff --git a/src/settings/settings.ui b/src/settings/settings.ui index a63a5ab..a121f64 100644 --- a/src/settings/settings.ui +++ b/src/settings/settings.ui @@ -49,7 +49,7 @@ 0 0 457 - 657 + 667 @@ -71,7 +71,7 @@ 0 - 0 + 1 diff --git a/src/widgets/dialogs/wifi/network.h b/src/widgets/dialogs/wifi/network.h index 171d5bc..9ef91f9 100644 --- a/src/widgets/dialogs/wifi/network.h +++ b/src/widgets/dialogs/wifi/network.h @@ -14,6 +14,7 @@ class network : public QWidget Q_OBJECT public: + QString className = this->metaObject()->className(); explicit network(QWidget *parent = nullptr); ~network(); global::wifi::wifiNetworkData mainData; diff --git a/src/widgets/dialogs/wifi/wifidialog.cpp b/src/widgets/dialogs/wifi/wifidialog.cpp index 2c81f13..a5fdf28 100644 --- a/src/widgets/dialogs/wifi/wifidialog.cpp +++ b/src/widgets/dialogs/wifi/wifidialog.cpp @@ -10,6 +10,7 @@ #include "functions.h" #include "mainwindow.h" #include "network.h" +#include "wifilogger.h" wifiDialog::wifiDialog(QWidget *parent) : QDialog(parent), @@ -265,6 +266,7 @@ void wifiDialog::refreshNetworksList() { network* connectedNetwork = new network; connectedNetwork->mainData = wifiNetwork; connectedNetwork->currentlyConnectedNetwork = currentNetwork; + connectedNetworkDataParent = wifiNetwork; // this doesnt work so a layout is needed // ui->scrollArea->addScrollBarWidget(connectedNetwork, Qt::AlignTop); connectedNetwork->applyVariables(); @@ -303,7 +305,7 @@ void wifiDialog::refreshNetworksList() { connect(this, SIGNAL(killNetworkWidgets()), connectedNetwork, SLOT(close())); ui->scrollBarLayout->addWidget(connectedNetwork, Qt::AlignTop); } - + scannedAtLeastOnce = true; } @@ -332,3 +334,17 @@ void wifiDialog::turnOnWifi() { void wifiDialog::turnOffWifi() { string_writeconfig("/opt/ibxd", "toggle_wifi_off\n"); } + +void wifiDialog::on_logBtn_clicked() +{ + // To avoid half informations + 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; + wifiLoggerDialog->connectedNetworkData = connectedNetworkDataParent; + wifiLoggerDialog->exec(); + } + +} diff --git a/src/widgets/dialogs/wifi/wifidialog.h b/src/widgets/dialogs/wifi/wifidialog.h index 1f30049..1ce10f2 100644 --- a/src/widgets/dialogs/wifi/wifidialog.h +++ b/src/widgets/dialogs/wifi/wifidialog.h @@ -18,10 +18,12 @@ public: QString className = this->metaObject()->className(); explicit wifiDialog(QWidget *parent = nullptr); ~wifiDialog(); + global::wifi::wifiNetworkData connectedNetworkDataParent; private: Ui::wifiDialog *ui; bool wifiButtonEnabled = false; + bool scannedAtLeastOnce = false; public slots: void launchRefresh(); @@ -39,6 +41,7 @@ private slots: void on_Wificheckbox_stateChanged(int arg1); void turnOnWifi(); void turnOffWifi(); + void on_logBtn_clicked(); }; #endif // WIFIDIALOG_H diff --git a/src/widgets/dialogs/wifi/wifilogger.cpp b/src/widgets/dialogs/wifi/wifilogger.cpp new file mode 100644 index 0000000..d6bd22b --- /dev/null +++ b/src/widgets/dialogs/wifi/wifilogger.cpp @@ -0,0 +1,139 @@ +#include + +#include "wifilogger.h" +#include "ui_wifilogger.h" +#include "functions.h" + +wifilogger::wifilogger(QWidget *parent) : + QDialog(parent), + ui(new Ui::wifilogger) +{ + ui->setupUi(this); + + // Stylesheet, style & misc. + QFile stylesheetFile("/mnt/onboard/.adds/inkbox/eink.qss"); + stylesheetFile.open(QFile::ReadOnly); + this->setStyleSheet(stylesheetFile.readAll()); + stylesheetFile.close(); + this->setModal(true); + + + setWifiInfoPage(); + QObject::connect(&updateLogsTimer, &QTimer::timeout, this, &wifilogger::updateLogs); + updateLogsTimer.start(1000); +} + +wifilogger::~wifilogger() +{ + delete ui; +} + +void wifilogger::setWifiInfoPage() { + if(checkWifiState() == global::wifi::WifiState::Configured) { + QTimer::singleShot(0, this, SLOT(getWifiInformations())); + ui->stackedWidget->setCurrentIndex(0); + ui->nameLabel->setText("Network informations"); + } + else { + ui->stackedWidget->setCurrentIndex(1); + ui->nameLabel->setText("No network connected"); + } +} + +void wifilogger::setFancyLoggingPage() { + ui->stackedWidget->setCurrentIndex(2); + ui->nameLabel->setText("Important logs"); +} + +void wifilogger::setAllLogsPage() { + 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 shouldnt happen.", className); + } +} + +void wifilogger::getWifiInformations() { + QFile wifiInformationsPath = QFile("/external_root/run/wifi_informations"); + wifiInformationsPath.remove(); + + string_writeconfig("/opt/ibxd", "get_wifi_informations\n"); + while(wifiInformationsPath.exists() == false) { + sleep(1); + } + + QString wifiInfo = readFile(wifiInformationsPath.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; + } + + ui->encryptionLabel->setText(QVariant(connectedNetworkData.encryption).toString()); + + ui->signalLabel->setText(QString::number(connectedNetworkData.signal) + "%"); + + ui->macLabel->setText(connectedNetworkData.mac); +} + + +void wifilogger::on_returnBtn_clicked() +{ + updateLogsTimer.stop(); + this->deleteLater(); +} + +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); + } +} diff --git a/src/widgets/dialogs/wifi/wifilogger.h b/src/widgets/dialogs/wifi/wifilogger.h new file mode 100644 index 0000000..4776844 --- /dev/null +++ b/src/widgets/dialogs/wifi/wifilogger.h @@ -0,0 +1,45 @@ +#ifndef WIFILOGGER_H +#define WIFILOGGER_H + +#include +#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; + +private: + Ui::wifilogger *ui; + /* + * 0 is wifi info / no wifi info page + * 1 is fancy logs page + * 2 is all logs + */ + int currentPage = 0; + QTimer updateLogsTimer; + QFile fancyLogs = QFile("/external_root/run/wifi_stats"); + QFile allLogs = QFile("/external_root/run/wifi_logs"); + +private slots: + void setWifiInfoPage(); + void setFancyLoggingPage(); + void setAllLogsPage(); + void on_nextBtn_clicked(); + void on_previousBtn_clicked(); + void changePage(); + void getWifiInformations(); + void on_returnBtn_clicked(); + void updateLogs(); +}; + +#endif // WIFILOGGER_H diff --git a/src/widgets/dialogs/wifi/wifilogger.ui b/src/widgets/dialogs/wifi/wifilogger.ui new file mode 100644 index 0000000..ff5344b --- /dev/null +++ b/src/widgets/dialogs/wifi/wifilogger.ui @@ -0,0 +1,400 @@ + + + wifilogger + + + + 0 + 0 + 755 + 613 + + + + Dialog + + + + + + 0 + + + 0 + + + + + + + + + + 75 + true + + + + Network name: + + + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + 75 + false + true + + + + IP address: + + + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + 75 + true + + + + Mask: + + + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + 75 + true + + + + Gateway: + + + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + 75 + true + + + + Password protected: + + + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + 75 + true + + + + Signal strength: + + + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + 75 + true + + + + MAC address: + + + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + + + 75 + true + + + + 0 + + + No wifi connected + + + Qt::AlignCenter + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + :/resources/chevron-left.png:/resources/chevron-left.png + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + TextLabel + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + :/resources/chevron-right.png:/resources/chevron-right.png + + + + + + + + + Return + + + + + + + + + +