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 QDomElement infoXml = m_doc.elementsByTagName("kdenlivedoc").at(0).toElement();
341 infoXml.setAttribute("modified", "1");
344 connect(m_ui.recursiveSearch, SIGNAL(pressed()), this, SLOT(slotSearchClips()));
345 connect(m_ui.usePlaceholders, SIGNAL(pressed()), this, SLOT(slotPlaceholders()));
346 connect(m_ui.removeSelected, SIGNAL(pressed()), this, SLOT(slotDeleteSelected()));
347 connect(m_ui.fixDuration, SIGNAL(pressed()), this, SLOT(slotFixDuration()));
348 connect(m_ui.treeWidget, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)), this, SLOT(slotEditItem(QTreeWidgetItem *, int)));
349 connect(m_ui.treeWidget, SIGNAL(itemSelectionChanged()), this, SLOT(slotCheckButtons()));
351 if (m_ui.treeWidget->topLevelItem(0)) m_ui.treeWidget->setCurrentItem(m_ui.treeWidget->topLevelItem(0));
353 int acceptMissing = m_dialog->exec();
354 if (acceptMissing == QDialog::Accepted) acceptDialog();
355 return (acceptMissing != QDialog::Accepted);
358 DocumentChecker::~DocumentChecker()
360 if (m_dialog) delete m_dialog;
364 QString DocumentChecker::getProperty(QDomElement effect, const QString &name)
366 QDomNodeList params = effect.elementsByTagName("property");
367 for (int i = 0; i < params.count(); i++) {
368 QDomElement e = params.item(i).toElement();
369 if (e.attribute("name") == name) {
370 return e.firstChild().nodeValue();
376 void DocumentChecker::setProperty(QDomElement effect, const QString &name, const QString value)
378 QDomNodeList params = effect.elementsByTagName("property");
379 for (int i = 0; i < params.count(); i++) {
380 QDomElement e = params.item(i).toElement();
381 if (e.attribute("name") == name) {
382 e.firstChild().setNodeValue(value);
387 void DocumentChecker::slotSearchClips()
389 QString newpath = KFileDialog::getExistingDirectory(KUrl("kfiledialog:///clipfolder"), kapp->activeWindow(), i18n("Clips folder"));
390 if (newpath.isEmpty()) return;
393 m_ui.recursiveSearch->setEnabled(false);
394 QTreeWidgetItem *child = m_ui.treeWidget->topLevelItem(ix);
395 QDir searchDir(newpath);
397 if (child->data(0, statusRole).toInt() == CLIPMISSING) {
398 QString clipPath = searchFileRecursively(searchDir, child->data(0, sizeRole).toString(), child->data(0, hashRole).toString());
399 if (!clipPath.isEmpty()) {
401 child->setText(1, clipPath);
402 child->setIcon(0, KIcon("dialog-ok"));
403 child->setData(0, statusRole, CLIPOK);
405 } else if (child->data(0, statusRole).toInt() == LUMAMISSING) {
406 QString fileName = searchLuma(child->data(0, idRole).toString());
407 if (!fileName.isEmpty()) {
409 child->setText(1, fileName);
410 child->setIcon(0, KIcon("dialog-ok"));
411 child->setData(0, statusRole, LUMAOK);
414 else if (child->data(0, typeRole).toInt() == TITLE_IMAGE_ELEMENT && child->data(0, statusRole).toInt() == CLIPPLACEHOLDER) {
415 // Search missing title images
416 QString missingFileName = KUrl(child->text(1)).fileName();
417 QString newPath = searchPathRecursively(searchDir, missingFileName);
418 if (!newPath.isEmpty()) {
421 child->setText(1, newPath);
422 child->setIcon(0, KIcon("dialog-ok"));
423 child->setData(0, statusRole, CLIPOK);
427 child = m_ui.treeWidget->topLevelItem(ix);
429 m_ui.recursiveSearch->setEnabled(true);
431 // original doc was modified
432 QDomElement infoXml = m_doc.elementsByTagName("kdenlivedoc").at(0).toElement();
433 infoXml.setAttribute("modified", "1");
439 QString DocumentChecker::searchLuma(QString file) const
441 KUrl searchPath(KdenliveSettings::mltpath());
442 if (file.contains("PAL"))
443 searchPath.cd("../lumas/PAL");
445 searchPath.cd("../lumas/NTSC");
446 QString result = searchPath.path(KUrl::AddTrailingSlash) + KUrl(file).fileName();
447 if (QFile::exists(result))
449 // try to find luma in application path
451 searchPath = KUrl(QCoreApplication::applicationDirPath());
452 searchPath.cd("../share/apps/kdenlive/lumas");
453 result = searchPath.path(KUrl::AddTrailingSlash) + KUrl(file).fileName();
454 if (QFile::exists(result))
459 QString DocumentChecker::searchPathRecursively(const QDir &dir, const QString &fileName) const
461 QString foundFileName;
465 searchDir.setNameFilters(filters);
466 QStringList filesAndDirs = searchDir.entryList(QDir::Files | QDir::Readable);
467 if (!filesAndDirs.isEmpty()) return searchDir.absoluteFilePath(filesAndDirs.at(0));
468 searchDir.setNameFilters(QStringList());
469 filesAndDirs = searchDir.entryList(QDir::Dirs | QDir::Readable | QDir::Executable | QDir::NoDotAndDotDot);
470 for (int i = 0; i < filesAndDirs.size() && foundFileName.isEmpty(); i++) {
471 foundFileName = searchPathRecursively(searchDir.absoluteFilePath(filesAndDirs.at(i)), fileName);
472 if (!foundFileName.isEmpty())
475 return foundFileName;
478 QString DocumentChecker::searchFileRecursively(const QDir &dir, const QString &matchSize, const QString &matchHash) const
480 QString foundFileName;
483 QStringList filesAndDirs = dir.entryList(QDir::Files | QDir::Readable);
484 for (int i = 0; i < filesAndDirs.size() && foundFileName.isEmpty(); i++) {
485 QFile file(dir.absoluteFilePath(filesAndDirs.at(i)));
486 if (QString::number(file.size()) == matchSize) {
487 if (file.open(QIODevice::ReadOnly)) {
489 * 1 MB = 1 second per 450 files (or faster)
490 * 10 MB = 9 seconds per 450 files (or faster)
492 if (file.size() > 1000000 * 2) {
493 fileData = file.read(1000000);
494 if (file.seek(file.size() - 1000000))
495 fileData.append(file.readAll());
497 fileData = file.readAll();
499 fileHash = QCryptographicHash::hash(fileData, QCryptographicHash::Md5);
500 if (QString(fileHash.toHex()) == matchHash)
501 return file.fileName();
504 //kDebug() << filesAndDirs.at(i) << file.size() << fileHash.toHex();
506 filesAndDirs = dir.entryList(QDir::Dirs | QDir::Readable | QDir::Executable | QDir::NoDotAndDotDot);
507 for (int i = 0; i < filesAndDirs.size() && foundFileName.isEmpty(); i++) {
508 foundFileName = searchFileRecursively(dir.absoluteFilePath(filesAndDirs.at(i)), matchSize, matchHash);
509 if (!foundFileName.isEmpty())
512 return foundFileName;
515 void DocumentChecker::slotEditItem(QTreeWidgetItem *item, int)
517 int t = item->data(0, typeRole).toInt();
518 if (t == TITLE_FONT_ELEMENT) return;
519 //|| t == TITLE_IMAGE_ELEMENT) {
521 KUrl url = KUrlRequesterDialog::getUrl(item->text(1), m_dialog, i18n("Enter new location for file"));
522 if (url.isEmpty()) return;
523 item->setText(1, url.path());
524 if (KIO::NetAccess::exists(url, KIO::NetAccess::SourceSide, 0)) {
525 item->setIcon(0, KIcon("dialog-ok"));
526 int id = item->data(0, statusRole).toInt();
527 if (id < 10) item->setData(0, statusRole, CLIPOK);
528 else item->setData(0, statusRole, LUMAOK);
531 item->setIcon(0, KIcon("dialog-close"));
532 int id = item->data(0, statusRole).toInt();
533 if (id < 10) item->setData(0, statusRole, CLIPMISSING);
534 else item->setData(0, statusRole, LUMAMISSING);
540 void DocumentChecker::acceptDialog()
542 QDomElement e, property;
543 QDomNodeList producers = m_doc.elementsByTagName("producer");
544 QDomNodeList infoproducers = m_doc.elementsByTagName("kdenlive_producer");
545 QDomNodeList properties;
548 // prepare transitions
549 QDomNodeList trans = m_doc.elementsByTagName("transition");
551 // Mark document as modified
552 m_doc.documentElement().setAttribute("modified", 1);
554 QTreeWidgetItem *child = m_ui.treeWidget->topLevelItem(ix);
556 int t = child->data(0, typeRole).toInt();
557 if (child->data(0, statusRole).toInt() == CLIPOK) {
558 QString id = child->data(0, idRole).toString();
559 if (t == TITLE_IMAGE_ELEMENT) {
560 // edit images embedded in titles
561 for (int i = 0; i < infoproducers.count(); i++) {
562 e = infoproducers.item(i).toElement();
563 if (e.attribute("id") == id) {
565 QString xml = e.attribute("xmldata");
566 xml.replace(child->data(0, typeOriginalResource).toString(), child->text(1));
567 e.setAttribute("xmldata", xml);
571 for (int i = 0; i < producers.count(); i++) {
572 e = producers.item(i).toElement();
573 if (e.attribute("id").section('_', 0, 0) == id) {
575 properties = e.childNodes();
576 for (int j = 0; j < properties.count(); ++j) {
577 property = properties.item(j).toElement();
578 if (property.attribute("name") == "xmldata") {
579 QString xml = property.firstChild().nodeValue();
580 xml.replace(child->data(0, typeOriginalResource).toString(), child->text(1));
581 property.firstChild().setNodeValue(xml);
589 for (int i = 0; i < infoproducers.count(); i++) {
590 e = infoproducers.item(i).toElement();
591 if (e.attribute("id") == id) {
593 e.setAttribute("resource", child->text(1));
594 e.setAttribute("name", KUrl(child->text(1)).fileName());
598 for (int i = 0; i < producers.count(); i++) {
599 e = producers.item(i).toElement();
600 if (e.attribute("id").section('_', 0, 0) == id || e.attribute("id").section(':', 1, 1) == id) {
602 properties = e.childNodes();
603 for (int j = 0; j < properties.count(); ++j) {
604 property = properties.item(j).toElement();
605 if (property.attribute("name") == "resource") {
606 QString resource = property.firstChild().nodeValue();
607 if (resource.contains(QRegExp("\\?[0-9]+\\.[0-9]+(&strobe=[0-9]+)?$")))
608 property.firstChild().setNodeValue(child->text(1) + '?' + resource.section('?', -1));
610 property.firstChild().setNodeValue(child->text(1));
617 } else if (child->data(0, statusRole).toInt() == CLIPPLACEHOLDER && t != TITLE_FONT_ELEMENT && t != TITLE_IMAGE_ELEMENT) {
618 QString id = child->data(0, idRole).toString();
619 for (int i = 0; i < infoproducers.count(); i++) {
620 e = infoproducers.item(i).toElement();
621 if (e.attribute("id") == id) {
623 e.setAttribute("placeholder", '1');
627 } else if (child->data(0, statusRole).toInt() == LUMAOK) {
628 for (int i = 0; i < trans.count(); i++) {
629 QString luma = getProperty(trans.at(i).toElement(), "luma");
631 kDebug() << "luma: " << luma;
632 if (!luma.isEmpty() && luma == child->data(0, idRole).toString()) {
633 setProperty(trans.at(i).toElement(), "luma", child->text(1));
634 kDebug() << "replace with; " << child->text(1);
637 } else if (child->data(0, statusRole).toInt() == LUMAMISSING) {
638 for (int i = 0; i < trans.count(); i++) {
639 QString luma = getProperty(trans.at(i).toElement(), "luma");
640 if (!luma.isEmpty() && luma == child->data(0, idRole).toString()) {
641 setProperty(trans.at(i).toElement(), "luma", QString());
646 child = m_ui.treeWidget->topLevelItem(ix);
651 void DocumentChecker::slotPlaceholders()
654 QTreeWidgetItem *child = m_ui.treeWidget->topLevelItem(ix);
656 if (child->data(0, statusRole).toInt() == CLIPMISSING) {
657 child->setData(0, statusRole, CLIPPLACEHOLDER);
658 child->setIcon(0, KIcon("dialog-ok"));
659 } else if (child->data(0, statusRole).toInt() == LUMAMISSING) {
660 child->setData(0, statusRole, LUMAPLACEHOLDER);
661 child->setIcon(0, KIcon("dialog-ok"));
664 child = m_ui.treeWidget->topLevelItem(ix);
669 void DocumentChecker::slotFixDuration()
672 QTreeWidgetItem *child = m_ui.treeWidget->topLevelItem(ix);
673 QDomNodeList documentProducers = m_doc.elementsByTagName("producer");
675 if (child->data(0, statusRole).toInt() == CLIPWRONGDURATION) {
676 QString id = child->data(0, idRole).toString();
677 bool resetDuration = child->data(0, resetDurationRole).toInt();
679 for (int i = 0; i < m_info.count(); i++) {
680 QDomElement e = m_info.at(i).toElement();
681 if (e.attribute("id") == id) {
682 if (m_missingClips.contains(e)) {
683 // we cannot fix duration of missing clips
684 resetDuration = false;
687 if (resetDuration) e.removeAttribute("duration");
688 else e.setAttribute("duration", child->data(0, sizeRole).toString());
689 child->setData(0, statusRole, CLIPOK);
690 child->setIcon(0, KIcon("dialog-ok"));
696 // something is wrong in clip durations, so remove them so mlt fetches them again
697 for (int j = 0; j < documentProducers.count(); j++) {
698 QDomElement mltProd = documentProducers.at(j).toElement();
699 QString prodId = mltProd.attribute("id");
700 if (prodId == id || prodId.startsWith(id + "_")) {
701 EffectsList::removeProperty(mltProd, "length");
707 child = m_ui.treeWidget->topLevelItem(ix);
709 QDomElement infoXml = m_doc.elementsByTagName("kdenlivedoc").at(0).toElement();
710 infoXml.setAttribute("modified", "1");
711 m_ui.fixDuration->setEnabled(false);
716 void DocumentChecker::checkStatus()
720 QTreeWidgetItem *child = m_ui.treeWidget->topLevelItem(ix);
722 int status = child->data(0, statusRole).toInt();
723 if (status == CLIPMISSING || status == LUMAMISSING || status == CLIPWRONGDURATION) {
728 child = m_ui.treeWidget->topLevelItem(ix);
730 m_ui.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(status);
734 void DocumentChecker::slotDeleteSelected()
736 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)
738 QStringList deletedIds;
739 QStringList deletedLumas;
740 QDomNodeList playlists = m_doc.elementsByTagName("playlist");
742 foreach(QTreeWidgetItem *child, m_ui.treeWidget->selectedItems()) {
743 int id = child->data(0, statusRole).toInt();
744 if (id == CLIPMISSING) {
745 deletedIds.append(child->data(0, idRole).toString());
748 else if (id == LUMAMISSING) {
749 deletedLumas.append(child->data(0, idRole).toString());
754 if (!deletedLumas.isEmpty()) {
756 QDomNodeList transitions = m_doc.elementsByTagName("transition");
757 foreach (QString lumaPath, deletedLumas) {
758 for (int i = 0; i < transitions.count(); i++) {
759 e = transitions.item(i).toElement();
760 QString resource = EffectsList::property(e, "luma");
761 if (resource == lumaPath) EffectsList::removeProperty(e, "luma");
766 if (!deletedIds.isEmpty()) {
768 QDomNodeList producers = m_doc.elementsByTagName("producer");
769 QDomNodeList infoproducers = m_doc.elementsByTagName("kdenlive_producer");
771 QDomNode mlt = m_doc.elementsByTagName("mlt").at(0);
772 QDomNode kdenlivedoc = m_doc.elementsByTagName("kdenlivedoc").at(0);
774 for (int i = 0, j = 0; i < infoproducers.count() && j < deletedIds.count(); i++) {
775 e = infoproducers.item(i).toElement();
776 if (deletedIds.contains(e.attribute("id"))) {
778 kdenlivedoc.removeChild(e);
784 for (int i = 0; i < producers.count(); i++) {
785 e = producers.item(i).toElement();
786 if (deletedIds.contains(e.attribute("id").section('_', 0, 0)) || deletedIds.contains(e.attribute("id").section(':', 1, 1).section('_', 0, 0))) {
793 for (int i = 0; i < playlists.count(); i++) {
794 QDomNodeList entries = playlists.at(i).toElement().elementsByTagName("entry");
795 for (int j = 0; j < entries.count(); j++) {
796 e = entries.item(j).toElement();
797 if (deletedIds.contains(e.attribute("producer").section('_', 0, 0)) || deletedIds.contains(e.attribute("producer").section(':', 1, 1).section('_', 0, 0))) {
798 // Replace clip with blank
799 while (e.childNodes().count() > 0)
800 e.removeChild(e.firstChild());
801 e.setTagName("blank");
802 e.removeAttribute("producer");
803 int length = e.attribute("out").toInt() - e.attribute("in").toInt();
804 e.setAttribute("length", length);
809 QDomElement infoXml = m_doc.elementsByTagName("kdenlivedoc").at(0).toElement();
810 infoXml.setAttribute("modified", "1");
815 void DocumentChecker::checkMissingImages(QStringList images, QStringList fonts, QString id, QString baseClip)
818 foreach(const QString &img, images) {
819 if (!KIO::NetAccess::exists(KUrl(img), KIO::NetAccess::SourceSide, 0)) {
820 QDomElement e = doc.createElement("missingclip");
821 e.setAttribute("type", TITLE_IMAGE_ELEMENT);
822 e.setAttribute("resource", img);
823 e.setAttribute("id", id);
824 e.setAttribute("name", baseClip);
825 m_missingClips.append(e);
828 kDebug() << "/ / / CHK FONTS: " << fonts;
829 foreach(const QString &fontelement, fonts) {
830 QFont f(fontelement);
831 kDebug() << "/ / / CHK FONTS: " << fontelement << " = " << QFontInfo(f).family();
832 if (fontelement != QFontInfo(f).family()) {
833 QDomElement e = doc.createElement("missingclip");
834 e.setAttribute("type", TITLE_FONT_ELEMENT);
835 e.setAttribute("resource", fontelement);
836 e.setAttribute("id", id);
837 e.setAttribute("name", baseClip);
838 m_missingClips.append(e);
844 void DocumentChecker::slotCheckButtons()
846 if (m_ui.treeWidget->currentItem()) {
847 QTreeWidgetItem *item = m_ui.treeWidget->currentItem();
848 int t = item->data(0, typeRole).toInt();
849 int s = item->data(0, statusRole).toInt();
850 if (t == TITLE_FONT_ELEMENT || t == TITLE_IMAGE_ELEMENT || s == PROXYMISSING) {
851 m_ui.removeSelected->setEnabled(false);
852 } else m_ui.removeSelected->setEnabled(true);
857 #include "documentchecker.moc"