Ticket #620: titlesort.patch
File titlesort.patch, 3.8 KB (added by , 18 years ago) |
---|
-
libs/libmythtv/proglist.cpp
1328 1328 1329 1329 bool operator()(const ProgramInfo *a, const ProgramInfo *b) 1330 1330 { 1331 if (m_reverse) 1332 return (a->sortTitle > b->sortTitle); 1333 else 1334 return (a->sortTitle < b->sortTitle); 1335 } 1331 if (a->sortTitle != b->sortTitle) 1332 { 1333 if (m_reverse) 1334 return (a->sortTitle > b->sortTitle); 1335 else 1336 return (a->sortTitle < b->sortTitle); 1337 } 1336 1338 1337 private: 1338 bool m_reverse; 1339 }; 1339 // Prefer recorded titles to recording to will record 1340 // Return it so preferred program will occur first 1341 if (a->recstatus == rsRecorded) return true; 1342 if (b->recstatus == rsRecorded) return false; 1340 1343 1341 class plTimeSort 1342 { 1343 public: 1344 plTimeSort(bool reverseSort = false) {m_reverse = reverseSort;} 1344 if (a->recstatus == rsRecording) return true; 1345 if (b->recstatus == rsRecording) return false; 1345 1346 1346 bool operator()(const ProgramInfo *a, const ProgramInfo *b) 1347 { 1348 if (a->startts == b->startts) 1349 return (a->chanid < b->chanid); 1347 if (a->recstatus == rsWillRecord) return true; 1348 if (b->recstatus == rsWillRecord) return false; 1350 1349 1351 1350 if (m_reverse) 1352 return (a->startts > b->startts);1351 return a->startts < b->startts; 1353 1352 else 1354 return (a->startts < b->startts);1353 return a->startts > b->startts; 1355 1354 } 1356 1355 1357 1356 private: … … 1494 1493 "INTERVAL '1' HOUR) "; 1495 1494 } 1496 1495 1497 if (titleSort && type == plTitle) 1498 where += " GROUP BY subtitle "; 1499 else if (type == plNewListings || titleSort) 1500 where += " GROUP BY title "; 1496 QString order = ""; 1497 if (reverseSort) order = " DESC "; 1498 if (type == plNewListings) 1499 where += " GROUP BY title ORDER BY program.starttime" + order + ", title" + order; 1500 else 1501 { 1502 where += " GROUP BY channel.chanid, program.title, " 1503 "program.starttime "; 1501 1504 1505 if (titleSort) 1506 { 1507 if (type == plTitle) 1508 where += " ORDER BY title" + order + ",subtitle" + order + ", program.starttime"; 1509 else 1510 where += " ORDER BY title " + order + ", program.starttime"; 1511 } 1512 else if (reverseSort) 1513 { 1514 where += QString(" ORDER BY program.starttime DESC, ") + 1515 gContext->GetSetting("ChannelOrdering", "channum+0") + " DESC"; 1516 } 1517 } 1518 1502 1519 schedList.FromScheduler(); 1503 1520 itemList.FromProgram(where, bindings, schedList); 1504 1521 1505 if (titleSort || reverseSort)1522 if (titleSort) // Sort without The/A/An prefixes 1506 1523 { 1507 1524 ProgramInfo *s; 1508 1525 … … 1519 1536 sortedList.push_back(s); 1520 1537 } 1521 1538 1522 if (titleSort) 1523 sort(sortedList.begin(), sortedList.end(), 1524 plTitleSort(reverseSort)); 1525 else 1526 sort(sortedList.begin(), sortedList.end(), 1527 plTimeSort(reverseSort)); 1539 sort(sortedList.begin(), sortedList.end(), 1540 plTitleSort(reverseSort)); 1528 1541 1529 1542 vector<ProgramInfo *>::iterator i = sortedList.begin(); 1543 QString prev = ""; 1530 1544 for (; i != sortedList.end(); i++) 1531 itemList.append(*i); 1545 { 1546 ProgramInfo *s = *i; 1547 if (s->sortTitle != prev) 1548 { 1549 prev = s->sortTitle; 1550 itemList.append(*i); 1551 } 1552 } 1532 1553 } 1533 1554 1534 1555 if (curItem < 0 && itemList.count() > 0)