]> git.sesse.net Git - kdenlive/blob - renderer/renderjob.cpp
* use KNotify so that now users get a popup when a rendering starts / ends
[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, 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;
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 << preargs;
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);
46 }
47
48
49 RenderJob::~RenderJob() {
50     if (m_renderProcess) delete m_renderProcess;
51 }
52
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", "");
57     if (m_erase) {
58         QFile f(m_scenelist);
59         f.remove();
60     }
61     QFile f(m_dest);
62     f.remove();
63     qApp->quit();
64 }
65
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) {
72         m_progress = pro;
73         if (m_jobUiserver) QDBusReply<QString> reply = m_jobUiserver->call("setPercent", (uint) m_progress);
74     }
75 }
76
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)));
85
86         QDBusConnection::sessionBus().connect("org.kde.JobViewServer", reply, "org.kde.JobView",
87                                           "cancelRequested", this, SLOT(slotAbort()));
88     }
89     m_renderProcess->start(m_prog, m_args);
90 }
91
92
93 void RenderJob::slotIsOver(int exitcode, QProcess::ExitStatus status) {
94     if (m_jobUiserver) QDBusReply<QString> reply = m_jobUiserver->call("terminate", "");
95     if (m_erase) {
96         QFile f(m_scenelist);
97         f.remove();
98     }
99     if (status == QProcess::CrashExit) {
100         // rendering crashed
101         QStringList args;
102         args << "--error" << tr("Rendering of %1 aborted, resulting video will probably be corrupted.").arg(m_dest);
103         QProcess::startDetached("kdialog", args);
104     } else {
105         QDBusConnectionInterface* interface = QDBusConnection::sessionBus().interface();
106         if (interface && interface->isServiceRegistered("org.kde.knotify")) {
107                         QDBusMessage m = QDBusMessage::createMethodCall("org.kde.knotify",
108                                               "/Notify",
109                                               "org.kde.KNotify",
110                                               "event");
111
112                         QList<QVariant> args;
113                         args.append( QString("RenderFinished") ); // action name
114                         args.append( QString("kdenlive") ); // app name
115                         args.append( QVariantList() ); // contexts
116                         args.append( tr("Rendering of %1 is over").arg(m_dest) ); // body
117                         args.append( QByteArray() ); // app icon
118                         QStringList actionList;
119                         args.append( actionList ); // actions
120                         qlonglong wid;
121                         args.append( wid ); // win id
122
123                         /*
124                         uint id = 0;
125                         int timeout = 5000;
126                         QDBusMessage m = QDBusMessage::createMethodCall("org.kde.VisualNotifications",
127                                               "/VisualNotifications",
128                                               "org.kde.VisualNotifications",
129                                               "Notify");
130
131                         args.append( QString("kdenlive") ); // app_name
132                         args.append( id ); // replaces_id
133                         args.append( QString("kdenlive") ); // app_icon
134                         args.append( tr("Rendering finished")); // summary
135                         args.append( tr("Rendering of %1 is over").arg(m_dest) ); // body
136                         QStringList actionList;
137                         args.append( actionList ); // actions
138                         args.append( QVariantMap() ); // hints - unused atm
139                         args.append( timeout ); // expire timout
140                         */
141
142                         m.setArguments( args );
143                         QDBusMessage replyMsg = QDBusConnection::sessionBus().call(m);
144                 }
145
146                 if (m_player != "-") {
147                         QStringList args;
148                         args << m_dest;
149                         QProcess::startDetached(m_player, args);
150                 }
151     }
152     qApp->quit();
153 }
154
155 #include "renderjob.moc"