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 <QCryptographicHash>
46 #include <QInputDialog>
47 #include <QDomImplementation>
49 #include <mlt++/Mlt.h>
51 const double DOCUMENTVERSION = 0.85;
53 KdenliveDoc::KdenliveDoc(const KUrl &url, const KUrl &projectFolder, QUndoGroup *undoGroup, QString profileName, const QPoint tracks, Render *render, KTextEdit *notes, MainWindow *parent, KProgressDialog *progressDialog) :
59 m_commandStack(new QUndoStack(undoGroup)),
61 m_projectFolder(projectFolder)
63 m_clipManager = new ClipManager(this);
64 m_autoSaveTimer = new QTimer(this);
65 m_autoSaveTimer->setSingleShot(true);
68 // init default document properties
69 m_documentProperties["zoom"] = "7";
70 m_documentProperties["verticalzoom"] = "1";
71 m_documentProperties["zonein"] = "0";
72 m_documentProperties["zoneout"] = "100";
76 success = KIO::NetAccess::download(url.path(), tmpFile, parent);
77 if (!success) // The file cannot be opened
78 KMessageBox::error(parent, KIO::NetAccess::lastErrorString());
82 QDomImplementation impl;
83 impl.setInvalidDataPolicy(QDomImplementation::DropInvalidChars);
84 success = m_document.setContent(&file, false, &errorMsg);
86 KIO::NetAccess::removeTempFile(tmpFile);
88 if (!success) // It is corrupted
89 KMessageBox::error(parent, errorMsg);
91 parent->slotGotProgressInfo(i18n("Validating"), 0);
92 qApp->processEvents();
93 DocumentValidator validator(m_document);
94 success = validator.isProject();
96 // It is not a project file
97 parent->slotGotProgressInfo(i18n("File %1 is not a Kdenlive project file", m_url.path()), 100);
100 * Validate the file against the current version (upgrade
101 * and recover it if needed). It is NOT a passive operation
103 // TODO: backup the document or alert the user?
104 success = validator.validate(DOCUMENTVERSION);
105 if (success) { // Let the validator handle error messages
106 parent->slotGotProgressInfo(i18n("Check missing clips"), 0);
107 qApp->processEvents();
108 QDomNodeList infoproducers = m_document.elementsByTagName("kdenlive_producer");
109 success = checkDocumentClips(infoproducers);
111 parent->slotGotProgressInfo(i18n("Loading"), 0);
112 QDomElement mlt = m_document.firstChildElement("mlt");
113 QDomElement infoXml = mlt.firstChildElement("kdenlivedoc");
115 // Check embedded effects
116 QDomElement customeffects = infoXml.firstChildElement("customeffects");
117 if (!customeffects.isNull() && customeffects.hasChildNodes()) {
118 parent->slotGotProgressInfo(i18n("Importing project effects"), 0);
119 qApp->processEvents();
120 if (saveCustomEffects(customeffects.childNodes())) parent->slotReloadEffects();
125 QDomElement notesxml = infoXml.firstChildElement("documentnotes");
126 if (!notesxml.isNull()) m_notesWidget->setText(notesxml.firstChild().nodeValue());
129 QDomElement tracksinfo = infoXml.firstChildElement("tracksinfo");
130 if (!tracksinfo.isNull()) {
131 QDomNodeList trackslist = tracksinfo.childNodes();
132 int maxchild = trackslist.count();
133 for (int k = 0; k < maxchild; k++) {
134 e = trackslist.at(k).toElement();
135 if (e.tagName() == "trackinfo") {
136 TrackInfo projectTrack;
137 if (e.attribute("type") == "audio")
138 projectTrack.type = AUDIOTRACK;
140 projectTrack.type = VIDEOTRACK;
141 projectTrack.isMute = e.attribute("mute").toInt();
142 projectTrack.isBlind = e.attribute("blind").toInt();
143 projectTrack.isLocked = e.attribute("locked").toInt();
144 projectTrack.trackName = e.attribute("trackname");
145 m_tracksList.append(projectTrack);
148 mlt.removeChild(tracksinfo);
151 QDomNodeList folders = m_document.elementsByTagName("folder");
152 for (int i = 0; i < folders.count(); i++) {
153 e = folders.item(i).cloneNode().toElement();
154 m_clipManager->addFolder(e.attribute("id"), e.attribute("name"));
157 const int infomax = infoproducers.count();
158 QDomNodeList producers = m_document.elementsByTagName("producer");
159 const int max = producers.count();
161 if (!progressDialog) {
162 progressDialog = new KProgressDialog(parent, i18n("Loading project"), i18n("Adding clips"));
163 progressDialog->setAllowCancel(false);
165 progressDialog->setLabelText(i18n("Adding clips"));
167 progressDialog->progressBar()->setMaximum(infomax);
168 progressDialog->show();
169 qApp->processEvents();
171 for (int i = 0; i < infomax; i++) {
172 e = infoproducers.item(i).cloneNode().toElement();
173 QString prodId = e.attribute("id");
174 if (!e.isNull() && prodId != "black" && !prodId.startsWith("slowmotion")) {
175 e.setTagName("producer");
176 // Get MLT's original producer properties
178 for (int j = 0; j < max; j++) {
179 QDomNode o = producers.item(j);
180 QString origId = o.attributes().namedItem("id").nodeValue().section('_', 0, 0);
181 if (origId == prodId) {
182 orig = o.cloneNode().toElement();
187 if (!addClipInfo(e, orig, prodId)) {
188 // The user manually aborted the loading.
190 emit resetProjectList();
191 m_tracksList.clear();
192 m_clipManager->clear();
197 progressDialog->progressBar()->setValue(i);
201 QDomElement markers = infoXml.firstChildElement("markers");
202 if (!markers.isNull()) {
203 QDomNodeList markerslist = markers.childNodes();
204 int maxchild = markerslist.count();
205 for (int k = 0; k < maxchild; k++) {
206 e = markerslist.at(k).toElement();
207 if (e.tagName() == "marker")
208 m_clipManager->getClipById(e.attribute("id"))->addSnapMarker(GenTime(e.attribute("time").toDouble()), e.attribute("comment"));
210 infoXml.removeChild(markers);
213 m_projectFolder = KUrl(infoXml.attribute("projectfolder"));
214 QDomElement docproperties = infoXml.firstChildElement("documentproperties");
215 QDomNamedNodeMap props = docproperties.attributes();
216 for (int i = 0; i < props.count(); i++)
217 m_documentProperties.insert(props.item(i).nodeName(), props.item(i).nodeValue());
218 setProfilePath(infoXml.attribute("profile"));
219 setModified(validator.isModified());
220 kDebug() << "Reading file: " << url.path() << ", found clips: " << producers.count();
229 // Something went wrong, or a new file was requested: create a new project
232 setProfilePath(profileName);
233 m_document = createEmptyDocument(tracks.x(), tracks.y());
236 // Set the video profile (empty == default)
237 KdenliveSettings::setCurrent_profile(profilePath());
239 // Ask to create the project directory if it does not exist
240 if (!QFile::exists(m_projectFolder.path())) {
241 int create = KMessageBox::questionYesNo(parent, i18n("Project directory %1 does not exist. Create it?", m_projectFolder.path()));
242 if (create == KMessageBox::Yes) {
243 QDir projectDir(m_projectFolder.path());
244 bool ok = projectDir.mkpath(m_projectFolder.path());
246 KMessageBox::sorry(parent, i18n("The directory %1, could not be created.\nPlease make sure you have the required permissions.", m_projectFolder.path()));
251 // Make sure the project folder is usable
252 if (m_projectFolder.isEmpty() || !KIO::NetAccess::exists(m_projectFolder.path(), KIO::NetAccess::DestinationSide, parent)) {
253 KMessageBox::information(parent, i18n("Document project folder is invalid, setting it to the default one: %1", KdenliveSettings::defaultprojectfolder()));
254 m_projectFolder = KUrl(KdenliveSettings::defaultprojectfolder());
257 // Make sure that the necessary folders exist
258 KStandardDirs::makeDir(m_projectFolder.path(KUrl::AddTrailingSlash) + "titles/");
259 KStandardDirs::makeDir(m_projectFolder.path(KUrl::AddTrailingSlash) + "thumbs/");
260 KStandardDirs::makeDir(m_projectFolder.path(KUrl::AddTrailingSlash) + "ladspa/");
262 //kDebug() << "// SETTING SCENE LIST:\n\n" << m_document.toString();
263 connect(m_autoSaveTimer, SIGNAL(timeout()), this, SLOT(slotAutoSave()));
266 KdenliveDoc::~KdenliveDoc()
268 m_autoSaveTimer->stop();
269 delete m_commandStack;
270 kDebug() << "// DEL CLP MAN";
271 delete m_clipManager;
272 kDebug() << "// DEL CLP MAN done";
273 delete m_autoSaveTimer;
275 if (!m_autosave->fileName().isEmpty()) m_autosave->remove();
280 int KdenliveDoc::setSceneList()
282 m_render->resetProfile(KdenliveSettings::current_profile());
283 if (m_render->setSceneList(m_document.toString(), m_documentProperties.value("position").toInt()) == -1) {
284 // INVALID MLT Consumer, something is wrong
287 m_documentProperties.remove("position");
288 // m_document xml is now useless, clear it
293 QDomDocument KdenliveDoc::createEmptyDocument(int videotracks, int audiotracks)
295 m_tracksList.clear();
297 // Tracks are added «backwards», so we need to reverse the track numbering
298 // mbt 331: http://www.kdenlive.org/mantis/view.php?id=331
299 // Better default names for tracks: Audio 1 etc. instead of blank numbers
300 for (int i = 0; i < audiotracks; i++) {
301 TrackInfo audioTrack;
302 audioTrack.type = AUDIOTRACK;
303 audioTrack.isMute = false;
304 audioTrack.isBlind = true;
305 audioTrack.isLocked = false;
306 audioTrack.trackName = QString("Audio ") + QString::number(audiotracks - i);
307 m_tracksList.append(audioTrack);
310 for (int i = 0; i < videotracks; i++) {
311 TrackInfo videoTrack;
312 videoTrack.type = VIDEOTRACK;
313 videoTrack.isMute = false;
314 videoTrack.isBlind = false;
315 videoTrack.isLocked = false;
316 videoTrack.trackName = QString("Video ") + QString::number(videotracks - i);
317 m_tracksList.append(videoTrack);
319 return createEmptyDocument(m_tracksList);
322 QDomDocument KdenliveDoc::createEmptyDocument(QList <TrackInfo> tracks)
324 // Creating new document
326 QDomElement mlt = doc.createElement("mlt");
327 doc.appendChild(mlt);
330 // Create black producer
331 // For some unknown reason, we have to build the black producer here and not in renderer.cpp, otherwise
332 // the composite transitions with the black track are corrupted.
333 QDomElement blk = doc.createElement("producer");
334 blk.setAttribute("in", 0);
335 blk.setAttribute("out", 500);
336 blk.setAttribute("id", "black");
338 QDomElement property = doc.createElement("property");
339 property.setAttribute("name", "mlt_type");
340 QDomText value = doc.createTextNode("producer");
341 property.appendChild(value);
342 blk.appendChild(property);
344 property = doc.createElement("property");
345 property.setAttribute("name", "aspect_ratio");
346 value = doc.createTextNode(QString::number(0.0));
347 property.appendChild(value);
348 blk.appendChild(property);
350 property = doc.createElement("property");
351 property.setAttribute("name", "length");
352 value = doc.createTextNode(QString::number(15000));
353 property.appendChild(value);
354 blk.appendChild(property);
356 property = doc.createElement("property");
357 property.setAttribute("name", "eof");
358 value = doc.createTextNode("pause");
359 property.appendChild(value);
360 blk.appendChild(property);
362 property = doc.createElement("property");
363 property.setAttribute("name", "resource");
364 value = doc.createTextNode("black");
365 property.appendChild(value);
366 blk.appendChild(property);
368 property = doc.createElement("property");
369 property.setAttribute("name", "mlt_service");
370 value = doc.createTextNode("colour");
371 property.appendChild(value);
372 blk.appendChild(property);
374 mlt.appendChild(blk);
377 QDomElement tractor = doc.createElement("tractor");
378 tractor.setAttribute("id", "maintractor");
379 QDomElement multitrack = doc.createElement("multitrack");
380 QDomElement playlist = doc.createElement("playlist");
381 playlist.setAttribute("id", "black_track");
382 mlt.appendChild(playlist);
384 QDomElement blank0 = doc.createElement("entry");
385 blank0.setAttribute("in", "0");
386 blank0.setAttribute("out", "1");
387 blank0.setAttribute("producer", "black");
388 playlist.appendChild(blank0);
391 int total = tracks.count() + 1;
393 for (int i = 1; i < total; i++) {
394 QDomElement playlist = doc.createElement("playlist");
395 playlist.setAttribute("id", "playlist" + QString::number(i));
396 mlt.appendChild(playlist);
399 QDomElement track0 = doc.createElement("track");
400 track0.setAttribute("producer", "black_track");
401 tractor.appendChild(track0);
403 // create audio and video tracks
404 for (int i = 1; i < total; i++) {
405 QDomElement track = doc.createElement("track");
406 track.setAttribute("producer", "playlist" + QString::number(i));
407 if (tracks.at(i - 1).type == AUDIOTRACK) {
408 track.setAttribute("hide", "video");
409 } else if (tracks.at(i - 1).isBlind)
410 track.setAttribute("hide", "video");
411 if (tracks.at(i - 1).isMute)
412 track.setAttribute("hide", "audio");
413 tractor.appendChild(track);
416 for (int i = 2; i < total ; i++) {
417 QDomElement transition = doc.createElement("transition");
418 transition.setAttribute("always_active", "1");
420 QDomElement property = doc.createElement("property");
421 property.setAttribute("name", "a_track");
422 QDomText value = doc.createTextNode(QString::number(1));
423 property.appendChild(value);
424 transition.appendChild(property);
426 property = doc.createElement("property");
427 property.setAttribute("name", "b_track");
428 value = doc.createTextNode(QString::number(i));
429 property.appendChild(value);
430 transition.appendChild(property);
432 property = doc.createElement("property");
433 property.setAttribute("name", "mlt_service");
434 value = doc.createTextNode("mix");
435 property.appendChild(value);
436 transition.appendChild(property);
438 property = doc.createElement("property");
439 property.setAttribute("name", "combine");
440 value = doc.createTextNode("1");
441 property.appendChild(value);
442 transition.appendChild(property);
444 property = doc.createElement("property");
445 property.setAttribute("name", "internal_added");
446 value = doc.createTextNode("237");
447 property.appendChild(value);
448 transition.appendChild(property);
449 tractor.appendChild(transition);
451 mlt.appendChild(tractor);
456 void KdenliveDoc::syncGuides(QList <Guide *> guides)
459 QDomElement guideNode = m_guidesXml.createElement("guides");
460 m_guidesXml.appendChild(guideNode);
463 for (int i = 0; i < guides.count(); i++) {
464 e = m_guidesXml.createElement("guide");
465 e.setAttribute("time", guides.at(i)->position().ms() / 1000);
466 e.setAttribute("comment", guides.at(i)->label());
467 guideNode.appendChild(e);
470 emit guidesUpdated();
473 QDomElement KdenliveDoc::guidesXml() const
475 return m_guidesXml.documentElement();
478 void KdenliveDoc::slotAutoSave()
480 if (m_render && m_autosave) {
481 if (!m_autosave->isOpen() && !m_autosave->open(QIODevice::ReadWrite)) {
482 // show error: could not open the autosave file
483 kDebug() << "ERROR; CANNOT CREATE AUTOSAVE FILE";
485 kDebug() << "// AUTOSAVE FILE: " << m_autosave->fileName();
486 saveSceneList(m_autosave->fileName(), m_render->sceneList());
490 void KdenliveDoc::setZoom(int horizontal, int vertical)
492 m_documentProperties["zoom"] = QString::number(horizontal);
493 m_documentProperties["verticalzoom"] = QString::number(vertical);
496 QPoint KdenliveDoc::zoom() const
498 return QPoint(m_documentProperties.value("zoom").toInt(), m_documentProperties.value("verticalzoom").toInt());
501 void KdenliveDoc::setZone(int start, int end)
503 m_documentProperties["zonein"] = QString::number(start);
504 m_documentProperties["zoneout"] = QString::number(end);
507 QPoint KdenliveDoc::zone() const
509 return QPoint(m_documentProperties.value("zonein").toInt(), m_documentProperties.value("zoneout").toInt());
512 bool KdenliveDoc::saveSceneList(const QString &path, const QString &scene)
514 QDomDocument sceneList;
515 sceneList.setContent(scene, true);
516 QDomElement mlt = sceneList.firstChildElement("mlt");
517 if (mlt.isNull() || !mlt.hasChildNodes()) {
518 //Make sure we don't save if scenelist is corrupted
519 KMessageBox::error(kapp->activeWindow(), i18n("Cannot write to file %1, scene list is corrupted.", path));
523 QDomElement addedXml = sceneList.createElement("kdenlivedoc");
524 mlt.appendChild(addedXml);
526 // check if project contains custom effects to embed them in project file
527 QDomNodeList effects = mlt.elementsByTagName("filter");
528 int maxEffects = effects.count();
529 kDebug() << "// FOUD " << maxEffects << " EFFECTS+++++++++++++++++++++";
530 QMap <QString, QString> effectIds;
531 for (int i = 0; i < maxEffects; i++) {
532 QDomNode m = effects.at(i);
533 QDomNodeList params = m.childNodes();
536 for (int j = 0; j < params.count(); j++) {
537 QDomElement e = params.item(j).toElement();
538 if (e.attribute("name") == "kdenlive_id") {
539 id = e.firstChild().nodeValue();
541 if (e.attribute("name") == "tag") {
542 tag = e.firstChild().nodeValue();
544 if (!id.isEmpty() && !tag.isEmpty()) effectIds.insert(id, tag);
547 QDomDocument customeffects = initEffects::getUsedCustomEffects(effectIds);
548 addedXml.appendChild(sceneList.importNode(customeffects.documentElement(), true));
550 QDomElement markers = sceneList.createElement("markers");
551 addedXml.setAttribute("version", DOCUMENTVERSION);
552 addedXml.setAttribute("kdenliveversion", VERSION);
553 addedXml.setAttribute("profile", profilePath());
554 addedXml.setAttribute("projectfolder", m_projectFolder.path());
556 QDomElement docproperties = sceneList.createElement("documentproperties");
557 QMapIterator<QString, QString> i(m_documentProperties);
558 while (i.hasNext()) {
560 docproperties.setAttribute(i.key(), i.value());
562 docproperties.setAttribute("position", m_render->seekPosition().frames(m_fps));
563 addedXml.appendChild(docproperties);
565 QDomElement docnotes = sceneList.createElement("documentnotes");
566 QDomText value = sceneList.createTextNode(m_notesWidget->toPlainText());
567 docnotes.appendChild(value);
568 addedXml.appendChild(docnotes);
571 QDomElement profileinfo = sceneList.createElement("profileinfo");
572 profileinfo.setAttribute("description", m_profile.description);
573 profileinfo.setAttribute("frame_rate_num", m_profile.frame_rate_num);
574 profileinfo.setAttribute("frame_rate_den", m_profile.frame_rate_den);
575 profileinfo.setAttribute("width", m_profile.width);
576 profileinfo.setAttribute("height", m_profile.height);
577 profileinfo.setAttribute("progressive", m_profile.progressive);
578 profileinfo.setAttribute("sample_aspect_num", m_profile.sample_aspect_num);
579 profileinfo.setAttribute("sample_aspect_den", m_profile.sample_aspect_den);
580 profileinfo.setAttribute("display_aspect_num", m_profile.display_aspect_num);
581 profileinfo.setAttribute("display_aspect_den", m_profile.display_aspect_den);
582 addedXml.appendChild(profileinfo);
585 QDomElement tracksinfo = sceneList.createElement("tracksinfo");
586 foreach(const TrackInfo & info, m_tracksList) {
587 QDomElement trackinfo = sceneList.createElement("trackinfo");
588 if (info.type == AUDIOTRACK) trackinfo.setAttribute("type", "audio");
589 trackinfo.setAttribute("mute", info.isMute);
590 trackinfo.setAttribute("blind", info.isBlind);
591 trackinfo.setAttribute("locked", info.isLocked);
592 trackinfo.setAttribute("trackname", info.trackName);
593 tracksinfo.appendChild(trackinfo);
595 addedXml.appendChild(tracksinfo);
597 // save project folders
598 QMap <QString, QString> folderlist = m_clipManager->documentFolderList();
600 QMapIterator<QString, QString> f(folderlist);
601 while (f.hasNext()) {
603 QDomElement folder = sceneList.createElement("folder");
604 folder.setAttribute("id", f.key());
605 folder.setAttribute("name", f.value());
606 addedXml.appendChild(folder);
609 // Save project clips
611 QList <DocClipBase*> list = m_clipManager->documentClipList();
612 for (int i = 0; i < list.count(); i++) {
613 e = list.at(i)->toXML();
614 e.setTagName("kdenlive_producer");
615 addedXml.appendChild(sceneList.importNode(e, true));
616 QList < CommentedTime > marks = list.at(i)->commentedSnapMarkers();
617 for (int j = 0; j < marks.count(); j++) {
618 QDomElement marker = sceneList.createElement("marker");
619 marker.setAttribute("time", marks.at(j).time().ms() / 1000);
620 marker.setAttribute("comment", marks.at(j).comment());
621 marker.setAttribute("id", e.attribute("id"));
622 markers.appendChild(marker);
625 addedXml.appendChild(markers);
628 if (!m_guidesXml.isNull()) addedXml.appendChild(sceneList.importNode(m_guidesXml.documentElement(), true));
631 addedXml.appendChild(sceneList.importNode(m_clipManager->groupsXml(), true));
633 //wes.appendChild(doc.importNode(kdenliveData, true));
636 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
637 kWarning() << "////// ERROR writing to file: " << path;
638 KMessageBox::error(kapp->activeWindow(), i18n("Cannot write to file %1", path));
642 file.write(sceneList.toString().toUtf8());
643 if (file.error() != QFile::NoError) {
644 KMessageBox::error(kapp->activeWindow(), i18n("Cannot write to file %1", path));
652 ClipManager *KdenliveDoc::clipManager()
654 return m_clipManager;
657 KUrl KdenliveDoc::projectFolder() const
659 //if (m_projectFolder.isEmpty()) return KUrl(KStandardDirs::locateLocal("appdata", "/projects/"));
660 return m_projectFolder;
663 void KdenliveDoc::setProjectFolder(KUrl url)
665 if (url == m_projectFolder) return;
667 KStandardDirs::makeDir(url.path());
668 KStandardDirs::makeDir(url.path(KUrl::AddTrailingSlash) + "titles/");
669 KStandardDirs::makeDir(url.path(KUrl::AddTrailingSlash) + "thumbs/");
670 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);
671 m_projectFolder = url;
674 void KdenliveDoc::moveProjectData(KUrl url)
676 QList <DocClipBase*> list = m_clipManager->documentClipList();
677 //TODO: Also move ladspa effects files
678 for (int i = 0; i < list.count(); i++) {
679 DocClipBase *clip = list.at(i);
680 if (clip->clipType() == TEXT) {
681 // the image for title clip must be moved
682 KUrl oldUrl = clip->fileURL();
683 KUrl newUrl = KUrl(url.path(KUrl::AddTrailingSlash) + "titles/" + oldUrl.fileName());
684 KIO::Job *job = KIO::copy(oldUrl, newUrl);
685 if (KIO::NetAccess::synchronousRun(job, 0)) clip->setProperty("resource", newUrl.path());
687 QString hash = clip->getClipHash();
688 KUrl oldVideoThumbUrl = KUrl(m_projectFolder.path(KUrl::AddTrailingSlash) + "thumbs/" + hash + ".png");
689 KUrl oldAudioThumbUrl = KUrl(m_projectFolder.path(KUrl::AddTrailingSlash) + "thumbs/" + hash + ".thumb");
690 if (KIO::NetAccess::exists(oldVideoThumbUrl, KIO::NetAccess::SourceSide, 0)) {
691 KUrl newUrl = KUrl(url.path(KUrl::AddTrailingSlash) + "thumbs/" + hash + ".png");
692 KIO::Job *job = KIO::copy(oldVideoThumbUrl, newUrl);
693 KIO::NetAccess::synchronousRun(job, 0);
695 if (KIO::NetAccess::exists(oldAudioThumbUrl, KIO::NetAccess::SourceSide, 0)) {
696 KUrl newUrl = KUrl(url.path(KUrl::AddTrailingSlash) + "thumbs/" + hash + ".thumb");
697 KIO::Job *job = KIO::copy(oldAudioThumbUrl, newUrl);
698 if (KIO::NetAccess::synchronousRun(job, 0)) clip->refreshThumbUrl();
703 const QString &KdenliveDoc::profilePath() const
705 return m_profile.path;
708 MltVideoProfile KdenliveDoc::mltProfile() const
713 bool KdenliveDoc::setProfilePath(QString path)
715 if (path.isEmpty()) path = KdenliveSettings::default_profile();
716 if (path.isEmpty()) path = "dv_pal";
717 m_profile = ProfilesDialog::getVideoProfile(path);
718 bool current_fps = m_fps;
719 if (m_profile.path.isEmpty()) {
720 // Profile not found, use embedded profile
721 QDomElement profileInfo = m_document.elementsByTagName("profileinfo").at(0).toElement();
722 if (profileInfo.isNull()) {
723 KMessageBox::information(kapp->activeWindow(), i18n("Project profile was not found, using default profile."), i18n("Missing Profile"));
724 m_profile = ProfilesDialog::getVideoProfile(KdenliveSettings::default_profile());
726 m_profile.description = profileInfo.attribute("description");
727 m_profile.frame_rate_num = profileInfo.attribute("frame_rate_num").toInt();
728 m_profile.frame_rate_den = profileInfo.attribute("frame_rate_den").toInt();
729 m_profile.width = profileInfo.attribute("width").toInt();
730 m_profile.height = profileInfo.attribute("height").toInt();
731 m_profile.progressive = profileInfo.attribute("progressive").toInt();
732 m_profile.sample_aspect_num = profileInfo.attribute("sample_aspect_num").toInt();
733 m_profile.sample_aspect_den = profileInfo.attribute("sample_aspect_den").toInt();
734 m_profile.display_aspect_num = profileInfo.attribute("display_aspect_num").toInt();
735 m_profile.display_aspect_den = profileInfo.attribute("display_aspect_den").toInt();
736 QString existing = ProfilesDialog::existingProfile(m_profile);
737 if (!existing.isEmpty()) {
738 m_profile = ProfilesDialog::getVideoProfile(existing);
739 KMessageBox::information(kapp->activeWindow(), i18n("Project profile not found, replacing with existing one: %1", m_profile.description), i18n("Missing Profile"));
741 QString newDesc = m_profile.description;
743 while (ok && (newDesc.isEmpty() || ProfilesDialog::existingProfileDescription(newDesc))) {
744 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);
747 // User canceled, use default profile
748 m_profile = ProfilesDialog::getVideoProfile(KdenliveSettings::default_profile());
750 if (newDesc != m_profile.description) {
751 // Profile description existed, was replaced by new one
752 m_profile.description = newDesc;
754 KMessageBox::information(kapp->activeWindow(), i18n("Project profile was not found, it will be added to your system now."), i18n("Missing Profile"));
756 ProfilesDialog::saveProfile(m_profile);
763 KdenliveSettings::setProject_display_ratio((double) m_profile.display_aspect_num / m_profile.display_aspect_den);
764 m_fps = (double) m_profile.frame_rate_num / m_profile.frame_rate_den;
765 KdenliveSettings::setProject_fps(m_fps);
766 m_width = m_profile.width;
767 m_height = m_profile.height;
768 kDebug() << "Kdenlive document, init timecode from path: " << path << ", " << m_fps;
769 m_timecode.setFormat(m_fps);
770 return (current_fps != m_fps);
773 double KdenliveDoc::dar() const
775 return (double) m_profile.display_aspect_num / m_profile.display_aspect_den;
778 void KdenliveDoc::setThumbsProgress(const QString &message, int progress)
780 emit progressInfo(message, progress);
783 QUndoStack *KdenliveDoc::commandStack()
785 return m_commandStack;
789 void KdenliveDoc::setRenderer(Render *render) {
790 if (m_render) return;
792 emit progressInfo(i18n("Loading playlist..."), 0);
793 //qApp->processEvents();
795 m_render->setSceneList(m_document.toString(), m_startPos);
796 kDebug() << "// SETTING SCENE LIST:\n\n" << m_document.toString();
799 emit progressInfo(QString(), -1);
802 void KdenliveDoc::checkProjectClips()
804 if (m_render == NULL) return;
805 m_clipManager->resetProducersList(m_render->producersList());
808 Render *KdenliveDoc::renderer()
813 void KdenliveDoc::updateClip(const QString id)
815 emit updateClipDisplay(id);
818 int KdenliveDoc::getFramePos(QString duration)
820 return m_timecode.getFrameCount(duration);
823 QString KdenliveDoc::producerName(const QString &id)
825 QString result = "unnamed";
826 QDomNodeList prods = producersList();
827 int ct = prods.count();
828 for (int i = 0; i < ct ; i++) {
829 QDomElement e = prods.item(i).toElement();
830 if (e.attribute("id") != "black" && e.attribute("id") == id) {
831 result = e.attribute("name");
832 if (result.isEmpty()) result = KUrl(e.attribute("resource")).fileName();
839 QDomDocument KdenliveDoc::toXml()
844 Timecode KdenliveDoc::timecode() const
849 QDomNodeList KdenliveDoc::producersList()
851 return m_document.elementsByTagName("producer");
854 double KdenliveDoc::projectDuration() const
857 return GenTime(m_render->getLength(), m_fps).ms() / 1000;
862 double KdenliveDoc::fps() const
867 int KdenliveDoc::width() const
872 int KdenliveDoc::height() const
877 KUrl KdenliveDoc::url() const
882 void KdenliveDoc::setUrl(KUrl url)
887 void KdenliveDoc::setModified(bool mod)
889 if (!m_url.isEmpty() && mod && KdenliveSettings::crashrecovery()) {
890 m_autoSaveTimer->start(3000);
892 if (mod == m_modified) return;
894 emit docModified(m_modified);
897 bool KdenliveDoc::isModified() const
902 const QString KdenliveDoc::description() const
905 return i18n("Untitled") + " / " + m_profile.description;
907 return m_url.fileName() + " / " + m_profile.description;
910 bool KdenliveDoc::addClip(QDomElement elem, QString clipId, bool createClipItem)
912 const QString producerId = clipId.section('_', 0, 0);
913 DocClipBase *clip = m_clipManager->getClipById(producerId);
916 elem.setAttribute("id", producerId);
917 QString path = elem.attribute("resource");
919 if (elem.attribute("type").toInt() == SLIDESHOW) {
920 extension = KUrl(path).fileName();
921 path = KUrl(path).directory();
924 if (path.isEmpty() == false && QFile::exists(path) == false && elem.attribute("type").toInt() != TEXT && !elem.hasAttribute("placeholder")) {
925 kDebug() << "// FOUND MISSING CLIP: " << path << ", TYPE: " << elem.attribute("type").toInt();
926 const QString size = elem.attribute("file_size");
927 const QString hash = elem.attribute("file_hash");
929 int action = KMessageBox::No;
930 if (!size.isEmpty() && !hash.isEmpty()) {
931 if (!m_searchFolder.isEmpty())
932 newpath = searchFileRecursively(m_searchFolder, size, hash);
934 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")));
936 if (elem.attribute("type").toInt() == SLIDESHOW) {
937 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")));
938 if (res == KMessageBox::Yes)
939 newpath = KFileDialog::getExistingDirectory(KUrl("kfiledialog:///clipfolder"), kapp->activeWindow(), i18n("Looking for %1", path));
941 // Abort project loading
945 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")));
946 if (res == KMessageBox::Yes)
947 newpath = KFileDialog::getOpenFileName(KUrl("kfiledialog:///clipfolder"), QString(), kapp->activeWindow(), i18n("Looking for %1", path));
949 // Abort project loading
954 if (action == KMessageBox::Yes) {
955 kDebug() << "// ASKED FOR SRCH CLIP: " << clipId;
956 m_searchFolder = KFileDialog::getExistingDirectory(KUrl("kfiledialog:///clipfolder"), kapp->activeWindow());
957 if (!m_searchFolder.isEmpty())
958 newpath = searchFileRecursively(QDir(m_searchFolder), size, hash);
959 } else if (action == KMessageBox::Cancel) {
961 } else if (action == KMessageBox::No) {
962 // Keep clip as placeHolder
963 elem.setAttribute("placeholder", '1');
965 if (!newpath.isEmpty()) {
966 if (elem.attribute("type").toInt() == SLIDESHOW)
967 newpath.append('/' + extension);
968 elem.setAttribute("resource", newpath);
969 setNewClipResource(clipId, newpath);
973 clip = new DocClipBase(m_clipManager, elem, producerId);
974 m_clipManager->addClip(clip);
977 if (createClipItem) {
978 emit addProjectClip(clip);
979 //qApp->processEvents();
985 void KdenliveDoc::setNewClipResource(const QString &id, const QString &path)
987 QDomNodeList prods = m_document.elementsByTagName("producer");
988 int maxprod = prods.count();
989 for (int i = 0; i < maxprod; i++) {
990 QDomNode m = prods.at(i);
991 QString prodId = m.toElement().attribute("id");
992 if (prodId == id || prodId.startsWith(id + '_')) {
993 QDomNodeList params = m.childNodes();
994 for (int j = 0; j < params.count(); j++) {
995 QDomElement e = params.item(j).toElement();
996 if (e.attribute("name") == "resource") {
997 e.firstChild().setNodeValue(path);
1005 QString KdenliveDoc::searchFileRecursively(const QDir &dir, const QString &matchSize, const QString &matchHash) const
1007 QString foundFileName;
1008 QByteArray fileData;
1009 QByteArray fileHash;
1010 QStringList filesAndDirs = dir.entryList(QDir::Files | QDir::Readable);
1011 for (int i = 0; i < filesAndDirs.size() && foundFileName.isEmpty(); i++) {
1012 QFile file(dir.absoluteFilePath(filesAndDirs.at(i)));
1013 if (file.open(QIODevice::ReadOnly)) {
1014 if (QString::number(file.size()) == matchSize) {
1016 * 1 MB = 1 second per 450 files (or faster)
1017 * 10 MB = 9 seconds per 450 files (or faster)
1019 if (file.size() > 1000000 * 2) {
1020 fileData = file.read(1000000);
1021 if (file.seek(file.size() - 1000000))
1022 fileData.append(file.readAll());
1024 fileData = file.readAll();
1026 fileHash = QCryptographicHash::hash(fileData, QCryptographicHash::Md5);
1027 if (QString(fileHash.toHex()) == matchHash)
1028 return file.fileName();
1031 kDebug() << filesAndDirs.at(i) << file.size() << fileHash.toHex();
1033 filesAndDirs = dir.entryList(QDir::Dirs | QDir::Readable | QDir::Executable | QDir::NoDotAndDotDot);
1034 for (int i = 0; i < filesAndDirs.size() && foundFileName.isEmpty(); i++) {
1035 foundFileName = searchFileRecursively(dir.absoluteFilePath(filesAndDirs.at(i)), matchSize, matchHash);
1036 if (!foundFileName.isEmpty())
1039 return foundFileName;
1042 bool KdenliveDoc::addClipInfo(QDomElement elem, QDomElement orig, QString clipId)
1044 DocClipBase *clip = m_clipManager->getClipById(clipId);
1046 if (!addClip(elem, clipId, false))
1049 QMap <QString, QString> properties;
1050 QDomNamedNodeMap attributes = elem.attributes();
1051 for (int i = 0; i < attributes.count(); i++) {
1052 QString attrname = attributes.item(i).nodeName();
1053 if (attrname != "resource")
1054 properties.insert(attrname, attributes.item(i).nodeValue());
1055 kDebug() << attrname << " = " << attributes.item(i).nodeValue();
1057 clip->setProperties(properties);
1058 emit addProjectClip(clip, false);
1060 if (orig != QDomElement()) {
1061 QMap<QString, QString> meta;
1062 for (QDomNode m = orig.firstChild(); !m.isNull(); m = m.nextSibling()) {
1063 QString name = m.toElement().attribute("name");
1064 if (name.startsWith("meta.attr"))
1065 meta.insert(name.section('.', 2, 3), m.firstChild().nodeValue());
1067 if (!meta.isEmpty()) {
1069 clip = m_clipManager->getClipById(clipId);
1071 clip->setMetadata(meta);
1078 void KdenliveDoc::deleteClip(const QString &clipId)
1080 emit signalDeleteProjectClip(clipId);
1083 void KdenliveDoc::slotAddClipList(const KUrl::List urls, const QString group, const QString &groupId)
1085 m_clipManager->slotAddClipList(urls, group, groupId);
1086 //emit selectLastAddedClip(QString::number(m_clipManager->lastClipId()));
1091 void KdenliveDoc::slotAddClipFile(const KUrl url, const QString group, const QString &groupId)
1093 m_clipManager->slotAddClipFile(url, group, groupId);
1094 emit selectLastAddedClip(QString::number(m_clipManager->lastClipId()));
1098 const QString KdenliveDoc::getFreeClipId()
1100 return QString::number(m_clipManager->getFreeClipId());
1103 DocClipBase *KdenliveDoc::getBaseClip(const QString &clipId)
1105 return m_clipManager->getClipById(clipId);
1108 void KdenliveDoc::slotCreateXmlClip(const QString &name, const QDomElement xml, QString group, const QString &groupId)
1110 m_clipManager->slotAddXmlClipFile(name, xml, group, groupId);
1112 emit selectLastAddedClip(QString::number(m_clipManager->lastClipId()));
1115 void KdenliveDoc::slotCreateColorClip(const QString &name, const QString &color, const QString &duration, QString group, const QString &groupId)
1117 m_clipManager->slotAddColorClipFile(name, color, duration, group, groupId);
1119 emit selectLastAddedClip(QString::number(m_clipManager->lastClipId()));
1122 void KdenliveDoc::slotCreateSlideshowClipFile(const QString name, const QString path, int count, const QString duration,
1123 const bool loop, const bool crop, const bool fade,
1124 const QString &luma_duration, const QString &luma_file, const int softness,
1125 const QString &animation, QString group, const QString &groupId)
1127 m_clipManager->slotAddSlideshowClipFile(name, path, count, duration, loop,
1128 crop, fade, luma_duration,
1129 luma_file, softness,
1130 animation, group, groupId);
1132 emit selectLastAddedClip(QString::number(m_clipManager->lastClipId()));
1135 void KdenliveDoc::slotCreateTextClip(QString group, const QString &groupId, const QString &templatePath)
1137 QString titlesFolder = projectFolder().path(KUrl::AddTrailingSlash) + "titles/";
1138 KStandardDirs::makeDir(titlesFolder);
1139 TitleWidget *dia_ui = new TitleWidget(templatePath, m_timecode, titlesFolder, m_render, kapp->activeWindow());
1140 if (dia_ui->exec() == QDialog::Accepted) {
1141 m_clipManager->slotAddTextClipFile(i18n("Title clip"), dia_ui->outPoint(), dia_ui->xml().toString(), group, groupId);
1143 emit selectLastAddedClip(QString::number(m_clipManager->lastClipId()));
1148 void KdenliveDoc::slotCreateTextTemplateClip(QString group, const QString &groupId, KUrl path)
1150 QString titlesFolder = projectFolder().path(KUrl::AddTrailingSlash) + "titles/";
1151 if (path.isEmpty()) {
1152 path = KFileDialog::getOpenUrl(KUrl(titlesFolder), "application/x-kdenlivetitle", kapp->activeWindow(), i18n("Enter Template Path"));
1155 if (path.isEmpty()) return;
1157 //TODO: rewrite with new title system (just set resource)
1158 m_clipManager->slotAddTextTemplateClip(i18n("Template title clip"), path, group, groupId);
1160 emit selectLastAddedClip(QString::number(m_clipManager->lastClipId()));
1163 int KdenliveDoc::tracksCount() const
1165 return m_tracksList.count();
1168 TrackInfo KdenliveDoc::trackInfoAt(int ix) const
1170 if (ix < 0 || ix >= m_tracksList.count()) {
1171 kWarning() << "Track INFO outisde of range";
1174 return m_tracksList.at(ix);
1177 void KdenliveDoc::switchTrackAudio(int ix, bool hide)
1179 if (ix < 0 || ix >= m_tracksList.count()) {
1180 kWarning() << "SWITCH Track outisde of range";
1183 m_tracksList[ix].isMute = hide; // !m_tracksList.at(ix).isMute;
1186 void KdenliveDoc::switchTrackLock(int ix, bool lock)
1188 if (ix < 0 || ix >= m_tracksList.count()) {
1189 kWarning() << "Track Lock outisde of range";
1192 m_tracksList[ix].isLocked = lock;
1195 bool KdenliveDoc::isTrackLocked(int ix) const
1197 if (ix < 0 || ix >= m_tracksList.count()) {
1198 kWarning() << "Track Lock outisde of range";
1201 return m_tracksList.at(ix).isLocked;
1204 void KdenliveDoc::switchTrackVideo(int ix, bool hide)
1206 if (ix < 0 || ix >= m_tracksList.count()) {
1207 kWarning() << "SWITCH Track outisde of range";
1210 m_tracksList[ix].isBlind = hide; // !m_tracksList.at(ix).isBlind;
1213 void KdenliveDoc::insertTrack(int ix, TrackInfo type)
1215 if (ix == -1) m_tracksList << type;
1216 else m_tracksList.insert(ix, type);
1219 void KdenliveDoc::deleteTrack(int ix)
1221 if (ix < 0 || ix >= m_tracksList.count()) {
1222 kWarning() << "Delete Track outisde of range";
1225 m_tracksList.removeAt(ix);
1228 void KdenliveDoc::setTrackType(int ix, TrackInfo type)
1230 if (ix < 0 || ix >= m_tracksList.count()) {
1231 kWarning() << "SET Track Type outisde of range";
1234 m_tracksList[ix].type = type.type;
1235 m_tracksList[ix].isMute = type.isMute;
1236 m_tracksList[ix].isBlind = type.isBlind;
1237 m_tracksList[ix].isLocked = type.isLocked;
1238 m_tracksList[ix].trackName = type.trackName;
1241 const QList <TrackInfo> KdenliveDoc::tracksList() const
1243 return m_tracksList;
1246 QPoint KdenliveDoc::getTracksCount() const
1250 foreach(const TrackInfo & info, m_tracksList) {
1251 if (info.type == VIDEOTRACK) video++;
1254 return QPoint(video, audio);
1257 void KdenliveDoc::cachePixmap(const QString &fileId, const QPixmap &pix) const
1259 pix.save(m_projectFolder.path(KUrl::AddTrailingSlash) + "thumbs/" + fileId + ".png");
1262 QString KdenliveDoc::getLadspaFile() const
1265 QString counter = QString::number(ct).rightJustified(5, '0', false);
1266 while (QFile::exists(m_projectFolder.path(KUrl::AddTrailingSlash) + "ladspa/" + counter + ".ladspa")) {
1268 counter = QString::number(ct).rightJustified(5, '0', false);
1270 return m_projectFolder.path(KUrl::AddTrailingSlash) + "ladspa/" + counter + ".ladspa";
1273 bool KdenliveDoc::checkDocumentClips(QDomNodeList infoproducers)
1275 DocumentChecker d(infoproducers, m_document);
1276 return (d.hasMissingClips() == false);
1282 QList <QDomElement> missingClips;
1283 for (int i = 0; i < infoproducers.count(); i++) {
1284 e = infoproducers.item(i).toElement();
1285 clipType = e.attribute("type").toInt();
1286 if (clipType == COLOR) continue;
1287 if (clipType == TEXT) {
1288 //TODO: Check is clip template is missing (xmltemplate) or hash changed
1291 id = e.attribute("id");
1292 resource = e.attribute("resource");
1293 if (clipType == SLIDESHOW) resource = KUrl(resource).directory();
1294 if (!KIO::NetAccess::exists(KUrl(resource), KIO::NetAccess::SourceSide, 0)) {
1295 // Missing clip found
1296 missingClips.append(e);
1298 // Check if the clip has changed
1299 if (clipType != SLIDESHOW && e.hasAttribute("file_hash")) {
1300 if (e.attribute("file_hash") != DocClipBase::getHash(e.attribute("resource")))
1301 e.removeAttribute("file_hash");
1305 if (missingClips.isEmpty()) return true;
1306 DocumentChecker d(missingClips, m_document);
1307 return (d.exec() == QDialog::Accepted);*/
1310 void KdenliveDoc::setDocumentProperty(const QString &name, const QString &value)
1312 m_documentProperties[name] = value;
1315 const QString KdenliveDoc::getDocumentProperty(const QString &name) const
1317 return m_documentProperties.value(name);
1320 QMap <QString, QString> KdenliveDoc::getRenderProperties() const
1322 QMap <QString, QString> renderProperties;
1323 QMapIterator<QString, QString> i(m_documentProperties);
1324 while (i.hasNext()) {
1326 if (i.key().startsWith("render")) renderProperties.insert(i.key(), i.value());
1328 return renderProperties;
1331 void KdenliveDoc::addTrackEffect(int ix, QDomElement effect)
1333 if (ix < 0 || ix >= m_tracksList.count()) {
1334 kWarning() << "Add Track effect outisde of range";
1337 effect.setAttribute("kdenlive_ix", m_tracksList.at(ix).effectsList.count() + 1);
1339 // Init parameter value & keyframes if required
1340 QDomNodeList params = effect.elementsByTagName("parameter");
1341 for (int i = 0; i < params.count(); i++) {
1342 QDomElement e = params.item(i).toElement();
1344 // Check if this effect has a variable parameter
1345 if (e.attribute("default").startsWith('%')) {
1346 double evaluatedValue = ProfilesDialog::getStringEval(m_profile, e.attribute("default"));
1347 e.setAttribute("default", evaluatedValue);
1348 if (e.hasAttribute("value") && e.attribute("value").startsWith('%')) {
1349 e.setAttribute("value", evaluatedValue);
1353 if (!e.isNull() && (e.attribute("type") == "keyframe" || e.attribute("type") == "simplekeyframe")) {
1354 QString def = e.attribute("default");
1355 // Effect has a keyframe type parameter, we need to set the values
1356 if (e.attribute("keyframes").isEmpty()) {
1357 e.setAttribute("keyframes", "0:" + def + ';');
1358 kDebug() << "///// EFFECT KEYFRAMES INITED: " << e.attribute("keyframes");
1364 m_tracksList[ix].effectsList.append(effect);
1367 void KdenliveDoc::removeTrackEffect(int ix, QDomElement effect)
1369 if (ix < 0 || ix >= m_tracksList.count()) {
1370 kWarning() << "Remove Track effect outisde of range";
1374 QString toRemove = effect.attribute("kdenlive_ix");
1375 for (int i = 0; i < m_tracksList.at(ix).effectsList.count(); ++i) {
1376 index = m_tracksList.at(ix).effectsList.at(i).attribute("kdenlive_ix");
1377 if (toRemove == index) {
1378 m_tracksList[ix].effectsList.removeAt(i);
1380 } else if (index.toInt() > toRemove.toInt()) {
1381 m_tracksList[ix].effectsList.item(i).setAttribute("kdenlive_ix", index.toInt() - 1);
1386 void KdenliveDoc::setTrackEffect(int trackIndex, int effectIndex, QDomElement effect)
1388 if (trackIndex < 0 || trackIndex >= m_tracksList.count()) {
1389 kWarning() << "Set Track effect outisde of range";
1392 if (effectIndex < 0 || effectIndex > (m_tracksList.at(trackIndex).effectsList.count() - 1) || effect.isNull()) {
1393 kDebug() << "Invalid effect index: " << effectIndex;
1396 effect.setAttribute("kdenlive_ix", effectIndex + 1);
1397 m_tracksList[trackIndex].effectsList.replace(effectIndex, effect);
1400 const EffectsList KdenliveDoc::getTrackEffects(int ix)
1402 if (ix < 0 || ix >= m_tracksList.count()) {
1403 kWarning() << "Get Track effects outisde of range";
1404 return EffectsList();
1406 return m_tracksList.at(ix).effectsList;
1409 QDomElement KdenliveDoc::getTrackEffect(int trackIndex, int effectIndex) const
1411 if (trackIndex < 0 || trackIndex >= m_tracksList.count()) {
1412 kWarning() << "Get Track effect outisde of range";
1413 return QDomElement();
1415 EffectsList list = m_tracksList.at(trackIndex).effectsList;
1416 if (effectIndex > list.count() - 1 || effectIndex < 0 || list.at(effectIndex).isNull()) return QDomElement();
1417 return list.at(effectIndex).cloneNode().toElement();
1420 bool KdenliveDoc::saveCustomEffects(QDomNodeList customeffects)
1423 QStringList importedEffects;
1424 int maxchild = customeffects.count();
1425 for (int i = 0; i < maxchild; i++) {
1426 e = customeffects.at(i).toElement();
1427 QString id = e.attribute("id");
1428 QString tag = e.attribute("tag");
1429 if (!id.isEmpty()) {
1430 // Check if effect exists or save it
1431 if (MainWindow::customEffects.hasEffect(tag, id) == -1) {
1433 doc.appendChild(doc.importNode(e, true));
1434 QString path = KStandardDirs::locateLocal("appdata", "effects/", true);
1435 path += id + ".xml";
1436 if (!QFile::exists(path)) {
1437 importedEffects << id;
1439 if (file.open(QFile::WriteOnly | QFile::Truncate)) {
1440 QTextStream out(&file);
1441 out << doc.toString();
1447 if (!importedEffects.isEmpty()) KMessageBox::informationList(kapp->activeWindow(), i18n("The following effects were imported from the project:"), importedEffects);
1448 return (!importedEffects.isEmpty());
1451 #include "kdenlivedoc.moc"