Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 736 lines (659 sloc) 20.906 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:
83 case ADDON_SCRIPT:
9a8454a added: script support to media windows. Scripts should use the same exte...
jmarshallnz authored
84 return AddonPtr(new CPluginSource(props));
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:
9d4264e added: Initial support for python module addons.
jmarshallnz authored
89 case ADDON_SCRIPT_MODULE:
113777a merged: r33383,r33386 from webinterface branch
jmarshallnz authored
90 case ADDON_WEB_INTERFACE:
257d969 changed: Move Addon constructors to take the extension point they're act...
jmarshallnz authored
91 return AddonPtr(new CAddon(props));
6a9704f changed: Split scrapers into separate extension points per content type....
jmarshallnz authored
92 case ADDON_SCRAPER_ALBUMS:
93 case ADDON_SCRAPER_ARTISTS:
94 case ADDON_SCRAPER_MOVIES:
95 case ADDON_SCRAPER_MUSICVIDEOS:
96 case ADDON_SCRAPER_TVSHOWS:
97 case ADDON_SCRAPER_LIBRARY:
257d969 changed: Move Addon constructors to take the extension point they're act...
jmarshallnz authored
98 return AddonPtr(new CScraper(props));
1b2781c added: basic cpluff support
alcoheca authored
99 case ADDON_VIZ:
100 case ADDON_SCREENSAVER:
c14bf20 changed: moved addonptr factory to CAddonMgr.
alcoheca authored
101 { // begin temporary platform handling for Dlls
102 // ideally platforms issues will be handled by C-Pluff
103 // this is not an attempt at a solution
104 CStdString value;
0cefd50 changed: Moved builtin screensavers to addons so that we can utilize the...
jmarshallnz authored
105 if (type == ADDON_SCREENSAVER && 0 == strnicmp(props->plugin->identifier, "screensaver.xbmc.builtin.", 25))
106 { // built in screensaver
107 return AddonPtr(new CAddon(props));
108 }
c14bf20 changed: moved addonptr factory to CAddonMgr.
alcoheca authored
109 #if defined(_LINUX) && !defined(__APPLE__)
110 if ((value = GetExtValue(props->plugin->extensions->configuration, "@library_linux")) && value.empty())
111 break;
112 #elif defined(_WIN32) && defined(HAS_SDL_OPENGL)
113 if ((value = GetExtValue(props->plugin->extensions->configuration, "@library_wingl")) && value.empty())
114 break;
115 #elif defined(_WIN32) && defined(HAS_DX)
116 if ((value = GetExtValue(props->plugin->extensions->configuration, "@library_windx")) && value.empty())
117 break;
118 #elif defined(__APPLE__)
119 if ((value = GetExtValue(props->plugin->extensions->configuration, "@library_osx")) && value.empty())
120 break;
121 #elif defined(_XBOX)
122 if ((value = GetExtValue(props->plugin->extensions->configuration, "@library_xbox")) && value.empty())
123 break;
124 #endif
125 if (type == ADDON_VIZ)
07e5742 [arm] merge arm-camelot into trunk, thanks to mcgeagh for all his hard w...
davilla authored
126 {
127 #if defined(HAS_VISUALISATION)
257d969 changed: Move Addon constructors to take the extension point they're act...
jmarshallnz authored
128 return AddonPtr(new CVisualisation(props));
07e5742 [arm] merge arm-camelot into trunk, thanks to mcgeagh for all his hard w...
davilla authored
129 #endif
130 }
c14bf20 changed: moved addonptr factory to CAddonMgr.
alcoheca authored
131 else
257d969 changed: Move Addon constructors to take the extension point they're act...
jmarshallnz authored
132 return AddonPtr(new CScreenSaver(props));
c14bf20 changed: moved addonptr factory to CAddonMgr.
alcoheca authored
133 }
5ff028a added: skin support via cpluff
alcoheca authored
134 case ADDON_SKIN:
257d969 changed: Move Addon constructors to take the extension point they're act...
jmarshallnz authored
135 return AddonPtr(new CSkinInfo(props));
1b2781c added: basic cpluff support
alcoheca authored
136 case ADDON_VIZ_LIBRARY:
257d969 changed: Move Addon constructors to take the extension point they're act...
jmarshallnz authored
137 return AddonPtr(new CAddonLibrary(props));
9ea9065 changed: Move repositories to cpluff
jmarshallnz authored
138 case ADDON_REPOSITORY:
257d969 changed: Move Addon constructors to take the extension point they're act...
jmarshallnz authored
139 return AddonPtr(new CRepository(props));
1b2781c added: basic cpluff support
alcoheca authored
140 default:
c14bf20 changed: moved addonptr factory to CAddonMgr.
alcoheca authored
141 break;
1b2781c added: basic cpluff support
alcoheca authored
142 }
c14bf20 changed: moved addonptr factory to CAddonMgr.
alcoheca authored
143 return AddonPtr();
1b2781c added: basic cpluff support
alcoheca authored
144 }
145
bb4e01c Support creating userdirs in addons. This also has the benefit of being ...
ceros7 authored
146 bool CAddonMgr::CheckUserDirs(const cp_cfg_element_t *settings)
147 {
148 if (!settings)
149 return false;
150
151 const cp_cfg_element_t *userdirs = GetExtElement((cp_cfg_element_t *)settings, "userdirs");
152 if (!userdirs)
153 return false;
154
155 DEQUEELEMENTS elements;
156 bool status = GetExtElementDeque(elements, (cp_cfg_element_t *)userdirs, "userdir");
157 if (!status)
158 return false;
159
160 IDEQUEELEMENTS itr = elements.begin();
161 while (itr != elements.end())
162 {
163 CStdString path = GetExtValue(*itr++, "@path");
164 if (!CFile::Exists(path))
165 {
166 if (!CUtil::CreateDirectoryEx(path))
167 {
168 CLog::Log(LOGERROR, "CAddonMgr::CheckUserDirs: Unable to create directory %s.", path.c_str());
169 return false;
170 }
171 }
172 }
173
174 return true;
175 }
176
074db86 merged: addons-fw branch
elupus authored
177 CAddonMgr::CAddonMgr()
178 {
179 }
180
181 CAddonMgr::~CAddonMgr()
182 {
37a994e added: Deinit to the addons manager to ensure we unload cpluff prior to ...
jmarshallnz authored
183 DeInit();
074db86 merged: addons-fw branch
elupus authored
184 }
185
47a8196 changed: matched other singelton calls
alcoheca authored
186 CAddonMgr &CAddonMgr::Get()
074db86 merged: addons-fw branch
elupus authored
187 {
47a8196 changed: matched other singelton calls
alcoheca authored
188 static CAddonMgr sAddonMgr;
189 return sAddonMgr;
074db86 merged: addons-fw branch
elupus authored
190 }
191
192 IAddonMgrCallback* CAddonMgr::GetCallbackForType(TYPE type)
193 {
194 if (m_managers.find(type) == m_managers.end())
195 return NULL;
196 else
197 return m_managers[type];
198 }
199
200 bool CAddonMgr::RegisterAddonMgrCallback(const TYPE type, IAddonMgrCallback* cb)
201 {
202 if (cb == NULL)
203 return false;
204
205 m_managers.erase(type);
206 m_managers[type] = cb;
207
208 return true;
209 }
210
211 void CAddonMgr::UnregisterAddonMgrCallback(TYPE type)
212 {
213 m_managers.erase(type);
214 }
215
1b2781c added: basic cpluff support
alcoheca authored
216 bool CAddonMgr::Init()
217 {
218 m_cpluff = new DllLibCPluff;
219 m_cpluff->Load();
220
b700e3f changed: Hold the addons database as a member in the AddonManager. Shou...
jmarshallnz authored
221 m_database.Open();
222
1b2781c added: basic cpluff support
alcoheca authored
223 if (!m_cpluff->IsLoaded())
224 {
b6076e5 changed: screensavers are now supported via cpluff schema
alcoheca authored
225 CLog::Log(LOGERROR, "ADDONS: Fatal Error, could not load libcpluff");
226 return false;
1b2781c added: basic cpluff support
alcoheca authored
227 }
228
229 m_cpluff->set_fatal_error_handler(cp_fatalErrorHandler);
230
231 cp_status_t status;
232 status = m_cpluff->init();
233 if (status != CP_OK)
234 {
235 CLog::Log(LOGERROR, "ADDONS: Fatal Error, cp_init() returned status: %i", status);
b6076e5 changed: screensavers are now supported via cpluff schema
alcoheca authored
236 return false;
1b2781c added: basic cpluff support
alcoheca authored
237 }
238
239 //TODO could separate addons into different contexts
240 // would allow partial unloading of addon framework
241 m_cp_context = m_cpluff->create_context(&status);
242 assert(m_cp_context);
7cef07e cleanup: remove unused XBMCIsHome function, now that they're no longer t...
jmarshallnz authored
243 status = m_cpluff->register_pcollection(m_cp_context, _P("special://home/addons"));
b6076e5 changed: screensavers are now supported via cpluff schema
alcoheca authored
244 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 pytho...
althekiller authored
245 status = m_cpluff->register_pcollection(m_cp_context, _P("special://xbmcbin/addons"));
b6076e5 changed: screensavers are now supported via cpluff schema
alcoheca authored
246 if (status != CP_OK)
247 {
248 CLog::Log(LOGERROR, "ADDONS: Fatal Error, cp_register_pcollection() returned status: %i", status);
249 return false;
1b2781c added: basic cpluff support
alcoheca authored
250 }
b6076e5 changed: screensavers are now supported via cpluff schema
alcoheca authored
251
185686a added: even more missing from r29798
alcoheca authored
252 status = m_cpluff->register_logger(m_cp_context, cp_logger,
7188808 changed: bail out immeditaly if CAddonMgr::Init returns false
alcoheca authored
253 &CAddonMgr::Get(), clog_to_cp(g_advancedSettings.m_logLevel));
b6076e5 changed: screensavers are now supported via cpluff schema
alcoheca authored
254 if (status != CP_OK)
255 {
256 CLog::Log(LOGERROR, "ADDONS: Fatal Error, cp_register_logger() returned status: %i", status);
257 return false;
258 }
1b2781c added: basic cpluff support
alcoheca authored
259
f0b69e1 changed: move the cpluff plugin scanner call to findaddons
spiff_ authored
260 FindAddons();
b6076e5 changed: screensavers are now supported via cpluff schema
alcoheca authored
261 return true;
1b2781c added: basic cpluff support
alcoheca authored
262 }
263
37a994e added: Deinit to the addons manager to ensure we unload cpluff prior to ...
jmarshallnz authored
264 void CAddonMgr::DeInit()
265 {
266 if (m_cpluff)
267 m_cpluff->destroy();
268 m_cpluff = NULL;
b700e3f changed: Hold the addons database as a member in the AddonManager. Shou...
jmarshallnz authored
269 m_database.Close();
37a994e added: Deinit to the addons manager to ensure we unload cpluff prior to ...
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 them ...
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 in ...
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 them ...
jmarshallnz authored
284 if (!allowRepos && ADDON_REPOSITORY == (TYPE)i)
816cf12 fixed: Get weather, subtitles, lyrics and library scripts to show up in ...
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 in ...
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 with ...
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 add...
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 add...
jmarshallnz authored
331 AddonPtr addon(Factory(exts[i]));
b700e3f changed: Hold the addons database as a member in the AddonManager. Shou...
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 add...
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 add...
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 sc...
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 ignorin...
jmarshallnz authored
345 if (status == CP_OK && cpaddon)
c22f535 cosmetics
alcoheca authored
346 {
2bf2640 added: Functions for sanity checking addons (platform checks and ignorin...
jmarshallnz authored
347 addon = GetAddonFromDescriptor(cpaddon);
c22f535 cosmetics
alcoheca authored
348 m_cpluff->release_info(m_cp_context, cpaddon);
ec6e50b fixed: make sure addon is valid before use
CrystalPT authored
349 if (addon.get() && enabledOnly && m_database.IsAddonDisabled(addon->ID()))
83a5edb fixed: Ensure the context menu in the addon manager is consistent (no sc...
jmarshallnz authored
350 return false;
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 act...
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 type....
jmarshallnz authored
363 switch (type)
074db86 merged: addons-fw branch
elupus authored
364 {
6a9704f changed: Split scrapers into separate extension points per content type....
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 ad...
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 type....
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 scraper...
jmarshallnz authored
373 break;
6a9704f changed: Split scrapers into separate extension points per content type....
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 type....
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 type....
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 type....
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 type....
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 type....
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/addons o...
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 ad...
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 add...
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 di...
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.addon....
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 extension...
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));
6a9704f changed: Split scrapers into separate extension points per content type....
jmarshallnz authored
484 case ADDON_SCRAPER_ALBUMS:
485 case ADDON_SCRAPER_ARTISTS:
486 case ADDON_SCRAPER_MOVIES:
487 case ADDON_SCRAPER_MUSICVIDEOS:
488 case ADDON_SCRAPER_TVSHOWS:
489 case ADDON_SCRAPER_LIBRARY:
eca3c5b changed: refactor
spiff_ authored
490 return AddonPtr(new CScraper(addonProps));
553d213 changed: finished moving skins to addon framework
alcoheca authored
491 case ADDON_SKIN:
492 return AddonPtr(new CSkinInfo(addonProps));
07e5742 [arm] merge arm-camelot into trunk, thanks to mcgeagh for all his hard w...
davilla authored
493 #if defined(HAS_VISUALISATION)
af8cb2a Revert "wip"
alcoheca authored
494 case ADDON_VIZ:
eca3c5b changed: refactor
spiff_ authored
495 return AddonPtr(new CVisualisation(addonProps));
07e5742 [arm] merge arm-camelot into trunk, thanks to mcgeagh for all his hard w...
davilla authored
496 #endif
af8cb2a Revert "wip"
alcoheca authored
497 case ADDON_SCREENSAVER:
eca3c5b changed: refactor
spiff_ authored
498 return AddonPtr(new CScreenSaver(addonProps));
af8cb2a Revert "wip"
alcoheca authored
499 case ADDON_VIZ_LIBRARY:
eca3c5b changed: refactor
spiff_ authored
500 return AddonPtr(new CAddonLibrary(addonProps));
606248f added: addon repository class
spiff_ authored
501 case ADDON_REPOSITORY:
502 return AddonPtr(new CRepository(addonProps));
af8cb2a Revert "wip"
alcoheca authored
503 default:
eca3c5b changed: refactor
spiff_ authored
504 break;
af8cb2a Revert "wip"
alcoheca authored
505 }
eca3c5b changed: refactor
spiff_ authored
506 return AddonPtr();
af8cb2a Revert "wip"
alcoheca authored
507 }
508
772d686 added: built-in XBMC.UpdateAddonRepos to force an update of enabled add-...
vdrfan authored
509 void CAddonMgr::UpdateRepos(bool force)
639b314 changed: move addonbrowser to a mediawindow derivate
spiff_ authored
510 {
511 CSingleLock lock(m_critSection);
772d686 added: built-in XBMC.UpdateAddonRepos to force an update of enabled add-...
vdrfan authored
512 if (!force && m_watch.IsRunning() && m_watch.GetElapsedSeconds() < 600)
639b314 changed: move addonbrowser to a mediawindow derivate
spiff_ authored
513 return;
514 m_watch.StartZero();
515 VECADDONS addons;
516 GetAddons(ADDON_REPOSITORY,addons);
517 for (unsigned int i=0;i<addons.size();++i)
518 {
519 RepositoryPtr repo = boost::dynamic_pointer_cast<CRepository>(addons[i]);
c4f8e76 changed: Have UpdateRepos() use it's db member to fetch the repo timesta...
jmarshallnz authored
520 CDateTime lastUpdate = m_database.GetRepoTimestamp(repo->ID());
772d686 added: built-in XBMC.UpdateAddonRepos to force an update of enabled add-...
vdrfan authored
521 if (force || !lastUpdate.IsValid() || lastUpdate + CDateTimeSpan(0,6,0,0) < CDateTime::GetCurrentDateTime())
639b314 changed: move addonbrowser to a mediawindow derivate
spiff_ authored
522 {
523 CLog::Log(LOGDEBUG,"Checking repository %s for updates",repo->Name().c_str());
6dadda1 cleanup: Get rid of needless additional SetRepoTimestamp after retrievin...
jmarshallnz authored
524 CJobManager::GetInstance().AddJob(new CRepositoryUpdateJob(repo), NULL);
639b314 changed: move addonbrowser to a mediawindow derivate
spiff_ authored
525 }
526 }
527 }
528
1b2781c added: basic cpluff support
alcoheca authored
529 /*
530 * libcpluff interaction
531 */
532
2bf2640 added: Functions for sanity checking addons (platform checks and ignorin...
jmarshallnz authored
533 bool CAddonMgr::PlatformSupportsAddon(const cp_plugin_info_t *plugin) const
534 {
535 if (!plugin || !plugin->num_extensions)
536 return false;
537 const cp_extension_t *metadata = GetExtension(plugin, "xbmc.addon.metadata");
9d9704e cleanup: Make <supportedcontent> and <platform> use the same xs:list sty...
jmarshallnz authored
538 if (!metadata)
539 return false;
540
541 vector<CStdString> platforms;
542 if (CAddonMgr::Get().GetExtList(metadata->configuration, "platform", platforms))
2bf2640 added: Functions for sanity checking addons (platform checks and ignorin...
jmarshallnz authored
543 {
544 for (unsigned int i = 0; i < platforms.size(); ++i)
545 {
546 if (platforms[i] == "all")
547 return true;
548 #if defined(_LINUX) && !defined(__APPLE__)
549 if (platforms[i] == "linux")
550 #elif defined(_WIN32) && defined(HAS_SDL_OPENGL)
551 if (platforms[i] == "wingl")
552 #elif defined(_WIN32) && defined(HAS_DX)
553 if (platforms[i] == "windx")
554 #elif defined(__APPLE__)
555 if (platforms[i] == "osx")
556 #endif
557 return true;
558 }
9d9704e cleanup: Make <supportedcontent> and <platform> use the same xs:list sty...
jmarshallnz authored
559 return false; // no <platform> works for us
2bf2640 added: Functions for sanity checking addons (platform checks and ignorin...
jmarshallnz authored
560 }
9d9704e cleanup: Make <supportedcontent> and <platform> use the same xs:list sty...
jmarshallnz authored
561 return true; // assume no <platform> is equivalent to <platform>all</platform>
2bf2640 added: Functions for sanity checking addons (platform checks and ignorin...
jmarshallnz authored
562 }
563
bb4e01c Support creating userdirs in addons. This also has the benefit of being ...
ceros7 authored
564 const cp_cfg_element_t *CAddonMgr::GetExtElement(cp_cfg_element_t *base, const char *path)
565 {
566 const cp_cfg_element_t *element = NULL;
567 if (base)
568 element = m_cpluff->lookup_cfg_element(base, path);
569 return element;
570 }
571
572 /* Returns all duplicate elements from a base element */
16b848a added: CPluginSource class for all pluginsource addons
alcoheca authored
573 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
574 {
575 if (!base)
576 return false;
577
578 unsigned int i = 0;
579 while (true)
580 {
581 if (i >= base->num_children)
582 break;
583 CStdString temp = (base->children+i)->name;
584 if (!temp.compare(path))
585 elements.push_back(base->children+i);
586 i++;
587 }
588
589 if (elements.empty()) return false;
590 return true;
591 }
592
2bf2640 added: Functions for sanity checking addons (platform checks and ignorin...
jmarshallnz authored
593 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
594 {
595 if (!props)
596 return NULL;
597 for (unsigned int i = 0; i < props->num_extensions; ++i)
598 {
599 if (0 == strcmp(props->extensions[i].ext_point_id, extension))
600 return &props->extensions[i];
601 }
602 return NULL;
603 }
604
a16721e changed: move scraper libraries to cpluff
spiff_ authored
605 ADDONDEPS CAddonMgr::GetDeps(const CStdString &id)
606 {
607 ADDONDEPS result;
608 cp_status_t status;
609
610 cp_plugin_info_t *info = m_cpluff->get_plugin_info(m_cp_context,id.c_str(),&status);
611 if (info)
612 {
613 for (unsigned int i=0;i<info->num_imports;++i)
614 result.insert(make_pair(CStdString(info->imports[i].plugin_id),
615 make_pair(AddonVersion(info->version),
616 AddonVersion(info->version))));
bb067ed fixed: Don't return true from GetAddon, and ensure we release the c-pluf...
jmarshallnz authored
617 m_cpluff->release_info(m_cp_context, info);
a16721e changed: move scraper libraries to cpluff
spiff_ authored
618 }
619
620 return result;
621 }
622
b6076e5 changed: screensavers are now supported via cpluff schema
alcoheca authored
623 CStdString CAddonMgr::GetExtValue(cp_cfg_element_t *base, const char *path)
624 {
625 const char *value = NULL;
626 if (base && (value = m_cpluff->lookup_cfg_value(base, path)))
627 return CStdString(value);
628 else return CStdString();
629 }
630
9d9704e cleanup: Make <supportedcontent> and <platform> use the same xs:list sty...
jmarshallnz authored
631 bool CAddonMgr::GetExtList(cp_cfg_element_t *base, const char *path, vector<CStdString> &result) const
a16721e changed: move scraper libraries to cpluff
spiff_ authored
632 {
9d9704e cleanup: Make <supportedcontent> and <platform> use the same xs:list sty...
jmarshallnz authored
633 if (!base || !path)
634 return false;
635 CStdString all = m_cpluff->lookup_cfg_value(base, path);
636 if (all.IsEmpty())
637 return false;
638 StringUtils::SplitString(all, " ", result);
639 return true;
a16721e changed: move scraper libraries to cpluff
spiff_ authored
640 }
641
2bf2640 added: Functions for sanity checking addons (platform checks and ignorin...
jmarshallnz authored
642 AddonPtr CAddonMgr::GetAddonFromDescriptor(const cp_plugin_info_t *info)
643 {
644 if (!info || !info->extensions)
645 return AddonPtr();
646
647 // FIXME: If we want to support multiple extension points per addon, we'll need to extend this to not just take
648 // the first extension point (eg use the TYPE information we pass in)
649
650 // grab a relevant extension point, ignoring our xbmc.addon.metadata extension point
28cd382 fixed: sanity is not just a state of mind...
jmarshallnz authored
651 for (unsigned int i = 0; i < info->num_extensions; ++i)
2bf2640 added: Functions for sanity checking addons (platform checks and ignorin...
jmarshallnz authored
652 {
653 if (0 != strcmp("xbmc.addon.metadata", info->extensions[i].ext_point_id))
654 { // note that Factory takes care of whether or not we have platform support
655 return Factory(&info->extensions[i]);
656 }
657 }
658 return AddonPtr();
659 }
660
661 // FIXME: This function may not be required
5bca9c0 cleanup: Rename and document the cpluff versions of loading addon descri...
jmarshallnz authored
662 bool CAddonMgr::LoadAddonDescription(const CStdString &path, AddonPtr &addon)
92afa2e fixed: Addons weren't installed correctly
jmarshallnz authored
663 {
664 cp_status_t status;
665 cp_plugin_info_t *info = m_cpluff->load_plugin_descriptor(m_cp_context, _P(path).c_str(), &status);
666 if (info)
667 {
2bf2640 added: Functions for sanity checking addons (platform checks and ignorin...
jmarshallnz authored
668 addon = GetAddonFromDescriptor(info);
92afa2e fixed: Addons weren't installed correctly
jmarshallnz authored
669 m_cpluff->release_info(m_cp_context, info);
9785be9 cleanup: Got rid of ADDON_SCRIPT_LIBRARY, compile warnings, and cosmetic...
jmarshallnz authored
670 return NULL != addon.get();
92afa2e fixed: Addons weren't installed correctly
jmarshallnz authored
671 }
672 return false;
673 }
674
5bca9c0 cleanup: Rename and document the cpluff versions of loading addon descri...
jmarshallnz authored
675 bool CAddonMgr::AddonsFromRepoXML(const TiXmlElement *root, VECADDONS &addons)
4488d3a changed: Allow repository to have c-pluff XML files
jmarshallnz authored
676 {
677 // create a context for these addons
678 cp_status_t status;
679 cp_context_t *context = m_cpluff->create_context(&status);
680 if (!root || !context)
681 return false;
682
cfe53d3 fixed: Put the UTF-8 descriptor on the XML before feeding it to c-pluff
jmarshallnz authored
683 // each addon XML should have a UTF-8 declaration
684 TiXmlDeclaration decl("1.0", "UTF-8", "");
4488d3a changed: Allow repository to have c-pluff XML files
jmarshallnz authored
685 const TiXmlElement *element = root->FirstChildElement("addon");
686 while (element)
687 {
cfe53d3 fixed: Put the UTF-8 descriptor on the XML before feeding it to c-pluff
jmarshallnz authored
688 // dump the XML back to text
4488d3a changed: Allow repository to have c-pluff XML files
jmarshallnz authored
689 std::string xml;
cfe53d3 fixed: Put the UTF-8 descriptor on the XML before feeding it to c-pluff
jmarshallnz authored
690 xml << decl;
4488d3a changed: Allow repository to have c-pluff XML files
jmarshallnz authored
691 xml << *element;
692 cp_status_t status;
cd2be2f added: Expose cp_load_plugin_descriptor and separate out the from_memory...
jmarshallnz authored
693 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
694 if (info)
695 {
2bf2640 added: Functions for sanity checking addons (platform checks and ignorin...
jmarshallnz authored
696 AddonPtr addon = GetAddonFromDescriptor(info);
ed51e37 fixed: check for NULL before adding the addon in AddonsFromInfoXML
jmarshallnz authored
697 if (addon.get())
698 addons.push_back(addon);
2bf2640 added: Functions for sanity checking addons (platform checks and ignorin...
jmarshallnz authored
699 m_cpluff->release_info(context, info);
4488d3a changed: Allow repository to have c-pluff XML files
jmarshallnz authored
700 }
701 element = element->NextSiblingElement("addon");
702 }
703 m_cpluff->destroy_context(context);
704 return true;
705 }
706
1b2781c added: basic cpluff support
alcoheca authored
707 int cp_to_clog(cp_log_severity_t lvl)
708 {
dec0bfe changed: sanitize the cpluff logging levels
jmarshallnz authored
709 if (lvl >= CP_LOG_ERROR)
710 return LOGINFO;
711 return LOGDEBUG;
1b2781c added: basic cpluff support
alcoheca authored
712 }
713
714 cp_log_severity_t clog_to_cp(int lvl)
715 {
dec0bfe changed: sanitize the cpluff logging levels
jmarshallnz authored
716 if (lvl >= LOG_LEVEL_DEBUG)
1b2781c added: basic cpluff support
alcoheca authored
717 return CP_LOG_INFO;
dec0bfe changed: sanitize the cpluff logging levels
jmarshallnz authored
718 return CP_LOG_ERROR;
1b2781c added: basic cpluff support
alcoheca authored
719 }
720
b6f0f59 cleanup: Don't expose the AddonManager's privates when not required.
jmarshallnz authored
721 void cp_fatalErrorHandler(const char *msg)
722 {
723 CLog::Log(LOGERROR, "ADDONS: CPluffFatalError(%s)", msg);
724 }
725
726 void cp_logger(cp_log_severity_t level, const char *msg, const char *apid, void *user_data)
1b2781c added: basic cpluff support
alcoheca authored
727 {
728 if(!apid)
5b793b6 added: missing change from r29798
alcoheca authored
729 CLog::Log(cp_to_clog(level), "ADDON: cpluff: '%s'", msg);
1b2781c added: basic cpluff support
alcoheca authored
730 else
5b793b6 added: missing change from r29798
alcoheca authored
731 CLog::Log(cp_to_clog(level), "ADDON: cpluff: '%s' reports '%s'", apid, msg);
1b2781c added: basic cpluff support
alcoheca authored
732 }
733
074db86 merged: addons-fw branch
elupus authored
734 } /* namespace ADDON */
735
Something went wrong with that request. Please try again.