History

rewrite a bunch of path/url mangling code

Seth Alves committed 10 years ago

Commit 26e01bb1 parent bd5757d6 files · +104 −79Browse files

Showing the changes to libraries/script-engine/src/ScriptsModel.cpp (1 of 6 files). Show all

Unified · Split

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