]> git.sesse.net Git - kdenlive/blobdiff - src/renderwidget.cpp
outline-text
[kdenlive] / src / renderwidget.cpp
index b71203ed8876b99af9a397f201ccc37d75b7969f..84411b71ee8ae4558ddc63638ef841c1a86f336c 100644 (file)
@@ -21,6 +21,7 @@
 #include "renderwidget.h"
 #include "kdenlivesettings.h"
 #include "ui_saveprofile_ui.h"
+#include "timecode.h"
 
 #include <KStandardDirs>
 #include <KDebug>
@@ -30,6 +31,7 @@
 #include <KIO/NetAccess>
 #include <KColorScheme>
 #include <KNotification>
+#include <KStartupInfo>
 // #include <knewstuff2/engine.h>
 
 #include <QDomDocument>
 #include <QListWidgetItem>
 #include <QHeaderView>
 #include <QMenu>
-#include <QProcess>
 #include <QInputDialog>
+#include <QProcess>
+#include <QDBusConnectionInterface>
+#include <QDBusInterface>
 
 const int GroupRole = Qt::UserRole;
 const int ExtensionRole = GroupRole + 1;
@@ -77,6 +81,9 @@ RenderWidget::RenderWidget(const QString &projectfolder, QWidget * parent) :
     m_view.buttonInfo->setIcon(KIcon("help-about"));
     m_view.hide_log->setIcon(KIcon("go-down"));
 
+    m_view.buttonFavorite->setIcon(KIcon("favorites"));
+    m_view.buttonFavorite->setToolTip(i18n("Copy profile to favorites"));
+    
     if (KdenliveSettings::showrenderparams()) {
         m_view.buttonInfo->setDown(true);
     } else m_view.advanced_params->hide();
@@ -116,7 +123,10 @@ RenderWidget::RenderWidget(const QString &projectfolder, QWidget * parent) :
     connect(m_view.buttonSave, SIGNAL(clicked()), this, SLOT(slotSaveProfile()));
     connect(m_view.buttonEdit, SIGNAL(clicked()), this, SLOT(slotEditProfile()));
     connect(m_view.buttonDelete, SIGNAL(clicked()), this, SLOT(slotDeleteProfile()));
+    connect(m_view.buttonFavorite, SIGNAL(clicked()), this, SLOT(slotCopyToFavorites()));
+
     connect(m_view.abort_job, SIGNAL(clicked()), this, SLOT(slotAbortCurrentJob()));
+    connect(m_view.start_job, SIGNAL(clicked()), this, SLOT(slotStartCurrentJob()));
     connect(m_view.clean_up, SIGNAL(clicked()), this, SLOT(slotCLeanUpJobs()));
     connect(m_view.hide_log, SIGNAL(clicked()), this, SLOT(slotHideLog()));
 
@@ -155,7 +165,8 @@ RenderWidget::RenderWidget(const QString &projectfolder, QWidget * parent) :
     m_view.out_file->setMode(KFile::File);
 
     m_view.running_jobs->setHeaderLabels(QStringList() << QString() << i18n("File") << i18n("Progress"));
-    m_view.running_jobs->setItemDelegate(new RenderViewDelegate(this));
+    m_jobsDelegate = new RenderViewDelegate(this);
+    m_view.running_jobs->setItemDelegate(m_jobsDelegate);
 
     QHeaderView *header = m_view.running_jobs->header();
     QFontMetrics fm = fontMetrics();
@@ -169,14 +180,38 @@ RenderWidget::RenderWidget(const QString &projectfolder, QWidget * parent) :
 
 
     m_view.scripts_list->setHeaderLabels(QStringList() << QString() << i18n("Script Files"));
-    m_view.scripts_list->setItemDelegate(new RenderViewDelegate(this));
+    m_scriptsDelegate = new RenderViewDelegate(this);
+    m_view.scripts_list->setItemDelegate(m_scriptsDelegate);
     header = m_view.scripts_list->header();
     header->setResizeMode(0, QHeaderView::Fixed);
     header->resizeSection(0, 30);
 
