[videodb] Remove nested transaction when saving state after stopping PVR playback
[xbmc.git] / xbmc / settings / SettingPath.cpp
blobfa215ff735275000bb5d49521da4074c3cdc738b
1 /*
2 * Copyright (C) 2013-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
9 #include "SettingPath.h"
11 #include "settings/lib/SettingsManager.h"
12 #include "utils/FileExtensionProvider.h"
13 #include "utils/StringUtils.h"
14 #include "utils/XBMCTinyXML.h"
15 #include "utils/XMLUtils.h"
16 #include "utils/log.h"
18 #include <mutex>
20 #define XML_ELM_DEFAULT "default"
21 #define XML_ELM_CONSTRAINTS "constraints"
23 CSettingPath::CSettingPath(const std::string &id, CSettingsManager *settingsManager /* = nullptr */)
24 : CSettingString(id, settingsManager)
25 { }
27 CSettingPath::CSettingPath(const std::string &id, int label, const std::string &value, CSettingsManager *settingsManager /* = nullptr */)
28 : CSettingString(id, label, value, settingsManager)
29 { }
31 CSettingPath::CSettingPath(const std::string &id, const CSettingPath &setting)
32 : CSettingString(id, setting)
34 copy(setting);
37 SettingPtr CSettingPath::Clone(const std::string &id) const
39 return std::make_shared<CSettingPath>(id, *this);
42 bool CSettingPath::Deserialize(const TiXmlNode *node, bool update /* = false */)
44 std::unique_lock<CSharedSection> lock(m_critical);
46 if (!CSettingString::Deserialize(node, update))
47 return false;
49 if (m_control != nullptr &&
50 (m_control->GetType() != "button" || (m_control->GetFormat() != "path" && m_control->GetFormat() != "file" && m_control->GetFormat() != "image")))
52 CLog::Log(LOGERROR, "CSettingPath: invalid <control> of \"{}\"", m_id);
53 return false;
56 auto constraints = node->FirstChild(XML_ELM_CONSTRAINTS);
57 if (constraints != nullptr)
59 // get writable
60 XMLUtils::GetBoolean(constraints, "writable", m_writable);
61 // get hide extensions
62 XMLUtils::GetBoolean(constraints, "hideextensions", m_hideExtension);
64 // get sources
65 auto sources = constraints->FirstChild("sources");
66 if (sources != nullptr)
68 m_sources.clear();
69 auto source = sources->FirstChild("source");
70 while (source != nullptr)
72 auto child = source->FirstChild();
73 if (child != nullptr)
75 const std::string& strSource = child->ValueStr();
76 if (!strSource.empty())
77 m_sources.push_back(strSource);
80 source = source->NextSibling("source");
84 // get masking
85 auto masking = constraints->FirstChild("masking");
86 if (masking != nullptr)
87 m_masking = masking->FirstChild()->ValueStr();
90 return true;
93 bool CSettingPath::SetValue(const std::string &value)
95 // for backwards compatibility to Frodo
96 if (StringUtils::EqualsNoCase(value, "select folder") ||
97 StringUtils::EqualsNoCase(value, "select writable folder"))
98 return CSettingString::SetValue("");
100 return CSettingString::SetValue(value);
103 std::string CSettingPath::GetMasking(const CFileExtensionProvider& fileExtensionProvider) const
105 if (m_masking.empty())
106 return m_masking;
108 // setup masking
109 auto audioMask = fileExtensionProvider.GetMusicExtensions();
110 auto videoMask = fileExtensionProvider.GetVideoExtensions();
111 auto imageMask = fileExtensionProvider.GetPictureExtensions();
112 auto execMask = "";
113 #if defined(TARGET_WINDOWS)
114 execMask = ".exe|.bat|.cmd|.py";
115 #endif // defined(TARGET_WINDOWS)
117 std::string masking = m_masking;
118 if (masking == "video")
119 return videoMask;
120 if (masking == "audio")
121 return audioMask;
122 if (masking == "image")
123 return imageMask;
124 if (masking == "executable")
125 return execMask;
127 // convert mask qualifiers
128 StringUtils::Replace(masking, "$AUDIO", audioMask);
129 StringUtils::Replace(masking, "$VIDEO", videoMask);
130 StringUtils::Replace(masking, "$IMAGE", imageMask);
131 StringUtils::Replace(masking, "$EXECUTABLE", execMask);
133 return masking;
136 void CSettingPath::copy(const CSettingPath& setting)
138 CSettingString::Copy(setting);
140 std::unique_lock<CSharedSection> lock(m_critical);
141 m_writable = setting.m_writable;
142 m_sources = setting.m_sources;
143 m_hideExtension = setting.m_hideExtension;
144 m_masking = setting.m_masking;