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 , 18 years ago) |
---|
-
mythvideo/mythvideo/videolist.h
3 3 4 4 #include <qapplication.h> 5 5 #include <qdialog.h> 6 #include <qmap.h>7 6 8 7 #include <mythtv/mythwidgets.h> 9 8 #include <mythtv/uitypes.h> … … 21 20 #define ORDER_SUB 1 22 21 #define ORDER_ITEM 2 23 22 23 class SortableMetadataList : public QPtrList<Metadata> 24 { 25 public: 26 SortableMetadataList() {}; 27 ~SortableMetadataList() {}; 28 29 protected: 30 virtual int compareItems(QPtrCollection::Item, QPtrCollection::Item); 31 }; 32 24 33 class VideoList 25 34 { 26 35 public: -
mythvideo/mythvideo/videolist.cpp
6 6 #include <mythtv/mythmedia.h> 7 7 #include <mythtv/mythmediamonitor.h> 8 8 9 int 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 9 32 VideoList::VideoList(const QString& _prefix) 10 33 { 11 34 currentVideoFilter = new VideoFilterSettings(true, _prefix); … … 164 187 // 165 188 // Accumulate query results into the metaptrs list. 166 189 // 167 QPtrList<Metadata>metaptrs;190 SortableMetadataList metaptrs; 168 191 while (query.next()) 169 192 { 170 193 unsigned int intid = query.value(0).toUInt(); … … 176 199 177 200 // 178 201 // 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. 184 208 // 185 209 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(); 198 211 199 // Append the video ID to allow multiple videos with the same title200 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 the206 // 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 216 212 // 217 213 // Build list of videos. 218 214 //