+    // Find path for Kdenlive renderer
+    m_renderer = QCoreApplication::applicationDirPath() + QString("/kdenlive_render");
+    if (!QFile::exists(m_renderer)) {
+        m_renderer = KStandardDirs::findExe("kdenlive_render");
+        if (m_renderer.isEmpty()) m_renderer = KStandardDirs::locate("exe", "kdenlive_render");
+        if (m_renderer.isEmpty()) m_renderer = "kdenlive_render";
+    }
+
+    QDBusConnectionInterface* interface = QDBusConnection::sessionBus().interface();
+    if (!interface || !interface->isServiceRegistered("org.kde.ksmserver")) {
+        m_view.shutdown->setEnabled(false);
+    }
+
     focusFirstVisibleItem();
 }
 
+RenderWidget::~RenderWidget()
+{
+    m_view.running_jobs->blockSignals(true);
+    m_view.scripts_list->blockSignals(true);
+    m_view.running_jobs->clear();
+    m_view.scripts_list->clear();
+    delete m_jobsDelegate;
+    delete m_scriptsDelegate;
+}
+
 void RenderWidget::slotEditItem(QListWidgetItem *item)
 {
     QString edit = item->data(EditableRole).toString();
@@ -199,10 +234,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 +273,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)
@@ -259,6 +300,10 @@ void RenderWidget::slotUpdateButtons(KUrl url)
     }
     if (url != 0) {
         QListWidgetItem *item = m_view.size_list->currentItem();
+        if (!item) {
+            m_view.buttonStart->setEnabled(false);
+            return;
+        }
         QString extension = item->data(ExtensionRole).toString();
         url = filenameWithExtension(url, extension);
         m_view.out_file->setUrl(url);
@@ -298,7 +343,30 @@ void RenderWidget::slotSaveProfile()
     ui.profile_name->setFocus();
 
     if (d->exec() == QDialog::Accepted && !ui.profile_name->text().simplified().isEmpty()) {
-        QString exportFile = KStandardDirs::locateLocal("appdata", "export/customprofiles.xml");
+        QString newProfileName = ui.profile_name->text().simplified();
+        QString newGroupName = ui.group_name->text().simplified();
+        if (newGroupName.isEmpty()) newGroupName = i18n("Custom");
+        QString newMetaGroupId = ui.destination_list->itemData(ui.destination_list->currentIndex(), Qt::UserRole).toString();
+       
+       QDomDocument doc;
+        QDomElement profileElement = doc.createElement("profile");
+        profileElement.setAttribute("name", newProfileName);
+        profileElement.setAttribute("category", newGroupName);
+        profileElement.setAttribute("destinationid", newMetaGroupId);
+        profileElement.setAttribute("extension", ui.extension->text().simplified());
+        profileElement.setAttribute("args", ui.parameters->toPlainText().simplified());
+       doc.appendChild(profileElement);
+       saveProfile(doc.documentElement());
+        
+        parseProfiles(newMetaGroupId, newGroupName, newProfileName);
+    }
+    delete d;
+}
+
+
+void RenderWidget::saveProfile(QDomElement newprofile)
+{
+  QString exportFile = KStandardDirs::locateLocal("appdata", "export/customprofiles.xml");
         QDomDocument doc;
         QFile file(exportFile);
         doc.setContent(&file, false);
@@ -320,20 +388,17 @@ void RenderWidget::slotSaveProfile()
             doc.appendChild(profiles);
         }
 
-        QString newProfileName = ui.profile_name->text().simplified();
-        QString newGroupName = ui.group_name->text().simplified();
-        if (newGroupName.isEmpty()) newGroupName = i18n("Custom");
-        QString newMetaGroupId = ui.destination_list->itemData(ui.destination_list->currentIndex(), Qt::UserRole).toString();
+
         QDomNodeList profilelist = doc.elementsByTagName("profile");
         int i = 0;
         while (!profilelist.item(i).isNull()) {
             // make sure a profile with same name doesn't exist
             documentElement = profilelist.item(i).toElement();
             QString profileName = documentElement.attribute("name");
-            if (profileName == newProfileName) {
+            if (profileName == newprofile.attribute("name")) {
                 // a profile with that same name already exists
                 bool ok;
-                newProfileName = QInputDialog::getText(this, i18n("Profile already exists"), i18n("This profile name already exists. Change the name if you don't want to overwrite it."), QLineEdit::Normal, newProfileName, &ok);
+                QString newProfileName = QInputDialog::getText(this, i18n("Profile already exists"), i18n("This profile name already exists. Change the name if you don't want to overwrite it."), QLineEdit::Normal, profileName, &ok);
                 if (!ok) return;
                 if (profileName == newProfileName) {
                     profiles.removeChild(profilelist.item(i));
@@ -343,19 +408,12 @@ void RenderWidget::slotSaveProfile()
             i++;
         }
 
-        QDomElement profileElement = doc.createElement("profile");
-        profileElement.setAttribute("name", newProfileName);
-        profileElement.setAttribute("category", newGroupName);
-        profileElement.setAttribute("destinationid", newMetaGroupId);
-        profileElement.setAttribute("extension", ui.extension->text().simplified());
-        profileElement.setAttribute("args", ui.parameters->toPlainText().simplified());
-        profiles.appendChild(profileElement);
+        profiles.appendChild(newprofile);
 
         //QCString save = doc.toString().utf8();
 
         if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
             KMessageBox::sorry(this, i18n("Unable to write to file %1", exportFile));
-            delete d;
             return;
         }
         QTextStream out(&file);
@@ -363,13 +421,30 @@ void RenderWidget::slotSaveProfile()
         if (file.error() != QFile::NoError) {
             KMessageBox::error(this, i18n("Cannot write to file %1", exportFile));
             file.close();
-            delete d;
             return;
         }
         file.close();
-        parseProfiles(newMetaGroupId, newGroupName, newProfileName);
-    }
-    delete d;
+}
+
+void RenderWidget::slotCopyToFavorites()
+{
+    QListWidgetItem *item = m_view.size_list->currentItem();
+    if (!item) return;
+    QString currentGroup = m_view.format_list->currentItem()->text();
+
+    QString params = item->data(ParamsRole).toString();
+    QString extension = item->data(ExtensionRole).toString();
+    QString currentProfile = item->text();
+    QDomDocument doc;
+    QDomElement profileElement = doc.createElement("profile");
+    profileElement.setAttribute("name", currentProfile);
+    profileElement.setAttribute("category", i18n("Custom"));
+    profileElement.setAttribute("destinationid", "favorites");
+    profileElement.setAttribute("extension", extension);
+    profileElement.setAttribute("args", params);
+    doc.appendChild(profileElement);
+    saveProfile(doc.documentElement());
+    parseProfiles(m_view.destination_list->itemData(m_view.destination_list->currentIndex(), Qt::UserRole).toString(), currentGroup, currentProfile);
 }
 
 void RenderWidget::slotEditProfile()
@@ -587,6 +662,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 +681,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 +717,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,25 +785,17 @@ 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)) {
             KMessageBox::error(this, i18n("Cannot write to file %1", scriptPath));
             return;
         }
-        QString renderer = QCoreApplication::applicationDirPath() + QString("/kdenlive_render");
-        if (!QFile::exists(renderer)) renderer = "kdenlive_render";
         QTextStream outStream(&file);
         outStream << "#! /bin/sh" << "\n" << "\n";
         outStream << "SOURCE=" << "\"" + playlistPath + "\"" << "\n";
         outStream << "TARGET=" << "\"" + dest + "\"" << "\n";
-        outStream << "RENDERER=" << "\"" + renderer + "\"" << "\n";
+        outStream << "RENDERER=" << "\"" + m_renderer + "\"" << "\n";
         outStream << "MELT=" << "\"" + render_process_args.takeFirst() + "\"" << "\n";
         outStream << "PARAMETERS=" << "\"" + render_process_args.join(" ") + "\"" << "\n";
         outStream << "$RENDERER $MELT $PARAMETERS" << "\n" << "\n";
