Showing the changes to libraries/script-engine/src/ScriptsModel.cpp (1 of 1 file). Show all
Unified · Split
| @@ -156,39 +156,42 @@ void ScriptsModel::reloadDefaultFiles() { · 155 unmodified lines | |||
| 156 | void ScriptsModel::requestDefaultFiles(QString marker) { | 156 | void ScriptsModel::requestDefaultFiles(QString marker) { |
| 157 | QUrl url(defaultScriptsLocation()); | 157 | QUrl url(defaultScriptsLocation()); |
| 158 | 158 | ||
| 159 | if (url.isLocalFile()) { | 159 | // targets that don't have a scripts folder in the appropriate location will have an empty URL here |
| 160 | // if the url indicates a local directory, use QDirIterator | 160 | if (!url.isEmpty()) { |
| 161 | QString localDir = expandScriptUrl(url).toLocalFile(); | 161 | if (url.isLocalFile()) { |
| 162 | int localDirPartCount = localDir.split("/").size(); | 162 | // if the url indicates a local directory, use QDirIterator |
| 163 | if (localDir.endsWith("/")) { | 163 | QString localDir = expandScriptUrl(url).toLocalFile(); |
| 164 | localDirPartCount--; | 164 | int localDirPartCount = localDir.split("/").size(); |
| 165 | } | 165 | if (localDir.endsWith("/")) { |
| 166 | #ifdef Q_OS_WIN | 166 | localDirPartCount--; |
| 167 | localDirPartCount++; // one for the drive letter | 167 | } |
| 168 | #endif | 168 | #ifdef Q_OS_WIN |
| 169 | QDirIterator it(localDir, QStringList() << "*.js", QDir::Files, QDirIterator::Subdirectories); | 169 | localDirPartCount++; // one for the drive letter |
| 170 | while (it.hasNext()) { | 170 | #endif |
| 171 | QUrl jsFullPath = QUrl::fromLocalFile(it.next()); | 171 | QDirIterator it(localDir, QStringList() << "*.js", QDir::Files, QDirIterator::Subdirectories); |
| 172 | QString jsPartialPath = jsFullPath.path().split("/").mid(localDirPartCount).join("/"); | 172 | while (it.hasNext()) { |
| 173 | jsFullPath = normalizeScriptURL(jsFullPath); | 173 | QUrl jsFullPath = QUrl::fromLocalFile(it.next()); |
| 174 | _treeNodes.append(new TreeNodeScript(jsPartialPath, jsFullPath.toString(), SCRIPT_ORIGIN_DEFAULT)); | 174 | QString jsPartialPath = jsFullPath.path().split("/").mid(localDirPartCount).join("/"); |
| 175 | } | 175 | jsFullPath = normalizeScriptURL(jsFullPath); |
| 176 | _loadingScripts = false; | 176 | _treeNodes.append(new TreeNodeScript(jsPartialPath, jsFullPath.toString(), SCRIPT_ORIGIN_DEFAULT)); |
| 177 | } else { | 177 | } |
| 178 | // the url indicates http(s), use QNetworkRequest | 178 | _loadingScripts = false; |
| 179 | QUrlQuery query; | 179 | } else { |
| 180 | query.addQueryItem(PREFIX_PARAMETER_NAME, "."); | 180 | // the url indicates http(s), use QNetworkRequest |
| 181 | if (!marker.isEmpty()) { | 181 | QUrlQuery query; |
| 182 | query.addQueryItem(MARKER_PARAMETER_NAME, marker); | 182 | query.addQueryItem(PREFIX_PARAMETER_NAME, "."); |
| 183 | if (!marker.isEmpty()) { | ||
| 184 | query.addQueryItem(MARKER_PARAMETER_NAME, marker); | ||
| 185 | } | ||
| 186 | url.setQuery(query); | ||
| 187 | |||
| 188 | QNetworkAccessManager& networkAccessManager = NetworkAccessManager::getInstance(); | ||
| 189 | QNetworkRequest request(url); | ||
| 190 | request.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true); | ||
| 191 | request.setHeader(QNetworkRequest::UserAgentHeader, HIGH_FIDELITY_USER_AGENT); | ||
| 192 | QNetworkReply* reply = networkAccessManager.get(request); | ||
| 193 | connect(reply, SIGNAL(finished()), SLOT(downloadFinished())); | ||
| 183 | } | 194 | } |
| 184 | url.setQuery(query); | ||
| 185 | |||
| 186 | QNetworkAccessManager& networkAccessManager = NetworkAccessManager::getInstance(); | ||
| 187 | QNetworkRequest request(url); | ||
| 188 | request.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true); | ||
| 189 | request.setHeader(QNetworkRequest::UserAgentHeader, HIGH_FIDELITY_USER_AGENT); | ||
| 190 | QNetworkReply* reply = networkAccessManager.get(request); | ||
| 191 | connect(reply, SIGNAL(finished()), SLOT(downloadFinished())); | ||
| 192 | } | 195 | } |
| 193 | } | 196 | } |
| 194 | 197 | ||