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