mirror of
https://github.com/Quill-OS/quill.git
synced 2024-12-26 23:57:22 -08:00
Dirty commit that's not even working
This commit is contained in:
parent
f6099b9394
commit
cb65131841
4 changed files with 159 additions and 78 deletions
|
@ -21,6 +21,7 @@ namespace global {
|
||||||
inline int bookNumber;
|
inline int bookNumber;
|
||||||
inline bool skipOpenDialog;
|
inline bool skipOpenDialog;
|
||||||
inline bool startBatteryWatchdog;
|
inline bool startBatteryWatchdog;
|
||||||
|
inline bool bookIsEpub;
|
||||||
}
|
}
|
||||||
namespace kobox {
|
namespace kobox {
|
||||||
inline bool showKoboxSplash;
|
inline bool showKoboxSplash;
|
||||||
|
|
7
main.cpp
7
main.cpp
|
@ -64,6 +64,13 @@ int main(int argc, char *argv[])
|
||||||
global::reader::startBatteryWatchdog = true;
|
global::reader::startBatteryWatchdog = true;
|
||||||
global::reader::skipOpenDialog = true;
|
global::reader::skipOpenDialog = true;
|
||||||
|
|
||||||
|
if(checkconfig("/inkbox/bookIsEpub") == true) {
|
||||||
|
global::reader::bookIsEpub = true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
global::reader::bookIsEpub = false;
|
||||||
|
}
|
||||||
|
|
||||||
string_writeconfig("/inkbox/skip_opendialog", "true");
|
string_writeconfig("/inkbox/skip_opendialog", "true");
|
||||||
QApplication a(argc, argv);
|
QApplication a(argc, argv);
|
||||||
reader w;
|
reader w;
|
||||||
|
|
119
reader.cpp
119
reader.cpp
|
@ -25,6 +25,9 @@ reader::reader(QWidget *parent) :
|
||||||
// Variables
|
// Variables
|
||||||
global::battery::showLowBatteryDialog = true;
|
global::battery::showLowBatteryDialog = true;
|
||||||
global::battery::showCriticalBatteryAlert = true;
|
global::battery::showCriticalBatteryAlert = true;
|
||||||
|
if(global::reader::bookIsEpub == true) {
|
||||||
|
is_epub = true;
|
||||||
|
}
|
||||||
|
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
ui->previousBtn->setProperty("type", "borderless");
|
ui->previousBtn->setProperty("type", "borderless");
|
||||||
|
@ -402,7 +405,12 @@ reader::reader(QWidget *parent) :
|
||||||
ui->text->setStyleSheet(font_size);
|
ui->text->setStyleSheet(font_size);
|
||||||
|
|
||||||
// Wheeee!
|
// Wheeee!
|
||||||
|
if(is_epub != true) {
|
||||||
ui->text->setText(ittext);
|
ui->text->setText(ittext);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ui->text->setText(epubPageContent);
|
||||||
|
}
|
||||||
|
|
||||||
// Clean up
|
// Clean up
|
||||||
string_writeconfig("/inkbox/remount", "true");
|
string_writeconfig("/inkbox/remount", "true");
|
||||||
|
@ -515,30 +523,35 @@ int reader::setup_book(QString book, int i, bool run_parser) {
|
||||||
mount_proc->waitForFinished();
|
mount_proc->waitForFinished();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(booktostr_ran != true) {
|
if(filematch_ran != true) {
|
||||||
if(epub_file_match(book) == true) {
|
if(epub_file_match(book) == true) {
|
||||||
// Parsing ePUBs with epub2txt, thanks to GitHub:kevinboone
|
QFile::copy(book, "/inkbox/book/book.epub");
|
||||||
|
QFile::copy(book, "/mutool_rootfs/run/book.epub");
|
||||||
|
|
||||||
|
// Parsing ePUBs with `mutool'
|
||||||
QString epubProg ("sh");
|
QString epubProg ("sh");
|
||||||
QStringList epubArgs;
|
QStringList epubArgs;
|
||||||
epubArgs << "/mnt/onboard/.adds/inkbox/epub.sh" << book;
|
convertMuPdfVars();
|
||||||
|
epubArgs << "/mnt/onboard/.adds/inkbox/epub.sh" << mupdf::fontSize_qstr << mupdf::width_qstr << mupdf::height_qstr << mupdf::epubPageNumber_qstr;
|
||||||
QProcess *epubProc = new QProcess();
|
QProcess *epubProc = new QProcess();
|
||||||
epubProc->start(epubProg, epubArgs);
|
epubProc->start(epubProg, epubArgs);
|
||||||
epubProc->waitForFinished();
|
epubProc->waitForFinished();
|
||||||
|
|
||||||
|
filematch_ran = true;
|
||||||
is_epub = true;
|
is_epub = true;
|
||||||
booktostr_ran = true;
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// This is likely not an ePUB.
|
// This is likely not an ePUB.
|
||||||
// Copying book specified in the function call
|
// Copying book specified in the function call
|
||||||
QFile::copy(book, "/inkbox/book/book.txt");
|
QFile::copy(book, "/inkbox/book/book.txt");
|
||||||
|
|
||||||
|
filematch_ran = true;
|
||||||
is_epub = false;
|
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.
|
// Checking whether the user has defined an option for the number of words per page; if not, then setting the default.
|
||||||
|
// NOTE: This is only for plain text files.
|
||||||
QDir::setCurrent("/mnt/onboard/.adds/inkbox");
|
QDir::setCurrent("/mnt/onboard/.adds/inkbox");
|
||||||
string_checkconfig(".config/07-words_number/config");
|
string_checkconfig(".config/07-words_number/config");
|
||||||
if(checkconfig_str_val == "") {
|
if(checkconfig_str_val == "") {
|
||||||
|
@ -547,17 +560,18 @@ int reader::setup_book(QString book, int i, bool run_parser) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parsing file
|
// Parsing file
|
||||||
if(parser_ran != true) {
|
if(filematch_ran != true) {
|
||||||
if(is_epub == true) {
|
if(is_epub == true) {
|
||||||
QString parse_prog ("python3");
|
QString epubProg ("sh");
|
||||||
QStringList parse_args;
|
QStringList epubArgs;
|
||||||
parse_args << "split.py" << checkconfig_str_val;
|
convertMuPdfVars();
|
||||||
QProcess *parse_proc = new QProcess();
|
epubArgs << "/mnt/onboard/.adds/inkbox/epub.sh" << mupdf::fontSize_qstr << mupdf::width_qstr << mupdf::height_qstr << mupdf::epubPageNumber_qstr;
|
||||||
parse_proc->start(parse_prog, parse_args);
|
QProcess *epubProc = new QProcess();
|
||||||
parse_proc->waitForFinished();
|
epubProc->start(epubProg, epubArgs);
|
||||||
parser_ran = true;
|
epubProc->waitForFinished();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
if(parser_ran != true) {
|
||||||
QString parse_prog ("python3");
|
QString parse_prog ("python3");
|
||||||
QStringList parse_args;
|
QStringList parse_args;
|
||||||
parse_args << "split-txt.py" << checkconfig_str_val;
|
parse_args << "split-txt.py" << checkconfig_str_val;
|
||||||
|
@ -566,12 +580,17 @@ int reader::setup_book(QString book, int i, bool run_parser) {
|
||||||
parse_proc->waitForFinished();
|
parse_proc->waitForFinished();
|
||||||
parser_ran = true;
|
parser_ran = true;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Changing current working directory
|
// Changing current working directory
|
||||||
QDir::setCurrent("/inkbox/book");
|
QDir::setCurrent("/inkbox/book");
|
||||||
|
|
||||||
// Reading file
|
// Reading files
|
||||||
|
if(is_epub != true) {
|
||||||
if(run_parser == true) {
|
if(run_parser == true) {
|
||||||
QDirIterator it("/inkbox/book/split");
|
QDirIterator it("/inkbox/book/split");
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
|
@ -587,6 +606,15 @@ int reader::setup_book(QString book, int i, bool run_parser) {
|
||||||
ittext = content[i];
|
ittext = content[i];
|
||||||
QDir::setCurrent("/mnt/onboard/.adds/inkbox");
|
QDir::setCurrent("/mnt/onboard/.adds/inkbox");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
QFile epubPage("/inkbox/book/page");
|
||||||
|
epubPage.open(QIODevice::ReadOnly);
|
||||||
|
QTextStream in(&epubPage);
|
||||||
|
epubPageContent = in.readAll();
|
||||||
|
epubPage.close();
|
||||||
|
QDir::setCurrent("/mnt/onboard/.adds/inkbox");
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -665,6 +693,7 @@ void reader::save_word(string word, bool remove) {
|
||||||
|
|
||||||
void reader::on_nextBtn_clicked()
|
void reader::on_nextBtn_clicked()
|
||||||
{
|
{
|
||||||
|
if(is_epub != true) {
|
||||||
if(split_total - 1 == 1 or split_total - 1 == 0) {
|
if(split_total - 1 == 1 or split_total - 1 == 0) {
|
||||||
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."));
|
||||||
}
|
}
|
||||||
|
@ -677,24 +706,22 @@ void reader::on_nextBtn_clicked()
|
||||||
ui->text->setText(ittext);
|
ui->text->setText(ittext);
|
||||||
|
|
||||||
pagesTurned = pagesTurned + 1;
|
pagesTurned = pagesTurned + 1;
|
||||||
if(neverRefresh == true) {
|
|
||||||
// Do nothing; "Never refresh" was set
|
|
||||||
;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if(pagesTurned >= pageRefreshSetting) {
|
|
||||||
// Refreshing the screen
|
|
||||||
this->repaint();
|
|
||||||
// Reset count
|
|
||||||
pagesTurned = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
writeconfig_pagenumber();
|
writeconfig_pagenumber();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
mupdf::epubPageNumber = mupdf::epubPageNumber + 1;
|
||||||
|
setup_book(book_file, mupdf::epubPageNumber, false);
|
||||||
|
|
||||||
|
pagesTurned = pagesTurned + 1;
|
||||||
|
writeconfig_pagenumber();
|
||||||
|
}
|
||||||
|
refreshScreen();
|
||||||
}
|
}
|
||||||
|
|
||||||
void reader::on_previousBtn_clicked()
|
void reader::on_previousBtn_clicked()
|
||||||
{
|
{
|
||||||
|
if(is_epub != true) {
|
||||||
// Making sure we won't encounter a "List index out of range" error ;)
|
// Making sure we won't encounter a "List index out of range" error ;)
|
||||||
if(split_total >= split_files_number - 1) {
|
if(split_total >= split_files_number - 1) {
|
||||||
QMessageBox::critical(this, tr("Invalid argument"), tr("No previous page."));
|
QMessageBox::critical(this, tr("Invalid argument"), tr("No previous page."));
|
||||||
|
@ -704,10 +731,30 @@ void reader::on_previousBtn_clicked()
|
||||||
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("");
|
||||||
|
if(is_epub != true) {
|
||||||
ui->text->setText(ittext);
|
ui->text->setText(ittext);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ui->text->setText(epubPageContent);
|
||||||
|
}
|
||||||
|
|
||||||
// We always increment pagesTurned regardless if we press the Previous or Next button
|
// We always increment pagesTurned regardless whether we press the Previous or Next button
|
||||||
pagesTurned = pagesTurned + 1;
|
pagesTurned = pagesTurned + 1;
|
||||||
|
refreshScreen();
|
||||||
|
writeconfig_pagenumber();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
mupdf::epubPageNumber = mupdf::epubPageNumber - 1;
|
||||||
|
setup_book(book_file, mupdf::epubPageNumber, false);
|
||||||
|
|
||||||
|
// We always increment pagesTurned regardless whether we press the Previous or Next button
|
||||||
|
pagesTurned = pagesTurned + 1;
|
||||||
|
writeconfig_pagenumber();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void reader::refreshScreen() {
|
||||||
if(neverRefresh == true) {
|
if(neverRefresh == true) {
|
||||||
// Do nothing; "Never refresh" was set
|
// Do nothing; "Never refresh" was set
|
||||||
;
|
;
|
||||||
|
@ -720,8 +767,6 @@ void reader::on_previousBtn_clicked()
|
||||||
pagesTurned = 0;
|
pagesTurned = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
writeconfig_pagenumber();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void reader::on_optionsBtn_clicked()
|
void reader::on_optionsBtn_clicked()
|
||||||
|
@ -1069,8 +1114,14 @@ void reader::on_sizeSlider_valueChanged(int value)
|
||||||
|
|
||||||
void reader::writeconfig_pagenumber() {
|
void reader::writeconfig_pagenumber() {
|
||||||
// Saving the page number in tmpfs
|
// Saving the page number in tmpfs
|
||||||
string split_total_str = to_string(split_total);
|
if(is_epub != true) {
|
||||||
|
std::string split_total_str = std::to_string(split_total);
|
||||||
string_writeconfig("/tmp/inkboxPageNumber", split_total_str);
|
string_writeconfig("/tmp/inkboxPageNumber", split_total_str);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
std::string epubPageNumber_str = std::to_string(mupdf::epubPageNumber);
|
||||||
|
string_writeconfig("/tmp/inkboxPageNumber", epubPageNumber_str);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void reader::quit_restart() {
|
void reader::quit_restart() {
|
||||||
|
@ -1099,3 +1150,9 @@ void reader::openCriticalBatteryAlertWindow() {
|
||||||
alertWindow->setGeometry(QRect(QPoint(0,0), screen()->geometry ().size()));
|
alertWindow->setGeometry(QRect(QPoint(0,0), screen()->geometry ().size()));
|
||||||
alertWindow->show();
|
alertWindow->show();
|
||||||
}
|
}
|
||||||
|
void reader::convertMuPdfVars() {
|
||||||
|
mupdf::fontSize_qstr = QString::number(mupdf::fontSize);
|
||||||
|
mupdf::width_qstr = QString::number(mupdf::width);
|
||||||
|
mupdf::height_qstr = QString::number(mupdf::height);
|
||||||
|
mupdf::epubPageNumber_qstr = QString::number(mupdf::epubPageNumber);
|
||||||
|
}
|
||||||
|
|
16
reader.h
16
reader.h
|
@ -9,6 +9,18 @@
|
||||||
|
|
||||||
using namespace std;
|
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 Ui {
|
namespace Ui {
|
||||||
class reader;
|
class reader;
|
||||||
}
|
}
|
||||||
|
@ -37,6 +49,7 @@ public:
|
||||||
bool is_epub = false;
|
bool is_epub = false;
|
||||||
bool parser_ran = false;
|
bool parser_ran = false;
|
||||||
bool booktostr_ran = false;
|
bool booktostr_ran = false;
|
||||||
|
bool filematch_ran = false;
|
||||||
bool neverRefresh = false;
|
bool neverRefresh = false;
|
||||||
bool wakeFromSleep = false;
|
bool wakeFromSleep = false;
|
||||||
bool remount = true;
|
bool remount = true;
|
||||||
|
@ -58,6 +71,7 @@ public:
|
||||||
QPixmap scaledFullPixmap;
|
QPixmap scaledFullPixmap;
|
||||||
QPixmap scaledEmptyPixmap;
|
QPixmap scaledEmptyPixmap;
|
||||||
QList<QString> content;
|
QList<QString> content;
|
||||||
|
QString epubPageContent;
|
||||||
int setup_book(QString book, int i, bool run_parser);
|
int setup_book(QString book, int i, bool run_parser);
|
||||||
void checkwords();
|
void checkwords();
|
||||||
bool epub_file_match(QString file);
|
bool epub_file_match(QString file);
|
||||||
|
@ -69,6 +83,8 @@ public:
|
||||||
void wordwidget_hide();
|
void wordwidget_hide();
|
||||||
void openLowBatteryDialog();
|
void openLowBatteryDialog();
|
||||||
void openCriticalBatteryAlertWindow();
|
void openCriticalBatteryAlertWindow();
|
||||||
|
void convertMuPdfVars();
|
||||||
|
void refreshScreen();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void on_nextBtn_clicked();
|
void on_nextBtn_clicked();
|
||||||
|
|
Loading…
Reference in a new issue