2 * Copyright (C) 2013 Team XBMC
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with XBMC; see the file COPYING. If not, see
17 * <http://www.gnu.org/licenses/>.
21 #include "SettingAddon.h"
22 #include "addons/Addon.h"
23 #include "settings/SettingsManager.h"
24 #include "threads/SingleLock.h"
25 #include "utils/log.h"
26 #include "utils/XBMCTinyXML.h"
27 #include "utils/XMLUtils.h"
29 #define XML_ELM_DEFAULT "default"
31 CSettingAddon::CSettingAddon(const std::string &id, CSettingsManager *settingsManager /* = NULL */)
32 : CSettingString(id, settingsManager),
33 m_addonType(ADDON::ADDON_UNKNOWN)
35 m_control.SetType(SettingControlTypeButton);
36 m_control.SetFormat(SettingControlFormatAddon);
37 m_control.SetAttributes(SettingControlAttributeNone);
40 CSettingAddon::CSettingAddon(const std::string &id, const CSettingAddon &setting)
41 : CSettingString(id, setting)
46 bool CSettingAddon::Deserialize(const TiXmlNode *node, bool update /* = false */)
48 CSingleLock lock(m_critical);
50 if (!CSettingString::Deserialize(node, update))
53 if (m_control.GetType() != SettingControlTypeButton ||
54 m_control.GetFormat() != SettingControlFormatAddon ||
55 m_control.GetAttributes() != SettingControlAttributeNone)
57 CLog::Log(LOGERROR, "CSettingAddon: invalid <control> of \"%s\"", m_id.c_str());
61 // get the default value by abusing the FromString
62 // implementation to parse the default value
64 if (XMLUtils::GetString(node, XML_ELM_DEFAULT, value))
65 m_value = m_default = value;
68 CLog::Log(LOGERROR, "CSettingAddon: error reading the default value of \"%s\"", m_id.c_str());
73 CStdString strAddonType;
74 bool ok = XMLUtils::GetString(node, "addontype", strAddonType);
77 m_addonType = ADDON::TranslateType(strAddonType);
78 if (m_addonType == ADDON::ADDON_UNKNOWN)
84 CLog::Log(LOGERROR, "CSettingAddon: error reading the addontype value \"%s\" of \"%s\"", strAddonType.c_str(), m_id.c_str());
91 void CSettingAddon::copy(const CSettingAddon &setting)
93 CSettingString::Copy(setting);
95 m_addonType = setting.m_addonType;