make the type property writable (no wonder it wasn't documented on techbase!)

This commit is contained in:
Aaron Seigo 2011-12-22 14:06:11 +01:00 committed by Marco Martin
parent 5362e4e3b6
commit ffeb10641b
2 changed files with 44 additions and 1 deletions

View File

@ -277,6 +277,48 @@ QString Containment::type() const
return d->containment.data()->pluginName();
}
void Containment::setType(const QString &type)
{
if (!d->containment || d->containment.data()->pluginName() == type || type.isEmpty()) {
return;
}
Plasma::Containment *old = d->containment.data();
Plasma::Corona *corona = old->corona();
Plasma::Containment *c = corona->addContainmentDelayed(type);
if (c) {
c->init();
KConfigGroup oldConfig = old->config();
KConfigGroup newConfig = c->config();
// ensure that the old containments configuration is up to date
old->save(oldConfig);
// Copy configuration to new containment
oldConfig.copyTo(&newConfig);
// load the configuration of the old containment into the new one
c->restore(newConfig);
c->updateConstraints(Plasma::StartupCompletedConstraint);
c->flushPendingConstraintsEvents();
foreach (Plasma::Applet *applet, c->applets()) {
applet->init();
// We have to flush the applet constraints manually
applet->flushPendingConstraintsEvents();
}
// destroy the old one
old->destroy(false);
// and now save the config
c->save(newConfig);
corona->requestConfigSync();
d->containment = c;
}
}
void Containment::remove()
{
if (d->containment) {

View File

@ -49,7 +49,7 @@ class PLASMAGENERICSHELL_EXPORT Containment : public Applet
Q_PROPERTY(QString wallpaperPlugin READ wallpaperPlugin WRITE setWallpaperPlugin)
Q_PROPERTY(QString wallpaperMode READ wallpaperMode WRITE setWallpaperMode)
Q_PROPERTY(bool locked READ locked WRITE setLocked)
Q_PROPERTY(QString type READ type)
Q_PROPERTY(QString type READ type WRITE setType)
Q_PROPERTY(QString formFactor READ formFactor)
Q_PROPERTY(QList<int> widgetIds READ widgetIds)
Q_PROPERTY(int screen READ screen WRITE setScreen)
@ -62,6 +62,7 @@ public:
uint id() const;
QString type() const;
void setType(const QString &type);
QString formFactor() const;
QList<int> widgetIds() const;