JSONRPC: make default fields "file" and "thumbnail" optional
authormontellese <montellese@xbmc.org>
Wed, 6 Apr 2011 12:28:21 +0000 (14:28 +0200)
committermontellese <montellese@xbmc.org>
Wed, 6 Apr 2011 16:57:46 +0000 (18:57 +0200)
xbmc/interfaces/json-rpc/AudioLibrary.cpp
xbmc/interfaces/json-rpc/FileItemHandler.cpp
xbmc/interfaces/json-rpc/FileOperations.cpp
xbmc/interfaces/json-rpc/ServiceDescription.h

index 684034d..fa2bfe3 100644 (file)
@@ -157,6 +157,7 @@ JSON_STATUS CAudioLibrary::GetGenres(const CStdString &method, ITransportLayer *
   if (!param.isMember("fields"))
     param["fields"] = Value(arrayValue);
   param["fields"].append("genre");
+  param["fields"].append("thumbnail");
 
   CFileItemList items;
   if (musicdatabase.GetGenresNav("", items))
index 7699f22..357ea64 100644 (file)
@@ -83,7 +83,7 @@ void CFileItemHandler::FillDetails(ISerializable* info, CFileItemPtr item, const
       }
     }
 
-    if (serialization.isMember(field))
+    if (serialization.isMember(field) && !result.isMember(field))
       result[field] = serialization[field];
   }
 }
