/***
Olive - Non-Linear Video Editor
Copyright (C) 2022 Olive Team
Modifications Copyright (C) 2025 mikesolar
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
***/
#include "serializer210528.h"
#include "config/config.h"
#include "node/factory.h"
#include "node/group/group.h"
namespace olive
{
ProjectSerializer210528::LoadData
ProjectSerializer210528::load(Project *project, QXmlStreamReader *reader,
LoadType load_type, void *reserved) const
{
XMLNodeData xml_node_data;
while (xml_read_next_start_element(reader)) {
if (reader->name() == QStringLiteral("uuid")) {
project->set_uuid(QUuid::fromString(reader->readElementText()));
} else if (reader->name() == QStringLiteral("nodes")) {
while (xml_read_next_start_element(reader)) {
if (reader->name() == QStringLiteral("node")) {
bool is_root = false;
bool is_cm = false;
bool is_settings = false;
QString id;
{
XMLAttributeLoop(reader, attr)
{
if (attr.name() == QStringLiteral("id")) {
id = attr.value().toString();
} else if (attr.name() == QStringLiteral("root") &&
attr.value() == QStringLiteral("1")) {
is_root = true;
} else if (attr.name() == QStringLiteral("cm") &&
attr.value() == QStringLiteral("1")) {
is_cm = true;
} else if (attr.name() ==
QStringLiteral("settings") &&
attr.value() == QStringLiteral("1")) {
is_settings = true;
}
}
}
if (id.isEmpty()) {
qWarning() << "Failed to load node with empty ID";
reader->skipCurrentElement();
} else {
Node *node;
bool handled_elsewhere = false;
if (is_root) {
project->initialize();
node = project->root();
} else if (is_cm) {
load_color_manager(reader, project);
handled_elsewhere = true;
} else if (is_settings) {
load_project_settings(reader, project);
handled_elsewhere = true;
} else {
node = NodeFactory::create_from_id(id);
}
if (!handled_elsewhere) {
if (!node) {
qWarning()
<< "Failed to find node with ID" << id;
reader->skipCurrentElement();
} else {
load_node(node, xml_node_data, reader);
node->setParent(project);
}
}
}
} else {
reader->skipCurrentElement();
}
}
} else if (reader->name() == QStringLiteral("positions")) {
while (xml_read_next_start_element(reader)) {
if (reader->name() == QStringLiteral("context")) {
quintptr context_ptr = 0;
XMLAttributeLoop(reader, attr)
{
if (attr.name() == QStringLiteral("ptr")) {
context_ptr = attr.value().toULongLong();
break;
}
}
Node *context = xml_node_data.node_ptrs.value(context_ptr);
if (!context) {
qWarning() << "Failed to find pointer for context";
reader->skipCurrentElement();
} else {
while (xml_read_next_start_element(reader)) {
if (reader->name() == QStringLiteral("node")) {
quintptr node_ptr;
Node::Position node_pos;
if (load_position(reader, &node_ptr,
&node_pos)) {
Node *node =
xml_node_data.node_ptrs.value(node_ptr);
if (node) {
context->set_node_position_in_context(
node, node_pos);
} else {
qWarning()
<< "Failed to find pointer for node position";
reader->skipCurrentElement();
}
}
} else {
reader->skipCurrentElement();
}
}
}
} else {
reader->skipCurrentElement();
}
}
} else {
// Skip this
reader->skipCurrentElement();
}
}
// Make connections
post_connect(xml_node_data);
// Resolve tracks
for (Node *n : project->nodes()) {
n->set_caches_enabled(true);
if (Track *t = dynamic_cast