[guilib] fix labelcontrols with auto width always being marked as dirty if they speci...
[vuplus_xbmc] / xbmc / guilib / GUIAction.cpp
1 /*
2  *      Copyright (C) 2005-2013 Team XBMC
3  *      http://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   // take a copy of actions that satisfy our conditions
44   vector<CStdString> actions;
45   for (ciActions it = m_actions.begin() ; it != m_actions.end() ; ++it)
46   {
47     if (it->condition.empty() || g_infoManager.EvaluateBool(it->condition))
48     {
49       if (!StringUtils::IsInteger(it->action))
50         actions.push_back(it->action);
51     }
52   }
53   // execute them
54   bool retval = false;
55   for (vector<CStdString>::iterator i = actions.begin(); i != actions.end(); ++i)
56   {
57     CGUIMessage msg(GUI_MSG_EXECUTE, controlID, parentID);
58     msg.SetStringParam(*i);
59     if (m_sendThreadMessages)
60       g_windowManager.SendThreadMessage(msg);
61     else
62       g_windowManager.SendMessage(msg);
63     retval |= true;
64   }
65   return retval;
66 }
67
68 int CGUIAction::GetNavigation() const
69 {
70   for (ciActions it = m_actions.begin() ; it != m_actions.end() ; ++it)
71   {
72     if (StringUtils::IsInteger(it->action))
73     {
74       if (it->condition.empty() || g_infoManager.EvaluateBool(it->condition))
75         return atoi(it->action.c_str());
76     }
77   }
78   return 0;
79 }
80
81 void CGUIAction::SetNavigation(int id)
82 {
83   if (id == 0) return;
84   CStdString strId = StringUtils::Format("%i", id);
85   for (iActions it = m_actions.begin() ; it != m_actions.end() ; ++it)
86   {
87     if (StringUtils::IsInteger(it->action) && it->condition.empty())
88     {
89       it->action = strId;
90       return;
91     }
92   }
93   cond_action_pair pair;
94   pair.action = strId;
95   m_actions.push_back(pair);
96 }
97
98 bool CGUIAction::HasActionsMeetingCondition() const
99 {
100   for (ciActions it = m_actions.begin() ; it != m_actions.end() ; ++it)
101   {
102     if (it->condition.empty() || g_infoManager.EvaluateBool(it->condition))
103       return true;
104   }
105   return false;
106 }