almost working logging and info wifi dialog

This commit is contained in:
Szybet 2022-08-17 15:57:33 +02:00
parent 2cf679a303
commit dc191269f3
9 changed files with 610 additions and 5 deletions

View file

@ -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();
}

View file

@ -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);

View file

@ -49,7 +49,7 @@
<x>0</x>
<y>0</y>
<width>457</width>
<height>657</height>
<height>667</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_4">
@ -71,7 +71,7 @@
<number>0</number>
</property>
<property name="currentIndex">
<number>0</number>
<number>1</number>
</property>
<widget class="QWidget" name="page">
<layout class="QVBoxLayout" name="verticalLayout_2">

View file

@ -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;

View file

@ -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();
}
}

View file

@ -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

View file

@ -0,0 +1,139 @@
#include <QFile>
#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);
}
}

View file

@ -0,0 +1,45 @@
#ifndef WIFILOGGER_H
#define WIFILOGGER_H
#include <QDialog>
#include "functions.h"
namespace Ui {
class wifilogger;
}
class wifilogger : public QDialog
{
Q_OBJECT
public:
QString className = this->metaObject()->className();
explicit wifilogger(QWidget *parent = nullptr);
~wifilogger();
global::wifi::wifiNetworkData connectedNetworkData;
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

View file

@ -0,0 +1,400 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>wifilogger</class>
<widget class="QDialog" name="wifilogger">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>755</width>
<height>613</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="1" column="0">
<widget class="QStackedWidget" name="stackedWidget">
<property name="lineWidth">
<number>0</number>
</property>
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="page_0">
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QLabel" name="label_3">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Network name: </string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="netNameLabel">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="label">
<property name="font">
<font>
<weight>75</weight>
<italic>false</italic>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>IP address:</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="ipLabel">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QLabel" name="label_4">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Mask: </string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="maskLabel">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_5">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_7">
<item>
<widget class="QLabel" name="label_5">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Gateway: </string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="gatewayLabel">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_6">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_10">
<item>
<widget class="QLabel" name="label_6">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Password protected:</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="encryptionLabel">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_7">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_12">
<item>
<widget class="QLabel" name="label_2">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Signal strength: </string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="signalLabel">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_8">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_15">
<item>
<widget class="QLabel" name="label_7">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>MAC address: </string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="macLabel">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_9">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
<widget class="QWidget" name="page_0_fallback">
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="label_8">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="lineWidth">
<number>0</number>
</property>
<property name="text">
<string>No wifi connected</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="page_1">
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0">
<widget class="QTextBrowser" name="fancyLogsText"/>
</item>
</layout>
</widget>
<widget class="QWidget" name="page_2">
<layout class="QGridLayout" name="gridLayout_4">
<item row="0" column="0">
<widget class="QTextBrowser" name="allLogsText"/>
</item>
</layout>
</widget>
</widget>
</item>
<item row="0" column="0">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QPushButton" name="previousBtn">
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../../../eink.qrc">
<normaloff>:/resources/chevron-left.png</normaloff>:/resources/chevron-left.png</iconset>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="nameLabel">
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="nextBtn">
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../../../eink.qrc">
<normaloff>:/resources/chevron-right.png</normaloff>:/resources/chevron-right.png</iconset>
</property>
</widget>
</item>
</layout>
</item>
<item row="2" column="0">
<widget class="QPushButton" name="returnBtn">
<property name="text">
<string>Return</string>
</property>
</widget>
</item>
</layout>
</widget>
<resources>
<include location="../../../eink.qrc"/>
</resources>
<connections/>
</ui>