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 if (!convertDocument(version)) {
65 KMessageBox::sorry(parent, i18n("This project type is unsupported and can't be loaded."), i18n("Unable to open project"));
66 m_document = createEmptyDocument(tracks.x(), tracks.y());
67 setProfilePath(profileName);
70 * read again <kdenlivedoc> and <westley> to get all the new
71 * stuff (convertDocument() can now do anything without breaking
74 infoXmlNode = m_document.elementsByTagName("kdenlivedoc").at(0);
75 infoXml = infoXmlNode.toElement();
76 version = infoXml.attribute("version").toDouble();
77 westley = m_document.elementsByTagName("westley").at(0);
79 QString profilePath = infoXml.attribute("profile");
80 QString projectFolderPath = infoXml.attribute("projectfolder");
81 if (!projectFolderPath.isEmpty()) m_projectFolder = KUrl(projectFolderPath);
82 if (m_projectFolder.isEmpty()) m_projectFolder = KUrl(KdenliveSettings::defaultprojectfolder());
83 m_startPos = infoXml.attribute("position").toInt();
84 m_zoom = infoXml.attribute("zoom", "7").toInt();
85 setProfilePath(profilePath);
88 QString tracks = infoXml.attribute("tracks");
90 videoTrack.type = VIDEOTRACK;
91 videoTrack.isMute = false;
92 videoTrack.isBlind = false;
95 audioTrack.type = AUDIOTRACK;
96 audioTrack.isMute = false;
97 audioTrack.isBlind = true;
98 for (int i = 0; i < tracks.size(); i++) {
99 if (tracks.data()[i] == 'v') m_tracksList.append(videoTrack);
100 else m_tracksList.append(audioTrack);
105 QDomNodeList producers = m_document.elementsByTagName("producer");
106 QDomNodeList infoproducers = m_document.elementsByTagName("kdenlive_producer");
107 const int max = producers.count();
108 const int infomax = infoproducers.count();
111 m_documentLoadingStep = 100.0 / (max + infomax + m_document.elementsByTagName("entry").count());
112 parent->slotGotProgressInfo(i18n("Loading project clips"), (int) m_documentLoadingProgress);
115 for (int i = 0; i < max; i++) {
116 e = producers.item(i).cloneNode().toElement();
117 if (m_documentLoadingStep > 0) {
118 m_documentLoadingProgress += m_documentLoadingStep;
119 parent->slotGotProgressInfo(QString(), (int) m_documentLoadingProgress);
120 //qApp->processEvents();
122 QString prodId = e.attribute("id");
123 if (!e.isNull() && prodId != "black" && !prodId.startsWith("slowmotion")/*&& prodId.toInt() > 0*/) {
124 // addClip(e, prodId, false);
125 kDebug() << "// PROD: " << prodId;
129 for (int i = 0; i < infomax; i++) {
130 e = infoproducers.item(i).cloneNode().toElement();
131 if (m_documentLoadingStep > 0) {
132 m_documentLoadingProgress += m_documentLoadingStep;
133 parent->slotGotProgressInfo(QString(), (int) m_documentLoadingProgress);
134 //qApp->processEvents();
136 QString prodId = e.attribute("id");
137 if (!e.isNull() && prodId != "black" && !prodId.startsWith("slowmotion")) {
138 e.setTagName("producer");
139 addClipInfo(e, prodId);
140 kDebug() << "// NLIVE PROD: " << prodId;
144 QDomNode markers = m_document.elementsByTagName("markers").at(0);
145 if (!markers.isNull()) {
146 QDomNodeList markerslist = markers.childNodes();
147 int maxchild = markerslist.count();
148 for (int k = 0; k < maxchild; k++) {
149 e = markerslist.at(k).toElement();
150 if (e.tagName() == "marker") {
151 m_clipManager->getClipById(e.attribute("id"))->addSnapMarker(GenTime(e.attribute("time").toDouble()), e.attribute("comment"));
154 westley.removeChild(markers);
156 m_document.removeChild(infoXmlNode);
158 kDebug() << "Reading file: " << url.path() << ", found clips: " << producers.count();
161 parent->slotGotProgressInfo(i18n("File %1 is not a Kdenlive project file."), 100);
162 kWarning() << " NO KDENLIVE INFO FOUND IN FILE: " << url.path();
163 m_document = createEmptyDocument(tracks.x(), tracks.y());
164 setProfilePath(profileName);
166 KIO::NetAccess::removeTempFile(tmpFile);
168 KMessageBox::error(parent, KIO::NetAccess::lastErrorString());
169 parent->slotGotProgressInfo(i18n("File %1 is not a Kdenlive project file."), 100);
170 m_document = createEmptyDocument(tracks.x(), tracks.y());
171 setProfilePath(profileName);
174 m_document = createEmptyDocument(tracks.x(), tracks.y());
175 setProfilePath(profileName);
177 if (m_projectFolder.isEmpty()) m_projectFolder = KUrl(KdenliveSettings::defaultprojectfolder());
179 // make sure that the necessary folders exist
180 KStandardDirs::makeDir(m_projectFolder.path() + "/titles/");
181 KStandardDirs::makeDir(m_projectFolder.path() + "/thumbs/");
183 m_scenelist = m_document.toString();
184 kDebug() << "KDEnnlive document, init timecode: " << m_fps;
185 if (m_fps == 30000.0 / 1001.0) m_timecode.setFormat(30, true);
186 else m_timecode.setFormat((int) m_fps);
188 connect(m_autoSaveTimer, SIGNAL(timeout()), this, SLOT(slotAutoSave()));
191 KdenliveDoc::~KdenliveDoc() {
192 delete m_commandStack;
193 delete m_clipManager;
194 delete m_autoSaveTimer;
196 m_autosave->remove();
201 QDomDocument KdenliveDoc::createEmptyDocument(const int videotracks, const int audiotracks) {
202 // Creating new document
204 QDomElement westley = doc.createElement("westley");
205 doc.appendChild(westley);
208 TrackInfo videoTrack;
209 videoTrack.type = VIDEOTRACK;
210 videoTrack.isMute = false;
211 videoTrack.isBlind = false;
213 TrackInfo audioTrack;
214 audioTrack.type = AUDIOTRACK;
215 audioTrack.isMute = false;
216 audioTrack.isBlind = true;
218 QDomElement tractor = doc.createElement("tractor");
219 tractor.setAttribute("id", "maintractor");
220 QDomElement multitrack = doc.createElement("multitrack");
221 QDomElement playlist = doc.createElement("playlist");
222 playlist.setAttribute("id", "black_track");
223 westley.appendChild(playlist);
227 int total = audiotracks + videotracks + 1;
229 for (int i = 1; i < total; i++) {
230 QDomElement playlist = doc.createElement("playlist");
231 playlist.setAttribute("id", "playlist" + QString::number(i));
232 westley.appendChild(playlist);
235 QDomElement track0 = doc.createElement("track");
236 track0.setAttribute("producer", "black_track");
237 tractor.appendChild(track0);
239 // create audio tracks
240 for (int i = 1; i < audiotracks + 1; i++) {
241 QDomElement track = doc.createElement("track");
242 track.setAttribute("producer", "playlist" + QString::number(i));
243 track.setAttribute("hide", "video");
244 tractor.appendChild(track);
245 m_tracksList.append(audioTrack);
248 // create video tracks
249 for (int i = audiotracks + 1; i < total; i++) {
250 QDomElement track = doc.createElement("track");
251 track.setAttribute("producer", "playlist" + QString::number(i));
252 tractor.appendChild(track);
253 m_tracksList.append(videoTrack);
256 for (uint i = 2; i < total ; i++) {
257 QDomElement transition = doc.createElement("transition");
258 transition.setAttribute("always_active", "1");
260 QDomElement property = doc.createElement("property");
261 property.setAttribute("name", "a_track");
262 QDomText value = doc.createTextNode(QString::number(1));
263 property.appendChild(value);
264 transition.appendChild(property);
266 property = doc.createElement("property");
267 property.setAttribute("name", "b_track");
268 value = doc.createTextNode(QString::number(i));
269 property.appendChild(value);
270 transition.appendChild(property);
272 property = doc.createElement("property");
273 property.setAttribute("name", "mlt_service");
274 value = doc.createTextNode("mix");
275 property.appendChild(value);
276 transition.appendChild(property);
278 property = doc.createElement("property");
279 property.setAttribute("name", "combine");
280 value = doc.createTextNode("1");
281 property.appendChild(value);
282 transition.appendChild(property);
284 property = doc.createElement("property");
285 property.setAttribute("name", "internal_added");
286 value = doc.createTextNode("237");
287 property.appendChild(value);
288 transition.appendChild(property);
289 tractor.appendChild(transition);
291 westley.appendChild(tractor);
296 void KdenliveDoc::syncGuides(QList <Guide *> guides) {
300 m_guidesXml = doc.createElement("guides");
302 for (int i = 0; i < guides.count(); i++) {
303 e = doc.createElement("guide");
304 e.setAttribute("time", guides.at(i)->position().ms() / 1000);
305 e.setAttribute("comment", guides.at(i)->label());
306 m_guidesXml.appendChild(e);
308 emit guidesUpdated();
311 QDomElement KdenliveDoc::guidesXml() const {
315 void KdenliveDoc::slotAutoSave() {
316 if (m_render && m_autosave) {
317 if (!m_autosave->isOpen() && !m_autosave->open(QIODevice::ReadWrite)) {
318 // show error: could not open the autosave file
319 kDebug() << "ERROR; CANNOT CREATE AUTOSAVE FILE";
321 kDebug() << "// AUTOSAVE FILE: " << m_autosave->fileName();
323 doc.setContent(m_render->sceneList());
324 saveSceneList(m_autosave->fileName(), doc);
328 void KdenliveDoc::setZoom(int factor) {
332 int KdenliveDoc::zoom() const {
336 bool KdenliveDoc::convertDocument(double version) {
337 kDebug() << "Opening a document with version " << version;
339 // Opening a old Kdenlive document
340 if (version == 0.5 || version == 0.7) {
341 kDebug() << "Unable to open document with version " << version;
342 // TODO: convert 0.7 (0.5?) files to the new document format.
346 if (version == 0.8) {
347 // Add the tracks information
349 QDomNodeList tracks = m_document.elementsByTagName("track");
350 int max = tracks.count();
351 for (int i = 0; i < max; i++) {
352 QDomElement t = tracks.at(i).toElement();
353 if (t.attribute("hide") == "video")
354 tracksOrder.append('a');
355 else if (t.attribute("producer") != "black_track")
356 tracksOrder.append('v');
358 QDomNode kdenlivedoc = m_document.elementsByTagName("kdenlivedoc").at(0);
359 QDomElement infoXml = kdenlivedoc.toElement();
360 QString currentTrackOrder = infoXml.attribute("tracks");
361 if (currentTrackOrder.isEmpty()) infoXml.setAttribute("tracks", tracksOrder);
366 QDomNode westley = m_document.elementsByTagName("westley").at(1);
367 QDomNode tractor = m_document.elementsByTagName("tractor").at(0);
368 QDomNode kdenlivedoc = m_document.elementsByTagName("kdenlivedoc").at(0);
369 QDomElement kdenlivedoc_old = kdenlivedoc.cloneNode(true).toElement(); // Needed for folders
370 QDomNode multitrack = m_document.elementsByTagName("multitrack").at(0);
371 QDomNodeList playlists = m_document.elementsByTagName("playlist");
373 QDomNode props = m_document.elementsByTagName("properties").at(0).toElement();
374 QString profile = props.toElement().attribute("videoprofile");
375 m_startPos = props.toElement().attribute("timeline_position").toInt();
376 if (profile == "dv_wide") profile = "dv_pal_wide";
378 // move playlists outside of tractor and add the tracks instead
379 int max = playlists.count();
380 for (int i = 0; i < max; i++) {
381 QDomNode n = playlists.at(i);
382 westley.insertBefore(n, QDomNode());
383 QDomElement pl = n.toElement();
384 QDomElement track = m_document.createElement("track");
385 QString trackType = pl.attribute("hide");
386 if (!trackType.isEmpty())
387 track.setAttribute("hide", trackType);
388 QString playlist_id = pl.attribute("id");
389 if (playlist_id.isEmpty()) {
390 playlist_id = "black_track";
391 pl.setAttribute("id", playlist_id);
393 track.setAttribute("producer", playlist_id);
394 //tractor.appendChild(track);
395 #define KEEP_TRACK_ORDER 1
396 #ifdef KEEP_TRACK_ORDER
397 tractor.insertAfter(track, QDomNode());
399 // Insert the new track in an order that hopefully matches the 3 video, then 2 audio tracks of Kdenlive 0.7.0
400 // insertion sort - O( tracks*tracks )
401 // Note, this breaks _all_ transitions - but you can move them up and down afterwards.
402 QDomElement tractor_elem = tractor.toElement();
403 if (! tractor_elem.isNull()) {
404 QDomNodeList tracks = tractor_elem.elementsByTagName("track");
405 int size = tracks.size();
407 tractor.insertAfter(track, QDomNode());
409 bool inserted = false;
410 for (int i = 0; i < size; ++i) {
411 QDomElement track_elem = tracks.at(i).toElement();
412 if (track_elem.isNull()) {
413 tractor.insertAfter(track, QDomNode());
417 kDebug() << "playlist_id: " << playlist_id << " producer:" << track_elem.attribute("producer");
418 if (playlist_id < track_elem.attribute("producer")) {
419 tractor.insertBefore(track, track_elem);
425 // Reach here, no insertion, insert last
427 tractor.insertAfter(track, QDomNode());
431 kWarning() << "tractor was not a QDomElement";
432 tractor.insertAfter(track, QDomNode());
436 tractor.removeChild(multitrack);
438 // write tracks order now that they've been sorted
440 QDomNodeList tracks = m_document.elementsByTagName("track");
441 for (int i = 0; i < tracks.count(); ++i) {
442 QDomElement track = tracks.at(i).toElement();
443 if (track.attribute("hide") == "video")
444 tracksOrder.append('a');
445 else if (track.attribute("producer") != "black_track")
446 tracksOrder.append('v');
449 //Â audio track mixing transitions should not be added to track view, so add required attribute
450 QDomNodeList transitions = m_document.elementsByTagName("transition");
451 max = transitions.count();
452 for (int i = 0; i < max; i++) {
453 QDomElement tr = transitions.at(i).toElement();
454 if (tr.attribute("combine") == "1" && tr.attribute("mlt_service") == "mix") {
455 QDomElement property = m_document.createElement("property");
456 property.setAttribute("name", "internal_added");
457 QDomText value = m_document.createTextNode("237");
458 property.appendChild(value);
459 tr.appendChild(property);
461 // convert transition
462 QDomNamedNodeMap attrs = tr.attributes();
463 for (unsigned int j = 0; j < attrs.count(); j++) {
464 QString attrName = attrs.item(j).nodeName();
465 if (attrName != "in" && attrName != "out" && attrName != "id") {
466 QDomElement property = m_document.createElement("property");
467 property.setAttribute("name", attrName);
468 QDomText value = m_document.createTextNode(attrs.item(j).nodeValue());
469 property.appendChild(value);
470 tr.appendChild(property);
476 //Â move transitions after tracks
477 for (int i = 0; i < max; i++) {
478 tractor.insertAfter(transitions.at(0), QDomNode());
481 // Fix filters format
482 QDomNodeList entries = m_document.elementsByTagName("entry");
483 max = entries.count();
484 for (int i = 0; i < max; i++) {
487 QDomNode m = entries.at(i).firstChild();
488 while (!m.isNull()) {
489 if (m.toElement().tagName() == "filter") {
490 QDomElement filt = m.toElement();
491 QDomNamedNodeMap attrs = filt.attributes();
492 QString current_id = filt.attribute("kdenlive_id");
493 if (current_id != last_id) {
495 last_id = current_id;
497 QDomElement e = m_document.createElement("property");
498 e.setAttribute("name", "kdenlive_ix");
499 QDomText value = m_document.createTextNode(QString::number(effectix));
500 e.appendChild(value);
502 for (int j = 0; j < attrs.count(); j++) {
503 QDomAttr a = attrs.item(j).toAttr();
505 kDebug() << " FILTER; adding :" << a.name() << ":" << a.value();
506 QDomElement e = m_document.createElement("property");
507 e.setAttribute("name", a.name());
508 QDomText value = m_document.createTextNode(a.value());
509 e.appendChild(value);
520 QDomNodeList filters = m_document.elementsByTagName("filter");
521 max = filters.count();
524 for (int i = 0; i < max; i++) {
525 QDomElement filt = filters.at(i).toElement();
526 QDomNamedNodeMap attrs = filt.attributes();
527 QString current_id = filt.attribute("kdenlive_id");
528 if (current_id != last_id) {
530 last_id = current_id;
532 QDomElement e = m_document.createElement("property");
533 e.setAttribute("name", "kdenlive_ix");
534 QDomText value = m_document.createTextNode(QString::number(1));
535 e.appendChild(value);
537 for (int j = 0; j < attrs.count(); j++) {
538 QDomAttr a = attrs.item(j).toAttr();
540 kDebug() << " FILTER; adding :" << a.name() << ":" << a.value();
541 QDomElement e = m_document.createElement("property");
542 e.setAttribute("name", a.name());
543 QDomText value = m_document.createTextNode(a.value());
544 e.appendChild(value);
551 QDomNodeList producers = westley.toElement().elementsByTagName("producer");
552 max = producers.count();
553 for (int i = 0; i < max; i++) {
554 QDomElement prod = producers.at(i).toElement();
555 if (prod.attribute("mlt_service") == "framebuffer") {
556 QString slowmotionprod = prod.attribute("resource");
557 slowmotionprod.replace(':', '?');
558 kDebug() << "// FOUND WRONG SLOWMO, new: " << slowmotionprod;
559 prod.setAttribute("resource", slowmotionprod);
562 //Â move producers to correct place, markers to a global list, fix clip descriptions
563 QDomElement markers = m_document.createElement("markers");
564 // This will get the westley producers:
565 producers = m_document.elementsByTagName("producer");
566 max = producers.count();
567 for (int i = 0; i < max; i++) {
568 QDomElement prod = producers.at(0).toElement();
569 // add resource also as a property (to allow path correction in setNewResource())
570 // TODO: will it work with slowmotion? needs testing
571 if (!prod.attribute("resource").isEmpty()) {
572 QDomElement prop_resource = m_document.createElement("property");
573 prop_resource.setAttribute("name", "resource");
574 QDomText resource = m_document.createTextNode(prod.attribute("resource"));
575 prop_resource.appendChild(resource);
576 prod.appendChild(prop_resource);
578 QDomNode m = prod.firstChild();
580 if (m.toElement().tagName() == "markers") {
581 QDomNodeList prodchilds = m.childNodes();
582 int maxchild = prodchilds.count();
583 for (int k = 0; k < maxchild; k++) {
584 QDomElement mark = prodchilds.at(0).toElement();
585 mark.setAttribute("id", prod.attribute("id"));
586 markers.insertAfter(mark, QDomNode());
589 } else if (prod.attribute("type").toInt() == TEXT) {
590 // convert title clip
591 if (m.toElement().tagName() == "textclip") {
593 QDomElement titleclip = m.toElement();
594 QDomElement title = tdoc.createElement("kdenlivetitle");
595 tdoc.appendChild(title);
596 QDomNodeList objects = titleclip.childNodes();
597 int maxchild = objects.count();
598 for (int k = 0; k < maxchild; k++) {
600 QDomElement ob = objects.at(k).toElement();
601 if (ob.attribute("type") == "3") {
602 // text object - all of this goes into "xmldata"...
603 QDomElement item = tdoc.createElement("item");
604 item.setAttribute("z-index", ob.attribute("z"));
605 item.setAttribute("type", "QGraphicsTextItem");
606 QDomElement position = tdoc.createElement("position");
607 position.setAttribute("x", ob.attribute("x"));
608 position.setAttribute("y", ob.attribute("y"));
609 QDomElement content = tdoc.createElement("content");
610 content.setAttribute("font", ob.attribute("font_family"));
611 content.setAttribute("font-size", ob.attribute("font_size"));
612 content.setAttribute("font-bold", ob.attribute("bold"));
613 content.setAttribute("font-italic", ob.attribute("italic"));
614 content.setAttribute("font-underline", ob.attribute("underline"));
615 QString col = ob.attribute("color");
617 content.setAttribute("font-color", colorToString(c));
618 // todo: These fields are missing from the newly generated xmldata:
619 // transform, startviewport, endviewport, background
621 QDomText conttxt = tdoc.createTextNode(ob.attribute("text"));
622 content.appendChild(conttxt);
623 item.appendChild(position);
624 item.appendChild(content);
625 title.appendChild(item);
626 } else if (ob.attribute("type") == "5") {
628 QDomElement item = tdoc.createElement("item");
629 item.setAttribute("z-index", ob.attribute("z"));
630 item.setAttribute("type", "QGraphicsRectItem");
631 QDomElement position = tdoc.createElement("position");
632 position.setAttribute("x", ob.attribute("x"));
633 position.setAttribute("y", ob.attribute("y"));
634 QDomElement content = tdoc.createElement("content");
635 QString col = ob.attribute("color");
637 content.setAttribute("brushcolor", colorToString(c));
638 QString rect = "0,0,";
639 rect.append(ob.attribute("width"));
641 rect.append(ob.attribute("height"));
642 content.setAttribute("rect", rect);
643 item.appendChild(position);
644 item.appendChild(content);
645 title.appendChild(item);
648 prod.setAttribute("xmldata", tdoc.toString());
649 // mbd todo: This clearly does not work, as every title gets the same name - trying to leave it empty
650 // QStringList titleInfo = TitleWidget::getFreeTitleInfo(projectFolder());
651 // prod.setAttribute("titlename", titleInfo.at(0));
652 // prod.setAttribute("resource", titleInfo.at(1));
653 //kDebug()<<"TITLE DATA:\n"<<tdoc.toString();
655 } // End conversion of title clips.
657 } else if (m.isText()) {
658 QString comment = m.nodeValue();
659 if (!comment.isEmpty()) {
660 prod.setAttribute("description", comment);
665 int duration = prod.attribute("duration").toInt();
666 if (duration > 0) prod.setAttribute("out", QString::number(duration));
667 // The clip goes back in, but text clips should not go back in, at least not modified
668 westley.insertBefore(prod, QDomNode());
672 QDomNode westley0 = m_document.elementsByTagName("westley").at(0);
673 if (!markers.firstChild().isNull()) westley0.appendChild(markers);
676 // Convert as much of the kdenlivedoc as possible. Use the producer in westley
677 // First, remove the old stuff from westley, and add a new empty one
678 // Also, track the max id in order to use it for the adding of groups/folders
679 int max_kproducer_id = 0;
680 westley0.removeChild(kdenlivedoc);
681 QDomElement kdenlivedoc_new = m_document.createElement("kdenlivedoc");
682 kdenlivedoc_new.setAttribute("profile", profile);
683 kdenlivedoc_new.setAttribute("tracks", tracksOrder);
684 // Add all the producers that has a ressource in westley
685 QDomElement westley_element = westley0.toElement();
686 if (westley_element.isNull()) {
687 kWarning() << "westley0 element in document was not a QDomElement - unable to add producers to new kdenlivedoc";
689 QDomNodeList wproducers = westley_element.elementsByTagName("producer");
690 int kmax = wproducers.count();
691 for (int i = 0; i < kmax; i++) {
692 QDomElement wproducer = wproducers.at(i).toElement();
693 if (wproducer.isNull()) {
694 kWarning() << "Found producer in westley0, that was not a QDomElement";
696 // We have to do slightly different things, depending on the type
697 kDebug() << "Converting producer element with type" << wproducer.attribute("type");
698 if (wproducer.attribute("type").toInt() == TEXT) {
699 kDebug() << "Found TEXT element in producer" << endl;
700 QDomElement kproducer = wproducer.cloneNode(true).toElement();
701 kproducer.setTagName("kdenlive_producer");
702 kdenlivedoc_new.appendChild(kproducer);
703 // TODO: Perhaps needs some more changes here to "frequency", aspect ratio as a float, frame_size, channels, and later, ressource and title name
705 QDomElement kproducer = m_document.createElement("kdenlive_producer");
706 kproducer.setAttribute("id", wproducer.attribute("id"));
707 if (!wproducer.attribute("description").isEmpty())
708 kproducer.setAttribute("description", wproducer.attribute("description"));
709 kproducer.setAttribute("resource", wproducer.attribute("resource"));
710 kproducer.setAttribute("type", wproducer.attribute("type"));
711 // Testing fix for 358
712 if (!wproducer.attribute("aspect_ratio").isEmpty()) {
713 kproducer.setAttribute("aspect_ratio", wproducer.attribute("aspect_ratio"));
715 if (!wproducer.attribute("source_fps").isEmpty()) {
716 kproducer.setAttribute("fps", wproducer.attribute("source_fps"));
718 if (!wproducer.attribute("length").isEmpty()) {
719 kproducer.setAttribute("duration", wproducer.attribute("length"));
721 kdenlivedoc_new.appendChild(kproducer);
723 if (wproducer.attribute("id").toInt() > max_kproducer_id) {
724 max_kproducer_id = wproducer.attribute("id").toInt();
729 #define LOOKUP_FOLDER 1
731 // Look through all the folder elements of the old doc, for each folder, for each producer,
732 // get the id, look it up in the new doc, set the groupname and groupid
733 // Note, this does not work at the moment - at least one folders shows up missing, and clips with no folder
735 // QDomElement kdenlivedoc_old = kdenlivedoc.toElement();
736 if (!kdenlivedoc_old.isNull()) {
737 QDomNodeList folders = kdenlivedoc_old.elementsByTagName("folder");
738 int fsize = folders.size();
739 int groupId = max_kproducer_id + 1; // Start at +1 of max id of the kdenlive_producers
740 for (int i = 0; i < fsize; ++i) {
741 QDomElement folder = folders.at(i).toElement();
742 if (!folder.isNull()) {
743 QString groupName = folder.attribute("name");
744 kDebug() << "groupName: " << groupName << " with groupId: " << groupId;
745 QDomNodeList fproducers = folder.elementsByTagName("producer");
746 int psize = fproducers.size();
747 for (int j = 0; j < psize; ++j) {
748 QDomElement fproducer = fproducers.at(j).toElement();
749 if (!fproducer.isNull()) {
750 QString id = fproducer.attribute("id");
751 // This is not very effective, but compared to loading the clips, its a breeze
752 QDomNodeList kdenlive_producers = kdenlivedoc_new.elementsByTagName("kdenlive_producer");
753 int kpsize = kdenlive_producers.size();
754 for (int k = 0; k < kpsize; ++k) {
755 QDomElement kproducer = kdenlive_producers.at(k).toElement(); // Its an element for sure
756 if (id == kproducer.attribute("id")) {
757 // We do not check that it already is part of a folder
758 kproducer.setAttribute("groupid", groupId);
759 kproducer.setAttribute("groupname", groupName);
770 westley0.appendChild(kdenlivedoc_new);
772 QDomNodeList elements = westley.childNodes();
773 max = elements.count();
774 for (int i = 0; i < max; i++) {
775 QDomElement prod = elements.at(0).toElement();
776 westley0.insertAfter(prod, QDomNode());
779 westley0.removeChild(westley);
781 // experimental and probably slow
782 // adds <avfile /> information to <kdenlive_producer />
783 QDomNodeList kproducers = m_document.elementsByTagName("kdenlive_producer");
784 QDomNodeList avfiles = kdenlivedoc_old.elementsByTagName("avfile");
785 kDebug() << "found" << avfiles.count() << "<avfile />s and" << kproducers.count() << "<kdenlive_producer />s";
786 for (int i = 0; i < avfiles.count(); ++i) {
787 QDomElement avfile = avfiles.at(i).toElement();
788 QDomElement kproducer = QDomElement();
790 kWarning() << "found an <avfile /> that is not a QDomElement";
792 QString id = avfile.attribute("id");
793 // this is horrible, must be rewritten, it's just for test
794 for (int j = 0; j < kproducers.count(); ++j) {
795 //kDebug() << "checking <kdenlive_producer /> with id" << kproducers.at(j).toElement().attribute("id");
796 if (kproducers.at(j).toElement().attribute("id") == id) {
797 kproducer = kproducers.at(j).toElement();
801 if (kproducer == QDomElement())
802 kWarning() << "no match for <avfile /> with id =" << id;
804 //kDebug() << "ready to set additional <avfile />'s attributes (id =" << id << ")";
805 kproducer.setAttribute("channels", avfile.attribute("channels"));
806 kproducer.setAttribute("duration", avfile.attribute("duration"));
807 kproducer.setAttribute("frame_size", avfile.attribute("width") + "x" + avfile.attribute("height"));
808 kproducer.setAttribute("frequency", avfile.attribute("frequency"));
809 if (kproducer.attribute("description").isEmpty() && !avfile.attribute("description").isEmpty())
810 kproducer.setAttribute("description", avfile.attribute("description"));
815 //kDebug() << "///////////////// CONVERTEDÂ DOC:";
816 //kDebug() << m_document.toString();
818 QFile file( "converted.kdenlive" );
819 if ( file.open( QIODevice::WriteOnly ) ) {
820 QTextStream stream( &file );
821 stream << m_document.toString();
824 kDebug() << "Unable to dump file to converted.kdenlive";
827 //kDebug() << "///////////////// END CONVERTEDÂ DOC:";
832 QString KdenliveDoc::colorToString(const QColor& c) {
833 QString ret = "%1,%2,%3,%4";
834 ret = ret.arg(c.red()).arg(c.green()).arg(c.blue()).arg(c.alpha());
838 bool KdenliveDoc::saveSceneList(const QString &path, QDomDocument sceneList) {
839 QDomNode wes = sceneList.elementsByTagName("westley").at(0);
841 QDomElement addedXml = sceneList.createElement("kdenlivedoc");
842 QDomElement markers = sceneList.createElement("markers");
843 addedXml.setAttribute("version", "0.8");
844 addedXml.setAttribute("profile", profilePath());
845 addedXml.setAttribute("position", m_render->seekPosition().frames(m_fps));
846 addedXml.setAttribute("projectfolder", m_projectFolder.path());
847 addedXml.setAttribute("tracks", getTracksInfo());
848 addedXml.setAttribute("zoom", m_zoom);
851 QList <DocClipBase*> list = m_clipManager->documentClipList();
852 for (int i = 0; i < list.count(); i++) {
853 e = list.at(i)->toXML();
854 e.setTagName("kdenlive_producer");
855 addedXml.appendChild(sceneList.importNode(e, true));
856 QList < CommentedTime > marks = list.at(i)->commentedSnapMarkers();
857 for (int j = 0; j < marks.count(); j++) {
858 QDomElement marker = sceneList.createElement("marker");
859 marker.setAttribute("time", marks.at(j).time().ms() / 1000);
860 marker.setAttribute("comment", marks.at(j).comment());
861 marker.setAttribute("id", e.attribute("id"));
862 markers.appendChild(marker);
865 addedXml.appendChild(markers);
866 if (!m_guidesXml.isNull()) addedXml.appendChild(sceneList.importNode(m_guidesXml, true));
868 wes.appendChild(addedXml);
869 //wes.appendChild(doc.importNode(kdenliveData, true));
872 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
873 kWarning() << "////// ERROR writing to file: " << path;
874 KMessageBox::error(kapp->activeWindow(), i18n("Cannot write to file %1", path));
877 QTextStream out(&file);
878 out << sceneList.toString();
883 ClipManager *KdenliveDoc::clipManager() {
884 return m_clipManager;
887 KUrl KdenliveDoc::projectFolder() const {
888 //if (m_projectFolder.isEmpty()) return KUrl(KStandardDirs::locateLocal("appdata", "/projects/"));
889 return m_projectFolder;
892 void KdenliveDoc::setProjectFolder(KUrl url) {
893 if (url == m_projectFolder) return;
895 KStandardDirs::makeDir(url.path());
896 KStandardDirs::makeDir(url.path() + "/titles/");
897 KStandardDirs::makeDir(url.path() + "/thumbs/");
898 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);
899 m_projectFolder = url;
902 void KdenliveDoc::moveProjectData(KUrl url) {
903 QList <DocClipBase*> list = m_clipManager->documentClipList();
904 for (int i = 0; i < list.count(); i++) {
905 DocClipBase *clip = list.at(i);
906 if (clip->clipType() == TEXT) {
907 // the image for title clip must be moved
908 KUrl oldUrl = clip->fileURL();
909 KUrl newUrl = KUrl(url.path() + "/titles/" + oldUrl.fileName());
910 KIO::Job *job = KIO::copy(oldUrl, newUrl);
911 if (KIO::NetAccess::synchronousRun(job, 0)) clip->setProperty("resource", newUrl.path());
913 QString hash = clip->getClipHash();
914 KUrl oldVideoThumbUrl = KUrl(m_projectFolder.path() + "/thumbs/" + hash + ".png");
915 KUrl oldAudioThumbUrl = KUrl(m_projectFolder.path() + "/thumbs/" + hash + ".thumb");
916 if (KIO::NetAccess::exists(oldVideoThumbUrl, KIO::NetAccess::SourceSide, 0)) {
917 KUrl newUrl = KUrl(url.path() + "/thumbs/" + hash + ".png");
918 KIO::Job *job = KIO::copy(oldVideoThumbUrl, newUrl);
919 KIO::NetAccess::synchronousRun(job, 0);
921 if (KIO::NetAccess::exists(oldAudioThumbUrl, KIO::NetAccess::SourceSide, 0)) {
922 KUrl newUrl = KUrl(url.path() + "/thumbs/" + hash + ".thumb");
923 KIO::Job *job = KIO::copy(oldAudioThumbUrl, newUrl);
924 if (KIO::NetAccess::synchronousRun(job, 0)) clip->refreshThumbUrl();
929 QString KdenliveDoc::profilePath() const {
930 return m_profile.path;
933 MltVideoProfile KdenliveDoc::mltProfile() const {
937 void KdenliveDoc::setProfilePath(QString path) {
938 if (path.isEmpty()) path = KdenliveSettings::default_profile();
939 if (path.isEmpty()) path = "dv_pal";
940 m_profile = ProfilesDialog::getVideoProfile(path);
941 KdenliveSettings::setProject_display_ratio((double) m_profile.display_aspect_num / m_profile.display_aspect_den);
942 m_fps = (double) m_profile.frame_rate_num / m_profile.frame_rate_den;
943 m_width = m_profile.width;
944 m_height = m_profile.height;
945 kDebug() << "KDEnnlive document, init timecode from path: " << path << ", " << m_fps;
946 if (m_fps == 30000.0 / 1001.0) m_timecode.setFormat(30, true);
947 else m_timecode.setFormat((int) m_fps);
950 const double KdenliveDoc::dar() {
951 return (double) m_profile.display_aspect_num / m_profile.display_aspect_den;
954 void KdenliveDoc::setThumbsProgress(const QString &message, int progress) {
955 emit progressInfo(message, progress);
958 void KdenliveDoc::loadingProgressed() {
959 m_documentLoadingProgress += m_documentLoadingStep;
960 emit progressInfo(QString(), (int) m_documentLoadingProgress);
963 QUndoStack *KdenliveDoc::commandStack() {
964 return m_commandStack;
967 void KdenliveDoc::setRenderer(Render *render) {
968 if (m_render) return;
970 emit progressInfo(i18n("Loading playlist..."), 0);
971 //qApp->processEvents();
973 m_render->setSceneList(m_document.toString(), m_startPos);
974 kDebug() << "// SETTING SCENE LIST:\n\n" << m_document.toString();
977 emit progressInfo(QString(), -1);
980 void KdenliveDoc::checkProjectClips() {
981 if (m_render == NULL) return;
982 QList <Mlt::Producer *> prods = m_render->producersList();
986 for (int i = 0; i < prods.count(); i++) {
987 id = prods.at(i)->get("id");
988 prodId = id.section('_', 0, 0);
989 prodTrack = id.section('_', 1, 1);
990 DocClipBase *clip = m_clipManager->getClipById(prodId);
991 if (clip) clip->setProducer(prods.at(i));
992 if (clip && clip->clipType() == TEXT && !QFile::exists(clip->fileURL().path())) {
993 // regenerate text clip image if required
994 kDebug() << "// TITLE: " << clip->getProperty("titlename") << " Preview file: " << clip->getProperty("resource") << " DOES NOT EXIST";
995 QString titlename = clip->getProperty("titlename");
996 QString titleresource;
997 if (titlename.isEmpty()) {
998 QStringList titleInfo = TitleWidget::getFreeTitleInfo(projectFolder());
999 titlename = titleInfo.at(0);
1000 titleresource = titleInfo.at(1);
1001 clip->setProperty("titlename", titlename);
1002 kDebug() << "// New title set to: " << titlename;
1004 titleresource = TitleWidget::getTitleResourceFromName(projectFolder(), titlename);
1006 QString titlepath = projectFolder().path() + "/titles/";
1007 TitleWidget *dia_ui = new TitleWidget(KUrl(), titlepath, m_render, kapp->activeWindow());
1009 doc.setContent(clip->getProperty("xmldata"));
1010 dia_ui->setXml(doc);
1011 QPixmap pix = dia_ui->renderedPixmap();
1012 pix.save(titleresource);
1013 clip->setProperty("resource", titleresource);
1015 clip->producer()->set("force_reload", 1);
1020 Render *KdenliveDoc::renderer() {
1024 void KdenliveDoc::updateClip(const QString &id) {
1025 emit updateClipDisplay(id);
1028 int KdenliveDoc::getFramePos(QString duration) {
1029 return m_timecode.getFrameCount(duration, m_fps);
1032 QString KdenliveDoc::producerName(const QString &id) {
1033 QString result = "unnamed";
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 result = e.attribute("name");
1040 if (result.isEmpty()) result = KUrl(e.attribute("resource")).fileName();
1047 void KdenliveDoc::setProducerDuration(const QString &id, int duration) {
1048 QDomNodeList prods = producersList();
1049 int ct = prods.count();
1050 for (int i = 0; i < ct ; i++) {
1051 QDomElement e = prods.item(i).toElement();
1052 if (e.attribute("id") != "black" && e.attribute("id") == id) {
1053 e.setAttribute("duration", QString::number(duration));
1059 int KdenliveDoc::getProducerDuration(const QString &id) {
1061 QDomNodeList prods = producersList();
1062 int ct = prods.count();
1063 for (int i = 0; i < ct ; i++) {
1064 QDomElement e = prods.item(i).toElement();
1065 if (e.attribute("id") != "black" && e.attribute("id") == id) {
1066 result = e.attribute("duration").toInt();
1074 QDomDocument KdenliveDoc::generateSceneList() {
1076 QDomElement westley = doc.createElement("westley");
1077 doc.appendChild(westley);
1078 QDomElement prod = doc.createElement("producer");
1081 QDomDocument KdenliveDoc::toXml() const {
1085 Timecode KdenliveDoc::timecode() const {
1089 QDomNodeList KdenliveDoc::producersList() {
1090 return m_document.elementsByTagName("producer");
1093 void KdenliveDoc::backupMltPlaylist() {
1094 if (m_render) m_scenelist = m_render->sceneList();
1097 double KdenliveDoc::projectDuration() const {
1098 if (m_render) return GenTime(m_render->getLength(), m_fps).ms() / 1000;
1101 double KdenliveDoc::fps() const {
1105 int KdenliveDoc::width() const {
1109 int KdenliveDoc::height() const {
1113 KUrl KdenliveDoc::url() const {
1117 void KdenliveDoc::setUrl(KUrl url) {
1121 void KdenliveDoc::setModified(bool mod) {
1122 if (!m_url.isEmpty() && mod && KdenliveSettings::crashrecovery()) {
1123 m_autoSaveTimer->start(3000);
1125 if (mod == m_modified) return;
1127 emit docModified(m_modified);
1130 bool KdenliveDoc::isModified() const {
1134 QString KdenliveDoc::description() const {
1135 if (m_url.isEmpty())
1136 return i18n("Untitled") + " / " + m_profile.description;
1138 return m_url.fileName() + " / " + m_profile.description;
1141 void KdenliveDoc::addClip(QDomElement elem, QString clipId, bool createClipItem) {
1142 const QString producerId = clipId.section('_', 0, 0);
1143 int subtrack = clipId.section('_', 1, 1).toInt();
1144 DocClipBase *clip = m_clipManager->getClipById(producerId);
1146 elem.setAttribute("id", producerId);
1147 QString path = elem.attribute("resource");
1149 if (elem.attribute("type").toInt() == SLIDESHOW) {
1150 extension = KUrl(path).fileName();
1151 path = KUrl(path).directory();
1153 if (!path.isEmpty() && !QFile::exists(path)) {
1154 const QString size = elem.attribute("file_size");
1155 const QString hash = elem.attribute("file_hash");
1157 KMessageBox::ButtonCode action = KMessageBox::No;
1158 if (!size.isEmpty() && !hash.isEmpty()) {
1159 if (!m_searchFolder.isEmpty()) newpath = searchFileRecursively(m_searchFolder, size, hash);
1160 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")));
1162 if (elem.attribute("type").toInt() == SLIDESHOW) {
1163 if (KMessageBox::messageBox(kapp->activeWindow(), KMessageBox::WarningYesNo, i18n("<qt>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("Remove from project")),*/ KGuiItem(i18n("Keep as placeholder"))) == KMessageBox::Yes)
1164 newpath = KFileDialog::getExistingDirectory(KUrl("kfiledialog:///clipfolder"), kapp->activeWindow(), i18n("Looking for %1", path));
1165 } else if (KMessageBox::messageBox(kapp->activeWindow(), KMessageBox::WarningYesNo, i18n("<qt>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("Remove from project")),*/ KGuiItem(i18n("Keep as placeholder"))) == KMessageBox::Yes)
1166 newpath = KFileDialog::getOpenFileName(KUrl("kfiledialog:///clipfolder"), QString(), kapp->activeWindow(), i18n("Looking for %1", path));
1168 if (action == KMessageBox::Yes) {
1169 kDebug() << "// ASKED FOR SRCH CLIP: " << clipId;
1170 m_searchFolder = KFileDialog::getExistingDirectory(KUrl("kfiledialog:///clipfolder"), kapp->activeWindow());
1171 if (!m_searchFolder.isEmpty()) {
1172 newpath = searchFileRecursively(QDir(m_searchFolder), size, hash);
1175 if (!newpath.isEmpty()) {
1176 if (elem.attribute("type").toInt() == SLIDESHOW) newpath.append('/' + extension);
1177 elem.setAttribute("resource", newpath);
1178 setNewClipResource(clipId, newpath);
1182 clip = new DocClipBase(m_clipManager, elem, producerId);
1183 m_clipManager->addClip(clip);
1185 if (createClipItem) emit addProjectClip(clip);
1188 void KdenliveDoc::setNewClipResource(const QString &id, const QString &path) {
1189 QDomNodeList prods = m_document.elementsByTagName("producer");
1190 int maxprod = prods.count();
1191 for (int i = 0; i < maxprod; i++) {
1192 QDomNode m = prods.at(i);
1193 QString prodId = m.toElement().attribute("id");
1194 if (prodId == id || prodId.startsWith(id + "_")) {
1195 QDomNodeList params = m.childNodes();
1196 for (int j = 0; j < params.count(); j++) {
1197 QDomElement e = params.item(j).toElement();
1198 if (e.attribute("name") == "resource") {
1199 e.firstChild().setNodeValue(path);
1207 QString KdenliveDoc::searchFileRecursively(const QDir &dir, const QString &matchSize, const QString &matchHash) const {
1208 QString foundFileName;
1209 QByteArray fileData;
1210 QByteArray fileHash;
1211 QStringList filesAndDirs = dir.entryList(QDir::Files | QDir::Readable);
1212 for (int i = 0; i < filesAndDirs.size() && foundFileName.isEmpty(); i++) {
1213 QFile file(dir.absoluteFilePath(filesAndDirs.at(i)));
1214 if (file.open(QIODevice::ReadOnly)) {
1215 if (QString::number(file.size()) == matchSize) {
1217 * 1 MB = 1 second per 450 files (or faster)
1218 * 10 MB = 9 seconds per 450 files (or faster)
1220 if (file.size() > 1000000*2) {
1221 fileData = file.read(1000000);
1222 if (file.seek(file.size() - 1000000))
1223 fileData.append(file.readAll());
1225 fileData = file.readAll();
1227 fileHash = QCryptographicHash::hash(fileData, QCryptographicHash::Md5);
1228 if (QString(fileHash.toHex()) == matchHash)
1229 return file.fileName();
1232 kDebug() << filesAndDirs.at(i) << file.size() << fileHash.toHex();
1234 filesAndDirs = dir.entryList(QDir::Dirs | QDir::Readable | QDir::Executable | QDir::NoDotAndDotDot);
1235 for (int i = 0; i < filesAndDirs.size() && foundFileName.isEmpty(); i++) {
1236 foundFileName = searchFileRecursively(dir.absoluteFilePath(filesAndDirs.at(i)), matchSize, matchHash);
1237 if (!foundFileName.isEmpty())
1240 return foundFileName;
1243 void KdenliveDoc::addClipInfo(QDomElement elem, QString clipId) {
1244 DocClipBase *clip = m_clipManager->getClipById(clipId);
1246 addClip(elem, clipId);
1248 QMap <QString, QString> properties;
1249 QDomNamedNodeMap attributes = elem.attributes();
1251 for (unsigned int i = 0; i < attributes.count(); i++) {
1252 attrname = attributes.item(i).nodeName();
1253 if (attrname != "resource")
1254 properties.insert(attrname, attributes.item(i).nodeValue());
1255 kDebug() << attrname << " = " << attributes.item(i).nodeValue();
1257 clip->setProperties(properties);
1258 emit addProjectClip(clip, false);
1262 void KdenliveDoc::addFolder(const QString foldername, const QString &clipId, bool edit) {
1263 emit addProjectFolder(foldername, clipId, false, edit);
1266 void KdenliveDoc::deleteFolder(const QString foldername, const QString &clipId) {
1267 emit addProjectFolder(foldername, clipId, true);
1270 void KdenliveDoc::deleteProjectClip(QList <QString> ids) {
1271 for (int i = 0; i < ids.size(); ++i) {
1272 emit deleteTimelineClip(ids.at(i));
1273 m_clipManager->slotDeleteClip(ids.at(i));
1278 void KdenliveDoc::deleteProjectFolder(QMap <QString, QString> map) {
1279 QMapIterator<QString, QString> i(map);
1280 while (i.hasNext()) {
1282 slotDeleteFolder(i.key(), i.value());
1287 void KdenliveDoc::deleteClip(const QString &clipId) {
1288 emit signalDeleteProjectClip(clipId);
1289 m_clipManager->deleteClip(clipId);
1292 void KdenliveDoc::slotAddClipList(const KUrl::List urls, const QString group, const QString &groupId) {
1293 m_clipManager->slotAddClipList(urls, group, groupId);
1294 emit selectLastAddedClip(QString::number(m_clipManager->lastClipId()));
1299 void KdenliveDoc::slotAddClipFile(const KUrl url, const QString group, const QString &groupId) {
1300 kDebug() << "///////// DOCUM, ADD CLP: " << url;
1301 m_clipManager->slotAddClipFile(url, group, groupId);
1302 emit selectLastAddedClip(QString::number(m_clipManager->lastClipId()));
1306 void KdenliveDoc::slotAddFolder(const QString folderName) {
1307 AddFolderCommand *command = new AddFolderCommand(this, folderName, QString::number(m_clipManager->getFreeClipId()), true);
1308 commandStack()->push(command);
1312 void KdenliveDoc::slotDeleteFolder(const QString folderName, const QString &id) {
1313 AddFolderCommand *command = new AddFolderCommand(this, folderName, id, false);
1314 commandStack()->push(command);
1318 void KdenliveDoc::slotEditFolder(const QString newfolderName, const QString oldfolderName, const QString &clipId) {
1319 EditFolderCommand *command = new EditFolderCommand(this, newfolderName, oldfolderName, clipId, false);
1320 commandStack()->push(command);
1324 const QString&KdenliveDoc::getFreeClipId() {
1325 return QString::number(m_clipManager->getFreeClipId());
1328 DocClipBase *KdenliveDoc::getBaseClip(const QString &clipId) {
1329 return m_clipManager->getClipById(clipId);
1332 void KdenliveDoc::slotAddColorClipFile(const QString name, const QString color, QString duration, const QString group, const QString &groupId) {
1333 m_clipManager->slotAddColorClipFile(name, color, duration, group, groupId);
1337 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) {
1338 m_clipManager->slotAddSlideshowClipFile(name, path, count, duration, loop, fade, luma_duration, luma_file, softness, group, groupId);
1342 void KdenliveDoc::slotCreateTextClip(QString group, const QString &groupId) {
1343 QString titlesFolder = projectFolder().path() + "/titles/";
1344 KStandardDirs::makeDir(titlesFolder);
1345 TitleWidget *dia_ui = new TitleWidget(KUrl(), titlesFolder, m_render, kapp->activeWindow());
1346 if (dia_ui->exec() == QDialog::Accepted) {
1347 QStringList titleInfo = TitleWidget::getFreeTitleInfo(projectFolder());
1348 QPixmap pix = dia_ui->renderedPixmap();
1349 pix.save(titleInfo.at(1));
1350 //dia_ui->saveTitle(path + ".kdenlivetitle");
1351 m_clipManager->slotAddTextClipFile(titleInfo.at(0), titleInfo.at(1), dia_ui->xml().toString(), QString(), QString());
1357 int KdenliveDoc::tracksCount() const {
1358 return m_tracksList.count();
1361 TrackInfo KdenliveDoc::trackInfoAt(int ix) const {
1362 return m_tracksList.at(ix);
1365 void KdenliveDoc::switchTrackAudio(int ix, bool hide) {
1366 m_tracksList[ix].isMute = hide; // !m_tracksList.at(ix).isMute;
1369 void KdenliveDoc::switchTrackVideo(int ix, bool hide) {
1370 m_tracksList[ix].isBlind = hide; // !m_tracksList.at(ix).isBlind;
1373 void KdenliveDoc::insertTrack(int ix, TrackInfo type) {
1374 if (ix == -1) m_tracksList << type;
1375 else m_tracksList.insert(ix, type);
1378 void KdenliveDoc::deleteTrack(int ix) {
1379 m_tracksList.removeAt(ix);
1382 void KdenliveDoc::setTrackType(int ix, TrackInfo type) {
1383 m_tracksList[ix].type = type.type;
1384 m_tracksList[ix].isMute = type.isMute;
1385 m_tracksList[ix].isBlind = type.isBlind;
1388 const QList <TrackInfo> KdenliveDoc::tracksList() const {
1389 return m_tracksList;
1392 QPoint KdenliveDoc::getTracksCount() const {
1395 foreach(const TrackInfo &info, m_tracksList) {
1396 if (info.type == VIDEOTRACK) video++;
1399 return QPoint(video, audio);
1402 QString KdenliveDoc::getTracksInfo() const {
1404 foreach(const TrackInfo &info, m_tracksList) {
1405 if (info.type == VIDEOTRACK) result.append('v');
1406 else result.append('a');
1411 void KdenliveDoc::cachePixmap(const QString &fileId, const QPixmap &pix) const {
1412 pix.save(m_projectFolder.path() + "/thumbs/" + fileId + ".png");
1415 #include "kdenlivedoc.moc"