修改部分语法错误
This commit is contained in:
+39
-23
@@ -89,29 +89,7 @@ void NodeFactory::Initialize()
|
||||
}
|
||||
|
||||
olive::plugin::loadPlugins(QString());
|
||||
|
||||
for (auto plugin : OFX::Host::PluginCache::getPluginCache()->getPlugins()) {
|
||||
auto *image_effect =
|
||||
dynamic_cast<OFX::Host::ImageEffect::ImageEffectPlugin *>(plugin);
|
||||
if (!image_effect) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const auto &contexts = image_effect->getContexts();
|
||||
std::string context = kOfxImageEffectContextFilter;
|
||||
if (!contexts.empty() &&
|
||||
contexts.find(kOfxImageEffectContextFilter) == contexts.end()) {
|
||||
context = *contexts.begin();
|
||||
}
|
||||
|
||||
auto *instance = image_effect->createInstance(context, nullptr);
|
||||
if (!instance) {
|
||||
continue;
|
||||
}
|
||||
|
||||
plugin::PluginNode *plugin_node = new plugin::PluginNode(instance);
|
||||
library_.append(plugin_node);
|
||||
}
|
||||
RegisterPluginNodes();
|
||||
|
||||
}
|
||||
|
||||
@@ -238,6 +216,44 @@ Node *NodeFactory::CreateFromID(const QString &id)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void NodeFactory::RegisterPluginNodes()
|
||||
{
|
||||
QSet<QString> existing_ids;
|
||||
for (Node *node : library_) {
|
||||
existing_ids.insert(node->id());
|
||||
}
|
||||
|
||||
for (auto plugin : OFX::Host::PluginCache::getPluginCache()->getPlugins()) {
|
||||
auto *image_effect =
|
||||
dynamic_cast<OFX::Host::ImageEffect::ImageEffectPlugin *>(plugin);
|
||||
if (!image_effect) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const QString plugin_id = QString::fromStdString(
|
||||
image_effect->getIdentifier());
|
||||
if (existing_ids.contains(plugin_id)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const auto &contexts = image_effect->getContexts();
|
||||
std::string context = kOfxImageEffectContextFilter;
|
||||
if (!contexts.empty() &&
|
||||
contexts.find(kOfxImageEffectContextFilter) == contexts.end()) {
|
||||
context = *contexts.begin();
|
||||
}
|
||||
|
||||
auto *instance = image_effect->createInstance(context, nullptr);
|
||||
if (!instance) {
|
||||
continue;
|
||||
}
|
||||
|
||||
plugin::PluginNode *plugin_node = new plugin::PluginNode(instance);
|
||||
library_.append(plugin_node);
|
||||
existing_ids.insert(plugin_id);
|
||||
}
|
||||
}
|
||||
|
||||
Node *NodeFactory::CreateFromFactoryIndex(const NodeFactory::InternalID &id)
|
||||
{
|
||||
switch (id) {
|
||||
|
||||
@@ -102,6 +102,7 @@ public:
|
||||
static QString GetNameFromID(const QString &id);
|
||||
|
||||
static Node *CreateFromID(const QString &id);
|
||||
static void RegisterPluginNodes();
|
||||
|
||||
static Node *CreateFromFactoryIndex(const InternalID &id);
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include <QDir>
|
||||
#include <QFileInfo>
|
||||
|
||||
#include "common/Current.h"
|
||||
#include "common/qtutils.h"
|
||||
#include "common/xmlutils.h"
|
||||
#include "core.h"
|
||||
@@ -28,6 +29,8 @@
|
||||
#include "node/color/ociobase/ociobase.h"
|
||||
#include "node/factory.h"
|
||||
#include "node/serializeddata.h"
|
||||
#include "pluginSupport/OliveHost.h"
|
||||
#include "ofxhPluginCache.h"
|
||||
#include "render/diskmanager.h"
|
||||
#include "window/mainwindow/mainwindow.h"
|
||||
|
||||
@@ -95,11 +98,53 @@ void Project::Clear()
|
||||
SerializedData Project::Load(QXmlStreamReader *reader)
|
||||
{
|
||||
SerializedData data;
|
||||
QSet<QString> plugin_paths;
|
||||
|
||||
while (XMLReadNextStartElement(reader)) {
|
||||
if (reader->name() == QStringLiteral("uuid")) {
|
||||
this->SetUuid(QUuid::fromString(reader->readElementText()));
|
||||
|
||||
} else if (reader->name() == QStringLiteral("plugins")) {
|
||||
while (XMLReadNextStartElement(reader)) {
|
||||
if (reader->name() == QStringLiteral("plugin")) {
|
||||
QString bundle_path;
|
||||
QString file_path;
|
||||
XMLAttributeLoop(reader, attr)
|
||||
{
|
||||
if (attr.name() == QStringLiteral("bundle")) {
|
||||
bundle_path = attr.value().toString();
|
||||
} else if (attr.name() == QStringLiteral("file")) {
|
||||
file_path = attr.value().toString();
|
||||
}
|
||||
}
|
||||
|
||||
const QString path = bundle_path.isEmpty()
|
||||
? file_path
|
||||
: bundle_path;
|
||||
if (!path.isEmpty()) {
|
||||
plugin_paths.insert(path);
|
||||
}
|
||||
|
||||
reader->skipCurrentElement();
|
||||
} else {
|
||||
reader->skipCurrentElement();
|
||||
}
|
||||
}
|
||||
|
||||
if (!plugin_paths.isEmpty()) {
|
||||
if (!Current::getInstance().pluginHost() ||
|
||||
!Current::getInstance().pluginCache()) {
|
||||
plugin::loadPlugins(QString());
|
||||
}
|
||||
|
||||
auto *cache = OFX::Host::PluginCache::getPluginCache();
|
||||
for (const QString &path : plugin_paths) {
|
||||
cache->addFileToPath(path.toStdString(), true);
|
||||
}
|
||||
cache->scanPluginFiles();
|
||||
NodeFactory::RegisterPluginNodes();
|
||||
}
|
||||
|
||||
} else if (reader->name() == QStringLiteral("nodes")) {
|
||||
while (XMLReadNextStartElement(reader)) {
|
||||
if (reader->name() == QStringLiteral("node")) {
|
||||
@@ -171,6 +216,65 @@ void Project::Save(QXmlStreamWriter *writer) const
|
||||
writer->writeTextElement(QStringLiteral("uuid"),
|
||||
this->GetUuid().toString());
|
||||
|
||||
QVector<QPair<QString, QMap<QString, QString>>> plugins_to_save;
|
||||
{
|
||||
QSet<QString> seen;
|
||||
for (Node *node : this->nodes()) {
|
||||
auto *plugin = node->getPlugin();
|
||||
if (!plugin) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const std::string id = plugin->getIdentifier();
|
||||
const int major = plugin->getVersionMajor();
|
||||
const int minor = plugin->getVersionMinor();
|
||||
QString bundle_path;
|
||||
QString file_path;
|
||||
if (auto *binary = plugin->getBinary()) {
|
||||
bundle_path = QString::fromStdString(binary->getBundlePath());
|
||||
file_path = QString::fromStdString(binary->getFilePath());
|
||||
}
|
||||
|
||||
const QString key = QStringLiteral("%1|%2|%3|%4|%5")
|
||||
.arg(QString::fromStdString(id))
|
||||
.arg(major)
|
||||
.arg(minor)
|
||||
.arg(bundle_path)
|
||||
.arg(file_path);
|
||||
if (seen.contains(key)) {
|
||||
continue;
|
||||
}
|
||||
seen.insert(key);
|
||||
|
||||
QMap<QString, QString> attrs;
|
||||
attrs.insert(QStringLiteral("id"),
|
||||
QString::fromStdString(id));
|
||||
attrs.insert(QStringLiteral("major"), QString::number(major));
|
||||
attrs.insert(QStringLiteral("minor"), QString::number(minor));
|
||||
if (!bundle_path.isEmpty()) {
|
||||
attrs.insert(QStringLiteral("bundle"), bundle_path);
|
||||
}
|
||||
if (!file_path.isEmpty()) {
|
||||
attrs.insert(QStringLiteral("file"), file_path);
|
||||
}
|
||||
|
||||
plugins_to_save.append({ QString::fromStdString(id), attrs });
|
||||
}
|
||||
}
|
||||
|
||||
if (!plugins_to_save.isEmpty()) {
|
||||
writer->writeStartElement(QStringLiteral("plugins"));
|
||||
for (const auto &entry : plugins_to_save) {
|
||||
writer->writeStartElement(QStringLiteral("plugin"));
|
||||
for (auto it = entry.second.cbegin();
|
||||
it != entry.second.cend(); ++it) {
|
||||
writer->writeAttribute(it.key(), it.value());
|
||||
}
|
||||
writer->writeEndElement();
|
||||
}
|
||||
writer->writeEndElement();
|
||||
}
|
||||
|
||||
if (!this->nodes().isEmpty()) {
|
||||
writer->writeStartElement(QStringLiteral("nodes"));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user