From dc864f6d4e61ba98fa086252e2c8b723a4940a2e Mon Sep 17 00:00:00 2001 From: Nicolas Mailloux Date: Sun, 29 Aug 2021 15:05:07 -0400 Subject: [PATCH] PDF support! --- alert.cpp | 1 + dictionarywidget.cpp | 1 + functions.h | 69 ++- generaldialog.cpp | 1 + mainwindow.cpp | 3 + otamanager.cpp | 2 +- reader.cpp | 338 ++++++++++--- reader.h | 44 +- reader.ui | 1148 ++++++++++++++++++++++-------------------- settings.cpp | 11 +- usbms_splash.cpp | 6 + 11 files changed, 962 insertions(+), 662 deletions(-) diff --git a/alert.cpp b/alert.cpp index 1b1f825..c217101 100644 --- a/alert.cpp +++ b/alert.cpp @@ -106,6 +106,7 @@ void alert::on_resetBtn_clicked() QProcess *reboot_proc = new QProcess(); reboot_proc->start(reboot_prog, reboot_args); reboot_proc->waitForFinished(); + reboot_proc->deleteLater(); } void alert::on_continue2Btn_clicked() diff --git a/dictionarywidget.cpp b/dictionarywidget.cpp index 82b8b1e..67d8dc0 100644 --- a/dictionarywidget.cpp +++ b/dictionarywidget.cpp @@ -72,6 +72,7 @@ void dictionaryWidget::dictionaryLookup(std::string word, QString first_letter, QProcess *lookup_proc = new QProcess(); lookup_proc->start(lookup_prog, lookup_args); lookup_proc->waitForFinished(); + lookup_proc->deleteLater(); QFile definition_file("/inkbox/dictionary/definition"); definition_file.open(QIODevice::ReadWrite); diff --git a/functions.h b/functions.h index 94d4f0f..aa35c45 100644 --- a/functions.h +++ b/functions.h @@ -104,6 +104,8 @@ namespace { int batt_level_int; int defaultEpubPageWidth; int defaultEpubPageHeight; + int defaultPdfPageWidth; + int defaultPdfPageHeight; bool checked_box = false; bool checkconfig(QString file) { QFile config(file); @@ -179,6 +181,7 @@ namespace { QProcess *quote_proc = new QProcess(); quote_proc->start(quote_prog, quote_args); quote_proc->waitForFinished(); + quote_proc->deleteLater(); QDir::setCurrent("/mnt/onboard/.adds/inkbox"); int quote_value = int_checkconfig(".config/05-quote/quote"); @@ -314,6 +317,8 @@ namespace { QStringList args; QProcess *proc = new QProcess(); proc->start(prog, args); + proc->waitForFinished(); + proc->deleteLater(); } else { QString prog ("/sbin/poweroff"); @@ -321,6 +326,8 @@ namespace { args << "no_splash"; QProcess *proc = new QProcess(); proc->start(prog, args); + proc->waitForFinished(); + proc->deleteLater(); } } void reboot(bool splash) { @@ -332,6 +339,8 @@ namespace { } QProcess *proc = new QProcess(); proc->start(prog, args); + proc->waitForFinished(); + proc->deleteLater(); } else { QString prog ("/sbin/reboot"); @@ -344,6 +353,8 @@ namespace { } QProcess *proc = new QProcess(); proc->start(prog, args); + proc->waitForFinished(); + proc->deleteLater(); } } void getUID() { @@ -356,6 +367,8 @@ namespace { deviceUID = proc->readAllStandardOutput(); deviceUID = deviceUID.left(256); + + proc->deleteLater(); } void getKernelVersion() { QString prog ("uname"); @@ -375,6 +388,7 @@ namespace { QProcess *fifo_proc = new QProcess(); fifo_proc->start(fifo_prog, fifo_args); fifo_proc->waitForFinished(); + fifo_proc->deleteLater(); QThread::msleep(100); string_checkconfig_ro("/external_root/run/build_id"); @@ -394,6 +408,8 @@ namespace { if(ipAddress == "") { ipAddress = "Not available"; } + + getIpProc->deleteLater(); return ipAddress; } void getSystemInfo() { @@ -432,23 +448,44 @@ namespace { QString returnedMetadata = proc->readAllStandardOutput(); return returnedMetadata; } - void defineDefaultPageSize() { - string_checkconfig_ro("/opt/inkbox_device"); - if(checkconfig_str_val == "n705\n") { - defaultEpubPageWidth = 365; - defaultEpubPageHeight = 365; + 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; + } + if(checkconfig_str_val == "n613\n") { + defaultEpubPageHeight = 450; + defaultEpubPageWidth = 450; + } + if(checkconfig_str_val == "n873\n") { + defaultEpubPageHeight = 525; + defaultEpubPageWidth = 525; + } } - if(checkconfig_str_val == "n905\n") { - defaultEpubPageHeight = 425; - defaultEpubPageWidth = 425; - } - if(checkconfig_str_val == "n613\n") { - defaultEpubPageHeight = 450; - defaultEpubPageWidth = 450; - } - if(checkconfig_str_val == "n873\n") { - defaultEpubPageHeight = 525; - defaultEpubPageWidth = 525; + 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; + } + else if(checkconfig_str_val == "n613\n") { + defaultPdfPageHeight = 974; + defaultPdfPageWidth = 708; + } + else if(checkconfig_str_val == "n873\n") { + defaultPdfPageHeight = 1630; + defaultPdfPageWidth = 1214; + } } } void pre_set_brightness(int brightnessValue) { diff --git a/generaldialog.cpp b/generaldialog.cpp index 9debefb..918fa9d 100644 --- a/generaldialog.cpp +++ b/generaldialog.cpp @@ -192,6 +192,7 @@ void generalDialog::on_okBtn_clicked() QProcess *proc = new QProcess(); proc->start(prog, args); proc->waitForFinished(); + proc->deleteLater(); // Relaunching InkBox QProcess process; diff --git a/mainwindow.cpp b/mainwindow.cpp index 134f89c..6ccae4d 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -207,6 +207,7 @@ MainWindow::MainWindow(QWidget *parent) QProcess *rootfs_internal_proc = new QProcess(); rootfs_internal_proc->start(rootfs_internal_prog, rootfs_internal_args); rootfs_internal_proc->waitForFinished(); + rootfs_internal_proc->deleteLater(); // Second script QString rootfs_prog ("chroot"); @@ -217,6 +218,7 @@ MainWindow::MainWindow(QWidget *parent) QProcess *rootfs_proc = new QProcess(); rootfs_proc->start(rootfs_prog, rootfs_args); rootfs_proc->waitForFinished(); + rootfs_proc->deleteLater(); // Removing update directory contents QDir dir("/mnt/onboard/onboard/.inkbox"); @@ -532,6 +534,7 @@ MainWindow::MainWindow(QWidget *parent) QProcess *proc = new QProcess(); proc->start(prog, args); proc->waitForFinished(); + proc->deleteLater(); QFile::remove("/mnt/onboard/onboard/.inkbox/DEVKEY"); QFile::remove("/mnt/onboard/onboard/.inkbox/DEVKEY.dgst"); diff --git a/otamanager.cpp b/otamanager.cpp index fbc3969..4934d93 100644 --- a/otamanager.cpp +++ b/otamanager.cpp @@ -37,7 +37,7 @@ otaManager::otaManager(QWidget *parent) : string_writeconfig("/opt/ibxd", "ota_update_download\n"); QTimer * otaDownloadTimer = new QTimer(this); otaDownloadTimer->setInterval(100); - connect(otaDownloadTimer, &QTimer::timeout, [&]() { + connect(otaDownloadTimer, &QTimer::timeout, [&]() { if(QFile::exists("/run/can_install_ota_update") == true) { if(checkconfig("/run/can_install_ota_update") == true) { emit downloadedOtaUpdate(true); diff --git a/reader.cpp b/reader.cpp index 133b89a..45f2b4d 100644 --- a/reader.cpp +++ b/reader.cpp @@ -16,6 +16,7 @@ #include #include #include +#include using namespace std; @@ -23,6 +24,9 @@ reader::reader(QWidget *parent) : QWidget(parent), ui(new Ui::reader) { + // Elements + graphicsScene = new QGraphicsScene(this); + // Variables global::battery::showLowBatteryDialog = true; global::battery::showCriticalBatteryAlert = true; @@ -248,11 +252,12 @@ reader::reader(QWidget *parent) : ui->gotoBtn->setStyleSheet("font-size: 9pt; padding: 9px; font-weight: bold; background: lightGrey"); ui->pageNumberLabel->setFont(QFont("Source Serif Pro")); - // Hiding the menubar + definition widget + brightness widget + // Hiding the menubar + definition widget + brightness widget + buttons bar widget ui->hideOptionsBtn->hide(); ui->menuWidget->setVisible(false); ui->brightnessWidget->setVisible(false); ui->menuBarWidget->setVisible(false); + ui->buttonsBarWidget->setVisible(false); ui->wordWidget->setVisible(false); if(checkconfig(".config/11-menubar/sticky") == true) { ui->menuWidget->setVisible(true); @@ -263,6 +268,9 @@ reader::reader(QWidget *parent) : ui->statusBarWidget->setVisible(false); } ui->pageWidget->hide(); + if(pdf_file_match(book_file) == true) { + ui->line_4->setLineWidth(2); + } // Topbar widget / book info ui->topbarStackedWidget->setVisible(true); @@ -454,8 +462,15 @@ reader::reader(QWidget *parent) : // Wheeee! if(is_epub == true) { + ui->graphicsView->hide(); + ui->graphicsView->deleteLater(); ui->text->setText(epubPageContent); } + else if(is_pdf == true) { + ui->text->hide(); + ui->text->deleteLater(); + setupPng(); + } else { ui->text->setText(ittext); } @@ -643,6 +658,9 @@ reader::reader(QWidget *parent) : if(is_epub == true) { getTotalEpubPagesNumber(); } + else if(is_pdf == true) { + getTotalPdfPagesNumber(); + } setupPageWidget(); // Reading settings auto-save timer @@ -661,13 +679,14 @@ reader::~reader() int reader::setup_book(QString book, int i, bool run_parser) { // Parse ebook - if(remount != false) { + if(remount == true) { QString mount_prog ("sh"); QStringList mount_args; mount_args << "split.sh"; - QProcess *mount_proc = new QProcess(); + QProcess * mount_proc = new QProcess(); mount_proc->start(mount_prog, mount_args); mount_proc->waitForFinished(); + mount_proc->deleteLater(); remount = false; } else { @@ -675,12 +694,13 @@ int reader::setup_book(QString book, int i, bool run_parser) { QString mount_prog ("sh"); QStringList mount_args; mount_args << "split.sh"; - QProcess *mount_proc = new QProcess(); + QProcess * mount_proc = new QProcess(); mount_proc->start(mount_prog, mount_args); mount_proc->waitForFinished(); + mount_proc->deleteLater(); } - if(filematch_ran != true) { + if(filematch_ran == false) { if(epub_file_match(book) == true) { QFile::remove("/run/book.epub"); QFile::copy(book, "/run/book.epub"); @@ -688,16 +708,30 @@ int reader::setup_book(QString book, int i, bool run_parser) { // Parsing ePUBs with `mutool' QString epubProg ("sh"); QStringList epubArgs; - convertMuPdfVars(); - epubArgs << "/mnt/onboard/.adds/inkbox/epub.sh" << mupdf::fontSize_qstr << mupdf::width_qstr << mupdf::height_qstr << mupdf::epubPageNumber_qstr; - QProcess *epubProc = new QProcess(); + convertMuPdfVars(0); + epubArgs << "/mnt/onboard/.adds/inkbox/epub.sh" << mupdf::epub::fontSize_qstr << mupdf::epub::width_qstr << mupdf::epub::height_qstr << mupdf::epub::epubPageNumber_qstr; + QProcess * epubProc = new QProcess(); epubProc->start(epubProg, epubArgs); epubProc->waitForFinished(); + epubProc->deleteLater(); filematch_ran = true; is_epub = true; - } - else { + } + else if(pdf_file_match(book) == true) { + QString pdfProg("/usr/local/bin/mutool"); + QStringList pdfArgs; + convertMuPdfVars(1); + pdfArgs << "convert" << "-F" << "png" << "-O" << "width=" + mupdf::pdf::width_qstr + ",height=" + mupdf::pdf::height_qstr << "-o" << "/run/page.png" << book_file << mupdf::pdf::pdfPageNumber_qstr; + QProcess * pdfProc = new QProcess(); + pdfProc->start(pdfProg, pdfArgs); + pdfProc->waitForFinished(); + pdfProc->deleteLater(); + + filematch_ran = true; + is_pdf = true; + } + else { // This is likely not an ePUB. // Copying book specified in the function call QFile::copy(book, "/inkbox/book/book.txt"); @@ -719,14 +753,35 @@ int reader::setup_book(QString book, int i, bool run_parser) { // Parsing file if(is_epub == true) { if(run_parser == true) { - if(filematch_ran != false) { + if(filematch_ran == true) { QString epubProg ("sh"); QStringList epubArgs; - convertMuPdfVars(); - epubArgs << "/mnt/onboard/.adds/inkbox/epub.sh" << mupdf::fontSize_qstr << mupdf::width_qstr << mupdf::height_qstr << mupdf::epubPageNumber_qstr; - QProcess *epubProc = new QProcess(); + convertMuPdfVars(0); + epubArgs << "/mnt/onboard/.adds/inkbox/epub.sh" << mupdf::epub::fontSize_qstr << mupdf::epub::width_qstr << mupdf::epub::height_qstr << mupdf::epub::epubPageNumber_qstr; + QProcess * epubProc = new QProcess(); epubProc->start(epubProg, epubArgs); epubProc->waitForFinished(); + epubProc->deleteLater(); + } + else { + ; + } + } + else { + ; + } + } + else if(is_pdf == true) { + if(run_parser == true) { + if(filematch_ran == true) { + QString pdfProg("/usr/local/bin/mutool"); + QStringList pdfArgs; + convertMuPdfVars(1); + pdfArgs << "convert" << "-F" << "png" << "-O" << "width=" + mupdf::pdf::width_qstr + ",height=" + mupdf::pdf::height_qstr << "-o" << "/run/page.png" << book_file << mupdf::pdf::pdfPageNumber_qstr; + QProcess * pdfProc = new QProcess(); + pdfProc->start(pdfProg, pdfArgs); + pdfProc->waitForFinished(); + pdfProc->deleteLater(); } else { ; @@ -740,13 +795,14 @@ int reader::setup_book(QString book, int i, bool run_parser) { QString parse_prog ("python3"); QStringList parse_args; parse_args << "split-txt.py" << checkconfig_str_val; - QProcess *parse_proc = new QProcess(); + QProcess * parse_proc = new QProcess(); parse_proc->start(parse_prog, parse_args); parse_proc->waitForFinished(); + parse_proc->deleteLater(); } // Reading files - if(is_epub != true) { + if(is_epub == false) { if(run_parser == true) { QDirIterator it("/inkbox/book/split"); while (it.hasNext()) { @@ -805,9 +861,10 @@ void reader::dictionary_lookup(string word, QString first_letter, int position) QStringList lookup_args; QString position_str = QString::number(position); lookup_args << "../scripts/lookup.sh" << position_str; - QProcess *lookup_proc = new QProcess(); + QProcess * lookup_proc = new QProcess(); lookup_proc->start(lookup_prog, lookup_args); lookup_proc->waitForFinished(); + lookup_proc->deleteLater(); QFile definition_file("/inkbox/dictionary/definition"); definition_file.open(QIODevice::ReadWrite); @@ -849,7 +906,7 @@ void reader::save_word(string word, bool remove) { void reader::on_nextBtn_clicked() { - if(is_epub != true) { + if(is_epub == false and is_pdf == false) { if(split_total - 1 == 1 or split_total - 1 == 0) { showToast("You've reached the end of the document"); } @@ -862,30 +919,44 @@ void reader::on_nextBtn_clicked() pagesTurned = pagesTurned + 1; writeconfig_pagenumber(false); + alignText(textAlignment); } } - else { - if(mupdf::epubPageNumber + 1 > totalPagesInt) { + else if(is_epub == true) { + if(mupdf::epub::epubPageNumber + 1 > totalPagesInt) { showToast("You've reached the end of the document"); } else { - mupdf::epubPageNumber = mupdf::epubPageNumber + 1; - setup_book(book_file, mupdf::epubPageNumber, true); + mupdf::epub::epubPageNumber = mupdf::epub::epubPageNumber + 1; + setup_book(book_file, mupdf::epub::epubPageNumber, true); ui->text->setText(""); ui->text->setText(epubPageContent); + pagesTurned = pagesTurned + 1; + writeconfig_pagenumber(false); + alignText(textAlignment); + } + } + else if(is_pdf == true) { + if(mupdf::pdf::pdfPageNumber + 1 > totalPagesInt) { + showToast("You've reached the end of the document"); + } + else { + mupdf::pdf::pdfPageNumber = mupdf::pdf::pdfPageNumber + 1; + setup_book(book_file, mupdf::pdf::pdfPageNumber, true); + setupPng(); + pagesTurned = pagesTurned + 1; writeconfig_pagenumber(false); } } - alignText(textAlignment); setupPageWidget(); refreshScreen(); } void reader::on_previousBtn_clicked() { - if(is_epub != true) { + if(is_epub == false and is_pdf == false) { // Making sure we won't encounter a "List index out of range" error ;) if(split_total >= split_files_number - 1) { showToast("No previous page"); @@ -899,24 +970,39 @@ void reader::on_previousBtn_clicked() // We always increment pagesTurned regardless whether we press the Previous or Next button pagesTurned = pagesTurned + 1; writeconfig_pagenumber(false); + alignText(textAlignment); } } - else { - if(mupdf::epubPageNumber - 1 <= 0) { + else if (is_pdf == true) { + if(mupdf::pdf::pdfPageNumber - 1 <= 0) { showToast("No previous page"); } else { - mupdf::epubPageNumber = mupdf::epubPageNumber - 1; - setup_book(book_file, mupdf::epubPageNumber, true); - ui->text->setText(""); - ui->text->setText(epubPageContent); + mupdf::pdf::pdfPageNumber = mupdf::pdf::pdfPageNumber - 1; + setup_book(book_file, mupdf::pdf::pdfPageNumber, true); + setupPng(); // We always increment pagesTurned regardless whether we press the Previous or Next button pagesTurned = pagesTurned + 1; writeconfig_pagenumber(false); } } - alignText(textAlignment); + else { + if(mupdf::epub::epubPageNumber - 1 <= 0) { + showToast("No previous page"); + } + else { + mupdf::epub::epubPageNumber = mupdf::epub::epubPageNumber - 1; + setup_book(book_file, mupdf::epub::epubPageNumber, true); + ui->text->setText(""); + ui->text->setText(epubPageContent); + + // We always increment pagesTurned regardless whether we press the Previous or Next button + pagesTurned = pagesTurned + 1; + writeconfig_pagenumber(false); + alignText(textAlignment); + } + } setupPageWidget(); refreshScreen(); } @@ -1194,7 +1280,10 @@ void reader::menubar_show() { ui->hideOptionsBtn->show(); ui->optionsBtn->hide(); ui->menuWidget->setVisible(true); - ui->menuBarWidget->setVisible(true); + if(is_pdf == false) { + ui->menuBarWidget->setVisible(true); + } + ui->buttonsBarWidget->setVisible(true); ui->statusBarWidget->setVisible(true); ui->pageWidget->setVisible(true); @@ -1220,7 +1309,10 @@ void reader::menubar_hide() { } ui->hideOptionsBtn->hide(); ui->optionsBtn->show(); - ui->menuBarWidget->setVisible(false); + if(is_pdf == false) { + ui->menuBarWidget->setVisible(false); + } + ui->buttonsBarWidget->setVisible(false); ui->pageWidget->setVisible(false); if(checkconfig(".config/11-menubar/sticky") == true) { ui->statusBarWidget->setVisible(true); @@ -1400,7 +1492,7 @@ void reader::writeconfig_pagenumber(bool persistent) { } } else { - std::string epubPageNumber_str = std::to_string(mupdf::epubPageNumber); + std::string epubPageNumber_str = std::to_string(mupdf::epub::epubPageNumber); string_writeconfig("/tmp/inkboxPageNumber", epubPageNumber_str); if(persistent == true) { epubPageNumber_str.append("\n"); @@ -1442,52 +1534,85 @@ void reader::openCriticalBatteryAlertWindow() { alertWindow->show(); } -void reader::convertMuPdfVars() { - setPageStyle(); - mupdf::fontSize = 12; - mupdf::fontSize_qstr = QString::number(mupdf::fontSize); - mupdf::width_qstr = QString::number(mupdf::width); - mupdf::height_qstr = QString::number(mupdf::height); - if(global::reader::globalReadingSettings == false) { - if(goToSavedPageDone == false) { - string_checkconfig_ro(".config/A-page_number/config"); - mupdf::epubPageNumber = checkconfig_str_val.toInt(); - goToSavedPageDone = true; +void reader::convertMuPdfVars(int fileType) { + /* fileType can be: + * 0: ePUB + * 1: PDF + */ + if(fileType == 0) { + setPageStyle(0); + mupdf::epub::fontSize = 12; + mupdf::epub::fontSize_qstr = QString::number(mupdf::epub::fontSize); + mupdf::epub::width_qstr = QString::number(mupdf::epub::width); + mupdf::epub::height_qstr = QString::number(mupdf::epub::height); + if(global::reader::globalReadingSettings == false) { + if(goToSavedPageDone == false) { + string_checkconfig_ro(".config/A-page_number/config"); + mupdf::epub::epubPageNumber = checkconfig_str_val.toInt(); + goToSavedPageDone = true; + } } + if(mupdf::epub::epubPageNumber <= 0) { + mupdf::epub::epubPageNumber = 1; + } + mupdf::epub::epubPageNumber_qstr = QString::number(mupdf::epub::epubPageNumber); } - if(mupdf::epubPageNumber <= 0) { - mupdf::epubPageNumber = 1; + else if(fileType == 1) { + setPageStyle(1); + mupdf::pdf::width = defaultPdfPageWidth; + mupdf::pdf::height = defaultPdfPageHeight; + mupdf::pdf::width_qstr = QString::number(mupdf::pdf::width); + mupdf::pdf::height_qstr = QString::number(mupdf::pdf::height); + if(global::reader::globalReadingSettings == false) { + if(goToSavedPageDone == false) { + string_checkconfig_ro(".config/A-page_number/config"); + mupdf::pdf::pdfPageNumber = checkconfig_str_val.toInt(); + goToSavedPageDone = true; + } + } + if(mupdf::pdf::pdfPageNumber <= 0) { + mupdf::pdf::pdfPageNumber = 1; + } + mupdf::pdf::pdfPageNumber_qstr = QString::number(mupdf::pdf::pdfPageNumber); } - mupdf::epubPageNumber_qstr = QString::number(mupdf::epubPageNumber); } -void reader::setPageStyle() { - // General page size - defineDefaultPageSize(); +void reader::setPageStyle(int fileType) { + /* fileType can be: + * 0: ePUB + * 1: PDF + */ + if(fileType == 0) { + // General page size + defineDefaultPageSize(0); - string_checkconfig_ro(".config/13-epub_page_size/width"); - if(checkconfig_str_val != "") { - ; - } - else { - std::string pageWidth = std::to_string(defaultEpubPageWidth); - string_writeconfig(".config/13-epub_page_size/width", pageWidth); - string_writeconfig(".config/13-epub_page_size/set", "true"); string_checkconfig_ro(".config/13-epub_page_size/width"); - } - mupdf::width = checkconfig_str_val.toInt(); + if(checkconfig_str_val != "") { + ; + } + else { + std::string pageWidth = std::to_string(defaultEpubPageWidth); + string_writeconfig(".config/13-epub_page_size/width", pageWidth); + string_writeconfig(".config/13-epub_page_size/set", "true"); + string_checkconfig_ro(".config/13-epub_page_size/width"); + } + mupdf::epub::width = checkconfig_str_val.toInt(); - string_checkconfig_ro(".config/13-epub_page_size/height"); - if(checkconfig_str_val != "") { - ; - } - else { - std::string pageHeight = std::to_string(defaultEpubPageHeight); - string_writeconfig(".config/13-epub_page_size/height", pageHeight); - string_writeconfig(".config/13-epub_page_size/set", "true"); string_checkconfig_ro(".config/13-epub_page_size/height"); + if(checkconfig_str_val != "") { + ; + } + else { + std::string pageHeight = std::to_string(defaultEpubPageHeight); + string_writeconfig(".config/13-epub_page_size/height", pageHeight); + string_writeconfig(".config/13-epub_page_size/set", "true"); + string_checkconfig_ro(".config/13-epub_page_size/height"); + } + mupdf::epub::height = checkconfig_str_val.toInt(); + } + else if(fileType == 1) { + defineDefaultPageSize(1); } - mupdf::height = checkconfig_str_val.toInt(); } void reader::delay(int seconds) { @@ -1566,7 +1691,17 @@ QString reader::setPageNumberLabelContent() { if(is_epub == true) { QString pageNumber; QString totalPages; - pageNumberInt = mupdf::epubPageNumber; + pageNumberInt = mupdf::epub::epubPageNumber; + pageNumber = QString::number(pageNumberInt); + totalPages = QString::number(totalPagesInt); + content.append(pageNumber); + content.append(" of "); + content.append(totalPages); + } + else if(is_pdf == true) { + QString pageNumber; + QString totalPages; + pageNumberInt = mupdf::pdf::pdfPageNumber; pageNumber = QString::number(pageNumberInt); totalPages = QString::number(totalPagesInt); content.append(pageNumber); @@ -1598,11 +1733,12 @@ void reader::setupPageWidget() { void reader::getTotalEpubPagesNumber() { QString epubProg ("sh"); QStringList epubArgs; - convertMuPdfVars(); - epubArgs << "/mnt/onboard/.adds/inkbox/epub.sh" << mupdf::fontSize_qstr << mupdf::width_qstr << mupdf::height_qstr << mupdf::epubPageNumber_qstr << "get_pages_number"; + convertMuPdfVars(0); + epubArgs << "/mnt/onboard/.adds/inkbox/epub.sh" << mupdf::epub::fontSize_qstr << mupdf::epub::width_qstr << mupdf::epub::height_qstr << mupdf::epub::epubPageNumber_qstr << "get_pages_number"; QProcess *epubProc = new QProcess(); epubProc->start(epubProg, epubArgs); epubProc->waitForFinished(); + epubProc->deleteLater(); string_checkconfig_ro("/run/epub_total_pages_number"); totalPagesInt = checkconfig_str_val.toInt(); @@ -1623,11 +1759,25 @@ void reader::gotoPage(int pageNumber) { showToast("Request is beyond page range"); } else { - mupdf::epubPageNumber = pageNumber; - setup_book(book_file, mupdf::epubPageNumber, true); + mupdf::epub::epubPageNumber = pageNumber; + setup_book(book_file, mupdf::epub::epubPageNumber, true); ui->text->setText(""); ui->text->setText(epubPageContent); + pagesTurned = 0; + writeconfig_pagenumber(false); + alignText(textAlignment); + } + } + else if(is_pdf == true) { + if(pageNumber > totalPagesInt or pageNumber < 1) { + showToast("Request is beyond page range"); + } + else { + mupdf::pdf::pdfPageNumber = pageNumber; + setup_book(book_file, mupdf::pdf::pdfPageNumber, true); + setupPng(); + pagesTurned = 0; writeconfig_pagenumber(false); } @@ -1645,9 +1795,9 @@ void reader::gotoPage(int pageNumber) { pagesTurned = 0; writeconfig_pagenumber(false); + alignText(textAlignment); } } - alignText(textAlignment); setupPageWidget(); refreshScreen(); } @@ -1763,3 +1913,39 @@ void reader::setupLocalSettingsEnvironment() { QDir pageNumberDir; pageNumberDir.mkpath(pageNumberDirPath); } + +void reader::setupPng() { + // Note: Output file is supposed to be '/run/page.png', but somehow mutool puts it in '/run/page1.png' + // QGraphicsScene * graphicsScene = new QGraphicsScene(); + QPixmap pixmap("/run/page1.png"); + graphicsScene->addPixmap(pixmap); + ui->graphicsView->items().clear(); + ui->graphicsView->setScene(graphicsScene); +} + +bool reader::pdf_file_match(QString file) { + QString fileExt = file.right(3); + + if(fileExt == "pdf" or fileExt == "PDF") { + string_writeconfig("/inkbox/bookIsPdf", "true"); + return true; + } + else { + string_writeconfig("/inkbox/bookIsPdf", "false"); + return false; + } +} + +void reader::getTotalPdfPagesNumber() { + QString epubProg ("sh"); + QStringList epubArgs; + convertMuPdfVars(0); + epubArgs << "/mnt/onboard/.adds/inkbox/pdf_get_total_pages_number.sh" << book_file; + QProcess * epubProc = new QProcess(); + epubProc->start(epubProg, epubArgs); + epubProc->waitForFinished(); + epubProc->deleteLater(); + + string_checkconfig_ro("/run/pdf_total_pages_number"); + totalPagesInt = checkconfig_str_val.toInt(); +} diff --git a/reader.h b/reader.h index f0cf6d5..33e039b 100644 --- a/reader.h +++ b/reader.h @@ -7,19 +7,30 @@ #include "toast.h" #include +#include using namespace std; // ePUB scaling namespace mupdf { - inline int fontSize; - inline int width; - inline int height; - inline int epubPageNumber; - inline QString fontSize_qstr; - inline QString width_qstr; - inline QString height_qstr; - inline QString epubPageNumber_qstr; + namespace epub { + inline int fontSize; + inline int width; + inline int height; + inline int epubPageNumber; + inline QString fontSize_qstr; + inline QString width_qstr; + inline QString height_qstr; + inline QString epubPageNumber_qstr; + } + namespace pdf { + inline int width; + inline int height; + inline int pdfPageNumber; + inline QString width_qstr; + inline QString height_qstr; + inline QString pdfPageNumber_qstr; + } } namespace Ui { @@ -48,6 +59,7 @@ public: bool menubar_shown = false; bool nextdefinition_lock = false; bool is_epub = false; + bool is_pdf = false; bool parser_ran = false; bool filematch_ran = false; bool neverRefresh = false; @@ -91,19 +103,21 @@ public: void wordwidget_hide(); void openLowBatteryDialog(); void openCriticalBatteryAlertWindow(); - void convertMuPdfVars(); + void convertMuPdfVars(int fileType); void refreshScreen(); - void setPageStyle(); + void setPageStyle(int fileType); void alignText(int alignment); void delay(int seconds); void openUsbmsDialog(); QString setPageNumberLabelContent(); void setupPageWidget(); void getTotalEpubPagesNumber(); + void getTotalPdfPagesNumber(); void setBitterFont(); void setCrimsonProFont(); void setIbarraFont(); void showToast(QString messageToDisplay); + bool pdf_file_match(QString file); private slots: void on_nextBtn_clicked(); @@ -135,12 +149,14 @@ private slots: void setupSearchDialog(); void saveReadingSettings(); void setupLocalSettingsEnvironment(); + void setupPng(); private: - Ui::reader *ui; - alert *alertWindow; - generalDialog *generalDialogWindow; - toast *toastWindow; + Ui::reader * ui; + alert * alertWindow; + generalDialog * generalDialogWindow; + toast * toastWindow; + QGraphicsScene * graphicsScene; }; #endif // READER_H diff --git a/reader.ui b/reader.ui index 1da26cf..2a4d457 100644 --- a/reader.ui +++ b/reader.ui @@ -6,8 +6,8 @@ 0 0 - 549 - 750 + 630 + 851 @@ -16,7 +16,396 @@ - + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + QFrame::Plain + + + 8 + + + Qt::Horizontal + + + + + + + 0 + + + 6 + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Save + + + + + + + Close + + + + + + + + 75 + true + + + + Word search + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + 0 + + + + + 0 + + + + + QFrame::Plain + + + 2 + + + Qt::Vertical + + + + + + + + Source Serif Pro + + + + Definition + + + Qt::AlignJustify|Qt::AlignVCenter + + + true + + + + + + + + Inter + 75 + true + + + + Word + + + Qt::AlignCenter + + + true + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + 0 + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Previous + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Status + + + + + + + Next + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + QFrame::Plain + + + 8 + + + Qt::Horizontal + + + + + + + + + + + + QFrame::Plain + + + 2 + + + Qt::Horizontal + + + + + + + QFrame::NoFrame + + + QFrame::Plain + + + 0 + + + Qt::ScrollBarAlwaysOff + + + Qt::ScrollBarAlwaysOff + + + + + + + + + QFrame::Plain + + + Qt::Vertical + + + + + + + + 75 + true + + + + Previous + + + + + + + QFrame::Plain + + + Qt::Vertical + + + + + + + + 75 + true + + + + Options + + + + + + + + 75 + true + + + + Next + + + + + + + + 75 + true + + + + Hide + + + + + + @@ -320,19 +709,6 @@ 0 - - - - QFrame::Plain - - - 4 - - - Qt::Horizontal - - - @@ -361,6 +737,40 @@ 0 + + + + + + 4 + + + 1 + + + 0 + + + Qt::Horizontal + + + + + + + Value + + + + + + + + + Font: + + + @@ -410,13 +820,6 @@ - - - - Font: - - - @@ -424,32 +827,12 @@ - - - - - - 4 - - - 1 - - - 0 - - - Qt::Horizontal - - - - - - - Value - - - - + + + + Alignment: + + @@ -531,131 +914,23 @@ - - - - Alignment: - - - - - - - - - QFrame::Plain - - - 2 - - - Qt::Horizontal - - - - - - - 0 - - - - - QFrame::Plain - - - Qt::Vertical - - - - - - - Battery Icon - - - - - - - Night mode - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - QFrame::Plain - - - 1 - - - Qt::Vertical - - - - - - - About - - - - - - - Home - - - - - - - Search - - - - - - - - 75 - true - - - - Battery - - - - - - - QFrame::Plain - - - Qt::Vertical - - - + + + + QFrame::Plain + + + 2 + + + Qt::Horizontal + + + @@ -668,377 +943,7 @@ - - - - QFrame::Plain - - - 2 - - - Qt::Horizontal - - - - - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - QFrame::Plain - - - 8 - - - Qt::Horizontal - - - - - - - 0 - - - 6 - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Save - - - - - - - Close - - - - - - - - 75 - true - - - - Word search - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - 0 - - - - - 0 - - - - - QFrame::Plain - - - 2 - - - Qt::Vertical - - - - - - - - Source Serif Pro - - - - Definition - - - Qt::AlignJustify|Qt::AlignVCenter - - - true - - - - - - - - Inter - 75 - true - - - - Word - - - Qt::AlignCenter - - - true - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - 0 - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Previous - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Status - - - - - - - Next - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - QFrame::Plain - - - 8 - - - Qt::Horizontal - - - - - - - - - - - - - - QFrame::Plain - - - Qt::Vertical - - - - - - - - 75 - true - - - - Previous - - - - - - - QFrame::Plain - - - Qt::Vertical - - - - - - - - 75 - true - - - - Options - - - - - - - - 75 - true - - - - Next - - - - - - - - 75 - true - - - - Hide - - - - - - + @@ -1056,19 +961,6 @@ - - - - QFrame::Plain - - - 2 - - - Qt::Horizontal - - - @@ -1097,6 +989,19 @@ + + + + QFrame::Plain + + + 2 + + + Qt::Horizontal + + + @@ -1104,6 +1009,141 @@ + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + 0 + + + + + QFrame::Plain + + + Qt::Vertical + + + + + + + Night mode + + + + + + + QFrame::Plain + + + Qt::Vertical + + + + + + + QFrame::Plain + + + 1 + + + Qt::Vertical + + + + + + + Home + + + + + + + + 75 + true + + + + Battery + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Search + + + + + + + About + + + + + + + Battery Icon + + + + + + + + + QFrame::Plain + + + 4 + + + Qt::Horizontal + + + + + + + + diff --git a/settings.cpp b/settings.cpp index 903a859..f98f15f 100644 --- a/settings.cpp +++ b/settings.cpp @@ -70,7 +70,8 @@ settings::settings(QWidget *parent) : ui->uiScalingLabel->hide(); // Variables - defineDefaultPageSize(); + defineDefaultPageSize(0); + defineDefaultPageSize(1); // Settings tweaking + enabling specific features whether it's running on the provided integrated OS or Kobo firmware if(checkconfig(".config/01-demo/config") == true) { @@ -429,6 +430,7 @@ void settings::on_requestLeaseBtn_clicked() QProcess *proc = new QProcess(); proc->start(prog, args); proc->waitForFinished(); + proc->deleteLater(); } void settings::on_usbmsBtn_clicked() @@ -442,6 +444,7 @@ void settings::on_usbmsBtn_clicked() QProcess *umount_proc = new QProcess(); umount_proc->start(umount_prog, umount_args); umount_proc->waitForFinished(); + umount_proc->deleteLater(); QString rmmod ("rmmod"); QStringList rmmod_args; @@ -449,6 +452,7 @@ void settings::on_usbmsBtn_clicked() QProcess *rmmod_proc = new QProcess(); rmmod_proc->start(rmmod, rmmod_args); rmmod_proc->waitForFinished(); + rmmod_proc->deleteLater(); QString prog ("insmod"); QStringList args; @@ -456,6 +460,7 @@ void settings::on_usbmsBtn_clicked() QProcess *proc = new QProcess(); proc->start(prog, args); proc->waitForFinished(); + proc->deleteLater(); QString prog_1 ("insmod"); QStringList args_1; @@ -463,6 +468,7 @@ void settings::on_usbmsBtn_clicked() QProcess *proc_1 = new QProcess(); proc_1->start(prog_1, args_1); proc_1->waitForFinished(); + proc_1->deleteLater(); usbmsWindow = new usbms_splash(); usbmsWindow->setAttribute(Qt::WA_DeleteOnClose); @@ -477,6 +483,7 @@ void settings::on_usbmsBtn_clicked() QProcess *proc = new QProcess(); proc->start(prog, args); proc->waitForFinished(); + proc->deleteLater(); QFile modules("/tmp/usbevent"); modules.open(QIODevice::ReadWrite); @@ -491,6 +498,7 @@ void settings::on_usbmsBtn_clicked() QProcess *reboot_proc = new QProcess(); reboot_proc->start(reboot_prog, reboot_args); reboot_proc->waitForFinished(); + reboot_proc->deleteLater(); } else { ; @@ -593,6 +601,7 @@ void settings::on_updateBtn_clicked() QProcess *proc = new QProcess(); proc->start(prog, args); proc->waitForFinished(); + proc->deleteLater(); } void settings::on_darkModeCheckBox_toggled(bool checked) diff --git a/usbms_splash.cpp b/usbms_splash.cpp index 645d821..3f6b428 100644 --- a/usbms_splash.cpp +++ b/usbms_splash.cpp @@ -78,6 +78,7 @@ void usbms_splash::usbms_launch() QProcess *umount_proc = new QProcess(); umount_proc->start(umount_prog, umount_args); umount_proc->waitForFinished(); + umount_proc->deleteLater(); QString rmmod ("rmmod"); QStringList rmmod_args; @@ -85,6 +86,7 @@ void usbms_splash::usbms_launch() QProcess *rmmod_proc = new QProcess(); rmmod_proc->start(rmmod, rmmod_args); rmmod_proc->waitForFinished(); + rmmod_proc->deleteLater(); QString prog ("insmod"); QStringList args; @@ -92,6 +94,7 @@ void usbms_splash::usbms_launch() QProcess *proc = new QProcess(); proc->start(prog, args); proc->waitForFinished(); + proc->deleteLater(); QString prog_1 ("insmod"); QStringList args_1; @@ -106,6 +109,7 @@ void usbms_splash::usbms_launch() QProcess *proc_1 = new QProcess(); proc_1->start(prog_1, args_1); proc_1->waitForFinished(); + proc_1->deleteLater(); QTimer *usbms_t = new QTimer(this); usbms_t->setInterval(1000); @@ -115,6 +119,7 @@ void usbms_splash::usbms_launch() QProcess *proc = new QProcess(); proc->start(prog, args); proc->waitForFinished(); + proc->deleteLater(); QFile modules("/tmp/usbevent"); modules.open(QIODevice::ReadWrite); @@ -129,6 +134,7 @@ void usbms_splash::usbms_launch() QProcess *reboot_proc = new QProcess(); reboot_proc->start(reboot_prog, reboot_args); reboot_proc->waitForFinished(); + reboot_proc->deleteLater(); } else { ;