diff --git a/alert.cpp b/alert.cpp index f995668..ddc0014 100644 --- a/alert.cpp +++ b/alert.cpp @@ -1,5 +1,6 @@ #include "alert.h" #include "ui_alert.h" +#include "functions.h" #include #include diff --git a/alert.h b/alert.h index b299e65..a5ffe3a 100644 --- a/alert.h +++ b/alert.h @@ -2,10 +2,6 @@ #define ALERT_H #include -#include -#include -#include -#include namespace Ui { class alert; @@ -20,32 +16,10 @@ class alert : public QWidget public: explicit alert(QWidget *parent = nullptr); ~alert(); - void string_writeconfig(string file, string config_option) { - ofstream fhandler; - fhandler.open(file); - fhandler << config_option; - fhandler.close(); - } - bool checkconfig(QString file) { - QFile config(file); - config.open(QIODevice::ReadOnly); - 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(); - }; private slots: void on_continueBtn_clicked(); - void on_resetBtn_clicked(); - void on_continue2Btn_clicked(); private: diff --git a/apps.h b/apps.h index f366fbd..5f3f7c9 100644 --- a/apps.h +++ b/apps.h @@ -20,11 +20,8 @@ public: private slots: void on_scribbleLaunchBtn_clicked(); void exitSlot(); - void on_lightmapsLaunchBtn_clicked(); - void on_savedWordsLaunchBtn_clicked(); - void on_calendarLaunchBtn_clicked(); private: diff --git a/brightnessdialog.cpp b/brightnessdialog.cpp index 66ead4e..23f05f6 100644 --- a/brightnessdialog.cpp +++ b/brightnessdialog.cpp @@ -1,5 +1,6 @@ #include "brightnessdialog.h" #include "ui_brightnessdialog.h" +#include "functions.h" #include #include diff --git a/brightnessdialog.h b/brightnessdialog.h index c90e2fa..ba10238 100644 --- a/brightnessdialog.h +++ b/brightnessdialog.h @@ -2,10 +2,6 @@ #define BRIGHTNESSDIALOG_H #include -#include -#include -#include -#include using namespace std; @@ -22,43 +18,12 @@ public: int oldValue; explicit brightnessDialog(QWidget *parent = nullptr); ~brightnessDialog(); - void brightness_writeconfig(int value) { - ofstream fhandler; - fhandler.open(".config/03-brightness/config"); - fhandler << value; - fhandler.close(); - } - void string_checkconfig_ro(QString file) { - QFile config(file); - config.open(QIODevice::ReadOnly); - QTextStream in (&config); - checkconfig_str_val = in.readAll(); - config.close(); - } - int get_brightness() { - QFile brightness("/var/run/brightness"); - brightness.open(QIODevice::ReadOnly); - QString valuestr = brightness.readAll(); - int value = valuestr.toInt(); - brightness.close(); - return value; - } - void set_brightness(int value) { - ofstream fhandler; - fhandler.open("/var/run/brightness"); - fhandler << value; - fhandler.close(); - } private slots: void on_quitBtn_clicked(); - void on_horizontalSlider_valueChanged(int value); - void on_incBtn_clicked(); - void on_decBtn_clicked(); - void on_okBtn_clicked(); private: diff --git a/functions.h b/functions.h new file mode 100644 index 0000000..2230966 --- /dev/null +++ b/functions.h @@ -0,0 +1,158 @@ +#ifndef FUNCTIONS_H +#define FUNCTIONS_H + +#include +#include +#include +#include +#include +#include +#include + +// https://stackoverflow.com/questions/6080853/c-multiple-definition-error-for-global-functions-in-the-header-file/20679534#20679534 +namespace { + QString checkconfig_str_val; + QString batt_level; + int batt_level_int; + bool checked_box = false; + bool checkconfig(QString 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(); + return 0; + }; + bool checkconfig_rw(QString 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(); + return 0; + }; + int brightness_checkconfig(QString 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(); + 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; + fhandler.open("/var/run/brightness"); + fhandler << value; + fhandler.close(); + } + int int_checkconfig(QString file) { + QFile int_config(file); + int_config.open(QIODevice::ReadOnly); + QString valuestr = int_config.readAll(); + int value = valuestr.toInt(); + int_config.close(); + return value; + 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(); + 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) { + QFile config(file); + config.open(QIODevice::ReadWrite); + QTextStream in (&config); + checkconfig_str_val = in.readAll(); + config.close(); + } + void string_checkconfig_ro(QString file) { + QFile config(file); + config.open(QIODevice::ReadOnly); + QTextStream in (&config); + checkconfig_str_val = in.readAll(); + config.close(); + } + void brightness_writeconfig(int value) { + std::ofstream fhandler; + fhandler.open(".config/03-brightness/config"); + fhandler << value; + fhandler.close(); + } + 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); + 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(); + } + void writeconfig(std::string file, std::string config) { + std::ofstream fhandler; + fhandler.open(file); + fhandler << config << std::boolalpha << checked_box << endl; + fhandler.close(); + } + 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; + }; +} +#endif // FUNCTIONS_H diff --git a/generaldialog.cpp b/generaldialog.cpp index b006138..8713cb7 100644 --- a/generaldialog.cpp +++ b/generaldialog.cpp @@ -1,5 +1,6 @@ #include "generaldialog.h" #include "ui_generaldialog.h" +#include "functions.h" #include #include diff --git a/generaldialog.h b/generaldialog.h index e5b1676..8565ce1 100644 --- a/generaldialog.h +++ b/generaldialog.h @@ -2,9 +2,6 @@ #define GENERALDIALOG_H #include -#include -#include -#include using namespace std; @@ -21,26 +18,6 @@ public: ~generalDialog(); bool resetDialog = false; bool updateDialog = false; - bool checkconfig(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 string_writeconfig(string file, string config_option) { - ofstream fhandler; - fhandler.open(file); - fhandler << config_option; - fhandler.close(); - } private slots: void on_cancelBtn_clicked(); diff --git a/inkbox.pro b/inkbox.pro index 06cd7e7..1cc9b7f 100644 --- a/inkbox.pro +++ b/inkbox.pro @@ -4,6 +4,8 @@ greaterThan(QT_MAJOR_VERSION, 4): QT += widgets CONFIG += c++11 +QMAKE_CXXFLAGS += -Wno-unused-function + # You can make your code fail to compile if it uses deprecated APIs. # In order to do so, uncomment the following line. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 @@ -27,6 +29,7 @@ HEADERS += \ apps.h \ brightnessdialog.h \ calendarapp.h \ + functions.h \ generaldialog.h \ mainwindow.h \ quit.h \ diff --git a/main.cpp b/main.cpp index 5cc1c04..f455929 100644 --- a/main.cpp +++ b/main.cpp @@ -16,6 +16,7 @@ #include "mainwindow.h" #include "alert.h" #include "generaldialog.h" +#include "functions.h" #include #include #include @@ -25,14 +26,9 @@ int main(int argc, char *argv[]) { + checkconfig("test"); // Checking if there has been an ALERT flag set up, and if there is, show a big warning - QFile config("/external_root/boot/flags/ALERT"); - config.open(QIODevice::ReadOnly); - QTextStream in (&config); - const QString content = in.readAll(); - string contentstr = content.toStdString(); - config.close(); - if(contentstr.find("true") != std::string::npos) { + if(checkconfig("/external_root/boot/flags/ALERT") == true) { QApplication a(argc, argv); alert w; diff --git a/mainwindow.cpp b/mainwindow.cpp index c7bee6f..ed23915 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -4,6 +4,7 @@ #include "ui_settings.h" #include "apps.h" #include "ui_apps.h" +#include "functions.h" #include #include #include diff --git a/mainwindow.h b/mainwindow.h index 7a13e59..50b7be4 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -10,9 +10,6 @@ #include "usbms_splash.h" #include "brightnessdialog.h" #include "generaldialog.h" -#include -#include -#include using namespace std; QT_BEGIN_NAMESPACE @@ -26,128 +23,11 @@ class MainWindow : public QMainWindow public: MainWindow(QWidget *parent = nullptr); ~MainWindow(); - bool checked_box = false; 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; - bool checkconfig(QString file) { - QFile config(file); - config.open(QIODevice::ReadOnly); - 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(); - }; - 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); - fhandler << config << boolalpha << checked_box << endl; - fhandler.close(); - } - 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); - 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(); - } - int brightness_checkconfig(QString 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(); - }; - int get_brightness() { - QFile brightness("/var/run/brightness"); - brightness.open(QIODevice::ReadOnly); - QString valuestr = brightness.readAll(); - int value = valuestr.toInt(); - brightness.close(); - return value; - } - void set_brightness(int value) { - ofstream fhandler; - fhandler.open("/var/run/brightness"); - fhandler << value; - fhandler.close(); - } - void brightness_writeconfig(int value) { - ofstream fhandler; - fhandler.open(".config/03-brightness/config"); - fhandler << value; - fhandler.close(); - } - int int_checkconfig(QString file) { - QFile int_config(file); - int_config.open(QIODevice::ReadOnly); - QString valuestr = int_config.readAll(); - int value = valuestr.toInt(); - int_config.close(); - return value; - } - void string_checkconfig(QString file) { - QFile config(file); - config.open(QIODevice::ReadWrite); - QTextStream in (&config); - checkconfig_str_val = in.readAll(); - config.close(); - } - void string_checkconfig_ro(QString file) { - QFile config(file); - config.open(QIODevice::ReadOnly); - QTextStream in (&config); - checkconfig_str_val = in.readAll(); - config.close(); - } - void string_writeconfig(string file, string config_option) { - ofstream fhandler; - fhandler.open(file); - fhandler << config_option; - fhandler.close(); - } - 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(); - QDir::setCurrent("/mnt/onboard/.adds/inkbox"); - - int quote_value = int_checkconfig(".config/05-quote/quote"); - return quote_value; - } public slots: private slots: diff --git a/quit.cpp b/quit.cpp index 0b7a6eb..7f6fd94 100644 --- a/quit.cpp +++ b/quit.cpp @@ -1,5 +1,6 @@ #include "quit.h" #include "ui_quit.h" +#include "functions.h" #include #include #include diff --git a/quit.h b/quit.h index 5a083bc..6582b01 100644 --- a/quit.h +++ b/quit.h @@ -2,8 +2,6 @@ #define QUIT_H #include -#include -#include using namespace std; @@ -18,22 +16,12 @@ class quit : public QWidget public: explicit quit(QWidget *parent = nullptr); ~quit(); - void string_writeconfig(string file, string config_option) { - ofstream fhandler; - fhandler.open(file); - fhandler << config_option; - fhandler.close(); - } private slots: void on_pushButton_clicked(); - void on_pushButton_2_clicked(); - void on_pushButton_4_clicked(); - void on_backBtn_clicked(); - void on_pushButton_3_clicked(); private: diff --git a/reader.cpp b/reader.cpp index 68a010a..f8694a7 100644 --- a/reader.cpp +++ b/reader.cpp @@ -1,5 +1,6 @@ #include "reader.h" #include "ui_reader.h" +#include "functions.h" #include #include #include @@ -11,6 +12,7 @@ #include #include #include +#include using namespace std; diff --git a/reader.h b/reader.h index 06bfef6..07c8233 100644 --- a/reader.h +++ b/reader.h @@ -1,6 +1,8 @@ #ifndef READER_H #define READER_H +#include "functions.h" + #include #include #include @@ -8,12 +10,6 @@ #include #include #include -#include -#include -#include -#include -#include -#include using namespace std; @@ -30,7 +26,6 @@ public: int split_files_number; int page_number; int dictionary_position = 1; - int batt_level_int; int pagesTurned = 0; // -1 : Never refresh | 0 : Refresh every page | 1 : Refresh every 1 page. And so on... @@ -50,10 +45,7 @@ public: QString book_4; QString ittext; QString book_file; - QString batt_level; bool batt_status; - QString percent = "%"; - QString checkconfig_str_val; QString selected_text; QString word; QString words; // Saved words @@ -67,20 +59,6 @@ public: QList content; explicit reader(QWidget *parent = nullptr); ~reader(); - bool checkconfig(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(); - }; int setup_book(QString book, int i, bool run_parser) { // Parse ebook QString mount_prog ("sh"); @@ -163,29 +141,6 @@ public: QDir::setCurrent("/mnt/onboard/.adds/inkbox"); } } - int get_brightness() { - QFile brightness("/var/run/brightness"); - brightness.open(QIODevice::ReadOnly); - QString valuestr = brightness.readAll(); - int value = valuestr.toInt(); - brightness.close(); - return value; - } - int int_checkconfig(QString file) { - QFile int_config(file); - int_config.open(QIODevice::ReadOnly); - QString valuestr = int_config.readAll(); - int value = valuestr.toInt(); - int_config.close(); - return value; - } - void string_checkconfig_ro(QString file) { - QFile config(file); - config.open(QIODevice::ReadOnly); - QTextStream in (&config); - checkconfig_str_val = in.readAll(); - config.close(); - } void checkwords() { QFile words_list(".config/06-words/config"); words_list.open(QIODevice::ReadWrite); @@ -193,44 +148,6 @@ public: words = in.readAll(); words_list.close(); } - void set_brightness(int value) { - ofstream fhandler; - fhandler.open("/var/run/brightness"); - fhandler << value; - fhandler.close(); - } - void brightness_writeconfig(int value) { - ofstream fhandler; - fhandler.open(".config/03-brightness/config"); - fhandler << value; - fhandler.close(); - } - void string_checkconfig(QString file) { - QFile config(file); - config.open(QIODevice::ReadWrite); - QTextStream in (&config); - checkconfig_str_val = in.readAll(); - config.close(); - } - bool checkconfig_match(QString file, string pattern) { - QFile config(file); - config.open(QIODevice::ReadWrite); - QTextStream in (&config); - const QString content = in.readAll(); - 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(); - }; bool epub_file_match(QString file) { QString fileExt = file.right(4); @@ -241,21 +158,6 @@ public: return false; } }; - void string_writeconfig(string file, string config_option) { - ofstream fhandler; - fhandler.open(file); - fhandler << config_option; - fhandler.close(); - } - 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); - 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(); - } void dictionary_lookup(string word, QString first_letter, int position) { ofstream fhandler; fhandler.open("/inkbox/dictionary/word"); diff --git a/settings.cpp b/settings.cpp index 61c6038..fc366c8 100644 --- a/settings.cpp +++ b/settings.cpp @@ -2,6 +2,7 @@ #include "ui_settings.h" #include "mainwindow.h" #include "ui_mainwindow.h" +#include "functions.h" #include #include #include diff --git a/settings.h b/settings.h index a409f67..fec7230 100644 --- a/settings.h +++ b/settings.h @@ -2,9 +2,6 @@ #define SETTINGS_H #include -#include -#include -#include #include #include "generaldialog.h" @@ -21,53 +18,11 @@ class settings : public QWidget public: int settings_page = 1; - bool checked_box = false; bool launch_sh = false; bool not_user_change = true; - QString checkconfig_str_val; explicit settings(QWidget *parent = nullptr); ~settings(); - bool checkconfig(QString file) { - QFile config(file); - config.open(QIODevice::ReadOnly); - 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); - fhandler << config << boolalpha << checked_box << endl; - fhandler.close(); - } - void string_writeconfig(string file, string config_option) { - ofstream fhandler; - fhandler.open(file); - fhandler << config_option; - fhandler.close(); - } - void string_checkconfig(QString file) { - QFile config(file); - config.open(QIODevice::ReadWrite); - QTextStream in (&config); - checkconfig_str_val = in.readAll(); - config.close(); - } - void string_checkconfig_ro(QString file) { - QFile config(file); - config.open(QIODevice::ReadOnly); - QTextStream in (&config); - checkconfig_str_val = in.readAll(); - config.close(); - } private slots: void exitSlot(); @@ -75,33 +30,19 @@ private slots: void on_aboutBtn_clicked(); void on_okBtn_clicked(); void on_clockCheckBox_toggled(bool checked); - void on_quoteCheckBox_toggled(bool checked); - void on_requestLeaseBtn_clicked(); - void on_usbmsBtn_clicked(); - void on_previousBtn_clicked(); - void on_nextBtn_clicked(); - void on_wordsNumber_valueChanged(int arg1); - void on_updateBtn_clicked(); - void on_darkModeCheckBox_toggled(bool checked); - void on_uiScalingSlider_valueChanged(int value); - void on_menuBarCheckBox_toggled(bool checked); - void on_comboBox_currentIndexChanged(const QString &arg1); - void on_resetBtn_clicked(); - void on_setPasscodeBtn_clicked(); - void on_enableLockscreenCheckBox_toggled(bool checked); private: diff --git a/usbms_splash.h b/usbms_splash.h index a8bceb4..4dfa6f1 100644 --- a/usbms_splash.h +++ b/usbms_splash.h @@ -2,8 +2,6 @@ #define USBMS_SPLASH_H #include -#include -#include namespace Ui { class usbms_splash;