Skip to content
This repository
Browse code

Merge pull request #3246 from bavison/faster_sorting_step2

Faster sorting of CFileItemLists, step 2
  • Loading branch information...
commit c0a666eeb5c573f01f73a832c78c4f7df68b53d9 2 parents 464a2ed + a94f3c7
jmarshallnz authored October 03, 2013
69  xbmc/FileItem.cpp
@@ -699,45 +699,58 @@ void CFileItem::Serialize(CVariant& value) const
699 699
     (*m_pictureInfoTag).Serialize(value["pictureInfoTag"]);
700 700
 }
701 701
 
702  
-void CFileItem::ToSortable(SortItem &sortable)
703  
-{
704  
-  sortable[FieldPath] = m_strPath;
705  
-  sortable[FieldDate] = (m_dateTime.IsValid()) ? m_dateTime.GetAsDBDateTime() : "";
706  
-  sortable[FieldSize] = m_dwSize;
707  
-  sortable[FieldDriveType] = m_iDriveType;
708  
-  sortable[FieldStartOffset] = m_lStartOffset;
709  
-  sortable[FieldEndOffset] = m_lEndOffset;
710  
-  sortable[FieldProgramCount] = m_iprogramCount;
711  
-  sortable[FieldBitrate] = m_dwSize;
712  
-  sortable[FieldTitle] = m_strTitle;
713  
-  sortable[FieldSortSpecial] = m_specialSort;
714  
-  sortable[FieldFolder] = m_bIsFolder;
715  
-
  702
+void CFileItem::ToSortable(SortItem &sortable, Field field) const
  703
+{
  704
+  switch (field)
  705
+  {
  706
+  case FieldPath:         sortable[FieldPath] = m_strPath; break;
  707
+  case FieldDate:         sortable[FieldDate] = (m_dateTime.IsValid()) ? m_dateTime.GetAsDBDateTime() : ""; break;
  708
+  case FieldSize:         sortable[FieldSize] = m_dwSize; break;
  709
+  case FieldDriveType:    sortable[FieldDriveType] = m_iDriveType; break;
  710
+  case FieldStartOffset:  sortable[FieldStartOffset] = m_lStartOffset; break;
  711
+  case FieldEndOffset:    sortable[FieldEndOffset] = m_lEndOffset; break;
  712
+  case FieldProgramCount: sortable[FieldProgramCount] = m_iprogramCount; break;
  713
+  case FieldBitrate:      sortable[FieldBitrate] = m_dwSize; break;
  714
+  case FieldTitle:        sortable[FieldTitle] = m_strTitle; break;
716 715
   // If there's ever a need to convert more properties from CGUIListItem it might be
717 716
   // worth to make CGUIListItem  implement ISortable as well and call it from here
718  
-  sortable[FieldLabel] = GetLabel();
  717
+  default: break;
  718
+  }
719 719
 
720 720
   if (HasMusicInfoTag())
721  
-    GetMusicInfoTag()->ToSortable(sortable);
722  
-    
  721
+    GetMusicInfoTag()->ToSortable(sortable, field);
  722
+
723 723
   if (HasVideoInfoTag())
724 724
   {
725  
-    GetVideoInfoTag()->ToSortable(sortable);
  725
+    GetVideoInfoTag()->ToSortable(sortable, field);
726 726
 
727 727
     if (GetVideoInfoTag()->m_type == "tvshow")
728 728
     {
729  
-      if (HasProperty("totalepisodes"))
  729
+      if (field == FieldNumberOfEpisodes && HasProperty("totalepisodes"))
730 730
         sortable[FieldNumberOfEpisodes] = GetProperty("totalepisodes");
731  
-      if (HasProperty("unwatchedepisodes"))
  731
+      if (field == FieldNumberOfWatchedEpisodes && HasProperty("unwatchedepisodes"))
732 732
         sortable[FieldNumberOfWatchedEpisodes] = GetProperty("unwatchedepisodes");
733 733
     }
734 734
   }
735  
-    
  735
+
736 736
   if (HasPictureInfoTag())
737  
-    GetPictureInfoTag()->ToSortable(sortable);
  737
+    GetPictureInfoTag()->ToSortable(sortable, field);
738 738
 
739 739
   if (HasPVRChannelInfoTag())
740  
-    GetPVRChannelInfoTag()->ToSortable(sortable);
  740
+    GetPVRChannelInfoTag()->ToSortable(sortable, field);
  741
+}
  742
+
  743
+void CFileItem::ToSortable(SortItem &sortable, const Fields &fields) const
  744
+{
  745
+  Fields::const_iterator it;
  746
+  for (it = fields.begin(); it != fields.end(); it++)
  747
+    ToSortable(sortable, *it);
  748
+
  749
+  /* FieldLabel is used as a fallback by all sorters and therefore has to be present as well */
  750
+  sortable[FieldLabel] = GetLabel();
  751
+  /* FieldSortSpecial and FieldFolder are required in conjunction with all other sorters as well */
  752
+  sortable[FieldSortSpecial] = m_specialSort;
  753
+  sortable[FieldFolder] = m_bIsFolder;
741 754
 }
742 755
 
743 756
 bool CFileItem::Exists(bool bUseCache /* = true */) const
@@ -1887,11 +1900,13 @@ void CFileItemList::Sort(SortDescription sortDescription)
1887 1900
   if (m_sortIgnoreFolders)
1888 1901
     sortDescription.sortAttributes = (SortAttribute)((int)sortDescription.sortAttributes | SortAttributeIgnoreFolders);
1889 1902
 
  1903
+  const Fields fields = SortUtils::GetFieldsForSorting(sortDescription.sortBy);
1890 1904
   SortItems sortItems((size_t)Size());
1891 1905
   for (int index = 0; index < Size(); index++)
1892 1906
   {
1893  
-    m_items[index]->ToSortable(sortItems[index]);
1894  
-    sortItems[index][FieldId] = index;
  1907
+    sortItems[index] = boost::shared_ptr<SortItem>(new SortItem);
  1908
+    m_items[index]->ToSortable(*sortItems[index], fields);
  1909
+    (*sortItems[index])[FieldId] = index;
1895 1910
   }
1896 1911
 
1897 1912
   // do the sorting
@@ -1902,9 +1917,9 @@ void CFileItemList::Sort(SortDescription sortDescription)
1902 1917
   sortedFileItems.reserve(Size());
1903 1918
   for (SortItems::const_iterator it = sortItems.begin(); it != sortItems.end(); it++)
1904 1919
   {
1905  
-    CFileItemPtr item = m_items[(int)it->at(FieldId).asInteger()];
  1920
+    CFileItemPtr item = m_items[(int)(*it)->at(FieldId).asInteger()];
1906 1921
     // Set the sort label in the CFileItem
1907  
-    item->SetSortLabel(CStdStringW(it->at(FieldSort).asWideString()));
  1922
+    item->SetSortLabel(CStdStringW((*it)->at(FieldSort).asWideString()));
1908 1923
 
1909 1924
     sortedFileItems.push_back(item);
1910 1925
   }
3  xbmc/FileItem.h
@@ -113,7 +113,8 @@ class CFileItem :
113 113
   const CFileItem& operator=(const CFileItem& item);
114 114
   virtual void Archive(CArchive& ar);
115 115
   virtual void Serialize(CVariant& value) const;
116  
-  virtual void ToSortable(SortItem &sortable);
  116
+  virtual void ToSortable(SortItem &sortable, Field field) const;
  117
+  void ToSortable(SortItem &sortable, const Fields &fields) const;
117 118
   virtual bool IsFileItem() const { return true; };
118 119
 
119 120
   bool Exists(bool bUseCache = true) const;
36  xbmc/music/tags/MusicInfoTag.cpp
@@ -590,22 +590,26 @@ void CMusicInfoTag::Serialize(CVariant& value) const
590 590
   value["compilationartist"] = m_bCompilation;
591 591
 }
