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); } } }
void AddOrReplace(VECSOURCES& sources, const CMediaSource& source) { unsigned int i; for( i=0;i<sources.size();++i ) { if (sources[i].strPath.Equals(source.strPath)) { sources[i] = source; break; } } if (i == sources.size()) sources.push_back(source); }
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 CGUIWindowMusicPlaylistEditor::OnLoadPlaylist() { // prompt user for file to load std::string playlist; VECSOURCES shares; m_rootDir.GetSources(shares); // add the playlist share CMediaSource share; share.strName = g_localizeStrings.Get(20011); share.strPath = "special://musicplaylists/"; if (find(shares.begin(), shares.end(), share) == shares.end()) shares.push_back(share); if (CGUIDialogFileBrowser::ShowAndGetFile(shares, ".m3u|.pls|.b4s|.wpl", g_localizeStrings.Get(656), playlist)) LoadPlaylist(playlist); }
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); } } }
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); }
bool CGUIDialogFileBrowser::ShowAndGetDirectory(const VECSOURCES &shares, const std::string &heading, std::string &path, bool bWriteOnly) { // an extension mask of "/" ensures that no files are shown if (bWriteOnly) { VECSOURCES shareWritable; for (unsigned int i=0;i<shares.size();++i) { if (shares[i].IsWritable()) shareWritable.push_back(shares[i]); } return ShowAndGetFile(shareWritable, "/w", heading, path); } return ShowAndGetFile(shares, "/", heading, path); }
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 AddOrReplace(VECSOURCES& sources, const VECSOURCES& extras) { unsigned int i; for( i=0;i<extras.size();++i ) { unsigned int j; for ( j=0;j<sources.size();++j) { if (StringUtils::EqualsNoCase(sources[j].strPath, extras[i].strPath)) { sources[j] = extras[i]; break; } } if (j == sources.size()) sources.push_back(extras[i]); } }
void CGUIDialogLibExportSettings::OnSettingAction(std::shared_ptr<const CSetting> setting) { if (setting == NULL) return; CGUIDialogSettingsManualBase::OnSettingAction(setting); const std::string &settingId = setting->GetId(); if (settingId == CSettings::SETTING_MUSICLIBRARY_EXPORT_FOLDER) { VECSOURCES shares; g_mediaManager.GetLocalDrives(shares); g_mediaManager.GetNetworkLocations(shares); g_mediaManager.GetRemovableDrives(shares); std::string strDirectory = m_settings.m_strPath; if (!strDirectory.empty()) { URIUtils::AddSlashAtEnd(strDirectory); bool bIsSource; if (CUtil::GetMatchingSource(strDirectory, shares, bIsSource) < 0) // path is outside shares - add it as a separate one { CMediaSource share; share.strName = g_localizeStrings.Get(13278); share.strPath = strDirectory; shares.push_back(share); } } else strDirectory = "default location"; if (CGUIDialogFileBrowser::ShowAndGetDirectory(shares, g_localizeStrings.Get(661), strDirectory, true)) { if (!strDirectory.empty()) { m_destinationChecked = true; m_settings.m_strPath = strDirectory; SetLabel2(CSettings::SETTING_MUSICLIBRARY_EXPORT_FOLDER, strDirectory); SetFocus(CSettings::SETTING_MUSICLIBRARY_EXPORT_FOLDER); } } UpdateButtons(); } }
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 }
bool CGUIDialogProfileSettings::OnProfilePath(CStdString &dir, bool isDefault) { VECSOURCES shares; CMediaSource share; share.strName = "Profiles"; share.strPath = "special://masterprofile/profiles/"; shares.push_back(share); CStdString strDirectory; if (dir.IsEmpty()) strDirectory = share.strPath; else strDirectory = URIUtils::AddFileToFolder("special://masterprofile/", dir); if (CGUIDialogFileBrowser::ShowAndGetDirectory(shares,g_localizeStrings.Get(657),strDirectory,true)) { dir = strDirectory; if (!isDefault) dir.erase(0,24); return true; } return false; }
void CMediaSourceSettings::GetSources(const TiXmlNode* pRootElement, const std::string& strTagName, VECSOURCES& items, std::string& strDefault) { strDefault = ""; items.clear(); const TiXmlNode *pChild = pRootElement->FirstChild(strTagName.c_str()); if (pChild == NULL) { CLog::Log(LOGDEBUG, "CMediaSourceSettings: <%s> tag is missing or sources.xml is malformed", strTagName.c_str()); return; } pChild = pChild->FirstChild(); while (pChild != NULL) { std::string strValue = pChild->ValueStr(); if (strValue == XML_SOURCE || strValue == "bookmark") // "bookmark" left in for backwards compatibility { CMediaSource share; if (GetSource(strTagName, pChild, share)) items.push_back(share); else CLog::Log(LOGERROR, "CMediaSourceSettings: Missing or invalid <name> and/or <path> in source"); } else if (strValue == "default") { const TiXmlNode *pValueNode = pChild->FirstChild(); if (pValueNode) { std::string pszText = pChild->FirstChild()->ValueStr(); if (!pszText.empty()) strDefault = pszText; CLog::Log(LOGDEBUG, "CMediaSourceSettings: Setting <default> source to : %s", strDefault.c_str()); } } pChild = pChild->NextSibling(); } }
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(); } }
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); } }
/*! \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; }
void CUDevProvider::GetDisks(VECSOURCES& disks, bool removable) { // enumerate existing block devices struct udev_enumerate *u_enum = udev_enumerate_new(m_udev); if (u_enum == NULL) { fprintf(stderr, "Error: udev_enumerate_new(udev)\n"); return; } udev_enumerate_add_match_subsystem(u_enum, "block"); udev_enumerate_add_match_property(u_enum, "DEVTYPE", "disk"); udev_enumerate_add_match_property(u_enum, "DEVTYPE", "partition"); udev_enumerate_scan_devices(u_enum); struct udev_list_entry *u_list_ent; struct udev_list_entry *u_first_list_ent; u_first_list_ent = udev_enumerate_get_list_entry(u_enum); udev_list_entry_foreach(u_list_ent, u_first_list_ent) { const char *name = udev_list_entry_get_name(u_list_ent); struct udev *context = udev_enumerate_get_udev(u_enum); struct udev_device *device = udev_device_new_from_syspath(context, name); if (device == NULL) continue; // filter out devices that are not mounted const char *mountpoint = get_mountpoint(udev_device_get_devnode(device)); if (!mountpoint) { udev_device_unref(device); continue; } // filter out root partition if (strcmp(mountpoint, "/") == 0) { udev_device_unref(device); continue; } // filter out things mounted on /tmp if (strstr(mountpoint, "/tmp")) { udev_device_unref(device); continue; } // look for devices on the usb bus, or mounted on */media/ (sdcards), or optical devices const char *bus = udev_device_get_property_value(device, "ID_BUS"); const char *optical = udev_device_get_property_value(device, "ID_CDROM"); // matches also DVD, Blu-ray bool isRemovable = ((bus && strstr(bus, "usb")) || (optical && strstr(optical,"1")) || (mountpoint && strstr(mountpoint, "/media/"))); // filter according to requested device type if (removable != isRemovable) { udev_device_unref(device); continue; } const char *udev_label = udev_device_get_property_value(device, "ID_FS_LABEL"); std::string label; if (udev_label) label = udev_label; else label = URIUtils::GetFileName(mountpoint); CMediaSource share; share.strName = label; share.strPath = mountpoint; share.m_ignore = true; if (isRemovable) { if (optical) share.m_iDriveType = CMediaSource::SOURCE_TYPE_DVD; else share.m_iDriveType = CMediaSource::SOURCE_TYPE_REMOVABLE; } else share.m_iDriveType = CMediaSource::SOURCE_TYPE_LOCAL; disks.push_back(share); udev_device_unref(device); } udev_enumerate_unref(u_enum); }
bool CGUIWindowPVRChannels::OnContextButtonSetThumb(CFileItem *item, CONTEXT_BUTTON button) { bool bReturn = false; if (button == CONTEXT_BUTTON_SET_THUMB) { if (CProfilesManager::Get().GetCurrentProfile().canWriteSources() && !g_passwordManager.IsProfileLockUnlocked()) return bReturn; else if (!g_passwordManager.IsMasterLockUnlocked(true)) return bReturn; /* setup our thumb list */ CFileItemList items; CPVRChannel *channel = item->GetPVRChannelInfoTag(); if (!channel->IconPath().IsEmpty()) { /* add the current thumb, if available */ CFileItemPtr current(new CFileItem("thumb://Current", false)); current->SetArt("thumb", channel->IconPath()); current->SetLabel(g_localizeStrings.Get(20016)); items.Add(current); } else if (item->HasArt("thumb")) { /* already have a thumb that the share doesn't know about - must be a local one, so we may as well reuse it */ CFileItemPtr current(new CFileItem("thumb://Current", false)); current->SetArt("thumb", item->GetArt("thumb")); current->SetLabel(g_localizeStrings.Get(20016)); items.Add(current); } /* and add a "no thumb" entry as well */ CFileItemPtr nothumb(new CFileItem("thumb://None", false)); nothumb->SetIconImage(item->GetIconImage()); nothumb->SetLabel(g_localizeStrings.Get(20018)); items.Add(nothumb); CStdString strThumb; VECSOURCES shares; if (g_guiSettings.GetString("pvrmenu.iconpath") != "") { CMediaSource share1; share1.strPath = g_guiSettings.GetString("pvrmenu.iconpath"); share1.strName = g_localizeStrings.Get(19018); shares.push_back(share1); } g_mediaManager.GetLocalDrives(shares); if (!CGUIDialogFileBrowser::ShowAndGetImage(items, shares, g_localizeStrings.Get(1030), strThumb)) return bReturn; if (strThumb != "thumb://Current") { if (strThumb == "thumb://None") strThumb = ""; channel->SetIconPath(strThumb, true); channel->Persist(); UpdateData(); } bReturn = true; } return bReturn; }
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?? std::string path; bool allowNetworkShares(m_type != "programs"); VECSOURCES extraShares; if (m_name != CUtil::GetTitleFromPath(m_paths->Get(item)->GetPath())) m_bNameChanged = true; std::string strDevices = g_localizeStrings.Get(33040); //"% Devices" 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() && CDirectory::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); // add the recordings dir as needed if (CPVRDirectory::HasRadioRecordings()) { share1.strPath = PVR::CPVRRecordingsPath::PATH_ACTIVE_RADIO_RECORDINGS; share1.strName = g_localizeStrings.Get(19017); // Recordings extraShares.push_back(share1); } if (CPVRDirectory::HasDeletedRadioRecordings()) { share1.strPath = PVR::CPVRRecordingsPath::PATH_DELETED_RADIO_RECORDINGS; share1.strName = g_localizeStrings.Get(19184); // Deleted recordings extraShares.push_back(share1); } if (CSettings::GetInstance().GetString(CSettings::SETTING_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); // add the recordings dir as needed if (CPVRDirectory::HasTVRecordings()) { share1.strPath = PVR::CPVRRecordingsPath::PATH_ACTIVE_TV_RECORDINGS; share1.strName = g_localizeStrings.Get(19017); // Recordings extraShares.push_back(share1); } if (CPVRDirectory::HasDeletedTVRecordings()) { share1.strPath = PVR::CPVRRecordingsPath::PATH_DELETED_TV_RECORDINGS; share1.strName = g_localizeStrings.Get(19184); // Deleted 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::GetInstance().GetString(CSettings::SETTING_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(); } }
// same as above, starting in a single directory bool CGUIDialogFileBrowser::ShowAndGetFile(const std::string &directory, const std::string &mask, const std::string &heading, std::string &path, bool useThumbs /* = false */, bool useFileDirectories /* = false */, bool singleList /* = false */) { CGUIDialogFileBrowser *browser = new CGUIDialogFileBrowser(); if (!browser) return false; CServiceBroker::GetGUI()->GetWindowManager().AddUniqueInstance(browser); browser->m_useFileDirectories = useFileDirectories; browser->m_browsingForImages = useThumbs; browser->SetHeading(heading); // add a single share for this directory if (!singleList) { VECSOURCES shares; CMediaSource share; share.strPath = directory; URIUtils::RemoveSlashAtEnd(share.strPath); // this is needed for the dodgy code in WINDOW_INIT shares.push_back(share); browser->SetSources(shares); } else { browser->m_vecItems->Clear(); CDirectory::GetDirectory(directory,*browser->m_vecItems, "", DIR_FLAG_DEFAULTS); CFileItemPtr item(new CFileItem("file://Browse", false)); item->SetLabel(g_localizeStrings.Get(20153)); item->SetIconImage("DefaultFolder.png"); browser->m_vecItems->Add(item); browser->m_singleList = true; } std::string strMask = mask; if (mask == "/") browser->m_browsingForFolders=1; else if (mask == "/w") { browser->m_browsingForFolders=2; strMask = "/"; } else browser->m_browsingForFolders = 0; browser->m_rootDir.SetMask(strMask); browser->m_selectedPath = directory; browser->m_addNetworkShareEnabled = false; browser->Open(); bool confirmed(browser->IsConfirmed()); if (confirmed) path = browser->m_selectedPath; if (path == "file://Browse") { // "Browse for thumb" CServiceBroker::GetGUI()->GetWindowManager().Remove(browser->GetID()); delete browser; VECSOURCES shares; g_mediaManager.GetLocalDrives(shares); return ShowAndGetFile(shares, mask, heading, path, useThumbs,useFileDirectories); } CServiceBroker::GetGUI()->GetWindowManager().Remove(browser->GetID()); delete browser; return confirmed; }
void CDarwinStorageProvider::GetLocalDrives(VECSOURCES &localDrives) { CMediaSource share; // User home folder #ifdef TARGET_DARWIN_IOS share.strPath = "special://envhome/"; #else share.strPath = getenv("HOME"); #endif share.strName = g_localizeStrings.Get(21440); share.m_ignore = true; localDrives.push_back(share); #if defined(TARGET_DARWIN_IOS) // iOS Inbox folder share.strPath = "special://envhome/Documents/Inbox"; share.strName = "Inbox"; share.m_ignore = true; localDrives.push_back(share); #endif #if defined(TARGET_DARWIN_OSX) // User desktop folder share.strPath = getenv("HOME"); share.strPath += "/Desktop"; share.strName = "Desktop"; share.m_ignore = true; localDrives.push_back(share); // Volumes (all mounts are present here) share.strPath = "/Volumes"; share.strName = "Volumes"; share.m_ignore = true; localDrives.push_back(share); // This will pick up all local non-removable disks including the Root Disk. 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 (kCFBooleanFalse == CFDictionaryGetValue(details, kDADiskDescriptionMediaRemovableKey)) { CMediaSource share; share.strPath = mountpoint; Cocoa_GetVolumeNameFromMountPoint(mountpoint.c_str(), share.strName); share.m_ignore = true; localDrives.push_back(share); } CFRelease(details); } CFRelease(disk); } } CFRelease(session); } #endif }
void CMediaManager::GetLocalDrives(VECSOURCES &localDrives, bool includeQ) { #if defined(_WIN32PC) char lDrives[128]; GetLogicalDriveStrings(sizeof(lDrives)-1, lDrives); char *pch = lDrives; while (*pch) { CMediaSource share; int iDrive = GetDriveType(pch); if(iDrive == DRIVE_CDROM) { share.m_iDriveType = CMediaSource::SOURCE_TYPE_DVD; //share.strName = g_localizeStrings.Get(218); } else { share.m_iDriveType = CMediaSource::SOURCE_TYPE_LOCAL; } share.m_ignore = true; share.strName.Format(g_localizeStrings.Get(21438),pch[0]); share.strPath.Format("%s", _P(pch)); localDrives.push_back(share); pch = &pch[strlen(pch) + 1]; } if (includeQ) { CMediaSource share; share.strPath = _P("Q:\\"); share.strName.Format(g_localizeStrings.Get(21438),'Q'); share.m_ignore = true; localDrives.push_back(share) ; } #else #ifndef _LINUX // Local shares CMediaSource share; share.strPath = _P("C:\\"); share.strName.Format(g_localizeStrings.Get(21438),'C'); share.m_ignore = true; share.m_iDriveType = CMediaSource::SOURCE_TYPE_LOCAL; localDrives.push_back(share); #endif #ifdef _LINUX // Home directory CMediaSource share; share.strPath = getenv("HOME"); share.strName = g_localizeStrings.Get(21440); share.m_ignore = true; share.m_iDriveType = CMediaSource::SOURCE_TYPE_LOCAL; localDrives.push_back(share); #endif share.strPath = _P("D:\\"); share.strName = g_localizeStrings.Get(218); share.m_iDriveType = CMediaSource::SOURCE_TYPE_DVD; localDrives.push_back(share); share.m_iDriveType = CMediaSource::SOURCE_TYPE_LOCAL; #ifndef _LINUX share.strPath = _P("E:\\"); share.strName.Format(g_localizeStrings.Get(21438),'E'); localDrives.push_back(share); for (char driveletter=EXTEND_DRIVE_BEGIN; driveletter<=EXTEND_DRIVE_END; driveletter++) { if (CIoSupport::DriveExists(driveletter)) { CMediaSource share; share.strPath.Format("%c:\\", driveletter); share.strName.Format(g_localizeStrings.Get(21438),driveletter); share.m_ignore = true; localDrives.push_back(share); } } if (includeQ) { CMediaSource share; share.strPath = _P("Q:\\"); share.strName.Format(g_localizeStrings.Get(21438),'Q'); share.m_ignore = true; localDrives.push_back(share) ; } #endif #ifdef _LINUX #ifdef HAS_HAL /* HalManager will autosource items so we only want the nonremovable devices here. removable devices will be added in CVirtualDirectory */ vector<CStdString> result = CLinuxFileSystem::GetLocalDrives(); #else vector<CStdString> result = CLinuxFileSystem::GetLocalDrives(); #endif for (unsigned int i = 0; i < result.size(); i++) { CMediaSource share; share.strPath = result[i]; share.strName = CUtil::GetFileName(result[i]); share.m_ignore = true; localDrives.push_back(share) ; } #endif #endif // Win32PC }
void CGUIDialogInfoProviderSettings::OnSettingAction(std::shared_ptr<const CSetting> setting) { if (setting == nullptr) return; CGUIDialogSettingsManualBase::OnSettingAction(setting); const std::string &settingId = setting->GetId(); if (settingId == CSettings::SETTING_MUSICLIBRARY_ALBUMSSCRAPER) { std::string currentScraperId; if (m_albumscraper) currentScraperId = m_albumscraper->ID(); std::string selectedAddonId = currentScraperId; if (CGUIWindowAddonBrowser::SelectAddonID(ADDON_SCRAPER_ALBUMS, selectedAddonId, false) == 1 && selectedAddonId != currentScraperId) { AddonPtr scraperAddon; CServiceBroker::GetAddonMgr().GetAddon(selectedAddonId, scraperAddon); m_albumscraper = std::dynamic_pointer_cast<CScraper>(scraperAddon); SetupView(); SetFocus(settingId); } } else if (settingId == CSettings::SETTING_MUSICLIBRARY_ARTISTSSCRAPER) { std::string currentScraperId; if (m_artistscraper) currentScraperId = m_artistscraper->ID(); std::string selectedAddonId = currentScraperId; if (CGUIWindowAddonBrowser::SelectAddonID(ADDON_SCRAPER_ARTISTS, selectedAddonId, false) == 1 && selectedAddonId != currentScraperId) { AddonPtr scraperAddon; CServiceBroker::GetAddonMgr().GetAddon(selectedAddonId, scraperAddon); m_artistscraper = std::dynamic_pointer_cast<CScraper>(scraperAddon); SetupView(); SetFocus(settingId); } } else if (settingId == SETTING_ALBUMSCRAPER_SETTINGS) CGUIDialogAddonSettings::ShowForAddon(m_albumscraper, false); else if (settingId == SETTING_ARTISTSCRAPER_SETTINGS) CGUIDialogAddonSettings::ShowForAddon(m_artistscraper, false); else if (settingId == CSettings::SETTING_MUSICLIBRARY_ARTISTSFOLDER) { VECSOURCES shares; g_mediaManager.GetLocalDrives(shares); g_mediaManager.GetNetworkLocations(shares); g_mediaManager.GetRemovableDrives(shares); std::string strDirectory = m_strArtistInfoPath; if (!strDirectory.empty()) { URIUtils::AddSlashAtEnd(strDirectory); bool bIsSource; if (CUtil::GetMatchingSource(strDirectory, shares, bIsSource) < 0) // path is outside shares - add it as a separate one { CMediaSource share; share.strName = g_localizeStrings.Get(13278); share.strPath = strDirectory; shares.push_back(share); } } else strDirectory = "default location"; if (CGUIDialogFileBrowser::ShowAndGetDirectory(shares, g_localizeStrings.Get(20223), strDirectory, true)) { if (!strDirectory.empty()) { m_strArtistInfoPath = strDirectory; SetLabel2(CSettings::SETTING_MUSICLIBRARY_ARTISTSFOLDER, strDirectory); SetFocus(CSettings::CSettings::SETTING_MUSICLIBRARY_ARTISTSFOLDER); } } } }
void CAndroidStorageProvider::GetRemovableDrives(VECSOURCES &removableDrives) { // mounted usb disks char* buf = NULL; FILE* pipe; std::map<std::string, std::string> result; CRegExp reMount; reMount.RegComp("^(.+?)\\s+(.+?)\\s+(.+?)\\s"); /* /proc/mounts is only guaranteed atomic for the current read * operation, so we need to read it all at once. */ if ((pipe = fopen("/proc/mounts", "r"))) { char* new_buf; size_t buf_len = 4096; while ((new_buf = (char*)realloc(buf, buf_len * sizeof(char)))) { size_t nread; buf = new_buf; nread = fread(buf, sizeof(char), buf_len, pipe); if (nread == buf_len) { rewind(pipe); buf_len *= 2; } else { buf[nread] = '\0'; if (!feof(pipe)) new_buf = NULL; break; } } if (!new_buf) { free(buf); buf = NULL; } fclose(pipe); } else CLog::Log(LOGERROR, "Cannot read mount points"); if (buf) { char* line; char* saveptr = NULL; line = strtok_r(buf, "\n", &saveptr); while (line) { if (reMount.RegFind(line) != -1) { bool accepted = false; std::string device = reMount.GetReplaceString("\\1"); std::string mountStr = reMount.GetReplaceString("\\2"); std::string fsStr = reMount.GetReplaceString("\\3"); const char* fs = fsStr.c_str(); // Here we choose which filesystems are approved if (strcmp(fs, "fuseblk") == 0 || strcmp(fs, "vfat") == 0 || strcmp(fs, "ext2") == 0 || strcmp(fs, "ext3") == 0 || strcmp(fs, "ext4") == 0 || strcmp(fs, "reiserfs") == 0 || strcmp(fs, "xfs") == 0 || strcmp(fs, "ntfs-3g") == 0 || strcmp(fs, "iso9660") == 0 || strcmp(fs, "exfat") == 0 || strcmp(fs, "fusefs") == 0 || strcmp(fs, "hfs") == 0) accepted = true; // Ignore sdcards if (!StringUtils::StartsWith(device, "/dev/block/vold/") || mountStr.find("sdcard") != std::string::npos || mountStr.find("secure/asec") != std::string::npos) accepted = false; if(accepted) result[device] = mountStr; } line = strtok_r(NULL, "\n", &saveptr); } free(buf); } for (std::map<std::string, std::string>::const_iterator i = result.begin(); i != result.end(); ++i) { CMediaSource share; share.strPath = unescape(i->second); share.strName = URIUtils::GetFileName(share.strPath); share.m_ignore = true; removableDrives.push_back(share); } }
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(); } }
bool CGUIDialogPVRChannelManager::OnMessage(CGUIMessage& message) { unsigned int iControl = 0; unsigned int iMessage = message.GetMessage(); switch (iMessage) { case GUI_MSG_WINDOW_DEINIT: { Clear(); } break; case GUI_MSG_WINDOW_INIT: { CGUIWindow::OnMessage(message); m_iSelected = 0; m_bIsRadio = false; m_bMovingMode = false; m_bContainsChanges = false; SetProperty("IsRadio", ""); Update(); SetData(m_iSelected); return true; } break; case GUI_MSG_CLICKED: { iControl = message.GetSenderId(); if (iControl == CONTROL_LIST_CHANNELS) { if (!m_bMovingMode) { int iAction = message.GetParam1(); int iItem = m_viewControl.GetSelectedItem(); /* Check file item is in list range and get his pointer */ if (iItem < 0 || iItem >= (int)m_channelItems->Size()) return true; /* Process actions */ if (iAction == ACTION_SELECT_ITEM || iAction == ACTION_CONTEXT_MENU || iAction == ACTION_MOUSE_RIGHT_CLICK) { /* Show Contextmenu */ OnPopupMenu(iItem); } } else { CFileItemPtr pItem = m_channelItems->Get(m_iSelected); if (pItem) { pItem->SetProperty("Changed", true); pItem->Select(false); m_bMovingMode = false; m_bContainsChanges = true; return true; } else return false; } } else if (iControl == BUTTON_OK) { SaveList(); Close(); return true; } else if (iControl == BUTTON_APPLY) { SaveList(); return true; } else if (iControl == BUTTON_CANCEL) { Close(); return true; } else if (iControl == BUTTON_RADIO_TV) { if (m_bContainsChanges) { // prompt user for confirmation of channel record CGUIDialogYesNo* pDialog = (CGUIDialogYesNo*)g_windowManager.GetWindow(WINDOW_DIALOG_YES_NO); if (!pDialog) return true; pDialog->SetHeading(20052); pDialog->SetLine(0, ""); pDialog->SetLine(1, 19212); pDialog->SetLine(2, 20103); pDialog->DoModal(); if (pDialog->IsConfirmed()) SaveList(); } m_iSelected = 0; m_bMovingMode = false; m_bContainsChanges = false; m_bIsRadio = !m_bIsRadio; SetProperty("IsRadio", m_bIsRadio ? "true" : ""); Update(); SetData(m_iSelected); return true; } else if (iControl == RADIOBUTTON_ACTIVE) { CGUIRadioButtonControl *pRadioButton = (CGUIRadioButtonControl *)GetControl(RADIOBUTTON_ACTIVE); if (pRadioButton) { CFileItemPtr pItem = m_channelItems->Get(m_iSelected); if (pItem) { pItem->SetProperty("Changed", true); pItem->SetProperty("ActiveChannel", pRadioButton->IsSelected()); m_bContainsChanges = true; Renumber(); } } } else if (iControl == EDIT_NAME) { CGUIEditControl *pEdit = (CGUIEditControl *)GetControl(EDIT_NAME); if (pEdit) { CFileItemPtr pItem = m_channelItems->Get(m_iSelected); if (pItem) { pItem->SetProperty("Changed", true); pItem->SetProperty("Name", pEdit->GetLabel2()); m_bContainsChanges = true; } } } else if (iControl == BUTTON_CHANNEL_LOGO) { CFileItemPtr pItem = m_channelItems->Get(m_iSelected); if (!pItem) return false; if (g_settings.GetCurrentProfile().canWriteSources() && !g_passwordManager.IsProfileLockUnlocked()) return false; else if (!g_passwordManager.IsMasterLockUnlocked(true)) return false; // setup our thumb list CFileItemList items; // add the current thumb, if available if (!pItem->GetProperty("Icon").IsEmpty()) { CFileItemPtr current(new CFileItem("thumb://Current", false)); current->SetThumbnailImage(pItem->GetPVRChannelInfoTag()->IconPath()); current->SetLabel(g_localizeStrings.Get(20016)); items.Add(current); } else if (pItem->HasThumbnail()) { // already have a thumb that the share doesn't know about - must be a local one, so we mayaswell reuse it. CFileItemPtr current(new CFileItem("thumb://Current", false)); current->SetThumbnailImage(pItem->GetThumbnailImage()); current->SetLabel(g_localizeStrings.Get(20016)); items.Add(current); } // and add a "no thumb" entry as well CFileItemPtr nothumb(new CFileItem("thumb://None", false)); nothumb->SetIconImage(pItem->GetIconImage()); nothumb->SetLabel(g_localizeStrings.Get(20018)); items.Add(nothumb); CStdString strThumb; VECSOURCES shares; if (g_guiSettings.GetString("pvrmenu.iconpath") != "") { CMediaSource share1; share1.strPath = g_guiSettings.GetString("pvrmenu.iconpath"); share1.strName = g_localizeStrings.Get(19018); shares.push_back(share1); } g_mediaManager.GetLocalDrives(shares); if (!CGUIDialogFileBrowser::ShowAndGetImage(items, shares, g_localizeStrings.Get(1030), strThumb)) return false; if (strThumb == "thumb://Current") return true; if (strThumb == "thumb://None") strThumb = ""; pItem->SetProperty("Icon", strThumb); pItem->SetProperty("Changed", true); m_bContainsChanges = true; return true; } else if (iControl == RADIOBUTTON_USEEPG) { CGUIRadioButtonControl *pRadioButton = (CGUIRadioButtonControl *)GetControl(RADIOBUTTON_USEEPG); if (pRadioButton) { CFileItemPtr pItem = m_channelItems->Get(m_iSelected); if (pItem) { pItem->SetProperty("Changed", true); pItem->SetProperty("UseEPG", pRadioButton->IsSelected()); m_bContainsChanges = true; } } } else if (iControl == SPIN_EPGSOURCE_SELECTION) { /// TODO: Add EPG scraper support return true; CGUISpinControlEx *pSpin = (CGUISpinControlEx *)GetControl(SPIN_EPGSOURCE_SELECTION); if (pSpin) { CFileItemPtr pItem = m_channelItems->Get(m_iSelected); if (pItem) { pItem->SetProperty("EPGSource", (int)0); pItem->SetProperty("Changed", true); m_bContainsChanges = true; return true; } } } else if (iControl == BUTTON_GROUP_MANAGER) { /* Load group manager dialog */ CGUIDialogPVRGroupManager* pDlgInfo = (CGUIDialogPVRGroupManager*)g_windowManager.GetWindow(WINDOW_DIALOG_PVR_GROUP_MANAGER); if (!pDlgInfo) return false; pDlgInfo->SetRadio(m_bIsRadio); /* Open dialog window */ pDlgInfo->DoModal(); return true; } else if (iControl == BUTTON_EDIT_CHANNEL) { CFileItemPtr pItem = m_channelItems->Get(m_iSelected); if (!pItem) return false; if (pItem->GetPropertyBOOL("Virtual")) { CStdString strURL = pItem->GetProperty("StreamURL"); if (CGUIDialogKeyboard::ShowAndGetInput(strURL, g_localizeStrings.Get(19214), false)) pItem->SetProperty("StreamURL", strURL); return true; } CGUIDialogOK::ShowAndGetInput(19033,19038,0,0); return true; } else if (iControl == BUTTON_DELETE_CHANNEL) { CFileItemPtr pItem = m_channelItems->Get(m_iSelected); if (!pItem) return false; // prompt user for confirmation of channel record CGUIDialogYesNo* pDialog = (CGUIDialogYesNo*)g_windowManager.GetWindow(WINDOW_DIALOG_YES_NO); if (!pDialog) return true; pDialog->SetHeading(19211); pDialog->SetLine(0, ""); pDialog->SetLine(1, 750); pDialog->SetLine(2, ""); pDialog->DoModal(); if (pDialog->IsConfirmed()) { if (pItem->GetPropertyBOOL("Virtual")) { CPVRDatabase *database = CPVRManager::Get()->GetTVDatabase(); database->Open(); database->Delete(*pItem->GetPVRChannelInfoTag()); database->Close(); m_channelItems->Remove(m_iSelected); m_viewControl.SetItems(*m_channelItems); Renumber(); return true; } CGUIDialogOK::ShowAndGetInput(19033,19038,0,0); } return true; } else if (iControl == BUTTON_NEW_CHANNEL) { std::vector<long> clients; CGUIDialogSelect* pDlgSelect = (CGUIDialogSelect*)g_windowManager.GetWindow(WINDOW_DIALOG_SELECT); if (!pDlgSelect) return false; pDlgSelect->SetHeading(19213); // Select Client pDlgSelect->Add(g_localizeStrings.Get(19209)); clients.push_back(XBMC_VIRTUAL_CLIENTID); std::map<long, CStdString> clientMap; if (CPVRManager::GetClients()->GetClients(&clientMap) > 0) { std::map<long,CStdString>::iterator itr; for (itr = clientMap.begin() ; itr != clientMap.end(); itr++) { clients.push_back((*itr).first); pDlgSelect->Add(clientMap[(*itr).first]); } } pDlgSelect->DoModal(); int selection = pDlgSelect->GetSelectedLabel(); if (selection >= 0 && selection <= (int) clients.size()) { int clientID = clients[selection]; if (clientID == XBMC_VIRTUAL_CLIENTID) { CStdString strURL = ""; if (CGUIDialogKeyboard::ShowAndGetInput(strURL, g_localizeStrings.Get(19214), false)) { if (!strURL.IsEmpty()) { CPVRChannel newchannel(m_bIsRadio); newchannel.SetChannelName(g_localizeStrings.Get(19204)); newchannel.SetEPGEnabled(false); newchannel.SetVirtual(true); newchannel.SetStreamURL(strURL); newchannel.SetClientID(XBMC_VIRTUAL_CLIENTID); CPVRDatabase *database = CPVRManager::Get()->GetTVDatabase(); database->Open(); database->Persist(newchannel); database->Close(); CFileItemPtr channel(new CFileItem(newchannel)); if (channel) { channel->SetProperty("ActiveChannel", true); channel->SetProperty("Name", g_localizeStrings.Get(19204)); channel->SetProperty("UseEPG", false); channel->SetProperty("Icon", newchannel.IconPath()); channel->SetProperty("EPGSource", (int)0); channel->SetProperty("ClientName", g_localizeStrings.Get(19209)); m_channelItems->AddFront(channel, m_iSelected); m_viewControl.SetItems(*m_channelItems); Renumber(); } } } } else { CGUIDialogOK::ShowAndGetInput(19033,19038,0,0); } } return true; } } break; } return CGUIDialog::OnMessage(message); }
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(); } }
void CAndroidStorageProvider::GetRemovableDrives(VECSOURCES &removableDrives) { // mounted usb disks char* buf = NULL; FILE* pipe; CRegExp reMount; reMount.RegComp("^(.+?)\\s+(.+?)\\s+(.+?)\\s+(.+?)\\s"); /* /proc/mounts is only guaranteed atomic for the current read * operation, so we need to read it all at once. */ if ((pipe = fopen("/proc/mounts", "r"))) { char* new_buf; size_t buf_len = 4096; while ((new_buf = (char*)realloc(buf, buf_len * sizeof(char)))) { size_t nread; buf = new_buf; nread = fread(buf, sizeof(char), buf_len, pipe); if (nread == buf_len) { rewind(pipe); buf_len *= 2; } else { buf[nread] = '\0'; if (!feof(pipe)) new_buf = NULL; break; } } if (!new_buf) { free(buf); buf = NULL; } fclose(pipe); } else CLog::Log(LOGERROR, "Cannot read mount points"); if (buf) { char* line; char* saveptr = NULL; line = strtok_r(buf, "\n", &saveptr); while (line) { if (reMount.RegFind(line) != -1) { std::string deviceStr = reMount.GetReplaceString("\\1"); std::string mountStr = reMount.GetReplaceString("\\2"); std::string fsStr = reMount.GetReplaceString("\\3"); std::string optStr = reMount.GetReplaceString("\\4"); // Blacklist bool bl_ok = true; // Reject unreadable if (!XFILE::CDirectory::Exists(mountStr)) bl_ok = false; // What mount points are rejected for (unsigned int i=0; i < ARRAY_SIZE(mountBL); ++i) if (StringUtils::StartsWithNoCase(mountStr, mountBL[i])) bl_ok = false; if (bl_ok) { // What filesystems are accepted bool fsok = false; for (unsigned int i=0; i < ARRAY_SIZE(typeWL); ++i) if (StringUtils::StartsWithNoCase(fsStr, typeWL[i])) continue; // What devices are accepted bool devok = false; for (unsigned int i=0; i < ARRAY_SIZE(deviceWL); ++i) if (StringUtils::StartsWithNoCase(deviceStr, deviceWL[i])) devok = true; // What mount points are accepted bool mountok = false; for (unsigned int i=0; i < ARRAY_SIZE(mountWL); ++i) if (StringUtils::StartsWithNoCase(mountStr, mountWL[i])) mountok = true; if(devok && (fsok || mountok)) { CMediaSource share; share.strPath = unescape(mountStr); share.strName = URIUtils::GetFileName(mountStr); share.m_ignore = true; removableDrives.push_back(share); } } } line = strtok_r(NULL, "\n", &saveptr); } free(buf); } }