Commit 61de26d5 authored by Vincent Pinon's avatar Vincent Pinon
Browse files

Fix 'abort/remove job' button toggling

parent b520e187
*~
build/*
build/
CMakeLists.txt.user*
*.kdev4
po
*.patch
packaging/flatpak/.flatpak-builder
......
......@@ -251,6 +251,13 @@ void RenderJob::start()
connect(m_kdenlivesocket, &QLocalSocket::connected, this, [this](){
m_kdenlivesocket->write(QJsonDocument({{"url", m_dest}}).toJson());
m_kdenlivesocket->flush();
QJsonObject method, args;
args["url"] = m_dest;
args["progress"] = 0;
args["frame"] = 0;
method["setRenderingProgress"] = args;
m_kdenlivesocket->write(QJsonDocument(method).toJson());
m_kdenlivesocket->flush();
});
connect(m_kdenlivesocket, &QLocalSocket::readyRead, this, [this](){
QByteArray msg = m_kdenlivesocket->readAll();
......
......@@ -19,9 +19,12 @@ RenderServer::RenderServer(QObject *parent)
if (m_server.listen(servername)) {
connect(&m_server, &QLocalServer::newConnection, this, &RenderServer::jobConnected);
} else {
pCore->displayMessage(i18n("Can't open communication with render job %1").arg(servername), ErrorMessage);
pCore->displayMessage(i18n("Can't open communication with render job %1", servername), ErrorMessage);
qWarning() << "Render server failed to listen on " << servername;
}
connect(pCore->window(), &MainWindow::abortRenderJob, this, &RenderServer::abortJob);
connect(this, &RenderServer::setRenderingProgress, pCore->window(), &MainWindow::setRenderingProgress);
connect(this, &RenderServer::setRenderingFinished, pCore->window(), &MainWindow::setRenderingFinished);
}
RenderServer::~RenderServer() {}
......@@ -33,29 +36,36 @@ void RenderServer::jobConnected()
}
void RenderServer::jobSent() {
QJsonParseError error;
QLocalSocket* socket = reinterpret_cast<QLocalSocket*>(sender());
const QByteArray bytes = socket->readAll();
const QJsonObject json = QJsonDocument::fromJson(bytes, &error).object();
if (error.error != QJsonParseError::NoError) {
pCore->displayMessage(i18n("Communication error with render job %1 %2")
.arg(error.errorString(), bytes), ErrorMessage);
}
if (json.contains("url")) {
m_jobSocket[json["url"].toString()] = socket;
}
if (json.contains("setRenderingProgress")) {
pCore->window()->setRenderingProgress(
json["setRenderingProgress"]["url"].toString(),
json["setRenderingProgress"]["progress"].toInt(),
json["setRenderingProgress"]["frame"].toInt());
}
if (json.contains("setRenderingFinished")) {
pCore->window()->setRenderingFinished(
json["setRenderingFinished"]["url"].toString(),
json["setRenderingFinished"]["status"].toInt(),
json["setRenderingFinished"]["error"].toString());
m_jobSocket.remove(json["setRenderingFinished"]["url"].toString());
QTextStream text(socket);
QString block, line;
while(text.readLineInto(&line)) {
block.append(line);
if(line == QLatin1String("}")) { // end of json object
QJsonParseError error;
const QJsonObject json = QJsonDocument::fromJson(block.toUtf8(), &error).object();
if (error.error != QJsonParseError::NoError) {
pCore->displayMessage(i18n("Communication error with render job"), ErrorMessage);
qWarning() << "RenderServer recieve error: " << error.errorString() << block;
}
if (json.contains("url")) {
m_jobSocket[json["url"].toString()] = socket;
}
if (json.contains("setRenderingProgress")) {
emit setRenderingProgress(
json["setRenderingProgress"]["url"].toString(),
json["setRenderingProgress"]["progress"].toInt(),
json["setRenderingProgress"]["frame"].toInt());
}
if (json.contains("setRenderingFinished")) {
emit setRenderingFinished(
json["setRenderingFinished"]["url"].toString(),
json["setRenderingFinished"]["status"].toInt(),
json["setRenderingFinished"]["error"].toString());
m_jobSocket.remove(json["setRenderingFinished"]["url"].toString());
}
block.clear();
}
}
}
......@@ -64,6 +74,6 @@ void RenderServer::abortJob(const QString &job) {
m_jobSocket[job]->write("abort");
m_jobSocket[job]->flush();
} else {
pCore->displayMessage(i18n("Can't open communication with render job %1").arg(job), ErrorMessage);
pCore->displayMessage(i18n("Can't open communication with render job %1", job), ErrorMessage);
}
}
......@@ -19,6 +19,10 @@ public:
RenderServer(QObject *parent);
~RenderServer() override;
signals:
void setRenderingProgress(const QString &url, int progress, int frame);
void setRenderingFinished(const QString &url, int status, const QString &error);
public slots:
void abortJob(const QString &job);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment