[WASAPI] fix stream types and frequencies enumeration
[xbmc.git] / xbmc / guilib / GUIAction.cpp
blobe14df2e9b5da515ffb4799db46b567f87b4aaf3a
1 /*
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.
7 */
9 #include "GUIAction.h"
11 #include "GUIComponent.h"
12 #include "GUIInfoManager.h"
13 #include "GUIWindowManager.h"
14 #include "ServiceBroker.h"
15 #include "utils/StringUtils.h"
17 namespace
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
34 return m_condition;
37 std::string CGUIAction::CExecutableAction::GetAction() const
39 return m_action;
42 bool CGUIAction::CExecutableAction::HasCondition() const
44 return !m_condition.empty();
47 void CGUIAction::CExecutableAction::SetAction(const std::string& action)
49 m_action = 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,
63 int parentID,
64 const std::shared_ptr<CGUIListItem>& item /* = NULL */) const
66 if (m_actions.empty())
67 return false;
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());
80 // execute them
81 bool retval = false;
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);
88 else
89 CServiceBroker::GetGUI()->GetWindowManager().SendMessage(msg);
90 retval = true;
92 return retval;
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());
106 return 0;
109 void CGUIAction::SetNavigation(int id)
111 if (id == 0)
112 return;
114 std::string strId = std::to_string(id);
115 for (auto &i : m_actions)
117 if (StringUtils::IsInteger(i.GetAction()) && !i.HasCondition())
119 i.SetAction(strId);
120 return;
123 m_actions.emplace_back(std::move(strId));
126 bool CGUIAction::HasConditionalActions() const
128 for (const auto& i : m_actions)
130 if (i.HasCondition())
131 return true;
133 return false;
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))
142 return true;
144 return false;
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()
169 m_actions.clear();