]> git.sesse.net Git - kdenlive/blob - src/kdenlivedoc.cpp
Cleanup some mess introduced by last commit, looking for missing slideshow clips...
[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 <QCryptographicHash>
21 #include <QFile>
22
23 #include <KDebug>
24 #include <KStandardDirs>
25 #include <KMessageBox>
26 #include <KLocale>
27 #include <KFileDialog>
28 #include <KIO/NetAccess>
29 #include <KApplication>
30
31
32 #include <mlt++/Mlt.h>
33
34 #include "kdenlivedoc.h"
35 #include "docclipbase.h"
36 #include "profilesdialog.h"
37 #include "kdenlivesettings.h"
38 #include "renderer.h"
39 #include "clipmanager.h"
40 #include "addfoldercommand.h"
41 #include "editfoldercommand.h"
42 #include "titlewidget.h"
43 #include "mainwindow.h"
44
45
46 KdenliveDoc::KdenliveDoc(const KUrl &url, const KUrl &projectFolder, QUndoGroup *undoGroup, const QString &profileName, const QPoint tracks, 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), m_autosave(NULL) {
47     m_clipManager = new ClipManager(this);
48     if (!url.isEmpty()) {
49         QString tmpFile;
50         if (KIO::NetAccess::download(url.path(), tmpFile, parent)) {
51             QFile file(tmpFile);
52             m_document.setContent(&file, false);
53             file.close();
54             QDomNode infoXmlNode = m_document.elementsByTagName("kdenlivedoc").at(0);
55             QDomNode westley = m_document.elementsByTagName("westley").at(0);
56             if (!infoXmlNode.isNull()) {
57                 QDomElement infoXml = infoXmlNode.toElement();
58                 QString profilePath = infoXml.attribute("profile");
59                 m_startPos = infoXml.attribute("position").toInt();
60                 m_zoom = infoXml.attribute("zoom", "7").toInt();
61                 setProfilePath(profilePath);
62                 double version = infoXml.attribute("version").toDouble();
63                 if (version < 0.8) convertDocument(version);
64                 else {
65                     //delete all mlt producers and instead, use Kdenlive saved producers
66                     /*QDomNodeList prods = m_document.elementsByTagName("producer");
67                     int maxprod = prods.count();
68                     int pos = 0;
69                     for (int i = 0; i < maxprod; i++) {
70                         QDomNode m = prods.at(pos);
71                         QString prodId = m.toElement().attribute("id");
72                         if (prodId == "black" || prodId.startsWith("slowmotion"))
73                             pos++;
74                         else westley.removeChild(m);
75                     }*/
76                     /*prods = m_document.elementsByTagName("kdenlive_producer");
77                     maxprod = prods.count();
78                     for (int i = 0; i < maxprod; i++) {
79                         prods.at(0).toElement().setTagName("producer");
80                         westley.insertBefore(prods.at(0), QDomNode());
81                     }*/
82                 }
83                 QDomElement e;
84                 QDomNodeList producers = m_document.elementsByTagName("producer");
85                 QDomNodeList infoproducers = m_document.elementsByTagName("kdenlive_producer");
86                 const int max = producers.count();
87                 const int infomax = infoproducers.count();
88
89                 if (max > 0) {
90                     m_documentLoadingStep = 100.0 / (max + infomax + m_document.elementsByTagName("entry").count());
91                     parent->slotGotProgressInfo(i18n("Loading project clips"), (int) m_documentLoadingProgress);
92                 }
93
94                 for (int i = 0; i < max; i++) {
95                     e = producers.item(i).cloneNode().toElement();
96                     if (m_documentLoadingStep > 0) {
97                         m_documentLoadingProgress += m_documentLoadingStep;
98                         parent->slotGotProgressInfo(QString(), (int) m_documentLoadingProgress);
99                         //qApp->processEvents();
100                     }
101                     QString prodId = e.attribute("id");
102                     if (!e.isNull() && prodId != "black" && !prodId.startsWith("slowmotion")/*&& prodId.toInt() > 0*/) {
103                         // addClip(e, prodId, false);
104                         kDebug() << "// PROD: " << prodId;
105                     }
106                 }
107
108                 for (int i = 0; i < infomax; i++) {
109                     e = infoproducers.item(i).cloneNode().toElement();
110                     if (m_documentLoadingStep > 0) {
111                         m_documentLoadingProgress += m_documentLoadingStep;
112                         parent->slotGotProgressInfo(QString(), (int) m_documentLoadingProgress);
113                         //qApp->processEvents();
114                     }
115                     QString prodId = e.attribute("id");
116                     if (!e.isNull() && prodId != "black" && !prodId.startsWith("slowmotion")) {
117                         e.setTagName("producer");
118                         addClipInfo(e, prodId);
119                         kDebug() << "// NLIVE PROD: " << prodId;
120                     }
121                 }
122
123                 QDomNode markers = m_document.elementsByTagName("markers").at(0);
124                 if (!markers.isNull()) {
125                     QDomNodeList markerslist = markers.childNodes();
126                     int maxchild = markerslist.count();
127                     for (int k = 0; k < maxchild; k++) {
128                         e = markerslist.at(k).toElement();
129                         if (e.tagName() == "marker") {
130                             m_clipManager->getClipById(e.attribute("id"))->addSnapMarker(GenTime(e.attribute("time").toDouble()), e.attribute("comment"));
131                         }
132                     }
133                     westley.removeChild(markers);
134                 }
135                 m_document.removeChild(infoXmlNode);
136
137                 kDebug() << "Reading file: " << url.path() << ", found clips: " << producers.count();
138             } else {
139                 parent->slotGotProgressInfo(i18n("File %1 is not a Kdenlive project file."), 100);
140                 kWarning() << "  NO KDENLIVE INFO FOUND IN FILE: " << url.path();
141                 m_document = createEmptyDocument(tracks.x(), tracks.y());
142                 setProfilePath(profileName);
143             }
144             KIO::NetAccess::removeTempFile(tmpFile);
145         } else {
146             KMessageBox::error(parent, KIO::NetAccess::lastErrorString());
147             parent->slotGotProgressInfo(i18n("File %1 is not a Kdenlive project file."), 100);
148             m_document = createEmptyDocument(tracks.x(), tracks.y());
149             setProfilePath(profileName);
150         }
151     } else {
152         m_document = createEmptyDocument(tracks.x(), tracks.y());
153         setProfilePath(profileName);
154     }
155     m_scenelist = m_document.toString();
156     kDebug() << "KDEnnlive document, init timecode: " << m_fps;
157     if (m_fps == 30000.0 / 1001.0) m_timecode.setFormat(30, true);
158     else m_timecode.setFormat((int) m_fps);
159
160     m_autoSaveTimer = new QTimer(this);
161     m_autoSaveTimer->setSingleShot(true);
162     connect(m_autoSaveTimer, SIGNAL(timeout()), this, SLOT(slotAutoSave()));
163 }
164
165 KdenliveDoc::~KdenliveDoc() {
166     delete m_commandStack;
167     delete m_clipManager;
168     delete m_autoSaveTimer;
169     m_autosave->remove();
170 }
171
172 QDomDocument KdenliveDoc::createEmptyDocument(const int videotracks, const int audiotracks) {
173     // Creating new document
174     QDomDocument doc;
175     QDomElement westley = doc.createElement("westley");
176     doc.appendChild(westley);
177
178     QDomElement tractor = doc.createElement("tractor");
179     tractor.setAttribute("id", "maintractor");
180     QDomElement multitrack = doc.createElement("multitrack");
181     QDomElement playlist = doc.createElement("playlist");
182     playlist.setAttribute("id", "black_track");
183     westley.appendChild(playlist);
184
185
186     // create playlists
187     int total = audiotracks + videotracks + 1;
188
189     for (int i = 1; i < total; i++) {
190         QDomElement playlist = doc.createElement("playlist");
191         playlist.setAttribute("id", "playlist" + QString::number(i));
192         westley.appendChild(playlist);
193     }
194
195     QDomElement track0 = doc.createElement("track");
196     track0.setAttribute("producer", "black_track");
197     tractor.appendChild(track0);
198
199     // create audio tracks
200     for (int i = 1; i < audiotracks + 1; i++) {
201         QDomElement track = doc.createElement("track");
202         track.setAttribute("producer", "playlist" + QString::number(i));
203         track.setAttribute("hide", "video");
204         tractor.appendChild(track);
205     }
206
207     // create video tracks
208     for (int i = audiotracks + 1; i < total; i++) {
209         QDomElement track = doc.createElement("track");
210         track.setAttribute("producer", "playlist" + QString::number(i));
211         tractor.appendChild(track);
212     }
213
214     for (uint i = 2; i < total ; i++) {
215         QDomElement transition = doc.createElement("transition");
216         transition.setAttribute("always_active", "1");
217
218         QDomElement property = doc.createElement("property");
219         property.setAttribute("name", "a_track");
220         QDomText value = doc.createTextNode(QString::number(1));
221         property.appendChild(value);
222         transition.appendChild(property);
223
224         property = doc.createElement("property");
225         property.setAttribute("name", "b_track");
226         value = doc.createTextNode(QString::number(i));
227         property.appendChild(value);
228         transition.appendChild(property);
229
230         property = doc.createElement("property");
231         property.setAttribute("name", "mlt_service");
232         value = doc.createTextNode("mix");
233         property.appendChild(value);
234         transition.appendChild(property);
235
236         property = doc.createElement("property");
237         property.setAttribute("name", "combine");
238         value = doc.createTextNode("1");
239         property.appendChild(value);
240         transition.appendChild(property);
241
242         property = doc.createElement("property");
243         property.setAttribute("name", "internal_added");
244         value = doc.createTextNode("237");
245         property.appendChild(value);
246         transition.appendChild(property);
247         tractor.appendChild(transition);
248     }
249     westley.appendChild(tractor);
250     return doc;
251 }
252
253
254 void KdenliveDoc::syncGuides(QList <Guide *> guides) {
255     QDomDocument doc;
256     QDomElement e;
257     m_guidesXml.clear();
258     m_guidesXml = doc.createElement("guides");
259
260     for (int i = 0; i < guides.count(); i++) {
261         e = doc.createElement("guide");
262         e.setAttribute("time", guides.at(i)->position().ms() / 1000);
263         e.setAttribute("comment", guides.at(i)->label());
264         m_guidesXml.appendChild(e);
265     }
266     emit guidesUpdated();
267 }
268
269 QDomElement KdenliveDoc::guidesXml() const {
270     return m_guidesXml;
271 }
272
273 void KdenliveDoc::slotAutoSave() {
274     if (m_render) {
275         if (!m_autosave->isOpen() && !m_autosave->open(QIODevice::ReadWrite)) {
276             // show error: could not open the autosave file
277             kDebug() << "ERROR; CANNOT CREATE AUTOSAVE FILE";
278         }
279         kDebug() << "// AUTOSAVE FILE: " << m_autosave->fileName();
280         QDomDocument doc;
281         doc.setContent(m_render->sceneList());
282         saveSceneList(m_autosave->fileName(), doc);
283     }
284 }
285
286 void KdenliveDoc::setZoom(int factor) {
287     m_zoom = factor;
288 }
289
290 int KdenliveDoc::zoom() const {
291     return m_zoom;
292 }
293
294 void KdenliveDoc::convertDocument(double version) {
295     kDebug() << "Opening a document with version " << version;
296     // Opening a old Kdenlive document
297     if (version == 0.7) {
298         kDebug() << "Unable to open document with version " << version;
299         // TODO: convert 0.7 files to the new document format.
300         return;
301     }
302     QDomNode westley = m_document.elementsByTagName("westley").at(1);
303     QDomNode tractor = m_document.elementsByTagName("tractor").at(0);
304     QDomNode kdenlivedoc = m_document.elementsByTagName("kdenlivedoc").at(0);
305     QDomElement kdenlivedoc_old = kdenlivedoc.cloneNode(true).toElement(); // Needed for folders
306     QDomNode multitrack = m_document.elementsByTagName("multitrack").at(0);
307     QDomNodeList playlists = m_document.elementsByTagName("playlist");
308
309     m_startPos = kdenlivedoc.toElement().attribute("timeline_position").toInt();
310
311     QDomNode props = m_document.elementsByTagName("properties").at(0).toElement();
312     QString profile = props.toElement().attribute("videoprofile");
313     if (profile == "dv_wide") profile = "dv_pal_wide";
314     setProfilePath(profile);
315
316     // move playlists outside of tractor and add the tracks instead
317     int max = playlists.count();
318     for (int i = 0; i < max; i++) {
319         QDomNode n = playlists.at(i);
320         westley.insertBefore(n, QDomNode());
321         QDomElement pl = n.toElement();
322         QDomElement track = m_document.createElement("track");
323         QString trackType = pl.attribute("hide");
324         if (!trackType.isEmpty()) track.setAttribute("hide", trackType);
325         QString playlist_id =  pl.attribute("id");
326         if (playlist_id.isEmpty()) {
327             playlist_id = "black_track";
328             pl.setAttribute("id", playlist_id);
329         }
330         track.setAttribute("producer", playlist_id);
331         //tractor.appendChild(track);
332 #define KEEP_TRACK_ORDER 1
333 #ifdef KEEP_TRACK_ORDER
334         tractor.insertAfter(track, QDomNode());
335 #else
336         // Insert the new track in an order that hopefully matches the 3 video, then 2 audio tracks of Kdenlive 0.7.0
337         // insertion sort - O( tracks*tracks )
338         // Note, this breaks _all_ transitions - but you can move them up and down afterwards.
339         QDomElement tractor_elem = tractor.toElement();
340         if (! tractor_elem.isNull()) {
341             QDomNodeList tracks = tractor_elem.elementsByTagName("track");
342             int size = tracks.size();
343             if (size == 0) {
344                 tractor.insertAfter(track, QDomNode());
345             } else {
346                 bool inserted = false;
347                 for (int i = 0; i < size; ++i) {
348                     QDomElement track_elem = tracks.at(i).toElement();
349                     if (track_elem.isNull()) {
350                         tractor.insertAfter(track, QDomNode());
351                         inserted = true;
352                         break;
353                     } else {
354                         kDebug() << "playlist_id: " << playlist_id << " producer:" << track_elem.attribute("producer");
355                         if (playlist_id < track_elem.attribute("producer")) {
356                             tractor.insertBefore(track, track_elem);
357                             inserted = true;
358                             break;
359                         }
360                     }
361                 }
362                 // Reach here, no insertion, insert last
363                 if (!inserted) {
364                     tractor.insertAfter(track, QDomNode());
365                 }
366             }
367         } else {
368             kWarning() << "tractor was not a QDomElement";
369             tractor.insertAfter(track, QDomNode());
370         }
371 #endif
372     }
373     tractor.removeChild(multitrack);
374
375     // audio track mixing transitions should not be added to track view, so add required attribute
376     QDomNodeList transitions = m_document.elementsByTagName("transition");
377     max = transitions.count();
378     for (int i = 0; i < max; i++) {
379         QDomElement tr = transitions.at(i).toElement();
380         if (tr.attribute("combine") == "1" && tr.attribute("mlt_service") == "mix") {
381             QDomElement property = m_document.createElement("property");
382             property.setAttribute("name", "internal_added");
383             QDomText value = m_document.createTextNode("237");
384             property.appendChild(value);
385             tr.appendChild(property);
386         } else {
387             // convert transition
388             QDomNamedNodeMap attrs = tr.attributes();
389             for (unsigned int j = 0; j < attrs.count(); j++) {
390                 QString attrName = attrs.item(j).nodeName();
391                 if (attrName != "in" && attrName != "out" && attrName != "id") {
392                     QDomElement property = m_document.createElement("property");
393                     property.setAttribute("name", attrName);
394                     QDomText value = m_document.createTextNode(attrs.item(j).nodeValue());
395                     property.appendChild(value);
396                     tr.appendChild(property);
397                 }
398             }
399         }
400     }
401
402     // move transitions after tracks
403     for (int i = 0; i < max; i++) {
404         tractor.insertAfter(transitions.at(0), QDomNode());
405     }
406
407     // Fix filters format
408     QDomNodeList entries = m_document.elementsByTagName("entry");
409     max = entries.count();
410     for (int i = 0; i < max; i++) {
411         QString last_id;
412         int effectix = 0;
413         QDomNode m = entries.at(i).firstChild();
414         while (!m.isNull()) {
415             if (m.toElement().tagName() == "filter") {
416                 QDomElement filt = m.toElement();
417                 QDomNamedNodeMap attrs = filt.attributes();
418                 QString current_id = filt.attribute("kdenlive_id");
419                 if (current_id != last_id) {
420                     effectix++;
421                     last_id = current_id;
422                 }
423                 QDomElement e = m_document.createElement("property");
424                 e.setAttribute("name", "kdenlive_ix");
425                 QDomText value = m_document.createTextNode(QString::number(effectix));
426                 e.appendChild(value);
427                 filt.appendChild(e);
428                 for (int j = 0; j < attrs.count(); j++) {
429                     QDomAttr a = attrs.item(j).toAttr();
430                     if (!a.isNull()) {
431                         kDebug() << " FILTER; adding :" << a.name() << ":" << a.value();
432                         QDomElement e = m_document.createElement("property");
433                         e.setAttribute("name", a.name());
434                         QDomText value = m_document.createTextNode(a.value());
435                         e.appendChild(value);
436                         filt.appendChild(e);
437
438                     }
439                 }
440             }
441             m = m.nextSibling();
442         }
443     }
444
445     /*
446         QDomNodeList filters = m_document.elementsByTagName("filter");
447         max = filters.count();
448         QString last_id;
449         int effectix = 0;
450         for (int i = 0; i < max; i++) {
451             QDomElement filt = filters.at(i).toElement();
452             QDomNamedNodeMap attrs = filt.attributes();
453      QString current_id = filt.attribute("kdenlive_id");
454      if (current_id != last_id) {
455          effectix++;
456          last_id = current_id;
457      }
458      QDomElement e = m_document.createElement("property");
459             e.setAttribute("name", "kdenlive_ix");
460             QDomText value = m_document.createTextNode(QString::number(1));
461             e.appendChild(value);
462             filt.appendChild(e);
463             for (int j = 0; j < attrs.count(); j++) {
464                 QDomAttr a = attrs.item(j).toAttr();
465                 if (!a.isNull()) {
466                     kDebug() << " FILTER; adding :" << a.name() << ":" << a.value();
467                     QDomElement e = m_document.createElement("property");
468                     e.setAttribute("name", a.name());
469                     QDomText value = m_document.createTextNode(a.value());
470                     e.appendChild(value);
471                     filt.appendChild(e);
472                 }
473             }
474         }*/
475
476     // fix slowmotion
477     QDomNodeList producers = westley.toElement().elementsByTagName("producer");
478     max = producers.count();
479     for (int i = 0; i < max; i++) {
480         QDomElement prod = producers.at(i).toElement();
481         if (prod.attribute("mlt_service") == "framebuffer") {
482             QString slowmotionprod = prod.attribute("resource");
483             slowmotionprod.replace(':', '?');
484             kDebug() << "// FOUND WRONG SLOWMO, new: " << slowmotionprod;
485             prod.setAttribute("resource", slowmotionprod);
486         }
487     }
488     // move producers to correct place, markers to a global list, fix clip descriptions
489     QDomElement markers = m_document.createElement("markers");
490     // This will get the westley producers:
491     producers = m_document.elementsByTagName("producer");
492     max = producers.count();
493     for (int i = 0; i < max; i++) {
494         QDomElement prod = producers.at(0).toElement();
495         QDomNode m = prod.firstChild();
496         if (!m.isNull()) {
497             if (m.toElement().tagName() == "markers") {
498                 QDomNodeList prodchilds = m.childNodes();
499                 int maxchild = prodchilds.count();
500                 for (int k = 0; k < maxchild; k++) {
501                     QDomElement mark = prodchilds.at(0).toElement();
502                     mark.setAttribute("id", prod.attribute("id"));
503                     markers.insertAfter(mark, QDomNode());
504                 }
505                 prod.removeChild(m);
506             } else if (prod.attribute("type").toInt() == TEXT) {
507                 // convert title clip
508                 if (m.toElement().tagName() == "textclip") {
509                     QDomDocument tdoc;
510                     QDomElement titleclip = m.toElement();
511                     QDomElement title = tdoc.createElement("kdenlivetitle");
512                     tdoc.appendChild(title);
513                     QDomNodeList objects = titleclip.childNodes();
514                     int maxchild = objects.count();
515                     for (int k = 0; k < maxchild; k++) {
516                         QString objectxml;
517                         QDomElement ob = objects.at(k).toElement();
518                         if (ob.attribute("type") == "3") {
519                             // text object - all of this goes into "xmldata"...
520                             QDomElement item = tdoc.createElement("item");
521                             item.setAttribute("z-index", ob.attribute("z"));
522                             item.setAttribute("type", "QGraphicsTextItem");
523                             QDomElement position = tdoc.createElement("position");
524                             position.setAttribute("x", ob.attribute("x"));
525                             position.setAttribute("y", ob.attribute("y"));
526                             QDomElement content = tdoc.createElement("content");
527                             content.setAttribute("font", ob.attribute("font_family"));
528                             content.setAttribute("font-size", ob.attribute("font_size"));
529                             content.setAttribute("font-bold", ob.attribute("bold"));
530                             content.setAttribute("font-italic", ob.attribute("italic"));
531                             content.setAttribute("font-underline", ob.attribute("underline"));
532                             QString col = ob.attribute("color");
533                             QColor c(col);
534                             content.setAttribute("font-color", colorToString(c));
535                             // todo: These fields are missing from the newly generated xmldata:
536                             // transform, startviewport, endviewport, background
537
538                             QDomText conttxt = tdoc.createTextNode(ob.attribute("text"));
539                             content.appendChild(conttxt);
540                             item.appendChild(position);
541                             item.appendChild(content);
542                             title.appendChild(item);
543                         } else if (ob.attribute("type") == "5") {
544                             // rectangle object
545                             QDomElement item = tdoc.createElement("item");
546                             item.setAttribute("z-index", ob.attribute("z"));
547                             item.setAttribute("type", "QGraphicsRectItem");
548                             QDomElement position = tdoc.createElement("position");
549                             position.setAttribute("x", ob.attribute("x"));
550                             position.setAttribute("y", ob.attribute("y"));
551                             QDomElement content = tdoc.createElement("content");
552                             QString col = ob.attribute("color");
553                             QColor c(col);
554                             content.setAttribute("brushcolor", colorToString(c));
555                             QString rect = "0,0,";
556                             rect.append(ob.attribute("width"));
557                             rect.append(",");
558                             rect.append(ob.attribute("height"));
559                             content.setAttribute("rect", rect);
560                             item.appendChild(position);
561                             item.appendChild(content);
562                             title.appendChild(item);
563                         }
564                     }
565                     prod.setAttribute("xmldata", tdoc.toString());
566                     // mbd todo: This clearly does not work, as every title gets the same name - trying to leave it empty
567                     // QStringList titleInfo = TitleWidget::getFreeTitleInfo(projectFolder());
568                     // prod.setAttribute("titlename", titleInfo.at(0));
569                     // prod.setAttribute("resource", titleInfo.at(1));
570                     //kDebug()<<"TITLE DATA:\n"<<tdoc.toString();
571                     prod.removeChild(m);
572                 } // End conversion of title clips.
573
574             } else if (m.isText()) {
575                 QString comment = m.nodeValue();
576                 if (!comment.isEmpty()) {
577                     prod.setAttribute("description", comment);
578                 }
579                 prod.removeChild(m);
580             }
581         }
582         int duration = prod.attribute("duration").toInt();
583         if (duration > 0) prod.setAttribute("out", QString::number(duration));
584         // The clip goes back in, but text clips should not go back in, at least not modified
585         westley.insertBefore(prod, QDomNode());
586
587     }
588
589     QDomNode westley0 = m_document.elementsByTagName("westley").at(0);
590     if (!markers.firstChild().isNull()) westley0.appendChild(markers);
591
592
593     // Convert as much of the kdenlivedoc as possible. Use the producer in westley
594     // First, remove the old stuff from westley, and add a new empty one
595     // Also, track the max id in order to use it for the adding of groups/folders
596     int max_kproducer_id = 0;
597     westley0.removeChild(kdenlivedoc);
598     QDomElement kdenlivedoc_new = m_document.createElement("kdenlivedoc");
599     kdenlivedoc_new.setAttribute("profile", profile);
600     // Add all the producers that has a ressource in westley
601     QDomElement westley_element = westley0.toElement();
602     if (westley_element.isNull()) {
603         kWarning() << "westley0 element in document was not a QDomElement - unable to add producers to new kdenlivedoc";
604     } else {
605         QDomNodeList wproducers = westley_element.elementsByTagName("producer");
606         int kmax = wproducers.count();
607         for (int i = 0; i < kmax; i++) {
608             QDomElement wproducer = wproducers.at(i).toElement();
609             if (wproducer.isNull()) {
610                 kWarning() << "Found producer in westley0, that was not a QDomElement";
611             } else {
612                 // We have to do slightly different things, depending on the type
613                 kDebug() << "Converting producer element with type " << wproducer.attribute("type");
614                 if (wproducer.attribute("type").toInt() == TEXT) {
615                     kDebug() << "Found TEXT element in producer" << endl;
616                     QDomElement kproducer = wproducer.cloneNode(true).toElement();
617                     kproducer.setTagName("kdenlive_producer");
618                     kdenlivedoc_new.appendChild(kproducer);
619                     // todo: Perhaps needs some more changes here to "frequency", aspect ratio as a float, frame_size, channels, and later, ressource and title name
620                 } else {
621                     QDomElement kproducer = m_document.createElement("kdenlive_producer");
622                     kproducer.setAttribute("id", wproducer.attribute("id"));
623                     kproducer.setAttribute("description", wproducer.attribute("description"));
624                     kproducer.setAttribute("resource", wproducer.attribute("resource"));
625                     kproducer.setAttribute("type", wproducer.attribute("type"));
626                     kdenlivedoc_new.appendChild(kproducer);
627                 }
628                 if (wproducer.attribute("id").toInt() > max_kproducer_id) {
629                     max_kproducer_id = wproducer.attribute("id").toInt();
630                 }
631             }
632         }
633     }
634 #define LOOKUP_FOLDER 1
635 #ifdef LOOKUP_FOLDER
636     // Look through all the folder elements of the old doc, for each folder, for each producer,
637     // get the id, look it up in the new doc, set the groupname and groupid
638     // Note, this does not work at the moment - at least one folders shows up missing, and clips with no folder
639     // does not show up.
640     //    QDomElement kdenlivedoc_old = kdenlivedoc.toElement();
641     if (!kdenlivedoc_old.isNull()) {
642         QDomNodeList folders = kdenlivedoc_old.elementsByTagName("folder");
643         int fsize = folders.size();
644         int groupId = max_kproducer_id + 1; // Start at +1 of max id of the kdenlive_producers
645         for (int i = 0; i < fsize; ++i) {
646             QDomElement folder = folders.at(i).toElement();
647             if (!folder.isNull()) {
648                 QString groupName = folder.attribute("name");
649                 kDebug() << "groupName: " << groupName << " with groupId: " << groupId;
650                 QDomNodeList fproducers = folder.elementsByTagName("producer");
651                 int psize = fproducers.size();
652                 for (int j = 0; j < psize; ++j) {
653                     QDomElement fproducer = fproducers.at(j).toElement();
654                     if (!fproducer.isNull()) {
655                         QString id = fproducer.attribute("id");
656                         // This is not very effective, but compared to loading the clips, its a breeze
657                         QDomNodeList kdenlive_producers = kdenlivedoc_new.elementsByTagName("kdenlive_producer");
658                         int kpsize = kdenlive_producers.size();
659                         for (int k = 0; k < kpsize; ++k) {
660                             QDomElement kproducer = kdenlive_producers.at(k).toElement(); // Its an element for sure
661                             if (id == kproducer.attribute("id")) {
662                                 // We do not check that it already is part of a folder
663                                 kproducer.setAttribute("groupid", groupId);
664                                 kproducer.setAttribute("groupname", groupName);
665                                 break;
666                             }
667                         }
668                     }
669                 }
670                 ++groupId;
671             }
672         }
673     }
674 #endif
675     westley0.appendChild(kdenlivedoc_new);
676
677     QDomNodeList elements = westley.childNodes();
678     max = elements.count();
679     for (int i = 0; i < max; i++) {
680         QDomElement prod = elements.at(0).toElement();
681         westley0.insertAfter(prod, QDomNode());
682     }
683
684     westley0.removeChild(westley);
685
686     //kDebug() << "/////////////////  CONVERTED DOC:";
687     // kDebug() << m_document.toString();
688     /*
689     QFile file( "converted.kdenlive" );
690     if ( file.open( QIODevice::WriteOnly ) ) {
691       QTextStream stream( &file );
692       stream << m_document.toString();
693       file.close();
694     } else {
695       kDebug() << "Unable to dump file to converted.kdenlive";
696     }
697     */
698     //kDebug() << "/////////////////  END CONVERTED DOC:";
699 }
700
701 QString KdenliveDoc::colorToString(const QColor& c) {
702     QString ret = "%1,%2,%3,%4";
703     ret = ret.arg(c.red()).arg(c.green()).arg(c.blue()).arg(c.alpha());
704     return ret;
705 }
706
707 bool KdenliveDoc::saveSceneList(const QString &path, QDomDocument sceneList) {
708     QDomNode wes = sceneList.elementsByTagName("westley").at(0);
709
710     QDomElement addedXml = sceneList.createElement("kdenlivedoc");
711     QDomElement markers = sceneList.createElement("markers");
712     addedXml.setAttribute("version", "0.8");
713     addedXml.setAttribute("profile", profilePath());
714     addedXml.setAttribute("position", m_render->seekPosition().frames(m_fps));
715     addedXml.setAttribute("zoom", m_zoom);
716
717     QDomElement e;
718     QList <DocClipBase*> list = m_clipManager->documentClipList();
719     for (int i = 0; i < list.count(); i++) {
720         e = list.at(i)->toXML();
721         e.setTagName("kdenlive_producer");
722         addedXml.appendChild(sceneList.importNode(e, true));
723         QList < CommentedTime > marks = list.at(i)->commentedSnapMarkers();
724         for (int j = 0; j < marks.count(); j++) {
725             QDomElement marker = sceneList.createElement("marker");
726             marker.setAttribute("time", marks.at(j).time().ms() / 1000);
727             marker.setAttribute("comment", marks.at(j).comment());
728             marker.setAttribute("id", e.attribute("id"));
729             markers.appendChild(marker);
730         }
731     }
732     addedXml.appendChild(markers);
733     if (!m_guidesXml.isNull()) addedXml.appendChild(sceneList.importNode(m_guidesXml, true));
734
735     wes.appendChild(addedXml);
736     //wes.appendChild(doc.importNode(kdenliveData, true));
737
738     QFile file(path);
739     if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
740         kWarning() << "//////  ERROR writing to file: " << path;
741         KMessageBox::error(kapp->activeWindow(), i18n("Cannot write to file %1", path));
742         return false;
743     }
744     QTextStream out(&file);
745     out << sceneList.toString();
746     file.close();
747     return true;
748 }
749
750 QDomElement KdenliveDoc::documentInfoXml() {
751     QDomDocument doc;
752     QDomElement e;
753     QDomElement addedXml = doc.createElement("kdenlivedoc");
754     QDomElement markers = doc.createElement("markers");
755     addedXml.setAttribute("version", "0.7");
756     addedXml.setAttribute("profile", profilePath());
757     addedXml.setAttribute("position", m_render->seekPosition().frames(m_fps));
758     addedXml.setAttribute("zoom", m_zoom);
759     QList <DocClipBase*> list = m_clipManager->documentClipList();
760     for (int i = 0; i < list.count(); i++) {
761         e = list.at(i)->toXML();
762         e.setTagName("kdenlive_producer");
763         addedXml.appendChild(doc.importNode(e, true));
764         QList < CommentedTime > marks = list.at(i)->commentedSnapMarkers();
765         for (int j = 0; j < marks.count(); j++) {
766             QDomElement marker = doc.createElement("marker");
767             marker.setAttribute("time", marks.at(j).time().ms() / 1000);
768             marker.setAttribute("comment", marks.at(j).comment());
769             marker.setAttribute("id", e.attribute("id"));
770             markers.appendChild(marker);
771         }
772     }
773     addedXml.appendChild(markers);
774     if (!m_guidesXml.isNull()) addedXml.appendChild(doc.importNode(m_guidesXml, true));
775     //kDebug() << m_document.toString();
776     return addedXml;
777 }
778
779
780 ClipManager *KdenliveDoc::clipManager() {
781     return m_clipManager;
782 }
783
784 KUrl KdenliveDoc::projectFolder() const {
785     if (m_projectFolder.isEmpty()) return KUrl(KStandardDirs::locateLocal("appdata", "/projects/"));
786     return m_projectFolder;
787 }
788
789 QString KdenliveDoc::profilePath() const {
790     return m_profile.path;
791 }
792
793 MltVideoProfile KdenliveDoc::mltProfile() const {
794     return m_profile;
795 }
796
797 void KdenliveDoc::setProfilePath(QString path) {
798     if (path.isEmpty()) path = KdenliveSettings::default_profile();
799     if (path.isEmpty()) path = "dv_pal";
800     m_profile = ProfilesDialog::getVideoProfile(path);
801     KdenliveSettings::setProject_display_ratio((double) m_profile.display_aspect_num / m_profile.display_aspect_den);
802     m_fps = (double) m_profile.frame_rate_num / m_profile.frame_rate_den;
803     m_width = m_profile.width;
804     m_height = m_profile.height;
805     kDebug() << "KDEnnlive document, init timecode from path: " << path << ",  " << m_fps;
806     if (m_fps == 30000.0 / 1001.0) m_timecode.setFormat(30, true);
807     else m_timecode.setFormat((int) m_fps);
808 }
809
810 const double KdenliveDoc::dar() {
811     return (double) m_profile.display_aspect_num / m_profile.display_aspect_den;
812 }
813
814 void KdenliveDoc::setThumbsProgress(const QString &message, int progress) {
815     emit progressInfo(message, progress);
816 }
817
818 void KdenliveDoc::loadingProgressed() {
819     m_documentLoadingProgress += m_documentLoadingStep;
820     emit progressInfo(QString(), (int) m_documentLoadingProgress);
821 }
822
823 QUndoStack *KdenliveDoc::commandStack() {
824     return m_commandStack;
825 }
826
827 void KdenliveDoc::setRenderer(Render *render) {
828     if (m_render) return;
829     m_render = render;
830     emit progressInfo(i18n("Loading playlist..."), 0);
831     //qApp->processEvents();
832     if (m_render) {
833         m_render->setSceneList(m_document.toString(), m_startPos);
834         checkProjectClips();
835     }
836     emit progressInfo(QString(), -1);
837 }
838
839 void KdenliveDoc::checkProjectClips() {
840     if (m_render == NULL) return;
841     QList <Mlt::Producer *> prods = m_render->producersList();
842     QString id ;
843     QString prodId ;
844     QString prodTrack ;
845     for (int i = 0; i < prods.count(); i++) {
846         id = prods.at(i)->get("id");
847         prodId = id.section('_', 0, 0);
848         prodTrack = id.section('_', 1, 1);
849         kDebug() << "CHECK PRO CLIP, ID: " << id;
850         DocClipBase *clip = m_clipManager->getClipById(prodId);
851         if (clip) clip->setProducer(prods.at(i));
852         kDebug() << "CHECK PRO CLIP, ID: " << id << " DONE";
853         if (clip && clip->clipType() == TEXT && !QFile::exists(clip->fileURL().path())) {
854             // regenerate text clip image if required
855             kDebug() << "// TITLE: " << clip->getProperty("titlename") << " Preview file: " << clip->getProperty("resource") << " DOES NOT EXIST";
856             QString titlename = clip->getProperty("titlename");
857             QString titleresource;
858             if (titlename.isEmpty()) {
859                 QStringList titleInfo = TitleWidget::getFreeTitleInfo(projectFolder());
860                 titlename = titleInfo.at(0);
861                 titleresource = titleInfo.at(1);
862                 clip->setProperty("titlename", titlename);
863                 kDebug() << "// New title set to: " << titlename;
864             } else {
865                 titleresource = TitleWidget::getTitleResourceFromName(projectFolder(), titlename);
866             }
867             QString titlepath = projectFolder().path() + "/titles/";
868             TitleWidget *dia_ui = new TitleWidget(KUrl(), titlepath, m_render, kapp->activeWindow());
869             QDomDocument doc;
870             doc.setContent(clip->getProperty("xmldata"));
871             dia_ui->setXml(doc);
872             QPixmap pix = dia_ui->renderedPixmap();
873             pix.save(titleresource);
874             clip->setProperty("resource", titleresource);
875             delete dia_ui;
876             clip->producer()->set("force_reload", 1);
877         }
878     }
879 }
880
881 Render *KdenliveDoc::renderer() {
882     return m_render;
883 }
884
885 void KdenliveDoc::updateClip(const QString &id) {
886     emit updateClipDisplay(id);
887 }
888
889 int KdenliveDoc::getFramePos(QString duration) {
890     return m_timecode.getFrameCount(duration, m_fps);
891 }
892
893 QString KdenliveDoc::producerName(const QString &id) {
894     QString result = "unnamed";
895     QDomNodeList prods = producersList();
896     int ct = prods.count();
897     for (int i = 0; i <  ct ; i++) {
898         QDomElement e = prods.item(i).toElement();
899         if (e.attribute("id") != "black" && e.attribute("id") == id) {
900             result = e.attribute("name");
901             if (result.isEmpty()) result = KUrl(e.attribute("resource")).fileName();
902             break;
903         }
904     }
905     return result;
906 }
907
908 void KdenliveDoc::setProducerDuration(const QString &id, int duration) {
909     QDomNodeList prods = producersList();
910     int ct = prods.count();
911     for (int i = 0; i <  ct ; i++) {
912         QDomElement e = prods.item(i).toElement();
913         if (e.attribute("id") != "black" && e.attribute("id") == id) {
914             e.setAttribute("duration", QString::number(duration));
915             break;
916         }
917     }
918 }
919
920 int KdenliveDoc::getProducerDuration(const QString &id) {
921     int result = 0;
922     QDomNodeList prods = producersList();
923     int ct = prods.count();
924     for (int i = 0; i <  ct ; i++) {
925         QDomElement e = prods.item(i).toElement();
926         if (e.attribute("id") != "black" && e.attribute("id") == id) {
927             result = e.attribute("duration").toInt();
928             break;
929         }
930     }
931     return result;
932 }
933
934
935 QDomDocument KdenliveDoc::generateSceneList() {
936     QDomDocument doc;
937     QDomElement westley = doc.createElement("westley");
938     doc.appendChild(westley);
939     QDomElement prod = doc.createElement("producer");
940 }
941
942 QDomDocument KdenliveDoc::toXml() const {
943     return m_document;
944 }
945
946 Timecode KdenliveDoc::timecode() const {
947     return m_timecode;
948 }
949
950 QDomNodeList KdenliveDoc::producersList() {
951     return m_document.elementsByTagName("producer");
952 }
953
954 void KdenliveDoc::backupMltPlaylist() {
955     if (m_render) m_scenelist = m_render->sceneList();
956 }
957
958 double KdenliveDoc::projectDuration() const {
959     if (m_render) return GenTime(m_render->getLength(), m_fps).ms() / 1000;
960 }
961
962 double KdenliveDoc::fps() const {
963     return m_fps;
964 }
965
966 int KdenliveDoc::width() const {
967     return m_width;
968 }
969
970 int KdenliveDoc::height() const {
971     return m_height;
972 }
973
974 KUrl KdenliveDoc::url() const {
975     return m_url;
976 }
977
978 void KdenliveDoc::setUrl(KUrl url) {
979     m_url = url;
980 }
981
982 void KdenliveDoc::setModified(bool mod) {
983     if (!m_url.isEmpty() && mod && KdenliveSettings::crashrecovery()) {
984         m_autoSaveTimer->start(3000);
985     }
986     if (mod == m_modified) return;
987     m_modified = mod;
988     emit docModified(m_modified);
989 }
990
991 bool KdenliveDoc::isModified() const {
992     return m_modified;
993 }
994
995 QString KdenliveDoc::description() const {
996     if (m_url.isEmpty())
997         return i18n("Untitled") + " / " + m_profile.description;
998     else
999         return m_url.fileName() + " / " + m_profile.description;
1000 }
1001
1002 void KdenliveDoc::addClip(QDomElement elem, QString clipId, bool createClipItem) {
1003     const QString producerId = clipId.section('_', 0, 0);
1004     int subtrack = clipId.section('_', 1, 1).toInt();
1005     DocClipBase *clip = m_clipManager->getClipById(producerId);
1006     if (clip == NULL) {
1007         elem.setAttribute("id", producerId);
1008         QString path = elem.attribute("resource");
1009         QString extension;
1010         if (elem.attribute("type").toInt() == SLIDESHOW) {
1011             extension = KUrl(path).fileName();
1012             path = KUrl(path).directory();
1013         }
1014         if (!path.isEmpty() && !QFile::exists(path)) {
1015             const QString size = elem.attribute("file_size");
1016             const QString hash = elem.attribute("file_hash");
1017             QString newpath;
1018             KMessageBox::ButtonCode action = KMessageBox::No;
1019             if (!size.isEmpty() && !hash.isEmpty()) {
1020                 if (!m_searchFolder.isEmpty()) newpath = searchFileRecursively(m_searchFolder, size, hash);
1021                 else action = (KMessageBox::ButtonCode)KMessageBox::messageBox(kapp->activeWindow(), KMessageBox::WarningYesNo, i18n("<qt>Clip <b>%1</b><br>is invalid, what do you want to do?", path), i18n("File not found"), KGuiItem(i18n("Search automatically")), /*KGuiItem(i18n("Remove from project")), */KGuiItem(i18n("Keep as placeholder")));
1022             } else {
1023                 if (elem.attribute("type").toInt() == SLIDESHOW) {
1024                     if (KMessageBox::messageBox(kapp->activeWindow(), KMessageBox::WarningYesNo, i18n("<qt>Clip <b>%1</b><br>is invalid, what do you want to do?", path), i18n("File not found"), KGuiItem(i18n("Search automatically")), /*KGuiItem(i18n("Remove from project")),*/ KGuiItem(i18n("Keep as placeholder"))) == KMessageBox::Yes)
1025                         newpath = KFileDialog::getExistingDirectory(KUrl("kfiledialog:///clipfolder"), kapp->activeWindow(), i18n("Looking for %1", path));
1026                 } else newpath = KFileDialog::getOpenFileName(KUrl("kfiledialog:///clipfolder"), QString(), kapp->activeWindow(), i18n("Looking for %1", path));
1027             }
1028             if (action == KMessageBox::Yes) {
1029                 kDebug() << "// ASKED FOR SRCH CLIP: " << clipId;
1030                 m_searchFolder = KFileDialog::getExistingDirectory(KUrl("kfiledialog:///clipfolder"), kapp->activeWindow());
1031                 if (!m_searchFolder.isEmpty()) {
1032                     newpath = searchFileRecursively(QDir(m_searchFolder), size, hash);
1033                 }
1034             }
1035             if (!newpath.isEmpty()) {
1036                 if (elem.attribute("type").toInt() == SLIDESHOW) newpath.append('/' + extension);
1037                 elem.setAttribute("resource", newpath);
1038                 setNewClipResource(clipId, newpath);
1039             }
1040         }
1041         clip = new DocClipBase(m_clipManager, elem, producerId);
1042         m_clipManager->addClip(clip);
1043     }
1044     if (createClipItem) emit addProjectClip(clip);
1045 }
1046
1047 void KdenliveDoc::setNewClipResource(const QString &id, const QString &path) {
1048     QDomNodeList prods = m_document.elementsByTagName("producer");
1049     int maxprod = prods.count();
1050     for (int i = 0; i < maxprod; i++) {
1051         QDomNode m = prods.at(i);
1052         QString prodId = m.toElement().attribute("id");
1053         if (prodId == id || prodId.startsWith(id + "_")) {
1054             QDomNodeList params = m.childNodes();
1055             for (int j = 0; j < params.count(); j++) {
1056                 QDomElement e = params.item(j).toElement();
1057                 if (e.attribute("name") == "resource") {
1058                     e.firstChild().setNodeValue(path);
1059                     break;
1060                 }
1061             }
1062         }
1063     }
1064 }
1065
1066 QString KdenliveDoc::searchFileRecursively(const QDir &dir, const QString &matchSize, const QString &matchHash) const {
1067     QString foundFileName;
1068     QByteArray fileData;
1069     QByteArray fileHash;
1070     QStringList filesAndDirs = dir.entryList(QDir::Files | QDir::Readable);
1071     for (int i = 0; i < filesAndDirs.size() && foundFileName.isEmpty(); i++) {
1072         QFile file(dir.absoluteFilePath(filesAndDirs.at(i)));
1073         if (file.open(QIODevice::ReadOnly)) {
1074             if (QString::number(file.size()) == matchSize) {
1075                 /*
1076                 * 1 MB = 1 second per 450 files (or faster)
1077                 * 10 MB = 9 seconds per 450 files (or faster)
1078                 */
1079                 if (file.size() > 1000000*2) {
1080                     fileData = file.read(1000000);
1081                     if (file.seek(file.size() - 1000000))
1082                         fileData.append(file.readAll());
1083                 } else
1084                     fileData = file.readAll();
1085                 file.close();
1086                 fileHash = QCryptographicHash::hash(fileData, QCryptographicHash::Md5);
1087                 if (QString(fileHash.toHex()) == matchHash)
1088                     return file.fileName();
1089             }
1090         }
1091         kDebug() << filesAndDirs.at(i) << file.size() << fileHash.toHex();
1092     }
1093     filesAndDirs = dir.entryList(QDir::Dirs | QDir::Readable | QDir::Executable | QDir::NoDotAndDotDot);
1094     for (int i = 0; i < filesAndDirs.size() && foundFileName.isEmpty(); i++) {
1095         foundFileName = searchFileRecursively(dir.absoluteFilePath(filesAndDirs.at(i)), matchSize, matchHash);
1096         if (!foundFileName.isEmpty())
1097             break;
1098     }
1099     return foundFileName;
1100 }
1101
1102 void KdenliveDoc::addClipInfo(QDomElement elem, QString clipId) {
1103     DocClipBase *clip = m_clipManager->getClipById(clipId);
1104     if (clip == NULL) {
1105         addClip(elem, clipId);
1106     } else {
1107         QMap <QString, QString> properties;
1108         QDomNamedNodeMap attributes = elem.attributes();
1109         QString attrname;
1110         for (unsigned int i = 0; i < attributes.count(); i++) {
1111             attrname = attributes.item(i).nodeName();
1112             if (attrname != "resource")
1113                 properties.insert(attrname, attributes.item(i).nodeValue());
1114             kDebug() << attrname << " = " << attributes.item(i).nodeValue();
1115         }
1116         clip->setProperties(properties);
1117         emit addProjectClip(clip);
1118     }
1119 }
1120
1121 void KdenliveDoc::addFolder(const QString foldername, const QString &clipId, bool edit) {
1122     emit addProjectFolder(foldername, clipId, false, edit);
1123 }
1124
1125 void KdenliveDoc::deleteFolder(const QString foldername, const QString &clipId) {
1126     emit addProjectFolder(foldername, clipId, true);
1127 }
1128
1129 void KdenliveDoc::deleteProjectClip(QList <QString> ids) {
1130     for (int i = 0; i < ids.size(); ++i) {
1131         emit deleteTimelineClip(ids.at(i));
1132         m_clipManager->slotDeleteClip(ids.at(i));
1133     }
1134     setModified(true);
1135 }
1136
1137 void KdenliveDoc::deleteProjectFolder(QMap <QString, QString> map) {
1138     QMapIterator<QString, QString> i(map);
1139     while (i.hasNext()) {
1140         i.next();
1141         slotDeleteFolder(i.key(), i.value());
1142     }
1143     setModified(true);
1144 }
1145
1146 void KdenliveDoc::deleteClip(const QString &clipId) {
1147     emit signalDeleteProjectClip(clipId);
1148     m_clipManager->deleteClip(clipId);
1149 }
1150
1151 void KdenliveDoc::slotAddClipList(const KUrl::List urls, const QString group, const QString &groupId) {
1152     m_clipManager->slotAddClipList(urls, group, groupId);
1153     emit selectLastAddedClip(QString::number(m_clipManager->lastClipId()));
1154     setModified(true);
1155 }
1156
1157
1158 void KdenliveDoc::slotAddClipFile(const KUrl url, const QString group, const QString &groupId) {
1159     kDebug() << "/////////  DOCUM, ADD CLP: " << url;
1160     m_clipManager->slotAddClipFile(url, group, groupId);
1161     emit selectLastAddedClip(QString::number(m_clipManager->lastClipId()));
1162     setModified(true);
1163 }
1164
1165 void KdenliveDoc::slotAddFolder(const QString folderName) {
1166     AddFolderCommand *command = new AddFolderCommand(this, folderName, QString::number(m_clipManager->getFreeClipId()), true);
1167     commandStack()->push(command);
1168     setModified(true);
1169 }
1170
1171 void KdenliveDoc::slotDeleteFolder(const QString folderName, const QString &id) {
1172     AddFolderCommand *command = new AddFolderCommand(this, folderName, id, false);
1173     commandStack()->push(command);
1174     setModified(true);
1175 }
1176
1177 void KdenliveDoc::slotEditFolder(const QString newfolderName, const QString oldfolderName, const QString &clipId) {
1178     EditFolderCommand *command = new EditFolderCommand(this, newfolderName, oldfolderName, clipId, false);
1179     commandStack()->push(command);
1180     setModified(true);
1181 }
1182
1183 const QString&KdenliveDoc::getFreeClipId() {
1184     return QString::number(m_clipManager->getFreeClipId());
1185 }
1186
1187 DocClipBase *KdenliveDoc::getBaseClip(const QString &clipId) {
1188     return m_clipManager->getClipById(clipId);
1189 }
1190
1191 void KdenliveDoc::slotAddColorClipFile(const QString name, const QString color, QString duration, const QString group, const QString &groupId) {
1192     m_clipManager->slotAddColorClipFile(name, color, duration, group, groupId);
1193     setModified(true);
1194 }
1195
1196 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 QString &groupId) {
1197     m_clipManager->slotAddSlideshowClipFile(name, path, count, duration, loop, fade, luma_duration, luma_file, softness, group, groupId);
1198     setModified(true);
1199 }
1200
1201 void KdenliveDoc::slotCreateTextClip(QString group, const QString &groupId) {
1202     QString titlesFolder = projectFolder().path() + "/titles/";
1203     KStandardDirs::makeDir(titlesFolder);
1204     TitleWidget *dia_ui = new TitleWidget(KUrl(), titlesFolder, m_render, kapp->activeWindow());
1205     if (dia_ui->exec() == QDialog::Accepted) {
1206         QStringList titleInfo = TitleWidget::getFreeTitleInfo(projectFolder());
1207         QPixmap pix = dia_ui->renderedPixmap();
1208         pix.save(titleInfo.at(1));
1209         //dia_ui->saveTitle(path + ".kdenlivetitle");
1210         m_clipManager->slotAddTextClipFile(titleInfo.at(0), titleInfo.at(1), dia_ui->xml().toString(), QString(), QString());
1211         setModified(true);
1212     }
1213     delete dia_ui;
1214 }
1215
1216
1217
1218 #include "kdenlivedoc.moc"
1219