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)
if (rootDir == QLatin1String("$CURRENTPATH")) {
// The document was extracted from a Kdenlive archived project, fix root directory
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);
mlt = m_doc.firstChildElement(QStringLiteral("mlt"));
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
......
......@@ -125,7 +125,7 @@ ArchiveWidget::ArchiveWidget(const QString &projectName, const QDomDocument &doc
else if (t == QText) {
allFonts << clip->property(QStringLiteral("family"));
}
else if (t == Text) {
else if (t == Text || t == TextTemplate) {
QStringList imagefiles = TitleWidget::extractImageList(clip->property(QStringLiteral("xmldata")));
QStringList fonts = TitleWidget::extractFontList(clip->property(QStringLiteral("xmldata")));
extraImageUrls << imagefiles;
......@@ -444,20 +444,16 @@ void ArchiveWidget::generateItems(QTreeWidgetItem *parentItem, const QMap<QStrin
// pattern url (like clip%.3d.png)
QStringList result = dir.entryList(QDir::Files);
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);
QString regexp = QLatin1Char('^') + filter + QStringLiteral("\\d+\\.") + ext + QLatin1Char('$');
QRegExp rx(regexp);
QStringList slideImages;
qint64 totalSize = 0;
QString directory = dir.absolutePath();
if (!directory.endsWith(QLatin1Char('/'))) {
directory.append(QLatin1Char('/'));
}
foreach (const QString &path, result) {
if (rx.exactMatch(path)) {
totalSize += QFileInfo(directory + path).size();
slideImages << directory + path;
totalSize += QFileInfo(dir.absoluteFilePath(path)).size();
slideImages << dir.absoluteFilePath(path);
}
}
item->setData(0, Qt::UserRole + 1, slideImages);
......@@ -699,18 +695,18 @@ bool ArchiveWidget::processProjectFile()
for (int i = 0; i < files_list->topLevelItemCount(); ++i) {
QTreeWidgetItem *parentItem = files_list->topLevelItem(i);
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");
for (int j = 0; j < parentItem->childCount(); ++j) {
item = parentItem->child(j);
QUrl src = QUrl::fromLocalFile(item->text(0));
QUrl dest = destUrl;
QUrl dest = QUrl::fromLocalFile(destFolder.absolutePath());
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()) {
dest = QUrl::fromLocalFile(destUrl.toLocalFile() + QDir::separator() + src.fileName());
dest = QUrl::fromLocalFile(parentItem->data(0, Qt::UserRole).toString() + QLatin1Char('/') + src.fileName());
} 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);
}
......@@ -728,11 +724,10 @@ bool ArchiveWidget::processProjectFile()
if (isArchive) {
basePath = QStringLiteral("$CURRENTPATH");
} else {
basePath = archive_url->url().adjusted(QUrl::StripTrailingSlash).toLocalFile();
basePath = archive_url->url().adjusted(QUrl::StripTrailingSlash | QUrl::StripTrailingSlash).toLocalFile();
}
mlt.setAttribute(QStringLiteral("root"), basePath);
QDomElement project = mlt.firstChildElement(QStringLiteral("kdenlivedoc"));
project.setAttribute(QStringLiteral("projectfolder"), basePath);
// Switch to relative path
mlt.removeAttribute(QStringLiteral("root"));
// process kdenlive producers
QDomNodeList prods = mlt.elementsByTagName(QStringLiteral("kdenlive_producer"));
......@@ -775,6 +770,30 @@ bool ArchiveWidget::processProjectFile()
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)
......@@ -849,10 +868,14 @@ bool ArchiveWidget::processProjectFile()
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());
QString user = dirInfo.owner();
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);
// Create folders
......
......@@ -214,8 +214,6 @@ public:
/** @brief Returns last requested seeking pos, or current cursor position. */
int seekPosition() const;
/** @brief Trigger a monitor refresh. */
void monitorRefresh(const QList<ItemInfo> &range, bool invalidateRange = false);
void monitorRefresh(bool invalidateRange = false);
/** @brief Trigger a monitor refresh if timeline cursor is inside range. */
void monitorRefresh(const ItemInfo &range, bool invalidateRange = false);
......@@ -365,6 +363,8 @@ public slots:
void slotUpdateAllThumbs();
void slotCheckPositionScrolling();
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.
* @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