History

Make individual reload buttons reload scripts

David Rowe committed 11 years ago

Commit 67206331 parent 2a005868 files · +53 −30Browse files

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

Unified · Split

libraries/script-engine/src/ScriptCache.cpp+12−3
@@ -16,16 +16,20 @@ · 15 unmodified lines
1616 #include <QNetworkReply>
1717 #include <QObject>
1818
19+#include <assert.h>
1920 #include <NetworkAccessManager.h>
2021 #include <SharedUtil.h>
21−#include "ScriptEngineLogging.h"
22+
2223 #include "ScriptCache.h"
24+#include "ScriptEngineLogging.h"
2325
2426 ScriptCache::ScriptCache(QObject* parent) {
2527 // nothing to do here...
2628 }
2729
28−QString ScriptCache::getScript(const QUrl& url, ScriptUser* scriptUser, bool& isPending) {
30+QString ScriptCache::getScript(const QUrl& url, ScriptUser* scriptUser, bool& isPending, bool redownload) {
31+ assert(!_scriptCache.contains(url) || !redownload);
32+
2933 QString scriptContents;
3034 if (_scriptCache.contains(url)) {
3135 qCDebug(scriptengine) << "Found script in cache:" << url.toString();
@@ -43,8 +47,13 @@ QString ScriptCache::getScript(const QUrl& url, ScriptUser* scriptUser, bool& is · 11 unmodified lines
4347 QNetworkAccessManager& networkAccessManager = NetworkAccessManager::getInstance();
4448 QNetworkRequest networkRequest = QNetworkRequest(url);
4549 networkRequest.setHeader(QNetworkRequest::UserAgentHeader, HIGH_FIDELITY_USER_AGENT);
50+ if (redownload) {
51+ networkRequest.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferNetwork);
52+ qCDebug(scriptengine) << "Redownloading script at:" << url.toString();
53+ } else {
54+ qCDebug(scriptengine) << "Downloading script at:" << url.toString();
55+ }
4656
47− qCDebug(scriptengine) << "Downloading script at:" << url.toString();
4857 QNetworkReply* reply = networkAccessManager.get(networkRequest);
4958 connect(reply, &QNetworkReply::finished, this, &ScriptCache::scriptDownloaded);
5059 }