Showing the changes to libraries/script-engine/src/ScriptEngines.cpp (1 of 4 files). Show all
Unified · Split
| @@ -44,16 +44,21 @@ ScriptEngines::ScriptEngines() · 43 unmodified lines | ||
| 44 | 44 | |
| 45 | 45 | QUrl normalizeScriptURL(const QUrl& rawScriptURL) { |
| 46 | 46 | if (rawScriptURL.scheme() == "file") { |
| 47 | + qDebug() << "+"; | |
| 48 | + qDebug() << "+"; | |
| 49 | + qDebug() << "+"; | |
| 50 | + | |
| 47 | 51 | QUrl fullNormal = rawScriptURL; |
| 48 | 52 | QUrl defaultScriptLoc = defaultScriptsLocation(); |
| 49 | 53 | |
| 50 | − #ifdef Q_OS_LINUX | |
| 51 | − #else | |
| 52 | − // Force lowercase on file scripts because of drive letter weirdness. | |
| 53 | − if (rawScriptURL.isLocalFile()) { | |
| 54 | − fullNormal.setPath(fullNormal.path().toLower()); | |
| 55 | − } | |
| 56 | − #endif | |
| 54 | + // #ifdef Q_OS_LINUX | |
| 55 | + // #else | |
| 56 | + // // Force lowercase on file scripts because of drive letter weirdness. | |
| 57 | + // if (rawScriptURL.isLocalFile()) { | |
| 58 | + // fullNormal.setPath(fullNormal.path()); // .toLower()); | |
| 59 | + // } | |
| 60 | + // #endif | |
| 61 | + | |
| 57 | 62 | // if this url is something "beneath" the default script url, replace the local path with ~ |
| 58 | 63 | if (fullNormal.scheme() == defaultScriptLoc.scheme() && |
| 59 | 64 | fullNormal.host() == defaultScriptLoc.host() && |
| @@ -69,21 +74,37 @@ QUrl normalizeScriptURL(const QUrl& rawScriptURL) { · 9 unmodified lines | ||
| 69 | 74 | } |
| 70 | 75 | } |
| 71 | 76 | |
| 72 | −QUrl expandScriptUrl(const QUrl& normalizedScriptURL) { | |
| 77 | +QUrl expandScriptUrl(const QUrl& rawScriptURL) { | |
| 78 | + QUrl normalizedScriptURL = normalizeScriptURL(rawScriptURL); | |
| 79 | + | |
| 80 | + qDebug() << "expandScriptUrl in = " << rawScriptURL; | |
| 81 | + | |
| 73 | 82 | if (normalizedScriptURL.scheme() == "http" || |
| 74 | 83 | normalizedScriptURL.scheme() == "https" || |
| 75 | 84 | normalizedScriptURL.scheme() == "atp") { |
| 85 | + | |
| 86 | + qDebug() << "expandScriptUrl out(net) = " << normalizedScriptURL; | |
| 87 | + | |
| 76 | 88 | return normalizedScriptURL; |
| 77 | 89 | } else if (normalizedScriptURL.scheme() == "file") { |
| 78 | 90 | if (normalizedScriptURL.path().startsWith("/~/")) { |
| 79 | 91 | QUrl url = normalizedScriptURL; |
| 92 | + qDebug() << "in expand, normalizedScriptURL = " << normalizedScriptURL; | |
| 80 | 93 | QStringList splitPath = url.path().split("/"); |
| 81 | 94 | QUrl defaultScriptsLoc = defaultScriptsLocation(); |
| 82 | 95 | url.setPath(defaultScriptsLoc.path() + "/" + splitPath.mid(2).join("/")); // 2 to skip the slashes in /~/ |
| 96 | + | |
| 97 | + qDebug() << "expandScriptUrl out(file 0) = " << url; | |
| 98 | + | |
| 83 | 99 | return url; |
| 84 | 100 | } |
| 101 | + | |
| 102 | + qDebug() << "expandScriptUrl out(file 1) = " << normalizedScriptURL; | |
| 103 | + | |
| 85 | 104 | return normalizedScriptURL; |
| 86 | 105 | } else { |
| 106 | + qDebug() << "expandScriptUrl out(bad scheme) = " << normalizedScriptURL; | |
| 107 | + | |
| 87 | 108 | return QUrl(""); |
| 88 | 109 | } |
| 89 | 110 | } |
| @@ -230,7 +251,7 @@ QVariantList ScriptEngines::getRunning() { · 140 unmodified lines | ||
| 230 | 251 | } |
| 231 | 252 | QVariantMap resultNode; |
| 232 | 253 | resultNode.insert("name", runningScriptURL.fileName()); |
| 233 | − QUrl displayURL = expandScriptUrl(QUrl(runningScriptURL)); | |
| 254 | + QUrl displayURL = expandScriptUrl(runningScriptURL); | |
| 234 | 255 | QString displayURLString; |
| 235 | 256 | if (displayURL.isLocalFile()) { |
| 236 | 257 | displayURLString = displayURL.toLocalFile(); |
| @@ -268,7 +289,7 @@ void ScriptEngines::loadScripts() { · 31 unmodified lines | ||
| 268 | 289 | loadDefaultScripts(); |
| 269 | 290 | _firstRun.set(false); |
| 270 | 291 | return; |
| 271 | − } | |
| 292 | + } | |
| 272 | 293 | |
| 273 | 294 | // loads all saved scripts |
| 274 | 295 | Settings settings; |
| @@ -310,7 +331,12 @@ void ScriptEngines::saveScripts() { · 35 unmodified lines | ||
| 310 | 331 | |
| 311 | 332 | QStringList ScriptEngines::getRunningScripts() { |
| 312 | 333 | QReadLocker lock(&_scriptEnginesHashLock); |
| 313 | − return _scriptEnginesHash.keys(); | |
| 334 | + QList<QUrl> urls = _scriptEnginesHash.keys(); | |
| 335 | + QStringList result; | |
| 336 | + for (auto url : urls) { | |
| 337 | + result.append(url.toString()); | |
| 338 | + } | |
| 339 | + return result; | |
| 314 | 340 | } |
| 315 | 341 | |
| 316 | 342 | void ScriptEngines::stopAllScripts(bool restart) { |
| @@ -318,7 +344,7 @@ void ScriptEngines::stopAllScripts(bool restart) { · 1 unmodified line | ||
| 318 | 344 | if (restart) { |
| 319 | 345 | // Delete all running scripts from cache so that they are re-downloaded when they are restarted |
| 320 | 346 | auto scriptCache = DependencyManager::get<ScriptCache>(); |
| 321 | − for (QHash<QString, ScriptEngine*>::const_iterator it = _scriptEnginesHash.constBegin(); | |
| 347 | + for (QHash<QUrl, ScriptEngine*>::const_iterator it = _scriptEnginesHash.constBegin(); | |
| 322 | 348 | it != _scriptEnginesHash.constEnd(); it++) { |
| 323 | 349 | if (!it.value()->isFinished()) { |
| 324 | 350 | scriptCache->deleteScript(it.key()); |
| @@ -327,7 +353,7 @@ void ScriptEngines::stopAllScripts(bool restart) { · 2 unmodified lines | ||
| 327 | 353 | } |
| 328 | 354 | |
| 329 | 355 | // Stop and possibly restart all currently running scripts |
| 330 | − for (QHash<QString, ScriptEngine*>::const_iterator it = _scriptEnginesHash.constBegin(); | |
| 356 | + for (QHash<QUrl, ScriptEngine*>::const_iterator it = _scriptEnginesHash.constBegin(); | |
| 331 | 357 | it != _scriptEnginesHash.constEnd(); it++) { |
| 332 | 358 | if (it.value()->isFinished()) { |
| 333 | 359 | continue; |
| @@ -350,21 +376,20 @@ bool ScriptEngines::stopScript(const QString& rawScriptURL, bool restart) { · 16 unmodified lines | ||
| 350 | 376 | if (!scriptURL.isValid()) { |
| 351 | 377 | scriptURL = normalizeScriptURL(QUrl::fromLocalFile(rawScriptURL)); |
| 352 | 378 | } |
| 353 | − const QString scriptURLString = scriptURL.toString(); | |
| 354 | 379 | |
| 355 | 380 | QReadLocker lock(&_scriptEnginesHashLock); |
| 356 | − if (_scriptEnginesHash.contains(scriptURLString)) { | |
| 357 | − ScriptEngine* scriptEngine = _scriptEnginesHash[scriptURLString]; | |
| 381 | + if (_scriptEnginesHash.contains(scriptURL)) { | |
| 382 | + ScriptEngine* scriptEngine = _scriptEnginesHash[scriptURL]; | |
| 358 | 383 | if (restart) { |
| 359 | 384 | auto scriptCache = DependencyManager::get<ScriptCache>(); |
| 360 | − scriptCache->deleteScript(QUrl(scriptURLString)); | |
| 385 | + scriptCache->deleteScript(scriptURL); | |
| 361 | 386 | connect(scriptEngine, &ScriptEngine::finished, this, [this](QString scriptName, ScriptEngine* engine) { |
| 362 | 387 | reloadScript(scriptName); |
| 363 | 388 | }); |
| 364 | 389 | } |
| 365 | 390 | scriptEngine->stop(); |
| 366 | 391 | stoppedScript = true; |
| 367 | − qCDebug(scriptengine) << "stopping script..." << scriptURLString; | |
| 392 | + qCDebug(scriptengine) << "stopping script..." << scriptURL; | |
| 368 | 393 | } |
| 369 | 394 | } |
| 370 | 395 | return stoppedScript; |
| @@ -379,7 +404,7 @@ void ScriptEngines::setScriptsLocation(const QString& scriptsLocation) { · 8 unmodified lines | ||
| 379 | 404 | _scriptsModel.updateScriptsLocation(scriptsLocation); |
| 380 | 405 | } |
| 381 | 406 | |
| 382 | −void ScriptEngines::reloadAllScripts() { | |
| 407 | +void ScriptEngines::reloadAllScripts() { | |
| 383 | 408 | DependencyManager::get<ScriptCache>()->clearCache(); |
| 384 | 409 | emit scriptsReloading(); |
| 385 | 410 | stopAllScripts(true); |
| @@ -409,7 +434,7 @@ ScriptEngine* ScriptEngines::loadScript(const QUrl& scriptFilename, bool isUserL · 23 unmodified lines | ||
| 409 | 434 | scriptUrl = normalizeScriptURL(scriptFilename); |
| 410 | 435 | } |
| 411 | 436 | |
| 412 | − auto scriptEngine = getScriptEngine(scriptUrl.toString()); | |
| 437 | + auto scriptEngine = getScriptEngine(scriptUrl); | |
| 413 | 438 | if (scriptEngine) { |
| 414 | 439 | return scriptEngine; |
| 415 | 440 | } |
| @@ -435,12 +460,12 @@ ScriptEngine* ScriptEngines::loadScript(const QUrl& scriptFilename, bool isUserL · 19 unmodified lines | ||
| 435 | 460 | return scriptEngine; |
| 436 | 461 | } |
| 437 | 462 | |
| 438 | −ScriptEngine* ScriptEngines::getScriptEngine(const QString& rawScriptURL) { | |
| 463 | +ScriptEngine* ScriptEngines::getScriptEngine(const QUrl& rawScriptURL) { | |
| 439 | 464 | ScriptEngine* result = nullptr; |
| 440 | 465 | { |
| 441 | 466 | QReadLocker lock(&_scriptEnginesHashLock); |
| 442 | − const QString scriptURLString = normalizeScriptURL(QUrl(rawScriptURL)).toString(); | |
| 443 | − auto it = _scriptEnginesHash.find(scriptURLString); | |
| 467 | + const QUrl scriptURL = normalizeScriptURL(rawScriptURL); | |
| 468 | + auto it = _scriptEnginesHash.find(scriptURL); | |
| 444 | 469 | if (it != _scriptEnginesHash.end()) { |
| 445 | 470 | result = it.value(); |
| 446 | 471 | } |
| @@ -459,8 +484,7 @@ void ScriptEngines::onScriptEngineLoaded(const QString& rawScriptURL) { · 12 unmodified lines | ||
| 459 | 484 | QWriteLocker lock(&_scriptEnginesHashLock); |
| 460 | 485 | QUrl url = QUrl(rawScriptURL); |
| 461 | 486 | QUrl normalized = normalizeScriptURL(url); |
| 462 | − const QString scriptURLString = normalized.toString(); | |
| 463 | − _scriptEnginesHash.insertMulti(scriptURLString, scriptEngine); | |
| 487 | + _scriptEnginesHash.insertMulti(normalized, scriptEngine); | |
| 464 | 488 | } |
| 465 | 489 | emit scriptCountChanged(); |
| 466 | 490 | } |
| @@ -486,8 +510,8 @@ void ScriptEngines::onScriptFinished(const QString& rawScriptURL, ScriptEngine* · 19 unmodified lines | ||
| 486 | 510 | bool removed = false; |
| 487 | 511 | { |
| 488 | 512 | QWriteLocker lock(&_scriptEnginesHashLock); |
| 489 | − const QString scriptURLString = normalizeScriptURL(QUrl(rawScriptURL)).toString(); | |
| 490 | − for (auto it = _scriptEnginesHash.find(scriptURLString); it != _scriptEnginesHash.end(); ++it) { | |
| 513 | + const QUrl scriptURL = normalizeScriptURL(QUrl(rawScriptURL)); | |
| 514 | + for (auto it = _scriptEnginesHash.find(scriptURL); it != _scriptEnginesHash.end(); ++it) { | |
| 491 | 515 | if (it.value() == engine) { |
| 492 | 516 | _scriptEnginesHash.erase(it); |
| 493 | 517 | removed = true; |