comparison doc/TCL-HOWTO.dox @ 24375:73e827a93ae9

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