1 /***************************************************************************
2 * Copyright (C) 2007 by Jean-Baptiste Mardelle (jb@kdenlive.org) *
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. *
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. *
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 ***************************************************************************/
21 #include "kdenlivedoc.h"
22 #include "docclipbase.h"
23 #include "profilesdialog.h"
24 #include "kdenlivesettings.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 #include "initeffects.h"
35 #include <KStandardDirs>
36 #include <KMessageBox>
37 #include <KProgressDialog>
39 #include <KFileDialog>
40 #include <KIO/NetAccess>
41 #include <KIO/CopyJob>
42 #include <KApplication>
44 #include <KBookmarkManager>
46 #include <KStandardDirs>
48 #include <QCryptographicHash>
50 #include <QInputDialog>
51 #include <QDomImplementation>
53 #include <mlt++/Mlt.h>
55 const double DOCUMENTVERSION = 0.85;
57 KdenliveDoc::KdenliveDoc(const KUrl &url, const KUrl &projectFolder, QUndoGroup *undoGroup, QString profileName, const QPoint tracks, Render *render, KTextEdit *notes, MainWindow *parent, KProgressDialog *progressDialog) :
63 m_commandStack(new QUndoStack(undoGroup)),
65 m_projectFolder(projectFolder)
67 m_clipManager = new ClipManager(this);
68 m_autoSaveTimer = new QTimer(this);
69 m_autoSaveTimer->setSingleShot(true);
72 // init default document properties
73 m_documentProperties["zoom"] = "7";
74 m_documentProperties["verticalzoom"] = "1";
75 m_documentProperties["zonein"] = "0";
76 m_documentProperties["zoneout"] = "100";
80 success = KIO::NetAccess::download(url.path(), tmpFile, parent);
81 if (!success) // The file cannot be opened
82 KMessageBox::error(parent, KIO::NetAccess::lastErrorString());
86 QDomImplementation impl;
87 impl.setInvalidDataPolicy(QDomImplementation::DropInvalidChars);
88 success = m_document.setContent(&file, false, &errorMsg);
90 KIO::NetAccess::removeTempFile(tmpFile);
92 if (!success) // It is corrupted
93 KMessageBox::error(parent, errorMsg);
95 parent->slotGotProgressInfo(i18n("Validating"), 0);
96 qApp->processEvents();
97 DocumentValidator validator(m_document);
98 success = validator.isProject();
100 // It is not a project file
101 parent->slotGotProgressInfo(i18n("File %1 is not a Kdenlive project file", m_url.path()), 100);
104 * Validate the file against the current version (upgrade
105 * and recover it if needed). It is NOT a passive operation
107 // TODO: backup the document or alert the user?
108 success = validator.validate(DOCUMENTVERSION);
109 if (success) { // Let the validator handle error messages
110 parent->slotGotProgressInfo(i18n("Check missing clips"), 0);
111 qApp->processEvents();
112 QDomNodeList infoproducers = m_document.elementsByTagName("kdenlive_producer");
113 success = checkDocumentClips(infoproducers);
115 if (m_document.documentElement().attribute("modified") == "1") setModified(true);
116 parent->slotGotProgressInfo(i18n("Loading"), 0);
117 QDomElement mlt = m_document.firstChildElement("mlt");
118 QDomElement infoXml = mlt.firstChildElement("kdenlivedoc");
120 // Check embedded effects
121 QDomElement customeffects = infoXml.firstChildElement("customeffects");
122 if (!customeffects.isNull() && customeffects.hasChildNodes()) {
123 parent->slotGotProgressInfo(i18n("Importing project effects"), 0);
124 qApp->processEvents();
125 if (saveCustomEffects(customeffects.childNodes())) parent->slotReloadEffects();
130 QDomElement notesxml = infoXml.firstChildElement("documentnotes");
131 if (!notesxml.isNull()) m_notesWidget->setText(notesxml.firstChild().nodeValue());
134 QDomElement tracksinfo = infoXml.firstChildElement("tracksinfo");
135 if (!tracksinfo.isNull()) {
136 QDomNodeList trackslist = tracksinfo.childNodes();
137 int maxchild = trackslist.count();
138 for (int k = 0; k < maxchild; k++) {
139 e = trackslist.at(k).toElement();
140 if (e.tagName() == "trackinfo") {
141 TrackInfo projectTrack;
142 if (e.attribute("type") == "audio")
143 projectTrack.type = AUDIOTRACK;
145 projectTrack.type = VIDEOTRACK;
146 projectTrack.isMute = e.attribute("mute").toInt();
147 projectTrack.isBlind = e.attribute("blind").toInt();
148 projectTrack.isLocked = e.attribute("locked").toInt();
149 projectTrack.trackName = e.attribute("trackname");
150 m_tracksList.append(projectTrack);
153 mlt.removeChild(tracksinfo);
156 QDomNodeList folders = m_document.elementsByTagName("folder");
157 for (int i = 0; i < folders.count(); i++) {
158 e = folders.item(i).cloneNode().toElement();
159 m_clipManager->addFolder(e.attribute("id"), e.attribute("name"));
162 const int infomax = infoproducers.count();
163 QDomNodeList producers = m_document.elementsByTagName("producer");
164 const int max = producers.count();
166 if (!progressDialog) {
167 progressDialog = new KProgressDialog(parent, i18n("Loading project"), i18n("Adding clips"));
168 progressDialog->setAllowCancel(false);
170 progressDialog->setLabelText(i18n("Adding clips"));
172 progressDialog->progressBar()->setMaximum(infomax);
173 progressDialog->show();
174 qApp->processEvents();
176 for (int i = 0; i < infomax; i++) {
177 e = infoproducers.item(i).cloneNode().toElement();
178 QString prodId = e.attribute("id");
179 if (!e.isNull() && prodId != "black" && !prodId.startsWith("slowmotion")) {
180 e.setTagName("producer");
181 // Get MLT's original producer properties
183 for (int j = 0; j < max; j++) {
184 QDomNode o = producers.item(j);
185 QString origId = o.attributes().namedItem("id").nodeValue().section('_', 0, 0);
186 if (origId == prodId) {
187 orig = o.cloneNode().toElement();
192 if (!addClipInfo(e, orig, prodId)) {
193 // The user manually aborted the loading.
195 emit resetProjectList();
196 m_tracksList.clear();
197 m_clipManager->clear();
202 progressDialog->progressBar()->setValue(i);
206 QDomElement markers = infoXml.firstChildElement("markers");
207 if (!markers.isNull()) {
208 QDomNodeList markerslist = markers.childNodes();
209 int maxchild = markerslist.count();
210 for (int k = 0; k < maxchild; k++) {
211 e = markerslist.at(k).toElement();
212 if (e.tagName() == "marker")
213 m_clipManager->getClipById(e.attribute("id"))->addSnapMarker(GenTime(e.attribute("time").toDouble()), e.attribute("comment"));
215 infoXml.removeChild(markers);
218 m_projectFolder = KUrl(infoXml.attribute("projectfolder"));
219 QDomElement docproperties = infoXml.firstChildElement("documentproperties");
220 QDomNamedNodeMap props = docproperties.attributes();
221 for (int i = 0; i < props.count(); i++)
222 m_documentProperties.insert(props.item(i).nodeName(), props.item(i).nodeValue());
223 setProfilePath(infoXml.attribute("profile"));
224 if (validator.isModified()) setModified(true);
225 kDebug() << "Reading file: " << url.path() << ", found clips: " << producers.count();
234 // Something went wrong, or a new file was requested: create a new project
237 setProfilePath(profileName);
238 m_document = createEmptyDocument(tracks.x(), tracks.y());
241 // Set the video profile (empty == default)
242 KdenliveSettings::setCurrent_profile(profilePath());
244 // Ask to create the project directory if it does not exist
245 if (!QFile::exists(m_projectFolder.path())) {
246 int create = KMessageBox::questionYesNo(parent, i18n("Project directory %1 does not exist. Create it?", m_projectFolder.path()));
247 if (create == KMessageBox::Yes) {
248 QDir projectDir(m_projectFolder.path());
249 bool ok = projectDir.mkpath(m_projectFolder.path());
251 KMessageBox::sorry(parent, i18n("The directory %1, could not be created.\nPlease make sure you have the required permissions.", m_projectFolder.path()));
256 // Make sure the project folder is usable
257 if (m_projectFolder.isEmpty() || !KIO::NetAccess::exists(m_projectFolder.path(), KIO::NetAccess::DestinationSide, parent)) {
258 KMessageBox::information(parent, i18n("Document project folder is invalid, setting it to the default one: %1", KdenliveSettings::defaultprojectfolder()));
259 m_projectFolder = KUrl(KdenliveSettings::defaultprojectfolder());
262 // Make sure that the necessary folders exist
263 KStandardDirs::makeDir(m_projectFolder.path(KUrl::AddTrailingSlash) + "titles/");
264 KStandardDirs::makeDir(m_projectFolder.path(KUrl::AddTrailingSlash) + "thumbs/");
265 KStandardDirs::makeDir(m_projectFolder.path(KUrl::AddTrailingSlash) + "ladspa/");
267 updateProjectFolderPlacesEntry();
269 //kDebug() << "// SETTING SCENE LIST:\n\n" << m_document.toString();
270 connect(m_autoSaveTimer, SIGNAL(timeout()), this, SLOT(slotAutoSave()));
273 KdenliveDoc::~KdenliveDoc()
275 m_autoSaveTimer->stop();
276 delete m_commandStack;
277 kDebug() << "// DEL CLP MAN";
278 delete m_clipManager;
279 kDebug() << "// DEL CLP MAN done";
280 delete m_autoSaveTimer;
282 if (!m_autosave->fileName().isEmpty()) m_autosave->remove();
287 int KdenliveDoc::setSceneList()
289 m_render->resetProfile(KdenliveSettings::current_profile());
290 if (m_render->setSceneList(m_document.toString(), m_documentProperties.value("position").toInt()) == -1) {
291 // INVALID MLT Consumer, something is wrong
294 m_documentProperties.remove("position");
295 // m_document xml is now useless, clear it
300 QDomDocument KdenliveDoc::createEmptyDocument(int videotracks, int audiotracks)
302 m_tracksList.clear();
304 // Tracks are added «backwards», so we need to reverse the track numbering
305 // mbt 331: http://www.kdenlive.org/mantis/view.php?id=331
306 // Better default names for tracks: Audio 1 etc. instead of blank numbers
307 for (int i = 0; i < audiotracks; i++) {
308 TrackInfo audioTrack;
309 audioTrack.type = AUDIOTRACK;
310 audioTrack.isMute = false;
311 audioTrack.isBlind = true;
312 audioTrack.isLocked = false;
313 audioTrack.trackName = QString("Audio ") + QString::number(audiotracks - i);
314 audioTrack.duration = 0;
315 m_tracksList.append(audioTrack);
318 for (int i = 0; i < videotracks; i++) {
319 TrackInfo videoTrack;
320 videoTrack.type = VIDEOTRACK;
321 videoTrack.isMute = false;
322 videoTrack.isBlind = false;
323 videoTrack.isLocked = false;
324 videoTrack.trackName = QString("Video ") + QString::number(videotracks - i);
325 videoTrack.duration = 0;
326 m_tracksList.append(videoTrack);
328 return createEmptyDocument(m_tracksList);
331 QDomDocument KdenliveDoc::createEmptyDocument(QList <TrackInfo> tracks)
333 // Creating new document
335 QDomElement mlt = doc.createElement("mlt");
336 doc.appendChild(mlt);
339 // Create black producer
340 // For some unknown reason, we have to build the black producer here and not in renderer.cpp, otherwise
341 // the composite transitions with the black track are corrupted.
342 QDomElement blk = doc.createElement("producer");
343 blk.setAttribute("in", 0);
344 blk.setAttribute("out", 500);
345 blk.setAttribute("id", "black");
347 QDomElement property = doc.createElement("property");
348 property.setAttribute("name", "mlt_type");
349 QDomText value = doc.createTextNode("producer");
350 property.appendChild(value);
351 blk.appendChild(property);
353 property = doc.createElement("property");
354 property.setAttribute("name", "aspect_ratio");
355 value = doc.createTextNode(QString::number(0.0));
356 property.appendChild(value);
357 blk.appendChild(property);
359 property = doc.createElement("property");
360 property.setAttribute("name", "length");
361 value = doc.createTextNode(QString::number(15000));
362 property.appendChild(value);
363 blk.appendChild(property);
365 property = doc.createElement("property");
366 property.setAttribute("name", "eof");
367 value = doc.createTextNode("pause");
368 property.appendChild(value);
369 blk.appendChild(property);
371 property = doc.createElement("property");
372 property.setAttribute("name", "resource");
373 value = doc.createTextNode("black");
374 property.appendChild(value);
375 blk.appendChild(property);
377 property = doc.createElement("property");
378 property.setAttribute("name", "mlt_service");
379 value = doc.createTextNode("colour");
380 property.appendChild(value);
381 blk.appendChild(property);
383 mlt.appendChild(blk);
386 QDomElement tractor = doc.createElement("tractor");
387 tractor.setAttribute("id", "maintractor");
388 QDomElement multitrack = doc.createElement("multitrack");
389 QDomElement playlist = doc.createElement("playlist");
390 playlist.setAttribute("id", "black_track");
391 mlt.appendChild(playlist);
393 QDomElement blank0 = doc.createElement("entry");
394 blank0.setAttribute("in", "0");
395 blank0.setAttribute("out", "1");
396 blank0.setAttribute("producer", "black");
397 playlist.appendChild(blank0);
400 int total = tracks.count() + 1;
402 for (int i = 1; i < total; i++) {
403 QDomElement playlist = doc.createElement("playlist");
404 playlist.setAttribute("id", "playlist" + QString::number(i));
405 mlt.appendChild(playlist);
408 QDomElement track0 = doc.createElement("track");
409 track0.setAttribute("producer", "black_track");
410 tractor.appendChild(track0);
412 // create audio and video tracks
413 for (int i = 1; i < total; i++) {
414 QDomElement track = doc.createElement("track");
415 track.setAttribute("producer", "playlist" + QString::number(i));
416 if (tracks.at(i - 1).type == AUDIOTRACK) {
417 track.setAttribute("hide", "video");
418 } else if (tracks.at(i - 1).isBlind)
419 track.setAttribute("hide", "video");
420 if (tracks.at(i - 1).isMute)
421 track.setAttribute("hide", "audio");
422 tractor.appendChild(track);
425 for (int i = 2; i < total ; i++) {
426 QDomElement transition = doc.createElement("transition");
427 transition.setAttribute("always_active", "1");
429 QDomElement property = doc.createElement("property");
430 property.setAttribute("name", "a_track");
431 QDomText value = doc.createTextNode(QString::number(1));
432 property.appendChild(value);
433 transition.appendChild(property);
435 property = doc.createElement("property");
436 property.setAttribute("name", "b_track");
437 value = doc.createTextNode(QString::number(i));
438 property.appendChild(value);
439 transition.appendChild(property);
441 property = doc.createElement("property");
442 property.setAttribute("name", "mlt_service");
443 value = doc.createTextNode("mix");
444 property.appendChild(value);
445 transition.appendChild(property);
447 property = doc.createElement("property");
448 property.setAttribute("name", "combine");
449 value = doc.createTextNode("1");
450 property.appendChild(value);
451 transition.appendChild(property);
453 property = doc.createElement("property");
454 property.setAttribute("name", "internal_added");
455 value = doc.createTextNode("237");
456 property.appendChild(value);
457 transition.appendChild(property);
458 tractor.appendChild(transition);
460 mlt.appendChild(tractor);
465 void KdenliveDoc::syncGuides(QList <Guide *> guides)
468 QDomElement guideNode = m_guidesXml.createElement("guides");
469 m_guidesXml.appendChild(guideNode);
472 for (int i = 0; i < guides.count(); i++) {
473 e = m_guidesXml.createElement("guide");
474 e.setAttribute("time", guides.at(i)->position().ms() / 1000);
475 e.setAttribute("comment", guides.at(i)->label());
476 guideNode.appendChild(e);
479 emit guidesUpdated();
482 QDomElement KdenliveDoc::guidesXml() const
484 return m_guidesXml.documentElement();
487 void KdenliveDoc::slotAutoSave()
489 if (m_render && m_autosave) {
490 if (!m_autosave->isOpen() && !m_autosave->open(QIODevice::ReadWrite)) {
491 // show error: could not open the autosave file
492 kDebug() << "ERROR; CANNOT CREATE AUTOSAVE FILE";
494 kDebug() << "// AUTOSAVE FILE: " << m_autosave->fileName();
495 saveSceneList(m_autosave->fileName(), m_render->sceneList());
499 void KdenliveDoc::setZoom(int horizontal, int vertical)
501 m_documentProperties["zoom"] = QString::number(horizontal);
502 m_documentProperties["verticalzoom"] = QString::number(vertical);
505 QPoint KdenliveDoc::zoom() const
507 return QPoint(m_documentProperties.value("zoom").toInt(), m_documentProperties.value("verticalzoom").toInt());
510 void KdenliveDoc::setZone(int start, int end)
512 m_documentProperties["zonein"] = QString::number(start);
513 m_documentProperties["zoneout"] = QString::number(end);
516 QPoint KdenliveDoc::zone() const
518 return QPoint(m_documentProperties.value("zonein").toInt(), m_documentProperties.value("zoneout").toInt());
521 bool KdenliveDoc::saveSceneList(const QString &path, const QString &scene)
523 QDomDocument sceneList;
524 sceneList.setContent(scene, true);
525 QDomElement mlt = sceneList.firstChildElement("mlt");
526 if (mlt.isNull() || !mlt.hasChildNodes()) {
527 //Make sure we don't save if scenelist is corrupted
528 KMessageBox::error(kapp->activeWindow(), i18n("Cannot write to file %1, scene list is corrupted.", path));
532 QDomElement addedXml = sceneList.createElement("kdenlivedoc");
533 mlt.appendChild(addedXml);
535 // check if project contains custom effects to embed them in project file
536 QDomNodeList effects = mlt.elementsByTagName("filter");
537 int maxEffects = effects.count();
538 kDebug() << "// FOUD " << maxEffects << " EFFECTS+++++++++++++++++++++";
539 QMap <QString, QString> effectIds;
540 for (int i = 0; i < maxEffects; i++) {
541 QDomNode m = effects.at(i);
542 QDomNodeList params = m.childNodes();
545 for (int j = 0; j < params.count(); j++) {
546 QDomElement e = params.item(j).toElement();
547 if (e.attribute("name") == "kdenlive_id") {
548 id = e.firstChild().nodeValue();
550 if (e.attribute("name") == "tag") {
551 tag = e.firstChild().nodeValue();
553 if (!id.isEmpty() && !tag.isEmpty()) effectIds.insert(id, tag);
556 QDomDocument customeffects = initEffects::getUsedCustomEffects(effectIds);
557 addedXml.appendChild(sceneList.importNode(customeffects.documentElement(), true));
559 QDomElement markers = sceneList.createElement("markers");
560 addedXml.setAttribute("version", DOCUMENTVERSION);
561 addedXml.setAttribute("kdenliveversion", VERSION);
562 addedXml.setAttribute("profile", profilePath());
563 addedXml.setAttribute("projectfolder", m_projectFolder.path());
565 QDomElement docproperties = sceneList.createElement("documentproperties");
566 QMapIterator<QString, QString> i(m_documentProperties);
567 while (i.hasNext()) {
569 docproperties.setAttribute(i.key(), i.value());
571 docproperties.setAttribute("position", m_render->seekPosition().frames(m_fps));
572 addedXml.appendChild(docproperties);
574 QDomElement docnotes = sceneList.createElement("documentnotes");
575 QDomText value = sceneList.createTextNode(m_notesWidget->toPlainText());
576 docnotes.appendChild(value);
577 addedXml.appendChild(docnotes);
580 QDomElement profileinfo = sceneList.createElement("profileinfo");
581 profileinfo.setAttribute("description", m_profile.description);
582 profileinfo.setAttribute("frame_rate_num", m_profile.frame_rate_num);
583 profileinfo.setAttribute("frame_rate_den", m_profile.frame_rate_den);
584 profileinfo.setAttribute("width", m_profile.width);
585 profileinfo.setAttribute("height", m_profile.height);
586 profileinfo.setAttribute("progressive", m_profile.progressive);
587 profileinfo.setAttribute("sample_aspect_num", m_profile.sample_aspect_num);
588 profileinfo.setAttribute("sample_aspect_den", m_profile.sample_aspect_den);
589 profileinfo.setAttribute("display_aspect_num", m_profile.display_aspect_num);
590 profileinfo.setAttribute("display_aspect_den", m_profile.display_aspect_den);
591 addedXml.appendChild(profileinfo);
594 QDomElement tracksinfo = sceneList.createElement("tracksinfo");
595 foreach(const TrackInfo & info, m_tracksList) {
596 QDomElement trackinfo = sceneList.createElement("trackinfo");
597 if (info.type == AUDIOTRACK) trackinfo.setAttribute("type", "audio");
598 trackinfo.setAttribute("mute", info.isMute);
599 trackinfo.setAttribute("blind", info.isBlind);
600 trackinfo.setAttribute("locked", info.isLocked);
601 trackinfo.setAttribute("trackname", info.trackName);
602 tracksinfo.appendChild(trackinfo);
604 addedXml.appendChild(tracksinfo);
606 // save project folders
607 QMap <QString, QString> folderlist = m_clipManager->documentFolderList();
609 QMapIterator<QString, QString> f(folderlist);
610 while (f.hasNext()) {
612 QDomElement folder = sceneList.createElement("folder");
613 folder.setAttribute("id", f.key());
614 folder.setAttribute("name", f.value());
615 addedXml.appendChild(folder);
618 // Save project clips
620 QList <DocClipBase*> list = m_clipManager->documentClipList();
621 for (int i = 0; i < list.count(); i++) {
622 e = list.at(i)->toXML();
623 e.setTagName("kdenlive_producer");
624 addedXml.appendChild(sceneList.importNode(e, true));
625 QList < CommentedTime > marks = list.at(i)->commentedSnapMarkers();
626 for (int j = 0; j < marks.count(); j++) {
627 QDomElement marker = sceneList.createElement("marker");
628 marker.setAttribute("time", marks.at(j).time().ms() / 1000);
629 marker.setAttribute("comment", marks.at(j).comment());
630 marker.setAttribute("id", e.attribute("id"));
631 markers.appendChild(marker);
634 addedXml.appendChild(markers);
637 if (!m_guidesXml.isNull()) addedXml.appendChild(sceneList.importNode(m_guidesXml.documentElement(), true));
640 addedXml.appendChild(sceneList.importNode(m_clipManager->groupsXml(), true));
642 //wes.appendChild(doc.importNode(kdenliveData, true));
645 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
646 kWarning() << "////// ERROR writing to file: " << path;
647 KMessageBox::error(kapp->activeWindow(), i18n("Cannot write to file %1", path));
651 file.write(sceneList.toString().toUtf8());
652 if (file.error() != QFile::NoError) {
653 KMessageBox::error(kapp->activeWindow(), i18n("Cannot write to file %1", path));
661 ClipManager *KdenliveDoc::clipManager()
663 return m_clipManager;
666 KUrl KdenliveDoc::projectFolder() const
668 //if (m_projectFolder.isEmpty()) return KUrl(KStandardDirs::locateLocal("appdata", "/projects/"));
669 return m_projectFolder;
672 void KdenliveDoc::setProjectFolder(KUrl url)
674 if (url == m_projectFolder) return;
676 KStandardDirs::makeDir(url.path());
677 KStandardDirs::makeDir(url.path(KUrl::AddTrailingSlash) + "titles/");
678 KStandardDirs::makeDir(url.path(KUrl::AddTrailingSlash) + "thumbs/");
679 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);
680 m_projectFolder = url;
682 updateProjectFolderPlacesEntry();
685 void KdenliveDoc::moveProjectData(KUrl url)
687 QList <DocClipBase*> list = m_clipManager->documentClipList();
688 //TODO: Also move ladspa effects files
689 for (int i = 0; i < list.count(); i++) {
690 DocClipBase *clip = list.at(i);
691 if (clip->clipType() == TEXT) {
692 // the image for title clip must be moved
693 KUrl oldUrl = clip->fileURL();
694 KUrl newUrl = KUrl(url.path(KUrl::AddTrailingSlash) + "titles/" + oldUrl.fileName());
695 KIO::Job *job = KIO::copy(oldUrl, newUrl);
696 if (KIO::NetAccess::synchronousRun(job, 0)) clip->setProperty("resource", newUrl.path());
698 QString hash = clip->getClipHash();
699 KUrl oldVideoThumbUrl = KUrl(m_projectFolder.path(KUrl::AddTrailingSlash) + "thumbs/" + hash + ".png");
700 KUrl oldAudioThumbUrl = KUrl(m_projectFolder.path(KUrl::AddTrailingSlash) + "thumbs/" + hash + ".thumb");
701 if (KIO::NetAccess::exists(oldVideoThumbUrl, KIO::NetAccess::SourceSide, 0)) {
702 KUrl newUrl = KUrl(url.path(KUrl::AddTrailingSlash) + "thumbs/" + hash + ".png");
703 KIO::Job *job = KIO::copy(oldVideoThumbUrl, newUrl);
704 KIO::NetAccess::synchronousRun(job, 0);
706 if (KIO::NetAccess::exists(oldAudioThumbUrl, KIO::NetAccess::SourceSide, 0)) {
707 KUrl newUrl = KUrl(url.path(KUrl::AddTrailingSlash) + "thumbs/" + hash + ".thumb");
708 KIO::Job *job = KIO::copy(oldAudioThumbUrl, newUrl);
709 if (KIO::NetAccess::synchronousRun(job, 0)) clip->refreshThumbUrl();
714 const QString &KdenliveDoc::profilePath() const
716 return m_profile.path;
719 MltVideoProfile KdenliveDoc::mltProfile() const
724 bool KdenliveDoc::setProfilePath(QString path)
726 if (path.isEmpty()) path = KdenliveSettings::default_profile();
727 if (path.isEmpty()) path = "dv_pal";
728 m_profile = ProfilesDialog::getVideoProfile(path);
729 bool current_fps = m_fps;
730 if (m_profile.path.isEmpty()) {
731 // Profile not found, use embedded profile
732 QDomElement profileInfo = m_document.elementsByTagName("profileinfo").at(0).toElement();
733 if (profileInfo.isNull()) {
734 KMessageBox::information(kapp->activeWindow(), i18n("Project profile was not found, using default profile."), i18n("Missing Profile"));
735 m_profile = ProfilesDialog::getVideoProfile(KdenliveSettings::default_profile());
737 m_profile.description = profileInfo.attribute("description");
738 m_profile.frame_rate_num = profileInfo.attribute("frame_rate_num").toInt();
739 m_profile.frame_rate_den = profileInfo.attribute("frame_rate_den").toInt();
740 m_profile.width = profileInfo.attribute("width").toInt();
741 m_profile.height = profileInfo.attribute("height").toInt();
742 m_profile.progressive = profileInfo.attribute("progressive").toInt();
743 m_profile.sample_aspect_num = profileInfo.attribute("sample_aspect_num").toInt();
744 m_profile.sample_aspect_den = profileInfo.attribute("sample_aspect_den").toInt();
745 m_profile.display_aspect_num = profileInfo.attribute("display_aspect_num").toInt();
746 m_profile.display_aspect_den = profileInfo.attribute("display_aspect_den").toInt();
747 QString existing = ProfilesDialog::existingProfile(m_profile);
748 if (!existing.isEmpty()) {
749 m_profile = ProfilesDialog::getVideoProfile(existing);
750 KMessageBox::information(kapp->activeWindow(), i18n("Project profile not found, replacing with existing one: %1", m_profile.description), i18n("Missing Profile"));
752 QString newDesc = m_profile.description;
754 while (ok && (newDesc.isEmpty() || ProfilesDialog::existingProfileDescription(newDesc))) {
755 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);
758 // User canceled, use default profile
759 m_profile = ProfilesDialog::getVideoProfile(KdenliveSettings::default_profile());
761 if (newDesc != m_profile.description) {
762 // Profile description existed, was replaced by new one
763 m_profile.description = newDesc;
765 KMessageBox::information(kapp->activeWindow(), i18n("Project profile was not found, it will be added to your system now."), i18n("Missing Profile"));
767 ProfilesDialog::saveProfile(m_profile);
774 KdenliveSettings::setProject_display_ratio((double) m_profile.display_aspect_num / m_profile.display_aspect_den);
775 m_fps = (double) m_profile.frame_rate_num / m_profile.frame_rate_den;
776 KdenliveSettings::setProject_fps(m_fps);
777 m_width = m_profile.width;
778 m_height = m_profile.height;
779 kDebug() << "Kdenlive document, init timecode from path: " << path << ", " << m_fps;
780 m_timecode.setFormat(m_fps);
781 return (current_fps != m_fps);
784 double KdenliveDoc::dar() const
786 return (double) m_profile.display_aspect_num / m_profile.display_aspect_den;
789 void KdenliveDoc::setThumbsProgress(const QString &message, int progress)
791 emit progressInfo(message, progress);
794 QUndoStack *KdenliveDoc::commandStack()
796 return m_commandStack;
800 void KdenliveDoc::setRenderer(Render *render) {
801 if (m_render) return;
803 emit progressInfo(i18n("Loading playlist..."), 0);
804 //qApp->processEvents();
806 m_render->setSceneList(m_document.toString(), m_startPos);
807 kDebug() << "// SETTING SCENE LIST:\n\n" << m_document.toString();
810 emit progressInfo(QString(), -1);
813 void KdenliveDoc::checkProjectClips()
815 if (m_render == NULL) return;
816 m_clipManager->resetProducersList(m_render->producersList());
819 Render *KdenliveDoc::renderer()
824 void KdenliveDoc::updateClip(const QString id)
826 emit updateClipDisplay(id);
829 int KdenliveDoc::getFramePos(QString duration)
831 return m_timecode.getFrameCount(duration);
834 QString KdenliveDoc::producerName(const QString &id)
836 QString result = "unnamed";
837 QDomNodeList prods = producersList();
838 int ct = prods.count();
839 for (int i = 0; i < ct ; i++) {
840 QDomElement e = prods.item(i).toElement();
841 if (e.attribute("id") != "black" && e.attribute("id") == id) {
842 result = e.attribute("name");
843 if (result.isEmpty()) result = KUrl(e.attribute("resource")).fileName();
850 QDomDocument KdenliveDoc::toXml()
855 Timecode KdenliveDoc::timecode() const
860 QDomNodeList KdenliveDoc::producersList()
862 return m_document.elementsByTagName("producer");
865 double KdenliveDoc::projectDuration() const
868 return GenTime(m_render->getLength(), m_fps).ms() / 1000;
873 double KdenliveDoc::fps() const
878 int KdenliveDoc::width() const
883 int KdenliveDoc::height() const
888 KUrl KdenliveDoc::url() const
893 void KdenliveDoc::setUrl(KUrl url)
898 void KdenliveDoc::setModified(bool mod)
900 if (!m_url.isEmpty() && mod && KdenliveSettings::crashrecovery()) {
901 m_autoSaveTimer->start(3000);
903 if (mod == m_modified) return;
905 emit docModified(m_modified);
908 bool KdenliveDoc::isModified() const
913 const QString KdenliveDoc::description() const
916 return i18n("Untitled") + " / " + m_profile.description;
918 return m_url.fileName() + " / " + m_profile.description;
921 bool KdenliveDoc::addClip(QDomElement elem, QString clipId, bool createClipItem)
923 const QString producerId = clipId.section('_', 0, 0);
924 DocClipBase *clip = m_clipManager->getClipById(producerId);
927 elem.setAttribute("id", producerId);
928 QString path = elem.attribute("resource");
930 if (elem.attribute("type").toInt() == SLIDESHOW) {
931 extension = KUrl(path).fileName();
932 path = KUrl(path).directory();
935 if (path.isEmpty() == false && QFile::exists(path) == false && elem.attribute("type").toInt() != TEXT && !elem.hasAttribute("placeholder")) {
936 kDebug() << "// FOUND MISSING CLIP: " << path << ", TYPE: " << elem.attribute("type").toInt();
937 const QString size = elem.attribute("file_size");
938 const QString hash = elem.attribute("file_hash");
940 int action = KMessageBox::No;
941 if (!size.isEmpty() && !hash.isEmpty()) {
942 if (!m_searchFolder.isEmpty())
943 newpath = searchFileRecursively(m_searchFolder, size, hash);
945 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")));
947 if (elem.attribute("type").toInt() == SLIDESHOW) {
948 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")));
949 if (res == KMessageBox::Yes)
950 newpath = KFileDialog::getExistingDirectory(KUrl("kfiledialog:///clipfolder"), kapp->activeWindow(), i18n("Looking for %1", path));
952 // Abort project loading
956 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")));
957 if (res == KMessageBox::Yes)
958 newpath = KFileDialog::getOpenFileName(KUrl("kfiledialog:///clipfolder"), QString(), kapp->activeWindow(), i18n("Looking for %1", path));
960 // Abort project loading
965 if (action == KMessageBox::Yes) {
966 kDebug() << "// ASKED FOR SRCH CLIP: " << clipId;
967 m_searchFolder = KFileDialog::getExistingDirectory(KUrl("kfiledialog:///clipfolder"), kapp->activeWindow());
968 if (!m_searchFolder.isEmpty())
969 newpath = searchFileRecursively(QDir(m_searchFolder), size, hash);
970 } else if (action == KMessageBox::Cancel) {
972 } else if (action == KMessageBox::No) {
973 // Keep clip as placeHolder
974 elem.setAttribute("placeholder", '1');
976 if (!newpath.isEmpty()) {
977 if (elem.attribute("type").toInt() == SLIDESHOW)
978 newpath.append('/' + extension);
979 elem.setAttribute("resource", newpath);
980 setNewClipResource(clipId, newpath);
984 clip = new DocClipBase(m_clipManager, elem, producerId);
985 m_clipManager->addClip(clip);
988 if (createClipItem) {
989 emit addProjectClip(clip);
990 //qApp->processEvents();
996 void KdenliveDoc::setNewClipResource(const QString &id, const QString &path)
998 QDomNodeList prods = m_document.elementsByTagName("producer");
999 int maxprod = prods.count();
1000 for (int i = 0; i < maxprod; i++) {
1001 QDomNode m = prods.at(i);
1002 QString prodId = m.toElement().attribute("id");
1003 if (prodId == id || prodId.startsWith(id + '_')) {
1004 QDomNodeList params = m.childNodes();
1005 for (int j = 0; j < params.count(); j++) {
1006 QDomElement e = params.item(j).toElement();
1007 if (e.attribute("name") == "resource") {
1008 e.firstChild().setNodeValue(path);
1016 QString KdenliveDoc::searchFileRecursively(const QDir &dir, const QString &matchSize, const QString &matchHash) const
1018 QString foundFileName;
1019 QByteArray fileData;
1020 QByteArray fileHash;
1021 QStringList filesAndDirs = dir.entryList(QDir::Files | QDir::Readable);
1022 for (int i = 0; i < filesAndDirs.size() && foundFileName.isEmpty(); i++) {
1023 QFile file(dir.absoluteFilePath(filesAndDirs.at(i)));
1024 if (file.open(QIODevice::ReadOnly)) {
1025 if (QString::number(file.size()) == matchSize) {
1027 * 1 MB = 1 second per 450 files (or faster)
1028 * 10 MB = 9 seconds per 450 files (or faster)
1030 if (file.size() > 1000000 * 2) {
1031 fileData = file.read(1000000);
1032 if (file.seek(file.size() - 1000000))
1033 fileData.append(file.readAll());
1035 fileData = file.readAll();
1037 fileHash = QCryptographicHash::hash(fileData, QCryptographicHash::Md5);
1038 if (QString(fileHash.toHex()) == matchHash)
1039 return file.fileName();
1042 kDebug() << filesAndDirs.at(i) << file.size() << fileHash.toHex();
1044 filesAndDirs = dir.entryList(QDir::Dirs | QDir::Readable | QDir::Executable | QDir::NoDotAndDotDot);
1045 for (int i = 0; i < filesAndDirs.size() && foundFileName.isEmpty(); i++) {
1046 foundFileName = searchFileRecursively(dir.absoluteFilePath(filesAndDirs.at(i)), matchSize, matchHash);
1047 if (!foundFileName.isEmpty())
1050 return foundFileName;
1053 bool KdenliveDoc::addClipInfo(QDomElement elem, QDomElement orig, QString clipId)
1055 DocClipBase *clip = m_clipManager->getClipById(clipId);
1057 if (!addClip(elem, clipId, false))
1060 QMap <QString, QString> properties;
1061 QDomNamedNodeMap attributes = elem.attributes();
1062 for (int i = 0; i < attributes.count(); i++) {
1063 QString attrname = attributes.item(i).nodeName();
1064 if (attrname != "resource")
1065 properties.insert(attrname, attributes.item(i).nodeValue());
1066 kDebug() << attrname << " = " << attributes.item(i).nodeValue();
1068 clip->setProperties(properties);
1069 emit addProjectClip(clip, false);
1071 if (orig != QDomElement()) {
1072 QMap<QString, QString> meta;
1073 for (QDomNode m = orig.firstChild(); !m.isNull(); m = m.nextSibling()) {
1074 QString name = m.toElement().attribute("name");
1075 if (name.startsWith("meta.attr"))
1076 meta.insert(name.section('.', 2, 3), m.firstChild().nodeValue());
1078 if (!meta.isEmpty()) {
1080 clip = m_clipManager->getClipById(clipId);
1082 clip->setMetadata(meta);
1089 void KdenliveDoc::deleteClip(const QString &clipId)
1091 emit signalDeleteProjectClip(clipId);
1094 void KdenliveDoc::slotAddClipList(const KUrl::List urls, const QString group, const QString &groupId)
1096 m_clipManager->slotAddClipList(urls, group, groupId);
1097 //emit selectLastAddedClip(QString::number(m_clipManager->lastClipId()));
1102 void KdenliveDoc::slotAddClipFile(const KUrl url, const QString group, const QString &groupId)
1104 m_clipManager->slotAddClipFile(url, group, groupId);
1105 emit selectLastAddedClip(QString::number(m_clipManager->lastClipId()));
1109 const QString KdenliveDoc::getFreeClipId()
1111 return QString::number(m_clipManager->getFreeClipId());
1114 DocClipBase *KdenliveDoc::getBaseClip(const QString &clipId)
1116 return m_clipManager->getClipById(clipId);
1119 void KdenliveDoc::slotCreateXmlClip(const QString &name, const QDomElement xml, QString group, const QString &groupId)
1121 m_clipManager->slotAddXmlClipFile(name, xml, group, groupId);
1123 emit selectLastAddedClip(QString::number(m_clipManager->lastClipId()));
1126 void KdenliveDoc::slotCreateColorClip(const QString &name, const QString &color, const QString &duration, QString group, const QString &groupId)
1128 m_clipManager->slotAddColorClipFile(name, color, duration, group, groupId);
1130 emit selectLastAddedClip(QString::number(m_clipManager->lastClipId()));
1133 void KdenliveDoc::slotCreateSlideshowClipFile(const QString name, const QString path, int count, const QString duration,
1134 const bool loop, const bool crop, const bool fade,
1135 const QString &luma_duration, const QString &luma_file, const int softness,
1136 const QString &animation, QString group, const QString &groupId)
1138 m_clipManager->slotAddSlideshowClipFile(name, path, count, duration, loop,
1139 crop, fade, luma_duration,
1140 luma_file, softness,
1141 animation, group, groupId);
1143 emit selectLastAddedClip(QString::number(m_clipManager->lastClipId()));
1146 void KdenliveDoc::slotCreateTextClip(QString group, const QString &groupId, const QString &templatePath)
1148 QString titlesFolder = projectFolder().path(KUrl::AddTrailingSlash) + "titles/";
1149 KStandardDirs::makeDir(titlesFolder);
1150 TitleWidget *dia_ui = new TitleWidget(templatePath, m_timecode, titlesFolder, m_render, kapp->activeWindow());
1151 if (dia_ui->exec() == QDialog::Accepted) {
1152 m_clipManager->slotAddTextClipFile(i18n("Title clip"), dia_ui->outPoint(), dia_ui->xml().toString(), group, groupId);
1154 emit selectLastAddedClip(QString::number(m_clipManager->lastClipId()));
1159 void KdenliveDoc::slotCreateTextTemplateClip(QString group, const QString &groupId, KUrl path)
1161 QString titlesFolder = projectFolder().path(KUrl::AddTrailingSlash) + "titles/";
1162 if (path.isEmpty()) {
1163 path = KFileDialog::getOpenUrl(KUrl(titlesFolder), "application/x-kdenlivetitle", kapp->activeWindow(), i18n("Enter Template Path"));
1166 if (path.isEmpty()) return;
1168 //TODO: rewrite with new title system (just set resource)
1169 m_clipManager->slotAddTextTemplateClip(i18n("Template title clip"), path, group, groupId);
1171 emit selectLastAddedClip(QString::number(m_clipManager->lastClipId()));
1174 int KdenliveDoc::tracksCount() const
1176 return m_tracksList.count();
1179 TrackInfo KdenliveDoc::trackInfoAt(int ix) const
1181 if (ix < 0 || ix >= m_tracksList.count()) {
1182 kWarning() << "Track INFO outisde of range";
1185 return m_tracksList.at(ix);
1188 void KdenliveDoc::switchTrackAudio(int ix, bool hide)
1190 if (ix < 0 || ix >= m_tracksList.count()) {
1191 kWarning() << "SWITCH Track outisde of range";
1194 m_tracksList[ix].isMute = hide; // !m_tracksList.at(ix).isMute;
1197 void KdenliveDoc::switchTrackLock(int ix, bool lock)
1199 if (ix < 0 || ix >= m_tracksList.count()) {
1200 kWarning() << "Track Lock outisde of range";
1203 m_tracksList[ix].isLocked = lock;
1206 bool KdenliveDoc::isTrackLocked(int ix) const
1208 if (ix < 0 || ix >= m_tracksList.count()) {
1209 kWarning() << "Track Lock outisde of range";
1212 return m_tracksList.at(ix).isLocked;
1215 void KdenliveDoc::switchTrackVideo(int ix, bool hide)
1217 if (ix < 0 || ix >= m_tracksList.count()) {
1218 kWarning() << "SWITCH Track outisde of range";
1221 m_tracksList[ix].isBlind = hide; // !m_tracksList.at(ix).isBlind;
1224 int KdenliveDoc::trackDuration(int ix)
1226 return m_tracksList.at(ix).duration;
1229 void KdenliveDoc::setTrackDuration(int ix, int duration)
1231 m_tracksList[ix].duration = duration;
1234 void KdenliveDoc::insertTrack(int ix, TrackInfo type)
1236 if (ix == -1) m_tracksList << type;
1237 else m_tracksList.insert(ix, type);
1240 void KdenliveDoc::deleteTrack(int ix)
1242 if (ix < 0 || ix >= m_tracksList.count()) {
1243 kWarning() << "Delete Track outisde of range";
1246 m_tracksList.removeAt(ix);
1249 void KdenliveDoc::setTrackType(int ix, TrackInfo type)
1251 if (ix < 0 || ix >= m_tracksList.count()) {
1252 kWarning() << "SET Track Type outisde of range";
1255 m_tracksList[ix].type = type.type;
1256 m_tracksList[ix].isMute = type.isMute;
1257 m_tracksList[ix].isBlind = type.isBlind;
1258 m_tracksList[ix].isLocked = type.isLocked;
1259 m_tracksList[ix].trackName = type.trackName;
1262 const QList <TrackInfo> KdenliveDoc::tracksList() const
1264 return m_tracksList;
1267 QPoint KdenliveDoc::getTracksCount() const
1271 foreach(const TrackInfo & info, m_tracksList) {
1272 if (info.type == VIDEOTRACK) video++;
1275 return QPoint(video, audio);
1278 void KdenliveDoc::cachePixmap(const QString &fileId, const QPixmap &pix) const
1280 pix.save(m_projectFolder.path(KUrl::AddTrailingSlash) + "thumbs/" + fileId + ".png");
1283 QString KdenliveDoc::getLadspaFile() const
1286 QString counter = QString::number(ct).rightJustified(5, '0', false);
1287 while (QFile::exists(m_projectFolder.path(KUrl::AddTrailingSlash) + "ladspa/" + counter + ".ladspa")) {
1289 counter = QString::number(ct).rightJustified(5, '0', false);
1291 return m_projectFolder.path(KUrl::AddTrailingSlash) + "ladspa/" + counter + ".ladspa";
1294 bool KdenliveDoc::checkDocumentClips(QDomNodeList infoproducers)
1296 DocumentChecker d(infoproducers, m_document);
1297 return (d.hasMissingClips() == false);
1303 QList <QDomElement> missingClips;
1304 for (int i = 0; i < infoproducers.count(); i++) {
1305 e = infoproducers.item(i).toElement();
1306 clipType = e.attribute("type").toInt();
1307 if (clipType == COLOR) continue;
1308 if (clipType == TEXT) {
1309 //TODO: Check is clip template is missing (xmltemplate) or hash changed
1312 id = e.attribute("id");
1313 resource = e.attribute("resource");
1314 if (clipType == SLIDESHOW) resource = KUrl(resource).directory();
1315 if (!KIO::NetAccess::exists(KUrl(resource), KIO::NetAccess::SourceSide, 0)) {
1316 // Missing clip found
1317 missingClips.append(e);
1319 // Check if the clip has changed
1320 if (clipType != SLIDESHOW && e.hasAttribute("file_hash")) {
1321 if (e.attribute("file_hash") != DocClipBase::getHash(e.attribute("resource")))
1322 e.removeAttribute("file_hash");
1326 if (missingClips.isEmpty()) return true;
1327 DocumentChecker d(missingClips, m_document);
1328 return (d.exec() == QDialog::Accepted);*/
1331 void KdenliveDoc::setDocumentProperty(const QString &name, const QString &value)
1333 m_documentProperties[name] = value;
1336 const QString KdenliveDoc::getDocumentProperty(const QString &name) const
1338 return m_documentProperties.value(name);
1341 QMap <QString, QString> KdenliveDoc::getRenderProperties() const
1343 QMap <QString, QString> renderProperties;
1344 QMapIterator<QString, QString> i(m_documentProperties);
1345 while (i.hasNext()) {
1347 if (i.key().startsWith("render")) renderProperties.insert(i.key(), i.value());
1349 return renderProperties;
1352 void KdenliveDoc::addTrackEffect(int ix, QDomElement effect)
1354 if (ix < 0 || ix >= m_tracksList.count()) {
1355 kWarning() << "Add Track effect outisde of range";
1358 effect.setAttribute("kdenlive_ix", m_tracksList.at(ix).effectsList.count() + 1);
1360 // Init parameter value & keyframes if required
1361 QDomNodeList params = effect.elementsByTagName("parameter");
1362 for (int i = 0; i < params.count(); i++) {
1363 QDomElement e = params.item(i).toElement();
1365 // Check if this effect has a variable parameter
1366 if (e.attribute("default").startsWith('%')) {
1367 double evaluatedValue = ProfilesDialog::getStringEval(m_profile, e.attribute("default"));
1368 e.setAttribute("default", evaluatedValue);
1369 if (e.hasAttribute("value") && e.attribute("value").startsWith('%')) {
1370 e.setAttribute("value", evaluatedValue);
1374 if (!e.isNull() && (e.attribute("type") == "keyframe" || e.attribute("type") == "simplekeyframe")) {
1375 QString def = e.attribute("default");
1376 // Effect has a keyframe type parameter, we need to set the values
1377 if (e.attribute("keyframes").isEmpty()) {
1378 e.setAttribute("keyframes", "0:" + def + ';');
1379 kDebug() << "///// EFFECT KEYFRAMES INITED: " << e.attribute("keyframes");
1385 m_tracksList[ix].effectsList.append(effect);
1388 void KdenliveDoc::removeTrackEffect(int ix, QDomElement effect)
1390 if (ix < 0 || ix >= m_tracksList.count()) {
1391 kWarning() << "Remove Track effect outisde of range";
1395 QString toRemove = effect.attribute("kdenlive_ix");
1396 for (int i = 0; i < m_tracksList.at(ix).effectsList.count(); ++i) {
1397 index = m_tracksList.at(ix).effectsList.at(i).attribute("kdenlive_ix");
1398 if (toRemove == index) {
1399 m_tracksList[ix].effectsList.removeAt(i);
1401 } else if (index.toInt() > toRemove.toInt()) {
1402 m_tracksList[ix].effectsList.item(i).setAttribute("kdenlive_ix", index.toInt() - 1);
1407 void KdenliveDoc::setTrackEffect(int trackIndex, int effectIndex, QDomElement effect)
1409 if (trackIndex < 0 || trackIndex >= m_tracksList.count()) {
1410 kWarning() << "Set Track effect outisde of range";
1413 if (effectIndex < 0 || effectIndex > (m_tracksList.at(trackIndex).effectsList.count() - 1) || effect.isNull()) {
1414 kDebug() << "Invalid effect index: " << effectIndex;
1417 effect.setAttribute("kdenlive_ix", effectIndex + 1);
1418 m_tracksList[trackIndex].effectsList.replace(effectIndex, effect);
1421 const EffectsList KdenliveDoc::getTrackEffects(int ix)
1423 if (ix < 0 || ix >= m_tracksList.count()) {
1424 kWarning() << "Get Track effects outisde of range";
1425 return EffectsList();
1427 return m_tracksList.at(ix).effectsList;
1430 QDomElement KdenliveDoc::getTrackEffect(int trackIndex, int effectIndex) const
1432 if (trackIndex < 0 || trackIndex >= m_tracksList.count()) {
1433 kWarning() << "Get Track effect outisde of range";
1434 return QDomElement();
1436 EffectsList list = m_tracksList.at(trackIndex).effectsList;
1437 if (effectIndex > list.count() - 1 || effectIndex < 0 || list.at(effectIndex).isNull()) return QDomElement();
1438 return list.at(effectIndex).cloneNode().toElement();
1441 bool KdenliveDoc::saveCustomEffects(QDomNodeList customeffects)
1444 QStringList importedEffects;
1445 int maxchild = customeffects.count();
1446 for (int i = 0; i < maxchild; i++) {
1447 e = customeffects.at(i).toElement();
1448 QString id = e.attribute("id");
1449 QString tag = e.attribute("tag");
1450 if (!id.isEmpty()) {
1451 // Check if effect exists or save it
1452 if (MainWindow::customEffects.hasEffect(tag, id) == -1) {
1454 doc.appendChild(doc.importNode(e, true));
1455 QString path = KStandardDirs::locateLocal("appdata", "effects/", true);
1456 path += id + ".xml";
1457 if (!QFile::exists(path)) {
1458 importedEffects << id;
1460 if (file.open(QFile::WriteOnly | QFile::Truncate)) {
1461 QTextStream out(&file);
1462 out << doc.toString();
1468 if (!importedEffects.isEmpty()) KMessageBox::informationList(kapp->activeWindow(), i18n("The following effects were imported from the project:"), importedEffects);
1469 return (!importedEffects.isEmpty());
1472 void KdenliveDoc::updateProjectFolderPlacesEntry()
1475 * For similar and more code have a look at kfileplacesmodel.cpp and the included files:
1476 * http://websvn.kde.org/trunk/KDE/kdelibs/kfile/kfileplacesmodel.cpp?view=markup
1479 const QString file = KStandardDirs::locateLocal("data", "kfileplaces/bookmarks.xml");
1480 KBookmarkManager *bookmarkManager = KBookmarkManager::managerForFile(file, "kfilePlaces");
1481 KBookmarkGroup root = bookmarkManager->root();
1482 KBookmark bookmark = root.first();
1484 QString kdenliveName = KGlobal::mainComponent().componentName();
1485 KUrl documentLocation = m_projectFolder;
1487 bool exists = false;
1489 while (!bookmark.isNull()) {
1490 // UDI not empty indicates a device
1491 QString udi = bookmark.metaDataItem("UDI");
1492 QString appName = bookmark.metaDataItem("OnlyInApp");
1494 if (udi.isEmpty() && appName == kdenliveName && bookmark.text() == i18n("Project Folder")) {
1495 if (bookmark.url() != documentLocation) {
1496 bookmark.setUrl(documentLocation);
1497 bookmarkManager->emitChanged(root);
1503 bookmark = root.next(bookmark);
1506 // if entry does not exist yet (was not found), well, create it then
1508 bookmark = root.addBookmark(i18n("Project Folder"), documentLocation, "folder-favorites");
1509 // Make this user selectable ?
1510 bookmark.setMetaDataItem("OnlyInApp", kdenliveName);
1511 bookmarkManager->emitChanged(root);
1515 #include "kdenlivedoc.moc"