CSettingBool* CGUIDialogSettingsManualBase::AddToggle(CSettingGroup *group, const std::string &id, int label, int level, bool value, bool delayed /* = false */, bool visible /* = true */, int help /* = -1 */) { if (group == NULL || id.empty() || label < 0 || GetSetting(id) != NULL) return NULL; CSettingBool *setting = new CSettingBool(id, label, value, m_settingsManager); if (setting == NULL) return NULL; setting->SetControl(GetCheckmarkControl(delayed)); setSettingDetails(setting, level, visible, help); group->AddSetting(setting); return setting; }
void CGUIDialogPeripheralSettings::InitializeSettings() { if (m_item == NULL) { m_initialising = false; return; } m_initialising = true; bool usePopup = g_SkinInfo->HasSkinFile("DialogSlider.xml"); CPeripheral *peripheral = g_peripherals.GetByPath(m_item->GetPath()); if (peripheral == NULL) { CLog::Log(LOGDEBUG, "%s - no peripheral", __FUNCTION__); m_initialising = false; return; } m_settingsMap.clear(); CGUIDialogSettingsManualBase::InitializeSettings(); CSettingCategory *category = AddCategory("peripheralsettings", -1); if (category == NULL) { CLog::Log(LOGERROR, "CGUIDialogPeripheralSettings: unable to setup settings"); return; } CSettingGroup *group = AddGroup(category); if (group == NULL) { CLog::Log(LOGERROR, "CGUIDialogPeripheralSettings: unable to setup settings"); return; } std::vector<CSetting*> settings = peripheral->GetSettings(); for (std::vector<CSetting*>::iterator itSetting = settings.begin(); itSetting != settings.end(); ++itSetting) { CSetting *setting = *itSetting; if (setting == NULL) continue; if (!setting->IsVisible()) { CLog::Log(LOGDEBUG, "%s - invisible", __FUNCTION__); continue; } // we need to create a copy of the setting because the CSetting instances // are destroyed when leaving the dialog CSetting *settingCopy = NULL; switch(setting->GetType()) { case SettingTypeBool: { CSettingBool *settingBool = new CSettingBool(setting->GetId(), *static_cast<CSettingBool*>(setting)); settingBool->SetControl(GetCheckmarkControl()); settingCopy = static_cast<CSetting*>(settingBool); break; } case SettingTypeInteger: { CSettingInt *intSetting = static_cast<CSettingInt*>(setting); if (intSetting == NULL) break; CSettingInt *settingInt = new CSettingInt(setting->GetId(), *intSetting); if (settingInt->GetOptions().empty()) settingInt->SetControl(GetSliderControl("integer", false, -1, usePopup, -1, "%i")); else settingInt->SetControl(GetSpinnerControl("string")); settingCopy = static_cast<CSetting*>(settingInt); break; } case SettingTypeNumber: { CSettingNumber *settingNumber = new CSettingNumber(setting->GetId(), *static_cast<CSettingNumber*>(setting)); settingNumber->SetControl(GetSliderControl("number", false, -1, usePopup, -1, "%2.2f")); settingCopy = static_cast<CSetting*>(settingNumber); break; } case SettingTypeString: { CSettingString *settingString = new CSettingString(setting->GetId(), *static_cast<CSettingString*>(setting)); settingString->SetControl(GetEditControl("string")); settingCopy = static_cast<CSetting*>(settingString); break; } default: // TODO: add more types if needed CLog::Log(LOGDEBUG, "%s - unknown type", __FUNCTION__); break; } if (settingCopy != NULL && settingCopy->GetControl() != NULL) { settingCopy->SetLevel(SettingLevelBasic); group->AddSetting(settingCopy); m_settingsMap.insert(std::make_pair(setting->GetId(), setting)); } } m_initialising = false; }