Kross::Api::ScriptAction Class Reference

#include <scriptaction.h>

Inheritance diagram for Kross::Api::ScriptAction:

Inheritance graph
[legend]
Collaboration diagram for Kross::Api::ScriptAction:

Collaboration graph
[legend]
List of all members.

Detailed Description

A ScriptAction extends a KAction by providing a wrapper around a ScriptContainer to execute scripting code on activation.

Definition at line 39 of file scriptaction.h.

Public Types

typedef KSharedPtr< ScriptActionPtr
 Shared pointer to implement reference-counting.

Public Slots

virtual void activate ()
void finalize ()

Signals

void success ()
void failed (const QString &errormessage, const QString &tracedetails)

Public Member Functions

 ScriptAction (const QString &file)
 A list of ScriptAction instances.
 ScriptAction (const QString &scriptconfigfile, const QDomElement &element)
virtual ~ScriptAction ()
const QString getDescription () const
void setDescription (const QString &description)
void setInterpreterName (const QString &name)
const QString getPackagePath ()
const QStringListgetLogs () const
void attach (ScriptActionCollection *collection)
void detach (ScriptActionCollection *collection)
void detachAll ()
const QStringgetName () const
void setName (const QString &name)
const QStringgetCode () const
void setCode (const QString &code)
const QStringgetInterpreterName () const
const QStringgetFile () const
void setFile (const QString &scriptfile)
QMap< QString, QVariant > & getOptions ()
const QVariantgetOption (const QString name, QVariant defaultvalue=QVariant(), bool recursive=false)
bool setOption (const QString name, const QVariant &value)
Object::Ptr execute ()
const QStringList getFunctionNames ()
KSharedPtr< ObjectcallFunction (const QString &functionname, KSharedPtr< List > arguments=0)
const QStringList getClassNames ()
KSharedPtr< ObjectclassInstance (const QString &classname)
bool initialize ()
virtual const QString getClassName () const
bool hadException ()
Exception::Ptr getException ()
void setException (Exception::Ptr exception)
bool hasChild (const QString &name) const
Object::Ptr hasChild (List::Ptr args)
EventSignal::Ptr addSignal (const QString &name, QObject *sender, QCString signal)
EventSlot::Ptr addSlot (const QString &name, QObject *receiver, QCString slot)
QtObject::Ptr addQObject (QObject *object, const QString &name=QString::null)
EventAction::Ptr addKAction (KAction *action, const QString &name=QString::null)
virtual Kross::Api::Object::Ptr get (const QString &, void *=0)
void addFunction (const QString &name, FunctionPtr function, const ArgumentList &=ArgumentList())
void addFunction (const QString &name, Function *function)
void addProxyFunction (const QString &name, INSTANCE *instance, METHOD method)
void addProxyFunction (const QString &name, INSTANCE *instance, METHOD method)
 Same as above, but with three arguments.
void addProxyFunction (const QString &name, INSTANCE *instance, METHOD method)
 Same as above, but with two arguments.
void addProxyFunction (const QString &name, INSTANCE *instance, METHOD method)
 Same as above, but with one argument.
void addProxyFunction (const QString &name, INSTANCE *instance, METHOD method)
 Same as above, but with no arguments.
bool isAFunction (const QString &name) const
virtual Object::Ptr call (const QString &name, List::Ptr arguments)
virtual Object::Ptr call (const QString &name, KSharedPtr< List > arguments)
Object::Ptr getChild (List::Ptr args)
Object::Ptr getChild (const QString &name) const
Object::Ptr getChildrenList (List::Ptr args)
Object::Ptr getChildrenDict (List::Ptr args)
Object::Ptr callChild (List::Ptr args)
virtual const QString toString ()
Object::Ptr getParent () const
QMap< QString, Object::PtrgetChildren () const
bool addChild (Object::Ptr object, const QString &name=QString::null)
void removeChild (const QString &name)
void removeAllChildren ()
virtual QStringList getCalls ()

Static Public Member Functions

template<class T>
static T * fromObject (Object::Ptr object)

Protected Attributes

ArgumentList m_arglist

Properties

QString description
 The description for this ScriptAction .


Constructor & Destructor Documentation

ScriptAction::ScriptAction const QString file  )  [explicit]
 

A list of ScriptAction instances.

Constructor.

Parameters:
file The KURL scriptfile this ScriptAction points to.

Definition at line 56 of file scriptaction.cpp.

References Kross::Api::ScriptContainer::setFile().

00057     : KAction(0, file.latin1())
00058     , Kross::Api::ScriptContainer(file)
00059     , d( new ScriptActionPrivate() ) // initialize d-pointer class
00060 {
00061     //kdDebug() << QString("Kross::Api::ScriptAction::ScriptAction(const char*, const QString&) name='%1' text='%2'").arg(name).arg(text) << endl;
00062 
00063     KURL url(file);
00064     if(url.isLocalFile()) {
00065         setFile(file);
00066         setText(url.fileName());
00067         setIcon(KMimeType::iconForURL(url));
00068     }
00069     else {
00070         setText(file);
00071     }
00072 
00073     setDescription(file);
00074     setEnabled(false);
00075 }

