diff --git a/generaldialog.cpp b/generaldialog.cpp index acb3bd4..5756d4d 100644 --- a/generaldialog.cpp +++ b/generaldialog.cpp @@ -3,6 +3,7 @@ #include #include +#include generalDialog::generalDialog(QWidget *parent) : QDialog(parent), @@ -35,6 +36,15 @@ generalDialog::generalDialog(QWidget *parent) : this->adjustSize(); string_writeconfig("/inkbox/resetDialog", "false"); } + 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"); + } else { // We shouldn't be there ;) ; @@ -51,6 +61,10 @@ void generalDialog::on_cancelBtn_clicked() if(resetDialog == true) { generalDialog::close(); } + if(updateDialog == true) { + string_writeconfig("/tmp/cancelUpdateDialog", "true"); + generalDialog::close(); + } } void generalDialog::on_okBtn_clicked() @@ -59,4 +73,14 @@ void generalDialog::on_okBtn_clicked() // Reset the device ... some code to come ; } + 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(); + } } diff --git a/generaldialog.h b/generaldialog.h index 2ccfe73..e5b1676 100644 --- a/generaldialog.h +++ b/generaldialog.h @@ -20,6 +20,7 @@ public: explicit generalDialog(QWidget *parent = nullptr); ~generalDialog(); bool resetDialog = false; + bool updateDialog = false; bool checkconfig(QString file) { QFile config(file); config.open(QIODevice::ReadWrite); diff --git a/main.cpp b/main.cpp index 27bf506..5cc1c04 100644 --- a/main.cpp +++ b/main.cpp @@ -15,6 +15,7 @@ #include "mainwindow.h" #include "alert.h" +#include "generaldialog.h" #include #include #include diff --git a/mainwindow.cpp b/mainwindow.cpp index fd212dc..51b24a7 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -418,6 +418,17 @@ MainWindow::MainWindow(QWidget *parent) } } + // Check for an update and ask if the user wants to install it + if(checkconfig("/mnt/onboard/onboard/.inkbox/can_update") == true) { + if(checkconfig("/tmp/cancelUpdateDialog") == false) { + // I'm sorry. + QTimer::singleShot(2000, this, SLOT(openUpdateDialog())); + } + else { + qDebug() << "Not showing update dialog, user dismissed it..."; + } + } + // Check if it's the first boot since an update and confirm that it installed successfully if(checkconfig("/opt/inkbox_genuine") == true) { if(checkconfig("/external_root/opt/update/inkbox_updated") == true) { @@ -439,6 +450,18 @@ MainWindow::~MainWindow() delete ui; } +void MainWindow::openUpdateDialog() { + updateDialog = true; + // We write to a temporary file to show a "Reset" prompt + string_writeconfig("/inkbox/updateDialog", "true"); + + // We show the dialog + generalDialogWindow = new generalDialog(this); + generalDialogWindow->setAttribute(Qt::WA_DeleteOnClose); + generalDialogWindow->show(); + QApplication::processEvents(); +} + void MainWindow::on_settingsBtn_clicked() { settingsWindow = new settings(); diff --git a/mainwindow.h b/mainwindow.h index 6c3409c..7a13e59 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -30,6 +30,8 @@ public: bool existing_recent_books = false; bool reboot_after_update = false; int batt_level_int; + bool updateDialog = false; + int timerTime = 0; QString checkconfig_str_val; QString relative_path; QString batt_level; @@ -47,6 +49,20 @@ public: } config.close(); }; + bool checkconfig_rw(QString file) { + QFile config(file); + config.open(QIODevice::ReadWrite); + QTextStream in (&config); + const QString content = in.readAll(); + string contentstr = content.toStdString(); + if(contentstr.find("true") != std::string::npos) { + return true; + } + else { + return false; + } + config.close(); + }; void writeconfig(string file, string config) { ofstream fhandler; fhandler.open(file); @@ -137,22 +153,15 @@ public slots: private slots: void on_settingsBtn_clicked(); void on_appsBtn_clicked(); - void on_pushButton_clicked(); - void on_searchBtn_clicked(); - void on_quitBtn_clicked(); - void on_book1Btn_clicked(); - void on_book2Btn_clicked(); - void on_book3Btn_clicked(); - void on_book4Btn_clicked(); - void on_brightnessBtn_clicked(); + void openUpdateDialog(); private: Ui::MainWindow *ui; diff --git a/mainwindow.ui b/mainwindow.ui index 94cc4e4..b4ecc72 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -366,7 +366,9 @@ - + + +