summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Sluift/sluift.cpp')
-rw-r--r--Sluift/sluift.cpp39
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