#include <KMessageBox>
#include <KApplication>
#include <KLocale>
-#include <KUrl>
#include <KStandardDirs>
#include <QFile>
#include <mlt++/Mlt.h>
-#include "locale.h"
+#include <locale>
-DocumentValidator::DocumentValidator(QDomDocument doc):
+DocumentValidator::DocumentValidator(const QDomDocument &doc, const KUrl &documentUrl):
m_doc(doc),
+ m_url(documentUrl),
m_modified(false)
{}
// Check if we're validating a Kdenlive project
if (kdenliveDoc.isNull())
return false;
+
+ QString rootDir = mlt.attribute("root");
+ if (rootDir == "$CURRENTPATH") {
+ // The document was extracted from a Kdenlive archived project, fix root directory
+ QString playlist = m_doc.toString();
+ playlist.replace("$CURRENTPATH", m_url.directory(KUrl::IgnoreTrailingSlash));
+ m_doc.setContent(playlist);
+ mlt = m_doc.firstChildElement("mlt");
+ kdenliveDoc = mlt.firstChildElement("kdenlivedoc");
+ }
// 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());
+ // Set locale for the document
+ const QString newLocale = 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 (newLocale.isEmpty()) {
+ // Requested locale not available, ask for install
+ KMessageBox::sorry(kapp->activeWindow(), i18n("The document was created in \"%1\" locale, which is not installed on your system. Please install that language pack. Until then, Kdenlive might not be able to correctly open the document.", mlt.attribute("LC_NUMERIC")));
+ }
+
+ if (separator != documentLocale.decimalPoint()) {
+ KMessageBox::sorry(kapp->activeWindow(), i18n("There is a locale conflict on your system. The document uses locale %1 which uses a \"%2\" as numeric separator (in system libraries) but Qt expects \"%3\". You might not be able to correctly open the project.", mlt.attribute("LC_NUMERIC"), 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);
if (documentLocale.decimalPoint() != QLocale().decimalPoint()) {
// If loading an older MLT file without LC_NUMERIC, set locale to C which was previously the default
- if (!mlt.hasAttribute("LC_NUMERIC")) setlocale(LC_NUMERIC, "C");
+ if (!mlt.hasAttribute("LC_NUMERIC")) {
+ setlocale(LC_NUMERIC, "C");
+ }
QLocale::setDefault(documentLocale);
// locale conversion might need to be redone
- initEffects::parseEffectFiles();
+ initEffects::parseEffectFiles(setlocale(LC_NUMERIC, NULL));
}
- // 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"));
-
+ bool ok;
+ double version = documentLocale.toDouble(kdenliveDoc.attribute("version"), &ok);
+ if (!ok) {
+ // Could not parse version number, there is probably a conflict in decimal separator
+ QLocale tempLocale = QLocale(mlt.attribute("LC_NUMERIC"));
+ version = tempLocale.toDouble(kdenliveDoc.attribute("version"), &ok);
+ if (!ok) version = kdenliveDoc.attribute("version").toDouble(&ok);
+ if (!ok) {
+ // Last try: replace comma with a dot
+ QString versionString = kdenliveDoc.attribute("version");
+ if (versionString.contains(',')) versionString.replace(',', '.');
+ version = versionString.toDouble(&ok);
+ if (!ok) kDebug()<<"// CANNOT PARSE VERSION NUMBER, ERROR!";
+ }
+ }
+
// Upgrade the document to the latest version
- if (!upgrade(documentLocale.toDouble(kdenliveDoc.attribute("version")), currentVersion))
+ if (!upgrade(version, currentVersion))
return false;
/*
tnode = tinfo.firstChild();
}
- for (int i = 1; i < tracks.count(); i++) {
+ 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") {
blank_tractor.appendChild(blank_track);
QDomNodeList kdenlivetracks = m_doc.elementsByTagName("kdenlivetrack");
- for (int i = 0; i < kdenlivetracks.count(); i++) {
+ for (int i = 0; i < kdenlivetracks.count(); ++i) {
blank_playlist = m_doc.createElement("playlist");
blank_playlist.setAttribute("id", "playlist" + QString::number(i));
westley.insertBefore(blank_playlist, QDomNode());
blank_track.setAttribute("hide", "video");
}
}
- } else for (int i = 0; i < max; i++) {
+ } else for (int i = 0; i < max; ++i) {
QDomNode n = playlists.at(i);
westley.insertBefore(n, QDomNode());
QDomElement pl = n.toElement();
// audio track mixing transitions should not be added to track view, so add required attribute
QDomNodeList transitions = m_doc.elementsByTagName("transition");
max = transitions.count();
- for (int i = 0; i < max; i++) {
+ for (int i = 0; i < max; ++i) {
QDomElement tr = transitions.at(i).toElement();
if (tr.attribute("combine") == "1" && tr.attribute("mlt_service") == "mix") {
QDomElement property = m_doc.createElement("property");
}
// move transitions after tracks
- for (int i = 0; i < max; i++) {
+ for (int i = 0; i < max; ++i) {
tractor.insertAfter(transitions.at(0), QDomNode());
}
// Fix filters format
QDomNodeList entries = m_doc.elementsByTagName("entry");
max = entries.count();
- for (int i = 0; i < max; i++) {
+ for (int i = 0; i < max; ++i) {
QString last_id;
int effectix = 0;
QDomNode m = entries.at(i).firstChild();
max = filters.count();
QString last_id;
int effectix = 0;
- for (int i = 0; i < max; i++) {
+ for (int i = 0; i < max; ++i) {
QDomElement filt = filters.at(i).toElement();
QDomNamedNodeMap attrs = filt.attributes();
QString current_id = filt.attribute("kdenlive_id");
// fix slowmotion
QDomNodeList producers = westley.toElement().elementsByTagName("producer");
max = producers.count();
- for (int i = 0; i < max; i++) {
+ for (int i = 0; i < max; ++i) {
QDomElement prod = producers.at(i).toElement();
if (prod.attribute("mlt_service") == "framebuffer") {
QString slowmotionprod = prod.attribute("resource");
// This will get the xml producers:
producers = m_doc.elementsByTagName("producer");
max = producers.count();
- for (int i = 0; i < max; i++) {
+ for (int i = 0; i < max; ++i) {
QDomElement prod = producers.at(0).toElement();
// add resource also as a property (to allow path correction in setNewResource())
// TODO: will it work with slowmotion? needs testing
} else {
QDomNodeList wproducers = westley_element.elementsByTagName("producer");
int kmax = wproducers.count();
- for (int i = 0; i < kmax; i++) {
+ for (int i = 0; i < kmax; ++i) {
QDomElement wproducer = wproducers.at(i).toElement();
if (wproducer.isNull()) {
kWarning() << "Found producer in westley0, that was not a QDomElement";
#endif
QDomNodeList elements = westley.childNodes();
max = elements.count();
- for (int i = 0; i < max; i++) {
+ for (int i = 0; i < max; ++i) {
QDomElement prod = elements.at(0).toElement();
westley0.insertAfter(prod, QDomNode());
}
QString tracksOrder = infoXml.attribute("tracks");
if (tracksOrder.isEmpty()) {
QDomNodeList tracks = m_doc.elementsByTagName("track");
- for (int i = 0; i < tracks.count(); i++) {
+ for (int i = 0; i < tracks.count(); ++i) {
QDomElement track = tracks.at(i).toElement();
if (track.attribute("producer") != "black_track") {
if (track.attribute("hide") == "video")
}
}
QDomElement tracksinfo = m_doc.createElement("tracksinfo");
- for (int i = 0; i < tracksOrder.size(); i++) {
+ for (int i = 0; i < tracksOrder.size(); ++i) {
QDomElement trackinfo = m_doc.createElement("trackinfo");
if (tracksOrder.data()[i] == 'a') {
trackinfo.setAttribute("type", "audio");
if (version <= 0.82) {
// Convert <westley />s in <mlt />s (MLT extreme makeover)
QDomNodeList westleyNodes = m_doc.elementsByTagName("westley");
- for (int i = 0; i < westleyNodes.count(); i++) {
+ for (int i = 0; i < westleyNodes.count(); ++i) {
QDomElement westley = westleyNodes.at(i).toElement();
westley.setTagName("mlt");
}
// Make sure we don't have avformat-novalidate producers, since it caused crashes
QDomNodeList producers = m_doc.elementsByTagName("producer");
int max = producers.count();
- for (int i = 0; i < max; i++) {
+ for (int i = 0; i < max; ++i) {
QDomElement prod = producers.at(i).toElement();
if (EffectsList::property(prod, "mlt_service") == "avformat-novalidate")
EffectsList::setProperty(prod, "mlt_service", "avformat");
QDomNodeList transitions = m_doc.elementsByTagName("transition");
max = transitions.count();
int out;
- for (int i = 0; i < max; i++) {
+ for (int i = 0; i < max; ++i) {
QDomElement trans = transitions.at(i).toElement();
out = trans.attribute("out").toInt() - trans.attribute("in").toInt();
QString geom = EffectsList::property(trans, "geometry");
return true;
}
-QStringList DocumentValidator::getInfoFromEffectName(const QString oldName)
+QStringList DocumentValidator::getInfoFromEffectName(const QString &oldName)
{
QStringList info;
// Returns a list to convert old Kdenlive ladspa effects
}
}
-bool DocumentValidator::updateEffectParameters(QDomNodeList parameters, const QScriptValue* updateRules, const double serviceVersion, const double effectVersion)
+bool DocumentValidator::updateEffectParameters(const QDomNodeList ¶meters, const QScriptValue* updateRules, const double serviceVersion, const double effectVersion)
{
bool updated = false;
bool isDowngrade = serviceVersion < effectVersion;