]> git.sesse.net Git - kdenlive/blob - renderer/renderjob.cpp
No error message if jobViewServer is unavailable, fix timeout on Notify popups
[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 << "-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     if (m_jobUiserver) 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         if (m_jobUiserver) QDBusReply<QString> reply = m_jobUiserver->call("setPercent", (uint) m_progress);
71     }
72 }
73
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)));
82
83         QDBusConnection::sessionBus().connect("org.kde.JobViewServer", reply, "org.kde.JobView",
84                                           "cancelRequested", this, SLOT(slotAbort()));
85     }
86     m_renderProcess->start(m_prog, m_args);
87 }
88
89
90 void RenderJob::slotIsOver(int exitcode, QProcess::ExitStatus status) {
91     if (m_jobUiserver) QDBusReply<QString> reply = m_jobUiserver->call("terminate", "");
92     if (m_erase) {
93         QFile f(m_scenelist);
94         f.remove();
95     }
96     if (status == QProcess::CrashExit) {
97         // rendering crashed
98         QStringList args;
99         args << "--error" << tr("Rendering of %1 aborted, resulting video will probably be corrupted.").arg(m_dest);
100         QProcess::startDetached("kdialog", args);
101     } else {
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",
107                                               "Notify");
108                         QList<QVariant> args;
109                         uint id = 0;
110                         int timeout = 5000;
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
120
121                         m.setArguments( args );
122                         QDBusMessage replyMsg = QDBusConnection::sessionBus().call(m);
123                 }
124
125                 if (m_player != "-") {
126                         QStringList args;
127                         args << m_dest;
128                         QProcess::startDetached(m_player, args);
129                 }
130     }
131     qApp->quit();
132 }
133
134 #include "renderjob.moc"