1 /***************************************************************************
2 * Copyright (C) 2008 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 "documentchecker.h"
23 #include "docclipbase.h"
24 #include "titlewidget.h"
25 #include "definitions.h"
26 #include "kdenlivesettings.h"
29 #include <KGlobalSettings>
31 #include <KIO/NetAccess>
32 #include <KFileDialog>
33 #include <KApplication>
34 #include <KUrlRequesterDialog>
35 #include <KMessageBox>
37 #include <QTreeWidgetItem>
39 #include <QHeaderView>
43 #include <QCryptographicHash>
45 const int hashRole = Qt::UserRole;
46 const int sizeRole = Qt::UserRole + 1;
47 const int idRole = Qt::UserRole + 2;
48 const int statusRole = Qt::UserRole + 3;
49 const int typeRole = Qt::UserRole + 4;
50 const int typeOriginalResource = Qt::UserRole + 5;
51 const int resetDurationRole = Qt::UserRole + 6;
53 const int CLIPMISSING = 0;
55 const int CLIPPLACEHOLDER = 2;
56 const int CLIPWRONGDURATION = 3;
57 const int PROXYMISSING = 4;
59 const int LUMAMISSING = 10;
60 const int LUMAOK = 11;
61 const int LUMAPLACEHOLDER = 12;
63 enum TITLECLIPTYPE { TITLE_IMAGE_ELEMENT = 20, TITLE_FONT_ELEMENT = 21 };
65 DocumentChecker::DocumentChecker(QDomNodeList infoproducers, QDomDocument doc):
66 m_info(infoproducers), m_doc(doc), m_dialog(NULL)
72 bool DocumentChecker::hasErrorInClips()
77 QDomNodeList documentProducers = m_doc.elementsByTagName("producer");
78 QList <QDomElement> wrongDurationClips;
79 QList <QDomElement> missingProxies;
80 for (int i = 0; i < m_info.count(); i++) {
81 e = m_info.item(i).toElement();
82 clipType = e.attribute("type").toInt();
83 if (clipType == COLOR) continue;
84 if (clipType != TEXT && clipType != IMAGE && clipType != SLIDESHOW) {
85 QString id = e.attribute("id");
86 int duration = e.attribute("duration").toInt();
88 // Check that the duration is in sync between Kdenlive's info and MLT's playlist
89 for (int j = 0; j < documentProducers.count(); j++) {
90 QDomElement mltProd = documentProducers.at(j).toElement();
91 QString prodId = mltProd.attribute("id");
92 // Don't check slowmotion clips for now... (TODO?)
93 if (prodId.startsWith("slowmotion")) continue;
94 if (prodId.contains("_")) prodId = prodId.section("_", 0, 0);
95 if (prodId != id) continue;
96 if (mltDuration > 0 ) {
97 // We have several MLT producers for the same clip (probably track producers)
98 int newLength = EffectsList::property(mltProd, "length").toInt();
99 if (newLength != mltDuration) {
100 // we have a different duration for the same clip, that is not safe
101 e.setAttribute("_resetDuration", 1);
104 mltDuration = EffectsList::property(mltProd, "length").toInt();
105 if (mltDuration != duration) {
107 e.setAttribute("_mismatch", mltDuration);
108 if (mltDuration == 15000) {
109 // a length of 15000 might indicate a wrong clip length since it is a default length
110 e.setAttribute("_resetDuration", 1);
112 if (!wrongDurationClips.contains(e)) wrongDurationClips.append(e);
117 if (clipType == TEXT) {
118 //TODO: Check is clip template is missing (xmltemplate) or hash changed
119 QStringList images = TitleWidget::extractImageList(e.attribute("xmldata"));
120 QStringList fonts = TitleWidget::extractFontList(e.attribute("xmldata"));
121 checkMissingImages(images, fonts, e.attribute("id"), e.attribute("name"));
124 resource = e.attribute("resource");
125 if (e.hasAttribute("proxy")) {
126 QString proxyresource = e.attribute("proxy");
127 if (!proxyresource.isEmpty() && proxyresource != "-" && !KIO::NetAccess::exists(KUrl(proxyresource), KIO::NetAccess::SourceSide, 0)) {
128 // Missing clip found
129 missingProxies.append(e);
132 if (clipType == SLIDESHOW) resource = KUrl(resource).directory();
133 if (!KIO::NetAccess::exists(KUrl(resource), KIO::NetAccess::SourceSide, 0)) {
134 // Missing clip found
135 m_missingClips.append(e);
137 // Check if the clip has changed
138 if (clipType != SLIDESHOW && e.hasAttribute("file_hash")) {
139 if (e.attribute("file_hash") != DocClipBase::getHash(e.attribute("resource")))
140 e.removeAttribute("file_hash");
145 QStringList missingLumas;
146 QString root = m_doc.documentElement().attribute("root");
147 if (!root.isEmpty()) root = KUrl(root).path(KUrl::AddTrailingSlash);
148 QDomNodeList trans = m_doc.elementsByTagName("transition");
149 for (int i = 0; i < trans.count(); i++) {
150 QString luma = getProperty(trans.at(i).toElement(), "luma");
151 if (!luma.isEmpty()) {
152 QString lumaPath = luma;
153 if (!lumaPath.startsWith('/')) lumaPath.prepend(root);
154 if (!QFile::exists(lumaPath) && !missingLumas.contains(luma)) {
155 missingLumas.append(luma);
160 if (m_missingClips.isEmpty() && missingLumas.isEmpty() && wrongDurationClips.isEmpty() && missingProxies.isEmpty())
163 m_dialog = new QDialog();
164 m_dialog->setFont(KGlobalSettings::toolBarFont());
165 m_ui.setupUi(m_dialog);
167 foreach(const QString l, missingLumas) {
168 QTreeWidgetItem *item = new QTreeWidgetItem(m_ui.treeWidget, QStringList() << i18n("Luma file") << l);
169 item->setIcon(0, KIcon("dialog-close"));
170 item->setData(0, idRole, l);
171 item->setData(0, statusRole, LUMAMISSING);
174 m_ui.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
175 for (int i = 0; i < m_missingClips.count(); i++) {
176 e = m_missingClips.at(i).toElement();
178 int t = e.attribute("type").toInt();
181 clipType = i18n("Video clip");
184 clipType = i18n("Mute video clip");
187 clipType = i18n("Audio clip");
190 clipType = i18n("Playlist clip");
193 clipType = i18n("Image clip");
196 clipType = i18n("Slideshow clip");
198 case TITLE_IMAGE_ELEMENT:
199 clipType = i18n("Title Image");
201 case TITLE_FONT_ELEMENT:
202 clipType = i18n("Title Font");
205 clipType = i18n("Video clip");
207 QTreeWidgetItem *item = new QTreeWidgetItem(m_ui.treeWidget, QStringList() << clipType);
208 if (t == TITLE_IMAGE_ELEMENT) {
209 item->setIcon(0, KIcon("dialog-warning"));
210 item->setToolTip(1, e.attribute("name"));
211 item->setText(1, e.attribute("resource"));
212 item->setData(0, statusRole, CLIPPLACEHOLDER);
213 item->setData(0, typeOriginalResource, e.attribute("resource"));
214 } else if (t == TITLE_FONT_ELEMENT) {
215 item->setIcon(0, KIcon("dialog-warning"));
216 item->setToolTip(1, e.attribute("name"));
217 QString ft = e.attribute("resource");
218 QString newft = QFontInfo(QFont(ft)).family();
219 item->setText(1, i18n("%1 will be replaced by %2", ft, newft));
220 item->setData(0, statusRole, CLIPPLACEHOLDER);
222 item->setIcon(0, KIcon("dialog-close"));
223 item->setText(1, e.attribute("resource"));
224 item->setData(0, hashRole, e.attribute("file_hash"));
225 item->setData(0, sizeRole, e.attribute("file_size"));
226 item->setData(0, statusRole, CLIPMISSING);
228 item->setData(0, typeRole, t);
229 item->setData(0, idRole, e.attribute("id"));
230 item->setToolTip(0, i18n("Missing item"));
233 if (m_missingClips.count() > 0) {
234 if (wrongDurationClips.count() > 0) {
235 m_ui.infoLabel->setText(i18n("The project file contains missing clips or files and clip duration mismatch"));
238 m_ui.infoLabel->setText(i18n("The project file contains missing clips or files"));
241 else if (wrongDurationClips.count() > 0) {
242 m_ui.infoLabel->setText(i18n("The project file contains clips with duration mismatch"));
244 if (missingProxies.count() > 0) {
245 if (!m_ui.infoLabel->text().isEmpty()) m_ui.infoLabel->setText(m_ui.infoLabel->text() + ". ");
246 m_ui.infoLabel->setText(m_ui.infoLabel->text() + i18n("Missing proxies will be recreated after opening."));
249 m_ui.removeSelected->setEnabled(!m_missingClips.isEmpty());
250 m_ui.recursiveSearch->setEnabled(!m_missingClips.isEmpty() || !missingLumas.isEmpty());
251 m_ui.usePlaceholders->setEnabled(!m_missingClips.isEmpty());
252 m_ui.fixDuration->setEnabled(!wrongDurationClips.isEmpty());
254 for (int i = 0; i < wrongDurationClips.count(); i++) {
255 e = wrongDurationClips.at(i).toElement();
257 int t = e.attribute("type").toInt();
260 clipType = i18n("Video clip");
263 clipType = i18n("Mute video clip");
266 clipType = i18n("Audio clip");
269 clipType = i18n("Playlist clip");
272 clipType = i18n("Image clip");
275 clipType = i18n("Slideshow clip");
278 clipType = i18n("Video clip");
280 QTreeWidgetItem *item = new QTreeWidgetItem(m_ui.treeWidget, QStringList() << clipType);
281 item->setIcon(0, KIcon("timeadjust"));
282 item->setText(1, e.attribute("resource"));
283 item->setData(0, hashRole, e.attribute("file_hash"));
284 item->setData(0, sizeRole, e.attribute("_mismatch"));
285 e.removeAttribute("_mismatch");
286 item->setData(0, resetDurationRole, (int) e.hasAttribute("_resetDuration"));
287 e.removeAttribute("_resetDuration");
288 item->setData(0, statusRole, CLIPWRONGDURATION);
289 item->setData(0, typeRole, t);
290 item->setData(0, idRole, e.attribute("id"));
291 item->setToolTip(0, i18n("Duration mismatch"));
294 if (missingProxies.count() > 0) {
295 QTreeWidgetItem *item = new QTreeWidgetItem(m_ui.treeWidget, QStringList() << i18n("Proxy clip"));
296 item->setIcon(0, KIcon("dialog-warning"));
297 item->setText(1, i18n("%1 missing proxy clips, will be recreated on project opening", missingProxies.count()));
298 item->setData(0, hashRole, e.attribute("file_hash"));
299 item->setData(0, statusRole, PROXYMISSING);
300 item->setToolTip(0, i18n("Missing proxy"));
303 for (int i = 0; i < missingProxies.count(); i++) {
304 e = missingProxies.at(i).toElement();
306 QString realPath = e.attribute("resource");
307 QString id = e.attribute("id");
308 // Replace proxy url with real clip in MLT producers
309 QDomNodeList properties;
311 QDomElement property;
312 for (int j = 0; j < documentProducers.count(); j++) {
313 mltProd = documentProducers.at(j).toElement();
314 QString prodId = mltProd.attribute("id");
315 bool slowmotion = false;
316 if (prodId.startsWith("slowmotion")) {
318 prodId = prodId.section(':', 1, 1);
320 if (prodId.contains('_')) prodId = prodId.section('_', 0, 0);
322 // Hit, we must replace url
323 properties = mltProd.childNodes();
324 for (int k = 0; k < properties.count(); ++k) {
325 property = properties.item(k).toElement();
326 if (property.attribute("name") == "resource") {
327 QString resource = property.firstChild().nodeValue();
329 if (slowmotion) suffix = "?" + resource.section('?', -1);
330 property.firstChild().setNodeValue(realPath + suffix);
338 if (missingProxies.count() > 0) {
339 // original doc was modified
340 QDomNode infoXmlNode = m_doc.elementsByTagName("kdenlivedoc").at(0);
341 QDomElement infoXml = infoXmlNode.toElement();
342 infoXml.setAttribute("modified", "1");
345 connect(m_ui.recursiveSearch, SIGNAL(pressed()), this, SLOT(slotSearchClips()));
346 connect(m_ui.usePlaceholders, SIGNAL(pressed()), this, SLOT(slotPlaceholders()));
347 connect(m_ui.removeSelected, SIGNAL(pressed()), this, SLOT(slotDeleteSelected()));
348 connect(m_ui.fixDuration, SIGNAL(pressed()), this, SLOT(slotFixDuration()));
349 connect(m_ui.treeWidget, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)), this, SLOT(slotEditItem(QTreeWidgetItem *, int)));
350 connect(m_ui.treeWidget, SIGNAL(itemSelectionChanged()), this, SLOT(slotCheckButtons()));
352 if (m_ui.treeWidget->topLevelItem(0)) m_ui.treeWidget->setCurrentItem(m_ui.treeWidget->topLevelItem(0));
354 int acceptMissing = m_dialog->exec();
355 if (acceptMissing == QDialog::Accepted) acceptDialog();
356 return (acceptMissing != QDialog::Accepted);
359 DocumentChecker::~DocumentChecker()
361 if (m_dialog) delete m_dialog;
365 QString DocumentChecker::getProperty(QDomElement effect, const QString &name)
367 QDomNodeList params = effect.elementsByTagName("property");
368 for (int i = 0; i < params.count(); i++) {
369 QDomElement e = params.item(i).toElement();
370 if (e.attribute("name") == name) {
371 return e.firstChild().nodeValue();
377 void DocumentChecker::setProperty(QDomElement effect, const QString &name, const QString value)
379 QDomNodeList params = effect.elementsByTagName("property");
380 for (int i = 0; i < params.count(); i++) {
381 QDomElement e = params.item(i).toElement();
382 if (e.attribute("name") == name) {
383 e.firstChild().setNodeValue(value);
388 void DocumentChecker::slotSearchClips()
390 QString newpath = KFileDialog::getExistingDirectory(KUrl("kfiledialog:///clipfolder"), kapp->activeWindow(), i18n("Clips folder"));
391 if (newpath.isEmpty()) return;
394 m_ui.recursiveSearch->setEnabled(false);
395 QTreeWidgetItem *child = m_ui.treeWidget->topLevelItem(ix);
396 QDir searchDir(newpath);
398 if (child->data(0, statusRole).toInt() == CLIPMISSING) {
399 QString clipPath = searchFileRecursively(searchDir, child->data(0, sizeRole).toString(), child->data(0, hashRole).toString());
400 if (!clipPath.isEmpty()) {
402 child->setText(1, clipPath);
403 child->setIcon(0, KIcon("dialog-ok"));
404 child->setData(0, statusRole, CLIPOK);
406 } else if (child->data(0, statusRole).toInt() == LUMAMISSING) {
407 QString fileName = searchLuma(child->data(0, idRole).toString());
408 if (!fileName.isEmpty()) {
410 child->setText(1, fileName);
411 child->setIcon(0, KIcon("dialog-ok"));
412 child->setData(0, statusRole, LUMAOK);
415 else if (child->data(0, typeRole).toInt() == TITLE_IMAGE_ELEMENT && child->data(0, statusRole).toInt() == CLIPPLACEHOLDER) {
416 // Search missing title images
417 QString missingFileName = KUrl(child->text(1)).fileName();
418 QString newPath = searchPathRecursively(searchDir, missingFileName);
419 if (!newPath.isEmpty()) {
422 child->setText(1, newPath);
423 child->setIcon(0, KIcon("dialog-ok"));
424 child->setData(0, statusRole, CLIPOK);
428 child = m_ui.treeWidget->topLevelItem(ix);
430 m_ui.recursiveSearch->setEnabled(true);
432 // original doc was modified
433 QDomNode infoXmlNode = m_doc.elementsByTagName("kdenlivedoc").at(0);
434 QDomElement infoXml = infoXmlNode.toElement();
435 infoXml.setAttribute("modified", "1");
441 QString DocumentChecker::searchLuma(QString file) const
443 KUrl searchPath(KdenliveSettings::mltpath());
444 if (file.contains("PAL"))
445 searchPath.cd("../lumas/PAL");
447 searchPath.cd("../lumas/NTSC");
448 QString result = searchPath.path(KUrl::AddTrailingSlash) + KUrl(file).fileName();
449 if (QFile::exists(result))
451 // try to find luma in application path
453 searchPath = KUrl(QCoreApplication::applicationDirPath());
454 searchPath.cd("../share/apps/kdenlive/lumas");
455 result = searchPath.path(KUrl::AddTrailingSlash) + KUrl(file).fileName();
456 if (QFile::exists(result))
461 QString DocumentChecker::searchPathRecursively(const QDir &dir, const QString &fileName) const
463 QString foundFileName;
467 searchDir.setNameFilters(filters);
468 QStringList filesAndDirs = searchDir.entryList(QDir::Files | QDir::Readable);
469 if (!filesAndDirs.isEmpty()) return searchDir.absoluteFilePath(filesAndDirs.at(0));
470 searchDir.setNameFilters(QStringList());
471 filesAndDirs = searchDir.entryList(QDir::Dirs | QDir::Readable | QDir::Executable | QDir::NoDotAndDotDot);
472 for (int i = 0; i < filesAndDirs.size() && foundFileName.isEmpty(); i++) {
473 foundFileName = searchPathRecursively(searchDir.absoluteFilePath(filesAndDirs.at(i)), fileName);
474 if (!foundFileName.isEmpty())
477 return foundFileName;
480 QString DocumentChecker::searchFileRecursively(const QDir &dir, const QString &matchSize, const QString &matchHash) const
482 QString foundFileName;
485 QStringList filesAndDirs = dir.entryList(QDir::Files | QDir::Readable);
486 for (int i = 0; i < filesAndDirs.size() && foundFileName.isEmpty(); i++) {
487 QFile file(dir.absoluteFilePath(filesAndDirs.at(i)));
488 if (QString::number(file.size()) == matchSize) {
489 if (file.open(QIODevice::ReadOnly)) {
491 * 1 MB = 1 second per 450 files (or faster)
492 * 10 MB = 9 seconds per 450 files (or faster)
494 if (file.size() > 1000000 * 2) {
495 fileData = file.read(1000000);
496 if (file.seek(file.size() - 1000000))
497 fileData.append(file.readAll());
499 fileData = file.readAll();
501 fileHash = QCryptographicHash::hash(fileData, QCryptographicHash::Md5);
502 if (QString(fileHash.toHex()) == matchHash)
503 return file.fileName();
506 //kDebug() << filesAndDirs.at(i) << file.size() << fileHash.toHex();
508 filesAndDirs = dir.entryList(QDir::Dirs | QDir::Readable | QDir::Executable | QDir::NoDotAndDotDot);
509 for (int i = 0; i < filesAndDirs.size() && foundFileName.isEmpty(); i++) {
510 foundFileName = searchFileRecursively(dir.absoluteFilePath(filesAndDirs.at(i)), matchSize, matchHash);
511 if (!foundFileName.isEmpty())
514 return foundFileName;
517 void DocumentChecker::slotEditItem(QTreeWidgetItem *item, int)
519 int t = item->data(0, typeRole).toInt();
520 if (t == TITLE_FONT_ELEMENT) return;
521 //|| t == TITLE_IMAGE_ELEMENT) {
523 KUrl url = KUrlRequesterDialog::getUrl(item->text(1), m_dialog, i18n("Enter new location for file"));
524 if (url.isEmpty()) return;
525 item->setText(1, url.path());
526 if (KIO::NetAccess::exists(url, KIO::NetAccess::SourceSide, 0)) {
527 item->setIcon(0, KIcon("dialog-ok"));
528 int id = item->data(0, statusRole).toInt();
529 if (id < 10) item->setData(0, statusRole, CLIPOK);
530 else item->setData(0, statusRole, LUMAOK);
533 item->setIcon(0, KIcon("dialog-close"));
534 int id = item->data(0, statusRole).toInt();
535 if (id < 10) item->setData(0, statusRole, CLIPMISSING);
536 else item->setData(0, statusRole, LUMAMISSING);
542 void DocumentChecker::acceptDialog()
544 QDomElement e, property;
545 QDomNodeList producers = m_doc.elementsByTagName("producer");
546 QDomNodeList infoproducers = m_doc.elementsByTagName("kdenlive_producer");
547 QDomNodeList properties;
550 // prepare transitions
551 QDomNodeList trans = m_doc.elementsByTagName("transition");
553 // Mark document as modified
554 m_doc.documentElement().setAttribute("modified", 1);
556 QTreeWidgetItem *child = m_ui.treeWidget->topLevelItem(ix);
558 int t = child->data(0, typeRole).toInt();
559 if (child->data(0, statusRole).toInt() == CLIPOK) {
560 QString id = child->data(0, idRole).toString();
561 if (t == TITLE_IMAGE_ELEMENT) {
562 // edit images embedded in titles
563 for (int i = 0; i < infoproducers.count(); i++) {
564 e = infoproducers.item(i).toElement();
565 if (e.attribute("id") == id) {
567 QString xml = e.attribute("xmldata");
568 xml.replace(child->data(0, typeOriginalResource).toString(), child->text(1));
569 e.setAttribute("xmldata", xml);
573 for (int i = 0; i < producers.count(); i++) {
574 e = producers.item(i).toElement();
575 if (e.attribute("id").section('_', 0, 0) == id) {
577 properties = e.childNodes();
578 for (int j = 0; j < properties.count(); ++j) {
579 property = properties.item(j).toElement();
580 if (property.attribute("name") == "xmldata") {
581 QString xml = property.firstChild().nodeValue();
582 xml.replace(child->data(0, typeOriginalResource).toString(), child->text(1));
583 property.firstChild().setNodeValue(xml);
591 for (int i = 0; i < infoproducers.count(); i++) {
592 e = infoproducers.item(i).toElement();
593 if (e.attribute("id") == id) {
595 e.setAttribute("resource", child->text(1));
596 e.setAttribute("name", KUrl(child->text(1)).fileName());
600 for (int i = 0; i < producers.count(); i++) {
601 e = producers.item(i).toElement();
602 if (e.attribute("id").section('_', 0, 0) == id || e.attribute("id").section(':', 1, 1) == id) {
604 properties = e.childNodes();
605 for (int j = 0; j < properties.count(); ++j) {
606 property = properties.item(j).toElement();
607 if (property.attribute("name") == "resource") {
608 QString resource = property.firstChild().nodeValue();
609 if (resource.contains(QRegExp("\\?[0-9]+\\.[0-9]+(&strobe=[0-9]+)?$")))
610 property.firstChild().setNodeValue(child->text(1) + '?' + resource.section('?', -1));
612 property.firstChild().setNodeValue(child->text(1));
619 } else if (child->data(0, statusRole).toInt() == CLIPPLACEHOLDER && t != TITLE_FONT_ELEMENT && t != TITLE_IMAGE_ELEMENT) {
620 QString id = child->data(0, idRole).toString();
621 for (int i = 0; i < infoproducers.count(); i++) {
622 e = infoproducers.item(i).toElement();
623 if (e.attribute("id") == id) {
625 e.setAttribute("placeholder", '1');
629 } else if (child->data(0, statusRole).toInt() == LUMAOK) {
630 for (int i = 0; i < trans.count(); i++) {
631 QString luma = getProperty(trans.at(i).toElement(), "luma");
633 kDebug() << "luma: " << luma;
634 if (!luma.isEmpty() && luma == child->data(0, idRole).toString()) {
635 setProperty(trans.at(i).toElement(), "luma", child->text(1));
636 kDebug() << "replace with; " << child->text(1);
639 } else if (child->data(0, statusRole).toInt() == LUMAMISSING) {
640 for (int i = 0; i < trans.count(); i++) {
641 QString luma = getProperty(trans.at(i).toElement(), "luma");
642 if (!luma.isEmpty() && luma == child->data(0, idRole).toString()) {
643 setProperty(trans.at(i).toElement(), "luma", QString());
648 child = m_ui.treeWidget->topLevelItem(ix);
653 void DocumentChecker::slotPlaceholders()
656 QTreeWidgetItem *child = m_ui.treeWidget->topLevelItem(ix);
658 if (child->data(0, statusRole).toInt() == CLIPMISSING) {
659 child->setData(0, statusRole, CLIPPLACEHOLDER);
660 child->setIcon(0, KIcon("dialog-ok"));
661 } else if (child->data(0, statusRole).toInt() == LUMAMISSING) {
662 child->setData(0, statusRole, LUMAPLACEHOLDER);
663 child->setIcon(0, KIcon("dialog-ok"));
666 child = m_ui.treeWidget->topLevelItem(ix);
671 void DocumentChecker::slotFixDuration()
674 QTreeWidgetItem *child = m_ui.treeWidget->topLevelItem(ix);
675 QDomNodeList documentProducers = m_doc.elementsByTagName("producer");
677 if (child->data(0, statusRole).toInt() == CLIPWRONGDURATION) {
678 QString id = child->data(0, idRole).toString();
679 bool resetDuration = child->data(0, resetDurationRole).toInt();
681 for (int i = 0; i < m_info.count(); i++) {
682 QDomElement e = m_info.at(i).toElement();
683 if (e.attribute("id") == id) {
684 if (m_missingClips.contains(e)) {
685 // we cannot fix duration of missing clips
686 resetDuration = false;
689 if (resetDuration) e.removeAttribute("duration");
690 else e.setAttribute("duration", child->data(0, sizeRole).toString());
691 child->setData(0, statusRole, CLIPOK);
692 child->setIcon(0, KIcon("dialog-ok"));
698 // something is wrong in clip durations, so remove them so mlt fetches them again
699 for (int j = 0; j < documentProducers.count(); j++) {
700 QDomElement mltProd = documentProducers.at(j).toElement();
701 QString prodId = mltProd.attribute("id");
702 if (prodId == id || prodId.startsWith(id + "_")) {
703 EffectsList::removeProperty(mltProd, "length");
709 child = m_ui.treeWidget->topLevelItem(ix);
711 QDomNode infoXmlNode = m_doc.elementsByTagName("kdenlivedoc").at(0);
712 QDomElement infoXml = infoXmlNode.toElement();
713 infoXml.setAttribute("modified", "1");
714 m_ui.fixDuration->setEnabled(false);
719 void DocumentChecker::checkStatus()
723 QTreeWidgetItem *child = m_ui.treeWidget->topLevelItem(ix);
725 int status = child->data(0, statusRole).toInt();
726 if (status == CLIPMISSING || status == LUMAMISSING || status == CLIPWRONGDURATION) {
731 child = m_ui.treeWidget->topLevelItem(ix);
733 m_ui.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(status);
737 void DocumentChecker::slotDeleteSelected()
739 if (KMessageBox::warningContinueCancel(m_dialog, i18np("This will remove the selected clip from this project", "This will remove the selected clips from this project", m_ui.treeWidget->selectedItems().count()), i18n("Remove clips")) == KMessageBox::Cancel)
741 QStringList deletedIds;
742 QStringList deletedLumas;
743 QDomNodeList playlists = m_doc.elementsByTagName("playlist");
745 foreach(QTreeWidgetItem *child, m_ui.treeWidget->selectedItems()) {
746 int id = child->data(0, statusRole).toInt();
747 if (id == CLIPMISSING) {
748 deletedIds.append(child->data(0, idRole).toString());
751 else if (id == LUMAMISSING) {
752 deletedLumas.append(child->data(0, idRole).toString());
757 if (!deletedLumas.isEmpty()) {
759 QDomNodeList transitions = m_doc.elementsByTagName("transition");
760 foreach (QString lumaPath, deletedLumas) {
761 for (int i = 0; i < transitions.count(); i++) {
762 e = transitions.item(i).toElement();
763 QString resource = EffectsList::property(e, "luma");
764 if (resource == lumaPath) EffectsList::removeProperty(e, "luma");
769 if (!deletedIds.isEmpty()) {
771 QDomNodeList producers = m_doc.elementsByTagName("producer");
772 QDomNodeList infoproducers = m_doc.elementsByTagName("kdenlive_producer");
774 QDomElement mlt = m_doc.firstChildElement("mlt");
775 QDomElement kdenlivedoc = mlt.firstChildElement("kdenlivedoc");
777 for (int i = 0, j = 0; i < infoproducers.count() && j < deletedIds.count(); i++) {
778 e = infoproducers.item(i).toElement();
779 if (deletedIds.contains(e.attribute("id"))) {
781 kdenlivedoc.removeChild(e);
787 for (int i = 0; i < producers.count(); i++) {
788 e = producers.item(i).toElement();
789 if (deletedIds.contains(e.attribute("id").section('_', 0, 0)) || deletedIds.contains(e.attribute("id").section(':', 1, 1).section('_', 0, 0))) {
796 for (int i = 0; i < playlists.count(); i++) {
797 QDomNodeList entries = playlists.at(i).toElement().elementsByTagName("entry");
798 for (int j = 0; j < entries.count(); j++) {
799 e = entries.item(j).toElement();
800 if (deletedIds.contains(e.attribute("producer").section('_', 0, 0)) || deletedIds.contains(e.attribute("producer").section(':', 1, 1).section('_', 0, 0))) {
801 // Replace clip with blank
802 while (e.childNodes().count() > 0)
803 e.removeChild(e.firstChild());
804 e.setTagName("blank");
805 e.removeAttribute("producer");
806 int length = e.attribute("out").toInt() - e.attribute("in").toInt();
807 e.setAttribute("length", length);
812 QDomNode infoXmlNode = m_doc.elementsByTagName("kdenlivedoc").at(0);
813 QDomElement infoXml = infoXmlNode.toElement();
814 infoXml.setAttribute("modified", "1");
819 void DocumentChecker::checkMissingImages(QStringList images, QStringList fonts, QString id, QString baseClip)
822 foreach(const QString &img, images) {
823 if (!KIO::NetAccess::exists(KUrl(img), KIO::NetAccess::SourceSide, 0)) {
824 QDomElement e = doc.createElement("missingclip");
825 e.setAttribute("type", TITLE_IMAGE_ELEMENT);
826 e.setAttribute("resource", img);
827 e.setAttribute("id", id);
828 e.setAttribute("name", baseClip);
829 m_missingClips.append(e);
832 kDebug() << "/ / / CHK FONTS: " << fonts;
833 foreach(const QString &fontelement, fonts) {
834 QFont f(fontelement);
835 kDebug() << "/ / / CHK FONTS: " << fontelement << " = " << QFontInfo(f).family();
836 if (fontelement != QFontInfo(f).family()) {
837 QDomElement e = doc.createElement("missingclip");
838 e.setAttribute("type", TITLE_FONT_ELEMENT);
839 e.setAttribute("resource", fontelement);
840 e.setAttribute("id", id);
841 e.setAttribute("name", baseClip);
842 m_missingClips.append(e);
848 void DocumentChecker::slotCheckButtons()
850 if (m_ui.treeWidget->currentItem()) {
851 QTreeWidgetItem *item = m_ui.treeWidget->currentItem();
852 int t = item->data(0, typeRole).toInt();
853 int s = item->data(0, statusRole).toInt();
854 if (t == TITLE_FONT_ELEMENT || t == TITLE_IMAGE_ELEMENT || s == PROXYMISSING) {
855 m_ui.removeSelected->setEnabled(false);
856 } else m_ui.removeSelected->setEnabled(true);
861 #include "documentchecker.moc"