Toast messages; Wi-Fi dialog improvements

This commit is contained in:
Nicolas Mailloux 2021-07-14 01:24:30 -04:00
parent a532d00f48
commit 5793607d2b
13 changed files with 371 additions and 17 deletions

View file

@ -67,6 +67,10 @@ namespace global {
inline QString keyboardText;
inline QString keypadText;
}
namespace toast {
inline QString message;
inline bool wifiToast;
}
inline QString systemInfoText;
inline bool forbidOpenSearchDialog;
inline bool isN705;

View file

@ -27,6 +27,7 @@ SOURCES += \
settings.cpp \
settingschooser.cpp \
textwidget.cpp \
toast.cpp \
usbms_splash.cpp \
virtualkeyboard.cpp \
virtualkeypad.cpp \
@ -49,6 +50,7 @@ HEADERS += \
settings.h \
settingschooser.h \
textwidget.h \
toast.h \
usbms_splash.h \
virtualkeyboard.h \
virtualkeypad.h \
@ -70,6 +72,7 @@ FORMS += \
settings.ui \
settingschooser.ui \
textwidget.ui \
toast.ui \
usbms_splash.ui \
virtualkeyboard.ui \
virtualkeypad.ui \

View file

@ -74,8 +74,8 @@ MainWindow::MainWindow(QWidget *parent)
brightnessIconHeight = sH / 24;
homeIconWidth = sW / 18;
homeIconHeight = sW / 18;
wifiIconWidth = sW / 20;
wifiIconHeight = sH / 20;
wifiIconWidth = sW / 20.5;
wifiIconHeight = sH / 20.5;
}
else if(checkconfig_str_val == "n905\n") {
stdIconWidth = sW / 14;
@ -84,8 +84,8 @@ MainWindow::MainWindow(QWidget *parent)
brightnessIconHeight = sH / 26;
homeIconWidth = sW / 20;
homeIconHeight = sW / 20;
wifiIconWidth = sW / 22;
wifiIconHeight = sH / 22;
wifiIconWidth = sW / 22.5;
wifiIconHeight = sH / 22.5;
}
else if(checkconfig_str_val == "n613\n") {
stdIconWidth = sW / 12.5;
@ -94,8 +94,8 @@ MainWindow::MainWindow(QWidget *parent)
brightnessIconHeight = sH / 24.5;
homeIconWidth = sW / 18.5;
homeIconHeight = sW / 18.5;
wifiIconWidth = sW / 20.5;
wifiIconHeight = sH / 20.5;
wifiIconWidth = sW / 21;
wifiIconHeight = sH / 21;
}
else {
stdIconWidth = sW / 14;
@ -104,8 +104,8 @@ MainWindow::MainWindow(QWidget *parent)
brightnessIconHeight = sH / 26;
homeIconWidth = sW / 20;
homeIconHeight = sW / 20;
wifiIconWidth = sW / 22;
wifiIconHeight = sH / 22;
wifiIconWidth = sW / 22.5;
wifiIconHeight = sH / 22.5;
}
// Setting icons up
@ -346,6 +346,7 @@ MainWindow::MainWindow(QWidget *parent)
}
else {
// An USB cable is connected!
setBatteryIcon();
openUsbmsDialog();
}
}
@ -907,3 +908,25 @@ void MainWindow::setWifiIcon() {
ui->wifiBtn->setIconSize(QSize(wifiIconWidth, wifiIconHeight));
}
}
void MainWindow::openWifiDialog() {
global::toast::wifiToast = true;
showToast("Searching for networks");
}
void MainWindow::on_wifiBtn_clicked()
{
openWifiDialog();
}
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)));
toastWindow->show();
}
void MainWindow::hello(int testNumber) {
qDebug() << "Hello" << testNumber;
}

View file

@ -15,6 +15,7 @@
#include "koboxappsdialog.h"
#include "textwidget.h"
#include "virtualkeypad.h"
#include "toast.h"
using namespace std;
@ -53,9 +54,9 @@ public:
void resetWindow(bool resetStackedWidget);
void resetIcons();
void setBatteryIcon();
void updateWifiIcon(int mode);
int testPing();
bool checkWifiState();
void showToast(QString messageToDisplay);
public slots:
@ -71,11 +72,15 @@ private slots:
void on_book4Btn_clicked();
void on_brightnessBtn_clicked();
void openUpdateDialog();
void openWifiDialog();
void setInitialBrightness();
void on_homeBtn_clicked();
void refreshScreen();
void setupSearchDialog();
void setWifiIcon();
void on_wifiBtn_clicked();
void updateWifiIcon(int mode);
void hello(int testNumber);
private:
Ui::MainWindow *ui;
@ -91,6 +96,7 @@ private:
koboxAppsDialog *koboxAppsDialogWindow;
textwidget *textwidgetWindow;
virtualkeypad *keypadWidget;
toast *toastWindow;
};
#endif // MAINWINDOW_H

