]> git.sesse.net Git - kdenlive/blobdiff - src/kdenlivedoc.cpp
const modifiers are useless on integral return types [PATCH by Ray Lehtiniemi]
[kdenlive] / src / kdenlivedoc.cpp
index 2f752556fd1a362d53c24637543f141cc2a4ecb1..2b230524b16953da3f19c2402fe6e9e7935459f2 100644 (file)
@@ -60,7 +60,7 @@ KdenliveDoc::KdenliveDoc(const KUrl &url, const KUrl &projectFolder, QUndoGroup
 
                 // Upgrade old Kdenlive documents to current version
                 if (!convertDocument(version)) {
-                    KMessageBox::sorry(parent, i18n("This project type is unsupported and can't be loaded."), i18n("Unable to open project"));
+                    m_url.clear();
                     m_document = createEmptyDocument(tracks.x(), tracks.y());
                     setProfilePath(profileName);
                 } else {
@@ -85,10 +85,6 @@ KdenliveDoc::KdenliveDoc(const KUrl &url, const KUrl &projectFolder, QUndoGroup
                     }
                     m_startPos = infoXml.attribute("position").toInt();
                     m_zoom = infoXml.attribute("zoom", "7").toInt();
-
-
-
-
                     m_zoneEnd = infoXml.attribute("zoneout", "100").toInt();
                     setProfilePath(profilePath);
 
@@ -113,7 +109,6 @@ KdenliveDoc::KdenliveDoc(const KUrl &url, const KUrl &projectFolder, QUndoGroup
                         westley.removeChild(tracksinfo);
                     }
 
-                    QDomElement orig;
                     QDomNodeList producers = m_document.elementsByTagName("producer");
                     QDomNodeList infoproducers = m_document.elementsByTagName("kdenlive_producer");
                     const int max = producers.count();
@@ -142,7 +137,7 @@ KdenliveDoc::KdenliveDoc(const KUrl &url, const KUrl &projectFolder, QUndoGroup
                         if (!e.isNull() && prodId != "black" && !prodId.startsWith("slowmotion") && !m_abortLoading) {
                             e.setTagName("producer");
                             // Get MLT's original producer properties
-
+                            QDomElement orig;
                             for (int j = 0; j < max; j++) {
                                 QDomElement o = producers.item(j).cloneNode().toElement();
                                 QString origId = o.attribute("id").section('_', 0, 0);
@@ -377,13 +372,31 @@ int KdenliveDoc::zoom() const {
 
 bool KdenliveDoc::convertDocument(double version) {
     kDebug() << "Opening a document with version " << version;
+    const double current_version = 0.82;
+
+    if (version == current_version) return true;
+
+    if (version > current_version) {
+        kDebug() << "Unable to open document with version " << version;
+        KMessageBox::sorry(kapp->activeWindow(), i18n("This project type is unsupported (version %1) and can't be loaded.\nPlease consider upgrading you Kdenlive version.", version), i18n("Unable to open project"));
+        return false;
+    }
+
+    // Opening a old Kdenlive document
+    if (version == 0.5 || version == 0.7) {
+        KMessageBox::sorry(kapp->activeWindow(), i18n("This project type is unsupported (version %1) and can't be loaded.", version), i18n("Unable to open project"));
+        kDebug() << "Unable to open document with version " << version;
+        // TODO: convert 0.7 (0.5?) files to the new document format.
+        return false;
+    }
 
-    if (version == 0.82) return true;
+    setModified(true);
 
     if (version == 0.81) {
         // Add correct tracks info
         QDomNode kdenlivedoc = m_document.elementsByTagName("kdenlivedoc").at(0);
         QDomElement infoXml = kdenlivedoc.toElement();
+        infoXml.setAttribute("version", current_version);
         QString currentTrackOrder = infoXml.attribute("tracks");
         QDomElement tracksinfo = m_document.createElement("tracksinfo");
         for (int i = 0; i < currentTrackOrder.size(); i++) {
@@ -400,13 +413,6 @@ bool KdenliveDoc::convertDocument(double version) {
         return true;
     }
 
-    // Opening a old Kdenlive document
-    if (version == 0.5 || version == 0.7 || version > 0.81) {
-        kDebug() << "Unable to open document with version " << version;
-        // TODO: convert 0.7 (0.5?) files to the new document format.
-        return false;
-    }
-
     if (version == 0.8) {
         // Add the tracks information
         QDomNodeList tracks = m_document.elementsByTagName("track");
@@ -414,6 +420,7 @@ bool KdenliveDoc::convertDocument(double version) {
 
         QDomNode kdenlivedoc = m_document.elementsByTagName("kdenlivedoc").at(0);
         QDomElement infoXml = kdenlivedoc.toElement();
+        infoXml.setAttribute("version", current_version);
         QDomElement tracksinfo = m_document.createElement("tracksinfo");
 
         for (int i = 0; i < max; i++) {
@@ -435,6 +442,8 @@ bool KdenliveDoc::convertDocument(double version) {
     QDomNode tractor = m_document.elementsByTagName("tractor").at(0);
     QDomNode kdenlivedoc = m_document.elementsByTagName("kdenlivedoc").at(0);
     QDomElement kdenlivedoc_old = kdenlivedoc.cloneNode(true).toElement(); // Needed for folders
+    QDomElement infoXml = kdenlivedoc.toElement();
+    infoXml.setAttribute("version", current_version);
     QDomNode multitrack = m_document.elementsByTagName("multitrack").at(0);
     QDomNodeList playlists = m_document.elementsByTagName("playlist");
 
@@ -1060,7 +1069,7 @@ void KdenliveDoc::setProfilePath(QString path) {
     else m_timecode.setFormat((int) m_fps);
 }
 
-const double KdenliveDoc::dar() {
+double KdenliveDoc::dar() {
     return (double) m_profile.display_aspect_num / m_profile.display_aspect_den;
 }
 
@@ -1262,10 +1271,6 @@ void KdenliveDoc::addClip(QDomElement elem, QString clipId, bool createClipItem)
     const QString producerId = clipId.section('_', 0, 0);
     DocClipBase *clip = m_clipManager->getClipById(producerId);
     if (clip == NULL) {
-        /*kDebug()<<"// CLIP "<<clipId<<" NOT OFUND in LIST, CREATING";
-        QDomDocument doc;
-        doc.appendChild(doc.importNode(elem, true));
-        kDebug() << "IMPORTED CLIP: \n" << doc.toString()<<"\n";*/
         elem.setAttribute("id", producerId);
         QString path = elem.attribute("resource");
         QString extension;
@@ -1273,7 +1278,7 @@ void KdenliveDoc::addClip(QDomElement elem, QString clipId, bool createClipItem)
             extension = KUrl(path).fileName();
             path = KUrl(path).directory();
         }
-        if (!QFile::exists(path) && elem.attribute("type").toInt() == TEXT) {
+        if (elem.attribute("type").toInt() == TEXT && !QFile::exists(path)) {
             kDebug() << "// TITLE: " << elem.attribute("titlename") << " Preview file: " << elem.attribute("resource") << " DOES NOT EXIST";
             QString titlename = elem.attribute("titlename");
             QString titleresource;
@@ -1343,6 +1348,7 @@ void KdenliveDoc::addClip(QDomElement elem, QString clipId, bool createClipItem)
         clip = new DocClipBase(m_clipManager, elem, producerId);
         m_clipManager->addClip(clip);
     }
+
     if (createClipItem) {
         emit addProjectClip(clip);
         qApp->processEvents();
@@ -1434,7 +1440,7 @@ void KdenliveDoc::addClipInfo(QDomElement elem, QDomElement orig, QString clipId
             m = m.nextSibling();
         }
         if (!meta.isEmpty()) {
-            clip = m_clipManager->getClipById(clipId);
+            if (clip == NULL) clip = m_clipManager->getClipById(clipId);
             if (clip) clip->setMetadata(meta);
         }
     }