Debian Codegraph @

doc/script.txt

raw
1 Introduction:
2
3 Starting from the version 0.5.6, QTerm supports scripts with QtScript. With
4 the greatest and latest script support in QTerm, you can:
5
6 1. Do boring and repeating operation automatically.
7 2. Change the default behavior of QTerm with system scripts.
8 3. Try new functions with script (In order to do this you might want to have
9 Qt bindings for QtScript installed, they can be downloaded from
10 http://labs.trolltech.com/page/Projects/QtScript/Generator)
11
12 ================================================================================
13
14 How to Use:
15
16 You can run simple scripts using Script->Run, for example, save the following
17 code
18
19 for (var i = 0; i < 10; i++)
20 QTerm.sendString("q");
21
22 to a script file, run it in QTerm will send 10 q's to the server.
23
24 To use the system control script. Open the address book, in the very end of
25 the General tab. First enable the Load Control Script checkbox, then choose
26 your system script.
27
28 ================================================================================
29
30 How to Debug:
31
32 If you want to develop serious/complicate scripts for QTerm, it is very
33 helpful to have QScriptEngineDebugger enable. This feature is introduced in Qt
34 4.5, make sure your qt is new enough. Then you can run cmake with
35 -DQTERM_ENABLE_SCRIPT_DEBUGGER=ON, for example:
36
37 cmake .. -DQTERM_ENABLE_SCRIPT_DEBUGGER=ON
38
39 Then do the usual make, make install to install QTerm
40
41 After you enable the debugger. It will pop up every time the script engine
42 catches a exception. You can also call the debugger any time by Script->Debug.
43
44 ================================================================================
45
46 How To Write a Script
47
48 Here is a list of functions you can call in the scripts, they are all in the
49 "QTerm" object, so for example if you want to call "version()" you should call
50 "QTerm.version()" instead.
51
52 QString version()
53 Return the version of QTerm.
54
55 int caretX()
56 int caretY()
57 Return the x or y coordinate of the current position of caret.
58
59 int columns()
60 int rows()
61 Return the number of columns or rows of the current window.
62
63 int charX(int x, int y)
64 int charY(int x, int y)
65 Given the graphical coordinate in the current window, convert it to the
66 text coordinate.
67
68 int posX()
69 int posY()
70 Return the x or y coordinate of the mouse.
71
72 QString getUrl()
73 QString getIP()
74 Return the URL or IP address under the mouse pointer, if no url is
75 detected an empty string will be returned.
76
77 bool isConnected()
78 Check if the current window is conneced to a BBS server.
79
80 void reconnect()
81 Reconnect to the BBS server, do nothing if the current window is already
82 connected.
83 void disconnect()
84 Disconnect from the current BBS server.
85
86 void buzz()
87 Shake QTerm.
88
89 void sendString(const QString & string)
90 Send string to the BBS server.
91
92 void sendParsedString(const QString & string)
93 Send parsed string to the BBS server. you can use '^M' to represent the
94 return key for example.
95
96 void osdMessage(const QString & message, int icon = 1, int duration = 0)
97 Show message in the osd, icon = 0, 1, 2, 3 means No/Info/Warning/Error
98 icon. Duration is in the unit of ms, 0 means forever.
99
100 void showMessage(const QString & message, int duration = -1)
101 Show message in the notification area or system tray. duration is not
102 really useful for now.
103
104 void cancelZmodem()
105 Cancel the current zmodem transfer.
106
107 void setZmodemFileList(const QStringList & fileList)
108 Set the list of files you want to upload with zmodem. call it before your
109 start zmodem to avoid the file selection dialog.
110
111 QScriptValue getLine(int line)
112 Get the object represent the 'line' line text.
113
114 QScriptValue window()
115 Return the current window object.
116
117 bool addPopupMenu(QString id, QString menuTitle, QString icon = "QTerm")
118 Add a menu item to the popup menu, you can access to the new action with
119 QTerm.id property if the method succeed. menuTitle is the text displayed
120 in the menu. currently icon parameter has no effect. Return true if
121 succeed, otherwise it will return false.
122
123 bool addUrlMenu(QString id, QString menuTitle, QString icon = "QTerm")
124 Add a menu item to the url popup menu, you can access to the new action
125 with QTerm.id property if the method succeed. menuTitle is the text
126 displayed in the menu. currently icon parameter has no effect. Return true
127 if succeed, otherwise it will return false.
128
129 void addPopupSeparator()
130 void addUrlSeparator()
131 Add separators to the popup/url menu so they will look nicer.
132
133 void loadScript(const QString & filename)
134 Import external javascript files, QTerm will search the file under the
135 "scripts" directory under the local path (e.g.SHOME/.qterm) first and then
136 search the global path (e.g. /usr/share)
137
138 void globalPath()
139 Return the global data path, for example, if you installed QTerm to /usr,
140 then it will return /usr/share.
141
142 void localPath()
143 Return the local data path, $HOME/.qterm under Linux.
144
145 QString getSelectedText(bool rect = false, bool color = false, const QString & escape = "")
146 Return the current selected region. rect should always be false currently.
147 color indicate if you want the copy the attribute of the text, escape is
148 only useful when color is true, indicate how you want to represent the
149 escape sequence.
150
151 void openUrl(const QString & url)
152 Open the url using the http browser specified in QTerm.
153
154 void loadExtension(const QString & extension)
155 Load extension, if you want to use the classes in Qt bindings, you
156 need to load them first.
157
158 ================================================================================
159
160 How to Write a System Script
161
162 In order to change the behavior of QTerm. You can reimplement the following
163 functions in the system script, again all the functions are members of 'QTerm'
164 object, for example init() should be understand as QTerm.init():
165
166 There is a property which is important for this usage: QTerm.accepted. It
167 should be set to true if you do not want the native QTerm code to handle the
168 event any further, otherwise it should set to false.
169
170 init()
171 This function is called every time the system script is loaded. You can
172 show messages or initiate some variables here.
173
174 setCursorType(x,y)
175 Determine what kind of mouse cursor should be shown in the current
176 context, if mouse release events is not handle by the script this function
177 also determine how the mouse release will be handled.
178
179 setPageState()
180 Determine the current state of the BBS page, useful for further determine
181 the mouse behavior
182
183 setSelectRect(x,y)
184 Determine if the text under mouse cursor is clickable, x and y is
185 the mouse text coordinate. Return an 4-int array (x,y,w,h)
186
187 onMouseEvent(type, button, buttons, modifiers, pt_x, pt_y)
188 Handle the mouse event, type, button, buttons, modifiers follow the
189 definition in QMouseEvent, pt_x and pt_y is the graphical coordinate of the
190 mouse pointer.
191
192 onKeyPressEvent(key, modifiers, text)
193 Handle the key press event, the definition of the arguments again follows
194 QKeyEvent.
195
196 onWheelEvent(delta, buttons, modifiers, orientation, pt_x, pt_y)
197 Handle the mouse wheel event, the definition of delta, button, modifiers,
198 and orientation follow QWheelEvent. pt_x and pt_y is the graphical
199 coordinate of the mouse pointer.
200
201 onNewData()
202 The function will be called every time QTerm gets new data, you can
203 manipulate the received data a little bit.
204
205 antiIdle()
206 Determine how the anti idle event should be handled.
207
208 autoReply()
209 Determine how to reply the incoming message. Useful for those who want to
210 write BBS robots.
211
212 checkUrl()
213 Determine if there is a URL under the mouse pointer, return the URL if
214 found, otherwise return a empty string.
215
216 checkIP()
217 Determine if there is a IP address under the mouse pointer, return the URL
218 if found, otherwise return a empty string.
219
220 onTelnetState(int state)
221 Handle telnet events
222
223 onZmodemState(int type, int value, const QString& msg)
224 Handle zmodem events
225
226 endOfArticle()
227 Implement this to check the end of articles for downloading articles
228
229 There is also a signal: scriptEvent(const QString& type) which can be used by
230 the script to emit and handle signals
231
232 ================================================================================
233
234 Example Scripts:
235
236 There are several examples provided in the QTerm source code, you can use them
237 in you script or get a feeling about how the scripts can be used.
238
239 utils.js
240 This script provides useful auxiliary functions to save a few keystrokes
241 for you.
242 article.js
243 This script provides basic article downloading functionality, note that
244 the downloading operation is not well handled right now. Do this through
245 the upcoming dbus interface might be a better idea.
246
247 highlight.js
248 This script will highlight keywords your specified in the code if they are
249 found in the current page.
250
251 console.js
252 This script gives you a console to test different script functions. Steal
253 from the great Amarok. You need qt bindings to run it.
254
255 websnap.js
256 This script, modified from the code in graphics dojo
257 (http://qt.gitorious.org/qt-labs/graphics-dojo/trees/master/websnap),
258 generates webpage snapshot. Currently it has troubles with webpage with
259 frames, you are more than welcome to improve this if you are interested.
260
261 smth.js
262 Sample system script for newsmth.net.
263
264 ptt.js
265 Sample system script for ptt.cc.