diff options
Diffstat (limited to 'xbmc/filesystem/MusicDatabaseDirectory')
37 files changed, 1753 insertions, 0 deletions
diff --git a/xbmc/filesystem/MusicDatabaseDirectory/CMakeLists.txt b/xbmc/filesystem/MusicDatabaseDirectory/CMakeLists.txt new file mode 100644 index 0000000..6eafcba --- /dev/null +++ b/xbmc/filesystem/MusicDatabaseDirectory/CMakeLists.txt @@ -0,0 +1,39 @@ +set(SOURCES DirectoryNodeAlbum.cpp + DirectoryNodeAlbumRecentlyAdded.cpp + DirectoryNodeAlbumRecentlyAddedSong.cpp + DirectoryNodeAlbumRecentlyPlayed.cpp + DirectoryNodeAlbumRecentlyPlayedSong.cpp + DirectoryNodeAlbumTop100.cpp + DirectoryNodeAlbumTop100Song.cpp + DirectoryNodeArtist.cpp + DirectoryNodeDiscs.cpp + DirectoryNode.cpp + DirectoryNodeGrouped.cpp + DirectoryNodeOverview.cpp + DirectoryNodeRoot.cpp + DirectoryNodeSingles.cpp + DirectoryNodeSong.cpp + DirectoryNodeSongTop100.cpp + DirectoryNodeTop100.cpp + QueryParams.cpp) + +set(HEADERS DirectoryNode.h + DirectoryNodeAlbum.h + DirectoryNodeAlbumRecentlyAdded.h + DirectoryNodeAlbumRecentlyAddedSong.h + DirectoryNodeAlbumRecentlyPlayed.h + DirectoryNodeAlbumRecentlyPlayedSong.h + DirectoryNodeAlbumTop100.h + DirectoryNodeAlbumTop100Song.h + DirectoryNodeArtist.h + DirectoryNodeDiscs.h + DirectoryNodeGrouped.h + DirectoryNodeOverview.h + DirectoryNodeRoot.h + DirectoryNodeSingles.h + DirectoryNodeSong.h + DirectoryNodeSongTop100.h + DirectoryNodeTop100.h + QueryParams.h) + +core_add_library(musicdatabasedirectory) diff --git a/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNode.cpp b/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNode.cpp new file mode 100644 index 0000000..00e1bce --- /dev/null +++ b/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNode.cpp @@ -0,0 +1,284 @@ +/* + * Copyright (C) 2005-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#include "DirectoryNode.h" + +#include "DirectoryNodeAlbum.h" +#include "DirectoryNodeAlbumRecentlyAdded.h" +#include "DirectoryNodeAlbumRecentlyAddedSong.h" +#include "DirectoryNodeAlbumRecentlyPlayed.h" +#include "DirectoryNodeAlbumRecentlyPlayedSong.h" +#include "DirectoryNodeAlbumTop100.h" +#include "DirectoryNodeAlbumTop100Song.h" +#include "DirectoryNodeArtist.h" +#include "DirectoryNodeDiscs.h" +#include "DirectoryNodeGrouped.h" +#include "DirectoryNodeOverview.h" +#include "DirectoryNodeRoot.h" +#include "DirectoryNodeSingles.h" +#include "DirectoryNodeSong.h" +#include "DirectoryNodeSongTop100.h" +#include "DirectoryNodeTop100.h" +#include "FileItem.h" +#include "QueryParams.h" +#include "URL.h" +#include "utils/StringUtils.h" +#include "utils/URIUtils.h" + +using namespace XFILE::MUSICDATABASEDIRECTORY; + +// Constructor is protected use ParseURL() +CDirectoryNode::CDirectoryNode(NODE_TYPE Type, const std::string& strName, CDirectoryNode* pParent) +{ + m_Type=Type; + m_strName=strName; + m_pParent=pParent; +} + +CDirectoryNode::~CDirectoryNode() +{ + delete m_pParent; +} + +// Parses a given path and returns the current node of the path +CDirectoryNode* CDirectoryNode::ParseURL(const std::string& strPath) +{ + CURL url(strPath); + + std::string strDirectory=url.GetFileName(); + URIUtils::RemoveSlashAtEnd(strDirectory); + + std::vector<std::string> Path = StringUtils::Split(strDirectory, '/'); + Path.insert(Path.begin(), ""); + + CDirectoryNode* pNode = nullptr; + CDirectoryNode* pParent = nullptr; + NODE_TYPE NodeType = NODE_TYPE_ROOT; + + for (int i=0; i < static_cast<int>(Path.size()); ++i) + { + pNode = CreateNode(NodeType, Path[i], pParent); + NodeType = pNode ? pNode->GetChildType() : NODE_TYPE_NONE; + pParent = pNode; + } + + // Add all the additional URL options to the last node + if (pNode) + pNode->AddOptions(url.GetOptions()); + + return pNode; +} + +// returns the database ids of the path, +void CDirectoryNode::GetDatabaseInfo(const std::string& strPath, CQueryParams& params) +{ + std::unique_ptr<CDirectoryNode> pNode(CDirectoryNode::ParseURL(strPath)); + + if (!pNode) + return; + + pNode->CollectQueryParams(params); +} + +bool CDirectoryNode::GetNodeInfo(const std::string& strPath, + NODE_TYPE& type, + NODE_TYPE& childtype, + CQueryParams& params) +{ + std::unique_ptr<CDirectoryNode> pNode(CDirectoryNode::ParseURL(strPath)); + if (!pNode) + return false; + + type = pNode->GetType(); + childtype = pNode->GetChildType(); + pNode->CollectQueryParams(params); + + return true; +} + +// Create a node object +CDirectoryNode* CDirectoryNode::CreateNode(NODE_TYPE Type, const std::string& strName, CDirectoryNode* pParent) +{ + switch (Type) + { + case NODE_TYPE_ROOT: + return new CDirectoryNodeRoot(strName, pParent); + case NODE_TYPE_OVERVIEW: + return new CDirectoryNodeOverview(strName, pParent); + case NODE_TYPE_GENRE: + case NODE_TYPE_SOURCE: + case NODE_TYPE_ROLE: + case NODE_TYPE_YEAR: + return new CDirectoryNodeGrouped(Type, strName, pParent); + case NODE_TYPE_DISC: + return new CDirectoryNodeDiscs(strName, pParent); + case NODE_TYPE_ARTIST: + return new CDirectoryNodeArtist(strName, pParent); + case NODE_TYPE_ALBUM: + return new CDirectoryNodeAlbum(strName, pParent); + case NODE_TYPE_SONG: + return new CDirectoryNodeSong(strName, pParent); + case NODE_TYPE_SINGLES: + return new CDirectoryNodeSingles(strName, pParent); + case NODE_TYPE_TOP100: + return new CDirectoryNodeTop100(strName, pParent); + case NODE_TYPE_ALBUM_TOP100: + return new CDirectoryNodeAlbumTop100(strName, pParent); + case NODE_TYPE_ALBUM_TOP100_SONGS: + return new CDirectoryNodeAlbumTop100Song(strName, pParent); + case NODE_TYPE_SONG_TOP100: + return new CDirectoryNodeSongTop100(strName, pParent); + case NODE_TYPE_ALBUM_RECENTLY_ADDED: + return new CDirectoryNodeAlbumRecentlyAdded(strName, pParent); + case NODE_TYPE_ALBUM_RECENTLY_ADDED_SONGS: + return new CDirectoryNodeAlbumRecentlyAddedSong(strName, pParent); + case NODE_TYPE_ALBUM_RECENTLY_PLAYED: + return new CDirectoryNodeAlbumRecentlyPlayed(strName, pParent); + case NODE_TYPE_ALBUM_RECENTLY_PLAYED_SONGS: + return new CDirectoryNodeAlbumRecentlyPlayedSong(strName, pParent); + default: + break; + } + + return nullptr; +} + +// Current node name +const std::string& CDirectoryNode::GetName() const +{ + return m_strName; +} + +int CDirectoryNode::GetID() const +{ + return atoi(m_strName.c_str()); +} + +std::string CDirectoryNode::GetLocalizedName() const +{ + return ""; +} + +// Current node type +NODE_TYPE CDirectoryNode::GetType() const +{ + return m_Type; +} + +// Return the parent directory node or NULL, if there is no +CDirectoryNode* CDirectoryNode::GetParent() const +{ + return m_pParent; +} + +void CDirectoryNode::RemoveParent() +{ + m_pParent = nullptr; +} + +// should be overloaded by a derived class +// to get the content of a node. Will be called +// by GetChilds() of a parent node +bool CDirectoryNode::GetContent(CFileItemList& items) const +{ + return false; +} + +// Creates a musicdb url +std::string CDirectoryNode::BuildPath() const +{ + std::vector<std::string> array; + + if (!m_strName.empty()) + array.insert(array.begin(), m_strName); + + CDirectoryNode* pParent=m_pParent; + while (pParent != nullptr) + { + const std::string& strNodeName=pParent->GetName(); + if (!strNodeName.empty()) + array.insert(array.begin(), strNodeName); + + pParent=pParent->GetParent(); + } + + std::string strPath="musicdb://"; + for (int i = 0; i < static_cast<int>(array.size()); ++i) + strPath+=array[i]+"/"; + + std::string options = m_options.GetOptionsString(); + if (!options.empty()) + strPath += "?" + options; + + return strPath; +} + +void CDirectoryNode::AddOptions(const std::string &options) +{ + if (options.empty()) + return; + + m_options.AddOptions(options); +} + +// Collects Query params from this and all parent nodes. If a NODE_TYPE can +// be used as a database parameter, it will be added to the +// params object. +void CDirectoryNode::CollectQueryParams(CQueryParams& params) const +{ + params.SetQueryParam(m_Type, m_strName); + + CDirectoryNode* pParent=m_pParent; + while (pParent != nullptr) + { + params.SetQueryParam(pParent->GetType(), pParent->GetName()); + pParent=pParent->GetParent(); + } +} + +// Should be overloaded by a derived class. +// Returns the NODE_TYPE of the child nodes. +NODE_TYPE CDirectoryNode::GetChildType() const +{ + return NODE_TYPE_NONE; +} + +// Get the child fileitems of this node +bool CDirectoryNode::GetChilds(CFileItemList& items) +{ + if (CanCache() && items.Load()) + return true; + + std::unique_ptr<CDirectoryNode> pNode(CDirectoryNode::CreateNode(GetChildType(), "", this)); + + bool bSuccess=false; + if (pNode) + { + pNode->m_options = m_options; + bSuccess=pNode->GetContent(items); + if (bSuccess) + { + if (CanCache()) + items.SetCacheToDisc(CFileItemList::CACHE_ALWAYS); + } + else + items.Clear(); + + pNode->RemoveParent(); + } + + return bSuccess; +} + + +bool CDirectoryNode::CanCache() const +{ + // JM: No need to cache these views, as caching is added in the mediawindow baseclass for anything that takes + // longer than a second + return false; +} diff --git a/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNode.h b/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNode.h new file mode 100644 index 0000000..63d11d1 --- /dev/null +++ b/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNode.h @@ -0,0 +1,92 @@ +/* + * Copyright (C) 2005-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#pragma once + +#include "utils/UrlOptions.h" + +class CFileItemList; + +namespace XFILE +{ + namespace MUSICDATABASEDIRECTORY + { + class CQueryParams; + + typedef enum _NODE_TYPE + { + NODE_TYPE_NONE=0, + NODE_TYPE_ROOT, + NODE_TYPE_OVERVIEW, + NODE_TYPE_TOP100, + NODE_TYPE_ROLE, + NODE_TYPE_SOURCE, + NODE_TYPE_GENRE, + NODE_TYPE_ARTIST, + NODE_TYPE_ALBUM, + NODE_TYPE_ALBUM_RECENTLY_ADDED, + NODE_TYPE_ALBUM_RECENTLY_ADDED_SONGS, + NODE_TYPE_ALBUM_RECENTLY_PLAYED, + NODE_TYPE_ALBUM_RECENTLY_PLAYED_SONGS, + NODE_TYPE_ALBUM_TOP100, + NODE_TYPE_ALBUM_TOP100_SONGS, + NODE_TYPE_SONG, + NODE_TYPE_SONG_TOP100, + NODE_TYPE_YEAR, + NODE_TYPE_SINGLES, + NODE_TYPE_DISC, + } NODE_TYPE; + + typedef struct { + NODE_TYPE node; + std::string id; + int label; + } Node; + + class CDirectoryNode + { + public: + static CDirectoryNode* ParseURL(const std::string& strPath); + static void GetDatabaseInfo(const std::string& strPath, CQueryParams& params); + static bool GetNodeInfo(const std::string& strPath, NODE_TYPE& type, NODE_TYPE& childtype, CQueryParams& params); + virtual ~CDirectoryNode(); + + NODE_TYPE GetType() const; + + bool GetChilds(CFileItemList& items); + virtual NODE_TYPE GetChildType() const; + virtual std::string GetLocalizedName() const; + + CDirectoryNode* GetParent() const; + virtual bool CanCache() const; + + std::string BuildPath() const; + + protected: + CDirectoryNode(NODE_TYPE Type, const std::string& strName, CDirectoryNode* pParent); + static CDirectoryNode* CreateNode(NODE_TYPE Type, const std::string& strName, CDirectoryNode* pParent); + + void AddOptions(const std::string &options); + void CollectQueryParams(CQueryParams& params) const; + + const std::string& GetName() const; + int GetID() const; + void RemoveParent(); + + virtual bool GetContent(CFileItemList& items) const; + + private: + NODE_TYPE m_Type; + std::string m_strName; + CDirectoryNode* m_pParent; + CUrlOptions m_options; + }; + } +} + + diff --git a/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeAlbum.cpp b/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeAlbum.cpp new file mode 100644 index 0000000..f60a025 --- /dev/null +++ b/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeAlbum.cpp @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2005-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#include "DirectoryNodeAlbum.h" + +#include "QueryParams.h" +#include "guilib/LocalizeStrings.h" +#include "music/MusicDatabase.h" + +using namespace XFILE::MUSICDATABASEDIRECTORY; + +CDirectoryNodeAlbum::CDirectoryNodeAlbum(const std::string& strName, CDirectoryNode* pParent) + : CDirectoryNode(NODE_TYPE_ALBUM, strName, pParent) +{ + +} + +NODE_TYPE CDirectoryNodeAlbum::GetChildType() const +{ + return NODE_TYPE_DISC; +} + +std::string CDirectoryNodeAlbum::GetLocalizedName() const +{ + if (GetID() == -1) + return g_localizeStrings.Get(15102); // All Albums + CMusicDatabase db; + if (db.Open()) + return db.GetAlbumById(GetID()); + return ""; +} + +bool CDirectoryNodeAlbum::GetContent(CFileItemList& items) const +{ + CMusicDatabase musicdatabase; + if (!musicdatabase.Open()) + return false; + + CQueryParams params; + CollectQueryParams(params); + + bool bSuccess=musicdatabase.GetAlbumsNav(BuildPath(), items, params.GetGenreId(), params.GetArtistId()); + + musicdatabase.Close(); + + return bSuccess; +} diff --git a/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeAlbum.h b/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeAlbum.h new file mode 100644 index 0000000..60fb233 --- /dev/null +++ b/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeAlbum.h @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2005-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#pragma once + +#include "DirectoryNode.h" + +namespace XFILE +{ + namespace MUSICDATABASEDIRECTORY + { + class CDirectoryNodeAlbum : public CDirectoryNode + { + public: + CDirectoryNodeAlbum(const std::string& strName, CDirectoryNode* pParent); + protected: + NODE_TYPE GetChildType() const override; + bool GetContent(CFileItemList& items) const override; + std::string GetLocalizedName() const override; + }; + } +} + + diff --git a/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeAlbumRecentlyAdded.cpp b/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeAlbumRecentlyAdded.cpp new file mode 100644 index 0000000..f274b59 --- /dev/null +++ b/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeAlbumRecentlyAdded.cpp @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2005-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#include "DirectoryNodeAlbumRecentlyAdded.h" + +#include "FileItem.h" +#include "guilib/LocalizeStrings.h" +#include "music/MusicDatabase.h" +#include "utils/StringUtils.h" + +using namespace XFILE::MUSICDATABASEDIRECTORY; + +CDirectoryNodeAlbumRecentlyAdded::CDirectoryNodeAlbumRecentlyAdded(const std::string& strName, CDirectoryNode* pParent) + : CDirectoryNode(NODE_TYPE_ALBUM_RECENTLY_ADDED, strName, pParent) +{ + +} + +NODE_TYPE CDirectoryNodeAlbumRecentlyAdded::GetChildType() const +{ + if (GetName()=="-1") + return NODE_TYPE_ALBUM_RECENTLY_ADDED_SONGS; + + return NODE_TYPE_DISC; +} + +std::string CDirectoryNodeAlbumRecentlyAdded::GetLocalizedName() const +{ + if (GetID() == -1) + return g_localizeStrings.Get(15102); // All Albums + CMusicDatabase db; + if (db.Open()) + return db.GetAlbumById(GetID()); + return ""; +} + +bool CDirectoryNodeAlbumRecentlyAdded::GetContent(CFileItemList& items) const +{ + CMusicDatabase musicdatabase; + if (!musicdatabase.Open()) + return false; + + VECALBUMS albums; + if (!musicdatabase.GetRecentlyAddedAlbums(albums)) + { + musicdatabase.Close(); + return false; + } + + for (int i=0; i<(int)albums.size(); ++i) + { + CAlbum& album=albums[i]; + std::string strDir = StringUtils::Format("{}{}/", BuildPath(), album.idAlbum); + CFileItemPtr pItem(new CFileItem(strDir, album)); + items.Add(pItem); + } + + musicdatabase.Close(); + return true; +} diff --git a/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeAlbumRecentlyAdded.h b/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeAlbumRecentlyAdded.h new file mode 100644 index 0000000..a1b4dc1 --- /dev/null +++ b/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeAlbumRecentlyAdded.h @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2005-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#pragma once + +#include "DirectoryNode.h" + +namespace XFILE +{ + namespace MUSICDATABASEDIRECTORY + { + class CDirectoryNodeAlbumRecentlyAdded : public CDirectoryNode + { + public: + CDirectoryNodeAlbumRecentlyAdded(const std::string& strName, CDirectoryNode* pParent); + protected: + NODE_TYPE GetChildType() const override; + bool GetContent(CFileItemList& items) const override; + std::string GetLocalizedName() const override; + }; + } +} + + diff --git a/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeAlbumRecentlyAddedSong.cpp b/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeAlbumRecentlyAddedSong.cpp new file mode 100644 index 0000000..8c8d786 --- /dev/null +++ b/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeAlbumRecentlyAddedSong.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2005-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#include "DirectoryNodeAlbumRecentlyAddedSong.h" + +#include "music/MusicDatabase.h" + +using namespace XFILE::MUSICDATABASEDIRECTORY; + +CDirectoryNodeAlbumRecentlyAddedSong::CDirectoryNodeAlbumRecentlyAddedSong(const std::string& strName, CDirectoryNode* pParent) + : CDirectoryNode(NODE_TYPE_ALBUM_RECENTLY_ADDED_SONGS, strName, pParent) +{ + +} + +bool CDirectoryNodeAlbumRecentlyAddedSong::GetContent(CFileItemList& items) const +{ + CMusicDatabase musicdatabase; + if (!musicdatabase.Open()) + return false; + + std::string strBaseDir=BuildPath(); + bool bSuccess=musicdatabase.GetRecentlyAddedAlbumSongs(strBaseDir, items); + + musicdatabase.Close(); + + return bSuccess; +} diff --git a/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeAlbumRecentlyAddedSong.h b/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeAlbumRecentlyAddedSong.h new file mode 100644 index 0000000..9cc46c1 --- /dev/null +++ b/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeAlbumRecentlyAddedSong.h @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2005-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#pragma once + +#include "DirectoryNode.h" + +namespace XFILE +{ + namespace MUSICDATABASEDIRECTORY + { + class CDirectoryNodeAlbumRecentlyAddedSong : public CDirectoryNode + { + public: + CDirectoryNodeAlbumRecentlyAddedSong(const std::string& strName, CDirectoryNode* pParent); + protected: + bool GetContent(CFileItemList& items) const override; + }; + } +} + + diff --git a/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeAlbumRecentlyPlayed.cpp b/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeAlbumRecentlyPlayed.cpp new file mode 100644 index 0000000..77940c2 --- /dev/null +++ b/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeAlbumRecentlyPlayed.cpp @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2005-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#include "DirectoryNodeAlbumRecentlyPlayed.h" + +#include "FileItem.h" +#include "guilib/LocalizeStrings.h" +#include "music/MusicDatabase.h" +#include "utils/StringUtils.h" + +using namespace XFILE::MUSICDATABASEDIRECTORY; + +CDirectoryNodeAlbumRecentlyPlayed::CDirectoryNodeAlbumRecentlyPlayed(const std::string& strName, CDirectoryNode* pParent) + : CDirectoryNode(NODE_TYPE_ALBUM_RECENTLY_PLAYED, strName, pParent) +{ + +} + +NODE_TYPE CDirectoryNodeAlbumRecentlyPlayed::GetChildType() const +{ + if (GetName()=="-1") + return NODE_TYPE_ALBUM_RECENTLY_PLAYED_SONGS; + + return NODE_TYPE_DISC; +} + +std::string CDirectoryNodeAlbumRecentlyPlayed::GetLocalizedName() const +{ + if (GetID() == -1) + return g_localizeStrings.Get(15102); // All Albums + CMusicDatabase db; + if (db.Open()) + return db.GetAlbumById(GetID()); + return ""; +} + +bool CDirectoryNodeAlbumRecentlyPlayed::GetContent(CFileItemList& items) const +{ + CMusicDatabase musicdatabase; + if (!musicdatabase.Open()) + return false; + + VECALBUMS albums; + if (!musicdatabase.GetRecentlyPlayedAlbums(albums)) + { + musicdatabase.Close(); + return false; + } + + for (int i=0; i<(int)albums.size(); ++i) + { + CAlbum& album=albums[i]; + std::string strDir = StringUtils::Format("{}{}/", BuildPath(), album.idAlbum); + CFileItemPtr pItem(new CFileItem(strDir, album)); + items.Add(pItem); + } + + musicdatabase.Close(); + return true; +} diff --git a/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeAlbumRecentlyPlayed.h b/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeAlbumRecentlyPlayed.h new file mode 100644 index 0000000..4691c89 --- /dev/null +++ b/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeAlbumRecentlyPlayed.h @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2005-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#pragma once + +#include "DirectoryNode.h" + +namespace XFILE +{ + namespace MUSICDATABASEDIRECTORY + { + class CDirectoryNodeAlbumRecentlyPlayed : public CDirectoryNode + { + public: + CDirectoryNodeAlbumRecentlyPlayed(const std::string& strName, CDirectoryNode* pParent); + protected: + NODE_TYPE GetChildType() const override; + bool GetContent(CFileItemList& items) const override; + std::string GetLocalizedName() const override; + }; + } +} + + diff --git a/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeAlbumRecentlyPlayedSong.cpp b/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeAlbumRecentlyPlayedSong.cpp new file mode 100644 index 0000000..7a01af0 --- /dev/null +++ b/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeAlbumRecentlyPlayedSong.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2005-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#include "DirectoryNodeAlbumRecentlyPlayedSong.h" + +#include "music/MusicDatabase.h" + +using namespace XFILE::MUSICDATABASEDIRECTORY; + +CDirectoryNodeAlbumRecentlyPlayedSong::CDirectoryNodeAlbumRecentlyPlayedSong(const std::string& strName, CDirectoryNode* pParent) + : CDirectoryNode(NODE_TYPE_ALBUM_RECENTLY_PLAYED_SONGS, strName, pParent) +{ + +} + +bool CDirectoryNodeAlbumRecentlyPlayedSong::GetContent(CFileItemList& items) const +{ + CMusicDatabase musicdatabase; + if (!musicdatabase.Open()) + return false; + + std::string strBaseDir=BuildPath(); + bool bSuccess=musicdatabase.GetRecentlyPlayedAlbumSongs(strBaseDir, items); + + musicdatabase.Close(); + + return bSuccess; +} diff --git a/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeAlbumRecentlyPlayedSong.h b/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeAlbumRecentlyPlayedSong.h new file mode 100644 index 0000000..3ffab08 --- /dev/null +++ b/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeAlbumRecentlyPlayedSong.h @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2005-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#pragma once + +#include "DirectoryNode.h" + +namespace XFILE +{ + namespace MUSICDATABASEDIRECTORY + { + class CDirectoryNodeAlbumRecentlyPlayedSong : public CDirectoryNode + { + public: + CDirectoryNodeAlbumRecentlyPlayedSong(const std::string& strName, CDirectoryNode* pParent); + protected: + bool GetContent(CFileItemList& items) const override; + }; + } +} + + diff --git a/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeAlbumTop100.cpp b/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeAlbumTop100.cpp new file mode 100644 index 0000000..88ffaff --- /dev/null +++ b/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeAlbumTop100.cpp @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2005-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#include "DirectoryNodeAlbumTop100.h" + +#include "FileItem.h" +#include "music/MusicDatabase.h" +#include "utils/StringUtils.h" + +using namespace XFILE::MUSICDATABASEDIRECTORY; + +CDirectoryNodeAlbumTop100::CDirectoryNodeAlbumTop100(const std::string& strName, CDirectoryNode* pParent) + : CDirectoryNode(NODE_TYPE_ALBUM_TOP100, strName, pParent) +{ + +} + +NODE_TYPE CDirectoryNodeAlbumTop100::GetChildType() const +{ + if (GetName()=="-1") + return NODE_TYPE_ALBUM_TOP100_SONGS; + + return NODE_TYPE_SONG; +} + +std::string CDirectoryNodeAlbumTop100::GetLocalizedName() const +{ + CMusicDatabase db; + if (db.Open()) + return db.GetAlbumById(GetID()); + return ""; +} + +bool CDirectoryNodeAlbumTop100::GetContent(CFileItemList& items) const +{ + CMusicDatabase musicdatabase; + if (!musicdatabase.Open()) + return false; + + VECALBUMS albums; + if (!musicdatabase.GetTop100Albums(albums)) + { + musicdatabase.Close(); + return false; + } + + for (int i=0; i<(int)albums.size(); ++i) + { + CAlbum& album=albums[i]; + std::string strDir = StringUtils::Format("{}{}/", BuildPath(), album.idAlbum); + CFileItemPtr pItem(new CFileItem(strDir, album)); + items.Add(pItem); + } + + musicdatabase.Close(); + + return true; +} diff --git a/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeAlbumTop100.h b/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeAlbumTop100.h new file mode 100644 index 0000000..de117bd --- /dev/null +++ b/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeAlbumTop100.h @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2005-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#pragma once + +#include "DirectoryNode.h" + +namespace XFILE +{ + namespace MUSICDATABASEDIRECTORY + { + class CDirectoryNodeAlbumTop100 : public CDirectoryNode + { + public: + CDirectoryNodeAlbumTop100(const std::string& strName, CDirectoryNode* pParent); + protected: + NODE_TYPE GetChildType() const override; + bool GetContent(CFileItemList& items) const override; + std::string GetLocalizedName() const override; + }; + } +} + + diff --git a/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeAlbumTop100Song.cpp b/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeAlbumTop100Song.cpp new file mode 100644 index 0000000..109af60 --- /dev/null +++ b/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeAlbumTop100Song.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2005-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#include "DirectoryNodeAlbumTop100Song.h" + +#include "music/MusicDatabase.h" + +using namespace XFILE::MUSICDATABASEDIRECTORY; + +CDirectoryNodeAlbumTop100Song::CDirectoryNodeAlbumTop100Song(const std::string& strName, CDirectoryNode* pParent) + : CDirectoryNode(NODE_TYPE_ALBUM_TOP100_SONGS, strName, pParent) +{ + +} + +bool CDirectoryNodeAlbumTop100Song::GetContent(CFileItemList& items) const +{ + CMusicDatabase musicdatabase; + if (!musicdatabase.Open()) + return false; + + std::string strBaseDir=BuildPath(); + bool bSuccess=musicdatabase.GetTop100AlbumSongs(strBaseDir, items); + + musicdatabase.Close(); + + return bSuccess; +} diff --git a/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeAlbumTop100Song.h b/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeAlbumTop100Song.h new file mode 100644 index 0000000..18351d7 --- /dev/null +++ b/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeAlbumTop100Song.h @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2005-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#pragma once + +#include "DirectoryNode.h" + +namespace XFILE +{ + namespace MUSICDATABASEDIRECTORY + { + class CDirectoryNodeAlbumTop100Song : public CDirectoryNode + { + public: + CDirectoryNodeAlbumTop100Song(const std::string& strName, CDirectoryNode* pParent); + protected: + bool GetContent(CFileItemList& items) const override; + }; + } +} + + diff --git a/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeArtist.cpp b/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeArtist.cpp new file mode 100644 index 0000000..b087fa2 --- /dev/null +++ b/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeArtist.cpp @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2005-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#include "DirectoryNodeArtist.h" + +#include "QueryParams.h" +#include "ServiceBroker.h" +#include "guilib/LocalizeStrings.h" +#include "music/MusicDatabase.h" +#include "settings/Settings.h" +#include "settings/SettingsComponent.h" + +using namespace XFILE::MUSICDATABASEDIRECTORY; + +CDirectoryNodeArtist::CDirectoryNodeArtist(const std::string& strName, CDirectoryNode* pParent) + : CDirectoryNode(NODE_TYPE_ARTIST, strName, pParent) +{ + +} + +NODE_TYPE CDirectoryNodeArtist::GetChildType() const +{ + return NODE_TYPE_ALBUM; +} + +std::string CDirectoryNodeArtist::GetLocalizedName() const +{ + if (GetID() == -1) + return g_localizeStrings.Get(15103); // All Artists + CMusicDatabase db; + if (db.Open()) + return db.GetArtistById(GetID()); + return ""; +} + +bool CDirectoryNodeArtist::GetContent(CFileItemList& items) const +{ + CMusicDatabase musicdatabase; + if (!musicdatabase.Open()) + return false; + + CQueryParams params; + CollectQueryParams(params); + + bool bSuccess = musicdatabase.GetArtistsNav(BuildPath(), items, !CServiceBroker::GetSettingsComponent()->GetSettings()->GetBool(CSettings::SETTING_MUSICLIBRARY_SHOWCOMPILATIONARTISTS), params.GetGenreId()); + + musicdatabase.Close(); + + return bSuccess; +} diff --git a/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeArtist.h b/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeArtist.h new file mode 100644 index 0000000..59b8c73 --- /dev/null +++ b/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeArtist.h @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2005-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#pragma once + +#include "DirectoryNode.h" + +namespace XFILE +{ + namespace MUSICDATABASEDIRECTORY + { + class CDirectoryNodeArtist : public CDirectoryNode + { + public: + CDirectoryNodeArtist(const std::string& strName, CDirectoryNode* pParent); + protected: + NODE_TYPE GetChildType() const override; + bool GetContent(CFileItemList& items) const override; + std::string GetLocalizedName() const override; + }; + } +} + + diff --git a/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeDiscs.cpp b/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeDiscs.cpp new file mode 100644 index 0000000..42cf3bb --- /dev/null +++ b/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeDiscs.cpp @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2005-2019 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#include "DirectoryNodeDiscs.h" + +#include "QueryParams.h" +#include "guilib/LocalizeStrings.h" +#include "music/MusicDatabase.h" + +using namespace XFILE::MUSICDATABASEDIRECTORY; + +CDirectoryNodeDiscs::CDirectoryNodeDiscs(const std::string& strName, + CDirectoryNode* pParent) + : CDirectoryNode(NODE_TYPE_DISC, strName, pParent) +{ +} + +NODE_TYPE CDirectoryNodeDiscs::GetChildType() const +{ + return NODE_TYPE_SONG; +} + +std::string CDirectoryNodeDiscs::GetLocalizedName() const +{ + CQueryParams params; + CollectQueryParams(params); + std::string title; + CMusicDatabase db; + if (db.Open()) + title = db.GetAlbumDiscTitle(params.GetAlbumId(), params.GetDisc()); + db.Close(); + if (title.empty()) + title = g_localizeStrings.Get(15102); // All Albums + + return title; +} + +bool CDirectoryNodeDiscs::GetContent(CFileItemList& items) const +{ + CMusicDatabase musicdatabase; + if (!musicdatabase.Open()) + return false; + + CQueryParams params; + CollectQueryParams(params); + + bool bSuccess = musicdatabase.GetDiscsNav(BuildPath(), items, params.GetAlbumId()); + + musicdatabase.Close(); + + return bSuccess; +} diff --git a/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeDiscs.h b/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeDiscs.h new file mode 100644 index 0000000..5cf4f6a --- /dev/null +++ b/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeDiscs.h @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2005-2019 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#pragma once + +#include "DirectoryNode.h" + +namespace XFILE +{ +namespace MUSICDATABASEDIRECTORY +{ +class CDirectoryNodeDiscs : public CDirectoryNode +{ +public: + CDirectoryNodeDiscs(const std::string& strName, CDirectoryNode* pParent); + +protected: + NODE_TYPE GetChildType() const override; + bool GetContent(CFileItemList& items) const override; + std::string GetLocalizedName() const override; +}; +} // namespace MUSICDATABASEDIRECTORY +} // namespace XFILE diff --git a/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeGrouped.cpp b/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeGrouped.cpp new file mode 100644 index 0000000..65875f7 --- /dev/null +++ b/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeGrouped.cpp @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2005-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#include "DirectoryNodeGrouped.h" + +#include "music/MusicDatabase.h" + +using namespace XFILE::MUSICDATABASEDIRECTORY; + +CDirectoryNodeGrouped::CDirectoryNodeGrouped(NODE_TYPE type, const std::string& strName, CDirectoryNode* pParent) + : CDirectoryNode(type, strName, pParent) +{ } + +NODE_TYPE CDirectoryNodeGrouped::GetChildType() const +{ + if (GetType() == NODE_TYPE_YEAR) + return NODE_TYPE_ALBUM; + + return NODE_TYPE_ARTIST; +} + +std::string CDirectoryNodeGrouped::GetLocalizedName() const +{ + CMusicDatabase db; + if (db.Open()) + return db.GetItemById(GetContentType(), GetID()); + return ""; +} + +bool CDirectoryNodeGrouped::GetContent(CFileItemList& items) const +{ + CMusicDatabase musicdatabase; + if (!musicdatabase.Open()) + return false; + + return musicdatabase.GetItems(BuildPath(), GetContentType(), items); +} + +std::string CDirectoryNodeGrouped::GetContentType() const +{ + switch (GetType()) + { + case NODE_TYPE_GENRE: + return "genres"; + case NODE_TYPE_SOURCE: + return "sources"; + case NODE_TYPE_ROLE: + return "roles"; + case NODE_TYPE_YEAR: + return "years"; + default: + break; + } + + return ""; +} diff --git a/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeGrouped.h b/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeGrouped.h new file mode 100644 index 0000000..38e7fd9 --- /dev/null +++ b/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeGrouped.h @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2005-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#pragma once + +#include "DirectoryNode.h" + +namespace XFILE +{ + namespace MUSICDATABASEDIRECTORY + { + class CDirectoryNodeGrouped : public CDirectoryNode + { + public: + CDirectoryNodeGrouped(NODE_TYPE type, const std::string& strName, CDirectoryNode* pParent); + protected: + NODE_TYPE GetChildType() const override; + bool GetContent(CFileItemList& items) const override; + std::string GetLocalizedName() const override; + + private: + std::string GetContentType() const; + }; + } +} + + diff --git a/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeOverview.cpp b/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeOverview.cpp new file mode 100644 index 0000000..fefeb6d --- /dev/null +++ b/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeOverview.cpp @@ -0,0 +1,87 @@ +/* + * Copyright (C) 2005-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#include "DirectoryNodeOverview.h" + +#include "FileItem.h" +#include "guilib/LocalizeStrings.h" +#include "music/MusicDatabase.h" +#include "utils/StringUtils.h" + +namespace XFILE +{ + namespace MUSICDATABASEDIRECTORY + { + Node OverviewChildren[] = { + { NODE_TYPE_GENRE, "genres", 135 }, + { NODE_TYPE_ARTIST, "artists", 133 }, + { NODE_TYPE_ALBUM, "albums", 132 }, + { NODE_TYPE_SINGLES, "singles", 1050 }, + { NODE_TYPE_SONG, "songs", 134 }, + { NODE_TYPE_YEAR, "years", 652 }, + { NODE_TYPE_TOP100, "top100", 271 }, + { NODE_TYPE_ALBUM_RECENTLY_ADDED, "recentlyaddedalbums", 359 }, + { NODE_TYPE_ALBUM_RECENTLY_PLAYED, "recentlyplayedalbums", 517 }, + { NODE_TYPE_ALBUM, "compilations", 521 }, + { NODE_TYPE_ROLE, "roles", 38033 }, + { NODE_TYPE_SOURCE, "sources", 39031 }, + { NODE_TYPE_DISC, "discs", 14087 }, + { NODE_TYPE_YEAR, "originalyears", 38078 }, + }; + }; +}; + +using namespace XFILE::MUSICDATABASEDIRECTORY; + +CDirectoryNodeOverview::CDirectoryNodeOverview(const std::string& strName, CDirectoryNode* pParent) + : CDirectoryNode(NODE_TYPE_OVERVIEW, strName, pParent) +{ + +} + +NODE_TYPE CDirectoryNodeOverview::GetChildType() const +{ + for (const Node& node : OverviewChildren) + if (GetName() == node.id) + return node.node; + return NODE_TYPE_NONE; +} + +std::string CDirectoryNodeOverview::GetLocalizedName() const +{ + for (const Node& node : OverviewChildren) + if (GetName() == node.id) + return g_localizeStrings.Get(node.label); + return ""; +} + +bool CDirectoryNodeOverview::GetContent(CFileItemList& items) const +{ + CMusicDatabase musicDatabase; + musicDatabase.Open(); + + bool hasSingles = (musicDatabase.GetSinglesCount() > 0); + bool hasCompilations = (musicDatabase.GetCompilationAlbumsCount() > 0); + + for (unsigned int i = 0; i < sizeof(OverviewChildren) / sizeof(Node); ++i) + { + if (i == 3 && !hasSingles) + continue; + if (i == 9 && !hasCompilations) + continue; + + CFileItemPtr pItem(new CFileItem(g_localizeStrings.Get(OverviewChildren[i].label))); + std::string strDir = StringUtils::Format("{}/", OverviewChildren[i].id); + pItem->SetPath(BuildPath() + strDir); + pItem->m_bIsFolder = true; + pItem->SetCanQueue(false); + items.Add(pItem); + } + + return true; +} diff --git a/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeOverview.h b/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeOverview.h new file mode 100644 index 0000000..057a9e8 --- /dev/null +++ b/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeOverview.h @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2005-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#pragma once + +#include "DirectoryNode.h" + +namespace XFILE +{ + namespace MUSICDATABASEDIRECTORY + { + class CDirectoryNodeOverview : public CDirectoryNode + { + public: + CDirectoryNodeOverview(const std::string& strName, CDirectoryNode* pParent); + protected: + NODE_TYPE GetChildType() const override; + bool GetContent(CFileItemList& items) const override; + std::string GetLocalizedName() const override; + }; + } +} + + diff --git a/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeRoot.cpp b/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeRoot.cpp new file mode 100644 index 0000000..31cc761 --- /dev/null +++ b/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeRoot.cpp @@ -0,0 +1,22 @@ +/* + * Copyright (C) 2005-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#include "DirectoryNodeRoot.h" + +using namespace XFILE::MUSICDATABASEDIRECTORY; + +CDirectoryNodeRoot::CDirectoryNodeRoot(const std::string& strName, CDirectoryNode* pParent) + : CDirectoryNode(NODE_TYPE_ROOT, strName, pParent) +{ + +} + +NODE_TYPE CDirectoryNodeRoot::GetChildType() const +{ + return NODE_TYPE_OVERVIEW; +} diff --git a/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeRoot.h b/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeRoot.h new file mode 100644 index 0000000..c4128a3 --- /dev/null +++ b/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeRoot.h @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2005-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#pragma once + +#include "DirectoryNode.h" + +namespace XFILE +{ + namespace MUSICDATABASEDIRECTORY + { + class CDirectoryNodeRoot : public CDirectoryNode + { + public: + CDirectoryNodeRoot(const std::string& strName, CDirectoryNode* pParent); + protected: + NODE_TYPE GetChildType() const override; + }; + } +} + + diff --git a/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeSingles.cpp b/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeSingles.cpp new file mode 100644 index 0000000..8deae27 --- /dev/null +++ b/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeSingles.cpp @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2005-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#include "DirectoryNodeSingles.h" + +#include "music/MusicDatabase.h" + +using namespace XFILE::MUSICDATABASEDIRECTORY; + +CDirectoryNodeSingles::CDirectoryNodeSingles(const std::string& strName, CDirectoryNode* pParent) + : CDirectoryNode(NODE_TYPE_SINGLES, strName, pParent) +{ + +} + +bool CDirectoryNodeSingles::GetContent(CFileItemList& items) const +{ + CMusicDatabase musicdatabase; + if (!musicdatabase.Open()) + return false; + + bool bSuccess = musicdatabase.GetSongsFullByWhere(BuildPath(), CDatabase::Filter(), items, SortDescription(), true); + + musicdatabase.Close(); + + return bSuccess; +} diff --git a/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeSingles.h b/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeSingles.h new file mode 100644 index 0000000..cc297b7 --- /dev/null +++ b/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeSingles.h @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2005-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#pragma once + +#include "DirectoryNode.h" + +namespace XFILE +{ + namespace MUSICDATABASEDIRECTORY + { + class CDirectoryNodeSingles : public CDirectoryNode + { + public: + CDirectoryNodeSingles(const std::string& strName, CDirectoryNode* pParent); + protected: + bool GetContent(CFileItemList& items) const override; + }; + } +} + + diff --git a/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeSong.cpp b/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeSong.cpp new file mode 100644 index 0000000..4c43f90 --- /dev/null +++ b/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeSong.cpp @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2005-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#include "DirectoryNodeSong.h" + +#include "QueryParams.h" +#include "music/MusicDatabase.h" + +using namespace XFILE::MUSICDATABASEDIRECTORY; + +CDirectoryNodeSong::CDirectoryNodeSong(const std::string& strName, CDirectoryNode* pParent) + : CDirectoryNode(NODE_TYPE_SONG, strName, pParent) +{ + +} + +bool CDirectoryNodeSong::GetContent(CFileItemList& items) const +{ + CMusicDatabase musicdatabase; + if (!musicdatabase.Open()) + return false; + + CQueryParams params; + CollectQueryParams(params); + + std::string strBaseDir=BuildPath(); + bool bSuccess=musicdatabase.GetSongsNav(strBaseDir, items, params.GetGenreId(), params.GetArtistId(), params.GetAlbumId()); + + musicdatabase.Close(); + + return bSuccess; +} diff --git a/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeSong.h b/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeSong.h new file mode 100644 index 0000000..668014b --- /dev/null +++ b/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeSong.h @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2005-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#pragma once + +#include "DirectoryNode.h" + +namespace XFILE +{ + namespace MUSICDATABASEDIRECTORY + { + class CDirectoryNodeSong : public CDirectoryNode + { + public: + CDirectoryNodeSong(const std::string& strEntryName, CDirectoryNode* pParent); + protected: + bool GetContent(CFileItemList& items) const override; + }; + } +} + + diff --git a/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeSongTop100.cpp b/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeSongTop100.cpp new file mode 100644 index 0000000..a03a8ff --- /dev/null +++ b/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeSongTop100.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2005-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#include "DirectoryNodeSongTop100.h" + +#include "music/MusicDatabase.h" + +using namespace XFILE::MUSICDATABASEDIRECTORY; + +CDirectoryNodeSongTop100::CDirectoryNodeSongTop100(const std::string& strName, CDirectoryNode* pParent) + : CDirectoryNode(NODE_TYPE_SONG_TOP100, strName, pParent) +{ + +} + +bool CDirectoryNodeSongTop100::GetContent(CFileItemList& items) const +{ + CMusicDatabase musicdatabase; + if (!musicdatabase.Open()) + return false; + + std::string strBaseDir=BuildPath(); + bool bSuccess=musicdatabase.GetTop100(strBaseDir, items); + + musicdatabase.Close(); + + return bSuccess; +} diff --git a/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeSongTop100.h b/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeSongTop100.h new file mode 100644 index 0000000..ca34a72 --- /dev/null +++ b/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeSongTop100.h @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2005-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#pragma once + +#include "DirectoryNode.h" + +namespace XFILE +{ + namespace MUSICDATABASEDIRECTORY + { + class CDirectoryNodeSongTop100 : public CDirectoryNode + { + public: + CDirectoryNodeSongTop100(const std::string& strName, CDirectoryNode* pParent); + protected: + bool GetContent(CFileItemList& items) const override; + }; + } +} + + diff --git a/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeTop100.cpp b/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeTop100.cpp new file mode 100644 index 0000000..fff9228 --- /dev/null +++ b/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeTop100.cpp @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2005-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#include "DirectoryNodeTop100.h" + +#include "FileItem.h" +#include "guilib/LocalizeStrings.h" +#include "utils/StringUtils.h" + +using namespace XFILE::MUSICDATABASEDIRECTORY; + +Node Top100Children[] = { + { NODE_TYPE_SONG_TOP100, "songs", 10504 }, + { NODE_TYPE_ALBUM_TOP100, "albums", 10505 }, + }; + +CDirectoryNodeTop100::CDirectoryNodeTop100(const std::string& strName, CDirectoryNode* pParent) + : CDirectoryNode(NODE_TYPE_TOP100, strName, pParent) +{ + +} + +NODE_TYPE CDirectoryNodeTop100::GetChildType() const +{ + for (const Node& node : Top100Children) + if (GetName() == node.id) + return node.node; + + return NODE_TYPE_NONE; +} + +std::string CDirectoryNodeTop100::GetLocalizedName() const +{ + for (const Node& node : Top100Children) + if (GetName() == node.id) + return g_localizeStrings.Get(node.label); + return ""; +} + +bool CDirectoryNodeTop100::GetContent(CFileItemList& items) const +{ + for (const Node& node : Top100Children) + { + CFileItemPtr pItem(new CFileItem(g_localizeStrings.Get(node.label))); + std::string strDir = StringUtils::Format("{}/", node.id); + pItem->SetPath(BuildPath() + strDir); + pItem->m_bIsFolder = true; + items.Add(pItem); + } + + return true; +} diff --git a/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeTop100.h b/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeTop100.h new file mode 100644 index 0000000..bf5068f --- /dev/null +++ b/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeTop100.h @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2005-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#pragma once + +#include "DirectoryNode.h" + +namespace XFILE +{ + namespace MUSICDATABASEDIRECTORY + { + class CDirectoryNodeTop100 : public CDirectoryNode + { + public: + CDirectoryNodeTop100(const std::string& strName, CDirectoryNode* pParent); + protected: + NODE_TYPE GetChildType() const override; + bool GetContent(CFileItemList& items) const override; + std::string GetLocalizedName() const override; + }; + } +} + + diff --git a/xbmc/filesystem/MusicDatabaseDirectory/QueryParams.cpp b/xbmc/filesystem/MusicDatabaseDirectory/QueryParams.cpp new file mode 100644 index 0000000..3353631 --- /dev/null +++ b/xbmc/filesystem/MusicDatabaseDirectory/QueryParams.cpp @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2005-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#include "QueryParams.h" + +#include <stdlib.h> + +using namespace XFILE::MUSICDATABASEDIRECTORY; + +CQueryParams::CQueryParams() +{ + m_idArtist=-1; + m_idAlbum=-1; + m_idGenre=-1; + m_idSong=-1; + m_year=-1; + m_disc = -1; +} + +void CQueryParams::SetQueryParam(NODE_TYPE NodeType, const std::string& strNodeName) +{ + int idDb = atoi(strNodeName.c_str()); + + switch (NodeType) + { + case NODE_TYPE_GENRE: + m_idGenre=idDb; + break; + case NODE_TYPE_YEAR: + m_year=idDb; + break; + case NODE_TYPE_ARTIST: + m_idArtist=idDb; + break; + case NODE_TYPE_DISC: + m_disc = idDb; + break; + case NODE_TYPE_ALBUM_RECENTLY_PLAYED: + case NODE_TYPE_ALBUM_RECENTLY_ADDED: + case NODE_TYPE_ALBUM_TOP100: + case NODE_TYPE_ALBUM: + m_idAlbum=idDb; + break; + case NODE_TYPE_ALBUM_RECENTLY_ADDED_SONGS: + case NODE_TYPE_ALBUM_RECENTLY_PLAYED_SONGS: + case NODE_TYPE_ALBUM_TOP100_SONGS: + case NODE_TYPE_SONG: + case NODE_TYPE_SONG_TOP100: + m_idSong=idDb; + default: + break; + } +} diff --git a/xbmc/filesystem/MusicDatabaseDirectory/QueryParams.h b/xbmc/filesystem/MusicDatabaseDirectory/QueryParams.h new file mode 100644 index 0000000..abfbdea --- /dev/null +++ b/xbmc/filesystem/MusicDatabaseDirectory/QueryParams.h @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2005-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#pragma once + +#include "DirectoryNode.h" + +namespace XFILE +{ + namespace MUSICDATABASEDIRECTORY + { + class CQueryParams + { + public: + CQueryParams(); + int GetArtistId() { return m_idArtist; } + int GetAlbumId() { return m_idAlbum; } + int GetGenreId() { return m_idGenre; } + int GetSongId() { return m_idSong; } + int GetYear() { return m_year; } + int GetDisc() { return m_disc; } + + protected: + void SetQueryParam(NODE_TYPE NodeType, const std::string& strNodeName); + + friend class CDirectoryNode; + private: + int m_idArtist; + int m_idAlbum; + int m_idGenre; + int m_idSong; + int m_year; + int m_disc; + }; + } +} + + |