add activity ID to containment & context

svn path=/trunk/KDE/kdelibs/; revision=1124740
This commit is contained in:
Chani Armitage 2010-05-10 01:43:06 +00:00
parent 20d58299b2
commit a18d89b4d2
4 changed files with 78 additions and 13 deletions

View File

@ -357,6 +357,10 @@ void Containment::restore(KConfigGroup &group)
setFormFactor((Plasma::FormFactor)group.readEntry("formfactor", (int)d->formFactor)); setFormFactor((Plasma::FormFactor)group.readEntry("formfactor", (int)d->formFactor));
//kDebug() << "setScreen from restore"; //kDebug() << "setScreen from restore";
setScreen(group.readEntry("screen", d->screen), group.readEntry("desktop", d->desktop)); setScreen(group.readEntry("screen", d->screen), group.readEntry("desktop", d->desktop));
QString activityId = group.readEntry("activityId", QString());
if (! activityId.isEmpty()) {
setActivityId(activityId);
}
setActivity(group.readEntry("activity", QString())); setActivity(group.readEntry("activity", QString()));
flushPendingConstraintsEvents(); flushPendingConstraintsEvents();
@ -1982,17 +1986,44 @@ void Containment::setActivity(const QString &activity)
} }
} }
void Containment::setActivityId(const QString &activity)
{
Context *context = d->context();
if (context->currentActivityId() != activity) {
context->setCurrentActivityId(activity);
foreach (Applet *a, d->applets) {
a->updateConstraints(ContextConstraint);
}
KConfigGroup c = config();
c.writeEntry("activityId", activity);
if (d->toolBox) {
d->toolBox.data()->update();
}
emit configNeedsSaving();
}
}
QString Containment::activity() const QString Containment::activity() const
{ {
return d->context()->currentActivity(); return d->context()->currentActivity();
} }
QString Containment::activityId() const
{
return d->context()->currentActivityId();
}
Context *ContainmentPrivate::context() Context *ContainmentPrivate::context()
{ {
if (!con) { if (!con) {
con = new Context(q); con = new Context(q);
q->connect(con, SIGNAL(changed(Plasma::Context*)), q->connect(con, SIGNAL(changed(Plasma::Context*)),
q, SIGNAL(contextChanged(Plasma::Context*))); q, SIGNAL(contextChanged(Plasma::Context*)));
q->connect(con, SIGNAL(activityChanged(Plasma::Context*)),
q, SIGNAL(activityNameChanged(Plasma::Context*)));
} }
return con; return con;

View File

@ -342,16 +342,27 @@ class PLASMA_EXPORT Containment : public Applet
/** /**
* Sets the current activity by name * Sets the current activity by name
* *
* @param activity the name of the activity; if it doesn't exist in the * @param activity the name of the activity
* semantic store, it will be created.
*/ */
void setActivity(const QString &activity); void setActivity(const QString &activity);
/** /**
* @return the current activity associated with this activity * @return the current activity name associated with this containment
*/ */
QString activity() const; QString activity() const;
/**
* Sets the current activity by id
*
* @param activity the id of the activity
*/
void setActivityId(const QString &activity);
/**
* @return the current activity id associated with this containment
*/
QString activityId() const;
/** /**
* Shows the context menu for the containment directly, bypassing Applets * Shows the context menu for the containment directly, bypassing Applets
* altogether. * altogether.
@ -448,9 +459,14 @@ class PLASMA_EXPORT Containment : public Applet
void configureRequested(Plasma::Containment *containment); void configureRequested(Plasma::Containment *containment);
/** /**
* The activity associated to this containemnt has changed * The context associated to this containment has changed
*/ */
void contextChanged(Plasma::Context *context); void contextChanged(Plasma::Context *context);
/**
* The activity name for the context associated to this containment has changed
* @since 4.5
*/
void activityNameChanged(Plasma::Context *context);
public Q_SLOTS: public Q_SLOTS:
/** /**

View File

@ -25,7 +25,8 @@ namespace Plasma
class ContextPrivate class ContextPrivate
{ {
public: public:
QString activity; QString activityId;
QString activityName;
}; };
Context::Context(QObject *parent) Context::Context(QObject *parent)
@ -33,6 +34,7 @@ Context::Context(QObject *parent)
d(new ContextPrivate) d(new ContextPrivate)
{ {
//TODO: look up activity in Nepomuk //TODO: look up activity in Nepomuk
//except we can't, because that code is in kdebase.
} }
Context::~Context() Context::~Context()
@ -52,23 +54,33 @@ QStringList Context::listActivities() const
void Context::setCurrentActivity(const QString &name) void Context::setCurrentActivity(const QString &name)
{ {
if (d->activity == name || name.isEmpty()) { if (d->activityName == name || name.isEmpty()) {
return; return;
} }
d->activity = name; d->activityName = name;
emit activityChanged(this); emit activityChanged(this);
emit changed(this); emit changed(this);
const QStringList activities = listActivities();
if (!activities.contains(name)) {
createActivity(name);
}
} }
QString Context::currentActivity() const QString Context::currentActivity() const
{ {
return d->activity; return d->activityName;
}
void Context::setCurrentActivityId(const QString &id)
{
if (d->activityId == id || id.isEmpty()) {
return;
}
d->activityId = id;
emit changed(this);
}
QString Context::currentActivityId() const
{
return d->activityId;
} }
} // namespace Plasma } // namespace Plasma

View File

@ -38,12 +38,18 @@ public:
explicit Context(QObject *parent = 0); explicit Context(QObject *parent = 0);
~Context(); ~Context();
//don't use these two
void createActivity(const QString &name); void createActivity(const QString &name);
QStringList listActivities() const; QStringList listActivities() const;
//activity name
void setCurrentActivity(const QString &name); void setCurrentActivity(const QString &name);
QString currentActivity() const; QString currentActivity() const;
//activity id
void setCurrentActivityId(const QString &id);
QString currentActivityId() const;
//TODO: location //TODO: location
Q_SIGNALS: Q_SIGNALS: