mirror of
https://github.com/Quill-OS/quill.git
synced 2024-10-31 21:33:22 -07:00
Merge branch 'master' of github.com:Szybet/inkbox
This commit is contained in:
commit
04a10aaecf
28 changed files with 2441 additions and 451 deletions
|
@ -32,6 +32,9 @@ SOURCES += \
|
|||
src/apps/calendarapp.cpp \
|
||||
src/widgets/dialogs/reader/highlightslistdialog.cpp \
|
||||
src/widgets/dialogs/reader/textdialog.cpp \
|
||||
src/widgets/dialogs/wifi/connectiondialog.cpp \
|
||||
src/widgets/dialogs/wifi/network.cpp \
|
||||
src/widgets/dialogs/wifi/wifilogger.cpp \
|
||||
src/widgets/reader/dictionarywidget.cpp \
|
||||
src/encfs/encryptionmanager.cpp \
|
||||
src/widgets/dialogs/generaldialog.cpp \
|
||||
|
@ -72,6 +75,9 @@ HEADERS += \
|
|||
src/apps/calendarapp.h \
|
||||
src/widgets/dialogs/reader/highlightslistdialog.h \
|
||||
src/widgets/dialogs/reader/textdialog.h \
|
||||
src/widgets/dialogs/wifi/connectiondialog.h \
|
||||
src/widgets/dialogs/wifi/network.h \
|
||||
src/widgets/dialogs/wifi/wifilogger.h \
|
||||
src/widgets/reader/dictionarywidget.h \
|
||||
src/encfs/encryptionmanager.h \
|
||||
src/functions.h \
|
||||
|
@ -112,6 +118,9 @@ FORMS += \
|
|||
src/apps/calendarapp.ui \
|
||||
src/widgets/dialogs/reader/highlightslistdialog.ui \
|
||||
src/widgets/dialogs/reader/textdialog.ui \
|
||||
src/widgets/dialogs/wifi/connectiondialog.ui \
|
||||
src/widgets/dialogs/wifi/network.ui \
|
||||
src/widgets/dialogs/wifi/wifilogger.ui \
|
||||
src/widgets/reader/dictionarywidget.ui \
|
||||
src/encfs/encryptionmanager.ui \
|
||||
src/widgets/dialogs/generaldialog.ui \
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
13
src/eink.qrc
13
src/eink.qrc
|
@ -84,5 +84,18 @@
|
|||
<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>
|
||||
<file>resources/hide.png</file>
|
||||
<file>resources/show.png</file>
|
||||
<file>resources/christie.jpg</file>
|
||||
<file>resources/encryption-small.png</file>
|
||||
<file>resources/lock.png</file>
|
||||
<file>resources/public.png</file>
|
||||
<file>resources/wifi-0.png</file>
|
||||
<file>resources/wifi-100.png</file>
|
||||
<file>resources/wifi-25.png</file>
|
||||
<file>resources/wifi-50.png</file>
|
||||
<file>resources/wifi-75.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
|
167
src/functions.h
167
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,23 @@ namespace global {
|
|||
namespace highlightsListDialog {
|
||||
inline QString bookPath;
|
||||
}
|
||||
namespace wifi {
|
||||
enum class wifiState
|
||||
{
|
||||
configured,
|
||||
enabled,
|
||||
disabled,
|
||||
unknown, // To not confuse lastWifiState
|
||||
};
|
||||
inline bool isConnected;
|
||||
class wifiNetworkData {
|
||||
public:
|
||||
QString mac;
|
||||
QString name;
|
||||
bool encryption;
|
||||
int signal;
|
||||
};
|
||||
}
|
||||
inline QString systemInfoText;
|
||||
inline bool forbidOpenSearchDialog;
|
||||
inline bool isN705 = false;
|
||||
|
@ -780,41 +793,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 +844,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 +1068,72 @@ namespace {
|
|||
return 2;
|
||||
}
|
||||
}
|
||||
global::wifi::wifiState checkWifiState() {
|
||||
QProcess *wifiStateProcess = new QProcess();
|
||||
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 doesn't exist", "functions");
|
||||
}
|
||||
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;
|
||||
QString function = __func__; log(function + ": Critical error", "functions");
|
||||
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;
|
||||
}
|
||||
bool checkProcessName(QString name) {
|
||||
QDirIterator appsDir("/proc", QDirIterator::NoIteratorFlags);
|
||||
while (appsDir.hasNext()) {
|
||||
QDir dir(appsDir.next());
|
||||
QFile process = QFile(dir.path() + "/cmdline");
|
||||
if(process.exists() == true) {
|
||||
process.open(QIODevice::ReadOnly);
|
||||
QTextStream stream(&process);
|
||||
if(stream.readLine().contains(name) == true) {
|
||||
process.close();
|
||||
return true;
|
||||
}
|
||||
process.close();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
#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();
|
||||
updateWifiAble();
|
||||
if(global::device::isWifiAble == true) {
|
||||
updateWifiIcon(0);
|
||||
// Start wifi updater
|
||||
QTimer *wifiIconTimer = new QTimer(this);
|
||||
wifiIconTimer->setInterval(2500);
|
||||
connect(wifiIconTimer, SIGNAL(timeout()), this, SLOT(updateWifiIcon()));
|
||||
wifiIconTimer->start();
|
||||
}
|
||||
setBatteryIcon();
|
||||
|
||||
|
@ -749,136 +751,104 @@ void MainWindow::setupSearchDialog() {
|
|||
}
|
||||
}
|
||||
|
||||
void MainWindow::updateWifiIcon(int mode) {
|
||||
void MainWindow::updateWifiIcon() {
|
||||
/* Usage:
|
||||
* mode 0: auto
|
||||
* mode 1: off
|
||||
* mode 2: standby
|
||||
* mode 3: connected
|
||||
* Mode 0 (looping it) 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;
|
||||
ui->wifiBtn->setIcon(QIcon(":/resources/wifi-off.png"));
|
||||
ui->wifiBtn->setIconSize(QSize(wifiIconWidth, wifiIconHeight));
|
||||
}
|
||||
if(mode == 2) {
|
||||
lastWifiState = 2;
|
||||
ui->wifiBtn->setIcon(QIcon(":/resources/wifi-standby.png"));
|
||||
ui->wifiBtn->setIconSize(QSize(wifiIconWidth, wifiIconHeight));
|
||||
}
|
||||
if(mode == 3) {
|
||||
lastWifiState = 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
|
||||
*/
|
||||
if(global::deviceID == "n437\n") {
|
||||
string_checkconfig_ro("/sys/class/net/wlan0/operstate");
|
||||
}
|
||||
else {
|
||||
string_checkconfig_ro("/sys/class/net/eth0/operstate");
|
||||
}
|
||||
global::wifi::wifiState currentWifiState = checkWifiState();
|
||||
|
||||
if(checkconfig_str_val == "up\n") {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::setWifiIcon() {
|
||||
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));
|
||||
}
|
||||
// It's executing only in enabled mode, which is a mode between connected and disabled, so don't worry about performance
|
||||
if(isConnecting == false and isReconnecting == false) {
|
||||
if(currentWifiState == global::wifi::wifiState::enabled) {
|
||||
if(checkProcessName("connection_manager.sh") == true) {
|
||||
isConnecting = true;
|
||||
}
|
||||
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 if(checkProcessName("connect_to_network.sh") == true){
|
||||
isConnecting = true;
|
||||
isReconnecting = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
// ms can make a difference, so:
|
||||
currentWifiState = checkWifiState();
|
||||
|
||||
if(lastWifiState != currentWifiState) {
|
||||
if(currentWifiState == global::wifi::wifiState::disabled) {
|
||||
if(isConnecting == true) {
|
||||
if(checkconfig("/mnt/onboard/.adds/inkbox/.config/17-wifi_connection_information/stopped") == false) {
|
||||
QString wifiName = readFile("/mnt/onboard/.adds/inkbox/.config/17-wifi_connection_information/essid").replace("\n", "");
|
||||
if(isReconnecting == true) {
|
||||
showToast("Failed to reconnnect to " + wifiName);
|
||||
isReconnecting = false;
|
||||
}
|
||||
else {
|
||||
showToast("Failed to connect to " + wifiName);
|
||||
}
|
||||
isConnecting = false;
|
||||
QFile("/mnt/onboard/.adds/inkbox/.config/17-wifi_connection_information/essid").remove();
|
||||
QFile("/mnt/onboard/.adds/inkbox/.config/17-wifi_connection_information/passphrase").remove();
|
||||
}
|
||||
else {
|
||||
QFile("/mnt/onboard/.adds/inkbox/.config/17-wifi_connection_information/stopped").remove();
|
||||
}
|
||||
}
|
||||
lastWifiState = global::wifi::wifiState::disabled;
|
||||
ui->wifiBtn->setIcon(QIcon(":/resources/wifi-off.png"));
|
||||
ui->wifiBtn->setIconSize(QSize(wifiIconWidth, wifiIconHeight));
|
||||
}
|
||||
if(currentWifiState == global::wifi::wifiState::enabled) {
|
||||
lastWifiState = global::wifi::wifiState::enabled;
|
||||
ui->wifiBtn->setIcon(QIcon(":/resources/wifi-standby.png"));
|
||||
ui->wifiBtn->setIconSize(QSize(wifiIconWidth, wifiIconHeight));
|
||||
}
|
||||
if(currentWifiState == global::wifi::wifiState::configured) {
|
||||
if(isConnecting == true) {
|
||||
setDefaultWorkDir();
|
||||
QString wifiName = readFile("/mnt/onboard/.adds/inkbox/.config/17-wifi_connection_information/essid").replace("\n", "");
|
||||
if(isReconnecting == true) {
|
||||
showToast("Reconnected successfully to " + wifiName);
|
||||
isReconnecting = false;
|
||||
}
|
||||
else {
|
||||
showToast("Connected successfully to " + wifiName);
|
||||
}
|
||||
isConnecting = false;
|
||||
QFile("/mnt/onboard/.adds/inkbox/.config/17-wifi_connection_information/stopped").remove();
|
||||
}
|
||||
lastWifiState = global::wifi::wifiState::configured;
|
||||
ui->wifiBtn->setIcon(QIcon(":/resources/wifi-100.png"));
|
||||
ui->wifiBtn->setIconSize(QSize(wifiIconWidth, wifiIconHeight));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::updateWifiAble() {
|
||||
if(global::device::isWifiAble == false) {
|
||||
ui->wifiBtn->hide();
|
||||
ui->line_9->hide();
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
QObject::connect(newWIfiDialog, &wifiDialog::showToast, this, &MainWindow::showToast);
|
||||
newWIfiDialog->exec();
|
||||
}
|
||||
|
||||
void MainWindow::showToast(QString messageToDisplay) {
|
||||
global::toast::message = messageToDisplay;
|
||||
toastWindow = new toast(this);
|
||||
toastWindow->setAttribute(Qt::WA_DeleteOnClose);
|
||||
connect(toastWindow, SIGNAL(updateWifiIconSig(int)), SLOT(updateWifiIcon(int)));
|
||||
connect(toastWindow, SIGNAL(refreshScreen()), SLOT(refreshScreen()));
|
||||
connect(toastWindow, SIGNAL(showToast(QString)), SLOT(showToast(QString)));
|
||||
connect(toastWindow, SIGNAL(closeIndefiniteToast()), SLOT(closeIndefiniteToast()));
|
||||
toastWindow->show();
|
||||
|
||||
if(messageToDisplay == "Connection successful") {
|
||||
// I will soon manage the update thing in a more proper way somewhere else... ~ Szybet
|
||||
if(messageToDisplay.contains("onnected successfully") == true) {
|
||||
// Give the toast some time to vanish away, then launch OTA updater
|
||||
QTimer::singleShot(5000, this, SLOT(launchOtaUpdater()));
|
||||
}
|
||||
|
@ -963,7 +933,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 +970,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 +986,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,11 @@ 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;
|
||||
bool isConnecting = false;
|
||||
bool isReconnecting = false;
|
||||
|
||||
int timerTime = 0;
|
||||
QString relative_path;
|
||||
QString usbmsStatus;
|
||||
|
@ -62,9 +65,10 @@ public:
|
|||
void openUsbmsDialog();
|
||||
void resetIcons();
|
||||
void setBatteryIcon();
|
||||
bool checkWifiState();
|
||||
|
||||
public slots:
|
||||
void showToast(QString messageToDisplay);
|
||||
void closeIndefiniteToast();
|
||||
|
||||
private slots:
|
||||
void on_settingsBtn_clicked();
|
||||
|
@ -74,17 +78,14 @@ 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 updateWifiAble();
|
||||
void on_wifiBtn_clicked();
|
||||
void updateWifiIcon(int mode);
|
||||
void updateWifiIcon();
|
||||
void hello(int testNumber);
|
||||
void showToast(QString messageToDisplay);
|
||||
void closeIndefiniteToast();
|
||||
void openUpdateDialogOTA(bool open);
|
||||
void launchOtaUpdater();
|
||||
void openBookFile(QString book, bool relativePath);
|
||||
|
@ -95,7 +96,6 @@ private slots:
|
|||
void on_libraryButton_clicked();
|
||||
void resetWindow(bool resetStackedWidget);
|
||||
void resetFullWindow();
|
||||
void resetWifiIconClickedWhileReconnecting();
|
||||
void setupLocalLibraryWidget();
|
||||
void setupHomePageWidget();
|
||||
|
||||
|
|
|
@ -41,6 +41,7 @@ int main(int argc, char *argv[])
|
|||
global::logger::status = true;
|
||||
}
|
||||
}
|
||||
|
||||
global::deviceID = readFile("/opt/inkbox_device");
|
||||
log("Running on device " + global::deviceID, "main", true);
|
||||
|
||||
|
@ -226,7 +227,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/hide.png
Normal file
BIN
src/resources/hide.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1 KiB |
BIN
src/resources/show.png
Normal file
BIN
src/resources/show.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 993 B |
BIN
src/resources/stop.png
Normal file
BIN
src/resources/stop.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 11 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 {
|
||||
|
|
|
@ -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">
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
@ -495,15 +495,13 @@ void generalDialog::on_okBtn_clicked()
|
|||
}
|
||||
else if(global::keyboard::wifiPassphraseDialog == true) {
|
||||
if(!global::keyboard::keyboardText.isEmpty()) {
|
||||
log("Attempting connection to Wi-Fi network '" + wifiEssid + "'", className);
|
||||
this->hide();
|
||||
wifiPassphrase = global::keyboard::keyboardText;
|
||||
global::toast::indefiniteToast = true;
|
||||
global::toast::modalToast = true;
|
||||
emit showToast("Connecting");
|
||||
QTimer::singleShot(100, this, SLOT(connectToNetworkSlot()));
|
||||
global::keyboard::wifiPassphraseDialog = false;
|
||||
global::keyboard::keyboardDialog = false;
|
||||
if(global::keyboard::keyboardText.count() < 8) {
|
||||
global::toast::delay = 3000;
|
||||
showToast("Minimum password length is 8 characters");
|
||||
}
|
||||
else {
|
||||
generalDialog::close();
|
||||
}
|
||||
}
|
||||
else {
|
||||
global::toast::delay = 3000;
|
||||
|
@ -596,6 +594,7 @@ void generalDialog::restartSearchDialog() {
|
|||
}
|
||||
|
||||
void generalDialog::setupKeyboardDialog() {
|
||||
adjust_size();
|
||||
ui->stackedWidget->setCurrentIndex(0);
|
||||
keyboardDialog = true;
|
||||
ui->stackedWidget->setVisible(true);
|
||||
|
@ -612,7 +611,7 @@ void generalDialog::setupKeyboardDialog() {
|
|||
}
|
||||
else if(global::keyboard::wifiPassphraseDialog == true) {
|
||||
ui->headerLabel->setText("Enter the network's passphrase");
|
||||
ui->okBtn->setText("Connect");
|
||||
ui->okBtn->setText("Enter");
|
||||
ui->cancelBtn->setText("Cancel");
|
||||
}
|
||||
else if(global::keyboard::encfsDialog == true) {
|
||||
|
@ -629,6 +628,7 @@ void generalDialog::setupKeyboardDialog() {
|
|||
connect(keyboardWidget, SIGNAL(adjust_size()), SLOT(adjust_size()));
|
||||
ui->mainStackedWidget->insertWidget(1, keyboardWidget);
|
||||
ui->mainStackedWidget->setCurrentIndex(1);
|
||||
adjust_size();
|
||||
QTimer::singleShot(1000, this, SLOT(adjust_size()));
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
|
323
src/widgets/dialogs/wifi/connectiondialog.cpp
Normal file
323
src/widgets/dialogs/wifi/connectiondialog.cpp
Normal file
|
@ -0,0 +1,323 @@
|
|||
#include <QFile>
|
||||
#include <QScreen>
|
||||
|
||||
#include "connectiondialog.h"
|
||||
#include "ui_connectiondialog.h"
|
||||
#include "generaldialog.h"
|
||||
#include "functions.h"
|
||||
|
||||
connectiondialog::connectiondialog(QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::connectiondialog)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
// Stylesheet, style & misc.
|
||||
QFile stylesheetFile("/mnt/onboard/.adds/inkbox/eink.qss");
|
||||
stylesheetFile.open(QFile::ReadOnly);
|
||||
this->setStyleSheet(stylesheetFile.readAll());
|
||||
stylesheetFile.close();
|
||||
|
||||
ui->cancelBtn->setStyleSheet("font-size: 9pt");
|
||||
ui->connectBtn->setStyleSheet("font-size: 9pt");
|
||||
ui->showPasswordBtn->setStyleSheet("font-size: 9pt");
|
||||
|
||||
// Size
|
||||
QRect screenGeometry = QGuiApplication::screens()[0]->geometry();
|
||||
this->setFixedWidth(screenGeometry.width());
|
||||
|
||||
|
||||
}
|
||||
|
||||
connectiondialog::~connectiondialog()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void connectiondialog::applyVariables() {
|
||||
// Here, for some devices it will be propably needed to limit the size
|
||||
ui->nameLabel->setText(connectedNetworkData.name);
|
||||
ui->macLabel->setText(connectedNetworkData.mac);
|
||||
ui->signalLabel->setText(QString::number(connectedNetworkData.signal) + "%");
|
||||
|
||||
if(connectedNetworkData.encryption == false) {
|
||||
ui->showPasswordBtn->hide();
|
||||
ui->passwordTextEdit->setText("No password required");
|
||||
ui->passwordTextEdit->setDisabled(true);
|
||||
}
|
||||
else {
|
||||
if(passwordDatabase.exists() == false) {
|
||||
log("Creating empty database", className);
|
||||
// https://forum.qt.io/topic/104791/how-i-can-create-json-format-in-qt/5
|
||||
QJsonObject root;
|
||||
QJsonArray array;
|
||||
QJsonDocument newJsonDocument;
|
||||
root["list"] = array;
|
||||
newJsonDocument.setObject(root);
|
||||
|
||||
passwordDatabase.open(QFile::WriteOnly | QFile::Text | QFile::Truncate);
|
||||
passwordDatabase.write(newJsonDocument.toJson());
|
||||
passwordDatabase.flush();
|
||||
passwordDatabase.close();
|
||||
}
|
||||
QString password = searchDatabase(connectedNetworkData.name);
|
||||
if(password.isEmpty() == false) {
|
||||
log("Found password: " + password, className);
|
||||
ui->showPasswordBtn->setIcon(QIcon(":/resources/show.png"));
|
||||
showedPassword = false;
|
||||
savedPassword = password;
|
||||
|
||||
ui->passwordTextEdit->setText("********");
|
||||
}
|
||||
else {
|
||||
log("No password found", className);
|
||||
ui->passwordTextEdit->setText("No password was saved");
|
||||
showedPassword = true;
|
||||
ui->showPasswordBtn->hide();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QString connectiondialog::searchDatabase(QString key) {
|
||||
passwordDatabase.open(QIODevice::ReadOnly | QIODevice::Text);
|
||||
QString fileRead = passwordDatabase.readAll();
|
||||
passwordDatabase.close();
|
||||
QJsonDocument jsonDocument = QJsonDocument::fromJson(fileRead.toUtf8());
|
||||
|
||||
if(jsonDocument["list"].isArray() == true) {
|
||||
QJsonArray jsonArray = jsonDocument["list"].toArray();
|
||||
for(QJsonValueRef refJsonObject: jsonArray) {
|
||||
QJsonObject jsonMainObject = refJsonObject.toObject();
|
||||
QString searchedName = jsonMainObject.keys().first().toUtf8();
|
||||
log("Found in database: '" + searchedName + "'", className);
|
||||
if(searchedName == key) {
|
||||
QString returnedPassword = jsonMainObject.value(key).toString();
|
||||
log("Searched name '" + searchedName + "' matched '" + key + "' and the password is: '" + returnedPassword + "'", className);
|
||||
return returnedPassword;
|
||||
}
|
||||
else {
|
||||
log("Searched name '" + searchedName + "' doesn't match " + key + "'", className);
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
else {
|
||||
log("Something went horribly wrong", className);
|
||||
}
|
||||
}
|
||||
|
||||
void connectiondialog::writeToDatabase(QString name, QString password) {
|
||||
if(searchDatabase(name).isEmpty() == false) {
|
||||
removeFromDatabase(name);
|
||||
}
|
||||
|
||||
passwordDatabase.open(QIODevice::ReadOnly | QIODevice::Text);
|
||||
QString fileRead = passwordDatabase.readAll();
|
||||
passwordDatabase.close();
|
||||
QJsonDocument jsonDocument = QJsonDocument::fromJson(fileRead.toUtf8());
|
||||
|
||||
if(jsonDocument["list"].isArray() == true) {
|
||||
QJsonArray jsonArray = jsonDocument["list"].toArray();
|
||||
QJsonValue newValue;
|
||||
|
||||
// https://stackoverflow.com/questions/26804660/how-to-initialize-qjsonobject-from-qstring
|
||||
// I hoped this would be easier
|
||||
QJsonObject newObject = QJsonDocument::fromJson(QString("{\"" + name + "\" : \"" + password + "\" }").toUtf8()).object();
|
||||
jsonArray.append(newObject);
|
||||
|
||||
QJsonDocument newJsonDocument;
|
||||
QJsonObject root;
|
||||
root["list"] = jsonArray;
|
||||
newJsonDocument.setObject(root);
|
||||
|
||||
passwordDatabase.open(QFile::WriteOnly | QFile::Text | QFile::Truncate);
|
||||
passwordDatabase.write(newJsonDocument.toJson());
|
||||
passwordDatabase.flush();
|
||||
passwordDatabase.close();
|
||||
}
|
||||
else {
|
||||
log("Something went horribly wrong", className);
|
||||
}
|
||||
}
|
||||
|
||||
void connectiondialog::removeFromDatabase(QString name) {
|
||||
passwordDatabase.open(QIODevice::ReadOnly | QIODevice::Text);
|
||||
QString fileRead = passwordDatabase.readAll();
|
||||
passwordDatabase.close();
|
||||
QJsonDocument jsonDocument = QJsonDocument::fromJson(fileRead.toUtf8());
|
||||
|
||||
int counter = 0;
|
||||
bool remove = false;
|
||||
if(jsonDocument["list"].isArray() == true) {
|
||||
QJsonArray jsonArray = jsonDocument["list"].toArray();
|
||||
for(QJsonValueRef refJsonObject: jsonArray) {
|
||||
QJsonObject jsonMainObject = refJsonObject.toObject();
|
||||
QString searchedName = jsonMainObject.keys().first().toUtf8();
|
||||
log("Found in database: '" + searchedName + "'", className);
|
||||
if(searchedName == name) {
|
||||
remove = true;
|
||||
}
|
||||
if(remove == false) {
|
||||
counter = counter + 1;
|
||||
}
|
||||
}
|
||||
if(remove == true) {
|
||||
jsonArray.removeAt(counter);
|
||||
QJsonDocument newJsonDocument;
|
||||
QJsonObject root;
|
||||
root["list"] = jsonArray;
|
||||
newJsonDocument.setObject(root);
|
||||
|
||||
passwordDatabase.open(QFile::WriteOnly | QFile::Text | QFile::Truncate);
|
||||
passwordDatabase.write(newJsonDocument.toJson());
|
||||
passwordDatabase.flush();
|
||||
passwordDatabase.close();
|
||||
}
|
||||
else {
|
||||
log("ERROR: tried to remove from database, but couldn't find key", className);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void connectiondialog::on_cancelBtn_clicked()
|
||||
{
|
||||
this->deleteLater();
|
||||
this->close();
|
||||
}
|
||||
|
||||
void connectiondialog::on_passwordTextEdit_selectionChanged()
|
||||
{
|
||||
ui->passwordTextEdit->setSelection(0, 0);
|
||||
}
|
||||
|
||||
void connectiondialog::on_passwordTextEdit_cursorPositionChanged(int oldpos, int newpos)
|
||||
{
|
||||
log("Detected click on text edit widget", className);
|
||||
if(cursorPositionIgnore == true) {
|
||||
if(newpos != 0) {
|
||||
if(showedPassword == true) {
|
||||
ui->passwordTextEdit->setCursorPosition(0);
|
||||
global::keyboard::keyboardDialog = true;
|
||||
global::keyboard::wifiPassphraseDialog = true;
|
||||
global::keyboard::keyboardText = "";
|
||||
generalDialog* generalDialogWindow = new generalDialog();
|
||||
generalDialogWindow->setAttribute(Qt::WA_DeleteOnClose);
|
||||
generalDialogWindow->wifiEssid = connectedNetworkData.name;
|
||||
connect(generalDialogWindow, &generalDialog::showToast, this, &connectiondialog::showToastSlot);
|
||||
connect(generalDialogWindow, &generalDialog::refreshScreen, this, &connectiondialog::refreshScreenSlot);
|
||||
|
||||
generalDialogWindow->exec();
|
||||
|
||||
global::keyboard::keyboardDialog = false;
|
||||
global::keyboard::wifiPassphraseDialog = false;
|
||||
if(global::keyboard::keyboardText.isEmpty() == false) {
|
||||
// A bit hacky: avoid summoning the keyboard back when the text is changing (and the cursor too) showedPassword shouldn't be used for this, but it works and adding another boolean would start being messy
|
||||
showedPassword = false;
|
||||
ui->passwordTextEdit->setText(global::keyboard::keyboardText);
|
||||
ui->showPasswordBtn->setIcon(QIcon(":/resources/hide.png"));
|
||||
ui->showPasswordBtn->show();
|
||||
showedPassword = true;
|
||||
savedPassword = global::keyboard::keyboardText;
|
||||
ui->showPasswordBtn->show();
|
||||
}
|
||||
global::keyboard::keyboardText = "";
|
||||
}
|
||||
else {
|
||||
log("Password is not saved; ignoring text edit call", className);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
log("Ignoring click on text edit", className);
|
||||
cursorPositionIgnore = true;
|
||||
}
|
||||
}
|
||||
|
||||
void connectiondialog::showToastSlot(QString message) {
|
||||
emit showToastSignal(message);
|
||||
}
|
||||
|
||||
void connectiondialog::on_showPasswordBtn_clicked()
|
||||
{
|
||||
if(showedPassword == false) {
|
||||
ui->showPasswordBtn->setIcon(QIcon(":/resources/hide.png"));
|
||||
ui->passwordTextEdit->setText(savedPassword);
|
||||
showedPassword = true;
|
||||
}
|
||||
else {
|
||||
showedPassword = false;
|
||||
ui->showPasswordBtn->setIcon(QIcon(":/resources/show.png"));
|
||||
ui->passwordTextEdit->setText("********");
|
||||
}
|
||||
}
|
||||
|
||||
void connectiondialog::refreshScreenSlot() {
|
||||
this->repaint();
|
||||
emit refreshScreenSignal();
|
||||
}
|
||||
|
||||
void connectiondialog::on_connectBtn_clicked()
|
||||
{
|
||||
QString finalPassword;
|
||||
if(connectedNetworkData.encryption == false) {
|
||||
finalPassword = "NONE";
|
||||
}
|
||||
else {
|
||||
if(savedPassword.isEmpty() == false) {
|
||||
finalPassword = savedPassword;
|
||||
writeToDatabase(connectedNetworkData.name, savedPassword);
|
||||
}
|
||||
else {
|
||||
showToastSlot("Provide a password first");
|
||||
return void();
|
||||
}
|
||||
}
|
||||
passwordForReconnecting = finalPassword;
|
||||
|
||||
ui->cancelBtn->setEnabled(false);
|
||||
if(checkWifiState() == global::wifi::wifiState::configured) {
|
||||
string_writeconfig("/opt/ibxd", "stop_wifi_operations\n");
|
||||
}
|
||||
writeFile("/run/wifi_network_essid", connectedNetworkData.name);
|
||||
writeFile("/run/wifi_network_passphrase", finalPassword);
|
||||
finalConnectWait();
|
||||
}
|
||||
|
||||
void connectiondialog::finalConnectWait() {
|
||||
if(checkIfWifiBusy() == true) {
|
||||
// To be sure
|
||||
if(waitTry == 10) {
|
||||
string_writeconfig("/opt/ibxd", "stop_wifi_operations\n");
|
||||
}
|
||||
// Wait for everything to shut down; 10 seconds timeout
|
||||
if(waitTry == 20) {
|
||||
string_writeconfig("/opt/ibxd", "stop_wifi_operations\n");
|
||||
emit showToastSignal("Failed to stop other Wi-Fi processes");
|
||||
ui->cancelBtn->setEnabled(true);
|
||||
}
|
||||
else {
|
||||
QTimer::singleShot(500, this, SLOT(finalConnectWait()));
|
||||
waitTry = waitTry + 1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
string_writeconfig("/opt/ibxd", "connect_to_wifi_network\n");
|
||||
|
||||
// This will be deleted later in MainWindow's icon updater if it failed. It is also deleted in the Wi-Fi stop script
|
||||
log("Writing to config directory with connection information data", className);
|
||||
string_writeconfig("/mnt/onboard/.adds/inkbox/.config/17-wifi_connection_information/essid", connectedNetworkData.name.toStdString());
|
||||
string_writeconfig("/mnt/onboard/.adds/inkbox/.config/17-wifi_connection_information/passphrase", passwordForReconnecting.toStdString());
|
||||
|
||||
this->deleteLater();
|
||||
this->close();
|
||||
}
|
||||
}
|
||||
|
||||
bool connectiondialog::checkIfWifiBusy() {
|
||||
if(checkProcessName("connect_to_network.sh") == true or checkProcessName("connection_manager.sh") == true or checkProcessName("prepare_changing_wifi.sh") == true) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
58
src/widgets/dialogs/wifi/connectiondialog.h
Normal file
58
src/widgets/dialogs/wifi/connectiondialog.h
Normal file
|
@ -0,0 +1,58 @@
|
|||
#ifndef CONNECTIONDIALOG_H
|
||||
#define CONNECTIONDIALOG_H
|
||||
|
||||
#include <QDialog>
|
||||
#include "functions.h"
|
||||
|
||||
namespace Ui {
|
||||
class connectiondialog;
|
||||
}
|
||||
|
||||
class connectiondialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
QString className = this->metaObject()->className();
|
||||
explicit connectiondialog(QWidget *parent = nullptr);
|
||||
~connectiondialog();
|
||||
global::wifi::wifiNetworkData connectedNetworkData;
|
||||
QString currentlyConnectedNetworkName;
|
||||
QFile passwordDatabase = QFile("/mnt/onboard/.adds/inkbox/.config/17-wifi_connection_information/passwords.json");
|
||||
|
||||
signals:
|
||||
void showToastSignal(QString message);
|
||||
void refreshScreenSignal();
|
||||
|
||||
public slots:
|
||||
void applyVariables();
|
||||
void showToastSlot(QString message);
|
||||
void refreshScreenSlot();
|
||||
|
||||
private slots:
|
||||
// We are opening/loading the JSON database many times, it might not be efficient, but:
|
||||
// 1. It's modular
|
||||
// 2. Those operations are rare
|
||||
QString searchDatabase(QString key);
|
||||
void writeToDatabase(QString name, QString password);
|
||||
void removeFromDatabase(QString name);
|
||||
|
||||
void finalConnectWait();
|
||||
bool checkIfWifiBusy();
|
||||
|
||||
void on_cancelBtn_clicked();
|
||||
void on_passwordTextEdit_selectionChanged();
|
||||
void on_passwordTextEdit_cursorPositionChanged(int arg1, int arg2);
|
||||
void on_showPasswordBtn_clicked();
|
||||
void on_connectBtn_clicked();
|
||||
|
||||
private:
|
||||
Ui::connectiondialog *ui;
|
||||
bool cursorPositionIgnore = false;
|
||||
bool showedPassword;
|
||||
QString savedPassword;
|
||||
int waitTry = 0;
|
||||
QString passwordForReconnecting;
|
||||
};
|
||||
|
||||
#endif // CONNECTIONDIALOG_H
|
189
src/widgets/dialogs/wifi/connectiondialog.ui
Normal file
189
src/widgets/dialogs/wifi/connectiondialog.ui
Normal file
|
@ -0,0 +1,189 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>connectiondialog</class>
|
||||
<widget class="QDialog" name="connectiondialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>263</width>
|
||||
<height>136</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Dialog</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<property name="sizeConstraint">
|
||||
<enum>QLayout::SetFixedSize</enum>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QPushButton" name="cancelBtn">
|
||||
<property name="text">
|
||||
<string>Cancel</string>
|
||||
</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="connectBtn">
|
||||
<property name="text">
|
||||
<string>Connect</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||
<item>
|
||||
<widget class="QLineEdit" name="passwordTextEdit">
|
||||
<property name="cursor">
|
||||
<cursorShape>BlankCursor</cursorShape>
|
||||
</property>
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="showPasswordBtn">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_4">
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<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>TextLabel</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_2">
|
||||
<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>TextLabel</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>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
89
src/widgets/dialogs/wifi/network.cpp
Normal file
89
src/widgets/dialogs/wifi/network.cpp
Normal file
|
@ -0,0 +1,89 @@
|
|||
#include "network.h"
|
||||
#include "ui_network.h"
|
||||
#include "connectiondialog.h"
|
||||
|
||||
network::network(QWidget *parent) :
|
||||
QWidget(parent),
|
||||
ui(new Ui::network)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
// Stylesheet, style & misc.
|
||||
QFile stylesheetFile("/mnt/onboard/.adds/inkbox/eink.qss");
|
||||
stylesheetFile.open(QFile::ReadOnly);
|
||||
this->setStyleSheet(stylesheetFile.readAll());
|
||||
stylesheetFile.close();
|
||||
|
||||
// Buttons
|
||||
ui->encryptionIcon->setProperty("type", "borderless");
|
||||
ui->encryptionIcon->setStyleSheet("QPushButton[type='borderless']:pressed { background: white; color: white; border: none; }");
|
||||
ui->enterButton->setProperty("type", "borderless");
|
||||
}
|
||||
|
||||
network::~network()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void network::applyVariables() {
|
||||
log("Applying variables for network", className);
|
||||
QString percent = "%";
|
||||
if(mainData.signal < 100) {
|
||||
percent.append(" ");
|
||||
}
|
||||
ui->signalStrengthLabel->setText(QString::number(mainData.signal) + percent);
|
||||
|
||||
// Limit name size
|
||||
QString cutSingleData = mainData.name;
|
||||
if(cutSingleData.count() > 27) {
|
||||
cutSingleData = cutSingleData.remove(24, cutSingleData.count() - 24);
|
||||
cutSingleData.append("...");
|
||||
}
|
||||
ui->nameLabel->setText(cutSingleData);
|
||||
|
||||
if(mainData.encryption == true) {
|
||||
ui->encryptionIcon->setIcon(QIcon(":/resources/lock.png"));
|
||||
}
|
||||
else {
|
||||
ui->encryptionIcon->setIcon(QIcon(":/resources/public.png"));
|
||||
}
|
||||
|
||||
if(currentlyConnectedNetwork == mainData.name) {
|
||||
ui->frame->setStyleSheet(".QFrame{background-color: grey; border: 3px solid black; border-radius: 10px;}");
|
||||
ui->signalStrengthLabel->setStyleSheet("background-color:grey;");
|
||||
ui->nameLabel->setStyleSheet("background-color:grey;");
|
||||
ui->encryptionIcon->setStyleSheet("background-color:grey;");
|
||||
ui->enterButton->setStyleSheet("background-color:grey;");
|
||||
|
||||
ui->encryptionIcon->setStyleSheet("QPushButton {background-color: grey; border: none}; QPushButton[type='borderless']:pressed { background: grey; color: grey; border: none; }");
|
||||
ui->enterButton->setStyleSheet("QPushButton {background-color: grey; border: none}; QPushButton[type='borderless']:pressed { background: grey; color: grey; border: none; }");
|
||||
|
||||
}
|
||||
else {
|
||||
ui->frame->setStyleSheet(".QFrame{background-color: white; border: 3px solid black; border-radius: 10px;}");
|
||||
}
|
||||
}
|
||||
|
||||
void network::on_enterButton_clicked()
|
||||
{
|
||||
connectiondialog* newConnectionDialog = new connectiondialog;
|
||||
newConnectionDialog->connectedNetworkData = mainData;
|
||||
newConnectionDialog->currentlyConnectedNetworkName = currentlyConnectedNetwork;
|
||||
newConnectionDialog->applyVariables();
|
||||
connect(newConnectionDialog, &connectiondialog::showToastSignal, this, &network::showToastSlot);
|
||||
connect(newConnectionDialog, &connectiondialog::refreshScreenSignal, this, &network::refreshScreenSlot);
|
||||
newConnectionDialog->exec();
|
||||
}
|
||||
|
||||
void network::closeWrapper() {
|
||||
this->deleteLater();
|
||||
this->close();
|
||||
}
|
||||
|
||||
void network::showToastSlot(QString message) {
|
||||
emit showToastSignal(message);
|
||||
}
|
||||
|
||||
void network::refreshScreenSlot() {
|
||||
emit refreshScreenSignal();
|
||||
}
|
40
src/widgets/dialogs/wifi/network.h
Normal file
40
src/widgets/dialogs/wifi/network.h
Normal file
|
@ -0,0 +1,40 @@
|
|||
#ifndef NETWORK_H
|
||||
#define NETWORK_H
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
#include "functions.h"
|
||||
|
||||
namespace Ui {
|
||||
class network;
|
||||
}
|
||||
|
||||
class network : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
QString className = this->metaObject()->className();
|
||||
explicit network(QWidget *parent = nullptr);
|
||||
~network();
|
||||
global::wifi::wifiNetworkData mainData;
|
||||
QString currentlyConnectedNetwork;
|
||||
|
||||
signals:
|
||||
void showToastSignal(QString message);
|
||||
void refreshScreenSignal();
|
||||
|
||||
public slots:
|
||||
void applyVariables();
|
||||
void closeWrapper();
|
||||
void showToastSlot(QString message);
|
||||
void refreshScreenSlot();
|
||||
|
||||
private slots:
|
||||
void on_enterButton_clicked();
|
||||
|
||||
private:
|
||||
Ui::network *ui;
|
||||
};
|
||||
|
||||
#endif // NETWORK_H
|
132
src/widgets/dialogs/wifi/network.ui
Normal file
132
src/widgets/dialogs/wifi/network.ui
Normal file
|
@ -0,0 +1,132 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>network</class>
|
||||
<widget class="QWidget" name="network">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>605</width>
|
||||
<height>62</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<property name="leftMargin">
|
||||
<number>17</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>4</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>17</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>4</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QFrame" name="frame">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Plain</enum>
|
||||
</property>
|
||||
<property name="lineWidth">
|
||||
<number>3</number>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<property name="leftMargin">
|
||||
<number>3</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>3</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>3</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>3</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="signalStrengthLabel">
|
||||
<property name="text">
|
||||
<string>SIgnal strenth</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="Line" name="line">
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Plain</enum>
|
||||
</property>
|
||||
<property name="lineWidth">
|
||||
<number>3</number>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="nameLabel">
|
||||
<property name="text">
|
||||
<string>wifi name</string>
|
||||
</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="QPushButton" name="encryptionIcon">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="enterButton">
|
||||
<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>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources>
|
||||
<include location="../../../eink.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
</ui>
|
|
@ -3,18 +3,20 @@
|
|||
#include <QScreen>
|
||||
#include <QDesktopWidget>
|
||||
#include <QMessageBox>
|
||||
#include <QScrollBar>
|
||||
|
||||
#include "wifidialog.h"
|
||||
#include "ui_wifidialog.h"
|
||||
#include "functions.h"
|
||||
#include "mainwindow.h"
|
||||
#include "network.h"
|
||||
#include "wifilogger.h"
|
||||
|
||||
wifiDialog::wifiDialog(QWidget *parent) :
|
||||
QDialog(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 +25,47 @@ 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; }");
|
||||
ui->returnBtn->setProperty("type", "borderless");
|
||||
|
||||
checkWifiNetworks();
|
||||
// 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);
|
||||
|
||||
// And set wifi checkbox state. also ignore this first call
|
||||
global::wifi::wifiState currentWifiState = checkWifiState();
|
||||
if(currentWifiState != global::wifi::wifiState::disabled and currentWifiState != global::wifi::wifiState::unknown) {
|
||||
ui->wifiCheckBox->setChecked(true);
|
||||
// To be sure nothing breaks
|
||||
refreshFromWatcher = true;
|
||||
ui->refreshBtn->click();
|
||||
} else {
|
||||
wifiButtonEnabled = true;
|
||||
ui->stopBtn->setStyleSheet("background-color: gray;");
|
||||
ui->stopBtn->setEnabled(false);
|
||||
}
|
||||
|
||||
// To avoid confusion with reconnecting
|
||||
QTimer::singleShot(2000, this, SLOT(theWatcher()));
|
||||
}
|
||||
|
||||
wifiDialog::~wifiDialog()
|
||||
|
@ -39,105 +73,441 @@ 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();
|
||||
void wifiDialog::on_refreshBtn_clicked()
|
||||
{
|
||||
log("Clicked refresh button", className);
|
||||
if(checkWifiState() == global::wifi::wifiState::disabled) {
|
||||
if(refreshFromWatcher == true) {
|
||||
refreshFromWatcher = false;
|
||||
emit showToast("To scan, turn on wi-fi first");
|
||||
log("To scan, turn on wi-fi first", className);
|
||||
}
|
||||
} );
|
||||
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);
|
||||
refreshFromWatcher = false;
|
||||
launchRefresh();
|
||||
}
|
||||
}
|
||||
|
||||
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::launchRefresh() {
|
||||
// Order is important
|
||||
if(scanInProgress == false) {
|
||||
scanInProgress = true;
|
||||
ui->refreshBtn->setStyleSheet("background-color: gray;");
|
||||
ui->refreshBtn->setEnabled(false);
|
||||
|
||||
elapsedSeconds = 0;
|
||||
fullList.remove();
|
||||
formattedList.remove();
|
||||
writeFile("/opt/ibxd", "list_wifi_networks\n");
|
||||
QTimer::singleShot(0, this, SLOT(refreshWait()));
|
||||
}
|
||||
else {
|
||||
log("Scan is already in progress", className);
|
||||
}
|
||||
}
|
||||
|
||||
void wifiDialog::on_cancelBtn_clicked()
|
||||
void wifiDialog::refreshWait() {
|
||||
if(fullList.exists() == false and formattedList.exists() == false) {
|
||||
if(elapsedSeconds == 6) {
|
||||
emit showToast("Failed to get networks list");
|
||||
ui->refreshBtn->setStyleSheet("background-color:white;");
|
||||
ui->refreshBtn->setEnabled(true);
|
||||
scanInProgress = false;
|
||||
}
|
||||
else {
|
||||
elapsedSeconds = elapsedSeconds + 1;
|
||||
QTimer::singleShot(1000, this, SLOT(refreshWait()));
|
||||
}
|
||||
} else {
|
||||
log("Retrieved network list successfully", className);
|
||||
refreshNetworksList();
|
||||
}
|
||||
}
|
||||
|
||||
void wifiDialog::refreshNetworksList() {
|
||||
emit killNetworkWidgets();
|
||||
QStringList networkList = readFile("/external_root/run/wifi_list_format").split("%%==SPLIT==%%\n");
|
||||
QVector<global::wifi::wifiNetworkData> pureNetworkList;
|
||||
for(QString network: networkList) {
|
||||
QStringList data = network.split("\n");
|
||||
int count = 1;
|
||||
global::wifi::wifiNetworkData singleNetwork;
|
||||
if(data.count() < 4) {
|
||||
log("Data lines count is below 4; skipping", className);
|
||||
continue;
|
||||
}
|
||||
for(QString singleData: data) {
|
||||
if(count == 1) {
|
||||
singleNetwork.mac = singleData;
|
||||
log("MAC is: " + singleData, className);
|
||||
}
|
||||
if(count == 2) {
|
||||
if(singleData.isEmpty() == true) {
|
||||
log("Network name is empty", className);
|
||||
}
|
||||
else {
|
||||
log("Network name is: " + singleData, className);
|
||||
}
|
||||
singleNetwork.name = singleData;
|
||||
}
|
||||
if(count == 3) {
|
||||
log("Encryption type is: " + singleData, className);
|
||||
singleNetwork.encryption = QVariant(singleData).toBool();
|
||||
}
|
||||
if(count == 4) {
|
||||
log("Signal strength is: " + singleData, className);
|
||||
singleNetwork.signal = QVariant(singleData).toInt();
|
||||
}
|
||||
if(count >= 5) {
|
||||
log("Skipping additional items from network information", className);
|
||||
}
|
||||
count = count + 1;
|
||||
}
|
||||
// Filter out remaining empty networks
|
||||
if(singleNetwork.name.isEmpty() == false) {
|
||||
pureNetworkList.append(singleNetwork);
|
||||
}
|
||||
}
|
||||
log("Found " + QString::number(pureNetworkList.count()) + " valid networks", className);
|
||||
if(pureNetworkList.count() == 0) {
|
||||
if(secondScanTry == false) {
|
||||
secondScanTry = true;
|
||||
if(checkWifiState() != global::wifi::wifiState::disabled) {
|
||||
scanInProgress = false;
|
||||
QTimer::singleShot(0, this, SLOT(launchRefresh()));
|
||||
log("No networks found. Trying one more time");
|
||||
return void();
|
||||
}
|
||||
else {
|
||||
return void();
|
||||
}
|
||||
}
|
||||
else {
|
||||
secondScanTry = false;
|
||||
log("No networks found, skipping", className);
|
||||
showToastSlot("No networks found");
|
||||
ui->refreshBtn->setEnabled(true);
|
||||
ui->refreshBtn->setStyleSheet("background-color: white;");
|
||||
scanInProgress = false;
|
||||
return void();
|
||||
}
|
||||
}
|
||||
QFile currentWifiNameFile = QFile("/external_root/run/current_wifi_name");
|
||||
currentWifiNameFile.remove();
|
||||
writeFile("/opt/ibxd", "get_current_wifi_name\n");
|
||||
usleep(300000); // 0.3s
|
||||
// Here, it's looking for the currently connected network to put it on top of the list
|
||||
QString currentNetwork = "";
|
||||
if(currentWifiNameFile.exists() == true) {
|
||||
QString currentWifiNetwork = readFile(currentWifiNameFile.fileName());
|
||||
currentWifiNetwork = currentWifiNetwork.replace("\n", "");
|
||||
log("Current network name is: " + currentWifiNetwork, className);
|
||||
int countVec = 0;
|
||||
int vectorNetworkLocation = 9999;
|
||||
for(global::wifi::wifiNetworkData wifiNetwork: pureNetworkList) {
|
||||
if(currentWifiNetwork.isEmpty() == false and wifiNetwork.name.contains(currentWifiNetwork) == true) {
|
||||
log("Found current network in vector", className);
|
||||
vectorNetworkLocation = countVec;
|
||||
currentNetwork = wifiNetwork.name;
|
||||
network* connectedNetwork = new network;
|
||||
connectedNetwork->mainData = wifiNetwork;
|
||||
// To be really sure that the the info is put there
|
||||
connectedNetwork->currentlyConnectedNetwork = currentNetwork;
|
||||
connectedNetworkDataParent = wifiNetwork;
|
||||
connectedNetworkDataParentSet = true;
|
||||
|
||||
// This doesn't work, so a layout is needed
|
||||
// ui->scrollArea->addScrollBarWidget(connectedNetwork, Qt::AlignTop);
|
||||
connectedNetwork->applyVariables();
|
||||
connect(this, &wifiDialog::killNetworkWidgets, connectedNetwork, &network::closeWrapper);
|
||||
connect(connectedNetwork, &network::showToastSignal, this, &wifiDialog::showToastSlot);
|
||||
connect(connectedNetwork, &network::refreshScreenSignal, this, &wifiDialog::refreshScreenSlot);
|
||||
ui->scrollBarLayout->addWidget(connectedNetwork, Qt::AlignTop);
|
||||
}
|
||||
else {
|
||||
countVec = countVec + 1;
|
||||
}
|
||||
}
|
||||
if(vectorNetworkLocation != 9999) {
|
||||
log("pureNetworkList size is: " + QString::number(pureNetworkList.count()) + ", entry at " + QString::number(vectorNetworkLocation) + " slated for removal", className);
|
||||
pureNetworkList.removeAt(vectorNetworkLocation);
|
||||
}
|
||||
}
|
||||
|
||||
// Sort based on signal strength
|
||||
QVector<global::wifi::wifiNetworkData> sortedPureNetworkList;
|
||||
sortedPureNetworkList.append(pureNetworkList.first());
|
||||
pureNetworkList.removeFirst();
|
||||
for(global::wifi::wifiNetworkData wifiNetwork: pureNetworkList) {
|
||||
bool stopIterating = false;
|
||||
int counter = 0;
|
||||
for(global::wifi::wifiNetworkData wifiNetworkToSort: sortedPureNetworkList) {
|
||||
if(stopIterating == false) {
|
||||
if(wifiNetwork.signal >= wifiNetworkToSort.signal) {
|
||||
sortedPureNetworkList.insert(counter, wifiNetwork);
|
||||
stopIterating = true;
|
||||
}
|
||||
counter = counter + 1;
|
||||
}
|
||||
}
|
||||
// This happens if it's the smallest value, so insert it at the end
|
||||
if(stopIterating == false) {
|
||||
sortedPureNetworkList.append(wifiNetwork);
|
||||
}
|
||||
}
|
||||
log("There are " + QString::number(sortedPureNetworkList.count()) + " sorted networks", className);
|
||||
|
||||
for(global::wifi::wifiNetworkData wifiNetwork: sortedPureNetworkList) {
|
||||
log("Signal strength with sorting: " + QString::number(wifiNetwork.signal), className);
|
||||
}
|
||||
|
||||
// And now, handle the remainder of the networks
|
||||
for(global::wifi::wifiNetworkData wifiNetwork: sortedPureNetworkList) {
|
||||
network* connectedNetwork = new network;
|
||||
connectedNetwork->mainData = wifiNetwork;
|
||||
connectedNetwork->currentlyConnectedNetwork = currentNetwork;
|
||||
connectedNetwork->applyVariables();
|
||||
connect(this, &wifiDialog::killNetworkWidgets, connectedNetwork, &network::closeWrapper);
|
||||
connect(connectedNetwork, &network::showToastSignal, this, &wifiDialog::showToastSlot);
|
||||
connect(connectedNetwork, &network::refreshScreenSignal, this, &wifiDialog::refreshScreenSlot);
|
||||
ui->scrollBarLayout->addWidget(connectedNetwork, Qt::AlignTop);
|
||||
}
|
||||
scannedAtLeastOnce = true;
|
||||
ui->refreshBtn->setEnabled(true);
|
||||
ui->refreshBtn->setStyleSheet("background-color:white;");
|
||||
scanInProgress = false;
|
||||
secondScanTry = false;
|
||||
}
|
||||
|
||||
|
||||
void wifiDialog::on_wifiCheckBox_stateChanged(int arg1)
|
||||
{
|
||||
if(ignoreCheckBoxCall == false) {
|
||||
connectedNetworkDataParentSet = false;
|
||||
log("wifi dialog clicked: " + QString::number(arg1), className);
|
||||
if(wifiButtonEnabled == true) {
|
||||
if(arg1 == 2) {
|
||||
log("Turning Wi-Fi on", className);
|
||||
// the watcher will scan wifi
|
||||
QTimer::singleShot(0, this, SLOT(turnOnWifi()));
|
||||
ui->stopBtn->setStyleSheet("background-color: white;");
|
||||
ui->stopBtn->setEnabled(true);
|
||||
} else {
|
||||
log("Turning Wi-Fi off", className);
|
||||
QTimer::singleShot(0, this, SLOT(turnOffWifi()));
|
||||
// To inform the wifi icon GUI to don't show the connected/failed to connect message
|
||||
string_writeconfig("/mnt/onboard/.adds/inkbox/.config/17-wifi_connection_information/stopped", "true");
|
||||
ui->stopBtn->setStyleSheet("background-color: gray;");
|
||||
ui->stopBtn->setEnabled(false);
|
||||
}
|
||||
emit killNetworkWidgets();
|
||||
}
|
||||
if(wifiButtonEnabled == false){
|
||||
wifiButtonEnabled = true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
ignoreCheckBoxCall = false;
|
||||
if(checkWifiState() != global::wifi::wifiState::disabled) {
|
||||
emit killNetworkWidgets();
|
||||
forceRefresh = true;
|
||||
}
|
||||
else {
|
||||
emit killNetworkWidgets();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void wifiDialog::turnOnWifi() {
|
||||
string_writeconfig("/opt/ibxd", "toggle_wifi_on\n");
|
||||
// No one will notice this freeze :>
|
||||
waitToScan();
|
||||
}
|
||||
|
||||
void wifiDialog::turnOffWifi() {
|
||||
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;
|
||||
}
|
||||
|
||||
void wifiDialog::on_logBtn_clicked()
|
||||
{
|
||||
// To avoid half of the information
|
||||
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;
|
||||
if(connectedNetworkDataParentSet == true) {
|
||||
wifiLoggerDialog->connectedNetworkData = connectedNetworkDataParent;
|
||||
wifiLoggerDialog->isThereData = true;
|
||||
}
|
||||
wifiLoggerDialog->exec();
|
||||
}
|
||||
}
|
||||
|
||||
void wifiDialog::showToastSlot(QString message) {
|
||||
emit showToast(message);
|
||||
}
|
||||
|
||||
void wifiDialog::refreshScreenSlot() {
|
||||
this->repaint();
|
||||
}
|
||||
|
||||
/*
|
||||
Some documentation used by the watcher
|
||||
* connection_manager.sh - Manages all things, launches other processes
|
||||
* connect_to_network.sh - All-in-one connection manager. Manages everything, used by IPD, should be used for Wi-Fi reconnections after sleeping/booting
|
||||
* get_dhcp.sh - Gets dhcp addresses
|
||||
* prepare_changing_wifi.sh - Kills everything, prepares to changing network
|
||||
* smarter_time_sync.sh - Syncs time
|
||||
* toggle.sh - Turns on/off Wi-Fi adapter
|
||||
* list_networks.bin - Lists networks
|
||||
* check_wifi_password.sh - Checks Wi-Fi network password
|
||||
* watcher() first watches at processes that could kill other ones
|
||||
*/
|
||||
|
||||
void wifiDialog::watcher() {
|
||||
bool killing = checkProcessName("toggle.sh");
|
||||
bool changing = checkProcessName("prepare_changing_wifi.sh");
|
||||
if(killing == true) {
|
||||
setStatusText("Changing Wi-Fi adapter status");
|
||||
isToggleRunning = true;
|
||||
QTimer::singleShot(relaunchMs, this, SLOT(watcher()));
|
||||
return void();
|
||||
}
|
||||
|
||||
if(changing == true) {
|
||||
setStatusText("Disconnecting from a network or cleaning up");
|
||||
log("prepare_changing_wifi.sh is active", className);
|
||||
QTimer::singleShot(relaunchMs, this, SLOT(watcher()));
|
||||
return void();
|
||||
}
|
||||
|
||||
bool reconnection = checkProcessName("connect_to_network.sh");
|
||||
if(reconnection == true) {
|
||||
forceRefresh = true;
|
||||
QFile recName = QFile("/mnt/onboard/.adds/inkbox/.config/17-wifi_connection_information/essid");
|
||||
if(recName.exists() == true) {
|
||||
setStatusText("Reconnecting after suspending to " + readFile(recName.fileName()).replace("\n", ""));
|
||||
}
|
||||
else {
|
||||
// Shouldn't be possible
|
||||
setStatusText("Reconnecting after sleep");
|
||||
}
|
||||
QTimer::singleShot(relaunchMs, this, SLOT(watcher()));
|
||||
return void();
|
||||
}
|
||||
|
||||
bool listing = checkProcessName("list_networks.bin");
|
||||
if(listing == true) {
|
||||
setStatusText("Scanning networks ...");
|
||||
QTimer::singleShot(relaunchMs, this, SLOT(watcher()));
|
||||
return void();
|
||||
}
|
||||
|
||||
bool dhcp = checkProcessName("get_dhcp.sh");
|
||||
if(dhcp == true) {
|
||||
forceRefresh = true;
|
||||
setStatusText("Getting IP address");
|
||||
QTimer::singleShot(relaunchMs, this, SLOT(watcher()));
|
||||
return void();
|
||||
}
|
||||
|
||||
bool passwordCheck = checkProcessName("check_wifi_password.sh");
|
||||
if(passwordCheck == true) {
|
||||
forceRefresh = true;
|
||||
setStatusText("Checking Wi-Fi network password");
|
||||
QTimer::singleShot(relaunchMs, this, SLOT(watcher()));
|
||||
return void();
|
||||
}
|
||||
|
||||
bool time = checkProcessName("smarter_time_sync.sh");
|
||||
if(time == true) {
|
||||
forceRefresh = true;
|
||||
setStatusText("Syncing");
|
||||
QTimer::singleShot(relaunchMs, this, SLOT(watcher()));
|
||||
return void();
|
||||
}
|
||||
|
||||
bool connecting = checkProcessName("connection_manager.sh");
|
||||
if(connecting == true) {
|
||||
forceRefresh = true;
|
||||
setStatusText("Connecting to Wi-Fi network ...");
|
||||
QTimer::singleShot(relaunchMs, this, SLOT(watcher()));
|
||||
return void();
|
||||
}
|
||||
|
||||
if(ui->statusLabel->text() != "Idling") {
|
||||
setStatusText("Idling");
|
||||
}
|
||||
|
||||
if(unlockCheckBox == true) {
|
||||
ui->wifiCheckBox->setEnabled(true);
|
||||
unlockCheckBox = false;
|
||||
}
|
||||
|
||||
if(isToggleRunning == true) {
|
||||
isToggleRunning = false;
|
||||
// Make sure the checkbox is in the right state
|
||||
if(checkWifiState() == global::wifi::wifiState::disabled) {
|
||||
// In this state, ignore forceRefresh to avoid message
|
||||
forceRefresh = false;
|
||||
if(ui->wifiCheckBox->isChecked() == true) {
|
||||
ignoreCheckBoxCall = true;
|
||||
ui->wifiCheckBox->setChecked(false);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(ui->wifiCheckBox->isChecked() == false) {
|
||||
ignoreCheckBoxCall = true;
|
||||
ui->wifiCheckBox->setChecked(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
emit quit(0);
|
||||
wifiDialog::close();
|
||||
|
||||
if(forceRefresh == true) {
|
||||
forceRefresh = false;
|
||||
refreshFromWatcher = true;
|
||||
QTimer::singleShot(1500, this, SLOT(waitToScan()));
|
||||
}
|
||||
|
||||
QTimer::singleShot(relaunchMs, this, SLOT(watcher()));
|
||||
}
|
||||
|
||||
void wifiDialog::on_connectBtn_clicked()
|
||||
void wifiDialog::setStatusText(QString message) {
|
||||
ui->statusLabel->setText(message);
|
||||
}
|
||||
|
||||
void wifiDialog::on_stopBtn_clicked()
|
||||
{
|
||||
index = ui->networksListWidget->currentIndex();
|
||||
itemText = index.data(Qt::DisplayRole).toString();
|
||||
if(itemText.isEmpty()) {
|
||||
showToast("You must select a network");
|
||||
log("Stop button was clicked", className);
|
||||
connectedNetworkDataParentSet = false;
|
||||
ui->wifiCheckBox->setEnabled(false);
|
||||
unlockCheckBox = true;
|
||||
|
||||
// To inform the wifi icon GUI to don't show the connected/failed to connect message
|
||||
writeFile("/mnt/onboard/.adds/inkbox/.config/17-wifi_connection_information/stopped", "true");
|
||||
writeFile("/opt/ibxd", "stop_wifi_operations\n");
|
||||
|
||||
QFile("/mnt/onboard/.adds/inkbox/.config/17-wifi_connection_information/essid").remove();
|
||||
QFile("/mnt/onboard/.adds/inkbox/.config/17-wifi_connection_information/passphrase").remove();
|
||||
|
||||
// This variable just avoids showing the toast, so it is usable here too
|
||||
waitToScan();
|
||||
}
|
||||
|
||||
void wifiDialog::on_returnBtn_clicked()
|
||||
{
|
||||
this->deleteLater();
|
||||
this->close();
|
||||
}
|
||||
|
||||
void wifiDialog::waitToScan() {
|
||||
if(checkWifiState() != global::wifi::wifiState::disabled) {
|
||||
ui->refreshBtn->click();
|
||||
}
|
||||
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();
|
||||
QTimer::singleShot(750, this, SLOT(waitToScan()));
|
||||
}
|
||||
}
|
||||
|
||||
void wifiDialog::refreshScreenNative() {
|
||||
emit refreshScreen();
|
||||
}
|
||||
|
||||
void wifiDialog::updateWifiIcon(int mode) {
|
||||
emit updateWifiIconSig(mode);
|
||||
}
|
||||
|
||||
void wifiDialog::showToastNative(QString messageToDisplay) {
|
||||
emit showToast(messageToDisplay);
|
||||
}
|
||||
|
||||
void wifiDialog::closeIndefiniteToastNative() {
|
||||
emit closeIndefiniteToast();
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include <QModelIndex>
|
||||
|
||||
#include "generaldialog.h"
|
||||
#include "wifilogger.h"
|
||||
|
||||
namespace Ui {
|
||||
class wifiDialog;
|
||||
|
@ -18,33 +19,60 @@ public:
|
|||
QString className = this->metaObject()->className();
|
||||
explicit wifiDialog(QWidget *parent = nullptr);
|
||||
~wifiDialog();
|
||||
QString wifiNetworksList;
|
||||
QString itemText;
|
||||
QModelIndex index;
|
||||
void checkWifiNetworks();
|
||||
void printWifiNetworks();
|
||||
void centerDialog();
|
||||
global::wifi::wifiNetworkData connectedNetworkDataParent;
|
||||
bool connectedNetworkDataParentSet = false;
|
||||
|
||||
private:
|
||||
Ui::wifiDialog *ui;
|
||||
QTimer * wifiListTimer;
|
||||
generalDialog * generalDialogWindow;
|
||||
bool wifiButtonEnabled = false;
|
||||
bool scannedAtLeastOnce = false;
|
||||
|
||||
// Variables for refreshWait() and network refresh in general
|
||||
int elapsedSeconds = 0;
|
||||
QFile fullList = QFile("/external_root/run/wifi_list_full");
|
||||
QFile formattedList = QFile("/external_root/run/wifi_list_format");
|
||||
|
||||
// Used by watcher
|
||||
bool forceRefresh = false;
|
||||
int relaunchMs = 300;
|
||||
bool refreshFromWatcher = false;
|
||||
bool unlockCheckBox = false;
|
||||
bool scanInProgress = false;
|
||||
|
||||
bool isToggleRunning = false;
|
||||
bool ignoreCheckBoxCall = false;
|
||||
|
||||
bool secondScanTry = false;
|
||||
|
||||
public slots:
|
||||
void launchRefresh();
|
||||
void refreshNetworksList();
|
||||
void showToastSlot(QString message);
|
||||
void refreshScreenSlot();
|
||||
|
||||
// Shows status of Wi-Fi processes, like reconnection and others. Also manages refreshing the networks list after connection
|
||||
void watcher();
|
||||
|
||||
signals:
|
||||
void wifiNetworksListReady(int networksFound);
|
||||
void quit(int exitCode);
|
||||
void refreshScreen();
|
||||
void updateWifiIconSig(int mode);
|
||||
void showToast(QString messageToDisplay);
|
||||
void closeIndefiniteToast();
|
||||
void killNetworkWidgets();
|
||||
|
||||
private slots:
|
||||
void on_cancelBtn_clicked();
|
||||
void on_connectBtn_clicked();
|
||||
void refreshScreenNative();
|
||||
void updateWifiIcon(int mode);
|
||||
void showToastNative(QString messageToDisplay);
|
||||
void closeIndefiniteToastNative();
|
||||
void on_refreshBtn_clicked();
|
||||
void on_wifiCheckBox_stateChanged(int arg1);
|
||||
void turnOnWifi();
|
||||
void turnOffWifi();
|
||||
void on_logBtn_clicked();
|
||||
|
||||
// This function is a more clever sleep(1), non-blocking
|
||||
void refreshWait();
|
||||
|
||||
void setStatusText(QString message);
|
||||
void on_stopBtn_clicked();
|
||||
void on_returnBtn_clicked();
|
||||
void waitToScan();
|
||||
};
|
||||
|
||||
#endif // WIFIDIALOG_H
|
||||
|
|
|
@ -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,82 +15,248 @@
|
|||
</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">
|
||||
<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>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<property name="spacing">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_4">
|
||||
<property name="spacing">
|
||||
<number>10</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QPushButton" name="logBtn">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_3">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::Fixed</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<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>
|
||||
<spacer name="horizontalSpacer_4">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::Fixed</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</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>
|
||||
<pointsize>9</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Wifi status</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</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::NoFrame</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Plain</enum>
|
||||
</property>
|
||||
<property name="lineWidth">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="verticalScrollBarPolicy">
|
||||
<enum>Qt::ScrollBarAsNeeded</enum>
|
||||
</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>765</width>
|
||||
<height>567</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="page_2">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<property name="rightMargin">
|
||||
<number>9</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="scrollBarLayoutParent">
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<layout class="QGridLayout" name="gridLayout_4">
|
||||
<item row="1" column="0">
|
||||
<widget class="QListView" name="networksListWidget">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="mainLabel">
|
||||
<property name="font">
|
||||
<font>
|
||||
<weight>75</weight>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Select a network</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</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>
|
||||
<layout class="QVBoxLayout" name="scrollBarLayout"/>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="Line" name="line">
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Plain</enum>
|
||||
</property>
|
||||
<property name="lineWidth">
|
||||
<number>3</number>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</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>
|
||||
|
|
180
src/widgets/dialogs/wifi/wifilogger.cpp
Normal file
180
src/widgets/dialogs/wifi/wifilogger.cpp
Normal file
|
@ -0,0 +1,180 @@
|
|||
#include <QFile>
|
||||
#include <QScrollBar>
|
||||
|
||||
#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);
|
||||
|
||||
// Scroll bar
|
||||
// Needed for the nia.
|
||||
ui->allLogsText->verticalScrollBar()->setStyleSheet("QScrollBar:vertical { width: 50px; }");
|
||||
ui->fancyLogsText->verticalScrollBar()->setStyleSheet("QScrollBar:vertical { width: 50px; }");
|
||||
|
||||
|
||||
log("Entered wifilogger", className);
|
||||
setWifiInfoPage();
|
||||
ui->refreshBtn->setProperty("type", "borderless");
|
||||
|
||||
ui->nextBtn->setFixedWidth(70);
|
||||
ui->previousBtn->setFixedWidth(70);
|
||||
}
|
||||
|
||||
wifilogger::~wifilogger()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void wifilogger::setWifiInfoPage() {
|
||||
if(checkWifiState() == global::wifi::wifiState::configured) {
|
||||
QTimer::singleShot(0, this, SLOT(getWifiInformation()));
|
||||
ui->stackedWidget->setCurrentIndex(0);
|
||||
ui->nameLabel->setText("Network information");
|
||||
}
|
||||
else {
|
||||
ui->stackedWidget->setCurrentIndex(1);
|
||||
ui->nameLabel->setText("Not currently connected to a network");
|
||||
}
|
||||
}
|
||||
|
||||
void wifilogger::setFancyLoggingPage() {
|
||||
updateLogs();
|
||||
ui->stackedWidget->setCurrentIndex(2);
|
||||
ui->nameLabel->setText("Important logs");
|
||||
}
|
||||
|
||||
void wifilogger::setAllLogsPage() {
|
||||
updateLogs();
|
||||
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::getWifiInformation() {
|
||||
log("Retrieving Wi-Fi information", className);
|
||||
QFile wifiInformationPath = QFile("/external_root/run/wifi_information");
|
||||
if(waitingForFile == false) {
|
||||
wifiInformationPath.remove();
|
||||
|
||||
log("Sending get_wifi_information ibxd call", className);
|
||||
string_writeconfig("/opt/ibxd", "get_wifi_information\n");
|
||||
waitingForFile = true;
|
||||
}
|
||||
|
||||
if(waitingForFile == true) {
|
||||
if(wifiInformationPath.exists() == false) {
|
||||
QTimer::singleShot(1000, this, SLOT(getWifiInformation()));
|
||||
return void();
|
||||
}
|
||||
}
|
||||
|
||||
waitingForFile = false;
|
||||
log("Setting variables", className);
|
||||
QString wifiInfo = readFile(wifiInformationPath.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;
|
||||
}
|
||||
|
||||
if(isThereData == true) {
|
||||
ui->encryptionLabel->setText(QVariant(connectedNetworkData.encryption).toString());
|
||||
ui->signalLabel->setText(QString::number(connectedNetworkData.signal) + "%");
|
||||
ui->macLabel->setText(connectedNetworkData.mac);
|
||||
}
|
||||
else {
|
||||
// Shouldn't happen for 99%, but if anyway... it's designed to be non-blocking, so I can't really wait for this.
|
||||
ui->encryptionLabel->setText("Rescan needed");
|
||||
ui->signalLabel->setText("Rescan needed");
|
||||
ui->macLabel->setText("Rescan needed");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void wifilogger::on_returnBtn_clicked()
|
||||
{
|
||||
log("Exiting wifilogger", className);
|
||||
this->deleteLater();
|
||||
this->close();
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
void wifilogger::on_refreshBtn_clicked()
|
||||
{
|
||||
if(currentPage == 0) {
|
||||
if(waitingForFile == false) {
|
||||
setWifiInfoPage();
|
||||
}
|
||||
}
|
||||
else {
|
||||
updateLogs();
|
||||
}
|
||||
}
|
48
src/widgets/dialogs/wifi/wifilogger.h
Normal file
48
src/widgets/dialogs/wifi/wifilogger.h
Normal file
|
@ -0,0 +1,48 @@
|
|||
#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;
|
||||
// To the above value
|
||||
bool isThereData = false;
|
||||
|
||||
private:
|
||||
Ui::wifilogger *ui;
|
||||
/*
|
||||
* 0 Is Wi-Fi info/no Wi-Fi info page
|
||||
* 1 Is fancy logs page
|
||||
* 2 Is all logs page
|
||||
*/
|
||||
int currentPage = 0;
|
||||
QFile fancyLogs = QFile("/external_root/run/wifi_stats");
|
||||
QFile allLogs = QFile("/external_root/run/wifi_logs");
|
||||
bool waitingForFile = false;
|
||||
|
||||
private slots:
|
||||
void setWifiInfoPage();
|
||||
void setFancyLoggingPage();
|
||||
void setAllLogsPage();
|
||||
void on_nextBtn_clicked();
|
||||
void on_previousBtn_clicked();
|
||||
void changePage();
|
||||
void getWifiInformation();
|
||||
void on_returnBtn_clicked();
|
||||
void updateLogs();
|
||||
void on_refreshBtn_clicked();
|
||||
};
|
||||
|
||||
#endif // WIFILOGGER_H
|
425
src/widgets/dialogs/wifi/wifilogger.ui
Normal file
425
src/widgets/dialogs/wifi/wifilogger.ui
Normal file
|
@ -0,0 +1,425 @@
|
|||
<?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>3</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">
|
||||
<property name="textInteractionFlags">
|
||||
<set>Qt::NoTextInteraction</set>
|
||||
</property>
|
||||
</widget>
|
||||
</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">
|
||||
<property name="textInteractionFlags">
|
||||
<set>Qt::NoTextInteraction</set>
|
||||
</property>
|
||||
</widget>
|
||||
</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>
|
||||
<widget class="QPushButton" name="refreshBtn">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../../../eink.qrc">
|
||||
<normaloff>:/resources/refresh.png</normaloff>:/resources/refresh.png</iconset>
|
||||
</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>
|
|
@ -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