diff options
author | Remko Tronçon <git@el-tramo.be> | 2014-01-19 11:46:51 (GMT) |
---|---|---|
committer | Remko Tronçon <git@el-tramo.be> | 2014-01-19 16:49:19 (GMT) |
commit | cbd01a5368f0b761d2032d75c9f7dfde2bf61578 (patch) | |
tree | 5016505b1e977e84655cc3bba4435ef7cb80e811 /Sluift/ElementConvertors | |
parent | 4083d6da47ac0e3b77da9c7c222a9439b3e1c04c (diff) | |
download | swift-contrib-cbd01a5368f0b761d2032d75c9f7dfde2bf61578.zip swift-contrib-cbd01a5368f0b761d2032d75c9f7dfde2bf61578.tar.bz2 |
Sluift: Add iTunes & PEP User Tune support
Change-Id: I25b3840bb40ce38531922cc737bc82828e026d3f
Diffstat (limited to 'Sluift/ElementConvertors')
-rw-r--r-- | Sluift/ElementConvertors/ElementConvertors.ipp | 4 | ||||
-rw-r--r-- | Sluift/ElementConvertors/SConscript | 1 | ||||
-rw-r--r-- | Sluift/ElementConvertors/UserTuneConvertor.cpp | 111 | ||||
-rw-r--r-- | Sluift/ElementConvertors/UserTuneConvertor.h | 29 |
4 files changed, 144 insertions, 1 deletions
diff --git a/Sluift/ElementConvertors/ElementConvertors.ipp b/Sluift/ElementConvertors/ElementConvertors.ipp index b7b9166..da25eb6 100644 --- a/Sluift/ElementConvertors/ElementConvertors.ipp +++ b/Sluift/ElementConvertors/ElementConvertors.ipp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013 Remko Tronçon + * Copyright (c) 2013-2014 Remko Tronçon * Licensed under the GNU General Public License. * See the COPYING file for more information. */ @@ -10,6 +10,7 @@ #include <Sluift/ElementConvertors/PubSubItemsConvertor.h> #include <Sluift/ElementConvertors/PubSubOwnerRedirectConvertor.h> #include <Sluift/ElementConvertors/PubSubEventRedirectConvertor.h> +#include <Sluift/ElementConvertors/UserTuneConvertor.h> #include <Sluift/ElementConvertors/PubSubConfigureConvertor.h> #include <Sluift/ElementConvertors/PubSubEventDisassociateConvertor.h> #include <Sluift/ElementConvertors/PubSubOwnerAffiliationsConvertor.h> @@ -48,6 +49,7 @@ void LuaElementConvertors::registerConvertors() { convertors.push_back(boost::make_shared<PubSubItemsConvertor>(this)); convertors.push_back(boost::make_shared<PubSubOwnerRedirectConvertor>(this)); convertors.push_back(boost::make_shared<PubSubEventRedirectConvertor>(this)); + convertors.push_back(boost::make_shared<UserTuneConvertor>(this)); convertors.push_back(boost::make_shared<PubSubConfigureConvertor>(this)); convertors.push_back(boost::make_shared<PubSubEventDisassociateConvertor>(this)); convertors.push_back(boost::make_shared<PubSubOwnerAffiliationsConvertor>(this)); diff --git a/Sluift/ElementConvertors/SConscript b/Sluift/ElementConvertors/SConscript index e98f7c4..921e325 100644 --- a/Sluift/ElementConvertors/SConscript +++ b/Sluift/ElementConvertors/SConscript @@ -8,6 +8,7 @@ convertors = [ env.File("PubSubItemsConvertor.cpp"), env.File("PubSubOwnerRedirectConvertor.cpp"), env.File("PubSubEventRedirectConvertor.cpp"), + env.File("UserTuneConvertor.cpp"), env.File("PubSubConfigureConvertor.cpp"), env.File("PubSubEventDisassociateConvertor.cpp"), env.File("PubSubOwnerAffiliationsConvertor.cpp"), diff --git a/Sluift/ElementConvertors/UserTuneConvertor.cpp b/Sluift/ElementConvertors/UserTuneConvertor.cpp new file mode 100644 index 0000000..22ca94e --- /dev/null +++ b/Sluift/ElementConvertors/UserTuneConvertor.cpp @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2014 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#include <Sluift/ElementConvertors/UserTuneConvertor.h> + +#include <lua.hpp> +#include <boost/smart_ptr/make_shared.hpp> +#include <boost/numeric/conversion/cast.hpp> + + + +#pragma clang diagnostic ignored "-Wunused-private-field" + +using namespace Swift; + +UserTuneConvertor::UserTuneConvertor(LuaElementConvertors* convertors) : + GenericLuaElementConvertor<UserTune>("user_tune"), + convertors(convertors) { +} + +UserTuneConvertor::~UserTuneConvertor() { +} + +boost::shared_ptr<UserTune> UserTuneConvertor::doConvertFromLua(lua_State* L) { + boost::shared_ptr<UserTune> result = boost::make_shared<UserTune>(); + lua_getfield(L, -1, "rating"); + if (lua_isnumber(L, -1)) { + result->setRating(boost::numeric_cast<unsigned int>(lua_tonumber(L, -1))); + } + lua_pop(L, 1); + lua_getfield(L, -1, "title"); + if (lua_isstring(L, -1)) { + result->setTitle(std::string(lua_tostring(L, -1))); + } + lua_pop(L, 1); + lua_getfield(L, -1, "track"); + if (lua_isstring(L, -1)) { + result->setTrack(std::string(lua_tostring(L, -1))); + } + lua_pop(L, 1); + lua_getfield(L, -1, "artist"); + if (lua_isstring(L, -1)) { + result->setArtist(std::string(lua_tostring(L, -1))); + } + lua_pop(L, 1); + lua_getfield(L, -1, "uri"); + if (lua_isstring(L, -1)) { + result->setURI(std::string(lua_tostring(L, -1))); + } + lua_pop(L, 1); + lua_getfield(L, -1, "source"); + if (lua_isstring(L, -1)) { + result->setSource(std::string(lua_tostring(L, -1))); + } + lua_pop(L, 1); + lua_getfield(L, -1, "length"); + if (lua_isnumber(L, -1)) { + result->setLength(boost::numeric_cast<unsigned int>(lua_tonumber(L, -1))); + } + lua_pop(L, 1); + return result; +} + +void UserTuneConvertor::doConvertToLua(lua_State* L, boost::shared_ptr<UserTune> payload) { + lua_createtable(L, 0, 0); + if (payload->getRating()) { + lua_pushnumber(L, (*payload->getRating())); + lua_setfield(L, -2, "rating"); + } + if (payload->getTitle()) { + lua_pushstring(L, (*payload->getTitle()).c_str()); + lua_setfield(L, -2, "title"); + } + if (payload->getTrack()) { + lua_pushstring(L, (*payload->getTrack()).c_str()); + lua_setfield(L, -2, "track"); + } + if (payload->getArtist()) { + lua_pushstring(L, (*payload->getArtist()).c_str()); + lua_setfield(L, -2, "artist"); + } + if (payload->getURI()) { + lua_pushstring(L, (*payload->getURI()).c_str()); + lua_setfield(L, -2, "uri"); + } + if (payload->getSource()) { + lua_pushstring(L, (*payload->getSource()).c_str()); + lua_setfield(L, -2, "source"); + } + if (payload->getLength()) { + lua_pushnumber(L, (*payload->getLength())); + lua_setfield(L, -2, "length"); + } +} + +boost::optional<LuaElementConvertor::Documentation> UserTuneConvertor::getDocumentation() const { + return Documentation( + "UserTune", + "This table has the following fields:\n\n" + "- `rating`: number (Optional)\n" + "- `title`: string (Optional)\n" + "- `track`: string (Optional)\n" + "- `artist`: string (Optional)\n" + "- `uri`: string (Optional)\n" + "- `source`: string (Optional)\n" + "- `length`: number (Optional)\n" + ); +} diff --git a/Sluift/ElementConvertors/UserTuneConvertor.h b/Sluift/ElementConvertors/UserTuneConvertor.h new file mode 100644 index 0000000..6f95164 --- /dev/null +++ b/Sluift/ElementConvertors/UserTuneConvertor.h @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2014 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Base/Override.h> + +#include <Sluift/GenericLuaElementConvertor.h> +#include <Swiften/Elements/UserTune.h> + +namespace Swift { + class LuaElementConvertors; + + class UserTuneConvertor : public GenericLuaElementConvertor<UserTune> { + public: + UserTuneConvertor(LuaElementConvertors* convertors); + virtual ~UserTuneConvertor(); + + virtual boost::shared_ptr<UserTune> doConvertFromLua(lua_State*) SWIFTEN_OVERRIDE; + virtual void doConvertToLua(lua_State*, boost::shared_ptr<UserTune>) SWIFTEN_OVERRIDE; + virtual boost::optional<Documentation> getDocumentation() const SWIFTEN_OVERRIDE; + + private: + LuaElementConvertors* convertors; + }; +} |