2021-03-31 05:38:59 -07:00
|
|
|
#include "generaldialog.h"
|
|
|
|
#include "ui_generaldialog.h"
|
2021-04-05 06:50:58 -07:00
|
|
|
#include "functions.h"
|
2021-03-31 05:38:59 -07:00
|
|
|
|
|
|
|
#include <QFile>
|
|
|
|
#include <QDebug>
|
2021-04-01 05:58:37 -07:00
|
|
|
#include <QProcess>
|
2021-04-02 18:06:15 -07:00
|
|
|
#include <QScreen>
|
2021-03-31 05:38:59 -07:00
|
|
|
|
|
|
|
generalDialog::generalDialog(QWidget *parent) :
|
|
|
|
QDialog(parent),
|
|
|
|
ui(new Ui::generalDialog)
|
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
|
|
|
// Preventing outside interaction
|
|
|
|
this->setModal(true);
|
|
|
|
|
|
|
|
// Stylesheet, style & misc.
|
|
|
|
QFile stylesheetFile(":/resources/eink.qss");
|
|
|
|
stylesheetFile.open(QFile::ReadOnly);
|
|
|
|
this->setStyleSheet(stylesheetFile.readAll());
|
|
|
|
stylesheetFile.close();
|
|
|
|
|
|
|
|
ui->okBtn->setProperty("type", "borderless");
|
|
|
|
ui->cancelBtn->setProperty("type", "borderless");
|
2021-04-05 12:35:25 -07:00
|
|
|
ui->acceptBtn->setProperty("type", "borderless");
|
2021-03-31 05:38:59 -07:00
|
|
|
|
|
|
|
ui->okBtn->setStyleSheet("font-size: 9pt; padding: 10px; font-weight: bold; background: lightGrey");
|
|
|
|
ui->cancelBtn->setStyleSheet("font-size: 9pt; padding: 10px; font-weight: bold; background: lightGrey");
|
2021-04-05 12:35:25 -07:00
|
|
|
ui->acceptBtn->setStyleSheet("font-size: 9pt; padding: 10px; font-weight: bold; background: lightGrey");
|
2021-03-31 05:38:59 -07:00
|
|
|
ui->bodyLabel->setStyleSheet("font-size: 9pt");
|
|
|
|
|
|
|
|
if(checkconfig("/inkbox/resetDialog") == true) {
|
2021-04-06 10:40:43 -07:00
|
|
|
if(checkconfig("/opt/inkbox_genuine") == true) {
|
|
|
|
resetDialog = true;
|
|
|
|
ui->okBtn->setText("Proceed");
|
|
|
|
ui->cancelBtn->setText("Go back");
|
|
|
|
ui->bodyLabel->setText("This will erase any books you have on the device. Settings will be reset.");
|
|
|
|
ui->headerLabel->setText("Warning");
|
|
|
|
this->adjustSize();
|
|
|
|
string_writeconfig("/inkbox/resetDialog", "false");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
resetDialog = true;
|
|
|
|
ui->okBtn->setText("Proceed");
|
|
|
|
ui->cancelBtn->setText("Go back");
|
|
|
|
ui->bodyLabel->setText("Settings will be reset.");
|
|
|
|
ui->headerLabel->setText("Warning");
|
|
|
|
this->adjustSize();
|
|
|
|
string_writeconfig("/inkbox/resetDialog", "false");
|
|
|
|
}
|
2021-03-31 05:38:59 -07:00
|
|
|
}
|
2021-04-01 05:58:37 -07:00
|
|
|
if(checkconfig("/inkbox/updateDialog") == true) {
|
|
|
|
updateDialog = true;
|
|
|
|
ui->okBtn->setText("Update");
|
|
|
|
ui->cancelBtn->setText("Not now");
|
|
|
|
ui->bodyLabel->setText("Do you want to update InkBox now?");
|
|
|
|
ui->headerLabel->setText("Update available");
|
|
|
|
this->adjustSize();
|
|
|
|
string_writeconfig("/inkbox/updateDialog", "false");
|
|
|
|
}
|
2021-04-05 12:35:25 -07:00
|
|
|
if(checkconfig("/inkbox/settingsRebootDialog") == true) {
|
|
|
|
settingsRebootDialog = true;
|
|
|
|
ui->stackedWidget->setCurrentIndex(1);
|
|
|
|
ui->bodyLabel->setText("The settings you chose might require a complete reboot of the device for them to work properly.");
|
|
|
|
ui->headerLabel->setText("Information");
|
|
|
|
this->adjustSize();
|
|
|
|
string_writeconfig("/inkbox/settingsRebootDialog", "false");
|
|
|
|
}
|
2021-03-31 05:38:59 -07:00
|
|
|
else {
|
|
|
|
// We shouldn't be there ;)
|
|
|
|
;
|
|
|
|
}
|
2021-04-02 18:06:15 -07:00
|
|
|
|
|
|
|
// Centering dialog
|
|
|
|
QRect screenGeometry = QGuiApplication::screens()[0]->geometry();
|
|
|
|
int x = (screenGeometry.width() - this->width()) / 2;
|
|
|
|
int y = (screenGeometry.height() - this->height()) / 2;
|
|
|
|
this->move(x, y);
|
2021-03-31 05:38:59 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
generalDialog::~generalDialog()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
|
|
|
void generalDialog::on_cancelBtn_clicked()
|
|
|
|
{
|
|
|
|
if(resetDialog == true) {
|
|
|
|
generalDialog::close();
|
|
|
|
}
|
2021-04-01 05:58:37 -07:00
|
|
|
if(updateDialog == true) {
|
|
|
|
string_writeconfig("/tmp/cancelUpdateDialog", "true");
|
|
|
|
generalDialog::close();
|
|
|
|
}
|
2021-03-31 05:38:59 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void generalDialog::on_okBtn_clicked()
|
|
|
|
{
|
|
|
|
if(resetDialog == true) {
|
2021-04-05 12:35:25 -07:00
|
|
|
if(checkconfig("/opt/inkbox_genuine") == true) {
|
|
|
|
// Soft-reset the device
|
|
|
|
// We set a custom boot flag and reboot silently in Diagnostics
|
|
|
|
string_writeconfig("/external_root/boot/flags/DIAGS_BOOT", "true");
|
|
|
|
string_writeconfig("/external_root/boot/flags/DO_SOFT_RESET", "true");
|
|
|
|
QString prog ("reboot");
|
|
|
|
QStringList args;
|
|
|
|
QProcess *proc = new QProcess();
|
|
|
|
proc->start(prog, args);
|
|
|
|
proc->waitForFinished();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Restore default settings, we're not running on InkBox OS
|
|
|
|
QString prog ("sh");
|
|
|
|
QStringList args;
|
|
|
|
args << "reset-config.sh";
|
|
|
|
QProcess *proc = new QProcess();
|
2021-04-06 10:40:43 -07:00
|
|
|
proc->start(prog, args);
|
|
|
|
proc->waitForFinished();
|
|
|
|
|
|
|
|
// Relaunching InkBox
|
|
|
|
QProcess process;
|
|
|
|
process.startDetached("inkbox.sh", QStringList());
|
2021-04-05 12:35:25 -07:00
|
|
|
qApp->quit();
|
|
|
|
}
|
2021-03-31 05:38:59 -07:00
|
|
|
}
|
2021-04-01 05:58:37 -07:00
|
|
|
if(updateDialog == true) {
|
|
|
|
string_writeconfig("/mnt/onboard/onboard/.inkbox/can_really_update", "true");
|
|
|
|
string_writeconfig("/external_root/opt/update/will_update", "true");
|
|
|
|
string_writeconfig("/external_root/boot/flags/WILL_UPDATE", "true");
|
|
|
|
QString prog ("reboot");
|
|
|
|
QStringList args;
|
|
|
|
QProcess *proc = new QProcess();
|
|
|
|
proc->start(prog, args);
|
|
|
|
proc->waitForFinished();
|
|
|
|
}
|
2021-03-31 05:38:59 -07:00
|
|
|
}
|
2021-04-05 12:35:25 -07:00
|
|
|
void generalDialog::on_acceptBtn_clicked()
|
|
|
|
{
|
|
|
|
// We don't have any other option ;p
|
|
|
|
generalDialog::close();
|
|
|
|
|
|
|
|
QProcess process;
|
|
|
|
process.startDetached("inkbox.sh", QStringList());
|
|
|
|
qApp->quit();
|
|
|
|
}
|