blob: 53980b90496eea8dca880f3357fcecb82063cf5f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
/*
* Copyright (C) 2005-2018 Team Kodi
* This file is part of Kodi - https://kodi.tv
*
* SPDX-License-Identifier: GPL-2.0-or-later
* See LICENSES/README.md for more information.
*/
#include "SkinVariable.h"
#include "GUIInfoManager.h"
#include "ServiceBroker.h"
#include "guilib/GUIComponent.h"
#include "utils/XBMCTinyXML.h"
using namespace INFO;
using namespace KODI;
const CSkinVariableString* CSkinVariable::CreateFromXML(const TiXmlElement& node, int context)
{
const char* name = node.Attribute("name");
if (name)
{
CSkinVariableString* tmp = new CSkinVariableString;
tmp->m_name = name;
tmp->m_context = context;
const TiXmlElement* valuenode = node.FirstChildElement("value");
while (valuenode)
{
CSkinVariableString::ConditionLabelPair pair;
const char *condition = valuenode->Attribute("condition");
if (condition)
pair.m_condition = CServiceBroker::GetGUI()->GetInfoManager().Register(condition, context);
auto label = valuenode->FirstChild() ? valuenode->FirstChild()->ValueStr() : "";
pair.m_label = GUILIB::GUIINFO::CGUIInfoLabel(label);
tmp->m_conditionLabelPairs.push_back(pair);
if (!pair.m_condition)
break; // once we reach default value (without condition) break iterating
valuenode = valuenode->NextSiblingElement("value");
}
if (!tmp->m_conditionLabelPairs.empty())
return tmp;
delete tmp;
}
return NULL;
}
CSkinVariableString::CSkinVariableString() = default;
int CSkinVariableString::GetContext() const
{
return m_context;
}
const std::string& CSkinVariableString::GetName() const
{
return m_name;
}
std::string CSkinVariableString::GetValue(int contextWindow,
bool preferImage /* = false */,
const CGUIListItem* item /* = nullptr */) const
{
for (const auto& it : m_conditionLabelPairs)
{
// use propagated context in case this skin variable has the default context (i.e. if not tied to a specific window)
// nested skin variables are supported
int context = m_context == INFO::DEFAULT_CONTEXT ? contextWindow : m_context;
if (!it.m_condition || it.m_condition->Get(context, item))
{
if (item)
return it.m_label.GetItemLabel(item, preferImage);
else
{
return it.m_label.GetLabel(context, preferImage);
}
}
}
return "";
}
|