remove references to Context classes, activity stored by id

This commit is contained in:
Aaron Seigo 2011-05-20 09:41:19 +02:00
parent 3ed8a6fad2
commit 5717088b57
3 changed files with 21 additions and 84 deletions

View File

@ -54,7 +54,6 @@
#include "abstracttoolbox.h" #include "abstracttoolbox.h"
#include "animator.h" #include "animator.h"
#include "context.h"
#include "containmentactions.h" #include "containmentactions.h"
#include "containmentactionspluginsconfig.h" #include "containmentactionspluginsconfig.h"
#include "corona.h" #include "corona.h"
@ -331,11 +330,7 @@ void Containment::restore(KConfigGroup &group)
d->lastScreen = group.readEntry("lastScreen", d->lastScreen); d->lastScreen = group.readEntry("lastScreen", d->lastScreen);
d->lastDesktop = group.readEntry("lastDesktop", d->lastDesktop); d->lastDesktop = group.readEntry("lastDesktop", d->lastDesktop);
d->setScreen(group.readEntry("screen", d->screen), group.readEntry("desktop", d->desktop), false); d->setScreen(group.readEntry("screen", d->screen), group.readEntry("desktop", d->desktop), false);
QString activityId = group.readEntry("activityId", QString()); d->activityId = group.readEntry("activityId", QString());
if (!activityId.isEmpty()) {
d->context()->setCurrentActivityId(activityId);
}
setActivity(group.readEntry("activity", QString()));
flushPendingConstraintsEvents(); flushPendingConstraintsEvents();
restoreContents(group); restoreContents(group);
@ -354,13 +349,13 @@ void Containment::restore(KConfigGroup &group)
d->containmentActionsSource = ContainmentPrivate::Local; d->containmentActionsSource = ContainmentPrivate::Local;
cfg = KConfigGroup(&group, "ActionPlugins"); cfg = KConfigGroup(&group, "ActionPlugins");
} else { } else {
QString source = group.readEntry("ActionPluginsSource", QString()); const QString source = group.readEntry("ActionPluginsSource", QString());
if (source == "Global") { if (source == "Global") {
cfg = KConfigGroup(corona()->config(), "ActionPlugins"); cfg = KConfigGroup(corona()->config(), "ActionPlugins");
d->containmentActionsSource = ContainmentPrivate::Global; d->containmentActionsSource = ContainmentPrivate::Global;
} else if (source == "Activity") { } else if (source == "Activity") {
cfg = KConfigGroup(corona()->config(), "Activities"); cfg = KConfigGroup(corona()->config(), "Activities");
cfg = KConfigGroup(&cfg, activityId); cfg = KConfigGroup(&cfg, d->activityId);
cfg = KConfigGroup(&cfg, "ActionPlugins"); cfg = KConfigGroup(&cfg, "ActionPlugins");
d->containmentActionsSource = ContainmentPrivate::Activity; d->containmentActionsSource = ContainmentPrivate::Activity;
} else if (source == "Local") { } else if (source == "Local") {
@ -377,6 +372,7 @@ void Containment::restore(KConfigGroup &group)
group.writeEntry("ActionPluginsSource", "Global"); group.writeEntry("ActionPluginsSource", "Global");
} }
} }
//kDebug() << cfg.keyList(); //kDebug() << cfg.keyList();
if (cfg.exists()) { if (cfg.exists()) {
foreach (const QString &key, cfg.keyList()) { foreach (const QString &key, cfg.keyList()) {
@ -427,9 +423,7 @@ void Containment::save(KConfigGroup &g) const
group.writeEntry("lastDesktop", d->lastDesktop); group.writeEntry("lastDesktop", d->lastDesktop);
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->context()->currentActivity()); group.writeEntry("activityId", d->activityId);
group.writeEntry("activityId", d->context()->currentActivityId());
QMetaObject::invokeMethod(d->toolBox.data(), "save", Q_ARG(KConfigGroup, group)); QMetaObject::invokeMethod(d->toolBox.data(), "save", Q_ARG(KConfigGroup, group));
@ -1991,60 +1985,26 @@ QString Containment::containmentActions(const QString &trigger)
return c ? c->pluginName() : QString(); return c ? c->pluginName() : QString();
} }
void Containment::setActivity(const QString &activity) void Containment::setActivity(const QString &activityId)
{ {
Context *context = d->context(); if (activityId.isEmpty()) {
if (context->currentActivity() != activity) { return;
context->setCurrentActivity(activity);
}
}
void ContainmentPrivate::onContextChanged(Plasma::Context *con)
{
foreach (Applet *a, applets) {
a->updateConstraints(ContextConstraint);
} }
KConfigGroup c = q->config(); d->activityId = activityId;
QString act = con->currentActivityId(); KConfigGroup c = config();
c.writeEntry("activityId", activityId);
//save anything that's been set (boy I hope this avoids overwriting things) if (d->toolBox) {
//FIXME of course if the user sets the name to an empty string we have a bug d->toolBox.data()->update();
//but once we get context retrieving the name as soon as the id is set, this issue should go away
if (!act.isEmpty()) {
c.writeEntry("activityId", act);
}
act = con->currentActivity();
if (!act.isEmpty()) {
c.writeEntry("activity", act);
} }
if (toolBox) { emit configNeedsSaving();
toolBox.data()->update();
}
emit q->configNeedsSaving();
emit q->contextChanged(con);
} }
QString Containment::activity() const QString Containment::activity() const
{ {
return d->context()->currentActivity(); return d->activityId;
}
Context *Containment::context() const
{
return d->context();
}
Context *ContainmentPrivate::context()
{
if (!con) {
con = new Context(q);
q->connect(con, SIGNAL(changed(Plasma::Context*)),
q, SLOT(onContextChanged(Plasma::Context*)));
}
return con;
} }
KActionCollection* ContainmentPrivate::actions() KActionCollection* ContainmentPrivate::actions()
@ -2533,7 +2493,7 @@ KConfigGroup Containment::containmentActionsConfig()
break; break;
case ContainmentPrivate::Activity: case ContainmentPrivate::Activity:
cfg = KConfigGroup(corona()->config(), "Activities"); cfg = KConfigGroup(corona()->config(), "Activities");
cfg = KConfigGroup(&cfg, d->context()->currentActivityId()); cfg = KConfigGroup(&cfg, d->activityId);
cfg = KConfigGroup(&cfg, "ActionPlugins"); cfg = KConfigGroup(&cfg, "ActionPlugins");
break; break;
default: default:

View File

@ -356,23 +356,17 @@ class PLASMA_EXPORT Containment : public Applet
Plasma::Wallpaper *wallpaper() const; Plasma::Wallpaper *wallpaper() const;
/** /**
* Sets the current activity by name * Sets the current activity by id
* *
* @param activity the name of the activity * @param activity the id of the activity
*/ */
void setActivity(const QString &activity); void setActivity(const QString &activityId);
/** /**
* @return the current activity name associated with this containment * @return the current activity id associated with this containment
*/ */
QString activity() const; QString activity() const;
/**
* @return the context for this containment
* @since 4.5
*/
Context* context() const;
/** /**
* Shows the context menu for the containment directly, bypassing Applets * Shows the context menu for the containment directly, bypassing Applets
* altogether. * altogether.
@ -474,11 +468,6 @@ Q_SIGNALS:
*/ */
void configureRequested(Plasma::Containment *containment); void configureRequested(Plasma::Containment *containment);
/**
* The context associated to this containment has changed
*/
void contextChanged(Plasma::Context *context);
public Q_SLOTS: public Q_SLOTS:
/** /**
* Informs the Corona as to what position it is in. This is informational * Informs the Corona as to what position it is in. This is informational
@ -644,7 +633,6 @@ Q_SIGNALS:
Q_PRIVATE_SLOT(d, void showDropZoneDelayed()) Q_PRIVATE_SLOT(d, void showDropZoneDelayed())
Q_PRIVATE_SLOT(d, void checkStatus(Plasma::ItemStatus)) Q_PRIVATE_SLOT(d, void checkStatus(Plasma::ItemStatus))
Q_PRIVATE_SLOT(d, void remoteAppletReady(Plasma::AccessAppletJob *)) Q_PRIVATE_SLOT(d, void remoteAppletReady(Plasma::AccessAppletJob *))
Q_PRIVATE_SLOT(d, void onContextChanged(Plasma::Context *con))
/** /**
* This slot is called when the 'stat' after a job event has finished. * This slot is called when the 'stat' after a job event has finished.
*/ */

View File

@ -56,7 +56,6 @@ public:
lastScreen(-1), lastScreen(-1),
desktop(-1), // all desktops desktop(-1), // all desktops
lastDesktop(-1), lastDesktop(-1),
con(0),
type(Containment::NoContainmentType), type(Containment::NoContainmentType),
showDropZoneDelayTimer(0), showDropZoneDelayTimer(0),
drawWallpaper(true), drawWallpaper(true),
@ -125,16 +124,6 @@ public:
*/ */
void focusApplet(Plasma::Applet *applet); void focusApplet(Plasma::Applet *applet);
/**
* returns the Context for this Containment
*/
Context *context();
/**
* propogates context changes
*/
void onContextChanged(Plasma::Context *con);
/** /**
* Handles dropped/pasted mimetype data * Handles dropped/pasted mimetype data
* @param scenePos scene-relative position * @param scenePos scene-relative position
@ -179,7 +168,7 @@ public:
int desktop; int desktop;
int lastDesktop; int lastDesktop;
QWeakPointer<AbstractToolBox> toolBox; QWeakPointer<AbstractToolBox> toolBox;
Context *con; QString activityId;
Containment::Type type; Containment::Type type;
QHash<KJob*, QPointF> dropPoints; QHash<KJob*, QPointF> dropPoints;
QHash<KJob*, KMenu*> dropMenus; QHash<KJob*, KMenu*> dropMenus;