Merge pull request #4594 from FernetMenta/paplayer
[xbmc.git] / xbmc / input / ButtonTranslator.h
blob11ac033cc1e2d1423c12da58df262cb8e47efc25
1 /*
2 * Copyright (C) 2005-2013 Team XBMC
3 * http://xbmc.org
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.
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.
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/>.
21 #ifndef BUTTON_TRANSLATOR_H
22 #define BUTTON_TRANSLATOR_H
24 #pragma once
26 #include <map>
27 #include <vector>
28 #include "system.h" // for HAS_EVENT_SERVER, HAS_SDL_JOYSTICK, HAS_LIRC
30 #ifdef HAS_EVENT_SERVER
31 #include "network/EventClient.h"
32 #endif
33 #include "utils/StdString.h"
35 class CKey;
36 class CAction;
37 class TiXmlNode;
39 struct CButtonAction
41 int id;
42 CStdString strID; // needed for "XBMC.ActivateWindow()" type actions
44 ///
45 /// singleton class to map from buttons to actions
46 /// Warning: _not_ threadsafe!
47 class CButtonTranslator
49 #ifdef HAS_EVENT_SERVER
50 friend class EVENTCLIENT::CEventButtonState;
51 #endif
53 private:
54 //private construction, and no assignements; use the provided singleton methods
55 CButtonTranslator();
56 CButtonTranslator(const CButtonTranslator&);
57 CButtonTranslator const& operator=(CButtonTranslator const&);
58 virtual ~CButtonTranslator();
59 bool HasDeviceType(TiXmlNode *pWindow, CStdString type);
60 public:
61 ///access to singleton
62 static CButtonTranslator& GetInstance();
64 // Add/remove a HID device with custom mappings
65 void AddDevice(CStdString& strDevice);
66 void RemoveDevice(CStdString& strDevice);
68 /// loads Lircmap.xml/IRSSmap.xml (if enabled) and Keymap.xml
69 bool Load(bool AlwaysLoad = false);
70 /// clears the maps
71 void Clear();
73 static void GetActions(std::vector<std::string> &actionList);
74 static void GetWindows(std::vector<std::string> &windowList);
76 CAction GetAction(int window, const CKey &key, bool fallback = true);
78 /*! \brief Translate between a window name and it's id
79 \param window name of the window
80 \return id of the window, or WINDOW_INVALID if not found
82 static int TranslateWindow(const CStdString &window);
84 /*! \brief Translate between a window id and it's name
85 \param window id of the window
86 \return name of the window, or an empty string if not found
88 static CStdString TranslateWindow(int window);
90 static bool TranslateActionString(const char *szAction, int &action);
92 #if defined(HAS_LIRC) || defined(HAS_IRSERVERSUITE)
93 int TranslateLircRemoteString(const char* szDevice, const char *szButton);
94 #endif
95 #if defined(HAS_SDL_JOYSTICK) || defined(HAS_EVENT_SERVER)
96 bool TranslateJoystickString(int window, const char* szDevice, int id,
97 short inputType, int& action, CStdString& strAction,
98 bool &fullrange);
99 #endif
101 bool TranslateTouchAction(int window, int touchAction, int touchPointers, int &action);
103 private:
104 typedef std::multimap<uint32_t, CButtonAction> buttonMap; // our button map to fill in
106 // m_translatorMap contains all mappings i.e. m_BaseMap + HID device mappings
107 std::map<int, buttonMap> m_translatorMap;
108 // m_deviceList contains the list of connected HID devices
109 std::list<CStdString> m_deviceList;
111 int GetActionCode(int window, int action);
112 int GetActionCode(int window, const CKey &key, CStdString &strAction) const;
113 #if defined(HAS_SDL_JOYSTICK) || defined(HAS_EVENT_SERVER)
114 typedef std::map<int, std::map<int, std::string> > JoystickMap; // <window, <button/axis, action> >
115 int GetActionCode(int window, int id, const JoystickMap &wmap, CStdString &strAction, bool &fullrange) const;
116 #endif
117 int GetFallbackWindow(int windowID);
119 static uint32_t TranslateGamepadString(const char *szButton);
120 static uint32_t TranslateRemoteString(const char *szButton);
121 static uint32_t TranslateUniversalRemoteString(const char *szButton);
123 static uint32_t TranslateKeyboardString(const char *szButton);
124 static uint32_t TranslateKeyboardButton(TiXmlElement *pButton);
126 static uint32_t TranslateMouseCommand(const char *szButton);
128 static uint32_t TranslateAppCommand(const char *szButton);
130 void MapWindowActions(TiXmlNode *pWindow, int wWindowID);
131 void MapAction(uint32_t buttonCode, const char *szAction, buttonMap &map);
133 bool LoadKeymap(const CStdString &keymapPath);
134 #if defined(HAS_LIRC) || defined(HAS_IRSERVERSUITE)
135 bool LoadLircMap(const CStdString &lircmapPath);
136 void ClearLircButtonMapEntries();
138 void MapRemote(TiXmlNode *pRemote, const char* szDevice);
140 typedef std::map<CStdString, CStdString> lircButtonMap;
141 std::map<CStdString, lircButtonMap*> lircRemotesMap;
142 #endif
144 #if defined(HAS_SDL_JOYSTICK) || defined(HAS_EVENT_SERVER)
145 void MapJoystickActions(int windowID, TiXmlNode *pJoystick);
147 std::map<std::string, JoystickMap> m_joystickButtonMap; // <joy name, button map>
148 std::map<std::string, JoystickMap> m_joystickAxisMap; // <joy name, axis map>
149 std::map<std::string, JoystickMap> m_joystickHatMap; // <joy name, hat map>
150 #endif
152 void MapTouchActions(int windowID, TiXmlNode *pTouch);
153 static uint32_t TranslateTouchCommand(TiXmlElement *pButton, CButtonAction &action);
154 int GetTouchActionCode(int window, int action);
156 std::map<int, buttonMap> m_touchMap;
158 bool m_Loaded;
161 #endif