From d89ad4cba0a836462698aa2258d9436f0c0fa0e7 Mon Sep 17 00:00:00 2001 From: "Aaron J. Seigo" Date: Fri, 5 Sep 2008 00:22:42 +0000 Subject: [PATCH] context API adjustments svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=857207 --- applet.cpp | 5 +++-- applet.h | 3 ++- containment.cpp | 23 ++++++++++++++--------- context.cpp | 15 ++++++++++++++- context.h | 5 ++++- private/containment_p.h | 8 +++++++- 6 files changed, 44 insertions(+), 15 deletions(-) diff --git a/applet.cpp b/applet.cpp index 7cea46343..12d25c03f 100644 --- a/applet.cpp +++ b/applet.cpp @@ -1016,10 +1016,11 @@ Location Applet::location() const return c ? c->d->location : Plasma::Desktop; } -QString Applet::context() const +Context* Applet::context() const { Containment *c = containment(); - return c->Containment::context(); + Q_ASSERT(c); + return c->d->context(); } Plasma::AspectRatioMode Applet::aspectRatioMode() const diff --git a/applet.h b/applet.h index ac2166698..a60f8b2c5 100644 --- a/applet.h +++ b/applet.h @@ -46,6 +46,7 @@ namespace Plasma class AppletPrivate; class Containment; +class Context; class DataEngine; class Extender; class ExtenderItem; @@ -245,7 +246,7 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget /** * 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 diff --git a/containment.cpp b/containment.cpp index 402a9607e..0e269fb5c 100644 --- a/containment.cpp +++ b/containment.cpp @@ -277,7 +277,7 @@ void Containment::save(KConfigGroup &g) const group.writeEntry("screen", d->screen); group.writeEntry("formfactor", (int)d->formFactor); group.writeEntry("location", (int)d->location); - group.writeEntry("activity", d->activity); + group.writeEntry("activity", d->context()->currentActivity()); if (d->wallpaper) { group.writeEntry("wallpaperplugin", d->wallpaper->pluginName()); @@ -1207,13 +1207,9 @@ Plasma::Wallpaper* Containment::wallpaper() const void Containment::setActivity(const QString &activity) { - if (d->activity != activity) { - d->activity = activity; - Context c; - QStringList activities = c.listActivities(); - if (!activities.contains(activity)) { - c.createActivity(activity); - } + Context *context = d->context(); + if (context->currentActivity() != activity) { + context->setCurrentActivity(activity); foreach (Applet *a, d->applets) { a->updateConstraints(ContextConstraint); @@ -1223,7 +1219,16 @@ void Containment::setActivity(const QString &activity) 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() diff --git a/context.cpp b/context.cpp index a4e19e30e..8e0601b7d 100644 --- a/context.cpp +++ b/context.cpp @@ -25,12 +25,14 @@ namespace Plasma class ContextPrivate { public: + QString activity; }; Context::Context(QObject *parent) : QObject(parent), d(new ContextPrivate) { + //TODO: look up activity in Nepomuk } Context::~Context() @@ -49,11 +51,22 @@ QStringList Context::listActivities() const 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 { - return QString(); + return d->activity; } } // namespace Plasma diff --git a/context.h b/context.h index e16af37e5..55a89dc07 100644 --- a/context.h +++ b/context.h @@ -44,8 +44,11 @@ public: void setCurrentActivity(const QString &name); QString currentActivity() const; + //TODO: location + Q_SIGNALS: - void currentChanged(const QString &); + void activityChanged(Plasma::Context *context); + void locationChanged(Plasma::Context *context); private: ContextPrivate * const d; diff --git a/private/containment_p.h b/private/containment_p.h index e7d809512..5558d0fe1 100644 --- a/private/containment_p.h +++ b/private/containment_p.h @@ -41,6 +41,7 @@ public: wallpaper(0), screen(-1), // no screen toolBox(0), + con(0), type(Containment::NoContainmentType), positioning(false), drawWallpaper(true) @@ -92,6 +93,11 @@ public: */ void focusApplet(Plasma::Applet *applet); + /** + * returns the Context for this Containment + */ + Context* context(); + Containment *q; FormFactor formFactor; Location location; @@ -101,8 +107,8 @@ public: QMap handles; int screen; ToolBox *toolBox; + Context *con; Containment::Type type; - QString activity; bool positioning; bool drawWallpaper; };