* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
+#include <QCryptographicHash>
+#include <QFile>
+
#include <KDebug>
#include <KStandardDirs>
#include <KMessageBox>
#include <KIO/NetAccess>
#include <KApplication>
-#include <QFile>
#include <mlt++/Mlt.h>
if (clip == NULL) {
elem.setAttribute("id", producerId);
QString path = elem.attribute("resource");
+ QString extension;
+ if (elem.attribute("type").toInt() == SLIDESHOW) {
+ extension = KUrl(path).fileName();
+ path = KUrl(path).directory();
+ }
if (!path.isEmpty() && !QFile::exists(path)) {
const QString size = elem.attribute("file_size");
const QString hash = elem.attribute("file_hash");
QString newpath;
KMessageBox::ButtonCode action = KMessageBox::No;
if (!size.isEmpty() && !hash.isEmpty()) {
- if (!m_searchFolder.isEmpty()) newpath = Render::searchFileRecursively(m_searchFolder, size, hash);
- else action = (KMessageBox::ButtonCode)KMessageBox::messageBox(kapp->activeWindow(), KMessageBox::WarningYesNoCancel, i18n("<qt>Clip <b>%1</b><br>is invalid, what do you want to do?", path), i18n("File not found"), KGuiItem(i18n("Search automatically")), KGuiItem(i18n("Remove from project")), KGuiItem(i18n("Keep as placeholder")));
+ if (!m_searchFolder.isEmpty()) newpath = searchFileRecursively(m_searchFolder, size, hash);
+ else action = (KMessageBox::ButtonCode)KMessageBox::messageBox(kapp->activeWindow(), KMessageBox::WarningYesNo, i18n("<qt>Clip <b>%1</b><br>is invalid, what do you want to do?", path), i18n("File not found"), KGuiItem(i18n("Search automatically")), /*KGuiItem(i18n("Remove from project")), */KGuiItem(i18n("Keep as placeholder")));
} else {
- newpath = KFileDialog::getOpenFileName(KUrl("kfiledialog:///clipfolder"), QString(), kapp->activeWindow(), i18n("Looking for %1", path));
+ if (elem.attribute("type").toInt() == SLIDESHOW) {
+ if (KMessageBox::messageBox(kapp->activeWindow(), KMessageBox::WarningYesNo, i18n("<qt>Clip <b>%1</b><br>is invalid, what do you want to do?", path), i18n("File not found"), KGuiItem(i18n("Search automatically")), /*KGuiItem(i18n("Remove from project")),*/ KGuiItem(i18n("Keep as placeholder"))) == KMessageBox::Yes)
+ newpath = KFileDialog::getExistingDirectory(KUrl("kfiledialog:///clipfolder"), kapp->activeWindow(), i18n("Looking for %1", path));
+ } else newpath = KFileDialog::getOpenFileName(KUrl("kfiledialog:///clipfolder"), QString(), kapp->activeWindow(), i18n("Looking for %1", path));
}
if (action == KMessageBox::Yes) {
kDebug() << "// ASKED FOR SRCH CLIP: " << clipId;
m_searchFolder = KFileDialog::getExistingDirectory(KUrl("kfiledialog:///clipfolder"), kapp->activeWindow());
if (!m_searchFolder.isEmpty()) {
- newpath = Render::searchFileRecursively(QDir(m_searchFolder), size, hash);
+ newpath = searchFileRecursively(QDir(m_searchFolder), size, hash);
}
}
if (!newpath.isEmpty()) {
+ if (elem.attribute("type").toInt() == SLIDESHOW) newpath.append('/' + extension);
elem.setAttribute("resource", newpath);
setNewClipResource(clipId, newpath);
}
}
}
+QString KdenliveDoc::searchFileRecursively(const QDir &dir, const QString &matchSize, const QString &matchHash) const {
+ QString foundFileName;
+ QByteArray fileData;
+ QByteArray fileHash;
+ 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) {
+ /*
+ * 1 MB = 1 second per 450 files (or faster)
+ * 10 MB = 9 seconds per 450 files (or faster)
+ */
+ if (file.size() > 1000000*2) {
+ fileData = file.read(1000000);
+ if (file.seek(file.size() - 1000000))
+ fileData.append(file.readAll());
+ } else
+ fileData = file.readAll();
+ file.close();
+ fileHash = QCryptographicHash::hash(fileData, QCryptographicHash::Md5);
+ if (QString(fileHash.toHex()) == matchHash)
+ return file.fileName();
+ }
+ }
+ 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++) {
+ foundFileName = searchFileRecursively(dir.absoluteFilePath(filesAndDirs.at(i)), matchSize, matchHash);
+ if (!foundFileName.isEmpty())
+ break;
+ }
+ return foundFileName;
+}
+
void KdenliveDoc::addClipInfo(QDomElement elem, QString clipId) {
DocClipBase *clip = m_clipManager->getClipById(clipId);
if (clip == NULL) {
ProjectItem *item = getItemById(id);
if (item) {
const QString path = item->referencedClip()->fileURL().path();
- //if (!path.isEmpty()) KMessageBox::sorry(this, i18n("<qt>Clip <b>%1</b><br>is invalid, will be removed from project.", path));
- KMessageBox::ButtonCode action;
- if (!path.isEmpty()) {
- action = (KMessageBox::ButtonCode)KMessageBox::messageBox(this, KMessageBox::WarningYesNoCancel, i18n("<qt>Clip <b>%1</b><br>is invalid, what do you want to do?", path), i18n("File not found"), KGuiItem(i18n("Search automatically")), KGuiItem(i18n("Remove from project")), KGuiItem(i18n("Keep as placeholder")));
- } else
- action = KMessageBox::No; // then remove
- if (action == KMessageBox::Yes) { // search
- QString foundFileName;
- if (!item->referencedClip()->getProperty("file_size").isEmpty() && !item->referencedClip()->getProperty("file_hash").isEmpty()) { // both hash and file size were registered
- QString rootDir = KFileDialog::getExistingDirectory(KUrl("kfiledialog:///clipfolder"), this);
- if (!rootDir.isEmpty()) {
- foundFileName = Render::searchFileRecursively(QDir(rootDir), item->referencedClip()->getProperty("file_size"), item->referencedClip()->getProperty("file_hash"));
- }
- }
- if (foundFileName.isEmpty())
- KMessageBox::sorry(this, i18n("<qt>Cannot find a match for clip<br><b>%1</b>,<br>leaving in project as a placeholder.", path));
- else {
- QMap <QString, QString> properties;
- properties["resource"] = foundFileName;
- kDebug() << "CLIP ID:" << item->referencedClip()->getId() << "--- setting 'resource' to" << foundFileName;
- slotUpdateClipProperties(item->referencedClip()->getId(), properties);
- }
- } else if (action == KMessageBox::No) { // remove
- QList <QString> ids;
- ids << id;
- m_doc->deleteProjectClip(ids);
- } // else keep it (last choice to be automatically bound to ESC)
+ if (!path.isEmpty()) KMessageBox::sorry(this, i18n("<qt>Clip <b>%1</b><br>is invalid, will be removed from project.", path));
+ QList <QString> ids;
+ ids << id;
+ m_doc->deleteProjectClip(ids);
}
if (!m_infoQueue.isEmpty()) QTimer::singleShot(300, this, SLOT(slotProcessNextClipInQueue()));
}
#include <QTimer>
#include <QDir>
#include <QApplication>
-//#include <QPainter>
-#include <QCryptographicHash>
#include <KDebug>
#include <KStandardDirs>
}
-//static
-
-QString Render::searchFileRecursively(const QDir &dir, const QString &matchSize, const QString &matchHash) {
- QString foundFileName;
- QByteArray fileData;
- QByteArray fileHash;
- 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) {
- /*
- * 1 MB = 1 second per 450 files (or faster)
- * 10 MB = 9 seconds per 450 files (or faster)
- */
- if (file.size() > 1000000*2) {
- fileData = file.read(1000000);
- if (file.seek(file.size() - 1000000))
- fileData.append(file.readAll());
- } else
- fileData = file.readAll();
- file.close();
- fileHash = QCryptographicHash::hash(fileData, QCryptographicHash::Md5);
- if (QString(fileHash.toHex()) == matchHash)
- return file.fileName();
- }
- }
- 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++) {
- foundFileName = searchFileRecursively(dir.absoluteFilePath(filesAndDirs.at(i)), matchSize, matchHash);
- if (!foundFileName.isEmpty())
- break;
- }
- return foundFileName;
-}
-
/** Create the producer from the Westley QDomDocument */
#if 0
void Render::initSceneList() {