1 /*
2 * Copyright (C) 2005-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 "GUIViewStateMusic.h"
10
11 #include "FileItem.h"
12 #include "PlayListPlayer.h"
13 #include "ServiceBroker.h"
14 #include "filesystem/Directory.h"
15 #include "filesystem/MusicDatabaseDirectory.h"
16 #include "filesystem/VideoDatabaseDirectory.h"
17 #include "guilib/LocalizeStrings.h"
18 #include "guilib/WindowIDs.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"
27
28 using namespace XFILE;
29 using namespace MUSICDATABASEDIRECTORY;
30
GetPlaylist() const31 int CGUIViewStateWindowMusic::GetPlaylist() const
32 {
33 //return PLAYLIST_MUSIC_TEMP;
34 return PLAYLIST_MUSIC;
35 }
36
AutoPlayNextItem()37 bool CGUIViewStateWindowMusic::AutoPlayNextItem()
38 {
39 const std::shared_ptr<CSettings> settings = CServiceBroker::GetSettingsComponent()->GetSettings();
40 return settings->GetBool(CSettings::SETTING_MUSICPLAYER_AUTOPLAYNEXTITEM) &&
41 !settings->GetBool(CSettings::SETTING_MUSICPLAYER_QUEUEBYDEFAULT);
42 }
43
GetLockType()44 std::string CGUIViewStateWindowMusic::GetLockType()
45 {
46 return "music";
47 }
48
GetExtensions()49 std::string CGUIViewStateWindowMusic::GetExtensions()
50 {
51 return CServiceBroker::GetFileExtensionProvider().GetMusicExtensions();
52 }
53
GetSources()54 VECSOURCES& CGUIViewStateWindowMusic::GetSources()
55 {
56 return CGUIViewState::GetSources();
57 }
58
CGUIViewStateMusicSearch(const CFileItemList & items)59 CGUIViewStateMusicSearch::CGUIViewStateMusicSearch(const CFileItemList& items) : CGUIViewStateWindowMusic(items)
60 {
61 SortAttribute sortAttribute = SortAttributeNone;
62 if (CServiceBroker::GetSettingsComponent()->GetSettings()->GetBool(CSettings::SETTING_FILELISTS_IGNORETHEWHENSORTING))
63 sortAttribute = SortAttributeIgnoreArticle;
64
65 AddSortMethod(SortByTitle, sortAttribute, 556, LABEL_MASKS("%T - %A", "%D", "%L", "%A")); // Title - Artist, Duration | Label, Artist
66 SetSortMethod(SortByTitle);
67
68 const CViewState *viewState = CViewStateSettings::GetInstance().Get("musicnavsongs");
69 SetViewAsControl(viewState->m_viewMode);
70 SetSortOrder(viewState->m_sortDescription.sortOrder);
71
72 LoadViewState(items.GetPath(), WINDOW_MUSIC_NAV);
73 }
74
SaveViewState()75 void CGUIViewStateMusicSearch::SaveViewState()
76 {
77 SaveViewToDb(m_items.GetPath(), WINDOW_MUSIC_NAV, CViewStateSettings::GetInstance().Get("musicnavsongs"));
78 }
79
CGUIViewStateMusicDatabase(const CFileItemList & items)80 CGUIViewStateMusicDatabase::CGUIViewStateMusicDatabase(const CFileItemList& items) : CGUIViewStateWindowMusic(items)
81 {
82 CMusicDatabaseDirectory dir;
83 NODE_TYPE NodeType=dir.GetDirectoryChildType(items.GetPath());
84
85 const std::shared_ptr<CSettings> settings = CServiceBroker::GetSettingsComponent()->GetSettings();
86 std::string strTrack = settings->GetString(CSettings::SETTING_MUSICFILES_LIBRARYTRACKFORMAT);
87 if (strTrack.empty())
88 strTrack = settings->GetString(CSettings::SETTING_MUSICFILES_TRACKFORMAT);
89 std::string strAlbum = CServiceBroker::GetSettingsComponent()->GetAdvancedSettings()->m_strMusicLibraryAlbumFormat;
90 if (strAlbum.empty())
91 strAlbum = "%B"; // album
92 CLog::Log(LOGDEBUG,"Custom album format = [%s]", strAlbum.c_str());
93 SortAttribute sortAttribute = SortAttributeNone;
94 if (settings->GetBool(CSettings::SETTING_FILELISTS_IGNORETHEWHENSORTING))
95 sortAttribute = SortAttributeIgnoreArticle;
96 if (settings->GetBool(CSettings::SETTING_MUSICLIBRARY_USEARTISTSORTNAME))
97 sortAttribute = static_cast<SortAttribute>(sortAttribute | SortAttributeUseArtistSortName);
98
99 switch (NodeType)
100 {
101 case NODE_TYPE_OVERVIEW:
102 {
103 AddSortMethod(SortByNone, 551, LABEL_MASKS("%F", "", "%L", "")); // Filename, empty | Foldername, empty
104 SetSortMethod(SortByNone);
105
106 SetViewAsControl(DEFAULT_VIEW_LIST);
107
108 SetSortOrder(SortOrderNone);
109 }
110 break;
111 case NODE_TYPE_TOP100:
112 {
113 AddSortMethod(SortByNone, 551, LABEL_MASKS("%F", "", "%L", "")); // Filename, empty | Foldername, empty
114 SetSortMethod(SortByNone);
115
116 SetViewAsControl(DEFAULT_VIEW_LIST);
117
118 SetSortOrder(SortOrderNone);
119 }
120 break;
121 case NODE_TYPE_GENRE:
122 {
123 AddSortMethod(SortByGenre, 515, LABEL_MASKS("%F", "", "%G", "")); // Filename, empty | Genre, empty
124 SetSortMethod(SortByGenre);
125
126 SetViewAsControl(DEFAULT_VIEW_LIST);
127
128 SetSortOrder(SortOrderAscending);
129 }
130 break;
131 case NODE_TYPE_ROLE:
132 {
133 AddSortMethod(SortByNone, 576, LABEL_MASKS("%F", "", "%G", "")); // Filename, empty | Genre, empty
134 SetSortMethod(SortByPlaycount);
135
136 SetViewAsControl(DEFAULT_VIEW_LIST);
137
138 SetSortOrder(SortOrderNone);
139 }
140 break;
141 case NODE_TYPE_YEAR:
142 {
143 AddSortMethod(SortByLabel, 562, LABEL_MASKS("%F", "", "%Y", "")); // Filename, empty | Year, empty
144 SetSortMethod(SortByLabel);
145
146 SetViewAsControl(DEFAULT_VIEW_LIST);
147
148 SetSortOrder(SortOrderAscending);
149 }
150 break;
151 case NODE_TYPE_ARTIST:
152 {
153 AddSortMethod(SortByArtist, sortAttribute, 557, LABEL_MASKS("%F", "", "%A", "")); // Filename, empty | Artist, empty
154 AddSortMethod(SortByDateAdded, sortAttribute, 570, LABEL_MASKS("%F", "", "%A", "%a")); // Filename, empty | Artist, dateAdded
155 SetSortMethod(SortByArtist);
156
157 const CViewState *viewState = CViewStateSettings::GetInstance().Get("musicnavartists");
158 SetViewAsControl(viewState->m_viewMode);
159 SetSortOrder(viewState->m_sortDescription.sortOrder);
160 }
161 break;
162 case NODE_TYPE_ALBUM:
163 {
164 // album
165 AddSortMethod(SortByAlbum, sortAttribute, 558, LABEL_MASKS("%F", "", strAlbum, "%A")); // Filename, empty | Userdefined (default=%B), Artist
166 // artist
167 AddSortMethod(SortByArtist, sortAttribute, 557, LABEL_MASKS("%F", "", strAlbum, "%A")); // Filename, empty | Userdefined, Artist
168 // artist / year
169 AddSortMethod(SortByArtistThenYear, sortAttribute, 578, LABEL_MASKS("%F", "", strAlbum, "%A / %Y")); // Filename, empty | Userdefined, Artist / Year
170 // discs
171 AddSortMethod(
172 SortByTotalDiscs, sortAttribute, 38077,
173 LABEL_MASKS("%F", "", strAlbum, "%b")); // Filename, empty | Userdefined, Total discs
174 // year
175 AddSortMethod(SortByYear, 562, LABEL_MASKS("%F", "", strAlbum, "%Y")); // Filename, empty | Userdefined, Year
176 // original release year
177 if (!CServiceBroker::GetSettingsComponent()->GetSettings()->GetBool(
178 CSettings::SETTING_MUSICLIBRARY_USEORIGINALDATE))
179 AddSortMethod(
180 SortByOrigDate, sortAttribute, 38079,
181 LABEL_MASKS("%F", "", strAlbum, "%e")); // Filename, empty | Userdefined, Original date
182 // album date added
183 AddSortMethod(SortByDateAdded, sortAttribute, 570, LABEL_MASKS("%F", "", strAlbum, "%a")); // Filename, empty | Userdefined, dateAdded
184 // play count
185 AddSortMethod(SortByPlaycount, 567, LABEL_MASKS("%F", "", strAlbum, "%V")); // Filename, empty | Userdefined, Play count
186 // last played
187 AddSortMethod(SortByLastPlayed, 568, LABEL_MASKS("%F", "", strAlbum, "%p")); // Filename, empty | Userdefined, last played
188 // rating
189 AddSortMethod(SortByRating, 563, LABEL_MASKS("%F", "", strAlbum, "%R")); // Filename, empty | Userdefined, Rating
190 // userrating
191 AddSortMethod(SortByUserRating, 38018, LABEL_MASKS("%F", "", strAlbum, "%r")); // Filename, empty | Userdefined, UserRating
192
193 const CViewState *viewState = CViewStateSettings::GetInstance().Get("musicnavalbums");
194 SetSortMethod(viewState->m_sortDescription);
195 SetViewAsControl(viewState->m_viewMode);
196 SetSortOrder(viewState->m_sortDescription.sortOrder);
197 }
198 break;
199 case NODE_TYPE_ALBUM_RECENTLY_ADDED:
200 {
201 AddSortMethod(SortByNone, 552, LABEL_MASKS("%F", "", strAlbum, "%a")); // Filename, empty | Userdefined, dateAdded
202 SetSortMethod(SortByNone);
203
204 SetViewAsControl(CViewStateSettings::GetInstance().Get("musicnavalbums")->m_viewMode);
205
206 SetSortOrder(SortOrderNone);
207 }
208 break;
209 case NODE_TYPE_ALBUM_RECENTLY_ADDED_SONGS:
210 {
211 AddSortMethod(SortByNone, 552, LABEL_MASKS(strTrack, "%a")); // Userdefined, dateAdded | empty, empty
212 SetSortMethod(SortByNone);
213
214 SetViewAsControl(CViewStateSettings::GetInstance().Get("musicnavsongs")->m_viewMode);
215
216 SetSortOrder(SortOrderNone);
217 }
218 break;
219 case NODE_TYPE_ALBUM_RECENTLY_PLAYED:
220 {
221 AddSortMethod(SortByLastPlayed, 568, LABEL_MASKS("%F", "", strAlbum, "%p")); // Filename, empty | Userdefined, last played
222
223 SetViewAsControl(CViewStateSettings::GetInstance().Get("musicnavalbums")->m_viewMode);
224 }
225 break;
226 case NODE_TYPE_ALBUM_RECENTLY_PLAYED_SONGS:
227 {
228 AddSortMethod(SortByLastPlayed, 568, LABEL_MASKS(strTrack, "%p")); // Userdefined, last played | empty, empty
229
230 SetViewAsControl(CViewStateSettings::GetInstance().Get("musicnavalbums")->m_viewMode);
231 }
232 break;
233 case NODE_TYPE_ALBUM_TOP100:
234 {
235 AddSortMethod(SortByNone, 551, LABEL_MASKS("%F", "", strAlbum, "%V")); // Filename, empty | Userdefined, Play count
236 SetSortMethod(SortByNone);
237
238 SetViewAsControl(DEFAULT_VIEW_LIST);
239 SetSortOrder(SortOrderNone);
240 }
241 break;
242 case NODE_TYPE_SINGLES:
243 {
244 AddSortMethod(SortByArtist, sortAttribute, 557, LABEL_MASKS("%A - %T", "%D")); // Artist, Title, Duration| empty, empty
245 AddSortMethod(SortByArtistThenYear, sortAttribute, 578, LABEL_MASKS("%A - %T", "%Y")); // Artist, Title, Year| empty, empty
246 AddSortMethod(SortByTitle, sortAttribute, 556, LABEL_MASKS("%T - %A", "%D")); // Title, Artist, Duration| empty, empty
247 AddSortMethod(SortByLabel, sortAttribute, 551, LABEL_MASKS(strTrack, "%D"));
248 AddSortMethod(SortByTime, 180, LABEL_MASKS("%T - %A", "%D")); // Titel, Artist, Duration| empty, empty
249 AddSortMethod(SortByRating, 563, LABEL_MASKS("%T - %A", "%R")); // Title - Artist, Rating
250 AddSortMethod(SortByUserRating, 38018, LABEL_MASKS("%T - %A", "%r")); // Title - Artist, UserRating
251 AddSortMethod(SortByYear, 562, LABEL_MASKS("%T - %A", "%Y")); // Title, Artist, Year
252 // original release date (singles can be re-released)
253 if (!CServiceBroker::GetSettingsComponent()->GetSettings()->GetBool(
254 CSettings::SETTING_MUSICLIBRARY_USEORIGINALDATE))
255 AddSortMethod(SortByOrigDate, 38079,
256 LABEL_MASKS("%T - %A", "%e")); // Title, Artist, Original Date
257 AddSortMethod(SortByDateAdded, 570,
258 LABEL_MASKS("%T - %A", "%a")); // Title - Artist, DateAdded | empty, empty
259 AddSortMethod(SortByPlaycount, 567, LABEL_MASKS("%T - %A", "%V")); // Title - Artist, PlayCount
260 AddSortMethod(SortByLastPlayed, 568, LABEL_MASKS(strTrack, "%p")); // Userdefined, last played | empty, empty
261
262 const CViewState *viewState = CViewStateSettings::GetInstance().Get("musicnavsongs");
263 SetSortMethod(viewState->m_sortDescription);
264 SetViewAsControl(viewState->m_viewMode);
265 SetSortOrder(viewState->m_sortDescription.sortOrder);
266 }
267 break;
268 case NODE_TYPE_ALBUM_TOP100_SONGS:
269 case NODE_TYPE_SONG:
270 {
271 AddSortMethod(SortByTrackNumber, 554, LABEL_MASKS(strTrack, "%D")); // Userdefined, Duration| empty, empty
272 AddSortMethod(SortByTitle, sortAttribute, 556, LABEL_MASKS("%T - %A", "%D")); // Title, Artist, Duration| empty, empty
273 AddSortMethod(SortByAlbum, sortAttribute, 558, LABEL_MASKS("%B - %T - %A", "%D")); // Album, Title, Artist, Duration| empty, empty
274 AddSortMethod(SortByArtist, sortAttribute, 557, LABEL_MASKS("%A - %T", "%D")); // Artist, Title, Duration| empty, empty
275 AddSortMethod(SortByArtistThenYear, sortAttribute, 578, LABEL_MASKS("%A - %T", "%Y")); // Artist, Title, Year| empty, empty
276 AddSortMethod(SortByLabel, sortAttribute, 551, LABEL_MASKS(strTrack, "%D"));
277 AddSortMethod(SortByTime, 180, LABEL_MASKS("%T - %A", "%D")); // Titel, Artist, Duration| empty, empty
278 AddSortMethod(SortByRating, 563, LABEL_MASKS("%T - %A", "%R")); // Title - Artist, Rating
279 AddSortMethod(SortByUserRating, 38018, LABEL_MASKS("%T - %A", "%r")); // Title - Artist, UserRating
280 AddSortMethod(SortByYear, 562, LABEL_MASKS("%T - %A", "%Y")); // Title, Artist, Year
281 // original release date
282 if (!CServiceBroker::GetSettingsComponent()->GetSettings()->GetBool(
283 CSettings::SETTING_MUSICLIBRARY_USEORIGINALDATE))
284 AddSortMethod(SortByOrigDate, 38079,
285 LABEL_MASKS("%T - %A", "%e")); // Title, Artist, Original Date
286 AddSortMethod(SortByDateAdded, 570, LABEL_MASKS("%T - %A", "%a")); // Title - Artist, DateAdded | empty, empty
287 AddSortMethod(SortByPlaycount, 567, LABEL_MASKS("%T - %A", "%V")); // Title - Artist, PlayCount
288 AddSortMethod(SortByLastPlayed, 568, LABEL_MASKS(strTrack, "%p")); // Userdefined, last played | empty, empty
289 AddSortMethod(SortByBPM, 38080, LABEL_MASKS(strTrack, "%f")); // Userdefined, bpm, empty,empty
290
291 const CViewState *viewState = CViewStateSettings::GetInstance().Get("musicnavsongs");
292 // the "All Albums" entries always default to SortByAlbum as this is most logical - user can always
293 // change it and the change will be saved for this particular path
294 if (dir.IsAllItem(items.GetPath()))
295 SetSortMethod(SortByAlbum);
296 else
297 SetSortMethod(viewState->m_sortDescription);
298
299 SetViewAsControl(viewState->m_viewMode);
300 SetSortOrder(viewState->m_sortDescription.sortOrder);
301 }
302 break;
303 case NODE_TYPE_SONG_TOP100:
304 {
305 AddSortMethod(SortByNone, 576, LABEL_MASKS("%T - %A", "%V"));
306 SetSortMethod(SortByPlaycount);
307
308 SetViewAsControl(CViewStateSettings::GetInstance().Get("musicnavsongs")->m_viewMode);
309
310 SetSortOrder(SortOrderNone);
311 }
312 break;
313 case NODE_TYPE_DISC:
314 {
315 AddSortMethod(SortByNone, 427, LABEL_MASKS("%L")); // Use the existing label
316 SetSortMethod(SortByNone);
317 }
318 break;
319 default:
320 break;
321 }
322
323 LoadViewState(items.GetPath(), WINDOW_MUSIC_NAV);
324 }
325
SaveViewState()326 void CGUIViewStateMusicDatabase::SaveViewState()
327 {
328 CMusicDatabaseDirectory dir;
329 NODE_TYPE NodeType=dir.GetDirectoryChildType(m_items.GetPath());
330
331 switch (NodeType)
332 {
333 case NODE_TYPE_ARTIST:
334 SaveViewToDb(m_items.GetPath(), WINDOW_MUSIC_NAV, CViewStateSettings::GetInstance().Get("musicnavartists"));
335 break;
336 case NODE_TYPE_ALBUM:
337 SaveViewToDb(m_items.GetPath(), WINDOW_MUSIC_NAV, CViewStateSettings::GetInstance().Get("musicnavalbums"));
338 break;
339 case NODE_TYPE_SINGLES:
340 case NODE_TYPE_SONG:
341 SaveViewToDb(m_items.GetPath(), WINDOW_MUSIC_NAV, CViewStateSettings::GetInstance().Get("musicnavsongs"));
342 break;
343 default:
344 SaveViewToDb(m_items.GetPath(), WINDOW_MUSIC_NAV);
345 break;
346 }
347 }
348
CGUIViewStateMusicSmartPlaylist(const CFileItemList & items)349 CGUIViewStateMusicSmartPlaylist::CGUIViewStateMusicSmartPlaylist(const CFileItemList& items) : CGUIViewStateWindowMusic(items)
350 {
351 SortAttribute sortAttribute = SortAttributeNone;
352 const std::shared_ptr<CSettings> settings = CServiceBroker::GetSettingsComponent()->GetSettings();
353 if (settings->GetBool(CSettings::SETTING_FILELISTS_IGNORETHEWHENSORTING))
354 sortAttribute = SortAttributeIgnoreArticle;
355 if (settings->GetBool(CSettings::SETTING_MUSICLIBRARY_USEARTISTSORTNAME))
356 sortAttribute = static_cast<SortAttribute>(sortAttribute | SortAttributeUseArtistSortName);
357 const CViewState *viewState = CViewStateSettings::GetInstance().Get("musicnavsongs");
358
359 if (items.GetContent() == "songs" || items.GetContent() == "mixed")
360 {
361 std::string strTrack=settings->GetString(CSettings::SETTING_MUSICFILES_TRACKFORMAT);
362 AddSortMethod(SortByTrackNumber, 554, LABEL_MASKS(strTrack, "%D")); // Userdefined, Duration| empty, empty
363 AddSortMethod(SortByTitle, sortAttribute, 556, LABEL_MASKS("%T - %A", "%D")); // Title, Artist, Duration| empty, empty
364 AddSortMethod(SortByAlbum, sortAttribute, 558, LABEL_MASKS("%B - %T - %A", "%D")); // Album, Titel, Artist, Duration| empty, empty
365 AddSortMethod(SortByArtist, sortAttribute, 557, LABEL_MASKS("%A - %T", "%D")); // Artist, Titel, Duration| empty, empty
366 AddSortMethod(SortByArtistThenYear, sortAttribute, 578, LABEL_MASKS("%A - %T", "%Y")); // Artist, Titel, Year| empty, empty
367 AddSortMethod(SortByLabel, sortAttribute, 551, LABEL_MASKS(strTrack, "%D"));
368 AddSortMethod(SortByTime, 180, LABEL_MASKS("%T - %A", "%D")); // Titel, Artist, Duration| empty, empty
369 AddSortMethod(SortByRating, 563, LABEL_MASKS("%T - %A", "%R")); // Titel, Artist, Rating| empty, empty
370 AddSortMethod(SortByUserRating, 38018, LABEL_MASKS("%T - %A", "%r")); // Title - Artist, UserRating
371 AddSortMethod(SortByYear, 562, LABEL_MASKS("%T - %A", "%Y")); // Title, Artist, Year
372 AddSortMethod(SortByDateAdded, 570, LABEL_MASKS("%T - %A", "%a")); // Title - Artist, DateAdded | empty, empty
373 AddSortMethod(SortByPlaycount, 567, LABEL_MASKS("%T - %A", "%V")); // Titel - Artist, PlayCount
374 if (!CServiceBroker::GetSettingsComponent()->GetSettings()->GetBool(
375 CSettings::SETTING_MUSICLIBRARY_USEORIGINALDATE))
376 AddSortMethod(SortByOrigDate, 38079,
377 LABEL_MASKS("%T - %A", "%e")); // Title - Artist, original date, empty, empty
378 AddSortMethod(SortByBPM, 38080,
379 LABEL_MASKS("%T - %A", "%f")); // Title - Artist, bpm, empty, empty
380
381 if (items.IsSmartPlayList() || items.IsLibraryFolder())
382 AddPlaylistOrder(items, LABEL_MASKS(strTrack, "%D"));
383 else
384 {
385 SetSortMethod(viewState->m_sortDescription);
386 SetSortOrder(viewState->m_sortDescription.sortOrder);
387 }
388
389 SetViewAsControl(CViewStateSettings::GetInstance().Get("musicnavsongs")->m_viewMode);
390 }
391 else if (items.GetContent() == "albums")
392 {
393 std::string strAlbum = CServiceBroker::GetSettingsComponent()->GetAdvancedSettings()->m_strMusicLibraryAlbumFormat;
394 if (strAlbum.empty())
395 strAlbum = "%B"; // album
396 // album
397 AddSortMethod(SortByAlbum, sortAttribute, 558, LABEL_MASKS("%F", "", strAlbum, "%A")); // Filename, empty | Userdefined (default=%B), Artist
398 // artist
399 AddSortMethod(SortByArtist, sortAttribute, 557, LABEL_MASKS("%F", "", strAlbum, "%A")); // Filename, empty | Userdefined, Artist
400 // artist / year
401 AddSortMethod(SortByArtistThenYear, sortAttribute, 578, LABEL_MASKS("%F", "", strAlbum, "%A / %Y")); // Filename, empty | Userdefined, Artist / Year
402 // discs
403 AddSortMethod(
404 SortByTotalDiscs, sortAttribute, 38077,
405 LABEL_MASKS("%F", "", strAlbum, "%b")); // Filename, empty | Userdefined, Total discs
406 // year
407 AddSortMethod(SortByYear, 562, LABEL_MASKS("%F", "", strAlbum, "%Y"));
408 // original release date
409 if (!CServiceBroker::GetSettingsComponent()->GetSettings()->GetBool(
410 CSettings::SETTING_MUSICLIBRARY_USEORIGINALDATE))
411 AddSortMethod(
412 SortByOrigDate, 38079,
413 LABEL_MASKS("%F", "", strAlbum, "%e")); // Filename, empty | Userdefined, Original date
414 // album date added
415 AddSortMethod(SortByDateAdded, sortAttribute, 570, LABEL_MASKS("%F", "", strAlbum, "%a")); // Filename, empty | Userdefined, dateAdded
416 // play count
417 AddSortMethod(SortByPlaycount, 567, LABEL_MASKS("%F", "", strAlbum, "%V")); // Filename, empty | Userdefined, Play count
418 // last played
419 AddSortMethod(SortByLastPlayed, 568, LABEL_MASKS("%F", "", strAlbum, "%p")); // Filename, empty | Userdefined, last played
420 // rating
421 AddSortMethod(SortByRating, 563, LABEL_MASKS("%F", "", strAlbum, "%R")); // Filename, empty | Userdefined, Rating
422 // userrating
423 AddSortMethod(SortByUserRating, 38018, LABEL_MASKS("%F", "", strAlbum, "%r")); // Filename, empty | Userdefined, UserRating
424
425 if (items.IsSmartPlayList() || items.IsLibraryFolder())
426 AddPlaylistOrder(items, LABEL_MASKS("%F", "", strAlbum, "%D"));
427 else
428 {
429 SetSortMethod(viewState->m_sortDescription);
430 SetSortOrder(viewState->m_sortDescription.sortOrder);
431 }
432
433 SetViewAsControl(CViewStateSettings::GetInstance().Get("musicnavalbums")->m_viewMode);
434 }
435 else
436 {
437 CLog::Log(LOGERROR,"Music Smart Playlist must be one of songs, mixed or albums");
438 }
439
440 LoadViewState(items.GetPath(), WINDOW_MUSIC_NAV);
441 }
442
SaveViewState()443 void CGUIViewStateMusicSmartPlaylist::SaveViewState()
444 {
445 SaveViewToDb(m_items.GetPath(), WINDOW_MUSIC_NAV, CViewStateSettings::GetInstance().Get("musicnavsongs"));
446 }
447
CGUIViewStateMusicPlaylist(const CFileItemList & items)448 CGUIViewStateMusicPlaylist::CGUIViewStateMusicPlaylist(const CFileItemList& items) : CGUIViewStateWindowMusic(items)
449 {
450 SortAttribute sortAttribute = SortAttributeNone;
451 const std::shared_ptr<CSettings> settings = CServiceBroker::GetSettingsComponent()->GetSettings();
452 if (settings->GetBool(CSettings::SETTING_FILELISTS_IGNORETHEWHENSORTING))
453 sortAttribute = SortAttributeIgnoreArticle;
454 if (settings->GetBool(CSettings::SETTING_MUSICLIBRARY_USEARTISTSORTNAME))
455 sortAttribute = static_cast<SortAttribute>(sortAttribute | SortAttributeUseArtistSortName);
456
457 std::string strTrack = settings->GetString(CSettings::SETTING_MUSICFILES_TRACKFORMAT);
458 AddSortMethod(SortByPlaylistOrder, 559, LABEL_MASKS(strTrack, "%D"));
459 AddSortMethod(SortByTrackNumber, 554, LABEL_MASKS(strTrack, "%D")); // Userdefined, Duration| empty, empty
460 AddSortMethod(SortByTitle, sortAttribute, 556, LABEL_MASKS("%T - %A", "%D")); // Title, Artist, Duration| empty, empty
461 AddSortMethod(SortByAlbum, sortAttribute, 558, LABEL_MASKS("%B - %T - %A", "%D")); // Album, Titel, Artist, Duration| empty, empty
462 AddSortMethod(SortByArtist, sortAttribute, 557, LABEL_MASKS("%A - %T", "%D")); // Artist, Titel, Duration| empty, empty
463 AddSortMethod(SortByArtistThenYear, sortAttribute, 578, LABEL_MASKS("%A - %T", "%Y")); // Artist, Titel, Year| empty, empty
464 AddSortMethod(SortByLabel, sortAttribute, 551, LABEL_MASKS(strTrack, "%D"));
465 AddSortMethod(SortByTime, 180, LABEL_MASKS("%T - %A", "%D")); // Titel - Artist, Duration| empty, empty
466 AddSortMethod(SortByRating, 563, LABEL_MASKS("%T - %A", "%R")); // Titel - Artist, Rating| empty, empty
467 AddSortMethod(SortByUserRating, 38018, LABEL_MASKS("%T - %A", "%r")); // Title - Artist, UserRating
468 SetSortMethod(SortByPlaylistOrder);
469 const CViewState *viewState = CViewStateSettings::GetInstance().Get("musicfiles");
470 SetViewAsControl(viewState->m_viewMode);
471 SetSortOrder(viewState->m_sortDescription.sortOrder);
472
473 LoadViewState(items.GetPath(), WINDOW_MUSIC_NAV);
474 }
475
SaveViewState()476 void CGUIViewStateMusicPlaylist::SaveViewState()
477 {
478 SaveViewToDb(m_items.GetPath(), WINDOW_MUSIC_NAV);
479 }
480
CGUIViewStateWindowMusicNav(const CFileItemList & items)481 CGUIViewStateWindowMusicNav::CGUIViewStateWindowMusicNav(const CFileItemList& items) : CGUIViewStateWindowMusic(items)
482 {
483 SortAttribute sortAttribute = SortAttributeNone;
484 const std::shared_ptr<CSettings> settings = CServiceBroker::GetSettingsComponent()->GetSettings();
485 if (settings->GetBool(CSettings::SETTING_FILELISTS_IGNORETHEWHENSORTING))
486 sortAttribute = SortAttributeIgnoreArticle;
487 if (settings->GetBool(CSettings::SETTING_MUSICLIBRARY_USEARTISTSORTNAME))
488 sortAttribute = static_cast<SortAttribute>(sortAttribute | SortAttributeUseArtistSortName);
489
490 if (items.IsVirtualDirectoryRoot())
491 {
492 AddSortMethod(SortByNone, 551, LABEL_MASKS("%F", "%I", "%L", "")); // Filename, Size | Foldername, empty
493 SetSortMethod(SortByNone);
494
495 SetViewAsControl(DEFAULT_VIEW_LIST);
496
497 SetSortOrder(SortOrderNone);
498 }
499 else if (items.GetPath() == "special://musicplaylists/")
500 { // playlists list sorts by label only, ignoring folders
501 AddSortMethod(SortByLabel, SortAttributeIgnoreFolders, 551,
502 LABEL_MASKS("%F", "%D", "%L", "")); // Filename, Duration | Foldername, empty
503 SetSortMethod(SortByLabel);
504 }
505 else
506 {
507 if (items.IsVideoDb() && items.Size() > (settings->GetBool(CSettings::SETTING_FILELISTS_SHOWPARENTDIRITEMS)?1:0))
508 {
509 XFILE::VIDEODATABASEDIRECTORY::CQueryParams params;
510 XFILE::CVideoDatabaseDirectory::GetQueryParams(items[settings->GetBool(CSettings::SETTING_FILELISTS_SHOWPARENTDIRITEMS) ? 1 : 0]->GetPath(), params);
511 if (params.GetMVideoId() != -1)
512 {
513 AddSortMethod(SortByLabel, sortAttribute, 551, LABEL_MASKS("%T", "%Y")); // Filename, Duration | Foldername, empty
514 AddSortMethod(SortByYear, 562, LABEL_MASKS("%T", "%Y"));
515 AddSortMethod(SortByArtist, sortAttribute, 557, LABEL_MASKS("%A - %T", "%Y"));
516 AddSortMethod(SortByArtistThenYear, sortAttribute, 578, LABEL_MASKS("%A - %T", "%Y"));
517 AddSortMethod(SortByAlbum, sortAttribute, 558, LABEL_MASKS("%B - %T", "%Y"));
518
519 std::string strTrack = settings->GetString(CSettings::SETTING_MUSICFILES_TRACKFORMAT);
520 AddSortMethod(SortByTrackNumber, 554, LABEL_MASKS(strTrack, "%D")); // Userdefined, Duration| empty, empty
521 }
522 else
523 {
524 AddSortMethod(SortByLabel, 551, LABEL_MASKS("%F", "%D", "%L", "")); // Filename, Duration | Foldername, empty
525 SetSortMethod(SortByLabel);
526 }
527 }
528 else
529 {
530 //In navigation of music files tag data is scanned whenever present and can be used as sort criteria
531 //hence sort methods available are similar to song node (not the same as only tag data)
532 //Unfortunately anything here appears at all levels of file navigation even if no song files there.
533 std::string strTrack = settings->GetString(CSettings::SETTING_MUSICFILES_LIBRARYTRACKFORMAT);
534 if (strTrack.empty())
535 strTrack = settings->GetString(CSettings::SETTING_MUSICFILES_TRACKFORMAT);
536 AddSortMethod(SortByLabel, 551, LABEL_MASKS(strTrack, "%D", "%L", ""), // Userdefined, Duration | FolderName, empty
537 settings->GetBool(CSettings::SETTING_FILELISTS_IGNORETHEWHENSORTING) ? SortAttributeIgnoreArticle : SortAttributeNone);
538 AddSortMethod(SortBySize, 553, LABEL_MASKS("%F", "%I", "%L", "%I")); // Filename, Size | Foldername, Size
539 AddSortMethod(SortByDate, 552, LABEL_MASKS("%F", "%J", "%L", "%J")); // Filename, Date | Foldername, Date
540 AddSortMethod(SortByFile, 561, LABEL_MASKS("%F", "%I", "%L", "")); // Filename, Size | Label, empty
541 AddSortMethod(SortByTrackNumber, 554, LABEL_MASKS(strTrack, "%D")); // Userdefined, Duration| empty, empty
542 AddSortMethod(SortByTitle, sortAttribute, 556, LABEL_MASKS("%T - %A", "%D")); // Title, Artist, Duration| empty, empty
543 AddSortMethod(SortByAlbum, sortAttribute, 558, LABEL_MASKS("%B - %T - %A", "%D")); // Album, Title, Artist, Duration| empty, empty
544 AddSortMethod(SortByArtist, sortAttribute, 557, LABEL_MASKS("%A - %T", "%D")); // Artist, Title, Duration| empty, empty
545 AddSortMethod(SortByArtistThenYear, sortAttribute, 578, LABEL_MASKS("%A - %T", "%Y")); // Artist(year), Title, Year| empty, empty
546 AddSortMethod(SortByTime, 180, LABEL_MASKS("%T - %A", "%D")); // Titel, Artist, Duration| empty, empty
547 AddSortMethod(SortByYear, 562, LABEL_MASKS("%T - %A", "%Y")); // Title, Artist, Year
548
549 SetSortMethod(SortByLabel);
550 }
551 const CViewState *viewState = CViewStateSettings::GetInstance().Get("musicnavsongs");
552 SetViewAsControl(viewState->m_viewMode);
553 SetSortOrder(viewState->m_sortDescription.sortOrder);
554
555 SetSortOrder(SortOrderAscending);
556 }
557 LoadViewState(items.GetPath(), WINDOW_MUSIC_NAV);
558 }
559
SaveViewState()560 void CGUIViewStateWindowMusicNav::SaveViewState()
561 {
562 SaveViewToDb(m_items.GetPath(), WINDOW_MUSIC_NAV);
563 }
564
AddOnlineShares()565 void CGUIViewStateWindowMusicNav::AddOnlineShares()
566 {
567 if (!CServiceBroker::GetSettingsComponent()->GetAdvancedSettings()->m_bVirtualShares)
568 return;
569
570 VECSOURCES *musicSources = CMediaSourceSettings::GetInstance().GetSources("music");
571
572 for (int i = 0; i < (int)musicSources->size(); ++i)
573 {
574 CMediaSource share = musicSources->at(i);
575 }
576 }
577
GetSources()578 VECSOURCES& CGUIViewStateWindowMusicNav::GetSources()
579 {
580 // Setup shares we want to have
581 m_sources.clear();
582 CFileItemList items;
583
584 CDirectory::GetDirectory("library://music/", items, "", DIR_FLAG_DEFAULTS);
585 for (int i=0; i<items.Size(); ++i)
586 {
587 CFileItemPtr item=items[i];
588 CMediaSource share;
589 share.strName = item->GetLabel();
590 share.strPath = item->GetPath();
591 share.m_strThumbnailImage = item->GetArt("icon");
592 share.m_iDriveType = CMediaSource::SOURCE_TYPE_LOCAL;
593 m_sources.push_back(share);
594 }
595
596 AddOnlineShares();
597
598 return CGUIViewStateWindowMusic::GetSources();
599 }
600
CGUIViewStateWindowMusicPlaylist(const CFileItemList & items)601 CGUIViewStateWindowMusicPlaylist::CGUIViewStateWindowMusicPlaylist(const CFileItemList& items) : CGUIViewStateWindowMusic(items)
602 {
603 const std::shared_ptr<CSettings> settings = CServiceBroker::GetSettingsComponent()->GetSettings();
604 std::string strTrack = settings->GetString(CSettings::SETTING_MUSICFILES_NOWPLAYINGTRACKFORMAT);
605 if (strTrack.empty())
606 strTrack = settings->GetString(CSettings::SETTING_MUSICFILES_TRACKFORMAT);
607
608 AddSortMethod(SortByNone, 551, LABEL_MASKS(strTrack, "%D", "%L", "")); // Userdefined, Duration | FolderName, empty
609 SetSortMethod(SortByNone);
610
611 SetViewAsControl(DEFAULT_VIEW_LIST);
612
613 SetSortOrder(SortOrderNone);
614
615 LoadViewState(items.GetPath(), WINDOW_MUSIC_PLAYLIST);
616 }
617
SaveViewState()618 void CGUIViewStateWindowMusicPlaylist::SaveViewState()
619 {
620 SaveViewToDb(m_items.GetPath(), WINDOW_MUSIC_PLAYLIST);
621 }
622
GetPlaylist() const623 int CGUIViewStateWindowMusicPlaylist::GetPlaylist() const
624 {
625 return PLAYLIST_MUSIC;
626 }
627
AutoPlayNextItem()628 bool CGUIViewStateWindowMusicPlaylist::AutoPlayNextItem()
629 {
630 return false;
631 }
632
HideParentDirItems()633 bool CGUIViewStateWindowMusicPlaylist::HideParentDirItems()
634 {
635 return true;
636 }
637
GetSources()638 VECSOURCES& CGUIViewStateWindowMusicPlaylist::GetSources()
639 {
640 m_sources.clear();
641 // Playlist share
642 CMediaSource share;
643 share.strPath = "playlistmusic://";
644 share.m_iDriveType = CMediaSource::SOURCE_TYPE_LOCAL;
645 m_sources.push_back(share);
646
647 // CGUIViewState::GetSources would add music plugins
648 return m_sources;
649 }
650