ScriptAction::ScriptAction const QString scriptconfigfile,
const QDomElement element
[explicit]
 

Constructor.

Parameters:
element The QDomElement which will be used to setup the ScriptAction attributes.

Definition at line 77 of file scriptaction.cpp.

References QDomElement::attribute(), description, and QString::isEmpty().

00078     : KAction()
00079     , Kross::Api::ScriptContainer()
00080     , d( new ScriptActionPrivate() ) // initialize d-pointer class
00081 {
00082     //kdDebug() << "Kross::Api::ScriptAction::ScriptAction(const QDomElement&)" << endl;
00083 
00084     QString name = element.attribute("name");
00085     QString text = element.attribute("text");
00086     QString description = element.attribute("description");
00087     QString file = element.attribute("file");
00088     QString icon = element.attribute("icon");
00089 
00090     if(file.isEmpty()) {
00091         if(text.isEmpty())
00092             text = name;
00093     }
00094     else {
00095         if(name.isEmpty())
00096             name = file;
00097         if(text.isEmpty())
00098             text = file;
00099     }
00100 
00101     //d->scriptcontainer = Manager::scriptManager()->getScriptContainer(name);
00102 
00103     QString interpreter = element.attribute("interpreter");
00104     if(interpreter.isNull())
00105         setEnabled(false);
00106     else
00107         setInterpreterName( interpreter );
00108 
00109     if(file.isNull()) {
00110         setCode( element.text().stripWhiteSpace() );
00111         if(description.isNull())
00112             description = text;
00113         ScriptContainer::setName(name);
00114     }
00115     else {
00116         QDir dir = QFileInfo(scriptconfigfile).dir(true);
00117         d->packagepath = dir.absPath();
00118         QFileInfo fi(dir, file);
00119         file = fi.absFilePath();
00120         setEnabled(fi.exists());
00121         setFile(file);
00122         if(icon.isNull())
00123             icon = KMimeType::iconForURL( KURL(file) );
00124         if(description.isEmpty())
00125             description = QString("%1<br>%2").arg(text.isEmpty() ? name : text).arg(file);
00126         else
00127             description += QString("<br>%1").arg(file);
00128         ScriptContainer::setName(file);
00129     }
00130 
00131     KAction::setName(name.latin1());
00132     KAction::setText(text);
00133     setDescription(description);
00134     KAction::setIcon(icon);
00135 
00136     // connect signal
00137     connect(this, SIGNAL(activated()), this, SLOT(activate()));
00138 }

ScriptAction::~ScriptAction  )  [virtual]
 

Destructor.

Definition at line 140 of file scriptaction.cpp.

References detachAll().

00141 {
00142     //kdDebug() << QString("Kross::Api::ScriptAction::~ScriptAction() name='%1' text='%2'").arg(name()).arg(text()) << endl;
00143     detachAll();
00144     delete d;
00145 }


Member Function Documentation

void ScriptAction::activate  )  [virtual, slot]
 

If the ScriptAction got activated the ScriptContainer got executed. Once this slot got executed it will emit a success() or failed() signal.

Definition at line 191 of file scriptaction.cpp.

References QStyleSheet::escape(), Kross::Api::ScriptContainer::execute(), failed(), Kross::Api::MainModule::getException(), Kross::Api::MainModule::hadException(), Kross::Api::ScriptActionPrivate::logs, and success().

00192 {
00193     Kross::Api::ScriptContainer::execute();
00194     if( Kross::Api::ScriptContainer::hadException() ) {
00195         QString errormessage = Kross::Api::ScriptContainer::getException()->getError();
00196         QString tracedetails = Kross::Api::ScriptContainer::getException()->getTrace();
00197         d->logs << QString("<b>%1</b><br>%2")
00198                    .arg( QStyleSheet::escape(errormessage) )
00199                    .arg( QStyleSheet::escape(tracedetails) );
00200         emit failed(errormessage, tracedetails);
00201     }
00202     else {
00203         emit success();
00204     }
00205 }

bool Object::addChild Object::Ptr  object,
const QString name = QString::null
[inherited]
 

Add a new child. Replaces a possible already existing child with such a name.

Parameters:
name the name of the child
object The Object to add.
Returns:
true if the Object was added successfully else false.

Definition at line 79 of file object.cpp.

References QString::arg(), QString::isEmpty(), QString::isNull(), and QMap::replace().

Referenced by Kross::Api::MainModule::addKAction(), Kross::Api::MainModule::addQObject(), Kross::Api::MainModule::addSignal(), Kross::Api::MainModule::addSlot(), Kross::Api::QtObject::QtObject(), and TestPluginModule::TestPluginModule().

00080 {
00081     QString n = name.isNull() ? object->getName() : name;
00082 
00083 #ifdef KROSS_API_OBJECT_ADDCHILD_DEBUG
00084     kdDebug() << QString("Kross::Api::Object::addChild() object.name='%2' object.classname='%3'")
00085         .arg(n).arg(object->getClassName()) << endl;
00086 #endif
00087 
00088     if(n.isEmpty()) // prevent invalid items.
00089         return false; //throw Exception::Ptr( new Exception( QString("Failed to add child object to object '%1'. Invalid name for class '%2'.").arg(getName()).arg(object->getClassName()) ) );
00090 
00091     object->m_parent = this;
00092     m_children.replace(n, object);
00093     return true;
00094 }

