[XBOX] Merged: Linuxport revisions
[xbmc:xbmc-antiquated.git] / xbmc / GUIViewStateMusic.cpp
1 /*
2  *      Copyright (C) 2005-2008 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, write to
17  *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
18  *  http://www.gnu.org/copyleft/gpl.html
19  *
20  */
21
22 #include "stdafx.h"
23 #include "GUIViewStateMusic.h"
24 #include "PlayListPlayer.h"
25 #include "GUIBaseContainer.h" // for VIEW_TYPE_*
26 #include "VideoDatabase.h"
27 #include "Settings.h"
28 #include "FileItem.h"
29 #include "Util.h"
30
31 #include "FileSystem/MusicDatabaseDirectory.h"
32 #include "FileSystem/VideoDatabaseDirectory.h"
33 #include "FileSystem/PluginDirectory.h"
34 #include "FileSystem/ShoutcastDirectory.h"
35
36 using namespace DIRECTORY;
37 using namespace MUSICDATABASEDIRECTORY;
38
39 int CGUIViewStateWindowMusic::GetPlaylist()
40 {
41   //return PLAYLIST_MUSIC_TEMP;
42   return PLAYLIST_MUSIC;
43 }
44
45 bool CGUIViewStateWindowMusic::UnrollArchives()
46 {
47   return g_guiSettings.GetBool("filelists.unrollarchives");
48 }
49
50 bool CGUIViewStateWindowMusic::AutoPlayNextItem()
51 {
52   return g_guiSettings.GetBool("mymusic.autoplaynextitem");
53 }
54
55 CStdString CGUIViewStateWindowMusic::GetLockType()
56 {
57   return "music";
58 }
59
60 CStdString CGUIViewStateWindowMusic::GetExtensions()
61 {
62   return g_stSettings.m_musicExtensions;
63 }
64
65 CGUIViewStateMusicSearch::CGUIViewStateMusicSearch(const CFileItemList& items) : CGUIViewStateWindowMusic(items)
66 {
67   CStdString strTrackLeft=g_guiSettings.GetString("musicfiles.librarytrackformat");
68   if (strTrackLeft.IsEmpty())
69     strTrackLeft = g_guiSettings.GetString("musicfiles.trackformat");
70   CStdString strTrackRight=g_guiSettings.GetString("musicfiles.librarytrackformatright");
71   if (strTrackRight.IsEmpty())
72     strTrackRight = g_guiSettings.GetString("musicfiles.trackformatright");
73
74   CStdString strAlbumLeft = g_advancedSettings.m_strMusicLibraryAlbumFormat;
75   if (strAlbumLeft.IsEmpty())
76     strAlbumLeft = "%B"; // album
77   CStdString strAlbumRight = g_advancedSettings.m_strMusicLibraryAlbumFormatRight;
78   if (strAlbumRight.IsEmpty())
79     strAlbumRight = "%A"; // artist
80
81   if (g_guiSettings.GetBool("filelists.ignorethewhensorting"))
82   {
83     AddSortMethod(SORT_METHOD_TITLE_IGNORE_THE, 556, LABEL_MASKS("%T - %A", "%D", "%L", "%A"));  // Title, Artist, Duration| empty, empty
84     SetSortMethod(SORT_METHOD_TITLE_IGNORE_THE);
85   }
86   else
87   {
88     AddSortMethod(SORT_METHOD_TITLE, 556, LABEL_MASKS("%T - %A", "%D", "%L", "%A"));  // Title, Artist, Duration| empty, empty
89     SetSortMethod(SORT_METHOD_TITLE);
90   }
91
92   SetViewAsControl(g_stSettings.m_viewStateMusicNavSongs.m_viewMode);
93
94   SetSortOrder(g_stSettings.m_viewStateMusicNavSongs.m_sortOrder);
95
96   LoadViewState(items.m_strPath, WINDOW_MUSIC_NAV);
97 }
98
99 void CGUIViewStateMusicSearch::SaveViewState()
100 {
101   SaveViewToDb(m_items.m_strPath, WINDOW_MUSIC_NAV, &g_stSettings.m_viewStateMusicNavSongs);
102 }
103
104 CGUIViewStateMusicDatabase::CGUIViewStateMusicDatabase(const CFileItemList& items) : CGUIViewStateWindowMusic(items)
105 {
106   CMusicDatabaseDirectory dir;
107   NODE_TYPE NodeType=dir.GetDirectoryChildType(items.m_strPath);
108
109   CStdString strTrackLeft=g_guiSettings.GetString("musicfiles.librarytrackformat");
110   if (strTrackLeft.IsEmpty())
111     strTrackLeft = g_guiSettings.GetString("musicfiles.trackformat");
112   CStdString strTrackRight=g_guiSettings.GetString("musicfiles.librarytrackformatright");
113   if (strTrackRight.IsEmpty())
114     strTrackRight = g_guiSettings.GetString("musicfiles.trackformatright");
115
116   CStdString strAlbumLeft = g_advancedSettings.m_strMusicLibraryAlbumFormat;
117   if (strAlbumLeft.IsEmpty())
118     strAlbumLeft = "%B"; // album
119   CStdString strAlbumRight = g_advancedSettings.m_strMusicLibraryAlbumFormatRight;
120   if (strAlbumRight.IsEmpty())
121     strAlbumRight = "%A"; // artist
122
123   CLog::Log(LOGDEBUG,"Album format left  = [%s]", strAlbumLeft.c_str());
124   CLog::Log(LOGDEBUG,"Album format right = [%s]", strAlbumRight.c_str());
125
126   switch (NodeType)
127   {
128   case NODE_TYPE_OVERVIEW:
129     {
130       AddSortMethod(SORT_METHOD_NONE, 551, LABEL_MASKS("%F", "", "%L", ""));  // Filename, empty | Foldername, empty
131       SetSortMethod(SORT_METHOD_NONE);
132
133       SetViewAsControl(DEFAULT_VIEW_LIST);
134
135       SetSortOrder(SORT_ORDER_NONE);
136     }
137     break;
138   case NODE_TYPE_TOP100:
139     {
140       AddSortMethod(SORT_METHOD_NONE, 551, LABEL_MASKS("%F", "", "%L", ""));  // Filename, empty | Foldername, empty
141       SetSortMethod(SORT_METHOD_NONE);
142
143       SetViewAsControl(DEFAULT_VIEW_LIST);
144
145       SetSortOrder(SORT_ORDER_NONE);
146     }
147     break;
148   case NODE_TYPE_GENRE:
149     {
150       AddSortMethod(SORT_METHOD_GENRE, 551, LABEL_MASKS("%F", "", "%G", ""));  // Filename, empty | Genre, empty
151       SetSortMethod(SORT_METHOD_GENRE);
152
153       SetViewAsControl(DEFAULT_VIEW_LIST);
154
155       SetSortOrder(SORT_ORDER_ASC);
156     }
157     break;
158   case NODE_TYPE_YEAR:
159     {
160       AddSortMethod(SORT_METHOD_LABEL, 551, LABEL_MASKS("%F", "", "%Y", ""));  // Filename, empty | Year, empty
161       SetSortMethod(SORT_METHOD_LABEL);
162
163       SetViewAsControl(DEFAULT_VIEW_LIST);
164
165       SetSortOrder(SORT_ORDER_ASC);
166     }
167     break;
168   case NODE_TYPE_ARTIST:
169     {
170       if (g_guiSettings.GetBool("filelists.ignorethewhensorting"))
171       {
172         AddSortMethod(SORT_METHOD_ARTIST_IGNORE_THE, 551, LABEL_MASKS("%F", "", "%A", ""));  // Filename, empty | Artist, empty
173         SetSortMethod(SORT_METHOD_ARTIST_IGNORE_THE);
174       }
175       else
176       {
177         AddSortMethod(SORT_METHOD_ARTIST, 551, LABEL_MASKS("%F", "", "%A", ""));  // Filename, empty | Artist, empty
178         SetSortMethod(SORT_METHOD_ARTIST);
179       }
180
181       SetViewAsControl(g_stSettings.m_viewStateMusicNavArtists.m_viewMode);
182
183       SetSortOrder(g_stSettings.m_viewStateMusicNavArtists.m_sortOrder);
184     }
185     break;
186   case NODE_TYPE_ALBUM_COMPILATIONS:
187   case NODE_TYPE_ALBUM:
188   case NODE_TYPE_YEAR_ALBUM:
189     {
190       // album
191       if (g_guiSettings.GetBool("filelists.ignorethewhensorting"))
192         AddSortMethod(SORT_METHOD_ALBUM_IGNORE_THE, 558, LABEL_MASKS("%F", "", strAlbumLeft, strAlbumRight));  // Filename, empty | Userdefined, Userdefined
193       else
194         AddSortMethod(SORT_METHOD_ALBUM, 558, LABEL_MASKS("%F", "", strAlbumLeft, strAlbumRight));  // Filename, empty | Userdefined, Userdefined
195
196       // artist
197       if (g_guiSettings.GetBool("filelists.ignorethewhensorting"))
198         AddSortMethod(SORT_METHOD_ARTIST_IGNORE_THE, 557, LABEL_MASKS("%F", "", strAlbumLeft, strAlbumRight));  // Filename, empty | Userdefined, Userdefined
199       else
200         AddSortMethod(SORT_METHOD_ARTIST, 557, LABEL_MASKS("%F", "", strAlbumLeft, strAlbumRight));  // Filename, empty | Userdefined, Userdefined
201
202       // year
203       AddSortMethod(SORT_METHOD_YEAR, 562, LABEL_MASKS("%F", "", strAlbumLeft, strAlbumRight));
204
205       SetSortMethod(g_stSettings.m_viewStateMusicNavAlbums.m_sortMethod);
206
207       SetViewAsControl(g_stSettings.m_viewStateMusicNavAlbums.m_viewMode);
208
209       SetSortOrder(g_stSettings.m_viewStateMusicNavAlbums.m_sortOrder);
210     }
211     break;
212   case NODE_TYPE_ALBUM_RECENTLY_ADDED:
213     {
214       AddSortMethod(SORT_METHOD_NONE, 552, LABEL_MASKS("%F", "", strAlbumLeft, strAlbumRight));  // Filename, empty | Userdefined, Userdefined
215       SetSortMethod(SORT_METHOD_NONE);
216
217       SetViewAsControl(g_stSettings.m_viewStateMusicNavAlbums.m_viewMode);
218
219       SetSortOrder(SORT_ORDER_NONE);
220     }
221     break;
222   case NODE_TYPE_ALBUM_RECENTLY_ADDED_SONGS:
223     {
224       AddSortMethod(SORT_METHOD_NONE, 552, LABEL_MASKS(strTrackLeft, strTrackRight));  // Userdefined, Userdefined | empty, empty
225       SetSortMethod(SORT_METHOD_NONE);
226
227       SetViewAsControl(g_stSettings.m_viewStateMusicNavSongs.m_viewMode);
228
229       SetSortOrder(SORT_ORDER_NONE);
230     }
231     break;
232   case NODE_TYPE_ALBUM_RECENTLY_PLAYED:
233     {
234       AddSortMethod(SORT_METHOD_NONE, 551, LABEL_MASKS("%F", "", strAlbumLeft, strAlbumRight));  // Filename, empty | Userdefined, Userdefined
235       SetSortMethod(SORT_METHOD_NONE);
236
237       SetViewAsControl(g_stSettings.m_viewStateMusicNavAlbums.m_viewMode);
238
239       SetSortOrder(SORT_ORDER_NONE);
240     }
241     break;
242   case NODE_TYPE_ALBUM_RECENTLY_PLAYED_SONGS:
243     {
244       AddSortMethod(SORT_METHOD_NONE, 551, LABEL_MASKS(strTrackLeft, strTrackRight));  // Userdefined, Userdefined | empty, empty
245       SetSortMethod(SORT_METHOD_NONE);
246
247       SetViewAsControl(g_stSettings.m_viewStateMusicNavAlbums.m_viewMode);
248
249       SetSortOrder(SORT_ORDER_NONE);
250     }
251     break;
252   case NODE_TYPE_ALBUM_TOP100:
253     {
254       AddSortMethod(SORT_METHOD_NONE, 551, LABEL_MASKS("%F", "", strAlbumLeft, strAlbumRight));  // Filename, empty | Userdefined, Userdefined
255       SetSortMethod(SORT_METHOD_NONE);
256
257       SetViewAsControl(DEFAULT_VIEW_LIST);
258
259       SetSortOrder(SORT_ORDER_NONE);
260     }
261     break;
262   case NODE_TYPE_ALBUM_COMPILATIONS_SONGS:
263   case NODE_TYPE_ALBUM_TOP100_SONGS:
264   case NODE_TYPE_YEAR_SONG:
265   case NODE_TYPE_SONG:
266     {
267       AddSortMethod(SORT_METHOD_TRACKNUM, 554, LABEL_MASKS(strTrackLeft, strTrackRight));  // Userdefined, Userdefined| empty, empty
268       if (g_guiSettings.GetBool("filelists.ignorethewhensorting"))
269       {
270         AddSortMethod(SORT_METHOD_TITLE_IGNORE_THE, 556, LABEL_MASKS("%T - %A", "%D"));  // Title, Artist, Duration| empty, empty
271         AddSortMethod(SORT_METHOD_ALBUM_IGNORE_THE, 558, LABEL_MASKS("%B - %T - %A", "%D"));  // Album, Title, Artist, Duration| empty, empty
272         AddSortMethod(SORT_METHOD_ARTIST_IGNORE_THE, 557, LABEL_MASKS("%A - %T", "%D"));  // Artist, Title, Duration| empty, empty
273         AddSortMethod(SORT_METHOD_LABEL_IGNORE_THE, 551, LABEL_MASKS(strTrackLeft, strTrackRight));
274       }
275       else
276       {
277         AddSortMethod(SORT_METHOD_TITLE, 556, LABEL_MASKS("%T - %A", "%D"));  // Title, Artist, Duration| empty, empty
278         AddSortMethod(SORT_METHOD_ALBUM, 558, LABEL_MASKS("%B - %T - %A", "%D"));  // Album, Title, Artist, Duration| empty, empty
279         AddSortMethod(SORT_METHOD_ARTIST, 557, LABEL_MASKS("%A - %T", "%D"));  // Artist, Title, Duration| empty, empty
280         AddSortMethod(SORT_METHOD_LABEL, 551, LABEL_MASKS(strTrackLeft, strTrackRight));
281       }
282       AddSortMethod(SORT_METHOD_DURATION, 555, LABEL_MASKS("%T - %A", "%D"));  // Titel, Artist, Duration| empty, empty
283       AddSortMethod(SORT_METHOD_SONG_RATING, 563, LABEL_MASKS("%T - %A", "%R"));  // Title - Artist, Rating
284
285       // the "All Albums" entries always default to SORT_METHOD_ALBUM as this is most logical - user can always
286       // change it and the change will be saved for this particular path
287       if (dir.IsAllItem(items.m_strPath))
288         SetSortMethod(g_guiSettings.GetBool("filelists.ignorethewhensorting") ? SORT_METHOD_ALBUM_IGNORE_THE : SORT_METHOD_ALBUM);
289       else
290         SetSortMethod(g_stSettings.m_viewStateMusicNavSongs.m_sortMethod);
291
292       SetViewAsControl(g_stSettings.m_viewStateMusicNavSongs.m_viewMode);
293
294       SetSortOrder(g_stSettings.m_viewStateMusicNavSongs.m_sortOrder);
295     }
296     break;
297   case NODE_TYPE_SONG_TOP100:
298     {
299       AddSortMethod(SORT_METHOD_NONE, 554, LABEL_MASKS(strTrackLeft, strTrackRight));  // Userdefined, Userdefined | empty, empty
300       SetSortMethod(SORT_METHOD_NONE);
301
302       SetViewAsControl(g_stSettings.m_viewStateMusicNavSongs.m_viewMode);
303
304       SetSortOrder(SORT_ORDER_NONE);
305     }
306     break;
307   default:
308     break;
309   }
310
311   LoadViewState(items.m_strPath, WINDOW_MUSIC_NAV);
312 }
313
314 void CGUIViewStateMusicDatabase::SaveViewState()
315 {
316   CMusicDatabaseDirectory dir;
317   NODE_TYPE NodeType=dir.GetDirectoryChildType(m_items.m_strPath);
318
319   switch (NodeType)
320   {
321     case NODE_TYPE_ARTIST:
322       SaveViewToDb(m_items.m_strPath, WINDOW_MUSIC_NAV, &g_stSettings.m_viewStateMusicNavArtists);
323       break;
324     case NODE_TYPE_ALBUM_COMPILATIONS:
325     case NODE_TYPE_ALBUM:
326     case NODE_TYPE_YEAR_ALBUM:
327       SaveViewToDb(m_items.m_strPath, WINDOW_MUSIC_NAV, &g_stSettings.m_viewStateMusicNavAlbums);
328       break;
329     case NODE_TYPE_ALBUM_RECENTLY_ADDED:
330     case NODE_TYPE_ALBUM_TOP100:
331     case NODE_TYPE_ALBUM_RECENTLY_PLAYED:
332       SaveViewToDb(m_items.m_strPath, WINDOW_MUSIC_NAV);
333       break;
334     case NODE_TYPE_ALBUM_COMPILATIONS_SONGS:
335     case NODE_TYPE_SONG:
336     case NODE_TYPE_YEAR_SONG:
337       SaveViewToDb(m_items.m_strPath, WINDOW_MUSIC_NAV, &g_stSettings.m_viewStateMusicNavSongs);
338       break;
339     case NODE_TYPE_ALBUM_RECENTLY_PLAYED_SONGS:
340     case NODE_TYPE_ALBUM_RECENTLY_ADDED_SONGS:
341     case NODE_TYPE_SONG_TOP100:
342       SaveViewToDb(m_items.m_strPath, WINDOW_MUSIC_NAV);
343       break;
344     default:
345       SaveViewToDb(m_items.m_strPath, WINDOW_MUSIC_NAV);
346       break;
347         }
348 }
349
350
351 CGUIViewStateMusicSmartPlaylist::CGUIViewStateMusicSmartPlaylist(const CFileItemList& items) : CGUIViewStateWindowMusic(items)
352 {
353   CStdString strTrackLeft=g_guiSettings.GetString("musicfiles.trackformat");
354   CStdString strTrackRight=g_guiSettings.GetString("musicfiles.trackformatright");
355
356   AddSortMethod(SORT_METHOD_PLAYLIST_ORDER, 559, LABEL_MASKS(strTrackLeft, strTrackRight));
357   AddSortMethod(SORT_METHOD_TRACKNUM, 554, LABEL_MASKS(strTrackLeft, strTrackRight));  // Userdefined, Userdefined| empty, empty
358   if (g_guiSettings.GetBool("filelists.ignorethewhensorting"))
359   {
360     AddSortMethod(SORT_METHOD_TITLE_IGNORE_THE, 556, LABEL_MASKS("%T - %A", "%D"));  // Title, Artist, Duration| empty, empty
361     AddSortMethod(SORT_METHOD_ALBUM_IGNORE_THE, 558, LABEL_MASKS("%B - %T - %A", "%D"));  // Album, Titel, Artist, Duration| empty, empty
362     AddSortMethod(SORT_METHOD_ARTIST_IGNORE_THE, 557, LABEL_MASKS("%A - %T", "%D"));  // Artist, Titel, Duration| empty, empty
363     AddSortMethod(SORT_METHOD_LABEL_IGNORE_THE, 551, LABEL_MASKS(strTrackLeft, strTrackRight));
364   }
365   else
366   {
367     AddSortMethod(SORT_METHOD_TITLE, 556, LABEL_MASKS("%T - %A", "%D"));  // Title, Artist, Duration| empty, empty
368     AddSortMethod(SORT_METHOD_ALBUM, 558, LABEL_MASKS("%B - %T - %A", "%D"));  // Album, Titel, Artist, Duration| empty, empty
369     AddSortMethod(SORT_METHOD_ARTIST, 557, LABEL_MASKS("%A - %T", "%D"));  // Artist, Titel, Duration| empty, empty
370     AddSortMethod(SORT_METHOD_LABEL, 551, LABEL_MASKS(strTrackLeft, strTrackRight));
371   }
372   AddSortMethod(SORT_METHOD_DURATION, 555, LABEL_MASKS("%T - %A", "%D"));  // Titel, Artist, Duration| empty, empty
373   AddSortMethod(SORT_METHOD_SONG_RATING, 563, LABEL_MASKS("%T - %A", "%R"));  // Titel, Artist, Rating| empty, empty
374   SetSortMethod(g_stSettings.m_viewStateMusicNavSongs.m_sortMethod);
375
376   SetViewAsControl(g_stSettings.m_viewStateMusicNavSongs.m_viewMode);
377
378   SetSortOrder(g_stSettings.m_viewStateMusicNavSongs.m_sortOrder);
379   LoadViewState(items.m_strPath, WINDOW_MUSIC_NAV);
380 }
381
382 void CGUIViewStateMusicSmartPlaylist::SaveViewState()
383 {
384   SaveViewToDb(m_items.m_strPath, WINDOW_MUSIC_NAV, &g_stSettings.m_viewStateMusicNavSongs);
385 }
386
387 CGUIViewStateMusicPlaylist::CGUIViewStateMusicPlaylist(const CFileItemList& items) : CGUIViewStateWindowMusic(items)
388 {
389   CStdString strTrackLeft=g_guiSettings.GetString("musicfiles.trackformat");
390   CStdString strTrackRight=g_guiSettings.GetString("musicfiles.trackformatright");
391
392   AddSortMethod(SORT_METHOD_PLAYLIST_ORDER, 559, LABEL_MASKS(strTrackLeft, strTrackRight));
393   AddSortMethod(SORT_METHOD_TRACKNUM, 554, LABEL_MASKS(strTrackLeft, strTrackRight));  // Userdefined, Userdefined| empty, empty
394   if (g_guiSettings.GetBool("filelists.ignorethewhensorting"))
395   {
396     AddSortMethod(SORT_METHOD_TITLE_IGNORE_THE, 556, LABEL_MASKS("%T - %A", "%D"));  // Title, Artist, Duration| empty, empty
397     AddSortMethod(SORT_METHOD_ALBUM_IGNORE_THE, 558, LABEL_MASKS("%B - %T - %A", "%D"));  // Album, Titel, Artist, Duration| empty, empty
398     AddSortMethod(SORT_METHOD_ARTIST_IGNORE_THE, 557, LABEL_MASKS("%A - %T", "%D"));  // Artist, Titel, Duration| empty, empty
399     AddSortMethod(SORT_METHOD_LABEL_IGNORE_THE, 551, LABEL_MASKS(strTrackLeft, strTrackRight));
400   }
401   else
402   {
403     AddSortMethod(SORT_METHOD_TITLE, 556, LABEL_MASKS("%T - %A", "%D"));  // Title, Artist, Duration| empty, empty
404     AddSortMethod(SORT_METHOD_ALBUM, 558, LABEL_MASKS("%B - %T - %A", "%D"));  // Album, Titel, Artist, Duration| empty, empty
405     AddSortMethod(SORT_METHOD_ARTIST, 557, LABEL_MASKS("%A - %T", "%D"));  // Artist, Titel, Duration| empty, empty
406     AddSortMethod(SORT_METHOD_LABEL, 551, LABEL_MASKS(strTrackLeft, strTrackRight));
407   }
408   AddSortMethod(SORT_METHOD_DURATION, 555, LABEL_MASKS("%T - %A", "%D"));  // Titel, Artist, Duration| empty, empty
409   AddSortMethod(SORT_METHOD_SONG_RATING, 563, LABEL_MASKS("%T - %A", "%R"));  // Titel, Artist, Rating| empty, empty
410
411   SetSortMethod(g_stSettings.m_viewStateMusicFiles.m_sortMethod);
412   SetViewAsControl(g_stSettings.m_viewStateMusicFiles.m_viewMode);
413   SetSortOrder(g_stSettings.m_viewStateMusicFiles.m_sortOrder);
414
415   LoadViewState(items.m_strPath, WINDOW_MUSIC_FILES);
416 }
417
418 void CGUIViewStateMusicPlaylist::SaveViewState()
419 {
420   SaveViewToDb(m_items.m_strPath, WINDOW_MUSIC_FILES);
421 }
422
423
424 CGUIViewStateWindowMusicNav::CGUIViewStateWindowMusicNav(const CFileItemList& items) : CGUIViewStateWindowMusic(items)
425 {
426   if (items.IsVirtualDirectoryRoot())
427   {
428     AddSortMethod(SORT_METHOD_NONE, 551, LABEL_MASKS("%F", "%I", "%L", ""));  // Filename, Size | Foldername, empty
429     SetSortMethod(SORT_METHOD_NONE);
430
431     SetViewAsControl(DEFAULT_VIEW_LIST);
432
433     SetSortOrder(SORT_ORDER_NONE);
434   }
435   else
436   {
437     if (items.IsVideoDb() && items.Size() > (g_guiSettings.GetBool("filelists.hideparentdiritems")?0:1))
438     {
439       DIRECTORY::VIDEODATABASEDIRECTORY::CQueryParams params;
440       DIRECTORY::CVideoDatabaseDirectory::GetQueryParams(items[g_guiSettings.GetBool("filelists.hideparentdiritems")?0:1]->m_strPath,params);
441       if (params.GetMVideoId() != -1)
442       {
443         if (g_guiSettings.GetBool("filelists.ignorethewhensorting"))
444           AddSortMethod(SORT_METHOD_LABEL_IGNORE_THE, 556, LABEL_MASKS("%T", "%Y"));  // Filename, Duration | Foldername, empty
445         else
446           AddSortMethod(SORT_METHOD_LABEL, 551, LABEL_MASKS("%T", "%Y"));  // Filename, Duration | Foldername, empty
447         AddSortMethod(SORT_METHOD_YEAR,562, LABEL_MASKS("%T", "%Y"));
448         if (g_guiSettings.GetBool("filelists.ignorethewhensorting"))
449         {
450           AddSortMethod(SORT_METHOD_ARTIST_IGNORE_THE,557, LABEL_MASKS("%A - %T", "%Y"));
451           AddSortMethod(SORT_METHOD_ALBUM_IGNORE_THE,558, LABEL_MASKS("%B - %T", "%Y"));
452         }
453         else
454         {
455           AddSortMethod(SORT_METHOD_ARTIST,557, LABEL_MASKS("%A - %T", "%Y"));
456           AddSortMethod(SORT_METHOD_ALBUM,558, LABEL_MASKS("%B - %T", "%Y"));
457         }
458         CStdString strTrackLeft=g_guiSettings.GetString("musicfiles.trackformat");
459         CStdString strTrackRight=g_guiSettings.GetString("musicfiles.trackformatright");
460         AddSortMethod(SORT_METHOD_TRACKNUM, 554, LABEL_MASKS(strTrackLeft, strTrackRight));  // Userdefined, Userdefined| empty, empty
461       }
462       else
463       {
464         AddSortMethod(SORT_METHOD_LABEL, 551, LABEL_MASKS("%F", "%D", "%L", ""));  // Filename, Duration | Foldername, empty
465         SetSortMethod(SORT_METHOD_LABEL);
466       }
467     }
468     else
469     {
470       AddSortMethod(SORT_METHOD_LABEL, 551, LABEL_MASKS("%F", "%D", "%L", ""));  // Filename, Duration | Foldername, empty
471       SetSortMethod(SORT_METHOD_LABEL);
472     }
473     SetViewAsControl(DEFAULT_VIEW_LIST);
474
475     SetSortOrder(SORT_ORDER_ASC);
476   }
477   LoadViewState(items.m_strPath, WINDOW_MUSIC_NAV);
478 }
479
480 void CGUIViewStateWindowMusicNav::SaveViewState()
481 {
482   SaveViewToDb(m_items.m_strPath, WINDOW_MUSIC_NAV);
483 }
484
485 void CGUIViewStateWindowMusicNav::AddOnlineShares()
486 {
487   if (!g_guiSettings.GetBool("network.enableinternet")) return;
488   if (!g_advancedSettings.m_bVirtualShares) return;
489   for (int i = 0; i < (int)g_settings.m_musicSources.size(); ++i)
490   {
491     CMediaSource share = g_settings.m_musicSources.at(i);
492     if (share.strPath.Find(SHOUTCAST_MASTER_LINK) == 0)//shoutcast shares
493       m_sources.push_back(share);
494     else if (share.strPath.Find("lastfm://") == 0)//lastfm share
495       m_sources.push_back(share);
496   }
497 }
498
499 VECSOURCES& CGUIViewStateWindowMusicNav::GetSources()
500 {
501   //  Setup shares we want to have
502   m_sources.clear();
503   //  Musicdb shares
504   CFileItemList items;
505   CDirectory::GetDirectory("musicdb://", items);
506   for (int i=0; i<items.Size(); ++i)
507   {
508     CFileItemPtr item=items[i];
509     CMediaSource share;
510     share.strName=item->GetLabel();
511     share.strPath = item->m_strPath;
512     share.m_strThumbnailImage = item->GetThumbnailImage();
513     share.m_iDriveType = CMediaSource::SOURCE_TYPE_LOCAL;
514     m_sources.push_back(share);
515   }
516
517   //  Playlists share
518   CMediaSource share;
519   share.strName=g_localizeStrings.Get(136); // Playlists
520   share.strPath = "special://musicplaylists/";
521   share.m_strThumbnailImage = CUtil::GetDefaultFolderThumb("DefaultMusicPlaylists.png");
522   share.m_iDriveType = CMediaSource::SOURCE_TYPE_LOCAL;
523   m_sources.push_back(share);
524
525   AddOnlineShares();
526
527   // Search share
528   share.strName=g_localizeStrings.Get(137); // Search
529   share.strPath = "musicsearch://";
530   share.m_strThumbnailImage = CUtil::GetDefaultFolderThumb("DefaultMusicSearch.png");
531   share.m_iDriveType = CMediaSource::SOURCE_TYPE_LOCAL;
532   m_sources.push_back(share);
533
534   // music video share
535   CVideoDatabase database;
536   database.Open();
537   if (database.HasContent(VIDEODB_CONTENT_MUSICVIDEOS))
538   {
539     share.strName = g_localizeStrings.Get(20389);
540     share.strPath = "videodb://3/";
541     share.m_strThumbnailImage = CUtil::GetDefaultFolderThumb("DefaultMusicVideos.png");
542     share.m_iDriveType = CMediaSource::SOURCE_TYPE_LOCAL;
543     m_sources.push_back(share);
544   }
545
546   // plugins share
547   if (CPluginDirectory::HasPlugins("music") && g_advancedSettings.m_bVirtualShares)
548   {
549     share.strName = g_localizeStrings.Get(1038);
550     share.strPath = "plugin://music/";
551     share.m_strThumbnailImage = CUtil::GetDefaultFolderThumb("DefaultMusicPlugins.png");
552     share.m_ignore = true;
553     m_sources.push_back(share);
554   }
555
556   return CGUIViewStateWindowMusic::GetSources();
557 }
558
559 CGUIViewStateWindowMusicSongs::CGUIViewStateWindowMusicSongs(const CFileItemList& items) : CGUIViewStateWindowMusic(items)
560 {
561   if (items.IsVirtualDirectoryRoot())
562   {
563     AddSortMethod(SORT_METHOD_LABEL, 551, LABEL_MASKS()); // Preformated
564     AddSortMethod(SORT_METHOD_DRIVE_TYPE, 564, LABEL_MASKS()); // Preformated
565     SetSortMethod(SORT_METHOD_LABEL);
566
567     SetViewAsControl(DEFAULT_VIEW_LIST);
568
569     SetSortOrder(SORT_ORDER_ASC);
570   }
571   else
572   {
573     CStdString strTrackLeft=g_guiSettings.GetString("musicfiles.trackformat");
574     CStdString strTrackRight=g_guiSettings.GetString("musicfiles.trackformatright");
575
576     if (g_guiSettings.GetBool("filelists.ignorethewhensorting"))
577       AddSortMethod(SORT_METHOD_LABEL_IGNORE_THE, 551, LABEL_MASKS(strTrackLeft, strTrackRight, "%L", ""));  // Userdefined, Userdefined | FolderName, empty
578     else
579       AddSortMethod(SORT_METHOD_LABEL, 551, LABEL_MASKS(strTrackLeft, strTrackRight, "%L", ""));  // Userdefined, Userdefined | FolderName, empty
580     AddSortMethod(SORT_METHOD_SIZE, 553, LABEL_MASKS(strTrackLeft, "%I", "%L", "%I"));  // Userdefined, Size | FolderName, Size
581     AddSortMethod(SORT_METHOD_DATE, 552, LABEL_MASKS(strTrackLeft, "%J", "%L", "%J"));  // Userdefined, Date | FolderName, Date
582     AddSortMethod(SORT_METHOD_FILE, 561, LABEL_MASKS(strTrackLeft, strTrackRight, "%L", ""));  // Userdefined, Userdefined | FolderName, empty
583     SetSortMethod(g_stSettings.m_viewStateMusicFiles.m_sortMethod);
584     SetViewAsControl(g_stSettings.m_viewStateMusicFiles.m_viewMode);
585     SetSortOrder(g_stSettings.m_viewStateMusicFiles.m_sortOrder);
586   }
587   LoadViewState(items.m_strPath, WINDOW_MUSIC_FILES);
588 }
589
590 void CGUIViewStateWindowMusicSongs::SaveViewState()
591 {
592   if (g_guiSettings.GetBool("musicfiles.savefolderviews"))
593     SaveViewToDb(m_items.m_strPath, WINDOW_MUSIC_FILES, &g_stSettings.m_viewStateMusicFiles);  
594   else
595   {
596     g_stSettings.m_viewStateMusicFiles = CViewState(GetViewAsControl(), GetSortMethod(), GetSortOrder());
597     g_settings.Save();
598   }
599 }
600
601 VECSOURCES& CGUIViewStateWindowMusicSongs::GetSources()
602 {
603   bool bIsSourceName = true;
604   // plugins share
605   if (CPluginDirectory::HasPlugins("music") && g_advancedSettings.m_bVirtualShares)
606   {
607     CMediaSource share;
608     share.strName = g_localizeStrings.Get(1038);
609     share.strPath = "plugin://music/";
610     if (CUtil::GetMatchingSource(share.strName, g_settings.m_musicSources, bIsSourceName) < 0)
611       g_settings.m_musicSources.push_back(share);
612   }
613   return g_settings.m_musicSources; 
614 }
615
616 CGUIViewStateWindowMusicPlaylist::CGUIViewStateWindowMusicPlaylist(const CFileItemList& items) : CGUIViewStateWindowMusic(items)
617 {
618   CStdString strTrackLeft=g_guiSettings.GetString("musicfiles.nowplayingtrackformat");
619   if (strTrackLeft.IsEmpty())
620     strTrackLeft = g_guiSettings.GetString("musicfiles.trackformat");
621   CStdString strTrackRight=g_guiSettings.GetString("musicfiles.nowplayingtrackformatright");
622   if (strTrackRight.IsEmpty())
623     strTrackRight = g_guiSettings.GetString("musicfiles.trackformatright");
624
625   AddSortMethod(SORT_METHOD_NONE, 551, LABEL_MASKS(strTrackLeft, strTrackRight, "%L", ""));  // Userdefined, Userdefined | FolderName, empty
626   SetSortMethod(SORT_METHOD_NONE);
627
628   SetViewAsControl(DEFAULT_VIEW_LIST);
629
630   SetSortOrder(SORT_ORDER_NONE);
631
632   LoadViewState(items.m_strPath, WINDOW_MUSIC_PLAYLIST);
633 }
634
635 void CGUIViewStateWindowMusicPlaylist::SaveViewState()
636 {
637   SaveViewToDb(m_items.m_strPath, WINDOW_MUSIC_PLAYLIST);
638 }
639
640 int CGUIViewStateWindowMusicPlaylist::GetPlaylist()
641 {
642   return PLAYLIST_MUSIC;
643 }
644
645 bool CGUIViewStateWindowMusicPlaylist::AutoPlayNextItem()
646 {
647   return false;
648 }
649
650 bool CGUIViewStateWindowMusicPlaylist::HideParentDirItems()
651 {
652   return true;
653 }
654
655 VECSOURCES& CGUIViewStateWindowMusicPlaylist::GetSources()
656 {
657   m_sources.clear();
658   //  Playlist share
659   CMediaSource share;
660   share.strPath = "playlistmusic://";
661   share.m_iDriveType = CMediaSource::SOURCE_TYPE_LOCAL;
662   m_sources.push_back(share);
663
664   return CGUIViewStateWindowMusic::GetSources();
665 }
666
667 CGUIViewStateMusicShoutcast::CGUIViewStateMusicShoutcast(const CFileItemList& items) : CGUIViewStateWindowMusic(items)
668 {
669   /* sadly m_idepth isn't remembered when a directory is retrieved from cache */
670   /* and thus this check hardly ever works, so let's just disable it for now */
671   if( true || m_items.m_idepth > 1 )
672   { /* station list */
673     AddSortMethod(SORT_METHOD_LABEL, 551, LABEL_MASKS("%K", "%B kbps", "%K", ""));  // Title, Bitrate | Title, nothing
674     AddSortMethod(SORT_METHOD_VIDEO_RATING, 563, LABEL_MASKS("%K", "%A listeners", "%K", ""));  // Titel, Listeners | Titel, nothing
675     AddSortMethod(SORT_METHOD_SIZE, 553, LABEL_MASKS("%K", "%B kbps", "%K", ""));  // Title, Bitrate | Title, nothing
676
677     SetSortMethod(g_stSettings.m_viewStateMusicShoutcast.m_sortMethod);
678     SetSortOrder(g_stSettings.m_viewStateMusicShoutcast.m_sortOrder);
679   }
680   else
681   { /* genre list */
682     AddSortMethod(SORT_METHOD_LABEL, 551, LABEL_MASKS("%K", "", "%K", ""));  // Title, nothing | Title, nothing
683     SetSortMethod(SORT_METHOD_LABEL);
684     SetSortOrder(SORT_ORDER_ASC); /* maybe we should have this stored somewhere */
685   }
686
687   SetViewAsControl(DEFAULT_VIEW_LIST);
688   LoadViewState(items.m_strPath, WINDOW_MUSIC_FILES);
689 }
690
691 bool CGUIViewStateMusicShoutcast::AutoPlayNextItem()
692 {
693   return false;
694 }
695
696 void CGUIViewStateMusicShoutcast::SaveViewState()
697 {
698   SaveViewToDb(m_items.m_strPath, WINDOW_MUSIC_FILES, &g_stSettings.m_viewStateMusicShoutcast);
699 }
700
701 CGUIViewStateMusicLastFM::CGUIViewStateMusicLastFM(const CFileItemList& items) : CGUIViewStateWindowMusic(items)
702 {
703   CStdString strTrackLeft=g_guiSettings.GetString("musicfiles.trackformat");
704   CStdString strTrackRight=g_guiSettings.GetString("musicfiles.trackformatright");
705
706   AddSortMethod(SORT_METHOD_UNSORTED, 571, LABEL_MASKS(strTrackLeft, strTrackRight, "%L", ""));  // Userdefined, Userdefined | FolderName, empty
707   AddSortMethod(SORT_METHOD_LABEL, 551, LABEL_MASKS(strTrackLeft, strTrackRight, "%L", ""));  // Userdefined, Userdefined | FolderName, empty
708   AddSortMethod(SORT_METHOD_SIZE, 553, LABEL_MASKS(strTrackLeft, "%I", "%L", "%I"));  // Userdefined, Size | FolderName, Size
709
710   SetSortMethod(g_stSettings.m_viewStateMusicLastFM.m_sortMethod);
711   SetSortOrder(g_stSettings.m_viewStateMusicLastFM.m_sortOrder);
712
713   SetViewAsControl(DEFAULT_VIEW_LIST);
714   LoadViewState(items.m_strPath, WINDOW_MUSIC_FILES);
715 }
716
717 bool CGUIViewStateMusicLastFM::AutoPlayNextItem()
718 {
719   return false;
720 }
721
722 void CGUIViewStateMusicLastFM::SaveViewState()
723 {
724   SaveViewToDb(m_items.m_strPath, WINDOW_MUSIC_FILES, &g_stSettings.m_viewStateMusicLastFM);
725 }
726