changeset 13884:eac18261c6f0

[gaim-migrate @ 16364] Let's have chats in the buddylist. committer: Tailor Script <tailor@pidgin.im>
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Wed, 28 Jun 2006 01:46:41 +0000
parents ab6376814e73
children 582aaa4e287e
files console/Makefile console/gntblist.c console/gntui.c console/libgnt/Makefile
diffstat 4 files changed, 83 insertions(+), 37 deletions(-) [+]
line wrap: on
line diff
--- a/console/Makefile	Wed Jun 28 00:21:38 2006 +0000
+++ b/console/Makefile	Wed Jun 28 01:46:41 2006 +0000
@@ -25,6 +25,6 @@
 
 clean:
 	cd libgnt && make clean
-	rm *.o
-	rm gntgaim
+	rm -f *.o
+	rm -f gntgaim
 
--- a/console/gntblist.c	Wed Jun 28 00:21:38 2006 +0000
+++ b/console/gntblist.c	Wed Jun 28 01:46:41 2006 +0000
@@ -24,6 +24,7 @@
 
 static void add_buddy(GaimBuddy *buddy, GGBlist *ggblist);
 static void add_group(GaimGroup *group, GGBlist *ggblist);
+static void add_chat(GaimChat *chat, GGBlist *ggblist);
 static void add_node(GaimBlistNode *node, GGBlist *ggblist);
 static void draw_tooltip(GGBlist *ggblist);
 
@@ -38,6 +39,8 @@
 		add_buddy((GaimBuddy*)node, ggblist);
 	else if (GAIM_BLIST_NODE_IS_GROUP(node))
 		add_group((GaimGroup*)node, ggblist);
+	else if (GAIM_BLIST_NODE_IS_CHAT(node))
+		add_chat((GaimChat *)node, ggblist);
 	draw_tooltip(ggblist);
 }
 
@@ -81,6 +84,10 @@
 		else
 			node_remove(gaim_get_blist(), node);
 	}
+	else if (GAIM_BLIST_NODE_IS_CHAT(node))
+	{
+		add_chat((GaimChat *)node, list->ui_data);
+	}
 }
 
 static void
@@ -121,52 +128,80 @@
 }
 
 static const char *
