History

normalize how ScriptCache::getScript() works relative to ResourceManager

Brad Hefta-Gaub committed 11 years ago

Commit 8395fb61 parent f85cb2c5 files · +28 −47Browse files

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

Unified · Split

libraries/script-engine/src/ScriptEngine.cpp+3−35
@@ -275,8 +275,6 @@ bool ScriptEngine::setScriptContents(const QString& scriptContents, const QStrin · 274 unmodified lines
275 275
276// FIXME - remove the file/url scheme code here and let the script cache handle things276// FIXME - remove the file/url scheme code here and let the script cache handle things
277void ScriptEngine::loadURL(const QUrl& scriptURL, bool reload) {277void ScriptEngine::loadURL(const QUrl& scriptURL, bool reload) {
278 qDebug() << "ScriptEngine::loadURL(" << scriptURL << ", " << reload << ");";
279
280 if (_isRunning) {278 if (_isRunning) {
281 return;279 return;
282 }280 }
@@ -286,39 +284,9 @@ void ScriptEngine::loadURL(const QUrl& scriptURL, bool reload) { · 3 unmodified lines
286 284
287 QUrl url(scriptURL);285 QUrl url(scriptURL);
288 286
289 // if the scheme length is one or lower, maybe they typed in a file, let's try287 bool isPending;
290 const int WINDOWS_DRIVE_LETTER_SIZE = 1;288 auto scriptCache = DependencyManager::get<ScriptCache>();
291 if (url.scheme().size() <= WINDOWS_DRIVE_LETTER_SIZE) {289 scriptCache->getScript(url, this, isPending, reload);
292 url = QUrl::fromLocalFile(_fileNameString);
293 }
294
295 // ok, let's see if it's valid... and if so, load it
296 if (url.isValid()) {
297 if (url.scheme() == "file") {
298 _fileNameString = url.toLocalFile();
299 QFile scriptFile(_fileNameString);
300 if (scriptFile.open(QFile::ReadOnly | QFile::Text)) {
301 qCDebug(scriptengine) << "ScriptEngine loading file:" << _fileNameString;
302 QTextStream in(&scriptFile);
303 _scriptContents = in.readAll();
304 if (_wantSignals) {
305 emit scriptLoaded(_fileNameString);
306 }
307 } else {
308 qCDebug(scriptengine) << "ERROR Loading file:" << _fileNameString << "line:" << __LINE__;
309 if (_wantSignals) {
310 emit errorLoadingScript(_fileNameString);
311 }
312 }
313 } else {
314 bool isPending;
315 auto scriptCache = DependencyManager::get<ScriptCache>();
316 qDebug() << "calling scriptCache->getScript(" << url << ", " << reload << ");";
317 scriptCache->getScript(url, this, isPending, reload);
318 qDebug() << " scriptCache->getScript(" << url << ", " << reload << ") ... isPending:" << isPending;
319
320 }
321 }
322}290}
323 291
324void ScriptEngine::scriptContentsAvailable(const QUrl& url, const QString& scriptContents) {292void ScriptEngine::scriptContentsAvailable(const QUrl& url, const QString& scriptContents) {