]> git.sesse.net Git - kdenlive/blobdiff - src/documentvalidator.cpp
Fix issues when switching between projects with different locales.
[kdenlive] / src / documentvalidator.cpp
index 44fd3a41b43d2ba8428dfddc8c3c025e2576580c..185d597e36934db512640e7c1b97a17ca1dd992d 100644 (file)
@@ -20,6 +20,7 @@
 
 #include "documentvalidator.h"
 #include "definitions.h"
+#include "initeffects.h"
 
 #include <KDebug>
 #include <KMessageBox>
 
 #include <QFile>
 #include <QColor>
+#include <QString>
 
 #include <mlt++/Mlt.h>
 
+#include "locale.h"
+
 
 DocumentValidator::DocumentValidator(QDomDocument doc):
         m_doc(doc),
@@ -48,8 +52,31 @@ bool DocumentValidator::validate(const double currentVersion)
     // Check if we're validating a Kdenlive project
     if (kdenliveDoc.isNull())
         return false;
+
+    // Previous MLT / Kdenlive versions used C locale by default
+    QLocale documentLocale = QLocale::c();
+    
+    if (mlt.hasAttribute("LC_NUMERIC")) {
+        // Set locale for the document
+        // WARNING: what should be done in case the locale does not exist on the system?
+        setlocale(LC_NUMERIC, mlt.attribute("LC_NUMERIC").toUtf8().constData());
+        documentLocale = QLocale(mlt.attribute("LC_NUMERIC"));
+    }
+
+    documentLocale.setNumberOptions(QLocale::OmitGroupSeparator);
+
+    if (documentLocale != QLocale()) {
+        QLocale::setDefault(documentLocale);
+        // locale conversion might need to be redone
+        initEffects::parseEffectFiles();
+    }
+
+    // TODO: remove after string freeze
+    if (0)
+        KMessageBox::sorry(kapp->activeWindow(), i18n("The document you are opening uses a different locale (%1) than your system. You can only open and render it, no editing is supported unless you change your system's locale.", mlt.attribute("LC_NUMERIC")), i18n("Read only project"));
+
     // Upgrade the document to the latest version
-    if (!upgrade(kdenliveDoc.attribute("version").toDouble(), currentVersion))
+    if (!upgrade(documentLocale.toDouble(kdenliveDoc.attribute("version")), currentVersion))
         return false;
 
     /*
@@ -888,6 +915,12 @@ bool DocumentValidator::upgrade(double version, const double currentVersion)
         }
     }
 
+    if (version <= 0.87) {
+        if (!m_doc.firstChildElement("mlt").hasAttribute("LC_NUMERIC")) {
+            m_doc.firstChildElement("mlt").setAttribute("LC_NUMERIC", "C");
+        }
+    }
+
     // The document has been converted: mark it as modified
     infoXml.setAttribute("version", currentVersion);
     m_modified = true;