]> git.sesse.net Git - kdenlive/blob - src/kdenlivedoc.cpp
start of the clip tracks view
[kdenlive] / src / kdenlivedoc.cpp
1 /***************************************************************************
2                         kdenlivedoc.cpp  -  description
3                            -------------------
4   begin                : Fri Nov 22 2002
5   copyright            : (C) 2002 by Jason Wood
6   email                : jasonwood@blueyonder.co.uk
7   copyright            : (C) 2005 Lucio Flavio Correa
8   email                : lucio.correa@gmail.com
9   copyright            : (C) Marco Gittler
10   email                : g.marco@freenet.de
11   copyright            : (C) 2006 Jean-Baptiste Mardelle
12   email                : jb@ader.ch
13
14 ***************************************************************************/
15
16 /***************************************************************************
17  *                                                                         *
18  *   This program is free software; you can redistribute it and/or modify  *
19  *   it under the terms of the GNU General Public License as published by  *
20  *   the Free Software Foundation; either version 2 of the License, or     *
21  *   (at your option) any later version.                                   *
22  *                                                                         *
23  ***************************************************************************/
24
25
26 #include <KDebug>
27 #include <KStandardDirs>
28 #include <KMessageBox>
29 #include <KLocale>
30 #include <KFileDialog>
31 #include <KIO/NetAccess>
32
33
34 #include "kdenlivedoc.h"
35
36
37 KdenliveDoc::KdenliveDoc(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)
38 {
39   if (!url.isEmpty()) {
40     QString tmpFile;
41     if(KIO::NetAccess::download(url.path(), tmpFile, parent))
42     {
43       QFile file(tmpFile);
44       m_document.setContent(&file, false);
45       file.close();
46       m_projectName = url.fileName();
47       KIO::NetAccess::removeTempFile(tmpFile);
48     }
49     else
50     {
51       KMessageBox::error(parent, KIO::NetAccess::lastErrorString());
52     }
53   }
54   else {
55     // Creating new document
56     /*QDomElement westley = m_document.createElement("westley");
57     m_document.appendChild(westley);
58     QDomElement doc = m_document.createElement("kdenlivedoc");
59     doc.setAttribute("version", "0.6");
60     westley.appendChild(doc);
61     QDomElement props = m_document.createElement("properties");
62     doc.setAttribute("width", m_width);
63     doc.setAttribute("height", m_height);
64     doc.setAttribute("projectfps", m_fps);
65     doc.appendChild(props);*/
66
67
68     QDomElement westley = m_document.createElement("westley");
69     m_document.appendChild(westley);
70     QDomElement prod = m_document.createElement("producer");
71     prod.setAttribute("resource", "colour");
72     prod.setAttribute("colour", "red");
73     prod.setAttribute("id", "black");
74     prod.setAttribute("in", "0");
75     prod.setAttribute("out", "0");
76
77     QDomElement tractor = m_document.createElement("tractor");
78     QDomElement multitrack = m_document.createElement("multitrack");
79
80     QDomElement playlist1 = m_document.createElement("playlist");
81     playlist1.appendChild(prod);
82     multitrack.appendChild(playlist1);
83     QDomElement playlist2 = m_document.createElement("playlist");
84     multitrack.appendChild(playlist2);
85     QDomElement playlist3 = m_document.createElement("playlist");
86     multitrack.appendChild(playlist3);
87     QDomElement playlist4 = m_document.createElement("playlist");
88     playlist4.setAttribute("hide", "video");
89     multitrack.appendChild(playlist4);
90     QDomElement playlist5 = m_document.createElement("playlist");
91     playlist5.setAttribute("hide", "video");
92     multitrack.appendChild(playlist5);
93     tractor.appendChild(multitrack);
94     westley.appendChild(tractor);
95     
96   }
97   if (fps == 30000.0 / 1001.0 ) m_timecode.setFormat(30, true);
98     else m_timecode.setFormat((int) fps);
99 }
100
101 KdenliveDoc::~KdenliveDoc()
102 {
103 }
104
105 void KdenliveDoc::setRenderer(Render *render)
106 {
107   m_render = render;
108   if (m_render) m_render->setSceneList(m_document);
109 }
110
111 QDomDocument KdenliveDoc::generateSceneList()
112 {
113     QDomDocument doc;
114     QDomElement westley = doc.createElement("westley");
115     doc.appendChild(westley);
116     QDomElement prod = doc.createElement("producer");
117 }
118
119 QDomDocument KdenliveDoc::toXml()
120 {
121   return m_document;
122 }
123
124 Timecode KdenliveDoc::timecode()
125 {
126   return m_timecode;
127 }
128
129 QString KdenliveDoc::documentName()
130 {
131   return m_projectName;
132 }
133
134 QDomNodeList KdenliveDoc::producersList()
135 {
136   return m_document.elementsByTagName("producer");
137 }
138
139 void KdenliveDoc::setProducers(QDomElement doc)
140 {
141   QDomNode kdenlivedocument = m_document.elementsByTagName("kdenlivedoc").item(0);
142
143   QDomNodeList list = m_document.elementsByTagName("producer");
144   int ct = list.count();
145     kDebug()<<"DELETING CHILD PRODUCERS: "<<ct;
146   for (int i = 0; i < ct; i++) {
147     kdenlivedocument.removeChild(list.item(0));
148    }
149
150   QDomNode n = doc.firstChild();
151   ct = 0;
152   while(!n.isNull()) {
153      QDomElement e = n.toElement(); // try to convert the node to an element.
154      if(!e.isNull() && e.tagName() == "producer") {
155          kdenlivedocument.appendChild(m_document.importNode(e, true));
156         ct++;
157      }
158      n = n.nextSibling();
159   }
160   kDebug()<<"ADDING CHILD PRODS: "<<ct<<"\n";
161   //kDebug()<<m_document.toString();
162 }
163
164 double KdenliveDoc::fps()
165 {
166   return m_fps;
167 }
168
169 int KdenliveDoc::width()
170 {
171   return m_width;
172 }
173
174 int KdenliveDoc::height()
175 {
176   return m_height;
177 }
178
179 #include "kdenlivedoc.moc"
180