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;
20 class CTouchTranslator;
21 class IButtonMapper;
22 class IWindowKeymap;
23 
24 namespace tinyxml2
25 {
26 class XMLNode;
27 }
28 
32 {
33  friend class EVENTCLIENT::CEventButtonState;
34 
35 public:
36  CButtonTranslator() = default;
37  CButtonTranslator(const CButtonTranslator&) = delete;
38  CButtonTranslator const& operator=(CButtonTranslator const&) = delete;
39  virtual ~CButtonTranslator() = default;
40 
41  // Add/remove a HID device with custom mappings
42  bool AddDevice(const std::string& strDevice);
43  bool RemoveDevice(const std::string& strDevice);
44 
46  bool Load();
47 
49  void Clear();
50 
56  bool HasLongpressMapping(int window, const CKey& key);
57 
65  CAction GetAction(int window, const CKey& key, bool fallback = true);
66 
67  void RegisterMapper(const std::string& device, IButtonMapper* mapper);
68  void UnregisterMapper(const IButtonMapper* mapper);
69 
70  static uint32_t TranslateString(const std::string& strMap, const std::string& strButton);
71 
72 private:
73  struct CButtonAction
74  {
75  unsigned int id;
76  std::string strID; // needed for "ActivateWindow()" type actions
77  };
78 
79  typedef std::multimap<uint32_t, CButtonAction> buttonMap; // our button map to fill in
80 
81  // m_translatorMap contains all mappings i.e. m_BaseMap + HID device mappings
82  std::map<int, buttonMap> m_translatorMap;
83 
84  // m_deviceList contains the list of connected HID devices
85  std::set<std::string> m_deviceList;
86 
87  unsigned int GetActionCode(int window, const CKey& key, std::string& strAction) const;
88 
89  void MapWindowActions(const tinyxml2::XMLNode* pWindow, int wWindowID);
90  void MapAction(uint32_t buttonCode, const std::string& szAction, buttonMap& map);
91 
92  bool LoadKeymap(const std::string& keymapPath);
93 
94  bool HasLongpressMapping_Internal(int window, const CKey& key);
95 
96  std::map<std::string, IButtonMapper*> m_buttonMappers;
97 };
Interface for classes that can map buttons to Kodi actions.
Definition: IButtonMapper.h:19
Definition: EventClient.h:47
Definition: SkinTimerManager.h:18
Definition: TouchTranslator.h:22
class encapsulating information regarding a particular user action to be sent to windows and controls...
Definition: Action.h:22
Definition: CustomControllerTranslator.h:21
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:31
Definition: Key.h:135