gui: IpcServer: Use IPCPreviewWorker

This commit is contained in:
Albert S. 2022-05-27 09:26:37 +02:00
rodič 6439adffc6
revize 3e03fed1a2
2 změnil soubory, kde provedl 28 přidání a 8 odebrání

Zobrazit soubor

@ -3,8 +3,13 @@
enum IPCCommand enum IPCCommand
{ {
DocOpen, GeneratePreviews = 23,
FileOpen, StopGeneratePreviews,
AddFile,
}; };
enum IPCReply
{
FinishedGeneratePreviews,
};
#endif // IPC_H #endif // IPC_H

Zobrazit soubor

@ -9,6 +9,9 @@
#include "common.h" #include "common.h"
#include "databasefactory.h" #include "databasefactory.h"
#include "../shared/logger.h" #include "../shared/logger.h"
#include "renderconfig.h"
#include "rendertarget.h"
#include "ipcpreviewworker.h"
IpcServer::IpcServer() IpcServer::IpcServer()
{ {
@ -23,22 +26,34 @@ bool IpcServer::startSpawner(QString socketPath)
void IpcServer::spawnerNewConnection() void IpcServer::spawnerNewConnection()
{ {
QScopedPointer<QLocalSocket> socket{this->spawningServer.nextPendingConnection()}; QLocalSocket *socket = this->spawningServer.nextPendingConnection();
if(!socket.isNull()) connect(socket, &QLocalSocket::disconnected, socket, &QLocalSocket::deleteLater);
if(socket != nullptr)
{ {
if(!socket->waitForReadyRead()) if(!socket->waitForReadyRead())
{ {
return; return;
} }
QDataStream stream(socket.get()); QDataStream stream(socket);
IPCCommand command; IPCCommand command;
stream >> command; stream >> command;
if(command == GeneratePreviews) if(command == GeneratePreviews)
{ {
IPCPreviewWorker *worker = new IPCPreviewWorker();
RenderConfig renderConfig; RenderConfig renderConfig;
QVector<RenderTarget> targets; QVector<RenderTarget> targets;
stream >> renderConfig;
stream >> targets; do
{
/* TODO: this is not entirely robust */
socket->waitForReadyRead(100);
stream.startTransaction();
stream >> renderConfig >> targets;
} while(!stream.commitTransaction() && socket->state() == QLocalSocket::ConnectedState);
stream << targets.count();
socket->flush();
worker->start(renderConfig, targets, socket);
} }
} }
} }