Ticket #620: titlesort.patch

File titlesort.patch, 3.8 KB (added by mythtv@…, 18 years ago)

proposed patch

  • libs/libmythtv/proglist.cpp

     
    13281328
    13291329        bool operator()(const ProgramInfo *a, const ProgramInfo *b)
    13301330        {
    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            }
    13361338
    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;
    13401343
    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;
    13451346
    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;
    13501349
    13511350            if (m_reverse)
    1352                 return (a->startts > b->startts);
     1351                return a->startts < b->startts;
    13531352            else
    1354                 return (a->startts < b->startts);
     1353                return a->startts > b->startts;
    13551354        }
    13561355
    13571356    private:
     
    14941493                     "INTERVAL '1' HOUR) ";
    14951494    }
    14961495
    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  ";
    15011504
     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
    15021519    schedList.FromScheduler();
    15031520    itemList.FromProgram(where, bindings, schedList);
    15041521
    1505     if (titleSort || reverseSort)
     1522    if (titleSort) // Sort without The/A/An prefixes
    15061523    {
    15071524        ProgramInfo *s;
    15081525
     
    15191536            sortedList.push_back(s);
    15201537        }
    15211538
    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));
    15281541
    15291542        vector<ProgramInfo *>::iterator i = sortedList.begin();
     1543        QString prev = "";
    15301544        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        }
    15321553    }
    15331554
    15341555    if (curItem < 0 && itemList.count() > 0)