/* * Copyright (C) 2005-2018 Team Kodi * This file is part of Kodi - https://kodi.tv * * SPDX-License-Identifier: GPL-2.0-or-later * See LICENSES/README.md for more information. */ #include "GUIDialogSettingsManualBase.h" #include "settings/SettingAddon.h" #include "settings/SettingDateTime.h" #include "settings/SettingPath.h" #include "settings/SettingUtils.h" #include "settings/lib/Setting.h" #include "settings/lib/SettingSection.h" #include "settings/lib/SettingsManager.h" #include "utils/StringUtils.h" #include "utils/Variant.h" #include #include CGUIDialogSettingsManualBase::CGUIDialogSettingsManualBase(int windowId, const std::string &xmlFile) : CGUIDialogSettingsManagerBase(windowId, xmlFile) , m_settingsManager(nullptr) { } CGUIDialogSettingsManualBase::~CGUIDialogSettingsManualBase() { if (GetSettingsManager() != nullptr) { GetSettingsManager()->Clear(); m_section = nullptr; delete GetSettingsManager(); } } void CGUIDialogSettingsManualBase::SetupView() { InitializeSettings(); if (GetSettingsManager() != nullptr) { // add the created setting section to the settings manager and mark it as ready GetSettingsManager()->AddSection(m_section); GetSettingsManager()->SetInitialized(); GetSettingsManager()->SetLoaded(); } CGUIDialogSettingsBase::SetupView(); } CSettingsManager* CGUIDialogSettingsManualBase::GetSettingsManager() const { if (m_settingsManager == nullptr) m_settingsManager = new CSettingsManager(); return m_settingsManager; } void CGUIDialogSettingsManualBase::InitializeSettings() { if (GetSettingsManager() != nullptr) { GetSettingsManager()->Clear(); m_section = NULL; // create a std::make_shared
(GetProperty("xmlfile").asString(), GetSettingsManager()); } } SettingCategoryPtr CGUIDialogSettingsManualBase::AddCategory(const std::string &id, int label, int help /* = -1 */) { if (id.empty()) return NULL; SettingCategoryPtr category = std::make_shared(id, GetSettingsManager()); if (category == NULL) return NULL; category->SetLabel(label); if (help >= 0) category->SetHelp(help); m_section->AddCategory(category); return category; } SettingGroupPtr CGUIDialogSettingsManualBase::AddGroup(const SettingCategoryPtr& category, int label /* = -1 */, int help /* = -1 */, bool separatorBelowLabel /* = true */, bool hideSeparator /* = false */) { if (category == NULL) return NULL; size_t groups = category->GetGroups().size(); SettingGroupPtr group = std::make_shared(StringUtils::Format("{0}", groups + 1), GetSettingsManager()); if (group == NULL) return NULL; if (label >= 0) group->SetLabel(label); if (help >= 0) group->SetHelp(help); group->SetControl(GetTitleControl(separatorBelowLabel, hideSeparator)); category->AddGroup(group); return group; } std::shared_ptr CGUIDialogSettingsManualBase::AddToggle(const SettingGroupPtr& group, const std::string& id, int label, SettingLevel level, bool value, bool delayed /* = false */, bool visible /* = true */, int help /* = -1 */) { if (group == NULL || id.empty() || label < 0 || GetSetting(id) != NULL) return NULL; std::shared_ptr setting = std::make_shared(id, label, value, GetSettingsManager()); if (setting == NULL) return NULL; setting->SetControl(GetCheckmarkControl(delayed)); setSettingDetails(setting, level, visible, help); group->AddSetting(setting); return setting; } std::shared_ptr CGUIDialogSettingsManualBase::AddEdit( const SettingGroupPtr& group, const std::string& id, int label, SettingLevel level, int value, int minimum /* = 0 */, int step /* = 1 */, int maximum /* = 0 */, bool verifyNewValue /* = false */, int heading /* = -1 */, bool delayed /* = false */, bool visible /* = true */, int help /* = -1 */) { if (group == NULL || id.empty() || label < 0 || GetSetting(id) != NULL) return NULL; std::shared_ptr setting = std::make_shared(id, label, value, minimum, step, maximum, GetSettingsManager()); if (setting == NULL) return NULL; setting->SetControl(GetEditControl("integer", delayed, false, verifyNewValue, heading)); setSettingDetails(setting, level, visible, help); group->AddSetting(setting); return setting; } std::shared_ptr CGUIDialogSettingsManualBase::AddEdit( const SettingGroupPtr& group, const std::string& id, int label, SettingLevel level, float value, float minimum /* = 0.0f */, float step /* = 1.0f */, float maximum /* = 0.0f */, bool verifyNewValue /* = false */, int heading /* = -1 */, bool delayed /* = false */, bool visible /* = true */, int help /* = -1 */) { if (group == NULL || id.empty() || label < 0 || GetSetting(id) != NULL) return NULL; std::shared_ptr setting = std::make_shared(id, label, value, minimum, step, maximum, GetSettingsManager()); if (setting == NULL) return NULL; setting->SetControl(GetEditControl("number", delayed, false, verifyNewValue, heading)); setSettingDetails(setting, level, visible, help); group->AddSetting(setting); return setting; } std::shared_ptr CGUIDialogSettingsManualBase::AddEdit(const SettingGroupPtr& group, const std::string& id, int label, SettingLevel level, const std::string& value, bool allowEmpty /* = false */, bool hidden /* = false */, int heading /* = -1 */, bool delayed /* = false */, bool visible /* = true */, int help /* = -1 */) { if (group == NULL || id.empty() || label < 0 || GetSetting(id) != NULL) return NULL; std::shared_ptr setting = std::make_shared(id, label, value, GetSettingsManager()); if (setting == NULL) return NULL; setting->SetControl(GetEditControl("string", delayed, hidden, false, heading)); setting->SetAllowEmpty(allowEmpty); setSettingDetails(setting, level, visible, help); group->AddSetting(setting); return setting; } std::shared_ptr CGUIDialogSettingsManualBase::AddIp(const SettingGroupPtr& group, const std::string& id, int label, SettingLevel level, const std::string& value, bool allowEmpty /* = false */, int heading /* = -1 */, bool delayed /* = false */, bool visible /* = true */, int help /* = -1 */) { if (group == NULL || id.empty() || label < 0 || GetSetting(id) != NULL) return NULL; std::shared_ptr setting = std::make_shared(id, label, value, GetSettingsManager()); if (setting == NULL) return NULL; setting->SetControl(GetEditControl("ip", delayed, false, false, heading)); setting->SetAllowEmpty(allowEmpty); setSettingDetails(setting, level, visible, help); group->AddSetting(setting); return setting; } std::shared_ptr CGUIDialogSettingsManualBase::AddPasswordMd5( const SettingGroupPtr& group, const std::string& id, int label, SettingLevel level, const std::string& value, bool allowEmpty /* = false */, int heading /* = -1 */, bool delayed /* = false */, bool visible /* = true */, int help /* = -1 */) { if (group == NULL || id.empty() || label < 0 || GetSetting(id) != NULL) return NULL; std::shared_ptr setting = std::make_shared(id, label, value, GetSettingsManager()); if (setting == NULL) return NULL; setting->SetControl(GetEditControl("md5", delayed, false, false, heading)); setting->SetAllowEmpty(allowEmpty); setSettingDetails(setting, level, visible, help); group->AddSetting(setting); return setting; } std::shared_ptr CGUIDialogSettingsManualBase::AddButton( const SettingGroupPtr& group, const std::string& id, int label, SettingLevel level, const std::string& data /* = "" */, bool delayed /* = false */, bool visible /* = true */, int help /* = -1 */) { if (group == NULL || id.empty() || label < 0 || GetSetting(id) != NULL) return NULL; std::shared_ptr setting = std::make_shared(id, label, GetSettingsManager()); if (setting == NULL) return NULL; setting->SetControl(GetButtonControl("action", delayed)); setting->SetData(data); setSettingDetails(setting, level, visible, help); group->AddSetting(setting); return setting; } std::shared_ptr CGUIDialogSettingsManualBase::AddInfoLabelButton( const SettingGroupPtr& group, const std::string& id, int label, SettingLevel level, const std::string& info, bool visible /* = true */, int help /* = -1 */) { if (group == NULL || id.empty() || label < 0 || GetSetting(id) != NULL) return NULL; std::shared_ptr setting = std::make_shared(id, label, info, GetSettingsManager()); if (setting == NULL) return NULL; setting->SetControl(GetButtonControl("infolabel", false)); setSettingDetails(setting, level, visible, help); group->AddSetting(setting); return setting; } std::shared_ptr CGUIDialogSettingsManualBase::AddAddon( const SettingGroupPtr& group, const std::string& id, int label, SettingLevel level, const std::string& value, ADDON::AddonType addonType, bool allowEmpty /* = false */, int heading /* = -1 */, bool hideValue /* = false */, bool showInstalledAddons /* = true */, bool showInstallableAddons /* = false */, bool showMoreAddons /* = true */, bool delayed /* = false */, bool visible /* = true */, int help /* = -1 */) { if (group == NULL || id.empty() || label < 0 || GetSetting(id) != NULL) return NULL; std::shared_ptr setting = std::make_shared(id, label, value, GetSettingsManager()); if (setting == NULL) return NULL; setting->SetControl(GetButtonControl("addon", delayed, heading, hideValue, showInstalledAddons, showInstallableAddons, showMoreAddons)); setting->SetAddonType(addonType); setting->SetAllowEmpty(allowEmpty); setSettingDetails(setting, level, visible, help); group->AddSetting(setting); return setting; } std::shared_ptr CGUIDialogSettingsManualBase::AddPath( const SettingGroupPtr& group, const std::string& id, int label, SettingLevel level, const std::string& value, bool writable /* = true */, const std::vector& sources /* = std::vector() */, bool allowEmpty /* = false */, int heading /* = -1 */, bool hideValue /* = false */, bool delayed /* = false */, bool visible /* = true */, int help /* = -1 */) { if (group == NULL || id.empty() || label < 0 || GetSetting(id) != NULL) return NULL; std::shared_ptr setting = std::make_shared(id, label, value, GetSettingsManager()); if (setting == NULL) return NULL; setting->SetControl(GetButtonControl("path", delayed, heading, hideValue)); setting->SetWritable(writable); setting->SetSources(sources); setting->SetAllowEmpty(allowEmpty); setSettingDetails(setting, level, visible, help); group->AddSetting(setting); return setting; } std::shared_ptr CGUIDialogSettingsManualBase::AddDate(const SettingGroupPtr& group, const std::string& id, int label, SettingLevel level, const std::string& value, bool allowEmpty /* = false */, int heading /* = -1 */, bool delayed /* = false */, bool visible /* = true */, int help /* = -1 */) { if (group == NULL || id.empty() || label < 0 || GetSetting(id) != NULL) return NULL; std::shared_ptr setting = std::make_shared(id, label, value, GetSettingsManager()); if (setting == NULL) return NULL; setting->SetControl(GetButtonControl("date", delayed, heading)); setting->SetAllowEmpty(allowEmpty); setSettingDetails(setting, level, visible, help); group->AddSetting(setting); return setting; } std::shared_ptr CGUIDialogSettingsManualBase::AddTime(const SettingGroupPtr& group, const std::string& id, int label, SettingLevel level, const std::string& value, bool allowEmpty /* = false */, int heading /* = -1 */, bool delayed /* = false */, bool visible /* = true */, int help /* = -1 */) { if (group == NULL || id.empty() || label < 0 || GetSetting(id) != NULL) return NULL; std::shared_ptr setting = std::make_shared(id, label, value, GetSettingsManager()); if (setting == NULL) return NULL; setting->SetControl(GetButtonControl("time", delayed, heading)); setting->SetAllowEmpty(allowEmpty); setSettingDetails(setting, level, visible, help); group->AddSetting(setting); return setting; } std::shared_ptr CGUIDialogSettingsManualBase::AddSpinner( const SettingGroupPtr& group, const std::string& id, int label, SettingLevel level, const std::string& value, StringSettingOptionsFiller filler, bool delayed /* = false */, bool visible /* = true */, int help /* = -1 */) { if (group == NULL || id.empty() || label < 0 || filler == NULL || GetSetting(id) != NULL) return NULL; std::shared_ptr setting = std::make_shared(id, label, value, GetSettingsManager()); if (setting == NULL) return NULL; setting->SetControl(GetSpinnerControl("string", delayed)); setting->SetOptionsFiller(filler, this); setSettingDetails(setting, level, visible, help); group->AddSetting(setting); return setting; } std::shared_ptr CGUIDialogSettingsManualBase::AddSpinner(const SettingGroupPtr& group, const std::string& id, int label, SettingLevel level, int value, int minimum, int step, int maximum, int formatLabel /* = -1 */, int minimumLabel /* = -1 */, bool delayed /* = false */, bool visible /* = true */, int help /* = -1 */) { if (group == NULL || id.empty() || label < 0 || GetSetting(id) != NULL) return NULL; std::shared_ptr setting = std::make_shared(id, label, value, GetSettingsManager()); if (setting == NULL) return NULL; setting->SetControl(GetSpinnerControl("string", delayed, minimumLabel, formatLabel)); setting->SetMinimum(minimum); setting->SetStep(step); setting->SetMaximum(maximum); setSettingDetails(setting, level, visible, help); group->AddSetting(setting); return setting; } std::shared_ptr CGUIDialogSettingsManualBase::AddSpinner( const SettingGroupPtr& group, const std::string& id, int label, SettingLevel level, int value, int minimum, int step, int maximum, const std::string& formatString, int minimumLabel /* = -1 */, bool delayed /* = false */, bool visible /* = true */, int help /* = -1 */) { if (group == NULL || id.empty() || label < 0 || GetSetting(id) != NULL) return NULL; std::shared_ptr setting = std::make_shared(id, label, value, GetSettingsManager()); if (setting == NULL) return NULL; setting->SetControl(GetSpinnerControl("string", delayed, minimumLabel, -1, formatString)); setting->SetMinimum(minimum); setting->SetStep(step); setting->SetMaximum(maximum); setSettingDetails(setting, level, visible, help); group->AddSetting(setting); return setting; } std::shared_ptr CGUIDialogSettingsManualBase::AddSpinner( const SettingGroupPtr& group, const std::string& id, int label, SettingLevel level, int value, const TranslatableIntegerSettingOptions& entries, bool delayed /* = false */, bool visible /* = true */, int help /* = -1 */) { if (group == NULL || id.empty() || label < 0 || entries.empty() || GetSetting(id) != NULL) return NULL; std::shared_ptr setting = std::make_shared(id, label, value, GetSettingsManager()); if (setting == NULL) return NULL; setting->SetControl(GetSpinnerControl("string", delayed)); setting->SetTranslatableOptions(entries); setSettingDetails(setting, level, visible, help); group->AddSetting(setting); return setting; } std::shared_ptr CGUIDialogSettingsManualBase::AddSpinner( const SettingGroupPtr& group, const std::string& id, int label, SettingLevel level, int value, const IntegerSettingOptions& entries, bool delayed /* = false */, bool visible /* = true */, int help /* = -1 */) { if (group == NULL || id.empty() || label < 0 || entries.empty() || GetSetting(id) != NULL) return NULL; std::shared_ptr setting = std::make_shared(id, label, value, GetSettingsManager()); if (setting == NULL) return NULL; setting->SetControl(GetSpinnerControl("string", delayed)); setting->SetOptions(entries); setSettingDetails(setting, level, visible, help); group->AddSetting(setting); return setting; } std::shared_ptr CGUIDialogSettingsManualBase::AddSpinner( const SettingGroupPtr& group, const std::string& id, int label, SettingLevel level, int value, IntegerSettingOptionsFiller filler, bool delayed /* = false */, bool visible /* = true */, int help /* = -1 */) { if (group == NULL || id.empty() || label < 0 || filler == NULL || GetSetting(id) != NULL) return NULL; std::shared_ptr setting = std::make_shared(id, label, value, GetSettingsManager()); if (setting == NULL) return NULL; setting->SetControl(GetSpinnerControl("string", delayed)); setting->SetOptionsFiller(filler, this); setSettingDetails(setting, level, visible, help); group->AddSetting(setting); return setting; } std::shared_ptr CGUIDialogSettingsManualBase::AddSpinner( const SettingGroupPtr& group, const std::string& id, int label, SettingLevel level, float value, float minimum, float step, float maximum, int formatLabel /* = -1 */, int minimumLabel /* = -1 */, bool delayed /* = false */, bool visible /* = true */, int help /* = -1 */) { if (group == NULL || id.empty() || label < 0 || GetSetting(id) != NULL) return NULL; std::shared_ptr setting = std::make_shared(id, label, value, GetSettingsManager()); if (setting == NULL) return NULL; setting->SetControl(GetSpinnerControl("number", delayed, minimumLabel, formatLabel)); setting->SetMinimum(static_cast(minimum)); setting->SetStep(static_cast(step)); setting->SetMaximum(static_cast(maximum)); setSettingDetails(setting, level, visible, help); group->AddSetting(setting); return setting; } std::shared_ptr CGUIDialogSettingsManualBase::AddSpinner( const SettingGroupPtr& group, const std::string& id, int label, SettingLevel level, float value, float minimum, float step, float maximum, const std::string& formatString, int minimumLabel /* = -1 */, bool delayed /* = false */, bool visible /* = true */, int help /* = -1 */) { if (group == NULL || id.empty() || label < 0 || GetSetting(id) != NULL) return NULL; std::shared_ptr setting = std::make_shared(id, label, value, GetSettingsManager()); if (setting == NULL) return NULL; setting->SetControl(GetSpinnerControl("number", delayed, minimumLabel, -1, formatString)); setting->SetMinimum(static_cast(minimum)); setting->SetStep(static_cast(step)); setting->SetMaximum(static_cast(maximum)); setSettingDetails(setting, level, visible, help); group->AddSetting(setting); return setting; } std::shared_ptr CGUIDialogSettingsManualBase::AddList( const SettingGroupPtr& group, const std::string& id, int label, SettingLevel level, const std::string& value, StringSettingOptionsFiller filler, int heading, bool visible /* = true */, int help /* = -1 */, bool details /* = false */) { if (group == NULL || id.empty() || label < 0 || filler == NULL || GetSetting(id) != NULL) return NULL; std::shared_ptr setting = std::make_shared(id, label, value, GetSettingsManager()); if (setting == NULL) return NULL; setting->SetControl(GetListControl("string", false, heading, false, nullptr, details)); setting->SetOptionsFiller(filler, this); setSettingDetails(setting, level, visible, help); group->AddSetting(setting); return setting; } std::shared_ptr CGUIDialogSettingsManualBase::AddList( const SettingGroupPtr& group, const std::string& id, int label, SettingLevel level, int value, const TranslatableIntegerSettingOptions& entries, int heading, bool visible /* = true */, int help /* = -1 */, bool details /* = false */) { if (group == NULL || id.empty() || label < 0 || entries.empty() || GetSetting(id) != NULL) return NULL; std::shared_ptr setting = std::make_shared(id, label, value, GetSettingsManager()); if (setting == NULL) return NULL; setting->SetControl(GetListControl("integer", false, heading, false, nullptr, details)); setting->SetTranslatableOptions(entries); setSettingDetails(setting, level, visible, help); group->AddSetting(setting); return setting; } std::shared_ptr CGUIDialogSettingsManualBase::AddList( const SettingGroupPtr& group, const std::string& id, int label, SettingLevel level, int value, const IntegerSettingOptions& entries, int heading, bool visible /* = true */, int help /* = -1 */, bool details /* = false */) { if (group == NULL || id.empty() || label < 0 || entries.empty() || GetSetting(id) != NULL) return NULL; std::shared_ptr setting = std::make_shared(id, label, value, GetSettingsManager()); if (setting == NULL) return NULL; setting->SetControl(GetListControl("integer", false, heading, false, nullptr, details)); setting->SetOptions(entries); setSettingDetails(setting, level, visible, help); group->AddSetting(setting); return setting; } std::shared_ptr CGUIDialogSettingsManualBase::AddList( const SettingGroupPtr& group, const std::string& id, int label, SettingLevel level, int value, IntegerSettingOptionsFiller filler, int heading, bool visible /* = true */, int help /* = -1 */, bool details /* = false */) { if (group == NULL || id.empty() || label < 0 || filler == NULL || GetSetting(id) != NULL) return NULL; std::shared_ptr setting = std::make_shared(id, label, value, GetSettingsManager()); if (setting == NULL) return NULL; setting->SetControl(GetListControl("integer", false, heading, false, nullptr, details)); setting->SetOptionsFiller(filler, this); setSettingDetails(setting, level, visible, help); group->AddSetting(setting); return setting; } std::shared_ptr CGUIDialogSettingsManualBase::AddList( const SettingGroupPtr& group, const std::string& id, int label, SettingLevel level, std::vector values, StringSettingOptionsFiller filler, int heading, int minimumItems /* = 0 */, int maximumItems /* = -1 */, bool visible /* = true */, int help /* = -1 */, bool details /* = false */) { if (group == NULL || id.empty() || label < 0 || filler == NULL || GetSetting(id) != NULL) return NULL; std::shared_ptr settingDefinition = std::make_shared(id, GetSettingsManager()); if (settingDefinition == NULL) return NULL; settingDefinition->SetOptionsFiller(filler, this); std::shared_ptr setting = std::make_shared(id, settingDefinition, label, GetSettingsManager()); if (setting == NULL) return NULL; std::vector valueList; for (std::vector::const_iterator itValue = values.begin(); itValue != values.end(); ++itValue) valueList.emplace_back(*itValue); SettingList settingValues; if (!CSettingUtils::ValuesToList(setting, valueList, settingValues)) return NULL; // setting the default will also set the actual value on an unchanged setting setting->SetDefault(settingValues); setting->SetControl(GetListControl("string", false, heading, true, nullptr, details)); setting->SetMinimumItems(minimumItems); setting->SetMaximumItems(maximumItems); setSettingDetails(setting, level, visible, help); group->AddSetting(setting); return setting; } std::shared_ptr CGUIDialogSettingsManualBase::AddList( const SettingGroupPtr& group, const std::string& id, int label, SettingLevel level, std::vector values, const TranslatableIntegerSettingOptions& entries, int heading, int minimumItems /* = 0 */, int maximumItems /* = -1 */, bool visible /* = true */, int help /* = -1 */, bool details /* = false */) { if (group == NULL || id.empty() || label < 0 || entries.empty() || GetSetting(id) != NULL) return NULL; std::shared_ptr settingDefinition = std::make_shared(id, GetSettingsManager()); if (settingDefinition == NULL) return NULL; settingDefinition->SetTranslatableOptions(entries); std::shared_ptr setting = std::make_shared(id, settingDefinition, label, GetSettingsManager()); if (setting == NULL) return NULL; std::vector valueList; for (std::vector::const_iterator itValue = values.begin(); itValue != values.end(); ++itValue) valueList.emplace_back(*itValue); SettingList settingValues; if (!CSettingUtils::ValuesToList(setting, valueList, settingValues)) return NULL; // setting the default will also set the actual value on an unchanged setting setting->SetDefault(settingValues); setting->SetControl(GetListControl("integer", false, heading, true, nullptr, details)); setting->SetMinimumItems(minimumItems); setting->SetMaximumItems(maximumItems); setSettingDetails(setting, level, visible, help); group->AddSetting(setting); return setting; } std::shared_ptr CGUIDialogSettingsManualBase::AddList( const SettingGroupPtr& group, const std::string& id, int label, SettingLevel level, std::vector values, const IntegerSettingOptions& entries, int heading, int minimumItems /* = 0 */, int maximumItems /* = -1 */, bool visible /* = true */, int help /* = -1 */, bool details /* = false */) { if (group == NULL || id.empty() || label < 0 || entries.empty() || GetSetting(id) != NULL) return NULL; std::shared_ptr settingDefinition = std::make_shared(id, GetSettingsManager()); if (settingDefinition == NULL) return NULL; settingDefinition->SetOptions(entries); std::shared_ptr setting = std::make_shared(id, settingDefinition, label, GetSettingsManager()); if (setting == NULL) return NULL; std::vector valueList; for (std::vector::const_iterator itValue = values.begin(); itValue != values.end(); ++itValue) valueList.emplace_back(*itValue); SettingList settingValues; if (!CSettingUtils::ValuesToList(setting, valueList, settingValues)) return NULL; // setting the default will also set the actual value on an unchanged setting setting->SetDefault(settingValues); setting->SetControl(GetListControl("integer", false, heading, true, nullptr, details)); setting->SetMinimumItems(minimumItems); setting->SetMaximumItems(maximumItems); setSettingDetails(setting, level, visible, help); group->AddSetting(setting); return setting; } std::shared_ptr CGUIDialogSettingsManualBase::AddList( const SettingGroupPtr& group, const std::string& id, int label, SettingLevel level, std::vector values, IntegerSettingOptionsFiller filler, int heading, int minimumItems /* = 0 */, int maximumItems /* = -1 */, bool visible /* = true */, int help /* = -1 */, SettingControlListValueFormatter formatter /* = NULL */, bool details /* = false */) { if (group == NULL || id.empty() || label < 0 || filler == NULL || GetSetting(id) != NULL) return NULL; std::shared_ptr settingDefinition = std::make_shared(id, GetSettingsManager()); if (settingDefinition == NULL) return NULL; settingDefinition->SetOptionsFiller(filler, this); std::shared_ptr setting = std::make_shared(id, settingDefinition, label, GetSettingsManager()); if (setting == NULL) return NULL; std::vector valueList; for (std::vector::const_iterator itValue = values.begin(); itValue != values.end(); ++itValue) valueList.emplace_back(*itValue); SettingList settingValues; if (!CSettingUtils::ValuesToList(setting, valueList, settingValues)) return NULL; // setting the default will also set the actual value on an unchanged setting setting->SetDefault(settingValues); setting->SetControl(GetListControl("integer", false, heading, true, formatter, details)); setting->SetMinimumItems(minimumItems); setting->SetMaximumItems(maximumItems); setSettingDetails(setting, level, visible, help); group->AddSetting(setting); return setting; } std::shared_ptr CGUIDialogSettingsManualBase::AddPercentageSlider( const SettingGroupPtr& group, const std::string& id, int label, SettingLevel level, int value, int formatLabel, int step /* = 1 */, int heading /* = -1 */, bool usePopup /* = false */, bool delayed /* = false */, bool visible /* = true */, int help /* = -1 */) { if (group == NULL || id.empty() || label < 0 || GetSetting(id) != NULL) return NULL; std::shared_ptr setting = std::make_shared(id, label, value, GetSettingsManager()); if (setting == NULL) return NULL; setting->SetControl(GetSliderControl("percentage", delayed, heading, usePopup, formatLabel)); setting->SetMinimum(0); setting->SetStep(step); setting->SetMaximum(100); setSettingDetails(setting, level, visible, help); group->AddSetting(setting); return setting; } std::shared_ptr CGUIDialogSettingsManualBase::AddPercentageSlider( const SettingGroupPtr& group, const std::string& id, int label, SettingLevel level, int value, const std::string& formatString, int step /* = 1 */, int heading /* = -1 */, bool usePopup /* = false */, bool delayed /* = false */, bool visible /* = true */, int help /* = -1 */) { if (group == NULL || id.empty() || label < 0 || GetSetting(id) != NULL) return NULL; std::shared_ptr setting = std::make_shared(id, label, value, GetSettingsManager()); if (setting == NULL) return NULL; setting->SetControl(GetSliderControl("percentage", delayed, heading, usePopup, -1, formatString)); setting->SetMinimum(0); setting->SetStep(step); setting->SetMaximum(100); setSettingDetails(setting, level, visible, help); group->AddSetting(setting); return setting; } std::shared_ptr CGUIDialogSettingsManualBase::AddSlider(const SettingGroupPtr& group, const std::string& id, int label, SettingLevel level, int value, int formatLabel, int minimum, int step, int maximum, int heading /* = -1 */, bool usePopup /* = false */, bool delayed /* = false */, bool visible /* = true */, int help /* = -1 */) { if (group == NULL || id.empty() || label < 0 || GetSetting(id) != NULL) return NULL; std::shared_ptr setting = std::make_shared(id, label, value, GetSettingsManager()); if (setting == NULL) return NULL; setting->SetControl(GetSliderControl("integer", delayed, heading, usePopup, formatLabel)); setting->SetMinimum(minimum); setting->SetStep(step); setting->SetMaximum(maximum); setSettingDetails(setting, level, visible, help); group->AddSetting(setting); return setting; } std::shared_ptr CGUIDialogSettingsManualBase::AddSlider( const SettingGroupPtr& group, const std::string& id, int label, SettingLevel level, int value, const std::string& formatString, int minimum, int step, int maximum, int heading /* = -1 */, bool usePopup /* = false */, bool delayed /* = false */, bool visible /* = true */, int help /* = -1 */) { if (group == NULL || id.empty() || label < 0 || GetSetting(id) != NULL) return NULL; std::shared_ptr setting = std::make_shared(id, label, value, GetSettingsManager()); if (setting == NULL) return NULL; setting->SetControl(GetSliderControl("integer", delayed, heading, usePopup, -1, formatString)); setting->SetMinimum(minimum); setting->SetStep(step); setting->SetMaximum(maximum); setSettingDetails(setting, level, visible, help); group->AddSetting(setting); return setting; } std::shared_ptr CGUIDialogSettingsManualBase::AddSlider( const SettingGroupPtr& group, const std::string& id, int label, SettingLevel level, float value, int formatLabel, float minimum, float step, float maximum, int heading /* = -1 */, bool usePopup /* = false */, bool delayed /* = false */, bool visible /* = true */, int help /* = -1 */) { if (group == NULL || id.empty() || label < 0 || GetSetting(id) != NULL) return NULL; std::shared_ptr setting = std::make_shared(id, label, value, GetSettingsManager()); if (setting == NULL) return NULL; setting->SetControl(GetSliderControl("number", delayed, heading, usePopup, formatLabel)); setting->SetMinimum(static_cast(minimum)); setting->SetStep(static_cast(step)); setting->SetMaximum(static_cast(maximum)); setSettingDetails(setting, level, visible, help); group->AddSetting(setting); return setting; } std::shared_ptr CGUIDialogSettingsManualBase::AddSlider( const SettingGroupPtr& group, const std::string& id, int label, SettingLevel level, float value, const std::string& formatString, float minimum, float step, float maximum, int heading /* = -1 */, bool usePopup /* = false */, bool delayed /* = false */, bool visible /* = true */, int help /* = -1 */) { if (group == NULL || id.empty() || label < 0 || GetSetting(id) != NULL) return NULL; std::shared_ptr setting = std::make_shared(id, label, value, GetSettingsManager()); if (setting == NULL) return NULL; setting->SetControl(GetSliderControl("number", delayed, heading, usePopup, -1, formatString)); setting->SetMinimum(static_cast(minimum)); setting->SetStep(static_cast(step)); setting->SetMaximum(static_cast(maximum)); setSettingDetails(setting, level, visible, help); group->AddSetting(setting); return setting; } std::shared_ptr CGUIDialogSettingsManualBase::AddPercentageRange( const SettingGroupPtr& group, const std::string& id, int label, SettingLevel level, int valueLower, int valueUpper, int valueFormatLabel, int step /* = 1 */, int formatLabel /* = 21469 */, bool delayed /* = false */, bool visible /* = true */, int help /* = -1 */) { return AddRange(group, id, label, level, valueLower, valueUpper, 0, step, 100, "percentage", formatLabel, valueFormatLabel, "", delayed, visible, help); } std::shared_ptr CGUIDialogSettingsManualBase::AddPercentageRange( const SettingGroupPtr& group, const std::string& id, int label, SettingLevel level, int valueLower, int valueUpper, const std::string& valueFormatString /* = "{:d} %" */, int step /* = 1 */, int formatLabel /* = 21469 */, bool delayed /* = false */, bool visible /* = true */, int help /* = -1 */) { return AddRange(group, id, label, level, valueLower, valueUpper, 0, step, 100, "percentage", formatLabel, -1, valueFormatString, delayed, visible, help); } std::shared_ptr CGUIDialogSettingsManualBase::AddRange(const SettingGroupPtr& group, const std::string& id, int label, SettingLevel level, int valueLower, int valueUpper, int minimum, int step, int maximum, int valueFormatLabel, int formatLabel /* = 21469 */, bool delayed /* = false */, bool visible /* = true */, int help /* = -1 */) { return AddRange(group, id, label, level, valueLower, valueUpper, minimum, step, maximum, "integer", formatLabel, valueFormatLabel, "", delayed, visible, help); } std::shared_ptr CGUIDialogSettingsManualBase::AddRange( const SettingGroupPtr& group, const std::string& id, int label, SettingLevel level, int valueLower, int valueUpper, int minimum, int step, int maximum, const std::string& valueFormatString /* = "{:d}" */, int formatLabel /* = 21469 */, bool delayed /* = false */, bool visible /* = true */, int help /* = -1 */) { return AddRange(group, id, label, level, valueLower, valueUpper, minimum, step, maximum, "integer", formatLabel, -1, valueFormatString, delayed, visible, help); } std::shared_ptr CGUIDialogSettingsManualBase::AddRange(const SettingGroupPtr& group, const std::string& id, int label, SettingLevel level, float valueLower, float valueUpper, float minimum, float step, float maximum, int valueFormatLabel, int formatLabel /* = 21469 */, bool delayed /* = false */, bool visible /* = true */, int help /* = -1 */) { return AddRange(group, id, label, level, valueLower, valueUpper, minimum, step, maximum, "number", formatLabel, valueFormatLabel, "", delayed, visible, help); } std::shared_ptr CGUIDialogSettingsManualBase::AddRange( const SettingGroupPtr& group, const std::string& id, int label, SettingLevel level, float valueLower, float valueUpper, float minimum, float step, float maximum, const std::string& valueFormatString /* = "{:.1f}" */, int formatLabel /* = 21469 */, bool delayed /* = false */, bool visible /* = true */, int help /* = -1 */) { return AddRange(group, id, label, level, valueLower, valueUpper, minimum, step, maximum, "number", formatLabel, -1, valueFormatString, delayed, visible, help); } std::shared_ptr CGUIDialogSettingsManualBase::AddDateRange( const SettingGroupPtr& group, const std::string& id, int label, SettingLevel level, int valueLower, int valueUpper, int minimum, int step, int maximum, int valueFormatLabel, int formatLabel /* = 21469 */, bool delayed /* = false */, bool visible /* = true */, int help /* = -1 */) { return AddRange(group, id, label, level, valueLower, valueUpper, minimum, step, maximum, "date", formatLabel, valueFormatLabel, "", delayed, visible, help); } std::shared_ptr CGUIDialogSettingsManualBase::AddDateRange( const SettingGroupPtr& group, const std::string& id, int label, SettingLevel level, int valueLower, int valueUpper, int minimum, int step, int maximum, const std::string& valueFormatString /* = "" */, int formatLabel /* = 21469 */, bool delayed /* = false */, bool visible /* = true */, int help /* = -1 */) { return AddRange(group, id, label, level, valueLower, valueUpper, minimum, step, maximum, "date", formatLabel, -1, valueFormatString, delayed, visible, help); } std::shared_ptr CGUIDialogSettingsManualBase::AddTimeRange( const SettingGroupPtr& group, const std::string& id, int label, SettingLevel level, int valueLower, int valueUpper, int minimum, int step, int maximum, int valueFormatLabel, int formatLabel /* = 21469 */, bool delayed /* = false */, bool visible /* = true */, int help /* = -1 */) { return AddRange(group, id, label, level, valueLower, valueUpper, minimum, step, maximum, "time", formatLabel, valueFormatLabel, "", delayed, visible, help); } std::shared_ptr CGUIDialogSettingsManualBase::AddTimeRange( const SettingGroupPtr& group, const std::string& id, int label, SettingLevel level, int valueLower, int valueUpper, int minimum, int step, int maximum, const std::string& valueFormatString /* = "mm:ss" */, int formatLabel /* = 21469 */, bool delayed /* = false */, bool visible /* = true */, int help /* = -1 */) { return AddRange(group, id, label, level, valueLower, valueUpper, minimum, step, maximum, "time", formatLabel, -1, valueFormatString, delayed, visible, help); } std::shared_ptr CGUIDialogSettingsManualBase::AddRange( const SettingGroupPtr& group, const std::string& id, int label, SettingLevel level, int valueLower, int valueUpper, int minimum, int step, int maximum, const std::string& format, int formatLabel, int valueFormatLabel, const std::string& valueFormatString, bool delayed, bool visible, int help) { if (group == NULL || id.empty() || label < 0 || GetSetting(id) != NULL) return NULL; std::shared_ptr settingDefinition = std::make_shared(id, GetSettingsManager()); if (settingDefinition == NULL) return NULL; settingDefinition->SetMinimum(minimum); settingDefinition->SetStep(step); settingDefinition->SetMaximum(maximum); std::shared_ptr setting = std::make_shared(id, settingDefinition, label, GetSettingsManager()); if (setting == NULL) return NULL; std::vector valueList; valueList.emplace_back(valueLower); valueList.emplace_back(valueUpper); SettingList settingValues; if (!CSettingUtils::ValuesToList(setting, valueList, settingValues)) return NULL; // setting the default will also set the actual value on an unchanged setting setting->SetDefault(settingValues); setting->SetControl(GetRangeControl(format, delayed, formatLabel, valueFormatLabel, valueFormatString)); setting->SetMinimumItems(2); setting->SetMaximumItems(2); setSettingDetails(setting, level, visible, help); group->AddSetting(setting); return setting; } std::shared_ptr CGUIDialogSettingsManualBase::AddRange( const SettingGroupPtr& group, const std::string& id, int label, SettingLevel level, float valueLower, float valueUpper, float minimum, float step, float maximum, const std::string& format, int formatLabel, int valueFormatLabel, const std::string& valueFormatString, bool delayed, bool visible, int help) { if (group == NULL || id.empty() || label < 0 || GetSetting(id) != NULL) return NULL; std::shared_ptr settingDefinition = std::make_shared(id, GetSettingsManager()); if (settingDefinition == NULL) return NULL; settingDefinition->SetMinimum(static_cast(minimum)); settingDefinition->SetStep(static_cast(step)); settingDefinition->SetMaximum(static_cast(maximum)); std::shared_ptr setting = std::make_shared(id, settingDefinition, label, GetSettingsManager()); if (setting == NULL) return NULL; std::vector valueList; valueList.emplace_back(valueLower); valueList.emplace_back(valueUpper); SettingList settingValues; if (!CSettingUtils::ValuesToList(setting, valueList, settingValues)) return NULL; // setting the default will also set the actual value on an unchanged setting setting->SetDefault(settingValues); setting->SetControl(GetRangeControl(format, delayed, formatLabel, valueFormatLabel, valueFormatString)); setting->SetMinimumItems(2); setting->SetMaximumItems(2); setSettingDetails(setting, level, visible, help); group->AddSetting(setting); return setting; } void CGUIDialogSettingsManualBase::setSettingDetails(const std::shared_ptr& setting, SettingLevel level, bool visible, int help) { if (setting == NULL) return; if (level < SettingLevel::Basic) level = SettingLevel::Basic; else if (level > SettingLevel::Expert) level = SettingLevel::Expert; setting->SetLevel(level); setting->SetVisible(visible); if (help >= 0) setting->SetHelp(help); } std::shared_ptr CGUIDialogSettingsManualBase::GetCheckmarkControl(bool delayed /* = false */) { std::shared_ptr control = std::make_shared(); control->SetDelayed(delayed); return control; } std::shared_ptr CGUIDialogSettingsManualBase::GetTitleControl(bool separatorBelowLabel /* = true */, bool hideSeparator /* = false */) { std::shared_ptr control = std::make_shared(); control->SetSeparatorBelowLabel(separatorBelowLabel); control->SetSeparatorHidden(hideSeparator); return control; } std::shared_ptr CGUIDialogSettingsManualBase::GetEditControl(const std::string &format, bool delayed /* = false */, bool hidden /* = false */, bool verifyNewValue /* = false */, int heading /* = -1 */) { std::shared_ptr control = std::make_shared(); if (!control->SetFormat(format)) return NULL; control->SetDelayed(delayed); control->SetHidden(hidden); control->SetVerifyNewValue(verifyNewValue); control->SetHeading(heading); return control; } std::shared_ptr CGUIDialogSettingsManualBase::GetButtonControl(const std::string &format, bool delayed /* = false */, int heading /* = -1 */, bool hideValue /* = false */, bool showInstalledAddons /* = true */, bool showInstallableAddons /* = false */, bool showMoreAddons /* = true */) { std::shared_ptr control = std::make_shared(); if (!control->SetFormat(format)) return NULL; control->SetDelayed(delayed); control->SetHeading(heading); control->SetHideValue(hideValue); control->SetShowInstalledAddons(showInstalledAddons); control->SetShowInstallableAddons(showInstallableAddons); control->SetShowMoreAddons(showMoreAddons); return control; } std::shared_ptr CGUIDialogSettingsManualBase::GetSpinnerControl(const std::string &format, bool delayed /* = false */, int minimumLabel /* = -1 */, int formatLabel /* = -1 */, const std::string &formatString /* = "" */) { std::shared_ptr control = std::make_shared(); if (!control->SetFormat(format)) return NULL; control->SetDelayed(delayed); if (formatLabel >= 0) control->SetFormatLabel(formatLabel); if (!formatString.empty()) control->SetFormatString(formatString); if (minimumLabel >= 0) control->SetMinimumLabel(minimumLabel); return control; } std::shared_ptr CGUIDialogSettingsManualBase::GetListControl( const std::string& format, bool delayed /* = false */, int heading /* = -1 */, bool multiselect /* = false */, SettingControlListValueFormatter formatter /* = NULL */, bool details /* = false */) { std::shared_ptr control = std::make_shared(); if (!control->SetFormat(format)) return NULL; control->SetDelayed(delayed); control->SetHeading(heading); control->SetMultiSelect(multiselect); control->SetFormatter(formatter); control->SetUseDetails(details); return control; } std::shared_ptr CGUIDialogSettingsManualBase::GetSliderControl(const std::string &format, bool delayed /* = false */, int heading /* = -1 */, bool usePopup /* = false */, int formatLabel /* = -1 */, const std::string &formatString /* = "" */) { std::shared_ptr control = std::make_shared(); if (!control->SetFormat(format)) return NULL; control->SetDelayed(delayed); if (heading >= 0) control->SetHeading(heading); control->SetPopup(usePopup); if (formatLabel >= 0) control->SetFormatLabel(formatLabel); if (!formatString.empty()) control->SetFormatString(formatString); return control; } std::shared_ptr CGUIDialogSettingsManualBase::GetRangeControl(const std::string &format, bool delayed /* = false */, int formatLabel /* = -1 */, int valueFormatLabel /* = -1 */, const std::string &valueFormatString /* = "" */) { std::shared_ptr control = std::make_shared(); if (!control->SetFormat(format)) return NULL; control->SetDelayed(delayed); if (formatLabel >= 0) control->SetFormatLabel(formatLabel); if (valueFormatLabel >= 0) control->SetValueFormatLabel(valueFormatLabel); if (!valueFormatString.empty()) control->SetValueFormat(valueFormatString); return control; }