2 * Copyright (C) 2005-2008 Team XBMC
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)
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.
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
22 #include "SmartPlaylistDirectory.h"
23 #include "utils/log.h"
24 #include "playlists/SmartPlayList.h"
25 #include "music/MusicDatabase.h"
26 #include "video/VideoDatabase.h"
27 #include "Directory.h"
33 CSmartPlaylistDirectory::CSmartPlaylistDirectory()
37 CSmartPlaylistDirectory::~CSmartPlaylistDirectory()
41 bool CSmartPlaylistDirectory::GetDirectory(const CStdString& strPath, CFileItemList& items)
43 // Load in the SmartPlaylist and get the WHERE query
44 CSmartPlaylist playlist;
45 if (!playlist.Load(strPath))
47 bool success = false, success2 = false;
48 if (playlist.GetType().Equals("tvshows"))
52 CStdString whereOrder = playlist.GetWhereClause(db) + " " + playlist.GetOrderClause(db);
53 success = db.GetTvShowsByWhere("videodb://2/2/", whereOrder, items);
54 items.SetContent("tvshows");
57 else if (playlist.GetType().Equals("episodes"))
61 CStdString whereOrder = playlist.GetWhereClause(db) + " " + playlist.GetOrderClause(db);
62 success = db.GetEpisodesByWhere("videodb://2/2/", whereOrder, items);
63 items.SetContent("episodes");
66 else if (playlist.GetType().Equals("movies"))
70 success = db.GetMoviesByWhere("videodb://1/2/", playlist.GetWhereClause(db), playlist.GetOrderClause(db), items, true);
71 items.SetContent("movies");
74 else if (playlist.GetType().Equals("albums"))
78 success = db.GetAlbumsByWhere("musicdb://3/", playlist.GetWhereClause(db), playlist.GetOrderClause(db), items);
79 items.SetContent("albums");
82 if (playlist.GetType().Equals("songs") || playlist.GetType().Equals("mixed") || playlist.GetType().IsEmpty())
86 CStdString type=playlist.GetType();
89 if (playlist.GetType().Equals("mixed"))
90 playlist.SetType("songs");
92 CStdString whereOrder = playlist.GetWhereClause(db) + " " + playlist.GetOrderClause(db);
93 success = db.GetSongsByWhere("", whereOrder, items);
94 items.SetContent("songs");
96 playlist.SetType(type);
98 if (playlist.GetType().Equals("musicvideos") || playlist.GetType().Equals("mixed"))
102 CStdString type=playlist.GetType();
103 if (playlist.GetType().Equals("mixed"))
104 playlist.SetType("musicvideos");
105 CStdString whereOrder = playlist.GetWhereClause(db) + " " + playlist.GetOrderClause(db);
106 CFileItemList items2;
107 success2 = db.GetMusicVideosByWhere("videodb://3/2/", whereOrder, items2, false); // TODO: SMARTPLAYLISTS Don't check locks???
109 items.Append(items2);
111 items.SetContent("musicvideos");
112 playlist.SetType(type);
114 items.SetLabel(playlist.GetName());
115 // go through and set the playlist order
116 for (int i = 0; i < items.Size(); i++)
118 CFileItemPtr item = items[i];
119 item->m_iprogramCount = i; // hack for playlist order
121 if (playlist.GetType().Equals("mixed"))
122 return success || success2;
123 else if (playlist.GetType().Equals("musicvideos"))
129 bool CSmartPlaylistDirectory::ContainsFiles(const CStdString& strPath)
131 // smart playlists always have files??
135 CStdString CSmartPlaylistDirectory::GetPlaylistByName(const CStdString& name, const CStdString& playlistType)
138 bool filesExist = false;
139 if (playlistType == "songs" || playlistType == "albums")
140 filesExist = CDirectory::GetDirectory("special://musicplaylists/", list, "*.xsp");
141 else // all others are video
142 filesExist = CDirectory::GetDirectory("special://videoplaylists/", list, "*.xsp");
145 for (int i = 0; i < list.Size(); i++)
147 CFileItemPtr item = list[i];
148 if (item->GetLabel().CompareNoCase(name) == 0)
150 return item->m_strPath;
157 bool CSmartPlaylistDirectory::Remove(const char *strPath)
159 return XFILE::CFile::Delete(strPath);