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