mirror of
https://github.com/Quill-OS/quill.git
synced 2024-12-26 23:57:22 -08:00
PDF support!
This commit is contained in:
parent
ffb37ec9fa
commit
dc864f6d4e
11 changed files with 962 additions and 662 deletions
|
@ -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()
|
||||
|
|
|
@ -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);
|
||||
|
|
69
functions.h
69
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) {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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);
|
||||
|
|
338
reader.cpp
338
reader.cpp
|
@ -16,6 +16,7 @@
|
|||
#include <QDirIterator>
|
||||
#include <QTextCursor>
|
||||
#include <QDebug>
|
||||
#include <QGraphicsScene>
|
||||
|
||||
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(" <i>of</i> ");
|
||||
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();
|
||||
}
|
||||
|
|
44
reader.h
44
reader.h
|
@ -7,19 +7,30 @@
|
|||
#include "toast.h"
|
||||
|
||||
#include <QWidget>
|
||||
#include <QGraphicsScene>
|
||||
|
||||
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
|
||||
|
|
11
settings.cpp
11
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)
|
||||
|
|
|
@ -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 {
|
||||
;
|
||||
|
|
Loading…
Reference in a new issue