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