]> git.sesse.net Git - kdenlive/commitdiff
Fix some clips metadata corrupting project file: http://kdenlive.org/mantis/view...
authorJean-Baptiste Mardelle <jb@kdenlive.org>
Mon, 4 Feb 2013 15:14:36 +0000 (16:14 +0100)
committerJean-Baptiste Mardelle <jb@kdenlive.org>
Mon, 4 Feb 2013 15:14:36 +0000 (16:14 +0100)
src/docclipbase.cpp
src/kdenlivedoc.cpp
src/renderer.cpp

index 132dde9bd7f914e4f7e3512a4ce03d8285d39b2b..8573056021d96e9fa30fd83b58dc8bafe6500966 100644 (file)
@@ -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<QString, QString> 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()) {
index 269cfae41a75f2f50c1ed5fb8665931762825322..c1804867a187e675a136e5b5a78466f39bb1805c 100644 (file)
@@ -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<QString, QString> 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)
index 431a5d5133d6b11adc212d7ec7863b7dcc31b701..23503f07a996549843aeb6806dcbcbb1347331b3 100644 (file)
@@ -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);