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