1 /***************************************************************************
2 * Copyright (C) 2007 by Jean-Baptiste Mardelle (jb@kdenlive.org) *
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. *
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. *
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 ***************************************************************************/
24 #include "renderjob.h"
26 static QDBusConnection connection(QLatin1String(""));
28 RenderJob::RenderJob(bool erase, QString renderer, QString profile, QString rendermodule, QString player, QString scenelist, QString dest, QStringList args, int in, int out) : QObject(), m_jobUiserver(NULL) {
29 m_scenelist = scenelist;
34 m_renderProcess = new QProcess;
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);
46 RenderJob::~RenderJob() {
47 if (m_renderProcess) delete m_renderProcess;
50 void RenderJob::slotAbort() {
51 qDebug() << "Kdenlive-render: JOBĀ ABORTED BY USER...";
52 m_renderProcess->kill();
53 if (m_jobUiserver) QDBusReply<QString> reply = m_jobUiserver->call("terminate", "");
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) {
70 if (m_jobUiserver) QDBusReply<QString> reply = m_jobUiserver->call("setPercent", (uint) m_progress);
74 void RenderJob::start() {
75 QDBusConnectionInterface* interface = QDBusConnection::sessionBus().interface();
76 if (interface && interface->isServiceRegistered("org.kde.JobViewServer")) {
77 QDBusInterface kuiserver("org.kde.JobViewServer", "/JobViewServer", "org.kde.JobViewServer");
78 QDBusReply<QDBusObjectPath> objectPath = kuiserver.call("requestView", "kdenlive", "kdenlive", 1);
79 QString reply = ((QDBusObjectPath) objectPath).path();
80 m_jobUiserver = new QDBusInterface("org.kde.JobViewServer", reply, "org.kde.JobView");
81 m_jobUiserver->call("setInfoMessage", tr("Rendering %1").arg(m_dest.section('/', -1)));
83 QDBusConnection::sessionBus().connect("org.kde.JobViewServer", reply, "org.kde.JobView",
84 "cancelRequested", this, SLOT(slotAbort()));
86 m_renderProcess->start(m_prog, m_args);
90 void RenderJob::slotIsOver(int exitcode, QProcess::ExitStatus status) {
91 if (m_jobUiserver) QDBusReply<QString> reply = m_jobUiserver->call("terminate", "");
96 if (status == QProcess::CrashExit) {
99 args << "--error" << tr("Rendering of %1 aborted, resulting video will probably be corrupted.").arg(m_dest);
100 QProcess::startDetached("kdialog", args);
102 QDBusConnectionInterface* interface = QDBusConnection::sessionBus().interface();
103 if (interface && interface->isServiceRegistered("org.kde.VisualNotifications")) {
104 QDBusMessage m = QDBusMessage::createMethodCall("org.kde.VisualNotifications",
105 "/VisualNotifications",
106 "org.kde.VisualNotifications",
108 QList<QVariant> args;
111 args.append( QString("kdenlive") ); // app_name
112 args.append( id ); // replaces_id
113 args.append( QString("kdenlive") ); // app_icon
114 args.append( tr("Rendering finished")); // summary
115 args.append( tr("Rendering of %1 is over").arg(m_dest) ); // body
116 QStringList actionList;
117 args.append( actionList ); // actions
118 args.append( QVariantMap() ); // hints - unused atm
119 args.append( timeout ); // expire timout
121 m.setArguments( args );
122 QDBusMessage replyMsg = QDBusConnection::sessionBus().call(m);
125 if (m_player != "-") {
128 QProcess::startDetached(m_player, args);
134 #include "renderjob.moc"