void CGUIControlButtonSetting::OnSliderChange(void *data, CGUISliderControl *slider) { if (slider == NULL) return; std::string strText; switch (m_pSetting->GetType()) { case SettingTypeInteger: { CSettingInt *settingInt = static_cast<CSettingInt*>(m_pSetting); if (settingInt->SetValue(slider->GetIntValue())) strText = CGUIControlSliderSetting::GetText(static_cast<const CSettingControlSlider*>(m_pSetting->GetControl()), settingInt->GetValue(), settingInt->GetMinimum(), settingInt->GetStep(), settingInt->GetMaximum()); break; } case SettingTypeNumber: { CSettingNumber *settingNumber = static_cast<CSettingNumber*>(m_pSetting); if (settingNumber->SetValue(static_cast<double>(slider->GetFloatValue()))) strText = CGUIControlSliderSetting::GetText(static_cast<const CSettingControlSlider*>(m_pSetting->GetControl()), settingNumber->GetValue(), settingNumber->GetMinimum(), settingNumber->GetStep(), settingNumber->GetMaximum()); break; } default: break; } if (!strText.empty()) slider->SetTextValue(strText); }
void CPeripheral::PersistSettings(bool bExiting /* = false */) { CXBMCTinyXML doc; TiXmlElement node("settings"); doc.InsertEndChild(node); for (map<CStdString, CSetting *>::const_iterator itr = m_settings.begin(); itr != m_settings.end(); itr++) { TiXmlElement nodeSetting("setting"); nodeSetting.SetAttribute("id", itr->first.c_str()); CStdString strValue; switch ((*itr).second->GetType()) { case SettingTypeString: { CSettingString *stringSetting = (CSettingString *) (*itr).second; if (stringSetting) strValue = stringSetting->GetValue(); } break; case SettingTypeInteger: { CSettingInt *intSetting = (CSettingInt *) (*itr).second; if (intSetting) strValue = StringUtils::Format("%d", intSetting->GetValue()); } break; case SettingTypeNumber: { CSettingNumber *floatSetting = (CSettingNumber *) (*itr).second; if (floatSetting) strValue = StringUtils::Format("%.2f", floatSetting->GetValue()); } break; case SettingTypeBool: { CSettingBool *boolSetting = (CSettingBool *) (*itr).second; if (boolSetting) strValue = StringUtils::Format("%d", boolSetting->GetValue() ? 1:0); } break; default: break; } nodeSetting.SetAttribute("value", strValue.c_str()); doc.RootElement()->InsertEndChild(nodeSetting); } doc.SaveFile(m_strSettingsFile); if (!bExiting) { for (set<CStdString>::const_iterator it = m_changedSettings.begin(); it != m_changedSettings.end(); it++) OnSettingChanged(*it); } m_changedSettings.clear(); }
float CPeripheral::GetSettingFloat(const CStdString &strKey) const { map<CStdString, CSetting *>::const_iterator it = m_settings.find(strKey); if (it != m_settings.end() && (*it).second->GetType() == SettingTypeNumber) { CSettingNumber *floatSetting = (CSettingNumber *) (*it).second; if (floatSetting) return (float)floatSetting->GetValue(); } return 0; }
float CPeripheral::GetSettingFloat(const std::string &strKey) const { std::map<std::string, PeripheralDeviceSetting>::const_iterator it = m_settings.find(strKey); if (it != m_settings.end() && (*it).second.m_setting->GetType() == SettingTypeNumber) { CSettingNumber *floatSetting = (CSettingNumber *) (*it).second.m_setting; if (floatSetting) return (float)floatSetting->GetValue(); } return 0; }
void CGUIControlSpinExSetting::FillControl() { m_pSpin->Clear(); switch (m_pSetting->GetControl().GetFormat()) { case SettingControlFormatNumber: { CSettingNumber *pSettingNumber = (CSettingNumber *)m_pSetting; m_pSpin->SetType(SPIN_CONTROL_TYPE_FLOAT); m_pSpin->SetFloatRange((float)pSettingNumber->GetMinimum(), (float)pSettingNumber->GetMaximum()); m_pSpin->SetFloatInterval((float)pSettingNumber->GetStep()); m_pSpin->SetFloatValue((float)pSettingNumber->GetValue()); break; } case SettingControlFormatInteger: { m_pSpin->SetType(SPIN_CONTROL_TYPE_TEXT); FillIntegerSettingControl(); break; } case SettingControlFormatString: { m_pSpin->SetType(SPIN_CONTROL_TYPE_TEXT); if (m_pSetting->GetType() == SettingTypeInteger) FillIntegerSettingControl(); else if (m_pSetting->GetType() == SettingTypeString) { CSettingString *pSettingString = (CSettingString *)m_pSetting; if (pSettingString->GetOptionsType() == SettingOptionsTypeDynamic) { DynamicStringSettingOptions options = pSettingString->UpdateDynamicOptions(); for (std::vector< std::pair<std::string, std::string> >::const_iterator option = options.begin(); option != options.end(); ++option) m_pSpin->AddLabel(option->first, option->second); m_pSpin->SetStringValue(pSettingString->GetValue()); } } break; } default: break; } }
bool CPeripheral::SetSetting(const CStdString &strKey, float fValue) { bool bChanged(false); map<CStdString, CSetting *>::iterator it = m_settings.find(strKey); if (it != m_settings.end() && (*it).second->GetType() == SettingTypeNumber) { CSettingNumber *floatSetting = (CSettingNumber *) (*it).second; if (floatSetting) { bChanged = floatSetting->GetValue() != fValue; floatSetting->SetValue(fValue); if (bChanged && m_bInitialised) m_changedSettings.insert(strKey); } } return bChanged; }
void CGUIControlSpinExSetting::FillControl() { if (m_pSpin == NULL) return; m_pSpin->Clear(); const std::string &controlFormat = m_pSetting->GetControl()->GetFormat(); if (controlFormat == "number") { CSettingNumber *pSettingNumber = (CSettingNumber *)m_pSetting; m_pSpin->SetType(SPIN_CONTROL_TYPE_FLOAT); m_pSpin->SetFloatRange((float)pSettingNumber->GetMinimum(), (float)pSettingNumber->GetMaximum()); m_pSpin->SetFloatInterval((float)pSettingNumber->GetStep()); m_pSpin->SetFloatValue((float)pSettingNumber->GetValue()); } else if (controlFormat == "integer") { m_pSpin->SetType(SPIN_CONTROL_TYPE_TEXT); FillIntegerSettingControl(); } else if (controlFormat == "string") { m_pSpin->SetType(SPIN_CONTROL_TYPE_TEXT); if (m_pSetting->GetType() == SettingTypeInteger) FillIntegerSettingControl(); else if (m_pSetting->GetType() == SettingTypeString) { DynamicStringSettingOptions options; std::set<std::string> selectedValues; // get the string options if (!GetStringOptions(m_pSetting, options, selectedValues) || selectedValues.size() != 1) return; // add them to the spinner for (const auto& option : options) m_pSpin->AddLabel(option.first, option.second); // and set the current value m_pSpin->SetStringValue(*selectedValues.begin()); } } }
bool CGUIControlButtonSetting::OnClick() { if (m_pButton == NULL) return false; const ISettingControl *control = m_pSetting->GetControl(); const std::string &controlType = control->GetType(); const std::string &controlFormat = control->GetFormat(); if (controlType == "button") { const CSettingControlButton *buttonControl = static_cast<const CSettingControlButton*>(control); if (controlFormat == "addon") { // prompt for the addon CSettingAddon *setting = (CSettingAddon *)m_pSetting; std::string addonID = setting->GetValue(); if (CGUIWindowAddonBrowser::SelectAddonID(setting->GetAddonType(), addonID, setting->AllowEmpty(), buttonControl->ShowAddonDetails(), buttonControl->ShowInstalledAddons(), buttonControl->ShowInstallableAddons(), buttonControl->ShowMoreAddons()) != 1) return false; SetValid(setting->SetValue(addonID)); } else if (controlFormat == "path") SetValid(GetPath((CSettingPath *)m_pSetting)); else if (controlFormat == "action") { // simply call the OnSettingAction callback and whoever knows what to // do can do so (based on the setting's identification CSettingAction *pSettingAction = (CSettingAction *)m_pSetting; pSettingAction->OnSettingAction(pSettingAction); SetValid(true); } } else if (controlType == "slider") { float value, min, step, max; if (m_pSetting->GetType() == SettingTypeInteger) { CSettingInt *settingInt = static_cast<CSettingInt*>(m_pSetting); value = (float)settingInt->GetValue(); min = (float)settingInt->GetMinimum(); step = (float)settingInt->GetStep(); max = (float)settingInt->GetMaximum(); } else if (m_pSetting->GetType() == SettingTypeNumber) { CSettingNumber *settingNumber = static_cast<CSettingNumber*>(m_pSetting); value = (float)settingNumber->GetValue(); min = (float)settingNumber->GetMinimum(); step = (float)settingNumber->GetStep(); max = (float)settingNumber->GetMaximum(); } else return false; const CSettingControlSlider *sliderControl = static_cast<const CSettingControlSlider*>(control); CGUIDialogSlider::ShowAndGetInput(g_localizeStrings.Get(sliderControl->GetHeading()), value, min, step, max, this, NULL); SetValid(true); } return IsValid(); }
void CGUIDialogPeripheralSettings::CreateSettings() { m_bIsInitialising = true; m_usePopupSliders = g_SkinInfo->HasSkinFile("DialogSlider.xml"); if (m_item) { CPeripheral *peripheral = g_peripherals.GetByPath(m_item->GetPath()); if (peripheral) { vector<CSetting *> settings = peripheral->GetSettings(); for (size_t iPtr = 0; iPtr < settings.size(); iPtr++) { CSetting *setting = settings[iPtr]; if (!setting->IsVisible()) { CLog::Log(LOGDEBUG, "%s - invisible", __FUNCTION__); continue; } switch(setting->GetType()) { case SettingTypeBool: { CSettingBool *boolSetting = (CSettingBool *) setting; if (boolSetting) { m_boolSettings.insert(make_pair(CStdString(boolSetting->GetId()), boolSetting->GetValue())); AddBool(m_settingId++, boolSetting->GetLabel(), &m_boolSettings[boolSetting->GetId()], true); } } break; case SettingTypeInteger: { CSettingInt *intSetting = (CSettingInt *) setting; if (intSetting) { if (intSetting->GetControl()->GetFormat() == "integer") { m_intSettings.insert(make_pair(CStdString(intSetting->GetId()), (float) intSetting->GetValue())); AddSlider(m_settingId++, intSetting->GetLabel(), &m_intSettings[intSetting->GetId()], (float)intSetting->GetMinimum(), (float)intSetting->GetStep(), (float)intSetting->GetMaximum(), CGUIDialogVideoSettings::FormatInteger, false); } else if (intSetting->GetControl()->GetFormat() == "string") { m_intTextSettings.insert(make_pair(CStdString(intSetting->GetId()), intSetting->GetValue())); vector<pair<int, int> > entries; StaticIntegerSettingOptions::const_iterator entriesItr = intSetting->GetOptions().begin(); while (entriesItr != intSetting->GetOptions().end()) { entries.push_back(make_pair(entriesItr->first, entriesItr->second)); ++entriesItr; } AddSpin(m_settingId++, intSetting->GetLabel(), &m_intTextSettings[intSetting->GetId()], entries); } } } break; case SettingTypeNumber: { CSettingNumber *floatSetting = (CSettingNumber *) setting; if (floatSetting) { m_floatSettings.insert(make_pair(CStdString(floatSetting->GetId()), (float)floatSetting->GetValue())); AddSlider(m_settingId++, floatSetting->GetLabel(), &m_floatSettings[floatSetting->GetId()], (float)floatSetting->GetMinimum(), (float)floatSetting->GetStep(), (float)floatSetting->GetMaximum(), CGUIDialogVideoSettings::FormatFloat, false); } } break; case SettingTypeString: { CSettingString *stringSetting = (CSettingString *) setting; if (stringSetting) { m_stringSettings.insert(make_pair(CStdString(stringSetting->GetId()), stringSetting->GetValue())); AddString(m_settingId++, stringSetting->GetLabel(), &m_stringSettings[stringSetting->GetId()]); } } break; default: //TODO add more types if needed CLog::Log(LOGDEBUG, "%s - unknown type", __FUNCTION__); break; } } } else { CLog::Log(LOGDEBUG, "%s - no peripheral", __FUNCTION__); } } m_bIsInitialising = false; }