API reviews:

checkImmutability()->Q_PRIVATE_SLOT
added a q-pointer into Applet needed for this and themeChanged the other
Q_PRIVATE_SLOT that will be added

svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=802124
This commit is contained in:
Marco Martin 2008-04-28 15:41:18 +00:00
parent e985e96129
commit 48be92bdab
2 changed files with 42 additions and 44 deletions

View File

@ -100,8 +100,9 @@ protected:
class Applet::Private class Applet::Private
{ {
public: public:
Private(KService::Ptr service, int uniqueID) Private(KService::Ptr service, int uniqueID, Applet *applet)
: appletId(uniqueID), : appletId(uniqueID),
q(applet),
backgroundHints(StandardBackground), backgroundHints(StandardBackground),
appletDescription(service), appletDescription(service),
package(0), package(0),
@ -141,15 +142,15 @@ public:
delete mainConfig; delete mainConfig;
} }
void init(Applet* applet) void init()
{ {
// WARNING: do not access config() OR globalConfig() in this method! // WARNING: do not access config() OR globalConfig() in this method!
// that requires a scene, which is not available at this point // that requires a scene, which is not available at this point
applet->setAcceptsHoverEvents(true); q->setAcceptsHoverEvents(true);
applet->setFlag(QGraphicsItem::ItemIsFocusable, true); q->setFlag(QGraphicsItem::ItemIsFocusable, true);
if (!appletDescription.isValid()) { if (!appletDescription.isValid()) {
applet->setFailedToLaunch(true, i18n("Invalid applet description")); q->setFailedToLaunch(true, i18n("Invalid applet description"));
return; return;
} }
@ -163,7 +164,7 @@ public:
"/"); "/");
if (path.isEmpty()) { if (path.isEmpty()) {
applet->setFailedToLaunch(true, i18n("Could not locate the %1 package required for the %2 widget.", q->setFailedToLaunch(true, i18n("Could not locate the %1 package required for the %2 widget.",
appletDescription.pluginName(), appletDescription.name())); appletDescription.pluginName(), appletDescription.name()));
} else { } else {
// create the package and see if we have something real // create the package and see if we have something real
@ -177,48 +178,49 @@ public:
// it will be parented to this applet and so will get // it will be parented to this applet and so will get
// deleted when the applet does // deleted when the applet does
script = Plasma::loadScriptEngine(language, applet); script = Plasma::loadScriptEngine(language, q);
if (!script) { if (!script) {
delete package; delete package;
package = 0; package = 0;
applet->setFailedToLaunch(true, i18n("Could not create a %1 ScriptEngine for the %2 widget.", q->setFailedToLaunch(true, i18n("Could not create a %1 ScriptEngine for the %2 widget.",
language, appletDescription.name())); language, appletDescription.name()));
} }
} else { } else {
applet->setFailedToLaunch(true, i18n("Could not open the %1 package required for the %2 widget.", q->setFailedToLaunch(true, i18n("Could not open the %1 package required for the %2 widget.",
appletDescription.pluginName(), appletDescription.name())); appletDescription.pluginName(), appletDescription.name()));
delete package; delete package;
package = 0; package = 0;
} }
if (package) { if (package) {
setupScriptSupport(applet); setupScriptSupport();
} }
} }
} }
applet->setBackgroundHints(DefaultBackground); q->setBackgroundHints(DefaultBackground);
connect(Plasma::Theme::defaultTheme(), SIGNAL(themeChanged()), applet, SLOT(themeChanged())); connect(Plasma::Theme::defaultTheme(), SIGNAL(themeChanged()), q, SLOT(themeChanged()));
} }
// put all setup routines for script here. at this point we can assume that // put all setup routines for script here. at this point we can assume that
// package exists and that we have a script engin // package exists and that we have a script engin
void setupScriptSupport(Applet* applet) void setupScriptSupport()
{ {
Q_ASSERT(package); Q_ASSERT(package);
QString xmlPath = package->filePath("mainconfigxml"); QString xmlPath = package->filePath("mainconfigxml");
if (!xmlPath.isEmpty()) { if (!xmlPath.isEmpty()) {
QFile file(xmlPath); QFile file(xmlPath);
// FIXME: KConfigSkeleton doesn't play well with KConfigGroup =/ // FIXME: KConfigSkeleton doesn't play well with KConfigGroup =/
KConfigGroup config = applet->config(); KConfigGroup config = q->config();
configXml = new ConfigXml(&config, &file); configXml = new ConfigXml(&config, &file);
} }
if (!package->filePath("mainconfigui").isEmpty()) { if (!package->filePath("mainconfigui").isEmpty()) {
applet->setHasConfigurationInterface(true); q->setHasConfigurationInterface(true);
} }
} }
QString instanceName() QString instanceName()
{ {
if (!appletDescription.isValid()) { if (!appletDescription.isValid()) {
@ -240,15 +242,15 @@ public:
} }
} }
void scheduleConstraintsUpdate(Plasma::Constraints c, Applet* applet) void scheduleConstraintsUpdate(Plasma::Constraints c)
{ {
if (pendingConstraints == NoConstraint) { if (pendingConstraints == NoConstraint) {
QTimer::singleShot(0, applet, SLOT(flushPendingConstraintsEvents())); QTimer::singleShot(0, q, SLOT(flushPendingConstraintsEvents()));
} }
pendingConstraints |= c; pendingConstraints |= c;
} }
KConfigGroup* mainConfigGroup(const Applet* q) KConfigGroup* mainConfigGroup()
{ {
if (mainConfig) { if (mainConfig) {
return mainConfig; return mainConfig;
@ -312,6 +314,17 @@ public:
return text; return text;
} }
void checkImmutability()
{
const bool systemImmutable = q->globalConfig().isImmutable() || q->config().isImmutable() ||
(q->containment() && q->containment()->immutability() == SystemImmutable) ||
(dynamic_cast<Corona*>(q->scene()) && static_cast<Corona*>(q->scene())->immutability() == SystemImmutable);
if (systemImmutable) {
q->updateConstraints(ImmutableConstraint);
}
}
//TODO: examine the usage of memory here; there's a pretty large //TODO: examine the usage of memory here; there's a pretty large
// number of members at this point. // number of members at this point.
static uint s_maxAppletId; static uint s_maxAppletId;
@ -319,6 +332,7 @@ public:
static uint s_minZValue; static uint s_minZValue;
static PackageStructure::Ptr packageStructure; static PackageStructure::Ptr packageStructure;
uint appletId; uint appletId;
Applet *q;
BackgroundHints backgroundHints; BackgroundHints backgroundHints;
KPluginInfo appletDescription; KPluginInfo appletDescription;
Package* package; Package* package;
@ -351,22 +365,22 @@ Applet::Applet(QGraphicsItem *parent,
const QString& serviceID, const QString& serviceID,
uint appletId) uint appletId)
: QGraphicsWidget(parent), : QGraphicsWidget(parent),
d(new Private(KService::serviceByStorageId(serviceID), appletId)) d(new Private(KService::serviceByStorageId(serviceID), appletId, this))
{ {
// WARNING: do not access config() OR globalConfig() in this method! // WARNING: do not access config() OR globalConfig() in this method!
// that requires a scene, which is not available at this point // that requires a scene, which is not available at this point
d->init(this); d->init();
} }
Applet::Applet(QObject* parentObject, const QVariantList& args) Applet::Applet(QObject* parentObject, const QVariantList& args)
: QGraphicsWidget(0), : QGraphicsWidget(0),
d(new Private(KService::serviceByStorageId(args.count() > 0 ? args[0].toString() : QString()), d(new Private(KService::serviceByStorageId(args.count() > 0 ? args[0].toString() : QString()),
args.count() > 1 ? args[1].toInt() : 0)) args.count() > 1 ? args[1].toInt() : 0, this))
{ {
setParent(parentObject); setParent(parentObject);
// WARNING: do not access config() OR globalConfig() in this method! // WARNING: do not access config() OR globalConfig() in this method!
// that requires a scene, which is not available at this point // that requires a scene, which is not available at this point
d->init(this); d->init();
// the brain damage seen in the initialization list is due to the // the brain damage seen in the initialization list is due to the
// inflexibility of KService::createInstance // inflexibility of KService::createInstance
@ -512,10 +526,10 @@ KConfigGroup Applet::config(const QString &group) const
KConfigGroup Applet::config() const KConfigGroup Applet::config() const
{ {
if (d->isContainment) { if (d->isContainment) {
return *(d->mainConfigGroup(this)); return *(d->mainConfigGroup());
} }
return KConfigGroup(d->mainConfigGroup(this), "Configuration"); return KConfigGroup(d->mainConfigGroup(), "Configuration");
} }
KConfigGroup Applet::globalConfig() const KConfigGroup Applet::globalConfig() const
@ -547,7 +561,7 @@ void Applet::destroy()
void Applet::resetConfigurationObject() void Applet::resetConfigurationObject()
{ {
d->mainConfigGroup(this)->deleteGroup(); d->mainConfigGroup()->deleteGroup();
delete d->mainConfig; delete d->mainConfig;
d->mainConfig = 0; d->mainConfig = 0;
} }
@ -664,7 +678,7 @@ QPoint Applet::popupPosition(const QSize &s) const
void Applet::updateConstraints(Plasma::Constraints constraints) void Applet::updateConstraints(Plasma::Constraints constraints)
{ {
d->scheduleConstraintsUpdate(constraints, this); d->scheduleConstraintsUpdate(constraints);
} }
void Applet::constraintsEvent(Plasma::Constraints constraints) void Applet::constraintsEvent(Plasma::Constraints constraints)
@ -891,17 +905,6 @@ void Applet::setNeedsConfiguring(bool needsConfig)
d->needsConfigOverlay->show(); d->needsConfigOverlay->show();
} }
void Applet::checkImmutability()
{
const bool systemImmutable = globalConfig().isImmutable() || config().isImmutable() ||
(containment() && containment()->immutability() == SystemImmutable) ||
(dynamic_cast<Corona*>(scene()) && static_cast<Corona*>(scene())->immutability() == SystemImmutable);
if (systemImmutable) {
updateConstraints(ImmutableConstraint);
}
}
void Applet::flushPendingConstraintsEvents() void Applet::flushPendingConstraintsEvents()
{ {
if (d->pendingConstraints == NoConstraint) { if (d->pendingConstraints == NoConstraint) {
@ -1392,7 +1395,7 @@ QVariant Applet::itemChange(GraphicsItemChange change, const QVariant &value)
case ItemSceneHasChanged: { case ItemSceneHasChanged: {
QGraphicsScene *newScene = qvariant_cast<QGraphicsScene*>(value); QGraphicsScene *newScene = qvariant_cast<QGraphicsScene*>(value);
if (newScene) { if (newScene) {
checkImmutability(); d->checkImmutability();
} }
if (d->shadow) { if (d->shadow) {

View File

@ -690,14 +690,9 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
*/ */
QVariant itemChange(GraphicsItemChange change, const QVariant &value); QVariant itemChange(GraphicsItemChange change, const QVariant &value);
protected Q_SLOTS:
/**
* @internal used to check the immutability of the item in the config file
*/
void checkImmutability();
private: private:
Q_DISABLE_COPY(Applet) Q_DISABLE_COPY(Applet)
Q_PRIVATE_SLOT(d, void checkImmutability())
/** /**
* Reimplemented from QGraphicsItem * Reimplemented from QGraphicsItem