1 /***************************************************************************
2 * Copyright (C) 2007 by Jean-Baptiste Mardelle (jb@kdenlive.org) *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
21 #include <KStandardDirs>
22 #include <KMessageBox>
24 #include <KFileDialog>
25 #include <KIO/NetAccess>
28 #include "kdenlivedoc.h"
31 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())
35 if(KIO::NetAccess::download(url.path(), tmpFile, parent))
38 m_document.setContent(&file, false);
40 m_projectName = url.fileName();
41 KIO::NetAccess::removeTempFile(tmpFile);
45 KMessageBox::error(parent, KIO::NetAccess::lastErrorString());
49 // Creating new document
50 QDomElement westley = m_document.createElement("westley");
51 m_document.appendChild(westley);
52 QDomElement doc = m_document.createElement("kdenlivedoc");
53 doc.setAttribute("version", "0.6");
54 westley.appendChild(doc);
55 QDomElement props = m_document.createElement("properties");
56 doc.setAttribute("width", m_width);
57 doc.setAttribute("height", m_height);
58 doc.setAttribute("projectfps", m_fps);
59 doc.appendChild(props);
62 /*QDomElement westley = m_document.createElement("westley");
63 m_document.appendChild(westley);*/
66 QDomElement tractor = m_document.createElement("tractor");
67 QDomElement multitrack = m_document.createElement("multitrack");
68 QDomElement playlist = m_document.createElement("playlist");
69 multitrack.appendChild(playlist);
70 QDomElement playlist1 = m_document.createElement("playlist");
71 playlist1.setAttribute("id", "playlist1");
72 multitrack.appendChild(playlist1);
73 QDomElement playlist2 = m_document.createElement("playlist");
74 playlist2.setAttribute("id", "playlist2");
75 multitrack.appendChild(playlist2);
76 QDomElement playlist3 = m_document.createElement("playlist");
77 multitrack.appendChild(playlist3);
78 playlist3.setAttribute("id", "playlist3");
79 QDomElement playlist4 = m_document.createElement("playlist");
80 playlist4.setAttribute("hide", "video");
81 multitrack.appendChild(playlist4);
82 playlist1.setAttribute("id", "playlist4");
83 QDomElement playlist5 = m_document.createElement("playlist");
84 playlist5.setAttribute("hide", "video");
85 multitrack.appendChild(playlist5);
86 playlist1.setAttribute("id", "playlist5");
87 tractor.appendChild(multitrack);
88 doc.appendChild(tractor);
91 if (fps == 30000.0 / 1001.0 ) m_timecode.setFormat(30, true);
92 else m_timecode.setFormat((int) fps);
95 KdenliveDoc::~KdenliveDoc()
97 delete m_commandStack;
100 KUndoStack *KdenliveDoc::commandStack()
102 return m_commandStack;
105 void KdenliveDoc::setRenderer(Render *render)
108 if (m_render) m_render->setSceneList(m_document);
111 Render *KdenliveDoc::renderer()
116 QString KdenliveDoc::producerName(int id)
118 QString result = "unnamed";
119 QDomNodeList prods = producersList();
120 int ct = prods.count();
121 for (int i = 0; i < ct ; i++)
123 QDomElement e = prods.item(i).toElement();
124 if (e.attribute("id") != "black" && e.attribute("id").toInt() == id) {
125 result = e.attribute("name");
126 if (result.isEmpty()) result = KUrl(e.attribute("resource")).fileName();
133 void KdenliveDoc::setProducerDuration(int id, int duration)
135 QDomNodeList prods = producersList();
136 int ct = prods.count();
137 for (int i = 0; i < ct ; i++)
139 QDomElement e = prods.item(i).toElement();
140 if (e.attribute("id") != "black" && e.attribute("id").toInt() == id) {
141 e.setAttribute("duration", QString::number(duration));
147 int KdenliveDoc::getProducerDuration(int id)
150 QDomNodeList prods = producersList();
151 int ct = prods.count();
152 for (int i = 0; i < ct ; i++)
154 QDomElement e = prods.item(i).toElement();
155 if (e.attribute("id") != "black" && e.attribute("id").toInt() == id) {
156 result = e.attribute("duration").toInt();
164 QDomDocument KdenliveDoc::generateSceneList()
167 QDomElement westley = doc.createElement("westley");
168 doc.appendChild(westley);
169 QDomElement prod = doc.createElement("producer");
172 QDomDocument KdenliveDoc::toXml()
177 Timecode KdenliveDoc::timecode()
182 QString KdenliveDoc::documentName()
184 return m_projectName;
187 QDomNodeList KdenliveDoc::producersList()
189 return m_document.elementsByTagName("producer");
192 void KdenliveDoc::setProducers(QDomElement doc)
194 QDomNode kdenlivedocument = m_document.elementsByTagName("kdenlivedoc").item(0);
196 QDomNodeList list = m_document.elementsByTagName("producer");
197 int ct = list.count();
198 kDebug()<<"DELETING CHILD PRODUCERS: "<<ct;
199 for (int i = ct; i > 0; i--) {
200 kdenlivedocument.removeChild(list.item(i));
203 QDomNode n = doc.firstChild();
206 QDomElement e = n.toElement(); // try to convert the node to an element.
207 if(!e.isNull() && e.tagName() == "producer") {
208 kdenlivedocument.appendChild(m_document.importNode(e, true));
213 kDebug()<<"ADDING CHILD PRODS: "<<ct<<"\n";
214 //kDebug()<<m_document.toString();
217 double KdenliveDoc::fps()
222 int KdenliveDoc::width()
227 int KdenliveDoc::height()
232 KUrl KdenliveDoc::url()
237 #include "kdenlivedoc.moc"