]> git.sesse.net Git - kdenlive/blobdiff - src/documentchecker.cpp
First work on rotoscoping GUI
[kdenlive] / src / documentchecker.cpp
index 6af599747055e167cae2244345a2f0e439476ec8..a998171113fe6634e12898c055899442e0c38fda 100644 (file)
@@ -59,7 +59,7 @@ const int LUMAPLACEHOLDER = 12;
 enum TITLECLIPTYPE { TITLE_IMAGE_ELEMENT = 20, TITLE_FONT_ELEMENT = 21 };
 
 DocumentChecker::DocumentChecker(QDomNodeList infoproducers, QDomDocument doc):
-        m_info(infoproducers), m_doc(doc), m_dialog(NULL)
+    m_info(infoproducers), m_doc(doc), m_dialog(NULL)
 {
 
 }
@@ -97,28 +97,35 @@ bool DocumentChecker::hasMissingClips()
             }
         }
     }
-    if (missingClips.isEmpty()) {
-        return false;
-    }
-    m_dialog = new QDialog();
-    m_dialog->setFont(KGlobalSettings::toolBarFont());
-    m_ui.setupUi(m_dialog);
 
     QStringList missingLumas;
+    QString root = m_doc.documentElement().attribute("root");
+    if (!root.isEmpty()) root = KUrl(root).path(KUrl::AddTrailingSlash);
     QDomNodeList trans = m_doc.elementsByTagName("transition");
     for (int i = 0; i < trans.count(); i++) {
         QString luma = getProperty(trans.at(i).toElement(), "luma");
-        if (!luma.isEmpty() && !QFile::exists(luma)) {
-            if (!missingLumas.contains(luma)) {
+        if (!luma.isEmpty()) {
+            if (!luma.startsWith('/')) luma.prepend(root);
+            if (!QFile::exists(luma) && !missingLumas.contains(luma)) {
                 missingLumas.append(luma);
-                QTreeWidgetItem *item = new QTreeWidgetItem(m_ui.treeWidget, QStringList() << i18n("Luma file") << luma);
-                item->setIcon(0, KIcon("dialog-close"));
-                item->setData(0, idRole, luma);
-                item->setData(0, statusRole, LUMAMISSING);
             }
         }
     }
 
+    if (missingClips.isEmpty() && missingLumas.isEmpty())
+        return false;
+
+    m_dialog = new QDialog();
+    m_dialog->setFont(KGlobalSettings::toolBarFont());
+    m_ui.setupUi(m_dialog);
+
+    foreach(const QString l, missingLumas) {
+        QTreeWidgetItem *item = new QTreeWidgetItem(m_ui.treeWidget, QStringList() << i18n("Luma file") << l);
+        item->setIcon(0, KIcon("dialog-close"));
+        item->setData(0, idRole, l);
+        item->setData(0, statusRole, LUMAMISSING);
+    }
+
     m_ui.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
     for (int i = 0; i < missingClips.count(); i++) {
         e = missingClips.at(i).toElement();
@@ -164,7 +171,7 @@ bool DocumentChecker::hasMissingClips()
             item->setToolTip(1, e.attribute("name"));
             QString ft = e.attribute("resource");
             QString newft = QFontInfo(QFont(ft)).family();
-            item->setText(1, i18n("%1, will be replaced by %2", ft, newft));
+            item->setText(1, i18n("%1 will be replaced by %2", ft, newft));
             item->setData(0, statusRole, CLIPPLACEHOLDER);
         } else {
             item->setIcon(0, KIcon("dialog-close"));
@@ -277,7 +284,7 @@ QString DocumentChecker::searchFileRecursively(const QDir &dir, const QString &m
                 * 1 MB = 1 second per 450 files (or faster)
                 * 10 MB = 9 seconds per 450 files (or faster)
                 */
-                if (file.size() > 1000000*2) {
+                if (file.size() > 1000000 * 2) {
                     fileData = file.read(1000000);
                     if (file.seek(file.size() - 1000000))
                         fileData.append(file.readAll());
@@ -336,6 +343,9 @@ void DocumentChecker::acceptDialog()
     // prepare transitions
     QDomNodeList trans = m_doc.elementsByTagName("transition");
 
+    // Mark document as modified
+    m_doc.documentElement().setAttribute("modified", 1);
+
     QTreeWidgetItem *child = m_ui.treeWidget->topLevelItem(ix);
     while (child) {
         int t = child->data(0, typeRole).toInt();
@@ -382,13 +392,17 @@ void DocumentChecker::acceptDialog()
                 }
                 for (int i = 0; i < producers.count(); i++) {
                     e = producers.item(i).toElement();
-                    if (e.attribute("id").section('_', 0, 0) == id) {
+                    if (e.attribute("id").section('_', 0, 0) == id || e.attribute("id").section(':', 1, 1) == id) {
                         // Fix clip
                         properties = e.childNodes();
                         for (int j = 0; j < properties.count(); ++j) {
                             property = properties.item(j).toElement();
                             if (property.attribute("name") == "resource") {
-                                property.firstChild().setNodeValue(child->text(1));
+                                QString resource = property.firstChild().nodeValue();
+                                if (resource.contains(QRegExp("\\?[0-9]+\\.[0-9]+(&amp;strobe=[0-9]+)?$")))
+                                    property.firstChild().setNodeValue(child->text(1) + '?' + resource.section('?', -1));
+                                else
+                                    property.firstChild().setNodeValue(child->text(1));
                                 break;
                             }
                         }
@@ -466,22 +480,16 @@ void DocumentChecker::checkStatus()
 
 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;
-    int ix = 0;
+    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;
-    QTreeWidgetItem *child = m_ui.treeWidget->topLevelItem(ix);
     QDomNodeList playlists = m_doc.elementsByTagName("playlist");
 
-    while (child) {
-        int id = child->data(0, statusRole).toInt();
-        if (child->isSelected() && id < 10) {
-            QString id = child->data(0, idRole).toString();
-            deletedIds.append(id);
-            for (int j = 0; j < playlists.count(); j++)
-                deletedIds.append(id + '_' + QString::number(j));
+    foreach(QTreeWidgetItem *child, m_ui.treeWidget->selectedItems()) {
+        if (child->data(0, statusRole).toInt() < 10) {
+            deletedIds.append(child->data(0, idRole).toString());
             delete child;
-        } else ix++;
-        child = m_ui.treeWidget->topLevelItem(ix);
+        }
     }
     kDebug() << "// Clips to delete: " << deletedIds;
 
@@ -493,34 +501,38 @@ void DocumentChecker::slotDeleteSelected()
         QDomElement mlt = m_doc.firstChildElement("mlt");
         QDomElement kdenlivedoc = mlt.firstChildElement("kdenlivedoc");
 
-        for (int i = 0; i < infoproducers.count(); i++) {
+        for (int i = 0, j = 0; i < infoproducers.count() && j < deletedIds.count(); i++) {
             e = infoproducers.item(i).toElement();
             if (deletedIds.contains(e.attribute("id"))) {
                 // Remove clip
                 kdenlivedoc.removeChild(e);
-                break;
+                i--;
+                j++;
             }
         }
 
         for (int i = 0; i < producers.count(); i++) {
             e = producers.item(i).toElement();
-            if (deletedIds.contains(e.attribute("id"))) {
+            if (deletedIds.contains(e.attribute("id").section('_', 0, 0)) || deletedIds.contains(e.attribute("id").section(':', 1, 1).section('_', 0, 0))) {
                 // Remove clip
                 mlt.removeChild(e);
-                break;
+                i--;
             }
         }
 
         for (int i = 0; i < playlists.count(); i++) {
             QDomNodeList entries = playlists.at(i).toElement().elementsByTagName("entry");
-            for (int j = 0; j < playlists.count(); j++) {
+            for (int j = 0; j < entries.count(); j++) {
                 e = entries.item(j).toElement();
-                if (deletedIds.contains(e.attribute("producer"))) {
+                if (deletedIds.contains(e.attribute("producer").section('_', 0, 0)) || deletedIds.contains(e.attribute("producer").section(':', 1, 1).section('_', 0, 0))) {
                     // Replace clip with blank
+                    while (e.childNodes().count() > 0)
+                        e.removeChild(e.firstChild());
                     e.setTagName("blank");
                     e.removeAttribute("producer");
                     int length = e.attribute("out").toInt() - e.attribute("in").toInt();
                     e.setAttribute("length", length);
+                    j--;
                 }
             }
         }