annotate plugins/tcl/tcl_cmds.c @ 10401:3e4ecbdf8d0a

[gaim-migrate @ 11638] Stuff compiles again, if that's what you wanted stuff to do. It works a bit too. I fixed one crash in oscar, only to reveal another that I didnn't fix (tooltips). Most protocols still need updating to actually log in in the specified state, TCL needs some love for gaim_account_connect, perl probably does too but that needs more love anyway. The reconnect plugin could be more intelligent too, as could gaim-remote. committer: Tailor Script <tailor@pidgin.im>
author Stu Tomlinson <stu@nosnilmot.com>
date Tue, 21 Dec 2004 01:48:30 +0000
parents 3eb03f22e082
children 0e886a234d92
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;
10339
3eb03f22e082 [gaim-migrate @ 11548]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
79 const 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;
10339
3eb03f22e082 [gaim-migrate @ 11548]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
86 const char *listopts[] = { "-all", "-online", NULL };
6694
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
10401
3e4ecbdf8d0a [gaim-migrate @ 11638]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10339
diff changeset
124 #warning Someone who knows TCL (Ethan!) fix this so TCL plugins can specify the status
3e4ecbdf8d0a [gaim-migrate @ 11638]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10339
diff changeset
125 Tcl_SetIntObj(result, (int)gaim_account_connect(account,
3e4ecbdf8d0a [gaim-migrate @ 11638]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10339
diff changeset
126 gaim_account_get_status(account, "online")));
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
127 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
128 case CMD_ACCOUNT_CONNECTION:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
129 if (objc != 3) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
130 Tcl_WrongNumArgs(interp, 2, objv, "account");
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
131 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
132 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
133 error = Tcl_GetIntFromObj(interp, objv[2], (int *)&account);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
134 if (error || !tcl_validate_account(account, interp))
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
135 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
136 Tcl_SetIntObj(result, (int)gaim_account_get_connection(account));
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
137 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
138 case CMD_ACCOUNT_DISCONNECT:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
139 if (objc != 3) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
140 Tcl_WrongNumArgs(interp, 2, objv, "account");
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
141 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
142 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
143 error = Tcl_GetIntFromObj(interp, objv[2], (int *)&account);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
144 if (error || !tcl_validate_account(account, interp))
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
145 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
146 gaim_account_disconnect(account);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
147 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
148 case CMD_ACCOUNT_FIND:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
149 if (objc != 4) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
150 Tcl_WrongNumArgs(interp, 2, objv, "username protocol");
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
151 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
152 }
7156
bb484e976aa8 [gaim-migrate @ 7723]
Nathan Walp <nwalp@pidgin.im>
parents: 7118
diff changeset
153 Tcl_SetIntObj(result, (int)gaim_accounts_find(Tcl_GetString(objv[2]),
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
154 Tcl_GetString(objv[3])));
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
155 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
156 case CMD_ACCOUNT_HANDLE:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
157 if (objc != 2) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
158 Tcl_WrongNumArgs(interp, 2, objv, "");
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
159 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
160 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
161 Tcl_SetIntObj(result, (int)gaim_accounts_get_handle());
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
162 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
163 case CMD_ACCOUNT_ISCONNECTED:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
164 if (objc != 3) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
165 Tcl_WrongNumArgs(interp, 2, objv, "account");
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
166 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
167 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
168 error = Tcl_GetIntFromObj(interp, objv[2], (int *)&account);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
169 if (error || !tcl_validate_account(account, interp))
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
170 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
171 Tcl_SetBooleanObj(result, gaim_account_is_connected(account));
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
172 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
173 case CMD_ACCOUNT_LIST:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
174 listopt = CMD_ACCOUNTLIST_ALL;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
175 if (objc > 3) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
176 Tcl_WrongNumArgs(interp, 2, objv, "?option?");
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
177 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
178 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
179 if (objc == 3) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
180 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
181 return error;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
182 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
183 list = Tcl_NewListObj(0, NULL);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
184 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
185 account = cur->data;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
186 if (listopt == CMD_ACCOUNTLIST_ONLINE && !gaim_account_is_connected(account))
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
187 continue;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
188 elem = Tcl_NewIntObj((int)account);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
189 Tcl_ListObjAppendElement(interp, list, elem);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
190 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
191 Tcl_SetObjResult(interp, list);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
192 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
193 case CMD_ACCOUNT_PROTOCOL:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
194 if (objc != 3) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
195 Tcl_WrongNumArgs(interp, 2, objv, "account");
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
196 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
197 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
198 error = Tcl_GetIntFromObj(interp, objv[2], (int *)&account);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
199 if (error || !tcl_validate_account(account, interp))
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
200 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
201 Tcl_SetStringObj(result, (char *)gaim_account_get_protocol_id(account), -1);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
202 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
203 case CMD_ACCOUNT_USERNAME:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
204 if (objc != 3) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
205 Tcl_WrongNumArgs(interp, 2, objv, "account");
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
206 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
207 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
208 error = Tcl_GetIntFromObj(interp, objv[2], (int *)&account);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
209 if (error || !tcl_validate_account(account, interp))
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
210 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
211 Tcl_SetStringObj(result, (char *)gaim_account_get_username(account), -1);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
212 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
213 }
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 return TCL_OK;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
216 }
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 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
219 {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
220 GaimBlistNode *node = NULL;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
221 GaimAccount *account;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
222 char *name;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
223 char *type;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
224
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
225 if (count < 3) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
226 Tcl_SetStringObj(Tcl_GetObjResult(interp), "list too short", -1);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
227 return NULL;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
228 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
229
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
230 type = Tcl_GetString(elems[0]);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
231 name = Tcl_GetString(elems[1]);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
232 if (Tcl_GetIntFromObj(interp, elems[2], (int *)&account) != TCL_OK)
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 if (!tcl_validate_account(account, interp))
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
235 return NULL;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
236
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
237 if (!strcmp(type, "buddy")) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
238 node = (GaimBlistNode *)gaim_find_buddy(account, name);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
239 } else if (!strcmp(type, "group")) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
240 node = (GaimBlistNode *)gaim_blist_find_chat(account, name);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
241 }
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 return node;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
244 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
245
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
246 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
247 {
6746
c45c90c8ce8a [gaim-migrate @ 7278]
Ethan Blanton <elb@pidgin.im>
parents: 6737
diff changeset
248 Tcl_Obj *list, *tclgroup, *tclgrouplist, *tclcontact, *tclcontactlist, *tclbud, **elems, *result;
10339
3eb03f22e082 [gaim-migrate @ 11548]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
249 const char *cmds[] = { "alias", "handle", "info", "list", NULL };
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
250 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
251 GaimBuddyList *blist;
6746
c45c90c8ce8a [gaim-migrate @ 7278]
Ethan Blanton <elb@pidgin.im>
parents: 6737
diff changeset
252 GaimBlistNode *node, *gnode, *bnode;
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
253 GaimAccount *account;
6746
c45c90c8ce8a [gaim-migrate @ 7278]
Ethan Blanton <elb@pidgin.im>
parents: 6737
diff changeset
254 GaimBuddy *bud;
7118
bf630f7dfdcd [gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents: 7100
diff changeset
255 GaimChat *cnode;
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
256 int error, all = 0, count;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
257
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
258 if (objc < 2) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
259 Tcl_WrongNumArgs(interp, 1, objv, "subcommand ?args?");
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
260 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
261 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
262 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
263 return error;
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 result = Tcl_GetObjResult(interp);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
266
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
267 switch (cmd) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
268 case CMD_BUDDY_ALIAS:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
269 if (objc != 3) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
270 Tcl_WrongNumArgs(interp, 2, objv, "buddy");
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
271 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
272 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
273 if ((error = Tcl_ListObjGetElements(interp, objv[2], &count, &elems)) != TCL_OK)
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
274 return error;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
275 if ((node = tcl_list_to_buddy(interp, count, elems)) == NULL)
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
276 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
277 if (node->type == GAIM_BLIST_CHAT_NODE)
7118
bf630f7dfdcd [gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents: 7100
diff changeset
278 Tcl_SetStringObj(result, ((GaimChat *)node)->alias, -1);
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
279 else if (node->type == GAIM_BLIST_BUDDY_NODE)
9620
c001be3c330e [gaim-migrate @ 10464]
Mark Doliner <mark@kingant.net>
parents: 8834
diff changeset
280 Tcl_SetStringObj(result, (char *)gaim_buddy_get_alias((GaimBuddy *)node), -1);
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
281 return TCL_OK;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
282 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
283 case CMD_BUDDY_HANDLE:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
284 if (objc != 2) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
285 Tcl_WrongNumArgs(interp, 2, objv, "");
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
286 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
287 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
288 Tcl_SetIntObj(result, (int)gaim_blist_get_handle());
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
289 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
290 case CMD_BUDDY_INFO:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
291 if (objc != 3 && objc != 4) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
292 Tcl_WrongNumArgs(interp, 2, objv, "( buddy | account username )");
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
293 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
294 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
295 if (objc == 3) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
296 if ((error = Tcl_ListObjGetElements(interp, objv[2], &count, &elems)) != TCL_OK)
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
297 return error;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
298 if (count < 3) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
299 Tcl_SetStringObj(result, "buddy too short", -1);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
300 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
301 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
302 if (strcmp("buddy", Tcl_GetString(elems[0]))) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
303 Tcl_SetStringObj(result, "invalid buddy", -1);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
304 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
305 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
306 if ((error = Tcl_GetIntFromObj(interp, elems[2], (int *)&account)) != TCL_OK)
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 if (!tcl_validate_account(account, interp))
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
309 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
310 serv_get_info(gaim_account_get_connection(account), Tcl_GetString(elems[1]));
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
311 } else {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
312 if ((error = Tcl_GetIntFromObj(interp, objv[2], (int *)&account)) != TCL_OK)
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
313 return error;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
314 if (!tcl_validate_account(account, interp))
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
315 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
316 serv_get_info(gaim_account_get_connection(account), Tcl_GetString(objv[3]));
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
317 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
318 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
319 case CMD_BUDDY_LIST:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
320 if (objc == 3) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
321 if (!strcmp("-all", Tcl_GetString(objv[2]))) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
322 all = 1;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
323 } else {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
324 Tcl_SetStringObj(result, "", -1);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
325 Tcl_AppendStringsToObj(result, "unknown option: ", Tcl_GetString(objv[2]), NULL);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
326 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
327 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
328 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
329 list = Tcl_NewListObj(0, NULL);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
330 blist = gaim_get_blist();
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
331 for (gnode = blist->root; gnode != NULL; gnode = gnode->next) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
332 tclgroup = Tcl_NewListObj(0, NULL);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
333 Tcl_ListObjAppendElement(interp, tclgroup, Tcl_NewStringObj("group", -1));
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
334 Tcl_ListObjAppendElement(interp, tclgroup,
6700
57161e3abbb5 [gaim-migrate @ 7226]
Ethan Blanton <elb@pidgin.im>
parents: 6694
diff changeset
335 Tcl_NewStringObj(((GaimGroup *)gnode)->name, -1));
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
336 tclgrouplist = Tcl_NewListObj(0, NULL);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
337 for (node = gnode->child; node != NULL; node = node->next) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
338 switch (node->type) {
6746
c45c90c8ce8a [gaim-migrate @ 7278]
Ethan Blanton <elb@pidgin.im>
parents: 6737
diff changeset
339 case GAIM_BLIST_CONTACT_NODE:
c45c90c8ce8a [gaim-migrate @ 7278]
Ethan Blanton <elb@pidgin.im>
parents: 6737
diff changeset
340 tclcontact = Tcl_NewListObj(0, NULL);
c45c90c8ce8a [gaim-migrate @ 7278]
Ethan Blanton <elb@pidgin.im>
parents: 6737
diff changeset
341 Tcl_IncrRefCount(tclcontact);
c45c90c8ce8a [gaim-migrate @ 7278]
Ethan Blanton <elb@pidgin.im>
parents: 6737
diff changeset
342 Tcl_ListObjAppendElement(interp, tclcontact, Tcl_NewStringObj("contact", -1));
c45c90c8ce8a [gaim-migrate @ 7278]
Ethan Blanton <elb@pidgin.im>
parents: 6737
diff changeset
343 tclcontactlist = Tcl_NewListObj(0, NULL);
c45c90c8ce8a [gaim-migrate @ 7278]
Ethan Blanton <elb@pidgin.im>
parents: 6737
diff changeset
344 Tcl_IncrRefCount(tclcontactlist);
c45c90c8ce8a [gaim-migrate @ 7278]
Ethan Blanton <elb@pidgin.im>
parents: 6737
diff changeset
345 count = 0;
c45c90c8ce8a [gaim-migrate @ 7278]
Ethan Blanton <elb@pidgin.im>
parents: 6737
diff changeset
346 for (bnode = node->child; bnode != NULL; bnode = bnode ->next) {
c45c90c8ce8a [gaim-migrate @ 7278]
Ethan Blanton <elb@pidgin.im>
parents: 6737
diff changeset
347 if (bnode->type != GAIM_BLIST_BUDDY_NODE)
c45c90c8ce8a [gaim-migrate @ 7278]
Ethan Blanton <elb@pidgin.im>
parents: 6737
diff changeset
348 continue;
c45c90c8ce8a [gaim-migrate @ 7278]
Ethan Blanton <elb@pidgin.im>
parents: 6737
diff changeset
349 bud = (GaimBuddy *)bnode;
c45c90c8ce8a [gaim-migrate @ 7278]
Ethan Blanton <elb@pidgin.im>
parents: 6737
diff changeset
350 if (!all && !gaim_account_is_connected(bud->account))
c45c90c8ce8a [gaim-migrate @ 7278]
Ethan Blanton <elb@pidgin.im>
parents: 6737
diff changeset
351 continue;
c45c90c8ce8a [gaim-migrate @ 7278]
Ethan Blanton <elb@pidgin.im>
parents: 6737
diff changeset
352 count++;
c45c90c8ce8a [gaim-migrate @ 7278]
Ethan Blanton <elb@pidgin.im>
parents: 6737
diff changeset
353 tclbud = Tcl_NewListObj(0, NULL);
c45c90c8ce8a [gaim-migrate @ 7278]
Ethan Blanton <elb@pidgin.im>
parents: 6737
diff changeset
354 Tcl_ListObjAppendElement(interp, tclbud, Tcl_NewStringObj("buddy", -1));
c45c90c8ce8a [gaim-migrate @ 7278]
Ethan Blanton <elb@pidgin.im>
parents: 6737
diff changeset
355 Tcl_ListObjAppendElement(interp, tclbud, Tcl_NewStringObj(bud->name, -1));
c45c90c8ce8a [gaim-migrate @ 7278]
Ethan Blanton <elb@pidgin.im>
parents: 6737
diff changeset
356 Tcl_ListObjAppendElement(interp, tclbud, Tcl_NewIntObj((int)bud->account));
c45c90c8ce8a [gaim-migrate @ 7278]
Ethan Blanton <elb@pidgin.im>
parents: 6737
diff changeset
357 Tcl_ListObjAppendElement(interp, tclcontactlist, tclbud);
c45c90c8ce8a [gaim-migrate @ 7278]
Ethan Blanton <elb@pidgin.im>
parents: 6737
diff changeset
358 }
c45c90c8ce8a [gaim-migrate @ 7278]
Ethan Blanton <elb@pidgin.im>
parents: 6737
diff changeset
359 if (count) {
c45c90c8ce8a [gaim-migrate @ 7278]
Ethan Blanton <elb@pidgin.im>
parents: 6737
diff changeset
360 Tcl_ListObjAppendElement(interp, tclcontact, tclcontactlist);
c45c90c8ce8a [gaim-migrate @ 7278]
Ethan Blanton <elb@pidgin.im>
parents: 6737
diff changeset
361 Tcl_ListObjAppendElement(interp, tclgrouplist, tclcontact);
c45c90c8ce8a [gaim-migrate @ 7278]
Ethan Blanton <elb@pidgin.im>
parents: 6737
diff changeset
362 }
c45c90c8ce8a [gaim-migrate @ 7278]
Ethan Blanton <elb@pidgin.im>
parents: 6737
diff changeset
363 Tcl_DecrRefCount(tclcontact);
c45c90c8ce8a [gaim-migrate @ 7278]
Ethan Blanton <elb@pidgin.im>
parents: 6737
diff changeset
364 Tcl_DecrRefCount(tclcontactlist);
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
365 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
366 case GAIM_BLIST_CHAT_NODE:
7118
bf630f7dfdcd [gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents: 7100
diff changeset
367 cnode = (GaimChat *)node;
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
368 if (!all && !gaim_account_is_connected(cnode->account))
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
369 continue;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
370 tclbud = Tcl_NewListObj(0, NULL);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
371 Tcl_ListObjAppendElement(interp, tclbud, Tcl_NewStringObj("chat", -1));
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
372 Tcl_ListObjAppendElement(interp, tclbud, Tcl_NewStringObj(cnode->alias, -1));
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
373 Tcl_ListObjAppendElement(interp, tclbud, Tcl_NewIntObj((int)cnode->account));
6746
c45c90c8ce8a [gaim-migrate @ 7278]
Ethan Blanton <elb@pidgin.im>
parents: 6737
diff changeset
374 Tcl_ListObjAppendElement(interp, tclgrouplist, tclbud);
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
375 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
376 default:
6746
c45c90c8ce8a [gaim-migrate @ 7278]
Ethan Blanton <elb@pidgin.im>
parents: 6737
diff changeset
377 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
378 continue;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
379 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
380 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
381 Tcl_ListObjAppendElement(interp, tclgroup, tclgrouplist);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
382 Tcl_ListObjAppendElement(interp, list, tclgroup);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
383 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
384 Tcl_SetObjResult(interp, list);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
385 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
386 }
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 return TCL_OK;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
389 }
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 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
392 {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
393 Tcl_Obj *result = Tcl_GetObjResult(interp), *list, *elem;
10339
3eb03f22e082 [gaim-migrate @ 11548]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
394 const char *cmds[] = { "account", "displayname", "handle", "list", NULL };
7713
1adc71ed6d45 [gaim-migrate @ 8358]
Ethan Blanton <elb@pidgin.im>
parents: 7156
diff changeset
395 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
396 int error;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
397 GList *cur;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
398 GaimConnection *gc;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
399
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
400 if (objc < 2) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
401 Tcl_WrongNumArgs(interp, 1, objv, "subcommand ?args?");
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
402 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
403 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
404
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
405 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
406 return error;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
407
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
408 switch (cmd) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
409 case CMD_CONN_ACCOUNT:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
410 if (objc != 3) {
6864
1dd0f3492ab1 [gaim-migrate @ 7410]
Luke Schierer <lschiere@pidgin.im>
parents: 6746
diff changeset
411 Tcl_WrongNumArgs(interp, 2, objv, "gc");
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
412 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
413 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
414 error = Tcl_GetIntFromObj(interp, objv[2], (int *)&gc);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
415 if (error || !tcl_validate_gc(gc)) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
416 Tcl_SetStringObj(result, "invalid gc", -1);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
417 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
418 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
419 Tcl_SetIntObj(result, (int)gaim_connection_get_account(gc));
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
420 break;
7713
1adc71ed6d45 [gaim-migrate @ 8358]
Ethan Blanton <elb@pidgin.im>
parents: 7156
diff changeset
421 case CMD_CONN_DISPLAYNAME:
1adc71ed6d45 [gaim-migrate @ 8358]
Ethan Blanton <elb@pidgin.im>
parents: 7156
diff changeset
422 if (objc != 3) {
1adc71ed6d45 [gaim-migrate @ 8358]
Ethan Blanton <elb@pidgin.im>
parents: 7156
diff changeset
423 Tcl_WrongNumArgs(interp, 2, objv, "gc");
1adc71ed6d45 [gaim-migrate @ 8358]
Ethan Blanton <elb@pidgin.im>
parents: 7156
diff changeset
424 return TCL_ERROR;
1adc71ed6d45 [gaim-migrate @ 8358]
Ethan Blanton <elb@pidgin.im>
parents: 7156
diff changeset
425 }
1adc71ed6d45 [gaim-migrate @ 8358]
Ethan Blanton <elb@pidgin.im>
parents: 7156
diff changeset
426 error = Tcl_GetIntFromObj(interp, objv[2], (int *)&gc);
1adc71ed6d45 [gaim-migrate @ 8358]
Ethan Blanton <elb@pidgin.im>
parents: 7156
diff changeset
427 if (error || !tcl_validate_gc(gc)) {
1adc71ed6d45 [gaim-migrate @ 8358]
Ethan Blanton <elb@pidgin.im>
parents: 7156
diff changeset
428 Tcl_SetStringObj(result, "invalid gc", -1);
1adc71ed6d45 [gaim-migrate @ 8358]
Ethan Blanton <elb@pidgin.im>
parents: 7156
diff changeset
429 return TCL_ERROR;
1adc71ed6d45 [gaim-migrate @ 8358]
Ethan Blanton <elb@pidgin.im>
parents: 7156
diff changeset
430 }
1adc71ed6d45 [gaim-migrate @ 8358]
Ethan Blanton <elb@pidgin.im>
parents: 7156
diff changeset
431 Tcl_SetStringObj(result, (char *)gaim_connection_get_display_name(gc), -1);
1adc71ed6d45 [gaim-migrate @ 8358]
Ethan Blanton <elb@pidgin.im>
parents: 7156
diff changeset
432 break;
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
433 case CMD_CONN_HANDLE:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
434 if (objc != 2) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
435 Tcl_WrongNumArgs(interp, 2, objv, "");
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
436 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
437 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
438 Tcl_SetIntObj(result, (int)gaim_connections_get_handle());
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
439 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
440 case CMD_CONN_LIST:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
441 if (objc != 2) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
442 Tcl_WrongNumArgs(interp, 2, objv, "");
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
443 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
444 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
445 list = Tcl_NewListObj(0, NULL);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
446 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
447 elem = Tcl_NewIntObj((int)cur->data);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
448 Tcl_ListObjAppendElement(interp, list, elem);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
449 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
450 Tcl_SetObjResult(interp, list);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
451 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
452 }
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 return TCL_OK;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
455 }
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 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
458 {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
459 Tcl_Obj *list, *elem, *result = Tcl_GetObjResult(interp);
10339
3eb03f22e082 [gaim-migrate @ 11548]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
460 const char *cmds[] = { "find", "handle", "list", "new", "write", NULL };
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
461 enum { CMD_CONV_FIND, CMD_CONV_HANDLE, CMD_CONV_LIST, CMD_CONV_NEW, CMD_CONV_WRITE } cmd;
10339
3eb03f22e082 [gaim-migrate @ 11548]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
462 const char *styles[] = { "send", "recv", "system", NULL };
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
463 enum { CMD_CONV_WRITE_SEND, CMD_CONV_WRITE_RECV, CMD_CONV_WRITE_SYSTEM } style;
10339
3eb03f22e082 [gaim-migrate @ 11548]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
464 const char *findopts[] = { "-account", NULL };
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
465 enum { CMD_CONV_FIND_ACCOUNT } findopt;
10339
3eb03f22e082 [gaim-migrate @ 11548]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
466 const char *newopts[] = { "-chat", "-im" };
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
467 enum { CMD_CONV_NEW_CHAT, CMD_CONV_NEW_IM } newopt;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
468 GaimConversation *convo;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
469 GaimAccount *account;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
470 GaimConversationType type;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
471 GList *cur;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
472 char *opt, *from, *what;
7156
bb484e976aa8 [gaim-migrate @ 7723]
Nathan Walp <nwalp@pidgin.im>
parents: 7118
diff changeset
473 int error, argsused, flags = 0;
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
474
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
475 if (objc < 2) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
476 Tcl_WrongNumArgs(interp, 1, objv, "subcommand ?args?");
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
477 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
478 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
479
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
480 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
481 return error;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
482
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
483 switch (cmd) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
484 case CMD_CONV_FIND:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
485 if (objc < 3) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
486 Tcl_WrongNumArgs(interp, 2, objv, "?options? name");
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
487 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
488 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
489 argsused = 2;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
490 account = NULL;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
491 while (argsused < objc) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
492 opt = Tcl_GetString(objv[argsused]);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
493 if (*opt == '-') {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
494 if ((error = Tcl_GetIndexFromObj(interp, objv[argsused], findopts,
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
495 "option", 0, (int *)&findopt)) != TCL_OK)
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
496 return error;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
497 argsused++;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
498 switch (findopt) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
499 case CMD_CONV_FIND_ACCOUNT:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
500 if (argsused == objc - 1) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
501 Tcl_SetStringObj(result, "-account requires an argument", -1);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
502 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
503 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
504 if ((error = Tcl_GetIntFromObj(interp, objv[argsused],
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
505 (int *)&account)) != TCL_OK)
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
506 return error;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
507 if (!tcl_validate_account(account, interp))
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
508 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
509 argsused++;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
510 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
511 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
512 } else {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
513 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
514 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
515 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
516 if (objc - argsused != 1) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
517 Tcl_WrongNumArgs(interp, 2, objv, "?options? name");
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
518 return error;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
519 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
520 if (account != NULL) {
10246
a66cf83552dc [gaim-migrate @ 11386]
Mark Doliner <mark@kingant.net>
parents: 9620
diff changeset
521 convo = gaim_find_conversation_with_account(GAIM_CONV_ANY, Tcl_GetString(objv[argsused]), account);
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
522 } else {
10246
a66cf83552dc [gaim-migrate @ 11386]
Mark Doliner <mark@kingant.net>
parents: 9620
diff changeset
523 convo = gaim_find_conversation(GAIM_CONV_ANY, Tcl_GetString(objv[argsused]));
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
524 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
525 Tcl_SetIntObj(result, (int)convo);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
526 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
527 case CMD_CONV_HANDLE:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
528 if (objc != 2) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
529 Tcl_WrongNumArgs(interp, 2, objv, "");
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
530 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
531 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
532 Tcl_SetIntObj(result, (int)gaim_conversations_get_handle());
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
533 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
534 case CMD_CONV_LIST:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
535 list = Tcl_NewListObj(0, NULL);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
536 for (cur = gaim_get_conversations(); cur != NULL; cur = g_list_next(cur)) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
537 elem = Tcl_NewIntObj((int)cur->data);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
538 Tcl_ListObjAppendElement(interp, list, elem);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
539 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
540 Tcl_SetObjResult(interp, list);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
541 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
542 case CMD_CONV_NEW:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
543 if (objc < 4) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
544 Tcl_WrongNumArgs(interp, 2, objv, "?options? account name");
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
545 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
546 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
547 argsused = 2;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
548 type = GAIM_CONV_IM;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
549 while (argsused < objc) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
550 opt = Tcl_GetString(objv[argsused]);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
551 if (*opt == '-') {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
552 if ((error = Tcl_GetIndexFromObj(interp, objv[argsused], newopts,
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
553 "option", 0, (int *)&newopt)) != TCL_OK)
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
554 return error;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
555 argsused++;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
556 switch (newopt) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
557 case CMD_CONV_NEW_CHAT:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
558 type = GAIM_CONV_CHAT;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
559 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
560 case CMD_CONV_NEW_IM:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
561 type = GAIM_CONV_IM;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
562 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
563 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
564 } else {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
565 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
566 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
567 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
568 if (objc - argsused != 2) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
569 Tcl_WrongNumArgs(interp, 2, objv, "?options? account name");
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
570 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
571 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
572 if ((error = Tcl_GetIntFromObj(interp, objv[argsused++], (int *)&account)) != TCL_OK)
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
573 return error;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
574 if (!tcl_validate_account(account, interp))
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
575 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
576 convo = gaim_conversation_new(type, account, Tcl_GetString(objv[argsused]));
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
577 Tcl_SetIntObj(result, (int)convo);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
578 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
579 case CMD_CONV_WRITE:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
580 if (objc != 6) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
581 Tcl_WrongNumArgs(interp, 2, objv, "conversation style from what");
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
582 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
583 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
584 if ((error = Tcl_GetIntFromObj(interp, objv[2], (int *)&convo)) != 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 ((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
587 return error;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
588 if (!tcl_validate_conversation(convo, interp))
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
589 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
590 from = Tcl_GetString(objv[4]);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
591 what = Tcl_GetString(objv[5]);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
592
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
593 switch (style) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
594 case CMD_CONV_WRITE_SEND:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
595 flags = GAIM_MESSAGE_SEND;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
596 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
597 case CMD_CONV_WRITE_RECV:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
598 flags = GAIM_MESSAGE_RECV;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
599 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
600 case CMD_CONV_WRITE_SYSTEM:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
601 flags = GAIM_MESSAGE_SYSTEM;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
602 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
603 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
604 if (gaim_conversation_get_type(convo) == GAIM_CONV_CHAT)
7118
bf630f7dfdcd [gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents: 7100
diff changeset
605 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
606 else
7118
bf630f7dfdcd [gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents: 7100
diff changeset
607 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
608 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
609 }
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 return TCL_OK;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
612 }
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 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
615 {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
616 Tcl_Obj *result = Tcl_GetObjResult(interp);
10339
3eb03f22e082 [gaim-migrate @ 11548]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
617 const char *cmds[] = { "handle", "quit", NULL };
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
618 enum { CMD_CORE_HANDLE, CMD_CORE_QUIT } cmd;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
619 int error;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
620
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
621 if (objc < 2) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
622 Tcl_WrongNumArgs(interp, 1, objv, "subcommand ?args?");
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
623 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
624 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
625
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
626 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
627 return error;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
628
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
629 switch (cmd) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
630 case CMD_CORE_HANDLE:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
631 if (objc != 2) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
632 Tcl_WrongNumArgs(interp, 2, objv, "");
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
633 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
634 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
635 Tcl_SetIntObj(result, (int)gaim_get_core());
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
636 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
637 case CMD_CORE_QUIT:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
638 if (objc != 2) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
639 Tcl_WrongNumArgs(interp, 2, objv, "");
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
640 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
641 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
642 gaim_core_quit();
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
643 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
644 }
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 return TCL_OK;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
647 }
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 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
650 {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
651 char *category, *message;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
652 int lev;
10339
3eb03f22e082 [gaim-migrate @ 11548]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
653 const char *levels[] = { "-misc", "-info", "-warning", "-error", NULL };
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
654 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
655 int error;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
656
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
657 if (objc != 4) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
658 Tcl_WrongNumArgs(interp, 1, objv, "level category message");
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
659 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
660 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
661
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
662 error = Tcl_GetIndexFromObj(interp, objv[1], levels, "debug level", 0, &lev);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
663 if (error != TCL_OK)
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
664 return error;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
665
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
666 category = Tcl_GetString(objv[2]);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
667 message = Tcl_GetString(objv[3]);
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 gaim_debug(levelind[lev], category, "%s\n", message);
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 return TCL_OK;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
672 }
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 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
675 {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
676 int error, type;
10339
3eb03f22e082 [gaim-migrate @ 11548]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
677 const char *opts[] = { "-error", "-warning", "-info", NULL };
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
678 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
679 char *title, *msg1, *msg2;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
680
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
681 if (objc < 4 || objc > 5) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
682 Tcl_WrongNumArgs(interp, 1, objv, "?type? title primary secondary");
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
683 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
684 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
685
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
686 if (objc == 4) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
687 title = Tcl_GetString(objv[1]);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
688 msg1 = Tcl_GetString(objv[2]);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
689 msg2 = Tcl_GetString(objv[3]);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
690 } else {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
691 error = Tcl_GetIndexFromObj(interp, objv[1], opts, "message type", 0, &type);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
692 if (error != TCL_OK)
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
693 return error;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
694 title = Tcl_GetString(objv[2]);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
695 msg1 = Tcl_GetString(objv[3]);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
696 msg2 = Tcl_GetString(objv[4]);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
697 }
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 gaim_notify_message(_tcl_plugin, optind[type], title, msg1, msg2, NULL, NULL);
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 return TCL_OK;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
702 }
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 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
705 {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
706 Tcl_Obj *result, *list, *elem, **elems;
10339
3eb03f22e082 [gaim-migrate @ 11548]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
707 const char *cmds[] = { "get", "set", "type", NULL };
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
708 enum { CMD_PREFS_GET, CMD_PREFS_SET, CMD_PREFS_TYPE } cmd;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
709 /* char *types[] = { "none", "boolean", "int", "string", "stringlist", NULL }; */
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
710 /* 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
711 GaimPrefType preftype;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
712 GList *cur;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
713 int error, intval, nelem, i;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
714
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
715 if (objc < 2) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
716 Tcl_WrongNumArgs(interp, 1, objv, "subcommand ?args?");
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
717 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
718 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
719
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
720 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
721 return error;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
722
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
723 result = Tcl_GetObjResult(interp);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
724 switch (cmd) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
725 case CMD_PREFS_GET:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
726 if (objc != 3) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
727 Tcl_WrongNumArgs(interp, 1, objv, "path");
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
728 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
729 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
730 preftype = gaim_prefs_get_type(Tcl_GetString(objv[2]));
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
731 switch (preftype) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
732 case GAIM_PREF_NONE:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
733 Tcl_SetStringObj(result, "pref type none", -1);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
734 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
735 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
736 case GAIM_PREF_BOOLEAN:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
737 Tcl_SetBooleanObj(result, gaim_prefs_get_bool(Tcl_GetString(objv[2])));
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
738 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
739 case GAIM_PREF_INT:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
740 Tcl_SetIntObj(result, gaim_prefs_get_int(Tcl_GetString(objv[2])));
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
741 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
742 case GAIM_PREF_STRING:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
743 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
744 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
745 case GAIM_PREF_STRING_LIST:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
746 cur = gaim_prefs_get_string_list(Tcl_GetString(objv[2]));
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
747 list = Tcl_NewListObj(0, NULL);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
748 while (cur != NULL) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
749 elem = Tcl_NewStringObj((char *)cur->data, -1);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
750 Tcl_ListObjAppendElement(interp, list, elem);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
751 cur = g_list_next(cur);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
752 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
753 Tcl_SetObjResult(interp, list);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
754 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
755 default:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
756 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
757 Tcl_SetStringObj(result, "unknown pref type", -1);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
758 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
759 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
760 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
761 case CMD_PREFS_SET:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
762 if (objc != 4) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
763 Tcl_WrongNumArgs(interp, 1, objv, "path value");
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
764 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
765 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
766 preftype = gaim_prefs_get_type(Tcl_GetString(objv[2]));
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
767 switch (preftype) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
768 case GAIM_PREF_NONE:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
769 Tcl_SetStringObj(result, "bad path or pref type none", -1);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
770 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
771 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
772 case GAIM_PREF_BOOLEAN:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
773 if ((error = Tcl_GetBooleanFromObj(interp, objv[3], &intval)) != TCL_OK)
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
774 return error;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
775 gaim_prefs_set_bool(Tcl_GetString(objv[2]), intval);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
776 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
777 case GAIM_PREF_INT:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
778 if ((error = Tcl_GetIntFromObj(interp, objv[3], &intval)) != TCL_OK)
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
779 return error;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
780 gaim_prefs_set_int(Tcl_GetString(objv[2]), intval);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
781 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
782 case GAIM_PREF_STRING:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
783 gaim_prefs_set_string(Tcl_GetString(objv[2]), Tcl_GetString(objv[3]));
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
784 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
785 case GAIM_PREF_STRING_LIST:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
786 if ((error = Tcl_ListObjGetElements(interp, objv[3], &nelem, &elems)) != TCL_OK)
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
787 return error;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
788 cur = NULL;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
789 for (i = 0; i < nelem; i++) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
790 cur = g_list_append(cur, (gpointer)Tcl_GetString(elems[i]));
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
791 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
792 gaim_prefs_set_string_list(Tcl_GetString(objv[2]), cur);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
793 g_list_free(cur);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
794 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
795 default:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
796 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
797 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
798 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
799 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
800 case CMD_PREFS_TYPE:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
801 if (objc != 3) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
802 Tcl_WrongNumArgs(interp, 1, objv, "path");
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
803 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
804 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
805 preftype = gaim_prefs_get_type(Tcl_GetString(objv[2]));
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
806 switch (preftype) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
807 case GAIM_PREF_NONE:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
808 Tcl_SetStringObj(result, "none", -1);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
809 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
810 case GAIM_PREF_BOOLEAN:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
811 Tcl_SetStringObj(result, "boolean", -1);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
812 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
813 case GAIM_PREF_INT:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
814 Tcl_SetStringObj(result, "int", -1);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
815 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
816 case GAIM_PREF_STRING:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
817 Tcl_SetStringObj(result, "string", -1);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
818 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
819 case GAIM_PREF_STRING_LIST:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
820 Tcl_SetStringObj(result, "stringlist", -1);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
821 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
822 default:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
823 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
824 Tcl_SetStringObj(result, "unknown", -1);
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 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
827 }
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 return TCL_OK;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
830 }
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 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
833 {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
834 GaimConnection *gc;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
835 char *who, *text;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
836 int error;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
837 Tcl_Obj *result;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
838
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
839 if (objc != 4) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
840 Tcl_WrongNumArgs(interp, 1, objv, "gc who text");
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
841 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
842 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
843
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
844 if ((error = Tcl_GetIntFromObj(interp, objv[1], (int *)&gc)) != TCL_OK)
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
845 return error;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
846 if (!tcl_validate_gc(gc)) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
847 result = Tcl_GetObjResult(interp);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
848 Tcl_SetStringObj(result, "invalid gc", -1);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
849 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
850 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
851
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
852 who = Tcl_GetString(objv[2]);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
853 text = Tcl_GetString(objv[3]);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
854
6982
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6864
diff changeset
855 serv_send_im(gc, who, text, 0);
6694
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 return TCL_OK;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
858 }
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 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
861 {
10339
3eb03f22e082 [gaim-migrate @ 11548]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
862 const char *cmds[] = { "connect", "disconnect", NULL };
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
863 enum { CMD_SIGNAL_CONNECT, CMD_SIGNAL_DISCONNECT } cmd;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
864 struct tcl_signal_handler *handler;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
865 Tcl_Obj **elems, *result = Tcl_GetObjResult(interp);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
866 void *instance;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
867 int error, nelems, i;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
868
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
869 if (objc < 2) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
870 Tcl_WrongNumArgs(interp, 1, objv, "subcommand ?args?");
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
871 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
872 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
873
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
874 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
875 return error;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
876
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
877 switch (cmd) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
878 case CMD_SIGNAL_CONNECT:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
879 if (objc != 6) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
880 Tcl_WrongNumArgs(interp, 2, objv, "instance signal args proc");
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
881 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
882 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
883 if ((error = Tcl_ListObjGetElements(interp, objv[4], &nelems, &elems)) != TCL_OK)
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
884 return error;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
885 handler = g_new0(struct tcl_signal_handler, 1);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
886 if ((error = Tcl_GetIntFromObj(interp, objv[2], (int *)&handler->instance)) != TCL_OK) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
887 g_free(handler);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
888 return error;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
889 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
890 handler->signal = g_strdup(Tcl_GetString(objv[3]));
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
891 if (nelems) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
892 handler->argnames = g_new0(char *, nelems);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
893 for (i = 0; i < nelems; i++) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
894 handler->argnames[i] = g_strdup(Tcl_GetString(elems[i]));
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
895 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
896 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
897 handler->nnames = nelems;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
898 handler->proc = Tcl_NewStringObj("namespace eval ::gaim::_callback { ", -1);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
899 Tcl_AppendStringsToObj(handler->proc, Tcl_GetString(objv[5]), " }", NULL);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
900 Tcl_IncrRefCount(handler->proc);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
901 handler->interp = interp;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
902 if (!tcl_signal_connect(handler)) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
903 tcl_signal_handler_free(handler);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
904 Tcl_SetIntObj(result, 1);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
905 } else {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
906 Tcl_SetIntObj(result, 0);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
907 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
908 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
909 case CMD_SIGNAL_DISCONNECT:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
910 if (objc != 4) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
911 Tcl_WrongNumArgs(interp, 2, objv, "signal");
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
912 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
913 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
914 if ((error = Tcl_GetIntFromObj(interp, objv[2], (int *)&instance)) != TCL_OK)
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
915 return error;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
916 tcl_signal_disconnect(instance, Tcl_GetString(objv[3]), interp);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
917 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
918 }
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 return TCL_OK;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
921 }
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 static gboolean unload_self(gpointer data)
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
924 {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
925 GaimPlugin *plugin = data;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
926 gaim_plugin_unload(plugin);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
927 return FALSE;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
928 }
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 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
931 {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
932 GaimPlugin *plugin;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
933 if (objc != 1) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
934 Tcl_WrongNumArgs(interp, 1, objv, "");
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
935 return TCL_ERROR;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
936 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
937
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
938 if ((plugin = tcl_interp_get_plugin(interp)) == NULL) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
939 /* This isn't exactly OK, but heh. What do you do? */
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
940 return TCL_OK;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
941 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
942 /* We can't unload immediately, but we can unload at the first
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
943 * known safe opportunity. */
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
944 g_idle_add(unload_self, (gpointer)plugin);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
945
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
946 return TCL_OK;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
947 }