Showing the changes to libraries/script-engine/src/RecordingScriptingInterface.cpp (1 of 260 files). Show all
Unified · Split
| @@ -11,7 +11,6 @@ · 10 unmodified lines | ||
| 11 | 11 | #include <QStandardPaths> |
| 12 | 12 | #include <QtCore/QThread> |
| 13 | 13 | #include <QtCore/QUrl> |
| 14 | −#include <QtScript/QScriptValue> | |
| 15 | 14 | #include <QtWidgets/QFileDialog> |
| 16 | 15 | |
| 17 | 16 | #include <shared/QtHelpers.h> |
| @@ -27,7 +26,10 @@ · 9 unmodified lines | ||
| 27 | 26 | #include <recording/Frame.h> |
| 28 | 27 | #include <recording/ClipCache.h> |
| 29 | 28 | |
| 29 | +#include "ScriptEngine.h" | |
| 30 | 30 | #include "ScriptEngineLogging.h" |
| 31 | +#include "ScriptManager.h" | |
| 32 | +#include "ScriptValue.h" | |
| 31 | 33 | |
| 32 | 34 | using namespace recording; |
| 33 | 35 | |
| @@ -54,18 +56,19 @@ float RecordingScriptingInterface::playerLength() const { · 20 unmodified lines | ||
| 54 | 56 | return _player->length(); |
| 55 | 57 | } |
| 56 | 58 | |
| 57 | −void RecordingScriptingInterface::playClip(NetworkClipLoaderPointer clipLoader, const QString& url, QScriptValue callback) { | |
| 59 | +void RecordingScriptingInterface::playClip(NetworkClipLoaderPointer clipLoader, const QString& url, ScriptValuePointer callback) { | |
| 58 | 60 | _player->queueClip(clipLoader->getClip()); |
| 59 | 61 | |
| 60 | − if (callback.isFunction()) { | |
| 61 | − QScriptValueList args { true, url }; | |
| 62 | − callback.call(QScriptValue(), args); | |
| 62 | + if (callback->isFunction()) { | |
| 63 | + auto engine = callback->engine(); | |
| 64 | + ScriptValueList args{ engine->newValue(true), engine->newValue(url) }; | |
| 65 | + callback->call(ScriptValuePointer(), args); | |
| 63 | 66 | } |
| 64 | 67 | } |
| 65 | 68 | |
| 66 | −void RecordingScriptingInterface::loadRecording(const QString& url, QScriptValue callback) { | |
| 69 | +void RecordingScriptingInterface::loadRecording(const QString& url, ScriptValuePointer callback) { | |
| 67 | 70 | if (QThread::currentThread() != thread()) { |
| 68 | − BLOCKING_INVOKE_METHOD(this, "loadRecording", Q_ARG(const QString&, url), Q_ARG(QScriptValue, callback)); | |
| 71 | + BLOCKING_INVOKE_METHOD(this, "loadRecording", Q_ARG(const QString&, url), Q_ARG(ScriptValuePointer, callback)); | |
| 69 | 72 | return; |
| 70 | 73 | } |
| 71 | 74 | |
| @@ -82,8 +85,14 @@ void RecordingScriptingInterface::loadRecording(const QString& url, QScriptValue · 10 unmodified lines | ||
| 82 | 85 | |
| 83 | 86 | auto weakClipLoader = clipLoader.toWeakRef(); |
| 84 | 87 | |
| 88 | + auto manager = callback->engine()->manager(); | |
| 89 | + if (!manager) { | |
| 90 | + qWarning() << "This script does not belong to a ScriptManager"; | |
| 91 | + return; | |
| 92 | + } | |
| 93 | + | |
| 85 | 94 | // when clip loaded, call the callback with the URL and success boolean |
| 86 | − connect(clipLoader.data(), &recording::NetworkClipLoader::clipLoaded, callback.engine(), | |
| 95 | + connect(clipLoader.data(), &recording::NetworkClipLoader::clipLoaded, manager, | |
| 87 | 96 | [this, weakClipLoader, url, callback]() mutable { |
| 88 | 97 | |
| 89 | 98 | if (auto clipLoader = weakClipLoader.toStrongRef()) { |
| @@ -97,12 +106,14 @@ void RecordingScriptingInterface::loadRecording(const QString& url, QScriptValue · 7 unmodified lines | ||
| 97 | 106 | }); |
| 98 | 107 | |
| 99 | 108 | // when clip load fails, call the callback with the URL and failure boolean |
| 100 | − connect(clipLoader.data(), &recording::NetworkClipLoader::failed, callback.engine(), [this, weakClipLoader, url, callback](QNetworkReply::NetworkError error) mutable { | |
| 109 | + connect(clipLoader.data(), &recording::NetworkClipLoader::failed, manager, | |
| 110 | + [this, weakClipLoader, url, callback](QNetworkReply::NetworkError error) mutable { | |
| 101 | 111 | qCDebug(scriptengine) << "Failed to load recording from\"" << url << '"'; |
| 102 | 112 | |
| 103 | − if (callback.isFunction()) { | |
| 104 | − QScriptValueList args { false, url }; | |
| 105 | − callback.call(QScriptValue(), args); | |
| 113 | + if (callback->isFunction()) { | |
| 114 | + auto engine = callback->engine(); | |
| 115 | + ScriptValueList args{ engine->newValue(false), engine->newValue(url) }; | |
| 116 | + callback->call(ScriptValuePointer(), args); | |
| 106 | 117 | } |
| 107 | 118 | |
| 108 | 119 | if (auto clipLoader = weakClipLoader.toStrongRef()) { |
| @@ -248,8 +259,8 @@ void RecordingScriptingInterface::saveRecording(const QString& filename) { · 139 unmodified lines | ||
| 248 | 259 | recording::Clip::toFile(filename, _lastClip); |
| 249 | 260 | } |
| 250 | 261 | |
| 251 | −bool RecordingScriptingInterface::saveRecordingToAsset(QScriptValue getClipAtpUrl) { | |
| 252 | − if (!getClipAtpUrl.isFunction()) { | |
| 262 | +bool RecordingScriptingInterface::saveRecordingToAsset(ScriptValuePointer getClipAtpUrl) { | |
| 263 | + if (!getClipAtpUrl->isFunction()) { | |
| 253 | 264 | qCWarning(scriptengine) << "The argument is not a function."; |
| 254 | 265 | return false; |
| 255 | 266 | } |
| @@ -258,7 +269,7 @@ bool RecordingScriptingInterface::saveRecordingToAsset(QScriptValue getClipAtpUr · 2 unmodified lines | ||
| 258 | 269 | bool result; |
| 259 | 270 | BLOCKING_INVOKE_METHOD(this, "saveRecordingToAsset", |
| 260 | 271 | Q_RETURN_ARG(bool, result), |
| 261 | − Q_ARG(QScriptValue, getClipAtpUrl)); | |
| 272 | + Q_ARG(ScriptValuePointer, getClipAtpUrl)); | |
| 262 | 273 | return result; |
| 263 | 274 | } |
| 264 | 275 | |
| @@ -267,9 +278,14 @@ bool RecordingScriptingInterface::saveRecordingToAsset(QScriptValue getClipAtpUr · 2 unmodified lines | ||
| 267 | 278 | return false; |
| 268 | 279 | } |
| 269 | 280 | |
| 281 | + auto manager = getClipAtpUrl->engine()->manager(); | |
| 282 | + if (!manager) { | |
| 283 | + qWarning() << "This script does not belong to a ScriptManager"; | |
| 284 | + return false; | |
| 285 | + } | |
| 286 | + | |
| 270 | 287 | if (auto upload = DependencyManager::get<AssetClient>()->createUpload(recording::Clip::toBuffer(_lastClip))) { |
| 271 | − QObject::connect(upload, &AssetUpload::finished, | |
| 272 | − getClipAtpUrl.engine(), [=](AssetUpload* upload, const QString& hash) mutable { | |
| 288 | + QObject::connect(upload, &AssetUpload::finished, manager, [=](AssetUpload* upload, const QString& hash) mutable { | |
| 273 | 289 | QString clip_atp_url = ""; |
| 274 | 290 | |
| 275 | 291 | if (upload->getError() == AssetUpload::NoError) { |
| @@ -280,9 +296,9 @@ bool RecordingScriptingInterface::saveRecordingToAsset(QScriptValue getClipAtpUr · 4 unmodified lines | ||
| 280 | 296 | qCWarning(scriptengine) << "Error during the Asset upload."; |
| 281 | 297 | } |
| 282 | 298 | |
| 283 | − QScriptValueList args; | |
| 284 | − args << clip_atp_url; | |
| 285 | − getClipAtpUrl.call(QScriptValue(), args); | |
| 299 | + ScriptValueList args; | |
| 300 | + args << getClipAtpUrl->engine()->newValue(clip_atp_url); | |
| 301 | + getClipAtpUrl->call(ScriptValuePointer(), args); | |
| 286 | 302 | }); |
| 287 | 303 | upload->start(); |
| 288 | 304 | return true; |