2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
9 #include "GUIStaticItem.h"
11 #include "GUIControlFactory.h"
12 #include "GUIInfoManager.h"
13 #include "guilib/GUIComponent.h"
14 #include "utils/StringUtils.h"
15 #include "utils/Variant.h"
16 #include "utils/XMLUtils.h"
18 using namespace KODI::GUILIB
;
20 CGUIStaticItem::CGUIStaticItem(const TiXmlElement
*item
, int parentID
) : CFileItem()
26 GUIINFO::CGUIInfoLabel label
, label2
, thumb
, icon
;
27 CGUIControlFactory::GetInfoLabel(item
, "label", label
, parentID
);
28 CGUIControlFactory::GetInfoLabel(item
, "label2", label2
, parentID
);
29 CGUIControlFactory::GetInfoLabel(item
, "thumb", thumb
, parentID
);
30 CGUIControlFactory::GetInfoLabel(item
, "icon", icon
, parentID
);
31 const char *id
= item
->Attribute("id");
32 std::string condition
;
33 CGUIControlFactory::GetConditionalVisibility(item
, condition
);
34 SetVisibleCondition(condition
, parentID
);
35 CGUIControlFactory::GetActions(item
, "onclick", m_clickActions
);
36 SetLabel(label
.GetLabel(parentID
));
37 SetLabel2(label2
.GetLabel(parentID
));
38 SetArt("thumb", thumb
.GetLabel(parentID
, true));
39 SetArt("icon", icon
.GetLabel(parentID
, true));
40 if (!label
.IsConstant())
41 m_info
.emplace_back(label
, "label");
42 if (!label2
.IsConstant())
43 m_info
.emplace_back(label2
, "label2");
44 if (!thumb
.IsConstant())
45 m_info
.emplace_back(thumb
, "thumb");
46 if (!icon
.IsConstant())
47 m_info
.emplace_back(icon
, "icon");
48 m_iprogramCount
= id
? atoi(id
) : 0;
50 const TiXmlElement
*property
= item
->FirstChildElement("property");
53 std::string name
= XMLUtils::GetAttribute(property
, "name");
54 GUIINFO::CGUIInfoLabel prop
;
55 if (!name
.empty() && CGUIControlFactory::GetInfoLabelFromElement(property
, prop
, parentID
))
57 SetProperty(name
, prop
.GetLabel(parentID
, true).c_str());
58 if (!prop
.IsConstant())
59 m_info
.emplace_back(prop
, name
);
61 property
= property
->NextSiblingElement("property");
65 CGUIStaticItem::CGUIStaticItem(const CFileItem
&item
)
71 CGUIStaticItem::CGUIStaticItem(const CGUIStaticItem
& other
)
74 m_visCondition(other
.m_visCondition
),
75 m_visState(other
.m_visState
),
76 m_clickActions(other
.m_clickActions
)
80 void CGUIStaticItem::UpdateProperties(int contextWindow
)
82 for (const auto& i
: m_info
)
84 const GUIINFO::CGUIInfoLabel
& info
= i
.first
;
85 const std::string
& name
= i
.second
;
86 bool preferTexture
= StringUtils::CompareNoCase("label", name
, 5) != 0;
87 const std::string
& value(info
.GetLabel(contextWindow
, preferTexture
));
88 if (StringUtils::EqualsNoCase(name
, "label"))
90 else if (StringUtils::EqualsNoCase(name
, "label2"))
92 else if (StringUtils::EqualsNoCase(name
, "thumb"))
93 SetArt("thumb", value
);
94 else if (StringUtils::EqualsNoCase(name
, "icon"))
95 SetArt("icon", value
);
97 SetProperty(name
, value
.c_str());
101 bool CGUIStaticItem::UpdateVisibility(int contextWindow
)
105 bool state
= m_visCondition
->Get(contextWindow
);
106 if (state
!= m_visState
)
114 bool CGUIStaticItem::IsVisible() const
121 void CGUIStaticItem::SetVisibleCondition(const std::string
&condition
, int context
)
123 m_visCondition
= CServiceBroker::GetGUI()->GetInfoManager().Register(condition
, context
);