@@ -127,7 +127,20 @@ void CFileItemHandler::HandleFileItemList(const char *ID, bool allowFile, const
 void CFileItemHandler::HandleFileItem(const char *ID, bool allowFile, const char *resultname, CFileItemPtr item, const Json::Value &parameterObject, const Json::Value &validFields, Json::Value &result)
 {
   Value object;
-  if (allowFile)
+  bool hasFileField = false;
+  bool hasThumbnailField = false;
+
+  for (unsigned int i = 0; i < validFields.size(); i++)
+  {
+    CStdString field = validFields[i].asString();
+
+    if (field == "file")
+      hasFileField = true;
+    if (field == "thumbnail")
+      hasThumbnailField = true;
+  }
+
+  if (allowFile && hasFileField)
   {
     if (item->HasVideoInfoTag() && !item->GetVideoInfoTag()->m_strFileNameAndPath.IsEmpty())
       object["file"] = item->GetVideoInfoTag()->m_strFileNameAndPath.c_str();
@@ -148,7 +161,7 @@ void CFileItemHandler::HandleFileItem(const char *ID, bool allowFile, const char
       object[ID] = item->GetVideoInfoTag()->m_iDbId;
   }
 
-  if (!item->GetThumbnailImage().IsEmpty())
+  if (hasThumbnailField && !item->GetThumbnailImage().IsEmpty())
     object["thumbnail"] = item->GetThumbnailImage().c_str();
 
   if (item->HasVideoInfoTag())
index d199bd4..fee46ab 100644 (file)
@@ -106,14 +106,34 @@ JSON_STATUS CFileOperations::GetDirectory(const CStdString &method, ITransportLa
         filteredFiles.Add(items[i]);
     }
 
-    HandleFileItemList(NULL, true, "files", filteredDirectories, parameterObject, result);
+    // Check if the "fields" list exists
+    // and make sure it contains the "file"
+    // field
+    Value param = parameterObject;
+    if (!param.isMember("fields"))
+      param["fields"] = Value(arrayValue);
+
+    bool hasFileField = false;
+    for (unsigned int i = 0; i < param["fields"].size(); i++)
+    {
+      if (param["fields"][i].asString().compare("file") == 0)
+      {
+        hasFileField = true;
+        break;
+      }
+    }
+
+    if (!hasFileField)
+      param["fields"].append("file");
+
+    HandleFileItemList(NULL, true, "files", filteredDirectories, param, result);
     for (unsigned int index = 0; index < result["files"].size(); index++)
     {
       result["files"][index]["filetype"] = "directory";
     }
     int count = result["limits"]["total"].asInt();
 
-    HandleFileItemList(NULL, true, "files", filteredFiles, parameterObject, result);
+    HandleFileItemList(NULL, true, "files", filteredFiles, param, result);
     for (unsigned int index = count; index < result["files"].size(); index++)
     {
       result["files"][index]["filetype"] = "file";
index 221e84c..f299899 100644 (file)
@@ -555,7 +555,8 @@ namespace JSONRPC
                               "\"plotoutline\", \"originaltitle\", \"lastplayed\", \"writer\", \"studio\","
                               "\"mpaa\", \"cast\", \"country\", \"imdbnumber\", \"premiered\", \"productioncode\","
                               "\"runtime\", \"set\", \"showlink\", \"streamDetails\", \"top250\", \"votes\","
-                              "\"writingcredits\", \"firstaired\", \"season\", \"episode\", \"showtitle\" ]"
+                              "\"writingcredits\", \"firstaired\", \"season\", \"episode\", \"showtitle\","
+                              "\"thumbnail\", \"file\" ]"
                 "}"
             "},"
             "{ \"name\": \"limits\", \"$ref\": \"List.Limits\" },"
@@ -726,7 +727,8 @@ namespace JSONRPC
                               "\"plotoutline\", \"originaltitle\", \"lastplayed\", \"writer\", \"studio\","
                               "\"mpaa\", \"cast\", \"country\", \"imdbnumber\", \"premiered\", \"productioncode\","
                               "\"runtime\", \"set\", \"showlink\", \"streamDetails\", \"top250\", \"votes\","
-                              "\"writingcredits\", \"firstaired\", \"season\", \"episode\", \"showtitle\" ]"
+                              "\"writingcredits\", \"firstaired\", \"season\", \"episode\", \"showtitle\","
+                              "\"thumbnail\", \"file\" ]"
                 "}"
             "},"
             "{ \"name\": \"limits\", \"$ref\": \"List.Limits\" },"
@@ -1065,7 +1067,8 @@ namespace JSONRPC
                 "\"items\": { \"type\": \"string\","
                     "\"enum\": [ \"instrument\", \"style\", \"mood\", \"born\", \"formed\","
                                  "\"description\", \"genre\", \"died\", \"disbanded\","
-                                 "\"yearsactive\", \"musicbrainzartistid\", \"fanart\" ]"
+                                 "\"yearsactive\", \"musicbrainzartistid\", \"fanart\","
+                                 "\"thumbnail\" ]"
                 "}"
             "},"
             "{ \"name\": \"limits\", \"$ref\": \"List.Limits\" },"
@@ -1113,7 +1116,7 @@ namespace JSONRPC
                     "\"enum\": [ \"title\", \"description\", \"artist\", \"genre\","
                                  "\"theme\", \"mood\", \"style\", \"type\", \"label\"," 
                                  "\"rating\", \"year\", \"musicbrainzalbumid\","
-                                 "\"musicbrainzalbumartistid\", \"fanart\" ]"
+                                 "\"musicbrainzalbumartistid\", \"fanart\", \"thumbnail\" ]"
                 "}"
             "},"
             "{ \"name\": \"limits\", \"$ref\": \"List.Limits\" },"
@@ -1179,7 +1182,7 @@ namespace JSONRPC
                                 "\"rating\", \"album\", \"track\", \"duration\", \"comment\","
                                 "\"lyrics\", \"musicbrainztrackid\", \"musicbrainzartistid\","
                                 "\"musicbrainzalbumid\", \"musicbrainzalbumartistid\","
-                                "\"playcount\", \"fanart\" ]"
+                                "\"playcount\", \"fanart\", \"thumbnail\", \"file\" ]"
                 "}"
             "},"
             "{ \"name\": \"limits\", \"$ref\": \"List.Limits\" },"
@@ -1194,7 +1197,7 @@ namespace JSONRPC
                         "\"properties\": {"
                             "\"songid\": { \"$ref\": \"Library.Id\", \"required\": true },"
                             "\"label\": { \"type\": \"string\", \"required\": true },"
-                            "\"file\": { \"type\": \"string\", \"required\": true },"
+                            "\"file\": { \"type\": \"string\" },"
                             "\"fanart\": { \"type\": \"string\" },"
                             "\"thumbnail\": { \"type\": \"string\" },"
                             "\"title\": { \"type\": \"string\" },"
@@ -1281,7 +1284,8 @@ namespace JSONRPC
                                 "\"tagline\", \"plot\", \"plotoutline\", \"originaltitle\", \"lastplayed\","
                                 "\"playcount\", \"writer\", \"studio\", \"mpaa\", \"cast\", \"country\","
                                 "\"imdbnumber\", \"premiered\", \"productioncode\", \"runtime\", \"set\","
-                                "\"showlink\", \"streamDetails\", \"top250\", \"votes\", \"writingcredits\", \"fanart\" ]"
+                                "\"showlink\", \"streamDetails\", \"top250\", \"votes\", \"writingcredits\","
+                                "\"fanart\", \"thumbnail\", \"file\" ]"
                 "}"
             "},"
             "{ \"name\": \"limits\", \"$ref\": \"List.Limits\" },"
@@ -1296,7 +1300,7 @@ namespace JSONRPC
                         "\"properties\": {"
                             "\"movieid\": { \"$ref\": \"Library.Id\", \"required\": true },"
                             "\"label\": { \"type\": \"string\", \"required\": true },"
-                            "\"file\": { \"type\": \"string\", \"required\": true },"
+                            "\"file\": { \"type\": \"string\" },"
                             "\"fanart\": { \"type\": \"string\" },"
                             "\"thumbnail\": { \"type\": \"string\" },"
                             "\"title\": { \"type\": \"string\" },"
@@ -1393,7 +1397,8 @@ namespace JSONRPC
                     "\"description\": \"Requesting the cast field will result in increased response times\","
                     "\"enum\": [ \"title\", \"genre\", \"year\", \"rating\", \"plot\","
                                "\"studio\", \"mpaa\", \"cast\", \"playcount\", \"episode\","
-                               "\"imdbnumber\", \"premiered\", \"votes\", \"lastplayed\", \"fanart\" ]"
+                               "\"imdbnumber\", \"premiered\", \"votes\", \"lastplayed\","
+                               "\"fanart\", \"thumbnail\", \"file\" ]"
                 "}"
             "},"
             "{ \"name\": \"limits\", \"$ref\": \"List.Limits\" },"
@@ -1407,7 +1412,7 @@ namespace JSONRPC
                         "\"properties\": {"
                             "\"tvshowid\": { \"$ref\": \"Library.Id\", \"required\": true },"
                             "\"label\": { \"type\": \"string\", \"required\": true },"
-                            "\"file\": { \"type\": \"string\", \"required\": true },"
+                            "\"file\": { \"type\": \"string\" },"
                             "\"fanart\": { \"type\": \"string\" },"
                             "\"thumbnail\": { \"type\": \"string\" },"
                             "\"title\": { \"type\": \"string\" },"
@@ -1454,7 +1459,7 @@ namespace JSONRPC
             "{ \"name\": \"tvshowid\", \"$ref\": \"Library.Id\", \"required\": true },"
             "{ \"name\": \"fields\", \"type\": \"array\", \"id\": \"Library.Fields.Season\", \"uniqueItems\": true,"
                 "\"items\": { \"type\": \"string\","
-                    "\"enum\": [ \"season\", \"showtitle\", \"playcount\", \"episode\", \"fanart\" ]"
+                    "\"enum\": [ \"season\", \"showtitle\", \"playcount\", \"episode\", \"fanart\", \"thumbnail\" ]"
                 "}"
             "},"
             "{ \"name\": \"limits\", \"$ref\": \"List.Limits\" },"
@@ -1493,7 +1498,8 @@ namespace JSONRPC
                     "\"enum\": [ \"title\", \"plot\", \"votes\", \"rating\", \"writingcredits\","
                               "\"firstaired\", \"playcount\", \"runtime\", \"director\","
                               "\"productioncode\", \"season\", \"episode\", \"originaltitle\","
-                              "\"showtitle\", \"cast\", \"streamDetails\", \"lastplayed\", \"fanart\" ]"
+                              "\"showtitle\", \"cast\", \"streamDetails\", \"lastplayed\", \"fanart\","
+                              "\"thumbnail\", \"file\" ]"
                 "}"
             "},"
             "{ \"name\": \"limits\", \"$ref\": \"List.Limits\" },"
@@ -1507,7 +1513,7 @@ namespace JSONRPC
                         "\"properties\": {"
                             "\"episodeid\": { \"$ref\": \"Library.Id\", \"required\": true },"
                             "\"label\": { \"type\": \"string\", \"required\": true },"
-                            "\"file\": { \"type\": \"string\", \"required\": true },"
+                            "\"file\": { \"type\": \"string\" },"
                             "\"fanart\": { \"type\": \"string\" },"
                             "\"thumbnail\": { \"type\": \"string\" },"
                             "\"title\": { \"type\": \"string\" },"
@@ -1561,7 +1567,7 @@ namespace JSONRPC
                     "\"enum\": [ \"title\", \"playcount\", \"runtime\", \"director\","
                                 "\"studio\", \"year\", \"plot\", \"album\", \"artist\","
                                 "\"genre\", \"track\", \"streamDetails\", \"lastplayed\","
-                                "\"fanart\" ]"
+                                "\"fanart\", \"thumbnail\", \"file\" ]"
                 "}"
             "},"
             "{ \"name\": \"limits\", \"$ref\": \"List.Limits\" },"
@@ -1575,7 +1581,7 @@ namespace JSONRPC
                         "\"properties\": {"
                             "\"musicvideoid\": { \"$ref\": \"Library.Id\", \"required\": true },"
                             "\"label\": { \"type\": \"string\", \"required\": true },"
-                            "\"file\": { \"type\": \"string\", \"required\": true },"
+                            "\"file\": { \"type\": \"string\" },"
                             "\"fanart\": { \"type\": \"string\" },"
                             "\"thumbnail\": { \"type\": \"string\" },"
                             "\"title\": { \"type\": \"string\" },"