summaryrefslogtreecommitdiffstats
blob: 6c7799ec6bccdda89d69ad31849468d104821c08 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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();
}

}