[Scummvm-cvs-logs] SF.net SVN: scummvm:[33131] scummvm/branches/gsoc2008-vkeybd/backends/ common

kenny-d at users.sourceforge.net kenny-d at users.sourceforge.net
Sun Jul 20 17:42:55 CEST 2008


Revision: 33131
          http://scummvm.svn.sourceforge.net/scummvm/?rev=33131&view=rev
Author:   kenny-d
Date:     2008-07-20 15:42:52 +0000 (Sun, 20 Jul 2008)

Log Message:
-----------
WIP KeymapManager implementation, can only register/unregister keymaps.

Modified Paths:
--------------
    scummvm/branches/gsoc2008-vkeybd/backends/common/keymap-manager.cpp
    scummvm/branches/gsoc2008-vkeybd/backends/common/keymap-manager.h

Modified: scummvm/branches/gsoc2008-vkeybd/backends/common/keymap-manager.cpp
===================================================================
--- scummvm/branches/gsoc2008-vkeybd/backends/common/keymap-manager.cpp	2008-07-20 15:16:26 UTC (rev 33130)
+++ scummvm/branches/gsoc2008-vkeybd/backends/common/keymap-manager.cpp	2008-07-20 15:42:52 UTC (rev 33131)
@@ -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

Modified: scummvm/branches/gsoc2008-vkeybd/backends/common/keymap-manager.h
===================================================================
--- scummvm/branches/gsoc2008-vkeybd/backends/common/keymap-manager.h	2008-07-20 15:16:26 UTC (rev 33130)
+++ scummvm/branches/gsoc2008-vkeybd/backends/common/keymap-manager.h	2008-07-20 15:42:52 UTC (rev 33131)
@@ -10,9 +10,13 @@
 
 	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 @@
 		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


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list