string ByTvShowTitle(SortAttribute attributes, const SortItem &values) { return values.at(FieldTvShowTitle).asString() + " " + ByLabel(attributes, values); }
std::string ByUserRating(SortAttribute attributes, const SortItem &values) { return StringUtils::Format("%d %s", static_cast<int>(values.at(FieldUserRating).asInteger()), ByLabel(attributes, values).c_str()); }
std::string ByMPAA(SortAttribute attributes, const SortItem &values) { return values.at(FieldMPAA).asString() + " " + ByLabel(attributes, values); }
std::string ByProgramCount(SortAttribute attributes, const SortItem &values) { return StringUtils::Format("%i", (int)values.at(FieldProgramCount).asInteger()); }
std::string ByCountry(SortAttribute attributes, const SortItem &values) { return ArrayToString(attributes, values.at(FieldCountry)); }
string BySize(SortAttribute attributes, const SortItem &values) { return StringUtils::Format("%" PRId64, values.at(FieldSize).asInteger()); }
std::string ByAlbumType(SortAttribute attributes, const SortItem &values) { return values.at(FieldAlbumType).asString() + " " + ByLabel(attributes, values); }
string BySubtitleLanguage(SortAttribute attributes, const SortItem &values) { return StringUtils::Format("%s %s", values.at(FieldSubtitleLanguage).asString().c_str(), ByLabel(attributes, values).c_str()); }
string ByListeners(SortAttribute attributes, const SortItem &values) { return StringUtils::Format("%" PRId64, values.at(FieldListeners).asInteger()); }
string ByAudioChannels(SortAttribute attributes, const SortItem &values) { return StringUtils::Format("%i %s", (int)values.at(FieldAudioChannels).asInteger(), ByLabel(attributes, values).c_str()); }
string ByAudioCodec(SortAttribute attributes, const SortItem &values) { return StringUtils::Format("%s %s", values.at(FieldAudioCodec).asString().c_str(), ByLabel(attributes, values).c_str()); }
string ByVideoAspectRatio(SortAttribute attributes, const SortItem &values) { return StringUtils::Format("%.03f %s", values.at(FieldVideoAspectRatio).asFloat(), ByLabel(attributes, values).c_str()); }
string ByVideoResolution(SortAttribute attributes, const SortItem &values) { return StringUtils::Format("%i %s", (int)values.at(FieldVideoResolution).asInteger(), ByLabel(attributes, values).c_str()); }
string ByProductionCode(SortAttribute attributes, const SortItem &values) { return values.at(FieldProductionCode).asString(); }
string ByDate(SortAttribute attributes, const SortItem &values) { return values.at(FieldDate).asString() + " " + ByLabel(attributes, values); }
string ByChannel(SortAttribute attributes, const SortItem &values) { return values.at(FieldChannelName).asString(); }
string ByDateAdded(SortAttribute attributes, const SortItem &values) { return StringUtils::Format("%s %d", values.at(FieldDateAdded).asString().c_str(), (int)values.at(FieldId).asInteger()); }
string ByDateTaken(SortAttribute attributes, const SortItem &values) { return values.at(FieldDateTaken).asString(); }
void CVideoInfoTag::ToSortable(SortItem& sortable, Field field) const { switch (field) { case FieldDirector: sortable[FieldDirector] = m_director; break; case FieldWriter: sortable[FieldWriter] = m_writingCredits; break; case FieldGenre: sortable[FieldGenre] = m_genre; break; case FieldCountry: sortable[FieldCountry] = m_country; break; case FieldTagline: sortable[FieldTagline] = m_strTagLine; break; case FieldPlotOutline: sortable[FieldPlotOutline] = m_strPlotOutline; break; case FieldPlot: sortable[FieldPlot] = m_strPlot; break; case FieldTitle: { // make sure not to overwrite an existing title with an empty one std::string title = m_strTitle; if (!title.empty() || sortable.find(FieldTitle) == sortable.end()) sortable[FieldTitle] = title; break; } case FieldVotes: sortable[FieldVotes] = GetRating().votes; break; case FieldStudio: sortable[FieldStudio] = m_studio; break; case FieldTrailer: sortable[FieldTrailer] = m_strTrailer; break; case FieldSet: sortable[FieldSet] = m_strSet; break; case FieldTime: sortable[FieldTime] = GetDuration(); break; case FieldFilename: sortable[FieldFilename] = m_strFile; break; case FieldMPAA: sortable[FieldMPAA] = m_strMPAARating; break; case FieldPath: { // make sure not to overwrite an existing path with an empty one std::string path = GetPath(); if (!path.empty() || sortable.find(FieldPath) == sortable.end()) sortable[FieldPath] = path; break; } case FieldSortTitle: { // seasons with a custom name/title need special handling as they should be sorted by season number if (m_type == MediaTypeSeason && !m_strSortTitle.empty()) sortable[FieldSortTitle] = StringUtils::Format(g_localizeStrings.Get(20358).c_str(), m_iSeason); else sortable[FieldSortTitle] = m_strSortTitle; break; } case FieldTvShowStatus: sortable[FieldTvShowStatus] = m_strStatus; break; case FieldProductionCode: sortable[FieldProductionCode] = m_strProductionCode; break; case FieldAirDate: sortable[FieldAirDate] = m_firstAired.IsValid() ? m_firstAired.GetAsDBDate() : (m_premiered.IsValid() ? m_premiered.GetAsDBDate() : StringUtils::Empty); break; case FieldTvShowTitle: sortable[FieldTvShowTitle] = m_strShowTitle; break; case FieldAlbum: sortable[FieldAlbum] = m_strAlbum; break; case FieldArtist: sortable[FieldArtist] = m_artist; break; case FieldPlaycount: sortable[FieldPlaycount] = GetPlayCount(); break; case FieldLastPlayed: sortable[FieldLastPlayed] = m_lastPlayed.IsValid() ? m_lastPlayed.GetAsDBDateTime() : StringUtils::Empty; break; case FieldTop250: sortable[FieldTop250] = m_iTop250; break; case FieldYear: sortable[FieldYear] = m_premiered.GetYear(); break; case FieldSeason: sortable[FieldSeason] = m_iSeason; break; case FieldEpisodeNumber: sortable[FieldEpisodeNumber] = m_iEpisode; break; case FieldNumberOfEpisodes: sortable[FieldNumberOfEpisodes] = m_iEpisode; break; case FieldNumberOfWatchedEpisodes: sortable[FieldNumberOfWatchedEpisodes] = m_iEpisode; break; case FieldEpisodeNumberSpecialSort: sortable[FieldEpisodeNumberSpecialSort] = m_iSpecialSortEpisode; break; case FieldSeasonSpecialSort: sortable[FieldSeasonSpecialSort] = m_iSpecialSortSeason; break; case FieldRating: sortable[FieldRating] = GetRating().rating; break; case FieldUserRating: sortable[FieldUserRating] = m_iUserRating; break; case FieldId: sortable[FieldId] = m_iDbId; break; case FieldTrackNumber: sortable[FieldTrackNumber] = m_iTrack; break; case FieldTag: sortable[FieldTag] = m_tags; break; case FieldVideoResolution: sortable[FieldVideoResolution] = m_streamDetails.GetVideoHeight(); break; case FieldVideoAspectRatio: sortable[FieldVideoAspectRatio] = m_streamDetails.GetVideoAspect(); break; case FieldVideoCodec: sortable[FieldVideoCodec] = m_streamDetails.GetVideoCodec(); break; case FieldStereoMode: sortable[FieldStereoMode] = m_streamDetails.GetStereoMode(); break; case FieldAudioChannels: sortable[FieldAudioChannels] = m_streamDetails.GetAudioChannels(); break; case FieldAudioCodec: sortable[FieldAudioCodec] = m_streamDetails.GetAudioCodec(); break; case FieldAudioLanguage: sortable[FieldAudioLanguage] = m_streamDetails.GetAudioLanguage(); break; case FieldSubtitleLanguage: sortable[FieldSubtitleLanguage] = m_streamDetails.GetSubtitleLanguage(); break; case FieldInProgress: sortable[FieldInProgress] = m_resumePoint.IsPartWay(); break; case FieldDateAdded: sortable[FieldDateAdded] = m_dateAdded.IsValid() ? m_dateAdded.GetAsDBDateTime() : StringUtils::Empty; break; case FieldMediaType: sortable[FieldMediaType] = m_type; break; case FieldRelevance: sortable[FieldRelevance] = m_relevance; break; default: break; } }
bool preliminarySort(const SortItem &left, const SortItem &right, bool handleFolder, bool &result, std::wstring &labelLeft, std::wstring &labelRight) { // make sure both items have the necessary data to do the sorting SortItem::const_iterator itLeftSort, itRightSort; if ((itLeftSort = left.find(FieldSort)) == left.end()) { result = false; return true; } if ((itRightSort = right.find(FieldSort)) == right.end()) { result = true; return true; } // look at special sorting behaviour SortItem::const_iterator itLeft, itRight; SortSpecial leftSortSpecial = SortSpecialNone; SortSpecial rightSortSpecial = SortSpecialNone; if ((itLeft = left.find(FieldSortSpecial)) != left.end() && itLeft->second.asInteger() <= (int64_t)SortSpecialOnBottom) leftSortSpecial = (SortSpecial)itLeft->second.asInteger(); if ((itRight = right.find(FieldSortSpecial)) != right.end() && itRight->second.asInteger() <= (int64_t)SortSpecialOnBottom) rightSortSpecial = (SortSpecial)itRight->second.asInteger(); // one has a special sort if (leftSortSpecial != rightSortSpecial) { // left should be sorted on top // or right should be sorted on bottom // => left is sorted above right if (leftSortSpecial == SortSpecialOnTop || rightSortSpecial == SortSpecialOnBottom) { result = true; return true; } // otherwise right is sorted above left result = false; return true; } // both have either sort on top or sort on bottom -> leave as-is else if (leftSortSpecial != SortSpecialNone && leftSortSpecial == rightSortSpecial) { result = false; return true; } if (handleFolder) { itLeft = left.find(FieldFolder); itRight = right.find(FieldFolder); if (itLeft != left.end() && itRight != right.end() && itLeft->second.asBoolean() != itRight->second.asBoolean()) { result = itLeft->second.asBoolean(); return true; } } labelLeft = itLeftSort->second.asWideString(); labelRight = itRightSort->second.asWideString(); return false; }
std::string ByTrackNumber(SortAttribute attributes, const SortItem &values) { return StringUtils::Format("%i", (int)values.at(FieldTrackNumber).asInteger()); }
string ByFile(SortAttribute attributes, const SortItem &values) { CURL url(values.at(FieldPath).asString()); return StringUtils::Format("%s %" PRId64, url.GetFileNameWithoutPath().c_str(), values.at(FieldStartOffset).asInteger()); }
std::string ByGenre(SortAttribute attributes, const SortItem &values) { return ArrayToString(attributes, values.at(FieldGenre)); }
string ByPath(SortAttribute attributes, const SortItem &values) { return StringUtils::Format("%s %" PRId64, values.at(FieldPath).asString().c_str(), values.at(FieldStartOffset).asInteger()); }
std::string ByRating(SortAttribute attributes, const SortItem &values) { return StringUtils::Format("%f %s", values.at(FieldRating).asFloat(), ByLabel(attributes, values).c_str()); }
string ByLastPlayed(SortAttribute attributes, const SortItem &values) { return StringUtils::Format("%s %s", values.at(FieldLastPlayed).asString().c_str(), ByLabel(attributes, values).c_str()); }
std::string ByTop250(SortAttribute attributes, const SortItem &values) { return StringUtils::Format("%d %s", (int)values.at(FieldTop250).asInteger(), ByLabel(attributes, values).c_str()); }
string ByPlaycount(SortAttribute attributes, const SortItem &values) { return StringUtils::Format("%i %s", (int)values.at(FieldPlaycount).asInteger(), ByLabel(attributes, values).c_str()); }
std::string ByStudio(SortAttribute attributes, const SortItem &values) { return ArrayToString(attributes, values.at(FieldStudio)); }
string ByNumberOfWatchedEpisodes(SortAttribute attributes, const SortItem &values) { return StringUtils::Format("%i %s", (int)values.at(FieldNumberOfWatchedEpisodes).asInteger(), ByLabel(attributes, values).c_str()); }