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 const TiXmlNode *constraints = node->FirstChild(XML_ELM_CONSTRAINTS);
63 if (constraints != NULL)
66 XMLUtils::GetBoolean(constraints, "writable", m_writable);
69 const TiXmlNode *sources = constraints->FirstChild("sources");
73 const TiXmlNode *source = sources->FirstChild("source");
74 while (source != NULL)
76 std::string strSource = source->FirstChild()->ValueStr();
77 if (!strSource.empty())
78 m_sources.push_back(strSource);
80 source = source->NextSibling("source");
88 bool CSettingPath::SetValue(const std::string &value)
90 // for backwards compatibility to Frodo
91 if (StringUtils::EqualsNoCase(value, "select folder") ||
92 StringUtils::EqualsNoCase(value, "select writable folder"))
93 return CSettingString::SetValue("");
95 return CSettingString::SetValue(value);
98 void CSettingPath::copy(const CSettingPath &setting)
100 CSettingString::Copy(setting);
102 m_writable = setting.m_writable;
103 m_sources = setting.m_sources;