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