Drastic speed improvement when reading big books. Initial EPUB support.

UI fixes.
This commit is contained in:
Nicolas Mailloux 2021-03-27 19:08:05 -04:00
parent 69327c5363
commit 2f0c8d2a30
3 changed files with 620 additions and 550 deletions

View file

@ -104,14 +104,17 @@ reader::reader(QWidget *parent) :
// Hiding the menubar + definition widget + brightness widget
ui->hideOptionsBtn->hide();
ui->menuWidget->setVisible(false);
ui->brightnessWidget->setVisible(false);
ui->menuBarWidget->setVisible(false);
ui->wordWidget->setVisible(false);
if(checkconfig(".config/11-menubar/sticky") == true) {
ui->menuWidget->setVisible(true);
ui->spacerWidget->setVisible(true);
ui->statusBarWidget->setVisible(true);
}
else {
ui->menuWidget->setVisible(false);
ui->spacerWidget->setVisible(false);
ui->statusBarWidget->setVisible(false);
}
@ -277,9 +280,8 @@ reader::reader(QWidget *parent) :
// Counting number of parsed files
split_total = setup_book(book_file, 0, true);
split_files_number = split_total;
split_total = split_total - 1;
split_files_number = setup_book(book_file, 0, true);
split_files_number = split_files_number / 2;
// Get text
QDir::setCurrent("/mnt/onboard/.adds/inkbox");
@ -365,6 +367,7 @@ void reader::on_nextBtn_clicked()
QMessageBox::critical(this, tr("Invalid argument"), tr("You've reached the end of the document."));
}
else {
parser_ran = true;
split_total = split_total - 1;
setup_book(book_file, split_total, false);
ui->text->setText("");
@ -379,6 +382,7 @@ void reader::on_previousBtn_clicked()
QMessageBox::critical(this, tr("Invalid argument"), tr("No previous page."));
}
else {
parser_ran = true;
split_total = split_total + 1;
setup_book(book_file, split_total, false);
ui->text->setText("");
@ -519,6 +523,7 @@ void reader::menubar_show() {
ui->hideOptionsBtn->show();
ui->optionsBtn->hide();
ui->menuWidget->setVisible(true);
ui->menuBarWidget->setVisible(true);
ui->statusBarWidget->setVisible(true);
@ -529,6 +534,13 @@ void reader::menubar_show() {
else {
ui->brightnessWidget->setVisible(true);
}
if(checkconfig(".config/11-menubar/sticky") == true) {
ui->spacerWidget->setVisible(false);
}
else {
// Safety measure
ui->spacerWidget->setVisible(false);
}
menubar_shown = true;
}
@ -536,9 +548,10 @@ void reader::menubar_show() {
void reader::menubar_hide() {
string_checkconfig("/opt/inkbox_device");
if(checkconfig_str_val == "n705\n") {
;
ui->brightnessWidget->setVisible(false);
}
else {
// Safety measure
ui->brightnessWidget->setVisible(false);
}
ui->hideOptionsBtn->hide();
@ -552,6 +565,7 @@ void reader::menubar_hide() {
ui->spacerWidget->setVisible(false);
ui->statusBarWidget->setVisible(false);
}
ui->menuWidget->hide();
menubar_shown = false;
}

View file

@ -32,6 +32,9 @@ public:
bool menubar_shown = false;
bool selected_text_lock = false;
bool nextdefinition_lock = false;
bool is_epub = false;
bool parser_ran = false;
bool booktostr_ran = false;
QString book_1;
QString book_2;
QString book_3;
@ -71,7 +74,6 @@ public:
};
int setup_book(QString book, int i, bool run_parser) {
// Parse ebook
// TODO: Use BeautifulSoup with Python to parse ePUBs and display them... somehow (?
QString mount_prog ("sh");
QStringList mount_args;
mount_args << "split.sh";
@ -79,17 +81,28 @@ public:
mount_proc->start(mount_prog, mount_args);
mount_proc->waitForFinished();
if(epub_file_match(book) == true) {
// Parsing ePUB with epub2txt, thanks to GitHub:kevinboone
if(booktostr_ran != true) {
if(epub_file_match(book) == true) {
// Parsing ePUBs with epub2txt, thanks to GitHub:kevinboone
QString epubProg ("sh");
QStringList epubArgs;
epubArgs << "/mnt/onboard/.adds/inkbox/epub.sh" << book;
QProcess *epubProc = new QProcess();
epubProc->start(epubProg, epubArgs);
epubProc->waitForFinished();
}
else {
// This is likely not an ePUB.
;
}
is_epub = true;
booktostr_ran = true;
}
else {
// This is likely not an ePUB.
// Copying book specified in the function call
QFile::copy(book, "/inkbox/book/book.txt");
// Copying book specified in the function call
QFile::copy(book, "/inkbox/book/book.txt");
is_epub = false;
booktostr_ran = true;
}
}
// Checking if the user has defined an option for the number of words per page; if not, then setting the default.
QDir::setCurrent("/mnt/onboard/.adds/inkbox");
@ -100,12 +113,26 @@ public:
}
// Parsing file
QString parse_prog ("python3");
QStringList parse_args;
parse_args << "split.py" << checkconfig_str_val;
QProcess *parse_proc = new QProcess();
parse_proc->start(parse_prog, parse_args);
parse_proc->waitForFinished();
if(parser_ran != true) {
if(is_epub == true) {
QString parse_prog ("python3");
QStringList parse_args;
parse_args << "split.py" << checkconfig_str_val;
QProcess *parse_proc = new QProcess();
parse_proc->start(parse_prog, parse_args);
parse_proc->waitForFinished();
parser_ran = false;
}
else {
QString parse_prog ("python3");
QStringList parse_args;
parse_args << "split-txt.py" << checkconfig_str_val;
QProcess *parse_proc = new QProcess();
parse_proc->start(parse_prog, parse_args);
parse_proc->waitForFinished();
parser_ran = false;
}
}
// Changing current working directory
QDir::setCurrent("/inkbox/book");
@ -141,7 +168,6 @@ public:
QString valuestr = int_config.readAll();
int value = valuestr.toInt();
int_config.close();
qDebug() << value;
return value;
}
void string_checkconfig_ro(QString file) {
@ -200,11 +226,9 @@ public:
QString fileExt = file.right(4);
if(fileExt == "epub" or fileExt=="EPUB") {
qDebug() << "True.";
return true;
}
else {
qDebug() << "False.";
return false;
}
};

1088
reader.ui

File diff suppressed because it is too large Load diff