diff --git a/brightnessdialog.cpp b/brightnessdialog.cpp index 905c28f..e04e4fe 100644 --- a/brightnessdialog.cpp +++ b/brightnessdialog.cpp @@ -83,7 +83,7 @@ brightnessDialog::~brightnessDialog() void brightnessDialog::on_quitBtn_clicked() { // Reverting back to the old value - pre_set_brightness(oldValue); + brightnessDialog::pre_set_brightness(oldValue); // Just in case ;) brightness_writeconfig(oldValue); @@ -94,7 +94,7 @@ void brightnessDialog::on_quitBtn_clicked() void brightnessDialog::on_horizontalSlider_valueChanged(int value) { - pre_set_brightness(value); + brightnessDialog::pre_set_brightness(value); QString valueStr = QString::number(value); valueStr = valueStr.append("%"); ui->valueLabel->setText(valueStr); diff --git a/functions.h b/functions.h index 9ea500d..6747f14 100644 --- a/functions.h +++ b/functions.h @@ -117,15 +117,6 @@ namespace { return content_int; config.close(); return 0; - }; - int get_brightness() { - QFile brightness("/var/run/brightness"); - brightness.open(QIODevice::ReadOnly); - QString valuestr = brightness.readAll(); - int value = valuestr.toInt(); - brightness.close(); - return value; - return 0; } void set_brightness(int value) { std::ofstream fhandler; @@ -192,6 +183,29 @@ namespace { fhandler << value; fhandler.close(); } + int get_brightness() { + string_checkconfig_ro("/opt/inkbox_device"); + if(checkconfig_str_val == "n613") { + string_checkconfig_ro(".config/03-brightness/config"); + int brightness; + if(checkconfig_str_val == "") { + brightness = 0; + } + else { + brightness = checkconfig_str_val.toInt(); + } + return brightness; + } + else { + QFile brightness("/var/run/brightness"); + brightness.open(QIODevice::ReadOnly); + QString valuestr = brightness.readAll(); + int value = valuestr.toInt(); + brightness.close(); + return value; + } + return 0; + } void get_battery_level() { QFile batt_level_file("/sys/devices/platform/pmic_battery.1/power_supply/mc13892_bat/capacity"); batt_level_file.open(QIODevice::ReadOnly); @@ -379,5 +393,40 @@ namespace { defaultEpubPageWidth = 450; } } + void pre_set_brightness(int brightnessValue) { + string_checkconfig_ro("/opt/inkbox_device"); + + if(checkconfig_str_val == "n705\n" or checkconfig_str_val == "n905\n") { + set_brightness(brightnessValue); + } + else if(checkconfig_str_val == "n613\n") { + set_brightness_ntxio(brightnessValue); + } + else { + set_brightness(brightnessValue); + } + } + void cinematicBrightness(int value, int mode) { + /* mode can be 0 or 1, respectively + * 0: Bring UP brightness + * 1: Bring DOWN brightness + */ + if(mode == 0) { + int brightness = 0; + while(brightness != value) { + brightness = brightness + 1; + pre_set_brightness(brightness); + QThread::msleep(33); + } + } + else { + int brightness = get_brightness(); + while(brightness != 0) { + brightness = brightness - 1; + pre_set_brightness(brightness); + QThread::msleep(33); + } + } + } } #endif // FUNCTIONS_H diff --git a/mainwindow.cpp b/mainwindow.cpp index 4a19b31..19b1412 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -345,7 +345,15 @@ MainWindow::MainWindow(QWidget *parent) // We set the brightness level saved in the config file int brightness_value = brightness_checkconfig(".config/03-brightness/config"); - pre_set_brightness(brightness_value); + if(checkconfig("/tmp/oobe-inkbox_completed") == true) { + // Coming from OOBE setup; not doing that fancy stuff again ;p + QFile::remove("/tmp/oobe-inkbox_completed"); + pre_set_brightness(brightness_value); + } + else { + // Fancy brightness fade-in + cinematicBrightness(brightness_value, 0); + } // Display quote if requested; otherwise, display recent books string_checkconfig(".config/05-quote/config"); @@ -786,17 +794,3 @@ void MainWindow::setBatteryIcon() { } } } - -void MainWindow::pre_set_brightness(int brightnessValue) { - string_checkconfig_ro("/opt/inkbox_device"); - - if(checkconfig_str_val == "n705\n" or checkconfig_str_val == "n905\n") { - set_brightness(brightnessValue); - } - else if(checkconfig_str_val == "n613\n") { - set_brightness_ntxio(brightnessValue); - } - else { - set_brightness(brightnessValue); - } -} diff --git a/mainwindow.h b/mainwindow.h index 13c3ef9..b397add 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -49,7 +49,6 @@ public: void resetWindow(bool resetStackedWidget); void resetIcons(); void setBatteryIcon(); - void pre_set_brightness(); public slots: @@ -66,7 +65,6 @@ private slots: void on_brightnessBtn_clicked(); void openUpdateDialog(); void on_homeBtn_clicked(); - void pre_set_brightness(int brightnessValue); private: Ui::MainWindow *ui; diff --git a/reader.cpp b/reader.cpp index 36ced86..ae53c9d 100644 --- a/reader.cpp +++ b/reader.cpp @@ -1400,17 +1400,3 @@ void reader::on_nightModeBtn_clicked() isNightModeActive = true; } } - -void reader::pre_set_brightness(int brightnessValue) { - string_checkconfig_ro("/opt/inkbox_device"); - - if(checkconfig_str_val == "n705\n" or checkconfig_str_val == "n905\n") { - set_brightness(brightnessValue); - } - else if(checkconfig_str_val == "n613\n") { - set_brightness_ntxio(brightnessValue); - } - else { - set_brightness(brightnessValue); - } -} diff --git a/reader.h b/reader.h index 9b2e6ac..d13d073 100644 --- a/reader.h +++ b/reader.h @@ -91,7 +91,6 @@ public: void setPageStyle(); void alignText(int alignment); void delay(int seconds); - void pre_set_brightness(int brightnessValue); private slots: void on_nextBtn_clicked();