+ delete m_autoSaveTimer;
+ m_autosave->remove();
+}
+
+QDomDocument KdenliveDoc::createEmptyDocument(const int videotracks, const int audiotracks) {
+ // Creating new document
+ QDomDocument doc;
+ QDomElement westley = doc.createElement("westley");
+ doc.appendChild(westley);
+
+ QDomElement tractor = doc.createElement("tractor");
+ tractor.setAttribute("id", "maintractor");
+ QDomElement multitrack = doc.createElement("multitrack");
+ QDomElement playlist = doc.createElement("playlist");
+ playlist.setAttribute("id", "black_track");
+ westley.appendChild(playlist);
+
+
+ // create playlists
+ int total = audiotracks + videotracks + 1;
+
+ for (int i = 1; i < total; i++) {
+ QDomElement playlist = doc.createElement("playlist");
+ playlist.setAttribute("id", "playlist" + QString::number(i));
+ westley.appendChild(playlist);
+ }
+
+ QDomElement track0 = doc.createElement("track");
+ track0.setAttribute("producer", "black_track");
+ tractor.appendChild(track0);
+
+ // create audio tracks
+ for (int i = 1; i < audiotracks + 1; i++) {
+ QDomElement track = doc.createElement("track");
+ track.setAttribute("producer", "playlist" + QString::number(i));
+ track.setAttribute("hide", "video");
+ tractor.appendChild(track);
+ }
+
+ // create video tracks
+ for (int i = audiotracks + 1; i < total; i++) {
+ QDomElement track = doc.createElement("track");
+ track.setAttribute("producer", "playlist" + QString::number(i));
+ tractor.appendChild(track);
+ }
+
+ for (uint i = 2; i < total ; i++) {
+ QDomElement transition = doc.createElement("transition");
+ transition.setAttribute("always_active", "1");
+
+ QDomElement property = doc.createElement("property");
+ property.setAttribute("name", "a_track");
+ QDomText value = doc.createTextNode(QString::number(1));
+ property.appendChild(value);
+ transition.appendChild(property);
+
+ property = doc.createElement("property");
+ property.setAttribute("name", "b_track");
+ value = doc.createTextNode(QString::number(i));
+ property.appendChild(value);
+ transition.appendChild(property);
+
+ property = doc.createElement("property");
+ property.setAttribute("name", "mlt_service");
+ value = doc.createTextNode("mix");
+ property.appendChild(value);
+ transition.appendChild(property);
+
+ property = doc.createElement("property");
+ property.setAttribute("name", "combine");
+ value = doc.createTextNode("1");
+ property.appendChild(value);
+ transition.appendChild(property);
+
+ property = doc.createElement("property");
+ property.setAttribute("name", "internal_added");
+ value = doc.createTextNode("237");
+ property.appendChild(value);
+ transition.appendChild(property);
+ tractor.appendChild(transition);
+ }
+ westley.appendChild(tractor);
+ return doc;
+}
+
+
+void KdenliveDoc::syncGuides(QList <Guide *> guides) {
+ QDomDocument doc;
+ QDomElement e;
+ m_guidesXml.clear();
+ m_guidesXml = doc.createElement("guides");
+
+ for (int i = 0; i < guides.count(); i++) {
+ e = doc.createElement("guide");
+ e.setAttribute("time", guides.at(i)->position().ms() / 1000);
+ e.setAttribute("comment", guides.at(i)->label());
+ m_guidesXml.appendChild(e);
+ }
+ emit guidesUpdated();
+}
+
+QDomElement KdenliveDoc::guidesXml() const {
+ return m_guidesXml;
+}
+
+void KdenliveDoc::slotAutoSave() {
+ if (m_render) {
+ if (!m_autosave->isOpen() && !m_autosave->open(QIODevice::ReadWrite)) {
+ // show error: could not open the autosave file
+ kDebug() << "ERROR; CANNOT CREATE AUTOSAVE FILE";
+ }
+ kDebug() << "// AUTOSAVE FILE: " << m_autosave->fileName();
+ QDomDocument doc;
+ doc.setContent(m_render->sceneList());
+ saveSceneList(m_autosave->fileName(), doc);
+ }
+}
+
+void KdenliveDoc::setZoom(int factor) {
+ m_zoom = factor;
+}
+
+int KdenliveDoc::zoom() const {
+ return m_zoom;
+}
+
+void KdenliveDoc::convertDocument(double version) {
+ // Opening a old Kdenlive document
+ if (version == 0.7) {
+ // TODO: convert 0.7 files to the new document format.
+ return;
+ }
+ QDomNode westley = m_document.elementsByTagName("westley").at(1);
+ QDomNode tractor = m_document.elementsByTagName("tractor").at(0);
+ QDomNode kdenlivedoc = m_document.elementsByTagName("kdenlivedoc").at(0);
+ QDomNode multitrack = m_document.elementsByTagName("multitrack").at(0);
+ QDomNodeList playlists = m_document.elementsByTagName("playlist");
+
+ m_startPos = kdenlivedoc.toElement().attribute("timeline_position").toInt();
+
+ QDomNode props = m_document.elementsByTagName("properties").at(0).toElement();
+ QString profile = props.toElement().attribute("videoprofile");
+ if (profile == "dv_wide") profile = "dv_pal_wide";
+ setProfilePath(profile);
+
+ // move playlists outside of tractor and add the tracks instead
+ int max = playlists.count();
+ for (int i = 0; i < max; i++) {
+ QDomNode n = playlists.at(i);
+ westley.insertBefore(n, QDomNode());
+ QDomElement pl = n.toElement();
+ QDomElement track = m_document.createElement("track");
+ QString trackType = pl.attribute("hide");
+ if (!trackType.isEmpty()) track.setAttribute("hide", trackType);
+ QString playlist_id = pl.attribute("id");
+ if (playlist_id.isEmpty()) {
+ playlist_id = "black_track";
+ pl.setAttribute("id", playlist_id);
+ }
+ track.setAttribute("producer", playlist_id);
+ //tractor.appendChild(track);
+ tractor.insertAfter(track, QDomNode());
+ }
+ tractor.removeChild(multitrack);
+
+ // audio track mixing transitions should not be added to track view, so add required attribute
+ QDomNodeList transitions = m_document.elementsByTagName("transition");
+ max = transitions.count();
+ for (int i = 0; i < max; i++) {
+ QDomElement tr = transitions.at(i).toElement();
+ if (tr.attribute("combine") == "1" && tr.attribute("mlt_service") == "mix") {
+ QDomElement property = m_document.createElement("property");
+ property.setAttribute("name", "internal_added");
+ QDomText value = m_document.createTextNode("237");
+ property.appendChild(value);
+ tr.appendChild(property);
+ } else {
+ // convert transition
+ QDomNamedNodeMap attrs = tr.attributes();
+ for (unsigned 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");
+ property.setAttribute("name", attrName);
+ QDomText value = m_document.createTextNode(attrs.item(j).nodeValue());
+ property.appendChild(value);
+ tr.appendChild(property);
+ }
+ }
+ }
+ }
+
+ // move transitions after tracks
+ for (int i = 0; i < max; i++) {
+ tractor.insertAfter(transitions.at(0), QDomNode());
+ }
+
+ // Fix filters format
+ QDomNodeList entries = m_document.elementsByTagName("entry");
+ max = entries.count();
+ for (int i = 0; i < max; i++) {
+ QString last_id;
+ int effectix = 0;
+ QDomNode m = entries.at(i).firstChild();
+ while (!m.isNull()) {
+ if (m.toElement().tagName() == "filter") {
+ QDomElement filt = m.toElement();
+ QDomNamedNodeMap attrs = filt.attributes();
+ QString current_id = filt.attribute("kdenlive_id");
+ if (current_id != last_id) {
+ effectix++;
+ last_id = current_id;
+ }
+ QDomElement e = m_document.createElement("property");
+ e.setAttribute("name", "kdenlive_ix");
+ QDomText value = m_document.createTextNode(QString::number(effectix));
+ e.appendChild(value);
+ filt.appendChild(e);
+ for (int j = 0; j < attrs.count(); j++) {
+ QDomAttr a = attrs.item(j).toAttr();
+ if (!a.isNull()) {
+ kDebug() << " FILTER; adding :" << a.name() << ":" << a.value();
+ QDomElement e = m_document.createElement("property");
+ e.setAttribute("name", a.name());
+ QDomText value = m_document.createTextNode(a.value());
+ e.appendChild(value);
+ filt.appendChild(e);
+
+ }
+ }
+ }
+ m = m.nextSibling();
+ }
+ }
+
+ /*
+ QDomNodeList filters = m_document.elementsByTagName("filter");
+ max = filters.count();
+ QString last_id;
+ int effectix = 0;
+ for (int i = 0; i < max; i++) {
+ QDomElement filt = filters.at(i).toElement();
+ QDomNamedNodeMap attrs = filt.attributes();
+ QString current_id = filt.attribute("kdenlive_id");
+ if (current_id != last_id) {
+ effectix++;
+ last_id = current_id;
+ }
+ QDomElement e = m_document.createElement("property");
+ e.setAttribute("name", "kdenlive_ix");
+ QDomText value = m_document.createTextNode(QString::number(1));
+ e.appendChild(value);
+ filt.appendChild(e);
+ for (int j = 0; j < attrs.count(); j++) {
+ QDomAttr a = attrs.item(j).toAttr();
+ if (!a.isNull()) {
+ kDebug() << " FILTER; adding :" << a.name() << ":" << a.value();
+ QDomElement e = m_document.createElement("property");
+ e.setAttribute("name", a.name());
+ QDomText value = m_document.createTextNode(a.value());
+ e.appendChild(value);
+ filt.appendChild(e);
+ }
+ }
+ }*/
+
+ // fix slowmotion
+ QDomNodeList producers = westley.toElement().elementsByTagName("producer");
+ max = producers.count();
+ for (int i = 0; i < max; i++) {
+ QDomElement prod = producers.at(i).toElement();
+ if (prod.attribute("mlt_service") == "framebuffer") {
+ QString slowmotionprod = prod.attribute("resource");
+ slowmotionprod.replace(':', '?');
+ kDebug() << "// FOUND WRONG SLOWMO, new: " << slowmotionprod;
+ prod.setAttribute("resource", slowmotionprod);
+ }
+ }
+ // move producers to correct place, markers to a global list, fix clip descriptions
+ QDomElement markers = m_document.createElement("markers");
+ 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()) {
+ if (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);
+ } else if (prod.attribute("type").toInt() == TEXT) {
+ // convert title clip
+ if (m.toElement().tagName() == "textclip") {
+ QDomDocument tdoc;
+ QDomElement titleclip = m.toElement();
+ QDomElement title = tdoc.createElement("kdenlivetitle");
+ tdoc.appendChild(title);
+ QDomNodeList objects = titleclip.childNodes();
+ int maxchild = objects.count();
+ for (int k = 0; k < maxchild; k++) {
+ QString objectxml;
+ QDomElement ob = objects.at(k).toElement();
+ if (ob.attribute("type") == "3") {
+ // text object
+ QDomElement item = tdoc.createElement("item");
+ item.setAttribute("z-index", ob.attribute("z"));
+ item.setAttribute("type", "QGraphicsTextItem");
+ QDomElement position = tdoc.createElement("position");
+ position.setAttribute("x", ob.attribute("x"));
+ position.setAttribute("y", ob.attribute("y"));
+ QDomElement content = tdoc.createElement("content");
+ content.setAttribute("font", ob.attribute("font_family"));
+ content.setAttribute("font-size", ob.attribute("font_size"));
+ content.setAttribute("font-bold", ob.attribute("bold"));
+ content.setAttribute("font-italic", ob.attribute("italic"));
+ content.setAttribute("font-underline", ob.attribute("underline"));
+ QString col = ob.attribute("color");
+ QColor c(col);
+ content.setAttribute("font-color", colorToString(c));
+ QDomText conttxt = tdoc.createTextNode(ob.attribute("text"));
+ content.appendChild(conttxt);
+ item.appendChild(position);
+ item.appendChild(content);
+ title.appendChild(item);
+ } else if (ob.attribute("type") == "5") {
+ // rectangle object
+ QDomElement item = tdoc.createElement("item");
+ item.setAttribute("z-index", ob.attribute("z"));
+ item.setAttribute("type", "QGraphicsRectItem");
+ QDomElement position = tdoc.createElement("position");
+ position.setAttribute("x", ob.attribute("x"));
+ position.setAttribute("y", ob.attribute("y"));
+ QDomElement content = tdoc.createElement("content");
+ QString col = ob.attribute("color");
+ QColor c(col);
+ content.setAttribute("brushcolor", colorToString(c));
+ QString rect = "0,0,";
+ rect.append(ob.attribute("width"));
+ rect.append(",");
+ rect.append(ob.attribute("height"));
+ content.setAttribute("rect", rect);
+ item.appendChild(position);
+ item.appendChild(content);
+ title.appendChild(item);
+ }
+ }
+ prod.setAttribute("xmldata", tdoc.toString());
+ QStringList titleInfo = TitleWidget::getFreeTitleInfo(projectFolder());
+ prod.setAttribute("titlename", titleInfo.at(0));
+ prod.setAttribute("resource", titleInfo.at(1));
+ //kDebug()<<"TITLE DATA:\n"<<tdoc.toString();
+ prod.removeChild(m);
+ }
+
+ } else if (m.isText()) {
+ QString comment = m.nodeValue();
+ if (!comment.isEmpty()) {
+ prod.setAttribute("description", comment);
+ }
+ 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);
+ westley0.removeChild(kdenlivedoc);
+
+ QDomNodeList elements = westley.childNodes();
+ max = elements.count();
+ for (int i = 0; i < max; i++) {
+ QDomElement prod = elements.at(0).toElement();
+ westley0.insertAfter(prod, QDomNode());
+ }
+
+ westley0.removeChild(westley);
+
+ //kDebug() << "///////////////// CONVERTED DOC:";
+ //kDebug() << m_document.toString();
+ //kDebug() << "///////////////// END CONVERTED DOC:";
+}
+
+QString KdenliveDoc::colorToString(const QColor& c) {
+ QString ret = "%1,%2,%3,%4";
+ ret = ret.arg(c.red()).arg(c.green()).arg(c.blue()).arg(c.alpha());
+ return ret;
+}
+
+void KdenliveDoc::saveSceneList(const QString &path, QDomDocument sceneList) {
+ QDomNode wes = sceneList.elementsByTagName("westley").at(0);
+
+ QDomElement addedXml = sceneList.createElement("kdenlivedoc");
+ QDomElement markers = sceneList.createElement("markers");
+ addedXml.setAttribute("version", "0.8");
+ addedXml.setAttribute("profile", profilePath());
+ addedXml.setAttribute("position", m_render->seekPosition().frames(m_fps));
+ addedXml.setAttribute("zoom", m_zoom);
+
+ QDomElement e;
+ QList <DocClipBase*> list = m_clipManager->documentClipList();
+ for (int i = 0; i < list.count(); i++) {
+ e = list.at(i)->toXML();
+ e.setTagName("kdenlive_producer");
+ addedXml.appendChild(sceneList.importNode(e, true));
+ QList < CommentedTime > marks = list.at(i)->commentedSnapMarkers();
+ for (int j = 0; j < marks.count(); j++) {
+ QDomElement marker = sceneList.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);
+ if (!m_guidesXml.isNull()) addedXml.appendChild(sceneList.importNode(m_guidesXml, true));
+
+ wes.appendChild(addedXml);
+ //wes.appendChild(doc.importNode(kdenliveData, true));
+
+ QFile file(path);
+ if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
+ kWarning() << "////// ERROR writing to file: " << path;
+ return;
+ }
+ QTextStream out(&file);
+ out << sceneList.toString();
+ file.close();
+