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/sluift.cpp | |
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/sluift.cpp')
-rw-r--r-- | Sluift/sluift.cpp | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/Sluift/sluift.cpp b/Sluift/sluift.cpp index 08ffd92..17990e8 100644 --- a/Sluift/sluift.cpp +++ b/Sluift/sluift.cpp @@ -34,4 +34,5 @@ #include <Swiften/Crypto/CryptoProvider.h> #include <Swiften/Crypto/PlatformCryptoProvider.h> +#include <Sluift/ITunesInterface.h> using namespace Swift; @@ -177,5 +178,4 @@ SLUIFT_LUA_FUNCTION_WITH_HELP( } - /******************************************************************************* * JID Functions @@ -272,4 +272,32 @@ SLUIFT_LUA_FUNCTION(IDN, stringprep) { } +/******************************************************************************* + * iTunes Functions + ******************************************************************************/ + +#ifdef HAVE_ITUNES +SLUIFT_LUA_FUNCTION(iTunes, get_current_track) { + boost::optional<ITunesInterface::Track> track = Sluift::globals.iTunes.getCurrentTrack(); + if (!track) { + return 0; + } + lua_createtable(L, 0, 0); + lua_pushstring(L, track->artist.c_str()); + lua_setfield(L, -2, "artist"); + lua_pushstring(L, track->name.c_str()); + lua_setfield(L, -2, "name"); + lua_pushstring(L, track->album.c_str()); + lua_setfield(L, -2, "album"); + lua_pushinteger(L, track->trackNumber); + lua_setfield(L, -2, "track_number"); + lua_pushnumber(L, track->duration); + lua_setfield(L, -2, "duration"); + lua_pushinteger(L, track->rating); + lua_setfield(L, -2, "rating"); + Lua::registerTableToString(L, -1); + Lua::registerTableEquals(L, -1); + return 1; +} +#endif /******************************************************************************* @@ -297,4 +325,9 @@ SLUIFT_API int luaopen_sluift(lua_State* L) { Sluift::globals.coreLibIndex = luaL_ref(L, LUA_REGISTRYINDEX); + lua_rawgeti(L, LUA_REGISTRYINDEX, Sluift::globals.coreLibIndex); + lua_getfield(L, -1, "Client"); + lua_setmetatable(L, -3); + lua_pop(L, 1); + // Register functions Lua::FunctionRegistry::getInstance().addFunctionsToTable(L, "Sluift"); @@ -305,4 +338,8 @@ SLUIFT_API int luaopen_sluift(lua_State* L) { Lua::FunctionRegistry::getInstance().createFunctionTable(L, "IDN"); lua_setfield(L, -2, "idn"); +#ifdef HAVE_ITUNES + Lua::FunctionRegistry::getInstance().createFunctionTable(L, "iTunes"); + lua_setfield(L, -2, "itunes"); +#endif // Register convenience functions |