]> git.sesse.net Git - kdenlive/blobdiff - src/documentchecker.cpp
Improve handling of missing clips:
[kdenlive] / src / documentchecker.cpp
index 4aeafaf39c9152afa1b3a818e4f535422d82369f..3444503f3137cdf6b5be39d2818e5f6ea223b81a 100644 (file)
@@ -29,6 +29,7 @@
 #include <KFileDialog>
 #include <KApplication>
 #include <KUrlRequesterDialog>
+#include <KMessageBox>
 
 #include <QTreeWidgetItem>
 #include <QFile>
@@ -47,34 +48,13 @@ const int CLIPMISSING = 0;
 const int CLIPOK = 1;
 const int CLIPPLACEHOLDER = 2;
 
-DocumentChecker::DocumentChecker(QDomDocument doc, QWidget * parent) :
+DocumentChecker::DocumentChecker(QDomNodeList producers, QDomNodeList infoproducers, QList <QDomElement> missingClips, QDomDocument doc, QWidget * parent) :
         QDialog(parent), m_doc(doc)
 {
     setFont(KGlobalSettings::toolBarFont());
     m_view.setupUi(this);
-
-    QDomNodeList producers = m_doc.elementsByTagName("producer");
-    QDomNodeList infoproducers = m_doc.elementsByTagName("kdenlive_producer");
-
-    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()) QTimer::singleShot(0, this, SLOT(accept()));
     m_view.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
     for (int i = 0; i < missingClips.count(); i++) {
         e = missingClips.at(i).toElement();
@@ -110,6 +90,7 @@ DocumentChecker::DocumentChecker(QDomDocument doc, QWidget * parent) :
     }
     connect(m_view.recursiveSearch, SIGNAL(pressed()), this, SLOT(slotSearchClips()));
     connect(m_view.usePlaceholders, SIGNAL(pressed()), this, SLOT(slotPlaceholders()));
+    connect(m_view.removeSelected, SIGNAL(pressed()), this, SLOT(slotDeleteSelected()));
     connect(m_view.treeWidget, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)), this, SLOT(slotEditItem(QTreeWidgetItem *, int)));
     //adjustSize();
 }
@@ -121,6 +102,7 @@ void DocumentChecker::slotSearchClips()
     QString newpath = KFileDialog::getExistingDirectory(KUrl("kfiledialog:///clipfolder"), kapp->activeWindow(), i18n("Clips folder"));
     if (newpath.isEmpty()) return;
     int ix = 0;
+    m_view.recursiveSearch->setEnabled(false);
     QTreeWidgetItem *child = m_view.treeWidget->topLevelItem(ix);
     while (child && child->data(0, statusRole).toInt() == CLIPMISSING) {
         QString clipPath = searchFileRecursively(QDir(newpath), child->data(0, sizeRole).toString(), child->data(0, hashRole).toString());
@@ -132,6 +114,7 @@ void DocumentChecker::slotSearchClips()
         ix++;
         child = m_view.treeWidget->topLevelItem(ix);
     }
+    m_view.recursiveSearch->setEnabled(true);
     checkStatus();
 }
 
@@ -161,7 +144,7 @@ QString DocumentChecker::searchFileRecursively(const QDir &dir, const QString &m
                     return file.fileName();
             }
         }
-        kDebug() << filesAndDirs.at(i) << file.size() << fileHash.toHex();
+        //kDebug() << filesAndDirs.at(i) << file.size() << fileHash.toHex();
     }
     filesAndDirs = dir.entryList(QDir::Dirs | QDir::Readable | QDir::Executable | QDir::NoDotAndDotDot);
     for (int i = 0; i < filesAndDirs.size() && foundFileName.isEmpty(); i++) {
@@ -260,6 +243,70 @@ void DocumentChecker::checkStatus()
     m_view.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(status);
 }
 
+
+void DocumentChecker::slotDeleteSelected()
+{
+    if (KMessageBox::warningContinueCancel(this, i18n("This will remove the selected clips from this project"), i18n("Remove clips")) == KMessageBox::Cancel) return;
+    int ix = 0;
+    QStringList deletedIds;
+    QTreeWidgetItem *child = m_view.treeWidget->topLevelItem(ix);
+    QDomNodeList playlists = m_doc.elementsByTagName("playlist");
+
+    while (child) {
+        if (child->isSelected()) {
+            QString id = child->data(0, idRole).toString();
+            deletedIds.append(id);
+            for (int j = 0; j < playlists.count(); j++)
+                deletedIds.append(id + '_' + QString::number(j));
+            delete child;
+        } else ix++;
+        child = m_view.treeWidget->topLevelItem(ix);
+    }
+    kDebug() << "// Clips to delete: " << deletedIds;
+
+    if (!deletedIds.isEmpty()) {
+        QDomElement e;
+        QDomNodeList producers = m_doc.elementsByTagName("producer");
+        QDomNodeList infoproducers = m_doc.elementsByTagName("kdenlive_producer");
+
+        QDomElement westley = m_doc.firstChildElement("westley");
+        QDomElement kdenlivedoc = westley.firstChildElement("kdenlivedoc");
+
+        for (int i = 0; i < infoproducers.count(); i++) {
+            e = infoproducers.item(i).toElement();
+            if (deletedIds.contains(e.attribute("id"))) {
+                // Remove clip
+                kdenlivedoc.removeChild(e);
+                break;
+            }
+        }
+
+        for (int i = 0; i < producers.count(); i++) {
+            e = producers.item(i).toElement();
+            if (deletedIds.contains(e.attribute("id"))) {
+                // Remove clip
+                westley.removeChild(e);
+                break;
+            }
+        }
+
+        for (int i = 0; i < playlists.count(); i++) {
+            QDomNodeList entries = playlists.at(i).toElement().elementsByTagName("entry");
+            for (int j = 0; j < playlists.count(); j++) {
+                e = entries.item(j).toElement();
+                if (deletedIds.contains(e.attribute("producer"))) {
+                    // Replace clip with blank
+                    e.setTagName("blank");
+                    e.removeAttribute("producer");
+                    int length = e.attribute("out").toInt() - e.attribute("in").toInt();
+                    e.setAttribute("length", length);
+                }
+            }
+        }
+        checkStatus();
+    }
+}
+
 #include "documentchecker.moc"