mirror of
https://github.com/Quill-OS/quill.git
synced 2024-12-26 23:57:22 -08:00
Merge branch 'Kobo-InkBox:master' into master
This commit is contained in:
commit
339b345f1e
6 changed files with 165 additions and 48 deletions
|
@ -13,6 +13,7 @@
|
|||
#include <QDirIterator>
|
||||
#include <QStringListModel>
|
||||
#include <QListView>
|
||||
#include <QDateTime>
|
||||
|
||||
generalDialog::generalDialog(QWidget *parent) :
|
||||
QDialog(parent),
|
||||
|
@ -39,6 +40,11 @@ generalDialog::generalDialog(QWidget *parent) :
|
|||
ui->bodyLabel->setStyleSheet("font-size: 9pt");
|
||||
ui->searchComboBox->setStyleSheet("font-size: 9pt");
|
||||
|
||||
// Disabling "Online library" search if device doesn't have Wi-Fi
|
||||
if(global::device::isWifiAble == false && readFile("/opt/inkbox_device") != "emu\n") {
|
||||
ui->searchComboBox->removeItem(2);
|
||||
}
|
||||
|
||||
if(QFile::exists("/inkbox/searchComboBoxFunction") == true) {
|
||||
string_checkconfig_ro("/inkbox/searchComboBoxFunction");
|
||||
if(checkconfig_str_val == "Dictionary") {
|
||||
|
@ -324,7 +330,7 @@ void generalDialog::on_okBtn_clicked()
|
|||
dirIt.next();
|
||||
if(QFileInfo(dirIt.filePath()).isFile()) {
|
||||
QString suffix = QFileInfo(dirIt.filePath()).suffix();
|
||||
if(suffix == "txt" or suffix == "TXT" or suffix == "epub" or suffix == "pdf" or suffix == "PDF") {
|
||||
if(suffix == "txt" or suffix == "TXT" or suffix == "epub" or suffix == "EPUB" or suffix == "pdf" or suffix == "PDF" or suffix == "png" or suffix == "PNG" or suffix == "tif" or suffix == "TIF" or suffix == "bmp" or suffix == "BMP" or suffix == "tiff" or suffix == "TIFF" or suffix == "jpg" or suffix == "JPG" or suffix == "jpeg" or suffix == "JPEG") {
|
||||
if(dirIt.fileName().contains(global::keyboard::keyboardText) == true) {
|
||||
storageSearchResults.append(dirIt.fileName());
|
||||
}
|
||||
|
@ -356,43 +362,38 @@ void generalDialog::on_okBtn_clicked()
|
|||
}
|
||||
else if(ui->searchComboBox->currentText() == "Online library") {
|
||||
string_writeconfig("/inkbox/searchComboBoxFunction", "Online library");
|
||||
string_writeconfig("/inkbox/gutenberg_search_request", global::keyboard::keyboardText.toStdString());
|
||||
string_writeconfig("/opt/ibxd", "gutenberg_search\n");
|
||||
while(true) {
|
||||
if(QFile::exists("/inkbox/gutenberg-search/search_done")) {
|
||||
if(checkconfig("/inkbox/gutenberg-search/search_done") == true) {
|
||||
QStringList searchResults = readFile("/inkbox/gutenberg-search/search_results_titles").split("\n");
|
||||
global::library::libraryResults = true;
|
||||
|
||||
for(int i = ui->mainStackedWidget->count(); i >= 0; i--) {
|
||||
QWidget * widget = ui->mainStackedWidget->widget(i);
|
||||
ui->mainStackedWidget->removeWidget(widget);
|
||||
widget->deleteLater();
|
||||
}
|
||||
ui->topStackedWidget->setVisible(false);
|
||||
ui->stackedWidget->setVisible(false);
|
||||
searchResultsWidgetWindow = new searchResultsWidget(this);
|
||||
searchResultsWidgetWindow->setAttribute(Qt::WA_DeleteOnClose);
|
||||
global::forbidOpenSearchDialog = true;
|
||||
connect(searchResultsWidgetWindow, SIGNAL(destroyed(QObject*)), SLOT(restartSearchDialog()));
|
||||
connect(searchResultsWidgetWindow, SIGNAL(showToast(QString)), SLOT(showToastNative(QString)));
|
||||
connect(searchResultsWidgetWindow, SIGNAL(closeIndefiniteToast()), SLOT(closeIndefiniteToastNative()));
|
||||
connect(searchResultsWidgetWindow, SIGNAL(hideDialog()), SLOT(hide()));
|
||||
searchResultsWidgetWindow->setListViewContents(searchResults);
|
||||
ui->mainStackedWidget->insertWidget(1, searchResultsWidgetWindow);
|
||||
QFile::remove("/inkbox/gutenberg-search/search_done");
|
||||
break;
|
||||
}
|
||||
else {
|
||||
global::toast::delay = 3000;
|
||||
emit showToast("No results found");
|
||||
keyboardWidget->clearLineEdit();
|
||||
global::keyboard::keyboardText = "";
|
||||
QFile::remove("/inkbox/gutenberg-search/search_done");
|
||||
break;
|
||||
}
|
||||
if(!readFile("/external_root/opt/storage/gutenberg/last_sync").isEmpty()) {
|
||||
unsigned long currentEpoch = QDateTime::currentSecsSinceEpoch();
|
||||
unsigned long syncEpoch = readFile("/external_root/opt/storage/gutenberg/last_sync").toULong();
|
||||
unsigned long allowSyncEpoch = syncEpoch + 86400;
|
||||
if(currentEpoch > allowSyncEpoch) {
|
||||
syncGutenbergCatalog();
|
||||
}
|
||||
else {
|
||||
noGutenbergSyncToDo = true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
syncGutenbergCatalog();
|
||||
}
|
||||
|
||||
QTimer * searchTimer = new QTimer(this);
|
||||
searchTimer->setInterval(100);
|
||||
connect(searchTimer, &QTimer::timeout, [&]() {
|
||||
if(noGutenbergSyncToDo == true or (gutenbergSyncDone == true && gutenbergSyncStatus == true)) {
|
||||
if(searchTimerDone == false) {
|
||||
searchTimerDone = true;
|
||||
string_writeconfig("/inkbox/gutenberg_search_request", global::keyboard::keyboardText.toStdString());
|
||||
string_writeconfig("/opt/ibxd", "gutenberg_search\n");
|
||||
global::toast::modalToast = true;
|
||||
global::toast::indefiniteToast = true;
|
||||
emit showToast("Searching");
|
||||
QTimer::singleShot(100, this, SLOT(waitForGutenbergSearchDone()));
|
||||
}
|
||||
}
|
||||
} );
|
||||
searchTimer->start();
|
||||
}
|
||||
else {
|
||||
;
|
||||
|
@ -610,3 +611,78 @@ void generalDialog::quit_restart() {
|
|||
process.startDetached("inkbox", QStringList());
|
||||
qApp->quit();
|
||||
}
|
||||
|
||||
void generalDialog::syncGutenbergCatalog() {
|
||||
global::toast::modalToast = true;
|
||||
global::toast::indefiniteToast = true;
|
||||
emit showToast("Sync in progress");
|
||||
|
||||
string_writeconfig("/opt/ibxd", "gutenberg_sync\n");
|
||||
QTimer * syncCheckTimer = new QTimer(this);
|
||||
syncCheckTimer->setInterval(100);
|
||||
connect(syncCheckTimer, &QTimer::timeout, [&]() {
|
||||
if(QFile::exists("/inkbox/gutenbergSyncDone") == true) {
|
||||
if(checkconfig("/inkbox/gutenbergSyncDone") == true) {
|
||||
qDebug() << "Gutenberg sync successfully completed";
|
||||
gutenbergSyncDone = true;
|
||||
gutenbergSyncStatus = true;
|
||||
emit closeIndefiniteToast();
|
||||
}
|
||||
else {
|
||||
qDebug() << "Gutenberg sync encountered an error";
|
||||
gutenbergSyncDone = true;
|
||||
gutenbergSyncStatus = false;
|
||||
emit closeIndefiniteToast();
|
||||
emit showToast("Error");
|
||||
global::keyboard::searchDialog = false;
|
||||
global::forbidOpenSearchDialog = true;
|
||||
global::keyboard::keyboardDialog = false;
|
||||
global::keyboard::keyboardText = "";
|
||||
global::library::librarySearchDialog = false;
|
||||
QTimer::singleShot(5000, this, SLOT(close()));
|
||||
}
|
||||
QFile::remove("/inkbox/gutenbergSyncDone");
|
||||
}
|
||||
} );
|
||||
syncCheckTimer->start();
|
||||
}
|
||||
|
||||
void generalDialog::waitForGutenbergSearchDone() {
|
||||
while(true) {
|
||||
if(QFile::exists("/inkbox/gutenberg-search/search_done")) {
|
||||
if(checkconfig("/inkbox/gutenberg-search/search_done") == true) {
|
||||
QStringList searchResults = readFile("/inkbox/gutenberg-search/search_results_titles").split("\n");
|
||||
global::library::libraryResults = true;
|
||||
|
||||
for(int i = ui->mainStackedWidget->count(); i >= 0; i--) {
|
||||
QWidget * widget = ui->mainStackedWidget->widget(i);
|
||||
ui->mainStackedWidget->removeWidget(widget);
|
||||
widget->deleteLater();
|
||||
}
|
||||
ui->topStackedWidget->setVisible(false);
|
||||
ui->stackedWidget->setVisible(false);
|
||||
searchResultsWidgetWindow = new searchResultsWidget(this);
|
||||
searchResultsWidgetWindow->setAttribute(Qt::WA_DeleteOnClose);
|
||||
global::forbidOpenSearchDialog = true;
|
||||
connect(searchResultsWidgetWindow, SIGNAL(destroyed(QObject*)), SLOT(restartSearchDialog()));
|
||||
connect(searchResultsWidgetWindow, SIGNAL(showToast(QString)), SLOT(showToastNative(QString)));
|
||||
connect(searchResultsWidgetWindow, SIGNAL(closeIndefiniteToast()), SLOT(closeIndefiniteToastNative()));
|
||||
connect(searchResultsWidgetWindow, SIGNAL(hideDialog()), SLOT(hide()));
|
||||
searchResultsWidgetWindow->setListViewContents(searchResults);
|
||||
ui->mainStackedWidget->insertWidget(1, searchResultsWidgetWindow);
|
||||
QFile::remove("/inkbox/gutenberg-search/search_done");
|
||||
emit closeIndefiniteToast();
|
||||
break;
|
||||
}
|
||||
else {
|
||||
global::toast::delay = 3000;
|
||||
emit showToast("No results found");
|
||||
keyboardWidget->clearLineEdit();
|
||||
global::keyboard::keyboardText = "";
|
||||
QFile::remove("/inkbox/gutenberg-search/search_done");
|
||||
emit closeIndefiniteToast();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,6 +37,10 @@ public:
|
|||
bool dictionaryResults = false;
|
||||
bool vncServerSet = false;
|
||||
bool vncPasswordSet = false;
|
||||
bool gutenbergSyncDone = false;
|
||||
bool gutenbergSyncStatus = false;
|
||||
bool noGutenbergSyncToDo = false;
|
||||
bool searchTimerDone = false;
|
||||
QString vncServerAddress;
|
||||
QString vncServerPassword;
|
||||
QString vncServerPort;
|
||||
|
@ -58,6 +62,8 @@ private slots:
|
|||
void showToastNative(QString messageToDisplay);
|
||||
void closeIndefiniteToastNative();
|
||||
void quit_restart();
|
||||
void syncGutenbergCatalog();
|
||||
void waitForGutenbergSearchDone();
|
||||
|
||||
private:
|
||||
Ui::generalDialog *ui;
|
||||
|
|
|
@ -182,6 +182,8 @@ MainWindow::MainWindow(QWidget *parent)
|
|||
|
||||
// Deleting/Hiding "Library" button if device is not WiFi-able
|
||||
if(global::device::isWifiAble == false && readFile("/opt/inkbox_device") != "emu\n") {
|
||||
ui->libraryButton->hide();
|
||||
ui->line_10->hide();
|
||||
ui->libraryButton->deleteLater();
|
||||
ui->line_10->deleteLater();
|
||||
}
|
||||
|
@ -446,6 +448,7 @@ MainWindow::MainWindow(QWidget *parent)
|
|||
ui->book3Btn->show();
|
||||
ui->book4Btn->show();
|
||||
|
||||
setRecentBooksLabelsTruncateTreshold();
|
||||
// Book 1
|
||||
string_checkconfig(".config/08-recent_books/1");
|
||||
if(checkconfig_str_val == "") {
|
||||
|
@ -453,8 +456,10 @@ MainWindow::MainWindow(QWidget *parent)
|
|||
}
|
||||
else {
|
||||
relative_path = checkconfig_str_val.split("/").last();
|
||||
relative_path.prepend(" ");
|
||||
relative_path.append(" ");
|
||||
if(relative_path.length() > truncateTreshold) {
|
||||
relative_path.truncate(truncateTreshold);
|
||||
relative_path.append(" ...");
|
||||
}
|
||||
ui->book1Btn->setText(relative_path);
|
||||
existing_recent_books = true;
|
||||
}
|
||||
|
@ -465,8 +470,10 @@ MainWindow::MainWindow(QWidget *parent)
|
|||
}
|
||||
else {
|
||||
relative_path = checkconfig_str_val.split("/").last();
|
||||
relative_path.prepend(" ");
|
||||
relative_path.append(" ");
|
||||
if(relative_path.length() > truncateTreshold) {
|
||||
relative_path.truncate(truncateTreshold);
|
||||
relative_path.append(" ...");
|
||||
}
|
||||
ui->book2Btn->setText(relative_path);
|
||||
existing_recent_books = true;
|
||||
}
|
||||
|
@ -477,8 +484,10 @@ MainWindow::MainWindow(QWidget *parent)
|
|||
}
|
||||
else {
|
||||
relative_path = checkconfig_str_val.split("/").last();
|
||||
relative_path.prepend(" ");
|
||||
relative_path.append(" ");
|
||||
if(relative_path.length() > truncateTreshold) {
|
||||
relative_path.truncate(truncateTreshold);
|
||||
relative_path.append(" ...");
|
||||
}
|
||||
ui->book3Btn->setText(relative_path);
|
||||
existing_recent_books = true;
|
||||
}
|
||||
|
@ -489,8 +498,10 @@ MainWindow::MainWindow(QWidget *parent)
|
|||
}
|
||||
else {
|
||||
relative_path = checkconfig_str_val.split("/").last();
|
||||
relative_path.prepend(" ");
|
||||
relative_path.append(" ");
|
||||
if(relative_path.length() > truncateTreshold) {
|
||||
relative_path.truncate(truncateTreshold);
|
||||
relative_path.append(" ...");
|
||||
}
|
||||
ui->book4Btn->setText(relative_path);
|
||||
existing_recent_books = true;
|
||||
}
|
||||
|
@ -1077,3 +1088,15 @@ void MainWindow::on_libraryButton_clicked()
|
|||
void MainWindow::resetFullWindow() {
|
||||
resetWindow(true);
|
||||
}
|
||||
|
||||
void MainWindow::setRecentBooksLabelsTruncateTreshold() {
|
||||
if(readFile("/opt/inkbox_device") == "n705\n" or readFile("/opt/inkbox_device") == "n905b\n" or readFile("/opt/inkbox_device") == "n905c\n") {
|
||||
truncateTreshold = 12;
|
||||
}
|
||||
else if(readFile("/opt/inkbox_device") == "n613\n" or readFile("/opt/inkbox_device") == "n873\n"){
|
||||
truncateTreshold = 20;
|
||||
}
|
||||
else {
|
||||
truncateTreshold = 12;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,6 +43,7 @@ public:
|
|||
float wifiIconHeight;
|
||||
float sW;
|
||||
float sH;
|
||||
int truncateTreshold;
|
||||
|
||||
bool existing_recent_books = false;
|
||||
bool reboot_after_update = false;
|
||||
|
@ -92,6 +93,7 @@ private slots:
|
|||
void on_libraryButton_clicked();
|
||||
void resetWindow(bool resetStackedWidget);
|
||||
void resetFullWindow();
|
||||
void setRecentBooksLabelsTruncateTreshold();
|
||||
|
||||
private:
|
||||
Ui::MainWindow * ui;
|
||||
|
|
19
reader.cpp
19
reader.cpp
|
@ -1093,13 +1093,23 @@ void reader::on_optionsBtn_clicked()
|
|||
{
|
||||
if(menubar_shown == true) {
|
||||
menubar_hide();
|
||||
ui->optionsBtn->setStyleSheet("background: white; color: black");
|
||||
if(readFile("/opt/inkbox_device") == "n873\n") {
|
||||
ui->optionsBtn->setStyleSheet("background: white; color: black; padding: 13.5px");
|
||||
}
|
||||
else {
|
||||
ui->optionsBtn->setStyleSheet("background: white; color: black");
|
||||
}
|
||||
this->repaint();
|
||||
menubar_shown = false;
|
||||
}
|
||||
else {
|
||||
menubar_show();
|
||||
ui->optionsBtn->setStyleSheet("background: black; color: white");
|
||||
if(readFile("/opt/inkbox_device") == "n873\n") {
|
||||
ui->optionsBtn->setStyleSheet("background: black; color: white; padding: 13.5px");
|
||||
}
|
||||
else {
|
||||
ui->optionsBtn->setStyleSheet("background: black; color: white");
|
||||
}
|
||||
this->repaint();
|
||||
menubar_shown = true;
|
||||
}
|
||||
|
@ -1431,6 +1441,7 @@ void reader::wordwidget_show() {
|
|||
|
||||
void reader::wordwidget_hide() {
|
||||
ui->wordWidget->setVisible(false);
|
||||
ui->optionsBtn->setStyleSheet("background: white; color: black");
|
||||
ui->optionsBtn->show();
|
||||
ui->line->show();
|
||||
wordwidgetLock = false;
|
||||
|
@ -2070,11 +2081,11 @@ bool reader::pdf_file_match(QString file) {
|
|||
}
|
||||
|
||||
bool reader::image_file_match(QString file) {
|
||||
if(file.right(3) == "png" or file.right(3) == "jpg" or file.right(3) == "bmp" or file.right(3) == "tif") {
|
||||
if(file.right(3) == "png" or file.right(3) == "PNG" or file.right(3) == "jpg" or file.right(3) == "JPG" or file.right(3) == "bmp" or file.right(3) == "BMP" or file.right(3) == "tif" or file.right(3) == "TIF") {
|
||||
string_writeconfig("/inkbox/bookIsImage", "true");
|
||||
return true;
|
||||
}
|
||||
else if(file.right(4) == "jpeg" or file.right(4) == "tiff") {
|
||||
else if(file.right(4) == "jpeg" or file.right(4) == "JPEG" or file.right(4) == "tiff" or file.right(4) == "TIFF") {
|
||||
string_writeconfig("/inkbox/bookIsImage", "true");
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -40,7 +40,6 @@ void searchResultsWidget::setListViewContents(QStringList searchResults) {
|
|||
void searchResultsWidget::on_openBtn_clicked()
|
||||
{
|
||||
if(libraryResults == true) {
|
||||
qDebug() << "Got there";
|
||||
index = ui->listView->currentIndex();
|
||||
itemText = index.data(Qt::DisplayRole).toString();
|
||||
if(!itemText.isEmpty()) {
|
||||
|
|
Loading…
Reference in a new issue