+void KdenliveDoc::addTrackEffect(int ix, QDomElement effect)
+{
+ if (ix < 0 || ix >= m_tracksList.count()) {
+ kWarning() << "Add Track effect outisde of range";
+ return;
+ }
+ effect.setAttribute("kdenlive_ix", m_tracksList.at(ix).effectsList.count() + 1);
+
+ // Init parameter value & keyframes if required
+ QDomNodeList params = effect.elementsByTagName("parameter");
+ for (int i = 0; i < params.count(); i++) {
+ QDomElement e = params.item(i).toElement();
+
+ // Check if this effect has a variable parameter
+ if (e.attribute("default").startsWith('%')) {
+ double evaluatedValue = ProfilesDialog::getStringEval(m_profile, e.attribute("default"));
+ e.setAttribute("default", evaluatedValue);
+ if (e.hasAttribute("value") && e.attribute("value").startsWith('%')) {
+ e.setAttribute("value", evaluatedValue);
+ }
+ }
+
+ if (!e.isNull() && (e.attribute("type") == "keyframe" || e.attribute("type") == "simplekeyframe")) {
+ QString def = e.attribute("default");
+ // Effect has a keyframe type parameter, we need to set the values
+ if (e.attribute("keyframes").isEmpty()) {
+ e.setAttribute("keyframes", "0:" + def + ';');
+ kDebug() << "///// EFFECT KEYFRAMES INITED: " << e.attribute("keyframes");
+ //break;
+ }
+ }
+ }
+
+ m_tracksList[ix].effectsList.append(effect);
+}
+
+void KdenliveDoc::removeTrackEffect(int ix, QDomElement effect)
+{
+ if (ix < 0 || ix >= m_tracksList.count()) {
+ kWarning() << "Remove Track effect outisde of range";
+ return;
+ }
+ QString index;
+ QString toRemove = effect.attribute("kdenlive_ix");
+ for (int i = 0; i < m_tracksList.at(ix).effectsList.count(); ++i) {
+ index = m_tracksList.at(ix).effectsList.at(i).attribute("kdenlive_ix");
+ if (toRemove == index) {
+ m_tracksList[ix].effectsList.removeAt(i);
+ i--;
+ } else if (index.toInt() > toRemove.toInt()) {
+ m_tracksList[ix].effectsList.item(i).setAttribute("kdenlive_ix", index.toInt() - 1);
+ }
+ }
+}
+
+void KdenliveDoc::setTrackEffect(int trackIndex, int effectIndex, QDomElement effect)
+{
+ if (trackIndex < 0 || trackIndex >= m_tracksList.count()) {
+ kWarning() << "Set Track effect outisde of range";
+ return;
+ }
+ if (effectIndex < 0 || effectIndex > (m_tracksList.at(trackIndex).effectsList.count() - 1) || effect.isNull()) {
+ kDebug() << "Invalid effect index: " << effectIndex;
+ return;
+ }
+ effect.setAttribute("kdenlive_ix", effectIndex + 1);
+ m_tracksList[trackIndex].effectsList.replace(effectIndex, effect);
+}
+
+const EffectsList KdenliveDoc::getTrackEffects(int ix)
+{
+ if (ix < 0 || ix >= m_tracksList.count()) {
+ kWarning() << "Get Track effects outisde of range";
+ return EffectsList();
+ }
+ return m_tracksList.at(ix).effectsList;
+}
+
+QDomElement KdenliveDoc::getTrackEffect(int trackIndex, int effectIndex) const
+{
+ if (trackIndex < 0 || trackIndex >= m_tracksList.count()) {
+ kWarning() << "Get Track effect outisde of range";
+ return QDomElement();
+ }
+ EffectsList list = m_tracksList.at(trackIndex).effectsList;
+ if (effectIndex > list.count() - 1 || effectIndex < 0 || list.at(effectIndex).isNull()) return QDomElement();
+ return list.at(effectIndex).cloneNode().toElement();
+}
+
+bool KdenliveDoc::saveCustomEffects(QDomNodeList customeffects)
+{
+ QDomElement e;
+ QStringList importedEffects;
+ int maxchild = customeffects.count();
+ for (int i = 0; i < maxchild; i++) {
+ e = customeffects.at(i).toElement();
+ QString id = e.attribute("id");
+ QString tag = e.attribute("tag");
+ if (!id.isEmpty()) {
+ // Check if effect exists or save it
+ if (MainWindow::customEffects.hasEffect(tag, id) == -1) {
+ QDomDocument doc;
+ doc.appendChild(doc.importNode(e, true));
+ QString path = KStandardDirs::locateLocal("appdata", "effects/", true);
+ path += id + ".xml";
+ if (!QFile::exists(path)) {
+ importedEffects << id;
+ QFile file(path);
+ if (file.open(QFile::WriteOnly | QFile::Truncate)) {
+ QTextStream out(&file);
+ out << doc.toString();
+ }
+ }
+ }
+ }
+ }
+ if (!importedEffects.isEmpty()) KMessageBox::informationList(kapp->activeWindow(), i18n("The following effects were imported from the project:"), importedEffects);
+ return (!importedEffects.isEmpty());
+}
+
+void KdenliveDoc::updateProjectFolderPlacesEntry()
+{
+ const QString file = KStandardDirs::locateLocal("data", "kfileplaces/bookmarks.xml");
+ KBookmarkManager *bookmarkManager = KBookmarkManager::managerForFile(file, "kfilePlaces");
+ KBookmarkGroup root = bookmarkManager->root();
+ KBookmark bookmark = root.first();
+
+ QString kdenliveName = KGlobal::mainComponent().componentName();
+ KUrl documentLocation = m_projectFolder;
+
+ bool exists = false;
+
+ while (!bookmark.isNull()) {
+ // UDI not empty indicates a device
+ QString udi = bookmark.metaDataItem("UDI");
+ QString appName = bookmark.metaDataItem("OnlyInApp");
+
+ if (udi.isEmpty() && appName == kdenliveName && bookmark.text() == i18n("Project Folder")) {
+ if (bookmark.url() != documentLocation) {
+ bookmark.setUrl(documentLocation);
+ bookmarkManager->emitChanged(root);
+ }
+ exists = true;
+ break;
+ }
+
+ bookmark = root.next(bookmark);
+ }
+
+ // if entry does not exist yet (was not found), well, create it then
+ if (!exists) {
+ KBookmark newBookmark = root.addBookmark(i18n("Project Folder"), documentLocation, "folder-favorites");
+ // Make this user selectable ?
+ newBookmark.setMetaDataItem("OnlyInApp", kdenliveName);
+ bookmarkManager->emitChanged(root);
+ }
+}
+