2 * Copyright (C) 2005-2013 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, see
17 * <http://www.gnu.org/licenses/>.
21 #include "VideoDatabaseDirectory.h"
22 #include "utils/URIUtils.h"
23 #include "VideoDatabaseDirectory/QueryParams.h"
24 #include "video/VideoDatabase.h"
25 #include "guilib/TextureManager.h"
28 #include "settings/Settings.h"
29 #include "utils/Crc32.h"
30 #include "guilib/LocalizeStrings.h"
31 #include "utils/LegacyPathTranslation.h"
32 #include "utils/log.h"
35 using namespace XFILE;
36 using namespace VIDEODATABASEDIRECTORY;
38 CVideoDatabaseDirectory::CVideoDatabaseDirectory(void)
42 CVideoDatabaseDirectory::~CVideoDatabaseDirectory(void)
46 bool CVideoDatabaseDirectory::GetDirectory(const CStdString& strPath, CFileItemList &items)
48 CStdString path = CLegacyPathTranslation::TranslateVideoDbPath(strPath);
50 auto_ptr<CDirectoryNode> pNode(CDirectoryNode::ParseURL(path));
55 bool bResult = pNode->GetChilds(items);
56 for (int i=0;i<items.Size();++i)
58 CFileItemPtr item = items[i];
59 if (item->m_bIsFolder && !item->HasIcon() && !item->HasArt("thumb"))
61 CStdString strImage = GetIcon(item->GetPath());
62 if (!strImage.IsEmpty() && g_TextureManager.HasTexture(strImage))
63 item->SetIconImage(strImage);
66 items.SetLabel(pNode->GetLocalizedName());
71 NODE_TYPE CVideoDatabaseDirectory::GetDirectoryChildType(const CStdString& strPath)
73 CStdString path = CLegacyPathTranslation::TranslateVideoDbPath(strPath);
74 auto_ptr<CDirectoryNode> pNode(CDirectoryNode::ParseURL(path));
77 return NODE_TYPE_NONE;
79 return pNode->GetChildType();
82 NODE_TYPE CVideoDatabaseDirectory::GetDirectoryType(const CStdString& strPath)
84 CStdString path = CLegacyPathTranslation::TranslateVideoDbPath(strPath);
85 auto_ptr<CDirectoryNode> pNode(CDirectoryNode::ParseURL(path));
88 return NODE_TYPE_NONE;
90 return pNode->GetType();
93 NODE_TYPE CVideoDatabaseDirectory::GetDirectoryParentType(const CStdString& strPath)
95 CStdString path = CLegacyPathTranslation::TranslateVideoDbPath(strPath);
96 auto_ptr<CDirectoryNode> pNode(CDirectoryNode::ParseURL(path));
99 return NODE_TYPE_NONE;
101 CDirectoryNode* pParentNode=pNode->GetParent();
104 return NODE_TYPE_NONE;
106 return pParentNode->GetChildType();
109 bool CVideoDatabaseDirectory::GetQueryParams(const CStdString& strPath, CQueryParams& params)
111 CStdString path = CLegacyPathTranslation::TranslateVideoDbPath(strPath);
112 auto_ptr<CDirectoryNode> pNode(CDirectoryNode::ParseURL(path));
117 CDirectoryNode::GetDatabaseInfo(strPath,params);
121 void CVideoDatabaseDirectory::ClearDirectoryCache(const CStdString& strDirectory)
123 CStdString path = CLegacyPathTranslation::TranslateVideoDbPath(strDirectory);
124 URIUtils::RemoveSlashAtEnd(path);
127 crc.ComputeFromLowerCase(path);
129 CStdString strFileName;
130 strFileName.Format("special://temp/%08x.fi", (unsigned __int32) crc);
131 CFile::Delete(strFileName);
134 bool CVideoDatabaseDirectory::IsAllItem(const CStdString& strDirectory)
136 if (strDirectory.Right(4).Equals("/-1/"))
141 bool CVideoDatabaseDirectory::GetLabel(const CStdString& strDirectory, CStdString& strLabel)
145 CStdString path = CLegacyPathTranslation::TranslateVideoDbPath(strDirectory);
146 auto_ptr<CDirectoryNode> pNode(CDirectoryNode::ParseURL(path));
147 if (!pNode.get() || path.IsEmpty())
150 // first see if there's any filter criteria
152 CDirectoryNode::GetDatabaseInfo(path, params);
154 CVideoDatabase videodatabase;
155 if (!videodatabase.Open())
159 if (params.GetGenreId() != -1)
160 strLabel += videodatabase.GetGenreById(params.GetGenreId());
163 if (params.GetCountryId() != -1)
164 strLabel += videodatabase.GetCountryById(params.GetCountryId());
167 if (params.GetSetId() != -1)
168 strLabel += videodatabase.GetSetById(params.GetSetId());
171 if (params.GetTagId() != -1)
172 strLabel += videodatabase.GetTagById(params.GetTagId());
175 if (params.GetYear() != -1)
178 strTemp.Format("%i",params.GetYear());
179 if (!strLabel.IsEmpty())
184 if (strLabel.IsEmpty())
186 switch (pNode->GetChildType())
188 case NODE_TYPE_TITLE_MOVIES:
189 case NODE_TYPE_TITLE_TVSHOWS:
190 case NODE_TYPE_TITLE_MUSICVIDEOS:
191 strLabel = g_localizeStrings.Get(369); break;
192 case NODE_TYPE_ACTOR: // Actor
193 strLabel = g_localizeStrings.Get(344); break;
194 case NODE_TYPE_GENRE: // Genres
195 strLabel = g_localizeStrings.Get(135); break;
196 case NODE_TYPE_COUNTRY: // Countries
197 strLabel = g_localizeStrings.Get(20451); break;
198 case NODE_TYPE_YEAR: // Year
199 strLabel = g_localizeStrings.Get(562); break;
200 case NODE_TYPE_DIRECTOR: // Director
201 strLabel = g_localizeStrings.Get(20348); break;
202 case NODE_TYPE_SETS: // Sets
203 strLabel = g_localizeStrings.Get(20434); break;
204 case NODE_TYPE_TAGS: // Tags
205 strLabel = g_localizeStrings.Get(20459); break;
206 case NODE_TYPE_MOVIES_OVERVIEW: // Movies
207 strLabel = g_localizeStrings.Get(342); break;
208 case NODE_TYPE_TVSHOWS_OVERVIEW: // TV Shows
209 strLabel = g_localizeStrings.Get(20343); break;
210 case NODE_TYPE_RECENTLY_ADDED_MOVIES: // Recently Added Movies
211 strLabel = g_localizeStrings.Get(20386); break;
212 case NODE_TYPE_RECENTLY_ADDED_EPISODES: // Recently Added Episodes
213 strLabel = g_localizeStrings.Get(20387); break;
214 case NODE_TYPE_STUDIO: // Studios
215 strLabel = g_localizeStrings.Get(20388); break;
216 case NODE_TYPE_MUSICVIDEOS_OVERVIEW: // Music Videos
217 strLabel = g_localizeStrings.Get(20389); break;
218 case NODE_TYPE_RECENTLY_ADDED_MUSICVIDEOS: // Recently Added Music Videos
219 strLabel = g_localizeStrings.Get(20390); break;
220 case NODE_TYPE_SEASONS: // Seasons
221 strLabel = g_localizeStrings.Get(33054); break;
222 case NODE_TYPE_EPISODES: // Episodes
223 strLabel = g_localizeStrings.Get(20360); break;
225 CLog::Log(LOGWARNING, "%s - Unknown nodetype requested %d", __FUNCTION__, pNode->GetChildType());
233 CStdString CVideoDatabaseDirectory::GetIcon(const CStdString &strDirectory)
235 CStdString path = CLegacyPathTranslation::TranslateVideoDbPath(strDirectory);
236 switch (GetDirectoryChildType(path))
238 case NODE_TYPE_TITLE_MOVIES:
239 if (path.Equals("videodb://movies/titles/"))
241 if (CSettings::Get().GetBool("myvideos.flatten"))
242 return "DefaultMovies.png";
243 return "DefaultMovieTitle.png";
246 case NODE_TYPE_TITLE_TVSHOWS:
247 if (path.Equals("videodb://tvshows/titles/"))
249 if (CSettings::Get().GetBool("myvideos.flatten"))
250 return "DefaultTVShows.png";
251 return "DefaultTVShowTitle.png";
254 case NODE_TYPE_TITLE_MUSICVIDEOS:
255 if (path.Equals("videodb://musicvideos/titles/"))
257 if (CSettings::Get().GetBool("myvideos.flatten"))
258 return "DefaultMusicVideos.png";
259 return "DefaultMusicVideoTitle.png";
262 case NODE_TYPE_ACTOR: // Actor
263 return "DefaultActor.png";
264 case NODE_TYPE_GENRE: // Genres
265 return "DefaultGenre.png";
266 case NODE_TYPE_COUNTRY: // Countries
267 return "DefaultCountry.png";
268 case NODE_TYPE_SETS: // Sets
269 return "DefaultSets.png";
270 case NODE_TYPE_TAGS: // Tags
271 return "DefaultTags.png";
272 case NODE_TYPE_YEAR: // Year
273 return "DefaultYear.png";
274 case NODE_TYPE_DIRECTOR: // Director
275 return "DefaultDirector.png";
276 case NODE_TYPE_MOVIES_OVERVIEW: // Movies
277 return "DefaultMovies.png";
278 case NODE_TYPE_TVSHOWS_OVERVIEW: // TV Shows
279 return "DefaultTVShows.png";
280 case NODE_TYPE_RECENTLY_ADDED_MOVIES: // Recently Added Movies
281 return "DefaultRecentlyAddedMovies.png";
282 case NODE_TYPE_RECENTLY_ADDED_EPISODES: // Recently Added Episodes
283 return "DefaultRecentlyAddedEpisodes.png";
284 case NODE_TYPE_RECENTLY_ADDED_MUSICVIDEOS: // Recently Added Episodes
285 return "DefaultRecentlyAddedMusicVideos.png";
286 case NODE_TYPE_STUDIO: // Studios
287 return "DefaultStudios.png";
288 case NODE_TYPE_MUSICVIDEOS_OVERVIEW: // Music Videos
289 return "DefaultMusicVideos.png";
290 case NODE_TYPE_MUSICVIDEOS_ALBUM: // Music Videos - Albums
291 return "DefaultMusicAlbums.png";
293 CLog::Log(LOGWARNING, "%s - Unknown nodetype requested %s", __FUNCTION__, strDirectory.c_str());
300 bool CVideoDatabaseDirectory::ContainsMovies(const CStdString &path)
302 VIDEODATABASEDIRECTORY::NODE_TYPE type = GetDirectoryChildType(path);
303 if (type == VIDEODATABASEDIRECTORY::NODE_TYPE_TITLE_MOVIES || type == VIDEODATABASEDIRECTORY::NODE_TYPE_EPISODES || type == VIDEODATABASEDIRECTORY::NODE_TYPE_TITLE_MUSICVIDEOS) return true;
307 bool CVideoDatabaseDirectory::Exists(const char* strPath)
309 CStdString path = CLegacyPathTranslation::TranslateVideoDbPath(strPath);
310 auto_ptr<CDirectoryNode> pNode(CDirectoryNode::ParseURL(path));
315 if (pNode->GetChildType() == VIDEODATABASEDIRECTORY::NODE_TYPE_NONE)
321 bool CVideoDatabaseDirectory::CanCache(const CStdString& strPath)
323 CStdString path = CLegacyPathTranslation::TranslateVideoDbPath(strPath);
324 auto_ptr<CDirectoryNode> pNode(CDirectoryNode::ParseURL(path));
327 return pNode->CanCache();