[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-panel-devel
Subject:    patch for Containment config
From:       "Aaron J. Seigo" <aseigo () kde ! org>
Date:       2008-05-21 16:52:38
Message-ID: 200805211102.57870.aseigo () kde ! org
[Download RAW message or body]

[Attachment #2 (multipart/signed)]

[Attachment #4 (multipart/mixed)]


hi..

(not using review board because it seems to be, once again, fubar)

the attached patch does three things:

* switches use from KConfigGroup* to KConfigGroup&

* consolidates save/load/restore in Applet and Containment into one set of 
virtual methods (as well as settle on restore instead of load everywhere)

* introduces Containment::saveContents and restoreContents

the point of this (besides the API cleanliness) is to allow Containments to 
have fine grained control of their save/restore process. this will allow 
runtime containments that do not get saved as part of the layout, for example 
(needed by the notification applet) as well open the doors for containments 
that just don't follow the usual Applet pattern.

this is really a flaw in the API design, requires a BIC change and thus i 
consider it a bug fix.

for the existing codebase it is life as usual; this simply opens new doors 
where they are needed. please review and comment; i'd like to commit soon.

-- 
Aaron J. Seigo
humru othro a kohnu se
GPG Fingerprint: 8B8B 2209 0C6F 7C47 B1EA  EE75 D6B7 2EB1 A7F1 DB43

KDE core developer sponsored by Trolltech

["flexible_containment_save_restore.diff" (text/x-diff)]

Index: corona.cpp
===================================================================
--- corona.cpp	(revision 810615)
+++ corona.cpp	(working copy)
@@ -89,13 +89,7 @@
         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 @@
         // so this unsafe looking code is actually just fine.
         Containment* containment = static_cast<Plasma::Containment*>(obj);
         int index = containments.indexOf(containment);
-    
+
         if (index > -1) {
             containments.removeAt(index);
         }
@@ -276,7 +270,7 @@
 
         addItem(c);
         c->init();
-        c->loadContainment(&containmentConfig);
+        c->restore(containmentConfig);
     }
 
     if (d->containments.isEmpty()) {
Index: applet.h
===================================================================
--- applet.h	(revision 810615)
+++ applet.h	(working copy)
@@ -26,8 +26,9 @@
 #include <QtGui/QWidget>
 #include <QtGui/QGraphicsWidget>
 
+#include <KDE/KConfigGroup>
+#include <KDE/KGenericFactory>
 #include <KDE/KPluginInfo>
-#include <KDE/KGenericFactory>
 
 #include <plasma/configxml.h>
 #include <plasma/packagestructure.h>
@@ -120,12 +121,12 @@
         /**
          * 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 @@
          * 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
Index: applet.cpp
===================================================================
--- applet.cpp	(revision 810615)
+++ applet.cpp	(working copy)
@@ -135,42 +135,42 @@
     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<qreal> 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<qreal> m = c->readEntry("transform", QList<qreal>());
+    QList<qreal> m = group.readEntry("transform", QList<qreal>());
     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 @@
 
     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 @@
     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 @@
     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";
@@ -1417,6 +1417,7 @@
 
     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;
     }
 
@@ -1548,22 +1549,6 @@
     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 text;
Index: containment.h
===================================================================
--- containment.h	(revision 810615)
+++ containment.h	(working copy)
@@ -210,14 +210,14 @@
         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 @@
          */
         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);
Index: containment.cpp
===================================================================
--- containment.cpp	(revision 810615)
+++ containment.cpp	(working copy)
@@ -184,15 +184,19 @@
     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
     if (geo.size() != geo.size().boundedTo(maximumSize())) {
         setMaximumSize(maximumSize().expandedTo(geo.size()));
@@ -202,14 +206,39 @@
     }
     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
     QList<KConfigGroup> appletConfigs;
@@ -230,18 +259,10 @@
         }
 
         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;


["signature.asc" (application/pgp-signature)]

_______________________________________________
Panel-devel mailing list
Panel-devel@kde.org
https://mail.kde.org/mailman/listinfo/panel-devel


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic