]> 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 4f098d2e61e232f62cd7dddfbb61325cdc9b4fd1..2b230524b16953da3f19c2402fe6e9e7935459f2 100644 (file)
  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
  ***************************************************************************/
 
-#include <QCryptographicHash>
-#include <QFile>
+
+#include "kdenlivedoc.h"
+#include "docclipbase.h"
+#include "profilesdialog.h"
+#include "kdenlivesettings.h"
+#include "renderer.h"
+#include "clipmanager.h"
+#include "titlewidget.h"
+#include "mainwindow.h"
 
 #include <KDebug>
 #include <KStandardDirs>
 #include <KIO/CopyJob>
 #include <KApplication>
 
+#include <QCryptographicHash>
+#include <QFile>
 
 #include <mlt++/Mlt.h>
 
-#include "kdenlivedoc.h"
-#include "docclipbase.h"
-#include "profilesdialog.h"
-#include "kdenlivesettings.h"
-#include "renderer.h"
-#include "clipmanager.h"
-#include "titlewidget.h"
-#include "mainwindow.h"
 
 KdenliveDoc::KdenliveDoc(const KUrl &url, const KUrl &projectFolder, QUndoGroup *undoGroup, const QString &profileName, const QPoint tracks, Render *render, MainWindow *parent): QObject(parent), m_render(render), m_url(url), m_projectFolder(projectFolder), m_commandStack(new QUndoStack(undoGroup)), m_modified(false), m_documentLoadingProgress(0), m_documentLoadingStep(0.0), m_startPos(0), m_zoom(7), m_autosave(NULL), m_zoneStart(0), m_zoneEnd(100), m_abortLoading(false) {
     m_clipManager = new ClipManager(this);
@@ -59,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 {
@@ -84,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);
 
@@ -112,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();
@@ -141,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);
@@ -354,14 +350,14 @@ void KdenliveDoc::slotAutoSave() {
             kDebug() << "ERROR; CANNOT CREATE AUTOSAVE FILE";
         }
         kDebug() << "// AUTOSAVE FILE: " << m_autosave->fileName();
-        QDomDocument doc;
+        QString doc;
         if (KdenliveSettings::dropbframes()) {
             KdenliveSettings::setDropbframes(false);
             m_clipManager->updatePreviewSettings();
-            doc.setContent(m_render->sceneList());
+            doc = m_render->sceneList();
             KdenliveSettings::setDropbframes(true);
             m_clipManager->updatePreviewSettings();
-        } else doc.setContent(m_render->sceneList());
+        } else doc = m_render->sceneList();
         saveSceneList(m_autosave->fileName(), doc);
     }
 }
@@ -376,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;
+    }
 
-    if (version == 0.82) return true;
+    // 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;
+    }
+
+    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++) {
@@ -399,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");
@@ -413,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++) {
@@ -427,13 +435,15 @@ bool KdenliveDoc::convertDocument(double version) {
             if (t.attribute("producer") != "black_track") tracksinfo.appendChild(trackinfo);
         }
         infoXml.appendChild(tracksinfo);
-        return TRUE;
+        return true;
     }
 
     QDomNode westley = m_document.elementsByTagName("westley").at(1);
     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");
 
