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 "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"
28 #define XML_ELM_DEFAULT "default"
29 #define XML_ELM_CONSTRAINTS "constraints"
31 CSettingPath::CSettingPath(const std::string &id, CSettingsManager *settingsManager /* = NULL */)
32 : CSettingString(id, settingsManager),
36 CSettingPath::CSettingPath(const std::string &id, const CSettingPath &setting)
37 : CSettingString(id, setting)
42 CSetting* CSettingPath::Clone(const std::string &id) const
44 return new CSettingPath(id, *this);
47 bool CSettingPath::Deserialize(const TiXmlNode *node, bool update /* = false */)
49 CExclusiveLock lock(m_critical);
51 if (!CSettingString::Deserialize(node, update))
54 if (m_control != NULL &&
55 (m_control->GetType() != "button" || m_control->GetFormat() != "path"))
57 CLog::Log(LOGERROR, "CSettingPath: invalid <control> of \"%s\"", m_id.c_str());
61 const TiXmlNode *constraints = node->FirstChild(XML_ELM_CONSTRAINTS);
62 if (constraints != NULL)
65 XMLUtils::GetBoolean(constraints, "writable", m_writable);
68 const TiXmlNode *sources = constraints->FirstChild("sources");
72 const TiXmlNode *source = sources->FirstChild("source");
73 while (source != NULL)
75 std::string strSource = source->FirstChild()->ValueStr();
76 if (!strSource.empty())
77 m_sources.push_back(strSource);
79 source = source->NextSibling("source");
87 bool CSettingPath::SetValue(const std::string &value)
89 // for backwards compatibility to Frodo
90 if (StringUtils::EqualsNoCase(value, "select folder") ||
91 StringUtils::EqualsNoCase(value, "select writable folder"))
92 return CSettingString::SetValue("");
94 return CSettingString::SetValue(value);
97 void CSettingPath::copy(const CSettingPath &setting)
99 CSettingString::Copy(setting);
101 CExclusiveLock lock(m_critical);
102 m_writable = setting.m_writable;
103 m_sources = setting.m_sources;