MCPcopy Create free account
hub / github.com/amule-project/amule / SortProc

Method SortProc

src/ServerListCtrl.cpp:568–638  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

566
567
568int CServerListCtrl::SortProc(wxUIntPtr item1, wxUIntPtr item2, wxIntPtr sortData)
569{
570 CServer* server1 = reinterpret_cast<CServer*>(item1);
571 CServer* server2 = reinterpret_cast<CServer*>(item2);
572
573 int mode = (sortData & CMuleListCtrl::SORT_DES) ? -1 : 1;
574
575 switch (sortData & CMuleListCtrl::COLUMN_MASK) {
576 // Sort by server-name
577 case COLUMN_SERVER_NAME:
578 return mode * server1->GetListName().CmpNoCase(server2->GetListName());
579
580 // Sort by address
581 case COLUMN_SERVER_ADDR:
582 {
583 if ( server1->HasDynIP() && server2->HasDynIP()) {
584 return mode * server1->GetDynIP().CmpNoCase( server2->GetDynIP() );
585 } else if (server1->HasDynIP()) {
586 return mode * -1;
587 } else if (server2->HasDynIP()) {
588 return mode * 1;
589 } else {
590 uint32 a = wxUINT32_SWAP_ALWAYS(server1->GetIP());
591 uint32 b = wxUINT32_SWAP_ALWAYS(server2->GetIP());
592 return mode * CmpAny(a, b);
593 }
594 }
595 // Sort by port
596 case COLUMN_SERVER_PORT: return mode * CmpAny( server1->GetPort(), server2->GetPort() );
597 // Sort by description
598 case COLUMN_SERVER_DESC: return mode * server1->GetDescription().CmpNoCase( server2->GetDescription() );
599 // Sort by Ping
600 // The -1 ensures that a value of zero (no ping known) is sorted last.
601 case COLUMN_SERVER_PING: return mode * CmpAny( server1->GetPing() - 1, server2->GetPing() -1 );
602 // Sort by user-count
603 case COLUMN_SERVER_USERS: return mode * CmpAny( server1->GetUsers(), server2->GetUsers() );
604 // Sort by file-count
605 case COLUMN_SERVER_FILES: return mode * CmpAny( server1->GetFiles(), server2->GetFiles() );
606 // Sort by priority
607 case COLUMN_SERVER_PRIO:
608 {
609 uint32 srv_pr1 = server1->GetPreferences();
610 uint32 srv_pr2 = server2->GetPreferences();
611 switch ( srv_pr1 ) {
612 case SRV_PR_HIGH: srv_pr1 = SRV_PR_MAX; break;
613 case SRV_PR_NORMAL: srv_pr1 = SRV_PR_MID; break;
614 case SRV_PR_LOW: srv_pr1 = SRV_PR_MIN; break;
615 default: return 0;
616 }
617 switch ( srv_pr2 ) {
618 case SRV_PR_HIGH: srv_pr2 = SRV_PR_MAX; break;
619 case SRV_PR_NORMAL: srv_pr2 = SRV_PR_MID; break;
620 case SRV_PR_LOW: srv_pr2 = SRV_PR_MIN; break;
621 default: return 0;
622 }
623 return mode * CmpAny( srv_pr1, srv_pr2 );
624 }
625 // Sort by failure-count

Callers

nothing calls this directly

Calls 12

FuzzyStrCmpFunction · 0.85
HasDynIPMethod · 0.80
GetPreferencesMethod · 0.80
GetFailedCountMethod · 0.80
IsStaticMemberMethod · 0.80
CmpAnyFunction · 0.70
GetIPMethod · 0.45
GetPortMethod · 0.45
GetPingMethod · 0.45
GetUsersMethod · 0.45
GetFilesMethod · 0.45
GetVersionMethod · 0.45

Tested by

no test coverage detected