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>
36 #include <KStandardDirs>
38 #include <QTreeWidgetItem>
40 #include <QHeaderView>
44 #include <QCryptographicHash>
46 const int hashRole = Qt::UserRole;
47 const int sizeRole = Qt::UserRole + 1;
48 const int idRole = Qt::UserRole + 2;
49 const int statusRole = Qt::UserRole + 3;
50 const int typeRole = Qt::UserRole + 4;
51 const int typeOriginalResource = Qt::UserRole + 5;
52 const int resetDurationRole = Qt::UserRole + 6;
54 const int CLIPMISSING = 0;
56 const int CLIPPLACEHOLDER = 2;
57 const int CLIPWRONGDURATION = 3;
58 const int PROXYMISSING = 4;
60 const int LUMAMISSING = 10;
61 const int LUMAOK = 11;
62 const int LUMAPLACEHOLDER = 12;
64 enum TITLECLIPTYPE { TITLE_IMAGE_ELEMENT = 20, TITLE_FONT_ELEMENT = 21 };
66 DocumentChecker::DocumentChecker(QDomNodeList infoproducers, QDomDocument doc):
67 m_info(infoproducers), m_doc(doc), m_dialog(NULL)
73 bool DocumentChecker::hasErrorInClips()
79 QDomNodeList documentProducers = m_doc.elementsByTagName("producer");
80 QList <QDomElement> wrongDurationClips;
81 QList <QDomElement> missingProxies;
85 for (int i = 0; i < max; i++) {
86 e = m_info.item(i).toElement();
87 clipType = e.attribute("type").toInt();
88 if (clipType == COLOR) continue;
89 if (clipType != TEXT && clipType != IMAGE && clipType != SLIDESHOW) {
90 QString id = e.attribute("id");
91 int duration = e.attribute("duration").toInt();
95 // Check that the duration is in sync between Kdenlive's info and MLT's playlist
96 int prodsCount = documentProducers.count();
97 for (int j = 0; j < prodsCount; j++) {
98 mltProd = documentProducers.at(j).toElement();
99 prodId = mltProd.attribute("id");
100 // Don't check slowmotion clips for now... (TODO?)
101 if (prodId.startsWith("slowmotion")) continue;
102 if (prodId.contains("_")) prodId = prodId.section("_", 0, 0);
103 if (prodId != id) continue;
104 if (mltDuration > 0 ) {
105 // We have several MLT producers for the same clip (probably track producers)
106 int newLength = EffectsList::property(mltProd, "length").toInt();
107 if (newLength != mltDuration) {
108 // we have a different duration for the same clip, that is not safe
109 e.setAttribute("_resetDuration", 1);
112 mltDuration = EffectsList::property(mltProd, "length").toInt();
113 if (mltDuration != duration) {
115 e.setAttribute("_mismatch", mltDuration);
116 if (mltDuration == 15000) {
117 // a length of 15000 might indicate a wrong clip length since it is a default length
118 e.setAttribute("_resetDuration", 1);
120 if (!wrongDurationClips.contains(e)) wrongDurationClips.append(e);
125 if (clipType == TEXT) {
126 //TODO: Check is clip template is missing (xmltemplate) or hash changed
127 QStringList images = TitleWidget::extractImageList(e.attribute("xmldata"));
128 QStringList fonts = TitleWidget::extractFontList(e.attribute("xmldata"));
129 checkMissingImagesAndFonts(images, fonts, e.attribute("id"), e.attribute("name"));
132 resource = e.attribute("resource");
133 if (e.hasAttribute("proxy")) {
134 QString proxyresource = e.attribute("proxy");
135 if (!proxyresource.isEmpty() && proxyresource != "-" && !KIO::NetAccess::exists(KUrl(proxyresource), KIO::NetAccess::SourceSide, 0)) {
136 // Missing clip found
137 missingProxies.append(e);
140 if (clipType == SLIDESHOW) resource = KUrl(resource).directory();
141 if (!KIO::NetAccess::exists(KUrl(resource), KIO::NetAccess::SourceSide, 0)) {
142 // Missing clip found
143 m_missingClips.append(e);
145 // Check if the clip has changed
146 if (clipType != SLIDESHOW && e.hasAttribute("file_hash")) {
147 if (e.attribute("file_hash") != DocClipBase::getHash(e.attribute("resource")))
148 e.removeAttribute("file_hash");
153 // Get list of used Luma files
154 QStringList missingLumas;
155 QStringList filesToCheck;
157 QString root = m_doc.documentElement().attribute("root");
158 if (!root.isEmpty()) root = KUrl(root).path(KUrl::AddTrailingSlash);
159 QDomNodeList trans = m_doc.elementsByTagName("transition");
161 for (int i = 0; i < max; i++) {
162 QString luma = getProperty(trans.at(i).toElement(), "luma");
163 if (!luma.isEmpty() && !filesToCheck.contains(luma))
164 filesToCheck.append(luma);
166 // Check existence of luma files
167 foreach (const QString lumafile, filesToCheck) {
169 if (!filePath.startsWith('/')) filePath.prepend(root);
170 if (!QFile::exists(filePath)) {
171 missingLumas.append(lumafile);
177 if (m_missingClips.isEmpty() && missingLumas.isEmpty() && wrongDurationClips.isEmpty() && missingProxies.isEmpty())
180 m_dialog = new QDialog();
181 m_dialog->setFont(KGlobalSettings::toolBarFont());
182 m_ui.setupUi(m_dialog);
184 foreach(const QString l, missingLumas) {
185 QTreeWidgetItem *item = new QTreeWidgetItem(m_ui.treeWidget, QStringList() << i18n("Luma file") << l);
186 item->setIcon(0, KIcon("dialog-close"));
187 item->setData(0, idRole, l);
188 item->setData(0, statusRole, LUMAMISSING);
191 m_ui.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
192 max = m_missingClips.count();
193 for (int i = 0; i < max; i++) {
194 e = m_missingClips.at(i).toElement();
196 int t = e.attribute("type").toInt();
199 clipType = i18n("Video clip");
202 clipType = i18n("Mute video clip");
205 clipType = i18n("Audio clip");
208 clipType = i18n("Playlist clip");
211 clipType = i18n("Image clip");
214 clipType = i18n("Slideshow clip");
216 case TITLE_IMAGE_ELEMENT:
217 clipType = i18n("Title Image");
219 case TITLE_FONT_ELEMENT:
220 clipType = i18n("Title Font");
223 clipType = i18n("Video clip");
225 QTreeWidgetItem *item = new QTreeWidgetItem(m_ui.treeWidget, QStringList() << clipType);
226 if (t == TITLE_IMAGE_ELEMENT) {
227 item->setIcon(0, KIcon("dialog-warning"));
228 item->setToolTip(1, e.attribute("name"));
229 item->setText(1, e.attribute("resource"));
230 item->setData(0, statusRole, CLIPPLACEHOLDER);
231 item->setData(0, typeOriginalResource, e.attribute("resource"));
232 } else if (t == TITLE_FONT_ELEMENT) {
233 item->setIcon(0, KIcon("dialog-warning"));
234 item->setToolTip(1, e.attribute("name"));
235 QString ft = e.attribute("resource");
236 QString newft = QFontInfo(QFont(ft)).family();
237 item->setText(1, i18n("%1 will be replaced by %2", ft, newft));
238 item->setData(0, statusRole, CLIPPLACEHOLDER);
240 item->setIcon(0, KIcon("dialog-close"));
241 item->setText(1, e.attribute("resource"));
242 item->setData(0, hashRole, e.attribute("file_hash"));
243 item->setData(0, sizeRole, e.attribute("file_size"));
244 item->setData(0, statusRole, CLIPMISSING);
246 item->setData(0, typeRole, t);
247 item->setData(0, idRole, e.attribute("id"));
248 item->setToolTip(0, i18n("Missing item"));
251 if (m_missingClips.count() > 0) {
252 if (wrongDurationClips.count() > 0) {
253 m_ui.infoLabel->setText(i18n("The project file contains missing clips or files and clip duration mismatch"));
256 m_ui.infoLabel->setText(i18n("The project file contains missing clips or files"));
259 else if (wrongDurationClips.count() > 0) {
260 m_ui.infoLabel->setText(i18n("The project file contains clips with duration mismatch"));
262 if (missingProxies.count() > 0) {
263 if (!m_ui.infoLabel->text().isEmpty()) m_ui.infoLabel->setText(m_ui.infoLabel->text() + ". ");
264 m_ui.infoLabel->setText(m_ui.infoLabel->text() + i18n("Missing proxies will be recreated after opening."));
267 m_ui.removeSelected->setEnabled(!m_missingClips.isEmpty());
268 m_ui.recursiveSearch->setEnabled(!m_missingClips.isEmpty() || !missingLumas.isEmpty());
269 m_ui.usePlaceholders->setEnabled(!m_missingClips.isEmpty());
270 m_ui.fixDuration->setEnabled(!wrongDurationClips.isEmpty());
272 max = wrongDurationClips.count();
273 for (int i = 0; i < max; i++) {
274 e = wrongDurationClips.at(i).toElement();
276 int t = e.attribute("type").toInt();
279 clipType = i18n("Video clip");
282 clipType = i18n("Mute video clip");
285 clipType = i18n("Audio clip");
288 clipType = i18n("Playlist clip");
291 clipType = i18n("Image clip");
294 clipType = i18n("Slideshow clip");
297 clipType = i18n("Video clip");
299 QTreeWidgetItem *item = new QTreeWidgetItem(m_ui.treeWidget, QStringList() << clipType);
300 item->setIcon(0, KIcon("timeadjust"));
301 item->setText(1, e.attribute("resource"));
302 item->setData(0, hashRole, e.attribute("file_hash"));
303 item->setData(0, sizeRole, e.attribute("_mismatch"));
304 e.removeAttribute("_mismatch");
305 item->setData(0, resetDurationRole, (int) e.hasAttribute("_resetDuration"));
306 e.removeAttribute("_resetDuration");
307 item->setData(0, statusRole, CLIPWRONGDURATION);
308 item->setData(0, typeRole, t);
309 item->setData(0, idRole, e.attribute("id"));
310 item->setToolTip(0, i18n("Duration mismatch"));
313 if (missingProxies.count() > 0) {
314 QTreeWidgetItem *item = new QTreeWidgetItem(m_ui.treeWidget, QStringList() << i18n("Proxy clip"));
315 item->setIcon(0, KIcon("dialog-warning"));
316 item->setText(1, i18n("%1 missing proxy clips, will be recreated on project opening", missingProxies.count()));
317 item->setData(0, hashRole, e.attribute("file_hash"));
318 item->setData(0, statusRole, PROXYMISSING);
319 item->setToolTip(0, i18n("Missing proxy"));
322 max = missingProxies.count();
323 for (int i = 0; i < max; i++) {
324 e = missingProxies.at(i).toElement();
326 QString realPath = e.attribute("resource");
327 QString id = e.attribute("id");
328 // Tell Kdenlive to recreate proxy
329 e.setAttribute("_replaceproxy", "1");
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(searchDir, 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(const QDir &dir, const QString &file) const
464 KUrl searchPath(KdenliveSettings::mltpath());
465 QString fname = KUrl(file).fileName();
466 if (file.contains("PAL"))
467 searchPath.cd("../lumas/PAL");
469 searchPath.cd("../lumas/NTSC");
470 QString result = searchPath.path(KUrl::AddTrailingSlash) + fname;
471 if (QFile::exists(result))
473 // try to find luma in application path
475 searchPath = KUrl(QCoreApplication::applicationDirPath());
476 searchPath.cd("../share/apps/kdenlive/lumas");
477 result = searchPath.path(KUrl::AddTrailingSlash) + fname;
478 if (QFile::exists(result))
480 // Try in Kdenlive's standard KDE path
481 result = KStandardDirs::locate("appdata", "lumas/" + fname);
482 if (!result.isEmpty()) return result;
483 // Try in user's chosen folder
484 return searchPathRecursively(dir, fname);
487 QString DocumentChecker::searchPathRecursively(const QDir &dir, const QString &fileName) const
489 QString foundFileName;
493 searchDir.setNameFilters(filters);
494 QStringList filesAndDirs = searchDir.entryList(QDir::Files | QDir::Readable);
495 if (!filesAndDirs.isEmpty()) return searchDir.absoluteFilePath(filesAndDirs.at(0));
496 searchDir.setNameFilters(QStringList());
497 filesAndDirs = searchDir.entryList(QDir::Dirs | QDir::Readable | QDir::Executable | QDir::NoDotAndDotDot);
498 for (int i = 0; i < filesAndDirs.size() && foundFileName.isEmpty(); i++) {
499 foundFileName = searchPathRecursively(searchDir.absoluteFilePath(filesAndDirs.at(i)), fileName);
500 if (!foundFileName.isEmpty())
503 return foundFileName;
506 QString DocumentChecker::searchFileRecursively(const QDir &dir, const QString &matchSize, const QString &matchHash) const
508 QString foundFileName;
511 QStringList filesAndDirs = dir.entryList(QDir::Files | QDir::Readable);
512 for (int i = 0; i < filesAndDirs.size() && foundFileName.isEmpty(); i++) {
513 QFile file(dir.absoluteFilePath(filesAndDirs.at(i)));
514 if (QString::number(file.size()) == matchSize) {
515 if (file.open(QIODevice::ReadOnly)) {
517 * 1 MB = 1 second per 450 files (or faster)
518 * 10 MB = 9 seconds per 450 files (or faster)
520 if (file.size() > 1000000 * 2) {
521 fileData = file.read(1000000);
522 if (file.seek(file.size() - 1000000))
523 fileData.append(file.readAll());
525 fileData = file.readAll();
527 fileHash = QCryptographicHash::hash(fileData, QCryptographicHash::Md5);
528 if (QString(fileHash.toHex()) == matchHash)
529 return file.fileName();
532 //kDebug() << filesAndDirs.at(i) << file.size() << fileHash.toHex();
534 filesAndDirs = dir.entryList(QDir::Dirs | QDir::Readable | QDir::Executable | QDir::NoDotAndDotDot);
535 for (int i = 0; i < filesAndDirs.size() && foundFileName.isEmpty(); i++) {
536 foundFileName = searchFileRecursively(dir.absoluteFilePath(filesAndDirs.at(i)), matchSize, matchHash);
537 if (!foundFileName.isEmpty())
540 return foundFileName;
543 void DocumentChecker::slotEditItem(QTreeWidgetItem *item, int)
545 int t = item->data(0, typeRole).toInt();
546 if (t == TITLE_FONT_ELEMENT) return;
547 //|| t == TITLE_IMAGE_ELEMENT) {
549 KUrl url = KUrlRequesterDialog::getUrl(item->text(1), m_dialog, i18n("Enter new location for file"));
550 if (url.isEmpty()) return;
551 item->setText(1, url.path());
552 if (KIO::NetAccess::exists(url, KIO::NetAccess::SourceSide, 0)) {
553 item->setIcon(0, KIcon("dialog-ok"));
554 int id = item->data(0, statusRole).toInt();
555 if (id < 10) item->setData(0, statusRole, CLIPOK);
556 else item->setData(0, statusRole, LUMAOK);
559 item->setIcon(0, KIcon("dialog-close"));
560 int id = item->data(0, statusRole).toInt();
561 if (id < 10) item->setData(0, statusRole, CLIPMISSING);
562 else item->setData(0, statusRole, LUMAMISSING);
568 void DocumentChecker::acceptDialog()
570 QDomElement e, property;
571 QDomNodeList producers = m_doc.elementsByTagName("producer");
572 QDomNodeList infoproducers = m_doc.elementsByTagName("kdenlive_producer");
573 QDomNodeList properties;
576 // prepare transitions
577 QDomNodeList trans = m_doc.elementsByTagName("transition");
579 // Mark document as modified
580 m_doc.documentElement().setAttribute("modified", 1);
582 QTreeWidgetItem *child = m_ui.treeWidget->topLevelItem(ix);
584 int t = child->data(0, typeRole).toInt();
585 if (child->data(0, statusRole).toInt() == CLIPOK) {
586 QString id = child->data(0, idRole).toString();
587 if (t == TITLE_IMAGE_ELEMENT) {
588 // edit images embedded in titles
589 for (int i = 0; i < infoproducers.count(); i++) {
590 e = infoproducers.item(i).toElement();
591 if (e.attribute("id") == id) {
593 QString xml = e.attribute("xmldata");
594 xml.replace(child->data(0, typeOriginalResource).toString(), child->text(1));
595 e.setAttribute("xmldata", xml);
599 for (int i = 0; i < producers.count(); i++) {
600 e = producers.item(i).toElement();
601 if (e.attribute("id").section('_', 0, 0) == id) {
603 properties = e.childNodes();
604 for (int j = 0; j < properties.count(); ++j) {
605 property = properties.item(j).toElement();
606 if (property.attribute("name") == "xmldata") {
607 QString xml = property.firstChild().nodeValue();
608 xml.replace(child->data(0, typeOriginalResource).toString(), child->text(1));
609 property.firstChild().setNodeValue(xml);
617 for (int i = 0; i < infoproducers.count(); i++) {
618 e = infoproducers.item(i).toElement();
619 if (e.attribute("id") == id) {
621 e.setAttribute("resource", child->text(1));
622 e.setAttribute("name", KUrl(child->text(1)).fileName());
626 for (int i = 0; i < producers.count(); i++) {
627 e = producers.item(i).toElement();
628 if (e.attribute("id").section('_', 0, 0) == id || e.attribute("id").section(':', 1, 1) == id) {
630 properties = e.childNodes();
631 for (int j = 0; j < properties.count(); ++j) {
632 property = properties.item(j).toElement();
633 if (property.attribute("name") == "resource") {
634 QString resource = property.firstChild().nodeValue();
635 if (resource.contains(QRegExp("\\?[0-9]+\\.[0-9]+(&strobe=[0-9]+)?$")))
636 property.firstChild().setNodeValue(child->text(1) + '?' + resource.section('?', -1));
638 property.firstChild().setNodeValue(child->text(1));
645 } else if (child->data(0, statusRole).toInt() == CLIPPLACEHOLDER && t != TITLE_FONT_ELEMENT && t != TITLE_IMAGE_ELEMENT) {
646 QString id = child->data(0, idRole).toString();
647 for (int i = 0; i < infoproducers.count(); i++) {
648 e = infoproducers.item(i).toElement();
649 if (e.attribute("id") == id) {
651 e.setAttribute("placeholder", '1');
655 } else if (child->data(0, statusRole).toInt() == LUMAOK) {
656 for (int i = 0; i < trans.count(); i++) {
657 QString luma = getProperty(trans.at(i).toElement(), "luma");
659 kDebug() << "luma: " << luma;
660 if (!luma.isEmpty() && luma == child->data(0, idRole).toString()) {
661 setProperty(trans.at(i).toElement(), "luma", child->text(1));
662 kDebug() << "replace with; " << child->text(1);
665 } else if (child->data(0, statusRole).toInt() == LUMAMISSING) {
666 for (int i = 0; i < trans.count(); i++) {
667 QString luma = getProperty(trans.at(i).toElement(), "luma");
668 if (!luma.isEmpty() && luma == child->data(0, idRole).toString()) {
669 setProperty(trans.at(i).toElement(), "luma", QString());
674 child = m_ui.treeWidget->topLevelItem(ix);
679 void DocumentChecker::slotPlaceholders()
682 QTreeWidgetItem *child = m_ui.treeWidget->topLevelItem(ix);
684 if (child->data(0, statusRole).toInt() == CLIPMISSING) {
685 child->setData(0, statusRole, CLIPPLACEHOLDER);
686 child->setIcon(0, KIcon("dialog-ok"));
687 } else if (child->data(0, statusRole).toInt() == LUMAMISSING) {
688 child->setData(0, statusRole, LUMAPLACEHOLDER);
689 child->setIcon(0, KIcon("dialog-ok"));
692 child = m_ui.treeWidget->topLevelItem(ix);
697 void DocumentChecker::slotFixDuration()
700 QTreeWidgetItem *child = m_ui.treeWidget->topLevelItem(ix);
701 QDomNodeList documentProducers = m_doc.elementsByTagName("producer");
703 if (child->data(0, statusRole).toInt() == CLIPWRONGDURATION) {
704 QString id = child->data(0, idRole).toString();
705 bool resetDuration = child->data(0, resetDurationRole).toInt();
707 for (int i = 0; i < m_info.count(); i++) {
708 QDomElement e = m_info.at(i).toElement();
709 if (e.attribute("id") == id) {
710 if (m_missingClips.contains(e)) {
711 // we cannot fix duration of missing clips
712 resetDuration = false;
715 if (resetDuration) e.removeAttribute("duration");
716 else e.setAttribute("duration", child->data(0, sizeRole).toString());
717 child->setData(0, statusRole, CLIPOK);
718 child->setIcon(0, KIcon("dialog-ok"));
724 // something is wrong in clip durations, so remove them so mlt fetches them again
725 for (int j = 0; j < documentProducers.count(); j++) {
726 QDomElement mltProd = documentProducers.at(j).toElement();
727 QString prodId = mltProd.attribute("id");
728 if (prodId == id || prodId.startsWith(id + "_")) {
729 EffectsList::removeProperty(mltProd, "length");
735 child = m_ui.treeWidget->topLevelItem(ix);
737 QDomElement infoXml = m_doc.elementsByTagName("kdenlivedoc").at(0).toElement();
738 infoXml.setAttribute("modified", "1");
739 m_ui.fixDuration->setEnabled(false);
744 void DocumentChecker::checkStatus()
748 QTreeWidgetItem *child = m_ui.treeWidget->topLevelItem(ix);
750 int status = child->data(0, statusRole).toInt();
751 if (status == CLIPMISSING || status == LUMAMISSING || status == CLIPWRONGDURATION) {
756 child = m_ui.treeWidget->topLevelItem(ix);
758 m_ui.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(status);
762 void DocumentChecker::slotDeleteSelected()
764 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)
766 QStringList deletedIds;
767 QStringList deletedLumas;
768 QDomNodeList playlists = m_doc.elementsByTagName("playlist");
770 foreach(QTreeWidgetItem *child, m_ui.treeWidget->selectedItems()) {
771 int id = child->data(0, statusRole).toInt();
772 if (id == CLIPMISSING) {
773 deletedIds.append(child->data(0, idRole).toString());
776 else if (id == LUMAMISSING) {
777 deletedLumas.append(child->data(0, idRole).toString());
782 if (!deletedLumas.isEmpty()) {
784 QDomNodeList transitions = m_doc.elementsByTagName("transition");
785 foreach (QString lumaPath, deletedLumas) {
786 for (int i = 0; i < transitions.count(); i++) {
787 e = transitions.item(i).toElement();
788 QString resource = EffectsList::property(e, "luma");
789 if (resource == lumaPath) EffectsList::removeProperty(e, "luma");
794 if (!deletedIds.isEmpty()) {
796 QDomNodeList producers = m_doc.elementsByTagName("producer");
797 QDomNodeList infoproducers = m_doc.elementsByTagName("kdenlive_producer");
799 QDomNode mlt = m_doc.elementsByTagName("mlt").at(0);
800 QDomNode kdenlivedoc = m_doc.elementsByTagName("kdenlivedoc").at(0);
802 for (int i = 0, j = 0; i < infoproducers.count() && j < deletedIds.count(); i++) {
803 e = infoproducers.item(i).toElement();
804 if (deletedIds.contains(e.attribute("id"))) {
806 kdenlivedoc.removeChild(e);
812 for (int i = 0; i < producers.count(); i++) {
813 e = producers.item(i).toElement();
814 if (deletedIds.contains(e.attribute("id").section('_', 0, 0)) || deletedIds.contains(e.attribute("id").section(':', 1, 1).section('_', 0, 0))) {
821 for (int i = 0; i < playlists.count(); i++) {
822 QDomNodeList entries = playlists.at(i).toElement().elementsByTagName("entry");
823 for (int j = 0; j < entries.count(); j++) {
824 e = entries.item(j).toElement();
825 if (deletedIds.contains(e.attribute("producer").section('_', 0, 0)) || deletedIds.contains(e.attribute("producer").section(':', 1, 1).section('_', 0, 0))) {
826 // Replace clip with blank
827 while (e.childNodes().count() > 0)
828 e.removeChild(e.firstChild());
829 e.setTagName("blank");
830 e.removeAttribute("producer");
831 int length = e.attribute("out").toInt() - e.attribute("in").toInt();
832 e.setAttribute("length", length);
837 QDomElement infoXml = m_doc.elementsByTagName("kdenlivedoc").at(0).toElement();
838 infoXml.setAttribute("modified", "1");
843 void DocumentChecker::checkMissingImagesAndFonts(QStringList images, QStringList fonts, const QString &id, const QString &baseClip)
846 foreach(const QString &img, images) {
847 if (m_safeImages.contains(img)) continue;
848 if (!KIO::NetAccess::exists(KUrl(img), KIO::NetAccess::SourceSide, 0)) {
849 QDomElement e = doc.createElement("missingclip");
850 e.setAttribute("type", TITLE_IMAGE_ELEMENT);
851 e.setAttribute("resource", img);
852 e.setAttribute("id", id);
853 e.setAttribute("name", baseClip);
854 m_missingClips.append(e);
856 else m_safeImages.append(img);
858 foreach(const QString &fontelement, fonts) {
859 if (m_safeFonts.contains(fontelement)) continue;
860 QFont f(fontelement);
861 //kDebug() << "/ / / CHK FONTS: " << fontelement << " = " << QFontInfo(f).family();
862 if (fontelement != QFontInfo(f).family()) {
863 QDomElement e = doc.createElement("missingclip");
864 e.setAttribute("type", TITLE_FONT_ELEMENT);
865 e.setAttribute("resource", fontelement);
866 e.setAttribute("id", id);
867 e.setAttribute("name", baseClip);
868 m_missingClips.append(e);
870 else m_safeFonts.append(fontelement);
875 void DocumentChecker::slotCheckButtons()
877 if (m_ui.treeWidget->currentItem()) {
878 QTreeWidgetItem *item = m_ui.treeWidget->currentItem();
879 int t = item->data(0, typeRole).toInt();
880 int s = item->data(0, statusRole).toInt();
881 if (t == TITLE_FONT_ELEMENT || t == TITLE_IMAGE_ELEMENT || s == PROXYMISSING) {
882 m_ui.removeSelected->setEnabled(false);
883 } else m_ui.removeSelected->setEnabled(true);
888 #include "documentchecker.moc"