From 9d934932d46b9c13ba99a9f82efe4c9a2e07a395 Mon Sep 17 00:00:00 2001 From: "Aaron J. Seigo" Date: Sat, 15 Jan 2011 21:36:52 +0000 Subject: [PATCH] wallpaperPlugins svn path=/trunk/KDE/kdebase/workspace/; revision=1214674 --- scriptengine.cpp | 40 +++++++++++++++++++++++++++++++++++----- scriptengine.h | 1 + 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/scriptengine.cpp b/scriptengine.cpp index e5ed570f1..19aea5fa1 100644 --- a/scriptengine.cpp +++ b/scriptengine.cpp @@ -39,6 +39,7 @@ #include #include #include +#include #include "appinterface.h" #include "containment.h" @@ -479,12 +480,12 @@ QScriptValue ScriptEngine::userDataPath(QScriptContext *context, QScriptEngine * { Q_UNUSED(engine) if (context->argumentCount() == 0) { - return QString(); + return QDir::homePath(); } const QString type = context->argument(0).toString(); if (type.isEmpty()) { - return QString(); + return QDir::homePath(); } if (context->argumentCount() > 1) { @@ -492,9 +493,7 @@ QScriptValue ScriptEngine::userDataPath(QScriptContext *context, QScriptEngine * return KStandardDirs::locateLocal(type.toLatin1(), filename); } - if (type.compare("home", Qt::CaseInsensitive) == 0) { - return QDir::homePath(); - } else if (type.compare("desktop", Qt::CaseInsensitive) == 0) { + if (type.compare("desktop", Qt::CaseInsensitive) == 0) { return KGlobalSettings::desktopPath(); } else if (type.compare("autostart", Qt::CaseInsensitive) == 0) { return KGlobalSettings::autostartPath(); @@ -513,6 +512,36 @@ QScriptValue ScriptEngine::userDataPath(QScriptContext *context, QScriptEngine * return QString(); } +QScriptValue ScriptEngine::wallpaperPlugins(QScriptContext *context, QScriptEngine *engine) +{ + Q_UNUSED(engine) + + QString formFactor; + if (context->argumentCount() > 0) { + formFactor = context->argument(0).toString(); + } + + QString constraint; + if (!formFactor.isEmpty()) { + constraint.append("[X-Plasma-FormFactors] ~~ '").append(formFactor).append("'"); + } + + KService::List services = KServiceTypeTrader::self()->query("Plasma/Wallpaper", constraint); + QScriptValue rv = engine->newArray(services.size()); + foreach (const KService::Ptr service, services) { + QList modeActions = service->actions(); + QScriptValue modes = engine->newArray(modeActions.size()); + int i = 0; + foreach (const KServiceAction &action, modeActions) { + modes.setProperty(i++, action.name()); + } + + rv.setProperty(service->name(), modes); + } + + return rv; +} + void ScriptEngine::setupEngine() { QScriptValue v = globalObject(); @@ -539,6 +568,7 @@ void ScriptEngine::setupEngine() m_scriptSelf.setProperty("defaultApplication", newFunction(ScriptEngine::defaultApplication)); m_scriptSelf.setProperty("userDataPath", newFunction(ScriptEngine::userDataPath)); m_scriptSelf.setProperty("applicationPath", newFunction(ScriptEngine::applicationPath)); + m_scriptSelf.setProperty("wallpaperPlugins", newFunction(ScriptEngine::wallpaperPlugins)); setGlobalObject(m_scriptSelf); } diff --git a/scriptengine.h b/scriptengine.h index 07c9996cd..57394d221 100644 --- a/scriptengine.h +++ b/scriptengine.h @@ -80,6 +80,7 @@ private: static QScriptValue defaultApplication(QScriptContext *context, QScriptEngine *engine); static QScriptValue applicationPath(QScriptContext *context, QScriptEngine *engine); static QScriptValue userDataPath(QScriptContext *context, QScriptEngine *engine); + static QScriptValue wallpaperPlugins(QScriptContext *context, QScriptEngine *engine); // helpers static QScriptValue createContainment(const QString &type, const QString &defautPlugin,