give proper control over saving/restoring to the containment
svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=811211
This commit is contained in:
parent
73c4847a75
commit
26f7e83a53
53
applet.cpp
53
applet.cpp
@ -135,42 +135,42 @@ uint Applet::id() const
|
|||||||
return d->appletId;
|
return d->appletId;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Applet::save(KConfigGroup* group) const
|
void Applet::save(KConfigGroup &group) const
|
||||||
{
|
{
|
||||||
// we call the dptr member directly for locked since isImmutable()
|
// we call the dptr member directly for locked since isImmutable()
|
||||||
// also checks kiosk and parent containers
|
// also checks kiosk and parent containers
|
||||||
group->writeEntry("immutability", (int)d->immutability);
|
group.writeEntry("immutability", (int)d->immutability);
|
||||||
group->writeEntry("plugin", pluginName());
|
group.writeEntry("plugin", pluginName());
|
||||||
//FIXME: for containments, we need to have some special values here w/regards to
|
//FIXME: for containments, we need to have some special values here w/regards to
|
||||||
// screen affinity (e.g. "bottom of screen 0")
|
// screen affinity (e.g. "bottom of screen 0")
|
||||||
//kDebug() << pluginName() << "geometry is" << geometry() << "pos is" << pos() << "bounding rect is" << boundingRect();
|
//kDebug() << pluginName() << "geometry is" << geometry() << "pos is" << pos() << "bounding rect is" << boundingRect();
|
||||||
group->writeEntry("geometry", geometry());
|
group.writeEntry("geometry", geometry());
|
||||||
group->writeEntry("zvalue", zValue());
|
group.writeEntry("zvalue", zValue());
|
||||||
|
|
||||||
if (transform() == QTransform()) {
|
if (transform() == QTransform()) {
|
||||||
group->deleteEntry("transform");
|
group.deleteEntry("transform");
|
||||||
} else {
|
} else {
|
||||||
QList<qreal> m;
|
QList<qreal> m;
|
||||||
QTransform t = transform();
|
QTransform t = transform();
|
||||||
m << t.m11() << t.m12() << t.m13() << t.m21() << t.m22() << t.m23() << t.m31() << t.m32() << t.m33();
|
m << t.m11() << t.m12() << t.m13() << t.m21() << t.m22() << t.m23() << t.m31() << t.m32() << t.m33();
|
||||||
group->writeEntry("transform", m);
|
group.writeEntry("transform", m);
|
||||||
//group->writeEntry("transform", transformToString(transform()));
|
//group.writeEntry("transform", transformToString(transform()));
|
||||||
}
|
}
|
||||||
|
|
||||||
KConfigGroup appletConfigGroup(group, "Configuration");
|
KConfigGroup appletConfigGroup(&group, "Configuration");
|
||||||
//FIXME: we need a global save state too
|
//FIXME: we need a global save state too
|
||||||
saveState(&appletConfigGroup);
|
saveState(appletConfigGroup);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Applet::restore(KConfigGroup *c)
|
void Applet::restore(KConfigGroup &group)
|
||||||
{
|
{
|
||||||
QList<qreal> m = c->readEntry("transform", QList<qreal>());
|
QList<qreal> m = group.readEntry("transform", QList<qreal>());
|
||||||
if (m.count() == 9) {
|
if (m.count() == 9) {
|
||||||
QTransform t(m[0], m[1], m[2], m[3], m[4], m[5], m[6], m[7], m[8]);
|
QTransform t(m[0], m[1], m[2], m[3], m[4], m[5], m[6], m[7], m[8]);
|
||||||
setTransform(t);
|
setTransform(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
qreal z = c->readEntry("zvalue", 0);
|
qreal z = group.readEntry("zvalue", 0);
|
||||||
|
|
||||||
if (z >= Private::s_maxZValue) {
|
if (z >= Private::s_maxZValue) {
|
||||||
Private::s_maxZValue = z;
|
Private::s_maxZValue = z;
|
||||||
@ -178,9 +178,9 @@ void Applet::restore(KConfigGroup *c)
|
|||||||
|
|
||||||
setZValue(z);
|
setZValue(z);
|
||||||
|
|
||||||
setImmutability((ImmutabilityType)c->readEntry("immutability", (int)Mutable));
|
setImmutability((ImmutabilityType)group.readEntry("immutability", (int)Mutable));
|
||||||
|
|
||||||
QRectF geom = c->readEntry("geometry",QRectF());
|
QRectF geom = group.readEntry("geometry",QRectF());
|
||||||
if (geom.isValid()) {
|
if (geom.isValid()) {
|
||||||
setGeometry(geom);
|
setGeometry(geom);
|
||||||
}
|
}
|
||||||
@ -217,13 +217,13 @@ void Applet::setFailedToLaunch(bool failed, const QString& reason)
|
|||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Applet::saveState(KConfigGroup* group) const
|
void Applet::saveState(KConfigGroup &group) const
|
||||||
{
|
{
|
||||||
if (group->config()->name() != config().config()->name()) {
|
if (group.config()->name() != config().config()->name()) {
|
||||||
// we're being saved to a different file!
|
// we're being saved to a different file!
|
||||||
// let's just copy the current values in our configuration over
|
// let's just copy the current values in our configuration over
|
||||||
KConfigGroup c = config();
|
KConfigGroup c = config();
|
||||||
d->copyEntries(&c, group);
|
c.copyTo(&group);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1415,6 +1415,7 @@ void Applet::Private::init()
|
|||||||
|
|
||||||
if (!appletDescription.isValid()) {
|
if (!appletDescription.isValid()) {
|
||||||
q->setFailedToLaunch(true, i18n("Invalid applet description"));
|
q->setFailedToLaunch(true, i18n("Invalid applet description"));
|
||||||
|
kDebug() << "Check your constructor! You must be passing a Service::Ptr or a QVariantList args through!";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1546,22 +1547,6 @@ KConfigGroup* Applet::Private::mainConfigGroup()
|
|||||||
return mainConfig;
|
return mainConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Applet::Private::copyEntries(KConfigGroup *source, KConfigGroup *destination)
|
|
||||||
{
|
|
||||||
foreach (const QString &group, source->groupList()) {
|
|
||||||
KConfigGroup subSource(source, group);
|
|
||||||
KConfigGroup subDest(destination, group);
|
|
||||||
copyEntries(&subSource, &subDest);
|
|
||||||
}
|
|
||||||
|
|
||||||
QMap<QString, QString> entries = source->entryMap();
|
|
||||||
QMapIterator<QString, QString> it(entries);
|
|
||||||
while (it.hasNext()) {
|
|
||||||
it.next();
|
|
||||||
destination->writeEntry(it.key(), it.value());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
QString Applet::Private::visibleFailureText(const QString& reason)
|
QString Applet::Private::visibleFailureText(const QString& reason)
|
||||||
{
|
{
|
||||||
QString text;
|
QString text;
|
||||||
|
9
applet.h
9
applet.h
@ -26,8 +26,9 @@
|
|||||||
#include <QtGui/QWidget>
|
#include <QtGui/QWidget>
|
||||||
#include <QtGui/QGraphicsWidget>
|
#include <QtGui/QGraphicsWidget>
|
||||||
|
|
||||||
#include <KDE/KPluginInfo>
|
#include <KDE/KConfigGroup>
|
||||||
#include <KDE/KGenericFactory>
|
#include <KDE/KGenericFactory>
|
||||||
|
#include <KDE/KPluginInfo>
|
||||||
|
|
||||||
#include <plasma/configxml.h>
|
#include <plasma/configxml.h>
|
||||||
#include <plasma/packagestructure.h>
|
#include <plasma/packagestructure.h>
|
||||||
@ -120,12 +121,12 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
|
|||||||
/**
|
/**
|
||||||
* Saves state information about this applet.
|
* Saves state information about this applet.
|
||||||
**/
|
**/
|
||||||
void save(KConfigGroup* group) const;
|
virtual void save(KConfigGroup &group) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Restores state information about this applet.
|
* Restores state information about this applet.
|
||||||
**/
|
**/
|
||||||
void restore(KConfigGroup* group);
|
virtual void restore(KConfigGroup &group);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a KConfigGroup object to be shared by all applets of this
|
* Returns a KConfigGroup object to be shared by all applets of this
|
||||||
@ -582,7 +583,7 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
|
|||||||
* Called when a request to save the state of the applet is made
|
* Called when a request to save the state of the applet is made
|
||||||
* during runtime
|
* during runtime
|
||||||
**/
|
**/
|
||||||
virtual void saveState(KConfigGroup* config) const;
|
virtual void saveState(KConfigGroup &config) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets whether or not this applet provides a user interface for
|
* Sets whether or not this applet provides a user interface for
|
||||||
|
@ -184,15 +184,19 @@ bool appletConfigLessThan(const KConfigGroup &c1, const KConfigGroup &c2)
|
|||||||
return p1.y() < p2.y();
|
return p1.y() < p2.y();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Containment::loadContainment(KConfigGroup* group)
|
void Containment::restore(KConfigGroup &group)
|
||||||
{
|
{
|
||||||
/*kDebug() << "!!!!!!!!!!!!initConstraints" << group->name() << containmentType();
|
/*kDebug() << "!!!!!!!!!!!!initConstraints" << group.name() << containmentType();
|
||||||
kDebug() << " location:" << group->readEntry("location", (int)d->location);
|
kDebug() << " location:" << group.readEntry("location", (int)d->location);
|
||||||
kDebug() << " geom:" << group->readEntry("geometry", geometry());
|
kDebug() << " geom:" << group.readEntry("geometry", geometry());
|
||||||
kDebug() << " formfactor:" << group->readEntry("formfactor", (int)d->formFactor);
|
kDebug() << " formfactor:" << group.readEntry("formfactor", (int)d->formFactor);
|
||||||
kDebug() << " screen:" << group->readEntry("screen", d->screen);*/
|
kDebug() << " screen:" << group.readEntry("screen", d->screen);*/
|
||||||
|
if (!isContainment()) {
|
||||||
|
Applet::restore(group);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
QRectF geo = group->readEntry("geometry", geometry());
|
QRectF geo = group.readEntry("geometry", geometry());
|
||||||
//override max/min
|
//override max/min
|
||||||
//this ensures panels are set to their saved size even when they have max & min set to prevent
|
//this ensures panels are set to their saved size even when they have max & min set to prevent
|
||||||
//resizing
|
//resizing
|
||||||
@ -204,13 +208,38 @@ void Containment::loadContainment(KConfigGroup* group)
|
|||||||
}
|
}
|
||||||
setGeometry(geo);
|
setGeometry(geo);
|
||||||
|
|
||||||
setLocation((Plasma::Location)group->readEntry("location", (int)d->location));
|
setLocation((Plasma::Location)group.readEntry("location", (int)d->location));
|
||||||
setFormFactor((Plasma::FormFactor)group->readEntry("formfactor", (int)d->formFactor));
|
setFormFactor((Plasma::FormFactor)group.readEntry("formfactor", (int)d->formFactor));
|
||||||
setScreen(group->readEntry("screen", d->screen));
|
setScreen(group.readEntry("screen", d->screen));
|
||||||
|
|
||||||
flushPendingConstraintsEvents();
|
flushPendingConstraintsEvents();
|
||||||
//kDebug() << "Containment" << id() << "geometry is" << geometry() << "config'd with" << appletConfig.name();
|
//kDebug() << "Containment" << id() << "geometry is" << geometry() << "config'd with" << appletConfig.name();
|
||||||
KConfigGroup applets(group, "Applets");
|
restoreContents(group);
|
||||||
|
setImmutability((ImmutabilityType)group.readEntry("immutability", (int)Mutable));
|
||||||
|
}
|
||||||
|
|
||||||
|
void Containment::save(KConfigGroup &group) const
|
||||||
|
{
|
||||||
|
// locking is saved in Applet::save
|
||||||
|
Applet::save(group);
|
||||||
|
group.writeEntry("screen", d->screen);
|
||||||
|
group.writeEntry("formfactor", (int)d->formFactor);
|
||||||
|
group.writeEntry("location", (int)d->location);
|
||||||
|
saveContents(group);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Containment::saveContents(KConfigGroup &group) const
|
||||||
|
{
|
||||||
|
KConfigGroup applets(&group, "Applets");
|
||||||
|
foreach (const Applet* applet, d->applets) {
|
||||||
|
KConfigGroup appletConfig(&applets, QString::number(applet->id()));
|
||||||
|
applet->save(appletConfig);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Containment::restoreContents(KConfigGroup &group)
|
||||||
|
{
|
||||||
|
KConfigGroup applets(&group, "Applets");
|
||||||
|
|
||||||
// Sort the applet configs in order of geometry to ensure that applets
|
// Sort the applet configs in order of geometry to ensure that applets
|
||||||
// are added from left to right or top to bottom for a panel containment
|
// are added from left to right or top to bottom for a panel containment
|
||||||
@ -232,18 +261,10 @@ void Containment::loadContainment(KConfigGroup* group)
|
|||||||
}
|
}
|
||||||
|
|
||||||
Applet *applet = d->addApplet(plugin, QVariantList(), appletConfig.readEntry("geometry", QRectF()), appId, true);
|
Applet *applet = d->addApplet(plugin, QVariantList(), appletConfig.readEntry("geometry", QRectF()), appId, true);
|
||||||
applet->restore(&appletConfig);
|
applet->restore(appletConfig);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Containment::saveContainment(KConfigGroup* group) const
|
|
||||||
{
|
|
||||||
// locking is saved in Applet::save
|
|
||||||
group->writeEntry("screen", d->screen);
|
|
||||||
group->writeEntry("formfactor", (int)d->formFactor);
|
|
||||||
group->writeEntry("location", (int)d->location);
|
|
||||||
}
|
|
||||||
|
|
||||||
Containment::Type Containment::containmentType() const
|
Containment::Type Containment::containmentType() const
|
||||||
{
|
{
|
||||||
return d->type;
|
return d->type;
|
||||||
|
@ -210,14 +210,14 @@ class PLASMA_EXPORT Containment : public Applet
|
|||||||
QPoint effectiveScreenPos() const;
|
QPoint effectiveScreenPos() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @reimplemented from Applet
|
||||||
*/
|
*/
|
||||||
void saveContainment(KConfigGroup *group) const;
|
void save(KConfigGroup &group) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @reimplemented from Applet
|
||||||
*/
|
*/
|
||||||
void loadContainment(KConfigGroup *group);
|
void restore(KConfigGroup &group);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a ToolBox item and adds it to the toolbox. The toolbox takes over ownership of the item. Returns the constructed tool.
|
* Constructs a ToolBox item and adds it to the toolbox. The toolbox takes over ownership of the item. Returns the constructed tool.
|
||||||
@ -369,6 +369,23 @@ class PLASMA_EXPORT Containment : public Applet
|
|||||||
*/
|
*/
|
||||||
void setContainmentType(Containment::Type type);
|
void setContainmentType(Containment::Type type);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when the contents of the containment should be saved. By default this saves
|
||||||
|
* all loaded Applets
|
||||||
|
*
|
||||||
|
* @param group the KConfigGroup to save settings under
|
||||||
|
*/
|
||||||
|
virtual void saveContents(KConfigGroup &group) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when the contents of the containment should be loaded. By default this loads
|
||||||
|
* all previously saved Applets
|
||||||
|
*
|
||||||
|
* @param group the KConfigGroup to save settings under
|
||||||
|
*/
|
||||||
|
virtual void restoreContents(KConfigGroup &group);
|
||||||
|
|
||||||
|
|
||||||
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event);
|
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event);
|
||||||
void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
|
void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
|
||||||
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
|
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
|
||||||
|
10
corona.cpp
10
corona.cpp
@ -89,13 +89,7 @@ public:
|
|||||||
foreach (const Containment *containment, containments) {
|
foreach (const Containment *containment, containments) {
|
||||||
QString cid = QString::number(containment->id());
|
QString cid = QString::number(containment->id());
|
||||||
KConfigGroup containmentConfig(&containmentsGroup, cid);
|
KConfigGroup containmentConfig(&containmentsGroup, cid);
|
||||||
containment->saveContainment(&containmentConfig);
|
containment->save(containmentConfig);
|
||||||
containment->save(&containmentConfig);
|
|
||||||
KConfigGroup applets(&containmentConfig, "Applets");
|
|
||||||
foreach (const Applet* applet, containment->applets()) {
|
|
||||||
KConfigGroup appletConfig(&applets, QString::number(applet->id()));
|
|
||||||
applet->save(&appletConfig);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -276,7 +270,7 @@ void Corona::loadLayout(const QString& configName)
|
|||||||
|
|
||||||
addItem(c);
|
addItem(c);
|
||||||
c->init();
|
c->init();
|
||||||
c->loadContainment(&containmentConfig);
|
c->restore(containmentConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (d->containments.isEmpty()) {
|
if (d->containments.isEmpty()) {
|
||||||
|
Loading…
Reference in New Issue
Block a user