From 7b41efcf8622b4ac2a269b7e592e757615ec5c76 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Mon, 12 Oct 2015 13:35:21 -0700 Subject: [PATCH 1/2] All file types eligible for upload to asset server --- interface/src/Application.cpp | 128 ++++++++++---------- interface/src/Application.h | 2 +- interface/src/ui/AssetUploadDialogFactory.h | 1 - 3 files changed, 64 insertions(+), 67 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index cfeb77f638..0d51ccbbc7 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -126,6 +126,7 @@ #include "Stars.h" #include "ui/AddressBarDialog.h" #include "ui/AvatarInputs.h" +#include "ui/AssetUploadDialogFactory.h" #include "ui/DataWebDialog.h" #include "ui/DialogsManager.h" #include "ui/LoginDialog.h" @@ -159,6 +160,7 @@ static const QString SVO_JSON_EXTENSION = ".svo.json"; static const QString JS_EXTENSION = ".js"; static const QString FST_EXTENSION = ".fst"; static const QString FBX_EXTENSION = ".fbx"; +static const QString OBJ_EXTENSION = ".obj"; static const int MIRROR_VIEW_TOP_PADDING = 5; static const int MIRROR_VIEW_LEFT_PADDING = 10; @@ -179,9 +181,6 @@ static const unsigned int THROTTLED_SIM_FRAMERATE = 15; static const int TARGET_SIM_FRAME_PERIOD_MS = MSECS_PER_SECOND / TARGET_SIM_FRAMERATE; static const int THROTTLED_SIM_FRAME_PERIOD_MS = MSECS_PER_SECOND / THROTTLED_SIM_FRAMERATE; -const QString CHECK_VERSION_URL = "https://highfidelity.com/latestVersion.xml"; -const QString SKIP_FILENAME = QStandardPaths::writableLocation(QStandardPaths::DataLocation) + "/hifi.skipversion"; - #ifndef __APPLE__ static const QString DESKTOP_LOCATION = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation); #else @@ -197,8 +196,7 @@ const QHash Application::_acceptedExtensi { SVO_EXTENSION, &Application::importSVOFromURL }, { SVO_JSON_EXTENSION, &Application::importSVOFromURL }, { JS_EXTENSION, &Application::askToLoadScript }, - { FST_EXTENSION, &Application::askToSetAvatarUrl }, - { FBX_EXTENSION, &Application::askToUploadAsset } + { FST_EXTENSION, &Application::askToSetAvatarUrl } }; #ifdef Q_OS_WIN @@ -2023,21 +2021,14 @@ void Application::dropEvent(QDropEvent *event) { const QMimeData* mimeData = event->mimeData(); for (auto& url : mimeData->urls()) { QString urlString = url.toString(); - if (canAcceptURL(urlString) && acceptURL(urlString)) { + if (acceptURL(urlString, true)) { event->acceptProposedAction(); } } } void Application::dragEnterEvent(QDragEnterEvent* event) { - const QMimeData* mimeData = event->mimeData(); - for (auto& url : mimeData->urls()) { - auto urlString = url.toString(); - if (canAcceptURL(urlString)) { - event->acceptProposedAction(); - break; - } - } + event->acceptProposedAction(); } bool Application::acceptSnapshot(const QString& urlString) { @@ -3973,26 +3964,26 @@ bool Application::canAcceptURL(const QString& urlString) { return false; } -bool Application::acceptURL(const QString& urlString) { +bool Application::acceptURL(const QString& urlString, bool defaultUpload) { if (urlString.startsWith(HIFI_URL_SCHEME)) { // this is a hifi URL - have the AddressManager handle it QMetaObject::invokeMethod(DependencyManager::get().data(), "handleLookupString", Qt::AutoConnection, Q_ARG(const QString&, urlString)); return true; - } else { - QUrl url(urlString); - QHashIterator i(_acceptedExtensions); - QString lowerPath = url.path().toLower(); - while (i.hasNext()) { - i.next(); - if (lowerPath.endsWith(i.key())) { - AcceptURLMethod method = i.value(); - (this->*method)(urlString); - return true; - } + } + + QUrl url(urlString); + QHashIterator i(_acceptedExtensions); + QString lowerPath = url.path().toLower(); + while (i.hasNext()) { + i.next(); + if (lowerPath.endsWith(i.key())) { + AcceptURLMethod method = i.value(); + return (this->*method)(urlString); } } - return false; + + return defaultUpload && askToUploadAsset(urlString); } void Application::setSessionUUID(const QUuid& sessionUUID) { @@ -4076,8 +4067,36 @@ bool Application::askToUploadAsset(const QString& filename) { QUrl url { filename }; if (auto upload = DependencyManager::get()->createUpload(url.toLocalFile())) { + + QMessageBox messageBox; + messageBox.setWindowTitle("Asset upload"); + messageBox.setText("You are about to upload the following file to the asset server:\n" + + url.toDisplayString()); + messageBox.setInformativeText("Do you want to continue?"); + messageBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel); + messageBox.setDefaultButton(QMessageBox::Ok); + + // Option to drop model in world for models + if (filename.endsWith(FBX_EXTENSION) || filename.endsWith(OBJ_EXTENSION)) { + auto checkBox = new QCheckBox(&messageBox); + checkBox->setText("Drop model in world."); + messageBox.setCheckBox(checkBox); + } + + if (messageBox.exec() != QMessageBox::Ok) { + upload->deleteLater(); + return false; + } + // connect to the finished signal so we know when the AssetUpload is done - QObject::connect(upload, &AssetUpload::finished, this, &Application::assetUploadFinished); + if (messageBox.checkBox() && (messageBox.checkBox()->checkState() == Qt::Checked)) { + // Custom behavior for models + QObject::connect(upload, &AssetUpload::finished, this, &Application::assetUploadFinished); + } else { + QObject::connect(upload, &AssetUpload::finished, + &AssetUploadDialogFactory::getInstance(), + &AssetUploadDialogFactory::handleUploadFinished); + } // start the upload now upload->start(); @@ -4090,46 +4109,25 @@ bool Application::askToUploadAsset(const QString& filename) { } 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; + auto filename = QFileInfo(upload->getFilename()).fileName(); + + if ((upload->getError() == AssetUpload::NoError) && + (filename.endsWith(FBX_EXTENSION) || filename.endsWith(OBJ_EXTENSION))) { - 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; - } + auto entities = DependencyManager::get(); - // 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); + EntityItemProperties properties; + properties.setType(EntityTypes::Model); + properties.setModelURL(QString("%1:%2.%3").arg(ATP_SCHEME).arg(hash).arg(upload->getExtension())); + properties.setPosition(_myCamera.getPosition() + _myCamera.getOrientation() * Vectors::FRONT * 2.0f); + properties.setName(QUrl(upload->getFilename()).fileName()); + + entities->addEntity(properties); + + upload->deleteLater(); + } else { + AssetUploadDialogFactory::getInstance().handleUploadFinished(upload, hash); } - - 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, diff --git a/interface/src/Application.h b/interface/src/Application.h index 8444eab2b6..3e443ea843 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -211,7 +211,7 @@ public: void setScriptsLocation(const QString& scriptsLocation); bool canAcceptURL(const QString& url); - bool acceptURL(const QString& url); + bool acceptURL(const QString& url, bool defaultUpload = false); void setMaxOctreePacketsPerSecond(int maxOctreePPS); int getMaxOctreePacketsPerSecond(); diff --git a/interface/src/ui/AssetUploadDialogFactory.h b/interface/src/ui/AssetUploadDialogFactory.h index 36c5d10595..a8e8765f20 100644 --- a/interface/src/ui/AssetUploadDialogFactory.h +++ b/interface/src/ui/AssetUploadDialogFactory.h @@ -30,7 +30,6 @@ public: public slots: void showDialog(); -private slots: void handleUploadFinished(AssetUpload* upload, const QString& hash); private: From eea89ba010bedfe3052bf14e68450a6ba404e129 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Mon, 12 Oct 2015 14:26:28 -0700 Subject: [PATCH 2/2] CR - Rename method --- interface/src/Application.cpp | 4 ++-- interface/src/Application.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 0d51ccbbc7..9e9830d977 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -4091,7 +4091,7 @@ bool Application::askToUploadAsset(const QString& filename) { // connect to the finished signal so we know when the AssetUpload is done if (messageBox.checkBox() && (messageBox.checkBox()->checkState() == Qt::Checked)) { // Custom behavior for models - QObject::connect(upload, &AssetUpload::finished, this, &Application::assetUploadFinished); + QObject::connect(upload, &AssetUpload::finished, this, &Application::modelUploadFinished); } else { QObject::connect(upload, &AssetUpload::finished, &AssetUploadDialogFactory::getInstance(), @@ -4108,7 +4108,7 @@ bool Application::askToUploadAsset(const QString& filename) { return false; } -void Application::assetUploadFinished(AssetUpload* upload, const QString& hash) { +void Application::modelUploadFinished(AssetUpload* upload, const QString& hash) { auto filename = QFileInfo(upload->getFilename()).fileName(); if ((upload->getError() == AssetUpload::NoError) && diff --git a/interface/src/Application.h b/interface/src/Application.h index 3e443ea843..a2125e7e09 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -329,7 +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 modelUploadFinished(AssetUpload* upload, const QString& hash); void setSessionUUID(const QUuid& sessionUUID); void domainChanged(const QString& domainHostname);