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