X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fdocumentchecker.cpp;h=b58cfc7a4c82f8261d99de10d7a06dac1c412c2b;hb=a6aafb4cb3d09e17564f60bce207e7678b507a95;hp=96af5e687d751ab33915dcfea4366fa3109a3a4c;hpb=4711a4a809d3bde112e697686b8b50ab2f2c836b;p=kdenlive diff --git a/src/documentchecker.cpp b/src/documentchecker.cpp index 96af5e68..b58cfc7a 100644 --- a/src/documentchecker.cpp +++ b/src/documentchecker.cpp @@ -20,6 +20,8 @@ #include "documentchecker.h" #include "kthumb.h" +#include "docclipbase.h" +#include "titlewidget.h" #include "definitions.h" #include "kdenlivesettings.h" @@ -44,6 +46,8 @@ const int hashRole = Qt::UserRole; const int sizeRole = Qt::UserRole + 1; const int idRole = Qt::UserRole + 2; const int statusRole = Qt::UserRole + 3; +const int typeRole = Qt::UserRole + 4; +const int typeOriginalResource = Qt::UserRole + 5; const int CLIPMISSING = 0; const int CLIPOK = 1; @@ -52,33 +56,82 @@ const int LUMAMISSING = 10; const int LUMAOK = 11; const int LUMAPLACEHOLDER = 12; -DocumentChecker::DocumentChecker(QList missingClips, QDomDocument doc, QWidget * parent) : - QDialog(parent), - m_doc(doc) +enum TITLECLIPTYPE { TITLE_IMAGE_ELEMENT = 20, TITLE_FONT_ELEMENT = 21 }; + +DocumentChecker::DocumentChecker(QDomNodeList infoproducers, QDomDocument doc): + m_info(infoproducers), m_doc(doc), m_dialog(NULL) { - setFont(KGlobalSettings::toolBarFont()); - setupUi(this); + +} + + +bool DocumentChecker::hasMissingClips() +{ + int clipType; QDomElement e; + QString id; + QString resource; + QList missingClips; + for (int i = 0; i < m_info.count(); i++) { + e = m_info.item(i).toElement(); + clipType = e.attribute("type").toInt(); + if (clipType == COLOR) continue; + if (clipType == TEXT) { + //TODO: Check is clip template is missing (xmltemplate) or hash changed + QStringList images = TitleWidget::extractImageList(e.attribute("xmldata")); + QStringList fonts = TitleWidget::extractFontList(e.attribute("xmldata")); + checkMissingImages(missingClips, images, fonts, e.attribute("id"), e.attribute("name")); + continue; + } + id = e.attribute("id"); + resource = e.attribute("resource"); + if (clipType == SLIDESHOW) resource = KUrl(resource).directory(); + if (!KIO::NetAccess::exists(KUrl(resource), KIO::NetAccess::SourceSide, 0)) { + // Missing clip found + missingClips.append(e); + } else { + // Check if the clip has changed + if (clipType != SLIDESHOW && e.hasAttribute("file_hash")) { + if (e.attribute("file_hash") != DocClipBase::getHash(e.attribute("resource"))) + e.removeAttribute("file_hash"); + } + } + } + QStringList missingLumas; - QDomNodeList trans = doc.elementsByTagName("transition"); + QString root = m_doc.documentElement().attribute("root"); + if (!root.isEmpty()) root = KUrl(root).path(KUrl::AddTrailingSlash); + QDomNodeList trans = m_doc.elementsByTagName("transition"); for (int i = 0; i < trans.count(); i++) { QString luma = getProperty(trans.at(i).toElement(), "luma"); + if (!luma.startsWith('/')) luma.prepend(root); if (!luma.isEmpty() && !QFile::exists(luma)) { if (!missingLumas.contains(luma)) { missingLumas.append(luma); - QTreeWidgetItem *item = new QTreeWidgetItem(treeWidget, QStringList() << i18n("Luma file") << luma); - item->setIcon(0, KIcon("dialog-close")); - item->setData(0, idRole, luma); - item->setData(0, statusRole, LUMAMISSING); } } } - buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false); + if (missingClips.isEmpty() && missingLumas.isEmpty()) { + return false; + } + m_dialog = new QDialog(); + m_dialog->setFont(KGlobalSettings::toolBarFont()); + m_ui.setupUi(m_dialog); + + foreach(const QString l, missingLumas) { + QTreeWidgetItem *item = new QTreeWidgetItem(m_ui.treeWidget, QStringList() << i18n("Luma file") << l); + item->setIcon(0, KIcon("dialog-close")); + item->setData(0, idRole, l); + item->setData(0, statusRole, LUMAMISSING); + } + + m_ui.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false); for (int i = 0; i < missingClips.count(); i++) { e = missingClips.at(i).toElement(); QString clipType; - switch (e.attribute("type").toInt()) { + int t = e.attribute("type").toInt(); + switch (t) { case AV: clipType = i18n("Video clip"); break; @@ -97,24 +150,56 @@ DocumentChecker::DocumentChecker(QList missingClips, QDomDocument case SLIDESHOW: clipType = i18n("Slideshow clip"); break; + case TITLE_IMAGE_ELEMENT: + clipType = i18n("Title Image"); + break; + case TITLE_FONT_ELEMENT: + clipType = i18n("Title Font"); + break; default: clipType = i18n("Video clip"); } - QTreeWidgetItem *item = new QTreeWidgetItem(treeWidget, QStringList() << clipType << e.attribute("resource")); - item->setIcon(0, KIcon("dialog-close")); - item->setData(0, hashRole, e.attribute("file_hash")); - item->setData(0, sizeRole, e.attribute("file_size")); + QTreeWidgetItem *item = new QTreeWidgetItem(m_ui.treeWidget, QStringList() << clipType); + if (t == TITLE_IMAGE_ELEMENT) { + item->setIcon(0, KIcon("dialog-warning")); + item->setToolTip(1, e.attribute("name")); + item->setText(1, e.attribute("resource")); + item->setData(0, statusRole, CLIPPLACEHOLDER); + item->setData(0, typeOriginalResource, e.attribute("resource")); + } else if (t == TITLE_FONT_ELEMENT) { + item->setIcon(0, KIcon("dialog-warning")); + item->setToolTip(1, e.attribute("name")); + QString ft = e.attribute("resource"); + QString newft = QFontInfo(QFont(ft)).family(); + item->setText(1, i18n("%1 will be replaced by %2", ft, newft)); + item->setData(0, statusRole, CLIPPLACEHOLDER); + } else { + item->setIcon(0, KIcon("dialog-close")); + item->setText(1, e.attribute("resource")); + item->setData(0, hashRole, e.attribute("file_hash")); + item->setData(0, sizeRole, e.attribute("file_size")); + item->setData(0, statusRole, CLIPMISSING); + } + item->setData(0, typeRole, t); item->setData(0, idRole, e.attribute("id")); - item->setData(0, statusRole, CLIPMISSING); } - connect(recursiveSearch, SIGNAL(pressed()), this, SLOT(slotSearchClips())); - connect(usePlaceholders, SIGNAL(pressed()), this, SLOT(slotPlaceholders())); - connect(removeSelected, SIGNAL(pressed()), this, SLOT(slotDeleteSelected())); - connect(treeWidget, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)), this, SLOT(slotEditItem(QTreeWidgetItem *, int))); + connect(m_ui.recursiveSearch, SIGNAL(pressed()), this, SLOT(slotSearchClips())); + connect(m_ui.usePlaceholders, SIGNAL(pressed()), this, SLOT(slotPlaceholders())); + connect(m_ui.removeSelected, SIGNAL(pressed()), this, SLOT(slotDeleteSelected())); + connect(m_ui.treeWidget, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)), this, SLOT(slotEditItem(QTreeWidgetItem *, int))); + connect(m_ui.treeWidget, SIGNAL(itemSelectionChanged()), this, SLOT(slotCheckButtons())); //adjustSize(); + if (m_ui.treeWidget->topLevelItem(0)) m_ui.treeWidget->setCurrentItem(m_ui.treeWidget->topLevelItem(0)); + checkStatus(); + int acceptMissing = m_dialog->exec(); + if (acceptMissing == QDialog::Accepted) acceptDialog(); + return (acceptMissing != QDialog::Accepted); } -DocumentChecker::~DocumentChecker() {} +DocumentChecker::~DocumentChecker() +{ + if (m_dialog) delete m_dialog; +} QString DocumentChecker::getProperty(QDomElement effect, const QString &name) @@ -145,8 +230,8 @@ void DocumentChecker::slotSearchClips() QString newpath = KFileDialog::getExistingDirectory(KUrl("kfiledialog:///clipfolder"), kapp->activeWindow(), i18n("Clips folder")); if (newpath.isEmpty()) return; int ix = 0; - recursiveSearch->setEnabled(false); - QTreeWidgetItem *child = treeWidget->topLevelItem(ix); + m_ui.recursiveSearch->setEnabled(false); + QTreeWidgetItem *child = m_ui.treeWidget->topLevelItem(ix); while (child) { if (child->data(0, statusRole).toInt() == CLIPMISSING) { QString clipPath = searchFileRecursively(QDir(newpath), child->data(0, sizeRole).toString(), child->data(0, hashRole).toString()); @@ -164,9 +249,9 @@ void DocumentChecker::slotSearchClips() } } ix++; - child = treeWidget->topLevelItem(ix); + child = m_ui.treeWidget->topLevelItem(ix); } - recursiveSearch->setEnabled(true); + m_ui.recursiveSearch->setEnabled(true); checkStatus(); } @@ -224,7 +309,11 @@ QString DocumentChecker::searchFileRecursively(const QDir &dir, const QString &m void DocumentChecker::slotEditItem(QTreeWidgetItem *item, int) { - KUrl url = KUrlRequesterDialog::getUrl(item->text(1), this, i18n("Enter new location for file")); + int t = item->data(0, typeRole).toInt(); + if (t == TITLE_FONT_ELEMENT) return; + //|| t == TITLE_IMAGE_ELEMENT) { + + KUrl url = KUrlRequesterDialog::getUrl(item->text(1), m_dialog, i18n("Enter new location for file")); if (url.isEmpty()) return; item->setText(1, url.path()); if (KIO::NetAccess::exists(url, KIO::NetAccess::SourceSide, 0)) { @@ -233,11 +322,17 @@ void DocumentChecker::slotEditItem(QTreeWidgetItem *item, int) if (id < 10) item->setData(0, statusRole, CLIPOK); else item->setData(0, statusRole, LUMAOK); checkStatus(); + } else { + item->setIcon(0, KIcon("dialog-close")); + int id = item->data(0, statusRole).toInt(); + if (id < 10) item->setData(0, statusRole, CLIPMISSING); + else item->setData(0, statusRole, LUMAMISSING); + checkStatus(); } } -// virtual -void DocumentChecker::accept() + +void DocumentChecker::acceptDialog() { QDomElement e, property; QDomNodeList producers = m_doc.elementsByTagName("producer"); @@ -248,35 +343,66 @@ void DocumentChecker::accept() // prepare transitions QDomNodeList trans = m_doc.elementsByTagName("transition"); - QTreeWidgetItem *child = treeWidget->topLevelItem(ix); + QTreeWidgetItem *child = m_ui.treeWidget->topLevelItem(ix); while (child) { + int t = child->data(0, typeRole).toInt(); if (child->data(0, statusRole).toInt() == CLIPOK) { QString id = child->data(0, idRole).toString(); - for (int i = 0; i < infoproducers.count(); i++) { - e = infoproducers.item(i).toElement(); - if (e.attribute("id") == id) { - // Fix clip - e.setAttribute("resource", child->text(1)); - e.setAttribute("name", KUrl(child->text(1)).fileName()); - break; + if (t == TITLE_IMAGE_ELEMENT) { + // edit images embedded in titles + for (int i = 0; i < infoproducers.count(); i++) { + e = infoproducers.item(i).toElement(); + if (e.attribute("id") == id) { + // Fix clip + QString xml = e.attribute("xmldata"); + xml.replace(child->data(0, typeOriginalResource).toString(), child->text(1)); + e.setAttribute("xmldata", xml); + break; + } } - } - for (int i = 0; i < producers.count(); i++) { - e = producers.item(i).toElement(); - if (e.attribute("id").section('_', 0, 0) == id) { - // Fix clip - properties = e.childNodes(); - for (int j = 0; j < properties.count(); ++j) { - property = properties.item(j).toElement(); - if (property.attribute("name") == "resource") { - property.firstChild().setNodeValue(child->text(1)); - break; + for (int i = 0; i < producers.count(); i++) { + e = producers.item(i).toElement(); + if (e.attribute("id").section('_', 0, 0) == id) { + // Fix clip + properties = e.childNodes(); + for (int j = 0; j < properties.count(); ++j) { + property = properties.item(j).toElement(); + if (property.attribute("name") == "xmldata") { + QString xml = property.firstChild().nodeValue(); + xml.replace(child->data(0, typeOriginalResource).toString(), child->text(1)); + property.firstChild().setNodeValue(xml); + break; + } + } + } + } + } else { + // edit clip url + for (int i = 0; i < infoproducers.count(); i++) { + e = infoproducers.item(i).toElement(); + if (e.attribute("id") == id) { + // Fix clip + e.setAttribute("resource", child->text(1)); + e.setAttribute("name", KUrl(child->text(1)).fileName()); + break; + } + } + for (int i = 0; i < producers.count(); i++) { + e = producers.item(i).toElement(); + if (e.attribute("id").section('_', 0, 0) == id) { + // Fix clip + properties = e.childNodes(); + for (int j = 0; j < properties.count(); ++j) { + property = properties.item(j).toElement(); + if (property.attribute("name") == "resource") { + property.firstChild().setNodeValue(child->text(1)); + break; + } } } - break; } } - } else if (child->data(0, statusRole).toInt() == CLIPPLACEHOLDER) { + } else if (child->data(0, statusRole).toInt() == CLIPPLACEHOLDER && t != TITLE_FONT_ELEMENT && t != TITLE_IMAGE_ELEMENT) { QString id = child->data(0, idRole).toString(); for (int i = 0; i < infoproducers.count(); i++) { e = infoproducers.item(i).toElement(); @@ -304,15 +430,15 @@ void DocumentChecker::accept() } } ix++; - child = treeWidget->topLevelItem(ix); + child = m_ui.treeWidget->topLevelItem(ix); } - QDialog::accept(); + //QDialog::accept(); } void DocumentChecker::slotPlaceholders() { int ix = 0; - QTreeWidgetItem *child = treeWidget->topLevelItem(ix); + QTreeWidgetItem *child = m_ui.treeWidget->topLevelItem(ix); while (child) { if (child->data(0, statusRole).toInt() == CLIPMISSING) { child->setData(0, statusRole, CLIPPLACEHOLDER); @@ -322,7 +448,7 @@ void DocumentChecker::slotPlaceholders() child->setIcon(0, KIcon("dialog-ok")); } ix++; - child = treeWidget->topLevelItem(ix); + child = m_ui.treeWidget->topLevelItem(ix); } checkStatus(); } @@ -332,25 +458,25 @@ void DocumentChecker::checkStatus() { bool status = true; int ix = 0; - QTreeWidgetItem *child = treeWidget->topLevelItem(ix); + QTreeWidgetItem *child = m_ui.treeWidget->topLevelItem(ix); while (child) { if (child->data(0, statusRole).toInt() == CLIPMISSING || child->data(0, statusRole).toInt() == LUMAMISSING) { status = false; break; } ix++; - child = treeWidget->topLevelItem(ix); + child = m_ui.treeWidget->topLevelItem(ix); } - buttonBox->button(QDialogButtonBox::Ok)->setEnabled(status); + m_ui.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(status); } void DocumentChecker::slotDeleteSelected() { - if (KMessageBox::warningContinueCancel(this, i18np("This will remove the selected clip from this project", "This will remove the selected clips from this project", treeWidget->selectedItems().count()), i18n("Remove clips")) == KMessageBox::Cancel) return; + 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) return; int ix = 0; QStringList deletedIds; - QTreeWidgetItem *child = treeWidget->topLevelItem(ix); + QTreeWidgetItem *child = m_ui.treeWidget->topLevelItem(ix); QDomNodeList playlists = m_doc.elementsByTagName("playlist"); while (child) { @@ -362,7 +488,7 @@ void DocumentChecker::slotDeleteSelected() deletedIds.append(id + '_' + QString::number(j)); delete child; } else ix++; - child = treeWidget->topLevelItem(ix); + child = m_ui.treeWidget->topLevelItem(ix); } kDebug() << "// Clips to delete: " << deletedIds; @@ -409,6 +535,47 @@ void DocumentChecker::slotDeleteSelected() } } +void DocumentChecker::checkMissingImages(QList &missingClips, QStringList images, QStringList fonts, QString id, QString baseClip) +{ + QDomDocument doc; + foreach(const QString &img, images) { + if (!KIO::NetAccess::exists(KUrl(img), KIO::NetAccess::SourceSide, 0)) { + QDomElement e = doc.createElement("missingclip"); + e.setAttribute("type", TITLE_IMAGE_ELEMENT); + e.setAttribute("resource", img); + e.setAttribute("id", id); + e.setAttribute("name", baseClip); + missingClips.append(e); + } + } + kDebug() << "/ / / CHK FONTS: " << fonts; + foreach(const QString &fontelement, fonts) { + QFont f(fontelement); + kDebug() << "/ / / CHK FONTS: " << fontelement << " = " << QFontInfo(f).family(); + if (fontelement != QFontInfo(f).family()) { + QDomElement e = doc.createElement("missingclip"); + e.setAttribute("type", TITLE_FONT_ELEMENT); + e.setAttribute("resource", fontelement); + e.setAttribute("id", id); + e.setAttribute("name", baseClip); + missingClips.append(e); + } + } +} + + +void DocumentChecker::slotCheckButtons() +{ + if (m_ui.treeWidget->currentItem()) { + QTreeWidgetItem *item = m_ui.treeWidget->currentItem(); + int t = item->data(0, typeRole).toInt(); + if (t == TITLE_FONT_ELEMENT || t == TITLE_IMAGE_ELEMENT) { + m_ui.removeSelected->setEnabled(false); + } else m_ui.removeSelected->setEnabled(true); + } + +} + #include "documentchecker.moc"