]> git.sesse.net Git - kdenlive/blob - renderer/renderjob.cpp
3d5594221cc92b9e3141937f0a9b083374c5a0eb
[kdenlive] / renderer / renderjob.cpp
1 /***************************************************************************
2  *   Copyright (C) 2007 by Jean-Baptiste Mardelle (jb@kdenlive.org)        *
3  *                                                                         *
4  *   This program is free software; you can redistribute it and/or modify  *
5  *   it under the terms of the GNU General Public License as published by  *
6  *   the Free Software Foundation; either version 2 of the License, or     *
7  *   (at your option) any later version.                                   *
8  *                                                                         *
9  *   This program is distributed in the hope that it will be useful,       *
10  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
11  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
12  *   GNU General Public License for more details.                          *
13  *                                                                         *
14  *   You should have received a copy of the GNU General Public License     *
15  *   along with this program; if not, write to the                         *
16  *   Free Software Foundation, Inc.,                                       *
17  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
18  ***************************************************************************/
19
20
21 #include <QtDBus>
22
23 #include "renderjob.h"
24
25 static QDBusConnection connection(QLatin1String(""));
26
27 RenderJob::RenderJob(QString scenelist, QString dest, QString player) : QObject() {
28     m_scenelist = scenelist;
29     m_dest = dest;
30     m_player = player;
31     m_progress = 0;
32     m_renderProcess = new QProcess;
33     m_prog = "inigo";
34     m_args << scenelist << "-consumer" << "avformat:" + m_dest << "progress=1";
35     connect(m_renderProcess, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(slotIsOver(int, QProcess::ExitStatus)));
36     connect(m_renderProcess, SIGNAL(readyReadStandardError()), this, SLOT(receivedStderr()));
37     m_renderProcess->setReadChannel(QProcess::StandardError);
38 }
39
40
41 RenderJob::~RenderJob() {
42     delete m_renderProcess;
43 }
44
45 void RenderJob::receivedStderr() {
46     QString result = QString(m_renderProcess->readAllStandardError());
47     result = result.simplified();
48     result = result.section(" ", -1);
49     int pro = result.toInt();
50     if (pro > m_progress) {
51         m_progress = pro;
52         QDBusReply<QString> reply = m_jobUiserver->call("setPercent", (uint) m_progress);
53     }
54 }
55
56 void RenderJob::start() {
57     QDBusInterface kuiserver("org.kde.JobViewServer", "/JobViewServer", "org.kde.JobViewServer", QDBusConnection::sessionBus());
58     QDBusReply<QString> reply = kuiserver.call("requestView", "kdenlive", "kdenlive", 1);
59     //kDebug()<<"///// JOB REPLY: "<<reply;
60     QStringList args;
61     m_jobUiserver = new QDBusInterface("org.kde.JobViewServer", "/JobViewServer/JobView_1", "org.kde.JobView", QDBusConnection::sessionBus());
62     reply = m_jobUiserver->call("setInfoMessage", tr("Rendering %1").arg(m_dest));
63     m_renderProcess->start(m_prog, m_args);
64 }
65
66
67 void RenderJob::slotIsOver(int exitcode, QProcess::ExitStatus status) {
68     QDBusReply<QString> reply = m_jobUiserver->call("terminate", "");
69     if (!m_player.isEmpty()) {
70         QStringList args;
71         args<<m_dest;
72         QProcess::startDetached(m_player, args);
73     }
74     exit(1);
75 }
76
77 #include "renderjob.moc"