xbmc
ButtonTranslator.h
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 #pragma once
10 
11 #include "input/actions/Action.h"
12 #include "network/EventClient.h"
13 
14 #include <map>
15 #include <set>
16 #include <string>
17 
18 class CKey;
19 class TiXmlNode;
21 class CTouchTranslator;
22 class IButtonMapper;
23 class IWindowKeymap;
24 
28 {
29  friend class EVENTCLIENT::CEventButtonState;
30 
31 public:
32  CButtonTranslator() = default;
33  CButtonTranslator(const CButtonTranslator&) = delete;
34  CButtonTranslator const& operator=(CButtonTranslator const&) = delete;
35  virtual ~CButtonTranslator() = default;
36 
37  // Add/remove a HID device with custom mappings
38  bool AddDevice(const std::string& strDevice);
39  bool RemoveDevice(const std::string& strDevice);
40 
42  bool Load();
43 
45  void Clear();
46 
52  bool HasLongpressMapping(int window, const CKey& key);
53 
61  CAction GetAction(int window, const CKey& key, bool fallback = true);
62 
63  void RegisterMapper(const std::string& device, IButtonMapper* mapper);
64  void UnregisterMapper(const IButtonMapper* mapper);
65 
66  static uint32_t TranslateString(const std::string& strMap, const std::string& strButton);
67 
68 private:
69  struct CButtonAction
70  {
71  unsigned int id;
72  std::string strID; // needed for "ActivateWindow()" type actions
73  };
74 
75  typedef std::multimap<uint32_t, CButtonAction> buttonMap; // our button map to fill in
76 
77  // m_translatorMap contains all mappings i.e. m_BaseMap + HID device mappings
78  std::map<int, buttonMap> m_translatorMap;
79 
80  // m_deviceList contains the list of connected HID devices
81  std::set<std::string> m_deviceList;
82 
83  unsigned int GetActionCode(int window, const CKey& key, std::string& strAction) const;
84 
85  void MapWindowActions(const TiXmlNode* pWindow, int wWindowID);
86  void MapAction(uint32_t buttonCode, const std::string& szAction, buttonMap& map);
87 
88  bool LoadKeymap(const std::string& keymapPath);
89 
90  bool HasLongpressMapping_Internal(int window, const CKey& key);
91 
92  std::map<std::string, IButtonMapper*> m_buttonMappers;
93 };
Interface for classes that can map buttons to Kodi actions.
Definition: IButtonMapper.h:16
bool Load()
loads Keymap.xml
Definition: ButtonTranslator.cpp:66
void Clear()
clears the maps
Definition: ButtonTranslator.cpp:389
Definition: EventClient.h:47
Definition: TouchTranslator.h:18
class encapsulating information regarding a particular user action to be sent to windows and controls...
Definition: Action.h:22
bool HasLongpressMapping(int window, const CKey &key)
Finds out if a longpress mapping exists for this key.
Definition: ButtonTranslator.cpp:198
Definition: CustomControllerTranslator.h:18
CAction GetAction(int window, const CKey &key, bool fallback=true)
Obtain the action configured for a given window and key.
Definition: ButtonTranslator.cpp:175
Interface for mapping buttons to Kodi actions for specific windows.
Definition: IKeymap.h:54
singleton class to map from buttons to actions Warning: not threadsafe!
Definition: ButtonTranslator.h:27
Definition: Key.h:135