diff --git a/interface/resources/qml/Marketplaces.qml b/interface/resources/qml/Marketplaces.qml index 9780de04f2..fa4811ff5b 100644 --- a/interface/resources/qml/Marketplaces.qml +++ b/interface/resources/qml/Marketplaces.qml @@ -97,6 +97,7 @@ Rectangle { element.unbind("click"); element.bind("click", function(event) { console.log("Initiate Clara.io FBX file download for {uuid}"); + EventBridge.emitWebEvent("CLARA.IO DOWNLOAD"); window.open("https://clara.io/api/scenes/{uuid}/export/fbx?fbxVersion=7.4&fbxEmbedTextures=true¢erScene=true&alignSceneGound=true"); return false; });' @@ -154,6 +155,16 @@ Rectangle { }); } } + + function onWebEventReceived(event) { + if (event === "CLARA.IO DOWNLOAD") { + ApplicationInterface.addAssetToWorldInitiate(); + } + } + + Component.onCompleted: { + eventBridge.webEventReceived.connect(onWebEventReceived); + } } Rectangle { diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index f9c1b7f8d3..aa5b0b9df6 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -5470,13 +5470,41 @@ void Application::showAssetServerWidget(QString filePath) { startUpload(nullptr, nullptr); } +void Application::addAssetToWorldInitiate() { + qCDebug(interfaceapp) << "Start downloading asset file"; + + if (!_addAssetToWorldMessageBox) { + _addAssetToWorldMessageBox = DependencyManager::get()->createMessageBox(OffscreenUi::ICON_INFORMATION, + "Downloading Asset", "Preparing asset for download", QMessageBox::Cancel, QMessageBox::NoButton); + } + + connect(_addAssetToWorldMessageBox, SIGNAL(destroyed()), this, SLOT(onAssetToWorldMessageBoxClosed())); +} + +void Application::onAssetToWorldMessageBoxClosed() { + disconnect(_addAssetToWorldMessageBox); + _addAssetToWorldMessageBox = nullptr; +} + +void Application::addAssetToWorldError(QString errorText) { + _addAssetToWorldMessageBox->setProperty("title", "Error Downloading Asset"); + _addAssetToWorldMessageBox->setProperty("icon", OffscreenUi::ICON_CRITICAL); + _addAssetToWorldMessageBox->setProperty("text", errorText); +} + void Application::addAssetToWorld(QString filePath) { // Automatically upload and add asset to world as an alternative manual process initiated by showAssetServerWidget(). + if (!_addAssetToWorldMessageBox) { + return; + } + + _addAssetToWorldMessageBox->setProperty("text", "Downloading asset file"); + if (!DependencyManager::get()->getThisNodeCanWriteAssets()) { QString errorInfo = "Do not have permissions to write to asset server."; qCDebug(interfaceapp) << "Error downloading asset: " + errorInfo; - OffscreenUi::warning("Error Downloading Asset", errorInfo); + addAssetToWorldError(errorInfo); return; } @@ -5487,6 +5515,10 @@ void Application::addAssetToWorld(QString filePath) { } void Application::addAssetToWorldWithNewMapping(QString path, QString mapping, int copy) { + if (!_addAssetToWorldMessageBox) { + return; + } + auto request = DependencyManager::get()->createGetMappingRequest(mapping); QObject::connect(request, &GetMappingRequest::finished, this, [=](GetMappingRequest* request) mutable { const int MAX_COPY_COUNT = 100; // Limit number of duplicate assets; recursion guard. @@ -5503,7 +5535,7 @@ void Application::addAssetToWorldWithNewMapping(QString path, QString mapping, i QString errorInfo = "Too many copies of asset name: " + mapping.left(mapping.length() - QString::number(copy).length() - 1); qCDebug(interfaceapp) << "Error downloading asset: " + errorInfo; - OffscreenUi::warning("Error Downloading Asset", errorInfo); + addAssetToWorldError(errorInfo); } request->deleteLater(); }); @@ -5512,12 +5544,16 @@ void Application::addAssetToWorldWithNewMapping(QString path, QString mapping, i } void Application::addAssetToWorldUpload(QString path, QString mapping) { + if (!_addAssetToWorldMessageBox) { + return; + } + auto upload = DependencyManager::get()->createUpload(path); QObject::connect(upload, &AssetUpload::finished, this, [=](AssetUpload* upload, const QString& hash) mutable { if (upload->getError() != AssetUpload::NoError) { QString errorInfo = "Could not upload asset to asset server."; qCDebug(interfaceapp) << "Error downloading asset: " + errorInfo; - OffscreenUi::warning("Error Downloading Asset", errorInfo); + addAssetToWorldError(errorInfo); } else { addAssetToWorldSetMapping(mapping, hash); } @@ -5537,12 +5573,16 @@ void Application::addAssetToWorldUpload(QString path, QString mapping) { } void Application::addAssetToWorldSetMapping(QString mapping, QString hash) { + if (!_addAssetToWorldMessageBox) { + return; + } + auto request = DependencyManager::get()->createSetMappingRequest(mapping, hash); connect(request, &SetMappingRequest::finished, this, [=](SetMappingRequest* request) mutable { if (request->getError() != SetMappingRequest::NoError) { QString errorInfo = "Could not set asset mapping."; qCDebug(interfaceapp) << "Error downloading asset: " + errorInfo; - OffscreenUi::warning("Error Downloading Asset", errorInfo); + addAssetToWorldError(errorInfo); } else { addAssetToWorldAddEntity(mapping); } @@ -5553,6 +5593,10 @@ void Application::addAssetToWorldSetMapping(QString mapping, QString hash) { } void Application::addAssetToWorldAddEntity(QString mapping) { + if (!_addAssetToWorldMessageBox) { + return; + } + EntityItemProperties properties; properties.setType(EntityTypes::Model); properties.setName(mapping.right(mapping.length() - 1)); @@ -5566,11 +5610,13 @@ void Application::addAssetToWorldAddEntity(QString mapping) { if (result == QUuid()) { QString errorInfo = "Could not add downloaded asset " + mapping + " to world."; qCDebug(interfaceapp) << "Error downloading asset: " + errorInfo; - OffscreenUi::warning("Error Downloading Asset", errorInfo); + addAssetToWorldError(errorInfo); } else { QString successInfo = "Downloaded asset " + mapping + " added to world"; qCDebug(interfaceapp) << "Downloading asset completed: " + successInfo; - OffscreenUi::information("Downloading Asset Completed", successInfo); + _addAssetToWorldMessageBox->setProperty("text", "Downloading asset completed"); + _addAssetToWorldMessageBox->setProperty("buttons", QMessageBox::Ok); + _addAssetToWorldMessageBox->setProperty("defaultButton", QMessageBox::Ok); } } diff --git a/interface/src/Application.h b/interface/src/Application.h index ea69498408..e97b4c8a26 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -18,6 +18,7 @@ #include #include #include +#include #include @@ -309,6 +310,7 @@ public slots: void toggleLogDialog(); void toggleRunningScriptsWidget() const; Q_INVOKABLE void showAssetServerWidget(QString filePath = ""); + Q_INVOKABLE void addAssetToWorldInitiate(); void addAssetToWorld(QString filePath); void addAssetToWorldWithNewMapping(QString path, QString mapping, int copy); void addAssetToWorldUpload(QString path, QString mapping); @@ -398,6 +400,8 @@ private slots: void updateDisplayMode(); void domainConnectionRefused(const QString& reasonMessage, int reason, const QString& extraInfo); + void onAssetToWorldMessageBoxClosed(); + private: static void initDisplay(); void init(); @@ -616,6 +620,9 @@ private: model::SkyboxPointer _defaultSkybox { new ProceduralSkybox() } ; gpu::TexturePointer _defaultSkyboxTexture; gpu::TexturePointer _defaultSkyboxAmbientTexture; + + QQuickItem* _addAssetToWorldMessageBox{ nullptr }; + void Application::addAssetToWorldError(QString errorText); };