#include "documentchecker.h"
#include "kthumb.h"
#include "definitions.h"
+#include "kdenlivesettings.h"
#include <KDebug>
#include <KGlobalSettings>
#include <KFileDialog>
#include <KApplication>
#include <KUrlRequesterDialog>
+#include <KMessageBox>
#include <QTreeWidgetItem>
#include <QFile>
const int CLIPMISSING = 0;
const int CLIPOK = 1;
const int CLIPPLACEHOLDER = 2;
+const int LUMAMISSING = 10;
+const int LUMAOK = 11;
+const int LUMAPLACEHOLDER = 12;
-DocumentChecker::DocumentChecker(QDomDocument doc, QWidget * parent) :
- QDialog(parent), m_doc(doc)
+DocumentChecker::DocumentChecker(QList <QDomElement> missingClips, QDomDocument doc, QWidget * parent) :
+ QDialog(parent),
+ m_doc(doc)
{
setFont(KGlobalSettings::toolBarFont());
- m_view.setupUi(this);
-
- QDomNodeList producers = m_doc.elementsByTagName("producer");
- QDomNodeList infoproducers = m_doc.elementsByTagName("kdenlive_producer");
-
- int clipType;
+ setupUi(this);
QDomElement e;
- QString id;
- QString resource;
- QList <QDomElement> missingClips;
- for (int i = 0; i < infoproducers.count(); i++) {
- e = infoproducers.item(i).toElement();
- clipType = e.attribute("type").toInt();
- if (clipType == TEXT) 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);
+ QStringList missingLumas;
+ QDomNodeList trans = 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)) {
+ 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);
+ }
}
}
- if (missingClips.isEmpty()) QTimer::singleShot(0, this, SLOT(accept()));
- m_view.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
+ buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
for (int i = 0; i < missingClips.count(); i++) {
e = missingClips.at(i).toElement();
QString clipType;
default:
clipType = i18n("Video clip");
}
- QTreeWidgetItem *item = new QTreeWidgetItem(m_view.treeWidget, QStringList() << clipType << e.attribute("resource"));
+ 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"));
item->setData(0, idRole, e.attribute("id"));
item->setData(0, statusRole, CLIPMISSING);
}
- connect(m_view.recursiveSearch, SIGNAL(pressed()), this, SLOT(slotSearchClips()));
- connect(m_view.usePlaceholders, SIGNAL(pressed()), this, SLOT(slotPlaceholders()));
- connect(m_view.treeWidget, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)), this, SLOT(slotEditItem(QTreeWidgetItem *, int)));
+ 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)));
//adjustSize();
}
DocumentChecker::~DocumentChecker() {}
+
+QString DocumentChecker::getProperty(QDomElement effect, const QString &name)
+{
+ QDomNodeList params = effect.elementsByTagName("property");
+ 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)
+{
+ QDomNodeList params = effect.elementsByTagName("property");
+ for (int i = 0; i < params.count(); i++) {
+ QDomElement e = params.item(i).toElement();
+ if (e.attribute("name") == name) {
+ e.firstChild().setNodeValue(value);
+ }
+ }
+}
+
void DocumentChecker::slotSearchClips()
{
QString newpath = KFileDialog::getExistingDirectory(KUrl("kfiledialog:///clipfolder"), kapp->activeWindow(), i18n("Clips folder"));
if (newpath.isEmpty()) return;
int ix = 0;
- QTreeWidgetItem *child = m_view.treeWidget->topLevelItem(ix);
- while (child && child->data(0, statusRole).toInt() == CLIPMISSING) {
- QString clipPath = searchFileRecursively(QDir(newpath), child->data(0, sizeRole).toString(), child->data(0, hashRole).toString());
- if (!clipPath.isEmpty()) {
- child->setText(1, clipPath);
- child->setIcon(0, KIcon("dialog-ok"));
- child->setData(0, statusRole, CLIPOK);
+ recursiveSearch->setEnabled(false);
+ QTreeWidgetItem *child = 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()) {
+ 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()) {
+ child->setText(1, fileName);
+ child->setIcon(0, KIcon("dialog-ok"));
+ child->setData(0, statusRole, LUMAOK);
+ }
}
ix++;
- child = m_view.treeWidget->topLevelItem(ix);
+ child = treeWidget->topLevelItem(ix);
}
+ recursiveSearch->setEnabled(true);
checkStatus();
}
+
+QString DocumentChecker::searchLuma(QString file) const
+{
+ KUrl searchPath(KdenliveSettings::mltpath());
+ if (file.contains("PAL"))
+ searchPath.cd("../lumas/PAL");
+ else
+ searchPath.cd("../lumas/NTSC");
+ QString result = searchPath.path(KUrl::AddTrailingSlash) + KUrl(file).fileName();
+ if (QFile::exists(result))
+ return result;
+ return QString();
+}
+
+
QString DocumentChecker::searchFileRecursively(const QDir &dir, const QString &matchSize, const QString &matchHash) const
{
QString foundFileName;
QStringList filesAndDirs = dir.entryList(QDir::Files | QDir::Readable);
for (int i = 0; i < filesAndDirs.size() && foundFileName.isEmpty(); i++) {
QFile file(dir.absoluteFilePath(filesAndDirs.at(i)));
- if (file.open(QIODevice::ReadOnly)) {
- if (QString::number(file.size()) == matchSize) {
+ if (QString::number(file.size()) == matchSize) {
+ if (file.open(QIODevice::ReadOnly)) {
/*
* 1 MB = 1 second per 450 files (or faster)
* 10 MB = 9 seconds per 450 files (or faster)
return file.fileName();
}
}
- kDebug() << filesAndDirs.at(i) << file.size() << fileHash.toHex();
+ //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++) {
item->setText(1, url.path());
if (KIO::NetAccess::exists(url, KIO::NetAccess::SourceSide, 0)) {
item->setIcon(0, KIcon("dialog-ok"));
- item->setData(0, statusRole, CLIPOK);
+ int id = item->data(0, statusRole).toInt();
+ if (id < 10) item->setData(0, statusRole, CLIPOK);
+ else item->setData(0, statusRole, LUMAOK);
checkStatus();
}
}
// virtual
void DocumentChecker::accept()
{
- QDomElement e;
+ QDomElement e, property;
QDomNodeList producers = m_doc.elementsByTagName("producer");
QDomNodeList infoproducers = m_doc.elementsByTagName("kdenlive_producer");
+ QDomNodeList properties;
int ix = 0;
- QTreeWidgetItem *child = m_view.treeWidget->topLevelItem(ix);
+
+ // prepare transitions
+ QDomNodeList trans = m_doc.elementsByTagName("transition");
+
+ QTreeWidgetItem *child = treeWidget->topLevelItem(ix);
while (child) {
if (child->data(0, statusRole).toInt() == CLIPOK) {
QString id = child->data(0, idRole).toString();
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") == id) {
+ if (e.attribute("id").section('_', 0, 0) == id) {
// Fix clip
- e.setAttribute("resource", child->text(1));
+ 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;
}
}
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);
+ }
+ }
+ } 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_view.treeWidget->topLevelItem(ix);
+ child = treeWidget->topLevelItem(ix);
}
QDialog::accept();
}
void DocumentChecker::slotPlaceholders()
{
int ix = 0;
- QTreeWidgetItem *child = m_view.treeWidget->topLevelItem(ix);
+ QTreeWidgetItem *child = treeWidget->topLevelItem(ix);
while (child) {
if (child->data(0, statusRole).toInt() == CLIPMISSING) {
child->setData(0, statusRole, CLIPPLACEHOLDER);
child->setIcon(0, KIcon("dialog-ok"));
+ } else if (child->data(0, statusRole).toInt() == LUMAMISSING) {
+ child->setData(0, statusRole, LUMAPLACEHOLDER);
+ child->setIcon(0, KIcon("dialog-ok"));
}
ix++;
- child = m_view.treeWidget->topLevelItem(ix);
+ child = treeWidget->topLevelItem(ix);
}
checkStatus();
}
{
bool status = true;
int ix = 0;
- QTreeWidgetItem *child = m_view.treeWidget->topLevelItem(ix);
+ QTreeWidgetItem *child = treeWidget->topLevelItem(ix);
while (child) {
- if (child->data(0, statusRole).toInt() == CLIPMISSING) {
+ if (child->data(0, statusRole).toInt() == CLIPMISSING || child->data(0, statusRole).toInt() == LUMAMISSING) {
status = false;
break;
}
ix++;
- child = m_view.treeWidget->topLevelItem(ix);
+ child = treeWidget->topLevelItem(ix);
+ }
+ buttonBox->button(QDialogButtonBox::Ok)->setEnabled(status);
+}
+
+
+void DocumentChecker::slotDeleteSelected()
+{
+ if (KMessageBox::warningContinueCancel(this, i18n("This will remove the selected clips from this project"), i18n("Remove clips")) == KMessageBox::Cancel) return;
+ int ix = 0;
+ QStringList deletedIds;
+ QTreeWidgetItem *child = 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));
+ delete child;
+ } else ix++;
+ child = treeWidget->topLevelItem(ix);
+ }
+ 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");
+
+ for (int i = 0; i < infoproducers.count(); i++) {
+ e = infoproducers.item(i).toElement();
+ if (deletedIds.contains(e.attribute("id"))) {
+ // Remove clip
+ kdenlivedoc.removeChild(e);
+ break;
+ }
+ }
+
+ for (int i = 0; i < producers.count(); i++) {
+ e = producers.item(i).toElement();
+ if (deletedIds.contains(e.attribute("id"))) {
+ // Remove clip
+ mlt.removeChild(e);
+ break;
+ }
+ }
+
+ for (int i = 0; i < playlists.count(); i++) {
+ QDomNodeList entries = playlists.at(i).toElement().elementsByTagName("entry");
+ for (int j = 0; j < playlists.count(); j++) {
+ e = entries.item(j).toElement();
+ if (deletedIds.contains(e.attribute("producer"))) {
+ // Replace clip with blank
+ e.setTagName("blank");
+ e.removeAttribute("producer");
+ int length = e.attribute("out").toInt() - e.attribute("in").toInt();
+ e.setAttribute("length", length);
+ }
+ }
+ }
+ checkStatus();
}
- m_view.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(status);
}
#include "documentchecker.moc"