2021-04-05 06:50:58 -07:00
|
|
|
#ifndef FUNCTIONS_H
|
|
|
|
#define FUNCTIONS_H
|
|
|
|
|
|
|
|
#include <QFile>
|
|
|
|
#include <QString>
|
|
|
|
#include <QTextStream>
|
|
|
|
#include <fstream>
|
|
|
|
#include <QDir>
|
|
|
|
#include <QProcess>
|
|
|
|
#include <regex>
|
2021-06-23 05:16:04 -07:00
|
|
|
#include <QThread>
|
2021-07-14 15:23:54 -07:00
|
|
|
#include <QTimer>
|
2021-12-25 10:50:30 -08:00
|
|
|
#include <QDebug>
|
2021-04-05 06:50:58 -07:00
|
|
|
|
2021-06-25 19:09:42 -07:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
|
2021-04-22 07:10:47 -07:00
|
|
|
// WoW, global variables and namespaces are awesome
|
|
|
|
namespace global {
|
2021-04-22 04:38:54 -07:00
|
|
|
namespace battery {
|
2021-04-22 07:10:47 -07:00
|
|
|
inline bool showLowBatteryDialog;
|
|
|
|
inline bool showCriticalBatteryAlert;
|
|
|
|
inline bool batteryAlertLock;
|
2021-04-22 04:38:54 -07:00
|
|
|
}
|
|
|
|
namespace reader {
|
2021-09-04 20:46:47 -07:00
|
|
|
inline QString bookFile;
|
2021-04-22 07:10:47 -07:00
|
|
|
inline int pageNumber;
|
|
|
|
inline int bookNumber;
|
|
|
|
inline bool skipOpenDialog;
|
2021-04-23 16:22:53 -07:00
|
|
|
inline bool startBatteryWatchdog;
|
2021-06-29 09:26:30 -07:00
|
|
|
inline bool startUsbmsPrompt;
|
2021-06-17 05:34:00 -07:00
|
|
|
inline bool bookIsEpub;
|
2021-08-19 09:55:12 -07:00
|
|
|
inline bool globalReadingSettings;
|
2021-04-22 07:10:47 -07:00
|
|
|
}
|
2021-04-30 20:55:38 -07:00
|
|
|
namespace kobox {
|
|
|
|
inline bool showKoboxSplash;
|
2021-05-01 12:53:52 -07:00
|
|
|
inline bool koboxSettingsRebootDialog;
|
2021-06-14 11:31:49 -07:00
|
|
|
inline bool resetKoboxUserDataBool;
|
|
|
|
inline bool resetKoboxDialog;
|
2021-04-30 20:55:38 -07:00
|
|
|
}
|
2021-04-22 07:10:47 -07:00
|
|
|
namespace mainwindow {
|
2021-04-23 19:23:24 -07:00
|
|
|
namespace tabSwitcher {
|
2021-04-24 06:34:35 -07:00
|
|
|
inline bool repaint;
|
2021-04-23 19:23:24 -07:00
|
|
|
inline bool appsWidgetCreated;
|
|
|
|
inline bool appsWidgetSelected;
|
2021-04-24 09:44:57 -07:00
|
|
|
inline bool settingsChooserWidgetCreated;
|
|
|
|
inline bool settingsChooserWidgetSelected;
|
2021-12-26 05:36:29 -08:00
|
|
|
inline bool libraryWidgetCreated;
|
|
|
|
inline bool libraryWidgetSelected;
|
2021-04-23 19:23:24 -07:00
|
|
|
}
|
2021-04-22 07:10:47 -07:00
|
|
|
inline bool updateDialog;
|
|
|
|
inline bool lowBatteryDialog;
|
2021-05-09 11:07:05 -07:00
|
|
|
}
|
|
|
|
namespace usbms {
|
2021-05-07 22:03:25 -07:00
|
|
|
inline bool usbmsDialog;
|
2021-05-09 11:07:05 -07:00
|
|
|
inline bool showUsbmsDialog;
|
|
|
|
inline bool launchUsbms;
|
2021-05-13 18:40:05 -07:00
|
|
|
inline bool koboxExportExtensions;
|
2021-04-22 04:38:54 -07:00
|
|
|
}
|
2021-05-01 12:53:52 -07:00
|
|
|
namespace settings {
|
|
|
|
inline bool settingsRebootDialog;
|
|
|
|
}
|
2021-06-08 04:49:52 -07:00
|
|
|
namespace text {
|
|
|
|
inline bool textBrowserDialog;
|
|
|
|
inline QString textBrowserContents;
|
|
|
|
}
|
2021-07-05 10:45:35 -07:00
|
|
|
namespace keyboard {
|
|
|
|
inline bool keyboardDialog;
|
|
|
|
inline bool keypadDialog;
|
2021-07-05 19:21:20 -07:00
|
|
|
inline bool searchDialog;
|
2021-10-08 20:37:32 -07:00
|
|
|
inline bool encfsDialog;
|
2021-07-05 21:13:11 -07:00
|
|
|
inline bool vncDialog;
|
2021-07-14 15:23:54 -07:00
|
|
|
inline bool wifiPassphraseDialog;
|
2021-07-05 10:45:35 -07:00
|
|
|
inline QString keyboardText;
|
|
|
|
inline QString keypadText;
|
|
|
|
}
|
2021-07-13 22:24:30 -07:00
|
|
|
namespace toast {
|
|
|
|
inline QString message;
|
|
|
|
inline bool wifiToast;
|
2021-07-14 15:23:54 -07:00
|
|
|
inline bool modalToast;
|
|
|
|
inline bool indefiniteToast;
|
2021-09-05 06:37:07 -07:00
|
|
|
inline int delay;
|
2021-07-13 22:24:30 -07:00
|
|
|
}
|
2021-07-16 13:41:36 -07:00
|
|
|
namespace device {
|
|
|
|
inline bool isWifiAble;
|
|
|
|
}
|
2021-08-19 05:23:18 -07:00
|
|
|
namespace network {
|
|
|
|
inline bool isConnected;
|
|
|
|
}
|
|
|
|
namespace otaUpdate {
|
|
|
|
inline bool isUpdateOta;
|
|
|
|
inline bool downloadOta;
|
|
|
|
}
|
2021-10-08 20:37:32 -07:00
|
|
|
namespace encfs {
|
|
|
|
inline QString passphrase;
|
2021-10-10 12:02:20 -07:00
|
|
|
inline QString unlockTime;
|
|
|
|
inline bool cancelSetup;
|
|
|
|
inline bool cancelUnlock;
|
|
|
|
inline bool lockdown;
|
2021-10-18 05:46:27 -07:00
|
|
|
inline bool enableStorageEncryptionDialog;
|
2021-10-17 19:31:44 -07:00
|
|
|
inline bool disableStorageEncryptionDialog;
|
2021-11-14 18:22:58 -08:00
|
|
|
inline bool errorNoBooksInDropboxDialog;
|
2021-12-31 12:50:59 -08:00
|
|
|
inline bool repackDialog;
|
2021-10-08 20:37:32 -07:00
|
|
|
}
|
2021-12-27 12:04:39 -08:00
|
|
|
namespace library {
|
|
|
|
inline unsigned long bookId;
|
|
|
|
inline bool isLatestBook;
|
|
|
|
inline int latestBookNumber;
|
|
|
|
inline QString bookTitle;
|
|
|
|
inline bool librarySearchDialog;
|
2021-12-27 20:59:28 -08:00
|
|
|
inline bool libraryResults;
|
2021-12-27 12:04:39 -08:00
|
|
|
}
|
2021-06-08 05:03:46 -07:00
|
|
|
inline QString systemInfoText;
|
2021-07-05 19:21:20 -07:00
|
|
|
inline bool forbidOpenSearchDialog;
|
2021-06-26 07:09:51 -07:00
|
|
|
inline bool isN705;
|
|
|
|
inline bool isN905C;
|
|
|
|
inline bool isN613;
|
2021-07-10 22:08:38 -07:00
|
|
|
inline bool isN873;
|
2022-01-27 12:16:48 -08:00
|
|
|
inline bool isN236;
|
2021-09-05 08:47:09 -07:00
|
|
|
inline bool runningInstanceIsReaderOnly;
|
2021-04-22 04:38:54 -07:00
|
|
|
}
|
|
|
|
|
2021-04-05 06:50:58 -07:00
|
|
|
// https://stackoverflow.com/questions/6080853/c-multiple-definition-error-for-global-functions-in-the-header-file/20679534#20679534
|
|
|
|
namespace {
|
|
|
|
QString checkconfig_str_val;
|
2021-05-26 05:33:40 -07:00
|
|
|
QString deviceUID;
|
2021-06-25 19:09:42 -07:00
|
|
|
QString device;
|
2021-04-05 06:50:58 -07:00
|
|
|
QString batt_level;
|
2021-06-14 09:24:20 -07:00
|
|
|
QString kernelVersion;
|
2021-04-05 06:50:58 -07:00
|
|
|
int batt_level_int;
|
2021-06-20 19:57:10 -07:00
|
|
|
int defaultEpubPageWidth;
|
|
|
|
int defaultEpubPageHeight;
|
2021-08-29 12:05:07 -07:00
|
|
|
int defaultPdfPageWidth;
|
|
|
|
int defaultPdfPageHeight;
|
2021-04-05 06:50:58 -07:00
|
|
|
bool checked_box = false;
|
|
|
|
bool checkconfig(QString file) {
|
2021-09-05 06:49:37 -07:00
|
|
|
if(QFile::exists(file)) {
|
|
|
|
QFile config(file);
|
|
|
|
config.open(QIODevice::ReadOnly);
|
|
|
|
QTextStream in (&config);
|
|
|
|
const QString content = in.readAll();
|
|
|
|
std::string contentstr = content.toStdString();
|
|
|
|
if(contentstr.find("true") != std::string::npos) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
config.close();
|
2021-04-05 06:50:58 -07:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
};
|
|
|
|
bool checkconfig_rw(QString file) {
|
2021-09-05 06:49:37 -07:00
|
|
|
if(QFile::exists(file)) {
|
|
|
|
QFile config(file);
|
|
|
|
config.open(QIODevice::ReadWrite);
|
|
|
|
QTextStream in (&config);
|
|
|
|
const QString content = in.readAll();
|
|
|
|
std::string contentstr = content.toStdString();
|
|
|
|
if(contentstr.find("true") != std::string::npos) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
config.close();
|
2021-04-05 06:50:58 -07:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
};
|
2021-06-26 16:29:51 -07:00
|
|
|
void setDefaultWorkDir() {
|
|
|
|
QDir::setCurrent("/mnt/onboard/.adds/inkbox");
|
|
|
|
}
|
2021-04-05 06:50:58 -07:00
|
|
|
int brightness_checkconfig(QString file) {
|
2021-09-05 06:49:37 -07:00
|
|
|
if(QFile::exists(file)) {
|
|
|
|
QFile config(file);
|
|
|
|
config.open(QIODevice::ReadWrite);
|
|
|
|
QTextStream in (&config);
|
|
|
|
const QString content = in.readAll();
|
|
|
|
int content_int = content.toInt();
|
|
|
|
return content_int;
|
|
|
|
config.close();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
2021-04-05 06:50:58 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
void set_brightness(int value) {
|
|
|
|
std::ofstream fhandler;
|
|
|
|
fhandler.open("/var/run/brightness");
|
|
|
|
fhandler << value;
|
|
|
|
fhandler.close();
|
|
|
|
}
|
2021-06-25 19:09:42 -07:00
|
|
|
void set_brightness_ntxio(int value) {
|
|
|
|
// Thanks to Kevin Short for this (GloLight)
|
|
|
|
int light;
|
2021-06-27 10:28:41 -07:00
|
|
|
if((light = open("/dev/ntx_io", O_RDWR)) == -1) {
|
|
|
|
fprintf(stderr, "Error opening ntx_io device\n");
|
2021-06-25 19:09:42 -07:00
|
|
|
}
|
|
|
|
ioctl(light, 241, value);
|
|
|
|
}
|
2021-04-05 06:50:58 -07:00
|
|
|
int int_checkconfig(QString file) {
|
2021-09-05 06:49:37 -07:00
|
|
|
if(QFile::exists(file)) {
|
|
|
|
QFile int_config(file);
|
|
|
|
int_config.open(QIODevice::ReadOnly);
|
|
|
|
QString valuestr = int_config.readAll();
|
|
|
|
int value = valuestr.toInt();
|
|
|
|
int_config.close();
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
2021-04-05 06:50:58 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
int display_quote() {
|
|
|
|
QDir::setCurrent(".config/05-quote");
|
|
|
|
QString quote_prog ("sh");
|
|
|
|
QStringList quote_args;
|
|
|
|
quote_args << "quote.sh";
|
|
|
|
QProcess *quote_proc = new QProcess();
|
|
|
|
quote_proc->start(quote_prog, quote_args);
|
|
|
|
quote_proc->waitForFinished();
|
2021-08-29 12:05:07 -07:00
|
|
|
quote_proc->deleteLater();
|
2021-04-05 06:50:58 -07:00
|
|
|
QDir::setCurrent("/mnt/onboard/.adds/inkbox");
|
|
|
|
|
|
|
|
int quote_value = int_checkconfig(".config/05-quote/quote");
|
|
|
|
return quote_value;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
void string_writeconfig(std::string file, std::string config_option) {
|
|
|
|
std::ofstream fhandler;
|
|
|
|
fhandler.open(file);
|
|
|
|
fhandler << config_option;
|
|
|
|
fhandler.close();
|
|
|
|
}
|
|
|
|
void string_checkconfig(QString file) {
|
2021-09-05 06:49:37 -07:00
|
|
|
if(QFile::exists(file)) {
|
|
|
|
checkconfig_str_val = "";
|
|
|
|
QFile config(file);
|
|
|
|
config.open(QIODevice::ReadWrite);
|
|
|
|
QTextStream in (&config);
|
|
|
|
checkconfig_str_val = in.readAll();
|
|
|
|
config.close();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
checkconfig_str_val = "";
|
|
|
|
}
|
2021-04-05 06:50:58 -07:00
|
|
|
}
|
|
|
|
void string_checkconfig_ro(QString file) {
|
2021-09-05 06:49:37 -07:00
|
|
|
if(QFile::exists(file)) {
|
|
|
|
checkconfig_str_val = "";
|
|
|
|
QFile config(file);
|
|
|
|
config.open(QIODevice::ReadOnly);
|
|
|
|
QTextStream in (&config);
|
|
|
|
checkconfig_str_val = in.readAll();
|
|
|
|
config.close();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
checkconfig_str_val = "";
|
|
|
|
}
|
2021-04-05 06:50:58 -07:00
|
|
|
}
|
2021-12-26 16:08:21 -08:00
|
|
|
QString readFile(QString file) {
|
|
|
|
if(QFile::exists(file)) {
|
|
|
|
QFile fileToRead(file);
|
|
|
|
fileToRead.open(QIODevice::ReadOnly);
|
|
|
|
QTextStream in (&fileToRead);
|
|
|
|
QString content = in.readAll();
|
|
|
|
return content;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
2021-04-05 06:50:58 -07:00
|
|
|
void brightness_writeconfig(int value) {
|
|
|
|
std::ofstream fhandler;
|
|
|
|
fhandler.open(".config/03-brightness/config");
|
|
|
|
fhandler << value;
|
|
|
|
fhandler.close();
|
|
|
|
}
|
2021-07-16 13:41:36 -07:00
|
|
|
void warmth_writeconfig(int value) {
|
|
|
|
std::ofstream fhandler;
|
|
|
|
fhandler.open(".config/03-brightness/config-warmth");
|
|
|
|
fhandler << value;
|
|
|
|
fhandler.close();
|
|
|
|
}
|
2021-06-28 12:26:04 -07:00
|
|
|
int get_brightness() {
|
|
|
|
string_checkconfig_ro("/opt/inkbox_device");
|
2021-06-29 12:28:54 -07:00
|
|
|
if(checkconfig_str_val == "n613\n") {
|
2021-06-28 12:26:04 -07:00
|
|
|
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;
|
|
|
|
}
|
2021-04-05 06:50:58 -07:00
|
|
|
void get_battery_level() {
|
|
|
|
QFile batt_level_file("/sys/devices/platform/pmic_battery.1/power_supply/mc13892_bat/capacity");
|
2021-12-25 07:36:38 -08:00
|
|
|
if(batt_level_file.exists()) {
|
|
|
|
batt_level_file.open(QIODevice::ReadOnly);
|
|
|
|
batt_level = batt_level_file.readAll();
|
|
|
|
batt_level = batt_level.trimmed();
|
|
|
|
batt_level_int = batt_level.toInt();
|
|
|
|
batt_level = batt_level.append("%");
|
|
|
|
batt_level_file.close();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
batt_level_int = 100;
|
|
|
|
batt_level = "100%";
|
|
|
|
}
|
2021-04-05 06:50:58 -07:00
|
|
|
}
|
|
|
|
void writeconfig(std::string file, std::string config) {
|
2021-09-05 06:49:37 -07:00
|
|
|
std::ofstream fhandler;
|
|
|
|
fhandler.open(file);
|
|
|
|
fhandler << config << std::boolalpha << checked_box << std::endl;
|
|
|
|
fhandler.close();
|
2021-04-05 06:50:58 -07:00
|
|
|
}
|
|
|
|
bool checkconfig_match(QString file, std::string pattern) {
|
|
|
|
QFile config(file);
|
|
|
|
config.open(QIODevice::ReadWrite);
|
|
|
|
QTextStream in (&config);
|
|
|
|
const QString content = in.readAll();
|
|
|
|
std::string contentstr = content.toStdString();
|
|
|
|
|
|
|
|
// Thanks to https://stackoverflow.com/questions/22516463/how-do-i-find-a-complete-word-not-part-of-it-in-a-string-in-c
|
|
|
|
std::regex r("\\b" + pattern + "\\b");
|
|
|
|
std::smatch m;
|
|
|
|
|
|
|
|
if(std::regex_search(contentstr, m, r)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
config.close();
|
|
|
|
return 0;
|
|
|
|
};
|
2021-04-22 04:38:54 -07:00
|
|
|
bool isBatteryLow() {
|
|
|
|
// Checks if battery level is under 15% of total capacity.
|
|
|
|
get_battery_level();
|
|
|
|
if(batt_level_int <= 15) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
bool isBatteryCritical() {
|
|
|
|
// Checks if the battery level is critical (i.e. <= 5%)
|
|
|
|
get_battery_level();
|
|
|
|
if(batt_level_int <= 5) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2021-06-27 10:28:41 -07:00
|
|
|
void zeroBrightness() {
|
|
|
|
string_checkconfig_ro("/opt/inkbox_device");
|
|
|
|
if(checkconfig_str_val != "n613\n") {
|
|
|
|
set_brightness(0);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
set_brightness_ntxio(0);
|
|
|
|
}
|
|
|
|
}
|
2021-04-22 04:38:54 -07:00
|
|
|
void poweroff(bool splash) {
|
|
|
|
if(splash == true) {
|
2021-05-28 05:36:24 -07:00
|
|
|
QString prog ("/sbin/poweroff");
|
2021-04-22 04:38:54 -07:00
|
|
|
QStringList args;
|
|
|
|
QProcess *proc = new QProcess();
|
|
|
|
proc->start(prog, args);
|
2021-08-29 12:05:07 -07:00
|
|
|
proc->waitForFinished();
|
|
|
|
proc->deleteLater();
|
2021-04-22 04:38:54 -07:00
|
|
|
}
|
|
|
|
else {
|
2021-05-28 05:36:24 -07:00
|
|
|
QString prog ("/sbin/poweroff");
|
2021-04-22 04:38:54 -07:00
|
|
|
QStringList args;
|
2021-05-28 05:36:24 -07:00
|
|
|
args << "no_splash";
|
2021-04-22 04:38:54 -07:00
|
|
|
QProcess *proc = new QProcess();
|
|
|
|
proc->start(prog, args);
|
2021-08-29 12:05:07 -07:00
|
|
|
proc->waitForFinished();
|
|
|
|
proc->deleteLater();
|
2021-04-22 04:38:54 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
void reboot(bool splash) {
|
|
|
|
if(splash == true) {
|
2021-06-20 10:31:24 -07:00
|
|
|
QString prog ("/sbin/reboot");
|
2021-04-22 04:38:54 -07:00
|
|
|
QStringList args;
|
2021-06-14 11:31:49 -07:00
|
|
|
if(global::kobox::resetKoboxUserDataBool == true) {
|
|
|
|
args << "splash" << "reset_kobox";
|
|
|
|
}
|
2021-04-22 04:38:54 -07:00
|
|
|
QProcess *proc = new QProcess();
|
|
|
|
proc->start(prog, args);
|
2021-08-29 12:05:07 -07:00
|
|
|
proc->waitForFinished();
|
|
|
|
proc->deleteLater();
|
2021-04-22 04:38:54 -07:00
|
|
|
}
|
|
|
|
else {
|
2021-06-20 10:31:24 -07:00
|
|
|
QString prog ("/sbin/reboot");
|
2021-04-22 04:38:54 -07:00
|
|
|
QStringList args;
|
2021-06-14 11:31:49 -07:00
|
|
|
if(global::kobox::resetKoboxUserDataBool == true) {
|
|
|
|
args << "no_splash" << "reset_kobox";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
args << "no_splash";
|
|
|
|
}
|
2021-04-22 04:38:54 -07:00
|
|
|
QProcess *proc = new QProcess();
|
|
|
|
proc->start(prog, args);
|
2021-08-29 12:05:07 -07:00
|
|
|
proc->waitForFinished();
|
|
|
|
proc->deleteLater();
|
2021-04-22 04:38:54 -07:00
|
|
|
}
|
|
|
|
}
|
2021-05-26 05:33:40 -07:00
|
|
|
void getUID() {
|
2021-05-26 05:06:50 -07:00
|
|
|
QString prog ("dd");
|
|
|
|
QStringList args;
|
|
|
|
args << "if=/dev/mmcblk0" << "bs=512" << "skip=1" << "count=1" << "status=none";
|
|
|
|
QProcess *proc = new QProcess();
|
|
|
|
proc->start(prog, args);
|
|
|
|
proc->waitForFinished();
|
|
|
|
|
2021-05-26 05:33:40 -07:00
|
|
|
deviceUID = proc->readAllStandardOutput();
|
|
|
|
deviceUID = deviceUID.left(256);
|
2021-08-29 12:05:07 -07:00
|
|
|
|
|
|
|
proc->deleteLater();
|
2021-05-26 05:06:50 -07:00
|
|
|
}
|
2021-06-14 09:24:20 -07:00
|
|
|
void getKernelVersion() {
|
|
|
|
QString prog ("uname");
|
|
|
|
QStringList args;
|
|
|
|
args << "-r";
|
|
|
|
QProcess *proc = new QProcess();
|
|
|
|
proc->start(prog, args);
|
|
|
|
proc->waitForFinished();
|
|
|
|
|
|
|
|
kernelVersion = proc->readAllStandardOutput();
|
2021-06-23 05:16:04 -07:00
|
|
|
kernelVersion = kernelVersion.trimmed();
|
2021-06-26 16:29:51 -07:00
|
|
|
|
|
|
|
setDefaultWorkDir();
|
|
|
|
QString fifo_prog("sh");
|
|
|
|
QStringList fifo_args;
|
|
|
|
fifo_args << "get_kernel_build_id.sh";
|
|
|
|
QProcess *fifo_proc = new QProcess();
|
|
|
|
fifo_proc->start(fifo_prog, fifo_args);
|
|
|
|
fifo_proc->waitForFinished();
|
2021-08-29 12:05:07 -07:00
|
|
|
fifo_proc->deleteLater();
|
2021-06-23 05:16:04 -07:00
|
|
|
QThread::msleep(100);
|
2021-06-26 16:29:51 -07:00
|
|
|
|
2021-06-23 05:16:04 -07:00
|
|
|
string_checkconfig_ro("/external_root/run/build_id");
|
|
|
|
QString kernelBuildID = checkconfig_str_val.trimmed();
|
|
|
|
kernelVersion.append(", build ");
|
|
|
|
kernelVersion.append(kernelBuildID);
|
2021-06-14 09:24:20 -07:00
|
|
|
}
|
2021-07-20 20:27:32 -07:00
|
|
|
QString getConnectionInformation() {
|
|
|
|
QString getIpProg ("sh");
|
|
|
|
QStringList getIpArgs;
|
|
|
|
getIpArgs << "-c" << "/sbin/ifconfig eth0 | grep 'inet addr' | cut -d: -f2 | awk '{print $1}'";
|
|
|
|
QProcess *getIpProc = new QProcess();
|
|
|
|
getIpProc->start(getIpProg, getIpArgs);
|
|
|
|
getIpProc->waitForFinished();
|
|
|
|
|
|
|
|
QString ipAddress = getIpProc->readAllStandardOutput();
|
2021-08-18 17:11:18 -07:00
|
|
|
if(ipAddress == "") {
|
|
|
|
ipAddress = "Not available";
|
|
|
|
}
|
2021-08-29 12:05:07 -07:00
|
|
|
|
|
|
|
getIpProc->deleteLater();
|
2021-07-20 20:27:32 -07:00
|
|
|
return ipAddress;
|
|
|
|
}
|
2021-06-08 05:03:46 -07:00
|
|
|
void getSystemInfo() {
|
|
|
|
getUID();
|
2021-06-14 09:24:20 -07:00
|
|
|
getKernelVersion();
|
|
|
|
global::systemInfoText = "<b>InkBox OS version ";
|
2021-06-08 05:03:46 -07:00
|
|
|
string_checkconfig_ro("/external_root/opt/isa/version");
|
|
|
|
global::systemInfoText.append(checkconfig_str_val);
|
2021-06-14 09:24:20 -07:00
|
|
|
global::systemInfoText.append("</b>");
|
2021-06-20 14:32:25 -07:00
|
|
|
global::systemInfoText.append("<br><b>Device UID:</b> ");
|
2021-06-08 05:03:46 -07:00
|
|
|
global::systemInfoText.append(deviceUID);
|
2021-06-20 14:32:25 -07:00
|
|
|
global::systemInfoText.append("<br><b>Kernel version:</b> ");
|
2021-06-14 09:24:20 -07:00
|
|
|
global::systemInfoText.append(kernelVersion);
|
2021-06-23 05:16:04 -07:00
|
|
|
global::systemInfoText.append("<br><b>Device:</b> ");
|
|
|
|
string_checkconfig_ro("/opt/inkbox_device");
|
|
|
|
QString device = checkconfig_str_val.trimmed();
|
|
|
|
global::systemInfoText.append(device);
|
2021-07-20 20:27:32 -07:00
|
|
|
QString ipAddress = getConnectionInformation();
|
|
|
|
global::systemInfoText.append("<br><b>IP address: </b>");
|
|
|
|
global::systemInfoText.append(ipAddress);
|
|
|
|
|
2021-06-08 05:03:46 -07:00
|
|
|
}
|
2021-06-14 11:31:49 -07:00
|
|
|
void resetKoboxUserData() {
|
|
|
|
global::kobox::resetKoboxUserDataBool = true;
|
|
|
|
reboot(true);
|
|
|
|
}
|
2021-06-20 10:31:24 -07:00
|
|
|
QString findEpubMetadata(QString book_file, QString metadata) {
|
|
|
|
setDefaultWorkDir();
|
|
|
|
QString prog ("sh");
|
|
|
|
QStringList args;
|
|
|
|
args << "find_epub_metadata.sh" << book_file << metadata;
|
|
|
|
QProcess *proc = new QProcess();
|
|
|
|
proc->start(prog, args);
|
|
|
|
proc->waitForFinished();
|
|
|
|
|
|
|
|
QString returnedMetadata = proc->readAllStandardOutput();
|
|
|
|
return returnedMetadata;
|
|
|
|
}
|
2021-08-29 12:05:07 -07:00
|
|
|
void defineDefaultPageSize(int fileType) {
|
|
|
|
/* fileType can be:
|
|
|
|
* 0: ePUB
|
|
|
|
* 1: PDF
|
|
|
|
*/
|
|
|
|
if(fileType == 0) {
|
|
|
|
string_checkconfig_ro("/opt/inkbox_device");
|
|
|
|
if(checkconfig_str_val == "n705\n") {
|
|
|
|
defaultEpubPageHeight = 365;
|
|
|
|
defaultEpubPageWidth = 365;
|
|
|
|
}
|
|
|
|
if(checkconfig_str_val == "n905\n") {
|
|
|
|
defaultEpubPageHeight = 425;
|
|
|
|
defaultEpubPageWidth = 425;
|
|
|
|
}
|
2022-01-27 12:16:48 -08:00
|
|
|
if(checkconfig_str_val == "n613\n" or checkconfig_str_val == "n236\n" or checkconfig_str_val == "emu\n") {
|
2021-08-29 12:05:07 -07:00
|
|
|
defaultEpubPageHeight = 450;
|
|
|
|
defaultEpubPageWidth = 450;
|
|
|
|
}
|
|
|
|
if(checkconfig_str_val == "n873\n") {
|
|
|
|
defaultEpubPageHeight = 525;
|
|
|
|
defaultEpubPageWidth = 525;
|
|
|
|
}
|
2021-06-26 07:21:07 -07:00
|
|
|
}
|
2021-08-29 12:05:07 -07:00
|
|
|
else if(fileType == 1) {
|
|
|
|
string_checkconfig_ro("/opt/inkbox_device");
|
|
|
|
if(checkconfig_str_val == "n705\n" or checkconfig_str_val == "n905\n") {
|
|
|
|
defaultPdfPageHeight = 750;
|
|
|
|
defaultPdfPageWidth = 550;
|
|
|
|
}
|
2022-01-27 12:16:48 -08:00
|
|
|
else if(checkconfig_str_val == "n613\n" or checkconfig_str_val == "n236\n" or checkconfig_str_val == "emu\n") {
|
2021-08-29 12:05:07 -07:00
|
|
|
defaultPdfPageHeight = 974;
|
|
|
|
defaultPdfPageWidth = 708;
|
|
|
|
}
|
|
|
|
else if(checkconfig_str_val == "n873\n") {
|
|
|
|
defaultPdfPageHeight = 1630;
|
|
|
|
defaultPdfPageWidth = 1214;
|
|
|
|
}
|
2021-07-10 22:08:38 -07:00
|
|
|
}
|
2021-06-20 19:57:10 -07:00
|
|
|
}
|
2021-06-28 12:26:04 -07:00
|
|
|
void pre_set_brightness(int brightnessValue) {
|
|
|
|
string_checkconfig_ro("/opt/inkbox_device");
|
|
|
|
|
2022-01-27 12:16:48 -08:00
|
|
|
if(checkconfig_str_val == "n705\n" or checkconfig_str_val == "n905\n" or checkconfig_str_val == "n873\n" or checkconfig_str_val == "n236\n") {
|
2021-06-28 12:26:04 -07:00
|
|
|
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);
|
2021-06-28 13:13:44 -07:00
|
|
|
QThread::msleep(30);
|
2021-06-28 12:26:04 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
int brightness = get_brightness();
|
|
|
|
while(brightness != 0) {
|
|
|
|
brightness = brightness - 1;
|
|
|
|
pre_set_brightness(brightness);
|
2021-06-28 13:13:44 -07:00
|
|
|
QThread::msleep(30);
|
2021-06-28 12:26:04 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-07-14 15:23:54 -07:00
|
|
|
bool connectToNetwork(QString essid, QString passphrase) {
|
|
|
|
std::string essid_str = essid.toStdString();
|
|
|
|
std::string passphrase_str = passphrase.toStdString();
|
|
|
|
string_writeconfig("/run/wifi_network_essid", essid_str);
|
|
|
|
string_writeconfig("/run/wifi_network_passphrase", passphrase_str);
|
|
|
|
string_writeconfig("/opt/ibxd", "connect_to_wifi_network\n");
|
|
|
|
|
|
|
|
int connectionSuccessful = 0;
|
|
|
|
|
|
|
|
while(connectionSuccessful == 0) {
|
|
|
|
if(QFile::exists("/run/wifi_connected_successfully")) {
|
|
|
|
if(checkconfig("/run/wifi_connected_successfully") == true) {
|
|
|
|
QFile::remove("/run/wifi_connected_successfully");
|
2021-07-14 15:27:39 -07:00
|
|
|
connectionSuccessful = 1;
|
2021-08-19 05:23:18 -07:00
|
|
|
global::network::isConnected = true;
|
2021-09-06 12:14:32 -07:00
|
|
|
setDefaultWorkDir();
|
|
|
|
string_writeconfig(".config/17-wifi_connection_information/essid", essid_str);
|
|
|
|
string_writeconfig(".config/17-wifi_connection_information/passphrase", passphrase_str);
|
2021-07-14 15:23:54 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
QFile::remove("/run/wifi_connected_successfully");
|
2021-07-14 15:27:39 -07:00
|
|
|
connectionSuccessful = 0;
|
2021-08-19 05:23:18 -07:00
|
|
|
global::network::isConnected = false;
|
2021-07-14 15:23:54 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
QThread::msleep(100);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-07-16 13:41:36 -07:00
|
|
|
int get_warmth() {
|
|
|
|
QString sysfsWarmthPath;
|
|
|
|
string_checkconfig_ro("/opt/inkbox_device");
|
|
|
|
if(checkconfig_str_val == "n873\n") {
|
|
|
|
sysfsWarmthPath = "/sys/class/backlight/lm3630a_led/color";
|
|
|
|
}
|
|
|
|
string_checkconfig_ro(sysfsWarmthPath);
|
|
|
|
int warmthValue = checkconfig_str_val.toInt();
|
|
|
|
warmthValue = 10 - warmthValue;
|
|
|
|
return warmthValue;
|
|
|
|
}
|
|
|
|
void set_warmth(int warmthValue) {
|
|
|
|
// Value 0 gives a warmer lighting than value 10
|
|
|
|
warmthValue = 10 - warmthValue;
|
|
|
|
std::string warmthValueStr = std::to_string(warmthValue);
|
|
|
|
std::string sysfsWarmthPath;
|
|
|
|
string_checkconfig_ro("/opt/inkbox_device");
|
|
|
|
if(checkconfig_str_val == "n873\n") {
|
|
|
|
sysfsWarmthPath = "/sys/class/backlight/lm3630a_led/color";
|
|
|
|
}
|
|
|
|
string_writeconfig(sysfsWarmthPath, warmthValueStr);
|
|
|
|
}
|
2021-08-19 05:23:18 -07:00
|
|
|
void installUpdate() {
|
|
|
|
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");
|
|
|
|
reboot(true);
|
|
|
|
}
|
2021-11-14 18:22:58 -08:00
|
|
|
bool getEncFSStatus() {
|
2021-11-14 19:23:09 -08:00
|
|
|
return checkconfig("/external_root/run/encfs_mounted");
|
2021-11-14 18:22:58 -08:00
|
|
|
}
|
2021-04-05 06:50:58 -07:00
|
|
|
}
|
2021-07-16 13:41:36 -07:00
|
|
|
|
2021-04-05 06:50:58 -07:00
|
|
|
#endif // FUNCTIONS_H
|