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 ***************************************************************************/
20 #include <QCryptographicHash>
24 #include <KStandardDirs>
25 #include <KMessageBox>
27 #include <KFileDialog>
28 #include <KIO/NetAccess>
29 #include <KIO/CopyJob>
30 #include <KApplication>
33 #include <mlt++/Mlt.h>
35 #include "kdenlivedoc.h"
36 #include "docclipbase.h"
37 #include "profilesdialog.h"
38 #include "kdenlivesettings.h"
40 #include "clipmanager.h"
41 #include "addfoldercommand.h"
42 #include "editfoldercommand.h"
43 #include "titlewidget.h"
44 #include "mainwindow.h"
47 KdenliveDoc::KdenliveDoc(const KUrl &url, const KUrl &projectFolder, QUndoGroup *undoGroup, const QString &profileName, const QPoint tracks, MainWindow *parent): QObject(parent), m_render(NULL), m_url(url), m_projectFolder(projectFolder), m_commandStack(new QUndoStack(undoGroup)), m_modified(false), m_documentLoadingProgress(0), m_documentLoadingStep(0.0), m_startPos(0), m_zoom(7), m_autosave(NULL) {
48 m_clipManager = new ClipManager(this);
49 m_autoSaveTimer = new QTimer(this);
50 m_autoSaveTimer->setSingleShot(true);
53 if (KIO::NetAccess::download(url.path(), tmpFile, parent)) {
55 m_document.setContent(&file, false);
57 QDomNode infoXmlNode = m_document.elementsByTagName("kdenlivedoc").at(0);
58 QDomNode westley = m_document.elementsByTagName("westley").at(0);
59 if (!infoXmlNode.isNull()) {
60 QDomElement infoXml = infoXmlNode.toElement();
61 double version = infoXml.attribute("version").toDouble();
63 // Upgrade old Kdenlive documents to current version
64 convertDocument(version);
66 * read again <kdenlivedoc> and <westley> to get all the new
67 * stuff (convertDocument() can now do anything without breaking
70 infoXmlNode = m_document.elementsByTagName("kdenlivedoc").at(0);
71 infoXml = infoXmlNode.toElement();
72 version = infoXml.attribute("version").toDouble();
73 westley = m_document.elementsByTagName("westley").at(0);
75 QString profilePath = infoXml.attribute("profile");
76 QString projectFolderPath = infoXml.attribute("projectfolder");
77 if (!projectFolderPath.isEmpty()) m_projectFolder = KUrl(projectFolderPath);
78 if (m_projectFolder.isEmpty()) m_projectFolder = KUrl(KdenliveSettings::defaultprojectfolder());
79 m_startPos = infoXml.attribute("position").toInt();
80 m_zoom = infoXml.attribute("zoom", "7").toInt();
81 setProfilePath(profilePath);
84 QString tracks = infoXml.attribute("tracks");
86 videoTrack.type = VIDEOTRACK;
87 videoTrack.isMute = false;
88 videoTrack.isBlind = false;
91 audioTrack.type = AUDIOTRACK;
92 audioTrack.isMute = false;
93 audioTrack.isBlind = true;
94 for (int i = 0; i < tracks.size(); i++) {
95 if (tracks.data()[i] == 'v') m_tracksList.append(videoTrack);
96 else m_tracksList.append(audioTrack);
101 QDomNodeList producers = m_document.elementsByTagName("producer");
102 QDomNodeList infoproducers = m_document.elementsByTagName("kdenlive_producer");
103 const int max = producers.count();
104 const int infomax = infoproducers.count();
107 m_documentLoadingStep = 100.0 / (max + infomax + m_document.elementsByTagName("entry").count());
108 parent->slotGotProgressInfo(i18n("Loading project clips"), (int) m_documentLoadingProgress);
111 for (int i = 0; i < max; i++) {
112 e = producers.item(i).cloneNode().toElement();
113 if (m_documentLoadingStep > 0) {
114 m_documentLoadingProgress += m_documentLoadingStep;
115 parent->slotGotProgressInfo(QString(), (int) m_documentLoadingProgress);
116 //qApp->processEvents();
118 QString prodId = e.attribute("id");
119 if (!e.isNull() && prodId != "black" && !prodId.startsWith("slowmotion")/*&& prodId.toInt() > 0*/) {
120 // addClip(e, prodId, false);
121 kDebug() << "// PROD: " << prodId;
125 for (int i = 0; i < infomax; i++) {
126 e = infoproducers.item(i).cloneNode().toElement();
127 if (m_documentLoadingStep > 0) {
128 m_documentLoadingProgress += m_documentLoadingStep;
129 parent->slotGotProgressInfo(QString(), (int) m_documentLoadingProgress);
130 //qApp->processEvents();
132 QString prodId = e.attribute("id");
133 if (!e.isNull() && prodId != "black" && !prodId.startsWith("slowmotion")) {
134 e.setTagName("producer");
135 addClipInfo(e, prodId);
136 kDebug() << "// NLIVE PROD: " << prodId;
140 QDomNode markers = m_document.elementsByTagName("markers").at(0);
141 if (!markers.isNull()) {
142 QDomNodeList markerslist = markers.childNodes();
143 int maxchild = markerslist.count();
144 for (int k = 0; k < maxchild; k++) {
145 e = markerslist.at(k).toElement();
146 if (e.tagName() == "marker") {
147 m_clipManager->getClipById(e.attribute("id"))->addSnapMarker(GenTime(e.attribute("time").toDouble()), e.attribute("comment"));
150 westley.removeChild(markers);
152 m_document.removeChild(infoXmlNode);
154 kDebug() << "Reading file: " << url.path() << ", found clips: " << producers.count();
156 parent->slotGotProgressInfo(i18n("File %1 is not a Kdenlive project file."), 100);
157 kWarning() << " NO KDENLIVE INFO FOUND IN FILE: " << url.path();
158 m_document = createEmptyDocument(tracks.x(), tracks.y());
159 setProfilePath(profileName);
161 KIO::NetAccess::removeTempFile(tmpFile);
163 KMessageBox::error(parent, KIO::NetAccess::lastErrorString());
164 parent->slotGotProgressInfo(i18n("File %1 is not a Kdenlive project file."), 100);
165 m_document = createEmptyDocument(tracks.x(), tracks.y());
166 setProfilePath(profileName);
169 m_document = createEmptyDocument(tracks.x(), tracks.y());
170 setProfilePath(profileName);
172 if (m_projectFolder.isEmpty()) m_projectFolder = KUrl(KdenliveSettings::defaultprojectfolder());
174 // make sure that the necessary folders exist
175 KStandardDirs::makeDir(m_projectFolder.path() + "/titles/");
176 KStandardDirs::makeDir(m_projectFolder.path() + "/thumbs/");
178 m_scenelist = m_document.toString();
179 kDebug() << "KDEnnlive document, init timecode: " << m_fps;
180 if (m_fps == 30000.0 / 1001.0) m_timecode.setFormat(30, true);
181 else m_timecode.setFormat((int) m_fps);
183 connect(m_autoSaveTimer, SIGNAL(timeout()), this, SLOT(slotAutoSave()));
186 KdenliveDoc::~KdenliveDoc() {
187 delete m_commandStack;
188 delete m_clipManager;
189 delete m_autoSaveTimer;
191 m_autosave->remove();
196 QDomDocument KdenliveDoc::createEmptyDocument(const int videotracks, const int audiotracks) {
197 // Creating new document
199 QDomElement westley = doc.createElement("westley");
200 doc.appendChild(westley);
203 TrackInfo videoTrack;
204 videoTrack.type = VIDEOTRACK;
205 videoTrack.isMute = false;
206 videoTrack.isBlind = false;
208 TrackInfo audioTrack;
209 audioTrack.type = AUDIOTRACK;
210 audioTrack.isMute = false;
211 audioTrack.isBlind = true;
213 QDomElement tractor = doc.createElement("tractor");
214 tractor.setAttribute("id", "maintractor");
215 QDomElement multitrack = doc.createElement("multitrack");
216 QDomElement playlist = doc.createElement("playlist");
217 playlist.setAttribute("id", "black_track");
218 westley.appendChild(playlist);
222 int total = audiotracks + videotracks + 1;
224 for (int i = 1; i < total; i++) {
225 QDomElement playlist = doc.createElement("playlist");
226 playlist.setAttribute("id", "playlist" + QString::number(i));
227 westley.appendChild(playlist);
230 QDomElement track0 = doc.createElement("track");
231 track0.setAttribute("producer", "black_track");
232 tractor.appendChild(track0);
234 // create audio tracks
235 for (int i = 1; i < audiotracks + 1; i++) {
236 QDomElement track = doc.createElement("track");
237 track.setAttribute("producer", "playlist" + QString::number(i));
238 track.setAttribute("hide", "video");
239 tractor.appendChild(track);
240 m_tracksList.append(audioTrack);
243 // create video tracks
244 for (int i = audiotracks + 1; i < total; i++) {
245 QDomElement track = doc.createElement("track");
246 track.setAttribute("producer", "playlist" + QString::number(i));
247 tractor.appendChild(track);
248 m_tracksList.append(videoTrack);
251 for (uint i = 2; i < total ; i++) {
252 QDomElement transition = doc.createElement("transition");
253 transition.setAttribute("always_active", "1");
255 QDomElement property = doc.createElement("property");
256 property.setAttribute("name", "a_track");
257 QDomText value = doc.createTextNode(QString::number(1));
258 property.appendChild(value);
259 transition.appendChild(property);
261 property = doc.createElement("property");
262 property.setAttribute("name", "b_track");
263 value = doc.createTextNode(QString::number(i));
264 property.appendChild(value);
265 transition.appendChild(property);
267 property = doc.createElement("property");
268 property.setAttribute("name", "mlt_service");
269 value = doc.createTextNode("mix");
270 property.appendChild(value);
271 transition.appendChild(property);
273 property = doc.createElement("property");
274 property.setAttribute("name", "combine");
275 value = doc.createTextNode("1");
276 property.appendChild(value);
277 transition.appendChild(property);
279 property = doc.createElement("property");
280 property.setAttribute("name", "internal_added");
281 value = doc.createTextNode("237");
282 property.appendChild(value);
283 transition.appendChild(property);
284 tractor.appendChild(transition);
286 westley.appendChild(tractor);
291 void KdenliveDoc::syncGuides(QList <Guide *> guides) {
295 m_guidesXml = doc.createElement("guides");
297 for (int i = 0; i < guides.count(); i++) {
298 e = doc.createElement("guide");
299 e.setAttribute("time", guides.at(i)->position().ms() / 1000);
300 e.setAttribute("comment", guides.at(i)->label());
301 m_guidesXml.appendChild(e);
303 emit guidesUpdated();
306 QDomElement KdenliveDoc::guidesXml() const {
310 void KdenliveDoc::slotAutoSave() {
311 if (m_render && m_autosave) {
312 if (!m_autosave->isOpen() && !m_autosave->open(QIODevice::ReadWrite)) {
313 // show error: could not open the autosave file
314 kDebug() << "ERROR; CANNOT CREATE AUTOSAVE FILE";
316 kDebug() << "// AUTOSAVE FILE: " << m_autosave->fileName();
318 doc.setContent(m_render->sceneList());
319 saveSceneList(m_autosave->fileName(), doc);
323 void KdenliveDoc::setZoom(int factor) {
327 int KdenliveDoc::zoom() const {
331 void KdenliveDoc::convertDocument(double version) {
332 kDebug() << "Opening a document with version " << version;
333 if (version == 0.8) {
334 // Add the tracks information
336 QDomNodeList tracks = m_document.elementsByTagName("track");
337 int max = tracks.count();
338 for (int i = 0; i < max; i++) {
339 QDomElement t = tracks.at(i).toElement();
340 if (t.attribute("hide") == "video") tracksOrder.append('a');
341 else tracksOrder.append('v');
343 QDomNode kdenlivedoc = m_document.elementsByTagName("kdenlivedoc").at(0);
344 QDomElement infoXml = kdenlivedoc.toElement();
345 QString currentTrackOrder = infoXml.attribute("tracks");
346 if (currentTrackOrder.isEmpty()) infoXml.setAttribute("tracks", tracksOrder);
351 // Opening a old Kdenlive document
352 if (version == 0.7) {
353 kDebug() << "Unable to open document with version " << version;
354 // TODO: convert 0.7 files to the new document format.
359 QDomNode westley = m_document.elementsByTagName("westley").at(1);
360 QDomNode tractor = m_document.elementsByTagName("tractor").at(0);
361 QDomNode kdenlivedoc = m_document.elementsByTagName("kdenlivedoc").at(0);
362 QDomElement kdenlivedoc_old = kdenlivedoc.cloneNode(true).toElement(); // Needed for folders
363 QDomNode multitrack = m_document.elementsByTagName("multitrack").at(0);
364 QDomNodeList playlists = m_document.elementsByTagName("playlist");
366 //m_startPos = kdenlivedoc.toElement().attribute("timeline_position").toInt();
368 QDomNode props = m_document.elementsByTagName("properties").at(0).toElement();
369 QString profile = props.toElement().attribute("videoprofile");
370 m_startPos = props.toElement().attribute("timeline_position").toInt();
371 if (profile == "dv_wide") profile = "dv_pal_wide";
372 //setProfilePath(profile);
374 // move playlists outside of tractor and add the tracks instead
375 int max = playlists.count();
376 for (int i = 0; i < max; i++) {
377 QDomNode n = playlists.at(i);
378 westley.insertBefore(n, QDomNode());
379 QDomElement pl = n.toElement();
380 QDomElement track = m_document.createElement("track");
381 QString trackType = pl.attribute("hide");
382 if (!trackType.isEmpty()) {
383 track.setAttribute("hide", trackType);
384 if (trackType == "video") tracksOrder.append('a');
385 else tracksOrder.append('v');
386 } else tracksOrder.append('v');
387 QString playlist_id = pl.attribute("id");
388 if (playlist_id.isEmpty()) {
389 playlist_id = "black_track";
390 pl.setAttribute("id", playlist_id);
392 track.setAttribute("producer", playlist_id);
393 //tractor.appendChild(track);
394 #define KEEP_TRACK_ORDER 1
395 #ifdef KEEP_TRACK_ORDER
396 tractor.insertAfter(track, QDomNode());
398 // Insert the new track in an order that hopefully matches the 3 video, then 2 audio tracks of Kdenlive 0.7.0
399 // insertion sort - O( tracks*tracks )
400 // Note, this breaks _all_ transitions - but you can move them up and down afterwards.
401 QDomElement tractor_elem = tractor.toElement();
402 if (! tractor_elem.isNull()) {
403 QDomNodeList tracks = tractor_elem.elementsByTagName("track");
404 int size = tracks.size();
406 tractor.insertAfter(track, QDomNode());
408 bool inserted = false;
409 for (int i = 0; i < size; ++i) {
410 QDomElement track_elem = tracks.at(i).toElement();
411 if (track_elem.isNull()) {
412 tractor.insertAfter(track, QDomNode());
416 kDebug() << "playlist_id: " << playlist_id << " producer:" << track_elem.attribute("producer");
417 if (playlist_id < track_elem.attribute("producer")) {
418 tractor.insertBefore(track, track_elem);
424 // Reach here, no insertion, insert last
426 tractor.insertAfter(track, QDomNode());
430 kWarning() << "tractor was not a QDomElement";
431 tractor.insertAfter(track, QDomNode());
435 tractor.removeChild(multitrack);
437 //Â audio track mixing transitions should not be added to track view, so add required attribute
438 QDomNodeList transitions = m_document.elementsByTagName("transition");
439 max = transitions.count();
440 for (int i = 0; i < max; i++) {
441 QDomElement tr = transitions.at(i).toElement();
442 if (tr.attribute("combine") == "1" && tr.attribute("mlt_service") == "mix") {
443 QDomElement property = m_document.createElement("property");
444 property.setAttribute("name", "internal_added");
445 QDomText value = m_document.createTextNode("237");
446 property.appendChild(value);
447 tr.appendChild(property);
449 // convert transition
450 QDomNamedNodeMap attrs = tr.attributes();
451 for (unsigned int j = 0; j < attrs.count(); j++) {
452 QString attrName = attrs.item(j).nodeName();
453 if (attrName != "in" && attrName != "out" && attrName != "id") {
454 QDomElement property = m_document.createElement("property");
455 property.setAttribute("name", attrName);
456 QDomText value = m_document.createTextNode(attrs.item(j).nodeValue());
457 property.appendChild(value);
458 tr.appendChild(property);
464 //Â move transitions after tracks
465 for (int i = 0; i < max; i++) {
466 tractor.insertAfter(transitions.at(0), QDomNode());
469 // Fix filters format
470 QDomNodeList entries = m_document.elementsByTagName("entry");
471 max = entries.count();
472 for (int i = 0; i < max; i++) {
475 QDomNode m = entries.at(i).firstChild();
476 while (!m.isNull()) {
477 if (m.toElement().tagName() == "filter") {
478 QDomElement filt = m.toElement();
479 QDomNamedNodeMap attrs = filt.attributes();
480 QString current_id = filt.attribute("kdenlive_id");
481 if (current_id != last_id) {
483 last_id = current_id;
485 QDomElement e = m_document.createElement("property");
486 e.setAttribute("name", "kdenlive_ix");
487 QDomText value = m_document.createTextNode(QString::number(effectix));
488 e.appendChild(value);
490 for (int j = 0; j < attrs.count(); j++) {
491 QDomAttr a = attrs.item(j).toAttr();
493 kDebug() << " FILTER; adding :" << a.name() << ":" << a.value();
494 QDomElement e = m_document.createElement("property");
495 e.setAttribute("name", a.name());
496 QDomText value = m_document.createTextNode(a.value());
497 e.appendChild(value);
508 QDomNodeList filters = m_document.elementsByTagName("filter");
509 max = filters.count();
512 for (int i = 0; i < max; i++) {
513 QDomElement filt = filters.at(i).toElement();
514 QDomNamedNodeMap attrs = filt.attributes();
515 QString current_id = filt.attribute("kdenlive_id");
516 if (current_id != last_id) {
518 last_id = current_id;
520 QDomElement e = m_document.createElement("property");
521 e.setAttribute("name", "kdenlive_ix");
522 QDomText value = m_document.createTextNode(QString::number(1));
523 e.appendChild(value);
525 for (int j = 0; j < attrs.count(); j++) {
526 QDomAttr a = attrs.item(j).toAttr();
528 kDebug() << " FILTER; adding :" << a.name() << ":" << a.value();
529 QDomElement e = m_document.createElement("property");
530 e.setAttribute("name", a.name());
531 QDomText value = m_document.createTextNode(a.value());
532 e.appendChild(value);
539 QDomNodeList producers = westley.toElement().elementsByTagName("producer");
540 max = producers.count();
541 for (int i = 0; i < max; i++) {
542 QDomElement prod = producers.at(i).toElement();
543 if (prod.attribute("mlt_service") == "framebuffer") {
544 QString slowmotionprod = prod.attribute("resource");
545 slowmotionprod.replace(':', '?');
546 kDebug() << "// FOUND WRONG SLOWMO, new: " << slowmotionprod;
547 prod.setAttribute("resource", slowmotionprod);
550 //Â move producers to correct place, markers to a global list, fix clip descriptions
551 QDomElement markers = m_document.createElement("markers");
552 // This will get the westley producers:
553 producers = m_document.elementsByTagName("producer");
554 max = producers.count();
555 for (int i = 0; i < max; i++) {
556 QDomElement prod = producers.at(0).toElement();
557 // add resource also as a property (to allow path correction in setNewResource())
558 // TODO: will it work with slowmotion? needs testing
559 if (!prod.attribute("resource").isEmpty()) {
560 QDomElement prop_resource = m_document.createElement("property");
561 prop_resource.setAttribute("name", "resource");
562 QDomText resource = m_document.createTextNode(prod.attribute("resource"));
563 prop_resource.appendChild(resource);
564 prod.appendChild(prop_resource);
566 QDomNode m = prod.firstChild();
568 if (m.toElement().tagName() == "markers") {
569 QDomNodeList prodchilds = m.childNodes();
570 int maxchild = prodchilds.count();
571 for (int k = 0; k < maxchild; k++) {
572 QDomElement mark = prodchilds.at(0).toElement();
573 mark.setAttribute("id", prod.attribute("id"));
574 markers.insertAfter(mark, QDomNode());
577 } else if (prod.attribute("type").toInt() == TEXT) {
578 // convert title clip
579 if (m.toElement().tagName() == "textclip") {
581 QDomElement titleclip = m.toElement();
582 QDomElement title = tdoc.createElement("kdenlivetitle");
583 tdoc.appendChild(title);
584 QDomNodeList objects = titleclip.childNodes();
585 int maxchild = objects.count();
586 for (int k = 0; k < maxchild; k++) {
588 QDomElement ob = objects.at(k).toElement();
589 if (ob.attribute("type") == "3") {
590 // text object - all of this goes into "xmldata"...
591 QDomElement item = tdoc.createElement("item");
592 item.setAttribute("z-index", ob.attribute("z"));
593 item.setAttribute("type", "QGraphicsTextItem");
594 QDomElement position = tdoc.createElement("position");
595 position.setAttribute("x", ob.attribute("x"));
596 position.setAttribute("y", ob.attribute("y"));
597 QDomElement content = tdoc.createElement("content");
598 content.setAttribute("font", ob.attribute("font_family"));
599 content.setAttribute("font-size", ob.attribute("font_size"));
600 content.setAttribute("font-bold", ob.attribute("bold"));
601 content.setAttribute("font-italic", ob.attribute("italic"));
602 content.setAttribute("font-underline", ob.attribute("underline"));
603 QString col = ob.attribute("color");
605 content.setAttribute("font-color", colorToString(c));
606 // todo: These fields are missing from the newly generated xmldata:
607 // transform, startviewport, endviewport, background
609 QDomText conttxt = tdoc.createTextNode(ob.attribute("text"));
610 content.appendChild(conttxt);
611 item.appendChild(position);
612 item.appendChild(content);
613 title.appendChild(item);
614 } else if (ob.attribute("type") == "5") {
616 QDomElement item = tdoc.createElement("item");
617 item.setAttribute("z-index", ob.attribute("z"));
618 item.setAttribute("type", "QGraphicsRectItem");
619 QDomElement position = tdoc.createElement("position");
620 position.setAttribute("x", ob.attribute("x"));
621 position.setAttribute("y", ob.attribute("y"));
622 QDomElement content = tdoc.createElement("content");
623 QString col = ob.attribute("color");
625 content.setAttribute("brushcolor", colorToString(c));
626 QString rect = "0,0,";
627 rect.append(ob.attribute("width"));
629 rect.append(ob.attribute("height"));
630 content.setAttribute("rect", rect);
631 item.appendChild(position);
632 item.appendChild(content);
633 title.appendChild(item);
636 prod.setAttribute("xmldata", tdoc.toString());
637 // mbd todo: This clearly does not work, as every title gets the same name - trying to leave it empty
638 // QStringList titleInfo = TitleWidget::getFreeTitleInfo(projectFolder());
639 // prod.setAttribute("titlename", titleInfo.at(0));
640 // prod.setAttribute("resource", titleInfo.at(1));
641 //kDebug()<<"TITLE DATA:\n"<<tdoc.toString();
643 } // End conversion of title clips.
645 } else if (m.isText()) {
646 QString comment = m.nodeValue();
647 if (!comment.isEmpty()) {
648 prod.setAttribute("description", comment);
653 int duration = prod.attribute("duration").toInt();
654 if (duration > 0) prod.setAttribute("out", QString::number(duration));
655 // The clip goes back in, but text clips should not go back in, at least not modified
656 westley.insertBefore(prod, QDomNode());
660 QDomNode westley0 = m_document.elementsByTagName("westley").at(0);
661 if (!markers.firstChild().isNull()) westley0.appendChild(markers);
664 // Convert as much of the kdenlivedoc as possible. Use the producer in westley
665 // First, remove the old stuff from westley, and add a new empty one
666 // Also, track the max id in order to use it for the adding of groups/folders
667 int max_kproducer_id = 0;
668 westley0.removeChild(kdenlivedoc);
669 QDomElement kdenlivedoc_new = m_document.createElement("kdenlivedoc");
670 kdenlivedoc_new.setAttribute("profile", profile);
671 kdenlivedoc_new.setAttribute("tracks", tracksOrder);
672 // Add all the producers that has a ressource in westley
673 QDomElement westley_element = westley0.toElement();
674 if (westley_element.isNull()) {
675 kWarning() << "westley0 element in document was not a QDomElement - unable to add producers to new kdenlivedoc";
677 QDomNodeList wproducers = westley_element.elementsByTagName("producer");
678 int kmax = wproducers.count();
679 for (int i = 0; i < kmax; i++) {
680 QDomElement wproducer = wproducers.at(i).toElement();
681 if (wproducer.isNull()) {
682 kWarning() << "Found producer in westley0, that was not a QDomElement";
684 // We have to do slightly different things, depending on the type
685 kDebug() << "Converting producer element with type" << wproducer.attribute("type");
686 if (wproducer.attribute("type").toInt() == TEXT) {
687 kDebug() << "Found TEXT element in producer" << endl;
688 QDomElement kproducer = wproducer.cloneNode(true).toElement();
689 kproducer.setTagName("kdenlive_producer");
690 kdenlivedoc_new.appendChild(kproducer);
691 // TODO: Perhaps needs some more changes here to "frequency", aspect ratio as a float, frame_size, channels, and later, ressource and title name
693 QDomElement kproducer = m_document.createElement("kdenlive_producer");
694 kproducer.setAttribute("id", wproducer.attribute("id"));
695 if (!wproducer.attribute("description").isEmpty())
696 kproducer.setAttribute("description", wproducer.attribute("description"));
697 kproducer.setAttribute("resource", wproducer.attribute("resource"));
698 kproducer.setAttribute("type", wproducer.attribute("type"));
699 // Testing fix for 358
700 if (!wproducer.attribute("aspect_ratio").isEmpty()) {
701 kproducer.setAttribute("aspect_ratio", wproducer.attribute("aspect_ratio"));
703 if (!wproducer.attribute("source_fps").isEmpty()) {
704 kproducer.setAttribute("fps", wproducer.attribute("source_fps"));
706 if (!wproducer.attribute("length").isEmpty()) {
707 kproducer.setAttribute("duration", wproducer.attribute("length"));
709 kdenlivedoc_new.appendChild(kproducer);
711 if (wproducer.attribute("id").toInt() > max_kproducer_id) {
712 max_kproducer_id = wproducer.attribute("id").toInt();
717 #define LOOKUP_FOLDER 1
719 // Look through all the folder elements of the old doc, for each folder, for each producer,
720 // get the id, look it up in the new doc, set the groupname and groupid
721 // Note, this does not work at the moment - at least one folders shows up missing, and clips with no folder
723 // QDomElement kdenlivedoc_old = kdenlivedoc.toElement();
724 if (!kdenlivedoc_old.isNull()) {
725 QDomNodeList folders = kdenlivedoc_old.elementsByTagName("folder");
726 int fsize = folders.size();
727 int groupId = max_kproducer_id + 1; // Start at +1 of max id of the kdenlive_producers
728 for (int i = 0; i < fsize; ++i) {
729 QDomElement folder = folders.at(i).toElement();
730 if (!folder.isNull()) {
731 QString groupName = folder.attribute("name");
732 kDebug() << "groupName: " << groupName << " with groupId: " << groupId;
733 QDomNodeList fproducers = folder.elementsByTagName("producer");
734 int psize = fproducers.size();
735 for (int j = 0; j < psize; ++j) {
736 QDomElement fproducer = fproducers.at(j).toElement();
737 if (!fproducer.isNull()) {
738 QString id = fproducer.attribute("id");
739 // This is not very effective, but compared to loading the clips, its a breeze
740 QDomNodeList kdenlive_producers = kdenlivedoc_new.elementsByTagName("kdenlive_producer");
741 int kpsize = kdenlive_producers.size();
742 for (int k = 0; k < kpsize; ++k) {
743 QDomElement kproducer = kdenlive_producers.at(k).toElement(); // Its an element for sure
744 if (id == kproducer.attribute("id")) {
745 // We do not check that it already is part of a folder
746 kproducer.setAttribute("groupid", groupId);
747 kproducer.setAttribute("groupname", groupName);
758 westley0.appendChild(kdenlivedoc_new);
760 QDomNodeList elements = westley.childNodes();
761 max = elements.count();
762 for (int i = 0; i < max; i++) {
763 QDomElement prod = elements.at(0).toElement();
764 westley0.insertAfter(prod, QDomNode());
767 westley0.removeChild(westley);
769 // experimental and probably slow
770 // adds <avfile /> information to <kdenlive_producer />
771 QDomNodeList kproducers = m_document.elementsByTagName("kdenlive_producer");
772 QDomNodeList avfiles = kdenlivedoc_old.elementsByTagName("avfile");
773 kDebug() << "found" << avfiles.count() << "<avfile />s and" << kproducers.count() << "<kdenlive_producer />s";
774 for (int i = 0; i < avfiles.count(); ++i) {
775 QDomElement avfile = avfiles.at(i).toElement();
776 QDomElement kproducer = QDomElement();
778 kWarning() << "found an <avfile /> that is not a QDomElement";
780 QString id = avfile.attribute("id");
781 // this is horrible, must be rewritten, it's just for test
782 for (int j = 0; j < kproducers.count(); ++j) {
783 //kDebug() << "checking <kdenlive_producer /> with id" << kproducers.at(j).toElement().attribute("id");
784 if (kproducers.at(j).toElement().attribute("id") == id) {
785 kproducer = kproducers.at(j).toElement();
789 if (kproducer == QDomElement())
790 kWarning() << "no match for <avfile /> with id =" << id;
792 //kDebug() << "ready to set additional <avfile />'s attributes (id =" << id << ")";
793 kproducer.setAttribute("channels", avfile.attribute("channels"));
794 kproducer.setAttribute("duration", avfile.attribute("duration"));
795 kproducer.setAttribute("frame_size", avfile.attribute("width") + "x" + avfile.attribute("height"));
796 kproducer.setAttribute("frequency", avfile.attribute("frequency"));
797 if (kproducer.attribute("description").isEmpty() && !avfile.attribute("description").isEmpty())
798 kproducer.setAttribute("description", avfile.attribute("description"));
803 //kDebug() << "///////////////// CONVERTEDÂ DOC:";
804 //kDebug() << m_document.toString();
806 QFile file( "converted.kdenlive" );
807 if ( file.open( QIODevice::WriteOnly ) ) {
808 QTextStream stream( &file );
809 stream << m_document.toString();
812 kDebug() << "Unable to dump file to converted.kdenlive";
815 //kDebug() << "///////////////// END CONVERTEDÂ DOC:";
818 QString KdenliveDoc::colorToString(const QColor& c) {
819 QString ret = "%1,%2,%3,%4";
820 ret = ret.arg(c.red()).arg(c.green()).arg(c.blue()).arg(c.alpha());
824 bool KdenliveDoc::saveSceneList(const QString &path, QDomDocument sceneList) {
825 QDomNode wes = sceneList.elementsByTagName("westley").at(0);
827 QDomElement addedXml = sceneList.createElement("kdenlivedoc");
828 QDomElement markers = sceneList.createElement("markers");
829 addedXml.setAttribute("version", "0.8");
830 addedXml.setAttribute("profile", profilePath());
831 addedXml.setAttribute("position", m_render->seekPosition().frames(m_fps));
832 addedXml.setAttribute("projectfolder", m_projectFolder.path());
833 addedXml.setAttribute("tracks", getTracksInfo());
834 addedXml.setAttribute("zoom", m_zoom);
837 QList <DocClipBase*> list = m_clipManager->documentClipList();
838 for (int i = 0; i < list.count(); i++) {
839 e = list.at(i)->toXML();
840 e.setTagName("kdenlive_producer");
841 addedXml.appendChild(sceneList.importNode(e, true));
842 QList < CommentedTime > marks = list.at(i)->commentedSnapMarkers();
843 for (int j = 0; j < marks.count(); j++) {
844 QDomElement marker = sceneList.createElement("marker");
845 marker.setAttribute("time", marks.at(j).time().ms() / 1000);
846 marker.setAttribute("comment", marks.at(j).comment());
847 marker.setAttribute("id", e.attribute("id"));
848 markers.appendChild(marker);
851 addedXml.appendChild(markers);
852 if (!m_guidesXml.isNull()) addedXml.appendChild(sceneList.importNode(m_guidesXml, true));
854 wes.appendChild(addedXml);
855 //wes.appendChild(doc.importNode(kdenliveData, true));
858 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
859 kWarning() << "////// ERROR writing to file: " << path;
860 KMessageBox::error(kapp->activeWindow(), i18n("Cannot write to file %1", path));
863 QTextStream out(&file);
864 out << sceneList.toString();
869 ClipManager *KdenliveDoc::clipManager() {
870 return m_clipManager;
873 KUrl KdenliveDoc::projectFolder() const {
874 //if (m_projectFolder.isEmpty()) return KUrl(KStandardDirs::locateLocal("appdata", "/projects/"));
875 return m_projectFolder;
878 void KdenliveDoc::setProjectFolder(KUrl url) {
879 if (url == m_projectFolder) return;
881 KStandardDirs::makeDir(url.path());
882 KStandardDirs::makeDir(url.path() + "/titles/");
883 KStandardDirs::makeDir(url.path() + "/thumbs/");
884 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);
885 m_projectFolder = url;
888 void KdenliveDoc::moveProjectData(KUrl url) {
889 QList <DocClipBase*> list = m_clipManager->documentClipList();
890 for (int i = 0; i < list.count(); i++) {
891 DocClipBase *clip = list.at(i);
892 if (clip->clipType() == TEXT) {
893 // the image for title clip must be moved
894 KUrl oldUrl = clip->fileURL();
895 KUrl newUrl = KUrl(url.path() + "/titles/" + oldUrl.fileName());
896 KIO::Job *job = KIO::copy(oldUrl, newUrl);
897 if (KIO::NetAccess::synchronousRun(job, 0)) clip->setProperty("resource", newUrl.path());
899 QString hash = clip->getClipHash();
900 KUrl oldVideoThumbUrl = KUrl(m_projectFolder.path() + "/thumbs/" + hash + ".png");
901 KUrl oldAudioThumbUrl = KUrl(m_projectFolder.path() + "/thumbs/" + hash + ".thumb");
902 if (KIO::NetAccess::exists(oldVideoThumbUrl, KIO::NetAccess::SourceSide, 0)) {
903 KUrl newUrl = KUrl(url.path() + "/thumbs/" + hash + ".png");
904 KIO::Job *job = KIO::copy(oldVideoThumbUrl, newUrl);
905 KIO::NetAccess::synchronousRun(job, 0);
907 if (KIO::NetAccess::exists(oldAudioThumbUrl, KIO::NetAccess::SourceSide, 0)) {
908 KUrl newUrl = KUrl(url.path() + "/thumbs/" + hash + ".thumb");
909 KIO::Job *job = KIO::copy(oldAudioThumbUrl, newUrl);
910 if (KIO::NetAccess::synchronousRun(job, 0)) clip->refreshThumbUrl();
915 QString KdenliveDoc::profilePath() const {
916 return m_profile.path;
919 MltVideoProfile KdenliveDoc::mltProfile() const {
923 void KdenliveDoc::setProfilePath(QString path) {
924 if (path.isEmpty()) path = KdenliveSettings::default_profile();
925 if (path.isEmpty()) path = "dv_pal";
926 m_profile = ProfilesDialog::getVideoProfile(path);
927 KdenliveSettings::setProject_display_ratio((double) m_profile.display_aspect_num / m_profile.display_aspect_den);
928 m_fps = (double) m_profile.frame_rate_num / m_profile.frame_rate_den;
929 m_width = m_profile.width;
930 m_height = m_profile.height;
931 kDebug() << "KDEnnlive document, init timecode from path: " << path << ", " << m_fps;
932 if (m_fps == 30000.0 / 1001.0) m_timecode.setFormat(30, true);
933 else m_timecode.setFormat((int) m_fps);
936 const double KdenliveDoc::dar() {
937 return (double) m_profile.display_aspect_num / m_profile.display_aspect_den;
940 void KdenliveDoc::setThumbsProgress(const QString &message, int progress) {
941 emit progressInfo(message, progress);
944 void KdenliveDoc::loadingProgressed() {
945 m_documentLoadingProgress += m_documentLoadingStep;
946 emit progressInfo(QString(), (int) m_documentLoadingProgress);
949 QUndoStack *KdenliveDoc::commandStack() {
950 return m_commandStack;
953 void KdenliveDoc::setRenderer(Render *render) {
954 if (m_render) return;
956 emit progressInfo(i18n("Loading playlist..."), 0);
957 //qApp->processEvents();
959 m_render->setSceneList(m_document.toString(), m_startPos);
960 kDebug() << "// SETTING SCENE LIST:\n\n" << m_document.toString();
963 emit progressInfo(QString(), -1);
966 void KdenliveDoc::checkProjectClips() {
967 if (m_render == NULL) return;
968 QList <Mlt::Producer *> prods = m_render->producersList();
972 for (int i = 0; i < prods.count(); i++) {
973 id = prods.at(i)->get("id");
974 prodId = id.section('_', 0, 0);
975 prodTrack = id.section('_', 1, 1);
976 DocClipBase *clip = m_clipManager->getClipById(prodId);
977 if (clip) clip->setProducer(prods.at(i));
978 if (clip && clip->clipType() == TEXT && !QFile::exists(clip->fileURL().path())) {
979 // regenerate text clip image if required
980 kDebug() << "// TITLE: " << clip->getProperty("titlename") << " Preview file: " << clip->getProperty("resource") << " DOES NOT EXIST";
981 QString titlename = clip->getProperty("titlename");
982 QString titleresource;
983 if (titlename.isEmpty()) {
984 QStringList titleInfo = TitleWidget::getFreeTitleInfo(projectFolder());
985 titlename = titleInfo.at(0);
986 titleresource = titleInfo.at(1);
987 clip->setProperty("titlename", titlename);
988 kDebug() << "// New title set to: " << titlename;
990 titleresource = TitleWidget::getTitleResourceFromName(projectFolder(), titlename);
992 QString titlepath = projectFolder().path() + "/titles/";
993 TitleWidget *dia_ui = new TitleWidget(KUrl(), titlepath, m_render, kapp->activeWindow());
995 doc.setContent(clip->getProperty("xmldata"));
997 QPixmap pix = dia_ui->renderedPixmap();
998 pix.save(titleresource);
999 clip->setProperty("resource", titleresource);
1001 clip->producer()->set("force_reload", 1);
1006 Render *KdenliveDoc::renderer() {
1010 void KdenliveDoc::updateClip(const QString &id) {
1011 emit updateClipDisplay(id);
1014 int KdenliveDoc::getFramePos(QString duration) {
1015 return m_timecode.getFrameCount(duration, m_fps);
1018 QString KdenliveDoc::producerName(const QString &id) {
1019 QString result = "unnamed";
1020 QDomNodeList prods = producersList();
1021 int ct = prods.count();
1022 for (int i = 0; i < ct ; i++) {
1023 QDomElement e = prods.item(i).toElement();
1024 if (e.attribute("id") != "black" && e.attribute("id") == id) {
1025 result = e.attribute("name");
1026 if (result.isEmpty()) result = KUrl(e.attribute("resource")).fileName();
1033 void KdenliveDoc::setProducerDuration(const QString &id, int duration) {
1034 QDomNodeList prods = producersList();
1035 int ct = prods.count();
1036 for (int i = 0; i < ct ; i++) {
1037 QDomElement e = prods.item(i).toElement();
1038 if (e.attribute("id") != "black" && e.attribute("id") == id) {
1039 e.setAttribute("duration", QString::number(duration));
1045 int KdenliveDoc::getProducerDuration(const QString &id) {
1047 QDomNodeList prods = producersList();
1048 int ct = prods.count();
1049 for (int i = 0; i < ct ; i++) {
1050 QDomElement e = prods.item(i).toElement();
1051 if (e.attribute("id") != "black" && e.attribute("id") == id) {
1052 result = e.attribute("duration").toInt();
1060 QDomDocument KdenliveDoc::generateSceneList() {
1062 QDomElement westley = doc.createElement("westley");
1063 doc.appendChild(westley);
1064 QDomElement prod = doc.createElement("producer");
1067 QDomDocument KdenliveDoc::toXml() const {
1071 Timecode KdenliveDoc::timecode() const {
1075 QDomNodeList KdenliveDoc::producersList() {
1076 return m_document.elementsByTagName("producer");
1079 void KdenliveDoc::backupMltPlaylist() {
1080 if (m_render) m_scenelist = m_render->sceneList();
1083 double KdenliveDoc::projectDuration() const {
1084 if (m_render) return GenTime(m_render->getLength(), m_fps).ms() / 1000;
1087 double KdenliveDoc::fps() const {
1091 int KdenliveDoc::width() const {
1095 int KdenliveDoc::height() const {
1099 KUrl KdenliveDoc::url() const {
1103 void KdenliveDoc::setUrl(KUrl url) {
1107 void KdenliveDoc::setModified(bool mod) {
1108 if (!m_url.isEmpty() && mod && KdenliveSettings::crashrecovery()) {
1109 m_autoSaveTimer->start(3000);
1111 if (mod == m_modified) return;
1113 emit docModified(m_modified);
1116 bool KdenliveDoc::isModified() const {
1120 QString KdenliveDoc::description() const {
1121 if (m_url.isEmpty())
1122 return i18n("Untitled") + " / " + m_profile.description;
1124 return m_url.fileName() + " / " + m_profile.description;
1127 void KdenliveDoc::addClip(QDomElement elem, QString clipId, bool createClipItem) {
1128 const QString producerId = clipId.section('_', 0, 0);
1129 int subtrack = clipId.section('_', 1, 1).toInt();
1130 DocClipBase *clip = m_clipManager->getClipById(producerId);
1132 elem.setAttribute("id", producerId);
1133 QString path = elem.attribute("resource");
1135 if (elem.attribute("type").toInt() == SLIDESHOW) {
1136 extension = KUrl(path).fileName();
1137 path = KUrl(path).directory();
1139 if (!path.isEmpty() && !QFile::exists(path)) {
1140 const QString size = elem.attribute("file_size");
1141 const QString hash = elem.attribute("file_hash");
1143 KMessageBox::ButtonCode action = KMessageBox::No;
1144 if (!size.isEmpty() && !hash.isEmpty()) {
1145 if (!m_searchFolder.isEmpty()) newpath = searchFileRecursively(m_searchFolder, size, hash);
1146 else action = (KMessageBox::ButtonCode)KMessageBox::messageBox(kapp->activeWindow(), KMessageBox::WarningYesNo, i18n("<qt>Clip <b>%1</b><br>is invalid, what do you want to do?", path), i18n("File not found"), KGuiItem(i18n("Search automatically")), /*KGuiItem(i18n("Remove from project")), */KGuiItem(i18n("Keep as placeholder")));
1148 if (elem.attribute("type").toInt() == SLIDESHOW) {
1149 if (KMessageBox::messageBox(kapp->activeWindow(), KMessageBox::WarningYesNo, i18n("<qt>Clip <b>%1</b><br>is invalid, what do you want to do?", path), i18n("File not found"), KGuiItem(i18n("Search automatically")), /*KGuiItem(i18n("Remove from project")),*/ KGuiItem(i18n("Keep as placeholder"))) == KMessageBox::Yes)
1150 newpath = KFileDialog::getExistingDirectory(KUrl("kfiledialog:///clipfolder"), kapp->activeWindow(), i18n("Looking for %1", path));
1151 } else newpath = KFileDialog::getOpenFileName(KUrl("kfiledialog:///clipfolder"), QString(), kapp->activeWindow(), i18n("Looking for %1", path));
1153 if (action == KMessageBox::Yes) {
1154 kDebug() << "// ASKED FOR SRCH CLIP: " << clipId;
1155 m_searchFolder = KFileDialog::getExistingDirectory(KUrl("kfiledialog:///clipfolder"), kapp->activeWindow());
1156 if (!m_searchFolder.isEmpty()) {
1157 newpath = searchFileRecursively(QDir(m_searchFolder), size, hash);
1160 if (!newpath.isEmpty()) {
1161 if (elem.attribute("type").toInt() == SLIDESHOW) newpath.append('/' + extension);
1162 elem.setAttribute("resource", newpath);
1163 setNewClipResource(clipId, newpath);
1167 clip = new DocClipBase(m_clipManager, elem, producerId);
1168 m_clipManager->addClip(clip);
1170 if (createClipItem) emit addProjectClip(clip);
1173 void KdenliveDoc::setNewClipResource(const QString &id, const QString &path) {
1174 QDomNodeList prods = m_document.elementsByTagName("producer");
1175 int maxprod = prods.count();
1176 for (int i = 0; i < maxprod; i++) {
1177 QDomNode m = prods.at(i);
1178 QString prodId = m.toElement().attribute("id");
1179 if (prodId == id || prodId.startsWith(id + "_")) {
1180 QDomNodeList params = m.childNodes();
1181 for (int j = 0; j < params.count(); j++) {
1182 QDomElement e = params.item(j).toElement();
1183 if (e.attribute("name") == "resource") {
1184 e.firstChild().setNodeValue(path);
1192 QString KdenliveDoc::searchFileRecursively(const QDir &dir, const QString &matchSize, const QString &matchHash) const {
1193 QString foundFileName;
1194 QByteArray fileData;
1195 QByteArray fileHash;
1196 QStringList filesAndDirs = dir.entryList(QDir::Files | QDir::Readable);
1197 for (int i = 0; i < filesAndDirs.size() && foundFileName.isEmpty(); i++) {
1198 QFile file(dir.absoluteFilePath(filesAndDirs.at(i)));
1199 if (file.open(QIODevice::ReadOnly)) {
1200 if (QString::number(file.size()) == matchSize) {
1202 * 1 MB = 1 second per 450 files (or faster)
1203 * 10 MB = 9 seconds per 450 files (or faster)
1205 if (file.size() > 1000000*2) {
1206 fileData = file.read(1000000);
1207 if (file.seek(file.size() - 1000000))
1208 fileData.append(file.readAll());
1210 fileData = file.readAll();
1212 fileHash = QCryptographicHash::hash(fileData, QCryptographicHash::Md5);
1213 if (QString(fileHash.toHex()) == matchHash)
1214 return file.fileName();
1217 kDebug() << filesAndDirs.at(i) << file.size() << fileHash.toHex();
1219 filesAndDirs = dir.entryList(QDir::Dirs | QDir::Readable | QDir::Executable | QDir::NoDotAndDotDot);
1220 for (int i = 0; i < filesAndDirs.size() && foundFileName.isEmpty(); i++) {
1221 foundFileName = searchFileRecursively(dir.absoluteFilePath(filesAndDirs.at(i)), matchSize, matchHash);
1222 if (!foundFileName.isEmpty())
1225 return foundFileName;
1228 void KdenliveDoc::addClipInfo(QDomElement elem, QString clipId) {
1229 DocClipBase *clip = m_clipManager->getClipById(clipId);
1231 addClip(elem, clipId);
1233 QMap <QString, QString> properties;
1234 QDomNamedNodeMap attributes = elem.attributes();
1236 for (unsigned int i = 0; i < attributes.count(); i++) {
1237 attrname = attributes.item(i).nodeName();
1238 if (attrname != "resource")
1239 properties.insert(attrname, attributes.item(i).nodeValue());
1240 kDebug() << attrname << " = " << attributes.item(i).nodeValue();
1242 clip->setProperties(properties);
1243 emit addProjectClip(clip, false);
1247 void KdenliveDoc::addFolder(const QString foldername, const QString &clipId, bool edit) {
1248 emit addProjectFolder(foldername, clipId, false, edit);
1251 void KdenliveDoc::deleteFolder(const QString foldername, const QString &clipId) {
1252 emit addProjectFolder(foldername, clipId, true);
1255 void KdenliveDoc::deleteProjectClip(QList <QString> ids) {
1256 for (int i = 0; i < ids.size(); ++i) {
1257 emit deleteTimelineClip(ids.at(i));
1258 m_clipManager->slotDeleteClip(ids.at(i));
1263 void KdenliveDoc::deleteProjectFolder(QMap <QString, QString> map) {
1264 QMapIterator<QString, QString> i(map);
1265 while (i.hasNext()) {
1267 slotDeleteFolder(i.key(), i.value());
1272 void KdenliveDoc::deleteClip(const QString &clipId) {
1273 emit signalDeleteProjectClip(clipId);
1274 m_clipManager->deleteClip(clipId);
1277 void KdenliveDoc::slotAddClipList(const KUrl::List urls, const QString group, const QString &groupId) {
1278 m_clipManager->slotAddClipList(urls, group, groupId);
1279 emit selectLastAddedClip(QString::number(m_clipManager->lastClipId()));
1284 void KdenliveDoc::slotAddClipFile(const KUrl url, const QString group, const QString &groupId) {
1285 kDebug() << "///////// DOCUM, ADD CLP: " << url;
1286 m_clipManager->slotAddClipFile(url, group, groupId);
1287 emit selectLastAddedClip(QString::number(m_clipManager->lastClipId()));
1291 void KdenliveDoc::slotAddFolder(const QString folderName) {
1292 AddFolderCommand *command = new AddFolderCommand(this, folderName, QString::number(m_clipManager->getFreeClipId()), true);
1293 commandStack()->push(command);
1297 void KdenliveDoc::slotDeleteFolder(const QString folderName, const QString &id) {
1298 AddFolderCommand *command = new AddFolderCommand(this, folderName, id, false);
1299 commandStack()->push(command);
1303 void KdenliveDoc::slotEditFolder(const QString newfolderName, const QString oldfolderName, const QString &clipId) {
1304 EditFolderCommand *command = new EditFolderCommand(this, newfolderName, oldfolderName, clipId, false);
1305 commandStack()->push(command);
1309 const QString&KdenliveDoc::getFreeClipId() {
1310 return QString::number(m_clipManager->getFreeClipId());
1313 DocClipBase *KdenliveDoc::getBaseClip(const QString &clipId) {
1314 return m_clipManager->getClipById(clipId);
1317 void KdenliveDoc::slotAddColorClipFile(const QString name, const QString color, QString duration, const QString group, const QString &groupId) {
1318 m_clipManager->slotAddColorClipFile(name, color, duration, group, groupId);
1322 void KdenliveDoc::slotAddSlideshowClipFile(const QString name, const QString path, int count, const QString duration, const bool loop, const bool fade, const QString &luma_duration, const QString &luma_file, const int softness, const QString group, const QString &groupId) {
1323 m_clipManager->slotAddSlideshowClipFile(name, path, count, duration, loop, fade, luma_duration, luma_file, softness, group, groupId);
1327 void KdenliveDoc::slotCreateTextClip(QString group, const QString &groupId) {
1328 QString titlesFolder = projectFolder().path() + "/titles/";
1329 KStandardDirs::makeDir(titlesFolder);
1330 TitleWidget *dia_ui = new TitleWidget(KUrl(), titlesFolder, m_render, kapp->activeWindow());
1331 if (dia_ui->exec() == QDialog::Accepted) {
1332 QStringList titleInfo = TitleWidget::getFreeTitleInfo(projectFolder());
1333 QPixmap pix = dia_ui->renderedPixmap();
1334 pix.save(titleInfo.at(1));
1335 //dia_ui->saveTitle(path + ".kdenlivetitle");
1336 m_clipManager->slotAddTextClipFile(titleInfo.at(0), titleInfo.at(1), dia_ui->xml().toString(), QString(), QString());
1342 int KdenliveDoc::tracksCount() const {
1343 return m_tracksList.count();
1346 TrackInfo KdenliveDoc::trackInfoAt(int ix) const {
1347 return m_tracksList.at(ix);
1350 void KdenliveDoc::switchTrackAudio(int ix, bool hide) {
1351 m_tracksList[ix].isMute = hide; // !m_tracksList.at(ix).isMute;
1354 void KdenliveDoc::switchTrackVideo(int ix, bool hide) {
1355 m_tracksList[ix].isBlind = hide; // !m_tracksList.at(ix).isBlind;
1358 void KdenliveDoc::insertTrack(int ix, TrackInfo type) {
1359 if (ix == -1) m_tracksList << type;
1360 else m_tracksList.insert(ix, type);
1363 void KdenliveDoc::deleteTrack(int ix) {
1364 m_tracksList.removeAt(ix);
1367 void KdenliveDoc::setTrackType(int ix, TrackInfo type) {
1368 m_tracksList[ix].type = type.type;
1369 m_tracksList[ix].isMute = type.isMute;
1370 m_tracksList[ix].isBlind = type.isBlind;
1373 const QList <TrackInfo> KdenliveDoc::tracksList() const {
1374 return m_tracksList;
1377 QPoint KdenliveDoc::getTracksCount() const {
1380 foreach(const TrackInfo &info, m_tracksList) {
1381 if (info.type == VIDEOTRACK) video++;
1384 return QPoint(video, audio);
1387 QString KdenliveDoc::getTracksInfo() const {
1389 foreach(const TrackInfo &info, m_tracksList) {
1390 if (info.type == VIDEOTRACK) result.append('v');
1391 else result.append('a');
1396 void KdenliveDoc::cachePixmap(const QString &fileId, const QPixmap &pix) const {
1397 pix.save(m_projectFolder.path() + "/thumbs/" + fileId + ".png");
1400 #include "kdenlivedoc.moc"