void Kross::Api::Event< Module >::addFunction const QString name,
Function function
[inline, inherited]
 

Add a methodfunction to the list of functions this Object supports.

Parameters:
name The functionname. Each function this object holds should have an unique name to be still accessable.
function A Function instance which defines the methodfunction. This Event will be the owner of the Function instance and will take care of deleting it if this Event got deleted.
arglist A list of arguments for the function.

Definition at line 119 of file event.h.

00120             {
00121                 m_functions.replace(name, function);
00122             }

void Kross::Api::Event< Module >::addFunction const QString name,
FunctionPtr  function,
const ArgumentList = ArgumentList()
[inline, inherited]
 

Add a Callable methodfunction to the list of functions this Object supports.

The FunctionPtr points to the concret Object::Ptr myfuncname(List::Ptr) method in the class defined with template T.

Parameters:
name The functionname. Each function this object holds should have an unique name to be still accessable.
function A pointer to the methodfunction that should handle calls.
arglist A list of arguments for the function.

Definition at line 101 of file event.h.

00102             {
00103                 m_functions.replace(name, new VarFunction0<T>(static_cast<T*>(this), function));
00104             }

EventAction::Ptr MainModule::addKAction KAction *  action,
const QString name = QString::null
[inherited]
 

Add a KAction to the eventcollection. The KAction will be wrapped by a EventAction and will be added to this collection.

Parameters:
name name to identify the action by
action the KAction instance that should be added to this MainModule
Returns:
the newly added EventAction instance which is now a child of this MainModule
Todo:
check name dox.

Definition at line 110 of file mainmodule.cpp.

References Kross::Api::Object::addChild().

00111 {
00112     EventAction* event = new EventAction(name, this, action);
00113     if(! addChild(event)) {
00114         kdWarning() << QString("Failed to add KAction name='%1'").arg(action->name()) << endl;
00115         delete event;
00116         return 0;
00117     }
00118     return event;
00119 }

void Kross::Api::Event< Module >::addProxyFunction const QString name,
INSTANCE *  instance,
METHOD  method
[inline, inherited]
 

Template function to add a Kross::Api::ProxyFunction as builtin-function to this Event instance.

Definition at line 129 of file event.h.

00130             {
00131                 m_functions.replace(name,
00132                     new Kross::Api::ProxyFunction <
00133                         INSTANCE, METHOD,
00134                         RET, ARG1, ARG2, ARG3, ARG4
00135                     > ( instance, method ) );
00136             }

QtObject::Ptr MainModule::addQObject QObject object,
const QString name = QString::null
[inherited]
 

Add a QObject to the eventcollection. All signals and slots the QObject has will be added to a new EventCollection instance which is child of this EventCollection instance.

Parameters:
object the QObject instance that should be added to this MainModule
name the name under which this QObject instance should be registered as
Returns:
the newly added QtObject instance which is now a child of this MainModule

Definition at line 99 of file mainmodule.cpp.

References Kross::Api::Object::addChild(), and QObject::name().

00100 {
00101     QtObject* qtobject = new QtObject(this, object, name);
00102     if(! addChild(qtobject)) {
00103         kdWarning() << QString("Failed to add QObject name='%1'").arg(object->name()) << endl;
00104         delete qtobject;
00105         return 0;
00106     }
00107     return qtobject;
00108 }

EventSignal::Ptr MainModule::addSignal const QString name,
QObject sender,
QCString  signal
[inherited]
 

Add a Qt signal to the Module by creating an EventSignal for it.

Parameters:
name the name the EventSignal is reachable as
sender the QObject instance which is the sender of the signal
signal the Qt signal macro the sender emits to call the EventSignal
Returns:
the newly added EventSignal instance which is now a child of this MainModule

Definition at line 78 of file mainmodule.cpp.

References Kross::Api::Object::addChild().

00079 {
00080     EventSignal* event = new EventSignal(name, this, sender, signal);
00081     if(! addChild(event)) {
00082         kdWarning() << QString("Failed to add signal name='%1' signature='%2'").arg(name).arg(signal) << endl;
00083         return 0;
00084     }
00085     return event;
00086 }

EventSlot::Ptr MainModule::addSlot const QString name,
QObject receiver,
QCString  slot
[inherited]
 

Add a Qt slot to the Module by creating an EventSlot for it.

Parameters:
name the name the EventSlot is reachable as
receiver the QObject instance which is the receiver of the signal
slot the Qt slot macro of the receiver to invoke if the EventSlot got called.
Returns:
the newly added EventSlot instance which is now a child of this MainModule

Definition at line 88 of file mainmodule.cpp.

References Kross::Api::Object::addChild().

00089 {
00090     EventSlot* event = new EventSlot(name, this, receiver, slot);
00091     if(! addChild(event)) {
00092         kdWarning() << QString("Failed to add slot name='%1' signature='%2'").arg(name).arg(slot) << endl;
00093         delete event;
00094         return 0;
00095     }
00096     return event;
00097 }

