Merge pull request #25808 from CastagnaIT/fix_url_parse
[xbmc.git] / xbmc / filesystem / SourcesDirectory.cpp
blob166861e32341c1f1a960ecac344590812d95ce27
1 /*
2 * Copyright (C) 2005-2020 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
9 #include "SourcesDirectory.h"
11 #include "FileItem.h"
12 #include "FileItemList.h"
13 #include "ServiceBroker.h"
14 #include "URL.h"
15 #include "Util.h"
16 #include "guilib/TextureManager.h"
17 #include "media/MediaLockState.h"
18 #include "music/MusicFileItemClassify.h"
19 #include "network/NetworkFileItemClassify.h"
20 #include "profiles/ProfileManager.h"
21 #include "settings/MediaSourceSettings.h"
22 #include "storage/MediaManager.h"
23 #include "utils/FileUtils.h"
24 #include "utils/URIUtils.h"
25 #include "video/VideoFileItemClassify.h"
27 using namespace KODI;
28 using namespace XFILE;
30 CSourcesDirectory::CSourcesDirectory(void) = default;
32 CSourcesDirectory::~CSourcesDirectory(void) = default;
34 bool CSourcesDirectory::GetDirectory(const CURL& url, CFileItemList &items)
36 // break up our path
37 // format is: sources://<type>/
38 std::string type(url.GetFileName());
39 URIUtils::RemoveSlashAtEnd(type);
41 VECSOURCES sources;
42 VECSOURCES *sourcesFromType = CMediaSourceSettings::GetInstance().GetSources(type);
43 if (!sourcesFromType)
44 return false;
46 sources = *sourcesFromType;
47 CServiceBroker::GetMediaManager().GetRemovableDrives(sources);
49 return GetDirectory(sources, items);
52 bool CSourcesDirectory::GetDirectory(const VECSOURCES &sources, CFileItemList &items)
54 for (unsigned int i = 0; i < sources.size(); ++i)
56 const CMediaSource& share = sources[i];
57 CFileItemPtr pItem(new CFileItem(share));
58 if (URIUtils::IsProtocol(pItem->GetPath(), "musicsearch"))
59 pItem->SetCanQueue(false);
61 std::string strIcon;
62 // We have the real DVD-ROM, set icon on disktype
63 if (share.m_iDriveType == CMediaSource::SOURCE_TYPE_DVD && share.m_strThumbnailImage.empty())
65 CUtil::GetDVDDriveIcon( pItem->GetPath(), strIcon );
66 // CDetectDVDMedia::SetNewDVDShareUrl() caches disc thumb as special://temp/dvdicon.tbn
67 std::string strThumb = "special://temp/dvdicon.tbn";
68 if (CFileUtils::Exists(strThumb))
69 pItem->SetArt("thumb", strThumb);
71 else if (URIUtils::IsProtocol(pItem->GetPath(), "addons"))
72 strIcon = "DefaultHardDisk.png";
73 else if ( pItem->IsPath("special://musicplaylists/")
74 || pItem->IsPath("special://videoplaylists/"))
75 strIcon = "DefaultPlaylist.png";
76 else if (VIDEO::IsVideoDb(*pItem) || MUSIC::IsMusicDb(*pItem) || pItem->IsPlugin() ||
77 pItem->IsPath("musicsearch://"))
78 strIcon = "DefaultFolder.png";
79 else if (NETWORK::IsRemote(*pItem))
80 strIcon = "DefaultNetwork.png";
81 else if (pItem->IsISO9660())
82 strIcon = "DefaultDVDRom.png";
83 else if (pItem->IsDVD())
84 strIcon = "DefaultDVDFull.png";
85 else if (pItem->IsBluray())
86 strIcon = "DefaultBluray.png";
87 else if (MUSIC::IsCDDA(*pItem))
88 strIcon = "DefaultCDDA.png";
89 else if (pItem->IsRemovable() && CServiceBroker::GetGUI()->GetTextureManager().HasTexture("DefaultRemovableDisk.png"))
90 strIcon = "DefaultRemovableDisk.png";
91 else
92 strIcon = "DefaultHardDisk.png";
94 pItem->SetArt("icon", strIcon);
95 if (share.m_iHasLock == LOCK_STATE_LOCKED &&
96 m_profileManager->GetMasterProfile().getLockMode() != LOCK_MODE_EVERYONE)
97 pItem->SetOverlayImage(CGUIListItem::ICON_OVERLAY_LOCKED);
98 else
99 pItem->SetOverlayImage(CGUIListItem::ICON_OVERLAY_NONE);
101 items.Add(pItem);
103 return true;
106 bool CSourcesDirectory::Exists(const CURL& url)
108 return true;