View file

@ -819,7 +819,7 @@ void reader::on_nextBtn_clicked()
{
if(is_epub != true) {
if(split_total - 1 == 1 or split_total - 1 == 0) {
QMessageBox::critical(this, tr("Invalid argument"), tr("You've reached the end of the document."));
showToast("You've reached the end of the document");
}
else {
split_total = split_total - 1;
@ -834,7 +834,7 @@ void reader::on_nextBtn_clicked()
}
else {
if(mupdf::epubPageNumber + 1 > totalPagesInt) {
QMessageBox::critical(this, tr("Invalid argument"), tr("You've reached the end of the document."));
showToast("You've reached the end of the document");
}
else {
mupdf::epubPageNumber = mupdf::epubPageNumber + 1;
@ -856,7 +856,7 @@ void reader::on_previousBtn_clicked()
if(is_epub != true) {
// Making sure we won't encounter a "List index out of range" error ;)
if(split_total >= split_files_number - 1) {
QMessageBox::critical(this, tr("Invalid argument"), tr("No previous page."));
showToast("No previous page");
}
else {
split_total = split_total + 1;
@ -871,7 +871,7 @@ void reader::on_previousBtn_clicked()
}
else {
if(mupdf::epubPageNumber - 1 <= 0) {
QMessageBox::critical(this, tr("Invalid argument"), tr("No previous page."));
showToast("No previous page");
}
else {
mupdf::epubPageNumber = mupdf::epubPageNumber - 1;
@ -1567,7 +1567,7 @@ void reader::on_gotoBtn_clicked()
void reader::gotoPage(int pageNumber) {
if(is_epub == true) {
if(pageNumber > totalPagesInt or pageNumber < 1) {
QMessageBox::critical(this, tr("Invalid argument"), tr("Request is beyond the page range."));
showToast("Request is beyond page range");
}
else {
mupdf::epubPageNumber = pageNumber;
@ -1581,7 +1581,7 @@ void reader::gotoPage(int pageNumber) {
}
else {
if(split_files_number - pageNumber < 2 or split_files_number - pageNumber > split_files_number - 1) {
QMessageBox::critical(this, tr("Invalid argument"), tr("You've reached the end of the document."));
showToast("You've reached the end of the document");
}
else {
split_total = split_files_number - pageNumber;
@ -1693,3 +1693,10 @@ void reader::setIbarraFont() {
void reader::searchRefreshScreen() {
this->repaint();
}
void reader::showToast(QString messageToDisplay) {
global::toast::message = messageToDisplay;
toastWindow = new toast(this);
toastWindow->setAttribute(Qt::WA_DeleteOnClose);
toastWindow->show();
}

View file

@ -4,6 +4,7 @@
#include "functions.h"
#include "alert.h"
#include "generaldialog.h"
#include "toast.h"
#include <QWidget>
@ -101,6 +102,7 @@ public:
void setBitterFont();
void setCrimsonProFont();
void setIbarraFont();
void showToast(QString messageToDisplay);
private slots:
void on_nextBtn_clicked();
@ -135,6 +137,7 @@ private:
Ui::reader *ui;
alert *alertWindow;
generalDialog *generalDialogWindow;
toast *toastWindow;
};
#endif // READER_H

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 6.3 KiB

63
toast.cpp Normal file
View file

@ -0,0 +1,63 @@
#include "toast.h"
#include "ui_toast.h"
#include "functions.h"
#include <QScreen>
#include <QTimer>
toast::toast(QWidget *parent) :
QDialog(parent),
ui(new Ui::toast)
{
ui->setupUi(this);
ui->messageLabel->setStyleSheet("padding: 35px");
ui->messageLabel->setText(global::toast::message);
this->adjustSize();
centerToast();
if(global::toast::wifiToast == true) {
global::toast::wifiToast = false;
wifiDialogWindow = new wifiDialog(this);
wifiDialogWindow->setAttribute(Qt::WA_DeleteOnClose);
connect(wifiDialogWindow, SIGNAL(wifiNetworksListReady(int)), SLOT(showWifiDialog(int)));
connect(wifiDialogWindow, SIGNAL(destroyed(QObject*)), SLOT(exitSlot()));
}
else {
QTimer::singleShot(5000, this, SLOT(exitSlot()));
}
}
toast::~toast()
{
delete ui;
}
void toast::showWifiDialog(int networksFound) {
if(networksFound == 1) {
emit updateWifiIconSig(2);
this->hide();
wifiDialogWindow->show();
wifiDialogWindow->adjustSize();
wifiDialogWindow->centerDialog();
}
else {
ui->messageLabel->setText("No networks found");
QThread::sleep(5);
toast::close();
}
}
void toast::centerToast() {
// 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 toast::exitSlot() {
toast::close();
}

33
toast.h Normal file
View file

@ -0,0 +1,33 @@
#ifndef TOAST_H
#define TOAST_H
#include <QDialog>
#include "wifidialog.h"
namespace Ui {
class toast;
}
class toast : public QDialog
{
Q_OBJECT
public:
explicit toast(QWidget *parent = nullptr);
~toast();
void centerToast();
private:
Ui::toast *ui;
wifiDialog *wifiDialogWindow;
private slots:
void showWifiDialog(int networksFound);
void exitSlot();
signals:
void updateWifiIconSig(int mode);
};
#endif // TOAST_H

53
toast.ui Normal file
View file

@ -0,0 +1,53 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>toast</class>
<widget class="QDialog" name="toast">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>63</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="leftMargin">
<number>6</number>
</property>
<property name="topMargin">
<number>6</number>
</property>
<property name="rightMargin">
<number>6</number>
</property>
<property name="bottomMargin">
<number>6</number>
</property>
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="messageLabel">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Message</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View file

@ -1,14 +1,92 @@
#include <QTimer>
#include <QStringListModel>
#include <QScreen>
#include <QDesktopWidget>
#include "wifidialog.h"
#include "ui_wifidialog.h"
#include "functions.h"
#include "mainwindow.h"
wifiDialog::wifiDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::wifiDialog)
{
ui->setupUi(this);
wifiListTimer = new QTimer(this);
// Stylesheet, style & misc.
QFile stylesheetFile(":/resources/eink.qss");
stylesheetFile.open(QFile::ReadOnly);
this->setStyleSheet(stylesheetFile.readAll());
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->setStyleSheet("font-size: 9pt");
checkWifiNetworks();
}
wifiDialog::~wifiDialog()
{
delete ui;
}
void wifiDialog::checkWifiNetworks() {
string_writeconfig("/opt/ibxd", "list_wifi_networks\n");
wifiListTimer->setInterval(100);
connect(wifiListTimer, &QTimer::timeout, [&]() {
if(QFile::exists("/run/wifi_networks_list")) {
printWifiNetworks();
wifiListTimer->stop();
}
} );
wifiListTimer->start();
}
void wifiDialog::printWifiNetworks() {
string_checkconfig_ro("/run/wifi_networks_list");
if(checkconfig_str_val == "") {
emit wifiNetworksListReady(0);
wifiDialog::close();
}
else {
QFile wifiNetworksListFile("/run/wifi_networks_list");
wifiNetworksListFile.open(QIODevice::ReadWrite);
QTextStream in (&wifiNetworksListFile);
wifiNetworksList = in.readAll();
wifiNetworksListFile.close();
QFile::remove("/run/wifi_networks_list");
QStringListModel* model = new QStringListModel(this);
QStringList list = wifiNetworksList.split("\n", QString::SkipEmptyParts);
model->setStringList(list);
ui->networksListWidget->setModel(model);
ui->networksListWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);
emit wifiNetworksListReady(1);
}
}
void wifiDialog::centerDialog() {
// Centering dialog
// Get current screen size
QRect rec = QGuiApplication::screenAt(this->pos())->geometry();
// Using minimum size of window
QSize size = this->minimumSize();
// Set top left point
QPoint topLeft = QPoint((rec.width() / 2) - (size.width() / 2), (rec.height() / 2) - (size.height() / 2));
// set window position
setGeometry(QRect(topLeft, size));
}
void wifiDialog::on_cancelBtn_clicked()
{
wifiDialog::close();
}

View file

@ -14,9 +14,19 @@ class wifiDialog : public QDialog
public:
explicit wifiDialog(QWidget *parent = nullptr);
~wifiDialog();
QString wifiNetworksList;
void checkWifiNetworks();
void printWifiNetworks();
void centerDialog();
private:
Ui::wifiDialog *ui;
QTimer * wifiListTimer;
signals:
void wifiNetworksListReady(int networksFound);
private slots:
void on_cancelBtn_clicked();
};
#endif // WIFIDIALOG_H

View file

@ -16,8 +16,79 @@
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="2" column="0">
<widget class="QStackedWidget" name="stackedWidget">
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="page_2">
<layout class="QVBoxLayout" name="verticalLayout_3">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<layout class="QGridLayout" name="gridLayout_4">
<item row="1" column="0">
<widget class="QListView" name="networksListWidget">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QListWidget" name="networksListWidget"/>
<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>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</item>