]> git.sesse.net Git - kdenlive/commitdiff
Fix recently introduced project corruption with special characters in clip name ...
authorJean-Baptiste Mardelle <jb@kdenlive.org>
Wed, 6 Jul 2011 01:42:39 +0000 (01:42 +0000)
committerJean-Baptiste Mardelle <jb@kdenlive.org>
Wed, 6 Jul 2011 01:42:39 +0000 (01:42 +0000)
svn path=/trunk/kdenlive/; revision=5767

src/docclipbase.cpp
src/trackview.cpp
src/trackview.h

index 6004a1300d25e9d810501aeb785aac3c7880f473..527f9399bc9d3d66bc766a34fa1d4556d7b74ab8 100644 (file)
@@ -619,7 +619,7 @@ Mlt::Producer *DocClipBase::producer(int track)
 Mlt::Producer *DocClipBase::cloneProducer(Mlt::Producer *source)
 {
     Mlt::Producer *result = NULL;
-    QString url = source->get("resource");
+    QString url = QString::fromUtf8(source->get("resource"));
     if (KIO::NetAccess::exists(KUrl(url), KIO::NetAccess::SourceSide, 0)) {
         char *tmp = qstrdup(url.toUtf8().constData());
         result = new Mlt::Producer(*source->profile(), tmp);
@@ -637,6 +637,7 @@ Mlt::Producer *DocClipBase::cloneProducer(Mlt::Producer *source)
             result->set("bgcolour", "0xff0000ff");
             result->set("pad", "10");
         }
+        return result;
     }
     Mlt::Properties props(result->get_properties());
     Mlt::Properties src_props(source->get_properties());
index ab83ac6e39ebd0c7fa518bd5901431674723ec84..41ea52094802dfffa506b171a54323781aeadc99 100644 (file)
@@ -189,6 +189,7 @@ void TrackView::parseDocument(QDomDocument doc)
 {
     //int cursorPos = 0;
     m_documentErrors.clear();
+    m_replacementProducerIds.clear();
 
     //kDebug() << "//// DOCUMENT: " << doc.toString();
     /*QDomNode props = doc.elementsByTagName("properties").item(0);
@@ -595,6 +596,7 @@ int TrackView::slotAddProjectTrack(int ix, QDomElement xml, bool locked, QDomNod
 {
     // parse track
     int position = 0;
+    QMap <QString, QString> producerReplacementIds;
     QDomNodeList children = xml.childNodes();
     for (int nodeindex = 0; nodeindex < children.count(); nodeindex++) {
         QDomNode n = children.item(nodeindex);
@@ -612,6 +614,11 @@ int TrackView::slotAddProjectTrack(int ix, QDomElement xml, bool locked, QDomNod
                 continue;
             }
             QString idString = elem.attribute("producer");
+            if (producerReplacementIds.contains(idString)) {
+                // replace id
+                elem.setAttribute("producer", producerReplacementIds.value(idString));
+                idString = elem.attribute("producer");
+            }
             QString id = idString;
             double speed = 1.0;
             int strobe = 1;
@@ -629,8 +636,55 @@ int TrackView::slotAddProjectTrack(int ix, QDomElement xml, bool locked, QDomNod
                 kWarning() << "CANNOT INSERT CLIP " << id;
                 QString docRoot = m_doc->toXml().documentElement().attribute("root");
                 if (!docRoot.endsWith('/')) docRoot.append('/');
-                clip = getMissingProducer(id);
-                if (!clip) {
+                clip = getMissingProducer(idString);
+                if (clip) {
+                    // We found the original producer in Kdenlive's producers
+                    // Found correct producer
+                    m_documentErrors.append(i18n("Replaced wrong clip producer %1 with %2", id, clip->getId()) + '\n');
+                    QString prodId = clip->getId();
+                    if (clip->clipType() == PLAYLIST || clip->clipType() == AV || clip->clipType() == AUDIO) {
+                        // We need producer for the track
+                        prodId.append("_" + QString::number(ix));
+                    }
+                    elem.setAttribute("producer", prodId);
+                    producerReplacementIds.insert(idString, prodId);
+                    // now adjust the mlt producer
+                    bool found = false;
+                    for (int i = 0; i < producers.count(); i++) {
+                        QDomElement prod = producers.at(i).toElement();
+                        if (prod.attribute("id") == prodId) {
+                            // ok, producer already exists
+                            found = true;
+                            break;
+                        }
+                    }
+                    if (!found) {
+                        for (int i = 0; i < producers.count(); i++) {
+                            QDomElement prod = producers.at(i).toElement();
+                            if (prod.attribute("id") == idString) {
+                                prod.setAttribute("id", prodId);
+                                m_replacementProducerIds.insert(idString, prodId);
+                                found = true;
+                                break;
+                            }
+                        }
+                    }
+                    if (!found) {
+                        // We didn't find the producer for this track, find producer for another track and duplicate
+                        for (int i = 0; i < producers.count(); i++) {
+                            QDomElement prod = producers.at(i).toElement();
+                            QString mltProdId = prod.attribute("id");
+                            if (mltProdId == prodId || mltProdId.startsWith(prodId + "_")) {
+                                // Found parent producer, clone it
+                                QDomElement clone = prod.cloneNode().toElement();
+                                clone.setAttribute("id", prodId);
+                                m_doc->toXml().documentElement().insertBefore(clone, xml);
+                                break;
+                            }
+                        }
+                    }                    
+                }
+                else {
                     // We cannot find the producer, something is really wrong, add
                     // placeholder color clip
                     QDomDocument doc;
@@ -667,11 +721,6 @@ int TrackView::slotAddProjectTrack(int ix, QDomElement xml, bool locked, QDomNod
                         elem.setTagName("blank");
                         m_documentErrors.append(i18n("Broken clip producer %1, removed from project", id) + '\n');
                     }
-
-                } else {
-                    // Found correct producer
-                    m_documentErrors.append(i18n("Replaced wrong clip producer %1 with %2", id, clip->getId()) + '\n');
-                    elem.setAttribute("producer", clip->getId());
                 }
                 m_doc->setModified(true);
             }
@@ -936,6 +985,26 @@ DocClipBase *TrackView::getMissingProducer(const QString id) const
             break;
         }
     }
+    if (missingXml == QDomElement()) {
+        // Check if producer id was replaced in another track
+        if (m_replacementProducerIds.contains(id)) {
+            QString newId = m_replacementProducerIds.value(id);
+            slowmotionClip = false;
+            for (int i = 0; i < maxprod; i++) {
+                QDomNode m = prods.at(i);
+                QString prodId = m.toElement().attribute("id");
+                if (prodId.startsWith("slowmotion")) {
+                    slowmotionClip = true;
+                    prodId = prodId.section(':', 1, 1);
+                }
+                prodId = prodId.section('_', 0, 0);
+                if (prodId == id) {
+                    missingXml =  m.toElement();
+                    break;
+                }
+            }       
+        }
+    }
     if (missingXml == QDomElement()) return NULL;
     QString resource = EffectsList::property(missingXml, "resource");
     QString service = EffectsList::property(missingXml, "mlt_service");
index 24fcabbfe7ea4a90dc9d08d02d227e35ddb27e93..5dcbd7e997385ac44266a879be77e27aa87d1e19 100644 (file)
@@ -94,6 +94,8 @@ private:
     int m_projectTracks;
     QString m_editMode;
     CustomTrackScene *m_scene;
+    /** @brief A list of producer ids to be replaced when opening a corrupted document*/
+    QMap <QString, QString> m_replacementProducerIds;
 
     KdenliveDoc *m_doc;
     int m_verticalZoom;