• Skip to content
  • Skip to link menu
KDE 4.0 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

Kross

  • Kross
  • Kross::Action
Public Slots | Signals | Public Member Functions

Kross::Action Class Reference

The Action class is an abstract container to deal with scripts like a single standalone scriptfile. More...

#include <action.h>

Inheritance diagram for Kross::Action:
Inheritance graph
[legend]

List of all members.

Public Slots

QString name () const
int version () const
QString description () const
void setDescription (const QString &description)
QString iconName () const
void setIconName (const QString &iconname)
bool isEnabled () const
void setEnabled (bool enabled)
QString file () const
bool setFile (const QString &scriptfile)
QByteArray code () const
void setCode (const QByteArray &code)
QString interpreter () const
void setInterpreter (const QString &interpretername)
QString currentPath () const

Signals

void updated ()
void started (Kross::Action *)
void finished (Kross::Action *)
void finalized (Kross::Action *)

Public Member Functions

 Action (QObject *parent, const QString &name, const QDir &packagepath=QDir())
 Action (QObject *parent, const QUrl &url)
virtual ~Action ()
void fromDomElement (const QDomElement &element)
QDomElement toDomElement () const
QMap< QString, QVariant > & options () const
QVariant option (const QString &name, const QVariant &defaultvalue=QVariant())
bool setOption (const QString &name, const QVariant &value)
QStringList functionNames ()
QVariant callFunction (const QString &name, const QVariantList &args=QVariantList())
bool initialize ()
void finalize ()
bool isFinalized () const

Detailed Description

The Action class is an abstract container to deal with scripts like a single standalone scriptfile.

Each action holds a reference to by the matching Kross::Interpreter created Kross::Script instance.

The Manager takes care of handling the Action instances application by providing access to ActionCollection containers for those Action instances.

Once you've such a Action instance you're able to perform actions with it like to execute scripting code.

Following sample shows "Hello World." executed with the python interpreter;

 # Create a new Kross::Action instance.
 Kross::Action* action = new Kross::Action(0,"MyFirstScript");
 # Set the interpreter we like to use. This could be e.g. "python", "ruby" or "kjs".
 action->setInterpreter("python");
 # Set the scripting code.
 action->setCode("print \"Hello World.\"");
 # Execute the scripting code.
 action->trigger();

Following sample demonstrates how to execute an external python script file. The script file itself is named "mytest.py" and contains;

 # this function got called from within C++
 def myfunction(args):
     print "Arguments are: %s" % args
 # Import the published QObject's
 import MyFirstQObject, MySecondQObject
 # Call a slot MyFirstQObject provides.
 MyFirstQObject.someSlot("Some string")
 # Set a property MySecondQObject provides.
 MySecondQObject.someProperty = "Other string"

Then you are able to load the script file, publish QObject instances and let the script do whatever it likes to do;

 # Publish a QObject instance for all Kross::Action instances.
 Kross::Manager::self().addObject(myqobject1, "MyFirstQObject")
 # Create a new Kross::Action instance.
 Kross::Action* action = new Kross::Action(0,"MySecondScript");
 # Publish a QObject instance only for the Kross::Action instance.
 action->addObject(myqobject2, "MySecondQObject");
 # Set the script file we like to execute.
 action->setFile("/home/myuser/mytest.py");
 # Execute the script file.
 action->trigger();
 # Call the "myfunction" defined in the "mytest.py" python script.
 QVariant result = action->callFunction("myfunction", QVariantList()<<"Arg");

Definition at line 92 of file action.h.


Constructor & Destructor Documentation

Action::Action ( QObject *  parent,
const QString &  name,
const QDir &  packagepath = QDir() 
)

Constructor.

Parameters:
parent The parent QObject this Action is child of.
name The unique name this Action has. It's used e.g. at the Manager to identify the Action. The name is accessible via QObject::objectName .

Definition at line 99 of file action.cpp.

Action::Action ( QObject *  parent,
const QUrl &  url 
)

Constructor.

Parameters:
parent The parent QObject this Action is child of.
url The URL should point to a valid scriptingfile. This Action will be filled with the content of the file (e.g. the file is readed and code should return it's content and it's also tried to determinate the interpreter ). Remember to use QUrl c'tor explicitly. The name will be set to url.path()

Definition at line 114 of file action.cpp.

Action::~Action (  )  [virtual]

Destructor.

Definition at line 131 of file action.cpp.


Member Function Documentation

QVariant Action::callFunction ( const QString &  name,
const QVariantList &  args = QVariantList() 
)

Call a function in the script.

Parameters:
name The name of the function which should be called.
args The optional list of arguments.

