Merge pull request #1994 from nemphys/pvr-epg-startup
[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/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"
28
29 #define XML_ELM_DEFAULT     "default"
30 #define XML_ELM_CONSTRAINTS "constraints"
31
32 CSettingPath::CSettingPath(const std::string &id, CSettingsManager *settingsManager /* = NULL */)
33   : CSettingString(id, settingsManager),
34     m_writable(true)
35 {
36   m_control.SetType(SettingControlTypeButton);
37   m_control.SetFormat(SettingControlFormatPath);
38   m_control.SetAttributes(SettingControlAttributeNone);
39 }
40   
41 CSettingPath::CSettingPath(const std::string &id, const CSettingPath &setting)
42   : CSettingString(id, setting)
43 {
44   copy(setting);
45 }
46
47 bool CSettingPath::Deserialize(const TiXmlNode *node, bool update /* = false */)
48 {
49   CSingleLock lock(m_critical);
50
51   if (!CSettingString::Deserialize(node, update))
52     return false;
53     
54   if (m_control.GetType() != SettingControlTypeButton ||
55       m_control.GetFormat() != SettingControlFormatPath ||
56       m_control.GetAttributes() != SettingControlAttributeNone)
57   {
58     CLog::Log(LOGERROR, "CSettingPath: invalid <control> of \"%s\"", m_id.c_str());
59     return false;
60   }
61     
62   const TiXmlNode *constraints = node->FirstChild(XML_ELM_CONSTRAINTS);
63   if (constraints != NULL)
64   {
65     // get writable
66     XMLUtils::GetBoolean(constraints, "writable", m_writable);
67
68     // get sources
69     const TiXmlNode *sources = constraints->FirstChild("sources");
70     if (sources != NULL)
71     {
72       m_sources.clear();
73       const TiXmlNode *source = sources->FirstChild("source");
74       while (source != NULL)
75       {
76         std::string strSource = source->FirstChild()->ValueStr();
77         if (!strSource.empty())
78           m_sources.push_back(strSource);
79
80         source = source->NextSibling("source");
81       }
82     }
83   }
84
85   return true;
86 }
87
88 bool CSettingPath::SetValue(const std::string &value)
89 {
90   // for backwards compatibility to Frodo
91   if (StringUtils::EqualsNoCase(value, "select folder") ||
92       StringUtils::EqualsNoCase(value, "select writable folder"))
93     return CSettingString::SetValue("");
94
95   return CSettingString::SetValue(value);
96 }
97
98 void CSettingPath::copy(const CSettingPath &setting)
99 {
100   CSettingString::Copy(setting);
101
102   m_writable = setting.m_writable;
103   m_sources = setting.m_sources;
104 }