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