allow applets to query for their context, update the context via a constraint (we're running out of them!)

svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=848820
This commit is contained in:
Aaron J. Seigo 2008-08-18 14:04:30 +00:00
parent a0a6acb5dc
commit 46ef63168e
6 changed files with 51 additions and 2 deletions

View File

@ -1006,6 +1006,12 @@ Location Applet::location() const
return c ? c->d->location : Plasma::Desktop; return c ? c->d->location : Plasma::Desktop;
} }
QString Applet::context() const
{
Containment *c = containment();
return c->Containment::context();
}
Plasma::AspectRatioMode Applet::aspectRatioMode() const Plasma::AspectRatioMode Applet::aspectRatioMode() const
{ {
return d->aspectRatioMode; return d->aspectRatioMode;
@ -1058,6 +1064,7 @@ void Applet::setHasConfigurationInterface(bool hasInterface)
if (d->hasConfigurationInterface == hasInterface) { if (d->hasConfigurationInterface == hasInterface) {
return; return;
} }
d->hasConfigurationInterface = hasInterface; d->hasConfigurationInterface = hasInterface;
//config action //config action
//TODO respect security when it's implemented (4.2) //TODO respect security when it's implemented (4.2)

View File

@ -240,6 +240,11 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
*/ */
virtual Location location() const; virtual Location location() const;
/**
* Returns the workspace context which the applet is operating in
*/
QString context() const;
/** /**
* @return the preferred aspect ratio mode for placement and resizing * @return the preferred aspect ratio mode for placement and resizing
*/ */

View File

@ -45,6 +45,7 @@
#include <KWindowSystem> #include <KWindowSystem>
#include "animator.h" #include "animator.h"
#include "context.h"
#include "corona.h" #include "corona.h"
#include "svg.h" #include "svg.h"
#include "wallpaper.h" #include "wallpaper.h"
@ -1054,6 +1055,27 @@ Plasma::Wallpaper* Containment::wallpaper() const
return d->wallpaper; return d->wallpaper;
} }
void Containment::setContext(const QString &context)
{
if (d->context != context) {
d->context = context;
Context c;
QStringList contexts = c.contexts();
if (!contexts.contains(context)) {
c.createContext(context);
}
foreach (Applet *a, d->applets) {
a->updateConstraints(ContextConstraint);
}
}
}
QString Containment::context() const
{
return d->context;
}
KActionCollection& ContainmentPrivate::actions() KActionCollection& ContainmentPrivate::actions()
{ {
return static_cast<Applet*>(q)->d->actions; return static_cast<Applet*>(q)->d->actions;

View File

@ -295,6 +295,18 @@ class PLASMA_EXPORT Containment : public Applet
*/ */
Plasma::Wallpaper* wallpaper() const; Plasma::Wallpaper* wallpaper() const;
/**
* Sets the current context
*
* @param context the name of the context; if it doesn't exist in the
* semantic store, it will be created.
*/
void setContext(const QString &context);
/**
* @return the current context associated with this activity
*/
QString context() const;
Q_SIGNALS: Q_SIGNALS:
/** /**

View File

@ -45,7 +45,9 @@ enum Constraint { NoConstraint = 0,
SizeConstraint = 8 /** the size of the applet was changed */, SizeConstraint = 8 /** the size of the applet was changed */,
ImmutableConstraint = 16 /** the immutability (locked) nature of the applet changed */, ImmutableConstraint = 16 /** the immutability (locked) nature of the applet changed */,
StartupCompletedConstraint = 32 /** application startup has completed */, StartupCompletedConstraint = 32 /** application startup has completed */,
AllConstraints = FormFactorConstraint | LocationConstraint | ScreenConstraint | SizeConstraint | ImmutableConstraint ContextConstraint = 64 /** the desktop context has changed */,
AllConstraints = FormFactorConstraint | LocationConstraint | ScreenConstraint |
SizeConstraint | ImmutableConstraint | ContextConstraint
}; };
Q_DECLARE_FLAGS(Constraints, Constraint) Q_DECLARE_FLAGS(Constraints, Constraint)

View File

@ -102,6 +102,7 @@ public:
int screen; int screen;
ToolBox *toolBox; ToolBox *toolBox;
Containment::Type type; Containment::Type type;
QString context;
bool positioning; bool positioning;
bool drawWallpaper; bool drawWallpaper;
}; };