Mercurial > pidgin.yaz
annotate libgaim/plugins/tcl/tcl_cmds.c @ 14972:99112cd4a2f4
[gaim-migrate @ 17750]
Fix bug #1596631: keybinding not working with xterm
committer: Tailor Script <tailor@pidgin.im>
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Wed, 15 Nov 2006 07:18:16 +0000 |
parents | 4558e71a5a34 |
children |
rev | line source |
---|---|
14192 | 1 /** |
2 * @file tcl_cmds.c Commands for the Gaim Tcl plugin bindings | |
3 * | |
4 * gaim | |
5 * | |
6 * Copyright (C) 2003 Ethan Blanton <eblanton@cs.purdue.edu> | |
7 * | |
8 * This program is free software; you can redistribute it and/or modify | |
9 * it under the terms of the GNU General Public License as published by | |
10 * the Free Software Foundation; either version 2 of the License, or | |
11 * (at your option) any later version. | |
12 * | |
13 * This program is distributed in the hope that it will be useful, | |
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 * GNU General Public License for more details. | |
17 * | |
18 * You should have received a copy of the GNU General Public License | |
19 * along with this program; if not, write to the Free Software | |
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
21 */ | |
22 | |
23 #include <tcl.h> | |
24 | |
25 #include "internal.h" | |
26 #include "conversation.h" | |
27 #include "connection.h" | |
28 #include "account.h" | |
29 #include "server.h" | |
30 #include "notify.h" | |
31 #include "blist.h" | |
32 #include "debug.h" | |
33 #include "prefs.h" | |
34 #include "core.h" | |
35 | |
36 #include "tcl_gaim.h" | |
37 | |
38 static GaimAccount *tcl_validate_account(Tcl_Obj *obj, Tcl_Interp *interp); | |
39 static GaimConversation *tcl_validate_conversation(Tcl_Obj *obj, Tcl_Interp *interp); | |
40 static GaimConnection *tcl_validate_gc(Tcl_Obj *obj, Tcl_Interp *interp); | |
41 | |
42 static GaimAccount *tcl_validate_account(Tcl_Obj *obj, Tcl_Interp *interp) | |
43 { | |
44 GaimAccount *account; | |
45 GList *cur; | |
46 | |
47 account = gaim_tcl_ref_get(interp, obj, GaimTclRefAccount); | |
48 | |
49 if (account == NULL) | |
50 return NULL; | |
51 | |
52 for (cur = gaim_accounts_get_all(); cur != NULL; cur = g_list_next(cur)) { | |
53 if (account == cur->data) | |
54 return account; | |
55 } | |
56 if (interp != NULL) | |
57 Tcl_SetStringObj(Tcl_GetObjResult(interp), "invalid account", -1); | |
58 return NULL; | |
59 } | |
60 | |
61 static GaimConversation *tcl_validate_conversation(Tcl_Obj *obj, Tcl_Interp *interp) | |
62 { | |
63 GaimConversation *convo; | |
64 GList *cur; | |
65 | |
66 convo = gaim_tcl_ref_get(interp, obj, GaimTclRefConversation); | |
67 | |
68 if (convo == NULL) | |
69 return NULL; | |
70 | |
71 for (cur = gaim_get_conversations(); cur != NULL; cur = g_list_next(cur)) { | |
72 if (convo == cur->data) | |
73 return convo; | |
74 } | |
75 if (interp != NULL) | |
76 Tcl_SetStringObj(Tcl_GetObjResult(interp), "invalid conversation", -1); | |
77 return NULL; | |
78 } | |
79 | |
80 static GaimConnection *tcl_validate_gc(Tcl_Obj *obj, Tcl_Interp *interp) | |
81 { | |
82 GaimConnection *gc; | |
83 GList *cur; | |
84 | |
85 gc = gaim_tcl_ref_get(interp, obj, GaimTclRefConnection); | |
86 | |
87 if (gc == NULL) | |
88 return NULL; | |
89 | |
90 for (cur = gaim_connections_get_all(); cur != NULL; cur = g_list_next(cur)) { | |
91 if (gc == cur->data) | |
92 return gc; | |
93 } | |
94 return NULL; | |
95 } | |
96 | |
97 int tcl_cmd_account(ClientData unused, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) | |
98 { | |
99 Tcl_Obj *result = Tcl_GetObjResult(interp), *list, *elem; | |
100 const char *cmds[] = { "alias", "connect", "connection", "disconnect", | |
101 "enabled", "find", "handle", "isconnected", | |
102 "list", "presence", "protocol", "status", | |
103 "status_type", "status_types", "username", | |
104 NULL }; | |
105 enum { CMD_ACCOUNT_ALIAS, | |
106 CMD_ACCOUNT_CONNECT, CMD_ACCOUNT_CONNECTION, | |
107 CMD_ACCOUNT_DISCONNECT, CMD_ACCOUNT_ENABLED, CMD_ACCOUNT_FIND, | |
108 CMD_ACCOUNT_HANDLE, CMD_ACCOUNT_ISCONNECTED, CMD_ACCOUNT_LIST, | |
109 CMD_ACCOUNT_PRESENCE, CMD_ACCOUNT_PROTOCOL, CMD_ACCOUNT_STATUS, | |
110 CMD_ACCOUNT_STATUS_TYPE, CMD_ACCOUNT_STATUS_TYPES, | |
111 CMD_ACCOUNT_USERNAME } cmd; | |
112 const char *listopts[] = { "-all", "-online", NULL }; | |
113 enum { CMD_ACCOUNTLIST_ALL, CMD_ACCOUNTLIST_ONLINE } listopt; | |
114 const char *alias; | |
115 const GList *cur; | |
116 GaimAccount *account; | |
117 GaimStatus *status; | |
118 GaimStatusType *status_type; | |
119 GaimValue *value; | |
120 char *attr_id; | |
121 int error; | |
122 int b, i; | |
123 | |
124 if (objc < 2) { | |
125 Tcl_WrongNumArgs(interp, 1, objv, "subcommand ?args?"); | |
126 return TCL_ERROR; | |
127 } | |
128 | |
129 if ((error = Tcl_GetIndexFromObj(interp, objv[1], cmds, "subcommand", 0, (int *)&cmd)) != TCL_OK) | |
130 return error; | |
131 | |
132 switch (cmd) { | |
133 case CMD_ACCOUNT_ALIAS: | |
134 if (objc != 3) { | |
135 Tcl_WrongNumArgs(interp, 2, objv, "account"); | |
136 return TCL_ERROR; | |
137 } | |
138 if ((account = tcl_validate_account(objv[2], interp)) == NULL) | |
139 return TCL_ERROR; | |
140 alias = gaim_account_get_alias(account); | |
141 Tcl_SetStringObj(result, alias ? (char *)alias : "", -1); | |
142 break; | |
143 case CMD_ACCOUNT_CONNECT: | |
144 if (objc != 3) { | |
145 Tcl_WrongNumArgs(interp, 2, objv, "account"); | |
146 return TCL_ERROR; | |
147 } | |
148 if ((account = tcl_validate_account(objv[2], interp)) == NULL) | |
149 return TCL_ERROR; | |
150 if (!gaim_account_is_connected(account)) | |
151 gaim_account_connect(account); | |
152 Tcl_SetObjResult(interp, | |
153 gaim_tcl_ref_new(GaimTclRefConnection, | |
154 gaim_account_get_connection(account))); | |
155 break; | |
156 case CMD_ACCOUNT_CONNECTION: | |
157 if (objc != 3) { | |
158 Tcl_WrongNumArgs(interp, 2, objv, "account"); | |
159 return TCL_ERROR; | |
160 } | |
161 | |
162 if ((account = tcl_validate_account(objv[2], interp)) == NULL) | |
163 return TCL_ERROR; | |
164 Tcl_SetObjResult(interp, | |
165 gaim_tcl_ref_new(GaimTclRefConnection, | |
166 gaim_account_get_connection(account))); | |
167 break; | |
168 case CMD_ACCOUNT_DISCONNECT: | |
169 if (objc != 3) { | |
170 Tcl_WrongNumArgs(interp, 2, objv, "account"); | |
171 return TCL_ERROR; | |
172 } | |
173 if ((account = tcl_validate_account(objv[2], interp)) == NULL) | |
174 return TCL_ERROR; | |
175 gaim_account_disconnect(account); | |
176 break; | |
177 case CMD_ACCOUNT_ENABLED: | |
178 if (objc != 3 && objc != 4) { | |
179 Tcl_WrongNumArgs(interp, 2, objv, "account ?enabled?"); | |
180 return TCL_ERROR; | |
181 } | |
182 if ((account = tcl_validate_account(objv[2], interp)) == NULL) | |
183 return TCL_ERROR; | |
184 if (objc == 3) { | |
185 Tcl_SetBooleanObj(result, | |
186 gaim_account_get_enabled(account, | |
187 gaim_core_get_ui())); | |
188 } else { | |
189 if ((error = Tcl_GetBooleanFromObj(interp, objv[3], &b)) != TCL_OK) | |
190 return TCL_ERROR; | |
191 gaim_account_set_enabled(account, gaim_core_get_ui(), b); | |
192 } | |
193 break; | |
194 case CMD_ACCOUNT_FIND: | |
195 if (objc != 4) { | |
196 Tcl_WrongNumArgs(interp, 2, objv, "username protocol"); | |
197 return TCL_ERROR; | |
198 } | |
199 account = gaim_accounts_find(Tcl_GetString(objv[2]), | |
200 Tcl_GetString(objv[3])); | |
201 Tcl_SetObjResult(interp, | |
202 gaim_tcl_ref_new(GaimTclRefAccount, account)); | |
203 break; | |
204 case CMD_ACCOUNT_HANDLE: | |
205 if (objc != 2) { | |
206 Tcl_WrongNumArgs(interp, 2, objv, ""); | |
207 return TCL_ERROR; | |
208 } | |
209 Tcl_SetIntObj(result, (int)gaim_accounts_get_handle()); | |
210 break; | |
211 case CMD_ACCOUNT_ISCONNECTED: | |
212 if (objc != 3) { | |
213 Tcl_WrongNumArgs(interp, 2, objv, "account"); | |
214 return TCL_ERROR; | |
215 } | |
216 if ((account = tcl_validate_account(objv[2], interp)) == NULL) | |
217 return TCL_ERROR; | |
218 Tcl_SetBooleanObj(result, gaim_account_is_connected(account)); | |
219 break; | |
220 case CMD_ACCOUNT_LIST: | |
221 listopt = CMD_ACCOUNTLIST_ALL; | |
222 if (objc > 3) { | |
223 Tcl_WrongNumArgs(interp, 2, objv, "?option?"); | |
224 return TCL_ERROR; | |
225 } | |
226 if (objc == 3) { | |
227 if ((error = Tcl_GetIndexFromObj(interp, objv[2], listopts, "option", 0, (int *)&listopt)) != TCL_OK) | |
228 return error; | |
229 } | |
230 list = Tcl_NewListObj(0, NULL); | |
231 for (cur = gaim_accounts_get_all(); cur != NULL; cur = g_list_next(cur)) { | |
232 account = cur->data; | |
233 if (listopt == CMD_ACCOUNTLIST_ONLINE && !gaim_account_is_connected(account)) | |
234 continue; | |
235 elem = gaim_tcl_ref_new(GaimTclRefAccount, account); | |
236 Tcl_ListObjAppendElement(interp, list, elem); | |
237 } | |
238 Tcl_SetObjResult(interp, list); | |
239 break; | |
240 case CMD_ACCOUNT_PRESENCE: | |
241 if (objc != 3) { | |
242 Tcl_WrongNumArgs(interp, 2, objv, "account"); | |
243 return TCL_ERROR; | |
244 } | |
245 if ((account = tcl_validate_account(objv[2], interp)) == NULL) | |
246 return TCL_ERROR; | |
247 Tcl_SetObjResult(interp, gaim_tcl_ref_new(GaimTclRefPresence, | |
248 gaim_account_get_presence(account))); | |
249 break; | |
250 case CMD_ACCOUNT_PROTOCOL: | |
251 if (objc != 3) { | |
252 Tcl_WrongNumArgs(interp, 2, objv, "account"); | |
253 return TCL_ERROR; | |
254 } | |
255 if ((account = tcl_validate_account(objv[2], interp)) == NULL) | |
256 return TCL_ERROR; | |
257 Tcl_SetStringObj(result, (char *)gaim_account_get_protocol_id(account), -1); | |
258 break; | |
259 case CMD_ACCOUNT_STATUS: | |
260 if (objc < 3) { | |
261 Tcl_WrongNumArgs(interp, 2, objv, "account ?status_id name value ...?"); | |
262 return TCL_ERROR; | |
263 } | |
264 if ((account = tcl_validate_account(objv[2], interp)) == NULL) | |
265 return TCL_ERROR; | |
266 if (objc == 3) { | |
267 Tcl_SetObjResult(interp, | |
268 gaim_tcl_ref_new(GaimTclRefStatus, | |
269 gaim_account_get_active_status(account))); | |
270 } else { | |
271 GList *l = NULL; | |
272 if (objc % 2) { | |
273 Tcl_SetStringObj(result, "name without value setting status", -1); | |
274 return TCL_ERROR; | |
275 } | |
276 status = gaim_account_get_status(account, Tcl_GetString(objv[3])); | |
277 if (status == NULL) { | |
278 Tcl_SetStringObj(result, "invalid status for account", -1); | |
279 return TCL_ERROR; | |
280 } | |
281 for (i = 4; i < objc; i += 2) { | |
282 attr_id = Tcl_GetString(objv[i]); | |
283 value = gaim_status_get_attr_value(status, attr_id); | |
284 if (value == NULL) { | |
285 Tcl_SetStringObj(result, "invalid attribute for account", -1); | |
286 return TCL_ERROR; | |
287 } | |
288 switch (gaim_value_get_type(value)) { | |
289 case GAIM_TYPE_BOOLEAN: | |
290 error = Tcl_GetBooleanFromObj(interp, objv[i + 1], &b); | |
291 if (error != TCL_OK) | |
292 return error; | |
293 l = g_list_append(l, attr_id); | |
294 l = g_list_append(l, GINT_TO_POINTER(b)); | |
295 break; | |
296 case GAIM_TYPE_INT: | |
297 error = Tcl_GetIntFromObj(interp, objv[i + 1], &b); | |
298 if (error != TCL_OK) | |
299 return error; | |
300 l = g_list_append(l, attr_id); | |
301 l = g_list_append(l, GINT_TO_POINTER(b)); | |
302 break; | |
303 case GAIM_TYPE_STRING: | |
304 l = g_list_append(l, attr_id); | |
305 l = g_list_append(l, Tcl_GetString(objv[i + 1])); | |
306 break; | |
307 default: | |
308 Tcl_SetStringObj(result, "unknown GaimValue type", -1); | |
309 return TCL_ERROR; | |
310 } | |
311 } | |
312 gaim_account_set_status_list(account, Tcl_GetString(objv[3]), TRUE, l); | |
313 g_list_free(l); | |
314 } | |
315 break; | |
316 case CMD_ACCOUNT_STATUS_TYPE: | |
317 if (objc != 4 && objc != 5) { | |
318 Tcl_WrongNumArgs(interp, 2, objv, "account ?statustype? ?-primitive primitive?"); | |
319 return TCL_ERROR; | |
320 } | |
321 if ((account = tcl_validate_account(objv[2], interp)) == NULL) | |
322 return TCL_ERROR; | |
323 if (objc == 4) { | |
324 status_type = gaim_account_get_status_type(account, | |
325 Tcl_GetString(objv[3])); | |
326 } else { | |
327 GaimStatusPrimitive primitive; | |
328 if (strcmp(Tcl_GetString(objv[3]), "-primitive")) { | |
329 Tcl_SetStringObj(result, "bad option \"", -1); | |
330 Tcl_AppendObjToObj(result, objv[3]); | |
331 Tcl_AppendToObj(result, | |
332 "\": should be -primitive", -1); | |
333 return TCL_ERROR; | |
334 } | |
335 primitive = gaim_primitive_get_type_from_id(Tcl_GetString(objv[4])); | |
336 status_type = gaim_account_get_status_type_with_primitive(account, | |
337 primitive); | |
338 } | |
339 if (status_type == NULL) { | |
340 Tcl_SetStringObj(result, "status type not found", -1); | |
341 return TCL_ERROR; | |
342 } | |
343 Tcl_SetObjResult(interp, | |
344 gaim_tcl_ref_new(GaimTclRefStatusType, | |
345 status_type)); | |
346 break; | |
347 case CMD_ACCOUNT_STATUS_TYPES: | |
348 if (objc != 3) { | |
349 Tcl_WrongNumArgs(interp, 2, objv, "account"); | |
350 return TCL_ERROR; | |
351 } | |
352 if ((account = tcl_validate_account(objv[2], interp)) == NULL) | |
353 return TCL_ERROR; | |
354 list = Tcl_NewListObj(0, NULL); | |
355 for (cur = gaim_account_get_status_types(account); cur != NULL; | |
356 cur = g_list_next(cur)) { | |
357 Tcl_ListObjAppendElement(interp, list, | |
358 gaim_tcl_ref_new(GaimTclRefStatusType, | |
359 cur->data)); | |
360 } | |
361 Tcl_SetObjResult(interp, list); | |
362 break; | |
363 case CMD_ACCOUNT_USERNAME: | |
364 if (objc != 3) { | |
365 Tcl_WrongNumArgs(interp, 2, objv, "account"); | |
366 return TCL_ERROR; | |
367 } | |
368 if ((account = tcl_validate_account(objv[2], interp)) == NULL) | |
369 return TCL_ERROR; | |
370 Tcl_SetStringObj(result, (char *)gaim_account_get_username(account), -1); | |
371 break; | |
372 } | |
373 | |
374 return TCL_OK; | |
375 } | |
376 | |
377 static GaimBlistNode *tcl_list_to_buddy(Tcl_Interp *interp, int count, Tcl_Obj **elems) | |
378 { | |
379 GaimBlistNode *node = NULL; | |
380 GaimAccount *account; | |
381 char *name; | |
382 char *type; | |
383 | |
384 if (count < 3) { | |
385 Tcl_SetStringObj(Tcl_GetObjResult(interp), "list too short", -1); | |
386 return NULL; | |
387 } | |
388 | |
389 type = Tcl_GetString(elems[0]); | |
390 name = Tcl_GetString(elems[1]); | |
391 if ((account = tcl_validate_account(elems[2], interp)) == NULL) | |
392 return NULL; | |
393 | |
394 if (!strcmp(type, "buddy")) { | |
395 node = (GaimBlistNode *)gaim_find_buddy(account, name); | |
396 } else if (!strcmp(type, "group")) { | |
397 node = (GaimBlistNode *)gaim_blist_find_chat(account, name); | |
398 } | |
399 | |
400 return node; | |
401 } | |
402 | |
403 int tcl_cmd_buddy(ClientData unused, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) | |
404 { | |
405 Tcl_Obj *list, *tclgroup, *tclgrouplist, *tclcontact, *tclcontactlist, *tclbud, **elems, *result; | |
406 const char *cmds[] = { "alias", "handle", "info", "list", NULL }; | |
407 enum { CMD_BUDDY_ALIAS, CMD_BUDDY_HANDLE, CMD_BUDDY_INFO, CMD_BUDDY_LIST } cmd; | |
408 GaimBuddyList *blist; | |
409 GaimBlistNode *node, *gnode, *bnode; | |
410 GaimAccount *account; | |
411 GaimBuddy *bud; | |
412 GaimChat *cnode; | |
413 int error, all = 0, count; | |
414 | |
415 if (objc < 2) { | |
416 Tcl_WrongNumArgs(interp, 1, objv, "subcommand ?args?"); | |
417 return TCL_ERROR; | |
418 } | |
419 if ((error = Tcl_GetIndexFromObj(interp, objv[1], cmds, "subcommand", 0, (int *)&cmd)) != TCL_OK) | |
420 return error; | |
421 | |
422 result = Tcl_GetObjResult(interp); | |
423 | |
424 switch (cmd) { | |
425 case CMD_BUDDY_ALIAS: | |
426 if (objc != 3) { | |
427 Tcl_WrongNumArgs(interp, 2, objv, "buddy"); | |
428 return TCL_ERROR; | |
429 } | |
430 if ((error = Tcl_ListObjGetElements(interp, objv[2], &count, &elems)) != TCL_OK) | |
431 return error; | |
432 if ((node = tcl_list_to_buddy(interp, count, elems)) == NULL) | |
433 return TCL_ERROR; | |
434 if (node->type == GAIM_BLIST_CHAT_NODE) | |
435 Tcl_SetStringObj(result, ((GaimChat *)node)->alias, -1); | |
436 else if (node->type == GAIM_BLIST_BUDDY_NODE) | |
437 Tcl_SetStringObj(result, (char *)gaim_buddy_get_alias((GaimBuddy *)node), -1); | |
438 return TCL_OK; | |
439 break; | |
440 case CMD_BUDDY_HANDLE: | |
441 if (objc != 2) { | |
442 Tcl_WrongNumArgs(interp, 2, objv, ""); | |
443 return TCL_ERROR; | |
444 } | |
445 Tcl_SetIntObj(result, (int)gaim_blist_get_handle()); | |
446 break; | |
447 case CMD_BUDDY_INFO: | |
448 if (objc != 3 && objc != 4) { | |
449 Tcl_WrongNumArgs(interp, 2, objv, "( buddy | account username )"); | |
450 return TCL_ERROR; | |
451 } | |
452 if (objc == 3) { | |
453 if ((error = Tcl_ListObjGetElements(interp, objv[2], &count, &elems)) != TCL_OK) | |
454 return error; | |
455 if (count < 3) { | |
456 Tcl_SetStringObj(result, "buddy too short", -1); | |
457 return TCL_ERROR; | |
458 } | |
459 if (strcmp("buddy", Tcl_GetString(elems[0]))) { | |
460 Tcl_SetStringObj(result, "invalid buddy", -1); | |
461 return TCL_ERROR; | |
462 } | |
463 if ((account = tcl_validate_account(elems[2], interp)) == NULL) | |
464 return TCL_ERROR; | |
465 serv_get_info(gaim_account_get_connection(account), Tcl_GetString(elems[1])); | |
466 } else { | |
467 if ((account = tcl_validate_account(objv[2], interp)) == NULL) | |
468 return TCL_ERROR; | |
469 serv_get_info(gaim_account_get_connection(account), Tcl_GetString(objv[3])); | |
470 } | |
471 break; | |
472 case CMD_BUDDY_LIST: | |
473 if (objc == 3) { | |
474 if (!strcmp("-all", Tcl_GetString(objv[2]))) { | |
475 all = 1; | |
476 } else { | |
477 Tcl_SetStringObj(result, "", -1); | |
478 Tcl_AppendStringsToObj(result, "unknown option: ", Tcl_GetString(objv[2]), NULL); | |
479 return TCL_ERROR; | |
480 } | |
481 } | |
482 list = Tcl_NewListObj(0, NULL); | |
483 blist = gaim_get_blist(); | |
484 for (gnode = blist->root; gnode != NULL; gnode = gnode->next) { | |
485 tclgroup = Tcl_NewListObj(0, NULL); | |
486 Tcl_ListObjAppendElement(interp, tclgroup, Tcl_NewStringObj("group", -1)); | |
487 Tcl_ListObjAppendElement(interp, tclgroup, | |
488 Tcl_NewStringObj(((GaimGroup *)gnode)->name, -1)); | |
489 tclgrouplist = Tcl_NewListObj(0, NULL); | |
490 for (node = gnode->child; node != NULL; node = node->next) { | |
491 switch (node->type) { | |
492 case GAIM_BLIST_CONTACT_NODE: | |
493 tclcontact = Tcl_NewListObj(0, NULL); | |
494 Tcl_IncrRefCount(tclcontact); | |
495 Tcl_ListObjAppendElement(interp, tclcontact, Tcl_NewStringObj("contact", -1)); | |
496 tclcontactlist = Tcl_NewListObj(0, NULL); | |
497 Tcl_IncrRefCount(tclcontactlist); | |
498 count = 0; | |
499 for (bnode = node->child; bnode != NULL; bnode = bnode ->next) { | |
500 if (bnode->type != GAIM_BLIST_BUDDY_NODE) | |
501 continue; | |
502 bud = (GaimBuddy *)bnode; | |
503 if (!all && !gaim_account_is_connected(bud->account)) | |
504 continue; | |
505 count++; | |
506 tclbud = Tcl_NewListObj(0, NULL); | |
507 Tcl_ListObjAppendElement(interp, tclbud, Tcl_NewStringObj("buddy", -1)); | |
508 Tcl_ListObjAppendElement(interp, tclbud, Tcl_NewStringObj(bud->name, -1)); | |
509 Tcl_ListObjAppendElement(interp, tclbud, gaim_tcl_ref_new(GaimTclRefAccount, bud->account)); | |
510 Tcl_ListObjAppendElement(interp, tclcontactlist, tclbud); | |
511 } | |
512 if (count) { | |
513 Tcl_ListObjAppendElement(interp, tclcontact, tclcontactlist); | |
514 Tcl_ListObjAppendElement(interp, tclgrouplist, tclcontact); | |
515 } | |
516 Tcl_DecrRefCount(tclcontact); | |
517 Tcl_DecrRefCount(tclcontactlist); | |
518 break; | |
519 case GAIM_BLIST_CHAT_NODE: | |
520 cnode = (GaimChat *)node; | |
521 if (!all && !gaim_account_is_connected(cnode->account)) | |
522 continue; | |
523 tclbud = Tcl_NewListObj(0, NULL); | |
524 Tcl_ListObjAppendElement(interp, tclbud, Tcl_NewStringObj("chat", -1)); | |
525 Tcl_ListObjAppendElement(interp, tclbud, Tcl_NewStringObj(cnode->alias, -1)); | |
526 Tcl_ListObjAppendElement(interp, tclbud, gaim_tcl_ref_new(GaimTclRefAccount, cnode->account)); | |
527 Tcl_ListObjAppendElement(interp, tclgrouplist, tclbud); | |
528 break; | |
529 default: | |
530 gaim_debug(GAIM_DEBUG_WARNING, "tcl", "Unexpected buddy type %d", node->type); | |
531 continue; | |
532 } | |
533 } | |
534 Tcl_ListObjAppendElement(interp, tclgroup, tclgrouplist); | |
535 Tcl_ListObjAppendElement(interp, list, tclgroup); | |
536 } | |
537 Tcl_SetObjResult(interp, list); | |
538 break; | |
539 } | |
540 | |
541 return TCL_OK; | |
542 } | |
543 | |
544 int tcl_cmd_cmd(ClientData unused, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) | |
545 { | |
546 const char *cmds[] = { "register", "unregister", NULL }; | |
547 enum { CMD_CMD_REGISTER, CMD_CMD_UNREGISTER } cmd; | |
548 struct tcl_cmd_handler *handler; | |
549 Tcl_Obj *result = Tcl_GetObjResult(interp); | |
550 GaimCmdId id; | |
551 int error; | |
552 | |
553 if (objc < 2) { | |
554 Tcl_WrongNumArgs(interp, 1, objv, "subcommand ?args?"); | |
555 return TCL_ERROR; | |
556 } | |
557 | |
558 if ((error = Tcl_GetIndexFromObj(interp, objv[1], cmds, "subcommand", 0, (int *)&cmd)) != TCL_OK) | |
559 return error; | |
560 | |
561 switch (cmd) { | |
562 case CMD_CMD_REGISTER: | |
563 if (objc != 9) { | |
564 Tcl_WrongNumArgs(interp, 2, objv, "cmd arglist priority flags prpl_id proc helpstr"); | |
565 return TCL_ERROR; | |
566 } | |
567 handler = g_new0(struct tcl_cmd_handler, 1); | |
568 handler->cmd = objv[2]; | |
569 handler->args = Tcl_GetString(objv[3]); | |
570 handler->nargs = strlen(handler->args); | |
571 if ((error = Tcl_GetIntFromObj(interp, objv[4], | |
572 &handler->priority)) != TCL_OK) { | |
573 g_free(handler); | |
574 return error; | |
575 } | |
576 if ((error = Tcl_GetIntFromObj(interp, objv[5], | |
577 &handler->flags)) != TCL_OK) { | |
578 g_free(handler); | |
579 return error; | |
580 } | |
581 handler->prpl_id = Tcl_GetString(objv[6]); | |
582 handler->proc = objv[7]; | |
583 handler->helpstr = Tcl_GetString(objv[8]); | |
584 handler->interp = interp; | |
585 if ((id = tcl_cmd_register(handler)) == 0) { | |
586 tcl_cmd_handler_free(handler); | |
587 Tcl_SetIntObj(result, 0); | |
588 } else { | |
589 handler->id = id; | |
590 Tcl_SetIntObj(result, id); | |
591 } | |
592 break; | |
593 case CMD_CMD_UNREGISTER: | |
594 if (objc != 3) { | |
595 Tcl_WrongNumArgs(interp, 2, objv, "id"); | |
596 return TCL_ERROR; | |
597 } | |
598 if ((error = Tcl_GetIntFromObj(interp, objv[2], | |
599 (int *)&id)) != TCL_OK) | |
600 return error; | |
601 tcl_cmd_unregister(id, interp); | |
602 break; | |
603 } | |
604 | |
605 return TCL_OK; | |
606 } | |
607 | |
608 int tcl_cmd_connection(ClientData unused, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) | |
609 { | |
610 Tcl_Obj *result = Tcl_GetObjResult(interp), *list, *elem; | |
611 const char *cmds[] = { "account", "displayname", "handle", "list", NULL }; | |
612 enum { CMD_CONN_ACCOUNT, CMD_CONN_DISPLAYNAME, CMD_CONN_HANDLE, CMD_CONN_LIST } cmd; | |
613 int error; | |
614 GList *cur; | |
615 GaimConnection *gc; | |
616 | |
617 if (objc < 2) { | |
618 Tcl_WrongNumArgs(interp, 1, objv, "subcommand ?args?"); | |
619 return TCL_ERROR; | |
620 } | |
621 | |
622 if ((error = Tcl_GetIndexFromObj(interp, objv[1], cmds, "subcommand", 0, (int *)&cmd)) != TCL_OK) | |
623 return error; | |
624 | |
625 switch (cmd) { | |
626 case CMD_CONN_ACCOUNT: | |
627 if (objc != 3) { | |
628 Tcl_WrongNumArgs(interp, 2, objv, "gc"); | |
629 return TCL_ERROR; | |
630 } | |
631 if ((gc = tcl_validate_gc(objv[2], interp)) == NULL) | |
632 return TCL_ERROR; | |
633 Tcl_SetObjResult(interp, | |
634 gaim_tcl_ref_new(GaimTclRefAccount, | |
635 gaim_connection_get_account(gc))); | |
636 break; | |
637 case CMD_CONN_DISPLAYNAME: | |
638 if (objc != 3) { | |
639 Tcl_WrongNumArgs(interp, 2, objv, "gc"); | |
640 return TCL_ERROR; | |
641 } | |
642 if ((gc = tcl_validate_gc(objv[2], interp)) == NULL) | |
643 return TCL_ERROR; | |
644 Tcl_SetStringObj(result, (char *)gaim_connection_get_display_name(gc), -1); | |
645 break; | |
646 case CMD_CONN_HANDLE: | |
647 if (objc != 2) { | |
648 Tcl_WrongNumArgs(interp, 2, objv, ""); | |
649 return TCL_ERROR; | |
650 } | |
651 Tcl_SetIntObj(result, (int)gaim_connections_get_handle()); | |
652 break; | |
653 case CMD_CONN_LIST: | |
654 if (objc != 2) { | |
655 Tcl_WrongNumArgs(interp, 2, objv, ""); | |
656 return TCL_ERROR; | |
657 } | |
658 list = Tcl_NewListObj(0, NULL); | |
659 for (cur = gaim_connections_get_all(); cur != NULL; cur = g_list_next(cur)) { | |
660 elem = gaim_tcl_ref_new(GaimTclRefConnection, cur->data); | |
661 Tcl_ListObjAppendElement(interp, list, elem); | |
662 } | |
663 Tcl_SetObjResult(interp, list); | |
664 break; | |
665 } | |
666 | |
667 return TCL_OK; | |
668 } | |
669 | |
670 int tcl_cmd_conversation(ClientData unused, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) | |
671 { | |
672 Tcl_Obj *list, *elem, *result = Tcl_GetObjResult(interp); | |
14363
4558e71a5a34
[gaim-migrate @ 17069]
Etan Reisner <pidgin@unreliablesource.net>
parents:
14295
diff
changeset
|
673 const char *cmds[] = { "find", "handle", "list", "new", "write", "name", "title", "send", NULL }; |
4558e71a5a34
[gaim-migrate @ 17069]
Etan Reisner <pidgin@unreliablesource.net>
parents:
14295
diff
changeset
|
674 enum { CMD_CONV_FIND, CMD_CONV_HANDLE, CMD_CONV_LIST, CMD_CONV_NEW, CMD_CONV_WRITE , CMD_CONV_NAME, CMD_CONV_TITLE, CMD_CONV_SEND } cmd; |
14192 | 675 const char *styles[] = { "send", "recv", "system", NULL }; |
676 enum { CMD_CONV_WRITE_SEND, CMD_CONV_WRITE_RECV, CMD_CONV_WRITE_SYSTEM } style; | |
677 const char *newopts[] = { "-chat", "-im" }; | |
678 enum { CMD_CONV_NEW_CHAT, CMD_CONV_NEW_IM } newopt; | |
679 GaimConversation *convo; | |
680 GaimAccount *account; | |
681 GaimConversationType type; | |
682 GList *cur; | |
683 char *opt, *from, *what; | |
684 int error, argsused, flags = 0; | |
685 | |
686 if (objc < 2) { | |
687 Tcl_WrongNumArgs(interp, 1, objv, "subcommand ?args?"); | |
688 return TCL_ERROR; | |
689 } | |
690 | |
691 if ((error = Tcl_GetIndexFromObj(interp, objv[1], cmds, "subcommand", 0, (int *)&cmd)) != TCL_OK) | |
692 return error; | |
693 | |
694 switch (cmd) { | |
695 case CMD_CONV_FIND: | |
696 if (objc != 4) { | |
697 Tcl_WrongNumArgs(interp, 2, objv, "account name"); | |
698 return TCL_ERROR; | |
699 } | |
700 account = NULL; | |
701 if ((account = tcl_validate_account(objv[2], interp)) == NULL) | |
702 return TCL_ERROR; | |
703 convo = gaim_find_conversation_with_account(GAIM_CONV_TYPE_ANY, | |
704 Tcl_GetString(objv[3]), | |
705 account); | |
706 Tcl_SetObjResult(interp, gaim_tcl_ref_new(GaimTclRefConversation, convo)); | |
707 break; | |
708 case CMD_CONV_HANDLE: | |
709 if (objc != 2) { | |
710 Tcl_WrongNumArgs(interp, 2, objv, ""); | |
711 return TCL_ERROR; | |
712 } | |
713 Tcl_SetIntObj(result, (int)gaim_conversations_get_handle()); | |
714 break; | |
715 case CMD_CONV_LIST: | |
716 list = Tcl_NewListObj(0, NULL); | |
717 for (cur = gaim_get_conversations(); cur != NULL; cur = g_list_next(cur)) { | |
718 elem = gaim_tcl_ref_new(GaimTclRefConversation, cur->data); | |
719 Tcl_ListObjAppendElement(interp, list, elem); | |
720 } | |
721 Tcl_SetObjResult(interp, list); | |
722 break; | |
723 case CMD_CONV_NEW: | |
724 if (objc < 4) { | |
725 Tcl_WrongNumArgs(interp, 2, objv, "?options? account name"); | |
726 return TCL_ERROR; | |
727 } | |
728 argsused = 2; | |
729 type = GAIM_CONV_TYPE_IM; | |
730 while (argsused < objc) { | |
731 opt = Tcl_GetString(objv[argsused]); | |
732 if (*opt == '-') { | |
733 if ((error = Tcl_GetIndexFromObj(interp, objv[argsused], newopts, | |
734 "option", 0, (int *)&newopt)) != TCL_OK) | |
735 return error; | |
736 argsused++; | |
737 switch (newopt) { | |
738 case CMD_CONV_NEW_CHAT: | |
739 type = GAIM_CONV_TYPE_CHAT; | |
740 break; | |
741 case CMD_CONV_NEW_IM: | |
742 type = GAIM_CONV_TYPE_IM; | |
743 break; | |
744 } | |
745 } else { | |
746 break; | |
747 } | |
748 } | |
749 if (objc - argsused != 2) { | |
750 Tcl_WrongNumArgs(interp, 2, objv, "?options? account name"); | |
751 return TCL_ERROR; | |
752 } | |
753 if ((account = tcl_validate_account(objv[argsused++], interp)) == NULL) | |
754 return TCL_ERROR; | |
755 convo = gaim_conversation_new(type, account, Tcl_GetString(objv[argsused])); | |
756 Tcl_SetObjResult(interp, gaim_tcl_ref_new(GaimTclRefConversation, convo)); | |
757 break; | |
758 case CMD_CONV_WRITE: | |
759 if (objc != 6) { | |
760 Tcl_WrongNumArgs(interp, 2, objv, "conversation style from what"); | |
761 return TCL_ERROR; | |
762 } | |
763 if ((convo = tcl_validate_conversation(objv[2], interp)) == NULL) | |
764 return TCL_ERROR; | |
765 if ((error = Tcl_GetIndexFromObj(interp, objv[3], styles, "style", 0, (int *)&style)) != TCL_OK) | |
766 return error; | |
767 from = Tcl_GetString(objv[4]); | |
768 what = Tcl_GetString(objv[5]); | |
769 | |
770 switch (style) { | |
771 case CMD_CONV_WRITE_SEND: | |
772 flags = GAIM_MESSAGE_SEND; | |
773 break; | |
774 case CMD_CONV_WRITE_RECV: | |
775 flags = GAIM_MESSAGE_RECV; | |
776 break; | |
777 case CMD_CONV_WRITE_SYSTEM: | |
778 flags = GAIM_MESSAGE_SYSTEM; | |
779 break; | |
780 } | |
781 if (gaim_conversation_get_type(convo) == GAIM_CONV_TYPE_CHAT) | |
782 gaim_conv_chat_write(GAIM_CONV_CHAT(convo), from, what, flags, time(NULL)); | |
783 else | |
784 gaim_conv_im_write(GAIM_CONV_IM(convo), from, what, flags, time(NULL)); | |
785 break; | |
14295
b76462fea543
[gaim-migrate @ 16985]
Etan Reisner <pidgin@unreliablesource.net>
parents:
14192
diff
changeset
|
786 case CMD_CONV_NAME: |
b76462fea543
[gaim-migrate @ 16985]
Etan Reisner <pidgin@unreliablesource.net>
parents:
14192
diff
changeset
|
787 if (objc != 3) { |
b76462fea543
[gaim-migrate @ 16985]
Etan Reisner <pidgin@unreliablesource.net>
parents:
14192
diff
changeset
|
788 Tcl_WrongNumArgs(interp, 2, objv, "conversation"); |
b76462fea543
[gaim-migrate @ 16985]
Etan Reisner <pidgin@unreliablesource.net>
parents:
14192
diff
changeset
|
789 return TCL_ERROR; |
b76462fea543
[gaim-migrate @ 16985]
Etan Reisner <pidgin@unreliablesource.net>
parents:
14192
diff
changeset
|
790 } |
b76462fea543
[gaim-migrate @ 16985]
Etan Reisner <pidgin@unreliablesource.net>
parents:
14192
diff
changeset
|
791 |
b76462fea543
[gaim-migrate @ 16985]
Etan Reisner <pidgin@unreliablesource.net>
parents:
14192
diff
changeset
|
792 if ((convo = tcl_validate_conversation(objv[2], interp)) == NULL) |
b76462fea543
[gaim-migrate @ 16985]
Etan Reisner <pidgin@unreliablesource.net>
parents:
14192
diff
changeset
|
793 return TCL_ERROR; |
b76462fea543
[gaim-migrate @ 16985]
Etan Reisner <pidgin@unreliablesource.net>
parents:
14192
diff
changeset
|
794 Tcl_SetStringObj(result, (char *)gaim_conversation_get_name(convo), -1); |
b76462fea543
[gaim-migrate @ 16985]
Etan Reisner <pidgin@unreliablesource.net>
parents:
14192
diff
changeset
|
795 break; |
b76462fea543
[gaim-migrate @ 16985]
Etan Reisner <pidgin@unreliablesource.net>
parents:
14192
diff
changeset
|
796 case CMD_CONV_TITLE: |
b76462fea543
[gaim-migrate @ 16985]
Etan Reisner <pidgin@unreliablesource.net>
parents:
14192
diff
changeset
|
797 if (objc != 3) { |
b76462fea543
[gaim-migrate @ 16985]
Etan Reisner <pidgin@unreliablesource.net>
parents:
14192
diff
changeset
|
798 Tcl_WrongNumArgs(interp, 2, objv, "conversation"); |
b76462fea543
[gaim-migrate @ 16985]
Etan Reisner <pidgin@unreliablesource.net>
parents:
14192
diff
changeset
|
799 return TCL_ERROR; |
b76462fea543
[gaim-migrate @ 16985]
Etan Reisner <pidgin@unreliablesource.net>
parents:
14192
diff
changeset
|
800 } |
b76462fea543
[gaim-migrate @ 16985]
Etan Reisner <pidgin@unreliablesource.net>
parents:
14192
diff
changeset
|
801 |
b76462fea543
[gaim-migrate @ 16985]
Etan Reisner <pidgin@unreliablesource.net>
parents:
14192
diff
changeset
|
802 if ((convo = tcl_validate_conversation(objv[2], interp)) == NULL) |
b76462fea543
[gaim-migrate @ 16985]
Etan Reisner <pidgin@unreliablesource.net>
parents:
14192
diff
changeset
|
803 return TCL_ERROR; |
b76462fea543
[gaim-migrate @ 16985]
Etan Reisner <pidgin@unreliablesource.net>
parents:
14192
diff
changeset
|
804 Tcl_SetStringObj(result, (char *)gaim_conversation_get_title(convo), -1); |
b76462fea543
[gaim-migrate @ 16985]
Etan Reisner <pidgin@unreliablesource.net>
parents:
14192
diff
changeset
|
805 break; |
14363
4558e71a5a34
[gaim-migrate @ 17069]
Etan Reisner <pidgin@unreliablesource.net>
parents:
14295
diff
changeset
|
806 case CMD_CONV_SEND: |
4558e71a5a34
[gaim-migrate @ 17069]
Etan Reisner <pidgin@unreliablesource.net>
parents:
14295
diff
changeset
|
807 if (objc != 4) { |
4558e71a5a34
[gaim-migrate @ 17069]
Etan Reisner <pidgin@unreliablesource.net>
parents:
14295
diff
changeset
|
808 Tcl_WrongNumArgs(interp, 2, objv, "conversation message"); |
4558e71a5a34
[gaim-migrate @ 17069]
Etan Reisner <pidgin@unreliablesource.net>
parents:
14295
diff
changeset
|
809 return TCL_ERROR; |
4558e71a5a34
[gaim-migrate @ 17069]
Etan Reisner <pidgin@unreliablesource.net>
parents:
14295
diff
changeset
|
810 } |
4558e71a5a34
[gaim-migrate @ 17069]
Etan Reisner <pidgin@unreliablesource.net>
parents:
14295
diff
changeset
|
811 if ((convo = tcl_validate_conversation(objv[2], interp)) == NULL) |
4558e71a5a34
[gaim-migrate @ 17069]
Etan Reisner <pidgin@unreliablesource.net>
parents:
14295
diff
changeset
|
812 return TCL_ERROR; |
4558e71a5a34
[gaim-migrate @ 17069]
Etan Reisner <pidgin@unreliablesource.net>
parents:
14295
diff
changeset
|
813 what = Tcl_GetString(objv[3]); |
4558e71a5a34
[gaim-migrate @ 17069]
Etan Reisner <pidgin@unreliablesource.net>
parents:
14295
diff
changeset
|
814 if (gaim_conversation_get_type(convo) == GAIM_CONV_TYPE_CHAT) |
4558e71a5a34
[gaim-migrate @ 17069]
Etan Reisner <pidgin@unreliablesource.net>
parents:
14295
diff
changeset
|
815 gaim_conv_chat_send(GAIM_CONV_CHAT(convo), what); |
4558e71a5a34
[gaim-migrate @ 17069]
Etan Reisner <pidgin@unreliablesource.net>
parents:
14295
diff
changeset
|
816 else |
4558e71a5a34
[gaim-migrate @ 17069]
Etan Reisner <pidgin@unreliablesource.net>
parents:
14295
diff
changeset
|
817 gaim_conv_im_send(GAIM_CONV_IM(convo), what); |
4558e71a5a34
[gaim-migrate @ 17069]
Etan Reisner <pidgin@unreliablesource.net>
parents:
14295
diff
changeset
|
818 break; |
14192 | 819 } |
820 | |
821 return TCL_OK; | |
822 } | |
823 | |
824 int tcl_cmd_core(ClientData unused, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) | |
825 { | |
826 Tcl_Obj *result = Tcl_GetObjResult(interp); | |
827 const char *cmds[] = { "handle", "quit", NULL }; | |
828 enum { CMD_CORE_HANDLE, CMD_CORE_QUIT } cmd; | |
829 int error; | |
830 | |
831 if (objc < 2) { | |
832 Tcl_WrongNumArgs(interp, 1, objv, "subcommand ?args?"); | |
833 return TCL_ERROR; | |
834 } | |
835 | |
836 if ((error = Tcl_GetIndexFromObj(interp, objv[1], cmds, "subcommand", 0, (int *)&cmd)) != TCL_OK) | |
837 return error; | |
838 | |
839 switch (cmd) { | |
840 case CMD_CORE_HANDLE: | |
841 if (objc != 2) { | |
842 Tcl_WrongNumArgs(interp, 2, objv, ""); | |
843 return TCL_ERROR; | |
844 } | |
845 Tcl_SetIntObj(result, (int)gaim_get_core()); | |
846 break; | |
847 case CMD_CORE_QUIT: | |
848 if (objc != 2) { | |
849 Tcl_WrongNumArgs(interp, 2, objv, ""); | |
850 return TCL_ERROR; | |
851 } | |
852 gaim_core_quit(); | |
853 break; | |
854 } | |
855 | |
856 return TCL_OK; | |
857 } | |
858 | |
859 int tcl_cmd_debug(ClientData unused, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) | |
860 { | |
861 char *category, *message; | |
862 int lev; | |
863 const char *levels[] = { "-misc", "-info", "-warning", "-error", NULL }; | |
864 GaimDebugLevel levelind[] = { GAIM_DEBUG_MISC, GAIM_DEBUG_INFO, GAIM_DEBUG_WARNING, GAIM_DEBUG_ERROR }; | |
865 int error; | |
866 | |
867 if (objc != 4) { | |
868 Tcl_WrongNumArgs(interp, 1, objv, "level category message"); | |
869 return TCL_ERROR; | |
870 } | |
871 | |
872 error = Tcl_GetIndexFromObj(interp, objv[1], levels, "debug level", 0, &lev); | |
873 if (error != TCL_OK) | |
874 return error; | |
875 | |
876 category = Tcl_GetString(objv[2]); | |
877 message = Tcl_GetString(objv[3]); | |
878 | |
879 gaim_debug(levelind[lev], category, "%s\n", message); | |
880 | |
881 return TCL_OK; | |
882 } | |
883 | |
884 int tcl_cmd_notify(ClientData unused, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) | |
885 { | |
886 int error, type; | |
887 const char *opts[] = { "-error", "-warning", "-info", NULL }; | |
888 GaimNotifyMsgType optind[] = { GAIM_NOTIFY_MSG_ERROR, GAIM_NOTIFY_MSG_WARNING, GAIM_NOTIFY_MSG_INFO }; | |
889 char *title, *msg1, *msg2; | |
890 | |
891 if (objc < 4 || objc > 5) { | |
892 Tcl_WrongNumArgs(interp, 1, objv, "?type? title primary secondary"); | |
893 return TCL_ERROR; | |
894 } | |
895 | |
896 if (objc == 4) { | |
897 type = 1; /* Default to warning */ | |
898 title = Tcl_GetString(objv[1]); | |
899 msg1 = Tcl_GetString(objv[2]); | |
900 msg2 = Tcl_GetString(objv[3]); | |
901 } else { | |
902 error = Tcl_GetIndexFromObj(interp, objv[1], opts, "message type", 0, &type); | |
903 if (error != TCL_OK) | |
904 return error; | |
905 title = Tcl_GetString(objv[2]); | |
906 msg1 = Tcl_GetString(objv[3]); | |
907 msg2 = Tcl_GetString(objv[4]); | |
908 } | |
909 | |
910 gaim_notify_message(_tcl_plugin, optind[type], title, msg1, msg2, NULL, NULL); | |
911 | |
912 return TCL_OK; | |
913 } | |
914 | |
915 int tcl_cmd_prefs(ClientData unused, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) | |
916 { | |
917 Tcl_Obj *result, *list, *elem, **elems; | |
918 const char *cmds[] = { "get", "set", "type", NULL }; | |
919 enum { CMD_PREFS_GET, CMD_PREFS_SET, CMD_PREFS_TYPE } cmd; | |
920 /* char *types[] = { "none", "boolean", "int", "string", "stringlist", NULL }; */ | |
921 /* enum { TCL_PREFS_NONE, TCL_PREFS_BOOL, TCL_PREFS_INT, TCL_PREFS_STRING, TCL_PREFS_STRINGLIST } type; */ | |
922 GaimPrefType preftype; | |
923 GList *cur; | |
924 int error, intval, nelem, i; | |
925 | |
926 if (objc < 2) { | |
927 Tcl_WrongNumArgs(interp, 1, objv, "subcommand ?args?"); | |
928 return TCL_ERROR; | |
929 } | |
930 | |
931 if ((error = Tcl_GetIndexFromObj(interp, objv[1], cmds, "subcommand", 0, (int *)&cmd)) != TCL_OK) | |
932 return error; | |
933 | |
934 result = Tcl_GetObjResult(interp); | |
935 switch (cmd) { | |
936 case CMD_PREFS_GET: | |
937 if (objc != 3) { | |
938 Tcl_WrongNumArgs(interp, 1, objv, "path"); | |
939 return TCL_ERROR; | |
940 } | |
941 preftype = gaim_prefs_get_type(Tcl_GetString(objv[2])); | |
942 switch (preftype) { | |
943 case GAIM_PREF_NONE: | |
944 Tcl_SetStringObj(result, "pref type none", -1); | |
945 return TCL_ERROR; | |
946 break; | |
947 case GAIM_PREF_BOOLEAN: | |
948 Tcl_SetBooleanObj(result, gaim_prefs_get_bool(Tcl_GetString(objv[2]))); | |
949 break; | |
950 case GAIM_PREF_INT: | |
951 Tcl_SetIntObj(result, gaim_prefs_get_int(Tcl_GetString(objv[2]))); | |
952 break; | |
953 case GAIM_PREF_STRING: | |
954 Tcl_SetStringObj(result, (char *)gaim_prefs_get_string(Tcl_GetString(objv[2])), -1); | |
955 break; | |
956 case GAIM_PREF_STRING_LIST: | |
957 cur = gaim_prefs_get_string_list(Tcl_GetString(objv[2])); | |
958 list = Tcl_NewListObj(0, NULL); | |
959 while (cur != NULL) { | |
960 elem = Tcl_NewStringObj((char *)cur->data, -1); | |
961 Tcl_ListObjAppendElement(interp, list, elem); | |
962 cur = g_list_next(cur); | |
963 } | |
964 Tcl_SetObjResult(interp, list); | |
965 break; | |
966 default: | |
967 gaim_debug(GAIM_DEBUG_ERROR, "tcl", "tcl does not know about pref type %d\n", preftype); | |
968 Tcl_SetStringObj(result, "unknown pref type", -1); | |
969 return TCL_ERROR; | |
970 } | |
971 break; | |
972 case CMD_PREFS_SET: | |
973 if (objc != 4) { | |
974 Tcl_WrongNumArgs(interp, 1, objv, "path value"); | |
975 return TCL_ERROR; | |
976 } | |
977 preftype = gaim_prefs_get_type(Tcl_GetString(objv[2])); | |
978 switch (preftype) { | |
979 case GAIM_PREF_NONE: | |
980 Tcl_SetStringObj(result, "bad path or pref type none", -1); | |
981 return TCL_ERROR; | |
982 break; | |
983 case GAIM_PREF_BOOLEAN: | |
984 if ((error = Tcl_GetBooleanFromObj(interp, objv[3], &intval)) != TCL_OK) | |
985 return error; | |
986 gaim_prefs_set_bool(Tcl_GetString(objv[2]), intval); | |
987 break; | |
988 case GAIM_PREF_INT: | |
989 if ((error = Tcl_GetIntFromObj(interp, objv[3], &intval)) != TCL_OK) | |
990 return error; | |
991 gaim_prefs_set_int(Tcl_GetString(objv[2]), intval); | |
992 break; | |
993 case GAIM_PREF_STRING: | |
994 gaim_prefs_set_string(Tcl_GetString(objv[2]), Tcl_GetString(objv[3])); | |
995 break; | |
996 case GAIM_PREF_STRING_LIST: | |
997 if ((error = Tcl_ListObjGetElements(interp, objv[3], &nelem, &elems)) != TCL_OK) | |
998 return error; | |
999 cur = NULL; | |
1000 for (i = 0; i < nelem; i++) { | |
1001 cur = g_list_append(cur, (gpointer)Tcl_GetString(elems[i])); | |
1002 } | |
1003 gaim_prefs_set_string_list(Tcl_GetString(objv[2]), cur); | |
1004 g_list_free(cur); | |
1005 break; | |
1006 default: | |
1007 gaim_debug(GAIM_DEBUG_ERROR, "tcl", "tcl does not know about pref type %d\n", preftype); | |
1008 return TCL_ERROR; | |
1009 } | |
1010 break; | |
1011 case CMD_PREFS_TYPE: | |
1012 if (objc != 3) { | |
1013 Tcl_WrongNumArgs(interp, 1, objv, "path"); | |
1014 return TCL_ERROR; | |
1015 } | |
1016 preftype = gaim_prefs_get_type(Tcl_GetString(objv[2])); | |
1017 switch (preftype) { | |
1018 case GAIM_PREF_NONE: | |
1019 Tcl_SetStringObj(result, "none", -1); | |
1020 break; | |
1021 case GAIM_PREF_BOOLEAN: | |
1022 Tcl_SetStringObj(result, "boolean", -1); | |
1023 break; | |
1024 case GAIM_PREF_INT: | |
1025 Tcl_SetStringObj(result, "int", -1); | |
1026 break; | |
1027 case GAIM_PREF_STRING: | |
1028 Tcl_SetStringObj(result, "string", -1); | |
1029 break; | |
1030 case GAIM_PREF_STRING_LIST: | |
1031 Tcl_SetStringObj(result, "stringlist", -1); | |
1032 break; | |
1033 default: | |
1034 gaim_debug(GAIM_DEBUG_ERROR, "tcl", "tcl does not know about pref type %d\n", preftype); | |
1035 Tcl_SetStringObj(result, "unknown", -1); | |
1036 } | |
1037 break; | |
1038 } | |
1039 | |
1040 return TCL_OK; | |
1041 } | |
1042 | |
1043 int tcl_cmd_presence(ClientData unused, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) | |
1044 { | |
1045 const char *cmds[] = { "account", "active_status", "available", | |
1046 "chat_user", "context", "conversation", "idle", | |
1047 "login", "online", "status", "statuses", NULL }; | |
1048 enum { CMD_PRESENCE_ACCOUNT, CMD_PRESENCE_ACTIVE_STATUS, | |
1049 CMD_PRESENCE_AVAILABLE, CMD_PRESENCE_CHAT_USER, | |
1050 CMD_PRESENCE_CONTEXT, CMD_PRESENCE_CONVERSATION, | |
1051 CMD_PRESENCE_IDLE, CMD_PRESENCE_LOGIN, CMD_PRESENCE_ONLINE, | |
1052 CMD_PRESENCE_STATUS, CMD_PRESENCE_STATUSES } cmd; | |
1053 Tcl_Obj *result = Tcl_GetObjResult(interp); | |
1054 Tcl_Obj *list, *elem; | |
1055 GaimPresence *presence; | |
1056 const GList *cur; | |
1057 int error, idle, idle_time, login_time; | |
1058 | |
1059 if (objc < 2) { | |
1060 Tcl_WrongNumArgs(interp, 1, objv, "subcommand ?args?"); | |
1061 return TCL_ERROR; | |
1062 } | |
1063 | |
1064 if ((error = Tcl_GetIndexFromObj(interp, objv[1], cmds, "subcommand", 0, (int *)&cmd)) != TCL_OK) | |
1065 return error; | |
1066 | |
1067 switch (cmd) { | |
1068 case CMD_PRESENCE_ACCOUNT: | |
1069 if (objc != 3) { | |
1070 Tcl_WrongNumArgs(interp, 2, objv, "presence"); | |
1071 return TCL_ERROR; | |
1072 } | |
1073 if ((presence = gaim_tcl_ref_get(interp, objv[2], GaimTclRefPresence)) == NULL) | |
1074 return TCL_ERROR; | |
1075 Tcl_SetObjResult(interp, gaim_tcl_ref_new(GaimTclRefAccount, | |
1076 gaim_presence_get_account(presence))); | |
1077 break; | |
1078 case CMD_PRESENCE_ACTIVE_STATUS: | |
1079 if (objc != 3 && objc != 4 && objc != 5) { | |
1080 Tcl_WrongNumArgs(interp, 2, objv, "presence [?status_id? | ?-primitive primitive?]"); | |
1081 return TCL_ERROR; | |
1082 } | |
1083 if ((presence = gaim_tcl_ref_get(interp, objv[2], GaimTclRefPresence)) == NULL) | |
1084 return TCL_ERROR; | |
1085 if (objc == 3) { | |
1086 Tcl_SetObjResult(interp, | |
1087 gaim_tcl_ref_new(GaimTclRefStatus, | |
1088 gaim_presence_get_active_status(presence))); | |
1089 } else if (objc == 4) { | |
1090 Tcl_SetBooleanObj(result, | |
1091 gaim_presence_is_status_active(presence, | |
1092 Tcl_GetString(objv[3]))); | |
1093 } else { | |
1094 GaimStatusPrimitive primitive; | |
1095 if (strcmp(Tcl_GetString(objv[3]), "-primitive")) { | |
1096 Tcl_SetStringObj(result, "bad option \"", -1); | |
1097 Tcl_AppendObjToObj(result, objv[3]); | |
1098 Tcl_AppendToObj(result, | |
1099 "\": should be -primitive", -1); | |
1100 return TCL_ERROR; | |
1101 } | |
1102 primitive = gaim_primitive_get_type_from_id(Tcl_GetString(objv[4])); | |
1103 if (primitive == GAIM_STATUS_UNSET) { | |
1104 Tcl_SetStringObj(result, "invalid primitive ", -1); | |
1105 Tcl_AppendObjToObj(result, objv[4]); | |
1106 return TCL_ERROR; | |
1107 } | |
1108 Tcl_SetBooleanObj(result, gaim_presence_is_status_primitive_active(presence, primitive)); | |
1109 break; | |
1110 } | |
1111 break; | |
1112 case CMD_PRESENCE_AVAILABLE: | |
1113 if (objc != 3) { | |
1114 Tcl_WrongNumArgs(interp, 2, objv, "presence"); | |
1115 return TCL_ERROR; | |
1116 } | |
1117 if ((presence = gaim_tcl_ref_get(interp, objv[2], GaimTclRefPresence)) == NULL) | |
1118 return TCL_ERROR; | |
1119 Tcl_SetBooleanObj(result, gaim_presence_is_available(presence)); | |
1120 break; | |
1121 case CMD_PRESENCE_CHAT_USER: | |
1122 if (objc != 3) { | |
1123 Tcl_WrongNumArgs(interp, 2, objv, "presence"); | |
1124 return TCL_ERROR; | |
1125 } | |
1126 if ((presence = gaim_tcl_ref_get(interp, objv[2], GaimTclRefPresence)) == NULL) | |
1127 return TCL_ERROR; | |
1128 Tcl_SetStringObj(result, gaim_presence_get_chat_user(presence), -1); | |
1129 break; | |
1130 case CMD_PRESENCE_CONTEXT: | |
1131 if (objc != 3) { | |
1132 Tcl_WrongNumArgs(interp, 2, objv, "presence"); | |
1133 return TCL_ERROR; | |
1134 } | |
1135 if ((presence = gaim_tcl_ref_get(interp, objv[2], GaimTclRefPresence)) == NULL) | |
1136 return TCL_ERROR; | |
1137 switch (gaim_presence_get_context(presence)) { | |
1138 case GAIM_PRESENCE_CONTEXT_UNSET: | |
1139 Tcl_SetStringObj(result, "unset", -1); | |
1140 break; | |
1141 case GAIM_PRESENCE_CONTEXT_ACCOUNT: | |
1142 Tcl_SetStringObj(result, "account", -1); | |
1143 break; | |
1144 case GAIM_PRESENCE_CONTEXT_CONV: | |
1145 Tcl_SetStringObj(result, "conversation", -1); | |
1146 break; | |
1147 case GAIM_PRESENCE_CONTEXT_BUDDY: | |
1148 Tcl_SetStringObj(result, "buddy", -1); | |
1149 break; | |
1150 } | |
1151 break; | |
1152 case CMD_PRESENCE_CONVERSATION: | |
1153 if (objc != 3) { | |
1154 Tcl_WrongNumArgs(interp, 2, objv, "presence"); | |
1155 return TCL_ERROR; | |
1156 } | |
1157 if ((presence = gaim_tcl_ref_get(interp, objv[2], GaimTclRefPresence)) == NULL) | |
1158 return TCL_ERROR; | |
1159 Tcl_SetObjResult(interp, gaim_tcl_ref_new(GaimTclRefConversation, | |
1160 gaim_presence_get_conversation(presence))); | |
1161 break; | |
1162 case CMD_PRESENCE_IDLE: | |
1163 if (objc < 3 || objc > 5) { | |
1164 Tcl_WrongNumArgs(interp, 2, objv, "presence ?idle? ?time?"); | |
1165 return TCL_ERROR; | |
1166 } | |
1167 if ((presence = gaim_tcl_ref_get(interp, objv[2], GaimTclRefPresence)) == NULL) | |
1168 return TCL_ERROR; | |
1169 if (objc == 3) { | |
1170 if (gaim_presence_is_idle(presence)) { | |
1171 idle_time = gaim_presence_get_idle_time (presence); | |
1172 Tcl_SetIntObj(result, idle_time); | |
1173 } else { | |
1174 result = Tcl_NewListObj(0, NULL); | |
1175 Tcl_SetObjResult(interp, result); | |
1176 } | |
1177 break; | |
1178 } | |
1179 if ((error = Tcl_GetBooleanFromObj(interp, objv[3], &idle)) != TCL_OK) | |
1180 return TCL_ERROR; | |
1181 if (objc == 4) { | |
1182 gaim_presence_set_idle(presence, idle, time(NULL)); | |
1183 } else if (objc == 5) { | |
1184 if ((error = Tcl_GetIntFromObj(interp, | |
1185 objv[4], | |
1186 &idle_time)) != TCL_OK) | |
1187 return TCL_ERROR; | |
1188 gaim_presence_set_idle(presence, idle, idle_time); | |
1189 } | |
1190 break; | |
1191 case CMD_PRESENCE_LOGIN: | |
1192 if (objc != 3 && objc != 4) { | |
1193 Tcl_WrongNumArgs(interp, 2, objv, "presence ?time?"); | |
1194 return TCL_ERROR; | |
1195 } | |
1196 if ((presence = gaim_tcl_ref_get(interp, objv[2], GaimTclRefPresence)) == NULL) | |
1197 return TCL_ERROR; | |
1198 if (objc == 3) { | |
1199 Tcl_SetIntObj(result, gaim_presence_get_login_time(presence)); | |
1200 } else { | |
1201 if ((error == Tcl_GetIntFromObj(interp, | |
1202 objv[3], | |
1203 &login_time)) != TCL_OK) | |
1204 return TCL_ERROR; | |
1205 gaim_presence_set_login_time(presence, login_time); | |
1206 } | |
1207 break; | |
1208 case CMD_PRESENCE_ONLINE: | |
1209 if (objc != 3) { | |
1210 Tcl_WrongNumArgs(interp, 2, objv, "presence"); | |
1211 return TCL_ERROR; | |
1212 } | |
1213 if ((presence = gaim_tcl_ref_get(interp, objv[2], GaimTclRefPresence)) == NULL) | |
1214 return TCL_ERROR; | |
1215 Tcl_SetBooleanObj(result, gaim_presence_is_online(presence)); | |
1216 break; | |
1217 case CMD_PRESENCE_STATUS: | |
1218 if (objc != 4) { | |
1219 Tcl_WrongNumArgs(interp, 2, objv, "presence status_id"); | |
1220 return TCL_ERROR; | |
1221 } | |
1222 if ((presence = gaim_tcl_ref_get(interp, objv[2], GaimTclRefPresence)) == NULL) | |
1223 return TCL_ERROR; | |
1224 Tcl_SetObjResult(interp, | |
1225 gaim_tcl_ref_new(GaimTclRefStatus, | |
1226 gaim_presence_get_status(presence, | |
1227 Tcl_GetString(objv[3])))); | |
1228 break; | |
1229 case CMD_PRESENCE_STATUSES: | |
1230 if (objc != 3) { | |
1231 Tcl_WrongNumArgs(interp, 2, objv, "presence"); | |
1232 return TCL_ERROR; | |
1233 } | |
1234 if ((presence = gaim_tcl_ref_get(interp, objv[2], GaimTclRefPresence)) == NULL) | |
1235 return TCL_ERROR; | |
1236 list = Tcl_NewListObj(0, NULL); | |
1237 for (cur = gaim_presence_get_statuses(presence); cur != NULL; | |
1238 cur = g_list_next(cur)) { | |
1239 elem = gaim_tcl_ref_new(GaimTclRefStatus, cur->data); | |
1240 Tcl_ListObjAppendElement(interp, list, elem); | |
1241 } | |
1242 Tcl_SetObjResult(interp, list); | |
1243 break; | |
1244 } | |
1245 | |
1246 return TCL_OK; | |
1247 } | |
1248 | |
1249 int tcl_cmd_send_im(ClientData unused, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) | |
1250 { | |
1251 GaimConnection *gc; | |
1252 char *who, *text; | |
1253 | |
1254 if (objc != 4) { | |
1255 Tcl_WrongNumArgs(interp, 1, objv, "gc who text"); | |
1256 return TCL_ERROR; | |
1257 } | |
1258 | |
1259 if ((gc = tcl_validate_gc(objv[1], interp)) == NULL) | |
1260 return TCL_ERROR; | |
1261 | |
1262 who = Tcl_GetString(objv[2]); | |
1263 text = Tcl_GetString(objv[3]); | |
1264 | |
1265 serv_send_im(gc, who, text, 0); | |
1266 | |
1267 return TCL_OK; | |
1268 } | |
1269 | |
1270 int tcl_cmd_signal(ClientData unused, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) | |
1271 { | |
1272 const char *cmds[] = { "connect", "disconnect", NULL }; | |
1273 enum { CMD_SIGNAL_CONNECT, CMD_SIGNAL_DISCONNECT } cmd; | |
1274 struct tcl_signal_handler *handler; | |
1275 Tcl_Obj *result = Tcl_GetObjResult(interp); | |
1276 void *instance; | |
1277 int error; | |
1278 | |
1279 if (objc < 2) { | |
1280 Tcl_WrongNumArgs(interp, 1, objv, "subcommand ?args?"); | |
1281 return TCL_ERROR; | |
1282 } | |
1283 | |
1284 if ((error = Tcl_GetIndexFromObj(interp, objv[1], cmds, "subcommand", 0, (int *)&cmd)) != TCL_OK) | |
1285 return error; | |
1286 | |
1287 switch (cmd) { | |
1288 case CMD_SIGNAL_CONNECT: | |
1289 if (objc != 6) { | |
1290 Tcl_WrongNumArgs(interp, 2, objv, "instance signal args proc"); | |
1291 return TCL_ERROR; | |
1292 } | |
1293 handler = g_new0(struct tcl_signal_handler, 1); | |
1294 if ((error = Tcl_GetIntFromObj(interp, objv[2], (int *)&handler->instance)) != TCL_OK) { | |
1295 g_free(handler); | |
1296 return error; | |
1297 } | |
1298 handler->signal = objv[3]; | |
1299 Tcl_IncrRefCount(handler->signal); | |
1300 handler->args = objv[4]; | |
1301 handler->proc = objv[5]; | |
1302 handler->interp = interp; | |
1303 if (!tcl_signal_connect(handler)) { | |
1304 tcl_signal_handler_free(handler); | |
1305 Tcl_SetIntObj(result, 1); | |
1306 } else { | |
1307 Tcl_SetIntObj(result, 0); | |
1308 } | |
1309 break; | |
1310 case CMD_SIGNAL_DISCONNECT: | |
1311 if (objc != 4) { | |
1312 Tcl_WrongNumArgs(interp, 2, objv, "instance signal"); | |
1313 return TCL_ERROR; | |
1314 } | |
1315 if ((error = Tcl_GetIntFromObj(interp, objv[2], (int *)&instance)) != TCL_OK) | |
1316 return error; | |
1317 tcl_signal_disconnect(instance, Tcl_GetString(objv[3]), interp); | |
1318 break; | |
1319 } | |
1320 | |
1321 return TCL_OK; | |
1322 } | |
1323 | |
1324 int tcl_cmd_status(ClientData unused, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) | |
1325 { | |
1326 const char *cmds[] = { "attr", "type", NULL }; | |
1327 enum { CMD_STATUS_ATTR, CMD_STATUS_TYPE } cmd; | |
1328 Tcl_Obj *result = Tcl_GetObjResult(interp); | |
1329 GaimStatus *status; | |
1330 GaimStatusType *status_type; | |
1331 GaimValue *value; | |
1332 const char *attr; | |
1333 int error, v; | |
1334 | |
1335 if (objc < 2) { | |
1336 Tcl_WrongNumArgs(interp, 1, objv, "subcommand ?args?"); | |
1337 return TCL_ERROR; | |
1338 } | |
1339 | |
1340 if ((error = Tcl_GetIndexFromObj(interp, objv[1], cmds, "subcommand", 0, (int *)&cmd)) != TCL_OK) | |
1341 return error; | |
1342 | |
1343 switch (cmd) { | |
1344 case CMD_STATUS_ATTR: | |
1345 if (objc != 4 && objc != 5) { | |
1346 Tcl_WrongNumArgs(interp, 2, objv, "status attr_id ?value?"); | |
1347 return TCL_ERROR; | |
1348 } | |
1349 if ((status = gaim_tcl_ref_get(interp, objv[2], GaimTclRefStatus)) == NULL) | |
1350 return TCL_ERROR; | |
1351 attr = Tcl_GetString(objv[3]); | |
1352 value = gaim_status_get_attr_value(status, attr); | |
1353 if (value == NULL) { | |
1354 Tcl_SetStringObj(result, "no such attribute", -1); | |
1355 return TCL_ERROR; | |
1356 } | |
1357 switch (gaim_value_get_type(value)) { | |
1358 case GAIM_TYPE_BOOLEAN: | |
1359 if (objc == 4) { | |
1360 Tcl_SetBooleanObj(result, gaim_value_get_boolean(value)); | |
1361 } else { | |
1362 if ((error = Tcl_GetBooleanFromObj(interp, objv[4], &v)) != TCL_OK) | |
1363 return error; | |
1364 gaim_status_set_attr_boolean(status, attr, v); | |
1365 } | |
1366 break; | |
1367 case GAIM_TYPE_INT: | |
1368 if (objc == 4) { | |
1369 Tcl_SetIntObj(result, gaim_value_get_int(value)); | |
1370 } else { | |
1371 if ((error = Tcl_GetIntFromObj(interp, objv[4], &v)) != TCL_OK) | |
1372 return error; | |
1373 gaim_status_set_attr_int(status, attr, v ); | |
1374 } | |
1375 break; | |
1376 case GAIM_TYPE_STRING: | |
1377 if (objc == 4) | |
1378 Tcl_SetStringObj(result, gaim_value_get_string(value), -1); | |
1379 else | |
1380 gaim_status_set_attr_string(status, attr, Tcl_GetString(objv[4])); | |
1381 break; | |
1382 default: | |
1383 Tcl_SetStringObj(result, "attribute has unknown type", -1); | |
1384 return TCL_ERROR; | |
1385 } | |
1386 break; | |
1387 case CMD_STATUS_TYPE: | |
1388 if (objc != 3) { | |
1389 Tcl_WrongNumArgs(interp, 2, objv, "status"); | |
1390 return TCL_ERROR; | |
1391 } | |
1392 if ((status = gaim_tcl_ref_get(interp, objv[2], GaimTclRefStatus)) == NULL) | |
1393 return TCL_ERROR; | |
1394 status_type = gaim_status_get_type(status); | |
1395 Tcl_SetObjResult(interp, gaim_tcl_ref_new(GaimTclRefStatusType, | |
1396 status_type)); | |
1397 break; | |
1398 } | |
1399 | |
1400 return TCL_OK; | |
1401 } | |
1402 | |
1403 int tcl_cmd_status_attr(ClientData unused, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) | |
1404 { | |
1405 const char *cmds[] = { "id", "name", NULL }; | |
1406 enum { CMD_STATUS_ATTR_ID, CMD_STATUS_ATTR_NAME } cmd; | |
1407 Tcl_Obj *result = Tcl_GetObjResult(interp); | |
1408 GaimStatusAttr *attr; | |
1409 int error; | |
1410 | |
1411 if (objc < 2) { | |
1412 Tcl_WrongNumArgs(interp, 1, objv, "subcommand ?args?"); | |
1413 return TCL_ERROR; | |
1414 } | |
1415 | |
1416 if ((error = Tcl_GetIndexFromObj(interp, objv[1], cmds, "subcommand", 0, (int *)&cmd)) != TCL_OK) | |
1417 return error; | |
1418 | |
1419 switch (cmd) { | |
1420 case CMD_STATUS_ATTR_ID: | |
1421 if (objc != 3) { | |
1422 Tcl_WrongNumArgs(interp, 2, objv, "attr"); | |
1423 return TCL_ERROR; | |
1424 } | |
1425 if ((attr = gaim_tcl_ref_get(interp, objv[2], GaimTclRefStatusAttr)) == NULL) | |
1426 return TCL_ERROR; | |
1427 Tcl_SetStringObj(result, gaim_status_attr_get_id(attr), -1); | |
1428 break; | |
1429 case CMD_STATUS_ATTR_NAME: | |
1430 if (objc != 3) { | |
1431 Tcl_WrongNumArgs(interp, 2, objv, "attr"); | |
1432 return TCL_ERROR; | |
1433 } | |
1434 if ((attr = gaim_tcl_ref_get(interp, objv[2], GaimTclRefStatusAttr)) == NULL) | |
1435 return TCL_ERROR; | |
1436 Tcl_SetStringObj(result, gaim_status_attr_get_name(attr), -1); | |
1437 break; | |
1438 } | |
1439 | |
1440 return TCL_OK; | |
1441 } | |
1442 | |
1443 int tcl_cmd_status_type(ClientData unused, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) | |
1444 { | |
1445 const char *cmds[] = { "attr", "attrs", "available", "exclusive", "id", | |
1446 "independent", "name", "primary_attr", | |
1447 "primitive", "saveable", "user_settable", | |
1448 NULL }; | |
1449 enum { CMD_STATUS_TYPE_ATTR, CMD_STATUS_TYPE_ATTRS, | |
1450 CMD_STATUS_TYPE_AVAILABLE, CMD_STATUS_TYPE_EXCLUSIVE, | |
1451 CMD_STATUS_TYPE_ID, CMD_STATUS_TYPE_INDEPENDENT, | |
1452 CMD_STATUS_TYPE_NAME, CMD_STATUS_TYPE_PRIMARY_ATTR, | |
1453 CMD_STATUS_TYPE_PRIMITIVE, CMD_STATUS_TYPE_SAVEABLE, | |
1454 CMD_STATUS_TYPE_USER_SETTABLE } cmd; | |
1455 Tcl_Obj *result = Tcl_GetObjResult(interp); | |
1456 GaimStatusType *status_type; | |
1457 Tcl_Obj *list, *elem; | |
1458 const GList *cur; | |
1459 int error; | |
1460 | |
1461 if (objc < 2) { | |
1462 Tcl_WrongNumArgs(interp, 1, objv, "subcommand ?args?"); | |
1463 return TCL_ERROR; | |
1464 } | |
1465 | |
1466 if ((error = Tcl_GetIndexFromObj(interp, objv[1], cmds, "subcommand", 0, (int *)&cmd)) != TCL_OK) | |
1467 return error; | |
1468 | |
1469 switch (cmd) { | |
1470 case CMD_STATUS_TYPE_AVAILABLE: | |
1471 if (objc != 3) { | |
1472 Tcl_WrongNumArgs(interp, 2, objv, "statustype"); | |
1473 return TCL_ERROR; | |
1474 } | |
1475 if ((status_type = gaim_tcl_ref_get(interp, objv[2], GaimTclRefStatusType)) == NULL) | |
1476 return TCL_ERROR; | |
1477 Tcl_SetBooleanObj(result, gaim_status_type_is_available(status_type)); | |
1478 break; | |
1479 case CMD_STATUS_TYPE_ATTR: | |
1480 if (objc != 4) { | |
1481 Tcl_WrongNumArgs(interp, 2, objv, "statustype attr"); | |
1482 return TCL_ERROR; | |
1483 } | |
1484 if ((status_type = gaim_tcl_ref_get(interp, objv[2], GaimTclRefStatusType)) == NULL) | |
1485 return TCL_ERROR; | |
1486 Tcl_SetObjResult(interp, | |
1487 gaim_tcl_ref_new(GaimTclRefStatusAttr, | |
1488 gaim_status_type_get_attr(status_type, | |
1489 Tcl_GetStringFromObj(objv[3], NULL)))); | |
1490 break; | |
1491 case CMD_STATUS_TYPE_ATTRS: | |
1492 if (objc != 3) { | |
1493 Tcl_WrongNumArgs(interp, 2, objv, "statustype"); | |
1494 return TCL_ERROR; | |
1495 } | |
1496 if ((status_type = gaim_tcl_ref_get(interp, objv[2], GaimTclRefStatusType)) == NULL) | |
1497 return TCL_ERROR; | |
1498 list = Tcl_NewListObj(0, NULL); | |
1499 for (cur = gaim_status_type_get_attrs(status_type); | |
1500 cur != NULL; cur = g_list_next(cur)) { | |
1501 elem = gaim_tcl_ref_new(GaimTclRefStatusAttr, cur->data); | |
1502 Tcl_ListObjAppendElement(interp, list, elem); | |
1503 } | |
1504 Tcl_SetObjResult(interp, list); | |
1505 break; | |
1506 case CMD_STATUS_TYPE_EXCLUSIVE: | |
1507 if (objc != 3) { | |
1508 Tcl_WrongNumArgs(interp, 2, objv, "statustype"); | |
1509 return TCL_ERROR; | |
1510 } | |
1511 if ((status_type = gaim_tcl_ref_get(interp, objv[2], GaimTclRefStatusType)) == NULL) | |
1512 return TCL_ERROR; | |
1513 Tcl_SetBooleanObj(result, gaim_status_type_is_exclusive(status_type)); | |
1514 break; | |
1515 case CMD_STATUS_TYPE_ID: | |
1516 if (objc != 3) { | |
1517 Tcl_WrongNumArgs(interp, 2, objv, "statustype"); | |
1518 return TCL_ERROR; | |
1519 } | |
1520 if ((status_type = gaim_tcl_ref_get(interp, objv[2], GaimTclRefStatusType)) == NULL) | |
1521 return TCL_ERROR; | |
1522 Tcl_SetStringObj(result, gaim_status_type_get_id(status_type), -1); | |
1523 break; | |
1524 case CMD_STATUS_TYPE_INDEPENDENT: | |
1525 if (objc != 3) { | |
1526 Tcl_WrongNumArgs(interp, 2, objv, "statustype"); | |
1527 return TCL_ERROR; | |
1528 } | |
1529 if ((status_type = gaim_tcl_ref_get(interp, objv[2], GaimTclRefStatusType)) == NULL) | |
1530 return TCL_ERROR; | |
1531 Tcl_SetBooleanObj(result, gaim_status_type_is_independent(status_type)); | |
1532 break; | |
1533 case CMD_STATUS_TYPE_NAME: | |
1534 if (objc != 3) { | |
1535 Tcl_WrongNumArgs(interp, 2, objv, "statustype"); | |
1536 return TCL_ERROR; | |
1537 } | |
1538 if ((status_type = gaim_tcl_ref_get(interp, objv[2], GaimTclRefStatusType)) == NULL) | |
1539 return TCL_ERROR; | |
1540 Tcl_SetStringObj(result, gaim_status_type_get_name(status_type), -1); | |
1541 break; | |
1542 case CMD_STATUS_TYPE_PRIMITIVE: | |
1543 if (objc != 3) { | |
1544 Tcl_WrongNumArgs(interp, 2, objv, "statustype"); | |
1545 return TCL_ERROR; | |
1546 } | |
1547 if ((status_type = gaim_tcl_ref_get(interp, objv[2], GaimTclRefStatusType)) == NULL) | |
1548 return TCL_ERROR; | |
1549 Tcl_SetStringObj(result, gaim_primitive_get_id_from_type(gaim_status_type_get_primitive(status_type)), -1); | |
1550 break; | |
1551 case CMD_STATUS_TYPE_PRIMARY_ATTR: | |
1552 if (objc != 3) { | |
1553 Tcl_WrongNumArgs(interp, 2, objv, "statustype"); | |
1554 return TCL_ERROR; | |
1555 } | |
1556 if ((status_type = gaim_tcl_ref_get(interp, objv[2], GaimTclRefStatusType)) == NULL) | |
1557 return TCL_ERROR; | |
1558 Tcl_SetStringObj(result, gaim_status_type_get_primary_attr(status_type), -1); | |
1559 break; | |
1560 case CMD_STATUS_TYPE_SAVEABLE: | |
1561 if (objc != 3) { | |
1562 Tcl_WrongNumArgs(interp, 2, objv, "statustype"); | |
1563 return TCL_ERROR; | |
1564 } | |
1565 if ((status_type = gaim_tcl_ref_get(interp, objv[2], GaimTclRefStatusType)) == NULL) | |
1566 return TCL_ERROR; | |
1567 Tcl_SetBooleanObj(result, gaim_status_type_is_saveable(status_type)); | |
1568 break; | |
1569 case CMD_STATUS_TYPE_USER_SETTABLE: | |
1570 if (objc != 3) { | |
1571 Tcl_WrongNumArgs(interp, 2, objv, "statustype"); | |
1572 return TCL_ERROR; | |
1573 } | |
1574 if ((status_type = gaim_tcl_ref_get(interp, objv[2], GaimTclRefStatusType)) == NULL) | |
1575 return TCL_ERROR; | |
1576 Tcl_SetBooleanObj(result, gaim_status_type_is_user_settable(status_type)); | |
1577 break; | |
1578 } | |
1579 | |
1580 return TCL_OK; | |
1581 } | |
1582 | |
1583 static gboolean unload_self(gpointer data) | |
1584 { | |
1585 GaimPlugin *plugin = data; | |
1586 gaim_plugin_unload(plugin); | |
1587 return FALSE; | |
1588 } | |
1589 | |
1590 int tcl_cmd_unload(ClientData unused, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) | |
1591 { | |
1592 GaimPlugin *plugin; | |
1593 if (objc != 1) { | |
1594 Tcl_WrongNumArgs(interp, 1, objv, ""); | |
1595 return TCL_ERROR; | |
1596 } | |
1597 | |
1598 if ((plugin = tcl_interp_get_plugin(interp)) == NULL) { | |
1599 /* This isn't exactly OK, but heh. What do you do? */ | |
1600 return TCL_OK; | |
1601 } | |
1602 /* We can't unload immediately, but we can unload at the first | |
1603 * known safe opportunity. */ | |
1604 g_idle_add(unload_self, (gpointer)plugin); | |
1605 | |
1606 return TCL_OK; | |
1607 } |