On Thursday 11 September 2008 17:47:27 Aaron J. Seigo wrote:
> On Thursday 11 September 2008, Petri Damstén wrote:
> > Applets connect to apply & ok to know when user accepted config, but if
> > AppletScript uses configxml there seems to be no way to do that? Maybe
> > configAccepted signal in applet? I guess this could be good for Applets
> > too so they don't have to rely parent to have ok/apply.
>
> there is a configChanged() signal from KCoreConfigSkeleton as well; we
> might be able to use that. it gets emitted when writeConfig() is called...
> soooo ... we could do sth like:
>
> * connect d->configXml configChanged to a configChanged signal (or slot?)
> * create dialog using d->configXml
> * writeConfig gets called by the dialog (for free) and that triggers things

patch for:
- configChanged functions in Applet and AppletScript
- connected to configXml configChanged() and applyClicked/okClicked (for C++ 
applets)
- package typo mainconfiggui -> mainconfigui
- and some Q_UNUSED to remove warnings

Petri

Index: scripting/appletscript.h
===================================================================
--- scripting/appletscript.h	(revision 860110)
+++ scripting/appletscript.h	(working copy)
@@ -125,6 +125,11 @@
      */
     virtual void showConfigurationInterface();
 
+    /**
+     * Configure was changed.
+     */
+    virtual void configChanged();
+
 protected:
     /**
      * @arg engine name of the engine
Index: scripting/appletscript.cpp
===================================================================
--- scripting/appletscript.cpp	(revision 860110)
+++ scripting/appletscript.cpp	(working copy)
@@ -93,6 +93,7 @@
 
 void AppletScript::setHasConfigurationInterface(bool hasInterface)
 {
+    Q_UNUSED(hasInterface)
     if (applet()) {
         applet()->setHasConfigurationInterface(true);
     }
@@ -102,6 +103,10 @@
 {
 }
 
+void AppletScript::configChanged()
+{
+}
+
 DataEngine* AppletScript::dataEngine(const QString &engine) const
 {
     Q_ASSERT(d->applet);
Index: applet.h
===================================================================
--- applet.h	(revision 860110)
+++ applet.h	(working copy)
@@ -594,6 +594,11 @@
         virtual void init();
 
         /**
+         * Called when applet configuration values has changed.
+         */
+        virtual void configChanged();
+
+        /**
          * Get's called when and extender item has to be initialized after a plasma restart. If you
          * create ExtenderItems in your applet, you should implement this function to again create
          * the widget that should be shown in this extender item. This function might look something
Index: applet.cpp
===================================================================
--- applet.cpp	(revision 860110)
+++ applet.cpp	(working copy)
@@ -190,7 +190,7 @@
         //which isn't very nice.
         foreach (ExtenderItem *item, extender()->attachedItems()) {
             if (!item->isDetached() || item->autoExpireDelay()) {
-                //destroy temporary extender items, or items that aren't detached, so their 
+                //destroy temporary extender items, or items that aren't detached, so their
                 //configuration won't linger after a plasma restart.
                 item->destroy();
             }
@@ -443,7 +443,7 @@
     QGraphicsView *found = 0;
     QGraphicsView *possibleFind = 0;
     foreach (QGraphicsView *view, scene()->views()) {
-        kDebug() << "checking" << view->sceneRect() << "against" << sceneBoundingRect() 
+        kDebug() << "checking" << view->sceneRect() << "against" << sceneBoundingRect()
                  << scenePos();
         if (view->sceneRect().intersects(sceneBoundingRect()) ||
             view->sceneRect().contains(scenePos())) {
@@ -651,6 +651,9 @@
 
 void Applet::paintWindowFrame(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget)
 {
+    Q_UNUSED(painter)
+    Q_UNUSED(option)
+    Q_UNUSED(widget)
     //Here come the code for the window frame
     //kDebug() << windowFrameGeometry();
     //painter->drawRoundedRect(windowFrameGeometry(), 5, 5);
@@ -1238,12 +1241,21 @@
         connect(dialog, SIGNAL(finished()), nullManager, SLOT(deleteLater()));
         //TODO: Apply button does not correctly work for now, so do not show it
         dialog->showButton( KDialog::Apply, false );
+        connect(dialog, SIGNAL(applyClicked()), this, SLOT(configChanged()));
+        connect(dialog, SIGNAL(okClicked()), this, SLOT(configChanged()));
         dialog->show();
     }
 
     emit releaseVisualFocus();
 }
 
+void Applet::configChanged()
+{
+    if (d->script) {
+        d->script->configChanged();
+    }
+}
+
 void Applet::createConfigurationInterface(KConfigDialog *parent)
 {
     Q_UNUSED(parent)
@@ -1642,6 +1654,7 @@
         // FIXME: KConfigSkeleton doesn't play well with KConfigGroup =/
         KConfigGroup config = q->config();
         configXml = new ConfigXml(&config, &file);
+        QObject::connect(configXml, SIGNAL(configChanged()), q, SLOT(configChanged()));
     }
 
     if (!package->filePath("mainconfigui").isEmpty()) {
Index: private/packages.cpp
===================================================================
--- private/packages.cpp	(revision 860110)
+++ private/packages.cpp	(working copy)
@@ -48,7 +48,7 @@
     mimetypes << "text/*";
     setMimetypes("scripts", mimetypes);
 
-    addFileDefinition("mainconfiggui", "ui/config.ui", i18n("Main Config UI File"));
+    addFileDefinition("mainconfigui", "ui/config.ui", i18n("Main Config UI File"));
     addFileDefinition("mainconfigxml", "config/main.xml", i18n("Configuration XML file"));
     addFileDefinition("mainscript", "code/main", i18n("Main Script File"));
     setRequired("mainscript", true);

Attachment: signature.asc
Description: This is a digitally signed message part.

_______________________________________________
Plasma-devel mailing list
Plasma-devel@kde.org
https://mail.kde.org/mailman/listinfo/plasma-devel

Reply via email to