2021-09-04 19:18:17 -07:00
|
|
|
#include "searchresultswidget.h"
|
|
|
|
#include "ui_searchresultswidget.h"
|
2021-09-05 07:06:56 -07:00
|
|
|
#include "functions.h"
|
2021-09-04 19:18:17 -07:00
|
|
|
|
2021-09-04 20:46:47 -07:00
|
|
|
#include <QMessageBox>
|
2021-09-04 19:18:17 -07:00
|
|
|
|
|
|
|
searchResultsWidget::searchResultsWidget(QWidget *parent) :
|
|
|
|
QWidget(parent),
|
|
|
|
ui(new Ui::searchResultsWidget)
|
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
2021-12-27 20:59:28 -08:00
|
|
|
|
2021-09-04 20:46:47 -07:00
|
|
|
ui->listView->setStyleSheet("font-size: 10pt");
|
2021-09-04 19:18:17 -07:00
|
|
|
ui->backBtn->setProperty("type", "borderless");
|
|
|
|
ui->backBtn->setStyleSheet("font-size: 9pt; padding: 10px; font-weight: bold; background: lightGrey");
|
2021-09-04 20:46:47 -07:00
|
|
|
ui->openBtn->setProperty("type", "borderless");
|
|
|
|
ui->openBtn->setStyleSheet("font-size: 9pt; padding: 10px; font-weight: bold; background: lightGrey");
|
2021-12-27 20:59:28 -08:00
|
|
|
|
|
|
|
if(global::library::libraryResults == true) {
|
|
|
|
global::library::libraryResults = false;
|
|
|
|
libraryResults = true;
|
|
|
|
}
|
2021-09-04 19:18:17 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
searchResultsWidget::~searchResultsWidget()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
|
|
|
void searchResultsWidget::setListViewContents(QStringList searchResults) {
|
|
|
|
QStringListModel * model = new QStringListModel(this);
|
|
|
|
model->setStringList(searchResults);
|
|
|
|
ui->listView->setModel(model);
|
|
|
|
}
|
2021-09-04 20:46:47 -07:00
|
|
|
|
|
|
|
void searchResultsWidget::on_openBtn_clicked()
|
|
|
|
{
|
2021-12-27 20:59:28 -08:00
|
|
|
if(libraryResults == true) {
|
|
|
|
// Get currently selected row number
|
|
|
|
int selectedRow = ui->listView->currentIndex().row();
|
|
|
|
// So that row 0 becomes row 1
|
2021-12-28 16:08:14 -08:00
|
|
|
selectedRow = selectedRow + 1;
|
|
|
|
QString selectedRowQstr = QString::number(selectedRow);
|
2021-12-27 20:59:28 -08:00
|
|
|
|
2021-12-28 16:08:14 -08:00
|
|
|
QString prog ("sed");
|
|
|
|
QStringList args;
|
|
|
|
args << "-n" << selectedRowQstr + "p" << "/inkbox/gutenberg-search/search_results_ids";
|
|
|
|
QProcess *proc = new QProcess();
|
|
|
|
proc->start(prog, args);
|
|
|
|
proc->waitForFinished();
|
|
|
|
QString bookIdQstr = proc->readAllStandardOutput();
|
|
|
|
proc->deleteLater();
|
2021-12-27 20:59:28 -08:00
|
|
|
|
2021-12-28 16:08:14 -08:00
|
|
|
unsigned long bookId = bookIdQstr.toULong();
|
|
|
|
global::library::bookId = bookId;
|
|
|
|
|
|
|
|
index = ui->listView->currentIndex();
|
|
|
|
itemText = index.data(Qt::DisplayRole).toString();
|
|
|
|
global::library::bookTitle = itemText;
|
2021-12-27 12:04:39 -08:00
|
|
|
|
2021-12-27 20:59:28 -08:00
|
|
|
bookInfoDialog * bookInfoDialogWindow = new bookInfoDialog();
|
|
|
|
bookInfoDialogWindow->setAttribute(Qt::WA_DeleteOnClose);
|
|
|
|
bookInfoDialogWindow->show();
|
2021-12-28 16:08:14 -08:00
|
|
|
|
|
|
|
global::keyboard::searchDialog = false;
|
|
|
|
global::keyboard::keyboardDialog = false;
|
|
|
|
searchResultsWidget::close();
|
2021-09-04 20:46:47 -07:00
|
|
|
}
|
|
|
|
else {
|
2021-12-27 12:04:39 -08:00
|
|
|
index = ui->listView->currentIndex();
|
|
|
|
itemText = index.data(Qt::DisplayRole).toString();
|
|
|
|
if(!itemText.isEmpty()) {
|
|
|
|
emit openBookFile(itemText, true);
|
|
|
|
global::keyboard::searchDialog = false;
|
|
|
|
global::keyboard::keyboardDialog = false;
|
|
|
|
searchResultsWidget::close();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
QMessageBox::critical(this, tr("Invalid argument"), tr("Please select a search result."));
|
|
|
|
}
|
2021-09-04 20:46:47 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void searchResultsWidget::on_backBtn_clicked()
|
|
|
|
{
|
2021-09-05 07:06:56 -07:00
|
|
|
global::forbidOpenSearchDialog = false;
|
2021-09-04 20:46:47 -07:00
|
|
|
searchResultsWidget::close();
|
|
|
|
}
|
|
|
|
|