]> git.sesse.net Git - kdenlive/blob - src/kdenlivedoc.cpp
* Be more clever when adding several clips to a project
[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, QUndoGroup *undoGroup, MainWindow *parent): QObject(parent), m_render(NULL), m_url(url), m_projectFolder(projectFolder), m_commandStack(new QUndoStack(undoGroup)), m_modified(false), m_documentLoadingProgress(0), m_documentLoadingStep(0.0), m_startPos(0), m_zoom(7) {
41     m_clipManager = new ClipManager(this);
42     if (!url.isEmpty()) {
43         QString tmpFile;
44         if (KIO::NetAccess::download(url.path(), tmpFile, parent)) {
45             QFile file(tmpFile);
46             m_document.setContent(&file, false);
47             file.close();
48             QDomNode infoXmlNode = m_document.elementsByTagName("kdenlivedoc").at(0);
49             QDomNode westley = m_document.elementsByTagName("westley").at(0);
50             if (!infoXmlNode.isNull()) {
51                 QDomElement infoXml = infoXmlNode.toElement();
52                 QString profilePath = infoXml.attribute("profile");
53                 m_startPos = infoXml.attribute("position").toInt();
54                 m_zoom = infoXml.attribute("zoom", "7").toInt();
55                 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                         QString prodId = m.toElement().attribute("id");
66                         if (prodId == "black" || prodId.startsWith("slowmotion"))
67                             pos++;
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                     QString prodId = e.attribute("id");
93                     if (!e.isNull() && prodId != "black" && prodId.toInt() > 0) {
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("always_active", "1");
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::setZoom(int factor) {
244     m_zoom = factor;
245 }
246
247 int KdenliveDoc::zoom() const {
248     return m_zoom;
249 }
250
251 void KdenliveDoc::convertDocument(double version) {
252     // Opening a old Kdenlive document
253     QDomNode westley = m_document.elementsByTagName("westley").at(1);
254     QDomNode tractor = m_document.elementsByTagName("tractor").at(0);
255     QDomNode kdenlivedoc = m_document.elementsByTagName("kdenlivedoc").at(0);
256     QDomNode multitrack = m_document.elementsByTagName("multitrack").at(0);
257     QDomNodeList playlists = m_document.elementsByTagName("playlist");
258
259     m_startPos = kdenlivedoc.toElement().attribute("timeline_position").toInt();
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     setProfilePath(profile);
265
266     // move playlists outside of tractor and add the tracks instead
267     int max = playlists.count();
268     for (int i = 0; i < max; i++) {
269         QDomNode n = playlists.at(i);
270         westley.insertBefore(n, QDomNode());
271         QDomElement pl = n.toElement();
272         QDomElement track = m_document.createElement("track");
273         QString trackType = pl.attribute("hide");
274         if (!trackType.isEmpty()) track.setAttribute("hide", trackType);
275         QString playlist_id =  pl.attribute("id");
276         if (playlist_id.isEmpty()) {
277             playlist_id = "black_track";
278             pl.setAttribute("id", playlist_id);
279         }
280         track.setAttribute("producer", playlist_id);
281         tractor.appendChild(track);
282     }
283     tractor.removeChild(multitrack);
284
285     // audio track mixing transitions should not be added to track view, so add required attribute
286     QDomNodeList transitions = m_document.elementsByTagName("transition");
287     max = transitions.count();
288     for (int i = 0; i < max; i++) {
289         QDomElement tr = transitions.at(i).toElement();
290         if (tr.attribute("combine") == "1" && tr.attribute("mlt_service") == "mix") {
291             QDomElement property = m_document.createElement("property");
292             property.setAttribute("name", "internal_added");
293             QDomText value = m_document.createTextNode("237");
294             property.appendChild(value);
295             tr.appendChild(property);
296         } else {
297             // convert transition
298             QDomNamedNodeMap attrs = tr.attributes();
299             for (unsigned int j = 0; j < attrs.count(); j++) {
300                 QString attrName = attrs.item(j).nodeName();
301                 if (attrName != "in" && attrName != "out" && attrName != "id") {
302                     QDomElement property = m_document.createElement("property");
303                     property.setAttribute("name", attrName);
304                     QDomText value = m_document.createTextNode(attrs.item(j).nodeValue());
305                     property.appendChild(value);
306                     tr.appendChild(property);
307                 }
308             }
309         }
310     }
311
312     // move transitions after tracks
313     for (int i = 0; i < max; i++) {
314         tractor.insertAfter(transitions.at(0), QDomNode());
315     }
316
317     // Fix filters format
318     QDomNodeList filters = m_document.elementsByTagName("filter");
319     max = filters.count();
320     for (int i = 0; i < max; i++) {
321         QDomElement filt = filters.at(i).toElement();
322         QDomNamedNodeMap attrs = filt.attributes();
323         for (int j = 0; j < attrs.count(); j++) {
324             QDomAttr a = attrs.item(j).toAttr();
325             if (!a.isNull()) {
326                 kDebug() << " FILTER; adding :" << a.name() << ":" << a.value();
327                 QDomElement e = m_document.createElement("property");
328                 e.setAttribute("name", a.name());
329                 QDomText value = m_document.createTextNode(a.value());
330                 e.appendChild(value);
331                 filt.appendChild(e);
332             }
333         }
334     }
335
336
337     // move markers to a global list
338     QDomElement markers = m_document.createElement("markers");
339     QDomNodeList producers = m_document.elementsByTagName("producer");
340     max = producers.count();
341     for (int i = 0; i < max; i++) {
342         QDomElement prod = producers.at(0).toElement();
343         QDomNode m = prod.firstChild();
344         if (!m.isNull() && m.toElement().tagName() == "markers") {
345             QDomNodeList prodchilds = m.childNodes();
346             int maxchild = prodchilds.count();
347             for (int k = 0; k < maxchild; k++) {
348                 QDomElement mark = prodchilds.at(0).toElement();
349                 mark.setAttribute("id", prod.attribute("id"));
350                 markers.insertAfter(mark, QDomNode());
351             }
352             prod.removeChild(m);
353         }
354         int duration = prod.attribute("duration").toInt();
355         if (duration > 0) prod.setAttribute("out", QString::number(duration));
356         westley.insertBefore(prod, QDomNode());
357     }
358
359     QDomNode westley0 = m_document.elementsByTagName("westley").at(0);
360     if (!markers.firstChild().isNull()) westley0.appendChild(markers);
361     westley0.removeChild(kdenlivedoc);
362
363     QDomNodeList elements = westley.childNodes();
364     max = elements.count();
365     for (int i = 0; i < max; i++) {
366         QDomElement prod = elements.at(0).toElement();
367         westley0.insertAfter(prod, QDomNode());
368     }
369
370     westley0.removeChild(westley);
371
372     //kDebug() << "/////////////////  CONVERTED DOC:";
373     //kDebug() << m_document.toString();
374     //kDebug() << "/////////////////  END CONVERTED DOC:";
375 }
376
377 QDomElement KdenliveDoc::documentInfoXml() {
378     QDomDocument doc;
379     QDomElement e;
380     QDomElement addedXml = doc.createElement("kdenlivedoc");
381     QDomElement markers = doc.createElement("markers");
382     addedXml.setAttribute("version", "0.7");
383     addedXml.setAttribute("profile", profilePath());
384     addedXml.setAttribute("position", m_render->seekPosition().frames(m_fps));
385     addedXml.setAttribute("zoom", m_zoom);
386     QList <DocClipBase*> list = m_clipManager->documentClipList();
387     for (int i = 0; i < list.count(); i++) {
388         e = list.at(i)->toXML();
389         e.setTagName("kdenlive_producer");
390         addedXml.appendChild(doc.importNode(e, true));
391         QList < CommentedTime > marks = list.at(i)->commentedSnapMarkers();
392         for (int j = 0; j < marks.count(); j++) {
393             QDomElement marker = doc.createElement("marker");
394             marker.setAttribute("time", marks.at(j).time().ms() / 1000);
395             marker.setAttribute("comment", marks.at(j).comment());
396             marker.setAttribute("id", e.attribute("id"));
397             markers.appendChild(marker);
398         }
399     }
400     addedXml.appendChild(markers);
401     if (!m_guidesXml.isNull()) addedXml.appendChild(doc.importNode(m_guidesXml, true));
402     //kDebug() << m_document.toString();
403     return addedXml;
404 }
405
406
407 ClipManager *KdenliveDoc::clipManager() {
408     return m_clipManager;
409 }
410
411 KUrl KdenliveDoc::projectFolder() const {
412     if (m_projectFolder.isEmpty()) return KUrl(KStandardDirs::locateLocal("appdata", "/projects/"));
413     return m_projectFolder;
414 }
415
416 QString KdenliveDoc::getDocumentStandard() {
417     //WARNING: this way to tell the video standard is a bit hackish...
418     if (m_profile.description.contains("pal", Qt::CaseInsensitive) || m_profile.description.contains("25", Qt::CaseInsensitive) || m_profile.description.contains("50", Qt::CaseInsensitive)) return "PAL";
419     return "NTSC";
420 }
421
422 QString KdenliveDoc::profilePath() const {
423     return m_profile.path;
424 }
425
426 void KdenliveDoc::setProfilePath(QString path) {
427     if (path.isEmpty()) path = KdenliveSettings::default_profile();
428     if (path.isEmpty()) path = "dv_pal";
429     m_profile = ProfilesDialog::getVideoProfile(path);
430     KdenliveSettings::setProject_display_ratio((double) m_profile.display_aspect_num / m_profile.display_aspect_den);
431     m_fps = (double) m_profile.frame_rate_num / m_profile.frame_rate_den;
432     m_width = m_profile.width;
433     m_height = m_profile.height;
434     kDebug() << "KDEnnlive document, init timecode from path: " << path << ",  " << m_fps;
435     if (m_fps == 30000.0 / 1001.0) m_timecode.setFormat(30, true);
436     else m_timecode.setFormat((int) m_fps);
437 }
438
439 const double KdenliveDoc::dar() {
440     return (double) m_profile.display_aspect_num / m_profile.display_aspect_den;
441 }
442
443 void KdenliveDoc::setThumbsProgress(const QString &message, int progress) {
444     emit progressInfo(message, progress);
445 }
446
447 void KdenliveDoc::loadingProgressed() {
448     m_documentLoadingProgress += m_documentLoadingStep;
449     emit progressInfo(QString(), (int) m_documentLoadingProgress);
450 }
451
452 QUndoStack *KdenliveDoc::commandStack() {
453     return m_commandStack;
454 }
455
456 void KdenliveDoc::setRenderer(Render *render) {
457     m_render = render;
458     emit progressInfo(i18n("Loading playlist..."), 0);
459     qApp->processEvents();
460     if (m_render) m_render->setSceneList(m_document.toString(), m_startPos);
461     emit progressInfo(QString(), -1);
462 }
463
464 Render *KdenliveDoc::renderer() {
465     return m_render;
466 }
467
468 void KdenliveDoc::updateClip(int id) {
469     emit updateClipDisplay(id);
470 }
471
472 void KdenliveDoc::updateAllProjectClips() {
473     QList <DocClipBase*> list = m_clipManager->documentClipList();
474     for (int i = 0; i < list.count(); i++)
475         emit updateClipDisplay(list.at(i)->getId());
476 }
477
478 int KdenliveDoc::getFramePos(QString duration) {
479     return m_timecode.getFrameCount(duration, m_fps);
480 }
481
482 QString KdenliveDoc::producerName(int id) {
483     QString result = "unnamed";
484     QDomNodeList prods = producersList();
485     int ct = prods.count();
486     for (int i = 0; i <  ct ; i++) {
487         QDomElement e = prods.item(i).toElement();
488         if (e.attribute("id") != "black" && e.attribute("id").toInt() == id) {
489             result = e.attribute("name");
490             if (result.isEmpty()) result = KUrl(e.attribute("resource")).fileName();
491             break;
492         }
493     }
494     return result;
495 }
496
497 void KdenliveDoc::setProducerDuration(int id, int duration) {
498     QDomNodeList prods = producersList();
499     int ct = prods.count();
500     for (int i = 0; i <  ct ; i++) {
501         QDomElement e = prods.item(i).toElement();
502         if (e.attribute("id") != "black" && e.attribute("id").toInt() == id) {
503             e.setAttribute("duration", QString::number(duration));
504             break;
505         }
506     }
507 }
508
509 int KdenliveDoc::getProducerDuration(int id) {
510     int result = 0;
511     QDomNodeList prods = producersList();
512     int ct = prods.count();
513     for (int i = 0; i <  ct ; i++) {
514         QDomElement e = prods.item(i).toElement();
515         if (e.attribute("id") != "black" && e.attribute("id").toInt() == id) {
516             result = e.attribute("duration").toInt();
517             break;
518         }
519     }
520     return result;
521 }
522
523
524 QDomDocument KdenliveDoc::generateSceneList() {
525     QDomDocument doc;
526     QDomElement westley = doc.createElement("westley");
527     doc.appendChild(westley);
528     QDomElement prod = doc.createElement("producer");
529 }
530
531 QDomDocument KdenliveDoc::toXml() const {
532     return m_document;
533 }
534
535 Timecode KdenliveDoc::timecode() const {
536     return m_timecode;
537 }
538
539 QDomNodeList KdenliveDoc::producersList() {
540     return m_document.elementsByTagName("producer");
541 }
542
543 void KdenliveDoc::backupMltPlaylist() {
544     if (m_render) m_scenelist = m_render->sceneList();
545 }
546
547 double KdenliveDoc::fps() const {
548     return m_fps;
549 }
550
551 int KdenliveDoc::width() const {
552     return m_width;
553 }
554
555 int KdenliveDoc::height() const {
556     return m_height;
557 }
558
559 KUrl KdenliveDoc::url() const {
560     return m_url;
561 }
562
563 void KdenliveDoc::setUrl(KUrl url) {
564     m_url = url;
565     QString directory = m_url.directory();
566     QString fileName = m_url.fileName();
567     m_recoveryUrl.setDirectory(directory);
568     m_recoveryUrl.setFileName("~" + fileName);
569 }
570
571 void KdenliveDoc::setModified(bool mod) {
572     if (!m_url.isEmpty() && mod && KdenliveSettings::crashrecovery()) {
573         m_autoSaveTimer->start(3000);
574     }
575     if (mod == m_modified) return;
576     m_modified = mod;
577     emit docModified(m_modified);
578 }
579
580 bool KdenliveDoc::isModified() const {
581     return m_modified;
582 }
583
584 QString KdenliveDoc::description() const {
585     if (m_url.isEmpty())
586         return i18n("Untitled") + " / " + m_profile.description;
587     else
588         return m_url.fileName() + " / " + m_profile.description;
589 }
590
591 void KdenliveDoc::addClip(const QDomElement &elem, const int clipId) {
592     DocClipBase *clip = new DocClipBase(m_clipManager, elem, clipId);
593     kDebug() << "/////////  DOCUM, CREATING NEW CLIP, ID:" << clipId << ", PAR ID:" << elem.attribute("groupid");
594     m_clipManager->addClip(clip);
595     emit addProjectClip(clip);
596 }
597
598 void KdenliveDoc::addFolder(const QString foldername, int clipId, bool edit) {
599     emit addProjectFolder(foldername, clipId, false, edit);
600 }
601
602 void KdenliveDoc::deleteFolder(const QString foldername, int clipId) {
603     emit addProjectFolder(foldername, clipId, true);
604 }
605
606 void KdenliveDoc::deleteProjectClip(QList <int> ids) {
607     for (int i = 0; i < ids.size(); ++i) {
608         emit deletTimelineClip(ids.at(i));
609         m_clipManager->slotDeleteClip(ids.at(i));
610     }
611     setModified(true);
612 }
613
614 void KdenliveDoc::deleteProjectFolder(QMap <QString, int> map) {
615     QMapIterator<QString, int> i(map);
616     while (i.hasNext()) {
617         i.next();
618         slotDeleteFolder(i.key(), i.value());
619     }
620     setModified(true);
621 }
622
623 void KdenliveDoc::deleteClip(const uint clipId) {
624     emit signalDeleteProjectClip(clipId);
625     m_clipManager->deleteClip(clipId);
626 }
627
628 void KdenliveDoc::slotAddClipList(const KUrl::List urls, const QString group, const int groupId) {
629     m_clipManager->slotAddClipList(urls, group, groupId);
630     emit selectLastAddedClip(m_clipManager->lastClipId());
631     setModified(true);
632 }
633
634
635 void KdenliveDoc::slotAddClipFile(const KUrl url, const QString group, const int groupId) {
636     kDebug() << "/////////  DOCUM, ADD CLP: " << url;
637     m_clipManager->slotAddClipFile(url, group, groupId);
638     emit selectLastAddedClip(m_clipManager->lastClipId());
639     setModified(true);
640 }
641
642 void KdenliveDoc::slotAddTextClipFile(const QString path, const QString xml, const QString group, const int groupId) {
643     kDebug() << "/////////  DOCUM, ADD TXT CLP: " << path;
644     m_clipManager->slotAddTextClipFile(path, xml, group, groupId);
645     setModified(true);
646 }
647
648 void KdenliveDoc::slotAddFolder(const QString folderName) {
649     AddFolderCommand *command = new AddFolderCommand(this, folderName, m_clipManager->getFreeClipId(), true);
650     commandStack()->push(command);
651     setModified(true);
652 }
653
654 void KdenliveDoc::slotDeleteFolder(const QString folderName, const int id) {
655     AddFolderCommand *command = new AddFolderCommand(this, folderName, id, false);
656     commandStack()->push(command);
657     setModified(true);
658 }
659
660 void KdenliveDoc::slotEditFolder(const QString newfolderName, const QString oldfolderName, int clipId) {
661     EditFolderCommand *command = new EditFolderCommand(this, newfolderName, oldfolderName, clipId, false);
662     commandStack()->push(command);
663     setModified(true);
664 }
665
666 int KdenliveDoc::getFreeClipId() {
667     return m_clipManager->getFreeClipId();
668 }
669
670 DocClipBase *KdenliveDoc::getBaseClip(int clipId) {
671     return m_clipManager->getClipById(clipId);
672 }
673
674 void KdenliveDoc::slotAddColorClipFile(const QString name, const QString color, QString duration, const QString group, const int groupId) {
675     m_clipManager->slotAddColorClipFile(name, color, duration, group, groupId);
676     setModified(true);
677 }
678
679 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) {
680     m_clipManager->slotAddSlideshowClipFile(name, path, count, duration, loop, fade, luma_duration, luma_file, softness, group, groupId);
681     setModified(true);
682 }
683
684 void KdenliveDoc::slotCreateTextClip(QString group, int groupId) {
685     QString titlesFolder = projectFolder().path() + "/titles/";
686     KStandardDirs::makeDir(titlesFolder);
687     TitleWidget *dia_ui = new TitleWidget(KUrl(), titlesFolder, m_render, kapp->activeWindow());
688     if (dia_ui->exec() == QDialog::Accepted) {
689         QString titleName = "title";
690         int counter = 0;
691         QString path = titlesFolder + titleName + QString::number(counter).rightJustified(3, '0', false);
692         while (QFile::exists(path + ".kdenlivetitle")) {
693             counter++;
694             path = titlesFolder + titleName + QString::number(counter).rightJustified(3, '0', false);
695         }
696         QPixmap pix = dia_ui->renderedPixmap();
697         pix.save(path + ".png");
698         //dia_ui->saveTitle(path + ".kdenlivetitle");
699         slotAddTextClipFile(path, dia_ui->xml().toString(), QString(), -1);
700     }
701     delete dia_ui;
702 }
703
704 void KdenliveDoc::editTextClip(QString path, int id) {
705     DocClipBase *clip = m_clipManager->getClipById(id);
706     if (!clip) return;
707     TitleWidget *dia_ui = new TitleWidget(KUrl()/*path + ".kdenlivetitle")*/, path, m_render, kapp->activeWindow());
708     QDomDocument doc;
709     doc.setContent(clip->getProperty("xmldata"));
710     dia_ui->setXml(doc);
711     if (dia_ui->exec() == QDialog::Accepted) {
712         QPixmap pix = dia_ui->renderedPixmap();
713         pix.save(path + ".png");
714         //dia_ui->saveTitle(path + ".kdenlivetitle");
715         //slotAddClipFile(KUrl("/tmp/kdenlivetitle.png"), QString(), -1);
716         emit refreshClipThumbnail(id);
717     }
718     delete dia_ui;
719 }
720
721
722 #include "kdenlivedoc.moc"
723