]> git.sesse.net Git - kdenlive/blobdiff - src/kdenlivedoc.cpp
Don't crash when wrong sdl driver was selected by user (needs MLT patch):
[kdenlive] / src / kdenlivedoc.cpp
index 0835a60f8af76af4f7c74784e7050b71018bd78b..5494ab718e40252d7f1c497452433a955ab8c938 100644 (file)
@@ -66,6 +66,7 @@ KdenliveDoc::KdenliveDoc(const KUrl &url, const KUrl &projectFolder, QUndoGroup
 
     // init default document properties
     m_documentProperties["zoom"] = "7";
+    m_documentProperties["verticalzoom"] = "1";
     m_documentProperties["zonein"] = "0";
     m_documentProperties["zoneout"] = "100";
 
@@ -95,12 +96,11 @@ KdenliveDoc::KdenliveDoc(const KUrl &url, const KUrl &projectFolder, QUndoGroup
                     // TODO: backup the document or alert the user?
                     success = validator.validate(DOCUMENTVERSION);
                     if (success) { // Let the validator handle error messages
-                        setModified(validator.isModified());
                         QDomElement mlt = m_document.firstChildElement("mlt");
                         QDomElement infoXml = mlt.firstChildElement("kdenlivedoc");
 
                         profileName = infoXml.attribute("profile");
-                        m_projectFolder = infoXml.attribute("projectfolder");
+                        m_projectFolder = KUrl(infoXml.attribute("projectfolder"));
                         QDomElement docproperties = infoXml.firstChildElement("documentproperties");
                         QDomNamedNodeMap props = docproperties.attributes();
                         for (int i = 0; i < props.count(); i++) {
@@ -192,6 +192,7 @@ KdenliveDoc::KdenliveDoc(const KUrl &url, const KUrl &projectFolder, QUndoGroup
                                 infoXml.removeChild(markers);
                             }
                             setProfilePath(profileName);
+                            setModified(validator.isModified());
                             kDebug() << "Reading file: " << url.path() << ", found clips: " << producers.count();
                         }
                     }
@@ -238,13 +239,17 @@ KdenliveDoc::~KdenliveDoc()
     }
 }
 
-void KdenliveDoc::setSceneList()
+int KdenliveDoc::setSceneList()
 {
-    m_render->setSceneList(m_document.toString(), m_documentProperties.value("position").toInt());
+    if (m_render->setSceneList(m_document.toString(), m_documentProperties.value("position").toInt()) == -1) {
+        // INVALID MLT Consumer, something is wrong
+        return -1;
+    }
     m_documentProperties.remove("position");
     // m_document xml is now useless, clear it
     m_document.clear();
     checkProjectClips();
+    return 0;
 }
 
 QDomDocument KdenliveDoc::createEmptyDocument(const int videotracks, const int audiotracks)
@@ -387,14 +392,15 @@ void KdenliveDoc::slotAutoSave()
     }
 }
 
-void KdenliveDoc::setZoom(int factor)
+void KdenliveDoc::setZoom(int horizontal, int vertical)
 {
-    m_documentProperties["zoom"] = QString::number(factor);
+    m_documentProperties["zoom"] = QString::number(horizontal);
+    m_documentProperties["verticalzoom"] = QString::number(vertical);
 }
 
-int KdenliveDoc::zoom() const
+QPoint KdenliveDoc::zoom() const
 {
-    return m_documentProperties.value("zoom").toInt();
+    return QPoint(m_documentProperties.value("zoom").toInt(), m_documentProperties.value("verticalzoom").toInt());
 }
 
 void KdenliveDoc::setZone(int start, int end)
@@ -672,45 +678,6 @@ void KdenliveDoc::checkProjectClips()
     kDebug() << "+++++++++++++ + + + + CHK PCLIPS";
     if (m_render == NULL) return;
     m_clipManager->resetProducersList(m_render->producersList());
