wallpaperPlugins

svn path=/trunk/KDE/kdebase/workspace/; revision=1214674
This commit is contained in:
Aaron J. Seigo 2011-01-15 21:36:52 +00:00 committed by Marco Martin
parent 991badb778
commit 9d934932d4
2 changed files with 36 additions and 5 deletions

View File

@ -39,6 +39,7 @@
#include <Plasma/Containment>
#include <Plasma/Corona>
#include <Plasma/Package>
#include <Plasma/Wallpaper>
#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<KServiceAction> 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);
}

View File

@ -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,