592 592
 
593  
-void CMusicInfoTag::ToSortable(SortItem& sortable)
594  
-{
595  
-  sortable[FieldTitle] = m_strTitle;
596  
-  sortable[FieldArtist] = m_artist;
597  
-  sortable[FieldAlbum] = m_strAlbum;
598  
-  sortable[FieldAlbumArtist] = FieldAlbumArtist;
599  
-  sortable[FieldGenre] = m_genre;
600  
-  sortable[FieldTime] = m_iDuration;
601  
-  sortable[FieldTrackNumber] = m_iTrack;
602  
-  sortable[FieldYear] = m_dwReleaseDate.wYear;
603  
-  sortable[FieldComment] = m_strComment;
604  
-  sortable[FieldRating] = (float)(m_rating - '0');
605  
-  sortable[FieldPlaycount] = m_iTimesPlayed;
606  
-  sortable[FieldLastPlayed] = m_lastPlayed.IsValid() ? m_lastPlayed.GetAsDBDateTime() : StringUtils::EmptyString;
607  
-  sortable[FieldListeners] = m_listeners;
608  
-  sortable[FieldId] = (int64_t)m_iDbId;
  593
+void CMusicInfoTag::ToSortable(SortItem& sortable, Field field) const
  594
+{
  595
+  switch (field)
  596
+  {
  597
+  case FieldTitle:       sortable[FieldTitle] = m_strTitle; break;
  598
+  case FieldArtist:      sortable[FieldArtist] = m_artist; break;
  599
+  case FieldAlbum:       sortable[FieldAlbum] = m_strAlbum; break;
  600
+  case FieldAlbumArtist: sortable[FieldAlbumArtist] = m_albumArtist; break;
  601
+  case FieldGenre:       sortable[FieldGenre] = m_genre; break;
  602
+  case FieldTime:        sortable[FieldTime] = m_iDuration; break;
  603
+  case FieldTrackNumber: sortable[FieldTrackNumber] = m_iTrack; break;
  604
+  case FieldYear:        sortable[FieldYear] = m_dwReleaseDate.wYear; break;
  605
+  case FieldComment:     sortable[FieldComment] = m_strComment; break;
  606
+  case FieldRating:      sortable[FieldRating] = (float)(m_rating - '0'); break;
  607
+  case FieldPlaycount:   sortable[FieldPlaycount] = m_iTimesPlayed; break;
  608
+  case FieldLastPlayed:  sortable[FieldLastPlayed] = m_lastPlayed.IsValid() ? m_lastPlayed.GetAsDBDateTime() : StringUtils::EmptyString; break;
  609
+  case FieldListeners:   sortable[FieldListeners] = m_listeners; break;
  610
+  case FieldId:          sortable[FieldId] = (int64_t)m_iDbId; break;
  611
+  default: break;
  612
+  }
609 613
 }
610 614
 
611 615
 void CMusicInfoTag::Archive(CArchive& ar)
2  xbmc/music/tags/MusicInfoTag.h
@@ -173,7 +173,7 @@ class CMusicInfoTag : public IArchivable, public ISerializable, public ISortable
173 173
 
174 174
   virtual void Archive(CArchive& ar);
175 175
   virtual void Serialize(CVariant& ar) const;
176  
-  virtual void ToSortable(SortItem& sortable);
  176
+  virtual void ToSortable(SortItem& sortable, Field field) const;
177 177
 
178 178
   void Clear();
179 179
 protected:
4  xbmc/pictures/PictureInfoTag.cpp
@@ -270,9 +270,9 @@ void CPictureInfoTag::Serialize(CVariant& value) const
270 270
   value["imagetype"] = CStdString(m_iptcInfo.ImageType);
271 271
 }
