Compare commits

..

No commits in common. "0b829215e5aa05680c99c19468db8f02db969bc5" and "590a8888fcf18881349d7ac5352bf88d31f5156b" have entirely different histories.

15 changed files with 60 additions and 49 deletions

View File

@ -23,7 +23,7 @@ void CommandAdd::indexerFinished()
if(failedPathsCount > 0) if(failedPathsCount > 0)
{ {
Logger::info() << "Failed paths: " << Qt::endl; Logger::info() << "Failed paths: " << Qt::endl;
for(const QString &paths : result.failedPaths()) for(QString paths : result.failedPaths())
{ {
Logger::info() << paths << Qt::endl; Logger::info() << paths << Qt::endl;
} }
@ -95,8 +95,8 @@ int CommandAdd::handle(QStringList arguments)
connect(indexer, &Indexer::pathsCountChanged, this, connect(indexer, &Indexer::pathsCountChanged, this,
[](int pathsCount) { Logger::info() << "Found paths: " << pathsCount << Qt::endl; }); [](int pathsCount) { Logger::info() << "Found paths: " << pathsCount << Qt::endl; });
connect(indexer, &Indexer::indexProgress, this, connect(indexer, &Indexer::indexProgress, this,
[](int pathsCount, unsigned int /*added*/, unsigned int /*skipped*/, unsigned int /*failed*/, [](int pathsCount, unsigned int added, unsigned int skipped, unsigned int failed, unsigned int totalCount)
unsigned int /*totalCount*/) { Logger::info() << "Processed files: " << pathsCount << Qt::endl; }); { Logger::info() << "Processed files: " << pathsCount << Qt::endl; });
connect(indexer, &Indexer::finished, this, &CommandAdd::indexerFinished); connect(indexer, &Indexer::finished, this, &CommandAdd::indexerFinished);
this->autoFinish = false; this->autoFinish = false;

View File

@ -1,5 +1,6 @@
#include <QCommandLineParser> #include <QCommandLineParser>
#include "commandlist.h" #include "commandlist.h"
#include "databasefactory.h"
#include "logger.h" #include "logger.h"
int CommandList::handle(QStringList arguments) int CommandList::handle(QStringList arguments)

View File

@ -38,6 +38,7 @@ int CommandUpdate::handle(QStringList arguments)
QThreadPool::globalInstance()->setMaxThreadCount(threadsCount.toInt()); QThreadPool::globalInstance()->setMaxThreadCount(threadsCount.toInt());
} }
bool hasErrors = false;
IndexSyncer *syncer = new IndexSyncer(*this->dbService); IndexSyncer *syncer = new IndexSyncer(*this->dbService);
FileSaverOptions fileOptions; FileSaverOptions fileOptions;
@ -63,7 +64,7 @@ int CommandUpdate::handle(QStringList arguments)
/* TODO: updated not printed, handled be verbose in FileSaver, but this can be improved */ /* TODO: updated not printed, handled be verbose in FileSaver, but this can be improved */
} }
connect(syncer, &IndexSyncer::finished, this, connect(syncer, &IndexSyncer::finished, this,
[this, dryRun, keepGoing](unsigned int totalUpdated, unsigned int totalRemoved, unsigned int totalErrors) [&](unsigned int totalUpdated, unsigned int totalRemoved, unsigned int totalErrors)
{ {
Logger::info() << "Syncing finished" << Qt::endl; Logger::info() << "Syncing finished" << Qt::endl;
@ -75,7 +76,7 @@ int CommandUpdate::handle(QStringList arguments)
} }
int retval = 0; int retval = 0;
if(this->hasErrors && !keepGoing) if(hasErrors && !keepGoing)
{ {
retval = 1; retval = 1;
} }
@ -85,7 +86,7 @@ int CommandUpdate::handle(QStringList arguments)
[&](QString error) [&](QString error)
{ {
Logger::error() << error << Qt::endl; Logger::error() << error << Qt::endl;
this->hasErrors = true; hasErrors = true;
}); });
this->autoFinish = false; this->autoFinish = false;

View File

