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

Method SortProc

src/SearchListCtrl.cpp:469–564  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

467
468
469int CSearchListCtrl::SortProc(wxUIntPtr item1, wxUIntPtr item2, wxIntPtr sortData)
470{
471 CSearchFile* file1 = reinterpret_cast<CSearchFile*>(item1);
472 CSearchFile* file2 = reinterpret_cast<CSearchFile*>(item2);
473
474 // Modifies the result, 1 for ascending, -1 for descending
475 int modifier = (sortData & CMuleListCtrl::SORT_DES) ? -1 : 1;
476 bool alternate = (sortData & CMuleListCtrl::SORT_ALT) != 0;
477
478 // Decide if which should files we should sort by.
479 wxUIntPtr parent1 = reinterpret_cast<wxUIntPtr>(file1->GetParent());
480 wxUIntPtr parent2 = reinterpret_cast<wxUIntPtr>(file2->GetParent());
481 wxUIntPtr filePtr1 = reinterpret_cast<wxUIntPtr>(file1);
482 wxUIntPtr filePtr2 = reinterpret_cast<wxUIntPtr>(file2);
483 if (parent1 && parent2) {
484 if (parent1 != parent2) {
485 return SortProc(parent1, parent2, sortData);
486 }
487 } else if (parent1) {
488 if (parent1 == filePtr2) {
489 return 1;
490 } else {
491 return SortProc(parent1, filePtr2, sortData);
492 }
493 } else if (parent2) {
494 if (parent2 == filePtr1) {
495 return -1;
496 } else {
497 return SortProc(filePtr1, parent2, sortData);
498 }
499 }
500
501 int result = 0;
502 switch (sortData & CMuleListCtrl::COLUMN_MASK) {
503 // Sort by filename
504 case ID_SEARCH_COL_NAME:
505 result = CmpAny(file1->GetFileName(), file2->GetFileName());
506 break;
507
508 // Sort file-size
509 case ID_SEARCH_COL_SIZE:
510 result = CmpAny( file1->GetFileSize(), file2->GetFileSize() );
511 break;
512
513 // Sort by sources
514 case ID_SEARCH_COL_SOURCES: {
515 int cmp = CmpAny( file1->GetSourceCount(), file2->GetSourceCount() );
516 int cmp2 = CmpAny( file1->GetCompleteSourceCount(), file2->GetCompleteSourceCount() );
517
518 if ( alternate ) {
519 // Swap criteria
520 int temp = cmp2;
521 cmp2 = cmp;
522 cmp = temp;
523 }
524
525 if ( cmp == 0 ) {
526 cmp = cmp2;

Callers

nothing calls this directly

Calls 7

GetFiletypeByNameFunction · 0.85
GetParentMethod · 0.80
GetExtMethod · 0.80
CmpAnyFunction · 0.70
GetFileSizeMethod · 0.45
GetSourceCountMethod · 0.45

Tested by

no test coverage detected