From d1e6242c20436bfa1ac8d1c3a5dc9f55bd8f10ca Mon Sep 17 00:00:00 2001 From: Till Theato Date: Sun, 28 Aug 2011 14:47:54 +0000 Subject: [PATCH] Allow to edit projects with a locale different to the one used by Kdenlive. This also fixes loading of old projects (lc_numeric = C) in a system not using '.' as the decimal point[1]. Switching between projects with different locales can still cause problems. [1] http://kdenlive.org/mantis/view.php?id=2270 svn path=/trunk/kdenlive/; revision=5841 --- src/documentvalidator.cpp | 26 +++++++++++++++++--------- src/kdenlivedoc.cpp | 14 +++++++------- src/kdenlivedoc.h | 2 -- src/mainwindow.cpp | 9 +-------- src/projectlist.cpp | 1 - src/renderer.cpp | 9 ++++----- src/trackview.cpp | 2 -- 7 files changed, 29 insertions(+), 34 deletions(-) diff --git a/src/documentvalidator.cpp b/src/documentvalidator.cpp index fc46f14f..3cc588b8 100644 --- a/src/documentvalidator.cpp +++ b/src/documentvalidator.cpp @@ -20,6 +20,7 @@ #include "documentvalidator.h" #include "definitions.h" +#include "initeffects.h" #include #include @@ -55,17 +56,18 @@ bool DocumentValidator::validate(const double currentVersion) if (mlt.hasAttribute("LC_NUMERIC")) { // Set locale for the document documentLocale = QLocale(mlt.attribute("LC_NUMERIC")); - if (documentLocale.decimalPoint() != QLocale().decimalPoint()) { - QDomElement docProperties = kdenliveDoc.firstChildElement("documentproperties"); - if (docProperties.isNull()) { - docProperties = m_doc.createElement("documentproperties"); - kdenliveDoc.appendChild(docProperties); - } - docProperties.setAttribute("readonly", 1); - 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")); - } } + 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(documentLocale.toDouble(kdenliveDoc.attribute("version")), currentVersion)) return false; @@ -906,6 +908,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; diff --git a/src/kdenlivedoc.cpp b/src/kdenlivedoc.cpp index f453f70d..86a73e61 100644 --- a/src/kdenlivedoc.cpp +++ b/src/kdenlivedoc.cpp @@ -52,7 +52,7 @@ #include -const double DOCUMENTVERSION = 0.87; +const double DOCUMENTVERSION = 0.88; KdenliveDoc::KdenliveDoc(const KUrl &url, const KUrl &projectFolder, QUndoGroup *undoGroup, QString profileName, QMap properties, const QPoint tracks, Render *render, KTextEdit *notes, bool *openBackup, MainWindow *parent, KProgressDialog *progressDialog) : QObject(parent), @@ -95,6 +95,12 @@ KdenliveDoc::KdenliveDoc(const KUrl &url, const KUrl &projectFolder, QUndoGroup m_documentProperties[i.key()] = i.value(); } + if (QLocale() != QLocale::system()) { + QLocale::setDefault(QLocale::system()); + // locale conversion might need to be redone + initEffects::parseEffectFiles(); + } + *openBackup = false; if (!url.isEmpty()) { @@ -972,7 +978,6 @@ void KdenliveDoc::setUrl(KUrl url) void KdenliveDoc::setModified(bool mod) { - if (isReadOnly()) return; if (!m_url.isEmpty() && mod && KdenliveSettings::crashrecovery()) { m_autoSaveTimer->start(3000); } @@ -1637,11 +1642,6 @@ void KdenliveDoc::backupLastSavedVersion(const QString &path) } } -bool KdenliveDoc::isReadOnly() const -{ - return m_documentProperties.contains("readonly"); -} - void KdenliveDoc::cleanupBackupFiles() { KUrl backupFile = m_projectFolder; diff --git a/src/kdenlivedoc.h b/src/kdenlivedoc.h index 17bbf972..77818ade 100644 --- a/src/kdenlivedoc.h +++ b/src/kdenlivedoc.h @@ -162,8 +162,6 @@ Q_OBJECT public: static double getDisplayRatio(const QString &path); /** @brief Backup the project file */ void backupLastSavedVersion(const QString &path); - /** @brief True if the document was opened in read only mode. */ - bool isReadOnly() const; private: KUrl m_url; diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 4b534f62..8d9b0edc 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -2086,13 +2086,6 @@ void MainWindow::doOpenFile(const KUrl &url, KAutoSaveFile *stale) m_clipMonitor->refreshMonitor(true); progressDialog.progressBar()->setValue(4); - bool readOnly = !doc->isReadOnly(); - factory()->container("edit", this)->setEnabled(readOnly); - factory()->container("project", this)->setEnabled(readOnly); - factory()->container("tool", this)->setEnabled(readOnly); - factory()->container("clip", this)->setEnabled(readOnly); - factory()->container("timeline", this)->setEnabled(readOnly); - factory()->container("monitor", this)->setEnabled(readOnly); if (openBackup) slotOpenBackupDialog(url); } @@ -2373,7 +2366,7 @@ void MainWindow::slotUpdateMousePosition(int pos) void MainWindow::slotUpdateDocumentState(bool modified) { - if (!m_activeDocument || m_activeDocument->isReadOnly()) return; + if (!m_activeDocument) return; setCaption(m_activeDocument->description(), modified); m_saveAction->setEnabled(modified); if (modified) { diff --git a/src/projectlist.cpp b/src/projectlist.cpp index ab153157..001395d8 100644 --- a/src/projectlist.cpp +++ b/src/projectlist.cpp @@ -1522,7 +1522,6 @@ void ProjectList::setDocument(KdenliveDoc *doc) m_timecode = doc->timecode(); m_commandStack = doc->commandStack(); m_doc = doc; - setEnabled(!m_doc->isReadOnly()); QMap flist = doc->clipManager()->documentFolderList(); QStringList openedFolders = doc->getExpandedFolders(); diff --git a/src/renderer.cpp b/src/renderer.cpp index 2142f930..66e16ecd 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp @@ -51,6 +51,7 @@ static void kdenlive_callback(void* /*ptr*/, int level, const char* fmt, va_list vl) { +// kDebug() << "log level" << level << QString().vsprintf(fmt, vl).simplified(); if (level > MLT_LOG_ERROR) return; QString error; QApplication::postEvent(qApp->activeWindow(), new MltErrorEvent(error.vsprintf(fmt, vl).simplified())); @@ -1051,11 +1052,9 @@ int Render::setSceneList(QString playlist, int position) } blockSignals(true); - // WARNING: disabled because it caused crashes (see Kdenlive bug #2205 and #2206) - jbm - /*if (KdenliveSettings::projectloading_avformatnovalidate()) - playlist.replace(">avformat", ">avformat-novalidate"); - else - playlist.replace(">avformat-novalidate", ">avformat");*/ + + m_locale = QLocale(); + m_mltProducer = new Mlt::Producer(*m_mltProfile, "xml-string", playlist.toUtf8().constData()); if (!m_mltProducer || !m_mltProducer->is_valid()) { kDebug() << " WARNING - - - - -INVALID PLAYLIST: " << playlist.toUtf8().constData(); diff --git a/src/trackview.cpp b/src/trackview.cpp index 4dbd355d..1947f5df 100644 --- a/src/trackview.cpp +++ b/src/trackview.cpp @@ -118,7 +118,6 @@ TrackView::TrackView(KdenliveDoc *doc, bool *ok, QWidget *parent) : slotChangeZoom(m_doc->zoom().x(), m_doc->zoom().y()); slotSetZone(m_doc->zone(), false); - setEnabled(!doc->isReadOnly()); } TrackView::~TrackView() @@ -200,7 +199,6 @@ void TrackView::parseDocument(QDomDocument doc) // parse project tracks QDomElement mlt = doc.firstChildElement("mlt"); - if (mlt.hasAttribute("LC_NUMERIC")) m_locale = QLocale(mlt.attribute("LC_NUMERIC")); QDomElement tractor = mlt.firstChildElement("tractor"); QDomNodeList tracks = tractor.elementsByTagName("track"); QDomNodeList playlists = doc.elementsByTagName("playlist"); -- 2.39.2