]> git.sesse.net Git - kdenlive/blobdiff - src/kdenlivedoc.cpp
Improve handling of missing clips:
[kdenlive] / src / kdenlivedoc.cpp
index eb12c9f4a183d5dc16138a1e726acc8cc7701c87..f10e6caa0636fa27ae7956f1ea36228c476018be 100644 (file)
@@ -134,9 +134,9 @@ KdenliveDoc::KdenliveDoc(const KUrl &url, const KUrl &projectFolder, QUndoGroup
                         }
                         westley.removeChild(tracksinfo);
                     }
-                    checkDocumentClips();
                     QDomNodeList producers = m_document.elementsByTagName("producer");
                     QDomNodeList infoproducers = m_document.elementsByTagName("kdenlive_producer");
+                    if (checkDocumentClips(producers, infoproducers) == false) m_abortLoading = true;
                     const int max = producers.count();
                     const int infomax = infoproducers.count();
 
@@ -1357,7 +1357,7 @@ void KdenliveDoc::addClip(QDomElement elem, QString clipId, bool createClipItem)
 {
     const QString producerId = clipId.section('_', 0, 0);
     DocClipBase *clip = m_clipManager->getClipById(producerId);
-    bool placeHolder = false;
+
     if (clip == NULL) {
         elem.setAttribute("id", producerId);
         QString path = elem.attribute("resource");
@@ -1390,7 +1390,7 @@ void KdenliveDoc::addClip(QDomElement elem, QString clipId, bool createClipItem)
             delete dia_ui;
         }
 
-        if (path.isEmpty() == false && QFile::exists(path) == false && elem.attribute("type").toInt() != TEXT) {
+        if (path.isEmpty() == false && QFile::exists(path) == false && elem.attribute("type").toInt() != TEXT && !elem.hasAttribute("placeholder")) {
             kDebug() << "// FOUND MISSING CLIP: " << path << ", TYPE: " << elem.attribute("type").toInt();
             const QString size = elem.attribute("file_size");
             const QString hash = elem.attribute("file_hash");
@@ -1429,7 +1429,7 @@ void KdenliveDoc::addClip(QDomElement elem, QString clipId, bool createClipItem)
                 return;
             } else if (action == KMessageBox::No) {
                 // Keep clip as placeHolder
-                placeHolder = true;
+                elem.setAttribute("placeholder", '1');
             }
             if (!newpath.isEmpty()) {
                 if (elem.attribute("type").toInt() == SLIDESHOW) newpath.append('/' + extension);
@@ -1438,7 +1438,7 @@ void KdenliveDoc::addClip(QDomElement elem, QString clipId, bool createClipItem)
                 setModified(true);
             }
         }
-        clip = new DocClipBase(m_clipManager, elem, producerId, placeHolder);
+        clip = new DocClipBase(m_clipManager, elem, producerId);
         m_clipManager->addClip(clip);
     }
 
@@ -1680,10 +1680,28 @@ QString KdenliveDoc::getLadspaFile() const
     return m_projectFolder.path() + "/ladspa/" + counter + ".ladspa";
 }
 
-void KdenliveDoc::checkDocumentClips()
+bool KdenliveDoc::checkDocumentClips(QDomNodeList producers, QDomNodeList infoproducers)
 {
-    DocumentChecker d(m_document);
-    d.exec();
+    int clipType;
+    QDomElement e;
+    QString id;
+    QString resource;
+    QList <QDomElement> missingClips;
+    for (int i = 0; i < infoproducers.count(); i++) {
+        e = infoproducers.item(i).toElement();
+        clipType = e.attribute("type").toInt();
+        if (clipType == TEXT) continue;
+        id = e.attribute("id");
+        resource = e.attribute("resource");
+        if (clipType == SLIDESHOW) resource = KUrl(resource).directory();
+        if (!KIO::NetAccess::exists(KUrl(resource), KIO::NetAccess::SourceSide, 0)) {
+            // Missing clip found
+            missingClips.append(e);
+        }
+    }
+    if (missingClips.isEmpty()) return true;
+    DocumentChecker d(producers, infoproducers, missingClips, m_document);
+    return (d.exec() == QDialog::Accepted);
 }