JSONRPC_STATUS CSettingsOperations::GetSections(const std::string &method, ITransportLayer *transport, IClient *client, const CVariant ¶meterObject, CVariant &result) { SettingLevel level = (SettingLevel)ParseSettingLevel(parameterObject["level"].asString()); bool listCategories = !parameterObject["properties"].empty() && parameterObject["properties"][0].asString() == "categories"; vector<CSettingSection*> sections; result["sections"] = CVariant(CVariant::VariantTypeArray); // apply the level filter vector<CSettingSection*> allSections = CSettings::Get().GetSections(); for (vector<CSettingSection*>::const_iterator itSection = allSections.begin(); itSection != allSections.end(); ++itSection) { SettingCategoryList categories = (*itSection)->GetCategories(level); if (categories.empty()) continue; CVariant varSection(CVariant::VariantTypeObject); if (!SerializeSettingSection(*itSection, varSection)) continue; if (listCategories) { varSection["categories"] = CVariant(CVariant::VariantTypeArray); for (SettingCategoryList::const_iterator itCategory = categories.begin(); itCategory != categories.end(); ++itCategory) { CVariant varCategory(CVariant::VariantTypeObject); if (!SerializeSettingCategory(*itCategory, varCategory)) continue; varSection["categories"].push_back(varCategory); } } result["sections"].push_back(varSection); } return OK; }
JSONRPC_STATUS CSettingsOperations::GetCategories(const std::string &method, ITransportLayer *transport, IClient *client, const CVariant ¶meterObject, CVariant &result) { SettingLevel level = (SettingLevel)ParseSettingLevel(parameterObject["level"].asString()); std::string strSection = parameterObject["section"].asString(); bool listSettings = !parameterObject["properties"].empty() && parameterObject["properties"][0].asString() == "settings"; std::vector<SettingSectionPtr> sections; if (!strSection.empty()) { SettingSectionPtr section = CServiceBroker::GetSettings().GetSection(strSection); if (section == NULL) return InvalidParams; sections.push_back(section); } else sections = CServiceBroker::GetSettings().GetSections(); result["categories"] = CVariant(CVariant::VariantTypeArray); for (std::vector<SettingSectionPtr>::const_iterator itSection = sections.begin(); itSection != sections.end(); ++itSection) { SettingCategoryList categories = (*itSection)->GetCategories(level); for (SettingCategoryList::const_iterator itCategory = categories.begin(); itCategory != categories.end(); ++itCategory) { CVariant varCategory(CVariant::VariantTypeObject); if (!SerializeSettingCategory(*itCategory, varCategory)) continue; if (listSettings) { varCategory["groups"] = CVariant(CVariant::VariantTypeArray); SettingGroupList groups = (*itCategory)->GetGroups(level); for (SettingGroupList::const_iterator itGroup = groups.begin(); itGroup != groups.end(); ++itGroup) { CVariant varGroup(CVariant::VariantTypeObject); if (!SerializeSettingGroup(*itGroup, varGroup)) continue; varGroup["settings"] = CVariant(CVariant::VariantTypeArray); SettingList settings = (*itGroup)->GetSettings(level); for (SettingList::const_iterator itSetting = settings.begin(); itSetting != settings.end(); ++itSetting) { if ((*itSetting)->IsVisible()) { CVariant varSetting(CVariant::VariantTypeObject); if (!SerializeSetting(*itSetting, varSetting)) continue; varGroup["settings"].push_back(varSetting); } } varCategory["groups"].push_back(varGroup); } } result["categories"].push_back(varCategory); } } return OK; }
JSONRPC_STATUS CSettingsOperations::GetSettings(const std::string &method, ITransportLayer *transport, IClient *client, const CVariant ¶meterObject, CVariant &result) { SettingLevel level = (SettingLevel)ParseSettingLevel(parameterObject["level"].asString()); const CVariant &filter = parameterObject["filter"]; bool doFilter = filter.isMember("section") && filter.isMember("category"); std::string strSection, strCategory; if (doFilter) { strSection = filter["section"].asString(); strCategory = filter["category"].asString(); } std::vector<SettingSectionPtr> sections; if (doFilter) { SettingSectionPtr section = CServiceBroker::GetSettings().GetSection(strSection); if (section == NULL) return InvalidParams; sections.push_back(section); } else sections = CServiceBroker::GetSettings().GetSections(); result["settings"] = CVariant(CVariant::VariantTypeArray); for (std::vector<SettingSectionPtr>::const_iterator itSection = sections.begin(); itSection != sections.end(); ++itSection) { SettingCategoryList categories = (*itSection)->GetCategories(level); bool found = !doFilter; for (SettingCategoryList::const_iterator itCategory = categories.begin(); itCategory != categories.end(); ++itCategory) { if (!doFilter || StringUtils::EqualsNoCase((*itCategory)->GetId(), strCategory)) { SettingGroupList groups = (*itCategory)->GetGroups(level); for (SettingGroupList::const_iterator itGroup = groups.begin(); itGroup != groups.end(); ++itGroup) { SettingList settings = (*itGroup)->GetSettings(level); for (SettingList::const_iterator itSetting = settings.begin(); itSetting != settings.end(); ++itSetting) { if ((*itSetting)->IsVisible()) { CVariant varSetting(CVariant::VariantTypeObject); if (!SerializeSetting(*itSetting, varSetting)) continue; result["settings"].push_back(varSetting); } } } found = true; if (doFilter) break; } } if (doFilter && !found) return InvalidParams; } return OK; }
void CSettingSection::AddCategories(const SettingCategoryList &categories) { for (SettingCategoryList::const_iterator itCategory = categories.begin(); itCategory != categories.end(); ++itCategory) addISetting(NULL, *itCategory, m_categories); }