]> git.sesse.net Git - kdenlive/blobdiff - src/kdenlivedoc.cpp
*Render dialog can now create xml files for dvd chapters based on guides (usable...
[kdenlive] / src / kdenlivedoc.cpp
index 4a920cc40475accc3b746a09362857cf58dc626b..7fc0333b82a6b2569c6424781f8e3b7b289986a5 100644 (file)
@@ -26,6 +26,8 @@
 #include "clipmanager.h"
 #include "titlewidget.h"
 #include "mainwindow.h"
+#include "documentchecker.h"
+#include "kdenlive-config.h"
 
 #include <KDebug>
 #include <KStandardDirs>
 
 #include <mlt++/Mlt.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)
+KdenliveDoc::KdenliveDoc(const KUrl &url, const KUrl &projectFolder, QUndoGroup *undoGroup, const QString &profileName, const QPoint tracks, Render *render, MainWindow *parent) :
+        QObject(parent),
+        m_autosave(NULL),
+        m_url(url),
+        m_zoom(7),
+        m_startPos(0),
+        m_render(render),
+        m_commandStack(new QUndoStack(undoGroup)),
+        m_modified(false),
+        m_projectFolder(projectFolder),
+        m_documentLoadingStep(0.0),
+        m_documentLoadingProgress(0),
+        m_abortLoading(false),
+        m_zoneStart(0),
+        m_zoneEnd(100)
 {
     m_clipManager = new ClipManager(this);
     m_autoSaveTimer = new QTimer(this);
@@ -63,7 +78,6 @@ KdenliveDoc::KdenliveDoc(const KUrl &url, const KUrl &projectFolder, QUndoGroup
 
         if (success) {
             QDomNode infoXmlNode = m_document.elementsByTagName("kdenlivedoc").at(0);
-            QDomNode westley = m_document.elementsByTagName("westley").at(0);
             if (!infoXmlNode.isNull()) {
                 QDomElement infoXml = infoXmlNode.toElement();
                 double version = infoXml.attribute("version").toDouble();
@@ -75,14 +89,14 @@ KdenliveDoc::KdenliveDoc(const KUrl &url, const KUrl &projectFolder, QUndoGroup
                     setProfilePath(profileName);
                 } else {
                     /*
-                     * read again <kdenlivedoc> and <westley> to get all the new
-                     * stuff (convertDocument() can now do anything without breaking
+                     * read again <kdenlivedoc> to get all the new stuff
+                     * (convertDocument() can now do anything without breaking
                      * document loading)
                      */
                     infoXmlNode = m_document.elementsByTagName("kdenlivedoc").at(0);
                     infoXml = infoXmlNode.toElement();
                     version = infoXml.attribute("version").toDouble();
-                    westley = m_document.elementsByTagName("westley").at(0);
+                    QDomNode westley = m_document.elementsByTagName("westley").at(0);
 
                     QString profilePath = infoXml.attribute("profile");
                     QString projectFolderPath = infoXml.attribute("projectfolder");
@@ -95,6 +109,7 @@ KdenliveDoc::KdenliveDoc(const KUrl &url, const KUrl &projectFolder, QUndoGroup
                     }
                     m_startPos = infoXml.attribute("position").toInt();
                     m_zoom = infoXml.attribute("zoom", "7").toInt();
+                    m_zoneStart = infoXml.attribute("zonein", "0").toInt();
                     m_zoneEnd = infoXml.attribute("zoneout", "100").toInt();
                     setProfilePath(profilePath);
 
@@ -118,9 +133,9 @@ KdenliveDoc::KdenliveDoc(const KUrl &url, const KUrl &projectFolder, QUndoGroup
                         }
                         westley.removeChild(tracksinfo);
                     }
-
                     QDomNodeList producers = m_document.elementsByTagName("producer");
                     QDomNodeList infoproducers = m_document.elementsByTagName("kdenlive_producer");
+                    if (checkDocumentClips(producers, infoproducers) == false) m_abortLoading = true;
                     const int max = producers.count();
                     const int infomax = infoproducers.count();
 
@@ -235,6 +250,8 @@ KdenliveDoc::~KdenliveDoc()
 void KdenliveDoc::setSceneList()
 {
     m_render->setSceneList(m_document.toString(), m_startPos);
+    // m_document xml is now useless, clear it
+    m_document.clear();
     checkProjectClips();
 }
 
@@ -296,7 +313,7 @@ QDomDocument KdenliveDoc::createEmptyDocument(const int videotracks, const int a
         m_tracksList.append(videoTrack);
     }
 
-    for (uint i = 2; i < total ; i++) {
+    for (int i = 2; i < total ; i++) {
         QDomElement transition = doc.createElement("transition");
         transition.setAttribute("always_active", "1");
 
@@ -577,7 +594,7 @@ bool KdenliveDoc::convertDocument(double version)
         } else {
             // convert transition
             QDomNamedNodeMap attrs = tr.attributes();
-            for (unsigned int j = 0; j < attrs.count(); j++) {
+            for (int j = 0; j < attrs.count(); j++) {
                 QString attrName = attrs.item(j).nodeName();
                 if (attrName != "in" && attrName != "out" && attrName != "id") {
                     QDomElement property = m_document.createElement("property");
@@ -993,6 +1010,7 @@ bool KdenliveDoc::saveSceneList(const QString &path, const QString &scene)
 
     QDomElement markers = sceneList.createElement("markers");
     addedXml.setAttribute("version", "0.82");
+    addedXml.setAttribute("kdenliveversion", VERSION);
     addedXml.setAttribute("profile", profilePath());
     addedXml.setAttribute("position", m_render->seekPosition().frames(m_fps));
     addedXml.setAttribute("zonein", m_zoneStart);
@@ -1180,7 +1198,12 @@ void KdenliveDoc::setRenderer(Render *render) {
 
 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 ;
@@ -1193,20 +1216,20 @@ void KdenliveDoc::checkProjectClips()
         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("titlename");
+            //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("titlename", titlename);
+                clip->setProperty("name", titlename);
                 kDebug() << "// New title set to: " << titlename;
             } else {
-                titleresource = TitleWidget::getTitleResourceFromName(projectFolder(), titlename);
+                titleresource = TitleWidget::getFreeTitleInfo(projectFolder()).at(1);
+                //titleresource = TitleWidget::getTitleResourceFromName(projectFolder(), titlename);
             }
-            QString titlepath = projectFolder().path() + "/titles/";
-            TitleWidget *dia_ui = new TitleWidget(KUrl(), titlepath, m_render, kapp->activeWindow());
+            TitleWidget *dia_ui = new TitleWidget(KUrl(), KUrl(titleresource).directory(), m_render, kapp->activeWindow());
             QDomDocument doc;
             doc.setContent(clip->getProperty("xmldata"));
             dia_ui->setXml(doc);
@@ -1258,34 +1281,6 @@ QString KdenliveDoc::producerName(const QString &id)
     return result;
 }
 
-void KdenliveDoc::setProducerDuration(const QString &id, int duration)
-{
-    QDomNodeList prods = producersList();
-    int ct = prods.count();
-    for (int i = 0; i <  ct ; i++) {
-        QDomElement e = prods.item(i).toElement();
-        if (e.attribute("id") != "black" && e.attribute("id") == id) {
-            e.setAttribute("duration", QString::number(duration));
-            break;
-        }
-    }
-}
-
-int KdenliveDoc::getProducerDuration(const QString &id)
-{
-    int result = 0;
-    QDomNodeList prods = producersList();
-    int ct = prods.count();
-    for (int i = 0; i <  ct ; i++) {
-        QDomElement e = prods.item(i).toElement();
-        if (e.attribute("id") != "black" && e.attribute("id") == id) {
-            result = e.attribute("duration").toInt();
-            break;
-        }
-    }
-    return result;
-}
-
 QDomDocument KdenliveDoc::toXml()
 {
     return m_document;
@@ -1361,6 +1356,7 @@ 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) {
         elem.setAttribute("id", producerId);
         QString path = elem.attribute("resource");
@@ -1369,29 +1365,31 @@ void KdenliveDoc::addClip(QDomElement elem, QString clipId, bool createClipItem)
             extension = KUrl(path).fileName();
             path = KUrl(path).directory();
         } else if (elem.attribute("type").toInt() == TEXT && QFile::exists(path) == false) {
-            kDebug() << "// TITLE: " << elem.attribute("titlename") << " Preview file: " << elem.attribute("resource") << " DOES NOT EXIST";
-            QString titlename = elem.attribute("titlename");
+            kDebug() << "// TITLE: " << elem.attribute("name") << " Preview file: " << elem.attribute("resource") << " DOES NOT EXIST";
+            QString titlename = elem.attribute("name");
             QString titleresource;
             if (titlename.isEmpty()) {
                 QStringList titleInfo = TitleWidget::getFreeTitleInfo(projectFolder());
                 titlename = titleInfo.at(0);
                 titleresource = titleInfo.at(1);
-                elem.setAttribute("titlename", titlename);
+                elem.setAttribute("name", titlename);
                 kDebug() << "// New title set to: " << titlename;
             } else {
-                titleresource = TitleWidget::getTitleResourceFromName(projectFolder(), titlename);
+                titleresource = TitleWidget::getFreeTitleInfo(projectFolder()).at(1);
+                //titleresource = TitleWidget::getTitleResourceFromName(projectFolder(), titlename);
             }
-            QString titlepath = projectFolder().path() + "/titles/";
-            TitleWidget *dia_ui = new TitleWidget(KUrl(), titlepath, m_render, kapp->activeWindow());
+            TitleWidget *dia_ui = new TitleWidget(KUrl(), KUrl(titleresource).directory(), m_render, kapp->activeWindow());
             QDomDocument doc;
             doc.setContent(elem.attribute("xmldata"));
             dia_ui->setXml(doc);
             QImage pix = dia_ui->renderedPixmap();
             pix.save(titleresource);
             elem.setAttribute("resource", titleresource);
+            setNewClipResource(clipId, titleresource);
             delete dia_ui;
         }
-        if (path.isEmpty() == false && QFile::exists(path) == false && elem.attribute("type").toInt() != TEXT) {
+
+        if (path.isEmpty() == false && QFile::exists(path) == false && elem.attribute("type").toInt() != TEXT && !elem.hasAttribute("placeholder")) {
             kDebug() << "// FOUND MISSING CLIP: " << path << ", TYPE: " << elem.attribute("type").toInt();
             const QString size = elem.attribute("file_size");
             const QString hash = elem.attribute("file_hash");
@@ -1405,17 +1403,17 @@ void KdenliveDoc::addClip(QDomElement elem, QString clipId, bool createClipItem)
                     int res = KMessageBox::questionYesNoCancel(kapp->activeWindow(), i18n("Clip <b>%1</b><br>is invalid or missing, what do you want to do?", path), i18n("File not found"), KGuiItem(i18n("Search manually")), KGuiItem(i18n("Keep as placeholder")));
                     if (res == KMessageBox::Yes)
                         newpath = KFileDialog::getExistingDirectory(KUrl("kfiledialog:///clipfolder"), kapp->activeWindow(), i18n("Looking for %1", path));
-                    else if (res == KMessageBox::Cancel) {
+                    else {
                         // Abort project loading
-                        action = KMessageBox::Cancel;
+                        action = res;
                     }
                 } else {
                     int res = KMessageBox::questionYesNoCancel(kapp->activeWindow(), i18n("Clip <b>%1</b><br>is invalid or missing, what do you want to do?", path), i18n("File not found"), KGuiItem(i18n("Search manually")), KGuiItem(i18n("Keep as placeholder")));
                     if (res == KMessageBox::Yes)
                         newpath = KFileDialog::getOpenFileName(KUrl("kfiledialog:///clipfolder"), QString(), kapp->activeWindow(), i18n("Looking for %1", path));
-                    else if (res == KMessageBox::Cancel) {
+                    else {
                         // Abort project loading
-                        action = KMessageBox::Cancel;
+                        action = res;
                     }
                 }
             }
@@ -1428,6 +1426,9 @@ void KdenliveDoc::addClip(QDomElement elem, QString clipId, bool createClipItem)
             } else if (action == KMessageBox::Cancel) {
                 m_abortLoading = true;
                 return;
+            } else if (action == KMessageBox::No) {
+                // Keep clip as placeHolder
+                elem.setAttribute("placeholder", '1');
             }
             if (!newpath.isEmpty()) {
                 if (elem.attribute("type").toInt() == SLIDESHOW) newpath.append('/' + extension);
@@ -1514,7 +1515,7 @@ void KdenliveDoc::addClipInfo(QDomElement elem, QDomElement orig, QString clipId
         QMap <QString, QString> properties;
         QDomNamedNodeMap attributes = elem.attributes();
         QString attrname;
-        for (unsigned int i = 0; i < attributes.count(); i++) {
+        for (int i = 0; i < attributes.count(); i++) {
             attrname = attributes.item(i).nodeName();
             if (attrname != "resource")
                 properties.insert(attrname, attributes.item(i).nodeValue());
@@ -1678,5 +1679,30 @@ QString KdenliveDoc::getLadspaFile() const
     return m_projectFolder.path() + "/ladspa/" + counter + ".ladspa";
 }
 
+bool KdenliveDoc::checkDocumentClips(QDomNodeList producers, QDomNodeList infoproducers)
+{
+    int clipType;
+    QDomElement e;
+    QString id;
+    QString resource;
+    QList <QDomElement> missingClips;
+    for (int i = 0; i < infoproducers.count(); i++) {
+        e = infoproducers.item(i).toElement();
+        clipType = e.attribute("type").toInt();
+        if (clipType == TEXT || clipType == COLOR) 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);
+        }
+    }
+    if (missingClips.isEmpty()) return true;
+    DocumentChecker d(producers, infoproducers, missingClips, m_document);
+    return (d.exec() == QDialog::Accepted);
+}
+
+
 #include "kdenlivedoc.moc"