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