Commit 43ae922a authored by Jean-Baptiste Mardelle's avatar Jean-Baptiste Mardelle
Browse files

Fix opening project containing invalid clips (when a source file somehow went missing)

Related to #190
parent 828f2434
Pipeline #3598 passed with stage
in 20 minutes and 55 seconds
......@@ -139,7 +139,7 @@ bool DocumentChecker::hasErrorInClips()
QStringList missingPaths;
QStringList serviceToCheck;
serviceToCheck << QStringLiteral("kdenlivetitle") << QStringLiteral("qimage") << QStringLiteral("pixbuf") << QStringLiteral("timewarp")
<< QStringLiteral("framebuffer") << QStringLiteral("xml");
<< QStringLiteral("framebuffer") << QStringLiteral("xml") << QStringLiteral("qtext");
for (int i = 0; i < max; ++i) {
QDomElement e = documentProducers.item(i).toElement();
QString service = Xml::getXmlProperty(e, QStringLiteral("mlt_service"));
......@@ -147,6 +147,42 @@ bool DocumentChecker::hasErrorInClips()
continue;
}
if (service == QLatin1String("qtext")) {
QString text = Xml::getXmlProperty(e, QStringLiteral("text"));
if (text == QLatin1String("INVALID")) {
// Warning, this is an invalid clip (project saved with missing source)
// Check if source clip is now available
QString resource = Xml::getXmlProperty(e, QStringLiteral("warp_resource"));
if (resource.isEmpty()) {
resource = Xml::getXmlProperty(e, QStringLiteral("resource"));
}
// Make sure to have absolute paths
if (QFileInfo(resource).isRelative()) {
resource.prepend(root);
}
if (QFile::exists(resource)) {
// Reset to original service
Xml::removeXmlProperty(e, QStringLiteral("text"));
QString original_service = Xml::getXmlProperty(e, QStringLiteral("kdenlive:orig_service"));
if (!original_service.isEmpty()) {
Xml::setXmlProperty(e, QStringLiteral("mlt_service"), original_service);
} else {
// Try to guess service
if (Xml::hasXmlProperty(e, QStringLiteral("ttl"))) {
Xml::setXmlProperty(e, QStringLiteral("mlt_service"), QStringLiteral("qimage"));
}
else if (resource.endsWith(QLatin1String(".kdenlivetitle"))) {
Xml::setXmlProperty(e, QStringLiteral("mlt_service"), QStringLiteral("kdenlivetitle"));
} else if (resource.endsWith(QLatin1String(".kdenlive")) || resource.endsWith(QLatin1String(".mlt"))) {
Xml::setXmlProperty(e, QStringLiteral("mlt_service"), QStringLiteral("xml"));
} else {
Xml::setXmlProperty(e, QStringLiteral("mlt_service"), QStringLiteral("avformat"));
}
}
}
continue;
}
checkMissingImagesAndFonts(QStringList(), QStringList(Xml::getXmlProperty(e, QStringLiteral("family"))), e.attribute(QStringLiteral("id")),
e.attribute(QStringLiteral("name")));
continue;
......
......@@ -134,6 +134,18 @@ void Xml::setXmlProperty(QDomElement element, const QString &propertyName, const
}
}
bool Xml::hasXmlProperty(QDomElement element, const QString &propertyName)
{
QDomNodeList params = element.elementsByTagName(QStringLiteral("property"));
for (int i = 0; i < params.count(); ++i) {
QDomElement e = params.item(i).toElement();
if (e.attribute(QStringLiteral("name")) == propertyName) {
return true;
}
}
return false;
}
void Xml::removeXmlProperty(QDomElement effect, const QString &name)
{
QDomNodeList params = effect.elementsByTagName(QStringLiteral("property"));
......
......@@ -61,6 +61,10 @@ QString getTagContentByAttribute(const QDomElement &element, const QString &tagN
QString getXmlProperty(const QDomElement &element, const QString &propertyName, const QString &defaultReturn = QString());
QString getXmlParameter(const QDomElement &element, const QString &propertyName, const QString &defaultReturn = QString());
/* @brief Returns true if the element contains a named property
*/
bool hasXmlProperty(QDomElement element, const QString &propertyName);
/* @brief Add properties to the given xml element
For each element (n, v) in the properties map, it creates a sub element of the form : <property name="n">v</property>
@param producer is the xml element where to append properties
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment