]> git.sesse.net Git - kdenlive/blob - src/kdenlivedoc.cpp
progress in timeline widget
[kdenlive] / src / kdenlivedoc.cpp
1 /***************************************************************************
2  *   Copyright (C) 2007 by Jean-Baptiste Mardelle (jb@kdenlive.org)        *
3  *                                                                         *
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.                                   *
8  *                                                                         *
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.                          *
13  *                                                                         *
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  ***************************************************************************/
19
20 #include <KDebug>
21 #include <KStandardDirs>
22 #include <KMessageBox>
23 #include <KLocale>
24 #include <KFileDialog>
25 #include <KIO/NetAccess>
26
27
28 #include "kdenlivedoc.h"
29
30
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)
32 {
33
34   m_commandStack = new KUndoStack();
35   if (!url.isEmpty()) {
36     QString tmpFile;
37     if(KIO::NetAccess::download(url.path(), tmpFile, parent))
38     {
39       QFile file(tmpFile);
40       m_document.setContent(&file, false);
41       file.close();
42       m_projectName = url.fileName();
43       KIO::NetAccess::removeTempFile(tmpFile);
44     }
45     else
46     {
47       KMessageBox::error(parent, KIO::NetAccess::lastErrorString());
48     }
49   }
50   else {
51     // Creating new document
52     QDomElement westley = m_document.createElement("westley");
53     m_document.appendChild(westley);
54     QDomElement doc = m_document.createElement("kdenlivedoc");
55     doc.setAttribute("version", "0.6");
56     westley.appendChild(doc);
57     QDomElement props = m_document.createElement("properties");
58     doc.setAttribute("width", m_width);
59     doc.setAttribute("height", m_height);
60     doc.setAttribute("projectfps", m_fps);
61     doc.appendChild(props);
62
63
64     /*QDomElement westley = m_document.createElement("westley");
65     m_document.appendChild(westley);*/
66     QDomElement prod = m_document.createElement("producer");
67     prod.setAttribute("resource", "colour");
68     prod.setAttribute("colour", "red");
69     prod.setAttribute("id", "black");
70     prod.setAttribute("in", "0");
71     prod.setAttribute("out", "0");
72
73     QDomElement tractor = m_document.createElement("tractor");
74     QDomElement multitrack = m_document.createElement("multitrack");
75
76     QDomElement playlist1 = m_document.createElement("playlist");
77     playlist1.appendChild(prod);
78     playlist1.setAttribute("id", "playlist1");
79     multitrack.appendChild(playlist1);
80     QDomElement playlist2 = m_document.createElement("playlist");
81     playlist2.setAttribute("id", "playlist2");
82     multitrack.appendChild(playlist2);
83     QDomElement playlist3 = m_document.createElement("playlist");
84     multitrack.appendChild(playlist3);
85     playlist3.setAttribute("id", "playlist3");
86     QDomElement playlist4 = m_document.createElement("playlist");
87     playlist4.setAttribute("hide", "video");
88     multitrack.appendChild(playlist4);
89     playlist1.setAttribute("id", "playlist4");
90     QDomElement playlist5 = m_document.createElement("playlist");
91     playlist5.setAttribute("hide", "video");
92     multitrack.appendChild(playlist5);
93     playlist1.setAttribute("id", "playlist5");
94     tractor.appendChild(multitrack);
95     doc.appendChild(tractor);
96     
97   }
98   if (fps == 30000.0 / 1001.0 ) m_timecode.setFormat(30, true);
99     else m_timecode.setFormat((int) fps);
100 }
101
102 KdenliveDoc::~KdenliveDoc()
103 {
104   delete m_commandStack;
105 }
106
107 KUndoStack *KdenliveDoc::commandStack()
108 {
109   return m_commandStack;
110 }
111
112 void KdenliveDoc::setRenderer(Render *render)
113 {
114   m_render = render;
115   if (m_render) m_render->setSceneList(m_document);
116 }
117
118 QString KdenliveDoc::producerName(int id)
119 {
120   QString result = "unnamed";
121   QDomNodeList prods = producersList();
122   int ct = prods.count();
123   for (int i = 0; i <  ct ; i++)
124   {
125     QDomElement e = prods.item(i).toElement();
126     if (e.attribute("id") != "black" && e.attribute("id").toInt() == id) {
127       result = e.attribute("name");
128       if (result.isEmpty()) result = KUrl(e.attribute("resource")).fileName();
129       break;
130     }
131   }
132   return result;
133 }
134
135 void KdenliveDoc::setProducerDuration(int id, int duration)
136 {
137   QDomNodeList prods = producersList();
138   int ct = prods.count();
139   for (int i = 0; i <  ct ; i++)
140   {
141     QDomElement e = prods.item(i).toElement();
142     if (e.attribute("id") != "black" && e.attribute("id").toInt() == id) {
143       e.setAttribute("duration", QString::number(duration));
144       break;
145     }
146   }
147 }
148
149 int KdenliveDoc::getProducerDuration(int id)
150 {
151   int result = 0;
152   QDomNodeList prods = producersList();
153   int ct = prods.count();
154   for (int i = 0; i <  ct ; i++)
155   {
156     QDomElement e = prods.item(i).toElement();
157     if (e.attribute("id") != "black" && e.attribute("id").toInt() == id) {
158       result = e.attribute("duration").toInt();
159       break;
160     }
161   }
162   return result;
163 }
164
165
166 QDomDocument KdenliveDoc::generateSceneList()
167 {
168     QDomDocument doc;
169     QDomElement westley = doc.createElement("westley");
170     doc.appendChild(westley);
171     QDomElement prod = doc.createElement("producer");
172 }
173
174 QDomDocument KdenliveDoc::toXml()
175 {
176   return m_document;
177 }
178
179 Timecode KdenliveDoc::timecode()
180 {
181   return m_timecode;
182 }
183
184 QString KdenliveDoc::documentName()
185 {
186   return m_projectName;
187 }
188
189 QDomNodeList KdenliveDoc::producersList()
190 {
191   return m_document.elementsByTagName("producer");
192 }
193
194 void KdenliveDoc::setProducers(QDomElement doc)
195 {
196   QDomNode kdenlivedocument = m_document.elementsByTagName("kdenlivedoc").item(0);
197
198   QDomNodeList list = m_document.elementsByTagName("producer");
199   int ct = list.count();
200     kDebug()<<"DELETING CHILD PRODUCERS: "<<ct;
201   for (int i = ct; i > 0; i--) {
202     kdenlivedocument.removeChild(list.item(i));
203    }
204
205   QDomNode n = doc.firstChild();
206   ct = 0;
207   while(!n.isNull()) {
208      QDomElement e = n.toElement(); // try to convert the node to an element.
209      if(!e.isNull() && e.tagName() == "producer") {
210          kdenlivedocument.appendChild(m_document.importNode(e, true));
211         ct++;
212      }
213      n = n.nextSibling();
214   }
215   kDebug()<<"ADDING CHILD PRODS: "<<ct<<"\n";
216   //kDebug()<<m_document.toString();
217 }
218
219 double KdenliveDoc::fps()
220 {
221   return m_fps;
222 }
223
224 int KdenliveDoc::width()
225 {
226   return m_width;
227 }
228
229 int KdenliveDoc::height()
230 {
231   return m_height;
232 }
233
234 KUrl KdenliveDoc::url()
235 {
236   return m_url;
237 }
238
239 #include "kdenlivedoc.moc"
240