]> git.sesse.net Git - kdenlive/blobdiff - src/kdenlivedoc.cpp
Start of the new document checker (check for missing clips,...) not fully functionnal yet
[kdenlive] / src / kdenlivedoc.cpp
index 4a920cc40475accc3b746a09362857cf58dc626b..eb12c9f4a183d5dc16138a1e726acc8cc7701c87 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);
@@ -95,6 +110,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,7 +134,7 @@ KdenliveDoc::KdenliveDoc(const KUrl &url, const KUrl &projectFolder, QUndoGroup
                         }
                         westley.removeChild(tracksinfo);
                     }
-
+                    checkDocumentClips();
                     QDomNodeList producers = m_document.elementsByTagName("producer");
                     QDomNodeList infoproducers = m_document.elementsByTagName("kdenlive_producer");
                     const int max = producers.count();
@@ -235,6 +251,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 +314,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 +595,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 +1011,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 +1199,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 +1217,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 +1282,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 +1357,7 @@ void KdenliveDoc::addClip(QDomElement elem, QString clipId, bool createClipItem)
 {
     const QString producerId = clipId.section('_', 0, 0);
     DocClipBase *clip = m_clipManager->getClipById(producerId);
+    bool placeHolder = false;
     if (clip == NULL) {
         elem.setAttribute("id", producerId);
         QString path = elem.attribute("resource");
@@ -1369,28 +1366,30 @@ 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) {
             kDebug() << "// FOUND MISSING CLIP: " << path << ", TYPE: " << elem.attribute("type").toInt();
             const QString size = elem.attribute("file_size");
@@ -1405,17 +1404,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 +1427,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
+                placeHolder = true;
             }
             if (!newpath.isEmpty()) {
                 if (elem.attribute("type").toInt() == SLIDESHOW) newpath.append('/' + extension);
@@ -1436,7 +1438,7 @@ void KdenliveDoc::addClip(QDomElement elem, QString clipId, bool createClipItem)
                 setModified(true);
             }
         }
-        clip = new DocClipBase(m_clipManager, elem, producerId);
+        clip = new DocClipBase(m_clipManager, elem, producerId, placeHolder);
         m_clipManager->addClip(clip);
     }
 
@@ -1514,7 +1516,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 +1680,12 @@ QString KdenliveDoc::getLadspaFile() const
     return m_projectFolder.path() + "/ladspa/" + counter + ".ladspa";
 }
 
+void KdenliveDoc::checkDocumentClips()
+{
+    DocumentChecker d(m_document);
+    d.exec();
+}
+
+
 #include "kdenlivedoc.moc"