Mercurial > pidgin.yaz
annotate plugins/tcl/tcl_cmds.c @ 13897:eaaf73de9188
[gaim-migrate @ 16382]
I have added a sort of a taskbar, useful in showing the active windows.
I have also readjusted the blue color a little bit, since this is the
one I am using in a few places right now. And also getting rid of some
code-duplication.
committer: Tailor Script <tailor@pidgin.im>
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Sat, 01 Jul 2006 04:24:31 +0000 |
parents | d0ff520f87da |
children |
rev | line source |
---|---|
6694 | 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" | |
6700 | 31 #include "blist.h" |
6694 | 32 #include "debug.h" |
33 #include "prefs.h" | |
34 #include "core.h" | |
35 | |
36 #include "tcl_gaim.h" | |
37 | |
13810 | 38 static GaimAccount *tcl_validate_account(Tcl_Obj *obj, Tcl_Interp *interp); |
39 static GaimConversation *tcl_validate_conversation(Tcl_Obj *obj, Tcl_Interp *interp); | |
13815 | 40 static GaimConnection *tcl_validate_gc(Tcl_Obj *obj, Tcl_Interp *interp); |
6694 | 41 |
13810 | 42 static GaimAccount *tcl_validate_account(Tcl_Obj *obj, Tcl_Interp *interp) |
6694 | 43 { |
13810 | 44 GaimAccount *account; |
6694 | 45 GList *cur; |
13810 | 46 |
47 account = gaim_tcl_ref_get(interp, obj, GaimTclRefAccount); | |
48 | |
49 if (account == NULL) | |
50 return NULL; | |
51 | |
6694 | 52 for (cur = gaim_accounts_get_all(); cur != NULL; cur = g_list_next(cur)) { |
53 if (account == cur->data) | |
13810 | 54 return account; |
6694 | 55 } |
56 if (interp != NULL) | |
57 Tcl_SetStringObj(Tcl_GetObjResult(interp), "invalid account", -1); | |
13810 | 58 return NULL; |
6694 | 59 } |
60 | |
13810 | 61 static GaimConversation *tcl_validate_conversation(Tcl_Obj *obj, Tcl_Interp *interp) |
6694 | 62 { |
13810 | 63 GaimConversation *convo; |
6694 | 64 GList *cur; |
65 | |
13810 | 66 convo = gaim_tcl_ref_get(interp, obj, GaimTclRefConversation); |
67 | |
68 if (convo == NULL) | |
69 return NULL; | |
70 | |
6694 | 71 for (cur = gaim_get_conversations(); cur != NULL; cur = g_list_next(cur)) { |
72 if (convo == cur->data) | |
13810 | 73 return convo; |
6694 | 74 } |
75 if (interp != NULL) | |
13844 | 76 Tcl_SetStringObj(Tcl_GetObjResult(interp), "invalid conversation", -1); |
13810 | 77 return NULL; |
6694 | 78 } |
79 | |
13815 | 80 static GaimConnection *tcl_validate_gc(Tcl_Obj *obj, Tcl_Interp *interp) |
6694 | 81 { |
13815 | 82 GaimConnection *gc; |
6694 | 83 GList *cur; |
13815 | 84 |
85 gc = gaim_tcl_ref_get(interp, obj, GaimTclRefConnection); | |
86 | |
87 if (gc == NULL) | |
88 return NULL; | |
89 | |
6694 | 90 for (cur = gaim_connections_get_all(); cur != NULL; cur = g_list_next(cur)) { |
91 if (gc == cur->data) | |
13815 | 92 return gc; |
6694 | 93 } |
13815 | 94 return NULL; |
6694 | 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; | |
13826 | 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, | |
13810 | 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, | |
13826 | 109 CMD_ACCOUNT_PRESENCE, CMD_ACCOUNT_PROTOCOL, CMD_ACCOUNT_STATUS, |
110 CMD_ACCOUNT_STATUS_TYPE, CMD_ACCOUNT_STATUS_TYPES, | |
111 CMD_ACCOUNT_USERNAME } cmd; | |
10339 | 112 const char *listopts[] = { "-all", "-online", NULL }; |
6694 | 113 enum { CMD_ACCOUNTLIST_ALL, CMD_ACCOUNTLIST_ONLINE } listopt; |
8834 | 114 const char *alias; |
13810 | 115 const GList *cur; |
6694 | 116 GaimAccount *account; |
13826 | 117 GaimStatus *status; |
13810 | 118 GaimStatusType *status_type; |
13826 | 119 GaimValue *value; |
120 char *attr_id; | |
6694 | 121 int error; |
13826 | 122 int b, i; |
6694 | 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 } | |
13810 | 138 if ((account = tcl_validate_account(objv[2], interp)) == NULL) |
6694 | 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 } | |
13810 | 148 if ((account = tcl_validate_account(objv[2], interp)) == NULL) |
6694 | 149 return TCL_ERROR; |
10740 | 150 if (!gaim_account_is_connected(account)) |
151 gaim_account_connect(account); | |
13815 | 152 Tcl_SetObjResult(interp, |
153 gaim_tcl_ref_new(GaimTclRefConnection, | |
154 gaim_account_get_connection(account))); | |
6694 | 155 break; |
156 case CMD_ACCOUNT_CONNECTION: | |
157 if (objc != 3) { | |
158 Tcl_WrongNumArgs(interp, 2, objv, "account"); | |
159 return TCL_ERROR; | |
160 } | |
13810 | 161 |
162 if ((account = tcl_validate_account(objv[2], interp)) == NULL) | |
6694 | 163 return TCL_ERROR; |
13815 | 164 Tcl_SetObjResult(interp, |
165 gaim_tcl_ref_new(GaimTclRefConnection, | |
166 gaim_account_get_connection(account))); | |
6694 | 167 break; |
168 case CMD_ACCOUNT_DISCONNECT: | |
169 if (objc != 3) { | |
170 Tcl_WrongNumArgs(interp, 2, objv, "account"); | |
171 return TCL_ERROR; | |
172 } | |
13810 | 173 if ((account = tcl_validate_account(objv[2], interp)) == NULL) |
6694 | 174 return TCL_ERROR; |
175 gaim_account_disconnect(account); | |
176 break; | |
13810 | 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; | |
6694 | 194 case CMD_ACCOUNT_FIND: |
195 if (objc != 4) { | |
196 Tcl_WrongNumArgs(interp, 2, objv, "username protocol"); | |
197 return TCL_ERROR; | |
198 } | |
13815 | 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)); | |
6694 | 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 } | |
13810 | 216 if ((account = tcl_validate_account(objv[2], interp)) == NULL) |
6694 | 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; | |
13810 | 235 elem = gaim_tcl_ref_new(GaimTclRefAccount, account); |
6694 | 236 Tcl_ListObjAppendElement(interp, list, elem); |
237 } | |
238 Tcl_SetObjResult(interp, list); | |
239 break; | |
13821 | 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; | |
13824 | 247 Tcl_SetObjResult(interp, gaim_tcl_ref_new(GaimTclRefPresence, |
13821 | 248 gaim_account_get_presence(account))); |
249 break; | |
6694 | 250 case CMD_ACCOUNT_PROTOCOL: |
251 if (objc != 3) { | |
252 Tcl_WrongNumArgs(interp, 2, objv, "account"); | |
253 return TCL_ERROR; | |
254 } | |
13810 | 255 if ((account = tcl_validate_account(objv[2], interp)) == NULL) |
6694 | 256 return TCL_ERROR; |
257 Tcl_SetStringObj(result, (char *)gaim_account_get_protocol_id(account), -1); | |
258 break; | |
13826 | 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; | |
13810 | 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; | |
6694 | 363 case CMD_ACCOUNT_USERNAME: |
364 if (objc != 3) { | |
365 Tcl_WrongNumArgs(interp, 2, objv, "account"); | |
366 return TCL_ERROR; | |
367 } | |
13810 | 368 if ((account = tcl_validate_account(objv[2], interp)) == NULL) |
6694 | 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]); | |
13810 | 391 if ((account = tcl_validate_account(elems[2], interp)) == NULL) |
6694 | 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 { | |
6746 | 405 Tcl_Obj *list, *tclgroup, *tclgrouplist, *tclcontact, *tclcontactlist, *tclbud, **elems, *result; |
10339 | 406 const char *cmds[] = { "alias", "handle", "info", "list", NULL }; |
6694 | 407 enum { CMD_BUDDY_ALIAS, CMD_BUDDY_HANDLE, CMD_BUDDY_INFO, CMD_BUDDY_LIST } cmd; |
7100
abdc55ffadba
[gaim-migrate @ 7665]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
408 GaimBuddyList *blist; |
6746 | 409 GaimBlistNode *node, *gnode, *bnode; |
6694 | 410 GaimAccount *account; |
6746 | 411 GaimBuddy *bud; |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7100
diff
changeset
|
412 GaimChat *cnode; |
6694 | 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) | |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7100
diff
changeset
|
435 Tcl_SetStringObj(result, ((GaimChat *)node)->alias, -1); |
6694 | 436 else if (node->type == GAIM_BLIST_BUDDY_NODE) |
9620 | 437 Tcl_SetStringObj(result, (char *)gaim_buddy_get_alias((GaimBuddy *)node), -1); |
6694 | 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 } | |
13810 | 463 if ((account = tcl_validate_account(elems[2], interp)) == NULL) |
6694 | 464 return TCL_ERROR; |
465 serv_get_info(gaim_account_get_connection(account), Tcl_GetString(elems[1])); | |
466 } else { | |
13810 | 467 if ((account = tcl_validate_account(objv[2], interp)) == NULL) |
6694 | 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, | |
6700 | 488 Tcl_NewStringObj(((GaimGroup *)gnode)->name, -1)); |
6694 | 489 tclgrouplist = Tcl_NewListObj(0, NULL); |
490 for (node = gnode->child; node != NULL; node = node->next) { | |
491 switch (node->type) { | |
6746 | 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)); | |
13810 | 509 Tcl_ListObjAppendElement(interp, tclbud, gaim_tcl_ref_new(GaimTclRefAccount, bud->account)); |
6746 | 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); | |
6694 | 518 break; |
519 case GAIM_BLIST_CHAT_NODE: | |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7100
diff
changeset
|
520 cnode = (GaimChat *)node; |
6694 | 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)); | |
13810 | 526 Tcl_ListObjAppendElement(interp, tclbud, gaim_tcl_ref_new(GaimTclRefAccount, cnode->account)); |
6746 | 527 Tcl_ListObjAppendElement(interp, tclgrouplist, tclbud); |
6694 | 528 break; |
529 default: | |
6746 | 530 gaim_debug(GAIM_DEBUG_WARNING, "tcl", "Unexpected buddy type %d", node->type); |
6694 | 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 | |
13845
d0ff520f87da
[gaim-migrate @ 16301]
Etan Reisner <pidgin@unreliablesource.net>
parents:
13844
diff
changeset
|
544 int tcl_cmd_cmd(ClientData unused, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) |
d0ff520f87da
[gaim-migrate @ 16301]
Etan Reisner <pidgin@unreliablesource.net>
parents:
13844
diff
changeset
|
545 { |
d0ff520f87da
[gaim-migrate @ 16301]
Etan Reisner <pidgin@unreliablesource.net>
parents:
13844
diff
changeset
|
546 const char *cmds[] = { "register", "unregister", NULL }; |
d0ff520f87da
[gaim-migrate @ 16301]
Etan Reisner <pidgin@unreliablesource.net>
parents:
13844
diff
changeset
|
547 enum { CMD_CMD_REGISTER, CMD_CMD_UNREGISTER } cmd; |
d0ff520f87da
[gaim-migrate @ 16301]
Etan Reisner <pidgin@unreliablesource.net>
parents:
13844
diff
changeset
|
548 struct tcl_cmd_handler *handler; |
d0ff520f87da
[gaim-migrate @ 16301]
Etan Reisner <pidgin@unreliablesource.net>
parents:
13844
diff
changeset
|
549 Tcl_Obj *result = Tcl_GetObjResult(interp); |
d0ff520f87da
[gaim-migrate @ 16301]
Etan Reisner <pidgin@unreliablesource.net>
parents:
13844
diff
changeset
|
550 GaimCmdId id; |
d0ff520f87da
[gaim-migrate @ 16301]
Etan Reisner <pidgin@unreliablesource.net>
parents:
13844
diff
changeset
|
551 int error; |
d0ff520f87da
[gaim-migrate @ 16301]
Etan Reisner <pidgin@unreliablesource.net>
parents:
13844
diff
changeset
|
552 |
d0ff520f87da
[gaim-migrate @ 16301]
Etan Reisner <pidgin@unreliablesource.net>
parents:
13844
diff
changeset
|
553 if (objc < 2) { |
d0ff520f87da
[gaim-migrate @ 16301]
Etan Reisner <pidgin@unreliablesource.net>
parents:
13844
diff
changeset
|
554 Tcl_WrongNumArgs(interp, 1, objv, "subcommand ?args?"); |
d0ff520f87da
[gaim-migrate @ 16301]
Etan Reisner <pidgin@unreliablesource.net>
parents:
13844
diff
changeset
|
555 return TCL_ERROR; |
d0ff520f87da
[gaim-migrate @ 16301]
Etan Reisner <pidgin@unreliablesource.net>
parents:
13844
diff
changeset
|
556 } |
d0ff520f87da
[gaim-migrate @ 16301]
Etan Reisner <pidgin@unreliablesource.net>
parents:
13844
diff
changeset
|
557 |
d0ff520f87da
[gaim-migrate @ 16301]
Etan Reisner <pidgin@unreliablesource.net>
parents:
13844
diff
changeset
|
558 if ((error = Tcl_GetIndexFromObj(interp, objv[1], cmds, "subcommand", 0, (int *)&cmd)) != TCL_OK) |
d0ff520f87da
[gaim-migrate @ 16301]
Etan Reisner <pidgin@unreliablesource.net>
parents:
13844
diff
changeset
|
559 return error; |
d0ff520f87da
[gaim-migrate @ 16301]
Etan Reisner <pidgin@unreliablesource.net>
parents:
13844
diff
changeset
|
560 |
d0ff520f87da
[gaim-migrate @ 16301]
Etan Reisner <pidgin@unreliablesource.net>
parents:
13844
diff
changeset
|
561 switch (cmd) { |
d0ff520f87da
[gaim-migrate @ 16301]
Etan Reisner <pidgin@unreliablesource.net>
parents:
13844
diff
changeset
|
562 case CMD_CMD_REGISTER: |
d0ff520f87da
[gaim-migrate @ 16301]
Etan Reisner <pidgin@unreliablesource.net>
parents:
13844
diff
changeset
|
563 if (objc != 9) { |
d0ff520f87da
[gaim-migrate @ 16301]
Etan Reisner <pidgin@unreliablesource.net>
parents:
13844
diff
changeset
|
564 Tcl_WrongNumArgs(interp, 2, objv, "cmd arglist priority flags prpl_id proc helpstr"); |
d0ff520f87da
[gaim-migrate @ 16301]
Etan Reisner <pidgin@unreliablesource.net>
parents:
13844
diff
changeset
|
565 return TCL_ERROR; |
d0ff520f87da
[gaim-migrate @ 16301]
Etan Reisner <pidgin@unreliablesource.net>
parents:
13844
diff
changeset
|
566 } |
d0ff520f87da
[gaim-migrate @ 16301]
Etan Reisner <pidgin@unreliablesource.net>
parents:
13844
diff
changeset
|
567 handler = g_new0(struct tcl_cmd_handler, 1); |
d0ff520f87da
[gaim-migrate @ 16301]
Etan Reisner <pidgin@unreliablesource.net>
parents:
13844
diff
changeset
|
568 handler->cmd = objv[2]; |
d0ff520f87da
[gaim-migrate @ 16301]
Etan Reisner <pidgin@unreliablesource.net>
parents:
13844
diff
changeset
|
569 handler->args = Tcl_GetString(objv[3]); |
d0ff520f87da
[gaim-migrate @ 16301]
Etan Reisner <pidgin@unreliablesource.net>
parents:
13844
diff
changeset
|
570 handler->nargs = strlen(handler->args); |
d0ff520f87da
[gaim-migrate @ 16301]
Etan Reisner <pidgin@unreliablesource.net>
parents:
13844
diff
changeset
|
571 if ((error = Tcl_GetIntFromObj(interp, objv[4], |
d0ff520f87da
[gaim-migrate @ 16301]
Etan Reisner <pidgin@unreliablesource.net>
parents:
13844
diff
changeset
|
572 &handler->priority)) != TCL_OK) { |
d0ff520f87da
[gaim-migrate @ 16301]
Etan Reisner <pidgin@unreliablesource.net>
parents:
13844
diff
changeset
|
573 g_free(handler); |
d0ff520f87da
[gaim-migrate @ 16301]
Etan Reisner <pidgin@unreliablesource.net>
parents:
13844
diff
changeset
|
574 return error; |
d0ff520f87da
[gaim-migrate @ 16301]
Etan Reisner <pidgin@unreliablesource.net>
parents:
13844
diff
changeset
|
575 } |
d0ff520f87da
[gaim-migrate @ 16301]
Etan Reisner <pidgin@unreliablesource.net>
parents:
13844
diff
changeset
|
576 if ((error = Tcl_GetIntFromObj(interp, objv[5], |
d0ff520f87da
[gaim-migrate @ 16301]
Etan Reisner <pidgin@unreliablesource.net>
parents:
13844
diff
changeset
|
577 &handler->flags)) != TCL_OK) { |
d0ff520f87da
[gaim-migrate @ 16301]
Etan Reisner <pidgin@unreliablesource.net>
parents:
13844
diff
changeset
|
578 g_free(handler); |
d0ff520f87da
[gaim-migrate @ 16301]
Etan Reisner <pidgin@unreliablesource.net>
parents:
13844
diff
changeset
|
579 return error; |
d0ff520f87da
[gaim-migrate @ 16301]
Etan Reisner <pidgin@unreliablesource.net>
parents:
13844
diff
changeset
|
580 } |
d0ff520f87da
[gaim-migrate @ 16301]
Etan Reisner <pidgin@unreliablesource.net>
parents:
13844
diff
changeset
|
581 handler->prpl_id = Tcl_GetString(objv[6]); |
d0ff520f87da
[gaim-migrate @ 16301]
Etan Reisner <pidgin@unreliablesource.net>
parents:
13844
diff
changeset
|
582 handler->proc = objv[7]; |
d0ff520f87da
[gaim-migrate @ 16301]
Etan Reisner <pidgin@unreliablesource.net>
parents:
13844
diff
changeset
|
583 handler->helpstr = Tcl_GetString(objv[8]); |
d0ff520f87da
[gaim-migrate @ 16301]
Etan Reisner <pidgin@unreliablesource.net>
parents:
13844
diff
changeset
|
584 handler->interp = interp; |
d0ff520f87da
[gaim-migrate @ 16301]
Etan Reisner <pidgin@unreliablesource.net>
parents:
13844
diff
changeset
|
585 if ((id = tcl_cmd_register(handler)) == 0) { |
d0ff520f87da
[gaim-migrate @ 16301]
Etan Reisner <pidgin@unreliablesource.net>
parents:
13844
diff
changeset
|
586 tcl_cmd_handler_free(handler); |
d0ff520f87da
[gaim-migrate @ 16301]
Etan Reisner <pidgin@unreliablesource.net>
parents:
13844
diff
changeset
|
587 Tcl_SetIntObj(result, 0); |
d0ff520f87da
[gaim-migrate @ 16301]
Etan Reisner <pidgin@unreliablesource.net>
parents:
13844
diff
changeset
|
588 } else { |
d0ff520f87da
[gaim-migrate @ 16301]
Etan Reisner <pidgin@unreliablesource.net>
parents:
13844
diff
changeset
|
589 handler->id = id; |
d0ff520f87da
[gaim-migrate @ 16301]
Etan Reisner <pidgin@unreliablesource.net>
parents:
13844
diff
changeset
|
590 Tcl_SetIntObj(result, id); |
d0ff520f87da
[gaim-migrate @ 16301]
Etan Reisner <pidgin@unreliablesource.net>
parents:
13844
diff
changeset
|
591 } |
d0ff520f87da
[gaim-migrate @ 16301]
Etan Reisner <pidgin@unreliablesource.net>
parents:
13844
diff
changeset
|
592 break; |
d0ff520f87da
[gaim-migrate @ 16301]
Etan Reisner <pidgin@unreliablesource.net>
parents:
13844
diff
changeset
|
593 case CMD_CMD_UNREGISTER: |
d0ff520f87da
[gaim-migrate @ 16301]
Etan Reisner <pidgin@unreliablesource.net>
parents:
13844
diff
changeset
|
594 if (objc != 3) { |
d0ff520f87da
[gaim-migrate @ 16301]
Etan Reisner <pidgin@unreliablesource.net>
parents:
13844
diff
changeset
|
595 Tcl_WrongNumArgs(interp, 2, objv, "id"); |
d0ff520f87da
[gaim-migrate @ 16301]
Etan Reisner <pidgin@unreliablesource.net>
parents:
13844
diff
changeset
|
596 return TCL_ERROR; |
d0ff520f87da
[gaim-migrate @ 16301]
Etan Reisner <pidgin@unreliablesource.net>
parents:
13844
diff
changeset
|
597 } |
d0ff520f87da
[gaim-migrate @ 16301]
Etan Reisner <pidgin@unreliablesource.net>
parents:
13844
diff
changeset
|
598 if ((error = Tcl_GetIntFromObj(interp, objv[2], |
d0ff520f87da
[gaim-migrate @ 16301]
Etan Reisner <pidgin@unreliablesource.net>
parents:
13844
diff
changeset
|
599 (int *)&id)) != TCL_OK) |
d0ff520f87da
[gaim-migrate @ 16301]
Etan Reisner <pidgin@unreliablesource.net>
parents:
13844
diff
changeset
|
600 return error; |
d0ff520f87da
[gaim-migrate @ 16301]
Etan Reisner <pidgin@unreliablesource.net>
parents:
13844
diff
changeset
|
601 tcl_cmd_unregister(id, interp); |
d0ff520f87da
[gaim-migrate @ 16301]
Etan Reisner <pidgin@unreliablesource.net>
parents:
13844
diff
changeset
|
602 break; |
d0ff520f87da
[gaim-migrate @ 16301]
Etan Reisner <pidgin@unreliablesource.net>
parents:
13844
diff
changeset
|
603 } |
d0ff520f87da
[gaim-migrate @ 16301]
Etan Reisner <pidgin@unreliablesource.net>
parents:
13844
diff
changeset
|
604 |
d0ff520f87da
[gaim-migrate @ 16301]
Etan Reisner <pidgin@unreliablesource.net>
parents:
13844
diff
changeset
|
605 return TCL_OK; |
d0ff520f87da
[gaim-migrate @ 16301]
Etan Reisner <pidgin@unreliablesource.net>
parents:
13844
diff
changeset
|
606 } |
d0ff520f87da
[gaim-migrate @ 16301]
Etan Reisner <pidgin@unreliablesource.net>
parents:
13844
diff
changeset
|
607 |
6694 | 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; | |
10339 | 611 const char *cmds[] = { "account", "displayname", "handle", "list", NULL }; |
7713 | 612 enum { CMD_CONN_ACCOUNT, CMD_CONN_DISPLAYNAME, CMD_CONN_HANDLE, CMD_CONN_LIST } cmd; |
6694 | 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) { | |
6864 | 628 Tcl_WrongNumArgs(interp, 2, objv, "gc"); |
6694 | 629 return TCL_ERROR; |
630 } | |
13815 | 631 if ((gc = tcl_validate_gc(objv[2], interp)) == NULL) |
6694 | 632 return TCL_ERROR; |
13815 | 633 Tcl_SetObjResult(interp, |
634 gaim_tcl_ref_new(GaimTclRefAccount, | |
635 gaim_connection_get_account(gc))); | |
6694 | 636 break; |
7713 | 637 case CMD_CONN_DISPLAYNAME: |
638 if (objc != 3) { | |
639 Tcl_WrongNumArgs(interp, 2, objv, "gc"); | |
640 return TCL_ERROR; | |
641 } | |
13815 | 642 if ((gc = tcl_validate_gc(objv[2], interp)) == NULL) |
7713 | 643 return TCL_ERROR; |
644 Tcl_SetStringObj(result, (char *)gaim_connection_get_display_name(gc), -1); | |
645 break; | |
6694 | 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)) { | |
13815 | 660 elem = gaim_tcl_ref_new(GaimTclRefConnection, cur->data); |
6694 | 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); | |
10339 | 673 const char *cmds[] = { "find", "handle", "list", "new", "write", NULL }; |
6694 | 674 enum { CMD_CONV_FIND, CMD_CONV_HANDLE, CMD_CONV_LIST, CMD_CONV_NEW, CMD_CONV_WRITE } cmd; |
10339 | 675 const char *styles[] = { "send", "recv", "system", NULL }; |
6694 | 676 enum { CMD_CONV_WRITE_SEND, CMD_CONV_WRITE_RECV, CMD_CONV_WRITE_SYSTEM } style; |
10339 | 677 const char *newopts[] = { "-chat", "-im" }; |
6694 | 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; | |
7156 | 684 int error, argsused, flags = 0; |
6694 | 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: | |
10829 | 696 if (objc != 4) { |
697 Tcl_WrongNumArgs(interp, 2, objv, "account name"); | |
6694 | 698 return TCL_ERROR; |
699 } | |
700 account = NULL; | |
13810 | 701 if ((account = tcl_validate_account(objv[2], interp)) == NULL) |
10829 | 702 return TCL_ERROR; |
11338 | 703 convo = gaim_find_conversation_with_account(GAIM_CONV_TYPE_ANY, |
10829 | 704 Tcl_GetString(objv[3]), |
705 account); | |
13815 | 706 Tcl_SetObjResult(interp, gaim_tcl_ref_new(GaimTclRefConversation, convo)); |
6694 | 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)) { | |
13815 | 718 elem = gaim_tcl_ref_new(GaimTclRefConversation, cur->data); |
6694 | 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; | |
11338 | 729 type = GAIM_CONV_TYPE_IM; |
6694 | 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: | |
11338 | 739 type = GAIM_CONV_TYPE_CHAT; |
6694 | 740 break; |
741 case CMD_CONV_NEW_IM: | |
11338 | 742 type = GAIM_CONV_TYPE_IM; |
6694 | 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 } | |
13810 | 753 if ((account = tcl_validate_account(objv[argsused++], interp)) == NULL) |
6694 | 754 return TCL_ERROR; |
755 convo = gaim_conversation_new(type, account, Tcl_GetString(objv[argsused])); | |
13815 | 756 Tcl_SetObjResult(interp, gaim_tcl_ref_new(GaimTclRefConversation, convo)); |
6694 | 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 } | |
13810 | 763 if ((convo = tcl_validate_conversation(objv[2], interp)) == NULL) |
764 return TCL_ERROR; | |
6694 | 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 } | |
11338 | 781 if (gaim_conversation_get_type(convo) == GAIM_CONV_TYPE_CHAT) |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7100
diff
changeset
|
782 gaim_conv_chat_write(GAIM_CONV_CHAT(convo), from, what, flags, time(NULL)); |
6694 | 783 else |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7100
diff
changeset
|
784 gaim_conv_im_write(GAIM_CONV_IM(convo), from, what, flags, time(NULL)); |
6694 | 785 break; |
786 } | |
787 | |
788 return TCL_OK; | |
789 } | |
790 | |
791 int tcl_cmd_core(ClientData unused, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) | |
792 { | |
793 Tcl_Obj *result = Tcl_GetObjResult(interp); | |
10339 | 794 const char *cmds[] = { "handle", "quit", NULL }; |
6694 | 795 enum { CMD_CORE_HANDLE, CMD_CORE_QUIT } cmd; |
796 int error; | |
797 | |
798 if (objc < 2) { | |
799 Tcl_WrongNumArgs(interp, 1, objv, "subcommand ?args?"); | |
800 return TCL_ERROR; | |
801 } | |
802 | |
803 if ((error = Tcl_GetIndexFromObj(interp, objv[1], cmds, "subcommand", 0, (int *)&cmd)) != TCL_OK) | |
804 return error; | |
805 | |
806 switch (cmd) { | |
807 case CMD_CORE_HANDLE: | |
808 if (objc != 2) { | |
809 Tcl_WrongNumArgs(interp, 2, objv, ""); | |
810 return TCL_ERROR; | |
811 } | |
812 Tcl_SetIntObj(result, (int)gaim_get_core()); | |
813 break; | |
814 case CMD_CORE_QUIT: | |
815 if (objc != 2) { | |
816 Tcl_WrongNumArgs(interp, 2, objv, ""); | |
817 return TCL_ERROR; | |
818 } | |
819 gaim_core_quit(); | |
820 break; | |
821 } | |
822 | |
823 return TCL_OK; | |
824 } | |
825 | |
826 int tcl_cmd_debug(ClientData unused, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) | |
827 { | |
828 char *category, *message; | |
829 int lev; | |
10339 | 830 const char *levels[] = { "-misc", "-info", "-warning", "-error", NULL }; |
6694 | 831 GaimDebugLevel levelind[] = { GAIM_DEBUG_MISC, GAIM_DEBUG_INFO, GAIM_DEBUG_WARNING, GAIM_DEBUG_ERROR }; |
832 int error; | |
833 | |
834 if (objc != 4) { | |
835 Tcl_WrongNumArgs(interp, 1, objv, "level category message"); | |
836 return TCL_ERROR; | |
837 } | |
838 | |
839 error = Tcl_GetIndexFromObj(interp, objv[1], levels, "debug level", 0, &lev); | |
840 if (error != TCL_OK) | |
841 return error; | |
842 | |
843 category = Tcl_GetString(objv[2]); | |
844 message = Tcl_GetString(objv[3]); | |
845 | |
846 gaim_debug(levelind[lev], category, "%s\n", message); | |
847 | |
848 return TCL_OK; | |
849 } | |
850 | |
851 int tcl_cmd_notify(ClientData unused, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) | |
852 { | |
853 int error, type; | |
10339 | 854 const char *opts[] = { "-error", "-warning", "-info", NULL }; |
6694 | 855 GaimNotifyMsgType optind[] = { GAIM_NOTIFY_MSG_ERROR, GAIM_NOTIFY_MSG_WARNING, GAIM_NOTIFY_MSG_INFO }; |
856 char *title, *msg1, *msg2; | |
857 | |
858 if (objc < 4 || objc > 5) { | |
859 Tcl_WrongNumArgs(interp, 1, objv, "?type? title primary secondary"); | |
860 return TCL_ERROR; | |
861 } | |
862 | |
863 if (objc == 4) { | |
13423 | 864 type = 1; /* Default to warning */ |
6694 | 865 title = Tcl_GetString(objv[1]); |
866 msg1 = Tcl_GetString(objv[2]); | |
867 msg2 = Tcl_GetString(objv[3]); | |
868 } else { | |
869 error = Tcl_GetIndexFromObj(interp, objv[1], opts, "message type", 0, &type); | |
870 if (error != TCL_OK) | |
871 return error; | |
872 title = Tcl_GetString(objv[2]); | |
873 msg1 = Tcl_GetString(objv[3]); | |
874 msg2 = Tcl_GetString(objv[4]); | |
875 } | |
876 | |
877 gaim_notify_message(_tcl_plugin, optind[type], title, msg1, msg2, NULL, NULL); | |
878 | |
879 return TCL_OK; | |
880 } | |
881 | |
882 int tcl_cmd_prefs(ClientData unused, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) | |
883 { | |
884 Tcl_Obj *result, *list, *elem, **elems; | |
10339 | 885 const char *cmds[] = { "get", "set", "type", NULL }; |
6694 | 886 enum { CMD_PREFS_GET, CMD_PREFS_SET, CMD_PREFS_TYPE } cmd; |
887 /* char *types[] = { "none", "boolean", "int", "string", "stringlist", NULL }; */ | |
888 /* enum { TCL_PREFS_NONE, TCL_PREFS_BOOL, TCL_PREFS_INT, TCL_PREFS_STRING, TCL_PREFS_STRINGLIST } type; */ | |
889 GaimPrefType preftype; | |
890 GList *cur; | |
891 int error, intval, nelem, i; | |
892 | |
893 if (objc < 2) { | |
894 Tcl_WrongNumArgs(interp, 1, objv, "subcommand ?args?"); | |
895 return TCL_ERROR; | |
896 } | |
897 | |
898 if ((error = Tcl_GetIndexFromObj(interp, objv[1], cmds, "subcommand", 0, (int *)&cmd)) != TCL_OK) | |
899 return error; | |
900 | |
901 result = Tcl_GetObjResult(interp); | |
902 switch (cmd) { | |
903 case CMD_PREFS_GET: | |
904 if (objc != 3) { | |
905 Tcl_WrongNumArgs(interp, 1, objv, "path"); | |
906 return TCL_ERROR; | |
907 } | |
908 preftype = gaim_prefs_get_type(Tcl_GetString(objv[2])); | |
909 switch (preftype) { | |
910 case GAIM_PREF_NONE: | |
911 Tcl_SetStringObj(result, "pref type none", -1); | |
912 return TCL_ERROR; | |
913 break; | |
914 case GAIM_PREF_BOOLEAN: | |
915 Tcl_SetBooleanObj(result, gaim_prefs_get_bool(Tcl_GetString(objv[2]))); | |
916 break; | |
917 case GAIM_PREF_INT: | |
918 Tcl_SetIntObj(result, gaim_prefs_get_int(Tcl_GetString(objv[2]))); | |
919 break; | |
920 case GAIM_PREF_STRING: | |
921 Tcl_SetStringObj(result, (char *)gaim_prefs_get_string(Tcl_GetString(objv[2])), -1); | |
922 break; | |
923 case GAIM_PREF_STRING_LIST: | |
924 cur = gaim_prefs_get_string_list(Tcl_GetString(objv[2])); | |
925 list = Tcl_NewListObj(0, NULL); | |
926 while (cur != NULL) { | |
927 elem = Tcl_NewStringObj((char *)cur->data, -1); | |
928 Tcl_ListObjAppendElement(interp, list, elem); | |
929 cur = g_list_next(cur); | |
930 } | |
931 Tcl_SetObjResult(interp, list); | |
932 break; | |
933 default: | |
934 gaim_debug(GAIM_DEBUG_ERROR, "tcl", "tcl does not know about pref type %d\n", preftype); | |
935 Tcl_SetStringObj(result, "unknown pref type", -1); | |
936 return TCL_ERROR; | |
937 } | |
938 break; | |
939 case CMD_PREFS_SET: | |
940 if (objc != 4) { | |
941 Tcl_WrongNumArgs(interp, 1, objv, "path value"); | |
942 return TCL_ERROR; | |
943 } | |
944 preftype = gaim_prefs_get_type(Tcl_GetString(objv[2])); | |
945 switch (preftype) { | |
946 case GAIM_PREF_NONE: | |
947 Tcl_SetStringObj(result, "bad path or pref type none", -1); | |
948 return TCL_ERROR; | |
949 break; | |
950 case GAIM_PREF_BOOLEAN: | |
951 if ((error = Tcl_GetBooleanFromObj(interp, objv[3], &intval)) != TCL_OK) | |
952 return error; | |
953 gaim_prefs_set_bool(Tcl_GetString(objv[2]), intval); | |
954 break; | |
955 case GAIM_PREF_INT: | |
956 if ((error = Tcl_GetIntFromObj(interp, objv[3], &intval)) != TCL_OK) | |
957 return error; | |
958 gaim_prefs_set_int(Tcl_GetString(objv[2]), intval); | |
959 break; | |
960 case GAIM_PREF_STRING: | |
961 gaim_prefs_set_string(Tcl_GetString(objv[2]), Tcl_GetString(objv[3])); | |
962 break; | |
963 case GAIM_PREF_STRING_LIST: | |
964 if ((error = Tcl_ListObjGetElements(interp, objv[3], &nelem, &elems)) != TCL_OK) | |
965 return error; | |
966 cur = NULL; | |
967 for (i = 0; i < nelem; i++) { | |
968 cur = g_list_append(cur, (gpointer)Tcl_GetString(elems[i])); | |
969 } | |
970 gaim_prefs_set_string_list(Tcl_GetString(objv[2]), cur); | |
971 g_list_free(cur); | |
972 break; | |
973 default: | |
974 gaim_debug(GAIM_DEBUG_ERROR, "tcl", "tcl does not know about pref type %d\n", preftype); | |
975 return TCL_ERROR; | |
976 } | |
977 break; | |
978 case CMD_PREFS_TYPE: | |
979 if (objc != 3) { | |
980 Tcl_WrongNumArgs(interp, 1, objv, "path"); | |
981 return TCL_ERROR; | |
982 } | |
983 preftype = gaim_prefs_get_type(Tcl_GetString(objv[2])); | |
984 switch (preftype) { | |
985 case GAIM_PREF_NONE: | |
986 Tcl_SetStringObj(result, "none", -1); | |
987 break; | |
988 case GAIM_PREF_BOOLEAN: | |
989 Tcl_SetStringObj(result, "boolean", -1); | |
990 break; | |
991 case GAIM_PREF_INT: | |
992 Tcl_SetStringObj(result, "int", -1); | |
993 break; | |
994 case GAIM_PREF_STRING: | |
995 Tcl_SetStringObj(result, "string", -1); | |
996 break; | |
997 case GAIM_PREF_STRING_LIST: | |
998 Tcl_SetStringObj(result, "stringlist", -1); | |
999 break; | |
1000 default: | |
1001 gaim_debug(GAIM_DEBUG_ERROR, "tcl", "tcl does not know about pref type %d\n", preftype); | |
1002 Tcl_SetStringObj(result, "unknown", -1); | |
1003 } | |
1004 break; | |
1005 } | |
1006 | |
1007 return TCL_OK; | |
1008 } | |
1009 | |
13821 | 1010 int tcl_cmd_presence(ClientData unused, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) |
1011 { | |
1012 const char *cmds[] = { "account", "active_status", "available", | |
1013 "chat_user", "context", "conversation", "idle", | |
1014 "login", "online", "status", "statuses", NULL }; | |
1015 enum { CMD_PRESENCE_ACCOUNT, CMD_PRESENCE_ACTIVE_STATUS, | |
1016 CMD_PRESENCE_AVAILABLE, CMD_PRESENCE_CHAT_USER, | |
1017 CMD_PRESENCE_CONTEXT, CMD_PRESENCE_CONVERSATION, | |
1018 CMD_PRESENCE_IDLE, CMD_PRESENCE_LOGIN, CMD_PRESENCE_ONLINE, | |
1019 CMD_PRESENCE_STATUS, CMD_PRESENCE_STATUSES } cmd; | |
1020 Tcl_Obj *result = Tcl_GetObjResult(interp); | |
1021 Tcl_Obj *list, *elem; | |
1022 GaimPresence *presence; | |
1023 const GList *cur; | |
1024 int error, idle, idle_time, login_time; | |
1025 | |
1026 if (objc < 2) { | |
1027 Tcl_WrongNumArgs(interp, 1, objv, "subcommand ?args?"); | |
1028 return TCL_ERROR; | |
1029 } | |
1030 | |
1031 if ((error = Tcl_GetIndexFromObj(interp, objv[1], cmds, "subcommand", 0, (int *)&cmd)) != TCL_OK) | |
1032 return error; | |
1033 | |
1034 switch (cmd) { | |
1035 case CMD_PRESENCE_ACCOUNT: | |
1036 if (objc != 3) { | |
1037 Tcl_WrongNumArgs(interp, 2, objv, "presence"); | |
1038 return TCL_ERROR; | |
1039 } | |
1040 if ((presence = gaim_tcl_ref_get(interp, objv[2], GaimTclRefPresence)) == NULL) | |
1041 return TCL_ERROR; | |
1042 Tcl_SetObjResult(interp, gaim_tcl_ref_new(GaimTclRefAccount, | |
1043 gaim_presence_get_account(presence))); | |
1044 break; | |
1045 case CMD_PRESENCE_ACTIVE_STATUS: | |
1046 if (objc != 3 && objc != 4 && objc != 5) { | |
1047 Tcl_WrongNumArgs(interp, 2, objv, "presence [?status_id? | ?-primitive primitive?]"); | |
1048 return TCL_ERROR; | |
1049 } | |
1050 if ((presence = gaim_tcl_ref_get(interp, objv[2], GaimTclRefPresence)) == NULL) | |
1051 return TCL_ERROR; | |
1052 if (objc == 3) { | |
1053 Tcl_SetObjResult(interp, | |
1054 gaim_tcl_ref_new(GaimTclRefStatus, | |
1055 gaim_presence_get_active_status(presence))); | |
1056 } else if (objc == 4) { | |
1057 Tcl_SetBooleanObj(result, | |
1058 gaim_presence_is_status_active(presence, | |
1059 Tcl_GetString(objv[3]))); | |
1060 } else { | |
1061 GaimStatusPrimitive primitive; | |
1062 if (strcmp(Tcl_GetString(objv[3]), "-primitive")) { | |
1063 Tcl_SetStringObj(result, "bad option \"", -1); | |
1064 Tcl_AppendObjToObj(result, objv[3]); | |
1065 Tcl_AppendToObj(result, | |
1066 "\": should be -primitive", -1); | |
1067 return TCL_ERROR; | |
1068 } | |
1069 primitive = gaim_primitive_get_type_from_id(Tcl_GetString(objv[4])); | |
1070 if (primitive == GAIM_STATUS_UNSET) { | |
1071 Tcl_SetStringObj(result, "invalid primitive ", -1); | |
1072 Tcl_AppendObjToObj(result, objv[4]); | |
1073 return TCL_ERROR; | |
1074 } | |
1075 Tcl_SetBooleanObj(result, gaim_presence_is_status_primitive_active(presence, primitive)); | |
1076 break; | |
1077 } | |
1078 break; | |
1079 case CMD_PRESENCE_AVAILABLE: | |
1080 if (objc != 3) { | |
1081 Tcl_WrongNumArgs(interp, 2, objv, "presence"); | |
1082 return TCL_ERROR; | |
1083 } | |
1084 if ((presence = gaim_tcl_ref_get(interp, objv[2], GaimTclRefPresence)) == NULL) | |
1085 return TCL_ERROR; | |
1086 Tcl_SetBooleanObj(result, gaim_presence_is_available(presence)); | |
1087 break; | |
1088 case CMD_PRESENCE_CHAT_USER: | |
1089 if (objc != 3) { | |
1090 Tcl_WrongNumArgs(interp, 2, objv, "presence"); | |
1091 return TCL_ERROR; | |
1092 } | |
1093 if ((presence = gaim_tcl_ref_get(interp, objv[2], GaimTclRefPresence)) == NULL) | |
1094 return TCL_ERROR; | |
1095 Tcl_SetStringObj(result, gaim_presence_get_chat_user(presence), -1); | |
1096 break; | |
1097 case CMD_PRESENCE_CONTEXT: | |
1098 if (objc != 3) { | |
1099 Tcl_WrongNumArgs(interp, 2, objv, "presence"); | |
1100 return TCL_ERROR; | |
1101 } | |
1102 if ((presence = gaim_tcl_ref_get(interp, objv[2], GaimTclRefPresence)) == NULL) | |
1103 return TCL_ERROR; | |
1104 switch (gaim_presence_get_context(presence)) { | |
1105 case GAIM_PRESENCE_CONTEXT_UNSET: | |
1106 Tcl_SetStringObj(result, "unset", -1); | |
1107 break; | |
1108 case GAIM_PRESENCE_CONTEXT_ACCOUNT: | |
1109 Tcl_SetStringObj(result, "account", -1); | |
1110 break; | |
1111 case GAIM_PRESENCE_CONTEXT_CONV: | |
1112 Tcl_SetStringObj(result, "conversation", -1); | |
1113 break; | |
1114 case GAIM_PRESENCE_CONTEXT_BUDDY: | |
1115 Tcl_SetStringObj(result, "buddy", -1); | |
1116 break; | |
1117 } | |
1118 break; | |
1119 case CMD_PRESENCE_CONVERSATION: | |
1120 if (objc != 3) { | |
1121 Tcl_WrongNumArgs(interp, 2, objv, "presence"); | |
1122 return TCL_ERROR; | |
1123 } | |
1124 if ((presence = gaim_tcl_ref_get(interp, objv[2], GaimTclRefPresence)) == NULL) | |
1125 return TCL_ERROR; | |
1126 Tcl_SetObjResult(interp, gaim_tcl_ref_new(GaimTclRefConversation, | |
1127 gaim_presence_get_conversation(presence))); | |
1128 break; | |
1129 case CMD_PRESENCE_IDLE: | |
1130 if (objc < 3 || objc > 5) { | |
1131 Tcl_WrongNumArgs(interp, 2, objv, "presence ?idle? ?time?"); | |
1132 return TCL_ERROR; | |
1133 } | |
1134 if ((presence = gaim_tcl_ref_get(interp, objv[2], GaimTclRefPresence)) == NULL) | |
1135 return TCL_ERROR; | |
1136 if (objc == 3) { | |
1137 if (gaim_presence_is_idle(presence)) { | |
1138 idle_time = gaim_presence_get_idle_time (presence); | |
1139 Tcl_SetIntObj(result, idle_time); | |
1140 } else { | |
1141 result = Tcl_NewListObj(0, NULL); | |
1142 Tcl_SetObjResult(interp, result); | |
1143 } | |
1144 break; | |
1145 } | |
1146 if ((error = Tcl_GetBooleanFromObj(interp, objv[3], &idle)) != TCL_OK) | |
1147 return TCL_ERROR; | |
1148 if (objc == 4) { | |
1149 gaim_presence_set_idle(presence, idle, time(NULL)); | |
1150 } else if (objc == 5) { | |
1151 if ((error = Tcl_GetIntFromObj(interp, | |
1152 objv[4], | |
1153 &idle_time)) != TCL_OK) | |
1154 return TCL_ERROR; | |
1155 gaim_presence_set_idle(presence, idle, idle_time); | |
1156 } | |
1157 break; | |
1158 case CMD_PRESENCE_LOGIN: | |
1159 if (objc != 3 && objc != 4) { | |
1160 Tcl_WrongNumArgs(interp, 2, objv, "presence ?time?"); | |
1161 return TCL_ERROR; | |
1162 } | |
1163 if ((presence = gaim_tcl_ref_get(interp, objv[2], GaimTclRefPresence)) == NULL) | |
1164 return TCL_ERROR; | |
1165 if (objc == 3) { | |
1166 Tcl_SetIntObj(result, gaim_presence_get_login_time(presence)); | |
1167 } else { | |
1168 if ((error == Tcl_GetIntFromObj(interp, | |
1169 objv[3], | |
1170 &login_time)) != TCL_OK) | |
1171 return TCL_ERROR; | |
1172 gaim_presence_set_login_time(presence, login_time); | |
1173 } | |
1174 break; | |
1175 case CMD_PRESENCE_ONLINE: | |
1176 if (objc != 3) { | |
1177 Tcl_WrongNumArgs(interp, 2, objv, "presence"); | |
1178 return TCL_ERROR; | |
1179 } | |
1180 if ((presence = gaim_tcl_ref_get(interp, objv[2], GaimTclRefPresence)) == NULL) | |
1181 return TCL_ERROR; | |
1182 Tcl_SetBooleanObj(result, gaim_presence_is_online(presence)); | |
1183 break; | |
1184 case CMD_PRESENCE_STATUS: | |
1185 if (objc != 4) { | |
1186 Tcl_WrongNumArgs(interp, 2, objv, "presence status_id"); | |
1187 return TCL_ERROR; | |
1188 } | |
1189 if ((presence = gaim_tcl_ref_get(interp, objv[2], GaimTclRefPresence)) == NULL) | |
1190 return TCL_ERROR; | |
1191 Tcl_SetObjResult(interp, | |
1192 gaim_tcl_ref_new(GaimTclRefStatus, | |
1193 gaim_presence_get_status(presence, | |
1194 Tcl_GetString(objv[3])))); | |
1195 break; | |
1196 case CMD_PRESENCE_STATUSES: | |
1197 if (objc != 3) { | |
1198 Tcl_WrongNumArgs(interp, 2, objv, "presence"); | |
1199 return TCL_ERROR; | |
1200 } | |
1201 if ((presence = gaim_tcl_ref_get(interp, objv[2], GaimTclRefPresence)) == NULL) | |
1202 return TCL_ERROR; | |
1203 list = Tcl_NewListObj(0, NULL); | |
1204 for (cur = gaim_presence_get_statuses(presence); cur != NULL; | |
1205 cur = g_list_next(cur)) { | |
1206 elem = gaim_tcl_ref_new(GaimTclRefStatus, cur->data); | |
1207 Tcl_ListObjAppendElement(interp, list, elem); | |
1208 } | |
1209 Tcl_SetObjResult(interp, list); | |
1210 break; | |
1211 } | |
1212 | |
1213 return TCL_OK; | |
1214 } | |
1215 | |
6694 | 1216 int tcl_cmd_send_im(ClientData unused, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) |
1217 { | |
1218 GaimConnection *gc; | |
1219 char *who, *text; | |
1220 | |
1221 if (objc != 4) { | |
1222 Tcl_WrongNumArgs(interp, 1, objv, "gc who text"); | |
1223 return TCL_ERROR; | |
1224 } | |
1225 | |
13815 | 1226 if ((gc = tcl_validate_gc(objv[1], interp)) == NULL) |
6694 | 1227 return TCL_ERROR; |
1228 | |
1229 who = Tcl_GetString(objv[2]); | |
1230 text = Tcl_GetString(objv[3]); | |
1231 | |
6982 | 1232 serv_send_im(gc, who, text, 0); |
6694 | 1233 |
1234 return TCL_OK; | |
1235 } | |
1236 | |
1237 int tcl_cmd_signal(ClientData unused, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) | |
1238 { | |
10339 | 1239 const char *cmds[] = { "connect", "disconnect", NULL }; |
6694 | 1240 enum { CMD_SIGNAL_CONNECT, CMD_SIGNAL_DISCONNECT } cmd; |
1241 struct tcl_signal_handler *handler; | |
10597 | 1242 Tcl_Obj *result = Tcl_GetObjResult(interp); |
6694 | 1243 void *instance; |
10597 | 1244 int error; |
6694 | 1245 |
1246 if (objc < 2) { | |
1247 Tcl_WrongNumArgs(interp, 1, objv, "subcommand ?args?"); | |
1248 return TCL_ERROR; | |
1249 } | |
1250 | |
1251 if ((error = Tcl_GetIndexFromObj(interp, objv[1], cmds, "subcommand", 0, (int *)&cmd)) != TCL_OK) | |
1252 return error; | |
1253 | |
1254 switch (cmd) { | |
1255 case CMD_SIGNAL_CONNECT: | |
1256 if (objc != 6) { | |
1257 Tcl_WrongNumArgs(interp, 2, objv, "instance signal args proc"); | |
1258 return TCL_ERROR; | |
1259 } | |
1260 handler = g_new0(struct tcl_signal_handler, 1); | |
1261 if ((error = Tcl_GetIntFromObj(interp, objv[2], (int *)&handler->instance)) != TCL_OK) { | |
1262 g_free(handler); | |
1263 return error; | |
1264 } | |
10597 | 1265 handler->signal = objv[3]; |
13810 | 1266 Tcl_IncrRefCount(handler->signal); |
10597 | 1267 handler->args = objv[4]; |
1268 handler->proc = objv[5]; | |
6694 | 1269 handler->interp = interp; |
1270 if (!tcl_signal_connect(handler)) { | |
1271 tcl_signal_handler_free(handler); | |
1272 Tcl_SetIntObj(result, 1); | |
1273 } else { | |
1274 Tcl_SetIntObj(result, 0); | |
1275 } | |
1276 break; | |
1277 case CMD_SIGNAL_DISCONNECT: | |
1278 if (objc != 4) { | |
13810 | 1279 Tcl_WrongNumArgs(interp, 2, objv, "instance signal"); |
6694 | 1280 return TCL_ERROR; |
1281 } | |
1282 if ((error = Tcl_GetIntFromObj(interp, objv[2], (int *)&instance)) != TCL_OK) | |
1283 return error; | |
1284 tcl_signal_disconnect(instance, Tcl_GetString(objv[3]), interp); | |
1285 break; | |
1286 } | |
1287 | |
1288 return TCL_OK; | |
1289 } | |
1290 | |
13810 | 1291 int tcl_cmd_status(ClientData unused, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) |
1292 { | |
13826 | 1293 const char *cmds[] = { "attr", "type", NULL }; |
13810 | 1294 enum { CMD_STATUS_ATTR, CMD_STATUS_TYPE } cmd; |
1295 Tcl_Obj *result = Tcl_GetObjResult(interp); | |
1296 GaimStatus *status; | |
1297 GaimStatusType *status_type; | |
1298 GaimValue *value; | |
13824 | 1299 const char *attr; |
1300 int error, v; | |
13810 | 1301 |
1302 if (objc < 2) { | |
1303 Tcl_WrongNumArgs(interp, 1, objv, "subcommand ?args?"); | |
1304 return TCL_ERROR; | |
1305 } | |
1306 | |
1307 if ((error = Tcl_GetIndexFromObj(interp, objv[1], cmds, "subcommand", 0, (int *)&cmd)) != TCL_OK) | |
1308 return error; | |
1309 | |
1310 switch (cmd) { | |
1311 case CMD_STATUS_ATTR: | |
13824 | 1312 if (objc != 4 && objc != 5) { |
1313 Tcl_WrongNumArgs(interp, 2, objv, "status attr_id ?value?"); | |
13810 | 1314 return TCL_ERROR; |
1315 } | |
1316 if ((status = gaim_tcl_ref_get(interp, objv[2], GaimTclRefStatus)) == NULL) | |
1317 return TCL_ERROR; | |
13824 | 1318 attr = Tcl_GetString(objv[3]); |
1319 value = gaim_status_get_attr_value(status, attr); | |
13810 | 1320 if (value == NULL) { |
1321 Tcl_SetStringObj(result, "no such attribute", -1); | |
1322 return TCL_ERROR; | |
1323 } | |
1324 switch (gaim_value_get_type(value)) { | |
1325 case GAIM_TYPE_BOOLEAN: | |
13824 | 1326 if (objc == 4) { |
1327 Tcl_SetBooleanObj(result, gaim_value_get_boolean(value)); | |
1328 } else { | |
1329 if ((error = Tcl_GetBooleanFromObj(interp, objv[4], &v)) != TCL_OK) | |
1330 return error; | |
1331 gaim_status_set_attr_boolean(status, attr, v); | |
1332 } | |
13810 | 1333 break; |
1334 case GAIM_TYPE_INT: | |
13824 | 1335 if (objc == 4) { |
1336 Tcl_SetIntObj(result, gaim_value_get_int(value)); | |
1337 } else { | |
1338 if ((error = Tcl_GetIntFromObj(interp, objv[4], &v)) != TCL_OK) | |
1339 return error; | |
1340 gaim_status_set_attr_int(status, attr, v ); | |
1341 } | |
13810 | 1342 break; |
1343 case GAIM_TYPE_STRING: | |
13824 | 1344 if (objc == 4) |
1345 Tcl_SetStringObj(result, gaim_value_get_string(value), -1); | |
1346 else | |
1347 gaim_status_set_attr_string(status, attr, Tcl_GetString(objv[4])); | |
13810 | 1348 break; |
1349 default: | |
1350 Tcl_SetStringObj(result, "attribute has unknown type", -1); | |
1351 return TCL_ERROR; | |
1352 } | |
1353 break; | |
1354 case CMD_STATUS_TYPE: | |
1355 if (objc != 3) { | |
1356 Tcl_WrongNumArgs(interp, 2, objv, "status"); | |
1357 return TCL_ERROR; | |
1358 } | |
1359 if ((status = gaim_tcl_ref_get(interp, objv[2], GaimTclRefStatus)) == NULL) | |
1360 return TCL_ERROR; | |
1361 status_type = gaim_status_get_type(status); | |
1362 Tcl_SetObjResult(interp, gaim_tcl_ref_new(GaimTclRefStatusType, | |
1363 status_type)); | |
1364 break; | |
1365 } | |
1366 | |
1367 return TCL_OK; | |
1368 } | |
1369 | |
1370 int tcl_cmd_status_attr(ClientData unused, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) | |
1371 { | |
1372 const char *cmds[] = { "id", "name", NULL }; | |
1373 enum { CMD_STATUS_ATTR_ID, CMD_STATUS_ATTR_NAME } cmd; | |
1374 Tcl_Obj *result = Tcl_GetObjResult(interp); | |
1375 GaimStatusAttr *attr; | |
1376 int error; | |
1377 | |
1378 if (objc < 2) { | |
1379 Tcl_WrongNumArgs(interp, 1, objv, "subcommand ?args?"); | |
1380 return TCL_ERROR; | |
1381 } | |
1382 | |
1383 if ((error = Tcl_GetIndexFromObj(interp, objv[1], cmds, "subcommand", 0, (int *)&cmd)) != TCL_OK) | |
1384 return error; | |
1385 | |
1386 switch (cmd) { | |
1387 case CMD_STATUS_ATTR_ID: | |
1388 if (objc != 3) { | |
1389 Tcl_WrongNumArgs(interp, 2, objv, "attr"); | |
1390 return TCL_ERROR; | |
1391 } | |
1392 if ((attr = gaim_tcl_ref_get(interp, objv[2], GaimTclRefStatusAttr)) == NULL) | |
1393 return TCL_ERROR; | |
1394 Tcl_SetStringObj(result, gaim_status_attr_get_id(attr), -1); | |
1395 break; | |
1396 case CMD_STATUS_ATTR_NAME: | |
1397 if (objc != 3) { | |
1398 Tcl_WrongNumArgs(interp, 2, objv, "attr"); | |
1399 return TCL_ERROR; | |
1400 } | |
1401 if ((attr = gaim_tcl_ref_get(interp, objv[2], GaimTclRefStatusAttr)) == NULL) | |
1402 return TCL_ERROR; | |
1403 Tcl_SetStringObj(result, gaim_status_attr_get_name(attr), -1); | |
1404 break; | |
1405 } | |
1406 | |
1407 return TCL_OK; | |
1408 } | |
1409 | |
1410 int tcl_cmd_status_type(ClientData unused, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) | |
1411 { | |
1412 const char *cmds[] = { "attr", "attrs", "available", "exclusive", "id", | |
1413 "independent", "name", "primary_attr", | |
1414 "primitive", "saveable", "user_settable", | |
1415 NULL }; | |
1416 enum { CMD_STATUS_TYPE_ATTR, CMD_STATUS_TYPE_ATTRS, | |
1417 CMD_STATUS_TYPE_AVAILABLE, CMD_STATUS_TYPE_EXCLUSIVE, | |
1418 CMD_STATUS_TYPE_ID, CMD_STATUS_TYPE_INDEPENDENT, | |
1419 CMD_STATUS_TYPE_NAME, CMD_STATUS_TYPE_PRIMARY_ATTR, | |
1420 CMD_STATUS_TYPE_PRIMITIVE, CMD_STATUS_TYPE_SAVEABLE, | |
1421 CMD_STATUS_TYPE_USER_SETTABLE } cmd; | |
1422 Tcl_Obj *result = Tcl_GetObjResult(interp); | |
1423 GaimStatusType *status_type; | |
1424 Tcl_Obj *list, *elem; | |
1425 const GList *cur; | |
1426 int error; | |
1427 | |
1428 if (objc < 2) { | |
1429 Tcl_WrongNumArgs(interp, 1, objv, "subcommand ?args?"); | |
1430 return TCL_ERROR; | |
1431 } | |
1432 | |
1433 if ((error = Tcl_GetIndexFromObj(interp, objv[1], cmds, "subcommand", 0, (int *)&cmd)) != TCL_OK) | |
1434 return error; | |
1435 | |
1436 switch (cmd) { | |
1437 case CMD_STATUS_TYPE_AVAILABLE: | |
1438 if (objc != 3) { | |
1439 Tcl_WrongNumArgs(interp, 2, objv, "statustype"); | |
1440 return TCL_ERROR; | |
1441 } | |
1442 if ((status_type = gaim_tcl_ref_get(interp, objv[2], GaimTclRefStatusType)) == NULL) | |
1443 return TCL_ERROR; | |
1444 Tcl_SetBooleanObj(result, gaim_status_type_is_available(status_type)); | |
1445 break; | |
1446 case CMD_STATUS_TYPE_ATTR: | |
1447 if (objc != 4) { | |
1448 Tcl_WrongNumArgs(interp, 2, objv, "statustype attr"); | |
1449 return TCL_ERROR; | |
1450 } | |
1451 if ((status_type = gaim_tcl_ref_get(interp, objv[2], GaimTclRefStatusType)) == NULL) | |
1452 return TCL_ERROR; | |
1453 Tcl_SetObjResult(interp, | |
1454 gaim_tcl_ref_new(GaimTclRefStatusAttr, | |
1455 gaim_status_type_get_attr(status_type, | |
1456 Tcl_GetStringFromObj(objv[3], NULL)))); | |
1457 break; | |
1458 case CMD_STATUS_TYPE_ATTRS: | |
1459 if (objc != 3) { | |
1460 Tcl_WrongNumArgs(interp, 2, objv, "statustype"); | |
1461 return TCL_ERROR; | |
1462 } | |
1463 if ((status_type = gaim_tcl_ref_get(interp, objv[2], GaimTclRefStatusType)) == NULL) | |
1464 return TCL_ERROR; | |
1465 list = Tcl_NewListObj(0, NULL); | |
1466 for (cur = gaim_status_type_get_attrs(status_type); | |
1467 cur != NULL; cur = g_list_next(cur)) { | |
1468 elem = gaim_tcl_ref_new(GaimTclRefStatusAttr, cur->data); | |
1469 Tcl_ListObjAppendElement(interp, list, elem); | |
1470 } | |
1471 Tcl_SetObjResult(interp, list); | |
1472 break; | |
1473 case CMD_STATUS_TYPE_EXCLUSIVE: | |
1474 if (objc != 3) { | |
1475 Tcl_WrongNumArgs(interp, 2, objv, "statustype"); | |
1476 return TCL_ERROR; | |
1477 } | |
1478 if ((status_type = gaim_tcl_ref_get(interp, objv[2], GaimTclRefStatusType)) == NULL) | |
1479 return TCL_ERROR; | |
1480 Tcl_SetBooleanObj(result, gaim_status_type_is_exclusive(status_type)); | |
1481 break; | |
1482 case CMD_STATUS_TYPE_ID: | |
1483 if (objc != 3) { | |
1484 Tcl_WrongNumArgs(interp, 2, objv, "statustype"); | |
1485 return TCL_ERROR; | |
1486 } | |
1487 if ((status_type = gaim_tcl_ref_get(interp, objv[2], GaimTclRefStatusType)) == NULL) | |
1488 return TCL_ERROR; | |
1489 Tcl_SetStringObj(result, gaim_status_type_get_id(status_type), -1); | |
1490 break; | |
1491 case CMD_STATUS_TYPE_INDEPENDENT: | |
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 Tcl_SetBooleanObj(result, gaim_status_type_is_independent(status_type)); | |
1499 break; | |
1500 case CMD_STATUS_TYPE_NAME: | |
1501 if (objc != 3) { | |
1502 Tcl_WrongNumArgs(interp, 2, objv, "statustype"); | |
1503 return TCL_ERROR; | |
1504 } | |
1505 if ((status_type = gaim_tcl_ref_get(interp, objv[2], GaimTclRefStatusType)) == NULL) | |
1506 return TCL_ERROR; | |
1507 Tcl_SetStringObj(result, gaim_status_type_get_name(status_type), -1); | |
1508 break; | |
1509 case CMD_STATUS_TYPE_PRIMITIVE: | |
1510 if (objc != 3) { | |
1511 Tcl_WrongNumArgs(interp, 2, objv, "statustype"); | |
1512 return TCL_ERROR; | |
1513 } | |
1514 if ((status_type = gaim_tcl_ref_get(interp, objv[2], GaimTclRefStatusType)) == NULL) | |
1515 return TCL_ERROR; | |
1516 Tcl_SetStringObj(result, gaim_primitive_get_id_from_type(gaim_status_type_get_primitive(status_type)), -1); | |
1517 break; | |
1518 case CMD_STATUS_TYPE_PRIMARY_ATTR: | |
1519 if (objc != 3) { | |
1520 Tcl_WrongNumArgs(interp, 2, objv, "statustype"); | |
1521 return TCL_ERROR; | |
1522 } | |
1523 if ((status_type = gaim_tcl_ref_get(interp, objv[2], GaimTclRefStatusType)) == NULL) | |
1524 return TCL_ERROR; | |
1525 Tcl_SetStringObj(result, gaim_status_type_get_primary_attr(status_type), -1); | |
1526 break; | |
1527 case CMD_STATUS_TYPE_SAVEABLE: | |
1528 if (objc != 3) { | |
1529 Tcl_WrongNumArgs(interp, 2, objv, "statustype"); | |
1530 return TCL_ERROR; | |
1531 } | |
1532 if ((status_type = gaim_tcl_ref_get(interp, objv[2], GaimTclRefStatusType)) == NULL) | |
1533 return TCL_ERROR; | |
1534 Tcl_SetBooleanObj(result, gaim_status_type_is_saveable(status_type)); | |
1535 break; | |
1536 case CMD_STATUS_TYPE_USER_SETTABLE: | |
1537 if (objc != 3) { | |
1538 Tcl_WrongNumArgs(interp, 2, objv, "statustype"); | |
1539 return TCL_ERROR; | |
1540 } | |
1541 if ((status_type = gaim_tcl_ref_get(interp, objv[2], GaimTclRefStatusType)) == NULL) | |
1542 return TCL_ERROR; | |
1543 Tcl_SetBooleanObj(result, gaim_status_type_is_user_settable(status_type)); | |
1544 break; | |
1545 } | |
1546 | |
1547 return TCL_OK; | |
1548 } | |
1549 | |
6694 | 1550 static gboolean unload_self(gpointer data) |
1551 { | |
1552 GaimPlugin *plugin = data; | |
1553 gaim_plugin_unload(plugin); | |
1554 return FALSE; | |
1555 } | |
1556 | |
1557 int tcl_cmd_unload(ClientData unused, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) | |
1558 { | |
1559 GaimPlugin *plugin; | |
1560 if (objc != 1) { | |
1561 Tcl_WrongNumArgs(interp, 1, objv, ""); | |
1562 return TCL_ERROR; | |
1563 } | |
1564 | |
1565 if ((plugin = tcl_interp_get_plugin(interp)) == NULL) { | |
1566 /* This isn't exactly OK, but heh. What do you do? */ | |
1567 return TCL_OK; | |
1568 } | |
1569 /* We can't unload immediately, but we can unload at the first | |
1570 * known safe opportunity. */ | |
1571 g_idle_add(unload_self, (gpointer)plugin); | |
1572 | |
1573 return TCL_OK; | |
1574 } |