272 272
 
273  
-void CPictureInfoTag::ToSortable(SortItem& sortable)
  273
+void CPictureInfoTag::ToSortable(SortItem& sortable, Field field) const
274 274
 {
275  
-  if (m_dateTimeTaken.IsValid())
  275
+  if (field == FieldDateTaken && m_dateTimeTaken.IsValid())
276 276
     sortable[FieldDateTaken] = m_dateTimeTaken.GetAsDBDateTime();
277 277
 }
278 278
 
2  xbmc/pictures/PictureInfoTag.h
@@ -96,7 +96,7 @@ class CPictureInfoTag : public IArchivable, public ISerializable, public ISortab
96 96
   void Reset();
97 97
   virtual void Archive(CArchive& ar);
98 98
   virtual void Serialize(CVariant& value) const;
99  
-  virtual void ToSortable(SortItem& sortable);
  99
+  virtual void ToSortable(SortItem& sortable, Field field) const;
100 100
   const CPictureInfoTag& operator=(const CPictureInfoTag& item);
101 101
   const CStdString GetInfo(int info) const;
102 102
 
9  xbmc/pvr/channels/PVRChannel.cpp
@@ -707,10 +707,13 @@ void CPVRChannel::SetCachedChannelNumber(unsigned int iChannelNumber)
707 707
   m_iCachedChannelNumber = iChannelNumber;
