#include "documentchecker.h"
#include "kthumb.h"
#include "docclipbase.h"
-#include "titlewidget.h"
+#include "widgets/titlewidget.h"
#include "definitions.h"
#include "kdenlivesettings.h"
#include <KApplication>
#include <KUrlRequesterDialog>
#include <KMessageBox>
+#include <KStandardDirs>
#include <QTreeWidgetItem>
#include <QFile>
const int statusRole = Qt::UserRole + 3;
const int typeRole = Qt::UserRole + 4;
const int typeOriginalResource = Qt::UserRole + 5;
+const int resetDurationRole = Qt::UserRole + 6;
const int CLIPMISSING = 0;
const int CLIPOK = 1;
const int CLIPPLACEHOLDER = 2;
const int CLIPWRONGDURATION = 3;
const int PROXYMISSING = 4;
+const int SOURCEMISSING = 5;
const int LUMAMISSING = 10;
const int LUMAOK = 11;
enum TITLECLIPTYPE { TITLE_IMAGE_ELEMENT = 20, TITLE_FONT_ELEMENT = 21 };
-DocumentChecker::DocumentChecker(QDomNodeList infoproducers, QDomDocument doc):
+DocumentChecker::DocumentChecker(const QDomNodeList &infoproducers, const QDomDocument &doc):
m_info(infoproducers), m_doc(doc), m_dialog(NULL)
{
int clipType;
QDomElement e;
QString resource;
+ int max;
QDomNodeList documentProducers = m_doc.elementsByTagName("producer");
QList <QDomElement> wrongDurationClips;
- QList <QDomElement> missingClips;
+ // List clips whose proxy is missing
QList <QDomElement> missingProxies;
- for (int i = 0; i < m_info.count(); i++) {
+ // List clips who have a working proxy but no source clip
+ QList <QDomElement> missingSources;
+ m_safeImages.clear();
+ m_safeFonts.clear();
+ max = m_info.count();
+ for (int i = 0; i < max; ++i) {
e = m_info.item(i).toElement();
clipType = e.attribute("type").toInt();
- if (clipType == COLOR) continue;
- if (clipType != TEXT && clipType != IMAGE) {
+ if (clipType == Color) continue;
+ if (clipType != Text && clipType != Image && clipType != SlideShow) {
QString id = e.attribute("id");
int duration = e.attribute("duration").toInt();
+ int mltDuration = -1;
+ QDomElement mltProd;
+ QString prodId;
// Check that the duration is in sync between Kdenlive's info and MLT's playlist
- for (int j = 0; j < documentProducers.count(); j++) {
- QDomElement mltProd = documentProducers.at(j).toElement();
- QString prodId = mltProd.attribute("id");
+ int prodsCount = documentProducers.count();
+ for (int j = 0; j < prodsCount; j++) {
+ mltProd = documentProducers.at(j).toElement();
+ prodId = mltProd.attribute("id");
// Don't check slowmotion clips for now... (TODO?)
if (prodId.startsWith("slowmotion")) continue;
- if (prodId.contains("_")) prodId = prodId.section("_", 0, 0);
+ if (prodId.contains('_')) prodId = prodId.section('_', 0, 0);
if (prodId != id) continue;
- int mltDuration = mltProd.attribute("out").toInt() + 1;
- if (mltDuration != duration && !e.hasAttribute("_mismatch")) {
+ if (mltDuration > 0 ) {
+ // We have several MLT producers for the same clip (probably track producers)
+ int newLength = EffectsList::property(mltProd, "length").toInt();
+ if (newLength != mltDuration) {
+ // we have a different duration for the same clip, that is not safe
+ e.setAttribute("_resetDuration", 1);
+ }
+ }
+ mltDuration = EffectsList::property(mltProd, "length").toInt();
+ if (mltDuration != duration) {
// Duration mismatch
e.setAttribute("_mismatch", mltDuration);
+ if (mltDuration == 15000) {
+ // a length of 15000 might indicate a wrong clip length since it is a default length
+ e.setAttribute("_resetDuration", 1);
+ }
if (!wrongDurationClips.contains(e)) wrongDurationClips.append(e);
- kDebug() << "WRONG DURTAION: "<<id<<", TYPE: "<<clipType;
}
}
}
- if (clipType == TEXT) {
+ 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"));
+ checkMissingImagesAndFonts(images, fonts, e.attribute("id"), e.attribute("name"));
continue;
}
resource = e.attribute("resource");
if (e.hasAttribute("proxy")) {
QString proxyresource = e.attribute("proxy");
- if (!KIO::NetAccess::exists(KUrl(proxyresource), KIO::NetAccess::SourceSide, 0)) {
- // Missing clip found
- missingProxies.append(e);
+ if (!proxyresource.isEmpty() && proxyresource != "-") {
+ // clip has a proxy
+ if (!KIO::NetAccess::exists(KUrl(proxyresource), KIO::NetAccess::SourceSide, 0)) {
+ // Missing clip found
+ missingProxies.append(e);
+ }
+ else if (!KIO::NetAccess::exists(KUrl(resource), KIO::NetAccess::SourceSide, 0)) {
+ // clip has proxy but original clip is missing
+ missingSources.append(e);
+ continue;
+ }
}
}
- if (clipType == SLIDESHOW) resource = KUrl(resource).directory();
+ if (clipType == SlideShow) resource = KUrl(resource).directory();
if (!KIO::NetAccess::exists(KUrl(resource), KIO::NetAccess::SourceSide, 0)) {
// Missing clip found
- missingClips.append(e);
+ m_missingClips.append(e);
} else {
// Check if the clip has changed
- if (clipType != SLIDESHOW && e.hasAttribute("file_hash")) {
+ if (clipType != SlideShow && e.hasAttribute("file_hash")) {
if (e.attribute("file_hash") != DocClipBase::getHash(e.attribute("resource")))
e.removeAttribute("file_hash");
}
}
}
+ // Get list of used Luma files
QStringList missingLumas;
+ QStringList filesToCheck;
+ QString filePath;
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++) {
+ max = trans.count();
+ for (int i = 0; i < max; ++i) {
QString luma = getProperty(trans.at(i).toElement(), "luma");
- if (!luma.isEmpty()) {
- if (!luma.startsWith('/')) luma.prepend(root);
- if (!QFile::exists(luma) && !missingLumas.contains(luma)) {
- missingLumas.append(luma);
- }
+ if (!luma.isEmpty() && !filesToCheck.contains(luma))
+ filesToCheck.append(luma);
+ }
+ // Check existence of luma files
+ foreach (const QString &lumafile, filesToCheck) {
+ filePath = lumafile;
+ if (!filePath.startsWith('/')) filePath.prepend(root);
+ if (!QFile::exists(filePath)) {
+ missingLumas.append(lumafile);
}
}
+
+
- if (missingClips.isEmpty() && missingLumas.isEmpty() && wrongDurationClips.isEmpty() && missingProxies.isEmpty())
+ if (m_missingClips.isEmpty() && missingLumas.isEmpty() && wrongDurationClips.isEmpty() && missingProxies.isEmpty() && missingSources.isEmpty())
return false;
m_dialog = new QDialog();
m_dialog->setFont(KGlobalSettings::toolBarFont());
m_ui.setupUi(m_dialog);
- foreach(const QString l, missingLumas) {
+ 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);
}
m_ui.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
- for (int i = 0; i < missingClips.count(); i++) {
- e = missingClips.at(i).toElement();
+ max = m_missingClips.count();
+ for (int i = 0; i < max; ++i) {
+ e = m_missingClips.at(i).toElement();
QString clipType;
int t = e.attribute("type").toInt();
switch (t) {
case AV:
clipType = i18n("Video clip");
break;
- case VIDEO:
+ case Video:
clipType = i18n("Mute video clip");
break;
- case AUDIO:
+ case Audio:
clipType = i18n("Audio clip");
break;
- case PLAYLIST:
+ case Playlist:
clipType = i18n("Playlist clip");
break;
- case IMAGE:
+ case Image:
clipType = i18n("Image clip");
break;
- case SLIDESHOW:
+ case SlideShow:
clipType = i18n("Slideshow clip");
break;
case TITLE_IMAGE_ELEMENT:
item->setToolTip(0, i18n("Missing item"));
}
- if (missingClips.count() > 0) {
+ if (m_missingClips.count() > 0) {
if (wrongDurationClips.count() > 0) {
m_ui.infoLabel->setText(i18n("The project file contains missing clips or files and clip duration mismatch"));
}
if (!m_ui.infoLabel->text().isEmpty()) m_ui.infoLabel->setText(m_ui.infoLabel->text() + ". ");
m_ui.infoLabel->setText(m_ui.infoLabel->text() + i18n("Missing proxies will be recreated after opening."));
}
+ if (missingSources.count() > 0) {
+ if (!m_ui.infoLabel->text().isEmpty()) m_ui.infoLabel->setText(m_ui.infoLabel->text() + ". ");
+ m_ui.infoLabel->setText(m_ui.infoLabel->text() + i18np("The project file contains a missing clip, you can still work with its proxy.", "The project file contains missing clips, you can still work with their proxies.", missingSources.count()));
+ }
- m_ui.removeSelected->setEnabled(!missingClips.isEmpty());
- m_ui.recursiveSearch->setEnabled(!missingClips.isEmpty());
- m_ui.usePlaceholders->setEnabled(!missingClips.isEmpty());
+ m_ui.removeSelected->setEnabled(!m_missingClips.isEmpty());
+ m_ui.recursiveSearch->setEnabled(!m_missingClips.isEmpty() || !missingLumas.isEmpty() || !missingSources.isEmpty());
+ m_ui.usePlaceholders->setEnabled(!m_missingClips.isEmpty());
m_ui.fixDuration->setEnabled(!wrongDurationClips.isEmpty());
-
- for (int i = 0; i < wrongDurationClips.count(); i++) {
+
+ max = wrongDurationClips.count();
+ for (int i = 0; i < max; ++i) {
e = wrongDurationClips.at(i).toElement();
QString clipType;
int t = e.attribute("type").toInt();
case AV:
clipType = i18n("Video clip");
break;
- case VIDEO:
+ case Video:
clipType = i18n("Mute video clip");
break;
- case AUDIO:
+ case Audio:
clipType = i18n("Audio clip");
break;
- case PLAYLIST:
+ case Playlist:
clipType = i18n("Playlist clip");
break;
- case IMAGE:
+ case Image:
clipType = i18n("Image clip");
break;
- case SLIDESHOW:
+ case SlideShow:
clipType = i18n("Slideshow clip");
break;
default:
item->setData(0, hashRole, e.attribute("file_hash"));
item->setData(0, sizeRole, e.attribute("_mismatch"));
e.removeAttribute("_mismatch");
+ item->setData(0, resetDurationRole, (int) e.hasAttribute("_resetDuration"));
+ e.removeAttribute("_resetDuration");
item->setData(0, statusRole, CLIPWRONGDURATION);
item->setData(0, typeRole, t);
item->setData(0, idRole, e.attribute("id"));
item->setToolTip(0, i18n("Duration mismatch"));
}
-
- for (int i = 0; i < missingProxies.count(); i++) {
- e = missingProxies.at(i).toElement();
- QString clipType;
- int t = e.attribute("type").toInt();
+ // Check missing proxies
+ max = missingProxies.count();
+ if (max > 0) {
QTreeWidgetItem *item = new QTreeWidgetItem(m_ui.treeWidget, QStringList() << i18n("Proxy clip"));
- item->setIcon(0, KIcon("dialog-close"));
- item->setText(1, e.attribute("proxy"));
+ item->setIcon(0, KIcon("dialog-warning"));
+ item->setText(1, i18n("%1 missing proxy clips, will be recreated on project opening", max));
item->setData(0, hashRole, e.attribute("file_hash"));
item->setData(0, statusRole, PROXYMISSING);
- item->setData(0, typeRole, t);
- item->setData(0, idRole, e.attribute("id"));
item->setToolTip(0, i18n("Missing proxy"));
}
+
+ for (int i = 0; i < max; ++i) {
+ e = missingProxies.at(i).toElement();
+ QString realPath = e.attribute("resource");
+ QString id = e.attribute("id");
+ // Tell Kdenlive to recreate proxy
+ e.setAttribute("_replaceproxy", "1");
+ // Replace proxy url with real clip in MLT producers
+ QDomNodeList properties;
+ QDomElement mltProd;
+ QDomElement property;
+ int prodsCount = documentProducers.count();
+ for (int j = 0; j < prodsCount; j++) {
+ mltProd = documentProducers.at(j).toElement();
+ QString prodId = mltProd.attribute("id");
+ bool slowmotion = false;
+ if (prodId.startsWith("slowmotion")) {
+ slowmotion = true;
+ prodId = prodId.section(':', 1, 1);
+ }
+ if (prodId.contains('_')) prodId = prodId.section('_', 0, 0);
+ if (prodId == id) {
+ // Hit, we must replace url
+ properties = mltProd.childNodes();
+ for (int k = 0; k < properties.count(); ++k) {
+ property = properties.item(k).toElement();
+ if (property.attribute("name") == "resource") {
+ QString resource = property.firstChild().nodeValue();
+ QString suffix;
+ if (slowmotion) suffix = '?' + resource.section('?', -1);
+ property.firstChild().setNodeValue(realPath + suffix);
+ break;
+ }
+ }
+ }
+ }
+ }
+
+ if (max > 0) {
+ // original doc was modified
+ QDomElement infoXml = m_doc.elementsByTagName("kdenlivedoc").at(0).toElement();
+ infoXml.setAttribute("modified", "1");
+ }
+
+ // Check clips with available proxies but missing original source clips
+ max = missingSources.count();
+ if (max > 0) {
+ QTreeWidgetItem *item = new QTreeWidgetItem(m_ui.treeWidget, QStringList() << i18n("Source clip"));
+ item->setIcon(0, KIcon("dialog-warning"));
+ item->setText(1, i18n("%1 missing source clips, you can only use the proxies", max));
+ item->setData(0, hashRole, e.attribute("file_hash"));
+ item->setData(0, statusRole, SOURCEMISSING);
+ item->setToolTip(0, i18n("Missing source clip"));
+ for (int i = 0; i < max; ++i) {
+ e = missingSources.at(i).toElement();
+ QString clipType;
+ QString realPath = e.attribute("resource");
+ QString id = e.attribute("id");
+ // Tell Kdenlive the source is missing
+ e.setAttribute("_missingsource", "1");
+ QTreeWidgetItem *subitem = new QTreeWidgetItem(item, QStringList() << i18n("Source clip"));
+ kDebug()<<"// Adding missing source clip: "<<realPath;
+ subitem->setIcon(0, KIcon("dialog-close"));
+ subitem->setText(1, realPath);
+ subitem->setData(0, hashRole, e.attribute("file_hash"));
+ subitem->setData(0, sizeRole, e.attribute("file_size"));
+ subitem->setData(0, statusRole, CLIPMISSING);
+ int t = e.attribute("type").toInt();
+ subitem->setData(0, typeRole, t);
+ subitem->setData(0, idRole, id);
+ }
+ }
+
+ if (max > 0) {
+ // original doc was modified
+ QDomElement infoXml = m_doc.elementsByTagName("kdenlivedoc").at(0).toElement();
+ infoXml.setAttribute("modified", "1");
+ }
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.fixDuration, SIGNAL(pressed()), this, SLOT(slotFixDuration()));
- connect(m_ui.treeWidget, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)), this, SLOT(slotEditItem(QTreeWidgetItem *, int)));
+ 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));
DocumentChecker::~DocumentChecker()
{
- if (m_dialog) delete m_dialog;
+ delete m_dialog;
}
QString DocumentChecker::getProperty(QDomElement effect, const QString &name)
{
QDomNodeList params = effect.elementsByTagName("property");
- for (int i = 0; i < params.count(); i++) {
+ for (int i = 0; i < params.count(); ++i) {
QDomElement e = params.item(i).toElement();
if (e.attribute("name") == name) {
return e.firstChild().nodeValue();
return QString();
}
-void DocumentChecker::setProperty(QDomElement effect, const QString &name, const QString value)
+void DocumentChecker::setProperty(QDomElement effect, const QString &name, const QString &value)
{
QDomNodeList params = effect.elementsByTagName("property");
- for (int i = 0; i < params.count(); i++) {
+ for (int i = 0; i < params.count(); ++i) {
QDomElement e = params.item(i).toElement();
if (e.attribute("name") == name) {
e.firstChild().setNodeValue(value);
if (newpath.isEmpty()) return;
int ix = 0;
bool fixed = false;
- m_ui.recursiveSearch->setEnabled(false);
+ m_ui.recursiveSearch->setChecked(true);
+ qApp->processEvents();
QTreeWidgetItem *child = m_ui.treeWidget->topLevelItem(ix);
+ QDir searchDir(newpath);
while (child) {
- if (child->data(0, statusRole).toInt() == CLIPMISSING) {
- QString clipPath = searchFileRecursively(QDir(newpath), child->data(0, sizeRole).toString(), child->data(0, hashRole).toString());
+ if (child->data(0, statusRole).toInt() == SOURCEMISSING) {
+ for (int j = 0; j < child->childCount(); j++) {
+ QTreeWidgetItem *subchild = child->child(j);
+ QString clipPath = searchFileRecursively(searchDir, subchild->data(0, sizeRole).toString(), subchild->data(0, hashRole).toString());
+ if (!clipPath.isEmpty()) {
+ fixed = true;
+
+ subchild->setText(1, clipPath);
+ subchild->setIcon(0, KIcon("dialog-ok"));
+ subchild->setData(0, statusRole, CLIPOK);
+ }
+ }
+ }
+ else if (child->data(0, statusRole).toInt() == CLIPMISSING) {
+ QString clipPath = searchFileRecursively(searchDir, child->data(0, sizeRole).toString(), child->data(0, hashRole).toString());
if (!clipPath.isEmpty()) {
fixed = true;
child->setText(1, clipPath);
child->setData(0, statusRole, CLIPOK);
}
} else if (child->data(0, statusRole).toInt() == LUMAMISSING) {
- QString fileName = searchLuma(child->data(0, idRole).toString());
+ QString fileName = searchLuma(searchDir, child->data(0, idRole).toString());
if (!fileName.isEmpty()) {
fixed = true;
child->setText(1, fileName);
child->setData(0, statusRole, LUMAOK);
}
}
+ else if (child->data(0, typeRole).toInt() == TITLE_IMAGE_ELEMENT && child->data(0, statusRole).toInt() == CLIPPLACEHOLDER) {
+ // Search missing title images
+ QString missingFileName = KUrl(child->text(1)).fileName();
+ QString newPath = searchPathRecursively(searchDir, missingFileName);
+ if (!newPath.isEmpty()) {
+ // File found
+ fixed = true;
+ child->setText(1, newPath);
+ child->setIcon(0, KIcon("dialog-ok"));
+ child->setData(0, statusRole, CLIPOK);
+ }
+ }
ix++;
child = m_ui.treeWidget->topLevelItem(ix);
}
+ m_ui.recursiveSearch->setChecked(false);
m_ui.recursiveSearch->setEnabled(true);
if (fixed) {
// original doc was modified
- QDomNode infoXmlNode = m_doc.elementsByTagName("kdenlivedoc").at(0);
- QDomElement infoXml = infoXmlNode.toElement();
+ QDomElement infoXml = m_doc.elementsByTagName("kdenlivedoc").at(0).toElement();
infoXml.setAttribute("modified", "1");
}
checkStatus();
}
-QString DocumentChecker::searchLuma(QString file) const
+QString DocumentChecker::searchLuma(const QDir &dir, const QString &file) const
{
KUrl searchPath(KdenliveSettings::mltpath());
+ QString fname = KUrl(file).fileName();
if (file.contains("PAL"))
searchPath.cd("../lumas/PAL");
else
searchPath.cd("../lumas/NTSC");
- QString result = searchPath.path(KUrl::AddTrailingSlash) + KUrl(file).fileName();
+ QString result = searchPath.path(KUrl::AddTrailingSlash) + fname;
if (QFile::exists(result))
return result;
- return QString();
+ // try to find luma in application path
+ searchPath.clear();
+ searchPath = KUrl(QCoreApplication::applicationDirPath());
+ searchPath.cd("../share/apps/kdenlive/lumas");
+ result = searchPath.path(KUrl::AddTrailingSlash) + fname;
+ if (QFile::exists(result))
+ return result;
+ // Try in Kdenlive's standard KDE path
+ result = KStandardDirs::locate("appdata", "lumas/" + fname);
+ if (!result.isEmpty()) return result;
+ // Try in user's chosen folder
+ return searchPathRecursively(dir, fname);
}
+QString DocumentChecker::searchPathRecursively(const QDir &dir, const QString &fileName) const
+{
+ QString foundFileName;
+ QStringList filters;
+ filters << fileName;
+ QDir searchDir(dir);
+ searchDir.setNameFilters(filters);
+ QStringList filesAndDirs = searchDir.entryList(QDir::Files | QDir::Readable);
+ if (!filesAndDirs.isEmpty()) return searchDir.absoluteFilePath(filesAndDirs.at(0));
+ searchDir.setNameFilters(QStringList());
+ filesAndDirs = searchDir.entryList(QDir::Dirs | QDir::Readable | QDir::Executable | QDir::NoDotAndDotDot);
+ for (int i = 0; i < filesAndDirs.size() && foundFileName.isEmpty(); ++i) {
+ foundFileName = searchPathRecursively(searchDir.absoluteFilePath(filesAndDirs.at(i)), fileName);
+ if (!foundFileName.isEmpty())
+ break;
+ }
+ return foundFileName;
+}
QString DocumentChecker::searchFileRecursively(const QDir &dir, const QString &matchSize, const QString &matchHash) const
{
QByteArray fileData;
QByteArray fileHash;
QStringList filesAndDirs = dir.entryList(QDir::Files | QDir::Readable);
- for (int i = 0; i < filesAndDirs.size() && foundFileName.isEmpty(); i++) {
+ for (int i = 0; i < filesAndDirs.size() && foundFileName.isEmpty(); ++i) {
QFile file(dir.absoluteFilePath(filesAndDirs.at(i)));
if (QString::number(file.size()) == matchSize) {
if (file.open(QIODevice::ReadOnly)) {
//kDebug() << filesAndDirs.at(i) << file.size() << fileHash.toHex();
}
filesAndDirs = dir.entryList(QDir::Dirs | QDir::Readable | QDir::Executable | QDir::NoDotAndDotDot);
- for (int i = 0; i < filesAndDirs.size() && foundFileName.isEmpty(); i++) {
+ for (int i = 0; i < filesAndDirs.size() && foundFileName.isEmpty(); ++i) {
foundFileName = searchFileRecursively(dir.absoluteFilePath(filesAndDirs.at(i)), matchSize, matchHash);
if (!foundFileName.isEmpty())
break;
void DocumentChecker::slotEditItem(QTreeWidgetItem *item, int)
{
int t = item->data(0, typeRole).toInt();
- if (t == TITLE_FONT_ELEMENT) return;
+ if (t == TITLE_FONT_ELEMENT || t == Unknown) return;
//|| t == TITLE_IMAGE_ELEMENT) {
KUrl url = KUrlRequesterDialog::getUrl(item->text(1), m_dialog, i18n("Enter new location for file"));
void DocumentChecker::acceptDialog()
{
- QDomElement e, property;
QDomNodeList producers = m_doc.elementsByTagName("producer");
QDomNodeList infoproducers = m_doc.elementsByTagName("kdenlive_producer");
- QDomNodeList properties;
int ix = 0;
// prepare transitions
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();
- 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") == "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;
- }
+ if (child->data(0, statusRole).toInt() == SOURCEMISSING) {
+ for (int j = 0; j < child->childCount(); j++) {
+ fixClipItem(child->child(j), producers, infoproducers, trans);
+ }
+ }
+ else fixClipItem(child, producers, infoproducers, trans);
+ ix++;
+ child = m_ui.treeWidget->topLevelItem(ix);
+ }
+ //QDialog::accept();
+}
+
+void DocumentChecker::fixClipItem(QTreeWidgetItem *child, QDomNodeList producers, QDomNodeList infoproducers, QDomNodeList trans)
+{
+ QDomElement e, property;
+ QDomNodeList properties;
+ int t = child->data(0, typeRole).toInt();
+ if (child->data(0, statusRole).toInt() == CLIPOK) {
+ QString id = child->data(0, idRole).toString();
+ 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 || e.attribute("id").section(':', 1, 1) == id) {
- // Fix clip
- properties = e.childNodes();
- for (int j = 0; j < properties.count(); ++j) {
- property = properties.item(j).toElement();
- if (property.attribute("name") == "resource") {
- QString resource = property.firstChild().nodeValue();
- if (resource.contains(QRegExp("\\?[0-9]+\\.[0-9]+(&strobe=[0-9]+)?$")))
- property.firstChild().setNodeValue(child->text(1) + '?' + resource.section('?', -1));
- else
- 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 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++) {
+ } 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("placeholder", '1');
+ e.setAttribute("resource", child->text(1));
+ e.setAttribute("name", KUrl(child->text(1)).fileName());
+ e.removeAttribute("_missingsource");
break;
}
}
- } else if (child->data(0, statusRole).toInt() == LUMAOK) {
- for (int i = 0; i < trans.count(); i++) {
- QString luma = getProperty(trans.at(i).toElement(), "luma");
- kDebug() << "luma: " << luma;
- if (!luma.isEmpty() && luma == child->data(0, idRole).toString()) {
- setProperty(trans.at(i).toElement(), "luma", child->text(1));
- kDebug() << "replace with; " << child->text(1);
+ for (int i = 0; i < producers.count(); ++i) {
+ e = producers.item(i).toElement();
+ if (e.attribute("id").section('_', 0, 0) == id || e.attribute("id").section(':', 1, 1) == id) {
+ // Fix clip
+ properties = e.childNodes();
+ for (int j = 0; j < properties.count(); ++j) {
+ property = properties.item(j).toElement();
+ if (property.attribute("name") == "resource") {
+ QString resource = property.firstChild().nodeValue();
+ if (resource.contains(QRegExp("\\?[0-9]+\\.[0-9]+(&strobe=[0-9]+)?$")))
+ property.firstChild().setNodeValue(child->text(1) + '?' + resource.section('?', -1));
+ else
+ property.firstChild().setNodeValue(child->text(1));
+ break;
+ }
+ }
}
}
- } else if (child->data(0, statusRole).toInt() == LUMAMISSING) {
- for (int i = 0; i < trans.count(); i++) {
- QString luma = getProperty(trans.at(i).toElement(), "luma");
- if (!luma.isEmpty() && luma == child->data(0, idRole).toString()) {
- setProperty(trans.at(i).toElement(), "luma", QString());
- }
+ }
+ } 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();
+ if (e.attribute("id") == id) {
+ // Fix clip
+ e.setAttribute("placeholder", '1');
+ break;
+ }
+ }
+ } else if (child->data(0, statusRole).toInt() == LUMAOK) {
+ for (int i = 0; i < trans.count(); ++i) {
+ QString luma = getProperty(trans.at(i).toElement(), "luma");
+ if (!luma.isEmpty() && luma == child->data(0, idRole).toString()) {
+ setProperty(trans.at(i).toElement(), "luma", child->text(1));
+ kDebug() << "replace with; " << child->text(1);
+ }
+ }
+ } else if (child->data(0, statusRole).toInt() == LUMAMISSING) {
+ for (int i = 0; i < trans.count(); ++i) {
+ QString luma = getProperty(trans.at(i).toElement(), "luma");
+ if (!luma.isEmpty() && luma == child->data(0, idRole).toString()) {
+ setProperty(trans.at(i).toElement(), "luma", QString());
}
}
- ix++;
- child = m_ui.treeWidget->topLevelItem(ix);
}
- //QDialog::accept();
}
void DocumentChecker::slotPlaceholders()
{
int ix = 0;
QTreeWidgetItem *child = m_ui.treeWidget->topLevelItem(ix);
+ QDomNodeList documentProducers = m_doc.elementsByTagName("producer");
while (child) {
if (child->data(0, statusRole).toInt() == CLIPWRONGDURATION) {
- child->setData(0, statusRole, CLIPOK);
- child->setIcon(0, KIcon("dialog-ok"));
QString id = child->data(0, idRole).toString();
- for (int i = 0; i < m_info.count(); i++) {
+ bool resetDuration = child->data(0, resetDurationRole).toInt();
+
+ for (int i = 0; i < m_info.count(); ++i) {
QDomElement e = m_info.at(i).toElement();
if (e.attribute("id") == id) {
- e.setAttribute("duration", child->data(0, sizeRole).toString());
+ if (m_missingClips.contains(e)) {
+ // we cannot fix duration of missing clips
+ resetDuration = false;
+ }
+ else {
+ if (resetDuration) e.removeAttribute("duration");
+ else e.setAttribute("duration", child->data(0, sizeRole).toString());
+ child->setData(0, statusRole, CLIPOK);
+ child->setIcon(0, KIcon("dialog-ok"));
+ }
break;
}
}
+ if (resetDuration) {
+ // something is wrong in clip durations, so remove them so mlt fetches them again
+ for (int j = 0; j < documentProducers.count(); j++) {
+ QDomElement mltProd = documentProducers.at(j).toElement();
+ QString prodId = mltProd.attribute("id");
+ if (prodId == id || prodId.startsWith(id + '_')) {
+ EffectsList::removeProperty(mltProd, "length");
+ }
+ }
+ }
}
ix++;
child = m_ui.treeWidget->topLevelItem(ix);
}
- QDomNode infoXmlNode = m_doc.elementsByTagName("kdenlivedoc").at(0);
- QDomElement infoXml = infoXmlNode.toElement();
+ QDomElement infoXml = m_doc.elementsByTagName("kdenlivedoc").at(0).toElement();
infoXml.setAttribute("modified", "1");
m_ui.fixDuration->setEnabled(false);
checkStatus();
int ix = 0;
QTreeWidgetItem *child = m_ui.treeWidget->topLevelItem(ix);
while (child) {
- int status = child->data(0, statusRole).toInt();
- if (status == CLIPMISSING || status == LUMAMISSING || status == CLIPWRONGDURATION) {
+ int childStatus = child->data(0, statusRole).toInt();
+ if (childStatus == CLIPMISSING || childStatus == LUMAMISSING || childStatus == CLIPWRONGDURATION) {
status = false;
break;
}
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;
QStringList deletedIds;
+ QStringList deletedLumas;
QDomNodeList playlists = m_doc.elementsByTagName("playlist");
foreach(QTreeWidgetItem *child, m_ui.treeWidget->selectedItems()) {
- if (child->data(0, statusRole).toInt() < 10) {
+ int id = child->data(0, statusRole).toInt();
+ if (id == CLIPMISSING) {
deletedIds.append(child->data(0, idRole).toString());
delete child;
}
+ else if (id == LUMAMISSING) {
+ deletedLumas.append(child->data(0, idRole).toString());
+ delete child;
+ }
+ }
+
+ if (!deletedLumas.isEmpty()) {
+ QDomElement e;
+ QDomNodeList transitions = m_doc.elementsByTagName("transition");
+ foreach (const QString &lumaPath, deletedLumas) {
+ for (int i = 0; i < transitions.count(); ++i) {
+ e = transitions.item(i).toElement();
+ QString resource = EffectsList::property(e, "luma");
+ if (resource == lumaPath) EffectsList::removeProperty(e, "luma");
+ }
+ }
}
- kDebug() << "// Clips to delete: " << deletedIds;
if (!deletedIds.isEmpty()) {
QDomElement e;
QDomNodeList producers = m_doc.elementsByTagName("producer");
QDomNodeList infoproducers = m_doc.elementsByTagName("kdenlive_producer");
- QDomElement mlt = m_doc.firstChildElement("mlt");
- QDomElement kdenlivedoc = mlt.firstChildElement("kdenlivedoc");
+ QDomNode mlt = m_doc.elementsByTagName("mlt").at(0);
+ QDomNode kdenlivedoc = m_doc.elementsByTagName("kdenlivedoc").at(0);
- for (int i = 0, j = 0; i < infoproducers.count() && j < deletedIds.count(); i++) {
+ for (int i = 0, j = 0; i < infoproducers.count() && j < deletedIds.count(); ++i) {
e = infoproducers.item(i).toElement();
if (deletedIds.contains(e.attribute("id"))) {
// Remove clip
kdenlivedoc.removeChild(e);
- i--;
+ --i;
j++;
}
}
- for (int i = 0; i < producers.count(); i++) {
+ for (int i = 0; i < producers.count(); ++i) {
e = producers.item(i).toElement();
if (deletedIds.contains(e.attribute("id").section('_', 0, 0)) || deletedIds.contains(e.attribute("id").section(':', 1, 1).section('_', 0, 0))) {
// Remove clip
mlt.removeChild(e);
- i--;
+ --i;
}
}
- for (int i = 0; i < playlists.count(); i++) {
+ for (int i = 0; i < playlists.count(); ++i) {
QDomNodeList entries = playlists.at(i).toElement().elementsByTagName("entry");
for (int j = 0; j < entries.count(); j++) {
e = entries.item(j).toElement();
}
}
}
- QDomNode infoXmlNode = m_doc.elementsByTagName("kdenlivedoc").at(0);
- QDomElement infoXml = infoXmlNode.toElement();
+ QDomElement infoXml = m_doc.elementsByTagName("kdenlivedoc").at(0).toElement();
infoXml.setAttribute("modified", "1");
checkStatus();
}
}
-void DocumentChecker::checkMissingImages(QList <QDomElement>&missingClips, QStringList images, QStringList fonts, QString id, QString baseClip)
+void DocumentChecker::checkMissingImagesAndFonts(const QStringList &images, const QStringList &fonts, const QString &id, const QString &baseClip)
{
QDomDocument doc;
foreach(const QString &img, images) {
+ if (m_safeImages.contains(img)) continue;
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);
+ m_missingClips.append(e);
}
+ else m_safeImages.append(img);
}
- kDebug() << "/ / / CHK FONTS: " << fonts;
foreach(const QString &fontelement, fonts) {
+ if (m_safeFonts.contains(fontelement)) continue;
QFont f(fontelement);
- kDebug() << "/ / / CHK FONTS: " << fontelement << " = " << QFontInfo(f).family();
+ //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);
+ m_missingClips.append(e);
}
+ else m_safeFonts.append(fontelement);
}
}
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) {
+ int s = item->data(0, statusRole).toInt();
+ if (t == TITLE_FONT_ELEMENT || t == TITLE_IMAGE_ELEMENT || s == PROXYMISSING) {
m_ui.removeSelected->setEnabled(false);
} else m_ui.removeSelected->setEnabled(true);
}