Progress in implementing "Open" function from search

This commit is contained in:
Nicolas Mailloux 2021-09-04 23:46:47 -04:00
parent f670ba207b
commit 34252c01bc
9 changed files with 90 additions and 6 deletions

View file

@ -23,6 +23,7 @@ namespace global {
inline bool batteryAlertLock; inline bool batteryAlertLock;
} }
namespace reader { namespace reader {
inline QString bookFile;
inline int pageNumber; inline int pageNumber;
inline int bookNumber; inline int bookNumber;
inline bool skipOpenDialog; inline bool skipOpenDialog;

View file

@ -39,6 +39,19 @@ generalDialog::generalDialog(QWidget *parent) :
ui->bodyLabel->setStyleSheet("font-size: 9pt"); ui->bodyLabel->setStyleSheet("font-size: 9pt");
ui->searchComboBox->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("/inkbox/resetDialog") == true) {
if(checkconfig("/opt/inkbox_genuine") == true) { if(checkconfig("/opt/inkbox_genuine") == true) {
resetDialog = true; resetDialog = true;
@ -242,6 +255,7 @@ void generalDialog::on_okBtn_clicked()
if(global::keyboard::searchDialog == true) { if(global::keyboard::searchDialog == true) {
if(global::keyboard::keyboardText != "") { if(global::keyboard::keyboardText != "") {
if(ui->searchComboBox->currentText() == "Dictionary") { if(ui->searchComboBox->currentText() == "Dictionary") {
string_writeconfig("/inkbox/searchComboBoxFunction", "Dictionary");
for(int i = ui->mainStackedWidget->count(); i >= 0; i--) { for(int i = ui->mainStackedWidget->count(); i >= 0; i--) {
QWidget * widget = ui->mainStackedWidget->widget(i); QWidget * widget = ui->mainStackedWidget->widget(i);
ui->mainStackedWidget->removeWidget(widget); ui->mainStackedWidget->removeWidget(widget);
@ -256,6 +270,7 @@ void generalDialog::on_okBtn_clicked()
ui->mainStackedWidget->insertWidget(1, dictionaryWidgetWindow); ui->mainStackedWidget->insertWidget(1, dictionaryWidgetWindow);
} }
else if(ui->searchComboBox->currentText() == "Local storage") { else if(ui->searchComboBox->currentText() == "Local storage") {
string_writeconfig("/inkbox/searchComboBoxFunction", "Local storage");
QString onboardPath; QString onboardPath;
QStringList storageSearchResults; QStringList storageSearchResults;
if(checkconfig("/opt/inkbox_genuine") == true) { if(checkconfig("/opt/inkbox_genuine") == true) {
@ -285,6 +300,9 @@ void generalDialog::on_okBtn_clicked()
ui->topStackedWidget->setVisible(false); ui->topStackedWidget->setVisible(false);
ui->stackedWidget->setVisible(false); ui->stackedWidget->setVisible(false);
searchResultsWidgetWindow = new searchResultsWidget(this); 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); searchResultsWidgetWindow->setListViewContents(storageSearchResults);
ui->mainStackedWidget->insertWidget(1, searchResultsWidgetWindow); ui->mainStackedWidget->insertWidget(1, searchResultsWidgetWindow);
} }
@ -459,3 +477,7 @@ void generalDialog::startOtaUpdate(bool wasDownloadSuccessful) {
} }
generalDialog::close(); generalDialog::close();
} }
void generalDialog::openBookFileNative(QString book) {
emit openBookFile(book);
}

View file

@ -54,6 +54,7 @@ private slots:
void refreshScreenNative(); void refreshScreenNative();
void connectToNetworkSlot(); void connectToNetworkSlot();
void startOtaUpdate(bool wasDownloadSuccessful); void startOtaUpdate(bool wasDownloadSuccessful);
void openBookFileNative(QString book);
private: private:
Ui::generalDialog *ui; Ui::generalDialog *ui;
@ -71,6 +72,7 @@ signals:
void updateWifiIcon(int mode); void updateWifiIcon(int mode);
void showToast(QString messageToDisplay); void showToast(QString messageToDisplay);
void closeIndefiniteToast(); void closeIndefiniteToast();
void openBookFile(QString book);
}; };
#endif // GENERALDIALOG_H #endif // GENERALDIALOG_H

View file

@ -861,6 +861,7 @@ void MainWindow::setupSearchDialog() {
generalDialogWindow->setAttribute(Qt::WA_DeleteOnClose); generalDialogWindow->setAttribute(Qt::WA_DeleteOnClose);
connect(generalDialogWindow, SIGNAL(refreshScreen()), SLOT(refreshScreen())); connect(generalDialogWindow, SIGNAL(refreshScreen()), SLOT(refreshScreen()));
connect(generalDialogWindow, SIGNAL(destroyed(QObject*)), SLOT(setupSearchDialog())); connect(generalDialogWindow, SIGNAL(destroyed(QObject*)), SLOT(setupSearchDialog()));
connect(generalDialogWindow, SIGNAL(openBookFile(QString)), SLOT(openBookFile(QString)));
generalDialogWindow->show(); generalDialogWindow->show();
} }
else { else {
@ -996,3 +997,11 @@ void MainWindow::launchOtaUpdater() {
connect(otaManagerWindow, SIGNAL(canOtaUpdate(bool)), SLOT(openUpdateDialogOTA(bool))); connect(otaManagerWindow, SIGNAL(canOtaUpdate(bool)), SLOT(openUpdateDialogOTA(bool)));
otaManagerWindow->setAttribute(Qt::WA_DeleteOnClose); 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();
}

View file

@ -85,6 +85,7 @@ private slots:
void closeIndefiniteToast(); void closeIndefiniteToast();
void openUpdateDialogOTA(bool open); void openUpdateDialogOTA(bool open);
void launchOtaUpdater(); void launchOtaUpdater();
void openBookFile(QString book);
private: private:
Ui::MainWindow *ui; Ui::MainWindow *ui;

View file

@ -117,6 +117,10 @@ reader::reader(QWidget *parent) :
string_writeconfig("/tmp/suspendBook", "false"); string_writeconfig("/tmp/suspendBook", "false");
book_file = "/inkbox/book/book.txt"; book_file = "/inkbox/book/book.txt";
} }
else if(global::reader::bookFile.isEmpty() == false) {
book_file = global::reader::bookFile;
global::reader::bookFile = "";
}
else { else {
if(global::reader::bookNumber == 1) { if(global::reader::bookNumber == 1) {
string_checkconfig(".config/08-recent_books/1"); string_checkconfig(".config/08-recent_books/1");

View file

@ -1,16 +1,18 @@
#include "searchresultswidget.h" #include "searchresultswidget.h"
#include "ui_searchresultswidget.h" #include "ui_searchresultswidget.h"
#include <QDebug> #include <QMessageBox>
searchResultsWidget::searchResultsWidget(QWidget *parent) : searchResultsWidget::searchResultsWidget(QWidget *parent) :
QWidget(parent), QWidget(parent),
ui(new Ui::searchResultsWidget) ui(new Ui::searchResultsWidget)
{ {
ui->setupUi(this); ui->setupUi(this);
ui->listView->setStyleSheet("font-size: 9pt"); ui->listView->setStyleSheet("font-size: 10pt");
ui->backBtn->setProperty("type", "borderless"); ui->backBtn->setProperty("type", "borderless");
ui->backBtn->setStyleSheet("font-size: 9pt; padding: 10px; font-weight: bold; background: lightGrey"); 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() searchResultsWidget::~searchResultsWidget()
@ -23,3 +25,23 @@ void searchResultsWidget::setListViewContents(QStringList searchResults) {
model->setStringList(searchResults); model->setStringList(searchResults);
ui->listView->setModel(model); 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();
}

View file

@ -16,9 +16,18 @@ public:
explicit searchResultsWidget(QWidget *parent = nullptr); explicit searchResultsWidget(QWidget *parent = nullptr);
~searchResultsWidget(); ~searchResultsWidget();
void setListViewContents(QStringList searchResults); void setListViewContents(QStringList searchResults);
QModelIndex index;
QString itemText;
private slots:
void on_openBtn_clicked();
void on_backBtn_clicked();
private: private:
Ui::searchResultsWidget *ui; Ui::searchResultsWidget *ui;
signals:
void openBookFile(QString book);
}; };
#endif // SEARCHRESULTSWIDGET_H #endif // SEARCHRESULTSWIDGET_H

View file

@ -48,6 +48,18 @@
</widget> </widget>
</item> </item>
<item row="2" column="0"> <item row="2" column="0">
<layout class="QGridLayout" name="gridLayout_2">
<property name="bottomMargin">
<number>0</number>
</property>
<item row="0" column="1">
<widget class="QPushButton" name="openBtn">
<property name="text">
<string>Open</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QPushButton" name="backBtn"> <widget class="QPushButton" name="backBtn">
<property name="text"> <property name="text">
<string>Back</string> <string>Back</string>
@ -57,6 +69,8 @@
</layout> </layout>
</item> </item>
</layout> </layout>
</item>
</layout>
</widget> </widget>
<resources/> <resources/>
<connections/> <connections/>