708 708
 }
709 709
 
710  
-void CPVRChannel::ToSortable(SortItem& sortable) const
  710
+void CPVRChannel::ToSortable(SortItem& sortable, Field field) const
711 711
 {
712  
-  CSingleLock lock(m_critSection);
713  
-  sortable[FieldChannelName] = m_strChannelName;
  712
+  if (field == FieldChannelName)
  713
+  {
  714
+    CSingleLock lock(m_critSection);
  715
+    sortable[FieldChannelName] = m_strChannelName;
  716
+  }
714 717
 }
715 718
 
716 719
 int CPVRChannel::ChannelID(void) const
4  xbmc/pvr/channels/PVRChannel.h
@@ -43,7 +43,7 @@ namespace PVR
43 43
   typedef boost::shared_ptr<PVR::CPVRChannel> CPVRChannelPtr;
44 44
 
45 45
   /** PVR Channel class */
46  
-  class CPVRChannel : public Observable, public ISerializable
  46
+  class CPVRChannel : public Observable, public ISerializable, public ISortable
47 47
   {
48 48
     friend class CPVRDatabase;
49 49
     friend class CPVRChannelGroupInternal;
@@ -320,7 +320,7 @@ namespace PVR
320 320
      */
321 321
     CStdString Path(void) const;
322 322
 
323  
-    void ToSortable(SortItem& sortable) const;
  323
+    virtual void ToSortable(SortItem& sortable, Field field) const;
324 324
 
325 325
     /*!
326 326
      * @brief Update the path after the channel number in the internal group changed.
2  xbmc/utils/ISortable.h
@@ -27,5 +27,5 @@ class ISortable
27 27
 {
28 28
 public:
29 29
   virtual ~ISortable() { }
30  
-  virtual void ToSortable(SortItem& sortable) = 0;
  30
+  virtual void ToSortable(SortItem& sortable, Field field) const = 0;
31 31
 };
76  xbmc/utils/SortUtils.cpp
@@ -522,6 +522,26 @@ bool SorterIgnoreFoldersDescending(const SortItem &left, const SortItem &right)
522 522
   return StringUtils::AlphaNumericCompare(labelLeft.c_str(), labelRight.c_str()) > 0;
523 523
 }
524 524
 
  525
+bool SorterIndirectAscending(const SortItemPtr &left, const SortItemPtr &right)
  526
+{
  527
+  return SorterAscending(*left, *right);
  528
+}
  529
+
  530
+bool SorterIndirectDescending(const SortItemPtr &left, const SortItemPtr &right)
  531
+{
  532
+  return SorterDescending(*left, *right);
  533
+}
  534
+
  535
+bool SorterIndirectIgnoreFoldersAscending(const SortItemPtr &left, const SortItemPtr &right)
  536
+{
  537
+  return SorterIgnoreFoldersAscending(*left, *right);
  538
+}
  539
+
  540
+bool SorterIndirectIgnoreFoldersDescending(const SortItemPtr &left, const SortItemPtr &right)
  541
+{
  542
+  return SorterIgnoreFoldersDescending(*left, *right);
  543
+}
  544
+
525 545
 map<SortBy, SortUtils::SortPreparator> fillPreparators()
526 546
 {
527 547
   map<SortBy, SortUtils::SortPreparator> preparators;
@@ -650,7 +670,7 @@ map<SortBy, Fields> fillSortingFields()
650 670
 map<SortBy, SortUtils::SortPreparator> SortUtils::m_preparators = fillPreparators();
651 671
 map<SortBy, Fields> SortUtils::m_sortingFields = fillSortingFields();
652 672
 
653  
-void SortUtils::Sort(SortBy sortBy, SortOrder sortOrder, SortAttribute attributes, SortItems& items, int limitEnd /* = -1 */, int limitStart /* = 0 */)
  673
