annotate plugins/tcl/tcl_cmds.c @ 13897:eaaf73de9188

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