]> git.sesse.net Git - kdenlive/blobdiff - src/renderwidget.cpp
const modifiers are useless on integral return types [PATCH by Ray Lehtiniemi]
[kdenlive] / src / renderwidget.cpp
index 9b38562e269a2dc5370868878dc3aad3385a15ad..b16c0e34b8b61db3eaea9ccd3f67401b9220aa30 100644 (file)
  ***************************************************************************/
 
 
-#include <QDomDocument>
-#include <QItemDelegate>
-#include <QTreeWidgetItem>
-#include <QListWidgetItem>
-#include <QHeaderView>
-#include <QMenu>
-#include <QProcess>
-#include <QInputDialog>
+#include "renderwidget.h"
+#include "kdenlivesettings.h"
+#include "ui_saveprofile_ui.h"
 
 #include <KStandardDirs>
 #include <KDebug>
 #include <KComboBox>
 #include <KRun>
 #include <KIO/NetAccess>
+// #include <knewstuff2/engine.h>
 
-#include "kdenlivesettings.h"
-#include "renderwidget.h"
-#include "ui_saveprofile_ui.h"
+#include <QDomDocument>
+#include <QItemDelegate>
+#include <QTreeWidgetItem>
+#include <QListWidgetItem>
+#include <QHeaderView>
+#include <QMenu>
+#include <QProcess>
+#include <QInputDialog>
 
 const int GroupRole = Qt::UserRole;
 const int ExtensionRole = GroupRole + 1;
@@ -72,9 +73,9 @@ RenderWidget::RenderWidget(const QString &projectfolder, QWidget * parent): QDia
 
 
     QMenu *renderMenu = new QMenu(i18n("Start Rendering"), this);
-    QAction *renderAction = renderMenu->addAction(KIcon("file-new"), i18n("Render to File"));
+    QAction *renderAction = renderMenu->addAction(KIcon("video-x-generic"), i18n("Render to File"));
     connect(renderAction, SIGNAL(triggered()), this, SLOT(slotExport()));
-    QAction *scriptAction = renderMenu->addAction(KIcon("file-new"), i18n("Generate Script"));
+    QAction *scriptAction = renderMenu->addAction(KIcon("application-x-shellscript"), i18n("Generate Script"));
     connect(scriptAction, SIGNAL(triggered()), this, SLOT(slotGenerateScript()));
 
     m_view.buttonStart->setMenu(renderMenu);
@@ -85,6 +86,8 @@ RenderWidget::RenderWidget(const QString &projectfolder, QWidget * parent): QDia
     m_view.start_script->setEnabled(false);
     m_view.delete_script->setEnabled(false);
 
+    m_view.format_list->setAlternatingRowColors(true);
+    m_view.size_list->setAlternatingRowColors(true);
 
     parseProfiles();
     parseScriptFiles();
@@ -156,7 +159,8 @@ RenderWidget::RenderWidget(const QString &projectfolder, QWidget * parent): QDia
 }
 
 void RenderWidget::slotEditItem(QListWidgetItem *item) {
-    if (item->data(EditableRole).toString().isEmpty()) slotSaveProfile();
+    QString edit = item->data(EditableRole).toString();
+    if (edit.isEmpty() || !edit.endsWith("customprofiles.xml")) slotSaveProfile();
     else slotEditProfile();
 }
 
