CGUIControl* CGUIDialogSettingsBase::AddSetting(CSetting *pSetting, float width, int &iControlID) { if (pSetting == NULL) return NULL; BaseSettingControlPtr pSettingControl; CGUIControl *pControl = NULL; // determine the label and any possible indentation in case of sub settings string label = GetLocalizedString(pSetting->GetLabel()); int parentLevels = 0; CSetting *parentSetting = GetSetting(pSetting->GetParent()); while (parentSetting != NULL) { parentLevels++; parentSetting = GetSetting(parentSetting->GetParent()); } if (parentLevels > 0) { // add additional 2 spaces indentation for anything past one level string indentation; for (int index = 1; index < parentLevels; index++) indentation.append(" "); label = StringUtils::Format(g_localizeStrings.Get(168).c_str(), indentation.c_str(), label.c_str()); } // create the proper controls if (!pSetting->GetControl()) return NULL; std::string controlType = pSetting->GetControl()->GetType(); if (controlType == "toggle") { if (m_pOriginalRadioButton != NULL) pControl = new CGUIRadioButtonControl(*m_pOriginalRadioButton); if (pControl == NULL) return NULL; ((CGUIRadioButtonControl *)pControl)->SetLabel(label); pSettingControl.reset(new CGUIControlRadioButtonSetting((CGUIRadioButtonControl *)pControl, iControlID, pSetting)); } else if (controlType == "spinner") { if (m_pOriginalSpin != NULL) pControl = new CGUISpinControlEx(*m_pOriginalSpin); if (pControl == NULL) return NULL; ((CGUISpinControlEx *)pControl)->SetText(label); pSettingControl.reset(new CGUIControlSpinExSetting((CGUISpinControlEx *)pControl, iControlID, pSetting)); } else if (controlType == "edit") { if (m_pOriginalEdit != NULL) pControl = new CGUIEditControl(*m_pOriginalEdit); if (pControl == NULL) return NULL; ((CGUIEditControl *)pControl)->SetLabel(label); pSettingControl.reset(new CGUIControlEditSetting((CGUIEditControl *)pControl, iControlID, pSetting)); } else if (controlType == "list") { if (m_pOriginalButton != NULL) pControl = new CGUIButtonControl(*m_pOriginalButton); if (pControl == NULL) return NULL; ((CGUIButtonControl *)pControl)->SetLabel(label); pSettingControl.reset(new CGUIControlListSetting((CGUIButtonControl *)pControl, iControlID, pSetting)); } else if (controlType == "button" || controlType == "slider") { if (controlType == "button" || static_cast<const CSettingControlSlider*>(pSetting->GetControl())->UsePopup()) { if (m_pOriginalButton != NULL) pControl = new CGUIButtonControl(*m_pOriginalButton); if (pControl == NULL) return NULL; ((CGUIButtonControl *)pControl)->SetLabel(label); pSettingControl.reset(new CGUIControlButtonSetting((CGUIButtonControl *)pControl, iControlID, pSetting)); } else { if (m_pOriginalSlider != NULL) pControl = new CGUISettingsSliderControl(*m_pOriginalSlider); if (pControl == NULL) return NULL; ((CGUISettingsSliderControl *)pControl)->SetText(label); pSettingControl.reset(new CGUIControlSliderSetting((CGUISettingsSliderControl *)pControl, iControlID, pSetting)); } } else if (controlType == "range") { if (m_pOriginalSlider != NULL) pControl = new CGUISettingsSliderControl(*m_pOriginalSlider); if (pControl == NULL) return NULL; ((CGUISettingsSliderControl *)pControl)->SetText(label); pSettingControl.reset(new CGUIControlRangeSetting((CGUISettingsSliderControl *)pControl, iControlID, pSetting)); } else return NULL; if (pSetting->GetControl()->GetDelayed()) pSettingControl->SetDelayed(); return AddSettingControl(pControl, pSettingControl, width, iControlID); }
CGUIControl* CGUIWindowSettingsCategory::AddSetting(CSetting *pSetting, float width, int &iControlID) { if (pSetting == NULL) return NULL; BaseSettingControlPtr pSettingControl; CGUIControl *pControl = NULL; // determine the label and any possible indentation in case of sub settings string label = g_localizeStrings.Get(pSetting->GetLabel()); int parentLevels = 0; CSetting *parentSetting = m_settings.GetSetting(pSetting->GetParent()); while (parentSetting != NULL) { parentLevels++; parentSetting = m_settings.GetSetting(parentSetting->GetParent()); } if (parentLevels > 0) { // add additional 2 spaces indentation for anything past one level string indentation; for (int index = 1; index < parentLevels; index++) indentation.append(" "); label = StringUtils::Format(g_localizeStrings.Get(168).c_str(), indentation.c_str(), label.c_str()); } // create the proper controls switch (pSetting->GetControl().GetType()) { case SettingControlTypeCheckmark: { pControl = new CGUIRadioButtonControl(*m_pOriginalRadioButton); if (pControl == NULL) return NULL; ((CGUIRadioButtonControl *)pControl)->SetLabel(label); pSettingControl.reset(new CGUIControlRadioButtonSetting((CGUIRadioButtonControl *)pControl, iControlID, pSetting)); break; } case SettingControlTypeSpinner: { pControl = new CGUISpinControlEx(*m_pOriginalSpin); if (pControl == NULL) return NULL; ((CGUISpinControlEx *)pControl)->SetText(label); pSettingControl.reset(new CGUIControlSpinExSetting((CGUISpinControlEx *)pControl, iControlID, pSetting)); break; } case SettingControlTypeEdit: { pControl = new CGUIEditControl(*m_pOriginalEdit); if (pControl == NULL) return NULL; ((CGUIEditControl *)pControl)->SetLabel(label); pSettingControl.reset(new CGUIControlEditSetting((CGUIEditControl *)pControl, iControlID, pSetting)); break; } case SettingControlTypeList: { pControl = new CGUIButtonControl(*m_pOriginalButton); if (pControl == NULL) return NULL; ((CGUIButtonControl *)pControl)->SetLabel(label); pSettingControl.reset(new CGUIControlListSetting((CGUIButtonControl *)pControl, iControlID, pSetting)); break; } case SettingControlTypeButton: { pControl = new CGUIButtonControl(*m_pOriginalButton); if (pControl == NULL) return NULL; ((CGUIButtonControl *)pControl)->SetLabel(label); pSettingControl.reset(new CGUIControlButtonSetting((CGUIButtonControl *)pControl, iControlID, pSetting)); break; } case SettingControlTypeNone: default: return NULL; } if (pSetting->GetControl().GetDelayed()) pSettingControl->SetDelayed(); return AddSettingControl(pControl, pSettingControl, width, iControlID); }