Mercurial > pidgin.yaz
comparison plugins/tcl/TCL-HOWTO @ 6694:2d2f04c5c7d2
[gaim-migrate @ 7220]
Sean probably won't think this is contact support. This is in fact a
Tcl script plugin loader. That's probably what he'll think it is.
committer: Tailor Script <tailor@pidgin.im>
author | Ethan Blanton <elb@pidgin.im> |
---|---|
date | Tue, 02 Sep 2003 03:34:37 +0000 |
parents | |
children | 1adc71ed6d45 |
comparison
equal
deleted
inserted
replaced
6693:8c1b5dd87fbf | 6694:2d2f04c5c7d2 |
---|---|
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 | |
152 gaim::connection handle | |
153 gaim::connection list | |
154 | |
155 'gaim::connection' is a collection of subcommands pertaining to | |
156 account connections. | |
157 | |
158 'account' returns the Gaim account associated with 'gc'. This | |
159 account is the same account used by gaim::account and other | |
160 commands. | |
161 | |
162 'handle' returns the gaim connections instance handle. (See | |
163 'gaim::signal connect'). | |
164 | |
165 'list' returns a list of all known connections. The elements of | |
166 this list are appropriate as 'gc' arguments to the other | |
167 gaim::connection subcommands or other commands requiring a gc. | |
168 | |
169 | |
170 gaim::conv_send account who text | |
171 | |
172 'gaim::conv' is simply a convenience wrapper for 'gaim::send_im' and | |
173 'gaim::conversation write'. It sends the IM, determines the from | |
174 and to arguments for 'gaim::conversation write', and prints the text | |
175 sent to the conversation as one would expect. For the curious, you | |
176 may view the source for it by typing 'info body gaim::conv_send' at | |
177 a Gaim Commander prompt. | |
178 | |
179 Note that an error in either gaim::send_im or 'gaim::conversation | |
180 write' will not be caught by this procedure, and will be propagated | |
181 to the caller. | |
182 | |
183 gaim::conversation find ?-account account? name | |
184 gaim::conversation handle | |
185 gaim::conversation list | |
186 gaim::conversation new ?-chat? ?-im? account name | |
187 gaim::conversation write conversation style from to text | |
188 | |
189 'gaim::conversation' provides an API for dealing with conversations. | |
190 Given that Gaim is an instant messenger program, you'll probably | |
191 spend a lot of time here. | |
192 | |
193 The command 'find' attempts to find an existing conversation with | |
194 username 'name'. If the '-account' option is given, it refines its | |
195 search to include only conversations on that account. | |
196 | |
197 'handle' returns the conversations instance handle for the purposes | |
198 of signal connection. (See 'gaim::signal connect'). | |
199 | |
200 'list' returns a list of all currently open conversations. | |
201 | |
202 The 'new' subcommand can be used to create a new conversation with | |
203 a specified user on a specified account if one does not exist, or | |
204 retrieve the existing conversation if it does. The '-chat' and | |
205 '-im' options specify whether the created conversation should be a | |
206 chat or a standard IM, respectively. | |
207 | |
208 'write' is used to write to the specified conversation. The 'style' | |
209 argument specifies how the text should be printed -- as text coming | |
210 from the gaim user (style 'send'), being sent to the gaim user | |
211 (style 'recv'), or as a system message (such as "so-and-so has | |
212 signed off", style 'system'). From is the name to whom the text | |
213 should be attributed -- you probably want to check for aliases here, | |
214 lest you confuse the user. 'text' is the text to print. | |
215 | |
216 gaim::core handle | |
217 gaim::core quit | |
218 | |
219 This command exposes functionality provided by the gaim core API. | |
220 | |
221 'gaim::core handle' returns a handle to the gaim core for signal | |
222 connection. (See 'gaim::signal connect'). | |
223 | |
224 'quit' exits gaim cleanly, and should be used in preference to the | |
225 tcl 'exit' command. (Note that 'exit' has not been removed, | |
226 however.) | |
227 | |
228 gaim::debug level category message | |
229 | |
230 Equivalent to the C gaim_debug function, this command outputs | |
231 debugging information to the gaim debug window (or stdout if gaim is | |
232 invoked with -n). The valid levels are, in increasing level of | |
233 severity, -misc, -info, -warning, and -error. 'category' is a short | |
234 (a few characters ... for instance, "tcl" or "tcl plugin") "topic" | |
235 type name for this message, and 'message' is the text of the | |
236 message. In the style of Tcl 'puts' (and differing from gaim_debug), | |
237 no trailing \n is required. (However, embedded newlines may be | |
238 generated with \n). | |
239 | |
240 gaim::notify ?type? title primary secondary | |
241 | |
242 Also a direct equivalent to a C function, gaim_notify, this command | |
243 causes gaim to present the provided notification information to the | |
244 user via some appropriate UI method. The 'type' argument, if | |
245 present, must be one of -error, -warning, or -info. The following | |
246 three arguments' absolute meanings may vary with the Gaim UI being | |
247 used (presently only a Gtk2 UI is available), but 'title' should | |
248 generally be the title of the window, and 'primary' and 'secondary' | |
249 text within that window; in the Gtk2 UI, 'primary' is slightly | |
250 larger than 'secondary' and displayed in a boldface font. | |
251 | |
252 gaim::send_im gc who text | |
253 | |
254 This sends an IM in the fashion of serv_send_im. 'gc' is the GC of | |
255 the connection on which you wish to send (as returned by most event | |
256 handlers), 'who' is the nick of the buddy to which you wish to send, | |
257 and 'text' is the text of the message. | |
258 | |
259 gaim::signal connect instance signal args proc | |
260 gaim::signal disconnect instance signal | |
261 | |
262 'gaim::signal' is a set of subcommands for dealing with gaim signals | |
263 (known as "events" prior to gaim 0.68). | |
264 | |
265 The 'connect' subcommand registers the procedure 'proc' as a handler | |
266 for the signal 'signal' on the instance 'instance'. 'instance' | |
267 should be an instance handle as returned by one of the 'handle' | |
268 commands from the various parts of gaim. 'args' and 'proc' are as in | |
269 the Tcl 'proc' command; note that the number of arguments in 'args' | |
270 must match the number of arguments emitted by the signal exactly, | |
271 although you need not use them all. The procedure 'proc' may be | |
272 either a simple command or a procedure in curly brackets. Note that | |
273 only one procedure may be associated with each signal; an attempt to | |
274 connect a second procedure to the same signal will remove the | |
275 existing binding and replace it with the new procedure. | |
276 'gaim::signal connect' returns 0 on success and 1 on failure. | |
277 | |
278 'disconnect' removes any existing signal handler for the named | |
279 signal and instance. | |
280 | |
281 gaim::unload | |
282 | |
283 This unloads the current plugin. Note that preferences will not be | |
284 updated (yet). | |
285 | |
286 SIGNALS | |
287 | |
288 Check the file SIGNALS for the meaning of these signals; this is | |
289 intended to be a list only of their arguments. Signal callbacks will | |
290 be made in their own namespace, and arguments to those signal | |
291 callbacks will live in the namespace 'event' underneath that | |
292 namespace. To briefly illustrate, the signal received-im-msg is | |
293 provided with three arguments; the account on which the IM was | |
294 received, the screen name of the user sending the IM, and the text of | |
295 the IM. These arguments live in the variables event::account, | |
296 event::sender, and event::buffer, respectively. Therefore a callback | |
297 which notifies the user of an incoming IM containing the word 'shizzle' | |
298 might look like this: | |
299 | |
300 gaim::add_event_handler received-im-msg { | |
301 if {[ string match "*shizzle*" $event::buffer ]} { | |
302 gaim::notify -info "tcl plugin" "Fo' shizzle" \ | |
303 "$event::sender is down with the shizzle" | |
304 } | |
305 } | |
306 | |
307 Note that for some signals (notably received-im-msg, sending-im-msg, | |
308 and their chat counterparts), changes to the event arguments will | |
309 change the message itself from Gaim's vantage. For those signals | |
310 whose return value is meaningful, returning a value from the Tcl event |