2021-03-25 05:00:19 -07:00
|
|
|
#include "alert.h"
|
|
|
|
#include "ui_alert.h"
|
2021-04-05 06:50:58 -07:00
|
|
|
#include "functions.h"
|
2021-03-25 05:00:19 -07:00
|
|
|
|
|
|
|
#include <QPixmap>
|
|
|
|
#include <QScreen>
|
|
|
|
#include <QFile>
|
|
|
|
#include <QProcess>
|
|
|
|
|
|
|
|
alert::alert(QWidget *parent) :
|
|
|
|
QWidget(parent),
|
|
|
|
ui(new Ui::alert)
|
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
2022-04-04 21:47:15 -07:00
|
|
|
ui->messageLabel->setFont(QFont("u001"));
|
2021-04-23 05:47:05 -07:00
|
|
|
|
2021-03-25 05:00:19 -07:00
|
|
|
// Getting the screen's size
|
|
|
|
float sW = QGuiApplication::screens()[0]->size().width();
|
|
|
|
float sH = QGuiApplication::screens()[0]->size().height();
|
|
|
|
// Defining what the "Alert" icon size will be
|
|
|
|
float stdIconWidth = sW / 1.7;
|
|
|
|
float stdIconHeight = sH / 1.7;
|
|
|
|
|
|
|
|
// General stylesheet
|
2022-02-12 21:37:48 -08:00
|
|
|
QFile stylesheetFile(":/resources/eink-dark.qss");
|
2021-03-25 05:00:19 -07:00
|
|
|
stylesheetFile.open(QFile::ReadOnly);
|
|
|
|
this->setStyleSheet(stylesheetFile.readAll());
|
|
|
|
stylesheetFile.close();
|
|
|
|
|
2021-04-26 09:36:45 -07:00
|
|
|
// Default icon in case none of the conditions below are met
|
|
|
|
QPixmap pixmap(":/resources/alert.png");
|
|
|
|
QPixmap scaledPixmap = pixmap.scaled(stdIconWidth, stdIconHeight, Qt::KeepAspectRatio);
|
|
|
|
ui->alertIconLabel->setPixmap(scaledPixmap);
|
|
|
|
|
2021-04-06 13:08:03 -07:00
|
|
|
// Checking if the update's signature is untrusted. The signature error will always take precedence over the downgrade one (c.f. update.sh script)
|
2021-04-02 10:42:00 -07:00
|
|
|
if(checkconfig("/external_root/boot/flags/ALERT_SIGN") == true) {
|
2021-04-22 07:10:47 -07:00
|
|
|
QPixmap pixmap(":/resources/alert.png");
|
|
|
|
QPixmap scaledPixmap = pixmap.scaled(stdIconWidth, stdIconHeight, Qt::KeepAspectRatio);
|
|
|
|
ui->alertIconLabel->setPixmap(scaledPixmap);
|
|
|
|
|
2021-04-06 13:08:03 -07:00
|
|
|
signatureError = true;
|
2021-04-02 18:38:52 -07:00
|
|
|
ui->securityLabel->setText("Failed to update InkBox.");
|
2021-04-02 19:56:19 -07:00
|
|
|
ui->messageLabel->setText("The digital signature of the update is untrusted.\nFor security reasons, it cannot be installed.");
|
2021-04-02 10:42:00 -07:00
|
|
|
ui->stackedWidget->setCurrentIndex(1);
|
|
|
|
}
|
2021-04-06 13:08:03 -07:00
|
|
|
if(checkconfig("/external_root/boot/flags/ALERT_DOWNGRADE") == true) {
|
2021-04-22 07:10:47 -07:00
|
|
|
QPixmap pixmap(":/resources/alert.png");
|
|
|
|
QPixmap scaledPixmap = pixmap.scaled(stdIconWidth, stdIconHeight, Qt::KeepAspectRatio);
|
|
|
|
ui->alertIconLabel->setPixmap(scaledPixmap);
|
|
|
|
|
2021-04-06 13:08:03 -07:00
|
|
|
downgradeError = true;
|
|
|
|
ui->securityLabel->setText("Failed to update InkBox.");
|
2021-04-06 18:29:33 -07:00
|
|
|
ui->messageLabel->setText("An error occured during the update process.\nThe update package's version is lower than the actual installed version.");
|
2021-04-06 13:08:03 -07:00
|
|
|
ui->stackedWidget->setCurrentIndex(1);
|
|
|
|
}
|
2021-10-10 12:02:20 -07:00
|
|
|
if(global::encfs::lockdown == true) {
|
|
|
|
ui->stackedWidget->setVisible(false);
|
|
|
|
ui->stackedWidget->deleteLater();
|
|
|
|
QPixmap pixmap(":/resources/alert.png");
|
|
|
|
QPixmap scaledPixmap = pixmap.scaled(stdIconWidth, stdIconHeight, Qt::KeepAspectRatio);
|
|
|
|
ui->alertIconLabel->setPixmap(scaledPixmap);
|
|
|
|
|
|
|
|
ui->warningLabel->setText("Fatal error");
|
|
|
|
ui->securityLabel->setText("Device lockdown");
|
2022-04-04 22:37:04 -07:00
|
|
|
log(global::encfs::lockdownMessage, className);
|
2021-10-10 12:02:20 -07:00
|
|
|
QString message = "Due to multiple incorrect passphrase attempts, this device is locked down until\n" + global::encfs::unlockTime + "\nand won't boot.";
|
|
|
|
ui->messageLabel->setText(message);
|
2022-04-04 22:37:04 -07:00
|
|
|
poweroff(false);
|
|
|
|
QTimer::singleShot(1000, this, SLOT(quit()));
|
2021-10-10 12:02:20 -07:00
|
|
|
}
|
2021-04-22 07:10:47 -07:00
|
|
|
if(global::battery::showCriticalBatteryAlert == true) {
|
2021-04-23 05:47:05 -07:00
|
|
|
global::battery::showCriticalBatteryAlert = false;
|
2021-04-22 10:56:29 -07:00
|
|
|
ui->stackedWidget->setVisible(false);
|
|
|
|
ui->stackedWidget->deleteLater();
|
|
|
|
|
2021-04-22 07:10:47 -07:00
|
|
|
QPixmap pixmap(":/resources/battery_alert.png");
|
|
|
|
QPixmap scaledPixmap = pixmap.scaled(stdIconWidth, stdIconHeight, Qt::KeepAspectRatio);
|
|
|
|
ui->alertIconLabel->setPixmap(scaledPixmap);
|
|
|
|
|
2021-04-22 04:38:54 -07:00
|
|
|
criticalBattery = true;
|
2021-04-22 10:56:29 -07:00
|
|
|
ui->warningLabel->setText("Please charge your eReader.");
|
|
|
|
ui->securityLabel->setText("The battery's charge level is critical.");
|
2021-06-10 04:51:22 -07:00
|
|
|
ui->messageLabel->setText("To prevent damage, your device has been turned off.\nPlease consider charging it.");
|
2022-02-12 20:56:44 -08:00
|
|
|
poweroff(false);
|
2022-04-04 22:37:04 -07:00
|
|
|
QTimer::singleShot(1000, this, SLOT(quit()));
|
2021-04-22 04:38:54 -07:00
|
|
|
}
|
2021-04-02 10:42:00 -07:00
|
|
|
|
2022-04-04 21:47:15 -07:00
|
|
|
ui->warningLabel->setStyleSheet("QLabel { background-color : black; color : white; font-size: 16pt }");
|
2022-03-02 21:40:11 -08:00
|
|
|
ui->messageLabel->setStyleSheet("QLabel { background-color : black; color : white; font-size: 10pt }");
|
2022-04-04 21:47:15 -07:00
|
|
|
ui->securityLabel->setStyleSheet("QLabel { background-color : black; color : white; font-size: 11pt }");
|
2021-03-25 05:00:19 -07:00
|
|
|
ui->continueBtn->setProperty("type", "borderless");
|
|
|
|
ui->resetBtn->setProperty("type", "borderless");
|
|
|
|
ui->continueBtn->setStyleSheet("padding: 20px");
|
|
|
|
ui->resetBtn->setStyleSheet("padding: 20px");
|
2021-04-02 10:42:00 -07:00
|
|
|
ui->continue2Btn->setProperty("type", "borderless");
|
|
|
|
ui->continue2Btn->setStyleSheet("padding: 20px");
|
2021-03-25 05:00:19 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
alert::~alert()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
|
|
|
void alert::on_continueBtn_clicked()
|
|
|
|
{
|
|
|
|
// We continue anyway and re-set the ALERT flag
|
|
|
|
string_writeconfig("/external_root/boot/flags/ALERT", "false");
|
2021-04-02 10:42:00 -07:00
|
|
|
string_writeconfig("/external_root/boot/flags/ALERT_SIGN", "false");
|
2021-06-26 07:09:51 -07:00
|
|
|
updateReset();
|
2021-03-25 05:00:19 -07:00
|
|
|
QProcess process;
|
|
|
|
process.startDetached("inkbox", QStringList());
|
|
|
|
qApp->quit();
|
|
|
|
}
|
|
|
|
|
|
|
|
void alert::on_resetBtn_clicked()
|
|
|
|
{
|
|
|
|
// We set the DO_FACTORY_RESET flag and we restart the Kobo
|
|
|
|
string_writeconfig("/external_root/boot/flags/DO_FACTORY_RESET", "true");
|
|
|
|
string_writeconfig("/external_root/boot/flags/DIAGS_BOOT", "true");
|
2021-05-28 05:36:24 -07:00
|
|
|
QString reboot_prog ("/sbin/reboot");
|
2021-03-25 05:00:19 -07:00
|
|
|
QStringList reboot_args;
|
2021-05-28 05:36:24 -07:00
|
|
|
reboot_args << "no_splash";
|
2021-03-25 05:00:19 -07:00
|
|
|
QProcess *reboot_proc = new QProcess();
|
|
|
|
reboot_proc->start(reboot_prog, reboot_args);
|
|
|
|
reboot_proc->waitForFinished();
|
2021-08-29 12:05:07 -07:00
|
|
|
reboot_proc->deleteLater();
|
2021-03-25 05:00:19 -07:00
|
|
|
}
|
2021-04-02 10:42:00 -07:00
|
|
|
|
|
|
|
void alert::on_continue2Btn_clicked()
|
|
|
|
{
|
|
|
|
// We continue anyway and re-set the ALERT flag
|
|
|
|
string_writeconfig("/external_root/boot/flags/ALERT", "false");
|
2021-06-26 07:09:51 -07:00
|
|
|
updateReset();
|
2021-04-06 13:08:03 -07:00
|
|
|
|
|
|
|
if(signatureError == true) {
|
|
|
|
string_writeconfig("/external_root/boot/flags/ALERT_SIGN", "false");
|
|
|
|
QProcess process;
|
|
|
|
process.startDetached("inkbox", QStringList());
|
|
|
|
qApp->quit();
|
|
|
|
}
|
|
|
|
if(downgradeError == true) {
|
|
|
|
string_writeconfig("/external_root/boot/flags/ALERT_DOWNGRADE", "false");
|
|
|
|
QProcess process;
|
|
|
|
process.startDetached("inkbox", QStringList());
|
|
|
|
qApp->quit();
|
|
|
|
}
|
2021-04-02 10:42:00 -07:00
|
|
|
}
|
2021-06-26 07:09:51 -07:00
|
|
|
|
|
|
|
void alert::updateReset() {
|
|
|
|
string_writeconfig("/mnt/onboard/onboard/.inkbox/can_really_update", "false");
|
|
|
|
string_writeconfig("/mnt/onboard/onboard/.inkbox/can_update", "false");
|
|
|
|
}
|
2022-04-04 22:37:04 -07:00
|
|
|
|
|
|
|
void alert::quit() {
|
|
|
|
qApp->quit();
|
|
|
|
}
|