gui: IpcServer: Use IPCPreviewWorker

このコミットが含まれているのは:
Albert S. 2022-05-27 09:26:37 +02:00
コミット 3e03fed1a2
2個のファイルの変更28行の追加8行の削除

ファイルの表示

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

ファイルの表示

@ -9,6 +9,9 @@
#include "common.h"
#include "databasefactory.h"
#include "../shared/logger.h"
#include "renderconfig.h"
#include "rendertarget.h"
#include "ipcpreviewworker.h"
IpcServer::IpcServer()
{
@ -23,22 +26,34 @@ bool IpcServer::startSpawner(QString socketPath)
void IpcServer::spawnerNewConnection()
{
QScopedPointer<QLocalSocket> socket{this->spawningServer.nextPendingConnection()};
if(!socket.isNull())
QLocalSocket *socket = this->spawningServer.nextPendingConnection();
connect(socket, &QLocalSocket::disconnected, socket, &QLocalSocket::deleteLater);
if(socket != nullptr)
{
if(!socket->waitForReadyRead())
{
return;
}
QDataStream stream(socket.get());
QDataStream stream(socket);
IPCCommand command;
stream >> command;
if(command == GeneratePreviews)
{
IPCPreviewWorker *worker = new IPCPreviewWorker();
RenderConfig renderConfig;
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);
}
}
}