diff --git a/applet.cpp b/applet.cpp index 3866ea469..446756e21 100644 --- a/applet.cpp +++ b/applet.cpp @@ -135,42 +135,42 @@ uint Applet::id() const 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() // also checks kiosk and parent containers - group->writeEntry("immutability", (int)d->immutability); - group->writeEntry("plugin", pluginName()); + group.writeEntry("immutability", (int)d->immutability); + group.writeEntry("plugin", pluginName()); //FIXME: for containments, we need to have some special values here w/regards to // screen affinity (e.g. "bottom of screen 0") //kDebug() << pluginName() << "geometry is" << geometry() << "pos is" << pos() << "bounding rect is" << boundingRect(); - group->writeEntry("geometry", geometry()); - group->writeEntry("zvalue", zValue()); + group.writeEntry("geometry", geometry()); + group.writeEntry("zvalue", zValue()); if (transform() == QTransform()) { - group->deleteEntry("transform"); + group.deleteEntry("transform"); } else { QList m; QTransform t = transform(); 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", transformToString(transform())); + group.writeEntry("transform", m); + //group.writeEntry("transform", transformToString(transform())); } - KConfigGroup appletConfigGroup(group, "Configuration"); + KConfigGroup appletConfigGroup(&group, "Configuration"); //FIXME: we need a global save state too - saveState(&appletConfigGroup); + saveState(appletConfigGroup); } -void Applet::restore(KConfigGroup *c) +void Applet::restore(KConfigGroup &group) { - QList m = c->readEntry("transform", QList()); + QList m = group.readEntry("transform", QList()); if (m.count() == 9) { QTransform t(m[0], m[1], m[2], m[3], m[4], m[5], m[6], m[7], m[8]); setTransform(t); } - qreal z = c->readEntry("zvalue", 0); + qreal z = group.readEntry("zvalue", 0); if (z >= Private::s_maxZValue) { Private::s_maxZValue = z; @@ -178,9 +178,9 @@ void Applet::restore(KConfigGroup *c) 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()) { setGeometry(geom); } @@ -217,13 +217,13 @@ void Applet::setFailedToLaunch(bool failed, const QString& reason) 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! // let's just copy the current values in our configuration over KConfigGroup c = config(); - d->copyEntries(&c, group); + c.copyTo(&group); } } @@ -589,7 +589,7 @@ bool Applet::hasFailedToLaunch() const return d->failed; } -void Applet::paintWindowFrame ( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget) +void Applet::paintWindowFrame(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget) { //Here come the code for the window frame //kDebug()<<"ENTER in windowFrame"; @@ -1415,6 +1415,7 @@ void Applet::Private::init() if (!appletDescription.isValid()) { q->setFailedToLaunch(true, i18n("Invalid applet description")); + kDebug() << "Check your constructor! You must be passing a Service::Ptr or a QVariantList args through!"; return; } @@ -1546,22 +1547,6 @@ KConfigGroup* Applet::Private::mainConfigGroup() 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 entries = source->entryMap(); - QMapIterator it(entries); - while (it.hasNext()) { - it.next(); - destination->writeEntry(it.key(), it.value()); - } -} - QString Applet::Private::visibleFailureText(const QString& reason) { QString text; diff --git a/applet.h b/applet.h index a38441dfc..d955df37d 100644 --- a/applet.h +++ b/applet.h @@ -26,8 +26,9 @@ #include #include -#include +#include #include +#include #include #include @@ -120,12 +121,12 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget /** * Saves state information about this applet. **/ - void save(KConfigGroup* group) const; + virtual void save(KConfigGroup &group) const; /** * 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 @@ -582,7 +583,7 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget * Called when a request to save the state of the applet is made * 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 diff --git a/containment.cpp b/containment.cpp index f21126a2f..5760c0b9a 100644 --- a/containment.cpp +++ b/containment.cpp @@ -184,15 +184,19 @@ bool appletConfigLessThan(const KConfigGroup &c1, const KConfigGroup &c2) return p1.y() < p2.y(); } -void Containment::loadContainment(KConfigGroup* group) +void Containment::restore(KConfigGroup &group) { - /*kDebug() << "!!!!!!!!!!!!initConstraints" << group->name() << containmentType(); - kDebug() << " location:" << group->readEntry("location", (int)d->location); - kDebug() << " geom:" << group->readEntry("geometry", geometry()); - kDebug() << " formfactor:" << group->readEntry("formfactor", (int)d->formFactor); - kDebug() << " screen:" << group->readEntry("screen", d->screen);*/ + /*kDebug() << "!!!!!!!!!!!!initConstraints" << group.name() << containmentType(); + kDebug() << " location:" << group.readEntry("location", (int)d->location); + kDebug() << " geom:" << group.readEntry("geometry", geometry()); + kDebug() << " formfactor:" << group.readEntry("formfactor", (int)d->formFactor); + 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 //this ensures panels are set to their saved size even when they have max & min set to prevent //resizing @@ -204,13 +208,38 @@ void Containment::loadContainment(KConfigGroup* group) } setGeometry(geo); - setLocation((Plasma::Location)group->readEntry("location", (int)d->location)); - setFormFactor((Plasma::FormFactor)group->readEntry("formfactor", (int)d->formFactor)); - setScreen(group->readEntry("screen", d->screen)); + setLocation((Plasma::Location)group.readEntry("location", (int)d->location)); + setFormFactor((Plasma::FormFactor)group.readEntry("formfactor", (int)d->formFactor)); + setScreen(group.readEntry("screen", d->screen)); flushPendingConstraintsEvents(); //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 // 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->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 { return d->type; diff --git a/containment.h b/containment.h index c79c86714..bceb863bb 100644 --- a/containment.h +++ b/containment.h @@ -210,14 +210,14 @@ class PLASMA_EXPORT Containment : public Applet 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. @@ -369,6 +369,23 @@ class PLASMA_EXPORT Containment : public Applet */ 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 hoverEnterEvent(QGraphicsSceneHoverEvent *event); void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); diff --git a/corona.cpp b/corona.cpp index 892fc2723..459006f24 100644 --- a/corona.cpp +++ b/corona.cpp @@ -89,13 +89,7 @@ public: foreach (const Containment *containment, containments) { QString cid = QString::number(containment->id()); KConfigGroup containmentConfig(&containmentsGroup, cid); - containment->saveContainment(&containmentConfig); - containment->save(&containmentConfig); - KConfigGroup applets(&containmentConfig, "Applets"); - foreach (const Applet* applet, containment->applets()) { - KConfigGroup appletConfig(&applets, QString::number(applet->id())); - applet->save(&appletConfig); - } + containment->save(containmentConfig); } } @@ -115,7 +109,7 @@ public: // so this unsafe looking code is actually just fine. Containment* containment = static_cast(obj); int index = containments.indexOf(containment); - + if (index > -1) { containments.removeAt(index); } @@ -276,7 +270,7 @@ void Corona::loadLayout(const QString& configName) addItem(c); c->init(); - c->loadContainment(&containmentConfig); + c->restore(containmentConfig); } if (d->containments.isEmpty()) {