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