History

Save clip to asset

EdgarPironti committed 10 years ago

Commit 1b18d361 parent a7d5ca92 files · +65 −0Browse files

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

Unified · Split

libraries/script-engine/src/RecordingScriptingInterface.cpp+56−0
@@ -18,10 +18,15 @@ · 17 unmodified lines
1818 #include <recording/Frame.h>
1919 #include <recording/ClipCache.h>
2020
21+#include <QtCore/QUrl>
22+#include <QtWidgets/QFileDialog>
23+
2124 #include "ScriptEngineLogging.h"
2225
2326 using namespace recording;
2427
28+static const QString HFR_EXTENSION = ".hfr";
29+const QString URL_SCHEME_ATP = "atp";
2530
2631 RecordingScriptingInterface::RecordingScriptingInterface() {
2732 _player = DependencyManager::get<Deck>();
@@ -171,6 +176,57 @@ void RecordingScriptingInterface::saveRecording(const QString& filename) { · 143 unmodified lines
171176 recording::Clip::toFile(filename, _lastClip);
172177 }
173178
179+bool RecordingScriptingInterface::saveRecordingToAsset(QScriptValue getClipAtpUrl) {
180+
181+ if (!getClipAtpUrl.isFunction())
182+ return false;
183+
184+ if (QThread::currentThread() != thread()) {
185+ QMetaObject::invokeMethod(this, "saveRecordingToAsset", Qt::BlockingQueuedConnection,
186+ Q_ARG(QScriptValue, getClipAtpUrl));
187+ return false;
188+ }
189+
190+ if (!_lastClip) {
191+ qWarning() << "There is no recording to save";
192+ return false;
193+ }
194+
195+ QString filename = "./temp.hfr";
196+ recording::Clip::toFile(filename, _lastClip);
197+
198+ QUrl url{ filename };
199+
200+ if (auto upload = DependencyManager::get<AssetClient>()->createUpload(url.toLocalFile())) { // Here we should use the other implementation of createUpload, but we need the QByteArray of the _lastClip
201+
202+ QObject::connect(upload, &AssetUpload::finished, this, [=](AssetUpload* upload, const QString& hash) mutable {
203+ auto filename = QFileInfo(upload->getFilename()).fileName();
204+ QString clip_atp_url = "";
205+
206+ if (upload->getError() == AssetUpload::NoError) {
207+
208+ clip_atp_url = QString("%1:%2.%3").arg(URL_SCHEME_ATP, hash, upload->getExtension());
209+ upload->deleteLater();
210+ } else {
211+ AssetUploadDialogFactory::getInstance().handleUploadFinished(upload, hash);
212+ }
213+
214+ QScriptValueList args;
215+ args << clip_atp_url;
216+ getClipAtpUrl.call(QScriptValue(), args);
217+ });
218+
219+ // start the upload now
220+ upload->start();
221+ return true;
222+
223+ }
224+
225+ return false;
226+
227+}
228+
229+
174230 void RecordingScriptingInterface::loadLastRecording() {
175231 if (QThread::currentThread() != thread()) {
176232 QMetaObject::invokeMethod(this, "loadLastRecording", Qt::BlockingQueuedConnection);