]> git.sesse.net Git - kdenlive/blobdiff - src/documentchecker.cpp
improve feedback for missing proxy clips on project opening
[kdenlive] / src / documentchecker.cpp
index a39f1037ff61adc06b33fad13d320468cf97bb53..153cceaaa5cb4fe15324ae8030bf08b022bd0b80 100644 (file)
 
 #include "documentchecker.h"
 #include "kthumb.h"
+#include "docclipbase.h"
+#include "titlewidget.h"
 #include "definitions.h"
+#include "kdenlivesettings.h"
 
 #include <KDebug>
 #include <KGlobalSettings>
@@ -43,44 +46,124 @@ const int hashRole = Qt::UserRole;
 const int sizeRole = Qt::UserRole + 1;
 const int idRole = Qt::UserRole + 2;
 const int statusRole = Qt::UserRole + 3;
+const int typeRole = Qt::UserRole + 4;
+const int typeOriginalResource = Qt::UserRole + 5;
 
 const int CLIPMISSING = 0;
 const int CLIPOK = 1;
 const int CLIPPLACEHOLDER = 2;
+const int CLIPWRONGDURATION = 3;
+const int PROXYMISSING = 4;
 
-DocumentChecker::DocumentChecker(QDomDocument doc, QWidget * parent) :
-        QDialog(parent), m_doc(doc)
+const int LUMAMISSING = 10;
+const int LUMAOK = 11;
+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)
 {
-    setFont(KGlobalSettings::toolBarFont());
-    m_view.setupUi(this);
 
-    QDomNodeList producers = m_doc.elementsByTagName("producer");
-    QDomNodeList infoproducers = m_doc.elementsByTagName("kdenlive_producer");
+}
 
+
+bool DocumentChecker::hasErrorInClips()
+{
     int clipType;
     QDomElement e;
-    QString id;
     QString resource;
+    QDomNodeList documentProducers = m_doc.elementsByTagName("producer");
+    QList <QDomElement> wrongDurationClips;
     QList <QDomElement> missingClips;
-    for (int i = 0; i < infoproducers.count(); i++) {
-        e = infoproducers.item(i).toElement();
+    QList <QDomElement> missingProxies;
+    for (int i = 0; i < m_info.count(); i++) {
+        e = m_info.item(i).toElement();
         clipType = e.attribute("type").toInt();
-        if (clipType == TEXT) continue;
-        id = e.attribute("id");
+        if (clipType == COLOR) continue;
+        if (clipType != TEXT && clipType != IMAGE) {
+            QString id = e.attribute("id");
+            int duration = e.attribute("duration").toInt();
+            // Check that the duration is in sync between Kdenlive's info and MLT's playlist
+            for (int j = 0; j < documentProducers.count(); j++) {
+                QDomElement mltProd = documentProducers.at(j).toElement();
+                QString prodId = mltProd.attribute("id");
+                // Don't check slowmotion clips for now... (TODO?)
+                if (prodId.startsWith("slowmotion")) continue;
+                if (prodId.contains("_")) prodId = prodId.section("_", 0, 0);
+                if (prodId != id) continue;
+                int mltDuration = mltProd.attribute("out").toInt() + 1;
+                if (mltDuration != duration && !e.hasAttribute("_mismatch")) {
+                    // Duration mismatch
+                    e.setAttribute("_mismatch", mltDuration);
+                    if (!wrongDurationClips.contains(e)) wrongDurationClips.append(e);
+                    kDebug() << "WRONG DURTAION: "<<id<<", TYPE: "<<clipType;
+                }
+            }
+        }
+        
+        if (clipType == TEXT) {
+            //TODO: Check is clip template is missing (xmltemplate) or hash changed
+            QStringList images = TitleWidget::extractImageList(e.attribute("xmldata"));
+            QStringList fonts = TitleWidget::extractFontList(e.attribute("xmldata"));
+            checkMissingImages(missingClips, images, fonts, e.attribute("id"), e.attribute("name"));
+            continue;
+        }
         resource = e.attribute("resource");
+        if (e.hasAttribute("proxy")) {
+            QString proxyresource = e.attribute("proxy");
+            if (!proxyresource.isEmpty() && proxyresource != "-" && !KIO::NetAccess::exists(KUrl(proxyresource), KIO::NetAccess::SourceSide, 0)) {
+                // Missing clip found
+                missingProxies.append(e);
+            }
+        }
         if (clipType == SLIDESHOW) resource = KUrl(resource).directory();
         if (!KIO::NetAccess::exists(KUrl(resource), KIO::NetAccess::SourceSide, 0)) {
             // Missing clip found
             missingClips.append(e);
+        } else {
+            // Check if the clip has changed
+            if (clipType != SLIDESHOW && e.hasAttribute("file_hash")) {
+                if (e.attribute("file_hash") != DocClipBase::getHash(e.attribute("resource")))
+                    e.removeAttribute("file_hash");
+            }
+        }
+    }
+
+    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()) {
+            if (!luma.startsWith('/')) luma.prepend(root);
+            if (!QFile::exists(luma) && !missingLumas.contains(luma)) {
+                missingLumas.append(luma);
+            }
         }
     }
 
