From 53bd5bb0ca9e46a9798d0b1c90852a394e9217e8 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Mardelle Date: Mon, 4 Feb 2013 16:14:36 +0100 Subject: [PATCH] Fix some clips metadata corrupting project file: http://kdenlive.org/mantis/view.php?id=2976 --- src/docclipbase.cpp | 19 +++++++++++++++++-- src/kdenlivedoc.cpp | 10 +++++++--- src/renderer.cpp | 2 +- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/docclipbase.cpp b/src/docclipbase.cpp index 132dde9b..85730560 100644 --- a/src/docclipbase.cpp +++ b/src/docclipbase.cpp @@ -64,9 +64,16 @@ DocClipBase::DocClipBase(ClipManager *clipManager, QDomElement xml, const QStrin for (int i = 0; i < attributes.count(); i++) { QString name = attributes.item(i).nodeName(); if (name.startsWith("meta.attr.")) { - m_metadata.insert(name.section('.', 2, 3), attributes.item(i).nodeValue()); + m_metadata.insert(name.section('.', 2), attributes.item(i).nodeValue()); } else m_properties.insert(name, attributes.item(i).nodeValue()); } + QDomNodeList metas = xml.elementsByTagName("metaproperty"); + for (int i = 0; i < metas.count(); i++) { + QDomElement e = metas.item(i).toElement(); + if (!e.isNull()) { + m_metadata.insert(e.attribute("name").section('.', 2), e.firstChild().nodeValue()); + } + } if (xml.hasAttribute("cutzones")) { QStringList cuts = xml.attribute("cutzones").split(';', QString::SkipEmptyParts); @@ -255,10 +262,18 @@ QDomElement DocClipBase::toXML(bool hideTemporaryProperties) const if (hideTemporaryProperties && i.key().startsWith('_')) continue; if (!i.value().isEmpty()) clip.setAttribute(i.key(), i.value()); } + QMapIterator j(m_metadata); + // Metadata name can have special chars so we cannot pass it as simple attribute while (j.hasNext()) { j.next(); - if (!j.value().isEmpty()) clip.setAttribute("meta.attr." + j.key(), j.value()); + if (!j.value().isEmpty()) { + QDomElement property = doc.createElement("metaproperty"); + property.setAttribute("name", "meta.attr." + j.key()); + QDomText value = doc.createTextNode(j.value()); + property.appendChild(value); + clip.appendChild(property); + } } doc.appendChild(clip); if (!m_cutZones.isEmpty()) { diff --git a/src/kdenlivedoc.cpp b/src/kdenlivedoc.cpp index 269cfae4..c1804867 100644 --- a/src/kdenlivedoc.cpp +++ b/src/kdenlivedoc.cpp @@ -143,14 +143,16 @@ KdenliveDoc::KdenliveDoc(const KUrl &url, const KUrl &projectFolder, QUndoGroup else { QFile file(tmpFile); QString errorMsg; + int line; + int col; QDomImplementation::setInvalidDataPolicy(QDomImplementation::DropInvalidChars); - success = m_document.setContent(&file, false, &errorMsg); + success = m_document.setContent(&file, false, &errorMsg, &line, &col); file.close(); KIO::NetAccess::removeTempFile(tmpFile); if (!success) { // It is corrupted - if (KMessageBox::warningContinueCancel(parent, i18n("Cannot open the project file, error is:\n%1\nDo you want to open a backup file?", errorMsg), i18n("Error opening file"), KGuiItem(i18n("Open Backup"))) == KMessageBox::Continue) { + if (KMessageBox::warningContinueCancel(parent, i18n("Cannot open the project file, error is:\n%1 (line %2, col %3)\nDo you want to open a backup file?", errorMsg, line, col), i18n("Error opening file"), KGuiItem(i18n("Open Backup"))) == KMessageBox::Continue) { *openBackup = true; } //KMessageBox::error(parent, errorMsg); @@ -1203,8 +1205,10 @@ bool KdenliveDoc::addClipInfo(QDomElement elem, QDomElement orig, QString clipId QMap meta; for (QDomNode m = orig.firstChild(); !m.isNull(); m = m.nextSibling()) { QString name = m.toElement().attribute("name"); - if (name.startsWith("meta.attr")) + if (name.startsWith("meta.attr")) { + if (name.endsWith(".markup")) name = name.section('.', 0, -2); meta.insert(name.section('.', 2, -1), m.firstChild().nodeValue()); + } } if (!meta.isEmpty()) { if (clip == NULL) diff --git a/src/renderer.cpp b/src/renderer.cpp index 431a5d51..23503f07 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp @@ -1094,7 +1094,7 @@ void Render::processFileProperties() for (int i = 0; i < count; i ++) { QString name = metadata.get_name(i); QString value = QString::fromUtf8(metadata.get(i)); - if (name.endsWith("markup") && !value.isEmpty()) + if (name.endsWith(".markup") && !value.isEmpty()) metadataPropertyMap[ name.section('.', 0, -2)] = value; } producer->seek(0); -- 2.39.2