10409
|
1 /** @page tcl-howto Tcl Scripting HOWTO
|
|
2
|
|
3 @section Intoduction
|
|
4
|
10597
|
5 NOTA BENE: This documentation is badly out of date for 2.x.
|
|
6
|
10409
|
7 The Gaim Tcl interface provides a Tcl API for many useful gaim
|
|
8 functions. Like the perl API, the Tcl API does not provide
|
|
9 access to every corner of gaim exposed by the @e C interface. It does,
|
|
10 however, provide a very powerful interface to many of Gaim's functions
|
|
11 through a simple to learn and extend scripting language.
|
|
12
|
|
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
|
|
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
|
|
17 beginners and experienced programmers alike. There are numerous books
|
|
18 on the subject; we will not discuss it any further here.
|
|
19
|
|
20 @section start Getting Started
|
|
21
|
|
22 The only requirement placed on a Gaim Tcl script by Gaim is the
|
|
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
|
|
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
|
|
27 problem, as the only thing this procedure should do is return a simple
|
|
28 list containing five items: the @b name of the script, its @b version
|
|
29 number, a @b summary (just a few words) of its function, a short (longer
|
|
30 than the summary, but no more than a couple of sentences if possible)
|
|
31 @b description, the @b author, and a @b URL to web page. For example:
|
|
32
|
|
33 @code
|
|
34 proc plugin_init { } {
|
|
35 return [ list "Example Plugin" \
|
|
36 "1.0" \
|
|
37 "Example plugin registration" \
|
|
38 "Example of how to register a plugin for the Tcl HOWTO" \
|
|
39 "Ethan Blanton <eblanton@cs.purdue.edu>" \
|
|
40 "http://gaim.sf.net/" ]
|
|
41 }
|
|
42 @endcode
|
|
43
|
|
44 The rest of the script will generally be registration to recieve
|
|
45 notification of various Gaim signals (more about this below) and
|
|
46 definitions of procedures to be executed when those signals occur.
|
|
47
|
|
48 @section details Interpreter Details
|
|
49
|
|
50 Gaim initializes and drives the Tcl event loop (similar to Tk),
|
|
51 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 broken due to a bug somewhere in the Tcl/Glib event loop glue, and it
|
|
54 should not be used for now.
|
|
55
|
|
56 The gaim-specific functions are provided in a statically-linked
|
|
57 package called @c gaim; this means that if you spawn a child
|
|
58 interpreter and wish to use the gaim-specific functions, you will need
|
|
59 to execute <tt>load {} gaim</tt> in that interpreter.
|
|
60
|
|
61 @section internals Gaim Internal Procedures and Variables
|
|
62
|
|
63 All of the information provided for your use by Gaim will be in the @c
|
|
64 ::gaim 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 import gaim::*</tt>) or reference it explicitly. The following
|
|
67 descriptions will reference it explicitly for clarity.
|
|
68
|
|
69 @li Variables
|
|
70
|
|
71 @code
|
|
72 gaim::version
|
|
73 @endcode
|
|
74
|
|
75 This contains the version of the gaim process which loaded the
|
|
76 script.
|
|
77
|
|
78 @li Commands
|
|
79
|
|
80 @code
|
|
81 gaim::account alias account
|
|
82 gaim::account connect account
|
|
83 gaim::account connection account
|
|
84 gaim::account disconnect account
|
|
85 gaim::account find username protocol
|
|
86 gaim::account handle
|
|
87 gaim::account isconnected account
|
|
88 gaim::account list ?option?
|
|
89 gaim::account protocol account
|
|
90 gaim::account username account
|
|
91 @endcode
|
|
92
|
|
93 The @c gaim::account command consists of a set of subcommands
|
|
94 pertaining to gaim accounts.
|
|
95
|
|
96 @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
|
|
99 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 the @c gc for the account.
|
|
102
|
|
103 @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 other functions.
|
|
106
|
|
107 @c disconnect disconnects the given @c account if it is connected, or
|
|
108 does nothing if it is.
|
|
109
|
|
110 @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 returns the account if found, or 0 otherwise.
|
|
113
|
|
114 @c handle returns the instance handle required to connect to account
|
|
115 signals. (See <tt>gaim::signal connect</tt>).
|
|
116
|
|
117 The @c isconnected query returns true if the given account is
|
|
118 connected and false otherwise.
|
|
119
|
|
120 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 @c account argument of the other subcommands. The @c -all option
|
|
123 (default) returns all accounts, while the @c -online option returns
|
|
124 only those accounts which are online.
|
|
125
|
|
126 The @c protocol subcommand returns the protocol ID (e.g. "prpl-msn")
|
|
127 for the given account.
|
|
128
|
|
129 The @c username subcommand returns the username for the account
|
|
130 @c account.
|
|
131
|
|
132 @code
|
|
133 gaim::buddy alias buddy
|
|
134 gaim::buddy handle
|
|
135 gaim::buddy info ( buddy | account username )
|
|
136 gaim::buddy list
|
|
137 @endcode
|
|
138
|
|
139 @c gaim::buddy is a set of commands for retrieving information about
|
|
140 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 which being the type. The currently recognized types are "group",
|
|
143 "buddy", and "chat". A group node looks like:
|
|
144 @code
|
|
145 { group name { buddies } }
|
|
146 @endcode
|
|
147 A buddy node is:
|
|
148 @code
|
|
149 { buddy name account }
|
|
150 @endcode
|
|
151 And a chat node is:
|
|
152 @code
|
|
153 { chat alias account }
|
|
154 @endcode
|
|
155
|
|
156 The @c alias subcommand returns the alias for the given buddy if it
|
|
157 exists, or the empty string if it does not.
|
|
158
|
|
159 @c handle returns the blist handle for the purposes of connecting
|
|
160 signals to buddy list events. (See <tt>gaim::signal connect</tt>).
|
|
161
|
|
162 @c info causes gaim to display the info dialog for the given buddy.
|
|
163 Since it is possible to request user info for a buddy not in your
|
|
164 buddy list, you may also specify a buddy by his or her username and
|
|
165 the account through which you wish to retrieve info.
|
|
166
|
|
167 @c list returns a list of @c group structures, filled out with buddies
|
|
168 and chats as described above.
|
|
169
|
|
170 @code
|
|
171 gaim::connection account gc
|
|
172 gaim::connection displayname gc
|
|
173 gaim::connection handle
|
|
174 gaim::connection list
|
|
175 @endcode
|
|
176
|
|
177 @c gaim::connection is a collection of subcommands pertaining to
|
|
178 account connections.
|
|
179
|
|
180 @c account returns the Gaim account associated with @c gc. This
|
|
181 account is the same account used by @c gaim::account and other
|
|
182 commands.
|
|
183
|
|
184 @c displayname returns the display name (duh) of @c gc as reported by
|
|
185 <tt>gaim_connection_get_display_name(gc)</tt>.
|
|
186
|
|
187 @c handle returns the gaim connections instance handle. (See
|
|
188 <tt>gaim::signal connect</tt>).
|
|
189
|
|
190 @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 @c gaim::connection subcommands or other commands requiring a gc.
|
|
193
|
|
194 @code
|
|
195 gaim::conv_send account who text
|
|
196 @endcode
|
|
197
|
|
198 @c gaim::conv is simply a convenience wrapper for @c gaim::send_im and
|
|
199 <tt>gaim::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 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 a Gaim Commander prompt.
|
|
204
|
|
205 Note that an error in either @c gaim::send_im or <tt>gaim::conversation
|
|
206 write</tt> will not be caught by this procedure, and will be propagated
|
|
207 to the caller.
|
|
208
|
|
209 @code
|
|
210 gaim::conversation find ?-account account? name
|
|
211 gaim::conversation handle
|
|
212 gaim::conversation list
|
|
213 gaim::conversation new ?-chat? ?-im? account name
|
|
214 gaim::conversation write conversation style from to text
|
|
215 @endcode
|
|
216
|
|
217 @c gaim::conversation provides an API for dealing with conversations.
|
|
218 Given that Gaim is an instant messenger program, you'll probably
|
|
219 spend a lot of time here.
|
|
220
|
|
221 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 search to include only conversations on that account.
|
|
224
|
|
225 @c handle returns the conversations instance handle for the purposes
|
|
226 of signal connection. (See <tt>gaim::signal connect</tt>).
|
|
227
|
|
228 @c list returns a list of all currently open conversations.
|
|
229
|
|
230 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 retrieve the existing conversation if it does. The @c -chat and
|
|
233 @c -im options specify whether the created conversation should be a
|
|
234 chat or a standard IM, respectively.
|
|
235
|
|
236 @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 from the gaim user (style @c send), being sent to the gaim user
|
|
239 (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 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
|
|
244 @code
|
|
245 gaim::core handle
|
|
246 gaim::core quit
|
|
247 @endcode
|
|
248
|
|
249 This command exposes functionality provided by the gaim core API.
|
|
250
|
|
251 <tt>gaim::core handle</tt> returns a handle to the gaim core for signal
|
|
252 connection. (See <tt>gaim::signal connect</tt>).
|
|
253
|
|
254 @c quit exits gaim cleanly, and should be used in preference to the
|
|
255 tcl @c exit command. (Note that @c exit has not been removed,
|
|
256 however.)
|
|
257
|
|
258 @code
|
|
259 gaim::debug level category message
|
|
260 @endcode
|
|
261
|
|
262 Equivalent to the C gaim_debug function, this command outputs
|
|
263 debugging information to the gaim debug window (or stdout if gaim is
|
|
264 invoked with -d|--debug). The valid levels are, in increasing level
|
|
265 of severity, @c -misc, @c -info, @c -warning, and, or @c -error. @c
|
|
266 category is a short (a few characters ... for instance, "tcl" or "tcl
|
|
267 plugin") "topic" type name for this message, and @c message is the text
|
|
268 of the message. In the style of Tcl @e puts (and differing from
|
|
269 @e gaim_debug), no trailing \\n is required. (However, embedded newlines
|
|
270 may be generated with \\n).
|
|
271
|
|
272 @code
|
|
273 gaim::notify ?type? title primary secondary
|
|
274 @endcode
|
|
275
|
|
276 Also a direct equivalent to a C function, gaim_notify, this command
|
|
277 causes gaim to present the provided notification information to the
|
|
278 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 three arguments' absolute meanings may vary with the Gaim UI being
|
|
281 used (presently only a Gtk2 UI is available), but @c title should
|
|
282 generally be the title of the window, and @c primary and @c secondary
|
|
283 text within that window; in the Gtk2 UI, @c primary is slightly
|
|
284 larger than @c secondary and displayed in a @b boldface font.
|
|
285
|
|
286 @code
|
|
287 gaim::send_im gc who text
|
|
288 @endcode
|
|
289
|
|
290 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 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
|
|
295 @code
|
|
296 gaim::signal connect instance signal args proc
|
|
297 gaim::signal disconnect instance signal
|
|
298 @endcode
|
|
299
|
|
300 @c gaim::signal is a set of subcommands for dealing with gaim signals
|
|
301 (known as "events" prior to gaim 0.68).
|
|
302
|
|
303 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 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 the Tcl @e proc command; note that the number of arguments in @c args
|
|
308 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 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 connect a second procedure to the same signal will remove the
|
|
313 existing binding and replace it with the new procedure.
|
|
314 <tt>gaim::signal connect</tt> returns 0 on success and 1 on failure.
|
|
315
|
|
316 @c disconnect removes any existing signal handler for the named
|
|
317 signal and instance.
|
|
318
|
|
319 @code
|
|
320 gaim::unload
|
|
321 @endcode
|
|
322
|
|
323 This unloads the current plugin. Note that preferences will not be
|
|
324 updated (yet).
|
|
325
|
|
326 @section Signals
|
|
327
|
|
328 Check the signals documentation for the meaning of these signals; this is
|
|
329 intended to be a list only of their arguments. Signal callbacks will
|
|
330 be made in their own namespace, and arguments to those signal
|
|
331 callbacks will live in the namespace @c event underneath that
|
|
332 namespace. To briefly illustrate, the signal @c receiving-im-msg is
|
|
333 provided with three arguments; the account on which the IM was
|
|
334 received, the screen name of the user sending the IM, and the text of
|
|
335 the IM. These arguments live in the variables @c event::account,
|
|
336 @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 might look like this:
|
|
339
|
|
340 @code
|
|
341 gaim::signal connect [gaim::conversation handle] receiving-im-msg {
|
|
342 if {[ string match "*shizzle*" $event::buffer ]} {
|
|
343 gaim::notify -info "tcl plugin" "Fo' shizzle" \
|
|
344 "$event::sender is down with the shizzle"
|
|
345 }
|
|
346 }
|
|
347 @endcode
|
|
348
|
|
349 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 change the message itself from Gaim's vantage. For those signals
|
|
352 whose return value is meaningful, returning a value from the Tcl event
|
10410
|
353 will return that value as it would in C.
|
10409
|
354
|
|
355 */
|
|
356
|
10410
|
357 // vim: syntax=c tw=72 et
|