gui: Introduce PreviewCoordinator
Move some preview generation logic to PreviewCoordinator
Šī revīzija ir iekļauta:
vecāks
57f0afaf91
revīzija
8485a25b21
@ -34,6 +34,7 @@ SOURCES += \
|
|||||||
main.cpp \
|
main.cpp \
|
||||||
mainwindow.cpp \
|
mainwindow.cpp \
|
||||||
clicklabel.cpp \
|
clicklabel.cpp \
|
||||||
|
previewcoordinator.cpp \
|
||||||
previewgenerator.cpp \
|
previewgenerator.cpp \
|
||||||
previewgeneratormapfunctor.cpp \
|
previewgeneratormapfunctor.cpp \
|
||||||
previewgeneratorodt.cpp \
|
previewgeneratorodt.cpp \
|
||||||
@ -54,6 +55,7 @@ HEADERS += \
|
|||||||
ipcserver.h \
|
ipcserver.h \
|
||||||
mainwindow.h \
|
mainwindow.h \
|
||||||
clicklabel.h \
|
clicklabel.h \
|
||||||
|
previewcoordinator.h \
|
||||||
previewgenerator.h \
|
previewgenerator.h \
|
||||||
previewgeneratormapfunctor.h \
|
previewgeneratormapfunctor.h \
|
||||||
previewgeneratorodt.h \
|
previewgeneratorodt.h \
|
||||||
|
97
gui/previewcoordinator.cpp
Parasts fails
97
gui/previewcoordinator.cpp
Parasts fails
@ -0,0 +1,97 @@
|
|||||||
|
#include "previewcoordinator.h"
|
||||||
|
#include <QFileInfo>
|
||||||
|
|
||||||
|
PreviewCoordinator::PreviewCoordinator()
|
||||||
|
{
|
||||||
|
this->ipcPreviewClient.moveToThread(&this->ipcClientThread);
|
||||||
|
|
||||||
|
connect(&ipcPreviewClient, &IPCPreviewClient::previewReceived, this, &PreviewCoordinator::handleReceivedPreview,
|
||||||
|
Qt::QueuedConnection);
|
||||||
|
connect(&ipcPreviewClient, &IPCPreviewClient::finished, this, [&] { emit completedGeneration(); });
|
||||||
|
connect(this, &PreviewCoordinator::ipcStartGeneration, &ipcPreviewClient, &IPCPreviewClient::startGeneration,
|
||||||
|
Qt::QueuedConnection);
|
||||||
|
|
||||||
|
this->ipcClientThread.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
void PreviewCoordinator::init(const QVector<SearchResult> &searchResults)
|
||||||
|
{
|
||||||
|
this->previewableSearchResults.clear();
|
||||||
|
for(const SearchResult &result : searchResults)
|
||||||
|
{
|
||||||
|
if(result.wasContentSearch)
|
||||||
|
{
|
||||||
|
QString path = result.fileData.absPath;
|
||||||
|
// HACK until we can preview them properly
|
||||||
|
if(path.endsWith(".html") || path.endsWith(".htm"))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
QFileInfo info{path};
|
||||||
|
if(info.exists())
|
||||||
|
{
|
||||||
|
this->previewableSearchResults.append(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void PreviewCoordinator::setSocketPath(QString socketPath)
|
||||||
|
{
|
||||||
|
this->socketPath = socketPath;
|
||||||
|
this->ipcPreviewClient.setSocketPath(socketPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
int PreviewCoordinator::previewableCount() const
|
||||||
|
{
|
||||||
|
return this->previewableSearchResults.count();
|
||||||
|
}
|
||||||
|
|
||||||
|
QSharedPointer<PreviewResult> PreviewCoordinator::resultAt(int index)
|
||||||
|
{
|
||||||
|
if(this->previewResults.size() > index)
|
||||||
|
{
|
||||||
|
return {this->previewResults[index]};
|
||||||
|
}
|
||||||
|
return {nullptr};
|
||||||
|
}
|
||||||
|
|
||||||
|
const QVector<SearchResult> &PreviewCoordinator::getPreviewableSearchResults() const
|
||||||
|
{
|
||||||
|
return this->previewableSearchResults;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PreviewCoordinator::handleReceivedPreview(QSharedPointer<PreviewResult> preview, unsigned int previewGeneration)
|
||||||
|
{
|
||||||
|
if(previewGeneration < this->currentPreviewGeneration)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(!preview.isNull() && preview->hasPreview())
|
||||||
|
{
|
||||||
|
QString docPath = preview->getDocumentPath();
|
||||||
|
auto previewPage = preview->getPage();
|
||||||
|
int pos = previewOrder[docPath + QString::number(previewPage)];
|
||||||
|
this->previewResults[pos] = preview;
|
||||||
|
emit previewReady();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void PreviewCoordinator::startGeneration(RenderConfig config, const QVector<RenderTarget> &targets)
|
||||||
|
{
|
||||||
|
++this->currentPreviewGeneration;
|
||||||
|
|
||||||
|
this->previewOrder.clear();
|
||||||
|
this->previewResults.clear();
|
||||||
|
|
||||||
|
this->previewResults.resize(targets.size());
|
||||||
|
this->previewResults.fill(nullptr);
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
for(const RenderTarget &target : targets)
|
||||||
|
{
|
||||||
|
this->previewOrder[target.path + QString::number(target.page)] = i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
emit ipcStartGeneration(config, targets);
|
||||||
|
}
|
48
gui/previewcoordinator.h
Parasts fails
48
gui/previewcoordinator.h
Parasts fails
@ -0,0 +1,48 @@
|
|||||||
|
#ifndef PREVIEWCOORDINATOR_H
|
||||||
|
#define PREVIEWCOORDINATOR_H
|
||||||
|
#include <QVector>
|
||||||
|
#include <QObject>
|
||||||
|
#include <QThread>
|
||||||
|
#include "searchresult.h"
|
||||||
|
#include "previewresult.h"
|
||||||
|
#include "ipcpreviewclient.h"
|
||||||
|
#include "rendertarget.h"
|
||||||
|
class PreviewCoordinator : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
private:
|
||||||
|
QThread ipcClientThread;
|
||||||
|
IPCPreviewClient ipcPreviewClient;
|
||||||
|
QString socketPath;
|
||||||
|
|
||||||
|
QVector<QSharedPointer<PreviewResult>> previewResults;
|
||||||
|
QVector<SearchResult> previewableSearchResults;
|
||||||
|
|
||||||
|
unsigned int currentPreviewGeneration = 1;
|
||||||
|
|
||||||
|
/* Quick lookup table for the order a preview should have */
|
||||||
|
QHash<QString, int> previewOrder;
|
||||||
|
|
||||||
|
public:
|
||||||
|
PreviewCoordinator();
|
||||||
|
|
||||||
|
void init(const QVector<SearchResult> &searchResults);
|
||||||
|
|
||||||
|
int previewableCount() const;
|
||||||
|
const QVector<SearchResult> &getPreviewableSearchResults() const;
|
||||||
|
|
||||||
|
QSharedPointer<PreviewResult> resultAt(int index);
|
||||||
|
|
||||||
|
void setSocketPath(QString socketPath);
|
||||||
|
public slots:
|
||||||
|
void startGeneration(RenderConfig config, const QVector<RenderTarget> &targets);
|
||||||
|
void handleReceivedPreview(QSharedPointer<PreviewResult> preview, unsigned int previewGeneration);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void previewReady();
|
||||||
|
void completedGeneration();
|
||||||
|
void error(QString);
|
||||||
|
void ipcStartGeneration(RenderConfig config, const QVector<RenderTarget> &targets);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // PREVIEWCOORDINATOR_H
|
Notiek ielāde…
Atsaukties uz šo jaunā problēmā
Block a user