aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormontellese <montellese@xbmc.org>2013-10-12 14:38:09 +0200
committermontellese <montellese@xbmc.org>2013-11-03 12:18:25 +0100
commit1b7dbe5b4d13573e90e0dd0a2cf2b16d8bd83c35 (patch)
treec0c3f47b577649b00dddd6a55f91d4e01f3cdf4a
parent3636415f2e050200471e9d9e5f8a0ed847c4b666 (diff)
jsonrpc: add support for multiple items to Playlist.Add/Insert
-rw-r--r--addons/xbmc.json/addon.xml2
-rw-r--r--xbmc/interfaces/json-rpc/PlaylistOperations.cpp90
-rw-r--r--xbmc/interfaces/json-rpc/PlaylistOperations.h4
-rw-r--r--xbmc/interfaces/json-rpc/ServiceDescription.h16
-rw-r--r--xbmc/interfaces/json-rpc/methods.json14
5 files changed, 81 insertions, 45 deletions
diff --git a/addons/xbmc.json/addon.xml b/addons/xbmc.json/addon.xml
index 7b46134a29..acf321482b 100644
--- a/addons/xbmc.json/addon.xml
+++ b/addons/xbmc.json/addon.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
-<addon id="xbmc.json" version="6.10.0" provider-name="Team XBMC">
+<addon id="xbmc.json" version="6.11.0" provider-name="Team XBMC">
<backwards-compatibility abi="6.0.0"/>
<requires>
<import addon="xbmc.core" version="0.1.0"/>
diff --git a/xbmc/interfaces/json-rpc/PlaylistOperations.cpp b/xbmc/interfaces/json-rpc/PlaylistOperations.cpp
index a47eed29b1..b8a398cf63 100644
--- a/xbmc/interfaces/json-rpc/PlaylistOperations.cpp
+++ b/xbmc/interfaces/json-rpc/PlaylistOperations.cpp
@@ -95,15 +95,15 @@ JSONRPC_STATUS CPlaylistOperations::GetItems(const CStdString &method, ITranspor
return OK;
}
-bool CPlaylistOperations::CheckMediaParameter(int playlist, const CVariant &parameterObject)
+bool CPlaylistOperations::CheckMediaParameter(int playlist, const CVariant &itemObject)
{
- if (parameterObject["item"].isMember("media") && parameterObject["item"]["media"].asString().compare("files") != 0)
+ if (itemObject.isMember("media") && itemObject["media"].asString().compare("files") != 0)
{
- if (playlist == PLAYLIST_VIDEO && parameterObject["item"]["media"].asString().compare("video") != 0)
+ if (playlist == PLAYLIST_VIDEO && itemObject["media"].asString().compare("video") != 0)
return false;
- if (playlist == PLAYLIST_MUSIC && parameterObject["item"]["media"].asString().compare("music") != 0)
+ if (playlist == PLAYLIST_MUSIC && itemObject["media"].asString().compare("music") != 0)
return false;
- if (playlist == PLAYLIST_PICTURE && parameterObject["item"]["media"].asString().compare("video") != 0 && parameterObject["item"]["media"].asString().compare("pictures") != 0)
+ if (playlist == PLAYLIST_PICTURE && itemObject["media"].asString().compare("video") != 0 && itemObject["media"].asString().compare("pictures") != 0)
return false;
}
return true;
@@ -112,38 +112,27 @@ bool CPlaylistOperations::CheckMediaParameter(int playlist, const CVariant &para
JSONRPC_STATUS CPlaylistOperations::Add(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result)
{
int playlist = GetPlaylist(parameterObject["playlistid"]);
- CFileItemList list;
- CVariant params = parameterObject;
- if (!CheckMediaParameter(playlist, parameterObject))
+ CGUIWindowSlideShow *slideshow = NULL;
+ if (playlist == PLAYLIST_PICTURE)
+ {
+ slideshow = (CGUIWindowSlideShow*)g_windowManager.GetWindow(WINDOW_SLIDESHOW);
+ if (slideshow == NULL)
+ return FailedToExecute;
+ }
+
+ CFileItemList list;
+ if (!HandleItemsParameter(playlist, parameterObject["item"], list))
return InvalidParams;
- CGUIWindowSlideShow *slideshow = NULL;
switch (playlist)
{
case PLAYLIST_VIDEO:
case PLAYLIST_MUSIC:
- if (playlist == PLAYLIST_VIDEO)
- params["item"]["media"] = "video";
- else if (playlist == PLAYLIST_MUSIC)
- params["item"]["media"] = "music";
-
- if (!FillFileItemList(params["item"], list))
- return InvalidParams;
-
CApplicationMessenger::Get().PlayListPlayerAdd(playlist, list);
-
break;
case PLAYLIST_PICTURE:
- slideshow = (CGUIWindowSlideShow*)g_windowManager.GetWindow(WINDOW_SLIDESHOW);
- if (!slideshow)
- return FailedToExecute;
- if (!parameterObject["item"].isMember("media"))
- params["item"]["media"] = "pictures";
- if (!FillFileItemList(params["item"], list))
- return InvalidParams;
-
for (int index = 0; index < list.Size(); index++)
{
CPictureInfoTag picture = CPictureInfoTag();
@@ -154,6 +143,9 @@ JSONRPC_STATUS CPlaylistOperations::Add(const CStdString &method, ITransportLaye
slideshow->Add(list[index].get());
}
break;
+
+ default:
+ return InvalidParams;
}
NotifyAll();
@@ -166,19 +158,8 @@ JSONRPC_STATUS CPlaylistOperations::Insert(const CStdString &method, ITransportL
if (playlist == PLAYLIST_PICTURE)
return FailedToExecute;
- if (!CheckMediaParameter(playlist, parameterObject))
- return InvalidParams;
-
CFileItemList list;
- CVariant params = parameterObject;
- if (playlist == PLAYLIST_VIDEO)
- params["item"]["media"] = "video";
- else if (playlist == PLAYLIST_MUSIC)
- params["item"]["media"] = "music";
- else
- return FailedToExecute;
-
- if (!FillFileItemList(params["item"], list))
+ if (!HandleItemsParameter(playlist, parameterObject["item"], list))
return InvalidParams;
CApplicationMessenger::Get().PlayListPlayerInsert(GetPlaylist(parameterObject["playlistid"]), list, (int)parameterObject["position"].asInteger());
@@ -307,3 +288,36 @@ JSONRPC_STATUS CPlaylistOperations::GetPropertyValue(int playlist, const CStdStr
return OK;
}
+
+bool CPlaylistOperations::HandleItemsParameter(int playlistid, const CVariant &itemParam, CFileItemList &items)
+{
+ vector<CVariant> vecItems;
+ if (itemParam.isArray())
+ vecItems.assign(itemParam.begin_array(), itemParam.end_array());
+ else
+ vecItems.push_back(itemParam);
+
+ bool success = false;
+ for (vector<CVariant>::iterator itemIt = vecItems.begin(); itemIt != vecItems.end(); ++itemIt)
+ {
+ if (!CheckMediaParameter(playlistid, *itemIt))
+ continue;
+
+ switch (playlistid)
+ {
+ case PLAYLIST_VIDEO:
+ (*itemIt)["media"] = "video";
+ break;
+ case PLAYLIST_MUSIC:
+ (*itemIt)["media"] = "music";
+ break;
+ case PLAYLIST_PICTURE:
+ (*itemIt)["media"] = "pictures";
+ break;
+ }
+
+ success |= FillFileItemList(*itemIt, items);
+ }
+
+ return success;
+}
diff --git a/xbmc/interfaces/json-rpc/PlaylistOperations.h b/xbmc/interfaces/json-rpc/PlaylistOperations.h
index 1164341be6..54df4a1d99 100644
--- a/xbmc/interfaces/json-rpc/PlaylistOperations.h
+++ b/xbmc/interfaces/json-rpc/PlaylistOperations.h
@@ -22,6 +22,7 @@
#include "utils/StdString.h"
#include "JSONRPC.h"
#include "FileItemHandler.h"
+#include "FileItem.h"
namespace JSONRPC
{
@@ -41,6 +42,7 @@ namespace JSONRPC
static int GetPlaylist(const CVariant &playlist);
static inline void NotifyAll();
static JSONRPC_STATUS GetPropertyValue(int playlist, const CStdString &property, CVariant &result);
- static bool CheckMediaParameter(int playlist, const CVariant &parameterObject);
+ static bool CheckMediaParameter(int playlist, const CVariant &itemObject);
+ static bool HandleItemsParameter(int playlistid, const CVariant &itemParam, CFileItemList &items);
};
}
diff --git a/xbmc/interfaces/json-rpc/ServiceDescription.h b/xbmc/interfaces/json-rpc/ServiceDescription.h
index b431a25518..d2fe03613b 100644
--- a/xbmc/interfaces/json-rpc/ServiceDescription.h
+++ b/xbmc/interfaces/json-rpc/ServiceDescription.h
@@ -22,7 +22,7 @@
namespace JSONRPC
{
const char* const JSONRPC_SERVICE_ID = "http://xbmc.org/jsonrpc/ServiceDescription.json";
- const char* const JSONRPC_SERVICE_VERSION = "6.10.0";
+ const char* const JSONRPC_SERVICE_VERSION = "6.11.0";
const char* const JSONRPC_SERVICE_DESCRIPTION = "JSON-RPC API of XBMC";
const char* const JSONRPC_SERVICE_TYPES[] = {
@@ -1834,7 +1834,12 @@ namespace JSONRPC
"\"permission\": \"ControlPlayback\","
"\"params\": ["
"{ \"name\": \"playlistid\", \"$ref\": \"Playlist.Id\", \"required\": true },"
- "{ \"name\": \"item\", \"$ref\": \"Playlist.Item\", \"required\": true }"
+ "{ \"name\": \"item\","
+ "\"type\": ["
+ "{ \"$ref\": \"Playlist.Item\", \"required\": true },"
+ "{ \"type\": \"array\", \"items\": { \"$ref\": \"Playlist.Item\" }, \"required\": true }"
+ "],"
+ "\"required\": true }"
"],"
"\"returns\": \"string\""
"}",
@@ -1846,7 +1851,12 @@ namespace JSONRPC
"\"params\": ["
"{ \"name\": \"playlistid\", \"$ref\": \"Playlist.Id\", \"required\": true },"
"{ \"name\": \"position\", \"$ref\": \"Playlist.Position\", \"required\": true },"
- "{ \"name\": \"item\", \"$ref\": \"Playlist.Item\", \"required\": true }"
+ "{ \"name\": \"item\","
+ "\"type\": ["
+ "{ \"$ref\": \"Playlist.Item\", \"required\": true },"
+ "{ \"type\": \"array\", \"items\": { \"$ref\": \"Playlist.Item\" }, \"required\": true }"
+ "],"
+ "\"required\": true }"
"],"
"\"returns\": \"string\""
"}",
diff --git a/xbmc/interfaces/json-rpc/methods.json b/xbmc/interfaces/json-rpc/methods.json
index cbe2a675cd..33248c54bd 100644
--- a/xbmc/interfaces/json-rpc/methods.json
+++ b/xbmc/interfaces/json-rpc/methods.json
@@ -441,7 +441,12 @@
"permission": "ControlPlayback",
"params": [
{ "name": "playlistid", "$ref": "Playlist.Id", "required": true },
- { "name": "item", "$ref": "Playlist.Item", "required": true }
+ { "name": "item",
+ "type": [
+ { "$ref": "Playlist.Item", "required": true },
+ { "type": "array", "items": { "$ref": "Playlist.Item" }, "required": true }
+ ],
+ "required": true }
],
"returns": "string"
},
@@ -453,7 +458,12 @@
"params": [
{ "name": "playlistid", "$ref": "Playlist.Id", "required": true },
{ "name": "position", "$ref": "Playlist.Position", "required": true },
- { "name": "item", "$ref": "Playlist.Item", "required": true }
+ { "name": "item",
+ "type": [
+ { "$ref": "Playlist.Item", "required": true },
+ { "type": "array", "items": { "$ref": "Playlist.Item" }, "required": true }
+ ],
+ "required": true }
],
"returns": "string"
},