Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 681 lines (607 sloc) 19.08 kb
074db86 merged: addons-fw branch
elupus authored
1 /*
2 * Copyright (C) 2005-2009 Team XBMC
3 * http://www.xbmc.org
4 *
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
8 * any later version.
9 *
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with XBMC; see the file COPYING. If not, write to
17 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 */
21 #include "AddonManager.h"
22 #include "Addon.h"
1b2781c added: basic cpluff support
alcoheca authored
23 #include "DllLibCPluff.h"
074db86 merged: addons-fw branch
elupus authored
24 #include "StringUtils.h"
25 #include "RegExp.h"
26 #include "XMLUtils.h"
639b314 changed: move addonbrowser to a mediawindow derivate
spiff_ authored
27 #include "utils/JobManager.h"
28 #include "utils/SingleLock.h"
074db86 merged: addons-fw branch
elupus authored
29 #include "FileItem.h"
822ca91 added: translatable <description>, <title>, <summary> and <disclaimer> i...
spiff_ authored
30 #include "LangInfo.h"
074db86 merged: addons-fw branch
elupus authored
31 #include "Settings.h"
32 #include "GUISettings.h"
33 #include "DownloadQueueManager.h"
1b2781c added: basic cpluff support
alcoheca authored
34 #include "AdvancedSettings.h"
dacdca0 changed: moved CAddonStatusHandler to separate files
alcoheca authored
35 #include "log.h"
074db86 merged: addons-fw branch
elupus authored
36
37 #ifdef HAS_VISUALISATION
055f806 cosmetic/tidyup move all addon classes to /xbmc/addons/
alcoheca authored
38 #include "DllVisualisation.h"
39 #include "Visualisation.h"
074db86 merged: addons-fw branch
elupus authored
40 #endif
41 #ifdef HAS_SCREENSAVER
055f806 cosmetic/tidyup move all addon classes to /xbmc/addons/
alcoheca authored
42 #include "DllScreenSaver.h"
43 #include "ScreenSaver.h"
074db86 merged: addons-fw branch
elupus authored
44 #endif
45 //#ifdef HAS_SCRAPERS
055f806 cosmetic/tidyup move all addon classes to /xbmc/addons/
alcoheca authored
46 #include "Scraper.h"
074db86 merged: addons-fw branch
elupus authored
47 //#endif
16b848a added: CPluginSource class for all pluginsource addons
alcoheca authored
48 #include "PluginSource.h"
606248f added: addon repository class
spiff_ authored
49 #include "Repository.h"
553d213 changed: finished moving skins to addon framework
alcoheca authored
50 #include "Skin.h"
af8cb2a Revert "wip"
alcoheca authored
51
88e9b6f changed: expand std namespace
spiff_ authored
52 using namespace std;
53
074db86 merged: addons-fw branch
elupus authored
54 namespace ADDON
55 {
56
b6f0f59 cleanup: Don't expose the AddonManager's privates when not required.
jmarshallnz authored
57 cp_log_severity_t clog_to_cp(int lvl);
58 void cp_fatalErrorHandler(const char *msg);
59 void cp_logger(cp_log_severity_t level, const char *msg, const char *apid, void *user_data);
16b848a added: CPluginSource class for all pluginsource addons
alcoheca authored
60 bool GetExtElementDeque(DEQUEELEMENTS &elements, cp_cfg_element_t *base, const char *path);
074db86 merged: addons-fw branch
elupus authored
61
62 /**********************************************************
63 * CAddonMgr
64 *
65 */
66
88e9b6f changed: expand std namespace
spiff_ authored
67 map<TYPE, IAddonMgrCallback*> CAddonMgr::m_managers;
074db86 merged: addons-fw branch
elupus authored
68
c14bf20 changed: moved addonptr factory to CAddonMgr.
alcoheca authored
69 AddonPtr CAddonMgr::Factory(const cp_extension_t *props)
1b2781c added: basic cpluff support
alcoheca authored
70 {
2bf2640 added: Functions for sanity checking addons (platform checks and ignorin...
jmarshallnz authored
71 if (!PlatformSupportsAddon(props->plugin))
72 return AddonPtr();
73
bb4e01c Support creating userdirs in addons. This also has the benefit of being ...
ceros7 authored
74 /* Check if user directories need to be created */
2bf2640 added: Functions for sanity checking addons (platform checks and ignorin...
jmarshallnz authored
75 const cp_cfg_element_t *settings = GetExtElement(props->configuration, "settings");
bb4e01c Support creating userdirs in addons. This also has the benefit of being ...
ceros7 authored
76 if (settings)
77 CheckUserDirs(settings);
78
1b2781c added: basic cpluff support
alcoheca authored
79 const TYPE type = TranslateType(props->ext_point_id);
80 switch (type)
81 {
82 case ADDON_PLUGIN:
fa2b463 cleanup: move pluginsource <provides> tag reading to use xs:list and put...
jmarshallnz authored
83 return AddonPtr(new CPluginSource(props));
1b2781c added: basic cpluff support
alcoheca authored
84 case ADDON_SCRIPT:
35cf15f changed: get rid of the content types added earlier, favouring extension...
jmarshallnz authored
85 case ADDON_SCRIPT_LIBRARY:
86 case ADDON_SCRIPT_LYRICS:
87 case ADDON_SCRIPT_WEATHER:
88 case ADDON_SCRIPT_SUBTITLES:
257d969 changed: Move Addon constructors to take the extension point they're act...
jmarshallnz authored
89 return AddonPtr(new CAddon(props));
6a9704f changed: Split scrapers into separate extension points per content type....
jmarshallnz authored
90 case ADDON_SCRAPER_ALBUMS:
91 case ADDON_SCRAPER_ARTISTS:
92 case ADDON_SCRAPER_MOVIES:
93 case ADDON_SCRAPER_MUSICVIDEOS:
94 case ADDON_SCRAPER_TVSHOWS:
95 case ADDON_SCRAPER_LIBRARY:
257d969 changed: Move Addon constructors to take the extension point they're act...
jmarshallnz authored
96 return AddonPtr(new CScraper(props));
1b2781c added: basic cpluff support
alcoheca authored
97 case ADDON_VIZ:
98 case ADDON_SCREENSAVER:
c14bf20 changed: moved addonptr factory to CAddonMgr.
alcoheca authored
99 { // begin temporary platform handling for Dlls
100 // ideally platforms issues will be handled by C-Pluff
101 // this is not an attempt at a solution
102 CStdString value;
0cefd50 changed: Moved builtin screensavers to addons so that we can utilize the...
jmarshallnz authored
103 if (type == ADDON_SCREENSAVER && 0 == strnicmp(props->plugin->identifier, "screensaver.xbmc.builtin.", 25))
104 { // built in screensaver
105 return AddonPtr(new CAddon(props));
106 }
c14bf20 changed: moved addonptr factory to CAddonMgr.
alcoheca authored
107 #if defined(_LINUX) && !defined(__APPLE__)
108 if ((value = GetExtValue(props->plugin->extensions->configuration, "@library_linux")) && value.empty())
109 break;
110 #elif defined(_WIN32) && defined(HAS_SDL_OPENGL)
111 if ((value = GetExtValue(props->plugin->extensions->configuration, "@library_wingl")) && value.empty())
112 break;
113 #elif defined(_WIN32) && defined(HAS_DX)
114 if ((value = GetExtValue(props->plugin->extensions->configuration, "@library_windx")) && value.empty())
115 break;
116 #elif defined(__APPLE__)
117 if ((value = GetExtValue(props->plugin->extensions->configuration, "@library_osx")) && value.empty())
118 break;
119 #elif defined(_XBOX)
120 if ((value = GetExtValue(props->plugin->extensions->configuration, "@library_xbox")) && value.empty())
121 break;
122 #endif
123 if (type == ADDON_VIZ)
07e5742 [arm] merge arm-camelot into trunk, thanks to mcgeagh for all his hard w...
davilla authored
124 {
125 #if defined(HAS_VISUALISATION)
257d969 changed: Move Addon constructors to take the extension point they're act...
jmarshallnz authored
126 return AddonPtr(new CVisualisation(props));
07e5742 [arm] merge arm-camelot into trunk, thanks to mcgeagh for all his hard w...
davilla authored
127 #endif
128 }
c14bf20 changed: moved addonptr factory to CAddonMgr.
alcoheca authored
129 else
257d969 changed: Move Addon constructors to take the extension point they're act...
jmarshallnz authored
130 return AddonPtr(new CScreenSaver(props));
c14bf20 changed: moved addonptr factory to CAddonMgr.
alcoheca authored
131 }
5ff028a added: skin support via cpluff
alcoheca authored
132 case ADDON_SKIN:
257d969 changed: Move Addon constructors to take the extension point they're act...
jmarshallnz authored
133 return AddonPtr(new CSkinInfo(props));
1b2781c added: basic cpluff support
alcoheca authored
134 case ADDON_VIZ_LIBRARY:
257d969 changed: Move Addon constructors to take the extension point they're act...
jmarshallnz authored
135 return AddonPtr(new CAddonLibrary(props));
9ea9065 changed: Move repositories to cpluff
jmarshallnz authored
136 case ADDON_REPOSITORY:
257d969 changed: Move Addon constructors to take the extension point they're act...
jmarshallnz authored
137 return AddonPtr(new CRepository(props));
1b2781c added: basic cpluff support
alcoheca authored
138 default:
c14bf20 changed: moved addonptr factory to CAddonMgr.
alcoheca authored
139 break;
1b2781c added: basic cpluff support
alcoheca authored
140 }
c14bf20 changed: moved addonptr factory to CAddonMgr.
alcoheca authored
141 return AddonPtr();
1b2781c added: basic cpluff support
alcoheca authored
142 }
143
bb4e01c Support creating userdirs in addons. This also has the benefit of being ...
ceros7 authored
144 bool CAddonMgr::CheckUserDirs(const cp_cfg_element_t *settings)
145 {
146 if (!settings)
147 return false;
148
149 const cp_cfg_element_t *userdirs = GetExtElement((cp_cfg_element_t *)settings, "userdirs");
150 if (!userdirs)
151 return false;
152
153 DEQUEELEMENTS elements;
154 bool status = GetExtElementDeque(elements, (cp_cfg_element_t *)userdirs, "userdir");
155 if (!status)
156 return false;
157
158 IDEQUEELEMENTS itr = elements.begin();
159 while (itr != elements.end())
160 {
161 CStdString path = GetExtValue(*itr++, "@path");
162 if (!CFile::Exists(path))
163 {
164 if (!CUtil::CreateDirectoryEx(path))
165 {
166 CLog::Log(LOGERROR, "CAddonMgr::CheckUserDirs: Unable to create directory %s.", path.c_str());
167 return false;
168 }
169 }
170 }
171
172 return true;
173 }
174
074db86 merged: addons-fw branch
elupus authored
175 CAddonMgr::CAddonMgr()
176 {
639b314 changed: move addonbrowser to a mediawindow derivate
spiff_ authored
177 m_watch.StartZero();
074db86 merged: addons-fw branch
elupus authored
178 }
179
180 CAddonMgr::~CAddonMgr()
181 {
37a994e added: Deinit to the addons manager to ensure we unload cpluff prior to ...
jmarshallnz authored
182 DeInit();
074db86 merged: addons-fw branch
elupus authored
183 }
184
47a8196 changed: matched other singelton calls
alcoheca authored
185 CAddonMgr &CAddonMgr::Get()
074db86 merged: addons-fw branch
elupus authored
186 {
47a8196 changed: matched other singelton calls
alcoheca authored
187 static CAddonMgr sAddonMgr;
188 return sAddonMgr;
074db86 merged: addons-fw branch
elupus authored
189 }
190
191 IAddonMgrCallback* CAddonMgr::GetCallbackForType(TYPE type)
192 {
193 if (m_managers.find(type) == m_managers.end())
194 return NULL;
195 else
196 return m_managers[type];
197 }
198
199 bool CAddonMgr::RegisterAddonMgrCallback(const TYPE type, IAddonMgrCallback* cb)
200 {
201 if (cb == NULL)
202 return false;
203
204 m_managers.erase(type);
205 m_managers[type] = cb;
206
207 return true;
208 }
209
210 void CAddonMgr::UnregisterAddonMgrCallback(TYPE type)
211 {
212 m_managers.erase(type);
213 }
214
1b2781c added: basic cpluff support
alcoheca authored
215 bool CAddonMgr::Init()
216 {
217 m_cpluff = new DllLibCPluff;
218 m_cpluff->Load();
219
b700e3f changed: Hold the addons database as a member in the AddonManager. Shou...
jmarshallnz authored
220 m_database.Open();
221
1b2781c added: basic cpluff support
alcoheca authored
222 if (!m_cpluff->IsLoaded())
223 {
b6076e5 changed: screensavers are now supported via cpluff schema
alcoheca authored
224 CLog::Log(LOGERROR, "ADDONS: Fatal Error, could not load libcpluff");
225 return false;
1b2781c added: basic cpluff support
alcoheca authored
226 }
227
228 m_cpluff->set_fatal_error_handler(cp_fatalErrorHandler);
229
230 cp_status_t status;
231 status = m_cpluff->init();
232 if (status != CP_OK)
233 {
234 CLog::Log(LOGERROR, "ADDONS: Fatal Error, cp_init() returned status: %i", status);
b6076e5 changed: screensavers are now supported via cpluff schema
alcoheca authored
235 return false;
1b2781c added: basic cpluff support
alcoheca authored
236 }
237
238 //TODO could separate addons into different contexts
239 // would allow partial unloading of addon framework
240 m_cp_context = m_cpluff->create_context(&status);
241 assert(m_cp_context);
7cef07e cleanup: remove unused XBMCIsHome function, now that they're no longer t...
jmarshallnz authored
242 status = m_cpluff->register_pcollection(m_cp_context, _P("special://home/addons"));
b6076e5 changed: screensavers are now supported via cpluff schema
alcoheca authored
243 status = m_cpluff->register_pcollection(m_cp_context, _P("special://xbmc/addons"));
244 if (status != CP_OK)
245 {
246 CLog::Log(LOGERROR, "ADDONS: Fatal Error, cp_register_pcollection() returned status: %i", status);
247 return false;
1b2781c added: basic cpluff support
alcoheca authored
248 }
b6076e5 changed: screensavers are now supported via cpluff schema
alcoheca authored
249
185686a added: even more missing from r29798
alcoheca authored
250 status = m_cpluff->register_logger(m_cp_context, cp_logger,
7188808 changed: bail out immeditaly if CAddonMgr::Init returns false
alcoheca authored
251 &CAddonMgr::Get(), clog_to_cp(g_advancedSettings.m_logLevel));
b6076e5 changed: screensavers are now supported via cpluff schema
alcoheca authored
252 if (status != CP_OK)
253 {
254 CLog::Log(LOGERROR, "ADDONS: Fatal Error, cp_register_logger() returned status: %i", status);
255 return false;
256 }
1b2781c added: basic cpluff support
alcoheca authored
257
f0b69e1 changed: move the cpluff plugin scanner call to findaddons
spiff_ authored
258 FindAddons();
b6076e5 changed: screensavers are now supported via cpluff schema
alcoheca authored
259 return true;
1b2781c added: basic cpluff support
alcoheca authored
260 }
261
37a994e added: Deinit to the addons manager to ensure we unload cpluff prior to ...
jmarshallnz authored
262 void CAddonMgr::DeInit()
263 {
264 if (m_cpluff)
265 m_cpluff->destroy();
266 m_cpluff = NULL;
b700e3f changed: Hold the addons database as a member in the AddonManager. Shou...
jmarshallnz authored
267 m_database.Close();
37a994e added: Deinit to the addons manager to ensure we unload cpluff prior to ...
jmarshallnz authored
268 }
269
56aa69b added: Support for addons to be disabled while still being installed.
jmarshallnz authored
270 bool CAddonMgr::HasAddons(const TYPE &type, bool enabled /*= true*/)
074db86 merged: addons-fw branch
elupus authored
271 {
7672f26 fixed: Ensure HasAddons respects the content type.
jmarshallnz authored
272 // TODO: This isn't particularly efficient as we create an addon type for each addon using the Factory, just so
273 // we can check addon dependencies in the addon constructor.
274 VECADDONS addons;
56aa69b added: Support for addons to be disabled while still being installed.
jmarshallnz authored
275 return GetAddons(type, addons, enabled);
074db86 merged: addons-fw branch
elupus authored
276 }
277
56aa69b added: Support for addons to be disabled while still being installed.
jmarshallnz authored
278 bool CAddonMgr::GetAllAddons(VECADDONS &addons, bool enabled /*= true*/)
074db86 merged: addons-fw branch
elupus authored
279 {
816cf12 fixed: Get weather, subtitles, lyrics and library scripts to show up in ...
jmarshallnz authored
280 for (int i = ADDON_UNKNOWN+1; i < ADDON_VIZ_LIBRARY; ++i)
281 {
282 if (ADDON_REPOSITORY == (TYPE)i)
283 continue;
284 VECADDONS temp;
56aa69b added: Support for addons to be disabled while still being installed.
jmarshallnz authored
285 if (CAddonMgr::Get().GetAddons((TYPE)i, temp, enabled))
816cf12 fixed: Get weather, subtitles, lyrics and library scripts to show up in ...
jmarshallnz authored
286 addons.insert(addons.end(), temp.begin(), temp.end());
287 }
af8cb2a Revert "wip"
alcoheca authored
288 return !addons.empty();
074db86 merged: addons-fw branch
elupus authored
289 }
290
56aa69b added: Support for addons to be disabled while still being installed.
jmarshallnz authored
291 bool CAddonMgr::GetAddons(const TYPE &type, VECADDONS &addons, bool enabled /* = true */)
074db86 merged: addons-fw branch
elupus authored
292 {
4e5b98a added: locks to addon manager
spiff_ authored
293 CSingleLock lock(m_critSection);
af8cb2a Revert "wip"
alcoheca authored
294 addons.clear();
8c86aee cleanup: Get rid of some more old non-cpluff stuff. Should also fix add...
jmarshallnz authored
295 cp_status_t status;
296 int num;
297 CStdString ext_point(TranslateType(type));
298 cp_extension_t **exts = m_cpluff->get_extensions_info(m_cp_context, ext_point.c_str(), &status, &num);
299 for(int i=0; i <num; i++)
af8cb2a Revert "wip"
alcoheca authored
300 {
8c86aee cleanup: Get rid of some more old non-cpluff stuff. Should also fix add...
jmarshallnz authored
301 AddonPtr addon(Factory(exts[i]));
b700e3f changed: Hold the addons database as a member in the AddonManager. Shou...
jmarshallnz authored
302 if (addon && m_database.IsAddonDisabled(addon->ID()) != enabled)
8c86aee cleanup: Get rid of some more old non-cpluff stuff. Should also fix add...
jmarshallnz authored
303 addons.push_back(addon);
af8cb2a Revert "wip"
alcoheca authored
304 }
8c86aee cleanup: Get rid of some more old non-cpluff stuff. Should also fix add...
jmarshallnz authored
305 m_cpluff->release_info(m_cp_context, exts);
306 return addons.size() > 0;
074db86 merged: addons-fw branch
elupus authored
307 }
308
56aa69b added: Support for addons to be disabled while still being installed.
jmarshallnz authored
309 bool CAddonMgr::GetAddon(const CStdString &str, AddonPtr &addon, const TYPE &type/*=ADDON_UNKNOWN*/, bool enabled/*= true*/)
074db86 merged: addons-fw branch
elupus authored
310 {
4e5b98a added: locks to addon manager
spiff_ authored
311 CSingleLock lock(m_critSection);
074db86 merged: addons-fw branch
elupus authored
312
c22f535 cosmetics
alcoheca authored
313 cp_status_t status;
84824e3 cosmetics
spiff_ authored
314 cp_plugin_info_t *cpaddon = m_cpluff->get_plugin_info(m_cp_context, str.c_str(), &status);
2bf2640 added: Functions for sanity checking addons (platform checks and ignorin...
jmarshallnz authored
315 if (status == CP_OK && cpaddon)
c22f535 cosmetics
alcoheca authored
316 {
2bf2640 added: Functions for sanity checking addons (platform checks and ignorin...
jmarshallnz authored
317 addon = GetAddonFromDescriptor(cpaddon);
c22f535 cosmetics
alcoheca authored
318 m_cpluff->release_info(m_cp_context, cpaddon);
b700e3f changed: Hold the addons database as a member in the AddonManager. Shou...
jmarshallnz authored
319 return NULL != addon.get() && m_database.IsAddonDisabled(addon->ID()) != enabled;
c22f535 cosmetics
alcoheca authored
320 }
321 if (cpaddon)
322 m_cpluff->release_info(m_cp_context, cpaddon);
b6076e5 changed: screensavers are now supported via cpluff schema
alcoheca authored
323
074db86 merged: addons-fw branch
elupus authored
324 return false;
325 }
326
327 //TODO handle all 'default' cases here, not just scrapers & vizs
257d969 changed: Move Addon constructors to take the extension point they're act...
jmarshallnz authored
328 bool CAddonMgr::GetDefault(const TYPE &type, AddonPtr &addon)
074db86 merged: addons-fw branch
elupus authored
329 {
330 CStdString setting;
6a9704f changed: Split scrapers into separate extension points per content type....
jmarshallnz authored
331 switch (type)
074db86 merged: addons-fw branch
elupus authored
332 {
6a9704f changed: Split scrapers into separate extension points per content type....
jmarshallnz authored
333 case ADDON_VIZ:
334 setting = g_guiSettings.GetString("musicplayer.visualisation");
335 break;
336 case ADDON_SCRAPER_ALBUMS:
c077443 changed: Split the music scraping into separate album and artist scraper...
jmarshallnz authored
337 setting = g_guiSettings.GetString("musiclibrary.albumscraper");
338 break;
6a9704f changed: Split scrapers into separate extension points per content type....
jmarshallnz authored
339 case ADDON_SCRAPER_ARTISTS:
c077443 changed: Split the music scraping into separate album and artist scraper...
jmarshallnz authored
340 setting = g_guiSettings.GetString("musiclibrary.artistscraper");
6a9704f changed: Split scrapers into separate extension points per content type....
jmarshallnz authored
341 break;
342 case ADDON_SCRAPER_MOVIES:
343 setting = g_guiSettings.GetString("scrapers.moviedefault");
344 break;
345 case ADDON_SCRAPER_MUSICVIDEOS:
346 setting = g_guiSettings.GetString("scrapers.musicvideodefault");
347 break;
348 case ADDON_SCRAPER_TVSHOWS:
349 setting = g_guiSettings.GetString("scrapers.tvshowdefault");
350 break;
351 default:
352 return false;
074db86 merged: addons-fw branch
elupus authored
353 }
2ca76f9 changed: all addons should be store below either special://home/addons o...
alcoheca authored
354 return GetAddon(setting, addon, type);
074db86 merged: addons-fw branch
elupus authored
355 }
356
7411555 changed: renamed UUID to ID. we now accept any string as an identifier,
alcoheca authored
357 CStdString CAddonMgr::GetString(const CStdString &id, const int number)
074db86 merged: addons-fw branch
elupus authored
358 {
8c86aee cleanup: Get rid of some more old non-cpluff stuff. Should also fix add...
jmarshallnz authored
359 AddonPtr addon;
360 if (GetAddon(id, addon))
074db86 merged: addons-fw branch
elupus authored
361 return addon->GetString(number);
362
363 return "";
364 }
365
af8cb2a Revert "wip"
alcoheca authored
366 void CAddonMgr::FindAddons()
367 {
4e5b98a added: locks to addon manager
spiff_ authored
368 CSingleLock lock(m_critSection);
f0b69e1 changed: move the cpluff plugin scanner call to findaddons
spiff_ authored
369 if (m_cpluff && m_cp_context)
d8d145c fixed: update addon information after upgrade
ametovic authored
370 m_cpluff->scan_plugins(m_cp_context, CP_SP_UPGRADE);
535b4e7 changed: load addons from user directory first, then load from system di...
elupus authored
371 }
372
f1031c4 fixed: disabling addons
spiff_ authored
373 void CAddonMgr::RemoveAddon(const CStdString& ID)
374 {
375 if (m_cpluff && m_cp_context)
376 m_cpluff->uninstall_plugin(m_cp_context,ID.c_str());
377 }
378
096e8a3 changed: Move description information into addon.xml via the xbmc.addon....
jmarshallnz authored
379 const char *CAddonMgr::GetTranslatedString(const cp_cfg_element_t *root, const char *tag)
380 {
381 if (!root)
382 return NULL;
383
384 const cp_cfg_element_t *eng = NULL;
385 for (unsigned int i = 0; i < root->num_children; i++)
386 {
387 const cp_cfg_element_t &child = root->children[i];
388 if (strcmp(tag, child.name) == 0)
389 { // see if we have a "lang" attribute
390 const char *lang = m_cpluff->lookup_cfg_value((cp_cfg_element_t*)&child, "@lang");
391 if (lang && 0 == strcmp(lang,g_langInfo.GetDVDAudioLanguage().c_str()))
392 return child.value;
393 if (!lang || 0 == strcmp(lang, "en"))
394 eng = &child;
395 }
396 }
397 return (eng) ? eng->value : NULL;
398 }
399
eca3c5b changed: refactor
spiff_ authored
400 AddonPtr CAddonMgr::AddonFromProps(AddonProps& addonProps)
401 {
402 switch (addonProps.type)
af8cb2a Revert "wip"
alcoheca authored
403 {
404 case ADDON_PLUGIN:
16b848a added: CPluginSource class for all pluginsource addons
alcoheca authored
405 return AddonPtr(new CPluginSource(addonProps));
af8cb2a Revert "wip"
alcoheca authored
406 case ADDON_SCRIPT:
35cf15f changed: get rid of the content types added earlier, favouring extension...
jmarshallnz authored
407 case ADDON_SCRIPT_LIBRARY:
408 case ADDON_SCRIPT_LYRICS:
409 case ADDON_SCRIPT_WEATHER:
410 case ADDON_SCRIPT_SUBTITLES:
eca3c5b changed: refactor
spiff_ authored
411 return AddonPtr(new CAddon(addonProps));
6a9704f changed: Split scrapers into separate extension points per content type....
jmarshallnz authored
412 case ADDON_SCRAPER_ALBUMS:
413 case ADDON_SCRAPER_ARTISTS:
414 case ADDON_SCRAPER_MOVIES:
415 case ADDON_SCRAPER_MUSICVIDEOS:
416 case ADDON_SCRAPER_TVSHOWS:
417 case ADDON_SCRAPER_LIBRARY:
eca3c5b changed: refactor
spiff_ authored
418 return AddonPtr(new CScraper(addonProps));
553d213 changed: finished moving skins to addon framework
alcoheca authored
419 case ADDON_SKIN:
420 return AddonPtr(new CSkinInfo(addonProps));
07e5742 [arm] merge arm-camelot into trunk, thanks to mcgeagh for all his hard w...
davilla authored
421 #if defined(HAS_VISUALISATION)
af8cb2a Revert "wip"
alcoheca authored
422 case ADDON_VIZ:
eca3c5b changed: refactor
spiff_ authored
423 return AddonPtr(new CVisualisation(addonProps));
07e5742 [arm] merge arm-camelot into trunk, thanks to mcgeagh for all his hard w...
davilla authored
424 #endif
af8cb2a Revert "wip"
alcoheca authored
425 case ADDON_SCREENSAVER:
eca3c5b changed: refactor
spiff_ authored
426 return AddonPtr(new CScreenSaver(addonProps));
af8cb2a Revert "wip"
alcoheca authored
427 case ADDON_VIZ_LIBRARY:
eca3c5b changed: refactor
spiff_ authored
428 return AddonPtr(new CAddonLibrary(addonProps));
606248f added: addon repository class
spiff_ authored
429 case ADDON_REPOSITORY:
430 return AddonPtr(new CRepository(addonProps));
af8cb2a Revert "wip"
alcoheca authored
431 default:
eca3c5b changed: refactor
spiff_ authored
432 break;
af8cb2a Revert "wip"
alcoheca authored
433 }
eca3c5b changed: refactor
spiff_ authored
434 return AddonPtr();
af8cb2a Revert "wip"
alcoheca authored
435 }
436
639b314 changed: move addonbrowser to a mediawindow derivate
spiff_ authored
437 void CAddonMgr::UpdateRepos()
438 {
439 CSingleLock lock(m_critSection);
440 if (m_watch.GetElapsedSeconds() < 600)
441 return;
442 m_watch.StartZero();
443 VECADDONS addons;
444 GetAddons(ADDON_REPOSITORY,addons);
445 for (unsigned int i=0;i<addons.size();++i)
446 {
447 RepositoryPtr repo = boost::dynamic_pointer_cast<CRepository>(addons[i]);
448 if (repo->LastUpdate()+CDateTimeSpan(0,6,0,0) < CDateTime::GetCurrentDateTime())
449 {
450 CLog::Log(LOGDEBUG,"Checking repository %s for updates",repo->Name().c_str());
9617e5e cosmetics
spiff_ authored
451 CJobManager::GetInstance().AddJob(new CRepositoryUpdateJob(repo),this);
639b314 changed: move addonbrowser to a mediawindow derivate
spiff_ authored
452 }
453 }
454 }
455
456 void CAddonMgr::OnJobComplete(unsigned int jobID, bool success, CJob* job)
457 {
458 if (!success)
459 return;
460
461 ((CRepositoryUpdateJob*)job)->m_repo->SetUpdated(CDateTime::GetCurrentDateTime());
462 }
463
1b2781c added: basic cpluff support
alcoheca authored
464 /*
465 * libcpluff interaction
466 */
467
2bf2640 added: Functions for sanity checking addons (platform checks and ignorin...
jmarshallnz authored
468 bool CAddonMgr::PlatformSupportsAddon(const cp_plugin_info_t *plugin) const
469 {
470 if (!plugin || !plugin->num_extensions)
471 return false;
472 const cp_extension_t *metadata = GetExtension(plugin, "xbmc.addon.metadata");
9d9704e cleanup: Make <supportedcontent> and <platform> use the same xs:list sty...
jmarshallnz authored
473 if (!metadata)
474 return false;
475
476 vector<CStdString> platforms;
477 if (CAddonMgr::Get().GetExtList(metadata->configuration, "platform", platforms))
2bf2640 added: Functions for sanity checking addons (platform checks and ignorin...
jmarshallnz authored
478 {
479 for (unsigned int i = 0; i < platforms.size(); ++i)
480 {
481 if (platforms[i] == "all")
482 return true;
483 #if defined(_LINUX) && !defined(__APPLE__)
484 if (platforms[i] == "linux")
485 #elif defined(_WIN32) && defined(HAS_SDL_OPENGL)
486 if (platforms[i] == "wingl")
487 #elif defined(_WIN32) && defined(HAS_DX)
488 if (platforms[i] == "windx")
489 #elif defined(__APPLE__)
490 if (platforms[i] == "osx")
491 #endif
492 return true;
493 }
9d9704e cleanup: Make <supportedcontent> and <platform> use the same xs:list sty...
jmarshallnz authored
494 return false; // no <platform> works for us
2bf2640 added: Functions for sanity checking addons (platform checks and ignorin...
jmarshallnz authored
495 }
9d9704e cleanup: Make <supportedcontent> and <platform> use the same xs:list sty...
jmarshallnz authored
496 return true; // assume no <platform> is equivalent to <platform>all</platform>
2bf2640 added: Functions for sanity checking addons (platform checks and ignorin...
jmarshallnz authored
497 }
498
bb4e01c Support creating userdirs in addons. This also has the benefit of being ...
ceros7 authored
499 const cp_cfg_element_t *CAddonMgr::GetExtElement(cp_cfg_element_t *base, const char *path)
500 {
501 const cp_cfg_element_t *element = NULL;
502 if (base)
503 element = m_cpluff->lookup_cfg_element(base, path);
504 return element;
505 }
506
507 /* Returns all duplicate elements from a base element */
16b848a added: CPluginSource class for all pluginsource addons
alcoheca authored
508 bool GetExtElementDeque(DEQUEELEMENTS &elements, cp_cfg_element_t *base, const char *path)
bb4e01c Support creating userdirs in addons. This also has the benefit of being ...
ceros7 authored
509 {
510 if (!base)
511 return false;
512
513 unsigned int i = 0;
514 while (true)
515 {
516 if (i >= base->num_children)
517 break;
518 CStdString temp = (base->children+i)->name;
519 if (!temp.compare(path))
520 elements.push_back(base->children+i);
521 i++;
522 }
523
524 if (elements.empty()) return false;
525 return true;
526 }
527
2bf2640 added: Functions for sanity checking addons (platform checks and ignorin...
jmarshallnz authored
528 const cp_extension_t *CAddonMgr::GetExtension(const cp_plugin_info_t *props, const char *extension) const
096e8a3 changed: Move description information into addon.xml via the xbmc.addon....
jmarshallnz authored
529 {
530 if (!props)
531 return NULL;
532 for (unsigned int i = 0; i < props->num_extensions; ++i)
533 {
534 if (0 == strcmp(props->extensions[i].ext_point_id, extension))
535 return &props->extensions[i];
536 }
537 return NULL;
538 }
539
a16721e changed: move scraper libraries to cpluff
spiff_ authored
540 ADDONDEPS CAddonMgr::GetDeps(const CStdString &id)
541 {
542 ADDONDEPS result;
543 cp_status_t status;
544
545 cp_plugin_info_t *info = m_cpluff->get_plugin_info(m_cp_context,id.c_str(),&status);
546 if (info)
547 {
548 for (unsigned int i=0;i<info->num_imports;++i)
549 result.insert(make_pair(CStdString(info->imports[i].plugin_id),
550 make_pair(AddonVersion(info->version),
551 AddonVersion(info->version))));
bb067ed fixed: Don't return true from GetAddon, and ensure we release the c-pluf...
jmarshallnz authored
552 m_cpluff->release_info(m_cp_context, info);
a16721e changed: move scraper libraries to cpluff
spiff_ authored
553 }
554
555 return result;
556 }
557
b6076e5 changed: screensavers are now supported via cpluff schema
alcoheca authored
558 CStdString CAddonMgr::GetExtValue(cp_cfg_element_t *base, const char *path)
559 {
560 const char *value = NULL;
561 if (base && (value = m_cpluff->lookup_cfg_value(base, path)))
562 return CStdString(value);
563 else return CStdString();
564 }
565
9d9704e cleanup: Make <supportedcontent> and <platform> use the same xs:list sty...
jmarshallnz authored
566 bool CAddonMgr::GetExtList(cp_cfg_element_t *base, const char *path, vector<CStdString> &result) const
a16721e changed: move scraper libraries to cpluff
spiff_ authored
567 {
9d9704e cleanup: Make <supportedcontent> and <platform> use the same xs:list sty...
jmarshallnz authored
568 if (!base || !path)
569 return false;
570 CStdString all = m_cpluff->lookup_cfg_value(base, path);
571 if (all.IsEmpty())
572 return false;
573 StringUtils::SplitString(all, " ", result);
574 return true;
a16721e changed: move scraper libraries to cpluff
spiff_ authored
575 }
576
2bf2640 added: Functions for sanity checking addons (platform checks and ignorin...
jmarshallnz authored
577 AddonPtr CAddonMgr::GetAddonFromDescriptor(const cp_plugin_info_t *info)
578 {
579 if (!info || !info->extensions)
580 return AddonPtr();
581
582 // FIXME: If we want to support multiple extension points per addon, we'll need to extend this to not just take
583 // the first extension point (eg use the TYPE information we pass in)
584
585 // grab a relevant extension point, ignoring our xbmc.addon.metadata extension point
28cd382 fixed: sanity is not just a state of mind...
jmarshallnz authored
586 for (unsigned int i = 0; i < info->num_extensions; ++i)
2bf2640 added: Functions for sanity checking addons (platform checks and ignorin...
jmarshallnz authored
587 {
588 if (0 != strcmp("xbmc.addon.metadata", info->extensions[i].ext_point_id))
589 { // note that Factory takes care of whether or not we have platform support
590 return Factory(&info->extensions[i]);
591 }
592 }
593 return AddonPtr();
594 }
595
596 // FIXME: This function may not be required
5bca9c0 cleanup: Rename and document the cpluff versions of loading addon descri...
jmarshallnz authored
597 bool CAddonMgr::LoadAddonDescription(const CStdString &path, AddonPtr &addon)
92afa2e fixed: Addons weren't installed correctly
jmarshallnz authored
598 {
599 cp_status_t status;
600 cp_plugin_info_t *info = m_cpluff->load_plugin_descriptor(m_cp_context, _P(path).c_str(), &status);
601 if (info)
602 {
2bf2640 added: Functions for sanity checking addons (platform checks and ignorin...
jmarshallnz authored
603 addon = GetAddonFromDescriptor(info);
92afa2e fixed: Addons weren't installed correctly
jmarshallnz authored
604 m_cpluff->release_info(m_cp_context, info);
9785be9 cleanup: Got rid of ADDON_SCRIPT_LIBRARY, compile warnings, and cosmetic...
jmarshallnz authored
605 return NULL != addon.get();
92afa2e fixed: Addons weren't installed correctly
jmarshallnz authored
606 }
607 return false;
608 }
609
5bca9c0 cleanup: Rename and document the cpluff versions of loading addon descri...
jmarshallnz authored
610 bool CAddonMgr::AddonsFromRepoXML(const TiXmlElement *root, VECADDONS &addons)
4488d3a changed: Allow repository to have c-pluff XML files
jmarshallnz authored
611 {
612 // create a context for these addons
613 cp_status_t status;
614 cp_context_t *context = m_cpluff->create_context(&status);
615 if (!root || !context)
616 return false;
617
cfe53d3 fixed: Put the UTF-8 descriptor on the XML before feeding it to c-pluff
jmarshallnz authored
618 // each addon XML should have a UTF-8 declaration
619 TiXmlDeclaration decl("1.0", "UTF-8", "");
4488d3a changed: Allow repository to have c-pluff XML files
jmarshallnz authored
620 const TiXmlElement *element = root->FirstChildElement("addon");
621 while (element)
622 {
cfe53d3 fixed: Put the UTF-8 descriptor on the XML before feeding it to c-pluff
jmarshallnz authored
623 // dump the XML back to text
4488d3a changed: Allow repository to have c-pluff XML files
jmarshallnz authored
624 std::string xml;
cfe53d3 fixed: Put the UTF-8 descriptor on the XML before feeding it to c-pluff
jmarshallnz authored
625 xml << decl;
4488d3a changed: Allow repository to have c-pluff XML files
jmarshallnz authored
626 xml << *element;
627 cp_status_t status;
cd2be2f added: Expose cp_load_plugin_descriptor and separate out the from_memory...
jmarshallnz authored
628 cp_plugin_info_t *info = m_cpluff->load_plugin_descriptor_from_memory(context, xml.c_str(), xml.size(), &status);
4488d3a changed: Allow repository to have c-pluff XML files
jmarshallnz authored
629 if (info)
630 {
2bf2640 added: Functions for sanity checking addons (platform checks and ignorin...
jmarshallnz authored
631 AddonPtr addon = GetAddonFromDescriptor(info);
ed51e37 fixed: check for NULL before adding the addon in AddonsFromInfoXML
jmarshallnz authored
632 if (addon.get())
633 addons.push_back(addon);
2bf2640 added: Functions for sanity checking addons (platform checks and ignorin...
jmarshallnz authored
634 m_cpluff->release_info(context, info);
4488d3a changed: Allow repository to have c-pluff XML files
jmarshallnz authored
635 }
636 element = element->NextSiblingElement("addon");
637 }
638 m_cpluff->destroy_context(context);
639 return true;
640 }
641
1b2781c added: basic cpluff support
alcoheca authored
642 int cp_to_clog(cp_log_severity_t lvl)
643 {
644 if( lvl == CP_LOG_DEBUG )
645 return 0;
646 else if (lvl == CP_LOG_INFO)
647 return 1;
648 else if (lvl == CP_LOG_WARNING)
649 return 3;
650 else
651 return 4;
652 }
653
654 cp_log_severity_t clog_to_cp(int lvl)
655 {
656 if (lvl >= 4)
657 return CP_LOG_ERROR;
658 else if (lvl == 3)
659 return CP_LOG_WARNING;
660 else if (lvl >= 1)
661 return CP_LOG_INFO;
662 else
663 return CP_LOG_DEBUG;
664 }
665
b6f0f59 cleanup: Don't expose the AddonManager's privates when not required.
jmarshallnz authored
666 void cp_fatalErrorHandler(const char *msg)
667 {
668 CLog::Log(LOGERROR, "ADDONS: CPluffFatalError(%s)", msg);
669 }
670
671 void cp_logger(cp_log_severity_t level, const char *msg, const char *apid, void *user_data)
1b2781c added: basic cpluff support
alcoheca authored
672 {
673 if(!apid)
5b793b6 added: missing change from r29798
alcoheca authored
674 CLog::Log(cp_to_clog(level), "ADDON: cpluff: '%s'", msg);
1b2781c added: basic cpluff support
alcoheca authored
675 else
5b793b6 added: missing change from r29798
alcoheca authored
676 CLog::Log(cp_to_clog(level), "ADDON: cpluff: '%s' reports '%s'", apid, msg);
1b2781c added: basic cpluff support
alcoheca authored
677 }
678
074db86 merged: addons-fw branch
elupus authored
679 } /* namespace ADDON */
680
Something went wrong with that request. Please try again.