int CompareContacts( const struct ClcContact *contact1, const struct ClcContact *contact2 ) { MCONTACT a = contact1->hContact, b = contact2->hContact; TCHAR *namea,*nameb; int statusa,statusb; char *szProto1,*szProto2; int rc; GetContactInfosForSort(a,&szProto1,&namea,&statusa); GetContactInfosForSort(b,&szProto2,&nameb,&statusb); if (sortByProto) { /* deal with statuses, online contacts have to go above offline */ if (sortNoOfflineBottom == 0) if ((statusa == ID_STATUS_OFFLINE) != (statusb == ID_STATUS_OFFLINE)) { return 2*(statusa == ID_STATUS_OFFLINE)-1; } /* both are online, now check protocols */ rc = strcmp(SAFESTRING(szProto1),SAFESTRING(szProto2)); /* strcmp() doesn't like NULL so feed in "" as needed */ if (rc != 0 && (szProto1 != NULL && szProto2 != NULL)) return rc; /* protocols are the same, order by display name */ } if (sortByStatus) { int ordera,orderb; ordera = GetStatusModeOrdering(statusa); orderb = GetStatusModeOrdering(statusb); if (ordera != orderb) return ordera-orderb; } else { //one is offline: offline goes below online if (sortNoOfflineBottom == 0) { if ((statusa == ID_STATUS_OFFLINE) != (statusb == ID_STATUS_OFFLINE)) { return 2*(statusa == ID_STATUS_OFFLINE)-1; } } } //otherwise just compare names return _tcsicmp(namea,nameb); }
int CompareContacts2(WPARAM wParam,LPARAM lParam, int by) { HANDLE a=(HANDLE)wParam,b=(HANDLE)lParam; char *namea, *nameb; int statusa,statusb; char *szProto1,*szProto2; GetContactInfosForSort(a,&szProto1,&namea,&statusa); GetContactInfosForSort(b,&szProto2,&nameb,&statusb); if (by==1) { //status int ordera,orderb; ordera=GetStatusModeOrdering(statusa); orderb=GetStatusModeOrdering(statusb); if(ordera!=orderb) return ordera-orderb; else return 0; } if(sortNoOfflineBottom==0 && (statusa==ID_STATUS_OFFLINE)!=(statusb==ID_STATUS_OFFLINE)) { //one is offline: offline goes below online return 2*(statusa==ID_STATUS_OFFLINE)-1; } if (by==0) { //name return MyStrCmpi(namea,nameb); } else if (by==2) { //last message DWORD ta=CompareContacts2_getLMTime(a); DWORD tb=CompareContacts2_getLMTime(b); return tb-ta; } else if (by==3) { int rc=GetProtoIndex(szProto1)-GetProtoIndex(szProto2); if (rc != 0 && (szProto1 != NULL && szProto2 != NULL)) return rc; } // else :o) return 0; }