Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add support for limits to Files.GetDirectory

Also removes an unneeded loop.
  • Loading branch information...
commit ff3611c86b68103abd0cde4142d2b4cdf5b9690c 1 parent bef3b9f
Tolriq authored
5 xbmc/interfaces/json-rpc/FileItemHandler.cpp
View
@@ -306,6 +306,11 @@ void CFileItemHandler::HandleFileItem(const char *ID, bool allowFile, const char
if (!object.isMember("type"))
object["type"] = "unknown";
+
+ if (item->m_bIsFolder)
Sascha Montellese Owner

I'll have to revert this part of the change (i.e. saving the extra loops) because it results in "filetype" being returned in unwanted calls like Player.GetItem.

Tolriq
Tolriq added a note

Should not this field be added to definition if it really appears ? Speed on low end device is important and this data is not something without meaning so may be added.

Or i can search a better way but reverting speed gain should check for other solutions.

Sascha Montellese Owner

It's not the code that should dictate how the API looks like, it's the API that should dictate how the code works. With this change "filetype" is added to the result of some methods where it simply doesn't belong (for Player.GetItem the "filetype" property would always be "file" so it doesn't provide any useful information).

Tolriq
Tolriq added a note

So passing the field in parameterObject and check for it or any other way to keep speed should not be envisaged because speed does not matter ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ object["filetype"] = "directory";
+ else
+ object["filetype"] = "file";
}
}
26 xbmc/interfaces/json-rpc/FileOperations.cpp
View
@@ -113,7 +113,7 @@ JSONRPC_STATUS CFileOperations::GetDirectory(const CStdString &method, ITranspor
if (CDirectory::GetDirectory(strPath, items, extensions))
{
- CFileItemList filteredDirectories, filteredFiles;
+ CFileItemList filteredFiles;
for (unsigned int i = 0; i < (unsigned int)items.Size(); i++)
{
if (CUtil::ExcludeFileOrFolder(items[i]->GetPath(), regexps))
@@ -131,9 +131,6 @@ JSONRPC_STATUS CFileOperations::GetDirectory(const CStdString &method, ITranspor
media == "files" ||
URIUtils::IsUPnP(items.GetPath()))
{
- if (items[i]->m_bIsFolder)
- filteredDirectories.Add(items[i]);
- else
filteredFiles.Add(items[i]);
}
else
@@ -141,16 +138,10 @@ JSONRPC_STATUS CFileOperations::GetDirectory(const CStdString &method, ITranspor
CFileItemPtr fileItem(new CFileItem());
if (FillFileItem(items[i], fileItem, media, parameterObject))
{
- if (items[i]->m_bIsFolder)
- filteredDirectories.Add(fileItem);
- else
filteredFiles.Add(fileItem);
}
else
{
- if (items[i]->m_bIsFolder)
- filteredDirectories.Add(items[i]);
- else
filteredFiles.Add(items[i]);
}
}
@@ -176,22 +167,7 @@ JSONRPC_STATUS CFileOperations::GetDirectory(const CStdString &method, ITranspor
if (!hasFileField)
param["properties"].append("file");
- HandleFileItemList("id", true, "files", filteredDirectories, param, result);
- for (unsigned int index = 0; index < result["files"].size(); index++)
- {
- result["files"][index]["filetype"] = "directory";
- }
- int count = (int)result["limits"]["total"].asInteger();
-
HandleFileItemList("id", true, "files", filteredFiles, param, result);
- for (unsigned int index = count; index < result["files"].size(); index++)
- {
- result["files"][index]["filetype"] = "file";
- }
- count += (int)result["limits"]["total"].asInteger();
-
- result["limits"]["end"] = count;
- result["limits"]["total"] = count;
return OK;
}
5 xbmc/interfaces/json-rpc/ServiceDescription.h
View
@@ -22,7 +22,7 @@
namespace JSONRPC
{
const char* const JSONRPC_SERVICE_ID = "http://www.xbmc.org/jsonrpc/ServiceDescription.json";
- const char* const JSONRPC_SERVICE_VERSION = "6.0.3";
+ const char* const JSONRPC_SERVICE_VERSION = "6.1.0";
const char* const JSONRPC_SERVICE_DESCRIPTION = "JSON-RPC API of XBMC";
const char* const JSONRPC_SERVICE_TYPES[] = {
@@ -1794,7 +1794,8 @@ namespace JSONRPC
"{ \"name\": \"directory\", \"type\": \"string\", \"required\": true },"
"{ \"name\": \"media\", \"$ref\": \"Files.Media\", \"default\": \"files\" },"
"{ \"name\": \"properties\", \"$ref\": \"List.Fields.Files\" },"
- "{ \"name\": \"sort\", \"$ref\": \"List.Sort\" }"
+ "{ \"name\": \"sort\", \"$ref\": \"List.Sort\" },"
+ "{ \"name\": \"limits\", \"$ref\": \"List.Limits\", \"description\": \"Limits are applied after getting the directory content thus retrieval is not faster when they are applied.\" }"
"],"
"\"returns\": {"
"\"type\": \"object\","
3  xbmc/interfaces/json-rpc/methods.json
View
@@ -544,7 +544,8 @@
{ "name": "directory", "type": "string", "required": true },
{ "name": "media", "$ref": "Files.Media", "default": "files" },
{ "name": "properties", "$ref": "List.Fields.Files" },
- { "name": "sort", "$ref": "List.Sort" }
+ { "name": "sort", "$ref": "List.Sort" },
+ { "name": "limits", "$ref": "List.Limits", "description": "Limits are applied after getting the directory content thus retrieval is not faster when they are applied." }
],
"returns": {
"type": "object",
Sascha Montellese

I'll have to revert this part of the change (i.e. saving the extra loops) because it results in "filetype" being returned in unwanted calls like Player.GetItem.

Tolriq

Should not this field be added to definition if it really appears ? Speed on low end device is important and this data is not something without meaning so may be added.

Or i can search a better way but reverting speed gain should check for other solutions.

Sascha Montellese

It's not the code that should dictate how the API looks like, it's the API that should dictate how the code works. With this change "filetype" is added to the result of some methods where it simply doesn't belong (for Player.GetItem the "filetype" property would always be "file" so it doesn't provide any useful information).

Tolriq

So passing the field in parameterObject and check for it or any other way to keep speed should not be envisaged because speed does not matter ?

Please sign in to comment.
Something went wrong with that request. Please try again.