void ScriptAction::attach ScriptActionCollection collection  ) 
 

Attach this ScriptAction to the ScriptActionCollection collection .

Definition at line 175 of file scriptaction.cpp.

References QValueList::append(), and Kross::Api::ScriptActionPrivate::collections.

00176 {
00177     d->collections.append( collection );
00178 }

virtual Object::Ptr Kross::Api::Object::call const QString name,
KSharedPtr< List arguments
[virtual, inherited]
 

Pass a call to the object and evaluated it recursive down the object-hierachy. Objects like Class are able to handle call's by just implementing this function. If the call is done the called() method will be executed recursive from bottom up the call hierachy.

Exceptions:
TypeException if the object or the name is not callable.
Parameters:
name Each call has a name that says what should be called. In the case of a Class the name is the functionname.
arguments The list of arguments passed to the call.
Returns:
The call-result as Object::Ptr instance or NULL if the call has no result.

Reimplemented in Kross::Api::EventScript, Kross::Api::EventSignal, and Kross::Api::EventSlot.

Referenced by Kross::Api::Callable::call(), and Kross::Api::Callable::callChild().

virtual Object::Ptr Kross::Api::Event< Module >::call const QString name,
List::Ptr  arguments
[inline, virtual, inherited]
 

Overloaded method to handle function-calls.

Exceptions:
AttributeException if argumentparameters arn't valid.
RuntimeException if the functionname isn't valid.
Parameters:
name The functionname. Each function this Object holds should have a different name cause they are access by they name. If name is QString::null or empty, a self-reference to this instance is returned.
arguments The list of arguments.
Returns:
An Object representing the call result or NULL if there doesn't exists such a function with defined name.

Reimplemented from Kross::Api::Callable.

Definition at line 210 of file event.h.

00211             {
00212 #ifdef KROSS_API_EVENT_CALL_DEBUG
00213                 kdDebug() << QString("Event::call() name='%1' getName()='%2'").arg(name).arg(getName()) << endl;
00214 #endif
00215 
00216                 Function* function = m_functions[name];
00217                 if(function) {
00218 #ifdef KROSS_API_EVENT_CALL_DEBUG
00219                     kdDebug() << QString("Event::call() name='%1' is a builtin function.").arg(name) << endl;
00220 #endif
00221 
00222                     //FIXME checkArguments(arguments);
00223                     return function->call(arguments);
00224                 }
00225 
00226                 if(name.isNull()) {
00227                     // If no name is defined, we return a reference to our instance.
00228                     return this;
00229                 }
00230 
00231                 // Redirect the call to the Kross::Api::Callable we are inheritated from.
00232                 return Callable::call(name, arguments);
00233             }

Object::Ptr Callable::callChild List::Ptr  args  )  [inherited]
 

Wrapper for the Kross::Api::Object::call() method to call a children.

Definition at line 172 of file callable.cpp.

References Kross::Api::Object::call(), and Kross::Api::Variant::toString().

Referenced by Kross::Api::Callable::call().

00173 {
00174     //kdDebug() << QString("Kross::Api::Callable::callChild() getName()=%1").arg(getName()) << endl;
00175     return Object::call(Variant::toString(args->item(0)), args);
00176 }

KSharedPtr<Object> Kross::Api::ScriptContainer::callFunction const QString functionname,
KSharedPtr< List arguments = 0
[inherited]
 

Call a function in the script container.

Parameters:
functionname The name of the function to call.
arguments Optional list of arguments passed to the function.
Returns:
Object instance representing the functioncall returnvalue.

Object::Ptr ScriptContainer::classInstance const QString classname  )  [inherited]
 

Create and return a new class instance.

Definition at line 222 of file scriptcontainer.cpp.

References Kross::Api::Script::classInstance(), Kross::Api::ScriptContainer::finalize(), Kross::Api::Script::getException(), Kross::Api::Script::hadException(), Kross::Api::MainModule::hadException(), Kross::Api::ScriptContainer::initialize(), Kross::Api::ScriptContainerPrivate::script, and Kross::Api::MainModule::setException().

00223 {
00224     if(! d->script)
00225         if(! initialize())
00226             return 0;
00227 
00228     if(hadException())
00229         return 0;
00230 
00231     Object::Ptr r = d->script->classInstance(classname);
00232     if(d->script->hadException()) {
00233         setException( d->script->getException() );
00234         finalize();
00235         return 0;
00236     }
00237     return r;
00238 }

void ScriptAction::detach ScriptActionCollection collection  ) 
 

Detach this ScriptAction from the ScriptActionCollection collection .

Definition at line 180 of file scriptaction.cpp.

References Kross::Api::ScriptActionPrivate::collections, and QValueList::remove().

00181 {
00182     d->collections.remove( collection );
00183 }

void ScriptAction::detachAll  ) 
 

Detach this ScriptAction from all ScriptActionCollection instance his ScriptAction is attached to.

Definition at line 185 of file scriptaction.cpp.

References QValueList::begin(), Kross::Api::ScriptActionPrivate::collections, and QValueList::end().

Referenced by ~ScriptAction().

