History

Handle Clara marketplace downloads

David Rowe committed 9 years ago

Commit 5fbdd641 parent 0ef972c8 files · +111 −13Browse files

Showing the changes to interface/src/Application.cpp (1 of 8 files). Show all

Unified · Split

interface/src/Application.cpp+46−8
@@ -42,6 +42,7 @@ · 41 unmodified lines
42#include <QtMultimedia/QMediaPlayer>42#include <QtMultimedia/QMediaPlayer>
43 43
44#include <QProcessEnvironment>44#include <QProcessEnvironment>
45#include <QTemporaryDir>
45 46
46#include <gl/QOpenGLContextWrapper.h>47#include <gl/QOpenGLContextWrapper.h>
47 48
@@ -1859,9 +1860,9 @@ void Application::initializeUi() { · 1811 unmodified lines
1859 rootContext->setContextProperty("AudioStats", DependencyManager::get<AudioClient>()->getStats().data());1860 rootContext->setContextProperty("AudioStats", DependencyManager::get<AudioClient>()->getStats().data());
1860 rootContext->setContextProperty("Controller", DependencyManager::get<controller::ScriptingInterface>().data());1861 rootContext->setContextProperty("Controller", DependencyManager::get<controller::ScriptingInterface>().data());
1861 rootContext->setContextProperty("Entities", DependencyManager::get<EntityScriptingInterface>().data());1862 rootContext->setContextProperty("Entities", DependencyManager::get<EntityScriptingInterface>().data());
1862 FileScriptingInterface* fileDownload = new FileScriptingInterface(engine);1863 _fileDownload = new FileScriptingInterface(engine);
1863 rootContext->setContextProperty("File", fileDownload);1864 rootContext->setContextProperty("File", _fileDownload);
1864 connect(fileDownload, &FileScriptingInterface::unzipSuccess, this, &Application::handleUnzip);1865 connect(_fileDownload, &FileScriptingInterface::unzipSuccess, this, &Application::handleUnzip);
1865 rootContext->setContextProperty("MyAvatar", getMyAvatar().get());1866 rootContext->setContextProperty("MyAvatar", getMyAvatar().get());
1866 rootContext->setContextProperty("Messages", DependencyManager::get<MessagesClient>().data());1867 rootContext->setContextProperty("Messages", DependencyManager::get<MessagesClient>().data());
1867 rootContext->setContextProperty("Recording", DependencyManager::get<RecordingScriptingInterface>().data());1868 rootContext->setContextProperty("Recording", DependencyManager::get<RecordingScriptingInterface>().data());
@@ -5554,17 +5555,54 @@ void Application::showAssetServerWidget(QString filePath) { · 3686 unmodified lines
5554 startUpload(nullptr, nullptr);5555 startUpload(nullptr, nullptr);
5555}5556}
5556 5557
5557void Application::addAssetToWorldInitiate() {5558void Application::addAssetToWorldFromURL(QString url) {
5558 qCDebug(interfaceapp) << "Start downloading asset file";5559 qInfo(interfaceapp) << "Download asset and add to world from" << url;
5560
5561 QUrl urlURL = QUrl(url);
5562 auto request = ResourceManager::createResourceRequest(nullptr, urlURL);
5563 connect(request, &ResourceRequest::finished, this, &Application::addAssetToWorldFromURLRequestFinished);
5564 request->send();
5559 5565
5560 if (!_addAssetToWorldMessageBox) {5566 if (!_addAssetToWorldMessageBox) {
5561 _addAssetToWorldMessageBox = DependencyManager::get<OffscreenUi>()->createMessageBox(OffscreenUi::ICON_INFORMATION, 5567 _addAssetToWorldMessageBox = DependencyManager::get<OffscreenUi>()->createMessageBox(OffscreenUi::ICON_INFORMATION,
5562 "Downloading Asset", "Downloading asset file.", QMessageBox::Cancel, QMessageBox::NoButton);5568 "Downloading Asset", "Downloading asset file " + url.section("filename=", 1, 1),
5569 QMessageBox::Cancel, QMessageBox::NoButton);
5563 }5570 }
5564
5565 connect(_addAssetToWorldMessageBox, SIGNAL(destroyed()), this, SLOT(onAssetToWorldMessageBoxClosed()));5571 connect(_addAssetToWorldMessageBox, SIGNAL(destroyed()), this, SLOT(onAssetToWorldMessageBoxClosed()));
5566}5572}
5567 5573
5574void Application::addAssetToWorldFromURLRequestFinished() {
5575 auto request = qobject_cast<ResourceRequest*>(sender());
5576 auto url = request->getUrl().toString();
5577 auto result = request->getResult();
5578
5579 if (result == ResourceRequest::Success) {
5580 qInfo(interfaceapp) << "Downloaded asset from" << url;
5581
5582 QTemporaryDir temporaryDir;
5583 temporaryDir.setAutoRemove(false);
5584 QString temporaryDirPath = temporaryDir.path();
5585 QString filename = url.section("filename=", 1, 1);
5586 QString downloadPath = temporaryDirPath + "/" + filename;
5587 qInfo() << "Download path:" << downloadPath;
5588
5589 QFile tempFile(downloadPath);
5590 if (tempFile.open(QIODevice::WriteOnly)) {
5591 tempFile.write(request->getData());
5592 qApp->getFileDownloadInterface()->runUnzip(downloadPath, url, true);
5593 } else {
5594 QString errorInfo = "Couldn't open temporary file for writing";
5595 qWarning(interfaceapp) << errorInfo;
5596 addAssetToWorldError(errorInfo);
5597 }
5598 } else {
5599 qWarning(interfaceapp) << "Error downloading" << url << ":" << request->getResultString();
5600 addAssetToWorldError("Error downloading " + url.section("filename=", 1, 1) + " : " + request->getResultString());
5601 }
5602
5603 request->deleteLater();
5604}
5605
5568void Application::onAssetToWorldMessageBoxClosed() {5606void Application::onAssetToWorldMessageBoxClosed() {
5569 disconnect(_addAssetToWorldMessageBox);5607 disconnect(_addAssetToWorldMessageBox);
5570 _addAssetToWorldMessageBox = nullptr;5608 _addAssetToWorldMessageBox = nullptr;