aboutsummaryrefslogtreecommitdiff
path: root/backends/common/keymap-manager.cpp
diff options
context:
space:
mode:
authorStephen Kennedy2008-07-24 10:00:56 +0000
committerStephen Kennedy2008-07-24 10:00:56 +0000
commitdfcdbb0d335128c99d13ba017a4e36f2338f7736 (patch)
tree727f48a0e5e589229788b0c42b0a73cafd31b39e /backends/common/keymap-manager.cpp
parent2f064da1021344f28c9106285475c72930638390 (diff)
downloadscummvm-rg350-dfcdbb0d335128c99d13ba017a4e36f2338f7736.tar.gz
scummvm-rg350-dfcdbb0d335128c99d13ba017a4e36f2338f7736.tar.bz2
scummvm-rg350-dfcdbb0d335128c99d13ba017a4e36f2338f7736.zip
KeymapManager - implemented loading/saving of keymaps
- Refactoring of code to map a key to a UserAction - now we call a method on UserAction to do it (and it then tells the Keymap class) - General cleanup of code svn-id: r33262
Diffstat (limited to 'backends/common/keymap-manager.cpp')
-rw-r--r--backends/common/keymap-manager.cpp61
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);
+ }
}