Mercurial > pidgin.yaz
comparison doc/TCL-HOWTO.dox @ 10409:68d6065fc32f
[gaim-migrate @ 11657]
sf patch #1083616, from Balwinder Singh Dheeman
Convert the TCL-HOWTO to a doxygen version
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Fri, 24 Dec 2004 02:50:25 +0000 |
parents | |
children | f7878475292c |
comparison
equal
deleted
inserted
replaced
10408:f53c59c95f03 | 10409:68d6065fc32f |
---|---|
1 /** @page tcl-howto Tcl Scripting HOWTO | |
2 | |
3 @section Intoduction | |
4 | |
5 The Gaim Tcl interface provides a Tcl API for many useful gaim | |
6 functions. Like the perl API, the Tcl API does not provide | |
7 access to every corner of gaim exposed by the @e C interface. It does, | |
8 however, provide a very powerful interface to many of Gaim's functions | |
9 through a simple to learn and extend scripting language. | |
10 | |
11 If you are not familiar with Tcl, you will probably find it somewhat | |
12 different from what you are used to. Despite being somewhat unique | |
13 (more akin to shell programming than other traditional scripting | |
14 languages such as @e perl or @e python), it is simple to learn for | |
15 beginners and experienced programmers alike. There are numerous books | |
16 on the subject; we will not discuss it any further here. | |
17 | |
18 @section start Getting Started | |
19 | |
20 The only requirement placed on a Gaim Tcl script by Gaim is the | |
21 existence of a procedure called @c plugin_init. This procedure has | |
22 some limitations placed upon it; it will be parsed and evaluated before | |
23 the rest of the Tcl script, so it cannot reference any other variables | |
24 or procedures declared in the script. In practice this is not a | |
25 problem, as the only thing this procedure should do is return a simple | |
26 list containing five items: the @b name of the script, its @b version | |
27 number, a @b summary (just a few words) of its function, a short (longer | |
28 than the summary, but no more than a couple of sentences if possible) | |
29 @b description, the @b author, and a @b URL to web page. For example: | |
30 | |
31 @code | |
32 proc plugin_init { } { | |
33 return [ list "Example Plugin" \ | |
34 "1.0" \ | |
35 "Example plugin registration" \ | |
36 "Example of how to register a plugin for the Tcl HOWTO" \ | |
37 "Ethan Blanton <eblanton@cs.purdue.edu>" \ | |
38 "http://gaim.sf.net/" ] | |
39 } | |
40 @endcode | |
41 | |
42 The rest of the script will generally be registration to recieve | |
43 notification of various Gaim signals (more about this below) and | |
44 definitions of procedures to be executed when those signals occur. | |
45 | |
46 @section details Interpreter Details | |
47 | |
48 Gaim initializes and drives the Tcl event loop (similar to Tk), | |
49 meaning that commands like @c fileevent and @c after are available and | |
50 do not require @c vwait etc. The @c vwait actually seems to be somewhat | |
51 broken due to a bug somewhere in the Tcl/Glib event loop glue, and it | |
52 should not be used for now. | |
53 | |
54 The gaim-specific functions are provided in a statically-linked | |
55 package called @c gaim; this means that if you spawn a child | |
56 interpreter and wish to use the gaim-specific functions, you will need | |
57 to execute <tt>load {} gaim</tt> in that interpreter. | |
58 | |
59 @section internals Gaim Internal Procedures and Variables | |
60 | |
61 All of the information provided for your use by Gaim will be in the @c | |
62 ::gaim namespace. This means that in order to access it you will either | |
63 have to import the gaim namespace (e.g. via the command <tt>namespace | |
64 import gaim::*</tt>) or reference it explicitly. The following | |
65 descriptions will reference it explicitly for clarity. | |
66 | |
67 @li Variables | |
68 | |
69 @code | |
70 gaim::version | |
71 @endcode | |
72 | |
73 This contains the version of the gaim process which loaded the | |
74 script. | |
75 | |
76 @li Commands | |
77 | |
78 @code | |
79 gaim::account alias account | |
80 gaim::account connect account | |
81 gaim::account connection account | |
82 gaim::account disconnect account | |
83 gaim::account find username protocol | |
84 gaim::account handle | |
85 gaim::account isconnected account | |
86 gaim::account list ?option? | |
87 gaim::account protocol account | |
88 gaim::account username account | |
89 @endcode | |
90 | |
91 The @c gaim::account command consists of a set of subcommands | |
92 pertaining to gaim accounts. | |
93 | |
94 @c alias returns the alias for the account @c account. If there is no | |
95 alias for the given account, it returns the empty string. | |
96 | |
97 The subcommand @c connect connects the named account if it is not | |
98 connected, and does nothing if it is. In either case, it returns | |
99 the @c gc for the account. | |
100 | |
101 @c connection returns the @c gc of the given account if it is connected, | |
102 or 0 if it is not. This @c gc is the gc used by gaim::connection and | |
103 other functions. | |
104 | |
105 @c disconnect disconnects the given @c account if it is connected, or | |
106 does nothing if it is. | |
107 | |
108 @c find finds an account by its @c username and @c protocol (as returned by | |
109 <tt>gaim::account username</tt> and <tt>gaim::account protocol</tt>) and | |
110 returns the account if found, or 0 otherwise. | |
111 | |
112 @c handle returns the instance handle required to connect to account | |
113 signals. (See <tt>gaim::signal connect</tt>). | |
114 | |
115 The @c isconnected query returns true if the given account is | |
116 connected and false otherwise. | |
117 | |
118 The @c list subcommand returns a list of all of the accounts known to | |
119 Gaim. The elements of this lists are accounts appropriate for the | |
120 @c account argument of the other subcommands. The @c -all option | |
121 (default) returns all accounts, while the @c -online option returns | |
122 only those accounts which are online. | |
123 | |
124 The @c protocol subcommand returns the protocol ID (e.g. "prpl-msn") | |
125 for the given account. | |
126 | |
127 The @c username subcommand returns the username for the account | |
128 @c account. | |
129 | |
130 @code | |
131 gaim::buddy alias buddy | |
132 gaim::buddy handle | |
133 gaim::buddy info ( buddy | account username ) | |
134 gaim::buddy list | |
135 @endcode | |
136 | |
137 @c gaim::buddy is a set of commands for retrieving information about | |
138 buddies and manipulating the buddy list. For the purposes of Tcl, | |
139 a "buddy" is currently a list of several elements, the first of | |
140 which being the type. The currently recognized types are "group", | |
141 "buddy", and "chat". A group node looks like: | |
142 @code | |
143 { group name { buddies } } | |
144 @endcode | |
145 A buddy node is: | |
146 @code | |
147 { buddy name account } | |
148 @endcode | |
149 And a chat node is: | |
150 @code | |
151 { chat alias account } | |
152 @endcode | |
153 | |
154 The @c alias subcommand returns the alias for the given buddy if it | |
155 exists, or the empty string if it does not. | |
156 | |
157 @c handle returns the blist handle for the purposes of connecting | |
158 signals to buddy list events. (See <tt>gaim::signal connect</tt>). | |
159 | |
160 @c info causes gaim to display the info dialog for the given buddy. | |
161 Since it is possible to request user info for a buddy not in your | |
162 buddy list, you may also specify a buddy by his or her username and | |
163 the account through which you wish to retrieve info. | |
164 | |
165 @c list returns a list of @c group structures, filled out with buddies | |
166 and chats as described above. | |
167 | |
168 @code | |
169 gaim::connection account gc | |
170 gaim::connection displayname gc | |
171 gaim::connection handle | |
172 gaim::connection list | |
173 @endcode | |
174 | |
175 @c gaim::connection is a collection of subcommands pertaining to | |
176 account connections. | |
177 | |
178 @c account returns the Gaim account associated with @c gc. This | |
179 account is the same account used by @c gaim::account and other | |
180 commands. | |
181 | |
182 @c displayname returns the display name (duh) of @c gc as reported by | |
183 <tt>gaim_connection_get_display_name(gc)</tt>. | |
184 | |
185 @c handle returns the gaim connections instance handle. (See | |
186 <tt>gaim::signal connect</tt>). | |
187 | |
188 @c list returns a list of all known connections. The elements of | |
189 this list are appropriate as @c gc arguments to the other | |
190 @c gaim::connection subcommands or other commands requiring a gc. | |
191 | |
192 @code | |
193 gaim::conv_send account who text | |
194 @endcode | |
195 | |
196 @c gaim::conv is simply a convenience wrapper for @c gaim::send_im and | |
197 <tt>gaim::conversation write</tt>. It sends the IM, determines the from | |
198 and to arguments for <tt>gaim::conversation write</tt>, and prints the text | |
199 sent to the conversation as one would expect. For the curious, you | |
200 may view the source for it by typing <tt>info body gaim::conv_send</tt> at | |
201 a Gaim Commander prompt. | |
202 | |
203 Note that an error in either @c gaim::send_im or <tt>gaim::conversation | |
204 write</tt> will not be caught by this procedure, and will be propagated | |
205 to the caller. | |
206 | |
207 @code | |
208 gaim::conversation find ?-account account? name | |
209 gaim::conversation handle | |
210 gaim::conversation list | |
211 gaim::conversation new ?-chat? ?-im? account name | |
212 gaim::conversation write conversation style from to text | |
213 @endcode | |
214 | |
215 @c gaim::conversation provides an API for dealing with conversations. | |
216 Given that Gaim is an instant messenger program, you'll probably | |
217 spend a lot of time here. | |
218 | |
219 The command @c find attempts to find an existing conversation with | |
220 username @c name. If the @c -account option is given, it refines its | |
221 search to include only conversations on that account. | |
222 | |
223 @c handle returns the conversations instance handle for the purposes | |
224 of signal connection. (See <tt>gaim::signal connect</tt>). | |
225 | |
226 @c list returns a list of all currently open conversations. | |
227 | |
228 The @c new subcommand can be used to create a new conversation with | |
229 a specified user on a specified account if one does not exist, or | |
230 retrieve the existing conversation if it does. The @c -chat and | |
231 @c -im options specify whether the created conversation should be a | |
232 chat or a standard IM, respectively. | |
233 | |
234 @c write is used to write to the specified conversation. The @c style | |
235 argument specifies how the text should be printed -- as text coming | |
236 from the gaim user (style @c send), being sent to the gaim user | |
237 (style @c recv), or as a system message (such as "so-and-so has | |
238 signed off", style @c system). From is the name to whom the text | |
239 should be attributed -- you probably want to check for aliases here, | |
240 lest you confuse the user. @c text is the text to print. | |
241 | |
242 @code | |
243 gaim::core handle | |
244 gaim::core quit | |
245 @endcode | |
246 | |
247 This command exposes functionality provided by the gaim core API. | |
248 | |
249 <tt>gaim::core handle</tt> returns a handle to the gaim core for signal | |
250 connection. (See <tt>gaim::signal connect</tt>). | |
251 | |
252 @c quit exits gaim cleanly, and should be used in preference to the | |
253 tcl @c exit command. (Note that @c exit has not been removed, | |
254 however.) | |
255 | |
256 @code | |
257 gaim::debug level category message | |
258 @endcode | |
259 | |
260 Equivalent to the C gaim_debug function, this command outputs | |
261 debugging information to the gaim debug window (or stdout if gaim is | |
262 invoked with -d|--debug). The valid levels are, in increasing level | |
263 of severity, @c -misc, @c -info, @c -warning, and, or @c -error. @c | |
264 category is a short (a few characters ... for instance, "tcl" or "tcl | |
265 plugin") "topic" type name for this message, and @c message is the text | |
266 of the message. In the style of Tcl @e puts (and differing from | |
267 @e gaim_debug), no trailing \\n is required. (However, embedded newlines | |
268 may be generated with \\n). | |
269 | |
270 @code | |
271 gaim::notify ?type? title primary secondary | |
272 @endcode | |
273 | |
274 Also a direct equivalent to a C function, gaim_notify, this command | |
275 causes gaim to present the provided notification information to the | |
276 user via some appropriate UI method. The @c type argument, if | |
277 present, must be one of @c -error, @c -warning, or @c -info. The following | |
278 three arguments' absolute meanings may vary with the Gaim UI being | |
279 used (presently only a Gtk2 UI is available), but @c title should | |
280 generally be the title of the window, and @c primary and @c secondary | |
281 text within that window; in the Gtk2 UI, @c primary is slightly | |
282 larger than @c secondary and displayed in a @b boldface font. | |
283 | |
284 @code | |
285 gaim::send_im gc who text | |
286 @endcode | |
287 | |
288 This sends an IM in the fashion of serv_send_im. @c gc is the GC of | |
289 the connection on which you wish to send (as returned by most event | |
290 handlers), @c who is the nick of the buddy to which you wish to send, | |
291 and @c text is the text of the message. | |
292 | |
293 @code | |
294 gaim::signal connect instance signal args proc | |
295 gaim::signal disconnect instance signal | |
296 @endcode | |
297 | |
298 @c gaim::signal is a set of subcommands for dealing with gaim signals | |
299 (known as "events" prior to gaim 0.68). | |
300 | |
301 The @c connect subcommand registers the procedure @c proc as a handler | |
302 for the signal @c signal on the instance @c instance. @c instance | |
303 should be an instance handle as returned by one of the @c handle | |
304 commands from the various parts of gaim. @c args and @ proc are as in | |
305 the Tcl @e proc command; note that the number of arguments in @c args | |
306 must match the number of arguments emitted by the signal exactly, | |
307 although you need not use them all. The procedure @c proc may be | |
308 either a simple command or a procedure in curly brackets. Note that | |
309 only one procedure may be associated with each signal; an attempt to | |
310 connect a second procedure to the same signal will remove the | |
311 existing binding and replace it with the new procedure. | |
312 <tt>gaim::signal connect</tt> returns 0 on success and 1 on failure. | |
313 | |
314 @c disconnect removes any existing signal handler for the named | |
315 signal and instance. | |
316 | |
317 @code | |
318 gaim::unload | |
319 @endcode | |
320 | |
321 This unloads the current plugin. Note that preferences will not be | |
322 updated (yet). | |
323 | |
324 @section Signals | |
325 | |
326 Check the signals documentation for the meaning of these signals; this is | |
327 intended to be a list only of their arguments. Signal callbacks will | |
328 be made in their own namespace, and arguments to those signal | |
329 callbacks will live in the namespace @c event underneath that | |
330 namespace. To briefly illustrate, the signal @c receiving-im-msg is | |
331 provided with three arguments; the account on which the IM was | |
332 received, the screen name of the user sending the IM, and the text of | |
333 the IM. These arguments live in the variables @c event::account, | |
334 @c event::sender, and @c event::buffer, respectively. Therefore a callback | |
335 which notifies the user of an incoming IM containing the word 'shizzle' | |
336 might look like this: | |
337 | |
338 @code | |
339 gaim::signal connect [gaim::conversation handle] receiving-im-msg { | |
340 if {[ string match "*shizzle*" $event::buffer ]} { | |
341 gaim::notify -info "tcl plugin" "Fo' shizzle" \ | |
342 "$event::sender is down with the shizzle" | |
343 } | |
344 } | |
345 @endcode | |
346 | |
347 Note that for some signals (notably @c receiving-im-msg, @c sending-im-msg, | |
348 and their chat counterparts), changes to the event arguments will | |
349 change the message itself from Gaim's vantage. For those signals | |
350 whose return value is meaningful, returning a value from the Tcl event | |
351 | |
352 */ | |
353 | |
354 // vim: syntax=c tw=75 et |