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