diff options
-rw-r--r-- | backends/common/keymap-manager.cpp | 52 | ||||
-rw-r--r-- | backends/common/keymap-manager.h | 12 |
2 files changed, 47 insertions, 17 deletions
diff --git a/backends/common/keymap-manager.cpp b/backends/common/keymap-manager.cpp index 26c58be517..d52615faea 100644 --- a/backends/common/keymap-manager.cpp +++ b/backends/common/keymap-manager.cpp @@ -1,29 +1,55 @@ #include "backends/common/keymap-manager.h" +#define GLOBAL_ID "GLOBAL" + namespace Common { -void KeymapManager::registerGlobalKeymap(const String& name, const Keymap& map) { - if (name.size() == 0) { - warning("Name must be specified when registering global keymap"); - return; - } - insertEntry(name, "", map); +bool KeymapManager::registerSuperGlobalKeymap(const Keymap& map) { + return registerKeymap(GLOBAL_ID, GLOBAL_ID, map); } -void KeymapManager::registerKeymap(const String& name, const String& domain, const Keymap& map) { - if (name.size() == 0 || domain.size() == 0) { - warning("Name and domain must be specified when registering keymap"); - return; - } - insertEntry(name, domain, map); +bool KeymapManager::registerGlobalKeymap(const String& name, const Keymap& map) { + return registerKeymap(name, GLOBAL_ID, map); } -void KeymapManager::insertEntry(const String& name, const String& domain, const Keymap& map) { +bool KeymapManager::registerKeymap(const String& name, const String& domain, const Keymap& map) { + if (findEntry(name, domain) != _keymaps.end()) { + warning("Keymap with given name and domain already exists\n"); + return false; + } Entry *ent = new Entry; ent->_name = name; ent->_domain = domain; ent->_keymap = new Keymap(map); _keymaps.push_back(ent); + return true; +} + +bool KeymapManager::unregisterSuperGlobalKeymap() { + return unregisterKeymap(GLOBAL_ID, GLOBAL_ID); +} + +bool KeymapManager::unregisterGlobalKeymap(const String& name) { + return unregisterKeymap(name, GLOBAL_ID); +} + +bool KeymapManager::unregisterKeymap(const String& name, const String& domain) { + Iterator it = findEntry(name, domain); + if (it == _keymaps.end()) + return true; + delete (*it)->_keymap; + delete *it; + _keymaps.erase(it); + return true; +} + +KeymapManager::Iterator KeymapManager::findEntry(const String& name, const String& domain) { + Iterator it; + for (it = _keymaps.begin(); it != _keymaps.end(); it++) { + if ((*it)->_name == name && (*it)->_domain == domain) + break; + } + return it; } } // end of namespace Common
\ No newline at end of file diff --git a/backends/common/keymap-manager.h b/backends/common/keymap-manager.h index 8b945c5c7d..f5878a2467 100644 --- a/backends/common/keymap-manager.h +++ b/backends/common/keymap-manager.h @@ -10,9 +10,13 @@ public: KeymapManager(); - void registerGlobalKeymap(const String& name, const Keymap& map); + bool registerSuperGlobalKeymap(const Keymap& map); + bool registerGlobalKeymap(const String& name, const Keymap& map); + bool registerKeymap(const String& name, const String& domain, const Keymap& map); - void registerKeymap(const String& name, const String& domain, const Keymap& map); + bool unregisterSuperGlobalKeymap(); + bool unregisterGlobalKeymap(const String& name); + bool unregisterKeymap(const String& name, const String& domain); private: @@ -21,11 +25,11 @@ private: String _domain; Keymap *_keymap; }; + typedef List<Entry*>::iterator Iterator; - void insertEntry(const String& name, const String& domain, const Keymap& map); + Iterator findEntry(const String& name, const String& domain); List<Entry*> _keymaps; - }; } // end of namespace Common |