]> git.sesse.net Git - kdenlive/blobdiff - src/renderwidget.cpp
reindent
[kdenlive] / src / renderwidget.cpp
index 9dea571b7a6df33966273345886518b0153ce415..f9468a82df7e7ac61a617a9870bc1959fe0ca62d 100644 (file)
@@ -21,6 +21,7 @@
 #include "renderwidget.h"
 #include "kdenlivesettings.h"
 #include "ui_saveprofile_ui.h"
+#include "timecode.h"
 
 #include <KStandardDirs>
 #include <KDebug>
@@ -199,10 +200,13 @@ void RenderWidget::showInfoPanel()
 
 void RenderWidget::setDocumentPath(const QString path)
 {
+    if (m_view.out_file->url().directory() == KUrl(m_projectFolder).directory()) {
+        const QString fileName = m_view.out_file->url().fileName();
+        m_view.out_file->setUrl(KUrl(path + fileName));
+    }
     m_projectFolder = path;
-    const QString fileName = m_view.out_file->url().fileName();
-    m_view.out_file->setUrl(KUrl(m_projectFolder + fileName));
     parseScriptFiles();
+
 }
 
 void RenderWidget::slotUpdateGuideBox()
@@ -235,11 +239,14 @@ void RenderWidget::setGuides(QDomElement guidesxml, double duration)
         m_view.render_guide->setEnabled(false);
         m_view.create_chapter->setEnabled(false);
     }
+    double fps = (double) m_profile.frame_rate_num / m_profile.frame_rate_den;
     for (int i = 0; i < nodes.count(); i++) {
         QDomElement e = nodes.item(i).toElement();
         if (!e.isNull()) {
-            m_view.guide_start->addItem(e.attribute("comment"), e.attribute("time").toDouble());
-            m_view.guide_end->addItem(e.attribute("comment"), e.attribute("time").toDouble());
+            GenTime pos = GenTime(e.attribute("time").toDouble());
+            const QString guidePos = Timecode::getStringTimecode(pos.frames(fps), fps);
+            m_view.guide_start->addItem(e.attribute("comment") + '/' + guidePos, e.attribute("time").toDouble());
+            m_view.guide_end->addItem(e.attribute("comment") + '/' + guidePos, e.attribute("time").toDouble());
         }
     }
     if (nodes.count() > 0)
@@ -587,6 +594,10 @@ void RenderWidget::slotPrepareExport(bool scriptExport)
         KMessageBox::sorry(this, i18n("Cannot play video after rendering because the default video player application is not set.\nPlease define it in Kdenlive settings dialog."));
     QString chapterFile;
     if (m_view.create_chapter->isChecked()) chapterFile = m_view.out_file->url().path() + ".dvdchapter";
+
+    // mantisbt 1051
+    KStandardDirs::makeDir(m_view.out_file->url().directory());
+
     emit prepareRenderingData(scriptExport, m_view.render_zone->isChecked(), chapterFile);
 }
 
