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"
46 KdenliveDoc::KdenliveDoc(const KUrl &url, const KUrl &projectFolder, QUndoGroup *undoGroup, const QString &profileName, const QPoint tracks, Render *render, MainWindow *parent): QObject(parent), m_render(render), 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), m_zoneStart(0), m_zoneEnd(100) {
47 m_clipManager = new ClipManager(this);
48 m_autoSaveTimer = new QTimer(this);
49 m_autoSaveTimer->setSingleShot(true);
52 if (KIO::NetAccess::download(url.path(), tmpFile, parent)) {
54 m_document.setContent(&file, false);
56 QDomNode infoXmlNode = m_document.elementsByTagName("kdenlivedoc").at(0);
57 QDomNode westley = m_document.elementsByTagName("westley").at(0);
58 if (!infoXmlNode.isNull()) {
59 QDomElement infoXml = infoXmlNode.toElement();
60 double version = infoXml.attribute("version").toDouble();
62 // Upgrade old Kdenlive documents to current version
63 if (!convertDocument(version)) {
64 KMessageBox::sorry(parent, i18n("This project type is unsupported and can't be loaded."), i18n("Unable to open project"));
65 m_document = createEmptyDocument(tracks.x(), tracks.y());
66 setProfilePath(profileName);
69 * read again <kdenlivedoc> and <westley> to get all the new
70 * stuff (convertDocument() can now do anything without breaking
73 infoXmlNode = m_document.elementsByTagName("kdenlivedoc").at(0);
74 infoXml = infoXmlNode.toElement();
75 version = infoXml.attribute("version").toDouble();
76 westley = m_document.elementsByTagName("westley").at(0);
78 QString profilePath = infoXml.attribute("profile");
79 QString projectFolderPath = infoXml.attribute("projectfolder");
80 if (!projectFolderPath.isEmpty()) m_projectFolder = KUrl(projectFolderPath);
81 if (m_projectFolder.isEmpty()) m_projectFolder = KUrl(KdenliveSettings::defaultprojectfolder());
82 m_startPos = infoXml.attribute("position").toInt();
83 m_zoom = infoXml.attribute("zoom", "7").toInt();
84 m_zoneStart = infoXml.attribute("zonein", "0").toInt();
85 m_zoneEnd = infoXml.attribute("zoneout", "100").toInt();
86 setProfilePath(profilePath);
89 QString tracks = infoXml.attribute("tracks");
91 videoTrack.type = VIDEOTRACK;
92 videoTrack.isMute = false;
93 videoTrack.isBlind = false;
96 audioTrack.type = AUDIOTRACK;
97 audioTrack.isMute = false;
98 audioTrack.isBlind = true;
99 for (int i = 0; i < tracks.size(); i++) {
100 if (tracks.data()[i] == 'v') m_tracksList.append(videoTrack);
101 else m_tracksList.append(audioTrack);
106 QDomNodeList producers = m_document.elementsByTagName("producer");
107 QDomNodeList infoproducers = m_document.elementsByTagName("kdenlive_producer");
108 const int max = producers.count();
109 const int infomax = infoproducers.count();
112 m_documentLoadingStep = 100.0 / (max + infomax + m_document.elementsByTagName("entry").count());
113 parent->slotGotProgressInfo(i18n("Loading project clips"), (int) m_documentLoadingProgress);
116 for (int i = 0; i < max; i++) {
117 e = producers.item(i).cloneNode().toElement();
118 if (m_documentLoadingStep > 0) {
119 m_documentLoadingProgress += m_documentLoadingStep;
120 parent->slotGotProgressInfo(QString(), (int) m_documentLoadingProgress);
121 //qApp->processEvents();
123 QString prodId = e.attribute("id");
124 if (!e.isNull() && prodId != "black" && !prodId.startsWith("slowmotion")/*&& prodId.toInt() > 0*/) {
125 // addClip(e, prodId, false);
126 kDebug() << "// PROD: " << prodId;
130 for (int i = 0; i < infomax; i++) {
131 e = infoproducers.item(i).cloneNode().toElement();
132 if (m_documentLoadingStep > 0) {
133 m_documentLoadingProgress += m_documentLoadingStep;
134 parent->slotGotProgressInfo(QString(), (int) m_documentLoadingProgress);
135 //qApp->processEvents();
137 QString prodId = e.attribute("id");
138 if (!e.isNull() && prodId != "black" && !prodId.startsWith("slowmotion")) {
139 e.setTagName("producer");
140 addClipInfo(e, prodId);
141 kDebug() << "// NLIVE PROD: " << prodId;
145 QDomNode markers = m_document.elementsByTagName("markers").at(0);
146 if (!markers.isNull()) {
147 QDomNodeList markerslist = markers.childNodes();
148 int maxchild = markerslist.count();
149 for (int k = 0; k < maxchild; k++) {
150 e = markerslist.at(k).toElement();
151 if (e.tagName() == "marker") {
152 m_clipManager->getClipById(e.attribute("id"))->addSnapMarker(GenTime(e.attribute("time").toDouble()), e.attribute("comment"));
155 westley.removeChild(markers);
157 m_document.removeChild(infoXmlNode);
159 kDebug() << "Reading file: " << url.path() << ", found clips: " << producers.count();
162 parent->slotGotProgressInfo(i18n("File %1 is not a Kdenlive project file."), 100);
163 kWarning() << " NO KDENLIVE INFO FOUND IN FILE: " << url.path();
164 m_document = createEmptyDocument(tracks.x(), tracks.y());
165 setProfilePath(profileName);
167 KIO::NetAccess::removeTempFile(tmpFile);
169 KMessageBox::error(parent, KIO::NetAccess::lastErrorString());
170 parent->slotGotProgressInfo(i18n("File %1 is not a Kdenlive project file."), 100);
171 m_document = createEmptyDocument(tracks.x(), tracks.y());
172 setProfilePath(profileName);
175 m_document = createEmptyDocument(tracks.x(), tracks.y());
176 setProfilePath(profileName);
178 if (m_projectFolder.isEmpty()) m_projectFolder = KUrl(KdenliveSettings::defaultprojectfolder());
180 // make sure that the necessary folders exist
181 KStandardDirs::makeDir(m_projectFolder.path() + "/titles/");
182 KStandardDirs::makeDir(m_projectFolder.path() + "/thumbs/");
183 KStandardDirs::makeDir(m_projectFolder.path() + "/ladspa/");
185 m_scenelist = m_document.toString();
186 kDebug() << "KDEnnlive document, init timecode: " << m_fps;
187 if (m_fps == 30000.0 / 1001.0) m_timecode.setFormat(30, true);
188 else m_timecode.setFormat((int) m_fps);
190 m_render->setSceneList(m_document.toString(), m_startPos);
191 //kDebug() << "// SETTING SCENE LIST:\n\n" << m_document.toString();
194 connect(m_autoSaveTimer, SIGNAL(timeout()), this, SLOT(slotAutoSave()));
198 KdenliveDoc::~KdenliveDoc() {
199 delete m_commandStack;
200 delete m_clipManager;
201 delete m_autoSaveTimer;
203 m_autosave->remove();
208 QDomDocument KdenliveDoc::createEmptyDocument(const int videotracks, const int audiotracks) {
209 // Creating new document
211 QDomElement westley = doc.createElement("westley");
212 doc.appendChild(westley);
215 TrackInfo videoTrack;
216 videoTrack.type = VIDEOTRACK;
217 videoTrack.isMute = false;
218 videoTrack.isBlind = false;
220 TrackInfo audioTrack;
221 audioTrack.type = AUDIOTRACK;
222 audioTrack.isMute = false;
223 audioTrack.isBlind = true;
225 QDomElement tractor = doc.createElement("tractor");
226 tractor.setAttribute("id", "maintractor");
227 QDomElement multitrack = doc.createElement("multitrack");
228 QDomElement playlist = doc.createElement("playlist");
229 playlist.setAttribute("id", "black_track");
230 westley.appendChild(playlist);
234 int total = audiotracks + videotracks + 1;
236 for (int i = 1; i < total; i++) {
237 QDomElement playlist = doc.createElement("playlist");
238 playlist.setAttribute("id", "playlist" + QString::number(i));
239 westley.appendChild(playlist);
242 QDomElement track0 = doc.createElement("track");
243 track0.setAttribute("producer", "black_track");
244 tractor.appendChild(track0);
246 // create audio tracks
247 for (int i = 1; i < audiotracks + 1; i++) {
248 QDomElement track = doc.createElement("track");
249 track.setAttribute("producer", "playlist" + QString::number(i));
250 track.setAttribute("hide", "video");
251 tractor.appendChild(track);
252 m_tracksList.append(audioTrack);
255 // create video tracks
256 for (int i = audiotracks + 1; i < total; i++) {
257 QDomElement track = doc.createElement("track");
258 track.setAttribute("producer", "playlist" + QString::number(i));
259 tractor.appendChild(track);
260 m_tracksList.append(videoTrack);
263 for (uint i = 2; i < total ; i++) {
264 QDomElement transition = doc.createElement("transition");
265 transition.setAttribute("always_active", "1");
267 QDomElement property = doc.createElement("property");
268 property.setAttribute("name", "a_track");
269 QDomText value = doc.createTextNode(QString::number(1));
270 property.appendChild(value);
271 transition.appendChild(property);
273 property = doc.createElement("property");
274 property.setAttribute("name", "b_track");
275 value = doc.createTextNode(QString::number(i));
276 property.appendChild(value);
277 transition.appendChild(property);
279 property = doc.createElement("property");
280 property.setAttribute("name", "mlt_service");
281 value = doc.createTextNode("mix");
282 property.appendChild(value);
283 transition.appendChild(property);
285 property = doc.createElement("property");
286 property.setAttribute("name", "combine");
287 value = doc.createTextNode("1");
288 property.appendChild(value);
289 transition.appendChild(property);
291 property = doc.createElement("property");
292 property.setAttribute("name", "internal_added");
293 value = doc.createTextNode("237");
294 property.appendChild(value);
295 transition.appendChild(property);
296 tractor.appendChild(transition);
298 westley.appendChild(tractor);
303 void KdenliveDoc::syncGuides(QList <Guide *> guides) {
307 m_guidesXml = doc.createElement("guides");
309 for (int i = 0; i < guides.count(); i++) {
310 e = doc.createElement("guide");
311 e.setAttribute("time", guides.at(i)->position().ms() / 1000);
312 e.setAttribute("comment", guides.at(i)->label());
313 m_guidesXml.appendChild(e);
315 emit guidesUpdated();
318 QDomElement KdenliveDoc::guidesXml() const {
322 void KdenliveDoc::slotAutoSave() {
323 if (m_render && m_autosave) {
324 if (!m_autosave->isOpen() && !m_autosave->open(QIODevice::ReadWrite)) {
325 // show error: could not open the autosave file
326 kDebug() << "ERROR; CANNOT CREATE AUTOSAVE FILE";
328 kDebug() << "// AUTOSAVE FILE: " << m_autosave->fileName();
330 doc.setContent(m_render->sceneList());
331 saveSceneList(m_autosave->fileName(), doc);
335 void KdenliveDoc::setZoom(int factor) {
339 int KdenliveDoc::zoom() const {
343 bool KdenliveDoc::convertDocument(double version) {
344 kDebug() << "Opening a document with version " << version;
346 if (version == 0.81) return true;
348 // Opening a old Kdenlive document
349 if (version == 0.5 || version == 0.7 || version > 0.81) {
350 kDebug() << "Unable to open document with version " << version;
351 // TODO: convert 0.7 (0.5?) files to the new document format.
355 if (version == 0.8) {
356 // Add the tracks information
358 QDomNodeList tracks = m_document.elementsByTagName("track");
359 int max = tracks.count();
360 for (int i = 0; i < max; i++) {
361 QDomElement t = tracks.at(i).toElement();
362 if (t.attribute("hide") == "video")
363 tracksOrder.append('a');
364 else if (t.attribute("producer") != "black_track")
365 tracksOrder.append('v');
367 QDomNode kdenlivedoc = m_document.elementsByTagName("kdenlivedoc").at(0);
368 QDomElement infoXml = kdenlivedoc.toElement();
369 QString currentTrackOrder = infoXml.attribute("tracks");
370 if (currentTrackOrder.isEmpty()) infoXml.setAttribute("tracks", tracksOrder);
375 QDomNode westley = m_document.elementsByTagName("westley").at(1);
376 QDomNode tractor = m_document.elementsByTagName("tractor").at(0);
377 QDomNode kdenlivedoc = m_document.elementsByTagName("kdenlivedoc").at(0);
378 QDomElement kdenlivedoc_old = kdenlivedoc.cloneNode(true).toElement(); // Needed for folders
379 QDomNode multitrack = m_document.elementsByTagName("multitrack").at(0);
380 QDomNodeList playlists = m_document.elementsByTagName("playlist");
382 QDomNode props = m_document.elementsByTagName("properties").at(0).toElement();
383 QString profile = props.toElement().attribute("videoprofile");
384 m_startPos = props.toElement().attribute("timeline_position").toInt();
385 if (profile == "dv_wide") profile = "dv_pal_wide";
387 // move playlists outside of tractor and add the tracks instead
388 int max = playlists.count();
389 for (int i = 0; i < max; i++) {
390 QDomNode n = playlists.at(i);
391 westley.insertBefore(n, QDomNode());
392 QDomElement pl = n.toElement();
393 QDomElement track = m_document.createElement("track");
394 QString trackType = pl.attribute("hide");
395 if (!trackType.isEmpty())
396 track.setAttribute("hide", trackType);
397 QString playlist_id = pl.attribute("id");
398 if (playlist_id.isEmpty()) {
399 playlist_id = "black_track";
400 pl.setAttribute("id", playlist_id);
402 track.setAttribute("producer", playlist_id);
403 //tractor.appendChild(track);
404 #define KEEP_TRACK_ORDER 1
405 #ifdef KEEP_TRACK_ORDER
406 tractor.insertAfter(track, QDomNode());
408 // Insert the new track in an order that hopefully matches the 3 video, then 2 audio tracks of Kdenlive 0.7.0
409 // insertion sort - O( tracks*tracks )
410 // Note, this breaks _all_ transitions - but you can move them up and down afterwards.
411 QDomElement tractor_elem = tractor.toElement();
412 if (! tractor_elem.isNull()) {
413 QDomNodeList tracks = tractor_elem.elementsByTagName("track");
414 int size = tracks.size();
416 tractor.insertAfter(track, QDomNode());
418 bool inserted = false;
419 for (int i = 0; i < size; ++i) {
420 QDomElement track_elem = tracks.at(i).toElement();
421 if (track_elem.isNull()) {
422 tractor.insertAfter(track, QDomNode());
426 kDebug() << "playlist_id: " << playlist_id << " producer:" << track_elem.attribute("producer");
427 if (playlist_id < track_elem.attribute("producer")) {
428 tractor.insertBefore(track, track_elem);
434 // Reach here, no insertion, insert last
436 tractor.insertAfter(track, QDomNode());
440 kWarning() << "tractor was not a QDomElement";
441 tractor.insertAfter(track, QDomNode());
445 tractor.removeChild(multitrack);
447 // write tracks order now that they've been sorted
449 QDomNodeList tracks = m_document.elementsByTagName("track");
450 for (int i = 0; i < tracks.count(); ++i) {
451 QDomElement track = tracks.at(i).toElement();
452 if (track.attribute("hide") == "video")
453 tracksOrder.append('a');
454 else if (track.attribute("producer") != "black_track")
455 tracksOrder.append('v');
458 //Â audio track mixing transitions should not be added to track view, so add required attribute
459 QDomNodeList transitions = m_document.elementsByTagName("transition");
460 max = transitions.count();
461 for (int i = 0; i < max; i++) {
462 QDomElement tr = transitions.at(i).toElement();
463 if (tr.attribute("combine") == "1" && tr.attribute("mlt_service") == "mix") {
464 QDomElement property = m_document.createElement("property");
465 property.setAttribute("name", "internal_added");
466 QDomText value = m_document.createTextNode("237");
467 property.appendChild(value);
468 tr.appendChild(property);
470 // convert transition
471 QDomNamedNodeMap attrs = tr.attributes();
472 for (unsigned int j = 0; j < attrs.count(); j++) {
473 QString attrName = attrs.item(j).nodeName();
474 if (attrName != "in" && attrName != "out" && attrName != "id") {
475 QDomElement property = m_document.createElement("property");
476 property.setAttribute("name", attrName);
477 QDomText value = m_document.createTextNode(attrs.item(j).nodeValue());
478 property.appendChild(value);
479 tr.appendChild(property);
485 //Â move transitions after tracks
486 for (int i = 0; i < max; i++) {
487 tractor.insertAfter(transitions.at(0), QDomNode());
490 // Fix filters format
491 QDomNodeList entries = m_document.elementsByTagName("entry");
492 max = entries.count();
493 for (int i = 0; i < max; i++) {
496 QDomNode m = entries.at(i).firstChild();
497 while (!m.isNull()) {
498 if (m.toElement().tagName() == "filter") {
499 QDomElement filt = m.toElement();
500 QDomNamedNodeMap attrs = filt.attributes();
501 QString current_id = filt.attribute("kdenlive_id");
502 if (current_id != last_id) {
504 last_id = current_id;
506 QDomElement e = m_document.createElement("property");
507 e.setAttribute("name", "kdenlive_ix");
508 QDomText value = m_document.createTextNode(QString::number(effectix));
509 e.appendChild(value);
511 for (int j = 0; j < attrs.count(); j++) {
512 QDomAttr a = attrs.item(j).toAttr();
514 kDebug() << " FILTER; adding :" << a.name() << ":" << a.value();
515 QDomElement e = m_document.createElement("property");
516 e.setAttribute("name", a.name());
517 QDomText value = m_document.createTextNode(a.value());
518 e.appendChild(value);
529 QDomNodeList filters = m_document.elementsByTagName("filter");
530 max = filters.count();
533 for (int i = 0; i < max; i++) {
534 QDomElement filt = filters.at(i).toElement();
535 QDomNamedNodeMap attrs = filt.attributes();
536 QString current_id = filt.attribute("kdenlive_id");
537 if (current_id != last_id) {
539 last_id = current_id;
541 QDomElement e = m_document.createElement("property");
542 e.setAttribute("name", "kdenlive_ix");
543 QDomText value = m_document.createTextNode(QString::number(1));
544 e.appendChild(value);
546 for (int j = 0; j < attrs.count(); j++) {
547 QDomAttr a = attrs.item(j).toAttr();
549 kDebug() << " FILTER; adding :" << a.name() << ":" << a.value();
550 QDomElement e = m_document.createElement("property");
551 e.setAttribute("name", a.name());
552 QDomText value = m_document.createTextNode(a.value());
553 e.appendChild(value);
560 QDomNodeList producers = westley.toElement().elementsByTagName("producer");
561 max = producers.count();
562 for (int i = 0; i < max; i++) {
563 QDomElement prod = producers.at(i).toElement();
564 if (prod.attribute("mlt_service") == "framebuffer") {
565 QString slowmotionprod = prod.attribute("resource");
566 slowmotionprod.replace(':', '?');
567 kDebug() << "// FOUND WRONG SLOWMO, new: " << slowmotionprod;
568 prod.setAttribute("resource", slowmotionprod);
571 //Â move producers to correct place, markers to a global list, fix clip descriptions
572 QDomElement markers = m_document.createElement("markers");
573 // This will get the westley producers:
574 producers = m_document.elementsByTagName("producer");
575 max = producers.count();
576 for (int i = 0; i < max; i++) {
577 QDomElement prod = producers.at(0).toElement();
578 // add resource also as a property (to allow path correction in setNewResource())
579 // TODO: will it work with slowmotion? needs testing
580 if (!prod.attribute("resource").isEmpty()) {
581 QDomElement prop_resource = m_document.createElement("property");
582 prop_resource.setAttribute("name", "resource");
583 QDomText resource = m_document.createTextNode(prod.attribute("resource"));
584 prop_resource.appendChild(resource);
585 prod.appendChild(prop_resource);
587 QDomNode m = prod.firstChild();
589 if (m.toElement().tagName() == "markers") {
590 QDomNodeList prodchilds = m.childNodes();
591 int maxchild = prodchilds.count();
592 for (int k = 0; k < maxchild; k++) {
593 QDomElement mark = prodchilds.at(0).toElement();
594 mark.setAttribute("id", prod.attribute("id"));
595 markers.insertAfter(mark, QDomNode());
598 } else if (prod.attribute("type").toInt() == TEXT) {
599 // convert title clip
600 if (m.toElement().tagName() == "textclip") {
602 QDomElement titleclip = m.toElement();
603 QDomElement title = tdoc.createElement("kdenlivetitle");
604 tdoc.appendChild(title);
605 QDomNodeList objects = titleclip.childNodes();
606 int maxchild = objects.count();
607 for (int k = 0; k < maxchild; k++) {
609 QDomElement ob = objects.at(k).toElement();
610 if (ob.attribute("type") == "3") {
611 // text object - all of this goes into "xmldata"...
612 QDomElement item = tdoc.createElement("item");
613 item.setAttribute("z-index", ob.attribute("z"));
614 item.setAttribute("type", "QGraphicsTextItem");
615 QDomElement position = tdoc.createElement("position");
616 position.setAttribute("x", ob.attribute("x"));
617 position.setAttribute("y", ob.attribute("y"));
618 QDomElement content = tdoc.createElement("content");
619 content.setAttribute("font", ob.attribute("font_family"));
620 content.setAttribute("font-size", ob.attribute("font_size"));
621 content.setAttribute("font-bold", ob.attribute("bold"));
622 content.setAttribute("font-italic", ob.attribute("italic"));
623 content.setAttribute("font-underline", ob.attribute("underline"));
624 QString col = ob.attribute("color");
626 content.setAttribute("font-color", colorToString(c));
627 // todo: These fields are missing from the newly generated xmldata:
628 // transform, startviewport, endviewport, background
630 QDomText conttxt = tdoc.createTextNode(ob.attribute("text"));
631 content.appendChild(conttxt);
632 item.appendChild(position);
633 item.appendChild(content);
634 title.appendChild(item);
635 } else if (ob.attribute("type") == "5") {
637 QDomElement item = tdoc.createElement("item");
638 item.setAttribute("z-index", ob.attribute("z"));
639 item.setAttribute("type", "QGraphicsRectItem");
640 QDomElement position = tdoc.createElement("position");
641 position.setAttribute("x", ob.attribute("x"));
642 position.setAttribute("y", ob.attribute("y"));
643 QDomElement content = tdoc.createElement("content");
644 QString col = ob.attribute("color");
646 content.setAttribute("brushcolor", colorToString(c));
647 QString rect = "0,0,";
648 rect.append(ob.attribute("width"));
650 rect.append(ob.attribute("height"));
651 content.setAttribute("rect", rect);
652 item.appendChild(position);
653 item.appendChild(content);
654 title.appendChild(item);
657 prod.setAttribute("xmldata", tdoc.toString());
658 // mbd todo: This clearly does not work, as every title gets the same name - trying to leave it empty
659 // QStringList titleInfo = TitleWidget::getFreeTitleInfo(projectFolder());
660 // prod.setAttribute("titlename", titleInfo.at(0));
661 // prod.setAttribute("resource", titleInfo.at(1));
662 //kDebug()<<"TITLE DATA:\n"<<tdoc.toString();
664 } // End conversion of title clips.
666 } else if (m.isText()) {
667 QString comment = m.nodeValue();
668 if (!comment.isEmpty()) {
669 prod.setAttribute("description", comment);
674 int duration = prod.attribute("duration").toInt();
675 if (duration > 0) prod.setAttribute("out", QString::number(duration));
676 // The clip goes back in, but text clips should not go back in, at least not modified
677 westley.insertBefore(prod, QDomNode());
681 QDomNode westley0 = m_document.elementsByTagName("westley").at(0);
682 if (!markers.firstChild().isNull()) westley0.appendChild(markers);
685 // Convert as much of the kdenlivedoc as possible. Use the producer in westley
686 // First, remove the old stuff from westley, and add a new empty one
687 // Also, track the max id in order to use it for the adding of groups/folders
688 int max_kproducer_id = 0;
689 westley0.removeChild(kdenlivedoc);
690 QDomElement kdenlivedoc_new = m_document.createElement("kdenlivedoc");
691 kdenlivedoc_new.setAttribute("profile", profile);
692 kdenlivedoc_new.setAttribute("tracks", tracksOrder);
693 // Add all the producers that has a ressource in westley
694 QDomElement westley_element = westley0.toElement();
695 if (westley_element.isNull()) {
696 kWarning() << "westley0 element in document was not a QDomElement - unable to add producers to new kdenlivedoc";
698 QDomNodeList wproducers = westley_element.elementsByTagName("producer");
699 int kmax = wproducers.count();
700 for (int i = 0; i < kmax; i++) {
701 QDomElement wproducer = wproducers.at(i).toElement();
702 if (wproducer.isNull()) {
703 kWarning() << "Found producer in westley0, that was not a QDomElement";
705 // We have to do slightly different things, depending on the type
706 kDebug() << "Converting producer element with type" << wproducer.attribute("type");
707 if (wproducer.attribute("type").toInt() == TEXT) {
708 kDebug() << "Found TEXT element in producer" << endl;
709 QDomElement kproducer = wproducer.cloneNode(true).toElement();
710 kproducer.setTagName("kdenlive_producer");
711 kdenlivedoc_new.appendChild(kproducer);
712 // TODO: Perhaps needs some more changes here to "frequency", aspect ratio as a float, frame_size, channels, and later, ressource and title name
714 QDomElement kproducer = m_document.createElement("kdenlive_producer");
715 kproducer.setAttribute("id", wproducer.attribute("id"));
716 if (!wproducer.attribute("description").isEmpty())
717 kproducer.setAttribute("description", wproducer.attribute("description"));
718 kproducer.setAttribute("resource", wproducer.attribute("resource"));
719 kproducer.setAttribute("type", wproducer.attribute("type"));
720 // Testing fix for 358
721 if (!wproducer.attribute("aspect_ratio").isEmpty()) {
722 kproducer.setAttribute("aspect_ratio", wproducer.attribute("aspect_ratio"));
724 if (!wproducer.attribute("source_fps").isEmpty()) {
725 kproducer.setAttribute("fps", wproducer.attribute("source_fps"));
727 if (!wproducer.attribute("length").isEmpty()) {
728 kproducer.setAttribute("duration", wproducer.attribute("length"));
730 kdenlivedoc_new.appendChild(kproducer);
732 if (wproducer.attribute("id").toInt() > max_kproducer_id) {
733 max_kproducer_id = wproducer.attribute("id").toInt();
738 #define LOOKUP_FOLDER 1
740 // Look through all the folder elements of the old doc, for each folder, for each producer,
741 // get the id, look it up in the new doc, set the groupname and groupid
742 // Note, this does not work at the moment - at least one folders shows up missing, and clips with no folder
744 // QDomElement kdenlivedoc_old = kdenlivedoc.toElement();
745 if (!kdenlivedoc_old.isNull()) {
746 QDomNodeList folders = kdenlivedoc_old.elementsByTagName("folder");
747 int fsize = folders.size();
748 int groupId = max_kproducer_id + 1; // Start at +1 of max id of the kdenlive_producers
749 for (int i = 0; i < fsize; ++i) {
750 QDomElement folder = folders.at(i).toElement();
751 if (!folder.isNull()) {
752 QString groupName = folder.attribute("name");
753 kDebug() << "groupName: " << groupName << " with groupId: " << groupId;
754 QDomNodeList fproducers = folder.elementsByTagName("producer");
755 int psize = fproducers.size();
756 for (int j = 0; j < psize; ++j) {
757 QDomElement fproducer = fproducers.at(j).toElement();
758 if (!fproducer.isNull()) {
759 QString id = fproducer.attribute("id");
760 // This is not very effective, but compared to loading the clips, its a breeze
761 QDomNodeList kdenlive_producers = kdenlivedoc_new.elementsByTagName("kdenlive_producer");
762 int kpsize = kdenlive_producers.size();
763 for (int k = 0; k < kpsize; ++k) {
764 QDomElement kproducer = kdenlive_producers.at(k).toElement(); // Its an element for sure
765 if (id == kproducer.attribute("id")) {
766 // We do not check that it already is part of a folder
767 kproducer.setAttribute("groupid", groupId);
768 kproducer.setAttribute("groupname", groupName);
779 westley0.appendChild(kdenlivedoc_new);
781 QDomNodeList elements = westley.childNodes();
782 max = elements.count();
783 for (int i = 0; i < max; i++) {
784 QDomElement prod = elements.at(0).toElement();
785 westley0.insertAfter(prod, QDomNode());
788 westley0.removeChild(westley);
790 // experimental and probably slow
791 // adds <avfile /> information to <kdenlive_producer />
792 QDomNodeList kproducers = m_document.elementsByTagName("kdenlive_producer");
793 QDomNodeList avfiles = kdenlivedoc_old.elementsByTagName("avfile");
794 kDebug() << "found" << avfiles.count() << "<avfile />s and" << kproducers.count() << "<kdenlive_producer />s";
795 for (int i = 0; i < avfiles.count(); ++i) {
796 QDomElement avfile = avfiles.at(i).toElement();
797 QDomElement kproducer = QDomElement();
799 kWarning() << "found an <avfile /> that is not a QDomElement";
801 QString id = avfile.attribute("id");
802 // this is horrible, must be rewritten, it's just for test
803 for (int j = 0; j < kproducers.count(); ++j) {
804 //kDebug() << "checking <kdenlive_producer /> with id" << kproducers.at(j).toElement().attribute("id");
805 if (kproducers.at(j).toElement().attribute("id") == id) {
806 kproducer = kproducers.at(j).toElement();
810 if (kproducer == QDomElement())
811 kWarning() << "no match for <avfile /> with id =" << id;
813 //kDebug() << "ready to set additional <avfile />'s attributes (id =" << id << ")";
814 kproducer.setAttribute("channels", avfile.attribute("channels"));
815 kproducer.setAttribute("duration", avfile.attribute("duration"));
816 kproducer.setAttribute("frame_size", avfile.attribute("width") + "x" + avfile.attribute("height"));
817 kproducer.setAttribute("frequency", avfile.attribute("frequency"));
818 if (kproducer.attribute("description").isEmpty() && !avfile.attribute("description").isEmpty())
819 kproducer.setAttribute("description", avfile.attribute("description"));
824 //kDebug() << "///////////////// CONVERTEDÂ DOC:";
825 //kDebug() << m_document.toString();
827 QFile file( "converted.kdenlive" );
828 if ( file.open( QIODevice::WriteOnly ) ) {
829 QTextStream stream( &file );
830 stream << m_document.toString();
833 kDebug() << "Unable to dump file to converted.kdenlive";
836 //kDebug() << "///////////////// END CONVERTEDÂ DOC:";
841 QString KdenliveDoc::colorToString(const QColor& c) {
842 QString ret = "%1,%2,%3,%4";
843 ret = ret.arg(c.red()).arg(c.green()).arg(c.blue()).arg(c.alpha());
847 void KdenliveDoc::setZone(int start, int end) {
852 QPoint KdenliveDoc::zone() const {
853 return QPoint(m_zoneStart, m_zoneEnd);
856 bool KdenliveDoc::saveSceneList(const QString &path, QDomDocument sceneList) {
857 QDomNode wes = sceneList.elementsByTagName("westley").at(0);
859 QDomElement addedXml = sceneList.createElement("kdenlivedoc");
860 QDomElement markers = sceneList.createElement("markers");
861 addedXml.setAttribute("version", "0.81");
862 addedXml.setAttribute("profile", profilePath());
863 addedXml.setAttribute("position", m_render->seekPosition().frames(m_fps));
864 addedXml.setAttribute("zonein", m_zoneStart);
865 addedXml.setAttribute("zoneout", m_zoneEnd);
866 addedXml.setAttribute("projectfolder", m_projectFolder.path());
867 addedXml.setAttribute("tracks", getTracksInfo());
868 addedXml.setAttribute("zoom", m_zoom);
871 QList <DocClipBase*> list = m_clipManager->documentClipList();
872 for (int i = 0; i < list.count(); i++) {
873 e = list.at(i)->toXML();
874 e.setTagName("kdenlive_producer");
875 addedXml.appendChild(sceneList.importNode(e, true));
876 QList < CommentedTime > marks = list.at(i)->commentedSnapMarkers();
877 for (int j = 0; j < marks.count(); j++) {
878 QDomElement marker = sceneList.createElement("marker");
879 marker.setAttribute("time", marks.at(j).time().ms() / 1000);
880 marker.setAttribute("comment", marks.at(j).comment());
881 marker.setAttribute("id", e.attribute("id"));
882 markers.appendChild(marker);
885 addedXml.appendChild(markers);
886 if (!m_guidesXml.isNull()) addedXml.appendChild(sceneList.importNode(m_guidesXml, true));
888 wes.appendChild(addedXml);
889 //wes.appendChild(doc.importNode(kdenliveData, true));
892 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
893 kWarning() << "////// ERROR writing to file: " << path;
894 KMessageBox::error(kapp->activeWindow(), i18n("Cannot write to file %1", path));
897 QTextStream out(&file);
898 out << sceneList.toString();
903 ClipManager *KdenliveDoc::clipManager() {
904 return m_clipManager;
907 KUrl KdenliveDoc::projectFolder() const {
908 //if (m_projectFolder.isEmpty()) return KUrl(KStandardDirs::locateLocal("appdata", "/projects/"));
909 return m_projectFolder;
912 void KdenliveDoc::setProjectFolder(KUrl url) {
913 if (url == m_projectFolder) return;
915 KStandardDirs::makeDir(url.path());
916 KStandardDirs::makeDir(url.path() + "/titles/");
917 KStandardDirs::makeDir(url.path() + "/thumbs/");
918 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);
919 m_projectFolder = url;
922 void KdenliveDoc::moveProjectData(KUrl url) {
923 QList <DocClipBase*> list = m_clipManager->documentClipList();
924 //TODO: Also move ladspa effects files
925 for (int i = 0; i < list.count(); i++) {
926 DocClipBase *clip = list.at(i);
927 if (clip->clipType() == TEXT) {
928 // the image for title clip must be moved
929 KUrl oldUrl = clip->fileURL();
930 KUrl newUrl = KUrl(url.path() + "/titles/" + oldUrl.fileName());
931 KIO::Job *job = KIO::copy(oldUrl, newUrl);
932 if (KIO::NetAccess::synchronousRun(job, 0)) clip->setProperty("resource", newUrl.path());
934 QString hash = clip->getClipHash();
935 KUrl oldVideoThumbUrl = KUrl(m_projectFolder.path() + "/thumbs/" + hash + ".png");
936 KUrl oldAudioThumbUrl = KUrl(m_projectFolder.path() + "/thumbs/" + hash + ".thumb");
937 if (KIO::NetAccess::exists(oldVideoThumbUrl, KIO::NetAccess::SourceSide, 0)) {
938 KUrl newUrl = KUrl(url.path() + "/thumbs/" + hash + ".png");
939 KIO::Job *job = KIO::copy(oldVideoThumbUrl, newUrl);
940 KIO::NetAccess::synchronousRun(job, 0);
942 if (KIO::NetAccess::exists(oldAudioThumbUrl, KIO::NetAccess::SourceSide, 0)) {
943 KUrl newUrl = KUrl(url.path() + "/thumbs/" + hash + ".thumb");
944 KIO::Job *job = KIO::copy(oldAudioThumbUrl, newUrl);
945 if (KIO::NetAccess::synchronousRun(job, 0)) clip->refreshThumbUrl();
950 QString KdenliveDoc::profilePath() const {
951 return m_profile.path;
954 MltVideoProfile KdenliveDoc::mltProfile() const {
958 void KdenliveDoc::setProfilePath(QString path) {
959 if (path.isEmpty()) path = KdenliveSettings::default_profile();
960 if (path.isEmpty()) path = "dv_pal";
961 m_profile = ProfilesDialog::getVideoProfile(path);
962 KdenliveSettings::setProject_display_ratio((double) m_profile.display_aspect_num / m_profile.display_aspect_den);
963 m_fps = (double) m_profile.frame_rate_num / m_profile.frame_rate_den;
964 m_width = m_profile.width;
965 m_height = m_profile.height;
966 kDebug() << "KDEnnlive document, init timecode from path: " << path << ", " << m_fps;
967 if (m_fps == 30000.0 / 1001.0) m_timecode.setFormat(30, true);
968 else m_timecode.setFormat((int) m_fps);
971 const double KdenliveDoc::dar() {
972 return (double) m_profile.display_aspect_num / m_profile.display_aspect_den;
975 void KdenliveDoc::setThumbsProgress(const QString &message, int progress) {
976 emit progressInfo(message, progress);
979 void KdenliveDoc::loadingProgressed() {
980 m_documentLoadingProgress += m_documentLoadingStep;
981 emit progressInfo(QString(), (int) m_documentLoadingProgress);
984 QUndoStack *KdenliveDoc::commandStack() {
985 return m_commandStack;
989 void KdenliveDoc::setRenderer(Render *render) {
990 if (m_render) return;
992 emit progressInfo(i18n("Loading playlist..."), 0);
993 //qApp->processEvents();
995 m_render->setSceneList(m_document.toString(), m_startPos);
996 kDebug() << "// SETTING SCENE LIST:\n\n" << m_document.toString();
999 emit progressInfo(QString(), -1);
1002 void KdenliveDoc::checkProjectClips() {
1003 if (m_render == NULL) return;
1004 QList <Mlt::Producer *> prods = m_render->producersList();
1008 for (int i = 0; i < prods.count(); i++) {
1009 id = prods.at(i)->get("id");
1010 prodId = id.section('_', 0, 0);
1011 prodTrack = id.section('_', 1, 1);
1012 DocClipBase *clip = m_clipManager->getClipById(prodId);
1013 if (clip) clip->setProducer(prods.at(i));
1014 if (clip && clip->clipType() == TEXT && !QFile::exists(clip->fileURL().path())) {
1015 // regenerate text clip image if required
1016 kDebug() << "// TITLE: " << clip->getProperty("titlename") << " Preview file: " << clip->getProperty("resource") << " DOES NOT EXIST";
1017 QString titlename = clip->getProperty("titlename");
1018 QString titleresource;
1019 if (titlename.isEmpty()) {
1020 QStringList titleInfo = TitleWidget::getFreeTitleInfo(projectFolder());
1021 titlename = titleInfo.at(0);
1022 titleresource = titleInfo.at(1);
1023 clip->setProperty("titlename", titlename);
1024 kDebug() << "// New title set to: " << titlename;
1026 titleresource = TitleWidget::getTitleResourceFromName(projectFolder(), titlename);
1028 QString titlepath = projectFolder().path() + "/titles/";
1029 TitleWidget *dia_ui = new TitleWidget(KUrl(), titlepath, m_render, kapp->activeWindow());
1031 doc.setContent(clip->getProperty("xmldata"));
1032 dia_ui->setXml(doc);
1033 QPixmap pix = dia_ui->renderedPixmap();
1034 pix.save(titleresource);
1035 clip->setProperty("resource", titleresource);
1037 clip->producer()->set("force_reload", 1);
1042 Render *KdenliveDoc::renderer() {
1046 void KdenliveDoc::updateClip(const QString &id) {
1047 emit updateClipDisplay(id);
1050 int KdenliveDoc::getFramePos(QString duration) {
1051 return m_timecode.getFrameCount(duration, m_fps);
1054 QString KdenliveDoc::producerName(const QString &id) {
1055 QString result = "unnamed";
1056 QDomNodeList prods = producersList();
1057 int ct = prods.count();
1058 for (int i = 0; i < ct ; i++) {
1059 QDomElement e = prods.item(i).toElement();
1060 if (e.attribute("id") != "black" && e.attribute("id") == id) {
1061 result = e.attribute("name");
1062 if (result.isEmpty()) result = KUrl(e.attribute("resource")).fileName();
1069 void KdenliveDoc::setProducerDuration(const QString &id, int duration) {
1070 QDomNodeList prods = producersList();
1071 int ct = prods.count();
1072 for (int i = 0; i < ct ; i++) {
1073 QDomElement e = prods.item(i).toElement();
1074 if (e.attribute("id") != "black" && e.attribute("id") == id) {
1075 e.setAttribute("duration", QString::number(duration));
1081 int KdenliveDoc::getProducerDuration(const QString &id) {
1083 QDomNodeList prods = producersList();
1084 int ct = prods.count();
1085 for (int i = 0; i < ct ; i++) {
1086 QDomElement e = prods.item(i).toElement();
1087 if (e.attribute("id") != "black" && e.attribute("id") == id) {
1088 result = e.attribute("duration").toInt();
1096 QDomDocument KdenliveDoc::generateSceneList() {
1098 QDomElement westley = doc.createElement("westley");
1099 doc.appendChild(westley);
1100 QDomElement prod = doc.createElement("producer");
1103 QDomDocument KdenliveDoc::toXml() {
1107 Timecode KdenliveDoc::timecode() const {
1111 QDomNodeList KdenliveDoc::producersList() {
1112 return m_document.elementsByTagName("producer");
1115 void KdenliveDoc::backupMltPlaylist() {
1116 if (m_render) m_scenelist = m_render->sceneList();
1119 double KdenliveDoc::projectDuration() const {
1120 if (m_render) return GenTime(m_render->getLength(), m_fps).ms() / 1000;
1123 double KdenliveDoc::fps() const {
1127 int KdenliveDoc::width() const {
1131 int KdenliveDoc::height() const {
1135 KUrl KdenliveDoc::url() const {
1139 void KdenliveDoc::setUrl(KUrl url) {
1143 void KdenliveDoc::setModified(bool mod) {
1144 if (!m_url.isEmpty() && mod && KdenliveSettings::crashrecovery()) {
1145 m_autoSaveTimer->start(3000);
1147 if (mod == m_modified) return;
1149 emit docModified(m_modified);
1152 bool KdenliveDoc::isModified() const {
1156 QString KdenliveDoc::description() const {
1157 if (m_url.isEmpty())
1158 return i18n("Untitled") + " / " + m_profile.description;
1160 return m_url.fileName() + " / " + m_profile.description;
1163 void KdenliveDoc::addClip(QDomElement elem, QString clipId, bool createClipItem) {
1164 const QString producerId = clipId.section('_', 0, 0);
1165 int subtrack = clipId.section('_', 1, 1).toInt();
1166 DocClipBase *clip = m_clipManager->getClipById(producerId);
1168 /*kDebug()<<"// CLIP "<<clipId<<" NOT OFUND in LIST, CREATING";
1170 doc.appendChild(doc.importNode(elem, true));
1171 kDebug() << "IMPORTED CLIP: \n" << doc.toString()<<"\n";*/
1172 elem.setAttribute("id", producerId);
1173 QString path = elem.attribute("resource");
1175 if (elem.attribute("type").toInt() == SLIDESHOW) {
1176 extension = KUrl(path).fileName();
1177 path = KUrl(path).directory();
1179 if (!path.isEmpty() && !QFile::exists(path)) {
1180 const QString size = elem.attribute("file_size");
1181 const QString hash = elem.attribute("file_hash");
1183 KMessageBox::ButtonCode action = KMessageBox::No;
1184 if (!size.isEmpty() && !hash.isEmpty()) {
1185 if (!m_searchFolder.isEmpty()) newpath = searchFileRecursively(m_searchFolder, size, hash);
1186 else action = (KMessageBox::ButtonCode)KMessageBox::messageBox(kapp->activeWindow(), KMessageBox::WarningYesNo, i18n("Clip <b>%1</b><br>is invalid, what do you want to do?", path), i18n("File not found"), KGuiItem(i18n("Search automatically")), /*KGuiItem(i18n("Remove from project")), */KGuiItem(i18n("Keep as placeholder")));
1188 if (elem.attribute("type").toInt() == SLIDESHOW) {
1189 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)
1190 newpath = KFileDialog::getExistingDirectory(KUrl("kfiledialog:///clipfolder"), kapp->activeWindow(), i18n("Looking for %1", path));
1191 } else if (KMessageBox::messageBox(kapp->activeWindow(), KMessageBox::WarningYesNo, i18n("Clip <b>%1</b><br>is invalid or missing, what do you want to do?", path), i18n("File not found"), KGuiItem(i18n("Search manually")), /*KGuiItem(i18n("Remove from project")),*/ KGuiItem(i18n("Keep as placeholder"))) == KMessageBox::Yes)
1192 newpath = KFileDialog::getOpenFileName(KUrl("kfiledialog:///clipfolder"), QString(), kapp->activeWindow(), i18n("Looking for %1", path));
1194 if (action == KMessageBox::Yes) {
1195 kDebug() << "// ASKED FOR SRCH CLIP: " << clipId;
1196 m_searchFolder = KFileDialog::getExistingDirectory(KUrl("kfiledialog:///clipfolder"), kapp->activeWindow());
1197 if (!m_searchFolder.isEmpty()) {
1198 newpath = searchFileRecursively(QDir(m_searchFolder), size, hash);
1201 if (!newpath.isEmpty()) {
1202 if (elem.attribute("type").toInt() == SLIDESHOW) newpath.append('/' + extension);
1203 elem.setAttribute("resource", newpath);
1204 setNewClipResource(clipId, newpath);
1208 clip = new DocClipBase(m_clipManager, elem, producerId);
1209 m_clipManager->addClip(clip);
1211 if (createClipItem) {
1212 emit addProjectClip(clip);
1213 qApp->processEvents();
1214 m_render->getFileProperties(clip->toXML(), clip->getId());
1219 void KdenliveDoc::setNewClipResource(const QString &id, const QString &path) {
1220 QDomNodeList prods = m_document.elementsByTagName("producer");
1221 int maxprod = prods.count();
1222 for (int i = 0; i < maxprod; i++) {
1223 QDomNode m = prods.at(i);
1224 QString prodId = m.toElement().attribute("id");
1225 if (prodId == id || prodId.startsWith(id + "_")) {
1226 QDomNodeList params = m.childNodes();
1227 for (int j = 0; j < params.count(); j++) {
1228 QDomElement e = params.item(j).toElement();
1229 if (e.attribute("name") == "resource") {
1230 e.firstChild().setNodeValue(path);
1238 QString KdenliveDoc::searchFileRecursively(const QDir &dir, const QString &matchSize, const QString &matchHash) const {
1239 QString foundFileName;
1240 QByteArray fileData;
1241 QByteArray fileHash;
1242 QStringList filesAndDirs = dir.entryList(QDir::Files | QDir::Readable);
1243 for (int i = 0; i < filesAndDirs.size() && foundFileName.isEmpty(); i++) {
1244 QFile file(dir.absoluteFilePath(filesAndDirs.at(i)));
1245 if (file.open(QIODevice::ReadOnly)) {
1246 if (QString::number(file.size()) == matchSize) {
1248 * 1 MB = 1 second per 450 files (or faster)
1249 * 10 MB = 9 seconds per 450 files (or faster)
1251 if (file.size() > 1000000*2) {
1252 fileData = file.read(1000000);
1253 if (file.seek(file.size() - 1000000))
1254 fileData.append(file.readAll());
1256 fileData = file.readAll();
1258 fileHash = QCryptographicHash::hash(fileData, QCryptographicHash::Md5);
1259 if (QString(fileHash.toHex()) == matchHash)
1260 return file.fileName();
1263 kDebug() << filesAndDirs.at(i) << file.size() << fileHash.toHex();
1265 filesAndDirs = dir.entryList(QDir::Dirs | QDir::Readable | QDir::Executable | QDir::NoDotAndDotDot);
1266 for (int i = 0; i < filesAndDirs.size() && foundFileName.isEmpty(); i++) {
1267 foundFileName = searchFileRecursively(dir.absoluteFilePath(filesAndDirs.at(i)), matchSize, matchHash);
1268 if (!foundFileName.isEmpty())
1271 return foundFileName;
1274 void KdenliveDoc::addClipInfo(QDomElement elem, QString clipId) {
1275 DocClipBase *clip = m_clipManager->getClipById(clipId);
1277 addClip(elem, clipId, false);
1279 QMap <QString, QString> properties;
1280 QDomNamedNodeMap attributes = elem.attributes();
1282 for (unsigned int i = 0; i < attributes.count(); i++) {
1283 attrname = attributes.item(i).nodeName();
1284 if (attrname != "resource")
1285 properties.insert(attrname, attributes.item(i).nodeValue());
1286 kDebug() << attrname << " = " << attributes.item(i).nodeValue();
1288 clip->setProperties(properties);
1289 emit addProjectClip(clip, false);
1293 void KdenliveDoc::addFolder(const QString foldername, const QString &clipId, bool edit) {
1294 emit addProjectFolder(foldername, clipId, false, edit);
1297 void KdenliveDoc::deleteFolder(const QString foldername, const QString &clipId) {
1298 emit addProjectFolder(foldername, clipId, true);
1301 void KdenliveDoc::deleteProjectClip(QList <QString> ids) {
1302 for (int i = 0; i < ids.size(); ++i) {
1303 emit deleteTimelineClip(ids.at(i));
1304 m_clipManager->slotDeleteClip(ids.at(i));
1309 void KdenliveDoc::deleteProjectFolder(QMap <QString, QString> map) {
1310 QMapIterator<QString, QString> i(map);
1311 while (i.hasNext()) {
1313 slotDeleteFolder(i.key(), i.value());
1318 void KdenliveDoc::deleteClip(const QString &clipId) {
1319 emit signalDeleteProjectClip(clipId);
1320 m_clipManager->deleteClip(clipId);
1323 void KdenliveDoc::slotAddClipList(const KUrl::List urls, const QString group, const QString &groupId) {
1324 m_clipManager->slotAddClipList(urls, group, groupId);
1325 emit selectLastAddedClip(QString::number(m_clipManager->lastClipId()));
1330 void KdenliveDoc::slotAddClipFile(const KUrl url, const QString group, const QString &groupId) {
1331 kDebug() << "///////// DOCUM, ADD CLP: " << url;
1332 m_clipManager->slotAddClipFile(url, group, groupId);
1333 emit selectLastAddedClip(QString::number(m_clipManager->lastClipId()));
1337 void KdenliveDoc::slotAddFolder(const QString folderName) {
1338 AddFolderCommand *command = new AddFolderCommand(this, folderName, QString::number(m_clipManager->getFreeClipId()), true);
1339 commandStack()->push(command);
1343 void KdenliveDoc::slotDeleteFolder(const QString folderName, const QString &id) {
1344 AddFolderCommand *command = new AddFolderCommand(this, folderName, id, false);
1345 commandStack()->push(command);
1349 void KdenliveDoc::slotEditFolder(const QString newfolderName, const QString oldfolderName, const QString &clipId) {
1350 EditFolderCommand *command = new EditFolderCommand(this, newfolderName, oldfolderName, clipId, false);
1351 commandStack()->push(command);
1355 const QString&KdenliveDoc::getFreeClipId() {
1356 return QString::number(m_clipManager->getFreeClipId());
1359 DocClipBase *KdenliveDoc::getBaseClip(const QString &clipId) {
1360 return m_clipManager->getClipById(clipId);
1363 void KdenliveDoc::slotAddColorClipFile(const QString name, const QString color, QString duration, const QString group, const QString &groupId) {
1364 m_clipManager->slotAddColorClipFile(name, color, duration, group, groupId);
1368 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) {
1369 m_clipManager->slotAddSlideshowClipFile(name, path, count, duration, loop, fade, luma_duration, luma_file, softness, group, groupId);
1373 void KdenliveDoc::slotCreateTextClip(QString group, const QString &groupId) {
1374 QString titlesFolder = projectFolder().path() + "/titles/";
1375 KStandardDirs::makeDir(titlesFolder);
1376 TitleWidget *dia_ui = new TitleWidget(KUrl(), titlesFolder, m_render, kapp->activeWindow());
1377 if (dia_ui->exec() == QDialog::Accepted) {
1378 QStringList titleInfo = TitleWidget::getFreeTitleInfo(projectFolder());
1379 QPixmap pix = dia_ui->renderedPixmap();
1380 pix.save(titleInfo.at(1));
1381 //dia_ui->saveTitle(path + ".kdenlivetitle");
1382 m_clipManager->slotAddTextClipFile(titleInfo.at(0), titleInfo.at(1), dia_ui->xml().toString(), QString(), QString());
1388 int KdenliveDoc::tracksCount() const {
1389 return m_tracksList.count();
1392 TrackInfo KdenliveDoc::trackInfoAt(int ix) const {
1393 return m_tracksList.at(ix);
1396 void KdenliveDoc::switchTrackAudio(int ix, bool hide) {
1397 m_tracksList[ix].isMute = hide; // !m_tracksList.at(ix).isMute;
1400 void KdenliveDoc::switchTrackVideo(int ix, bool hide) {
1401 m_tracksList[ix].isBlind = hide; // !m_tracksList.at(ix).isBlind;
1404 void KdenliveDoc::insertTrack(int ix, TrackInfo type) {
1405 if (ix == -1) m_tracksList << type;
1406 else m_tracksList.insert(ix, type);
1409 void KdenliveDoc::deleteTrack(int ix) {
1410 m_tracksList.removeAt(ix);
1413 void KdenliveDoc::setTrackType(int ix, TrackInfo type) {
1414 m_tracksList[ix].type = type.type;
1415 m_tracksList[ix].isMute = type.isMute;
1416 m_tracksList[ix].isBlind = type.isBlind;
1419 const QList <TrackInfo> KdenliveDoc::tracksList() const {
1420 return m_tracksList;
1423 QPoint KdenliveDoc::getTracksCount() const {
1426 foreach(const TrackInfo &info, m_tracksList) {
1427 if (info.type == VIDEOTRACK) video++;
1430 return QPoint(video, audio);
1433 QString KdenliveDoc::getTracksInfo() const {
1435 foreach(const TrackInfo &info, m_tracksList) {
1436 if (info.type == VIDEOTRACK) result.append('v');
1437 else result.append('a');
1442 void KdenliveDoc::cachePixmap(const QString &fileId, const QPixmap &pix) const {
1443 pix.save(m_projectFolder.path() + "/thumbs/" + fileId + ".png");
1446 QString KdenliveDoc::getLadspaFile() const {
1448 QString counter = QString::number(ct).rightJustified(5, '0', false);
1449 while (QFile::exists(m_projectFolder.path() + "/ladspa/" + counter + ".ladspa")) {
1451 counter = QString::number(ct).rightJustified(5, '0', false);
1453 return m_projectFolder.path() + "/ladspa/" + counter + ".ladspa";
1456 #include "kdenlivedoc.moc"