void CGUIDialogSmartPlaylistRule::OnField() { const auto fields = CSmartPlaylistRule::GetFields(m_type); CGUIDialogSelect* dialog = g_windowManager.GetWindow<CGUIDialogSelect>(); dialog->Reset(); dialog->SetHeading(CVariant{20427}); int selected = -1; for (auto field = fields.begin(); field != fields.end(); field++) { dialog->Add(CSmartPlaylistRule::GetLocalizedField(*field)); if (*field == m_rule.m_field) selected = std::distance(fields.begin(), field); } if (selected > -1) dialog->SetSelected(selected); dialog->Open(); int newSelected = dialog->GetSelectedItem(); // check if selection has changed if (!dialog->IsConfirmed() || newSelected < 0 || newSelected == selected) return; m_rule.m_field = fields[newSelected]; // check if operator is still valid. if not, reset to first valid one std::vector< std::pair<std::string, int> > validOperators = GetValidOperators(m_rule); bool isValid = false; for (auto op : validOperators) if (std::get<0>(op) == std::get<0>(OperatorLabel(m_rule.m_operator))) isValid = true; if (!isValid) m_rule.m_operator = (CDatabaseQueryRule::SEARCH_OPERATOR)std::get<1>(validOperators[0]); m_rule.SetParameter(""); UpdateButtons(); }
int Interface_GUIDialogSelect::open(void* kodiBase, const char *heading, const char *entries[], unsigned int size, int selected, unsigned int autoclose) { CAddonDll* addon = static_cast<CAddonDll*>(kodiBase); if (!addon) { CLog::Log(LOGERROR, "Interface_GUIDialogSelect::%s - invalid data", __FUNCTION__); return -1; } CGUIDialogSelect* dialog = CServiceBroker::GetGUI()->GetWindowManager().GetWindow<CGUIDialogSelect>(WINDOW_DIALOG_SELECT); if (!heading || !entries || !dialog) { CLog::Log(LOGERROR, "Interface_GUIDialogSelect::%s - invalid handler data (heading='%p', entries='%p', " "dialog='%p') on addon '%s'", __FUNCTION__, heading, static_cast<const void*>(entries), static_cast<void*>(dialog), addon->ID().c_str()); return -1; } dialog->Reset(); dialog->SetHeading(CVariant{heading}); for (unsigned int i = 0; i < size; ++i) dialog->Add(entries[i]); if (selected > 0) dialog->SetSelected(selected); if (autoclose > 0) dialog->SetAutoClose(autoclose); dialog->Open(); return dialog->GetSelectedItem(); }
bool CGUIWindowPVRBase::OpenGroupSelectionDialog(void) { CGUIDialogSelect *dialog = (CGUIDialogSelect*)g_windowManager.GetWindow(WINDOW_DIALOG_SELECT); if (!dialog) return false; CFileItemList options; g_PVRChannelGroups->Get(m_bRadio)->GetGroupList(&options, true); dialog->Reset(); dialog->SetHeading(CVariant{g_localizeStrings.Get(19146)}); dialog->SetItems(options); dialog->SetMultiSelection(false); dialog->SetSelected(m_group->GroupName()); dialog->Open(); if (!dialog->IsConfirmed()) return false; const CFileItemPtr item = dialog->GetSelectedItem(); if (!item) return false; SetGroup(g_PVRChannelGroups->Get(m_bRadio)->GetByName(item->m_strTitle)); return true; }
string CGUIDialogVideoInfo::ChooseArtType(const CFileItem &videoItem, map<string, string> ¤tArt) { // prompt for choice CGUIDialogSelect *dialog = (CGUIDialogSelect*)g_windowManager.GetWindow(WINDOW_DIALOG_SELECT); if (!dialog || !videoItem.HasVideoInfoTag()) return ""; CFileItemList items; dialog->SetHeading(13511); dialog->Reset(); dialog->SetUseDetails(true); dialog->EnableButton(true, 13516); CVideoDatabase db; db.Open(); vector<string> artTypes = CVideoThumbLoader::GetArtTypes(videoItem.GetVideoInfoTag()->m_type); // add in any stored art for this item that is non-empty. db.GetArtForItem(videoItem.GetVideoInfoTag()->m_iDbId, videoItem.GetVideoInfoTag()->m_type, currentArt); for (CGUIListItem::ArtMap::iterator i = currentArt.begin(); i != currentArt.end(); ++i) { if (!i->second.empty() && find(artTypes.begin(), artTypes.end(), i->first) == artTypes.end()) artTypes.push_back(i->first); } // add any art types that exist for other media items of the same type vector<string> dbArtTypes; db.GetArtTypes(videoItem.GetVideoInfoTag()->m_type, dbArtTypes); for (vector<string>::const_iterator it = dbArtTypes.begin(); it != dbArtTypes.end(); it++) { if (find(artTypes.begin(), artTypes.end(), *it) == artTypes.end()) artTypes.push_back(*it); } for (vector<string>::const_iterator i = artTypes.begin(); i != artTypes.end(); ++i) { string type = *i; CFileItemPtr item(new CFileItem(type, "false")); item->SetLabel(type); if (videoItem.HasArt(type)) item->SetArt("thumb", videoItem.GetArt(type)); items.Add(item); } dialog->SetItems(&items); dialog->DoModal(); if (dialog->IsButtonPressed()) { // Get the new artwork name CStdString strArtworkName; if (!CGUIKeyboardFactory::ShowAndGetInput(strArtworkName, g_localizeStrings.Get(13516), false)) return ""; return strArtworkName; } return dialog->GetSelectedItem()->GetLabel(); }
PVR_ERROR CPVRClients::DeleteAllRecordingsFromTrash() { PVR_ERROR error(PVR_ERROR_NO_ERROR); PVR_CLIENTMAP clients; GetConnectedClients(clients); std::vector<PVR_CLIENT> suppClients; for (PVR_CLIENTMAP_CITR itrClients = clients.begin(); itrClients != clients.end(); ++itrClients) { if (itrClients->second->SupportsRecordingsUndelete() && itrClients->second->GetRecordingsAmount(true) > 0) suppClients.push_back(itrClients->second); } int selection = 0; if (suppClients.size() > 1) { // have user select client CGUIDialogSelect* pDialog = (CGUIDialogSelect*)g_windowManager.GetWindow(WINDOW_DIALOG_SELECT); pDialog->Reset(); pDialog->SetHeading(CVariant{19292}); //Delete all permanently pDialog->Add(g_localizeStrings.Get(24032)); // All Add-ons PVR_CLIENTMAP_CITR itrClients; for (itrClients = clients.begin(); itrClients != clients.end(); ++itrClients) { if (itrClients->second->SupportsRecordingsUndelete() && itrClients->second->GetRecordingsAmount(true) > 0) pDialog->Add(itrClients->second->GetBackendName()); } pDialog->Open(); selection = pDialog->GetSelectedItem(); } if (selection == 0) { typedef std::vector<PVR_CLIENT>::const_iterator suppClientsCITR; for (suppClientsCITR itrSuppClients = suppClients.begin(); itrSuppClients != suppClients.end(); ++itrSuppClients) { PVR_ERROR currentError = (*itrSuppClients)->DeleteAllRecordingsFromTrash(); if (currentError != PVR_ERROR_NO_ERROR) { CLog::Log(LOGERROR, "PVR - %s - cannot delete all recordings from client '%d': %s",__FUNCTION__, (*itrSuppClients)->GetID(), CPVRClient::ToString(currentError)); error = currentError; } } } else if (selection >= 1 && selection <= (int)suppClients.size()) { PVR_ERROR currentError = suppClients[selection-1]->DeleteAllRecordingsFromTrash(); if (currentError != PVR_ERROR_NO_ERROR) { CLog::Log(LOGERROR, "PVR - %s - cannot delete all recordings from client '%d': %s",__FUNCTION__, suppClients[selection-1]->GetID(), CPVRClient::ToString(currentError)); error = currentError; } } return error; }
bool CGUIWindowSettingsProfile::GetAutoLoginProfileChoice(int &iProfile) { CGUIDialogSelect *dialog = CServiceBroker::GetGUI()->GetWindowManager().GetWindow<CGUIDialogSelect>(WINDOW_DIALOG_SELECT); if (!dialog) return false; const CProfilesManager &profileManager = CServiceBroker::GetProfileManager(); // add items // "Last used profile" option comes first, so up indices by 1 int autoLoginProfileId = profileManager.GetAutoLoginProfileId() + 1; CFileItemList items; CFileItemPtr item(new CFileItem()); item->SetLabel(g_localizeStrings.Get(37014)); // Last used profile item->SetIconImage("DefaultUser.png"); items.Add(item); for (unsigned int i = 0; i < profileManager.GetNumberOfProfiles(); i++) { const CProfile *profile = profileManager.GetProfile(i); std::string locked = g_localizeStrings.Get(profile->getLockMode() > 0 ? 20166 : 20165); CFileItemPtr item(new CFileItem(profile->getName())); item->SetLabel2(locked); // lock setting std::string thumb = profile->getThumb(); if (thumb.empty()) thumb = "DefaultUser.png"; item->SetIconImage(thumb); items.Add(item); } dialog->SetHeading(CVariant{20093}); // Profile name dialog->Reset(); dialog->SetUseDetails(true); dialog->SetItems(items); dialog->SetSelected(autoLoginProfileId); dialog->Open(); if (dialog->IsButtonPressed() || dialog->GetSelectedItem() < 0) return false; // user cancelled iProfile = dialog->GetSelectedItem() - 1; return true; }
bool CGUIDialogMusicOSD::OnAction(const CAction &action) { switch (action.GetID()) { case ACTION_SHOW_OSD: Close(); return true; case ACTION_SET_RATING: { CGUIDialogSelect *dialog = g_windowManager.GetWindow<CGUIDialogSelect>(WINDOW_DIALOG_SELECT); if (dialog) { dialog->SetHeading(CVariant{ 38023 }); dialog->Add(g_localizeStrings.Get(38022)); for (int i = 1; i <= 10; i++) dialog->Add(StringUtils::Format("%s: %i", g_localizeStrings.Get(563).c_str(), i)); auto track = g_application.CurrentFileItemPtr(); dialog->SetSelected(track->GetMusicInfoTag()->GetUserrating()); dialog->Open(); int userrating = dialog->GetSelectedItem(); if (userrating < 0) userrating = 0; if (userrating > 10) userrating = 10; if (userrating != track->GetMusicInfoTag()->GetUserrating()) { track->GetMusicInfoTag()->SetUserrating(userrating); // send a message to all windows to tell them to update the fileitem (eg playlistplayer, media windows) CGUIMessage msg(GUI_MSG_NOTIFY_ALL, 0, 0, GUI_MSG_UPDATE_ITEM, 0, track); g_windowManager.SendMessage(msg); CMusicDatabase db; if (db.Open()) { db.SetSongUserrating(track->GetMusicInfoTag()->GetURL(), userrating); db.Close(); } } } return true; } default: break; } return CGUIDialog::OnAction(action); }
bool CGUIDialogSimpleMenu::ShowPlaySelection(CFileItem& item, const std::string& directory) { CFileItemList items; if (!XFILE::CDirectory::GetDirectory(directory, items, XFILE::CDirectory::CHints(), true)) { CLog::Log(LOGERROR, "CGUIWindowVideoBase::ShowPlaySelection - Failed to get play directory for %s", directory.c_str()); return true; } if (items.IsEmpty()) { CLog::Log(LOGERROR, "CGUIWindowVideoBase::ShowPlaySelection - Failed to get any items %s", directory.c_str()); return true; } CGUIDialogSelect* dialog = (CGUIDialogSelect*)g_windowManager.GetWindow(WINDOW_DIALOG_SELECT); while (true) { dialog->Reset(); dialog->SetHeading(CVariant{25006}); // Select playback item dialog->SetItems(items); dialog->SetUseDetails(true); dialog->Open(); CFileItemPtr item_new = dialog->GetSelectedItem(); if (!item_new || dialog->GetSelectedLabel() < 0) { CLog::Log(LOGDEBUG, "CGUIWindowVideoBase::ShowPlaySelection - User aborted %s", directory.c_str()); break; } if (item_new->m_bIsFolder == false) { std::string original_path = item.GetPath(); item.Reset(); item = *item_new; item.SetProperty("original_listitem_url", original_path); return true; } items.Clear(); if (!XFILE::CDirectory::GetDirectory(item_new->GetPath(), items, XFILE::CDirectory::CHints(), true) || items.IsEmpty()) { CLog::Log(LOGERROR, "CGUIWindowVideoBase::ShowPlaySelection - Failed to get any items %s", item_new->GetPath().c_str()); break; } } return false; }
void CPeripherals::OnSettingAction(const CSetting *setting) { if (setting == NULL) return; const std::string &settingId = setting->GetId(); if (settingId == CSettings::SETTING_INPUT_PERIPHERALS) { CGUIDialogSelect* pDialog = (CGUIDialogSelect*)g_windowManager.GetWindow(WINDOW_DIALOG_SELECT); CFileItemList items; GetDirectory("peripherals://all/", items); int iPos = -1; do { pDialog->Reset(); pDialog->SetHeading(CVariant{35000}); pDialog->SetUseDetails(true); pDialog->SetItems(items); pDialog->SetSelected(iPos); pDialog->Open(); iPos = pDialog->IsConfirmed() ? pDialog->GetSelectedItem() : -1; if (iPos >= 0) { CFileItemPtr pItem = items.Get(iPos); CGUIDialogPeripheralSettings *pSettingsDialog = (CGUIDialogPeripheralSettings *)g_windowManager.GetWindow(WINDOW_DIALOG_PERIPHERAL_SETTINGS); if (pItem && pSettingsDialog) { // pass peripheral item properties to settings dialog so skin authors // can use it to show more detailed information about the device pSettingsDialog->SetProperty("vendor", pItem->GetProperty("vendor")); pSettingsDialog->SetProperty("product", pItem->GetProperty("product")); pSettingsDialog->SetProperty("bus", pItem->GetProperty("bus")); pSettingsDialog->SetProperty("location", pItem->GetProperty("location")); pSettingsDialog->SetProperty("class", pItem->GetProperty("class")); pSettingsDialog->SetProperty("version", pItem->GetProperty("version")); // open settings dialog pSettingsDialog->SetFileItem(pItem.get()); pSettingsDialog->Open(); } } } while (pDialog->IsConfirmed()); } }
RENDER_STEREO_MODE CStereoscopicsManager::GetStereoModeByUserChoice(const std::string &heading) { RENDER_STEREO_MODE mode = GetStereoMode(); // if no stereo mode is set already, suggest mode of current video by preselecting it if (mode == RENDER_STEREO_MODE_OFF) mode = GetStereoModeOfPlayingVideo(); CGUIDialogSelect* pDlgSelect = (CGUIDialogSelect*)g_windowManager.GetWindow(WINDOW_DIALOG_SELECT); pDlgSelect->Reset(); if (heading.empty()) pDlgSelect->SetHeading(CVariant{g_localizeStrings.Get(36528)}); else pDlgSelect->SetHeading(CVariant{heading}); // prepare selectable stereo modes std::vector<RENDER_STEREO_MODE> selectableModes; for (int i = RENDER_STEREO_MODE_OFF; i < RENDER_STEREO_MODE_COUNT; i++) { RENDER_STEREO_MODE selectableMode = (RENDER_STEREO_MODE) i; if (g_Windowing.SupportsStereo(selectableMode)) { selectableModes.push_back(selectableMode); std::string label = GetLabelForStereoMode((RENDER_STEREO_MODE) i); pDlgSelect->Add( label ); if (mode == selectableMode) pDlgSelect->SetSelected( label ); } // inject AUTO pseudo mode after OFF if (i == RENDER_STEREO_MODE_OFF) { selectableModes.push_back(RENDER_STEREO_MODE_AUTO); pDlgSelect->Add(GetLabelForStereoMode(RENDER_STEREO_MODE_AUTO)); } } pDlgSelect->Open(); int iItem = pDlgSelect->GetSelectedItem(); if (iItem > -1 && pDlgSelect->IsConfirmed()) mode = (RENDER_STEREO_MODE) selectableModes[iItem]; else mode = GetStereoMode(); return mode; }
void CGUIDialogSmartPlaylistRule::OnOperator() { const auto labels = GetValidOperators(m_rule); CGUIDialogSelect* dialog = g_windowManager.GetWindow<CGUIDialogSelect>(); dialog->Reset(); dialog->SetHeading(CVariant{ 16023 }); for (auto label : labels) dialog->Add(std::get<0>(label)); dialog->SetSelected(CSmartPlaylistRule::GetLocalizedOperator(m_rule.m_operator)); dialog->Open(); int newSelected = dialog->GetSelectedItem(); // check if selection has changed if (!dialog->IsConfirmed() || newSelected < 0) return; m_rule.m_operator = (CDatabaseQueryRule::SEARCH_OPERATOR)std::get<1>(labels[newSelected]); UpdateButtons(); }
bool CGUIControlListSetting::OnClick() { if (m_pButton == NULL) return false; CGUIDialogSelect *dialog = (CGUIDialogSelect*)g_windowManager.GetWindow(WINDOW_DIALOG_SELECT); if (dialog == NULL) return false; CFileItemList options; if (!GetItems(m_pSetting, options) || options.Size() <= 1) return false; dialog->Reset(); dialog->SetHeading(g_localizeStrings.Get(m_pSetting->GetLabel())); dialog->SetItems(&options); dialog->SetMultiSelection(false); dialog->DoModal(); if (!dialog->IsConfirmed()) return false; const CFileItemPtr item = dialog->GetSelectedItem(); if (item == NULL || !item->HasProperty("value")) return false; CVariant value = item->GetProperty("value"); switch (m_pSetting->GetType()) { case SettingTypeInteger: return ((CSettingInt *)m_pSetting)->SetValue((int)value.asInteger()); case SettingTypeString: return ((CSettingString *)m_pSetting)->SetValue(value.asString()); default: break; } return true; }
bool CGUIViewState::ChooseSortMethod() { CGUIDialogSelect *dialog = g_windowManager.GetWindow<CGUIDialogSelect>(WINDOW_DIALOG_SELECT); if (!dialog) return false; dialog->Reset(); dialog->SetHeading(CVariant{ 39010 }); // Label "Sort by" for (auto &sortMethod : m_sortMethods) dialog->Add(g_localizeStrings.Get(sortMethod.m_buttonLabel)); dialog->SetSelected(m_currentSortMethod); dialog->Open(); int newSelected = dialog->GetSelectedItem(); // check if selection has changed if (!dialog->IsConfirmed() || newSelected < 0 || newSelected == m_currentSortMethod) return false; m_currentSortMethod = newSelected; SaveViewState(); return true; }
void CGUIDialogMusicInfo::OnSetUserrating() { CGUIDialogSelect *dialog = (CGUIDialogSelect *)g_windowManager.GetWindow(WINDOW_DIALOG_SELECT); if (dialog) { dialog->SetHeading(CVariant{ 38023 }); dialog->Add(g_localizeStrings.Get(38022)); for (int i = 1; i <= 10; i++) dialog->Add(StringUtils::Format("%s: %i", g_localizeStrings.Get(563).c_str(), i)); dialog->SetSelected(m_albumItem->GetMusicInfoTag()->GetUserrating()); dialog->Open(); int iItem = dialog->GetSelectedItem(); if (iItem < 0) return; SetUserrating(iItem); } }
string CGUIDialogVideoInfo::ChooseArtType(const CFileItem &videoItem, map<string, string> ¤tArt) { // prompt for choice CGUIDialogSelect *dialog = (CGUIDialogSelect*)g_windowManager.GetWindow(WINDOW_DIALOG_SELECT); if (!dialog || !videoItem.HasVideoInfoTag()) return ""; CFileItemList items; dialog->SetHeading(13511); dialog->Reset(); dialog->SetUseDetails(true); CVideoDatabase db; db.Open(); vector<string> artTypes = CVideoThumbLoader::GetArtTypes(videoItem.GetVideoInfoTag()->m_type); // add in any stored art for this item that is non-empty. db.GetArtForItem(videoItem.GetVideoInfoTag()->m_iDbId, videoItem.GetVideoInfoTag()->m_type, currentArt); for (CGUIListItem::ArtMap::iterator i = currentArt.begin(); i != currentArt.end(); ++i) { if (!i->second.empty() && find(artTypes.begin(), artTypes.end(), i->first) == artTypes.end()) artTypes.push_back(i->first); } for (vector<string>::const_iterator i = artTypes.begin(); i != artTypes.end(); ++i) { string type = *i; CFileItemPtr item(new CFileItem(type, "false")); item->SetLabel(type); if (videoItem.HasArt(type)) item->SetArt("thumb", videoItem.GetArt(type)); items.Add(item); } dialog->SetItems(&items); dialog->DoModal(); return dialog->GetSelectedItem()->GetLabel(); }
/*! \brief Select and set a skin bool setting. * \param params The parameters. * \details params[0] = Names of skin settings. */ static int SelectBool(const std::vector<std::string>& params) { std::vector<std::pair<std::string, std::string>> settings; CGUIDialogSelect* pDlgSelect = g_windowManager.GetWindow<CGUIDialogSelect>(); pDlgSelect->Reset(); pDlgSelect->SetHeading(CVariant{g_localizeStrings.Get(atoi(params[0].c_str()))}); for (unsigned int i = 1 ; i < params.size() ; i++) { if (params[i].find('|') != std::string::npos) { std::vector<std::string> values = StringUtils::Split(params[i], '|'); std::string label = g_localizeStrings.Get(atoi(values[0].c_str())); settings.push_back(std::make_pair(label, values[1].c_str())); pDlgSelect->Add(label); } } pDlgSelect->Open(); if(pDlgSelect->IsConfirmed()) { unsigned int iItem = pDlgSelect->GetSelectedItem(); for (unsigned int i = 0 ; i < settings.size() ; i++) { std::string item = settings[i].second; int setting = CSkinSettings::GetInstance().TranslateBool(item); if (i == iItem) CSkinSettings::GetInstance().SetBool(setting, true); else CSkinSettings::GetInstance().SetBool(setting, false); } CServiceBroker::GetSettings().Save(); } return 0; }
bool CGUIDialogPVRChannelManager::OnClickButtonNewChannel() { int iSelection = 0; if (CServiceBroker::GetPVRManager().Clients()->CreatedClientAmount() > 1) { CGUIDialogSelect* pDlgSelect = g_windowManager.GetWindow<CGUIDialogSelect>(WINDOW_DIALOG_SELECT); if (!pDlgSelect) return false; pDlgSelect->SetHeading(CVariant{19213}); // Select Client for (const auto client : m_clientsWithSettingsList) pDlgSelect->Add(client->Name()); pDlgSelect->Open(); iSelection = pDlgSelect->GetSelectedItem(); } if (iSelection >= 0 && iSelection < (int)m_clientsWithSettingsList.size()) { int iClientID = m_clientsWithSettingsList[iSelection]->GetID(); CPVRChannelPtr channel(new CPVRChannel(m_bIsRadio)); channel->SetChannelName(g_localizeStrings.Get(19204)); // New channel channel->SetEPGEnabled(CServiceBroker::GetPVRManager().Clients()->GetClientCapabilities(iClientID).SupportsEPG()); channel->SetClientID(iClientID); PVR_ERROR ret = CServiceBroker::GetPVRManager().Clients()->OpenDialogChannelAdd(channel); if (ret == PVR_ERROR_NO_ERROR) Update(); else if (ret == PVR_ERROR_NOT_IMPLEMENTED) CGUIDialogOK::ShowAndGetInput(CVariant{19033}, CVariant{19038}); // "Information", "Not supported by the PVR backend." else CGUIDialogOK::ShowAndGetInput(CVariant{2103}, CVariant{16029}); // "Add-on error", "Check the log for more information about this message." } return true; }
void CGUIDialogMusicInfo::OnSetUserrating() const { CGUIDialogSelect *dialog = g_windowManager.GetWindow<CGUIDialogSelect>(WINDOW_DIALOG_SELECT); if (dialog) { // If we refresh and then try to set the rating there will be an items already here... dialog->Reset(); dialog->SetHeading(CVariant{ 38023 }); dialog->Add(g_localizeStrings.Get(38022)); for (int i = 1; i <= 10; i++) dialog->Add(StringUtils::Format("%s: %i", g_localizeStrings.Get(563).c_str(), i)); dialog->SetSelected(m_albumItem->GetMusicInfoTag()->GetUserrating()); dialog->Open(); int iItem = dialog->GetSelectedItem(); if (iItem < 0) return; SetUserrating(iItem); } }
void CPeripherals::OnSettingAction(const CSetting *setting) { if (setting == nullptr) return; const std::string &settingId = setting->GetId(); if (settingId == CSettings::SETTING_INPUT_PERIPHERALS) { CGUIDialogSelect* pDialog = (CGUIDialogSelect*)g_windowManager.GetWindow(WINDOW_DIALOG_SELECT); CFileItemList items; GetDirectory("peripherals://all/", items); int iPos = -1; do { pDialog->Reset(); pDialog->SetHeading(CVariant{35000}); pDialog->SetUseDetails(true); pDialog->SetItems(items); pDialog->SetSelected(iPos); pDialog->Open(); iPos = pDialog->IsConfirmed() ? pDialog->GetSelectedItem() : -1; if (iPos >= 0) { CFileItemPtr pItem = items.Get(iPos); // show an error if the peripheral doesn't have any settings PeripheralPtr peripheral = GetByPath(pItem->GetPath()); if (!peripheral || peripheral->GetSettings().empty()) { CGUIDialogOK::ShowAndGetInput(CVariant{35000}, CVariant{35004}); continue; } CGUIDialogPeripheralSettings *pSettingsDialog = (CGUIDialogPeripheralSettings *)g_windowManager.GetWindow(WINDOW_DIALOG_PERIPHERAL_SETTINGS); if (pItem && pSettingsDialog) { // pass peripheral item properties to settings dialog so skin authors // can use it to show more detailed information about the device pSettingsDialog->SetProperty("vendor", pItem->GetProperty("vendor")); pSettingsDialog->SetProperty("product", pItem->GetProperty("product")); pSettingsDialog->SetProperty("bus", pItem->GetProperty("bus")); pSettingsDialog->SetProperty("location", pItem->GetProperty("location")); pSettingsDialog->SetProperty("class", pItem->GetProperty("class")); pSettingsDialog->SetProperty("version", pItem->GetProperty("version")); // open settings dialog pSettingsDialog->SetFileItem(pItem.get()); pSettingsDialog->Open(); } } } while (pDialog->IsConfirmed()); } else if (settingId == CSettings::SETTING_INPUT_CONTROLLERCONFIG) g_windowManager.ActivateWindow(WINDOW_DIALOG_GAME_CONTROLLERS); else if (settingId == CSettings::SETTING_INPUT_TESTRUMBLE) TestFeature(FEATURE_RUMBLE); }
std::string CGUIDialogSelectGameClient::ShowAndGetGameClient(const std::string &gamePath, const GameClientVector& candidates, const GameClientVector& installable) { std::string gameClient; LogGameClients(candidates, installable); std::string extension = URIUtils::GetExtension(gamePath); std::string xmlPath = CSavestateUtils::MakeMetadataPath(gamePath); // Load savestate CSavestate save; CSavestateDatabase db; CLog::Log(LOGDEBUG, "Select game client dialog: Loading savestate metadata %s", CURL::GetRedacted(xmlPath).c_str()); const bool bLoaded = db.GetSavestate(xmlPath, save); // Get savestate game client std::string saveGameClient; if (bLoaded) { saveGameClient = save.GameClient(); CLog::Log(LOGDEBUG, "Select game client dialog: Auto-selecting %s", saveGameClient.c_str()); } // "Select emulator for {0:s}" CGUIDialogSelect *dialog = GetDialog(StringUtils::Format(g_localizeStrings.Get(35258), extension)); if (dialog != nullptr) { // Turn the addons into items CFileItemList items; for (const auto &candidate : candidates) { CFileItemPtr item(XFILE::CAddonsDirectory::FileItemFromAddon(candidate, candidate->ID())); item->SetLabel2(g_localizeStrings.Get(35257)); // "Installed" if (item->GetPath() == saveGameClient) item->SetLabel2(item->GetLabel2() + ", " + g_localizeStrings.Get(35259)); // "Saved" items.Add(std::move(item)); } for (const auto &addon : installable) { CFileItemPtr item(XFILE::CAddonsDirectory::FileItemFromAddon(addon, addon->ID())); items.Add(std::move(item)); } items.Sort(SortByLabel, SortOrderAscending); dialog->SetItems(items); for (int i = 0; i < items.Size(); i++) { if (items[i]->GetPath() == saveGameClient) dialog->SetSelected(i); } dialog->Open(); // If the "Get More" button has been pressed, show a list of installable addons if (dialog->IsConfirmed()) { int selectedIndex = dialog->GetSelectedItem(); if (0 <= selectedIndex && selectedIndex < items.Size()) { gameClient = items[selectedIndex]->GetPath(); CLog::Log(LOGDEBUG, "Select game client dialog: User selected emulator %s", gameClient.c_str()); if (Install(gameClient)) { // If the addon is disabled we need to enable it if (!Enable(gameClient)) CLog::Log(LOGDEBUG, "Failed to enable game client %s", gameClient.c_str()); } else CLog::Log(LOGDEBUG, "Failed to install game client: %s", gameClient.c_str()); } else { CLog::Log(LOGDEBUG, "Select game client dialog: User selected invalid emulator %d", selectedIndex); } } else { CLog::Log(LOGDEBUG, "Select game client dialog: User cancelled game client installation"); } } return gameClient; }
bool CVideoLibraryRefreshingJob::Work(CVideoDatabase &db) { if (m_item == nullptr) return false; // determine the scraper for the item's path VIDEO::SScanSettings scanSettings; ADDON::ScraperPtr scraper = db.GetScraperForPath(m_item->GetPath(), scanSettings); if (scraper == nullptr) return false; // copy the scraper in case we need it again ADDON::ScraperPtr originalScraper(scraper); // get the item's correct title std::string itemTitle = m_searchTitle; if (itemTitle.empty()) itemTitle = m_item->GetMovieName(scanSettings.parent_name); CScraperUrl scraperUrl; VIDEO::CVideoInfoScanner scanner; bool needsRefresh = m_forceRefresh; bool hasDetails = false; bool ignoreNfo = m_ignoreNfo; // run this in a loop in case we need to refresh again bool failure = false; do { if (!ignoreNfo) { // check if there's an NFO for the item CNfoFile::NFOResult nfoResult = scanner.CheckForNFOFile(m_item.get(), scanSettings.parent_name_root, scraper, scraperUrl); // if there's no NFO remember it in case we have to refresh again if (nfoResult == CNfoFile::ERROR_NFO) ignoreNfo = true; else if (nfoResult != CNfoFile::NO_NFO) hasDetails = true; // if we are performing a forced refresh ask the user to choose between using a valid NFO and a valid scraper if (needsRefresh && IsModal() && !scraper->IsNoop() && (nfoResult == CNfoFile::URL_NFO || nfoResult == CNfoFile::COMBINED_NFO || nfoResult == CNfoFile::FULL_NFO)) { int heading = 20159; if (scraper->Content() == CONTENT_MOVIES) heading = 13346; else if (scraper->Content() == CONTENT_TVSHOWS) heading = m_item->m_bIsFolder ? 20351 : 20352; else if (scraper->Content() == CONTENT_MUSICVIDEOS) heading = 20393; if (CGUIDialogYesNo::ShowAndGetInput(heading, 20446)) { hasDetails = false; ignoreNfo = true; scraperUrl.Clear(); scraper = originalScraper; } } } // no need to re-fetch the episode guide for episodes if (scraper->Content() == CONTENT_TVSHOWS && !m_item->m_bIsFolder) hasDetails = true; // if we don't have an url or need to refresh anyway do the web search if (!hasDetails && (needsRefresh || scraperUrl.m_url.empty())) { SetTitle(StringUtils::Format(g_localizeStrings.Get(197).c_str(), scraper->Name().c_str())); SetText(itemTitle); SetProgress(0); // clear any cached data from the scraper scraper->ClearCache(); // create the info downloader for the scraper CVideoInfoDownloader infoDownloader(scraper); // try to find a matching item MOVIELIST itemResultList; int result = infoDownloader.FindMovie(itemTitle, itemResultList, GetProgressDialog()); // close the progress dialog MarkFinished(); if (result > 0) { // there are multiple matches for the item if (!itemResultList.empty()) { // choose the first match if (!IsModal()) scraperUrl = itemResultList.at(0); else { // ask the user what to do CGUIDialogSelect* selectDialog = static_cast<CGUIDialogSelect*>(g_windowManager.GetWindow(WINDOW_DIALOG_SELECT)); selectDialog->Reset(); selectDialog->SetHeading(scraper->Content() == CONTENT_TVSHOWS ? 20356 : 196); for (const auto& itemResult : itemResultList) selectDialog->Add(itemResult.strTitle); selectDialog->EnableButton(true, 413); // "Manual" selectDialog->Open(); // check if the user has chosen one of the results int selectedItem = selectDialog->GetSelectedItem(); if (selectedItem >= 0) scraperUrl = itemResultList.at(selectedItem); // the user hasn't chosen one of the results and but has chosen to manually enter a title to use else if (selectDialog->IsButtonPressed()) { // ask the user to input a title to use if (!CGUIKeyboardFactory::ShowAndGetInput(itemTitle, g_localizeStrings.Get(scraper->Content() == CONTENT_TVSHOWS ? 20357 : 16009), false)) return false; // go through the whole process again needsRefresh = true; continue; } // nothing else we can do else return false; } CLog::Log(LOGDEBUG, "CVideoLibraryRefreshingJob: user selected item '%s' with URL '%s'", scraperUrl.strTitle.c_str(), scraperUrl.m_url.at(0).m_url.c_str()); } } else if (result < 0 || !VIDEO::CVideoInfoScanner::DownloadFailed(GetProgressDialog())) { failure = true; break; } } // if the URL is still empty, check whether or not we're allowed // to prompt and ask the user to input a new search title if (!hasDetails && scraperUrl.m_url.empty()) { if (IsModal()) { // ask the user to input a title to use if (!CGUIKeyboardFactory::ShowAndGetInput(itemTitle, g_localizeStrings.Get(scraper->Content() == CONTENT_TVSHOWS ? 20357 : 16009), false)) return false; // go through the whole process again needsRefresh = true; continue; } // nothing else we can do failure = true; break; } // before we start downloading all the necessary information cleanup any existing artwork and hashes CTextureDatabase textureDb; if (textureDb.Open()) { for (const auto& artwork : m_item->GetArt()) textureDb.InvalidateCachedTexture(artwork.second); textureDb.Close(); } m_item->ClearArt(); // put together the list of items to refresh std::string path = m_item->GetPath(); CFileItemList items; if (m_item->HasVideoInfoTag() && m_item->GetVideoInfoTag()->m_iDbId > 0) { // for a tvshow we need to handle all paths of it std::vector<std::string> tvshowPaths; if (CMediaTypes::IsMediaType(m_item->GetVideoInfoTag()->m_type, MediaTypeTvShow) && m_refreshAll && db.GetPathsLinkedToTvShow(m_item->GetVideoInfoTag()->m_iDbId, tvshowPaths)) { for (const auto& tvshowPath : tvshowPaths) { CFileItemPtr tvshowItem(new CFileItem(*m_item->GetVideoInfoTag())); tvshowItem->SetPath(tvshowPath); items.Add(tvshowItem); } } // otherwise just add a copy of the item else items.Add(CFileItemPtr(new CFileItem(*m_item->GetVideoInfoTag()))); // update the path to the real path (instead of a videodb:// one) path = m_item->GetVideoInfoTag()->m_strPath; } else items.Add(CFileItemPtr(new CFileItem(*m_item))); // set the proper path of the list of items to lookup items.SetPath(m_item->m_bIsFolder ? URIUtils::GetParentPath(path) : URIUtils::GetDirectory(path)); int headingLabel = 198; if (scraper->Content() == CONTENT_TVSHOWS) { if (m_item->m_bIsFolder) headingLabel = 20353; else headingLabel = 20361; } else if (scraper->Content() == CONTENT_MUSICVIDEOS) headingLabel = 20394; // prepare the progress dialog for downloading all the necessary information SetTitle(g_localizeStrings.Get(headingLabel)); SetText(scraperUrl.strTitle); SetProgress(0); // remove any existing data for the item we're going to refresh if (m_item->GetVideoInfoTag()->m_iDbId > 0) { int dbId = m_item->GetVideoInfoTag()->m_iDbId; if (scraper->Content() == CONTENT_MOVIES) db.DeleteMovie(dbId); else if (scraper->Content() == CONTENT_MUSICVIDEOS) db.DeleteMusicVideo(dbId); else if (scraper->Content() == CONTENT_TVSHOWS) { if (!m_item->m_bIsFolder) db.DeleteEpisode(dbId); else if (m_refreshAll) db.DeleteTvShow(dbId); else db.DeleteDetailsForTvShow(dbId); } } // finally download the information for the item if (!scanner.RetrieveVideoInfo(items, scanSettings.parent_name, scraper->Content(), !ignoreNfo, &scraperUrl, m_refreshAll, GetProgressDialog())) { // something went wrong MarkFinished(); // check if the user cancelled if (!IsCancelled() && IsModal()) CGUIDialogOK::ShowAndGetInput(195, itemTitle); return false; } // retrieve the updated information from the database if (scraper->Content() == CONTENT_MOVIES) db.GetMovieInfo(m_item->GetPath(), *m_item->GetVideoInfoTag()); else if (scraper->Content() == CONTENT_MUSICVIDEOS) db.GetMusicVideoInfo(m_item->GetPath(), *m_item->GetVideoInfoTag()); else if (scraper->Content() == CONTENT_TVSHOWS) { // update tvshow info to get updated episode numbers if (m_item->m_bIsFolder) db.GetTvShowInfo(m_item->GetPath(), *m_item->GetVideoInfoTag()); else db.GetEpisodeInfo(m_item->GetPath(), *m_item->GetVideoInfoTag()); } // we're finally done MarkFinished(); break; } while (needsRefresh); if (failure && IsModal()) CGUIDialogOK::ShowAndGetInput(195, itemTitle); return true; }
void CStereoscopicsManager::OnPlaybackStarted(void) { STEREOSCOPIC_PLAYBACK_MODE playbackMode = (STEREOSCOPIC_PLAYBACK_MODE) CSettings::GetInstance().GetInt(CSettings::SETTING_VIDEOPLAYER_STEREOSCOPICPLAYBACKMODE); RENDER_STEREO_MODE mode = GetStereoMode(); // early return if playback mode should be ignored and we're in no stereoscopic mode right now if (playbackMode == STEREOSCOPIC_PLAYBACK_MODE_IGNORE && mode == RENDER_STEREO_MODE_OFF) return; if (!CStereoscopicsManager::IsVideoStereoscopic()) { // exit stereo mode if started item is not stereoscopic // and if user prefers to stop 3D playback when movie is finished if (mode != RENDER_STEREO_MODE_OFF && CSettings::GetInstance().GetBool(CSettings::SETTING_VIDEOPLAYER_QUITSTEREOMODEONSTOP)) SetStereoMode(RENDER_STEREO_MODE_OFF); return; } // if we're not in stereomode yet, restore previously selected stereo mode in case it was user selected if (m_stereoModeSetByUser != RENDER_STEREO_MODE_UNDEFINED) { SetStereoMode(m_stereoModeSetByUser); return; } RENDER_STEREO_MODE preferred = GetPreferredPlaybackMode(); RENDER_STEREO_MODE playing = GetStereoModeOfPlayingVideo(); if (mode != RENDER_STEREO_MODE_OFF) { // don't change mode if user selected to not exit stereomode on playback stop // users selecting this option usually have to manually switch their TV into 3D mode // and would be annoyed by having to switch TV modes when next movies comes up // @todo probably add a new setting for just this behavior if (CSettings::GetInstance().GetBool(CSettings::SETTING_VIDEOPLAYER_QUITSTEREOMODEONSTOP) == false) return; // only change to new stereo mode if not yet in preferred stereo mode if (mode == preferred || (preferred == RENDER_STEREO_MODE_AUTO && mode == playing)) return; } switch (playbackMode) { case STEREOSCOPIC_PLAYBACK_MODE_ASK: // Ask { CApplicationMessenger::GetInstance().SendMsg(TMSG_MEDIA_PAUSE); CGUIDialogSelect* pDlgSelect = (CGUIDialogSelect*)g_windowManager.GetWindow(WINDOW_DIALOG_SELECT); pDlgSelect->Reset(); pDlgSelect->SetHeading(CVariant{g_localizeStrings.Get(36527)}); int idx_playing = -1; // add choices int idx_preferred = pDlgSelect->Add(g_localizeStrings.Get(36524) // preferred + " (" + GetLabelForStereoMode(preferred) + ")"); int idx_mono = pDlgSelect->Add(GetLabelForStereoMode(RENDER_STEREO_MODE_MONO)); // mono / 2d if (playing != RENDER_STEREO_MODE_OFF && playing != preferred && preferred != RENDER_STEREO_MODE_AUTO && g_Windowing.SupportsStereo(playing)) // same as movie idx_playing = pDlgSelect->Add(g_localizeStrings.Get(36532) + " (" + GetLabelForStereoMode(playing) + ")"); int idx_select = pDlgSelect->Add( g_localizeStrings.Get(36531) ); // other / select pDlgSelect->Open(); if(pDlgSelect->IsConfirmed()) { int iItem = pDlgSelect->GetSelectedItem(); if (iItem == idx_preferred) mode = preferred; else if (iItem == idx_mono) mode = RENDER_STEREO_MODE_MONO; else if (iItem == idx_playing) mode = RENDER_STEREO_MODE_AUTO; else if (iItem == idx_select) mode = GetStereoModeByUserChoice(); SetStereoModeByUser( mode ); } CApplicationMessenger::GetInstance().SendMsg(TMSG_MEDIA_UNPAUSE); } break; case STEREOSCOPIC_PLAYBACK_MODE_PREFERRED: // Stereoscopic SetStereoMode( preferred ); break; case 2: // Mono SetStereoMode( RENDER_STEREO_MODE_MONO ); break; default: break; } }
bool CMusicInfoScanner::DownloadArtistInfo(const CStdString& strPath, const CStdString& strArtist, bool& bCanceled, CGUIDialogProgress* pDialog) { XFILE::MUSICDATABASEDIRECTORY::CQueryParams params; XFILE::MUSICDATABASEDIRECTORY::CDirectoryNode::GetDatabaseInfo(strPath, params); bCanceled = false; CArtist artist; m_musicDatabase.Open(); if (m_musicDatabase.GetArtistInfo(params.GetArtistId(),artist)) // already got the info return true; // find artist info ADDON::ScraperPtr info; if (!m_musicDatabase.GetScraperForPath(strPath, info, ADDON::ADDON_SCRAPER_ARTISTS) || !info) { m_musicDatabase.Close(); return false; } if (m_handle) { m_handle->SetTitle(StringUtils::Format(g_localizeStrings.Get(20320), info->Name().c_str())); m_handle->SetText(strArtist); } // clear our scraper cache info->ClearCache(); CMusicInfoScraper scraper(info); // handle nfo files CStdString strArtistPath, strNfo; m_musicDatabase.GetArtistPath(params.GetArtistId(),strArtistPath); URIUtils::AddFileToFolder(strArtistPath,"artist.nfo",strNfo); CNfoFile::NFOResult result=CNfoFile::NO_NFO; CNfoFile nfoReader; if (XFILE::CFile::Exists(strNfo)) { CLog::Log(LOGDEBUG,"Found matching nfo file: %s", strNfo.c_str()); result = nfoReader.Create(strNfo, info); if (result == CNfoFile::FULL_NFO) { CLog::Log(LOGDEBUG, "%s Got details from nfo", __FUNCTION__); CArtist artist; nfoReader.GetDetails(artist); m_musicDatabase.SetArtistInfo(params.GetArtistId(), artist); map<string, string> artwork = GetArtistArtwork(params.GetArtistId(), &artist); m_musicDatabase.SetArtForItem(params.GetArtistId(), "artist", artwork); m_musicDatabase.Close(); return true; } else if (result == CNfoFile::URL_NFO || result == CNfoFile::COMBINED_NFO) { CScraperUrl scrUrl(nfoReader.ScraperUrl()); CMusicArtistInfo artist("nfo",scrUrl); info = nfoReader.GetScraperInfo(); CLog::Log(LOGDEBUG,"-- nfo-scraper: %s",info->Name().c_str()); CLog::Log(LOGDEBUG,"-- nfo url: %s", scrUrl.m_url[0].m_url.c_str()); scraper.SetScraperInfo(info); scraper.GetArtists().push_back(artist); } else CLog::Log(LOGERROR,"Unable to find an url in nfo file: %s", strNfo.c_str()); } if (!scraper.GetArtistCount()) { scraper.FindArtistInfo(strArtist); while (!scraper.Completed()) { if (m_bStop) { scraper.Cancel(); bCanceled = true; } Sleep(1); } } int iSelectedArtist = 0; if (result == CNfoFile::NO_NFO) { if (scraper.Succeeded() && scraper.GetArtistCount() >= 1) { // now load the first match if (pDialog && scraper.GetArtistCount() > 1) { // if we found more then 1 album, let user choose one CGUIDialogSelect *pDlg = (CGUIDialogSelect*)g_windowManager.GetWindow(WINDOW_DIALOG_SELECT); if (pDlg) { pDlg->SetHeading(g_localizeStrings.Get(21890)); pDlg->Reset(); pDlg->EnableButton(true, 413); // manual for (int i = 0; i < scraper.GetArtistCount(); ++i) { // set the label to artist CFileItem item(scraper.GetArtist(i).GetArtist()); CStdString strTemp=scraper.GetArtist(i).GetArtist().strArtist; if (!scraper.GetArtist(i).GetArtist().strBorn.IsEmpty()) strTemp += " ("+scraper.GetArtist(i).GetArtist().strBorn+")"; if (!scraper.GetArtist(i).GetArtist().genre.empty()) { CStdString genres = StringUtils::Join(scraper.GetArtist(i).GetArtist().genre, g_advancedSettings.m_musicItemSeparator); if (!genres.empty()) strTemp.Format("[%s] %s", genres.c_str(), strTemp.c_str()); } item.SetLabel(strTemp); item.m_idepth = i; // use this to hold the index of the album in the scraper pDlg->Add(&item); } pDlg->DoModal(); // and wait till user selects one if (pDlg->GetSelectedLabel() < 0) { // none chosen if (!pDlg->IsButtonPressed()) { bCanceled = true; return false; } // manual button pressed CStdString strNewArtist = strArtist; if (!CGUIKeyboardFactory::ShowAndGetInput(strNewArtist, g_localizeStrings.Get(16025), false)) return false; if (pDialog) { pDialog->SetLine(0, strNewArtist); pDialog->Progress(); } m_musicDatabase.Close(); return DownloadArtistInfo(strPath,strNewArtist,bCanceled,pDialog); } iSelectedArtist = pDlg->GetSelectedItem()->m_idepth; } } } else { m_musicDatabase.Close(); return false; } } scraper.LoadArtistInfo(iSelectedArtist, strArtist); while (!scraper.Completed()) { if (m_bStop) { scraper.Cancel(); bCanceled = true; } Sleep(1); } if (scraper.Succeeded()) { artist = scraper.GetArtist(iSelectedArtist).GetArtist(); if (result == CNfoFile::COMBINED_NFO) nfoReader.GetDetails(artist,NULL,true); m_musicDatabase.SetArtistInfo(params.GetArtistId(), artist); } // check thumb stuff map<string, string> artwork = GetArtistArtwork(params.GetArtistId(), &artist); m_musicDatabase.SetArtForItem(params.GetArtistId(), "artist", artwork); m_musicDatabase.Close(); return true; }
void CGUIDialogContentSettings::OnSettingAction(std::shared_ptr<const CSetting> setting) { if (setting == NULL) return; CGUIDialogSettingsManualBase::OnSettingAction(setting); const std::string &settingId = setting->GetId(); if (settingId == SETTING_CONTENT_TYPE) { std::vector<std::pair<std::string, int>> labels; if (m_content == CONTENT_ALBUMS || m_content == CONTENT_ARTISTS) { labels.push_back(std::make_pair(ADDON::TranslateContent(m_content, true), m_content)); } else { labels.push_back(std::make_pair(ADDON::TranslateContent(CONTENT_NONE, true), CONTENT_NONE)); labels.push_back(std::make_pair(ADDON::TranslateContent(CONTENT_MOVIES, true), CONTENT_MOVIES)); labels.push_back(std::make_pair(ADDON::TranslateContent(CONTENT_TVSHOWS, true), CONTENT_TVSHOWS)); labels.push_back(std::make_pair(ADDON::TranslateContent(CONTENT_MUSICVIDEOS, true), CONTENT_MUSICVIDEOS)); } std::sort(labels.begin(), labels.end()); CGUIDialogSelect *dialog = g_windowManager.GetWindow<CGUIDialogSelect>(WINDOW_DIALOG_SELECT); if (dialog) { dialog->SetHeading(CVariant{ 20344 }); //Label "This directory contains" int iIndex = 0; int iSelected = 0; for (const auto &label : labels) { dialog->Add(label.first); if (m_content == label.second) iSelected = iIndex; iIndex++; } dialog->SetSelected(iSelected); dialog->Open(); // Selected item has not changes - in case of cancel or the user selecting the same item int newSelected = dialog->GetSelectedItem(); if (!dialog->IsConfirmed() || newSelected < 0 || newSelected == iSelected) return; auto selected = labels.at(newSelected); m_content = static_cast<CONTENT_TYPE>(selected.second); AddonPtr scraperAddon; if (!CAddonSystemSettings::GetInstance().GetActive(ADDON::ScraperTypeFromContent(m_content), scraperAddon) && m_content != CONTENT_NONE) return; m_scraper = std::dynamic_pointer_cast<CScraper>(scraperAddon); SetupView(); SetFocus(SETTING_CONTENT_TYPE); } } else if (settingId == SETTING_SCRAPER_LIST) { ADDON::TYPE type = ADDON::ScraperTypeFromContent(m_content); std::string currentScraperId; if (m_scraper != nullptr) currentScraperId = m_scraper->ID(); std::string selectedAddonId = currentScraperId; if (CGUIWindowAddonBrowser::SelectAddonID(type, selectedAddonId, false) == 1 && selectedAddonId != currentScraperId) { AddonPtr scraperAddon; CServiceBroker::GetAddonMgr().GetAddon(selectedAddonId, scraperAddon); m_scraper = std::dynamic_pointer_cast<CScraper>(scraperAddon); SetupView(); SetFocus(SETTING_SCRAPER_LIST); } } else if (settingId == SETTING_SCRAPER_SETTINGS) CGUIDialogAddonSettings::ShowForAddon(m_scraper, false); }
void CPVRClients::ProcessMenuHooks(int iClientID, PVR_MENUHOOK_CAT cat, const CFileItem *item) { // get client id if (iClientID < 0 && cat == PVR_MENUHOOK_SETTING) { PVR_CLIENTMAP clients; GetConnectedClients(clients); if (clients.size() == 1) { iClientID = clients.begin()->first; } else if (clients.size() > 1) { // have user select client CGUIDialogSelect* pDialog = (CGUIDialogSelect*)g_windowManager.GetWindow(WINDOW_DIALOG_SELECT); pDialog->Reset(); pDialog->SetHeading(CVariant{19196}); PVR_CLIENTMAP_CITR itrClients; for (itrClients = clients.begin(); itrClients != clients.end(); itrClients++) { pDialog->Add(itrClients->second->GetBackendName()); } pDialog->Open(); int selection = pDialog->GetSelectedItem(); if (selection >= 0) { itrClients = clients.begin(); for (int i = 0; i < selection; i++) itrClients++; iClientID = itrClients->first; } } } if (iClientID < 0) iClientID = GetPlayingClientID(); PVR_CLIENT client; if (GetConnectedClient(iClientID, client) && client->HaveMenuHooks(cat)) { PVR_MENUHOOKS *hooks = client->GetMenuHooks(); std::vector<int> hookIDs; int selection = 0; CGUIDialogSelect* pDialog = (CGUIDialogSelect*)g_windowManager.GetWindow(WINDOW_DIALOG_SELECT); pDialog->Reset(); pDialog->SetHeading(CVariant{19196}); for (unsigned int i = 0; i < hooks->size(); i++) if (hooks->at(i).category == cat || hooks->at(i).category == PVR_MENUHOOK_ALL) { pDialog->Add(g_localizeStrings.GetAddonString(client->ID(), hooks->at(i).iLocalizedStringId)); hookIDs.push_back(i); } if (hookIDs.size() > 1) { pDialog->Open(); selection = pDialog->GetSelectedItem(); } if (selection >= 0) client->CallMenuHook(hooks->at(hookIDs.at(selection)), item); } }
bool CPlayerController::OnAction(const CAction &action) { const unsigned int MsgTime = 300; const unsigned int DisplTime = 2000; if (g_application.GetAppPlayer().IsPlayingVideo()) { switch (action.GetID()) { case ACTION_SHOW_SUBTITLES: { if (g_application.GetAppPlayer().GetSubtitleCount() == 0) return true; bool subsOn = !g_application.GetAppPlayer().GetSubtitleVisible(); g_application.GetAppPlayer().SetSubtitleVisible(subsOn); std::string sub, lang; if (subsOn) { SubtitleStreamInfo info; g_application.GetAppPlayer().GetSubtitleStreamInfo(g_application.GetAppPlayer().GetSubtitle(), info); if (!g_LangCodeExpander.Lookup(info.language, lang)) lang = g_localizeStrings.Get(13205); // Unknown if (info.name.length() == 0) sub = lang; else sub = StringUtils::Format("%s - %s", lang.c_str(), info.name.c_str()); } else sub = g_localizeStrings.Get(1223); CGUIDialogKaiToast::QueueNotification(CGUIDialogKaiToast::Info, g_localizeStrings.Get(287), sub, DisplTime, false, MsgTime); return true; } case ACTION_NEXT_SUBTITLE: case ACTION_CYCLE_SUBTITLE: { if (g_application.GetAppPlayer().GetSubtitleCount() == 0) return true; int currentSub = g_application.GetAppPlayer().GetSubtitle(); bool currentSubVisible = true; if (g_application.GetAppPlayer().GetSubtitleVisible()) { if (++currentSub >= g_application.GetAppPlayer().GetSubtitleCount()) { currentSub = 0; if (action.GetID() == ACTION_NEXT_SUBTITLE) { g_application.GetAppPlayer().SetSubtitleVisible(false); currentSubVisible = false; } } g_application.GetAppPlayer().SetSubtitle(currentSub); } else if (action.GetID() == ACTION_NEXT_SUBTITLE) { g_application.GetAppPlayer().SetSubtitleVisible(true); } std::string sub, lang; if (currentSubVisible) { SubtitleStreamInfo info; g_application.GetAppPlayer().GetSubtitleStreamInfo(currentSub, info); if (!g_LangCodeExpander.Lookup(info.language, lang)) lang = g_localizeStrings.Get(13205); // Unknown if (info.name.length() == 0) sub = lang; else sub = StringUtils::Format("%s - %s", lang.c_str(), info.name.c_str()); } else sub = g_localizeStrings.Get(1223); CGUIDialogKaiToast::QueueNotification(CGUIDialogKaiToast::Info, g_localizeStrings.Get(287), sub, DisplTime, false, MsgTime); return true; } case ACTION_SUBTITLE_DELAY_MIN: { CVideoSettings vs = g_application.GetAppPlayer().GetVideoSettings(); vs.m_SubtitleDelay -= 0.1f; if (vs.m_SubtitleDelay < -g_advancedSettings.m_videoSubsDelayRange) vs.m_SubtitleDelay = -g_advancedSettings.m_videoSubsDelayRange; g_application.GetAppPlayer().SetSubTitleDelay(vs.m_SubtitleDelay); ShowSlider(action.GetID(), 22006, g_application.GetAppPlayer().GetVideoSettings().m_SubtitleDelay, -g_advancedSettings.m_videoSubsDelayRange, 0.1f, g_advancedSettings.m_videoSubsDelayRange); return true; } case ACTION_SUBTITLE_DELAY_PLUS: { CVideoSettings vs = g_application.GetAppPlayer().GetVideoSettings(); vs.m_SubtitleDelay += 0.1f; if (vs.m_SubtitleDelay > g_advancedSettings.m_videoSubsDelayRange) vs.m_SubtitleDelay = g_advancedSettings.m_videoSubsDelayRange; g_application.GetAppPlayer().SetSubTitleDelay(vs.m_SubtitleDelay); ShowSlider(action.GetID(), 22006, g_application.GetAppPlayer().GetVideoSettings().m_SubtitleDelay, -g_advancedSettings.m_videoSubsDelayRange, 0.1f, g_advancedSettings.m_videoSubsDelayRange); return true; } case ACTION_SUBTITLE_DELAY: { ShowSlider(action.GetID(), 22006, g_application.GetAppPlayer().GetVideoSettings().m_SubtitleDelay, -g_advancedSettings.m_videoSubsDelayRange, 0.1f, g_advancedSettings.m_videoSubsDelayRange, true); return true; } case ACTION_AUDIO_DELAY: { ShowSlider(action.GetID(), 297, g_application.GetAppPlayer().GetVideoSettings().m_AudioDelay, -g_advancedSettings.m_videoAudioDelayRange, 0.025f, g_advancedSettings.m_videoAudioDelayRange, true); return true; } case ACTION_AUDIO_DELAY_MIN: { CVideoSettings vs = g_application.GetAppPlayer().GetVideoSettings(); vs.m_AudioDelay -= 0.025f; if (vs.m_AudioDelay < -g_advancedSettings.m_videoAudioDelayRange) vs.m_AudioDelay = -g_advancedSettings.m_videoAudioDelayRange; g_application.GetAppPlayer().SetAVDelay(vs.m_AudioDelay); ShowSlider(action.GetID(), 297, g_application.GetAppPlayer().GetVideoSettings().m_AudioDelay, -g_advancedSettings.m_videoAudioDelayRange, 0.025f, g_advancedSettings.m_videoAudioDelayRange); return true; } case ACTION_AUDIO_DELAY_PLUS: { CVideoSettings vs = g_application.GetAppPlayer().GetVideoSettings(); vs.m_AudioDelay += 0.025f; if (vs.m_AudioDelay > g_advancedSettings.m_videoAudioDelayRange) vs.m_AudioDelay = g_advancedSettings.m_videoAudioDelayRange; g_application.GetAppPlayer().SetAVDelay(vs.m_AudioDelay); ShowSlider(action.GetID(), 297, g_application.GetAppPlayer().GetVideoSettings().m_AudioDelay, -g_advancedSettings.m_videoAudioDelayRange, 0.025f, g_advancedSettings.m_videoAudioDelayRange); return true; } case ACTION_AUDIO_NEXT_LANGUAGE: { if (g_application.GetAppPlayer().GetAudioStreamCount() == 1) return true; int currentAudio = g_application.GetAppPlayer().GetAudioStream(); if (++currentAudio >= g_application.GetAppPlayer().GetAudioStreamCount()) currentAudio = 0; g_application.GetAppPlayer().SetAudioStream(currentAudio); // Set the audio stream to the one selected std::string aud; std::string lan; AudioStreamInfo info; g_application.GetAppPlayer().GetAudioStreamInfo(currentAudio, info); if (!g_LangCodeExpander.Lookup(info.language, lan)) lan = g_localizeStrings.Get(13205); // Unknown if (info.name.empty()) aud = lan; else aud = StringUtils::Format("%s - %s", lan.c_str(), info.name.c_str()); CGUIDialogKaiToast::QueueNotification(CGUIDialogKaiToast::Info, g_localizeStrings.Get(460), aud, DisplTime, false, MsgTime); return true; } case ACTION_ZOOM_IN: { CVideoSettings vs = g_application.GetAppPlayer().GetVideoSettings(); vs.m_CustomZoomAmount += 0.01f; if (vs.m_CustomZoomAmount > 2.f) vs.m_CustomZoomAmount = 2.f; vs.m_ViewMode = ViewModeCustom; g_application.GetAppPlayer().SetRenderViewMode(ViewModeCustom, vs.m_CustomZoomAmount, vs.m_CustomPixelRatio, vs.m_CustomVerticalShift, vs.m_CustomNonLinStretch); ShowSlider(action.GetID(), 216, vs.m_CustomZoomAmount, 0.5f, 0.1f, 2.0f); return true; } case ACTION_ZOOM_OUT: { CVideoSettings vs = g_application.GetAppPlayer().GetVideoSettings(); vs.m_CustomZoomAmount -= 0.01f; if (vs.m_CustomZoomAmount < 0.5f) vs.m_CustomZoomAmount = 0.5f; vs.m_ViewMode = ViewModeCustom; g_application.GetAppPlayer().SetRenderViewMode(ViewModeCustom, vs.m_CustomZoomAmount, vs.m_CustomPixelRatio, vs.m_CustomVerticalShift, vs.m_CustomNonLinStretch); ShowSlider(action.GetID(), 216, vs.m_CustomZoomAmount, 0.5f, 0.1f, 2.0f); return true; } case ACTION_INCREASE_PAR: { CVideoSettings vs = g_application.GetAppPlayer().GetVideoSettings(); vs.m_CustomPixelRatio += 0.01f; if (vs.m_CustomPixelRatio > 2.f) vs.m_CustomPixelRatio = 2.f; vs.m_ViewMode = ViewModeCustom; g_application.GetAppPlayer().SetRenderViewMode(ViewModeCustom, vs.m_CustomZoomAmount, vs.m_CustomPixelRatio, vs.m_CustomVerticalShift, vs.m_CustomNonLinStretch); ShowSlider(action.GetID(), 217, vs.m_CustomPixelRatio, 0.5f, 0.1f, 2.0f); return true; } case ACTION_DECREASE_PAR: { CVideoSettings vs = g_application.GetAppPlayer().GetVideoSettings(); vs.m_CustomPixelRatio -= 0.01f; if (vs.m_CustomPixelRatio < 0.5f) vs.m_CustomPixelRatio = 0.5f; vs.m_ViewMode = ViewModeCustom; g_application.GetAppPlayer().SetRenderViewMode(ViewModeCustom, vs.m_CustomZoomAmount, vs.m_CustomPixelRatio, vs.m_CustomVerticalShift, vs.m_CustomNonLinStretch); ShowSlider(action.GetID(), 217, vs.m_CustomPixelRatio, 0.5f, 0.1f, 2.0f); return true; } case ACTION_VSHIFT_UP: { CVideoSettings vs = g_application.GetAppPlayer().GetVideoSettings(); vs.m_CustomVerticalShift -= 0.01f; if (vs.m_CustomVerticalShift < -2.0f) vs.m_CustomVerticalShift = -2.0f; vs.m_ViewMode = ViewModeCustom; g_application.GetAppPlayer().SetRenderViewMode(ViewModeCustom, vs.m_CustomZoomAmount, vs.m_CustomPixelRatio, vs.m_CustomVerticalShift, vs.m_CustomNonLinStretch); ShowSlider(action.GetID(), 225, vs.m_CustomVerticalShift, -2.0f, 0.1f, 2.0f); return true; } case ACTION_VSHIFT_DOWN: { CVideoSettings vs = g_application.GetAppPlayer().GetVideoSettings(); vs.m_CustomVerticalShift += 0.01f; if (vs.m_CustomVerticalShift > 2.0f) vs.m_CustomVerticalShift = 2.0f; vs.m_ViewMode = ViewModeCustom; g_application.GetAppPlayer().SetRenderViewMode(ViewModeCustom, vs.m_CustomZoomAmount, vs.m_CustomPixelRatio, vs.m_CustomVerticalShift, vs.m_CustomNonLinStretch); ShowSlider(action.GetID(), 225, vs.m_CustomVerticalShift, -2.0f, 0.1f, 2.0f); return true; } case ACTION_SUBTITLE_VSHIFT_UP: { RESOLUTION_INFO res_info = CServiceBroker::GetWinSystem()->GetGfxContext().GetResInfo(); int subalign = CServiceBroker::GetSettings().GetInt(CSettings::SETTING_SUBTITLES_ALIGN); if ((subalign == SUBTITLE_ALIGN_BOTTOM_OUTSIDE) || (subalign == SUBTITLE_ALIGN_TOP_INSIDE)) { res_info.iSubtitles ++; if (res_info.iSubtitles >= res_info.iHeight) res_info.iSubtitles = res_info.iHeight - 1; ShowSlider(action.GetID(), 274, (float) res_info.iHeight - res_info.iSubtitles, 0.0f, 1.0f, (float) res_info.iHeight); } else { res_info.iSubtitles --; if (res_info.iSubtitles < 0) res_info.iSubtitles = 0; if (subalign == SUBTITLE_ALIGN_MANUAL) ShowSlider(action.GetID(), 274, (float) res_info.iSubtitles, 0.0f, 1.0f, (float) res_info.iHeight); else ShowSlider(action.GetID(), 274, (float) res_info.iSubtitles - res_info.iHeight, (float) -res_info.iHeight, -1.0f, 0.0f); } CServiceBroker::GetWinSystem()->GetGfxContext().SetResInfo(CServiceBroker::GetWinSystem()->GetGfxContext().GetVideoResolution(), res_info); return true; } case ACTION_SUBTITLE_VSHIFT_DOWN: { RESOLUTION_INFO res_info = CServiceBroker::GetWinSystem()->GetGfxContext().GetResInfo(); int subalign = CServiceBroker::GetSettings().GetInt(CSettings::SETTING_SUBTITLES_ALIGN); if ((subalign == SUBTITLE_ALIGN_BOTTOM_OUTSIDE) || (subalign == SUBTITLE_ALIGN_TOP_INSIDE)) { res_info.iSubtitles--; if (res_info.iSubtitles < 0) res_info.iSubtitles = 0; ShowSlider(action.GetID(), 274, (float) res_info.iHeight - res_info.iSubtitles, 0.0f, 1.0f, (float) res_info.iHeight); } else { res_info.iSubtitles++; if (res_info.iSubtitles >= res_info.iHeight) res_info.iSubtitles = res_info.iHeight - 1; if (subalign == SUBTITLE_ALIGN_MANUAL) ShowSlider(action.GetID(), 274, (float) res_info.iSubtitles, 0.0f, 1.0f, (float) res_info.iHeight); else ShowSlider(action.GetID(), 274, (float) res_info.iSubtitles - res_info.iHeight, (float) -res_info.iHeight, -1.0f, 0.0f); } CServiceBroker::GetWinSystem()->GetGfxContext().SetResInfo(CServiceBroker::GetWinSystem()->GetGfxContext().GetVideoResolution(), res_info); return true; } case ACTION_SUBTITLE_ALIGN: { RESOLUTION_INFO res_info = CServiceBroker::GetWinSystem()->GetGfxContext().GetResInfo(); int subalign = CServiceBroker::GetSettings().GetInt(CSettings::SETTING_SUBTITLES_ALIGN); subalign++; if (subalign > SUBTITLE_ALIGN_TOP_OUTSIDE) subalign = SUBTITLE_ALIGN_MANUAL; res_info.iSubtitles = res_info.iHeight - 1; CServiceBroker::GetSettings().SetInt(CSettings::SETTING_SUBTITLES_ALIGN, subalign); CGUIDialogKaiToast::QueueNotification(CGUIDialogKaiToast::Info, g_localizeStrings.Get(21460), g_localizeStrings.Get(21461 + subalign), TOAST_DISPLAY_TIME, false); CServiceBroker::GetWinSystem()->GetGfxContext().SetResInfo(CServiceBroker::GetWinSystem()->GetGfxContext().GetVideoResolution(), res_info); return true; } case ACTION_VOLAMP_UP: case ACTION_VOLAMP_DOWN: { // Don't allow change with passthrough audio if (g_application.GetAppPlayer().IsPassthrough()) { CGUIDialogKaiToast::QueueNotification(CGUIDialogKaiToast::Warning, g_localizeStrings.Get(660), g_localizeStrings.Get(29802), TOAST_DISPLAY_TIME, false); return false; } float sliderMax = VOLUME_DRC_MAXIMUM / 100.0f; float sliderMin = VOLUME_DRC_MINIMUM / 100.0f; CVideoSettings vs = g_application.GetAppPlayer().GetVideoSettings(); if (action.GetID() == ACTION_VOLAMP_UP) vs.m_VolumeAmplification += 1.0f; else vs.m_VolumeAmplification -= 1.0f; vs.m_VolumeAmplification = std::max(std::min(vs.m_VolumeAmplification, sliderMax), sliderMin); g_application.GetAppPlayer().SetDynamicRangeCompression((long)(vs.m_VolumeAmplification * 100)); ShowSlider(action.GetID(), 660, vs.m_VolumeAmplification, sliderMin, 1.0f, sliderMax); return true; } case ACTION_VOLAMP: { float sliderMax = VOLUME_DRC_MAXIMUM / 100.0f; float sliderMin = VOLUME_DRC_MINIMUM / 100.0f; ShowSlider(action.GetID(), 660, g_application.GetAppPlayer().GetVideoSettings().m_VolumeAmplification, sliderMin, 1.0f, sliderMax, true); return true; } case ACTION_PLAYER_PROGRAM_SELECT: { std::vector<ProgramInfo> programs; g_application.GetAppPlayer().GetPrograms(programs); CGUIDialogSelect *dialog = CServiceBroker::GetGUI()->GetWindowManager().GetWindow<CGUIDialogSelect>(WINDOW_DIALOG_SELECT); if (dialog) { int playing = 0; int idx = 0; for (auto prog : programs) { dialog->Add(prog.name); if (prog.playing) playing = idx; idx++; } dialog->SetHeading(CVariant{g_localizeStrings.Get(39109)}); dialog->SetSelected(playing); dialog->Open(); idx = dialog->GetSelectedItem(); if (idx > 0) g_application.GetAppPlayer().SetProgram(programs[idx].id); } return true; } case ACTION_PLAYER_RESOLUTION_SELECT: { std::vector<CVariant> indexList = CServiceBroker::GetSettings().GetList(CSettings::SETTING_VIDEOSCREEN_WHITELIST); CGUIDialogSelect *dialog = CServiceBroker::GetGUI()->GetWindowManager().GetWindow<CGUIDialogSelect>(WINDOW_DIALOG_SELECT); if (dialog) { int current = 0; int idx = 0; auto currentRes = CServiceBroker::GetWinSystem()->GetGfxContext().GetVideoResolution(); for (const CVariant &mode : indexList) { auto res = CDisplaySettings::GetInstance().GetResFromString(mode.asString()); const RESOLUTION_INFO info = CServiceBroker::GetWinSystem()->GetGfxContext().GetResInfo(res); dialog->Add(info.strMode); if (res == currentRes) current = idx; idx++; } dialog->SetHeading(CVariant{g_localizeStrings.Get(39110)}); dialog->SetSelected(current); dialog->Open(); idx = dialog->GetSelectedItem(); if (idx >= 0) { auto res = CDisplaySettings::GetInstance().GetResFromString(indexList[idx].asString()); CServiceBroker::GetWinSystem()->GetGfxContext().SetVideoResolution(res, false); } } return true; } default: break; } } return false; }
INFO_RET CMusicInfoScanner::DownloadArtistInfo(const CArtist& artist, const ADDON::ScraperPtr& info, MUSIC_GRABBER::CMusicArtistInfo& artistInfo, CGUIDialogProgress* pDialog) { if (m_handle) { m_handle->SetTitle(StringUtils::Format(g_localizeStrings.Get(20320).c_str(), info->Name().c_str())); m_handle->SetText(artist.strArtist); } // clear our scraper cache info->ClearCache(); CMusicInfoScraper scraper(info); bool bMusicBrainz = false; if (!artist.strMusicBrainzArtistID.empty()) { CScraperUrl musicBrainzURL; if (ResolveMusicBrainz(artist.strMusicBrainzArtistID, info, musicBrainzURL)) { CMusicArtistInfo artistNfo("nfo", musicBrainzURL); scraper.GetArtists().clear(); scraper.GetArtists().push_back(artistNfo); bMusicBrainz = true; } } // handle nfo files std::string path = artist.strPath; if (path.empty()) m_musicDatabase.GetArtistPath(artist.idArtist, path); std::string strNfo = URIUtils::AddFileToFolder(path, "artist.nfo"); CNfoFile::NFOResult result=CNfoFile::NO_NFO; CNfoFile nfoReader; if (XFILE::CFile::Exists(strNfo)) { CLog::Log(LOGDEBUG,"Found matching nfo file: %s", strNfo.c_str()); result = nfoReader.Create(strNfo, info); if (result == CNfoFile::FULL_NFO) { CLog::Log(LOGDEBUG, "%s Got details from nfo", __FUNCTION__); nfoReader.GetDetails(artistInfo.GetArtist()); return INFO_ADDED; } else if (result == CNfoFile::URL_NFO || result == CNfoFile::COMBINED_NFO) { CScraperUrl scrUrl(nfoReader.ScraperUrl()); CMusicArtistInfo artistNfo("nfo",scrUrl); ADDON::ScraperPtr nfoReaderScraper = nfoReader.GetScraperInfo(); CLog::Log(LOGDEBUG,"-- nfo-scraper: %s",nfoReaderScraper->Name().c_str()); CLog::Log(LOGDEBUG,"-- nfo url: %s", scrUrl.m_url[0].m_url.c_str()); scraper.SetScraperInfo(nfoReaderScraper); scraper.GetArtists().push_back(artistNfo); } else CLog::Log(LOGERROR,"Unable to find an url in nfo file: %s", strNfo.c_str()); } if (!scraper.GetArtistCount()) { scraper.FindArtistInfo(artist.strArtist); while (!scraper.Completed()) { if (m_bStop) { scraper.Cancel(); return INFO_CANCELLED; } Sleep(1); } } int iSelectedArtist = 0; if (result == CNfoFile::NO_NFO && !bMusicBrainz) { if (scraper.GetArtistCount() >= 1) { // now load the first match if (pDialog && scraper.GetArtistCount() > 1) { // if we found more then 1 album, let user choose one CGUIDialogSelect *pDlg = (CGUIDialogSelect*)g_windowManager.GetWindow(WINDOW_DIALOG_SELECT); if (pDlg) { pDlg->SetHeading(g_localizeStrings.Get(21890)); pDlg->Reset(); pDlg->EnableButton(true, 413); // manual for (int i = 0; i < scraper.GetArtistCount(); ++i) { // set the label to artist CFileItem item(scraper.GetArtist(i).GetArtist()); std::string strTemp=scraper.GetArtist(i).GetArtist().strArtist; if (!scraper.GetArtist(i).GetArtist().strBorn.empty()) strTemp += " ("+scraper.GetArtist(i).GetArtist().strBorn+")"; if (!scraper.GetArtist(i).GetArtist().genre.empty()) { std::string genres = StringUtils::Join(scraper.GetArtist(i).GetArtist().genre, g_advancedSettings.m_musicItemSeparator); if (!genres.empty()) strTemp = StringUtils::Format("[%s] %s", genres.c_str(), strTemp.c_str()); } item.SetLabel(strTemp); item.m_idepth = i; // use this to hold the index of the album in the scraper pDlg->Add(&item); } pDlg->DoModal(); // and wait till user selects one if (pDlg->GetSelectedLabel() < 0) { // none chosen if (!pDlg->IsButtonPressed()) return INFO_CANCELLED; // manual button pressed std::string strNewArtist = artist.strArtist; if (!CGUIKeyboardFactory::ShowAndGetInput(strNewArtist, g_localizeStrings.Get(16025), false)) return INFO_CANCELLED; if (pDialog) { pDialog->SetLine(0, strNewArtist); pDialog->Progress(); } CArtist newArtist; newArtist.strArtist = strNewArtist; return DownloadArtistInfo(newArtist, info, artistInfo, pDialog); } iSelectedArtist = pDlg->GetSelectedItem()->m_idepth; } } } else return INFO_NOT_FOUND; } scraper.LoadArtistInfo(iSelectedArtist, artist.strArtist); while (!scraper.Completed()) { if (m_bStop) { scraper.Cancel(); return INFO_CANCELLED; } Sleep(1); } if (!scraper.Succeeded()) return INFO_ERROR; artistInfo = scraper.GetArtist(iSelectedArtist); if (result == CNfoFile::COMBINED_NFO) nfoReader.GetDetails(artistInfo.GetArtist(), NULL, true); return INFO_ADDED; }
INFO_RET CMusicInfoScanner::DownloadAlbumInfo(const CAlbum& album, const ADDON::ScraperPtr& info, CMusicAlbumInfo& albumInfo, CGUIDialogProgress* pDialog) { if (m_handle) { m_handle->SetTitle(StringUtils::Format(g_localizeStrings.Get(20321).c_str(), info->Name().c_str())); m_handle->SetText(StringUtils::Join(album.artist, g_advancedSettings.m_musicItemSeparator) + " - " + album.strAlbum); } // clear our scraper cache info->ClearCache(); CMusicInfoScraper scraper(info); bool bMusicBrainz = false; if (!album.strMusicBrainzAlbumID.empty()) { CScraperUrl musicBrainzURL; if (ResolveMusicBrainz(album.strMusicBrainzAlbumID, info, musicBrainzURL)) { CMusicAlbumInfo albumNfo("nfo", musicBrainzURL); scraper.GetAlbums().clear(); scraper.GetAlbums().push_back(albumNfo); bMusicBrainz = true; } } // handle nfo files std::string path = album.strPath; if (path.empty()) m_musicDatabase.GetAlbumPath(album.idAlbum, path); std::string strNfo = URIUtils::AddFileToFolder(path, "album.nfo"); CNfoFile::NFOResult result = CNfoFile::NO_NFO; CNfoFile nfoReader; if (XFILE::CFile::Exists(strNfo)) { CLog::Log(LOGDEBUG,"Found matching nfo file: %s", strNfo.c_str()); result = nfoReader.Create(strNfo, info); if (result == CNfoFile::FULL_NFO) { CLog::Log(LOGDEBUG, "%s Got details from nfo", __FUNCTION__); nfoReader.GetDetails(albumInfo.GetAlbum()); return INFO_ADDED; } else if (result == CNfoFile::URL_NFO || result == CNfoFile::COMBINED_NFO) { CScraperUrl scrUrl(nfoReader.ScraperUrl()); CMusicAlbumInfo albumNfo("nfo",scrUrl); ADDON::ScraperPtr nfoReaderScraper = nfoReader.GetScraperInfo(); CLog::Log(LOGDEBUG,"-- nfo-scraper: %s", nfoReaderScraper->Name().c_str()); CLog::Log(LOGDEBUG,"-- nfo url: %s", scrUrl.m_url[0].m_url.c_str()); scraper.SetScraperInfo(nfoReaderScraper); scraper.GetAlbums().clear(); scraper.GetAlbums().push_back(albumNfo); } else CLog::Log(LOGERROR,"Unable to find an url in nfo file: %s", strNfo.c_str()); } if (!scraper.CheckValidOrFallback(CSettings::Get().GetString("musiclibrary.albumsscraper"))) { // the current scraper is invalid, as is the default - bail CLog::Log(LOGERROR, "%s - current and default scrapers are invalid. Pick another one", __FUNCTION__); return INFO_ERROR; } if (!scraper.GetAlbumCount()) { scraper.FindAlbumInfo(album.strAlbum, StringUtils::Join(album.artist, g_advancedSettings.m_musicItemSeparator)); while (!scraper.Completed()) { if (m_bStop) { scraper.Cancel(); return INFO_CANCELLED; } Sleep(1); } } CGUIDialogSelect *pDlg = NULL; int iSelectedAlbum=0; if (result == CNfoFile::NO_NFO && !bMusicBrainz) { iSelectedAlbum = -1; // set negative so that we can detect a failure if (scraper.Succeeded() && scraper.GetAlbumCount() >= 1) { double bestRelevance = 0; double minRelevance = THRESHOLD; if (scraper.GetAlbumCount() > 1) // score the matches { //show dialog with all albums found if (pDialog) { pDlg = (CGUIDialogSelect*)g_windowManager.GetWindow(WINDOW_DIALOG_SELECT); pDlg->SetHeading(g_localizeStrings.Get(181).c_str()); pDlg->Reset(); pDlg->EnableButton(true, 413); // manual } for (int i = 0; i < scraper.GetAlbumCount(); ++i) { CMusicAlbumInfo& info = scraper.GetAlbum(i); double relevance = info.GetRelevance(); if (relevance < 0) relevance = CUtil::AlbumRelevance(info.GetAlbum().strAlbum, album.strAlbum, StringUtils::Join(info.GetAlbum().artist, g_advancedSettings.m_musicItemSeparator), StringUtils::Join(album.artist, g_advancedSettings.m_musicItemSeparator)); // if we're doing auto-selection (ie querying all albums at once, then allow 95->100% for perfect matches) // otherwise, perfect matches only if (relevance >= max(minRelevance, bestRelevance)) { // we auto-select the best of these bestRelevance = relevance; iSelectedAlbum = i; } if (pDialog) { // set the label to [relevance] album - artist std::string strTemp = StringUtils::Format("[%0.2f] %s", relevance, info.GetTitle2().c_str()); CFileItem item(strTemp); item.m_idepth = i; // use this to hold the index of the album in the scraper pDlg->Add(&item); } if (relevance > .99f) // we're so close, no reason to search further break; } if (pDialog && bestRelevance < THRESHOLD) { pDlg->Sort(false); pDlg->DoModal(); // and wait till user selects one if (pDlg->GetSelectedLabel() < 0) { // none chosen if (!pDlg->IsButtonPressed()) return INFO_CANCELLED; // manual button pressed std::string strNewAlbum = album.strAlbum; if (!CGUIKeyboardFactory::ShowAndGetInput(strNewAlbum, g_localizeStrings.Get(16011), false)) return INFO_CANCELLED; if (strNewAlbum == "") return INFO_CANCELLED; std::string strNewArtist = StringUtils::Join(album.artist, g_advancedSettings.m_musicItemSeparator); if (!CGUIKeyboardFactory::ShowAndGetInput(strNewArtist, g_localizeStrings.Get(16025), false)) return INFO_CANCELLED; pDialog->SetLine(0, strNewAlbum); pDialog->SetLine(1, strNewArtist); pDialog->Progress(); CAlbum newAlbum = album; newAlbum.strAlbum = strNewAlbum; newAlbum.artist = StringUtils::Split(strNewArtist, g_advancedSettings.m_musicItemSeparator); return DownloadAlbumInfo(newAlbum, info, albumInfo, pDialog); } iSelectedAlbum = pDlg->GetSelectedItem()->m_idepth; } } else { CMusicAlbumInfo& info = scraper.GetAlbum(0); double relevance = info.GetRelevance(); if (relevance < 0) relevance = CUtil::AlbumRelevance(info.GetAlbum().strAlbum, album.strAlbum, StringUtils::Join(info.GetAlbum().artist, g_advancedSettings.m_musicItemSeparator), StringUtils::Join(album.artist, g_advancedSettings.m_musicItemSeparator)); if (relevance < THRESHOLD) return INFO_NOT_FOUND; iSelectedAlbum = 0; } } if (iSelectedAlbum < 0) return INFO_NOT_FOUND; } scraper.LoadAlbumInfo(iSelectedAlbum); while (!scraper.Completed()) { if (m_bStop) { scraper.Cancel(); return INFO_CANCELLED; } Sleep(1); } if (!scraper.Succeeded()) return INFO_ERROR; albumInfo = scraper.GetAlbum(iSelectedAlbum); if (result == CNfoFile::COMBINED_NFO) nfoReader.GetDetails(albumInfo.GetAlbum(), NULL, true); return INFO_ADDED; }
bool CMusicInfoScanner::DownloadArtistInfo(const CStdString& strPath, const CStdString& strArtist, CGUIDialogProgress* pDialog) { DIRECTORY::MUSICDATABASEDIRECTORY::CQueryParams params; DIRECTORY::MUSICDATABASEDIRECTORY::CDirectoryNode::GetDatabaseInfo(strPath, params); CArtist artist; m_musicDatabase.Open(); if (m_musicDatabase.GetArtistInfo(params.GetArtistId(),artist)) // already got the info return true; // find artist info SScraperInfo info; if (!m_musicDatabase.GetScraperForPath(strPath,info)) { m_musicDatabase.Close(); return false; } if (m_pObserver) { m_pObserver->OnStateChanged(DOWNLOADING_ARTIST_INFO); m_pObserver->OnDirectoryChanged(strArtist); } CMusicInfoScraper scraper(info); // handle nfo files CStdString strArtistPath, strNfo; m_musicDatabase.GetArtistPath(params.GetArtistId(),strArtistPath); CUtil::AddFileToFolder(strArtistPath,"artist.nfo",strNfo); if (XFILE::CFile::Exists(strNfo)) { CLog::Log(LOGDEBUG,"Found matching nfo file: %s", strNfo.c_str()); CNfoFile nfoReader("albums"); if (nfoReader.Create(strNfo) == S_OK) { if (nfoReader.m_strScraper == "NFO") { CLog::Log(LOGDEBUG, "%s Got details from nfo", __FUNCTION__); CArtist artist; nfoReader.GetDetails(artist); m_musicDatabase.SetArtistInfo(params.GetArtistId(), artist); m_musicDatabase.Close(); return true; } else { CScraperUrl scrUrl(nfoReader.m_strImDbUrl); CMusicArtistInfo artist("nfo",scrUrl); scraper.GetArtists().push_back(artist); } } else CLog::Log(LOGERROR,"Unable to find an url in nfo file: %s", strNfo.c_str()); } if (!scraper.GetArtistCount()) scraper.FindArtistinfo(strArtist); while (!scraper.Completed()) { if (m_bStop) { scraper.Cancel(); break; } Sleep(1); } if (scraper.Successfull() && scraper.GetArtistCount() >= 1) { int iSelectedArtist = 0; // now load the first match if (pDialog && scraper.GetArtistCount() > 1) { // if we found more then 1 album, let user choose one CGUIDialogSelect *pDlg = (CGUIDialogSelect*)m_gWindowManager.GetWindow(WINDOW_DIALOG_SELECT); if (pDlg) { pDlg->SetHeading(g_localizeStrings.Get(21890)); pDlg->Reset(); pDlg->EnableButton(true); pDlg->SetButtonLabel(413); // manual for (int i = 0; i < scraper.GetArtistCount(); ++i) { // set the label to artist CFileItem item(scraper.GetArtist(i).GetArtist()); CStdString strTemp=scraper.GetArtist(i).GetArtist().strArtist; if (!scraper.GetArtist(i).GetArtist().strBorn.IsEmpty()) strTemp += " ("+scraper.GetArtist(i).GetArtist().strBorn+")"; if (!scraper.GetArtist(i).GetArtist().strGenre.IsEmpty()) strTemp.Format("[%s] %s",scraper.GetArtist(i).GetArtist().strGenre.c_str(),strTemp.c_str()); item.SetLabel(strTemp); item.m_idepth = i; // use this to hold the index of the album in the scraper pDlg->Add(&item); } pDlg->DoModal(); // and wait till user selects one if (pDlg->GetSelectedLabel() < 0) { // none chosen if (!pDlg->IsButtonPressed()) return false; // manual button pressed CStdString strNewArtist = strArtist; if (!CGUIDialogKeyboard::ShowAndGetInput(strNewArtist, g_localizeStrings.Get(16025), false)) return false; if (pDialog) { pDialog->SetLine(0, strNewArtist); pDialog->Progress(); } m_musicDatabase.Close(); return DownloadArtistInfo(strPath,strArtist,pDialog); } iSelectedArtist = pDlg->GetSelectedItem().m_idepth; } } scraper.LoadArtistinfo(iSelectedArtist); while (!scraper.Completed()) { if (m_bStop) { scraper.Cancel(); break; } Sleep(1); } if (scraper.Successfull()) { artist = scraper.GetArtist(iSelectedArtist).GetArtist(); m_musicDatabase.SetArtistInfo(params.GetArtistId(), artist); } } else { m_musicDatabase.Close(); return false; } // check thumb stuff if (artist.thumbURL.m_url.size()) { CFileItem item(strArtist); CStdString thumb = item.GetCachedArtistThumb(); if (!XFILE::CFile::Exists(thumb)) CScraperUrl::DownloadThumbnail(thumb,artist.thumbURL.m_url[0]); } m_musicDatabase.Close(); return true; }