diff options
author | Martin Ellis <malard@gmail.com> | 2011-06-12 14:41:16 +0100 |
---|---|---|
committer | Martin Ellis <malard@gmail.com> | 2011-06-12 15:43:16 +0100 |
commit | 393a5ef33975b87e7c445f507630ebcc09b04e49 (patch) | |
tree | 888ad9b4de74a654e61acb41543450f7a6f5d376 | |
parent | 1226f2b3020db6ed86c7db7e8403395c5a91b540 (diff) |
added: KeymapLoader will iterate over deviceidmappings and load relevant device id's, when a device is added or removed appropriate action is taken
-rw-r--r-- | system/deviceidmappings.xml | 3 | ||||
-rw-r--r-- | xbmc/input/KeymapLoader.cpp | 90 | ||||
-rw-r--r-- | xbmc/input/KeymapLoader.h | 34 |
3 files changed, 127 insertions, 0 deletions
diff --git a/system/deviceidmappings.xml b/system/deviceidmappings.xml new file mode 100644 index 0000000000..7114170a6d --- /dev/null +++ b/system/deviceidmappings.xml @@ -0,0 +1,3 @@ +<devicemappings> + <device id="HID#VID_1915&PID_003B&MI_00#7&314e95d&0&0000#" keymap="Motorola Nyxboard Hybrid" /> +</devicemappings>
\ No newline at end of file diff --git a/xbmc/input/KeymapLoader.cpp b/xbmc/input/KeymapLoader.cpp new file mode 100644 index 0000000000..7777b23e7f --- /dev/null +++ b/xbmc/input/KeymapLoader.cpp @@ -0,0 +1,90 @@ +/* + * Copyright (C) 2005-2011 Team XBMC + * http://xbmc.org + * + * This Program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This Program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XBMC; see the file COPYING. If not, write to + * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. + * http://www.gnu.org/copyleft/gpl.html + * + */ + +#include "KeymapLoader.h" +#include "filesystem/File.h" +#include "settings/Settings.h" +#include "utils/log.h" +#include "utils/XMLUtils.h" + +using namespace std; +using namespace XFILE; + +CKeymapLoader::CKeymapLoader() +{ + if (!parsedMappings) + { + ParseDeviceMappings(); + } +} + +void CKeymapLoader::DeviceAdded(CStdString deviceId) +{ + CStdString keymapName; + if (FindMappedDevice(deviceId, keymapName)) + { + CLog::Log(LOGDEBUG, "Switching Active Keymapping to: %s", keymapName.c_str()); + g_settings.m_activeKeyboardMapping = keymapName; + } +} + +void CKeymapLoader::DeviceRemoved(CStdString deviceId) +{ + CStdString keymapName; + if (FindMappedDevice(deviceId, keymapName)) + { + CLog::Log(LOGDEBUG, "Switching Active Keymapping to: default"); + g_settings.m_activeKeyboardMapping = "default"; + } +} + +void CKeymapLoader::ParseDeviceMappings() +{ + parsedMappings = true; + CStdString file("special://xbmc/system/deviceidmappings.xml"); + TiXmlDocument deviceXML; + if (!CFile::Exists(file) || !deviceXML.LoadFile(file)) + return; + + TiXmlElement *pRootElement = deviceXML.RootElement(); + if (!pRootElement || strcmpi(pRootElement->Value(), "devicemappings") != 0) + return; + + TiXmlElement *pDevice = pRootElement->FirstChildElement("device"); + while (pDevice) + { + CStdString deviceId(pDevice->Attribute("id")); + CStdString keymap(pDevice->Attribute("keymap")); + if (!deviceId.empty() && !keymap.empty()) + deviceMappings.insert(pair<CStdString, CStdString>(deviceId.ToUpper(), keymap)); + pDevice = pDevice->NextSiblingElement("device"); + } +} + +bool CKeymapLoader::FindMappedDevice(CStdString deviceId, CStdString& keymapName) +{ + std::map<CStdString, CStdString>::iterator deviceIdIt = deviceMappings.find(deviceId.ToUpper()); + if (deviceIdIt == deviceMappings.end()) + return false; + + keymapName = deviceIdIt->second; + return true; +}
\ No newline at end of file diff --git a/xbmc/input/KeymapLoader.h b/xbmc/input/KeymapLoader.h new file mode 100644 index 0000000000..c2be4163cc --- /dev/null +++ b/xbmc/input/KeymapLoader.h @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2005-2011 Team XBMC + * http://xbmc.org + * + * This Program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This Program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XBMC; see the file COPYING. If not, write to + * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. + * http://www.gnu.org/copyleft/gpl.html + * + */ + +static std::map<CStdString, CStdString> deviceMappings; +static bool parsedMappings; + +class CKeymapLoader +{ + public: + CKeymapLoader(); + void DeviceRemoved(CStdString deviceID); + void DeviceAdded(CStdString deviceID); + private: + void ParseDeviceMappings(); + bool FindMappedDevice(CStdString deviceId, CStdString& keymapName); +};
\ No newline at end of file |