@@ -743,7 +815,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;
@@ -769,7 +841,7 @@ void RenderWidget::slotExport(bool scriptExport, int zoneIn, int zoneOut, const
         if (m_view.open_dvd->isChecked()) {
             renderItem->setData(0, Qt::UserRole, group);
             if (renderArgs.contains("profile=")) {
-                // rendering profile contains an MLT profile, so pass it to the running jog item, useful for dvd
+                // rendering profile contains an MLT profile, so pass it to the running jog item, useful for dvd
                 QString prof = renderArgs.section("profile=", 1, 1);
                 prof = prof.section(' ', 0, 0);
                 kDebug() << "// render profile: " << prof;
@@ -779,7 +851,7 @@ void RenderWidget::slotExport(bool scriptExport, int zoneIn, int zoneOut, const
     } else {
         if (group == "websites" && m_view.open_browser->isChecked()) {
             renderItem->setData(0, Qt::UserRole, group);
-            // pass the url
+            // pass the url
             QString url = m_view.size_list->currentItem()->data(ExtraRole).toString();
             renderItem->setData(0, Qt::UserRole + 1, url);
         }
@@ -790,6 +862,7 @@ void RenderWidget::slotExport(bool scriptExport, int zoneIn, int zoneOut, const
 
 void RenderWidget::checkRenderStatus()
 {
+    // check if we have a job waiting to render
     if (m_blockProcessing) return;
     QTreeWidgetItem *item = m_view.running_jobs->topLevelItem(0);
     while (item) {
@@ -797,27 +870,38 @@ void RenderWidget::checkRenderStatus()
         item = m_view.running_jobs->itemBelow(item);
     }
     item = m_view.running_jobs->topLevelItem(0);
+    bool waitingJob = false;
     while (item) {
         if (item->data(1, Qt::UserRole + 2).toInt() == WAITINGJOB) {
             item->setData(1, Qt::UserRole + 1, QTime::currentTime());
-            if (item->data(1, Qt::UserRole + 4).isNull()) {
-                // Normal render process
-                QString renderer = QCoreApplication::applicationDirPath() + QString("/kdenlive_render");
-                if (!QFile::exists(renderer)) renderer = "kdenlive_render";
-                QProcess::startDetached(renderer, item->data(1, Qt::UserRole + 3).toStringList());
-                KNotification::event("RenderStarted", i18n("Rendering <i>%1</i> started", item->text(1)), QPixmap(), this);
-            } else {
-                // Script item
-                if (QProcess::startDetached(item->data(1, Qt::UserRole + 3).toString()) == false) {
-                    item->setData(1, Qt::UserRole, i18n("Rendering crashed"));
-                    item->setIcon(0, KIcon("dialog-close"));
-                    item->setData(2, Qt::UserRole, 100);
-                }
-            }
+            waitingJob = true;
+            startRendering(item);
             break;
         }
         item = m_view.running_jobs->itemBelow(item);
     }
+    if (waitingJob == false && m_view.shutdown->isChecked()) emit shutdown();
+}
+
+void RenderWidget::startRendering(QTreeWidgetItem *item)
+{
+    if (item->data(1, Qt::UserRole + 4).isNull()) {
+        // Normal render process
+        if (QProcess::startDetached(m_renderer, item->data(1, Qt::UserRole + 3).toStringList()) == false) {
+            item->setData(1, Qt::UserRole + 2, FINISHEDJOB);
+            item->setData(1, Qt::UserRole, i18n("Rendering crashed"));
+            item->setIcon(0, KIcon("dialog-close"));
+            item->setData(2, Qt::UserRole, 100);
+        } else KNotification::event("RenderStarted", i18n("Rendering <i>%1</i> started", item->text(1)), QPixmap(), this);
+    } else {
+        // Script item
+        if (QProcess::startDetached(item->data(1, Qt::UserRole + 3).toString()) == false) {
+            item->setData(1, Qt::UserRole + 2, FINISHEDJOB);
+            item->setData(1, Qt::UserRole, i18n("Rendering crashed"));
+            item->setIcon(0, KIcon("dialog-close"));
+            item->setData(2, Qt::UserRole, 100);
+        }
+    }
 }
 
 int RenderWidget::waitingJobsCount() const
@@ -925,7 +1009,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);
@@ -985,17 +1068,25 @@ 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;
+    if (url.isEmpty()) url = KUrl(m_projectFolder);
+    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);
 }
 
 
@@ -1058,6 +1149,7 @@ void RenderWidget::parseProfiles(QString meta, QString group, QString profile)
     m_view.format_list->clear();
     m_view.destination_list->clear();
     m_view.destination_list->addItem(KIcon("video-x-generic"), i18n("File rendering"));
+    m_view.destination_list->addItem(KIcon("favorites"), i18n("Favorites"), "favorites");
     m_view.destination_list->addItem(KIcon("media-optical"), i18n("DVD"), "dvd");
     m_view.destination_list->addItem(KIcon("audio-x-generic"), i18n("Audio only"), "audioonly");
     m_view.destination_list->addItem(KIcon("applications-internet"), i18n("Web sites"), "websites");
@@ -1078,8 +1170,8 @@ void RenderWidget::parseProfiles(QString meta, QString group, QString profile)
     // can also override profiles installed by KNewStuff
     fileList.removeAll("customprofiles.xml");
     foreach(const QString &filename, fileList)
-    parseFile(exportFolder + '/' + filename, true);
-    if (QFile::exists(exportFolder + "/customprofiles.xml")) parseFile(exportFolder + "/customprofiles.xml", true);
+    parseFile(exportFolder + filename, true);
+    if (QFile::exists(exportFolder + "customprofiles.xml")) parseFile(exportFolder + "customprofiles.xml", true);
 
     if (!meta.isEmpty()) {
         m_view.destination_list->blockSignals(true);
@@ -1116,6 +1208,13 @@ 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;
+    bool replaceLibfaacCodec = false;
+    if (!acodecsList.contains("aac") && acodecsList.contains("libfaac")) replaceLibfaacCodec = true;
+
+
     if (editable || groups.count() == 0) {
         QDomElement profiles = doc.documentElement();
         if (editable && profiles.attribute("version", 0).toInt() < 1) {
@@ -1162,6 +1261,16 @@ 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");
+            }
+            if (replaceLibfaacCodec && params.contains("acodec=aac")) {
+                // replace libfaac with aac
+                params = params.replace("aac", "libfaac");
+            }
+
             QString category = profile.attribute("category", i18n("Custom"));
             QString dest = profile.attribute("destinationid");
             QString prof_extension = profile.attribute("extension");
@@ -1231,7 +1340,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");
@@ -1267,6 +1377,16 @@ 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");
+            }
+            if (replaceLibfaacCodec && params.contains("acodec=aac")) {
+                // replace libfaac with aac
+                params = params.replace("aac", "libfaac");
+            }
+
             prof_extension = profileElement.attribute("extension");
             if (!prof_extension.isEmpty()) extension = prof_extension;
             item = new QListWidgetItem(profileName, m_view.size_list);
@@ -1368,18 +1488,31 @@ void RenderWidget::slotAbortCurrentJob()
         else {
             delete current;
             slotCheckJob();
+            checkRenderStatus();
         }
     }
 }
 
+void RenderWidget::slotStartCurrentJob()
+{
+    QTreeWidgetItem *current = m_view.running_jobs->currentItem();
+    if (current && current->data(1, Qt::UserRole + 2).toInt() == WAITINGJOB)
+        startRendering(current);
+    m_view.start_job->setEnabled(false);
+}
+
 void RenderWidget::slotCheckJob()
 {
     bool activate = false;
     QTreeWidgetItem *current = m_view.running_jobs->currentItem();
     if (current) {
-        if (current->data(1, Qt::UserRole + 2).toInt() == RUNNINGJOB)
+        if (current->data(1, Qt::UserRole + 2).toInt() == RUNNINGJOB) {
             m_view.abort_job->setText(i18n("Abort Job"));
-        else m_view.abort_job->setText(i18n("Remove Job"));
+            m_view.start_job->setEnabled(false);
+        } else {
+            m_view.abort_job->setText(i18n("Remove Job"));
+            m_view.start_job->setEnabled(current->data(1, Qt::UserRole + 2).toInt() == WAITINGJOB);
+        }
         activate = true;
     }
     m_view.abort_job->setEnabled(activate);
@@ -1409,7 +1542,6 @@ void RenderWidget::parseScriptFiles()
     QStringList scriptFiles = QDir(m_projectFolder + "scripts").entryList(scriptsFilter, QDir::Files);
     for (int i = 0; i < scriptFiles.size(); ++i) {
         KUrl scriptpath(m_projectFolder + "scripts/" + scriptFiles.at(i));
-        item = new QTreeWidgetItem(m_view.scripts_list, QStringList() << QString() << scriptpath.fileName());
         QString target;
         QString renderer;
         QString melt;
@@ -1430,12 +1562,16 @@ void RenderWidget::parseScriptFiles()
             }
             file.close();
         }
+        if (target.isEmpty()) continue;
+        item = new QTreeWidgetItem(m_view.scripts_list, QStringList() << QString() << scriptpath.fileName());
         if (!renderer.isEmpty() && renderer.contains('/') && !QFile::exists(renderer)) {
             item->setIcon(0, KIcon("dialog-cancel"));
             item->setToolTip(1, i18n("Script contains wrong command: %1", renderer));
+            item->setData(0, Qt::UserRole, '1');
         } else if (!melt.isEmpty() && melt.contains('/') && !QFile::exists(melt)) {
             item->setIcon(0, KIcon("dialog-cancel"));
             item->setToolTip(1, i18n("Script contains wrong command: %1", melt));
+            item->setData(0, Qt::UserRole, '1');
         } else item->setIcon(0, KIcon("application-x-executable-script"));
         item->setSizeHint(0, QSize(m_view.scripts_list->columnWidth(0), fontMetrics().height() * 2));
         item->setData(1, Qt::UserRole, target.simplified());
@@ -1454,11 +1590,10 @@ void RenderWidget::parseScriptFiles()
 
 void RenderWidget::slotCheckScript()
 {
-    bool activate = false;
-    QTreeWidgetItemIterator it(m_view.scripts_list);
-    if (*it) activate = true;
-    m_view.start_script->setEnabled(activate);
-    m_view.delete_script->setEnabled(activate);
+    QTreeWidgetItem *item = m_view.scripts_list->currentItem();
+    if (item == NULL) return;
+    m_view.start_script->setEnabled(item->data(0, Qt::UserRole).toString().isEmpty());
+    m_view.delete_script->setEnabled(true);
 }
 
 void RenderWidget::slotStartScript()
@@ -1513,11 +1648,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);
@@ -1554,16 +1692,19 @@ bool RenderWidget::startWaitingRenderJobs()
         return false;
     }
 
