| 165 | } |
| 166 | |
| 167 | bool ScriptedEffectLoader::loadDeclarativeEffect(const KPluginMetaData &metadata) |
| 168 | { |
| 169 | const QString name = metadata.pluginId(); |
| 170 | QString scriptFile = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QLatin1StringView("kwin-wayland/effects/") + name + QLatin1StringView("/contents/ui/main.qml")); |
| 171 | if (scriptFile.isNull()) { |
| 172 | scriptFile = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QLatin1StringView("kwin/effects/") + name + QLatin1StringView("/contents/ui/main.qml")); |
| 173 | if (scriptFile.isNull()) { |
| 174 | qCWarning(KWIN_CORE) << "Could not locate the effect script"; |
| 175 | return false; |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | QQmlEngine *engine = Scripting::self()->qmlEngine(); |
| 180 | QQmlComponent component(engine); |
| 181 | component.loadUrl(QUrl::fromLocalFile(scriptFile)); |
| 182 | if (component.isError()) { |
| 183 | qCWarning(KWIN_CORE).nospace() << "Failed to load " << scriptFile << ": " << component.errors(); |
| 184 | return false; |
| 185 | } |
| 186 | |
| 187 | QObject *object = component.beginCreate(engine->rootContext()); |
| 188 | auto effect = qobject_cast<ScriptedQuickSceneEffect *>(object); |
| 189 | if (!effect) { |
| 190 | qCDebug(KWIN_CORE) << "Could not initialize scripted effect: " << name; |
| 191 | delete object; |
| 192 | return false; |
| 193 | } |
| 194 | effect->setMetaData(metadata); |
| 195 | component.completeCreate(); |
| 196 | |
| 197 | connect(effect, &Effect::destroyed, this, [this, name]() { |
| 198 | m_loadedEffects.removeAll(name); |
| 199 | }); |
| 200 | |
| 201 | qCDebug(KWIN_CORE) << "Successfully loaded scripted effect: " << name; |
| 202 | Q_EMIT effectLoaded(effect, name); |
| 203 | m_loadedEffects << name; |
| 204 | return true; |
| 205 | } |
| 206 | |
| 207 | void ScriptedEffectLoader::queryAndLoadAll() |
| 208 | { |
nothing calls this directly
no test coverage detected