[cstdstring] demise Format, replacing with StringUtils::Format
[vuplus_xbmc] / xbmc / filesystem / MusicDatabaseDirectory / DirectoryNodeOverview.cpp
1 /*
2  *      Copyright (C) 2005-2013 Team XBMC
3  *      http://xbmc.org
4  *
5  *  This Program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2, or (at your option)
8  *  any later version.
9  *
10  *  This Program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with XBMC; see the file COPYING.  If not, see
17  *  <http://www.gnu.org/licenses/>.
18  *
19  */
20
21 #include "DirectoryNodeOverview.h"
22 #include "FileItem.h"
23 #include "music/MusicDatabase.h"
24 #include "guilib/LocalizeStrings.h"
25 #include "utils/StringUtils.h"
26
27 namespace XFILE
28 {
29   namespace MUSICDATABASEDIRECTORY
30   {
31     Node OverviewChildren[] = {
32                                 { NODE_TYPE_GENRE,                 "genres",               135 },
33                                 { NODE_TYPE_ARTIST,                "artists",              133 },
34                                 { NODE_TYPE_ALBUM,                 "albums",               132 },
35                                 { NODE_TYPE_SINGLES,               "singles",              1050 },
36                                 { NODE_TYPE_SONG,                  "songs",                134 },
37                                 { NODE_TYPE_YEAR,                  "years",                652 },
38                                 { NODE_TYPE_TOP100,                "top100",               271 },
39                                 { NODE_TYPE_ALBUM_RECENTLY_ADDED,  "recentlyaddedalbums",  359 },
40                                 { NODE_TYPE_ALBUM_RECENTLY_PLAYED, "recentlyplayedalbums", 517 },
41                                 { NODE_TYPE_ALBUM_COMPILATIONS,    "compilations",         521 },
42                               };
43   };
44 };
45
46 using namespace std;
47 using namespace XFILE::MUSICDATABASEDIRECTORY;
48
49 CDirectoryNodeOverview::CDirectoryNodeOverview(const CStdString& strName, CDirectoryNode* pParent)
50   : CDirectoryNode(NODE_TYPE_OVERVIEW, strName, pParent)
51 {
52
53 }
54
55 NODE_TYPE CDirectoryNodeOverview::GetChildType() const
56 {
57   for (unsigned int i = 0; i < sizeof(OverviewChildren) / sizeof(Node); ++i)
58     if (GetName().Equals(OverviewChildren[i].id.c_str()))
59       return OverviewChildren[i].node;
60   return NODE_TYPE_NONE;
61 }
62
63 CStdString CDirectoryNodeOverview::GetLocalizedName() const
64 {
65   for (unsigned int i = 0; i < sizeof(OverviewChildren) / sizeof(Node); ++i)
66     if (GetName().Equals(OverviewChildren[i].id.c_str()))
67       return g_localizeStrings.Get(OverviewChildren[i].label);
68   return "";
69 }
70
71 bool CDirectoryNodeOverview::GetContent(CFileItemList& items) const
72 {
73   CMusicDatabase musicDatabase;
74   bool showSingles = false;
75   if (musicDatabase.Open())
76   {
77     CDatabase::Filter filter("songview.idAlbum IN (SELECT idAlbum FROM album WHERE strAlbum = '')");
78     if (musicDatabase.GetSongsCount(filter) > 0)
79       showSingles = true;
80   }
81
82   for (unsigned int i = 0; i < sizeof(OverviewChildren) / sizeof(Node); ++i)
83   {
84     if (i == 3 && !showSingles) // singles
85       continue;
86     if (i == 9 && musicDatabase.GetCompilationAlbumsCount() == 0) // compilations
87       continue;
88
89     CFileItemPtr pItem(new CFileItem(g_localizeStrings.Get(OverviewChildren[i].label)));
90     CStdString strDir = StringUtils::Format("%s/", OverviewChildren[i].id.c_str());
91     pItem->SetPath(BuildPath() + strDir);
92     pItem->m_bIsFolder = true;
93     pItem->SetCanQueue(false);
94     items.Add(pItem);
95   }
96
97   return true;
98 }