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(); }
CGUIDialogSelect *CGUIDialogSelectGameClient::GetDialog(const std::string &title) { CGUIDialogSelect *dialog = CServiceBroker::GetGUI()->GetWindowManager().GetWindow<CGUIDialogSelect>(WINDOW_DIALOG_SELECT); if (dialog != nullptr) { dialog->Reset(); dialog->SetHeading(CVariant{ title }); dialog->SetUseDetails(true); } return dialog; }
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->GetSelectedLabel() : -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()); } }
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 CGUIWindowSettingsProfile::GetAutoLoginProfileChoice(int &iProfile) { CGUIDialogSelect *dialog = (CGUIDialogSelect*)g_windowManager.GetWindow(WINDOW_DIALOG_SELECT); if (!dialog) return false; // add items // "Most recent" option comes first, so up indices by 1 int autoLoginProfileId = CProfilesManager::Get().GetAutoLoginProfileId() + 1; CFileItemList items; CFileItemPtr item(new CFileItem()); item->SetLabel(g_localizeStrings.Get(37014)); // Most recent item->SetIconImage("unknown-user.png"); items.Add(item); for (unsigned int i = 0; i < CProfilesManager::Get().GetNumberOfProfiles(); i++) { const CProfile *profile = CProfilesManager::Get().GetProfile(i); CStdString locked = g_localizeStrings.Get(profile->getLockMode() > 0 ? 20166 : 20165); CFileItemPtr item(new CFileItem(profile->getName())); item->SetProperty("Addon.Summary", locked); // lock setting CStdString thumb = profile->getThumb(); if (thumb.IsEmpty()) thumb = "unknown-user.png"; item->SetIconImage(thumb); items.Add(item); } dialog->SetHeading(20093); // Profile name dialog->Reset(); dialog->SetUseDetails(true); dialog->EnableButton(true, 222); // Cancel dialog->SetItems(&items); dialog->SetSelected(autoLoginProfileId); dialog->DoModal(); if (dialog->IsButtonPressed() || dialog->GetSelectedLabel() < 0) return false; // user cancelled iProfile = dialog->GetSelectedLabel() - 1; 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); 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(); }
int CGUIWindowAddonBrowser::SelectAddonID(const std::vector<ADDON::TYPE> &types, std::vector<std::string> &addonIDs, bool showNone /* = false */, bool showDetails /* = true */, bool multipleSelection /* = true */, bool showInstalled /* = true */, bool showInstallable /* = false */, bool showMore /* = true */) { // if we shouldn't show neither installed nor installable addons the list will be empty if (!showInstalled && !showInstallable) return -1; // can't show the "Get More" button if we already show installable addons if (showInstallable) showMore = false; CGUIDialogSelect *dialog = g_windowManager.GetWindow<CGUIDialogSelect>(); if (!dialog) return -1; // get rid of any invalid addon types std::vector<ADDON::TYPE> validTypes(types.size()); std::copy_if(types.begin(), types.end(), validTypes.begin(), [](ADDON::TYPE type) { return type != ADDON_UNKNOWN; }); if (validTypes.empty()) return -1; // get all addons to show VECADDONS addons; if (showInstalled) { for (std::vector<ADDON::TYPE>::const_iterator type = validTypes.begin(); type != validTypes.end(); ++type) { VECADDONS typeAddons; if (*type == ADDON_AUDIO) CAddonsDirectory::GetScriptsAndPlugins("audio", typeAddons); else if (*type == ADDON_EXECUTABLE) CAddonsDirectory::GetScriptsAndPlugins("executable", typeAddons); else if (*type == ADDON_IMAGE) CAddonsDirectory::GetScriptsAndPlugins("image", typeAddons); else if (*type == ADDON_VIDEO) CAddonsDirectory::GetScriptsAndPlugins("video", typeAddons); else if (*type == ADDON_GAME) CAddonsDirectory::GetScriptsAndPlugins("game", typeAddons); else CAddonMgr::GetInstance().GetAddons(typeAddons, *type); addons.insert(addons.end(), typeAddons.begin(), typeAddons.end()); } } if (showInstallable || showMore) { VECADDONS installableAddons; if (CAddonMgr::GetInstance().GetInstallableAddons(installableAddons)) { for (ADDON::IVECADDONS addon = installableAddons.begin(); addon != installableAddons.end();) { AddonPtr pAddon = *addon; // check if the addon matches one of the provided addon types bool matchesType = false; for (std::vector<ADDON::TYPE>::const_iterator type = validTypes.begin(); type != validTypes.end(); ++type) { if (pAddon->IsType(*type)) { matchesType = true; break; } } if (matchesType) { ++addon; continue; } addon = installableAddons.erase(addon); } if (showInstallable) addons.insert(addons.end(), installableAddons.begin(), installableAddons.end()); else if (showMore) showMore = !installableAddons.empty(); } } if (addons.empty() && !showNone) return -1; // turn the addons into items std::map<std::string, AddonPtr> addonMap; CFileItemList items; for (ADDON::IVECADDONS addon = addons.begin(); addon != addons.end(); ++addon) { CFileItemPtr item(CAddonsDirectory::FileItemFromAddon(*addon, (*addon)->ID())); item->SetLabel2((*addon)->Summary()); if (!items.Contains(item->GetPath())) { items.Add(item); addonMap.insert(std::make_pair(item->GetPath(), *addon)); } } if (items.IsEmpty() && !showNone) return -1; std::string heading; for (std::vector<ADDON::TYPE>::const_iterator type = validTypes.begin(); type != validTypes.end(); ++type) { if (!heading.empty()) heading += ", "; heading += TranslateType(*type, true); } dialog->SetHeading(CVariant{std::move(heading)}); dialog->Reset(); dialog->SetUseDetails(showDetails); if (multipleSelection) { showNone = false; showMore = false; dialog->EnableButton(true, 186); } else if (showMore) dialog->EnableButton(true, 21452); if (showNone) { CFileItemPtr item(new CFileItem("", false)); item->SetLabel(g_localizeStrings.Get(231)); item->SetLabel2(g_localizeStrings.Get(24040)); item->SetIconImage("DefaultAddonNone.png"); item->SetSpecialSort(SortSpecialOnTop); items.Add(item); } items.Sort(SortByLabel, SortOrderAscending); if (!addonIDs.empty()) { for (std::vector<std::string>::const_iterator it = addonIDs.begin(); it != addonIDs.end() ; ++it) { CFileItemPtr item = items.Get(*it); if (item) item->Select(true); } } dialog->SetItems(items); dialog->SetMultiSelection(multipleSelection); dialog->Open(); // if the "Get More" button has been pressed and we haven't shown the // installable addons so far show a list of installable addons if (showMore&& dialog->IsButtonPressed()) return SelectAddonID(types, addonIDs, showNone, showDetails, multipleSelection, false, true, false); if (!dialog->IsConfirmed()) return 0; addonIDs.clear(); for (int i : dialog->GetSelectedItems()) { const CFileItemPtr& item = items.Get(i); // check if one of the selected addons needs to be installed if (showInstallable) { std::map<std::string, AddonPtr>::const_iterator itAddon = addonMap.find(item->GetPath()); if (itAddon != addonMap.end()) { const AddonPtr& addon = itAddon->second; // if the addon isn't installed we need to install it if (!CAddonMgr::GetInstance().IsAddonInstalled(addon->ID())) { AddonPtr installedAddon; if (!CAddonInstaller::GetInstance().InstallModal(addon->ID(), installedAddon, false)) continue; } // if the addon is disabled we need to enable it if (CAddonMgr::GetInstance().IsAddonDisabled(addon->ID())) CAddonMgr::GetInstance().EnableAddon(addon->ID()); } } addonIDs.push_back(item->GetPath()); } return 1; }
int CGUIWindowAddonBrowser::SelectAddonID(const vector<ADDON::TYPE> &types, CStdStringArray &addonIDs, bool showNone /*= false*/, bool multipleSelection /*= true*/) { CGUIDialogSelect *dialog = (CGUIDialogSelect*)g_windowManager.GetWindow(WINDOW_DIALOG_SELECT); if (!dialog) return 0; CFileItemList items; CStdString heading; int iTypes = 0; for (vector<ADDON::TYPE>::const_iterator it = types.begin(); it != types.end(); ++it) { if (*it == ADDON_UNKNOWN) continue; ADDON::VECADDONS addons; iTypes++; if (*it == ADDON_AUDIO) CAddonsDirectory::GetScriptsAndPlugins("audio",addons); else if (*it == ADDON_EXECUTABLE) CAddonsDirectory::GetScriptsAndPlugins("executable",addons); else if (*it == ADDON_IMAGE) CAddonsDirectory::GetScriptsAndPlugins("image",addons); else if (*it == ADDON_VIDEO) CAddonsDirectory::GetScriptsAndPlugins("video",addons); else CAddonMgr::Get().GetAddons(*it, addons); for (ADDON::IVECADDONS it2 = addons.begin() ; it2 != addons.end() ; ++it2) { CFileItemPtr item(CAddonsDirectory::FileItemFromAddon(*it2, "")); if (!items.Contains(item->GetPath())) items.Add(item); } if (!heading.IsEmpty()) heading += ", "; heading += TranslateType(*it, true); } if (iTypes == 0) return 0; dialog->SetHeading(heading); dialog->Reset(); dialog->SetUseDetails(true); if (multipleSelection) showNone = false; if (multipleSelection || iTypes > 1) dialog->EnableButton(true, 186); else dialog->EnableButton(true, 21452); if (showNone) { CFileItemPtr item(new CFileItem("", false)); item->SetLabel(g_localizeStrings.Get(231)); item->SetLabel2(g_localizeStrings.Get(24040)); item->SetIconImage("DefaultAddonNone.png"); item->SetSpecialSort(SortSpecialOnTop); items.Add(item); } items.Sort(SORT_METHOD_LABEL, SortOrderAscending); if (addonIDs.size() > 0) { for (CStdStringArray::const_iterator it = addonIDs.begin(); it != addonIDs.end() ; it++) { CFileItemPtr item = items.Get(*it); if (item) item->Select(true); } } dialog->SetItems(&items); dialog->SetMultiSelection(multipleSelection); dialog->DoModal(); if (!multipleSelection && iTypes == 1 && dialog->IsButtonPressed()) { // switch to the addons browser. vector<CStdString> params; params.push_back("addons://all/"+TranslateType(types[0],false)+"/"); params.push_back("return"); g_windowManager.ActivateWindow(WINDOW_ADDON_BROWSER, params); return 2; } if (!dialog->IsConfirmed()) return 0; addonIDs.clear(); const CFileItemList& list = dialog->GetSelectedItems(); for (int i = 0 ; i < list.Size() ; i++) addonIDs.push_back(list.Get(i)->GetPath()); return 1; }
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); }
int CGUIWindowAddonBrowser::SelectAddonID(ADDON::TYPE type, CStdStringArray &addonIDs, bool showNone /*= false*/, bool multipleSelection /*= true*/) { CGUIDialogSelect *dialog = (CGUIDialogSelect*)g_windowManager.GetWindow(WINDOW_DIALOG_SELECT); if (type == ADDON_UNKNOWN || !dialog) return 0; ADDON::VECADDONS addons; if (type == ADDON_AUDIO) CAddonsDirectory::GetScriptsAndPlugins("audio",addons); else if (type == ADDON_EXECUTABLE) CAddonsDirectory::GetScriptsAndPlugins("executable",addons); else if (type == ADDON_IMAGE) CAddonsDirectory::GetScriptsAndPlugins("image",addons); else if (type == ADDON_VIDEO) CAddonsDirectory::GetScriptsAndPlugins("video",addons); else CAddonMgr::Get().GetAddons(type, addons); CFileItemList items; for (ADDON::IVECADDONS i = addons.begin(); i != addons.end(); ++i) items.Add(CAddonsDirectory::FileItemFromAddon(*i, "")); dialog->SetHeading(TranslateType(type, true)); dialog->Reset(); dialog->SetUseDetails(true); if (multipleSelection) { showNone = false; dialog->EnableButton(true, 186); } else dialog->EnableButton(true, 21452); if (showNone) { CFileItemPtr item(new CFileItem("", false)); item->SetLabel(g_localizeStrings.Get(231)); item->SetLabel2(g_localizeStrings.Get(24040)); item->SetIconImage("DefaultAddonNone.png"); item->SetSpecialSort(SORT_ON_TOP); items.Add(item); } items.Sort(SORT_METHOD_LABEL, SORT_ORDER_ASC); if (addonIDs.size() > 0) { for (CStdStringArray::const_iterator it = addonIDs.begin(); it != addonIDs.end() ; it++) { CFileItemPtr item = items.Get(*it); if (item) item->Select(true); } } dialog->SetItems(&items); dialog->SetMultiSelection(multipleSelection); dialog->DoModal(); if (!multipleSelection && dialog->IsButtonPressed()) { // switch to the addons browser. vector<CStdString> params; params.push_back("addons://all/"+TranslateType(type,false)+"/"); params.push_back("return"); g_windowManager.ActivateWindow(WINDOW_ADDON_BROWSER, params); return 2; } if (!multipleSelection && dialog->GetSelectedLabel() == -1) return 0; addonIDs.clear(); const CFileItemList& list = dialog->GetSelectedItems(); for (int i = 0 ; i < list.Size() ; i++) addonIDs.push_back(list.Get(i)->GetPath()); return 1; }