e77a51754a841449b1b6ca8d5c564d7cf8bc9dfb
[vuplus_xbmc] / xbmc / settings / SettingAddon.cpp
1 /*
2  *      Copyright (C) 2013 Team XBMC
3  *      http://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 "utils/log.h"
25 #include "utils/XBMCTinyXML.h"
26 #include "utils/XMLUtils.h"
27
28 #define XML_ELM_DEFAULT     "default"
29
30 CSettingAddon::CSettingAddon(const std::string &id, CSettingsManager *settingsManager /* = NULL */)
31   : CSettingString(id, settingsManager),
32     m_addonType(ADDON::ADDON_UNKNOWN)
33 { }
34   
35 CSettingAddon::CSettingAddon(const std::string &id, const CSettingAddon &setting)
36   : CSettingString(id, setting)
37 {
38   copy(setting);
39 }
40
41 bool CSettingAddon::Deserialize(const TiXmlNode *node, bool update /* = false */)
42 {
43   CExclusiveLock lock(m_critical);
44
45   if (!CSettingString::Deserialize(node, update))
46     return false;
47     
48   if (m_control != NULL &&
49      (m_control->GetType() != "button" || m_control->GetFormat() != "addon"))
50   {
51     CLog::Log(LOGERROR, "CSettingAddon: invalid <control> of \"%s\"", m_id.c_str());
52     return false;
53   }
54     
55   bool ok = false;
56   CStdString strAddonType;
57   const TiXmlNode *constraints = node->FirstChild("constraints");
58   if (constraints != NULL)
59   {
60     // get the addon type
61     if (XMLUtils::GetString(constraints, "addontype", strAddonType) && !strAddonType.empty())
62     {
63       m_addonType = ADDON::TranslateType(strAddonType);
64       if (m_addonType != ADDON::ADDON_UNKNOWN)
65         ok = true;
66     }
67   }
68
69   if (!ok && !update)
70   {
71     CLog::Log(LOGERROR, "CSettingAddon: error reading the addontype value \"%s\" of \"%s\"", strAddonType.c_str(), m_id.c_str());
72     return false;
73   }
74
75   return true;
76 }
77
78 void CSettingAddon::copy(const CSettingAddon &setting)
79 {
80   CSettingString::Copy(setting);
81   
82   CExclusiveLock lock(m_critical);
83   m_addonType = setting.m_addonType;
84 }