-    if (missingClips.isEmpty()) QTimer::singleShot(0, this, SLOT(accept()));
-    m_view.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
+    if (missingClips.isEmpty() && missingLumas.isEmpty() && wrongDurationClips.isEmpty() && missingProxies.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();
         QString clipType;
-        switch (e.attribute("type").toInt()) {
+        int t = e.attribute("type").toInt();
+        switch (t) {
         case AV:
             clipType = i18n("Video clip");
             break;
@@ -99,44 +182,248 @@ DocumentChecker::DocumentChecker(QDomDocument doc, QWidget * parent) :
         case SLIDESHOW:
             clipType = i18n("Slideshow clip");
             break;
+        case TITLE_IMAGE_ELEMENT:
+            clipType = i18n("Title Image");
+            break;
+        case TITLE_FONT_ELEMENT:
+            clipType = i18n("Title Font");
+            break;
         default:
             clipType = i18n("Video clip");
         }
-        QTreeWidgetItem *item = new QTreeWidgetItem(m_view.treeWidget, QStringList() << clipType << e.attribute("resource"));
-        item->setIcon(0, KIcon("dialog-close"));
+        QTreeWidgetItem *item = new QTreeWidgetItem(m_ui.treeWidget, QStringList() << clipType);
+        if (t == TITLE_IMAGE_ELEMENT) {
+            item->setIcon(0, KIcon("dialog-warning"));
+            item->setToolTip(1, e.attribute("name"));
+            item->setText(1, e.attribute("resource"));
+            item->setData(0, statusRole, CLIPPLACEHOLDER);
+            item->setData(0, typeOriginalResource, e.attribute("resource"));
+        } else if (t == TITLE_FONT_ELEMENT) {
+            item->setIcon(0, KIcon("dialog-warning"));
+            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->setData(0, statusRole, CLIPPLACEHOLDER);
+        } else {
+            item->setIcon(0, KIcon("dialog-close"));
+            item->setText(1, e.attribute("resource"));
+            item->setData(0, hashRole, e.attribute("file_hash"));
+            item->setData(0, sizeRole, e.attribute("file_size"));
+            item->setData(0, statusRole, CLIPMISSING);
+        }
+        item->setData(0, typeRole, t);
+        item->setData(0, idRole, e.attribute("id"));
+        item->setToolTip(0, i18n("Missing item"));
+    }
+
+    if (missingClips.count() > 0) {
+        if (wrongDurationClips.count() > 0) {
+            m_ui.infoLabel->setText(i18n("The project file contains missing clips or files and clip duration mismatch"));
+        }
+        else {
+            m_ui.infoLabel->setText(i18n("The project file contains missing clips or files"));
+        }
+    }
+    else if (wrongDurationClips.count() > 0) {
+        m_ui.infoLabel->setText(i18n("The project file contains clips with duration mismatch"));
+    }
+    if (missingProxies.count() > 0) {
+        if (!m_ui.infoLabel->text().isEmpty()) m_ui.infoLabel->setText(m_ui.infoLabel->text() + ". ");
+        m_ui.infoLabel->setText(m_ui.infoLabel->text() + i18n("Missing proxies will be recreated after opening."));
+    }
+
+    m_ui.removeSelected->setEnabled(!missingClips.isEmpty());
+    m_ui.recursiveSearch->setEnabled(!missingClips.isEmpty());
+    m_ui.usePlaceholders->setEnabled(!missingClips.isEmpty());
+    m_ui.fixDuration->setEnabled(!wrongDurationClips.isEmpty());
+        
+    for (int i = 0; i < wrongDurationClips.count(); i++) {
+        e = wrongDurationClips.at(i).toElement();
+        QString clipType;
+        int t = e.attribute("type").toInt();
+        switch (t) {
+        case AV:
+            clipType = i18n("Video clip");
+            break;
+        case VIDEO:
+            clipType = i18n("Mute video clip");
+            break;
+        case AUDIO:
+            clipType = i18n("Audio clip");
+            break;
+        case PLAYLIST:
+            clipType = i18n("Playlist clip");
+            break;
+        case IMAGE:
+            clipType = i18n("Image clip");
+            break;
+        case SLIDESHOW:
+            clipType = i18n("Slideshow clip");
+            break;
+        default:
+            clipType = i18n("Video clip");
+        }
+        QTreeWidgetItem *item = new QTreeWidgetItem(m_ui.treeWidget, QStringList() << clipType);
+        item->setIcon(0, KIcon("timeadjust"));
+        item->setText(1, e.attribute("resource"));
         item->setData(0, hashRole, e.attribute("file_hash"));
-        item->setData(0, sizeRole, e.attribute("file_size"));
+        item->setData(0, sizeRole, e.attribute("_mismatch"));
+        e.removeAttribute("_mismatch");
+        item->setData(0, statusRole, CLIPWRONGDURATION);
+        item->setData(0, typeRole, t);
         item->setData(0, idRole, e.attribute("id"));
-        item->setData(0, statusRole, CLIPMISSING);
+        item->setToolTip(0, i18n("Duration mismatch"));
     }
-    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)));
+
+    if (missingProxies.count() > 0) {
+        QTreeWidgetItem *item = new QTreeWidgetItem(m_ui.treeWidget, QStringList() << i18n("Proxy clip"));
+        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->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()));
+    connect(m_ui.removeSelected, SIGNAL(pressed()), this, SLOT(slotDeleteSelected()));
+    connect(m_ui.fixDuration, SIGNAL(pressed()), this, SLOT(slotFixDuration()));
+    connect(m_ui.treeWidget, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)), this, SLOT(slotEditItem(QTreeWidgetItem *, int)));
+    connect(m_ui.treeWidget, SIGNAL(itemSelectionChanged()), this, SLOT(slotCheckButtons()));
     //adjustSize();
