Permalink
Browse files

Let context addon access their settings in the visibility expression …

…via Addon.HasSetting()... still stuff to do

Context items can now have addon.hasSetting... this also reacts to setting changes
  • Loading branch information...
Fice
Fice committed Oct 20, 2012
1 parent a438fd9 commit 9b3fa50d2f13ce737b27b18bcfc4539ec4580947
@@ -56,6 +56,7 @@ GUIContextMenuManager::GUIContextMenuManager()
}
}
+
bool GUIContextMenuManager::RegisterContextItem(ContextItemPtr cm)
{
ContextItemPtr item = GetContextItemByID(cm->getMsgID());
@@ -30,13 +30,13 @@
#include <list>
#include <boost/noncopyable.hpp>
+
class GUIContextMenuManager : boost::noncopyable
{
public:
static GUIContextMenuManager& Get();
-
bool RegisterContextItem(ContextItemPtr cm);
bool UnregisterContextItem(ContextItemPtr cm);
ContextItemPtr GetContextItemByID(const unsigned int ID);
View
@@ -144,11 +144,11 @@ bool CGUIInfoManager::OnMessage(CGUIMessage &message)
/// efficient retrieval of data. Can handle combined strings on the form
/// Player.Caching + VideoPlayer.IsFullscreen (Logical and)
/// Player.HasVideo | Player.HasAudio (Logical or)
-int CGUIInfoManager::TranslateString(const CStdString &condition)
+int CGUIInfoManager::TranslateString(const CStdString &condition, ADDON::IAddon* const contextAddon)
{
// translate $LOCALIZE as required
CStdString strCondition(CGUIInfoLabel::ReplaceLocalize(condition));
- return TranslateSingleString(strCondition);
+ return TranslateSingleString(strCondition, contextAddon);
}
typedef struct
@@ -719,7 +719,7 @@ void CGUIInfoManager::SplitInfoString(const CStdString &infoString, vector<Prope
/// \brief Translates a string as given by the skin into an int that we use for more
/// efficient retrieval of data.
-int CGUIInfoManager::TranslateSingleString(const CStdString &strCondition)
+int CGUIInfoManager::TranslateSingleString(const CStdString &strCondition, ADDON::IAddon* const contextAddon)
{
// trim whitespaces
CStdString strTest = strCondition;
@@ -740,11 +740,11 @@ int CGUIInfoManager::TranslateSingleString(const CStdString &strCondition)
else if (cat.name == "true" || cat.name == "yes" || cat.name == "on")
return SYSTEM_ALWAYS_TRUE;
if (cat.name == "isempty" && cat.num_params() == 1)
- return AddMultiInfo(GUIInfo(STRING_IS_EMPTY, TranslateSingleString(cat.param())));
+ return AddMultiInfo(GUIInfo(STRING_IS_EMPTY, TranslateSingleString(cat.param(), contextAddon)));
else if (cat.name == "stringcompare" && cat.num_params() == 2)
{
- int info = TranslateSingleString(cat.param(0));
- int info2 = TranslateSingleString(cat.param(1));
+ int info = TranslateSingleString(cat.param(0), contextAddon);
+ int info2 = TranslateSingleString(cat.param(1), contextAddon);
if (info2 > 0)
return AddMultiInfo(GUIInfo(STRING_COMPARE, info, -info2));
// pipe our original string through the localize parsing then make it lowercase (picks up $LBRACKET etc.)
@@ -754,13 +754,13 @@ int CGUIInfoManager::TranslateSingleString(const CStdString &strCondition)
}
else if (cat.name == "integergreaterthan" && cat.num_params() == 2)
{
- int info = TranslateSingleString(cat.param(0));
+ int info = TranslateSingleString(cat.param(0), contextAddon);
int compareInt = atoi(cat.param(1).c_str());
return AddMultiInfo(GUIInfo(INTEGER_GREATER_THAN, info, compareInt));
}
else if (cat.name == "substring" && cat.num_params() >= 2)
{
- int info = TranslateSingleString(cat.param(0));
+ int info = TranslateSingleString(cat.param(0), contextAddon);
CStdString label = CGUIInfoLabel::GetLabel(cat.param(1)).ToLower();
int compareString = ConditionalStringParameter(label);
if (cat.num_params() > 2)
@@ -876,15 +876,15 @@ int CGUIInfoManager::TranslateSingleString(const CStdString &strCondition)
}
else if (prop.name == "addontitle")
{
- int infoLabel = TranslateSingleString(param);
+ int infoLabel = TranslateSingleString(param, contextAddon);
if (infoLabel > 0)
return AddMultiInfo(GUIInfo(SYSTEM_ADDON_TITLE, infoLabel, 0));
CStdString label = CGUIInfoLabel::GetLabel(param).ToLower();
return AddMultiInfo(GUIInfo(SYSTEM_ADDON_TITLE, ConditionalStringParameter(label), 1));
}
else if (prop.name == "addonicon")
{
- int infoLabel = TranslateSingleString(param);
+ int infoLabel = TranslateSingleString(param, contextAddon);
if (infoLabel > 0)
return AddMultiInfo(GUIInfo(SYSTEM_ADDON_ICON, infoLabel, 0));
CStdString label = CGUIInfoLabel::GetLabel(param).ToLower();
@@ -1081,6 +1081,12 @@ int CGUIInfoManager::TranslateSingleString(const CStdString &strCondition)
return AddMultiInfo(GUIInfo(SKIN_HAS_THEME, ConditionalStringParameter(prop.param(0))));
}
}
+ else if (cat.name == "addon" && contextAddon)
+ {
+ if (prop.name == "hassetting") {
+ return AddMultiInfo(GUIInfo(ADDON_BOOL, contextAddon->TranslateAddonBool(prop.param(0))));
+ }
+ }
else if (cat.name == "window")
{
if (prop.name == "property" && prop.num_params() == 1)
@@ -1225,14 +1231,14 @@ TIME_FORMAT CGUIInfoManager::TranslateTimeFormat(const CStdString &format)
return TIME_FORMAT_GUESS;
}
-CStdString CGUIInfoManager::GetLabel(int info, int contextWindow, CStdString *fallback)
+CStdString CGUIInfoManager::GetLabel(int info, int contextWindow, CStdString *fallback, const ADDON::IAddon* const contextAddon)
{
if (info >= CONDITIONAL_LABEL_START && info <= CONDITIONAL_LABEL_END)
return GetSkinVariableString(info, false);
CStdString strLabel;
if (info >= MULTI_INFO_START && info <= MULTI_INFO_END)
- return GetMultiInfoLabel(m_multiInfo[info - MULTI_INFO_START], contextWindow);
+ return GetMultiInfoLabel(m_multiInfo[info - MULTI_INFO_START], contextWindow, NULL, contextAddon);
if (info >= SLIDE_INFO_START && info <= SLIDE_INFO_END)
return GetPictureLabel(info);
@@ -1590,7 +1596,7 @@ CStdString CGUIInfoManager::GetLabel(int info, int contextWindow, CStdString *fa
case CONTAINER_NUM_PAGES:
case CONTAINER_NUM_ITEMS:
case CONTAINER_CURRENT_PAGE:
- return GetMultiInfoLabel(GUIInfo(info), contextWindow);
+ return GetMultiInfoLabel(GUIInfo(info), contextWindow, NULL, contextAddon);
break;
case CONTAINER_SHOWPLOT:
{
@@ -1979,7 +1985,7 @@ bool CGUIInfoManager::GetInt(int &value, int info, int contextWindow, const CGUI
return false;
}
-unsigned int CGUIInfoManager::Register(const CStdString &expression, int context)
+unsigned int CGUIInfoManager::Register(const CStdString &expression, int context, ADDON::IAddon* const contextAddon)
{
CStdString condition(CGUIInfoLabel::ReplaceLocalize(expression));
condition.TrimLeft(" \t\r\n");
@@ -1990,17 +1996,17 @@ unsigned int CGUIInfoManager::Register(const CStdString &expression, int context
CSingleLock lock(m_critInfo);
// do we have the boolean expression already registered?
- InfoBool test(condition, context);
+ InfoBool test(condition, context, contextAddon);
for (unsigned int i = 0; i < m_bools.size(); ++i)
{
if (*m_bools[i] == test)
return i+1;
}
if (condition.find_first_of("|+[]!") != condition.npos)
- m_bools.push_back(new InfoExpression(condition, context));
+ m_bools.push_back(new InfoExpression(condition, context, contextAddon));
else
- m_bools.push_back(new InfoSingle(condition, context));
+ m_bools.push_back(new InfoSingle(condition, context, contextAddon));
return m_bools.size();
}
@@ -2032,7 +2038,7 @@ bool CGUIInfoManager::EvaluateBool(const CStdString &expression, int contextWind
Advantage is that we know this at creation time I think, so could perhaps signal it in IsDirty()?
*/
-bool CGUIInfoManager::GetBoolValue(unsigned int expression, const CGUIListItem *item)
+bool CGUIInfoManager::GetBoolValue(unsigned int expression, const CGUIListItem * const item)
{
if (expression && --expression < m_bools.size())
return m_bools[expression]->Get(m_updateTime, item);
@@ -2041,7 +2047,7 @@ bool CGUIInfoManager::GetBoolValue(unsigned int expression, const CGUIListItem *
// checks the condition and returns it as necessary. Currently used
// for toggle button controls and visibility of images.
-bool CGUIInfoManager::GetBool(int condition1, int contextWindow, const CGUIListItem *item)
+bool CGUIInfoManager::GetBool(int condition1, int contextWindow, const CGUIListItem *item, const ADDON::IAddon* const contextAddon)
{
bool bReturn = false;
int condition = abs(condition1);
@@ -2148,7 +2154,7 @@ bool CGUIInfoManager::GetBool(int condition1, int contextWindow, const CGUIListI
bReturn = m_playerShowCodec;
else if (condition >= MULTI_INFO_START && condition <= MULTI_INFO_END)
{
- return GetMultiInfoBool(m_multiInfo[condition - MULTI_INFO_START], contextWindow, item);
+ return GetMultiInfoBool(m_multiInfo[condition - MULTI_INFO_START], contextWindow, item, contextAddon);
}
else if (condition == SYSTEM_HASLOCKS)
bReturn = g_settings.GetMasterProfile().getLockMode() != LOCK_MODE_EVERYONE;
@@ -2476,7 +2482,7 @@ bool CGUIInfoManager::GetBool(int condition1, int contextWindow, const CGUIListI
}
/// \brief Examines the multi information sent and returns true or false accordingly.
-bool CGUIInfoManager::GetMultiInfoBool(const GUIInfo &info, int contextWindow, const CGUIListItem *item)
+bool CGUIInfoManager::GetMultiInfoBool(const GUIInfo &info, int contextWindow, const CGUIListItem *item, const ADDON::IAddon* const contextAddon)
{
bool bReturn = false;
int condition = abs(info.m_info);
@@ -2532,6 +2538,12 @@ bool CGUIInfoManager::GetMultiInfoBool(const GUIInfo &info, int contextWindow, c
bReturn = theme.Equals(m_stringParameters[info.GetData1()]);
}
break;
+ case ADDON_BOOL:
+ {
+ if(contextAddon)
+ bReturn = contextAddon->GetAddonBool(info.GetData1());
+ }
+ break;
case STRING_IS_EMPTY:
// note: Get*Image() falls back to Get*Label(), so this should cover all of them
if (item && item->IsFileItem() && info.GetData1() >= LISTITEM_START && info.GetData1() < LISTITEM_END)
@@ -2910,7 +2922,7 @@ bool CGUIInfoManager::GetMultiInfoInt(int &value, const GUIInfo &info, int conte
}
/// \brief Examines the multi information sent and returns the string as appropriate
-CStdString CGUIInfoManager::GetMultiInfoLabel(const GUIInfo &info, int contextWindow, CStdString *fallback)
+CStdString CGUIInfoManager::GetMultiInfoLabel(const GUIInfo &info, int contextWindow, CStdString *fallback, const ADDON::IAddon* const contextAddon)
{
if (info.m_info == SKIN_STRING)
{
@@ -2922,6 +2934,12 @@ CStdString CGUIInfoManager::GetMultiInfoLabel(const GUIInfo &info, int contextWi
if (bInfo)
return g_localizeStrings.Get(20122);
}
+ else if (info.m_info == ADDON_BOOL && contextAddon)
+ {
+ bool bInfo = contextAddon->GetAddonBool(info.GetData1());
+ if (bInfo)
+ return g_localizeStrings.Get(20122);
+ }
if (info.m_info >= LISTITEM_START && info.m_info <= LISTITEM_END)
{
CFileItemPtr item;
@@ -3100,7 +3118,7 @@ CStdString CGUIInfoManager::GetMultiInfoLabel(const GUIInfo &info, int contextWi
// in the future.
AddonPtr addon;
if (info.GetData2() == 0)
- CAddonMgr::Get().GetAddon(const_cast<CGUIInfoManager*>(this)->GetLabel(info.GetData1(), contextWindow),addon,ADDON_UNKNOWN,false);
+ CAddonMgr::Get().GetAddon(const_cast<CGUIInfoManager*>(this)->GetLabel(info.GetData1(), contextWindow, NULL, contextAddon),addon,ADDON_UNKNOWN,false);
else
CAddonMgr::Get().GetAddon(m_stringParameters[info.GetData1()],addon,ADDON_UNKNOWN,false);
if (addon && info.m_info == SYSTEM_ADDON_TITLE)
View
@@ -33,6 +33,7 @@
#include "XBDateTime.h"
#include "utils/Observer.h"
#include "interfaces/info/SkinVariable.h"
+#include "addons/IAddon.h"
#include <list>
#include <map>
@@ -370,6 +371,8 @@ namespace INFO
#define SKIN_HAS_THEME 606
#define SKIN_ASPECT_RATIO 607
+#define ADDON_BOOL 635
+
#define SYSTEM_TOTAL_MEMORY 644
#define SYSTEM_CPU_USAGE 645
#define SYSTEM_USED_MEMORY_PERCENT 646
@@ -690,11 +693,12 @@ class CGUIInfoManager : public IMsgTargetCallback, public Observable
\param expression the boolean condition or expression
\param context the context window
+ \param contextAddon the addon that wants to register this addon. If NULL the expressions: addon.hassetting, addon.getsetting are not available
\return an identifier used to reference this expression
\sa GetBoolValue
*/
- unsigned int Register(const CStdString &expression, int context = 0);
+ unsigned int Register(const CStdString &expression, int context = 0, ADDON::IAddon* const contextAddon=NULL);
/*! \brief Get a previously registered boolean expression's value
Checks the cache and evaluates the boolean expression if required.
@@ -710,7 +714,7 @@ class CGUIInfoManager : public IMsgTargetCallback, public Observable
*/
bool EvaluateBool(const CStdString &expression, int context = 0);
- int TranslateString(const CStdString &strCondition);
+ int TranslateString(const CStdString &strCondition, ADDON::IAddon* const contextAddon=NULL);
/*! \brief Get integer value of info.
\param value int reference to pass value of given info
@@ -721,7 +725,7 @@ class CGUIInfoManager : public IMsgTargetCallback, public Observable
\sa GetItemInt, GetMultiInfoInt
*/
bool GetInt(int &value, int info, int contextWindow = 0, const CGUIListItem *item = NULL) const;
- CStdString GetLabel(int info, int contextWindow = 0, CStdString *fallback = NULL);
+ CStdString GetLabel(int info, int contextWindow = 0, CStdString *fallback = NULL, const ADDON::IAddon* const contextAddon = NULL);
CStdString GetImage(int info, int contextWindow, CStdString *fallback = NULL);
@@ -806,7 +810,7 @@ class CGUIInfoManager : public IMsgTargetCallback, public Observable
void ResetLibraryBools();
CStdString LocalizeTime(const CDateTime &time, TIME_FORMAT format) const;
- int TranslateSingleString(const CStdString &strCondition);
+ int TranslateSingleString(const CStdString &strCondition, ADDON::IAddon* const contextAddon);
int RegisterSkinVariableString(const INFO::CSkinVariableString* info);
int TranslateSkinVariableString(const CStdString& name, int context);
@@ -816,7 +820,7 @@ class CGUIInfoManager : public IMsgTargetCallback, public Observable
bool ConditionsChangedValues(const std::map<int, bool>& map);
protected:
friend class INFO::InfoSingle;
- bool GetBool(int condition, int contextWindow = 0, const CGUIListItem *item=NULL);
+ bool GetBool(int condition, int contextWindow = 0, const CGUIListItem *item = NULL, const ADDON::IAddon* const contextAddon = NULL);
// routines for window retrieval
bool CheckWindowCondition(CGUIWindow *window, int condition) const;
@@ -837,9 +841,9 @@ class CGUIInfoManager : public IMsgTargetCallback, public Observable
std::vector<CStdString> params;
};
- bool GetMultiInfoBool(const GUIInfo &info, int contextWindow = 0, const CGUIListItem *item = NULL);
+ bool GetMultiInfoBool(const GUIInfo &info, int contextWindow = 0, const CGUIListItem *item = NULL, const ADDON::IAddon* const contextAddon = NULL);
bool GetMultiInfoInt(int &value, const GUIInfo &info, int contextWindow = 0) const;
- CStdString GetMultiInfoLabel(const GUIInfo &info, int contextWindow = 0, CStdString *fallback = NULL);
+ CStdString GetMultiInfoLabel(const GUIInfo &info, int contextWindow = 0, CStdString *fallback = NULL, const ADDON::IAddon* const contextAddon = NULL);
int TranslateListItem(const Property &info);
int TranslateMusicPlayerString(const CStdString &info) const;
TIME_FORMAT TranslateTimeFormat(const CStdString &format);
View
@@ -69,6 +69,22 @@ Outputlterator copy_if( Inputlterator begin, Inputlterator end,
return destBegin;
}
+
+template<class T, class Predicate = std::equal_to<typename T::value_type> >
+struct map_value_finder
+ : public std::binary_function<typename T::value_type,
+ typename Predicate::second_argument_type,
+ bool>
+{
+public:
+ bool operator() (const typename T::value_type pair,
+ const typename Predicate::second_argument_type i) const
+ {
+ return Predicate()(pair.second, i);
+ }
+};
+
+
class CUtil
{
public:
View
@@ -34,6 +34,7 @@
#include "utils/log.h"
#include "utils/StringUtils.h"
#include "utils/URIUtils.h"
+#include "Util.h"
#include "URL.h"
#include <vector>
#include <string.h>
@@ -519,6 +520,16 @@ void CAddon::SaveSettings(void)
CAddonMgr::Get().ReloadSettings(ID());//push the settings changes to the running addon instance
g_pythonParser.OnSettingsChanged(ID());
}
+
+bool CAddon::GetAddonBool(int setting) const
+{
+ return CAddonMgr::Get().GetAddonBool(setting);
+}
+
+int CAddon::TranslateAddonBool(const CStdString &settingName)
+{
+ return CAddonMgr::Get().TranslateAddonBool(*this, settingName);
+}
CStdString CAddon::GetSetting(const CStdString& key)
{
@@ -536,6 +547,9 @@ void CAddon::UpdateSetting(const CStdString& key, const CStdString& value)
LoadSettings();
if (key.empty()) return;
m_settings[key] = value;
+
+ //update bools
+ CAddonMgr::Get().UpdateBoolState(ID(), key, (0==strcmpi(value, "true")));
}
bool CAddon::SettingsFromXML(const CXBMCTinyXML &doc, bool loadDefaults /*=false */)
@@ -588,6 +602,11 @@ TiXmlElement* CAddon::GetSettingsXML()
{
return m_addonXmlDoc.RootElement();
}
+
+const TiXmlElement* CAddon::GetSettingsXML() const
+{
+ return m_addonXmlDoc.RootElement();
+}
void CAddon::BuildProfilePath()
{
Oops, something went wrong.

0 comments on commit 9b3fa50

Please sign in to comment.