Changeset View
Changeset View
Standalone View
Standalone View
shell/scripting/containment.cpp
Show First 20 Lines • Show All 140 Lines • ▼ Show 20 Line(s) | |||||
141 | 141 | | |||
142 | QList<int> Containment::widgetIds() const | 142 | QList<int> Containment::widgetIds() const | ||
143 | { | 143 | { | ||
144 | //FIXME: the ints could overflow since Applet::id() returns a uint, | 144 | //FIXME: the ints could overflow since Applet::id() returns a uint, | ||
145 | // however QScript deals with QList<uint> very, very poory | 145 | // however QScript deals with QList<uint> very, very poory | ||
146 | QList<int> w; | 146 | QList<int> w; | ||
147 | 147 | | |||
148 | if (d->containment) { | 148 | if (d->containment) { | ||
149 | foreach (const Plasma::Applet *applet, d->containment.data()->applets()) { | 149 | const auto applets = d->containment.data()->applets(); | ||
150 | for (const Plasma::Applet *applet : applets) { | ||||
150 | w.append(applet->id()); | 151 | w.append(applet->id()); | ||
151 | } | 152 | } | ||
152 | } | 153 | } | ||
153 | 154 | | |||
154 | return w; | 155 | return w; | ||
155 | } | 156 | } | ||
156 | 157 | | |||
157 | QJSValue Containment::widgetById(const QJSValue ¶mId) const | 158 | QJSValue Containment::widgetById(const QJSValue ¶mId) const | ||
158 | { | 159 | { | ||
159 | if (!paramId.isNumber()) { | 160 | if (!paramId.isNumber()) { | ||
160 | return d->engine->newError(i18n("widgetById requires an id")); | 161 | return d->engine->newError(i18n("widgetById requires an id")); | ||
161 | } | 162 | } | ||
162 | 163 | | |||
163 | const uint id = paramId.toInt(); | 164 | const uint id = paramId.toInt(); | ||
164 | 165 | | |||
165 | if (d->containment) { | 166 | if (d->containment) { | ||
166 | foreach (Plasma::Applet *w, d->containment.data()->applets()) { | 167 | const auto applets = d->containment.data()->applets(); | ||
168 | for (Plasma::Applet *w : applets) { | ||||
167 | if (w->id() == id) { | 169 | if (w->id() == id) { | ||
168 | return d->engine->wrap(w); | 170 | return d->engine->wrap(w); | ||
169 | } | 171 | } | ||
170 | } | 172 | } | ||
171 | } | 173 | } | ||
172 | 174 | | |||
173 | return QJSValue(); | 175 | return QJSValue(); | ||
174 | } | 176 | } | ||
▲ Show 20 Lines • Show All 50 Lines • ▼ Show 20 Line(s) | |||||
225 | { | 227 | { | ||
226 | if (!d->containment) { | 228 | if (!d->containment) { | ||
227 | return QJSValue(); | 229 | return QJSValue(); | ||
228 | } | 230 | } | ||
229 | 231 | | |||
230 | QJSValue widgets = d->engine->newArray(); | 232 | QJSValue widgets = d->engine->newArray(); | ||
231 | int count = 0; | 233 | int count = 0; | ||
232 | 234 | | |||
233 | foreach (Plasma::Applet *widget, d->containment.data()->applets()) { | 235 | const auto applets = d->containment.data()->applets(); | ||
236 | for (Plasma::Applet *widget : applets) { | ||||
234 | if (widgetType.isEmpty() || widget->pluginMetaData().pluginId() == widgetType) { | 237 | if (widgetType.isEmpty() || widget->pluginMetaData().pluginId() == widgetType) { | ||
235 | widgets.setProperty(count, d->engine->wrap(widget)); | 238 | widgets.setProperty(count, d->engine->wrap(widget)); | ||
236 | ++count; | 239 | ++count; | ||
237 | } | 240 | } | ||
238 | } | 241 | } | ||
239 | 242 | | |||
240 | widgets.setProperty(QStringLiteral("length"), count); | 243 | widgets.setProperty(QStringLiteral("length"), count); | ||
241 | return widgets; | 244 | return widgets; | ||
▲ Show 20 Lines • Show All 51 Lines • Show Last 20 Lines |