summaryrefslogtreecommitdiffstats
path: root/xbmc/addons/Addon.h
diff options
context:
space:
mode:
authormanuel <manuel@mausz.at>2015-03-04 00:23:39 +0100
committermanuel <manuel@mausz.at>2015-03-04 00:23:39 +0100
commit9d11b08ad61b1f0d6d7023ce403285d8662efaed (patch)
tree5bc0c947d9e10d3e8c9dc1e6b26f3d6599f0cea1 /xbmc/addons/Addon.h
parentc159d9f91f1573901868100a9464527a5a71575b (diff)
downloadkodi-pvr-build-9d11b08ad61b1f0d6d7023ce403285d8662efaed.tar.gz
kodi-pvr-build-9d11b08ad61b1f0d6d7023ce403285d8662efaed.tar.bz2
kodi-pvr-build-9d11b08ad61b1f0d6d7023ce403285d8662efaed.zip
sync with upstream
Diffstat (limited to 'xbmc/addons/Addon.h')
-rw-r--r--xbmc/addons/Addon.h278
1 files changed, 0 insertions, 278 deletions
diff --git a/xbmc/addons/Addon.h b/xbmc/addons/Addon.h
deleted file mode 100644
index 4fbf085..0000000
--- a/xbmc/addons/Addon.h
+++ /dev/null
@@ -1,278 +0,0 @@
1#pragma once
2/*
3 * Copyright (C) 2005-2013 Team XBMC
4 * http://xbmc.org
5 *
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)
9 * any later version.
10 *
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.
15 *
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/>.
19 *
20 */
21
22#include "IAddon.h"
23#include "addons/AddonVersion.h"
24#include "utils/XBMCTinyXML.h"
25#include "guilib/LocalizeStrings.h"
26#include "utils/ISerializable.h"
27#include <vector>
28
29class TiXmlElement;
30class CAddonCallbacksAddon;
31
32typedef struct cp_plugin_info_t cp_plugin_info_t;
33typedef struct cp_extension_t cp_extension_t;
34
35namespace ADDON
36{
37 typedef std::vector<AddonPtr> VECADDONS;
38 typedef std::vector<AddonPtr>::iterator IVECADDONS;
39
40// utils
41const std::string TranslateType(const TYPE &type, bool pretty=false);
42const std::string GetIcon(const TYPE &type);
43 TYPE TranslateType(const std::string &string);
44
45class AddonProps : public ISerializable
46{
47public:
48 AddonProps(const std::string &id, TYPE type, const std::string &versionstr, const std::string &minversionstr)
49 : id(id)
50 , type(type)
51 , version(versionstr)
52 , minversion(minversionstr)
53 , stars(0)
54 {
55 }
56
57 virtual ~AddonProps() {}
58
59 AddonProps(const cp_extension_t *ext);
60 AddonProps(const cp_plugin_info_t *plugin);
61
62 bool operator==(const AddonProps &rhs)
63 {
64 return (*this).id == rhs.id
65 && (*this).type == rhs.type
66 && (*this).version == rhs.version;
67 }
68
69 void Serialize(CVariant &variant) const;
70
71 std::string id;
72 TYPE type;
73 AddonVersion version;
74 AddonVersion minversion;
75 std::string name;
76 std::string license;
77 std::string summary;
78 std::string description;
79 std::string path;
80 std::string libname;
81 std::string author;
82 std::string source;
83 std::string icon;
84 std::string disclaimer;
85 std::string changelog;
86 std::string fanart;
87 ADDONDEPS dependencies;
88 std::string broken;
89 InfoMap extrainfo;
90 int stars;
91private:
92 void BuildDependencies(const cp_plugin_info_t *plugin);
93};
94
95typedef std::vector<class AddonProps> VECADDONPROPS;
96
97class CAddon : public IAddon
98{
99public:
100 CAddon(const AddonProps &addonprops);
101 CAddon(const cp_extension_t *ext);
102 CAddon(const cp_plugin_info_t *plugin);
103 virtual ~CAddon() {}
104 virtual AddonPtr Clone() const;
105
106 /*! \brief Check whether the this addon can be configured or not
107 \return true if the addon has settings, false otherwise
108 \sa LoadSettings, LoadUserSettings, SaveSettings, HasUserSettings, GetSetting, UpdateSetting
109 */
110 bool HasSettings();
111
112 /*! \brief Check whether the user has configured this addon or not
113 \return true if previously saved settings are found, false otherwise
114 \sa LoadSettings, LoadUserSettings, SaveSettings, HasSettings, GetSetting, UpdateSetting
115 */
116 bool HasUserSettings();
117
118 /*! \brief Save any user configured settings
119 \sa LoadSettings, LoadUserSettings, HasSettings, HasUserSettings, GetSetting, UpdateSetting
120 */
121 virtual void SaveSettings();
122
123 /*! \brief Update a user-configured setting with a new value
124 \param key the id of the setting to update
125 \param value the value that the setting should take
126 \sa LoadSettings, LoadUserSettings, SaveSettings, HasSettings, HasUserSettings, GetSetting
127 */
128 void UpdateSetting(const std::string& key, const std::string& value);
129
130 /*! \brief Retrieve a particular settings value
131 If a previously configured user setting is available, we return it's value, else we return the default (if available)
132 \param key the id of the setting to retrieve
133 \return the current value of the setting, or the default if the setting has yet to be configured.
134 \sa LoadSettings, LoadUserSettings, SaveSettings, HasSettings, HasUserSettings, UpdateSetting
135 */
136 virtual std::string GetSetting(const std::string& key);
137
138 TiXmlElement* GetSettingsXML();
139 virtual std::string GetString(uint32_t id);
140
141 // properties
142 TYPE Type() const { return m_props.type; }
143 bool IsType(TYPE type) const { return type == m_props.type; }
144 AddonProps Props() const { return m_props; }
145 AddonProps& Props() { return m_props; }
146 const std::string ID() const { return m_props.id; }
147 const std::string Name() const { return m_props.name; }
148 bool Enabled() const { return m_enabled; }
149 virtual bool IsInUse() const { return false; };
150 const AddonVersion Version() const { return m_props.version; }
151 const AddonVersion MinVersion() const { return m_props.minversion; }
152 const std::string Summary() const { return m_props.summary; }
153 const std::string Description() const { return m_props.description; }
154 const std::string Path() const { return m_props.path; }
155 const std::string Profile() const { return m_profile; }
156 const std::string LibPath() const;
157 const std::string Author() const { return m_props.author; }
158 const std::string ChangeLog() const { return m_props.changelog; }
159 const std::string FanArt() const { return m_props.fanart; }
160 const std::string Icon() const;
161 int Stars() const { return m_props.stars; }
162 const std::string Disclaimer() const { return m_props.disclaimer; }
163 const InfoMap &ExtraInfo() const { return m_props.extrainfo; }
164 const ADDONDEPS &GetDeps() const { return m_props.dependencies; }
165
166 /*! \brief get the required version of a dependency.
167 \param dependencyID the addon ID of the dependency.
168 \return the version this addon requires.
169 */
170 AddonVersion GetDependencyVersion(const std::string &dependencyID) const;
171
172 /*! \brief return whether or not this addon satisfies the given version requirements
173 \param version the version to meet.
174 \return true if min_version <= version <= current_version, false otherwise.
175 */
176 bool MeetsVersion(const AddonVersion &version) const;
177 virtual bool ReloadSettings();
178
179 void MarkAsDisabled() { m_enabled = false; }
180
181 /*! \brief callback for when this add-on is disabled.
182 Use to perform any needed actions (e.g. stop a service)
183 */
184 virtual void OnDisabled() {};
185
186 /*! \brief callback for when this add-on is enabled.
187 Use to perform any needed actions (e.g. start a service)
188 */
189 virtual void OnEnabled() {};
190
191 /*! \brief retrieve the running instance of an add-on if it persists while running.
192 */
193 virtual AddonPtr GetRunningInstance() const { return AddonPtr(); }
194
195 /*! \brief callbacks for special install/uninstall behaviour */
196 virtual bool OnPreInstall() { return false; };
197 virtual void OnPostInstall(bool restart, bool update, bool modal) {};
198 virtual void OnPreUnInstall() {};
199 virtual void OnPostUnInstall() {};
200 virtual bool CanInstall(const std::string& referer) { return true; }
201protected:
202 friend class CAddonCallbacksAddon;
203
204 CAddon(const CAddon &rhs); // protected as all copying is handled by Clone()
205 virtual void BuildLibName(const cp_extension_t *ext = NULL);
206
207 /*! \brief Load the default settings and override these with any previously configured user settings
208 \param bForce force the load of settings even if they are already loaded (reload)
209 \return true if settings exist, false otherwise
210 \sa LoadUserSettings, SaveSettings, HasSettings, HasUserSettings, GetSetting, UpdateSetting
211 */
212 virtual bool LoadSettings(bool bForce = false);
213
214 /*! \brief Load the user settings
215 \return true if user settings exist, false otherwise
216 \sa LoadSettings, SaveSettings, HasSettings, HasUserSettings, GetSetting, UpdateSetting
217 */
218 bool LoadUserSettings();
219
220 /*! \brief Parse settings from an XML document
221 \param doc XML document to parse for settings
222 \param loadDefaults if true, the default attribute is used and settings are reset prior to parsing, else the value attribute is used.
223 \return true if settings are loaded, false otherwise
224 \sa SettingsToXML
225 */
226 bool SettingsFromXML(const CXBMCTinyXML &doc, bool loadDefaults = false);
227
228 /*! \brief Parse settings into an XML document
229 \param doc XML document to receive the settings
230 \sa SettingsFromXML
231 */
232 void SettingsToXML(CXBMCTinyXML &doc) const;
233
234 CXBMCTinyXML m_addonXmlDoc;
235 std::string m_strLibName;
236 bool m_settingsLoaded;
237 bool m_userSettingsLoaded;
238
239 virtual void ClearStrings();
240private:
241 friend class CAddonMgr;
242 AddonProps m_props;
243 std::string m_userSettingsPath;
244 void BuildProfilePath();
245
246 virtual bool IsAddonLibrary() { return false; }
247
248 void Enable() { LoadStrings(); m_enabled = true; }
249 void Disable() { m_enabled = false; ClearStrings();}
250
251 virtual bool LoadStrings();
252
253 bool m_hasStrings;
254 bool m_checkedStrings;
255 bool m_hasSettings;
256
257 std::string m_profile;
258 bool m_enabled;
259 CLocalizeStrings m_strings;
260 std::map<std::string, std::string> m_settings;
261};
262
263class CAddonLibrary : public CAddon
264{
265public:
266 CAddonLibrary(const AddonProps &props);
267 CAddonLibrary(const cp_extension_t *ext);
268
269 virtual AddonPtr Clone() const;
270
271private:
272 virtual bool IsAddonLibrary() { return true; }
273 TYPE SetAddonType();
274 const TYPE m_addonType; // addon type this library enhances
275};
276
277}; /* namespace ADDON */
278