2018-08-12 16:45:39 +02:00
|
|
|
#include <poppler-qt5.h>
|
|
|
|
#include <QLabel>
|
|
|
|
#include <QtDebug>
|
|
|
|
#include <QFileInfo>
|
|
|
|
#include <QDesktopServices>
|
|
|
|
#include <QUrl>
|
|
|
|
#include <QClipboard>
|
2018-09-02 20:30:52 +02:00
|
|
|
#include <QtGlobal>
|
2018-08-12 16:45:39 +02:00
|
|
|
#include <QSettings>
|
|
|
|
#include <QDateTime>
|
2018-08-31 20:08:23 +02:00
|
|
|
#include <QProcess>
|
2018-09-02 20:30:52 +02:00
|
|
|
#include <QComboBox>
|
2019-04-27 21:24:53 +02:00
|
|
|
#include <QtConcurrent/QtConcurrent>
|
2022-04-15 21:00:39 +02:00
|
|
|
#include <QMessageBox>
|
2018-08-12 16:45:39 +02:00
|
|
|
#include "mainwindow.h"
|
|
|
|
#include "ui_mainwindow.h"
|
|
|
|
#include "clicklabel.h"
|
2019-04-25 10:27:54 +02:00
|
|
|
#include "../shared/sqlitesearch.h"
|
2021-06-12 14:59:58 +02:00
|
|
|
#include "../shared/looqsgeneralexception.h"
|
2020-05-24 15:36:27 +02:00
|
|
|
#include "../shared/common.h"
|
|
|
|
|
2021-09-28 21:44:09 +02:00
|
|
|
MainWindow::MainWindow(QWidget *parent, IPCClient &client) : QMainWindow(parent), ui(new Ui::MainWindow)
|
2018-08-12 16:45:39 +02:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
2021-03-07 21:09:38 +01:00
|
|
|
setWindowTitle(QCoreApplication::applicationName());
|
2021-09-28 21:44:09 +02:00
|
|
|
this->ipcClient = &client;
|
2019-08-26 09:20:21 +02:00
|
|
|
QSettings settings;
|
2018-08-12 16:45:39 +02:00
|
|
|
|
2022-04-14 15:04:16 +02:00
|
|
|
this->dbFactory = new DatabaseFactory(Common::databasePath());
|
|
|
|
|
|
|
|
db = this->dbFactory->forCurrentThread();
|
|
|
|
this->dbService = new SqliteDbService(*this->dbFactory);
|
|
|
|
|
|
|
|
indexer = new Indexer(*(this->dbService));
|
|
|
|
indexer->setParent(this);
|
2018-08-12 16:45:39 +02:00
|
|
|
connectSignals();
|
|
|
|
ui->treeResultsList->setContextMenuPolicy(Qt::ContextMenuPolicy::CustomContextMenu);
|
|
|
|
ui->tabWidget->setCurrentIndex(0);
|
2018-08-31 20:40:07 +02:00
|
|
|
ui->statusBar->addWidget(ui->lblSearchResults);
|
2022-01-03 23:02:21 +01:00
|
|
|
ui->statusBar->addWidget(ui->previewProcessBar);
|
|
|
|
ui->previewProcessBar->hide();
|
2019-04-25 10:27:54 +02:00
|
|
|
ui->comboScale->setCurrentText(settings.value("currentScale").toString());
|
2022-01-03 23:02:21 +01:00
|
|
|
previewsPerPage = settings.value("previewsPerPage", 20).toInt();
|
|
|
|
ui->spinPreviewPage->setMinimum(1);
|
2022-04-15 22:57:15 +02:00
|
|
|
|
|
|
|
QStringList indexPaths = settings.value("indexPaths").toStringList();
|
|
|
|
ui->lstPaths->addItems(indexPaths);
|
2018-08-12 16:45:39 +02:00
|
|
|
}
|
|
|
|
|
2022-04-15 21:00:39 +02:00
|
|
|
void MainWindow::addPathToIndex()
|
|
|
|
{
|
|
|
|
QString path = this->ui->txtPathScanAdd->text();
|
|
|
|
QFileInfo fileInfo{path};
|
|
|
|
if(!fileInfo.exists(path))
|
|
|
|
{
|
|
|
|
QMessageBox::critical(this, "Invalid path", "Path does not seem to exist");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if(!fileInfo.isReadable())
|
|
|
|
{
|
|
|
|
QMessageBox::critical(this, "Invalid path", "Path cannot be read");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this->ui->lstPaths->addItem(path);
|
|
|
|
this->ui->txtPathScanAdd->clear();
|
|
|
|
}
|
2018-08-12 16:45:39 +02:00
|
|
|
void MainWindow::connectSignals()
|
|
|
|
{
|
|
|
|
connect(ui->txtSearch, &QLineEdit::returnPressed, this, &MainWindow::lineEditReturnPressed);
|
2019-04-27 21:24:53 +02:00
|
|
|
connect(&searchWatcher, &QFutureWatcher<SearchResult>::finished, this,
|
|
|
|
[&]
|
|
|
|
{
|
2019-04-29 23:05:51 +02:00
|
|
|
try
|
|
|
|
{
|
2020-06-06 23:18:33 +02:00
|
|
|
this->ui->txtSearch->setEnabled(true);
|
2019-04-29 23:05:51 +02:00
|
|
|
auto results = searchWatcher.future().result();
|
|
|
|
handleSearchResults(results);
|
|
|
|
}
|
2021-06-12 14:59:58 +02:00
|
|
|
catch(LooqsGeneralException &e)
|
2019-04-29 23:05:51 +02:00
|
|
|
{
|
|
|
|
handleSearchError(e.message);
|
|
|
|
}
|
2019-04-27 21:24:53 +02:00
|
|
|
});
|
2022-01-03 23:02:21 +01:00
|
|
|
connect(&previewWorkerWatcher, &QFutureWatcher<QSharedPointer<PreviewResult>>::resultReadyAt, this,
|
|
|
|
[&](int index) { previewReceived(previewWorkerWatcher.resultAt(index)); });
|
|
|
|
connect(&previewWorkerWatcher, &QFutureWatcher<QSharedPointer<PreviewResult>>::progressValueChanged,
|
|
|
|
ui->previewProcessBar, &QProgressBar::setValue);
|
2022-04-17 20:52:07 +02:00
|
|
|
connect(&previewWorkerWatcher, &QFutureWatcher<QSharedPointer<PreviewResult>>::started, this,
|
|
|
|
[&] { ui->indexerTab->setEnabled(false); });
|
|
|
|
|
|
|
|
connect(&previewWorkerWatcher, &QFutureWatcher<QSharedPointer<PreviewResult>>::finished, this,
|
|
|
|
[&] { ui->indexerTab->setEnabled(true); });
|
|
|
|
|
2018-08-12 16:45:39 +02:00
|
|
|
connect(ui->treeResultsList, &QTreeWidget::itemActivated, this, &MainWindow::treeSearchItemActivated);
|
|
|
|
connect(ui->treeResultsList, &QTreeWidget::customContextMenuRequested, this,
|
|
|
|
&MainWindow::showSearchResultsContextMenu);
|
|
|
|
connect(ui->tabWidget, &QTabWidget::currentChanged, this, &MainWindow::tabChanged);
|
2021-06-12 23:01:14 +02:00
|
|
|
connect(ui->comboScale, qOverload<int>(&QComboBox::currentIndexChanged), this, &MainWindow::comboScaleChanged);
|
2022-01-03 23:02:21 +01:00
|
|
|
connect(ui->spinPreviewPage, qOverload<int>(&QSpinBox::valueChanged), this,
|
|
|
|
&MainWindow::spinPreviewPageValueChanged);
|
2022-04-14 15:04:16 +02:00
|
|
|
|
2022-04-15 21:00:39 +02:00
|
|
|
connect(ui->btnAddPath, &QPushButton::clicked, this, &MainWindow::addPathToIndex);
|
|
|
|
connect(ui->txtPathScanAdd, &QLineEdit::returnPressed, this, &MainWindow::addPathToIndex);
|
2022-04-14 15:04:16 +02:00
|
|
|
connect(ui->btnStartIndexing, &QPushButton::clicked, this, &MainWindow::startIndexing);
|
|
|
|
|
|
|
|
connect(this->indexer, &Indexer::pathsCountChanged, this,
|
|
|
|
[&](int number)
|
|
|
|
{
|
|
|
|
ui->lblSearchResults->setText("Found paths: " + QString::number(number));
|
|
|
|
ui->lblPathsFoundValue->setText(QString::number(number));
|
|
|
|
ui->previewProcessBar->setMaximum(number);
|
|
|
|
});
|
|
|
|
connect(this->indexer, &Indexer::indexProgress, this,
|
|
|
|
|
|
|
|
[&](int number, unsigned int added, unsigned int skipped, unsigned int failed, unsigned int totalCount)
|
|
|
|
{
|
|
|
|
ui->lblSearchResults->setText("Processed " + QString::number(number) + " files");
|
|
|
|
ui->previewProcessBar->setValue(number);
|
|
|
|
ui->previewProcessBar->setMaximum(totalCount);
|
|
|
|
ui->lblAddedValue->setText(QString::number(added));
|
|
|
|
ui->lblSkippedValue->setText(QString::number(skipped));
|
|
|
|
ui->lblFailedValue->setText(QString::number(failed));
|
|
|
|
});
|
|
|
|
|
|
|
|
connect(this->indexer, &Indexer::finished, this, &MainWindow::finishIndexing);
|
2022-04-15 21:05:00 +02:00
|
|
|
|
|
|
|
connect(ui->lstPaths->selectionModel(), &QItemSelectionModel::selectionChanged, this,
|
|
|
|
[&](const QItemSelection &selected, const QItemSelection &deselected)
|
|
|
|
{ ui->btnDeletePath->setEnabled(this->ui->lstPaths->selectedItems().count() > 0); });
|
|
|
|
|
|
|
|
connect(ui->btnDeletePath, &QPushButton::clicked, this, [&] { qDeleteAll(ui->lstPaths->selectedItems()); });
|
2019-08-26 09:20:21 +02:00
|
|
|
}
|
|
|
|
|
2022-01-03 23:02:21 +01:00
|
|
|
void MainWindow::spinPreviewPageValueChanged(int val)
|
2019-08-26 09:20:21 +02:00
|
|
|
{
|
2022-01-03 23:02:21 +01:00
|
|
|
makePreviews(val);
|
2018-08-12 16:45:39 +02:00
|
|
|
}
|
|
|
|
|
2022-04-14 15:04:16 +02:00
|
|
|
void MainWindow::startIndexing()
|
|
|
|
{
|
2022-04-15 21:06:19 +02:00
|
|
|
if(this->indexer->isRunning())
|
|
|
|
{
|
|
|
|
ui->btnStartIndexing->setEnabled(false);
|
|
|
|
ui->btnStartIndexing->setText("Start indexing");
|
|
|
|
this->indexer->requestCancellation();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ui->previewsTab->setEnabled(false);
|
|
|
|
ui->resultsTab->setEnabled(false);
|
2022-04-14 15:04:16 +02:00
|
|
|
ui->txtPathScanAdd->setEnabled(false);
|
|
|
|
ui->txtSearch->setEnabled(false);
|
|
|
|
ui->previewProcessBar->setValue(0);
|
2022-04-17 20:52:07 +02:00
|
|
|
ui->previewProcessBar->setVisible(true);
|
2022-04-14 15:04:16 +02:00
|
|
|
|
|
|
|
QVector<QString> paths;
|
2022-04-15 22:57:15 +02:00
|
|
|
QStringList pathSettingsValue;
|
2022-04-14 15:04:16 +02:00
|
|
|
for(int i = 0; i < ui->lstPaths->count(); i++)
|
|
|
|
{
|
2022-04-15 22:57:15 +02:00
|
|
|
QString path = ui->lstPaths->item(i)->text();
|
|
|
|
paths.append(path);
|
|
|
|
pathSettingsValue.append(path);
|
2022-04-14 15:04:16 +02:00
|
|
|
}
|
|
|
|
this->indexer->setTargetPaths(paths);
|
|
|
|
this->indexer->beginIndexing();
|
2022-04-15 22:57:15 +02:00
|
|
|
QSettings settings;
|
|
|
|
settings.setValue("indexPaths", pathSettingsValue);
|
2022-04-15 21:06:19 +02:00
|
|
|
ui->btnStartIndexing->setText("Stop indexing");
|
2022-04-14 15:04:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::finishIndexing()
|
|
|
|
{
|
|
|
|
IndexResult result = this->indexer->getResult();
|
|
|
|
|
|
|
|
ui->lblSearchResults->setText("Indexing finished");
|
|
|
|
ui->previewProcessBar->setValue(ui->previewProcessBar->maximum());
|
|
|
|
ui->lblFailedValue->setText(QString::number(result.erroredPaths));
|
|
|
|
ui->lblSkippedValue->setText(QString::number(result.skippedPaths));
|
|
|
|
ui->lblAddedValue->setText(QString::number(result.addedPaths));
|
2022-04-15 21:06:19 +02:00
|
|
|
ui->btnStartIndexing->setEnabled(true);
|
|
|
|
ui->btnStartIndexing->setText("Start indexing");
|
2022-04-15 22:56:11 +02:00
|
|
|
ui->previewsTab->setEnabled(true);
|
|
|
|
ui->resultsTab->setEnabled(true);
|
|
|
|
ui->txtPathScanAdd->setEnabled(true);
|
|
|
|
ui->txtSearch->setEnabled(true);
|
2022-04-14 15:04:16 +02:00
|
|
|
}
|
|
|
|
|
2021-06-12 23:01:14 +02:00
|
|
|
void MainWindow::comboScaleChanged(int i)
|
2018-09-02 20:30:52 +02:00
|
|
|
{
|
2019-04-25 10:27:54 +02:00
|
|
|
QSettings scaleSetting;
|
|
|
|
scaleSetting.setValue("currentScale", ui->comboScale->currentText());
|
2022-01-03 23:02:21 +01:00
|
|
|
makePreviews(ui->spinPreviewPage->value());
|
2018-09-02 20:30:52 +02:00
|
|
|
}
|
2022-04-14 15:04:16 +02:00
|
|
|
|
2022-01-03 23:02:21 +01:00
|
|
|
bool MainWindow::previewTabActive()
|
2018-08-12 16:45:39 +02:00
|
|
|
{
|
|
|
|
return ui->tabWidget->currentIndex() == 1;
|
|
|
|
}
|
|
|
|
|
2022-04-14 15:04:16 +02:00
|
|
|
bool MainWindow::indexerTabActive()
|
|
|
|
{
|
|
|
|
return ui->tabWidget->currentIndex() == 2;
|
|
|
|
}
|
|
|
|
|
2018-12-29 20:21:13 +01:00
|
|
|
void MainWindow::keyPressEvent(QKeyEvent *event)
|
|
|
|
{
|
|
|
|
bool quit =
|
|
|
|
((event->modifiers() & Qt::ControlModifier && event->key() == Qt::Key_Q) || event->key() == Qt::Key_Escape);
|
|
|
|
if(quit)
|
|
|
|
{
|
|
|
|
qApp->quit();
|
|
|
|
}
|
|
|
|
|
|
|
|
if(event->modifiers() & Qt::ControlModifier)
|
|
|
|
{
|
|
|
|
|
|
|
|
if(event->key() == Qt::Key_L)
|
|
|
|
{
|
|
|
|
ui->txtSearch->setFocus();
|
|
|
|
ui->txtSearch->selectAll();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
QWidget::keyPressEvent(event);
|
|
|
|
}
|
|
|
|
|
2018-08-12 16:45:39 +02:00
|
|
|
void MainWindow::tabChanged()
|
|
|
|
{
|
2022-04-17 20:52:07 +02:00
|
|
|
if(ui->tabWidget->currentIndex() == 0)
|
2018-08-12 16:45:39 +02:00
|
|
|
{
|
2022-04-17 20:52:07 +02:00
|
|
|
ui->previewProcessBar->hide();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if(ui->previewProcessBar->value() > 0)
|
2018-08-31 20:40:07 +02:00
|
|
|
{
|
2022-04-17 20:52:07 +02:00
|
|
|
ui->previewProcessBar->show();
|
2018-08-31 20:40:07 +02:00
|
|
|
}
|
|
|
|
}
|
2022-04-17 20:52:07 +02:00
|
|
|
if(previewTabActive())
|
2018-08-31 20:40:07 +02:00
|
|
|
{
|
2022-04-17 20:52:07 +02:00
|
|
|
if(previewDirty)
|
|
|
|
{
|
|
|
|
makePreviews(ui->spinPreviewPage->value());
|
|
|
|
}
|
2018-08-12 16:45:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-03 23:02:21 +01:00
|
|
|
void MainWindow::previewReceived(QSharedPointer<PreviewResult> preview)
|
2018-08-12 16:45:39 +02:00
|
|
|
{
|
2022-01-03 23:02:21 +01:00
|
|
|
if(preview->hasPreview())
|
2019-04-30 14:13:10 +02:00
|
|
|
{
|
2022-01-03 23:02:21 +01:00
|
|
|
QString docPath = preview->getDocumentPath();
|
|
|
|
auto previewPage = preview->getPage();
|
|
|
|
|
|
|
|
ClickLabel *label = dynamic_cast<ClickLabel *>(preview->createPreviewWidget());
|
2019-04-30 14:13:10 +02:00
|
|
|
ui->scrollAreaWidgetContents->layout()->addWidget(label);
|
2021-09-28 21:44:09 +02:00
|
|
|
connect(label, &ClickLabel::leftClick, [this, docPath, previewPage]() { ipcDocOpen(docPath, previewPage); });
|
2021-03-27 17:58:38 +01:00
|
|
|
connect(label, &ClickLabel::rightClick,
|
|
|
|
[this, docPath, previewPage]()
|
|
|
|
{
|
|
|
|
QFileInfo fileInfo{docPath};
|
|
|
|
QMenu menu("labeRightClick", this);
|
|
|
|
createSearchResutlMenu(menu, fileInfo);
|
|
|
|
menu.addAction("Copy page number", [previewPage]
|
|
|
|
{ QGuiApplication::clipboard()->setText(QString::number(previewPage)); });
|
|
|
|
menu.exec(QCursor::pos());
|
|
|
|
});
|
2019-04-30 14:13:10 +02:00
|
|
|
}
|
2018-08-12 16:45:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::lineEditReturnPressed()
|
|
|
|
{
|
|
|
|
QString q = ui->txtSearch->text();
|
2021-06-12 14:59:58 +02:00
|
|
|
if(!LooqsQuery::checkParanthesis(q))
|
2018-09-02 13:54:27 +02:00
|
|
|
{
|
|
|
|
ui->lblSearchResults->setText("Invalid paranthesis");
|
|
|
|
return;
|
|
|
|
}
|
2018-09-02 12:27:23 +02:00
|
|
|
// TODO: validate q;
|
2022-04-17 20:52:07 +02:00
|
|
|
ui->treeResultsList->clear();
|
2018-09-02 12:33:04 +02:00
|
|
|
ui->lblSearchResults->setText("Searching...");
|
2020-06-06 23:18:33 +02:00
|
|
|
this->ui->txtSearch->setEnabled(false);
|
2019-04-27 21:24:53 +02:00
|
|
|
QFuture<QVector<SearchResult>> searchFuture = QtConcurrent::run(
|
|
|
|
[&, q]()
|
|
|
|
{
|
|
|
|
SqliteSearch searcher(db);
|
2022-01-04 11:18:53 +01:00
|
|
|
QVector<SearchResult> results;
|
2021-12-30 12:17:12 +01:00
|
|
|
this->contentSearchQuery = LooqsQuery::build(q, TokenType::FILTER_CONTENT_CONTAINS, true);
|
|
|
|
|
2022-01-04 11:18:53 +01:00
|
|
|
/* We can have a path search in contentsearch too (if given explicitly), so no need to do it twice.
|
|
|
|
Make sure path results are listed first. */
|
|
|
|
bool addContentSearch = this->contentSearchQuery.hasContentSearch();
|
|
|
|
bool addPathSearch = !this->contentSearchQuery.hasPathSearch() || !addContentSearch;
|
|
|
|
if(addPathSearch)
|
|
|
|
{
|
|
|
|
LooqsQuery filesQuery = LooqsQuery::build(q, TokenType::FILTER_PATH_CONTAINS, false);
|
|
|
|
results.append(searcher.search(filesQuery));
|
|
|
|
}
|
|
|
|
if(addContentSearch)
|
|
|
|
{
|
|
|
|
results.append(searcher.search(this->contentSearchQuery));
|
|
|
|
}
|
2021-12-30 12:17:12 +01:00
|
|
|
return results;
|
2019-04-27 21:24:53 +02:00
|
|
|
});
|
|
|
|
searchWatcher.setFuture(searchFuture);
|
2018-08-12 16:45:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::handleSearchResults(const QVector<SearchResult> &results)
|
|
|
|
{
|
2022-01-03 23:02:21 +01:00
|
|
|
this->previewableSearchResults.clear();
|
2018-08-12 16:45:39 +02:00
|
|
|
ui->treeResultsList->clear();
|
2021-03-27 18:18:19 +01:00
|
|
|
|
|
|
|
bool hasDeleted = false;
|
2018-08-12 16:45:39 +02:00
|
|
|
for(const SearchResult &result : results)
|
|
|
|
{
|
2019-04-26 15:31:42 +02:00
|
|
|
QFileInfo pathInfo(result.fileData.absPath);
|
2021-03-27 18:18:19 +01:00
|
|
|
|
2019-04-26 15:31:42 +02:00
|
|
|
QString fileName = pathInfo.fileName();
|
|
|
|
QTreeWidgetItem *item = new QTreeWidgetItem(ui->treeResultsList);
|
|
|
|
|
|
|
|
QDateTime dt = QDateTime::fromSecsSinceEpoch(result.fileData.mtime);
|
|
|
|
item->setIcon(0, iconProvider.icon(pathInfo));
|
|
|
|
item->setText(0, fileName);
|
|
|
|
item->setText(1, result.fileData.absPath);
|
|
|
|
item->setText(2, dt.toString(Qt::ISODate));
|
2019-08-17 14:46:30 +02:00
|
|
|
item->setText(3, this->locale().formattedDataSize(result.fileData.size));
|
2021-03-27 18:18:19 +01:00
|
|
|
bool exists = pathInfo.exists();
|
|
|
|
if(exists)
|
|
|
|
{
|
|
|
|
if(result.fileData.absPath.endsWith(".pdf"))
|
|
|
|
{
|
2022-01-03 23:02:21 +01:00
|
|
|
this->previewableSearchResults.append(result);
|
2021-03-27 18:18:19 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2018-08-12 16:45:39 +02:00
|
|
|
{
|
2021-03-27 18:18:19 +01:00
|
|
|
hasDeleted = true;
|
2018-08-12 16:45:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
ui->treeResultsList->resizeColumnToContents(0);
|
|
|
|
ui->treeResultsList->resizeColumnToContents(1);
|
2022-01-03 23:02:21 +01:00
|
|
|
previewDirty = !this->previewableSearchResults.empty();
|
2019-08-26 09:20:21 +02:00
|
|
|
|
2022-01-03 23:02:21 +01:00
|
|
|
int numpages = ceil(static_cast<double>(this->previewableSearchResults.size()) / previewsPerPage);
|
|
|
|
ui->spinPreviewPage->setMinimum(1);
|
|
|
|
ui->spinPreviewPage->setMaximum(numpages);
|
|
|
|
ui->spinPreviewPage->setValue(1);
|
|
|
|
if(previewTabActive() && previewDirty)
|
2018-09-02 12:27:23 +02:00
|
|
|
{
|
2022-01-03 23:02:21 +01:00
|
|
|
makePreviews(1);
|
2018-09-02 12:27:23 +02:00
|
|
|
}
|
2021-03-27 18:18:19 +01:00
|
|
|
|
|
|
|
QString statusText = "Results: " + QString::number(results.size()) + " files";
|
|
|
|
if(hasDeleted)
|
|
|
|
{
|
|
|
|
statusText += " WARNING: Some files don't exist anymore. No preview available for those. Index out of sync";
|
|
|
|
}
|
|
|
|
ui->lblSearchResults->setText(statusText);
|
2018-08-12 16:45:39 +02:00
|
|
|
}
|
|
|
|
|
2022-01-03 23:02:21 +01:00
|
|
|
void MainWindow::makePreviews(int page)
|
2018-08-12 16:45:39 +02:00
|
|
|
{
|
2018-08-30 21:54:29 +02:00
|
|
|
|
2022-01-03 23:02:21 +01:00
|
|
|
this->previewWorkerWatcher.cancel();
|
|
|
|
this->previewWorkerWatcher.waitForFinished();
|
2019-04-29 20:50:52 +02:00
|
|
|
|
|
|
|
QCoreApplication::processEvents(); // Maybe not necessary anymore, depends on whether it's possible that a slot is
|
|
|
|
// still to be fired.
|
2018-08-12 16:45:39 +02:00
|
|
|
qDeleteAll(ui->scrollAreaWidgetContents->children());
|
|
|
|
|
|
|
|
ui->scrollAreaWidgetContents->setLayout(new QHBoxLayout());
|
2022-01-03 23:02:21 +01:00
|
|
|
ui->previewProcessBar->setMaximum(this->previewableSearchResults.size());
|
2018-08-31 20:40:07 +02:00
|
|
|
processedPdfPreviews = 0;
|
2018-09-02 20:30:52 +02:00
|
|
|
QString scaleText = ui->comboScale->currentText();
|
|
|
|
scaleText.chop(1);
|
2019-08-18 23:23:11 +02:00
|
|
|
|
|
|
|
QVector<QString> wordsToHighlight;
|
2019-08-19 19:43:05 +02:00
|
|
|
QRegularExpression extractor(R"#("([^"]*)"|(\w+))#");
|
2021-12-30 12:17:12 +01:00
|
|
|
for(const Token &token : this->contentSearchQuery.getTokens())
|
2019-08-18 23:23:11 +02:00
|
|
|
{
|
|
|
|
if(token.type == FILTER_CONTENT_CONTAINS)
|
|
|
|
{
|
2019-08-19 19:43:05 +02:00
|
|
|
QRegularExpressionMatchIterator i = extractor.globalMatch(token.value);
|
|
|
|
while(i.hasNext())
|
2019-08-18 23:23:11 +02:00
|
|
|
{
|
2019-08-19 19:43:05 +02:00
|
|
|
QRegularExpressionMatch m = i.next();
|
|
|
|
QString value = m.captured(1);
|
|
|
|
if(value.isEmpty())
|
|
|
|
{
|
|
|
|
value = m.captured(2);
|
|
|
|
}
|
|
|
|
wordsToHighlight.append(value);
|
2019-08-18 23:23:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-01-03 23:02:21 +01:00
|
|
|
PreviewWorker worker;
|
|
|
|
int end = previewsPerPage;
|
|
|
|
int begin = page * previewsPerPage - previewsPerPage;
|
|
|
|
this->previewWorkerWatcher.setFuture(worker.generatePreviews(this->previewableSearchResults.mid(begin, end),
|
|
|
|
wordsToHighlight, scaleText.toInt() / 100.));
|
|
|
|
ui->previewProcessBar->setMaximum(this->previewWorkerWatcher.progressMaximum());
|
|
|
|
ui->previewProcessBar->setMinimum(this->previewWorkerWatcher.progressMinimum());
|
2022-04-17 20:52:07 +02:00
|
|
|
ui->previewProcessBar->setVisible(this->previewableSearchResults.size() > 0);
|
2018-08-12 16:45:39 +02:00
|
|
|
}
|
|
|
|
|
2018-09-02 13:54:27 +02:00
|
|
|
void MainWindow::handleSearchError(QString error)
|
|
|
|
{
|
|
|
|
ui->lblSearchResults->setText("Error:" + error);
|
|
|
|
}
|
|
|
|
|
2021-03-27 17:58:38 +01:00
|
|
|
void MainWindow::createSearchResutlMenu(QMenu &menu, const QFileInfo &fileInfo)
|
|
|
|
{
|
|
|
|
menu.addAction("Copy filename to clipboard",
|
|
|
|
[&fileInfo] { QGuiApplication::clipboard()->setText(fileInfo.fileName()); });
|
|
|
|
menu.addAction("Copy full path to clipboard",
|
|
|
|
[&fileInfo] { QGuiApplication::clipboard()->setText(fileInfo.absoluteFilePath()); });
|
2021-09-28 21:44:09 +02:00
|
|
|
menu.addAction("Open containing folder", [this, &fileInfo] { this->ipcFileOpen(fileInfo.absolutePath()); });
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::ipcDocOpen(QString path, int num)
|
|
|
|
{
|
|
|
|
QStringList args;
|
|
|
|
args << path;
|
|
|
|
args << QString::number(num);
|
|
|
|
this->ipcClient->sendCommand(DocOpen, args);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::ipcFileOpen(QString path)
|
|
|
|
{
|
|
|
|
QStringList args;
|
|
|
|
args << path;
|
|
|
|
this->ipcClient->sendCommand(FileOpen, args);
|
2021-03-27 17:58:38 +01:00
|
|
|
}
|
|
|
|
|
2018-08-12 16:45:39 +02:00
|
|
|
void MainWindow::treeSearchItemActivated(QTreeWidgetItem *item, int i)
|
|
|
|
{
|
2021-09-28 21:44:09 +02:00
|
|
|
ipcFileOpen(item->text(1));
|
2018-08-12 16:45:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::showSearchResultsContextMenu(const QPoint &point)
|
|
|
|
{
|
|
|
|
QTreeWidgetItem *item = ui->treeResultsList->itemAt(point);
|
|
|
|
if(item == nullptr)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2021-03-27 17:58:38 +01:00
|
|
|
QFileInfo pathinfo(item->text(1));
|
|
|
|
QMenu menu("SearchResults", this);
|
|
|
|
createSearchResutlMenu(menu, pathinfo);
|
2018-08-12 16:45:39 +02:00
|
|
|
menu.exec(QCursor::pos());
|
|
|
|
}
|
|
|
|
|
|
|
|
MainWindow::~MainWindow()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|