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()
78 QDomNodeList documentProducers = m_doc.elementsByTagName("producer");
79 QList <QDomElement> wrongDurationClips;
80 QList <QDomElement> missingProxies;
82 for (int i = 0; i < max; i++) {
83 e = m_info.item(i).toElement();
84 clipType = e.attribute("type").toInt();
85 if (clipType == COLOR) continue;
86 if (clipType != TEXT && clipType != IMAGE && clipType != SLIDESHOW) {
87 QString id = e.attribute("id");
88 int duration = e.attribute("duration").toInt();
92 // Check that the duration is in sync between Kdenlive's info and MLT's playlist
93 int prodsCount = documentProducers.count();
94 for (int j = 0; j < prodsCount; j++) {
95 mltProd = documentProducers.at(j).toElement();
96 prodId = mltProd.attribute("id");
97 // Don't check slowmotion clips for now... (TODO?)
98 if (prodId.startsWith("slowmotion")) continue;
99 if (prodId.contains("_")) prodId = prodId.section("_", 0, 0);
100 if (prodId != id) continue;
101 if (mltDuration > 0 ) {
102 // We have several MLT producers for the same clip (probably track producers)
103 int newLength = EffectsList::property(mltProd, "length").toInt();
104 if (newLength != mltDuration) {
105 // we have a different duration for the same clip, that is not safe
106 e.setAttribute("_resetDuration", 1);
109 mltDuration = EffectsList::property(mltProd, "length").toInt();
110 if (mltDuration != duration) {
112 e.setAttribute("_mismatch", mltDuration);
113 if (mltDuration == 15000) {
114 // a length of 15000 might indicate a wrong clip length since it is a default length
115 e.setAttribute("_resetDuration", 1);
117 if (!wrongDurationClips.contains(e)) wrongDurationClips.append(e);
122 QStringList safeImages;
123 if (clipType == TEXT) {
124 //TODO: Check is clip template is missing (xmltemplate) or hash changed
125 QStringList images = TitleWidget::extractImageList(e.attribute("xmldata"));
126 QStringList fonts = TitleWidget::extractFontList(e.attribute("xmldata"));
127 // Make sure we don't check the same images twice
128 foreach(const QString &existingImage, safeImages) {
129 images.removeAll(existingImage);
131 safeImages.append(checkMissingImages(images, fonts, e.attribute("id"), e.attribute("name")));
134 resource = e.attribute("resource");
135 if (e.hasAttribute("proxy")) {
136 QString proxyresource = e.attribute("proxy");
137 if (!proxyresource.isEmpty() && proxyresource != "-" && !KIO::NetAccess::exists(KUrl(proxyresource), KIO::NetAccess::SourceSide, 0)) {
138 // Missing clip found
139 missingProxies.append(e);
142 if (clipType == SLIDESHOW) resource = KUrl(resource).directory();
143 if (!KIO::NetAccess::exists(KUrl(resource), KIO::NetAccess::SourceSide, 0)) {
144 // Missing clip found
145 m_missingClips.append(e);
147 // Check if the clip has changed
148 if (clipType != SLIDESHOW && e.hasAttribute("file_hash")) {
149 if (e.attribute("file_hash") != DocClipBase::getHash(e.attribute("resource")))
150 e.removeAttribute("file_hash");
155 // Get list of used Luma files
156 QStringList missingLumas;
157 QStringList filesToCheck;
159 QString root = m_doc.documentElement().attribute("root");
160 if (!root.isEmpty()) root = KUrl(root).path(KUrl::AddTrailingSlash);
161 QDomNodeList trans = m_doc.elementsByTagName("transition");
163 for (int i = 0; i < max; i++) {
164 QString luma = getProperty(trans.at(i).toElement(), "luma");
165 if (!luma.isEmpty() && !filesToCheck.contains(luma))
166 filesToCheck.append(luma);
168 // Check existence of luma files
169 foreach (const QString lumafile, filesToCheck) {
171 if (!filePath.startsWith('/')) filePath.prepend(root);
172 if (!QFile::exists(filePath)) {
173 missingLumas.append(lumafile);
179 if (m_missingClips.isEmpty() && missingLumas.isEmpty() && wrongDurationClips.isEmpty() && missingProxies.isEmpty())
182 m_dialog = new QDialog();
183 m_dialog->setFont(KGlobalSettings::toolBarFont());
184 m_ui.setupUi(m_dialog);
186 foreach(const QString l, missingLumas) {
187 QTreeWidgetItem *item = new QTreeWidgetItem(m_ui.treeWidget, QStringList() << i18n("Luma file") << l);
188 item->setIcon(0, KIcon("dialog-close"));
189 item->setData(0, idRole, l);
190 item->setData(0, statusRole, LUMAMISSING);
193 m_ui.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
194 max = m_missingClips.count();
195 for (int i = 0; i < max; i++) {
196 e = m_missingClips.at(i).toElement();
198 int t = e.attribute("type").toInt();
201 clipType = i18n("Video clip");
204 clipType = i18n("Mute video clip");
207 clipType = i18n("Audio clip");
210 clipType = i18n("Playlist clip");
213 clipType = i18n("Image clip");
216 clipType = i18n("Slideshow clip");
218 case TITLE_IMAGE_ELEMENT:
219 clipType = i18n("Title Image");
221 case TITLE_FONT_ELEMENT:
222 clipType = i18n("Title Font");
225 clipType = i18n("Video clip");
227 QTreeWidgetItem *item = new QTreeWidgetItem(m_ui.treeWidget, QStringList() << clipType);
228 if (t == TITLE_IMAGE_ELEMENT) {
229 item->setIcon(0, KIcon("dialog-warning"));
230 item->setToolTip(1, e.attribute("name"));
231 item->setText(1, e.attribute("resource"));
232 item->setData(0, statusRole, CLIPPLACEHOLDER);
233 item->setData(0, typeOriginalResource, e.attribute("resource"));
234 } else if (t == TITLE_FONT_ELEMENT) {
235 item->setIcon(0, KIcon("dialog-warning"));
236 item->setToolTip(1, e.attribute("name"));
237 QString ft = e.attribute("resource");
238 QString newft = QFontInfo(QFont(ft)).family();
239 item->setText(1, i18n("%1 will be replaced by %2", ft, newft));
240 item->setData(0, statusRole, CLIPPLACEHOLDER);
242 item->setIcon(0, KIcon("dialog-close"));
243 item->setText(1, e.attribute("resource"));
244 item->setData(0, hashRole, e.attribute("file_hash"));
245 item->setData(0, sizeRole, e.attribute("file_size"));
246 item->setData(0, statusRole, CLIPMISSING);
248 item->setData(0, typeRole, t);
249 item->setData(0, idRole, e.attribute("id"));
250 item->setToolTip(0, i18n("Missing item"));
253 if (m_missingClips.count() > 0) {
254 if (wrongDurationClips.count() > 0) {
255 m_ui.infoLabel->setText(i18n("The project file contains missing clips or files and clip duration mismatch"));
258 m_ui.infoLabel->setText(i18n("The project file contains missing clips or files"));
261 else if (wrongDurationClips.count() > 0) {
262 m_ui.infoLabel->setText(i18n("The project file contains clips with duration mismatch"));
264 if (missingProxies.count() > 0) {
265 if (!m_ui.infoLabel->text().isEmpty()) m_ui.infoLabel->setText(m_ui.infoLabel->text() + ". ");
266 m_ui.infoLabel->setText(m_ui.infoLabel->text() + i18n("Missing proxies will be recreated after opening."));
269 m_ui.removeSelected->setEnabled(!m_missingClips.isEmpty());
270 m_ui.recursiveSearch->setEnabled(!m_missingClips.isEmpty() || !missingLumas.isEmpty());
271 m_ui.usePlaceholders->setEnabled(!m_missingClips.isEmpty());
272 m_ui.fixDuration->setEnabled(!wrongDurationClips.isEmpty());
274 max = wrongDurationClips.count();
275 for (int i = 0; i < max; i++) {
276 e = wrongDurationClips.at(i).toElement();
278 int t = e.attribute("type").toInt();
281 clipType = i18n("Video clip");
284 clipType = i18n("Mute video clip");
287 clipType = i18n("Audio clip");
290 clipType = i18n("Playlist clip");
293 clipType = i18n("Image clip");
296 clipType = i18n("Slideshow clip");
299 clipType = i18n("Video clip");
301 QTreeWidgetItem *item = new QTreeWidgetItem(m_ui.treeWidget, QStringList() << clipType);
302 item->setIcon(0, KIcon("timeadjust"));
303 item->setText(1, e.attribute("resource"));
304 item->setData(0, hashRole, e.attribute("file_hash"));
305 item->setData(0, sizeRole, e.attribute("_mismatch"));
306 e.removeAttribute("_mismatch");
307 item->setData(0, resetDurationRole, (int) e.hasAttribute("_resetDuration"));
308 e.removeAttribute("_resetDuration");
309 item->setData(0, statusRole, CLIPWRONGDURATION);
310 item->setData(0, typeRole, t);
311 item->setData(0, idRole, e.attribute("id"));
312 item->setToolTip(0, i18n("Duration mismatch"));
315 if (missingProxies.count() > 0) {
316 QTreeWidgetItem *item = new QTreeWidgetItem(m_ui.treeWidget, QStringList() << i18n("Proxy clip"));
317 item->setIcon(0, KIcon("dialog-warning"));
318 item->setText(1, i18n("%1 missing proxy clips, will be recreated on project opening", missingProxies.count()));
319 item->setData(0, hashRole, e.attribute("file_hash"));
320 item->setData(0, statusRole, PROXYMISSING);
321 item->setToolTip(0, i18n("Missing proxy"));
324 max = missingProxies.count();
325 for (int i = 0; i < max; i++) {
326 e = missingProxies.at(i).toElement();
328 QString realPath = e.attribute("resource");
329 QString id = e.attribute("id");
330 // Replace proxy url with real clip in MLT producers
331 QDomNodeList properties;
333 QDomElement property;
334 int prodsCount = documentProducers.count();
335 for (int j = 0; j < prodsCount; j++) {
336 mltProd = documentProducers.at(j).toElement();
337 QString prodId = mltProd.attribute("id");
338 bool slowmotion = false;
339 if (prodId.startsWith("slowmotion")) {
341 prodId = prodId.section(':', 1, 1);
343 if (prodId.contains('_')) prodId = prodId.section('_', 0, 0);
345 // Hit, we must replace url
346 properties = mltProd.childNodes();
347 for (int k = 0; k < properties.count(); ++k) {
348 property = properties.item(k).toElement();
349 if (property.attribute("name") == "resource") {
350 QString resource = property.firstChild().nodeValue();
352 if (slowmotion) suffix = "?" + resource.section('?', -1);
353 property.firstChild().setNodeValue(realPath + suffix);
361 if (missingProxies.count() > 0) {
362 // original doc was modified
363 QDomElement infoXml = m_doc.elementsByTagName("kdenlivedoc").at(0).toElement();
364 infoXml.setAttribute("modified", "1");
367 connect(m_ui.recursiveSearch, SIGNAL(pressed()), this, SLOT(slotSearchClips()));
368 connect(m_ui.usePlaceholders, SIGNAL(pressed()), this, SLOT(slotPlaceholders()));
369 connect(m_ui.removeSelected, SIGNAL(pressed()), this, SLOT(slotDeleteSelected()));
370 connect(m_ui.fixDuration, SIGNAL(pressed()), this, SLOT(slotFixDuration()));
371 connect(m_ui.treeWidget, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)), this, SLOT(slotEditItem(QTreeWidgetItem *, int)));
372 connect(m_ui.treeWidget, SIGNAL(itemSelectionChanged()), this, SLOT(slotCheckButtons()));
374 if (m_ui.treeWidget->topLevelItem(0)) m_ui.treeWidget->setCurrentItem(m_ui.treeWidget->topLevelItem(0));
376 int acceptMissing = m_dialog->exec();
377 if (acceptMissing == QDialog::Accepted) acceptDialog();
378 return (acceptMissing != QDialog::Accepted);
381 DocumentChecker::~DocumentChecker()
383 if (m_dialog) delete m_dialog;
387 QString DocumentChecker::getProperty(QDomElement effect, const QString &name)
389 QDomNodeList params = effect.elementsByTagName("property");
390 for (int i = 0; i < params.count(); i++) {
391 QDomElement e = params.item(i).toElement();
392 if (e.attribute("name") == name) {
393 return e.firstChild().nodeValue();
399 void DocumentChecker::setProperty(QDomElement effect, const QString &name, const QString value)
401 QDomNodeList params = effect.elementsByTagName("property");
402 for (int i = 0; i < params.count(); i++) {
403 QDomElement e = params.item(i).toElement();
404 if (e.attribute("name") == name) {
405 e.firstChild().setNodeValue(value);
410 void DocumentChecker::slotSearchClips()
412 QString newpath = KFileDialog::getExistingDirectory(KUrl("kfiledialog:///clipfolder"), kapp->activeWindow(), i18n("Clips folder"));
413 if (newpath.isEmpty()) return;
416 m_ui.recursiveSearch->setEnabled(false);
417 QTreeWidgetItem *child = m_ui.treeWidget->topLevelItem(ix);
418 QDir searchDir(newpath);
420 if (child->data(0, statusRole).toInt() == CLIPMISSING) {
421 QString clipPath = searchFileRecursively(searchDir, child->data(0, sizeRole).toString(), child->data(0, hashRole).toString());
422 if (!clipPath.isEmpty()) {
424 child->setText(1, clipPath);
425 child->setIcon(0, KIcon("dialog-ok"));
426 child->setData(0, statusRole, CLIPOK);
428 } else if (child->data(0, statusRole).toInt() == LUMAMISSING) {
429 QString fileName = searchLuma(child->data(0, idRole).toString());
430 if (!fileName.isEmpty()) {
432 child->setText(1, fileName);
433 child->setIcon(0, KIcon("dialog-ok"));
434 child->setData(0, statusRole, LUMAOK);
437 else if (child->data(0, typeRole).toInt() == TITLE_IMAGE_ELEMENT && child->data(0, statusRole).toInt() == CLIPPLACEHOLDER) {
438 // Search missing title images
439 QString missingFileName = KUrl(child->text(1)).fileName();
440 QString newPath = searchPathRecursively(searchDir, missingFileName);
441 if (!newPath.isEmpty()) {
444 child->setText(1, newPath);
445 child->setIcon(0, KIcon("dialog-ok"));
446 child->setData(0, statusRole, CLIPOK);
450 child = m_ui.treeWidget->topLevelItem(ix);
452 m_ui.recursiveSearch->setEnabled(true);
454 // original doc was modified
455 QDomElement infoXml = m_doc.elementsByTagName("kdenlivedoc").at(0).toElement();
456 infoXml.setAttribute("modified", "1");
462 QString DocumentChecker::searchLuma(QString file) const
464 KUrl searchPath(KdenliveSettings::mltpath());
465 if (file.contains("PAL"))
466 searchPath.cd("../lumas/PAL");
468 searchPath.cd("../lumas/NTSC");
469 QString result = searchPath.path(KUrl::AddTrailingSlash) + KUrl(file).fileName();
470 if (QFile::exists(result))
472 // try to find luma in application path
474 searchPath = KUrl(QCoreApplication::applicationDirPath());
475 searchPath.cd("../share/apps/kdenlive/lumas");
476 result = searchPath.path(KUrl::AddTrailingSlash) + KUrl(file).fileName();
477 if (QFile::exists(result))
482 QString DocumentChecker::searchPathRecursively(const QDir &dir, const QString &fileName) const
484 QString foundFileName;
488 searchDir.setNameFilters(filters);
489 QStringList filesAndDirs = searchDir.entryList(QDir::Files | QDir::Readable);
490 if (!filesAndDirs.isEmpty()) return searchDir.absoluteFilePath(filesAndDirs.at(0));
491 searchDir.setNameFilters(QStringList());
492 filesAndDirs = searchDir.entryList(QDir::Dirs | QDir::Readable | QDir::Executable | QDir::NoDotAndDotDot);
493 for (int i = 0; i < filesAndDirs.size() && foundFileName.isEmpty(); i++) {
494 foundFileName = searchPathRecursively(searchDir.absoluteFilePath(filesAndDirs.at(i)), fileName);
495 if (!foundFileName.isEmpty())
498 return foundFileName;
501 QString DocumentChecker::searchFileRecursively(const QDir &dir, const QString &matchSize, const QString &matchHash) const
503 QString foundFileName;
506 QStringList filesAndDirs = dir.entryList(QDir::Files | QDir::Readable);
507 for (int i = 0; i < filesAndDirs.size() && foundFileName.isEmpty(); i++) {
508 QFile file(dir.absoluteFilePath(filesAndDirs.at(i)));
509 if (QString::number(file.size()) == matchSize) {
510 if (file.open(QIODevice::ReadOnly)) {
512 * 1 MB = 1 second per 450 files (or faster)
513 * 10 MB = 9 seconds per 450 files (or faster)
515 if (file.size() > 1000000 * 2) {
516 fileData = file.read(1000000);
517 if (file.seek(file.size() - 1000000))
518 fileData.append(file.readAll());
520 fileData = file.readAll();
522 fileHash = QCryptographicHash::hash(fileData, QCryptographicHash::Md5);
523 if (QString(fileHash.toHex()) == matchHash)
524 return file.fileName();
527 //kDebug() << filesAndDirs.at(i) << file.size() << fileHash.toHex();
529 filesAndDirs = dir.entryList(QDir::Dirs | QDir::Readable | QDir::Executable | QDir::NoDotAndDotDot);
530 for (int i = 0; i < filesAndDirs.size() && foundFileName.isEmpty(); i++) {
531 foundFileName = searchFileRecursively(dir.absoluteFilePath(filesAndDirs.at(i)), matchSize, matchHash);
532 if (!foundFileName.isEmpty())
535 return foundFileName;
538 void DocumentChecker::slotEditItem(QTreeWidgetItem *item, int)
540 int t = item->data(0, typeRole).toInt();
541 if (t == TITLE_FONT_ELEMENT) return;
542 //|| t == TITLE_IMAGE_ELEMENT) {
544 KUrl url = KUrlRequesterDialog::getUrl(item->text(1), m_dialog, i18n("Enter new location for file"));
545 if (url.isEmpty()) return;
546 item->setText(1, url.path());
547 if (KIO::NetAccess::exists(url, KIO::NetAccess::SourceSide, 0)) {
548 item->setIcon(0, KIcon("dialog-ok"));
549 int id = item->data(0, statusRole).toInt();
550 if (id < 10) item->setData(0, statusRole, CLIPOK);
551 else item->setData(0, statusRole, LUMAOK);
554 item->setIcon(0, KIcon("dialog-close"));
555 int id = item->data(0, statusRole).toInt();
556 if (id < 10) item->setData(0, statusRole, CLIPMISSING);
557 else item->setData(0, statusRole, LUMAMISSING);
563 void DocumentChecker::acceptDialog()
565 QDomElement e, property;
566 QDomNodeList producers = m_doc.elementsByTagName("producer");
567 QDomNodeList infoproducers = m_doc.elementsByTagName("kdenlive_producer");
568 QDomNodeList properties;
571 // prepare transitions
572 QDomNodeList trans = m_doc.elementsByTagName("transition");
574 // Mark document as modified
575 m_doc.documentElement().setAttribute("modified", 1);
577 QTreeWidgetItem *child = m_ui.treeWidget->topLevelItem(ix);
579 int t = child->data(0, typeRole).toInt();
580 if (child->data(0, statusRole).toInt() == CLIPOK) {
581 QString id = child->data(0, idRole).toString();
582 if (t == TITLE_IMAGE_ELEMENT) {
583 // edit images embedded in titles
584 for (int i = 0; i < infoproducers.count(); i++) {
585 e = infoproducers.item(i).toElement();
586 if (e.attribute("id") == id) {
588 QString xml = e.attribute("xmldata");
589 xml.replace(child->data(0, typeOriginalResource).toString(), child->text(1));
590 e.setAttribute("xmldata", xml);
594 for (int i = 0; i < producers.count(); i++) {
595 e = producers.item(i).toElement();
596 if (e.attribute("id").section('_', 0, 0) == id) {
598 properties = e.childNodes();
599 for (int j = 0; j < properties.count(); ++j) {
600 property = properties.item(j).toElement();
601 if (property.attribute("name") == "xmldata") {
602 QString xml = property.firstChild().nodeValue();
603 xml.replace(child->data(0, typeOriginalResource).toString(), child->text(1));
604 property.firstChild().setNodeValue(xml);
612 for (int i = 0; i < infoproducers.count(); i++) {
613 e = infoproducers.item(i).toElement();
614 if (e.attribute("id") == id) {
616 e.setAttribute("resource", child->text(1));
617 e.setAttribute("name", KUrl(child->text(1)).fileName());
621 for (int i = 0; i < producers.count(); i++) {
622 e = producers.item(i).toElement();
623 if (e.attribute("id").section('_', 0, 0) == id || e.attribute("id").section(':', 1, 1) == id) {
625 properties = e.childNodes();
626 for (int j = 0; j < properties.count(); ++j) {
627 property = properties.item(j).toElement();
628 if (property.attribute("name") == "resource") {
629 QString resource = property.firstChild().nodeValue();
630 if (resource.contains(QRegExp("\\?[0-9]+\\.[0-9]+(&strobe=[0-9]+)?$")))
631 property.firstChild().setNodeValue(child->text(1) + '?' + resource.section('?', -1));
633 property.firstChild().setNodeValue(child->text(1));
640 } else if (child->data(0, statusRole).toInt() == CLIPPLACEHOLDER && t != TITLE_FONT_ELEMENT && t != TITLE_IMAGE_ELEMENT) {
641 QString id = child->data(0, idRole).toString();
642 for (int i = 0; i < infoproducers.count(); i++) {
643 e = infoproducers.item(i).toElement();
644 if (e.attribute("id") == id) {
646 e.setAttribute("placeholder", '1');
650 } else if (child->data(0, statusRole).toInt() == LUMAOK) {
651 for (int i = 0; i < trans.count(); i++) {
652 QString luma = getProperty(trans.at(i).toElement(), "luma");
654 kDebug() << "luma: " << luma;
655 if (!luma.isEmpty() && luma == child->data(0, idRole).toString()) {
656 setProperty(trans.at(i).toElement(), "luma", child->text(1));
657 kDebug() << "replace with; " << child->text(1);
660 } else if (child->data(0, statusRole).toInt() == LUMAMISSING) {
661 for (int i = 0; i < trans.count(); i++) {
662 QString luma = getProperty(trans.at(i).toElement(), "luma");
663 if (!luma.isEmpty() && luma == child->data(0, idRole).toString()) {
664 setProperty(trans.at(i).toElement(), "luma", QString());
669 child = m_ui.treeWidget->topLevelItem(ix);
674 void DocumentChecker::slotPlaceholders()
677 QTreeWidgetItem *child = m_ui.treeWidget->topLevelItem(ix);
679 if (child->data(0, statusRole).toInt() == CLIPMISSING) {
680 child->setData(0, statusRole, CLIPPLACEHOLDER);
681 child->setIcon(0, KIcon("dialog-ok"));
682 } else if (child->data(0, statusRole).toInt() == LUMAMISSING) {
683 child->setData(0, statusRole, LUMAPLACEHOLDER);
684 child->setIcon(0, KIcon("dialog-ok"));
687 child = m_ui.treeWidget->topLevelItem(ix);
692 void DocumentChecker::slotFixDuration()
695 QTreeWidgetItem *child = m_ui.treeWidget->topLevelItem(ix);
696 QDomNodeList documentProducers = m_doc.elementsByTagName("producer");
698 if (child->data(0, statusRole).toInt() == CLIPWRONGDURATION) {
699 QString id = child->data(0, idRole).toString();
700 bool resetDuration = child->data(0, resetDurationRole).toInt();
702 for (int i = 0; i < m_info.count(); i++) {
703 QDomElement e = m_info.at(i).toElement();
704 if (e.attribute("id") == id) {
705 if (m_missingClips.contains(e)) {
706 // we cannot fix duration of missing clips
707 resetDuration = false;
710 if (resetDuration) e.removeAttribute("duration");
711 else e.setAttribute("duration", child->data(0, sizeRole).toString());
712 child->setData(0, statusRole, CLIPOK);
713 child->setIcon(0, KIcon("dialog-ok"));
719 // something is wrong in clip durations, so remove them so mlt fetches them again
720 for (int j = 0; j < documentProducers.count(); j++) {
721 QDomElement mltProd = documentProducers.at(j).toElement();
722 QString prodId = mltProd.attribute("id");
723 if (prodId == id || prodId.startsWith(id + "_")) {
724 EffectsList::removeProperty(mltProd, "length");
730 child = m_ui.treeWidget->topLevelItem(ix);
732 QDomElement infoXml = m_doc.elementsByTagName("kdenlivedoc").at(0).toElement();
733 infoXml.setAttribute("modified", "1");
734 m_ui.fixDuration->setEnabled(false);
739 void DocumentChecker::checkStatus()
743 QTreeWidgetItem *child = m_ui.treeWidget->topLevelItem(ix);
745 int status = child->data(0, statusRole).toInt();
746 if (status == CLIPMISSING || status == LUMAMISSING || status == CLIPWRONGDURATION) {
751 child = m_ui.treeWidget->topLevelItem(ix);
753 m_ui.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(status);
757 void DocumentChecker::slotDeleteSelected()
759 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)
761 QStringList deletedIds;
762 QStringList deletedLumas;
763 QDomNodeList playlists = m_doc.elementsByTagName("playlist");
765 foreach(QTreeWidgetItem *child, m_ui.treeWidget->selectedItems()) {
766 int id = child->data(0, statusRole).toInt();
767 if (id == CLIPMISSING) {
768 deletedIds.append(child->data(0, idRole).toString());
771 else if (id == LUMAMISSING) {
772 deletedLumas.append(child->data(0, idRole).toString());
777 if (!deletedLumas.isEmpty()) {
779 QDomNodeList transitions = m_doc.elementsByTagName("transition");
780 foreach (QString lumaPath, deletedLumas) {
781 for (int i = 0; i < transitions.count(); i++) {
782 e = transitions.item(i).toElement();
783 QString resource = EffectsList::property(e, "luma");
784 if (resource == lumaPath) EffectsList::removeProperty(e, "luma");
789 if (!deletedIds.isEmpty()) {
791 QDomNodeList producers = m_doc.elementsByTagName("producer");
792 QDomNodeList infoproducers = m_doc.elementsByTagName("kdenlive_producer");
794 QDomNode mlt = m_doc.elementsByTagName("mlt").at(0);
795 QDomNode kdenlivedoc = m_doc.elementsByTagName("kdenlivedoc").at(0);
797 for (int i = 0, j = 0; i < infoproducers.count() && j < deletedIds.count(); i++) {
798 e = infoproducers.item(i).toElement();
799 if (deletedIds.contains(e.attribute("id"))) {
801 kdenlivedoc.removeChild(e);
807 for (int i = 0; i < producers.count(); i++) {
808 e = producers.item(i).toElement();
809 if (deletedIds.contains(e.attribute("id").section('_', 0, 0)) || deletedIds.contains(e.attribute("id").section(':', 1, 1).section('_', 0, 0))) {
816 for (int i = 0; i < playlists.count(); i++) {
817 QDomNodeList entries = playlists.at(i).toElement().elementsByTagName("entry");
818 for (int j = 0; j < entries.count(); j++) {
819 e = entries.item(j).toElement();
820 if (deletedIds.contains(e.attribute("producer").section('_', 0, 0)) || deletedIds.contains(e.attribute("producer").section(':', 1, 1).section('_', 0, 0))) {
821 // Replace clip with blank
822 while (e.childNodes().count() > 0)
823 e.removeChild(e.firstChild());
824 e.setTagName("blank");
825 e.removeAttribute("producer");
826 int length = e.attribute("out").toInt() - e.attribute("in").toInt();
827 e.setAttribute("length", length);
832 QDomElement infoXml = m_doc.elementsByTagName("kdenlivedoc").at(0).toElement();
833 infoXml.setAttribute("modified", "1");
838 QStringList DocumentChecker::checkMissingImages(QStringList images, QStringList fonts, QString id, QString baseClip)
841 QStringList safeImages;
842 foreach(const QString &img, images) {
843 if (!KIO::NetAccess::exists(KUrl(img), KIO::NetAccess::SourceSide, 0)) {
844 QDomElement e = doc.createElement("missingclip");
845 e.setAttribute("type", TITLE_IMAGE_ELEMENT);
846 e.setAttribute("resource", img);
847 e.setAttribute("id", id);
848 e.setAttribute("name", baseClip);
849 m_missingClips.append(e);
851 else safeImages.append(img);
853 kDebug() << "/ / / CHK FONTS: " << fonts;
854 foreach(const QString &fontelement, fonts) {
855 QFont f(fontelement);
856 kDebug() << "/ / / CHK FONTS: " << fontelement << " = " << QFontInfo(f).family();
857 if (fontelement != QFontInfo(f).family()) {
858 QDomElement e = doc.createElement("missingclip");
859 e.setAttribute("type", TITLE_FONT_ELEMENT);
860 e.setAttribute("resource", fontelement);
861 e.setAttribute("id", id);
862 e.setAttribute("name", baseClip);
863 m_missingClips.append(e);
870 void DocumentChecker::slotCheckButtons()
872 if (m_ui.treeWidget->currentItem()) {
873 QTreeWidgetItem *item = m_ui.treeWidget->currentItem();
874 int t = item->data(0, typeRole).toInt();
875 int s = item->data(0, statusRole).toInt();
876 if (t == TITLE_FONT_ELEMENT || t == TITLE_IMAGE_ELEMENT || s == PROXYMISSING) {
877 m_ui.removeSelected->setEnabled(false);
878 } else m_ui.removeSelected->setEnabled(true);
883 #include "documentchecker.moc"