diff options
author | jmarshallnz <jmarshallnz@svn> | 2010-02-18 23:50:24 +0000 |
---|---|---|
committer | jmarshallnz <jmarshallnz@svn> | 2010-02-18 23:50:24 +0000 |
commit | 7c2ea63bf9f06cc50d98395b6fcace4291dabe88 (patch) | |
tree | 028882968c7c395d1b8703550bdbe0e6c5a9133d | |
parent | 938a870803a8623e353093c2ff8ba67a5c93af20 (diff) |
changed: use CGUIInfoLabel for static content's label and thumbs, allowing the use of the fallback attribute at the same time as cleaning up the code.
git-svn-id: https://xbmc.svn.sourceforge.net/svnroot/xbmc/trunk@27953 568bbfeb-2a22-0410-94d2-cc84cf5bfa90
-rw-r--r-- | guilib/GUIControlFactory.cpp | 42 | ||||
-rw-r--r-- | guilib/GUIControlFactory.h | 12 | ||||
-rw-r--r-- | guilib/GUIStaticItem.cpp | 69 | ||||
-rw-r--r-- | guilib/GUIStaticItem.h | 4 |
4 files changed, 74 insertions, 53 deletions
diff --git a/guilib/GUIControlFactory.cpp b/guilib/GUIControlFactory.cpp index 6f6c507927..862a891871 100644 --- a/guilib/GUIControlFactory.cpp +++ b/guilib/GUIControlFactory.cpp @@ -459,6 +459,28 @@ void CGUIControlFactory::GetInfoLabel(const TiXmlNode *pControlNode, const CStdS infoLabel = labels[0]; } +bool CGUIControlFactory::GetInfoLabelFromElement(const TiXmlElement *element, CGUIInfoLabel &infoLabel) +{ + if (!element || !element->FirstChild()) + return false; + + CStdString label = element->FirstChild()->Value(); + if (label.IsEmpty() || label == "-") + return false; + + CStdString fallback = element->Attribute("fallback"); + if (StringUtils::IsNaturalNumber(label)) + label = g_localizeStrings.Get(atoi(label)); + else // we assume the skin xml's aren't encoded as UTF-8 + g_charsetConverter.unknownToUTF8(label); + if (StringUtils::IsNaturalNumber(fallback)) + fallback = g_localizeStrings.Get(atoi(fallback)); + else + g_charsetConverter.unknownToUTF8(fallback); + infoLabel.SetLabel(label, fallback); + return true; +} + void CGUIControlFactory::GetInfoLabels(const TiXmlNode *pControlNode, const CStdString &labelTag, vector<CGUIInfoLabel> &infoLabels) { // we can have the following infolabels: @@ -477,23 +499,9 @@ void CGUIControlFactory::GetInfoLabels(const TiXmlNode *pControlNode, const CStd const TiXmlElement *labelNode = pControlNode->FirstChildElement(labelTag); while (labelNode) { - if (labelNode->FirstChild()) - { - CStdString label = labelNode->FirstChild()->Value(); - CStdString fallback = labelNode->Attribute("fallback"); - if (label.size() && label[0] != '-') - { - if (StringUtils::IsNaturalNumber(label)) - label = g_localizeStrings.Get(atoi(label)); - else // we assume the skin xml's aren't encoded as UTF-8 - g_charsetConverter.unknownToUTF8(label); - if (StringUtils::IsNaturalNumber(fallback)) - fallback = g_localizeStrings.Get(atoi(fallback)); - else - g_charsetConverter.unknownToUTF8(fallback); - infoLabels.push_back(CGUIInfoLabel(label, fallback)); - } - } + CGUIInfoLabel label; + if (GetInfoLabelFromElement(labelNode, label)) + infoLabels.push_back(label); labelNode = labelNode->NextSiblingElement(labelTag); } const TiXmlNode *infoNode = pControlNode->FirstChild("info"); diff --git a/guilib/GUIControlFactory.h b/guilib/GUIControlFactory.h index c4bb29e765..bc373b47e9 100644 --- a/guilib/GUIControlFactory.h +++ b/guilib/GUIControlFactory.h @@ -70,6 +70,18 @@ public: static bool GetAlignment(const TiXmlNode* pRootNode, const char* strTag, uint32_t& dwAlignment); static bool GetAlignmentY(const TiXmlNode* pRootNode, const char* strTag, uint32_t& dwAlignment); static bool GetAnimations(const TiXmlNode *control, const CRect &rect, std::vector<CAnimation> &animation); + + /*! \brief Create an info label from an XML element + Processes XML elements of the form + <xmltag fallback="fallback_value">info_value</xmltag> + where info_value may use $INFO[], $LOCALIZE[], $NUMBER[] etc. + If either the fallback_value or info_value are natural numbers they are interpreted + as ids for lookup in strings.xml. The fallback attribute is optional. + \param element XML element to process + \param infoLabel returned infoLabel + \return true if a valid info label was read, false otherwise + */ + static bool GetInfoLabelFromElement(const TiXmlElement *element, CGUIInfoLabel &infoLabel); static void GetInfoLabel(const TiXmlNode *pControlNode, const CStdString &labelTag, CGUIInfoLabel &infoLabel); static void GetInfoLabels(const TiXmlNode *pControlNode, const CStdString &labelTag, std::vector<CGUIInfoLabel> &infoLabels); static bool GetColor(const TiXmlNode* pRootNode, const char* strTag, color_t &value); diff --git a/guilib/GUIStaticItem.cpp b/guilib/GUIStaticItem.cpp index 27066759bf..1c342c7c6c 100644 --- a/guilib/GUIStaticItem.cpp +++ b/guilib/GUIStaticItem.cpp @@ -33,11 +33,11 @@ CGUIStaticItem::CGUIStaticItem(const TiXmlElement *item, int parentID) : CFileIt const TiXmlNode *click = item->FirstChild("onclick"); if (click && click->FirstChild()) { - CStdString label, label2, thumb, icon; - XMLUtils::GetString(item, "label", label); label = CGUIControlFactory::FilterLabel(label); - XMLUtils::GetString(item, "label2", label2); label2 = CGUIControlFactory::FilterLabel(label2); - XMLUtils::GetString(item, "thumb", thumb); thumb = CGUIControlFactory::FilterLabel(thumb); - XMLUtils::GetString(item, "icon", icon); icon = CGUIControlFactory::FilterLabel(icon); + CGUIInfoLabel label, label2, thumb, icon; + CGUIControlFactory::GetInfoLabel(item, "label", label); + CGUIControlFactory::GetInfoLabel(item, "label2", label2); + CGUIControlFactory::GetInfoLabel(item, "thumb", thumb); + CGUIControlFactory::GetInfoLabel(item, "icon", icon); const char *id = item->Attribute("id"); int visibleCondition = 0; CGUIControlFactory::GetConditionalVisibility(item, visibleCondition); @@ -53,14 +53,14 @@ CGUIStaticItem::CGUIStaticItem(const TiXmlElement *item, int parentID) : CFileIt } m_strPath += (*it).m_action; } - SetLabel(CGUIInfoLabel::GetLabel(label, parentID)); - SetLabel2(CGUIInfoLabel::GetLabel(label2, parentID)); - SetThumbnailImage(CGUIInfoLabel::GetLabel(thumb, parentID, true)); - SetIconImage(CGUIInfoLabel::GetLabel(icon, parentID, true)); - if (label.Find("$INFO") >= 0) SetProperty("info:label", label); - if (label2.Find("$INFO") >= 0) SetProperty("info:label2", label2); - if (icon.Find("$INFO") >= 0) SetProperty("info:icon", icon); - if (thumb.Find("$INFO") >= 0) SetProperty("info:thumb", thumb); + SetLabel(label.GetLabel(parentID)); + SetLabel2(label2.GetLabel(parentID)); + SetThumbnailImage(thumb.GetLabel(parentID, true)); + SetIconImage(icon.GetLabel(parentID, true)); + if (!label.IsConstant()) m_info.push_back(make_pair(label, "label")); + if (!label2.IsConstant()) m_info.push_back(make_pair(label2, "label2")); + if (!thumb.IsConstant()) m_info.push_back(make_pair(thumb, "thumb")); + if (!icon.IsConstant()) m_info.push_back(make_pair(icon, "icon")); m_iprogramCount = id ? atoi(id) : 0; m_idepth = visibleCondition; // add any properties @@ -68,13 +68,12 @@ CGUIStaticItem::CGUIStaticItem(const TiXmlElement *item, int parentID) : CFileIt while (property) { CStdString name = property->Attribute("name"); - CStdString value = property->FirstChild() ? property->FirstChild()->Value() : ""; - if (!name.IsEmpty() && !value.IsEmpty()) + CGUIInfoLabel prop; + if (!name.IsEmpty() && CGUIControlFactory::GetInfoLabelFromElement(property, prop)) { - value = CGUIControlFactory::FilterLabel(value); - SetProperty(name, CGUIInfoLabel::GetLabel(value, parentID)); - if (value.Find("$INFO") >= 0) - SetProperty("info:" + name, value); + SetProperty(name, prop.GetLabel(parentID, true)); + if (!prop.IsConstant()) + m_info.push_back(make_pair(prop, name)); } property = property->NextSiblingElement("property"); } @@ -99,23 +98,21 @@ CGUIStaticItem::CGUIStaticItem(const TiXmlElement *item, int parentID) : CFileIt void CGUIStaticItem::UpdateProperties(int contextWindow) { - for (PropertyMap::const_iterator i = m_mapProperties.begin(); i != m_mapProperties.end(); i++) + for (InfoVector::const_iterator i = m_info.begin(); i != m_info.end(); i++) { - if (i->first.Left(5).Equals("info:")) - { - // prefer images if it's not label or label2 - CStdString prop(i->first.Mid(5)); - CStdString info(CGUIInfoLabel::GetLabel(i->second, contextWindow, !prop.Left(5).Equals("label"))); - if (prop.Equals("label")) - SetLabel(info); - else if (prop.Equals("label2")) - SetLabel2(info); - else if (prop.Equals("thumb")) - SetThumbnailImage(info); - else if (prop.Equals("icon")) - SetIconImage(info); - else - SetProperty(prop, info); - } + const CGUIInfoLabel &info = i->first; + const CStdString &name = i->second; + bool preferTexture = strnicmp("label", name.c_str(), 5) == 0; + CStdString value(info.GetLabel(contextWindow, preferTexture)); + if (name.Equals("label")) + SetLabel(value); + else if (name.Equals("label2")) + SetLabel2(value); + else if (name.Equals("thumb")) + SetThumbnailImage(value); + else if (name.Equals("icon")) + SetIconImage(value); + else + SetProperty(name, value); } } diff --git a/guilib/GUIStaticItem.h b/guilib/GUIStaticItem.h index 46c556438e..269db1b22f 100644 --- a/guilib/GUIStaticItem.h +++ b/guilib/GUIStaticItem.h @@ -26,6 +26,7 @@ \brief */ +#include "GUIInfoTypes.h" #include "../xbmc/FileItem.h" class TiXmlElement; @@ -66,6 +67,9 @@ public: \param contextWindow window context to use for any info labels */ void UpdateProperties(int contextWindow); +private: + typedef std::vector< std::pair<CGUIInfoLabel, CStdString> > InfoVector; + InfoVector m_info; }; typedef boost::shared_ptr<CGUIStaticItem> CGUIStaticItemPtr; |