2 * Copyright (C) 2005-2013 Team XBMC
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)
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
28 #include "system.h" // for HAS_EVENT_SERVER, HAS_SDL_JOYSTICK, HAS_LIRC
30 #ifdef HAS_EVENT_SERVER
31 #include "network/EventClient.h"
41 CStdString strID; // needed for "XBMC.ActivateWindow()" type actions
44 /// singleton class to map from buttons to actions
45 /// Warning: _not_ threadsafe!
46 class CButtonTranslator
48 #ifdef HAS_EVENT_SERVER
49 friend class EVENTCLIENT::CEventButtonState;
53 //private construction, and no assignements; use the provided singleton methods
55 CButtonTranslator(const CButtonTranslator&);
56 CButtonTranslator const& operator=(CButtonTranslator const&);
57 virtual ~CButtonTranslator();
58 bool HasDeviceType(TiXmlNode *pWindow, CStdString type);
60 ///access to singleton
61 static CButtonTranslator& GetInstance();
63 // Add/remove a HID device with custom mappings
64 void AddDevice(CStdString& strDevice);
65 void RemoveDevice(CStdString& strDevice);
67 /// loads Lircmap.xml/IRSSmap.xml (if enabled) and Keymap.xml
68 bool Load(bool AlwaysLoad = false);
72 static void GetActions(std::vector<std::string> &actionList);
73 static void GetWindows(std::vector<std::string> &windowList);
75 CAction GetAction(int window, const CKey &key, bool fallback = true);
77 /*! \brief Translate between a window name and it's id
78 \param window name of the window
79 \return id of the window, or WINDOW_INVALID if not found
81 static int TranslateWindow(const CStdString &window);
83 /*! \brief Translate between a window id and it's name
84 \param window id of the window
85 \return name of the window, or an empty string if not found
87 static CStdString TranslateWindow(int window);
89 static bool TranslateActionString(const char *szAction, int &action);
91 #if defined(HAS_LIRC) || defined(HAS_IRSERVERSUITE)
92 int TranslateLircRemoteString(const char* szDevice, const char *szButton);
94 #if defined(HAS_SDL_JOYSTICK) || defined(HAS_EVENT_SERVER)
95 bool TranslateJoystickString(int window, const char* szDevice, int id,
96 short inputType, int& action, CStdString& strAction,
101 typedef std::multimap<uint32_t, CButtonAction> buttonMap; // our button map to fill in
103 // m_translatorMap contains all mappings i.e. m_BaseMap + HID device mappings
104 std::map<int, buttonMap> m_translatorMap;
105 // m_deviceList contains the list of connected HID devices
106 std::list<CStdString> m_deviceList;
108 int GetActionCode(int window, const CKey &key, CStdString &strAction) const;
109 #if defined(HAS_SDL_JOYSTICK) || defined(HAS_EVENT_SERVER)
110 typedef std::map<int, std::map<int, std::string> > JoystickMap; // <window, <button/axis, action> >
111 int GetActionCode(int window, int id, const JoystickMap &wmap, CStdString &strAction, bool &fullrange) const;
113 int GetFallbackWindow(int windowID);
115 static uint32_t TranslateGamepadString(const char *szButton);
116 static uint32_t TranslateRemoteString(const char *szButton);
117 static uint32_t TranslateUniversalRemoteString(const char *szButton);
119 static uint32_t TranslateKeyboardString(const char *szButton);
120 static uint32_t TranslateKeyboardButton(TiXmlElement *pButton);
122 static uint32_t TranslateMouseCommand(const char *szButton);
124 static uint32_t TranslateAppCommand(const char *szButton);
126 void MapWindowActions(TiXmlNode *pWindow, int wWindowID);
127 void MapAction(uint32_t buttonCode, const char *szAction, buttonMap &map);
129 bool LoadKeymap(const CStdString &keymapPath);
130 #if defined(HAS_LIRC) || defined(HAS_IRSERVERSUITE)
131 bool LoadLircMap(const CStdString &lircmapPath);
132 void ClearLircButtonMapEntries();
134 void MapRemote(TiXmlNode *pRemote, const char* szDevice);
136 typedef std::map<CStdString, CStdString> lircButtonMap;
137 std::map<CStdString, lircButtonMap*> lircRemotesMap;
140 #if defined(HAS_SDL_JOYSTICK) || defined(HAS_EVENT_SERVER)
141 void MapJoystickActions(int windowID, TiXmlNode *pJoystick);
143 std::map<std::string, JoystickMap> m_joystickButtonMap; // <joy name, button map>
144 std::map<std::string, JoystickMap> m_joystickAxisMap; // <joy name, axis map>
145 std::map<std::string, JoystickMap> m_joystickHatMap; // <joy name, hat map>