]> git.sesse.net Git - kdenlive/blobdiff - src/kdenlivedoc.cpp
Fix massive project corruption when opening a document with frame rate different...
[kdenlive] / src / kdenlivedoc.cpp
index 35355db0e74b989442973f1d21e2085d218b3198..eebaf6f721ba2df2a28cbaf24211d94ff0ba85c5 100644 (file)
@@ -81,7 +81,13 @@ KdenliveDoc::KdenliveDoc(const KUrl &url, const KUrl &projectFolder, QUndoGroup
     m_documentProperties["proxyminsize"] = QString::number(KdenliveSettings::proxyminsize());
     m_documentProperties["generateimageproxy"] = QString::number((int) KdenliveSettings::generateimageproxy());
     m_documentProperties["proxyimageminsize"] = QString::number(KdenliveSettings::proxyimageminsize());
-    
+#if QT_VERSION >= 0x040700
+    m_documentProperties["documentid"] = QString::number(QDateTime::currentMSecsSinceEpoch());
+#else
+    QDateTime date = QDateTime::currentDateTime();
+    m_documentProperties["documentid"] = QString::number(date.toTime_t());
+#endif
+
     // Load properties
     QMapIterator<QString, QString> i(properties);
     while (i.hasNext()) {
@@ -146,6 +152,9 @@ KdenliveDoc::KdenliveDoc(const KUrl &url, const KUrl &projectFolder, QUndoGroup
                             QDomElement mlt = m_document.firstChildElement("mlt");
                             QDomElement infoXml = mlt.firstChildElement("kdenlivedoc");
 
+                            // Set profile, fps, etc for the document
+                            setProfilePath(infoXml.attribute("profile"));
+
                             // Check embedded effects
                             QDomElement customeffects = infoXml.firstChildElement("customeffects");
                             if (!customeffects.isNull() && customeffects.hasChildNodes()) {
@@ -251,7 +260,7 @@ KdenliveDoc::KdenliveDoc(const KUrl &url, const KUrl &projectFolder, QUndoGroup
                                 QDomNamedNodeMap props = docproperties.attributes();
                                 for (int i = 0; i < props.count(); i++)
                                     m_documentProperties.insert(props.item(i).nodeName(), props.item(i).nodeValue());
-                                setProfilePath(infoXml.attribute("profile"));
+
                                 if (validator.isModified()) setModified(true);
                                 kDebug() << "Reading file: " << url.path() << ", found clips: " << producers.count();
                             }
@@ -703,6 +712,15 @@ bool KdenliveDoc::saveSceneList(const QString &path, const QString &scene, const
     file.close();
     if (!autosave) {
         cleanupBackupFiles();
+        QFileInfo info(file);
+        QString fileName = KUrl(path).fileName().section('.', 0, -2);   
+        fileName.append("-" + m_documentProperties.value("documentid"));
+        fileName.append(info.lastModified().toString("-yyyy-MM-dd-hh-mm"));
+        fileName.append(".kdenlive.png");
+        KUrl backupFile = m_projectFolder;
+        backupFile.addPath(".backup/");
+        backupFile.addPath(fileName);
+        emit saveTimelinePreview(backupFile.path());
     }
     return true;
 }
@@ -859,10 +877,10 @@ void KdenliveDoc::setRenderer(Render *render) {
     emit progressInfo(QString(), -1);
 }*/
 
-void KdenliveDoc::checkProjectClips(bool displayRatioChanged)
+void KdenliveDoc::checkProjectClips(bool displayRatioChanged, bool fpsChanged)
 {
     if (m_render == NULL) return;
-    m_clipManager->resetProducersList(m_render->producersList(), displayRatioChanged);
+    m_clipManager->resetProducersList(m_render->producersList(), displayRatioChanged, fpsChanged);
 }
 
 Render *KdenliveDoc::renderer()
@@ -1342,7 +1360,7 @@ QString KdenliveDoc::getLadspaFile() const
 bool KdenliveDoc::checkDocumentClips(QDomNodeList infoproducers)
 {
     DocumentChecker d(infoproducers, m_document);
-    return (d.hasMissingClips() == false);
+    return (d.hasErrorInClips() == false);
 
     /*    int clipType;
         QDomElement e;
@@ -1600,18 +1618,18 @@ double KdenliveDoc::getDisplayRatio(const QString &path)
 void KdenliveDoc::backupLastSavedVersion(const QString &path)
 {
     // Ensure backup folder exists
+    if (path.isEmpty()) return;
     QFile file(path);
     KUrl backupFile = m_projectFolder;
     backupFile.addPath(".backup/");
     KIO::NetAccess::mkdir(backupFile, kapp->activeWindow());
     QString fileName = KUrl(path).fileName().section('.', 0, -2);
     QFileInfo info(file);
+    fileName.append("-" + m_documentProperties.value("documentid"));
     fileName.append(info.lastModified().toString("-yyyy-MM-dd-hh-mm"));
     fileName.append(".kdenlive");
     backupFile.addPath(fileName);
 
-    emit saveTimelinePreview(backupFile.path() + ".png");
-
     if (file.exists()) {
         // delete previous backup if it was done less than 60 seconds ago
         QFile::remove(backupFile.path());
@@ -1627,6 +1645,7 @@ void KdenliveDoc::cleanupBackupFiles()
     backupFile.addPath(".backup/");
     QDir dir(backupFile.path());
     QString projectFile = url().fileName().section('.', 0, -2);
+    projectFile.append("-" + m_documentProperties.value("documentid"));
     projectFile.append("-??");
     projectFile.append("??");
     projectFile.append("-??");