soc.2009.vulture: 8fd38fdf: Show status icons in buddy list.

gdick at soc.pidgin.im gdick at soc.pidgin.im
Fri Jul 31 16:15:52 EDT 2009


-----------------------------------------------------------------
Revision: 8fd38fdf765a3b981dda6a4657d28e0247f8a53f
Ancestor: ab2e8a210fef618b45ef09fad85b8750f7bc6175
Author: gdick at soc.pidgin.im
Date: 2009-07-30T15:54:08
Branch: im.pidgin.soc.2009.vulture
URL: http://d.pidgin.im/viewmtn/revision/info/8fd38fdf765a3b981dda6a4657d28e0247f8a53f

Modified files:
        vulture/purpleblist.c vulture/res/status.bmp
        vulture/vultureblist.c vulture/vultureblist.h

ChangeLog: 

Show status icons in buddy list.

-------------- next part --------------
============================================================
--- vulture/purpleblist.c	4000dfae5d0ab34ce674b793b4acc6e1279d9bf9
+++ vulture/purpleblist.c	a65035b950969f1d2881f18ce4c1f8baa21ffaa7
@@ -36,7 +36,8 @@ static void DeleteBuddyFromAccount(Purpl
 static BOOL ShouldShowNode(PurpleBlistNode *lpblistnode);
 static void AddCommonMenuItems(HMENU hmenu, PurpleBlistNode *lpblistnode, GList **lplpglistVMA, PurpleConnection *lpconnection, int iProtoIndex, int iExtendedIndex);
 static void DeleteBuddyFromAccount(PurpleBuddy *lpbuddy);
-static void UpdateStatusText(PurpleBlistNode *lpblistnode);
+static void UpdateCachedStatus(PurpleBlistNode *lpblistnode);
+static int GetStatusIconIndex(PurpleBuddy *lpbuddy);
 
 
 
@@ -76,6 +77,7 @@ void PurpleBlistUpdateNode(PurpleBuddyLi
 		lpvbn->lpvbnParent = NULL;
 		lpvbn->bExpanded = FALSE;
 		lpvbn->szStatusText = NULL;
+		lpvbn->iStatusIcon = 0;
 		InitializeCriticalSection(&lpvbn->cs);
 	}
 
@@ -91,7 +93,7 @@ void PurpleBlistUpdateNode(PurpleBuddyLi
 
 			lpvbn->nodetype = lpblistnode->type;
 
-			UpdateStatusText(lpblistnode);
+			UpdateCachedStatus(lpblistnode);
 
 			switch(lpblistnode->type)
 			{
@@ -115,7 +117,7 @@ void PurpleBlistUpdateNode(PurpleBuddyLi
 				/* Maybe our contact needs to update its status
 				 * text.
 				 */
-				UpdateStatusText(lpblistnode->parent);
+				UpdateCachedStatus(lpblistnode->parent);
 
 				szNodeText = purple_buddy_get_alias((PurpleBuddy*)lpblistnode);
 
@@ -351,8 +353,8 @@ void PurpleBuddyStatusChanged(PurpleBudd
 	PurpleConversation *lpconv;
 	VULTURE_BLIST_NODE *lpvbnContact = ((PurpleBlistNode*)lpbuddy)->parent ? ((PurpleBlistNode*)lpbuddy)->parent->ui_data : NULL;
 
-	UpdateStatusText((PurpleBlistNode*)lpbuddy);
-	UpdateStatusText(((PurpleBlistNode*)lpbuddy)->parent);
+	UpdateCachedStatus((PurpleBlistNode*)lpbuddy);
+	UpdateCachedStatus(((PurpleBlistNode*)lpbuddy)->parent);
 
 	if(lpvbnContact)
 	{
@@ -624,11 +626,11 @@ static void DeleteBuddyFromAccount(Purpl
 
 
 /**
- * Updates the status text cached in a buddy-list node.
+ * Updates the status information cached in a buddy-list node.
  *
  * @param	lpblistnode	Buddy-list node.
  */
-static void UpdateStatusText(PurpleBlistNode *lpblistnode)
+static void UpdateCachedStatus(PurpleBlistNode *lpblistnode)
 {
 	VULTURE_BLIST_NODE *lpvblistnode;
 
@@ -643,14 +645,49 @@ static void UpdateStatusText(PurpleBlist
 		lpvblistnode->szStatusText = NULL;
 
 		if(PURPLE_BLIST_NODE_IS_BUDDY(lpblistnode))
+		{
 			lpvblistnode->szStatusText = PurpleBuddyGetStatusText((PurpleBuddy*)lpblistnode);
+			lpvblistnode->iStatusIcon = GetStatusIconIndex((PurpleBuddy*)lpblistnode);
+		}
 		else if(PURPLE_BLIST_NODE_IS_CONTACT(lpblistnode))
 		{
 			PurpleBuddy *lpbuddy = purple_contact_get_priority_buddy((PurpleContact*)lpblistnode);
 
 			if(lpbuddy)
+			{
 				lpvblistnode->szStatusText = PurpleBuddyGetStatusText(lpbuddy);
+				lpvblistnode->iStatusIcon = GetStatusIconIndex(lpbuddy);
+			}
 		}
 	}
 	LeaveCriticalSection(&lpvblistnode->cs);
 }
+
+
+/**
+ * Retrieves the status icon index for a buddy.
+ *
+ * @param	lpbuddy		Buddy.
+ */
+static int GetStatusIconIndex(PurpleBuddy *lpbuddy)
+{
+	const struct { PurpleStatusPrimitive statusprim; int iIndex; } c_rgprimiconpair[] =
+	{
+		{PURPLE_STATUS_UNAVAILABLE, SICON_BUSY},
+		{PURPLE_STATUS_AWAY, SICON_AWAY},
+		{PURPLE_STATUS_EXTENDED_AWAY, SICON_EXTAWAY},
+		{PURPLE_STATUS_OFFLINE, SICON_OFFLINE},
+		{PURPLE_STATUS_INVISIBLE, SICON_INVISIBLE}
+	};
+
+	PurplePresence *lppresence = purple_buddy_get_presence(lpbuddy);
+	int i;
+
+	for(i = 0; i < (int)NUM_ELEMENTS(c_rgprimiconpair); i++)
+	{
+		if(purple_presence_is_status_primitive_active(lppresence, c_rgprimiconpair[i].statusprim))
+			return c_rgprimiconpair[i].iIndex;
+	}
+
+	return SICON_AVAILABLE;
+}
============================================================
# vulture/res/status.bmp is binary
============================================================
--- vulture/vultureblist.c	e8956ec9ef47112af9bce18e6e08890b7c17fa00
+++ vulture/vultureblist.c	bf8b0c2b28339f9e533dd8c82a9d30b83a62e244
@@ -64,8 +64,10 @@ static void DrawBListNodeExtra(LPNMTVCUS
 static void DrawBListNodeExtra(LPNMTVCUSTOMDRAW lpnmtvcdraw);
 
 
-#define BLIST_MARGIN 6
-#define CX_STATUSICON 16
+#define BLIST_MARGIN		6
+#define CX_STATUSICON		16
+#define CY_STATUSICON		16
+#define CX_BLISTNODEINTSPACER	8
 
 enum CONTEXT_MENU_INDICES
 {
@@ -75,17 +77,7 @@ enum CONTEXT_MENU_INDICES
 	CMI_CHAT,
 };
 
-enum STATUS_ICONS
-{
-	SICON_AVAILABLE = 0,
-	SICON_AWAY,
-	SICON_BUSY,
-	SICON_INVISIBLE,
-	SICON_OFFLINE,
-	SICON_EXTAWAY,
-};
 
-
 HWND g_hwndMain = NULL;
 GList *g_lpglistConvContainers = NULL;
 
@@ -1245,6 +1237,39 @@ static void DrawBListNodeExtra(LPNMTVCUS
 
 	EnterCriticalSection(&lpvblistnode->cs);
 	{
+		/* Draw icon. */
+		if(lpvblistnode->nodetype != PURPLE_BLIST_GROUP_NODE)
+		{
+			int xIcon = rcText.left;
+			int yIcon = (rcText.bottom + rcText.top - CY_STATUSICON) / 2;
+			int iIndex = -1;
+
+			/* Adjust text rectangle for icon. */
+			rcText.left += CX_STATUSICON + CX_BLISTNODEINTSPACER;
+
+			switch(lpvblistnode->nodetype)
+			{
+			case PURPLE_BLIST_CONTACT_NODE:
+				if(lpvblistnode->bExpanded)
+					iIndex = SICON_PERSON;
+				else
+					/* Fall through. */
+			case PURPLE_BLIST_BUDDY_NODE:
+					iIndex = lpvblistnode->iStatusIcon;
+				break;
+
+			case PURPLE_BLIST_CHAT_NODE:
+				iIndex = SICON_CHAT;
+				break;
+
+			default:
+				break;
+			}
+
+			if(iIndex >= 0)
+				ImageList_Draw(g_himlStatusIcons, iIndex, lpnmtvcdraw->nmcd.hdc, xIcon, yIcon, ILD_NORMAL);
+		}
+
 		if(lpvblistnode->szStatusText &&
 			((lpvblistnode->nodetype == PURPLE_BLIST_CONTACT_NODE && !lpvblistnode->bExpanded) ||
 			lpvblistnode->nodetype == PURPLE_BLIST_BUDDY_NODE))
============================================================
--- vulture/vultureblist.h	516f25b18eb0dc962795616b27cea8c7e491c601
+++ vulture/vultureblist.h	fbed41f6358e7ee4666133e5a6c21a3d1d38c9c5
@@ -41,6 +41,9 @@ typedef struct _VULTURE_BLIST_NODE
 	LONG				lRefCount;
 	CRITICAL_SECTION		cs;
 
+	/* For contacts and buddies. */
+	int				iStatusIcon;
+
 	/* For contacts. */
 	BOOL				bExpanded;
 } VULTURE_BLIST_NODE;
@@ -64,6 +67,22 @@ typedef struct _VULTURE_BLIST_NODE_STRIN
 } VULTURE_BLIST_NODE_STRING_PAIR;
 
 
+
+enum VULTURE_STATUS_ICONS
+{
+	SICON_AVAILABLE = 0,
+	SICON_AWAY,
+	SICON_BUSY,
+	SICON_INVISIBLE,
+	SICON_OFFLINE,
+	SICON_EXTAWAY,
+	SICON_LOGIN,
+	SICON_LOGOUT,
+	SICON_PERSON,
+	SICON_CHAT
+};
+
+
 extern HWND g_hwndMain;
 GList *g_lpglistConvContainers;
 


More information about the Commits mailing list