mirror of
https://github.com/Quill-OS/quill.git
synced 2024-10-31 21:33:22 -07:00
Drastic speed improvement when reading big books. Initial EPUB support.
UI fixes.
This commit is contained in:
parent
69327c5363
commit
2f0c8d2a30
3 changed files with 620 additions and 550 deletions
20
reader.cpp
20
reader.cpp
|
@ -104,14 +104,17 @@ reader::reader(QWidget *parent) :
|
||||||
|
|
||||||
// Hiding the menubar + definition widget + brightness widget
|
// Hiding the menubar + definition widget + brightness widget
|
||||||
ui->hideOptionsBtn->hide();
|
ui->hideOptionsBtn->hide();
|
||||||
|
ui->menuWidget->setVisible(false);
|
||||||
ui->brightnessWidget->setVisible(false);
|
ui->brightnessWidget->setVisible(false);
|
||||||
ui->menuBarWidget->setVisible(false);
|
ui->menuBarWidget->setVisible(false);
|
||||||
ui->wordWidget->setVisible(false);
|
ui->wordWidget->setVisible(false);
|
||||||
if(checkconfig(".config/11-menubar/sticky") == true) {
|
if(checkconfig(".config/11-menubar/sticky") == true) {
|
||||||
|
ui->menuWidget->setVisible(true);
|
||||||
ui->spacerWidget->setVisible(true);
|
ui->spacerWidget->setVisible(true);
|
||||||
ui->statusBarWidget->setVisible(true);
|
ui->statusBarWidget->setVisible(true);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
ui->menuWidget->setVisible(false);
|
||||||
ui->spacerWidget->setVisible(false);
|
ui->spacerWidget->setVisible(false);
|
||||||
ui->statusBarWidget->setVisible(false);
|
ui->statusBarWidget->setVisible(false);
|
||||||
}
|
}
|
||||||
|
@ -277,9 +280,8 @@ reader::reader(QWidget *parent) :
|
||||||
|
|
||||||
// Counting number of parsed files
|
// Counting number of parsed files
|
||||||
split_total = setup_book(book_file, 0, true);
|
split_total = setup_book(book_file, 0, true);
|
||||||
|
split_files_number = split_total;
|
||||||
split_total = split_total - 1;
|
split_total = split_total - 1;
|
||||||
split_files_number = setup_book(book_file, 0, true);
|
|
||||||
split_files_number = split_files_number / 2;
|
|
||||||
|
|
||||||
// Get text
|
// Get text
|
||||||
QDir::setCurrent("/mnt/onboard/.adds/inkbox");
|
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."));
|
QMessageBox::critical(this, tr("Invalid argument"), tr("You've reached the end of the document."));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
parser_ran = true;
|
||||||
split_total = split_total - 1;
|
split_total = split_total - 1;
|
||||||
setup_book(book_file, split_total, false);
|
setup_book(book_file, split_total, false);
|
||||||
ui->text->setText("");
|
ui->text->setText("");
|
||||||
|
@ -379,6 +382,7 @@ void reader::on_previousBtn_clicked()
|
||||||
QMessageBox::critical(this, tr("Invalid argument"), tr("No previous page."));
|
QMessageBox::critical(this, tr("Invalid argument"), tr("No previous page."));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
parser_ran = true;
|
||||||
split_total = split_total + 1;
|
split_total = split_total + 1;
|
||||||
setup_book(book_file, split_total, false);
|
setup_book(book_file, split_total, false);
|
||||||
ui->text->setText("");
|
ui->text->setText("");
|
||||||
|
@ -519,6 +523,7 @@ void reader::menubar_show() {
|
||||||
|
|
||||||
ui->hideOptionsBtn->show();
|
ui->hideOptionsBtn->show();
|
||||||
ui->optionsBtn->hide();
|
ui->optionsBtn->hide();
|
||||||
|
ui->menuWidget->setVisible(true);
|
||||||
ui->menuBarWidget->setVisible(true);
|
ui->menuBarWidget->setVisible(true);
|
||||||
ui->statusBarWidget->setVisible(true);
|
ui->statusBarWidget->setVisible(true);
|
||||||
|
|
||||||
|
@ -529,6 +534,13 @@ void reader::menubar_show() {
|
||||||
else {
|
else {
|
||||||
ui->brightnessWidget->setVisible(true);
|
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;
|
menubar_shown = true;
|
||||||
}
|
}
|
||||||
|
@ -536,9 +548,10 @@ void reader::menubar_show() {
|
||||||
void reader::menubar_hide() {
|
void reader::menubar_hide() {
|
||||||
string_checkconfig("/opt/inkbox_device");
|
string_checkconfig("/opt/inkbox_device");
|
||||||
if(checkconfig_str_val == "n705\n") {
|
if(checkconfig_str_val == "n705\n") {
|
||||||
;
|
ui->brightnessWidget->setVisible(false);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
// Safety measure
|
||||||
ui->brightnessWidget->setVisible(false);
|
ui->brightnessWidget->setVisible(false);
|
||||||
}
|
}
|
||||||
ui->hideOptionsBtn->hide();
|
ui->hideOptionsBtn->hide();
|
||||||
|
@ -552,6 +565,7 @@ void reader::menubar_hide() {
|
||||||
ui->spacerWidget->setVisible(false);
|
ui->spacerWidget->setVisible(false);
|
||||||
ui->statusBarWidget->setVisible(false);
|
ui->statusBarWidget->setVisible(false);
|
||||||
}
|
}
|
||||||
|
ui->menuWidget->hide();
|
||||||
menubar_shown = false;
|
menubar_shown = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
62
reader.h
62
reader.h
|
@ -32,6 +32,9 @@ public:
|
||||||
bool menubar_shown = false;
|
bool menubar_shown = false;
|
||||||
bool selected_text_lock = false;
|
bool selected_text_lock = false;
|
||||||
bool nextdefinition_lock = false;
|
bool nextdefinition_lock = false;
|
||||||
|
bool is_epub = false;
|
||||||
|
bool parser_ran = false;
|
||||||
|
bool booktostr_ran = false;
|
||||||
QString book_1;
|
QString book_1;
|
||||||
QString book_2;
|
QString book_2;
|
||||||
QString book_3;
|
QString book_3;
|
||||||
|
@ -71,7 +74,6 @@ public:
|
||||||
};
|
};
|
||||||
int setup_book(QString book, int i, bool run_parser) {
|
int setup_book(QString book, int i, bool run_parser) {
|
||||||
// Parse ebook
|
// Parse ebook
|
||||||
// TODO: Use BeautifulSoup with Python to parse ePUBs and display them... somehow (?
|
|
||||||
QString mount_prog ("sh");
|
QString mount_prog ("sh");
|
||||||
QStringList mount_args;
|
QStringList mount_args;
|
||||||
mount_args << "split.sh";
|
mount_args << "split.sh";
|
||||||
|
@ -79,17 +81,28 @@ public:
|
||||||
mount_proc->start(mount_prog, mount_args);
|
mount_proc->start(mount_prog, mount_args);
|
||||||
mount_proc->waitForFinished();
|
mount_proc->waitForFinished();
|
||||||
|
|
||||||
if(epub_file_match(book) == true) {
|
if(booktostr_ran != true) {
|
||||||
// Parsing ePUB with epub2txt, thanks to GitHub:kevinboone
|
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();
|
||||||
|
|
||||||
}
|
is_epub = true;
|
||||||
else {
|
booktostr_ran = true;
|
||||||
// This is likely not an ePUB.
|
}
|
||||||
;
|
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
|
is_epub = false;
|
||||||
QFile::copy(book, "/inkbox/book/book.txt");
|
booktostr_ran = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Checking if the user has defined an option for the number of words per page; if not, then setting the default.
|
// 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");
|
QDir::setCurrent("/mnt/onboard/.adds/inkbox");
|
||||||
|
@ -100,12 +113,26 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parsing file
|
// Parsing file
|
||||||
QString parse_prog ("python3");
|
if(parser_ran != true) {
|
||||||
QStringList parse_args;
|
if(is_epub == true) {
|
||||||
parse_args << "split.py" << checkconfig_str_val;
|
QString parse_prog ("python3");
|
||||||
QProcess *parse_proc = new QProcess();
|
QStringList parse_args;
|
||||||
parse_proc->start(parse_prog, parse_args);
|
parse_args << "split.py" << checkconfig_str_val;
|
||||||
parse_proc->waitForFinished();
|
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
|
// Changing current working directory
|
||||||
QDir::setCurrent("/inkbox/book");
|
QDir::setCurrent("/inkbox/book");
|
||||||
|
@ -141,7 +168,6 @@ public:
|
||||||
QString valuestr = int_config.readAll();
|
QString valuestr = int_config.readAll();
|
||||||
int value = valuestr.toInt();
|
int value = valuestr.toInt();
|
||||||
int_config.close();
|
int_config.close();
|
||||||
qDebug() << value;
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
void string_checkconfig_ro(QString file) {
|
void string_checkconfig_ro(QString file) {
|
||||||
|
@ -200,11 +226,9 @@ public:
|
||||||
QString fileExt = file.right(4);
|
QString fileExt = file.right(4);
|
||||||
|
|
||||||
if(fileExt == "epub" or fileExt=="EPUB") {
|
if(fileExt == "epub" or fileExt=="EPUB") {
|
||||||
qDebug() << "True.";
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
qDebug() << "False.";
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue