int CALLBACK CLiveList::SortCallback(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort) { CListCtrl* pList = (CListCtrl*)lParamSort; ASSERT_VALID( pList ); int nColumn = (int)GetWindowLongPtr( pList->GetSafeHwnd(), GWLP_USERDATA ); LV_FINDINFO pFind; pFind.flags = LVFI_PARAM; pFind.lParam = lParam1; int nA = pList->FindItem( &pFind ); pFind.lParam = lParam2; int nB = pList->FindItem( &pFind ); CString sA( pList->GetItemText( nA, abs( nColumn ) - 1 ) ); CString sB( pList->GetItemText( nB, abs( nColumn ) - 1 ) ); return ( nColumn > 0 ) ? SortProc( sB, sA ) : SortProc( sA, sB ); }
local iproc getsort(string name) { sortmode *s; for (s=smode; SortName(s); s++) { dprintf(1,"GETSORT: Trying %s\n",SortName(s)); if (streq(SortName(s),name)) return SortProc(s); } error("%s: no valid sortname",name); return NULL; /* better not get here ... */ }
int CDownloadClientsCtrl::SortProc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort){ const CUpDownClient* item1 = (CUpDownClient*)lParam1; const CUpDownClient* item2 = (CUpDownClient*)lParam2; int iResult=0; switch(lParamSort){ case 0: if(item1->GetUserName() && item2->GetUserName()) iResult=CompareLocaleStringNoCase(item1->GetUserName(), item2->GetUserName()); else if(item1->GetUserName()) iResult=1; else iResult=-1; break; case 100: if(item1->GetUserName() && item2->GetUserName()) iResult=CompareLocaleStringNoCase(item2->GetUserName(), item1->GetUserName()); else if(item2->GetUserName()) iResult=1; else iResult=-1; break; case 1: if (item1->GetClientSoft() == item2->GetClientSoft()) iResult=item2->GetVersion() - item1->GetVersion(); else iResult=item1->GetClientSoft() - item2->GetClientSoft(); break; case 101: if (item1->GetClientSoft() == item2->GetClientSoft()) iResult=item1->GetVersion() - item2->GetVersion(); else iResult=item2->GetClientSoft() - item1->GetClientSoft(); break; case 2: { //==>Bugfix Xman [shadow2004] CPartFile* file1 = item1->GetRequestFile(); CPartFile* file2 = item2->GetRequestFile(); // CKnownFile* file1 = theApp.sharedfiles->GetFileByID(item1->GetUploadFileID()); // CKnownFile* file2 = theApp.sharedfiles->GetFileByID(item2->GetUploadFileID()); //<==Bugfix Xman [shadow2004] if( (file1 != NULL) && (file2 != NULL)) iResult=CompareLocaleStringNoCase(file1->GetFileName(), file2->GetFileName()); else if( file1 == NULL ) iResult=1; else iResult=-1; break; } case 102:{ //==>Bugfix Xman [shadow2004] CPartFile* file1 = item1->GetRequestFile(); CPartFile* file2 = item2->GetRequestFile(); // CKnownFile* file1 = theApp.sharedfiles->GetFileByID(item1->GetUploadFileID()); // CKnownFile* file2 = theApp.sharedfiles->GetFileByID(item2->GetUploadFileID()); //<==Bugfix Xman [shadow2004] if( (file1 != NULL) && (file2 != NULL)) iResult=CompareLocaleStringNoCase(file2->GetFileName(), file1->GetFileName()); else if( file1 == NULL ) iResult=1; else iResult=-1; break; } //==>Sort-Fix [shadow2004] /* case 3: iResult=CompareUnsigned(item2->GetDownloadDatarate(), item1->GetDownloadDatarate()); break; case 103: iResult=CompareUnsigned(item1->GetDownloadDatarate(), item2->GetDownloadDatarate()); break; case 4: iResult=CompareUnsigned(item2->GetPartCount(), item1->GetPartCount()); break; case 104: iResult=CompareUnsigned(item1->GetPartCount(), item2->GetPartCount()); break; case 5: iResult=CompareUnsigned(item2->GetSessionDown(), item1->GetSessionDown()); break; case 105: iResult=CompareUnsigned(item1->GetSessionDown(), item2->GetSessionDown()); break; case 6: iResult=CompareUnsigned(item2->GetSessionUp(), item1->GetSessionUp()); break; case 106: iResult=CompareUnsigned(item1->GetSessionUp(), item2->GetSessionUp()); break; case 7: iResult=CompareUnsigned(item1->GetSourceFrom(), item2->GetSourceFrom()); break; case 107: iResult=CompareUnsigned(item2->GetSourceFrom(), item1->GetSourceFrom()); break;*/ case 3: case 103: iResult=CompareUnsigned(item1->GetDownloadDatarate(), item2->GetDownloadDatarate()); break; case 4: case 104: iResult=CompareUnsigned(item1->GetPartCount(), item2->GetPartCount()); break; case 5: case 105: iResult=CompareUnsigned(item1->GetSessionDown(), item2->GetSessionDown()); break; case 6: case 106: iResult=CompareUnsigned(item1->GetSessionUp(), item2->GetSessionUp()); break; case 7: case 107: iResult=CompareUnsigned(item1->GetSourceFrom(), item2->GetSourceFrom()); break; //<==Sort-Fix [shadow2004] default: iResult=0; break; } //==>Sort-Fix [shadow2004] if (lParamSort>=103) iResult*=-1; //<==Sort-Fix [shadow2004] int dwNextSort; //call secondary sortorder, if this one results in equal //(Note: yes I know this call is evil OO wise, but better than changing a lot more code, while we have only one instance anyway - might be fixed later) if (iResult == 0 && (dwNextSort = theApp.emuledlg->transferwnd->downloadclientsctrl.GetNextSortOrder(lParamSort)) != (-1)){ iResult= SortProc(lParam1, lParam2, dwNextSort); } return iResult; }
int CUploadListCtrl::SortProc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort) { const CUpDownClient* item1 = (CUpDownClient*)lParam1; const CUpDownClient* item2 = (CUpDownClient*)lParam2; int iResult=0; switch(lParamSort){ case 0: if(item1->GetUserName() && item2->GetUserName()) iResult=CompareLocaleStringNoCase(item1->GetUserName(), item2->GetUserName()); else if(item1->GetUserName()) iResult=1; else iResult=-1; break; case 100: if(item1->GetUserName() && item2->GetUserName()) iResult=CompareLocaleStringNoCase(item2->GetUserName(), item1->GetUserName()); else if(item2->GetUserName()) iResult=1; else iResult=-1; break; case 1: { CKnownFile* file1 = theApp.sharedfiles->GetFileByID(item1->GetUploadFileID()); CKnownFile* file2 = theApp.sharedfiles->GetFileByID(item2->GetUploadFileID()); if( (file1 != NULL) && (file2 != NULL)) iResult=CompareLocaleStringNoCase(file1->GetFileName(), file2->GetFileName()); else if( file1 == NULL ) iResult=1; else iResult=-1; break; } case 101:{ CKnownFile* file1 = theApp.sharedfiles->GetFileByID(item1->GetUploadFileID()); CKnownFile* file2 = theApp.sharedfiles->GetFileByID(item2->GetUploadFileID()); if( (file1 != NULL) && (file2 != NULL)) iResult=CompareLocaleStringNoCase(file2->GetFileName(), file1->GetFileName()); else if( file1 == NULL ) iResult=1; else iResult=-1; break; } case 2: iResult=CompareUnsigned(item1->GetDatarate(), item2->GetDatarate()); break; case 102: iResult=CompareUnsigned(item2->GetDatarate(), item1->GetDatarate()); break; case 3: iResult=CompareUnsigned(item1->GetSessionUp(), item2->GetSessionUp()); if (iResult == 0 && thePrefs.m_bExtControls) { iResult = CompareUnsigned(item1->GetQueueSessionPayloadUp(), item2->GetQueueSessionPayloadUp()); } break; case 103: iResult=CompareUnsigned(item2->GetSessionUp(), item1->GetSessionUp()); if (iResult == 0 && thePrefs.m_bExtControls) { iResult = CompareUnsigned(item2->GetQueueSessionPayloadUp(), item1->GetQueueSessionPayloadUp()); } break; case 4: iResult=item1->GetWaitTime() - item2->GetWaitTime(); break; case 104: iResult=item2->GetWaitTime() - item1->GetWaitTime(); break; case 5: iResult=item1->GetUpStartTimeDelay() - item2->GetUpStartTimeDelay(); break; case 105: iResult=item2->GetUpStartTimeDelay() - item1->GetUpStartTimeDelay(); break; case 6: iResult=item1->GetUploadState() - item2->GetUploadState(); break; case 106: iResult=item2->GetUploadState() - item1->GetUploadState(); break; case 7: iResult=item1->GetUpPartCount() - item2->GetUpPartCount(); break; case 107: iResult=item2->GetUpPartCount() - item1->GetUpPartCount(); break; default: iResult=0; break; } int dwNextSort; //call secondary sortorder, if this one results in equal //(Note: yes I know this call is evil OO wise, but better than changing a lot more code, while we have only one instance anyway - might be fixed later) if (iResult == 0 && (dwNextSort = theApp.emuledlg->transferwnd->uploadlistctrl.GetNextSortOrder(lParamSort)) != (-1)){ iResult= SortProc(lParam1, lParam2, dwNextSort); } return iResult; }
int CQueueListCtrl::SortProc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort) { const CUpDownClient* item1 = (CUpDownClient*)lParam1; const CUpDownClient* item2 = (CUpDownClient*)lParam2; int iResult=0; switch(lParamSort){ case 0: if(item1->GetUserName() && item2->GetUserName()) iResult=CompareLocaleStringNoCase(item1->GetUserName(), item2->GetUserName()); else if(item1->GetUserName()) iResult=1; else iResult=-1; break; case 100: if(item2->GetUserName() && item1->GetUserName()) iResult=CompareLocaleStringNoCase(item2->GetUserName(), item1->GetUserName()); else if(item2->GetUserName()) iResult=1; else iResult=-1; break; case 1: { CKnownFile* file1 = theApp.sharedfiles->GetFileByID(item1->GetUploadFileID()); CKnownFile* file2 = theApp.sharedfiles->GetFileByID(item2->GetUploadFileID()); if( (file1 != NULL) && (file2 != NULL)) iResult=CompareLocaleStringNoCase(file1->GetFileName(), file2->GetFileName()); else if( file1 == NULL ) iResult=1; else iResult=-1; break; } case 101: { CKnownFile* file1 = theApp.sharedfiles->GetFileByID(item1->GetUploadFileID()); CKnownFile* file2 = theApp.sharedfiles->GetFileByID(item2->GetUploadFileID()); if( (file1 != NULL) && (file2 != NULL)) iResult=CompareLocaleStringNoCase(file2->GetFileName(), file1->GetFileName()); else if( file1 == NULL ) iResult=1; else iResult=-1; break; } case 2: { CKnownFile* file1 = theApp.sharedfiles->GetFileByID(item1->GetUploadFileID()); CKnownFile* file2 = theApp.sharedfiles->GetFileByID(item2->GetUploadFileID()); if( (file1 != NULL) && (file2 != NULL)) iResult=((file1->GetUpPriority()==PR_VERYLOW) ? -1 : file1->GetUpPriority()) - ((file2->GetUpPriority()==PR_VERYLOW) ? -1 : file2->GetUpPriority()); else if( file1 == NULL ) iResult=1; else iResult=-1; break; } case 102:{ CKnownFile* file1 = theApp.sharedfiles->GetFileByID(item1->GetUploadFileID()); CKnownFile* file2 = theApp.sharedfiles->GetFileByID(item2->GetUploadFileID()); if( (file1 != NULL) && (file2 != NULL)) iResult=((file2->GetUpPriority()==PR_VERYLOW) ? -1 : file2->GetUpPriority()) - ((file1->GetUpPriority()==PR_VERYLOW) ? -1 : file1->GetUpPriority()); else if( file1 == NULL ) iResult=1; else iResult=-1; break; } case 3: iResult=CompareUnsigned(item1->GetScore(false,false,true), item2->GetScore(false,false,true)); break; case 103: iResult=CompareUnsigned(item2->GetScore(false,false,true), item1->GetScore(false,false,true)); break; case 4: iResult=CompareUnsigned(item1->GetScore(false), item2->GetScore(false)); break; case 104: iResult=CompareUnsigned(item2->GetScore(false), item1->GetScore(false)); break; case 5: iResult=item1->GetAskedCount() - item2->GetAskedCount(); break; case 105: iResult=item2->GetAskedCount() - item1->GetAskedCount(); break; case 6: iResult=item1->GetLastUpRequest() - item2->GetLastUpRequest(); break; case 106: iResult=item2->GetLastUpRequest() - item1->GetLastUpRequest(); break; case 7: iResult=item1->GetWaitStartTime() - item2->GetWaitStartTime(); break; case 107: iResult=item2->GetWaitStartTime() - item1->GetWaitStartTime(); break; case 8: iResult=item1->IsBanned() - item2->IsBanned(); break; case 108: iResult=item2->IsBanned() - item1->IsBanned(); break; case 9: iResult=item1->GetUpPartCount() - item2->GetUpPartCount(); break; case 109: iResult=item2->GetUpPartCount() - item1->GetUpPartCount(); break; default: iResult=0; break; } int dwNextSort; //call secondary sortorder, if this one results in equal //(Note: yes I know this call is evil OO wise, but better than changing a lot more code, while we have only one instance anyway - might be fixed later) if (iResult == 0 && (dwNextSort = theApp.emuledlg->transferwnd->queuelistctrl.GetNextSortOrder(lParamSort)) != (-1)){ iResult= SortProc(lParam1, lParam2, dwNextSort); } return iResult; }
int CServerListCtrl::SortProc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort) { const CServer* item1 = (CServer*)lParam1; const CServer* item2 = (CServer*)lParam2; if (item1 == NULL || item2 == NULL) return 0; #define UNDEFINED_STR_AT_BOTTOM(s1, s2) \ if ((s1).IsEmpty() && (s2).IsEmpty()) \ return 0; \ if ((s1).IsEmpty()) \ return 1; \ if ((s2).IsEmpty()) \ return -1; \ #define UNDEFINED_INT_AT_BOTTOM(i1, i2) \ if ((i1) == (i2)) \ return 0; \ if ((i1) == 0) \ return 1; \ if ((i2) == 0) \ return -1; \ int iResult; switch (LOWORD(lParamSort)){ case 0: UNDEFINED_STR_AT_BOTTOM(item1->GetListName(), item2->GetListName()); iResult = item1->GetListName().CompareNoCase(item2->GetListName()); break; case 1: if (item1->HasDynIP() && item2->HasDynIP()) iResult = item1->GetDynIP().CompareNoCase(item2->GetDynIP()); else if (item1->HasDynIP()) iResult = -1; else if (item2->HasDynIP()) iResult = 1; else{ uint32 uIP1 = htonl(item1->GetIP()); uint32 uIP2 = htonl(item2->GetIP()); if (uIP1 < uIP2) iResult = -1; else if (uIP1 > uIP2) iResult = 1; else iResult = CompareUnsigned(item1->GetPort(), item2->GetPort()); } break; case 2: UNDEFINED_STR_AT_BOTTOM(item1->GetDescription(), item2->GetDescription()); iResult = item1->GetDescription().CompareNoCase(item2->GetDescription()); break; case 3: UNDEFINED_INT_AT_BOTTOM(item1->GetPing(), item2->GetPing()); iResult = CompareUnsigned(item1->GetPing(), item2->GetPing()); break; case 4: UNDEFINED_INT_AT_BOTTOM(item1->GetUsers(), item2->GetUsers()); iResult = CompareUnsigned(item1->GetUsers(), item2->GetUsers()); break; case 5: UNDEFINED_INT_AT_BOTTOM(item1->GetMaxUsers(), item2->GetMaxUsers()); iResult = CompareUnsigned(item1->GetMaxUsers(), item2->GetMaxUsers()); break; case 6: UNDEFINED_INT_AT_BOTTOM(item1->GetFiles(), item2->GetFiles()); iResult = CompareUnsigned(item1->GetFiles(), item2->GetFiles()); break; case 7: if (item2->GetPreference() == item1->GetPreference()) iResult = 0; else if (item2->GetPreference() == SRV_PR_LOW) iResult = 1; else if (item1->GetPreference() == SRV_PR_LOW) iResult = -1; else if (item2->GetPreference() == SRV_PR_HIGH) iResult = -1; else if (item1->GetPreference() == SRV_PR_HIGH) iResult = 1; else iResult = 0; break; case 8: iResult = CompareUnsigned(item1->GetFailedCount(), item2->GetFailedCount()); break; case 9: iResult = (int)item1->IsStaticMember() - (int)item2->IsStaticMember(); break; case 10: UNDEFINED_INT_AT_BOTTOM(item1->GetSoftFiles(), item2->GetSoftFiles()); iResult = CompareUnsigned(item1->GetSoftFiles(), item2->GetSoftFiles()); break; case 11: UNDEFINED_INT_AT_BOTTOM(item1->GetHardFiles(), item2->GetHardFiles()); iResult = CompareUnsigned(item1->GetHardFiles(), item2->GetHardFiles()); break; case 12: UNDEFINED_STR_AT_BOTTOM(item1->GetVersion(), item2->GetVersion()); iResult = item1->GetVersion().CompareNoCase(item2->GetVersion()); break; case 13: UNDEFINED_INT_AT_BOTTOM(item1->GetLowIDUsers(), item2->GetLowIDUsers()); iResult = CompareUnsigned(item1->GetLowIDUsers(), item2->GetLowIDUsers()); break; case 14: iResult = (int)(item1->SupportsObfuscationTCP() && item1->GetObfuscationPortTCP() != 0) - (int)(item2->SupportsObfuscationTCP() && item2->GetObfuscationPortTCP() != 0); break; default: iResult = 0; } int dwNextSort; //call secondary sortorder, if this one results in equal //(Note: yes I know this call is evil OO wise, but better than changing a lot more code, while we have only one instance anyway - might be fixed later) if (iResult == 0 && (dwNextSort = theApp.emuledlg->serverwnd->serverlistctrl.GetNextSortOrder(lParamSort)) != (-1)){ iResult= SortProc(lParam1, lParam2, dwNextSort); } if (HIWORD(lParamSort)) iResult = -iResult; return iResult; }
void CMuleListCtrl::SortList() { if (!IsSorting() && (m_sort_func && GetColumnCount())) { m_isSorting = true; MuleSortData sortdata(m_sort_orders, m_sort_func); // In many cases control already has correct order, and sorting causes nasty flickering. // Make one pass through it to check if sorting is necessary at all. int nrItems = GetItemCount(); bool clean = true; long lastItemdata = 0; if (nrItems > 1) { lastItemdata = GetItemData(0); } for (int i = 1; i < nrItems; i++) { long nextItemdata = GetItemData(i); if (SortProc(lastItemdata, nextItemdata, (long int)&sortdata) > 0) { // ok - we need to sort clean = false; break; } lastItemdata = nextItemdata; } if (clean) { // no need to sort m_isSorting = false; return; } // Positions are likely to be invalid after sorting. ResetTTS(); // Store the current selected items ItemDataList selectedItems = GetSelectedItems(); // Store the focused item long pos = GetNextItem( -1, wxLIST_NEXT_ALL, wxLIST_STATE_FOCUSED ); wxUIntPtr focused = (pos == -1) ? 0 : GetItemData(pos); SortItems(SortProc, (long int)&sortdata); // Re-select the selected items. for (unsigned i = 0; i < selectedItems.size(); ++i) { long it_pos = FindItem(-1, selectedItems[i]); if (it_pos != -1) { SetItemState(it_pos, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED); } } // Set focus on item if any was focused if (focused) { long it_pos = FindItem(-1, focused); if (it_pos != -1) { SetItemState(it_pos, wxLIST_STATE_FOCUSED, wxLIST_STATE_FOCUSED); } } m_isSorting = false; } }
int CQueueListCtrl::SortProc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort) { CUpDownClient* pClient1 = (CUpDownClient*)lParam1; CUpDownClient* pClient2 = (CUpDownClient*)lParam2; if (pClient1 == NULL || pClient2 == NULL) return 0; CKnownFile* pSharedFile1 = g_App.m_pSharedFilesList->GetFileByID(pClient1->m_reqFileHash); CKnownFile* pSharedFile2 = g_App.m_pSharedFilesList->GetFileByID(pClient2->m_reqFileHash); int iCompare = 0; int iSortMod = ((lParamSort & MLC_SORTDESC) == 0) ? 1 : -1; int iSortColumn = (lParamSort & MLC_COLUMNMASK); switch(iSortColumn) { case QLCOL_USERNAME: { iCompare = pClient1->CmpUserNames(pClient2->GetUserName()); break; } case QLCOL_COUNTRY: { CString strCountry1 = pClient1->GetCountryName(); CString strCountry2 = pClient2->GetCountryName(); if (!strCountry1.IsEmpty() && !strCountry2.IsEmpty()) iCompare = _tcsicmp(strCountry1, strCountry2); else { iCompare = strCountry1.IsEmpty() ? (strCountry2.IsEmpty() ? 0 : 1) : -1; iSortMod = 1; //empty entries at the bottom in any case } if (iCompare == 0) { iCompare = SortProc(lParam1,lParam2,QLCOL_USERNAME); iSortMod = 1; //sort allways in ascending order } break; } case QLCOL_FILENAME: if ((pSharedFile1 != NULL) && (pSharedFile2 != NULL)) iCompare = pSharedFile1->CmpFileNames(pSharedFile2->GetFileName()); else iCompare = (pSharedFile1 == NULL) ? ((pSharedFile2 == NULL) ? 0 : 1) : -1; if (iCompare == 0) { iCompare = SortProc(lParam1,lParam2, QLCOL_USERNAME); iSortMod = 1; //eklmn: sort allways in ascending order } break; case QLCOL_FILEPRIORITY: if(pSharedFile1 != NULL && pSharedFile2 != NULL) //Cax2 - right priority sortig { if (pSharedFile1->GetULPriority() == PR_VERYLOW) iCompare = -1; else if (pSharedFile2->GetULPriority() == PR_VERYLOW) iCompare = 1; else iCompare = pSharedFile1->GetULPriority() - pSharedFile2->GetULPriority(); } else iCompare = ( pSharedFile1 == NULL ) ? ((pSharedFile2 == NULL) ? 0 : 1) : -1; //eklmn: additional sorting by filename & username if (iCompare == 0) { iCompare = SortProc(lParam1,lParam2, QLCOL_FILENAME); iSortMod = 1; //eklmn: sort allways in ascending order } break; case QLCOL_PARTS: case QLCOL_PROGRESS: { // obaldin: sort by upload progress uint32 partcnt1 = pClient1->GetUpPartCount(); uint32 partcnt2 = pClient2->GetUpPartCount(); if((partcnt1!=0) && (partcnt2!=0)) { double dblProgress1 = static_cast<double>(pClient1->GetAvailUpPartCount())/static_cast<double>(partcnt1); double dblProgress2 = static_cast<double>(pClient2->GetAvailUpPartCount())/static_cast<double>(partcnt2); iCompare = (dblProgress1 > dblProgress2) ? 1 : ((dblProgress1 < dblProgress2) ? -1: 0); } else iCompare = ( partcnt1 == 0 ) ? ((partcnt2 == 0) ? 0 : 1) : -1; break; } case QLCOL_QLRATING: iCompare = pClient1->GetScore(true) - pClient2->GetScore(true); break; case QLCOL_SCORE: iCompare = pClient1->GetScore() - pClient2->GetScore(); break; case QLCOL_SFRATIO: //small file asc if( (pSharedFile1 != NULL) && (pSharedFile2 != NULL)) iCompare = static_cast<int>(100.0*(pSharedFile1->GetSizeRatio() - pSharedFile2->GetSizeRatio()) ); else iCompare = ( pSharedFile1 == NULL ) ? ((pSharedFile2 == NULL) ? 0 : 1) : -1; break; case QLCOL_RFRATIO: //rare file asc if( (pSharedFile1 != NULL) && (pSharedFile2 != NULL)) iCompare = static_cast<int>(100.0 *(pSharedFile1->GetPopularityRatio() - pSharedFile2->GetPopularityRatio()) ); else iCompare = ( pSharedFile1 == NULL ) ? ((pSharedFile2 == NULL) ? 0 : 1) : -1; break; case QLCOL_TIMESASKED: iCompare = pClient1->GetAskedCount() - pClient2->GetAskedCount(); break; case QLCOL_LASTSEEN: iCompare = pClient2->GetLastUpRequest() - pClient1->GetLastUpRequest(); break; case QLCOL_ENTEREDQUEUE: iCompare = pClient2->GetWaitStartTime() - pClient1->GetWaitStartTime(); break; case QLCOL_BANNED: iCompare = pClient1->IsBanned() - pClient2->IsBanned(); //eklmn: additional sorting by filename & username if (iCompare == 0) { iCompare = SortProc(lParam1,lParam2, QLCOL_FILENAME); iSortMod = 1; //eklmn: sort allways in ascending order } break; default: iCompare = 0; } return iCompare*iSortMod; }
int CDownloadClientsCtrl::SortProc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort) { const CUpDownClient *item1 = (CUpDownClient *)lParam1; const CUpDownClient *item2 = (CUpDownClient *)lParam2; int iColumn = (lParamSort >= 100) ? lParamSort - 100 : lParamSort; int iResult = 0; switch (iColumn) { case 0: if (item1->GetUserName() && item2->GetUserName()) iResult = CompareLocaleStringNoCase(item1->GetUserName(), item2->GetUserName()); else if (item1->GetUserName() == NULL) iResult = 1; // place clients with no usernames at bottom else if (item2->GetUserName() == NULL) iResult = -1; // place clients with no usernames at bottom break; case 1: if (item1->GetClientSoft() == item2->GetClientSoft()) iResult = item1->GetVersion() - item2->GetVersion(); else iResult = -(item1->GetClientSoft() - item2->GetClientSoft()); // invert result to place eMule's at top break; case 2: { const CKnownFile *file1 = item1->GetRequestFile(); const CKnownFile *file2 = item2->GetRequestFile(); if( (file1 != NULL) && (file2 != NULL)) iResult = CompareLocaleStringNoCase(file1->GetFileName(), file2->GetFileName()); else if (file1 == NULL) iResult = 1; else iResult = -1; break; } case 3: iResult = CompareUnsigned(item1->GetDownloadDatarate(), item2->GetDownloadDatarate()); break; case 4: iResult = CompareUnsigned(item1->GetPartCount(), item2->GetPartCount()); break; case 5: iResult = CompareUnsigned(item1->GetSessionDown(), item2->GetSessionDown()); break; case 6: iResult = CompareUnsigned(item1->GetSessionUp(), item2->GetSessionUp()); break; case 7: iResult = item1->GetSourceFrom() - item2->GetSourceFrom(); break; } if (lParamSort >= 100) iResult = -iResult; //call secondary sortorder, if this one results in equal int dwNextSort; if (iResult == 0 && (dwNextSort = theApp.emuledlg->transferwnd->GetDownloadClientsList()->GetNextSortOrder(lParamSort)) != -1) iResult = SortProc(lParam1, lParam2, dwNextSort); return iResult; }
int CClientListCtrl::SortProc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort) { const CUpDownClient* item1 = (CUpDownClient*)lParam1; const CUpDownClient* item2 = (CUpDownClient*)lParam2; int iResult=0; switch (lParamSort) { case 0: if (item1->GetUserName() && item2->GetUserName()) iResult=CompareLocaleStringNoCase(item1->GetUserName(), item2->GetUserName()); else if (!item1->GetUserName() && !item2->GetUserName()) iResult=0; else { // place clients with no usernames at bottom if (!item1->GetUserName()) iResult=1; else iResult=-1; } break; case 100: if (item1->GetUserName() && item2->GetUserName()) iResult=CompareLocaleStringNoCase(item2->GetUserName(), item1->GetUserName()); else if (!item1->GetUserName() && !item2->GetUserName()) iResult=0; else { // place clients with no usernames at bottom if (!item1->GetUserName()) iResult=1; else iResult=-1; } break; case 1: iResult=item1->GetUploadState() - item2->GetUploadState(); break; case 101: iResult=item2->GetUploadState() - item1->GetUploadState(); break; case 2: if (item1->credits && item2->credits) iResult=CompareUnsigned64(item1->credits->GetUploadedTotal(), item2->credits->GetUploadedTotal()); else if (!item1->credits) iResult=1; else iResult=-1; break; case 102: if (item1->credits && item2->credits) iResult=CompareUnsigned64(item2->credits->GetUploadedTotal(), item1->credits->GetUploadedTotal()); else if (!item1->credits) iResult=1; else iResult=-1; break; case 3: if (item1->GetDownloadState() == item2->GetDownloadState()) { if (item1->IsRemoteQueueFull() && item2->IsRemoteQueueFull()) iResult=0; else if (item1->IsRemoteQueueFull()) iResult=1; else if (item2->IsRemoteQueueFull()) iResult=-1; else iResult=0; } else iResult=item1->GetDownloadState() - item2->GetDownloadState(); break; case 103: if (item2->GetDownloadState() == item1->GetDownloadState()) { if (item2->IsRemoteQueueFull() && item1->IsRemoteQueueFull()) iResult=0; else if (item2->IsRemoteQueueFull()) iResult=1; else if (item1->IsRemoteQueueFull()) iResult=-1; else iResult=0; } else iResult=item2->GetDownloadState() - item1->GetDownloadState(); break; case 4: if (item1->credits && item2->credits) iResult=CompareUnsigned64(item1->credits->GetDownloadedTotal(), item2->credits->GetDownloadedTotal()); else if (!item1->credits) iResult=1; else iResult=-1; break; case 104: if (item1->credits && item2->credits) iResult=CompareUnsigned64(item2->credits->GetDownloadedTotal(), item1->credits->GetDownloadedTotal()); else if (!item1->credits) iResult=1; else iResult=-1; break; case 5: if (item1->GetClientSoft() == item2->GetClientSoft()) iResult=item2->GetVersion() - item1->GetVersion(); else iResult=item1->GetClientSoft() - item2->GetClientSoft(); break; case 105: if (item1->GetClientSoft() == item2->GetClientSoft()) iResult=item1->GetVersion() - item2->GetVersion(); else iResult=item2->GetClientSoft() - item1->GetClientSoft(); break; case 6: if (item1->socket && item2->socket) iResult=item1->socket->IsConnected() - item2->socket->IsConnected(); else if (!item1->socket) iResult=-1; else iResult=1; break; case 106: if (item1->socket && item2->socket) iResult=item2->socket->IsConnected() - item1->socket->IsConnected(); else if (!item2->socket) iResult=-1; else iResult=1; break; case 7: iResult=memcmp(item1->GetUserHash(), item2->GetUserHash(), 16); break; case 107: iResult=memcmp(item2->GetUserHash(), item1->GetUserHash(), 16); break; default: iResult=0; } int dwNextSort; //call secondary sortorder, if this one results in equal //(Note: yes I know this call is evil OO wise, but better than changing a lot more code, while we have only one instance anyway - might be fixed later) if (iResult == 0 && (dwNextSort = theApp.emuledlg->transferwnd->clientlistctrl.GetNextSortOrder(lParamSort)) != (-1)){ iResult= SortProc(lParam1, lParam2, dwNextSort); } return iResult; }