00186 {
00187     for(QValueList<ScriptActionCollection*>::Iterator it = d->collections.begin(); it != d->collections.end(); ++it)
00188         (*it)->detach( this );
00189 }

Object::Ptr ScriptContainer::execute  )  [inherited]
 

Execute the script container.

Definition at line 170 of file scriptcontainer.cpp.

References Kross::Api::Script::execute(), Kross::Api::ScriptContainer::finalize(), Kross::Api::Script::getException(), Kross::Api::Script::hadException(), Kross::Api::MainModule::hadException(), Kross::Api::ScriptContainer::initialize(), Kross::Api::ScriptContainerPrivate::script, and Kross::Api::MainModule::setException().

Referenced by activate().

00171 {
00172     if(! d->script)
00173         if(! initialize())
00174             return 0;
00175 
00176     if(hadException())
00177         return 0;
00178 
00179     Object::Ptr r = d->script->execute();
00180     if(d->script->hadException()) {
00181         setException( d->script->getException() );
00182         finalize();
00183         return 0;
00184     }
00185     return r;
00186 }

void Kross::Api::ScriptAction::failed const QString errormessage,
const QString tracedetails
[signal]
 

This signal got emitted after the try to execute this ScriptAction failed. The errormessage contains the error message.

Referenced by activate().

void ScriptAction::finalize  )  [slot]
 

This slot finalizes the ScriptContainer and tries to clean any still running script.

Reimplemented from Kross::Api::ScriptContainer.

Definition at line 207 of file scriptaction.cpp.

References Kross::Api::ScriptContainer::finalize().

00208 {
00209     Kross::Api::ScriptContainer::finalize();
00210 }

template<class T>
static T* Kross::Api::Object::fromObject Object::Ptr  object  )  [inline, static, inherited]
 

Try to convert the Object instance to the template class T.

Exceptions:
TypeException if the cast failed.
Parameters:
object The Object to cast.
Returns:
The to a instance from template type T casted Object.

Definition at line 198 of file object.h.

00199             {
00200                 T* t = (T*) object.data();
00201                 if(! t)
00202                     throw KSharedPtr<Exception>( new Exception(QString("Object \"%1\" invalid.").arg(object ? object->getClassName() : "")) );
00203                 return t;
00204             }

virtual Kross::Api::Object::Ptr Kross::Api::Module::get const QString ,
void *  = 0
[inline, virtual, inherited]
 

Method to load from Kross::Api::Object inherited classes this module implements from within other modules.

Reimplemented in TestPluginModule.

Definition at line 70 of file module.h.

00071             {
00072                 return 0;
00073             }

virtual QStringList Kross::Api::Object::getCalls  )  [inline, virtual, inherited]
 

Return a list of supported callable objects.

Returns:
List of supported calls.

Reimplemented in Kross::Python::PythonObject.

Definition at line 186 of file object.h.

00186 { return QStringList(); }

Object::Ptr Object::getChild const QString name  )  const [inherited]
 

Return the defined child or NULL if there is no such object with that name avaible.

Parameters:
name The name of the Object to return.
Returns:
The Object matching to the defined name or NULL if there is no such Object.

Definition at line 69 of file object.cpp.

Referenced by Kross::Api::Callable::getChild().

00070 {
00071     return m_children[name];
00072 }

Object::Ptr Callable::getChild List::Ptr  args  )  [inherited]
 

Wrapper for the Kross::Api::Object::getChild() method to return a children this object has.

Definition at line 146 of file callable.cpp.

References Kross::Api::Object::getChild(), Kross::Api::Object::getName(), and Kross::Api::Variant::toString().

Referenced by Kross::Api::Callable::call().

00147 {
00148     QString s = Variant::toString(args->item(0));
00149     //kdDebug() << QString("Kross::Api::Callable::getChild() getName()=%1 childName=%2").arg(getName()).arg(s) << endl;
00150     Object::Ptr obj = Object::getChild(s);
00151     if(! obj)
00152         throw Exception::Ptr( new Exception(QString("The object '%1' has no child object '%2'").arg(getName()).arg(s)) );
00153     return obj;
00154 }

QMap< QString, Object::Ptr > Object::getChildren  )  const [inherited]
 

Return all children.

Returns:
A ObjectMap of children this Object has.

Definition at line 74 of file object.cpp.

Referenced by Kross::Api::Callable::getChildrenDict(), and Kross::Api::Callable::getChildrenList().

00075 {
00076     return m_children;
00077 }

Object::Ptr Callable::getChildrenDict List::Ptr  args  )  [inherited]
 

Wrapper for the Kross::Api::Object::getChild() method to return a dictonary of children this object has.

Returns:
a Dict filled with the children.

Definition at line 166 of file callable.cpp.

References Kross::Api::Object::getChildren().

Referenced by Kross::Api::Callable::call().

00167 {
00168     //kdDebug()<<"Kross::Api::Callable::getChildrenDict()"<<endl;
00169     return new Dict(Object::getChildren(), "Kross::Api::Callable::getChildrenDict::Dict");
00170 }

Object::Ptr Callable::getChildrenList List::Ptr  args  )  [inherited]
 

