Ticket #1678: mythplugins-mythvideo-i18n_and_case_insensitive_sorting-2.patch

File mythplugins-mythvideo-i18n_and_case_insensitive_sorting-2.patch, 4.3 KB (added by sphery <mtdean@…>, 18 years ago)

Updated patch--removes no-longer-required qmap.h include

  • mythvideo/mythvideo/videolist.h

     
    33
    44#include <qapplication.h>
    55#include <qdialog.h>
    6 #include <qmap.h>
    76
    87#include <mythtv/mythwidgets.h>
    98#include <mythtv/uitypes.h>
     
    2120#define ORDER_SUB       1
    2221#define ORDER_ITEM      2
    2322
     23class SortableMetadataList : public QPtrList<Metadata>
     24{
     25    public:
     26        SortableMetadataList() {};
     27        ~SortableMetadataList() {};
     28
     29    protected:
     30        virtual int compareItems(QPtrCollection::Item, QPtrCollection::Item);
     31};
     32
    2433class VideoList
    2534{
    2635    public:
  • mythvideo/mythvideo/videolist.cpp

     
    66#include <mythtv/mythmedia.h>
    77#include <mythtv/mythmediamonitor.h>
    88
     9int SortableMetadataList::compareItems(QPtrCollection::Item item1,
     10                                       QPtrCollection::Item item2) {
     11    QRegExp prefixes = QObject::tr("^(The |A |An )");
     12    Metadata *meta1 = (Metadata*)item1;
     13    Metadata *meta2 = (Metadata*)item2;
     14    QString title1 = meta1->Title();
     15    QString title2 = meta2->Title();
     16
     17    // Remove indefinite articles from the title
     18    title1.remove(prefixes);
     19    title2.remove(prefixes);
     20    // Append a secondary sort key for like-named titles
     21    title1 += meta1->Filename();
     22    title2 += meta2->Filename();
     23    // If filenames are identical except for case, we need a tertiary sort key
     24    title1 += QString().sprintf("%.7d", meta1->ID());
     25    title2 += QString().sprintf("%.7d", meta2->ID());
     26    // Make the comparison case-insensitive
     27    title1 = title1.lower();
     28    title2 = title2.lower();
     29    return QString::localeAwareCompare(title1, title2);
     30}
     31
    932VideoList::VideoList(const QString& _prefix)
    1033{
    1134    currentVideoFilter = new VideoFilterSettings(true, _prefix);
     
    164187    //
    165188    //  Accumulate query results into the metaptrs list.
    166189    //
    167     QPtrList<Metadata> metaptrs;
     190    SortableMetadataList metaptrs;
    168191    while (query.next())
    169192    {
    170193        unsigned int intid = query.value(0).toUInt();
     
    176199
    177200    //
    178201    //  If sorting by title, re-sort by hand because the SQL sort doesn't
    179     //  ignore articles when sorting. This assumes all titles are in English.
    180     //  This means a movie with a foreign-language title like "A la carte" will
    181     //  be incorrectly alphabetized, because the "A" is actually significant.
    182     //  The set of ignored prefixes should be a database option, or each
    183     //  video's metadata should include a separate sort key.
     202    //  ignore articles when sorting. This assumes all titles are in the same
     203    //  language.  This means if the locale is set to English, a movie with a
     204    //  foreign-language title like "A la carte" will be incorrectly
     205    //  alphabetized, because the "A" is actually significant.  The set of
     206    //  ignored prefixes should be a database option, or each video's metadata
     207    //  should include a separate sort key.
    184208    //
    185209    if (currentVideoFilter->getOrderby() == VideoFilterSettings::kOrderByTitle)
    186     {
    187         //
    188         //  Pull things off the metaptrs list and put them into the
    189         //  "stringsort" qmap (which will automatically sort them by qmap key).
    190         //
    191         QMap<QString, Metadata*> stringsort;
    192         QRegExp prefixes = QObject::tr("^(The |A |An )");
    193         while (!metaptrs.isEmpty())
    194         {
    195             Metadata *myData = metaptrs.take(0);
    196             QString sTitle = myData->Title();
    197             sTitle.remove(prefixes);
     210        metaptrs.sort();
    198211
    199             // Append the video ID to allow multiple videos with the same title
    200             sTitle += QString().sprintf("%.7d", myData->ID());
    201             stringsort[sTitle] = myData;
    202         }
    203 
    204         //
    205         //  Now walk through the "stringsort" qmap and put them back on the
    206         //  list (in stringsort order).
    207         //
    208         for (QMap<QString, Metadata*>::iterator it = stringsort.begin();
    209                 it != stringsort.end();
    210                 it++)
    211         {
    212             metaptrs.append(*it);
    213         }
    214     }
    215 
    216212    //
    217213    //  Build list of videos.
    218214    //