Commit f2083aee authored by Julius Künzel's avatar Julius Künzel 💬
Browse files

Ensure files are open before reading to QDomDocument Pt. 2

This is required by future Qt versions

This makes use of Xml::docContentFromFile
parent 0a33db39
Pipeline #252130 failed with stage
in 5 minutes and 11 seconds
......@@ -2230,15 +2230,16 @@ void Bin::createClip(const QDomElement &xml)
}
QString path = Xml::getXmlProperty(xml, QStringLiteral("resource"));
if (path.endsWith(QStringLiteral(".mlt")) || path.endsWith(QStringLiteral(".kdenlive"))) {
QFile f(path);
QDomDocument doc;
doc.setContent(&f, false);
f.close();
if (!Xml::docContentFromFile(doc, path, false)) {
return;
}
DocumentChecker d(QUrl::fromLocalFile(path), doc);
if (!d.hasErrorInClips() && doc.documentElement().hasAttribute(QStringLiteral("modified"))) {
QString backupFile = path + QStringLiteral(".backup");
KIO::FileCopyJob *copyjob = KIO::file_copy(QUrl::fromLocalFile(path), QUrl::fromLocalFile(backupFile));
if (copyjob->exec()) {
QFile f(path);
if (!f.open(QIODevice::WriteOnly | QIODevice::Text)) {
KMessageBox::error(this, i18n("Unable to write to file %1", path));
} else {
......@@ -3920,7 +3921,7 @@ void Bin::slotExpandUrl(const ItemInfo &info, const QString &url, QUndoCommand *
// Parse playlist clips
QDomDocument doc;
QFile file(url);
doc.setContent(&file, false);
doc.setContent(&file, false); //TODO: use Xml::docContentFromFile
file.close();
bool invalid = false;
if (doc.documentElement().isNull()) {
......
......@@ -39,11 +39,8 @@ std::shared_ptr<EffectTreeModel> EffectTreeModel::construct(const QString &categ
std::shared_ptr<TreeItem> miscCategory = nullptr;
std::shared_ptr<TreeItem> audioCategory = nullptr;
// We parse category file
if (!categoryFile.isEmpty()) {
QDomDocument doc;
QFile file(categoryFile);
doc.setContent(&file, false);
file.close();
QDomDocument doc;
if (!categoryFile.isEmpty() && Xml::docContentFromFile(doc, categoryFile, false)) {
QDomNodeList groups = doc.documentElement().elementsByTagName(QStringLiteral("group"));
auto groupLegacy = self->rootItem->appendChild(QList<QVariant>{i18n("Legacy"), QStringLiteral("root")});
......
......@@ -366,10 +366,8 @@ void ClipLoadTask::run()
producerLength = producer->time_to_frames(pLength.toUtf8().constData());
}
// Title from .kdenlivetitle file
QFile txtfile(resource);
QDomDocument txtdoc(QStringLiteral("titledocument"));
if (txtfile.open(QIODevice::ReadOnly) && txtdoc.setContent(&txtfile)) {
txtfile.close();
if (Xml::docContentFromFile(txtdoc, resource, false)) {
if (txtdoc.documentElement().hasAttribute(QStringLiteral("duration"))) {
duration = txtdoc.documentElement().attribute(QStringLiteral("duration")).toInt();
} else if (txtdoc.documentElement().hasAttribute(QStringLiteral("out"))) {
......
......@@ -185,19 +185,17 @@ void FilterTask::run()
producer.reset();
// wholeProducer.reset();
QFile f1(sourceFile.fileName());
f1.open(QIODevice::ReadOnly);
QDomDocument dom(sourceFile.fileName());
dom.setContent(&f1);
f1.close();
Xml::docContentFromFile(dom, sourceFile.fileName(), false);
// add consumer element
QDomElement consumerNode = dom.createElement("consumer");
QDomNodeList profiles = dom.elementsByTagName("profile");
if (profiles.isEmpty())
if (profiles.isEmpty()) {
dom.documentElement().insertAfter(consumerNode, dom.documentElement());
else
} else {
dom.documentElement().insertAfter(consumerNode, profiles.at(profiles.length() - 1));
}
consumerNode.setAttribute("mlt_service", "xml");
for (const QString &param : qAsConst(m_consumerArgs)) {
if (param.contains(QLatin1Char('='))) {
......@@ -206,6 +204,7 @@ void FilterTask::run()
}
consumerNode.setAttribute("resource", destFile.fileName());
QFile f1(sourceFile.fileName());
f1.open(QIODevice::WriteOnly);
QTextStream stream(&f1);
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
......@@ -241,17 +240,16 @@ void FilterTask::run()
if (m_filterData.find(QStringLiteral("key")) != m_filterData.end()) {
key = m_filterData.at(QStringLiteral("key"));
}
QFile f2(destFile.fileName());
f2.open(QIODevice::ReadOnly);
dom.setContent(&f2);
f2.close();
QString resultData;
QDomNodeList filters = dom.elementsByTagName(QLatin1String("filter"));
for (int i = 0; i < filters.count(); ++i) {
QDomElement currentParameter = filters.item(i).toElement();
if (currentParameter.attribute(QLatin1String("id")) == QLatin1String("kdenlive-analysis")) {
resultData = Xml::getXmlProperty(currentParameter, key);
break;
if (Xml::docContentFromFile(dom, destFile.fileName(), false)) {
QDomNodeList filters = dom.elementsByTagName(QLatin1String("filter"));
for (int i = 0; i < filters.count(); ++i) {
QDomElement currentParameter = filters.item(i).toElement();
if (currentParameter.attribute(QLatin1String("id")) == QLatin1String("kdenlive-analysis")) {
resultData = Xml::getXmlProperty(currentParameter, key);
break;
}
}
}
......
......@@ -799,8 +799,7 @@ void ArchiveWidget::slotArchivingProgress(KJob *, qulonglong size)
QString ArchiveWidget::processPlaylistFile(const QString &filename)
{
QDomDocument doc;
QFile file(filename);
if (!file.open(QIODevice::ReadOnly) || !doc.setContent(&file)) {
if (!Xml::docContentFromFile(doc, filename, false)) {
return QString();
}
return processMltFile(doc, QStringLiteral("../"));
......
......@@ -644,15 +644,10 @@ QStringList ProjectSettings::extractPlaylistUrls(const QString &path)
{
QStringList urls;
QDomDocument doc;
QFile file(path);
if (!file.open(QIODevice::ReadOnly)) {
return urls;
}
if (!doc.setContent(&file)) {
file.close();
if (!Xml::docContentFromFile(doc, path, false)) {
return urls;
}
file.close();
QString root = doc.documentElement().attribute(QStringLiteral("root"));
if (!root.isEmpty() && !root.endsWith(QLatin1Char('/'))) {
root.append(QLatin1Char('/'));
......
......@@ -1193,10 +1193,12 @@ void ProjectManager::saveWithUpdatedProfile(const QString &updatedProfile)
m_project->setModified(false);
}
QFile f(currentFile);
QDomDocument doc;
doc.setContent(&f, false);
f.close();
if (!Xml::docContentFromFile(doc, currentFile, false)) {
KMessageBox::error(qApp->activeWindow(), i18n("Cannot read file %1", currentFile));
return;
}
QDomElement mltProfile = doc.documentElement().firstChildElement(QStringLiteral("profile"));
if (!mltProfile.isNull()) {
mltProfile.setAttribute(QStringLiteral("frame_rate_num"), newProfile->frame_rate_num());
......
......@@ -308,9 +308,12 @@ const QString RenderPresetRepository::savePreset(RenderPresetModel *preset, bool
if (!dir.exists()) {
dir.mkpath(QStringLiteral("."));
}
QFile file(dir.absoluteFilePath(QStringLiteral("customprofiles.xml")));
doc.setContent(&file, false);
file.close();
QString fileName(dir.absoluteFilePath(QStringLiteral("customprofiles.xml")));
if (!Xml::docContentFromFile(doc, fileName, false)) {
KMessageBox::error(nullptr, i18n("Cannot read file %1", fileName));
return {};
}
QDomElement documentElement;
QDomElement profiles = doc.documentElement();
if (profiles.isNull() || profiles.tagName() != QLatin1String("profiles")) {
......@@ -366,7 +369,7 @@ const QString RenderPresetRepository::savePreset(RenderPresetModel *preset, bool
}
profiles.appendChild(newPreset);
QFile file(fileName);
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
KMessageBox::error(nullptr, i18n("Cannot open file %1", file.fileName()));
return {};
......
......@@ -2207,12 +2207,11 @@ QDomDocument TimelineFunctions::extractClip(const std::shared_ptr<TimelineItemMo
int tid = timeline->getClipTrackId(cid);
int pos = timeline->getClipPosition(cid);
std::shared_ptr<ProjectClip> clip = pCore->bin()->getBinClip(binId);
const QString url = clip->clipUrl();
QFile f(url);
QDomDocument sourceDoc;
sourceDoc.setContent(&f, false);
f.close();
QDomDocument destDoc;
if (!Xml::docContentFromFile(sourceDoc, clip->clipUrl(), false)) {
return destDoc;
}
QDomElement container = destDoc.createElement(QStringLiteral("kdenlive-scene"));
destDoc.appendChild(container);
QDomElement bin = destDoc.createElement(QStringLiteral("bin"));
......
Supports Markdown
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