From 8e0ffafc0c98fba592aa4d6dd713372d2e6246b9 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Mardelle Date: Tue, 19 May 2009 12:21:37 +0000 Subject: [PATCH] New dialog for clip transcoding svn path=/trunk/kdenlive/; revision=3397 --- src/CMakeLists.txt | 2 + src/cliptranscode.cpp | 109 +++++++++++++++++++++ src/cliptranscode.h | 55 +++++++++++ src/mainwindow.cpp | 33 +------ src/mainwindow.h | 2 - src/widgets/cliptranscode_ui.ui | 165 ++++++++++++++++++++++++++++++++ 6 files changed, 336 insertions(+), 30 deletions(-) create mode 100644 src/cliptranscode.cpp create mode 100644 src/cliptranscode.h create mode 100644 src/widgets/cliptranscode_ui.ui diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 20a27854..9b7f948d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -73,6 +73,7 @@ kde4_add_ui_files(kdenlive_UI widgets/dvdwizardstatus_ui.ui widgets/dvdwizardchapters_ui.ui widgets/missingclips_ui.ui + widgets/cliptranscode_ui.ui ) set(kdenlive_SRCS @@ -161,6 +162,7 @@ set(kdenlive_SRCS documentchecker.cpp dvdwizardchapters.cpp documentconvert.cpp + cliptranscode.cpp ) add_definitions( ${KDE4_DEFINITIONS} ) diff --git a/src/cliptranscode.cpp b/src/cliptranscode.cpp new file mode 100644 index 00000000..334d969e --- /dev/null +++ b/src/cliptranscode.cpp @@ -0,0 +1,109 @@ +/*************************************************************************** + * Copyright (C) 2008 by Jean-Baptiste Mardelle (jb@kdenlive.org) * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + + +#include "cliptranscode.h" + +#include +#include +#include + + +ClipTranscode::ClipTranscode(const KUrl &src, const QString ¶ms, QWidget * parent) : + QDialog(parent) +{ + setFont(KGlobalSettings::toolBarFont()); + m_view.setupUi(this); + setAttribute(Qt::WA_DeleteOnClose); + setWindowTitle(i18n("Transcode Clip")); + + QString fileName = src.path(); //.section('.', 0, -1); + QString newFile = params.section(' ', -1).replace("%1", fileName); + KUrl dest(newFile); + m_view.source_url->setUrl(src); + m_view.dest_url->setUrl(dest); + m_view.params->setPlainText(params.simplified()); + kDebug() << "//PARAMS: " << params << "\n\nNAME: " << newFile; + + connect(m_view.button_start, SIGNAL(clicked()), this, SLOT(slotStartTransCode())); + + m_transcodeProcess.setProcessChannelMode(QProcess::MergedChannels); + connect(&m_transcodeProcess, SIGNAL(readyReadStandardOutput()), this, SLOT(slotShowTranscodeInfo())); + connect(&m_transcodeProcess, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(slotTranscodeFinished(int, QProcess::ExitStatus))); + + //adjustSize(); +} + +ClipTranscode::~ClipTranscode() +{ + if (m_transcodeProcess.state() != QProcess::NotRunning) { + m_transcodeProcess.close(); + } +} + +void ClipTranscode::slotStartTransCode() +{ + if (m_transcodeProcess.state() != QProcess::NotRunning) { + return; + } + QStringList parameters; + parameters << "-i" << m_view.source_url->url().path(); + + if (QFile::exists(m_view.dest_url->url().path())) { + if (KMessageBox::questionYesNo(this, i18n("File %1 already exists.\nDo you want to overwrite it?", m_view.dest_url->url().path())) == KMessageBox::No) return; + parameters << "-y"; + } + m_view.buttonBox->button(QDialogButtonBox::Abort)->setText(i18n("Abort")); + QString params = m_view.params->toPlainText().simplified(); + params = params.section(' ', 0, -2); + parameters << params.split(' ') << m_view.dest_url->url().path(); + + kDebug() << "/// FFMPEG ARGS: " << parameters; + + m_transcodeProcess.start("ffmpeg", parameters); + m_view.button_start->setEnabled(false); + +} + +void ClipTranscode::slotShowTranscodeInfo() +{ + QString log = QString(m_transcodeProcess.readAll()); + //kDebug() << "//LOG: " << log; + m_view.log->setPlainText(log); +} + +void ClipTranscode::slotTranscodeFinished(int exitCode, QProcess::ExitStatus exitStatus) +{ + m_view.buttonBox->button(QDialogButtonBox::Abort)->setText(i18n("Close")); + m_view.button_start->setEnabled(true); + + if (exitCode == 0 && exitStatus == QProcess::NormalExit) { + m_view.log->setHtml(m_view.log->toPlainText() + "
" + i18n("Transcoding finished.")); + if (m_view.auto_add->isChecked()) emit addClip(m_view.dest_url->url()); + if (m_view.auto_close->isChecked()) accept(); + } else { + m_view.log->setHtml(m_view.log->toPlainText() + "
" + i18n("Transcoding FAILED!")); + } + + m_transcodeProcess.close(); +} + +#include "cliptranscode.moc" + + diff --git a/src/cliptranscode.h b/src/cliptranscode.h new file mode 100644 index 00000000..979db76d --- /dev/null +++ b/src/cliptranscode.h @@ -0,0 +1,55 @@ +/*************************************************************************** + * Copyright (C) 2008 by Jean-Baptiste Mardelle (jb@kdenlive.org) * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + + +#ifndef CLIPTRANSCODE_H +#define CLIPTRANSCODE_H + + +#include "ui_cliptranscode_ui.h" + +#include + +#include + +class ClipTranscode : public QDialog +{ + Q_OBJECT + +public: + ClipTranscode(const KUrl &src, const QString ¶ms, QWidget * parent = 0); + ~ClipTranscode(); + + +private slots: + void slotShowTranscodeInfo(); + void slotStartTransCode(); + void slotTranscodeFinished(int exitCode, QProcess::ExitStatus exitStatus); + +private: + Ui::ClipTranscode_UI m_view; + QProcess m_transcodeProcess; + +signals: + void addClip(KUrl url); +}; + + +#endif + diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 15adae1b..9dface82 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -50,6 +50,7 @@ #include "clipitem.h" #include "interfaces.h" #include "kdenlive-config.h" +#include "cliptranscode.h" #include #include @@ -2671,40 +2672,16 @@ void MainWindow::loadTranscoders() void MainWindow::slotTranscode() { - if (m_transcodeProcess.state() != QProcess::NotRunning) { - m_messageLabel->setMessage(i18n("A transcoding job is already running"), ErrorMessage); - return; - } QString url = m_projectList->currentClipUrl(); if (url.isEmpty()) return; QAction *action = qobject_cast(sender()); QString params = action->data().toString(); - params = params.simplified(); - QStringList parameters; - parameters << "-i" << url; - QString fileName = url; //.section('.', 0, -1); - params.replace("%1", fileName); - QString newFile = params.section(' ', -1); - kDebug() << "//PARAMS: " << params << "\n\nNAME: " << newFile; - if (QFile::exists(newFile)) { - if (KMessageBox::questionYesNo(this, i18n("File %1 already exists.\nDo you want to overwrite it?", newFile)) == KMessageBox::No) return; - parameters << "-y"; - } - parameters << params.split(' '); - kDebug() << "/// FFMPEG ARGS: " << parameters; - m_transcodeProcess.setProcessChannelMode(QProcess::MergedChannels); - connect(&m_transcodeProcess, SIGNAL(readyReadStandardOutput()), this, SLOT(slotShowTranscodeInfo())); - m_transcodeProcess.start("ffmpeg", parameters); + ClipTranscode *d = new ClipTranscode(m_projectList->currentClipUrl(), params); + connect(d, SIGNAL(addClip(KUrl)), this, SLOT(slotAddProjectClip(KUrl))); + d->show(); - //QProcess::startDetached("ffmpeg", parameters); -} -void MainWindow::slotShowTranscodeInfo() -{ - QString log = QString(m_transcodeProcess.readAll()); - kDebug() << "//LOG: " << log; - //TODO: find better way to display transcode output info - m_messageLabel->setMessage(log, ErrorMessage); + //QProcess::startDetached("ffmpeg", parameters); } #include "mainwindow.moc" diff --git a/src/mainwindow.h b/src/mainwindow.h index 3e563f2e..82bc43f7 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -173,7 +173,6 @@ private: bool m_findActivated; QString m_findString; QTimer m_findTimer; - QProcess m_transcodeProcess; void readOptions(); void saveOptions(); @@ -300,7 +299,6 @@ private slots: void slotShowTimeline(bool show); void slotMaximizeCurrent(bool show); void slotTranscode(); - void slotShowTranscodeInfo(); signals: Q_SCRIPTABLE void abortRenderJob(const QString &url); diff --git a/src/widgets/cliptranscode_ui.ui b/src/widgets/cliptranscode_ui.ui new file mode 100644 index 00000000..fdc94fe1 --- /dev/null +++ b/src/widgets/cliptranscode_ui.ui @@ -0,0 +1,165 @@ + + + ClipTranscode_UI + + + + 0 + 0 + 304 + 300 + + + + Dialog + + + + + + Source + + + + + + + + + + Destination + + + + + + + + + + FFmpeg parameters + + + + + + + + 0 + 0 + + + + + + + + Job status + + + + + + + + 0 + 0 + + + + true + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Abort + + + + + + + Start + + + + + + + Add clip to project + + + + + + + Close after transcode + + + true + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + KUrlRequester + QFrame +
kurlrequester.h
+
+
+ + + + buttonBox + accepted() + ClipTranscode_UI + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + ClipTranscode_UI + reject() + + + 316 + 260 + + + 286 + 274 + + + + +
-- 2.39.2