Showing the changes to libraries/script-engine/src/ScriptsModel.cpp (1 of 6 files). Show all
Unified · Split
| @@ -158,14 +158,21 @@ void ScriptsModel::requestDefaultFiles(QString marker) { · 157 unmodified lines | ||
| 158 | 158 | QUrl url(defaultScriptsLocation()); |
| 159 | 159 | |
| 160 | 160 | if (url.isLocalFile()) { |
| 161 | − QString localDir = url.toLocalFile() + "/scripts"; | |
| 161 | + // if the url indicates a local directory, use QDirIterator | |
| 162 | + // QString localDir = url.toLocalFile() + "/scripts"; | |
| 163 | + QString localDir = expandScriptUrl(url).toLocalFile() + "/scripts"; | |
| 164 | + int localDirPartCount = localDir.split("/").size(); | |
| 162 | 165 | QDirIterator it(localDir, QStringList() << "*.js", QDir::Files, QDirIterator::Subdirectories); |
| 163 | 166 | while (it.hasNext()) { |
| 164 | − QString jsFullPath = normalizeScriptUrl(it.next()); | |
| 165 | − QString jsPartialPath = normalizeScriptUrl(jsFullPath.mid(localDir.length() + 1)); // + 1 to skip a separator | |
| 166 | − _treeNodes.append(new TreeNodeScript(jsPartialPath, jsFullPath, SCRIPT_ORIGIN_DEFAULT)); | |
| 167 | + QUrl jsFullPath = QUrl::fromLocalFile(it.next()); | |
| 168 | + // QString jsPartialPath = jsFullPath.path().mid(localDir.length() + 1); // + 1 to skip a separator | |
| 169 | + QString jsPartialPath = jsFullPath.path().split("/").mid(localDirPartCount).join("/"); | |
| 170 | + jsFullPath = normalizeScriptURL(jsFullPath); | |
| 171 | + _treeNodes.append(new TreeNodeScript(jsPartialPath, jsFullPath.toString(), SCRIPT_ORIGIN_DEFAULT)); | |
| 167 | 172 | } |
| 173 | + _loadingScripts = false; | |
| 168 | 174 | } else { |
| 175 | + // the url indicates http(s), use QNetworkRequest | |
| 169 | 176 | QUrlQuery query; |
| 170 | 177 | query.addQueryItem(PREFIX_PARAMETER_NAME, MODELS_LOCATION); |
| 171 | 178 | if (!marker.isEmpty()) { |
| @@ -227,11 +234,13 @@ bool ScriptsModel::parseXML(QByteArray xmlFile) { · 55 unmodified lines | ||
| 227 | 234 | while (!(xml.tokenType() == QXmlStreamReader::EndElement && xml.name() == CONTAINER_NAME)) { |
| 228 | 235 | if (xml.tokenType() == QXmlStreamReader::StartElement && xml.name() == KEY_NAME) { |
| 229 | 236 | xml.readNext(); |
| 230 | − lastKey = normalizeScriptUrl(xml.text().toString()); | |
| 237 | + lastKey = xml.text().toString(); | |
| 231 | 238 | if (jsRegex.exactMatch(xml.text().toString())) { |
| 232 | − _treeNodes.append(new TreeNodeScript(lastKey.mid(MODELS_LOCATION.length()), | |
| 233 | − defaultScriptsLocation() + "/" + lastKey, | |
| 234 | − SCRIPT_ORIGIN_DEFAULT)); | |
| 239 | + QString localPath = lastKey.split("/").mid(1).join("/"); | |
| 240 | + QUrl fullPath = defaultScriptsLocation(); | |
| 241 | + fullPath.setPath(fullPath.path() + "/" + lastKey); | |
| 242 | + const QString fullPathStr = normalizeScriptURL(fullPath).toString(); | |
| 243 | + _treeNodes.append(new TreeNodeScript(localPath, fullPathStr, SCRIPT_ORIGIN_DEFAULT)); | |
| 235 | 244 | } |
| 236 | 245 | } |
| 237 | 246 | xml.readNext(); |
| @@ -274,9 +283,9 @@ void ScriptsModel::reloadLocalFiles() { · 36 unmodified lines | ||
| 274 | 283 | const QFileInfoList localFiles = _localDirectory.entryInfoList(); |
| 275 | 284 | for (int i = 0; i < localFiles.size(); i++) { |
| 276 | 285 | QFileInfo file = localFiles[i]; |
| 277 | − QString fileName = normalizeScriptUrl(file.fileName()); | |
| 278 | − QString absPath = normalizeScriptUrl(file.absoluteFilePath()); | |
| 279 | − _treeNodes.append(new TreeNodeScript(fileName, absPath, SCRIPT_ORIGIN_LOCAL)); | |
| 286 | + QString fileName = file.fileName(); | |
| 287 | + QUrl absPath = normalizeScriptURL(QUrl::fromLocalFile(file.absoluteFilePath())); | |
| 288 | + _treeNodes.append(new TreeNodeScript(fileName, absPath.toString(), SCRIPT_ORIGIN_LOCAL)); | |
| 280 | 289 | } |
| 281 | 290 | rebuildTree(); |
| 282 | 291 | endResetModel(); |
| @@ -302,7 +311,7 @@ void ScriptsModel::rebuildTree() { · 19 unmodified lines | ||
| 302 | 311 | for (pathIterator = pathList.constBegin(); pathIterator != pathList.constEnd(); ++pathIterator) { |
| 303 | 312 | hash.append(*pathIterator + "/"); |
| 304 | 313 | if (!folders.contains(hash)) { |
| 305 | − folders[hash] = new TreeNodeFolder(normalizeScriptUrl(*pathIterator), parent); | |
| 314 | + folders[hash] = new TreeNodeFolder(*pathIterator, parent); | |
| 306 | 315 | } |
| 307 | 316 | parent = folders[hash]; |
| 308 | 317 | } |