]> git.sesse.net Git - kdenlive/blob - src/kdenlivedoc.cpp
Don't crash when wrong sdl driver was selected by user (needs MLT patch):
[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_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         m_url = KUrl();
207         m_document = createEmptyDocument(tracks.x(), tracks.y());
208     }
209
210     // Set the video profile (empty == default)
211
212     // Make sure the project folder is usable
213     if (m_projectFolder.isEmpty() || !KIO::NetAccess::exists(m_projectFolder.path(), KIO::NetAccess::DestinationSide, parent)) {
214         KMessageBox::information(parent, i18n("Document project folder is invalid, setting it to the default one: %1", KdenliveSettings::defaultprojectfolder()));
215         m_projectFolder = KUrl(KdenliveSettings::defaultprojectfolder());
216     }
217
218     // Make sure that the necessary folders exist
219     KStandardDirs::makeDir(m_projectFolder.path(KUrl::AddTrailingSlash) + "titles/");
220     KStandardDirs::makeDir(m_projectFolder.path(KUrl::AddTrailingSlash) + "thumbs/");
221     KStandardDirs::makeDir(m_projectFolder.path(KUrl::AddTrailingSlash) + "ladspa/");
222
223     kDebug() << "Kdenlive document, init timecode: " << m_fps;
224     if (m_fps == 30000.0 / 1001.0) m_timecode.setFormat(30, true);
225     else m_timecode.setFormat((int) m_fps);
226
227     //kDebug() << "// SETTING SCENE LIST:\n\n" << m_document.toString();
228     connect(m_autoSaveTimer, SIGNAL(timeout()), this, SLOT(slotAutoSave()));
229 }
230
231 KdenliveDoc::~KdenliveDoc()
232 {
233     delete m_commandStack;
234     delete m_clipManager;
235     delete m_autoSaveTimer;
236     if (m_autosave) {
237         if (!m_autosave->fileName().isEmpty()) m_autosave->remove();
238         delete m_autosave;
239     }
240 }
241
242 int KdenliveDoc::setSceneList()
243 {
244     if (m_render->setSceneList(m_document.toString(), m_documentProperties.value("position").toInt()) == -1) {
245         // INVALID MLT Consumer, something is wrong
246         return -1;
247     }
248     m_documentProperties.remove("position");
249     // m_document xml is now useless, clear it
250     m_document.clear();
251     checkProjectClips();
252     return 0;
253 }
254
255 QDomDocument KdenliveDoc::createEmptyDocument(const int videotracks, const int audiotracks)
256 {
257     // Creating new document
258     QDomDocument doc;
259     QDomElement mlt = doc.createElement("mlt");
260     doc.appendChild(mlt);
261
262
263     TrackInfo videoTrack;
264     videoTrack.type = VIDEOTRACK;
265     videoTrack.isMute = false;
266     videoTrack.isBlind = false;
267     videoTrack.isLocked = false;
268
269     TrackInfo audioTrack;
270     audioTrack.type = AUDIOTRACK;
271     audioTrack.isMute = false;
272     audioTrack.isBlind = true;
273     audioTrack.isLocked = false;
274
275     QDomElement tractor = doc.createElement("tractor");
276     tractor.setAttribute("id", "maintractor");
277     QDomElement multitrack = doc.createElement("multitrack");
278     QDomElement playlist = doc.createElement("playlist");
279     playlist.setAttribute("id", "black_track");
280     mlt.appendChild(playlist);
281
282
283     // create playlists
284     int total = audiotracks + videotracks + 1;
285
286     for (int i = 1; i < total; i++) {
287         QDomElement playlist = doc.createElement("playlist");
288         playlist.setAttribute("id", "playlist" + QString::number(i));
289         mlt.appendChild(playlist);
290     }
291
292     QDomElement track0 = doc.createElement("track");
293     track0.setAttribute("producer", "black_track");
294     tractor.appendChild(track0);
295
296     // create audio tracks
297     for (int i = 1; i < audiotracks + 1; i++) {
298         QDomElement track = doc.createElement("track");
299         track.setAttribute("producer", "playlist" + QString::number(i));
300         track.setAttribute("hide", "video");
301         tractor.appendChild(track);
302         m_tracksList.append(audioTrack);
303     }
304
305     // create video tracks
306     for (int i = audiotracks + 1; i < total; i++) {
307         QDomElement track = doc.createElement("track");
308         track.setAttribute("producer", "playlist" + QString::number(i));
309         tractor.appendChild(track);
310         m_tracksList.append(videoTrack);
311     }
312
313     for (int i = 2; i < total ; i++) {
314         QDomElement transition = doc.createElement("transition");
315         transition.setAttribute("always_active", "1");
316
317         QDomElement property = doc.createElement("property");
318         property.setAttribute("name", "a_track");
319         QDomText value = doc.createTextNode(QString::number(1));
320         property.appendChild(value);
321         transition.appendChild(property);
322
323         property = doc.createElement("property");
324         property.setAttribute("name", "b_track");
325         value = doc.createTextNode(QString::number(i));
326         property.appendChild(value);
327         transition.appendChild(property);
328
329         property = doc.createElement("property");
330         property.setAttribute("name", "mlt_service");
331         value = doc.createTextNode("mix");
332         property.appendChild(value);
333         transition.appendChild(property);
334
335         property = doc.createElement("property");
336         property.setAttribute("name", "combine");
337         value = doc.createTextNode("1");
338         property.appendChild(value);
339         transition.appendChild(property);
340
341         property = doc.createElement("property");
342         property.setAttribute("name", "internal_added");
343         value = doc.createTextNode("237");
344         property.appendChild(value);
345         transition.appendChild(property);
346         tractor.appendChild(transition);
347     }
348     mlt.appendChild(tractor);
349     return doc;
350 }
351
352
353 void KdenliveDoc::syncGuides(QList <Guide *> guides)
354 {
355     m_guidesXml.clear();
356     QDomElement guideNode = m_guidesXml.createElement("guides");
357     m_guidesXml.appendChild(guideNode);
358     QDomElement e;
359
360     for (int i = 0; i < guides.count(); i++) {
361         e = m_guidesXml.createElement("guide");
362         e.setAttribute("time", guides.at(i)->position().ms() / 1000);
363         e.setAttribute("comment", guides.at(i)->label());
364         guideNode.appendChild(e);
365     }
366     setModified(true);
367     emit guidesUpdated();
368 }
369
370 QDomElement KdenliveDoc::guidesXml() const
371 {
372     return m_guidesXml.documentElement();
373 }
374
375 void KdenliveDoc::slotAutoSave()
376 {
377     if (m_render && m_autosave) {
378         if (!m_autosave->isOpen() && !m_autosave->open(QIODevice::ReadWrite)) {
379             // show error: could not open the autosave file
380             kDebug() << "ERROR; CANNOT CREATE AUTOSAVE FILE";
381         }
382         kDebug() << "// AUTOSAVE FILE: " << m_autosave->fileName();
383         QString doc;
384         if (KdenliveSettings::dropbframes()) {
385             KdenliveSettings::setDropbframes(false);
386             m_clipManager->updatePreviewSettings();
387             doc = m_render->sceneList();
388             KdenliveSettings::setDropbframes(true);
389             m_clipManager->updatePreviewSettings();
390         } else doc = m_render->sceneList();
391         saveSceneList(m_autosave->fileName(), doc);
392     }
393 }
394
395 void KdenliveDoc::setZoom(int horizontal, int vertical)
396 {
397     m_documentProperties["zoom"] = QString::number(horizontal);
398     m_documentProperties["verticalzoom"] = QString::number(vertical);
399 }
400
401 QPoint KdenliveDoc::zoom() const
402 {
403     return QPoint(m_documentProperties.value("zoom").toInt(), m_documentProperties.value("verticalzoom").toInt());
404 }
405
406 void KdenliveDoc::setZone(int start, int end)
407 {
408     m_documentProperties["zonein"] = QString::number(start);
409     m_documentProperties["zoneout"] = QString::number(end);
410 }
411
412 QPoint KdenliveDoc::zone() const
413 {
414     return QPoint(m_documentProperties.value("zonein").toInt(), m_documentProperties.value("zoneout").toInt());
415 }
416
417 bool KdenliveDoc::saveSceneList(const QString &path, const QString &scene)
418 {
419     QDomDocument sceneList;
420     sceneList.setContent(scene, true);
421     QDomElement mlt = sceneList.firstChildElement("mlt");
422     QDomElement addedXml = sceneList.createElement("kdenlivedoc");
423     mlt.appendChild(addedXml);
424
425     QDomElement markers = sceneList.createElement("markers");
426     addedXml.setAttribute("version", DOCUMENTVERSION);
427     addedXml.setAttribute("kdenliveversion", VERSION);
428     addedXml.setAttribute("profile", profilePath());
429     addedXml.setAttribute("projectfolder", m_projectFolder.path());
430
431     QDomElement docproperties = sceneList.createElement("documentproperties");
432     QMapIterator<QString, QString> i(m_documentProperties);
433     while (i.hasNext()) {
434         i.next();
435         docproperties.setAttribute(i.key(), i.value());
436     }
437     docproperties.setAttribute("position", m_render->seekPosition().frames(m_fps));
438     addedXml.appendChild(docproperties);
439
440     // Add profile info
441     QDomElement profileinfo = sceneList.createElement("profileinfo");
442     profileinfo.setAttribute("description", m_profile.description);
443     profileinfo.setAttribute("frame_rate_num", m_profile.frame_rate_num);
444     profileinfo.setAttribute("frame_rate_den", m_profile.frame_rate_den);
445     profileinfo.setAttribute("width", m_profile.width);
446     profileinfo.setAttribute("height", m_profile.height);
447     profileinfo.setAttribute("progressive", m_profile.progressive);
448     profileinfo.setAttribute("sample_aspect_num", m_profile.sample_aspect_num);
449     profileinfo.setAttribute("sample_aspect_den", m_profile.sample_aspect_den);
450     profileinfo.setAttribute("display_aspect_num", m_profile.display_aspect_num);
451     profileinfo.setAttribute("display_aspect_den", m_profile.display_aspect_den);
452     addedXml.appendChild(profileinfo);
453
454     // tracks info
455     QDomElement tracksinfo = sceneList.createElement("tracksinfo");
456     foreach(const TrackInfo &info, m_tracksList) {
457         QDomElement trackinfo = sceneList.createElement("trackinfo");
458         if (info.type == AUDIOTRACK) trackinfo.setAttribute("type", "audio");
459         trackinfo.setAttribute("mute", info.isMute);
460         trackinfo.setAttribute("blind", info.isBlind);
461         trackinfo.setAttribute("locked", info.isLocked);
462         tracksinfo.appendChild(trackinfo);
463     }
464     addedXml.appendChild(tracksinfo);
465
466     // save project folders
467     QMap <QString, QString> folderlist = m_clipManager->documentFolderList();
468
469     QMapIterator<QString, QString> f(folderlist);
470     while (f.hasNext()) {
471         f.next();
472         QDomElement folder = sceneList.createElement("folder");
473         folder.setAttribute("id", f.key());
474         folder.setAttribute("name", f.value());
475         addedXml.appendChild(folder);
476     }
477
478     // Save project clips
479     QDomElement e;
480     QList <DocClipBase*> list = m_clipManager->documentClipList();
481     for (int i = 0; i < list.count(); i++) {
482         e = list.at(i)->toXML();
483         e.setTagName("kdenlive_producer");
484         addedXml.appendChild(sceneList.importNode(e, true));
485         QList < CommentedTime > marks = list.at(i)->commentedSnapMarkers();
486         for (int j = 0; j < marks.count(); j++) {
487             QDomElement marker = sceneList.createElement("marker");
488             marker.setAttribute("time", marks.at(j).time().ms() / 1000);
489             marker.setAttribute("comment", marks.at(j).comment());
490             marker.setAttribute("id", e.attribute("id"));
491             markers.appendChild(marker);
492         }
493     }
494     addedXml.appendChild(markers);
495
496     // Add guides
497     if (!m_guidesXml.isNull()) addedXml.appendChild(sceneList.importNode(m_guidesXml.documentElement(), true));
498
499     // Add clip groups
500     addedXml.appendChild(sceneList.importNode(m_clipManager->groupsXml(), true));
501
502     //wes.appendChild(doc.importNode(kdenliveData, true));
503
504     QFile file(path);
505     if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
506         kWarning() << "//////  ERROR writing to file: " << path;
507         KMessageBox::error(kapp->activeWindow(), i18n("Cannot write to file %1", path));
508         return false;
509     }
510
511     file.write(sceneList.toString().toUtf8());
512     if (file.error() != QFile::NoError) {
513         KMessageBox::error(kapp->activeWindow(), i18n("Cannot write to file %1", path));
514         file.close();
515         return false;
516     }
517     file.close();
518     return true;
519 }
520
521 ClipManager *KdenliveDoc::clipManager()
522 {
523     return m_clipManager;
524 }
525
526 KUrl KdenliveDoc::projectFolder() const
527 {
528     //if (m_projectFolder.isEmpty()) return KUrl(KStandardDirs::locateLocal("appdata", "/projects/"));
529     return m_projectFolder;
530 }
531
532 void KdenliveDoc::setProjectFolder(KUrl url)
533 {
534     if (url == m_projectFolder) return;
535     setModified(true);
536     KStandardDirs::makeDir(url.path());
537     KStandardDirs::makeDir(url.path(KUrl::AddTrailingSlash) + "titles/");
538     KStandardDirs::makeDir(url.path(KUrl::AddTrailingSlash) + "thumbs/");
539     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);
540     m_projectFolder = url;
541 }
542
543 void KdenliveDoc::moveProjectData(KUrl url)
544 {
545     QList <DocClipBase*> list = m_clipManager->documentClipList();
546     //TODO: Also move ladspa effects files
547     for (int i = 0; i < list.count(); i++) {
548         DocClipBase *clip = list.at(i);
549         if (clip->clipType() == TEXT) {
550             // the image for title clip must be moved
551             KUrl oldUrl = clip->fileURL();
552             KUrl newUrl = KUrl(url.path(KUrl::AddTrailingSlash) + "titles/" + oldUrl.fileName());
553             KIO::Job *job = KIO::copy(oldUrl, newUrl);
554             if (KIO::NetAccess::synchronousRun(job, 0)) clip->setProperty("resource", newUrl.path());
555         }
556         QString hash = clip->getClipHash();
557         KUrl oldVideoThumbUrl = KUrl(m_projectFolder.path(KUrl::AddTrailingSlash) + "thumbs/" + hash + ".png");
558         KUrl oldAudioThumbUrl = KUrl(m_projectFolder.path(KUrl::AddTrailingSlash) + "thumbs/" + hash + ".thumb");
559         if (KIO::NetAccess::exists(oldVideoThumbUrl, KIO::NetAccess::SourceSide, 0)) {
560             KUrl newUrl = KUrl(url.path(KUrl::AddTrailingSlash) + "thumbs/" + hash + ".png");
561             KIO::Job *job = KIO::copy(oldVideoThumbUrl, newUrl);
562             KIO::NetAccess::synchronousRun(job, 0);
563         }
564         if (KIO::NetAccess::exists(oldAudioThumbUrl, KIO::NetAccess::SourceSide, 0)) {
565             KUrl newUrl = KUrl(url.path(KUrl::AddTrailingSlash) + "thumbs/" + hash + ".thumb");
566             KIO::Job *job = KIO::copy(oldAudioThumbUrl, newUrl);
567             if (KIO::NetAccess::synchronousRun(job, 0)) clip->refreshThumbUrl();
568         }
569     }
570 }
571
572 const QString &KdenliveDoc::profilePath() const
573 {
574     return m_profile.path;
575 }
576
577 MltVideoProfile KdenliveDoc::mltProfile() const
578 {
579     return m_profile;
580 }
581
582 void KdenliveDoc::setProfilePath(QString path)
583 {
584     if (path.isEmpty()) path = KdenliveSettings::default_profile();
585     if (path.isEmpty()) path = "dv_pal";
586     m_profile = ProfilesDialog::getVideoProfile(path);
587     if (m_profile.path.isEmpty()) {
588         // Profile not found, use embedded profile
589         QDomElement profileInfo = m_document.elementsByTagName("profileinfo").at(0).toElement();
590         if (profileInfo.isNull()) {
591             KMessageBox::information(kapp->activeWindow(), i18n("Project profile was not found, using default profile."), i18n("Missing Profile"));
592             m_profile = ProfilesDialog::getVideoProfile(KdenliveSettings::default_profile());
593         } else {
594             m_profile.description = profileInfo.attribute("description");
595             m_profile.frame_rate_num = profileInfo.attribute("frame_rate_num").toInt();
596             m_profile.frame_rate_den = profileInfo.attribute("frame_rate_den").toInt();
597             m_profile.width = profileInfo.attribute("width").toInt();
598             m_profile.height = profileInfo.attribute("height").toInt();
599             m_profile.progressive = profileInfo.attribute("progressive").toInt();
600             m_profile.sample_aspect_num = profileInfo.attribute("sample_aspect_num").toInt();
601             m_profile.sample_aspect_den = profileInfo.attribute("sample_aspect_den").toInt();
602             m_profile.display_aspect_num = profileInfo.attribute("display_aspect_num").toInt();
603             m_profile.display_aspect_den = profileInfo.attribute("display_aspect_den").toInt();
604             QString existing = ProfilesDialog::existingProfile(m_profile);
605             if (!existing.isEmpty()) {
606                 m_profile = ProfilesDialog::getVideoProfile(existing);
607                 KMessageBox::information(kapp->activeWindow(), i18n("Project profile not found, replacing with existing one: %1", m_profile.description), i18n("Missing Profile"));
608             } else {
609                 QString newDesc = m_profile.description;
610                 bool ok = true;
611                 while (ok && (newDesc.isEmpty() || ProfilesDialog::existingProfileDescription(newDesc))) {
612                     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);
613                 }
614                 if (ok == false) {
615                     // User canceled, use default profile
616                     m_profile = ProfilesDialog::getVideoProfile(KdenliveSettings::default_profile());
617                 } else {
618                     if (newDesc != m_profile.description) {
619                         // Profile description existed, was replaced by new one
620                         m_profile.description = newDesc;
621                     } else {
622                         KMessageBox::information(kapp->activeWindow(), i18n("Project profile was not found, it will be added to your system now."), i18n("Missing Profile"));
623                     }
624                     ProfilesDialog::saveProfile(m_profile);
625                 }
626             }
627             setModified(true);
628         }
629     }
630
631     KdenliveSettings::setProject_display_ratio((double) m_profile.display_aspect_num / m_profile.display_aspect_den);
632     m_fps = (double) m_profile.frame_rate_num / m_profile.frame_rate_den;
633     KdenliveSettings::setProject_fps(m_fps);
634     m_width = m_profile.width;
635     m_height = m_profile.height;
636     kDebug() << "Kdenlive document, init timecode from path: " << path << ",  " << m_fps;
637     if (m_fps == 30000.0 / 1001.0) m_timecode.setFormat(30, true);
638     else m_timecode.setFormat((int) m_fps);
639 }
640
641 double KdenliveDoc::dar()
642 {
643     return (double) m_profile.display_aspect_num / m_profile.display_aspect_den;
644 }
645
646 void KdenliveDoc::setThumbsProgress(const QString &message, int progress)
647 {
648     emit progressInfo(message, progress);
649 }
650
651 void KdenliveDoc::loadingProgressed()
652 {
653     m_documentLoadingProgress += m_documentLoadingStep;
654     emit progressInfo(QString(), (int) m_documentLoadingProgress);
655 }
656
657 QUndoStack *KdenliveDoc::commandStack()
658 {
659     return m_commandStack;
660 }
661
662 /*
663 void KdenliveDoc::setRenderer(Render *render) {
664     if (m_render) return;
665     m_render = render;
666     emit progressInfo(i18n("Loading playlist..."), 0);
667     //qApp->processEvents();
668     if (m_render) {
669         m_render->setSceneList(m_document.toString(), m_startPos);
670         kDebug() << "// SETTING SCENE LIST:\n\n" << m_document.toString();
671         checkProjectClips();
672     }
673     emit progressInfo(QString(), -1);
674 }*/
675
676 void KdenliveDoc::checkProjectClips()
677 {
678     kDebug() << "+++++++++++++ + + + + CHK PCLIPS";
679     if (m_render == NULL) return;
680     m_clipManager->resetProducersList(m_render->producersList());
681 }
682
683 void KdenliveDoc::updatePreviewSettings()
684 {
685     m_clipManager->updatePreviewSettings();
686     m_render->updatePreviewSettings();
687     m_clipManager->resetProducersList(m_render->producersList());
688
689 }
690
691 Render *KdenliveDoc::renderer()
692 {
693     return m_render;
694 }
695
696 void KdenliveDoc::updateClip(const QString &id)
697 {
698     emit updateClipDisplay(id);
699 }
700
701 int KdenliveDoc::getFramePos(QString duration)
702 {
703     return m_timecode.getFrameCount(duration, m_fps);
704 }
705
706 QString KdenliveDoc::producerName(const QString &id)
707 {
708     QString result = "unnamed";
709     QDomNodeList prods = producersList();
710     int ct = prods.count();
711     for (int i = 0; i <  ct ; i++) {
712         QDomElement e = prods.item(i).toElement();
713         if (e.attribute("id") != "black" && e.attribute("id") == id) {
714             result = e.attribute("name");
715             if (result.isEmpty()) result = KUrl(e.attribute("resource")).fileName();
716             break;
717         }
718     }
719     return result;
720 }
721
722 QDomDocument KdenliveDoc::toXml()
723 {
724     return m_document;
725 }
726
727 Timecode KdenliveDoc::timecode() const
728 {
729     return m_timecode;
730 }
731
732 QDomNodeList KdenliveDoc::producersList()
733 {
734     return m_document.elementsByTagName("producer");
735 }
736
737 double KdenliveDoc::projectDuration() const
738 {
739     if (m_render)
740         return GenTime(m_render->getLength(), m_fps).ms() / 1000;
741     else
742         return 0;
743 }
744
745 double KdenliveDoc::fps() const
746 {
747     return m_fps;
748 }
749
750 int KdenliveDoc::width() const
751 {
752     return m_width;
753 }
754
755 int KdenliveDoc::height() const
756 {
757     return m_height;
758 }
759
760 KUrl KdenliveDoc::url() const
761 {
762     return m_url;
763 }
764
765 void KdenliveDoc::setUrl(KUrl url)
766 {
767     m_url = url;
768 }
769
770 void KdenliveDoc::setModified(bool mod)
771 {
772     if (!m_url.isEmpty() && mod && KdenliveSettings::crashrecovery()) {
773         m_autoSaveTimer->start(3000);
774     }
775     if (mod == m_modified) return;
776     m_modified = mod;
777     emit docModified(m_modified);
778 }
779
780 bool KdenliveDoc::isModified() const
781 {
782     return m_modified;
783 }
784
785 const QString KdenliveDoc::description() const
786 {
787     if (m_url.isEmpty())
788         return i18n("Untitled") + " / " + m_profile.description;
789     else
790         return m_url.fileName() + " / " + m_profile.description;
791 }
792
793 void KdenliveDoc::addClip(QDomElement elem, QString clipId, bool createClipItem)
794 {
795     const QString producerId = clipId.section('_', 0, 0);
796     DocClipBase *clip = m_clipManager->getClipById(producerId);
797
798     if (clip == NULL) {
799         elem.setAttribute("id", producerId);
800         QString path = elem.attribute("resource");
801         QString extension;
802         if (elem.attribute("type").toInt() == SLIDESHOW) {
803             extension = KUrl(path).fileName();
804             path = KUrl(path).directory();
805         } else if (elem.attribute("type").toInt() == TEXT && QFile::exists(path) == false) {
806             kDebug() << "// TITLE: " << elem.attribute("name") << " Preview file: " << elem.attribute("resource") << " DOES NOT EXIST";
807             QString titlename = elem.attribute("name");
808             QString titleresource;
809             if (titlename.isEmpty()) {
810                 QStringList titleInfo = TitleWidget::getFreeTitleInfo(projectFolder());
811                 titlename = titleInfo.at(0);
812                 titleresource = titleInfo.at(1);
813                 elem.setAttribute("name", titlename);
814                 kDebug() << "// New title set to: " << titlename;
815             } else {
816                 titleresource = TitleWidget::getFreeTitleInfo(projectFolder()).at(1);
817                 //titleresource = TitleWidget::getTitleResourceFromName(projectFolder(), titlename);
818             }
819             TitleWidget *dia_ui = new TitleWidget(KUrl(), KUrl(titleresource).directory(), m_render, kapp->activeWindow());
820             QDomDocument doc;
821             doc.setContent(elem.attribute("xmldata"));
822             dia_ui->setXml(doc);
823             QImage pix = dia_ui->renderedPixmap();
824             pix.save(titleresource);
825             elem.setAttribute("resource", titleresource);
826             setNewClipResource(clipId, titleresource);
827             delete dia_ui;
828         }
829
830         if (path.isEmpty() == false && QFile::exists(path) == false && elem.attribute("type").toInt() != TEXT && !elem.hasAttribute("placeholder")) {
831             kDebug() << "// FOUND MISSING CLIP: " << path << ", TYPE: " << elem.attribute("type").toInt();
832             const QString size = elem.attribute("file_size");
833             const QString hash = elem.attribute("file_hash");
834             QString newpath;
835             int action = KMessageBox::No;
836             if (!size.isEmpty() && !hash.isEmpty()) {
837                 if (!m_searchFolder.isEmpty()) newpath = searchFileRecursively(m_searchFolder, size, hash);
838                 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")));
839             } else {
840                 if (elem.attribute("type").toInt() == SLIDESHOW) {
841                     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")));
842                     if (res == KMessageBox::Yes)
843                         newpath = KFileDialog::getExistingDirectory(KUrl("kfiledialog:///clipfolder"), kapp->activeWindow(), i18n("Looking for %1", path));
844                     else {
845                         // Abort project loading
846                         action = res;
847                     }
848                 } else {
849                     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")));
850                     if (res == KMessageBox::Yes)
851                         newpath = KFileDialog::getOpenFileName(KUrl("kfiledialog:///clipfolder"), QString(), kapp->activeWindow(), i18n("Looking for %1", path));
852                     else {
853                         // Abort project loading
854                         action = res;
855                     }
856                 }
857             }
858             if (action == KMessageBox::Yes) {
859                 kDebug() << "// ASKED FOR SRCH CLIP: " << clipId;
860                 m_searchFolder = KFileDialog::getExistingDirectory(KUrl("kfiledialog:///clipfolder"), kapp->activeWindow());
861                 if (!m_searchFolder.isEmpty()) {
862                     newpath = searchFileRecursively(QDir(m_searchFolder), size, hash);
863                 }
864             } else if (action == KMessageBox::Cancel) {
865                 m_abortLoading = true;
866                 return;
867             } else if (action == KMessageBox::No) {
868                 // Keep clip as placeHolder
869                 elem.setAttribute("placeholder", '1');
870             }
871             if (!newpath.isEmpty()) {
872                 if (elem.attribute("type").toInt() == SLIDESHOW) newpath.append('/' + extension);
873                 elem.setAttribute("resource", newpath);
874                 setNewClipResource(clipId, newpath);
875                 setModified(true);
876             }
877         }
878         clip = new DocClipBase(m_clipManager, elem, producerId);
879         m_clipManager->addClip(clip);
880     }
881
882     if (createClipItem) {
883         emit addProjectClip(clip);
884         qApp->processEvents();
885         m_render->getFileProperties(clip->toXML(), clip->getId(), true);
886     }
887 }
888
889
890 void KdenliveDoc::setNewClipResource(const QString &id, const QString &path)
891 {
892     QDomNodeList prods = m_document.elementsByTagName("producer");
893     int maxprod = prods.count();
894     for (int i = 0; i < maxprod; i++) {
895         QDomNode m = prods.at(i);
896         QString prodId = m.toElement().attribute("id");
897         if (prodId == id || prodId.startsWith(id + '_')) {
898             QDomNodeList params = m.childNodes();
899             for (int j = 0; j < params.count(); j++) {
900                 QDomElement e = params.item(j).toElement();
901                 if (e.attribute("name") == "resource") {
902                     e.firstChild().setNodeValue(path);
903                     break;
904                 }
905             }
906         }
907     }
908 }
909
910 QString KdenliveDoc::searchFileRecursively(const QDir &dir, const QString &matchSize, const QString &matchHash) const
911 {
912     QString foundFileName;
913     QByteArray fileData;
914     QByteArray fileHash;
915     QStringList filesAndDirs = dir.entryList(QDir::Files | QDir::Readable);
916     for (int i = 0; i < filesAndDirs.size() && foundFileName.isEmpty(); i++) {
917         QFile file(dir.absoluteFilePath(filesAndDirs.at(i)));
918         if (file.open(QIODevice::ReadOnly)) {
919             if (QString::number(file.size()) == matchSize) {
920                 /*
921                 * 1 MB = 1 second per 450 files (or faster)
922                 * 10 MB = 9 seconds per 450 files (or faster)
923                 */
924                 if (file.size() > 1000000*2) {
925                     fileData = file.read(1000000);
926                     if (file.seek(file.size() - 1000000))
927                         fileData.append(file.readAll());
928                 } else
929                     fileData = file.readAll();
930                 file.close();
931                 fileHash = QCryptographicHash::hash(fileData, QCryptographicHash::Md5);
932                 if (QString(fileHash.toHex()) == matchHash)
933                     return file.fileName();
934             }
935         }
936         kDebug() << filesAndDirs.at(i) << file.size() << fileHash.toHex();
937     }
938     filesAndDirs = dir.entryList(QDir::Dirs | QDir::Readable | QDir::Executable | QDir::NoDotAndDotDot);
939     for (int i = 0; i < filesAndDirs.size() && foundFileName.isEmpty(); i++) {
940         foundFileName = searchFileRecursively(dir.absoluteFilePath(filesAndDirs.at(i)), matchSize, matchHash);
941         if (!foundFileName.isEmpty())
942             break;
943     }
944     return foundFileName;
945 }
946
947 void KdenliveDoc::addClipInfo(QDomElement elem, QDomElement orig, QString clipId)
948 {
949     DocClipBase *clip = m_clipManager->getClipById(clipId);
950     if (clip == NULL) {
951         addClip(elem, clipId, false);
952     } else {
953         QMap <QString, QString> properties;
954         QDomNamedNodeMap attributes = elem.attributes();
955         QString attrname;
956         for (int i = 0; i < attributes.count(); i++) {
957             attrname = attributes.item(i).nodeName();
958             if (attrname != "resource")
959                 properties.insert(attrname, attributes.item(i).nodeValue());
960             kDebug() << attrname << " = " << attributes.item(i).nodeValue();
961         }
962         clip->setProperties(properties);
963         emit addProjectClip(clip, false);
964     }
965     if (orig != QDomElement()) {
966         QMap<QString, QString> meta;
967         QDomNode m = orig.firstChild();
968         while (!m.isNull()) {
969             QString name = m.toElement().attribute("name");
970             if (name.startsWith("meta.attr")) {
971                 meta.insert(name.section('.', 2, 3), m.firstChild().nodeValue());
972             }
973             m = m.nextSibling();
974         }
975         if (!meta.isEmpty()) {
976             if (clip == NULL) clip = m_clipManager->getClipById(clipId);
977             if (clip) clip->setMetadata(meta);
978         }
979     }
980 }
981
982 void KdenliveDoc::deleteProjectClip(QList <QString> ids)
983 {
984     for (int i = 0; i < ids.size(); ++i) {
985         emit deleteTimelineClip(ids.at(i));
986         m_clipManager->slotDeleteClip(ids.at(i));
987     }
988     setModified(true);
989 }
990
991 void KdenliveDoc::deleteClip(const QString &clipId)
992 {
993     emit signalDeleteProjectClip(clipId);
994     m_clipManager->deleteClip(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