]> git.sesse.net Git - kdenlive/commitdiff
Fix loading & saving of markers, some indent fixes
authorJean-Baptiste Mardelle <jb@kdenlive.org>
Tue, 27 May 2008 23:25:27 +0000 (23:25 +0000)
committerJean-Baptiste Mardelle <jb@kdenlive.org>
Tue, 27 May 2008 23:25:27 +0000 (23:25 +0000)
svn path=/branches/KDE4/; revision=2201

src/customtrackview.cpp
src/kdenlivedoc.cpp
src/kdenlivedoc.h
src/mainwindow.cpp
src/mainwindow.h
src/trackview.cpp

index a95a0798228b240b20877929d1bcf1cafcbf3d2b..3997b9f26758fd410d6f627142447f96793de833 100644 (file)
@@ -926,7 +926,7 @@ void CustomTrackView::cutSelectedClips() {
 
 void CustomTrackView::addClip(QDomElement xml, int clipId, ItemInfo info) {
     DocClipBase *baseclip = m_document->clipManager()->getClipById(clipId);
-       int crop = xml.attribute("in").toInt();
+    int crop = xml.attribute("in").toInt();
     ClipItem *item = new ClipItem(baseclip, info, GenTime(crop, m_document->fps()), m_scale, m_document->fps());
     scene()->addItem(item);
     baseclip->addReference();
@@ -1132,9 +1132,9 @@ void CustomTrackView::slotAddClipMarker() {
 void CustomTrackView::addMarker(const int id, const GenTime &pos, const QString comment) {
     DocClipBase *base = m_document->clipManager()->getClipById(id);
     if (!comment.isEmpty()) base->addSnapMarker(pos, comment);
-       else base->deleteSnapMarker(pos);
-       m_document->setModified(true);
-       viewport()->update();
+    else base->deleteSnapMarker(pos);
+    m_document->setModified(true);
+    viewport()->update();
 }
 
 void CustomTrackView::setTool(PROJECTTOOL tool) {
index 03d06d49836c131556fb26bc1f35455be89c011e..5ca0b7abc5881d77371dfe2a452a3411fe7272c1 100644 (file)
@@ -45,45 +45,65 @@ KdenliveDoc::KdenliveDoc(const KUrl &url, const KUrl &projectFolder, MltVideoPro
             m_document.setContent(&file, false);
             file.close();
             QDomNode infoXmlNode = m_document.elementsByTagName("kdenlivedoc").at(0);
+            QDomNode westley = m_document.elementsByTagName("westley").at(0);
             if (!infoXmlNode.isNull()) {
                 QDomElement infoXml = infoXmlNode.toElement();
                 QString profilePath = infoXml.attribute("profile");
                 if (!profilePath.isEmpty()) setProfilePath(profilePath);
                 double version = infoXml.attribute("version").toDouble();
                 if (version < 0.7) convertDocument(version);
-                QDomNodeList producers = m_document.elementsByTagName("producer");
+                else {
+                    //delete all mlt producers and instead, use Kdenlive saved producers
+                    QDomNodeList prods = m_document.elementsByTagName("producer");
+                    int maxprod = prods.count();
+                    int pos = 0;
+                    for (int i = 0; i < maxprod; i++) {
+                        QDomNode m = prods.at(pos);
+                        if (m.toElement().attribute("id") == "black")
+                            pos = 1;
+                        else westley.removeChild(m);
+                    }
+                    prods = m_document.elementsByTagName("kdenlive_producer");
+                    maxprod = prods.count();
+                    for (int i = 0; i < maxprod; i++) {
+                        prods.at(0).toElement().setTagName("producer");
+                        westley.insertBefore(prods.at(0), QDomNode());
+                    }
+                }
                 QDomElement e;
-                               const int max = producers.count();
-                               if (max > 0) {
-                                       m_documentLoadingStep = 100.0 / (max + m_document.elementsByTagName("entry").count());
-                                       parent->slotGotProgressInfo(i18n("Loading project clips"), (int) m_documentLoadingProgress);
-                               }
+                QDomNodeList producers = m_document.elementsByTagName("producer");
+                const int max = producers.count();
+                if (max > 0) {
+                    m_documentLoadingStep = 100.0 / (max + m_document.elementsByTagName("entry").count());
+                    parent->slotGotProgressInfo(i18n("Loading project clips"), (int) m_documentLoadingProgress);
+                }
 
                 for (int i = 0; i < max; i++) {
                     e = producers.item(i).cloneNode().toElement();
-                                       if (m_documentLoadingStep > 0) {
-                                               m_documentLoadingProgress += m_documentLoadingStep;
-                                               parent->slotGotProgressInfo(QString(), (int) m_documentLoadingProgress);
-                                               qApp->processEvents();
-                                       }
+                    if (m_documentLoadingStep > 0) {
+                        m_documentLoadingProgress += m_documentLoadingStep;
+                        parent->slotGotProgressInfo(QString(), (int) m_documentLoadingProgress);
+                        qApp->processEvents();
+                    }
                     if (!e.isNull() && e.attribute("id") != "black") {
                         addClip(e, e.attribute("id").toInt());
                     }
                 }
+
+                QDomNode markers = m_document.elementsByTagName("markers").at(0);
+                if (!markers.isNull()) {
+                    QDomNodeList markerslist = markers.childNodes();
+                    int maxchild = markerslist.count();
+                    for (int k = 0; k < maxchild; k++) {
+                        e = markerslist.at(k).toElement();
+                        if (e.tagName() == "marker") {
+                            int id = e.attribute("id").toInt();
+                            m_clipManager->getClipById(id)->addSnapMarker(GenTime(e.attribute("time").toDouble()), e.attribute("comment"));
+                        }
+                    }
+                    m_document.removeChild(markers);
+                }
                 m_document.removeChild(infoXmlNode);
-                               QDomNode markers = m_document.elementsByTagName("markers").at(0);
-                               if (!markers.isNull()) {
-                                       QDomNodeList markerslist = markers.childNodes();
-                                       int maxchild = markerslist.count();
-                                       for (int k = 0; k < maxchild; k++) {
-                                               e = markerslist.item(k).toElement();
-                                               if (e.tagName() == "marker") {
-                                                       int id = e.attribute("id").toInt();
-                                                       m_clipManager->getClipById(id)->addSnapMarker(GenTime(e.attribute("time").toDouble()), e.attribute("comment"));
-                                               }
-                                       }
-                                       m_document.removeChild(markers);
-                               }
 
                 kDebug() << "Reading file: " << url.path() << ", found clips: " << producers.count();
             } else kWarning() << "  NO KDENLIVE INFO FOUND IN FILE: " << url.path();
@@ -194,7 +214,7 @@ void KdenliveDoc::convertDocument(double version) {
 
     QDomNode props = m_document.elementsByTagName("properties").at(0).toElement();
     QString profile = props.toElement().attribute("videoprofile");
-       if (profile == "dv_wide") profile = "dv_pal_wide";
+    if (profile == "dv_wide") profile = "dv_pal_wide";
     if (!profile.isEmpty()) {
         setProfilePath(profile);
     } else setProfilePath("dv_pal");
@@ -247,31 +267,31 @@ void KdenliveDoc::convertDocument(double version) {
         tractor.insertAfter(transitions.at(0), QDomNode());
     }
 
-       QDomElement markers = m_document.createElement("markers");
+    QDomElement markers = m_document.createElement("markers");
 
     // change producer names
     QDomNodeList producers = m_document.elementsByTagName("producer");
     max = producers.count();
     for (int i = 0; i < max; i++) {
         QDomElement prod = producers.at(0).toElement();
-               QDomNode m = prod.firstChild();
-               if (!m.isNull() && m.toElement().tagName() == "markers") {
-                       QDomNodeList prodchilds = m.childNodes();
-                       int maxchild = prodchilds.count();
-                       for (int k = 0; k < maxchild; k++) {
-                               QDomElement mark = prodchilds.at(0).toElement();
-                               mark.setAttribute("id", prod.attribute("id"));
-                               markers.insertAfter(mark, QDomNode());
-                       }
-                       prod.removeChild(m);
-               }
+        QDomNode m = prod.firstChild();
+        if (!m.isNull() && m.toElement().tagName() == "markers") {
+            QDomNodeList prodchilds = m.childNodes();
+            int maxchild = prodchilds.count();
+            for (int k = 0; k < maxchild; k++) {
+                QDomElement mark = prodchilds.at(0).toElement();
+                mark.setAttribute("id", prod.attribute("id"));
+                markers.insertAfter(mark, QDomNode());
+            }
+            prod.removeChild(m);
+        }
         int duration = prod.attribute("duration").toInt();
         if (duration > 0) prod.setAttribute("out", QString::number(duration));
         westley.insertBefore(prod, QDomNode());
     }
 
     QDomNode westley0 = m_document.elementsByTagName("westley").at(0);
-       if (!markers.firstChild().isNull()) westley0.appendChild(markers);
+    if (!markers.firstChild().isNull()) westley0.appendChild(markers);
     westley0.removeChild(kdenlivedoc);
 
     QDomNodeList elements = westley.childNodes();
@@ -283,7 +303,7 @@ void KdenliveDoc::convertDocument(double version) {
 
     westley0.removeChild(westley);
 
-    kDebug() << "/////////////////  CONVERTED DOC:";
+    //kDebug() << "/////////////////  CONVERTED DOC:";
     //kDebug() << m_document.toString();
     //kDebug() << "/////////////////  END CONVERTED DOC:";
 }
@@ -292,6 +312,7 @@ QDomElement KdenliveDoc::documentInfoXml() {
     QDomDocument doc;
     QDomElement e;
     QDomElement addedXml = doc.createElement("kdenlivedoc");
+    QDomElement markers = doc.createElement("markers");
     addedXml.setAttribute("version", "0.7");
     addedXml.setAttribute("profile", profilePath());
     QList <DocClipBase*> list = m_clipManager->documentClipList();
@@ -299,8 +320,16 @@ QDomElement KdenliveDoc::documentInfoXml() {
         e = list.at(i)->toXML();
         e.setTagName("kdenlive_producer");
         addedXml.appendChild(doc.importNode(e, true));
+        QList < CommentedTime > marks = list.at(i)->commentedSnapMarkers();
+        for (int j = 0; j < marks.count(); j++) {
+            QDomElement marker = doc.createElement("marker");
+            marker.setAttribute("time", marks.at(j).time().ms() / 1000);
+            marker.setAttribute("comment", marks.at(j).comment());
+            marker.setAttribute("id", e.attribute("id"));
+            markers.appendChild(marker);
+        }
     }
-
+    addedXml.appendChild(markers);
     //kDebug() << m_document.toString();
     return addedXml;
 }
@@ -340,8 +369,8 @@ void KdenliveDoc::setThumbsProgress(const QString &message, int progress) {
 }
 
 void KdenliveDoc::loadingProgressed() {
-       m_documentLoadingProgress += m_documentLoadingStep;
-       emit progressInfo(QString(), (int) m_documentLoadingProgress);
+    m_documentLoadingProgress += m_documentLoadingStep;
+    emit progressInfo(QString(), (int) m_documentLoadingProgress);
 }
 
 KUndoStack *KdenliveDoc::commandStack() {
index 0e50bd19de1e966966e6a018530ab4ebaa50dfd3..0a612440b72524a5149e562f1b2601c0ce073917 100644 (file)
@@ -93,8 +93,8 @@ Q_OBJECT public:
     bool isModified() const;
     /** Returns project folder, used to store project files (titles, effects,...) */
     KUrl projectFolder() const;
-       /** Used to inform main app of the current document loading progress */
-       void loadingProgressed();
+    /** Used to inform main app of the current document loading progress */
+    void loadingProgressed();
 private:
     KUrl m_url;
     QDomDocument m_document;
@@ -113,8 +113,8 @@ private:
     bool m_modified;
     /** Project folder, used to store project files (titles, effects,...) */
     KUrl m_projectFolder;
-       double m_documentLoadingStep;
-       double m_documentLoadingProgress;
+    double m_documentLoadingStep;
+    double m_documentLoadingProgress;
     void convertDocument(double version);
 
 public slots:
index 97daf70f9170888ecaf6c74bcf8fa6ff1cc4f10d..78a99d8518950b506357cb22e0cc042bce003595 100644 (file)
@@ -576,16 +576,15 @@ void MainWindow::newFile() {
     TrackView *trackView = new TrackView(doc, this);
     m_timelineArea->addTab(trackView, KIcon("kdenlive"), i18n("Untitled") + " / " + prof.description);
     if (m_timelineArea->count() == 1) {
-               connectDocumentInfo(doc);
+        connectDocumentInfo(doc);
         connectDocument(trackView, doc);
-       }
-    else m_timelineArea->setTabBarHidden(false);
+    } else m_timelineArea->setTabBarHidden(false);
 }
 
 void MainWindow::activateDocument() {
     TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
     KdenliveDoc *currentDoc = currentTab->document();
-       connectDocumentInfo(currentDoc);
+    connectDocumentInfo(currentDoc);
     connectDocument(currentTab, currentDoc);
 }
 
@@ -641,12 +640,12 @@ void MainWindow::openFile(const KUrl &url) { //new
     MltVideoProfile prof = ProfilesDialog::getVideoProfile(KdenliveSettings::default_profile());
     if (prof.width == 0) prof = ProfilesDialog::getVideoProfile("dv_pal");
     KdenliveDoc *doc = new KdenliveDoc(url, KUrl(), prof, m_commandStack, this);
-       connectDocumentInfo(doc);
+    connectDocumentInfo(doc);
     TrackView *trackView = new TrackView(doc, this);
     m_timelineArea->setCurrentIndex(m_timelineArea->addTab(trackView, KIcon("kdenlive"), doc->description()));
     m_timelineArea->setTabToolTip(m_timelineArea->currentIndex(), doc->url().path());
     if (m_timelineArea->count() > 1) m_timelineArea->setTabBarHidden(false);
-       slotGotProgressInfo(QString(), -1);
+    slotGotProgressInfo(QString(), -1);
     //connectDocument(trackView, doc);
 }
 
@@ -789,8 +788,8 @@ void MainWindow::connectDocumentInfo(KdenliveDoc *doc) {
     if (m_activeDocument) {
         if (m_activeDocument == doc) return;
         disconnect(m_activeDocument, SIGNAL(progressInfo(const QString &, int)), this, SLOT(slotGotProgressInfo(const QString &, int)));
-       }
-       connect(doc, SIGNAL(progressInfo(const QString &, int)), this, SLOT(slotGotProgressInfo(const QString &, int)));
+    }
+    connect(doc, SIGNAL(progressInfo(const QString &, int)), this, SLOT(slotGotProgressInfo(const QString &, int)));
 }
 
 void MainWindow::connectDocument(TrackView *trackView, KdenliveDoc *doc) { //changed
index 78c56391e0d7b39d7946587811bb328be259df8f..ac499b23028348ba1dbf8c948196d5084c8172de 100644 (file)
@@ -131,7 +131,7 @@ private:
     void saveOptions();
     void activateShuttleDevice();
     void slotShuttleAction(int code);
-       void connectDocumentInfo(KdenliveDoc *doc);
+    void connectDocumentInfo(KdenliveDoc *doc);
 
 public slots:
     void openFile(const KUrl &url);
index 43843046e259ea7f348e9e5db3486dcb346013f2..1e4dc407ac2c66fe0d7acf6f9e7eb0966c5b9f68 100644 (file)
@@ -136,7 +136,7 @@ void TrackView::parseDocument(QDomDocument doc) {
     QDomElement e;
     QDomElement p;
     bool videotrack;
-    
+
     int pos = m_projectTracks - 1;
 
     for (int i = 0; i < m_projectTracks; i++) {
@@ -155,17 +155,17 @@ void TrackView::parseDocument(QDomDocument doc) {
             //kDebug() << " PRO DUR: " << trackduration << ", TRACK DUR: " << duration;
             if (trackduration > duration) duration = trackduration;
         } else {
-                       // background black track
+            // background black track
             for (int j = 0; j < m_projectTracks; j++) {
                 p = playlists.item(j).toElement();
                 if (p.attribute("id") == playlist_name) break;
             }
-                       int black_clips = p.childNodes().count();
-                       for (int i = 0; i < black_clips; i++)
-                               m_doc->loadingProgressed();
-                       qApp->processEvents();
-                       pos--;
-               }
+            int black_clips = p.childNodes().count();
+            for (int i = 0; i < black_clips; i++)
+                m_doc->loadingProgressed();
+            qApp->processEvents();
+            pos--;
+        }
     }
 
     // parse transitions
@@ -294,8 +294,8 @@ int TrackView::slotAddProjectTrack(int ix, QDomElement xml, bool videotrack) {
         if (elem.tagName() == "blank") {
             position += elem.attribute("length").toInt();
         } else if (elem.tagName() == "entry") {
-                       m_doc->loadingProgressed();
-                       qApp->processEvents();
+            m_doc->loadingProgressed();
+            qApp->processEvents();
             // Found a clip
             int in = elem.attribute("in").toInt();
             int id = elem.attribute("producer").toInt();