-    QString renderer = QCoreApplication::applicationDirPath() + QString("/kdenlive_render");
-    if (!QFile::exists(renderer)) renderer = "kdenlive_render";
     QTextStream outStream(&file);
     outStream << "#! /bin/sh" << "\n" << "\n";
     QTreeWidgetItem *item = m_view.running_jobs->topLevelItem(0);
     while (item) {
         if (item->data(1, Qt::UserRole + 2).toInt() == WAITINGJOB) {
-            // Add render process for item
-            const QString params = item->data(1, Qt::UserRole + 3).toStringList().join(" ");
-            outStream << renderer << " " << params << "\n";
+            if (item->data(1, Qt::UserRole + 4).isNull()) {
+                // Add render process for item
+                const QString params = item->data(1, Qt::UserRole + 3).toStringList().join(" ");
+                outStream << m_renderer << " " << params << "\n";
+            } else {
+                // Script item
+                outStream << item->data(1, Qt::UserRole + 3).toString() << "\n";
+            }
         }
         item = m_view.running_jobs->itemBelow(item);
     }
@@ -1597,7 +1738,9 @@ QString RenderWidget::getFreeScriptName(const QString &prefix)
 void RenderWidget::slotPlayRendering(QTreeWidgetItem *item, int)
 {
     if (KdenliveSettings::defaultplayerapp().isEmpty() || item->data(1, Qt::UserRole + 2).toInt() != FINISHEDJOB) return;
-    QProcess::startDetached(KdenliveSettings::defaultplayerapp(), QStringList() << item->text(1));
+    const QByteArray startId = KStartupInfo::createNewStartupId();
+    const QString command = KdenliveSettings::defaultplayerapp() + ' ' + item->text(1);
+    KRun::runCommand(command, KdenliveSettings::defaultplayerapp(), KdenliveSettings::defaultplayerapp(), this, startId);
 }