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, const QString &renderer, const QString &profile, const QString &rendermodule, const QString &player, const QString &scenelist, const QString &dest, const QStringList &preargs, const QStringList &args, int in, int out) : QObject(), m_jobUiserver(NULL) {
29 m_scenelist = scenelist;
34 m_renderProcess = new QProcess;
37 if (in != -1) m_args << "in=" + QString::number(in);
38 if (out != -1) m_args << "out=" + QString::number(out);
40 //qDebug()<<"PRE ARGS: "<<preargs;
41 m_args << "-profile" << profile;
42 m_args << "-consumer" << rendermodule + ":" + m_dest << "progress=1" << args;
43 connect(m_renderProcess, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(slotIsOver(int, QProcess::ExitStatus)));
44 connect(m_renderProcess, SIGNAL(readyReadStandardError()), this, SLOT(receivedStderr()));
45 m_renderProcess->setReadChannel(QProcess::StandardError);
49 RenderJob::~RenderJob() {
50 if (m_renderProcess) delete m_renderProcess;
53 void RenderJob::slotAbort() {
54 qDebug() << "Kdenlive-render: JOBĀ ABORTED BY USER...";
55 m_renderProcess->kill();
56 if (m_jobUiserver) QDBusReply<QString> reply = m_jobUiserver->call("terminate", "");
66 void RenderJob::receivedStderr() {
67 QString result = QString(m_renderProcess->readAllStandardError());
68 result = result.simplified();
69 result = result.section(" ", -1);
70 int pro = result.toInt();
71 if (pro > m_progress) {
73 if (m_jobUiserver) QDBusReply<QString> reply = m_jobUiserver->call("setPercent", (uint) m_progress);
77 void RenderJob::start() {
78 QDBusConnectionInterface* interface = QDBusConnection::sessionBus().interface();
79 if (interface && interface->isServiceRegistered("org.kde.JobViewServer")) {
80 QDBusInterface kuiserver("org.kde.JobViewServer", "/JobViewServer", "org.kde.JobViewServer");
81 QDBusReply<QDBusObjectPath> objectPath = kuiserver.call("requestView", "kdenlive", "kdenlive", 1);
82 QString reply = ((QDBusObjectPath) objectPath).path();
83 m_jobUiserver = new QDBusInterface("org.kde.JobViewServer", reply, "org.kde.JobView");
84 m_jobUiserver->call("setInfoMessage", tr("Rendering %1").arg(m_dest.section('/', -1)));
86 QDBusConnection::sessionBus().connect("org.kde.JobViewServer", reply, "org.kde.JobView",
87 "cancelRequested", this, SLOT(slotAbort()));
89 m_renderProcess->start(m_prog, m_args);
93 void RenderJob::slotIsOver(int exitcode, QProcess::ExitStatus status) {
94 if (m_jobUiserver) QDBusReply<QString> reply = m_jobUiserver->call("terminate", "");
99 if (status == QProcess::CrashExit) {
102 args << "--error" << tr("Rendering of %1 aborted, resulting video will probably be corrupted.").arg(m_dest);
103 QProcess::startDetached("kdialog", args);
105 QDBusConnectionInterface* interface = QDBusConnection::sessionBus().interface();
106 if (interface && interface->isServiceRegistered("org.kde.VisualNotifications")) {
107 QDBusMessage m = QDBusMessage::createMethodCall("org.kde.VisualNotifications",
108 "/VisualNotifications",
109 "org.kde.VisualNotifications",
111 QList<QVariant> args;
114 args.append( QString("kdenlive") ); // app_name
115 args.append( id ); // replaces_id
116 args.append( QString("kdenlive") ); // app_icon
117 args.append( tr("Rendering finished")); // summary
118 args.append( tr("Rendering of %1 is over").arg(m_dest) ); // body
119 QStringList actionList;
120 args.append( actionList ); // actions
121 args.append( QVariantMap() ); // hints - unused atm
122 args.append( timeout ); // expire timout
124 m.setArguments( args );
125 QDBusMessage replyMsg = QDBusConnection::sessionBus().call(m);
128 if (m_player != "-") {
131 QProcess::startDetached(m_player, args);
137 #include "renderjob.moc"