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
26 struct IntegerSettingOption
;
27 struct StringSettingOption
;
32 class CSkinSettingUpdateHandler
;
37 virtual ~CSkinSetting() = default;
39 bool Serialize(TiXmlElement
* parent
) const;
41 virtual std::string
GetType() const = 0;
43 virtual bool Deserialize(const TiXmlElement
* element
);
48 virtual bool SerializeSetting(TiXmlElement
* element
) const = 0;
51 typedef std::shared_ptr
<CSkinSetting
> CSkinSettingPtr
;
53 class CSkinSettingString
: public CSkinSetting
56 ~CSkinSettingString() override
= default;
58 std::string
GetType() const override
{ return "string"; }
60 bool Deserialize(const TiXmlElement
* element
) override
;
65 bool SerializeSetting(TiXmlElement
* element
) const override
;
68 typedef std::shared_ptr
<CSkinSettingString
> CSkinSettingStringPtr
;
70 class CSkinSettingBool
: public CSkinSetting
73 ~CSkinSettingBool() override
= default;
75 std::string
GetType() const override
{ return "bool"; }
77 bool Deserialize(const TiXmlElement
* element
) override
;
82 bool SerializeSetting(TiXmlElement
* element
) const override
;
85 typedef std::shared_ptr
<CSkinSettingBool
> CSkinSettingBoolPtr
;
87 class CSkinInfo
: public CAddon
93 CStartupWindow(int id
, const char *name
):
94 m_id(id
), m_name(name
)
101 explicit CSkinInfo(const AddonInfoPtr
& addonInfo
);
102 //FIXME: CAddonCallbacksGUI/WindowXML hack
104 const AddonInfoPtr
& addonInfo
,
105 const RESOLUTION_INFO
& resolution
);
108 const AddonInfoPtr
& addonInfo
,
109 const RESOLUTION_INFO
& resolution
,
110 const std::vector
<RESOLUTION_INFO
>& resolutions
,
111 float effectsSlowDown
,
114 ~CSkinInfo() override
;
116 /*! \brief Load resolution information from directories in Path().
120 bool HasSkinFile(const std::string
&strFile
) const;
122 /*! \brief Get the full path to the specified file in the skin
123 We search for XML files in the skin folder that best matches the current resolution.
124 \param file XML file to look for
125 \param res [out] If non-NULL, the resolution that the returned XML file is in is returned. Defaults to NULL.
126 \param baseDir [in] If non-empty, the given directory is searched instead of the skin's directory. Defaults to empty.
127 \return path to the XML file
129 std::string
GetSkinPath(const std::string
& file
,
130 RESOLUTION_INFO
* res
= nullptr,
131 const std::string
& baseDir
= "") const;
133 /*! \brief Return whether skin debugging is enabled
134 \return true if skin debugging (set via <debugging>true</debugging> in addon.xml) is enabled.
136 bool IsDebugging() const { return m_debugging
; }
138 /*! \brief Get the id of the first window to load
139 The first window is generally Startup.xml unless it doesn't exist or if the skinner
140 has specified which start windows they support and the user is going to somewhere other
141 than the home screen.
142 \return id of the first window to load
144 int GetFirstWindow() const;
146 /*! \brief Get the id of the window the user wants to start in after any skin animation
147 \return id of the start window
149 int GetStartWindow() const;
151 /*! \brief Translate a resolution string
152 \param name the string to translate
153 \param res [out] the resolution structure if name is valid
154 \return true if the resolution is valid, false otherwise
156 static bool TranslateResolution(const std::string
&name
, RESOLUTION_INFO
&res
);
158 void ResolveIncludes(TiXmlElement
* node
,
159 std::map
<INFO::InfoPtr
, bool>* xmlIncludeConditions
= nullptr);
161 float GetEffectsSlowdown() const { return m_effectsSlowDown
; }
163 const std::vector
<CStartupWindow
>& GetStartupWindows() const { return m_startupWindows
; }
165 /*! \brief Retrieve the skin paths to search for skin XML files
166 \param paths [out] vector of paths to search, in order.
168 void GetSkinPaths(std::vector
<std::string
> &paths
) const;
170 bool IsInUse() const override
;
172 const std::string
& GetCurrentAspect() const { return m_currentAspect
; }
176 /*! \brief Load the defined skin timers
177 \details Skin timers are defined in Timers.xml \sa Skin_Timers
181 /*! \brief Starts evaluating timers
183 void ProcessTimers();
185 /*! \brief Called when unloading a skin, allows to cleanup specific
191 const INFO::CSkinVariableString
* CreateSkinVariable(const std::string
& name
, int context
);
193 static void SettingOptionsSkinColorsFiller(const std::shared_ptr
<const CSetting
>& setting
,
194 std::vector
<StringSettingOption
>& list
,
195 std::string
& current
,
197 static void SettingOptionsSkinFontsFiller(const std::shared_ptr
<const CSetting
>& setting
,
198 std::vector
<StringSettingOption
>& list
,
199 std::string
& current
,
201 static void SettingOptionsSkinThemesFiller(const std::shared_ptr
<const CSetting
>& setting
,
202 std::vector
<StringSettingOption
>& list
,
203 std::string
& current
,
205 static void SettingOptionsStartupWindowsFiller(const std::shared_ptr
<const CSetting
>& setting
,
206 std::vector
<IntegerSettingOption
>& list
,
210 /*! \brief Don't handle skin settings like normal addon settings
212 bool HasSettings(AddonInstanceId id
= ADDON_SETTINGS_ID
) override
{ return false; }
213 bool HasUserSettings(AddonInstanceId id
= ADDON_SETTINGS_ID
) override
{ return false; }
215 int TranslateString(const std::string
&setting
);
216 const std::string
& GetString(int setting
) const;
217 void SetString(int setting
, const std::string
&label
);
219 int TranslateBool(const std::string
&setting
);
220 bool GetBool(int setting
) const;
221 void SetBool(int setting
, bool set
);
223 /*! \brief Get the skin setting value as an integer value
224 * \param setting - the setting id
225 * \return the setting value as an integer, -1 if no conversion is possible
227 int GetInt(int setting
) const;
229 std::set
<CSkinSettingPtr
> GetSkinSettings() const;
230 CSkinSettingPtr
GetSkinSetting(const std::string
& settingId
);
231 std::shared_ptr
<const CSkinSetting
> GetSkinSetting(const std::string
& settingId
) const;
233 void Reset(const std::string
&setting
);
236 static std::set
<CSkinSettingPtr
> ParseSettings(const TiXmlElement
* rootElement
);
238 void OnPreInstall() override
;
239 void OnPostInstall(bool update
, bool modal
) override
;
241 // skin timer methods
243 /*! \brief Checks if the timer with name `timer` is running
244 \param timer the name of the skin timer
245 \return true if the given timer exists and is running, false otherwise
247 bool TimerIsRunning(const std::string
& timer
) const;
249 /*! \brief Get the elapsed seconds since the timer with name `timer` was started
250 \param timer the name of the skin timer
251 \return the elapsed time in seconds the given timer is running (0 if not running or if it does not exist)
253 float GetTimerElapsedSeconds(const std::string
& timer
) const;
255 /*! \brief Starts/Enables a given skin timer
256 \param timer the name of the skin timer
258 void TimerStart(const std::string
& timer
) const;
260 /*! \brief Stops/Disables a given skin timer
261 \param timer the name of the skin timer
263 void TimerStop(const std::string
& timer
) const;
266 bool LoadStartupWindows(const AddonInfoPtr
& addonInfo
);
268 static CSkinSettingPtr
ParseSetting(const TiXmlElement
* element
);
270 bool SettingsLoaded(AddonInstanceId id
= ADDON_SETTINGS_ID
) const override
;
271 bool SettingsFromXML(const CXBMCTinyXML
& doc
,
273 AddonInstanceId id
= ADDON_SETTINGS_ID
) override
;
274 bool SettingsToXML(CXBMCTinyXML
& doc
, AddonInstanceId id
= ADDON_SETTINGS_ID
) const override
;
276 RESOLUTION_INFO m_defaultRes
;
277 std::vector
<RESOLUTION_INFO
> m_resolutions
;
279 float m_effectsSlowDown
;
280 CGUIIncludes m_includes
;
281 std::string m_currentAspect
;
283 std::vector
<CStartupWindow
> m_startupWindows
;
286 /*! Manager/Owner of skin timers */
287 std::unique_ptr
<CSkinTimerManager
> m_skinTimerManager
;
290 std::map
<int, CSkinSettingStringPtr
> m_strings
;
291 std::map
<int, CSkinSettingBoolPtr
> m_bools
;
292 std::map
<std::string
, CSkinSettingPtr
> m_settings
;
293 std::unique_ptr
<CSkinSettingUpdateHandler
> m_settingsUpdateHandler
;
296 } /*namespace ADDON*/
298 extern std::shared_ptr
<ADDON::CSkinInfo
> g_SkinInfo
;