allow defining what type of widget to return from widgets()

svn path=/trunk/KDE/kdebase/workspace/; revision=1119874
This commit is contained in:
Aaron J. Seigo 2010-04-27 21:13:37 +00:00 committed by Marco Martin
parent 1d60579972
commit 760e0914a0

View File

@ -210,20 +210,22 @@ QScriptValue Containment::addWidget(QScriptContext *context, QScriptEngine *engi
QScriptValue Containment::widgets(QScriptContext *context, QScriptEngine *engine)
{
Q_UNUSED(context)
Containment *c = qobject_cast<Containment*>(context->thisObject().toQObject());
if (!c || !c->d->containment) {
return engine->undefinedValue();
}
const QString widgetType = context->argumentCount() > 0 ? context->argument(0).toString() : QString();
QScriptValue widgets = engine->newArray();
ScriptEngine *env = ScriptEngine::envFor(engine);
int count = 0;
foreach (Plasma::Applet *widget, c->d->containment.data()->applets()) {
widgets.setProperty(count, env->wrap(widget));
++count;
if (widgetType.isEmpty() || widget->pluginName() == widgetType) {
widgets.setProperty(count, env->wrap(widget));
++count;
}
}
widgets.setProperty("length", count);