bcf6dd38d656a8a2bae2b6cd68e43248cae64716
[vuplus_xbmc] / xbmc / settings / SettingAddon.cpp
1 /*
2  *      Copyright (C) 2013 Team XBMC
3  *      http://www.xbmc.org
4  *
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)
8  *  any later version.
9  *
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.
14  *
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/>.
18  *
19  */
20
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"
28
29 #define XML_ELM_DEFAULT     "default"
30
31 CSettingAddon::CSettingAddon(const std::string &id, CSettingsManager *settingsManager /* = NULL */)
32   : CSettingString(id, settingsManager),
33     m_addonType(ADDON::ADDON_UNKNOWN)
34 {
35   m_control.SetType(SettingControlTypeButton);
36   m_control.SetFormat(SettingControlFormatAddon);
37   m_control.SetAttributes(SettingControlAttributeNone);
38 }
39   
40 CSettingAddon::CSettingAddon(const std::string &id, const CSettingAddon &setting)
41   : CSettingString(id, setting)
42 {
43   copy(setting);
44 }
45
46 bool CSettingAddon::Deserialize(const TiXmlNode *node, bool update /* = false */)
47 {
48   CSingleLock lock(m_critical);
49
50   if (!CSettingString::Deserialize(node, update))
51     return false;
52     
53   if (m_control.GetType() != SettingControlTypeButton ||
54       m_control.GetFormat() != SettingControlFormatAddon ||
55       m_control.GetAttributes() != SettingControlAttributeNone)
56   {
57     CLog::Log(LOGERROR, "CSettingAddon: invalid <control> of \"%s\"", m_id.c_str());
58     return false;
59   }
60     
61   // get the default value by abusing the FromString
62   // implementation to parse the default value
63   CStdString value;
64   if (XMLUtils::GetString(node, XML_ELM_DEFAULT, value))
65     m_value = m_default = value;
66   else if (!update)
67   {
68     CLog::Log(LOGERROR, "CSettingAddon: error reading the default value of \"%s\"", m_id.c_str());
69     return false;
70   }
71     
72   // get the addon type
73   CStdString strAddonType;
74   bool ok = XMLUtils::GetString(node, "addontype", strAddonType);
75   if (ok)
76   {
77     m_addonType = ADDON::TranslateType(strAddonType);
78     if (m_addonType == ADDON::ADDON_UNKNOWN)
79       ok = false;
80   }
81
82   if (!ok && !update)
83   {
84     CLog::Log(LOGERROR, "CSettingAddon: error reading the addontype value \"%s\" of \"%s\"", strAddonType.c_str(), m_id.c_str());
85     return false;
86   }
87
88   return true;
89 }
90
91 void CSettingAddon::copy(const CSettingAddon &setting)
92 {
93   CSettingString::Copy(setting);
94
95   m_addonType = setting.m_addonType;
96 }