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