make all containment delayed init

allows us to remove another method from the public API
This commit is contained in:
Aaron Seigo 2012-12-20 10:47:51 +01:00
parent f413d7c388
commit f5cc98dc8a
4 changed files with 40 additions and 56 deletions

View File

@ -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<Containment> 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<Plasma::Containment *> CoronaPrivate::importLayout(const KConfigGroup &conf, bool mergeConfig)
@ -703,7 +706,7 @@ QList<Plasma::Containment *> 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;
}

View File

@ -46,8 +46,6 @@ class PLASMA_EXPORT Corona : public QObject
{
Q_OBJECT
//typedef QHash<QString, QList<Plasma::Applet*> > 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
*

View File

@ -32,6 +32,7 @@
#include <kaction.h>
#include <kactioncollection.h>
#include <kcoreauthorized.h>
#include <klocale.h>
#include <kurlmimedata.h>
#include <kwindowsystem.h>

View File

@ -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<Plasma::Containment *> importLayout(const KConfigGroup &conf, bool mergeConfig);
@ -57,8 +58,10 @@ public:
QString configName;
QString defaultContainmentPlugin;
KSharedConfigPtr config;
QTimer configSyncTimer;
QTimer *configSyncTimer;
QTimer *delayedInitTimer;
QList<Containment*> containments;
QList<QWeakPointer<Containment> > containmentsNeedingInit;
QHash<uint, QGraphicsWidget*> offscreenWidgets;
KActionCollection actions;
QMap<Containment::Type, ContainmentActionsPluginsConfig> containmentActionsDefaults;