mirror of
https://github.com/Quill-OS/quill.git
synced 2024-12-26 23:57:22 -08:00
Finalized low/critical battery alert warnings
QTimer implementation which triggers them when the battery reaches a certain charging level
This commit is contained in:
parent
917e28ab52
commit
09e14b74cd
10 changed files with 215 additions and 218 deletions
|
@ -12,6 +12,7 @@ alert::alert(QWidget *parent) :
|
||||||
ui(new Ui::alert)
|
ui(new Ui::alert)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
// Getting the screen's size
|
// Getting the screen's size
|
||||||
float sW = QGuiApplication::screens()[0]->size().width();
|
float sW = QGuiApplication::screens()[0]->size().width();
|
||||||
float sH = QGuiApplication::screens()[0]->size().height();
|
float sH = QGuiApplication::screens()[0]->size().height();
|
||||||
|
@ -47,6 +48,7 @@ alert::alert(QWidget *parent) :
|
||||||
ui->stackedWidget->setCurrentIndex(1);
|
ui->stackedWidget->setCurrentIndex(1);
|
||||||
}
|
}
|
||||||
if(global::battery::showCriticalBatteryAlert == true) {
|
if(global::battery::showCriticalBatteryAlert == true) {
|
||||||
|
global::battery::showCriticalBatteryAlert = false;
|
||||||
ui->stackedWidget->setVisible(false);
|
ui->stackedWidget->setVisible(false);
|
||||||
ui->stackedWidget->deleteLater();
|
ui->stackedWidget->deleteLater();
|
||||||
|
|
||||||
|
@ -54,12 +56,11 @@ alert::alert(QWidget *parent) :
|
||||||
QPixmap scaledPixmap = pixmap.scaled(stdIconWidth, stdIconHeight, Qt::KeepAspectRatio);
|
QPixmap scaledPixmap = pixmap.scaled(stdIconWidth, stdIconHeight, Qt::KeepAspectRatio);
|
||||||
ui->alertIconLabel->setPixmap(scaledPixmap);
|
ui->alertIconLabel->setPixmap(scaledPixmap);
|
||||||
|
|
||||||
global::battery::showCriticalBatteryAlert = false;
|
|
||||||
criticalBattery = true;
|
criticalBattery = true;
|
||||||
ui->warningLabel->setText("Please charge your eReader.");
|
ui->warningLabel->setText("Please charge your eReader.");
|
||||||
ui->securityLabel->setText("The battery's charge level is critical.");
|
ui->securityLabel->setText("The battery's charge level is critical.");
|
||||||
ui->messageLabel->setText("To prevent filesystem damage, your device has been turned off.\nPlease consider charging it.");
|
ui->messageLabel->setText("To prevent filesystem damage, your device has been turned off.\nPlease consider charging it.");
|
||||||
poweroff(false);
|
//poweroff(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
ui->warningLabel->setStyleSheet("QLabel { background-color : black; color : white; font-size: 16pt}");
|
ui->warningLabel->setStyleSheet("QLabel { background-color : black; color : white; font-size: 16pt}");
|
||||||
|
|
|
@ -74,7 +74,7 @@ generalDialog::generalDialog(QWidget *parent) :
|
||||||
lowBatteryDialog = true;
|
lowBatteryDialog = true;
|
||||||
ui->stackedWidget->setCurrentIndex(1);
|
ui->stackedWidget->setCurrentIndex(1);
|
||||||
get_battery_level();
|
get_battery_level();
|
||||||
QString message = "The battery's level is critical. Please charge your eReader.\nCurrent level: ";
|
QString message = "The battery's level is low. Please charge your eReader.\nCurrent level: ";
|
||||||
message.append(batt_level);
|
message.append(batt_level);
|
||||||
ui->bodyLabel->setText(message);
|
ui->bodyLabel->setText(message);
|
||||||
ui->headerLabel->setText("Low battery");
|
ui->headerLabel->setText("Low battery");
|
||||||
|
@ -151,9 +151,6 @@ void generalDialog::on_okBtn_clicked()
|
||||||
}
|
}
|
||||||
void generalDialog::on_acceptBtn_clicked()
|
void generalDialog::on_acceptBtn_clicked()
|
||||||
{
|
{
|
||||||
// We don't have any other option ;p
|
|
||||||
generalDialog::close();
|
|
||||||
|
|
||||||
if(lowBatteryDialog == true) {
|
if(lowBatteryDialog == true) {
|
||||||
global::mainwindow::lowBatteryDialog = false;
|
global::mainwindow::lowBatteryDialog = false;
|
||||||
global::battery::batteryAlertLock = false;
|
global::battery::batteryAlertLock = false;
|
||||||
|
@ -165,4 +162,7 @@ void generalDialog::on_acceptBtn_clicked()
|
||||||
process.startDetached("inkbox.sh", QStringList());
|
process.startDetached("inkbox.sh", QStringList());
|
||||||
qApp->quit();
|
qApp->quit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We don't have any other option ;p
|
||||||
|
generalDialog::close();
|
||||||
}
|
}
|
||||||
|
|
3
main.cpp
3
main.cpp
|
@ -18,13 +18,13 @@
|
||||||
#include "generaldialog.h"
|
#include "generaldialog.h"
|
||||||
#include "functions.h"
|
#include "functions.h"
|
||||||
#include "reader.h"
|
#include "reader.h"
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QTextStream>
|
#include <QTextStream>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QRect>
|
#include <QRect>
|
||||||
#include <QScreen>
|
#include <QScreen>
|
||||||
#include <QTimer>
|
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
@ -66,6 +66,7 @@ int main(int argc, char *argv[])
|
||||||
w.setGeometry(QRect(QPoint(0,0), screen->geometry().size()));
|
w.setGeometry(QRect(QPoint(0,0), screen->geometry().size()));
|
||||||
w.show();
|
w.show();
|
||||||
return a.exec();
|
return a.exec();
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
QApplication a(argc, argv);
|
QApplication a(argc, argv);
|
||||||
|
|
|
@ -43,6 +43,12 @@ MainWindow::MainWindow(QWidget *parent)
|
||||||
ui->searchBtn->setText("");
|
ui->searchBtn->setText("");
|
||||||
ui->brightnessBtn->setText("");
|
ui->brightnessBtn->setText("");
|
||||||
|
|
||||||
|
ui->quoteHeadingLabel->setStyleSheet("padding: 50px");
|
||||||
|
|
||||||
|
// Variables
|
||||||
|
global::battery::showLowBatteryDialog = true;
|
||||||
|
global::battery::showCriticalBatteryAlert = true;
|
||||||
|
|
||||||
// Getting the screen's size
|
// Getting the screen's size
|
||||||
float sW = QGuiApplication::screens()[0]->size().width();
|
float sW = QGuiApplication::screens()[0]->size().width();
|
||||||
float sH = QGuiApplication::screens()[0]->size().height();
|
float sH = QGuiApplication::screens()[0]->size().height();
|
||||||
|
@ -248,6 +254,7 @@ MainWindow::MainWindow(QWidget *parent)
|
||||||
// Reading from the config files and tweaking the program according to the options set
|
// Reading from the config files and tweaking the program according to the options set
|
||||||
|
|
||||||
// Safety mesure; /inkbox is a tmpfs
|
// Safety mesure; /inkbox is a tmpfs
|
||||||
|
string_writeconfig("/tmp/skip_opendialog", "true");
|
||||||
global::reader::skipOpenDialog = false;
|
global::reader::skipOpenDialog = false;
|
||||||
|
|
||||||
// Demo setting, changes "Welcome to InkBox" label to "InkBox"
|
// Demo setting, changes "Welcome to InkBox" label to "InkBox"
|
||||||
|
@ -255,7 +262,7 @@ MainWindow::MainWindow(QWidget *parent)
|
||||||
ui->inkboxLabel->setText("InkBox");
|
ui->inkboxLabel->setText("InkBox");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dark mode
|
// Dark mode; write to the Kobo Nightmode FIFO
|
||||||
if(checkconfig(".config/10-dark_mode/config") == true) {
|
if(checkconfig(".config/10-dark_mode/config") == true) {
|
||||||
string_writeconfig("/tmp/invertScreen", "y");
|
string_writeconfig("/tmp/invertScreen", "y");
|
||||||
}
|
}
|
||||||
|
@ -287,6 +294,44 @@ MainWindow::MainWindow(QWidget *parent)
|
||||||
t->start();
|
t->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QTimer *batteryWatchdog = new QTimer(this);
|
||||||
|
batteryWatchdog->setInterval(2000);
|
||||||
|
connect(batteryWatchdog, &QTimer::timeout, [&]() {
|
||||||
|
// Checking if battery level is low
|
||||||
|
if(global::battery::showCriticalBatteryAlert != true) {
|
||||||
|
;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if(isBatteryCritical() == true) {
|
||||||
|
qDebug() << "Warning! Battery is at a critical charge level!";
|
||||||
|
openCriticalBatteryAlertWindow();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(global::battery::showLowBatteryDialog != true) {
|
||||||
|
// Do nothing, since a dialog should already have been displayed and (probably) dismissed
|
||||||
|
;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if(isBatteryLow() == true) {
|
||||||
|
if(global::battery::batteryAlertLock == true) {
|
||||||
|
;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
qDebug() << "Warning! Battery is low!";
|
||||||
|
string_checkconfig_ro("/sys/devices/platform/pmic_battery.1/power_supply/mc13892_bat/status");
|
||||||
|
if(checkconfig_str_val == "Charging\n") {
|
||||||
|
;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
openLowBatteryDialog();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
batteryWatchdog->start();
|
||||||
|
|
||||||
// We set the brightness level saved in the config file
|
// We set the brightness level saved in the config file
|
||||||
int brightness_value = brightness_checkconfig(".config/03-brightness/config");
|
int brightness_value = brightness_checkconfig(".config/03-brightness/config");
|
||||||
set_brightness(brightness_value);
|
set_brightness(brightness_value);
|
||||||
|
@ -425,18 +470,6 @@ MainWindow::MainWindow(QWidget *parent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Checking if battery level is low
|
|
||||||
if(isBatteryLow() == true) {
|
|
||||||
qDebug() << "Warning! Battery is low!";
|
|
||||||
string_checkconfig_ro("/sys/devices/platform/pmic_battery.1/power_supply/mc13892_bat/status");
|
|
||||||
if(checkconfig_str_val == "Charging\n") {
|
|
||||||
;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
QTimer::singleShot(2000, this, SLOT(openLowBatteryDialog()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if it's the first boot since an update and confirm that it installed successfully
|
// Check if it's the first boot since an update and confirm that it installed successfully
|
||||||
if(checkconfig("/opt/inkbox_genuine") == true) {
|
if(checkconfig("/opt/inkbox_genuine") == true) {
|
||||||
if(checkconfig("/external_root/opt/update/inkbox_updated") == true) {
|
if(checkconfig("/external_root/opt/update/inkbox_updated") == true) {
|
||||||
|
@ -472,6 +505,7 @@ void MainWindow::openUpdateDialog() {
|
||||||
|
|
||||||
void MainWindow::openLowBatteryDialog() {
|
void MainWindow::openLowBatteryDialog() {
|
||||||
global::mainwindow::lowBatteryDialog = true;
|
global::mainwindow::lowBatteryDialog = true;
|
||||||
|
global::battery::batteryAlertLock = true;
|
||||||
|
|
||||||
generalDialogWindow = new generalDialog(this);
|
generalDialogWindow = new generalDialog(this);
|
||||||
generalDialogWindow->setAttribute(Qt::WA_DeleteOnClose);
|
generalDialogWindow->setAttribute(Qt::WA_DeleteOnClose);
|
||||||
|
@ -479,6 +513,16 @@ void MainWindow::openLowBatteryDialog() {
|
||||||
QApplication::processEvents();
|
QApplication::processEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::openCriticalBatteryAlertWindow() {
|
||||||
|
global::battery::showCriticalBatteryAlert = true;
|
||||||
|
global::battery::showLowBatteryDialog = false;
|
||||||
|
|
||||||
|
alertWindow = new alert();
|
||||||
|
alertWindow->setAttribute(Qt::WA_DeleteOnClose);
|
||||||
|
alertWindow->setGeometry(QRect(QPoint(0,0), screen()->geometry ().size()));
|
||||||
|
alertWindow->show();
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::on_settingsBtn_clicked()
|
void MainWindow::on_settingsBtn_clicked()
|
||||||
{
|
{
|
||||||
settingsWindow = new settings();
|
settingsWindow = new settings();
|
||||||
|
@ -489,8 +533,10 @@ void MainWindow::on_settingsBtn_clicked()
|
||||||
void MainWindow::on_appsBtn_clicked()
|
void MainWindow::on_appsBtn_clicked()
|
||||||
{
|
{
|
||||||
appsWindow = new apps();
|
appsWindow = new apps();
|
||||||
appsWindow->setAttribute(Qt::WA_DeleteOnClose);
|
//appsWindow->setAttribute(Qt::WA_DeleteOnClose);
|
||||||
appsWindow->showFullScreen();
|
//appsWindow->showFullScreen();
|
||||||
|
ui->stackedWidget->insertWidget(1, appsWindow);
|
||||||
|
ui->stackedWidget->setCurrentIndex(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_pushButton_clicked()
|
void MainWindow::on_pushButton_clicked()
|
||||||
|
@ -502,10 +548,13 @@ void MainWindow::on_pushButton_clicked()
|
||||||
|
|
||||||
void MainWindow::on_searchBtn_clicked()
|
void MainWindow::on_searchBtn_clicked()
|
||||||
{
|
{
|
||||||
/*// Testing
|
global::battery::showCriticalBatteryAlert = true;
|
||||||
generalDialogWindow = new generalDialog();
|
global::battery::showLowBatteryDialog = false;
|
||||||
generalDialogWindow->setAttribute(Qt::WA_DeleteOnClose);
|
|
||||||
generalDialogWindow->show();*/
|
alertWindow = new alert();
|
||||||
|
alertWindow->setAttribute(Qt::WA_DeleteOnClose);
|
||||||
|
alertWindow->setGeometry(QRect(QPoint(0,0), screen()->geometry ().size()));
|
||||||
|
alertWindow->show();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_quitBtn_clicked()
|
void MainWindow::on_quitBtn_clicked()
|
||||||
|
|
|
@ -27,6 +27,10 @@ public:
|
||||||
bool reboot_after_update = false;
|
bool reboot_after_update = false;
|
||||||
int timerTime = 0;
|
int timerTime = 0;
|
||||||
QString relative_path;
|
QString relative_path;
|
||||||
|
|
||||||
|
void openLowBatteryDialog();
|
||||||
|
void openCriticalBatteryAlertWindow();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
@ -41,7 +45,6 @@ private slots:
|
||||||
void on_book4Btn_clicked();
|
void on_book4Btn_clicked();
|
||||||
void on_brightnessBtn_clicked();
|
void on_brightnessBtn_clicked();
|
||||||
void openUpdateDialog();
|
void openUpdateDialog();
|
||||||
void openLowBatteryDialog();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::MainWindow *ui;
|
Ui::MainWindow *ui;
|
||||||
|
|
195
mainwindow.ui
195
mainwindow.ui
|
@ -141,19 +141,6 @@
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
|
||||||
<spacer name="verticalSpacer_6">
|
|
||||||
<property name="orientation">
|
|
||||||
<enum>Qt::Vertical</enum>
|
|
||||||
</property>
|
|
||||||
<property name="sizeHint" stdset="0">
|
|
||||||
<size>
|
|
||||||
<width>20</width>
|
|
||||||
<height>40</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
</spacer>
|
|
||||||
</item>
|
|
||||||
<item>
|
<item>
|
||||||
<widget class="QStackedWidget" name="stackedWidget">
|
<widget class="QStackedWidget" name="stackedWidget">
|
||||||
<property name="currentIndex">
|
<property name="currentIndex">
|
||||||
|
@ -164,35 +151,6 @@
|
||||||
<item>
|
<item>
|
||||||
<layout class="QGridLayout" name="gridLayout_3">
|
<layout class="QGridLayout" name="gridLayout_3">
|
||||||
<item row="2" column="0">
|
<item row="2" column="0">
|
||||||
<spacer name="verticalSpacer_5">
|
|
||||||
<property name="orientation">
|
|
||||||
<enum>Qt::Vertical</enum>
|
|
||||||
</property>
|
|
||||||
<property name="sizeHint" stdset="0">
|
|
||||||
<size>
|
|
||||||
<width>20</width>
|
|
||||||
<height>40</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
</spacer>
|
|
||||||
</item>
|
|
||||||
<item row="1" column="0">
|
|
||||||
<widget class="QLabel" name="quoteHeadingLabel">
|
|
||||||
<property name="font">
|
|
||||||
<font>
|
|
||||||
<weight>75</weight>
|
|
||||||
<bold>true</bold>
|
|
||||||
</font>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
|
||||||
<string>Author's quote</string>
|
|
||||||
</property>
|
|
||||||
<property name="alignment">
|
|
||||||
<set>Qt::AlignCenter</set>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="3" column="0">
|
|
||||||
<widget class="QLabel" name="recentBooksLabel">
|
<widget class="QLabel" name="recentBooksLabel">
|
||||||
<property name="font">
|
<property name="font">
|
||||||
<font>
|
<font>
|
||||||
|
@ -208,69 +166,7 @@
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="0" column="0">
|
|
||||||
<spacer name="verticalSpacer_4">
|
|
||||||
<property name="orientation">
|
|
||||||
<enum>Qt::Vertical</enum>
|
|
||||||
</property>
|
|
||||||
<property name="sizeHint" stdset="0">
|
|
||||||
<size>
|
|
||||||
<width>20</width>
|
|
||||||
<height>40</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
</spacer>
|
|
||||||
</item>
|
|
||||||
<item row="4" column="0">
|
<item row="4" column="0">
|
||||||
<layout class="QGridLayout" name="gridLayout">
|
|
||||||
<property name="bottomMargin">
|
|
||||||
<number>0</number>
|
|
||||||
</property>
|
|
||||||
<item row="0" column="0">
|
|
||||||
<layout class="QGridLayout" name="gridLayout_6">
|
|
||||||
<property name="bottomMargin">
|
|
||||||
<number>0</number>
|
|
||||||
</property>
|
|
||||||
<item row="0" column="0">
|
|
||||||
<widget class="QPushButton" name="book1Btn">
|
|
||||||
<property name="text">
|
|
||||||
<string>Book 1</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="0" column="1">
|
|
||||||
<widget class="QPushButton" name="book2Btn">
|
|
||||||
<property name="text">
|
|
||||||
<string>Book 2</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</item>
|
|
||||||
<item row="1" column="0">
|
|
||||||
<layout class="QGridLayout" name="gridLayout_8">
|
|
||||||
<property name="bottomMargin">
|
|
||||||
<number>0</number>
|
|
||||||
</property>
|
|
||||||
<item row="0" column="0">
|
|
||||||
<widget class="QPushButton" name="book3Btn">
|
|
||||||
<property name="text">
|
|
||||||
<string>Book 3</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="0" column="1">
|
|
||||||
<widget class="QPushButton" name="book4Btn">
|
|
||||||
<property name="text">
|
|
||||||
<string>Book 4</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</item>
|
|
||||||
<item row="5" column="0">
|
|
||||||
<layout class="QGridLayout" name="gridLayout_4">
|
<layout class="QGridLayout" name="gridLayout_4">
|
||||||
<property name="bottomMargin">
|
<property name="bottomMargin">
|
||||||
<number>0</number>
|
<number>0</number>
|
||||||
|
@ -362,6 +258,84 @@
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="1" column="0">
|
||||||
|
<widget class="QLabel" name="quoteHeadingLabel">
|
||||||
|
<property name="font">
|
||||||
|
<font>
|
||||||
|
<weight>75</weight>
|
||||||
|
<bold>true</bold>
|
||||||
|
</font>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Author's quote</string>
|
||||||
|
</property>
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignCenter</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="0">
|
||||||
|
<spacer name="verticalSpacer_4">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Vertical</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>20</width>
|
||||||
|
<height>40</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
<item row="3" column="0">
|
||||||
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
|
<property name="bottomMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<item row="0" column="0">
|
||||||
|
<layout class="QGridLayout" name="gridLayout_6">
|
||||||
|
<property name="bottomMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<item row="0" column="0">
|
||||||
|
<widget class="QPushButton" name="book1Btn">
|
||||||
|
<property name="text">
|
||||||
|
<string>Book 1</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="1">
|
||||||
|
<widget class="QPushButton" name="book2Btn">
|
||||||
|
<property name="text">
|
||||||
|
<string>Book 2</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="0">
|
||||||
|
<layout class="QGridLayout" name="gridLayout_8">
|
||||||
|
<property name="bottomMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<item row="0" column="0">
|
||||||
|
<widget class="QPushButton" name="book3Btn">
|
||||||
|
<property name="text">
|
||||||
|
<string>Book 3</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="1">
|
||||||
|
<widget class="QPushButton" name="book4Btn">
|
||||||
|
<property name="text">
|
||||||
|
<string>Book 4</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
|
@ -371,19 +345,6 @@
|
||||||
</widget>
|
</widget>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
|
||||||
<spacer name="verticalSpacer_3">
|
|
||||||
<property name="orientation">
|
|
||||||
<enum>Qt::Vertical</enum>
|
|
||||||
</property>
|
|
||||||
<property name="sizeHint" stdset="0">
|
|
||||||
<size>
|
|
||||||
<width>20</width>
|
|
||||||
<height>40</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
</spacer>
|
|
||||||
</item>
|
|
||||||
<item>
|
<item>
|
||||||
<widget class="Line" name="line_4">
|
<widget class="Line" name="line_4">
|
||||||
<property name="frameShadow">
|
<property name="frameShadow">
|
||||||
|
|
82
reader.cpp
82
reader.cpp
|
@ -14,6 +14,7 @@
|
||||||
#include <QScreen>
|
#include <QScreen>
|
||||||
#include <QFontDatabase>
|
#include <QFontDatabase>
|
||||||
#include <QDirIterator>
|
#include <QDirIterator>
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
@ -21,6 +22,9 @@ reader::reader(QWidget *parent) :
|
||||||
QWidget(parent),
|
QWidget(parent),
|
||||||
ui(new Ui::reader)
|
ui(new Ui::reader)
|
||||||
{
|
{
|
||||||
|
// Variables
|
||||||
|
global::battery::showLowBatteryDialog = true;
|
||||||
|
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
ui->previousBtn->setProperty("type", "borderless");
|
ui->previousBtn->setProperty("type", "borderless");
|
||||||
ui->nextBtn->setProperty("type", "borderless");
|
ui->nextBtn->setProperty("type", "borderless");
|
||||||
|
@ -223,13 +227,8 @@ reader::reader(QWidget *parent) :
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if(isBatteryCritical() == true) {
|
if(isBatteryLow() == true) {
|
||||||
openCriticalBatteryAlertWindow();
|
openLowBatteryDialog();
|
||||||
}
|
|
||||||
else {
|
|
||||||
if(isBatteryLow() == true) {
|
|
||||||
openLowBatteryDialog();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -253,13 +252,8 @@ reader::reader(QWidget *parent) :
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if(isBatteryCritical() == true) {
|
if(isBatteryLow() == true) {
|
||||||
openCriticalBatteryAlertWindow();
|
openLowBatteryDialog();
|
||||||
}
|
|
||||||
else {
|
|
||||||
if(isBatteryLow() == true) {
|
|
||||||
openLowBatteryDialog();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -306,31 +300,29 @@ reader::reader(QWidget *parent) :
|
||||||
} );
|
} );
|
||||||
select_t->start();
|
select_t->start();
|
||||||
|
|
||||||
|
// We have to get the file's path
|
||||||
|
if(checkconfig("/tmp/suspendBook") == true) {
|
||||||
|
wakeFromSleep = true;
|
||||||
|
// Prevent from opening the Reader framework next time unless the condition is reset
|
||||||
|
string_writeconfig("/tmp/suspendBook", "false");
|
||||||
|
book_file = "/inkbox/book/book.txt";
|
||||||
|
}
|
||||||
if(global::reader::skipOpenDialog == true) {
|
if(global::reader::skipOpenDialog == true) {
|
||||||
// We have to get the file's path
|
if(global::reader::bookNumber == 1) {
|
||||||
if(checkconfig("/tmp/suspendBook") == true) {
|
string_checkconfig(".config/08-recent_books/1");
|
||||||
wakeFromSleep = true;
|
book_file = checkconfig_str_val;
|
||||||
// Prevent from opening the Reader framework next time unless the condition is reset
|
|
||||||
string_writeconfig("/tmp/suspendBook", "false");
|
|
||||||
book_file = "/inkbox/book/book.txt";
|
|
||||||
}
|
}
|
||||||
else {
|
if(global::reader::bookNumber == 2) {
|
||||||
if(global::reader::bookNumber == 1) {
|
string_checkconfig(".config/08-recent_books/2");
|
||||||
string_checkconfig(".config/08-recent_books/1");
|
book_file = checkconfig_str_val;
|
||||||
book_file = checkconfig_str_val;
|
}
|
||||||
}
|
if(global::reader::bookNumber == 3) {
|
||||||
if(global::reader::bookNumber == 2) {
|
string_checkconfig(".config/08-recent_books/3");
|
||||||
string_checkconfig(".config/08-recent_books/2");
|
book_file = checkconfig_str_val;
|
||||||
book_file = checkconfig_str_val;
|
}
|
||||||
}
|
if(global::reader::bookNumber == 4) {
|
||||||
if(global::reader::bookNumber == 3) {
|
string_checkconfig(".config/08-recent_books/4");
|
||||||
string_checkconfig(".config/08-recent_books/3");
|
book_file = checkconfig_str_val;
|
||||||
book_file = checkconfig_str_val;
|
|
||||||
}
|
|
||||||
if(global::reader::bookNumber == 4) {
|
|
||||||
string_checkconfig(".config/08-recent_books/4");
|
|
||||||
book_file = checkconfig_str_val;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -1072,24 +1064,12 @@ void reader::quit_restart() {
|
||||||
qApp->quit();
|
qApp->quit();
|
||||||
}
|
}
|
||||||
|
|
||||||
void reader::batteryWatchdog() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void reader::openLowBatteryDialog() {
|
void reader::openLowBatteryDialog() {
|
||||||
global::battery::batteryAlertLock = true;
|
global::battery::batteryAlertLock = true;
|
||||||
|
global::battery::showLowBatteryDialog = false;
|
||||||
|
global::mainwindow::lowBatteryDialog = true;
|
||||||
|
|
||||||
generalDialogWindow = new generalDialog(this);
|
generalDialogWindow = new generalDialog(this);
|
||||||
generalDialogWindow->setAttribute(Qt::WA_DeleteOnClose);
|
generalDialogWindow->setAttribute(Qt::WA_DeleteOnClose);
|
||||||
generalDialogWindow->show();
|
generalDialogWindow->show();
|
||||||
QApplication::processEvents();
|
|
||||||
}
|
|
||||||
|
|
||||||
void reader::openCriticalBatteryAlertWindow() {
|
|
||||||
global::battery::showCriticalBatteryAlert = true;
|
|
||||||
|
|
||||||
alertWindow = new alert(this);
|
|
||||||
alertWindow->setAttribute(Qt::WA_DeleteOnClose);
|
|
||||||
alertWindow->showFullScreen();
|
|
||||||
QApplication::processEvents();
|
|
||||||
}
|
}
|
||||||
|
|
2
reader.h
2
reader.h
|
@ -67,9 +67,7 @@ public:
|
||||||
void menubar_hide();
|
void menubar_hide();
|
||||||
void wordwidget_show();
|
void wordwidget_show();
|
||||||
void wordwidget_hide();
|
void wordwidget_hide();
|
||||||
void batteryWatchdog();
|
|
||||||
void openLowBatteryDialog();
|
void openLowBatteryDialog();
|
||||||
void openCriticalBatteryAlertWindow();
|
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void on_nextBtn_clicked();
|
void on_nextBtn_clicked();
|
||||||
|
|
|
@ -41,7 +41,7 @@ void savedwords::on_backBtn_clicked()
|
||||||
void savedwords::on_clearBtn_clicked()
|
void savedwords::on_clearBtn_clicked()
|
||||||
{
|
{
|
||||||
// Warning: possible memory leak here. Though, usually, when you press the "Clear" button and all clears up, you don't have to press it again ;)
|
// Warning: possible memory leak here. Though, usually, when you press the "Clear" button and all clears up, you don't have to press it again ;)
|
||||||
save_word_init("");
|
save_word_init();
|
||||||
checkwords();
|
checkwords();
|
||||||
QStringListModel* model = new QStringListModel(this);
|
QStringListModel* model = new QStringListModel(this);
|
||||||
QStringList list = words.split("\n", QString::SkipEmptyParts);
|
QStringList list = words.split("\n", QString::SkipEmptyParts);
|
||||||
|
@ -49,3 +49,25 @@ void savedwords::on_clearBtn_clicked()
|
||||||
ui->wordsList->setModel(model);
|
ui->wordsList->setModel(model);
|
||||||
ui->wordsList->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
ui->wordsList->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void savedwords::checkwords() {
|
||||||
|
QFile words_list(".config/06-words/config");
|
||||||
|
words_list.open(QIODevice::ReadWrite);
|
||||||
|
QTextStream in (&words_list);
|
||||||
|
words = in.readAll();
|
||||||
|
words_list.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
void savedwords::save_word_init() {
|
||||||
|
QFile words(".config/06-words/config");
|
||||||
|
words.open(QIODevice::ReadWrite);
|
||||||
|
QTextStream in (&words);
|
||||||
|
QString words_list = in.readAll();
|
||||||
|
string words_list_str = words_list.toStdString();
|
||||||
|
words.close();
|
||||||
|
|
||||||
|
ofstream fhandler;
|
||||||
|
fhandler.open(".config/06-words/config");
|
||||||
|
fhandler << "";
|
||||||
|
fhandler.close();
|
||||||
|
}
|
||||||
|
|
22
savedwords.h
22
savedwords.h
|
@ -22,26 +22,8 @@ public:
|
||||||
explicit savedwords(QWidget *parent = nullptr);
|
explicit savedwords(QWidget *parent = nullptr);
|
||||||
~savedwords();
|
~savedwords();
|
||||||
QString words;
|
QString words;
|
||||||
void checkwords() {
|
void checkwords();
|
||||||
QFile words_list(".config/06-words/config");
|
void save_word_init();
|
||||||
words_list.open(QIODevice::ReadWrite);
|
|
||||||
QTextStream in (&words_list);
|
|
||||||
words = in.readAll();
|
|
||||||
words_list.close();
|
|
||||||
}
|
|
||||||
void save_word_init(string word) {
|
|
||||||
QFile words(".config/06-words/config");
|
|
||||||
words.open(QIODevice::ReadWrite);
|
|
||||||
QTextStream in (&words);
|
|
||||||
QString words_list = in.readAll();
|
|
||||||
string words_list_str = words_list.toStdString();
|
|
||||||
words.close();
|
|
||||||
|
|
||||||
ofstream fhandler;
|
|
||||||
fhandler.open(".config/06-words/config");
|
|
||||||
fhandler << "";
|
|
||||||
fhandler.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void on_backBtn_clicked();
|
void on_backBtn_clicked();
|
||||||
|
|
Loading…
Reference in a new issue