Asset Transfer Protocol Mappings
Showing the changes to interface/src/Application.cpp (1 of 52 files). Show all
Unified · Split
| @@ -141,6 +141,7 @@ · 140 unmodified lines | |||
| 141 | #include "ModelPackager.h" | 141 | #include "ModelPackager.h" |
| 142 | #include "PluginContainerProxy.h" | 142 | #include "PluginContainerProxy.h" |
| 143 | #include "scripting/AccountScriptingInterface.h" | 143 | #include "scripting/AccountScriptingInterface.h" |
| 144 | #include "scripting/AssetMappingsScriptingInterface.h" | ||
| 144 | #include "scripting/AudioDeviceScriptingInterface.h" | 145 | #include "scripting/AudioDeviceScriptingInterface.h" |
| 145 | #include "scripting/ClipboardScriptingInterface.h" | 146 | #include "scripting/ClipboardScriptingInterface.h" |
| 146 | #include "scripting/DesktopScriptingInterface.h" | 147 | #include "scripting/DesktopScriptingInterface.h" |
| @@ -158,7 +159,6 @@ · 11 unmodified lines | |||
| 158 | #include "Stars.h" | 159 | #include "Stars.h" |
| 159 | #include "ui/AddressBarDialog.h" | 160 | #include "ui/AddressBarDialog.h" |
| 160 | #include "ui/AvatarInputs.h" | 161 | #include "ui/AvatarInputs.h" |
| 161 | #include "ui/AssetUploadDialogFactory.h" | ||
| 162 | #include "ui/DialogsManager.h" | 162 | #include "ui/DialogsManager.h" |
| 163 | #include "ui/LoginDialog.h" | 163 | #include "ui/LoginDialog.h" |
| 164 | #include "ui/overlays/Cube3DOverlay.h" | 164 | #include "ui/overlays/Cube3DOverlay.h" |
| @@ -1295,6 +1295,7 @@ void Application::initializeUi() { · 1130 unmodified lines | |||
| 1295 | rootContext->setContextProperty("Quat", new Quat()); | 1295 | rootContext->setContextProperty("Quat", new Quat()); |
| 1296 | rootContext->setContextProperty("Vec3", new Vec3()); | 1296 | rootContext->setContextProperty("Vec3", new Vec3()); |
| 1297 | rootContext->setContextProperty("Uuid", new ScriptUUID()); | 1297 | rootContext->setContextProperty("Uuid", new ScriptUUID()); |
| 1298 | rootContext->setContextProperty("Assets", new AssetMappingsScriptingInterface()); | ||
| 1298 | 1299 | ||
| 1299 | rootContext->setContextProperty("AvatarList", DependencyManager::get<AvatarManager>().data()); | 1300 | rootContext->setContextProperty("AvatarList", DependencyManager::get<AvatarManager>().data()); |
| 1300 | 1301 | ||
| @@ -4018,9 +4019,6 @@ void Application::nodeAdded(SharedNodePointer node) { · 2717 unmodified lines | |||
| 4018 | if (node->getType() == NodeType::AvatarMixer) { | 4019 | if (node->getType() == NodeType::AvatarMixer) { |
| 4019 | // new avatar mixer, send off our identity packet right away | 4020 | // new avatar mixer, send off our identity packet right away |
| 4020 | getMyAvatar()->sendIdentityPacket(); | 4021 | getMyAvatar()->sendIdentityPacket(); |
| 4021 | } else if (node->getType() == NodeType::AssetServer) { | ||
| 4022 | // the addition of an asset-server always re-enables the upload to asset server menu option | ||
| 4023 | Menu::getInstance()->getActionForOption(MenuOption::UploadAsset)->setEnabled(true); | ||
| 4024 | } | 4022 | } |
| 4025 | } | 4023 | } |
| 4026 | 4024 | ||
| @@ -4070,10 +4068,6 @@ void Application::nodeKilled(SharedNodePointer node) { · 43 unmodified lines | |||
| 4070 | } else if (node->getType() == NodeType::AvatarMixer) { | 4068 | } else if (node->getType() == NodeType::AvatarMixer) { |
| 4071 | // our avatar mixer has gone away - clear the hash of avatars | 4069 | // our avatar mixer has gone away - clear the hash of avatars |
| 4072 | DependencyManager::get<AvatarManager>()->clearOtherAvatars(); | 4070 | DependencyManager::get<AvatarManager>()->clearOtherAvatars(); |
| 4073 | } else if (node->getType() == NodeType::AssetServer | ||
| 4074 | && !DependencyManager::get<NodeList>()->soloNodeOfType(NodeType::AssetServer)) { | ||
| 4075 | // this was our last asset server - disable the menu option to upload an asset | ||
| 4076 | Menu::getInstance()->getActionForOption(MenuOption::UploadAsset)->setEnabled(false); | ||
| 4077 | } | 4071 | } |
| 4078 | } | 4072 | } |
| 4079 | void Application::trackIncomingOctreePacket(ReceivedMessage& message, SharedNodePointer sendingNode, bool wasStatsPacket) { | 4073 | void Application::trackIncomingOctreePacket(ReceivedMessage& message, SharedNodePointer sendingNode, bool wasStatsPacket) { |
| @@ -4299,7 +4293,10 @@ bool Application::acceptURL(const QString& urlString, bool defaultUpload) { · 219 unmodified lines | |||
| 4299 | } | 4293 | } |
| 4300 | } | 4294 | } |
| 4301 | 4295 | ||
| 4302 | return defaultUpload && askToUploadAsset(urlString); | 4296 | if (defaultUpload) { |
| 4297 | toggleAssetServerWidget(urlString); | ||
| 4298 | } | ||
| 4299 | return defaultUpload; | ||
| 4303 | } | 4300 | } |
| 4304 | 4301 | ||
| 4305 | void Application::setSessionUUID(const QUuid& sessionUUID) { | 4302 | void Application::setSessionUUID(const QUuid& sessionUUID) { |
| @@ -4327,8 +4324,8 @@ bool Application::askToSetAvatarUrl(const QString& url) { · 21 unmodified lines | |||
| 4327 | 4324 | ||
| 4328 | case FSTReader::HEAD_AND_BODY_MODEL: | 4325 | case FSTReader::HEAD_AND_BODY_MODEL: |
| 4329 | ok = QMessageBox::Ok == OffscreenUi::question("Set Avatar", | 4326 | ok = QMessageBox::Ok == OffscreenUi::question("Set Avatar", |
| 4330 | "Would you like to use '" + modelName + "' for your avatar?", | 4327 | "Would you like to use '" + modelName + "' for your avatar?", |
| 4331 | QMessageBox::Ok | QMessageBox::Cancel, QMessageBox::Ok); | 4328 | QMessageBox::Ok | QMessageBox::Cancel, QMessageBox::Ok); |
| 4332 | break; | 4329 | break; |
| 4333 | 4330 | ||
| 4334 | default: | 4331 | default: |
| @@ -4361,79 +4358,6 @@ bool Application::askToLoadScript(const QString& scriptFilenameOrURL) { · 26 unmodified lines | |||
| 4361 | return true; | 4358 | return true; |
| 4362 | } | 4359 | } |
| 4363 | 4360 | ||
| 4364 | bool Application::askToUploadAsset(const QString& filename) { | ||
| 4365 | if (!DependencyManager::get<NodeList>()->getThisNodeCanRez()) { | ||
| 4366 | OffscreenUi::warning(_window, "Failed Upload", | ||
| 4367 | QString("You don't have upload rights on that domain.\n\n")); | ||
| 4368 | return false; | ||
| 4369 | } | ||
| 4370 | |||
| 4371 | QUrl url { filename }; | ||
| 4372 | if (auto upload = DependencyManager::get<AssetClient>()->createUpload(url.toLocalFile())) { | ||
| 4373 | |||
| 4374 | QMessageBox messageBox; | ||
| 4375 | messageBox.setWindowTitle("Asset upload"); | ||
| 4376 | messageBox.setText("You are about to upload the following file to the asset server:\n" + | ||
| 4377 | url.toDisplayString()); | ||
| 4378 | messageBox.setInformativeText("Do you want to continue?"); | ||
| 4379 | messageBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel); | ||
| 4380 | messageBox.setDefaultButton(QMessageBox::Ok); | ||
| 4381 | |||
| 4382 | // Option to drop model in world for models | ||
| 4383 | if (filename.endsWith(FBX_EXTENSION, Qt::CaseInsensitive) || filename.endsWith(OBJ_EXTENSION, Qt::CaseInsensitive)) { | ||
| 4384 | auto checkBox = new QCheckBox(&messageBox); | ||
| 4385 | checkBox->setText("Add to scene"); | ||
| 4386 | messageBox.setCheckBox(checkBox); | ||
| 4387 | } | ||
| 4388 | |||
| 4389 | if (messageBox.exec() != QMessageBox::Ok) { | ||
| 4390 | upload->deleteLater(); | ||
| 4391 | return false; | ||
| 4392 | } | ||
| 4393 | |||
| 4394 | // connect to the finished signal so we know when the AssetUpload is done | ||
| 4395 | if (messageBox.checkBox() && (messageBox.checkBox()->checkState() == Qt::Checked)) { | ||
| 4396 | // Custom behavior for models | ||
| 4397 | QObject::connect(upload, &AssetUpload::finished, this, &Application::modelUploadFinished); | ||
| 4398 | } else { | ||
| 4399 | QObject::connect(upload, &AssetUpload::finished, | ||
| 4400 | &AssetUploadDialogFactory::getInstance(), | ||
| 4401 | &AssetUploadDialogFactory::handleUploadFinished); | ||
| 4402 | } | ||
| 4403 | |||
| 4404 | // start the upload now | ||
| 4405 | upload->start(); | ||
| 4406 | return true; | ||
| 4407 | } | ||
| 4408 | |||
| 4409 | // display a message box with the error | ||
| 4410 | OffscreenUi::warning(_window, "Failed Upload", QString("Failed to upload %1.\n\n").arg(filename)); | ||
| 4411 | return false; | ||
| 4412 | } | ||
| 4413 | |||
| 4414 | void Application::modelUploadFinished(AssetUpload* upload, const QString& hash) { | ||
| 4415 | auto filename = QFileInfo(upload->getFilename()).fileName(); | ||
| 4416 | |||
| 4417 | if ((upload->getError() == AssetUpload::NoError) && | ||
| 4418 | (FBX_EXTENSION.endsWith(upload->getExtension(), Qt::CaseInsensitive) || | ||
| 4419 | OBJ_EXTENSION.endsWith(upload->getExtension(), Qt::CaseInsensitive))) { | ||
| 4420 | |||
| 4421 | auto entities = DependencyManager::get<EntityScriptingInterface>(); | ||
| 4422 | |||
| 4423 | EntityItemProperties properties; | ||
| 4424 | properties.setType(EntityTypes::Model); | ||
| 4425 | properties.setModelURL(QString("%1:%2.%3").arg(URL_SCHEME_ATP).arg(hash).arg(upload->getExtension())); | ||
| 4426 | properties.setPosition(_myCamera.getPosition() + _myCamera.getOrientation() * Vectors::FRONT * 2.0f); | ||
| 4427 | properties.setName(QUrl(upload->getFilename()).fileName()); | ||
| 4428 | |||
| 4429 | entities->addEntity(properties); | ||
| 4430 | |||
| 4431 | upload->deleteLater(); | ||
| 4432 | } else { | ||
| 4433 | AssetUploadDialogFactory::getInstance().handleUploadFinished(upload, hash); | ||
| 4434 | } | ||
| 4435 | } | ||
| 4436 | |||
| 4437 | bool Application::askToWearAvatarAttachmentUrl(const QString& url) { | 4361 | bool Application::askToWearAvatarAttachmentUrl(const QString& url) { |
| 4438 | 4362 | ||
| 4439 | QNetworkAccessManager& networkAccessManager = NetworkAccessManager::getInstance(); | 4363 | QNetworkAccessManager& networkAccessManager = NetworkAccessManager::getInstance(); |
| @@ -4533,6 +4457,22 @@ void Application::toggleRunningScriptsWidget() { · 93 unmodified lines | |||
| 4533 | //} | 4457 | //} |
| 4534 | } | 4458 | } |
| 4535 | 4459 | ||
| 4460 | void Application::toggleAssetServerWidget(QString filePath) { | ||
| 4461 | if (!DependencyManager::get<NodeList>()->getThisNodeCanRez()) { | ||
| 4462 | return; | ||
| 4463 | } | ||
| 4464 | |||
| 4465 | static const QUrl url { "AssetServer.qml" }; | ||
| 4466 | |||
| 4467 | auto startUpload = [=](QQmlContext* context, QObject* newObject){ | ||
| 4468 | if (!filePath.isEmpty()) { | ||
| 4469 | emit uploadRequest(filePath); | ||
| 4470 | } | ||
| 4471 | }; | ||
| 4472 | DependencyManager::get<OffscreenUi>()->show(url, "AssetServer", startUpload); | ||
| 4473 | startUpload(nullptr, nullptr); | ||
| 4474 | } | ||
| 4475 | |||
| 4536 | void Application::packageModel() { | 4476 | void Application::packageModel() { |
| 4537 | ModelPackager::package(); | 4477 | ModelPackager::package(); |
| 4538 | } | 4478 | } |