From 4b305738993beb1da3eaebee67329735c4c4162c Mon Sep 17 00:00:00 2001 From: Nicolas Mailloux Date: Mon, 27 Dec 2021 23:59:28 -0500 Subject: [PATCH] Basic search on online library implemented --- bookinfodialog.cpp | 7 +++++++ functions.h | 1 + generaldialog.cpp | 33 +++++++++++++++++++++++++++++++++ searchresultswidget.cpp | 20 +++++++++++++++++++- searchresultswidget.h | 3 +++ 5 files changed, 63 insertions(+), 1 deletion(-) diff --git a/bookinfodialog.cpp b/bookinfodialog.cpp index 8c0ea4e..c3dcfc4 100644 --- a/bookinfodialog.cpp +++ b/bookinfodialog.cpp @@ -9,6 +9,13 @@ bookInfoDialog::bookInfoDialog(QWidget *parent) : ui(new Ui::bookInfoDialog) { ui->setupUi(this); + + // Stylesheet + QFile stylesheetFile(":/resources/eink.qss"); + stylesheetFile.open(QFile::ReadOnly); + this->setStyleSheet(stylesheetFile.readAll()); + stylesheetFile.close(); + ui->closeBtn->setProperty("type", "borderless"); ui->closeBtn->setText(""); ui->closeBtn->setIcon(QIcon(":/resources/close.png")); diff --git a/functions.h b/functions.h index 93dc2a6..3585436 100644 --- a/functions.h +++ b/functions.h @@ -108,6 +108,7 @@ namespace global { inline int latestBookNumber; inline QString bookTitle; inline bool librarySearchDialog; + inline bool libraryResults; } inline QString systemInfoText; inline bool forbidOpenSearchDialog; diff --git a/generaldialog.cpp b/generaldialog.cpp index f975f0b..516b883 100644 --- a/generaldialog.cpp +++ b/generaldialog.cpp @@ -345,7 +345,40 @@ 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())); + searchResultsWidgetWindow->setListViewContents(searchResults); + ui->mainStackedWidget->insertWidget(1, searchResultsWidgetWindow); + break; + } + else { + global::toast::delay = 3000; + emit showToast("No results found"); + keyboardWidget->clearLineEdit(); + global::keyboard::keyboardText = ""; + break; + } + QFile::remove("/inkbox/gutenberg-search/search_done"); + } + } } else { ; diff --git a/searchresultswidget.cpp b/searchresultswidget.cpp index f13d846..59a818d 100644 --- a/searchresultswidget.cpp +++ b/searchresultswidget.cpp @@ -9,11 +9,17 @@ searchResultsWidget::searchResultsWidget(QWidget *parent) : ui(new Ui::searchResultsWidget) { ui->setupUi(this); + 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"); + + if(global::library::libraryResults == true) { + global::library::libraryResults = false; + libraryResults = true; + } } searchResultsWidget::~searchResultsWidget() @@ -29,8 +35,20 @@ void searchResultsWidget::setListViewContents(QStringList searchResults) { void searchResultsWidget::on_openBtn_clicked() { - if(global::library::librarySearchDialog == true) { + if(libraryResults == true) { + // Get currently selected row number + int selectedRow = ui->listView->currentIndex().row(); + // So that row 0 becomes row 1 + selectedRow = selectedRow++; + // TODO: Find book ID and pass it on to bookInfoDialog, then retrieve cover.jpg for display + + global::keyboard::searchDialog = false; + global::keyboard::keyboardDialog = false; + + bookInfoDialog * bookInfoDialogWindow = new bookInfoDialog(); + bookInfoDialogWindow->setAttribute(Qt::WA_DeleteOnClose); + bookInfoDialogWindow->show(); } else { index = ui->listView->currentIndex(); diff --git a/searchresultswidget.h b/searchresultswidget.h index 842a821..3a33808 100644 --- a/searchresultswidget.h +++ b/searchresultswidget.h @@ -3,6 +3,7 @@ #include #include +#include "bookinfodialog.h" namespace Ui { class searchResultsWidget; @@ -18,6 +19,7 @@ public: void setListViewContents(QStringList searchResults); QModelIndex index; QString itemText; + bool libraryResults; private slots: void on_openBtn_clicked(); @@ -25,6 +27,7 @@ private slots: private: Ui::searchResultsWidget *ui; + bookInfoDialog * bookInfoDialogWindow; signals: void openBookFile(QString book, bool relativePath);