[cosmetics] update date in GPL header
[vuplus_xbmc] / xbmc / filesystem / MusicDatabaseDirectory / DirectoryNodeOverview.cpp
1 /*
2  *      Copyright (C) 2005-2013 Team XBMC
3  *      http://www.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
26 namespace XFILE
27 {
28   namespace MUSICDATABASEDIRECTORY
29   {
30     Node OverviewChildren[] = {
31                                 { NODE_TYPE_GENRE,                 1, 135 },
32                                 { NODE_TYPE_ARTIST,                2, 133 },
33                                 { NODE_TYPE_ALBUM,                 3, 132 },
34                                 { NODE_TYPE_SINGLES,              10, 1050 },
35                                 { NODE_TYPE_SONG,                  4, 134 },
36                                 { NODE_TYPE_YEAR,                  9, 652 },
37                                 { NODE_TYPE_TOP100,                5, 271 },
38                                 { NODE_TYPE_ALBUM_RECENTLY_ADDED,  6, 359 },
39                                 { NODE_TYPE_ALBUM_RECENTLY_PLAYED, 7, 517 },
40                                 { NODE_TYPE_ALBUM_COMPILATIONS,    8, 521 },
41                               };
42   };
43 };
44
45 using namespace std;
46 using namespace XFILE::MUSICDATABASEDIRECTORY;
47
48 CDirectoryNodeOverview::CDirectoryNodeOverview(const CStdString& strName, CDirectoryNode* pParent)
49   : CDirectoryNode(NODE_TYPE_OVERVIEW, strName, pParent)
50 {
51
52 }
53
54 NODE_TYPE CDirectoryNodeOverview::GetChildType() const
55 {
56   for (unsigned int i = 0; i < sizeof(OverviewChildren) / sizeof(Node); ++i)
57     if (GetID() == OverviewChildren[i].id)
58       return OverviewChildren[i].node;
59   return NODE_TYPE_NONE;
60 }
61
62 CStdString CDirectoryNodeOverview::GetLocalizedName() const
63 {
64   for (unsigned int i = 0; i < sizeof(OverviewChildren) / sizeof(Node); ++i)
65     if (GetID() == OverviewChildren[i].id)
66       return g_localizeStrings.Get(OverviewChildren[i].label);
67   return "";
68 }
69
70 bool CDirectoryNodeOverview::GetContent(CFileItemList& items) const
71 {
72   CMusicDatabase musicDatabase;
73   bool showSingles = false;
74   if (musicDatabase.Open())
75   {
76     CDatabase::Filter filter("songview.idAlbum IN (SELECT idAlbum FROM album WHERE strAlbum = '')");
77     if (musicDatabase.GetSongsCount(filter) > 0)
78       showSingles = true;
79   }
80
81   for (unsigned int i = 0; i < sizeof(OverviewChildren) / sizeof(Node); ++i)
82   {
83     if (i == 3 && !showSingles) // singles
84       continue;
85     if (i == 9 && musicDatabase.GetCompilationAlbumsCount() == 0) // compilations
86       continue;
87
88     CFileItemPtr pItem(new CFileItem(g_localizeStrings.Get(OverviewChildren[i].label)));
89     CStdString strDir;
90     strDir.Format("%ld/", OverviewChildren[i].id);
91     pItem->SetPath(BuildPath() + strDir);
92     pItem->m_bIsFolder = true;
93     pItem->SetCanQueue(false);
94     items.Add(pItem);
95   }
96
97   return true;
98 }