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