Merge pull request #5039 from CEikermann/patch-1
[vuplus_xbmc] / xbmc / addons / PluginSource.cpp
1 /*
2  *      Copyright (C) 2005-2013 Team XBMC
3  *      http://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, see
17  *  <http://www.gnu.org/licenses/>.
18  *
19  */
20 #include "PluginSource.h"
21 #include "AddonManager.h"
22 #include "utils/StringUtils.h"
23
24 using namespace std;
25
26 namespace ADDON
27 {
28
29 CPluginSource::CPluginSource(const AddonProps &props)
30   : CAddon(props)
31 {
32   CStdString provides;
33   InfoMap::const_iterator i = Props().extrainfo.find("provides");
34   if (i != Props().extrainfo.end())
35     provides = i->second;
36   SetProvides(provides);
37 }
38
39 CPluginSource::CPluginSource(const cp_extension_t *ext)
40   : CAddon(ext)
41 {
42   CStdString provides;
43   if (ext)
44   {
45     provides = CAddonMgr::Get().GetExtValue(ext->configuration, "provides");
46     if (!provides.empty())
47       Props().extrainfo.insert(make_pair("provides", provides));
48   }
49   SetProvides(provides);
50 }
51
52 AddonPtr CPluginSource::Clone() const
53 {
54   return AddonPtr(new CPluginSource(*this));
55 }
56
57 void CPluginSource::SetProvides(const CStdString &content)
58 {
59   vector<CStdString> provides;
60   if (!content.empty())
61   {
62     StringUtils::SplitString(content, " ", provides);
63     for (unsigned int i = 0; i < provides.size(); ++i)
64     {
65       Content content = Translate(provides[i]);
66       if (content != UNKNOWN)
67         m_providedContent.insert(content);
68     }
69   }
70   if (Type() == ADDON_SCRIPT && m_providedContent.empty())
71     m_providedContent.insert(EXECUTABLE);
72 }
73
74 CPluginSource::Content CPluginSource::Translate(const CStdString &content)
75 {
76   if (content.Equals("audio"))
77     return CPluginSource::AUDIO;
78   else if (content.Equals("image"))
79     return CPluginSource::IMAGE;
80   else if (content.Equals("executable"))
81     return CPluginSource::EXECUTABLE;
82   else if (content.Equals("video"))
83     return CPluginSource::VIDEO;
84   else
85     return CPluginSource::UNKNOWN;
86 }
87
88 bool CPluginSource::IsType(TYPE type) const
89 {
90   return ((type == ADDON_VIDEO && Provides(VIDEO))
91        || (type == ADDON_AUDIO && Provides(AUDIO))
92        || (type == ADDON_IMAGE && Provides(IMAGE))
93        || (type == ADDON_EXECUTABLE && Provides(EXECUTABLE)));
94 }
95
96 } /*namespace ADDON*/
97