@ -4,9 +4,6 @@
#include "filesaver.h" #include "filesaver.h"
class CommandUpdate : public Command class CommandUpdate : public Command
{ {
protected:
bool hasErrors = false;
public: public:
using Command::Command; using Command::Command;
int handle(QStringList arguments) override; int handle(QStringList arguments) override;

View File

@ -22,6 +22,7 @@
#include "../shared/sqlitesearch.h" #include "../shared/sqlitesearch.h"
#include "../shared/looqsgeneralexception.h" #include "../shared/looqsgeneralexception.h"
#include "../shared/common.h" #include "../shared/common.h"
#include "previewgenerator.h"
#include "aboutdialog.h" #include "aboutdialog.h"
MainWindow::MainWindow(QWidget *parent, QString socketPath) MainWindow::MainWindow(QWidget *parent, QString socketPath)
@ -147,7 +148,7 @@ void MainWindow::connectSignals()
connect(this->indexer, &Indexer::finished, this, &MainWindow::finishIndexing); connect(this->indexer, &Indexer::finished, this, &MainWindow::finishIndexing);
connect(ui->lstPaths->selectionModel(), &QItemSelectionModel::selectionChanged, this, connect(ui->lstPaths->selectionModel(), &QItemSelectionModel::selectionChanged, this,
[&](const QItemSelection & /*selected*/, const QItemSelection & /*deselected*/) [&](const QItemSelection &selected, const QItemSelection &deselected)
{ ui->btnDeletePath->setEnabled(this->ui->lstPaths->selectedItems().count() > 0); }); { ui->btnDeletePath->setEnabled(this->ui->lstPaths->selectedItems().count() > 0); });
connect(ui->btnDeletePath, &QPushButton::clicked, this, [&] { qDeleteAll(ui->lstPaths->selectedItems()); }); connect(ui->btnDeletePath, &QPushButton::clicked, this, [&] { qDeleteAll(ui->lstPaths->selectedItems()); });
@ -167,20 +168,19 @@ void MainWindow::connectSignals()
} }
}); });
connect(ui->menuAboutAction, &QAction::triggered, this, connect(ui->menuAboutAction, &QAction::triggered, this,
[this](bool /*checked*/) [this](bool checked)
{ {
AboutDialog aboutDialog(this); AboutDialog aboutDialog(this);
aboutDialog.exec(); aboutDialog.exec();
}); });
connect(ui->menuAboutQtAction, &QAction::triggered, this, connect(ui->menuAboutQtAction, &QAction::triggered, this,
[this](bool /*checked*/) { QMessageBox::aboutQt(this, "About Qt"); }); [this](bool checked) { QMessageBox::aboutQt(this, "About Qt"); });
connect(ui->menuSyncIndexAction, &QAction::triggered, this, &MainWindow::startIndexSync); connect(ui->menuSyncIndexAction, &QAction::triggered, this, &MainWindow::startIndexSync);
connect(ui->menuOpenUserManualAction, &QAction::triggered, this, connect(ui->menuOpenUserManualAction, &QAction::triggered, this,
[]() { QDesktopServices::openUrl(Common::userManualUrl()); }); [this]() { QDesktopServices::openUrl(Common::userManualUrl()); });
connect( connect(indexSyncer, &IndexSyncer::finished, this,
indexSyncer, &IndexSyncer::finished, this,
[&](unsigned int totalUpdated, unsigned int totalDeleted, unsigned int totalErrored) [&](unsigned int totalUpdated, unsigned int totalDeleted, unsigned int totalErrored)
{ {
this->progressDialog.cancel(); this->progressDialog.cancel();
@ -188,7 +188,9 @@ void MainWindow::connectSignals()
QMessageBox::information( QMessageBox::information(
this, "Syncing finished", this, "Syncing finished",
QString("Syncing finished\n\nTotal updated: %1\nTotal deleted: %2\nTotal errors: %3\n") QString("Syncing finished\n\nTotal updated: %1\nTotal deleted: %2\nTotal errors: %3\n")
.arg(QString::number(totalUpdated), QString::number(totalDeleted), QString::number(totalErrored))); .arg(QString::number(totalUpdated))
.arg(QString::number(totalDeleted))
.arg(QString::number(totalErrored)));
}); });
connect(this, &MainWindow::beginIndexSync, indexSyncer, &IndexSyncer::sync); connect(this, &MainWindow::beginIndexSync, indexSyncer, &IndexSyncer::sync);
connect(&this->progressDialog, &QProgressDialog::canceled, indexSyncer, &IndexSyncer::cancel); connect(&this->progressDialog, &QProgressDialog::canceled, indexSyncer, &IndexSyncer::cancel);
@ -350,7 +352,7 @@ void MainWindow::finishIndexing()
} }
} }
void MainWindow::comboScaleChanged(int /*i*/) void MainWindow::comboScaleChanged(int i)
{ {
QSettings scaleSetting; QSettings scaleSetting;
scaleSetting.setValue("currentScale", ui->comboScale->currentText()); scaleSetting.setValue("currentScale", ui->comboScale->currentText());
@ -396,8 +398,7 @@ void MainWindow::processShortcut(int key)
{ {
ui->txtSearch->setFocus(); ui->txtSearch->setFocus();
QString currentText = ui->txtSearch->text().trimmed(); QString currentText = ui->txtSearch->text().trimmed();
static QRegularExpression separatorRegex("[\\s\\)]"); int index = currentText.lastIndexOf(QRegularExpression("[\\s\\)]"));
int index = currentText.lastIndexOf(separatorRegex);
if(index != -1) if(index != -1)
{ {
bool isFilter = (index == currentText.length() - 1); bool isFilter = (index == currentText.length() - 1);
@ -677,7 +678,7 @@ void MainWindow::previewReceived()
QFileInfo fileInfo{docPath}; QFileInfo fileInfo{docPath};
QMenu menu("labeRightClick", this); QMenu menu("labeRightClick", this);
createSearchResultMenu(menu, fileInfo); createSearchResultMenu(menu, fileInfo);
menu.addAction("Copy page number", this, menu.addAction("Copy page number",
[previewPage] { QGuiApplication::clipboard()->setText(QString::number(previewPage)); }); [previewPage] { QGuiApplication::clipboard()->setText(QString::number(previewPage)); });
menu.exec(QCursor::pos()); menu.exec(QCursor::pos());
}; };
@ -915,7 +916,7 @@ void MainWindow::makePreviews(int page)
ui->previewProcessBar->setMaximum(this->previewCoordinator.previewableCount()); ui->previewProcessBar->setMaximum(this->previewCoordinator.previewableCount());
QVector<QString> wordsToHighlight; QVector<QString> wordsToHighlight;
static QRegularExpression extractor(R"#("([^"]*)"|([^\s]+))#"); QRegularExpression extractor(R"#("([^"]*)"|([^\s]+))#");
for(const Token &token : this->contentSearchQuery.getTokens()) for(const Token &token : this->contentSearchQuery.getTokens())
{ {
if(token.type == FILTER_CONTENT_CONTAINS) if(token.type == FILTER_CONTENT_CONTAINS)
@ -947,6 +948,7 @@ void MainWindow::makePreviews(int page)
renderConfig.scaleY = QGuiApplication::primaryScreen()->physicalDotsPerInchY() * (currentScale / 100.); renderConfig.scaleY = QGuiApplication::primaryScreen()->physicalDotsPerInchY() * (currentScale / 100.);
renderConfig.wordsToHighlight = wordsToHighlight; renderConfig.wordsToHighlight = wordsToHighlight;
int previewPos = 0;
QVector<RenderTarget> targets; QVector<RenderTarget> targets;
for(const SearchResult &sr : this->previewCoordinator.getPreviewableSearchResults()) for(const SearchResult &sr : this->previewCoordinator.getPreviewableSearchResults())
{ {
@ -986,20 +988,20 @@ void MainWindow::handleSearchError(QString error)
void MainWindow::createSearchResultMenu(QMenu &menu, const QFileInfo &fileInfo) void MainWindow::createSearchResultMenu(QMenu &menu, const QFileInfo &fileInfo)
{ {
menu.addAction("Copy filename to clipboard", this, menu.addAction("Copy filename to clipboard",
[&fileInfo] { QGuiApplication::clipboard()->setText(fileInfo.fileName()); }); [&fileInfo] { QGuiApplication::clipboard()->setText(fileInfo.fileName()); });
menu.addAction("Copy full path to clipboard", this, menu.addAction("Copy full path to clipboard",
[&fileInfo] { QGuiApplication::clipboard()->setText(fileInfo.absoluteFilePath()); }); [&fileInfo] { QGuiApplication::clipboard()->setText(fileInfo.absoluteFilePath()); });
menu.addAction("Open containing folder", this, [this, &fileInfo] { this->openFile(fileInfo.absolutePath()); }); menu.addAction("Open containing folder", [this, &fileInfo] { this->openFile(fileInfo.absolutePath()); });
auto previewables = this->previewCoordinator.getPreviewableSearchResults(); auto previewables = this->previewCoordinator.getPreviewableSearchResults();
auto result = auto result =
std::find_if(previewables.begin(), previewables.end(), std::find_if(previewables.begin(), previewables.end(),
[&fileInfo](SearchResult &a) { return fileInfo.absoluteFilePath() == a.fileData.absPath; }); [this, &fileInfo](SearchResult &a) { return fileInfo.absoluteFilePath() == a.fileData.absPath; });
if(result != previewables.end()) if(result != previewables.end())
{ {
menu.addAction("Show previews for this file", this, menu.addAction("Show previews for this file",
[this, &fileInfo] [this, &fileInfo]
{ {
ui->tabWidget->setCurrentIndex(1); ui->tabWidget->setCurrentIndex(1);
@ -1035,7 +1037,7 @@ void MainWindow::openFile(QString path)
QDesktopServices::openUrl(QUrl::fromLocalFile(path)); QDesktopServices::openUrl(QUrl::fromLocalFile(path));
} }
void MainWindow::treeSearchItemActivated(QTreeWidgetItem *item, int /*i*/) void MainWindow::treeSearchItemActivated(QTreeWidgetItem *item, int i)
{ {
openFile(item->text(1)); openFile(item->text(1));
} }
@ -1063,7 +1065,7 @@ MainWindow::~MainWindow()
delete ui; delete ui;
} }
void MainWindow::closeEvent(QCloseEvent * /*event*/) void MainWindow::closeEvent(QCloseEvent *event)
{ {
QStringList list = this->searchHistory.toList(); QStringList list = this->searchHistory.toList();
QSettings settings; QSettings settings;

View File

@ -57,7 +57,7 @@ class MainWindow : public QMainWindow
void initSettingsTabs(); void initSettingsTabs();
int currentSelectedScale(); int currentSelectedScale();
void processShortcut(int key); void processShortcut(int key);
bool eventFilter(QObject *object, QEvent *event) override; bool eventFilter(QObject *object, QEvent *event);
private slots: private slots:
void lineEditReturnPressed(); void lineEditReturnPressed();

View File

@ -24,7 +24,7 @@ QSharedPointer<PreviewResult> PreviewGeneratorOdt::generate(RenderConfig config,
throw LooqsGeneralException("Error while reading content.xml of " + documentPath); throw LooqsGeneralException("Error while reading content.xml of " + documentPath);
} }
TagStripperProcessor tsp; TagStripperProcessor tsp;
QString content = tsp.process(entireContent).constFirst().content; QString content = tsp.process(entireContent).first().content;
PreviewGeneratorPlainText plainTextGenerator; PreviewGeneratorPlainText plainTextGenerator;
result->setText(plainTextGenerator.generatePreviewText(content, config, info.fileName())); result->setText(plainTextGenerator.generatePreviewText(content, config, info.fileName()));

View File

@ -195,7 +195,7 @@ QString PreviewGeneratorPlainText::generateLineBasedPreviewText(QTextStream &in,
int totalWordsA = 0; int totalWordsA = 0;
int differentWordsB = 0; int differentWordsB = 0;
int totalWordsB = 0; int totalWordsB = 0;
for(int count : qAsConst(a.wordCountMap)) for(int count : a.wordCountMap.values())
{ {
if(count > 0) if(count > 0)
{ {
@ -203,7 +203,7 @@ QString PreviewGeneratorPlainText::generateLineBasedPreviewText(QTextStream &in,
} }
totalWordsA += count; totalWordsA += count;
} }
for(int count : qAsConst(b.wordCountMap)) for(int count : b.wordCountMap.values())
{ {
if(count > 0) if(count > 0)
{ {

View File

@ -7,7 +7,6 @@
#include <optional> #include <optional>
#include <algorithm> #include <algorithm>
#include "looqsquery.h" #include "looqsquery.h"
#include "looqsgeneralexception.h"
const QVector<Token> &LooqsQuery::getTokens() const const QVector<Token> &LooqsQuery::getTokens() const
{ {
@ -181,8 +180,7 @@ LooqsQuery LooqsQuery::build(QString expression, TokenType loneWordsTokenType, b
QStringList loneWords; QStringList loneWords;
LooqsQuery result; LooqsQuery result;
static QRegularExpression rx( QRegularExpression rx("((?<filtername>(\\.|\\w)+):(?<args>\\((?<innerargs>[^\\)]+)\\)|([^\\s])+)|(?<boolean>AND|OR)"
"((?<filtername>(\\.|\\w)+):(?<args>\\((?<innerargs>[^\\)]+)\\)|([^\\s])+)|(?<boolean>AND|OR)"
"|(?<negation>!)|(?<bracket>\\(|\\))|(?<loneword>[^\\s]+))"); "|(?<negation>!)|(?<bracket>\\(|\\))|(?<loneword>[^\\s]+))");
QRegularExpressionMatchIterator i = rx.globalMatch(expression); QRegularExpressionMatchIterator i = rx.globalMatch(expression);
auto previousWasBool = [&result] { return !result.tokens.empty() && ((result.tokens.last().type & BOOL) == BOOL); }; auto previousWasBool = [&result] { return !result.tokens.empty() && ((result.tokens.last().type & BOOL) == BOOL); };

View File

@ -2,6 +2,7 @@
#define LOOQSQUERY_H #define LOOQSQUERY_H
#include <QString> #include <QString>
#include <QVector> #include <QVector>
#include "looqsgeneralexception.h"
#include "token.h" #include "token.h"
/* Fields that can be queried or sorted */ /* Fields that can be queried or sorted */
enum QueryField enum QueryField
@ -45,7 +46,7 @@ class LooqsQuery
void addToken(Token t); void addToken(Token t);
void updateTokensMask() void updateTokensMask()
{ {
for(const Token &t : qAsConst(tokens)) for(const Token &t : tokens)
{ {
this->tokensMask |= t.type; this->tokensMask |= t.type;
} }
@ -91,6 +92,14 @@ class LooqsQuery
this->sortConditions = sortConditions; this->sortConditions = sortConditions;
updateTokensMask(); updateTokensMask();
} }
LooqsQuery(const LooqsQuery &o)
{
this->tokens = o.tokens;
this->sortConditions = o.sortConditions;
this->tokensMask = o.tokensMask;
this->limit = o.limit;
}
}; };
#endif // LOOQSQUERY_H #endif // LOOQSQUERY_H

View File

@ -10,7 +10,7 @@ class NothingProcessor : public Processor
NothingProcessor(); NothingProcessor();
public: public:
QVector<PageData> process(const QByteArray & /*data*/) const override QVector<PageData> process(const QByteArray &data) const override
{ {
return {}; return {};
} }

View File

@ -3,7 +3,7 @@
#include "odtprocessor.h" #include "odtprocessor.h"
#include "tagstripperprocessor.h" #include "tagstripperprocessor.h"
QVector<PageData> OdtProcessor::process(const QByteArray & /*data*/) const QVector<PageData> OdtProcessor::process(const QByteArray &data) const
{ {
throw LooqsGeneralException("Not implemented yet"); throw LooqsGeneralException("Not implemented yet");
} }

View File

@ -1,3 +1,5 @@
#include "paralleldirscanner.h"
#include <QRunnable> #include <QRunnable>
#include <QMutex> #include <QMutex>
#include <QDirIterator> #include <QDirIterator>
@ -5,7 +7,7 @@
#include <QThreadPool> #include <QThreadPool>
#include <functional> #include <functional>
#include "dirscanworker.h" #include "dirscanworker.h"
#include "paralleldirscanner.h" #include "logger.h"
ParallelDirScanner::ParallelDirScanner() ParallelDirScanner::ParallelDirScanner()
{ {

View File

@ -69,7 +69,7 @@ QString SqliteSearch::createSortSql(const QVector<SortCondition> sortConditions)
QString SqliteSearch::escapeFtsArgument(QString ftsArg) QString SqliteSearch::escapeFtsArgument(QString ftsArg)
{ {
QString result; QString result;
static QRegularExpression extractor(R"#("([^"]*)"|([^\s]+))#"); QRegularExpression extractor(R"#("([^"]*)"|([^\s]+))#");
QRegularExpressionMatchIterator i = extractor.globalMatch(ftsArg); QRegularExpressionMatchIterator i = extractor.globalMatch(ftsArg);
while(i.hasNext()) while(i.hasNext())
{ {
@ -149,6 +149,7 @@ QPair<QString, QVector<QString>> SqliteSearch::createSql(const Token &token)
QSqlQuery SqliteSearch::makeSqlQuery(const LooqsQuery &query) QSqlQuery SqliteSearch::makeSqlQuery(const LooqsQuery &query)
{ {
QString whereSql; QString whereSql;
QString joinSql;
QVector<QString> bindValues; QVector<QString> bindValues;
bool isContentSearch = (query.getTokensMask() & FILTER_CONTENT) == FILTER_CONTENT; bool isContentSearch = (query.getTokensMask() & FILTER_CONTENT) == FILTER_CONTENT;
if(query.getTokens().isEmpty()) if(query.getTokens().isEmpty())

@ -1 +1 @@
Subproject commit 44b9a17becf6882e1b3728cbf885ae9e5a6717af Subproject commit 769f729dc51f2feb8bc3cbb2a48ed91ff2d56bf3