History

Merge pull request #7318 from birarda/atp

Asset Transfer Protocol Mappings

Andrew Meadows committed 10 years ago

Commit 6028c3e2 parents f30e8e9 aa4c0ca52 files · +2893 −754Browse files

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

Unified · Split

interface/src/Application.cpp+24−84
@@ -141,6 +141,7 @@ · 140 unmodified lines
141141 #include "ModelPackager.h"
142142 #include "PluginContainerProxy.h"
143143 #include "scripting/AccountScriptingInterface.h"
144+#include "scripting/AssetMappingsScriptingInterface.h"
144145 #include "scripting/AudioDeviceScriptingInterface.h"
145146 #include "scripting/ClipboardScriptingInterface.h"
146147 #include "scripting/DesktopScriptingInterface.h"
@@ -158,7 +159,6 @@ · 11 unmodified lines
158159 #include "Stars.h"
159160 #include "ui/AddressBarDialog.h"
160161 #include "ui/AvatarInputs.h"
161−#include "ui/AssetUploadDialogFactory.h"
162162 #include "ui/DialogsManager.h"
163163 #include "ui/LoginDialog.h"
164164 #include "ui/overlays/Cube3DOverlay.h"
@@ -1295,6 +1295,7 @@ void Application::initializeUi() { · 1130 unmodified lines
12951295 rootContext->setContextProperty("Quat", new Quat());
12961296 rootContext->setContextProperty("Vec3", new Vec3());
12971297 rootContext->setContextProperty("Uuid", new ScriptUUID());
1298+ rootContext->setContextProperty("Assets", new AssetMappingsScriptingInterface());
12981299
12991300 rootContext->setContextProperty("AvatarList", DependencyManager::get<AvatarManager>().data());
13001301
@@ -4018,9 +4019,6 @@ void Application::nodeAdded(SharedNodePointer node) { · 2717 unmodified lines
40184019 if (node->getType() == NodeType::AvatarMixer) {
40194020 // new avatar mixer, send off our identity packet right away
40204021 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);
40244022 }
40254023 }
40264024
@@ -4070,10 +4068,6 @@ void Application::nodeKilled(SharedNodePointer node) { · 43 unmodified lines
40704068 } else if (node->getType() == NodeType::AvatarMixer) {
40714069 // our avatar mixer has gone away - clear the hash of avatars
40724070 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);
40774071 }
40784072 }
40794073 void Application::trackIncomingOctreePacket(ReceivedMessage& message, SharedNodePointer sendingNode, bool wasStatsPacket) {
@@ -4299,7 +4293,10 @@ bool Application::acceptURL(const QString& urlString, bool defaultUpload) { · 219 unmodified lines
42994293 }
43004294 }
43014295
4302− return defaultUpload && askToUploadAsset(urlString);
4296+ if (defaultUpload) {
4297+ toggleAssetServerWidget(urlString);
4298+ }
4299+ return defaultUpload;
43034300 }
43044301
43054302 void Application::setSessionUUID(const QUuid& sessionUUID) {
@@ -4327,8 +4324,8 @@ bool Application::askToSetAvatarUrl(const QString& url) { · 21 unmodified lines
43274324
43284325 case FSTReader::HEAD_AND_BODY_MODEL:
43294326 ok = QMessageBox::Ok == OffscreenUi::question("Set Avatar",
4330− "Would you like to use '" + modelName + "' for your avatar?",
4331− QMessageBox::Ok | QMessageBox::Cancel, QMessageBox::Ok);
4327+ "Would you like to use '" + modelName + "' for your avatar?",
4328+ QMessageBox::Ok | QMessageBox::Cancel, QMessageBox::Ok);
43324329 break;
43334330
43344331 default:
@@ -4361,79 +4358,6 @@ bool Application::askToLoadScript(const QString& scriptFilenameOrURL) { · 26 unmodified lines
43614358 return true;
43624359 }
43634360
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−
44374361 bool Application::askToWearAvatarAttachmentUrl(const QString& url) {
44384362
44394363 QNetworkAccessManager& networkAccessManager = NetworkAccessManager::getInstance();
@@ -4533,6 +4457,22 @@ void Application::toggleRunningScriptsWidget() { · 93 unmodified lines
45334457 //}
45344458 }
45354459
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+
45364476 void Application::packageModel() {
45374477 ModelPackager::package();
45384478 }