• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

parley

  • sources
  • kde-4.12
  • kdeedu
  • parley
  • src
  • scripts
script.cpp
Go to the documentation of this file.
1 /***************************************************************************
2 
3  Copyright 2008 Avgoustinos Kadis <avgoustinos.kadis@kdemail.net>
4 
5  ***************************************************************************/
6 
7 /***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 #include "script.h"
16 
17 #include <KDebug>
18 #include <KLocale>
19 
20 #include <kross/core/action.h>
21 
22 
23 Script::Script ( QString file )
24 {
25  m_file = file;
26  m_activated = false;
27 }
28 
29 
30 Script::~Script()
31 {
32  delete m_object;
33 }
34 
35 
36 bool Script::isActivated()
37 {
38  return m_activated;
39 }
40 
41 
42 void Script::activate()
43 {
44  kDebug() << "Activating Script" << fileName();
45  if ( isActivated() )
46  {
47  kDebug() << "Script already activated";
48  return;
49  }
50  if ( !exists() )
51  {
52  kDebug() << "Script file given does not exist";
53  m_errorMessage = i18n("The script file does not exist.");
54  return;
55  }
56 
57  // Create the script container. m_object is the parent QObject,
58  // so that our action instance will be destroyed once the m_object
59  // is destroyed.
60  m_object = new QObject();
61  Kross::Action* action = new Kross::Action ( m_object, m_file );
62  // Publish our myobject instance and connect signals with
63  // scripting functions.
64  QMapIterator<QString,QObject*> i ( m_scriptObjects );
65  while ( i.hasNext() )
66  {
67  i.next();
68  kDebug() << i.key();
69  action->addObject ( i.value() , i.key(), Kross::ChildrenInterface::AutoConnectSignals );
70  }
71 
72  // Set the file to be execute
73  action->setFile ( m_file );
74 
75  // Execute the script.
76  action->trigger();
77 
78  m_activated = !action->isFinalized();
79  if (!m_activated) {
80  kDebug() << "Script not activated";
81  QString msg = action->errorMessage();
82  QString trace = action->errorTrace();
83  msg.replace('<', "&lt;").replace('\n',"<br/>");
84  trace.replace('<', "&lt;").replace('\n',"<br/>");
85  m_errorMessage = "<p><strong>"+i18n("Error in file %1 at line %2:", fileName(),
86  action->errorLineNo())+"</strong><br/>"+msg+"<br/><strong>"
87  +i18nc("debug information in error message", "Backtrace:")+
88  "</strong><br/>"+trace+"</p>";
89  }
90 }
91 
92 
93 void Script::deactivate()
94 {
95  delete m_object;
96  m_activated = false;
97 }
98 
99 
100 bool Script::exists()
101 {
102  QFileInfo fileInfo ( m_file );
103  return fileInfo.exists();
104 }
105 
106 
107 QString Script::fileName()
108 {
109  return m_file;
110 }
111 
112 
113 void Script::addObject ( QString name, QObject * object )
114 {
115  m_scriptObjects.insert ( name,object );
116 }
117 
118 
119 void Script::addObjects ( QMap<QString,QObject*> objects )
120 {
121  m_scriptObjects.unite ( objects );
122 }
123 
124 QString Script::errorMessage()
125 {
126  return m_errorMessage;
127 }
Script::addObjects
void addObjects(QMap< QString, QObject * > objects)
Adds more than one scripting Objects to the script.
Definition: script.cpp:119
Script::isActivated
bool isActivated()
Returns true if the script was successfully activated; false otherwise.
Definition: script.cpp:36
QObject
script.h
Script::deactivate
void deactivate()
Deactivate the script.
Definition: script.cpp:93
Script::errorMessage
QString errorMessage()
Returns an html error message if there have been errors in the script.
Definition: script.cpp:124
Script::~Script
~Script()
Definition: script.cpp:30
Script::fileName
QString fileName()
Returns the file that was given as parameter to the constructor.
Definition: script.cpp:107
Script::activate
void activate()
Activates the script.
Definition: script.cpp:42
Script::addObject
void addObject(QString name, QObject *object)
Add an object to be accessible by the script.
Definition: script.cpp:113
Script::exists
bool exists()
Checks if the script file assigned to the Script object exists as a file on the given path...
Definition: script.cpp:100
Script::Script
Script(QString file)
Script class constructor.
Definition: script.cpp:23
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:42:06 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

parley

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

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal