Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 733 lines (656 sloc) 20.751 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
56aa69b added: Support for addons to be disabled while still being installed.
jmarshallnz authored
280 bool CAddonMgr::GetAllAddons(VECADDONS &addons, bool enabled /*= true*/)
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 {
284 if (ADDON_REPOSITORY == (TYPE)i)
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
56aa69b added: Support for addons to be disabled while still being installed.
jmarshallnz authored
339 bool CAddonMgr::GetAddon(const CStdString &str, AddonPtr &addon, const TYPE &type/*=ADDON_UNKNOWN*/, bool enabled/*= 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);
b700e3f changed: Hold the addons database as a member in the AddonManager. Shou...
jmarshallnz authored
349 return NULL != addon.get() && m_database.IsAddonDisabled(addon->ID()) != enabled;
c22f535 cosmetics
alcoheca authored
350 }
351 if (cpaddon)
352 m_cpluff->release_info(m_cp_context, cpaddon);
b6076e5 changed: screensavers are now supported via cpluff schema
alcoheca authored
353
074db86 merged: addons-fw branch
elupus authored
354 return false;
355 }
356
357 //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
358 bool CAddonMgr::GetDefault(const TYPE &type, AddonPtr &addon)
074db86 merged: addons-fw branch
elupus authored
359 {
360 CStdString setting;
6a9704f changed: Split scrapers into separate extension points per content type....
jmarshallnz authored
361 switch (type)
074db86 merged: addons-fw branch
elupus authored
362 {
6a9704f changed: Split scrapers into separate extension points per content type....
jmarshallnz authored
363 case ADDON_VIZ:
364 setting = g_guiSettings.GetString("musicplayer.visualisation");
365 break;
730b6da added: addon.set.default built-in to set the default for a particular ad...
jmarshallnz authored
366 case ADDON_SCREENSAVER:
367 setting = g_guiSettings.GetString("screensaver.mode");
368 break;
6a9704f changed: Split scrapers into separate extension points per content type....
jmarshallnz authored
369 case ADDON_SCRAPER_ALBUMS:
92be514 changed: rename these settings. type changed. update sad
spiff_ authored
370 setting = g_guiSettings.GetString("musiclibrary.albumsscraper");
c077443 changed: Split the music scraping into separate album and artist scraper...
jmarshallnz authored
371 break;
6a9704f changed: Split scrapers into separate extension points per content type....
jmarshallnz authored
372 case ADDON_SCRAPER_ARTISTS:
92be514 changed: rename these settings. type changed. update sad
spiff_ authored
373 setting = g_guiSettings.GetString("musiclibrary.artistsscraper");
6a9704f changed: Split scrapers into separate extension points per content type....
jmarshallnz authored
374 break;
375 case ADDON_SCRAPER_MOVIES:
92be514 changed: rename these settings. type changed. update sad
spiff_ authored
376 setting = g_guiSettings.GetString("scrapers.moviesdefault");
6a9704f changed: Split scrapers into separate extension points per content type....
jmarshallnz authored
377 break;
378 case ADDON_SCRAPER_MUSICVIDEOS:
92be514 changed: rename these settings. type changed. update sad
spiff_ authored
379 setting = g_guiSettings.GetString("scrapers.musicvideosdefault");
6a9704f changed: Split scrapers into separate extension points per content type....
jmarshallnz authored
380 break;
381 case ADDON_SCRAPER_TVSHOWS:
92be514 changed: rename these settings. type changed. update sad
spiff_ authored
382 setting = g_guiSettings.GetString("scrapers.tvshowsdefault");
6a9704f changed: Split scrapers into separate extension points per content type....
jmarshallnz authored
383 break;
113777a merged: r33383,r33386 from webinterface branch
jmarshallnz authored
384 case ADDON_WEB_INTERFACE:
385 setting = g_guiSettings.GetString("services.webskin");
386 break;
6a9704f changed: Split scrapers into separate extension points per content type....
jmarshallnz authored
387 default:
388 return false;
074db86 merged: addons-fw branch
elupus authored
389 }
2ca76f9 changed: all addons should be store below either special://home/addons o...
alcoheca authored
390 return GetAddon(setting, addon, type);
074db86 merged: addons-fw branch
elupus authored
391 }
392
730b6da added: addon.set.default built-in to set the default for a particular ad...
jmarshallnz authored
393 bool CAddonMgr::SetDefault(const TYPE &type, const CStdString &addonID)
394 {
395 switch (type)
396 {
397 case ADDON_VIZ:
398 g_guiSettings.SetString("musicplayer.visualisation",addonID);
399 break;
400 case ADDON_SCREENSAVER:
401 g_guiSettings.SetString("screensaver.mode",addonID);
402 break;
403 case ADDON_SCRAPER_ALBUMS:
404 g_guiSettings.SetString("musiclibrary.albumsscraper",addonID);
405 break;
406 case ADDON_SCRAPER_ARTISTS:
407 g_guiSettings.SetString("musiclibrary.artistsscraper",addonID);
408 break;
409 case ADDON_SCRAPER_MOVIES:
410 g_guiSettings.SetString("scrapers.moviesdefault",addonID);
411 break;
412 case ADDON_SCRAPER_MUSICVIDEOS:
413 g_guiSettings.SetString("scrapers.musicvideosdefault",addonID);
414 break;
415 case ADDON_SCRAPER_TVSHOWS:
416 g_guiSettings.SetString("scrapers.tvshowsdefault",addonID);
417 break;
418 default:
419 return false;
420 }
421
422 return true;
423 }
424
7411555 changed: renamed UUID to ID. we now accept any string as an identifier,
alcoheca authored
425 CStdString CAddonMgr::GetString(const CStdString &id, const int number)
074db86 merged: addons-fw branch
elupus authored
426 {
8c86aee cleanup: Get rid of some more old non-cpluff stuff. Should also fix add...
jmarshallnz authored
427 AddonPtr addon;
428 if (GetAddon(id, addon))
074db86 merged: addons-fw branch
elupus authored
429 return addon->GetString(number);
430
431 return "";
432 }
433
af8cb2a Revert "wip"
alcoheca authored
434 void CAddonMgr::FindAddons()
435 {
4e5b98a added: locks to addon manager
spiff_ authored
436 CSingleLock lock(m_critSection);
f0b69e1 changed: move the cpluff plugin scanner call to findaddons
spiff_ authored
437 if (m_cpluff && m_cp_context)
d8d145c fixed: update addon information after upgrade
ametovic authored
438 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
439 }
440
f1031c4 fixed: disabling addons
spiff_ authored
441 void CAddonMgr::RemoveAddon(const CStdString& ID)
442 {
443 if (m_cpluff && m_cp_context)
444 m_cpluff->uninstall_plugin(m_cp_context,ID.c_str());
445 }
446
096e8a3 changed: Move description information into addon.xml via the xbmc.addon....
jmarshallnz authored
447 const char *CAddonMgr::GetTranslatedString(const cp_cfg_element_t *root, const char *tag)
448 {
449 if (!root)
450 return NULL;
451
452 const cp_cfg_element_t *eng = NULL;
453 for (unsigned int i = 0; i < root->num_children; i++)
454 {
455 const cp_cfg_element_t &child = root->children[i];
456 if (strcmp(tag, child.name) == 0)
457 { // see if we have a "lang" attribute
458 const char *lang = m_cpluff->lookup_cfg_value((cp_cfg_element_t*)&child, "@lang");
459 if (lang && 0 == strcmp(lang,g_langInfo.GetDVDAudioLanguage().c_str()))
460 return child.value;
461 if (!lang || 0 == strcmp(lang, "en"))
462 eng = &child;
463 }
464 }
465 return (eng) ? eng->value : NULL;
466 }
467
eca3c5b changed: refactor
spiff_ authored
468 AddonPtr CAddonMgr::AddonFromProps(AddonProps& addonProps)
469 {
470 switch (addonProps.type)
af8cb2a Revert "wip"
alcoheca authored
471 {
472 case ADDON_PLUGIN:
473 case ADDON_SCRIPT:
15de189 fixed: Make sure ADDON_SCRIPT uses CPluginSource so that Provides works
jmarshallnz authored
474 return AddonPtr(new CPluginSource(addonProps));
35cf15f changed: get rid of the content types added earlier, favouring extension...
jmarshallnz authored
475 case ADDON_SCRIPT_LIBRARY:
476 case ADDON_SCRIPT_LYRICS:
477 case ADDON_SCRIPT_WEATHER:
478 case ADDON_SCRIPT_SUBTITLES:
9d4264e added: Initial support for python module addons.
jmarshallnz authored
479 case ADDON_SCRIPT_MODULE:
eca3c5b changed: refactor
spiff_ authored
480 return AddonPtr(new CAddon(addonProps));
6a9704f changed: Split scrapers into separate extension points per content type....
jmarshallnz authored
481 case ADDON_SCRAPER_ALBUMS:
482 case ADDON_SCRAPER_ARTISTS:
483 case ADDON_SCRAPER_MOVIES:
484 case ADDON_SCRAPER_MUSICVIDEOS:
485 case ADDON_SCRAPER_TVSHOWS:
486 case ADDON_SCRAPER_LIBRARY:
eca3c5b changed: refactor
spiff_ authored
487 return AddonPtr(new CScraper(addonProps));
553d213 changed: finished moving skins to addon framework
alcoheca authored
488 case ADDON_SKIN:
489 return AddonPtr(new CSkinInfo(addonProps));
07e5742 [arm] merge arm-camelot into trunk, thanks to mcgeagh for all his hard w...
davilla authored
490 #if defined(HAS_VISUALISATION)
af8cb2a Revert "wip"
alcoheca authored
491 case ADDON_VIZ:
eca3c5b changed: refactor
spiff_ authored
492 return AddonPtr(new CVisualisation(addonProps));
07e5742 [arm] merge arm-camelot into trunk, thanks to mcgeagh for all his hard w...
davilla authored
493 #endif
af8cb2a Revert "wip"
alcoheca authored
494 case ADDON_SCREENSAVER:
eca3c5b changed: refactor
spiff_ authored
495 return AddonPtr(new CScreenSaver(addonProps));
af8cb2a Revert "wip"
alcoheca authored
496 case ADDON_VIZ_LIBRARY:
eca3c5b changed: refactor
spiff_ authored
497 return AddonPtr(new CAddonLibrary(addonProps));
606248f added: addon repository class
spiff_ authored
498 case ADDON_REPOSITORY:
499 return AddonPtr(new CRepository(addonProps));
af8cb2a Revert "wip"
alcoheca authored
500 default:
eca3c5b changed: refactor
spiff_ authored
501 break;
af8cb2a Revert "wip"
alcoheca authored
502 }
eca3c5b changed: refactor
spiff_ authored
503 return AddonPtr();
af8cb2a Revert "wip"
alcoheca authored
504 }
505
639b314 changed: move addonbrowser to a mediawindow derivate
spiff_ authored
506 void CAddonMgr::UpdateRepos()
507 {
508 CSingleLock lock(m_critSection);
e0e60d9 fixed: update/fetch addon repositories on startup. fixes empty addons li...
vdrfan authored
509 if (m_watch.IsRunning() && m_watch.GetElapsedSeconds() < 600)
639b314 changed: move addonbrowser to a mediawindow derivate
spiff_ authored
510 return;
511 m_watch.StartZero();
512 VECADDONS addons;
513 GetAddons(ADDON_REPOSITORY,addons);
514 for (unsigned int i=0;i<addons.size();++i)
515 {
516 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
517 CDateTime lastUpdate = m_database.GetRepoTimestamp(repo->ID());
e0e60d9 fixed: update/fetch addon repositories on startup. fixes empty addons li...
vdrfan authored
518 if (!lastUpdate.IsValid() || lastUpdate + CDateTimeSpan(0,6,0,0) < CDateTime::GetCurrentDateTime())
639b314 changed: move addonbrowser to a mediawindow derivate
spiff_ authored
519 {
520 CLog::Log(LOGDEBUG,"Checking repository %s for updates",repo->Name().c_str());
6dadda1 cleanup: Get rid of needless additional SetRepoTimestamp after retrievin...
jmarshallnz authored
521 CJobManager::GetInstance().AddJob(new CRepositoryUpdateJob(repo), NULL);
639b314 changed: move addonbrowser to a mediawindow derivate
spiff_ authored
522 }
523 }
524 }
525
1b2781c added: basic cpluff support
alcoheca authored
526 /*
527 * libcpluff interaction
528 */
529
2bf2640 added: Functions for sanity checking addons (platform checks and ignorin...
jmarshallnz authored
530 bool CAddonMgr::PlatformSupportsAddon(const cp_plugin_info_t *plugin) const
531 {
532 if (!plugin || !plugin->num_extensions)
533 return false;
534 const cp_extension_t *metadata = GetExtension(plugin, "xbmc.addon.metadata");
9d9704e cleanup: Make <supportedcontent> and <platform> use the same xs:list sty...
jmarshallnz authored
535 if (!metadata)
536 return false;
537
538 vector<CStdString> platforms;
539 if (CAddonMgr::Get().GetExtList(metadata->configuration, "platform", platforms))
2bf2640 added: Functions for sanity checking addons (platform checks and ignorin...
jmarshallnz authored
540 {
541 for (unsigned int i = 0; i < platforms.size(); ++i)
542 {
543 if (platforms[i] == "all")
544 return true;
545 #if defined(_LINUX) && !defined(__APPLE__)
546 if (platforms[i] == "linux")
547 #elif defined(_WIN32) && defined(HAS_SDL_OPENGL)
548 if (platforms[i] == "wingl")
549 #elif defined(_WIN32) && defined(HAS_DX)
550 if (platforms[i] == "windx")
551 #elif defined(__APPLE__)
552 if (platforms[i] == "osx")
553 #endif
554 return true;
555 }
9d9704e cleanup: Make <supportedcontent> and <platform> use the same xs:list sty...
jmarshallnz authored
556 return false; // no <platform> works for us
2bf2640 added: Functions for sanity checking addons (platform checks and ignorin...
jmarshallnz authored
557 }
9d9704e cleanup: Make <supportedcontent> and <platform> use the same xs:list sty...
jmarshallnz authored
558 return true; // assume no <platform> is equivalent to <platform>all</platform>
2bf2640 added: Functions for sanity checking addons (platform checks and ignorin...
jmarshallnz authored
559 }
560
bb4e01c Support creating userdirs in addons. This also has the benefit of being ...
ceros7 authored
561 const cp_cfg_element_t *CAddonMgr::GetExtElement(cp_cfg_element_t *base, const char *path)
562 {
563 const cp_cfg_element_t *element = NULL;
564 if (base)
565 element = m_cpluff->lookup_cfg_element(base, path);
566 return element;
567 }
568
569 /* Returns all duplicate elements from a base element */
16b848a added: CPluginSource class for all pluginsource addons
alcoheca authored
570 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
571 {
572 if (!base)
573 return false;
574
575 unsigned int i = 0;
576 while (true)
577 {
578 if (i >= base->num_children)
579 break;
580 CStdString temp = (base->children+i)->name;
581 if (!temp.compare(path))
582 elements.push_back(base->children+i);
583 i++;
584 }
585
586 if (elements.empty()) return false;
587 return true;
588 }
589
2bf2640 added: Functions for sanity checking addons (platform checks and ignorin...
jmarshallnz authored
590 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
591 {
592 if (!props)
593 return NULL;
594 for (unsigned int i = 0; i < props->num_extensions; ++i)
595 {
596 if (0 == strcmp(props->extensions[i].ext_point_id, extension))
597 return &props->extensions[i];
598 }
599 return NULL;
600 }
601
a16721e changed: move scraper libraries to cpluff
spiff_ authored
602 ADDONDEPS CAddonMgr::GetDeps(const CStdString &id)
603 {
604 ADDONDEPS result;
605 cp_status_t status;
606
607 cp_plugin_info_t *info = m_cpluff->get_plugin_info(m_cp_context,id.c_str(),&status);
608 if (info)
609 {
610 for (unsigned int i=0;i<info->num_imports;++i)
611 result.insert(make_pair(CStdString(info->imports[i].plugin_id),
612 make_pair(AddonVersion(info->version),
613 AddonVersion(info->version))));
bb067ed fixed: Don't return true from GetAddon, and ensure we release the c-pluf...
jmarshallnz authored
614 m_cpluff->release_info(m_cp_context, info);
a16721e changed: move scraper libraries to cpluff
spiff_ authored
615 }
616
617 return result;
618 }
619
b6076e5 changed: screensavers are now supported via cpluff schema
alcoheca authored
620 CStdString CAddonMgr::GetExtValue(cp_cfg_element_t *base, const char *path)
621 {
622 const char *value = NULL;
623 if (base && (value = m_cpluff->lookup_cfg_value(base, path)))
624 return CStdString(value);
625 else return CStdString();
626 }
627
9d9704e cleanup: Make <supportedcontent> and <platform> use the same xs:list sty...
jmarshallnz authored
628 bool CAddonMgr::GetExtList(cp_cfg_element_t *base, const char *path, vector<CStdString> &result) const
a16721e changed: move scraper libraries to cpluff
spiff_ authored
629 {
9d9704e cleanup: Make <supportedcontent> and <platform> use the same xs:list sty...
jmarshallnz authored
630 if (!base || !path)
631 return false;
632 CStdString all = m_cpluff->lookup_cfg_value(base, path);
633 if (all.IsEmpty())
634 return false;
635 StringUtils::SplitString(all, " ", result);
636 return true;
a16721e changed: move scraper libraries to cpluff
spiff_ authored
637 }
638
2bf2640 added: Functions for sanity checking addons (platform checks and ignorin...
jmarshallnz authored
639 AddonPtr CAddonMgr::GetAddonFromDescriptor(const cp_plugin_info_t *info)
640 {
641 if (!info || !info->extensions)
642 return AddonPtr();
643
644 // FIXME: If we want to support multiple extension points per addon, we'll need to extend this to not just take
645 // the first extension point (eg use the TYPE information we pass in)
646
647 // grab a relevant extension point, ignoring our xbmc.addon.metadata extension point
28cd382 fixed: sanity is not just a state of mind...
jmarshallnz authored
648 for (unsigned int i = 0; i < info->num_extensions; ++i)
2bf2640 added: Functions for sanity checking addons (platform checks and ignorin...
jmarshallnz authored
649 {
650 if (0 != strcmp("xbmc.addon.metadata", info->extensions[i].ext_point_id))
651 { // note that Factory takes care of whether or not we have platform support
652 return Factory(&info->extensions[i]);
653 }
654 }
655 return AddonPtr();
656 }
657
658 // FIXME: This function may not be required
5bca9c0 cleanup: Rename and document the cpluff versions of loading addon descri...
jmarshallnz authored
659 bool CAddonMgr::LoadAddonDescription(const CStdString &path, AddonPtr &addon)
92afa2e fixed: Addons weren't installed correctly
jmarshallnz authored
660 {
661 cp_status_t status;
662 cp_plugin_info_t *info = m_cpluff->load_plugin_descriptor(m_cp_context, _P(path).c_str(), &status);
663 if (info)
664 {
2bf2640 added: Functions for sanity checking addons (platform checks and ignorin...
jmarshallnz authored
665 addon = GetAddonFromDescriptor(info);
92afa2e fixed: Addons weren't installed correctly
jmarshallnz authored
666 m_cpluff->release_info(m_cp_context, info);
9785be9 cleanup: Got rid of ADDON_SCRIPT_LIBRARY, compile warnings, and cosmetic...
jmarshallnz authored
667 return NULL != addon.get();
92afa2e fixed: Addons weren't installed correctly
jmarshallnz authored
668 }
669 return false;
670 }
671
5bca9c0 cleanup: Rename and document the cpluff versions of loading addon descri...
jmarshallnz authored
672 bool CAddonMgr::AddonsFromRepoXML(const TiXmlElement *root, VECADDONS &addons)
4488d3a changed: Allow repository to have c-pluff XML files
jmarshallnz authored
673 {
674 // create a context for these addons
675 cp_status_t status;
676 cp_context_t *context = m_cpluff->create_context(&status);
677 if (!root || !context)
678 return false;
679
cfe53d3 fixed: Put the UTF-8 descriptor on the XML before feeding it to c-pluff
jmarshallnz authored
680 // each addon XML should have a UTF-8 declaration
681 TiXmlDeclaration decl("1.0", "UTF-8", "");
4488d3a changed: Allow repository to have c-pluff XML files
jmarshallnz authored
682 const TiXmlElement *element = root->FirstChildElement("addon");
683 while (element)
684 {
cfe53d3 fixed: Put the UTF-8 descriptor on the XML before feeding it to c-pluff
jmarshallnz authored
685 // dump the XML back to text
4488d3a changed: Allow repository to have c-pluff XML files
jmarshallnz authored
686 std::string xml;
cfe53d3 fixed: Put the UTF-8 descriptor on the XML before feeding it to c-pluff
jmarshallnz authored
687 xml << decl;
4488d3a changed: Allow repository to have c-pluff XML files
jmarshallnz authored
688 xml << *element;
689 cp_status_t status;
cd2be2f added: Expose cp_load_plugin_descriptor and separate out the from_memory...
jmarshallnz authored
690 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
691 if (info)
692 {
2bf2640 added: Functions for sanity checking addons (platform checks and ignorin...
jmarshallnz authored
693 AddonPtr addon = GetAddonFromDescriptor(info);
ed51e37 fixed: check for NULL before adding the addon in AddonsFromInfoXML
jmarshallnz authored
694 if (addon.get())
695 addons.push_back(addon);
2bf2640 added: Functions for sanity checking addons (platform checks and ignorin...
jmarshallnz authored
696 m_cpluff->release_info(context, info);
4488d3a changed: Allow repository to have c-pluff XML files
jmarshallnz authored
697 }
698 element = element->NextSiblingElement("addon");
699 }
700 m_cpluff->destroy_context(context);
701 return true;
702 }
703
1b2781c added: basic cpluff support
alcoheca authored
704 int cp_to_clog(cp_log_severity_t lvl)
705 {
dec0bfe changed: sanitize the cpluff logging levels
jmarshallnz authored
706 if (lvl >= CP_LOG_ERROR)
707 return LOGINFO;
708 return LOGDEBUG;
1b2781c added: basic cpluff support
alcoheca authored
709 }
710
711 cp_log_severity_t clog_to_cp(int lvl)
712 {
dec0bfe changed: sanitize the cpluff logging levels
jmarshallnz authored
713 if (lvl >= LOG_LEVEL_DEBUG)
1b2781c added: basic cpluff support
alcoheca authored
714 return CP_LOG_INFO;
dec0bfe changed: sanitize the cpluff logging levels
jmarshallnz authored
715 return CP_LOG_ERROR;
1b2781c added: basic cpluff support
alcoheca authored
716 }
717
b6f0f59 cleanup: Don't expose the AddonManager's privates when not required.
jmarshallnz authored
718 void cp_fatalErrorHandler(const char *msg)
719 {
720 CLog::Log(LOGERROR, "ADDONS: CPluffFatalError(%s)", msg);
721 }
722
723 void cp_logger(cp_log_severity_t level, const char *msg, const char *apid, void *user_data)
1b2781c added: basic cpluff support
alcoheca authored
724 {
725 if(!apid)
5b793b6 added: missing change from r29798
alcoheca authored
726 CLog::Log(cp_to_clog(level), "ADDON: cpluff: '%s'", msg);
1b2781c added: basic cpluff support
alcoheca authored
727 else
5b793b6 added: missing change from r29798
alcoheca authored
728 CLog::Log(cp_to_clog(level), "ADDON: cpluff: '%s' reports '%s'", apid, msg);
1b2781c added: basic cpluff support
alcoheca authored
729 }
730
074db86 merged: addons-fw branch
elupus authored
731 } /* namespace ADDON */
732
Something went wrong with that request. Please try again.