kodi
SettingSection.h
1 /*
2  * Copyright (C) 2013-2018 Team Kodi
3  * This file is part of Kodi - https://kodi.tv
4  *
5  * SPDX-License-Identifier: GPL-2.0-or-later
6  * See LICENSES/README.md for more information.
7  */
8 
9 #pragma once
10 
11 #include "ISetting.h"
12 #include "Setting.h"
13 #include "SettingCategoryAccess.h"
14 #include "utils/logtypes.h"
15 
16 #include <string>
17 #include <utility>
18 #include <vector>
19 
20 class CSettingsManager;
21 
28 class CSettingGroup : public ISetting
29 {
30 public:
37  CSettingGroup(const std::string &id, CSettingsManager *settingsManager = nullptr);
38  ~CSettingGroup() override = default;
39 
40  // implementation of ISetting
41  bool Deserialize(const TiXmlNode *node, bool update = false) override;
42 
48  const SettingList& GetSettings() const { return m_settings; }
57  SettingList GetSettings(SettingLevel level) const;
58 
59  /*
60  * \brief Determine if there are visible settings assigned to the given setting level (or below)
61  * and that they meet the requirements conditions belonging to the setting group.
62  * \param level Level the settings should be assigned to
63  * \return True if there are visible settings belonging to the setting group, otherwise false
64  */
65  bool ContainsVisibleSettings(const SettingLevel level) const;
66 
67  void AddSetting(const std::shared_ptr<CSetting>& setting);
68  void AddSettings(const SettingList &settings);
69 
70  bool ReplaceSetting(const std::shared_ptr<const CSetting>& currentSetting,
71  const std::shared_ptr<CSetting>& newSetting);
72 
73  std::shared_ptr<const ISettingControl> GetControl() const { return m_control; }
74  std::shared_ptr<ISettingControl> GetControl() { return m_control; }
75  void SetControl(std::shared_ptr<ISettingControl> control) { m_control = std::move(control); }
76 
77 private:
78  SettingList m_settings;
79  std::shared_ptr<ISettingControl> m_control;
80 
81  static Logger s_logger;
82 };
83 
84 using SettingGroupPtr = std::shared_ptr<CSettingGroup>;
85 using SettingGroupList = std::vector<SettingGroupPtr>;
86 
93 class CSettingCategory : public ISetting
94 {
95 public:
102  CSettingCategory(const std::string &id, CSettingsManager *settingsManager = nullptr);
103  ~CSettingCategory() override = default;
104 
105  // implementation of ISetting
106  bool Deserialize(const TiXmlNode *node, bool update = false) override;
107 
114  const SettingGroupList& GetGroups() const { return m_groups; }
123  SettingGroupList GetGroups(SettingLevel level) const;
124 
130  bool CanAccess() const;
131 
132  void AddGroup(const SettingGroupPtr& group);
133  void AddGroupToFront(const SettingGroupPtr& group);
134  void AddGroups(const SettingGroupList &groups);
135 
136 private:
137  SettingGroupList m_groups;
138  CSettingCategoryAccess m_accessCondition;
139 
140  static Logger s_logger;
141 };
142 
143 using SettingCategoryPtr = std::shared_ptr<CSettingCategory>;
144 using SettingCategoryList = std::vector<SettingCategoryPtr>;
145 
152 class CSettingSection : public ISetting
153 {
154 public:
161  CSettingSection(const std::string &id, CSettingsManager *settingsManager = nullptr);
162  ~CSettingSection() override = default;
163 
164  // implementation of ISetting
165  bool Deserialize(const TiXmlNode *node, bool update = false) override;
166 
173  const SettingCategoryList& GetCategories() const { return m_categories; }
182  SettingCategoryList GetCategories(SettingLevel level) const;
183 
184  void AddCategory(const SettingCategoryPtr& category);
185  void AddCategories(const SettingCategoryList &categories);
186 
187 private:
188  SettingCategoryList m_categories;
189 
190  static Logger s_logger;
191 };
192 
193 using SettingSectionPtr = std::shared_ptr<CSettingSection>;
194 using SettingSectionList = std::vector<SettingSectionPtr>;
Category of groups of settings being part of a section.
Definition: SettingSection.h:93
const SettingList & GetSettings() const
Gets the full list of settings belonging to the setting group.
Definition: SettingSection.h:48
Definition: SettingCategoryAccess.h:42
Interface defining the base of all setting objects.
Definition: ISetting.h:22
Section of setting categories.
Definition: SettingSection.h:152
const SettingCategoryList & GetCategories() const
Gets the full list of setting categories belonging to the setting section.
Definition: SettingSection.h:173
Definition: settings.py:1
Definition: SmartPlayList.cpp:137
bool Deserialize(const TiXmlNode *node, bool update=false) override
Deserializes the given XML node into the properties of the setting object.
Definition: SettingSection.cpp:70
Settings manager responsible for initializing, loading and handling all settings. ...
Definition: SettingsManager.h:41
CSettingGroup(const std::string &id, CSettingsManager *settingsManager=nullptr)
Creates a new setting group with the given identifier.
Definition: SettingSection.cpp:62
Group of settings being part of a category.
Definition: SettingSection.h:28
SettingLevel
Levels which every setting is assigned to.
Definition: SettingLevel.h:15
const SettingGroupList & GetGroups() const
Gets the full list of setting groups belonging to the setting category.
Definition: SettingSection.h:114