1 /*
2 SPDX-FileCopyrightText: 2007 Matt Broadstone <mbroadst@gmail.com>
3 SPDX-FileCopyrightText: 2007-2011 Aaron Seigo <aseigo@kde.org>
4 SPDX-FileCopyrightText: 2007 Riccardo Iaconelli <riccardo@kde.org>
5 SPDX-FileCopyrightText: 2009 Chani Armitage <chani@kde.org>
6
7 SPDX-License-Identifier: LGPL-2.0-or-later
8 */
9
10 #include "corona.h"
11 #include "private/corona_p.h"
12
13 #include <QDebug>
14 #include <QGuiApplication>
15 #include <QMimeData>
16 #include <QPainter>
17 #include <QScreen>
18 #include <QTimer>
19
20 #include <KLocalizedString>
21 #include <KWindowSystem>
22
23 #include <cmath>
24
25 #include "containment.h"
26 #include "debug_p.h"
27 #include "pluginloader.h"
28 #include "private/applet_p.h"
29 #include "private/containment_p.h"
30 #include "private/timetracker.h"
31
32 #if PLASMA_BUILD_DEPRECATED_SINCE(5, 83)
33 #include "packagestructure.h"
34 #include "private/package_p.h"
35 #endif
36
37 using namespace Plasma;
38
39 namespace Plasma
40 {
Corona(QObject * parent)41 Corona::Corona(QObject *parent)
42 : QObject(parent)
43 , d(new CoronaPrivate(this))
44 {
45 d->init();
46
47 #ifndef NDEBUG
48 if (qEnvironmentVariableIsSet("PLASMA_TRACK_STARTUP")) {
49 new TimeTracker(this);
50 }
51 #endif
52 }
53
~Corona()54 Corona::~Corona()
55 {
56 KConfigGroup trans(KSharedConfig::openConfig(), "PlasmaTransientsConfig");
57 trans.deleteGroup();
58
59 delete d;
60 }
61
62 #if PLASMA_BUILD_DEPRECATED_SINCE(5, 6)
package() const63 Plasma::Package Corona::package() const
64 {
65 return Package(d->package);
66 }
67
setPackage(const Plasma::Package & package)68 void Corona::setPackage(const Plasma::Package &package)
69 {
70 setKPackage(*package.d->internalPackage);
71 Q_EMIT packageChanged(package);
72 }
73 #endif
74
kPackage() const75 KPackage::Package Corona::kPackage() const
76 {
77 return d->package;
78 }
79
setKPackage(const KPackage::Package & package)80 void Corona::setKPackage(const KPackage::Package &package)
81 {
82 d->package = package;
83 Q_EMIT kPackageChanged(package);
84 }
85
saveLayout(const QString & configName) const86 void Corona::saveLayout(const QString &configName) const
87 {
88 KSharedConfigPtr c;
89
90 if (configName.isEmpty() || configName == d->configName) {
91 c = config();
92 } else {
93 c = KSharedConfig::openConfig(configName, KConfig::SimpleConfig);
94 }
95
96 d->saveLayout(c);
97 }
98
exportLayout(KConfigGroup & config,QList<Containment * > containments)99 void Corona::exportLayout(KConfigGroup &config, QList<Containment *> containments)
100 {
101 const auto groupList = config.groupList();
102 for (const QString &group : groupList) {
103 KConfigGroup cg(&config, group);
104 cg.deleteGroup();
105 }
106
107 // temporarily unlock so that removal works
108 Types::ImmutabilityType oldImm = immutability();
109 d->immutability = Types::Mutable;
110
111 KConfigGroup dest(&config, "Containments");
112 KConfigGroup dummy;
113 for (Plasma::Containment *c : std::as_const(containments)) {
114 c->save(dummy);
115 c->config().reparent(&dest);
116
117 // ensure the containment is unlocked
118 // this is done directly because we have to bypass any Types::SystemImmutable checks
119 c->Applet::d->immutability = Types::Mutable;
120 const auto lstApplet = c->applets();
121 for (Applet *a : lstApplet) {
122 a->d->immutability = Types::Mutable;
123 }
124
125 c->destroy();
126 }
127
128 // restore immutability
129 d->immutability = oldImm;
130
131 config.sync();
132 }
133
requestConfigSync()134 void Corona::requestConfigSync()
135 {
136 // constant controlling how long between requesting a configuration sync
137 // and one happening should occur. currently 10 seconds
138 static const int CONFIG_SYNC_TIMEOUT = 10000;
139
140 // TODO: should we check into our immutability before doing this?
141
142 // NOTE: this is a pretty simplistic model: we simply save no more than CONFIG_SYNC_TIMEOUT
143 // after the first time this is called. not much of a heuristic for save points, but
144 // it should at least compress these activities a bit and provide a way for applet
145 // authors to ween themselves from the sync() disease. A more interesting/dynamic
146 // algorithm for determining when to actually sync() to disk might be better, though.
147 if (!d->configSyncTimer->isActive()) {
148 d->configSyncTimer->start(CONFIG_SYNC_TIMEOUT);
149 }
150 }
151
requireConfigSync()152 void Corona::requireConfigSync()
153 {
154 d->syncConfig();
155 }
156
loadLayout(const QString & configName)157 void Corona::loadLayout(const QString &configName)
158 {
159 if (!configName.isEmpty() && configName != d->configName) {
160 // if we have a new config name passed in, then use that as the config file for this Corona
161 d->config = nullptr;
162 d->configName = configName;
163 }
164
165 KConfigGroup conf(config(), QString());
166 if (!config()->groupList().isEmpty()) {
167 d->importLayout(conf, false);
168 } else {
169 loadDefaultLayout();
170 d->notifyContainmentsReady();
171 }
172
173 KConfigGroup cg(config(), "General");
174 setImmutability((Plasma::Types::ImmutabilityType)cg.readEntry("immutability", (int)Plasma::Types::Mutable));
175 }
176
importLayout(const KConfigGroup & conf)177 QList<Plasma::Containment *> Corona::importLayout(const KConfigGroup &conf)
178 {
179 return d->importLayout(conf, true);
180 }
181
182 #if PLASMA_BUILD_DEPRECATED_SINCE(5, 46)
containmentForScreen(int screen) const183 Containment *Corona::containmentForScreen(int screen) const
184 {
185 for (Containment *containment : std::as_const(d->containments)) {
186 if (containment->screen() == screen //
187 && (containment->containmentType() == Plasma::Types::DesktopContainment //
188 || containment->containmentType() == Plasma::Types::CustomContainment)) {
189 return containment;
190 }
191 }
192
193 return nullptr;
194 }
195
containmentForScreen(int screen,const QString & defaultPluginIfNonExistent,const QVariantList & defaultArgs)196 Containment *Corona::containmentForScreen(int screen, const QString &defaultPluginIfNonExistent, const QVariantList &defaultArgs)
197 {
198 return containmentForScreen(screen, QString(), defaultPluginIfNonExistent, defaultArgs);
199 }
200 #endif
201
containmentForScreen(int screen,const QString & activity,const QString & defaultPluginIfNonExistent,const QVariantList & defaultArgs)202 Containment *Corona::containmentForScreen(int screen, const QString &activity, const QString &defaultPluginIfNonExistent, const QVariantList &defaultArgs)
203 {
204 Containment *containment = nullptr;
205
206 for (Containment *cont : std::as_const(d->containments)) {
207 /* clang-format off */
208 if (cont->lastScreen() == screen
209 && (cont->activity().isEmpty() || cont->activity() == activity)
210 && (cont->containmentType() == Plasma::Types::DesktopContainment
211 || cont->containmentType() == Plasma::Types::CustomContainment)) { /* clang-format on */
212 containment = cont;
213 }
214 }
215
216 if (!containment && !defaultPluginIfNonExistent.isEmpty()) {
217 // screen requests are allowed to bypass immutability
218 if (screen >= 0) {
219 Plasma::Types::ImmutabilityType imm = d->immutability;
220 d->immutability = Types::Mutable;
221 containment = d->addContainment(defaultPluginIfNonExistent, defaultArgs, 0, screen, false);
222
223 d->immutability = imm;
224 }
225 }
226
227 if (containment) {
228 containment->setActivity(activity);
229 }
230 return containment;
231 }
232
containmentsForActivity(const QString & activity)233 QList<Containment *> Corona::containmentsForActivity(const QString &activity)
234 {
235 QList<Containment *> conts;
236
237 if (activity.isEmpty()) {
238 return conts;
239 }
240
241 std::copy_if(d->containments.begin(), d->containments.end(), std::back_inserter(conts), [activity](Containment *cont) {
242 return cont->activity() == activity //
243 && (cont->containmentType() == Plasma::Types::DesktopContainment //
244 || cont->containmentType() == Plasma::Types::CustomContainment);
245 });
246
247 return conts;
248 }
249
containmentsForScreen(int screen)250 QList<Containment *> Corona::containmentsForScreen(int screen)
251 {
252 QList<Containment *> conts;
253
254 if (screen < 0) {
255 return conts;
256 }
257
258 std::copy_if(d->containments.begin(), d->containments.end(), std::back_inserter(conts), [screen](Containment *cont) {
259 return cont->lastScreen() == screen //
260 && (cont->containmentType() == Plasma::Types::DesktopContainment //
261 || cont->containmentType() == Plasma::Types::CustomContainment);
262 });
263
264 return conts;
265 }
266
containments() const267 QList<Containment *> Corona::containments() const
268 {
269 return d->containments;
270 }
271
isStartupCompleted() const272 bool Corona::isStartupCompleted() const
273 {
274 return d->containmentsStarting <= 0;
275 }
276
config() const277 KSharedConfigPtr Corona::config() const
278 {
279 if (!d->config) {
280 d->config = KSharedConfig::openConfig(d->configName, KConfig::SimpleConfig);
281 }
282
283 return d->config;
284 }
285
createContainment(const QString & name,const QVariantList & args)286 Containment *Corona::createContainment(const QString &name, const QVariantList &args)
287 {
288 if (d->immutability == Types::Mutable || args.contains(QVariant::fromValue(QStringLiteral("org.kde.plasma:force-create")))) {
289 return d->addContainment(name, args, 0, -1, false);
290 }
291
292 return nullptr;
293 }
294
createContainmentDelayed(const QString & name,const QVariantList & args)295 Containment *Corona::createContainmentDelayed(const QString &name, const QVariantList &args)
296 {
297 if (d->immutability == Types::Mutable) {
298 return d->addContainment(name, args, 0, -1, true);
299 }
300
301 return nullptr;
302 }
303
screenForContainment(const Containment *) const304 int Corona::screenForContainment(const Containment *) const
305 {
306 return -1;
307 }
308
numScreens() const309 int Corona::numScreens() const
310 {
311 return 1;
312 }
313
availableScreenRegion(int id) const314 QRegion Corona::availableScreenRegion(int id) const
315 {
316 return QRegion(screenGeometry(id));
317 }
318
availableScreenRect(int id) const319 QRect Corona::availableScreenRect(int id) const
320 {
321 return screenGeometry(id);
322 }
323
loadDefaultLayout()324 void Corona::loadDefaultLayout()
325 {
326 // Default implementation does nothing
327 }
328
immutability() const329 Types::ImmutabilityType Corona::immutability() const
330 {
331 return d->immutability;
332 }
333
setImmutability(const Types::ImmutabilityType immutable)334 void Corona::setImmutability(const Types::ImmutabilityType immutable)
335 {
336 if (d->immutability == immutable || d->immutability == Types::SystemImmutable) {
337 return;
338 }
339
340 #ifndef NDEBUG
341 // qCDebug(LOG_PLASMA) << "setting immutability to" << immutable;
342 #endif
343 d->immutability = immutable;
344 d->updateContainmentImmutability();
345 // tell non-containments that might care (like plasmaapp or a custom corona)
346 Q_EMIT immutabilityChanged(immutable);
347
348 // update our actions
349 QAction *action = d->actions.action(QStringLiteral("lock widgets"));
350 if (action) {
351 if (d->immutability == Types::SystemImmutable) {
352 action->setEnabled(false);
353 action->setVisible(false);
354 } else {
355 bool unlocked = d->immutability == Types::Mutable;
356 action->setText(unlocked ? i18n("Lock Widgets") : i18n("Unlock Widgets"));
357 action->setIcon(QIcon::fromTheme(unlocked ? QStringLiteral("object-locked") : QStringLiteral("object-unlocked")));
358 action->setEnabled(true);
359 action->setVisible(true);
360 }
361 }
362
363 action = d->actions.action(QStringLiteral("edit mode"));
364 if (action) {
365 switch (d->immutability) {
366 case Types::UserImmutable:
367 action->setEnabled(false);
368 action->setVisible(true);
369 break;
370 case Types::SystemImmutable:
371 action->setEnabled(false);
372 action->setVisible(false);
373 break;
374 case Types::Mutable:
375 default:
376 action->setEnabled(true);
377 action->setVisible(true);
378 break;
379 }
380 }
381
382 if (d->immutability != Types::SystemImmutable) {
383 KConfigGroup cg(config(), "General");
384
385 // we call the dptr member directly for locked since isImmutable()
386 // also checks kiosk and parent containers
387 cg.writeEntry("immutability", (int)d->immutability);
388 requestConfigSync();
389 }
390
391 if (d->immutability != Types::Mutable) {
392 setEditMode(false);
393 }
394 }
395
setEditMode(bool edit)396 void Corona::setEditMode(bool edit)
397 {
398 if (edit == d->editMode || (edit && d->immutability != Plasma::Types::Mutable)) {
399 return;
400 }
401
402 QAction *editAction = d->actions.action(QStringLiteral("edit mode"));
403 if (editAction) {
404 if (edit) {
405 editAction->setText(i18n("Exit Edit Mode"));
406 } else {
407 editAction->setText(i18n("Enter Edit Mode"));
408 }
409 }
410
411 if (!edit) {
412 requireConfigSync();
413 }
414
415 d->editMode = edit;
416 Q_EMIT editModeChanged(edit);
417 }
418
isEditMode() const419 bool Corona::isEditMode() const
420 {
421 return d->editMode;
422 }
423
freeEdges(int screen) const424 QList<Plasma::Types::Location> Corona::freeEdges(int screen) const
425 {
426 QList<Plasma::Types::Location> freeEdges;
427 /* clang-format off */
428 freeEdges << Plasma::Types::TopEdge
429 << Plasma::Types::BottomEdge
430 << Plasma::Types::LeftEdge
431 << Plasma::Types::RightEdge;
432 /* clang-format on */
433
434 const auto containments = this->containments();
435 for (Containment *containment : containments) {
436 if (containment->screen() == screen && freeEdges.contains(containment->location())) {
437 freeEdges.removeAll(containment->location());
438 }
439 }
440
441 return freeEdges;
442 }
443
actions() const444 KActionCollection *Corona::actions() const
445 {
446 return &d->actions;
447 }
448
CoronaPrivate(Corona * corona)449 CoronaPrivate::CoronaPrivate(Corona *corona)
450 : q(corona)
451 , immutability(Types::Mutable)
452 , config(nullptr)
453 , configSyncTimer(new QTimer(corona))
454 , actions(corona)
455 , containmentsStarting(0)
456 {
457 // TODO: make Package path configurable
458
459 if (QCoreApplication::instance()) {
460 configName = QCoreApplication::instance()->applicationName() + QStringLiteral("-appletsrc");
461 } else {
462 configName = QStringLiteral("plasma-appletsrc");
463 }
464 }
465
~CoronaPrivate()466 CoronaPrivate::~CoronaPrivate()
467 {
468 qDeleteAll(containments);
469 }
470
init()471 void CoronaPrivate::init()
472 {
473 desktopDefaultsConfig = KConfigGroup(KSharedConfig::openConfig(package.filePath("defaults")), "Desktop");
474
475 configSyncTimer->setSingleShot(true);
476 QObject::connect(configSyncTimer, SIGNAL(timeout()), q, SLOT(syncConfig()));
477
478 // some common actions
479 actions.setConfigGroup(QStringLiteral("Shortcuts"));
480
481 QAction *lockAction = actions.add<QAction>(QStringLiteral("lock widgets"));
482 QObject::connect(lockAction, SIGNAL(triggered(bool)), q, SLOT(toggleImmutability()));
483 lockAction->setText(i18n("Lock Widgets"));
484 lockAction->setAutoRepeat(true);
485 lockAction->setIcon(QIcon::fromTheme(QStringLiteral("object-locked")));
486 lockAction->setData(Plasma::Types::ControlAction);
487 lockAction->setShortcut(QKeySequence(QStringLiteral("alt+d, l")));
488 lockAction->setShortcutContext(Qt::ApplicationShortcut);
489
490 // fake containment/applet actions
491 KActionCollection *containmentActions = AppletPrivate::defaultActions(q); // containment has to start with applet stuff
492 ContainmentPrivate::addDefaultActions(containmentActions); // now it's really containment
493
494 QAction *editAction = actions.add<QAction>(QStringLiteral("edit mode"));
495 QObject::connect(editAction, &QAction::triggered, q, [this]() {
496 q->setEditMode(!q->isEditMode());
497 });
498 editAction->setText(i18n("Enter Edit Mode"));
499 editAction->setAutoRepeat(true);
500 editAction->setIcon(QIcon::fromTheme(QStringLiteral("document-edit")));
501 editAction->setData(Plasma::Types::ControlAction);
502 editAction->setShortcut(QKeySequence(QStringLiteral("alt+d, e")));
503 editAction->setShortcutContext(Qt::ApplicationShortcut);
504 }
505
toggleImmutability()506 void CoronaPrivate::toggleImmutability()
507 {
508 if (immutability == Types::Mutable) {
509 q->setImmutability(Types::UserImmutable);
510 } else {
511 q->setImmutability(Types::Mutable);
512 }
513 }
514
saveLayout(KSharedConfigPtr cg) const515 void CoronaPrivate::saveLayout(KSharedConfigPtr cg) const
516 {
517 KConfigGroup containmentsGroup(cg, "Containments");
518 for (const Containment *containment : containments) {
519 QString cid = QString::number(containment->id());
520 KConfigGroup containmentConfig(&containmentsGroup, cid);
521 containment->save(containmentConfig);
522 }
523 }
524
updateContainmentImmutability()525 void CoronaPrivate::updateContainmentImmutability()
526 {
527 for (Containment *c : std::as_const(containments)) {
528 // we need to tell each containment that immutability has been altered
529 c->updateConstraints(Types::ImmutableConstraint);
530 }
531 }
532
containmentDestroyed(QObject * obj)533 void CoronaPrivate::containmentDestroyed(QObject *obj)
534 {
535 // we do a static_cast here since it really isn't an Containment by this
536 // point anymore since we are in the qobject dtor. we don't actually
537 // try and do anything with it, we just need the value of the pointer
538 // so this unsafe looking code is actually just fine.
539 Containment *containment = static_cast<Plasma::Containment *>(obj);
540 int index = containments.indexOf(containment);
541
542 if (index > -1) {
543 containments.removeAt(index);
544 q->requestConfigSync();
545 }
546 }
547
syncConfig()548 void CoronaPrivate::syncConfig()
549 {
550 q->config()->sync();
551 Q_EMIT q->configSynced();
552 }
553
addContainment(const QString & name,const QVariantList & args,uint id,int lastScreen,bool delayedInit)554 Containment *CoronaPrivate::addContainment(const QString &name, const QVariantList &args, uint id, int lastScreen, bool delayedInit)
555 {
556 QString pluginName = name;
557 Containment *containment = nullptr;
558 Applet *applet = nullptr;
559
560 // qCDebug(LOG_PLASMA) << "Loading" << name << args << id;
561
562 if (pluginName.isEmpty() || pluginName == QLatin1String("default")) {
563 // default to the desktop containment
564 pluginName = desktopDefaultsConfig.readEntry("Containment", "org.kde.desktopcontainment");
565 }
566
567 bool loadingNull = pluginName == QLatin1String("null");
568 if (!loadingNull) {
569 applet = PluginLoader::self()->loadApplet(pluginName, id, args);
570 containment = dynamic_cast<Containment *>(applet);
571 if (containment) {
572 containment->setParent(q);
573 }
574 }
575
576 if (!containment) {
577 if (!loadingNull) {
578 #ifndef NDEBUG
579 // qCDebug(LOG_PLASMA) << "loading of containment" << name << "failed.";
580 #endif
581 }
582
583 // in case we got a non-Containment from Applet::loadApplet or
584 // a null containment was requested
585 if (applet) {
586 // the applet probably doesn't know what's hit it, so let's pretend it can be
587 // initialized to make assumptions in the applet's dtor safer
588 applet->init();
589 delete applet;
590 }
591 applet = containment = new Containment(q, KPluginMetaData(), QVariantList{QVariant(), QVariant(), id});
592 if (lastScreen >= 0) {
593 containment->d->lastScreen = lastScreen;
594 }
595 // if it's a dummy containment, just say its ui is ready, not blocking the corona
596 applet->updateConstraints(Plasma::Types::UiReadyConstraint);
597
598 // we want to provide something and don't care about the failure to launch
599 containment->setFormFactor(Plasma::Types::Planar);
600 }
601
602 // if this is a new containment, we need to ensure that there are no stale
603 // configuration data around
604 if (id == 0) {
605 KConfigGroup conf(q->config(), "Containments");
606 conf = KConfigGroup(&conf, QString::number(containment->id()));
607 conf.deleteGroup();
608 }
609
610 // make sure the containments are sorted by id
611 auto position = std::lower_bound(containments.begin(), containments.end(), containment, [](Plasma::Containment *c1, Plasma::Containment *c2) {
612 return c1->id() < c2->id();
613 });
614 containments.insert(position, containment);
615
616 QObject::connect(containment, SIGNAL(destroyed(QObject *)), q, SLOT(containmentDestroyed(QObject *)));
617 QObject::connect(containment, &Applet::configNeedsSaving, q, &Corona::requestConfigSync);
618 QObject::connect(containment, &Containment::screenChanged, q, &Corona::screenOwnerChanged);
619
620 if (!delayedInit) {
621 containment->init();
622 KConfigGroup cg = containment->config();
623 containment->restore(cg);
624 containment->updateConstraints(Plasma::Types::StartupCompletedConstraint);
625 containment->save(cg);
626 q->requestConfigSync();
627 containment->flushPendingConstraintsEvents();
628 Q_EMIT q->containmentAdded(containment);
629 // if id = 0 a new containment has been created, not restored
630 if (id == 0) {
631 Q_EMIT q->containmentCreated(containment);
632 }
633 }
634
635 return containment;
636 }
637
importLayout(const KConfigGroup & conf,bool mergeConfig)638 QList<Plasma::Containment *> CoronaPrivate::importLayout(const KConfigGroup &conf, bool mergeConfig)
639 {
640 if (!conf.isValid()) {
641 return QList<Containment *>();
642 }
643
644 QList<Plasma::Containment *> newContainments;
645 QSet<uint> containmentsIds;
646
647 for (Containment *containment : std::as_const(containments)) {
648 containmentsIds.insert(containment->id());
649 }
650
651 KConfigGroup containmentsGroup(&conf, "Containments");
652 QStringList groups = containmentsGroup.groupList();
653 std::sort(groups.begin(), groups.end());
654
655 for (const QString &group : std::as_const(groups)) {
656 KConfigGroup containmentConfig(&containmentsGroup, group);
657
658 if (containmentConfig.entryMap().isEmpty()) {
659 continue;
660 }
661
662 uint cid = group.toUInt();
663 if (containmentsIds.contains(cid)) {
664 cid = ++AppletPrivate::s_maxAppletId;
665 } else if (cid > AppletPrivate::s_maxAppletId) {
666 AppletPrivate::s_maxAppletId = cid;
667 }
668
669 if (mergeConfig) {
670 KConfigGroup realConf(q->config(), "Containments");
671 realConf = KConfigGroup(&realConf, QString::number(cid));
672 // in case something was there before us
673 realConf.deleteGroup();
674 containmentConfig.copyTo(&realConf);
675 }
676
677 // qCDebug(LOG_PLASMA) << "got a containment in the config, trying to make a" << containmentConfig.readEntry("plugin", QString()) << "from" << group;
678 #ifndef NDEBUG
679 // qCDebug(LOG_PLASMA) << "!!{} STARTUP TIME" << QTime().msecsTo(QTime::currentTime()) << "Adding Containment" << containmentConfig.readEntry("plugin",
680 // QString());
681 #endif
682 Containment *c = addContainment(containmentConfig.readEntry("plugin", QString()), QVariantList(), cid, -1);
683 if (!c) {
684 continue;
685 }
686
687 newContainments.append(c);
688 containmentsIds.insert(c->id());
689
690 #ifndef NDEBUG
691 // qCDebug(LOG_PLASMA) << "!!{} STARTUP TIME" << QTime().msecsTo(QTime::currentTime()) << "Restored Containment" << c->pluginName();
692 #endif
693 }
694
695 if (!mergeConfig) {
696 notifyContainmentsReady();
697 }
698
699 return newContainments;
700 }
701
notifyContainmentsReady()702 void CoronaPrivate::notifyContainmentsReady()
703 {
704 containmentsStarting = 0;
705 for (Containment *containment : std::as_const(containments)) {
706 if (!containment->isUiReady() && containment->screen() >= 0) {
707 ++containmentsStarting;
708 QObject::connect(containment, &Plasma::Containment::uiReadyChanged, q, [this](bool ready) {
709 containmentReady(ready);
710 });
711 }
712 }
713
714 if (containmentsStarting <= 0) {
715 Q_EMIT q->startupCompleted();
716 }
717 }
718
containmentReady(bool ready)719 void CoronaPrivate::containmentReady(bool ready)
720 {
721 if (!ready) {
722 return;
723 }
724 --containmentsStarting;
725 if (containmentsStarting <= 0) {
726 Q_EMIT q->startupCompleted();
727 }
728 }
729
730 } // namespace Plasma
731
732 #include "moc_corona.cpp"
733