]> git.sesse.net Git - kdenlive/blob - src/cliptranscode.cpp
New dialog for clip transcoding
[kdenlive] / src / cliptranscode.cpp
1 /***************************************************************************
2  *   Copyright (C) 2008 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 "cliptranscode.h"
22
23 #include <KDebug>
24 #include <KGlobalSettings>
25 #include <KMessageBox>
26
27
28 ClipTranscode::ClipTranscode(const KUrl &src, const QString &params, QWidget * parent) :
29         QDialog(parent)
30 {
31     setFont(KGlobalSettings::toolBarFont());
32     m_view.setupUi(this);
33     setAttribute(Qt::WA_DeleteOnClose);
34     setWindowTitle(i18n("Transcode Clip"));
35
36     QString fileName = src.path(); //.section('.', 0, -1);
37     QString newFile = params.section(' ', -1).replace("%1", fileName);
38     KUrl dest(newFile);
39     m_view.source_url->setUrl(src);
40     m_view.dest_url->setUrl(dest);
41     m_view.params->setPlainText(params.simplified());
42     kDebug() << "//PARAMS: " << params << "\n\nNAME: " << newFile;
43
44     connect(m_view.button_start, SIGNAL(clicked()), this, SLOT(slotStartTransCode()));
45
46     m_transcodeProcess.setProcessChannelMode(QProcess::MergedChannels);
47     connect(&m_transcodeProcess, SIGNAL(readyReadStandardOutput()), this, SLOT(slotShowTranscodeInfo()));
48     connect(&m_transcodeProcess, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(slotTranscodeFinished(int, QProcess::ExitStatus)));
49
50     //adjustSize();
51 }
52
53 ClipTranscode::~ClipTranscode()
54 {
55     if (m_transcodeProcess.state() != QProcess::NotRunning) {
56         m_transcodeProcess.close();
57     }
58 }
59
60 void ClipTranscode::slotStartTransCode()
61 {
62     if (m_transcodeProcess.state() != QProcess::NotRunning) {
63         return;
64     }
65     QStringList parameters;
66     parameters << "-i" << m_view.source_url->url().path();
67
68     if (QFile::exists(m_view.dest_url->url().path())) {
69         if (KMessageBox::questionYesNo(this, i18n("File %1 already exists.\nDo you want to overwrite it?", m_view.dest_url->url().path())) == KMessageBox::No) return;
70         parameters << "-y";
71     }
72     m_view.buttonBox->button(QDialogButtonBox::Abort)->setText(i18n("Abort"));
73     QString params = m_view.params->toPlainText().simplified();
74     params = params.section(' ', 0, -2);
75     parameters << params.split(' ') << m_view.dest_url->url().path();
76
77     kDebug() << "/// FFMPEG ARGS: " << parameters;
78
79     m_transcodeProcess.start("ffmpeg", parameters);
80     m_view.button_start->setEnabled(false);
81
82 }
83
84 void ClipTranscode::slotShowTranscodeInfo()
85 {
86     QString log = QString(m_transcodeProcess.readAll());
87     //kDebug() << "//LOG: " << log;
88     m_view.log->setPlainText(log);
89 }
90
91 void ClipTranscode::slotTranscodeFinished(int exitCode, QProcess::ExitStatus exitStatus)
92 {
93     m_view.buttonBox->button(QDialogButtonBox::Abort)->setText(i18n("Close"));
94     m_view.button_start->setEnabled(true);
95
96     if (exitCode == 0 && exitStatus == QProcess::NormalExit) {
97         m_view.log->setHtml(m_view.log->toPlainText() + "<br><b>" + i18n("Transcoding finished."));
98         if (m_view.auto_add->isChecked()) emit addClip(m_view.dest_url->url());
99         if (m_view.auto_close->isChecked()) accept();
100     } else {
101         m_view.log->setHtml(m_view.log->toPlainText() + "<br><b>" + i18n("Transcoding FAILED!"));
102     }
103
104     m_transcodeProcess.close();
105 }
106
107 #include "cliptranscode.moc"
108
109