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/SettingsManager.h"
23 #include "threads/SingleLock.h"
24 #include "utils/log.h"
25 #include "utils/StringUtils.h"
26 #include "utils/XBMCTinyXML.h"
27 #include "utils/XMLUtils.h"
29 #define XML_ELM_DEFAULT "default"
30 #define XML_ELM_CONSTRAINTS "constraints"
32 CSettingPath::CSettingPath(const std::string &id, CSettingsManager *settingsManager /* = NULL */)
33 : CSettingString(id, settingsManager),
36 m_control.SetType(SettingControlTypeButton);
37 m_control.SetFormat(SettingControlFormatPath);
38 m_control.SetAttributes(SettingControlAttributeNone);
41 CSettingPath::CSettingPath(const std::string &id, const CSettingPath &setting)
42 : CSettingString(id, setting)
47 bool CSettingPath::Deserialize(const TiXmlNode *node, bool update /* = false */)
49 CSingleLock lock(m_critical);
51 if (!CSettingString::Deserialize(node, update))
54 if (m_control.GetType() != SettingControlTypeButton ||
55 m_control.GetFormat() != SettingControlFormatPath ||
56 m_control.GetAttributes() != SettingControlAttributeNone)
58 CLog::Log(LOGERROR, "CSettingPath: invalid <control> of \"%s\"", m_id.c_str());
62 // get the default value by abusing the FromString
63 // implementation to parse the default value
65 if (XMLUtils::GetString(node, XML_ELM_DEFAULT, value))
66 m_value = m_default = value;
67 else if (!update && !m_allowEmpty)
69 CLog::Log(LOGERROR, "CSettingPath: error reading the default value of \"%s\"", m_id.c_str());
73 const TiXmlNode *constraints = node->FirstChild(XML_ELM_CONSTRAINTS);
74 if (constraints != NULL)
77 XMLUtils::GetBoolean(constraints, "writable", m_writable);
80 const TiXmlNode *sources = constraints->FirstChild("sources");
84 const TiXmlNode *source = sources->FirstChild("source");
85 while (source != NULL)
87 std::string strSource = source->FirstChild()->ValueStr();
88 if (!strSource.empty())
89 m_sources.push_back(strSource);
91 source = source->NextSibling("source");
99 bool CSettingPath::SetValue(const std::string &value)
101 // for backwards compatibility to Frodo
102 if (StringUtils::EqualsNoCase(value, "select folder") ||
103 StringUtils::EqualsNoCase(value, "select writable folder"))
104 return CSettingString::SetValue("");
106 return CSettingString::SetValue(value);
109 void CSettingPath::copy(const CSettingPath &setting)
111 CSettingString::Copy(setting);
113 m_writable = setting.m_writable;
114 m_sources = setting.m_sources;