Wrapper for the Kross::Api::Object::getChildren() method to return a list of childrennames this object has.

Returns:
a List filled with a list of names of the children this object has.

Definition at line 156 of file callable.cpp.

References QMap::begin(), QMap::end(), and Kross::Api::Object::getChildren().

Referenced by Kross::Api::Callable::call().

00157 {
00158     QStringList list;
00159     QMap<QString, Object::Ptr> children = getChildren();
00160     QMap<QString, Object::Ptr>::Iterator it( children.begin() );
00161     for(; it != children.end(); ++it)
00162         list.append( it.key() );
00163     return new Variant(list);
00164 }

const QString MainModule::getClassName  )  const [virtual, inherited]
 

See also:
Kross::Api::Object::getClassName()

Reimplemented from Kross::Api::Callable.

Definition at line 53 of file mainmodule.cpp.

00054 {
00055     return "Kross::Api::MainModule";
00056 }

const QStringList ScriptContainer::getClassNames  )  [inherited]
 

Return a list of classes.

Definition at line 217 of file scriptcontainer.cpp.

References Kross::Api::Script::getClassNames(), and Kross::Api::ScriptContainerPrivate::script.

00218 {
00219     return d->script ? d->script->getClassNames() : QStringList(); //FIXME init before if needed?
00220 }

const QString & ScriptContainer::getCode  )  const [inherited]
 

Return the scriptcode this ScriptContainer holds.

Definition at line 112 of file scriptcontainer.cpp.

References Kross::Api::ScriptContainerPrivate::code.

00113 {
00114     return d->code;
00115 }

const QString ScriptAction::getDescription  )  const
 

Returns:
the description for this ScriptAction has.

Definition at line 147 of file scriptaction.cpp.

References Kross::Api::ScriptActionPrivate::description.

00148 {
00149     return d->description;
00150 }

Exception::Ptr MainModule::getException  )  [inherited]
 

Returns:
the Exception this module throwed.

Definition at line 63 of file mainmodule.cpp.

References Kross::Api::MainModulePrivate::exception.

Referenced by activate().

00064 {
00065     return d->exception;
00066 }

const QString & ScriptContainer::getFile  )  const [inherited]
 

Returns:
the filename which will be executed on execute.

Definition at line 134 of file scriptcontainer.cpp.

References Kross::Api::ScriptContainerPrivate::scriptfile.

00135 {
00136     return d->scriptfile;
00137 }

const QStringList ScriptContainer::getFunctionNames  )  [inherited]
 

Return a list of functionnames the with setCode defined scriptcode spends.

Definition at line 188 of file scriptcontainer.cpp.

References Kross::Api::Script::getFunctionNames(), and Kross::Api::ScriptContainerPrivate::script.

00189 {
00190     return d->script ? d->script->getFunctionNames() : QStringList(); //FIXME init before if needed?
00191 }

const QString & ScriptContainer::getInterpreterName  )  const [inherited]
 

Returns:
the name of the interpreter used on execute.

Definition at line 123 of file scriptcontainer.cpp.

References Kross::Api::ScriptContainerPrivate::interpretername.

00124 {
00125     return d->interpretername;
00126 }

const QStringList & ScriptAction::getLogs  )  const
 

Returns:
a list of all kind of logs this ScriptAction does remember.

Definition at line 170 of file scriptaction.cpp.

References Kross::Api::ScriptActionPrivate::logs.

00171 {
00172     return d->logs;
00173 }

const QString & ScriptContainer::getName  )  const [inherited]
 

Return the unique name this ScriptContainer is reachable as.

Reimplemented from Kross::Api::Object.

Definition at line 102 of file scriptcontainer.cpp.

References Kross::Api::ScriptContainerPrivate::name.

00103 {
00104     return d->name;
00105 }

const QVariant & ScriptContainer::getOption const QString  name,
QVariant  defaultvalue = QVariant(),
bool  recursive = false
[inherited]
 

Returns:
the value of the option defined with name . If there doesn't exists an option with such a name, the defaultvalue is returned. If recursive is true then first the ScriptContainer options are seeked for the matching name and if not found the Manager options are seeked for the name and if not found either the defaultvalue is returned.

Definition at line 150 of file scriptcontainer.cpp.

References QMap::contains(), Kross::Api::Manager::getInterpreterInfo(), Kross::Api::InterpreterInfo::getOptionValue(), Kross::Api::ScriptContainerPrivate::interpretername, Kross::Api::ScriptContainerPrivate::options, and Kross::Api::Manager::scriptManager().

00151 {
00152     if(d->options.contains(name))
00153         return d->options[name];
00154     Kross::Api::InterpreterInfo* info = Kross::Api::Manager::scriptManager()->getInterpreterInfo( d->interpretername );
00155     return info ? info->getOptionValue(name, defaultvalue) : defaultvalue;
00156 }

QMap< QString, QVariant > & ScriptContainer::getOptions  )  [inherited]
 

Returns:
a map of options this ScriptContainer defines. The options are returned call-by-ref, so you are able to manipulate them.

Definition at line 145 of file scriptcontainer.cpp.

References Kross::Api::ScriptContainerPrivate::options.

00146 {
00147     return d->options;
00148 }