Definition at line 360 of file action.cpp.

QByteArray Action::code (  )  const [slot]
Returns:
the scriptcode this Action holds.

Definition at line 266 of file action.cpp.

QString Action::currentPath (  )  const [slot]
Returns:
the current path the script is running in or an empty string if there is no current path defined.

Definition at line 321 of file action.cpp.

QString Action::description (  )  const [slot]
Returns:
the optional description for this Action.

Definition at line 232 of file action.cpp.

QString Action::file (  )  const [slot]
Returns:
the scriptfile that should be executed.

Definition at line 295 of file action.cpp.

void Action::finalize (  ) 

Finalize the Script instance and free's any cached or still running executions.

Normaly it's not needed to call this function direct cause the Action will take care of calling it if needed.

Definition at line 417 of file action.cpp.

void Kross::Action::finalized ( Kross::Action *   )  [signal]

This signal is emitted once a script finalized.

void Kross::Action::finished ( Kross::Action *   )  [signal]

This signal is emitted after the script got executed.

void Action::fromDomElement ( const QDomElement &  element  ) 

Method to read settings from the QDomElement element that contains details about e.g.

the displayed text, the file to execute or the used interpreter.

Definition at line 140 of file action.cpp.

QStringList Action::functionNames (  ) 
Returns:
the list of functionnames.

Definition at line 351 of file action.cpp.

QString Action::iconName (  )  const [slot]

Return the name of the icon.

Definition at line 243 of file action.cpp.

bool Action::initialize (  ) 

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 ).

Returns:
true if the initialization was successfully else false is returned.

Definition at line 369 of file action.cpp.

QString Action::interpreter (  )  const [slot]
Returns:
the name of the interpreter. Could be for example "python" or "ruby".

Definition at line 280 of file action.cpp.

bool Action::isEnabled (  )  const [slot]

Return true if this Action is enabled else false is returned.

Definition at line 255 of file action.cpp.

bool Action::isFinalized (  )  const
Returns:
true if the action is finalized what means the action is currently not running.

Definition at line 425 of file action.cpp.

QString Action::name (  )  const [slot]
Returns:
the objectName for this Action.

Definition at line 222 of file action.cpp.

QVariant Action::option ( const QString &  name,
const QVariant &  defaultvalue = QVariant() 
)
Returns:
the value of the option defined with name . If there doesn't exists an option with such a name, the defaultvalue is returned.

Definition at line 331 of file action.cpp.

QMap< QString, QVariant > & Action::options (  )  const
Returns:
a map of options this Action defines. The options are returned call-by-ref, so you are able to manipulate them.

Definition at line 326 of file action.cpp.

void Action::setCode ( const QByteArray &  code  )  [slot]

Set the scriptcode code this Action should execute.

Definition at line 271 of file action.cpp.

void Action::setDescription ( const QString &  description  )  [slot]

Set the optional description for this Action.

Definition at line 237 of file action.cpp.

void Action::setEnabled ( bool  enabled  )  [slot]

Set the enable state of this Action to enabled .

Definition at line 260 of file action.cpp.

bool Action::setFile ( const QString &  scriptfile  )  [slot]

Set the scriptfile that should be executed.

Definition at line 300 of file action.cpp.

void Action::setIconName ( const QString &  iconname  )  [slot]

Set the name of the icon to iconname .

Definition at line 248 of file action.cpp.

void Action::setInterpreter ( const QString &  interpretername  )  [slot]

Set the name of the interpreter (javascript, python or ruby).

Definition at line 285 of file action.cpp.

bool Action::setOption ( const QString &  name,
const QVariant &  value 
)

Set the Interpreter::Option value.

Definition at line 339 of file action.cpp.

void Kross::Action::started ( Kross::Action *   )  [signal]

This signal is emitted before the script got executed.

QDomElement Action::toDomElement (  )  const
Returns:
a QDomElement that contains the settings like e.g. the displayed text, the file to execute or the used interpreter of this Action instance.

Definition at line 192 of file action.cpp.

void Kross::Action::updated (  )  [signal]

This signal is emitted if the content of the Action was changed.

The ActionCollection instances this Action is child of are connected with this signal to fire up there own updated signal if an Action of them was updated.

int Action::version (  )  const [slot]
Returns:
the version number this Action has. Per default 0 is returned.

Definition at line 227 of file action.cpp.


The documentation for this class was generated from the following files:
  • action.h
  • action.cpp

Kross

Skip menu "Kross"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • KIO
  • KIOSlave
  • KJS
  • KJSEmbed
  •   WTF
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  •   core
  • Phonon
  •   Backend
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.7.1
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal