Mon, 02 Mar 2009 06:17:44 +0000
Fix compile errors from the merge. Untested protocols: msnp9, sametime,
silc, silc10, zephyr. Also, toc doesn't work either, but I don't know how
to fix it.
| 6694 | 1 | /** |
| 15884 | 2 | * @file tcl_cmds.c Commands for the Purple Tcl plugin bindings |
| 6694 | 3 | * |
| 15884 | 4 | * purple |
| 6694 | 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 | |
|
19859
71d37b57eff2
The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
19726
diff
changeset
|
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
| 6694 | 21 | */ |
| 22 | ||
| 23 | #include <tcl.h> | |
| 24 | ||
| 25 | #include "internal.h" | |
| 26 | #include "conversation.h" | |
| 27 | #include "connection.h" | |
|
22353
daef90676a8f
One more g_idle_add call
Mark Doliner <markdoliner@pidgin.im>
parents:
22240
diff
changeset
|
28 | #include "eventloop.h" |
| 6694 | 29 | #include "account.h" |
| 30 | #include "server.h" | |
| 31 | #include "notify.h" | |
| 6700 | 32 | #include "blist.h" |
|
15758
d31f3317c849
Tcl savedstatus command, again from Dossy Shiobara. Dossy is on fire.
Ethan Blanton <elb@pidgin.im>
parents:
15750
diff
changeset
|
33 | #include "savedstatuses.h" |
| 6694 | 34 | #include "debug.h" |
| 35 | #include "prefs.h" | |
| 36 | #include "core.h" | |
| 37 | ||
| 15884 | 38 | #include "tcl_purple.h" |
| 6694 | 39 | |
| 15884 | 40 | static PurpleAccount *tcl_validate_account(Tcl_Obj *obj, Tcl_Interp *interp); |
| 41 | static PurpleConversation *tcl_validate_conversation(Tcl_Obj *obj, Tcl_Interp *interp); | |
| 42 | static PurpleConnection *tcl_validate_gc(Tcl_Obj *obj, Tcl_Interp *interp); | |
| 6694 | 43 | |
| 15884 | 44 | static PurpleAccount *tcl_validate_account(Tcl_Obj *obj, Tcl_Interp *interp) |
| 6694 | 45 | { |
| 15884 | 46 | PurpleAccount *account; |
|
18122
9bf9970c1b6a
disapproval of revision '2d8ea56b90971e7851442d96b7d74ecb4f052126'
Richard Laager <rlaager@pidgin.im>
parents:
18121
diff
changeset
|
47 | GList *cur; |
| 13812 | 48 | |
| 15884 | 49 | account = purple_tcl_ref_get(interp, obj, PurpleTclRefAccount); |
| 13812 | 50 | |
| 51 | if (account == NULL) | |
| 52 | return NULL; | |
| 53 | ||
| 15884 | 54 | for (cur = purple_accounts_get_all(); cur != NULL; cur = g_list_next(cur)) { |
| 6694 | 55 | if (account == cur->data) |
| 13812 | 56 | return account; |
| 6694 | 57 | } |
| 58 | if (interp != NULL) | |
|
20394
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
59 | Tcl_SetObjResult(interp, Tcl_NewStringObj("invalid account", -1)); |
| 13812 | 60 | return NULL; |
| 6694 | 61 | } |
| 62 | ||
| 15884 | 63 | static PurpleConversation *tcl_validate_conversation(Tcl_Obj *obj, Tcl_Interp *interp) |
| 6694 | 64 | { |
| 15884 | 65 | PurpleConversation *convo; |
|
18122
9bf9970c1b6a
disapproval of revision '2d8ea56b90971e7851442d96b7d74ecb4f052126'
Richard Laager <rlaager@pidgin.im>
parents:
18121
diff
changeset
|
66 | GList *cur; |
| 6694 | 67 | |
| 15884 | 68 | convo = purple_tcl_ref_get(interp, obj, PurpleTclRefConversation); |
| 13812 | 69 | |
| 70 | if (convo == NULL) | |
| 71 | return NULL; | |
| 72 | ||
| 15884 | 73 | for (cur = purple_get_conversations(); cur != NULL; cur = g_list_next(cur)) { |
| 6694 | 74 | if (convo == cur->data) |
| 13812 | 75 | return convo; |
| 6694 | 76 | } |
| 77 | if (interp != NULL) | |
|
20394
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
78 | Tcl_SetObjResult(interp, Tcl_NewStringObj("invalid conversation", -1)); |
| 13812 | 79 | return NULL; |
| 6694 | 80 | } |
| 81 | ||
| 15884 | 82 | static PurpleConnection *tcl_validate_gc(Tcl_Obj *obj, Tcl_Interp *interp) |
| 6694 | 83 | { |
| 15884 | 84 | PurpleConnection *gc; |
|
18122
9bf9970c1b6a
disapproval of revision '2d8ea56b90971e7851442d96b7d74ecb4f052126'
Richard Laager <rlaager@pidgin.im>
parents:
18121
diff
changeset
|
85 | GList *cur; |
| 13817 | 86 | |
| 15884 | 87 | gc = purple_tcl_ref_get(interp, obj, PurpleTclRefConnection); |
| 13817 | 88 | |
| 89 | if (gc == NULL) | |
| 90 | return NULL; | |
| 91 | ||
| 15884 | 92 | for (cur = purple_connections_get_all(); cur != NULL; cur = g_list_next(cur)) { |
| 6694 | 93 | if (gc == cur->data) |
| 13817 | 94 | return gc; |
| 6694 | 95 | } |
| 13817 | 96 | return NULL; |
| 6694 | 97 | } |
| 98 | ||
| 99 | int tcl_cmd_account(ClientData unused, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) | |
| 100 | { | |
|
20394
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
101 | Tcl_Obj *result, *list, *elem; |
| 13828 | 102 | const char *cmds[] = { "alias", "connect", "connection", "disconnect", |
| 103 | "enabled", "find", "handle", "isconnected", | |
| 104 | "list", "presence", "protocol", "status", | |
| 105 | "status_type", "status_types", "username", | |
| 106 | NULL }; | |
| 107 | enum { CMD_ACCOUNT_ALIAS, | |
| 13812 | 108 | CMD_ACCOUNT_CONNECT, CMD_ACCOUNT_CONNECTION, |
| 109 | CMD_ACCOUNT_DISCONNECT, CMD_ACCOUNT_ENABLED, CMD_ACCOUNT_FIND, | |
| 110 | CMD_ACCOUNT_HANDLE, CMD_ACCOUNT_ISCONNECTED, CMD_ACCOUNT_LIST, | |
| 13828 | 111 | CMD_ACCOUNT_PRESENCE, CMD_ACCOUNT_PROTOCOL, CMD_ACCOUNT_STATUS, |
| 112 | CMD_ACCOUNT_STATUS_TYPE, CMD_ACCOUNT_STATUS_TYPES, | |
| 113 | CMD_ACCOUNT_USERNAME } cmd; | |
|
10339
246feba79f04
[gaim-migrate @ 11548]
Mark Doliner <markdoliner@pidgin.im>
parents:
10246
diff
changeset
|
114 | const char *listopts[] = { "-all", "-online", NULL }; |
| 6694 | 115 | enum { CMD_ACCOUNTLIST_ALL, CMD_ACCOUNTLIST_ONLINE } listopt; |
|
8834
0a798e3d2b84
[gaim-migrate @ 9598]
Mark Doliner <markdoliner@pidgin.im>
parents:
7713
diff
changeset
|
116 | const char *alias; |
|
18190
bcf28ef7e8ff
Re-fix the DBus list handling code by killing const GList* / const GSList*
Richard Laager <rlaager@pidgin.im>
parents:
18122
diff
changeset
|
117 | GList *cur; |
| 15884 | 118 | PurpleAccount *account; |
| 119 | PurpleStatus *status; | |
| 120 | PurpleStatusType *status_type; | |
| 121 | PurpleValue *value; | |
| 13828 | 122 | char *attr_id; |
| 6694 | 123 | int error; |
| 13828 | 124 | int b, i; |
| 6694 | 125 | |
| 126 | if (objc < 2) { | |
| 127 | Tcl_WrongNumArgs(interp, 1, objv, "subcommand ?args?"); | |
| 128 | return TCL_ERROR; | |
| 129 | } | |
| 130 | ||
| 131 | if ((error = Tcl_GetIndexFromObj(interp, objv[1], cmds, "subcommand", 0, (int *)&cmd)) != TCL_OK) | |
| 132 | return error; | |
| 133 | ||
| 134 | switch (cmd) { | |
| 135 | case CMD_ACCOUNT_ALIAS: | |
| 136 | if (objc != 3) { | |
| 137 | Tcl_WrongNumArgs(interp, 2, objv, "account"); | |
| 138 | return TCL_ERROR; | |
| 139 | } | |
| 13812 | 140 | if ((account = tcl_validate_account(objv[2], interp)) == NULL) |
| 6694 | 141 | return TCL_ERROR; |
| 15884 | 142 | alias = purple_account_get_alias(account); |
|
20394
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
143 | Tcl_SetObjResult(interp, Tcl_NewStringObj(alias ? (char *)alias : "", -1)); |
| 6694 | 144 | break; |
| 145 | case CMD_ACCOUNT_CONNECT: | |
| 146 | if (objc != 3) { | |
| 147 | Tcl_WrongNumArgs(interp, 2, objv, "account"); | |
| 148 | return TCL_ERROR; | |
| 149 | } | |
| 13812 | 150 | if ((account = tcl_validate_account(objv[2], interp)) == NULL) |
| 6694 | 151 | return TCL_ERROR; |
| 15884 | 152 | if (!purple_account_is_connected(account)) |
| 153 | purple_account_connect(account); | |
| 13817 | 154 | Tcl_SetObjResult(interp, |
| 15884 | 155 | purple_tcl_ref_new(PurpleTclRefConnection, |
| 156 | purple_account_get_connection(account))); | |
| 6694 | 157 | break; |
| 158 | case CMD_ACCOUNT_CONNECTION: | |
| 159 | if (objc != 3) { | |
| 160 | Tcl_WrongNumArgs(interp, 2, objv, "account"); | |
| 161 | return TCL_ERROR; | |
| 162 | } | |
| 13812 | 163 | |
| 164 | if ((account = tcl_validate_account(objv[2], interp)) == NULL) | |
| 6694 | 165 | return TCL_ERROR; |
| 13817 | 166 | Tcl_SetObjResult(interp, |
| 15884 | 167 | purple_tcl_ref_new(PurpleTclRefConnection, |
|
20394
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
168 | purple_account_get_connection(account))); |
| 6694 | 169 | break; |
| 170 | case CMD_ACCOUNT_DISCONNECT: | |
| 171 | if (objc != 3) { | |
| 172 | Tcl_WrongNumArgs(interp, 2, objv, "account"); | |
| 173 | return TCL_ERROR; | |
| 174 | } | |
| 13812 | 175 | if ((account = tcl_validate_account(objv[2], interp)) == NULL) |
| 6694 | 176 | return TCL_ERROR; |
| 15884 | 177 | purple_account_disconnect(account); |
| 6694 | 178 | break; |
| 13812 | 179 | case CMD_ACCOUNT_ENABLED: |
| 180 | if (objc != 3 && objc != 4) { | |
| 181 | Tcl_WrongNumArgs(interp, 2, objv, "account ?enabled?"); | |
| 182 | return TCL_ERROR; | |
| 183 | } | |
| 184 | if ((account = tcl_validate_account(objv[2], interp)) == NULL) | |
| 185 | return TCL_ERROR; | |
| 186 | if (objc == 3) { | |
|
20394
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
187 | Tcl_SetObjResult(interp, |
|
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
188 | Tcl_NewBooleanObj( |
|
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
189 | purple_account_get_enabled(account, |
|
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
190 | purple_core_get_ui()))); |
| 13812 | 191 | } else { |
| 192 | if ((error = Tcl_GetBooleanFromObj(interp, objv[3], &b)) != TCL_OK) | |
| 193 | return TCL_ERROR; | |
| 15884 | 194 | purple_account_set_enabled(account, purple_core_get_ui(), b); |
| 13812 | 195 | } |
| 196 | break; | |
| 6694 | 197 | case CMD_ACCOUNT_FIND: |
| 198 | if (objc != 4) { | |
| 199 | Tcl_WrongNumArgs(interp, 2, objv, "username protocol"); | |
| 200 | return TCL_ERROR; | |
| 201 | } | |
| 15884 | 202 | account = purple_accounts_find(Tcl_GetString(objv[2]), |
| 13817 | 203 | Tcl_GetString(objv[3])); |
| 204 | Tcl_SetObjResult(interp, | |
| 15884 | 205 | purple_tcl_ref_new(PurpleTclRefAccount, account)); |
| 6694 | 206 | break; |
| 207 | case CMD_ACCOUNT_HANDLE: | |
| 208 | if (objc != 2) { | |
| 209 | Tcl_WrongNumArgs(interp, 2, objv, ""); | |
| 210 | return TCL_ERROR; | |
| 211 | } | |
|
20393
6280efb8c658
Another fabulous patch to our Tcl loader from venks on irc.freenode.net.
Ethan Blanton <elb@pidgin.im>
parents:
19859
diff
changeset
|
212 | Tcl_SetObjResult(interp, |
|
6280efb8c658
Another fabulous patch to our Tcl loader from venks on irc.freenode.net.
Ethan Blanton <elb@pidgin.im>
parents:
19859
diff
changeset
|
213 | purple_tcl_ref_new(PurpleTclRefHandle, |
|
6280efb8c658
Another fabulous patch to our Tcl loader from venks on irc.freenode.net.
Ethan Blanton <elb@pidgin.im>
parents:
19859
diff
changeset
|
214 | purple_accounts_get_handle())); |
| 6694 | 215 | break; |
| 216 | case CMD_ACCOUNT_ISCONNECTED: | |
| 217 | if (objc != 3) { | |
| 218 | Tcl_WrongNumArgs(interp, 2, objv, "account"); | |
| 219 | return TCL_ERROR; | |
| 220 | } | |
| 13812 | 221 | if ((account = tcl_validate_account(objv[2], interp)) == NULL) |
| 6694 | 222 | return TCL_ERROR; |
|
20394
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
223 | Tcl_SetObjResult(interp, |
|
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
224 | Tcl_NewBooleanObj( |
|
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
225 | purple_account_is_connected(account))); |
| 6694 | 226 | break; |
| 227 | case CMD_ACCOUNT_LIST: | |
| 228 | listopt = CMD_ACCOUNTLIST_ALL; | |
| 229 | if (objc > 3) { | |
| 230 | Tcl_WrongNumArgs(interp, 2, objv, "?option?"); | |
| 231 | return TCL_ERROR; | |
| 232 | } | |
| 233 | if (objc == 3) { | |
| 234 | if ((error = Tcl_GetIndexFromObj(interp, objv[2], listopts, "option", 0, (int *)&listopt)) != TCL_OK) | |
| 235 | return error; | |
| 236 | } | |
| 237 | list = Tcl_NewListObj(0, NULL); | |
| 15884 | 238 | for (cur = purple_accounts_get_all(); cur != NULL; cur = g_list_next(cur)) { |
| 6694 | 239 | account = cur->data; |
| 15884 | 240 | if (listopt == CMD_ACCOUNTLIST_ONLINE && !purple_account_is_connected(account)) |
| 6694 | 241 | continue; |
| 15884 | 242 | elem = purple_tcl_ref_new(PurpleTclRefAccount, account); |
| 6694 | 243 | Tcl_ListObjAppendElement(interp, list, elem); |
| 244 | } | |
| 245 | Tcl_SetObjResult(interp, list); | |
| 246 | break; | |
| 13823 | 247 | case CMD_ACCOUNT_PRESENCE: |
| 248 | if (objc != 3) { | |
| 249 | Tcl_WrongNumArgs(interp, 2, objv, "account"); | |
| 250 | return TCL_ERROR; | |
| 251 | } | |
| 252 | if ((account = tcl_validate_account(objv[2], interp)) == NULL) | |
| 253 | return TCL_ERROR; | |
| 15884 | 254 | Tcl_SetObjResult(interp, purple_tcl_ref_new(PurpleTclRefPresence, |
| 255 | purple_account_get_presence(account))); | |
| 13823 | 256 | break; |
| 6694 | 257 | case CMD_ACCOUNT_PROTOCOL: |
| 258 | if (objc != 3) { | |
| 259 | Tcl_WrongNumArgs(interp, 2, objv, "account"); | |
| 260 | return TCL_ERROR; | |
| 261 | } | |
| 13812 | 262 | if ((account = tcl_validate_account(objv[2], interp)) == NULL) |
| 6694 | 263 | return TCL_ERROR; |
|
20394
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
264 | Tcl_SetObjResult(interp, Tcl_NewStringObj((char *)purple_account_get_protocol_id(account), -1)); |
| 6694 | 265 | break; |
| 13828 | 266 | case CMD_ACCOUNT_STATUS: |
| 267 | if (objc < 3) { | |
| 268 | Tcl_WrongNumArgs(interp, 2, objv, "account ?status_id name value ...?"); | |
| 269 | return TCL_ERROR; | |
| 270 | } | |
| 271 | if ((account = tcl_validate_account(objv[2], interp)) == NULL) | |
| 272 | return TCL_ERROR; | |
| 273 | if (objc == 3) { | |
| 274 | Tcl_SetObjResult(interp, | |
| 15884 | 275 | purple_tcl_ref_new(PurpleTclRefStatus, |
| 276 | purple_account_get_active_status(account))); | |
| 13828 | 277 | } else { |
| 278 | GList *l = NULL; | |
| 279 | if (objc % 2) { | |
|
20394
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
280 | Tcl_SetObjResult(interp, Tcl_NewStringObj("name without value setting status", -1)); |
| 13828 | 281 | return TCL_ERROR; |
| 282 | } | |
| 15884 | 283 | status = purple_account_get_status(account, Tcl_GetString(objv[3])); |
| 13828 | 284 | if (status == NULL) { |
|
20394
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
285 | Tcl_SetObjResult(interp, Tcl_NewStringObj("invalid status for account", -1)); |
| 13828 | 286 | return TCL_ERROR; |
| 287 | } | |
| 288 | for (i = 4; i < objc; i += 2) { | |
| 289 | attr_id = Tcl_GetString(objv[i]); | |
| 15884 | 290 | value = purple_status_get_attr_value(status, attr_id); |
| 13828 | 291 | if (value == NULL) { |
|
20394
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
292 | Tcl_SetObjResult(interp, Tcl_NewStringObj("invalid attribute for account", -1)); |
| 13828 | 293 | return TCL_ERROR; |
| 294 | } | |
| 15884 | 295 | switch (purple_value_get_type(value)) { |
| 296 | case PURPLE_TYPE_BOOLEAN: | |
| 13828 | 297 | error = Tcl_GetBooleanFromObj(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; | |
| 15884 | 303 | case PURPLE_TYPE_INT: |
| 13828 | 304 | error = Tcl_GetIntFromObj(interp, objv[i + 1], &b); |
| 305 | if (error != TCL_OK) | |
| 306 | return error; | |
| 307 | l = g_list_append(l, attr_id); | |
| 308 | l = g_list_append(l, GINT_TO_POINTER(b)); | |
| 309 | break; | |
| 15884 | 310 | case PURPLE_TYPE_STRING: |
| 13828 | 311 | l = g_list_append(l, attr_id); |
| 312 | l = g_list_append(l, Tcl_GetString(objv[i + 1])); | |
| 313 | break; | |
| 314 | default: | |
|
20394
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
315 | Tcl_SetObjResult(interp, Tcl_NewStringObj("unknown PurpleValue type", -1)); |
| 13828 | 316 | return TCL_ERROR; |
| 317 | } | |
| 318 | } | |
| 15884 | 319 | purple_account_set_status_list(account, Tcl_GetString(objv[3]), TRUE, l); |
| 13828 | 320 | g_list_free(l); |
| 321 | } | |
| 322 | break; | |
| 13812 | 323 | case CMD_ACCOUNT_STATUS_TYPE: |
| 324 | if (objc != 4 && objc != 5) { | |
| 325 | Tcl_WrongNumArgs(interp, 2, objv, "account ?statustype? ?-primitive primitive?"); | |
| 326 | return TCL_ERROR; | |
| 327 | } | |
| 328 | if ((account = tcl_validate_account(objv[2], interp)) == NULL) | |
| 329 | return TCL_ERROR; | |
| 330 | if (objc == 4) { | |
| 15884 | 331 | status_type = purple_account_get_status_type(account, |
| 13812 | 332 | Tcl_GetString(objv[3])); |
| 333 | } else { | |
| 15884 | 334 | PurpleStatusPrimitive primitive; |
| 13812 | 335 | if (strcmp(Tcl_GetString(objv[3]), "-primitive")) { |
|
20394
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
336 | result = Tcl_NewStringObj("bad option \"", -1); |
| 13812 | 337 | Tcl_AppendObjToObj(result, objv[3]); |
|
20394
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
338 | Tcl_AppendToObj(result, "\": should be -primitive", -1); |
|
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
339 | Tcl_SetObjResult(interp,result); |
| 13812 | 340 | return TCL_ERROR; |
| 341 | } | |
| 15884 | 342 | primitive = purple_primitive_get_type_from_id(Tcl_GetString(objv[4])); |
| 343 | status_type = purple_account_get_status_type_with_primitive(account, | |
| 13812 | 344 | primitive); |
| 345 | } | |
| 346 | if (status_type == NULL) { | |
|
20394
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
347 | Tcl_SetObjResult(interp, Tcl_NewStringObj("status type not found", -1)); |
| 13812 | 348 | return TCL_ERROR; |
| 349 | } | |
| 350 | Tcl_SetObjResult(interp, | |
| 15884 | 351 | purple_tcl_ref_new(PurpleTclRefStatusType, |
| 13812 | 352 | status_type)); |
| 353 | break; | |
| 354 | case CMD_ACCOUNT_STATUS_TYPES: | |
| 355 | if (objc != 3) { | |
| 356 | Tcl_WrongNumArgs(interp, 2, objv, "account"); | |
| 357 | return TCL_ERROR; | |
| 358 | } | |
| 359 | if ((account = tcl_validate_account(objv[2], interp)) == NULL) | |
| 360 | return TCL_ERROR; | |
| 361 | list = Tcl_NewListObj(0, NULL); | |
| 15884 | 362 | for (cur = purple_account_get_status_types(account); cur != NULL; |
| 13812 | 363 | cur = g_list_next(cur)) { |
| 364 | Tcl_ListObjAppendElement(interp, list, | |
| 15884 | 365 | purple_tcl_ref_new(PurpleTclRefStatusType, |
| 13812 | 366 | cur->data)); |
| 367 | } | |
| 368 | Tcl_SetObjResult(interp, list); | |
| 369 | break; | |
| 6694 | 370 | case CMD_ACCOUNT_USERNAME: |
| 371 | if (objc != 3) { | |
| 372 | Tcl_WrongNumArgs(interp, 2, objv, "account"); | |
| 373 | return TCL_ERROR; | |
| 374 | } | |
| 13812 | 375 | if ((account = tcl_validate_account(objv[2], interp)) == NULL) |
| 6694 | 376 | return TCL_ERROR; |
|
20394
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
377 | Tcl_SetObjResult(interp, |
|
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
378 | Tcl_NewStringObj((char *)purple_account_get_username(account), -1)); |
| 6694 | 379 | break; |
| 380 | } | |
| 381 | ||
| 382 | return TCL_OK; | |
| 383 | } | |
| 384 | ||
| 15884 | 385 | static PurpleBlistNode *tcl_list_to_buddy(Tcl_Interp *interp, int count, Tcl_Obj **elems) |
| 6694 | 386 | { |
| 15884 | 387 | PurpleBlistNode *node = NULL; |
| 388 | PurpleAccount *account; | |
| 6694 | 389 | char *name; |
| 390 | char *type; | |
| 391 | ||
| 392 | if (count < 3) { | |
|
20394
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
393 | Tcl_SetObjResult(interp, |
|
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
394 | Tcl_NewStringObj("list too short", -1)); |
| 6694 | 395 | return NULL; |
| 396 | } | |
| 397 | ||
| 398 | type = Tcl_GetString(elems[0]); | |
| 399 | name = Tcl_GetString(elems[1]); | |
| 13812 | 400 | if ((account = tcl_validate_account(elems[2], interp)) == NULL) |
| 6694 | 401 | return NULL; |
| 402 | ||
| 403 | if (!strcmp(type, "buddy")) { | |
|
24974
a81952e9babb
Update some casts (that the script didn't fix correctly) to GObject macros.
Richard Laager <rlaager@pidgin.im>
parents:
24560
diff
changeset
|
404 | node = PURPLE_BLIST_NODE(purple_find_buddy(account, name)); |
| 6694 | 405 | } else if (!strcmp(type, "group")) { |
|
24974
a81952e9babb
Update some casts (that the script didn't fix correctly) to GObject macros.
Richard Laager <rlaager@pidgin.im>
parents:
24560
diff
changeset
|
406 | node = PURPLE_BLIST_NODE(purple_blist_find_chat(account, name)); |
| 6694 | 407 | } |
| 408 | ||
| 409 | return node; | |
| 410 | } | |
| 411 | ||
| 412 | int tcl_cmd_buddy(ClientData unused, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) | |
| 413 | { | |
| 6746 | 414 | Tcl_Obj *list, *tclgroup, *tclgrouplist, *tclcontact, *tclcontactlist, *tclbud, **elems, *result; |
|
10339
246feba79f04
[gaim-migrate @ 11548]
Mark Doliner <markdoliner@pidgin.im>
parents:
10246
diff
changeset
|
415 | const char *cmds[] = { "alias", "handle", "info", "list", NULL }; |
| 6694 | 416 | enum { CMD_BUDDY_ALIAS, CMD_BUDDY_HANDLE, CMD_BUDDY_INFO, CMD_BUDDY_LIST } cmd; |
|
24556
8c9cf439084a
Fix Tcl to compile with the hidden structs.
Richard Laager <rlaager@pidgin.im>
parents:
22353
diff
changeset
|
417 | PurpleBlistNodeType type; |
| 15884 | 418 | PurpleBlistNode *node, *gnode, *bnode; |
| 419 | PurpleAccount *account; | |
| 420 | PurpleBuddy *bud; | |
| 421 | PurpleChat *cnode; | |
| 6694 | 422 | int error, all = 0, count; |
| 423 | ||
| 424 | if (objc < 2) { | |
| 425 | Tcl_WrongNumArgs(interp, 1, objv, "subcommand ?args?"); | |
| 426 | return TCL_ERROR; | |
| 427 | } | |
| 428 | if ((error = Tcl_GetIndexFromObj(interp, objv[1], cmds, "subcommand", 0, (int *)&cmd)) != TCL_OK) | |
| 429 | return error; | |
| 430 | ||
| 431 | switch (cmd) { | |
| 432 | case CMD_BUDDY_ALIAS: | |
| 433 | if (objc != 3) { | |
| 434 | Tcl_WrongNumArgs(interp, 2, objv, "buddy"); | |
| 435 | return TCL_ERROR; | |
| 436 | } | |
| 437 | if ((error = Tcl_ListObjGetElements(interp, objv[2], &count, &elems)) != TCL_OK) | |
| 438 | return error; | |
| 439 | if ((node = tcl_list_to_buddy(interp, count, elems)) == NULL) | |
| 440 | return TCL_ERROR; | |
| 24560 | 441 | type = purple_blist_node_get_type(node); |
|
24556
8c9cf439084a
Fix Tcl to compile with the hidden structs.
Richard Laager <rlaager@pidgin.im>
parents:
22353
diff
changeset
|
442 | if (type == PURPLE_BLIST_CHAT_NODE) |
|
20394
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
443 | Tcl_SetObjResult(interp, |
|
24556
8c9cf439084a
Fix Tcl to compile with the hidden structs.
Richard Laager <rlaager@pidgin.im>
parents:
22353
diff
changeset
|
444 | Tcl_NewStringObj(purple_chat_get_name((PurpleChat *)node), -1)); |
|
8c9cf439084a
Fix Tcl to compile with the hidden structs.
Richard Laager <rlaager@pidgin.im>
parents:
22353
diff
changeset
|
445 | else if (type == PURPLE_BLIST_BUDDY_NODE) |
|
20394
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
446 | Tcl_SetObjResult(interp, |
|
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
447 | Tcl_NewStringObj((char *)purple_buddy_get_alias((PurpleBuddy *)node), -1)); |
| 6694 | 448 | return TCL_OK; |
| 449 | break; | |
| 450 | case CMD_BUDDY_HANDLE: | |
| 451 | if (objc != 2) { | |
| 452 | Tcl_WrongNumArgs(interp, 2, objv, ""); | |
| 453 | return TCL_ERROR; | |
| 454 | } | |
|
20393
6280efb8c658
Another fabulous patch to our Tcl loader from venks on irc.freenode.net.
Ethan Blanton <elb@pidgin.im>
parents:
19859
diff
changeset
|
455 | Tcl_SetObjResult(interp, |
|
6280efb8c658
Another fabulous patch to our Tcl loader from venks on irc.freenode.net.
Ethan Blanton <elb@pidgin.im>
parents:
19859
diff
changeset
|
456 | purple_tcl_ref_new(PurpleTclRefHandle, |
|
6280efb8c658
Another fabulous patch to our Tcl loader from venks on irc.freenode.net.
Ethan Blanton <elb@pidgin.im>
parents:
19859
diff
changeset
|
457 | purple_blist_get_handle())); |
| 6694 | 458 | break; |
| 459 | case CMD_BUDDY_INFO: | |
| 460 | if (objc != 3 && objc != 4) { | |
| 461 | Tcl_WrongNumArgs(interp, 2, objv, "( buddy | account username )"); | |
| 462 | return TCL_ERROR; | |
| 463 | } | |
| 464 | if (objc == 3) { | |
| 465 | if ((error = Tcl_ListObjGetElements(interp, objv[2], &count, &elems)) != TCL_OK) | |
| 466 | return error; | |
| 467 | if (count < 3) { | |
|
20394
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
468 | Tcl_SetObjResult(interp, |
|
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
469 | Tcl_NewStringObj("buddy too short", -1)); |
| 6694 | 470 | return TCL_ERROR; |
| 471 | } | |
| 472 | if (strcmp("buddy", Tcl_GetString(elems[0]))) { | |
|
20394
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
473 | Tcl_SetObjResult(interp, |
|
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
474 | Tcl_NewStringObj("invalid buddy", -1)); |
| 6694 | 475 | return TCL_ERROR; |
| 476 | } | |
| 13812 | 477 | if ((account = tcl_validate_account(elems[2], interp)) == NULL) |
| 6694 | 478 | return TCL_ERROR; |
| 15884 | 479 | serv_get_info(purple_account_get_connection(account), Tcl_GetString(elems[1])); |
| 6694 | 480 | } else { |
| 13812 | 481 | if ((account = tcl_validate_account(objv[2], interp)) == NULL) |
| 6694 | 482 | return TCL_ERROR; |
| 15884 | 483 | serv_get_info(purple_account_get_connection(account), Tcl_GetString(objv[3])); |
| 6694 | 484 | } |
| 485 | break; | |
| 486 | case CMD_BUDDY_LIST: | |
| 487 | if (objc == 3) { | |
| 488 | if (!strcmp("-all", Tcl_GetString(objv[2]))) { | |
| 489 | all = 1; | |
| 490 | } else { | |
|
20394
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
491 | result = Tcl_NewStringObj("",-1); |
| 6694 | 492 | Tcl_AppendStringsToObj(result, "unknown option: ", Tcl_GetString(objv[2]), NULL); |
|
20394
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
493 | Tcl_SetObjResult(interp,result); |
| 6694 | 494 | return TCL_ERROR; |
| 495 | } | |
| 496 | } | |
| 497 | list = Tcl_NewListObj(0, NULL); | |
|
24556
8c9cf439084a
Fix Tcl to compile with the hidden structs.
Richard Laager <rlaager@pidgin.im>
parents:
22353
diff
changeset
|
498 | for (gnode = purple_blist_get_root(); gnode != NULL; gnode = purple_blist_node_get_sibling_next(gnode)) { |
| 6694 | 499 | tclgroup = Tcl_NewListObj(0, NULL); |
| 500 | Tcl_ListObjAppendElement(interp, tclgroup, Tcl_NewStringObj("group", -1)); | |
| 501 | Tcl_ListObjAppendElement(interp, tclgroup, | |
|
24556
8c9cf439084a
Fix Tcl to compile with the hidden structs.
Richard Laager <rlaager@pidgin.im>
parents:
22353
diff
changeset
|
502 | Tcl_NewStringObj(purple_group_get_name((PurpleGroup *)gnode), -1)); |
| 6694 | 503 | tclgrouplist = Tcl_NewListObj(0, NULL); |
|
24556
8c9cf439084a
Fix Tcl to compile with the hidden structs.
Richard Laager <rlaager@pidgin.im>
parents:
22353
diff
changeset
|
504 | for (node = purple_blist_node_get_first_child(gnode); node != NULL; node = purple_blist_node_get_sibling_next(node)) { |
|
8c9cf439084a
Fix Tcl to compile with the hidden structs.
Richard Laager <rlaager@pidgin.im>
parents:
22353
diff
changeset
|
505 | PurpleAccount *account; |
|
8c9cf439084a
Fix Tcl to compile with the hidden structs.
Richard Laager <rlaager@pidgin.im>
parents:
22353
diff
changeset
|
506 | |
|
8c9cf439084a
Fix Tcl to compile with the hidden structs.
Richard Laager <rlaager@pidgin.im>
parents:
22353
diff
changeset
|
507 | type = purple_blist_node_get_type(node); |
|
8c9cf439084a
Fix Tcl to compile with the hidden structs.
Richard Laager <rlaager@pidgin.im>
parents:
22353
diff
changeset
|
508 | switch (type) { |
| 15884 | 509 | case PURPLE_BLIST_CONTACT_NODE: |
| 6746 | 510 | tclcontact = Tcl_NewListObj(0, NULL); |
| 511 | Tcl_IncrRefCount(tclcontact); | |
| 512 | Tcl_ListObjAppendElement(interp, tclcontact, Tcl_NewStringObj("contact", -1)); | |
| 513 | tclcontactlist = Tcl_NewListObj(0, NULL); | |
| 514 | Tcl_IncrRefCount(tclcontactlist); | |
| 515 | count = 0; | |
|
24556
8c9cf439084a
Fix Tcl to compile with the hidden structs.
Richard Laager <rlaager@pidgin.im>
parents:
22353
diff
changeset
|
516 | for (bnode = purple_blist_node_get_first_child(node); bnode != NULL; bnode = purple_blist_node_get_sibling_next(bnode)) { |
|
8c9cf439084a
Fix Tcl to compile with the hidden structs.
Richard Laager <rlaager@pidgin.im>
parents:
22353
diff
changeset
|
517 | if (purple_blist_node_get_type(bnode) != PURPLE_BLIST_BUDDY_NODE) |
| 6746 | 518 | continue; |
| 15884 | 519 | bud = (PurpleBuddy *)bnode; |
|
24556
8c9cf439084a
Fix Tcl to compile with the hidden structs.
Richard Laager <rlaager@pidgin.im>
parents:
22353
diff
changeset
|
520 | account = purple_buddy_get_account(bud); |
|
8c9cf439084a
Fix Tcl to compile with the hidden structs.
Richard Laager <rlaager@pidgin.im>
parents:
22353
diff
changeset
|
521 | if (!all && !purple_account_is_connected(account)) |
| 6746 | 522 | continue; |
| 523 | count++; | |
| 524 | tclbud = Tcl_NewListObj(0, NULL); | |
| 525 | Tcl_ListObjAppendElement(interp, tclbud, Tcl_NewStringObj("buddy", -1)); | |
|
24556
8c9cf439084a
Fix Tcl to compile with the hidden structs.
Richard Laager <rlaager@pidgin.im>
parents:
22353
diff
changeset
|
526 | Tcl_ListObjAppendElement(interp, tclbud, Tcl_NewStringObj(purple_buddy_get_name(bud), -1)); |
|
8c9cf439084a
Fix Tcl to compile with the hidden structs.
Richard Laager <rlaager@pidgin.im>
parents:
22353
diff
changeset
|
527 | Tcl_ListObjAppendElement(interp, tclbud, purple_tcl_ref_new(PurpleTclRefAccount, account)); |
| 6746 | 528 | Tcl_ListObjAppendElement(interp, tclcontactlist, tclbud); |
| 529 | } | |
| 530 | if (count) { | |
| 531 | Tcl_ListObjAppendElement(interp, tclcontact, tclcontactlist); | |
| 532 | Tcl_ListObjAppendElement(interp, tclgrouplist, tclcontact); | |
| 533 | } | |
| 534 | Tcl_DecrRefCount(tclcontact); | |
| 535 | Tcl_DecrRefCount(tclcontactlist); | |
| 6694 | 536 | break; |
| 15884 | 537 | case PURPLE_BLIST_CHAT_NODE: |
| 538 | cnode = (PurpleChat *)node; | |
|
24556
8c9cf439084a
Fix Tcl to compile with the hidden structs.
Richard Laager <rlaager@pidgin.im>
parents:
22353
diff
changeset
|
539 | account = purple_chat_get_account(cnode); |
|
8c9cf439084a
Fix Tcl to compile with the hidden structs.
Richard Laager <rlaager@pidgin.im>
parents:
22353
diff
changeset
|
540 | if (!all && !purple_account_is_connected(account)) |
| 6694 | 541 | continue; |
| 542 | tclbud = Tcl_NewListObj(0, NULL); | |
| 543 | Tcl_ListObjAppendElement(interp, tclbud, Tcl_NewStringObj("chat", -1)); | |
|
24556
8c9cf439084a
Fix Tcl to compile with the hidden structs.
Richard Laager <rlaager@pidgin.im>
parents:
22353
diff
changeset
|
544 | Tcl_ListObjAppendElement(interp, tclbud, Tcl_NewStringObj(purple_chat_get_name(cnode), -1)); |
|
8c9cf439084a
Fix Tcl to compile with the hidden structs.
Richard Laager <rlaager@pidgin.im>
parents:
22353
diff
changeset
|
545 | Tcl_ListObjAppendElement(interp, tclbud, purple_tcl_ref_new(PurpleTclRefAccount, account)); |
| 6746 | 546 | Tcl_ListObjAppendElement(interp, tclgrouplist, tclbud); |
| 6694 | 547 | break; |
| 548 | default: | |
|
24556
8c9cf439084a
Fix Tcl to compile with the hidden structs.
Richard Laager <rlaager@pidgin.im>
parents:
22353
diff
changeset
|
549 | purple_debug(PURPLE_DEBUG_WARNING, "tcl", "Unexpected buddy type %d", type); |
| 6694 | 550 | continue; |
| 551 | } | |
| 552 | } | |
| 553 | Tcl_ListObjAppendElement(interp, tclgroup, tclgrouplist); | |
| 554 | Tcl_ListObjAppendElement(interp, list, tclgroup); | |
| 555 | } | |
| 556 | Tcl_SetObjResult(interp, list); | |
| 557 | break; | |
| 558 | } | |
| 559 | ||
| 560 | return TCL_OK; | |
| 561 | } | |
| 562 | ||
| 13847 | 563 | int tcl_cmd_cmd(ClientData unused, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) |
| 564 | { | |
|
19726
22a31d50bab5
Patch from Dossy Shiobara which improves Tcl support for purple
Ethan Blanton <elb@pidgin.im>
parents:
18190
diff
changeset
|
565 | const char *cmds[] = { "do", "help", "list", "register", "unregister", NULL }; |
|
22a31d50bab5
Patch from Dossy Shiobara which improves Tcl support for purple
Ethan Blanton <elb@pidgin.im>
parents:
18190
diff
changeset
|
566 | enum { CMD_CMD_DO, CMD_CMD_HELP, CMD_CMD_LIST, CMD_CMD_REGISTER, CMD_CMD_UNREGISTER } cmd; |
| 13847 | 567 | struct tcl_cmd_handler *handler; |
|
20394
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
568 | Tcl_Obj *list, *elem; |
|
19726
22a31d50bab5
Patch from Dossy Shiobara which improves Tcl support for purple
Ethan Blanton <elb@pidgin.im>
parents:
18190
diff
changeset
|
569 | PurpleConversation *convo; |
| 15884 | 570 | PurpleCmdId id; |
|
19726
22a31d50bab5
Patch from Dossy Shiobara which improves Tcl support for purple
Ethan Blanton <elb@pidgin.im>
parents:
18190
diff
changeset
|
571 | PurpleCmdStatus status; |
| 13847 | 572 | int error; |
|
19726
22a31d50bab5
Patch from Dossy Shiobara which improves Tcl support for purple
Ethan Blanton <elb@pidgin.im>
parents:
18190
diff
changeset
|
573 | GList *l, *cur; |
|
22a31d50bab5
Patch from Dossy Shiobara which improves Tcl support for purple
Ethan Blanton <elb@pidgin.im>
parents:
18190
diff
changeset
|
574 | gchar *escaped, *errstr = NULL; |
| 13847 | 575 | |
| 576 | if (objc < 2) { | |
| 577 | Tcl_WrongNumArgs(interp, 1, objv, "subcommand ?args?"); | |
| 578 | return TCL_ERROR; | |
| 579 | } | |
| 580 | ||
| 581 | if ((error = Tcl_GetIndexFromObj(interp, objv[1], cmds, "subcommand", 0, (int *)&cmd)) != TCL_OK) | |
| 582 | return error; | |
| 583 | ||
| 584 | switch (cmd) { | |
|
19726
22a31d50bab5
Patch from Dossy Shiobara which improves Tcl support for purple
Ethan Blanton <elb@pidgin.im>
parents:
18190
diff
changeset
|
585 | case CMD_CMD_DO: |
|
22a31d50bab5
Patch from Dossy Shiobara which improves Tcl support for purple
Ethan Blanton <elb@pidgin.im>
parents:
18190
diff
changeset
|
586 | if (objc != 4) { |
|
22a31d50bab5
Patch from Dossy Shiobara which improves Tcl support for purple
Ethan Blanton <elb@pidgin.im>
parents:
18190
diff
changeset
|
587 | Tcl_WrongNumArgs(interp, 2, objv, "conversation command"); |
|
22a31d50bab5
Patch from Dossy Shiobara which improves Tcl support for purple
Ethan Blanton <elb@pidgin.im>
parents:
18190
diff
changeset
|
588 | return TCL_ERROR; |
|
22a31d50bab5
Patch from Dossy Shiobara which improves Tcl support for purple
Ethan Blanton <elb@pidgin.im>
parents:
18190
diff
changeset
|
589 | } |
|
22a31d50bab5
Patch from Dossy Shiobara which improves Tcl support for purple
Ethan Blanton <elb@pidgin.im>
parents:
18190
diff
changeset
|
590 | if ((convo = tcl_validate_conversation(objv[2], interp)) == NULL) |
|
22a31d50bab5
Patch from Dossy Shiobara which improves Tcl support for purple
Ethan Blanton <elb@pidgin.im>
parents:
18190
diff
changeset
|
591 | return TCL_ERROR; |
|
22a31d50bab5
Patch from Dossy Shiobara which improves Tcl support for purple
Ethan Blanton <elb@pidgin.im>
parents:
18190
diff
changeset
|
592 | escaped = g_markup_escape_text(Tcl_GetString(objv[3]), -1); |
|
22a31d50bab5
Patch from Dossy Shiobara which improves Tcl support for purple
Ethan Blanton <elb@pidgin.im>
parents:
18190
diff
changeset
|
593 | status = purple_cmd_do_command(convo, Tcl_GetString(objv[3]), |
|
22a31d50bab5
Patch from Dossy Shiobara which improves Tcl support for purple
Ethan Blanton <elb@pidgin.im>
parents:
18190
diff
changeset
|
594 | escaped, &errstr); |
|
22a31d50bab5
Patch from Dossy Shiobara which improves Tcl support for purple
Ethan Blanton <elb@pidgin.im>
parents:
18190
diff
changeset
|
595 | g_free(escaped); |
|
20394
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
596 | Tcl_SetObjResult(interp, |
|
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
597 | Tcl_NewStringObj(errstr ? (char *)errstr : "", -1)); |
|
19726
22a31d50bab5
Patch from Dossy Shiobara which improves Tcl support for purple
Ethan Blanton <elb@pidgin.im>
parents:
18190
diff
changeset
|
598 | g_free(errstr); |
|
22a31d50bab5
Patch from Dossy Shiobara which improves Tcl support for purple
Ethan Blanton <elb@pidgin.im>
parents:
18190
diff
changeset
|
599 | if (status != PURPLE_CMD_STATUS_OK) { |
|
22a31d50bab5
Patch from Dossy Shiobara which improves Tcl support for purple
Ethan Blanton <elb@pidgin.im>
parents:
18190
diff
changeset
|
600 | return TCL_ERROR; |
|
22a31d50bab5
Patch from Dossy Shiobara which improves Tcl support for purple
Ethan Blanton <elb@pidgin.im>
parents:
18190
diff
changeset
|
601 | } |
|
22a31d50bab5
Patch from Dossy Shiobara which improves Tcl support for purple
Ethan Blanton <elb@pidgin.im>
parents:
18190
diff
changeset
|
602 | break; |
|
22a31d50bab5
Patch from Dossy Shiobara which improves Tcl support for purple
Ethan Blanton <elb@pidgin.im>
parents:
18190
diff
changeset
|
603 | case CMD_CMD_HELP: |
|
22a31d50bab5
Patch from Dossy Shiobara which improves Tcl support for purple
Ethan Blanton <elb@pidgin.im>
parents:
18190
diff
changeset
|
604 | if (objc != 4) { |
|
22a31d50bab5
Patch from Dossy Shiobara which improves Tcl support for purple
Ethan Blanton <elb@pidgin.im>
parents:
18190
diff
changeset
|
605 | Tcl_WrongNumArgs(interp, 2, objv, "conversation name"); |
|
22a31d50bab5
Patch from Dossy Shiobara which improves Tcl support for purple
Ethan Blanton <elb@pidgin.im>
parents:
18190
diff
changeset
|
606 | return TCL_ERROR; |
|
22a31d50bab5
Patch from Dossy Shiobara which improves Tcl support for purple
Ethan Blanton <elb@pidgin.im>
parents:
18190
diff
changeset
|
607 | } |
|
22a31d50bab5
Patch from Dossy Shiobara which improves Tcl support for purple
Ethan Blanton <elb@pidgin.im>
parents:
18190
diff
changeset
|
608 | if ((convo = tcl_validate_conversation(objv[2], interp)) == NULL) |
|
22a31d50bab5
Patch from Dossy Shiobara which improves Tcl support for purple
Ethan Blanton <elb@pidgin.im>
parents:
18190
diff
changeset
|
609 | return TCL_ERROR; |
|
22a31d50bab5
Patch from Dossy Shiobara which improves Tcl support for purple
Ethan Blanton <elb@pidgin.im>
parents:
18190
diff
changeset
|
610 | l = cur = purple_cmd_help(convo, Tcl_GetString(objv[3])); |
|
22a31d50bab5
Patch from Dossy Shiobara which improves Tcl support for purple
Ethan Blanton <elb@pidgin.im>
parents:
18190
diff
changeset
|
611 | list = Tcl_NewListObj(0, NULL); |
|
22a31d50bab5
Patch from Dossy Shiobara which improves Tcl support for purple
Ethan Blanton <elb@pidgin.im>
parents:
18190
diff
changeset
|
612 | while (cur != NULL) { |
|
22a31d50bab5
Patch from Dossy Shiobara which improves Tcl support for purple
Ethan Blanton <elb@pidgin.im>
parents:
18190
diff
changeset
|
613 | elem = Tcl_NewStringObj((char *)cur->data, -1); |
|
22a31d50bab5
Patch from Dossy Shiobara which improves Tcl support for purple
Ethan Blanton <elb@pidgin.im>
parents:
18190
diff
changeset
|
614 | Tcl_ListObjAppendElement(interp, list, elem); |
|
22a31d50bab5
Patch from Dossy Shiobara which improves Tcl support for purple
Ethan Blanton <elb@pidgin.im>
parents:
18190
diff
changeset
|
615 | cur = g_list_next(cur); |
|
22a31d50bab5
Patch from Dossy Shiobara which improves Tcl support for purple
Ethan Blanton <elb@pidgin.im>
parents:
18190
diff
changeset
|
616 | } |
|
22a31d50bab5
Patch from Dossy Shiobara which improves Tcl support for purple
Ethan Blanton <elb@pidgin.im>
parents:
18190
diff
changeset
|
617 | g_list_free(l); |
|
22a31d50bab5
Patch from Dossy Shiobara which improves Tcl support for purple
Ethan Blanton <elb@pidgin.im>
parents:
18190
diff
changeset
|
618 | Tcl_SetObjResult(interp, list); |
|
22a31d50bab5
Patch from Dossy Shiobara which improves Tcl support for purple
Ethan Blanton <elb@pidgin.im>
parents:
18190
diff
changeset
|
619 | break; |
|
22a31d50bab5
Patch from Dossy Shiobara which improves Tcl support for purple
Ethan Blanton <elb@pidgin.im>
parents:
18190
diff
changeset
|
620 | case CMD_CMD_LIST: |
|
22a31d50bab5
Patch from Dossy Shiobara which improves Tcl support for purple
Ethan Blanton <elb@pidgin.im>
parents:
18190
diff
changeset
|
621 | if (objc != 3) { |
|
22a31d50bab5
Patch from Dossy Shiobara which improves Tcl support for purple
Ethan Blanton <elb@pidgin.im>
parents:
18190
diff
changeset
|
622 | Tcl_WrongNumArgs(interp, 2, objv, "conversation"); |
|
22a31d50bab5
Patch from Dossy Shiobara which improves Tcl support for purple
Ethan Blanton <elb@pidgin.im>
parents:
18190
diff
changeset
|
623 | return TCL_ERROR; |
|
22a31d50bab5
Patch from Dossy Shiobara which improves Tcl support for purple
Ethan Blanton <elb@pidgin.im>
parents:
18190
diff
changeset
|
624 | } |
|
22a31d50bab5
Patch from Dossy Shiobara which improves Tcl support for purple
Ethan Blanton <elb@pidgin.im>
parents:
18190
diff
changeset
|
625 | if ((convo = tcl_validate_conversation(objv[2], interp)) == NULL) |
|
22a31d50bab5
Patch from Dossy Shiobara which improves Tcl support for purple
Ethan Blanton <elb@pidgin.im>
parents:
18190
diff
changeset
|
626 | return TCL_ERROR; |
|
22a31d50bab5
Patch from Dossy Shiobara which improves Tcl support for purple
Ethan Blanton <elb@pidgin.im>
parents:
18190
diff
changeset
|
627 | l = cur = purple_cmd_list(convo); |
|
22a31d50bab5
Patch from Dossy Shiobara which improves Tcl support for purple
Ethan Blanton <elb@pidgin.im>
parents:
18190
diff
changeset
|
628 | list = Tcl_NewListObj(0, NULL); |
|
22a31d50bab5
Patch from Dossy Shiobara which improves Tcl support for purple
Ethan Blanton <elb@pidgin.im>
parents:
18190
diff
changeset
|
629 | while (cur != NULL) { |
|
22a31d50bab5
Patch from Dossy Shiobara which improves Tcl support for purple
Ethan Blanton <elb@pidgin.im>
parents:
18190
diff
changeset
|
630 | elem = Tcl_NewStringObj((char *)cur->data, -1); |
|
22a31d50bab5
Patch from Dossy Shiobara which improves Tcl support for purple
Ethan Blanton <elb@pidgin.im>
parents:
18190
diff
changeset
|
631 | Tcl_ListObjAppendElement(interp, list, elem); |
|
22a31d50bab5
Patch from Dossy Shiobara which improves Tcl support for purple
Ethan Blanton <elb@pidgin.im>
parents:
18190
diff
changeset
|
632 | cur = g_list_next(cur); |
|
22a31d50bab5
Patch from Dossy Shiobara which improves Tcl support for purple
Ethan Blanton <elb@pidgin.im>
parents:
18190
diff
changeset
|
633 | } |
|
22a31d50bab5
Patch from Dossy Shiobara which improves Tcl support for purple
Ethan Blanton <elb@pidgin.im>
parents:
18190
diff
changeset
|
634 | g_list_free(l); |
|
22a31d50bab5
Patch from Dossy Shiobara which improves Tcl support for purple
Ethan Blanton <elb@pidgin.im>
parents:
18190
diff
changeset
|
635 | Tcl_SetObjResult(interp, list); |
|
22a31d50bab5
Patch from Dossy Shiobara which improves Tcl support for purple
Ethan Blanton <elb@pidgin.im>
parents:
18190
diff
changeset
|
636 | break; |
| 13847 | 637 | case CMD_CMD_REGISTER: |
| 638 | if (objc != 9) { | |
| 639 | Tcl_WrongNumArgs(interp, 2, objv, "cmd arglist priority flags prpl_id proc helpstr"); | |
| 640 | return TCL_ERROR; | |
| 641 | } | |
| 642 | handler = g_new0(struct tcl_cmd_handler, 1); | |
| 643 | handler->cmd = objv[2]; | |
| 644 | handler->args = Tcl_GetString(objv[3]); | |
| 645 | handler->nargs = strlen(handler->args); | |
| 646 | if ((error = Tcl_GetIntFromObj(interp, objv[4], | |
| 647 | &handler->priority)) != TCL_OK) { | |
| 648 | g_free(handler); | |
| 649 | return error; | |
| 650 | } | |
| 651 | if ((error = Tcl_GetIntFromObj(interp, objv[5], | |
| 652 | &handler->flags)) != TCL_OK) { | |
| 653 | g_free(handler); | |
| 654 | return error; | |
| 655 | } | |
| 656 | handler->prpl_id = Tcl_GetString(objv[6]); | |
| 657 | handler->proc = objv[7]; | |
| 658 | handler->helpstr = Tcl_GetString(objv[8]); | |
| 659 | handler->interp = interp; | |
| 660 | if ((id = tcl_cmd_register(handler)) == 0) { | |
| 661 | tcl_cmd_handler_free(handler); | |
|
20394
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
662 | Tcl_SetObjResult(interp, Tcl_NewIntObj(0)); |
| 13847 | 663 | } else { |
| 664 | handler->id = id; | |
|
20394
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
665 | Tcl_SetObjResult(interp, Tcl_NewIntObj(id)); |
| 13847 | 666 | } |
| 667 | break; | |
| 668 | case CMD_CMD_UNREGISTER: | |
| 669 | if (objc != 3) { | |
| 670 | Tcl_WrongNumArgs(interp, 2, objv, "id"); | |
| 671 | return TCL_ERROR; | |
| 672 | } | |
| 673 | if ((error = Tcl_GetIntFromObj(interp, objv[2], | |
| 674 | (int *)&id)) != TCL_OK) | |
| 675 | return error; | |
| 676 | tcl_cmd_unregister(id, interp); | |
| 677 | break; | |
| 678 | } | |
| 679 | ||
| 680 | return TCL_OK; | |
| 681 | } | |
| 682 | ||
| 6694 | 683 | int tcl_cmd_connection(ClientData unused, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) |
| 684 | { | |
|
20394
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
685 | Tcl_Obj *list, *elem; |
|
10339
246feba79f04
[gaim-migrate @ 11548]
Mark Doliner <markdoliner@pidgin.im>
parents:
10246
diff
changeset
|
686 | const char *cmds[] = { "account", "displayname", "handle", "list", NULL }; |
| 7713 | 687 | enum { CMD_CONN_ACCOUNT, CMD_CONN_DISPLAYNAME, CMD_CONN_HANDLE, CMD_CONN_LIST } cmd; |
| 6694 | 688 | int error; |
|
18122
9bf9970c1b6a
disapproval of revision '2d8ea56b90971e7851442d96b7d74ecb4f052126'
Richard Laager <rlaager@pidgin.im>
parents:
18121
diff
changeset
|
689 | GList *cur; |
| 15884 | 690 | PurpleConnection *gc; |
| 6694 | 691 | |
| 692 | if (objc < 2) { | |
| 693 | Tcl_WrongNumArgs(interp, 1, objv, "subcommand ?args?"); | |
| 694 | return TCL_ERROR; | |
| 695 | } | |
| 696 | ||
| 697 | if ((error = Tcl_GetIndexFromObj(interp, objv[1], cmds, "subcommand", 0, (int *)&cmd)) != TCL_OK) | |
| 698 | return error; | |
| 699 | ||
| 700 | switch (cmd) { | |
| 701 | case CMD_CONN_ACCOUNT: | |
| 702 | if (objc != 3) { | |
|
6864
359bc55e767f
[gaim-migrate @ 7410]
Björn Voigt <bjoern@cs.tu-berlin.de>
parents:
6746
diff
changeset
|
703 | Tcl_WrongNumArgs(interp, 2, objv, "gc"); |
| 6694 | 704 | return TCL_ERROR; |
| 705 | } | |
| 13817 | 706 | if ((gc = tcl_validate_gc(objv[2], interp)) == NULL) |
| 6694 | 707 | return TCL_ERROR; |
| 13817 | 708 | Tcl_SetObjResult(interp, |
| 15884 | 709 | purple_tcl_ref_new(PurpleTclRefAccount, |
| 710 | purple_connection_get_account(gc))); | |
| 6694 | 711 | break; |
| 7713 | 712 | case CMD_CONN_DISPLAYNAME: |
| 713 | if (objc != 3) { | |
| 714 | Tcl_WrongNumArgs(interp, 2, objv, "gc"); | |
| 715 | return TCL_ERROR; | |
| 716 | } | |
| 13817 | 717 | if ((gc = tcl_validate_gc(objv[2], interp)) == NULL) |
| 7713 | 718 | return TCL_ERROR; |
|
20394
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
719 | Tcl_SetObjResult(interp, |
|
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
720 | Tcl_NewStringObj(purple_connection_get_display_name(gc), -1)); |
| 7713 | 721 | break; |
| 6694 | 722 | case CMD_CONN_HANDLE: |
| 723 | if (objc != 2) { | |
| 724 | Tcl_WrongNumArgs(interp, 2, objv, ""); | |
| 725 | return TCL_ERROR; | |
| 726 | } | |
|
20393
6280efb8c658
Another fabulous patch to our Tcl loader from venks on irc.freenode.net.
Ethan Blanton <elb@pidgin.im>
parents:
19859
diff
changeset
|
727 | Tcl_SetObjResult(interp, purple_tcl_ref_new(PurpleTclRefHandle, |
|
6280efb8c658
Another fabulous patch to our Tcl loader from venks on irc.freenode.net.
Ethan Blanton <elb@pidgin.im>
parents:
19859
diff
changeset
|
728 | purple_connections_get_handle())); |
| 6694 | 729 | break; |
| 730 | case CMD_CONN_LIST: | |
| 731 | if (objc != 2) { | |
| 732 | Tcl_WrongNumArgs(interp, 2, objv, ""); | |
| 733 | return TCL_ERROR; | |
| 734 | } | |
| 735 | list = Tcl_NewListObj(0, NULL); | |
| 15884 | 736 | for (cur = purple_connections_get_all(); cur != NULL; cur = g_list_next(cur)) { |
| 737 | elem = purple_tcl_ref_new(PurpleTclRefConnection, cur->data); | |
| 6694 | 738 | Tcl_ListObjAppendElement(interp, list, elem); |
| 739 | } | |
| 740 | Tcl_SetObjResult(interp, list); | |
| 741 | break; | |
| 742 | } | |
| 743 | ||
| 744 | return TCL_OK; | |
| 745 | } | |
| 746 | ||
| 747 | int tcl_cmd_conversation(ClientData unused, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) | |
| 748 | { | |
|
20394
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
749 | Tcl_Obj *list, *elem; |
| 14425 | 750 | const char *cmds[] = { "find", "handle", "list", "new", "write", "name", "title", "send", NULL }; |
| 751 | 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; | |
|
10339
246feba79f04
[gaim-migrate @ 11548]
Mark Doliner <markdoliner@pidgin.im>
parents:
10246
diff
changeset
|
752 | const char *styles[] = { "send", "recv", "system", NULL }; |
| 6694 | 753 | enum { CMD_CONV_WRITE_SEND, CMD_CONV_WRITE_RECV, CMD_CONV_WRITE_SYSTEM } style; |
|
10339
246feba79f04
[gaim-migrate @ 11548]
Mark Doliner <markdoliner@pidgin.im>
parents:
10246
diff
changeset
|
754 | const char *newopts[] = { "-chat", "-im" }; |
| 6694 | 755 | enum { CMD_CONV_NEW_CHAT, CMD_CONV_NEW_IM } newopt; |
| 15884 | 756 | PurpleConversation *convo; |
| 757 | PurpleAccount *account; | |
| 758 | PurpleConversationType type; | |
|
18122
9bf9970c1b6a
disapproval of revision '2d8ea56b90971e7851442d96b7d74ecb4f052126'
Richard Laager <rlaager@pidgin.im>
parents:
18121
diff
changeset
|
759 | GList *cur; |
| 6694 | 760 | char *opt, *from, *what; |
| 7156 | 761 | int error, argsused, flags = 0; |
| 6694 | 762 | |
| 763 | if (objc < 2) { | |
| 764 | Tcl_WrongNumArgs(interp, 1, objv, "subcommand ?args?"); | |
| 765 | return TCL_ERROR; | |
| 766 | } | |
| 767 | ||
| 768 | if ((error = Tcl_GetIndexFromObj(interp, objv[1], cmds, "subcommand", 0, (int *)&cmd)) != TCL_OK) | |
| 769 | return error; | |
| 770 | ||
| 771 | switch (cmd) { | |
| 772 | case CMD_CONV_FIND: | |
| 10829 | 773 | if (objc != 4) { |
| 774 | Tcl_WrongNumArgs(interp, 2, objv, "account name"); | |
| 6694 | 775 | return TCL_ERROR; |
| 776 | } | |
| 777 | account = NULL; | |
| 13812 | 778 | if ((account = tcl_validate_account(objv[2], interp)) == NULL) |
| 10829 | 779 | return TCL_ERROR; |
| 15884 | 780 | convo = purple_find_conversation_with_account(PURPLE_CONV_TYPE_ANY, |
| 10829 | 781 | Tcl_GetString(objv[3]), |
| 782 | account); | |
| 15884 | 783 | Tcl_SetObjResult(interp, purple_tcl_ref_new(PurpleTclRefConversation, convo)); |
| 6694 | 784 | break; |
| 785 | case CMD_CONV_HANDLE: | |
| 786 | if (objc != 2) { | |
| 787 | Tcl_WrongNumArgs(interp, 2, objv, ""); | |
| 788 | return TCL_ERROR; | |
| 789 | } | |
|
20393
6280efb8c658
Another fabulous patch to our Tcl loader from venks on irc.freenode.net.
Ethan Blanton <elb@pidgin.im>
parents:
19859
diff
changeset
|
790 | Tcl_SetObjResult(interp, |
|
6280efb8c658
Another fabulous patch to our Tcl loader from venks on irc.freenode.net.
Ethan Blanton <elb@pidgin.im>
parents:
19859
diff
changeset
|
791 | purple_tcl_ref_new(PurpleTclRefHandle, |
|
6280efb8c658
Another fabulous patch to our Tcl loader from venks on irc.freenode.net.
Ethan Blanton <elb@pidgin.im>
parents:
19859
diff
changeset
|
792 | purple_conversations_get_handle())); |
| 6694 | 793 | break; |
| 794 | case CMD_CONV_LIST: | |
| 795 | list = Tcl_NewListObj(0, NULL); | |
| 15884 | 796 | for (cur = purple_get_conversations(); cur != NULL; cur = g_list_next(cur)) { |
| 797 | elem = purple_tcl_ref_new(PurpleTclRefConversation, cur->data); | |
| 6694 | 798 | Tcl_ListObjAppendElement(interp, list, elem); |
| 799 | } | |
| 800 | Tcl_SetObjResult(interp, list); | |
| 801 | break; | |
| 802 | case CMD_CONV_NEW: | |
| 803 | if (objc < 4) { | |
| 804 | Tcl_WrongNumArgs(interp, 2, objv, "?options? account name"); | |
| 805 | return TCL_ERROR; | |
| 806 | } | |
| 807 | argsused = 2; | |
| 15884 | 808 | type = PURPLE_CONV_TYPE_IM; |
| 6694 | 809 | while (argsused < objc) { |
| 810 | opt = Tcl_GetString(objv[argsused]); | |
| 811 | if (*opt == '-') { | |
| 812 | if ((error = Tcl_GetIndexFromObj(interp, objv[argsused], newopts, | |
| 813 | "option", 0, (int *)&newopt)) != TCL_OK) | |
| 814 | return error; | |
| 815 | argsused++; | |
| 816 | switch (newopt) { | |
| 817 | case CMD_CONV_NEW_CHAT: | |
| 15884 | 818 | type = PURPLE_CONV_TYPE_CHAT; |
| 6694 | 819 | break; |
| 820 | case CMD_CONV_NEW_IM: | |
| 15884 | 821 | type = PURPLE_CONV_TYPE_IM; |
| 6694 | 822 | break; |
| 823 | } | |
| 824 | } else { | |
| 825 | break; | |
| 826 | } | |
| 827 | } | |
| 828 | if (objc - argsused != 2) { | |
| 829 | Tcl_WrongNumArgs(interp, 2, objv, "?options? account name"); | |
| 830 | return TCL_ERROR; | |
| 831 | } | |
| 13812 | 832 | if ((account = tcl_validate_account(objv[argsused++], interp)) == NULL) |
| 6694 | 833 | return TCL_ERROR; |
| 15884 | 834 | convo = purple_conversation_new(type, account, Tcl_GetString(objv[argsused])); |
| 835 | Tcl_SetObjResult(interp, purple_tcl_ref_new(PurpleTclRefConversation, convo)); | |
| 6694 | 836 | break; |
| 837 | case CMD_CONV_WRITE: | |
| 838 | if (objc != 6) { | |
| 839 | Tcl_WrongNumArgs(interp, 2, objv, "conversation style from what"); | |
| 840 | return TCL_ERROR; | |
| 841 | } | |
| 13812 | 842 | if ((convo = tcl_validate_conversation(objv[2], interp)) == NULL) |
| 843 | return TCL_ERROR; | |
| 6694 | 844 | if ((error = Tcl_GetIndexFromObj(interp, objv[3], styles, "style", 0, (int *)&style)) != TCL_OK) |
| 845 | return error; | |
| 846 | from = Tcl_GetString(objv[4]); | |
| 847 | what = Tcl_GetString(objv[5]); | |
| 848 | ||
| 849 | switch (style) { | |
| 850 | case CMD_CONV_WRITE_SEND: | |
| 15884 | 851 | flags = PURPLE_MESSAGE_SEND; |
| 6694 | 852 | break; |
| 853 | case CMD_CONV_WRITE_RECV: | |
| 15884 | 854 | flags = PURPLE_MESSAGE_RECV; |
| 6694 | 855 | break; |
| 856 | case CMD_CONV_WRITE_SYSTEM: | |
| 15884 | 857 | flags = PURPLE_MESSAGE_SYSTEM; |
| 6694 | 858 | break; |
| 859 | } | |
| 15884 | 860 | if (purple_conversation_get_type(convo) == PURPLE_CONV_TYPE_CHAT) |
| 861 | purple_conv_chat_write(PURPLE_CONV_CHAT(convo), from, what, flags, time(NULL)); | |
| 6694 | 862 | else |
| 15884 | 863 | purple_conv_im_write(PURPLE_CONV_IM(convo), from, what, flags, time(NULL)); |
| 6694 | 864 | break; |
| 14357 | 865 | case CMD_CONV_NAME: |
| 866 | if (objc != 3) { | |
| 867 | Tcl_WrongNumArgs(interp, 2, objv, "conversation"); | |
| 868 | return TCL_ERROR; | |
| 869 | } | |
| 870 | ||
| 871 | if ((convo = tcl_validate_conversation(objv[2], interp)) == NULL) | |
| 872 | return TCL_ERROR; | |
|
20394
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
873 | Tcl_SetObjResult(interp, |
|
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
874 | Tcl_NewStringObj((char *)purple_conversation_get_name(convo), -1)); |
| 14357 | 875 | break; |
| 876 | case CMD_CONV_TITLE: | |
| 877 | if (objc != 3) { | |
| 878 | Tcl_WrongNumArgs(interp, 2, objv, "conversation"); | |
| 879 | return TCL_ERROR; | |
| 880 | } | |
| 881 | ||
| 882 | if ((convo = tcl_validate_conversation(objv[2], interp)) == NULL) | |
| 883 | return TCL_ERROR; | |
|
20394
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
884 | Tcl_SetObjResult(interp, |
|
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
885 | Tcl_NewStringObj((char *)purple_conversation_get_title(convo), -1)); |
| 14357 | 886 | break; |
| 14425 | 887 | case CMD_CONV_SEND: |
| 888 | if (objc != 4) { | |
| 889 | Tcl_WrongNumArgs(interp, 2, objv, "conversation message"); | |
| 890 | return TCL_ERROR; | |
| 891 | } | |
| 892 | if ((convo = tcl_validate_conversation(objv[2], interp)) == NULL) | |
| 893 | return TCL_ERROR; | |
| 894 | what = Tcl_GetString(objv[3]); | |
| 15884 | 895 | if (purple_conversation_get_type(convo) == PURPLE_CONV_TYPE_CHAT) |
| 896 | purple_conv_chat_send(PURPLE_CONV_CHAT(convo), what); | |
| 14425 | 897 | else |
| 15884 | 898 | purple_conv_im_send(PURPLE_CONV_IM(convo), what); |
| 14425 | 899 | break; |
| 6694 | 900 | } |
| 901 | ||
| 902 | return TCL_OK; | |
| 903 | } | |
| 904 | ||
| 905 | int tcl_cmd_core(ClientData unused, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) | |
| 906 | { | |
|
10339
246feba79f04
[gaim-migrate @ 11548]
Mark Doliner <markdoliner@pidgin.im>
parents:
10246
diff
changeset
|
907 | const char *cmds[] = { "handle", "quit", NULL }; |
| 6694 | 908 | enum { CMD_CORE_HANDLE, CMD_CORE_QUIT } cmd; |
| 909 | int error; | |
| 910 | ||
| 911 | if (objc < 2) { | |
| 912 | Tcl_WrongNumArgs(interp, 1, objv, "subcommand ?args?"); | |
| 913 | return TCL_ERROR; | |
| 914 | } | |
| 915 | ||
| 916 | if ((error = Tcl_GetIndexFromObj(interp, objv[1], cmds, "subcommand", 0, (int *)&cmd)) != TCL_OK) | |
| 917 | return error; | |
| 918 | ||
| 919 | switch (cmd) { | |
| 920 | case CMD_CORE_HANDLE: | |
| 921 | if (objc != 2) { | |
| 922 | Tcl_WrongNumArgs(interp, 2, objv, ""); | |
| 923 | return TCL_ERROR; | |
| 924 | } | |
|
20393
6280efb8c658
Another fabulous patch to our Tcl loader from venks on irc.freenode.net.
Ethan Blanton <elb@pidgin.im>
parents:
19859
diff
changeset
|
925 | Tcl_SetObjResult(interp, |
|
6280efb8c658
Another fabulous patch to our Tcl loader from venks on irc.freenode.net.
Ethan Blanton <elb@pidgin.im>
parents:
19859
diff
changeset
|
926 | purple_tcl_ref_new(PurpleTclRefHandle, |
|
6280efb8c658
Another fabulous patch to our Tcl loader from venks on irc.freenode.net.
Ethan Blanton <elb@pidgin.im>
parents:
19859
diff
changeset
|
927 | purple_get_core())); |
| 6694 | 928 | break; |
| 929 | case CMD_CORE_QUIT: | |
| 930 | if (objc != 2) { | |
| 931 | Tcl_WrongNumArgs(interp, 2, objv, ""); | |
| 932 | return TCL_ERROR; | |
| 933 | } | |
| 15884 | 934 | purple_core_quit(); |
| 6694 | 935 | break; |
| 936 | } | |
| 937 | ||
| 938 | return TCL_OK; | |
| 939 | } | |
| 940 | ||
| 941 | int tcl_cmd_debug(ClientData unused, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) | |
| 942 | { | |
| 943 | char *category, *message; | |
| 944 | int lev; | |
|
10339
246feba79f04
[gaim-migrate @ 11548]
Mark Doliner <markdoliner@pidgin.im>
parents:
10246
diff
changeset
|
945 | const char *levels[] = { "-misc", "-info", "-warning", "-error", NULL }; |
| 15884 | 946 | PurpleDebugLevel levelind[] = { PURPLE_DEBUG_MISC, PURPLE_DEBUG_INFO, PURPLE_DEBUG_WARNING, PURPLE_DEBUG_ERROR }; |
| 6694 | 947 | int error; |
| 948 | ||
| 949 | if (objc != 4) { | |
| 950 | Tcl_WrongNumArgs(interp, 1, objv, "level category message"); | |
| 951 | return TCL_ERROR; | |
| 952 | } | |
| 953 | ||
| 954 | error = Tcl_GetIndexFromObj(interp, objv[1], levels, "debug level", 0, &lev); | |
| 955 | if (error != TCL_OK) | |
| 956 | return error; | |
| 957 | ||
| 958 | category = Tcl_GetString(objv[2]); | |
| 959 | message = Tcl_GetString(objv[3]); | |
| 960 | ||
| 15884 | 961 | purple_debug(levelind[lev], category, "%s\n", message); |
| 6694 | 962 | |
| 963 | return TCL_OK; | |
| 964 | } | |
| 965 | ||
| 966 | int tcl_cmd_notify(ClientData unused, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) | |
| 967 | { | |
| 968 | int error, type; | |
|
10339
246feba79f04
[gaim-migrate @ 11548]
Mark Doliner <markdoliner@pidgin.im>
parents:
10246
diff
changeset
|
969 | const char *opts[] = { "-error", "-warning", "-info", NULL }; |
| 15884 | 970 | PurpleNotifyMsgType optind[] = { PURPLE_NOTIFY_MSG_ERROR, PURPLE_NOTIFY_MSG_WARNING, PURPLE_NOTIFY_MSG_INFO }; |
| 6694 | 971 | char *title, *msg1, *msg2; |
| 972 | ||
| 973 | if (objc < 4 || objc > 5) { | |
| 974 | Tcl_WrongNumArgs(interp, 1, objv, "?type? title primary secondary"); | |
| 975 | return TCL_ERROR; | |
| 976 | } | |
| 977 | ||
| 978 | if (objc == 4) { | |
| 13424 | 979 | type = 1; /* Default to warning */ |
| 6694 | 980 | title = Tcl_GetString(objv[1]); |
| 981 | msg1 = Tcl_GetString(objv[2]); | |
| 982 | msg2 = Tcl_GetString(objv[3]); | |
| 983 | } else { | |
| 984 | error = Tcl_GetIndexFromObj(interp, objv[1], opts, "message type", 0, &type); | |
| 985 | if (error != TCL_OK) | |
| 986 | return error; | |
| 987 | title = Tcl_GetString(objv[2]); | |
| 988 | msg1 = Tcl_GetString(objv[3]); | |
| 989 | msg2 = Tcl_GetString(objv[4]); | |
| 990 | } | |
| 991 | ||
| 15884 | 992 | purple_notify_message(_tcl_plugin, optind[type], title, msg1, msg2, NULL, NULL); |
| 6694 | 993 | |
| 994 | return TCL_OK; | |
| 995 | } | |
| 996 | ||
|
15750
c238e0966eb1
gaim::plugin Tcl command, thanks to Dossy Shiobara
Ethan Blanton <elb@pidgin.im>
parents:
15435
diff
changeset
|
997 | int tcl_cmd_plugins(ClientData unused, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) |
|
c238e0966eb1
gaim::plugin Tcl command, thanks to Dossy Shiobara
Ethan Blanton <elb@pidgin.im>
parents:
15435
diff
changeset
|
998 | { |
|
c238e0966eb1
gaim::plugin Tcl command, thanks to Dossy Shiobara
Ethan Blanton <elb@pidgin.im>
parents:
15435
diff
changeset
|
999 | const char *cmds[] = { "handle", NULL }; |
|
c238e0966eb1
gaim::plugin Tcl command, thanks to Dossy Shiobara
Ethan Blanton <elb@pidgin.im>
parents:
15435
diff
changeset
|
1000 | enum { CMD_PLUGINS_HANDLE } cmd; |
|
c238e0966eb1
gaim::plugin Tcl command, thanks to Dossy Shiobara
Ethan Blanton <elb@pidgin.im>
parents:
15435
diff
changeset
|
1001 | int error; |
|
c238e0966eb1
gaim::plugin Tcl command, thanks to Dossy Shiobara
Ethan Blanton <elb@pidgin.im>
parents:
15435
diff
changeset
|
1002 | |
|
c238e0966eb1
gaim::plugin Tcl command, thanks to Dossy Shiobara
Ethan Blanton <elb@pidgin.im>
parents:
15435
diff
changeset
|
1003 | if (objc < 2) { |
|
c238e0966eb1
gaim::plugin Tcl command, thanks to Dossy Shiobara
Ethan Blanton <elb@pidgin.im>
parents:
15435
diff
changeset
|
1004 | Tcl_WrongNumArgs(interp, 1, objv, "subcommand ?args?"); |
|
c238e0966eb1
gaim::plugin Tcl command, thanks to Dossy Shiobara
Ethan Blanton <elb@pidgin.im>
parents:
15435
diff
changeset
|
1005 | return TCL_ERROR; |
|
c238e0966eb1
gaim::plugin Tcl command, thanks to Dossy Shiobara
Ethan Blanton <elb@pidgin.im>
parents:
15435
diff
changeset
|
1006 | } |
|
c238e0966eb1
gaim::plugin Tcl command, thanks to Dossy Shiobara
Ethan Blanton <elb@pidgin.im>
parents:
15435
diff
changeset
|
1007 | |
|
c238e0966eb1
gaim::plugin Tcl command, thanks to Dossy Shiobara
Ethan Blanton <elb@pidgin.im>
parents:
15435
diff
changeset
|
1008 | if ((error = Tcl_GetIndexFromObj(interp, objv[1], cmds, "subcommand", 0, (int *)&cmd)) != TCL_OK) |
|
c238e0966eb1
gaim::plugin Tcl command, thanks to Dossy Shiobara
Ethan Blanton <elb@pidgin.im>
parents:
15435
diff
changeset
|
1009 | return error; |
|
c238e0966eb1
gaim::plugin Tcl command, thanks to Dossy Shiobara
Ethan Blanton <elb@pidgin.im>
parents:
15435
diff
changeset
|
1010 | |
|
c238e0966eb1
gaim::plugin Tcl command, thanks to Dossy Shiobara
Ethan Blanton <elb@pidgin.im>
parents:
15435
diff
changeset
|
1011 | switch (cmd) { |
|
c238e0966eb1
gaim::plugin Tcl command, thanks to Dossy Shiobara
Ethan Blanton <elb@pidgin.im>
parents:
15435
diff
changeset
|
1012 | case CMD_PLUGINS_HANDLE: |
|
c238e0966eb1
gaim::plugin Tcl command, thanks to Dossy Shiobara
Ethan Blanton <elb@pidgin.im>
parents:
15435
diff
changeset
|
1013 | if (objc != 2) { |
|
c238e0966eb1
gaim::plugin Tcl command, thanks to Dossy Shiobara
Ethan Blanton <elb@pidgin.im>
parents:
15435
diff
changeset
|
1014 | Tcl_WrongNumArgs(interp, 2, objv, ""); |
|
c238e0966eb1
gaim::plugin Tcl command, thanks to Dossy Shiobara
Ethan Blanton <elb@pidgin.im>
parents:
15435
diff
changeset
|
1015 | return TCL_ERROR; |
|
c238e0966eb1
gaim::plugin Tcl command, thanks to Dossy Shiobara
Ethan Blanton <elb@pidgin.im>
parents:
15435
diff
changeset
|
1016 | } |
|
20393
6280efb8c658
Another fabulous patch to our Tcl loader from venks on irc.freenode.net.
Ethan Blanton <elb@pidgin.im>
parents:
19859
diff
changeset
|
1017 | Tcl_SetObjResult(interp, |
|
6280efb8c658
Another fabulous patch to our Tcl loader from venks on irc.freenode.net.
Ethan Blanton <elb@pidgin.im>
parents:
19859
diff
changeset
|
1018 | purple_tcl_ref_new(PurpleTclRefHandle, |
|
6280efb8c658
Another fabulous patch to our Tcl loader from venks on irc.freenode.net.
Ethan Blanton <elb@pidgin.im>
parents:
19859
diff
changeset
|
1019 | purple_plugins_get_handle())); |
|
15750
c238e0966eb1
gaim::plugin Tcl command, thanks to Dossy Shiobara
Ethan Blanton <elb@pidgin.im>
parents:
15435
diff
changeset
|
1020 | break; |
|
c238e0966eb1
gaim::plugin Tcl command, thanks to Dossy Shiobara
Ethan Blanton <elb@pidgin.im>
parents:
15435
diff
changeset
|
1021 | } |
|
c238e0966eb1
gaim::plugin Tcl command, thanks to Dossy Shiobara
Ethan Blanton <elb@pidgin.im>
parents:
15435
diff
changeset
|
1022 | |
|
c238e0966eb1
gaim::plugin Tcl command, thanks to Dossy Shiobara
Ethan Blanton <elb@pidgin.im>
parents:
15435
diff
changeset
|
1023 | return TCL_OK; |
|
c238e0966eb1
gaim::plugin Tcl command, thanks to Dossy Shiobara
Ethan Blanton <elb@pidgin.im>
parents:
15435
diff
changeset
|
1024 | } |
|
c238e0966eb1
gaim::plugin Tcl command, thanks to Dossy Shiobara
Ethan Blanton <elb@pidgin.im>
parents:
15435
diff
changeset
|
1025 | |
| 6694 | 1026 | int tcl_cmd_prefs(ClientData unused, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) |
| 1027 | { | |
|
20394
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
1028 | Tcl_Obj *list, *elem, **elems; |
|
10339
246feba79f04
[gaim-migrate @ 11548]
Mark Doliner <markdoliner@pidgin.im>
parents:
10246
diff
changeset
|
1029 | const char *cmds[] = { "get", "set", "type", NULL }; |
| 6694 | 1030 | enum { CMD_PREFS_GET, CMD_PREFS_SET, CMD_PREFS_TYPE } cmd; |
| 1031 | /* char *types[] = { "none", "boolean", "int", "string", "stringlist", NULL }; */ | |
| 1032 | /* enum { TCL_PREFS_NONE, TCL_PREFS_BOOL, TCL_PREFS_INT, TCL_PREFS_STRING, TCL_PREFS_STRINGLIST } type; */ | |
| 15884 | 1033 | PurplePrefType preftype; |
| 6694 | 1034 | GList *cur; |
| 1035 | int error, intval, nelem, i; | |
| 1036 | ||
| 1037 | if (objc < 2) { | |
| 1038 | Tcl_WrongNumArgs(interp, 1, objv, "subcommand ?args?"); | |
| 1039 | return TCL_ERROR; | |
| 1040 | } | |
| 1041 | ||
| 1042 | if ((error = Tcl_GetIndexFromObj(interp, objv[1], cmds, "subcommand", 0, (int *)&cmd)) != TCL_OK) | |
| 1043 | return error; | |
| 1044 | ||
| 1045 | switch (cmd) { | |
| 1046 | case CMD_PREFS_GET: | |
| 1047 | if (objc != 3) { | |
| 1048 | Tcl_WrongNumArgs(interp, 1, objv, "path"); | |
| 1049 | return TCL_ERROR; | |
| 1050 | } | |
| 15884 | 1051 | preftype = purple_prefs_get_type(Tcl_GetString(objv[2])); |
| 6694 | 1052 | switch (preftype) { |
| 15884 | 1053 | case PURPLE_PREF_NONE: |
|
20394
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
1054 | Tcl_SetObjResult(interp, |
|
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
1055 | Tcl_NewStringObj("pref type none", -1)); |
| 6694 | 1056 | return TCL_ERROR; |
| 1057 | break; | |
| 15884 | 1058 | case PURPLE_PREF_BOOLEAN: |
|
20394
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
1059 | Tcl_SetObjResult(interp, |
|
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
1060 | Tcl_NewBooleanObj( |
|
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
1061 | purple_prefs_get_bool(Tcl_GetString(objv[2])))); |
| 6694 | 1062 | break; |
| 15884 | 1063 | case PURPLE_PREF_INT: |
|
20394
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
1064 | Tcl_SetObjResult(interp, Tcl_NewIntObj(purple_prefs_get_int(Tcl_GetString(objv[2])))); |
| 6694 | 1065 | break; |
| 15884 | 1066 | case PURPLE_PREF_STRING: |
|
20394
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
1067 | Tcl_SetObjResult(interp, |
|
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
1068 | Tcl_NewStringObj((char *)purple_prefs_get_string(Tcl_GetString(objv[2])), -1)); |
| 6694 | 1069 | break; |
| 15884 | 1070 | case PURPLE_PREF_STRING_LIST: |
| 1071 | cur = purple_prefs_get_string_list(Tcl_GetString(objv[2])); | |
| 6694 | 1072 | list = Tcl_NewListObj(0, NULL); |
| 1073 | while (cur != NULL) { | |
| 1074 | elem = Tcl_NewStringObj((char *)cur->data, -1); | |
| 1075 | Tcl_ListObjAppendElement(interp, list, elem); | |
|
22240
3f3d4ff9f323
disapproval of revision 'b2c07c730315e96101dd0371133d170396333f4c'
Etan Reisner <deryni@pidgin.im>
parents:
22239
diff
changeset
|
1076 | cur = g_list_next(cur); |
| 6694 | 1077 | } |
| 1078 | Tcl_SetObjResult(interp, list); | |
| 1079 | break; | |
| 1080 | default: | |
| 15884 | 1081 | purple_debug(PURPLE_DEBUG_ERROR, "tcl", "tcl does not know about pref type %d\n", preftype); |
|
20394
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
1082 | Tcl_SetObjResult(interp, |
|
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
1083 | Tcl_NewStringObj("unknown pref type", -1)); |
| 6694 | 1084 | return TCL_ERROR; |
| 1085 | } | |
| 1086 | break; | |
| 1087 | case CMD_PREFS_SET: | |
| 1088 | if (objc != 4) { | |
| 1089 | Tcl_WrongNumArgs(interp, 1, objv, "path value"); | |
| 1090 | return TCL_ERROR; | |
| 1091 | } | |
| 15884 | 1092 | preftype = purple_prefs_get_type(Tcl_GetString(objv[2])); |
| 6694 | 1093 | switch (preftype) { |
| 15884 | 1094 | case PURPLE_PREF_NONE: |
|
20394
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
1095 | Tcl_SetObjResult(interp, |
|
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
1096 | Tcl_NewStringObj("bad path or pref type none", -1)); |
| 6694 | 1097 | return TCL_ERROR; |
| 1098 | break; | |
| 15884 | 1099 | case PURPLE_PREF_BOOLEAN: |
| 6694 | 1100 | if ((error = Tcl_GetBooleanFromObj(interp, objv[3], &intval)) != TCL_OK) |
| 1101 | return error; | |
| 15884 | 1102 | purple_prefs_set_bool(Tcl_GetString(objv[2]), intval); |
| 6694 | 1103 | break; |
| 15884 | 1104 | case PURPLE_PREF_INT: |
| 6694 | 1105 | if ((error = Tcl_GetIntFromObj(interp, objv[3], &intval)) != TCL_OK) |
| 1106 | return error; | |
| 15884 | 1107 | purple_prefs_set_int(Tcl_GetString(objv[2]), intval); |
| 6694 | 1108 | break; |
| 15884 | 1109 | case PURPLE_PREF_STRING: |
| 1110 | purple_prefs_set_string(Tcl_GetString(objv[2]), Tcl_GetString(objv[3])); | |
| 6694 | 1111 | break; |
| 15884 | 1112 | case PURPLE_PREF_STRING_LIST: |
| 6694 | 1113 | if ((error = Tcl_ListObjGetElements(interp, objv[3], &nelem, &elems)) != TCL_OK) |
| 1114 | return error; | |
| 1115 | cur = NULL; | |
| 1116 | for (i = 0; i < nelem; i++) { | |
| 1117 | cur = g_list_append(cur, (gpointer)Tcl_GetString(elems[i])); | |
| 1118 | } | |
| 15884 | 1119 | purple_prefs_set_string_list(Tcl_GetString(objv[2]), cur); |
| 6694 | 1120 | g_list_free(cur); |
| 1121 | break; | |
| 1122 | default: | |
| 15884 | 1123 | purple_debug(PURPLE_DEBUG_ERROR, "tcl", "tcl does not know about pref type %d\n", preftype); |
| 6694 | 1124 | return TCL_ERROR; |
| 1125 | } | |
| 1126 | break; | |
| 1127 | case CMD_PREFS_TYPE: | |
| 1128 | if (objc != 3) { | |
| 1129 | Tcl_WrongNumArgs(interp, 1, objv, "path"); | |
| 1130 | return TCL_ERROR; | |
| 1131 | } | |
| 15884 | 1132 | preftype = purple_prefs_get_type(Tcl_GetString(objv[2])); |
| 6694 | 1133 | switch (preftype) { |
| 15884 | 1134 | case PURPLE_PREF_NONE: |
|
20394
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
1135 | Tcl_SetObjResult(interp, Tcl_NewStringObj("none", -1)); |
| 6694 | 1136 | break; |
| 15884 | 1137 | case PURPLE_PREF_BOOLEAN: |
|
20394
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
1138 | Tcl_SetObjResult(interp, Tcl_NewStringObj("boolean", -1)); |
| 6694 | 1139 | break; |
| 15884 | 1140 | case PURPLE_PREF_INT: |
|
20394
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
1141 | Tcl_SetObjResult(interp, Tcl_NewStringObj("int", -1)); |
| 6694 | 1142 | break; |
| 15884 | 1143 | case PURPLE_PREF_STRING: |
|
20394
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
1144 | Tcl_SetObjResult(interp, Tcl_NewStringObj("string", -1)); |
| 6694 | 1145 | break; |
| 15884 | 1146 | case PURPLE_PREF_STRING_LIST: |
|
20394
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
1147 | Tcl_SetObjResult(interp, Tcl_NewStringObj("stringlist", -1)); |
| 6694 | 1148 | break; |
| 1149 | default: | |
| 15884 | 1150 | purple_debug(PURPLE_DEBUG_ERROR, "tcl", "tcl does not know about pref type %d\n", preftype); |
|
20394
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
1151 | Tcl_SetObjResult(interp, Tcl_NewStringObj("unknown", -1)); |
| 6694 | 1152 | } |
| 1153 | break; | |
| 1154 | } | |
| 1155 | ||
| 1156 | return TCL_OK; | |
| 1157 | } | |
| 1158 | ||
| 13823 | 1159 | int tcl_cmd_presence(ClientData unused, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) |
| 1160 | { | |
| 1161 | const char *cmds[] = { "account", "active_status", "available", | |
| 1162 | "chat_user", "context", "conversation", "idle", | |
| 1163 | "login", "online", "status", "statuses", NULL }; | |
| 1164 | enum { CMD_PRESENCE_ACCOUNT, CMD_PRESENCE_ACTIVE_STATUS, | |
| 1165 | CMD_PRESENCE_AVAILABLE, CMD_PRESENCE_CHAT_USER, | |
| 1166 | CMD_PRESENCE_CONTEXT, CMD_PRESENCE_CONVERSATION, | |
| 1167 | CMD_PRESENCE_IDLE, CMD_PRESENCE_LOGIN, CMD_PRESENCE_ONLINE, | |
| 1168 | CMD_PRESENCE_STATUS, CMD_PRESENCE_STATUSES } cmd; | |
|
20394
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
1169 | Tcl_Obj *result; |
| 13823 | 1170 | Tcl_Obj *list, *elem; |
| 15884 | 1171 | PurplePresence *presence; |
|
18190
bcf28ef7e8ff
Re-fix the DBus list handling code by killing const GList* / const GSList*
Richard Laager <rlaager@pidgin.im>
parents:
18122
diff
changeset
|
1172 | GList *cur; |
| 13823 | 1173 | int error, idle, idle_time, login_time; |
| 1174 | ||
| 1175 | if (objc < 2) { | |
| 1176 | Tcl_WrongNumArgs(interp, 1, objv, "subcommand ?args?"); | |
| 1177 | return TCL_ERROR; | |
| 1178 | } | |
| 1179 | ||
| 1180 | if ((error = Tcl_GetIndexFromObj(interp, objv[1], cmds, "subcommand", 0, (int *)&cmd)) != TCL_OK) | |
| 1181 | return error; | |
| 1182 | ||
| 1183 | switch (cmd) { | |
| 1184 | case CMD_PRESENCE_ACCOUNT: | |
| 1185 | if (objc != 3) { | |
| 1186 | Tcl_WrongNumArgs(interp, 2, objv, "presence"); | |
| 1187 | return TCL_ERROR; | |
| 1188 | } | |
| 15884 | 1189 | if ((presence = purple_tcl_ref_get(interp, objv[2], PurpleTclRefPresence)) == NULL) |
| 13823 | 1190 | return TCL_ERROR; |
| 15884 | 1191 | Tcl_SetObjResult(interp, purple_tcl_ref_new(PurpleTclRefAccount, |
| 1192 | purple_presence_get_account(presence))); | |
| 13823 | 1193 | break; |
| 1194 | case CMD_PRESENCE_ACTIVE_STATUS: | |
| 1195 | if (objc != 3 && objc != 4 && objc != 5) { | |
| 1196 | Tcl_WrongNumArgs(interp, 2, objv, "presence [?status_id? | ?-primitive primitive?]"); | |
| 1197 | return TCL_ERROR; | |
| 1198 | } | |
| 15884 | 1199 | if ((presence = purple_tcl_ref_get(interp, objv[2], PurpleTclRefPresence)) == NULL) |
| 13823 | 1200 | return TCL_ERROR; |
| 1201 | if (objc == 3) { | |
| 1202 | Tcl_SetObjResult(interp, | |
| 15884 | 1203 | purple_tcl_ref_new(PurpleTclRefStatus, |
| 1204 | purple_presence_get_active_status(presence))); | |
| 13823 | 1205 | } else if (objc == 4) { |
|
20394
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
1206 | Tcl_SetObjResult(interp, |
|
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
1207 | Tcl_NewBooleanObj( |
|
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
1208 | purple_presence_is_status_active(presence, |
|
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
1209 | Tcl_GetString(objv[3])))); |
| 13823 | 1210 | } else { |
| 15884 | 1211 | PurpleStatusPrimitive primitive; |
| 13823 | 1212 | if (strcmp(Tcl_GetString(objv[3]), "-primitive")) { |
|
20394
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
1213 | result = Tcl_NewStringObj("bad option \"", -1); |
| 13823 | 1214 | Tcl_AppendObjToObj(result, objv[3]); |
| 1215 | Tcl_AppendToObj(result, | |
| 1216 | "\": should be -primitive", -1); | |
|
20394
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
1217 | Tcl_SetObjResult(interp,result); |
| 13823 | 1218 | return TCL_ERROR; |
| 1219 | } | |
| 15884 | 1220 | primitive = purple_primitive_get_type_from_id(Tcl_GetString(objv[4])); |
| 1221 | if (primitive == PURPLE_STATUS_UNSET) { | |
|
20394
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
1222 | result = Tcl_NewStringObj("invalid primitive ", -1); |
| 13823 | 1223 | Tcl_AppendObjToObj(result, objv[4]); |
|
20394
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
1224 | Tcl_SetObjResult(interp,result); |
| 13823 | 1225 | return TCL_ERROR; |
| 1226 | } | |
|
20394
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
1227 | Tcl_SetObjResult(interp, |
|
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
1228 | Tcl_NewBooleanObj( |
|
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
1229 | purple_presence_is_status_primitive_active(presence, primitive))); |
| 13823 | 1230 | break; |
| 1231 | } | |
| 1232 | break; | |
| 1233 | case CMD_PRESENCE_AVAILABLE: | |
| 1234 | if (objc != 3) { | |
| 1235 | Tcl_WrongNumArgs(interp, 2, objv, "presence"); | |
| 1236 | return TCL_ERROR; | |
| 1237 | } | |
| 15884 | 1238 | if ((presence = purple_tcl_ref_get(interp, objv[2], PurpleTclRefPresence)) == NULL) |
| 13823 | 1239 | return TCL_ERROR; |
|
20394
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
1240 | Tcl_SetObjResult(interp, |
|
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
1241 | Tcl_NewBooleanObj(purple_presence_is_available(presence))); |
| 13823 | 1242 | break; |
| 1243 | case CMD_PRESENCE_CHAT_USER: | |
| 1244 | if (objc != 3) { | |
| 1245 | Tcl_WrongNumArgs(interp, 2, objv, "presence"); | |
| 1246 | return TCL_ERROR; | |
| 1247 | } | |
| 15884 | 1248 | if ((presence = purple_tcl_ref_get(interp, objv[2], PurpleTclRefPresence)) == NULL) |
| 13823 | 1249 | return TCL_ERROR; |
|
20394
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
1250 | Tcl_SetObjResult(interp, |
|
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
1251 | Tcl_NewStringObj(purple_presence_get_chat_user(presence), -1)); |
| 13823 | 1252 | break; |
| 1253 | case CMD_PRESENCE_CONTEXT: | |
| 1254 | if (objc != 3) { | |
| 1255 | Tcl_WrongNumArgs(interp, 2, objv, "presence"); | |
| 1256 | return TCL_ERROR; | |
| 1257 | } | |
| 15884 | 1258 | if ((presence = purple_tcl_ref_get(interp, objv[2], PurpleTclRefPresence)) == NULL) |
| 13823 | 1259 | return TCL_ERROR; |
| 15884 | 1260 | switch (purple_presence_get_context(presence)) { |
| 1261 | case PURPLE_PRESENCE_CONTEXT_UNSET: | |
|
20394
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
1262 | Tcl_SetObjResult(interp, Tcl_NewStringObj("unset", -1)); |
| 13823 | 1263 | break; |
| 15884 | 1264 | case PURPLE_PRESENCE_CONTEXT_ACCOUNT: |
|
20394
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
1265 | Tcl_SetObjResult(interp, Tcl_NewStringObj("account", -1)); |
| 13823 | 1266 | break; |
| 15884 | 1267 | case PURPLE_PRESENCE_CONTEXT_CONV: |
|
20394
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
1268 | Tcl_SetObjResult(interp, Tcl_NewStringObj("conversation", -1)); |
| 13823 | 1269 | break; |
| 15884 | 1270 | case PURPLE_PRESENCE_CONTEXT_BUDDY: |
|
20394
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
1271 | Tcl_SetObjResult(interp, Tcl_NewStringObj("buddy", -1)); |
| 13823 | 1272 | break; |
| 1273 | } | |
| 1274 | break; | |
| 1275 | case CMD_PRESENCE_CONVERSATION: | |
| 1276 | if (objc != 3) { | |
| 1277 | Tcl_WrongNumArgs(interp, 2, objv, "presence"); | |
| 1278 | return TCL_ERROR; | |
| 1279 | } | |
| 15884 | 1280 | if ((presence = purple_tcl_ref_get(interp, objv[2], PurpleTclRefPresence)) == NULL) |
| 13823 | 1281 | return TCL_ERROR; |
| 15884 | 1282 | Tcl_SetObjResult(interp, purple_tcl_ref_new(PurpleTclRefConversation, |
| 1283 | purple_presence_get_conversation(presence))); | |
| 13823 | 1284 | break; |
| 1285 | case CMD_PRESENCE_IDLE: | |
| 1286 | if (objc < 3 || objc > 5) { | |
| 1287 | Tcl_WrongNumArgs(interp, 2, objv, "presence ?idle? ?time?"); | |
| 1288 | return TCL_ERROR; | |
| 1289 | } | |
| 15884 | 1290 | if ((presence = purple_tcl_ref_get(interp, objv[2], PurpleTclRefPresence)) == NULL) |
| 13823 | 1291 | return TCL_ERROR; |
| 1292 | if (objc == 3) { | |
| 15884 | 1293 | if (purple_presence_is_idle(presence)) { |
| 1294 | idle_time = purple_presence_get_idle_time (presence); | |
|
20394
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
1295 | Tcl_SetObjResult(interp, Tcl_NewIntObj(idle_time)); |
| 13823 | 1296 | } else { |
| 1297 | result = Tcl_NewListObj(0, NULL); | |
| 1298 | Tcl_SetObjResult(interp, result); | |
| 1299 | } | |
| 1300 | break; | |
| 1301 | } | |
| 1302 | if ((error = Tcl_GetBooleanFromObj(interp, objv[3], &idle)) != TCL_OK) | |
| 1303 | return TCL_ERROR; | |
| 1304 | if (objc == 4) { | |
| 15884 | 1305 | purple_presence_set_idle(presence, idle, time(NULL)); |
| 13823 | 1306 | } else if (objc == 5) { |
| 1307 | if ((error = Tcl_GetIntFromObj(interp, | |
| 1308 | objv[4], | |
| 1309 | &idle_time)) != TCL_OK) | |
| 1310 | return TCL_ERROR; | |
| 15884 | 1311 | purple_presence_set_idle(presence, idle, idle_time); |
| 13823 | 1312 | } |
| 1313 | break; | |
| 1314 | case CMD_PRESENCE_LOGIN: | |
| 1315 | if (objc != 3 && objc != 4) { | |
| 1316 | Tcl_WrongNumArgs(interp, 2, objv, "presence ?time?"); | |
| 1317 | return TCL_ERROR; | |
| 1318 | } | |
| 15884 | 1319 | if ((presence = purple_tcl_ref_get(interp, objv[2], PurpleTclRefPresence)) == NULL) |
| 13823 | 1320 | return TCL_ERROR; |
| 1321 | if (objc == 3) { | |
|
20394
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
1322 | Tcl_SetObjResult(interp, Tcl_NewIntObj(purple_presence_get_login_time(presence))); |
| 13823 | 1323 | } else { |
| 1324 | if ((error == Tcl_GetIntFromObj(interp, | |
| 1325 | objv[3], | |
| 1326 | &login_time)) != TCL_OK) | |
| 1327 | return TCL_ERROR; | |
| 15884 | 1328 | purple_presence_set_login_time(presence, login_time); |
| 13823 | 1329 | } |
| 1330 | break; | |
| 1331 | case CMD_PRESENCE_ONLINE: | |
| 1332 | if (objc != 3) { | |
| 1333 | Tcl_WrongNumArgs(interp, 2, objv, "presence"); | |
| 1334 | return TCL_ERROR; | |
| 1335 | } | |
| 15884 | 1336 | if ((presence = purple_tcl_ref_get(interp, objv[2], PurpleTclRefPresence)) == NULL) |
| 13823 | 1337 | return TCL_ERROR; |
|
20394
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
1338 | Tcl_SetObjResult(interp, |
|
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
1339 | Tcl_NewBooleanObj( |
|
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
1340 | purple_presence_is_online(presence))); |
| 13823 | 1341 | break; |
| 1342 | case CMD_PRESENCE_STATUS: | |
| 1343 | if (objc != 4) { | |
| 1344 | Tcl_WrongNumArgs(interp, 2, objv, "presence status_id"); | |
| 1345 | return TCL_ERROR; | |
| 1346 | } | |
| 15884 | 1347 | if ((presence = purple_tcl_ref_get(interp, objv[2], PurpleTclRefPresence)) == NULL) |
| 13823 | 1348 | return TCL_ERROR; |
| 1349 | Tcl_SetObjResult(interp, | |
| 15884 | 1350 | purple_tcl_ref_new(PurpleTclRefStatus, |
| 1351 | purple_presence_get_status(presence, | |
| 13823 | 1352 | Tcl_GetString(objv[3])))); |
| 1353 | break; | |
| 1354 | case CMD_PRESENCE_STATUSES: | |
| 1355 | if (objc != 3) { | |
| 1356 | Tcl_WrongNumArgs(interp, 2, objv, "presence"); | |
| 1357 | return TCL_ERROR; | |
| 1358 | } | |
| 15884 | 1359 | if ((presence = purple_tcl_ref_get(interp, objv[2], PurpleTclRefPresence)) == NULL) |
| 13823 | 1360 | return TCL_ERROR; |
| 1361 | list = Tcl_NewListObj(0, NULL); | |
| 15884 | 1362 | for (cur = purple_presence_get_statuses(presence); cur != NULL; |
| 13823 | 1363 | cur = g_list_next(cur)) { |
| 15884 | 1364 | elem = purple_tcl_ref_new(PurpleTclRefStatus, cur->data); |
| 13823 | 1365 | Tcl_ListObjAppendElement(interp, list, elem); |
| 1366 | } | |
| 1367 | Tcl_SetObjResult(interp, list); | |
| 1368 | break; | |
| 1369 | } | |
| 1370 | ||
| 1371 | return TCL_OK; | |
| 1372 | } | |
| 1373 | ||
|
15758
d31f3317c849
Tcl savedstatus command, again from Dossy Shiobara. Dossy is on fire.
Ethan Blanton <elb@pidgin.im>
parents:
15750
diff
changeset
|
1374 | int tcl_cmd_savedstatus(ClientData unused, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) |
|
d31f3317c849
Tcl savedstatus command, again from Dossy Shiobara. Dossy is on fire.
Ethan Blanton <elb@pidgin.im>
parents:
15750
diff
changeset
|
1375 | { |
|
20394
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
1376 | Tcl_Obj *result; |
|
15758
d31f3317c849
Tcl savedstatus command, again from Dossy Shiobara. Dossy is on fire.
Ethan Blanton <elb@pidgin.im>
parents:
15750
diff
changeset
|
1377 | const char *cmds[] = { "current", "handle", NULL }; |
|
d31f3317c849
Tcl savedstatus command, again from Dossy Shiobara. Dossy is on fire.
Ethan Blanton <elb@pidgin.im>
parents:
15750
diff
changeset
|
1378 | enum { CMD_SAVEDSTATUS_CURRENT, CMD_SAVEDSTATUS_HANDLE } cmd; |
|
d31f3317c849
Tcl savedstatus command, again from Dossy Shiobara. Dossy is on fire.
Ethan Blanton <elb@pidgin.im>
parents:
15750
diff
changeset
|
1379 | int error; |
| 15884 | 1380 | PurpleSavedStatus *saved_status; |
|
15758
d31f3317c849
Tcl savedstatus command, again from Dossy Shiobara. Dossy is on fire.
Ethan Blanton <elb@pidgin.im>
parents:
15750
diff
changeset
|
1381 | |
|
d31f3317c849
Tcl savedstatus command, again from Dossy Shiobara. Dossy is on fire.
Ethan Blanton <elb@pidgin.im>
parents:
15750
diff
changeset
|
1382 | if (objc < 2) { |
|
d31f3317c849
Tcl savedstatus command, again from Dossy Shiobara. Dossy is on fire.
Ethan Blanton <elb@pidgin.im>
parents:
15750
diff
changeset
|
1383 | Tcl_WrongNumArgs(interp, 1, objv, "subcommand ?args?"); |
|
d31f3317c849
Tcl savedstatus command, again from Dossy Shiobara. Dossy is on fire.
Ethan Blanton <elb@pidgin.im>
parents:
15750
diff
changeset
|
1384 | return TCL_ERROR; |
|
d31f3317c849
Tcl savedstatus command, again from Dossy Shiobara. Dossy is on fire.
Ethan Blanton <elb@pidgin.im>
parents:
15750
diff
changeset
|
1385 | } |
|
d31f3317c849
Tcl savedstatus command, again from Dossy Shiobara. Dossy is on fire.
Ethan Blanton <elb@pidgin.im>
parents:
15750
diff
changeset
|
1386 | |
|
d31f3317c849
Tcl savedstatus command, again from Dossy Shiobara. Dossy is on fire.
Ethan Blanton <elb@pidgin.im>
parents:
15750
diff
changeset
|
1387 | if ((error = Tcl_GetIndexFromObj(interp, objv[1], cmds, "subcommand", 0, (int *)&cmd)) != TCL_OK) |
|
d31f3317c849
Tcl savedstatus command, again from Dossy Shiobara. Dossy is on fire.
Ethan Blanton <elb@pidgin.im>
parents:
15750
diff
changeset
|
1388 | return error; |
|
d31f3317c849
Tcl savedstatus command, again from Dossy Shiobara. Dossy is on fire.
Ethan Blanton <elb@pidgin.im>
parents:
15750
diff
changeset
|
1389 | |
|
d31f3317c849
Tcl savedstatus command, again from Dossy Shiobara. Dossy is on fire.
Ethan Blanton <elb@pidgin.im>
parents:
15750
diff
changeset
|
1390 | switch (cmd) { |
|
d31f3317c849
Tcl savedstatus command, again from Dossy Shiobara. Dossy is on fire.
Ethan Blanton <elb@pidgin.im>
parents:
15750
diff
changeset
|
1391 | case CMD_SAVEDSTATUS_CURRENT: |
|
d31f3317c849
Tcl savedstatus command, again from Dossy Shiobara. Dossy is on fire.
Ethan Blanton <elb@pidgin.im>
parents:
15750
diff
changeset
|
1392 | if (objc != 2) { |
|
d31f3317c849
Tcl savedstatus command, again from Dossy Shiobara. Dossy is on fire.
Ethan Blanton <elb@pidgin.im>
parents:
15750
diff
changeset
|
1393 | Tcl_WrongNumArgs(interp, 2, objv, ""); |
|
d31f3317c849
Tcl savedstatus command, again from Dossy Shiobara. Dossy is on fire.
Ethan Blanton <elb@pidgin.im>
parents:
15750
diff
changeset
|
1394 | return TCL_ERROR; |
|
d31f3317c849
Tcl savedstatus command, again from Dossy Shiobara. Dossy is on fire.
Ethan Blanton <elb@pidgin.im>
parents:
15750
diff
changeset
|
1395 | } |
| 15884 | 1396 | if ((saved_status = purple_savedstatus_get_current()) == NULL) |
|
15758
d31f3317c849
Tcl savedstatus command, again from Dossy Shiobara. Dossy is on fire.
Ethan Blanton <elb@pidgin.im>
parents:
15750
diff
changeset
|
1397 | return TCL_ERROR; |
|
20394
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
1398 | result = Tcl_NewListObj(0, NULL); |
| 15884 | 1399 | Tcl_ListObjAppendElement(interp, result, Tcl_NewStringObj(purple_savedstatus_get_title(saved_status), -1)); |
| 1400 | Tcl_ListObjAppendElement(interp, result, Tcl_NewIntObj(purple_savedstatus_get_type(saved_status))); | |
| 1401 | Tcl_ListObjAppendElement(interp, result, Tcl_NewStringObj(purple_savedstatus_get_message(saved_status), -1)); | |
|
20394
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
1402 | Tcl_SetObjResult(interp,result); |
|
15758
d31f3317c849
Tcl savedstatus command, again from Dossy Shiobara. Dossy is on fire.
Ethan Blanton <elb@pidgin.im>
parents:
15750
diff
changeset
|
1403 | break; |
|
d31f3317c849
Tcl savedstatus command, again from Dossy Shiobara. Dossy is on fire.
Ethan Blanton <elb@pidgin.im>
parents:
15750
diff
changeset
|
1404 | case CMD_SAVEDSTATUS_HANDLE: |
|
d31f3317c849
Tcl savedstatus command, again from Dossy Shiobara. Dossy is on fire.
Ethan Blanton <elb@pidgin.im>
parents:
15750
diff
changeset
|
1405 | if (objc != 2) { |
|
d31f3317c849
Tcl savedstatus command, again from Dossy Shiobara. Dossy is on fire.
Ethan Blanton <elb@pidgin.im>
parents:
15750
diff
changeset
|
1406 | Tcl_WrongNumArgs(interp, 2, objv, ""); |
|
d31f3317c849
Tcl savedstatus command, again from Dossy Shiobara. Dossy is on fire.
Ethan Blanton <elb@pidgin.im>
parents:
15750
diff
changeset
|
1407 | return TCL_ERROR; |
|
d31f3317c849
Tcl savedstatus command, again from Dossy Shiobara. Dossy is on fire.
Ethan Blanton <elb@pidgin.im>
parents:
15750
diff
changeset
|
1408 | } |
|
20393
6280efb8c658
Another fabulous patch to our Tcl loader from venks on irc.freenode.net.
Ethan Blanton <elb@pidgin.im>
parents:
19859
diff
changeset
|
1409 | Tcl_SetObjResult(interp, |
|
6280efb8c658
Another fabulous patch to our Tcl loader from venks on irc.freenode.net.
Ethan Blanton <elb@pidgin.im>
parents:
19859
diff
changeset
|
1410 | purple_tcl_ref_new(PurpleTclRefHandle, |
|
6280efb8c658
Another fabulous patch to our Tcl loader from venks on irc.freenode.net.
Ethan Blanton <elb@pidgin.im>
parents:
19859
diff
changeset
|
1411 | purple_savedstatuses_get_handle())); |
|
15758
d31f3317c849
Tcl savedstatus command, again from Dossy Shiobara. Dossy is on fire.
Ethan Blanton <elb@pidgin.im>
parents:
15750
diff
changeset
|
1412 | break; |
|
d31f3317c849
Tcl savedstatus command, again from Dossy Shiobara. Dossy is on fire.
Ethan Blanton <elb@pidgin.im>
parents:
15750
diff
changeset
|
1413 | } |
|
d31f3317c849
Tcl savedstatus command, again from Dossy Shiobara. Dossy is on fire.
Ethan Blanton <elb@pidgin.im>
parents:
15750
diff
changeset
|
1414 | |
|
d31f3317c849
Tcl savedstatus command, again from Dossy Shiobara. Dossy is on fire.
Ethan Blanton <elb@pidgin.im>
parents:
15750
diff
changeset
|
1415 | return TCL_OK; |
|
d31f3317c849
Tcl savedstatus command, again from Dossy Shiobara. Dossy is on fire.
Ethan Blanton <elb@pidgin.im>
parents:
15750
diff
changeset
|
1416 | } |
|
d31f3317c849
Tcl savedstatus command, again from Dossy Shiobara. Dossy is on fire.
Ethan Blanton <elb@pidgin.im>
parents:
15750
diff
changeset
|
1417 | |
| 6694 | 1418 | int tcl_cmd_send_im(ClientData unused, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) |
| 1419 | { | |
| 15884 | 1420 | PurpleConnection *gc; |
| 6694 | 1421 | char *who, *text; |
| 1422 | ||
| 1423 | if (objc != 4) { | |
| 1424 | Tcl_WrongNumArgs(interp, 1, objv, "gc who text"); | |
| 1425 | return TCL_ERROR; | |
| 1426 | } | |
| 1427 | ||
| 13817 | 1428 | if ((gc = tcl_validate_gc(objv[1], interp)) == NULL) |
| 6694 | 1429 | return TCL_ERROR; |
| 1430 | ||
| 1431 | who = Tcl_GetString(objv[2]); | |
| 1432 | text = Tcl_GetString(objv[3]); | |
| 1433 | ||
|
6982
12f08de92674
[gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
6864
diff
changeset
|
1434 | serv_send_im(gc, who, text, 0); |
| 6694 | 1435 | |
| 1436 | return TCL_OK; | |
| 1437 | } | |
| 1438 | ||
| 1439 | int tcl_cmd_signal(ClientData unused, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) | |
| 1440 | { | |
|
10339
246feba79f04
[gaim-migrate @ 11548]
Mark Doliner <markdoliner@pidgin.im>
parents:
10246
diff
changeset
|
1441 | const char *cmds[] = { "connect", "disconnect", NULL }; |
| 6694 | 1442 | enum { CMD_SIGNAL_CONNECT, CMD_SIGNAL_DISCONNECT } cmd; |
| 1443 | struct tcl_signal_handler *handler; | |
| 1444 | void *instance; | |
| 10597 | 1445 | int error; |
| 6694 | 1446 | |
| 1447 | if (objc < 2) { | |
| 1448 | Tcl_WrongNumArgs(interp, 1, objv, "subcommand ?args?"); | |
| 1449 | return TCL_ERROR; | |
| 1450 | } | |
| 1451 | ||
| 1452 | if ((error = Tcl_GetIndexFromObj(interp, objv[1], cmds, "subcommand", 0, (int *)&cmd)) != TCL_OK) | |
| 1453 | return error; | |
| 1454 | ||
| 1455 | switch (cmd) { | |
| 1456 | case CMD_SIGNAL_CONNECT: | |
| 1457 | if (objc != 6) { | |
| 1458 | Tcl_WrongNumArgs(interp, 2, objv, "instance signal args proc"); | |
| 1459 | return TCL_ERROR; | |
| 1460 | } | |
| 1461 | handler = g_new0(struct tcl_signal_handler, 1); | |
|
20393
6280efb8c658
Another fabulous patch to our Tcl loader from venks on irc.freenode.net.
Ethan Blanton <elb@pidgin.im>
parents:
19859
diff
changeset
|
1462 | if ((handler->instance = purple_tcl_ref_get(interp, objv[2],PurpleTclRefHandle)) == NULL) { |
| 6694 | 1463 | g_free(handler); |
| 1464 | return error; | |
| 1465 | } | |
| 10597 | 1466 | handler->signal = objv[3]; |
| 13812 | 1467 | Tcl_IncrRefCount(handler->signal); |
| 10597 | 1468 | handler->args = objv[4]; |
| 1469 | handler->proc = objv[5]; | |
| 6694 | 1470 | handler->interp = interp; |
| 1471 | if (!tcl_signal_connect(handler)) { | |
| 1472 | tcl_signal_handler_free(handler); | |
|
20394
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
1473 | Tcl_SetObjResult(interp, Tcl_NewIntObj(1)); |
| 6694 | 1474 | } else { |
|
20394
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
1475 | Tcl_SetObjResult(interp, Tcl_NewIntObj(0)); |
| 6694 | 1476 | } |
| 1477 | break; | |
| 1478 | case CMD_SIGNAL_DISCONNECT: | |
| 1479 | if (objc != 4) { | |
| 13812 | 1480 | Tcl_WrongNumArgs(interp, 2, objv, "instance signal"); |
| 6694 | 1481 | return TCL_ERROR; |
| 1482 | } | |
|
20393
6280efb8c658
Another fabulous patch to our Tcl loader from venks on irc.freenode.net.
Ethan Blanton <elb@pidgin.im>
parents:
19859
diff
changeset
|
1483 | if ((instance = purple_tcl_ref_get(interp, objv[2],PurpleTclRefHandle)) == NULL) |
| 6694 | 1484 | return error; |
| 1485 | tcl_signal_disconnect(instance, Tcl_GetString(objv[3]), interp); | |
| 1486 | break; | |
| 1487 | } | |
| 1488 | ||
| 1489 | return TCL_OK; | |
| 1490 | } | |
| 1491 | ||
| 13812 | 1492 | int tcl_cmd_status(ClientData unused, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) |
| 1493 | { | |
| 13828 | 1494 | const char *cmds[] = { "attr", "type", NULL }; |
| 13812 | 1495 | enum { CMD_STATUS_ATTR, CMD_STATUS_TYPE } cmd; |
| 15884 | 1496 | PurpleStatus *status; |
| 1497 | PurpleStatusType *status_type; | |
|
25913
3d5e1dfea10a
Fix compile errors from the merge. Untested protocols: msnp9, sametime,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
24974
diff
changeset
|
1498 | int error; |
|
3d5e1dfea10a
Fix compile errors from the merge. Untested protocols: msnp9, sametime,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
24974
diff
changeset
|
1499 | #if !(defined PURPLE_DISABLE_DEPRECATED) |
| 15884 | 1500 | PurpleValue *value; |
| 13826 | 1501 | const char *attr; |
|
25913
3d5e1dfea10a
Fix compile errors from the merge. Untested protocols: msnp9, sametime,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
24974
diff
changeset
|
1502 | int v; |
|
3d5e1dfea10a
Fix compile errors from the merge. Untested protocols: msnp9, sametime,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
24974
diff
changeset
|
1503 | #endif |
| 13812 | 1504 | |
| 1505 | if (objc < 2) { | |
| 1506 | Tcl_WrongNumArgs(interp, 1, objv, "subcommand ?args?"); | |
| 1507 | return TCL_ERROR; | |
| 1508 | } | |
| 1509 | ||
| 1510 | if ((error = Tcl_GetIndexFromObj(interp, objv[1], cmds, "subcommand", 0, (int *)&cmd)) != TCL_OK) | |
| 1511 | return error; | |
| 1512 | ||
| 1513 | switch (cmd) { | |
| 1514 | case CMD_STATUS_ATTR: | |
|
25913
3d5e1dfea10a
Fix compile errors from the merge. Untested protocols: msnp9, sametime,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
24974
diff
changeset
|
1515 | #if !(defined PURPLE_DISABLE_DEPRECATED) |
| 13826 | 1516 | if (objc != 4 && objc != 5) { |
| 1517 | Tcl_WrongNumArgs(interp, 2, objv, "status attr_id ?value?"); | |
| 13812 | 1518 | return TCL_ERROR; |
| 1519 | } | |
| 15884 | 1520 | if ((status = purple_tcl_ref_get(interp, objv[2], PurpleTclRefStatus)) == NULL) |
| 13812 | 1521 | return TCL_ERROR; |
| 13826 | 1522 | attr = Tcl_GetString(objv[3]); |
| 15884 | 1523 | value = purple_status_get_attr_value(status, attr); |
| 13812 | 1524 | if (value == NULL) { |
|
20394
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
1525 | Tcl_SetObjResult(interp, |
|
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
1526 | Tcl_NewStringObj("no such attribute", -1)); |
| 13812 | 1527 | return TCL_ERROR; |
| 1528 | } | |
| 15884 | 1529 | switch (purple_value_get_type(value)) { |
| 1530 | case PURPLE_TYPE_BOOLEAN: | |
| 13826 | 1531 | if (objc == 4) { |
|
20394
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
1532 | Tcl_SetObjResult(interp, |
|
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
1533 | Tcl_NewBooleanObj(purple_value_get_boolean(value))); |
| 13826 | 1534 | } else { |
| 1535 | if ((error = Tcl_GetBooleanFromObj(interp, objv[4], &v)) != TCL_OK) | |
| 1536 | return error; | |
| 15884 | 1537 | purple_status_set_attr_boolean(status, attr, v); |
| 13826 | 1538 | } |
| 13812 | 1539 | break; |
| 15884 | 1540 | case PURPLE_TYPE_INT: |
| 13826 | 1541 | if (objc == 4) { |
|
20394
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
1542 | Tcl_SetObjResult(interp, Tcl_NewIntObj(purple_value_get_int(value))); |
| 13826 | 1543 | } else { |
| 1544 | if ((error = Tcl_GetIntFromObj(interp, objv[4], &v)) != TCL_OK) | |
| 1545 | return error; | |
| 15884 | 1546 | purple_status_set_attr_int(status, attr, v ); |
| 13826 | 1547 | } |
| 13812 | 1548 | break; |
| 15884 | 1549 | case PURPLE_TYPE_STRING: |
| 13826 | 1550 | if (objc == 4) |
|
20394
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
1551 | Tcl_SetObjResult(interp, |
|
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
1552 | Tcl_NewStringObj(purple_value_get_string(value), -1)); |
| 13826 | 1553 | else |
| 15884 | 1554 | purple_status_set_attr_string(status, attr, Tcl_GetString(objv[4])); |
| 13812 | 1555 | break; |
| 1556 | default: | |
|
20394
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
1557 | Tcl_SetObjResult(interp, |
|
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
1558 | Tcl_NewStringObj("attribute has unknown type", -1)); |
| 13812 | 1559 | return TCL_ERROR; |
| 1560 | } | |
|
25913
3d5e1dfea10a
Fix compile errors from the merge. Untested protocols: msnp9, sametime,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
24974
diff
changeset
|
1561 | #endif |
| 13812 | 1562 | break; |
| 1563 | case CMD_STATUS_TYPE: | |
| 1564 | if (objc != 3) { | |
| 1565 | Tcl_WrongNumArgs(interp, 2, objv, "status"); | |
| 1566 | return TCL_ERROR; | |
| 1567 | } | |
| 15884 | 1568 | if ((status = purple_tcl_ref_get(interp, objv[2], PurpleTclRefStatus)) == NULL) |
| 13812 | 1569 | return TCL_ERROR; |
| 15884 | 1570 | status_type = purple_status_get_type(status); |
| 1571 | Tcl_SetObjResult(interp, purple_tcl_ref_new(PurpleTclRefStatusType, | |
| 13812 | 1572 | status_type)); |
| 1573 | break; | |
| 1574 | } | |
| 1575 | ||
| 1576 | return TCL_OK; | |
| 1577 | } | |
| 1578 | ||
| 1579 | int tcl_cmd_status_attr(ClientData unused, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) | |
| 1580 | { | |
| 1581 | const char *cmds[] = { "id", "name", NULL }; | |
| 1582 | enum { CMD_STATUS_ATTR_ID, CMD_STATUS_ATTR_NAME } cmd; | |
| 15884 | 1583 | PurpleStatusAttr *attr; |
| 13812 | 1584 | int error; |
| 1585 | ||
| 1586 | if (objc < 2) { | |
| 1587 | Tcl_WrongNumArgs(interp, 1, objv, "subcommand ?args?"); | |
| 1588 | return TCL_ERROR; | |
| 1589 | } | |
| 1590 | ||
| 1591 | if ((error = Tcl_GetIndexFromObj(interp, objv[1], cmds, "subcommand", 0, (int *)&cmd)) != TCL_OK) | |
| 1592 | return error; | |
| 1593 | ||
| 1594 | switch (cmd) { | |
| 1595 | case CMD_STATUS_ATTR_ID: | |
| 1596 | if (objc != 3) { | |
| 1597 | Tcl_WrongNumArgs(interp, 2, objv, "attr"); | |
| 1598 | return TCL_ERROR; | |
| 1599 | } | |
| 15884 | 1600 | if ((attr = purple_tcl_ref_get(interp, objv[2], PurpleTclRefStatusAttr)) == NULL) |
| 13812 | 1601 | return TCL_ERROR; |
|
20394
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
1602 | Tcl_SetObjResult(interp, |
|
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
1603 | Tcl_NewStringObj(purple_status_attr_get_id(attr), -1)); |
| 13812 | 1604 | break; |
| 1605 | case CMD_STATUS_ATTR_NAME: | |
| 1606 | if (objc != 3) { | |
| 1607 | Tcl_WrongNumArgs(interp, 2, objv, "attr"); | |
| 1608 | return TCL_ERROR; | |
| 1609 | } | |
| 15884 | 1610 | if ((attr = purple_tcl_ref_get(interp, objv[2], PurpleTclRefStatusAttr)) == NULL) |
| 13812 | 1611 | return TCL_ERROR; |
|
20394
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
1612 | Tcl_SetObjResult(interp, |
|
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
1613 | Tcl_NewStringObj(purple_status_attr_get_name(attr), -1)); |
| 13812 | 1614 | break; |
| 1615 | } | |
| 1616 | ||
| 1617 | return TCL_OK; | |
| 1618 | } | |
| 1619 | ||
| 1620 | int tcl_cmd_status_type(ClientData unused, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) | |
| 1621 | { | |
| 1622 | const char *cmds[] = { "attr", "attrs", "available", "exclusive", "id", | |
| 1623 | "independent", "name", "primary_attr", | |
| 1624 | "primitive", "saveable", "user_settable", | |
| 1625 | NULL }; | |
| 1626 | enum { CMD_STATUS_TYPE_ATTR, CMD_STATUS_TYPE_ATTRS, | |
| 1627 | CMD_STATUS_TYPE_AVAILABLE, CMD_STATUS_TYPE_EXCLUSIVE, | |
| 1628 | CMD_STATUS_TYPE_ID, CMD_STATUS_TYPE_INDEPENDENT, | |
| 1629 | CMD_STATUS_TYPE_NAME, CMD_STATUS_TYPE_PRIMARY_ATTR, | |
| 1630 | CMD_STATUS_TYPE_PRIMITIVE, CMD_STATUS_TYPE_SAVEABLE, | |
| 1631 | CMD_STATUS_TYPE_USER_SETTABLE } cmd; | |
| 15884 | 1632 | PurpleStatusType *status_type; |
| 13812 | 1633 | Tcl_Obj *list, *elem; |
|
18190
bcf28ef7e8ff
Re-fix the DBus list handling code by killing const GList* / const GSList*
Richard Laager <rlaager@pidgin.im>
parents:
18122
diff
changeset
|
1634 | GList *cur; |
| 13812 | 1635 | int error; |
| 1636 | ||
| 1637 | if (objc < 2) { | |
| 1638 | Tcl_WrongNumArgs(interp, 1, objv, "subcommand ?args?"); | |
| 1639 | return TCL_ERROR; | |
| 1640 | } | |
| 1641 | ||
| 1642 | if ((error = Tcl_GetIndexFromObj(interp, objv[1], cmds, "subcommand", 0, (int *)&cmd)) != TCL_OK) | |
| 1643 | return error; | |
| 1644 | ||
| 1645 | switch (cmd) { | |
| 1646 | case CMD_STATUS_TYPE_AVAILABLE: | |
| 1647 | if (objc != 3) { | |
| 1648 | Tcl_WrongNumArgs(interp, 2, objv, "statustype"); | |
| 1649 | return TCL_ERROR; | |
| 1650 | } | |
| 15884 | 1651 | if ((status_type = purple_tcl_ref_get(interp, objv[2], PurpleTclRefStatusType)) == NULL) |
| 13812 | 1652 | return TCL_ERROR; |
|
20394
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
1653 | Tcl_SetObjResult(interp, |
|
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
1654 | Tcl_NewBooleanObj(purple_status_type_is_available(status_type))); |
| 13812 | 1655 | break; |
| 1656 | case CMD_STATUS_TYPE_ATTR: | |
| 1657 | if (objc != 4) { | |
| 1658 | Tcl_WrongNumArgs(interp, 2, objv, "statustype attr"); | |
| 1659 | return TCL_ERROR; | |
| 1660 | } | |
| 15884 | 1661 | if ((status_type = purple_tcl_ref_get(interp, objv[2], PurpleTclRefStatusType)) == NULL) |
| 13812 | 1662 | return TCL_ERROR; |
| 1663 | Tcl_SetObjResult(interp, | |
| 15884 | 1664 | purple_tcl_ref_new(PurpleTclRefStatusAttr, |
| 1665 | purple_status_type_get_attr(status_type, | |
| 13812 | 1666 | Tcl_GetStringFromObj(objv[3], NULL)))); |
| 1667 | break; | |
| 1668 | case CMD_STATUS_TYPE_ATTRS: | |
| 1669 | if (objc != 3) { | |
| 1670 | Tcl_WrongNumArgs(interp, 2, objv, "statustype"); | |
| 1671 | return TCL_ERROR; | |
| 1672 | } | |
| 15884 | 1673 | if ((status_type = purple_tcl_ref_get(interp, objv[2], PurpleTclRefStatusType)) == NULL) |
| 13812 | 1674 | return TCL_ERROR; |
| 1675 | list = Tcl_NewListObj(0, NULL); | |
| 15884 | 1676 | for (cur = purple_status_type_get_attrs(status_type); |
| 13812 | 1677 | cur != NULL; cur = g_list_next(cur)) { |
| 15884 | 1678 | elem = purple_tcl_ref_new(PurpleTclRefStatusAttr, cur->data); |
| 13812 | 1679 | Tcl_ListObjAppendElement(interp, list, elem); |
| 1680 | } | |
| 1681 | Tcl_SetObjResult(interp, list); | |
| 1682 | break; | |
| 1683 | case CMD_STATUS_TYPE_EXCLUSIVE: | |
| 1684 | if (objc != 3) { | |
| 1685 | Tcl_WrongNumArgs(interp, 2, objv, "statustype"); | |
| 1686 | return TCL_ERROR; | |
| 1687 | } | |
| 15884 | 1688 | if ((status_type = purple_tcl_ref_get(interp, objv[2], PurpleTclRefStatusType)) == NULL) |
| 13812 | 1689 | return TCL_ERROR; |
|
20394
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
1690 | Tcl_SetObjResult(interp, |
|
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
1691 | Tcl_NewBooleanObj(purple_status_type_is_exclusive(status_type))); |
| 13812 | 1692 | break; |
| 1693 | case CMD_STATUS_TYPE_ID: | |
| 1694 | if (objc != 3) { | |
| 1695 | Tcl_WrongNumArgs(interp, 2, objv, "statustype"); | |
| 1696 | return TCL_ERROR; | |
| 1697 | } | |
| 15884 | 1698 | if ((status_type = purple_tcl_ref_get(interp, objv[2], PurpleTclRefStatusType)) == NULL) |
| 13812 | 1699 | return TCL_ERROR; |
|
20394
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
1700 | Tcl_SetObjResult(interp, |
|
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
1701 | Tcl_NewStringObj(purple_status_type_get_id(status_type), -1)); |
| 13812 | 1702 | break; |
| 1703 | case CMD_STATUS_TYPE_INDEPENDENT: | |
| 1704 | if (objc != 3) { | |
| 1705 | Tcl_WrongNumArgs(interp, 2, objv, "statustype"); | |
| 1706 | return TCL_ERROR; | |
| 1707 | } | |
| 15884 | 1708 | if ((status_type = purple_tcl_ref_get(interp, objv[2], PurpleTclRefStatusType)) == NULL) |
| 13812 | 1709 | return TCL_ERROR; |
|
20394
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
1710 | Tcl_SetObjResult(interp, |
|
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
1711 | Tcl_NewBooleanObj(purple_status_type_is_independent(status_type))); |
| 13812 | 1712 | break; |
| 1713 | case CMD_STATUS_TYPE_NAME: | |
| 1714 | if (objc != 3) { | |
| 1715 | Tcl_WrongNumArgs(interp, 2, objv, "statustype"); | |
| 1716 | return TCL_ERROR; | |
| 1717 | } | |
| 15884 | 1718 | if ((status_type = purple_tcl_ref_get(interp, objv[2], PurpleTclRefStatusType)) == NULL) |
| 13812 | 1719 | return TCL_ERROR; |
|
20394
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
1720 | Tcl_SetObjResult(interp, |
|
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
1721 | Tcl_NewStringObj(purple_status_type_get_name(status_type), -1)); |
| 13812 | 1722 | break; |
| 1723 | case CMD_STATUS_TYPE_PRIMITIVE: | |
| 1724 | if (objc != 3) { | |
| 1725 | Tcl_WrongNumArgs(interp, 2, objv, "statustype"); | |
| 1726 | return TCL_ERROR; | |
| 1727 | } | |
| 15884 | 1728 | if ((status_type = purple_tcl_ref_get(interp, objv[2], PurpleTclRefStatusType)) == NULL) |
| 13812 | 1729 | return TCL_ERROR; |
|
20394
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
1730 | Tcl_SetObjResult(interp, |
|
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
1731 | Tcl_NewStringObj(purple_primitive_get_id_from_type |
|
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
1732 | (purple_status_type_get_primitive(status_type)), -1)); |
| 13812 | 1733 | break; |
| 1734 | case CMD_STATUS_TYPE_PRIMARY_ATTR: | |
|
25913
3d5e1dfea10a
Fix compile errors from the merge. Untested protocols: msnp9, sametime,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
24974
diff
changeset
|
1735 | #if !(defined PURPLE_DISABLE_DEPRECATED) |
| 13812 | 1736 | if (objc != 3) { |
| 1737 | Tcl_WrongNumArgs(interp, 2, objv, "statustype"); | |
| 1738 | return TCL_ERROR; | |
| 1739 | } | |
| 15884 | 1740 | if ((status_type = purple_tcl_ref_get(interp, objv[2], PurpleTclRefStatusType)) == NULL) |
| 13812 | 1741 | return TCL_ERROR; |
|
20394
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
1742 | Tcl_SetObjResult(interp, |
|
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
1743 | Tcl_NewStringObj(purple_status_type_get_primary_attr(status_type), -1)); |
|
25913
3d5e1dfea10a
Fix compile errors from the merge. Untested protocols: msnp9, sametime,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
24974
diff
changeset
|
1744 | #endif |
| 13812 | 1745 | break; |
| 1746 | case CMD_STATUS_TYPE_SAVEABLE: | |
| 1747 | if (objc != 3) { | |
| 1748 | Tcl_WrongNumArgs(interp, 2, objv, "statustype"); | |
| 1749 | return TCL_ERROR; | |
| 1750 | } | |
| 15884 | 1751 | if ((status_type = purple_tcl_ref_get(interp, objv[2], PurpleTclRefStatusType)) == NULL) |
| 13812 | 1752 | return TCL_ERROR; |
|
20394
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
1753 | Tcl_SetObjResult(interp, |
|
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
1754 | Tcl_NewBooleanObj( |
|
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
1755 | purple_status_type_is_saveable(status_type))); |
| 13812 | 1756 | break; |
| 1757 | case CMD_STATUS_TYPE_USER_SETTABLE: | |
| 1758 | if (objc != 3) { | |
| 1759 | Tcl_WrongNumArgs(interp, 2, objv, "statustype"); | |
| 1760 | return TCL_ERROR; | |
| 1761 | } | |
| 15884 | 1762 | if ((status_type = purple_tcl_ref_get(interp, objv[2], PurpleTclRefStatusType)) == NULL) |
| 13812 | 1763 | return TCL_ERROR; |
|
20394
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
1764 | Tcl_SetObjResult(interp, |
|
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
1765 | Tcl_NewBooleanObj( |
|
4088fda4a8e7
The second in a series of Tcl-fixing patches from venks on
Ethan Blanton <elb@pidgin.im>
parents:
20393
diff
changeset
|
1766 | purple_status_type_is_user_settable(status_type))); |
| 13812 | 1767 | break; |
| 1768 | } | |
| 1769 | ||
| 1770 | return TCL_OK; | |
| 1771 | } | |
| 1772 | ||
| 6694 | 1773 | static gboolean unload_self(gpointer data) |
| 1774 | { | |
| 15884 | 1775 | PurplePlugin *plugin = data; |
| 1776 | purple_plugin_unload(plugin); | |
| 6694 | 1777 | return FALSE; |
| 1778 | } | |
| 1779 | ||
| 1780 | int tcl_cmd_unload(ClientData unused, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) | |
| 1781 | { | |
| 15884 | 1782 | PurplePlugin *plugin; |
| 6694 | 1783 | if (objc != 1) { |
| 1784 | Tcl_WrongNumArgs(interp, 1, objv, ""); | |
| 1785 | return TCL_ERROR; | |
| 1786 | } | |
| 1787 | ||
| 1788 | if ((plugin = tcl_interp_get_plugin(interp)) == NULL) { | |
| 1789 | /* This isn't exactly OK, but heh. What do you do? */ | |
| 1790 | return TCL_OK; | |
| 1791 | } | |
| 1792 | /* We can't unload immediately, but we can unload at the first | |
| 1793 | * known safe opportunity. */ | |
|
22353
daef90676a8f
One more g_idle_add call
Mark Doliner <markdoliner@pidgin.im>
parents:
22240
diff
changeset
|
1794 | purple_timeout_add(0, unload_self, (gpointer)plugin); |
| 6694 | 1795 | |
| 1796 | return TCL_OK; | |
| 1797 | } |