@@ -602,7 +613,7 @@ void RenderWidget::slotExport(bool scriptExport, int zoneIn, int zoneOut, const
     // Check whether target file has an extension.
     // If not, ask whether extension should be added or not.
     QString extension = item->data(ExtensionRole).toString();
-    if (!dest.endsWith(extension)) {
+    if (!dest.endsWith(extension, Qt::CaseInsensitive)) {
         if (KMessageBox::questionYesNo(this, i18n("File has no extension. Add extension (%1)?", extension)) == KMessageBox::Yes) {
             dest.append("." + extension);
         }
@@ -638,7 +649,8 @@ void RenderWidget::slotExport(bool scriptExport, int zoneIn, int zoneOut, const
         render_process_args << "in=" + QString::number(GenTime(guideStart).frames(fps)) << "out=" + QString::number(GenTime(guideEnd).frames(fps));
     }
 
-    render_process_args << overlayargs;
+    if (!overlayargs.isEmpty()) render_process_args << "preargs=" + overlayargs.join(" ");
+
     render_process_args << KdenliveSettings::rendererpath() << m_profile.path << item->data(RenderRole).toString();
     if (m_view.play_after->isChecked()) render_process_args << KdenliveSettings::KdenliveSettings::defaultplayerapp();
     else render_process_args << "-";
@@ -705,12 +717,6 @@ void RenderWidget::slotExport(bool scriptExport, int zoneIn, int zoneOut, const
 
     QString scriptName;
     if (scriptExport) {
-
-        /*renderParameters << scriptName;
-        if (group == "dvd") renderParameters << QString::number(m_view.create_chapter->isChecked());
-        else renderParameters << QString::number(false);
-        emit doRender(renderParameters, overlayargs);*/
-
         // Generate script file
         QFile file(scriptPath);
         if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
@@ -743,7 +749,7 @@ void RenderWidget::slotExport(bool scriptExport, int zoneIn, int zoneOut, const
     m_view.tabWidget->setCurrentIndex(1);
 
     // Save rendering profile to document
-    emit selectedRenderProfile(m_view.size_list->currentItem()->data(MetaGroupRole).toString(), m_view.size_list->currentItem()->text());
+    emit selectedRenderProfile(m_view.size_list->currentItem()->data(MetaGroupRole).toString(), m_view.size_list->currentItem()->text(), dest);
 
     // insert item in running jobs list
     QTreeWidgetItem *renderItem;
@@ -930,7 +936,6 @@ void RenderWidget::refreshView()
             if (!sizeItem->isHidden()) {
                 // Make sure the selected profile uses an installed avformat codec / format
                 std = sizeItem->data(ParamsRole).toString();
-
                 if (!formatsList.isEmpty()) {
                     QString format;
                     if (std.startsWith("f=")) format = std.section("f=", 1, 1);
@@ -990,17 +995,24 @@ void RenderWidget::refreshView()
 
 KUrl RenderWidget::filenameWithExtension(KUrl url, QString extension)
 {
-    QString path;
-    if (!url.isEmpty()) {
-        path = url.path();
-        int pos = path.lastIndexOf('.') + 1;
-        if (pos == 0) path.append('.' + extension);
-        else path = path.left(pos) + extension;
+    QString directory = url.directory(KUrl::AppendTrailingSlash | KUrl::ObeyTrailingSlash);
+    QString filename = url.fileName(KUrl::ObeyTrailingSlash);
+    QString ext;
 
-    } else {
-        path = m_projectFolder + "untitled." + extension;
+    if (extension.at(0) == '.') ext = extension;
+    else ext = '.' + extension;
+
+    if (filename.isEmpty()) filename = i18n("untitled");
+
+    int pos = filename.lastIndexOf('.');
+    if (pos == 0) filename.append(ext);
+    else {
+        if (!filename.endsWith(ext, Qt::CaseInsensitive)) {
+            filename = filename.left(pos) + ext;
+        }
     }
-    return KUrl(path);
+
+    return KUrl(directory + filename);
 }
 
 
@@ -1121,6 +1133,11 @@ void RenderWidget::parseFile(QString exportFile, bool editable)
     QListWidgetItem *item;
     QDomNodeList groups = doc.elementsByTagName("group");
 
+    const QStringList acodecsList = KdenliveSettings::audiocodecs();
+    bool replaceVorbisCodec = false;
+    if (!acodecsList.contains("vorbis") && acodecsList.contains("libvorbis")) replaceVorbisCodec = true;
+
+
     if (editable || groups.count() == 0) {
         QDomElement profiles = doc.documentElement();
         if (editable && profiles.attribute("version", 0).toInt() < 1) {
@@ -1167,6 +1184,13 @@ void RenderWidget::parseFile(QString exportFile, bool editable)
             QString profileName = profile.attribute("name");
             QString standard = profile.attribute("standard");
             QString params = profile.attribute("args");
+
+            if (replaceVorbisCodec && params.contains("acodec=vorbis")) {
+                // replace vorbis with libvorbis
+                params = params.replace("vorbis", "libvorbis");
+            }
+
+
             QString category = profile.attribute("category", i18n("Custom"));
             QString dest = profile.attribute("destinationid");
             QString prof_extension = profile.attribute("extension");
@@ -1236,7 +1260,8 @@ void RenderWidget::parseFile(QString exportFile, bool editable)
         if (!gname.isNull()) {
             metagroupName = gname.firstChild().nodeValue();
             metagroupId = gname.toElement().attribute("id");
-            if (!metagroupName.isEmpty() && !m_view.destination_list->contains(metagroupName)) {
+
+            if (!metagroupName.isEmpty() && m_view.destination_list->findData(metagroupId) == -1) {
                 if (metagroupId == "dvd") icon = KIcon("media-optical");
                 else if (metagroupId == "audioonly") icon = KIcon("audio-x-generic");
                 else if (metagroupId == "websites") icon = KIcon("applications-internet");
@@ -1272,6 +1297,11 @@ void RenderWidget::parseFile(QString exportFile, bool editable)
             profileName = profileElement.attribute("name");
             standard = profileElement.attribute("standard");
             params = profileElement.attribute("args");
+
+            if (replaceVorbisCodec && params.contains("acodec=vorbis")) {
+                // replace vorbis with libvorbis
+                params = params.replace("vorbis", "libvorbis");
+            }
             prof_extension = profileElement.attribute("extension");
             if (!prof_extension.isEmpty()) extension = prof_extension;
             item = new QListWidgetItem(profileName, m_view.size_list);
@@ -1521,11 +1551,14 @@ void RenderWidget::slotHideLog()
     m_view.error_box->setVisible(false);
 }
 
-void RenderWidget::setRenderProfile(const QString &dest, const QString &name)
+void RenderWidget::setRenderProfile(const QString &dest, const QString &name, const QString &url)
 {
     m_view.destination_list->blockSignals(true);
     m_view.format_list->blockSignals(true);
     m_view.size_list->blockSignals(true);
+
+    if (!url.isEmpty()) m_view.out_file->setUrl(KUrl(url));
+
     for (int i = 0; i < m_view.destination_list->count(); i++) {
         if (m_view.destination_list->itemData(i, Qt::UserRole) == dest) {
             m_view.destination_list->setCurrentIndex(i);