context API adjustments

svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=857207
This commit is contained in:
Aaron J. Seigo 2008-09-05 00:22:42 +00:00
parent b3b8ac7ee3
commit d89ad4cba0
6 changed files with 44 additions and 15 deletions

View File

@ -1016,10 +1016,11 @@ Location Applet::location() const
return c ? c->d->location : Plasma::Desktop; return c ? c->d->location : Plasma::Desktop;
} }
QString Applet::context() const Context* Applet::context() const
{ {
Containment *c = containment(); Containment *c = containment();
return c->Containment::context(); Q_ASSERT(c);
return c->d->context();
} }
Plasma::AspectRatioMode Applet::aspectRatioMode() const Plasma::AspectRatioMode Applet::aspectRatioMode() const

View File

@ -46,6 +46,7 @@ namespace Plasma
class AppletPrivate; class AppletPrivate;
class Containment; class Containment;
class Context;
class DataEngine; class DataEngine;
class Extender; class Extender;
class ExtenderItem; class ExtenderItem;
@ -245,7 +246,7 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
/** /**
* Returns the workspace context which the applet is operating in * Returns the workspace context which the applet is operating in
*/ */
QString context() const; Context *context() const;
/** /**
* @return the preferred aspect ratio mode for placement and resizing * @return the preferred aspect ratio mode for placement and resizing

View File

@ -277,7 +277,7 @@ void Containment::save(KConfigGroup &g) const
group.writeEntry("screen", d->screen); group.writeEntry("screen", d->screen);
group.writeEntry("formfactor", (int)d->formFactor); group.writeEntry("formfactor", (int)d->formFactor);
group.writeEntry("location", (int)d->location); group.writeEntry("location", (int)d->location);
group.writeEntry("activity", d->activity); group.writeEntry("activity", d->context()->currentActivity());
if (d->wallpaper) { if (d->wallpaper) {
group.writeEntry("wallpaperplugin", d->wallpaper->pluginName()); group.writeEntry("wallpaperplugin", d->wallpaper->pluginName());
@ -1207,13 +1207,9 @@ Plasma::Wallpaper* Containment::wallpaper() const
void Containment::setActivity(const QString &activity) void Containment::setActivity(const QString &activity)
{ {
if (d->activity != activity) { Context *context = d->context();
d->activity = activity; if (context->currentActivity() != activity) {
Context c; context->setCurrentActivity(activity);
QStringList activities = c.listActivities();
if (!activities.contains(activity)) {
c.createActivity(activity);
}
foreach (Applet *a, d->applets) { foreach (Applet *a, d->applets) {
a->updateConstraints(ContextConstraint); a->updateConstraints(ContextConstraint);
@ -1223,7 +1219,16 @@ void Containment::setActivity(const QString &activity)
QString Containment::activity() const QString Containment::activity() const
{ {
return d->activity; return d->context()->currentActivity();
}
Context* ContainmentPrivate::context()
{
if (!con) {
con = new Context(q);
}
return con;
} }
KActionCollection& ContainmentPrivate::actions() KActionCollection& ContainmentPrivate::actions()

View File

@ -25,12 +25,14 @@ namespace Plasma
class ContextPrivate class ContextPrivate
{ {
public: public:
QString activity;
}; };
Context::Context(QObject *parent) Context::Context(QObject *parent)
: QObject(parent), : QObject(parent),
d(new ContextPrivate) d(new ContextPrivate)
{ {
//TODO: look up activity in Nepomuk
} }
Context::~Context() Context::~Context()
@ -49,11 +51,22 @@ QStringList Context::listActivities() const
void Context::setCurrentActivity(const QString &name) void Context::setCurrentActivity(const QString &name)
{ {
if (d->activity == name || name.isEmpty()) {
return;
}
d->activity = name;
emit activityChanged(this);
QStringList activities = listActivities();
if (!activities.contains(name)) {
createActivity(name);
}
} }
QString Context::currentActivity() const QString Context::currentActivity() const
{ {
return QString(); return d->activity;
} }
} // namespace Plasma } // namespace Plasma

View File

@ -44,8 +44,11 @@ public:
void setCurrentActivity(const QString &name); void setCurrentActivity(const QString &name);
QString currentActivity() const; QString currentActivity() const;
//TODO: location
Q_SIGNALS: Q_SIGNALS:
void currentChanged(const QString &); void activityChanged(Plasma::Context *context);
void locationChanged(Plasma::Context *context);
private: private:
ContextPrivate * const d; ContextPrivate * const d;

View File

@ -41,6 +41,7 @@ public:
wallpaper(0), wallpaper(0),
screen(-1), // no screen screen(-1), // no screen
toolBox(0), toolBox(0),
con(0),
type(Containment::NoContainmentType), type(Containment::NoContainmentType),
positioning(false), positioning(false),
drawWallpaper(true) drawWallpaper(true)
@ -92,6 +93,11 @@ public:
*/ */
void focusApplet(Plasma::Applet *applet); void focusApplet(Plasma::Applet *applet);
/**
* returns the Context for this Containment
*/
Context* context();
Containment *q; Containment *q;
FormFactor formFactor; FormFactor formFactor;
Location location; Location location;
@ -101,8 +107,8 @@ public:
QMap<Applet*, AppletHandle*> handles; QMap<Applet*, AppletHandle*> handles;
int screen; int screen;
ToolBox *toolBox; ToolBox *toolBox;
Context *con;
Containment::Type type; Containment::Type type;
QString activity;
bool positioning; bool positioning;
bool drawWallpaper; bool drawWallpaper;
}; };