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