2 * Copyright (C) 2005-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.
11 #include "addons/Addon.h"
12 #include "addons/gui/skin/SkinTimerManager.h"
13 #include "guilib/GUIIncludes.h" // needed for the GUIInclude member
14 #include "windowing/GraphicContext.h" // needed for the RESOLUTION members
22 #define CREDIT_LINE_LENGTH 50
25 struct IntegerSettingOption
;
26 struct StringSettingOption
;
31 class CSkinSettingUpdateHandler
;
36 virtual ~CSkinSetting() = default;
38 bool Serialize(TiXmlElement
* parent
) const;
40 virtual std::string
GetType() const = 0;
42 virtual bool Deserialize(const TiXmlElement
* element
);
47 virtual bool SerializeSetting(TiXmlElement
* element
) const = 0;
50 typedef std::shared_ptr
<CSkinSetting
> CSkinSettingPtr
;
52 class CSkinSettingString
: public CSkinSetting
55 ~CSkinSettingString() override
= default;
57 std::string
GetType() const override
{ return "string"; }
59 bool Deserialize(const TiXmlElement
* element
) override
;
64 bool SerializeSetting(TiXmlElement
* element
) const override
;
67 typedef std::shared_ptr
<CSkinSettingString
> CSkinSettingStringPtr
;
69 class CSkinSettingBool
: public CSkinSetting
72 ~CSkinSettingBool() override
= default;
74 std::string
GetType() const override
{ return "bool"; }
76 bool Deserialize(const TiXmlElement
* element
) override
;
81 bool SerializeSetting(TiXmlElement
* element
) const override
;
84 typedef std::shared_ptr
<CSkinSettingBool
> CSkinSettingBoolPtr
;
86 class CSkinInfo
: public CAddon
92 CStartupWindow(int id
, const char *name
):
93 m_id(id
), m_name(name
)
100 explicit CSkinInfo(const AddonInfoPtr
& addonInfo
);
101 //FIXME: CAddonCallbacksGUI/WindowXML hack
103 const AddonInfoPtr
& addonInfo
,
104 const RESOLUTION_INFO
& resolution
);
107 const AddonInfoPtr
& addonInfo
,
108 const RESOLUTION_INFO
& resolution
,
109 const std::vector
<RESOLUTION_INFO
>& resolutions
,
110 float effectsSlowDown
,
113 ~CSkinInfo() override
;
115 /*! \brief Load resolution information from directories in Path().
119 bool HasSkinFile(const std::string
&strFile
) const;
121 /*! \brief Get the full path to the specified file in the skin
122 We search for XML files in the skin folder that best matches the current resolution.
123 \param file XML file to look for
124 \param res [out] If non-NULL, the resolution that the returned XML file is in is returned. Defaults to NULL.
125 \param baseDir [in] If non-empty, the given directory is searched instead of the skin's directory. Defaults to empty.
126 \return path to the XML file
128 std::string
GetSkinPath(const std::string
& file
,
129 RESOLUTION_INFO
* res
= nullptr,
130 const std::string
& baseDir
= "") const;
132 /*! \brief Return whether skin debugging is enabled
133 \return true if skin debugging (set via <debugging>true</debugging> in addon.xml) is enabled.
135 bool IsDebugging() const { return m_debugging
; }
137 /*! \brief Get the id of the first window to load
138 The first window is generally Startup.xml unless it doesn't exist or if the skinner
139 has specified which start windows they support and the user is going to somewhere other
140 than the home screen.
141 \return id of the first window to load
143 int GetFirstWindow() const;
145 /*! \brief Get the id of the window the user wants to start in after any skin animation
146 \return id of the start window
148 int GetStartWindow() const;
150 /*! \brief Translate a resolution string
151 \param name the string to translate
152 \param res [out] the resolution structure if name is valid
153 \return true if the resolution is valid, false otherwise
155 static bool TranslateResolution(const std::string
&name
, RESOLUTION_INFO
&res
);
157 void ResolveIncludes(TiXmlElement
* node
,
158 std::map
<INFO::InfoPtr
, bool>* xmlIncludeConditions
= nullptr);
160 float GetEffectsSlowdown() const { return m_effectsSlowDown
; }
162 const std::vector
<CStartupWindow
>& GetStartupWindows() const { return m_startupWindows
; }
164 /*! \brief Retrieve the skin paths to search for skin XML files
165 \param paths [out] vector of paths to search, in order.
167 void GetSkinPaths(std::vector
<std::string
> &paths
) const;
169 bool IsInUse() const override
;
171 const std::string
& GetCurrentAspect() const { return m_currentAspect
; }
175 /*! \brief Load the defined skin timers
176 \details Skin timers are defined in Timers.xml \sa Skin_Timers
180 /*! \brief Starts evaluating timers
182 void ProcessTimers();
184 /*! \brief Called when unloading a skin, allows to cleanup specific
190 const INFO::CSkinVariableString
* CreateSkinVariable(const std::string
& name
, int context
);
192 static void SettingOptionsSkinColorsFiller(const std::shared_ptr
<const CSetting
>& setting
,
193 std::vector
<StringSettingOption
>& list
,
194 std::string
& current
,
196 static void SettingOptionsSkinFontsFiller(const std::shared_ptr
<const CSetting
>& setting
,
197 std::vector
<StringSettingOption
>& list
,
198 std::string
& current
,
200 static void SettingOptionsSkinThemesFiller(const std::shared_ptr
<const CSetting
>& setting
,
201 std::vector
<StringSettingOption
>& list
,
202 std::string
& current
,
204 static void SettingOptionsStartupWindowsFiller(const std::shared_ptr
<const CSetting
>& setting
,
205 std::vector
<IntegerSettingOption
>& list
,
209 /*! \brief Don't handle skin settings like normal addon settings
211 bool HasSettings(AddonInstanceId id
= ADDON_SETTINGS_ID
) override
{ return false; }
212 bool HasUserSettings(AddonInstanceId id
= ADDON_SETTINGS_ID
) override
{ return false; }
214 int TranslateString(const std::string
&setting
);
215 const std::string
& GetString(int setting
) const;
216 void SetString(int setting
, const std::string
&label
);
218 int TranslateBool(const std::string
&setting
);
219 bool GetBool(int setting
) const;
220 void SetBool(int setting
, bool set
);
222 /*! \brief Get the skin setting value as an integer value
223 * \param setting - the setting id
224 * \return the setting value as an integer, -1 if no conversion is possible
226 int GetInt(int setting
) const;
228 std::set
<CSkinSettingPtr
> GetSkinSettings() const;
229 CSkinSettingPtr
GetSkinSetting(const std::string
& settingId
);
230 std::shared_ptr
<const CSkinSetting
> GetSkinSetting(const std::string
& settingId
) const;
232 void Reset(const std::string
&setting
);
235 static std::set
<CSkinSettingPtr
> ParseSettings(const TiXmlElement
* rootElement
);
237 void OnPreInstall() override
;
238 void OnPostInstall(bool update
, bool modal
) override
;
240 // skin timer methods
242 /*! \brief Checks if the timer with name `timer` is running
243 \param timer the name of the skin timer
244 \return true if the given timer exists and is running, false otherwise
246 bool TimerIsRunning(const std::string
& timer
) const;
248 /*! \brief Get the elapsed seconds since the timer with name `timer` was started
249 \param timer the name of the skin timer
250 \return the elapsed time in seconds the given timer is running (0 if not running or if it does not exist)
252 float GetTimerElapsedSeconds(const std::string
& timer
) const;
254 /*! \brief Starts/Enables a given skin timer
255 \param timer the name of the skin timer
257 void TimerStart(const std::string
& timer
) const;
259 /*! \brief Stops/Disables a given skin timer
260 \param timer the name of the skin timer
262 void TimerStop(const std::string
& timer
) const;
265 bool LoadStartupWindows(const AddonInfoPtr
& addonInfo
);
267 static CSkinSettingPtr
ParseSetting(const TiXmlElement
* element
);
269 bool SettingsLoaded(AddonInstanceId id
= ADDON_SETTINGS_ID
) const override
;
270 bool SettingsFromXML(const CXBMCTinyXML
& doc
,
272 AddonInstanceId id
= ADDON_SETTINGS_ID
) override
;
273 bool SettingsToXML(CXBMCTinyXML
& doc
, AddonInstanceId id
= ADDON_SETTINGS_ID
) const override
;
275 RESOLUTION_INFO m_defaultRes
;
276 std::vector
<RESOLUTION_INFO
> m_resolutions
;
278 float m_effectsSlowDown
;
279 CGUIIncludes m_includes
;
280 std::string m_currentAspect
;
282 std::vector
<CStartupWindow
> m_startupWindows
;
285 /*! Manager/Owner of skin timers */
286 std::unique_ptr
<CSkinTimerManager
> m_skinTimerManager
;
289 std::map
<int, CSkinSettingStringPtr
> m_strings
;
290 std::map
<int, CSkinSettingBoolPtr
> m_bools
;
291 std::map
<std::string
, CSkinSettingPtr
> m_settings
;
292 std::unique_ptr
<CSkinSettingUpdateHandler
> m_settingsUpdateHandler
;
295 } /*namespace ADDON*/
297 extern std::shared_ptr
<ADDON::CSkinInfo
> g_SkinInfo
;