]> git.sesse.net Git - kdenlive/blob - src/kdenlivedoc.cpp
Fix composite transition with black track broken
[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
21 #include "kdenlivedoc.h"
22 #include "docclipbase.h"
23 #include "profilesdialog.h"
24 #include "kdenlivesettings.h"
25 #include "renderer.h"
26 #include "clipmanager.h"
27 #include "titlewidget.h"
28 #include "mainwindow.h"
29 #include "documentchecker.h"
30 #include "documentvalidator.h"
31 #include "kdenlive-config.h"
32
33 #include <KDebug>
34 #include <KStandardDirs>
35 #include <KMessageBox>
36 #include <KLocale>
37 #include <KFileDialog>
38 #include <KIO/NetAccess>
39 #include <KIO/CopyJob>
40 #include <KApplication>
41
42 #include <QCryptographicHash>
43 #include <QFile>
44 #include <QInputDialog>
45
46 #include <mlt++/Mlt.h>
47
48 const double DOCUMENTVERSION = 0.84;
49
50 KdenliveDoc::KdenliveDoc(const KUrl &url, const KUrl &projectFolder, QUndoGroup *undoGroup, QString profileName, const QPoint tracks, Render *render, MainWindow *parent) :
51         QObject(parent),
52         m_autosave(NULL),
53         m_url(url),
54         m_render(render),
55         m_commandStack(new QUndoStack(undoGroup)),
56         m_modified(false),
57         m_projectFolder(projectFolder),
58         m_documentLoadingStep(0.0),
59         m_documentLoadingProgress(0),
60         m_abortLoading(false)
61 {
62     m_clipManager = new ClipManager(this);
63     m_autoSaveTimer = new QTimer(this);
64     m_autoSaveTimer->setSingleShot(true);
65     bool success = false;
66
67     // init default document properties
68     m_documentProperties["zoom"] = "7";
69     m_documentProperties["verticalzoom"] = "1";
70     m_documentProperties["zonein"] = "0";
71     m_documentProperties["zoneout"] = "100";
72
73     if (!url.isEmpty()) {
74         QString tmpFile;
75         success = KIO::NetAccess::download(url.path(), tmpFile, parent);
76         if (!success) // The file cannot be opened
77             KMessageBox::error(parent, KIO::NetAccess::lastErrorString());
78         else {
79             QFile file(tmpFile);
80             QString errorMsg;
81             success = m_document.setContent(&file, false, &errorMsg);
82             file.close();
83             KIO::NetAccess::removeTempFile(tmpFile);
84             if (!success) // It is corrupted
85                 KMessageBox::error(parent, errorMsg);
86             else {
87                 DocumentValidator validator(m_document);
88                 success = validator.isProject();
89                 if (!success) // It is not a project file
90                     parent->slotGotProgressInfo(i18n("File %1 is not a Kdenlive project file.", m_url.path()), 100);
91                 else {
92                     /*
93                      * Validate the file against the current version (upgrade
94                      * and recover it if needed). It is NOT a passive operation
95                      */
96                     // TODO: backup the document or alert the user?
97                     success = validator.validate(DOCUMENTVERSION);
98                     if (success) { // Let the validator handle error messages
99                         QDomElement mlt = m_document.firstChildElement("mlt");
100                         QDomElement infoXml = mlt.firstChildElement("kdenlivedoc");
101
102                         profileName = infoXml.attribute("profile");
103                         m_projectFolder = KUrl(infoXml.attribute("projectfolder"));
104                         QDomElement docproperties = infoXml.firstChildElement("documentproperties");
105                         QDomNamedNodeMap props = docproperties.attributes();
106                         for (int i = 0; i < props.count(); i++) {
107                             m_documentProperties.insert(props.item(i).nodeName(), props.item(i).nodeValue());
108                         }
109                         // Build tracks
110                         QDomElement e;
111                         QDomElement tracksinfo = infoXml.firstChildElement("tracksinfo");
112                         TrackInfo projectTrack;
113                         if (!tracksinfo.isNull()) {
114                             QDomNodeList trackslist = tracksinfo.childNodes();
115                             int maxchild = trackslist.count();
116                             for (int k = 0; k < maxchild; k++) {
117                                 e = trackslist.at(k).toElement();
118                                 if (e.tagName() == "trackinfo") {
119                                     if (e.attribute("type") == "audio") projectTrack.type = AUDIOTRACK;
120                                     else projectTrack.type = VIDEOTRACK;
121                                     projectTrack.isMute = e.attribute("mute").toInt();
122                                     projectTrack.isBlind = e.attribute("blind").toInt();
123                                     projectTrack.isLocked = e.attribute("locked").toInt();
124                                     m_tracksList.append(projectTrack);
125                                 }
126                             }
127                             mlt.removeChild(tracksinfo);
128                         }
129                         QDomNodeList producers = m_document.elementsByTagName("producer");
130                         QDomNodeList infoproducers = m_document.elementsByTagName("kdenlive_producer");
131                         if (checkDocumentClips(infoproducers) == false) m_abortLoading = true;
132                         const int max = producers.count();
133                         const int infomax = infoproducers.count();
134
135                         QDomNodeList folders = m_document.elementsByTagName("folder");
136                         for (int i = 0; i < folders.count(); i++) {
137                             e = folders.item(i).cloneNode().toElement();
138                             m_clipManager->addFolder(e.attribute("id"), e.attribute("name"));
139                         }
140
141                         if (max > 0) {
142                             m_documentLoadingStep = 100.0 / (max + infomax + m_document.elementsByTagName("entry").count());
143                             parent->slotGotProgressInfo(i18n("Loading project clips"), (int) m_documentLoadingProgress);
144                         }
145
146
147                         for (int i = 0; i < infomax && !m_abortLoading; i++) {
148                             e = infoproducers.item(i).cloneNode().toElement();
149                             if (m_documentLoadingStep > 0) {
150                                 m_documentLoadingProgress += m_documentLoadingStep;
151                                 parent->slotGotProgressInfo(QString(), (int) m_documentLoadingProgress);
152                                 //qApp->processEvents();
153                             }
154                             QString prodId = e.attribute("id");
155                             if (!e.isNull() && prodId != "black" && !prodId.startsWith("slowmotion") && !m_abortLoading) {
156                                 e.setTagName("producer");
157                                 // Get MLT's original producer properties
158                                 QDomElement orig;
159                                 for (int j = 0; j < max; j++) {
160                                     QDomElement o = producers.item(j).cloneNode().toElement();
161                                     QString origId = o.attribute("id").section('_', 0, 0);
162                                     if (origId == prodId) {
163                                         orig = o;
164                                         break;
165                                     }
166                                 }
167                                 addClipInfo(e, orig, prodId);
168                                 kDebug() << "// KDENLIVE PRODUCER: " << prodId;
169                             }
170                         }
171                         if (m_abortLoading) {
172                             //parent->slotGotProgressInfo(i18n("File %1 is not a Kdenlive project file."), 100);
173                             emit resetProjectList();
174                             m_documentProperties.remove("position");
175                             m_url = KUrl();
176                             m_tracksList.clear();
177                             kWarning() << "Aborted loading of: " << url.path();
178                             m_document = createEmptyDocument(KdenliveSettings::videotracks(), KdenliveSettings::audiotracks());
179                             setProfilePath(KdenliveSettings::default_profile());
180                             m_clipManager->clear();
181                         } else {
182                             QDomElement markers = infoXml.firstChildElement("markers");
183                             if (!markers.isNull()) {
184                                 QDomNodeList markerslist = markers.childNodes();
185                                 int maxchild = markerslist.count();
186                                 for (int k = 0; k < maxchild; k++) {
187                                     e = markerslist.at(k).toElement();
188                                     if (e.tagName() == "marker") {
189                                         m_clipManager->getClipById(e.attribute("id"))->addSnapMarker(GenTime(e.attribute("time").toDouble()), e.attribute("comment"));
190                                     }
191                                 }
192                                 infoXml.removeChild(markers);
193                             }
194                             setProfilePath(profileName);
195                             setModified(validator.isModified());
196                             kDebug() << "Reading file: " << url.path() << ", found clips: " << producers.count();
197                         }
198                     }
199                 }
200             }
201         }
202     } else setProfilePath(profileName);
203
204     // Something went wrong, or a new file was requested: create a new project
205     if (!success) {
206         setProfilePath(QString());
207         m_url = KUrl();
208         m_document = createEmptyDocument(tracks.x(), tracks.y());
209     }
210
211     // Set the video profile (empty == default)
212
213     // Make sure the project folder is usable
214     if (m_projectFolder.isEmpty() || !KIO::NetAccess::exists(m_projectFolder.path(), KIO::NetAccess::DestinationSide, parent)) {
215         KMessageBox::information(parent, i18n("Document project folder is invalid, setting it to the default one: %1", KdenliveSettings::defaultprojectfolder()));
216         m_projectFolder = KUrl(KdenliveSettings::defaultprojectfolder());
217     }
218
219     // Make sure that the necessary folders exist
220     KStandardDirs::makeDir(m_projectFolder.path(KUrl::AddTrailingSlash) + "titles/");
221     KStandardDirs::makeDir(m_projectFolder.path(KUrl::AddTrailingSlash) + "thumbs/");
222     KStandardDirs::makeDir(m_projectFolder.path(KUrl::AddTrailingSlash) + "ladspa/");
223
224     kDebug() << "Kdenlive document, init timecode: " << m_fps;
225     if (m_fps == 30000.0 / 1001.0) m_timecode.setFormat(30, true);
226     else m_timecode.setFormat((int)(m_fps + 0.5));
227
228     //kDebug() << "// SETTING SCENE LIST:\n\n" << m_document.toString();
229     connect(m_autoSaveTimer, SIGNAL(timeout()), this, SLOT(slotAutoSave()));
230 }
231
232 KdenliveDoc::~KdenliveDoc()
233 {
234     m_autoSaveTimer->stop();
235     delete m_commandStack;
236     kDebug() << "// DEL CLP MAN";
237     delete m_clipManager;
238     kDebug() << "// DEL CLP MAN done";
239     delete m_autoSaveTimer;
240     if (m_autosave) {
241         if (!m_autosave->fileName().isEmpty()) m_autosave->remove();
242         delete m_autosave;
243     }
244 }
245
246 int KdenliveDoc::setSceneList()
247 {
248     if (m_render->setSceneList(m_document.toString(), m_documentProperties.value("position").toInt()) == -1) {
249         // INVALID MLT Consumer, something is wrong
250         return -1;
251     }
252     m_documentProperties.remove("position");
253     // m_document xml is now useless, clear it
254     m_document.clear();
255     checkProjectClips();
256     return 0;
257 }
258
259 QDomDocument KdenliveDoc::createEmptyDocument(const int videotracks, const int audiotracks)
260 {
261     // Creating new document
262     QDomDocument doc;
263     QDomElement mlt = doc.createElement("mlt");
264     doc.appendChild(mlt);
265
266
267     TrackInfo videoTrack;
268     videoTrack.type = VIDEOTRACK;
269     videoTrack.isMute = false;
270     videoTrack.isBlind = false;
271     videoTrack.isLocked = false;
272
273     TrackInfo audioTrack;
274     audioTrack.type = AUDIOTRACK;
275     audioTrack.isMute = false;
276     audioTrack.isBlind = true;
277     audioTrack.isLocked = false;
278
279     // Create black producer
280     // For some unknown reason, we have to build the black producer here and not in renderer.cpp, otherwise
281     // the composite transitions with the black track are corrupted.
282     QDomElement blk = doc.createElement("producer");
283     blk.setAttribute("in", 0);
284     blk.setAttribute("out", 500);
285     blk.setAttribute("id", "black");
286
287     QDomElement property = doc.createElement("property");
288     property.setAttribute("name", "mlt_type");
289     QDomText value = doc.createTextNode("producer");
290     property.appendChild(value);
291     blk.appendChild(property);
292
293     property = doc.createElement("property");
294     property.setAttribute("name", "aspect_ratio");
295     value = doc.createTextNode(QString::number(0.0));
296     property.appendChild(value);
297     blk.appendChild(property);
298
299     property = doc.createElement("property");
300     property.setAttribute("name", "length");
301     value = doc.createTextNode(QString::number(15000));
302     property.appendChild(value);
303     blk.appendChild(property);
304
305     property = doc.createElement("property");
306     property.setAttribute("name", "eof");
307     value = doc.createTextNode("pause");
308     property.appendChild(value);
309     blk.appendChild(property);
310
311     property = doc.createElement("property");
312     property.setAttribute("name", "resource");
313     value = doc.createTextNode("black");
314     property.appendChild(value);
315     blk.appendChild(property);
316
317     property = doc.createElement("property");
318     property.setAttribute("name", "mlt_service");
319     value = doc.createTextNode("colour");
320     property.appendChild(value);
321     blk.appendChild(property);
322
323     mlt.appendChild(blk);
324
325
326     QDomElement tractor = doc.createElement("tractor");
327     tractor.setAttribute("id", "maintractor");
328     QDomElement multitrack = doc.createElement("multitrack");
329     QDomElement playlist = doc.createElement("playlist");
330     playlist.setAttribute("id", "black_track");
331     mlt.appendChild(playlist);
332
333     QDomElement blank0 = doc.createElement("entry");
334     blank0.setAttribute("in", "0");
335     blank0.setAttribute("out", "0");
336     blank0.setAttribute("producer", "black");
337     playlist.appendChild(blank0);
338
339     // create playlists
340     int total = audiotracks + videotracks + 1;
341
342     for (int i = 1; i < total; i++) {
343         QDomElement playlist = doc.createElement("playlist");
344         playlist.setAttribute("id", "playlist" + QString::number(i));
345         mlt.appendChild(playlist);
346     }
347
348     QDomElement track0 = doc.createElement("track");
349     track0.setAttribute("producer", "black_track");
350     tractor.appendChild(track0);
351
352     // create audio tracks
353     for (int i = 1; i < audiotracks + 1; i++) {
354         QDomElement track = doc.createElement("track");
355         track.setAttribute("producer", "playlist" + QString::number(i));
356         track.setAttribute("hide", "video");
357         tractor.appendChild(track);
358         m_tracksList.append(audioTrack);
359     }
360
361     // create video tracks
362     for (int i = audiotracks + 1; i < total; i++) {
363         QDomElement track = doc.createElement("track");
364         track.setAttribute("producer", "playlist" + QString::number(i));
365         tractor.appendChild(track);
366         m_tracksList.append(videoTrack);
367     }
368
369     for (int i = 2; i < total ; i++) {
370         QDomElement transition = doc.createElement("transition");
371         transition.setAttribute("always_active", "1");
372
373         QDomElement property = doc.createElement("property");
374         property.setAttribute("name", "a_track");
375         QDomText value = doc.createTextNode(QString::number(1));
376         property.appendChild(value);
377         transition.appendChild(property);
378
379         property = doc.createElement("property");
380         property.setAttribute("name", "b_track");
381         value = doc.createTextNode(QString::number(i));
382         property.appendChild(value);
383         transition.appendChild(property);
384
385         property = doc.createElement("property");
386         property.setAttribute("name", "mlt_service");
387         value = doc.createTextNode("mix");
388         property.appendChild(value);
389         transition.appendChild(property);
390
391         property = doc.createElement("property");
392         property.setAttribute("name", "combine");
393         value = doc.createTextNode("1");
394         property.appendChild(value);
395         transition.appendChild(property);
396
397         property = doc.createElement("property");
398         property.setAttribute("name", "internal_added");
399         value = doc.createTextNode("237");
400         property.appendChild(value);
401         transition.appendChild(property);
402         tractor.appendChild(transition);
403     }
404     mlt.appendChild(tractor);
405     return doc;
406 }
407
408
409 void KdenliveDoc::syncGuides(QList <Guide *> guides)
410 {
411     m_guidesXml.clear();
412     QDomElement guideNode = m_guidesXml.createElement("guides");
413     m_guidesXml.appendChild(guideNode);
414     QDomElement e;
415
416     for (int i = 0; i < guides.count(); i++) {
417         e = m_guidesXml.createElement("guide");
418         e.setAttribute("time", guides.at(i)->position().ms() / 1000);
419         e.setAttribute("comment", guides.at(i)->label());
420         guideNode.appendChild(e);
421     }
422     setModified(true);
423     emit guidesUpdated();
424 }
425
426 QDomElement KdenliveDoc::guidesXml() const
427 {
428     return m_guidesXml.documentElement();
429 }
430
431 void KdenliveDoc::slotAutoSave()
432 {
433     if (m_render && m_autosave) {
434         if (!m_autosave->isOpen() && !m_autosave->open(QIODevice::ReadWrite)) {
435             // show error: could not open the autosave file
436             kDebug() << "ERROR; CANNOT CREATE AUTOSAVE FILE";
437         }
438         kDebug() << "// AUTOSAVE FILE: " << m_autosave->fileName();
439         QString doc;
440         if (KdenliveSettings::dropbframes()) {
441             KdenliveSettings::setDropbframes(false);
442             m_clipManager->updatePreviewSettings();
443             doc = m_render->sceneList();
444             KdenliveSettings::setDropbframes(true);
445             m_clipManager->updatePreviewSettings();
446         } else doc = m_render->sceneList();
447         saveSceneList(m_autosave->fileName(), doc);
448     }
449 }
450
451 void KdenliveDoc::setZoom(int horizontal, int vertical)
452 {
453     m_documentProperties["zoom"] = QString::number(horizontal);
454     m_documentProperties["verticalzoom"] = QString::number(vertical);
455 }
456
457 QPoint KdenliveDoc::zoom() const
458 {
459     return QPoint(m_documentProperties.value("zoom").toInt(), m_documentProperties.value("verticalzoom").toInt());
460 }
461
462 void KdenliveDoc::setZone(int start, int end)
463 {
464     m_documentProperties["zonein"] = QString::number(start);
465     m_documentProperties["zoneout"] = QString::number(end);
466 }
467
468 QPoint KdenliveDoc::zone() const
469 {
470     return QPoint(m_documentProperties.value("zonein").toInt(), m_documentProperties.value("zoneout").toInt());
471 }
472
473 bool KdenliveDoc::saveSceneList(const QString &path, const QString &scene)
474 {
475     QDomDocument sceneList;
476     sceneList.setContent(scene, true);
477     QDomElement mlt = sceneList.firstChildElement("mlt");
478     QDomElement addedXml = sceneList.createElement("kdenlivedoc");
479     mlt.appendChild(addedXml);
480
481     QDomElement markers = sceneList.createElement("markers");
482     addedXml.setAttribute("version", DOCUMENTVERSION);
483     addedXml.setAttribute("kdenliveversion", VERSION);
484     addedXml.setAttribute("profile", profilePath());
485     addedXml.setAttribute("projectfolder", m_projectFolder.path());
486
487     QDomElement docproperties = sceneList.createElement("documentproperties");
488     QMapIterator<QString, QString> i(m_documentProperties);
489     while (i.hasNext()) {
490         i.next();
491         docproperties.setAttribute(i.key(), i.value());
492     }
493     docproperties.setAttribute("position", m_render->seekPosition().frames(m_fps));
494     addedXml.appendChild(docproperties);
495
496     // Add profile info
497     QDomElement profileinfo = sceneList.createElement("profileinfo");
498     profileinfo.setAttribute("description", m_profile.description);
499     profileinfo.setAttribute("frame_rate_num", m_profile.frame_rate_num);
500     profileinfo.setAttribute("frame_rate_den", m_profile.frame_rate_den);
501     profileinfo.setAttribute("width", m_profile.width);
502     profileinfo.setAttribute("height", m_profile.height);
503     profileinfo.setAttribute("progressive", m_profile.progressive);
504     profileinfo.setAttribute("sample_aspect_num", m_profile.sample_aspect_num);
505     profileinfo.setAttribute("sample_aspect_den", m_profile.sample_aspect_den);
506     profileinfo.setAttribute("display_aspect_num", m_profile.display_aspect_num);
507     profileinfo.setAttribute("display_aspect_den", m_profile.display_aspect_den);
508     addedXml.appendChild(profileinfo);
509
510     // tracks info
511     QDomElement tracksinfo = sceneList.createElement("tracksinfo");
512     foreach(const TrackInfo &info, m_tracksList) {
513         QDomElement trackinfo = sceneList.createElement("trackinfo");
514         if (info.type == AUDIOTRACK) trackinfo.setAttribute("type", "audio");
515         trackinfo.setAttribute("mute", info.isMute);
516         trackinfo.setAttribute("blind", info.isBlind);
517         trackinfo.setAttribute("locked", info.isLocked);
518         tracksinfo.appendChild(trackinfo);
519     }
520     addedXml.appendChild(tracksinfo);
521
522     // save project folders
523     QMap <QString, QString> folderlist = m_clipManager->documentFolderList();
524
525     QMapIterator<QString, QString> f(folderlist);
526     while (f.hasNext()) {
527         f.next();
528         QDomElement folder = sceneList.createElement("folder");
529         folder.setAttribute("id", f.key());
530         folder.setAttribute("name", f.value());
531         addedXml.appendChild(folder);
532     }
533
534     // Save project clips
535     QDomElement e;
536     QList <DocClipBase*> list = m_clipManager->documentClipList();
537     for (int i = 0; i < list.count(); i++) {
538         e = list.at(i)->toXML();
539         e.setTagName("kdenlive_producer");
540         addedXml.appendChild(sceneList.importNode(e, true));
541         QList < CommentedTime > marks = list.at(i)->commentedSnapMarkers();
542         for (int j = 0; j < marks.count(); j++) {
543             QDomElement marker = sceneList.createElement("marker");
544             marker.setAttribute("time", marks.at(j).time().ms() / 1000);
545             marker.setAttribute("comment", marks.at(j).comment());
546             marker.setAttribute("id", e.attribute("id"));
547             markers.appendChild(marker);
548         }
549     }
550     addedXml.appendChild(markers);
551
552     // Add guides
553     if (!m_guidesXml.isNull()) addedXml.appendChild(sceneList.importNode(m_guidesXml.documentElement(), true));
554
555     // Add clip groups
556     addedXml.appendChild(sceneList.importNode(m_clipManager->groupsXml(), true));
557
558     //wes.appendChild(doc.importNode(kdenliveData, true));
559
560     QFile file(path);
561     if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
562         kWarning() << "//////  ERROR writing to file: " << path;
563         KMessageBox::error(kapp->activeWindow(), i18n("Cannot write to file %1", path));
564         return false;
565     }
566
567     file.write(sceneList.toString().toUtf8());
568     if (file.error() != QFile::NoError) {
569         KMessageBox::error(kapp->activeWindow(), i18n("Cannot write to file %1", path));
570         file.close();
571         return false;
572     }
573     file.close();
574     return true;
575 }
576
577 ClipManager *KdenliveDoc::clipManager()
578 {
579     return m_clipManager;
580 }
581
582 KUrl KdenliveDoc::projectFolder() const
583 {
584     //if (m_projectFolder.isEmpty()) return KUrl(KStandardDirs::locateLocal("appdata", "/projects/"));
585     return m_projectFolder;
586 }
587
588 void KdenliveDoc::setProjectFolder(KUrl url)
589 {
590     if (url == m_projectFolder) return;
591     setModified(true);
592     KStandardDirs::makeDir(url.path());
593     KStandardDirs::makeDir(url.path(KUrl::AddTrailingSlash) + "titles/");
594     KStandardDirs::makeDir(url.path(KUrl::AddTrailingSlash) + "thumbs/");
595     if (KMessageBox::questionYesNo(kapp->activeWindow(), i18n("You have changed the project folder. Do you want to copy the cached data from %1 to the new folder %2?").arg(m_projectFolder.path(), url.path())) == KMessageBox::Yes) moveProjectData(url);
596     m_projectFolder = url;
597 }
598
599 void KdenliveDoc::moveProjectData(KUrl url)
600 {
601     QList <DocClipBase*> list = m_clipManager->documentClipList();
602     //TODO: Also move ladspa effects files
603     for (int i = 0; i < list.count(); i++) {
604         DocClipBase *clip = list.at(i);
605         if (clip->clipType() == TEXT) {
606             // the image for title clip must be moved
607             KUrl oldUrl = clip->fileURL();
608             KUrl newUrl = KUrl(url.path(KUrl::AddTrailingSlash) + "titles/" + oldUrl.fileName());
609             KIO::Job *job = KIO::copy(oldUrl, newUrl);
610             if (KIO::NetAccess::synchronousRun(job, 0)) clip->setProperty("resource", newUrl.path());
611         }
612         QString hash = clip->getClipHash();
613         KUrl oldVideoThumbUrl = KUrl(m_projectFolder.path(KUrl::AddTrailingSlash) + "thumbs/" + hash + ".png");
614         KUrl oldAudioThumbUrl = KUrl(m_projectFolder.path(KUrl::AddTrailingSlash) + "thumbs/" + hash + ".thumb");
615         if (KIO::NetAccess::exists(oldVideoThumbUrl, KIO::NetAccess::SourceSide, 0)) {
616             KUrl newUrl = KUrl(url.path(KUrl::AddTrailingSlash) + "thumbs/" + hash + ".png");
617             KIO::Job *job = KIO::copy(oldVideoThumbUrl, newUrl);
618             KIO::NetAccess::synchronousRun(job, 0);
619         }
620         if (KIO::NetAccess::exists(oldAudioThumbUrl, KIO::NetAccess::SourceSide, 0)) {
621             KUrl newUrl = KUrl(url.path(KUrl::AddTrailingSlash) + "thumbs/" + hash + ".thumb");
622             KIO::Job *job = KIO::copy(oldAudioThumbUrl, newUrl);
623             if (KIO::NetAccess::synchronousRun(job, 0)) clip->refreshThumbUrl();
624         }
625     }
626 }
627
628 const QString &KdenliveDoc::profilePath() const
629 {
630     return m_profile.path;
631 }
632
633 MltVideoProfile KdenliveDoc::mltProfile() const
634 {
635     return m_profile;
636 }
637
638 void KdenliveDoc::setProfilePath(QString path)
639 {
640     if (path.isEmpty()) path = KdenliveSettings::default_profile();
641     if (path.isEmpty()) path = "dv_pal";
642     m_profile = ProfilesDialog::getVideoProfile(path);
643     if (m_profile.path.isEmpty()) {
644         // Profile not found, use embedded profile
645         QDomElement profileInfo = m_document.elementsByTagName("profileinfo").at(0).toElement();
646         if (profileInfo.isNull()) {
647             KMessageBox::information(kapp->activeWindow(), i18n("Project profile was not found, using default profile."), i18n("Missing Profile"));
648             m_profile = ProfilesDialog::getVideoProfile(KdenliveSettings::default_profile());
649         } else {
650             m_profile.description = profileInfo.attribute("description");
651             m_profile.frame_rate_num = profileInfo.attribute("frame_rate_num").toInt();
652             m_profile.frame_rate_den = profileInfo.attribute("frame_rate_den").toInt();
653             m_profile.width = profileInfo.attribute("width").toInt();
654             m_profile.height = profileInfo.attribute("height").toInt();
655             m_profile.progressive = profileInfo.attribute("progressive").toInt();
656             m_profile.sample_aspect_num = profileInfo.attribute("sample_aspect_num").toInt();
657             m_profile.sample_aspect_den = profileInfo.attribute("sample_aspect_den").toInt();
658             m_profile.display_aspect_num = profileInfo.attribute("display_aspect_num").toInt();
659             m_profile.display_aspect_den = profileInfo.attribute("display_aspect_den").toInt();
660             QString existing = ProfilesDialog::existingProfile(m_profile);
661             if (!existing.isEmpty()) {
662                 m_profile = ProfilesDialog::getVideoProfile(existing);
663                 KMessageBox::information(kapp->activeWindow(), i18n("Project profile not found, replacing with existing one: %1", m_profile.description), i18n("Missing Profile"));
664             } else {
665                 QString newDesc = m_profile.description;
666                 bool ok = true;
667                 while (ok && (newDesc.isEmpty() || ProfilesDialog::existingProfileDescription(newDesc))) {
668                     newDesc = QInputDialog::getText(kapp->activeWindow(), i18n("Existing Profile"), i18n("Your project uses an unknown profile.\nIt uses an existing profile name: %1.\nPlease choose a new name to save it", newDesc), QLineEdit::Normal, newDesc, &ok);
669                 }
670                 if (ok == false) {
671                     // User canceled, use default profile
672                     m_profile = ProfilesDialog::getVideoProfile(KdenliveSettings::default_profile());
673                 } else {
674                     if (newDesc != m_profile.description) {
675                         // Profile description existed, was replaced by new one
676                         m_profile.description = newDesc;
677                     } else {
678                         KMessageBox::information(kapp->activeWindow(), i18n("Project profile was not found, it will be added to your system now."), i18n("Missing Profile"));
679                     }
680                     ProfilesDialog::saveProfile(m_profile);
681                 }
682             }
683             setModified(true);
684         }
685     }
686
687     KdenliveSettings::setProject_display_ratio((double) m_profile.display_aspect_num / m_profile.display_aspect_den);
688     m_fps = (double) m_profile.frame_rate_num / m_profile.frame_rate_den;
689     KdenliveSettings::setProject_fps(m_fps);
690     m_width = m_profile.width;
691     m_height = m_profile.height;
692     kDebug() << "Kdenlive document, init timecode from path: " << path << ",  " << m_fps;
693     if (m_fps == 30000.0 / 1001.0) m_timecode.setFormat(30, true);
694     else m_timecode.setFormat((int)(m_fps + 0.5));
695 }
696
697 double KdenliveDoc::dar()
698 {
699     return (double) m_profile.display_aspect_num / m_profile.display_aspect_den;
700 }
701
702 void KdenliveDoc::setThumbsProgress(const QString &message, int progress)
703 {
704     emit progressInfo(message, progress);
705 }
706
707 void KdenliveDoc::loadingProgressed()
708 {
709     m_documentLoadingProgress += m_documentLoadingStep;
710     emit progressInfo(QString(), (int) m_documentLoadingProgress);
711 }
712
713 QUndoStack *KdenliveDoc::commandStack()
714 {
715     return m_commandStack;
716 }
717
718 /*
719 void KdenliveDoc::setRenderer(Render *render) {
720     if (m_render) return;
721     m_render = render;
722     emit progressInfo(i18n("Loading playlist..."), 0);
723     //qApp->processEvents();
724     if (m_render) {
725         m_render->setSceneList(m_document.toString(), m_startPos);
726         kDebug() << "// SETTING SCENE LIST:\n\n" << m_document.toString();
727         checkProjectClips();
728     }
729     emit progressInfo(QString(), -1);
730 }*/
731
732 void KdenliveDoc::checkProjectClips()
733 {
734     kDebug() << "+++++++++++++ + + + + CHK PCLIPS";
735     if (m_render == NULL) return;
736     m_clipManager->resetProducersList(m_render->producersList());
737 }
738
739 void KdenliveDoc::updatePreviewSettings()
740 {
741     m_clipManager->updatePreviewSettings();
742     m_render->updatePreviewSettings();
743     m_clipManager->resetProducersList(m_render->producersList());
744
745 }
746
747 Render *KdenliveDoc::renderer()
748 {
749     return m_render;
750 }
751
752 void KdenliveDoc::updateClip(const QString &id)
753 {
754     emit updateClipDisplay(id);
755 }
756
757 int KdenliveDoc::getFramePos(QString duration)
758 {
759     return m_timecode.getFrameCount(duration, m_fps);
760 }
761
762 QString KdenliveDoc::producerName(const QString &id)
763 {
764     QString result = "unnamed";
765     QDomNodeList prods = producersList();
766     int ct = prods.count();
767     for (int i = 0; i <  ct ; i++) {
768         QDomElement e = prods.item(i).toElement();
769         if (e.attribute("id") != "black" && e.attribute("id") == id) {
770             result = e.attribute("name");
771             if (result.isEmpty()) result = KUrl(e.attribute("resource")).fileName();
772             break;
773         }
774     }
775     return result;
776 }
777
778 QDomDocument KdenliveDoc::toXml()
779 {
780     return m_document;
781 }
782
783 Timecode KdenliveDoc::timecode() const
784 {
785     return m_timecode;
786 }
787
788 QDomNodeList KdenliveDoc::producersList()
789 {
790     return m_document.elementsByTagName("producer");
791 }
792
793 double KdenliveDoc::projectDuration() const
794 {
795     if (m_render)
796         return GenTime(m_render->getLength(), m_fps).ms() / 1000;
797     else
798         return 0;
799 }
800
801 double KdenliveDoc::fps() const
802 {
803     return m_fps;
804 }
805
806 int KdenliveDoc::width() const
807 {
808     return m_width;
809 }
810
811 int KdenliveDoc::height() const
812 {
813     return m_height;
814 }
815
816 KUrl KdenliveDoc::url() const
817 {
818     return m_url;
819 }
820
821 void KdenliveDoc::setUrl(KUrl url)
822 {
823     m_url = url;
824 }
825
826 void KdenliveDoc::setModified(bool mod)
827 {
828     if (!m_url.isEmpty() && mod && KdenliveSettings::crashrecovery()) {
829         m_autoSaveTimer->start(3000);
830     }
831     if (mod == m_modified) return;
832     m_modified = mod;
833     emit docModified(m_modified);
834 }
835
836 bool KdenliveDoc::isModified() const
837 {
838     return m_modified;
839 }
840
841 const QString KdenliveDoc::description() const
842 {
843     if (m_url.isEmpty())
844         return i18n("Untitled") + " / " + m_profile.description;
845     else
846         return m_url.fileName() + " / " + m_profile.description;
847 }
848
849 void KdenliveDoc::addClip(QDomElement elem, QString clipId, bool createClipItem)
850 {
851     const QString producerId = clipId.section('_', 0, 0);
852     DocClipBase *clip = m_clipManager->getClipById(producerId);
853
854     if (clip == NULL) {
855         elem.setAttribute("id", producerId);
856         QString path = elem.attribute("resource");
857         QString extension;
858         if (elem.attribute("type").toInt() == SLIDESHOW) {
859             extension = KUrl(path).fileName();
860             path = KUrl(path).directory();
861         } /*else if (elem.attribute("type").toInt() == TEXT && QFile::exists(path) == false) {
862             kDebug() << "// TITLE: " << elem.attribute("name") << " Preview file: " << elem.attribute("resource") << " DOES NOT EXIST";
863             QString titlename = elem.attribute("name");
864             QString titleresource;
865             if (titlename.isEmpty()) {
866                 QStringList titleInfo = TitleWidget::getFreeTitleInfo(projectFolder());
867                 titlename = titleInfo.at(0);
868                 titleresource = titleInfo.at(1);
869                 elem.setAttribute("name", titlename);
870                 kDebug() << "// New title set to: " << titlename;
871             } else {
872                 titleresource = TitleWidget::getFreeTitleInfo(projectFolder()).at(1);
873                 //titleresource = TitleWidget::getTitleResourceFromName(projectFolder(), titlename);
874             }
875             TitleWidget *dia_ui = new TitleWidget(KUrl(), KUrl(titleresource).directory(), m_render, kapp->activeWindow());
876             QDomDocument doc;
877             doc.setContent(elem.attribute("xmldata"));
878             dia_ui->setXml(doc);
879             QImage pix = dia_ui->renderedPixmap();
880             pix.save(titleresource);
881             elem.setAttribute("resource", titleresource);
882             setNewClipResource(clipId, titleresource);
883             delete dia_ui;
884         }*/
885
886         if (path.isEmpty() == false && QFile::exists(path) == false && elem.attribute("type").toInt() != TEXT && !elem.hasAttribute("placeholder")) {
887             kDebug() << "// FOUND MISSING CLIP: " << path << ", TYPE: " << elem.attribute("type").toInt();
888             const QString size = elem.attribute("file_size");
889             const QString hash = elem.attribute("file_hash");
890             QString newpath;
891             int action = KMessageBox::No;
892             if (!size.isEmpty() && !hash.isEmpty()) {
893                 if (!m_searchFolder.isEmpty()) newpath = searchFileRecursively(m_searchFolder, size, hash);
894                 else action = (KMessageBox::ButtonCode) KMessageBox::questionYesNoCancel(kapp->activeWindow(), i18n("Clip <b>%1</b><br>is invalid, what do you want to do?", path), i18n("File not found"), KGuiItem(i18n("Search automatically")), KGuiItem(i18n("Keep as placeholder")));
895             } else {
896                 if (elem.attribute("type").toInt() == SLIDESHOW) {
897                     int res = KMessageBox::questionYesNoCancel(kapp->activeWindow(), i18n("Clip <b>%1</b><br>is invalid or missing, what do you want to do?", path), i18n("File not found"), KGuiItem(i18n("Search manually")), KGuiItem(i18n("Keep as placeholder")));
898                     if (res == KMessageBox::Yes)
899                         newpath = KFileDialog::getExistingDirectory(KUrl("kfiledialog:///clipfolder"), kapp->activeWindow(), i18n("Looking for %1", path));
900                     else {
901                         // Abort project loading
902                         action = res;
903                     }
904                 } else {
905                     int res = KMessageBox::questionYesNoCancel(kapp->activeWindow(), i18n("Clip <b>%1</b><br>is invalid or missing, what do you want to do?", path), i18n("File not found"), KGuiItem(i18n("Search manually")), KGuiItem(i18n("Keep as placeholder")));
906                     if (res == KMessageBox::Yes)
907                         newpath = KFileDialog::getOpenFileName(KUrl("kfiledialog:///clipfolder"), QString(), kapp->activeWindow(), i18n("Looking for %1", path));
908                     else {
909                         // Abort project loading
910                         action = res;
911                     }
912                 }
913             }
914             if (action == KMessageBox::Yes) {
915                 kDebug() << "// ASKED FOR SRCH CLIP: " << clipId;
916                 m_searchFolder = KFileDialog::getExistingDirectory(KUrl("kfiledialog:///clipfolder"), kapp->activeWindow());
917                 if (!m_searchFolder.isEmpty()) {
918                     newpath = searchFileRecursively(QDir(m_searchFolder), size, hash);
919                 }
920             } else if (action == KMessageBox::Cancel) {
921                 m_abortLoading = true;
922                 return;
923             } else if (action == KMessageBox::No) {
924                 // Keep clip as placeHolder
925                 elem.setAttribute("placeholder", '1');
926             }
927             if (!newpath.isEmpty()) {
928                 if (elem.attribute("type").toInt() == SLIDESHOW) newpath.append('/' + extension);
929                 elem.setAttribute("resource", newpath);
930                 setNewClipResource(clipId, newpath);
931                 setModified(true);
932             }
933         }
934         clip = new DocClipBase(m_clipManager, elem, producerId);
935         m_clipManager->addClip(clip);
936     }
937
938     if (createClipItem) {
939         emit addProjectClip(clip);
940         qApp->processEvents();
941         m_render->getFileProperties(clip->toXML(), clip->getId(), true);
942     }
943 }
944
945
946 void KdenliveDoc::setNewClipResource(const QString &id, const QString &path)
947 {
948     QDomNodeList prods = m_document.elementsByTagName("producer");
949     int maxprod = prods.count();
950     for (int i = 0; i < maxprod; i++) {
951         QDomNode m = prods.at(i);
952         QString prodId = m.toElement().attribute("id");
953         if (prodId == id || prodId.startsWith(id + '_')) {
954             QDomNodeList params = m.childNodes();
955             for (int j = 0; j < params.count(); j++) {
956                 QDomElement e = params.item(j).toElement();
957                 if (e.attribute("name") == "resource") {
958                     e.firstChild().setNodeValue(path);
959                     break;
960                 }
961             }
962         }
963     }
964 }
965
966 QString KdenliveDoc::searchFileRecursively(const QDir &dir, const QString &matchSize, const QString &matchHash) const
967 {
968     QString foundFileName;
969     QByteArray fileData;
970     QByteArray fileHash;
971     QStringList filesAndDirs = dir.entryList(QDir::Files | QDir::Readable);
972     for (int i = 0; i < filesAndDirs.size() && foundFileName.isEmpty(); i++) {
973         QFile file(dir.absoluteFilePath(filesAndDirs.at(i)));
974         if (file.open(QIODevice::ReadOnly)) {
975             if (QString::number(file.size()) == matchSize) {
976                 /*
977                 * 1 MB = 1 second per 450 files (or faster)
978                 * 10 MB = 9 seconds per 450 files (or faster)
979                 */
980                 if (file.size() > 1000000*2) {
981                     fileData = file.read(1000000);
982                     if (file.seek(file.size() - 1000000))
983                         fileData.append(file.readAll());
984                 } else
985                     fileData = file.readAll();
986                 file.close();
987                 fileHash = QCryptographicHash::hash(fileData, QCryptographicHash::Md5);
988                 if (QString(fileHash.toHex()) == matchHash)
989                     return file.fileName();
990             }
991         }
992         kDebug() << filesAndDirs.at(i) << file.size() << fileHash.toHex();
993     }
994     filesAndDirs = dir.entryList(QDir::Dirs | QDir::Readable | QDir::Executable | QDir::NoDotAndDotDot);
995     for (int i = 0; i < filesAndDirs.size() && foundFileName.isEmpty(); i++) {
996         foundFileName = searchFileRecursively(dir.absoluteFilePath(filesAndDirs.at(i)), matchSize, matchHash);
997         if (!foundFileName.isEmpty())
998             break;
999     }
1000     return foundFileName;
1001 }
1002
1003 void KdenliveDoc::addClipInfo(QDomElement elem, QDomElement orig, QString clipId)
1004 {
1005     DocClipBase *clip = m_clipManager->getClipById(clipId);
1006     if (clip == NULL) {
1007         addClip(elem, clipId, false);
1008     } else {
1009         QMap <QString, QString> properties;
1010         QDomNamedNodeMap attributes = elem.attributes();
1011         QString attrname;
1012         for (int i = 0; i < attributes.count(); i++) {
1013             attrname = attributes.item(i).nodeName();
1014             if (attrname != "resource")
1015                 properties.insert(attrname, attributes.item(i).nodeValue());
1016             kDebug() << attrname << " = " << attributes.item(i).nodeValue();
1017         }
1018         clip->setProperties(properties);
1019         emit addProjectClip(clip, false);
1020     }
1021     if (orig != QDomElement()) {
1022         QMap<QString, QString> meta;
1023         QDomNode m = orig.firstChild();
1024         while (!m.isNull()) {
1025             QString name = m.toElement().attribute("name");
1026             if (name.startsWith("meta.attr")) {
1027                 meta.insert(name.section('.', 2, 3), m.firstChild().nodeValue());
1028             }
1029             m = m.nextSibling();
1030         }
1031         if (!meta.isEmpty()) {
1032             if (clip == NULL) clip = m_clipManager->getClipById(clipId);
1033             if (clip) clip->setMetadata(meta);
1034         }
1035     }
1036 }
1037
1038 void KdenliveDoc::deleteProjectClip(QList <QString> ids)
1039 {
1040     for (int i = 0; i < ids.size(); ++i) {
1041         emit deleteTimelineClip(ids.at(i));
1042         m_clipManager->slotDeleteClip(ids.at(i));
1043     }
1044     setModified(true);
1045 }
1046
1047 void KdenliveDoc::deleteClip(const QString &clipId)
1048 {
1049     emit signalDeleteProjectClip(clipId);
1050 }
1051
1052 void KdenliveDoc::slotAddClipList(const KUrl::List urls, const QString group, const QString &groupId)
1053 {
1054     m_clipManager->slotAddClipList(urls, group, groupId);
1055     emit selectLastAddedClip(QString::number(m_clipManager->lastClipId()));
1056     setModified(true);
1057 }
1058
1059
1060 void KdenliveDoc::slotAddClipFile(const KUrl url, const QString group, const QString &groupId)
1061 {
1062     m_clipManager->slotAddClipFile(url, group, groupId);
1063     emit selectLastAddedClip(QString::number(m_clipManager->lastClipId()));
1064     setModified(true);
1065 }
1066
1067 const QString KdenliveDoc::getFreeClipId()
1068 {
1069     return QString::number(m_clipManager->getFreeClipId());
1070 }
1071
1072 DocClipBase *KdenliveDoc::getBaseClip(const QString &clipId)
1073 {
1074     return m_clipManager->getClipById(clipId);
1075 }
1076
1077 void KdenliveDoc::slotCreateColorClip(const QString &name, const QString &color, const QString &duration, QString group, const QString &groupId)
1078 {
1079     m_clipManager->slotAddColorClipFile(name, color, duration, group, groupId);
1080     setModified(true);
1081     emit selectLastAddedClip(QString::number(m_clipManager->lastClipId()));
1082 }
1083
1084 void KdenliveDoc::slotCreateSlideshowClipFile(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, QString group, const QString &groupId)
1085 {
1086     m_clipManager->slotAddSlideshowClipFile(name, path, count, duration, loop, fade, luma_duration, luma_file, softness, group, groupId);
1087     setModified(true);
1088     emit selectLastAddedClip(QString::number(m_clipManager->lastClipId()));
1089 }
1090
1091 void KdenliveDoc::slotCreateTextClip(QString group, const QString &groupId, const QString &templatePath)
1092 {
1093     QString titlesFolder = projectFolder().path(KUrl::AddTrailingSlash) + "titles/";
1094     KStandardDirs::makeDir(titlesFolder);
1095     TitleWidget *dia_ui = new TitleWidget(templatePath, m_timecode, titlesFolder, m_render, kapp->activeWindow());
1096     if (dia_ui->exec() == QDialog::Accepted) {
1097         /*QStringList titleInfo = TitleWidget::getFreeTitleInfo(projectFolder());
1098         QImage pix = dia_ui->renderedPixmap();
1099         pix.save(titleInfo.at(1));*/
1100         //dia_ui->saveTitle(path + ".kdenlivetitle");
1101         m_clipManager->slotAddTextClipFile(i18n("Title clip"), dia_ui->duration(), dia_ui->xml().toString(), group, groupId);
1102         setModified(true);
1103         emit selectLastAddedClip(QString::number(m_clipManager->lastClipId()));
1104     }
1105     delete dia_ui;
1106 }
1107
1108 void KdenliveDoc::slotCreateTextTemplateClip(QString group, const QString &groupId, KUrl path)
1109 {
1110     QString titlesFolder = projectFolder().path(KUrl::AddTrailingSlash) + "titles/";
1111     if (path.isEmpty()) {
1112         path = KFileDialog::getOpenUrl(KUrl(titlesFolder), "*.kdenlivetitle", kapp->activeWindow(), i18n("Enter Template Path"));
1113     }
1114
1115     if (path.isEmpty()) return;
1116
1117     QStringList titleInfo = TitleWidget::getFreeTitleInfo(projectFolder(), true);
1118
1119     //TODO: rewrite with new title system (just set resource)
1120     /*TitleWidget *dia_ui = new TitleWidget(path, titlesFolder, m_render, kapp->activeWindow());
1121     QImage pix = dia_ui->renderedPixmap();
1122     pix.save(titleInfo.at(1));
1123     delete dia_ui;
1124     m_clipManager->slotAddTextTemplateClip(titleInfo.at(0), titleInfo.at(1), path, group, groupId);
1125     setModified(true);*/
1126     emit selectLastAddedClip(QString::number(m_clipManager->lastClipId()));
1127 }
1128
1129 int KdenliveDoc::tracksCount() const
1130 {
1131     return m_tracksList.count();
1132 }
1133
1134 TrackInfo KdenliveDoc::trackInfoAt(int ix) const
1135 {
1136     return m_tracksList.at(ix);
1137 }
1138
1139 void KdenliveDoc::switchTrackAudio(int ix, bool hide)
1140 {
1141     m_tracksList[ix].isMute = hide; // !m_tracksList.at(ix).isMute;
1142 }
1143
1144 void KdenliveDoc::switchTrackLock(int ix, bool lock)
1145 {
1146     m_tracksList[ix].isLocked = lock;
1147 }
1148
1149 bool KdenliveDoc::isTrackLocked(int ix) const
1150 {
1151     return m_tracksList.at(ix).isLocked;
1152 }
1153
1154 void KdenliveDoc::switchTrackVideo(int ix, bool hide)
1155 {
1156     m_tracksList[ix].isBlind = hide; // !m_tracksList.at(ix).isBlind;
1157 }
1158
1159 void KdenliveDoc::insertTrack(int ix, TrackInfo type)
1160 {
1161     if (ix == -1) m_tracksList << type;
1162     else m_tracksList.insert(ix, type);
1163 }
1164
1165 void KdenliveDoc::deleteTrack(int ix)
1166 {
1167     m_tracksList.removeAt(ix);
1168 }
1169
1170 void KdenliveDoc::setTrackType(int ix, TrackInfo type)
1171 {
1172     m_tracksList[ix].type = type.type;
1173     m_tracksList[ix].isMute = type.isMute;
1174     m_tracksList[ix].isBlind = type.isBlind;
1175     m_tracksList[ix].isLocked = type.isLocked;
1176 }
1177
1178 const QList <TrackInfo> KdenliveDoc::tracksList() const
1179 {
1180     return m_tracksList;
1181 }
1182
1183 QPoint KdenliveDoc::getTracksCount() const
1184 {
1185     int audio = 0;
1186     int video = 0;
1187     foreach(const TrackInfo &info, m_tracksList) {
1188         if (info.type == VIDEOTRACK) video++;
1189         else audio++;
1190     }
1191     return QPoint(video, audio);
1192 }
1193
1194 void KdenliveDoc::cachePixmap(const QString &fileId, const QPixmap &pix) const
1195 {
1196     pix.save(m_projectFolder.path(KUrl::AddTrailingSlash) + "thumbs/" + fileId + ".png");
1197 }
1198
1199 QString KdenliveDoc::getLadspaFile() const
1200 {
1201     int ct = 0;
1202     QString counter = QString::number(ct).rightJustified(5, '0', false);
1203     while (QFile::exists(m_projectFolder.path(KUrl::AddTrailingSlash) + "ladspa/" + counter + ".ladspa")) {
1204         ct++;
1205         counter = QString::number(ct).rightJustified(5, '0', false);
1206     }
1207     return m_projectFolder.path(KUrl::AddTrailingSlash) + "ladspa/" + counter + ".ladspa";
1208 }
1209
1210 bool KdenliveDoc::checkDocumentClips(QDomNodeList infoproducers)
1211 {
1212     int clipType;
1213     QDomElement e;
1214     QString id;
1215     QString resource;
1216     QList <QDomElement> missingClips;
1217     for (int i = 0; i < infoproducers.count(); i++) {
1218         e = infoproducers.item(i).toElement();
1219         clipType = e.attribute("type").toInt();
1220         if (clipType == COLOR) continue;
1221         if (clipType == TEXT) {
1222             //TODO: Check is clip template is missing (xmltemplate) or hash changed
1223             continue;
1224         }
1225         id = e.attribute("id");
1226         resource = e.attribute("resource");
1227         if (clipType == SLIDESHOW) resource = KUrl(resource).directory();
1228         if (!KIO::NetAccess::exists(KUrl(resource), KIO::NetAccess::SourceSide, 0)) {
1229             // Missing clip found
1230             missingClips.append(e);
1231         } else {
1232             // Check if the clip has changed
1233             if (clipType != SLIDESHOW && e.hasAttribute("file_hash")) {
1234                 if (e.attribute("file_hash") != DocClipBase::getHash(e.attribute("resource")))
1235                     e.removeAttribute("file_hash");
1236             }
1237         }
1238     }
1239     if (missingClips.isEmpty()) return true;
1240     DocumentChecker d(missingClips, m_document);
1241     return (d.exec() == QDialog::Accepted);
1242 }
1243
1244 void KdenliveDoc::setDocumentProperty(const QString &name, const QString &value)
1245 {
1246     m_documentProperties[name] = value;
1247 }
1248
1249 const QString KdenliveDoc::getDocumentProperty(const QString &name) const
1250 {
1251     return m_documentProperties.value(name);
1252 }
1253
1254 #include "kdenlivedoc.moc"
1255