API changes needed for configurable contextmenu.

-setContainment, so that we don't have to try and use the parent any
more.
-hasConfigurationInterface; this should've already been there.
-default values for a couple of functions that I think make sense

svn path=/trunk/KDE/kdelibs/; revision=1012644
This commit is contained in:
Chani Armitage 2009-08-17 22:31:08 +00:00
parent 69365ddada
commit 5070e300f5
4 changed files with 55 additions and 20 deletions

View File

@ -257,6 +257,7 @@ void Containment::init()
if (action) { if (action) {
d->contextActions.insert(trigger, action); d->contextActions.insert(trigger, action);
action->setParent(this); action->setParent(this);
action->setContainment(this);
} }
} }
} }
@ -1692,25 +1693,23 @@ void Containment::setContextAction(const QString &trigger, const QString &plugin
} }
if (pluginName.isEmpty()) { if (pluginName.isEmpty()) {
cfg.deleteEntry(trigger); cfg.deleteEntry(trigger);
} else { } else if (action) {
if (!action) { //it already existed, just reload config
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);
}
}
if (action) {
if (action->isInitialized()) { if (action->isInitialized()) {
//FIXME make a truly unique config group //FIXME make a truly unique config group
KConfigGroup actionConfig = KConfigGroup(&cfg, pluginName); KConfigGroup actionConfig = KConfigGroup(&cfg, pluginName);
action->restore(actionConfig); action->restore(actionConfig);
} }
} else {
action = ContextAction::load(pluginName);
if (action) {
cfg.writeEntry(trigger, pluginName);
d->contextActions.insert(trigger, action);
action->setParent(this); action->setParent(this);
action->setContainment(this);
} else {
//bad plugin... gets removed. is this a feature or a bug?
cfg.deleteEntry(trigger);
} }
} }

View File

@ -127,9 +127,14 @@ PackageStructure::Ptr ContextAction::packageStructure()
return ContextActionPrivate::s_packageStructure; return ContextActionPrivate::s_packageStructure;
} }
void ContextAction::setContainment(Containment *c)
{
d->containment=c;
}
Containment *ContextAction::containment() Containment *ContextAction::containment()
{ {
return qobject_cast<Plasma::Containment*>(parent()); return d->containment;
} }
QString ContextAction::name() const QString ContextAction::name() const
@ -213,6 +218,16 @@ void ContextAction::setConfigurationRequired(bool needsConfig)
d->needsConfig = 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 ContextAction::eventToString(QEvent *event)
{ {
QString trigger; QString trigger;

View File

@ -178,6 +178,18 @@ class PLASMA_EXPORT ContextAction : public QObject
*/ */
bool configurationRequired() const; 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 * Turns a mouse or wheel event into a string suitable for a ContextAction
* @return the string representation of the event * @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, * @param needsConfiguring true if the applet needs to be configured,
* or false if it doesn't * 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(); Containment *containment();

View File

@ -31,20 +31,24 @@ class ContextActionPrivate : public DataEngineConsumer
public: public:
ContextActionPrivate(KService::Ptr service, ContextAction *contextAction) : ContextActionPrivate(KService::Ptr service, ContextAction *contextAction) :
q(contextAction), q(contextAction),
containment(0),
contextActionDescription(service), contextActionDescription(service),
initialized(false), initialized(false),
needsConfig(false) needsConfig(false),
hasConfig(false)
{ {
}; };
static PackageStructure::Ptr s_packageStructure; static PackageStructure::Ptr s_packageStructure;
ContextAction *q; ContextAction *q;
Containment *containment;
KPluginInfo contextActionDescription; KPluginInfo contextActionDescription;
Package *package; Package *package;
KServiceAction mode; KServiceAction mode;
bool initialized : 1; bool initialized : 1;
bool needsConfig : 1; bool needsConfig : 1;
bool hasConfig : 1;
}; };
} // namespace Plasma } // namespace Plasma