Skip to content
This repository
Browse code

Merge pull request #2871 from Tolriq/faster_fix_filetype

jsonrpc: faster and better way to fix "filetype" property than e0ec520
  • Loading branch information...
commit 0d317329ba1898ed6a7d2cea5343632e621e0b2c 2 parents 6763ab9 + cf8a71b
Sascha Montellese authored June 13, 2013
8  xbmc/interfaces/json-rpc/FileItemHandler.cpp
@@ -307,6 +307,14 @@ void CFileItemHandler::HandleFileItem(const char *ID, bool allowFile, const char
307 307
 
308 308
         if (!object.isMember("type"))
309 309
           object["type"] = "unknown";
  310
+
  311
+        if (fields.find("filetype") != fields.end())
  312
+        {
  313
+          if (item->m_bIsFolder)
  314
+            object["filetype"] = "directory";
  315
+          else 
  316
+            object["filetype"] = "file";
  317
+        }
310 318
       }
311 319
     }
312 320
 
20  xbmc/interfaces/json-rpc/FileOperations.cpp
@@ -132,8 +132,8 @@ JSONRPC_STATUS CFileOperations::GetDirectory(const CStdString &method, ITranspor
132 132
     }
133 133
 
134 134
     // Check if the "properties" list exists
135  
-    // and make sure it contains the "file"
136  
-    // field
  135
+    // and make sure it contains the "file" and "filetype"
  136
+    // fields
137 137
     CVariant param = parameterObject;
138 138
     if (!param.isMember("properties"))
139 139
       param["properties"] = CVariant(CVariant::VariantTypeArray);
@@ -150,22 +150,9 @@ JSONRPC_STATUS CFileOperations::GetDirectory(const CStdString &method, ITranspor
150 150
 
151 151
     if (!hasFileField)
152 152
       param["properties"].append("file");
  153
+    param["properties"].append("filetype");
153 154
 
154 155
     HandleFileItemList("id", true, "files", filteredFiles, param, result);
155  
-    for (CVariant::iterator_array item = result["files"].begin_array(); item != result["files"].end_array(); ++item)
156  
-    {
157  
-      if (!item->isMember("file"))
158  
-        continue;
159  
-
160  
-      CFileItemPtr pItem = filteredFiles.Get((*item)["file"].asString());
161  
-      if (pItem == NULL)
162  
-        continue;
163  
-
164  
-      if (pItem->m_bIsFolder)
165  
-        (*item)["filetype"] = "directory";
166  
-      else
167  
-        (*item)["filetype"] = "file";
168  
-    }
169 156
 
170 157
     return OK;
171 158
   }
@@ -212,6 +199,7 @@ JSONRPC_STATUS CFileOperations::GetFileDetails(const CStdString &method, ITransp
212 199
 
213 200
   if (!hasFileField)
214 201
     param["properties"].append("file");
  202
+  param["properties"].append("filetype");
215 203
 
216 204
   HandleFileItem("id", true, "filedetails", item, parameterObject, param["properties"], result, false);
217 205
   return OK;

0 notes on commit 0d31732

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