]> git.sesse.net Git - kdenlive/blobdiff - src/documentchecker.cpp
Prevent crash when deleting a clip while playing:
[kdenlive] / src / documentchecker.cpp
index 7df155d009820b4489cb5ed1886da58e673b3c77..7b36f7784d45edb340d22f1e26c7fe0720a27b1c 100644 (file)
@@ -112,7 +112,7 @@ bool DocumentChecker::hasErrorInClips()
         resource = e.attribute("resource");
         if (e.hasAttribute("proxy")) {
             QString proxyresource = e.attribute("proxy");
-            if (!KIO::NetAccess::exists(KUrl(proxyresource), KIO::NetAccess::SourceSide, 0)) {
+            if (!proxyresource.isEmpty() && proxyresource != "-" && !KIO::NetAccess::exists(KUrl(proxyresource), KIO::NetAccess::SourceSide, 0)) {
                 // Missing clip found
                 missingProxies.append(e);
             }
@@ -137,8 +137,9 @@ bool DocumentChecker::hasErrorInClips()
     for (int i = 0; i < trans.count(); i++) {
         QString luma = getProperty(trans.at(i).toElement(), "luma");
         if (!luma.isEmpty()) {
-            if (!luma.startsWith('/')) luma.prepend(root);
-            if (!QFile::exists(luma) && !missingLumas.contains(luma)) {
+            QString lumaPath = luma;
+            if (!lumaPath.startsWith('/')) lumaPath.prepend(root);
+            if (!QFile::exists(lumaPath) && !missingLumas.contains(luma)) {
                 missingLumas.append(luma);
             }
         }
@@ -276,20 +277,56 @@ bool DocumentChecker::hasErrorInClips()
         item->setToolTip(0, i18n("Duration mismatch"));
     }
 
-
-    for (int i = 0; i < missingProxies.count(); i++) {
-        e = missingProxies.at(i).toElement();
-        QString clipType;
-        int t = e.attribute("type").toInt();
+    if (missingProxies.count() > 0) {
         QTreeWidgetItem *item = new QTreeWidgetItem(m_ui.treeWidget, QStringList() << i18n("Proxy clip"));
-        item->setIcon(0, KIcon("dialog-close"));
-        item->setText(1, e.attribute("proxy"));
+        item->setIcon(0, KIcon("dialog-warning"));
+        item->setText(1, i18n("%1 missing proxy clips, will be recreated on project opening", missingProxies.count()));
         item->setData(0, hashRole, e.attribute("file_hash"));
         item->setData(0, statusRole, PROXYMISSING);
-        item->setData(0, typeRole, t);
-        item->setData(0, idRole, e.attribute("id"));
         item->setToolTip(0, i18n("Missing proxy"));
     }
+
+    for (int i = 0; i < missingProxies.count(); i++) {
+        e = missingProxies.at(i).toElement();
+        QString clipType;
+        QString realPath = e.attribute("resource");
+        QString id = e.attribute("id");
+        // Replace proxy url with real clip in MLT producers
+        QDomNodeList properties;
+        QDomElement mltProd;
+        QDomElement property;
+        for (int j = 0; j < documentProducers.count(); j++) {
+            mltProd = documentProducers.at(j).toElement();
+            QString prodId = mltProd.attribute("id");
+            bool slowmotion = false;
+            if (prodId.startsWith("slowmotion")) {
+                slowmotion = true;
+                prodId = prodId.section(':', 1, 1);
+            }
+            if (prodId.contains('_')) prodId = prodId.section('_', 0, 0);
+            if (prodId == id) {
+                // Hit, we must replace url
+                properties = mltProd.childNodes();
+                for (int k = 0; k < properties.count(); ++k) {
+                    property = properties.item(k).toElement();
+                    if (property.attribute("name") == "resource") {
+                        QString resource = property.firstChild().nodeValue();                    
+                        QString suffix;
+                        if (slowmotion) suffix = "?" + resource.section('?', -1);
+                        property.firstChild().setNodeValue(realPath + suffix);
+                        break;
+                    }
+                }
+            }
+        }
+    }
+    
+    if (missingProxies.count() > 0) {
+        // original doc was modified
+        QDomNode infoXmlNode = m_doc.elementsByTagName("kdenlivedoc").at(0);
+        QDomElement infoXml = infoXmlNode.toElement();
+        infoXml.setAttribute("modified", "1");
+    }
     
     connect(m_ui.recursiveSearch, SIGNAL(pressed()), this, SLOT(slotSearchClips()));
     connect(m_ui.usePlaceholders, SIGNAL(pressed()), this, SLOT(slotPlaceholders()));
@@ -382,6 +419,13 @@ QString DocumentChecker::searchLuma(QString file) const
     else
         searchPath.cd("../lumas/NTSC");
     QString result = searchPath.path(KUrl::AddTrailingSlash) + KUrl(file).fileName();
+    if (QFile::exists(result))
+        return result;
+    // try to find luma in application path
+    searchPath.clear();
+    searchPath = KUrl(QCoreApplication::applicationDirPath());
+    searchPath.cd("../share/apps/kdenlive/lumas");
+    result = searchPath.path(KUrl::AddTrailingSlash) + KUrl(file).fileName();
     if (QFile::exists(result))
         return result;
     return QString();
@@ -540,6 +584,7 @@ void DocumentChecker::acceptDialog()
         } else if (child->data(0, statusRole).toInt() == LUMAOK) {
             for (int i = 0; i < trans.count(); i++) {
                 QString luma = getProperty(trans.at(i).toElement(), "luma");
+                
                 kDebug() << "luma: " << luma;
                 if (!luma.isEmpty() && luma == child->data(0, idRole).toString()) {
                     setProperty(trans.at(i).toElement(), "luma", child->text(1));
@@ -629,15 +674,32 @@ void DocumentChecker::slotDeleteSelected()
     if (KMessageBox::warningContinueCancel(m_dialog, i18np("This will remove the selected clip from this project", "This will remove the selected clips from this project", m_ui.treeWidget->selectedItems().count()), i18n("Remove clips")) == KMessageBox::Cancel)
         return;
     QStringList deletedIds;
+    QStringList deletedLumas;
     QDomNodeList playlists = m_doc.elementsByTagName("playlist");
 
     foreach(QTreeWidgetItem *child, m_ui.treeWidget->selectedItems()) {
-        if (child->data(0, statusRole).toInt() < 10) {
+        int id = child->data(0, statusRole).toInt();
+        if (id == CLIPMISSING) {
             deletedIds.append(child->data(0, idRole).toString());
             delete child;
         }
+        else if (id == LUMAMISSING) {
+            deletedLumas.append(child->data(0, idRole).toString());
+            delete child;
+        }
+    }
+
+    if (!deletedLumas.isEmpty()) {
+        QDomElement e;
+        QDomNodeList transitions = m_doc.elementsByTagName("transition");
+        foreach (QString lumaPath, deletedLumas) {
+            for (int i = 0; i < transitions.count(); i++) {
+                e = transitions.item(i).toElement();
+                QString resource = EffectsList::property(e, "luma");
+                if (resource == lumaPath) EffectsList::removeProperty(e, "luma");
+            }
+        }
     }
-    kDebug() << "// Clips to delete: " << deletedIds;
 
     if (!deletedIds.isEmpty()) {
         QDomElement e;
@@ -723,7 +785,8 @@ void DocumentChecker::slotCheckButtons()
     if (m_ui.treeWidget->currentItem()) {
         QTreeWidgetItem *item = m_ui.treeWidget->currentItem();
         int t = item->data(0, typeRole).toInt();
-        if (t == TITLE_FONT_ELEMENT || t == TITLE_IMAGE_ELEMENT) {
+        int s = item->data(0, statusRole).toInt();
+        if (t == TITLE_FONT_ELEMENT || t == TITLE_IMAGE_ELEMENT || s == PROXYMISSING) {
             m_ui.removeSelected->setEnabled(false);
         } else m_ui.removeSelected->setEnabled(true);
     }