From c04dcc2e7d834218ef2d4194331e383402495ae1 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 10 Apr 2024 20:07:22 +0200 Subject: Adding upstream version 2:20.4+dfsg. Signed-off-by: Daniel Baumann --- xbmc/settings/SettingsValueXmlSerializer.cpp | 101 +++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 xbmc/settings/SettingsValueXmlSerializer.cpp (limited to 'xbmc/settings/SettingsValueXmlSerializer.cpp') diff --git a/xbmc/settings/SettingsValueXmlSerializer.cpp b/xbmc/settings/SettingsValueXmlSerializer.cpp new file mode 100644 index 0000000..42f83e3 --- /dev/null +++ b/xbmc/settings/SettingsValueXmlSerializer.cpp @@ -0,0 +1,101 @@ +/* + * Copyright (C) 2019 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 "SettingsValueXmlSerializer.h" + +#include "settings/lib/SettingDefinitions.h" +#include "settings/lib/SettingSection.h" +#include "settings/lib/SettingsManager.h" +#include "utils/XBMCTinyXML.h" +#include "utils/XMLUtils.h" +#include "utils/log.h" + +static constexpr char SETTINGS_XML_ROOT[] = "settings"; + +std::string CSettingsValueXmlSerializer::SerializeValues( + const CSettingsManager* settingsManager) const +{ + if (settingsManager == nullptr) + return ""; + + CXBMCTinyXML xmlDoc; + TiXmlElement rootElement(SETTINGS_XML_ROOT); + rootElement.SetAttribute(SETTING_XML_ROOT_VERSION, settingsManager->GetVersion()); + TiXmlNode* xmlRoot = xmlDoc.InsertEndChild(rootElement); + if (xmlRoot == nullptr) + return ""; + + const auto sections = settingsManager->GetSections(); + for (const auto& section : sections) + SerializeSection(xmlRoot, section); + + std::stringstream stream; + stream << *xmlDoc.RootElement(); + + return stream.str(); +} + +void CSettingsValueXmlSerializer::SerializeSection( + TiXmlNode* parent, const std::shared_ptr& section) const +{ + if (section == nullptr) + return; + + const auto categories = section->GetCategories(); + for (const auto& category : categories) + SerializeCategory(parent, category); +} + +void CSettingsValueXmlSerializer::SerializeCategory( + TiXmlNode* parent, const std::shared_ptr& category) const +{ + if (category == nullptr) + return; + + const auto groups = category->GetGroups(); + for (const auto& group : groups) + SerializeGroup(parent, group); +} + +void CSettingsValueXmlSerializer::SerializeGroup(TiXmlNode* parent, + const std::shared_ptr& group) const +{ + if (group == nullptr) + return; + + const auto settings = group->GetSettings(); + for (const auto& setting : settings) + SerializeSetting(parent, setting); +} + +void CSettingsValueXmlSerializer::SerializeSetting(TiXmlNode* parent, + const std::shared_ptr& setting) const +{ + if (setting == nullptr) + return; + + // ignore references and action settings (which don't have a value) + if (setting->IsReference() || setting->GetType() == SettingType::Action) + return; + + TiXmlElement settingElement(SETTING_XML_ELM_SETTING); + settingElement.SetAttribute(SETTING_XML_ATTR_ID, setting->GetId()); + + // add the default attribute + if (setting->IsDefault()) + settingElement.SetAttribute(SETTING_XML_ELM_DEFAULT, "true"); + + // add the value + TiXmlText value(setting->ToString()); + settingElement.InsertEndChild(value); + + if (parent->InsertEndChild(settingElement) == nullptr) + CLog::Log(LOGWARNING, + "CSettingsValueXmlSerializer: unable to write <" SETTING_XML_ELM_SETTING " id=\"{}\"> tag", + setting->GetId()); +} -- cgit v1.2.3