void CMediaManager::GetNetworkLocations(VECSOURCES &locations, bool autolocations) { // Load our xml file LoadSources(); for (unsigned int i = 0; i < m_locations.size(); i++) { CMediaSource share; share.strPath = m_locations[i].path; CURL url(share.strPath); share.strName = url.GetWithoutUserDetails(); locations.push_back(share); } if (autolocations) { CMediaSource share; share.m_ignore = true; #ifdef HAS_FILESYSTEM_SMB share.strPath = "smb://"; share.strName = g_localizeStrings.Get(20171); locations.push_back(share); #endif #ifdef HAS_FILESYSTEM_NFS share.strPath = "nfs://"; share.strName = g_localizeStrings.Get(20259); locations.push_back(share); #endif// HAS_FILESYSTEM_NFS #ifdef HAS_UPNP if (CServiceBroker::GetSettings().GetBool(CSettings::SETTING_SERVICES_UPNP)) { std::string strDevices = g_localizeStrings.Get(33040); //"% Devices" share.strPath = "upnp://"; share.strName = StringUtils::Format(strDevices.c_str(), "UPnP"); //"UPnP Devices" locations.push_back(share); } #endif #ifdef HAS_ZEROCONF share.strPath = "zeroconf://"; share.strName = g_localizeStrings.Get(20262); locations.push_back(share); #endif if (CServiceBroker::IsBinaryAddonCacheUp()) { for (const auto& addon : CServiceBroker::GetVFSAddonCache().GetAddonInstances()) { const auto& info = addon->GetProtocolInfo(); if (!info.type.empty() && info.supportBrowsing) { share.strPath = info.type + "://"; share.strName = g_localizeStrings.Get(info.label); locations.push_back(share); } } } } }
void CGUIDialogNetworkSetup::OnServerBrowse() { // open a filebrowser dialog with the current address VECSOURCES shares; std::string path = ConstructPath(); // get the share as the base path CMediaSource share; std::string basePath = path; std::string tempPath; while (URIUtils::GetParentPath(basePath, tempPath)) basePath = tempPath; share.strPath = basePath; // don't include the user details in the share name CURL url(share.strPath); share.strName = url.GetWithoutUserDetails(); shares.push_back(share); if (CGUIDialogFileBrowser::ShowAndGetDirectory(shares, g_localizeStrings.Get(1015), path)) { SetPath(path); UpdateButtons(); } }
CStdString CGUIWindowMusicSongs::GetStartFolder(const CStdString &dir) { SetupShares(); VECSOURCES shares; m_rootDir.GetSources(shares); bool bIsSourceName = false; int iIndex = CUtil::GetMatchingSource(dir, shares, bIsSourceName); if (iIndex > -1) { if (iIndex < (int)shares.size() && shares[iIndex].m_iHasLock == 2) { CFileItem item(shares[iIndex]); if (!g_passwordManager.IsItemUnlocked(&item,"music")) return ""; } // set current directory to matching share if (bIsSourceName) return shares[iIndex].strPath; return dir; } return CGUIWindowMusicBase::GetStartFolder(dir); }
bool CSourcesDirectory::GetDirectory(const VECSOURCES &sources, CFileItemList &items) { for (unsigned int i = 0; i < sources.size(); ++i) { const CMediaSource& share = sources[i]; CFileItemPtr pItem(new CFileItem(share)); if (StringUtils::StartsWithNoCase(pItem->GetPath(), "musicsearch://")) pItem->SetCanQueue(false); CStdString strIcon; // We have the real DVD-ROM, set icon on disktype if (share.m_iDriveType == CMediaSource::SOURCE_TYPE_DVD && share.m_strThumbnailImage.empty()) { CUtil::GetDVDDriveIcon( pItem->GetPath(), strIcon ); // CDetectDVDMedia::SetNewDVDShareUrl() caches disc thumb as special://temp/dvdicon.tbn CStdString strThumb = "special://temp/dvdicon.tbn"; if (XFILE::CFile::Exists(strThumb)) pItem->SetArt("thumb", strThumb); } else if (StringUtils::StartsWith(pItem->GetPath(), "addons://")) strIcon = "DefaultHardDisk.png"; else if ( pItem->IsVideoDb() || pItem->IsMusicDb() || pItem->IsPlugin() || pItem->GetPath() == "special://musicplaylists/" || pItem->GetPath() == "special://videoplaylists/" || pItem->GetPath() == "musicsearch://") strIcon = "DefaultFolder.png"; else if (pItem->IsRemote()) strIcon = "DefaultNetwork.png"; else if (pItem->IsISO9660()) strIcon = "DefaultDVDRom.png"; else if (pItem->IsDVD()) strIcon = "DefaultDVDRom.png"; else if (pItem->IsCDDA()) strIcon = "DefaultCDDA.png"; else if (pItem->IsRemovable() && g_TextureManager.HasTexture("DefaultRemovableDisk.png")) strIcon = "DefaultRemovableDisk.png"; else strIcon = "DefaultHardDisk.png"; pItem->SetIconImage(strIcon); if (share.m_iHasLock == 2 && CProfilesManager::Get().GetMasterProfile().getLockMode() != LOCK_MODE_EVERYONE) pItem->SetOverlayImage(CGUIListItem::ICON_OVERLAY_LOCKED); else pItem->SetOverlayImage(CGUIListItem::ICON_OVERLAY_NONE); items.Add(pItem); } return true; }
void CVirtualDirectory::GetSources(VECSOURCES &shares) const { shares = m_vecSources; // add our plug n play shares if (m_allowNonLocalSources) g_mediaManager.GetRemovableDrives(shares); #ifdef HAS_DVD_DRIVE // and update our dvd share for (unsigned int i = 0; i < shares.size(); ++i) { CMediaSource& share = shares[i]; if (share.m_iDriveType == CMediaSource::SOURCE_TYPE_DVD) { if(g_mediaManager.IsAudio(share.strPath)) { share.strStatus = "Audio-CD"; share.strPath = "cdda://local/"; share.strDiskUniqueId = ""; } else { share.strStatus = g_mediaManager.GetDiskLabel(share.strPath); share.strDiskUniqueId = g_mediaManager.GetDiskUniqueId(share.strPath); if (!share.strPath.length()) // unmounted CD { if (g_mediaManager.GetDiscPath() == "iso9660://") share.strPath = "iso9660://"; else // share is unmounted and not iso9660, discard it shares.erase(shares.begin() + i--); } } } } #endif }
bool CGUIDialogProfileSettings::GetProfilePath(std::string &directory, bool isDefault) { VECSOURCES shares; CMediaSource share; share.strName = g_localizeStrings.Get(13200); share.strPath = "special://masterprofile/profiles/"; shares.push_back(share); std::string strDirectory; if (directory.empty()) strDirectory = share.strPath; else strDirectory = URIUtils::AddFileToFolder("special://masterprofile/", directory); if (!CGUIDialogFileBrowser::ShowAndGetDirectory(shares, g_localizeStrings.Get(657), strDirectory, true)) return false; directory = strDirectory; if (!isDefault) directory.erase(0, 24); return true; }
bool CVirtualPathDirectory::GetMatchingSource(const CStdString &strPath, CMediaSource& share) { CStdString strType, strSource; if (!GetTypeAndSource(strPath, strType, strSource)) return false; // no support for "files" operation if (strType == "files") return false; VECSOURCES *VECSOURCES = g_settings.GetSourcesFromType(strType); if (!VECSOURCES) return false; bool bIsSourceName = false; int iIndex = CUtil::GetMatchingSource(strSource, *VECSOURCES, bIsSourceName); if (!bIsSourceName) return false; if (iIndex < 0 || iIndex >= (int)VECSOURCES->size()) return false; share = (*VECSOURCES)[iIndex]; return true; }
void CHALProvider::GetRemovableDrives(VECSOURCES &removableDrives) { std::vector<CStorageDevice> devices = g_HalManager.GetVolumeDevices(); for (size_t i = 0; i < devices.size(); i++) { if (devices[i].Mounted && devices[i].Approved && devices[i].HotPlugged) { CMediaSource share; devices[i].toMediaSource(&share); removableDrives.push_back(share); } } }
bool CMediaSourceSettings::SetSources(TiXmlNode *root, const char *section, const VECSOURCES &shares, const std::string &defaultPath) const { TiXmlElement sectionElement(section); TiXmlNode *sectionNode = root->InsertEndChild(sectionElement); if (sectionNode == NULL) return false; XMLUtils::SetPath(sectionNode, "default", defaultPath); for (CIVECSOURCES it = shares.begin(); it != shares.end(); it++) { const CMediaSource &share = *it; if (share.m_ignore) continue; TiXmlElement source(XML_SOURCE); XMLUtils::SetString(&source, "name", share.strName); for (unsigned int i = 0; i < share.vecPaths.size(); i++) XMLUtils::SetPath(&source, "path", share.vecPaths[i]); if (share.m_iHasLock) { XMLUtils::SetInt(&source, "lockmode", share.m_iLockMode); XMLUtils::SetString(&source, "lockcode", share.m_strLockCode); XMLUtils::SetInt(&source, "badpwdcount", share.m_iBadPwdCount); } if (!share.m_strThumbnailImage.empty()) XMLUtils::SetPath(&source, "thumbnail", share.m_strThumbnailImage); XMLUtils::SetBoolean(&source, "allowsharing", share.m_allowSharing); sectionNode->InsertEndChild(source); } return true; }
// \brief Show CGUIDialogMediaSource dialog and prompt for a new media source. // \return True if the media source is added, false otherwise. bool CGUIDialogMediaSource::ShowAndAddMediaSource(const CStdString &type) { CGUIDialogMediaSource *dialog = (CGUIDialogMediaSource *)g_windowManager.GetWindow(WINDOW_DIALOG_MEDIA_SOURCE); if (!dialog) return false; dialog->Initialize(); dialog->SetShare(CMediaSource()); dialog->SetTypeOfMedia(type); dialog->DoModal(); bool confirmed(dialog->IsConfirmed()); if (confirmed) { // yay, add this share CMediaSource share; unsigned int i,j=2; bool bConfirmed=false; VECSOURCES* pShares = CMediaSourceSettings::Get().GetSources(type); CStdString strName = dialog->m_name; while (!bConfirmed) { for (i=0;i<pShares->size();++i) { if ((*pShares)[i].strName.Equals(strName)) break; } if (i < pShares->size()) // found a match - try next strName = StringUtils::Format("%s (%i)", dialog->m_name.c_str(), j++); else bConfirmed = true; } share.FromNameAndPaths(type, strName, dialog->GetPaths()); if (dialog->m_paths->Size() > 0) { share.m_strThumbnailImage = dialog->m_paths->Get(0)->GetArt("thumb"); } CMediaSourceSettings::Get().AddShare(type, share); } dialog->m_paths->Clear(); return confirmed; }
void CMediaManager::GetNetworkLocations(VECSOURCES &locations, bool autolocations) { // Load our xml file LoadSources(); for (unsigned int i = 0; i < m_locations.size(); i++) { CMediaSource share; share.strPath = m_locations[i].path; CURL url(share.strPath); share.strName = url.GetWithoutUserDetails(); locations.push_back(share); } if (autolocations) { CMediaSource share; share.m_ignore = true; #ifdef HAS_FILESYSTEM_SMB share.strPath = "smb://"; share.strName = g_localizeStrings.Get(20171); locations.push_back(share); #endif #ifdef HAS_FILESYSTEM_NFS share.strPath = "nfs://"; share.strName = g_localizeStrings.Get(20259); locations.push_back(share); #endif// HAS_FILESYSTEM_NFS share.strPath = "upnp://"; share.strName = "UPnP Devices"; locations.push_back(share); share.strPath = "zeroconf://"; share.strName = "Zeroconf Browser"; locations.push_back(share); } }
void CGUIDialogMusicInfo::AddItemPathToFileBrowserSources(VECSOURCES &sources, const CFileItem &item) { std::string itemDir; std::string artistFolder; itemDir = item.GetPath(); if (item.HasMusicInfoTag()) { if (item.GetMusicInfoTag()->GetType() == MediaTypeSong) itemDir = URIUtils::GetParentPath(item.GetMusicInfoTag()->GetURL()); // For artist add Artist Info Folder path to browser sources if (item.GetMusicInfoTag()->GetType() == MediaTypeArtist) { artistFolder = CServiceBroker::GetSettings().GetString(CSettings::SETTING_MUSICLIBRARY_ARTISTSFOLDER); if (!artistFolder.empty() && artistFolder.compare(itemDir) == 0) itemDir.clear(); // skip *item when artist not have a unique path } } // Add "*Item folder" path to file browser sources if (!itemDir.empty() && CDirectory::Exists(itemDir)) { CMediaSource itemSource; itemSource.strName = g_localizeStrings.Get(36041); itemSource.strPath = itemDir; sources.push_back(itemSource); } // For artist add Artist Info Folder path to browser sources if (!artistFolder.empty() && CDirectory::Exists(artistFolder)) { CMediaSource itemSource; itemSource.strName = "* " + g_localizeStrings.Get(20223); itemSource.strPath = artistFolder; sources.push_back(itemSource); } }
void CAndroidStorageProvider::GetRemovableDrives(VECSOURCES &removableDrives) { for (const auto& mountStr : GetRemovableDrives()) { // Reject unreadable if (XFILE::CDirectory::Exists(mountStr)) { CMediaSource share; share.strPath = unescape(mountStr); share.strName = URIUtils::GetFileName(mountStr); share.m_ignore = true; removableDrives.push_back(share); } } }
bool CGUIPassword::IsDatabasePathUnlocked(const std::string& strPath, VECSOURCES& vecSources) { if (g_passwordManager.bMasterUser || CProfilesManager::Get().GetMasterProfile().getLockMode() == LOCK_MODE_EVERYONE) return true; // try to find the best matching source bool bName = false; int iIndex = CUtil::GetMatchingSource(strPath, vecSources, bName); if (iIndex > -1 && iIndex < (int)vecSources.size()) if (vecSources[iIndex].m_iHasLock < 2) return true; return false; }
/*! \brief Set a skin image setting. * \param params The parameters. * \details params[0] = Name of skin setting. * params[1] = Extra URL to allow selection from (optional). */ static int SetImage(const std::vector<std::string>& params) { int string = CSkinSettings::Get().TranslateString(params[0]); std::string value = CSkinSettings::Get().GetString(string); VECSOURCES localShares; g_mediaManager.GetLocalDrives(localShares); if (params.size() > 1) { value = params[1]; URIUtils::AddSlashAtEnd(value); bool bIsSource; if (CUtil::GetMatchingSource(value,localShares,bIsSource) < 0) // path is outside shares - add it as a separate one { CMediaSource share; share.strName = g_localizeStrings.Get(13278); share.strPath = value; localShares.push_back(share); } } if (CGUIDialogFileBrowser::ShowAndGetImage(localShares, g_localizeStrings.Get(1030), value)) CSkinSettings::Get().SetString(string, value); return 0; }
CStdString CGUIWindowPictures::GetStartFolder(const CStdString &dir) { if (dir.Equals("Plugins") || dir.Equals("Addons")) return "addons://sources/image/"; SetupShares(); VECSOURCES shares; m_rootDir.GetSources(shares); bool bIsSourceName = false; int iIndex = CUtil::GetMatchingSource(dir, shares, bIsSourceName); if (iIndex > -1) { if (iIndex < (int)shares.size() && shares[iIndex].m_iHasLock == 2) { CFileItem item(shares[iIndex]); if (!g_passwordManager.IsItemUnlocked(&item,"pictures")) return ""; } if (bIsSourceName) return shares[iIndex].strPath; return dir; } return CGUIMediaWindow::GetStartFolder(dir); }
bool CGUIDialogMediaSource::ShowAndEditMediaSource(const CStdString &type, const CMediaSource &share) { CStdString strOldName = share.strName; CGUIDialogMediaSource *dialog = (CGUIDialogMediaSource *)g_windowManager.GetWindow(WINDOW_DIALOG_MEDIA_SOURCE); if (!dialog) return false; dialog->Initialize(); dialog->SetShare(share); dialog->SetTypeOfMedia(type, true); dialog->DoModal(); bool confirmed(dialog->IsConfirmed()); if (confirmed) { // yay, add this share unsigned int i,j=2; bool bConfirmed=false; VECSOURCES* pShares = g_settings.GetSourcesFromType(type); CStdString strName = dialog->m_name; while (!bConfirmed) { for (i=0; i<pShares->size(); ++i) { if ((*pShares)[i].strName.Equals(strName)) break; } if (i < pShares->size() && (*pShares)[i].strName != strOldName) // found a match - try next strName.Format("%s (%i)",dialog->m_name,j++); else bConfirmed = true; } CMediaSource newShare; newShare.FromNameAndPaths(type, strName, dialog->GetPaths()); g_settings.UpdateShare(type, strOldName, newShare); } dialog->m_paths->Clear(); return confirmed; }
JSONRPC_STATUS CFileOperations::GetRootDirectory(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant ¶meterObject, CVariant &result) { CStdString media = parameterObject["media"].asString(); media = media.ToLower(); VECSOURCES *sources = g_settings.GetSourcesFromType(media); if (sources) { CFileItemList items; for (unsigned int i = 0; i < (unsigned int)sources->size(); i++) { // Do not show sources which are locked if (sources->at(i).m_iHasLock == 2) continue; items.Add(CFileItemPtr(new CFileItem(sources->at(i)))); } for (unsigned int i = 0; i < (unsigned int)items.Size(); i++) { if (items[i]->IsSmb()) { CURL url(items[i]->GetPath()); items[i]->SetPath(url.GetWithoutUserDetails()); } } CVariant param = parameterObject; param["properties"] = CVariant(CVariant::VariantTypeArray); param["properties"].append("file"); HandleFileItemList(NULL, true, "sources", items, param, result); } return OK; }
bool CMediaSourceSettings::DeleteSource(const std::string &strType, const std::string &strName, const std::string &strPath, bool virtualSource /* = false */) { VECSOURCES *pShares = GetSources(strType); if (pShares == NULL) return false; bool found = false; for (IVECSOURCES it = pShares->begin(); it != pShares->end(); it++) { if (it->strName == strName && it->strPath == strPath) { CLog::Log(LOGDEBUG, "CMediaSourceSettings: found share, removing!"); pShares->erase(it); found = true; break; } } if (virtualSource) return found; return Save(); }
void CMemoryUnitManager::GetMemoryUnitSources(VECSOURCES &shares) { for (unsigned int i = 0; i < m_memUnits.size(); i++) { CMediaSource share; CStdString volumeName = m_memUnits[i]->GetVolumeName(); volumeName.TrimRight(' '); // Memory Unit # (volumeName) (fs) if (volumeName.IsEmpty()) share.strName.Format("%s %i (%s)", g_localizeStrings.Get(20136).c_str(), i + 1, m_memUnits[i]->GetFileSystem()); else share.strName.Format("%s %i (%s) (%s)", g_localizeStrings.Get(20136).c_str(), i + 1, volumeName.c_str(), m_memUnits[i]->GetFileSystem()); share.strPath.Format("mem%i://", i); shares.push_back(share); } }
void CWin32StorageProvider::GetLocalDrives(VECSOURCES &localDrives) { CMediaSource share; wchar_t profilePath[MAX_PATH]; if (SUCCEEDED(SHGetFolderPath(nullptr, CSIDL_PROFILE, nullptr, 0, profilePath)) || GetEnvironmentVariable(L"USERPROFILE", profilePath, MAX_PATH) > 0) share.strPath = KODI::PLATFORM::WINDOWS::FromW(profilePath); else share.strPath = CSpecialProtocol::TranslatePath("special://home"); share.strName = g_localizeStrings.Get(21440); share.m_ignore = true; share.m_iDriveType = CMediaSource::SOURCE_TYPE_LOCAL; localDrives.push_back(share); GetDrivesByType(localDrives, LOCAL_DRIVES); }
void CGUIDialogMusicInfo::AddItemPathToFileBrowserSources(VECSOURCES &sources, const CFileItem &item) { std::string itemDir; if (item.HasMusicInfoTag() && item.GetMusicInfoTag()->GetType() == MediaTypeSong) itemDir = URIUtils::GetParentPath(item.GetMusicInfoTag()->GetURL()); else itemDir = item.GetPath(); if (!itemDir.empty() && CDirectory::Exists(itemDir)) { CMediaSource itemSource; itemSource.strName = g_localizeStrings.Get(36041); itemSource.strPath = itemDir; sources.push_back(itemSource); } }
void CDarwinStorageProvider::GetRemovableDrives(VECSOURCES &removableDrives) { #if defined(TARGET_DARWIN_OSX) DASessionRef session = DASessionCreate(kCFAllocatorDefault); if (session) { unsigned i, count = 0; struct statfs *buf = NULL; std::string mountpoint, devicepath; count = getmntinfo(&buf, 0); for (i=0; i<count; i++) { mountpoint = buf[i].f_mntonname; devicepath = buf[i].f_mntfromname; DADiskRef disk = DADiskCreateFromBSDName(kCFAllocatorDefault, session, devicepath.c_str()); if (disk) { CFDictionaryRef details = DADiskCopyDescription(disk); if (details) { if (kCFBooleanTrue == CFDictionaryGetValue(details, kDADiskDescriptionMediaRemovableKey)) { CMediaSource share; share.strPath = mountpoint; Cocoa_GetVolumeNameFromMountPoint(mountpoint.c_str(), share.strName); share.m_ignore = true; removableDrives.push_back(share); } CFRelease(details); } CFRelease(disk); } } CFRelease(session); } #endif }
void CGUIDialogVideoInfo::AddItemPathToFileBrowserSources(VECSOURCES &sources, const CFileItem &item) { if (!item.HasVideoInfoTag()) return; CStdString itemDir = item.GetVideoInfoTag()->m_basePath; //season if (itemDir.IsEmpty()) itemDir = item.GetVideoInfoTag()->GetPath(); CFileItem itemTmp(itemDir, false); if (itemTmp.IsVideo()) itemDir = URIUtils::GetParentPath(itemDir); if (!itemDir.IsEmpty() && CDirectory::Exists(itemDir)) { CMediaSource itemSource; itemSource.strName = g_localizeStrings.Get(36041); itemSource.strPath = itemDir; sources.push_back(itemSource); } }
bool CGUIControlButtonSetting::GetPath(CSettingPath *pathSetting) { if (pathSetting == NULL) return false; CStdString path = pathSetting->GetValue(); VECSOURCES shares; const std::vector<std::string>& sources = pathSetting->GetSources(); for (std::vector<std::string>::const_iterator source = sources.begin(); source != sources.end(); ++source) { VECSOURCES *sources = CMediaSourceSettings::Get().GetSources(*source); if (sources != NULL) shares.insert(shares.end(), sources->begin(), sources->end()); } g_mediaManager.GetNetworkLocations(shares); g_mediaManager.GetLocalDrives(shares); if (!CGUIDialogFileBrowser::ShowAndGetDirectory(shares, g_localizeStrings.Get(pathSetting->GetHeading()), path, pathSetting->Writable())) return false; return pathSetting->SetValue(path); }
void CGUIDialogSmartPlaylistRule::OnBrowse() { CFileItemList items; CMusicDatabase database; database.Open(); CVideoDatabase videodatabase; videodatabase.Open(); VIDEODB_CONTENT_TYPE type = VIDEODB_CONTENT_MOVIES; if (m_type.Equals("tvshows")) type = VIDEODB_CONTENT_TVSHOWS; else if (m_type.Equals("musicvideos")) type = VIDEODB_CONTENT_MUSICVIDEOS; else if (m_type.Equals("episodes")) type = VIDEODB_CONTENT_EPISODES; int iLabel = 0; if (m_rule.m_field == FieldGenre) { if (m_type.Equals("tvshows") || m_type.Equals("episodes") || m_type.Equals("movies")) videodatabase.GetGenresNav("videodb://2/1/",items,type); else if (m_type.Equals("songs") || m_type.Equals("albums") || m_type.Equals("artists") || m_type.Equals("mixed")) database.GetGenresNav("musicdb://1/",items); if (m_type.Equals("musicvideos") || m_type.Equals("mixed")) { CFileItemList items2; videodatabase.GetGenresNav("videodb://3/1/",items2,VIDEODB_CONTENT_MUSICVIDEOS); items.Append(items2); } iLabel = 515; } else if (m_rule.m_field == FieldCountry) { videodatabase.GetCountriesNav("videodb://2/1/",items,type); iLabel = 574; } else if (m_rule.m_field == FieldArtist || m_rule.m_field == FieldAlbumArtist) { if (m_type.Equals("songs") || m_type.Equals("mixed") || m_type.Equals("albums") || m_type.Equals("artists")) database.GetArtistsNav("musicdb://2/", items, m_rule.m_field == FieldAlbumArtist, -1); if (m_type.Equals("musicvideos") || m_type.Equals("mixed")) { CFileItemList items2; videodatabase.GetMusicVideoArtistsByName("",items2); items.Append(items2); } iLabel = 557; } else if (m_rule.m_field == FieldAlbum) { if (m_type.Equals("songs") || m_type.Equals("mixed") || m_type.Equals("albums")) database.GetAlbumsNav("musicdb://3/", items); if (m_type.Equals("musicvideos") || m_type.Equals("mixed")) { CFileItemList items2; videodatabase.GetMusicVideoAlbumsByName("",items2); items.Append(items2); } iLabel = 558; } else if (m_rule.m_field == FieldActor) { videodatabase.GetActorsNav("",items,type); iLabel = 20337; } else if (m_rule.m_field == FieldYear) { if (m_type.Equals("songs") || m_type.Equals("mixed") || m_type.Equals("albums")) database.GetYearsNav("musicdb://9/", items); if (!m_type.Equals("songs") && !m_type.Equals("albums")) { CFileItemList items2; videodatabase.GetYearsNav("", items2, type); items.Append(items2); } iLabel = 562; } else if (m_rule.m_field == FieldDirector) { videodatabase.GetDirectorsNav("",items,type); iLabel = 20339; } else if (m_rule.m_field == FieldStudio) { videodatabase.GetStudiosNav("",items,type); iLabel = 572; } else if (m_rule.m_field == FieldWriter) { videodatabase.GetWritersNav("",items,type); iLabel = 20417; } else if (m_rule.m_field == FieldTvShowTitle) { videodatabase.GetTvShowsNav("videodb://2/2/",items); iLabel = 20343; } else if (m_rule.m_field == FieldPlaylist) { // use filebrowser to grab another smart playlist // Note: This can cause infinite loops (playlist that refers to the same playlist) but I don't // think there's any decent way to deal with this, as the infinite loop may be an arbitrary // number of playlists deep, eg playlist1 -> playlist2 -> playlist3 ... -> playlistn -> playlist1 CStdString path = "special://videoplaylists/"; if (m_type.Equals("songs") || m_type.Equals("albums")) path = "special://musicplaylists/"; XFILE::CDirectory::GetDirectory(path, items, ".xsp", XFILE::DIR_FLAG_NO_FILE_DIRS); for (int i = 0; i < items.Size(); i++) { CFileItemPtr item = items[i]; CSmartPlaylist playlist; if (playlist.OpenAndReadName(item->GetPath())) item->SetLabel(playlist.GetName()); } iLabel = 559; } else if (m_rule.m_field == FieldPath) { VECSOURCES sources; if (m_type == "songs" || m_type == "mixed") sources = *g_settings.GetSourcesFromType("music"); if (m_type != "songs") { VECSOURCES sources2 = *g_settings.GetSourcesFromType("video"); sources.insert(sources.end(),sources2.begin(),sources2.end()); } g_mediaManager.GetLocalDrives(sources); CStdString path = m_rule.GetLocalizedParameter(m_type); CGUIDialogFileBrowser::ShowAndGetDirectory(sources, g_localizeStrings.Get(657), path, false); if (m_rule.m_parameter.size() > 0) m_rule.m_parameter.clear(); if (!path.empty()) m_rule.m_parameter.push_back(path); UpdateButtons(); return; } else if (m_rule.m_field == FieldSet) { videodatabase.GetSetsNav("videodb://1/7/", items, VIDEODB_CONTENT_MOVIES); iLabel = 20434; } else if (m_rule.m_field == FieldTag) { if (m_type == "movies") videodatabase.GetTagsNav("videodb://1/9/", items, VIDEODB_CONTENT_MOVIES); else return; iLabel = 20459; } else { // TODO: Add browseability in here. assert(false); } // sort the items items.Sort(SORT_METHOD_LABEL, SortOrderAscending); CGUIDialogSelect* pDialog = (CGUIDialogSelect*)g_windowManager.GetWindow(WINDOW_DIALOG_SELECT); pDialog->Reset(); pDialog->SetItems(&items); CStdString strHeading; strHeading.Format(g_localizeStrings.Get(13401),g_localizeStrings.Get(iLabel)); pDialog->SetHeading(strHeading); pDialog->SetMultiSelection(true); if (!m_rule.m_parameter.empty()) pDialog->SetSelected(m_rule.m_parameter); pDialog->DoModal(); if (pDialog->IsConfirmed()) { const CFileItemList &items = pDialog->GetSelectedItems(); m_rule.m_parameter.clear(); for (int index = 0; index < items.Size(); index++) m_rule.m_parameter.push_back(items[index]->GetLabel()); UpdateButtons(); } pDialog->Reset(); }
void CGUIDialogMediaSource::OnPathBrowse(int item) { if (item < 0 || item > m_paths->Size()) return; // Browse is called. Open the filebrowser dialog. // Ignore current path is best at this stage?? CStdString path; bool allowNetworkShares(m_type != "programs"); VECSOURCES extraShares; if (m_name != CUtil::GetTitleFromPath(m_paths->Get(item)->GetPath())) m_bNameChanged=true; if (m_type == "music") { // add the music playlist location CMediaSource share1; share1.strPath = "special://musicplaylists/"; share1.strName = g_localizeStrings.Get(20011); share1.m_ignore = true; extraShares.push_back(share1); #ifdef HAS_FILESYSTEM_SMB share1.strPath = "smb://"; share1.strName = g_localizeStrings.Get(20171); extraShares.push_back(share1); #endif #ifdef HAS_FILESYSTEM_NFS share1.strPath = "nfs://"; share1.strName = g_localizeStrings.Get(20259); extraShares.push_back(share1); #endif// HAS_FILESYSTEM_NFS share1.strPath = "upnp://"; share1.strName = "UPnP Devices"; extraShares.push_back(share1); share1.strPath = "sap://"; share1.strName = "SAP Streams"; extraShares.push_back(share1); share1.strPath = "zeroconf://"; share1.strName = "Zeroconf Browser"; extraShares.push_back(share1); if (g_guiSettings.GetString("audiocds.recordingpath",false) != "") { share1.strPath = "special://recordings/"; share1.strName = g_localizeStrings.Get(21883); extraShares.push_back(share1); } if (g_guiSettings.GetString("scrobbler.lastfmusername") != "") { share1.strName = "Last.FM"; share1.strPath = "lastfm://"; extraShares.push_back(share1); } } else if (m_type == "video") { // add the music playlist location CMediaSource share1; share1.m_ignore = true; share1.strPath = "special://videoplaylists/"; share1.strName = g_localizeStrings.Get(20012); extraShares.push_back(share1); share1.strPath = "rtv://*/"; share1.strName = "ReplayTV Devices"; extraShares.push_back(share1); #ifdef HAS_FILESYSTEM_SMB share1.strPath = "smb://"; share1.strName = g_localizeStrings.Get(20171); extraShares.push_back(share1); #endif #ifdef HAS_FILESYSTEM_NFS share1.strPath = "nfs://"; share1.strName = g_localizeStrings.Get(20259); extraShares.push_back(share1); #endif// HAS_FILESYSTEM_NFS share1.strPath = "hdhomerun://"; share1.strName = "HDHomerun Devices"; extraShares.push_back(share1); share1.strPath = "sap://"; share1.strName = "SAP Streams"; extraShares.push_back(share1); share1.strPath = "upnp://"; share1.strName = "UPnP Devices"; extraShares.push_back(share1); share1.strPath = "zeroconf://"; share1.strName = "Zeroconf Browser"; extraShares.push_back(share1); } else if (m_type == "pictures") { CMediaSource share1; share1.m_ignore = true; if (g_guiSettings.GetString("debug.screenshotpath",false)!= "") { share1.strPath = "special://screenshots/"; share1.strName = g_localizeStrings.Get(20008); extraShares.push_back(share1); } #ifdef HAS_FILESYSTEM_SMB share1.strPath = "smb://"; share1.strName = g_localizeStrings.Get(20171); extraShares.push_back(share1); #endif #ifdef HAS_FILESYSTEM_NFS share1.strPath = "nfs://"; share1.strName = g_localizeStrings.Get(20259); extraShares.push_back(share1); #endif// HAS_FILESYSTEM_NFS share1.strPath = "upnp://"; share1.strName = "UPnP Devices"; extraShares.push_back(share1); share1.strPath = "zeroconf://"; share1.strName = "Zeroconf Browser"; extraShares.push_back(share1); } else if (m_type == "programs") { // nothing to add } if (CGUIDialogFileBrowser::ShowAndGetSource(path, allowNetworkShares, extraShares.size()==0?NULL:&extraShares)) { if (item < m_paths->Size()) // if the skin does funky things, m_paths may have been cleared m_paths->Get(item)->SetPath(path); if (!m_bNameChanged || m_name.IsEmpty()) { CURL url(path); m_name = url.GetWithoutUserDetails(); URIUtils::RemoveSlashAtEnd(m_name); m_name = CUtil::GetTitleFromPath(m_name); } UpdateButtons(); } }
JSONRPC_STATUS CFileOperations::GetDirectory(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant ¶meterObject, CVariant &result) { CStdString media = parameterObject["media"].asString(); media = media.ToLower(); CFileItemList items; CStdString strPath = parameterObject["directory"].asString(); // Check if this directory is part of a source and whether it's locked VECSOURCES *sources; bool isSource; for (unsigned int index = 0; index < SourcesSize; index++) { sources = g_settings.GetSourcesFromType(SourceNames[index]); int sourceIndex = CUtil::GetMatchingSource(strPath, *sources, isSource); if (sourceIndex >= 0 && sourceIndex < (int)sources->size() && sources->at(sourceIndex).m_iHasLock == 2) return InvalidParams; } CStdStringArray regexps; CStdString extensions = ""; if (media.Equals("video")) { regexps = g_advancedSettings.m_videoExcludeFromListingRegExps; extensions = g_settings.m_videoExtensions; } else if (media.Equals("music")) { regexps = g_advancedSettings.m_audioExcludeFromListingRegExps; extensions = g_settings.m_musicExtensions; } else if (media.Equals("pictures")) { regexps = g_advancedSettings.m_pictureExcludeFromListingRegExps; extensions = g_settings.m_pictureExtensions; } if (CDirectory::GetDirectory(strPath, items, extensions)) { CFileItemList filteredDirectories, filteredFiles; for (unsigned int i = 0; i < (unsigned int)items.Size(); i++) { if (CUtil::ExcludeFileOrFolder(items[i]->GetPath(), regexps)) continue; if (items[i]->IsSmb()) { CURL url(items[i]->GetPath()); items[i]->SetPath(url.GetWithoutUserDetails()); } if ((media == "video" && items[i]->HasVideoInfoTag()) || (media == "music" && items[i]->HasMusicInfoTag()) || (media == "picture" && items[i]->HasPictureInfoTag()) || media == "files") { if (items[i]->m_bIsFolder) filteredDirectories.Add(items[i]); else filteredFiles.Add(items[i]); } else { CFileItem fileItem; if (FillFileItem(items[i], fileItem, media)) { if (items[i]->m_bIsFolder) filteredDirectories.Add(CFileItemPtr(new CFileItem(fileItem))); else filteredFiles.Add(CFileItemPtr(new CFileItem(fileItem))); } else { if (items[i]->m_bIsFolder) filteredDirectories.Add(items[i]); else filteredFiles.Add(items[i]); } } } // Check if the "properties" list exists // and make sure it contains the "file" // field CVariant param = parameterObject; if (!param.isMember("properties")) param["properties"] = CVariant(CVariant::VariantTypeArray); bool hasFileField = false; for (CVariant::const_iterator_array itr = param["properties"].begin_array(); itr != param["properties"].end_array(); itr++) { if (itr->asString().compare("file") == 0) { hasFileField = true; break; } } if (!hasFileField) param["properties"].append("file"); HandleFileItemList("id", true, "files", filteredDirectories, param, result); for (unsigned int index = 0; index < result["files"].size(); index++) { result["files"][index]["filetype"] = "directory"; } int count = (int)result["limits"]["total"].asInteger(); HandleFileItemList("id", true, "files", filteredFiles, param, result); for (unsigned int index = count; index < result["files"].size(); index++) { result["files"][index]["filetype"] = "file"; } count += (int)result["limits"]["total"].asInteger(); result["limits"]["end"] = count; result["limits"]["total"] = count; return OK; } return InvalidParams; }
void CGUIDialogMediaSource::OnPathBrowse(int item) { if (item < 0 || item > m_paths->Size()) return; // Browse is called. Open the filebrowser dialog. // Ignore current path is best at this stage?? CStdString path; bool allowNetworkShares(m_type != "programs"); VECSOURCES extraShares; if (m_name != CUtil::GetTitleFromPath(m_paths->Get(item)->GetPath())) m_bNameChanged=true; if (m_type == "music") { CMediaSource share1; #if defined(TARGET_ANDROID) // add the default android music directory std::string path; if (CXBMCApp::GetExternalStorage(path, "music") && !path.empty() && CFile::Exists(path)) { share1.strPath = path; share1.strName = g_localizeStrings.Get(20240); share1.m_ignore = true; extraShares.push_back(share1); } #endif // add the music playlist location share1.strPath = "special://musicplaylists/"; share1.strName = g_localizeStrings.Get(20011); share1.m_ignore = true; extraShares.push_back(share1); share1.strPath = "sap://"; share1.strName = "SAP Streams"; extraShares.push_back(share1); if (CSettings::Get().GetString("audiocds.recordingpath") != "") { share1.strPath = "special://recordings/"; share1.strName = g_localizeStrings.Get(21883); extraShares.push_back(share1); } } else if (m_type == "video") { CMediaSource share1; #if defined(TARGET_ANDROID) // add the default android video directory std::string path; if (CXBMCApp::GetExternalStorage(path, "videos") && !path.empty() && CFile::Exists(path)) { share1.strPath = path; share1.strName = g_localizeStrings.Get(20241); share1.m_ignore = true; extraShares.push_back(share1); } #endif // add the video playlist location share1.m_ignore = true; share1.strPath = "special://videoplaylists/"; share1.strName = g_localizeStrings.Get(20012); extraShares.push_back(share1); share1.strPath = "rtv://*/"; share1.strName = "ReplayTV Devices"; extraShares.push_back(share1); share1.strPath = "hdhomerun://"; share1.strName = "HDHomerun Devices"; extraShares.push_back(share1); share1.strPath = "sap://"; share1.strName = "SAP Streams"; extraShares.push_back(share1); // add the recordings dir as needed if (CPVRDirectory::HasRecordings()) { share1.strPath = "pvr://recordings/"; share1.strName = g_localizeStrings.Get(19017); // TV Recordings extraShares.push_back(share1); } } else if (m_type == "pictures") { CMediaSource share1; #if defined(TARGET_ANDROID) // add the default android music directory std::string path; if (CXBMCApp::GetExternalStorage(path, "pictures") && !path.empty() && CFile::Exists(path)) { share1.strPath = path; share1.strName = g_localizeStrings.Get(20242); share1.m_ignore = true; extraShares.push_back(share1); } path.clear(); if (CXBMCApp::GetExternalStorage(path, "photos") && !path.empty() && CFile::Exists(path)) { share1.strPath = path; share1.strName = g_localizeStrings.Get(20243); share1.m_ignore = true; extraShares.push_back(share1); } #endif share1.m_ignore = true; if (CSettings::Get().GetString("debug.screenshotpath") != "") { share1.strPath = "special://screenshots/"; share1.strName = g_localizeStrings.Get(20008); extraShares.push_back(share1); } } else if (m_type == "programs") { // nothing to add } if (CGUIDialogFileBrowser::ShowAndGetSource(path, allowNetworkShares, extraShares.size()==0?NULL:&extraShares)) { if (item < m_paths->Size()) // if the skin does funky things, m_paths may have been cleared m_paths->Get(item)->SetPath(path); if (!m_bNameChanged || m_name.empty()) { CURL url(path); m_name = url.GetWithoutUserDetails(); URIUtils::RemoveSlashAtEnd(m_name); m_name = CUtil::GetTitleFromPath(m_name); } UpdateButtons(); } }
void CGUIWindowFileManager::SetInitialPath(const CStdString &path) { /* 歌方: 1、 卦指: 1、 傍苧: 1、 */ // check for a passed destination path CStdString strDestination = path; m_rootDir.SetSources(*g_settings.GetSourcesFromType("files")); if (!strDestination.IsEmpty()) { CLog::Log(LOGINFO, "Attempting to quickpath to: %s", strDestination.c_str()); } // otherwise, is this the first time accessing this window? else if (m_Directory[0]->GetPath() == "?") { m_Directory[0]->SetPath(strDestination = g_settings.m_defaultFileSource); CLog::Log(LOGINFO, "Attempting to default to: %s", strDestination.c_str()); } // try to open the destination path if (!strDestination.IsEmpty()) { // open root if (strDestination.Equals("$ROOT")) { m_Directory[0]->SetPath(""); CLog::Log(LOGINFO, " Success! Opening root listing."); } else { // default parameters if the jump fails m_Directory[0]->SetPath(""); bool bIsSourceName = false; VECSOURCES shares; m_rootDir.GetSources(shares); int iIndex = CUtil::GetMatchingSource(strDestination, shares, bIsSourceName); if (iIndex > -1) { // set current directory to matching share CStdString path; if (bIsSourceName && iIndex < (int)shares.size()) path = shares[iIndex].strPath; else path = strDestination; URIUtils::RemoveSlashAtEnd(path); m_Directory[0]->SetPath(path); CLog::Log(LOGINFO, " Success! Opened destination path: %s", strDestination.c_str()); // outside call: check the share for connectivity bCheckShareConnectivity = Update(0, m_Directory[0]->GetPath()); if(!bCheckShareConnectivity) strCheckSharePath = m_Directory[0]->GetPath(); } else { CLog::Log(LOGERROR, " Failed! Destination parameter (%s) does not match a valid share!", strDestination.c_str()); } } } if (m_Directory[1]->GetPath() == "?") m_Directory[1]->SetPath(""); }