diff options
Diffstat (limited to 'backends/common/keymap-manager.cpp')
-rw-r--r-- | backends/common/keymap-manager.cpp | 61 |
1 files changed, 59 insertions, 2 deletions
diff --git a/backends/common/keymap-manager.cpp b/backends/common/keymap-manager.cpp index 8ef89add6e..9386dc5b5e 100644 --- a/backends/common/keymap-manager.cpp +++ b/backends/common/keymap-manager.cpp @@ -32,6 +32,11 @@ Keymap *KeymapManager::Domain::getKeymap(const String& name) { return 0; } +void KeymapManager::registerHardwareKeySet(HardwareKeySet *keys) { + if (_hardwareKeys) + error("Hardware key set already registered!"); + _hardwareKeys = keys; +} void KeymapManager::registerDefaultGlobalKeymap(Keymap *map) { ConfigManager::Domain *dom = ConfMan.getDomain(ConfigManager::kApplicationDomain); @@ -75,13 +80,65 @@ void KeymapManager::initKeymap(ConfigManager::Domain *domain, bool KeymapManager::loadKeymap(ConfigManager::Domain *domain, const String& name, Keymap *map) { + ConfigManager::Domain::iterator it; + String prefix = "km_" + name + "_"; + for (it = domain->begin(); it != domain->end(); it++) { + const String& key = it->_key; + if (!key.hasPrefix(prefix.c_str())) + continue; + + // parse UserAction ID + const char *actionIdStart = key.c_str() + prefix.size(); + char *err; + int32 actionId = (int32) strtol(actionIdStart, &err, 0); + if (err == actionIdStart) { + warning("'%s' is not a valid UserAction ID", err); + continue; + } + UserAction *ua = map->getUserAction(actionId); + if (!ua) { + warning("'%s' keymap does not contain UserAction with ID %d", + name.c_str(), (int)actionId); + continue; + } + + // parse HardwareKey ID + int32 hwKeyId = (int32) strtol(it->_value.c_str(), &err, 0); + if (err == it->_value.c_str()) { + warning("'%s' is not a valid HardwareKey ID", err); + continue; + } + const HardwareKey *hwKey = _hardwareKeys->findHardwareKey(hwKeyId); + if (!hwKey) { + warning("HardwareKey with ID %d not known", (int)hwKeyId); + continue; + } + + ua->mapKey(hwKey); + } + return isMapComplete(map); +} + +bool KeymapManager::isMapComplete(const Keymap *map) { return false; } void KeymapManager::saveKeymap(ConfigManager::Domain *domain, const String& name, - Keymap *map) { - + const Keymap *map) { + const Array<UserAction>& actions = map->getUserActions(); + Array<UserAction>::const_iterator it; + char buf[11]; + for (it = actions.begin(); it != actions.end(); it++) { + String key("km_"); + sprintf(buf, "%d", it->id); + key += name + "_" + buf; + if (it->getMappedKey()) + sprintf(buf, "%d", it->getMappedKey()->id); + else + strcpy(buf, ""); + domain->setVal(key, buf); + } } |