annotate plugins/tcl/tcl_cmds.c @ 9034:bbb8733c7818

[gaim-migrate @ 9810] SimGuy says Oops. committer: Tailor Script <tailor@pidgin.im>
author Tim Ringenbach <marv@pidgin.im>
date Sun, 23 May 2004 18:38:07 +0000
parents beb7be215db3
children c001be3c330e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
1 /**
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
2 * @file tcl_cmds.c Commands for the Gaim Tcl plugin bindings
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
3 *
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
4 * gaim
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
5 *
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
6 * Copyright (C) 2003 Ethan Blanton <eblanton@cs.purdue.edu>
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
7 *
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
8 * This program is free software; you can redistribute it and/or modify
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
9 * it under the terms of the GNU General Public License as published by
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
10 * the Free Software Foundation; either version 2 of the License, or
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
11 * (at your option) any later version.
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
12 *
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful,
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
16 * GNU General Public License for more details.
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
17 *
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
18 * You should have received a copy of the GNU General Public License
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
19 * along with this program; if not, write to the Free Software
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
21 */
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
22
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
23 #include <tcl.h>
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
24
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
25 #include "internal.h"
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
26 #include "conversation.h"
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
27 #include "connection.h"
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
28 #include "account.h"
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
29 #include "server.h"
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
30 #include "notify.h"
6700
57161e3abbb5 [gaim-migrate @ 7226]
Ethan Blanton <elb@pidgin.im>
parents: 6694
diff changeset
31 #include "blist.h"
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
32 #include "debug.h"
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
33 #include "prefs.h"
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
34 #include "core.h"
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
35
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
36 #include "tcl_gaim.h"
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
37
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
38 static gboolean tcl_validate_account(GaimAccount *account, Tcl_Interp *interp);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
39 static gboolean tcl_validate_gc(GaimConnection *gc);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
40
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
41 static gboolean tcl_validate_account(GaimAccount *account, Tcl_Interp *interp)
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
42 {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
43 GList *cur;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
44 for (cur = gaim_accounts_get_all(); cur != NULL; cur = g_list_next(cur)) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
45 if (account == cur->data)
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
46 return TRUE;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
47 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
48 if (interp != NULL)
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
49 Tcl_SetStringObj(Tcl_GetObjResult(interp), "invalid account", -1);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
50 return FALSE;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
51 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
52
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
53 static gboolean tcl_validate_conversation(GaimConversation *convo, Tcl_Interp *interp)
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
54 {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
55 GList *cur;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
56
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
57 for (cur = gaim_get_conversations(); cur != NULL; cur = g_list_next(cur)) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
58 if (convo == cur->data)
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
59 return TRUE;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
60 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
61 if (interp != NULL)
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
62 Tcl_SetStringObj(Tcl_GetObjResult(interp), "invalid account", -1);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
63 return FALSE;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
64 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
65
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
66 static gboolean tcl_validate_gc(GaimConnection *gc)
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
67 {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
68 GList *cur;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
69 for (cur = gaim_connections_get_all(); cur != NULL; cur = g_list_next(cur)) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
70 if (gc == cur->data)
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
71 return TRUE;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
72 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
73 return FALSE;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
74 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
75
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
76 int tcl_cmd_account(ClientData unused, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[])
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
77 {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
78 Tcl_Obj *result = Tcl_GetObjResult(interp), *list, *elem;
6737
05098da416bb [gaim-migrate @ 7269]
Ethan Blanton <elb@pidgin.im>
parents: 6700
diff changeset
79 char *cmds[] = { "alias", "connect", "connection", "disconnect", "find",
8834
beb7be215db3 [gaim-migrate @ 9598]
Mark Doliner <mark@kingant.net>
parents: 7713
diff changeset
80 "handle", "isconnected", "list",
6737
05098da416bb [gaim-migrate @ 7269]
Ethan Blanton <elb@pidgin.im>
parents: 6700
diff changeset
81 "protocol", "username", NULL };
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
82 enum { CMD_ACCOUNT_ALIAS, CMD_ACCOUNT_CONNECT, CMD_ACCOUNT_CONNECTION,
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
83 CMD_ACCOUNT_DISCONNECT, CMD_ACCOUNT_FIND, CMD_ACCOUNT_HANDLE,
8834
beb7be215db3 [gaim-migrate @ 9598]
Mark Doliner <mark@kingant.net>
parents: 7713
diff changeset
84 CMD_ACCOUNT_ISCONNECTED, CMD_ACCOUNT_LIST,
6737
05098da416bb [gaim-migrate @ 7269]
Ethan Blanton <elb@pidgin.im>
parents: 6700
diff changeset
85 CMD_ACCOUNT_PROTOCOL, CMD_ACCOUNT_USERNAME } cmd;
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
86 char *listopts[] = { "-all", "-online", NULL };
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
87 enum { CMD_ACCOUNTLIST_ALL, CMD_ACCOUNTLIST_ONLINE } listopt;
8834
beb7be215db3 [gaim-migrate @ 9598]
Mark Doliner <mark@kingant.net>
parents: 7713
diff changeset
88 const char *alias;
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
89 GList *cur;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
90 GaimAccount *account;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
91 int error;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
92
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
93 if (objc < 2) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
94 Tcl_WrongNumArgs(interp, 1, objv, "subcommand ?args?");
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
95 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
96 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
97
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
98 if ((error = Tcl_GetIndexFromObj(interp, objv[1], cmds, "subcommand", 0, (int *)&cmd)) != TCL_OK)
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
99 return error;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
100
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
101 switch (cmd) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
102 case CMD_ACCOUNT_ALIAS:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
103 if (objc != 3) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
104 Tcl_WrongNumArgs(interp, 2, objv, "account");
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
105 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
106 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
107 error = Tcl_GetIntFromObj(interp, objv[2], (int *)&account);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
108 if (error || !tcl_validate_account(account, interp))
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
109 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
110 alias = gaim_account_get_alias(account);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
111 Tcl_SetStringObj(result, alias ? (char *)alias : "", -1);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
112 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
113 case CMD_ACCOUNT_CONNECT:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
114 if (objc != 3) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
115 Tcl_WrongNumArgs(interp, 2, objv, "account");
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
116 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
117 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
118 error = Tcl_GetIntFromObj(interp, objv[2], (int *)&account);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
119 if (error || !tcl_validate_account(account, interp))
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
120 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
121 if (gaim_account_is_connected(account))
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
122 Tcl_SetIntObj(result, (int)gaim_account_get_connection(account));
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
123 else
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
124 Tcl_SetIntObj(result, (int)gaim_account_connect(account));
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
125 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
126 case CMD_ACCOUNT_CONNECTION:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
127 if (objc != 3) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
128 Tcl_WrongNumArgs(interp, 2, objv, "account");
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
129 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
130 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
131 error = Tcl_GetIntFromObj(interp, objv[2], (int *)&account);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
132 if (error || !tcl_validate_account(account, interp))
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
133 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
134 Tcl_SetIntObj(result, (int)gaim_account_get_connection(account));
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
135 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
136 case CMD_ACCOUNT_DISCONNECT:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
137 if (objc != 3) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
138 Tcl_WrongNumArgs(interp, 2, objv, "account");
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
139 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
140 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
141 error = Tcl_GetIntFromObj(interp, objv[2], (int *)&account);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
142 if (error || !tcl_validate_account(account, interp))
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
143 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
144 gaim_account_disconnect(account);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
145 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
146 case CMD_ACCOUNT_FIND:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
147 if (objc != 4) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
148 Tcl_WrongNumArgs(interp, 2, objv, "username protocol");
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
149 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
150 }
7156
bb484e976aa8 [gaim-migrate @ 7723]
Nathan Walp <nwalp@pidgin.im>
parents: 7118
diff changeset
151 Tcl_SetIntObj(result, (int)gaim_accounts_find(Tcl_GetString(objv[2]),
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
152 Tcl_GetString(objv[3])));
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
153 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
154 case CMD_ACCOUNT_HANDLE:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
155 if (objc != 2) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
156 Tcl_WrongNumArgs(interp, 2, objv, "");
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
157 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
158 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
159 Tcl_SetIntObj(result, (int)gaim_accounts_get_handle());
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
160 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
161 case CMD_ACCOUNT_ISCONNECTED:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
162 if (objc != 3) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
163 Tcl_WrongNumArgs(interp, 2, objv, "account");
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
164 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
165 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
166 error = Tcl_GetIntFromObj(interp, objv[2], (int *)&account);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
167 if (error || !tcl_validate_account(account, interp))
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
168 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
169 Tcl_SetBooleanObj(result, gaim_account_is_connected(account));
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
170 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
171 case CMD_ACCOUNT_LIST:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
172 listopt = CMD_ACCOUNTLIST_ALL;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
173 if (objc > 3) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
174 Tcl_WrongNumArgs(interp, 2, objv, "?option?");
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
175 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
176 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
177 if (objc == 3) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
178 if ((error = Tcl_GetIndexFromObj(interp, objv[2], listopts, "option", 0, (int *)&listopt)) != TCL_OK)
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
179 return error;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
180 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
181 list = Tcl_NewListObj(0, NULL);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
182 for (cur = gaim_accounts_get_all(); cur != NULL; cur = g_list_next(cur)) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
183 account = cur->data;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
184 if (listopt == CMD_ACCOUNTLIST_ONLINE && !gaim_account_is_connected(account))
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
185 continue;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
186 elem = Tcl_NewIntObj((int)account);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
187 Tcl_ListObjAppendElement(interp, list, elem);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
188 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
189 Tcl_SetObjResult(interp, list);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
190 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
191 case CMD_ACCOUNT_PROTOCOL:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
192 if (objc != 3) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
193 Tcl_WrongNumArgs(interp, 2, objv, "account");
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
194 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
195 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
196 error = Tcl_GetIntFromObj(interp, objv[2], (int *)&account);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
197 if (error || !tcl_validate_account(account, interp))
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
198 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
199 Tcl_SetStringObj(result, (char *)gaim_account_get_protocol_id(account), -1);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
200 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
201 case CMD_ACCOUNT_USERNAME:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
202 if (objc != 3) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
203 Tcl_WrongNumArgs(interp, 2, objv, "account");
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
204 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
205 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
206 error = Tcl_GetIntFromObj(interp, objv[2], (int *)&account);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
207 if (error || !tcl_validate_account(account, interp))
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
208 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
209 Tcl_SetStringObj(result, (char *)gaim_account_get_username(account), -1);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
210 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
211 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
212
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
213 return TCL_OK;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
214 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
215
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
216 static GaimBlistNode *tcl_list_to_buddy(Tcl_Interp *interp, int count, Tcl_Obj **elems)
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
217 {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
218 GaimBlistNode *node = NULL;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
219 GaimAccount *account;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
220 char *name;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
221 char *type;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
222
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
223 if (count < 3) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
224 Tcl_SetStringObj(Tcl_GetObjResult(interp), "list too short", -1);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
225 return NULL;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
226 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
227
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
228 type = Tcl_GetString(elems[0]);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
229 name = Tcl_GetString(elems[1]);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
230 if (Tcl_GetIntFromObj(interp, elems[2], (int *)&account) != TCL_OK)
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
231 return NULL;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
232 if (!tcl_validate_account(account, interp))
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
233 return NULL;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
234
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
235 if (!strcmp(type, "buddy")) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
236 node = (GaimBlistNode *)gaim_find_buddy(account, name);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
237 } else if (!strcmp(type, "group")) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
238 node = (GaimBlistNode *)gaim_blist_find_chat(account, name);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
239 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
240
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
241 return node;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
242 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
243
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
244 int tcl_cmd_buddy(ClientData unused, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[])
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
245 {
6746
c45c90c8ce8a [gaim-migrate @ 7278]
Ethan Blanton <elb@pidgin.im>
parents: 6737
diff changeset
246 Tcl_Obj *list, *tclgroup, *tclgrouplist, *tclcontact, *tclcontactlist, *tclbud, **elems, *result;
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
247 char *cmds[] = { "alias", "handle", "info", "list", NULL };
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
248 enum { CMD_BUDDY_ALIAS, CMD_BUDDY_HANDLE, CMD_BUDDY_INFO, CMD_BUDDY_LIST } cmd;
7100
abdc55ffadba [gaim-migrate @ 7665]
Christian Hammond <chipx86@chipx86.com>
parents: 6982
diff changeset
249 GaimBuddyList *blist;
6746
c45c90c8ce8a [gaim-migrate @ 7278]
Ethan Blanton <elb@pidgin.im>
parents: 6737
diff changeset
250 GaimBlistNode *node, *gnode, *bnode;
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
251 GaimAccount *account;
6746
c45c90c8ce8a [gaim-migrate @ 7278]
Ethan Blanton <elb@pidgin.im>
parents: 6737
diff changeset
252 GaimBuddy *bud;
7118
bf630f7dfdcd [gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents: 7100
diff changeset
253 GaimChat *cnode;
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
254 int error, all = 0, count;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
255
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
256 if (objc < 2) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
257 Tcl_WrongNumArgs(interp, 1, objv, "subcommand ?args?");
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
258 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
259 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
260 if ((error = Tcl_GetIndexFromObj(interp, objv[1], cmds, "subcommand", 0, (int *)&cmd)) != TCL_OK)
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
261 return error;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
262
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
263 result = Tcl_GetObjResult(interp);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
264
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
265 switch (cmd) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
266 case CMD_BUDDY_ALIAS:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
267 if (objc != 3) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
268 Tcl_WrongNumArgs(interp, 2, objv, "buddy");
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
269 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
270 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
271 if ((error = Tcl_ListObjGetElements(interp, objv[2], &count, &elems)) != TCL_OK)
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
272 return error;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
273 if ((node = tcl_list_to_buddy(interp, count, elems)) == NULL)
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
274 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
275 if (node->type == GAIM_BLIST_CHAT_NODE)
7118
bf630f7dfdcd [gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents: 7100
diff changeset
276 Tcl_SetStringObj(result, ((GaimChat *)node)->alias, -1);
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
277 else if (node->type == GAIM_BLIST_BUDDY_NODE)
6700
57161e3abbb5 [gaim-migrate @ 7226]
Ethan Blanton <elb@pidgin.im>
parents: 6694
diff changeset
278 Tcl_SetStringObj(result, (char *)gaim_get_buddy_alias((GaimBuddy *)node), -1);
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
279 return TCL_OK;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
280 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
281 case CMD_BUDDY_HANDLE:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
282 if (objc != 2) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
283 Tcl_WrongNumArgs(interp, 2, objv, "");
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
284 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
285 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
286 Tcl_SetIntObj(result, (int)gaim_blist_get_handle());
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
287 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
288 case CMD_BUDDY_INFO:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
289 if (objc != 3 && objc != 4) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
290 Tcl_WrongNumArgs(interp, 2, objv, "( buddy | account username )");
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
291 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
292 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
293 if (objc == 3) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
294 if ((error = Tcl_ListObjGetElements(interp, objv[2], &count, &elems)) != TCL_OK)
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
295 return error;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
296 if (count < 3) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
297 Tcl_SetStringObj(result, "buddy too short", -1);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
298 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
299 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
300 if (strcmp("buddy", Tcl_GetString(elems[0]))) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
301 Tcl_SetStringObj(result, "invalid buddy", -1);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
302 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
303 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
304 if ((error = Tcl_GetIntFromObj(interp, elems[2], (int *)&account)) != TCL_OK)
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
305 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
306 if (!tcl_validate_account(account, interp))
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
307 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
308 serv_get_info(gaim_account_get_connection(account), Tcl_GetString(elems[1]));
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
309 } else {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
310 if ((error = Tcl_GetIntFromObj(interp, objv[2], (int *)&account)) != TCL_OK)
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
311 return error;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
312 if (!tcl_validate_account(account, interp))
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
313 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
314 serv_get_info(gaim_account_get_connection(account), Tcl_GetString(objv[3]));
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
315 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
316 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
317 case CMD_BUDDY_LIST:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
318 if (objc == 3) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
319 if (!strcmp("-all", Tcl_GetString(objv[2]))) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
320 all = 1;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
321 } else {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
322 Tcl_SetStringObj(result, "", -1);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
323 Tcl_AppendStringsToObj(result, "unknown option: ", Tcl_GetString(objv[2]), NULL);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
324 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
325 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
326 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
327 list = Tcl_NewListObj(0, NULL);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
328 blist = gaim_get_blist();
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
329 for (gnode = blist->root; gnode != NULL; gnode = gnode->next) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
330 tclgroup = Tcl_NewListObj(0, NULL);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
331 Tcl_ListObjAppendElement(interp, tclgroup, Tcl_NewStringObj("group", -1));
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
332 Tcl_ListObjAppendElement(interp, tclgroup,
6700
57161e3abbb5 [gaim-migrate @ 7226]
Ethan Blanton <elb@pidgin.im>
parents: 6694
diff changeset
333 Tcl_NewStringObj(((GaimGroup *)gnode)->name, -1));
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
334 tclgrouplist = Tcl_NewListObj(0, NULL);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
335 for (node = gnode->child; node != NULL; node = node->next) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
336 switch (node->type) {
6746
c45c90c8ce8a [gaim-migrate @ 7278]
Ethan Blanton <elb@pidgin.im>
parents: 6737
diff changeset
337 case GAIM_BLIST_CONTACT_NODE:
c45c90c8ce8a [gaim-migrate @ 7278]
Ethan Blanton <elb@pidgin.im>
parents: 6737
diff changeset
338 tclcontact = Tcl_NewListObj(0, NULL);
c45c90c8ce8a [gaim-migrate @ 7278]
Ethan Blanton <elb@pidgin.im>
parents: 6737
diff changeset
339 Tcl_IncrRefCount(tclcontact);
c45c90c8ce8a [gaim-migrate @ 7278]
Ethan Blanton <elb@pidgin.im>
parents: 6737
diff changeset
340 Tcl_ListObjAppendElement(interp, tclcontact, Tcl_NewStringObj("contact", -1));
c45c90c8ce8a [gaim-migrate @ 7278]
Ethan Blanton <elb@pidgin.im>
parents: 6737
diff changeset
341 tclcontactlist = Tcl_NewListObj(0, NULL);
c45c90c8ce8a [gaim-migrate @ 7278]
Ethan Blanton <elb@pidgin.im>
parents: 6737
diff changeset
342 Tcl_IncrRefCount(tclcontactlist);
c45c90c8ce8a [gaim-migrate @ 7278]
Ethan Blanton <elb@pidgin.im>
parents: 6737
diff changeset
343 count = 0;
c45c90c8ce8a [gaim-migrate @ 7278]
Ethan Blanton <elb@pidgin.im>
parents: 6737
diff changeset
344 for (bnode = node->child; bnode != NULL; bnode = bnode ->next) {
c45c90c8ce8a [gaim-migrate @ 7278]
Ethan Blanton <elb@pidgin.im>
parents: 6737
diff changeset
345 if (bnode->type != GAIM_BLIST_BUDDY_NODE)
c45c90c8ce8a [gaim-migrate @ 7278]
Ethan Blanton <elb@pidgin.im>
parents: 6737
diff changeset
346 continue;
c45c90c8ce8a [gaim-migrate @ 7278]
Ethan Blanton <elb@pidgin.im>
parents: 6737
diff changeset
347 bud = (GaimBuddy *)bnode;
c45c90c8ce8a [gaim-migrate @ 7278]
Ethan Blanton <elb@pidgin.im>
parents: 6737
diff changeset
348 if (!all && !gaim_account_is_connected(bud->account))
c45c90c8ce8a [gaim-migrate @ 7278]
Ethan Blanton <elb@pidgin.im>
parents: 6737
diff changeset
349 continue;
c45c90c8ce8a [gaim-migrate @ 7278]
Ethan Blanton <elb@pidgin.im>
parents: 6737
diff changeset
350 count++;
c45c90c8ce8a [gaim-migrate @ 7278]
Ethan Blanton <elb@pidgin.im>
parents: 6737
diff changeset
351 tclbud = Tcl_NewListObj(0, NULL);
c45c90c8ce8a [gaim-migrate @ 7278]
Ethan Blanton <elb@pidgin.im>
parents: 6737
diff changeset
352 Tcl_ListObjAppendElement(interp, tclbud, Tcl_NewStringObj("buddy", -1));
c45c90c8ce8a [gaim-migrate @ 7278]
Ethan Blanton <elb@pidgin.im>
parents: 6737
diff changeset
353 Tcl_ListObjAppendElement(interp, tclbud, Tcl_NewStringObj(bud->name, -1));
c45c90c8ce8a [gaim-migrate @ 7278]
Ethan Blanton <elb@pidgin.im>
parents: 6737
diff changeset
354 Tcl_ListObjAppendElement(interp, tclbud, Tcl_NewIntObj((int)bud->account));
c45c90c8ce8a [gaim-migrate @ 7278]
Ethan Blanton <elb@pidgin.im>
parents: 6737
diff changeset
355 Tcl_ListObjAppendElement(interp, tclcontactlist, tclbud);
c45c90c8ce8a [gaim-migrate @ 7278]
Ethan Blanton <elb@pidgin.im>
parents: 6737
diff changeset
356 }
c45c90c8ce8a [gaim-migrate @ 7278]
Ethan Blanton <elb@pidgin.im>
parents: 6737
diff changeset
357 if (count) {
c45c90c8ce8a [gaim-migrate @ 7278]
Ethan Blanton <elb@pidgin.im>
parents: 6737
diff changeset
358 Tcl_ListObjAppendElement(interp, tclcontact, tclcontactlist);
c45c90c8ce8a [gaim-migrate @ 7278]
Ethan Blanton <elb@pidgin.im>
parents: 6737
diff changeset
359 Tcl_ListObjAppendElement(interp, tclgrouplist, tclcontact);
c45c90c8ce8a [gaim-migrate @ 7278]
Ethan Blanton <elb@pidgin.im>
parents: 6737
diff changeset
360 }
c45c90c8ce8a [gaim-migrate @ 7278]
Ethan Blanton <elb@pidgin.im>
parents: 6737
diff changeset
361 Tcl_DecrRefCount(tclcontact);
c45c90c8ce8a [gaim-migrate @ 7278]
Ethan Blanton <elb@pidgin.im>
parents: 6737
diff changeset
362 Tcl_DecrRefCount(tclcontactlist);
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
363 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
364 case GAIM_BLIST_CHAT_NODE:
7118
bf630f7dfdcd [gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents: 7100
diff changeset
365 cnode = (GaimChat *)node;
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
366 if (!all && !gaim_account_is_connected(cnode->account))
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
367 continue;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
368 tclbud = Tcl_NewListObj(0, NULL);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
369 Tcl_ListObjAppendElement(interp, tclbud, Tcl_NewStringObj("chat", -1));
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
370 Tcl_ListObjAppendElement(interp, tclbud, Tcl_NewStringObj(cnode->alias, -1));
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
371 Tcl_ListObjAppendElement(interp, tclbud, Tcl_NewIntObj((int)cnode->account));
6746
c45c90c8ce8a [gaim-migrate @ 7278]
Ethan Blanton <elb@pidgin.im>
parents: 6737
diff changeset
372 Tcl_ListObjAppendElement(interp, tclgrouplist, tclbud);
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
373 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
374 default:
6746
c45c90c8ce8a [gaim-migrate @ 7278]
Ethan Blanton <elb@pidgin.im>
parents: 6737
diff changeset
375 gaim_debug(GAIM_DEBUG_WARNING, "tcl", "Unexpected buddy type %d", node->type);
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
376 continue;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
377 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
378 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
379 Tcl_ListObjAppendElement(interp, tclgroup, tclgrouplist);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
380 Tcl_ListObjAppendElement(interp, list, tclgroup);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
381 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
382 Tcl_SetObjResult(interp, list);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
383 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
384 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
385
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
386 return TCL_OK;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
387 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
388
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
389 int tcl_cmd_connection(ClientData unused, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[])
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
390 {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
391 Tcl_Obj *result = Tcl_GetObjResult(interp), *list, *elem;
7713
1adc71ed6d45 [gaim-migrate @ 8358]
Ethan Blanton <elb@pidgin.im>
parents: 7156
diff changeset
392 char *cmds[] = { "account", "displayname", "handle", "list", NULL };
1adc71ed6d45 [gaim-migrate @ 8358]
Ethan Blanton <elb@pidgin.im>
parents: 7156
diff changeset
393 enum { CMD_CONN_ACCOUNT, CMD_CONN_DISPLAYNAME, CMD_CONN_HANDLE, CMD_CONN_LIST } cmd;
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
394 int error;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
395 GList *cur;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
396 GaimConnection *gc;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
397
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
398 if (objc < 2) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
399 Tcl_WrongNumArgs(interp, 1, objv, "subcommand ?args?");
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
400 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
401 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
402
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
403 if ((error = Tcl_GetIndexFromObj(interp, objv[1], cmds, "subcommand", 0, (int *)&cmd)) != TCL_OK)
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
404 return error;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
405
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
406 switch (cmd) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
407 case CMD_CONN_ACCOUNT:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
408 if (objc != 3) {
6864
1dd0f3492ab1 [gaim-migrate @ 7410]
Luke Schierer <lschiere@pidgin.im>
parents: 6746
diff changeset
409 Tcl_WrongNumArgs(interp, 2, objv, "gc");
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
410 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
411 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
412 error = Tcl_GetIntFromObj(interp, objv[2], (int *)&gc);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
413 if (error || !tcl_validate_gc(gc)) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
414 Tcl_SetStringObj(result, "invalid gc", -1);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
415 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
416 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
417 Tcl_SetIntObj(result, (int)gaim_connection_get_account(gc));
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
418 break;
7713
1adc71ed6d45 [gaim-migrate @ 8358]
Ethan Blanton <elb@pidgin.im>
parents: 7156
diff changeset
419 case CMD_CONN_DISPLAYNAME:
1adc71ed6d45 [gaim-migrate @ 8358]
Ethan Blanton <elb@pidgin.im>
parents: 7156
diff changeset
420 if (objc != 3) {
1adc71ed6d45 [gaim-migrate @ 8358]
Ethan Blanton <elb@pidgin.im>
parents: 7156
diff changeset
421 Tcl_WrongNumArgs(interp, 2, objv, "gc");
1adc71ed6d45 [gaim-migrate @ 8358]
Ethan Blanton <elb@pidgin.im>
parents: 7156
diff changeset
422 return TCL_ERROR;
1adc71ed6d45 [gaim-migrate @ 8358]
Ethan Blanton <elb@pidgin.im>
parents: 7156
diff changeset
423 }
1adc71ed6d45 [gaim-migrate @ 8358]
Ethan Blanton <elb@pidgin.im>
parents: 7156
diff changeset
424 error = Tcl_GetIntFromObj(interp, objv[2], (int *)&gc);
1adc71ed6d45 [gaim-migrate @ 8358]
Ethan Blanton <elb@pidgin.im>
parents: 7156
diff changeset
425 if (error || !tcl_validate_gc(gc)) {
1adc71ed6d45 [gaim-migrate @ 8358]
Ethan Blanton <elb@pidgin.im>
parents: 7156
diff changeset
426 Tcl_SetStringObj(result, "invalid gc", -1);
1adc71ed6d45 [gaim-migrate @ 8358]
Ethan Blanton <elb@pidgin.im>
parents: 7156
diff changeset
427 return TCL_ERROR;
1adc71ed6d45 [gaim-migrate @ 8358]
Ethan Blanton <elb@pidgin.im>
parents: 7156
diff changeset
428 }
1adc71ed6d45 [gaim-migrate @ 8358]
Ethan Blanton <elb@pidgin.im>
parents: 7156
diff changeset
429 Tcl_SetStringObj(result, (char *)gaim_connection_get_display_name(gc), -1);
1adc71ed6d45 [gaim-migrate @ 8358]
Ethan Blanton <elb@pidgin.im>
parents: 7156
diff changeset
430 break;
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
431 case CMD_CONN_HANDLE:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
432 if (objc != 2) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
433 Tcl_WrongNumArgs(interp, 2, objv, "");
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
434 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
435 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
436 Tcl_SetIntObj(result, (int)gaim_connections_get_handle());
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
437 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
438 case CMD_CONN_LIST:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
439 if (objc != 2) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
440 Tcl_WrongNumArgs(interp, 2, objv, "");
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
441 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
442 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
443 list = Tcl_NewListObj(0, NULL);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
444 for (cur = gaim_connections_get_all(); cur != NULL; cur = g_list_next(cur)) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
445 elem = Tcl_NewIntObj((int)cur->data);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
446 Tcl_ListObjAppendElement(interp, list, elem);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
447 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
448 Tcl_SetObjResult(interp, list);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
449 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
450 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
451
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
452 return TCL_OK;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
453 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
454
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
455 int tcl_cmd_conversation(ClientData unused, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[])
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
456 {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
457 Tcl_Obj *list, *elem, *result = Tcl_GetObjResult(interp);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
458 char *cmds[] = { "find", "handle", "list", "new", "write", NULL };
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
459 enum { CMD_CONV_FIND, CMD_CONV_HANDLE, CMD_CONV_LIST, CMD_CONV_NEW, CMD_CONV_WRITE } cmd;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
460 char *styles[] = { "send", "recv", "system", NULL };
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
461 enum { CMD_CONV_WRITE_SEND, CMD_CONV_WRITE_RECV, CMD_CONV_WRITE_SYSTEM } style;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
462 char *findopts[] = { "-account", NULL };
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
463 enum { CMD_CONV_FIND_ACCOUNT } findopt;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
464 char *newopts[] = { "-chat", "-im" };
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
465 enum { CMD_CONV_NEW_CHAT, CMD_CONV_NEW_IM } newopt;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
466 GaimConversation *convo;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
467 GaimAccount *account;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
468 GaimConversationType type;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
469 GList *cur;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
470 char *opt, *from, *what;
7156
bb484e976aa8 [gaim-migrate @ 7723]
Nathan Walp <nwalp@pidgin.im>
parents: 7118
diff changeset
471 int error, argsused, flags = 0;
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
472
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
473 if (objc < 2) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
474 Tcl_WrongNumArgs(interp, 1, objv, "subcommand ?args?");
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
475 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
476 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
477
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
478 if ((error = Tcl_GetIndexFromObj(interp, objv[1], cmds, "subcommand", 0, (int *)&cmd)) != TCL_OK)
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
479 return error;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
480
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
481 switch (cmd) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
482 case CMD_CONV_FIND:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
483 if (objc < 3) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
484 Tcl_WrongNumArgs(interp, 2, objv, "?options? name");
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
485 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
486 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
487 argsused = 2;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
488 account = NULL;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
489 while (argsused < objc) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
490 opt = Tcl_GetString(objv[argsused]);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
491 if (*opt == '-') {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
492 if ((error = Tcl_GetIndexFromObj(interp, objv[argsused], findopts,
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
493 "option", 0, (int *)&findopt)) != TCL_OK)
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
494 return error;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
495 argsused++;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
496 switch (findopt) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
497 case CMD_CONV_FIND_ACCOUNT:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
498 if (argsused == objc - 1) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
499 Tcl_SetStringObj(result, "-account requires an argument", -1);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
500 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
501 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
502 if ((error = Tcl_GetIntFromObj(interp, objv[argsused],
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
503 (int *)&account)) != TCL_OK)
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
504 return error;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
505 if (!tcl_validate_account(account, interp))
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
506 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
507 argsused++;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
508 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
509 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
510 } else {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
511 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
512 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
513 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
514 if (objc - argsused != 1) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
515 Tcl_WrongNumArgs(interp, 2, objv, "?options? name");
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
516 return error;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
517 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
518 if (account != NULL) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
519 convo = gaim_find_conversation_with_account(Tcl_GetString(objv[argsused]), account);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
520 } else {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
521 convo = gaim_find_conversation(Tcl_GetString(objv[argsused]));
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
522 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
523 Tcl_SetIntObj(result, (int)convo);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
524 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
525 case CMD_CONV_HANDLE:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
526 if (objc != 2) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
527 Tcl_WrongNumArgs(interp, 2, objv, "");
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
528 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
529 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
530 Tcl_SetIntObj(result, (int)gaim_conversations_get_handle());
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
531 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
532 case CMD_CONV_LIST:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
533 list = Tcl_NewListObj(0, NULL);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
534 for (cur = gaim_get_conversations(); cur != NULL; cur = g_list_next(cur)) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
535 elem = Tcl_NewIntObj((int)cur->data);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
536 Tcl_ListObjAppendElement(interp, list, elem);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
537 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
538 Tcl_SetObjResult(interp, list);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
539 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
540 case CMD_CONV_NEW:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
541 if (objc < 4) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
542 Tcl_WrongNumArgs(interp, 2, objv, "?options? account name");
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
543 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
544 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
545 argsused = 2;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
546 type = GAIM_CONV_IM;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
547 while (argsused < objc) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
548 opt = Tcl_GetString(objv[argsused]);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
549 if (*opt == '-') {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
550 if ((error = Tcl_GetIndexFromObj(interp, objv[argsused], newopts,
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
551 "option", 0, (int *)&newopt)) != TCL_OK)
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
552 return error;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
553 argsused++;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
554 switch (newopt) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
555 case CMD_CONV_NEW_CHAT:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
556 type = GAIM_CONV_CHAT;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
557 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
558 case CMD_CONV_NEW_IM:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
559 type = GAIM_CONV_IM;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
560 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
561 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
562 } else {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
563 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
564 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
565 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
566 if (objc - argsused != 2) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
567 Tcl_WrongNumArgs(interp, 2, objv, "?options? account name");
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
568 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
569 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
570 if ((error = Tcl_GetIntFromObj(interp, objv[argsused++], (int *)&account)) != TCL_OK)
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
571 return error;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
572 if (!tcl_validate_account(account, interp))
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
573 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
574 convo = gaim_conversation_new(type, account, Tcl_GetString(objv[argsused]));
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
575 Tcl_SetIntObj(result, (int)convo);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
576 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
577 case CMD_CONV_WRITE:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
578 if (objc != 6) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
579 Tcl_WrongNumArgs(interp, 2, objv, "conversation style from what");
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
580 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
581 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
582 if ((error = Tcl_GetIntFromObj(interp, objv[2], (int *)&convo)) != TCL_OK)
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
583 return error;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
584 if ((error = Tcl_GetIndexFromObj(interp, objv[3], styles, "style", 0, (int *)&style)) != TCL_OK)
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
585 return error;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
586 if (!tcl_validate_conversation(convo, interp))
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
587 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
588 from = Tcl_GetString(objv[4]);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
589 what = Tcl_GetString(objv[5]);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
590
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
591 switch (style) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
592 case CMD_CONV_WRITE_SEND:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
593 flags = GAIM_MESSAGE_SEND;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
594 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
595 case CMD_CONV_WRITE_RECV:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
596 flags = GAIM_MESSAGE_RECV;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
597 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
598 case CMD_CONV_WRITE_SYSTEM:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
599 flags = GAIM_MESSAGE_SYSTEM;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
600 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
601 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
602 if (gaim_conversation_get_type(convo) == GAIM_CONV_CHAT)
7118
bf630f7dfdcd [gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents: 7100
diff changeset
603 gaim_conv_chat_write(GAIM_CONV_CHAT(convo), from, what, flags, time(NULL));
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
604 else
7118
bf630f7dfdcd [gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents: 7100
diff changeset
605 gaim_conv_im_write(GAIM_CONV_IM(convo), from, what, flags, time(NULL));
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
606 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
607 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
608
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
609 return TCL_OK;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
610 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
611
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
612 int tcl_cmd_core(ClientData unused, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[])
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
613 {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
614 Tcl_Obj *result = Tcl_GetObjResult(interp);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
615 char *cmds[] = { "handle", "quit", NULL };
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
616 enum { CMD_CORE_HANDLE, CMD_CORE_QUIT } cmd;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
617 int error;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
618
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
619 if (objc < 2) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
620 Tcl_WrongNumArgs(interp, 1, objv, "subcommand ?args?");
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
621 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
622 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
623
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
624 if ((error = Tcl_GetIndexFromObj(interp, objv[1], cmds, "subcommand", 0, (int *)&cmd)) != TCL_OK)
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
625 return error;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
626
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
627 switch (cmd) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
628 case CMD_CORE_HANDLE:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
629 if (objc != 2) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
630 Tcl_WrongNumArgs(interp, 2, objv, "");
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
631 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
632 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
633 Tcl_SetIntObj(result, (int)gaim_get_core());
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
634 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
635 case CMD_CORE_QUIT:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
636 if (objc != 2) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
637 Tcl_WrongNumArgs(interp, 2, objv, "");
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
638 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
639 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
640 gaim_core_quit();
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
641 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
642 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
643
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
644 return TCL_OK;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
645 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
646
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
647 int tcl_cmd_debug(ClientData unused, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[])
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
648 {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
649 char *category, *message;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
650 int lev;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
651 char *levels[] = { "-misc", "-info", "-warning", "-error", NULL };
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
652 GaimDebugLevel levelind[] = { GAIM_DEBUG_MISC, GAIM_DEBUG_INFO, GAIM_DEBUG_WARNING, GAIM_DEBUG_ERROR };
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
653 int error;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
654
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
655 if (objc != 4) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
656 Tcl_WrongNumArgs(interp, 1, objv, "level category message");
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
657 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
658 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
659
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
660 error = Tcl_GetIndexFromObj(interp, objv[1], levels, "debug level", 0, &lev);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
661 if (error != TCL_OK)
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
662 return error;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
663
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
664 category = Tcl_GetString(objv[2]);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
665 message = Tcl_GetString(objv[3]);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
666
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
667 gaim_debug(levelind[lev], category, "%s\n", message);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
668
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
669 return TCL_OK;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
670 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
671
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
672 int tcl_cmd_notify(ClientData unused, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[])
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
673 {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
674 int error, type;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
675 char *opts[] = { "-error", "-warning", "-info", NULL };
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
676 GaimNotifyMsgType optind[] = { GAIM_NOTIFY_MSG_ERROR, GAIM_NOTIFY_MSG_WARNING, GAIM_NOTIFY_MSG_INFO };
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
677 char *title, *msg1, *msg2;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
678
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
679 if (objc < 4 || objc > 5) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
680 Tcl_WrongNumArgs(interp, 1, objv, "?type? title primary secondary");
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
681 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
682 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
683
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
684 if (objc == 4) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
685 title = Tcl_GetString(objv[1]);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
686 msg1 = Tcl_GetString(objv[2]);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
687 msg2 = Tcl_GetString(objv[3]);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
688 } else {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
689 error = Tcl_GetIndexFromObj(interp, objv[1], opts, "message type", 0, &type);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
690 if (error != TCL_OK)
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
691 return error;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
692 title = Tcl_GetString(objv[2]);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
693 msg1 = Tcl_GetString(objv[3]);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
694 msg2 = Tcl_GetString(objv[4]);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
695 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
696
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
697 gaim_notify_message(_tcl_plugin, optind[type], title, msg1, msg2, NULL, NULL);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
698
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
699 return TCL_OK;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
700 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
701
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
702 int tcl_cmd_prefs(ClientData unused, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[])
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
703 {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
704 Tcl_Obj *result, *list, *elem, **elems;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
705 char *cmds[] = { "get", "set", "type", NULL };
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
706 enum { CMD_PREFS_GET, CMD_PREFS_SET, CMD_PREFS_TYPE } cmd;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
707 /* char *types[] = { "none", "boolean", "int", "string", "stringlist", NULL }; */
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
708 /* enum { TCL_PREFS_NONE, TCL_PREFS_BOOL, TCL_PREFS_INT, TCL_PREFS_STRING, TCL_PREFS_STRINGLIST } type; */
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
709 GaimPrefType preftype;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
710 GList *cur;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
711 int error, intval, nelem, i;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
712
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
713 if (objc < 2) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
714 Tcl_WrongNumArgs(interp, 1, objv, "subcommand ?args?");
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
715 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
716 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
717
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
718 if ((error = Tcl_GetIndexFromObj(interp, objv[1], cmds, "subcommand", 0, (int *)&cmd)) != TCL_OK)
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
719 return error;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
720
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
721 result = Tcl_GetObjResult(interp);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
722 switch (cmd) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
723 case CMD_PREFS_GET:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
724 if (objc != 3) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
725 Tcl_WrongNumArgs(interp, 1, objv, "path");
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
726 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
727 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
728 preftype = gaim_prefs_get_type(Tcl_GetString(objv[2]));
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
729 switch (preftype) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
730 case GAIM_PREF_NONE:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
731 Tcl_SetStringObj(result, "pref type none", -1);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
732 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
733 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
734 case GAIM_PREF_BOOLEAN:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
735 Tcl_SetBooleanObj(result, gaim_prefs_get_bool(Tcl_GetString(objv[2])));
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
736 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
737 case GAIM_PREF_INT:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
738 Tcl_SetIntObj(result, gaim_prefs_get_int(Tcl_GetString(objv[2])));
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
739 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
740 case GAIM_PREF_STRING:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
741 Tcl_SetStringObj(result, (char *)gaim_prefs_get_string(Tcl_GetString(objv[2])), -1);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
742 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
743 case GAIM_PREF_STRING_LIST:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
744 cur = gaim_prefs_get_string_list(Tcl_GetString(objv[2]));
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
745 list = Tcl_NewListObj(0, NULL);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
746 while (cur != NULL) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
747 elem = Tcl_NewStringObj((char *)cur->data, -1);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
748 Tcl_ListObjAppendElement(interp, list, elem);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
749 cur = g_list_next(cur);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
750 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
751 Tcl_SetObjResult(interp, list);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
752 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
753 default:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
754 gaim_debug(GAIM_DEBUG_ERROR, "tcl", "tcl does not know about pref type %d\n", preftype);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
755 Tcl_SetStringObj(result, "unknown pref type", -1);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
756 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
757 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
758 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
759 case CMD_PREFS_SET:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
760 if (objc != 4) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
761 Tcl_WrongNumArgs(interp, 1, objv, "path value");
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
762 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
763 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
764 preftype = gaim_prefs_get_type(Tcl_GetString(objv[2]));
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
765 switch (preftype) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
766 case GAIM_PREF_NONE:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
767 Tcl_SetStringObj(result, "bad path or pref type none", -1);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
768 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
769 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
770 case GAIM_PREF_BOOLEAN:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
771 if ((error = Tcl_GetBooleanFromObj(interp, objv[3], &intval)) != TCL_OK)
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
772 return error;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
773 gaim_prefs_set_bool(Tcl_GetString(objv[2]), intval);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
774 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
775 case GAIM_PREF_INT:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
776 if ((error = Tcl_GetIntFromObj(interp, objv[3], &intval)) != TCL_OK)
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
777 return error;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
778 gaim_prefs_set_int(Tcl_GetString(objv[2]), intval);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
779 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
780 case GAIM_PREF_STRING:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
781 gaim_prefs_set_string(Tcl_GetString(objv[2]), Tcl_GetString(objv[3]));
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
782 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
783 case GAIM_PREF_STRING_LIST:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
784 if ((error = Tcl_ListObjGetElements(interp, objv[3], &nelem, &elems)) != TCL_OK)
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
785 return error;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
786 cur = NULL;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
787 for (i = 0; i < nelem; i++) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
788 cur = g_list_append(cur, (gpointer)Tcl_GetString(elems[i]));
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
789 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
790 gaim_prefs_set_string_list(Tcl_GetString(objv[2]), cur);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
791 g_list_free(cur);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
792 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
793 default:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
794 gaim_debug(GAIM_DEBUG_ERROR, "tcl", "tcl does not know about pref type %d\n", preftype);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
795 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
796 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
797 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
798 case CMD_PREFS_TYPE:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
799 if (objc != 3) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
800 Tcl_WrongNumArgs(interp, 1, objv, "path");
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
801 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
802 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
803 preftype = gaim_prefs_get_type(Tcl_GetString(objv[2]));
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
804 switch (preftype) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
805 case GAIM_PREF_NONE:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
806 Tcl_SetStringObj(result, "none", -1);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
807 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
808 case GAIM_PREF_BOOLEAN:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
809 Tcl_SetStringObj(result, "boolean", -1);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
810 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
811 case GAIM_PREF_INT:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
812 Tcl_SetStringObj(result, "int", -1);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
813 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
814 case GAIM_PREF_STRING:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
815 Tcl_SetStringObj(result, "string", -1);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
816 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
817 case GAIM_PREF_STRING_LIST:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
818 Tcl_SetStringObj(result, "stringlist", -1);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
819 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
820 default:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
821 gaim_debug(GAIM_DEBUG_ERROR, "tcl", "tcl does not know about pref type %d\n", preftype);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
822 Tcl_SetStringObj(result, "unknown", -1);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
823 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
824 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
825 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
826
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
827 return TCL_OK;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
828 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
829
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
830 int tcl_cmd_send_im(ClientData unused, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[])
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
831 {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
832 GaimConnection *gc;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
833 char *who, *text;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
834 int error;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
835 Tcl_Obj *result;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
836
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
837 if (objc != 4) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
838 Tcl_WrongNumArgs(interp, 1, objv, "gc who text");
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
839 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
840 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
841
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
842 if ((error = Tcl_GetIntFromObj(interp, objv[1], (int *)&gc)) != TCL_OK)
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
843 return error;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
844 if (!tcl_validate_gc(gc)) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
845 result = Tcl_GetObjResult(interp);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
846 Tcl_SetStringObj(result, "invalid gc", -1);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
847 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
848 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
849
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
850 who = Tcl_GetString(objv[2]);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
851 text = Tcl_GetString(objv[3]);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
852
6982
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6864
diff changeset
853 serv_send_im(gc, who, text, 0);
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
854
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
855 return TCL_OK;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
856 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
857
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
858 int tcl_cmd_signal(ClientData unused, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[])
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
859 {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
860 char *cmds[] = { "connect", "disconnect", NULL };
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
861 enum { CMD_SIGNAL_CONNECT, CMD_SIGNAL_DISCONNECT } cmd;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
862 struct tcl_signal_handler *handler;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
863 Tcl_Obj **elems, *result = Tcl_GetObjResult(interp);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
864 void *instance;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
865 int error, nelems, i;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
866
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
867 if (objc < 2) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
868 Tcl_WrongNumArgs(interp, 1, objv, "subcommand ?args?");
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
869 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
870 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
871
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
872 if ((error = Tcl_GetIndexFromObj(interp, objv[1], cmds, "subcommand", 0, (int *)&cmd)) != TCL_OK)
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
873 return error;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
874
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
875 switch (cmd) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
876 case CMD_SIGNAL_CONNECT:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
877 if (objc != 6) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
878 Tcl_WrongNumArgs(interp, 2, objv, "instance signal args proc");
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
879 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
880 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
881 if ((error = Tcl_ListObjGetElements(interp, objv[4], &nelems, &elems)) != TCL_OK)
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
882 return error;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
883 handler = g_new0(struct tcl_signal_handler, 1);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
884 if ((error = Tcl_GetIntFromObj(interp, objv[2], (int *)&handler->instance)) != TCL_OK) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
885 g_free(handler);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
886 return error;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
887 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
888 handler->signal = g_strdup(Tcl_GetString(objv[3]));
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
889 if (nelems) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
890 handler->argnames = g_new0(char *, nelems);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
891 for (i = 0; i < nelems; i++) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
892 handler->argnames[i] = g_strdup(Tcl_GetString(elems[i]));
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
893 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
894 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
895 handler->nnames = nelems;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
896 handler->proc = Tcl_NewStringObj("namespace eval ::gaim::_callback { ", -1);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
897 Tcl_AppendStringsToObj(handler->proc, Tcl_GetString(objv[5]), " }", NULL);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
898 Tcl_IncrRefCount(handler->proc);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
899 handler->interp = interp;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
900 if (!tcl_signal_connect(handler)) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
901 tcl_signal_handler_free(handler);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
902 Tcl_SetIntObj(result, 1);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
903 } else {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
904 Tcl_SetIntObj(result, 0);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
905 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
906 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
907 case CMD_SIGNAL_DISCONNECT:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
908 if (objc != 4) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
909 Tcl_WrongNumArgs(interp, 2, objv, "signal");
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
910 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
911 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
912 if ((error = Tcl_GetIntFromObj(interp, objv[2], (int *)&instance)) != TCL_OK)
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
913 return error;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
914 tcl_signal_disconnect(instance, Tcl_GetString(objv[3]), interp);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
915 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
916 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
917
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
918 return TCL_OK;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
919 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
920
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
921 static gboolean unload_self(gpointer data)
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
922 {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
923 GaimPlugin *plugin = data;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
924 gaim_plugin_unload(plugin);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
925 return FALSE;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
926 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
927
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
928 int tcl_cmd_unload(ClientData unused, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[])
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
929 {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
930 GaimPlugin *plugin;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
931 if (objc != 1) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
932 Tcl_WrongNumArgs(interp, 1, objv, "");
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
933 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
934 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
935
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
936 if ((plugin = tcl_interp_get_plugin(interp)) == NULL) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
937 /* This isn't exactly OK, but heh. What do you do? */
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
938 return TCL_OK;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
939 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
940 /* We can't unload immediately, but we can unload at the first
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
941 * known safe opportunity. */
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
942 g_idle_add(unload_self, (gpointer)plugin);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
943
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
944 return TCL_OK;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
945 }