2 * Copyright (C) 2005-2013 Team XBMC
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)
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.
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/>.
21 #include "GUIColorManager.h"
22 #include "filesystem/SpecialProtocol.h"
23 #include "addons/Skin.h"
24 #include "utils/log.h"
25 #include "utils/URIUtils.h"
26 #include "utils/XBMCTinyXML.h"
27 #include "utils/StringUtils.h"
29 CGUIColorManager g_colorManager;
31 CGUIColorManager::CGUIColorManager(void)
35 CGUIColorManager::~CGUIColorManager(void)
40 void CGUIColorManager::Clear()
45 // load the color file in
46 void CGUIColorManager::Load(const CStdString &colorFile)
50 // load the global color map if it exists
52 if (xmlDoc.LoadFile(CSpecialProtocol::TranslatePathConvertCase("special://xbmc/system/colors.xml")))
55 // first load the default color map if it exists
56 CStdString basePath = URIUtils::AddFileToFolder(g_SkinInfo->Path(), "colors");
57 CStdString path = URIUtils::AddFileToFolder(basePath, "defaults.xml");
59 if (xmlDoc.LoadFile(CSpecialProtocol::TranslatePathConvertCase(path)))
62 // now the color map requested
63 if (colorFile.CompareNoCase("SKINDEFAULT") == 0)
64 return; // nothing to do
66 path = URIUtils::AddFileToFolder(basePath, colorFile);
67 if (!URIUtils::HasExtension(path))
69 CLog::Log(LOGINFO, "Loading colors from %s", path.c_str());
71 if (xmlDoc.LoadFile(path))
75 bool CGUIColorManager::LoadXML(CXBMCTinyXML &xmlDoc)
77 TiXmlElement* pRootElement = xmlDoc.RootElement();
79 CStdString strValue = pRootElement->Value();
80 if (strValue != CStdString("colors"))
82 CLog::Log(LOGERROR, "color file doesnt start with <colors>");
86 const TiXmlElement *color = pRootElement->FirstChildElement("color");
90 if (color->FirstChild() && color->Attribute("name"))
92 color_t value = 0xffffffff;
93 sscanf(color->FirstChild()->Value(), "%x", (unsigned int*) &value);
94 CStdString name = color->Attribute("name");
95 iColor it = m_colors.find(name);
96 if (it != m_colors.end())
99 m_colors.insert(make_pair(name, value));
101 color = color->NextSiblingElement("color");
106 // lookup a color and return it's hex value
107 color_t CGUIColorManager::GetColor(const CStdString &color) const
109 // look in our color map
110 CStdString trimmed(color);
111 StringUtils::TrimLeft(trimmed, "= ");
112 icColor it = m_colors.find(trimmed);
113 if (it != m_colors.end())
116 // try converting hex directly
118 sscanf(trimmed.c_str(), "%x", &value);