Merge pull request #4857 from t-nelson/Gotham_13.2_backports
[vuplus_xbmc] / xbmc / filesystem / SourcesDirectory.cpp
1 /*
2  *      Copyright (C) 2005-2013 Team XBMC
3  *      http://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, see
17  *  <http://www.gnu.org/licenses/>.
18  *
19  */
20
21 #include "SourcesDirectory.h"
22 #include "utils/URIUtils.h"
23 #include "URL.h"
24 #include "Util.h"
25 #include "FileItem.h"
26 #include "File.h"
27 #include "profiles/ProfilesManager.h"
28 #include "settings/MediaSourceSettings.h"
29 #include "guilib/TextureManager.h"
30 #include "storage/MediaManager.h"
31 #include "utils/StringUtils.h"
32
33 using namespace XFILE;
34
35 CSourcesDirectory::CSourcesDirectory(void)
36 {
37 }
38
39 CSourcesDirectory::~CSourcesDirectory(void)
40 {
41 }
42
43 bool CSourcesDirectory::GetDirectory(const CStdString& strPath, CFileItemList &items)
44 {
45   // break up our path
46   // format is:  sources://<type>/
47   CURL url(strPath);
48   CStdString type(url.GetFileName());
49   URIUtils::RemoveSlashAtEnd(type);
50
51   VECSOURCES sources;
52   VECSOURCES *sourcesFromType = CMediaSourceSettings::Get().GetSources(type);
53   if (sourcesFromType)
54     sources = *sourcesFromType;
55   g_mediaManager.GetRemovableDrives(sources);
56
57   if (!sourcesFromType)
58     return false;
59
60   return GetDirectory(sources, items);
61 }
62
63 bool CSourcesDirectory::GetDirectory(const VECSOURCES &sources, CFileItemList &items)
64 {
65   for (unsigned int i = 0; i < sources.size(); ++i)
66   {
67     const CMediaSource& share = sources[i];
68     CFileItemPtr pItem(new CFileItem(share));
69     if (StringUtils::StartsWithNoCase(pItem->GetPath(), "musicsearch://"))
70       pItem->SetCanQueue(false);
71     
72     CStdString strIcon;
73     // We have the real DVD-ROM, set icon on disktype
74     if (share.m_iDriveType == CMediaSource::SOURCE_TYPE_DVD && share.m_strThumbnailImage.empty())
75     {
76       CUtil::GetDVDDriveIcon( pItem->GetPath(), strIcon );
77       // CDetectDVDMedia::SetNewDVDShareUrl() caches disc thumb as special://temp/dvdicon.tbn
78       CStdString strThumb = "special://temp/dvdicon.tbn";
79       if (XFILE::CFile::Exists(strThumb))
80         pItem->SetArt("thumb", strThumb);
81     }
82     else if (StringUtils::StartsWith(pItem->GetPath(), "addons://"))
83       strIcon = "DefaultHardDisk.png";
84     else if (   pItem->IsVideoDb()
85              || pItem->IsMusicDb()
86              || pItem->IsPlugin()
87              || pItem->GetPath() == "special://musicplaylists/"
88              || pItem->GetPath() == "special://videoplaylists/"
89              || pItem->GetPath() == "musicsearch://")
90       strIcon = "DefaultFolder.png";
91     else if (pItem->IsRemote())
92       strIcon = "DefaultNetwork.png";
93     else if (pItem->IsISO9660())
94       strIcon = "DefaultDVDRom.png";
95     else if (pItem->IsDVD())
96       strIcon = "DefaultDVDRom.png";
97     else if (pItem->IsCDDA())
98       strIcon = "DefaultCDDA.png";
99     else if (pItem->IsRemovable() && g_TextureManager.HasTexture("DefaultRemovableDisk.png"))
100       strIcon = "DefaultRemovableDisk.png";
101     else
102       strIcon = "DefaultHardDisk.png";
103     
104     pItem->SetIconImage(strIcon);
105     if (share.m_iHasLock == 2 && CProfilesManager::Get().GetMasterProfile().getLockMode() != LOCK_MODE_EVERYONE)
106       pItem->SetOverlayImage(CGUIListItem::ICON_OVERLAY_LOCKED);
107     else
108       pItem->SetOverlayImage(CGUIListItem::ICON_OVERLAY_NONE);
109     
110     items.Add(pItem);
111   }
112   return true;
113 }
114
115 bool CSourcesDirectory::Exists(const char* strPath)
116 {
117   return true;
118 }