+void SortUtils::Sort(SortBy sortBy, SortOrder sortOrder, SortAttribute attributes, DatabaseResults& items, int limitEnd /* = -1 */, int limitStart /* = 0 */)
654 674
 {
655 675
   if (sortBy != SortByNone)
656 676
   {
@@ -661,7 +681,7 @@ void SortUtils::Sort(SortBy sortBy, SortOrder sortOrder, SortAttribute attribute
661 681
       Fields sortingFields = GetFieldsForSorting(sortBy);
662 682
 
663 683
       // Prepare the string used for sorting and store it under FieldSort
664  
-      for (SortItems::iterator item = items.begin(); item != items.end(); item++)
  684
+      for (DatabaseResults::iterator item = items.begin(); item != items.end(); item++)
665 685
       {
666 686
         // add all fields to the item that are required for sorting if they are currently missing
667 687
         for (Fields::const_iterator field = sortingFields.begin(); field != sortingFields.end(); field++)
@@ -689,6 +709,50 @@ void SortUtils::Sort(SortBy sortBy, SortOrder sortOrder, SortAttribute attribute
689 709
     items.erase(items.begin() + limitEnd, items.end());
690 710
 }
691 711
 
  712
+void SortUtils::Sort(SortBy sortBy, SortOrder sortOrder, SortAttribute attributes, SortItems& items, int limitEnd /* = -1 */, int limitStart /* = 0 */)
  713
+{
  714
+  if (sortBy != SortByNone)
  715
+  {
  716
+    // get the matching SortPreparator
  717
+    SortPreparator preparator = getPreparator(sortBy);
  718
+    if (preparator != NULL)
  719
+    {
  720
+      Fields sortingFields = GetFieldsForSorting(sortBy);
  721
+
  722
+      // Prepare the string used for sorting and store it under FieldSort
  723
+      for (SortItems::iterator item = items.begin(); item != items.end(); item++)
  724
+      {
  725
+        // add all fields to the item that are required for sorting if they are currently missing
  726
+        for (Fields::const_iterator field = sortingFields.begin(); field != sortingFields.end(); field++)
  727
+        {
  728
+          if ((*item)->find(*field) == (*item)->end())
  729
+            (*item)->insert(pair<Field, CVariant>(*field, CVariant::ConstNullVariant));
  730
+        }
  731
+
  732
+        CStdStringW sortLabel;
  733
+        g_charsetConverter.utf8ToW(preparator(attributes, **item), sortLabel, false);
  734
+        (*item)->insert(pair<Field, CVariant>(FieldSort, CVariant(sortLabel)));
  735
+      }
  736
+
  737
+      // Do the sorting
  738
+      std::stable_sort(items.begin(), items.end(), getSorterIndirect(sortOrder, attributes));
  739
+    }
  740
+  }
  741
+
  742
+  if (limitStart > 0 && (size_t)limitStart < items.size())
  743
+  {
  744
+    items.erase(items.begin(), items.begin() + limitStart);
  745
+    limitEnd -= limitStart;
  746
+  }
  747
+  if (limitEnd > 0 && (size_t)limitEnd < items.size())
  748
+    items.erase(items.begin() + limitEnd, items.end());
  749
+}
  750
+
  751
+void SortUtils::Sort(const SortDescription &sortDescription, DatabaseResults& items)
  752
+{
  753
+  Sort(sortDescription.sortBy, sortDescription.sortOrder, sortDescription.sortAttributes, items, sortDescription.limitEnd, sortDescription.limitStart);
  754
+}
  755
+
692 756
 void SortUtils::Sort(const SortDescription &sortDescription, SortItems& items)
693 757
 {
694 758
   Sort(sortDescription.sortBy, sortDescription.sortOrder, sortDescription.sortAttributes, items, sortDescription.limitEnd, sortDescription.limitStart);
@@ -732,6 +796,14 @@ SortUtils::Sorter SortUtils::getSorter(SortOrder sortOrder, SortAttribute attrib
732 796
   return sortOrder == SortOrderDescending ? SorterDescending : SorterAscending;
733 797
 }
734 798
 
  799
+SortUtils::SorterIndirect SortUtils::getSorterIndirect(SortOrder sortOrder, SortAttribute attributes)
  800
+{
  801
+  if (attributes & SortAttributeIgnoreFolders)
  802
+    return sortOrder == SortOrderDescending ? SorterIndirectIgnoreFoldersDescending : SorterIndirectIgnoreFoldersAscending;
  803
+
  804
+  return sortOrder == SortOrderDescending ? SorterIndirectDescending : SorterIndirectAscending;
  805
+}
  806
+
735 807
 const Fields& SortUtils::GetFieldsForSorting(SortBy sortBy)
736 808
 {
737 809
   map<SortBy, Fields>::const_iterator it = m_sortingFields.find(sortBy);
10  xbmc/utils/SortUtils.h
@@ -21,6 +21,7 @@
21 21
 
22 22
 #include <map>
23 23
 #include <string>
  24
+#include "boost/shared_ptr.hpp"
24 25
 
25 26
 #include "DatabaseUtils.h"
26 27
 #include "SortFileItem.h"
@@ -114,7 +115,8 @@ typedef struct
114 115
 } SORT_METHOD_DETAILS;
115 116
 
116 117
 typedef DatabaseResult SortItem;
117  
-typedef DatabaseResults SortItems;
  118
+typedef boost::shared_ptr<SortItem> SortItemPtr;
  119
+typedef std::vector<SortItemPtr> SortItems;
118 120
 
119 121
 class SortUtils
120 122
 {
@@ -128,7 +130,9 @@ class SortUtils
128 130
    */
129 131
   static int GetSortLabel(SortBy sortBy);
130 132
 
  133
+  static void Sort(SortBy sortBy, SortOrder sortOrder, SortAttribute attributes, DatabaseResults& items, int limitEnd = -1, int limitStart = 0);
131 134
   static void Sort(SortBy sortBy, SortOrder sortOrder, SortAttribute attributes, SortItems& items, int limitEnd = -1, int limitStart = 0);
  135
+  static void Sort(const SortDescription &sortDescription, DatabaseResults& items);
132 136
   static void Sort(const SortDescription &sortDescription, SortItems& items);
133 137
   static bool SortFromDataset(const SortDescription &sortDescription, MediaType mediaType, const std::auto_ptr<dbiplus::Dataset> &dataset, DatabaseResults &results);
134 138
   
@@ -136,11 +140,13 @@ class SortUtils
136 140
   static std::string RemoveArticles(const std::string &label);
137 141
   
138 142
   typedef std::string (*SortPreparator) (SortAttribute, const SortItem&);
139  
-  typedef bool (*Sorter) (const SortItem&, const SortItem&);
  143
+  typedef bool (*Sorter) (const DatabaseResult &, const DatabaseResult &);
  144
+  typedef bool (*SorterIndirect) (const SortItemPtr &, const SortItemPtr &);
140 145
   
141 146
 private:
142 147
   static const SortPreparator& getPreparator(SortBy sortBy);
143 148
   static Sorter getSorter(SortOrder sortOrder, SortAttribute attributes);
  149
+  static SorterIndirect getSorterIndirect(SortOrder sortOrder, SortAttribute attributes);
144 150
 
145 151
   static std::map<SortBy, SortPreparator> m_preparators;
146 152
   static std::map<SortBy, Fields> m_sortingFields;
104  xbmc/video/VideoInfoTag.cpp
@@ -483,57 +483,61 @@ void CVideoInfoTag::Serialize(CVariant& value) const
483 483
   value["seasonid"] = m_iIdSeason;
484 484
 }
485 485
 
486  
-void CVideoInfoTag::ToSortable(SortItem& sortable)
  486
+void CVideoInfoTag::ToSortable(SortItem& sortable, Field field) const
487 487
 {
488  
-  sortable[FieldDirector] = m_director;
489  
-  sortable[FieldWriter] = m_writingCredits;
490  
-  sortable[FieldGenre] = m_genre;
491  
-  sortable[FieldCountry] = m_country;
492  
-  sortable[FieldTagline] = m_strTagLine;
493  
-  sortable[FieldPlotOutline] = m_strPlotOutline;
494  
-  sortable[FieldPlot] = m_strPlot;
495  
-  sortable[FieldTitle] = m_strTitle;
496  
-  sortable[FieldVotes] = m_strVotes;
497  
-  sortable[FieldStudio] = m_studio;
498  
-  sortable[FieldTrailer] = m_strTrailer;
499  
-  sortable[FieldSet] = m_strSet;
500  
-  sortable[FieldTime] = GetDuration();
501  
-  sortable[FieldFilename] = m_strFile;
502  
-  sortable[FieldMPAA] = m_strMPAARating;
503  
-  sortable[FieldPath] = m_strFileNameAndPath;
504  
-  sortable[FieldSortTitle] = m_strSortTitle;
505  
-  sortable[FieldTvShowStatus] = m_strStatus;
506  
-  sortable[FieldProductionCode] = m_strProductionCode;
507  
-  sortable[FieldAirDate] = m_firstAired.IsValid() ? m_firstAired.GetAsDBDate() : (m_premiered.IsValid() ? m_premiered.GetAsDBDate() : StringUtils::EmptyString);
508  
-  sortable[FieldTvShowTitle] = m_strShowTitle;
509  
-  sortable[FieldAlbum] = m_strAlbum;
510  
-  sortable[FieldArtist] = m_artist;
511  
-  sortable[FieldPlaycount] = m_playCount;
512  
-  sortable[FieldLastPlayed] = m_lastPlayed.IsValid() ? m_lastPlayed.GetAsDBDateTime() : StringUtils::EmptyString;
513  
-  sortable[FieldTop250] = m_iTop250;
514  
-  sortable[FieldYear] = m_iYear;
515  
-  sortable[FieldSeason] = m_iSeason;
516  
-  sortable[FieldEpisodeNumber] = m_iEpisode;
517  
-  sortable[FieldEpisodeNumberSpecialSort] = m_iSpecialSortEpisode;
518  
-  sortable[FieldSeasonSpecialSort] = m_iSpecialSortSeason;
519  
-  sortable[FieldRating] = m_fRating;
520  
-  sortable[FieldId] = m_iDbId;
521  
-  sortable[FieldTrackNumber] = m_iTrack;
522  
-  sortable[FieldTag] = m_tags;
523  
-
524  
-  sortable[FieldVideoResolution] = m_streamDetails.GetVideoHeight();
525  
-  sortable[FieldVideoAspectRatio] = m_streamDetails.GetVideoAspect();
526  
-  sortable[FieldVideoCodec] = m_streamDetails.GetVideoCodec();
527  
-  
528  
-  sortable[FieldAudioChannels] = m_streamDetails.GetAudioChannels();
529  
-  sortable[FieldAudioCodec] = m_streamDetails.GetAudioCodec();
530  
-  sortable[FieldAudioLanguage] = m_streamDetails.GetAudioLanguage();
531  
-  
532  
-  sortable[FieldSubtitleLanguage] = m_streamDetails.GetSubtitleLanguage();
533  
-
534  
-  sortable[FieldInProgress] = m_resumePoint.IsPartWay();
535  
-  sortable[FieldDateAdded] = m_dateAdded.IsValid() ? m_dateAdded.GetAsDBDateTime() : StringUtils::EmptyString;
536  
-  sortable[FieldMediaType] = DatabaseUtils::MediaTypeFromString(m_type);
  488
+  switch (field)
  489
+  {
  490
+  case FieldDirector:                 sortable[FieldDirector] = m_director; break;
  491
+  case FieldWriter:                   sortable[FieldWriter] = m_writingCredits; break;
  492
+  case FieldGenre:                    sortable[FieldGenre] = m_genre; break;
  493
+  case FieldCountry:                  sortable[FieldCountry] = m_country; break;
  494
+  case FieldTagline:                  sortable[FieldTagline] = m_strTagLine; break;
  495
+  case FieldPlotOutline:              sortable[FieldPlotOutline] = m_strPlotOutline; break;
  496
+  case FieldPlot:                     sortable[FieldPlot] = m_strPlot; break;
  497
+  case FieldTitle:                    sortable[FieldTitle] = m_strTitle; break;
  498
+  case FieldVotes:                    sortable[FieldVotes] = m_strVotes; break;
  499
+  case FieldStudio:                   sortable[FieldStudio] = m_studio; break;
  500
+  case FieldTrailer:                  sortable[FieldTrailer] = m_strTrailer; break;
  501
+  case FieldSet:                      sortable[FieldSet] = m_strSet; break;
  502
+  case FieldTime:                     sortable[FieldTime] = GetDuration(); break;
  503
+  case FieldFilename:                 sortable[FieldFilename] = m_strFile; break;
  504
+  case FieldMPAA:                     sortable[FieldMPAA] = m_strMPAARating; break;
  505
+  case FieldPath:                     sortable[FieldPath] = m_strFileNameAndPath; break;
  506
+  case FieldSortTitle:                sortable[FieldSortTitle] = m_strSortTitle; break;
  507
+  case FieldTvShowStatus:             sortable[FieldTvShowStatus] = m_strStatus; break;
  508
+  case FieldProductionCode:           sortable[FieldProductionCode] = m_strProductionCode; break;
  509
+  case FieldAirDate:                  sortable[FieldAirDate] = m_firstAired.IsValid() ? m_firstAired.GetAsDBDate() : (m_premiered.IsValid() ? m_premiered.GetAsDBDate() : StringUtils::EmptyString); break;
  510
+  case FieldTvShowTitle:              sortable[FieldTvShowTitle] = m_strShowTitle; break;
  511
+  case FieldAlbum:                    sortable[FieldAlbum] = m_strAlbum; break;
  512
+  case FieldArtist:                   sortable[FieldArtist] = m_artist; break;
  513
+  case FieldPlaycount:                sortable[FieldPlaycount] = m_playCount; break;
  514
+  case FieldLastPlayed:               sortable[FieldLastPlayed] = m_lastPlayed.IsValid() ? m_lastPlayed.GetAsDBDateTime() : StringUtils::EmptyString; break;
  515
+  case FieldTop250:                   sortable[FieldTop250] = m_iTop250; break;
  516
+  case FieldYear:                     sortable[FieldYear] = m_iYear; break;
  517
+  case FieldSeason:                   sortable[FieldSeason] = m_iSeason; break;
  518
+  case FieldEpisodeNumber:            sortable[FieldEpisodeNumber] = m_iEpisode; break;
  519
+  case FieldEpisodeNumberSpecialSort: sortable[FieldEpisodeNumberSpecialSort] = m_iSpecialSortEpisode; break;
  520
+  case FieldSeasonSpecialSort:        sortable[FieldSeasonSpecialSort] = m_iSpecialSortSeason; break;
  521
+  case FieldRating:                   sortable[FieldRating] = m_fRating; break;
  522
+  case FieldId:                       sortable[FieldId] = m_iDbId; break;
  523
+  case FieldTrackNumber:              sortable[FieldTrackNumber] = m_iTrack; break;
  524
+  case FieldTag:                      sortable[FieldTag] = m_tags; break;
  525
+
  526
+  case FieldVideoResolution:          sortable[FieldVideoResolution] = m_streamDetails.GetVideoHeight(); break;
  527
+  case FieldVideoAspectRatio:         sortable[FieldVideoAspectRatio] = m_streamDetails.GetVideoAspect(); break;
  528
+  case FieldVideoCodec:               sortable[FieldVideoCodec] = m_streamDetails.GetVideoCodec(); break;
  529
+
  530
+  case FieldAudioChannels:            sortable[FieldAudioChannels] = m_streamDetails.GetAudioChannels(); break;
  531
+  case FieldAudioCodec:               sortable[FieldAudioCodec] = m_streamDetails.GetAudioCodec(); break;
  532
+  case FieldAudioLanguage:            sortable[FieldAudioLanguage] = m_streamDetails.GetAudioLanguage(); break;
  533
+
  534
+  case FieldSubtitleLanguage:         sortable[FieldSubtitleLanguage] = m_streamDetails.GetSubtitleLanguage(); break;
  535
+
  536
+  case FieldInProgress:               sortable[FieldInProgress] = m_resumePoint.IsPartWay(); break;
  537
+  case FieldDateAdded:                sortable[FieldDateAdded] = m_dateAdded.IsValid() ? m_dateAdded.GetAsDBDateTime() : StringUtils::EmptyString; break;
  538
+  case FieldMediaType:                sortable[FieldMediaType] = DatabaseUtils::MediaTypeFromString(m_type); break;
  539
+  default: break;
  540
+  }
537 541
 }
538 542
 
539 543
 const CStdString CVideoInfoTag::GetCast(bool bIncludeRole /*= false*/) const
2  xbmc/video/VideoInfoTag.h
@@ -63,7 +63,7 @@ class CVideoInfoTag : public IArchivable, public ISerializable, public ISortable
63 63
   bool Save(TiXmlNode *node, const CStdString &tag, bool savePathInfo = true, const TiXmlElement *additionalNode = NULL);
64 64
   virtual void Archive(CArchive& ar);
65 65
   virtual void Serialize(CVariant& value) const;
66  
-  virtual void ToSortable(SortItem& sortable);
  66
+  virtual void ToSortable(SortItem& sortable, Field field) const;
67 67
   const CStdString GetCast(bool bIncludeRole = false) const;
68 68
   bool HasStreamDetails() const;
69 69
   bool IsEmpty() const;

0 notes on commit c0a666e

Please sign in to comment.
Something went wrong with that request. Please try again.