diff options
-rw-r--r-- | xbmc/music/Album.cpp | 54 | ||||
-rw-r--r-- | xbmc/music/Album.h | 15 |
2 files changed, 68 insertions, 1 deletions
diff --git a/xbmc/music/Album.cpp b/xbmc/music/Album.cpp index 447f6e05f5..b91363707a 100644 --- a/xbmc/music/Album.cpp +++ b/xbmc/music/Album.cpp @@ -30,6 +30,18 @@ using namespace std; using namespace MUSIC_INFO; +typedef struct ReleaseTypeInfo { + CAlbum::ReleaseType type; + std::string name; +} ReleaseTypeInfo; + +ReleaseTypeInfo releaseTypes[] = { + { CAlbum::Album, "album" }, + { CAlbum::Single, "single" } +}; + +#define RELEASE_TYPES_SIZE sizeof(releaseTypes) / sizeof(ReleaseTypeInfo) + CAlbum::CAlbum(const CFileItem& item) { Reset(); @@ -147,6 +159,40 @@ std::string CAlbum::GetGenreString() const return StringUtils::Join(genre, g_advancedSettings.m_musicItemSeparator); } +std::string CAlbum::GetReleaseType() const +{ + return ReleaseTypeToString(releaseType); +} + +void CAlbum::SetReleaseType(const std::string& strReleaseType) +{ + releaseType = ReleaseTypeFromString(strReleaseType); +} + +std::string CAlbum::ReleaseTypeToString(CAlbum::ReleaseType releaseType) +{ + for (size_t i = 0; i < RELEASE_TYPES_SIZE; i++) + { + const ReleaseTypeInfo& releaseTypeInfo = releaseTypes[i]; + if (releaseTypeInfo.type == releaseType) + return releaseTypeInfo.name; + } + + return "album"; +} + +CAlbum::ReleaseType CAlbum::ReleaseTypeFromString(const std::string& strReleaseType) +{ + for (size_t i = 0; i < RELEASE_TYPES_SIZE; i++) + { + const ReleaseTypeInfo& releaseTypeInfo = releaseTypes[i]; + if (releaseTypeInfo.name == strReleaseType) + return releaseTypeInfo.type; + } + + return Album; +} + bool CAlbum::operator<(const CAlbum &a) const { if (strMusicBrainzAlbumID.empty() && a.strMusicBrainzAlbumID.empty()) @@ -304,6 +350,12 @@ bool CAlbum::Load(const TiXmlElement *album, bool append, bool prioritise) node = node->NextSiblingElement("track"); } + std::string strReleaseType; + if (XMLUtils::GetString(album, "releasetype", strReleaseType)) + SetReleaseType(strReleaseType); + else + releaseType = Album; + return true; } @@ -379,6 +431,8 @@ bool CAlbum::Save(TiXmlNode *node, const std::string &tag, const std::string& st XMLUtils::SetString(node, "duration", StringUtils::SecondsToTimeString(song->iDuration)); } + XMLUtils::SetString(album, "releasetype", GetReleaseType()); + return true; } diff --git a/xbmc/music/Album.h b/xbmc/music/Album.h index 4b85b13ce2..db7d299368 100644 --- a/xbmc/music/Album.h +++ b/xbmc/music/Album.h @@ -36,7 +36,7 @@ class CAlbum { public: CAlbum(const CFileItem& item); - CAlbum() { idAlbum = 0; iRating = 0; iYear = 0; iTimesPlayed = 0; }; + CAlbum() { idAlbum = 0; iRating = 0; iYear = 0; iTimesPlayed = 0; releaseType = Album; }; bool operator<(const CAlbum &a) const; void MergeScrapedAlbum(const CAlbum& album, bool override = true); @@ -64,11 +64,23 @@ public: iTimesPlayed = 0; songs.clear(); infoSongs.clear(); + releaseType = Album; } std::string GetArtistString() const; std::string GetGenreString() const; + typedef enum ReleaseType { + Album = 0, + Single + } ReleaseType; + + std::string GetReleaseType() const; + void SetReleaseType(const std::string& strReleaseType); + + static std::string ReleaseTypeToString(ReleaseType releaseType); + static ReleaseType ReleaseTypeFromString(const std::string& strReleaseType); + /*! \brief Load album information from an XML file. See CVideoInfoTag::Load for a description of the types of elements we load. \param element the root XML element to parse. @@ -101,6 +113,7 @@ public: int iTimesPlayed; VECSONGS songs; ///< Local songs VECSONGS infoSongs; ///< Scraped songs + ReleaseType releaseType; }; typedef std::vector<CAlbum> VECALBUMS; |