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;
84 for (int i = 0; i < max; i++) {
85 e = m_info.item(i).toElement();
86 clipType = e.attribute("type").toInt();
87 if (clipType == COLOR) continue;
88 if (clipType != TEXT && clipType != IMAGE && clipType != SLIDESHOW) {
89 QString id = e.attribute("id");
90 int duration = e.attribute("duration").toInt();
94 // Check that the duration is in sync between Kdenlive's info and MLT's playlist
95 int prodsCount = documentProducers.count();
96 for (int j = 0; j < prodsCount; j++) {
97 mltProd = documentProducers.at(j).toElement();
98 prodId = mltProd.attribute("id");
99 // Don't check slowmotion clips for now... (TODO?)
100 if (prodId.startsWith("slowmotion")) continue;
101 if (prodId.contains("_")) prodId = prodId.section("_", 0, 0);
102 if (prodId != id) continue;
103 if (mltDuration > 0 ) {
104 // We have several MLT producers for the same clip (probably track producers)
105 int newLength = EffectsList::property(mltProd, "length").toInt();
106 if (newLength != mltDuration) {
107 // we have a different duration for the same clip, that is not safe
108 e.setAttribute("_resetDuration", 1);
111 mltDuration = EffectsList::property(mltProd, "length").toInt();
112 if (mltDuration != duration) {
114 e.setAttribute("_mismatch", mltDuration);
115 if (mltDuration == 15000) {
116 // a length of 15000 might indicate a wrong clip length since it is a default length
117 e.setAttribute("_resetDuration", 1);
119 if (!wrongDurationClips.contains(e)) wrongDurationClips.append(e);
124 if (clipType == TEXT) {
125 //TODO: Check is clip template is missing (xmltemplate) or hash changed
126 QStringList images = TitleWidget::extractImageList(e.attribute("xmldata"));
127 QStringList fonts = TitleWidget::extractFontList(e.attribute("xmldata"));
128 checkMissingImagesAndFonts(images, fonts, e.attribute("id"), e.attribute("name"));
131 resource = e.attribute("resource");
132 if (e.hasAttribute("proxy")) {
133 QString proxyresource = e.attribute("proxy");
134 if (!proxyresource.isEmpty() && proxyresource != "-" && !KIO::NetAccess::exists(KUrl(proxyresource), KIO::NetAccess::SourceSide, 0)) {
135 // Missing clip found
136 missingProxies.append(e);
139 if (clipType == SLIDESHOW) resource = KUrl(resource).directory();
140 if (!KIO::NetAccess::exists(KUrl(resource), KIO::NetAccess::SourceSide, 0)) {
141 // Missing clip found
142 m_missingClips.append(e);
144 // Check if the clip has changed
145 if (clipType != SLIDESHOW && e.hasAttribute("file_hash")) {
146 if (e.attribute("file_hash") != DocClipBase::getHash(e.attribute("resource")))
147 e.removeAttribute("file_hash");
152 // Get list of used Luma files
153 QStringList missingLumas;
154 QStringList filesToCheck;
156 QString root = m_doc.documentElement().attribute("root");
157 if (!root.isEmpty()) root = KUrl(root).path(KUrl::AddTrailingSlash);
158 QDomNodeList trans = m_doc.elementsByTagName("transition");
160 for (int i = 0; i < max; i++) {
161 QString luma = getProperty(trans.at(i).toElement(), "luma");
162 if (!luma.isEmpty() && !filesToCheck.contains(luma))
163 filesToCheck.append(luma);
165 // Check existence of luma files
166 foreach (const QString lumafile, filesToCheck) {
168 if (!filePath.startsWith('/')) filePath.prepend(root);
169 if (!QFile::exists(filePath)) {
170 missingLumas.append(lumafile);
176 if (m_missingClips.isEmpty() && missingLumas.isEmpty() && wrongDurationClips.isEmpty() && missingProxies.isEmpty())
179 m_dialog = new QDialog();
180 m_dialog->setFont(KGlobalSettings::toolBarFont());
181 m_ui.setupUi(m_dialog);
183 foreach(const QString l, missingLumas) {
184 QTreeWidgetItem *item = new QTreeWidgetItem(m_ui.treeWidget, QStringList() << i18n("Luma file") << l);
185 item->setIcon(0, KIcon("dialog-close"));
186 item->setData(0, idRole, l);
187 item->setData(0, statusRole, LUMAMISSING);
190 m_ui.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
191 max = m_missingClips.count();
192 for (int i = 0; i < max; i++) {
193 e = m_missingClips.at(i).toElement();
195 int t = e.attribute("type").toInt();
198 clipType = i18n("Video clip");
201 clipType = i18n("Mute video clip");
204 clipType = i18n("Audio clip");
207 clipType = i18n("Playlist clip");
210 clipType = i18n("Image clip");
213 clipType = i18n("Slideshow clip");
215 case TITLE_IMAGE_ELEMENT:
216 clipType = i18n("Title Image");
218 case TITLE_FONT_ELEMENT:
219 clipType = i18n("Title Font");
222 clipType = i18n("Video clip");
224 QTreeWidgetItem *item = new QTreeWidgetItem(m_ui.treeWidget, QStringList() << clipType);
225 if (t == TITLE_IMAGE_ELEMENT) {
226 item->setIcon(0, KIcon("dialog-warning"));
227 item->setToolTip(1, e.attribute("name"));
228 item->setText(1, e.attribute("resource"));
229 item->setData(0, statusRole, CLIPPLACEHOLDER);
230 item->setData(0, typeOriginalResource, e.attribute("resource"));
231 } else if (t == TITLE_FONT_ELEMENT) {
232 item->setIcon(0, KIcon("dialog-warning"));
233 item->setToolTip(1, e.attribute("name"));
234 QString ft = e.attribute("resource");
235 QString newft = QFontInfo(QFont(ft)).family();
236 item->setText(1, i18n("%1 will be replaced by %2", ft, newft));
237 item->setData(0, statusRole, CLIPPLACEHOLDER);
239 item->setIcon(0, KIcon("dialog-close"));
240 item->setText(1, e.attribute("resource"));
241 item->setData(0, hashRole, e.attribute("file_hash"));
242 item->setData(0, sizeRole, e.attribute("file_size"));
243 item->setData(0, statusRole, CLIPMISSING);
245 item->setData(0, typeRole, t);
246 item->setData(0, idRole, e.attribute("id"));
247 item->setToolTip(0, i18n("Missing item"));
250 if (m_missingClips.count() > 0) {
251 if (wrongDurationClips.count() > 0) {
252 m_ui.infoLabel->setText(i18n("The project file contains missing clips or files and clip duration mismatch"));
255 m_ui.infoLabel->setText(i18n("The project file contains missing clips or files"));
258 else if (wrongDurationClips.count() > 0) {
259 m_ui.infoLabel->setText(i18n("The project file contains clips with duration mismatch"));
261 if (missingProxies.count() > 0) {
262 if (!m_ui.infoLabel->text().isEmpty()) m_ui.infoLabel->setText(m_ui.infoLabel->text() + ". ");
263 m_ui.infoLabel->setText(m_ui.infoLabel->text() + i18n("Missing proxies will be recreated after opening."));
266 m_ui.removeSelected->setEnabled(!m_missingClips.isEmpty());
267 m_ui.recursiveSearch->setEnabled(!m_missingClips.isEmpty() || !missingLumas.isEmpty());
268 m_ui.usePlaceholders->setEnabled(!m_missingClips.isEmpty());
269 m_ui.fixDuration->setEnabled(!wrongDurationClips.isEmpty());
271 max = wrongDurationClips.count();
272 for (int i = 0; i < max; i++) {
273 e = wrongDurationClips.at(i).toElement();
275 int t = e.attribute("type").toInt();
278 clipType = i18n("Video clip");
281 clipType = i18n("Mute video clip");
284 clipType = i18n("Audio clip");
287 clipType = i18n("Playlist clip");
290 clipType = i18n("Image clip");
293 clipType = i18n("Slideshow clip");
296 clipType = i18n("Video clip");
298 QTreeWidgetItem *item = new QTreeWidgetItem(m_ui.treeWidget, QStringList() << clipType);
299 item->setIcon(0, KIcon("timeadjust"));
300 item->setText(1, e.attribute("resource"));
301 item->setData(0, hashRole, e.attribute("file_hash"));
302 item->setData(0, sizeRole, e.attribute("_mismatch"));
303 e.removeAttribute("_mismatch");
304 item->setData(0, resetDurationRole, (int) e.hasAttribute("_resetDuration"));
305 e.removeAttribute("_resetDuration");
306 item->setData(0, statusRole, CLIPWRONGDURATION);
307 item->setData(0, typeRole, t);
308 item->setData(0, idRole, e.attribute("id"));
309 item->setToolTip(0, i18n("Duration mismatch"));
312 if (missingProxies.count() > 0) {
313 QTreeWidgetItem *item = new QTreeWidgetItem(m_ui.treeWidget, QStringList() << i18n("Proxy clip"));
314 item->setIcon(0, KIcon("dialog-warning"));
315 item->setText(1, i18n("%1 missing proxy clips, will be recreated on project opening", missingProxies.count()));
316 item->setData(0, hashRole, e.attribute("file_hash"));
317 item->setData(0, statusRole, PROXYMISSING);
318 item->setToolTip(0, i18n("Missing proxy"));
321 max = missingProxies.count();
322 for (int i = 0; i < max; i++) {
323 e = missingProxies.at(i).toElement();
325 QString realPath = e.attribute("resource");
326 QString id = e.attribute("id");
327 // Replace proxy url with real clip in MLT producers
328 QDomNodeList properties;
330 QDomElement property;
331 int prodsCount = documentProducers.count();
332 for (int j = 0; j < prodsCount; j++) {
333 mltProd = documentProducers.at(j).toElement();
334 QString prodId = mltProd.attribute("id");
335 bool slowmotion = false;
336 if (prodId.startsWith("slowmotion")) {
338 prodId = prodId.section(':', 1, 1);
340 if (prodId.contains('_')) prodId = prodId.section('_', 0, 0);
342 // Hit, we must replace url
343 properties = mltProd.childNodes();
344 for (int k = 0; k < properties.count(); ++k) {
345 property = properties.item(k).toElement();
346 if (property.attribute("name") == "resource") {
347 QString resource = property.firstChild().nodeValue();
349 if (slowmotion) suffix = "?" + resource.section('?', -1);
350 property.firstChild().setNodeValue(realPath + suffix);
358 if (missingProxies.count() > 0) {
359 // original doc was modified
360 QDomElement infoXml = m_doc.elementsByTagName("kdenlivedoc").at(0).toElement();
361 infoXml.setAttribute("modified", "1");
364 connect(m_ui.recursiveSearch, SIGNAL(pressed()), this, SLOT(slotSearchClips()));
365 connect(m_ui.usePlaceholders, SIGNAL(pressed()), this, SLOT(slotPlaceholders()));
366 connect(m_ui.removeSelected, SIGNAL(pressed()), this, SLOT(slotDeleteSelected()));
367 connect(m_ui.fixDuration, SIGNAL(pressed()), this, SLOT(slotFixDuration()));
368 connect(m_ui.treeWidget, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)), this, SLOT(slotEditItem(QTreeWidgetItem *, int)));
369 connect(m_ui.treeWidget, SIGNAL(itemSelectionChanged()), this, SLOT(slotCheckButtons()));
371 if (m_ui.treeWidget->topLevelItem(0)) m_ui.treeWidget->setCurrentItem(m_ui.treeWidget->topLevelItem(0));
373 int acceptMissing = m_dialog->exec();
374 if (acceptMissing == QDialog::Accepted) acceptDialog();
375 return (acceptMissing != QDialog::Accepted);
378 DocumentChecker::~DocumentChecker()
380 if (m_dialog) delete m_dialog;
384 QString DocumentChecker::getProperty(QDomElement effect, const QString &name)
386 QDomNodeList params = effect.elementsByTagName("property");
387 for (int i = 0; i < params.count(); i++) {
388 QDomElement e = params.item(i).toElement();
389 if (e.attribute("name") == name) {
390 return e.firstChild().nodeValue();
396 void DocumentChecker::setProperty(QDomElement effect, const QString &name, const QString value)
398 QDomNodeList params = effect.elementsByTagName("property");
399 for (int i = 0; i < params.count(); i++) {
400 QDomElement e = params.item(i).toElement();
401 if (e.attribute("name") == name) {
402 e.firstChild().setNodeValue(value);
407 void DocumentChecker::slotSearchClips()
409 QString newpath = KFileDialog::getExistingDirectory(KUrl("kfiledialog:///clipfolder"), kapp->activeWindow(), i18n("Clips folder"));
410 if (newpath.isEmpty()) return;
413 m_ui.recursiveSearch->setEnabled(false);
414 QTreeWidgetItem *child = m_ui.treeWidget->topLevelItem(ix);
415 QDir searchDir(newpath);
417 if (child->data(0, statusRole).toInt() == CLIPMISSING) {
418 QString clipPath = searchFileRecursively(searchDir, child->data(0, sizeRole).toString(), child->data(0, hashRole).toString());
419 if (!clipPath.isEmpty()) {
421 child->setText(1, clipPath);
422 child->setIcon(0, KIcon("dialog-ok"));
423 child->setData(0, statusRole, CLIPOK);
425 } else if (child->data(0, statusRole).toInt() == LUMAMISSING) {
426 QString fileName = searchLuma(child->data(0, idRole).toString());
427 if (!fileName.isEmpty()) {
429 child->setText(1, fileName);
430 child->setIcon(0, KIcon("dialog-ok"));
431 child->setData(0, statusRole, LUMAOK);
434 else if (child->data(0, typeRole).toInt() == TITLE_IMAGE_ELEMENT && child->data(0, statusRole).toInt() == CLIPPLACEHOLDER) {
435 // Search missing title images
436 QString missingFileName = KUrl(child->text(1)).fileName();
437 QString newPath = searchPathRecursively(searchDir, missingFileName);
438 if (!newPath.isEmpty()) {
441 child->setText(1, newPath);
442 child->setIcon(0, KIcon("dialog-ok"));
443 child->setData(0, statusRole, CLIPOK);
447 child = m_ui.treeWidget->topLevelItem(ix);
449 m_ui.recursiveSearch->setEnabled(true);
451 // original doc was modified
452 QDomElement infoXml = m_doc.elementsByTagName("kdenlivedoc").at(0).toElement();
453 infoXml.setAttribute("modified", "1");
459 QString DocumentChecker::searchLuma(const QString &file) const
461 KUrl searchPath(KdenliveSettings::mltpath());
462 if (file.contains("PAL"))
463 searchPath.cd("../lumas/PAL");
465 searchPath.cd("../lumas/NTSC");
466 QString result = searchPath.path(KUrl::AddTrailingSlash) + KUrl(file).fileName();
467 if (QFile::exists(result))
469 // try to find luma in application path
471 searchPath = KUrl(QCoreApplication::applicationDirPath());
472 searchPath.cd("../share/apps/kdenlive/lumas");
473 result = searchPath.path(KUrl::AddTrailingSlash) + KUrl(file).fileName();
474 if (QFile::exists(result))
479 QString DocumentChecker::searchPathRecursively(const QDir &dir, const QString &fileName) const
481 QString foundFileName;
485 searchDir.setNameFilters(filters);
486 QStringList filesAndDirs = searchDir.entryList(QDir::Files | QDir::Readable);
487 if (!filesAndDirs.isEmpty()) return searchDir.absoluteFilePath(filesAndDirs.at(0));
488 searchDir.setNameFilters(QStringList());
489 filesAndDirs = searchDir.entryList(QDir::Dirs | QDir::Readable | QDir::Executable | QDir::NoDotAndDotDot);
490 for (int i = 0; i < filesAndDirs.size() && foundFileName.isEmpty(); i++) {
491 foundFileName = searchPathRecursively(searchDir.absoluteFilePath(filesAndDirs.at(i)), fileName);
492 if (!foundFileName.isEmpty())
495 return foundFileName;
498 QString DocumentChecker::searchFileRecursively(const QDir &dir, const QString &matchSize, const QString &matchHash) const
500 QString foundFileName;
503 QStringList filesAndDirs = dir.entryList(QDir::Files | QDir::Readable);
504 for (int i = 0; i < filesAndDirs.size() && foundFileName.isEmpty(); i++) {
505 QFile file(dir.absoluteFilePath(filesAndDirs.at(i)));
506 if (QString::number(file.size()) == matchSize) {
507 if (file.open(QIODevice::ReadOnly)) {
509 * 1 MB = 1 second per 450 files (or faster)
510 * 10 MB = 9 seconds per 450 files (or faster)
512 if (file.size() > 1000000 * 2) {
513 fileData = file.read(1000000);
514 if (file.seek(file.size() - 1000000))
515 fileData.append(file.readAll());
517 fileData = file.readAll();
519 fileHash = QCryptographicHash::hash(fileData, QCryptographicHash::Md5);
520 if (QString(fileHash.toHex()) == matchHash)
521 return file.fileName();
524 //kDebug() << filesAndDirs.at(i) << file.size() << fileHash.toHex();
526 filesAndDirs = dir.entryList(QDir::Dirs | QDir::Readable | QDir::Executable | QDir::NoDotAndDotDot);
527 for (int i = 0; i < filesAndDirs.size() && foundFileName.isEmpty(); i++) {
528 foundFileName = searchFileRecursively(dir.absoluteFilePath(filesAndDirs.at(i)), matchSize, matchHash);
529 if (!foundFileName.isEmpty())
532 return foundFileName;
535 void DocumentChecker::slotEditItem(QTreeWidgetItem *item, int)
537 int t = item->data(0, typeRole).toInt();
538 if (t == TITLE_FONT_ELEMENT) return;
539 //|| t == TITLE_IMAGE_ELEMENT) {
541 KUrl url = KUrlRequesterDialog::getUrl(item->text(1), m_dialog, i18n("Enter new location for file"));
542 if (url.isEmpty()) return;
543 item->setText(1, url.path());
544 if (KIO::NetAccess::exists(url, KIO::NetAccess::SourceSide, 0)) {
545 item->setIcon(0, KIcon("dialog-ok"));
546 int id = item->data(0, statusRole).toInt();
547 if (id < 10) item->setData(0, statusRole, CLIPOK);
548 else item->setData(0, statusRole, LUMAOK);
551 item->setIcon(0, KIcon("dialog-close"));
552 int id = item->data(0, statusRole).toInt();
553 if (id < 10) item->setData(0, statusRole, CLIPMISSING);
554 else item->setData(0, statusRole, LUMAMISSING);
560 void DocumentChecker::acceptDialog()
562 QDomElement e, property;
563 QDomNodeList producers = m_doc.elementsByTagName("producer");
564 QDomNodeList infoproducers = m_doc.elementsByTagName("kdenlive_producer");
565 QDomNodeList properties;
568 // prepare transitions
569 QDomNodeList trans = m_doc.elementsByTagName("transition");
571 // Mark document as modified
572 m_doc.documentElement().setAttribute("modified", 1);
574 QTreeWidgetItem *child = m_ui.treeWidget->topLevelItem(ix);
576 int t = child->data(0, typeRole).toInt();
577 if (child->data(0, statusRole).toInt() == CLIPOK) {
578 QString id = child->data(0, idRole).toString();
579 if (t == TITLE_IMAGE_ELEMENT) {
580 // edit images embedded in titles
581 for (int i = 0; i < infoproducers.count(); i++) {
582 e = infoproducers.item(i).toElement();
583 if (e.attribute("id") == id) {
585 QString xml = e.attribute("xmldata");
586 xml.replace(child->data(0, typeOriginalResource).toString(), child->text(1));
587 e.setAttribute("xmldata", xml);
591 for (int i = 0; i < producers.count(); i++) {
592 e = producers.item(i).toElement();
593 if (e.attribute("id").section('_', 0, 0) == id) {
595 properties = e.childNodes();
596 for (int j = 0; j < properties.count(); ++j) {
597 property = properties.item(j).toElement();
598 if (property.attribute("name") == "xmldata") {
599 QString xml = property.firstChild().nodeValue();
600 xml.replace(child->data(0, typeOriginalResource).toString(), child->text(1));
601 property.firstChild().setNodeValue(xml);
609 for (int i = 0; i < infoproducers.count(); i++) {
610 e = infoproducers.item(i).toElement();
611 if (e.attribute("id") == id) {
613 e.setAttribute("resource", child->text(1));
614 e.setAttribute("name", KUrl(child->text(1)).fileName());
618 for (int i = 0; i < producers.count(); i++) {
619 e = producers.item(i).toElement();
620 if (e.attribute("id").section('_', 0, 0) == id || e.attribute("id").section(':', 1, 1) == id) {
622 properties = e.childNodes();
623 for (int j = 0; j < properties.count(); ++j) {
624 property = properties.item(j).toElement();
625 if (property.attribute("name") == "resource") {
626 QString resource = property.firstChild().nodeValue();
627 if (resource.contains(QRegExp("\\?[0-9]+\\.[0-9]+(&strobe=[0-9]+)?$")))
628 property.firstChild().setNodeValue(child->text(1) + '?' + resource.section('?', -1));
630 property.firstChild().setNodeValue(child->text(1));
637 } else if (child->data(0, statusRole).toInt() == CLIPPLACEHOLDER && t != TITLE_FONT_ELEMENT && t != TITLE_IMAGE_ELEMENT) {
638 QString id = child->data(0, idRole).toString();
639 for (int i = 0; i < infoproducers.count(); i++) {
640 e = infoproducers.item(i).toElement();
641 if (e.attribute("id") == id) {
643 e.setAttribute("placeholder", '1');
647 } else if (child->data(0, statusRole).toInt() == LUMAOK) {
648 for (int i = 0; i < trans.count(); i++) {
649 QString luma = getProperty(trans.at(i).toElement(), "luma");
651 kDebug() << "luma: " << luma;
652 if (!luma.isEmpty() && luma == child->data(0, idRole).toString()) {
653 setProperty(trans.at(i).toElement(), "luma", child->text(1));
654 kDebug() << "replace with; " << child->text(1);
657 } else if (child->data(0, statusRole).toInt() == LUMAMISSING) {
658 for (int i = 0; i < trans.count(); i++) {
659 QString luma = getProperty(trans.at(i).toElement(), "luma");
660 if (!luma.isEmpty() && luma == child->data(0, idRole).toString()) {
661 setProperty(trans.at(i).toElement(), "luma", QString());
666 child = m_ui.treeWidget->topLevelItem(ix);
671 void DocumentChecker::slotPlaceholders()
674 QTreeWidgetItem *child = m_ui.treeWidget->topLevelItem(ix);
676 if (child->data(0, statusRole).toInt() == CLIPMISSING) {
677 child->setData(0, statusRole, CLIPPLACEHOLDER);
678 child->setIcon(0, KIcon("dialog-ok"));
679 } else if (child->data(0, statusRole).toInt() == LUMAMISSING) {
680 child->setData(0, statusRole, LUMAPLACEHOLDER);
681 child->setIcon(0, KIcon("dialog-ok"));
684 child = m_ui.treeWidget->topLevelItem(ix);
689 void DocumentChecker::slotFixDuration()
692 QTreeWidgetItem *child = m_ui.treeWidget->topLevelItem(ix);
693 QDomNodeList documentProducers = m_doc.elementsByTagName("producer");
695 if (child->data(0, statusRole).toInt() == CLIPWRONGDURATION) {
696 QString id = child->data(0, idRole).toString();
697 bool resetDuration = child->data(0, resetDurationRole).toInt();
699 for (int i = 0; i < m_info.count(); i++) {
700 QDomElement e = m_info.at(i).toElement();
701 if (e.attribute("id") == id) {
702 if (m_missingClips.contains(e)) {
703 // we cannot fix duration of missing clips
704 resetDuration = false;
707 if (resetDuration) e.removeAttribute("duration");
708 else e.setAttribute("duration", child->data(0, sizeRole).toString());
709 child->setData(0, statusRole, CLIPOK);
710 child->setIcon(0, KIcon("dialog-ok"));
716 // something is wrong in clip durations, so remove them so mlt fetches them again
717 for (int j = 0; j < documentProducers.count(); j++) {
718 QDomElement mltProd = documentProducers.at(j).toElement();
719 QString prodId = mltProd.attribute("id");
720 if (prodId == id || prodId.startsWith(id + "_")) {
721 EffectsList::removeProperty(mltProd, "length");
727 child = m_ui.treeWidget->topLevelItem(ix);
729 QDomElement infoXml = m_doc.elementsByTagName("kdenlivedoc").at(0).toElement();
730 infoXml.setAttribute("modified", "1");
731 m_ui.fixDuration->setEnabled(false);
736 void DocumentChecker::checkStatus()
740 QTreeWidgetItem *child = m_ui.treeWidget->topLevelItem(ix);
742 int status = child->data(0, statusRole).toInt();
743 if (status == CLIPMISSING || status == LUMAMISSING || status == CLIPWRONGDURATION) {
748 child = m_ui.treeWidget->topLevelItem(ix);
750 m_ui.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(status);
754 void DocumentChecker::slotDeleteSelected()
756 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)
758 QStringList deletedIds;
759 QStringList deletedLumas;
760 QDomNodeList playlists = m_doc.elementsByTagName("playlist");
762 foreach(QTreeWidgetItem *child, m_ui.treeWidget->selectedItems()) {
763 int id = child->data(0, statusRole).toInt();
764 if (id == CLIPMISSING) {
765 deletedIds.append(child->data(0, idRole).toString());
768 else if (id == LUMAMISSING) {
769 deletedLumas.append(child->data(0, idRole).toString());
774 if (!deletedLumas.isEmpty()) {
776 QDomNodeList transitions = m_doc.elementsByTagName("transition");
777 foreach (QString lumaPath, deletedLumas) {
778 for (int i = 0; i < transitions.count(); i++) {
779 e = transitions.item(i).toElement();
780 QString resource = EffectsList::property(e, "luma");
781 if (resource == lumaPath) EffectsList::removeProperty(e, "luma");
786 if (!deletedIds.isEmpty()) {
788 QDomNodeList producers = m_doc.elementsByTagName("producer");
789 QDomNodeList infoproducers = m_doc.elementsByTagName("kdenlive_producer");
791 QDomNode mlt = m_doc.elementsByTagName("mlt").at(0);
792 QDomNode kdenlivedoc = m_doc.elementsByTagName("kdenlivedoc").at(0);
794 for (int i = 0, j = 0; i < infoproducers.count() && j < deletedIds.count(); i++) {
795 e = infoproducers.item(i).toElement();
796 if (deletedIds.contains(e.attribute("id"))) {
798 kdenlivedoc.removeChild(e);
804 for (int i = 0; i < producers.count(); i++) {
805 e = producers.item(i).toElement();
806 if (deletedIds.contains(e.attribute("id").section('_', 0, 0)) || deletedIds.contains(e.attribute("id").section(':', 1, 1).section('_', 0, 0))) {
813 for (int i = 0; i < playlists.count(); i++) {
814 QDomNodeList entries = playlists.at(i).toElement().elementsByTagName("entry");
815 for (int j = 0; j < entries.count(); j++) {
816 e = entries.item(j).toElement();
817 if (deletedIds.contains(e.attribute("producer").section('_', 0, 0)) || deletedIds.contains(e.attribute("producer").section(':', 1, 1).section('_', 0, 0))) {
818 // Replace clip with blank
819 while (e.childNodes().count() > 0)
820 e.removeChild(e.firstChild());
821 e.setTagName("blank");
822 e.removeAttribute("producer");
823 int length = e.attribute("out").toInt() - e.attribute("in").toInt();
824 e.setAttribute("length", length);
829 QDomElement infoXml = m_doc.elementsByTagName("kdenlivedoc").at(0).toElement();
830 infoXml.setAttribute("modified", "1");
835 void DocumentChecker::checkMissingImagesAndFonts(QStringList images, QStringList fonts, const QString &id, const QString &baseClip)
838 foreach(const QString &img, images) {
839 if (m_safeImages.contains(img)) continue;
840 if (!KIO::NetAccess::exists(KUrl(img), KIO::NetAccess::SourceSide, 0)) {
841 QDomElement e = doc.createElement("missingclip");
842 e.setAttribute("type", TITLE_IMAGE_ELEMENT);
843 e.setAttribute("resource", img);
844 e.setAttribute("id", id);
845 e.setAttribute("name", baseClip);
846 m_missingClips.append(e);
848 else m_safeImages.append(img);
850 foreach(const QString &fontelement, fonts) {
851 if (m_safeFonts.contains(fontelement)) continue;
852 QFont f(fontelement);
853 //kDebug() << "/ / / CHK FONTS: " << fontelement << " = " << QFontInfo(f).family();
854 if (fontelement != QFontInfo(f).family()) {
855 QDomElement e = doc.createElement("missingclip");
856 e.setAttribute("type", TITLE_FONT_ELEMENT);
857 e.setAttribute("resource", fontelement);
858 e.setAttribute("id", id);
859 e.setAttribute("name", baseClip);
860 m_missingClips.append(e);
862 else m_safeFonts.append(fontelement);
867 void DocumentChecker::slotCheckButtons()
869 if (m_ui.treeWidget->currentItem()) {
870 QTreeWidgetItem *item = m_ui.treeWidget->currentItem();
871 int t = item->data(0, typeRole).toInt();
872 int s = item->data(0, statusRole).toInt();
873 if (t == TITLE_FONT_ELEMENT || t == TITLE_IMAGE_ELEMENT || s == PROXYMISSING) {
874 m_ui.removeSelected->setEnabled(false);
875 } else m_ui.removeSelected->setEnabled(true);
880 #include "documentchecker.moc"