]> git.sesse.net Git - kdenlive/blobdiff - src/kdenlivedoc.cpp
folders in project view
[kdenlive] / src / kdenlivedoc.cpp
index 72da064542b79dd9dcff56a9135798d75ebd37c4..06f6ff229424f0861af1332e3051ff0087c73710 100644 (file)
 
 #include "kdenlivedoc.h"
 #include "docclipbase.h"
-
-KdenliveDoc::KdenliveDoc(const KUrl &url, double fps, int width, int height, QWidget *parent): QObject(parent), m_render(NULL), m_url(url), m_fps(fps), m_width(width), m_height(height), m_projectName(NULL), m_commandStack(new KUndoStack()) {
+#include "profilesdialog.h"
+#include "kdenlivesettings.h"
+#include "renderer.h"
+#include "clipmanager.h"
+#include "addfoldercommand.h"
+#include "editfoldercommand.h"
+
+KdenliveDoc::KdenliveDoc(const KUrl &url, MltVideoProfile profile, QUndoGroup *undoGroup, QWidget *parent): QObject(parent), m_render(NULL), m_url(url), m_profile(profile), m_fps((double)profile.frame_rate_num / profile.frame_rate_den), m_width(profile.width), m_height(profile.height), m_commandStack(new KUndoStack(undoGroup)), m_modified(false) {
     m_clipManager = new ClipManager(this);
     if (!url.isEmpty()) {
         QString tmpFile;
@@ -36,7 +42,12 @@ KdenliveDoc::KdenliveDoc(const KUrl &url, double fps, int width, int height, QWi
             QFile file(tmpFile);
             m_document.setContent(&file, false);
             file.close();
-            m_projectName = url.fileName();
+            QDomNode infoXmlNode = m_document.elementsByTagName("kdenlive").at(0);
+            if (!infoXmlNode.isNull()) {
+                QDomElement infoXml = infoXmlNode.toElement();
+                QString profilePath = infoXml.attribute("profile");
+                if (!profilePath.isEmpty()) setProfilePath(profilePath);
+            }
             KIO::NetAccess::removeTempFile(tmpFile);
         } else {
             KMessageBox::error(parent, KIO::NetAccess::lastErrorString());
@@ -60,6 +71,7 @@ KdenliveDoc::KdenliveDoc(const KUrl &url, double fps, int width, int height, QWi
 
 
         QDomElement tractor = m_document.createElement("tractor");
+        tractor.setAttribute("id", "maintractor");
         QDomElement multitrack = m_document.createElement("multitrack");
         QDomElement playlist = m_document.createElement("playlist");
         QDomElement producer = m_document.createElement("producer");
@@ -97,12 +109,21 @@ KdenliveDoc::KdenliveDoc(const KUrl &url, double fps, int width, int height, QWi
             transition.setAttribute("combine", "1");
             tractor.appendChild(transition);
         }
-
+        QDomElement playlistmain = m_document.createElement("playlist");
+        playlistmain.setAttribute("id", "playlistmain");
+        QDomElement playentry = m_document.createElement("entry");
+        playentry.setAttribute("producer", "maintractor");
+        playentry.setAttribute("in", "0");
+        playentry.setAttribute("out", "15000");
+        playlistmain.appendChild(playentry);
         doc.appendChild(tractor);
+        doc.appendChild(playlistmain);
 
     }
-    if (fps == 30000.0 / 1001.0) m_timecode.setFormat(30, true);
-    else m_timecode.setFormat((int) fps);
+    m_scenelist = m_document.toString();
+    kDebug() << "scenelist" << m_scenelist;
+    if (m_fps == 30000.0 / 1001.0) m_timecode.setFormat(30, true);
+    else m_timecode.setFormat((int) m_fps);
 }
 
 KdenliveDoc::~KdenliveDoc() {
@@ -110,10 +131,40 @@ KdenliveDoc::~KdenliveDoc() {
     delete m_clipManager;
 }
 
+QDomElement KdenliveDoc::documentInfoXml() {
+    //QDomDocument doc;
+    QDomElement addedXml = m_document.createElement("kdenlive");
+    addedXml.setAttribute("version", "0.7");
+    addedXml.setAttribute("profile", profilePath());
+    kDebug() << m_document.toString();
+    return m_document.documentElement();
+}
+
+
 ClipManager *KdenliveDoc::clipManager() {
     return m_clipManager;
 }
 
+QString KdenliveDoc::getDocumentStandard() {
+    //WARNING: this way to tell the video standard is a bit hackish...
+    if (m_profile.description.contains("pal", Qt::CaseInsensitive) || m_profile.description.contains("25", Qt::CaseInsensitive) || m_profile.description.contains("50", Qt::CaseInsensitive)) return "PAL";
+    return "NTSC";
+}
+
+QString KdenliveDoc::profilePath() const {
+    return m_profile.path;
+}
+
+void KdenliveDoc::setProfilePath(QString path) {
+    KdenliveSettings::setCurrent_profile(path);
+    m_profile = ProfilesDialog::getVideoProfile(path);
+    m_fps = (double) m_profile.frame_rate_num / m_profile.frame_rate_den;
+    m_width = m_profile.width;
+    m_height = m_profile.height;
+    if (m_fps == 30000.0 / 1001.0) m_timecode.setFormat(30, true);
+    else m_timecode.setFormat((int) m_fps);
+}
+
 void KdenliveDoc::setThumbsProgress(KUrl url, int progress) {
     emit thumbsProgress(url, progress);
 }
@@ -124,7 +175,7 @@ KUndoStack *KdenliveDoc::commandStack() {
 
 void KdenliveDoc::setRenderer(Render *render) {
     m_render = render;
-    if (m_render) m_render->setSceneList(m_document);
+    if (m_render) m_render->setSceneList(m_scenelist);
 }
 
 Render *KdenliveDoc::renderer() {
@@ -188,72 +239,85 @@ QDomDocument KdenliveDoc::generateSceneList() {
     QDomElement prod = doc.createElement("producer");
 }
 
-QDomDocument KdenliveDoc::toXml() {
+QDomDocument KdenliveDoc::toXml() const {
     return m_document;
 }
 
-Timecode KdenliveDoc::timecode() {
+Timecode KdenliveDoc::timecode() const {
     return m_timecode;
 }
 
-QString KdenliveDoc::documentName() {
-    return m_projectName;
-}
-
 QDomNodeList KdenliveDoc::producersList() {
     return m_document.elementsByTagName("producer");
 }
 
-void KdenliveDoc::setProducers(QDomElement doc) {
-    QDomNode kdenlivedocument = m_document.elementsByTagName("kdenlivedoc").item(0);
-
-    QDomNodeList list = m_document.elementsByTagName("producer");
-    int ct = list.count();
-    kDebug() << "DELETING CHILD PRODUCERS: " << ct;
-    for (int i = ct; i > 0; i--) {
-        kdenlivedocument.removeChild(list.item(i));
-    }
-
-    QDomNode n = doc.firstChild();
-    ct = 0;
-    while (!n.isNull()) {
-        QDomElement e = n.toElement(); // try to convert the node to an element.
-        if (!e.isNull() && e.tagName() == "producer") {
-            kdenlivedocument.appendChild(m_document.importNode(e, true));
-            ct++;
-        }
-        n = n.nextSibling();
-    }
-    kDebug() << "ADDING CHILD PRODS: " << ct << "\n";
-    //kDebug()<<m_document.toString();
+void KdenliveDoc::backupMltPlaylist() {
+    if (m_render) m_scenelist = m_render->sceneList();
 }
 
-double KdenliveDoc::fps() {
+double KdenliveDoc::fps() const {
     return m_fps;
 }
 
-int KdenliveDoc::width() {
+int KdenliveDoc::width() const {
     return m_width;
 }
 
-int KdenliveDoc::height() {
+int KdenliveDoc::height() const {
     return m_height;
 }
 
-KUrl KdenliveDoc::url() {
+KUrl KdenliveDoc::url() const {
     return m_url;
 }
 
+void KdenliveDoc::setUrl(KUrl url) {
+    m_url = url;
+}
+
+void KdenliveDoc::setModified(bool mod) {
+    if (mod == m_modified) return;
+    m_modified = mod;
+    emit docModified(m_modified);
+}
+
+QString KdenliveDoc::description() const {
+    if (m_url.isEmpty())
+        return i18n("Untitled") + " / " + m_profile.description;
+    else
+        return m_url.fileName() + " / " + m_profile.description;
+}
+
 void KdenliveDoc::addClip(const QDomElement &elem, const int clipId) {
-    kDebug() << "/////////  DOCUM, CREATING NEW CLIP, ID:" << clipId;
     DocClipBase *clip = new DocClipBase(m_clipManager, elem, clipId);
+    kDebug() << "/////////  DOCUM, CREATING NEW CLIP, ID:" << clipId << ", PAR ID:" << elem.attribute("groupid");
     m_clipManager->addClip(clip);
     emit addProjectClip(clip);
 }
 
-void KdenliveDoc::deleteProjectClip(const uint clipId) {
-    emit deletTimelineClip(clipId);
-    m_clipManager->slotDeleteClip(clipId);
+void KdenliveDoc::addFolder(const QString foldername, int clipId, bool edit) {
+    emit addProjectFolder(foldername, clipId, false, edit);
+}
+
+void KdenliveDoc::deleteFolder(const QString foldername, int clipId) {
+    emit addProjectFolder(foldername, clipId, true);
+}
+
+void KdenliveDoc::deleteProjectClip(QList <int> ids) {
+    for (int i = 0; i < ids.size(); ++i) {
+        emit deletTimelineClip(ids.at(i));
+        m_clipManager->slotDeleteClip(ids.at(i));
+    }
+    setModified(true);
+}
+
+void KdenliveDoc::deleteProjectFolder(QMap <QString, int> map) {
+    QMapIterator<QString, int> i(map);
+    while (i.hasNext()) {
+        i.next();
+        slotDeleteFolder(i.key(), i.value());
+    }
+    setModified(true);
 }
 
 void KdenliveDoc::deleteClip(const uint clipId) {
@@ -261,17 +325,41 @@ void KdenliveDoc::deleteClip(const uint clipId) {
     m_clipManager->deleteClip(clipId);
 }
 
-void KdenliveDoc::slotAddClipFile(const KUrl url, const QString group) {
+void KdenliveDoc::slotAddClipFile(const KUrl url, const QString group, const int groupId) {
     kDebug() << "/////////  DOCUM, ADD CLP: " << url;
-    m_clipManager->slotAddClipFile(url, group);
+    m_clipManager->slotAddClipFile(url, group, groupId);
+    setModified(true);
+}
+
+void KdenliveDoc::slotAddFolder(const QString folderName) {
+    AddFolderCommand *command = new AddFolderCommand(this, folderName, m_clipManager->getFreeClipId(), true);
+    commandStack()->push(command);
+    setModified(true);
+}
+
+void KdenliveDoc::slotDeleteFolder(const QString folderName, const int id) {
+    AddFolderCommand *command = new AddFolderCommand(this, folderName, id, false);
+    commandStack()->push(command);
+    setModified(true);
+}
+
+void KdenliveDoc::slotEditFolder(const QString newfolderName, const QString oldfolderName, int clipId) {
+    EditFolderCommand *command = new EditFolderCommand(this, newfolderName, oldfolderName, clipId, false);
+    commandStack()->push(command);
+    setModified(true);
+}
+
+int KdenliveDoc::getFreeClipId() {
+    return m_clipManager->getFreeClipId();
 }
 
 DocClipBase *KdenliveDoc::getBaseClip(int clipId) {
     return m_clipManager->getClipById(clipId);
 }
 
-void KdenliveDoc::slotAddColorClipFile(const QString name, const QString color, QString duration, const QString group) {
-    m_clipManager->slotAddColorClipFile(name, color, duration, group);
+void KdenliveDoc::slotAddColorClipFile(const QString name, const QString color, QString duration, const QString group, const int groupId) {
+    m_clipManager->slotAddColorClipFile(name, color, duration, group, groupId);
+    setModified(true);
 }
 
 #include "kdenlivedoc.moc"