@@ -421,6 +425,17 @@ void RenderWidget::slotEditProfile() {
 }
 
 void RenderWidget::slotDeleteProfile(bool refresh) {
+    //TODO: delete a profile installed by KNewStuff the easy way
+    /*
+    QString edit = m_view.size_list->currentItem()->data(EditableRole).toString();
+    if (!edit.endsWith("customprofiles.xml")) {
+        // This is a KNewStuff installed file, process through KNS
+        KNS::Engine engine(0);
+        if (engine.init("kdenlive_render.knsrc")) {
+            KNS::Entry::List entries;
+        }
+        return;
+    }*/
     QString currentGroup = m_view.format_list->currentItem()->text();
     QString currentProfile = m_view.size_list->currentItem()->text();
     QString metaGroupId = m_view.destination_list->itemData(m_view.destination_list->currentIndex(), Qt::UserRole).toString();
@@ -473,9 +488,9 @@ void RenderWidget::updateButtons() {
         m_view.buttonStart->setEnabled(false);
     } else {
         m_view.buttonSave->setEnabled(true);
-        kDebug() << "BUTT: " << m_view.size_list->currentItem()->flags();
         m_view.buttonStart->setEnabled(m_view.size_list->currentItem()->flags() & Qt::ItemIsEnabled);
-        if (m_view.size_list->currentItem()->data(EditableRole).toString().isEmpty()) {
+        QString edit = m_view.size_list->currentItem()->data(EditableRole).toString();
+        if (edit.isEmpty() || !edit.endsWith("customprofiles.xml")) {
             m_view.buttonDelete->setEnabled(false);
             m_view.buttonEdit->setEnabled(false);
         } else {
@@ -560,7 +575,7 @@ void RenderWidget::slotExport(bool scriptExport) {
         width = m_profile.width;
         height = m_profile.height;
     }
-    renderArgs.replace("%dar", "@" + QString::number(m_profile.display_aspect_num) + "/" + QString::number(m_profile.display_aspect_den));
+    renderArgs.replace("%dar", '@' + QString::number(m_profile.display_aspect_num) + '/' + QString::number(m_profile.display_aspect_den));
 
     // Adjust scanning
     if (m_view.scanning_list->currentIndex() == 1) renderArgs.append(" progressive=1");
@@ -599,7 +614,7 @@ void RenderWidget::slotExport(bool scriptExport) {
     if (group == "dvd" && 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, usefull 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;
@@ -803,8 +818,8 @@ void RenderWidget::refreshParams() {
 //         m_view.out_file->setUrl(KUrl(QDir::homePath() + "/untitled." + extension));
 //     }
     m_view.out_file->setFilter("*." + extension);
-
-    if (item->data(EditableRole).toString().isEmpty()) {
+    QString edit = item->data(EditableRole).toString();
+    if (edit.isEmpty() || !edit.endsWith("customprofiles.xml")) {
         m_view.buttonDelete->setEnabled(false);
         m_view.buttonEdit->setEnabled(false);
     } else {
@@ -839,9 +854,13 @@ void RenderWidget::parseProfiles(QString meta, QString group, QString profile) {
     QDir directory = QDir(exportFolder);
     QStringList filter;
     filter << "*.xml";
-    const QStringList fileList = directory.entryList(filter, QDir::Files);
-    foreach(const QString filename, fileList)
-    parseFile(exportFolder + '/' + filename, filename == "customprofiles.xml");
+    QStringList fileList = directory.entryList(filter, QDir::Files);
+    // We should parse customprofiles.xml in last position, so that user profiles
+    // 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);
 
     if (!meta.isEmpty()) {
         m_view.destination_list->blockSignals(true);
@@ -941,6 +960,19 @@ void RenderWidget::parseFile(QString exportFile, bool editable) {
                 item->setData(MetaGroupRole, dest);
             }
 
+            // Check if item with same name already exists and replace it,
+            // allowing to override default profiles
+
+            list = m_view.size_list->findItems(profileName, Qt::MatchExactly);
+
+            for (int j = 0; j < list.count(); j++) {
+                if (list.at(j)->data(MetaGroupRole) == dest) {
+                    QListWidgetItem *duplicate = list.takeAt(j);
+                    delete duplicate;
+                    j--;
+                }
+            }
+
             item = new QListWidgetItem(profileName, m_view.size_list);
             //kDebug() << "// ADDINg item with name: " << profileName << ", GRP" << category << ", DEST:" << dest ;
             item->setData(GroupRole, category);
@@ -950,7 +982,11 @@ void RenderWidget::parseFile(QString exportFile, bool editable) {
             item->setData(StandardRole, standard);
             item->setData(ParamsRole, params);
             if (profile.hasAttribute("url")) item->setData(ExtraRole, profile.attribute("url"));
-            if (editable) item->setData(EditableRole, "true");
+            if (editable) {
+                item->setData(EditableRole, exportFile);
+                if (exportFile.endsWith("customprofiles.xml")) item->setIcon(KIcon("emblem-favorite"));
+                else item->setIcon(KIcon("applications-internet"));
+            }
             node = doc.elementsByTagName("profile").at(count);
             count++;
         }
@@ -986,8 +1022,8 @@ void RenderWidget::parseFile(QString exportFile, bool editable) {
             }
         }
         groupName = documentElement.attribute("name", i18n("Custom"));
-        extension = documentElement.attribute("extension", QString::null);
-        renderer = documentElement.attribute("renderer", QString::null);
+        extension = documentElement.attribute("extension", QString());
+        renderer = documentElement.attribute("renderer", QString());
         QList <QListWidgetItem *> list = m_view.format_list->findItems(groupName, Qt::MatchExactly);
         bool exists = false;
         for (int j = 0; j < list.count(); j++) {
@@ -1021,7 +1057,7 @@ void RenderWidget::parseFile(QString exportFile, bool editable) {
             item->setData(StandardRole, standard);
             item->setData(ParamsRole, params);
             if (profileElement.hasAttribute("url")) item->setData(ExtraRole, profileElement.attribute("url"));
-            if (editable) item->setData(EditableRole, "true");
+            if (editable) item->setData(EditableRole, exportFile);
             n = n.nextSibling();
         }
 
@@ -1067,7 +1103,7 @@ void RenderWidget::setRenderStatus(const QString &dest, int status, const QStrin
             emit openDvdWizard(item->text(1), item->data(0, Qt::UserRole + 1).toString());
         } else if (itemGroup == "websites") {
             QString url = item->data(0, Qt::UserRole + 1).toString();
-            if (!url.isEmpty()) KRun *openBrowser = new KRun(url, this);
+            if (!url.isEmpty()) new KRun(url, this);
         }
     } else if (status == -2) {
         // Rendering crashed
@@ -1173,4 +1209,5 @@ void RenderWidget::slotDeleteScript() {
 
 void RenderWidget::slotGenerateScript() {
     slotExport(true);
-}
\ No newline at end of file
+}
+