changeset 6746:c45c90c8ce8a

[gaim-migrate @ 7278] This brings contact support to Tcl's 'gaim::buddy list'. I'm not sure if this is its final format, but at least contacts are available... committer: Tailor Script <tailor@pidgin.im>
author Ethan Blanton <elb@pidgin.im>
date Thu, 04 Sep 2003 23:31:53 +0000
parents 57a24492434b
children 82348b5ab87e
files plugins/tcl/tcl_cmds.c
diffstat 1 files changed, 31 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/tcl/tcl_cmds.c	Thu Sep 04 23:08:57 2003 +0000
+++ b/plugins/tcl/tcl_cmds.c	Thu Sep 04 23:31:53 2003 +0000
@@ -254,13 +254,13 @@
 
 int tcl_cmd_buddy(ClientData unused, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[])
 {
-	Tcl_Obj *list, *tclgroup, *tclgrouplist, *tclbud, **elems, *result;
+	Tcl_Obj *list, *tclgroup, *tclgrouplist, *tclcontact, *tclcontactlist, *tclbud, **elems, *result;
 	char *cmds[] = { "alias", "handle", "info", "list", NULL };
 	enum { CMD_BUDDY_ALIAS, CMD_BUDDY_HANDLE, CMD_BUDDY_INFO, CMD_BUDDY_LIST } cmd;
 	struct gaim_buddy_list *blist;
-	GaimBlistNode *node, *gnode;
+	GaimBlistNode *node, *gnode, *bnode;
 	GaimAccount *account;
-	GaimBuddy *bnode;
+	GaimBuddy *bud;
 	GaimBlistChat *cnode;
 	int error, all = 0, count;
 
@@ -345,14 +345,32 @@
 			tclgrouplist = Tcl_NewListObj(0, NULL);
 			for (node = gnode->child; node != NULL; node = node->next) {
 				switch (node->type) {
-				case GAIM_BLIST_BUDDY_NODE:
-					bnode = (GaimBuddy *)node;
-					if (!all && !gaim_account_is_connected(bnode->account))
-						continue;
-					tclbud = Tcl_NewListObj(0, NULL);
-					Tcl_ListObjAppendElement(interp, tclbud, Tcl_NewStringObj("buddy", -1));
-					Tcl_ListObjAppendElement(interp, tclbud, Tcl_NewStringObj(bnode->name, -1));
-					Tcl_ListObjAppendElement(interp, tclbud, Tcl_NewIntObj((int)bnode->account));
+				case GAIM_BLIST_CONTACT_NODE:
+					tclcontact = Tcl_NewListObj(0, NULL);
+					Tcl_IncrRefCount(tclcontact);
+					Tcl_ListObjAppendElement(interp, tclcontact, Tcl_NewStringObj("contact", -1));
+					tclcontactlist = Tcl_NewListObj(0, NULL);
+					Tcl_IncrRefCount(tclcontactlist);
+					count = 0;
+					for (bnode = node->child; bnode != NULL; bnode = bnode ->next) {
+						if (bnode->type != GAIM_BLIST_BUDDY_NODE)
+							continue;
+						bud = (GaimBuddy *)bnode;
+						if (!all && !gaim_account_is_connected(bud->account))
+							continue;
+						count++;
+						tclbud = Tcl_NewListObj(0, NULL);
+						Tcl_ListObjAppendElement(interp, tclbud, Tcl_NewStringObj("buddy", -1));
+						Tcl_ListObjAppendElement(interp, tclbud, Tcl_NewStringObj(bud->name, -1));
+						Tcl_ListObjAppendElement(interp, tclbud, Tcl_NewIntObj((int)bud->account));
+						Tcl_ListObjAppendElement(interp, tclcontactlist, tclbud);
+					}
+					if (count) {
+						Tcl_ListObjAppendElement(interp, tclcontact, tclcontactlist);
+						Tcl_ListObjAppendElement(interp, tclgrouplist, tclcontact);
+					}
+					Tcl_DecrRefCount(tclcontact);
+					Tcl_DecrRefCount(tclcontactlist);
 					break;
 				case GAIM_BLIST_CHAT_NODE:
 					cnode = (GaimBlistChat *)node;
@@ -362,11 +380,12 @@
 					Tcl_ListObjAppendElement(interp, tclbud, Tcl_NewStringObj("chat", -1));
 					Tcl_ListObjAppendElement(interp, tclbud, Tcl_NewStringObj(cnode->alias, -1));
 					Tcl_ListObjAppendElement(interp, tclbud, Tcl_NewIntObj((int)cnode->account));
+					Tcl_ListObjAppendElement(interp, tclgrouplist, tclbud);
 					break;
 				default:
+					gaim_debug(GAIM_DEBUG_WARNING, "tcl", "Unexpected buddy type %d", node->type);
 					continue;
 				}
-				Tcl_ListObjAppendElement(interp, tclgrouplist, tclbud);
 			}
 			Tcl_ListObjAppendElement(interp, tclgroup, tclgrouplist);
 			Tcl_ListObjAppendElement(interp, list, tclgroup);