2 * Copyright (C) 2017-2021 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.
11 #include "commons/Exception.h"
12 #include "interfaces/legacy/AddonClass.h"
13 #include "interfaces/legacy/AddonString.h"
14 #include "interfaces/legacy/Exception.h"
15 #include "interfaces/legacy/Tuple.h"
16 #include "settings/lib/SettingDefinitions.h"
29 XBMCCOMMONS_STANDARD_EXCEPTION(SettingCallbacksNotSupportedException
);
32 /// \defgroup python_settings Settings
33 /// \ingroup python_xbmcaddon
35 /// @brief **Add-on settings**
37 /// \python_class{ Settings() }
39 /// This wrapper provides access to the settings specific to an add-on.
40 /// It supports reading and writing specific setting values.
42 ///-----------------------------------------------------------------------
43 /// @python_v20 New class added.
46 /// ~~~~~~~~~~~~~{.py}
48 /// settings = xbmcaddon.Addon('id').getSettings()
52 class Settings
: public AddonClass
55 #ifndef DOXYGEN_SHOULD_SKIP_THIS
57 std::shared_ptr
<CSettingsBase
> settings
;
58 Settings(std::shared_ptr
<CSettingsBase
> settings
);
60 virtual ~Settings() = default;
63 #ifdef DOXYGEN_SHOULD_USE_THIS
65 /// \ingroup python_settings
66 /// @brief \python_func{ getBool(id) }
67 /// Returns the value of a setting as a boolean.
69 /// @param id string - id of the setting that the module needs to access.
70 /// @return bool - Setting as a boolean
73 ///-----------------------------------------------------------------------
74 /// @python_v20 New function added.
77 /// ~~~~~~~~~~~~~{.py}
79 /// enabled = settings.getBool('enabled')
85 bool getBool(const char* id
);
88 #ifdef DOXYGEN_SHOULD_USE_THIS
90 /// \ingroup python_settings
91 /// @brief \python_func{ getInt(id) }
92 /// Returns the value of a setting as an integer.
94 /// @param id string - id of the setting that the module needs to access.
95 /// @return integer - Setting as an integer
98 ///-----------------------------------------------------------------------
99 /// @python_v20 New function added.
102 /// ~~~~~~~~~~~~~{.py}
104 /// max = settings.getInt('max')
110 int getInt(const char* id
);
113 #ifdef DOXYGEN_SHOULD_USE_THIS
115 /// \ingroup python_settings
116 /// @brief \python_func{ getNumber(id) }
117 /// Returns the value of a setting as a floating point number.
119 /// @param id string - id of the setting that the module needs to access.
120 /// @return float - Setting as a floating point number
123 ///-----------------------------------------------------------------------
124 /// @python_v20 New function added.
127 /// ~~~~~~~~~~~~~{.py}
129 /// max = settings.getNumber('max')
135 double getNumber(const char* id
);
138 #ifdef DOXYGEN_SHOULD_USE_THIS
140 /// \ingroup python_settings
141 /// @brief \python_func{ getString(id) }
142 /// Returns the value of a setting as a unicode string.
144 /// @param id string - id of the setting that the module needs to access.
145 /// @return string - Setting as a unicode string
148 ///-----------------------------------------------------------------------
149 /// @python_v20 New function added.
152 /// ~~~~~~~~~~~~~{.py}
154 /// apikey = settings.getString('apikey')
160 String
getString(const char* id
);
163 #ifdef DOXYGEN_SHOULD_USE_THIS
165 /// \ingroup python_settings
166 /// @brief \python_func{ getBoolList(id) }
167 /// Returns the value of a setting as a list of booleans.
169 /// @param id string - id of the setting that the module needs to access.
170 /// @return list - Setting as a list of booleans
173 ///-----------------------------------------------------------------------
174 /// @python_v20 New function added.
177 /// ~~~~~~~~~~~~~{.py}
179 /// enabled = settings.getBoolList('enabled')
185 std::vector
<bool> getBoolList(const char* id
);
188 #ifdef DOXYGEN_SHOULD_USE_THIS
190 /// \ingroup python_settings
191 /// @brief \python_func{ getIntList(id) }
192 /// Returns the value of a setting as a list of integers.
194 /// @param id string - id of the setting that the module needs to access.
195 /// @return list - Setting as a list of integers
198 ///-----------------------------------------------------------------------
199 /// @python_v20 New function added.
202 /// ~~~~~~~~~~~~~{.py}
204 /// ids = settings.getIntList('ids')
210 std::vector
<int> getIntList(const char* id
);
213 #ifdef DOXYGEN_SHOULD_USE_THIS
215 /// \ingroup python_settings
216 /// @brief \python_func{ getNumberList(id) }
217 /// Returns the value of a setting as a list of floating point numbers.
219 /// @param id string - id of the setting that the module needs to access.
220 /// @return list - Setting as a list of floating point numbers
223 ///-----------------------------------------------------------------------
224 /// @python_v20 New function added.
227 /// ~~~~~~~~~~~~~{.py}
229 /// max = settings.getNumberList('max')
235 std::vector
<double> getNumberList(const char* id
);
238 #ifdef DOXYGEN_SHOULD_USE_THIS
240 /// \ingroup python_settings
241 /// @brief \python_func{ getStringList(id) }
242 /// Returns the value of a setting as a list of unicode strings.
244 /// @param id string - id of the setting that the module needs to access.
245 /// @return list - Setting as a list of unicode strings
248 ///-----------------------------------------------------------------------
249 /// @python_v20 New function added.
252 /// ~~~~~~~~~~~~~{.py}
254 /// views = settings.getStringList('views')
260 std::vector
<String
> getStringList(const char* id
);
263 #ifdef DOXYGEN_SHOULD_USE_THIS
265 /// \ingroup python_settings
266 /// @brief \python_func{ setBool(id, value) }
267 /// Sets the value of a setting.
269 /// @param id string - id of the setting that the module needs to access.
270 /// @param value bool - value of the setting.
273 /// @note You can use the above as keywords for arguments.
276 ///-----------------------------------------------------------------------
277 /// @python_v20 New function added.
280 /// ~~~~~~~~~~~~~{.py}
282 /// settings.setBool(id='enabled', value=True)
288 void setBool(const char* id
, bool value
);
291 #ifdef DOXYGEN_SHOULD_USE_THIS
293 /// \ingroup python_settings
294 /// @brief \python_func{ setInt(id, value) }
295 /// Sets the value of a setting.
297 /// @param id string - id of the setting that the module needs to access.
298 /// @param value integer - value of the setting.
301 /// @note You can use the above as keywords for arguments.
304 ///-----------------------------------------------------------------------
305 /// @python_v20 New function added.
308 /// ~~~~~~~~~~~~~{.py}
310 /// settings.setInt(id='max', value=5)
316 void setInt(const char* id
, int value
);
319 #ifdef DOXYGEN_SHOULD_USE_THIS
321 /// \ingroup python_settings
322 /// @brief \python_func{ setNumber(id, value) }
323 /// Sets the value of a setting.
325 /// @param id string - id of the setting that the module needs to access.
326 /// @param value float - value of the setting.
329 /// @note You can use the above as keywords for arguments.
332 ///-----------------------------------------------------------------------
333 /// @python_v20 New function added.
336 /// ~~~~~~~~~~~~~{.py}
338 /// settings.setNumber(id='max', value=5.5)
344 void setNumber(const char* id
, double value
);
347 #ifdef DOXYGEN_SHOULD_USE_THIS
349 /// \ingroup python_settings
350 /// @brief \python_func{ setString(id, value) }
351 /// Sets the value of a setting.
353 /// @param id string - id of the setting that the module needs to access.
354 /// @param value string or unicode - value of the setting.
357 /// @note You can use the above as keywords for arguments.
360 ///-----------------------------------------------------------------------
361 /// @python_v20 New function added.
364 /// ~~~~~~~~~~~~~{.py}
366 /// settings.setString(id='username', value='teamkodi')
372 void setString(const char* id
, const String
& value
);
375 #ifdef DOXYGEN_SHOULD_USE_THIS
377 /// \ingroup python_settings
378 /// @brief \python_func{ setBoolList(id, values) }
379 /// Sets the boolean values of a list setting.
381 /// @param id string - id of the setting that the module needs to access.
382 /// @param values list of boolean - values of the setting.
385 /// @note You can use the above as keywords for arguments.
388 ///-----------------------------------------------------------------------
389 /// @python_v20 New function added.
392 /// ~~~~~~~~~~~~~{.py}
394 /// settings.setBoolList(id='enabled', values=[ True, False ])
400 void setBoolList(const char* id
, const std::vector
<bool>& values
);
403 #ifdef DOXYGEN_SHOULD_USE_THIS
405 /// \ingroup python_settings
406 /// @brief \python_func{ setIntList(id, value) }
407 /// Sets the integer values of a list setting.
409 /// @param id string - id of the setting that the module needs to access.
410 /// @param values list of int - values of the setting.
413 /// @note You can use the above as keywords for arguments.
416 ///-----------------------------------------------------------------------
417 /// @python_v20 New function added.
420 /// ~~~~~~~~~~~~~{.py}
422 /// settings.setIntList(id='max', values=[ 5, 23 ])
428 void setIntList(const char* id
, const std::vector
<int>& values
);
431 #ifdef DOXYGEN_SHOULD_USE_THIS
433 /// \ingroup python_settings
434 /// @brief \python_func{ setNumberList(id, value) }
435 /// Sets the floating point values of a list setting.
437 /// @param id string - id of the setting that the module needs to access.
438 /// @param values list of float - values of the setting.
441 /// @note You can use the above as keywords for arguments.
444 ///-----------------------------------------------------------------------
445 /// @python_v20 New function added.
448 /// ~~~~~~~~~~~~~{.py}
450 /// settings.setNumberList(id='max', values=[ 5.5, 5.8 ])
456 void setNumberList(const char* id
, const std::vector
<double>& values
);
459 #ifdef DOXYGEN_SHOULD_USE_THIS
461 /// \ingroup python_settings
462 /// @brief \python_func{ setStringList(id, value) }
463 /// Sets the string values of a list setting.
465 /// @param id string - id of the setting that the module needs to access.
466 /// @param values list of string or unicode - values of the setting.
469 /// @note You can use the above as keywords for arguments.
472 ///-----------------------------------------------------------------------
473 /// @python_v20 New function added.
476 /// ~~~~~~~~~~~~~{.py}
478 /// settings.setStringList(id='username', values=[ 'team', 'kodi' ])
484 void setStringList(const char* id
, const std::vector
<String
>& values
);
489 } // namespace xbmcaddon
490 } // namespace XBMCAddon