Changeset View
Changeset View
Standalone View
Standalone View
src/plasma/containment.cpp
Show First 20 Lines • Show All 185 Lines • ▼ Show 20 Line(s) | 166 | { | |||
---|---|---|---|---|---|
186 | setImmutability((Types::ImmutabilityType)group.readEntry("immutability", (int)Types::Mutable)); | 186 | setImmutability((Types::ImmutabilityType)group.readEntry("immutability", (int)Types::Mutable)); | ||
187 | 187 | | |||
188 | if (isContainment() && KAuthorized::authorize(QStringLiteral("plasma/containment_actions"))) { | 188 | if (isContainment() && KAuthorized::authorize(QStringLiteral("plasma/containment_actions"))) { | ||
189 | KConfigGroup cfg = KConfigGroup(corona()->config(), "ActionPlugins"); | 189 | KConfigGroup cfg = KConfigGroup(corona()->config(), "ActionPlugins"); | ||
190 | cfg = KConfigGroup(&cfg, QString::number(containmentType())); | 190 | cfg = KConfigGroup(&cfg, QString::number(containmentType())); | ||
191 | 191 | | |||
192 | //qCDebug(LOG_PLASMA) << cfg.keyList(); | 192 | //qCDebug(LOG_PLASMA) << cfg.keyList(); | ||
193 | if (cfg.exists()) { | 193 | if (cfg.exists()) { | ||
194 | foreach (const QString &key, cfg.keyList()) { | 194 | const auto keyList = cfg.keyList(); | ||
195 | for (const QString &key : keyList) { | ||||
195 | //qCDebug(LOG_PLASMA) << "loading" << key; | 196 | //qCDebug(LOG_PLASMA) << "loading" << key; | ||
196 | setContainmentActions(key, cfg.readEntry(key, QString())); | 197 | setContainmentActions(key, cfg.readEntry(key, QString())); | ||
197 | } | 198 | } | ||
198 | } else { //shell defaults | 199 | } else { //shell defaults | ||
199 | KConfigGroup defaultActionsCfg; | 200 | KConfigGroup defaultActionsCfg; | ||
200 | 201 | | |||
201 | switch (d->type) { | 202 | switch (d->type) { | ||
202 | case Plasma::Types::PanelContainment: | 203 | case Plasma::Types::PanelContainment: | ||
203 | /* fall through*/ | 204 | /* fall through*/ | ||
204 | case Plasma::Types::CustomPanelContainment: | 205 | case Plasma::Types::CustomPanelContainment: | ||
205 | defaultActionsCfg = KConfigGroup(KSharedConfig::openConfig(corona()->kPackage().filePath("defaults")), "Panel"); | 206 | defaultActionsCfg = KConfigGroup(KSharedConfig::openConfig(corona()->kPackage().filePath("defaults")), "Panel"); | ||
206 | break; | 207 | break; | ||
207 | case Plasma::Types::DesktopContainment: | 208 | case Plasma::Types::DesktopContainment: | ||
208 | defaultActionsCfg = KConfigGroup(KSharedConfig::openConfig(corona()->kPackage().filePath("defaults")), "Desktop"); | 209 | defaultActionsCfg = KConfigGroup(KSharedConfig::openConfig(corona()->kPackage().filePath("defaults")), "Desktop"); | ||
209 | break; | 210 | break; | ||
210 | default: | 211 | default: | ||
211 | //for any other type of containment, there are no defaults | 212 | //for any other type of containment, there are no defaults | ||
212 | break; | 213 | break; | ||
213 | } | 214 | } | ||
214 | if (defaultActionsCfg.isValid()) { | 215 | if (defaultActionsCfg.isValid()) { | ||
215 | defaultActionsCfg = KConfigGroup(&defaultActionsCfg, "ContainmentActions"); | 216 | defaultActionsCfg = KConfigGroup(&defaultActionsCfg, "ContainmentActions"); | ||
216 | foreach (const QString &key, defaultActionsCfg.keyList()) { | 217 | const auto keyList = defaultActionsCfg.keyList(); | ||
218 | for (const QString &key : keyList) { | ||||
217 | setContainmentActions(key, defaultActionsCfg.readEntry(key, QString())); | 219 | setContainmentActions(key, defaultActionsCfg.readEntry(key, QString())); | ||
218 | } | 220 | } | ||
219 | } | 221 | } | ||
220 | } | 222 | } | ||
221 | } | 223 | } | ||
222 | 224 | | |||
223 | /* | 225 | /* | ||
224 | #ifndef NDEBUG | 226 | #ifndef NDEBUG | ||
Show All 28 Lines | 249 | // group.writeEntry("screen", d->screen); | |||
253 | group.writeEntry("wallpaperplugin", d->wallpaper); | 255 | group.writeEntry("wallpaperplugin", d->wallpaper); | ||
254 | 256 | | |||
255 | saveContents(group); | 257 | saveContents(group); | ||
256 | } | 258 | } | ||
257 | 259 | | |||
258 | void Containment::saveContents(KConfigGroup &group) const | 260 | void Containment::saveContents(KConfigGroup &group) const | ||
259 | { | 261 | { | ||
260 | KConfigGroup applets(&group, "Applets"); | 262 | KConfigGroup applets(&group, "Applets"); | ||
261 | foreach (const Applet *applet, d->applets) { | 263 | for (const Applet *applet : qAsConst(d->applets)) { | ||
262 | KConfigGroup appletConfig(&applets, QString::number(applet->id())); | 264 | KConfigGroup appletConfig(&applets, QString::number(applet->id())); | ||
263 | applet->save(appletConfig); | 265 | applet->save(appletConfig); | ||
264 | } | 266 | } | ||
265 | } | 267 | } | ||
266 | 268 | | |||
267 | void Containment::restoreContents(KConfigGroup &group) | 269 | void Containment::restoreContents(KConfigGroup &group) | ||
268 | { | 270 | { | ||
269 | KConfigGroup applets(&group, "Applets"); | 271 | KConfigGroup applets(&group, "Applets"); | ||
270 | 272 | | |||
271 | //restore the applets ordered by id | 273 | //restore the applets ordered by id | ||
272 | QStringList groups = applets.groupList(); | 274 | QStringList groups = applets.groupList(); | ||
273 | std::sort(groups.begin(), groups.end()); | 275 | std::sort(groups.begin(), groups.end()); | ||
274 | 276 | | |||
275 | // Sort the applet configs in order of geometry to ensure that applets | 277 | // Sort the applet configs in order of geometry to ensure that applets | ||
276 | // are added from left to right or top to bottom for a panel containment | 278 | // are added from left to right or top to bottom for a panel containment | ||
277 | QList<KConfigGroup> appletConfigs; | 279 | QList<KConfigGroup> appletConfigs; | ||
278 | foreach (const QString &appletGroup, groups) { | 280 | for (const QString &appletGroup : qAsConst(groups)) { | ||
279 | //qCDebug(LOG_PLASMA) << "reading from applet group" << appletGroup; | 281 | //qCDebug(LOG_PLASMA) << "reading from applet group" << appletGroup; | ||
280 | KConfigGroup appletConfig(&applets, appletGroup); | 282 | KConfigGroup appletConfig(&applets, appletGroup); | ||
281 | appletConfigs.append(appletConfig); | 283 | appletConfigs.append(appletConfig); | ||
282 | } | 284 | } | ||
283 | std::stable_sort(appletConfigs.begin(), appletConfigs.end(), appletConfigLessThan); | 285 | std::stable_sort(appletConfigs.begin(), appletConfigs.end(), appletConfigLessThan); | ||
284 | 286 | | |||
285 | QMutableListIterator<KConfigGroup> it(appletConfigs); | 287 | QMutableListIterator<KConfigGroup> it(appletConfigs); | ||
286 | while (it.hasNext()) { | 288 | while (it.hasNext()) { | ||
287 | KConfigGroup &appletConfig = it.next(); | 289 | KConfigGroup &appletConfig = it.next(); | ||
288 | int appId = appletConfig.name().toUInt(); | 290 | int appId = appletConfig.name().toUInt(); | ||
289 | QString plugin = appletConfig.readEntry("plugin", QString()); | 291 | QString plugin = appletConfig.readEntry("plugin", QString()); | ||
290 | 292 | | |||
291 | if (plugin.isEmpty()) { | 293 | if (plugin.isEmpty()) { | ||
292 | continue; | 294 | continue; | ||
293 | } | 295 | } | ||
294 | 296 | | |||
295 | d->createApplet(plugin, QVariantList(), appId); | 297 | d->createApplet(plugin, QVariantList(), appId); | ||
296 | } | 298 | } | ||
297 | 299 | | |||
298 | //if there are no applets, none of them is "loading" | 300 | //if there are no applets, none of them is "loading" | ||
299 | if (Containment::applets().isEmpty()) { | 301 | if (Containment::applets().isEmpty()) { | ||
300 | d->appletsUiReady = true; | 302 | d->appletsUiReady = true; | ||
301 | } | 303 | } | ||
302 | foreach (Applet *applet, Containment::applets()) { | 304 | const auto lstApplets = Containment::applets(); | ||
305 | for (Applet *applet : lstApplets) { | ||||
apol: just applets? | |||||
303 | if (!applet->pluginMetaData().isValid()) { | 306 | if (!applet->pluginMetaData().isValid()) { | ||
304 | applet->updateConstraints(Plasma::Types::UiReadyConstraint); | 307 | applet->updateConstraints(Plasma::Types::UiReadyConstraint); | ||
305 | } | 308 | } | ||
306 | } | 309 | } | ||
307 | } | 310 | } | ||
308 | 311 | | |||
309 | Plasma::Types::ContainmentType Containment::containmentType() const | 312 | Plasma::Types::ContainmentType Containment::containmentType() const | ||
310 | { | 313 | { | ||
▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Line(s) | |||||
356 | void Containment::setLocation(Types::Location location) | 359 | void Containment::setLocation(Types::Location location) | ||
357 | { | 360 | { | ||
358 | if (d->location == location) { | 361 | if (d->location == location) { | ||
359 | return; | 362 | return; | ||
360 | } | 363 | } | ||
361 | 364 | | |||
362 | d->location = location; | 365 | d->location = location; | ||
363 | 366 | | |||
364 | foreach (Applet *applet, d->applets) { | 367 | for (Applet *applet : qAsConst(d->applets)) { | ||
365 | applet->updateConstraints(Plasma::Types::LocationConstraint); | 368 | applet->updateConstraints(Plasma::Types::LocationConstraint); | ||
366 | } | 369 | } | ||
367 | 370 | | |||
368 | updateConstraints(Plasma::Types::LocationConstraint); | 371 | updateConstraints(Plasma::Types::LocationConstraint); | ||
369 | 372 | | |||
370 | KConfigGroup c = config(); | 373 | KConfigGroup c = config(); | ||
371 | c.writeEntry("location", (int)location); | 374 | c.writeEntry("location", (int)location); | ||
372 | emit configNeedsSaving(); | 375 | emit configNeedsSaving(); | ||
▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Line(s) | 409 | if (currentContainment && currentContainment != this) { | |||
421 | //change the group to its configloader, if any | 424 | //change the group to its configloader, if any | ||
422 | //FIXME: this is very, very brutal | 425 | //FIXME: this is very, very brutal | ||
423 | if (applet->configScheme()) { | 426 | if (applet->configScheme()) { | ||
424 | const QString oldGroupPrefix = QStringLiteral("Containments") + QString::number(currentContainment->id()) + QStringLiteral("Applets"); | 427 | const QString oldGroupPrefix = QStringLiteral("Containments") + QString::number(currentContainment->id()) + QStringLiteral("Applets"); | ||
425 | const QString newGroupPrefix = QStringLiteral("Containments") + QString::number(id()) + QStringLiteral("Applets"); | 428 | const QString newGroupPrefix = QStringLiteral("Containments") + QString::number(id()) + QStringLiteral("Applets"); | ||
426 | 429 | | |||
427 | applet->configScheme()->setCurrentGroup(applet->configScheme()->currentGroup().replace(0, oldGroupPrefix.length(), newGroupPrefix)); | 430 | applet->configScheme()->setCurrentGroup(applet->configScheme()->currentGroup().replace(0, oldGroupPrefix.length(), newGroupPrefix)); | ||
428 | 431 | | |||
429 | foreach (KConfigSkeletonItem *item, applet->configScheme()->items()) { | 432 | const auto items = applet->configScheme()->items(); | ||
433 | for (KConfigSkeletonItem *item : items) { | ||||
430 | item->setGroup(item->group().replace(0, oldGroupPrefix.length(), newGroupPrefix)); | 434 | item->setGroup(item->group().replace(0, oldGroupPrefix.length(), newGroupPrefix)); | ||
431 | } | 435 | } | ||
432 | } | 436 | } | ||
433 | } else { | 437 | } else { | ||
434 | applet->setParent(this); | 438 | applet->setParent(this); | ||
435 | } | 439 | } | ||
436 | 440 | | |||
437 | //make sure the applets are sorted by id | 441 | //make sure the applets are sorted by id | ||
▲ Show 20 Lines • Show All 166 Lines • Show Last 20 Lines |
just applets?