const QString ScriptAction::getPackagePath  ) 
 

Returns:
the path of the package this ScriptAction belongs to or QString::null if it doesn't belong to any package.

Definition at line 165 of file scriptaction.cpp.

References Kross::Api::ScriptActionPrivate::packagepath.

00166 {
00167     return d->packagepath;
00168 }

Object::Ptr Object::getParent  )  const [inherited]
 

Return the parent object or NULL if this object doesn't has a parent.

Returns:
The parent-Object or NULL if this Object doesn't has a parent.

Definition at line 59 of file object.cpp.

00060 {
00061     return m_parent;
00062 }

bool MainModule::hadException  )  [inherited]
 

Returns:
true if the script throwed an exception else false.

Definition at line 58 of file mainmodule.cpp.

References Kross::Api::MainModulePrivate::exception.

Referenced by activate(), Kross::Api::ScriptContainer::classInstance(), and Kross::Api::ScriptContainer::execute().

00059 {
00060     return d->exception != 0;
00061 }

Object::Ptr Callable::hasChild List::Ptr  args  )  [inherited]
 

Wrapper for the Kross::Api::Object::hasChild() method to check if this object has children.

Definition at line 139 of file callable.cpp.

References Kross::Api::Object::hasChild(), and Kross::Api::Variant::toString().

Referenced by Kross::Api::Callable::call().

00140 {
00141     //kdDebug() << QString("Kross::Api::Callable::hasChild() getName()=%1").arg(getName()) << endl;
00142     return new Variant( Object::hasChild( Variant::toString(args->item(0)) ),
00143                         "Kross::Api::Callable::hasChild::Bool" );
00144 }

bool MainModule::hasChild const QString name  )  const [inherited]
 

Returns if the defined child is avaible.

Returns:
true if child exists else false.

Reimplemented from Kross::Api::Object.

Definition at line 73 of file mainmodule.cpp.

References Kross::Api::Object::hasChild().

00074 {
00075     return Object::hasChild(name);
00076 }

bool ScriptContainer::initialize  )  [inherited]
 

Initialize the Script instance.

Normaly it's not needed to call this function direct cause if will be internaly called if needed (e.g. on execute ).

Definition at line 240 of file scriptcontainer.cpp.

References Kross::Api::ScriptContainer::finalize(), Kross::Api::Manager::getInterpreternameForFile(), Kross::Api::ScriptContainerPrivate::interpretername, QString::isNull(), Kross::Api::ScriptContainerPrivate::scriptfile, Kross::Api::Manager::scriptManager(), and Kross::Api::MainModule::setException().

Referenced by Kross::Api::ScriptContainer::classInstance(), and Kross::Api::ScriptContainer::execute().

00241 {
00242     finalize();
00243 
00244     if(! d->scriptfile.isNull()) {
00245         kdDebug() << QString("Kross::Api::ScriptContainer::initialize() file=%1").arg(d->scriptfile) << endl;
00246 
00247         if(d->interpretername.isNull()) {
00248             d->interpretername = Manager::scriptManager()->getInterpreternameForFile( d->scriptfile );
00249             if(d->interpretername.isNull()) {
00250                 setException( new Exception(QString("Failed to determinate interpreter for scriptfile '%1'").arg(d->scriptfile)) );
00251                 return false;
00252             }
00253         }
00254 
00255         QFile f( d->scriptfile );
00256         if(! f.open(IO_ReadOnly)) {
00257             setException( new Exception(QString("Failed to open scriptfile '%1'").arg(d->scriptfile)) );
00258             return false;
00259         }
00260         d->code = QString( f.readAll() );
00261         f.close();
00262     }
00263 
00264     Interpreter* interpreter = Manager::scriptManager()->getInterpreter(d->interpretername);
00265     if(! interpreter) {
00266         setException( new Exception(QString("Unknown interpreter '%1'").arg(d->interpretername)) );
00267         return false;
00268     }
00269 
00270     d->script = interpreter->createScript(this);
00271     if(! d->script) {
00272         setException( new Exception(QString("Failed to create script for interpreter '%1'").arg(d->interpretername)) );
00273         return false;
00274     }
00275     if(d->script->hadException()) {
00276         setException( d->script->getException() );
00277         finalize();
00278         return false;
00279     }
00280     setException( 0 ); // clear old exception
00281 
00282     return true;
00283 }

bool Kross::Api::Event< Module >::isAFunction const QString name  )  const [inline, inherited]
 

Check if a function is a member of this Callable

Parameters:
name the function name
Returns:
true if the function is available in this Callable

Definition at line 187 of file event.h.

00188             {
00189                 return m_functions.contains(name);
00190             }

void Object::removeAllChildren  )  [inherited]
 

Remove all children.

Definition at line 104 of file object.cpp.

References QMap::clear().

00105 {
00106 #ifdef KROSS_API_OBJECT_REMCHILD_DEBUG
00107     kdDebug() << "Kross::Api::Object::removeAllChildren()" << endl;
00108 #endif
00109     m_children.clear();
00110 }

void Object::removeChild const QString name  )  [inherited]
 

Remove an existing child.

