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 <mlt++/Mlt.h>
30 #include "kdenlivedoc.h"
31 #include "docclipbase.h"
32 #include "profilesdialog.h"
33 #include "kdenlivesettings.h"
35 #include "clipmanager.h"
36 #include "addfoldercommand.h"
37 #include "editfoldercommand.h"
38 #include "titlewidget.h"
39 #include "mainwindow.h"
42 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) {
43 m_clipManager = new ClipManager(this);
46 if (KIO::NetAccess::download(url.path(), tmpFile, parent)) {
48 m_document.setContent(&file, false);
50 QDomNode infoXmlNode = m_document.elementsByTagName("kdenlivedoc").at(0);
51 QDomNode westley = m_document.elementsByTagName("westley").at(0);
52 if (!infoXmlNode.isNull()) {
53 QDomElement infoXml = infoXmlNode.toElement();
54 QString profilePath = infoXml.attribute("profile");
55 m_startPos = infoXml.attribute("position").toInt();
56 m_zoom = infoXml.attribute("zoom", "7").toInt();
57 setProfilePath(profilePath);
58 double version = infoXml.attribute("version").toDouble();
59 if (version < 0.7) convertDocument(version);
61 //delete all mlt producers and instead, use Kdenlive saved producers
62 QDomNodeList prods = m_document.elementsByTagName("producer");
63 int maxprod = prods.count();
65 for (int i = 0; i < maxprod; i++) {
66 QDomNode m = prods.at(pos);
67 QString prodId = m.toElement().attribute("id");
68 if (prodId == "black" || prodId.startsWith("slowmotion"))
70 else westley.removeChild(m);
72 prods = m_document.elementsByTagName("kdenlive_producer");
73 maxprod = prods.count();
74 for (int i = 0; i < maxprod; i++) {
75 prods.at(0).toElement().setTagName("producer");
76 westley.insertBefore(prods.at(0), QDomNode());
80 QDomNodeList producers = m_document.elementsByTagName("producer");
81 const int max = producers.count();
83 m_documentLoadingStep = 100.0 / (max + m_document.elementsByTagName("entry").count());
84 parent->slotGotProgressInfo(i18n("Loading project clips"), (int) m_documentLoadingProgress);
87 for (int i = 0; i < max; i++) {
88 e = producers.item(i).cloneNode().toElement();
89 if (m_documentLoadingStep > 0) {
90 m_documentLoadingProgress += m_documentLoadingStep;
91 parent->slotGotProgressInfo(QString(), (int) m_documentLoadingProgress);
92 qApp->processEvents();
94 QString prodId = e.attribute("id");
95 if (!e.isNull() && prodId != "black" && !prodId.startsWith("slowmotion")/*&& prodId.toInt() > 0*/) {
100 QDomNode markers = m_document.elementsByTagName("markers").at(0);
101 if (!markers.isNull()) {
102 QDomNodeList markerslist = markers.childNodes();
103 int maxchild = markerslist.count();
104 for (int k = 0; k < maxchild; k++) {
105 e = markerslist.at(k).toElement();
106 if (e.tagName() == "marker") {
107 m_clipManager->getClipById(e.attribute("id"))->addSnapMarker(GenTime(e.attribute("time").toDouble()), e.attribute("comment"));
110 westley.removeChild(markers);
112 m_document.removeChild(infoXmlNode);
114 kDebug() << "Reading file: " << url.path() << ", found clips: " << producers.count();
116 parent->slotGotProgressInfo(i18n("File %1 is not a Kdenlive project file."), 100);
117 kWarning() << " NO KDENLIVE INFO FOUND IN FILE: " << url.path();
118 m_document = createEmptyDocument(tracks.x(), tracks.y());
119 setProfilePath(profileName);
121 KIO::NetAccess::removeTempFile(tmpFile);
123 KMessageBox::error(parent, KIO::NetAccess::lastErrorString());
124 parent->slotGotProgressInfo(i18n("File %1 is not a Kdenlive project file."), 100);
125 m_document = createEmptyDocument(tracks.x(), tracks.y());
126 setProfilePath(profileName);
129 m_document = createEmptyDocument(tracks.x(), tracks.y());
130 setProfilePath(profileName);
132 m_scenelist = m_document.toString();
133 kDebug() << "KDEnnlive document, init timecode: " << m_fps;
134 if (m_fps == 30000.0 / 1001.0) m_timecode.setFormat(30, true);
135 else m_timecode.setFormat((int) m_fps);
137 m_autoSaveTimer = new QTimer(this);
138 m_autoSaveTimer->setSingleShot(true);
139 connect(m_autoSaveTimer, SIGNAL(timeout()), this, SLOT(slotAutoSave()));
142 KdenliveDoc::~KdenliveDoc() {
143 delete m_commandStack;
144 delete m_clipManager;
145 delete m_autoSaveTimer;
146 m_autosave->remove();
149 QDomDocument KdenliveDoc::createEmptyDocument(const int videotracks, const int audiotracks) {
150 // Creating new document
152 QDomElement westley = doc.createElement("westley");
153 doc.appendChild(westley);
155 QDomElement tractor = doc.createElement("tractor");
156 tractor.setAttribute("id", "maintractor");
157 QDomElement multitrack = doc.createElement("multitrack");
158 QDomElement playlist = doc.createElement("playlist");
159 playlist.setAttribute("id", "black_track");
160 westley.appendChild(playlist);
164 int total = audiotracks + videotracks + 1;
166 for (int i = 1; i < total; i++) {
167 QDomElement playlist = doc.createElement("playlist");
168 playlist.setAttribute("id", "playlist" + QString::number(i));
169 westley.appendChild(playlist);
172 QDomElement track0 = doc.createElement("track");
173 track0.setAttribute("producer", "black_track");
174 tractor.appendChild(track0);
176 // create audio tracks
177 for (int i = 1; i < audiotracks + 1; i++) {
178 QDomElement track = doc.createElement("track");
179 track.setAttribute("producer", "playlist" + QString::number(i));
180 track.setAttribute("hide", "video");
181 tractor.appendChild(track);
184 // create video tracks
185 for (int i = audiotracks + 1; i < total; i++) {
186 QDomElement track = doc.createElement("track");
187 track.setAttribute("producer", "playlist" + QString::number(i));
188 tractor.appendChild(track);
191 for (uint i = 2; i < total ; i++) {
192 QDomElement transition = doc.createElement("transition");
193 transition.setAttribute("always_active", "1");
195 QDomElement property = doc.createElement("property");
196 property.setAttribute("name", "a_track");
197 QDomText value = doc.createTextNode(QString::number(1));
198 property.appendChild(value);
199 transition.appendChild(property);
201 property = doc.createElement("property");
202 property.setAttribute("name", "b_track");
203 value = doc.createTextNode(QString::number(i));
204 property.appendChild(value);
205 transition.appendChild(property);
207 property = doc.createElement("property");
208 property.setAttribute("name", "mlt_service");
209 value = doc.createTextNode("mix");
210 property.appendChild(value);
211 transition.appendChild(property);
213 property = doc.createElement("property");
214 property.setAttribute("name", "combine");
215 value = doc.createTextNode("1");
216 property.appendChild(value);
217 transition.appendChild(property);
219 property = doc.createElement("property");
220 property.setAttribute("name", "internal_added");
221 value = doc.createTextNode("237");
222 property.appendChild(value);
223 transition.appendChild(property);
224 tractor.appendChild(transition);
226 westley.appendChild(tractor);
231 void KdenliveDoc::syncGuides(QList <Guide *> guides) {
235 m_guidesXml = doc.createElement("guides");
237 for (int i = 0; i < guides.count(); i++) {
238 e = doc.createElement("guide");
239 e.setAttribute("time", guides.at(i)->position().ms() / 1000);
240 e.setAttribute("comment", guides.at(i)->label());
241 m_guidesXml.appendChild(e);
243 emit guidesUpdated();
246 QDomElement KdenliveDoc::guidesXml() const {
250 void KdenliveDoc::slotAutoSave() {
252 if (!m_autosave->isOpen() && !m_autosave->open(QIODevice::ReadWrite)) {
253 // show error: could not open the autosave file
254 kDebug() << "ERROR; CANNOT CREATE AUTOSAVE FILE";
256 kDebug() << "// AUTOSAVE FILE: " << m_autosave->fileName();
257 m_render->saveSceneList(m_autosave->fileName(), documentInfoXml());
261 void KdenliveDoc::setZoom(int factor) {
265 int KdenliveDoc::zoom() const {
269 void KdenliveDoc::convertDocument(double version) {
270 // Opening a old Kdenlive document
271 QDomNode westley = m_document.elementsByTagName("westley").at(1);
272 QDomNode tractor = m_document.elementsByTagName("tractor").at(0);
273 QDomNode kdenlivedoc = m_document.elementsByTagName("kdenlivedoc").at(0);
274 QDomNode multitrack = m_document.elementsByTagName("multitrack").at(0);
275 QDomNodeList playlists = m_document.elementsByTagName("playlist");
277 m_startPos = kdenlivedoc.toElement().attribute("timeline_position").toInt();
279 QDomNode props = m_document.elementsByTagName("properties").at(0).toElement();
280 QString profile = props.toElement().attribute("videoprofile");
281 if (profile == "dv_wide") profile = "dv_pal_wide";
282 setProfilePath(profile);
284 // move playlists outside of tractor and add the tracks instead
285 int max = playlists.count();
286 for (int i = 0; i < max; i++) {
287 QDomNode n = playlists.at(i);
288 westley.insertBefore(n, QDomNode());
289 QDomElement pl = n.toElement();
290 QDomElement track = m_document.createElement("track");
291 QString trackType = pl.attribute("hide");
292 if (!trackType.isEmpty()) track.setAttribute("hide", trackType);
293 QString playlist_id = pl.attribute("id");
294 if (playlist_id.isEmpty()) {
295 playlist_id = "black_track";
296 pl.setAttribute("id", playlist_id);
298 track.setAttribute("producer", playlist_id);
299 //tractor.appendChild(track);
300 tractor.insertAfter(track, QDomNode());
302 tractor.removeChild(multitrack);
304 // audio track mixing transitions should not be added to track view, so add required attribute
305 QDomNodeList transitions = m_document.elementsByTagName("transition");
306 max = transitions.count();
307 for (int i = 0; i < max; i++) {
308 QDomElement tr = transitions.at(i).toElement();
309 if (tr.attribute("combine") == "1" && tr.attribute("mlt_service") == "mix") {
310 QDomElement property = m_document.createElement("property");
311 property.setAttribute("name", "internal_added");
312 QDomText value = m_document.createTextNode("237");
313 property.appendChild(value);
314 tr.appendChild(property);
316 // convert transition
317 QDomNamedNodeMap attrs = tr.attributes();
318 for (unsigned int j = 0; j < attrs.count(); j++) {
319 QString attrName = attrs.item(j).nodeName();
320 if (attrName != "in" && attrName != "out" && attrName != "id") {
321 QDomElement property = m_document.createElement("property");
322 property.setAttribute("name", attrName);
323 QDomText value = m_document.createTextNode(attrs.item(j).nodeValue());
324 property.appendChild(value);
325 tr.appendChild(property);
331 // move transitions after tracks
332 for (int i = 0; i < max; i++) {
333 tractor.insertAfter(transitions.at(0), QDomNode());
336 // Fix filters format
337 QDomNodeList entries = m_document.elementsByTagName("entry");
338 max = entries.count();
339 for (int i = 0; i < max; i++) {
342 QDomNode m = entries.at(i).firstChild();
343 while (!m.isNull()) {
344 if (m.toElement().tagName() == "filter") {
345 QDomElement filt = m.toElement();
346 QDomNamedNodeMap attrs = filt.attributes();
347 QString current_id = filt.attribute("kdenlive_id");
348 if (current_id != last_id) {
350 last_id = current_id;
352 QDomElement e = m_document.createElement("property");
353 e.setAttribute("name", "kdenlive_ix");
354 QDomText value = m_document.createTextNode(QString::number(effectix));
355 e.appendChild(value);
357 for (int j = 0; j < attrs.count(); j++) {
358 QDomAttr a = attrs.item(j).toAttr();
360 kDebug() << " FILTER; adding :" << a.name() << ":" << a.value();
361 QDomElement e = m_document.createElement("property");
362 e.setAttribute("name", a.name());
363 QDomText value = m_document.createTextNode(a.value());
364 e.appendChild(value);
375 QDomNodeList filters = m_document.elementsByTagName("filter");
376 max = filters.count();
379 for (int i = 0; i < max; i++) {
380 QDomElement filt = filters.at(i).toElement();
381 QDomNamedNodeMap attrs = filt.attributes();
382 QString current_id = filt.attribute("kdenlive_id");
383 if (current_id != last_id) {
385 last_id = current_id;
387 QDomElement e = m_document.createElement("property");
388 e.setAttribute("name", "kdenlive_ix");
389 QDomText value = m_document.createTextNode(QString::number(1));
390 e.appendChild(value);
392 for (int j = 0; j < attrs.count(); j++) {
393 QDomAttr a = attrs.item(j).toAttr();
395 kDebug() << " FILTER; adding :" << a.name() << ":" << a.value();
396 QDomElement e = m_document.createElement("property");
397 e.setAttribute("name", a.name());
398 QDomText value = m_document.createTextNode(a.value());
399 e.appendChild(value);
406 QDomNodeList producers = westley.toElement().elementsByTagName("producer");
407 max = producers.count();
408 for (int i = 0; i < max; i++) {
409 QDomElement prod = producers.at(i).toElement();
410 if (prod.attribute("mlt_service") == "framebuffer") {
411 QString slowmotionprod = prod.attribute("resource");
412 slowmotionprod.replace(':', '?');
413 kDebug() << "// FOUND WRONG SLOWMO, new: " << slowmotionprod;
414 prod.setAttribute("resource", slowmotionprod);
417 // move producers to correct place, markers to a global list, fix clip descriptions
418 QDomElement markers = m_document.createElement("markers");
419 producers = m_document.elementsByTagName("producer");
420 max = producers.count();
421 for (int i = 0; i < max; i++) {
422 QDomElement prod = producers.at(0).toElement();
423 QDomNode m = prod.firstChild();
425 if (m.toElement().tagName() == "markers") {
426 QDomNodeList prodchilds = m.childNodes();
427 int maxchild = prodchilds.count();
428 for (int k = 0; k < maxchild; k++) {
429 QDomElement mark = prodchilds.at(0).toElement();
430 mark.setAttribute("id", prod.attribute("id"));
431 markers.insertAfter(mark, QDomNode());
434 } else if (prod.attribute("type").toInt() == TEXT) {
435 // convert title clip
436 if (m.toElement().tagName() == "textclip") {
438 QDomElement titleclip = m.toElement();
439 QDomElement title = tdoc.createElement("kdenlivetitle");
440 tdoc.appendChild(title);
441 QDomNodeList objects = titleclip.childNodes();
442 int maxchild = objects.count();
443 for (int k = 0; k < maxchild; k++) {
445 QDomElement ob = objects.at(k).toElement();
446 if (ob.attribute("type") == "3") {
448 QDomElement item = tdoc.createElement("item");
449 item.setAttribute("z-index", ob.attribute("z"));
450 item.setAttribute("type", "QGraphicsTextItem");
451 QDomElement position = tdoc.createElement("position");
452 position.setAttribute("x", ob.attribute("x"));
453 position.setAttribute("y", ob.attribute("y"));
454 QDomElement content = tdoc.createElement("content");
455 content.setAttribute("font", ob.attribute("font_family"));
456 content.setAttribute("font-size", ob.attribute("font_size"));
457 content.setAttribute("font-bold", ob.attribute("bold"));
458 content.setAttribute("font-italic", ob.attribute("italic"));
459 content.setAttribute("font-underline", ob.attribute("underline"));
460 QString col = ob.attribute("color");
462 content.setAttribute("font-color", colorToString(c));
463 QDomText conttxt = tdoc.createTextNode(ob.attribute("text"));
464 content.appendChild(conttxt);
465 item.appendChild(position);
466 item.appendChild(content);
467 title.appendChild(item);
468 } else if (ob.attribute("type") == "5") {
470 QDomElement item = tdoc.createElement("item");
471 item.setAttribute("z-index", ob.attribute("z"));
472 item.setAttribute("type", "QGraphicsRectItem");
473 QDomElement position = tdoc.createElement("position");
474 position.setAttribute("x", ob.attribute("x"));
475 position.setAttribute("y", ob.attribute("y"));
476 QDomElement content = tdoc.createElement("content");
477 QString col = ob.attribute("color");
479 content.setAttribute("brushcolor", colorToString(c));
480 QString rect = "0,0,";
481 rect.append(ob.attribute("width"));
483 rect.append(ob.attribute("height"));
484 content.setAttribute("rect", rect);
485 item.appendChild(position);
486 item.appendChild(content);
487 title.appendChild(item);
490 prod.setAttribute("xmldata", tdoc.toString());
491 QString titlesFolder = projectFolder().path() + "/titles/";
492 KStandardDirs::makeDir(titlesFolder);
493 QString titleName = "title";
495 QString path = titlesFolder + titleName + QString::number(counter).rightJustified(3, '0', false);
496 while (QFile::exists(path + ".png")) {
498 path = titlesFolder + titleName + QString::number(counter).rightJustified(3, '0', false);
500 prod.setAttribute("xml", path);
501 prod.setAttribute("resource", path + ".png");
502 //kDebug()<<"TITLE DATA:\n"<<tdoc.toString();
506 } else if (m.isText()) {
507 QString comment = m.nodeValue();
508 if (!comment.isEmpty()) {
509 prod.setAttribute("description", comment);
514 int duration = prod.attribute("duration").toInt();
515 if (duration > 0) prod.setAttribute("out", QString::number(duration));
516 westley.insertBefore(prod, QDomNode());
520 QDomNode westley0 = m_document.elementsByTagName("westley").at(0);
521 if (!markers.firstChild().isNull()) westley0.appendChild(markers);
522 westley0.removeChild(kdenlivedoc);
524 QDomNodeList elements = westley.childNodes();
525 max = elements.count();
526 for (int i = 0; i < max; i++) {
527 QDomElement prod = elements.at(0).toElement();
528 westley0.insertAfter(prod, QDomNode());
531 westley0.removeChild(westley);
533 //kDebug() << "///////////////// CONVERTED DOC:";
534 //kDebug() << m_document.toString();
535 //kDebug() << "///////////////// END CONVERTED DOC:";
538 QString KdenliveDoc::colorToString(const QColor& c) {
539 QString ret = "%1,%2,%3,%4";
540 ret = ret.arg(c.red()).arg(c.green()).arg(c.blue()).arg(c.alpha());
544 QDomElement KdenliveDoc::documentInfoXml() {
547 QDomElement addedXml = doc.createElement("kdenlivedoc");
548 QDomElement markers = doc.createElement("markers");
549 addedXml.setAttribute("version", "0.7");
550 addedXml.setAttribute("profile", profilePath());
551 addedXml.setAttribute("position", m_render->seekPosition().frames(m_fps));
552 addedXml.setAttribute("zoom", m_zoom);
553 QList <DocClipBase*> list = m_clipManager->documentClipList();
554 for (int i = 0; i < list.count(); i++) {
555 e = list.at(i)->toXML();
556 e.setTagName("kdenlive_producer");
557 addedXml.appendChild(doc.importNode(e, true));
558 QList < CommentedTime > marks = list.at(i)->commentedSnapMarkers();
559 for (int j = 0; j < marks.count(); j++) {
560 QDomElement marker = doc.createElement("marker");
561 marker.setAttribute("time", marks.at(j).time().ms() / 1000);
562 marker.setAttribute("comment", marks.at(j).comment());
563 marker.setAttribute("id", e.attribute("id"));
564 markers.appendChild(marker);
567 addedXml.appendChild(markers);
568 if (!m_guidesXml.isNull()) addedXml.appendChild(doc.importNode(m_guidesXml, true));
569 //kDebug() << m_document.toString();
574 ClipManager *KdenliveDoc::clipManager() {
575 return m_clipManager;
578 KUrl KdenliveDoc::projectFolder() const {
579 if (m_projectFolder.isEmpty()) return KUrl(KStandardDirs::locateLocal("appdata", "/projects/"));
580 return m_projectFolder;
583 QString KdenliveDoc::getDocumentStandard() {
584 //WARNING: this way to tell the video standard is a bit hackish...
585 if (m_profile.description.contains("pal", Qt::CaseInsensitive) || m_profile.description.contains("25", Qt::CaseInsensitive) || m_profile.description.contains("50", Qt::CaseInsensitive)) return "PAL";
589 QString KdenliveDoc::profilePath() const {
590 return m_profile.path;
593 MltVideoProfile KdenliveDoc::mltProfile() const {
597 void KdenliveDoc::setProfilePath(QString path) {
598 if (path.isEmpty()) path = KdenliveSettings::default_profile();
599 if (path.isEmpty()) path = "dv_pal";
600 m_profile = ProfilesDialog::getVideoProfile(path);
601 KdenliveSettings::setProject_display_ratio((double) m_profile.display_aspect_num / m_profile.display_aspect_den);
602 m_fps = (double) m_profile.frame_rate_num / m_profile.frame_rate_den;
603 m_width = m_profile.width;
604 m_height = m_profile.height;
605 kDebug() << "KDEnnlive document, init timecode from path: " << path << ", " << m_fps;
606 if (m_fps == 30000.0 / 1001.0) m_timecode.setFormat(30, true);
607 else m_timecode.setFormat((int) m_fps);
610 const double KdenliveDoc::dar() {
611 return (double) m_profile.display_aspect_num / m_profile.display_aspect_den;
614 void KdenliveDoc::setThumbsProgress(const QString &message, int progress) {
615 emit progressInfo(message, progress);
618 void KdenliveDoc::loadingProgressed() {
619 m_documentLoadingProgress += m_documentLoadingStep;
620 emit progressInfo(QString(), (int) m_documentLoadingProgress);
623 QUndoStack *KdenliveDoc::commandStack() {
624 return m_commandStack;
627 void KdenliveDoc::setRenderer(Render *render) {
628 if (m_render) return;
630 emit progressInfo(i18n("Loading playlist..."), 0);
631 qApp->processEvents();
633 m_render->setSceneList(m_document.toString(), m_startPos);
636 emit progressInfo(QString(), -1);
639 void KdenliveDoc::checkProjectClips() {
640 if (m_render == NULL) return;
641 QList <Mlt::Producer *> prods = m_render->producersList();
643 for (int i = 0; i < prods.count(); i++) {
644 id = prods.at(i)->get("id");
645 DocClipBase *clip = m_clipManager->getClipById(id);
646 if (clip && clip->producer() == NULL) {
647 clip->setProducer(prods.at(i));
652 Render *KdenliveDoc::renderer() {
656 void KdenliveDoc::updateClip(const QString &id) {
657 emit updateClipDisplay(id);
660 int KdenliveDoc::getFramePos(QString duration) {
661 return m_timecode.getFrameCount(duration, m_fps);
664 QString KdenliveDoc::producerName(const QString &id) {
665 QString result = "unnamed";
666 QDomNodeList prods = producersList();
667 int ct = prods.count();
668 for (int i = 0; i < ct ; i++) {
669 QDomElement e = prods.item(i).toElement();
670 if (e.attribute("id") != "black" && e.attribute("id") == id) {
671 result = e.attribute("name");
672 if (result.isEmpty()) result = KUrl(e.attribute("resource")).fileName();
679 void KdenliveDoc::setProducerDuration(const QString &id, int duration) {
680 QDomNodeList prods = producersList();
681 int ct = prods.count();
682 for (int i = 0; i < ct ; i++) {
683 QDomElement e = prods.item(i).toElement();
684 if (e.attribute("id") != "black" && e.attribute("id") == id) {
685 e.setAttribute("duration", QString::number(duration));
691 int KdenliveDoc::getProducerDuration(const QString &id) {
693 QDomNodeList prods = producersList();
694 int ct = prods.count();
695 for (int i = 0; i < ct ; i++) {
696 QDomElement e = prods.item(i).toElement();
697 if (e.attribute("id") != "black" && e.attribute("id") == id) {
698 result = e.attribute("duration").toInt();
706 QDomDocument KdenliveDoc::generateSceneList() {
708 QDomElement westley = doc.createElement("westley");
709 doc.appendChild(westley);
710 QDomElement prod = doc.createElement("producer");
713 QDomDocument KdenliveDoc::toXml() const {
717 Timecode KdenliveDoc::timecode() const {
721 QDomNodeList KdenliveDoc::producersList() {
722 return m_document.elementsByTagName("producer");
725 void KdenliveDoc::backupMltPlaylist() {
726 if (m_render) m_scenelist = m_render->sceneList();
729 double KdenliveDoc::projectDuration() const {
730 if (m_render) return GenTime(m_render->getLength(), m_fps).ms() / 1000;
733 double KdenliveDoc::fps() const {
737 int KdenliveDoc::width() const {
741 int KdenliveDoc::height() const {
745 KUrl KdenliveDoc::url() const {
749 void KdenliveDoc::setUrl(KUrl url) {
753 void KdenliveDoc::setModified(bool mod) {
754 if (!m_url.isEmpty() && mod && KdenliveSettings::crashrecovery()) {
755 m_autoSaveTimer->start(3000);
757 if (mod == m_modified) return;
759 emit docModified(m_modified);
762 bool KdenliveDoc::isModified() const {
766 QString KdenliveDoc::description() const {
768 return i18n("Untitled") + " / " + m_profile.description;
770 return m_url.fileName() + " / " + m_profile.description;
773 void KdenliveDoc::addClip(const QDomElement &elem, const QString &clipId) {
774 DocClipBase *clip = new DocClipBase(m_clipManager, elem, clipId);
775 kDebug() << "///////// DOCUM, CREATING NEW CLIP, ID:" << clipId << ", PAR ID:" << elem.attribute("groupid");
776 m_clipManager->addClip(clip);
777 emit addProjectClip(clip);
780 void KdenliveDoc::addFolder(const QString foldername, const QString &clipId, bool edit) {
781 emit addProjectFolder(foldername, clipId, false, edit);
784 void KdenliveDoc::deleteFolder(const QString foldername, const QString &clipId) {
785 emit addProjectFolder(foldername, clipId, true);
788 void KdenliveDoc::deleteProjectClip(QList <QString> ids) {
789 for (int i = 0; i < ids.size(); ++i) {
790 emit deleteTimelineClip(ids.at(i));
791 m_clipManager->slotDeleteClip(ids.at(i));
796 void KdenliveDoc::deleteProjectFolder(QMap <QString, QString> map) {
797 QMapIterator<QString, QString> i(map);
798 while (i.hasNext()) {
800 slotDeleteFolder(i.key(), i.value());
805 void KdenliveDoc::deleteClip(const QString &clipId) {
806 emit signalDeleteProjectClip(clipId);
807 m_clipManager->deleteClip(clipId);
810 void KdenliveDoc::slotAddClipList(const KUrl::List urls, const QString group, const QString &groupId) {
811 m_clipManager->slotAddClipList(urls, group, groupId);
812 emit selectLastAddedClip(QString::number(m_clipManager->lastClipId()));
817 void KdenliveDoc::slotAddClipFile(const KUrl url, const QString group, const QString &groupId) {
818 kDebug() << "///////// DOCUM, ADD CLP: " << url;
819 m_clipManager->slotAddClipFile(url, group, groupId);
820 emit selectLastAddedClip(QString::number(m_clipManager->lastClipId()));
824 void KdenliveDoc::slotAddFolder(const QString folderName) {
825 AddFolderCommand *command = new AddFolderCommand(this, folderName, QString::number(m_clipManager->getFreeClipId()), true);
826 commandStack()->push(command);
830 void KdenliveDoc::slotDeleteFolder(const QString folderName, const QString &id) {
831 AddFolderCommand *command = new AddFolderCommand(this, folderName, id, false);
832 commandStack()->push(command);
836 void KdenliveDoc::slotEditFolder(const QString newfolderName, const QString oldfolderName, const QString &clipId) {
837 EditFolderCommand *command = new EditFolderCommand(this, newfolderName, oldfolderName, clipId, false);
838 commandStack()->push(command);
842 const QString&KdenliveDoc::getFreeClipId() {
843 return QString::number(m_clipManager->getFreeClipId());
846 DocClipBase *KdenliveDoc::getBaseClip(const QString &clipId) {
847 return m_clipManager->getClipById(clipId);
850 void KdenliveDoc::slotAddColorClipFile(const QString name, const QString color, QString duration, const QString group, const QString &groupId) {
851 m_clipManager->slotAddColorClipFile(name, color, duration, group, groupId);
855 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) {
856 m_clipManager->slotAddSlideshowClipFile(name, path, count, duration, loop, fade, luma_duration, luma_file, softness, group, groupId);
860 void KdenliveDoc::slotCreateTextClip(QString group, const QString &groupId) {
861 QString titlesFolder = projectFolder().path() + "/titles/";
862 KStandardDirs::makeDir(titlesFolder);
863 TitleWidget *dia_ui = new TitleWidget(KUrl(), titlesFolder, m_render, kapp->activeWindow());
864 if (dia_ui->exec() == QDialog::Accepted) {
865 QString titleName = "title";
867 QString path = titlesFolder + titleName + QString::number(counter).rightJustified(3, '0', false);
868 while (QFile::exists(path + ".png")) {
870 path = titlesFolder + titleName + QString::number(counter).rightJustified(3, '0', false);
872 QPixmap pix = dia_ui->renderedPixmap();
873 pix.save(path + ".png");
874 //dia_ui->saveTitle(path + ".kdenlivetitle");
875 m_clipManager->slotAddTextClipFile(path, dia_ui->xml().toString(), QString(), QString());
883 #include "kdenlivedoc.moc"