int cliCompareContacts(const ClcContact *contact1, const ClcContact *contact2) { ClcCacheEntry *c1 = contact1->pce, *c2 = contact2->pce; for (int i = 0; i < _countof(g_CluiData.bSortByOrder); i++) { BYTE &by = g_CluiData.bSortByOrder[i]; if (by == SORTBY_STATUS) { //status int ordera = GetStatusModeOrdering(c1->getStatus()); int orderb = GetStatusModeOrdering(c2->getStatus()); if (ordera == orderb) continue; return ordera - orderb; } // one is offline: offline goes below online if (!g_CluiData.fSortNoOfflineBottom) { int statusa = c1->getStatus(); int statusb = c2->getStatus(); if ((statusa == ID_STATUS_OFFLINE) != (statusb == ID_STATUS_OFFLINE)) return 2 * (statusa == ID_STATUS_OFFLINE) - 1; } int r = 0; switch (by) { case SORTBY_NAME: // name r = mir_wstrcmpi(contact1->szText, contact2->szText); break; case SORTBY_NAME_LOCALE: // name if (LocaleId == -1) LocaleId = Langpack_GetDefaultLocale(); r = CompareString(LocaleId, NORM_IGNORECASE, SAFETSTRING(contact1->szText), -1, SAFETSTRING(contact2->szText), -1) - 2; break; case SORTBY_LASTMSG: // last message r = (int)CompareContacts2_getLMTime(contact2->hContact) - (int)CompareContacts2_getLMTime(contact1->hContact); break; case SORTBY_PROTO: if (contact1->proto == nullptr || contact2->proto == nullptr) continue; r = GetProtoIndex(contact1->proto) - GetProtoIndex(contact2->proto); break; case SORTBY_RATE: r = contact2->bContactRate - contact1->bContactRate; // reverse order break; default: // should never happen continue; } if (r != 0) return r; } return 0; }
int CompareContacts2(const ClcContact *contact1, const ClcContact *contact2, int by) { TCHAR *namea, *nameb; int statusa, statusb; char *szProto1, *szProto2; if ((INT_PTR)contact1 < 100 || (INT_PTR)contact2 < 100) return 0; MCONTACT a = contact1->hContact; MCONTACT b = contact2->hContact; namea = (TCHAR *)contact1->szText; statusa = GetContactCachedStatus(contact1->hContact); szProto1 = contact1->proto; nameb = (TCHAR *)contact2->szText; statusb = GetContactCachedStatus(contact2->hContact); szProto2 = contact2->proto; if (by == SORTBY_STATUS) { //status int ordera, orderb; ordera = GetStatusModeOrdering(statusa); orderb = GetStatusModeOrdering(statusb); return (ordera != orderb) ? ordera - orderb : 0; } //one is offline: offline goes below online if (g_CluiData.fSortNoOfflineBottom == 0 && (statusa == ID_STATUS_OFFLINE) != (statusb == ID_STATUS_OFFLINE)) return 2 * (statusa == ID_STATUS_OFFLINE) - 1; if (by == SORTBY_NAME) //name return mir_tstrcmpi(namea, nameb); if (by == SORTBY_NAME_LOCALE) { //name static int LocaleId = -1; if (LocaleId == -1) LocaleId = Langpack_GetDefaultLocale(); return (CompareString(LocaleId, NORM_IGNORECASE, SAFETSTRING(namea), -1, SAFETSTRING(nameb), -1)) - 2; } if (by == SORTBY_LASTMSG) { //last message DWORD ta = CompareContacts2_getLMTime(a); DWORD tb = CompareContacts2_getLMTime(b); return tb - ta; } if (by == SORTBY_PROTO) { int rc = GetProtoIndex(szProto1) - GetProtoIndex(szProto2); if (rc != 0 && (szProto1 != NULL && szProto2 != NULL)) return rc; } else if (by == SORTBY_RATE) return contact2->bContactRate - contact1->bContactRate; // else :o) return 0; }
static INT_PTR CompareContacts(WPARAM wParam, LPARAM lParam) { MCONTACT a = wParam, b = lParam; TCHAR namea[128], *nameb; int statusa, statusb; char *szProto1, *szProto2; int rc; szProto1 = GetContactProto(a); szProto2 = GetContactProto(b); statusa = db_get_w(a, SAFESTRING(szProto1), "Status", ID_STATUS_OFFLINE); statusb = db_get_w(b, SAFESTRING(szProto2), "Status", ID_STATUS_OFFLINE); if (sortByProto) { /* deal with statuses, online contacts have to go above offline */ 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 ((statusa == ID_STATUS_OFFLINE) != (statusb == ID_STATUS_OFFLINE)) { return 2 * (statusa == ID_STATUS_OFFLINE) - 1; } } nameb = cli.pfnGetContactDisplayName(a, 0); _tcsncpy(namea, nameb, SIZEOF(namea)); namea[ SIZEOF(namea)-1 ] = 0; nameb = cli.pfnGetContactDisplayName(b, 0); //otherwise just compare names return _tcsicmp(namea, nameb); }
int CompareContacts(WPARAM wParam, LPARAM lParam) { HANDLE a = (HANDLE) wParam,b = (HANDLE) lParam; TCHAR namea[128], *nameb; int statusa, statusb; char *szProto1, *szProto2; int rc; szProto1 = (char*) CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM) a, 0); szProto2 = (char*) CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM) b, 0); statusa = DBGetContactSettingWord((HANDLE) a, SAFESTRING(szProto1), "Status", ID_STATUS_OFFLINE); statusb = DBGetContactSettingWord((HANDLE) b, SAFESTRING(szProto2), "Status", ID_STATUS_OFFLINE); if (sortByProto) { /* deal with statuses, online contacts have to go above offline */ 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 ((statusa == ID_STATUS_OFFLINE) != (statusb == ID_STATUS_OFFLINE)) { return 2 * (statusa == ID_STATUS_OFFLINE) - 1; } } nameb = GetContactDisplayNameW(a, 0); _tcsncpy(namea, nameb, safe_sizeof(namea)); namea[safe_sizeof(namea) - 1] = 0; nameb = GetContactDisplayNameW(b, 0); //otherwise just compare names return CompareString(LOCALE_USER_DEFAULT, NORM_IGNORECASE, namea, -1, nameb, -1) - 2; //return _tcsicmp(namea,nameb); }
int fnCompareContacts(const ClcContact* c1, const ClcContact* c2) { MCONTACT a = c1->hContact, b = c2->hContact; TCHAR namea[128], *nameb; int statusa, statusb; int rc; statusa = db_get_w(a, c1->proto, "Status", ID_STATUS_OFFLINE); statusb = db_get_w(b, c2->proto, "Status", ID_STATUS_OFFLINE); if (sortByProto) { /* deal with statuses, online contacts have to go above offline */ if ((statusa == ID_STATUS_OFFLINE) != (statusb == ID_STATUS_OFFLINE)) { return 2 * (statusa == ID_STATUS_OFFLINE) - 1; } /* both are online, now check protocols */ if (c1->proto != NULL && c2->proto != NULL) { rc = mir_strcmp(c1->proto, c2->proto); if (rc != 0) return rc; } /* protocols are the same, order by display name */ } if (sortByStatus) { int ordera = GetStatusModeOrdering(statusa); int orderb = GetStatusModeOrdering(statusb); if (ordera != orderb) return ordera - orderb; } else { //one is offline: offline goes below online if ((statusa == ID_STATUS_OFFLINE) != (statusb == ID_STATUS_OFFLINE)) return 2 * (statusa == ID_STATUS_OFFLINE) - 1; } nameb = cli.pfnGetContactDisplayName(a, 0); _tcsncpy(namea, nameb, SIZEOF(namea)); namea[ SIZEOF(namea)-1 ] = 0; nameb = cli.pfnGetContactDisplayName(b, 0); //otherwise just compare names return _tcsicmp(namea, nameb); }
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; }
int __forceinline INTSORT_CompareContacts(const ClcContact* c1, const ClcContact* c2, UINT bywhat) { TCHAR *namea, *nameb; int statusa, statusb; char *szProto1, *szProto2; int rc; if (c1 == 0 || c2 == 0) return 0; szProto1 = c1->proto; szProto2 = c2->proto; statusa = c1->wStatus; statusb = c2->wStatus; // make sure, sticky contacts are always at the beginning of the group/list if ((c1->flags & CONTACTF_STICKY) != (c2->flags & CONTACTF_STICKY)) return 2 * (c2->flags & CONTACTF_STICKY) - 1; if (bywhat == SORTBY_PRIOCONTACTS) { if ((cfg::clcdat->exStyle & CLS_EX_DIVIDERONOFF) && ((c1->flags & CONTACTF_ONLINE) != (c2->flags & CONTACTF_ONLINE))) return 0; if ((c1->flags & CONTACTF_PRIORITY) != (c2->flags & CONTACTF_PRIORITY)) return 2 * (c2->flags & CONTACTF_PRIORITY) - 1; else return 0; } if (bywhat == SORTBY_STATUS) { int ordera, orderb; ordera = GetStatusModeOrdering(statusa); orderb = GetStatusModeOrdering(statusb); if (ordera != orderb) return ordera - orderb; else return 0; } // separate contacts treated as "offline" if (!cfg::dat.bDontSeparateOffline && ((statusa == ID_STATUS_OFFLINE) != (statusb == ID_STATUS_OFFLINE))) return 2 * (statusa == ID_STATUS_OFFLINE) - 1; switch (bywhat) { case SORTBY_NAME: namea = (TCHAR *)c1->szText; nameb = (TCHAR *)c2->szText; return CompareString(LOCALE_USER_DEFAULT, NORM_IGNORECASE, namea, -1, nameb, -1) - 2; case SORTBY_LASTMSG: if (c1->pExtra && c2->pExtra) return c2->pExtra->dwLastMsgTime - c1->pExtra->dwLastMsgTime; else { DWORD timestamp1 = INTSORT_GetLastMsgTime(c1->hContact); DWORD timestamp2 = INTSORT_GetLastMsgTime(c2->hContact); return timestamp2 - timestamp1; } case SORTBY_FREQUENCY: if (c1->pExtra && c2->pExtra) return c1->pExtra->msgFrequency - c2->pExtra->msgFrequency; break; case SORTBY_PROTO: if (c1->bIsMeta) szProto1 = c1->metaProto ? c1->metaProto : c1->proto; if (c2->bIsMeta) szProto2 = c2->metaProto ? c2->metaProto : c2->proto; rc = GetProtoIndex(szProto1) - GetProtoIndex(szProto2); if (rc != 0 && (szProto1 != NULL && szProto2 != NULL)) return rc; } return 0; }
int InternalCompareContacts(WPARAM wParam, LPARAM lParam) { struct ClcContact *c1 = (struct ClcContact *) wParam, *c2 = (struct ClcContact *) lParam; HANDLE a = c1->hContact, b = c2->hContact; //TCHAR namea[128], *nameb; TCHAR *namea, *nameb; int statusa, statusb; char *szProto1, *szProto2; int rc; if (c1 == 0 || c2 == 0) return 0; szProto1 = c1->proto; szProto2 = c2->proto; //statusa = DBGetContactSettingWord((HANDLE) a, SAFESTRING(szProto1), "Status", ID_STATUS_OFFLINE); //statusb = DBGetContactSettingWord((HANDLE) b, SAFESTRING(szProto2), "Status", ID_STATUS_OFFLINE); statusa = c1->wStatus; statusb = c2->wStatus; // make sure, sticky contacts are always at the beginning of the group/list if ((c1->flags & CONTACTF_STICKY) != (c2->flags & CONTACTF_STICKY)) return 2 * (c2->flags & CONTACTF_STICKY) - 1; if (sortByProto) { /* deal with statuses, online contacts have to go above offline */ if (!g_CluiData.bDontSeparateOffline && ((statusa == ID_STATUS_OFFLINE) != (statusb == ID_STATUS_OFFLINE))) { return 2 * (statusa == ID_STATUS_OFFLINE) - 1; } /* both are online, now check protocols */ if(c1->bIsMeta) szProto1 = c1->metaProto ? c1->metaProto : c1->proto; if(c2->bIsMeta) szProto2 = c2->metaProto ? c2->metaProto : c2->proto; //rc = strcmp(SAFESTRING(szProto1), SAFESTRING(szProto2)); /* strcmp() doesn't like NULL so feed in "" as needed */ rc = GetProtoIndex(szProto1) - GetProtoIndex(szProto2); 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 if (!g_CluiData.bDontSeparateOffline) { //one is offline: offline goes below online if ((statusa == ID_STATUS_OFFLINE) != (statusb == ID_STATUS_OFFLINE)) { return 2 * (statusa == ID_STATUS_OFFLINE) - 1; } } /*nameb = GetContactDisplayNameW(a, 0); _tcsncpy(namea, nameb, sizeof(namea) / sizeof(TCHAR)); namea[sizeof(namea) - 1] = 0; nameb = GetContactDisplayNameW(b, 0);*/ namea = GetContactDisplayNameW(a, 0); nameb = GetContactDisplayNameW(b, 0); //otherwise just compare names return CompareString(LOCALE_USER_DEFAULT, NORM_IGNORECASE, namea, -1, nameb, -1) - 2; //return _tcsicmp(namea,nameb); }