style: unify identifier naming per updated conventions
Automated with clang-tidy readability-identifier-naming (config added to .clang-tidy) plus scripted passes, per the updated rules now documented in CONTRIBUTING.md: - types (class/struct/enum/alias/template params): PascalCase - functions, variables, members: snake_case (incl. rational -> Rational) - private/protected members: trailing underscore; static member variables likewise (instance_, available_themes_) - constants and enum values: snake_case (kLinear -> k_linear, F32P -> f32p); ALL_CAPS reserved for macros - macros: OAK_ prefix (OLIVE_ADD_TEST/OLIVE_ASSERT/OLIVE_CONFIG -> OAK_ADD_TEST/OAK_ASSERT/OAK_CONFIG, GL_PREAMBLE -> OAK_GL_PREAMBLE, include guards -> OAK_*) - file names: all lowercase (Current/Plugin/OliveHost/OliveClip/ OlivePluginInstance -> current/plugin/olivehost/oliveclip/ oliveplugininstance) - getters share the member name sans underscore, setters set_foo() - Qt and third-party (OpenFX) virtual overrides and framework callbacks keep their original names (exempt in .clang-tidy) Manual follow-ups required where automation could not reach: - string-based QMetaObject/SIGNAL/SLOT references updated to renamed methods (AddTask, CreatedFile, DeleteSpecificFile, moveSelectionUp, ...) - macro bodies referencing renamed methods (OLIVE_CONFIG, NODE_DEFAULT_DESTRUCTOR, MANAGEDDISPLAYWIDGET_*) - self-shadowing locals renamed where signals/methods became same-named (size_changed, worker_count, selected_items, import param, filters) - third_party OFX member/namespace usages restored (OFX::Host::*, _created, _clipPrefsDirty, createInstance, clearPersistentMessage) - STL protocol aliases restored (const_iterator) with .clang-tidy ignore rules; qHash overloads restored Full build and test suite pass: ctest 4/4, ~1960 gtest cases green.
This commit is contained in:
@@ -0,0 +1,286 @@
|
||||
/*
|
||||
* Oak Video Editor - Non-Linear Video Editor
|
||||
* Copyright (C) 2025 Olive CE Team
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "node/project.h"
|
||||
#include "ofxhImageEffect.h"
|
||||
#include <cstddef>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <memory>
|
||||
#include <ofxhPluginCache.h>
|
||||
#include <ofxhBinary.h>
|
||||
|
||||
#include <QApplication>
|
||||
#include <QCoreApplication>
|
||||
#include <QDir>
|
||||
#include "olivehost.h"
|
||||
|
||||
#include "oliveplugininstance.h"
|
||||
#include "common/current.h"
|
||||
#include "ofxMessage.h"
|
||||
#include "version.h"
|
||||
#include <QMessageBox>
|
||||
using namespace OFX::Host;
|
||||
using namespace olive::plugin;
|
||||
|
||||
namespace olive
|
||||
{
|
||||
namespace plugin
|
||||
{
|
||||
class PluginNode;
|
||||
}
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
void add_plugin_path(OFX::Host::PluginCache *cache, const QString &path,
|
||||
bool recurse = true)
|
||||
{
|
||||
if (!cache || path.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
QDir dir(path);
|
||||
if (!dir.exists()) {
|
||||
return;
|
||||
}
|
||||
cache->addFileToPath(dir.canonicalPath().toStdString(), recurse);
|
||||
}
|
||||
|
||||
void add_plugin_paths_from_env(OFX::Host::PluginCache *cache, const char *env_var)
|
||||
{
|
||||
QString raw = qEnvironmentVariable(env_var);
|
||||
if (raw.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
const QChar separator = QDir::listSeparator();
|
||||
const QStringList paths = raw.split(separator, Qt::SkipEmptyParts);
|
||||
for (const QString &path : paths) {
|
||||
add_plugin_path(cache, path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void olive::plugin::load_plugins(QString path)
|
||||
{
|
||||
std::shared_ptr<OliveHost> host = Current::getInstance().plugin_host();
|
||||
std::shared_ptr<ImageEffect::PluginCache> image_effect_plugin_cache =
|
||||
Current::getInstance().plugin_cache();
|
||||
|
||||
if (!host || !image_effect_plugin_cache) {
|
||||
host = std::make_shared<OliveHost>();
|
||||
Current::getInstance().setPluginHost(host);
|
||||
|
||||
image_effect_plugin_cache =
|
||||
std::make_shared<ImageEffect::PluginCache>(*host);
|
||||
Current::getInstance().setPluginCache(image_effect_plugin_cache);
|
||||
|
||||
image_effect_plugin_cache->registerInCache(
|
||||
*OFX::Host::PluginCache::getPluginCache());
|
||||
}
|
||||
OFX::Host::PluginCache *cache = OFX::Host::PluginCache::getPluginCache();
|
||||
cache->setPluginHostPath("Olive");
|
||||
|
||||
const QString home_path = QDir::homePath();
|
||||
add_plugin_path(cache, QDir(home_path).filePath(".OFX/Plugins"));
|
||||
add_plugin_path(cache, QDir(home_path).filePath(".local/share/OFX/Plugins"));
|
||||
add_plugin_path(cache,
|
||||
QDir(home_path).filePath(".local/share/olive/ofx/Plugins"));
|
||||
|
||||
const QString app_dir = QCoreApplication::applicationDirPath();
|
||||
add_plugin_path(cache, QDir(app_dir).filePath("../OFX/Plugins"));
|
||||
add_plugin_path(cache, QDir(app_dir).filePath("../share/olive/ofx/Plugins"));
|
||||
add_plugin_path(cache, QDir(app_dir).filePath("../lib/olive/ofx/Plugins"));
|
||||
|
||||
add_plugin_paths_from_env(cache, "OLIVE_OFX_PLUGIN_PATH");
|
||||
add_plugin_paths_from_env(cache, "OLIVE_PLUGIN_PATH");
|
||||
|
||||
if (!path.isEmpty()) {
|
||||
add_plugin_path(cache, path, true);
|
||||
}
|
||||
cache->scanPluginFiles();
|
||||
}
|
||||
OliveHost::OliveHost()
|
||||
{
|
||||
// Identify the host to plugins; HostSupport seeds these with "UNKNOWN".
|
||||
_properties.setStringProperty(kOfxPropName, "Oak Video Editor");
|
||||
_properties.setStringProperty(kOfxPropLabel, "Oak Video Editor");
|
||||
_properties.setStringProperty(kOfxPropVersionLabel,
|
||||
olive::k_app_version.toStdString());
|
||||
|
||||
// Numeric version for plugins that query kOfxPropVersion directly.
|
||||
const QStringList version_parts =
|
||||
olive::k_app_version.section(QLatin1Char('-'), 0, 0)
|
||||
.split(QLatin1Char('.'));
|
||||
_properties.setIntProperty(kOfxPropVersion,
|
||||
version_parts.value(0).toInt(), 0);
|
||||
_properties.setIntProperty(kOfxPropVersion,
|
||||
version_parts.value(1).toInt(), 1);
|
||||
_properties.setIntProperty(kOfxPropVersion,
|
||||
version_parts.value(2).toInt(), 2);
|
||||
}
|
||||
|
||||
OliveHost::~OliveHost()
|
||||
{
|
||||
}
|
||||
|
||||
void OliveHost::destroy_instance(OFX::Host::ImageEffect::Instance *instance)
|
||||
{
|
||||
if (!instance) {
|
||||
return;
|
||||
}
|
||||
for (auto it = instances_.begin(); it != instances_.end(); ++it) {
|
||||
if (it->get() == instance) {
|
||||
instances_.erase(it);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
std::shared_ptr<OFX::Host::ImageEffect::Descriptor>
|
||||
OliveHost::makeDescriptor(ImageEffect::ImageEffectPlugin *plugin)
|
||||
{
|
||||
std::shared_ptr<OFX::Host::ImageEffect::Descriptor> desc =
|
||||
std::make_shared<ImageEffect::Descriptor>(plugin);
|
||||
descriptors_.append(std::shared_ptr<ImageEffect::Descriptor>(desc));
|
||||
return desc;
|
||||
}
|
||||
std::shared_ptr<OFX::Host::ImageEffect::Descriptor>
|
||||
OliveHost::makeDescriptor(const ImageEffect::Descriptor &root_context,
|
||||
ImageEffect::ImageEffectPlugin *plugin)
|
||||
{
|
||||
std::shared_ptr<OFX::Host::ImageEffect::Descriptor> desc =
|
||||
std::make_shared<ImageEffect::Descriptor>(root_context, plugin);
|
||||
descriptors_.append(std::shared_ptr<ImageEffect::Descriptor>(desc));
|
||||
return desc;
|
||||
}
|
||||
std::shared_ptr<OFX::Host::ImageEffect::Descriptor>
|
||||
OliveHost::makeDescriptor(const std::string &bundle_path,
|
||||
ImageEffect::ImageEffectPlugin *plugin)
|
||||
{
|
||||
std::shared_ptr<OFX::Host::ImageEffect::Descriptor> desc =
|
||||
std::make_shared<ImageEffect::Descriptor>(bundle_path, plugin);
|
||||
descriptors_.append(std::shared_ptr<ImageEffect::Descriptor>(desc));
|
||||
return desc;
|
||||
}
|
||||
|
||||
ImageEffect::Instance *
|
||||
OliveHost::newInstance(void *client_data, ImageEffect::ImageEffectPlugin *plugin,
|
||||
ImageEffect::Descriptor &desc,
|
||||
const std::string &context)
|
||||
{
|
||||
auto *instance = new OlivePluginInstance(
|
||||
plugin, desc, context, Current::getInstance().interactive());
|
||||
if (client_data) {
|
||||
auto *node = static_cast<PluginNode *>(client_data);
|
||||
instance->setNode(
|
||||
std::shared_ptr<PluginNode>(node, [](PluginNode *) {}));
|
||||
}
|
||||
instances_.append(std::shared_ptr<OlivePluginInstance>(instance));
|
||||
return instance;
|
||||
};
|
||||
OfxStatus olive::plugin::OliveHost::vmessage(const char *type, const char *id,
|
||||
const char *format, va_list args)
|
||||
{
|
||||
if (!type || !format) {
|
||||
return kOfxStatFailed;
|
||||
}
|
||||
|
||||
char buffer[1024];
|
||||
buffer[0] = '\0';
|
||||
vsnprintf(buffer, sizeof(buffer), format, args);
|
||||
QString message(buffer);
|
||||
|
||||
auto *app = qobject_cast<QApplication *>(QCoreApplication::instance());
|
||||
// A modal dialog would hang a headless (offscreen) session, so log to
|
||||
// stderr instead of showing one.
|
||||
if (!app || QGuiApplication::platformName() == QLatin1String("offscreen")) {
|
||||
qWarning().noquote() << "OFX message:" << type << message;
|
||||
if (strcmp(type, kOfxMessageQuestion) == 0) {
|
||||
return kOfxStatReplyNo;
|
||||
}
|
||||
return kOfxStatOK;
|
||||
}
|
||||
|
||||
if (strcmp(type, kOfxMessageQuestion) == 0) {
|
||||
auto ret = QMessageBox::question(nullptr, "", message, QMessageBox::Ok,
|
||||
QMessageBox::Cancel);
|
||||
return (ret == QMessageBox::Ok) ? kOfxStatReplyYes : kOfxStatReplyNo;
|
||||
}
|
||||
|
||||
if (strcmp(type, kOfxMessageError) == 0) {
|
||||
QMessageBox::critical(nullptr, "", message);
|
||||
} else if (strcmp(type, kOfxMessageWarning) == 0) {
|
||||
QMessageBox::warning(nullptr, "", message);
|
||||
} else {
|
||||
QMessageBox::information(nullptr, "", message);
|
||||
}
|
||||
|
||||
return kOfxStatOK;
|
||||
}
|
||||
// TODO: Persistent messages shouldn't use pop-up window.
|
||||
OfxStatus olive::plugin::OliveHost::setPersistentMessage(const char *type,
|
||||
const char *id,
|
||||
const char *format,
|
||||
va_list args)
|
||||
{
|
||||
if (!type || !format) {
|
||||
return kOfxStatFailed;
|
||||
}
|
||||
|
||||
char buffer[1024];
|
||||
buffer[0] = '\0';
|
||||
vsnprintf(buffer, sizeof(buffer), format, args);
|
||||
QString message(buffer);
|
||||
|
||||
// A modal dialog would hang a headless (offscreen) session, so log to
|
||||
// stderr instead of showing one.
|
||||
const bool headless =
|
||||
QGuiApplication::platformName() == QLatin1String("offscreen");
|
||||
|
||||
if (strcmp(type, kOfxMessageError) == 0) {
|
||||
persistent_messages_.append({ HostMessageType::error, message });
|
||||
if (headless) {
|
||||
qWarning().noquote() << "OFX error:" << message;
|
||||
} else {
|
||||
QMessageBox::critical(nullptr, "", message);
|
||||
}
|
||||
} else if (strcmp(type, kOfxMessageWarning) == 0) {
|
||||
persistent_messages_.append({ HostMessageType::warning, message });
|
||||
if (headless) {
|
||||
qWarning().noquote() << "OFX warning:" << message;
|
||||
} else {
|
||||
QMessageBox::warning(nullptr, "", message);
|
||||
}
|
||||
} else if (strcmp(type, kOfxMessageMessage) == 0) {
|
||||
persistent_messages_.append({ HostMessageType::message, message });
|
||||
if (headless) {
|
||||
qWarning().noquote() << "OFX message:" << message;
|
||||
} else {
|
||||
QMessageBox::information(nullptr, "", message);
|
||||
}
|
||||
} else {
|
||||
return kOfxStatFailed;
|
||||
}
|
||||
|
||||
return kOfxStatOK;
|
||||
}
|
||||
|
||||
OfxStatus olive::plugin::OliveHost::clearPersistentMessage()
|
||||
{
|
||||
persistent_messages_.clear();
|
||||
return kOfxStatOK;
|
||||
}
|
||||
Reference in New Issue
Block a user