1 /***************************************************************************
2 * Copyright (C) 2007 by Jean-Baptiste Mardelle (jb@kdenlive.org) *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
21 #include <KStandardDirs>
22 #include <KMessageBox>
24 #include <KFileDialog>
25 #include <KIO/NetAccess>
26 #include <KApplication>
28 #include "kdenlivedoc.h"
29 #include "docclipbase.h"
30 #include "profilesdialog.h"
31 #include "kdenlivesettings.h"
33 #include "clipmanager.h"
34 #include "addfoldercommand.h"
35 #include "editfoldercommand.h"
36 #include "titlewidget.h"
37 #include "mainwindow.h"
40 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) {
41 m_clipManager = new ClipManager(this);
44 if (KIO::NetAccess::download(url.path(), tmpFile, parent)) {
46 m_document.setContent(&file, false);
48 QDomNode infoXmlNode = m_document.elementsByTagName("kdenlivedoc").at(0);
49 QDomNode westley = m_document.elementsByTagName("westley").at(0);
50 if (!infoXmlNode.isNull()) {
51 QDomElement infoXml = infoXmlNode.toElement();
52 QString profilePath = infoXml.attribute("profile");
53 m_startPos = infoXml.attribute("position").toInt();
54 m_zoom = infoXml.attribute("zoom", "7").toInt();
55 setProfilePath(profilePath);
56 double version = infoXml.attribute("version").toDouble();
57 if (version < 0.7) convertDocument(version);
59 //delete all mlt producers and instead, use Kdenlive saved producers
60 QDomNodeList prods = m_document.elementsByTagName("producer");
61 int maxprod = prods.count();
63 for (int i = 0; i < maxprod; i++) {
64 QDomNode m = prods.at(pos);
65 QString prodId = m.toElement().attribute("id");
66 if (prodId == "black" || prodId.startsWith("slowmotion"))
68 else westley.removeChild(m);
70 prods = m_document.elementsByTagName("kdenlive_producer");
71 maxprod = prods.count();
72 for (int i = 0; i < maxprod; i++) {
73 prods.at(0).toElement().setTagName("producer");
74 westley.insertBefore(prods.at(0), QDomNode());
78 QDomNodeList producers = m_document.elementsByTagName("producer");
79 const int max = producers.count();
81 m_documentLoadingStep = 100.0 / (max + m_document.elementsByTagName("entry").count());
82 parent->slotGotProgressInfo(i18n("Loading project clips"), (int) m_documentLoadingProgress);
85 for (int i = 0; i < max; i++) {
86 e = producers.item(i).cloneNode().toElement();
87 if (m_documentLoadingStep > 0) {
88 m_documentLoadingProgress += m_documentLoadingStep;
89 parent->slotGotProgressInfo(QString(), (int) m_documentLoadingProgress);
90 qApp->processEvents();
92 QString prodId = e.attribute("id");
93 if (!e.isNull() && prodId != "black" && !prodId.startsWith("slowmotion")/*&& prodId.toInt() > 0*/) {
98 QDomNode markers = m_document.elementsByTagName("markers").at(0);
99 if (!markers.isNull()) {
100 QDomNodeList markerslist = markers.childNodes();
101 int maxchild = markerslist.count();
102 for (int k = 0; k < maxchild; k++) {
103 e = markerslist.at(k).toElement();
104 if (e.tagName() == "marker") {
105 m_clipManager->getClipById(e.attribute("id"))->addSnapMarker(GenTime(e.attribute("time").toDouble()), e.attribute("comment"));
108 westley.removeChild(markers);
110 m_document.removeChild(infoXmlNode);
112 kDebug() << "Reading file: " << url.path() << ", found clips: " << producers.count();
114 parent->slotGotProgressInfo(i18n("File %1 is not a Kdenlive project file."), 100);
115 kWarning() << " NO KDENLIVE INFO FOUND IN FILE: " << url.path();
116 m_document = createEmptyDocument(tracks.x(), tracks.y());
117 setProfilePath(profileName);
119 KIO::NetAccess::removeTempFile(tmpFile);
121 KMessageBox::error(parent, KIO::NetAccess::lastErrorString());
122 parent->slotGotProgressInfo(i18n("File %1 is not a Kdenlive project file."), 100);
123 m_document = createEmptyDocument(tracks.x(), tracks.y());
124 setProfilePath(profileName);
127 m_document = createEmptyDocument(tracks.x(), tracks.y());
128 setProfilePath(profileName);
130 m_scenelist = m_document.toString();
131 kDebug() << "KDEnnlive document, init timecode: " << m_fps;
132 if (m_fps == 30000.0 / 1001.0) m_timecode.setFormat(30, true);
133 else m_timecode.setFormat((int) m_fps);
135 m_autoSaveTimer = new QTimer(this);
136 m_autoSaveTimer->setSingleShot(true);
137 connect(m_autoSaveTimer, SIGNAL(timeout()), this, SLOT(slotAutoSave()));
140 KdenliveDoc::~KdenliveDoc() {
141 delete m_commandStack;
142 delete m_clipManager;
143 delete m_autoSaveTimer;
144 m_autosave->remove();
147 QDomDocument KdenliveDoc::createEmptyDocument(const int videotracks, const int audiotracks) {
148 // Creating new document
150 QDomElement westley = doc.createElement("westley");
151 doc.appendChild(westley);
153 QDomElement tractor = doc.createElement("tractor");
154 tractor.setAttribute("id", "maintractor");
155 QDomElement multitrack = doc.createElement("multitrack");
156 QDomElement playlist = doc.createElement("playlist");
157 playlist.setAttribute("id", "black_track");
158 westley.appendChild(playlist);
162 int total = audiotracks + videotracks + 1;
164 for (int i = 1; i < total; i++) {
165 QDomElement playlist = doc.createElement("playlist");
166 playlist.setAttribute("id", "playlist" + QString::number(i));
167 westley.appendChild(playlist);
170 QDomElement track0 = doc.createElement("track");
171 track0.setAttribute("producer", "black_track");
172 tractor.appendChild(track0);
174 // create audio tracks
175 for (int i = 1; i < audiotracks + 1; i++) {
176 QDomElement track = doc.createElement("track");
177 track.setAttribute("producer", "playlist" + QString::number(i));
178 track.setAttribute("hide", "video");
179 tractor.appendChild(track);
182 // create video tracks
183 for (int i = audiotracks + 1; i < total; i++) {
184 QDomElement track = doc.createElement("track");
185 track.setAttribute("producer", "playlist" + QString::number(i));
186 tractor.appendChild(track);
189 for (uint i = 2; i < total ; i++) {
190 QDomElement transition = doc.createElement("transition");
191 transition.setAttribute("always_active", "1");
193 QDomElement property = doc.createElement("property");
194 property.setAttribute("name", "a_track");
195 QDomText value = doc.createTextNode(QString::number(1));
196 property.appendChild(value);
197 transition.appendChild(property);
199 property = doc.createElement("property");
200 property.setAttribute("name", "b_track");
201 value = doc.createTextNode(QString::number(i));
202 property.appendChild(value);
203 transition.appendChild(property);
205 property = doc.createElement("property");
206 property.setAttribute("name", "mlt_service");
207 value = doc.createTextNode("mix");
208 property.appendChild(value);
209 transition.appendChild(property);
211 property = doc.createElement("property");
212 property.setAttribute("name", "combine");
213 value = doc.createTextNode("1");
214 property.appendChild(value);
215 transition.appendChild(property);
217 property = doc.createElement("property");
218 property.setAttribute("name", "internal_added");
219 value = doc.createTextNode("237");
220 property.appendChild(value);
221 transition.appendChild(property);
222 tractor.appendChild(transition);
224 westley.appendChild(tractor);
229 void KdenliveDoc::syncGuides(QList <Guide *> guides) {
233 m_guidesXml = doc.createElement("guides");
235 for (int i = 0; i < guides.count(); i++) {
236 e = doc.createElement("guide");
237 e.setAttribute("time", guides.at(i)->position().ms() / 1000);
238 e.setAttribute("comment", guides.at(i)->label());
239 m_guidesXml.appendChild(e);
241 emit guidesUpdated();
244 QDomElement KdenliveDoc::guidesXml() const {
248 void KdenliveDoc::slotAutoSave() {
250 if (!m_autosave->isOpen() && !m_autosave->open(QIODevice::ReadWrite)) {
251 // show error: could not open the autosave file
252 kDebug() << "ERROR; CANNOT CREATE AUTOSAVE FILE";
254 kDebug() << "// AUTOSAVE FILE: " << m_autosave->fileName();
255 m_render->saveSceneList(m_autosave->fileName(), documentInfoXml());
259 void KdenliveDoc::setZoom(int factor) {
263 int KdenliveDoc::zoom() const {
267 void KdenliveDoc::convertDocument(double version) {
268 // Opening a old Kdenlive document
269 QDomNode westley = m_document.elementsByTagName("westley").at(1);
270 QDomNode tractor = m_document.elementsByTagName("tractor").at(0);
271 QDomNode kdenlivedoc = m_document.elementsByTagName("kdenlivedoc").at(0);
272 QDomNode multitrack = m_document.elementsByTagName("multitrack").at(0);
273 QDomNodeList playlists = m_document.elementsByTagName("playlist");
275 m_startPos = kdenlivedoc.toElement().attribute("timeline_position").toInt();
277 QDomNode props = m_document.elementsByTagName("properties").at(0).toElement();
278 QString profile = props.toElement().attribute("videoprofile");
279 if (profile == "dv_wide") profile = "dv_pal_wide";
280 setProfilePath(profile);
282 // move playlists outside of tractor and add the tracks instead
283 int max = playlists.count();
284 for (int i = 0; i < max; i++) {
285 QDomNode n = playlists.at(i);
286 westley.insertBefore(n, QDomNode());
287 QDomElement pl = n.toElement();
288 QDomElement track = m_document.createElement("track");
289 QString trackType = pl.attribute("hide");
290 if (!trackType.isEmpty()) track.setAttribute("hide", trackType);
291 QString playlist_id = pl.attribute("id");
292 if (playlist_id.isEmpty()) {
293 playlist_id = "black_track";
294 pl.setAttribute("id", playlist_id);
296 track.setAttribute("producer", playlist_id);
297 //tractor.appendChild(track);
298 tractor.insertAfter(track, QDomNode());
300 tractor.removeChild(multitrack);
302 // audio track mixing transitions should not be added to track view, so add required attribute
303 QDomNodeList transitions = m_document.elementsByTagName("transition");
304 max = transitions.count();
305 for (int i = 0; i < max; i++) {
306 QDomElement tr = transitions.at(i).toElement();
307 if (tr.attribute("combine") == "1" && tr.attribute("mlt_service") == "mix") {
308 QDomElement property = m_document.createElement("property");
309 property.setAttribute("name", "internal_added");
310 QDomText value = m_document.createTextNode("237");
311 property.appendChild(value);
312 tr.appendChild(property);
314 // convert transition
315 QDomNamedNodeMap attrs = tr.attributes();
316 for (unsigned int j = 0; j < attrs.count(); j++) {
317 QString attrName = attrs.item(j).nodeName();
318 if (attrName != "in" && attrName != "out" && attrName != "id") {
319 QDomElement property = m_document.createElement("property");
320 property.setAttribute("name", attrName);
321 QDomText value = m_document.createTextNode(attrs.item(j).nodeValue());
322 property.appendChild(value);
323 tr.appendChild(property);
329 // move transitions after tracks
330 for (int i = 0; i < max; i++) {
331 tractor.insertAfter(transitions.at(0), QDomNode());
334 // Fix filters format
335 QDomNodeList entries = m_document.elementsByTagName("entry");
336 max = entries.count();
337 for (int i = 0; i < max; i++) {
340 QDomNode m = entries.at(i).firstChild();
341 while (!m.isNull()) {
342 if (m.toElement().tagName() == "filter") {
343 QDomElement filt = m.toElement();
344 QDomNamedNodeMap attrs = filt.attributes();
345 QString current_id = filt.attribute("kdenlive_id");
346 if (current_id != last_id) {
348 last_id = current_id;
350 QDomElement e = m_document.createElement("property");
351 e.setAttribute("name", "kdenlive_ix");
352 QDomText value = m_document.createTextNode(QString::number(effectix));
353 e.appendChild(value);
355 for (int j = 0; j < attrs.count(); j++) {
356 QDomAttr a = attrs.item(j).toAttr();
358 kDebug() << " FILTER; adding :" << a.name() << ":" << a.value();
359 QDomElement e = m_document.createElement("property");
360 e.setAttribute("name", a.name());
361 QDomText value = m_document.createTextNode(a.value());
362 e.appendChild(value);
373 QDomNodeList filters = m_document.elementsByTagName("filter");
374 max = filters.count();
377 for (int i = 0; i < max; i++) {
378 QDomElement filt = filters.at(i).toElement();
379 QDomNamedNodeMap attrs = filt.attributes();
380 QString current_id = filt.attribute("kdenlive_id");
381 if (current_id != last_id) {
383 last_id = current_id;
385 QDomElement e = m_document.createElement("property");
386 e.setAttribute("name", "kdenlive_ix");
387 QDomText value = m_document.createTextNode(QString::number(1));
388 e.appendChild(value);
390 for (int j = 0; j < attrs.count(); j++) {
391 QDomAttr a = attrs.item(j).toAttr();
393 kDebug() << " FILTER; adding :" << a.name() << ":" << a.value();
394 QDomElement e = m_document.createElement("property");
395 e.setAttribute("name", a.name());
396 QDomText value = m_document.createTextNode(a.value());
397 e.appendChild(value);
404 QDomNodeList producers = westley.toElement().elementsByTagName("producer");
405 max = producers.count();
406 for (int i = 0; i < max; i++) {
407 QDomElement prod = producers.at(i).toElement();
409 if (prod.attribute("mlt_service") == "framebuffer") {
410 QString slowmotionprod = prod.attribute("resource");
411 slowmotionprod.replace(':', '?');
412 kDebug() << "// FOUND WRONG SLOWMO, new: " << slowmotionprod;
413 prod.setAttribute("resource", slowmotionprod);
416 // move producers to correct place, markers to a global list, fix clip descriptions
417 QDomElement markers = m_document.createElement("markers");
418 producers = m_document.elementsByTagName("producer");
419 max = producers.count();
420 for (int i = 0; i < max; i++) {
421 QDomElement prod = producers.at(0).toElement();
422 QDomNode m = prod.firstChild();
424 if (m.toElement().tagName() == "markers") {
425 QDomNodeList prodchilds = m.childNodes();
426 int maxchild = prodchilds.count();
427 for (int k = 0; k < maxchild; k++) {
428 QDomElement mark = prodchilds.at(0).toElement();
429 mark.setAttribute("id", prod.attribute("id"));
430 markers.insertAfter(mark, QDomNode());
433 } else if (prod.attribute("type").toInt() == TEXT) {
434 // convert title clip
435 if (m.toElement().tagName() == "textclip") {
437 QDomElement titleclip = m.toElement();
438 QDomElement title = tdoc.createElement("kdenlivetitle");
439 tdoc.appendChild(title);
440 QDomNodeList objects = titleclip.childNodes();
441 int maxchild = objects.count();
442 for (int k = 0; k < maxchild; k++) {
444 QDomElement ob = objects.at(k).toElement();
445 if (ob.attribute("type") == "3") {
447 QDomElement item = tdoc.createElement("item");
448 item.setAttribute("z-index", ob.attribute("z"));
449 item.setAttribute("type", "QGraphicsTextItem");
450 QDomElement position = tdoc.createElement("position");
451 position.setAttribute("x", ob.attribute("x"));
452 position.setAttribute("y", ob.attribute("y"));
453 QDomElement content = tdoc.createElement("content");
454 content.setAttribute("font", ob.attribute("font_family"));
455 content.setAttribute("font-size", ob.attribute("font_size"));
456 content.setAttribute("font-bold", ob.attribute("bold"));
457 content.setAttribute("font-italic", ob.attribute("italic"));
458 content.setAttribute("font-underline", ob.attribute("underline"));
459 QString col = ob.attribute("color");
461 content.setAttribute("font-color", colorToString(c));
462 QDomText conttxt = tdoc.createTextNode(ob.attribute("text"));
463 content.appendChild(conttxt);
464 item.appendChild(position);
465 item.appendChild(content);
466 title.appendChild(item);
467 } else if (ob.attribute("type") == "5") {
469 QDomElement item = tdoc.createElement("item");
470 item.setAttribute("z-index", ob.attribute("z"));
471 item.setAttribute("type", "QGraphicsRectItem");
472 QDomElement position = tdoc.createElement("position");
473 position.setAttribute("x", ob.attribute("x"));
474 position.setAttribute("y", ob.attribute("y"));
475 QDomElement content = tdoc.createElement("content");
476 QString col = ob.attribute("color");
478 content.setAttribute("brushcolor", colorToString(c));
479 QString rect = "0,0,";
480 rect.append(ob.attribute("width"));
482 rect.append(ob.attribute("height"));
483 content.setAttribute("rect", rect);
484 item.appendChild(position);
485 item.appendChild(content);
486 title.appendChild(item);
489 prod.setAttribute("xmldata", tdoc.toString());
490 QString titlesFolder = projectFolder().path() + "/titles/";
491 KStandardDirs::makeDir(titlesFolder);
492 QString titleName = "title";
494 QString path = titlesFolder + titleName + QString::number(counter).rightJustified(3, '0', false);
495 while (QFile::exists(path + ".png")) {
497 path = titlesFolder + titleName + QString::number(counter).rightJustified(3, '0', false);
499 prod.setAttribute("xml", path);
500 prod.setAttribute("resource", path + ".png");
501 //kDebug()<<"TITLE DATA:\n"<<tdoc.toString();
505 } else if (m.isText()) {
506 QString comment = m.nodeValue();
507 if (!comment.isEmpty()) {
508 prod.setAttribute("description", comment);
513 int duration = prod.attribute("duration").toInt();
514 if (duration > 0) prod.setAttribute("out", QString::number(duration));
515 westley.insertBefore(prod, QDomNode());
519 QDomNode westley0 = m_document.elementsByTagName("westley").at(0);
520 if (!markers.firstChild().isNull()) westley0.appendChild(markers);
521 westley0.removeChild(kdenlivedoc);
523 QDomNodeList elements = westley.childNodes();
524 max = elements.count();
525 for (int i = 0; i < max; i++) {
526 QDomElement prod = elements.at(0).toElement();
527 westley0.insertAfter(prod, QDomNode());
530 westley0.removeChild(westley);
532 //kDebug() << "///////////////// CONVERTED DOC:";
533 //kDebug() << m_document.toString();
534 //kDebug() << "///////////////// END CONVERTED DOC:";
537 QString KdenliveDoc::colorToString(const QColor& c) {
538 QString ret = "%1,%2,%3,%4";
539 ret = ret.arg(c.red()).arg(c.green()).arg(c.blue()).arg(c.alpha());
543 QDomElement KdenliveDoc::documentInfoXml() {
546 QDomElement addedXml = doc.createElement("kdenlivedoc");
547 QDomElement markers = doc.createElement("markers");
548 addedXml.setAttribute("version", "0.7");
549 addedXml.setAttribute("profile", profilePath());
550 addedXml.setAttribute("position", m_render->seekPosition().frames(m_fps));
551 addedXml.setAttribute("zoom", m_zoom);
552 QList <DocClipBase*> list = m_clipManager->documentClipList();
553 for (int i = 0; i < list.count(); i++) {
554 e = list.at(i)->toXML();
555 e.setTagName("kdenlive_producer");
556 addedXml.appendChild(doc.importNode(e, true));
557 QList < CommentedTime > marks = list.at(i)->commentedSnapMarkers();
558 for (int j = 0; j < marks.count(); j++) {
559 QDomElement marker = doc.createElement("marker");
560 marker.setAttribute("time", marks.at(j).time().ms() / 1000);
561 marker.setAttribute("comment", marks.at(j).comment());
562 marker.setAttribute("id", e.attribute("id"));
563 markers.appendChild(marker);
566 addedXml.appendChild(markers);
567 if (!m_guidesXml.isNull()) addedXml.appendChild(doc.importNode(m_guidesXml, true));
568 //kDebug() << m_document.toString();
573 ClipManager *KdenliveDoc::clipManager() {
574 return m_clipManager;
577 KUrl KdenliveDoc::projectFolder() const {
578 if (m_projectFolder.isEmpty()) return KUrl(KStandardDirs::locateLocal("appdata", "/projects/"));
579 return m_projectFolder;
582 QString KdenliveDoc::getDocumentStandard() {
583 //WARNING: this way to tell the video standard is a bit hackish...
584 if (m_profile.description.contains("pal", Qt::CaseInsensitive) || m_profile.description.contains("25", Qt::CaseInsensitive) || m_profile.description.contains("50", Qt::CaseInsensitive)) return "PAL";
588 QString KdenliveDoc::profilePath() const {
589 return m_profile.path;
592 MltVideoProfile KdenliveDoc::mltProfile() const {
596 void KdenliveDoc::setProfilePath(QString path) {
597 if (path.isEmpty()) path = KdenliveSettings::default_profile();
598 if (path.isEmpty()) path = "dv_pal";
599 m_profile = ProfilesDialog::getVideoProfile(path);
600 KdenliveSettings::setProject_display_ratio((double) m_profile.display_aspect_num / m_profile.display_aspect_den);
601 m_fps = (double) m_profile.frame_rate_num / m_profile.frame_rate_den;
602 m_width = m_profile.width;
603 m_height = m_profile.height;
604 kDebug() << "KDEnnlive document, init timecode from path: " << path << ", " << m_fps;
605 if (m_fps == 30000.0 / 1001.0) m_timecode.setFormat(30, true);
606 else m_timecode.setFormat((int) m_fps);
609 const double KdenliveDoc::dar() {
610 return (double) m_profile.display_aspect_num / m_profile.display_aspect_den;
613 void KdenliveDoc::setThumbsProgress(const QString &message, int progress) {
614 emit progressInfo(message, progress);
617 void KdenliveDoc::loadingProgressed() {
618 m_documentLoadingProgress += m_documentLoadingStep;
619 emit progressInfo(QString(), (int) m_documentLoadingProgress);
622 QUndoStack *KdenliveDoc::commandStack() {
623 return m_commandStack;
626 void KdenliveDoc::setRenderer(Render *render) {
627 if (m_render) return;
629 emit progressInfo(i18n("Loading playlist..."), 0);
630 qApp->processEvents();
631 if (m_render) m_render->setSceneList(m_document.toString(), m_startPos);
632 emit progressInfo(QString(), -1);
635 Render *KdenliveDoc::renderer() {
639 void KdenliveDoc::updateClip(const QString &id) {
640 emit updateClipDisplay(id);
643 void KdenliveDoc::updateAllProjectClips() {
644 QList <DocClipBase*> list = m_clipManager->documentClipList();
645 for (int i = 0; i < list.count(); i++)
646 emit updateClipDisplay(list.at(i)->getId());
649 int KdenliveDoc::getFramePos(QString duration) {
650 return m_timecode.getFrameCount(duration, m_fps);
653 QString KdenliveDoc::producerName(const QString &id) {
654 QString result = "unnamed";
655 QDomNodeList prods = producersList();
656 int ct = prods.count();
657 for (int i = 0; i < ct ; i++) {
658 QDomElement e = prods.item(i).toElement();
659 if (e.attribute("id") != "black" && e.attribute("id") == id) {
660 result = e.attribute("name");
661 if (result.isEmpty()) result = KUrl(e.attribute("resource")).fileName();
668 void KdenliveDoc::setProducerDuration(const QString &id, int duration) {
669 QDomNodeList prods = producersList();
670 int ct = prods.count();
671 for (int i = 0; i < ct ; i++) {
672 QDomElement e = prods.item(i).toElement();
673 if (e.attribute("id") != "black" && e.attribute("id") == id) {
674 e.setAttribute("duration", QString::number(duration));
680 int KdenliveDoc::getProducerDuration(const QString &id) {
682 QDomNodeList prods = producersList();
683 int ct = prods.count();
684 for (int i = 0; i < ct ; i++) {
685 QDomElement e = prods.item(i).toElement();
686 if (e.attribute("id") != "black" && e.attribute("id") == id) {
687 result = e.attribute("duration").toInt();
695 QDomDocument KdenliveDoc::generateSceneList() {
697 QDomElement westley = doc.createElement("westley");
698 doc.appendChild(westley);
699 QDomElement prod = doc.createElement("producer");
702 QDomDocument KdenliveDoc::toXml() const {
706 Timecode KdenliveDoc::timecode() const {
710 QDomNodeList KdenliveDoc::producersList() {
711 return m_document.elementsByTagName("producer");
714 void KdenliveDoc::backupMltPlaylist() {
715 if (m_render) m_scenelist = m_render->sceneList();
718 double KdenliveDoc::projectDuration() const {
719 if (m_render) return GenTime(m_render->getLength(), m_fps).ms() / 1000;
722 double KdenliveDoc::fps() const {
726 int KdenliveDoc::width() const {
730 int KdenliveDoc::height() const {
734 KUrl KdenliveDoc::url() const {
738 void KdenliveDoc::setUrl(KUrl url) {
742 void KdenliveDoc::setModified(bool mod) {
743 if (!m_url.isEmpty() && mod && KdenliveSettings::crashrecovery()) {
744 m_autoSaveTimer->start(3000);
746 if (mod == m_modified) return;
748 emit docModified(m_modified);
751 bool KdenliveDoc::isModified() const {
755 QString KdenliveDoc::description() const {
757 return i18n("Untitled") + " / " + m_profile.description;
759 return m_url.fileName() + " / " + m_profile.description;
762 void KdenliveDoc::addClip(const QDomElement &elem, const QString &clipId) {
763 DocClipBase *clip = new DocClipBase(m_clipManager, elem, clipId);
764 kDebug() << "///////// DOCUM, CREATING NEW CLIP, ID:" << clipId << ", PAR ID:" << elem.attribute("groupid");
765 m_clipManager->addClip(clip);
766 emit addProjectClip(clip);
769 void KdenliveDoc::addFolder(const QString foldername, const QString &clipId, bool edit) {
770 emit addProjectFolder(foldername, clipId, false, edit);
773 void KdenliveDoc::deleteFolder(const QString foldername, const QString &clipId) {
774 emit addProjectFolder(foldername, clipId, true);
777 void KdenliveDoc::deleteProjectClip(QList <QString> ids) {
778 for (int i = 0; i < ids.size(); ++i) {
779 emit deleteTimelineClip(ids.at(i));
780 m_clipManager->slotDeleteClip(ids.at(i));
785 void KdenliveDoc::deleteProjectFolder(QMap <QString, QString> map) {
786 QMapIterator<QString, QString> i(map);
787 while (i.hasNext()) {
789 slotDeleteFolder(i.key(), i.value());
794 void KdenliveDoc::deleteClip(const QString &clipId) {
795 emit signalDeleteProjectClip(clipId);
796 m_clipManager->deleteClip(clipId);
799 void KdenliveDoc::slotAddClipList(const KUrl::List urls, const QString group, const QString &groupId) {
800 m_clipManager->slotAddClipList(urls, group, groupId);
801 emit selectLastAddedClip(QString::number(m_clipManager->lastClipId()));
806 void KdenliveDoc::slotAddClipFile(const KUrl url, const QString group, const QString &groupId) {
807 kDebug() << "///////// DOCUM, ADD CLP: " << url;
808 m_clipManager->slotAddClipFile(url, group, groupId);
809 emit selectLastAddedClip(QString::number(m_clipManager->lastClipId()));
813 void KdenliveDoc::slotAddFolder(const QString folderName) {
814 AddFolderCommand *command = new AddFolderCommand(this, folderName, QString::number(m_clipManager->getFreeClipId()), true);
815 commandStack()->push(command);
819 void KdenliveDoc::slotDeleteFolder(const QString folderName, const QString &id) {
820 AddFolderCommand *command = new AddFolderCommand(this, folderName, id, false);
821 commandStack()->push(command);
825 void KdenliveDoc::slotEditFolder(const QString newfolderName, const QString oldfolderName, const QString &clipId) {
826 EditFolderCommand *command = new EditFolderCommand(this, newfolderName, oldfolderName, clipId, false);
827 commandStack()->push(command);
831 const QString&KdenliveDoc::getFreeClipId() {
832 return QString::number(m_clipManager->getFreeClipId());
835 DocClipBase *KdenliveDoc::getBaseClip(const QString &clipId) {
836 return m_clipManager->getClipById(clipId);
839 void KdenliveDoc::slotAddColorClipFile(const QString name, const QString color, QString duration, const QString group, const QString &groupId) {
840 m_clipManager->slotAddColorClipFile(name, color, duration, group, groupId);
844 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) {
845 m_clipManager->slotAddSlideshowClipFile(name, path, count, duration, loop, fade, luma_duration, luma_file, softness, group, groupId);
849 void KdenliveDoc::slotCreateTextClip(QString group, const QString &groupId) {
850 QString titlesFolder = projectFolder().path() + "/titles/";
851 KStandardDirs::makeDir(titlesFolder);
852 TitleWidget *dia_ui = new TitleWidget(KUrl(), titlesFolder, m_render, kapp->activeWindow());
853 if (dia_ui->exec() == QDialog::Accepted) {
854 QString titleName = "title";
856 QString path = titlesFolder + titleName + QString::number(counter).rightJustified(3, '0', false);
857 while (QFile::exists(path + ".png")) {
859 path = titlesFolder + titleName + QString::number(counter).rightJustified(3, '0', false);
861 QPixmap pix = dia_ui->renderedPixmap();
862 pix.save(path + ".png");
863 //dia_ui->saveTitle(path + ".kdenlivetitle");
864 m_clipManager->slotAddTextClipFile(path, dia_ui->xml().toString(), QString(), QString());
872 #include "kdenlivedoc.moc"