]> git.sesse.net Git - kdenlive/blobdiff - src/documentvalidator.cpp
move zonein, zoneout and zoom from <kdenlivedoc /> to <documentproperties /> when...
[kdenlive] / src / documentvalidator.cpp
index 9e4f11589cb1a674784f9bd3c9f2b3f44507b6b2..8f9d9cd942d0336e0c92e68ff869f530635904ce 100644 (file)
@@ -128,8 +128,8 @@ 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;
+        // TODO: uncomment when currentVersion == 0.84
+        //return true;
     }
 
     // The document is too new
@@ -675,34 +675,50 @@ 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;
             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"));
+            infoXml.appendChild(docProperties);
+        }
     }
 
     // The document has been converted: mark it as modified