Skip to content

Commit

Permalink
jsonrpc: add Player.SetPartymode
Browse files Browse the repository at this point in the history
  • Loading branch information
Montellese committed Sep 30, 2012
1 parent 37ed4d9 commit 95c4719
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 0 deletions.
11 changes: 11 additions & 0 deletions xbmc/PartyModeManager.cpp
Expand Up @@ -550,6 +550,17 @@ int CPartyModeManager::GetRandomSongs()
return m_iRandomSongs; return m_iRandomSongs;
} }


PartyModeContext CPartyModeManager::GetType() const
{
if (!IsEnabled())
return PARTYMODECONTEXT_UNKNOWN;

if (m_bIsVideo)
return PARTYMODECONTEXT_VIDEO;

return PARTYMODECONTEXT_MUSIC;
}

void CPartyModeManager::ClearState() void CPartyModeManager::ClearState()
{ {
m_iLastUserSong = -1; m_iLastUserSong = -1;
Expand Down
1 change: 1 addition & 0 deletions xbmc/PartyModeManager.h
Expand Up @@ -56,6 +56,7 @@ class CPartyModeManager
int GetMatchingSongsLeft(); int GetMatchingSongsLeft();
int GetRelaxedSongs(); int GetRelaxedSongs();
int GetRandomSongs(); int GetRandomSongs();
PartyModeContext GetType() const;


private: private:
void Process(); void Process();
Expand Down
1 change: 1 addition & 0 deletions xbmc/interfaces/json-rpc/JSONServiceDescription.cpp
Expand Up @@ -80,6 +80,7 @@ JsonRpcMethodMap CJSONServiceDescription::m_methodMaps[] = {
{ "Player.Shuffle", CPlayerOperations::Shuffle }, { "Player.Shuffle", CPlayerOperations::Shuffle },
{ "Player.UnShuffle", CPlayerOperations::UnShuffle }, { "Player.UnShuffle", CPlayerOperations::UnShuffle },
{ "Player.Repeat", CPlayerOperations::Repeat }, { "Player.Repeat", CPlayerOperations::Repeat },
{ "Player.SetPartymode", CPlayerOperations::SetPartymode },


{ "Player.SetAudioStream", CPlayerOperations::SetAudioStream }, { "Player.SetAudioStream", CPlayerOperations::SetAudioStream },
{ "Player.SetSubtitle", CPlayerOperations::SetSubtitle }, { "Player.SetSubtitle", CPlayerOperations::SetSubtitle },
Expand Down
50 changes: 50 additions & 0 deletions xbmc/interfaces/json-rpc/PlayerOperations.cpp
Expand Up @@ -681,6 +681,56 @@ JSONRPC_STATUS CPlayerOperations::Repeat(const CStdString &method, ITransportLay
return ACK; return ACK;
} }


JSONRPC_STATUS CPlayerOperations::SetPartymode(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result)
{
PlayerType player = GetPlayer(parameterObject["playerid"]);
switch (player)
{
case Video:
case Audio:
{
bool change = false;
PartyModeContext context = PARTYMODECONTEXT_UNKNOWN;
std::string strContext;
if (player == Video)
{
context = PARTYMODECONTEXT_VIDEO;
strContext = "video";
}
else if (player == Audio)
{
context = PARTYMODECONTEXT_MUSIC;
strContext = "music";
}

bool toggle = parameterObject["partymode"].isString();
if (g_partyModeManager.IsEnabled())
{
if (g_partyModeManager.GetType() != context)
return InvalidParams;

if (toggle || parameterObject["partymode"].asBoolean() == false)
change = true;
}
else
{
if (toggle || parameterObject["partymode"].asBoolean() == true)
change = true;
}

if (change)
CApplicationMessenger::Get().ExecBuiltIn("playercontrol(partymode(" + strContext + "))");
break;
}

case Picture:
default:
return FailedToExecute;
}

return ACK;
}

JSONRPC_STATUS CPlayerOperations::SetAudioStream(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result) JSONRPC_STATUS CPlayerOperations::SetAudioStream(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result)
{ {
switch (GetPlayer(parameterObject["playerid"])) switch (GetPlayer(parameterObject["playerid"]))
Expand Down
1 change: 1 addition & 0 deletions xbmc/interfaces/json-rpc/PlayerOperations.h
Expand Up @@ -64,6 +64,7 @@ namespace JSONRPC
static JSONRPC_STATUS Shuffle(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result); static JSONRPC_STATUS Shuffle(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result);
static JSONRPC_STATUS UnShuffle(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result); static JSONRPC_STATUS UnShuffle(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result);
static JSONRPC_STATUS Repeat(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result); static JSONRPC_STATUS Repeat(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result);
static JSONRPC_STATUS SetPartymode(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result);


static JSONRPC_STATUS SetAudioStream(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result); static JSONRPC_STATUS SetAudioStream(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result);
static JSONRPC_STATUS SetSubtitle(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result); static JSONRPC_STATUS SetSubtitle(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result);
Expand Down
11 changes: 11 additions & 0 deletions xbmc/interfaces/json-rpc/ServiceDescription.h
Expand Up @@ -1457,6 +1457,17 @@ namespace JSONRPC
"]," "],"
"\"returns\": \"string\"" "\"returns\": \"string\""
"}", "}",
"\"Player.SetPartymode\": {"
"\"type\": \"method\","
"\"description\": \"Turn partymode on or off\","
"\"transport\": \"Response\","
"\"permission\": \"ControlPlayback\","
"\"params\": ["
"{ \"name\": \"playerid\", \"$ref\": \"Player.Id\", \"required\": true },"
"{ \"name\": \"partymode\", \"$ref\": \"Global.Toggle\", \"required\": true }"
"],"
"\"returns\": \"string\""
"}",
"\"Player.SetAudioStream\": {" "\"Player.SetAudioStream\": {"
"\"type\": \"method\"," "\"type\": \"method\","
"\"description\": \"Set the audio stream played by the player\"," "\"description\": \"Set the audio stream played by the player\","
Expand Down
11 changes: 11 additions & 0 deletions xbmc/interfaces/json-rpc/methods.json
Expand Up @@ -393,6 +393,17 @@
], ],
"returns": "string" "returns": "string"
}, },
"Player.SetPartymode": {
"type": "method",
"description": "Turn partymode on or off",
"transport": "Response",
"permission": "ControlPlayback",
"params": [
{ "name": "playerid", "$ref": "Player.Id", "required": true },
{ "name": "partymode", "$ref": "Global.Toggle", "required": true }
],
"returns": "string"
},
"Player.SetAudioStream": { "Player.SetAudioStream": {
"type": "method", "type": "method",
"description": "Set the audio stream played by the player", "description": "Set the audio stream played by the player",
Expand Down

0 comments on commit 95c4719

Please sign in to comment.