diff options
author | dknn <yoann.blein@free.fr> | 2012-08-10 18:04:56 (GMT) |
---|---|---|
committer | dknn <yoann.blein@free.fr> | 2012-09-22 09:32:38 (GMT) |
commit | 955c4589ca254814ae7ec6ed911e0a62febc5da1 (patch) | |
tree | 1d3ba8ecc732f8239462f7428e758224f3d38b94 /Swiften/Parser/PayloadParsers/InputEventParser.cpp | |
parent | 577fffec4a1da6909740a392cf76617bdcbe5570 (diff) | |
download | swift-contrib-955c4589ca254814ae7ec6ed911e0a62febc5da1.zip swift-contrib-955c4589ca254814ae7ec6ed911e0a62febc5da1.tar.bz2 |
Capture and send user UI events
Diffstat (limited to 'Swiften/Parser/PayloadParsers/InputEventParser.cpp')
-rw-r--r-- | Swiften/Parser/PayloadParsers/InputEventParser.cpp | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/Swiften/Parser/PayloadParsers/InputEventParser.cpp b/Swiften/Parser/PayloadParsers/InputEventParser.cpp new file mode 100644 index 0000000..44d9849 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/InputEventParser.cpp @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2012 Yoann Blein + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#include <Swiften/Parser/PayloadParsers/InputEventParser.h> + +#include <boost/optional.hpp> +#include <boost/lexical_cast.hpp> + +namespace Swift { + +void InputEventParser::handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) { + if (level == 0) { + // <inputevt> tag + InputEventPayload::ref payload = getPayloadInternal(); + payload->setAction(actionFromString(attributes.getAttributeValue("action").get_value_or(""))); + } else if (level == 1) { + // <remote-control> tag + } else if (level == 2) { + InputEventPayload::Event event(eventTypeFromString(element)); + switch (event.type) { + case InputEventPayload::Event::MouseMove: + try { + event.realArg1 = boost::lexical_cast<float>(attributes.getAttributeValue("x").get_value_or("0")); + event.realArg2 = boost::lexical_cast<float>(attributes.getAttributeValue("y").get_value_or("0")); + } catch (boost::bad_lexical_cast &) {} + break; + case InputEventPayload::Event::MouseWheel: + case InputEventPayload::Event::MousePress: + case InputEventPayload::Event::MouseRelease: + case InputEventPayload::Event::KeyType: + case InputEventPayload::Event::KeyPress: + case InputEventPayload::Event::KeyRelease: + try { + event.integerArg = boost::lexical_cast<int>(attributes.getEntries().front().getValue()); + } catch (boost::bad_lexical_cast &) {} + default: + break; + } + } + ++level; +} + +void InputEventParser::handleEndElement(const std::string&, const std::string&) { + --level; +} + +void InputEventParser::handleCharacterData(const std::string&){ + +} + +InputEventPayload::Action InputEventParser::actionFromString(const std::string& action) +{ + if (action == "notify") + return InputEventPayload::Notify; + + return InputEventPayload::Unknown; +} + +InputEventPayload::Event::EventType InputEventParser::eventTypeFromString(const std::string& eventType) { + if (eventType == "mouse-move") + return InputEventPayload::Event::MouseMove; + else if (eventType == "mouse-wheel") + return InputEventPayload::Event::MouseWheel; + else if (eventType == "mouse-press") + return InputEventPayload::Event::MousePress; + else if (eventType == "mouse-release") + return InputEventPayload::Event::MouseRelease; + else if (eventType == "key-type") + return InputEventPayload::Event::KeyType; + else if (eventType == "key-press") + return InputEventPayload::Event::KeyPress; + else if (eventType == "key-release") + return InputEventPayload::Event::KeyRelease; + + return InputEventPayload::Event::Unknown; +} + +} |