-get_buddy_display_name(GaimBuddy *buddy)
+get_display_name(GaimBlistNode *node)
 {
 	static char text[2096];
-	char status[8];
-	GaimStatusPrimitive prim;
-	GaimPresence *presence;
-	GaimStatus *now;
+	char status[8] = " ";
+	const char *name = NULL;
 
-	presence = gaim_buddy_get_presence(buddy);
-	now = gaim_presence_get_active_status(presence);
+	if (GAIM_BLIST_NODE_IS_BUDDY(node))
+	{
+		GaimBuddy *buddy = (GaimBuddy *)node;
+		GaimStatusPrimitive prim;
+		GaimPresence *presence;
+		GaimStatus *now;
 
-	prim = gaim_status_type_get_primitive(gaim_status_get_type(now));
+		
+		presence = gaim_buddy_get_presence(buddy);
+		now = gaim_presence_get_active_status(presence);
 
-	switch(prim)
-	{
+		prim = gaim_status_type_get_primitive(gaim_status_get_type(now));
+
+		switch(prim)
+		{
 #if 1
-		case GAIM_STATUS_OFFLINE:
-			strncpy(status, "x", sizeof(status) - 1);
-			break;
-		case GAIM_STATUS_AVAILABLE:
-			strncpy(status, "o", sizeof(status) - 1);
-			break;
-		default:
-			strncpy(status, ".", sizeof(status) - 1);
-			break;
+			case GAIM_STATUS_OFFLINE:
+				strncpy(status, "x", sizeof(status) - 1);
+				break;
+			case GAIM_STATUS_AVAILABLE:
+				strncpy(status, "o", sizeof(status) - 1);
+				break;
+			default:
+				strncpy(status, ".", sizeof(status) - 1);
+				break;
 #else
-		/* XXX: Let's use these some time */
-		case GAIM_STATUS_OFFLINE:
-			strncpy(status, "⊗", sizeof(status) - 1);
-			break;
-		case GAIM_STATUS_AVAILABLE:
-			/* XXX: Detect idleness */
-			strncpy(status, "◯", sizeof(status) - 1);
-			break;
-		default:
-			strncpy(status, "⊖", sizeof(status) - 1);
-			break;
+			/* XXX: Let's use these some time */
+			case GAIM_STATUS_OFFLINE:
+				strncpy(status, "⊗", sizeof(status) - 1);
+				break;
+			case GAIM_STATUS_AVAILABLE:
+				/* XXX: Detect idleness */
+				strncpy(status, "◯", sizeof(status) - 1);
+				break;
+			default:
+				strncpy(status, "⊖", sizeof(status) - 1);
+				break;
 #endif
+		}
+		name = gaim_buddy_get_alias(buddy);
+	}
+	else if (GAIM_BLIST_NODE_IS_CHAT(node))
+	{
+		GaimChat *chat = (GaimChat*)node;
+		name = gaim_chat_get_name(chat);
 	}
 
-	snprintf(text, sizeof(text) - 1, "%s %s", status, gaim_buddy_get_alias(buddy));
+	snprintf(text, sizeof(text) - 1, "%s %s", status, name);
 
 	return text;
 }
 
 static void
+add_chat(GaimChat *chat, GGBlist *ggblist)
+{
+	GaimGroup *group;
+	GaimBlistNode *node = (GaimBlistNode *)chat;
+	if (node->ui_data)
+		return;
+
+	group = gaim_chat_get_group(chat);
+	add_node((GaimBlistNode*)group, ggblist);
+
+	node->ui_data = gnt_tree_add_row_after(GNT_TREE(ggblist->tree), chat,
+				get_display_name(node), group, NULL);
+}
+
+static void
 add_buddy(GaimBuddy *buddy, GGBlist *ggblist)
 {
 	GaimGroup *group;
@@ -178,7 +213,7 @@
 	add_node((GaimBlistNode*)group, ggblist);
 
 	node->ui_data = gnt_tree_add_row_after(GNT_TREE(ggblist->tree), buddy,
-				get_buddy_display_name(buddy), group, NULL);
+				get_display_name(node), group, NULL);
 }
 
 static void
@@ -268,6 +303,15 @@
 
 		title = g_strdup(group->name);
 	}
+	else if (GAIM_BLIST_NODE_IS_CHAT(node))
+	{
+		GaimChat *chat = (GaimChat *)node;
+		GaimAccount *account = chat->account;
+
+		g_string_append_printf(str, _("Account: %s"), gaim_account_get_username(account));
+
+		title = g_strdup(gaim_chat_get_name(chat));
+	}
 	else
 	{
 		g_string_free(str, TRUE);
@@ -325,7 +369,7 @@
 static void
 buddy_status_changed(GaimBuddy *buddy, GaimStatus *old, GaimStatus *now, GGBlist *ggblist)
 {
-	gnt_tree_change_text(GNT_TREE(ggblist->tree), buddy, get_buddy_display_name(buddy));
+	gnt_tree_change_text(GNT_TREE(ggblist->tree), buddy, get_display_name((GaimBlistNode*)buddy));
 	if (ggblist->tnode == (GaimBlistNode*)buddy)
 		draw_tooltip(ggblist);
 }
--- a/console/gntui.c	Wed Jun 28 00:21:38 2006 +0000
+++ b/console/gntui.c	Wed Jun 28 01:46:41 2006 +0000
@@ -12,6 +12,8 @@
 	gg_blist_init();
 	gaim_blist_set_ui_ops(gg_blist_get_ui_ops());
 
+	/* Now the conversations */
+
 	gnt_main();
 }
 
--- a/console/libgnt/Makefile	Wed Jun 28 00:21:38 2006 +0000
+++ b/console/libgnt/Makefile	Wed Jun 28 01:46:41 2006 +0000
@@ -57,6 +57,6 @@
 	$(CC) --shared -o libgnt.so $(OBJECTS)
 
 clean:
-	rm *.o
-	rm libgnt.so
+	rm -f *.o
+	rm -f libgnt.so