Debian Codegraph @

xbmc/guilib/guiinfo/LibraryGUIInfo.cpp

raw symbols SCIP
1 /*
2 * Copyright (C) 2012-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
4 *
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
8
9 #include "guilib/guiinfo/LibraryGUIInfo.h"
10
11 #include "FileItem.h"
12 #include "ServiceBroker.h"
13 #include "URL.h"
14 #include "filesystem/Directory.h"
15 #include "guilib/guiinfo/GUIInfo.h"
16 #include "guilib/guiinfo/GUIInfoLabels.h"
17 #include "music/MusicDatabase.h"
18 #include "music/MusicLibraryQueue.h"
19 #include "profiles/ProfileManager.h"
20 #include "settings/SettingsComponent.h"
21 #include "utils/FileUtils.h"
22 #include "utils/StringUtils.h"
23 #include "utils/URIUtils.h"
24 #include "video/VideoDatabase.h"
25 #include "video/VideoLibraryQueue.h"
26
27 using namespace KODI::GUILIB::GUIINFO;
28
29 CLibraryGUIInfo::CLibraryGUIInfo()
30 {
31 ResetLibraryBools();
32 }
33
34 bool CLibraryGUIInfo::GetLibraryBool(int condition) const
35 {
36 bool value = false;
37 GetBool(value, nullptr, 0, CGUIInfo(condition));
38 return value;
39 }
40
41 void CLibraryGUIInfo::SetLibraryBool(int condition, bool value)
42 {
43 switch (condition)
44 {
45 case LIBRARY_HAS_MUSIC:
46 m_libraryHasMusic = value ? 1 : 0;
47 break;
48 case LIBRARY_HAS_MOVIES:
49 m_libraryHasMovies = value ? 1 : 0;
50 break;
51 case LIBRARY_HAS_MOVIE_SETS:
52 m_libraryHasMovieSets = value ? 1 : 0;
53 break;
54 case LIBRARY_HAS_TVSHOWS:
55 m_libraryHasTVShows = value ? 1 : 0;
56 break;
57 case LIBRARY_HAS_MUSICVIDEOS:
58 m_libraryHasMusicVideos = value ? 1 : 0;
59 break;
60 case LIBRARY_HAS_SINGLES:
61 m_libraryHasSingles = value ? 1 : 0;
62 break;
63 case LIBRARY_HAS_COMPILATIONS:
64 m_libraryHasCompilations = value ? 1 : 0;
65 break;
66 case LIBRARY_HAS_BOXSETS:
67 m_libraryHasBoxsets = value ? 1 : 0;
68 break;
69 default:
70 break;
71 }
72 }
73
74 void CLibraryGUIInfo::ResetLibraryBools()
75 {
76 m_libraryHasMusic = -1;
77 m_libraryHasMovies = -1;
78 m_libraryHasTVShows = -1;
79 m_libraryHasMusicVideos = -1;
80 m_libraryHasMovieSets = -1;
81 m_libraryHasSingles = -1;
82 m_libraryHasCompilations = -1;
83 m_libraryHasBoxsets = -1;
84 m_libraryRoleCounts.clear();
85 }
86
87 bool CLibraryGUIInfo::InitCurrentItem(CFileItem *item)
88 {
89 return false;
90 }
91
92 bool CLibraryGUIInfo::GetLabel(std::string& value, const CFileItem *item, int contextWindow, const CGUIInfo &info, std::string *fallback) const
93 {
94 return false;
95 }
96
97 bool CLibraryGUIInfo::GetInt(int& value, const CGUIListItem *gitem, int contextWindow, const CGUIInfo &info) const
98 {
99 return false;
100 }
101
102 bool CLibraryGUIInfo::GetBool(bool& value, const CGUIListItem *gitem, int contextWindow, const CGUIInfo &info) const
103 {
104 switch (info.m_info)
105 {
106 ///////////////////////////////////////////////////////////////////////////////////////////////
107 // LIBRARY_*
108 ///////////////////////////////////////////////////////////////////////////////////////////////
109 case LIBRARY_HAS_MUSIC:
110 {
111 if (m_libraryHasMusic < 0)
112 { // query
113 CMusicDatabase db;
114 if (db.Open())
115 {
116 m_libraryHasMusic = (db.GetSongsCount() > 0) ? 1 : 0;
117 db.Close();
118 }
119 }
120 value = m_libraryHasMusic > 0;
121 return true;
122 }
123 case LIBRARY_HAS_MOVIES:
124 {
125 if (m_libraryHasMovies < 0)
126 {
127 CVideoDatabase db;
128 if (db.Open())
129 {
130 m_libraryHasMovies = db.HasContent(VideoDbContentType::MOVIES) ? 1 : 0;
131 db.Close();
132 }
133 }
134 value = m_libraryHasMovies > 0;
135 return true;
136 }
137 case LIBRARY_HAS_MOVIE_SETS:
138 {
139 if (m_libraryHasMovieSets < 0)
140 {
141 CVideoDatabase db;
142 if (db.Open())
143 {
144 m_libraryHasMovieSets = db.HasSets() ? 1 : 0;
145 db.Close();
146 }
147 }
148 value = m_libraryHasMovieSets > 0;
149 return true;
150 }
151 case LIBRARY_HAS_TVSHOWS:
152 {
153 if (m_libraryHasTVShows < 0)
154 {
155 CVideoDatabase db;
156 if (db.Open())
157 {
158 m_libraryHasTVShows = db.HasContent(VideoDbContentType::TVSHOWS) ? 1 : 0;
159 db.Close();
160 }
161 }
162 value = m_libraryHasTVShows > 0;
163 return true;
164 }
165 case LIBRARY_HAS_MUSICVIDEOS:
166 {
167 if (m_libraryHasMusicVideos < 0)
168 {
169 CVideoDatabase db;
170 if (db.Open())
171 {
172 m_libraryHasMusicVideos = db.HasContent(VideoDbContentType::MUSICVIDEOS) ? 1 : 0;
173 db.Close();
174 }
175 }
176 value = m_libraryHasMusicVideos > 0;
177 return true;
178 }
179 case LIBRARY_HAS_SINGLES:
180 {
181 if (m_libraryHasSingles < 0)
182 {
183 CMusicDatabase db;
184 if (db.Open())
185 {
186 m_libraryHasSingles = (db.GetSinglesCount() > 0) ? 1 : 0;
187 db.Close();
188 }
189 }
190 value = m_libraryHasSingles > 0;
191 return true;
192 }
193 case LIBRARY_HAS_COMPILATIONS:
194 {
195 if (m_libraryHasCompilations < 0)
196 {
197 CMusicDatabase db;
198 if (db.Open())
199 {
200 m_libraryHasCompilations = (db.GetCompilationAlbumsCount() > 0) ? 1 : 0;
201 db.Close();
202 }
203 }
204 value = m_libraryHasCompilations > 0;
205 return true;
206 }
207 case LIBRARY_HAS_BOXSETS:
208 {
209 if (m_libraryHasBoxsets < 0)
210 {
211 CMusicDatabase db;
212 if (db.Open())
213 {
214 m_libraryHasBoxsets = (db.GetBoxsetsCount() > 0) ? 1 : 0;
215 db.Close();
216 }
217 }
218 value = m_libraryHasBoxsets > 0;
219 return true;
220 }
221 case LIBRARY_HAS_VIDEO:
222 {
223 return (GetBool(value, gitem, contextWindow, CGUIInfo(LIBRARY_HAS_MOVIES)) ||
224 GetBool(value, gitem, contextWindow, CGUIInfo(LIBRARY_HAS_TVSHOWS)) ||
225 GetBool(value, gitem, contextWindow, CGUIInfo(LIBRARY_HAS_MUSICVIDEOS)));
226 }
227 case LIBRARY_HAS_ROLE:
228 {
229 std::string strRole = info.GetData3();
230 // Find value for role if already stored
231 int artistcount = -1;
232 for (const auto &role : m_libraryRoleCounts)
233 {
234 if (StringUtils::EqualsNoCase(strRole, role.first))
235 {
236 artistcount = role.second;
237 break;
238 }
239 }
240 // Otherwise get from DB and store
241 if (artistcount < 0)
242 {
243 CMusicDatabase db;
244 if (db.Open())
245 {
246 artistcount = db.GetArtistCountForRole(strRole);
247 db.Close();
248 m_libraryRoleCounts.emplace_back(strRole, artistcount);
249 }
250 }
251 value = artistcount > 0;
252 return true;
253 }
254 case LIBRARY_HAS_NODE:
255 {
256 const CURL url(info.GetData3());
257 const std::shared_ptr<CProfileManager> profileManager =
258 CServiceBroker::GetSettingsComponent()->GetProfileManager();
259 CFileItemList items;
260
261 std::string libDir = profileManager->GetLibraryFolder();
262 XFILE::CDirectory::GetDirectory(libDir, items, "", XFILE::DIR_FLAG_NO_FILE_DIRS);
263 if (items.Size() == 0)
264 libDir = "special://xbmc/system/library/";
265
266 std::string nodePath = URIUtils::AddFileToFolder(libDir, url.GetHostName() + "/");
267 nodePath = URIUtils::AddFileToFolder(nodePath, url.GetFileName());
268 value = CFileUtils::Exists(nodePath);
269 return true;
270 }
271 case LIBRARY_IS_SCANNING:
272 {
273 value = (CMusicLibraryQueue::GetInstance().IsScanningLibrary() ||
274 CVideoLibraryQueue::GetInstance().IsScanningLibrary());
275 return true;
276 }
277 case LIBRARY_IS_SCANNING_VIDEO:
278 {
279 value = CVideoLibraryQueue::GetInstance().IsScanningLibrary();
280 return true;
281 }
282 case LIBRARY_IS_SCANNING_MUSIC:
283 {
284 value = CMusicLibraryQueue::GetInstance().IsScanningLibrary();
285 return true;
286 }
287 }
288
289 return false;
290 }