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(); }
bool CPeripheral::GetSettingBool(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() == SettingTypeBool) { CSettingBool *boolSetting = (CSettingBool *) (*it).second.m_setting; if (boolSetting) return boolSetting->GetValue(); } return false; }
bool CPeripheral::GetSettingBool(const CStdString &strKey) const { map<CStdString, CSetting *>::const_iterator it = m_settings.find(strKey); if (it != m_settings.end() && (*it).second->GetType() == SettingTypeBool) { CSettingBool *boolSetting = (CSettingBool *) (*it).second; if (boolSetting) return boolSetting->GetValue(); } return false; }
bool CPeripheral::SetSetting(const CStdString &strKey, bool bValue) { bool bChanged(false); map<CStdString, CSetting *>::iterator it = m_settings.find(strKey); if (it != m_settings.end() && (*it).second->GetType() == SettingTypeBool) { CSettingBool *boolSetting = (CSettingBool *) (*it).second; if (boolSetting) { bChanged = boolSetting->GetValue() != bValue; boolSetting->SetValue(bValue); if (bChanged && m_bInitialised) m_changedSettings.insert(strKey); } } return bChanged; }
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; }