Ticket #12961: sort_helper.patch
File sort_helper.patch, 24.7 KB (added by , 7 years ago) |
---|
-
mythtv/libs/libmythbase/libmythbase.pro
mythtv/libs/libmythbase/libmythbase.pro | 3 ++ mythtv/libs/libmythbase/mythsorthelper.cpp | 47 +++++++++++++++++++ mythtv/libs/libmythbase/mythsorthelper.h | 30 +++++++++++++ mythtv/libs/libmythmetadata/videometadata.cpp | 27 ++--------- mythtv/libs/libmythmetadata/videometadata.h | 4 +- mythtv/programs/mythfrontend/globalsettings.cpp | 38 ++++++++++++++++ mythtv/programs/mythfrontend/playbackbox.cpp | 9 ++-- mythtv/programs/mythfrontend/playbackbox.h | 3 +- mythtv/programs/mythfrontend/proglist.cpp | 10 +++-- mythtv/programs/mythfrontend/proglist.h | 3 ++ .../programs/mythfrontend/programrecpriority.cpp | 5 +-- mythtv/programs/mythfrontend/programrecpriority.h | 2 + mythtv/programs/mythfrontend/videofilter.cpp | 19 ++++---- mythtv/programs/mythfrontend/videofilter.h | 7 +-- mythtv/programs/mythfrontend/videolist.cpp | 52 ++++++++-------------- 15 files changed, 174 insertions(+), 85 deletions(-) diff --git a/mythtv/libs/libmythbase/libmythbase.pro b/mythtv/libs/libmythbase/libmythbase.pro index 228617a..286f909 100644
a b HEADERS += threadedfilewriter.h mythsingledownload.h codecutil.h 34 34 HEADERS += mythsession.h 35 35 HEADERS += ../../external/qjsonwrapper/qjsonwrapper/Json.h 36 36 HEADERS += cleanupguard.h 37 HEADERS += mythsorthelper.h 37 38 38 39 SOURCES += mthread.cpp mthreadpool.cpp 39 40 SOURCES += mythsocket.cpp … … SOURCES += threadedfilewriter.cpp mythsingledownload.cpp codecutil.cpp 55 56 SOURCES += mythsession.cpp 56 57 SOURCES += ../../external/qjsonwrapper/qjsonwrapper/Json.cpp 57 58 SOURCES += cleanupguard.cpp 59 SOURCES += mythsorthelper.cpp 58 60 59 61 unix { 60 62 SOURCES += mythsystemunix.cpp … … inc.files += plist.h bswap.h signalhandling.h ffmpeg-mmx.h mythdate.h 84 86 inc.files += mythplugin.h mythpluginapi.h mythqtcompat.h 85 87 inc.files += remotefile.h mythsystemlegacy.h mythtypes.h 86 88 inc.files += threadedfilewriter.h mythsingledownload.h mythsession.h 89 inc.files += mythsorthelper.h 87 90 88 91 # Allow both #include <blah.h> and #include <libmythbase/blah.h> 89 92 inc2.path = $${PREFIX}/include/mythtv/libmythbase -
new file mythtv/libs/libmythbase/mythsorthelper.cpp
diff --git a/mythtv/libs/libmythbase/mythsorthelper.cpp b/mythtv/libs/libmythbase/mythsorthelper.cpp new file mode 100644 index 0000000..9f1de4b
- + 1 // -*- Mode: c++ -*- 2 // vim: set expandtab tabstop=4 shiftwidth=4 3 4 #include "mythsorthelper.h" 5 #include "mythcorecontext.h" 6 7 SortHelper::SortHelper() 8 { 9 QString prefixes(tr("^(The |A |An )", 10 "Regular Expression for what to ignore when sorting")); 11 m_ignore_case = gCoreContext->GetNumSetting("SortIgnoreCase", true); 12 m_ignore_prefixes = gCoreContext->GetNumSetting("SortIgnorePrefixes", true); 13 QString excludes = gCoreContext->GetSetting("SortIgnorePrefixExceptions", ""); 14 if (m_ignore_case) 15 { 16 prefixes = prefixes.toLower(); 17 excludes = excludes.toLower(); 18 } 19 m_ign_regex1 = QRegExp(prefixes); 20 m_ign_regex2 = QRegExp(prefixes.replace("^","/")); 21 m_excl_list = excludes.split(";", QString::SkipEmptyParts); 22 for (int i = 0; i < m_excl_list.size(); i++) 23 m_excl_list[i] = m_excl_list[i].trimmed(); 24 m_creator = "unknown"; 25 } 26 27 QString SortHelper::doTitle(QString title) const 28 { 29 if (m_ignore_case) 30 title = title.toLower(); 31 if (not m_ignore_prefixes) 32 return title; 33 if (m_excl_list.contains(title)) 34 return title; 35 return title.remove(m_ign_regex1); 36 } 37 38 QString SortHelper::doFilename(QString filename) const 39 { 40 if (m_ignore_case) 41 filename = filename.toLower(); 42 if (not m_ignore_prefixes) 43 return filename; 44 if (m_excl_list.contains(filename)) 45 return filename; 46 return filename.remove(m_ign_regex1).replace(m_ign_regex2, "/"); 47 } -
new file mythtv/libs/libmythbase/mythsorthelper.h
diff --git a/mythtv/libs/libmythbase/mythsorthelper.h b/mythtv/libs/libmythbase/mythsorthelper.h new file mode 100644 index 0000000..d2697d7
- + 1 // -*- Mode: c++ -*- 2 // vim: set expandtab tabstop=4 shiftwidth=4 3 4 #ifndef MYTHSORTHELPER_H_ 5 #define MYTHSORTHELPER_H_ 6 7 #include <QCoreApplication> 8 #include "mythbaseexp.h" 9 10 class MBASE_PUBLIC SortHelper 11 { 12 Q_DECLARE_TR_FUNCTIONS(SortHelper) 13 14 public: 15 SortHelper(); 16 QString doTitle(QString title) const; 17 QString doFilename(QString filename) const; 18 19 private: 20 bool m_ignore_case; 21 22 bool m_ignore_prefixes; 23 QRegExp m_ign_regex1; // Anchored at the start 24 QRegExp m_ign_regex2; // Following a '/' 25 26 QStringList m_excl_list; 27 QString m_creator; 28 }; 29 30 #endif // MYTHSORTHELPER_H_ -
mythtv/libs/libmythmetadata/videometadata.cpp
diff --git a/mythtv/libs/libmythmetadata/videometadata.cpp b/mythtv/libs/libmythmetadata/videometadata.cpp index 8f4c2b4..9021e55 100644
a b void VideoMetadataImp::GetImageMap(InfoMap &imageMap) const 961 961 //// Metadata 962 962 //////////////////////////////////////// 963 963 VideoMetadata::SortKey VideoMetadata::GenerateDefaultSortKey(const VideoMetadata &m, 964 bool ignore_case)964 const SortHelper &sort_helper) 965 965 { 966 QString title(ignore_case ? m.GetTitle().toLower() : m.GetTitle()); 967 title = TrimTitle(title, ignore_case); 968 969 return SortKey(SortData(title, m.GetFilename(), 966 QString title = sort_helper.doTitle(m.GetTitle()); 967 QString filename = sort_helper.doFilename(m.GetFilename()); 968 return SortKey(SortData(title, filename, 970 969 QString().sprintf("%.7d", m.GetID()))); 971 970 } 972 971 … … QString VideoMetadata::FilenameToMeta(const QString &file_name, int position) 1172 1171 return QString(); 1173 1172 } 1174 1173 1175 namespace1176 {1177 const QRegExp &getTitleTrim(bool ignore_case)1178 {1179 static QString pattern(VideoMetadata::tr("^(The |A |An )"));1180 static QRegExp prefixes_case(pattern, Qt::CaseSensitive);1181 static QRegExp prefixes_nocase(pattern, Qt::CaseInsensitive);1182 return ignore_case ? prefixes_nocase : prefixes_case;1183 }1184 }1185 1186 QString VideoMetadata::TrimTitle(const QString &title, bool ignore_case)1187 {1188 QString ret(title);1189 ret.remove(getTitleTrim(ignore_case));1190 return ret;1191 }1192 1193 1174 VideoMetadata::VideoMetadata(const QString &filename, const QString &hash, 1194 1175 const QString &trailer, const QString &coverfile, 1195 1176 const QString &screenshot, const QString &banner, const QString &fanart, -
mythtv/libs/libmythmetadata/videometadata.h
diff --git a/mythtv/libs/libmythmetadata/videometadata.h b/mythtv/libs/libmythmetadata/videometadata.h index a02587c..3587576 100644
a b 11 11 #include "parentalcontrols.h" 12 12 #include "mythmetaexp.h" 13 13 #include "metadatacommon.h" 14 #include "mythsorthelper.h" 14 15 15 16 class MSqlQuery; 16 17 class VideoMetadataListManager; … … class META_PUBLIC VideoMetadata 53 54 }; 54 55 55 56 public: 56 static SortKey GenerateDefaultSortKey(const VideoMetadata &m, bool ignore_case); 57 static SortKey GenerateDefaultSortKey(const VideoMetadata &m, 58 const SortHelper &sort_helper); 57 59 static int UpdateHashedDBRecord(const QString &hash, const QString &file_name, 58 60 const QString &host); 59 61 static QString VideoFileHash(const QString &file_name, const QString &host); -
mythtv/programs/mythfrontend/globalsettings.cpp
diff --git a/mythtv/programs/mythfrontend/globalsettings.cpp b/mythtv/programs/mythfrontend/globalsettings.cpp index b90d080..eb611e0 100644
a b ChannelGroupSettings::ChannelGroupSettings() : 2755 2755 addTarget("1", new VerticalConfigurationGroup(true,false)); 2756 2756 }; 2757 2757 2758 static HostCheckBox *SortIgnoreCase() 2759 { 2760 HostCheckBox *gc = new HostCheckBox("SortIgnoreCase"); 2761 gc->setLabel(GeneralSettings::tr("Ignore case when sorting")); 2762 gc->setValue(true); 2763 gc->setHelpText(GeneralSettings::tr("If enabled, all sorting will be case-insensitive.")); 2764 return gc; 2765 } 2766 2767 static HostCheckBox *SortIgnorePrefixes() 2768 { 2769 HostCheckBox *gc = new HostCheckBox("SortIgnorePrefixes"); 2770 2771 gc->setLabel(GeneralSettings::tr("Ignore prefixes when sorting")); 2772 gc->setValue(true); 2773 gc->setHelpText(GeneralSettings::tr("If enabled, video listings will " 2774 "ignore common prefixes (The, A, An) when " 2775 "sorting show names.")); 2776 return gc; 2777 } 2778 2779 static HostLineEdit *SortIgnorePrefixExceptions() 2780 { 2781 HostLineEdit *gc = new HostLineEdit("SortIgnorePrefixExceptions"); 2782 2783 gc->setLabel(MainGeneralSettings::tr("Names exempt from prefix removal")); 2784 gc->setValue(""); 2785 gc->setHelpText(MainGeneralSettings::tr("When stripping common prefixes (The, A, An) " 2786 "from filenames, this list of names " 2787 "will be exempt from that process. " 2788 "Enter multiple names separated by ';'.")); 2789 return gc; 2790 } 2791 2792 2758 2793 // General RecPriorities settings 2759 2794 2760 2795 static GlobalComboBox *GRSchedOpenEnd() … … MainGeneralSettings::MainGeneralSettings() 3862 3897 general->setLabel(tr("General")); 3863 3898 general->addChild(UseVirtualKeyboard()); 3864 3899 general->addChild(ScreenShotPath()); 3900 general->addChild(SortIgnoreCase()); 3901 general->addChild(SortIgnorePrefixes()); 3902 general->addChild(SortIgnorePrefixExceptions()); 3865 3903 addChild(general); 3866 3904 3867 3905 VerticalConfigurationGroup *media = -
mythtv/programs/mythfrontend/playbackbox.cpp
diff --git a/mythtv/programs/mythfrontend/playbackbox.cpp b/mythtv/programs/mythfrontend/playbackbox.cpp index 0141a39..fbc4dd8 100644
a b static PlaybackBox::ViewMask m_viewMaskToggle(PlaybackBox::ViewMask mask, 219 219 static QString construct_sort_title( 220 220 QString title, PlaybackBox::ViewMask viewmask, 221 221 PlaybackBox::ViewTitleSort titleSort, int recpriority, 222 const QRegExp &prefixes)222 const SortHelper &sortHelper) 223 223 { 224 224 if (title.isEmpty()) 225 225 return title; 226 226 227 QString sTitle = title;227 QString sTitle = sortHelper.doTitle(title); 228 228 229 sTitle.remove(prefixes);230 229 if (viewmask == PlaybackBox::VIEW_TITLES && 231 230 titleSort == PlaybackBox::TitleSortRecPriority) 232 231 { … … void * PlaybackBox::RunPlaybackBox(void * player, bool showTV) 386 385 PlaybackBox::PlaybackBox(MythScreenStack *parent, QString name, 387 386 TV *player, bool showTV) 388 387 : ScheduleCommon(parent, name), 389 m_ prefixes(QObject::tr("^(The |A |An )")),388 m_sortHelper(), 390 389 m_titleChaff(" \\(.*\\)$"), 391 390 // UI variables 392 391 m_recgroupList(NULL), … … bool PlaybackBox::UpdateUILists(void) 1721 1720 { 1722 1721 sTitle = construct_sort_title( 1723 1722 p->GetTitle(), m_viewMask, titleSort, 1724 p->GetRecordingPriority(), m_ prefixes);1723 p->GetRecordingPriority(), m_sortHelper); 1725 1724 sTitle = sTitle.toLower(); 1726 1725 1727 1726 if (!sortedList.contains(sTitle)) -
mythtv/programs/mythfrontend/playbackbox.h
diff --git a/mythtv/programs/mythfrontend/playbackbox.h b/mythtv/programs/mythfrontend/playbackbox.h index 6b7e144..236bd0a 100644
a b using namespace std; 24 24 25 25 #include "mythscreentype.h" 26 26 #include "metadatafactory.h" 27 #include "mythsorthelper.h" 27 28 28 29 // mythfrontend 29 30 #include "schedulecommon.h" … … class PlaybackBox : public ScheduleCommon 338 339 QString extract_commflag_state(const ProgramInfo &pginfo); 339 340 340 341 341 QRegExp m_prefixes;///< prefixes to be ignored when sorting342 SortHelper m_sortHelper; ///< prefixes to be ignored when sorting 342 343 QRegExp m_titleChaff; ///< stuff to remove for search rules 343 344 344 345 MythUIButtonList *m_recgroupList; -
mythtv/programs/mythfrontend/proglist.cpp
diff --git a/mythtv/programs/mythfrontend/proglist.cpp b/mythtv/programs/mythfrontend/proglist.cpp index 37e4506..72ef41e 100644
a b using namespace std; 27 27 #include "tv_actions.h" // for ACTION_CHANNELSEARCH 28 28 #include "mythdb.h" 29 29 #include "mythdate.h" 30 #include "mythsorthelper.h" 30 31 31 32 #define LOC QString("ProgLister: ") 32 33 #define LOC_WARN QString("ProgLister, Warning: ") … … ProgLister::ProgLister(MythScreenStack *parent, ProgListType pltype, 71 72 m_progList(NULL), 72 73 m_messageText(NULL), 73 74 75 m_sortHelper(), 76 74 77 m_allowViewDialog(true) 75 78 { 76 79 if (pltype == plMovies) … … ProgLister::ProgLister( 139 142 m_progList(NULL), 140 143 m_messageText(NULL), 141 144 145 m_sortHelper(), 146 142 147 m_allowViewDialog(true) 143 148 { 144 149 } … … void ProgLister::FillItemList(bool restorePosition, bool updateDisp) 1384 1389 LoadFromProgram(m_itemList, where, bindings, m_schedList); 1385 1390 } 1386 1391 1387 const QRegExp prefixes(1388 tr("^(The |A |An )",1389 "Regular Expression for what to ignore when sorting"));1390 1392 for (uint i = 0; i < m_itemList.size(); i++) 1391 1393 { 1392 1394 ProgramInfo *s = m_itemList[i]; 1393 1395 if (s) 1394 1396 { 1395 1397 s->sortTitle = (m_type == plTitle) ? s->GetSubtitle() : s->GetTitle(); 1396 s->sortTitle .remove(prefixes);1398 s->sortTitle = m_sortHelper.doTitle(s->sortTitle); 1397 1399 } 1398 1400 } 1399 1401 -
mythtv/programs/mythfrontend/proglist.h
diff --git a/mythtv/programs/mythfrontend/proglist.h b/mythtv/programs/mythfrontend/proglist.h index 39bb0de..e0c105d 100644
a b 9 9 #include "programinfo.h" // for ProgramList 10 10 #include "schedulecommon.h" 11 11 #include "proglist_helpers.h" 12 #include "mythsorthelper.h" 12 13 13 14 enum ProgListType { 14 15 plUnknown = 0, … … class ProgLister : public ScheduleCommon 128 129 MythUIButtonList *m_progList; 129 130 MythUIText *m_messageText; 130 131 132 SortHelper m_sortHelper; 133 131 134 bool m_allowViewDialog; 132 135 }; 133 136 -
mythtv/programs/mythfrontend/programrecpriority.cpp
diff --git a/mythtv/programs/mythfrontend/programrecpriority.cpp b/mythtv/programs/mythfrontend/programrecpriority.cpp index 4635873..924a5b5 100644
a b ProgramRecPriority::ProgramRecPriority(MythScreenStack *parent, 406 406 m_lastRecordedText(NULL), m_lastRecordedDateText(NULL), 407 407 m_lastRecordedTimeText(NULL), m_channameText(NULL), 408 408 m_channumText(NULL), m_callsignText(NULL), 409 m_recProfileText(NULL), m_currentItem(NULL) 409 m_recProfileText(NULL), m_currentItem(NULL), m_sortHelper() 410 410 { 411 411 m_sortType = (SortType)gCoreContext->GetNumSetting("ProgramRecPrioritySorting", 412 412 (int)byTitle); … … void ProgramRecPriority::FillList(void) 1208 1208 { 1209 1209 ProgramRecPriorityInfo *progInfo = &(*it); 1210 1210 1211 progInfo->sortTitle = progInfo->title; 1212 progInfo->sortTitle.remove(QRegExp(tr("^(The |A |An )"))); 1211 progInfo->sortTitle = m_sortHelper.doTitle(progInfo->title); 1213 1212 1214 1213 progInfo->recType = recType; 1215 1214 progInfo->matchCount = -
mythtv/programs/mythfrontend/programrecpriority.h
diff --git a/mythtv/programs/mythfrontend/programrecpriority.h b/mythtv/programs/mythfrontend/programrecpriority.h index a876eb5..ea72135 100644
a b 5 5 6 6 #include "recordinginfo.h" 7 7 #include "mythscreentype.h" 8 #include "mythsorthelper.h" 8 9 9 10 // mythfrontend 10 11 #include "schedulecommon.h" … … class ProgramRecPriority : public ScheduleCommon 129 130 bool m_reverseSort; 130 131 131 132 SortType m_sortType; 133 SortHelper m_sortHelper; 132 134 }; 133 135 134 136 Q_DECLARE_METATYPE(ProgramRecPriorityInfo *) -
mythtv/programs/mythfrontend/videofilter.cpp
diff --git a/mythtv/programs/mythfrontend/videofilter.cpp b/mythtv/programs/mythfrontend/videofilter.cpp index 2e82927..fc13bb5 100644
a b VideoFilterSettings::VideoFilterSettings(bool loaddefaultsettings, 79 79 m_parental_level(ParentalLevel::plNone), textfilter(""), 80 80 season(-1), episode(-1), insertdate(QDate()), 81 81 re_season("(\\d+)[xX](\\d*)"), re_date("-(\\d+)([dmw])"), 82 m_changed_state(0) 82 m_changed_state(0), m_sortHelper() 83 83 { 84 84 if (_prefix.isEmpty()) 85 85 prefix = "VideoDefault"; … … bool VideoFilterSettings::matches_filter(const VideoMetadata &mdata) const 389 389 390 390 /// Compares two VideoMetadata instances 391 391 bool VideoFilterSettings::meta_less_than(const VideoMetadata &lhs, 392 const VideoMetadata &rhs, 393 bool sort_ignores_case) const 392 const VideoMetadata &rhs) const 394 393 { 395 394 bool ret = false; 396 395 switch (orderby) … … bool VideoFilterSettings::meta_less_than(const VideoMetadata &lhs, 407 406 else 408 407 { 409 408 lhs_key = VideoMetadata::GenerateDefaultSortKey(lhs, 410 sort_ignores_case);409 m_sortHelper); 411 410 rhs_key = VideoMetadata::GenerateDefaultSortKey(rhs, 412 sort_ignores_case);411 m_sortHelper); 413 412 } 414 413 ret = lhs_key < rhs_key; 415 414 break; … … bool VideoFilterSettings::meta_less_than(const VideoMetadata &lhs, 433 432 else 434 433 { 435 434 lhs_key = VideoMetadata::GenerateDefaultSortKey(lhs, 436 sort_ignores_case);435 m_sortHelper); 437 436 rhs_key = VideoMetadata::GenerateDefaultSortKey(rhs, 438 sort_ignores_case);437 m_sortHelper); 439 438 } 440 439 ret = lhs_key < rhs_key; 441 440 } … … bool VideoFilterSettings::meta_less_than(const VideoMetadata &lhs, 463 462 } 464 463 case kOrderByFilename: 465 464 { 466 QString lhsfn(sort_ignores_case ? 467 lhs.GetFilename().toLower() : lhs.GetFilename()); 468 QString rhsfn(sort_ignores_case ? 469 rhs.GetFilename().toLower() : rhs.GetFilename()); 465 QString lhsfn = m_sortHelper.doFilename(lhs.GetFilename()); 466 QString rhsfn = m_sortHelper.doFilename(rhs.GetFilename()); 470 467 ret = naturalCompare(lhsfn, rhsfn) < 0; 471 468 break; 472 469 } -
mythtv/programs/mythfrontend/videofilter.h
diff --git a/mythtv/programs/mythfrontend/videofilter.h b/mythtv/programs/mythfrontend/videofilter.h index d518abf..6bee2e1 100644
a b 4 4 // MythTV headers 5 5 #include "mythscreentype.h" 6 6 #include "parentalcontrols.h" 7 #include "mythsorthelper.h" 7 8 8 9 // Qt headers 9 10 #include <QCoreApplication> … … class VideoFilterSettings 48 49 VideoFilterSettings &operator=(const VideoFilterSettings &rhs); 49 50 50 51 bool matches_filter(const VideoMetadata &mdata) const; 51 bool meta_less_than(const VideoMetadata &lhs, const VideoMetadata &rhs, 52 bool sort_ignores_case) const; 52 bool meta_less_than(const VideoMetadata &lhs, const VideoMetadata &rhs) const; 53 53 54 54 void saveAsDefault(); 55 55 … … class VideoFilterSettings 190 190 const QRegExp re_season; 191 191 const QRegExp re_date; 192 192 193 194 193 unsigned int m_changed_state; 194 195 SortHelper m_sortHelper; 195 196 }; 196 197 197 198 struct FilterSettingsProxy -
mythtv/programs/mythfrontend/videolist.cpp
diff --git a/mythtv/programs/mythfrontend/videolist.cpp b/mythtv/programs/mythfrontend/videolist.cpp index 9c32b2d..032cb8a 100644
a b QString TreeNodeData::GetPrefix(void) const 149 149 /// metadata sort function 150 150 struct metadata_sort 151 151 { 152 metadata_sort(const VideoFilterSettings &vfs, bool sort_ignores_case) : 153 m_vfs(vfs), m_sic(sort_ignores_case) {} 152 metadata_sort(const VideoFilterSettings &vfs) : m_vfs(vfs) {} 154 153 155 154 bool operator()(const VideoMetadata *lhs, const VideoMetadata *rhs) 156 155 { 157 return m_vfs.meta_less_than(*lhs, *rhs , m_sic);156 return m_vfs.meta_less_than(*lhs, *rhs); 158 157 } 159 158 160 159 bool operator()(const smart_meta_node &lhs, const smart_meta_node &rhs) 161 160 { 162 return m_vfs.meta_less_than(*(lhs->getData()), *(rhs->getData()), 163 m_sic); 161 return m_vfs.meta_less_than(*(lhs->getData()), *(rhs->getData())); 164 162 } 165 163 166 164 private: 167 165 const VideoFilterSettings &m_vfs; 168 bool m_sic;169 166 }; 170 167 171 168 struct metadata_path_sort 172 169 { 173 explicit metadata_path_sort( bool ignore_case) : m_ignore_case(ignore_case) {}170 explicit metadata_path_sort(void) : m_sortHelper() {} 174 171 175 172 bool operator()(const VideoMetadata &lhs, const VideoMetadata &rhs) 176 173 { … … struct metadata_path_sort 187 184 return sort(lhs->getPath(), rhs->getPath()); 188 185 } 189 186 190 private:191 const QRegExp &getTrim(void)192 {193 static QString pattern(VideoMetadata::tr("^(The |A |An )"));194 if (m_ignore_case)195 return QRegExp(prefixes, Qt::CaseInsensitive);196 return QRegExp(prefixes, Qt::CaseSensitive);197 }198 199 187 bool sort(const VideoMetadata *lhs, const VideoMetadata *rhs) 200 188 { 201 189 return sort(lhs->GetFilename(), rhs->GetFilename()); … … struct metadata_path_sort 203 191 204 192 bool sort(const QString &lhs, const QString &rhs) 205 193 { 206 const QRegExp prefixes = getTrim(); 207 QString lhs_comp = QString(lhs).remove(prefixes); 208 QString rhs_comp = QString(rhs).remove(prefixes); 209 if (m_ignore_case) 210 { 211 lhs_comp = lhs_comp.toLower(); 212 rhs_comp = rhs_comp.toLower(); 213 } 194 QString lhs_comp = m_sortHelper.doFilename(lhs); 195 QString rhs_comp = m_sortHelper.doFilename(rhs); 214 196 return naturalCompare(lhs_comp, rhs_comp) < 0; 215 197 } 216 198 217 bool m_ignore_case;199 SortHelper m_sortHelper; 218 200 }; 219 201 220 202 static QString path_to_node_name(const QString &path) … … class VideoListImp 476 458 metadata_list_type m_metadata_list_type; 477 459 478 460 VideoFilterSettings m_video_filter; 461 462 SortHelper m_sortHelper; 479 463 }; 480 464 481 465 VideoList::VideoList() … … void VideoList::InvalidateCache(void) 558 542 // VideoListImp 559 543 ////////////////////////////// 560 544 VideoListImp::VideoListImp() : m_metadata_view_tree("", "top"), 561 m_metadata_list_type(ltNone) 545 m_metadata_list_type(ltNone), 546 m_sortHelper() 562 547 { 563 548 m_ListUnknown = gCoreContext->GetNumSetting("VideoListUnknownFileTypes", 0); 564 549 … … void VideoListImp::sort_view_data(bool flat_list) 760 745 if (flat_list) 761 746 { 762 747 sort(m_metadata_view_flat.begin(), m_metadata_view_flat.end(), 763 metadata_sort(m_video_filter , true));748 metadata_sort(m_video_filter)); 764 749 } 765 750 else 766 751 { 767 m_metadata_view_tree.sort(metadata_path_sort(true), 768 metadata_sort(m_video_filter, 769 true)); 752 m_metadata_view_tree.sort(metadata_path_sort(), 753 metadata_sort(m_video_filter)); 770 754 } 771 755 } 772 756 … … void VideoListImp::buildGroupList(metadata_list_type whence) 820 804 transform(m_metadata.getList().begin(), m_metadata.getList().end(), 821 805 mli, to_metadata_ptr()); 822 806 823 metadata_path_sort mps (true);807 metadata_path_sort mps = metadata_path_sort(); 824 808 sort(mlist.begin(), mlist.end(), mps); 825 809 826 810 typedef map<QString, meta_dir_node *> group_to_node_map; … … void VideoListImp::buildTVList(void) 953 937 transform(m_metadata.getList().begin(), m_metadata.getList().end(), 954 938 mli, to_metadata_ptr()); 955 939 956 metadata_path_sort mps (true);940 metadata_path_sort mps = metadata_path_sort(); 957 941 sort(mlist.begin(), mlist.end(), mps); 958 942 959 943 meta_dir_node *video_root = &m_metadata_tree; … … void VideoListImp::buildDbList() 999 983 1000 984 // print_meta_list(mlist); 1001 985 1002 metadata_path_sort mps (true);986 metadata_path_sort mps = metadata_path_sort(); 1003 987 sort(mlist.begin(), mlist.end(), mps); 1004 988 1005 989 // TODO: break out the prefix in the DB so this isn't needed … … void VideoListImp::update_meta_view(bool flat_list) 1163 1147 if (!(*si)->HasSortKey()) 1164 1148 { 1165 1149 VideoMetadata::SortKey skey = 1166 VideoMetadata::GenerateDefaultSortKey(*(*si), true);1150 VideoMetadata::GenerateDefaultSortKey(*(*si), m_sortHelper); 1167 1151 (*si)->SetSortKey(skey); 1168 1152 } 1169 1153 }