]> git.sesse.net Git - kdenlive/blob - renderer/renderjob.cpp
activate monitor when clicking in timeline + small renderer update
[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(bool erase, QString renderer, QString rendermodule, QString player, QString scenelist, QString dest, QStringList args, int in, int out) : QObject() {
28     m_scenelist = scenelist;
29     m_dest = dest;
30     m_player = player;
31     m_progress = 0;
32     m_erase = erase;
33     m_renderProcess = new QProcess;
34     m_prog = renderer;
35     m_args << scenelist;
36     if (in != -1) m_args << "in=" + QString::number(in);
37     if (out != -1) m_args << "out=" + QString::number(out);
38     m_args << "-consumer" << rendermodule + ":" + m_dest << "progress=1" << args;
39     connect(m_renderProcess, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(slotIsOver(int, QProcess::ExitStatus)));
40     connect(m_renderProcess, SIGNAL(readyReadStandardError()), this, SLOT(receivedStderr()));
41     m_renderProcess->setReadChannel(QProcess::StandardError);
42 }
43
44
45 RenderJob::~RenderJob() {
46     if (m_renderProcess) delete m_renderProcess;
47 }
48
49 void RenderJob::slotAbort() {
50     fprintf(stderr, "Kdenlive-render: JOBĀ ABORTED BY USER...\n");
51     m_renderProcess->kill();
52     QDBusReply<QString> reply = m_jobUiserver->call("terminate", "");
53     if (m_erase) {
54         QFile f(m_scenelist);
55         f.remove();
56     }
57     QFile f(m_dest);
58     f.remove();
59     exit(1);
60 }
61
62 void RenderJob::receivedStderr() {
63     QString result = QString(m_renderProcess->readAllStandardError());
64     result = result.simplified();
65     result = result.section(" ", -1);
66     int pro = result.toInt();
67     if (pro > m_progress) {
68         m_progress = pro;
69         QDBusReply<QString> reply = m_jobUiserver->call("setPercent", (uint) m_progress);
70     }
71 }
72
73 void RenderJob::start() {
74     QDBusInterface kuiserver("org.kde.JobViewServer", "/JobViewServer", "org.kde.JobViewServer");
75     QDBusReply<QDBusObjectPath> objectPath = kuiserver.call("requestView", "kdenlive", "kdenlive", 1);
76     QString reply = ((QDBusObjectPath) objectPath).path();
77     m_jobUiserver = new QDBusInterface("org.kde.JobViewServer", reply, "org.kde.JobView");
78     m_jobUiserver->call("setInfoMessage", tr("Rendering %1").arg(m_dest));
79
80     QDBusConnection::sessionBus().connect("org.kde.JobViewServer", reply, "org.kde.JobView",
81                                           "cancelRequested", this, SLOT(slotAbort()));
82     m_renderProcess->start(m_prog, m_args);
83 }
84
85
86 void RenderJob::slotIsOver(int exitcode, QProcess::ExitStatus status) {
87     QDBusReply<QString> reply = m_jobUiserver->call("terminate", "");
88     if (m_erase) {
89         QFile f(m_scenelist);
90         f.remove();
91     }
92     if (status == QProcess::CrashExit) {
93         // rendering crashed
94         QStringList args;
95         args << "--error" << tr("Rendering of %1 aborted, resulting video will probably be corrupted.").arg(m_dest);
96         QProcess::startDetached("kdialog", args);
97     } else if (m_player != "-") {
98         QStringList args;
99         args << m_dest;
100         QProcess::startDetached(m_player, args);
101     }
102     exit(1);
103 }
104
105 #include "renderjob.moc"