Remove LiveTV menu.
[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/lib/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 CSetting* CSettingAddon::Clone(const std::string &id) const
42 {
43   return new CSettingAddon(id, *this);
44 }
45
46 bool CSettingAddon::Deserialize(const TiXmlNode *node, bool update /* = false */)
47 {
48   CExclusiveLock lock(m_critical);
49
50   if (!CSettingString::Deserialize(node, update))
51     return false;
52     
53   if (m_control != NULL &&
54      (m_control->GetType() != "button" || m_control->GetFormat() != "addon"))
55   {
56     CLog::Log(LOGERROR, "CSettingAddon: invalid <control> of \"%s\"", m_id.c_str());
57     return false;
58   }
59     
60   bool ok = false;
61   CStdString strAddonType;
62   const TiXmlNode *constraints = node->FirstChild("constraints");
63   if (constraints != NULL)
64   {
65     // get the addon type
66     if (XMLUtils::GetString(constraints, "addontype", strAddonType) && !strAddonType.empty())
67     {
68       m_addonType = ADDON::TranslateType(strAddonType);
69       if (m_addonType != ADDON::ADDON_UNKNOWN)
70         ok = true;
71     }
72   }
73
74   if (!ok && !update)
75   {
76     CLog::Log(LOGERROR, "CSettingAddon: error reading the addontype value \"%s\" of \"%s\"", strAddonType.c_str(), m_id.c_str());
77     return false;
78   }
79
80   return true;
81 }
82
83 void CSettingAddon::copy(const CSettingAddon &setting)
84 {
85   CSettingString::Copy(setting);
86   
87   CExclusiveLock lock(m_critical);
88   m_addonType = setting.m_addonType;
89 }