summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2014-01-19 11:46:51 (GMT)
committerRemko Tronçon <git@el-tramo.be>2014-01-19 16:49:19 (GMT)
commitcbd01a5368f0b761d2032d75c9f7dfde2bf61578 (patch)
tree5016505b1e977e84655cc3bba4435ef7cb80e811 /Swiften/Serializer/PayloadSerializers/UserTuneSerializer.cpp
parent4083d6da47ac0e3b77da9c7c222a9439b3e1c04c (diff)
downloadswift-contrib-cbd01a5368f0b761d2032d75c9f7dfde2bf61578.zip
swift-contrib-cbd01a5368f0b761d2032d75c9f7dfde2bf61578.tar.bz2
Sluift: Add iTunes & PEP User Tune support
Change-Id: I25b3840bb40ce38531922cc737bc82828e026d3f
Diffstat (limited to 'Swiften/Serializer/PayloadSerializers/UserTuneSerializer.cpp')
-rw-r--r--Swiften/Serializer/PayloadSerializers/UserTuneSerializer.cpp48
1 files changed, 48 insertions, 0 deletions
diff --git a/Swiften/Serializer/PayloadSerializers/UserTuneSerializer.cpp b/Swiften/Serializer/PayloadSerializers/UserTuneSerializer.cpp
new file mode 100644
index 0000000..6c7799e
--- /dev/null
+++ b/Swiften/Serializer/PayloadSerializers/UserTuneSerializer.cpp
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2014 Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#include <Swiften/Serializer/PayloadSerializers/UserTuneSerializer.h>
+
+#include <boost/shared_ptr.hpp>
+#include <boost/smart_ptr/make_shared.hpp>
+#include <boost/lexical_cast.hpp>
+
+#include <Swiften/Base/foreach.h>
+#include <Swiften/Serializer/XML/XMLElement.h>
+
+namespace Swift {
+
+UserTuneSerializer::UserTuneSerializer() {
+}
+
+std::string UserTuneSerializer::serializePayload(
+ boost::shared_ptr<UserTune> payload) const {
+ XMLElement result("tune", "http://jabber.org/protocol/tune");
+ if (boost::optional<std::string> value = payload->getArtist()) {
+ result.addNode(boost::make_shared<XMLElement>("artist", "", *value));
+ }
+ if (boost::optional<unsigned int> value = payload->getLength()) {
+ result.addNode(boost::make_shared<XMLElement>("length", "", boost::lexical_cast<std::string>(*value)));
+ }
+ if (boost::optional<unsigned int> value = payload->getRating()) {
+ result.addNode(boost::make_shared<XMLElement>("rating", "", boost::lexical_cast<std::string>(*value)));
+ }
+ if (boost::optional<std::string> value = payload->getSource()) {
+ result.addNode(boost::make_shared<XMLElement>("source", "", *value));
+ }
+ if (boost::optional<std::string> value = payload->getTitle()) {
+ result.addNode(boost::make_shared<XMLElement>("title", "", *value));
+ }
+ if (boost::optional<std::string> value = payload->getTrack()) {
+ result.addNode(boost::make_shared<XMLElement>("track", "", *value));
+ }
+ if (boost::optional<std::string> value = payload->getURI()) {
+ result.addNode(boost::make_shared<XMLElement>("uri", "", *value));
+ }
+ return result.serialize();
+}
+
+}