1 /** @page tcl-howto Tcl Scripting HOWTO
5 NOTA BENE: This documentation is badly out of date for 2.x.
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.
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.
20 @section start Getting Started
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:
34 proc plugin_init { } {
35 return [ list "Example Plugin" \
37 "Example plugin registration" \
38 "Example of how to register a plugin for the Tcl HOWTO" \
39 "Ethan Blanton <eblanton@cs.purdue.edu>" \
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.
48 @section details Interpreter Details
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.
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.
61 @section internals Gaim Internal Procedures and Variables
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.
75 This contains the version of the gaim process which loaded the
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
87 gaim::account isconnected account
88 gaim::account list ?option?
89 gaim::account protocol account
90 gaim::account username account
93 The @c gaim::account command consists of a set of subcommands
94 pertaining to gaim accounts.
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.
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.
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
107 @c disconnect disconnects the given @c account if it is connected, or
108 does nothing if it is.
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.
114 @c handle returns the instance handle required to connect to account
115 signals. (See <tt>gaim::signal connect</tt>).
117 The @c isconnected query returns true if the given account is
118 connected and false otherwise.
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.
126 The @c protocol subcommand returns the protocol ID (e.g. "prpl-msn")
127 for the given account.
129 The @c username subcommand returns the username for the account
133 gaim::buddy alias buddy
135 gaim::buddy info ( buddy | account username )
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:
145 { group name { buddies } }
149 { buddy name account }
153 { chat alias account }
156 The @c alias subcommand returns the alias for the given buddy if it
157 exists, or the empty string if it does not.
159 @c handle returns the blist handle for the purposes of connecting
160 signals to buddy list events. (See <tt>gaim::signal connect</tt>).
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.
167 @c list returns a list of @c group structures, filled out with buddies
168 and chats as described above.
171 gaim::connection account gc
172 gaim::connection displayname gc
173 gaim::connection handle
174 gaim::connection list
177 @c gaim::connection is a collection of subcommands pertaining to
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
184 @c displayname returns the display name (duh) of @c gc as reported by
185 <tt>gaim_connection_get_display_name(gc)</tt>.
187 @c handle returns the gaim connections instance handle. (See
188 <tt>gaim::signal connect</tt>).
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.
195 gaim::conv_send account who text
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.
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
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
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.
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.
225 @c handle returns the conversations instance handle for the purposes
226 of signal connection. (See <tt>gaim::signal connect</tt>).
228 @c list returns a list of all currently open conversations.
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.
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.
249 This command exposes functionality provided by the gaim core API.
251 <tt>gaim::core handle</tt> returns a handle to the gaim core for signal
252 connection. (See <tt>gaim::signal connect</tt>).
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,
259 gaim::debug level category message
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).
273 gaim::notify ?type? title primary secondary
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.
287 gaim::send_im gc who text
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.
296 gaim::signal connect instance signal args proc
297 gaim::signal disconnect instance signal
300 @c gaim::signal is a set of subcommands for dealing with gaim signals
301 (known as "events" prior to gaim 0.68).
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.
316 @c disconnect removes any existing signal handler for the named
323 This unloads the current plugin. Note that preferences will not be
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:
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"
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
353 will return that value as it would in C.
357 // vim: syntax=c tw=72 et