+void RenderJob::receivedStderr()
+{
+ QString result = QString::fromLocal8Bit(m_renderProcess->readAllStandardError()).simplified();
+ //fprintf(stderr, "* * * *RENDER LG: %s\n", result.toUtf8().data());
+ if (!result.startsWith(QLatin1String("Current Frame"))) m_errorMessage.append(result + QLatin1String("<br>"));
+ else {
+ if (m_enablelog) m_logstream << "ReceivedStderr from melt: " << result << endl;
+ result = result.section(QLatin1Char(' '), -1);
+ int pro = result.toInt();
+ if (pro < 0 || pro > 100) return;
+ if (pro > m_progress) {
+ m_progress = pro;
+ if (m_args.contains(QLatin1String("pass=1"))) {
+ m_progress /= 2.0;
+ } else if (m_args.contains(QLatin1String("pass=2"))) {
+ m_progress = 50 + m_progress / 2.0;
+ }
+ if (m_kdenliveinterface) {
+ if (!m_kdenliveinterface->isValid()) {
+ delete m_kdenliveinterface;
+ m_kdenliveinterface = NULL;
+ // qDebug() << "BROKEN COMMUNICATION WITH KDENLIVE";
+ } else {
+ m_dbusargs[1] = m_progress;
+ m_kdenliveinterface->callWithArgumentList(QDBus::NoBlock, QLatin1String("setRenderingProgress"), m_dbusargs);
+ }
+ } else if (pro % 5 == 0) {
+ // Try to restart communication with Kdenlive every 5 percents
+ // qDebug() << "TRYING TO RESTART COMMUNICATION WITH KDENLIVE";
+ initKdenliveDbusInterface();
+ }
+
+ if (m_jobUiserver) {
+ m_jobUiserver->call(QLatin1String("setPercent"), (uint) m_progress);
+ /*int seconds = m_startTime.secsTo(QTime::currentTime());
+ seconds = seconds * (100 - m_progress) / m_progress;
+ m_jobUiserver->call("setDescriptionField", (uint) 1, tr("Remaining time"), QTime().addSecs(seconds).toString("hh:mm:ss"));*/
+ }
+ }
+ }
+}
+
+void RenderJob::start()
+{
+ QDBusConnectionInterface* interface = QDBusConnection::sessionBus().interface();
+ if (interface && m_usekuiserver) {
+ if (!interface->isServiceRegistered(QLatin1String("org.kde.JobViewServer"))) {
+ qDebug() << "No org.kde.JobViewServer registered, trying to start kuiserver";
+ if (m_enablelog) m_logstream << "No org.kde.JobViewServer registered, trying to start kuiserver";
+ if (QProcess::startDetached(QLatin1String("kuiserver"))) {
+ qDebug() << "Started kuiserver";
+ if (m_enablelog) m_logstream << "Started kuiserver";
+ // Give it a couple of seconds to start
+ QTime t;
+ t.start();
+ while (!interface->isServiceRegistered(QLatin1String("org.kde.JobViewServer")) && t.elapsed() < 3000) {
+ SleepThread::msleep(100); //Sleep 100 ms
+ }
+ } else {
+ qDebug() << "Failed to start kuiserver";
+ if (m_enablelog) m_logstream << "Failed to start kuiserver";
+ }
+ }
+
+ if (interface->isServiceRegistered(QLatin1String("org.kde.JobViewServer"))) {
+ QDBusInterface kuiserver(QLatin1String("org.kde.JobViewServer"), QLatin1String("/JobViewServer"), QLatin1String("org.kde.JobViewServer"));
+ QDBusReply<QDBusObjectPath> objectPath = kuiserver.call(QLatin1String("requestView"),QLatin1String("Kdenlive"), QLatin1String("kdenlive"), 0x0001);
+ QString reply = ((QDBusObjectPath) objectPath).path();
+
+ // Use of the KDE JobViewServer is an ugly hack, it is not reliable
+ QString dbusView = QLatin1String("org.kde.JobViewV2");
+ m_jobUiserver = new QDBusInterface(QLatin1String("org.kde.JobViewServer"), reply, dbusView);
+ if (!m_jobUiserver || !m_jobUiserver->isValid()) {
+ dbusView = QLatin1String("org.kde.JobView");
+ m_jobUiserver = new QDBusInterface(QLatin1String("org.kde.JobViewServer"), reply, dbusView);
+ }
+
+ if (m_jobUiserver && m_jobUiserver->isValid()) {
+ m_startTime = QTime::currentTime();
+ if (!m_args.contains(QLatin1String("pass=2")))
+ m_jobUiserver->call(QLatin1String("setPercent"), (uint) 0);
+ //m_jobUiserver->call("setInfoMessage", tr("Rendering %1").arg(QFileInfo(m_dest).fileName()));
+ m_jobUiserver->call(QLatin1String("setDescriptionField"), (uint) 0, tr("Rendering"), m_dest);
+ QDBusConnection::sessionBus().connect(QLatin1String("org.kde.JobViewServer"), reply, dbusView, QLatin1String("cancelRequested"), this, SLOT(slotAbort()));
+ }
+ }
+ }
+
+ initKdenliveDbusInterface();
+
+ // Make sure the destination file is writable
+ QFile checkDestination(m_dest);
+ if (!checkDestination.open(QIODevice::WriteOnly)) {
+ slotIsOver(QProcess::NormalExit, false);
+ }
+ checkDestination.close();
+
+ // Because of the logging, we connect to stderr in all cases.
+ connect(m_renderProcess, SIGNAL(readyReadStandardError()), this, SLOT(receivedStderr()));