[cosmetics] update date in GPL header
[vuplus_xbmc] / xbmc / guilib / GUIAction.cpp
1 /*
2  *      Copyright (C) 2005-2013 Team XBMC
3  *      http://www.xbmc.org
4  *
5  *  This Program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2, or (at your option)
8  *  any later version.
9  *
10  *  This Program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with XBMC; see the file COPYING.  If not, see
17  *  <http://www.gnu.org/licenses/>.
18  *
19  */
20
21 #include "GUIAction.h"
22 #include "utils/StringUtils.h"
23 #include "GUIWindowManager.h"
24 #include "GUIControl.h"
25 #include "GUIInfoManager.h"
26
27 using namespace std;
28
29 CGUIAction::CGUIAction()
30 {
31   m_sendThreadMessages = false;
32 }
33
34 CGUIAction::CGUIAction(int controlID)
35 {
36   m_sendThreadMessages = false;
37   SetNavigation(controlID);
38 }
39
40 bool CGUIAction::ExecuteActions(int controlID, int parentID) const
41 {
42   if (m_actions.size() == 0) return false;
43   bool retval = false;
44   CGUIAction copy(*this);
45   for (ciActions it = copy.m_actions.begin() ; it != copy.m_actions.end() ; it++)
46   {
47     if (it->condition.IsEmpty() || g_infoManager.EvaluateBool(it->condition))
48     {
49       if (!StringUtils::IsInteger(it->action))
50       {
51         CGUIMessage msg(GUI_MSG_EXECUTE, controlID, parentID);
52         msg.SetStringParam(it->action);
53         if (m_sendThreadMessages)
54           g_windowManager.SendThreadMessage(msg);
55         else
56           g_windowManager.SendMessage(msg);
57         retval |= true;
58       }
59     }
60   }
61   return retval;
62 }
63
64 int CGUIAction::GetNavigation() const
65 {
66   for (ciActions it = m_actions.begin() ; it != m_actions.end() ; it++)
67   {
68     if (StringUtils::IsInteger(it->action))
69     {
70       if (it->condition.IsEmpty() || g_infoManager.EvaluateBool(it->condition))
71         return atoi(it->action.c_str());
72     }
73   }
74   return 0;
75 }
76
77 void CGUIAction::SetNavigation(int id)
78 {
79   if (id == 0) return;
80   CStdString strId;
81   strId.Format("%i", id);
82   for (iActions it = m_actions.begin() ; it != m_actions.end() ; it++)
83   {
84     if (StringUtils::IsInteger(it->action) && it->condition.IsEmpty())
85     {
86       it->action = strId;
87       return;
88     }
89   }
90   cond_action_pair pair;
91   pair.action = strId;
92   m_actions.push_back(pair);
93 }
94
95 bool CGUIAction::HasActionsMeetingCondition() const
96 {
97   for (ciActions it = m_actions.begin() ; it != m_actions.end() ; it++)
98   {
99     if (it->condition.IsEmpty() || g_infoManager.EvaluateBool(it->condition))
100       return true;
101   }
102   return false;
103 }