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