Fix archived project wrong path and missing images/slideshows

CCBUG: 377999
CCBUG: 378000
parent f99275fa
...@@ -63,10 +63,12 @@ bool DocumentValidator::validate(const double currentVersion) ...@@ -63,10 +63,12 @@ bool DocumentValidator::validate(const double currentVersion)
if (rootDir == QLatin1String("$CURRENTPATH")) { if (rootDir == QLatin1String("$CURRENTPATH")) {
// The document was extracted from a Kdenlive archived project, fix root directory // The document was extracted from a Kdenlive archived project, fix root directory
QString playlist = m_doc.toString(); QString playlist = m_doc.toString();
playlist.replace(QLatin1String("$CURRENTPATH"), m_url.adjusted(QUrl::RemoveFilename).toLocalFile()); playlist.replace(QLatin1String("$CURRENTPATH"), m_url.adjusted(QUrl::RemoveFilename | QUrl::StripTrailingSlash).toLocalFile());
m_doc.setContent(playlist); m_doc.setContent(playlist);
mlt = m_doc.firstChildElement(QStringLiteral("mlt")); mlt = m_doc.firstChildElement(QStringLiteral("mlt"));
kdenliveDoc = mlt.firstChildElement(QStringLiteral("kdenlivedoc")); kdenliveDoc = mlt.firstChildElement(QStringLiteral("kdenlivedoc"));
} else if (rootDir.isEmpty()) {
mlt.setAttribute(QStringLiteral("root"), m_url.adjusted(QUrl::RemoveFilename | QUrl::StripTrailingSlash).toLocalFile());
} }
// Previous MLT / Kdenlive versions used C locale by default // Previous MLT / Kdenlive versions used C locale by default
......
...@@ -125,7 +125,7 @@ ArchiveWidget::ArchiveWidget(const QString &projectName, const QDomDocument &doc ...@@ -125,7 +125,7 @@ ArchiveWidget::ArchiveWidget(const QString &projectName, const QDomDocument &doc
else if (t == QText) { else if (t == QText) {
allFonts << clip->property(QStringLiteral("family")); allFonts << clip->property(QStringLiteral("family"));
} }
else if (t == Text) { else if (t == Text || t == TextTemplate) {
QStringList imagefiles = TitleWidget::extractImageList(clip->property(QStringLiteral("xmldata"))); QStringList imagefiles = TitleWidget::extractImageList(clip->property(QStringLiteral("xmldata")));
QStringList fonts = TitleWidget::extractFontList(clip->property(QStringLiteral("xmldata"))); QStringList fonts = TitleWidget::extractFontList(clip->property(QStringLiteral("xmldata")));
extraImageUrls << imagefiles; extraImageUrls << imagefiles;
...@@ -444,20 +444,16 @@ void ArchiveWidget::generateItems(QTreeWidgetItem *parentItem, const QMap<QStrin ...@@ -444,20 +444,16 @@ void ArchiveWidget::generateItems(QTreeWidgetItem *parentItem, const QMap<QStrin
// pattern url (like clip%.3d.png) // pattern url (like clip%.3d.png)
QStringList result = dir.entryList(QDir::Files); QStringList result = dir.entryList(QDir::Files);
QString filter = slideUrl.fileName(); QString filter = slideUrl.fileName();
QString ext = filter.section(QLatin1Char('.'), -1); QString ext = filter.section(QLatin1Char('.'), -1).section(QLatin1Char('?'), 0, 0);
filter = filter.section(QLatin1Char('%'), 0, -2); filter = filter.section(QLatin1Char('%'), 0, -2);
QString regexp = QLatin1Char('^') + filter + QStringLiteral("\\d+\\.") + ext + QLatin1Char('$'); QString regexp = QLatin1Char('^') + filter + QStringLiteral("\\d+\\.") + ext + QLatin1Char('$');
QRegExp rx(regexp); QRegExp rx(regexp);
QStringList slideImages; QStringList slideImages;
qint64 totalSize = 0; qint64 totalSize = 0;
QString directory = dir.absolutePath();
if (!directory.endsWith(QLatin1Char('/'))) {
directory.append(QLatin1Char('/'));
}
foreach (const QString &path, result) { foreach (const QString &path, result) {
if (rx.exactMatch(path)) { if (rx.exactMatch(path)) {
totalSize += QFileInfo(directory + path).size(); totalSize += QFileInfo(dir.absoluteFilePath(path)).size();
slideImages << directory + path; slideImages << dir.absoluteFilePath(path);
} }
} }
item->setData(0, Qt::UserRole + 1, slideImages); item->setData(0, Qt::UserRole + 1, slideImages);
...@@ -699,18 +695,18 @@ bool ArchiveWidget::processProjectFile() ...@@ -699,18 +695,18 @@ bool ArchiveWidget::processProjectFile()
for (int i = 0; i < files_list->topLevelItemCount(); ++i) { for (int i = 0; i < files_list->topLevelItemCount(); ++i) {
QTreeWidgetItem *parentItem = files_list->topLevelItem(i); QTreeWidgetItem *parentItem = files_list->topLevelItem(i);
if (parentItem->childCount() > 0) { if (parentItem->childCount() > 0) {
destUrl = QUrl::fromLocalFile(archive_url->url().toLocalFile() + QDir::separator() + parentItem->data(0, Qt::UserRole).toString()); QDir destFolder(archive_url->url().toLocalFile() + QDir::separator() + parentItem->data(0, Qt::UserRole).toString());
bool isSlideshow = parentItem->data(0, Qt::UserRole).toString() == QLatin1String("slideshows"); bool isSlideshow = parentItem->data(0, Qt::UserRole).toString() == QLatin1String("slideshows");
for (int j = 0; j < parentItem->childCount(); ++j) { for (int j = 0; j < parentItem->childCount(); ++j) {
item = parentItem->child(j); item = parentItem->child(j);
QUrl src = QUrl::fromLocalFile(item->text(0)); QUrl src = QUrl::fromLocalFile(item->text(0));
QUrl dest = destUrl; QUrl dest = QUrl::fromLocalFile(destFolder.absolutePath());
if (isSlideshow) { if (isSlideshow) {
dest = QUrl::fromLocalFile(destUrl.toLocalFile() + QDir::separator() + item->data(0, Qt::UserRole).toString() + QLatin1Char('/') + src.fileName()); dest = QUrl::fromLocalFile(parentItem->data(0, Qt::UserRole).toString() + QLatin1Char('/') + item->data(0, Qt::UserRole).toString() + QLatin1Char('/') + src.fileName());
} else if (item->data(0, Qt::UserRole).isNull()) { } else if (item->data(0, Qt::UserRole).isNull()) {
dest = QUrl::fromLocalFile(destUrl.toLocalFile() + QDir::separator() + src.fileName()); dest = QUrl::fromLocalFile(parentItem->data(0, Qt::UserRole).toString() + QLatin1Char('/') + src.fileName());
} else { } else {
dest = QUrl::fromLocalFile(destUrl.toLocalFile() + QLatin1Char('/') + item->data(0, Qt::UserRole).toString()); dest = QUrl::fromLocalFile(parentItem->data(0, Qt::UserRole).toString() + QLatin1Char('/') + item->data(0, Qt::UserRole).toString());
} }
m_replacementList.insert(src, dest); m_replacementList.insert(src, dest);
} }
...@@ -728,11 +724,10 @@ bool ArchiveWidget::processProjectFile() ...@@ -728,11 +724,10 @@ bool ArchiveWidget::processProjectFile()
if (isArchive) { if (isArchive) {
basePath = QStringLiteral("$CURRENTPATH"); basePath = QStringLiteral("$CURRENTPATH");
} else { } else {
basePath = archive_url->url().adjusted(QUrl::StripTrailingSlash).toLocalFile(); basePath = archive_url->url().adjusted(QUrl::StripTrailingSlash | QUrl::StripTrailingSlash).toLocalFile();
} }
mlt.setAttribute(QStringLiteral("root"), basePath); // Switch to relative path
QDomElement project = mlt.firstChildElement(QStringLiteral("kdenlivedoc")); mlt.removeAttribute(QStringLiteral("root"));
project.setAttribute(QStringLiteral("projectfolder"), basePath);
// process kdenlive producers // process kdenlive producers
QDomNodeList prods = mlt.elementsByTagName(QStringLiteral("kdenlive_producer")); QDomNodeList prods = mlt.elementsByTagName(QStringLiteral("kdenlive_producer"));
...@@ -775,6 +770,30 @@ bool ArchiveWidget::processProjectFile() ...@@ -775,6 +770,30 @@ bool ArchiveWidget::processProjectFile()
EffectsList::setProperty(e, QStringLiteral("resource"), dest.toLocalFile()); EffectsList::setProperty(e, QStringLiteral("resource"), dest.toLocalFile());
} }
} }
src = EffectsList::property(e, QStringLiteral("xmldata"));
bool found = false;
if (!src.isEmpty() && (src.contains(QLatin1String("QGraphicsPixmapItem")) || src.contains(QLatin1String("QGraphicsSvgItem")))) {
// Title with images, replace paths
QDomDocument titleXML;
titleXML.setContent(src);
QDomNodeList images = titleXML.documentElement().elementsByTagName(QLatin1String("item"));
for (int i = 0; i < images.count(); i++) {
QDomNode n = images.at(i);
QDomElement url = n.firstChildElement(QLatin1String("content"));
if (!url.isNull() && url.hasAttribute(QLatin1String("url"))) {
QUrl srcUrl = QUrl::fromLocalFile(url.attribute(QLatin1String("url")));
QUrl dest = m_replacementList.value(srcUrl);
if (dest.isValid()) {
url.setAttribute(QLatin1String("url"), dest.toLocalFile());
found = true;
}
}
}
if (found) {
// replace content
EffectsList::setProperty(e, QStringLiteral("xmldata"), titleXML.toString());
}
}
} }
// process mlt transitions (for luma files) // process mlt transitions (for luma files)
...@@ -849,10 +868,14 @@ bool ArchiveWidget::processProjectFile() ...@@ -849,10 +868,14 @@ bool ArchiveWidget::processProjectFile()
void ArchiveWidget::createArchive() void ArchiveWidget::createArchive()
{ {
QString archiveName(archive_url->url().toLocalFile() + QDir::separator() + m_name + QStringLiteral(".tar.gz"));
if (QFile::exists(archiveName) && KMessageBox::questionYesNo(this, i18n("File %1 already exists.\nDo you want to overwrite it?", archiveName)) == KMessageBox::No) {
return;
}
QFileInfo dirInfo(archive_url->url().toLocalFile()); QFileInfo dirInfo(archive_url->url().toLocalFile());
QString user = dirInfo.owner(); QString user = dirInfo.owner();
QString group = dirInfo.group(); QString group = dirInfo.group();
KTar archive(archive_url->url().toLocalFile() + QDir::separator() + m_name + QStringLiteral(".tar.gz"), QStringLiteral("application/x-gzip")); KTar archive(archiveName, QStringLiteral("application/x-gzip"));
archive.open(QIODevice::WriteOnly); archive.open(QIODevice::WriteOnly);
// Create folders // Create folders
......
...@@ -214,8 +214,6 @@ public: ...@@ -214,8 +214,6 @@ public:
/** @brief Returns last requested seeking pos, or current cursor position. */ /** @brief Returns last requested seeking pos, or current cursor position. */
int seekPosition() const; int seekPosition() const;
/** @brief Trigger a monitor refresh. */
void monitorRefresh(const QList<ItemInfo> &range, bool invalidateRange = false);
void monitorRefresh(bool invalidateRange = false); void monitorRefresh(bool invalidateRange = false);
/** @brief Trigger a monitor refresh if timeline cursor is inside range. */ /** @brief Trigger a monitor refresh if timeline cursor is inside range. */
void monitorRefresh(const ItemInfo &range, bool invalidateRange = false); void monitorRefresh(const ItemInfo &range, bool invalidateRange = false);
...@@ -365,6 +363,8 @@ public slots: ...@@ -365,6 +363,8 @@ public slots:
void slotUpdateAllThumbs(); void slotUpdateAllThumbs();
void slotCheckPositionScrolling(); void slotCheckPositionScrolling();
void slotInsertTrack(int ix); void slotInsertTrack(int ix);
/** @brief Trigger a monitor refresh. */
void monitorRefresh(const QList<ItemInfo> &range, bool invalidateRange = false);
/** @brief Shows a dialog for selecting a track to delete. /** @brief Shows a dialog for selecting a track to delete.
* @param ix Number of the track, which should be pre-selected in the dialog */ * @param ix Number of the track, which should be pre-selected in the dialog */
......
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