]> git.sesse.net Git - kdenlive/blob - src/kdenlivedoc.cpp
One undo stack for each project file
[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
40   m_commandStack = new KUndoStack(this);
41   if (!url.isEmpty()) {
42     QString tmpFile;
43     if(KIO::NetAccess::download(url.path(), tmpFile, parent))
44     {
45       QFile file(tmpFile);
46       m_document.setContent(&file, false);
47       file.close();
48       m_projectName = url.fileName();
49       KIO::NetAccess::removeTempFile(tmpFile);
50     }
51     else
52     {
53       KMessageBox::error(parent, KIO::NetAccess::lastErrorString());
54     }
55   }
56   else {
57     // Creating new document
58     /*QDomElement westley = m_document.createElement("westley");
59     m_document.appendChild(westley);
60     QDomElement doc = m_document.createElement("kdenlivedoc");
61     doc.setAttribute("version", "0.6");
62     westley.appendChild(doc);
63     QDomElement props = m_document.createElement("properties");
64     doc.setAttribute("width", m_width);
65     doc.setAttribute("height", m_height);
66     doc.setAttribute("projectfps", m_fps);
67     doc.appendChild(props);*/
68
69
70     QDomElement westley = m_document.createElement("westley");
71     m_document.appendChild(westley);
72     QDomElement prod = m_document.createElement("producer");
73     prod.setAttribute("resource", "colour");
74     prod.setAttribute("colour", "red");
75     prod.setAttribute("id", "black");
76     prod.setAttribute("in", "0");
77     prod.setAttribute("out", "0");
78
79     QDomElement tractor = m_document.createElement("tractor");
80     QDomElement multitrack = m_document.createElement("multitrack");
81
82     QDomElement playlist1 = m_document.createElement("playlist");
83     playlist1.appendChild(prod);
84     multitrack.appendChild(playlist1);
85     QDomElement playlist2 = m_document.createElement("playlist");
86     multitrack.appendChild(playlist2);
87     QDomElement playlist3 = m_document.createElement("playlist");
88     multitrack.appendChild(playlist3);
89     QDomElement playlist4 = m_document.createElement("playlist");
90     playlist4.setAttribute("hide", "video");
91     multitrack.appendChild(playlist4);
92     QDomElement playlist5 = m_document.createElement("playlist");
93     playlist5.setAttribute("hide", "video");
94     multitrack.appendChild(playlist5);
95     tractor.appendChild(multitrack);
96     westley.appendChild(tractor);
97     
98   }
99   if (fps == 30000.0 / 1001.0 ) m_timecode.setFormat(30, true);
100     else m_timecode.setFormat((int) fps);
101 }
102
103 KdenliveDoc::~KdenliveDoc()
104 {
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 QDomDocument KdenliveDoc::generateSceneList()
119 {
120     QDomDocument doc;
121     QDomElement westley = doc.createElement("westley");
122     doc.appendChild(westley);
123     QDomElement prod = doc.createElement("producer");
124 }
125
126 QDomDocument KdenliveDoc::toXml()
127 {
128   return m_document;
129 }
130
131 Timecode KdenliveDoc::timecode()
132 {
133   return m_timecode;
134 }
135
136 QString KdenliveDoc::documentName()
137 {
138   return m_projectName;
139 }
140
141 QDomNodeList KdenliveDoc::producersList()
142 {
143   return m_document.elementsByTagName("producer");
144 }
145
146 void KdenliveDoc::setProducers(QDomElement doc)
147 {
148   QDomNode kdenlivedocument = m_document.elementsByTagName("kdenlivedoc").item(0);
149
150   QDomNodeList list = m_document.elementsByTagName("producer");
151   int ct = list.count();
152     kDebug()<<"DELETING CHILD PRODUCERS: "<<ct;
153   for (int i = 0; i < ct; i++) {
154     kdenlivedocument.removeChild(list.item(0));
155    }
156
157   QDomNode n = doc.firstChild();
158   ct = 0;
159   while(!n.isNull()) {
160      QDomElement e = n.toElement(); // try to convert the node to an element.
161      if(!e.isNull() && e.tagName() == "producer") {
162          kdenlivedocument.appendChild(m_document.importNode(e, true));
163         ct++;
164      }
165      n = n.nextSibling();
166   }
167   kDebug()<<"ADDING CHILD PRODS: "<<ct<<"\n";
168   //kDebug()<<m_document.toString();
169 }
170
171 double KdenliveDoc::fps()
172 {
173   return m_fps;
174 }
175
176 int KdenliveDoc::width()
177 {
178   return m_width;
179 }
180
181 int KdenliveDoc::height()
182 {
183   return m_height;
184 }
185
186 #include "kdenlivedoc.moc"
187