gui: mainwindow: Use new IPCPreviewClient
Este commit está contenido en:
padre
8f2e77b152
commit
13f28c37c6
@ -116,9 +116,10 @@ int main(int argc, char *argv[])
|
|||||||
qRegisterMetaType<QVector<PreviewResultPdf>>("QVector<PreviewResultPdf>");
|
qRegisterMetaType<QVector<PreviewResultPdf>>("QVector<PreviewResultPdf>");
|
||||||
qRegisterMetaType<PreviewResultPdf>("PreviewResultPdf");
|
qRegisterMetaType<PreviewResultPdf>("PreviewResultPdf");
|
||||||
qRegisterMetaType<FileScanResult>("FileScanResult");
|
qRegisterMetaType<FileScanResult>("FileScanResult");
|
||||||
|
qRegisterMetaType<RenderConfig>("RenderConfig");
|
||||||
IPCClient client{socketPath};
|
qRegisterMetaType<QVector<RenderTarget>>("QVector<RenderTarget>");
|
||||||
MainWindow w{0, client};
|
qRegisterMetaType<QSharedPointer<PreviewResult>>("QSharedPointer<PreviewResult>");
|
||||||
|
MainWindow w{0, socketPath};
|
||||||
w.showMaximized();
|
w.showMaximized();
|
||||||
return a.exec();
|
return a.exec();
|
||||||
}
|
}
|
||||||
|
@ -13,18 +13,33 @@
|
|||||||
#include <QtConcurrent/QtConcurrent>
|
#include <QtConcurrent/QtConcurrent>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
|
#include <QScreen>
|
||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
#include "ui_mainwindow.h"
|
#include "ui_mainwindow.h"
|
||||||
#include "clicklabel.h"
|
#include "clicklabel.h"
|
||||||
#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 "ipcpreviewclient.h"
|
||||||
|
#include "previewgenerator.h"
|
||||||
|
|
||||||
MainWindow::MainWindow(QWidget *parent, IPCClient &client) : QMainWindow(parent), ui(new Ui::MainWindow)
|
MainWindow::MainWindow(QWidget *parent, QString socketPath) : QMainWindow(parent), ui(new Ui::MainWindow)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
setWindowTitle(QCoreApplication::applicationName());
|
setWindowTitle(QCoreApplication::applicationName());
|
||||||
this->ipcClient = &client;
|
this->ipcPreviewClient.moveToThread(&this->ipcClientThread);
|
||||||
|
this->ipcPreviewClient.setSocketPath(socketPath);
|
||||||
|
|
||||||
|
connect(&ipcPreviewClient, &IPCPreviewClient::previewReceived, this, &MainWindow::previewReceived,
|
||||||
|
Qt::QueuedConnection);
|
||||||
|
connect(&ipcPreviewClient, &IPCPreviewClient::finished, this,
|
||||||
|
[&] { this->ui->previewProcessBar->setValue(this->ui->previewProcessBar->maximum()); });
|
||||||
|
|
||||||
|
connect(this, &MainWindow::startIpcPreviews, &ipcPreviewClient, &IPCPreviewClient::startGeneration,
|
||||||
|
Qt::QueuedConnection);
|
||||||
|
connect(this, &MainWindow::stopIpcPreviews, &ipcPreviewClient, &IPCPreviewClient::stopGeneration,
|
||||||
|
Qt::QueuedConnection);
|
||||||
|
this->ipcClientThread.start();
|
||||||
QSettings settings;
|
QSettings settings;
|
||||||
|
|
||||||
this->dbFactory = new DatabaseFactory(Common::databasePath());
|
this->dbFactory = new DatabaseFactory(Common::databasePath());
|
||||||
@ -82,16 +97,18 @@ void MainWindow::connectSignals()
|
|||||||
handleSearchError(e.message);
|
handleSearchError(e.message);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
connect(&previewWorkerWatcher, &QFutureWatcher<QSharedPointer<PreviewResult>>::resultReadyAt, this,
|
|
||||||
[&](int index) { previewReceived(previewWorkerWatcher.resultAt(index)); });
|
/* connect(&previewWorkerWatcher, &QFutureWatcher<QByteArray>::resultReadyAt, this,
|
||||||
|
[&](int index) {
|
||||||
|
previewReceived(previewWorkerWatcher.resultAt(index)); });
|
||||||
connect(&previewWorkerWatcher, &QFutureWatcher<QSharedPointer<PreviewResult>>::progressValueChanged,
|
connect(&previewWorkerWatcher, &QFutureWatcher<QSharedPointer<PreviewResult>>::progressValueChanged,
|
||||||
ui->previewProcessBar, &QProgressBar::setValue);
|
ui->previewProcessBar, &QProgressBar::setValue);
|
||||||
connect(&previewWorkerWatcher, &QFutureWatcher<QSharedPointer<PreviewResult>>::started, this,
|
connect(&previewWorkerWatcher, &QFutureWatcher<QSharedPointer<PreviewResult>>::started, this,
|
||||||
[&] { ui->indexerTab->setEnabled(false); });
|
[&] { ui->indexerTab->setEnabled(false); });*/
|
||||||
|
|
||||||
connect(&previewWorkerWatcher, &QFutureWatcher<QSharedPointer<PreviewResult>>::finished, this,
|
/*connect(&previewWorkerWatcher, &QFutureWatcher<QSharedPointer<PreviewResult>>::finished, this,
|
||||||
[&] { ui->indexerTab->setEnabled(true); });
|
[&] { ui->indexerTab->setEnabled(true); });
|
||||||
|
*/
|
||||||
connect(ui->treeResultsList, &QTreeWidget::itemActivated, this, &MainWindow::treeSearchItemActivated);
|
connect(ui->treeResultsList, &QTreeWidget::itemActivated, this, &MainWindow::treeSearchItemActivated);
|
||||||
connect(ui->treeResultsList, &QTreeWidget::customContextMenuRequested, this,
|
connect(ui->treeResultsList, &QTreeWidget::customContextMenuRequested, this,
|
||||||
&MainWindow::showSearchResultsContextMenu);
|
&MainWindow::showSearchResultsContextMenu);
|
||||||
@ -261,9 +278,14 @@ void MainWindow::tabChanged()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::previewReceived(QSharedPointer<PreviewResult> preview)
|
void MainWindow::previewReceived(QSharedPointer<PreviewResult> preview, unsigned int previewGeneration)
|
||||||
{
|
{
|
||||||
if(preview->hasPreview())
|
if(previewGeneration < this->currentPreviewGeneration)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this->ui->previewProcessBar->setValue(this->ui->previewProcessBar->value() + 1);
|
||||||
|
if(!preview.isNull() && preview->hasPreview())
|
||||||
{
|
{
|
||||||
QString docPath = preview->getDocumentPath();
|
QString docPath = preview->getDocumentPath();
|
||||||
auto previewPage = preview->getPage();
|
auto previewPage = preview->getPage();
|
||||||
@ -376,12 +398,10 @@ void MainWindow::handleSearchResults(const QVector<SearchResult> &results)
|
|||||||
|
|
||||||
void MainWindow::makePreviews(int page)
|
void MainWindow::makePreviews(int page)
|
||||||
{
|
{
|
||||||
|
if(this->previewableSearchResults.empty())
|
||||||
this->previewWorkerWatcher.cancel();
|
{
|
||||||
this->previewWorkerWatcher.waitForFinished();
|
return;
|
||||||
|
}
|
||||||
QCoreApplication::processEvents(); // Maybe not necessary anymore, depends on whether it's possible that a slot is
|
|
||||||
// still to be fired.
|
|
||||||
qDeleteAll(ui->scrollAreaWidgetContents->children());
|
qDeleteAll(ui->scrollAreaWidgetContents->children());
|
||||||
|
|
||||||
ui->scrollAreaWidgetContents->setLayout(new QHBoxLayout());
|
ui->scrollAreaWidgetContents->setLayout(new QHBoxLayout());
|
||||||
@ -409,14 +429,32 @@ void MainWindow::makePreviews(int page)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PreviewWorker worker;
|
|
||||||
int end = previewsPerPage;
|
int end = previewsPerPage;
|
||||||
int begin = page * previewsPerPage - previewsPerPage;
|
int begin = page * previewsPerPage - previewsPerPage;
|
||||||
this->previewWorkerWatcher.setFuture(worker.generatePreviews(this->previewableSearchResults.mid(begin, end),
|
|
||||||
wordsToHighlight, scaleText.toInt() / 100.));
|
RenderConfig renderConfig;
|
||||||
ui->previewProcessBar->setMaximum(this->previewWorkerWatcher.progressMaximum());
|
renderConfig.scaleX = QGuiApplication::primaryScreen()->physicalDotsPerInchX() * (scaleText.toInt() / 100.);
|
||||||
ui->previewProcessBar->setMinimum(this->previewWorkerWatcher.progressMinimum());
|
renderConfig.scaleY = QGuiApplication::primaryScreen()->physicalDotsPerInchY() * (scaleText.toInt() / 100.);
|
||||||
|
renderConfig.wordsToHighlight = wordsToHighlight;
|
||||||
|
|
||||||
|
QVector<RenderTarget> targets;
|
||||||
|
for(SearchResult &sr : this->previewableSearchResults.mid(begin, end))
|
||||||
|
{
|
||||||
|
RenderTarget renderTarget;
|
||||||
|
renderTarget.path = sr.fileData.absPath;
|
||||||
|
|
||||||
|
for(unsigned int pagenum : sr.pages)
|
||||||
|
{
|
||||||
|
renderTarget.page = (int)pagenum;
|
||||||
|
targets.append(renderTarget);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ui->previewProcessBar->setMaximum(targets.count());
|
||||||
|
ui->previewProcessBar->setMinimum(0);
|
||||||
|
ui->previewProcessBar->setValue(0);
|
||||||
ui->previewProcessBar->setVisible(this->previewableSearchResults.size() > 0);
|
ui->previewProcessBar->setVisible(this->previewableSearchResults.size() > 0);
|
||||||
|
++this->currentPreviewGeneration;
|
||||||
|
emit startIpcPreviews(renderConfig, targets);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::handleSearchError(QString error)
|
void MainWindow::handleSearchError(QString error)
|
||||||
@ -438,14 +476,14 @@ void MainWindow::ipcDocOpen(QString path, int num)
|
|||||||
QStringList args;
|
QStringList args;
|
||||||
args << path;
|
args << path;
|
||||||
args << QString::number(num);
|
args << QString::number(num);
|
||||||
this->ipcClient->sendCommand(DocOpen, args);
|
// this->ipcClient->sendCommand(DocOpen, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::ipcFileOpen(QString path)
|
void MainWindow::ipcFileOpen(QString path)
|
||||||
{
|
{
|
||||||
QStringList args;
|
QStringList args;
|
||||||
args << path;
|
args << path;
|
||||||
this->ipcClient->sendCommand(FileOpen, args);
|
// this->ipcClient->sendCommand(FileOpen, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::treeSearchItemActivated(QTreeWidgetItem *item, int i)
|
void MainWindow::treeSearchItemActivated(QTreeWidgetItem *item, int i)
|
||||||
|
@ -9,9 +9,8 @@
|
|||||||
#include <QFutureWatcher>
|
#include <QFutureWatcher>
|
||||||
#include <QSqlDatabase>
|
#include <QSqlDatabase>
|
||||||
#include <QLocalSocket>
|
#include <QLocalSocket>
|
||||||
#include "previewworker.h"
|
|
||||||
#include "../shared/looqsquery.h"
|
#include "../shared/looqsquery.h"
|
||||||
#include "ipcclient.h"
|
#include "ipcpreviewclient.h"
|
||||||
#include "indexer.h"
|
#include "indexer.h"
|
||||||
namespace Ui
|
namespace Ui
|
||||||
{
|
{
|
||||||
@ -23,7 +22,7 @@ class MainWindow : public QMainWindow
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit MainWindow(QWidget *parent, IPCClient &client);
|
explicit MainWindow(QWidget *parent, QString socketPath);
|
||||||
~MainWindow();
|
~MainWindow();
|
||||||
signals:
|
signals:
|
||||||
void beginSearch(const QString &query);
|
void beginSearch(const QString &query);
|
||||||
@ -33,13 +32,14 @@ class MainWindow : public QMainWindow
|
|||||||
DatabaseFactory *dbFactory;
|
DatabaseFactory *dbFactory;
|
||||||
SqliteDbService *dbService;
|
SqliteDbService *dbService;
|
||||||
Ui::MainWindow *ui;
|
Ui::MainWindow *ui;
|
||||||
IPCClient *ipcClient;
|
IPCPreviewClient ipcPreviewClient;
|
||||||
|
QThread ipcClientThread;
|
||||||
|
|
||||||
Indexer *indexer;
|
Indexer *indexer;
|
||||||
QFileIconProvider iconProvider;
|
QFileIconProvider iconProvider;
|
||||||
bool previewDirty;
|
bool previewDirty;
|
||||||
QSqlDatabase db;
|
QSqlDatabase db;
|
||||||
QFutureWatcher<QVector<SearchResult>> searchWatcher;
|
QFutureWatcher<QVector<SearchResult>> searchWatcher;
|
||||||
QFutureWatcher<QSharedPointer<PreviewResult>> previewWorkerWatcher;
|
|
||||||
void add(QString path, unsigned int page);
|
void add(QString path, unsigned int page);
|
||||||
QVector<SearchResult> previewableSearchResults;
|
QVector<SearchResult> previewableSearchResults;
|
||||||
void connectSignals();
|
void connectSignals();
|
||||||
@ -55,18 +55,22 @@ class MainWindow : public QMainWindow
|
|||||||
void createSearchResutlMenu(QMenu &menu, const QFileInfo &fileInfo);
|
void createSearchResutlMenu(QMenu &menu, const QFileInfo &fileInfo);
|
||||||
void ipcDocOpen(QString path, int num);
|
void ipcDocOpen(QString path, int num);
|
||||||
void ipcFileOpen(QString path);
|
void ipcFileOpen(QString path);
|
||||||
|
unsigned int currentPreviewGeneration = 1;
|
||||||
private slots:
|
private slots:
|
||||||
void lineEditReturnPressed();
|
void lineEditReturnPressed();
|
||||||
void treeSearchItemActivated(QTreeWidgetItem *item, int i);
|
void treeSearchItemActivated(QTreeWidgetItem *item, int i);
|
||||||
void showSearchResultsContextMenu(const QPoint &point);
|
void showSearchResultsContextMenu(const QPoint &point);
|
||||||
void tabChanged();
|
void tabChanged();
|
||||||
void previewReceived(QSharedPointer<PreviewResult> preview);
|
void previewReceived(QSharedPointer<PreviewResult> preview, unsigned int previewGeneration);
|
||||||
void comboScaleChanged(int i);
|
void comboScaleChanged(int i);
|
||||||
void spinPreviewPageValueChanged(int val);
|
void spinPreviewPageValueChanged(int val);
|
||||||
void startIndexing();
|
void startIndexing();
|
||||||
void finishIndexing();
|
void finishIndexing();
|
||||||
void addPathToIndex();
|
void addPathToIndex();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void startIpcPreviews(RenderConfig config, const QVector<RenderTarget> &targets);
|
||||||
|
void stopIpcPreviews();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MAINWINDOW_H
|
#endif // MAINWINDOW_H
|
||||||
|
Cargando…
Referencia en una nueva incidencia
Block a user