[PVR][Estuary] Timer settings dialog: Show client name in timer type selection dialog...
[xbmc.git] / xbmc / music / GUIViewStateMusic.cpp
blobf14f5015e47055573556733949074dec170d0609
1 /*
2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
9 #include "GUIViewStateMusic.h"
11 #include "FileItem.h"
12 #include "ServiceBroker.h"
13 #include "filesystem/Directory.h"
14 #include "filesystem/MusicDatabaseDirectory.h"
15 #include "filesystem/VideoDatabaseDirectory.h"
16 #include "guilib/LocalizeStrings.h"
17 #include "guilib/WindowIDs.h"
18 #include "playlists/PlayListTypes.h"
19 #include "settings/AdvancedSettings.h"
20 #include "settings/MediaSourceSettings.h"
21 #include "settings/Settings.h"
22 #include "settings/SettingsComponent.h"
23 #include "utils/FileExtensionProvider.h"
24 #include "utils/SortUtils.h"
25 #include "utils/log.h"
26 #include "view/ViewStateSettings.h"
28 using namespace XFILE;
29 using namespace MUSICDATABASEDIRECTORY;
31 PLAYLIST::Id CGUIViewStateWindowMusic::GetPlaylist() const
33 return PLAYLIST::TYPE_MUSIC;
36 bool CGUIViewStateWindowMusic::AutoPlayNextItem()
38 const std::shared_ptr<CSettings> settings = CServiceBroker::GetSettingsComponent()->GetSettings();
39 return settings->GetBool(CSettings::SETTING_MUSICPLAYER_AUTOPLAYNEXTITEM) &&
40 !settings->GetBool(CSettings::SETTING_MUSICPLAYER_QUEUEBYDEFAULT);
43 std::string CGUIViewStateWindowMusic::GetLockType()
45 return "music";
48 std::string CGUIViewStateWindowMusic::GetExtensions()
50 return CServiceBroker::GetFileExtensionProvider().GetMusicExtensions();
53 VECSOURCES& CGUIViewStateWindowMusic::GetSources()
55 return CGUIViewState::GetSources();
58 CGUIViewStateMusicSearch::CGUIViewStateMusicSearch(const CFileItemList& items) : CGUIViewStateWindowMusic(items)
60 SortAttribute sortAttribute = SortAttributeNone;
61 if (CServiceBroker::GetSettingsComponent()->GetSettings()->GetBool(CSettings::SETTING_FILELISTS_IGNORETHEWHENSORTING))
62 sortAttribute = SortAttributeIgnoreArticle;
64 AddSortMethod(SortByTitle, sortAttribute, 556, LABEL_MASKS("%T - %A", "%D", "%L", "%A")); // Title - Artist, Duration | Label, Artist
65 SetSortMethod(SortByTitle);
67 const CViewState *viewState = CViewStateSettings::GetInstance().Get("musicnavsongs");
68 SetViewAsControl(viewState->m_viewMode);
69 SetSortOrder(viewState->m_sortDescription.sortOrder);
71 LoadViewState(items.GetPath(), WINDOW_MUSIC_NAV);
74 void CGUIViewStateMusicSearch::SaveViewState()
76 SaveViewToDb(m_items.GetPath(), WINDOW_MUSIC_NAV, CViewStateSettings::GetInstance().Get("musicnavsongs"));
79 CGUIViewStateMusicDatabase::CGUIViewStateMusicDatabase(const CFileItemList& items) : CGUIViewStateWindowMusic(items)
81 CMusicDatabaseDirectory dir;
82 NODE_TYPE NodeType=dir.GetDirectoryChildType(items.GetPath());
84 const std::shared_ptr<CSettings> settings = CServiceBroker::GetSettingsComponent()->GetSettings();
85 std::string strTrack = settings->GetString(CSettings::SETTING_MUSICFILES_LIBRARYTRACKFORMAT);
86 if (strTrack.empty())
87 strTrack = settings->GetString(CSettings::SETTING_MUSICFILES_TRACKFORMAT);
88 std::string strAlbum = CServiceBroker::GetSettingsComponent()->GetAdvancedSettings()->m_strMusicLibraryAlbumFormat;
89 if (strAlbum.empty())
90 strAlbum = "%B"; // album
91 CLog::Log(LOGDEBUG, "Custom album format = [{}]", strAlbum);
92 SortAttribute sortAttribute = SortAttributeNone;
93 if (settings->GetBool(CSettings::SETTING_FILELISTS_IGNORETHEWHENSORTING))
94 sortAttribute = SortAttributeIgnoreArticle;
95 if (settings->GetBool(CSettings::SETTING_MUSICLIBRARY_USEARTISTSORTNAME))
96 sortAttribute = static_cast<SortAttribute>(sortAttribute | SortAttributeUseArtistSortName);
98 switch (NodeType)
100 case NODE_TYPE_OVERVIEW:
102 AddSortMethod(SortByNone, 551, LABEL_MASKS("%F", "", "%L", "")); // Filename, empty | Foldername, empty
103 SetSortMethod(SortByNone);
105 SetViewAsControl(DEFAULT_VIEW_LIST);
107 SetSortOrder(SortOrderNone);
109 break;
110 case NODE_TYPE_TOP100:
112 AddSortMethod(SortByNone, 551, LABEL_MASKS("%F", "", "%L", "")); // Filename, empty | Foldername, empty
113 SetSortMethod(SortByNone);
115 SetViewAsControl(DEFAULT_VIEW_LIST);
117 SetSortOrder(SortOrderNone);
119 break;
120 case NODE_TYPE_GENRE:
122 AddSortMethod(SortByGenre, 515, LABEL_MASKS("%F", "", "%G", "")); // Filename, empty | Genre, empty
123 SetSortMethod(SortByGenre);
125 SetViewAsControl(DEFAULT_VIEW_LIST);
127 SetSortOrder(SortOrderAscending);
129 break;
130 case NODE_TYPE_ROLE:
132 AddSortMethod(SortByNone, 576, LABEL_MASKS("%F", "", "%G", "")); // Filename, empty | Genre, empty
133 SetSortMethod(SortByPlaycount);
135 SetViewAsControl(DEFAULT_VIEW_LIST);
137 SetSortOrder(SortOrderNone);
139 break;
140 case NODE_TYPE_YEAR:
142 AddSortMethod(SortByLabel, 562, LABEL_MASKS("%F", "", "%Y", "")); // Filename, empty | Year, empty
143 SetSortMethod(SortByLabel);
145 SetViewAsControl(DEFAULT_VIEW_LIST);
147 SetSortOrder(SortOrderAscending);
149 break;
150 case NODE_TYPE_ARTIST:
152 AddSortMethod(SortByArtist, sortAttribute, 557, LABEL_MASKS("%F", "", "%A", "")); // Filename, empty | Artist, empty
153 AddSortMethod(SortByDateAdded, sortAttribute, 570, LABEL_MASKS("%F", "", "%A", "%a")); // Filename, empty | Artist, dateAdded
154 SetSortMethod(SortByArtist);
156 const CViewState *viewState = CViewStateSettings::GetInstance().Get("musicnavartists");
157 SetViewAsControl(viewState->m_viewMode);
158 SetSortOrder(viewState->m_sortDescription.sortOrder);
160 break;
161 case NODE_TYPE_ALBUM:
163 // album
164 AddSortMethod(SortByAlbum, sortAttribute, 558, LABEL_MASKS("%F", "", strAlbum, "%A")); // Filename, empty | Userdefined (default=%B), Artist
165 // artist
166 AddSortMethod(SortByArtist, sortAttribute, 557, LABEL_MASKS("%F", "", strAlbum, "%A")); // Filename, empty | Userdefined, Artist
167 // artist / year
168 AddSortMethod(SortByArtistThenYear, sortAttribute, 578, LABEL_MASKS("%F", "", strAlbum, "%A / %Y")); // Filename, empty | Userdefined, Artist / Year
169 // discs
170 AddSortMethod(
171 SortByTotalDiscs, sortAttribute, 38077,
172 LABEL_MASKS("%F", "", strAlbum, "%b")); // Filename, empty | Userdefined, Total discs
173 // year
174 AddSortMethod(SortByYear, 562, LABEL_MASKS("%F", "", strAlbum, "%Y")); // Filename, empty | Userdefined, Year
175 // original release year
176 if (!CServiceBroker::GetSettingsComponent()->GetSettings()->GetBool(
177 CSettings::SETTING_MUSICLIBRARY_USEORIGINALDATE))
178 AddSortMethod(
179 SortByOrigDate, sortAttribute, 38079,
180 LABEL_MASKS("%F", "", strAlbum, "%e")); // Filename, empty | Userdefined, Original date
181 // album date added
182 AddSortMethod(SortByDateAdded, sortAttribute, 570, LABEL_MASKS("%F", "", strAlbum, "%a")); // Filename, empty | Userdefined, dateAdded
183 // play count
184 AddSortMethod(SortByPlaycount, 567, LABEL_MASKS("%F", "", strAlbum, "%V")); // Filename, empty | Userdefined, Play count
185 // last played
186 AddSortMethod(SortByLastPlayed, 568, LABEL_MASKS("%F", "", strAlbum, "%p")); // Filename, empty | Userdefined, last played
187 // rating
188 AddSortMethod(SortByRating, 563, LABEL_MASKS("%F", "", strAlbum, "%R")); // Filename, empty | Userdefined, Rating
189 // userrating
190 AddSortMethod(SortByUserRating, 38018, LABEL_MASKS("%F", "", strAlbum, "%r")); // Filename, empty | Userdefined, UserRating
192 const CViewState *viewState = CViewStateSettings::GetInstance().Get("musicnavalbums");
193 SetSortMethod(viewState->m_sortDescription);
194 SetViewAsControl(viewState->m_viewMode);
195 SetSortOrder(viewState->m_sortDescription.sortOrder);
197 break;
198 case NODE_TYPE_ALBUM_RECENTLY_ADDED:
200 AddSortMethod(SortByNone, 552, LABEL_MASKS("%F", "", strAlbum, "%a")); // Filename, empty | Userdefined, dateAdded
201 SetSortMethod(SortByNone);
203 SetViewAsControl(CViewStateSettings::GetInstance().Get("musicnavalbums")->m_viewMode);
205 SetSortOrder(SortOrderNone);
207 break;
208 case NODE_TYPE_ALBUM_RECENTLY_ADDED_SONGS:
210 AddSortMethod(SortByNone, 552, LABEL_MASKS(strTrack, "%a")); // Userdefined, dateAdded | empty, empty
211 SetSortMethod(SortByNone);
213 SetViewAsControl(CViewStateSettings::GetInstance().Get("musicnavsongs")->m_viewMode);
215 SetSortOrder(SortOrderNone);
217 break;
218 case NODE_TYPE_ALBUM_RECENTLY_PLAYED:
220 AddSortMethod(SortByLastPlayed, 568, LABEL_MASKS("%F", "", strAlbum, "%p")); // Filename, empty | Userdefined, last played
222 SetViewAsControl(CViewStateSettings::GetInstance().Get("musicnavalbums")->m_viewMode);
224 break;
225 case NODE_TYPE_ALBUM_RECENTLY_PLAYED_SONGS:
227 AddSortMethod(SortByLastPlayed, 568, LABEL_MASKS(strTrack, "%p")); // Userdefined, last played | empty, empty
229 SetViewAsControl(CViewStateSettings::GetInstance().Get("musicnavalbums")->m_viewMode);
231 break;
232 case NODE_TYPE_ALBUM_TOP100:
234 AddSortMethod(SortByNone, 551, LABEL_MASKS("%F", "", strAlbum, "%V")); // Filename, empty | Userdefined, Play count
235 SetSortMethod(SortByNone);
237 SetViewAsControl(DEFAULT_VIEW_LIST);
238 SetSortOrder(SortOrderNone);
240 break;
241 case NODE_TYPE_SINGLES:
243 AddSortMethod(SortByArtist, sortAttribute, 557, LABEL_MASKS("%A - %T", "%D")); // Artist, Title, Duration| empty, empty
244 AddSortMethod(SortByArtistThenYear, sortAttribute, 578, LABEL_MASKS("%A - %T", "%Y")); // Artist, Title, Year| empty, empty
245 AddSortMethod(SortByTitle, sortAttribute, 556, LABEL_MASKS("%T - %A", "%D")); // Title, Artist, Duration| empty, empty
246 AddSortMethod(SortByLabel, sortAttribute, 551, LABEL_MASKS(strTrack, "%D"));
247 AddSortMethod(SortByTime, 180, LABEL_MASKS("%T - %A", "%D")); // Title, Artist, Duration| empty, empty
248 AddSortMethod(SortByRating, 563, LABEL_MASKS("%T - %A", "%R")); // Title - Artist, Rating
249 AddSortMethod(SortByUserRating, 38018, LABEL_MASKS("%T - %A", "%r")); // Title - Artist, UserRating
250 AddSortMethod(SortByYear, 562, LABEL_MASKS("%T - %A", "%Y")); // Title, Artist, Year
251 // original release date (singles can be re-released)
252 if (!CServiceBroker::GetSettingsComponent()->GetSettings()->GetBool(
253 CSettings::SETTING_MUSICLIBRARY_USEORIGINALDATE))
254 AddSortMethod(SortByOrigDate, 38079,
255 LABEL_MASKS("%T - %A", "%e")); // Title, Artist, Original Date
256 AddSortMethod(SortByDateAdded, 570,
257 LABEL_MASKS("%T - %A", "%a")); // Title - Artist, DateAdded | empty, empty
258 AddSortMethod(SortByPlaycount, 567, LABEL_MASKS("%T - %A", "%V")); // Title - Artist, PlayCount
259 AddSortMethod(SortByLastPlayed, 568, LABEL_MASKS(strTrack, "%p")); // Userdefined, last played | empty, empty
261 const CViewState *viewState = CViewStateSettings::GetInstance().Get("musicnavsongs");
262 SetSortMethod(viewState->m_sortDescription);
263 SetViewAsControl(viewState->m_viewMode);
264 SetSortOrder(viewState->m_sortDescription.sortOrder);
266 break;
267 case NODE_TYPE_ALBUM_TOP100_SONGS:
268 case NODE_TYPE_SONG:
270 AddSortMethod(SortByTrackNumber, 554, LABEL_MASKS(strTrack, "%D")); // Userdefined, Duration| empty, empty
271 AddSortMethod(SortByTitle, sortAttribute, 556, LABEL_MASKS("%T - %A", "%D")); // Title, Artist, Duration| empty, empty
272 AddSortMethod(SortByAlbum, sortAttribute, 558, LABEL_MASKS("%B - %T - %A", "%D")); // Album, Title, Artist, Duration| empty, empty
273 AddSortMethod(SortByArtist, sortAttribute, 557, LABEL_MASKS("%A - %T", "%D")); // Artist, Title, Duration| empty, empty
274 AddSortMethod(SortByArtistThenYear, sortAttribute, 578, LABEL_MASKS("%A - %T", "%Y")); // Artist, Title, Year| empty, empty
275 AddSortMethod(SortByLabel, sortAttribute, 551, LABEL_MASKS(strTrack, "%D"));
276 AddSortMethod(SortByTime, 180, LABEL_MASKS("%T - %A", "%D")); // Title, Artist, Duration| empty, empty
277 AddSortMethod(SortByRating, 563, LABEL_MASKS("%T - %A", "%R")); // Title - Artist, Rating
278 AddSortMethod(SortByUserRating, 38018, LABEL_MASKS("%T - %A", "%r")); // Title - Artist, UserRating
279 AddSortMethod(SortByYear, 562, LABEL_MASKS("%T - %A", "%Y")); // Title, Artist, Year
280 // original release date
281 if (!CServiceBroker::GetSettingsComponent()->GetSettings()->GetBool(
282 CSettings::SETTING_MUSICLIBRARY_USEORIGINALDATE))
283 AddSortMethod(SortByOrigDate, 38079,
284 LABEL_MASKS("%T - %A", "%e")); // Title, Artist, Original Date
285 AddSortMethod(SortByDateAdded, 570, LABEL_MASKS("%T - %A", "%a")); // Title - Artist, DateAdded | empty, empty
286 AddSortMethod(SortByPlaycount, 567, LABEL_MASKS("%T - %A", "%V")); // Title - Artist, PlayCount
287 AddSortMethod(SortByLastPlayed, 568, LABEL_MASKS(strTrack, "%p")); // Userdefined, last played | empty, empty
288 AddSortMethod(SortByBPM, 38080, LABEL_MASKS(strTrack, "%f")); // Userdefined, bpm, empty,empty
290 const CViewState *viewState = CViewStateSettings::GetInstance().Get("musicnavsongs");
291 // the "All Albums" entries always default to SortByAlbum as this is most logical - user can always
292 // change it and the change will be saved for this particular path
293 if (dir.IsAllItem(items.GetPath()))
294 SetSortMethod(SortByAlbum);
295 else
296 SetSortMethod(viewState->m_sortDescription);
298 SetViewAsControl(viewState->m_viewMode);
299 SetSortOrder(viewState->m_sortDescription.sortOrder);
301 break;
302 case NODE_TYPE_SONG_TOP100:
304 AddSortMethod(SortByNone, 576, LABEL_MASKS("%T - %A", "%V"));
305 SetSortMethod(SortByPlaycount);
307 SetViewAsControl(CViewStateSettings::GetInstance().Get("musicnavsongs")->m_viewMode);
309 SetSortOrder(SortOrderNone);
311 break;
312 case NODE_TYPE_DISC:
314 AddSortMethod(SortByNone, 427, LABEL_MASKS("%L")); // Use the existing label
315 SetSortMethod(SortByNone);
317 break;
318 default:
319 break;
322 LoadViewState(items.GetPath(), WINDOW_MUSIC_NAV);
325 void CGUIViewStateMusicDatabase::SaveViewState()
327 CMusicDatabaseDirectory dir;
328 NODE_TYPE NodeType=dir.GetDirectoryChildType(m_items.GetPath());
330 switch (NodeType)
332 case NODE_TYPE_ARTIST:
333 SaveViewToDb(m_items.GetPath(), WINDOW_MUSIC_NAV, CViewStateSettings::GetInstance().Get("musicnavartists"));
334 break;
335 case NODE_TYPE_ALBUM:
336 SaveViewToDb(m_items.GetPath(), WINDOW_MUSIC_NAV, CViewStateSettings::GetInstance().Get("musicnavalbums"));
337 break;
338 case NODE_TYPE_SINGLES:
339 case NODE_TYPE_SONG:
340 SaveViewToDb(m_items.GetPath(), WINDOW_MUSIC_NAV, CViewStateSettings::GetInstance().Get("musicnavsongs"));
341 break;
342 default:
343 SaveViewToDb(m_items.GetPath(), WINDOW_MUSIC_NAV);
344 break;
348 CGUIViewStateMusicSmartPlaylist::CGUIViewStateMusicSmartPlaylist(const CFileItemList& items) : CGUIViewStateWindowMusic(items)
350 SortAttribute sortAttribute = SortAttributeNone;
351 const std::shared_ptr<CSettings> settings = CServiceBroker::GetSettingsComponent()->GetSettings();
352 if (settings->GetBool(CSettings::SETTING_FILELISTS_IGNORETHEWHENSORTING))
353 sortAttribute = SortAttributeIgnoreArticle;
354 if (settings->GetBool(CSettings::SETTING_MUSICLIBRARY_USEARTISTSORTNAME))
355 sortAttribute = static_cast<SortAttribute>(sortAttribute | SortAttributeUseArtistSortName);
356 const CViewState *viewState = CViewStateSettings::GetInstance().Get("musicnavsongs");
358 if (items.GetContent() == "songs" || items.GetContent() == "mixed")
360 std::string strTrack=settings->GetString(CSettings::SETTING_MUSICFILES_TRACKFORMAT);
361 AddSortMethod(SortByTrackNumber, 554, LABEL_MASKS(strTrack, "%D")); // Userdefined, Duration| empty, empty
362 AddSortMethod(SortByTitle, sortAttribute, 556, LABEL_MASKS("%T - %A", "%D")); // Title, Artist, Duration| empty, empty
363 AddSortMethod(SortByAlbum, sortAttribute, 558, LABEL_MASKS("%B - %T - %A", "%D")); // Album, Title, Artist, Duration| empty, empty
364 AddSortMethod(SortByArtist, sortAttribute, 557, LABEL_MASKS("%A - %T", "%D")); // Artist, Title, Duration| empty, empty
365 AddSortMethod(SortByArtistThenYear, sortAttribute, 578, LABEL_MASKS("%A - %T", "%Y")); // Artist, Title, Year| empty, empty
366 AddSortMethod(SortByLabel, sortAttribute, 551, LABEL_MASKS(strTrack, "%D"));
367 AddSortMethod(SortByTime, 180, LABEL_MASKS("%T - %A", "%D")); // Title, Artist, Duration| empty, empty
368 AddSortMethod(SortByRating, 563, LABEL_MASKS("%T - %A", "%R")); // Title, Artist, Rating| empty, empty
369 AddSortMethod(SortByUserRating, 38018, LABEL_MASKS("%T - %A", "%r")); // Title - Artist, UserRating
370 AddSortMethod(SortByYear, 562, LABEL_MASKS("%T - %A", "%Y")); // Title, Artist, Year
371 AddSortMethod(SortByDateAdded, 570, LABEL_MASKS("%T - %A", "%a")); // Title - Artist, DateAdded | empty, empty
372 AddSortMethod(SortByPlaycount, 567, LABEL_MASKS("%T - %A", "%V")); // Title - Artist, PlayCount
373 if (!CServiceBroker::GetSettingsComponent()->GetSettings()->GetBool(
374 CSettings::SETTING_MUSICLIBRARY_USEORIGINALDATE))
375 AddSortMethod(SortByOrigDate, 38079,
376 LABEL_MASKS("%T - %A", "%e")); // Title - Artist, original date, empty, empty
377 AddSortMethod(SortByBPM, 38080,
378 LABEL_MASKS("%T - %A", "%f")); // Title - Artist, bpm, empty, empty
380 if (items.IsSmartPlayList() || items.IsLibraryFolder())
381 AddPlaylistOrder(items, LABEL_MASKS(strTrack, "%D"));
382 else
384 SetSortMethod(viewState->m_sortDescription);
385 SetSortOrder(viewState->m_sortDescription.sortOrder);
388 SetViewAsControl(CViewStateSettings::GetInstance().Get("musicnavsongs")->m_viewMode);
390 else if (items.GetContent() == "albums")
392 std::string strAlbum = CServiceBroker::GetSettingsComponent()->GetAdvancedSettings()->m_strMusicLibraryAlbumFormat;
393 if (strAlbum.empty())
394 strAlbum = "%B"; // album
395 // album
396 AddSortMethod(SortByAlbum, sortAttribute, 558, LABEL_MASKS("%F", "", strAlbum, "%A")); // Filename, empty | Userdefined (default=%B), Artist
397 // artist
398 AddSortMethod(SortByArtist, sortAttribute, 557, LABEL_MASKS("%F", "", strAlbum, "%A")); // Filename, empty | Userdefined, Artist
399 // artist / year
400 AddSortMethod(SortByArtistThenYear, sortAttribute, 578, LABEL_MASKS("%F", "", strAlbum, "%A / %Y")); // Filename, empty | Userdefined, Artist / Year
401 // discs
402 AddSortMethod(
403 SortByTotalDiscs, sortAttribute, 38077,
404 LABEL_MASKS("%F", "", strAlbum, "%b")); // Filename, empty | Userdefined, Total discs
405 // year
406 AddSortMethod(SortByYear, 562, LABEL_MASKS("%F", "", strAlbum, "%Y"));
407 // original release date
408 if (!CServiceBroker::GetSettingsComponent()->GetSettings()->GetBool(
409 CSettings::SETTING_MUSICLIBRARY_USEORIGINALDATE))
410 AddSortMethod(
411 SortByOrigDate, 38079,
412 LABEL_MASKS("%F", "", strAlbum, "%e")); // Filename, empty | Userdefined, Original date
413 // album date added
414 AddSortMethod(SortByDateAdded, sortAttribute, 570, LABEL_MASKS("%F", "", strAlbum, "%a")); // Filename, empty | Userdefined, dateAdded
415 // play count
416 AddSortMethod(SortByPlaycount, 567, LABEL_MASKS("%F", "", strAlbum, "%V")); // Filename, empty | Userdefined, Play count
417 // last played
418 AddSortMethod(SortByLastPlayed, 568, LABEL_MASKS("%F", "", strAlbum, "%p")); // Filename, empty | Userdefined, last played
419 // rating
420 AddSortMethod(SortByRating, 563, LABEL_MASKS("%F", "", strAlbum, "%R")); // Filename, empty | Userdefined, Rating
421 // userrating
422 AddSortMethod(SortByUserRating, 38018, LABEL_MASKS("%F", "", strAlbum, "%r")); // Filename, empty | Userdefined, UserRating
424 if (items.IsSmartPlayList() || items.IsLibraryFolder())
425 AddPlaylistOrder(items, LABEL_MASKS("%F", "", strAlbum, "%D"));
426 else
428 SetSortMethod(viewState->m_sortDescription);
429 SetSortOrder(viewState->m_sortDescription.sortOrder);
432 SetViewAsControl(CViewStateSettings::GetInstance().Get("musicnavalbums")->m_viewMode);
434 else
436 CLog::Log(LOGERROR,"Music Smart Playlist must be one of songs, mixed or albums");
439 LoadViewState(items.GetPath(), WINDOW_MUSIC_NAV);
442 void CGUIViewStateMusicSmartPlaylist::SaveViewState()
444 SaveViewToDb(m_items.GetPath(), WINDOW_MUSIC_NAV, CViewStateSettings::GetInstance().Get("musicnavsongs"));
447 CGUIViewStateMusicPlaylist::CGUIViewStateMusicPlaylist(const CFileItemList& items) : CGUIViewStateWindowMusic(items)
449 SortAttribute sortAttribute = SortAttributeNone;
450 const std::shared_ptr<CSettings> settings = CServiceBroker::GetSettingsComponent()->GetSettings();
451 if (settings->GetBool(CSettings::SETTING_FILELISTS_IGNORETHEWHENSORTING))
452 sortAttribute = SortAttributeIgnoreArticle;
453 if (settings->GetBool(CSettings::SETTING_MUSICLIBRARY_USEARTISTSORTNAME))
454 sortAttribute = static_cast<SortAttribute>(sortAttribute | SortAttributeUseArtistSortName);
456 std::string strTrack = settings->GetString(CSettings::SETTING_MUSICFILES_TRACKFORMAT);
457 AddSortMethod(SortByPlaylistOrder, 559, LABEL_MASKS(strTrack, "%D"));
458 AddSortMethod(SortByTrackNumber, 554, LABEL_MASKS(strTrack, "%D")); // Userdefined, Duration| empty, empty
459 AddSortMethod(SortByTitle, sortAttribute, 556, LABEL_MASKS("%T - %A", "%D")); // Title, Artist, Duration| empty, empty
460 AddSortMethod(SortByAlbum, sortAttribute, 558, LABEL_MASKS("%B - %T - %A", "%D")); // Album, Title, Artist, Duration| empty, empty
461 AddSortMethod(SortByArtist, sortAttribute, 557, LABEL_MASKS("%A - %T", "%D")); // Artist, Title, Duration| empty, empty
462 AddSortMethod(SortByArtistThenYear, sortAttribute, 578, LABEL_MASKS("%A - %T", "%Y")); // Artist, Title, Year| empty, empty
463 AddSortMethod(SortByLabel, sortAttribute, 551, LABEL_MASKS(strTrack, "%D"));
464 AddSortMethod(SortByTime, 180, LABEL_MASKS("%T - %A", "%D")); // Title - Artist, Duration| empty, empty
465 AddSortMethod(SortByRating, 563, LABEL_MASKS("%T - %A", "%R")); // Title - Artist, Rating| empty, empty
466 AddSortMethod(SortByUserRating, 38018, LABEL_MASKS("%T - %A", "%r")); // Title - Artist, UserRating
467 SetSortMethod(SortByPlaylistOrder);
468 const CViewState *viewState = CViewStateSettings::GetInstance().Get("musicfiles");
469 SetViewAsControl(viewState->m_viewMode);
470 SetSortOrder(viewState->m_sortDescription.sortOrder);
472 LoadViewState(items.GetPath(), WINDOW_MUSIC_NAV);
475 void CGUIViewStateMusicPlaylist::SaveViewState()
477 SaveViewToDb(m_items.GetPath(), WINDOW_MUSIC_NAV);
480 CGUIViewStateWindowMusicNav::CGUIViewStateWindowMusicNav(const CFileItemList& items) : CGUIViewStateWindowMusic(items)
482 SortAttribute sortAttribute = SortAttributeNone;
483 const std::shared_ptr<CSettings> settings = CServiceBroker::GetSettingsComponent()->GetSettings();
484 if (settings->GetBool(CSettings::SETTING_FILELISTS_IGNORETHEWHENSORTING))
485 sortAttribute = SortAttributeIgnoreArticle;
486 if (settings->GetBool(CSettings::SETTING_MUSICLIBRARY_USEARTISTSORTNAME))
487 sortAttribute = static_cast<SortAttribute>(sortAttribute | SortAttributeUseArtistSortName);
489 if (items.IsVirtualDirectoryRoot())
491 AddSortMethod(SortByNone, 551, LABEL_MASKS("%F", "%I", "%L", "")); // Filename, Size | Foldername, empty
492 SetSortMethod(SortByNone);
494 SetViewAsControl(DEFAULT_VIEW_LIST);
496 SetSortOrder(SortOrderNone);
498 else if (items.GetPath() == "special://musicplaylists/")
499 { // playlists list sorts by label only, ignoring folders
500 AddSortMethod(SortByLabel, SortAttributeIgnoreFolders, 551,
501 LABEL_MASKS("%F", "%D", "%L", "")); // Filename, Duration | Foldername, empty
502 SetSortMethod(SortByLabel);
504 else
506 if (items.IsVideoDb() && items.Size() > (settings->GetBool(CSettings::SETTING_FILELISTS_SHOWPARENTDIRITEMS)?1:0))
508 XFILE::VIDEODATABASEDIRECTORY::CQueryParams params;
509 XFILE::CVideoDatabaseDirectory::GetQueryParams(items[settings->GetBool(CSettings::SETTING_FILELISTS_SHOWPARENTDIRITEMS) ? 1 : 0]->GetPath(), params);
510 if (params.GetMVideoId() != -1)
512 AddSortMethod(SortByLabel, sortAttribute, 551, LABEL_MASKS("%T", "%Y")); // Filename, Duration | Foldername, empty
513 AddSortMethod(SortByYear, 562, LABEL_MASKS("%T", "%Y"));
514 AddSortMethod(SortByArtist, sortAttribute, 557, LABEL_MASKS("%A - %T", "%Y"));
515 AddSortMethod(SortByArtistThenYear, sortAttribute, 578, LABEL_MASKS("%A - %T", "%Y"));
516 AddSortMethod(SortByAlbum, sortAttribute, 558, LABEL_MASKS("%B - %T", "%Y"));
518 std::string strTrack = settings->GetString(CSettings::SETTING_MUSICFILES_TRACKFORMAT);
519 AddSortMethod(SortByTrackNumber, 554, LABEL_MASKS(strTrack, "%D")); // Userdefined, Duration| empty, empty
521 else
523 AddSortMethod(SortByLabel, 551, LABEL_MASKS("%F", "%D", "%L", "")); // Filename, Duration | Foldername, empty
524 SetSortMethod(SortByLabel);
527 else
529 //In navigation of music files tag data is scanned whenever present and can be used as sort criteria
530 //hence sort methods available are similar to song node (not the same as only tag data)
531 //Unfortunately anything here appears at all levels of file navigation even if no song files there.
532 std::string strTrack = settings->GetString(CSettings::SETTING_MUSICFILES_LIBRARYTRACKFORMAT);
533 if (strTrack.empty())
534 strTrack = settings->GetString(CSettings::SETTING_MUSICFILES_TRACKFORMAT);
535 AddSortMethod(SortByLabel, 551, LABEL_MASKS(strTrack, "%D", "%L", ""), // Userdefined, Duration | FolderName, empty
536 settings->GetBool(CSettings::SETTING_FILELISTS_IGNORETHEWHENSORTING) ? SortAttributeIgnoreArticle : SortAttributeNone);
537 AddSortMethod(SortBySize, 553, LABEL_MASKS("%F", "%I", "%L", "%I")); // Filename, Size | Foldername, Size
538 AddSortMethod(SortByDate, 552, LABEL_MASKS("%F", "%J", "%L", "%J")); // Filename, Date | Foldername, Date
539 AddSortMethod(SortByFile, 561, LABEL_MASKS("%F", "%I", "%L", "")); // Filename, Size | Label, empty
540 AddSortMethod(SortByTrackNumber, 554, LABEL_MASKS(strTrack, "%D")); // Userdefined, Duration| empty, empty
541 AddSortMethod(SortByTitle, sortAttribute, 556, LABEL_MASKS("%T - %A", "%D")); // Title, Artist, Duration| empty, empty
542 AddSortMethod(SortByAlbum, sortAttribute, 558, LABEL_MASKS("%B - %T - %A", "%D")); // Album, Title, Artist, Duration| empty, empty
543 AddSortMethod(SortByArtist, sortAttribute, 557, LABEL_MASKS("%A - %T", "%D")); // Artist, Title, Duration| empty, empty
544 AddSortMethod(SortByArtistThenYear, sortAttribute, 578, LABEL_MASKS("%A - %T", "%Y")); // Artist(year), Title, Year| empty, empty
545 AddSortMethod(SortByTime, 180, LABEL_MASKS("%T - %A", "%D")); // Title, Artist, Duration| empty, empty
546 AddSortMethod(SortByYear, 562, LABEL_MASKS("%T - %A", "%Y")); // Title, Artist, Year
548 SetSortMethod(SortByLabel);
550 const CViewState *viewState = CViewStateSettings::GetInstance().Get("musicnavsongs");
551 SetViewAsControl(viewState->m_viewMode);
552 SetSortOrder(viewState->m_sortDescription.sortOrder);
554 SetSortOrder(SortOrderAscending);
556 LoadViewState(items.GetPath(), WINDOW_MUSIC_NAV);
559 void CGUIViewStateWindowMusicNav::SaveViewState()
561 SaveViewToDb(m_items.GetPath(), WINDOW_MUSIC_NAV);
564 void CGUIViewStateWindowMusicNav::AddOnlineShares()
566 if (!CServiceBroker::GetSettingsComponent()->GetAdvancedSettings()->m_bVirtualShares)
567 return;
569 VECSOURCES *musicSources = CMediaSourceSettings::GetInstance().GetSources("music");
571 for (int i = 0; i < (int)musicSources->size(); ++i)
573 CMediaSource share = musicSources->at(i);
577 VECSOURCES& CGUIViewStateWindowMusicNav::GetSources()
579 // Setup shares we want to have
580 m_sources.clear();
581 CFileItemList items;
583 CDirectory::GetDirectory("library://music/", items, "", DIR_FLAG_DEFAULTS);
584 for (int i=0; i<items.Size(); ++i)
586 CFileItemPtr item=items[i];
587 CMediaSource share;
588 share.strName = item->GetLabel();
589 share.strPath = item->GetPath();
590 share.m_strThumbnailImage = item->GetArt("icon");
591 share.m_iDriveType = CMediaSource::SOURCE_TYPE_LOCAL;
592 m_sources.push_back(share);
595 AddOnlineShares();
597 return CGUIViewStateWindowMusic::GetSources();
600 CGUIViewStateWindowMusicPlaylist::CGUIViewStateWindowMusicPlaylist(const CFileItemList& items) : CGUIViewStateWindowMusic(items)
602 const std::shared_ptr<CSettings> settings = CServiceBroker::GetSettingsComponent()->GetSettings();
603 std::string strTrack = settings->GetString(CSettings::SETTING_MUSICFILES_NOWPLAYINGTRACKFORMAT);
604 if (strTrack.empty())
605 strTrack = settings->GetString(CSettings::SETTING_MUSICFILES_TRACKFORMAT);
607 AddSortMethod(SortByNone, 551, LABEL_MASKS(strTrack, "%D", "%L", "")); // Userdefined, Duration | FolderName, empty
608 SetSortMethod(SortByNone);
610 SetViewAsControl(DEFAULT_VIEW_LIST);
612 SetSortOrder(SortOrderNone);
614 LoadViewState(items.GetPath(), WINDOW_MUSIC_PLAYLIST);
617 void CGUIViewStateWindowMusicPlaylist::SaveViewState()
619 SaveViewToDb(m_items.GetPath(), WINDOW_MUSIC_PLAYLIST);
622 PLAYLIST::Id CGUIViewStateWindowMusicPlaylist::GetPlaylist() const
624 return PLAYLIST::TYPE_MUSIC;
627 bool CGUIViewStateWindowMusicPlaylist::AutoPlayNextItem()
629 return false;
632 bool CGUIViewStateWindowMusicPlaylist::HideParentDirItems()
634 return true;
637 VECSOURCES& CGUIViewStateWindowMusicPlaylist::GetSources()
639 m_sources.clear();
640 // Playlist share
641 CMediaSource share;
642 share.strPath = "playlistmusic://";
643 share.m_iDriveType = CMediaSource::SOURCE_TYPE_LOCAL;
644 m_sources.push_back(share);
646 // CGUIViewState::GetSources would add music plugins
647 return m_sources;