Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 782 lines (698 sloc) 22.041 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"
c51b118 Merged cptspiff's code-reshuffle branch.
theuni authored
24 #include "utils/StringUtils.h"
639b314 changed: move addonbrowser to a mediawindow derivate
spiff_ authored
25 #include "utils/JobManager.h"
c51b118 Merged cptspiff's code-reshuffle branch.
theuni authored
26 #include "threads/SingleLock.h"
074db86 merged: addons-fw branch
elupus authored
27 #include "FileItem.h"
822ca91 added: translatable <description>, <title>, <summary> and <disclaimer…
spiff_ authored
28 #include "LangInfo.h"
c51b118 Merged cptspiff's code-reshuffle branch.
theuni authored
29 #include "settings/Settings.h"
30 #include "settings/GUISettings.h"
31 #include "settings/AdvancedSettings.h"
32 #include "utils/log.h"
074db86 merged: addons-fw branch
elupus authored
33
34 #ifdef HAS_VISUALISATION
055f806 cosmetic/tidyup move all addon classes to /xbmc/addons/
alcoheca authored
35 #include "Visualisation.h"
074db86 merged: addons-fw branch
elupus authored
36 #endif
37 #ifdef HAS_SCREENSAVER
055f806 cosmetic/tidyup move all addon classes to /xbmc/addons/
alcoheca authored
38 #include "ScreenSaver.h"
074db86 merged: addons-fw branch
elupus authored
39 #endif
40 //#ifdef HAS_SCRAPERS
055f806 cosmetic/tidyup move all addon classes to /xbmc/addons/
alcoheca authored
41 #include "Scraper.h"
074db86 merged: addons-fw branch
elupus authored
42 //#endif
16b848a added: CPluginSource class for all pluginsource addons
alcoheca authored
43 #include "PluginSource.h"
606248f added: addon repository class
spiff_ authored
44 #include "Repository.h"
553d213 changed: finished moving skins to addon framework
alcoheca authored
45 #include "Skin.h"
b55ac44 added: service addons.
blinkseb authored
46 #include "Service.h"
af8cb2a Revert "wip"
alcoheca authored
47
88e9b6f changed: expand std namespace
spiff_ authored
48 using namespace std;
49
074db86 merged: addons-fw branch
elupus authored
50 namespace ADDON
51 {
52
b6f0f59 cleanup: Don't expose the AddonManager's privates when not required.
jmarshallnz authored
53 cp_log_severity_t clog_to_cp(int lvl);
54 void cp_fatalErrorHandler(const char *msg);
55 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
56 bool GetExtElementDeque(DEQUEELEMENTS &elements, cp_cfg_element_t *base, const char *path);
074db86 merged: addons-fw branch
elupus authored
57
58 /**********************************************************
59 * CAddonMgr
60 *
61 */
62
88e9b6f changed: expand std namespace
spiff_ authored
63 map<TYPE, IAddonMgrCallback*> CAddonMgr::m_managers;
074db86 merged: addons-fw branch
elupus authored
64
c14bf20 changed: moved addonptr factory to CAddonMgr.
alcoheca authored
65 AddonPtr CAddonMgr::Factory(const cp_extension_t *props)
1b2781c added: basic cpluff support
alcoheca authored
66 {
2bf2640 added: Functions for sanity checking addons (platform checks and igno…
jmarshallnz authored
67 if (!PlatformSupportsAddon(props->plugin))
68 return AddonPtr();
69
bb4e01c Support creating userdirs in addons. This also has the benefit of bei…
ceros7 authored
70 /* Check if user directories need to be created */
2bf2640 added: Functions for sanity checking addons (platform checks and igno…
jmarshallnz authored
71 const cp_cfg_element_t *settings = GetExtElement(props->configuration, "settings");
bb4e01c Support creating userdirs in addons. This also has the benefit of bei…
ceros7 authored
72 if (settings)
73 CheckUserDirs(settings);
74
1b2781c added: basic cpluff support
alcoheca authored
75 const TYPE type = TranslateType(props->ext_point_id);
76 switch (type)
77 {
78 case ADDON_PLUGIN:
79 case ADDON_SCRIPT:
9a8454a added: script support to media windows. Scripts should use the same e…
jmarshallnz authored
80 return AddonPtr(new CPluginSource(props));
35cf15f changed: get rid of the content types added earlier, favouring extens…
jmarshallnz authored
81 case ADDON_SCRIPT_LIBRARY:
82 case ADDON_SCRIPT_LYRICS:
83 case ADDON_SCRIPT_WEATHER:
84 case ADDON_SCRIPT_SUBTITLES:
9d4264e added: Initial support for python module addons.
jmarshallnz authored
85 case ADDON_SCRIPT_MODULE:
113777a merged: r33383,r33386 from webinterface branch
jmarshallnz authored
86 case ADDON_WEB_INTERFACE:
257d969 changed: Move Addon constructors to take the extension point they're …
jmarshallnz authored
87 return AddonPtr(new CAddon(props));
b55ac44 added: service addons.
blinkseb authored
88 case ADDON_SERVICE:
89 return AddonPtr(new CService(props));
6a9704f changed: Split scrapers into separate extension points per content ty…
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 …
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 …
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 har…
davilla authored
124 {
125 #if defined(HAS_VISUALISATION)
257d969 changed: Move Addon constructors to take the extension point they're …
jmarshallnz authored
126 return AddonPtr(new CVisualisation(props));
07e5742 [arm] merge arm-camelot into trunk, thanks to mcgeagh for all his har…
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 …
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 …
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 …
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 …
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 bei…
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 {
2f07dec ensure m_cpluff is initialized to NULL
Jonathan Marshall authored
177 m_cpluff = NULL;
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 …
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. S…
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 longe…
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"));
eb109c5 fixed: Need to look for addons in special://xbmcbin/ too thanks to py…
althekiller authored
244 status = m_cpluff->register_pcollection(m_cp_context, _P("special://xbmcbin/addons"));
b6076e5 changed: screensavers are now supported via cpluff schema
alcoheca authored
245 if (status != CP_OK)
246 {
247 CLog::Log(LOGERROR, "ADDONS: Fatal Error, cp_register_pcollection() returned status: %i", status);
248 return false;
1b2781c added: basic cpluff support
alcoheca authored
249 }
b6076e5 changed: screensavers are now supported via cpluff schema
alcoheca authored
250
185686a added: even more missing from r29798
alcoheca authored
251 status = m_cpluff->register_logger(m_cp_context, cp_logger,
7188808 changed: bail out immeditaly if CAddonMgr::Init returns false
alcoheca authored
252 &CAddonMgr::Get(), clog_to_cp(g_advancedSettings.m_logLevel));
b6076e5 changed: screensavers are now supported via cpluff schema
alcoheca authored
253 if (status != CP_OK)
254 {
255 CLog::Log(LOGERROR, "ADDONS: Fatal Error, cp_register_logger() returned status: %i", status);
256 return false;
257 }
1b2781c added: basic cpluff support
alcoheca authored
258
f0b69e1 changed: move the cpluff plugin scanner call to findaddons
spiff_ authored
259 FindAddons();
b6076e5 changed: screensavers are now supported via cpluff schema
alcoheca authored
260 return true;
1b2781c added: basic cpluff support
alcoheca authored
261 }
262
37a994e added: Deinit to the addons manager to ensure we unload cpluff prior …
jmarshallnz authored
263 void CAddonMgr::DeInit()
264 {
265 if (m_cpluff)
266 m_cpluff->destroy();
29ce354 fixed: some mem leaks spotted by valgrind (there are many many others)
elupus authored
267 delete m_cpluff;
37a994e added: Deinit to the addons manager to ensure we unload cpluff prior …
jmarshallnz authored
268 m_cpluff = NULL;
b700e3f changed: Hold the addons database as a member in the AddonManager. S…
jmarshallnz authored
269 m_database.Close();
37a994e added: Deinit to the addons manager to ensure we unload cpluff prior …
jmarshallnz authored
270 }
271
56aa69b added: Support for addons to be disabled while still being installed.
jmarshallnz authored
272 bool CAddonMgr::HasAddons(const TYPE &type, bool enabled /*= true*/)
074db86 merged: addons-fw branch
elupus authored
273 {
7672f26 fixed: Ensure HasAddons respects the content type.
jmarshallnz authored
274 // TODO: This isn't particularly efficient as we create an addon type for each addon using the Factory, just so
275 // we can check addon dependencies in the addon constructor.
276 VECADDONS addons;
56aa69b added: Support for addons to be disabled while still being installed.
jmarshallnz authored
277 return GetAddons(type, addons, enabled);
074db86 merged: addons-fw branch
elupus authored
278 }
279
4029b9f fixed: Show disabled addons in the Disabled Add-ons node, allowing th…
jmarshallnz authored
280 bool CAddonMgr::GetAllAddons(VECADDONS &addons, bool enabled /*= true*/, bool allowRepos /* = false */)
074db86 merged: addons-fw branch
elupus authored
281 {
816cf12 fixed: Get weather, subtitles, lyrics and library scripts to show up …
jmarshallnz authored
282 for (int i = ADDON_UNKNOWN+1; i < ADDON_VIZ_LIBRARY; ++i)
283 {
4029b9f fixed: Show disabled addons in the Disabled Add-ons node, allowing th…
jmarshallnz authored
284 if (!allowRepos && ADDON_REPOSITORY == (TYPE)i)
816cf12 fixed: Get weather, subtitles, lyrics and library scripts to show up …
jmarshallnz authored
285 continue;
286 VECADDONS temp;
56aa69b added: Support for addons to be disabled while still being installed.
jmarshallnz authored
287 if (CAddonMgr::Get().GetAddons((TYPE)i, temp, enabled))
816cf12 fixed: Get weather, subtitles, lyrics and library scripts to show up …
jmarshallnz authored
288 addons.insert(addons.end(), temp.begin(), temp.end());
289 }
af8cb2a Revert "wip"
alcoheca authored
290 return !addons.empty();
074db86 merged: addons-fw branch
elupus authored
291 }
292
e21982b added: ticket #9633 - "addons://outdated/" for listing all Add-ons wi…
spiff_ authored
293 bool CAddonMgr::GetAllOutdatedAddons(VECADDONS &addons, bool enabled /*= true*/)
294 {
295 CSingleLock lock(m_critSection);
296 for (int i = ADDON_UNKNOWN+1; i < ADDON_VIZ_LIBRARY; ++i)
297 {
298 VECADDONS temp;
299 if (CAddonMgr::Get().GetAddons((TYPE)i, temp, enabled))
300 {
301 AddonPtr repoAddon;
302 for (unsigned int j = 0; j < temp.size(); j++)
303 {
304 if (!m_database.GetAddon(temp[j]->ID(), repoAddon))
305 continue;
306
307 if (temp[j]->Version() < repoAddon->Version())
308 addons.push_back(repoAddon);
309 }
310 }
311 }
312 return !addons.empty();
313 }
314
315 bool CAddonMgr::HasOutdatedAddons(bool enabled /*= true*/)
316 {
317 VECADDONS dummy;
318 return GetAllOutdatedAddons(dummy,enabled);
319 }
320
56aa69b added: Support for addons to be disabled while still being installed.
jmarshallnz authored
321 bool CAddonMgr::GetAddons(const TYPE &type, VECADDONS &addons, bool enabled /* = true */)
074db86 merged: addons-fw branch
elupus authored
322 {
4e5b98a added: locks to addon manager
spiff_ authored
323 CSingleLock lock(m_critSection);
af8cb2a Revert "wip"
alcoheca authored
324 addons.clear();
8c86aee cleanup: Get rid of some more old non-cpluff stuff. Should also fix …
jmarshallnz authored
325 cp_status_t status;
326 int num;
327 CStdString ext_point(TranslateType(type));
328 cp_extension_t **exts = m_cpluff->get_extensions_info(m_cp_context, ext_point.c_str(), &status, &num);
329 for(int i=0; i <num; i++)
af8cb2a Revert "wip"
alcoheca authored
330 {
8c86aee cleanup: Get rid of some more old non-cpluff stuff. Should also fix …
jmarshallnz authored
331 AddonPtr addon(Factory(exts[i]));
b700e3f changed: Hold the addons database as a member in the AddonManager. S…
jmarshallnz authored
332 if (addon && m_database.IsAddonDisabled(addon->ID()) != enabled)
8c86aee cleanup: Get rid of some more old non-cpluff stuff. Should also fix …
jmarshallnz authored
333 addons.push_back(addon);
af8cb2a Revert "wip"
alcoheca authored
334 }
8c86aee cleanup: Get rid of some more old non-cpluff stuff. Should also fix …
jmarshallnz authored
335 m_cpluff->release_info(m_cp_context, exts);
336 return addons.size() > 0;
074db86 merged: addons-fw branch
elupus authored
337 }
338
83a5edb fixed: Ensure the context menu in the addon manager is consistent (no…
jmarshallnz authored
339 bool CAddonMgr::GetAddon(const CStdString &str, AddonPtr &addon, const TYPE &type/*=ADDON_UNKNOWN*/, bool enabledOnly /*= true*/)
074db86 merged: addons-fw branch
elupus authored
340 {
4e5b98a added: locks to addon manager
spiff_ authored
341 CSingleLock lock(m_critSection);
074db86 merged: addons-fw branch
elupus authored
342
c22f535 cosmetics
alcoheca authored
343 cp_status_t status;
84824e3 cosmetics
spiff_ authored
344 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 igno…
jmarshallnz authored
345 if (status == CP_OK && cpaddon)
c22f535 cosmetics
alcoheca authored
346 {
2bf2640 added: Functions for sanity checking addons (platform checks and igno…
jmarshallnz authored
347 addon = GetAddonFromDescriptor(cpaddon);
c22f535 cosmetics
alcoheca authored
348 m_cpluff->release_info(m_cp_context, cpaddon);
bfb0ba2 @opdenkamp Revert "Merge remote branch 'upstream/master'"
authored
349 if (addon.get() && enabledOnly && m_database.IsAddonDisabled(addon->ID()))
350 return false;
83a5edb fixed: Ensure the context menu in the addon manager is consistent (no…
jmarshallnz authored
351 return NULL != addon.get();
c22f535 cosmetics
alcoheca authored
352 }
353 if (cpaddon)
354 m_cpluff->release_info(m_cp_context, cpaddon);
b6076e5 changed: screensavers are now supported via cpluff schema
alcoheca authored
355
074db86 merged: addons-fw branch
elupus authored
356 return false;
357 }
358
359 //TODO handle all 'default' cases here, not just scrapers & vizs
257d969 changed: Move Addon constructors to take the extension point they're …
jmarshallnz authored
360 bool CAddonMgr::GetDefault(const TYPE &type, AddonPtr &addon)
074db86 merged: addons-fw branch
elupus authored
361 {
362 CStdString setting;
6a9704f changed: Split scrapers into separate extension points per content ty…
jmarshallnz authored
363 switch (type)
074db86 merged: addons-fw branch
elupus authored
364 {
6a9704f changed: Split scrapers into separate extension points per content ty…
jmarshallnz authored
365 case ADDON_VIZ:
366 setting = g_guiSettings.GetString("musicplayer.visualisation");
367 break;
730b6da added: addon.set.default built-in to set the default for a particular…
jmarshallnz authored
368 case ADDON_SCREENSAVER:
369 setting = g_guiSettings.GetString("screensaver.mode");
370 break;
6a9704f changed: Split scrapers into separate extension points per content ty…
jmarshallnz authored
371 case ADDON_SCRAPER_ALBUMS:
92be514 changed: rename these settings. type changed. update sad
spiff_ authored
372 setting = g_guiSettings.GetString("musiclibrary.albumsscraper");
c077443 changed: Split the music scraping into separate album and artist scra…
jmarshallnz authored
373 break;
6a9704f changed: Split scrapers into separate extension points per content ty…
jmarshallnz authored
374 case ADDON_SCRAPER_ARTISTS:
92be514 changed: rename these settings. type changed. update sad
spiff_ authored
375 setting = g_guiSettings.GetString("musiclibrary.artistsscraper");
6a9704f changed: Split scrapers into separate extension points per content ty…
jmarshallnz authored
376 break;
377 case ADDON_SCRAPER_MOVIES:
92be514 changed: rename these settings. type changed. update sad
spiff_ authored
378 setting = g_guiSettings.GetString("scrapers.moviesdefault");
6a9704f changed: Split scrapers into separate extension points per content ty…
jmarshallnz authored
379 break;
380 case ADDON_SCRAPER_MUSICVIDEOS:
92be514 changed: rename these settings. type changed. update sad
spiff_ authored
381 setting = g_guiSettings.GetString("scrapers.musicvideosdefault");
6a9704f changed: Split scrapers into separate extension points per content ty…
jmarshallnz authored
382 break;
383 case ADDON_SCRAPER_TVSHOWS:
92be514 changed: rename these settings. type changed. update sad
spiff_ authored
384 setting = g_guiSettings.GetString("scrapers.tvshowsdefault");
6a9704f changed: Split scrapers into separate extension points per content ty…
jmarshallnz authored
385 break;
113777a merged: r33383,r33386 from webinterface branch
jmarshallnz authored
386 case ADDON_WEB_INTERFACE:
387 setting = g_guiSettings.GetString("services.webskin");
388 break;
6a9704f changed: Split scrapers into separate extension points per content ty…
jmarshallnz authored
389 default:
390 return false;
074db86 merged: addons-fw branch
elupus authored
391 }
2ca76f9 changed: all addons should be store below either special://home/addon…
alcoheca authored
392 return GetAddon(setting, addon, type);
074db86 merged: addons-fw branch
elupus authored
393 }
394
730b6da added: addon.set.default built-in to set the default for a particular…
jmarshallnz authored
395 bool CAddonMgr::SetDefault(const TYPE &type, const CStdString &addonID)
396 {
397 switch (type)
398 {
399 case ADDON_VIZ:
400 g_guiSettings.SetString("musicplayer.visualisation",addonID);
401 break;
402 case ADDON_SCREENSAVER:
403 g_guiSettings.SetString("screensaver.mode",addonID);
404 break;
405 case ADDON_SCRAPER_ALBUMS:
406 g_guiSettings.SetString("musiclibrary.albumsscraper",addonID);
407 break;
408 case ADDON_SCRAPER_ARTISTS:
409 g_guiSettings.SetString("musiclibrary.artistsscraper",addonID);
410 break;
411 case ADDON_SCRAPER_MOVIES:
412 g_guiSettings.SetString("scrapers.moviesdefault",addonID);
413 break;
414 case ADDON_SCRAPER_MUSICVIDEOS:
415 g_guiSettings.SetString("scrapers.musicvideosdefault",addonID);
416 break;
417 case ADDON_SCRAPER_TVSHOWS:
418 g_guiSettings.SetString("scrapers.tvshowsdefault",addonID);
419 break;
420 default:
421 return false;
422 }
423
424 return true;
425 }
426
7411555 changed: renamed UUID to ID. we now accept any string as an identifier,
alcoheca authored
427 CStdString CAddonMgr::GetString(const CStdString &id, const int number)
074db86 merged: addons-fw branch
elupus authored
428 {
8c86aee cleanup: Get rid of some more old non-cpluff stuff. Should also fix …
jmarshallnz authored
429 AddonPtr addon;
430 if (GetAddon(id, addon))
074db86 merged: addons-fw branch
elupus authored
431 return addon->GetString(number);
432
433 return "";
434 }
435
af8cb2a Revert "wip"
alcoheca authored
436 void CAddonMgr::FindAddons()
437 {
4e5b98a added: locks to addon manager
spiff_ authored
438 CSingleLock lock(m_critSection);
f0b69e1 changed: move the cpluff plugin scanner call to findaddons
spiff_ authored
439 if (m_cpluff && m_cp_context)
d8d145c fixed: update addon information after upgrade
ametovic authored
440 m_cpluff->scan_plugins(m_cp_context, CP_SP_UPGRADE);
535b4e7 changed: load addons from user directory first, then load from system…
elupus authored
441 }
442
f1031c4 fixed: disabling addons
spiff_ authored
443 void CAddonMgr::RemoveAddon(const CStdString& ID)
444 {
445 if (m_cpluff && m_cp_context)
446 m_cpluff->uninstall_plugin(m_cp_context,ID.c_str());
447 }
448
096e8a3 changed: Move description information into addon.xml via the xbmc.add…
jmarshallnz authored
449 const char *CAddonMgr::GetTranslatedString(const cp_cfg_element_t *root, const char *tag)
450 {
451 if (!root)
452 return NULL;
453
454 const cp_cfg_element_t *eng = NULL;
455 for (unsigned int i = 0; i < root->num_children; i++)
456 {
457 const cp_cfg_element_t &child = root->children[i];
458 if (strcmp(tag, child.name) == 0)
459 { // see if we have a "lang" attribute
460 const char *lang = m_cpluff->lookup_cfg_value((cp_cfg_element_t*)&child, "@lang");
461 if (lang && 0 == strcmp(lang,g_langInfo.GetDVDAudioLanguage().c_str()))
462 return child.value;
463 if (!lang || 0 == strcmp(lang, "en"))
464 eng = &child;
465 }
466 }
467 return (eng) ? eng->value : NULL;
468 }
469
eca3c5b changed: refactor
spiff_ authored
470 AddonPtr CAddonMgr::AddonFromProps(AddonProps& addonProps)
471 {
472 switch (addonProps.type)
af8cb2a Revert "wip"
alcoheca authored
473 {
474 case ADDON_PLUGIN:
475 case ADDON_SCRIPT:
15de189 fixed: Make sure ADDON_SCRIPT uses CPluginSource so that Provides works
jmarshallnz authored
476 return AddonPtr(new CPluginSource(addonProps));
35cf15f changed: get rid of the content types added earlier, favouring extens…
jmarshallnz authored
477 case ADDON_SCRIPT_LIBRARY:
478 case ADDON_SCRIPT_LYRICS:
479 case ADDON_SCRIPT_WEATHER:
480 case ADDON_SCRIPT_SUBTITLES:
9d4264e added: Initial support for python module addons.
jmarshallnz authored
481 case ADDON_SCRIPT_MODULE:
21dd418 fixed: Webinterface section wasn't shown in Repositories
jmarshallnz authored
482 case ADDON_WEB_INTERFACE:
eca3c5b changed: refactor
spiff_ authored
483 return AddonPtr(new CAddon(addonProps));
b55ac44 added: service addons.
blinkseb authored
484 case ADDON_SERVICE:
485 return AddonPtr(new CService(addonProps));
6a9704f changed: Split scrapers into separate extension points per content ty…
jmarshallnz authored
486 case ADDON_SCRAPER_ALBUMS:
487 case ADDON_SCRAPER_ARTISTS:
488 case ADDON_SCRAPER_MOVIES:
489 case ADDON_SCRAPER_MUSICVIDEOS:
490 case ADDON_SCRAPER_TVSHOWS:
491 case ADDON_SCRAPER_LIBRARY:
eca3c5b changed: refactor
spiff_ authored
492 return AddonPtr(new CScraper(addonProps));
553d213 changed: finished moving skins to addon framework
alcoheca authored
493 case ADDON_SKIN:
494 return AddonPtr(new CSkinInfo(addonProps));
07e5742 [arm] merge arm-camelot into trunk, thanks to mcgeagh for all his har…
davilla authored
495 #if defined(HAS_VISUALISATION)
af8cb2a Revert "wip"
alcoheca authored
496 case ADDON_VIZ:
eca3c5b changed: refactor
spiff_ authored
497 return AddonPtr(new CVisualisation(addonProps));
07e5742 [arm] merge arm-camelot into trunk, thanks to mcgeagh for all his har…
davilla authored
498 #endif
af8cb2a Revert "wip"
alcoheca authored
499 case ADDON_SCREENSAVER:
eca3c5b changed: refactor
spiff_ authored
500 return AddonPtr(new CScreenSaver(addonProps));
af8cb2a Revert "wip"
alcoheca authored
501 case ADDON_VIZ_LIBRARY:
eca3c5b changed: refactor
spiff_ authored
502 return AddonPtr(new CAddonLibrary(addonProps));
606248f added: addon repository class
spiff_ authored
503 case ADDON_REPOSITORY:
504 return AddonPtr(new CRepository(addonProps));
af8cb2a Revert "wip"
alcoheca authored
505 default:
eca3c5b changed: refactor
spiff_ authored
506 break;
af8cb2a Revert "wip"
alcoheca authored
507 }
eca3c5b changed: refactor
spiff_ authored
508 return AddonPtr();
af8cb2a Revert "wip"
alcoheca authored
509 }
510
772d686 added: built-in XBMC.UpdateAddonRepos to force an update of enabled a…
vdrfan authored
511 void CAddonMgr::UpdateRepos(bool force)
639b314 changed: move addonbrowser to a mediawindow derivate
spiff_ authored
512 {
513 CSingleLock lock(m_critSection);
772d686 added: built-in XBMC.UpdateAddonRepos to force an update of enabled a…
vdrfan authored
514 if (!force && m_watch.IsRunning() && m_watch.GetElapsedSeconds() < 600)
639b314 changed: move addonbrowser to a mediawindow derivate
spiff_ authored
515 return;
516 m_watch.StartZero();
517 VECADDONS addons;
518 GetAddons(ADDON_REPOSITORY,addons);
519 for (unsigned int i=0;i<addons.size();++i)
520 {
521 RepositoryPtr repo = boost::dynamic_pointer_cast<CRepository>(addons[i]);
c4f8e76 changed: Have UpdateRepos() use it's db member to fetch the repo time…
jmarshallnz authored
522 CDateTime lastUpdate = m_database.GetRepoTimestamp(repo->ID());
772d686 added: built-in XBMC.UpdateAddonRepos to force an update of enabled a…
vdrfan authored
523 if (force || !lastUpdate.IsValid() || lastUpdate + CDateTimeSpan(0,6,0,0) < CDateTime::GetCurrentDateTime())
639b314 changed: move addonbrowser to a mediawindow derivate
spiff_ authored
524 {
525 CLog::Log(LOGDEBUG,"Checking repository %s for updates",repo->Name().c_str());
6dadda1 cleanup: Get rid of needless additional SetRepoTimestamp after retrie…
jmarshallnz authored
526 CJobManager::GetInstance().AddJob(new CRepositoryUpdateJob(repo), NULL);
639b314 changed: move addonbrowser to a mediawindow derivate
spiff_ authored
527 }
528 }
529 }
530
1b2781c added: basic cpluff support
alcoheca authored
531 /*
532 * libcpluff interaction
533 */
534
2bf2640 added: Functions for sanity checking addons (platform checks and igno…
jmarshallnz authored
535 bool CAddonMgr::PlatformSupportsAddon(const cp_plugin_info_t *plugin) const
536 {
537 if (!plugin || !plugin->num_extensions)
538 return false;
539 const cp_extension_t *metadata = GetExtension(plugin, "xbmc.addon.metadata");
9d9704e cleanup: Make <supportedcontent> and <platform> use the same xs:list …
jmarshallnz authored
540 if (!metadata)
541 return false;
a388e47 added: function to parse an addon descriptor from memory
Jonathan Marshall authored
542
9d9704e cleanup: Make <supportedcontent> and <platform> use the same xs:list …
jmarshallnz authored
543 vector<CStdString> platforms;
544 if (CAddonMgr::Get().GetExtList(metadata->configuration, "platform", platforms))
2bf2640 added: Functions for sanity checking addons (platform checks and igno…
jmarshallnz authored
545 {
546 for (unsigned int i = 0; i < platforms.size(); ++i)
547 {
548 if (platforms[i] == "all")
549 return true;
550 #if defined(_LINUX) && !defined(__APPLE__)
551 if (platforms[i] == "linux")
552 #elif defined(_WIN32) && defined(HAS_SDL_OPENGL)
553 if (platforms[i] == "wingl")
554 #elif defined(_WIN32) && defined(HAS_DX)
555 if (platforms[i] == "windx")
556 #elif defined(__APPLE__)
557 if (platforms[i] == "osx")
558 #endif
559 return true;
560 }
9d9704e cleanup: Make <supportedcontent> and <platform> use the same xs:list …
jmarshallnz authored
561 return false; // no <platform> works for us
2bf2640 added: Functions for sanity checking addons (platform checks and igno…
jmarshallnz authored
562 }
9d9704e cleanup: Make <supportedcontent> and <platform> use the same xs:list …
jmarshallnz authored
563 return true; // assume no <platform> is equivalent to <platform>all</platform>
2bf2640 added: Functions for sanity checking addons (platform checks and igno…
jmarshallnz authored
564 }
565
bb4e01c Support creating userdirs in addons. This also has the benefit of bei…
ceros7 authored
566 const cp_cfg_element_t *CAddonMgr::GetExtElement(cp_cfg_element_t *base, const char *path)
567 {
568 const cp_cfg_element_t *element = NULL;
569 if (base)
570 element = m_cpluff->lookup_cfg_element(base, path);
571 return element;
572 }
573
574 /* Returns all duplicate elements from a base element */
16b848a added: CPluginSource class for all pluginsource addons
alcoheca authored
575 bool GetExtElementDeque(DEQUEELEMENTS &elements, cp_cfg_element_t *base, const char *path)
bb4e01c Support creating userdirs in addons. This also has the benefit of bei…
ceros7 authored
576 {
577 if (!base)
578 return false;
579
580 unsigned int i = 0;
581 while (true)
582 {
583 if (i >= base->num_children)
584 break;
585 CStdString temp = (base->children+i)->name;
586 if (!temp.compare(path))
587 elements.push_back(base->children+i);
588 i++;
589 }
590
591 if (elements.empty()) return false;
592 return true;
593 }
594
2bf2640 added: Functions for sanity checking addons (platform checks and igno…
jmarshallnz authored
595 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.add…
jmarshallnz authored
596 {
597 if (!props)
598 return NULL;
599 for (unsigned int i = 0; i < props->num_extensions; ++i)
600 {
601 if (0 == strcmp(props->extensions[i].ext_point_id, extension))
602 return &props->extensions[i];
603 }
604 return NULL;
605 }
606
b6076e5 changed: screensavers are now supported via cpluff schema
alcoheca authored
607 CStdString CAddonMgr::GetExtValue(cp_cfg_element_t *base, const char *path)
608 {
609 const char *value = NULL;
610 if (base && (value = m_cpluff->lookup_cfg_value(base, path)))
611 return CStdString(value);
612 else return CStdString();
613 }
614
9d9704e cleanup: Make <supportedcontent> and <platform> use the same xs:list …
jmarshallnz authored
615 bool CAddonMgr::GetExtList(cp_cfg_element_t *base, const char *path, vector<CStdString> &result) const
a16721e changed: move scraper libraries to cpluff
spiff_ authored
616 {
9d9704e cleanup: Make <supportedcontent> and <platform> use the same xs:list …
jmarshallnz authored
617 if (!base || !path)
618 return false;
619 CStdString all = m_cpluff->lookup_cfg_value(base, path);
620 if (all.IsEmpty())
621 return false;
622 StringUtils::SplitString(all, " ", result);
623 return true;
a16721e changed: move scraper libraries to cpluff
spiff_ authored
624 }
625
2bf2640 added: Functions for sanity checking addons (platform checks and igno…
jmarshallnz authored
626 AddonPtr CAddonMgr::GetAddonFromDescriptor(const cp_plugin_info_t *info)
627 {
46bdb17 allow addons with no extensions to be returned for dependency checking
Jonathan Marshall authored
628 if (!info)
2bf2640 added: Functions for sanity checking addons (platform checks and igno…
jmarshallnz authored
629 return AddonPtr();
630
46bdb17 allow addons with no extensions to be returned for dependency checking
Jonathan Marshall authored
631 if (!info->extensions)
632 { // no extensions, so we need only the dep information
633 return AddonPtr(new CAddon(info));
634 }
635
2bf2640 added: Functions for sanity checking addons (platform checks and igno…
jmarshallnz authored
636 // FIXME: If we want to support multiple extension points per addon, we'll need to extend this to not just take
637 // the first extension point (eg use the TYPE information we pass in)
638
639 // grab a relevant extension point, ignoring our xbmc.addon.metadata extension point
28cd382 fixed: sanity is not just a state of mind...
jmarshallnz authored
640 for (unsigned int i = 0; i < info->num_extensions; ++i)
2bf2640 added: Functions for sanity checking addons (platform checks and igno…
jmarshallnz authored
641 {
642 if (0 != strcmp("xbmc.addon.metadata", info->extensions[i].ext_point_id))
643 { // note that Factory takes care of whether or not we have platform support
644 return Factory(&info->extensions[i]);
645 }
646 }
647 return AddonPtr();
648 }
649
650 // FIXME: This function may not be required
5bca9c0 cleanup: Rename and document the cpluff versions of loading addon des…
jmarshallnz authored
651 bool CAddonMgr::LoadAddonDescription(const CStdString &path, AddonPtr &addon)
92afa2e fixed: Addons weren't installed correctly
jmarshallnz authored
652 {
653 cp_status_t status;
654 cp_plugin_info_t *info = m_cpluff->load_plugin_descriptor(m_cp_context, _P(path).c_str(), &status);
655 if (info)
656 {
2bf2640 added: Functions for sanity checking addons (platform checks and igno…
jmarshallnz authored
657 addon = GetAddonFromDescriptor(info);
92afa2e fixed: Addons weren't installed correctly
jmarshallnz authored
658 m_cpluff->release_info(m_cp_context, info);
9785be9 cleanup: Got rid of ADDON_SCRIPT_LIBRARY, compile warnings, and cosme…
jmarshallnz authored
659 return NULL != addon.get();
92afa2e fixed: Addons weren't installed correctly
jmarshallnz authored
660 }
661 return false;
662 }
663
5bca9c0 cleanup: Rename and document the cpluff versions of loading addon des…
jmarshallnz authored
664 bool CAddonMgr::AddonsFromRepoXML(const TiXmlElement *root, VECADDONS &addons)
4488d3a changed: Allow repository to have c-pluff XML files
jmarshallnz authored
665 {
666 // create a context for these addons
667 cp_status_t status;
668 cp_context_t *context = m_cpluff->create_context(&status);
669 if (!root || !context)
670 return false;
671
cfe53d3 fixed: Put the UTF-8 descriptor on the XML before feeding it to c-pluff
jmarshallnz authored
672 // each addon XML should have a UTF-8 declaration
673 TiXmlDeclaration decl("1.0", "UTF-8", "");
4488d3a changed: Allow repository to have c-pluff XML files
jmarshallnz authored
674 const TiXmlElement *element = root->FirstChildElement("addon");
675 while (element)
676 {
cfe53d3 fixed: Put the UTF-8 descriptor on the XML before feeding it to c-pluff
jmarshallnz authored
677 // dump the XML back to text
4488d3a changed: Allow repository to have c-pluff XML files
jmarshallnz authored
678 std::string xml;
cfe53d3 fixed: Put the UTF-8 descriptor on the XML before feeding it to c-pluff
jmarshallnz authored
679 xml << decl;
4488d3a changed: Allow repository to have c-pluff XML files
jmarshallnz authored
680 xml << *element;
681 cp_status_t status;
cd2be2f added: Expose cp_load_plugin_descriptor and separate out the from_mem…
jmarshallnz authored
682 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
683 if (info)
684 {
2bf2640 added: Functions for sanity checking addons (platform checks and igno…
jmarshallnz authored
685 AddonPtr addon = GetAddonFromDescriptor(info);
ed51e37 fixed: check for NULL before adding the addon in AddonsFromInfoXML
jmarshallnz authored
686 if (addon.get())
687 addons.push_back(addon);
2bf2640 added: Functions for sanity checking addons (platform checks and igno…
jmarshallnz authored
688 m_cpluff->release_info(context, info);
4488d3a changed: Allow repository to have c-pluff XML files
jmarshallnz authored
689 }
690 element = element->NextSiblingElement("addon");
691 }
692 m_cpluff->destroy_context(context);
693 return true;
694 }
695
a388e47 added: function to parse an addon descriptor from memory
Jonathan Marshall authored
696 bool CAddonMgr::LoadAddonDescriptionFromMemory(const TiXmlElement *root, AddonPtr &addon)
697 {
698 // create a context for these addons
699 cp_status_t status;
700 cp_context_t *context = m_cpluff->create_context(&status);
701 if (!root || !context)
702 return false;
703
704 // dump the XML back to text
705 std::string xml;
706 xml << TiXmlDeclaration("1.0", "UTF-8", "");
707 xml << *root;
708 cp_plugin_info_t *info = m_cpluff->load_plugin_descriptor_from_memory(context, xml.c_str(), xml.size(), &status);
709 if (info)
710 {
711 addon = GetAddonFromDescriptor(info);
712 m_cpluff->release_info(context, info);
713 }
714 m_cpluff->destroy_context(context);
715 return addon != NULL;
716 }
717
b55ac44 added: service addons.
blinkseb authored
718 bool CAddonMgr::StartServices()
719 {
720 CLog::Log(LOGDEBUG, "ADDON: Starting service addons.");
721
722 VECADDONS services;
723 if (!GetAddons(ADDON_SERVICE, services))
724 return false;
725
726 bool ret = true;
727 for (IVECADDONS it = services.begin(); it != services.end(); ++it)
728 {
729 boost::shared_ptr<CService> service = boost::dynamic_pointer_cast<CService>(*it);
730 if (service)
731 ret &= service->Start();
732 }
733
734 return ret;
735 }
736
737 void CAddonMgr::StopServices()
738 {
739 CLog::Log(LOGDEBUG, "ADDON: Stopping service addons.");
740
741 VECADDONS services;
742 if (!GetAddons(ADDON_SERVICE, services))
743 return;
744
745 for (IVECADDONS it = services.begin(); it != services.end(); ++it)
746 {
747 boost::shared_ptr<CService> service = boost::dynamic_pointer_cast<CService>(*it);
748 if (service)
749 service->Stop();
750 }
751 }
752
1b2781c added: basic cpluff support
alcoheca authored
753 int cp_to_clog(cp_log_severity_t lvl)
754 {
dec0bfe changed: sanitize the cpluff logging levels
jmarshallnz authored
755 if (lvl >= CP_LOG_ERROR)
756 return LOGINFO;
757 return LOGDEBUG;
1b2781c added: basic cpluff support
alcoheca authored
758 }
759
760 cp_log_severity_t clog_to_cp(int lvl)
761 {
dec0bfe changed: sanitize the cpluff logging levels
jmarshallnz authored
762 if (lvl >= LOG_LEVEL_DEBUG)
1b2781c added: basic cpluff support
alcoheca authored
763 return CP_LOG_INFO;
dec0bfe changed: sanitize the cpluff logging levels
jmarshallnz authored
764 return CP_LOG_ERROR;
1b2781c added: basic cpluff support
alcoheca authored
765 }
766
b6f0f59 cleanup: Don't expose the AddonManager's privates when not required.
jmarshallnz authored
767 void cp_fatalErrorHandler(const char *msg)
768 {
769 CLog::Log(LOGERROR, "ADDONS: CPluffFatalError(%s)", msg);
770 }
771
772 void cp_logger(cp_log_severity_t level, const char *msg, const char *apid, void *user_data)
1b2781c added: basic cpluff support
alcoheca authored
773 {
774 if(!apid)
5b793b6 added: missing change from r29798
alcoheca authored
775 CLog::Log(cp_to_clog(level), "ADDON: cpluff: '%s'", msg);
1b2781c added: basic cpluff support
alcoheca authored
776 else
5b793b6 added: missing change from r29798
alcoheca authored
777 CLog::Log(cp_to_clog(level), "ADDON: cpluff: '%s' reports '%s'", apid, msg);
1b2781c added: basic cpluff support
alcoheca authored
778 }
779
074db86 merged: addons-fw branch
elupus authored
780 } /* namespace ADDON */
781
Something went wrong with that request. Please try again.