MCPcopy Create free account
hub / github.com/Sonic-DE/sonic-win / init

Method init

src/scripting/scriptedeffect.cpp:213–296  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

211ScriptedEffect::~ScriptedEffect() = default;
212
213bool ScriptedEffect::init(const QString &effectName, const QString &pathToScript)
214{
215 qRegisterMetaType<QJSValueList>();
216 qRegisterMetaType<QList<KWin::EffectWindow *>>();
217
218 QFile scriptFile(pathToScript);
219 if (!scriptFile.open(QIODevice::ReadOnly)) {
220 qCDebug(KWIN_SCRIPTING) << "Could not open script file: " << pathToScript;
221 return false;
222 }
223 m_effectName = effectName;
224 m_scriptFile = pathToScript;
225
226 // does the effect contain an KConfigXT file?
227 QString kconfigXTFile = QStandardPaths::locate(QStandardPaths::GenericDataLocation, KWIN_DATADIR + QLatin1String("/effects/") + m_effectName + QLatin1String("/contents/config/main.xml"));
228 if (kconfigXTFile.isNull()) {
229 kconfigXTFile = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QLatin1String("kwin/effects/") + m_effectName + QLatin1String("/contents/config/main.xml"));
230 }
231 if (!kconfigXTFile.isNull()) {
232 KConfigGroup cg = QCoreApplication::instance()->property("config").value<KSharedConfigPtr>()->group(QStringLiteral("Effect-%1").arg(m_effectName));
233 QFile xmlFile(kconfigXTFile);
234 m_config = new KConfigLoader(cg, &xmlFile, this);
235 m_config->load();
236 }
237
238 m_engine->installExtensions(QJSEngine::ConsoleExtension);
239
240 QJSValue globalObject = m_engine->globalObject();
241
242 QJSValue effectsObject = m_engine->newQObject(effects);
243 QJSEngine::setObjectOwnership(effects, QJSEngine::CppOwnership);
244 globalObject.setProperty(QStringLiteral("effects"), effectsObject);
245
246 QJSValue selfObject = m_engine->newQObject(this);
247 QJSEngine::setObjectOwnership(this, QJSEngine::CppOwnership);
248 globalObject.setProperty(QStringLiteral("effect"), selfObject);
249
250 globalObject.setProperty(QStringLiteral("Effect"),
251 m_engine->newQMetaObject(&ScriptedEffect::staticMetaObject));
252 globalObject.setProperty(QStringLiteral("KWin"),
253 m_engine->newQMetaObject(&QtScriptWorkspaceWrapper::staticMetaObject));
254 globalObject.setProperty(QStringLiteral("Globals"),
255 m_engine->newQMetaObject(&KWin::staticMetaObject));
256 globalObject.setProperty(QStringLiteral("QEasingCurve"),
257 m_engine->newQMetaObject(&QEasingCurve::staticMetaObject));
258
259 static const QStringList globalProperties{
260 QStringLiteral("animationTime"),
261 QStringLiteral("displayWidth"),
262 QStringLiteral("displayHeight"),
263
264 QStringLiteral("registerShortcut"),
265 QStringLiteral("registerScreenEdge"),
266 QStringLiteral("registerRealtimeScreenEdge"),
267 QStringLiteral("registerTouchScreenEdge"),
268 QStringLiteral("unregisterScreenEdge"),
269 QStringLiteral("unregisterTouchScreenEdge"),
270

Callers 1

createMethod · 0.45

Calls 8

setPropertyMethod · 0.80
openMethod · 0.45
isNullMethod · 0.45
groupMethod · 0.45
propertyMethod · 0.45
loadMethod · 0.45
evaluateMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected