diff --git a/containment.cpp b/containment.cpp index 934b0496d..84352721c 100644 --- a/containment.cpp +++ b/containment.cpp @@ -257,6 +257,7 @@ void Containment::init() if (action) { d->contextActions.insert(trigger, action); action->setParent(this); + action->setContainment(this); } } } @@ -1692,25 +1693,23 @@ void Containment::setContextAction(const QString &trigger, const QString &plugin } if (pluginName.isEmpty()) { cfg.deleteEntry(trigger); - } else { - if (!action) { - action = ContextAction::load(pluginName); - if (action) { - cfg.writeEntry(trigger, pluginName); - d->contextActions.insert(trigger, action); - } else { - //bad plugin... gets removed. is this a feature or a bug? - cfg.deleteEntry(trigger); - } + } else if (action) { + //it already existed, just reload config + if (action->isInitialized()) { + //FIXME make a truly unique config group + KConfigGroup actionConfig = KConfigGroup(&cfg, pluginName); + action->restore(actionConfig); } - + } else { + action = ContextAction::load(pluginName); if (action) { - if (action->isInitialized()) { - //FIXME make a truly unique config group - KConfigGroup actionConfig = KConfigGroup(&cfg, pluginName); - action->restore(actionConfig); - } + cfg.writeEntry(trigger, pluginName); + d->contextActions.insert(trigger, action); action->setParent(this); + action->setContainment(this); + } else { + //bad plugin... gets removed. is this a feature or a bug? + cfg.deleteEntry(trigger); } } diff --git a/contextaction.cpp b/contextaction.cpp index fda1710b6..9cd9ca91b 100644 --- a/contextaction.cpp +++ b/contextaction.cpp @@ -127,9 +127,14 @@ PackageStructure::Ptr ContextAction::packageStructure() return ContextActionPrivate::s_packageStructure; } +void ContextAction::setContainment(Containment *c) +{ + d->containment=c; +} + Containment *ContextAction::containment() { - return qobject_cast(parent()); + return d->containment; } QString ContextAction::name() const @@ -213,6 +218,16 @@ void ContextAction::setConfigurationRequired(bool needsConfig) d->needsConfig = needsConfig; } +bool ContextAction::hasConfigurationInterface() const +{ + return d->hasConfig; +} + +void ContextAction::setHasConfigurationInterface(bool hasConfig) +{ + d->hasConfig = hasConfig; +} + QString ContextAction::eventToString(QEvent *event) { QString trigger; diff --git a/contextaction.h b/contextaction.h index d6575dc57..64d84534d 100644 --- a/contextaction.h +++ b/contextaction.h @@ -178,6 +178,18 @@ class PLASMA_EXPORT ContextAction : public QObject */ bool configurationRequired() const; + /** + * @return true if the contextaction has a config UI + */ + bool hasConfigurationInterface() const; + + /** + * set the containment this contextaction is associated with. + * some plugins may need information from the containment in order to function or be + * configured. + */ + void setContainment(Containment *c); + /** * Turns a mouse or wheel event into a string suitable for a ContextAction * @return the string representation of the event @@ -211,10 +223,15 @@ class PLASMA_EXPORT ContextAction : public QObject * @param needsConfiguring true if the applet needs to be configured, * or false if it doesn't */ - void setConfigurationRequired(bool needsConfiguring); + void setConfigurationRequired(bool needsConfiguring = true); /** - * return the containment the plugin is associated with, if any. + * set whether the contextaction has a config UI + */ + void setHasConfigurationInterface(bool hasConfig = true); + + /** + * @return the containment the plugin is associated with, if any. */ Containment *containment(); diff --git a/private/contextaction_p.h b/private/contextaction_p.h index 07c289278..c0eb1c644 100644 --- a/private/contextaction_p.h +++ b/private/contextaction_p.h @@ -31,20 +31,24 @@ class ContextActionPrivate : public DataEngineConsumer public: ContextActionPrivate(KService::Ptr service, ContextAction *contextAction) : q(contextAction), + containment(0), contextActionDescription(service), initialized(false), - needsConfig(false) + needsConfig(false), + hasConfig(false) { }; static PackageStructure::Ptr s_packageStructure; ContextAction *q; + Containment *containment; KPluginInfo contextActionDescription; Package *package; KServiceAction mode; bool initialized : 1; bool needsConfig : 1; + bool hasConfig : 1; }; } // namespace Plasma