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