]> git.sesse.net Git - kdenlive/blob - src/renderjob.cpp
Autodetect jogshuttle device, improve handling
[kdenlive] / src / 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 <KDebug>
22 #include <KLocale>
23 #include <kuiserverjobtracker.h>
24
25 #include "renderjob.h"
26 #include "timecode.h"
27 #include "kdenlivesettings.h"
28
29
30
31 RenderJob::RenderJob(KUrl scenelist, KUrl dest) : KJob(), m_scenelist(scenelist), m_dest(dest), m_progress(0) {
32     m_renderProcess = new KProcess;
33     *m_renderProcess << "inigo" << scenelist.path() << "-consumer" << "avformat:" + m_dest.path() << "progress=1";
34     connect(m_renderProcess, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(slotIsOver(int, QProcess::ExitStatus)));
35     connect(m_renderProcess, SIGNAL(readyReadStandardOutput()), this, SLOT(receivedStderr()));
36     connect(m_renderProcess, SIGNAL(readyReadStandardError()), this, SLOT(receivedStderr()));
37     m_renderProcess->setOutputChannelMode(KProcess::OnlyStderrChannel);
38     m_renderProcess->start();
39
40 }
41
42
43 RenderJob::~RenderJob() {
44 }
45
46 void RenderJob::receivedStderr() {
47     QString result = QString(m_renderProcess->readAllStandardError());
48     result = result.simplified();
49     result = result.section(" ", -1);
50     int pro = result.toInt();
51     if (pro > m_progress) {
52         m_progress = pro;
53         update();
54     }
55 }
56
57 void RenderJob::start() {
58     registerJob(this);
59 }
60
61 void RenderJob::registerJob(KJob *job) {
62     KIO::getJobTracker()->registerJob(job);
63     emit description(this, "Rendering " + m_dest.fileName(),
64                      qMakePair(QString("source"), m_scenelist.path()),
65                      qMakePair(QString("destination"), m_dest.path()));
66 }
67
68 void RenderJob::unregisterJob(KJob *job) {
69     KIO::getJobTracker()->unregisterJob(job);
70 }
71
72
73 unsigned long RenderJob::percent() const {
74     return m_progress;
75 }
76
77 void RenderJob::update() {
78     setPercent(percent());
79 }
80
81 void RenderJob::slotIsOver(int exitcode, QProcess::ExitStatus status) {
82     emitResult();
83     KIO::getJobTracker()->unregisterJob(this);
84 }
85
86 #include "renderjob.moc"