3 * Copyright (C) 2005-2013 Team XBMC
6 * This Program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or (at your option)
11 * This Program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with XBMC; see the file COPYING. If not, see
18 * <http://www.gnu.org/licenses/>.
23 #include "addons/AddonVersion.h"
24 #include "utils/XBMCTinyXML.h"
25 #include "guilib/LocalizeStrings.h"
26 #include "utils/ISerializable.h"
29 class CAddonCallbacksAddon;
31 typedef struct cp_plugin_info_t cp_plugin_info_t;
32 typedef struct cp_extension_t cp_extension_t;
36 typedef std::vector<AddonPtr> VECADDONS;
37 typedef std::vector<AddonPtr>::iterator IVECADDONS;
40 const CStdString TranslateType(const TYPE &type, bool pretty=false);
41 const CStdString GetIcon(const TYPE &type);
42 TYPE TranslateType(const CStdString &string);
43 const CStdString UpdateVideoScraper(const CStdString &scraper);
44 const CStdString UpdateMusicScraper(const CStdString &scraper);
46 class AddonProps : public ISerializable
49 AddonProps(const CStdString &id, TYPE type, const CStdString &versionstr, const CStdString &minversionstr)
53 , minversion(minversionstr)
58 AddonProps(const cp_extension_t *ext);
59 AddonProps(const cp_plugin_info_t *plugin);
61 bool operator==(const AddonProps &rhs)
63 return (*this).id == rhs.id
64 && (*this).type == rhs.type
65 && (*this).version == rhs.version;
68 void Serialize(CVariant &variant) const;
73 AddonVersion minversion;
77 CStdString description;
83 CStdString disclaimer;
86 ADDONDEPS dependencies;
91 void BuildDependencies(const cp_plugin_info_t *plugin);
94 typedef std::vector<class AddonProps> VECADDONPROPS;
96 class CAddon : public IAddon
99 CAddon(const AddonProps &addonprops);
100 CAddon(const cp_extension_t *ext);
101 CAddon(const cp_plugin_info_t *plugin);
103 virtual AddonPtr Clone() const;
105 /*! \brief Check whether the this addon can be configured or not
106 \return true if the addon has settings, false otherwise
107 \sa LoadSettings, LoadUserSettings, SaveSettings, HasUserSettings, GetSetting, UpdateSetting
111 /*! \brief Check whether the user has configured this addon or not
112 \return true if previously saved settings are found, false otherwise
113 \sa LoadSettings, LoadUserSettings, SaveSettings, HasSettings, GetSetting, UpdateSetting
115 bool HasUserSettings();
117 /*! \brief Save any user configured settings
118 \sa LoadSettings, LoadUserSettings, HasSettings, HasUserSettings, GetSetting, UpdateSetting
120 virtual void SaveSettings();
122 /*! \brief Update a user-configured setting with a new value
123 \param key the id of the setting to update
124 \param value the value that the setting should take
125 \sa LoadSettings, LoadUserSettings, SaveSettings, HasSettings, HasUserSettings, GetSetting
127 void UpdateSetting(const CStdString& key, const CStdString& value);
129 /*! \brief Retrieve a particular settings value
130 If a previously configured user setting is available, we return it's value, else we return the default (if available)
131 \param key the id of the setting to retrieve
132 \return the current value of the setting, or the default if the setting has yet to be configured.
133 \sa LoadSettings, LoadUserSettings, SaveSettings, HasSettings, HasUserSettings, UpdateSetting
135 virtual CStdString GetSetting(const CStdString& key);
137 TiXmlElement* GetSettingsXML();
138 virtual CStdString GetString(uint32_t id);
141 TYPE Type() const { return m_props.type; }
142 bool IsType(TYPE type) const { return type == m_props.type; }
143 AddonProps Props() const { return m_props; }
144 AddonProps& Props() { return m_props; }
145 const CStdString ID() const { return m_props.id; }
146 const CStdString Name() const { return m_props.name; }
147 bool Enabled() const { return m_enabled; }
148 virtual bool IsInUse() const { return false; };
149 const AddonVersion Version() const { return m_props.version; }
150 const AddonVersion MinVersion() const { return m_props.minversion; }
151 const CStdString Summary() const { return m_props.summary; }
152 const CStdString Description() const { return m_props.description; }
153 const CStdString Path() const { return m_props.path; }
154 const CStdString Profile() const { return m_profile; }
155 const CStdString LibPath() const;
156 const CStdString Author() const { return m_props.author; }
157 const CStdString ChangeLog() const { return m_props.changelog; }
158 const CStdString FanArt() const { return m_props.fanart; }
159 const CStdString Icon() const;
160 int Stars() const { return m_props.stars; }
161 const CStdString Disclaimer() const { return m_props.disclaimer; }
162 const InfoMap &ExtraInfo() const { return m_props.extrainfo; }
163 const ADDONDEPS &GetDeps() const { return m_props.dependencies; }
165 /*! \brief return whether or not this addon satisfies the given version requirements
166 \param version the version to meet.
167 \return true if min_version <= version <= current_version, false otherwise.
169 bool MeetsVersion(const AddonVersion &version) const;
170 virtual bool ReloadSettings();
172 void MarkAsDisabled() { m_enabled = false; }
175 friend class CAddonCallbacksAddon;
177 CAddon(const CAddon &rhs); // protected as all copying is handled by Clone()
178 virtual void BuildLibName(const cp_extension_t *ext = NULL);
180 /*! \brief Load the default settings and override these with any previously configured user settings
181 \param bForce force the load of settings even if they are already loaded (reload)
182 \return true if settings exist, false otherwise
183 \sa LoadUserSettings, SaveSettings, HasSettings, HasUserSettings, GetSetting, UpdateSetting
185 virtual bool LoadSettings(bool bForce = false);
187 /*! \brief Load the user settings
188 \return true if user settings exist, false otherwise
189 \sa LoadSettings, SaveSettings, HasSettings, HasUserSettings, GetSetting, UpdateSetting
191 bool LoadUserSettings();
193 /*! \brief Parse settings from an XML document
194 \param doc XML document to parse for settings
195 \param loadDefaults if true, the default attribute is used and settings are reset prior to parsing, else the value attribute is used.
196 \return true if settings are loaded, false otherwise
199 bool SettingsFromXML(const CXBMCTinyXML &doc, bool loadDefaults = false);
201 /*! \brief Parse settings into an XML document
202 \param doc XML document to receive the settings
205 void SettingsToXML(CXBMCTinyXML &doc) const;
207 CXBMCTinyXML m_addonXmlDoc;
208 CStdString m_strLibName;
209 bool m_settingsLoaded;
210 bool m_userSettingsLoaded;
213 friend class CAddonMgr;
215 CStdString m_userSettingsPath;
216 void BuildProfilePath();
218 virtual bool IsAddonLibrary() { return false; }
220 void Enable() { LoadStrings(); m_enabled = true; }
221 void Disable() { m_enabled = false; ClearStrings();}
223 virtual bool LoadStrings();
224 virtual void ClearStrings();
226 bool m_checkedStrings;
229 CStdString m_profile;
231 CLocalizeStrings m_strings;
232 std::map<CStdString, CStdString> m_settings;
235 class CAddonLibrary : public CAddon
238 CAddonLibrary(const AddonProps &props);
239 CAddonLibrary(const cp_extension_t *ext);
241 virtual AddonPtr Clone() const;
244 virtual bool IsAddonLibrary() { return true; }
246 const TYPE m_addonType; // addon type this library enhances
249 }; /* namespace ADDON */