From 2229f942df99b14ecade9f08d909aa5fd6e3090e Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Thu, 8 Oct 2015 18:21:58 -0700 Subject: [PATCH] Spawn fbx dropped in front of avatar --- interface/src/Application.cpp | 61 +++++++++++++++++++++++++++++++++-- interface/src/Application.h | 2 ++ 2 files changed, 60 insertions(+), 3 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index c5b4333ea6..ef7b5924eb 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -43,6 +43,7 @@ #include #include #include +#include #include #include #include @@ -4066,14 +4067,68 @@ bool Application::askToLoadScript(const QString& scriptFilenameOrURL) { return true; } -#include "ui/AssetUploadDialogFactory.h" bool Application::askToUploadAsset(const QString& filename) { - if (!filename.isEmpty()) { - AssetUploadDialogFactory::getInstance().showDialog(filename); + QUrl url { filename }; + if (auto upload = DependencyManager::get()->createUpload(url.toLocalFile())) { + // connect to the finished signal so we know when the AssetUpload is done + QObject::connect(upload, &AssetUpload::finished, this, &Application::assetUploadFinished); + + // start the upload now + upload->start(); + + return true; } + + // display a message box with the error + auto errorMessage = QString("Failed to upload %1.\n\n").arg(filename); + QMessageBox::warning(_window, "Failed Upload", errorMessage); + return false; } +void Application::assetUploadFinished(AssetUpload* upload, const QString& hash) { + if (upload->getError() != AssetUpload::NoError) { + // figure out the right error message for the message box + QString additionalError; + + switch (upload->getError()) { + case AssetUpload::PermissionDenied: + additionalError = "You do not have permission to upload content to this asset-server."; + break; + case AssetUpload::TooLarge: + additionalError = "The uploaded content was too large and could not be stored in the asset-server."; + break; + case AssetUpload::FileOpenError: + additionalError = "The file could not be opened. Please check your permissions and try again."; + break; + case AssetUpload::NetworkError: + additionalError = "The file could not be opened. Please check your network connectivity."; + break; + default: + // not handled, do not show a message box + return; + } + + // display a message box with the error + auto filename = QFileInfo(upload->getFilename()).fileName(); + QString errorMessage = QString("Failed to upload %1.\n\n%2").arg(filename, additionalError); + QMessageBox::warning(_window, "Failed Upload", errorMessage); + } + + auto entities = DependencyManager::get(); + auto myAvatar = getMyAvatar(); + + EntityItemProperties properties; + properties.setType(EntityTypes::Model); + properties.setModelURL(QString("%1:%2.%3").arg(ATP_SCHEME).arg(hash).arg(upload->getExtension())); + properties.setPosition(myAvatar->getPosition() + myAvatar->getOrientation() * Vectors::FRONT * 2.0f); + properties.setName(QUrl(upload->getFilename()).fileName()); + + entities->addEntity(properties); + + upload->deleteLater(); +} + ScriptEngine* Application::loadScript(const QString& scriptFilename, bool isUserLoaded, bool loadScriptFromEditor, bool activateMainWindow, bool reload) { diff --git a/interface/src/Application.h b/interface/src/Application.h index dc1d9cdb84..8444eab2b6 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -67,6 +67,7 @@ class OffscreenGlCanvas; class GLCanvas; class FaceTracker; class MainWindow; +class AssetUpload; #ifdef Q_OS_WIN static const UINT UWM_IDENTIFY_INSTANCES = @@ -328,6 +329,7 @@ private slots: bool askToSetAvatarUrl(const QString& url); bool askToLoadScript(const QString& scriptFilenameOrURL); bool askToUploadAsset(const QString& asset); + void assetUploadFinished(AssetUpload* upload, const QString& hash); void setSessionUUID(const QUuid& sessionUUID); void domainChanged(const QString& domainHostname);