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

List:       kde-commits
Subject:    KDE/kdelibs/kross/ui
From:       Paulo Moura Guedes <moura () kdewebdev ! org>
Date:       2008-04-30 9:41:52
Message-ID: 1209548512.222440.20713.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 802693 by mojo:

Add an addObject function that will publish the object into the scripting code.

 M  +15 -0     plugin.cpp  
 M  +8 -0      plugin.h  


--- trunk/KDE/kdelibs/kross/ui/plugin.cpp #802692:802693
@@ -28,6 +28,8 @@
 #include <kross/core/actioncollection.h>
 #include <kio/netaccess.h>
 
+#include <QPointer>
+
 using namespace Kross;
 
 /// \internal d-pointer class
@@ -35,6 +37,7 @@
 {
 public:
     QString userActionsFile;
+    QHash<QString, QPointer<QObject> > objects;
 
     QDomElement menuFromName(QString const& name, const QDomDocument& document)
     {
@@ -67,6 +70,12 @@
     KXMLGUIClient::setDOMDocument(doc, merge);
 }
 
+void ScriptingPlugin::addObject(QObject* object, const QString& name)
+{
+    QString n = name.isNull() ? object->objectName() : name;
+    d->objects.insert(n, object);
+}
+
 QDomDocument ScriptingPlugin::buildDomDocument(const QDomDocument& document)
 {
     QStringList allActionFiles = KGlobal::dirs()->findAllResources("appdata", "scripts/*.rc");
@@ -95,6 +104,12 @@
     QDomElement menuElement = d->menuFromName(collection->name(), document);
 
     foreach(Kross::Action* action, collection->actions()) {
+        QHashIterator<QString, QPointer<QObject> > i(d->objects);
+        while(i.hasNext()) {
+            i.next();
+            action->addObject(i.value(), i.key());
+        }
+        
         // Create and append new Menu element if doesn't exist
         if(menuElement.isNull()) {
             menuElement = document.createElement("Menu");
--- trunk/KDE/kdelibs/kross/ui/plugin.h #802692:802693
@@ -80,6 +80,14 @@
      */
     virtual void setDOMDocument (const QDomDocument &document, bool merge = false);
 
+    /**
+     * Add a QObject to the list of children. The object will be published to the scripting code.
+     * \param object The QObject instance that should be added to the list of children.
+     * \param name The name the QObject should be known under. If not defined, the
+     * QObject's objectName is used.
+     */
+    void addObject(QObject* object, const QString& name = QString());
+
 protected Q_SLOTS:
 
     /**
[prev in list] [next in list] [prev in thread] [next in thread] 

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