]> git.sesse.net Git - kdenlive/commitdiff
Check script files for errors + cleanup
authorJean-Baptiste Mardelle <jb@kdenlive.org>
Tue, 23 Jun 2009 19:25:51 +0000 (19:25 +0000)
committerJean-Baptiste Mardelle <jb@kdenlive.org>
Tue, 23 Jun 2009 19:25:51 +0000 (19:25 +0000)
svn path=/trunk/kdenlive/; revision=3628

src/renderwidget.cpp
src/renderwidget.h

index 020d06e4c4c91de19d81fe098beb43810719e070..b71203ed8876b99af9a397f201ccc37d75b7969f 100644 (file)
@@ -159,19 +159,20 @@ RenderWidget::RenderWidget(const QString &projectfolder, QWidget * parent) :
 
     QHeaderView *header = m_view.running_jobs->header();
     QFontMetrics fm = fontMetrics();
-    //header->resizeSection(0, fm.width("typical-name-for-a-torrent.torrent"));
     header->setResizeMode(0, QHeaderView::Fixed);
     header->resizeSection(0, 30);
     header->setResizeMode(1, QHeaderView::Interactive);
-    header->resizeSection(1, fm.width("typical-name-for-a-file.torrent"));
     header->setResizeMode(2, QHeaderView::Fixed);
-    header->resizeSection(1, width() * 2 / 3);
+    header->resizeSection(1, width() * 2 / 3 - 15);
     header->setResizeMode(2, QHeaderView::Interactive);
     //header->setResizeMode(1, QHeaderView::Fixed);
 
-    m_view.scripts_list->setHeaderLabels(QStringList() << i18n("Script Files"));
-    m_view.scripts_list->setItemDelegate(new RenderScriptDelegate(this));
 
+    m_view.scripts_list->setHeaderLabels(QStringList() << QString() << i18n("Script Files"));
+    m_view.scripts_list->setItemDelegate(new RenderViewDelegate(this));
+    header = m_view.scripts_list->header();
+    header->setResizeMode(0, QHeaderView::Fixed);
+    header->resizeSection(0, 30);
 
     focusFirstVisibleItem();
 }
@@ -722,7 +723,10 @@ void RenderWidget::slotExport(bool scriptExport, int zoneIn, int zoneOut, const
         outStream << "#! /bin/sh" << "\n" << "\n";
         outStream << "SOURCE=" << "\"" + playlistPath + "\"" << "\n";
         outStream << "TARGET=" << "\"" + dest + "\"" << "\n";
-        outStream << renderer << " " << render_process_args.join(" ") << "\n" << "\n";
+        outStream << "RENDERER=" << "\"" + renderer + "\"" << "\n";
+        outStream << "MELT=" << "\"" + render_process_args.takeFirst() + "\"" << "\n";
+        outStream << "PARAMETERS=" << "\"" + render_process_args.join(" ") + "\"" << "\n";
+        outStream << "$RENDERER $MELT $PARAMETERS" << "\n" << "\n";
         if (file.error() != QFile::NoError) {
             KMessageBox::error(this, i18n("Cannot write to file %1", scriptPath));
             file.close();
@@ -762,7 +766,6 @@ void RenderWidget::slotExport(bool scriptExport, int zoneIn, int zoneOut, const
 
     // Set rendering type
     if (group == "dvd") {
-        renderParameters << QString::number(m_view.create_chapter->isChecked());
         if (m_view.open_dvd->isChecked()) {
             renderItem->setData(0, Qt::UserRole, group);
             if (renderArgs.contains("profile=")) {
@@ -774,7 +777,6 @@ void RenderWidget::slotExport(bool scriptExport, int zoneIn, int zoneOut, const
             }
         }
     } else {
-        renderParameters << QString::number(false);
         if (group == "websites" && m_view.open_browser->isChecked()) {
             renderItem->setData(0, Qt::UserRole, group);
             // pass the url
@@ -791,18 +793,26 @@ void RenderWidget::checkRenderStatus()
     if (m_blockProcessing) return;
     QTreeWidgetItem *item = m_view.running_jobs->topLevelItem(0);
     while (item) {
-        if (item->data(1, Qt::UserRole + 2).toInt() == RUNNINGJOB) break;
-        else if (item->data(1, Qt::UserRole + 2).toInt() == WAITINGJOB) {
+        if (item->data(1, Qt::UserRole + 2).toInt() == RUNNINGJOB) return;
+        item = m_view.running_jobs->itemBelow(item);
+    }
+    item = m_view.running_jobs->topLevelItem(0);
+    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);
-                //emit doRender(item->data(1, Qt::UserRole + 3).toStringList(), item->data(1, Qt::UserRole + 2).toStringList());
             } else {
                 // Script item
-                QProcess::startDetached(item->data(1, Qt::UserRole + 3).toString());
+                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);
+                }
             }
             break;
         }
@@ -1399,23 +1409,37 @@ 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() << scriptpath.fileName());
+        item = new QTreeWidgetItem(m_view.scripts_list, QStringList() << QString() << scriptpath.fileName());
         QString target;
+        QString renderer;
+        QString melt;
         QFile file(scriptpath.path());
         if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
             while (!file.atEnd()) {
                 QByteArray line = file.readLine();
                 if (line.startsWith("TARGET=")) {
-                    target = QString(line).section("TARGET=", 1);
+                    target = QString(line).section("TARGET=", 1).simplified();
                     target.remove(QChar('"'));
-                    break;
+                } else if (line.startsWith("RENDERER=")) {
+                    renderer = QString(line).section("RENDERER=", 1).simplified();
+                    renderer.remove(QChar('"'));
+                } else if (line.startsWith("MELT=")) {
+                    melt = QString(line).section("MELT=", 1).simplified();
+                    melt.remove(QChar('"'));
                 }
             }
             file.close();
         }
+        if (!renderer.isEmpty() && renderer.contains('/') && !QFile::exists(renderer)) {
+            item->setIcon(0, KIcon("dialog-cancel"));
+            item->setToolTip(1, i18n("Script contains wrong command: %1", renderer));
+        } 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));
+        } else item->setIcon(0, KIcon("application-x-executable-script"));
         item->setSizeHint(0, QSize(m_view.scripts_list->columnWidth(0), fontMetrics().height() * 2));
-        item->setData(0, Qt::UserRole, target.simplified());
-        item->setData(0, Qt::UserRole + 1, scriptpath.path());
+        item->setData(1, Qt::UserRole, target.simplified());
+        item->setData(1, Qt::UserRole + 1, scriptpath.path());
     }
     bool activate = false;
     QTreeWidgetItem *script = m_view.scripts_list->topLevelItem(0);
@@ -1441,8 +1465,8 @@ void RenderWidget::slotStartScript()
 {
     QTreeWidgetItem *item = m_view.scripts_list->currentItem();
     if (item) {
-        QString destination = item->data(0, Qt::UserRole).toString();
-        QString path = item->data(0, Qt::UserRole + 1).toString();
+        QString destination = item->data(1, Qt::UserRole).toString();
+        QString path = item->data(1, Qt::UserRole + 1).toString();
         // Insert new job in queue
         QTreeWidgetItem *renderItem;
         QList<QTreeWidgetItem *> existing = m_view.running_jobs->findItems(destination, Qt::MatchExactly, 1);
@@ -1472,7 +1496,7 @@ void RenderWidget::slotDeleteScript()
 {
     QTreeWidgetItem *item = m_view.scripts_list->currentItem();
     if (item) {
-        QString path = item->data(0, Qt::UserRole + 1).toString();
+        QString path = item->data(1, Qt::UserRole + 1).toString();
         KIO::NetAccess::del(path + ".mlt", this);
         KIO::NetAccess::del(path, this);
         parseScriptFiles();
@@ -1548,6 +1572,7 @@ bool RenderWidget::startWaitingRenderJobs()
     if (file.error() != QFile::NoError) {
         KMessageBox::error(0, i18n("Cannot write to file %1", autoscriptFile));
         file.close();
+        m_blockProcessing = false;
         return false;
     }
     file.close();
index 33cc4b5abce974563c90ea8d4deb9c43540210b9..bc9beaf5886ad1a77bdadcd255ef0c691fe874be 100644 (file)
@@ -40,10 +40,7 @@ public:
 
     void paint(QPainter *painter, const QStyleOptionViewItem &option,
                const QModelIndex &index) const {
-        if (index.column() == 0) {
-            QItemDelegate::paint(painter, option, index);
-            return;
-        } else if (index.column() == 1) {
+        if (index.column() == 1) {
             QRect r1 = option.rect;
             painter->save();
             if (option.state & (QStyle::State_Selected)) {
@@ -63,76 +60,40 @@ public:
             painter->setPen(option.palette.color(QPalette::Mid));
             painter->drawText(r2, Qt::AlignLeft | Qt::AlignVCenter , index.data(Qt::UserRole).toString());
             painter->restore();
-            return;
-        }
-        // Set up a QStyleOptionProgressBar to precisely mimic the
-        // environment of a progress bar.
-        QStyleOptionProgressBar progressBarOption;
-        progressBarOption.state = option.state;
-        progressBarOption.direction = QApplication::layoutDirection();
-        QRect rect = option.rect;
-        if (option.state & (QStyle::State_Selected)) {
-            painter->setPen(option.palette.color(QPalette::HighlightedText));
-            painter->fillRect(rect, option.palette.highlight());
-        }
-
-        int mid = rect.height() / 2;
-        rect.setTop(rect.top() + mid / 2);
-        rect.setHeight(mid);
-        progressBarOption.rect = rect;
-        progressBarOption.fontMetrics = QApplication::fontMetrics();
-        progressBarOption.minimum = 0;
-        progressBarOption.maximum = 100;
-        progressBarOption.textAlignment = Qt::AlignCenter;
-        progressBarOption.textVisible = true;
-
-        // Set the progress and text values of the style option.
-        int progress = index.data(Qt::UserRole).toInt();
-        progressBarOption.progress = progress < 0 ? 0 : progress;
-        progressBarOption.text = QString().sprintf("%d%%", progressBarOption.progress);
-
-        // Draw the progress bar onto the view.
-        QApplication::style()->drawControl(QStyle::CE_ProgressBar, &progressBarOption, painter);
-    }
-};
-
-
-// RenderScriptDelegate is used to draw the script items.
-class RenderScriptDelegate : public QItemDelegate
-{
-    Q_OBJECT
-public:
-    RenderScriptDelegate(QWidget *parent) : QItemDelegate(parent) {}
-
-    void paint(QPainter *painter, const QStyleOptionViewItem &option,
-               const QModelIndex &index) const {
-        if (index.column() == 0) {
-            QRect r1 = option.rect;
-            painter->save();
+        } else if (index.column() == 2) {
+            // Set up a QStyleOptionProgressBar to precisely mimic the
+            // environment of a progress bar.
+            QStyleOptionProgressBar progressBarOption;
+            progressBarOption.state = option.state;
+            progressBarOption.direction = QApplication::layoutDirection();
+            QRect rect = option.rect;
             if (option.state & (QStyle::State_Selected)) {
                 painter->setPen(option.palette.color(QPalette::HighlightedText));
-                painter->fillRect(r1, option.palette.highlight());
-            } else painter->setPen(option.palette.color(QPalette::Text));
-            QFont font = painter->font();
-            font.setBold(true);
-            painter->setFont(font);
-            int mid = (int)((r1.height() / 2));
-            r1.setBottom(r1.y() + mid);
-            r1.setLeft(r1.left() + 3);
-            QRect r2 = option.rect;
-            r2.setTop(r2.y() + mid);
-            r2.setLeft(r2.left() + 3);
-            painter->drawText(r1, Qt::AlignLeft | Qt::AlignBottom , index.data().toString());
-            font.setBold(false);
-            painter->setFont(font);
-            painter->setPen(option.palette.color(QPalette::Mid));
-            painter->drawText(r2, Qt::AlignLeft | Qt::AlignVCenter , index.data(Qt::UserRole).toString());
-            painter->restore();
-            return;
+                painter->fillRect(rect, option.palette.highlight());
+            }
+
+            int mid = rect.height() / 2;
+            rect.setTop(rect.top() + mid / 2);
+            rect.setHeight(mid);
+            progressBarOption.rect = rect;
+            progressBarOption.fontMetrics = QApplication::fontMetrics();
+            progressBarOption.minimum = 0;
+            progressBarOption.maximum = 100;
+            progressBarOption.textAlignment = Qt::AlignCenter;
+            progressBarOption.textVisible = true;
+
+            // Set the progress and text values of the style option.
+            int progress = index.data(Qt::UserRole).toInt();
+            progressBarOption.progress = progress < 0 ? 0 : progress;
+            progressBarOption.text = QString().sprintf("%d%%", progressBarOption.progress);
+
+            // Draw the progress bar onto the view.
+            QApplication::style()->drawControl(QStyle::CE_ProgressBar, &progressBarOption, painter);
         } else QItemDelegate::paint(painter, option, index);
     }
 };
 
+
 class RenderWidget : public QDialog
 {
     Q_OBJECT