const int CLIPMISSING = 0;
const int CLIPOK = 1;
const int CLIPPLACEHOLDER = 2;
+const int CLIPWRONGDURATION = 3;
+const int PROXYMISSING = 4;
+
const int LUMAMISSING = 10;
const int LUMAOK = 11;
const int LUMAPLACEHOLDER = 12;
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)
+ m_info(infoproducers), m_doc(doc), m_dialog(NULL)
{
}
-bool DocumentChecker::hasMissingClips()
+bool DocumentChecker::hasErrorInClips()
{
int clipType;
QDomElement e;
- QString id;
QString resource;
+ QDomNodeList documentProducers = m_doc.elementsByTagName("producer");
+ QList <QDomElement> wrongDurationClips;
QList <QDomElement> missingClips;
+ QList <QDomElement> missingProxies;
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 && clipType != IMAGE) {
+ QString id = e.attribute("id");
+ int duration = e.attribute("duration").toInt();
+ // 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");
+ // Don't check slowmotion clips for now... (TODO?)
+ if (prodId.startsWith("slowmotion")) continue;
+ 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")) {
+ // Duration mismatch
+ e.setAttribute("_mismatch", mltDuration);
+ if (!wrongDurationClips.contains(e)) wrongDurationClips.append(e);
+ kDebug() << "WRONG DURTAION: "<<id<<", TYPE: "<<clipType;
+ }
+ }
+ }
+
if (clipType == TEXT) {
//TODO: Check is clip template is missing (xmltemplate) or hash changed
QStringList images = TitleWidget::extractImageList(e.attribute("xmldata"));
checkMissingImages(missingClips, images, fonts, e.attribute("id"), e.attribute("name"));
continue;
}
- id = e.attribute("id");
resource = e.attribute("resource");
+ if (e.hasAttribute("proxy")) {
+ QString proxyresource = e.attribute("proxy");
+ if (!proxyresource.isEmpty() && proxyresource != "-" && !KIO::NetAccess::exists(KUrl(proxyresource), KIO::NetAccess::SourceSide, 0)) {
+ // Missing clip found
+ missingProxies.append(e);
+ }
+ }
if (clipType == SLIDESHOW) resource = KUrl(resource).directory();
if (!KIO::NetAccess::exists(KUrl(resource), KIO::NetAccess::SourceSide, 0)) {
// Missing clip found
}
QStringList missingLumas;
+ 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.isEmpty() && !QFile::exists(luma)) {
- if (!missingLumas.contains(luma)) {
+ if (!luma.isEmpty()) {
+ if (!luma.startsWith('/')) luma.prepend(root);
+ if (!QFile::exists(luma) && !missingLumas.contains(luma)) {
missingLumas.append(luma);
}
}
}
- if (missingClips.isEmpty() && missingLumas.isEmpty()) {
+ if (missingClips.isEmpty() && missingLumas.isEmpty() && wrongDurationClips.isEmpty() && missingProxies.isEmpty())
return false;
- }
+
m_dialog = new QDialog();
m_dialog->setFont(KGlobalSettings::toolBarFont());
m_ui.setupUi(m_dialog);
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->setText(1, i18n("%1 will be replaced by %2", ft, newft));
item->setData(0, statusRole, CLIPPLACEHOLDER);
} else {
item->setIcon(0, KIcon("dialog-close"));
}
item->setData(0, typeRole, t);
item->setData(0, idRole, e.attribute("id"));
+ item->setToolTip(0, i18n("Missing item"));
+ }
+
+ if (missingClips.count() > 0) {
+ if (wrongDurationClips.count() > 0) {
+ m_ui.infoLabel->setText(i18n("The project file contains missing clips or files and clip duration mismatch"));
+ }
+ else {
+ m_ui.infoLabel->setText(i18n("The project file contains missing clips or files"));
+ }
+ }
+ else if (wrongDurationClips.count() > 0) {
+ m_ui.infoLabel->setText(i18n("The project file contains clips with duration mismatch"));
+ }
+ if (missingProxies.count() > 0) {
+ 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."));
+ }
+
+ m_ui.removeSelected->setEnabled(!missingClips.isEmpty());
+ m_ui.recursiveSearch->setEnabled(!missingClips.isEmpty());
+ m_ui.usePlaceholders->setEnabled(!missingClips.isEmpty());
+ m_ui.fixDuration->setEnabled(!wrongDurationClips.isEmpty());
+
+ for (int i = 0; i < wrongDurationClips.count(); i++) {
+ e = wrongDurationClips.at(i).toElement();
+ QString clipType;
+ int t = e.attribute("type").toInt();
+ switch (t) {
+ case AV:
+ clipType = i18n("Video clip");
+ break;
+ case VIDEO:
+ clipType = i18n("Mute video clip");
+ break;
+ case AUDIO:
+ clipType = i18n("Audio clip");
+ break;
+ case PLAYLIST:
+ clipType = i18n("Playlist clip");
+ break;
+ case IMAGE:
+ clipType = i18n("Image clip");
+ break;
+ case SLIDESHOW:
+ clipType = i18n("Slideshow clip");
+ break;
+ default:
+ clipType = i18n("Video clip");
+ }
+ QTreeWidgetItem *item = new QTreeWidgetItem(m_ui.treeWidget, QStringList() << clipType);
+ item->setIcon(0, KIcon("timeadjust"));
+ item->setText(1, e.attribute("resource"));
+ item->setData(0, hashRole, e.attribute("file_hash"));
+ item->setData(0, sizeRole, e.attribute("_mismatch"));
+ e.removeAttribute("_mismatch");
+ item->setData(0, statusRole, CLIPWRONGDURATION);
+ item->setData(0, typeRole, t);
+ item->setData(0, idRole, e.attribute("id"));
+ item->setToolTip(0, i18n("Duration mismatch"));
+ }
+
+ if (missingProxies.count() > 0) {
+ QTreeWidgetItem *item = new QTreeWidgetItem(m_ui.treeWidget, QStringList() << i18n("Proxy clip"));
+ item->setIcon(0, KIcon("dialog-warning"));
+ item->setText(1, i18n("%1 missing proxy clips, will be recreated on project opening", missingProxies.count()));
+ item->setData(0, hashRole, e.attribute("file_hash"));
+ item->setData(0, statusRole, PROXYMISSING);
+ item->setToolTip(0, i18n("Missing proxy"));
}
+
+ for (int i = 0; i < missingProxies.count(); i++) {
+ e = missingProxies.at(i).toElement();
+ QString clipType;
+ QString realPath = e.attribute("resource");
+ QString id = e.attribute("id");
+ // Replace proxy url with real clip in MLT producers
+ QDomNodeList properties;
+ QDomElement mltProd;
+ QDomElement property;
+ for (int j = 0; j < documentProducers.count(); 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 (missingProxies.count() > 0) {
+ // original doc was modified
+ QDomNode infoXmlNode = m_doc.elementsByTagName("kdenlivedoc").at(0);
+ QDomElement infoXml = infoXmlNode.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(itemSelectionChanged()), this, SLOT(slotCheckButtons()));
//adjustSize();
QString newpath = KFileDialog::getExistingDirectory(KUrl("kfiledialog:///clipfolder"), kapp->activeWindow(), i18n("Clips folder"));
if (newpath.isEmpty()) return;
int ix = 0;
+ bool fixed = false;
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());
if (!clipPath.isEmpty()) {
+ fixed = true;
child->setText(1, clipPath);
child->setIcon(0, KIcon("dialog-ok"));
child->setData(0, statusRole, CLIPOK);
} else if (child->data(0, statusRole).toInt() == LUMAMISSING) {
QString fileName = searchLuma(child->data(0, idRole).toString());
if (!fileName.isEmpty()) {
+ fixed = true;
child->setText(1, fileName);
child->setIcon(0, KIcon("dialog-ok"));
child->setData(0, statusRole, LUMAOK);
child = m_ui.treeWidget->topLevelItem(ix);
}
m_ui.recursiveSearch->setEnabled(true);
+ if (fixed) {
+ // original doc was modified
+ QDomNode infoXmlNode = m_doc.elementsByTagName("kdenlivedoc").at(0);
+ QDomElement infoXml = infoXmlNode.toElement();
+ infoXml.setAttribute("modified", "1");
+ }
checkStatus();
}
* 1 MB = 1 second per 450 files (or faster)
* 10 MB = 9 seconds per 450 files (or faster)
*/
- if (file.size() > 1000000*2) {
+ if (file.size() > 1000000 * 2) {
fileData = file.read(1000000);
if (file.seek(file.size() - 1000000))
fileData.append(file.readAll());
// prepare transitions
QDomNodeList trans = m_doc.elementsByTagName("transition");
+ // Mark document as modified
+ m_doc.documentElement().setAttribute("modified", 1);
+
QTreeWidgetItem *child = m_ui.treeWidget->topLevelItem(ix);
while (child) {
int t = child->data(0, typeRole).toInt();
}
for (int i = 0; i < producers.count(); i++) {
e = producers.item(i).toElement();
- if (e.attribute("id").section('_', 0, 0) == id) {
+ 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") {
- property.firstChild().setNodeValue(child->text(1));
+ 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;
}
}
checkStatus();
}
+void DocumentChecker::slotFixDuration()
+{
+ int ix = 0;
+ QTreeWidgetItem *child = m_ui.treeWidget->topLevelItem(ix);
+ 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++) {
+ QDomElement e = m_info.at(i).toElement();
+ if (e.attribute("id") == id) {
+ e.setAttribute("duration", child->data(0, sizeRole).toString());
+ break;
+ }
+ }
+ }
+ ix++;
+ child = m_ui.treeWidget->topLevelItem(ix);
+ }
+ QDomNode infoXmlNode = m_doc.elementsByTagName("kdenlivedoc").at(0);
+ QDomElement infoXml = infoXmlNode.toElement();
+ infoXml.setAttribute("modified", "1");
+ m_ui.fixDuration->setEnabled(false);
+ checkStatus();
+}
+
void DocumentChecker::checkStatus()
{
int ix = 0;
QTreeWidgetItem *child = m_ui.treeWidget->topLevelItem(ix);
while (child) {
- if (child->data(0, statusRole).toInt() == CLIPMISSING || child->data(0, statusRole).toInt() == LUMAMISSING) {
+ int status = child->data(0, statusRole).toInt();
+ if (status == CLIPMISSING || status == LUMAMISSING || status == CLIPWRONGDURATION) {
status = false;
break;
}
void DocumentChecker::slotDeleteSelected()
{
- 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;
+ 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;
- QTreeWidgetItem *child = m_ui.treeWidget->topLevelItem(ix);
QDomNodeList playlists = m_doc.elementsByTagName("playlist");
- while (child) {
- int id = child->data(0, statusRole).toInt();
- if (child->isSelected() && id < 10) {
- QString id = child->data(0, idRole).toString();
- deletedIds.append(id);
- for (int j = 0; j < playlists.count(); j++)
- deletedIds.append(id + '_' + QString::number(j));
+ foreach(QTreeWidgetItem *child, m_ui.treeWidget->selectedItems()) {
+ if (child->data(0, statusRole).toInt() < 10) {
+ deletedIds.append(child->data(0, idRole).toString());
delete child;
- } else ix++;
- child = m_ui.treeWidget->topLevelItem(ix);
+ }
}
kDebug() << "// Clips to delete: " << deletedIds;
QDomElement mlt = m_doc.firstChildElement("mlt");
QDomElement kdenlivedoc = mlt.firstChildElement("kdenlivedoc");
- for (int i = 0; i < infoproducers.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);
- break;
+ i--;
+ j++;
}
}
for (int i = 0; i < producers.count(); i++) {
e = producers.item(i).toElement();
- if (deletedIds.contains(e.attribute("id"))) {
+ 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);
- break;
+ i--;
}
}
for (int i = 0; i < playlists.count(); i++) {
QDomNodeList entries = playlists.at(i).toElement().elementsByTagName("entry");
- for (int j = 0; j < playlists.count(); j++) {
+ for (int j = 0; j < entries.count(); j++) {
e = entries.item(j).toElement();
- if (deletedIds.contains(e.attribute("producer"))) {
+ if (deletedIds.contains(e.attribute("producer").section('_', 0, 0)) || deletedIds.contains(e.attribute("producer").section(':', 1, 1).section('_', 0, 0))) {
// Replace clip with blank
+ while (e.childNodes().count() > 0)
+ e.removeChild(e.firstChild());
e.setTagName("blank");
e.removeAttribute("producer");
int length = e.attribute("out").toInt() - e.attribute("in").toInt();
e.setAttribute("length", length);
+ j--;
}
}
}
+ QDomNode infoXmlNode = m_doc.elementsByTagName("kdenlivedoc").at(0);
+ QDomElement infoXml = infoXmlNode.toElement();
+ infoXml.setAttribute("modified", "1");
checkStatus();
}
}
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);
}