From 1ec42e494973026b4c62cba66d4507e237c95c78 Mon Sep 17 00:00:00 2001 From: Albert S Date: Sat, 4 Jun 2022 15:49:29 +0200 Subject: [PATCH] gui: mainwindow: Add 'sync index' menu option Opens a progress dialog while syncing takes place. --- gui/mainwindow.cpp | 48 +++++++++++++++++++++++++++++++++++++++++++++- gui/mainwindow.h | 7 +++++++ gui/mainwindow.ui | 11 +++++++++-- 3 files changed, 63 insertions(+), 3 deletions(-) diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index bdd8019..fd437ea 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include "mainwindow.h" #include "ui_mainwindow.h" #include "clicklabel.h" @@ -23,8 +24,10 @@ #include "ipcpreviewclient.h" #include "previewgenerator.h" -MainWindow::MainWindow(QWidget *parent, QString socketPath) : QMainWindow(parent), ui(new Ui::MainWindow) +MainWindow::MainWindow(QWidget *parent, QString socketPath) + : QMainWindow(parent), ui(new Ui::MainWindow), progressDialog(this) { + this->progressDialog.cancel(); // because constructing it shows it, quite weird ui->setupUi(this); setWindowTitle(QCoreApplication::applicationName()); this->ipcPreviewClient.moveToThread(&this->ipcClientThread); @@ -56,6 +59,8 @@ MainWindow::MainWindow(QWidget *parent, QString socketPath) : QMainWindow(parent db = this->dbFactory->forCurrentThread(); this->dbService = new SqliteDbService(*this->dbFactory); + this->indexSyncer = new IndexSyncer(*this->dbService); + this->indexSyncer->moveToThread(&this->syncerThread); indexer = new Indexer(*(this->dbService)); indexer->setParent(this); @@ -96,6 +101,7 @@ void MainWindow::addPathToIndex() this->ui->lstPaths->addItem(path); this->ui->txtPathScanAdd->clear(); } + void MainWindow::connectSignals() { connect(ui->txtSearch, &QLineEdit::returnPressed, this, &MainWindow::lineEditReturnPressed); @@ -194,8 +200,42 @@ void MainWindow::connectSignals() }); connect(ui->menuAboutQtAction, &QAction::triggered, this, [this](bool checked) { QMessageBox::aboutQt(this, "About Qt"); }); + connect(ui->menuSyncIndexAction, &QAction::triggered, this, &MainWindow::startIndexSync); + connect(indexSyncer, &IndexSyncer::finished, this, + [&](unsigned int totalUpdated, unsigned int totalDeleted, unsigned int totalErrored) + { + this->progressDialog.cancel(); + + QMessageBox::information( + this, "Syncing finished", + QString("Syncing finished\n\nTotal updated: %1\nTotal deleted: %2\nTotal errors: %3\n") + .arg(QString::number(totalUpdated)) + .arg(QString::number(totalDeleted)) + .arg(QString::number(totalErrored))); + }); + connect(this, &MainWindow::beginIndexSync, indexSyncer, &IndexSyncer::sync); + connect(&this->progressDialog, &QProgressDialog::canceled, indexSyncer, &IndexSyncer::cancel); } +void MainWindow::startIndexSync() +{ + progressDialog.setWindowTitle("Syncing"); + progressDialog.setLabelText("Syncing - this might take a moment, please wait"); + progressDialog.setWindowModality(Qt::ApplicationModal); + progressDialog.setMinimum(0); + progressDialog.setMaximum(0); + progressDialog.setValue(0); + progressDialog.open(); + + indexSyncer->setKeepGoing(true); + indexSyncer->setVerbose(false); + indexSyncer->setDryRun(false); + indexSyncer->setRemoveDeletedFromIndex(true); + + this->syncerThread.start(); + + emit beginIndexSync(); +} void MainWindow::spinPreviewPageValueChanged(int val) { makePreviews(val); @@ -563,5 +603,11 @@ void MainWindow::showSearchResultsContextMenu(const QPoint &point) MainWindow::~MainWindow() { + syncerThread.terminate(); + ipcClientThread.terminate(); + delete this->indexSyncer; + delete this->dbService; + delete this->dbFactory; + delete this->indexer; delete ui; } diff --git a/gui/mainwindow.h b/gui/mainwindow.h index 8c97a68..d5ee7c8 100644 --- a/gui/mainwindow.h +++ b/gui/mainwindow.h @@ -9,7 +9,9 @@ #include #include #include +#include #include "../shared/looqsquery.h" +#include "../shared/indexsyncer.h" #include "ipcpreviewclient.h" #include "indexer.h" namespace Ui @@ -34,6 +36,9 @@ class MainWindow : public QMainWindow Ui::MainWindow *ui; IPCPreviewClient ipcPreviewClient; QThread ipcClientThread; + QThread syncerThread; + IndexSyncer *indexSyncer; + QProgressDialog progressDialog; Indexer *indexer; QFileIconProvider iconProvider; @@ -67,10 +72,12 @@ class MainWindow : public QMainWindow void startIndexing(); void finishIndexing(); void addPathToIndex(); + void startIndexSync(); signals: void startIpcPreviews(RenderConfig config, const QVector &targets); void stopIpcPreviews(); + void beginIndexSync(); }; #endif // MAINWINDOW_H diff --git a/gui/mainwindow.ui b/gui/mainwindow.ui index c94cfc0..7c9eae0 100644 --- a/gui/mainwindow.ui +++ b/gui/mainwindow.ui @@ -7,7 +7,7 @@ 0 0 1221 - 674 + 709 @@ -82,7 +82,7 @@ 0 0 1185 - 384 + 419 @@ -377,8 +377,10 @@ looqs + + @@ -397,6 +399,11 @@ About Qt + + + Sync index (remove deleted, update existing files) + +