]> git.sesse.net Git - kdenlive/commitdiff
Workaround locale issue when system locale and Qt's locale do not have the same numer...
authorJean-Baptiste Mardelle <jb@kdenlive.org>
Sun, 20 Nov 2011 22:23:01 +0000 (23:23 +0100)
committerJean-Baptiste Mardelle <jb@kdenlive.org>
Sun, 20 Nov 2011 22:23:45 +0000 (23:23 +0100)
src/documentvalidator.cpp
src/mainwindow.cpp

index a31c18a841cf29688b6d1b06a38267fdf5c709fb..194a55ad437a343220f7592e0bade4a5cf352339 100644 (file)
@@ -66,6 +66,16 @@ bool DocumentValidator::validate(const double currentVersion)
         // 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"));
+        
+        // Make sure Qt locale and C++ locale have the same numeric separator, might not be the case
+        // With some locales since C++ and Qt use a different database for locales
+        char *separator = localeconv()->decimal_point;
+        if (separator != documentLocale.decimalPoint()) {
+            kDebug()<<"------\n!!! system locale is not similar to Qt's locale... be prepared for bugs!!!\n------";
+            // HACK: There is a locale conflict, so set locale to at least have correct decimal point
+            if (strncmp(separator, ".", 1) == 0) documentLocale = QLocale::c();
+            else if (strncmp(separator, ",", 1) == 0) documentLocale = QLocale("fr_FR.UTF-8");
+        }
     }
     
     documentLocale.setNumberOptions(QLocale::OmitGroupSeparator);
index 53fb77bb249deba922601e416e587b1fb36de53f..bc41e23287bd27871919e5a4f58fb2305c95a161 100644 (file)
 #include <QBitmap>
 
 #include <stdlib.h>
+#include <locale.h>
 
 // Uncomment for deeper debugging
 //#define DEBUG_MAINW
@@ -156,6 +157,15 @@ MainWindow::MainWindow(const QString &MltPath, const KUrl & Url, const QString &
 
     // Init locale
     QLocale systemLocale = QLocale();
+    setlocale(LC_NUMERIC, NULL);
+    char *separator = localeconv()->decimal_point;
+    if (separator != systemLocale.decimalPoint()) {
+        kDebug()<<"------\n!!! system locale is not similar to Qt's locale... be prepared for bugs!!!\n------";
+        // HACK: There is a locale conflict, so set locale to at least have correct decimal point
+        if (strncmp(separator, ".", 1) == 0) systemLocale = QLocale::c();
+        else if (strncmp(separator, ",", 1) == 0) systemLocale = QLocale("fr_FR.UTF-8");
+    }
+    
     systemLocale.setNumberOptions(QLocale::OmitGroupSeparator);
     QLocale::setDefault(systemLocale);