add activity ID to containment & context
svn path=/trunk/KDE/kdelibs/; revision=1124740
This commit is contained in:
parent
20d58299b2
commit
a18d89b4d2
@ -357,6 +357,10 @@ void Containment::restore(KConfigGroup &group)
|
||||
setFormFactor((Plasma::FormFactor)group.readEntry("formfactor", (int)d->formFactor));
|
||||
//kDebug() << "setScreen from restore";
|
||||
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()));
|
||||
|
||||
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
|
||||
{
|
||||
return d->context()->currentActivity();
|
||||
}
|
||||
|
||||
QString Containment::activityId() const
|
||||
{
|
||||
return d->context()->currentActivityId();
|
||||
}
|
||||
|
||||
Context *ContainmentPrivate::context()
|
||||
{
|
||||
if (!con) {
|
||||
con = new Context(q);
|
||||
q->connect(con, SIGNAL(changed(Plasma::Context*)),
|
||||
q, SIGNAL(contextChanged(Plasma::Context*)));
|
||||
q->connect(con, SIGNAL(activityChanged(Plasma::Context*)),
|
||||
q, SIGNAL(activityNameChanged(Plasma::Context*)));
|
||||
}
|
||||
|
||||
return con;
|
||||
|
@ -342,16 +342,27 @@ class PLASMA_EXPORT Containment : public Applet
|
||||
/**
|
||||
* Sets the current activity by name
|
||||
*
|
||||
* @param activity the name of the activity; if it doesn't exist in the
|
||||
* semantic store, it will be created.
|
||||
* @param activity the name of the 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;
|
||||
|
||||
/**
|
||||
* 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
|
||||
* altogether.
|
||||
@ -448,9 +459,14 @@ class PLASMA_EXPORT Containment : public Applet
|
||||
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);
|
||||
/**
|
||||
* The activity name for the context associated to this containment has changed
|
||||
* @since 4.5
|
||||
*/
|
||||
void activityNameChanged(Plasma::Context *context);
|
||||
|
||||
public Q_SLOTS:
|
||||
/**
|
||||
|
30
context.cpp
30
context.cpp
@ -25,7 +25,8 @@ namespace Plasma
|
||||
class ContextPrivate
|
||||
{
|
||||
public:
|
||||
QString activity;
|
||||
QString activityId;
|
||||
QString activityName;
|
||||
};
|
||||
|
||||
Context::Context(QObject *parent)
|
||||
@ -33,6 +34,7 @@ Context::Context(QObject *parent)
|
||||
d(new ContextPrivate)
|
||||
{
|
||||
//TODO: look up activity in Nepomuk
|
||||
//except we can't, because that code is in kdebase.
|
||||
}
|
||||
|
||||
Context::~Context()
|
||||
@ -52,23 +54,33 @@ QStringList Context::listActivities() const
|
||||
|
||||
void Context::setCurrentActivity(const QString &name)
|
||||
{
|
||||
if (d->activity == name || name.isEmpty()) {
|
||||
if (d->activityName == name || name.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
d->activity = name;
|
||||
d->activityName = name;
|
||||
emit activityChanged(this);
|
||||
emit changed(this);
|
||||
|
||||
const QStringList activities = listActivities();
|
||||
if (!activities.contains(name)) {
|
||||
createActivity(name);
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
|
@ -38,12 +38,18 @@ public:
|
||||
explicit Context(QObject *parent = 0);
|
||||
~Context();
|
||||
|
||||
//don't use these two
|
||||
void createActivity(const QString &name);
|
||||
QStringList listActivities() const;
|
||||
|
||||
//activity name
|
||||
void setCurrentActivity(const QString &name);
|
||||
QString currentActivity() const;
|
||||
|
||||
//activity id
|
||||
void setCurrentActivityId(const QString &id);
|
||||
QString currentActivityId() const;
|
||||
|
||||
//TODO: location
|
||||
|
||||
Q_SIGNALS:
|
||||
|
Loading…
Reference in New Issue
Block a user