PageRenderTime 38ms CodeModel.GetById 12ms app.highlight 22ms RepoModel.GetById 1ms app.codeStats 0ms

/xbmc/guilib/GUIAction.cpp

http://github.com/xbmc/xbmc
C++ | 94 lines | 76 code | 9 blank | 9 comment | 19 complexity | 81f7d1cf0d038f2bbf1a5faf28db3b26 MD5 | raw file
 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 "GUIAction.h"
10
11#include "GUIComponent.h"
12#include "GUIInfoManager.h"
13#include "GUIWindowManager.h"
14#include "ServiceBroker.h"
15#include "utils/StringUtils.h"
16
17CGUIAction::CGUIAction(int controlID)
18{
19  SetNavigation(controlID);
20}
21
22bool CGUIAction::ExecuteActions(int controlID, int parentID, const CGUIListItemPtr &item /* = NULL */) const
23{
24  if (m_actions.empty())
25    return false;
26
27  CGUIInfoManager& infoMgr = CServiceBroker::GetGUI()->GetInfoManager();
28  // take a copy of actions that satisfy our conditions
29  std::vector<std::string> actions;
30  for (const auto &i : m_actions)
31  {
32    if (i.condition.empty() || infoMgr.EvaluateBool(i.condition, 0, item))
33    {
34      if (!StringUtils::IsInteger(i.action))
35        actions.emplace_back(i.action);
36    }
37  }
38  // execute them
39  bool retval = false;
40  for (const auto &i : actions)
41  {
42    CGUIMessage msg(GUI_MSG_EXECUTE, controlID, parentID, 0, 0, item);
43    msg.SetStringParam(i);
44    if (m_sendThreadMessages)
45      CServiceBroker::GetGUI()->GetWindowManager().SendThreadMessage(msg);
46    else
47      CServiceBroker::GetGUI()->GetWindowManager().SendMessage(msg);
48    retval = true;
49  }
50  return retval;
51}
52
53int CGUIAction::GetNavigation() const
54{
55  CGUIInfoManager& infoMgr = CServiceBroker::GetGUI()->GetInfoManager();
56  for (const auto &i : m_actions)
57  {
58    if (StringUtils::IsInteger(i.action))
59    {
60      if (i.condition.empty() || infoMgr.EvaluateBool(i.condition))
61        return atoi(i.action.c_str());
62    }
63  }
64  return 0;
65}
66
67void CGUIAction::SetNavigation(int id)
68{
69  if (id == 0)
70    return;
71
72  std::string strId = StringUtils::Format("%i", id);
73  for (auto &i : m_actions)
74  {
75    if (StringUtils::IsInteger(i.action) && i.condition.empty())
76    {
77      i.action = std::move(strId);
78      return;
79    }
80  }
81  m_actions.emplace_back();
82  m_actions.back().action = std::move(strId);
83}
84
85bool CGUIAction::HasActionsMeetingCondition() const
86{
87  CGUIInfoManager& infoMgr = CServiceBroker::GetGUI()->GetInfoManager();
88  for (const auto &i : m_actions)
89  {
90    if (i.condition.empty() || infoMgr.EvaluateBool(i.condition))
91      return true;
92  }
93  return false;
94}