@@ -877,7 +887,7 @@ bool KdenliveDoc::convertDocument(double version) {
                 //kDebug() << "ready to set additional <avfile />'s attributes (id =" << id << ")";
                 kproducer.setAttribute("channels", avfile.attribute("channels"));
                 kproducer.setAttribute("duration", avfile.attribute("duration"));
-                kproducer.setAttribute("frame_size", avfile.attribute("width") + "x" + avfile.attribute("height"));
+                kproducer.setAttribute("frame_size", avfile.attribute("width") + 'x' + avfile.attribute("height"));
                 kproducer.setAttribute("frequency", avfile.attribute("frequency"));
                 if (kproducer.attribute("description").isEmpty() && !avfile.attribute("description").isEmpty())
                     kproducer.setAttribute("description", avfile.attribute("description"));
@@ -899,7 +909,7 @@ bool KdenliveDoc::convertDocument(double version) {
     */
     //kDebug() << "/////////////////  END CONVERTEDĀ DOC:";
 
-    return TRUE;
+    return true;
 }
 
 QString KdenliveDoc::colorToString(const QColor& c) {
@@ -917,10 +927,13 @@ QPoint KdenliveDoc::zone() const {
     return QPoint(m_zoneStart, m_zoneEnd);
 }
 
-bool KdenliveDoc::saveSceneList(const QString &path, QDomDocument sceneList) {
+bool KdenliveDoc::saveSceneList(const QString &path, const QString &scene) {
+    QDomDocument sceneList;
+    sceneList.setContent(scene, true);
     QDomNode wes = sceneList.elementsByTagName("westley").at(0);
-
     QDomElement addedXml = sceneList.createElement("kdenlivedoc");
+    wes.appendChild(addedXml);
+
     QDomElement markers = sceneList.createElement("markers");
     addedXml.setAttribute("version", "0.82");
     addedXml.setAttribute("profile", profilePath());
@@ -973,7 +986,6 @@ bool KdenliveDoc::saveSceneList(const QString &path, QDomDocument sceneList) {
     addedXml.appendChild(markers);
     if (!m_guidesXml.isNull()) addedXml.appendChild(sceneList.importNode(m_guidesXml, true));
 
-    wes.appendChild(addedXml);
     //wes.appendChild(doc.importNode(kdenliveData, true));
 
     QFile file(path);
@@ -982,6 +994,7 @@ bool KdenliveDoc::saveSceneList(const QString &path, QDomDocument sceneList) {
         KMessageBox::error(kapp->activeWindow(), i18n("Cannot write to file %1", path));
         return false;
     }
+
     QTextStream out(&file);
     out << sceneList.toString();
     file.close();
@@ -1035,7 +1048,7 @@ void KdenliveDoc::moveProjectData(KUrl url) {
     }
 }
 
-QString KdenliveDoc::profilePath() const {
+const QString &KdenliveDoc::profilePath() const {
     return m_profile.path;
 }
 
@@ -1056,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;
 }
 
@@ -1208,7 +1221,10 @@ QDomNodeList KdenliveDoc::producersList() {
 }
 
 double KdenliveDoc::projectDuration() const {
-    if (m_render) return GenTime(m_render->getLength(), m_fps).ms() / 1000;
+    if (m_render)
+        return GenTime(m_render->getLength(), m_fps).ms() / 1000;
+    else
+        return 0;
 }
 
 double KdenliveDoc::fps() const {
@@ -1244,7 +1260,7 @@ bool KdenliveDoc::isModified() const {
     return m_modified;
 }
 
-QString KdenliveDoc::description() const {
+const QString KdenliveDoc::description() const {
     if (m_url.isEmpty())
         return i18n("Untitled") + " / " + m_profile.description;
     else
@@ -1253,13 +1269,8 @@ QString KdenliveDoc::description() const {
 
 void KdenliveDoc::addClip(QDomElement elem, QString clipId, bool createClipItem) {
     const QString producerId = clipId.section('_', 0, 0);
-    int subtrack = clipId.section('_', 1, 1).toInt();
     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;
@@ -1267,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;
@@ -1337,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();
@@ -1351,7 +1363,7 @@ void KdenliveDoc::setNewClipResource(const QString &id, const QString &path) {
     for (int i = 0; i < maxprod; i++) {
         QDomNode m = prods.at(i);
         QString prodId = m.toElement().attribute("id");
-        if (prodId == id || prodId.startsWith(id + "_")) {
+        if (prodId == id || prodId.startsWith(id + '_')) {
             QDomNodeList params = m.childNodes();
             for (int j = 0; j < params.count(); j++) {
                 QDomElement e = params.item(j).toElement();
@@ -1428,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);
         }
     }
@@ -1455,13 +1467,13 @@ void KdenliveDoc::slotAddClipList(const KUrl::List urls, const QString group, co
 
 
 void KdenliveDoc::slotAddClipFile(const KUrl url, const QString group, const QString &groupId) {
-    kDebug() << "/////////  DOCUM, ADD CLP: " << url;
+    //kDebug() << "/////////  DOCUM, ADD CLP: " << url;
     m_clipManager->slotAddClipFile(url, group, groupId);
     emit selectLastAddedClip(QString::number(m_clipManager->lastClipId()));
     setModified(true);
 }
 
-const QString&KdenliveDoc::getFreeClipId() {
+const QString KdenliveDoc::getFreeClipId() {
     return QString::number(m_clipManager->getFreeClipId());
 }
 
@@ -1469,16 +1481,6 @@ DocClipBase *KdenliveDoc::getBaseClip(const QString &clipId) {
     return m_clipManager->getClipById(clipId);
 }
 
-void KdenliveDoc::slotAddColorClipFile(const QString name, const QString color, QString duration, const QString group, const QString &groupId) {
-    m_clipManager->slotAddColorClipFile(name, color, duration, group, groupId);
-    setModified(true);
-}
-
-void KdenliveDoc::slotAddSlideshowClipFile(const QString name, const QString path, int count, const QString duration, const bool loop, const bool fade, const QString &luma_duration, const QString &luma_file, const int softness, const QString group, const QString &groupId) {
-    m_clipManager->slotAddSlideshowClipFile(name, path, count, duration, loop, fade, luma_duration, luma_file, softness, group, groupId);
-    setModified(true);
-}
-
 void KdenliveDoc::slotCreateTextClip(QString group, const QString &groupId) {
     QString titlesFolder = projectFolder().path() + "/titles/";
     KStandardDirs::makeDir(titlesFolder);