From f5cc98dc8a2d969aef9bd99d626426c9fa86782f Mon Sep 17 00:00:00 2001 From: Aaron Seigo Date: Thu, 20 Dec 2012 10:47:51 +0100 Subject: [PATCH] make all containment delayed init allows us to remove another method from the public API --- corona.cpp | 65 ++++++++++++++++++++------------------- corona.h | 23 -------------- private/containment_p.cpp | 1 + private/corona_p.h | 7 +++-- 4 files changed, 40 insertions(+), 56 deletions(-) diff --git a/corona.cpp b/corona.cpp index ea6449b42..63c7bf26a 100644 --- a/corona.cpp +++ b/corona.cpp @@ -156,8 +156,8 @@ void Corona::requestConfigSync() // it should at least compress these activities a bit and provide a way for applet // authors to ween themselves from the sync() disease. A more interesting/dynamic // algorithm for determining when to actually sync() to disk might be better, though. - if (!d->configSyncTimer.isActive()) { - d->configSyncTimer.start(CONFIG_SYNC_TIMEOUT); + if (!d->configSyncTimer->isActive()) { + d->configSyncTimer->start(CONFIG_SYNC_TIMEOUT); } } @@ -225,7 +225,7 @@ Containment *Corona::containmentForScreen(int screen, int desktop, // screen requests are allowed to bypass immutability if (screen >= 0 && screen < numScreens() && desktop >= -1 && desktop < KWindowSystem::numberOfDesktops()) { - containment = d->addContainment(defaultPluginIfNonExistent, defaultArgs, 0, false); + containment = d->addContainment(defaultPluginIfNonExistent, defaultArgs, 0); if (containment) { containment->setScreen(screen, desktop); } @@ -259,16 +259,7 @@ KSharedConfigPtr Corona::config() const Containment *Corona::addContainment(const QString &name, const QVariantList &args) { if (d->immutability == Mutable) { - return d->addContainment(name, args, 0, false); - } - - return 0; -} - -Containment *Corona::addContainmentDelayed(const QString &name, const QVariantList &args) -{ - if (d->immutability == Mutable) { - return d->addContainment(name, args, 0, true); + return d->addContainment(name, args, 0); } return 0; @@ -281,7 +272,6 @@ int Corona::numScreens() const QRect Corona::screenGeometry(int id) const { - //This is unreliable, give better implementations in subclasses return qApp->desktop()->screenGeometry(id); } @@ -297,7 +287,6 @@ void Corona::loadDefaultLayout() void Corona::setPreferredToolBoxPlugin(const Containment::Type type, const QString &plugin) { d->toolBoxPlugins[type] = plugin; - //TODO: react to plugin changes on the fly? still don't see the use case (maybe for laptops that become tablets?) } QString Corona::preferredToolBoxPlugin(const Containment::Type type) const @@ -447,6 +436,8 @@ CoronaPrivate::CoronaPrivate(Corona *corona) mimetype("text/x-plasmoidservicename"), defaultContainmentPlugin("desktop"), config(0), + configSyncTimer(new QTimer(corona)), + delayedInitTimer(new QTimer(corona)), actions(corona) { if (QCoreApplication::instance()) { @@ -463,8 +454,11 @@ CoronaPrivate::~CoronaPrivate() void CoronaPrivate::init() { - configSyncTimer.setSingleShot(true); - QObject::connect(&configSyncTimer, SIGNAL(timeout()), q, SLOT(syncConfig())); + delayedInitTimer->setInterval(100); + delayedInitTimer->setSingleShot(true); + QObject::connect(delayedInitTimer, SIGNAL(timeout()), q, SLOT(delayedContainmentInit())); + configSyncTimer->setSingleShot(true); + QObject::connect(configSyncTimer, SIGNAL(timeout()), q, SLOT(syncConfig())); //some common actions actions.setConfigGroup("Shortcuts"); @@ -575,7 +569,7 @@ void CoronaPrivate::syncConfig() emit q->configSynced(); } -Containment *CoronaPrivate::addContainment(const QString &name, const QVariantList &args, uint id, bool delayedInit) +Containment *CoronaPrivate::addContainment(const QString &name, const QVariantList &args, uint id) { QString pluginName = name; Containment *containment = 0; @@ -635,16 +629,8 @@ Containment *CoronaPrivate::addContainment(const QString &name, const QVariantLi applet->d->isContainment = true; applet->d->setIsContainment(true, true); containments.append(containment); - - if (!delayedInit) { - containment->init(); - KConfigGroup cg = containment->config(); - containment->restore(cg); - containment->updateConstraints(Plasma::StartupCompletedConstraint); - containment->save(cg); - q->requestConfigSync(); - containment->flushPendingConstraintsEvents(); - } + containmentsNeedingInit.append(containment); + delayedInitTimer->start(); QObject::connect(containment, SIGNAL(destroyed(QObject*)), q, SLOT(containmentDestroyed(QObject*))); @@ -655,11 +641,28 @@ Containment *CoronaPrivate::addContainment(const QString &name, const QVariantLi QObject::connect(containment, SIGNAL(screenChanged(int,int,Plasma::Containment*)), q, SIGNAL(screenOwnerChanged(int,int,Plasma::Containment*))); - if (!delayedInit) { + return containment; +} + +void CoronaPrivate::delayedContainmentInit() +{ + foreach (QWeakPointer c, containmentsNeedingInit) { + Containment *containment = c.data(); + if (!containment) { + continue; + } + + containment->init(); + KConfigGroup cg = containment->config(); + containment->restore(cg); + containment->updateConstraints(Plasma::StartupCompletedConstraint); + containment->save(cg); + q->requestConfigSync(); + containment->flushPendingConstraintsEvents(); emit q->containmentAdded(containment); } - return containment; + containmentsNeedingInit.clear(); } QList CoronaPrivate::importLayout(const KConfigGroup &conf, bool mergeConfig) @@ -703,7 +706,7 @@ QList CoronaPrivate::importLayout(const KConfigGroup &con #ifndef NDEBUG kDebug() << "!!{} STARTUP TIME" << QTime().msecsTo(QTime::currentTime()) << "Adding Containment" << containmentConfig.readEntry("plugin", QString()); #endif - Containment *c = addContainment(containmentConfig.readEntry("plugin", QString()), QVariantList(), cid, true); + Containment *c = addContainment(containmentConfig.readEntry("plugin", QString()), QVariantList(), cid); if (!c) { continue; } diff --git a/corona.h b/corona.h index 525131d52..b6543b3f3 100644 --- a/corona.h +++ b/corona.h @@ -46,8 +46,6 @@ class PLASMA_EXPORT Corona : public QObject { Q_OBJECT -//typedef QHash > layouts; - public: explicit Corona(QObject * parent = 0); ~Corona(); @@ -101,27 +99,6 @@ public: */ Containment *addContainment(const QString &name, const QVariantList &args = QVariantList()); - /** - * Loads a containment with delayed initialization, primarily useful - * for implementations of loadDefaultLayout. The caller is responsible - * for all initializating, saving and notification of a new containment. - * - * @param name the plugin name for the containment, as given by - * KPluginInfo::pluginName(). If an empty string is passed in, the defalt - * containment plugin will be used (usually DesktopContainment). If the - * string literal "null" is passed in, then no plugin will be loaded and - * a simple Containment object will be created instead. - * @param args argument list to pass to the containment - * - * @return a pointer to the containment on success, or 0 on failure. Failure can - * be caused by the Immutability type being too restrictive, as containments can't be added - * when widgets are locked, or if the requested containment plugin can not be located - * or successfully loaded. - * @see addContainment - **/ - Containment *addContainmentDelayed(const QString &name, - const QVariantList &args = QVariantList()); - /** * Returns the Containment, if any, for a given physical screen and desktop * diff --git a/private/containment_p.cpp b/private/containment_p.cpp index e8e5352f1..40eee17fa 100644 --- a/private/containment_p.cpp +++ b/private/containment_p.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include #include diff --git a/private/corona_p.h b/private/corona_p.h index 4c05c7779..2cd809897 100644 --- a/private/corona_p.h +++ b/private/corona_p.h @@ -45,7 +45,8 @@ public: void updateContainmentImmutability(); void containmentDestroyed(QObject *obj); void syncConfig(); - Containment *addContainment(const QString &name, const QVariantList &args, uint id, bool delayedInit); + Containment *addContainment(const QString &name, const QVariantList &args, uint id); + void delayedContainmentInit(); void offscreenWidgetDestroyed(QObject *); QList importLayout(const KConfigGroup &conf, bool mergeConfig); @@ -57,8 +58,10 @@ public: QString configName; QString defaultContainmentPlugin; KSharedConfigPtr config; - QTimer configSyncTimer; + QTimer *configSyncTimer; + QTimer *delayedInitTimer; QList containments; + QList > containmentsNeedingInit; QHash offscreenWidgets; KActionCollection actions; QMap containmentActionsDefaults;