soc.2009.vulture: 644f7d71: Sort the user-list after changing it.
gdick at soc.pidgin.im
gdick at soc.pidgin.im
Fri Jul 10 18:05:58 EDT 2009
-----------------------------------------------------------------
Revision: 644f7d71ea77a3f757bc517c382692ecbb059694
Ancestor: 3ac7195006caa9a9e7315d064a29eefb42a3d8a4
Author: gdick at soc.pidgin.im
Date: 2009-07-10T14:32:58
Branch: im.pidgin.soc.2009.vulture
URL: http://d.pidgin.im/viewmtn/revision/info/644f7d71ea77a3f757bc517c382692ecbb059694
Modified files:
vulture/vultureconv.c vulture/vultureconv.h
ChangeLog:
Sort the user-list after changing it.
-------------- next part --------------
============================================================
--- vulture/vultureconv.c e3b594801e05add88a6a563e9a641f59eef9ca91
+++ vulture/vultureconv.c f670f8343fce3ee2ca257db8712b18e556a9077d
@@ -65,6 +65,8 @@ static void FreeChatUser(void *lpvChatUs
static void SetConvTitle(VULTURE_CONVERSATION *lpvconv, HWND hwndTabs, LPTSTR szTitle);
static void UpdateIMStatusText(HWND hwndDlg, VULTURE_CONVERSATION *lpvconv);
static void FreeChatUser(void *lpvChatUser);
+static int CALLBACK UserListComparator(LPARAM lParam1, LPARAM lParam2, LPARAM lParamUnused);
+static INLINE void SortUserList(HWND hwndTVUsers);
/**
@@ -477,6 +479,7 @@ static INT_PTR CALLBACK ChatDlgProc(HWND
VULTURE_ADD_CHAT_USER *lpvaddchatuser = lpglistRover->data;
TVINSERTSTRUCT tvis;
+ lpvcu->szName = _tcsdup(lpvaddchatuser->szName);
lpvcu->szAlias = lpvaddchatuser->szAlias ? _tcsdup(lpvaddchatuser->szAlias) : NULL;
lpvcu->szAliasKey = lpvaddchatuser->szAliasKey ? _tcsdup(lpvaddchatuser->szAliasKey) : NULL;
lpvcu->bIsBuddy = lpvaddchatuser->bIsBuddy;
@@ -495,6 +498,8 @@ static INT_PTR CALLBACK ChatDlgProc(HWND
}
VultureFreeChatAddUsers(lpvchataddusers);
+
+ SortUserList(hwndTVNames);
}
break;
@@ -529,6 +534,8 @@ static INT_PTR CALLBACK ChatDlgProc(HWND
TreeView_SetItem(hwndTVNames, &tvitem);
VultureFreeRenameUser(lpvchatrenameuser);
+
+ SortUserList(hwndTVNames);
}
break;
@@ -551,6 +558,8 @@ static INT_PTR CALLBACK ChatDlgProc(HWND
}
VultureFreeChatRemoveUsers(lpvchatremoveusers);
+
+ SortUserList(hwndTVNames);
}
break;
@@ -932,8 +941,71 @@ static void FreeChatUser(void *lpvChatUs
{
VULTURE_CHAT_USER *lpvchatuser = (VULTURE_CHAT_USER*)lpvChatUser;
+ free(lpvchatuser->szName);
if(lpvchatuser->szAlias) free(lpvchatuser->szAlias);
if(lpvchatuser->szAliasKey) free(lpvchatuser->szAliasKey);
ProcHeapFree(lpvchatuser);
}
+
+
+/**
+ * Comparator for comparing two user-list entries in a chat. Intended for use
+ * with TreeView_SortChildrenCB.
+ *
+ * @param lParam1 Address of first entry's VULTURE_CHAT_USER.
+ * @param lParam2 Address of second entry's VULTURE_CHAT_USER.
+ * @param lParamUnused Unused.
+ *
+ * @return Negative/zero/positive as the first entry should come resp. before/
+ * at/after the second.
+ */
+static int CALLBACK UserListComparator(LPARAM lParam1, LPARAM lParam2, LPARAM lParamUnused)
+{
+ /* Ranks in decreasing order of seniority. */
+ const int c_iRankedFlags[] =
+ {
+ PURPLE_CBFLAGS_FOUNDER,
+ PURPLE_CBFLAGS_OP,
+ PURPLE_CBFLAGS_HALFOP,
+ PURPLE_CBFLAGS_VOICE
+ };
+
+ VULTURE_CHAT_USER *lpvchatuser1 = (VULTURE_CHAT_USER*)lParam1;
+ VULTURE_CHAT_USER *lpvchatuser2 = (VULTURE_CHAT_USER*)lParam2;
+ int iRank1 = 0, iRank2 = 0;
+ int i;
+
+ UNREFERENCED_PARAMETER(lParamUnused);
+
+ /* Compute ranks based on flags. */
+ for(i = 0; i < (int)NUM_ELEMENTS(c_iRankedFlags) && !(lpvchatuser1->pccbflags & c_iRankedFlags[i]); i++)
+ iRank1++;
+
+ for(i = 0; i < (int)NUM_ELEMENTS(c_iRankedFlags) && !(lpvchatuser2->pccbflags & c_iRankedFlags[i]); i++)
+ iRank2++;
+
+ /* If ranks are different, the lower comes first. */
+ if(iRank1 != iRank2)
+ return iRank1 - iRank2;
+
+ /* If ranks are equal, compare the names. */
+ return _tcscmp(lpvchatuser1->szName, lpvchatuser2->szName);
+}
+
+
+/**
+ * Sorts the user-list in a chat.
+ *
+ * @param hwndTVUsers User-list window handle.
+ */
+static INLINE void SortUserList(HWND hwndTVUsers)
+{
+ TVSORTCB tvsortcb;
+
+ tvsortcb.hParent = TVI_ROOT;
+ tvsortcb.lParam = 0;
+ tvsortcb.lpfnCompare = UserListComparator;
+
+ TreeView_SortChildrenCB(hwndTVUsers, &tvsortcb, FALSE);
+}
============================================================
--- vulture/vultureconv.h 805ea9076253aad94f63a799077e7b0faf1de0b3
+++ vulture/vultureconv.h 908b9437a1729d9f7d08505e29c67aec29850d65
@@ -99,8 +99,7 @@ typedef struct _VULTURE_CHAT_USER
typedef struct _VULTURE_CHAT_USER
{
- /* We don't store the name here. */
-
+ LPTSTR szName;
LPTSTR szAlias;
LPTSTR szAliasKey;
BOOL bIsBuddy;
More information about the Commits
mailing list