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.
11 #include "GUIComponent.h"
12 #include "GUIInfoManager.h"
13 #include "GUIWindowManager.h"
14 #include "ServiceBroker.h"
15 #include "utils/StringUtils.h"
19 constexpr int DEFAULT_CONTROL_ID
= 0;
22 CGUIAction::CExecutableAction::CExecutableAction(const std::string
& action
) : m_action
{action
}
26 CGUIAction::CExecutableAction::CExecutableAction(const std::string
& condition
,
27 const std::string
& action
)
28 : m_condition
{condition
}, m_action
{action
}
32 std::string
CGUIAction::CExecutableAction::GetCondition() const
37 std::string
CGUIAction::CExecutableAction::GetAction() const
42 bool CGUIAction::CExecutableAction::HasCondition() const
44 return !m_condition
.empty();
47 void CGUIAction::CExecutableAction::SetAction(const std::string
& action
)
52 CGUIAction::CGUIAction(int controlID
)
54 SetNavigation(controlID
);
57 bool CGUIAction::ExecuteActions() const
59 return ExecuteActions(DEFAULT_CONTROL_ID
, DEFAULT_CONTROL_ID
);
62 bool CGUIAction::ExecuteActions(int controlID
,
64 const std::shared_ptr
<CGUIListItem
>& item
/* = NULL */) const
66 if (m_actions
.empty())
69 CGUIInfoManager
& infoMgr
= CServiceBroker::GetGUI()->GetInfoManager();
70 // take a copy of actions that satisfy our conditions
71 std::vector
<std::string
> actions
;
72 for (const auto &i
: m_actions
)
74 if (!i
.HasCondition() || infoMgr
.EvaluateBool(i
.GetCondition(), 0, item
))
76 if (!StringUtils::IsInteger(i
.GetAction()))
77 actions
.emplace_back(i
.GetAction());
82 for (const auto &i
: actions
)
84 CGUIMessage
msg(GUI_MSG_EXECUTE
, controlID
, parentID
, 0, 0, item
);
85 msg
.SetStringParam(i
);
86 if (m_sendThreadMessages
)
87 CServiceBroker::GetGUI()->GetWindowManager().SendThreadMessage(msg
);
89 CServiceBroker::GetGUI()->GetWindowManager().SendMessage(msg
);
95 int CGUIAction::GetNavigation() const
97 CGUIInfoManager
& infoMgr
= CServiceBroker::GetGUI()->GetInfoManager();
98 for (const auto &i
: m_actions
)
100 if (StringUtils::IsInteger(i
.GetAction()))
102 if (!i
.HasCondition() || infoMgr
.EvaluateBool(i
.GetCondition(), INFO::DEFAULT_CONTEXT
))
103 return std::stoi(i
.GetAction());
109 void CGUIAction::SetNavigation(int id
)
114 std::string strId
= std::to_string(id
);
115 for (auto &i
: m_actions
)
117 if (StringUtils::IsInteger(i
.GetAction()) && !i
.HasCondition())
123 m_actions
.emplace_back(std::move(strId
));
126 bool CGUIAction::HasConditionalActions() const
128 for (const auto& i
: m_actions
)
130 if (i
.HasCondition())
136 bool CGUIAction::HasActionsMeetingCondition() const
138 CGUIInfoManager
& infoMgr
= CServiceBroker::GetGUI()->GetInfoManager();
139 for (const auto &i
: m_actions
)
141 if (!i
.HasCondition() || infoMgr
.EvaluateBool(i
.GetCondition(), INFO::DEFAULT_CONTEXT
))
147 bool CGUIAction::HasAnyActions() const
149 return m_actions
.size() > 0;
152 size_t CGUIAction::GetActionCount() const
154 return m_actions
.size();
157 void CGUIAction::Append(const CExecutableAction
& action
)
159 m_actions
.emplace_back(action
);
162 void CGUIAction::EnableSendThreadMessageMode()
164 m_sendThreadMessages
= true;
167 void CGUIAction::Reset()