MCPcopy Create free account
hub / github.com/KDE/kwin / loadDeclarativeEffect

Method loadDeclarativeEffect

src/effect/effectloader.cpp:167–205  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

165}
166
167bool 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
207void ScriptedEffectLoader::queryAndLoadAll()
208{

Callers

nothing calls this directly

Calls 5

selfFunction · 0.85
pluginIdMethod · 0.80
isNullMethod · 0.45
qmlEngineMethod · 0.45
setMetaDataMethod · 0.45

Tested by

no test coverage detected