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

Fix delete selected clips not working on project opening.

Fixes #1092
parent 33caef63
......@@ -1031,11 +1031,12 @@ void ProjectItemModel::loadBinPlaylist(Mlt::Tractor *documentTractor, Mlt::Tract
emit pCore->loadingMessageUpdated(QString(), 1);
}
QScopedPointer<Mlt::Producer> prod(playlist.get_clip(i));
if (prod->is_blank() || !prod->is_valid()) {
if (prod->is_blank() || !prod->is_valid() || prod->parent().property_exists("kdenlive:remove")) {
qDebug()<<"==== IGNORING BIN PRODUCER: "<<prod->parent().get("kdenlive:id");
continue;
}
std::shared_ptr<Mlt::Producer> producer(new Mlt::Producer(prod->parent()));
int id = producer->get_int("kdenlive:id");
int id = producer->parent().get_int("kdenlive:id");
if (!id) id = getFreeClipId();
binProducers.insert(id, producer);
}
......
......@@ -1490,16 +1490,12 @@ void DocumentChecker::slotDeleteSelected()
if (!deletedIds.isEmpty()) {
QDomElement e;
QDomNodeList producers = m_doc.elementsByTagName(QStringLiteral("producer"));
QDomNode mlt = m_doc.elementsByTagName(QStringLiteral("mlt")).at(0);
for (int i = 0; i < producers.count(); ++i) {
e = producers.item(i).toElement();
if (deletedIds.contains(e.attribute(QStringLiteral("id")).section(QLatin1Char('_'), 0, 0)) ||
deletedIds.contains(e.attribute(QStringLiteral("id")).section(QLatin1Char(':'), 1, 1).section(QLatin1Char('_'), 0, 0))) {
// Remove clip
mlt.removeChild(e);
--i;
if (deletedIds.contains(Xml::getXmlProperty(e, QStringLiteral("kdenlive:id")))) {
// Mark clip for deletion
Xml::setXmlProperty(e, QStringLiteral("kdenlive:remove"), QStringLiteral("1"));
}
}
......@@ -1507,17 +1503,9 @@ void DocumentChecker::slotDeleteSelected()
QDomNodeList entries = playlists.at(i).toElement().elementsByTagName(QStringLiteral("entry"));
for (int j = 0; j < entries.count(); ++j) {
e = entries.item(j).toElement();
if (deletedIds.contains(e.attribute(QStringLiteral("producer")).section(QLatin1Char('_'), 0, 0)) ||
deletedIds.contains(e.attribute(QStringLiteral("producer")).section(QLatin1Char(':'), 1, 1).section(QLatin1Char('_'), 0, 0))) {
// Replace clip with blank
while (e.childNodes().count() > 0) {
e.removeChild(e.firstChild());
}
e.setTagName(QStringLiteral("blank"));
e.removeAttribute(QStringLiteral("producer"));
int length = e.attribute(QStringLiteral("out")).toInt() - e.attribute(QStringLiteral("in")).toInt();
e.setAttribute(QStringLiteral("length"), length);
j--;
if (deletedIds.contains(Xml::getXmlProperty(e, QStringLiteral("kdenlive:id")))) {
// Mark clip for deletion
Xml::setXmlProperty(e, QStringLiteral("kdenlive:remove"), QStringLiteral("1"));
}
}
}
......
......@@ -337,6 +337,10 @@ bool constructTrackFromMelt(const std::shared_ptr<TimelineItemModel> &timeline,
clipId = clip->get("kdenlive:id");
}
if (binIdCorresp.count(clipId) == 0) {
if (clip->property_exists("kdenlive:remove")) {
// Clip was marked for deletion
continue;
}
// Project was somehow corrupted
qWarning() << "can't find clip with id: " << clipId << "in bin playlist";
QStringList fixedId = pCore->projectItemModel()->getClipByUrl(QFileInfo(clip->parent().get("resource")));
......@@ -345,6 +349,8 @@ bool constructTrackFromMelt(const std::shared_ptr<TimelineItemModel> &timeline,
m_errorMessage << i18n("Invalid clip %1 (%2) not found in project bin, recovered.", clip->parent().get("id"), clipId);
} else {
m_errorMessage << i18n("Project corrupted. Clip %1 (%2) not found in project bin.", clip->parent().get("id"), clipId);
// Do not try to insert clip
continue;
}
} else {
binId = binIdCorresp.at(clipId);
......
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