diff --git a/functions.h b/functions.h index aa35c45..ecb0cfa 100644 --- a/functions.h +++ b/functions.h @@ -23,6 +23,7 @@ namespace global { inline bool batteryAlertLock; } namespace reader { + inline QString bookFile; inline int pageNumber; inline int bookNumber; inline bool skipOpenDialog; diff --git a/generaldialog.cpp b/generaldialog.cpp index 5c8cdfb..1a68bd6 100644 --- a/generaldialog.cpp +++ b/generaldialog.cpp @@ -39,6 +39,19 @@ generalDialog::generalDialog(QWidget *parent) : ui->bodyLabel->setStyleSheet("font-size: 9pt"); ui->searchComboBox->setStyleSheet("font-size: 9pt"); + if(QFile::exists("/inkbox/searchComboBoxFunction") == true) { + string_checkconfig_ro("/inkbox/searchComboBoxFunction"); + if(checkconfig_str_val == "Dictionary") { + ui->searchComboBox->setCurrentIndex(0); + } + else if(checkconfig_str_val == "Local storage") { + ui->searchComboBox->setCurrentIndex(1); + } + else { + ui->searchComboBox->setCurrentIndex(0); + } + } + if(checkconfig("/inkbox/resetDialog") == true) { if(checkconfig("/opt/inkbox_genuine") == true) { resetDialog = true; @@ -242,6 +255,7 @@ void generalDialog::on_okBtn_clicked() if(global::keyboard::searchDialog == true) { if(global::keyboard::keyboardText != "") { if(ui->searchComboBox->currentText() == "Dictionary") { + string_writeconfig("/inkbox/searchComboBoxFunction", "Dictionary"); for(int i = ui->mainStackedWidget->count(); i >= 0; i--) { QWidget * widget = ui->mainStackedWidget->widget(i); ui->mainStackedWidget->removeWidget(widget); @@ -256,6 +270,7 @@ void generalDialog::on_okBtn_clicked() ui->mainStackedWidget->insertWidget(1, dictionaryWidgetWindow); } else if(ui->searchComboBox->currentText() == "Local storage") { + string_writeconfig("/inkbox/searchComboBoxFunction", "Local storage"); QString onboardPath; QStringList storageSearchResults; if(checkconfig("/opt/inkbox_genuine") == true) { @@ -285,6 +300,9 @@ void generalDialog::on_okBtn_clicked() ui->topStackedWidget->setVisible(false); ui->stackedWidget->setVisible(false); searchResultsWidgetWindow = new searchResultsWidget(this); + searchResultsWidgetWindow->setAttribute(Qt::WA_DeleteOnClose); + connect(searchResultsWidgetWindow, SIGNAL(destroyed(QObject*)), SLOT(restartSearchDialog())); + connect(searchResultsWidgetWindow, SIGNAL(openBookFile(QString)), SLOT(openBookFileNative(QString))); searchResultsWidgetWindow->setListViewContents(storageSearchResults); ui->mainStackedWidget->insertWidget(1, searchResultsWidgetWindow); } @@ -459,3 +477,7 @@ void generalDialog::startOtaUpdate(bool wasDownloadSuccessful) { } generalDialog::close(); } + +void generalDialog::openBookFileNative(QString book) { + emit openBookFile(book); +} diff --git a/generaldialog.h b/generaldialog.h index 3e8e335..c03c192 100644 --- a/generaldialog.h +++ b/generaldialog.h @@ -54,6 +54,7 @@ private slots: void refreshScreenNative(); void connectToNetworkSlot(); void startOtaUpdate(bool wasDownloadSuccessful); + void openBookFileNative(QString book); private: Ui::generalDialog *ui; @@ -71,6 +72,7 @@ signals: void updateWifiIcon(int mode); void showToast(QString messageToDisplay); void closeIndefiniteToast(); + void openBookFile(QString book); }; #endif // GENERALDIALOG_H diff --git a/mainwindow.cpp b/mainwindow.cpp index c5f34b9..b062f06 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -861,6 +861,7 @@ void MainWindow::setupSearchDialog() { generalDialogWindow->setAttribute(Qt::WA_DeleteOnClose); connect(generalDialogWindow, SIGNAL(refreshScreen()), SLOT(refreshScreen())); connect(generalDialogWindow, SIGNAL(destroyed(QObject*)), SLOT(setupSearchDialog())); + connect(generalDialogWindow, SIGNAL(openBookFile(QString)), SLOT(openBookFile(QString))); generalDialogWindow->show(); } else { @@ -996,3 +997,11 @@ void MainWindow::launchOtaUpdater() { connect(otaManagerWindow, SIGNAL(canOtaUpdate(bool)), SLOT(openUpdateDialogOTA(bool))); otaManagerWindow->setAttribute(Qt::WA_DeleteOnClose); } + +void MainWindow::openBookFile(QString book) { + global::reader::skipOpenDialog = true; + global::reader::bookFile = book; + readerWindow = new reader(); + readerWindow->setAttribute(Qt::WA_DeleteOnClose); + readerWindow->showFullScreen(); +} diff --git a/mainwindow.h b/mainwindow.h index c2c80b7..6c4e05d 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -85,6 +85,7 @@ private slots: void closeIndefiniteToast(); void openUpdateDialogOTA(bool open); void launchOtaUpdater(); + void openBookFile(QString book); private: Ui::MainWindow *ui; diff --git a/reader.cpp b/reader.cpp index da5a1d1..f8bbd66 100644 --- a/reader.cpp +++ b/reader.cpp @@ -117,6 +117,10 @@ reader::reader(QWidget *parent) : string_writeconfig("/tmp/suspendBook", "false"); book_file = "/inkbox/book/book.txt"; } + else if(global::reader::bookFile.isEmpty() == false) { + book_file = global::reader::bookFile; + global::reader::bookFile = ""; + } else { if(global::reader::bookNumber == 1) { string_checkconfig(".config/08-recent_books/1"); diff --git a/searchresultswidget.cpp b/searchresultswidget.cpp index 685487e..f5a6458 100644 --- a/searchresultswidget.cpp +++ b/searchresultswidget.cpp @@ -1,16 +1,18 @@ #include "searchresultswidget.h" #include "ui_searchresultswidget.h" -#include +#include searchResultsWidget::searchResultsWidget(QWidget *parent) : QWidget(parent), ui(new Ui::searchResultsWidget) { ui->setupUi(this); - ui->listView->setStyleSheet("font-size: 9pt"); + ui->listView->setStyleSheet("font-size: 10pt"); ui->backBtn->setProperty("type", "borderless"); ui->backBtn->setStyleSheet("font-size: 9pt; padding: 10px; font-weight: bold; background: lightGrey"); + ui->openBtn->setProperty("type", "borderless"); + ui->openBtn->setStyleSheet("font-size: 9pt; padding: 10px; font-weight: bold; background: lightGrey"); } searchResultsWidget::~searchResultsWidget() @@ -23,3 +25,23 @@ void searchResultsWidget::setListViewContents(QStringList searchResults) { model->setStringList(searchResults); ui->listView->setModel(model); } + +void searchResultsWidget::on_openBtn_clicked() +{ + index = ui->listView->currentIndex(); + itemText = index.data(Qt::DisplayRole).toString(); + if(!itemText.isEmpty()) { + emit openBookFile(itemText); + searchResultsWidget::close(); + } + else { + QMessageBox::critical(this, tr("Invalid argument"), tr("Please select a search result.")); + } +} + + +void searchResultsWidget::on_backBtn_clicked() +{ + searchResultsWidget::close(); +} + diff --git a/searchresultswidget.h b/searchresultswidget.h index 83c4d2a..0b52098 100644 --- a/searchresultswidget.h +++ b/searchresultswidget.h @@ -16,9 +16,18 @@ public: explicit searchResultsWidget(QWidget *parent = nullptr); ~searchResultsWidget(); void setListViewContents(QStringList searchResults); + QModelIndex index; + QString itemText; + +private slots: + void on_openBtn_clicked(); + void on_backBtn_clicked(); private: Ui::searchResultsWidget *ui; + +signals: + void openBookFile(QString book); }; #endif // SEARCHRESULTSWIDGET_H diff --git a/searchresultswidget.ui b/searchresultswidget.ui index 50f7456..2808698 100644 --- a/searchresultswidget.ui +++ b/searchresultswidget.ui @@ -48,11 +48,25 @@ - - - Back + + + 0 - + + + + Open + + + + + + + Back + + + +