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

kstars

  • sources
  • kde-4.12
  • kdeedu
  • kstars
  • kstars
  • tools
scriptfunction.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  scriptfunction.cpp - description
3  -------------------
4  begin : Thu Apr 17 2003
5  copyright : (C) 2003 by Jason Harris
6  email : kstars@30doradus.org
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #include "scriptfunction.h"
19 
20 #include <qstringlist.h>
21 #include <kdebug.h>
22 
23 ScriptFunction::ScriptFunction( const QString &name, const QString &desc,
24  bool clockfcn, const QString &at1, const QString &an1,
25  const QString &at2, const QString &an2,
26  const QString &at3, const QString &an3,
27  const QString &at4, const QString &an4,
28  const QString &at5, const QString &an5,
29  const QString &at6, const QString &an6 ) : INDIProp(QString()) {
30  Name = name;
31  ClockFunction = clockfcn;
32 
33  ArgType[0] = at1; ArgDBusType[0] = DBusType(at1); ArgName[0] = an1;
34  ArgType[1] = at2; ArgDBusType[1] = DBusType(at2); ArgName[1] = an2;
35  ArgType[2] = at3; ArgDBusType[2] = DBusType(at3); ArgName[2] = an3;
36  ArgType[3] = at4; ArgDBusType[3] = DBusType(at4); ArgName[3] = an4;
37  ArgType[4] = at5; ArgDBusType[4] = DBusType(at5); ArgName[4] = an5;
38  ArgType[5] = at6; ArgDBusType[5] = DBusType(at6); ArgName[5] = an6;
39 
40  //Construct a richtext description of the function
41  QString nameStyle = "<span style=\"font-family:monospace;font-weight:600\">%1</span>"; //bold
42  QString typeStyle = "<span style=\"font-family:monospace;color:#009d00\">%1</span>"; //green
43  QString paramStyle = "<span style=\"font-family:monospace;color:#00007f\">%1</span>"; //blue
44 
45  Description = "<html><head><meta name=\"qrichtext\" content=\"1\" /></head>";
46  Description += "<body style=\"font-size:11pt;font-family:sans\">";
47  Description += "<p>" + nameStyle.arg( Name + '(' );
48 
49  NumArgs = 0;
50  if ( ! at1.isEmpty() && ! an1.isEmpty() ) {
51  Description += ' ' + typeStyle.arg( at1 );
52  Description += ' ' + paramStyle.arg( an1 );
53  NumArgs++;
54  }
55 
56  if ( ! at2.isEmpty() && ! an2.isEmpty() ) {
57  Description += ", " + typeStyle.arg( at2 );
58  Description += ' ' + paramStyle.arg( an2 );
59  NumArgs++;
60  }
61 
62  if ( ! at3.isEmpty() && ! an3.isEmpty() ) {
63  Description += ", " + typeStyle.arg( at3 );
64  Description += ' ' + paramStyle.arg( an3 );
65  NumArgs++;
66  }
67 
68  if ( ! at4.isEmpty() && ! an4.isEmpty() ) {
69  Description += ", " + typeStyle.arg( at4 );
70  Description += ' ' + paramStyle.arg( an4 );
71  NumArgs++;
72  }
73 
74  if ( ! at5.isEmpty() && ! an5.isEmpty() ) {
75  Description += ", " + typeStyle.arg( at5 );
76  Description += ' ' + paramStyle.arg( an5 );
77  NumArgs++;
78  }
79 
80  if ( ! at6.isEmpty() && ! an6.isEmpty() ) {
81  Description += ", " + typeStyle.arg( at6 );
82  Description += ' ' + paramStyle.arg( an6 );
83  NumArgs++;
84  }
85 
86  //Set Valid=false if there are arguments (indicates that this fcn's args must be filled in)
87  Valid = true;
88  if ( NumArgs ) Valid = false;
89 
90  //Finish writing function prototype
91  if ( NumArgs ) Description += ' ';
92  Description += nameStyle.arg( ")" ) + "</p><p>";
93 
94  //Add description
95  Description += desc;
96 
97  //Finish up
98  Description += "</p></body></html>";
99 }
100 
101 //Copy constructor
102 ScriptFunction::ScriptFunction( ScriptFunction *sf )
103 {
104  Name = sf->name();
105  Description = sf->description();
106  ClockFunction = sf->isClockFunction();
107  NumArgs = sf->numArgs();
108  INDIProp = sf->INDIProperty();
109  Valid = sf->valid();
110 
111  for ( unsigned int i=0; i<6; i++ ) {
112  ArgType[i] = sf->argType(i);
113  ArgName[i] = sf->argName(i);
114  ArgDBusType[i] = sf->argDBusType(i);
115  //ArgVal[i] .clear();
116  // JM: Some default argument values might be passed from another object as well
117  ArgVal[i] = sf->argVal(i);
118  }
119 }
120 
121 ScriptFunction::~ScriptFunction()
122 {
123 }
124 
125 QString ScriptFunction::DBusType(const QString &type)
126 {
127 
128  if (type == QString("int"))
129  return QString("int32");
130  else if (type == QString("uint"))
131  return QString("uint32");
132  else if (type == QString("double"))
133  return type;
134  else if (type == QString("QString"))
135  return QString("string");
136  else if (type == QString("bool"))
137  return QString("boolean");
138 
139  return NULL;
140 }
141 
142 QString ScriptFunction::prototype() const {
143  QString p = Name + '(';
144 
145  bool args( false );
146  if ( ! ArgType[0].isEmpty() && ! ArgName[0].isEmpty() ) {
147  p += ' ' + ArgType[0];
148  p += ' ' + ArgName[0];
149  args = true; //assume that if any args are present, 1st arg is present
150  }
151 
152  if ( ! ArgType[1].isEmpty() && ! ArgName[1].isEmpty() ) {
153  p += ", " + ArgType[1];
154  p += ' ' + ArgName[1];
155  }
156 
157  if ( ! ArgType[2].isEmpty() && ! ArgName[2].isEmpty() ) {
158  p += ", " + ArgType[2];
159  p += ' ' + ArgName[2];
160  }
161 
162  if ( ! ArgType[3].isEmpty() && ! ArgName[3].isEmpty() ) {
163  p += ", " + ArgType[3];
164  p += ' ' + ArgName[3];
165  }
166 
167  if ( ! ArgType[4].isEmpty() && ! ArgName[4].isEmpty() ) {
168  p += ", " + ArgType[4];
169  p += ' ' + ArgName[4];
170  }
171 
172  if ( ! ArgType[5].isEmpty() && ! ArgName[5].isEmpty() ) {
173  p += ", " + ArgType[5];
174  p += ' ' + ArgName[5];
175  }
176 
177  if ( args ) p += ' ';
178  p += ')';
179 
180  return p;
181 }
182 
183 QString ScriptFunction::scriptLine() const {
184  QString out( Name );
185  QString dbus_type;
186  unsigned int i=0;
187 
188  while ( ! ArgName[i].isEmpty() && i < 6 )
189  {
190  //Make sure strings are quoted
191  QString value = ArgVal[i];
192  if ( ArgDBusType[i] == "string" ) {
193  if ( value.isEmpty() ) {
194  value = "\"\"";
195  } else {
196  if ( value.left(1) != "\"" && value.left(1) != "\'" ) {
197  value = '\"' + value;
198  }
199  if ( value.right(1) != "\"" && value.right(1) != "\'" ) {
200  value = value + '\"';
201  }
202  }
203  }
204 
205  // Write DBus style prototype compatible with dbus-send format
206  out += ' ' + ArgDBusType[i] + ':' + value;
207  ++i;
208  }
209 
210  return out;
211 }
ScriptFunction::argDBusType
QString argDBusType(unsigned int n) const
Definition: scriptfunction.h:47
ScriptFunction::numArgs
int numArgs() const
Definition: scriptfunction.h:57
ScriptFunction::argVal
QString argVal(unsigned int n) const
Definition: scriptfunction.h:46
ScriptFunction::ScriptFunction
ScriptFunction(const QString &name, const QString &desc, bool clockfcn=false, const QString &at1=QString(), const QString &an1=QString(), const QString &at2=QString(), const QString &an2=QString(), const QString &at3=QString(), const QString &an3=QString(), const QString &at4=QString(), const QString &an4=QString(), const QString &at5=QString(), const QString &an5=QString(), const QString &at6=QString(), const QString &an6=QString())
Definition: scriptfunction.cpp:23
ScriptFunction::isClockFunction
bool isClockFunction() const
Definition: scriptfunction.h:53
ScriptFunction::argName
QString argName(unsigned int n) const
Definition: scriptfunction.h:45
ScriptFunction::argType
QString argType(unsigned int n) const
Definition: scriptfunction.h:44
ScriptFunction::valid
bool valid() const
Definition: scriptfunction.h:50
ScriptFunction::name
QString name() const
Definition: scriptfunction.h:41
ScriptFunction::prototype
QString prototype() const
Definition: scriptfunction.cpp:142
ScriptFunction::INDIProperty
QString INDIProperty() const
Definition: scriptfunction.h:62
ScriptFunction::DBusType
QString DBusType(const QString &type)
Definition: scriptfunction.cpp:125
ScriptFunction::scriptLine
QString scriptLine() const
Definition: scriptfunction.cpp:183
ScriptFunction
Jason Harris.
Definition: scriptfunction.h:27
scriptfunction.h
ScriptFunction::~ScriptFunction
~ScriptFunction()
Definition: scriptfunction.cpp:121
ScriptFunction::description
QString description() const
Definition: scriptfunction.h:43
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:36:20 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kstars

Skip menu "kstars"
  • 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