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