]> git.sesse.net Git - kdenlive/blob - src/kdenlivedoc.cpp
Reindent all source files
[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 #include "docclipbase.h"
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), m_commandStack(new KUndoStack()) {
32     m_clipManager = new ClipManager(this);
33     if (!url.isEmpty()) {
34         QString tmpFile;
35         if (KIO::NetAccess::download(url.path(), tmpFile, parent)) {
36             QFile file(tmpFile);
37             m_document.setContent(&file, false);
38             file.close();
39             m_projectName = url.fileName();
40             KIO::NetAccess::removeTempFile(tmpFile);
41         } else {
42             KMessageBox::error(parent, KIO::NetAccess::lastErrorString());
43         }
44     } else {
45         // Creating new document
46         QDomElement westley = m_document.createElement("westley");
47         m_document.appendChild(westley);
48         QDomElement doc = m_document.createElement("kdenlivedoc");
49         doc.setAttribute("version", "0.6");
50         westley.appendChild(doc);
51         QDomElement props = m_document.createElement("properties");
52         doc.setAttribute("width", m_width);
53         doc.setAttribute("height", m_height);
54         doc.setAttribute("projectfps", m_fps);
55         doc.appendChild(props);
56
57
58         /*QDomElement westley = m_document.createElement("westley");
59         m_document.appendChild(westley);*/
60
61
62         QDomElement tractor = m_document.createElement("tractor");
63         QDomElement multitrack = m_document.createElement("multitrack");
64         QDomElement playlist = m_document.createElement("playlist");
65         QDomElement producer = m_document.createElement("producer");
66         /*producer.setAttribute("mlt_service", "colour");
67         producer.setAttribute("colour", "red");
68         playlist.appendChild(producer);*/
69         multitrack.appendChild(playlist);
70         QDomElement playlist1 = m_document.createElement("playlist");
71         playlist1.setAttribute("id", "playlist1");
72         playlist1.setAttribute("hide", "video");
73         multitrack.appendChild(playlist1);
74         QDomElement playlist2 = m_document.createElement("playlist");
75         playlist2.setAttribute("id", "playlist2");
76         playlist2.setAttribute("hide", "video");
77         multitrack.appendChild(playlist2);
78         QDomElement playlist3 = m_document.createElement("playlist");
79         multitrack.appendChild(playlist3);
80         playlist3.setAttribute("id", "playlist3");
81         QDomElement playlist4 = m_document.createElement("playlist");
82         multitrack.appendChild(playlist4);
83         playlist4.setAttribute("id", "playlist4");
84         QDomElement playlist5 = m_document.createElement("playlist");
85         multitrack.appendChild(playlist5);
86         playlist5.setAttribute("id", "playlist5");
87         tractor.appendChild(multitrack);
88
89         for (uint i = 2; i < 6 ; i++) {
90             QDomElement transition = m_document.createElement("transition");
91             transition.setAttribute("in", "0");
92             //TODO: Make audio mix last for all project duration
93             transition.setAttribute("out", "15000");
94             transition.setAttribute("a_track", QString::number(1));
95             transition.setAttribute("b_track", QString::number(i));
96             transition.setAttribute("mlt_service", "mix");
97             transition.setAttribute("combine", "1");
98             tractor.appendChild(transition);
99         }
100
101         doc.appendChild(tractor);
102
103     }
104     if (fps == 30000.0 / 1001.0) m_timecode.setFormat(30, true);
105     else m_timecode.setFormat((int) fps);
106 }
107
108 KdenliveDoc::~KdenliveDoc() {
109     delete m_commandStack;
110     delete m_clipManager;
111 }
112
113 ClipManager *KdenliveDoc::clipManager() {
114     return m_clipManager;
115 }
116
117 void KdenliveDoc::setThumbsProgress(KUrl url, int progress) {
118     emit thumbsProgress(url, progress);
119 }
120
121 KUndoStack *KdenliveDoc::commandStack() {
122     return m_commandStack;
123 }
124
125 void KdenliveDoc::setRenderer(Render *render) {
126     m_render = render;
127     if (m_render) m_render->setSceneList(m_document);
128 }
129
130 Render *KdenliveDoc::renderer() {
131     return m_render;
132 }
133
134 void KdenliveDoc::updateClip(int id) {
135     emit updateClipDisplay(id);
136 }
137
138 int KdenliveDoc::getFramePos(QString duration) {
139     return m_timecode.getFrameCount(duration, m_fps);
140 }
141
142 QString KdenliveDoc::producerName(int id) {
143     QString result = "unnamed";
144     QDomNodeList prods = producersList();
145     int ct = prods.count();
146     for (int i = 0; i <  ct ; i++) {
147         QDomElement e = prods.item(i).toElement();
148         if (e.attribute("id") != "black" && e.attribute("id").toInt() == id) {
149             result = e.attribute("name");
150             if (result.isEmpty()) result = KUrl(e.attribute("resource")).fileName();
151             break;
152         }
153     }
154     return result;
155 }
156
157 void KdenliveDoc::setProducerDuration(int id, int duration) {
158     QDomNodeList prods = producersList();
159     int ct = prods.count();
160     for (int i = 0; i <  ct ; i++) {
161         QDomElement e = prods.item(i).toElement();
162         if (e.attribute("id") != "black" && e.attribute("id").toInt() == id) {
163             e.setAttribute("duration", QString::number(duration));
164             break;
165         }
166     }
167 }
168
169 int KdenliveDoc::getProducerDuration(int id) {
170     int result = 0;
171     QDomNodeList prods = producersList();
172     int ct = prods.count();
173     for (int i = 0; i <  ct ; i++) {
174         QDomElement e = prods.item(i).toElement();
175         if (e.attribute("id") != "black" && e.attribute("id").toInt() == id) {
176             result = e.attribute("duration").toInt();
177             break;
178         }
179     }
180     return result;
181 }
182
183
184 QDomDocument KdenliveDoc::generateSceneList() {
185     QDomDocument doc;
186     QDomElement westley = doc.createElement("westley");
187     doc.appendChild(westley);
188     QDomElement prod = doc.createElement("producer");
189 }
190
191 QDomDocument KdenliveDoc::toXml() {
192     return m_document;
193 }
194
195 Timecode KdenliveDoc::timecode() {
196     return m_timecode;
197 }
198
199 QString KdenliveDoc::documentName() {
200     return m_projectName;
201 }
202
203 QDomNodeList KdenliveDoc::producersList() {
204     return m_document.elementsByTagName("producer");
205 }
206
207 void KdenliveDoc::setProducers(QDomElement doc) {
208     QDomNode kdenlivedocument = m_document.elementsByTagName("kdenlivedoc").item(0);
209
210     QDomNodeList list = m_document.elementsByTagName("producer");
211     int ct = list.count();
212     kDebug() << "DELETING CHILD PRODUCERS: " << ct;
213     for (int i = ct; i > 0; i--) {
214         kdenlivedocument.removeChild(list.item(i));
215     }
216
217     QDomNode n = doc.firstChild();
218     ct = 0;
219     while (!n.isNull()) {
220         QDomElement e = n.toElement(); // try to convert the node to an element.
221         if (!e.isNull() && e.tagName() == "producer") {
222             kdenlivedocument.appendChild(m_document.importNode(e, true));
223             ct++;
224         }
225         n = n.nextSibling();
226     }
227     kDebug() << "ADDING CHILD PRODS: " << ct << "\n";
228     //kDebug()<<m_document.toString();
229 }
230
231 double KdenliveDoc::fps() {
232     return m_fps;
233 }
234
235 int KdenliveDoc::width() {
236     return m_width;
237 }
238
239 int KdenliveDoc::height() {
240     return m_height;
241 }
242
243 KUrl KdenliveDoc::url() {
244     return m_url;
245 }
246
247 void KdenliveDoc::addClip(const QDomElement &elem, const int clipId) {
248     kDebug() << "/////////  DOCUM, CREATING NEW CLIP, ID:" << clipId;
249     DocClipBase *clip = new DocClipBase(m_clipManager, elem, clipId);
250     m_clipManager->addClip(clip);
251     emit addProjectClip(clip);
252 }
253
254 void KdenliveDoc::deleteProjectClip(const uint clipId) {
255     emit deletTimelineClip(clipId);
256     m_clipManager->slotDeleteClip(clipId);
257 }
258
259 void KdenliveDoc::deleteClip(const uint clipId) {
260     emit signalDeleteProjectClip(clipId);
261     m_clipManager->deleteClip(clipId);
262 }
263
264 void KdenliveDoc::slotAddClipFile(const KUrl url, const QString group) {
265     kDebug() << "/////////  DOCUM, ADD CLP: " << url;
266     m_clipManager->slotAddClipFile(url, group);
267 }
268
269 DocClipBase *KdenliveDoc::getBaseClip(int clipId) {
270     return m_clipManager->getClipById(clipId);
271 }
272
273 void KdenliveDoc::slotAddColorClipFile(const QString name, const QString color, QString duration, const QString group) {
274     m_clipManager->slotAddColorClipFile(name, color, duration, group);
275 }
276
277 #include "kdenlivedoc.moc"
278