+    if (m_ui.treeWidget->topLevelItem(0)) m_ui.treeWidget->setCurrentItem(m_ui.treeWidget->topLevelItem(0));
+    checkStatus();
+    int acceptMissing = m_dialog->exec();
+    if (acceptMissing == QDialog::Accepted) acceptDialog();
+    return (acceptMissing != QDialog::Accepted);
+}
+
+DocumentChecker::~DocumentChecker()
+{
+    if (m_dialog) delete m_dialog;
+}
+
+
+QString DocumentChecker::getProperty(QDomElement effect, const QString &name)
+{
+    QDomNodeList params = effect.elementsByTagName("property");
+    for (int i = 0; i < params.count(); i++) {
+        QDomElement e = params.item(i).toElement();
+        if (e.attribute("name") == name) {
+            return e.firstChild().nodeValue();
+        }
+    }
+    return QString();
 }
 
-DocumentChecker::~DocumentChecker() {}
+void DocumentChecker::setProperty(QDomElement effect, const QString &name, const QString value)
+{
+    QDomNodeList params = effect.elementsByTagName("property");
+    for (int i = 0; i < params.count(); i++) {
+        QDomElement e = params.item(i).toElement();
+        if (e.attribute("name") == name) {
+            e.firstChild().setNodeValue(value);
+        }
+    }
+}
 
 void DocumentChecker::slotSearchClips()
 {
     QString newpath = KFileDialog::getExistingDirectory(KUrl("kfiledialog:///clipfolder"), kapp->activeWindow(), i18n("Clips folder"));
     if (newpath.isEmpty()) return;
     int ix = 0;
-    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());
-        if (!clipPath.isEmpty()) {
-            child->setText(1, clipPath);
-            child->setIcon(0, KIcon("dialog-ok"));
-            child->setData(0, statusRole, CLIPOK);
+    bool fixed = false;
+    m_ui.recursiveSearch->setEnabled(false);
+    QTreeWidgetItem *child = m_ui.treeWidget->topLevelItem(ix);
+    while (child) {
+        if (child->data(0, statusRole).toInt() == CLIPMISSING) {
+            QString clipPath = searchFileRecursively(QDir(newpath), child->data(0, sizeRole).toString(), child->data(0, hashRole).toString());
+            if (!clipPath.isEmpty()) {
+                fixed = true;
+                child->setText(1, clipPath);
+                child->setIcon(0, KIcon("dialog-ok"));
+                child->setData(0, statusRole, CLIPOK);
+            }
+        } else if (child->data(0, statusRole).toInt() == LUMAMISSING) {
+            QString fileName = searchLuma(child->data(0, idRole).toString());
+            if (!fileName.isEmpty()) {
+                fixed = true;
+                child->setText(1, fileName);
+                child->setIcon(0, KIcon("dialog-ok"));
+                child->setData(0, statusRole, LUMAOK);
+            }
         }
         ix++;
-        child = m_view.treeWidget->topLevelItem(ix);
+        child = m_ui.treeWidget->topLevelItem(ix);
+    }
+    m_ui.recursiveSearch->setEnabled(true);
+    if (fixed) {
+        // original doc was modified
+        QDomNode infoXmlNode = m_doc.elementsByTagName("kdenlivedoc").at(0);
+        QDomElement infoXml = infoXmlNode.toElement();
+        infoXml.setAttribute("modified", "1");
     }
     checkStatus();
 }
 