-    return;
-
-    // Useless now...
-    QList <Mlt::Producer *> prods = m_render->producersList();
-    QString id ;
-    QString prodId ;
-    QString prodTrack ;
-    for (int i = 0; i < prods.count(); i++) {
-        id = prods.at(i)->get("id");
-        prodId = id.section('_', 0, 0);
-        prodTrack = id.section('_', 1, 1);
-        DocClipBase *clip = m_clipManager->getClipById(prodId);
-        if (clip) clip->setProducer(prods.at(i));
-        if (clip && clip->clipType() == TEXT && !QFile::exists(clip->fileURL().path())) {
-            // regenerate text clip image if required
-            //kDebug() << "// TITLE: " << clip->getProperty("titlename") << " Preview file: " << clip->getProperty("resource") << " DOES NOT EXIST";
-            QString titlename = clip->getProperty("name");
-            QString titleresource;
-            if (titlename.isEmpty()) {
-                QStringList titleInfo = TitleWidget::getFreeTitleInfo(projectFolder());
-                titlename = titleInfo.at(0);
-                titleresource = titleInfo.at(1);
-                clip->setProperty("name", titlename);
-                kDebug() << "// New title set to: " << titlename;
-            } else {
-                titleresource = TitleWidget::getFreeTitleInfo(projectFolder()).at(1);
-                //titleresource = TitleWidget::getTitleResourceFromName(projectFolder(), titlename);
-            }
-            TitleWidget *dia_ui = new TitleWidget(KUrl(), KUrl(titleresource).directory(), m_render, kapp->activeWindow());
-            QDomDocument doc;
-            doc.setContent(clip->getProperty("xmldata"));
-            dia_ui->setXml(doc);
-            QImage pix = dia_ui->renderedPixmap();
-            pix.save(titleresource);
-            clip->setProperty("resource", titleresource);
-            delete dia_ui;
-            clip->producer()->set("force_reload", 1);
-        }
-    }
 }
 
 void KdenliveDoc::updatePreviewSettings()
@@ -915,7 +882,7 @@ void KdenliveDoc::addClip(QDomElement elem, QString clipId, bool createClipItem)
     if (createClipItem) {
         emit addProjectClip(clip);
         qApp->processEvents();
-        m_render->getFileProperties(clip->toXML(), clip->getId(), false);
+        m_render->getFileProperties(clip->toXML(), clip->getId(), true);
     }
 }
 
@@ -1092,7 +1059,7 @@ void KdenliveDoc::slotCreateTextTemplateClip(QString group, const QString &group
 
     if (path.isEmpty()) return;
 
-    QStringList titleInfo = TitleWidget::getFreeTitleInfo(projectFolder());
+    QStringList titleInfo = TitleWidget::getFreeTitleInfo(projectFolder(), true);
 
     TitleWidget *dia_ui = new TitleWidget(path, titlesFolder, m_render, kapp->activeWindow());
     QImage pix = dia_ui->renderedPixmap();
@@ -1170,18 +1137,18 @@ QPoint KdenliveDoc::getTracksCount() const
 
 void KdenliveDoc::cachePixmap(const QString &fileId, const QPixmap &pix) const
 {
-    pix.save(m_projectFolder.path() + "/thumbs/" + fileId + ".png");
+    pix.save(m_projectFolder.path(KUrl::AddTrailingSlash) + "thumbs/" + fileId + ".png");
 }
 
 QString KdenliveDoc::getLadspaFile() const
 {
     int ct = 0;
     QString counter = QString::number(ct).rightJustified(5, '0', false);
-    while (QFile::exists(m_projectFolder.path() + "/ladspa/" + counter + ".ladspa")) {
+    while (QFile::exists(m_projectFolder.path(KUrl::AddTrailingSlash) + "ladspa/" + counter + ".ladspa")) {
         ct++;
         counter = QString::number(ct).rightJustified(5, '0', false);
     }
-    return m_projectFolder.path() + "/ladspa/" + counter + ".ladspa";
+    return m_projectFolder.path(KUrl::AddTrailingSlash) + "ladspa/" + counter + ".ladspa";
 }
 
 bool KdenliveDoc::checkDocumentClips(QDomNodeList infoproducers)
@@ -1194,13 +1161,23 @@ bool KdenliveDoc::checkDocumentClips(QDomNodeList infoproducers)
     for (int i = 0; i < infoproducers.count(); i++) {
         e = infoproducers.item(i).toElement();
         clipType = e.attribute("type").toInt();
-        if (clipType == TEXT || clipType == COLOR) continue;
+        if (clipType == COLOR) continue;
+        if (clipType == TEXT) {
+            //TODO: Check is clip template is missing (xmltemplate) or hash changed
+            continue;
+        }
         id = e.attribute("id");
         resource = e.attribute("resource");
         if (clipType == SLIDESHOW) resource = KUrl(resource).directory();
         if (!KIO::NetAccess::exists(KUrl(resource), KIO::NetAccess::SourceSide, 0)) {
             // Missing clip found
             missingClips.append(e);
+        } else {
+            // Check if the clip has changed
+            if (clipType != SLIDESHOW && e.hasAttribute("file_hash")) {
+                if (e.attribute("file_hash") != DocClipBase::getHash(e.attribute("resource")))
+                    e.removeAttribute("file_hash");
+            }
         }
     }
     if (missingClips.isEmpty()) return true;