Fix keymap.
[vuplus_xbmc] / xbmc / settings / SettingPath.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 "SettingPath.h"
22 #include "settings/lib/SettingsManager.h"
23 #include "utils/log.h"
24 #include "utils/StringUtils.h"
25 #include "utils/XBMCTinyXML.h"
26 #include "utils/XMLUtils.h"
27
28 #define XML_ELM_DEFAULT     "default"
29 #define XML_ELM_CONSTRAINTS "constraints"
30
31 CSettingPath::CSettingPath(const std::string &id, CSettingsManager *settingsManager /* = NULL */)
32   : CSettingString(id, settingsManager),
33     m_writable(true)
34 { }
35   
36 CSettingPath::CSettingPath(const std::string &id, const CSettingPath &setting)
37   : CSettingString(id, setting)
38 {
39   copy(setting);
40 }
41
42 CSetting* CSettingPath::Clone(const std::string &id) const
43 {
44   return new CSettingPath(id, *this);
45 }
46
47 bool CSettingPath::Deserialize(const TiXmlNode *node, bool update /* = false */)
48 {
49   CExclusiveLock lock(m_critical);
50
51   if (!CSettingString::Deserialize(node, update))
52     return false;
53     
54   if (m_control != NULL &&
55      (m_control->GetType() != "button" || m_control->GetFormat() != "path"))
56   {
57     CLog::Log(LOGERROR, "CSettingPath: invalid <control> of \"%s\"", m_id.c_str());
58     return false;
59   }
60     
61   const TiXmlNode *constraints = node->FirstChild(XML_ELM_CONSTRAINTS);
62   if (constraints != NULL)
63   {
64     // get writable
65     XMLUtils::GetBoolean(constraints, "writable", m_writable);
66
67     // get sources
68     const TiXmlNode *sources = constraints->FirstChild("sources");
69     if (sources != NULL)
70     {
71       m_sources.clear();
72       const TiXmlNode *source = sources->FirstChild("source");
73       while (source != NULL)
74       {
75         std::string strSource = source->FirstChild()->ValueStr();
76         if (!strSource.empty())
77           m_sources.push_back(strSource);
78
79         source = source->NextSibling("source");
80       }
81     }
82   }
83
84   return true;
85 }
86
87 bool CSettingPath::SetValue(const std::string &value)
88 {
89   // for backwards compatibility to Frodo
90   if (StringUtils::EqualsNoCase(value, "select folder") ||
91       StringUtils::EqualsNoCase(value, "select writable folder"))
92     return CSettingString::SetValue("");
93
94   return CSettingString::SetValue(value);
95 }
96
97 void CSettingPath::copy(const CSettingPath &setting)
98 {
99   CSettingString::Copy(setting);
100
101   CExclusiveLock lock(m_critical);
102   m_writable = setting.m_writable;
103   m_sources = setting.m_sources;
104 }