Parameters:
name The name of the Object to remove. If there doesn't exists an Object with such name just nothing will be done.

Definition at line 96 of file object.cpp.

References QMap::remove().

00097 {
00098 #ifdef KROSS_API_OBJECT_REMCHILD_DEBUG
00099     kdDebug() << QString("Kross::Api::Object::removeChild() name='%1'").arg(name) << endl;
00100 #endif
00101     m_children.remove(name);
00102 }

void ScriptContainer::setCode const QString code  )  [inherited]
 

Set the scriptcode this ScriptContainer holds.

Definition at line 117 of file scriptcontainer.cpp.

References Kross::Api::ScriptContainerPrivate::code, and Kross::Api::ScriptContainer::finalize().

00118 {
00119     finalize();
00120     d->code = code;
00121 }

void ScriptAction::setDescription const QString description  ) 
 

Set the description description for this ScriptAction .

Definition at line 152 of file scriptaction.cpp.

References description, and Kross::Api::ScriptActionPrivate::description.

00153 {
00154     d->description = description;
00155     setToolTip( description );
00156     setWhatsThis( description );
00157 }

void MainModule::setException Exception::Ptr  exception  )  [inherited]
 

Set the Exception this module throwed.

Parameters:
exception The Exception this module throws or NULL if you like to clear exception and to let hadException() return false.

Definition at line 68 of file mainmodule.cpp.

References Kross::Api::MainModulePrivate::exception.

Referenced by Kross::Api::ScriptContainer::classInstance(), Kross::Api::ScriptContainer::execute(), Kross::Api::Manager::getInterpreter(), and Kross::Api::ScriptContainer::initialize().

00069 {
00070     d->exception = exception;
00071 }

void ScriptContainer::setFile const QString scriptfile  )  [inherited]
 

Set the filename which will be executed on execute. The scriptfile needs to be a valid local file or QString::null if you don't like to use a file rather then the with setCode() defined scripting code.

Definition at line 139 of file scriptcontainer.cpp.

References Kross::Api::ScriptContainer::finalize(), and Kross::Api::ScriptContainerPrivate::scriptfile.

Referenced by ScriptAction().

00140 {
00141     finalize();
00142     d->scriptfile = scriptfile;
00143 }

void ScriptAction::setInterpreterName const QString name  ) 
 

Set the name of the interpreter which will be used on activation to execute the scripting code.

Parameters:
name The name of the Interpreter . This could be e.g. "python".

Reimplemented from Kross::Api::ScriptContainer.

Definition at line 159 of file scriptaction.cpp.

References Kross::Api::Manager::scriptManager(), and Kross::Api::ScriptContainer::setInterpreterName().

00160 {
00161     setEnabled( Manager::scriptManager()->hasInterpreterInfo(name) );
00162     Kross::Api::ScriptContainer::setInterpreterName(name);
00163 }

void ScriptContainer::setName const QString name  )  [inherited]
 

Set the name this ScriptContainer is reachable as.

Definition at line 107 of file scriptcontainer.cpp.

References Kross::Api::ScriptContainerPrivate::name.

00108 {
00109     d->name = name;
00110 }

bool ScriptContainer::setOption const QString  name,
const QVariant value
[inherited]
 

Set the Interpreter::Option value.

Definition at line 158 of file scriptcontainer.cpp.

References Kross::Api::Manager::getInterpreterInfo(), Kross::Api::InterpreterInfo::hasOption(), Kross::Api::ScriptContainerPrivate::interpretername, Kross::Api::ScriptContainerPrivate::options, QMap::replace(), Kross::Api::Manager::scriptManager(), and QVariant::toString().

00159 {
00160     Kross::Api::InterpreterInfo* info = Kross::Api::Manager::scriptManager()->getInterpreterInfo( d->interpretername );
00161     if(info) {
00162         if(info->hasOption(name)) {
00163             d->options.replace(name, value);
00164             return true;
00165         } else kdWarning() << QString("Kross::Api::ScriptContainer::setOption(%1, %2): No such option").arg(name).arg(value.toString()) << endl;
00166     } else kdWarning() << QString("Kross::Api::ScriptContainer::setOption(%1, %2): No such interpreterinfo").arg(name).arg(value.toString()) << endl;
00167     return false;
00168 }

void Kross::Api::ScriptAction::success  )  [signal]
 

This signal got emitted after this ScriptAction got executed successfully.

Referenced by activate().

const QString Object::toString  )  [virtual, inherited]
 

Returns:
a string representation of the object or it's content. This method is mainly used for debugging and testing purposes.

Reimplemented in Kross::Api::Dict, Kross::Api::Exception, Kross::Api::List, and Kross::Api::Variant.

Definition at line 54 of file object.cpp.

References QString::arg(), and Kross::Api::Object::getClassName().

00055 {
00056     return QString("%1 (%2)").arg(m_name).arg(getClassName());
00057 }


Member Data Documentation

ArgumentList Kross::Api::Callable::m_arglist [protected, inherited]
 

List of arguments this callable object supports.

Definition at line 123 of file callable.h.


The documentation for this class was generated from the following files:
Generated on Thu Feb 9 18:01:08 2006 for Kross by  doxygen 1.4.6