Debian Codegraph @

xbmc/guilib/guiinfo/GUIInfoColor.cpp

raw symbols SCIP
1 /*
2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
4 *
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
8
9 #include "guilib/guiinfo/GUIInfoColor.h"
10
11 #include "FileItem.h"
12 #include "GUIInfoManager.h"
13 #include "ServiceBroker.h"
14 #include "addons/Skin.h"
15 #include "guilib/GUIColorManager.h"
16 #include "guilib/GUIComponent.h"
17 #include "utils/StringUtils.h"
18
19 using namespace KODI::GUILIB::GUIINFO;
20
21 bool CGUIInfoColor::Update(const CGUIListItem* item /* = nullptr */)
22 {
23 if (!m_info)
24 return false; // no infolabel
25
26 // Expand the infolabel, and then convert it to a color
27 std::string infoLabel;
28 if (item && item->IsFileItem())
29 infoLabel = CServiceBroker::GetGUI()->GetInfoManager().GetItemLabel(
30 static_cast<const CFileItem*>(item), 0, m_info);
31 else
32 infoLabel = CServiceBroker::GetGUI()->GetInfoManager().GetLabel(m_info, INFO::DEFAULT_CONTEXT);
33
34 UTILS::COLOR::Color color =
35 !infoLabel.empty() ? CServiceBroker::GetGUI()->GetColorManager().GetColor(infoLabel) : 0;
36 if (m_color != color)
37 {
38 m_color = color;
39 return true;
40 }
41 else
42 return false;
43 }
44
45 void CGUIInfoColor::Parse(const std::string &label, int context)
46 {
47 if (label.empty())
48 return;
49
50 CGUIInfoManager& infoMgr = CServiceBroker::GetGUI()->GetInfoManager();
51
52 // Check for the standard $INFO[] block layout, and strip it if present
53 std::string label2 = label;
54 if (StringUtils::StartsWithNoCase(label, "$var["))
55 {
56 label2 = label.substr(5, label.length() - 6);
57 m_info = infoMgr.TranslateSkinVariableString(label2, context);
58 if (!m_info)
59 m_info = infoMgr.RegisterSkinVariableString(g_SkinInfo->CreateSkinVariable(label2, context));
60 return;
61 }
62
63 if (StringUtils::StartsWithNoCase(label, "$info["))
64 label2 = label.substr(6, label.length()-7);
65
66 m_info = infoMgr.TranslateString(label2);
67 if (!m_info)
68 m_color = CServiceBroker::GetGUI()->GetColorManager().GetColor(label);
69 }