From 0af7d4a3dc8b2961a8e89feb6d06519b9cf608ca Mon Sep 17 00:00:00 2001 From: Albert S Date: Thu, 14 Apr 2022 15:04:16 +0200 Subject: [PATCH] GUI: Begin new 'Indexer' tab --- gui/gui.pro | 4 +- gui/main.cpp | 18 +++++ gui/mainwindow.cpp | 84 +++++++++++++++++++-- gui/mainwindow.h | 7 ++ gui/mainwindow.ui | 178 +++++++++++++++++++++++++++++++++++++++++---- 5 files changed, 269 insertions(+), 22 deletions(-) diff --git a/gui/gui.pro b/gui/gui.pro index 171d68c..6e84438 100644 --- a/gui/gui.pro +++ b/gui/gui.pro @@ -53,13 +53,15 @@ FORMS += \ mainwindow.ui INCLUDEPATH += /usr/include/poppler/qt5/ -LIBS += -lpoppler-qt5 + QT += widgets sql win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../shared/release/ -lshared else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../shared/debug/ -lshared else:unix: LIBS += -L$$OUT_PWD/../shared/ -lshared +LIBS += -luchardet -lpoppler-qt5 -lquazip5 + INCLUDEPATH += $$PWD/../shared DEPENDPATH += $$PWD/../shared diff --git a/gui/main.cpp b/gui/main.cpp index dc22d32..81c312d 100644 --- a/gui/main.cpp +++ b/gui/main.cpp @@ -10,6 +10,7 @@ #include "searchresult.h" #include "previewresultpdf.h" #include "../shared/common.h" +#include "../shared/sandboxedprocessor.h" #include "../submodules/exile.h/exile.h" #include "ipcserver.h" @@ -82,6 +83,22 @@ int main(int argc, char *argv[]) qDebug() << "Launched IPC Server"; return a.exec(); } + if(arg == "process") + { + Common::setupAppInfo(); + QApplication a(argc, argv); + + QStringList args = a.arguments(); + if(args.length() < 1) + { + qDebug() << "Filename is required"; + return 1; + } + + QString file = args.at(1); + SandboxedProcessor processor(file); + return processor.process(); + } } QProcess process; QStringList args; @@ -126,6 +143,7 @@ int main(int argc, char *argv[]) qRegisterMetaType>("QVector"); qRegisterMetaType>("QVector"); qRegisterMetaType("PreviewResultPdf"); + qRegisterMetaType("FileScanResult"); IPCClient client{socketPath}; MainWindow w{0, client}; diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 88171e6..5dddced 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -25,13 +25,13 @@ MainWindow::MainWindow(QWidget *parent, IPCClient &client) : QMainWindow(parent) this->ipcClient = &client; QSettings settings; - db = QSqlDatabase::addDatabase("QSQLITE"); - db.setDatabaseName(Common::databasePath()); - if(!db.open()) - { - qDebug() << "failed to open database"; - throw std::runtime_error("Failed to open database"); - } + this->dbFactory = new DatabaseFactory(Common::databasePath()); + + db = this->dbFactory->forCurrentThread(); + this->dbService = new SqliteDbService(*this->dbFactory); + + indexer = new Indexer(*(this->dbService)); + indexer->setParent(this); connectSignals(); ui->treeResultsList->setContextMenuPolicy(Qt::ContextMenuPolicy::CustomContextMenu); ui->tabWidget->setCurrentIndex(0); @@ -71,6 +71,41 @@ void MainWindow::connectSignals() connect(ui->comboScale, qOverload(&QComboBox::currentIndexChanged), this, &MainWindow::comboScaleChanged); connect(ui->spinPreviewPage, qOverload(&QSpinBox::valueChanged), this, &MainWindow::spinPreviewPageValueChanged); + + connect(ui->btnAddPath, &QPushButton::clicked, this, + [&] + { + this->ui->lstPaths->addItem(this->ui->txtPathScanAdd->text()); + this->ui->txtPathScanAdd->clear(); + }); + connect(ui->txtPathScanAdd, &QLineEdit::returnPressed, this, + [&] + { + this->ui->lstPaths->addItem(this->ui->txtPathScanAdd->text()); + this->ui->txtPathScanAdd->clear(); + }); + 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); } void MainWindow::spinPreviewPageValueChanged(int val) @@ -78,17 +113,49 @@ void MainWindow::spinPreviewPageValueChanged(int val) makePreviews(val); } +void MainWindow::startIndexing() +{ + ui->txtPathScanAdd->setEnabled(false); + ui->txtSearch->setEnabled(false); + ui->previewProcessBar->setValue(0); + + QVector paths; + for(int i = 0; i < ui->lstPaths->count(); i++) + { + paths.append(ui->lstPaths->item(i)->text()); + } + this->indexer->setTargetPaths(paths); + this->indexer->beginIndexing(); +} + +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)); +} + void MainWindow::comboScaleChanged(int i) { QSettings scaleSetting; scaleSetting.setValue("currentScale", ui->comboScale->currentText()); makePreviews(ui->spinPreviewPage->value()); } + bool MainWindow::previewTabActive() { return ui->tabWidget->currentIndex() == 1; } +bool MainWindow::indexerTabActive() +{ + return ui->tabWidget->currentIndex() == 2; +} + void MainWindow::keyPressEvent(QKeyEvent *event) { bool quit = @@ -112,7 +179,7 @@ void MainWindow::keyPressEvent(QKeyEvent *event) void MainWindow::tabChanged() { - if(previewTabActive()) + if(previewTabActive() || indexerTabActive()) { if(previewDirty) { @@ -120,6 +187,7 @@ void MainWindow::tabChanged() } ui->previewProcessBar->show(); } + else { ui->previewProcessBar->hide(); diff --git a/gui/mainwindow.h b/gui/mainwindow.h index d6ce9a4..25449af 100644 --- a/gui/mainwindow.h +++ b/gui/mainwindow.h @@ -12,6 +12,7 @@ #include "previewworker.h" #include "../shared/looqsquery.h" #include "ipcclient.h" +#include "indexer.h" namespace Ui { class MainWindow; @@ -29,8 +30,11 @@ class MainWindow : public QMainWindow void startPdfPreviewGeneration(QVector paths, double scalefactor); private: + DatabaseFactory *dbFactory; + SqliteDbService *dbService; Ui::MainWindow *ui; IPCClient *ipcClient; + Indexer *indexer; QFileIconProvider iconProvider; bool previewDirty; QSqlDatabase db; @@ -41,6 +45,7 @@ class MainWindow : public QMainWindow void connectSignals(); void makePreviews(int page); bool previewTabActive(); + bool indexerTabActive(); void keyPressEvent(QKeyEvent *event) override; unsigned int processedPdfPreviews; void handleSearchResults(const QVector &results); @@ -59,6 +64,8 @@ class MainWindow : public QMainWindow void previewReceived(QSharedPointer preview); void comboScaleChanged(int i); void spinPreviewPageValueChanged(int val); + void startIndexing(); + void finishIndexing(); }; #endif // MAINWINDOW_H diff --git a/gui/mainwindow.ui b/gui/mainwindow.ui index ca9cee6..100df00 100644 --- a/gui/mainwindow.ui +++ b/gui/mainwindow.ui @@ -7,7 +7,7 @@ 0 0 1221 - 614 + 674 @@ -27,7 +27,7 @@ QTabWidget::South - 1 + 2 @@ -82,7 +82,7 @@ 0 0 1185 - 324 + 419 @@ -172,6 +172,168 @@ + + + Index + + + + + + Add paths to scan + + + + + + + + + + + + Delete + + + + + + + ... + + + + + + + Add + + + + + + + + + + Ignore patterns, separated by ';'. Example: *.js;*Downloads* + + + + + + + Qt::PreventContextMenu + + + Index Progress + + + + + + + + Paths found: + + + + + + + + + + + + + + + + + + + 50 + false + + + + Added: + + + + + + + + + + + + + + + + + + + 50 + false + + + + Skipped: + + + + + + + + + + + + + + + + + + + 50 + false + + + + Failed: + + + + + + + + + + + + + + + + + + + + + + Start indexing + + + + + @@ -190,16 +352,6 @@ - - - - 0 - 0 - 1221 - 35 - - -