]> git.sesse.net Git - kdenlive/blob - src/kdenlivedoc.cpp
* New configuration page to set SDL audio/video driver and audio device
[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 #include <KApplication>
27
28 #include "kdenlivedoc.h"
29 #include "docclipbase.h"
30 #include "profilesdialog.h"
31 #include "kdenlivesettings.h"
32 #include "renderer.h"
33 #include "clipmanager.h"
34 #include "addfoldercommand.h"
35 #include "editfoldercommand.h"
36 #include "titlewidget.h"
37 #include "mainwindow.h"
38
39
40 KdenliveDoc::KdenliveDoc(const KUrl &url, const KUrl &projectFolder, MltVideoProfile profile, QUndoGroup *undoGroup, MainWindow *parent): QObject(parent), m_render(NULL), m_url(url), m_projectFolder(projectFolder), 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(undoGroup)), m_modified(false), m_documentLoadingProgress(0), m_documentLoadingStep(0.0), m_startPos(0), m_zoom(7) {
41     kDebug() << "// init profile, ratnum: " << profile.frame_rate_num << ", " << profile.frame_rate_num << ", width: " << profile.width;
42     m_clipManager = new ClipManager(this);
43     KdenliveSettings::setProject_fps(m_fps);
44     if (!url.isEmpty()) {
45         QString tmpFile;
46         if (KIO::NetAccess::download(url.path(), tmpFile, parent)) {
47             QFile file(tmpFile);
48             m_document.setContent(&file, false);
49             file.close();
50             QDomNode infoXmlNode = m_document.elementsByTagName("kdenlivedoc").at(0);
51             QDomNode westley = m_document.elementsByTagName("westley").at(0);
52             if (!infoXmlNode.isNull()) {
53                 QDomElement infoXml = infoXmlNode.toElement();
54                 QString profilePath = infoXml.attribute("profile");
55                 m_startPos = infoXml.attribute("position").toInt();
56                 m_zoom = infoXml.attribute("zoom", "7").toInt();
57                 if (!profilePath.isEmpty()) setProfilePath(profilePath);
58                 double version = infoXml.attribute("version").toDouble();
59                 if (version < 0.7) convertDocument(version);
60                 else {
61                     //delete all mlt producers and instead, use Kdenlive saved producers
62                     QDomNodeList prods = m_document.elementsByTagName("producer");
63                     int maxprod = prods.count();
64                     int pos = 0;
65                     for (int i = 0; i < maxprod; i++) {
66                         QDomNode m = prods.at(pos);
67                         QString prodId = m.toElement().attribute("id");
68                         if (prodId == "black" || prodId.startsWith("slowmotion"))
69                             pos++;
70                         else westley.removeChild(m);
71                     }
72                     prods = m_document.elementsByTagName("kdenlive_producer");
73                     maxprod = prods.count();
74                     for (int i = 0; i < maxprod; i++) {
75                         prods.at(0).toElement().setTagName("producer");
76                         westley.insertBefore(prods.at(0), QDomNode());
77                     }
78                 }
79                 QDomElement e;
80                 QDomNodeList producers = m_document.elementsByTagName("producer");
81                 const int max = producers.count();
82                 if (max > 0) {
83                     m_documentLoadingStep = 100.0 / (max + m_document.elementsByTagName("entry").count());
84                     parent->slotGotProgressInfo(i18n("Loading project clips"), (int) m_documentLoadingProgress);
85                 }
86
87                 for (int i = 0; i < max; i++) {
88                     e = producers.item(i).cloneNode().toElement();
89                     if (m_documentLoadingStep > 0) {
90                         m_documentLoadingProgress += m_documentLoadingStep;
91                         parent->slotGotProgressInfo(QString(), (int) m_documentLoadingProgress);
92                         qApp->processEvents();
93                     }
94                     QString prodId = e.attribute("id");
95                     if (!e.isNull() && prodId != "black" && prodId.toInt() > 0) {
96                         addClip(e, e.attribute("id").toInt());
97                     }
98                 }
99
100                 QDomNode markers = m_document.elementsByTagName("markers").at(0);
101                 if (!markers.isNull()) {
102                     QDomNodeList markerslist = markers.childNodes();
103                     int maxchild = markerslist.count();
104                     for (int k = 0; k < maxchild; k++) {
105                         e = markerslist.at(k).toElement();
106                         if (e.tagName() == "marker") {
107                             int id = e.attribute("id").toInt();
108                             m_clipManager->getClipById(id)->addSnapMarker(GenTime(e.attribute("time").toDouble()), e.attribute("comment"));
109                         }
110                     }
111                     m_document.removeChild(markers);
112                 }
113                 m_document.removeChild(infoXmlNode);
114
115                 kDebug() << "Reading file: " << url.path() << ", found clips: " << producers.count();
116             } else kWarning() << "  NO KDENLIVE INFO FOUND IN FILE: " << url.path();
117             KIO::NetAccess::removeTempFile(tmpFile);
118         } else {
119             KMessageBox::error(parent, KIO::NetAccess::lastErrorString());
120         }
121     } else {
122         // Creating new document
123         QDomElement westley = m_document.createElement("westley");
124         m_document.appendChild(westley);
125
126         QDomElement tractor = m_document.createElement("tractor");
127         tractor.setAttribute("id", "maintractor");
128         QDomElement multitrack = m_document.createElement("multitrack");
129         QDomElement playlist = m_document.createElement("playlist");
130         playlist.setAttribute("id", "black_track");
131         westley.appendChild(playlist);
132
133
134         // create playlists
135         int audiotracks = 2;
136         int videotracks = 3;
137         int total = audiotracks + videotracks + 1;
138
139         for (int i = 1; i < total; i++) {
140             QDomElement playlist = m_document.createElement("playlist");
141             playlist.setAttribute("id", "playlist" + QString::number(i));
142             westley.appendChild(playlist);
143         }
144
145         QDomElement track0 = m_document.createElement("track");
146         track0.setAttribute("producer", "black_track");
147         tractor.appendChild(track0);
148
149         // create audio tracks
150         for (int i = 1; i < audiotracks + 1; i++) {
151             QDomElement track = m_document.createElement("track");
152             track.setAttribute("producer", "playlist" + QString::number(i));
153             track.setAttribute("hide", "video");
154             tractor.appendChild(track);
155         }
156
157         // create video tracks
158         for (int i = audiotracks + 1; i < total; i++) {
159             QDomElement track = m_document.createElement("track");
160             track.setAttribute("producer", "playlist" + QString::number(i));
161             tractor.appendChild(track);
162         }
163
164         for (uint i = 2; i < total ; i++) {
165             QDomElement transition = m_document.createElement("transition");
166             transition.setAttribute("always_active", "1");
167
168             QDomElement property = m_document.createElement("property");
169             property.setAttribute("name", "a_track");
170             QDomText value = m_document.createTextNode(QString::number(1));
171             property.appendChild(value);
172             transition.appendChild(property);
173
174             property = m_document.createElement("property");
175             property.setAttribute("name", "b_track");
176             value = m_document.createTextNode(QString::number(i));
177             property.appendChild(value);
178             transition.appendChild(property);
179
180             property = m_document.createElement("property");
181             property.setAttribute("name", "mlt_service");
182             value = m_document.createTextNode("mix");
183             property.appendChild(value);
184             transition.appendChild(property);
185
186             property = m_document.createElement("property");
187             property.setAttribute("name", "combine");
188             value = m_document.createTextNode("1");
189             property.appendChild(value);
190             transition.appendChild(property);
191
192             property = m_document.createElement("property");
193             property.setAttribute("name", "internal_added");
194             value = m_document.createTextNode("237");
195             property.appendChild(value);
196             transition.appendChild(property);
197             tractor.appendChild(transition);
198         }
199         westley.appendChild(tractor);
200     }
201     m_scenelist = m_document.toString();
202     kDebug() << "KDEnnlive document, init timecode: " << m_fps;
203     if (m_fps == 30000.0 / 1001.0) m_timecode.setFormat(30, true);
204     else m_timecode.setFormat((int) m_fps);
205
206     m_autoSaveTimer = new QTimer(this);
207     m_autoSaveTimer->setSingleShot(true);
208     QString directory = m_url.directory();
209     QString fileName = m_url.fileName();
210     m_recoveryUrl.setDirectory(directory);
211     m_recoveryUrl.setFileName("~" + fileName);
212     connect(m_autoSaveTimer, SIGNAL(timeout()), this, SLOT(slotAutoSave()));
213 }
214
215 KdenliveDoc::~KdenliveDoc() {
216     delete m_commandStack;
217     delete m_clipManager;
218     delete m_autoSaveTimer;
219     if (!m_url.isEmpty()) {
220         // remove backup file
221         if (KIO::NetAccess::exists(m_recoveryUrl, KIO::NetAccess::SourceSide, NULL))
222             KIO::NetAccess::del(m_recoveryUrl, NULL);
223     }
224 }
225
226 void KdenliveDoc::syncGuides(QList <Guide *> guides) {
227     QDomDocument doc;
228     QDomElement e;
229     m_guidesXml.clear();
230     m_guidesXml = doc.createElement("guides");
231     for (int i = 0; i < guides.count(); i++) {
232         e = doc.createElement("guide");
233         e.setAttribute("time", guides.at(i)->position().ms() / 1000);
234         e.setAttribute("comment", guides.at(i)->label());
235         m_guidesXml.appendChild(e);
236     }
237 }
238
239 void KdenliveDoc::slotAutoSave() {
240     if (m_render)
241         m_render->saveSceneList(m_recoveryUrl.path(), documentInfoXml());
242
243 }
244
245 void KdenliveDoc::setZoom(int factor) {
246     m_zoom = factor;
247 }
248
249 int KdenliveDoc::zoom() const {
250     return m_zoom;
251 }
252
253 void KdenliveDoc::convertDocument(double version) {
254     // Opening a old Kdenlive document
255     QDomNode westley = m_document.elementsByTagName("westley").at(1);
256     QDomNode tractor = m_document.elementsByTagName("tractor").at(0);
257     QDomNode kdenlivedoc = m_document.elementsByTagName("kdenlivedoc").at(0);
258     QDomNode multitrack = m_document.elementsByTagName("multitrack").at(0);
259     QDomNodeList playlists = m_document.elementsByTagName("playlist");
260
261     m_startPos = kdenlivedoc.toElement().attribute("timeline_position").toInt();
262
263     QDomNode props = m_document.elementsByTagName("properties").at(0).toElement();
264     QString profile = props.toElement().attribute("videoprofile");
265     if (profile == "dv_wide") profile = "dv_pal_wide";
266     if (!profile.isEmpty()) {
267         setProfilePath(profile);
268     } else setProfilePath("dv_pal");
269
270     // move playlists outside of tractor and add the tracks instead
271     int max = playlists.count();
272     for (int i = 0; i < max; i++) {
273         QDomNode n = playlists.at(i);
274         westley.insertBefore(n, QDomNode());
275         QDomElement pl = n.toElement();
276         QDomElement track = m_document.createElement("track");
277         QString trackType = pl.attribute("hide");
278         if (!trackType.isEmpty()) track.setAttribute("hide", trackType);
279         QString playlist_id =  pl.attribute("id");
280         if (playlist_id.isEmpty()) {
281             playlist_id = "black_track";
282             pl.setAttribute("id", playlist_id);
283         }
284         track.setAttribute("producer", playlist_id);
285         tractor.appendChild(track);
286     }
287     tractor.removeChild(multitrack);
288
289     // audio track mixing transitions should not be added to track view, so add required attribute
290     QDomNodeList transitions = m_document.elementsByTagName("transition");
291     max = transitions.count();
292     for (int i = 0; i < max; i++) {
293         QDomElement tr = transitions.at(i).toElement();
294         if (tr.attribute("combine") == "1" && tr.attribute("mlt_service") == "mix") {
295             QDomElement property = m_document.createElement("property");
296             property.setAttribute("name", "internal_added");
297             QDomText value = m_document.createTextNode("237");
298             property.appendChild(value);
299             tr.appendChild(property);
300         } else {
301             // convert transition
302             QDomNamedNodeMap attrs = tr.attributes();
303             for (unsigned int j = 0; j < attrs.count(); j++) {
304                 QString attrName = attrs.item(j).nodeName();
305                 if (attrName != "in" && attrName != "out" && attrName != "id") {
306                     QDomElement property = m_document.createElement("property");
307                     property.setAttribute("name", attrName);
308                     QDomText value = m_document.createTextNode(attrs.item(j).nodeValue());
309                     property.appendChild(value);
310                     tr.appendChild(property);
311                 }
312             }
313         }
314     }
315
316     // move transitions after tracks
317     for (int i = 0; i < max; i++) {
318         tractor.insertAfter(transitions.at(0), QDomNode());
319     }
320
321     QDomElement markers = m_document.createElement("markers");
322
323     // change producer names
324     QDomNodeList producers = m_document.elementsByTagName("producer");
325     max = producers.count();
326     for (int i = 0; i < max; i++) {
327         QDomElement prod = producers.at(0).toElement();
328         QDomNode m = prod.firstChild();
329         if (!m.isNull() && m.toElement().tagName() == "markers") {
330             QDomNodeList prodchilds = m.childNodes();
331             int maxchild = prodchilds.count();
332             for (int k = 0; k < maxchild; k++) {
333                 QDomElement mark = prodchilds.at(0).toElement();
334                 mark.setAttribute("id", prod.attribute("id"));
335                 markers.insertAfter(mark, QDomNode());
336             }
337             prod.removeChild(m);
338         }
339         int duration = prod.attribute("duration").toInt();
340         if (duration > 0) prod.setAttribute("out", QString::number(duration));
341         westley.insertBefore(prod, QDomNode());
342     }
343
344     QDomNode westley0 = m_document.elementsByTagName("westley").at(0);
345     if (!markers.firstChild().isNull()) westley0.appendChild(markers);
346     westley0.removeChild(kdenlivedoc);
347
348     QDomNodeList elements = westley.childNodes();
349     max = elements.count();
350     for (int i = 0; i < max; i++) {
351         QDomElement prod = elements.at(0).toElement();
352         westley0.insertAfter(prod, QDomNode());
353     }
354
355     westley0.removeChild(westley);
356
357     //kDebug() << "/////////////////  CONVERTED DOC:";
358     //kDebug() << m_document.toString();
359     //kDebug() << "/////////////////  END CONVERTED DOC:";
360 }
361
362 QDomElement KdenliveDoc::documentInfoXml() {
363     QDomDocument doc;
364     QDomElement e;
365     QDomElement addedXml = doc.createElement("kdenlivedoc");
366     QDomElement markers = doc.createElement("markers");
367     addedXml.setAttribute("version", "0.7");
368     addedXml.setAttribute("profile", profilePath());
369     addedXml.setAttribute("position", m_render->seekPosition().frames(m_fps));
370     addedXml.setAttribute("zoom", m_zoom);
371     QList <DocClipBase*> list = m_clipManager->documentClipList();
372     for (int i = 0; i < list.count(); i++) {
373         e = list.at(i)->toXML();
374         e.setTagName("kdenlive_producer");
375         addedXml.appendChild(doc.importNode(e, true));
376         QList < CommentedTime > marks = list.at(i)->commentedSnapMarkers();
377         for (int j = 0; j < marks.count(); j++) {
378             QDomElement marker = doc.createElement("marker");
379             marker.setAttribute("time", marks.at(j).time().ms() / 1000);
380             marker.setAttribute("comment", marks.at(j).comment());
381             marker.setAttribute("id", e.attribute("id"));
382             markers.appendChild(marker);
383         }
384     }
385     addedXml.appendChild(markers);
386     if (!m_guidesXml.isNull()) addedXml.appendChild(doc.importNode(m_guidesXml, true));
387     //kDebug() << m_document.toString();
388     return addedXml;
389 }
390
391
392 ClipManager *KdenliveDoc::clipManager() {
393     return m_clipManager;
394 }
395
396 KUrl KdenliveDoc::projectFolder() const {
397     if (m_projectFolder.isEmpty()) return KUrl(KStandardDirs::locateLocal("appdata", "/projects/"));
398     return m_projectFolder;
399 }
400
401 QString KdenliveDoc::getDocumentStandard() {
402     //WARNING: this way to tell the video standard is a bit hackish...
403     if (m_profile.description.contains("pal", Qt::CaseInsensitive) || m_profile.description.contains("25", Qt::CaseInsensitive) || m_profile.description.contains("50", Qt::CaseInsensitive)) return "PAL";
404     return "NTSC";
405 }
406
407 QString KdenliveDoc::profilePath() const {
408     return m_profile.path;
409 }
410
411 void KdenliveDoc::setProfilePath(QString path) {
412     KdenliveSettings::setCurrent_profile(path);
413     m_profile = ProfilesDialog::getVideoProfile(path);
414     m_fps = (double) m_profile.frame_rate_num / m_profile.frame_rate_den;
415     m_width = m_profile.width;
416     m_height = m_profile.height;
417     KdenliveSettings::setProject_fps(m_fps);
418     kDebug() << "KDEnnlive document, init timecode from path: " << path << ",  " << m_fps;
419     if (m_fps == 30000.0 / 1001.0) m_timecode.setFormat(30, true);
420     else m_timecode.setFormat((int) m_fps);
421 }
422
423 void KdenliveDoc::setThumbsProgress(const QString &message, int progress) {
424     emit progressInfo(message, progress);
425 }
426
427 void KdenliveDoc::loadingProgressed() {
428     m_documentLoadingProgress += m_documentLoadingStep;
429     emit progressInfo(QString(), (int) m_documentLoadingProgress);
430 }
431
432 KUndoStack *KdenliveDoc::commandStack() {
433     return m_commandStack;
434 }
435
436 void KdenliveDoc::setRenderer(Render *render) {
437     m_render = render;
438     emit progressInfo(i18n("Loading playlist..."), 0);
439     qApp->processEvents();
440     if (m_render) m_render->setSceneList(m_scenelist, m_startPos);
441     emit progressInfo(QString(), -1);
442 }
443
444 Render *KdenliveDoc::renderer() {
445     return m_render;
446 }
447
448 void KdenliveDoc::updateClip(int id) {
449     emit updateClipDisplay(id);
450 }
451
452 void KdenliveDoc::updateAllProjectClips() {
453     QList <DocClipBase*> list = m_clipManager->documentClipList();
454     for (int i = 0; i < list.count(); i++)
455         emit updateClipDisplay(list.at(i)->getId());
456 }
457
458 int KdenliveDoc::getFramePos(QString duration) {
459     return m_timecode.getFrameCount(duration, m_fps);
460 }
461
462 QString KdenliveDoc::producerName(int id) {
463     QString result = "unnamed";
464     QDomNodeList prods = producersList();
465     int ct = prods.count();
466     for (int i = 0; i <  ct ; i++) {
467         QDomElement e = prods.item(i).toElement();
468         if (e.attribute("id") != "black" && e.attribute("id").toInt() == id) {
469             result = e.attribute("name");
470             if (result.isEmpty()) result = KUrl(e.attribute("resource")).fileName();
471             break;
472         }
473     }
474     return result;
475 }
476
477 void KdenliveDoc::setProducerDuration(int id, int duration) {
478     QDomNodeList prods = producersList();
479     int ct = prods.count();
480     for (int i = 0; i <  ct ; i++) {
481         QDomElement e = prods.item(i).toElement();
482         if (e.attribute("id") != "black" && e.attribute("id").toInt() == id) {
483             e.setAttribute("duration", QString::number(duration));
484             break;
485         }
486     }
487 }
488
489 int KdenliveDoc::getProducerDuration(int id) {
490     int result = 0;
491     QDomNodeList prods = producersList();
492     int ct = prods.count();
493     for (int i = 0; i <  ct ; i++) {
494         QDomElement e = prods.item(i).toElement();
495         if (e.attribute("id") != "black" && e.attribute("id").toInt() == id) {
496             result = e.attribute("duration").toInt();
497             break;
498         }
499     }
500     return result;
501 }
502
503
504 QDomDocument KdenliveDoc::generateSceneList() {
505     QDomDocument doc;
506     QDomElement westley = doc.createElement("westley");
507     doc.appendChild(westley);
508     QDomElement prod = doc.createElement("producer");
509 }
510
511 QDomDocument KdenliveDoc::toXml() const {
512     return m_document;
513 }
514
515 Timecode KdenliveDoc::timecode() const {
516     return m_timecode;
517 }
518
519 QDomNodeList KdenliveDoc::producersList() {
520     return m_document.elementsByTagName("producer");
521 }
522
523 void KdenliveDoc::backupMltPlaylist() {
524     if (m_render) m_scenelist = m_render->sceneList();
525 }
526
527 double KdenliveDoc::fps() const {
528     return m_fps;
529 }
530
531 int KdenliveDoc::width() const {
532     return m_width;
533 }
534
535 int KdenliveDoc::height() const {
536     return m_height;
537 }
538
539 KUrl KdenliveDoc::url() const {
540     return m_url;
541 }
542
543 void KdenliveDoc::setUrl(KUrl url) {
544     m_url = url;
545     QString directory = m_url.directory();
546     QString fileName = m_url.fileName();
547     m_recoveryUrl.setDirectory(directory);
548     m_recoveryUrl.setFileName("~" + fileName);
549 }
550
551 void KdenliveDoc::setModified(bool mod) {
552     if (!m_url.isEmpty() && mod && KdenliveSettings::crashrecovery()) {
553         m_autoSaveTimer->start(3000);
554     }
555     if (mod == m_modified) return;
556     m_modified = mod;
557     emit docModified(m_modified);
558 }
559
560 bool KdenliveDoc::isModified() const {
561     return m_modified;
562 }
563
564 QString KdenliveDoc::description() const {
565     if (m_url.isEmpty())
566         return i18n("Untitled") + " / " + m_profile.description;
567     else
568         return m_url.fileName() + " / " + m_profile.description;
569 }
570
571 void KdenliveDoc::addClip(const QDomElement &elem, const int clipId) {
572     DocClipBase *clip = new DocClipBase(m_clipManager, elem, clipId);
573     kDebug() << "/////////  DOCUM, CREATING NEW CLIP, ID:" << clipId << ", PAR ID:" << elem.attribute("groupid");
574     m_clipManager->addClip(clip);
575     emit addProjectClip(clip);
576 }
577
578 void KdenliveDoc::addFolder(const QString foldername, int clipId, bool edit) {
579     emit addProjectFolder(foldername, clipId, false, edit);
580 }
581
582 void KdenliveDoc::deleteFolder(const QString foldername, int clipId) {
583     emit addProjectFolder(foldername, clipId, true);
584 }
585
586 void KdenliveDoc::deleteProjectClip(QList <int> ids) {
587     for (int i = 0; i < ids.size(); ++i) {
588         emit deletTimelineClip(ids.at(i));
589         m_clipManager->slotDeleteClip(ids.at(i));
590     }
591     setModified(true);
592 }
593
594 void KdenliveDoc::deleteProjectFolder(QMap <QString, int> map) {
595     QMapIterator<QString, int> i(map);
596     while (i.hasNext()) {
597         i.next();
598         slotDeleteFolder(i.key(), i.value());
599     }
600     setModified(true);
601 }
602
603 void KdenliveDoc::deleteClip(const uint clipId) {
604     emit signalDeleteProjectClip(clipId);
605     m_clipManager->deleteClip(clipId);
606 }
607
608 void KdenliveDoc::slotAddClipFile(const KUrl url, const QString group, const int groupId) {
609     kDebug() << "/////////  DOCUM, ADD CLP: " << url;
610     m_clipManager->slotAddClipFile(url, group, groupId);
611     setModified(true);
612 }
613
614 void KdenliveDoc::slotAddTextClipFile(const QString path, const QString xml, const QString group, const int groupId) {
615     kDebug() << "/////////  DOCUM, ADD TXT CLP: " << path;
616     m_clipManager->slotAddTextClipFile(path, xml, group, groupId);
617     setModified(true);
618 }
619
620 void KdenliveDoc::slotAddFolder(const QString folderName) {
621     AddFolderCommand *command = new AddFolderCommand(this, folderName, m_clipManager->getFreeClipId(), true);
622     commandStack()->push(command);
623     setModified(true);
624 }
625
626 void KdenliveDoc::slotDeleteFolder(const QString folderName, const int id) {
627     AddFolderCommand *command = new AddFolderCommand(this, folderName, id, false);
628     commandStack()->push(command);
629     setModified(true);
630 }
631
632 void KdenliveDoc::slotEditFolder(const QString newfolderName, const QString oldfolderName, int clipId) {
633     EditFolderCommand *command = new EditFolderCommand(this, newfolderName, oldfolderName, clipId, false);
634     commandStack()->push(command);
635     setModified(true);
636 }
637
638 int KdenliveDoc::getFreeClipId() {
639     return m_clipManager->getFreeClipId();
640 }
641
642 DocClipBase *KdenliveDoc::getBaseClip(int clipId) {
643     return m_clipManager->getClipById(clipId);
644 }
645
646 void KdenliveDoc::slotAddColorClipFile(const QString name, const QString color, QString duration, const QString group, const int groupId) {
647     m_clipManager->slotAddColorClipFile(name, color, duration, group, groupId);
648     setModified(true);
649 }
650
651 void KdenliveDoc::slotAddSlideshowClipFile(const QString name, const QString path, int count, const QString duration, const bool loop, const bool fade, const QString &luma_duration, const QString &luma_file, const int softness, const QString group, const int groupId) {
652     m_clipManager->slotAddSlideshowClipFile(name, path, count, duration, loop, fade, luma_duration, luma_file, softness, group, groupId);
653     setModified(true);
654 }
655
656 void KdenliveDoc::slotCreateTextClip(QString group, int groupId) {
657     QString titlesFolder = projectFolder().path() + "/titles/";
658     KStandardDirs::makeDir(titlesFolder);
659     TitleWidget *dia_ui = new TitleWidget(KUrl(), titlesFolder, m_render, kapp->activeWindow());
660     if (dia_ui->exec() == QDialog::Accepted) {
661         QString titleName = "title";
662         int counter = 0;
663         QString path = titlesFolder + titleName + QString::number(counter).rightJustified(3, '0', false);
664         while (QFile::exists(path + ".kdenlivetitle")) {
665             counter++;
666             path = titlesFolder + titleName + QString::number(counter).rightJustified(3, '0', false);
667         }
668         QPixmap pix = dia_ui->renderedPixmap();
669         pix.save(path + ".png");
670         //dia_ui->saveTitle(path + ".kdenlivetitle");
671         slotAddTextClipFile(path, dia_ui->xml().toString(), QString(), -1);
672     }
673     delete dia_ui;
674 }
675
676 void KdenliveDoc::editTextClip(QString path, int id) {
677     DocClipBase *clip = m_clipManager->getClipById(id);
678     if (!clip) return;
679     TitleWidget *dia_ui = new TitleWidget(KUrl()/*path + ".kdenlivetitle")*/, path, m_render, kapp->activeWindow());
680     QDomDocument doc;
681     doc.setContent(clip->getProperty("xmldata"));
682     dia_ui->setXml(doc);
683     if (dia_ui->exec() == QDialog::Accepted) {
684         QPixmap pix = dia_ui->renderedPixmap();
685         pix.save(path + ".png");
686         //dia_ui->saveTitle(path + ".kdenlivetitle");
687         //slotAddClipFile(KUrl("/tmp/kdenlivetitle.png"), QString(), -1);
688         emit refreshClipThumbnail(id);
689     }
690     delete dia_ui;
691 }
692
693
694 #include "kdenlivedoc.moc"
695