+
+QString DocumentChecker::searchLuma(QString file) const
+{
+    KUrl searchPath(KdenliveSettings::mltpath());
+    if (file.contains("PAL"))
+        searchPath.cd("../lumas/PAL");
+    else
+        searchPath.cd("../lumas/NTSC");
+    QString result = searchPath.path(KUrl::AddTrailingSlash) + KUrl(file).fileName();
+    if (QFile::exists(result))
+        return result;
+    return QString();
+}
+
+
 QString DocumentChecker::searchFileRecursively(const QDir &dir, const QString &matchSize, const QString &matchHash) const
 {
     QString foundFileName;
@@ -145,13 +432,13 @@ QString DocumentChecker::searchFileRecursively(const QDir &dir, const QString &m
     QStringList filesAndDirs = dir.entryList(QDir::Files | QDir::Readable);
     for (int i = 0; i < filesAndDirs.size() && foundFileName.isEmpty(); i++) {
         QFile file(dir.absoluteFilePath(filesAndDirs.at(i)));
-        if (file.open(QIODevice::ReadOnly)) {
-            if (QString::number(file.size()) == matchSize) {
+        if (QString::number(file.size()) == matchSize) {
+            if (file.open(QIODevice::ReadOnly)) {
                 /*
                 * 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());
@@ -163,7 +450,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++) {
@@ -176,44 +463,107 @@ QString DocumentChecker::searchFileRecursively(const QDir &dir, const QString &m
 
 void DocumentChecker::slotEditItem(QTreeWidgetItem *item, int)
 {
-    KUrl url = KUrlRequesterDialog::getUrl(item->text(1), this, i18n("Enter new location for file"));
+    int t = item->data(0, typeRole).toInt();
+    if (t == TITLE_FONT_ELEMENT) return;
+    //|| t == TITLE_IMAGE_ELEMENT) {
+
+    KUrl url = KUrlRequesterDialog::getUrl(item->text(1), m_dialog, i18n("Enter new location for file"));
     if (url.isEmpty()) return;
     item->setText(1, url.path());
     if (KIO::NetAccess::exists(url, KIO::NetAccess::SourceSide, 0)) {
         item->setIcon(0, KIcon("dialog-ok"));
-        item->setData(0, statusRole, CLIPOK);
+        int id = item->data(0, statusRole).toInt();
+        if (id < 10) item->setData(0, statusRole, CLIPOK);
+        else item->setData(0, statusRole, LUMAOK);
+        checkStatus();
+    } else {
+        item->setIcon(0, KIcon("dialog-close"));
+        int id = item->data(0, statusRole).toInt();
+        if (id < 10) item->setData(0, statusRole, CLIPMISSING);
+        else item->setData(0, statusRole, LUMAMISSING);
         checkStatus();
     }
 }
 
-// virtual
-void DocumentChecker::accept()
+
+void DocumentChecker::acceptDialog()
 {
-    QDomElement e;
+    QDomElement e, property;
     QDomNodeList producers = m_doc.elementsByTagName("producer");
     QDomNodeList infoproducers = m_doc.elementsByTagName("kdenlive_producer");
+    QDomNodeList properties;
     int ix = 0;
-    QTreeWidgetItem *child = m_view.treeWidget->topLevelItem(ix);
+
+    // 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();
         if (child->data(0, statusRole).toInt() == CLIPOK) {
             QString id = child->data(0, idRole).toString();
-            for (int i = 0; i < infoproducers.count(); i++) {
-                e = infoproducers.item(i).toElement();
-                if (e.attribute("id") == id) {
-                    // Fix clip
-                    e.setAttribute("resource", child->text(1));
-                    break;
+            if (t == TITLE_IMAGE_ELEMENT) {
+                // edit images embedded in titles
+                for (int i = 0; i < infoproducers.count(); i++) {
+                    e = infoproducers.item(i).toElement();
+                    if (e.attribute("id") == id) {
+                        // Fix clip
+                        QString xml = e.attribute("xmldata");
+                        xml.replace(child->data(0, typeOriginalResource).toString(), child->text(1));
+                        e.setAttribute("xmldata", xml);
+                        break;
+                    }
                 }
-            }
-            for (int i = 0; i < producers.count(); i++) {
-                e = producers.item(i).toElement();
-                if (e.attribute("id") == id) {
-                    // Fix clip
-                    e.setAttribute("resource", child->text(1));
-                    break;
+                for (int i = 0; i < producers.count(); i++) {
+                    e = producers.item(i).toElement();
+                    if (e.attribute("id").section('_', 0, 0) == id) {
+                        // Fix clip
+                        properties = e.childNodes();
+                        for (int j = 0; j < properties.count(); ++j) {
+                            property = properties.item(j).toElement();
+                            if (property.attribute("name") == "xmldata") {
+                                QString xml = property.firstChild().nodeValue();
+                                xml.replace(child->data(0, typeOriginalResource).toString(), child->text(1));
+                                property.firstChild().setNodeValue(xml);
+                                break;
+                            }
+                        }
+                    }
+                }
+            } else {
+                // edit clip url
+                for (int i = 0; i < infoproducers.count(); i++) {
+                    e = infoproducers.item(i).toElement();
+                    if (e.attribute("id") == id) {
+                        // Fix clip
+                        e.setAttribute("resource", child->text(1));
+                        e.setAttribute("name", KUrl(child->text(1)).fileName());
+                        break;
+                    }
+                }
+                for (int i = 0; i < producers.count(); i++) {
+                    e = producers.item(i).toElement();
+                    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") {
+                                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;
+                            }
+                        }
+                    }
                 }
             }
-        } else if (child->data(0, statusRole).toInt() == CLIPPLACEHOLDER) {
+        } else if (child->data(0, statusRole).toInt() == CLIPPLACEHOLDER && t != TITLE_FONT_ELEMENT && t != TITLE_IMAGE_ELEMENT) {
             QString id = child->data(0, idRole).toString();
             for (int i = 0; i < infoproducers.count(); i++) {
                 e = infoproducers.item(i).toElement();
@@ -223,25 +573,71 @@ void DocumentChecker::accept()
                     break;
                 }
             }
+        } 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));
+                    kDebug() << "replace with; " << child->text(1);
+                }
+            }
+        } else if (child->data(0, statusRole).toInt() == LUMAMISSING) {
+            for (int i = 0; i < trans.count(); i++) {
+                QString luma = getProperty(trans.at(i).toElement(), "luma");
+                if (!luma.isEmpty() && luma == child->data(0, idRole).toString()) {
+                    setProperty(trans.at(i).toElement(), "luma", QString());
+                }
+            }
         }
         ix++;
-        child = m_view.treeWidget->topLevelItem(ix);
+        child = m_ui.treeWidget->topLevelItem(ix);
     }
-    QDialog::accept();
+    //QDialog::accept();
 }
 
 void DocumentChecker::slotPlaceholders()
 {
     int ix = 0;
-    QTreeWidgetItem *child = m_view.treeWidget->topLevelItem(ix);
+    QTreeWidgetItem *child = m_ui.treeWidget->topLevelItem(ix);
     while (child) {
         if (child->data(0, statusRole).toInt() == CLIPMISSING) {
             child->setData(0, statusRole, CLIPPLACEHOLDER);
             child->setIcon(0, KIcon("dialog-ok"));
+        } else if (child->data(0, statusRole).toInt() == LUMAMISSING) {
+            child->setData(0, statusRole, LUMAPLACEHOLDER);
+            child->setIcon(0, KIcon("dialog-ok"));
+        }
+        ix++;
+        child = m_ui.treeWidget->topLevelItem(ix);
+    }
+    checkStatus();
+}
+
+void DocumentChecker::slotFixDuration()
+{
+    int ix = 0;
+    QTreeWidgetItem *child = m_ui.treeWidget->topLevelItem(ix);
+    while (child) {
+        if (child->data(0, statusRole).toInt() == CLIPWRONGDURATION) {
+            child->setData(0, statusRole, CLIPOK);
+            child->setIcon(0, KIcon("dialog-ok"));
+            QString id = child->data(0, idRole).toString();
+            for (int i = 0; i < m_info.count(); i++) {
+                QDomElement e = m_info.at(i).toElement();
+                if (e.attribute("id") == id) {
+                    e.setAttribute("duration", child->data(0, sizeRole).toString());
+                    break;
+                }
+            }
         }
         ix++;
-        child = m_view.treeWidget->topLevelItem(ix);
+        child = m_ui.treeWidget->topLevelItem(ix);
     }
+    QDomNode infoXmlNode = m_doc.elementsByTagName("kdenlivedoc").at(0);
+    QDomElement infoXml = infoXmlNode.toElement();
+    infoXml.setAttribute("modified", "1");
+    m_ui.fixDuration->setEnabled(false);
     checkStatus();
 }
 
@@ -250,36 +646,32 @@ void DocumentChecker::checkStatus()
 {
     bool status = true;
     int ix = 0;
-    QTreeWidgetItem *child = m_view.treeWidget->topLevelItem(ix);
+    QTreeWidgetItem *child = m_ui.treeWidget->topLevelItem(ix);
     while (child) {
-        if (child->data(0, statusRole).toInt() == CLIPMISSING) {
+        int status = child->data(0, statusRole).toInt();
+        if (status == CLIPMISSING || status == LUMAMISSING || status == CLIPWRONGDURATION) {
             status = false;
             break;
         }
         ix++;
-        child = m_view.treeWidget->topLevelItem(ix);
+        child = m_ui.treeWidget->topLevelItem(ix);
     }
-    m_view.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(status);
+    m_ui.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;
+    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_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));
+    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_view.treeWidget->topLevelItem(ix);
+        }
     }
     kDebug() << "// Clips to delete: " << deletedIds;
 
@@ -288,44 +680,93 @@ void DocumentChecker::slotDeleteSelected()
         QDomNodeList producers = m_doc.elementsByTagName("producer");
         QDomNodeList infoproducers = m_doc.elementsByTagName("kdenlive_producer");
 
-        QDomElement westley = m_doc.firstChildElement("westley");
-        QDomElement kdenlivedoc = westley.firstChildElement("kdenlivedoc");
+        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
-                westley.removeChild(e);
-                break;
+                mlt.removeChild(e);
+                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--;
                 }
             }
         }
+        QDomNode infoXmlNode = m_doc.elementsByTagName("kdenlivedoc").at(0);
+        QDomElement infoXml = infoXmlNode.toElement();
+        infoXml.setAttribute("modified", "1");
         checkStatus();
     }
 }
 
+void DocumentChecker::checkMissingImages(QList <QDomElement>&missingClips, QStringList images, QStringList fonts, QString id, QString baseClip)
+{
+    QDomDocument doc;
+    foreach(const QString &img, images) {
+        if (!KIO::NetAccess::exists(KUrl(img), KIO::NetAccess::SourceSide, 0)) {
+            QDomElement e = doc.createElement("missingclip");
+            e.setAttribute("type", TITLE_IMAGE_ELEMENT);
+            e.setAttribute("resource", img);
+            e.setAttribute("id", id);
+            e.setAttribute("name", baseClip);
+            missingClips.append(e);
+        }
+    }
+    kDebug() << "/ / / CHK FONTS: " << fonts;
+    foreach(const QString &fontelement, fonts) {
+        QFont f(fontelement);
+        kDebug() << "/ / / CHK FONTS: " << fontelement << " = " << QFontInfo(f).family();
+        if (fontelement != QFontInfo(f).family()) {
+            QDomElement e = doc.createElement("missingclip");
+            e.setAttribute("type", TITLE_FONT_ELEMENT);
+            e.setAttribute("resource", fontelement);
+            e.setAttribute("id", id);
+            e.setAttribute("name", baseClip);
+            missingClips.append(e);
+        }
+    }
+}
+
+
+void DocumentChecker::slotCheckButtons()
+{
+    if (m_ui.treeWidget->currentItem()) {
+        QTreeWidgetItem *item = m_ui.treeWidget->currentItem();
+        int t = item->data(0, typeRole).toInt();
+        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);
+    }
+
+}
+
 #include "documentchecker.moc"