From: Jean-Baptiste Mardelle Date: Wed, 6 Jul 2011 01:42:39 +0000 (+0000) Subject: Fix recently introduced project corruption with special characters in clip name ... X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=4ef6fc168cffdc049504f22c4f9ca48db14d299d;p=kdenlive Fix recently introduced project corruption with special characters in clip name / path, and fix project recovery with broken producers svn path=/trunk/kdenlive/; revision=5767 --- diff --git a/src/docclipbase.cpp b/src/docclipbase.cpp index 6004a130..527f9399 100644 --- a/src/docclipbase.cpp +++ b/src/docclipbase.cpp @@ -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()); diff --git a/src/trackview.cpp b/src/trackview.cpp index ab83ac6e..41ea5209 100644 --- a/src/trackview.cpp +++ b/src/trackview.cpp @@ -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 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"); diff --git a/src/trackview.h b/src/trackview.h index 24fcabbf..5dcbd7e9 100644 --- a/src/trackview.h +++ b/src/trackview.h @@ -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 m_replacementProducerIds; KdenliveDoc *m_doc; int m_verticalZoom;