]> git.sesse.net Git - kdenlive/blob - renderer/renderjob.cpp
9a642f3867714d312f0ce6e423396c10de685096
[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 #include <QFile>
23
24 #include "renderjob.h"
25
26 static QDBusConnection connection(QLatin1String(""));
27
28 RenderJob::RenderJob(bool erase, QString renderer, QString profile, QString rendermodule, QString player, QString scenelist, QString dest, QStringList args, int in, int out) {
29     m_scenelist = scenelist;
30     m_dest = dest;
31     m_player = player;
32     m_progress = 0;
33     m_erase = erase;
34     m_renderProcess = new QProcess;
35     m_prog = renderer;
36     m_args << "-profile" << profile << scenelist;
37     if (in != -1) m_args << "in=" + QString::number(in);
38     if (out != -1) m_args << "out=" + QString::number(out);
39     m_args << "-consumer" << rendermodule + ":" + m_dest << "progress=1" << args;
40     connect(m_renderProcess, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(slotIsOver(int, QProcess::ExitStatus)));
41     connect(m_renderProcess, SIGNAL(readyReadStandardError()), this, SLOT(receivedStderr()));
42     m_renderProcess->setReadChannel(QProcess::StandardError);
43 }
44
45
46 RenderJob::~RenderJob() {
47     if (m_renderProcess) delete m_renderProcess;
48 }
49
50 void RenderJob::slotAbort() {
51     qDebug() << "Kdenlive-render: JOBĀ ABORTED BY USER...";
52     m_renderProcess->kill();
53     QDBusReply<QString> reply = m_jobUiserver->call("terminate", "");
54     if (m_erase) {
55         QFile f(m_scenelist);
56         f.remove();
57     }
58     QFile f(m_dest);
59     f.remove();
60     qApp->quit();
61 }
62
63 void RenderJob::receivedStderr() {
64     QString result = QString(m_renderProcess->readAllStandardError());
65     result = result.simplified();
66     result = result.section(" ", -1);
67     int pro = result.toInt();
68     if (pro > m_progress) {
69         m_progress = pro;
70         QDBusReply<QString> reply = m_jobUiserver->call("setPercent", (uint) m_progress);
71     }
72 }
73
74 void RenderJob::start() {
75     QDBusInterface kuiserver("org.kde.JobViewServer", "/JobViewServer", "org.kde.JobViewServer");
76     QDBusReply<QDBusObjectPath> objectPath = kuiserver.call("requestView", "kdenlive", "kdenlive", 1);
77     QString reply = ((QDBusObjectPath) objectPath).path();
78     m_jobUiserver = new QDBusInterface("org.kde.JobViewServer", reply, "org.kde.JobView");
79     m_jobUiserver->call("setInfoMessage", tr("Rendering %1").arg(m_dest.section('/', -1)));
80
81     QDBusConnection::sessionBus().connect("org.kde.JobViewServer", reply, "org.kde.JobView",
82                                           "cancelRequested", this, SLOT(slotAbort()));
83     m_renderProcess->start(m_prog, m_args);
84 }
85
86
87 void RenderJob::slotIsOver(int exitcode, QProcess::ExitStatus status) {
88     QDBusReply<QString> reply = m_jobUiserver->call("terminate", "");
89     if (m_erase) {
90         QFile f(m_scenelist);
91         f.remove();
92     }
93     if (status == QProcess::CrashExit) {
94         // rendering crashed
95         QStringList args;
96         args << "--error" << tr("Rendering of %1 aborted, resulting video will probably be corrupted.").arg(m_dest);
97         QProcess::startDetached("kdialog", args);
98     } else {
99                 QDBusConnectionInterface* interface = QDBusConnection::sessionBus().interface();
100         if (interface && interface->isServiceRegistered("org.kde.VisualNotifications")) {
101                         QDBusMessage m = QDBusMessage::createMethodCall("org.kde.VisualNotifications",
102                                               "/VisualNotifications",
103                                               "org.kde.VisualNotifications",
104                                               "Notify");
105                         QList<QVariant> args;
106                         uint id = 0;
107                         int timeout = 5;
108                         args.append( QString("kdenlive") ); // app_name
109                         args.append( id ); // replaces_id
110                         args.append( QString("kdenlive") ); // app_icon
111                         args.append( tr("Rendering finished")); // summary
112                         args.append( tr("Rendering of %1 is over").arg(m_dest) ); // body
113                         QStringList actionList;
114                         args.append( actionList ); // actions
115                         args.append( QVariantMap() ); // hints - unused atm
116                         args.append( timeout ); // expire timout
117
118                         m.setArguments( args );
119                         QDBusMessage replyMsg = QDBusConnection::sessionBus().call(m);
120                 }
121
122                 if (m_player != "-") {
123                         QStringList args;
124                         args << m_dest;
125                         QProcess::startDetached(m_player, args);
126                 }
127     }
128     qApp->quit();
129 }
130
131 #include "renderjob.moc"