]> git.sesse.net Git - kdenlive/blobdiff - src/documentvalidator.cpp
Fix typos (patch from yurchor)
[kdenlive] / src / documentvalidator.cpp
index 9e4f11589cb1a674784f9bd3c9f2b3f44507b6b2..1ebcb6f0556008780f7f3010d770163fb0c51fb8 100644 (file)
@@ -82,8 +82,40 @@ bool DocumentValidator::validate(const double currentVersion)
         if (playlists.count() - 1 < tracksMax ||
                 tracks.count() - 1 < tracksMax ||
                 tracksinfo.count() < tracksMax) {
+            kDebug() << "//// WARNING, PROJECT IS CORRUPTED, MISSING TRACK";
             m_modified = true;
             int difference;
+            // use the MLT tracks as reference
+            if (tracks.count() - 1 < tracksMax) {
+                // Looks like one MLT track is missing, remove the extra Kdenlive track if there is one.
+                if (tracksinfo.count() != tracks.count() - 1) {
+                    // The Kdenlive tracks are not ok, clear and rebuild them
+                    QDomNode tinfo = m_doc.elementsByTagName("tracksinfo").at(0);
+                    QDomNode tnode = tinfo.firstChild();
+                    while (!tnode.isNull()) {
+                        tinfo.removeChild(tnode);
+                        tnode = tinfo.firstChild();
+                    }
+
+                    for (int i = 1; i < tracks.count(); i++) {
+                        QString hide = tracks.at(i).toElement().attribute("hide");
+                        QDomElement newTrack = m_doc.createElement("trackinfo");
+                        if (hide == "video") {
+                            // audio track;
+                            newTrack.setAttribute("type", "audio");
+                            newTrack.setAttribute("blind", 1);
+                            newTrack.setAttribute("mute", 0);
+                            newTrack.setAttribute("lock", 0);
+                        } else {
+                            newTrack.setAttribute("blind", 0);
+                            newTrack.setAttribute("mute", 0);
+                            newTrack.setAttribute("lock", 0);
+                        }
+                        tinfo.appendChild(newTrack);
+                    }
+                }
+            }
+
             if (playlists.count() - 1 < tracksMax) {
                 difference = tracksMax - (playlists.count() - 1);
                 for (int i = 0; i < difference; ++i) {
@@ -128,14 +160,13 @@ bool DocumentValidator::upgrade(double version, const double currentVersion)
 
     // No conversion needed
     if (version == currentVersion) {
-        if (!m_doc.toString().contains("font-size")) // TODO: remove when currentVersion == 0.84
-            return true;
+        return true;
     }
 
     // The document is too new
     if (version > currentVersion) {
         kDebug() << "Unable to open document with version " << version;
-        KMessageBox::sorry(kapp->activeWindow(), i18n("This project type is unsupported (version %1) and can't be loaded.\nPlease consider upgrading you Kdenlive version.", version), i18n("Unable to open project"));
+        KMessageBox::sorry(kapp->activeWindow(), i18n("This project type is unsupported (version %1) and can't be loaded.\nPlease consider upgrading your Kdenlive version.", version), i18n("Unable to open project"));
         return false;
     }
 
@@ -149,6 +180,7 @@ bool DocumentValidator::upgrade(double version, const double currentVersion)
     // <kdenlivedoc />
     QDomNode infoXmlNode = m_doc.elementsByTagName("kdenlivedoc").at(0);
     QDomElement infoXml = infoXmlNode.toElement();
+    infoXml.setAttribute("upgraded", "1");
 
     if (version <= 0.6) {
         QDomElement infoXml_old = infoXmlNode.cloneNode(true).toElement(); // Needed for folders
@@ -675,40 +707,118 @@ bool DocumentValidator::upgrade(double version, const double currentVersion)
     if (version <= 0.83) {
         // Replace point size with pixel size in text titles
         if (m_doc.toString().contains("font-size")) {
+            KMessageBox::ButtonCode convert = KMessageBox::Continue;
             QDomNodeList kproducerNodes = m_doc.elementsByTagName("kdenlive_producer");
-            for (int i = 0; i < kproducerNodes.count(); ++i) {
+            for (int i = 0; i < kproducerNodes.count() && convert != KMessageBox::No; ++i) {
                 QDomElement kproducer = kproducerNodes.at(i).toElement();
                 if (kproducer.attribute("type").toInt() == TEXT) {
                     QDomDocument data;
                     data.setContent(kproducer.attribute("xmldata"));
                     QDomNodeList items = data.firstChild().childNodes();
-                    for (int j = 0; j < items.count(); ++j) {
+                    for (int j = 0; j < items.count() && convert != KMessageBox::No; ++j) {
                         if (items.at(j).attributes().namedItem("type").nodeValue() == "QGraphicsTextItem") {
                             QDomNamedNodeMap textProperties = items.at(j).namedItem("content").attributes();
-                            if (textProperties.namedItem("font-pixel-size").isNull()) {
-                                QFont font;
-                                font.setPointSize(textProperties.namedItem("font-size").nodeValue().toInt());
-                                QDomElement content = items.at(j).namedItem("content").toElement();
-                                content.setAttribute("font-pixel-size", QFontInfo(font).pixelSize());
-                                content.removeAttribute("font-size");
-                                kproducer.setAttribute("xmldata", data.toString());
-                                /*
-                                 * You may be tempted to delete the preview file
-                                 * to force its recreation: bad idea (see
-                                 * http://www.kdenlive.org/mantis/view.php?id=749)
-                                 */
+                            if (textProperties.namedItem("font-pixel-size").isNull() && !textProperties.namedItem("font-size").isNull()) {
+                                // Ask the user if he wants to convert
+                                if (convert != KMessageBox::Yes && convert != KMessageBox::No)
+                                    convert = (KMessageBox::ButtonCode)KMessageBox::warningYesNo(kapp->activeWindow(), i18n("Some of your text clips were saved with size in points, which means different sizes on different displays. Do you want to convert them to pixel size, making them portable? It is recommended you do this on the computer they were first created on, or you could have to adjust their size."), i18n("Update Text Clips"));
+                                if (convert == KMessageBox::Yes) {
+                                    QFont font;
+                                    font.setPointSize(textProperties.namedItem("font-size").nodeValue().toInt());
+                                    QDomElement content = items.at(j).namedItem("content").toElement();
+                                    content.setAttribute("font-pixel-size", QFontInfo(font).pixelSize());
+                                    content.removeAttribute("font-size");
+                                    kproducer.setAttribute("xmldata", data.toString());
+                                    /*
+                                     * You may be tempted to delete the preview file
+                                     * to force its recreation: bad idea (see
+                                     * http://www.kdenlive.org/mantis/view.php?id=749)
+                                     */
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+        }
+
+        // Fill the <documentproperties /> element
+        QDomElement docProperties = infoXml.firstChildElement("documentproperties");
+        if (docProperties.isNull()) {
+            docProperties = m_doc.createElement("documentproperties");
+            docProperties.setAttribute("zonein", infoXml.attribute("zonein"));
+            docProperties.setAttribute("zoneout", infoXml.attribute("zoneout"));
+            docProperties.setAttribute("zoom", infoXml.attribute("zoom"));
+            docProperties.setAttribute("position", infoXml.attribute("position"));
+            infoXml.appendChild(docProperties);
+        }
+    }
+
+    if (version <= 0.84) {
+        // update the title clips to use the new MLT kdenlivetitle producer
+        QDomNodeList kproducerNodes = m_doc.elementsByTagName("kdenlive_producer");
+        for (int i = 0; i < kproducerNodes.count(); ++i) {
+            QDomElement kproducer = kproducerNodes.at(i).toElement();
+            if (kproducer.attribute("type").toInt() == TEXT) {
+                QString data = kproducer.attribute("xmldata");
+                QString datafile = kproducer.attribute("resource");
+                if (!datafile.endsWith(".kdenlivetitle")) {
+                    datafile = QString();
+                    kproducer.setAttribute("resource", QString());
+                }
+                QString id = kproducer.attribute("id");
+                QDomNodeList mltproducers = m_doc.elementsByTagName("producer");
+                bool foundData = false;
+                bool foundResource = false;
+                bool foundService = false;
+                for (int j = 0; j < mltproducers.count(); j++) {
+                    QDomElement wproducer = mltproducers.at(j).toElement();
+                    if (wproducer.attribute("id") == id) {
+                        QDomNodeList props = wproducer.childNodes();
+                        for (int k = 0; k < props.count(); k++) {
+                            if (props.at(k).toElement().attribute("name") == "xmldata") {
+                                props.at(k).firstChild().setNodeValue(data);
+                                foundData = true;
+                            } else if (props.at(k).toElement().attribute("name") == "mlt_service") {
+                                props.at(k).firstChild().setNodeValue("kdenlivetitle");
+                                foundService = true;
+                            } else if (props.at(k).toElement().attribute("name") == "resource") {
+                                props.at(k).firstChild().setNodeValue(datafile);
+                                foundResource = true;
                             }
                         }
+                        if (!foundData) {
+                            QDomElement e = m_doc.createElement("property");
+                            e.setAttribute("name", "xmldata");
+                            QDomText value = m_doc.createTextNode(data);
+                            e.appendChild(value);
+                            wproducer.appendChild(e);
+                        }
+                        if (!foundService) {
+                            QDomElement e = m_doc.createElement("property");
+                            e.setAttribute("name", "mlt_service");
+                            QDomText value = m_doc.createTextNode("kdenlivetitle");
+                            e.appendChild(value);
+                            wproducer.appendChild(e);
+                        }
+                        if (!foundResource) {
+                            QDomElement e = m_doc.createElement("property");
+                            e.setAttribute("name", "resource");
+                            QDomText value = m_doc.createTextNode(datafile);
+                            e.appendChild(value);
+                            wproducer.appendChild(e);
+                        }
+                        break;
                     }
                 }
             }
         }
     }
 
+
     // The document has been converted: mark it as modified
     infoXml.setAttribute("version", currentVersion);
     m_modified = true;
-
     return true;
 }