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